Problem:
 Score : 200 points    Problem Statement You have an integer variable x .
Initially, x=0 .  Some person gave you a string S of length N , and using the string you performed the following operation N times.
In the i -th operation, you incremented the value of x by 1 if S_i= I , and decremented the value of x by 1 if S_i= D .  Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).      Constraints  1≤N≤100  |S|=N  No characters except I and D occur in S .         Input The input is given from Standard Input in the following format:  N  S       Output Print the maximum value taken by x during the operations.        Sample Input 1 5
IIDID      Sample Output 1 2  After each operation, the value of x becomes 1 , 2 , 1 , 2 and 1 , respectively. Thus, the output should be 2 , the maximum value.       Sample Input 2 7
DDIDDII      Sample Output 2 0  The initial value x=0 is the maximum value taken by x , thus the output should be 0 .

Solution (Python):
n = int(input())
s = list(input())
x = 0
tmp = 0
for i in s:
    if i == "I":
        x += 1
    else:
        x -= 1
    tmp = max(x, tmp)
print(tmp)

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

Solution (Python):
N = int(input())
S = input()

tmp = 0
ans = 0
for i in range(N):
    if 'I' == S[i]:
        tmp += 1
    else:
        tmp -= 1
    ans = max(tmp, ans)
print(ans)

Solution (Python):
n = int(input())
s = input()
x = 0
maxx = 0
for i in range(n):
    if s[i] == "I":
        x += 1
        if maxx < x:
            maxx = x
    else:
        x -= 1
print(maxx)

Solution (Python):
n = int(input())
s = input()
x = 0
res = 0

for i in range(n):
    if s[i] == "I":
        x += 1
    else:
        x -= 1
    res = max(res, x)

print(res)

Solution (Python):
N = int(input())
S = input()
x = 0
ans = x

for i in range(N):
    if S[i]=="I":
        x += 1
        ans = max(ans, x)
    else:
        x -= 1
print(ans)

Solution (Python):
N = int(input())
S = list(input())
x = 0
max = 0
for i in range(N):
    if S[i] == "I":
        x += 1
    else:
        x -= 1
    if x > max:
        max = x
print(max)

Solution (Python):
N = int(input())
S = input()
ans = 0
x = 0
for i in S:
  if i == 'I':
    x += 1
    ans = max(ans, x)
  else:
    x -= 1
print(ans)

Solution (Python):
N=int(input())
S=input()
ans=0
cnt=0
for i in range(len(S)):
  if S[i]=='I':
    cnt+=1
  else:
    cnt-=1
  ans=max(ans,cnt)
print(ans)

Solution (Python):
N=int(input())
S=input()
ans=0
cnt=0
for i in range(len(S)):
  if S[i]=='I':
    cnt+=1
  else:
    cnt-=1
  ans=max(ans,cnt)
print(ans)

Solution (Python):
n = int(input())
s = input()

x, ans = 0, 0
for o in s:
    if o == 'I':
        x += 1 
    else:
        x -= 1
    ans = max(ans, x)

print(ans)

Solution (Python):
n = int(input())
s = input()
x = 0
l = [0]
for a in s:
    if a == "I":
        x = x + 1
        l.append(x)
    else:
        x = x - 1
        l.append(x)

print(max(l))

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

Solution (Python):
n = int(input())
s = input()
x = 0
ans = 0
for i in s:
    if i == 'I':
        x+=1
    elif i == 'D':
        x-=1
    ans = max(ans,x)
print(ans)

Solution (Python):
n = int(input())
s = list(map(str, input()))
mx = 0
sm = 0

for char in s:
    if char == "I":
        sm += 1
        mx = max(mx, sm)
    elif char == "D":
        sm -= 1
    else:
        continue

print(mx)

Solution (Python):
def answer(n: int, s: str) -> int:
    while 'DI' in s:
        s = s.replace('DI', '')

    return s.count('I')


def main():
    n = int(input())
    s = input()
    print(answer(n, s))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = input()
ans = 0
x = 0
for i in s:
  if i == 'I':
    x += 1
  else:
    x -= 1
  if x > ans:
    ans = x
print(ans)

Solution (Python):
n = int(input())
s = input()

x = 0
ans = 0
for a in s:
    if a == 'I':
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print(ans)

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

Solution (Python):

import sys


def solve(N: int, S: str):
    ans = 0
    t  = 0
    for i in S:
        if i == "I":
            t += 1
        if i == "D":
            t -= 1
        if t > ans:
            ans = t
    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = next(tokens)  
    solve(N, S)

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
S=input()

def ans052(N:int, S:str):
    x=0
    x_list=[0]
    for i in range(N):
        if S[i]=="I":
            x+=1
            x_list.append(x)
        elif S[i]=="D":
            x-=1
            x_list.append(x)
    x_list.sort()
    return x_list[-1]

print(ans052(N,S))

Solution (Python):
n = int(input())
s = input()

m = 0
x = 0
for w in s:
	if w == "I":
		x += 1
	else:
		x -= 1
	
	if x > m:
		m = x
		
print(m)

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

Solution (Python):
N = int(input())
S = input()

x = 0
lst = [0]

for i in range(N):
   if S[i] == 'I':
      x += 1
   else:
      x -= 1
   lst.append(x)

print(max(lst))

Solution (Python):
n = int(input())
s = input()
x = 0
ans = [0]

for c in s:
    if c == 'I':
        x += 1
    else:
        x -= 1
    ans.append(x)
print(max(ans))

Solution (Python):
n = int(input())
ans = list(input())
count = 0
a = set()
for i in range(n):
    if ans[i] == 'I':
        count += 1
        a.add(count)
    elif ans[i] == 'D':
        count -= 1
        a.add(count)

print(max(max(a), 0))

Solution (Python):
n=int(input())
x=0
b=[]
s=input()
for S in s:
    if S=='I':
        x += 1
        b.append(x)
    else:
        x -= 1
        b.append(x)
print(max(max(b),0))

Solution (Python):
n=int(input())
S=input()
crt=0
ans=0
for s in S:
  if s=="I":
    crt+=1
  else:
    crt-=1
  ans=max(ans,crt)
print(ans)

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

Solution (Python):
n = int(input())
a = list(input())
xlist = [0]
x = 0
for i in range(n):
  if a[i]=="D":
    x-=1
  elif a[i]=="I":
    x+=1
  xlist.append(x)
print(max(xlist))

Solution (Python):
N = int(input())
S = input()

result = 0
x = 0
for i in S:
    if i == 'I':
        x += 1
    else:
        x -= 1
    result = max(result, x)

print(result)

Solution (Python):
a,b=[input() for i in range(2)]
p=0
ans=0

for i in b:
  if i =='I':
    p+=1
  elif i =='D' and p>0:
    p-=1
  else:
    p-=1
  
  if ans<p:
    ans=p
 
print(ans)

Solution (Python):
N = int(input())
S = input()

ans = 0
cnt = 0

for i in range(N):
  if S[i] == "I":
    cnt += 1
  elif S[i] == "D":
    cnt -= 1
  
  ans = max(ans, cnt)
  
print(ans)

Solution (Python):
n = int(input())
s = list(input())
max = x = 0

for i in s:
    if i=='I':
        x += 1
    else:
        x -= 1
    if max < x :
        max = x
print(max)

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

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

Solution (Python):
N = int(input())
S = input()

max_num = 0
idx = 0
x = 0
while idx < N:
    if S[idx] == 'I':
        x += 1
    else:
        x -= 1
    max_num = max(x, max_num)
    idx += 1

print(max_num)

Solution (Python):
N,S=int(input()),input()
print(max([(t:=S[:m+1]).count("I")-t.count("D") for m in range(N)]+[0]))

Solution (Python):

N = int(input())
S = str(input())

ans = 0
count = 0
for i in S:
    if i == 'I': count += 1
    elif i == 'D': count -= 1
    ans = max(ans, count)

print(ans)

Solution (Python):

import sys
input=sys.stdin.readline

def main():
    answers=[0]
    n = int(input())
    S = input()
    x=0

    for s in S:
        if "I" in s:
            x+=1
            answers.append(x)
        elif "D" in s:
            x-=1
            answers.append(x)
    print(max(answers))

if __name__=="__main__":
    main()

Solution (Python):
N = int(input())
S = str(input())

M = 0
Sum = 0

for x in S:
    if x == 'I':
        Sum += 1
    else:
        Sum -= 1
    M = max(M, Sum)

print(M)

Solution (Python):
N = int(input())
S = input()

x = 0
ans = 0
for i in S:
    if i == 'I':
        x += 1
    elif i == 'D':
        x -= 1
    ans = max(x, ans)
print(ans)

Solution (Python):
N = int(input())
S = list(input())
ans = 0
n_ans = 0
for i in range(N):
  if(S[i]=='I'):
    n_ans += 1
    ans = max(ans, n_ans)
  else:
    n_ans -= 1
    ans = max(ans, n_ans)
print(ans)

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

Solution (Python):
import sys
import copy
import math
import itertools
import numpy as np

N = int(input())
S = input()
x = 0
max = 0
for i in range(N):
    if S[i] == "I":
        x+=1
    elif S[i] == "D":
        x-=1
    
    if max < x:
        max = x

print(max)

Solution (Python):
n = int(input())
s = input()

c = 0
ans = 0
for i in list(s):
    if i == 'I':
        c+=1
    else:
        c-=1
    ans = max(ans, c)
print(ans)

Solution (Python):
N=int(input())
S=input()
x=0
ans=0
for c in S:
    if c=='I':
        x+=1
        ans=max(ans,x)
    else:
        x-=1
print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
x = 0
for s in S:
  if s == "I":
    x += 1
    ans = max(ans, x)
  else:
    x -= 1
print(ans)

Solution (Python):
N = int(input())
S = str(input())
x = 0
L = [x]
for i in S:
  if i == 'I':
    x += 1
  if i == 'D':
    x -= 1
  L.append(x)
print(max(L))

Solution (Python):


num = input()
count = 0
max = 0
message = input()
table = list(message)
for i in table:
    if i == "I":
        count += 1
    elif i == "D":
        count -= 1
    if max <= count:
        max = count
print(max)

Solution (Python):
N = int(input())
S = input()
ans = 0
cnt = 0
for i in range(N):
  if S[i] == 'I':
    cnt += 1
    ans = max(ans, cnt)
  else:
    cnt -= 1
print(ans)

Solution (Python):
n = int(input())
s = input()

x = 0
ans = 0
for i in s:
    if i == 'I':
        x += 1
    elif i == 'D':
        x -= 1
    ans = max(ans, x)

print(ans)

Solution (Python):
a=int(input())
b=input()
c=0
d=[0]
for i in b:
    if(i=="I"):
        c+=1
        d.append(c)
    elif(i=="D"):
        c-=1
        d.append(c)
print(max(d))

Solution (Python):
def main():
    n = int(input())
    s = input()
    x = 0
    ans = 0

    for ch in s:
        if ch == "I":
            x += 1
        else:
            x -= 1
        ans = max(ans, x)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n = int(input())
    s = input()
    x = 0
    max_s = 0

    for i in range(n):
        if s[i] == 'I':
            x += 1
        elif s[i] == 'D':
            x -= 1

        if max_s < x:
            max_s = x

    print(max_s)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = input().strip()

ans = 0
x = 0
for v in S:
    if v == 'I':
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print(ans)

Solution (Python):
a=int(input())
b=input()
c=0
d=0
for i in range(a):
  if b[i]=="D":
    c=c-1
  if b[i]=="I":
    c=c+1
  if c>d:
    d=c
print(d)

Solution (Python):
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

def main():
    n = int(input())
    S = input()

    array = [0]
    for i in range(len(S)):
        if S[i] == 'I':
            array.append(array[i]+1)
        if S[i] == 'D':
            array.append(array[i]-1)
    print(max(array))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = 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)

Solution (Python):
import sys
import copy
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(input().strip())
s = input().strip()
ans = 0
cnt = 0
for i in s:
    if i == "I": cnt += 1 
    else: cnt -= 1
    ans = max(ans, cnt)
print(ans)

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

Solution (Python):
n = int(input())
s = input()
x = 0
c = 0
for i in s:
  if i == "I":
    x += 1
  else:
    x -= 1
  c = max(x,c)
print(c)

Solution (Python):

N = int(input())
S = input()
x = 0
ans = [0]
for i in range(N):
    x = x+1 if S[i]=='I' else x-1
    ans.append(x)
print(max(ans))

Solution (Python):
N = int(input())
S = input()

x = 0
x_max = x

for c in S:
    if c == "I":
        x += 1
        if x > x_max:
            x_max = x
    elif c == "D":
        x -= 1

print(x_max)

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

Solution (Python):
N = int(input())
S = input()

x = 0
x_list= [0]
for s in S:
    if s == 'I':
        x += 1
        x_list.append(x)
    else:
        x -= 1
        x_list.append(x)

print(max(x_list))

Solution (Python):
N=int(input())
S=input()
a=[]
total=0
for i in range(len(S)):
    if S[i]=="I":
        total+=1
        a.append(total)
    else:
        total-=1
        a.append(total)
print(max(max(a),0))

Solution (Python):
N, S = input(), input()
x, xmax = 0, 0
for s in S:
    x = (lambda a:x+1 if a=='I' else x-1)(s)
    xmax = max(x,xmax)
print(xmax)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    S = input()

    ans = 0
    cur = 0

    for char in S:
        if char == "I":
            cur += 1
        else:
            cur -= 1

        ans = max(ans, cur)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys



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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    S = input()
    x = 0
    ans = 0
    for s in S:
        if s == "I":
            x += 1
        else:
            x -= 1
        ans = max(x, ans)
    print(ans)
    return


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
S = input()
ans = 0
ans_tmp = 0
for s in S:
  if s=="I":
    ans_tmp += 1
    ans = max(ans_tmp, ans)
  else:
    ans_tmp -= 1
print(ans)

Solution (Python):
n = int(input())
s = input()

ans = 0
x = 0
for c in s:
    if c == 'I':
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print(ans)

Solution (Python):
N = int(input())
S = list(input())

x = 0
maxi = 0

for i in S:
    if i == 'I':
        x += 1
    else:
        x -= 1

    if x > maxi:
        maxi = x

print(maxi)

Solution (Python):
n=int(input())
s=str(input())
ans=0
m=0
for i in range(n):
  if s[i]=="I":
    ans+=1
    m=max(m,ans)
  else:
    ans-=1

print(m)

Solution (Python):
N = int(input())
S = input()

m = 0
x=0
for i in range(N):
  if S[i] == 'I':
    x+=1
    
  else:
    x-=1
    
  m=max(m,x)
  
print(m)

Solution (Python):
N = int(input())
S = input()
res = 0
tmp = 0
for s in S:
  if s == 'I':
    tmp += 1
  elif s == 'D':
    tmp -= 1
  
  res = max(res, tmp)

print(res)

Solution (Python):
N = int(input())
S = input()
x = 0
ans = 0
for s in S:
    if s == "I":
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print(ans)

Solution (Python):
n=int(input())
s=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)

Solution (Python):
x = 0
mx = 0
n = int(input())
s = input()

for c in s:
    if c == 'I':
        x += 1
    else:
        x -= 1
    mx = max(mx, x)

print(mx)

Solution (Python):
input()

cur = 0
max_value = 0
for c in input():
  x = 1 if c == 'I' else -1
  cur += x
  max_value = max(max_value, cur)
  
print(max_value)

Solution (Python):
input();x,r=0,0
for i in input():
  if i=='I': x+=1
  else: x-=1
  r=max(r,x)
print(r)

Solution (Python):
n = int(input())
s = str(input())
x = 0
maximum = 0

for i in range(n):
    if s[i] == 'I':
        x += 1
    elif s[i] == 'D':
        x -= 1
    maximum = max(maximum, x)

print(maximum)

Solution (Python):
N = int(input())
S = input()
x = 0
ans = 0

for i in range(len(S)):
  if S[i] == 'I':
    x += 1
    ans = max(x, ans)
  else:
    x -= 1
print(ans)

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

Solution (Python):
n = int(input())
s = input()
x = 0
answer = 0

for i in range(n):
	if s[i] == "I":
		x += 1
		if answer < x:
			answer = x
	elif s[i] == "D":
		x -= 1

print(answer)

Solution (Python):
N = int(input())
S = str(input())

ans = 0
tmp = 0
for i in S:
  if i == 'I':
    tmp += 1
    ans = max(ans, tmp)
  else:
    tmp -= 1
print(ans)

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

Solution (Python):
n = int(input())
s = list(input())

x = 0
mx = 0

for a in s:
  if a == "I":
    x +=1
  else:
    x -=1
  if x > mx:
    mx = x
    
print(mx)

Solution (Python):
N = int(input())
S = list(input())
x = 0
a = [0]

for s in S:
  if s == 'I':
    x += 1
  else:
    x -= 1
  a.append(x)

print(max(a))

Solution (Python):
n = int(input())
s = input()
cnt = 0
ans = 0

for i in s:
    if i == 'I':
        cnt += 1
    else:
        cnt -= 1
    
    ans = max(ans,cnt)
    
print(ans)

Solution (Python):
n = int(input())
s = list(input())
count = 0
max = 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)

Solution (Python):
N = int(input())
S = input()

ans = 0
highest = 0
for i in S:
    if i == "I":
        ans += 1
    else:
        ans -= 1
    if highest <= ans:
        highest = ans 

print(highest)

Solution (Python):
def main():
    input()
    s = input()
    tmp = 0
    ans = 0
    for v in s:
        if v == "I":
            tmp += 1
        else:
            tmp -= 1
        ans = max(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
S = str(input())
max_int = 0
count = 0
for i in S:
    if i == 'I':
        count +=1
        max_int = max(max_int, count)
    elif i == 'D':
        count -= 1
print(max_int)

Solution (Python):
n=int(input())
s=input()

ans=0
num=0
for i in s:
  if i=="I":
    num+=1
    ans=max(ans,num)
  elif i=="D":
    num-=1
    ans=max(ans,num)
    
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    S = input()
    ans = 0
    val = 0
    for c in S:
        if c == 'I':
            val += 1
            ans = max(ans, val)
        else:
            val -= 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
S = input()
x = 0
ans = 0
 
for i in S:
  if i == "I":
    x += 1
  elif i == "D":
    x -= 1
  ans = max(ans,x)
  
print(ans)

Solution (Python):
N=int(input())
S=input()
x = 0
ans = x
for c in S:
    if c == 'I':
        x += 1
    elif c == 'D':
        x -= 1

    if x > ans:
        ans = x

print(ans)

Solution (Python):
n = int(input())
s = input()
x = 0
ans = 0
for i in range(n):
    if s[i] == 'I':
        x += 1
        ans = max(ans, x)
    elif s[i] == 'D':
        x -= 1
print(ans)

Solution (Python):
n = int(input())
s = str(input())

max_result = 0
result = 0


for i in s:
    if i == "I":
        result += 1
        if result > max_result:
            max_result = result
    else:
        result -= 1


print(max_result)

Solution (Python):
n = int(input())
s = input()

ans = 0
score = 0
for i in range(n):
  if s[i] == "I":
    score += 1
  if s[i] == "D":
    score -= 1
  ans = max(ans, score)
  
print(ans)

Solution (Python):
n = int(input())
s = str(input())
x = 0
a = 0
for i in s:
    if i == 'I':
        x += 1
        if x > a:
            a = x
    else:
        x -= 1
print(a)

Solution (Python):
N=int(input())
S=list(input())
x=0
X=[0]
for i in range(N):
    if S[i]=='I':
        x+=1
        X.append(x)
    elif S[i]=='D':
        x-=1
        X.append(x)
print(max(X))

Solution (Python):
n = int(input())
s = input()

num_list = [0]
sum = 0
for w in s:
  if w == 'I':
    sum += 1
  else:
    sum -= 1
  num_list.append(sum)

num_list.sort()
ans = num_list[-1]

print(ans)

Solution (Python):
x = 0
N = int(input())
S = input()
L = [x]
for t in S:
  if t == 'I':
    x += 1
    L.append(x)
  else:
    x -= 1
    L.append(x)
print(max(L))

Solution (Python):
n=int(input())
s=input()
d=0
m=0
for i in s:
    if(i=='D'):
        d-=1
    else:
        d+=1
    m=max(m,d)
print(m)

Solution (Python):
n = int(input())
a = []
b = input()
x = 0
a.append(0)
for i in range(n):
  if b[i] == "I":
    x += 1
  else:
    x -= 1
  a.append(x)
  
print(max(a))

Solution (Python):
N = int(input())
S = input()
ma = 0
count = 0
for i in S:
    count += -1 if i == 'D' else 1
    if ma < count:
        ma = count
print(ma)

Solution (Python):
N = int(input())
S = input()

max_cnt = 0
now_cnt = 0
for i in S:
    if i == 'I':
        now_cnt += 1
    else:
        now_cnt -= 1
    max_cnt = max(max_cnt, now_cnt)

print(max_cnt)

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())


s = input()

ans = 0
x = 0
for i in range(n):
    tar = s[i]
    if (tar == 'I'):
        x += 1
    else:
        x -= 1

    ans = max(x, ans)
    


print(ans)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

po = input()[:-1]
ma = 0
co = 0

for a in po:
    if a == "I":
        co += 1
    else:
        co -= 1
    ma = max(ma,co)
print(ma)

Solution (Python):
N=int(input())
S=str(input())
x,ans=0,0
for i in range(N):
    if S[i]=="I":
        x+=1
        if ans<x:
            ans=x
    elif S[i]=="D":
        x-=1

print(ans)

Solution (Python):
N=int(input())
S=str(input())
x,ans=0,0
for i in range(N):
    if S[i]=="I":
        x+=1
    elif S[i]=="D":
        x-=1
    if ans<x:
        ans=x
print(ans)

Solution (Python):
n = int(input())
s = input()
x = 0
x_max = 0
for i in range(n):
    if s[i] == 'I':
        x += 1
    else:
        x -= 1
    x_max = max(x_max,x)
print(x_max)

Solution (Python):
m,c,n = 0,0, raw_input()
for l in raw_input():
	c += 1 if l == 'I' else -1
	m = max(c,m)
print m

Solution (Python):

N = int(input())
S = input()

l = [0]
x = 0
for i in S:
    if i == 'I':
        x += 1
    else:
        x -= 1
    l.append(x)
print(max(l))

Solution (Python):
_ = int(input())
s = input()
x = 0
ans = 0
for i in s:
    if i == 'I':
        x += 1
        if x > ans:
            ans = x
    else:
        x -= 1
print(ans)

Solution (Python):

def main():
    n = int(input())
    s = input()
    cnt = 0
    ans = 0

    for i in range(n):
        if s[i] == 'I':
            cnt = cnt+1
            ans = max(cnt, ans)
        else:
            cnt = cnt-1
    else:
        print(ans)


if __name__ ==  "__main__":
    main()

Solution (Python):
N = int(input())
S = input()
MAX = 0
Now = 0
for TS in range(0,N):
    Now += [-1,1][S[TS]=='I']
    MAX = max(MAX,Now)
print(MAX)

Solution (Python):
n=int(input())
s=input()
m=0
t=0
for c in s:
    if c=='I':
        t+=1
    elif c=='D':
        t-=1
    m=max(m,t)
print(m)

Solution (Python):


N = int(input())
S = str(input())
sum = 0
L = []
for i in range(N):
    if S[i] == "I":
        sum += 1
        L.append(sum)
    elif S[i] == "D":
        sum -= 1
        L.append(sum)

if max(L) > 0:
    print(max(L))

else:
    print(0)

Solution (Python):
N = int(input())
S = input()
x = 0
ans = 0
for i in range(N):
    if S[i] == "I":
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print(ans)

Solution (Python):
n = int(input())
s = input()

cnt = 0
m = 0

for i in range(len(s)):
    if s[i] == 'I':
        cnt += 1
        m = max(m, cnt)
    if s[i] == 'D':
        cnt -= 1
        m = max(m, cnt)
print(m)

Solution (Python):
N = int(input())
S = input()
x = 0
res = 0
for s in S:
    if(s == "I"):
        x += 1
    elif(s == "D"):
        x -= 1
    res = max(res, x)
print(res)

Solution (Python):
N = int(input())
S = input()
x = 0
ans = 0
for s in S:
  x += 1 if s == "I" else -1
  ans = max(ans, x)
print(ans)

Solution (Python):
a = input()
s = input()

x = 0
m = 0
for i in s:
    if i == 'I':
        x += 1
        m = max(m, x)
    else:
        x -= 1

print(m)

Solution (Python):
n=int(input())
s=input()
x=0
m=-101
for i in s:
  if x>m:
    m=x
  if i=="I":
    x=x+1
  else:
    x=x-1
  if x>m:
    m=x
print(m)

Solution (Python):
N = int(input())
S = input()
x = 0
ans = 0
for i in range(N):
    if S[i] == 'I':
        x += 1
        ans = max(x, ans)
    elif S[i] == 'D':
        x -= 1
print(ans)

Solution (Python):
n = int(input())
s = input()
saidai = 0
x = 0
for i in range(n):
  if s[i] == 'I':
    x += 1
    saidai = max(x, saidai)
  else:
    x -= 1
print(saidai)

Solution (Python):
N = int(input())
S = list(input())

x = 0
ans = 0

for i in S:
    if i =='I':
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
    
print(ans)

Solution (Python):
num = int(input())
new = input()

x = 0
m = 0
for i in range(num):
  if new[i] == "D":
    x -= 1
  if new[i] == "I":
    x += 1
  if m < x:
    m = x
print(m)

Solution (Python):
firstline = int(input())
sec = input()
maxN = 0
init = 0

for i in sec:
  if i == "I":
    init += 1
  else:
    init -= 1
  if init > maxN:
    maxN = init
    
print(maxN)

Solution (Python):
length = int(input())
string = input()
x = 0
m = 0
for i in string:
  if(i == "D"):
    x-=1
  if(i == "I"):
    x+=1
  if(m < x):
    m = x
print(m)

Solution (Python):

def resolve():
    import sys
    input = sys.stdin.readline
    
    
    n = int(input().rstrip())
    s = input().rstrip()

    x = 0
    max_x = 0
    for c in s:
        if c == "I":
            x+=1
            if x > max_x:
                max_x = x
        else:
            x -= 1


    print(max_x)




if __name__ == "__main__":
    resolve()

Solution (Python):
n = int (input ())
s = input ()
x = 0
for i in range (n):
  y = s[:i+1].count ('I') - s[:i+1].count ('D')
  if x < y:
    x = y
print (x)

Solution (Python):
N = int(input())
S = input()
X = [0]
x = 0

for i in S:
    if i == 'I':
        x += 1
        X += [x]
    else:
        x -= 1
        X += [x]
print(max(X))

Solution (Python):
N = int(input())
S = input()
a = 0
sum_a = 0

for i in range(N):
  if S[i]=="I":
    sum_a += 1 
    a = max (a , sum_a)
  else:
    sum_a -= 1
print(a)

Solution (Python):
a = int(input())
b = input()
c = int(0)
d = int(0)
for i in range(a):
  if b[i] == "D":
    c = c - 1
  else:
    c = c + 1
    if c > d:
      d = c

print(int(d))

Solution (Python):
n = int(input())
s = list(input())
ans = 0
x = 0
for i in s:
    if i == "I":
        x += 1
    else:
        x += -1
    ans = max(ans, x)
print(ans)

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

Solution (Python):
def resolve():
    '''
    code here
    '''
    N = int(input())
    S = input()

    res = 0
    ans = 0
    for item in S:
        if item == 'I':
            res += 1
        else:
            res -= 1

        
        ans = max(ans, res)

    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

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

x=0
ans=0
for i in s:
  if i=='I':
    x+=1
  else:
    x-=1
  ans=max(ans,x)

print(ans)

Solution (Python):
N = int(input())
S = (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)

Solution (Python):
n = int(input())
l = list(input())
ans =[0]
for i in range(n):
    if l[i] == "D":
        ans.append(ans[i] - 1)
    else:
        ans.append(ans[i] + 1)
        
print(max(ans))

Solution (Python):
n=int(input())
s=input()
S=len(s)
x=0
X=0
for i in range(S):
    if s[i]=="I":
        x+=1
        if X<x:
            X=x
        
    else:
        x-=1

print(X)

Solution (Python):
n = int(input())
S = input()
ans = 0
x = 0
for s in S:
    if s == "I": x+= 1
    else: x -= 1
    if ans < x: ans = x
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
S = list(input())
ans = 0
x = 0
for s in S:
    if s=='I':
        x+=1
        ans = max(x, ans)
    else:
        x-=1
        ans = max(x, ans)
print(ans)

Solution (Python):
import sys

N = int(sys.stdin.readline())
S = sys.stdin.readline().strip()

ans = 0
tmp = 0
for c in S:
    if c == "I":
        tmp += 1
    elif c == "D":
        tmp -= 1
    ans = max(ans, tmp)

print(ans)

Solution (Python):
N = int(input())
S = list(input())
x = 0
ans = 0
for i in S:
    if i == "I":
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print(ans)

Solution (Python):
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n = int(input())
    s = input()
    ans = 0
    hoge = [ans]
    for i in s:
        if i == "I":
            ans += 1
        else:
            ans -= 1
        hoge.append(ans)
    print(max(hoge))
    return 0

if __name__ == "__main__":
    solve()