n = int(eval(input()))

s = eval(input())

ans = [0]

x = 0

for i in range(n):

  if s[i] == 'I':

    x += 1

    ans.append(x)

  else:

    x -= 1

    ans.append(x)

#print(ans)

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

s=eval(input())

ans=0

x=0

for i in range(n):

  if s[i]=='I':

    x+=1

  else:

    x-=1

  ans=max(ans,x)

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

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

-ans = [0] +ans = 0 -        ans.append(x) -        ans.append(x) -# print(ans) -print((max(ans))) +    ans = max(ans, x) +print(ans)