Vitaliy and Pie

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.

The potato pie is located in the n-th room and Vitaly needs to go there.

Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key.

In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.

Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.

Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.

Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number.

Input

The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house.

The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one.

The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2.

The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position iof the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1.

Output

Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n.

Sample Input

Input
3 aAbB
Output
0
Input
4 aBaCaB
Output
3
Input
5 xYyXzZaZ
Output
2
题解:注意钥匙只能用一次,刚开始ce,没敲头文件stdio....然后re,数组开小。。。然后wa,我傻逼的用位运算,这水题错了4次。。。
代码:
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
const int MAXN = ;
char s[MAXN];
int key[];
int main(){
int N;
while(~scanf("%d", &N)){
int ky = , nu = ;
scanf("%s", s);
int len = strlen(s);
memset(key, , sizeof(key));
for(int i = ; i < len; i++){
if(s[i] >= 'A' && s[i] <= 'Z'){
if(key[s[i] - 'A'] > ){
key[s[i] - 'A']--;
}
else nu++;
}
else if(s[i] >= 'a' && s[i] <= 'z'){
key[s[i] - 'a']++;
}
}
printf("%d\n", nu);
}
return ;
}

最新文章

  1. Servlet-Cookie源码分析 源码环境:Tomcat8
  2. 用Kotlin开发Android应用(III):扩展函数和默认值
  3. Android性能优化典范第二季
  4. 驱动笔记 - ioctl
  5. Hadoop集群(第8期)_HDFS初探之旅
  6. 浅谈JavaScript DOM编程艺术读后感和一点总结
  7. Mysql连接出错问题
  8. jQuery 属性(十二)
  9. txtbook简单HTML可读化改造
  10. JavaScript是如何工作的:引擎,运行时和调用堆栈的概述!
  11. Linux之redis-cluster(集群配置)
  12. Sqlserver 计算两坐标距离函数
  13. tomcat 配置细节
  14. Codeforces 1110D Jongmah [DP]
  15. 【转】分布式一致性算法:Raft 算法(Raft 论文翻译)
  16. Bitbox : a small open, DIY 32 bit VGA console
  17. Redis(五)主从复制
  18. xarmain使用Forms编译android工程出现support_r19.0.1.zip支持包错误
  19. Thrift辅助类,用于简化Thrift编程
  20. python入门(二):数据类型和结构

热门文章

  1. python高级编程之描述符与属性02
  2. 使用 Microsoft.ApplicationBlocks.Data SqlHelper 查询超时以及解决方案
  3. PHP连接Mysql服务器的操作
  4. blockUI
  5. LeetCode——Symmetric Tree
  6. 不同浏览器对URL最大长度的限制(转)
  7. 常见maven镜像
  8. POJ 1269 - Intersecting Lines 直线与直线相交
  9. Shell glob
  10. vs2010中出现:程序管理器匹配不正确错误