#P4808. Vitaliy and Pie

Vitaliy and Pie

Vitaliy and Pie

题面翻译

nn 个房间排成一行,从左到右编号 1n1-n 。只能从房间 x1x - 1 到房间 xx 。需要去那里第 nn 个房间。每一对连续的房间之间都有一扇门。房间有几种类型的门(用大写字母表示)和几种类型的钥匙(用小写字母表示)。当且仅当门的字母与钥匙的字母相同,大小写不同的情况下,才能打开相应的门。例如,f钥匙可以打开F门。每把钥匙只能打开一扇门。每经过一个房间可以拿到一个钥匙。

求还需要多少把钥匙才能到达房间 nn

第一行输入 nn

第二行包含长度为2×n22\times n - 2的字符串 ss

ii 个奇数位置都包含一个小写的字母代表房间号 ii 中的钥匙的类型。

ii 个偶数位置都包含一个大写字母代表从房间 ii 到房间 i+1i + 1 的门的类型。

题目描述

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 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 ( n1 n-1 )-th room to the n n -th room. Thus, you can go to room x x only from room x1 x-1 .

The potato pie is located in the n 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 x from room x1 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 t can open the door of type T T if and only if t t and T T are the same letter, written in different cases. For example, key f can open door F.

Each of the first n1 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 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 n , which has a delicious potato pie. Write a program that will help Vitaly find out this number.

输入格式

The first line of the input contains a positive integer n n ( 2<=n<=105 2<=n<=10^{5} ) — the number of rooms in the house.

The second line of the input contains string s s of length 2n2 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 s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i i of the given string s s contains a lowercase Latin letter — the type of the key that lies in room number (i+1)/2 (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 i of the given string s s contains an uppercase letter — the type of the door that leads from room i/2 i/2 to room i/2+1 i/2+1 .

输出格式

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

样例 #1

样例输入 #1

3
aAbB

样例输出 #1

0

样例 #2

样例输入 #2

4
aBaCaB

样例输出 #2

3

样例 #3

样例输入 #3

5
xYyXzZaZ

样例输出 #3

2