

n = int(eval(input()))

s = list(eval(input()))



ans = 0

l = [0]



for i in range(n):

    if s[i] == "I":

        ans += 1

        l.append(ans)

    elif s[i] == "D":

        ans -= 1

        l.append(ans)



print((max(l)))



n = int(eval(input()))

s = list(eval(input()))

max = 0

count = 0



for i in range(n):

    if s[i] == "I":

        count += 1

        if max < count:

            max = count

    elif s[i] == "D":

        count -= 1

print(max)

n = int(eval(input()))
s = list(eval(input()))
ans = 0
l = [0]
for i in range(n):
    if s[i] == "I":
        ans += 1
        l.append(ans)
    elif s[i] == "D":
        ans -= 1
        l.append(ans)
print((max(l)))

n = int(eval(input()))
s = list(eval(input()))
max = 0
count = 0
for i in range(n):
    if s[i] == "I":
        count += 1
        if max < count:
            max = count
    elif s[i] == "D":
        count -= 1
print(max)

-ans = 0 -l = [0] +max = 0 +count = 0 -        ans += 1 -        l.append(ans) +        count += 1 +        if max < count: +            max = count -        ans -= 1 -        l.append(ans) -print((max(l))) +        count -= 1 +print(max)