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-----
5
IIDID

-----Sample Output-----
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.

Difficulty: introductory

Starter code:

Solutions:
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)


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)

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)

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

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)

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)

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)

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

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

n = int(input())
s = input()
res = x = 0
for s_ in s:
  if s_=="I":
    x+=1
  else:
    x-=1
  res = max(res, x)
print(res)

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)


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)

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

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)


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

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

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

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)

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)


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)

import sys, math
from itertools import combinations as c, product as p
from collections import deque
sys.setrecursionlimit(10**9)


def si(): return input()
def ii(): return int(input())
def fi(): return float(input())
def lstr(): return input().split()
def lint(): return list(map(int, input().split()))
def lint_dec(): return list(map(lambda x:int(x) - 1, input().split()))
def lnstr(n): return [input() for _ in range(n)]
def lnint(n): return [int(input()) for _ in range(n)]
def lint_list(n): return [lint() for _ in range(n)]



############################################################
N = ii()
S = si()
x = 0
ans = 0

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

print(ans)

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


cnt = int(input())
string = input()
x = [0]

i = 0
for _ in string:
    if _ == "I":
        i += 1
        x.append(i)
    else:
        i -= 1
        x.append(i)

print(max(x))

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)

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)

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)

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

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

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)


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)

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)

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)

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)

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)

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

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)

# coding: utf-8

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)

n = int(input())
s = list(input())
cnt = 0

for i in range(n):
    cnt = max(cnt, s[0:i+1].count("I") - s[0:i+1].count("D"))

print(cnt)

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)


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

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

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)

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)

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)

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

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)

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


def __starting_point():
    main()
__starting_point()

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

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)

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)

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)

#-*-coding:utf-8-*-
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))

def __starting_point():
    main()
__starting_point()

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) 

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)

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)

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)


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)

n = int(input())
s = input()
x = 0
y = 0

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

print(y)

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)

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)

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)

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)

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)

n = int(input())
s = input()
maxnum = 0
cnt = 0
for i in range(len(s)):
    if s[i] == 'I':
        cnt += 1
        if cnt >= maxnum:
            maxnum = cnt
    elif s[i] == 'D':
        cnt -= 1
print(maxnum)

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)

# 31
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)

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

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)

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

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)

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)

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)


N = int(input())
S = input()
x = 0
X = [0]*(N+1)

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


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)

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)


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


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)

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)


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)

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

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

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)

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)

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)

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)


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)

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

print(ans)

# -*- coding:utf-8 -*-
N = int(input())
S = input()

ans = 0
max = 0

for s in S:
    if s == 'I':
        ans += 1
    else:
        ans -= 1
    
    if max < ans:
        max = ans

print(max)

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)


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)

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

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)

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)

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)

n = int(input())
s = input()
max = 0
sum = 0
for i in s:
    if(i == 'I'):
        sum += 1
        if(max < sum):
            max = sum
    else:
        sum -= 1
print(max)

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)


def __starting_point():
    main()
__starting_point()

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

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)


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)

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)