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.



Sample input:
5
IIDID


Sample output:
2

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC052B - Increment Decrement
_ = 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))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 入力
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = [0] * (N + 1)  # ansはi番目までのxの値をメモする配列
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))

Submission status: Accepted

Solution code:
#52
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding utf-8 -*-
n=int(input())
s=list(str(input()))
ans=0
h=[0]
for i in range(n):
    if  s[i]=="I":
        ans+=1
        h.append(ans)
    elif s[i]=="D":
        ans-=1
        h.append(ans)
print(max(h))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s =input()
x = 0
xmax = 0
for i in s:
    if i =='I':
        x +=1 
        xmax = max(xmax,x)
    else:
        x -=1
print(xmax)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())
word = input()

maxi = 0
x = 0
for i in word:
  if i=='I': x+=1
  else: x-=1
  if x>maxi: maxi=x

print(maxi)

Submission status: Accepted

Solution code:
n = int(input())

res = 0
sum = 0
for s in input():
    if "I" == s:
        sum+=1
    elif "D" == s:
        sum-=1
    if sum > res: res = sum

print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = input().rstrip()
x = 0
ans = 0
for c in s:
    if c == "I":
        x+=1
    elif c == "D":
        x-=1
    ans = max(ans, x)

print(ans)

Submission status: Accepted

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

x = [0]

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

print(max(x))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt,x,y,m=0,0,0,0

for i in range(n):
    if s[i] == "I":
        cnt += 1
        m = max(cnt,m)

    else:
        cnt -= 1

print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=input()
s=input()
while "DI" in s:
    s=s.replace("DI","")
print(s.count("I"))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#https://atcoder.jp/contests/abc052/tasks/abc052_b

def main():
    x = 0
    N = input()
    S = raw_input()
    
    # アルゴリズムを考えるよりも、 1 <= N <= 100 であるからすべてなめたほうが早い
    x_max = x
    for ope  in S:
        if ope == 'I':
            x = x + 1
        elif ope == 'D':
            x = x -1
        x_max = max(x,x_max)

    print(x_max)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
x_list = [0]
x = 0
for s in S:
    if s == "I":
        x += 1
        x_list.append(x)
    elif s == "D":
        x -= 1
print(max(x_list))

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = str(input().strip())

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

    return max(A)


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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    s = input()
    x = 0
    maxx = 0
    for i in s:
        if i == 'D':
            x -= 1
        if i == 'I':
            x += 1
        
        maxx = max(maxx, x)
    
    print(maxx)

solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding utf-8 -*-
N=int(input())
S=list(str(input()))
ans=0
ansl=[]
for i in range(N):
    if S[i]=="I":
        ans+=1
    else:
        ans-=1
    ansl.append(ans)


ansl.append(0)
print(max(ansl))

Submission status: Accepted

Solution code:
# -*- coding utf-8 -*-
N=int(input())
S=list(str(input()))
ans=0
ansl=[]
for i in range(N):
    if S[i]=="I":
        ans+=1
    elif S[i]=="D":
        ans-=1
    ansl.append(ans)


ansl.append(0)
print(max(ansl))

Submission status: Accepted

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

res = 0
tmp = 0
for s in S:
    if s == "I":
        tmp += 1
    if s == "D":
        tmp -= 1
    res = max(tmp,res)

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())

S=input()

x=0
X=[0]

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

print(max(X))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    

    N = int(input().rstrip())
    S = list(_ for _ in input())
    x = 0
    max_x = 0
    for s in S:        
        if s == 'I':
            x += 1
        elif s == 'D':
            x += -1
        max_x = max(x,max_x)
    print(max_x)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(max(ans))

Submission status: Accepted

Solution code:
N = int(input())
s = input()
ans = 0
x = 0
for c in s:
    if c == 'I':
        x += 1
    else:
        x -= 1
    if x > ans:
        ans = x
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
x,mx=0,0
for w in input():
  #print(w)
  x+=1 if w=='I' else -1
  mx = max(x,mx)
print(mx)

Submission status: Accepted

Solution code:
n = int(input())
cnt = 0
ch = 0
*w, = map(str,input().split())
#print(w)
for i in w:
  for j in i:
    #print(j)
    if j == 'I':
      cnt+=1
    elif j == 'D':
      cnt-=1
    if cnt > ch:
      ch = cnt
print(ch)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_,t=open(0);a=b=0
for x in t:b+=x>'D'or-1;a=max(a,b)
print(a)

Submission status: Accepted

Solution code:
n=input()
s=input();x,a=0,0
for i in s:
	x += 1 if i=='I' else -1
	a=max(a,x)
print(a)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
num = int(input())
S = list(input())


ans = 0
total = 0
for n in S:
  if n == "I":
    total += 1
  elif n == "D":
    total -= 1
  if total > ans:
    ans = total

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
b=0
t=0
for c in input():
    if c == 'I':
        t += 1
    else:
        t -= 1
    if t > b:
        b = t
print(b)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max(L))

Submission status: Accepted

Solution code:
def increment_decrement(N: int, S: str)->int:
    x, max_x = 0, 0
    for c in S:
        if c == 'I':
            x += 1
            max_x = max(max_x, x)
        else:
            x -= 1
    return max_x


if __name__ == "__main__":
    N = int(input())
    S = input()
    ans = increment_decrement(N, S)
    print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
n = input()
xs = list(input())
ys = [0]

for x in xs:
    if x == 'I':
        ys.append(1)
    else:
        ys.append(-1)

ans = max(list(accumulate(ys)))
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
hoge=list(input())
ans=0
now=0
for i in range(n):
  if(hoge[i]=="I"):
    now+=1
  else:
    now+=-1
  
  if(now>ans):
    ans=now
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(input())

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

Submission status: Accepted

Solution code:
def INSTR():
	return input()

def INNUM():
	return int(INSTR())

def INSTR_S():
	return INSTR().split()

def INNUM_S():
	return map(int, INSTR_S())

def INSTR_SM(n):
	return [tuple(INSTR_S()) for _ in range(n)]

def INNUM_SM(n):
	return [tuple(INNUM_S()) for _ in range(n)]

N = INNUM()
S = list(INSTR())
x = xmax = 0
for s in S:
	x += 1 if s == "I" else -1
	xmax = max(xmax, x)
print(xmax)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
a,b,c,d = LI()
print(max(a*b,c*d))
"""
#B
n = I()
s = S()
ans = 0
x = 0
for i in s:
    if i == "I":x += 1
    else:x-=1
    ans = max(ans,x)
print(ans)
#C
"""
def factor(n):
    i = 2
    m = n
    while m >= i:
        while m%i == 0:
            m //= i
            d[i] += 1
            d[i] %= mod
            if m < i:break
        i += 1
n = I()
d = defaultdict(int)
for i in range(2,n+1):
    factor(i)
ans = 1
for i in d.values():
    ans *= i+1
    ans %= mod
print(ans)
"""

#D
"""
n,a,b = LI()
x = LI()
ans = 0
for i in range(n-1):
    if a*(x[i+1]-x[i]) > b:
        ans += b
    else:
        ans += a*(x[i+1]-x[i])
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
from sys import stdin
ans = [0]
x = 0
n = int(stdin.readline())
for i, c in enumerate(list(stdin.readline())):
    if c == 'I':
        x += 1
        ans.append(x)
    else:
        x -= 1
print(max(ans))

Submission status: Accepted

Solution code:
N=int(input())
S=str(input())
x=0
M=0
for i in range(N):
    si=S[i]
    if si=='I':
        x+=1
        if M<x:
            M=x
    else:
        x-=1
print(M)

Submission status: Accepted

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

I_count = [i for i, x in enumerate(S) if x == 'I']
D_count = [i for i, x in enumerate(S) if x == 'D']

tmp = [0] * N
for i in I_count:
    tmp[i] = 1
for i in D_count:
    tmp[i] = -1

ans = 0
List = []
for i in range(N):
    ans += tmp[i]
    List.append(ans)

print(max(0, max(List)))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
judge = {"I":True, "D":False}
x = 0
ans = 0
for i in S:
    if judge[i]:
        x += 1
        ans = max(ans, x)
    else:
        x -= 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
now=0
for c in s:
    now+= 1 if c=='I' else -1
    ans=max(ans,now)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

x = 0
max_x = 0

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

print(max_x)

Submission status: Accepted

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

x = 0
ans = 0

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

Submission status: Accepted

Solution code:
x=0
curmax=0
input()
S=list(input())
for i in S:
    if i=="I":
        x+=1
        curmax=max(curmax,x)
    else:
        x-=1
print(curmax)

Submission status: Accepted

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

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

    res = max(res,now)

print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = 0
res = 0
for i in s:
    if i=="I":
        cnt += 1
    elif i=="D":
        cnt -= 1
    res = max(res,cnt)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(str, input()))

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

Submission status: Accepted

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

Submission status: Accepted

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

max = 0
x = 0

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

Submission status: Accepted

Solution code:
# ABC 051 B
N =int(input())
S =str(input())
x = 0
max_x =0
for s in S:
    if s =="I":
        x +=1
    else:
        x -=1
    if x > max_x:
        max_x = x
print(max_x)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = [i for i in input()]
anss=[0]
ans=0
for s in S:
    if s=="I":
        ans+=1
        anss.append(ans)
    elif s=="D":
        ans-=1
        anss.append(ans)
print(max(anss))

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
count = ans = 0
for i in range(0,N,1):
    if S[i] == "I":
        count += 1
    else:
        count -= 1
    if ans <= count:
        ans = count
print(ans)

Submission status: Accepted

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

x = 0
maxNum = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max(X))

Submission status: Accepted

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

x = nums =0
dic = {'I': 1, 'D': -1}
for i in s:
    x += dic[i]
    nums = max(x, nums)
print(nums)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    x = nums =0
    dic = {'I': 1, 'D': -1}
    for i in s:
        x += dic[i]
        nums = max(x, nums)
    print(nums)


if __name__ == '__main__':
    n = int(input())
    s = input()
    main()

Submission status: Accepted

Solution code:
x = 0
max_value = [0]

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

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

Submission status: Accepted

Solution code:
x = 0
max_value = [0]

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

list = [i for i in s]

for j in list:
    if j == 'I':
        x += 1
        max_value.append(x)
    else:
        x -= 1
        max_value.append(x)
print(max(max_value))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
g = m = 0
dic = {'I':1,'D':-1}
for s in input():
    g += dic[s]
    m = max(m,g)
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
listA=[0]
for i in range(n):
  if s[i]=="I":
    listA.append(listA[i]+1)
  elif s[i]=="D":
    listA.append(listA[i]-1)
listA.sort(reverse=True)
print(listA[0])