n = int(eval(input()))

s = eval(input())

x = 0

li = [0]

for i in range(n):

    if s[i] =="I":

        x += 1

        li.append(x)

    else:

        x -= 1

print((max(li)))
n = int(eval(input()))

s = eval(input())

x = 0

max = 0

for i in range(n):

    if s[i] =="I":

        x += 1

        if x>max:

            max = x

    else:

        x -= 1

print(max)
n = int(eval(input()))
s = eval(input())
x = 0
li = [0]
for i in range(n):
    if s[i] == "I":
        x += 1
        li.append(x)
    else:
        x -= 1
print((max(li)))

n = int(eval(input()))
s = eval(input())
x = 0
max = 0
for i in range(n):
    if s[i] == "I":
        x += 1
        if x > max:
            max = x
    else:
        x -= 1
print(max)

-li = [0] +max = 0 -        li.append(x) +        if x > max: +            max = x -print((max(li))) +print(max)