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 = input()
x = 0
ans = 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 = str(input())
x = 0
m = x
for i in range(n):
    if s[i] == "I":
        x += 1
    elif s[i] == "D":
        x -= 1
    if x > m:
        m = x
print(m)

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

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

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

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

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):
from collections import defaultdict

d = defaultdict(int)

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

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

ans = [0]
for k, v in d.items():
    ans.append(v)

print(max(ans))

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

Solution (Python):
n=int(input())
s=str(input())
x=0
l=[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):
N=int(input())
S=str(input())
x = 0
max_num = 0
for i in range(N):
  if S[i] == 'I': x = x + 1
  if S[i] == 'D': x = x - 1
  if max_num < x:
    max_num = x
print(max_num)

Solution (Python):
n=int(input())
s=list(str(input()))
m=0
t=0
for i in range(len(s)):
  if s[i]=='I':
    t+=1
  else:
    t-=1
  if t>m:
    m=t
print(m)

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

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

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

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

print(max(l))

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):
import sys
readline = sys.stdin.buffer.readline

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

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
    elif s[i] == 'D':
        x -= 1
    ans = max(ans, x)
print(ans)

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

Solution (Python):
input()
s=input()
ans=0;
cu=0
for c in s:
  if c=='I':
    cu+=1
  else:
      cu-=1
  ans=max(ans,cu)
  
print(ans)

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

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

print(max(x))

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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):
N = int(input())
S = input()
x = 0
Max = 0
for i in range(0,N):
    if(S[i] == 'I'):
        x += 1
    else:
        x -= 1
    if(x > Max):
        Max = x
print(Max)

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

pts, ans = 0, 0
for s in S:
  if s == "I":
    pts += 1
  else:
    pts -= 1
  ans = max(ans, pts)
print(ans)

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

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

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

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(x,ans)

print(ans)

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


if __name__ == '__main__':
    main()

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

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

    ans = max(cnt, ans)

print(ans)

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

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

print(max(X))

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

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

Solution (Python):
N=int(input())
S=list(input())
x=0
maxx=0
for i in S:
  if i=='I':
    x+=1
  elif i =='D':
    x-=1
  if x>maxx:
    maxx=x
print(maxx)

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

x=0
ans=0
for i in range(len(s)):
    if s[i]=='I':
        x+=1
    if s[i]=='D':
        x-=1
    if ans<x:
        ans=x
print(ans)

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

x = 0
res = 0
for op in list(s):
    if op=="I":
        x += 1
    else:
        x -= 1
    res = max(res, x)
print(res)

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

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

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

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

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

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

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

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())
s = 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))

Solution (Python):
input()
slist=list(input())
max=0
count=0
for a in slist:
    if a=="I":
        count+=1
        if count>max:
            max=count
    else:
        count-=1
print(max)

Solution (Python):
n = int(input())
s = input()
x = 0
ans = 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 = input()
x = 0
m = 0
for i in s:
    if i == 'I':
        x += 1
    else:
        x -= 1
    m = max(x, m)
print(m)

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

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())
l=list(map(str,input()))
count=0
lis=[0]
for i in range(n):
    if  l[i]=='D':
        lis.append(count-1)
        count-=1
    else:
        lis.append(count+1)
        count+=1
print(max(lis))

Solution (Python):
nim = int(input())
mike = input()
x = 0
y = 0
for i in mike:
    if i == 'I':
        x+=1
        if y<x:
            y=x
    else:
        x-=1
print(y)

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

maxv = 0
tmp = 0

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

    if maxv < tmp:
        maxv = tmp

print(maxv)

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

print(ans)

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

ans = 0
x = 0
for s in S:
  v = 1 if s == 'I' else -1
  x += v
  ans = max(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
    else:
        x -= 1
        
    ans = max(ans,x)
    
print(ans)

Solution (Python):

def myAnswer(N:int,S:list) -> int:
   
   ans = 0
   x = 0
   for i in  S:
      if(i == "I"):
         x +=1
      elif(i == "D"):
         x -= 1
      ans = max(ans,x)
   return ans


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   S = list(input())
   print(myAnswer(N,S[:]))

if __name__ == '__main__':
   main()

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

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

print(maximum)

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

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

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
s = ns()

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

print(ans)

Solution (Python):

n = int(input())
s = list(input())
max = 0
count = 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):
def main():
    N = int(input())
    S = input()

    x = 0
    maxval = 0

    for i in range(N):
        if S[i] == "I":
            x += 1
            if maxval < x:
                maxval = x
        elif S[i] == "D":
            x -= 1
            if maxval < x:
                maxval = x
    print(maxval)
main()

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

ans = [0]
cnt = 0
for si in s:
    if si == "I":
        cnt += 1
    else:
        cnt -= 1
    
    ans.append(cnt)

print(max(ans))

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

Solution (Python):
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

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

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

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

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

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

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

x = 0

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

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

x = 0

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

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

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

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    S = input().rstrip()

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


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


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,s=open(0).readlines()
ans=0
now=0
for i in list(s):
    if i=="I":now+=2
    now-=1
    ans=max(ans,now)

print(ans)

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

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

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

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

x = 0
ans = 0

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

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

for c in s:
    if c == 'I':
        now_num += 1
    else:
        now_num -= 1
    if now_num > max_num:
        max_num = now_num

print(int(max_num))

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

max = 0
x = 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()
x = m = 0
for i in range(n): x += [-1,1][s[i] == "I"]; m = max(m,x)
print(m)

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

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

Solution (Python):
import itertools

n = int(input())
s = list(input())
s1 = [1 if s[i] == 'I' else -1 for i in range(n)]
cumsum = list(itertools.accumulate(s1))
ans = max(cumsum)
print(max(ans, 0))

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

x=0
maxx=0

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

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

x = 0
mx = 0
for i in S:
    if i == "I":
        x += 1
        mx = max(mx, x)
    else:
        x -= 1
        mx = max(mx, x)
print(mx)

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

Solution (Python):

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

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

num = 0
max_num = num

for l in S:
    if l == 'I':
        num += 1
    else :
        num -= 1
    if num > max_num:
        max_num = num
        
print(max_num)

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

x = 0
M = 0
for c in S:
    if c == 'I':
        x += 1
    else:
        x -= 1
    if x > M:
        M = x
print(M)

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)
a = max(ans)
print(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):
max,cost = 0,0
N = int(input())
S = input()

def update(max,cost):
    a = max
    if cost > a:
        a = cost
    return a

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

print(max)

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

s=input()

ans = [0]*n

for i in range(len(s)):
    if s[i] == 'I':
        ans[i] = ans[i-1]+1
    else :
        ans[i] = ans[i-1]-1
ans.sort()
print(max(ans[-1],0))

Solution (Python):
N=int(input())
S=input().rstrip()
m=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 = [i for i in 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))

Solution (Python):

import sys
import itertools
import fractions
import copy
import bisect


from operator import itemgetter
from sys import stdin

from operator import mul
from functools import reduce
from collections import Counter


N=3
M=3
i=0
j=0
k=0
n=3
x=0
a=[0]*5
b=[]
ans=0




N=int(input())

"1行1つの整数を入力を取得し、整数と取得する"
s=input()
a=[i for i in s]
for i in range(len(s)):
     
     if a[i]=="I":
         ans=ans+1
         x=max(ans, x)
     if a[i]=="D":
         ans=ans-1

print(x)


"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

for i in number_list:
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''



"正方行列にstr型の値を入力"
'''




'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''











'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''




"aという変数に入っているものを大文字にして出力"

















'''
def cmb(n,r):
    
    r= min(n-r,r)
    
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    
    
    

    under = reduce(mul, range(1, r+1))
    
    
    
    

    return over // under
    
    
    
    
a = cmb(n, r)

'''

'''




for i in a.most_common(n):print(i)





 


'''









'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

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

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

print(tmp)

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

x=0
maxx=0
for i in range(N):
    if S[i]=="I":
        x=x+1
        if maxx<x:
            maxx=x

    elif S[i]=="D":
        x=x-1
        
        

print(maxx)

Solution (Python):




"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""





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

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

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

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

Solution (Python):
n=int(input())
s=input()
li=[]
ans=0
li.append(ans)

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

print(max(li))

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

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

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

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

x = 0
max_x = 0
for s in S:
  if (s == 'I'):
    x += 1
  elif (s == 'D'):
    x -= 1
  
  if (max_x < x):
    max_x = x

print(max_x)

Solution (Python):
n = int(input())
s = input()
r_list = list()
x = 0
r_list.append(x)
for t in s:
	if t == 'I':
		x = x + 1
	else:
		x = x - 1
	r_list.append(x)
print(max(r_list))

Solution (Python):



N = int(input())
S_list = list(input())


x_list = [0 for i in range(N)]
for i in range(N):
    x_before = 0
    if i != 0:
        x_before = x_list[i-1]

    if S_list[i] == "I":
        x_list[i] = x_before + 1
    elif S_list[i] == "D":
        x_list[i] = x_before - 1

print(max(max(x_list), 0))

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

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

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

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

x = 0
result = 0

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

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

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):
def main():
    n = int(input())
    s = list(input())

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

    print(ans)
if __name__ == '__main__':
    main()

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

Solution (Python):

import math
import itertools
import statistics

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

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

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

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

x = 0
x_max = 0
for s in S:
    if s == "I":
        x += 1
        if x_max < x:
            x_max = x
    else:
        x -= 1

print(x_max)

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(ans,x)
print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
t=0
for ss in s:
    if ss=='I':
        t+=1
    else:
        t-=1
    ans=max(ans,t)
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 = 0
ans = 0
for s in S:
    if s == "I":
        x += 1
    else:
        x -= 1
    if x > ans:
        ans = x
print(ans)

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

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

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, S: str):
    x = 0
    anx = 0
    for i in range(N):
        if S[i] == 'I':
            x += 1
        else:
            x -= 1
        anx = max(anx, x)

    print(anx)

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

import sys
input = sys.stdin.readline

n = int(input())
s = input().rstrip()
ans = 0
val = 0
for ch in s:
  if ch == "I":
    val += 1
    ans = max(ans, val)
  elif ch == "D":
    val -= 1
print(ans)

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

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

print(ans)