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):
x = 0
_n = input()
s = input()
maxX = x
for c in s:
    x = x + (1 if c == "I" else -1)
    maxX = max(maxX, x)
print(maxX)

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

x = 0
ret = 0

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

Solution (Python):
n=int(input())
l=list(str(input()))
ans=0
tmp=0
for i in l:
    if i=="I":tmp+=1
    else:tmp-=1
    if tmp>ans: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
        if ans < x:
            ans = x
    elif i == 'D':
        x -= 1
print(ans)

Solution (Python):

ans = 0

now = 0

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

for i in S:

    if i == "I":
        now += 1

    else:
        now -= 1

    ans = max(now,ans)

print (ans)

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

ans = 0
temp = 0

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

print(ans)

Solution (Python):
def main():
    n =int(input())
    s = list(input())
    x = 0
    ans = 0
    for i in s:
        if i =='I':
            x += 1
            if ans < x:
                ans = x
        else:
            x -=1
    print(ans)
if __name__ == '__main__':
    main()

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

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

print(res)

Solution (Python):
n = int(input())
s = input()
isum = 0
imax = 0

for i in range(n):
    if s[i] == "I":
        isum += 1
        if imax < isum:
            imax = isum
    else:
        isum -= 1
print(imax)

Solution (Python):
from collections import Counter

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
ans = [0]
for i in S:
  if i == 'I':
    x += 1
    ans.append(x)
  elif i == 'D':
    x -= 1
    ans.append(x)
print(max(ans))

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

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

print(max_x)

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

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

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

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
S = (stdin.readline().rstrip())
ans = 0
tmp = 0
for i in S:
    if i == "I":
        tmp += 1
    else:
        tmp -= 1
    ans = max(ans,tmp)
print(ans)

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

l_a = []
l_b = [0]
x = 0

for i in s:
    if i == 'I':
        l_a.append(1)
    else:
        l_a.append(-1)
        
for j in l_a:
    l_b.append(x + j)
    x += j

ans = max(l_b)

print(ans)

Solution (Python):
n = int(input())
s = input()
max = 0
tmp = 0
for i in s:
    if i == 'I':
        tmp += 1
        if tmp > max:
            max = tmp
    if i == 'D':
        tmp -= 1
print(max)

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

for r in range(0,n):
    if(s[r] == "I"):
        x += 1
    else:
        x -= 1
    a.append(x)
print(max(a))

Solution (Python):
N = int(input())
S = input()
cur = 0
ans = 0
for s in S:
    if s == "I":
        cur += 1
        if cur > ans:
            ans = cur
    elif s == "D":
        cur -= 1
print(ans)

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

Solution (Python):
a = int(input())
b = input()
c = [0]
x = 0

for i in range(a):
  if b[i]=="I":
    x+=1
    c.append(x)
  else:
    x-=1
    c.append(x)
else:
  print(max(c))

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

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

    print(max_num)


if __name__ == "__main__":

    main()

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

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

lst = [0]
for c in s:
    if c=='I':
        x += 1
    elif c=='D':
        x -= 1
    lst.append(x)
print(max(lst))

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

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

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

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

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

max_x = 0
x = 0
for s in S:
    if s == 'I':
        x += 1
    else:
        x -= 1
    
    if max_x < x:
        max_x = x

print(max_x)

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

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

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

Solution (Python):
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 = list(input())
ctr = 0
max_ctr = 0

for i in range(N):
    if S[i] == "I":
        ctr += 1
    else:
        ctr -= 1
    if max_ctr < ctr:
        max_ctr = ctr
print(max_ctr)

Solution (Python):
n = list(map(int, input().split()))
n = n[0]
s = list(map(str, input().split()))
s = s[0]

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



print(maxim)

Solution (Python):
n = list(map(int, input().split()))
n = n[0]
s = list(map(str, input().split()))
s = s[0]

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



print(maxim)

Solution (Python):
n=int(input())
s=input()
x_list=[0]
for i in range(n):
	if s[i]=='I':
		x_list.append(x_list[i]+1)
	elif s[i] == 'D':
		x_list.append(x_list[i]-1)
x_list.sort()
print(x_list[-1])

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

Solution (Python):

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

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

x = [0]

for i, s in enumerate(S):
    if s == "I":
        x.append(x[i] + 1)
    else:
        x.append(x[i] - 1)

print(max(x))

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

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

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

x = 0
max = 0

for i in s:
    if i == "I":
       x = x + 1
       if max < x:
           max = x
    else:
        x = x - 1

print(max)

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

Solution (Python):
n=int(input())
s=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 = str(input())
ans = [0 for i in range(0, N + 1)]
for i in range(0, N):
    if S[i] == "I":
        ans[i + 1] = ans[i] + 1
    else:
        ans[i + 1] = ans[i] - 1
print(max(ans))

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
S = s()

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)

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):
def abc():
    n = int(input())
    s = input().rstrip()
    x = 0
    ans = 0
    for i in range(n):
        if s[i] == 'I':
            x += 1
        if s[i] == 'D':
            x -= 1
        ans = max(ans, x)
    print(ans)


abc()

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

Solution (Python):
n=int(input())
s=input()
ans=0
temp=0
for i in range(n):
  if s[i]=="D":
    temp-=1
  elif s[i]=="I":
    temp+=1
  if temp>ans:
    ans=temp
print(ans)

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

x = 0
li = [0]

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

Solution (Python):
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")







N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()
S = np.array(list(S))
a = np.zeros(N)
a[S == 'I'] = 1
a[S == 'D'] = -1
print(max(0, int(a.cumsum().max())))

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

S = list(S)
count = 0
ans = 0

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

print(ans)

Solution (Python):
N = int(input())
S = input()
x = 0
ans = 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]
ans=0
for s in S:
  if s=="I":
    ans+=1
    Ans.append(ans)
  else:
    ans-=1
    Ans.append(ans)
print(max(Ans))

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

x, ma = 0, 0
for s in S:
    if s == "I":
        x += 1
        ma = max(ma, x)
    else:
        x -= 1

print(ma)

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

Solution (Python):

import time
import re
import math

def main():
    n=int(input())
    s=input()
    x=0
    mx=0
    for a in s:
        if(a=='I'):x+=1
        elif(a=='D'):x-=1

        mx=max([mx,x])
    print(mx)
main()

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

score = []
x = 0
score.append(x)
for ss in s :
    if (ss == "D") :
        x -= 1
    else :
        x += 1
    score.append(x)

print(max(score))

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

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

Solution (Python):

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

Solution (Python):
n = int(input())
s = input()
ans = 0
lst = []
for i in s:
    if i == 'I':
        ans += 1
    else:
        ans -= 1
    lst.append(ans)    

if max(lst) > 0:
    print(max(lst))
else:
    print(0)

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

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

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

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

x = 0
answer = 0
for c in S:
  if c == 'D':
    x -= 1
  else:
    x += 1
  answer = max(answer,x)

print(answer)

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

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

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

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

print(ans)

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

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

print(ans)

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

id=list(input())

nums=[0]

for i in id:
    if i=="I":
        nums.append(1)

    else:
        nums.append(-1)

ans=[]

for i in range(len(nums)-1):
    ans.append(nums[i]+nums[i+1])
    nums[i+1]=nums[i]+nums[i+1]

if max(ans)<0:
    print("0")

else:
    print(max(ans))

Solution (Python):
x=0
x_max = 0

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

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

print(x_max)

Solution (Python):


def solve():
    N = int(input())
    S = input()

    ans = 0
    x = 0

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


if __name__ == "__main__":
    solve()

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

ans = 0
for i in range(1,N+1):
  ans = max(S[:i].count('I')-S[:i].count('D'),ans)

print(ans)

Solution (Python):
n = int(input())
s = 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("{}".format(max(ans)))

Solution (Python):


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

ans = 0
x = 0

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

    ans = max(ans, x)

print(ans)

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

ans = 0
mx = 0
for i in S:
	if i == 'I':
		mx += 1
	else:
		mx-=1

	if ans < mx:
		ans = mx

print(ans)

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

Solution (Python):

"""
B - Increment Decrement
https://atcoder.jp/contests/abc052/tasks/abc052_b

"""
import sys


def solve(N, S):
    x = 0
    results = [x]
    for s in S:
        if s == 'I':
            x += 1
        else:
            x -= 1
        results.append(x)
    return max(results)


def main(args):
    N = int(input())
    S = input()
    ans = solve(N, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

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

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

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

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

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 


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):
s=int(input())
list=list(input())
temp=0
ans_list=[0]

for i in range(len(list)):
    if list[i]=='I':
        temp=temp+1
    elif list[i]=='D':
        temp=temp-1
    ans_list.append(temp)

print(max(ans_list))

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

Solution (Python):
N = int(input())
S = input()
ans = 0
que = 0
for i in S:
    if i=="I":
        que += 1
    else:
        que -= 1
    if ans < que:
        ans = que
print(ans)

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

x = 0
max_x = 0
for i in s:
  if i == "D":
    x -= 1
  else:
    x += 1
  max_x = max(x, max_x)
print(max_x)

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

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

Solution (Python):
n = int(input())
s = list(input())
ans = 0
x = 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
x_list = [0]

for i in S:
    if i == "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()
x = 0
ans = []
ans.append(x)

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

print(max(ans))

Solution (Python):
n = int(input())
s = input()
x = 0
xmax = 0
for i in s:
    if i == "I":
        x += 1
    elif i == "D":
        x -= 1
    if x >= xmax:
        xmax = x
print(xmax)

Solution (Python):
n=int(input())
s=input()
l=[0]
count=0
for num in range(n):
    if s[num]=='I':
        count += 1
        l.append(count)
    else:
        count -= 1
        l.append(count)
print(max(l))

Solution (Python):
from fractions import *
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(x, ans)

print(ans)

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

x = 0
maxx = 0
for c in s:
    if c == 'I':
        x += 1
    else:
        x -= 1

    maxx = max(maxx, x)

print(maxx)

Solution (Python):
input_n=input()
input_s=input()
tmp=0
x = 0
for i in input_s:
  if i == "I":
    x=x+1
  else:
    x=x-1
  tmp=max(tmp,x)

print(tmp)

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

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

for i in range(n):
    if s[i]=="I":
        ma+=1
        if max<=ma:
            max=ma
    else:
        ma-=1
print(max)

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

X = []
X.append(0)

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

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

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

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

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline

n = input()
S = input().rstrip()
max_count = 0
count = 0
for s in S:  
  count += 1 if s=='I' else -1
  max_count = max(count, max_count)
print(max_count)

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

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

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

ans = 0

x = 0

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

print(ans)

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

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

print(ans)

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

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

Solution (Python):
from itertools import accumulate
N=int(input())
S=input()
s=[0]
for i in range(N):
    if S[i]=='I':
        s.append(1)
    else:
        s.append(-1)
a=list(accumulate(s))
print(max(a))

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.append(a)
print(max(ans))

Solution (Python):
input()
x=[0]
for c in input():x.append(x[-1]+2*(c=="I")-1)
print(max(x))

Solution (Python):
input()
s=input()
ans=0
x=0
for c in s:
    x+=2*(c=="I")-1
    ans = max(ans,x)
print(ans)

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

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


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

if __name__ == '__main__':
    N = int(input())
    S = input()
    
    solve(N, S)

Solution (Python):


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

if __name__ == '__main__':
    N = int(input())
    S = input()
    
    solve(N, S)

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

Solution (Python):
input()
S = input()
cnt = 0
maxN = 0
for i in S:
    cnt += 1 if i=='I' else -1
    maxN = max(maxN, cnt)
print(maxN)

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

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
  if x > ans:
    ans = x
print(ans)

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

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

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

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

print(ans)

Solution (Python):
N = input()
S = list(input())
i = 0
j = 0
for s in S:
  j += 1 if s == 'I' else -1
  i = max(i,j)
print(i)

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

l  = [1 if i == "I" else -1 for i in list(x)]
ll = [sum(l[:i]) for i in range(n+1)]

print(max(ll))

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

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

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

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

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

x = 0
x_max = 0
for letter in s:
    if letter == 'I':
        x += 1
    else:
        x -= 1

    x_max = max(x_max, x)

print(x_max)

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

ans = 0
x = 0
for c in S:
    if c == 'I':
        x += 1
        if ans < x:
            ans = x
    elif c == 'D':
        x -= 1
print(ans)

Solution (Python):

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

Solution (Python):

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

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

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

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

Solution (Python):
N = int(input())
S = input()
t = m = 0
for s in S:
    t += 1 if s == 'I' else -1
    if t > m:
        m = t
print(m)

Solution (Python):


n = int(input())
s = str(input())
ret = 0
mx = 0
for c in s:
  if c=='I':
    ret += 1
  elif c=='D':
    ret -= 1
  if ret >= mx:
    mx = ret

print(mx)

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

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

x = 0
x_max = 0
for i in range(N):
    if S[i] == 'I':
        x += 1
    elif S[i] == 'D':
        x -= 1
    x_max = max(x_max, x)

print(x_max)

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

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

Solution (Python):
def main():
	N = int(input())
	S = input()
	x = 0
	max_x = 0
	for c in S:
		if c == "I":
			x += 1
		if c == "D":
			x -= 1
		max_x = max(max_x, x)
	print(max_x)


if __name__ == '__main__':
	main()

Solution (Python):


def read_input():
    n = int(input())
    s = input().strip()

    return n, s

def submit():
    n, s = read_input()

    x = 0
    max = x

    for c in s:
        if c == 'I':
            t = 1
        else:
            t = -1

        x += t

        if max < x:
            max = x

    print(max)


if __name__ == '__main__':
    submit()

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

Solution (Python):

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

c=0
mx=0

for x in S:
  if x=='I':
    c+=1
  elif x=='D':
    c-=1

  
  mx=max(mx,c)


print(mx)

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

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

Solution (Python):

n = int(input())
s = input()
ans = 0
temp = 0
for i in range(len(s)):
    if s[i]=='I':
        temp += 1
        if temp>ans:
            ans = temp
    else:
        temp -= 1
print(ans)

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

x, ans = 0, 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
mx = 0
for i in range(N):
    if S[i] == "I":
        ans += 1
        mx = max(mx,ans)
    else:
        ans -= 1
print(mx)

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

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

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

print(max_ans)