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: EASY
Tags: String algorithms

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
import string
n = int(input())
s = input()
ans = 0
c = dict()
for i in string.ascii_lowercase:
	c[i] = 0
for i in range(0, len(s), 2):
	if ord(s[i]) - ord('a') != ord(s[i + 1]) - ord('A'):
		c[s[i]] += 1
		if c[s[i + 1].lower()] > 0:
			c[s[i + 1].lower()] -= 1
		else:
			ans += 1
print(ans)


from collections import Counter
input()
c = Counter()
ans = 0
for i in input():
	if i.islower():
		c[i] += 1
	else:
		i = i.lower()
		if not c[i]:
			ans += 1
		else:
			c[i] -= 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
	elif 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)


input()
s = input()
d = {}
key = 0
for i in range(len(s)):
	if i % 2 != 0:
		if s[i].lower() in d and d[s[i].lower()] > 0:
			d[s[i].lower()] -= 1
		else:
			key += 1
	elif s[i] in d:
		d[s[i]] += 1
	else:
		d[s[i]] = 1
print(key)


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)
main()


n = int(input())
s = input()
keys = ''
tobuy = 0
i = 0
while True:
	keys += s[i].upper()
	z = keys.find(s[i + 1])
	if z == -1:
		tobuy += 1
	else:
		keys = keys[:z] + keys[z + 1:]
	i += 2
	if i == len(s):
		break
print(tobuy)


def main():
	n = int(input())
	a = input()
	d = [0] * 26
	count = 0
	for i in range(0, 2 * n - 2, 2):
		d[ord(a[i]) - ord('a')] += 1
		if d[ord(a[i + 1]) - ord('A')] > 0:
			d[ord(a[i + 1]) - ord('A')] -= 1
		else:
			count += 1
	print(count)
main()


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
import itertools

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def solution():
	n = Int()
	a = Str()
	m = len(a)
	k = Hash()
	i = 0
	count = 0
	while i < m:
		x = a[i].lower()
		if i % 2 == 0:
			if x in k:
				k[x] += 1
			else:
				k[x] = 1
		elif x in k:
			if k[x] > 0:
				k[x] = k[x] - 1
			else:
				count += 1
		else:
			count += 1
		i += 1
	print(count)
solution()


import string
n = int(input())
path = input()
keys = dict()
count = 0
for i in string.ascii_lowercase:
	keys[i] = 0
for c in path:
	if c.lower() == c:
		keys[c] = keys[c] + 1
	elif keys[c.lower()] > 0:
		keys[c.lower()] = keys[c.lower()] - 1
	else:
		count = count + 1
print(count)


input()
t = input()
keys = t[0::2]
rooms = t[1::2].lower()
keyDict = dict()
count = 0
for (k, r) in zip(keys, rooms):
	keyDict[k] = keyDict.get(k, 0) + 1
	if r in keyDict and keyDict[r] >= 1:
		keyDict[r] -= 1
	else:
		count += 1
print(count)


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
	elif f(c) in d:
		if d[f(c)] > 0:
			d[f(c)] -= 1
		else:
			sum1 += 1
	else:
		sum1 += 1
print(sum1)


n = int(input())
s = input()
cnt = [0] * 300
ans = 0
for i in range(2 * n - 2):
	if i % 2 == 0:
		cnt[ord(s[i])] += 1
	elif cnt[ord(s[i].lower())] == 0:
		ans += 1
	else:
		cnt[ord(s[i].lower())] -= 1
print(ans)


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import combinations, permutations
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
s = ip()
n = n * 2 - 2
c = 0
arr = defaultdict(lambda : 0)
for i in range(n):
	if i % 2 == 0:
		arr[s[i].upper()] += 1
	elif arr[s[i]]:
		arr[s[i]] -= 1
	else:
		c += 1
print(c)


n = int(input())
s = input()
n = 2 * n - 2
count = 0
d = dict()
for i in range(n):
	if i % 2 == 0:
		if d.get(s[i]) is None:
			d[s[i]] = 1
		else:
			d[s[i]] += 1
	elif d.get(s[i].lower()) is None or d.get(s[i].lower()) == 0:
		count += 1
	else:
		d[s[i].lower()] -= 1
print(count)


trash = int(input())
house = str(input())
keys = {}
score = 0
for i in range(0, len(house)):
	if i % 2 == 0:
		if house[i] in keys:
			keys[house[i]] += 1
		else:
			keys[house[i]] = 1
	elif house[i].lower() in keys and keys[house[i].lower()] > 0:
		keys[house[i].lower()] -= 1
	else:
		score += 1
print(score)


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()


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)


n = int(input())
s = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
c = 0
d = {}
for letra in abc:
	d[letra] = 0
for i in range(len(s)):
	if i % 2 == 0:
		d[s[i]] += 1
	else:
		h = s[i].lower()
		if d[h] != 0:
			d[h] -= 1
		else:
			c += 1
print(c)


def main():
	input()
	s = input()
	(l, lmax) = ([0] * 26, [0] * 26)
	for (a, b) in zip(s[::2], s[1::2]):
		l[ord(a) - 97] -= 1
		x = ord(b) - 65
		l[x] = y = l[x] + 1
		if lmax[x] < y:
			lmax[x] = y
	print(sum((x for x in lmax if x > 0)))
main()


import sys
import math
n = int(input())
st = input()
v = [0] * 26
res = 0
for i in range((n - 1) * 2):
	if i % 2 == 0:
		v[ord(st[i]) - ord('a')] += 1
	else:
		k = ord(st[i].lower()) - ord('a')
		if v[k] > 0:
			v[k] -= 1
		else:
			res += 1
print(res)


n = input()
s = [i for i in input()]
it = 0
result = 0
d = {}
for i in s:
	if it % 2 == 0:
		if i in d:
			d[i] = d[i] + 1
		else:
			d[i] = 1
	elif i.lower() in d:
		if d[i.lower()] > 0:
			d[i.lower()] -= 1
		else:
			result += 1
	else:
		result += 1
	it += 1
print(result)


__author__ = 'artyom'

def main():
	n = read()
	s = list(map(ord, list(read(0))))
	b = [0] * (ord('z') + 1)
	for i in range(0, 2 * n - 2, 2):
		t = s[i + 1] + 32
		if s[i] != t:
			b[s[i]] += 1
			if b[t]:
				b[t] -= 1
	return sum(b)

def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return int(inputs)
	if mode == 3:
		return list(map(int, inputs.split()))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
write(main())


n = int(input())
string = input()
listkeys = [0] * 26
count = 0
q = 2 * n - 2
for i in range(0, q):
	if i % 2 == 0:
		k = ord(string[i])
		k2 = k - 97
		listkeys[k2] = listkeys[k2] + 1
	else:
		k3 = ord(string[i])
		k4 = k3 + 32
		if listkeys[k4 - 97] >= 1:
			listkeys[k4 - 97] = listkeys[k4 - 97] - 1
		else:
			count = count + 1
print(count)


n = int(input())
l_c = input()
t = 0
d_k = {}
for i in range(n * 2 - 2):
	if i % 2 == 0:
		if l_c[i] not in d_k:
			d_k[l_c[i]] = 1
		else:
			d_k[l_c[i]] += 1
	elif l_c[i].lower() in d_k and d_k[l_c[i].lower()] > 0:
		d_k[l_c[i].lower()] -= 1
	else:
		t += 1
print(t)


import collections

def main():
	(first, second) = (int(input()), input())
	keys = collections.defaultdict()
	k = 0
	for i in second:
		if i == i.lower():
			if i in keys.keys():
				keys[i] += 1
			else:
				keys[i] = 1
		elif i.lower() not in keys.keys():
			k += 1
		else:
			keys[i.lower()] -= 1
			if keys[i.lower()] == 0:
				del keys[i.lower()]
	print(k)
main()


n = int(input())
s = input()
d = {}
m = len(s)
c = 0
for x in range(m):
	if x % 2 == 0:
		if s[x] not in d:
			d[s[x]] = 1
		else:
			d[s[x]] += 1
	else:
		val = ord(s[x]) ^ 32
		val = chr(val)
		if val not in d:
			c = c + 1
		elif d[val] == 0:
			c = c + 1
		else:
			d[val] -= 1
print(c)


import string
n = int(input())
s = input().lower()
key = [0] * 26
count = 0
i = 0
while i < len(s):
	key[string.ascii_lowercase.index(s[i])] += 1
	if key[string.ascii_lowercase.index(s[i + 1])] > 0:
		key[string.ascii_lowercase.index(s[i + 1])] -= 1
	else:
		count += 1
	i += 2
print(count)


import sys
import math
import bisect

def main():
	n = int(input())
	s = input()
	ans = 0
	d = dict()
	for ch in s:
		if ch.islower():
			if ch not in d:
				d[ch] = 0
			d[ch] += 1
		else:
			ch = ch.lower()
			if ch not in d:
				d[ch] = 0
			if d[ch] == 0:
				ans += 1
			else:
				d[ch] -= 1
	print(ans)
main()


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
	elif not key[i.lower()]:
		t += 1
	else:
		key[i.lower()] -= 1
print(t)


n = int(input())
s = input()
ans = 0
key = {}
for i in range(26):
	key[chr(ord('a') + i)] = 0
for i in range(2 * n - 2):
	if s[i].islower():
		key[s[i]] += 1
	elif key[s[i].lower()] <= 0:
		ans += 1
	else:
		key[s[i].lower()] -= 1
print(ans)


n = input().split()
n = int(n[0])
s = input()
keys = dict()
val = 0
for i in range(1, int(len(s) / 2) + 1):
	a = s[i * 2 - 2]
	b = s[i * 2 - 1].lower()
	if keys.get(a) == None:
		keys[a] = 1
	else:
		keys[a] += 1
	if keys.get(b) != None:
		if keys[b] > 0:
			keys[b] -= 1
		else:
			val += 1
	else:
		val += 1
print(val)


n = int(input())
s = input()
s = list(s)
r = []
for i in range(len(s)):
	s[i] = ord(s[i])
c = 0
for i in range(len(s)):
	if 97 <= s[i] <= 122:
		r.append(s[i])
	elif s[i] + 32 in r:
		r.remove(s[i] + 32)
	else:
		c = c + 1
print(c)


from collections import defaultdict
d = defaultdict(int)
input()
sum_v = 0
for (i, x) in enumerate(input()):
	if i % 2 == 0:
		d[x] += 1
	elif d[x.lower()] == 0:
		sum_v += 1
	else:
		d[x.lower()] -= 1
print(sum_v)


d = {}
x = input()
x = input()
o = 0
for (i, c) in enumerate(x):
	if i % 2:
		r = d.get(c, 0)
		if not r:
			o += 1
		else:
			d[c] = r - 1
	else:
		r = d.get(c.upper(), 0)
		d[c.upper()] = r + 1
print(o)


from collections import Counter as c
from string import ascii_lowercase as l
input()
a = input()
b = c()
d = 0
for i in a:
	if i in l:
		b[i] += 1
	elif b[i.lower()]:
		b[i.lower()] -= 1
	else:
		d += 1
print(d)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = input()
d = {}
c = 0
for i in range(2 * n - 2):
	if l[i].islower():
		d[l[i]] = d.get(l[i], 0) + 1
	elif not d.get(l[i].lower(), 0):
		c += 1
		d[l[i].lower()] = 0
	else:
		d[l[i].lower()] -= 1
print(c)


n = int(input())
s = input()
d = {}
res = 0
for data in s:
	if data.islower():
		d[data] = d.get(data, 0) + 1
	elif d.get(data.lower(), 0) > 0:
		d[data.lower()] = d[data.lower()] - 1
	else:
		res += 1
print(res)


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 = list(input().lower())
d = {}
ans = 0
for i in range(2 * n - 2):
	if i % 2 == 0:
		d[s[i]] = d.get(s[i], 0) + 1
	elif d.get(s[i], 0):
		d[s[i]] -= 1
	else:
		ans += 1
print(ans)


n = int(input())
s = input()
ans = 0
from collections import defaultdict
keys = defaultdict(int)
for (key, door) in zip(s[0::2], s[1::2]):
	keys[key.upper()] += 1
	if keys[door] > 0:
		keys[door] -= 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 = str(input())
l = [0] * 26
c = 0
for i in range(0, len(s), 2):
	if s[i].upper() != s[i + 1]:
		l[ord(s[i]) - 97] += 1
		if l[ord(s[i + 1].lower()) - 97] > 0:
			l[ord(s[i + 1].lower()) - 97] -= 1
		else:
			c += 1
print(c)


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
s1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
s2 = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(1):
	n = inin()
	ans = 0
	s = sin().strip()
	d = dd(int)
	for i in range(0, len(s), 2):
		if ord(s[i]) - ord('a') == ord(s[i + 1]) - ord('A'):
			continue
		elif ord(s[i]) - ord('A') == ord(s[i + 1]) - ord('a'):
			continue
		elif s[i + 1] in s1 and d[s2[ord(s[i + 1]) - ord('A')]] != 0:
			d[s2[ord(s[i + 1]) - ord('A')]] -= 1
			d[s[i]] += 1
			continue
		elif s[i + 1] in s2 and d[s1[ord(s[i + 1]) - ord('a')]] != 0:
			d[s1[ord(s[i + 1]) - ord('a')]] -= 1
			d[s[i]] += 1
			continue
		else:
			ans += 1
			d[s[i]] += 1
	print(ans)


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


from collections import defaultdict
n = int(input())
try:
	while True:
		s = input()
		if len(s) > 0:
			continue
		else:
			break
except EOFError:
	pass
d = defaultdict(int)
ans = 0
for i in s:
	if i >= 'A' and i <= 'Z':
		if d[i.lower()] > 0:
			d[i.lower()] -= 1
		else:
			ans += 1
	if i >= 'a' and i <= 'z':
		d[i] += 1
print(ans)


n = int(input())
input_string = input()
map = {}
map_string = 'abcdefghijklmnopqrstuvwxyz'
cost = 0
for i in range(0, len(map_string)):
	map[map_string[i]] = 0
for i in range(0, len(input_string)):
	if i % 2 == 0:
		map[input_string[i]] += 1
	else:
		lower = chr(ord(input_string[i]) + 32)
		if map[lower] > 0:
			map[lower] -= 1
		else:
			cost += 1
print(cost)


def getInput():
	n = int(input())
	carte = list(input())
	return (n, carte)

def solve(n, chaine):
	s = 0
	cle = []
	porte = []
	for i in range(26):
		cle.append(0)
		porte.append(0)
	for i in range(2 * n - 2):
		if chaine[i] < 'a':
			porte[ord(carte[i]) - 65] += 1
			j = ord(carte[i]) - 65
		else:
			cle[ord(carte[i]) - 97] += 1
			continue
		if porte[j] > cle[j]:
			s += porte[j] - cle[j]
			porte[j] = 0
			cle[j] = 0
		else:
			cle[j] -= porte[j]
			porte[j] = 0
	return s
(n, carte) = getInput()
print(solve(n, carte))


n = int(input())
a = input()
keys = 0
store = [0] * 26
for i in range(2 * n - 2):
	if i % 2 == 0:
		store[ord(a[i]) - ord('a')] += 1
	elif store[ord(a[i]) - ord('A')] == 0:
		keys += 1
	else:
		store[ord(a[i]) - ord('A')] -= 1
print(keys)


R = lambda : list(map(int, input().split()))
n = int(input())
s = input()
b = {}
c = 0
for x in s:
	if 'a' <= x <= 'z':
		if x in b:
			b[x] += 1
		else:
			b[x] = 1
	else:
		x = x.lower()
		if x in b:
			if b[x] > 0:
				b[x] -= 1
			else:
				c += 1
		else:
			c += 1
print(c)


n = int(input())
way = input()
keys = [0] * 26
res = 0
for i in range(n - 1):
	keys[ord(way[2 * i]) - 97] += 1
	if keys[ord(way[2 * i + 1]) - 65] == 0:
		res += 1
	else:
		keys[ord(way[2 * i + 1]) - 65] -= 1
print(res)


input()
s = input().lower()
keys = {}
neededKeyNum = 0
for i in range(0, len(s), 2):
	if s[i] not in keys:
		keys[s[i]] = 1
	else:
		keys[s[i]] += 1
	if s[i + 1] in keys and keys[s[i + 1]] > 0:
		keys[s[i + 1]] -= 1
	else:
		neededKeyNum += 1
print(neededKeyNum)


n = input()
s = input()
count = 1
key = 0
a = [0 for i in range(0, 27)]
for i in s:
	if count % 2 == 1:
		a[ord(i) - ord('a')] += 1
	elif a[ord(i) - ord('A')] != 0:
		a[ord(i) - ord('A')] -= 1
	else:
		key += 1
	count += 1
print(key)


n = int(input())
mass = str(input())
d = {}
keys = ''.join(list(filter(lambda c: c.islower(), mass)))
doors = ''.join(list(filter(lambda c: not c.islower(), mass)))
doors = doors.lower()
count = 0
for i in range(n - 1):
	if keys[i] in d.keys():
		d[keys[i]] += 1
	else:
		d[keys[i]] = 1
	if doors[i] in d.keys():
		if d[doors[i]] > 0:
			d[doors[i]] -= 1
			continue
		else:
			count += 1
	else:
		count += 1
print(count)


n = int(input())
doors = input()
charList = [0] * 26
res = 0
for char in doors:
	if char.islower():
		charList[ord(char) - ord('a')] += 1
	elif charList[ord(char) - ord('A')] == 0:
		res += 1
	else:
		charList[ord(char) - ord('A')] -= 1
print(res)


n = int(input())
z = input()
arr = [0] * 300
count = 0
for i in range(0, len(z), 2):
	if z[i] == z[i + 1].lower():
		continue
	elif arr[ord(z[i + 1].lower())] > 0:
		arr[ord(z[i + 1].lower())] -= 1
		arr[ord(z[i])] += 1
	else:
		count += 1
		arr[ord(z[i])] += 1
print(count)


n = int(input())
d = {}
s = input()
key = 0
for i in range(n * 2 - 2):
	if i % 2 != 0:
		try:
			if d[s[i].lower()] <= 0:
				key += 1
			else:
				d[s[i].lower()] -= 1
		except:
			key += 1
			d[s[i].lower()] = 0
	else:
		try:
			d[s[i]] += 1
		except:
			d[s[i]] = 1
print(key)


from collections import defaultdict
(MyDict, Check, Count) = (defaultdict(int), False, 0)
input()
for i in input():
	if Check and (i.lower() not in MyDict or MyDict[i.lower()] == 0):
		Count += 1
	elif Check and i.lower() in MyDict:
		MyDict[i.lower()] -= 1
	else:
		MyDict[i] += 1
	Check = not Check
print(Count)


n = int(input())
s = input()
count = 0
dic = {}
s = s.lower()
for i in range(0, len(s)):
	if i % 2 == 0:
		dic.setdefault(s[i], 0)
		dic[s[i]] = dic[s[i]] + 1
	elif s[i] not in dic:
		count += 1
	elif s[i] in dic:
		if dic[s[i]] > 0:
			dic[s[i]] = dic[s[i]] - 1
		elif dic[s[i]] == 0:
			count += 1
print(count)


n = int(input())
slst = [0 for i in range(26)]
s = input('')
count = 0
for i in s:
	if ord(i) >= 97 and ord(i) <= 122:
		slst[ord(i) - 97] += 1
	else:
		x = slst[ord(i) - 65]
		if x > 0:
			slst[ord(i) - 65] -= 1
		else:
			count += 1
print(count)


n = int(input())
a = input()
ans = 0
d = dict()
for i in range(2 * n - 2):
	if i % 2 == 0:
		try:
			d[chr(ord(a[i]) - 32)] += 1
		except:
			d[chr(ord(a[i]) - 32)] = 1
	elif i % 2 == 1:
		try:
			if d[a[i]] > 0:
				d[a[i]] -= 1
			else:
				ans += 1
		except:
			ans += 1
print(ans)


from collections import defaultdict

def input_ints():
	return list(map(int, input().split()))

def solve():
	input()
	s = input()
	d = defaultdict(int)
	ans = 0
	for c in s:
		if c.isupper():
			if d[c]:
				d[c] -= 1
			else:
				ans += 1
		else:
			d[c.upper()] += 1
	print(ans)
solve()


from collections import Counter
n = int(input())
s = input()
keys = Counter()
to_buy = 0
for i in range(n - 1):
	keys[s[2 * i]] += 1
	door = s[2 * i + 1].lower()
	if keys[door] > 0:
		keys[door] -= 1
	else:
		to_buy += 1
print(to_buy)


n = int(input())
s = input()
d = {}
ans = 0
for i in range(len(s)):
	if not i & 1:
		cur = s[i].upper()
		if cur in d:
			d[cur] += 1
		else:
			d[cur] = 1
	elif s[i] in d:
		d[s[i]] -= 1
		if d[s[i]] == 0:
			d.pop(s[i])
	else:
		ans += 1
print(ans)


n = int(input())
s = input().lower()
res = 0
d = {}
for i in range(len(s)):
	if i % 2 == 0:
		d[s[i]] = d.get(s[i], 0) + 1
	elif d.get(s[i], 0) > 0:
		d[s[i]] -= 1
	else:
		res += 1
print(res)


n = int(input())
s = input()
s = list(s)
k = [0] * 26
count = 0
for i in range(0, len(s) // 2):
	p = s[i * 2]
	q = s[i * 2 + 1]
	k[ord(p) - 97] += 1
	if k[ord(q) - 65] > 0:
		k[ord(q) - 65] -= 1
	else:
		count += 1
print(count)


n = int(input())
s = input()
qtyKeys = {}
answer = 0
for i in range(0, (n - 1) * 2, 2):
	if s[i] != s[i + 1].lower():
		answer += 1
		qtyKeys[s[i]] = qtyKeys.get(s[i], 0) + 1
		if s[i + 1].lower() in qtyKeys and qtyKeys[s[i + 1].lower()] > 0:
			answer -= 1
			qtyKeys[s[i + 1].lower()] = qtyKeys.get(s[i + 1].lower(), 0) - 1
print(answer)


n = int(input())
g = input()
count = 0
d = {}
for i in range(26):
	d[chr(97 + i)] = 0
for i in range(n - 1):
	d[g[2 * i]] += 1
	if d[chr(ord(g[2 * i + 1]) + 32)] == 0:
		count += 1
	else:
		d[chr(ord(g[2 * i + 1]) + 32)] -= 1
print(count)


(n, s) = (int(input()), input())
(cnt, a) = (0, [0] * 26)
for i in range(len(s)):
	if i & 1:
		if a[ord(s[i]) - ord('A')] == 0:
			a[ord(s[i]) - ord('A')] += 1
			cnt += 1
		a[ord(s[i]) - ord('A')] -= 1
	else:
		a[ord(s[i]) - ord('a')] += 1
print(cnt)


import math
from collections import defaultdict
n = int(input())
x = input()
keys = defaultdict(lambda : 0)
ans = 0
for i in x:
	if i.islower():
		keys[i] += 1
	elif keys[i.lower()] == 0:
		ans += 1
	else:
		keys[i.lower()] -= 1
print(ans)


def sol(n, s):
	dic = {}
	req = 0
	for e in range(0, len(s) - 1, 2):
		door = s[e + 1].lower()
		if s[e] == door:
			continue
		else:
			temp = dic.get(door, 0)
			if temp == 0:
				req += 1
			else:
				dic[door] -= 1
			a = dic.get(s[e], 0)
			dic[s[e]] = a + 1
	return req
n = int(input())
s = input()
print(sol(n, s))


n = int(input())
s = input()
D = dict()
D_mins = dict()
for i in range(len(s)):
	if i % 2 == 0:
		if s[i] in D:
			D[s[i]] += 1
		else:
			D[s[i]] = 1
		if s[i] in D_mins:
			D_mins[s[i]] = min(D_mins[s[i]], D[s[i]])
		else:
			D_mins[s[i]] = 1
	else:
		key = s[i].lower()
		if key in D:
			D[key] -= 1
		else:
			D[key] = -1
		if key in D_mins:
			D_mins[key] = min(D_mins[key], D[key])
		else:
			D_mins[key] = -1
key_to_buy = 0
for elem in D_mins.values():
	if elem < 0:
		key_to_buy += elem
print(-key_to_buy)


def check(alpha, val):
	for i in range(len(alpha)):
		if alpha[i] == val:
			return i
	return -1
dic = {'q': 0, 'w': 0, 'e': 0, 'r': 0, 't': 0, 'y': 0, 'u': 0, 'i': 0, 'o': 0, 'p': 0, 'l': 0, 'k': 0, 'j': 0, 'h': 0, 'g': 0, 'f': 0, 'd': 0, 's': 0, 'a': 0, 'z': 0, 'x': 0, 'c': 0, 'v': 0, 'b': 0, 'n': 0, 'm': 0}
n = int(input())
strin = input()
string = list(strin)
count = 0
for i in range(0, len(string)):
	if i % 2 == 0:
		dic[string[i]] += 1
	elif dic[chr(ord(string[i]) + 32)] != 0:
		dic[chr(ord(string[i]) + 32)] -= 1
	else:
		count += 1
print(count)


n = int(input())
s = list(input().lower())
sz = len(s)
cnt = [0] * 255
ans = 0
for i in range(0, sz, 2):
	cnt[ord(s[i])] += 1
	if cnt[ord(s[i + 1])] > 0:
		cnt[ord(s[i + 1])] -= 1
	else:
		ans += 1
print(ans)


import os
import sys
from math import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def array():
	return [int(i) for i in input().split()]
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = 2 * n - 2
s = input()
key = []
door = set()
d = {}
c = 0
for i in range(0, l, 2):
	try:
		d[s[i]] += 1
	except:
		d[s[i]] = 1
	if s[i + 1].lower() in d.keys() and d[s[i + 1].lower()] > 0:
		d[s[i + 1].lower()] -= 1
		c += 1
print(n - 1 - c)


from sys import stdin, stdout
from collections import defaultdict

def main():
	n = int(stdin.readline())
	s = stdin.readline().split('\n')[0]
	d = defaultdict(int)
	reqd = 0
	for i in range(1, len(s), 2):
		key_needed = s[i].lower()
		cur_key = s[i - 1]
		if cur_key == key_needed:
			continue
		elif cur_key != key_needed and key_needed not in d:
			reqd += 1
			d[cur_key] += 1
		else:
			d[cur_key] += 1
			d[key_needed] -= 1
			if d[key_needed] == 0:
				del d[key_needed]
	stdout.write('{}\n'.format(reqd))
main()


n = int(input())
s = input()
ans = 0
keys = {k: 0 for k in 'abcdefghijklmnopqrstuvwxyz'}
for k in s:
	if k.islower():
		keys[k] += 1
	else:
		k = k.lower()
		if keys[k]:
			keys[k] -= 1
		else:
			ans += 1
print(ans)


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
n = ii1()
s = is1()
keys = {}
res = 0
for (ind, j) in enumerate(s):
	if (ind + 1) % 2 != 0:
		keys.setdefault(j.upper(), [0])[0] += 1
	elif j not in keys or keys[j][0] <= 0:
		res += 1
	else:
		keys[j][0] -= 1
print(res)


room = int(input())
desc = input()
keys = desc[0::2]
way = desc[1::2].lower()
keys_on_hands = ''
keys_to_buy = 0
for i in range(len(way)):
	keys_on_hands += keys[i]
	pos = keys_on_hands.find(way[i])
	if pos == -1:
		keys_to_buy += 1
	else:
		keys_on_hands = keys_on_hands[:pos] + keys_on_hands[pos + 1:]
print(keys_to_buy)


n = int(input())
s = input()
l = [0] * 26
c = 0
for i in s:
	if i.islower():
		l[ord(i) - ord('a')] += 1
	elif l[ord(i) - ord('A')] == 0:
		c += 1
	else:
		l[ord(i) - ord('A')] -= 1
print(c)


n = int(input())
s = input()
d = {}
c = 0
for i in range(2 * n - 2):
	if i % 2 == 0:
		if s[i] not in d:
			d[s[i]] = 1
		else:
			d[s[i]] += 1
	else:
		k = chr(ord(s[i]) + 32)
		if k in d:
			if d[k] > 0:
				d[k] -= 1
			else:
				c += 1
		else:
			c += 1
print(c)


from collections import Counter
n = int(input())
seq = input()
ans = 0
seen = Counter()
for e in seq:
	if e.islower():
		seen[e] += 1
	elif seen[e.lower()] == 0:
		ans += 1
	else:
		seen[e.lower()] -= 1
print(ans)


from collections import defaultdict
input()
(s, keys, n) = (input().lower(), defaultdict(int), 0)
for (i, door) in zip(s[::2], s[1::2]):
	keys[i] += 1
	if keys[door]:
		keys[door] -= 1
	else:
		n += 1
print(n)


n = int(input())
s = input()
al = [0] * 26
ans = 0
for i in range(0, len(s), 2):
	if s[i] != s[i + 1]:
		j = ord(s[i + 1].lower()) - ord('a')
		al[ord(s[i]) - ord('a')] += 1
		if al[j] > 0:
			al[j] -= 1
		else:
			ans += 1
print(ans)


n = int(input())
s = input()
cnt = 0
i = 0
key = [0] * 256
while i < len(s):
	key[ord(s[i])] += 1
	if key[ord(s[i + 1].lower())] == 0:
		cnt += 1
	else:
		key[ord(s[i + 1].lower())] -= 1
	i += 2
print(cnt)


from collections import defaultdict
n = int(input())
s = input()
count = 0
d = defaultdict(int)
for i in range(1, len(s), 2):
	if s[i].lower() == s[i - 1]:
		continue
	elif s[i].lower() in d:
		d[s[i].lower()] -= 1
		if d[s[i].lower()] == 0:
			d.pop(s[i].lower())
		d[s[i - 1]] += 1
	else:
		d[s[i - 1]] += 1
		count += 1
print(count)


n = int(input())
s = input()
li1 = []
li2 = []
li3 = [0] * 26
cn = 0
bl_falan = 0
for i in s:
	if i >= 'A' and i <= 'Z':
		li1.append(i)
	else:
		li2.append(i)
for i in range(n - 1):
	if li1[i].lower() == li2[i]:
		bl_falan = 1
	else:
		ab = li1[i].lower()
		li3[ord(li2[i]) - ord('a')] += 1
		if li3[ord(ab) - ord('a')] == 0:
			cn += 1
		else:
			li3[ord(ab) - ord('a')] -= 1
print(cn)


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 = list(input())
has = [0] * 200
ans = 0
for i in range(2 * n - 2):
	if s[i] >= 'A' and s[i] <= 'Z':
		if has[ord(s[i]) + 32]:
			has[ord(s[i]) + 32] -= 1
		else:
			ans += 1
	else:
		has[ord(s[i])] += 1
print(ans)


n = int(input())
a = input()
dic = {}
tobuy = 0
for i in range((n - 1) * 2):
	if i % 2 == 0:
		ch = a[i]
		dic[ch] = dic.get(ch, 0) + 1
	else:
		ch = a[i].lower()
		if ch in dic and dic[ch] > 0:
			dic[ch] = dic[ch] - 1
		else:
			tobuy = tobuy + 1
print(tobuy)


count = int(input())
string = input()
answer = 0
keyMap = {}
for value in string:
	if value.islower():
		keyMap[value] = keyMap.get(value, 0) + 1
	elif keyMap.get(value.lower(), 0) > 0:
		keyMap[value.lower()] = keyMap.get(value.lower(), 0) - 1
	else:
		answer += 1
print(answer)


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
	elif ord(s[i]) + 32 in ers and er[ord(s[i]) + 32] >= 1:
		er[ord(s[i]) + 32] -= 1
	else:
		cnt += 1
print(cnt)


n = int(input())
string = list(input())
keys = {}
res = 0
for i in range(0, 2 * n - 2, 2):
	k = chr(ord(string[i + 1]) + 32)
	if k != string[i]:
		if keys.get(k) != None and keys[k] != 0:
			keys[k] -= 1
		else:
			res += 1
		if keys.get(string[i]) == None:
			keys[string[i]] = 1
		else:
			keys[string[i]] += 1
print(res)


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)


read = lambda : map(int, input().split())
n = int(input()) - 1
s = input()
low = lambda c: chr(ord(c) + ord('a') - ord('A'))
cnt = 0
f = [0] * 300
for i in range(n * 2):
	if i % 2:
		c = ord(low(s[i]))
		if f[c] == 0:
			cnt += 1
		else:
			f[c] -= 1
	else:
		c = ord(s[i])
		f[c] += 1
print(cnt)


from collections import defaultdict
nDoors = int(input())
pairs = input()
keys = {}
answer = 0
keys = defaultdict(lambda : 0, keys)
for x in range(0, 2 * nDoors - 2, 2):
	keys[pairs[x]] += 1
	if keys[pairs[x + 1].lower()] > 0:
		keys[pairs[x + 1].lower()] -= 1
	else:
		answer += 1
print(answer)


from collections import Counter
n = int(input())
x = input()
c = 0
cnt = Counter()
for i in x:
	if i.islower():
		cnt[chr(ord(i) - 32)] += 1
	elif cnt[i] == 0:
		c += 1
	else:
		cnt[i] -= 1
print(c)


n = int(input())
s = input()
count = {}
key = 0
for i in s:
	if i.islower():
		if i in count:
			count[i] += 1
		else:
			count[i] = 1
	elif i.lower() in count and count[i.lower()] > 0:
		count[i.lower()] -= 1
	else:
		key += 1
print(key)


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()


n = int(input())
s = input()
d = {}
count = 0
for i in range(0, 2 * n - 2, 2):
	key = s[i]
	door = s[i + 1]
	if key != door.lower():
		if d.get(door.lower(), 0):
			d[door.lower()] -= 1
		else:
			count += 1
		if d.get(key, 0):
			d[key] += 1
		else:
			d[key] = 1
print(count)


from collections import Counter
n = int(input())
s = input()
c = Counter()
m = 0
for (x, y) in zip(s[::2], s[1::2]):
	c[x] += 1
	y = y.lower()
	if c[y] > 0:
		c[y] -= 1
	else:
		m += 1
print(m)


n = int(input())
string = input()
mydict = dict()
l = 2 * n - 2
total = 0
for i in range(l):
	if i % 2 == 0:
		mydict[string[i]] = mydict.get(string[i], 0) + 1
	else:
		x = chr(ord(string[i]) + 32)
		if x not in mydict:
			total += 1
		elif mydict[x] > 1:
			mydict[x] -= 1
		elif mydict[x] == 1:
			del mydict[x]
print(total)


n = 2 * (int(input()) - 1)
s = input()
count = 0
i = 0
k = dict()
while i < n:
	x = s[i].lower()
	if i % 2 == 1:
		if x in k:
			if k[x] > 0:
				k[x] -= 1
			else:
				count += 1
		else:
			count += 1
	elif x in k:
		k[x] += 1
	else:
		k[x] = 1
	i += 1
print(count)


n = int(input())
s = input()
keys = [0 for i in range(26)]
ans = 0
for i in range(len(s)):
	if 'A' <= s[i] <= 'Z':
		if keys[ord(s[i]) - ord('A')] > 0:
			keys[ord(s[i]) - ord('A')] -= 1
		else:
			ans += 1
	else:
		keys[ord(s[i]) - ord('a')] += 1
print(ans)


n = int(input())
s = input()
e = {}
cnt = 0
for i in range(len(s)):
	if s[i].isupper():
		if s[i] in e and e[s[i]] >= 1:
			e[s[i]] -= 1
		else:
			cnt += 1
	elif s[i].upper() in e:
		e[s[i].upper()] += 1
	else:
		e[s[i].upper()] = 1
print(cnt)


from collections import defaultdict
d = defaultdict(int)
c = 0
input()
for x in input():
	if x in 'abcdefghijklmnopqrstuvwxyz':
		d[x] += 1
	else:
		x = chr(ord(x) - ord('A') + ord('a'))
		d[x] -= 1
		if d[x] < 0:
			d[x] = 0
			c += 1
print(c)


n = int(input())
lista = input()
total = 0
keys = {}
for i in lista:
	if i in keys:
		keys[i] += 1
	elif i <= 'Z':
		if i.lower() in keys:
			if keys[i.lower()] > 0:
				keys[i.lower()] -= 1
			else:
				total += 1
		else:
			total += 1
	else:
		keys[i] = 1
print(total)


n = int(input()) - 1
k = [0] * 26
a = input()
for i in a:
	o = ord(i)
	if o >= 97:
		k[o - 97] += 1
	else:
		t = min(k[o - 65], 1)
		k[o - 65] -= t
		n -= t
print(n)


n = input()
s = input()
s = s.lower()
check = {}
count = 0
for i in range(0, len(s), 2):
	if s[i] != s[i + 1]:
		if s[i] in check:
			check[s[i]] += 1
		else:
			check[s[i]] = 1
		if s[i + 1] not in check:
			count += 1
			continue
		else:
			if check[s[i + 1]] >= 1:
				check[s[i + 1]] -= 1
			if check[s[i + 1]] == 0:
				del check[s[i + 1]]
print(count)


n = int(input())
(c, k, o) = (1, {}, 0)
for i in input():
	if c:
		k[i] = k.setdefault(i, 0) + 1
	else:
		i = i.lower()
		a = k.get(i)
		if a:
			k[i] -= 1
		else:
			o += 1
	c = 1 - c
print(o)


n = int(input())
string = input().lower()
ans = 0
keys = dict()
for i in range(-1, -2 * n + 1, -1):
	if i % 2 == 1:
		keys[string[i]] = keys.setdefault(string[i], 0) + 1
	elif keys.get(string[i], 0) < 1:
		keys[string[i]] = 0
	else:
		keys[string[i]] -= 1
for i in keys.values():
	if i > 0:
		ans += i
print(ans)


def p1():
	n = int(input())
	l = [int(i) for i in input().split()]
	l.sort()
	t = 0
	for i in range(1, n):
		if l[i] <= l[i - 1]:
			t += l[i - 1] - l[i] + 1
			l[i] = l[i - 1] + 1
	print(t)
n = int(input())
way = input()
keys = [0] * 26
res = 0
for i in range(n - 1):
	keys[ord(way[2 * i]) - 97] += 1
	if keys[ord(way[2 * i + 1]) - 65] == 0:
		res += 1
	else:
		keys[ord(way[2 * i + 1]) - 65] -= 1
print(res)


def diff(c):
	return ord(c) - ord('a')

def main():
	n = int(input())
	s = input()
	keysLeft = [0] * 26
	keysRequired = 0
	for i in range(0, 2 * n - 2, 2):
		if ord(s[i]) - ord(s[i + 1]) != 32:
			if keysLeft[diff(s[i + 1].lower())] == 0:
				keysRequired += 1
				keysLeft[diff(s[i])] += 1
			else:
				keysLeft[diff(s[i + 1].lower())] -= 1
				keysLeft[diff(s[i])] += 1
	print(keysRequired)
main()


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)


n = int(input())
s = input()
keys = {}
isKey = True
result = 0
for c in s:
	if isKey:
		char = c.upper()
		if char in keys:
			keys[char] += 1
		else:
			keys[char] = 1
	elif c in keys:
		keys[c] -= 1
		if keys[c] == 0:
			del keys[c]
	else:
		result += 1
	isKey = not isKey
print(result)


from collections import defaultdict
n = int(input())
s = input()
have = defaultdict(lambda : 0)
need = 0
for i in range(0, 2 * n - 2):
	if i % 2 == 1:
		continue
	have[s[i]] += 1
	nxt = s[i + 1].lower()
	if have[nxt] == 0:
		need += 1
	else:
		have[nxt] -= 1
print(need)


n = int(input())
s = input()
a = {}
cnt = 0
for i in range(1, len(s) + 1):
	if i % 2 == 1:
		if a.get(s[i - 1]) is None:
			a[s[i - 1]] = 1
		else:
			a[s[i - 1]] += 1
	elif a.get(s[i - 1].lower()) is None or a[s[i - 1].lower()] == 0:
		cnt += 1
	else:
		a[s[i - 1].lower()] -= 1
print(cnt)


from collections import Counter
n = int(input())
s = input()
k = s[::2]
d = s[1::2].lower()
cnt = Counter()
ans = 0
for i in range(n - 1):
	cnt[k[i]] += 1
	if cnt.get(d[i], 0):
		cnt[d[i]] -= 1
	else:
		ans += 1
print(ans)


n = int(input())
s = input()
keys = {}
count = 0
for i in range(0, len(s)):
	if i % 2 == 0:
		if keys.get(s[i]):
			keys[s[i]] += 1
		else:
			keys[s[i]] = 1
	elif keys.get(s[i].lower()):
		if keys[s[i].lower()] == 0:
			count += 1
		else:
			keys[s[i].lower()] -= 1
	else:
		count += 1
print(count)


import sys
filename = sys.argv[-1]
if filename == 'LOCAL':
	all = open(filename, 'r').readlines()
else:
	all = sys.stdin.readlines()
check = [0] * 255
ans = 0
for i in range(len(all[1])):
	if i % 2 == 0:
		check[ord(all[1][i]) - ord('a')] += 1
	elif check[ord(all[1][i]) - ord('A')] == 0:
		ans += 1
	else:
		check[ord(all[1][i]) - ord('A')] -= 1
print(ans)


N = int(input())
S = input()
keyd = {}
doord = {}
ans = 0
for i in range(0, 2 * N - 2, 2):
	key = S[i]
	door = S[i + 1]
	keyd[key] = keyd.get(key, 0) + 1
	if door.lower() in keyd.keys() and keyd[door.lower()] >= 1:
		keyd[door.lower()] -= 1
	else:
		ans += 1
print(ans)


from collections import defaultdict

def zero():
	return 0
n = int(input())
s = input()
n = 2 * n - 2
res = 0
d = defaultdict(zero)
for i in range(len(s)):
	if i % 2 == 0:
		d[s[i]] += 1
	else:
		f = s[i].lower()
		if d[f] > 0:
			d[f] -= 1
		else:
			res += 1
print(res)


from collections import defaultdict

def solve(n, string):
	left_key = defaultdict(int)
	count = 0
	for i in range(2, 2 * n, 2):
		key = string[i - 2].upper()
		if key != string[i - 1]:
			left_key[key] += 1
			if string[i - 1] in left_key and left_key[string[i - 1]] != 0:
				left_key[string[i - 1]] -= 1
			else:
				count += 1
	return count
n = int(input())
string = input()
result = solve(n, string)
print(result)


n = int(input())
key = {}
t = input()
u = 0
for k in range(len(t)):
	if 97 <= ord(t[k]) <= 122:
		if t[k] in key:
			key[t[k]] += 1
		else:
			key[t[k]] = 1
	elif chr(ord(t[k]) + 32) in key:
		if key[chr(ord(t[k]) + 32)] > 0:
			key[chr(ord(t[k]) + 32)] -= 1
		else:
			u += 1
	else:
		u += 1
print(u)


n = int(input())
s = input()
res = 0
d = {}
for i in range(0, 2 * n - 2, 2):
	if s[i] in d:
		d[s[i]] += 1
	else:
		d[s[i]] = 1
	room = s[i + 1].lower()
	if room in d and d[room] > 0:
		d[room] -= 1
	else:
		res += 1
print(res)


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)


n = int(input())
a = input()
d = {}
c = 0
for i in range(0, len(a), 2):
	if chr(ord(a[i]) - 32) not in d:
		d[chr(ord(a[i]) - 32)] = 1
	else:
		d[chr(ord(a[i]) - 32)] += 1
	if a[i + 1] in d:
		d[a[i + 1]] -= 1
		if d[a[i + 1]] == 0:
			d.pop(a[i + 1])
	else:
		c += 1
print(c)


n = int(input())
str = input()
a = [0] * 26
dx = ord('a')
ans = 0
for i in range(2 * n - 2):
	if i % 2 == 0:
		a[ord(str[i]) - dx] += 1
	elif a[ord(str[i].lower()) - dx] == 0:
		ans += 1
	else:
		a[ord(str[i].lower()) - dx] -= 1
print(ans)


doors_amount = int(input())
keys_and_doors = input()
keys_needed = 0
alphabet = {}
for (idx, k_d) in enumerate(keys_and_doors):
	if k_d.islower():
		temp_char = k_d.lower()
		if temp_char not in alphabet:
			alphabet[temp_char] = list()
			alphabet[temp_char].append(idx)
		else:
			alphabet[temp_char].append(idx)
	elif k_d.lower() in alphabet and alphabet[k_d.lower()] != []:
		min_key = min(alphabet[k_d.lower()])
		if idx > min_key:
			alphabet[k_d.lower()].remove(min_key)
	else:
		keys_needed += 1
print(keys_needed)


n = int(input())
ls = [0 for i in range(26)]
st = input()
cou = 0
for x in st:
	if x.islower():
		ls[ord(x) - ord('a')] += 1
	elif ls[ord(x) - ord('A')] == 0:
		cou += 1
	else:
		ls[ord(x) - ord('A')] -= 1
print(cou)


def main():
	n = int(input())
	s = input()
	ans = 0
	cnt = [0] * 26
	for i in range(0, 2 * n - 2, 2):
		cnt[ord(s[i]) - ord('a')] += 1
		if cnt[ord(s[i + 1]) - ord('A')] == 0:
			ans += 1
		else:
			cnt[ord(s[i + 1]) - ord('A')] -= 1
	print(ans)
main()


def main():
	input()
	(s, l, res) = (input(), [0] * 26, 0)
	for (key, lock) in zip(s[::2], s[1::2]):
		l[ord(key) - 97] += 1
		x = ord(lock) - 65
		if l[x] > 0:
			l[x] -= 1
		else:
			res += 1
	print(res)
main()


n = int(input())
s = input()
(k, t) = ({}, 0)
for x in s:
	if x.islower():
		if x in k:
			k[x] += 1
		else:
			k[x] = 1
	elif x.lower() in k and k[x.lower()] > 0:
		k[x.lower()] -= 1
	else:
		t += 1
print(t)


n = int(input())
s = input()
keys = [0] * 256
res = 0
for i in range(0, len(s) - 1, 2):
	if s[i] != s[i + 1].lower():
		if keys[ord(s[i + 1].lower())] == 0:
			res += 1
		else:
			keys[ord(s[i + 1].lower())] -= 1
		keys[ord(s[i])] += 1
print(res)


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
	elif k[ord(i) - 65] > 0:
		k[ord(i) - 65] = k[ord(i) - 65] - 1
	else:
		r = r + 1
	j = j + 1
print(r)


n = int(input().strip())
l = input().strip()
result = 0
d = {}
for i in range(0, 2 * n - 2, 2):
	if l[i] == l[i + 1].lower():
		continue
	elif d.get(l[i + 1].lower(), 0):
		d[l[i + 1].lower()] -= 1
		d[l[i]] = d.get(l[i], 0) + 1
	else:
		result += 1
		d[l[i]] = d.get(l[i], 0) + 1
print(result)


n = int(input())
line = str(input())
cook = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0}
tar = 0
for i in range(n - 1):
	cook[line[2 * i]] += 1
	if cook[line[2 * i + 1].lower()] > 0:
		cook[line[2 * i + 1].lower()] -= 1
	else:
		tar += 1
print(tar)


ans = 0
d = [0] * 128
n = int(input()) - 1
s = list(input())
for i in range(n):
	d[ord(s[i * 2])] += 1
	d[ord(s[i * 2 + 1]) + 32] -= 1
	if d[ord(s[i * 2 + 1]) + 32] < 0:
		ans += 1
		d[ord(s[i * 2 + 1]) + 32] = 0
print(ans)


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()
need = 0
keys = {c: 0 for c in 'abcdefghijklmnopqrstuvwxyz'}
for c in s:
	if c.islower():
		keys[c] += 1
	else:
		c = c.lower()
		if keys[c]:
			keys[c] -= 1
		else:
			need += 1
print(need)


input()
path = input()
count = {}
to_buy = 0
for val in path:
	if val.islower():
		count[val] = count.get(val, 0) + 1
	else:
		v = val.lower()
		if count.get(v, 0) > 0:
			count[v] -= 1
		else:
			to_buy += 1
print(to_buy)


a = [*open(0)][1]
s = {}
r = 0
for (x, y) in [*zip(a, a[1:])][::2]:
	s[x.upper()] = s.get(x.upper(), 0) + 1
	if s.get(y, 0) > 0:
		s[y] -= 1
	else:
		r += 1
print(r)


from typing import List, Dict

def lowercase() -> str:
	return 'abcdefghijklmnopqrstuvwxyz'
n: int = int(input())
string: str = input()
i: int = 0
available_keys: Dict[str, int] = dict.fromkeys(lowercase(), 0)
buy: int = 0
next: str = ''
count: int = 0
while i <= 2 * n - 4:
	available_keys[string[i]] = available_keys[string[i]] + 1
	next = string[i + 1].lower()
	count = available_keys[next]
	if count > 0:
		available_keys[next] = count - 1
	else:
		buy = buy + 1
	i = i + 2
print(buy)


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


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())
s = input()
keys = [0] * 26
doors = 0
for i in range(len(s)):
	if i % 2 == 0:
		keys[ord(s[i]) - 97] += 1
	elif keys[ord(s[i].lower()) - 97] > 0:
		keys[ord(s[i].lower()) - 97] -= 1
	else:
		doors += 1
print(doors)


keys = 'abcdefghijklmnopqrstuvwxyz'
d = {}
for key in keys:
	d[key] = 0
buy = 0
n = int(input())
s = input()
for i in range(n - 1):
	k = s[2 * i]
	r = s[2 * i + 1].lower()
	if k != r:
		if d[r] > 0:
			d[r] -= 1
			d[k] += 1
		else:
			d[k] += 1
			buy += 1
print(buy)


room = input()
string = input()
keys = {}
rooms = {}
need = 0
for c in string:
	if c.islower():
		if c in keys:
			keys[c] += 1
		else:
			keys[c] = 1
	elif c.isupper():
		if c in rooms:
			rooms[c] += 1
		else:
			rooms[c] = 1
		try:
			if keys[c.lower()] > 0:
				keys[c.lower()] -= 1
			elif keys[c.lower()] == 0:
				need += 1
		except KeyError:
			need += 1
print(need)


n = input()
arr = input()
keys = dict()
i = 0
count = 0
while i < len(arr):
	keys[arr[i]] = keys.get(arr[i], 0) + 1
	if keys.get(arr[i + 1].lower(), 0) == 0:
		count += 1
	else:
		keys[arr[i + 1].lower()] -= 1
	i += 2
print(count)


n = int(input())
knowledge = input()
count = 0
keyHash = {}
for i in range(2 * n - 2):
	if i % 2 == 0:
		key = knowledge[i]
		if key in keyHash:
			keyHash[key] += 1
		else:
			keyHash[key] = 1
	else:
		door = knowledge[i]
		reqKey = chr(ord(door) + 32)
		if reqKey in keyHash and keyHash[reqKey] > 0:
			keyHash[reqKey] -= 1
		else:
			count += 1
print(count)


n = int(input())
strr = input()
d = {}
ans = 0
for i in range(len(strr)):
	if i % 2 != 0:
		if d.get(strr[i]):
			if d[strr[i]] > 0:
				d[strr[i]] -= 1
			else:
				ans += 1
		else:
			ans += 1
	elif d.get(strr[i].upper()):
		d[strr[i].upper()] += 1
	else:
		d[strr[i].upper()] = 1
print(ans)


n = int(input())
strin = input()
dic = dict()
ans = 0
for c in strin:
	if c.islower():
		if c not in dic:
			dic[c] = 1
		else:
			v = dic[c]
			dic[c] = v + 1
	else:
		C = c.lower()
		if C not in dic or dic[C] == 0:
			ans += 1
		if C in dic:
			v = dic[C]
			dic[C] = 0 if v == 0 else v - 1
print(ans)


n = int(input())
s = input()
key_dict = {}
k = 0
for i in range(0, 2 * n - 2, 2):
	if s[i] != s[i + 1].lower():
		if s[i] not in key_dict.keys():
			key_dict[s[i]] = 1
		else:
			key_dict[s[i]] += 1
		if s[i + 1].lower() in key_dict.keys() and key_dict[s[i + 1].lower()] > 0:
			key_dict[s[i + 1].lower()] -= 1
		elif s[i + 1].lower() not in key_dict.keys() or key_dict[s[i + 1].lower()] == 0:
			k += 1
print(k)


n = int(input())
keys = {}
count = 0
stroke = input()
for char in stroke:
	if char.islower():
		if char in keys.keys():
			keys[char] += 1
		else:
			keys[char] = 1
	else:
		char = char.lower()
		if char in keys.keys() and keys[char] > 0:
			keys[char] -= 1
		else:
			count += 1
print(count)


n = int(input())
s = str(input())
r = 0
A1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
A2 = 'abcdefghijklmnopqrstuvwxyz'
T = [0 for _ in range(26)]
for i in range(0, 2 * n - 2, 2):
	T[A2.index(s[i])] += 1
	if T[A1.index(s[i + 1])] == 0:
		r += 1
	else:
		T[A1.index(s[i + 1])] -= 1
print(r)


t = input()
s = input()
k = []
for i in s:
	k.append(i.lower())
ans = 0
kk = []
for i in range(len(k)):
	kk.append(0)
dd = dict(zip(k, kk))
for i in s:
	if i.islower():
		dd[i] += 1
	elif dd[i.lower()] > 0:
		dd[i.lower()] -= 1
	else:
		ans += 1
print(ans)


n = int(input())
doors = [0 for i in range(26)]
keys = [0 for i in range(26)]
ans = 0
ch = True
for i in input():
	s = ord(i)
	if ch:
		for j in range(ord('a'), ord('z') + 1):
			if j == s:
				keys[j - ord('a')] += 1
	else:
		for j in range(ord('A'), ord('Z') + 1):
			if j == s:
				if keys[j - ord('A')] > 0:
					keys[j - ord('A')] -= 1
				else:
					ans += 1
	ch = not ch
print(ans)


n = int(input())
s = input()
l = [0] * 26
c = 0
for i in s:
	if i.islower():
		l[ord(i) - 97] += 1
	else:
		i = i.lower()
		if l[ord(i) - 97] > 0:
			l[ord(i) - 97] -= 1
			continue
		else:
			c += 1
print(c)


from collections import defaultdict
n = int(input())
inp = input()
keys = defaultdict(lambda : 0)
res = 0
for i in range(0, 2 * (n - 1), 2):
	keys[inp[i]] += 1
	if keys[inp[i + 1].lower()] > 0:
		keys[inp[i + 1].lower()] -= 1
	else:
		res += 1
print(res)


s = [0 for _ in range(26)]
n = int(input())
room = input()
buy = 0
for i in range(2 * n - 2):
	if i % 2 == 0:
		s[ord(room[i]) - ord('a')] += 1
	else:
		p = room[i].lower()
		p = ord(p) - ord('a')
		if s[p]:
			s[p] -= 1
		else:
			buy += 1
print(buy)


(n, s, total) = (int(input()), input(), 0)
hash = dict({})
for i in range(0, 2 * n - 2, 2):
	if s[i].upper() != s[i + 1]:
		if s[i + 1] in hash and hash[s[i + 1]]:
			hash[s[i + 1]] = hash[s[i + 1]] - 1
		else:
			total += 1
		if s[i].upper() in hash:
			hash[s[i].upper()] += 1
		else:
			hash[s[i].upper()] = 1
print(total)


n = int(input())
s = input()
x = 2 * n - 2
alphabets = list('abcdefghijklmnopqrstuvwxyz')
memo = {alphabets[i].upper(): 0 for i in range(26)}
keys = 0
for i in range(0, x, 2):
	memo[s[i].upper()] += 1
	if memo[s[i + 1]]:
		memo[s[i + 1]] -= 1
	else:
		keys += 1
print(keys)


n = int(input())
s = input()
di = {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D', 'e': 'E', 'f': 'F', 'g': 'G', 'h': 'H', 'i': 'I', 'j': 'J', 'k': 'K', 'l': 'L', 'm': 'M', 'n': 'N', 'o': 'O', 'p': 'P', 'q': 'Q', 'r': 'R', 's': 'S', 't': 'T', 'u': 'U', 'v': 'V', 'w': 'W', 'x': 'X', 'y': 'Y', 'z': 'Z'}
(d, res) = ({}, 0)
for (i, x) in enumerate(di):
	d[di[x]] = 0
for i in range(0, n * 2 - 2, 2):
	x = di[s[i]]
	if x != s[i + 1]:
		if d[s[i + 1]] == 0:
			res += 1
		else:
			d[s[i + 1]] -= 1
		d[x] += 1
print(res)


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
	elif a[ord(s[i]) - ord('A')] > 0:
		a[ord(s[i]) - ord('A')] -= 1
	else:
		u += 1
print(u)


from collections import defaultdict
n = int(input())
s = input()
cnt = defaultdict(int)
ans = 0
for c in s:
	if c.isupper() and cnt[c.lower()] > 0:
		cnt[c.lower()] -= 1
	elif c.isupper():
		ans += 1
	else:
		cnt[c] += 1
print(ans)


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())
KD = list(input())
keys = [0] * 26
doors = [0] * 26
nrBuys = 0
for i in range(n - 1):
	keys[ord(KD[i * 2]) - ord('a')] += 1
	if keys[ord(KD[i * 2 + 1]) - ord('A')] == 0:
		nrBuys += 1
	else:
		keys[ord(KD[i * 2 + 1]) - ord('A')] -= 1
print(nrBuys)


llaves = [0] * 26

def save_key(key):
	global llaves
	llaves[ord(key) - 97] += 1

def open_room(lock):
	global llaves
	i = ord(lock) - 65
	if llaves[i] > 0:
		llaves[i] -= 1
		return True
	return False
(_, hotel) = (input(), input())
buy = 0
for i in range(0, len(hotel), 2):
	(i, j) = (i, i + 1)
	save_key(hotel[i])
	if not open_room(hotel[j]):
		buy += 1
print(buy)


n = int(input())
s = input()
s = s.lower()
l = 0
a = [0] * 27
for i in range(0, 2 * (n - 1), 2):
	a[ord(s[i]) - 97] += 1
	if a[ord(s[i + 1]) - 97] == 0:
		l += 1
	else:
		a[ord(s[i + 1]) - 97] -= 1
print(l)


from collections import Counter
n = int(input())
s = input()
nkeys = Counter()
cnt = 0
for i in range(n - 1):
	nkeys[s[i * 2]] += 1
	door = s[i * 2 + 1].lower()
	if nkeys[door] > 0:
		nkeys[door] -= 1
	else:
		cnt += 1
print(cnt)


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


from collections import Counter, defaultdict, deque
from math import *
import sys
input = sys.stdin.readline

def solve():
	n = 2 * int(input()) - 2
	s = input().strip()
	d = defaultdict(int)
	c = 0
	for i in range(n):
		if i & 1:
			door = s[i].lower()
			if d[door] == 0:
				c += 1
			else:
				d[door] -= 1
		else:
			d[s[i]] += 1
	print(c)
tt = 1
for test in range(tt):
	solve()


from collections import Counter
n = int(input())
s = input()
keys = Counter()
buy = 0
for i in range(0, 2 * n - 2, 2):
	keys[s[i]] += 1
	room = s[i + 1].lower()
	if room not in keys or not keys[room]:
		buy += 1
	else:
		keys[room] -= 1
print(buy)


n = input()
s = input()
klucze = {}
wynik = 0
s = s.lower()
for i in range(len(s)):
	if i % 2 == 0:
		if s[i] in klucze:
			klucze[s[i]] += 1
		else:
			klucze[s[i]] = 1
	elif s[i] in klucze:
		if klucze[s[i]] > 0:
			klucze[s[i]] -= 1
		else:
			wynik += 1
	else:
		wynik += 1
print(wynik)


def main():
	n = int(input())
	s = input()
	s = [s[i] for i in range(len(s))]
	keys = {}
	buy = 0
	for i in range(1, 2 * n - 2, 2):
		keys[s[i - 1]] = keys.get(s[i - 1], 0) + 1
		remain = keys.get(s[i].lower(), 0)
		if remain > 0:
			keys[s[i].lower()] = remain - 1
		else:
			buy += 1
	return buy
print(main())


from collections import Counter
n = int(input())
s = input()
c = Counter()
m = 0
for i in range(n - 1):
	k = s[2 * i]
	c[k] += 1
	d = s[2 * i + 1].lower()
	if c[d] > 0:
		c[d] -= 1
	else:
		m += 1
print(m)


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
	elif current[ord(string[i]) + 32 - 97] != 0:
		current[ord(string[i]) + 32 - 97] -= 1
	else:
		ans += 1
print(ans)


n = int(input())
keys = 26 * [0]
home = input()
need = 0
for i in range(len(home)):
	if i % 2:
		if ord(home[i]) - 65 != ord(home[i - 1]) - 97:
			keys[ord(home[i - 1]) - 97] += 1
			if keys[ord(home[i]) - 65]:
				keys[ord(home[i]) - 65] -= 1
			else:
				need += 1
print(need)


import math
import sys
n = int(input())
s = input()
d = dict()
alfa = 'abcdefghijklmnopqrstuvwxyz'
for i in alfa:
	d[i] = 0
ans = 0
for i in s:
	if i == i.lower():
		d[i] += 1
	elif d[i.lower()] == 0:
		ans += 1
	else:
		d[i.lower()] -= 1
print(ans)


n = int(input())
s = input()
a = {}
cnt = 0
for x in s:
	if x >= 'a' and x <= 'z':
		if x not in a:
			a[x] = 1
		else:
			a[x] += 1
	else:
		y = chr(ord('a') + ord(x) - ord('A'))
		if y in a:
			a[y] -= 1
			if a[y] == 0:
				del a[y]
		else:
			cnt += 1
print(cnt)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
from collections import Counter
n = int(input())
s = input()
v = [0] * 26
ans = 0
for i in range(len(s)):
	if i % 2 == 0:
		v[ord(s[i]) - 97] += 1
	else:
		var = s[i].lower()
		if v[ord(var) - 97] >= 1:
			v[ord(var) - 97] -= 1
		else:
			ans += 1
print(ans)


n = int(input())
s = input()
s = s.lower()
lt = {}
cnt = 0
for i in range(0, 2 * n - 3, 2):
	if s[i] == s[i + 1]:
		continue
	else:
		if s[i] in lt.keys():
			lt[s[i]] += 1
		else:
			lt[s[i]] = 1
		if s[i + 1] in lt.keys():
			if lt[s[i + 1]] > 0:
				lt[s[i + 1]] -= 1
			else:
				cnt += 1
		else:
			cnt += 1
print(cnt)


n = int(input()) - 1
s = input()
mx = {}
c = {}
for i in range(n):
	if not s[2 * i] in c:
		c[s[2 * i]] = 0
		mx[s[2 * i]] = 0
	c[s[2 * i]] -= 1
	if not s[2 * i + 1].lower() in c:
		c[s[2 * i + 1].lower()] = 0
		mx[s[2 * i + 1].lower()] = 0
	c[s[2 * i + 1].lower()] += 1
	mx[s[2 * i + 1].lower()] = max(mx[s[2 * i + 1].lower()], c[s[2 * i + 1].lower()])
ans = 0
for k in mx:
	ans += mx[k]
print(ans)


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 datetime
n = int(input())
string = input()
keys = [0] * 26
count = 0
for i in range(0, len(string), 2):
	if string[i].upper() == string[i + 1]:
		continue
	elif keys[ord(string[i + 1].lower()) - 97] >= 1:
		keys[ord(string[i + 1].lower()) - 97] -= 1
		keys[ord(string[i]) - 97] += 1
	else:
		count += 1
		keys[ord(string[i]) - 97] += 1
print(count)


import sys
import math
import itertools
import collections

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
n = ii()
s = input()
ans = 0
orda = ord('a')
d = [0] * 26
for i in range(2 * n - 2):
	if s[i].islower():
		d[orda - ord(s[i])] += 1
	elif d[orda - ord(s[i].lower())] > 0:
		d[orda - ord(s[i].lower())] -= 1
	else:
		ans += 1
print(ans)


n = int(input())
S = input()
S1 = {}
k = 0
for x in S:
	if x.islower():
		S1[x] = S1.get(x, 0) + 1
	else:
		v = x.lower()
		if S1.get(v, 0) > 0:
			S1[v] -= 1
		else:
			k = k + 1
print(k)


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
	elif 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)


input()
s = input()
keys_p = {x: 0 for x in 'abcdefghijklmnopqrstuvwxyz'}
keys_n = {x: 0 for x in 'abcdefghijklmnopqrstuvwxyz'}
for i in range(0, len(s), 2):
	keys_p[s[i]] += 1
	k = s[i + 1].lower()
	if keys_p[k] > 0:
		keys_p[k] -= 1
	else:
		keys_n[k] += 1
print(sum([v for (k, v) in keys_n.items()]))


n = int(input())
s = input()
my_dict = {}
cnt = 0
pos = 0
for c in s:
	if pos % 2 == 0:
		key = c
		if not key in my_dict:
			my_dict[key] = 1
		else:
			my_dict[key] += 1
	else:
		door = c.lower()
		if door not in my_dict or my_dict[door] == 0:
			cnt += 1
		else:
			my_dict[door] -= 1
	pos += 1
print(cnt)


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


rooms = int(input())
array = list(str(input()))
odds = list(set(list(array[0:len(array):2])))
keysNeeded = 0
dictionary = {}
for i in range(0, len(odds)):
	dictionary[odds[i]] = 0
for i in range(0, len(array)):
	if i % 2 == 0:
		dictionary[array[i]] += 1
	else:
		buffer = array[i].lower()
		if buffer in dictionary and dictionary[buffer] > 0:
			dictionary[buffer] -= 1
		else:
			keysNeeded += 1
print(keysNeeded)


from collections import defaultdict
n = int(input())
s = input()
d = defaultdict(int)
ans = 0
for i in s:
	if 97 <= ord(i) <= 122:
		d[i] += 1
	else:
		x = chr(ord(i) + 32)
		if d[x] > 0:
			d[x] -= 1
		else:
			ans += 1
print(ans)


n = int(input())
s = input()
res = 0
cnt = [0] * 26
for i in range(0, len(s), 2):
	if s[i] != s[i + 1]:
		j = ord(s[i]) - ord('a')
		k = ord(s[i + 1].lower()) - ord('a')
		cnt[j] += 1
		if cnt[k] > 0:
			cnt[k] -= 1
		else:
			res += 1
print(res)


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


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	s = S()
	r = 0
	d = collections.defaultdict(int)
	for i in range(n - 1):
		t = s[i * 2]
		u = chr(ord(s[i * 2 + 1]) - ord('A') + ord('a'))
		d[t] += 1
		if d[u] > 0:
			d[u] -= 1
		else:
			r += 1
	return r
print(main())


m = int(input())
a = str.lower(input())
c = 0
d = {}
for i in range(1, len(a), 2):
	if a[i - 1] in d:
		d[a[i - 1]] += 1
	else:
		d[a[i - 1]] = 1
	if a[i] in d:
		if d[a[i]] > 0:
			d[a[i]] -= 1
		else:
			c += 1
	else:
		c += 1
print(c)


class CodeforcesTask525ASolution:

	def __init__(self):
		self.result = ''
		self.rooms_count = 0
		self.doors = []
		self.keys = []

	def read_input(self):
		self.rooms_count = int(input())
		rooms = input()
		for x in range(len(rooms)):
			if x % 2:
				self.doors.append(rooms[x])
			else:
				self.keys.append(rooms[x].upper())

	def process_task(self):
		to_buy = 0
		keys = dict(zip(list('abcdefghijklmnopqrstuvwxyz'.upper()), [0 for x in range(len('abcdefghijklmnopqrstuvwxyz'))]))
		for x in range(len(self.doors)):
			keys[self.keys[x]] += 1
			if keys[self.doors[x]]:
				keys[self.doors[x]] -= 1
			else:
				to_buy += 1
		self.result = str(to_buy)

	def get_result(self):
		return self.result
Solution = CodeforcesTask525ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


from sys import stdin

def read():
	return map(int, stdin.readline().split())
input()
cnt = {}
seen2 = set()
ans = 0
for c in input():
	if 'A' <= c and c <= 'Z':
		if c.lower() not in cnt:
			ans += 1
		elif cnt[c.lower()] == 0:
			ans += 1
		else:
			cnt[c.lower()] -= 1
	elif c not in cnt:
		cnt[c] = 1
	else:
		cnt[c] += 1
print(ans)


n = int(input())
rooms = input()
chars = 'abcdefghijklmnopqrstuvwxyz'
chars = [c for c in chars]
cnt = [0] * 26
hash_map = dict(zip(chars, cnt))
count = 0
i = 0
while i < len(rooms):
	if rooms[i] in hash_map:
		hash_map[rooms[i]] += 1
	elif rooms[i] not in hash_map and hash_map[rooms[i].lower()] > 0:
		hash_map[rooms[i].lower()] -= 1
	else:
		count += 1
	i += 1
print(count)


from collections import *
S = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
s = 'abcdefghijklmnopqrstuvwxyz'
d = defaultdict()
for i in S:
	d[i] = 0
for i in s:
	d[i] = 0
m = int(input())
t = input()
for i in range(len(t)):
	if t[i].islower():
		q = t[i].upper()
		d[t[i]] += 1
	else:
		q = t[i].lower()
		if d[q] == 0:
			d[t[i]] += 1
		elif d[q] > 0:
			d[q] -= 1
sn = 0
for i in S:
	sn += d[i]
print(sn)


n = int(input())
s = input()
k = []
d = []
for i in range(0, 2 * n - 2, 2):
	k += [s[i]]
for i in range(1, 2 * n - 2, 2):
	d += [s[i].lower()]
aval = {}
for i in range(97, 123):
	aval[chr(i)] = 0
c = 0
for i in range(len(d)):
	aval[k[i]] += 1
	if aval[d[i]] == 0:
		c += 1
	else:
		aval[d[i]] -= 1
print(c)


n = int(input())
s = input()
d = {}
count = 0
for i in range(len(s)):
	if i % 2 == 0:
		try:
			d[s[i].upper()] += 1
		except:
			d[s[i].upper()] = 1
	else:
		try:
			if d[s[i]] > 0:
				d[s[i]] -= 1
			else:
				count += 1
		except:
			count += 1
print(count)


n = int(input())
s = input()
cnt = dict()
for i in range(ord('a'), ord('z') + 1):
	cnt[i] = int(0)
ans = 0
for i in range(2 * n - 2):
	c = ord(s[i].lower())
	if i % 2 == 0:
		cnt[c] += 1
	elif cnt[c] < 1:
		ans += 1
	else:
		cnt[c] -= 1
print(ans)


n = int(input())
s = input()
c = []
for i in range(26):
	c.append(0)
ans = 0
for i in range(2 * n - 2):
	if i % 2 == 0:
		c[ord(s[i]) - ord('a')] += 1
	elif c[ord(s[i]) + 32 - ord('a')] > 0:
		c[ord(s[i]) + 32 - ord('a')] -= 1
	else:
		ans += 1
print(ans)