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 ≤ 10^5) — 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 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

Difficulty: interview

Starter code:

Solutions:
n = int(input())
r = {}
ans = 0
for i in input():
    if i == i.lower():
        if i in r:
            r[i] += 1
        else:
            r[i] = 1
    else:
        i = i.lower()
        if i in r and r[i] > 0:
            r[i] -= 1
        else:
            ans += 1
print(ans)

n = int(input())
s = input()

d = {}
res = 0
for x in s:
    if x.islower():
        d[x] = d.get(x, 0) + 1
    else:
        if d.get(x.lower(), 0) > 0:
            d[x.lower()] -= 1
        else:
            res += 1

print(res)

n=int(input())
a=[0 for i in range(26)]
s=input().strip()
ans=0
for i in range(n-1):
    a[ord(s[2*i])-97]+=1
    if a[ord(s[2*i+1])-65]>0:
        a[ord(s[2*i+1])-65]-=1
    else:
        ans+=1
print(ans)

n = int(input())
s = input()
ans = 0
d = {}
for i in range(0, 2 * n - 2, 2):
    key = s[i]
    dor = s[i + 1]
    if key not in d:
        d[key] = 1
    else:
        d[key] += 1
    if (dor.lower() not in d) or (d[dor.lower()] == 0):
        ans += 1
    else:
        d[dor.lower()] -= 1
print(ans)

n = int(input())
s = input()
k = {}
ans = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] not in k:
            k[s[i]] = 1
        else:
            k[s[i]] += 1
    else:
        if s[i].lower() not in k or (s[i].lower() in k and k[s[i].lower()] <= 0):
            ans += 1
        else:
            k[s[i].lower()] -= 1
print(ans)


t=0
l='abcdefghijklmnopqrstuvwxyz'
key={}
for i in l:
    key[i] = 0
a=int(input())
b=input()
for i in b:
    if i in l:
        key[i] +=1
    else:
        if not key[i.lower()]:
            t+=1
        else:
            key[i.lower()]-=1
print(t)


n = int(input())
s = input()
cnt = 0
keys = {chr(i):0 for i in range(ord('a'),ord('z')+1)}
for i in range(len(s)//2):
	keys[s[i*2]] += 1
	if keys[s[i*2+1].lower()] == 0:
		cnt += 1
	else:
		keys[s[i*2+1].lower()]-=1
print(cnt)


from collections import defaultdict

d = defaultdict(int)

def __starting_point():
    input()

    sum_v = 0

    for i, x in enumerate(input()):
        if i % 2 == 0:
            d[x] += 1
        else:
            if d[x.lower()] == 0:
                sum_v += 1
            else:
                d[x.lower()] -= 1

    print(sum_v)
__starting_point()

ans = 0
n = int(input())
keys = [0 for i in range(30)]
s = input()
for i in range(n-1):
    keys[ord(s[2*i].capitalize()) - ord('A')] += 1
    if keys[ord(s[2*i + 1]) - ord('A')] == 0:
        ans += 1
    else:
        keys[ord(s[2*i + 1]) - ord('A')] -= 1
print(ans)



import sys
import collections

def main():
	n = int(sys.stdin.readline())
	s = sys.stdin.readline()
	more_keys = 0
	keys = collections.Counter()
	for i, x in enumerate(s):
		if i % 2 == 0:
			keys[x] += 1
		else:
			k = x.lower()
			if keys[k] > 0:
				keys[k] -= 1
			else:
				more_keys += 1
	print (more_keys)

def __starting_point():
	main()
__starting_point()

n = int(input())

data = input()

available_keys = {}
needed_keys = 0

k = 0
for _ in range(n-1):
    key = data[k]
    lock = data[k+1].lower()

    k += 2

    available_keys[key] = available_keys.get(key, 0) + 1

    if available_keys.get(lock, 0):
        available_keys[lock] -= 1
    else:
        needed_keys += 1

print(needed_keys)

n = int(input())
s = input()
er = {}
ers = set()
cnt = 0
for i in range(len(s)):
    if i % 2 == 0:
        if ord(s[i]) in ers:
            er[ord(s[i])] += 1
        else:
            ers.add(ord(s[i]))
            er[ord(s[i])] = 1
    else:
        if ord(s[i]) + 32 in ers and er[ord(s[i]) + 32] >= 1:
            er[ord(s[i]) + 32] -=  1
        else:
            cnt += 1
print(cnt)
        
        


def main():
    n = int(input())
    s = input()
    
    result = 0
    d = [0 for i in range(256)]
    for i in range(n - 1):
        key = s[i * 2]
        door = ord(s[i * 2 + 1])
        if key.islower(): key = key.upper()
        else: key = key.lower()
        d[ord(key)] += 1
        if not d[door]:
            result += 1
        else:
            d[door] -= 1
    
    print(result)
    
    
main()


d = dict()
n = int(input())
s = input().rstrip()
sum1 = 0
def f(c):
    return chr(ord(c) - ord('A') + ord('a'))
for i in range(len(s)):
    c = s[i]
    if (i + 1) % 2 == 1:
        if c in d:
            d[c] += 1
        else:
            d[c] = 1
    else:
        if f(c) in d:
           
            if d[f(c)] > 0:
                d[f(c)] -= 1
            else:
                sum1 += 1
        else:
            sum1 += 1
print(sum1)


n = int(input())
line = str(input())

doors = []
keys  = []
havekeys1  = [False] * 33
havekeys2  = [0] * 33

for i in range(len(line)):
    if i % 2 == 0:
        keys.append(line[i])
    else:
        doors.append(line[i])

res = 0
for i in range(n - 1):
    havekeys1[ord(keys[i]) - 97] = True
    havekeys2[ord(keys[i]) - 97] += 1
    if havekeys1[ord(doors[i]) - 65]:
        havekeys2[ord(doors[i]) - 65] -= 1
        if havekeys2[ord(doors[i]) - 65] == 0:
            havekeys1[ord(doors[i]) - 65] = False
    else:
        res += 1

print(res)





















n = int(input())
b = input()
a = set()
d = dict()
count = 0
for i in range(2 * n - 2):
    if i % 2 == 0:
        if b[i] not in a:
            a.add(b[i])
            d[b[i]] = 1
        else:
            d[b[i]] += 1
    else:
        if b[i].lower() in a:
            d[b[i].lower()] -= 1
            if d[b[i].lower()] == 0:
                a.remove(b[i].lower())
        else:
            count += 1    
print(count)

#!/usr/bin/env python
# -.- coding: utf-8 -.-


def main():
    n_rooms = int(input())
    line = input()
    keys = line[0::2]
    doors = line[1::2]
    buykeys = 0
    keyinbag = {}
    for room_index in range(n_rooms - 1):
        if keys[room_index] in keyinbag:
            keyinbag[keys[room_index]] += 1
        else:
            keyinbag[keys[room_index]] = 1
        if not doors[room_index].lower() in keyinbag or\
           keyinbag[doors[room_index].lower()] < 1:
            buykeys += 1
        else:
            keyinbag[doors[room_index].lower()] -= 1
    print(buykeys)


def __starting_point():
    main()

__starting_point()

#!/c/Python34/python
# coding: utf-8


def main():
    N = int(input())
    S = input()
    count = 0
    roomNum = 1
    alpha = [0] * 26
    for (i, s) in enumerate(S):
        if roomNum == N:
            break
        if i % 2 == 0:
            alpha[ord(s)-ord('a')] += 1
        else:
            if alpha[ord(s.lower())-ord('a')] == 0:
                count += 1
            else:
                alpha[ord(s.lower())-ord('a')] -= 1
            roomNum += 1
    print(count)



def __starting_point():
    main()

__starting_point()

n = int(input())
string = input()
ans = 0
current = [0 for i in range (26)]
for i in range(0, len(string)):
    if i % 2 == 0:
        current[ord(string[i]) - 97] += 1
    else:
        if current[ord(string[i]) + 32 - 97] != 0:
            current[ord(string[i]) + 32 - 97] -= 1
        else:
            ans += 1
print (ans)

n = int(input())-1
s = input()

ans = 0
keys = {}
for i in range(n):
    nkey = s[2*i]
    if nkey in keys:
        keys[nkey] += 1
    else:
        keys[nkey] = 1
    ndor = s[2*i+1].lower()

    if ndor in keys:
        keys[ndor] -=1
        if keys[ndor] == 0:
            del keys[ndor]
    else:
        ans += 1
print(ans)


n = int(input())
s = input().upper()
a = [0] * 26
u = 0
for i in range(len(s)):
    if i % 2 == 0:
        a[ord(s[i]) - ord('A')] += 1
    else:
        if a[ord(s[i]) - ord('A')] > 0:
            a[ord(s[i]) - ord('A')] -= 1
        else:
            u += 1
print(u)



import sys
n=int(sys.stdin.readline())
s=list(sys.stdin.readline())
s=s[:-1]
r=0
k=[0]*26
o=[0]*26
j=0

for i in s:
  if j%2==0:
    k[ord(i)-97]=k[ord(i)-97]+1
  else:
    if k[ord(i)-65]>0:  k[ord(i)-65]=k[ord(i)-65]-1
    else:  r=r+1
  j=j+1
print(r)

size = int(input()) - 1
string = input()
keys = [string[2 * i] for i in range(size)]
rooms = [string[2 * i + 1] for i in range(size)]

must_buy = 0
key_count = [0 for i in range(26)]
for i in range(size):
    key_count[ord(keys[i]) - ord('a')] += 1
    key_count[ord(rooms[i]) - ord('A')] -= 1
    if key_count[ord(rooms[i]) - ord('A')] < 0:
        key_count[ord(rooms[i]) - ord('A')] += 1
        must_buy += 1

print(must_buy)


from collections import Counter

n = int(input())
s = input()
keys = Counter()
need = 0
for i in range(0, n*2-2, 2):
    keys[s[i]] += 1
    neededkey = s[i+1].lower()
    if keys[neededkey]:
        keys[neededkey] -= 1
    else:
        need += 1
print(need)