5287: 维塔利和派

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:18 通过:7

题目描述

辛苦了一天后,维塔利饿了,他想吃他最喜欢的土豆派。但事情并没有那么简单。维塔利在房子的第一个房间里,n个房间排成一行,从左到右开始编号。你可以從第一個房間到第二個房間,從第二個房間到第三個房間,依此类推——你可以從(n-1)第一個房間到第n個房間。因此,您只能从房间 x-1 前往房间x。
土豆派位于第n个房间,维塔利需要去那里。
每对连续的房间之间都有一扇门。为了从房间x-1进入房间x,您需要使用相应的钥匙打开房间之间的门。
房子总共有几种类型的门(用大写拉丁字母表示)和几种类型的钥匙(用小写拉丁字母表示)。t型的钥匙可以打开T型的门,当且仅当t和T是同一个字母,写在不同的情况下。例如,钥匙f可以打开门F。
前n-1个房间中的每一个都只包含一把某种类型的钥匙,维塔利可以用来到达下一个房间。一旦用钥匙打开门,维塔利就不会从钥匙孔里拿到钥匙,但他会立即跑进下一个房间。换句话说,每把钥匙最多可以打开一扇门。
维塔利意识到他最终可能会在没有打开下一个房间门的钥匙的情况下进入某个房间。在开始之前,在他得到土豆派维塔利可以购买任何数量的任何类型的钥匙,保证到达房间n。
考虑到房子的平面图,维塔利想知道他需要购买的最少钥匙数量是多少,才能确定到达房间n,那里有一个美味的土豆派。编写一个程序来帮助维塔利找出这个数字
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 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 i of 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.
Examples
Input
3
aAbB
Output
0
Input
4
aBaCaB
Output
3
Input
5
xYyXzZaZ
Output
2

输入格式

输入的第一行包含一个正整数n (2≤n≤10^5)−房屋中的房间数。
输入的第二行包含长度为2·n-2.让我们从左到右对字符串的元素进行编号,从一个开始。
给定字符串s中的奇数位置包含小写拉丁字母 - 位于相应房间中的键的类型。因此,给定字符串s的每个奇数位置i都包含一个小写拉丁字母 − 房间号 (i+1)/2 中的密钥类型。
给定字符串中的偶数位置包含大写拉丁字母 - 房间之间的门类型。因此,给定字符串s的每个偶数位置 i 都包含一个大写字母 − 从房间 i/2 通向房间i/2+1 的门的类型。

输出格式

打印唯一的整数 - 维塔利需要购买的最小钥匙数,以确保从房间一到房间n。

输入样例1:

3

aAbB

输出样例1:

0

输入样例2:

4

aBaCaB

输出样例2:

3

输入样例3:

xYyXzZaZ

输出样例3:

2

输入样例 复制

3

aAbB

输出样例 复制

0