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

import sys


def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N = II()
S = IS()
x = 0
max = 0
for s in S:
    if s =="I":
        x += 1
    else:
        x -= 1
    if max < x:
        max = x
print(max)

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

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


if __name__ == '__main__':
    main()

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

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

Solution (Python):
def incre(num,char_obj):
    pos=0
    posmax=pos
    for n in range(num):
        if char_obj[n]=="I":
            pos=pos+1
            if pos>posmax:
                posmax=pos
        else:
            pos=pos-1
    return posmax

num=int(input())
char_obj=input()

print(incre(num,char_obj))

Solution (Python):
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

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

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

x = 0
m = 0

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

Solution (Python):
n = int(input())
S = input()
score = 0
max_score = 0
for s in S:
    score += -1 + 2*(s=='I')
    max_score=max(max_score,score)
print(max_score)

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

Solution (Python):
def test():
    n = int(input())
    s = input()
    result = 0; x = 0
    for i in s:
        if i == "I":
            x += 1
        elif i == "D":
            x -= 1
        result = max(result,x)
    print(result)


if __name__ == "__main__":
    test()

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

print(max(y))

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

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):
def main():
    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)
    return max_x
if __name__ == '__main__':
    print(main())

Solution (Python):
n=int(input())
s=list(input())
a=[0]*(n+1)
for i in range(n):
  a[i+1]=a[i]+[1,-1][s[i]=='D']
print(max(a))

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

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

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

Solution (Python):
n = int(input())
s = input()
ans = [0]
cnt = 0
for i in range(n):
    if s[i] == 'I':
        cnt += 1
    else:
        cnt -= 1
    ans.append(cnt)
print(max(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())

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

Solution (Python):
N = input()
S = input().strip()
x = 0
ans = 0
for c in S:
  if c == 'I':
    x += 1
  else:
    x -= 1
  if ans < x:
    ans = x
print(ans)

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

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

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

print(max(ans))

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

Solution (Python):
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):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
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 = [0]
for i in range(n):
  if s[i]=="I":
    x+=1
    X.append(x)
  else:
    x-=1
    X.append(x)
print(max(X))

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

ans = 0
mx = 0

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

print(mx)

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

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

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

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

ans = 0
cnt = 0
for i in s:
  if i == "I":
    cnt += 1
  else:
    cnt -= 1
  if ans < cnt:
    ans = cnt
print(ans)

Solution (Python):
input()
temp=0
maxV=0
for s in input():
  temp+=1 if s=="I" else -1
  if maxV<temp:maxV=temp 
print(maxV)

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

x=0
l=[0]

for i in range(N):
    if S[i] is "I":
        x+=1
        l.append(x)
    if S[i] is 'D':
        x-=1
        l.append(x)
        
        
out=max(l)
print(out)

Solution (Python):



N = int(input())
S = 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())
ans=0
tmp=0
for i in input():
  if i=='I':
    tmp+=1
  else:
    tmp-=1
  if tmp>ans:
    ans=tmp
print(ans)

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

Solution (Python):
n = int(input())
s = list(input())
x = 0
ans = [0]
for s_ in s:
    if s_ == "I":
        x += 1
    else:
        x -= 1
    ans.append(x)
print(max(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
    m = max(x, m)
print(m)

Solution (Python):

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

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 




 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    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)
    
if __name__ == "__main__":
	main()

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

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


if __name__ == '__main__':
    main()

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

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

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

ans=[0]*(n+1)
for i,s in enumerate(S):
  if s=="I":
    ans[i+1]=ans[i]+1
  elif s=="D":
    ans[i+1]=ans[i]-1

print(max(ans))

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

S = input()

x = 0
maxx= 0

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

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

Solution (Python):
N = int(input())
S = input()
x = 0
ans = []
ans.append(x)

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

print(max(ans))

Solution (Python):
N = int(input())
S = input()
r = 0
x = 0
for c in S:
  if c == "I":
    x += 1
  if c == "D":
    x -= 1
  if x > r:
    r = x
print(r)

Solution (Python):
from sys import stdin
N = int(stdin.readline())
S = stdin.readline()
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()

x = 0
ans = 0

for c in S:
    if c == 'I':
        x += 1
    else:
        x -= 1
    if ans < x:
        ans = x

print(ans)

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

print(max(ans))

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

Solution (Python):

def main():
    _, S = tuple(input() for _ in range(2))
    ans, x = [0], 0
    for i in S:
        x += 1 if i == "I" else -1
        ans += [x]
    print(max(ans))


if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
S=input()
x=0
max_val=0
for s in S:
  x+={'I':+1, 'D':-1}[s]
  max_val=max(max_val,x)
print(max_val)

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

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

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

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

x=0
array=[x]

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

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

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

Solution (Python):

count = raw_input()
s = raw_input()
max, sum = 0, 0

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

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

x = 0
ans = 0

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

print(ans)

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

x = 0
ans = [0]

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

print(max(ans))

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

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

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

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

x,m = 0, 0

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

print(m)

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

Solution (Python):
N = int(input())
S = input()
MAX = 0
res = 0
for i in S:
  if i == 'I':
    res += 1
    MAX = max(MAX,res)
  elif i == 'D':
    res -= 1
    MAX = max(MAX,res)
  else:
    pass
print(MAX)

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

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

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

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

ans = [0]
cnt = 0
for i in range(n):
    if s[i] == "I":
        cnt += 1
    else:
        cnt -= 1
    ans.append(cnt)
print(max(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 = input()
counter = []
num = 0
for s in S:
    if  s == 'I':
        num += 1
        counter.append(num)
    elif s == 'D':
        num -= 1
        counter.append(num)

arg_max = max(counter)
if arg_max <= 0:
    print(0)
else:
    print(arg_max)

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

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

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

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

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

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

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

x = 0
m = 0
for c in s:
    if c == "I":
        x += 1
        m = max(m, x)
    elif c == "D":
        x -= 1
print(m)

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

x_max = 0
x = 0
for c in S:
  if c == "I":
    x += 1
    x_max = max(x_max, x)
  if c == "D":
    x -= 1
print(x_max)

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

print(max(x_list))

Solution (Python):
A= int(raw_input())
S = list(raw_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 = 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
mx = 0
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
mx = 0

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

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

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

Solution (Python):
N=int(input())
ans=c=0
s=input()
for i in range(N):
    if s[i]=="I":
        c+=1
        ans=max(c,ans)
    if s[i]=="D":
        c-=1
        ans=max(c,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
    elif s[i] == 'D':
        x -= 1
    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
  elif s[i] == "D":
    x -= 1
  ans = max(ans,x)   
print(ans)

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

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

print(ansMax)

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

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

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

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

s=list(input())

ans=0
t=[0]

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

print(max(t))

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

Solution (Python):
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)

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

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

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

Solution (Python):
input()
S = input()
ans = 0
x = 0
for s in S:
    if s == 'I':
        x += 1
        if ans < x:
            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 = list(input())
x = 0
max = 0
for i in range(N):
    if S[i] == "I":
        x += 1
    elif S[i] == "D":
        x -= 1
    if x > max :
        max = x
print(max)

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

Solution (Python):

import sys, math, fractions, itertools


def solve(N: int, S: str):
    counter = 0
    mx = 0
    for i in range(N):
        if S[i] == 'I':
            counter += 1
        else:
            counter -= 1
        if mx < counter:
            mx = counter
    print(mx)
    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 = list(map(str, input()))

res = [0]
temp = 0
for i in s:
    if i == 'I':
        temp += 1
    elif i == 'D':
        temp -= 1
    res.append(temp)

print(max(res))

Solution (Python):
N=int(input())
S=input()
x=0
ans=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
tmpmax = 0
for char in s:
  if char == 'I':
    x += 1
    if x > tmpmax:
      tmpmax = x
  else:
    x -= 1
print (tmpmax)

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

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

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

Solution (Python):
N = int(input())
s = list(input())
a = [0] * (N+1)
x = 0
for i in range(N):
    if s[i] == 'I':
        x += 1
        a[i] = x
    else:
        x -= 1
        a[i] = x

print(max(a))

Solution (Python):
n=int(input())
s=list(input())
from collections import Counter
sd=Counter(s)

maxn=0
tmp=0
for si in s:
	if si=='I':
		tmp+=1
	else:
		tmp-=1
	if tmp>maxn:
		maxn=tmp
		
print(maxn)

Solution (Python):

from collections import defaultdict
import sys

def soinsuu(soinsuu_dic, num):
    for i in range(2, int(num ** 0.5) + 1):
        while num % i == 0:
            num //= i
            soinsuu_dic[i] += 1
    if num > 1:
        soinsuu_dic[num] += 1
    return soinsuu_dic

def main():
    num = int(input())
    data = list(input())

    now_ele = 0
    ans = now_ele
    for ele in data:
        if ele == 'I':
            now_ele += 1
        else:
            now_ele -= 1
        ans = max(ans, now_ele)

    print(ans)




if __name__ == '__main__':
    main()

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

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

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

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

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

for i in range(N):
    if S[i] == 'I':
        x += 1
    elif S[i] == 'D':
        x -= 1
    if xmax < x:
        xmax = x

print(xmax)

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

Solution (Python):
input()
a = input()
maxi = 0
now = 0
for c in a:
  if c == 'I':
    now += 1
  else:
    now -= 1
  maxi = max(now, maxi)
print(maxi)

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 x > max_x:
        max_x = x

print(max_x)

Solution (Python):
def larger(x, y):
	if x > y:
		return x
	return y

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

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

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

print(res)

Solution (Python):
n = int(input())
s = input()
 
mx = 0
current = 0
for c in s:
  if c == "I":
    current += 1
  elif c == "D":
    current -= 1
  if current > mx:
    mx = current
 
 
print(mx)

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

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

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b, c, d = LI()
    print(max(a * b, c * d))
    return


def B():
    _ = II()
    s = S()
    d = {}
    d["I"] = 1
    d["D"] = -1
    ans = 0
    now = 0
    for i in s:
        now += d[i]
        ans = max(ans, now)
    print(ans)
    return


def C():
    return


def D():
    return


if __name__ == '__main__':
    B()

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

Solution (Python):
N=int(input())
S=input()
arr=[]
v=0
for s in S:
	if s=="I":
		v+=1
		arr.append(v)
	else:
		v-=1
		arr.append(v)
print(max(0,max(arr)))

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(N: int, S: str):
    ret = 0
    cur = 0
    for c in S:
        if c == 'I':
            cur += 1
            ret = max(ret, cur)
        else:
            cur -= 1
    print(ret)
    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()
ans=0
li=[0]
for s in S:
  if s=="I":
    ans+=1
    li.append(ans)
  else:
    ans-=1
    li.append(ans)
print(max(li))

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

x,a=0,0
for l in s:x+=-1+2*(l=='I');a=max(a,x)
print(a)

Solution (Python):
import numpy as np


N = int(input())
S = [1 if e == 'I' else -1 for e in input()]
print(max(max(np.cumsum(S)), 0))

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

for c in s:
    x += 1 if c == 'I' else -1
    if x > result:
        result = x

print(result)

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

Solution (Python):
n=int(input())
s=input()
a,m,x=0,0,0
while True:
    if s[a]=='I':
        x+=1
    else:
        x-=1
    m=max(m,x)
    a+=1
    if a==n:
        break
print(m)

Solution (Python):
import sys
operaciones = list()
p=0
lines = sys.stdin.readlines()
for linea in lines:
    c = linea.split()
    c = list(map(str,c))
list(c)
x = c[0]
a = list(x)
for k in range(len(a)):
  if a[k]== "I":
    p+=1
    operaciones.append(p)
  if a[k] == "D":
    p-=1
    operaciones.append(p)
mayor=operaciones[0]
for i in range(len(operaciones)):
    if operaciones[i]>mayor:
        mayor=operaciones[i]
if mayor <0:
  print(0)
else:  
  print(mayor)

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

x = 0
A = 0

for i in range(N):
    if S[i] == 'D':
        x -= 1
        A = max(A, x)
    else:
        x += 1
        A = max(A, x)

print(A)

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

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