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
maxx  = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    II()
    s=SI()
    t=0
    ans=0
    for c in s:
        if c=="I":t+=1
        else:t-=1
        ans=max(ans,t)
    print(ans)

main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
c = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    x=0
    N=I()
    S=input()
    
    ans=0
    for i in range(N):
        if S[i]=="I":
            x+=1
        else:
            x-=1
            
        ans=max(ans,x)
        
    print(ans)

main()

Submission status: Accepted

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

peak.sort()
print(peak[-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    N=int(input())
    S=str(input())
    val=0
    valmax=0

    for i in range(N):
        if S[i]=='I':
            val+=1
            valmax = max(valmax, val)

        else:
            val-=1

    print(valmax)




resolve()

Submission status: Accepted

Solution code:
N=int(input())
S=str(input())
x=0
y=0
for i in range(N):
  if S[i]=='I':
    x+=1
  elif S[i]=='D':
    x-=1
  y=max(x,y)

print(y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
maxi=0
x=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Problem B - Increment Decrement

# input process
N = int(input())
S = input()

# initialization
max_score = 0
tmp = 0

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

print(max_score)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
c=0
b=0
for i in range(len(s)):
  if s[i]=="I":
       c+=1
  else:
       c-=1
  if b<=c:
       b=c
  else:
       pass
print(b)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

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

print(ans)

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

Submission status: Accepted

Solution code:
n = input()
s = input()
x = 0
ans = [0]
for i in s:
    if 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 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 = 0
l = [0]
for i in S:
    if i == "I":
        x += 1
        l.append(x)
    
    else:
        x -= 1
        l.append(x)
print(max(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    n=int(readline().strip())
    ss=readline().strip()
    x=0
    maxx=x
    for s in ss:
      diff=1 if s=="I" else -1
      x+=diff
      maxx=max(maxx,x)
    print(maxx)

    return


resolve()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
input()
s=input()
c,m=0,0
for i in range(len(s)):
    if s[i]=="I":
        c+=1
        m=max(c,m)
    if s[i]=="D":
        c=c-1
        #m=max(c,m)
print(m)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
num = [0]
cu = 0
for i in S:
  if i == "I":
    cu += 1
    num.append(cu)
  else:
    cu -= 1
num.sort()
print(num[-1])

Submission status: Accepted

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

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

print(max)

Submission status: Accepted

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

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

max_count = 0
curr_count = 0

for s in S:
    if s == 'I':
        curr_count += 1

    elif s == 'D':
        curr_count -= 1

    if curr_count > max_count:
        max_count = curr_count

print(max_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

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

if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = int(input())
s = list(input())
c, m = 0, 0
for i in s:
    if i == "I":
        c += 1
    else:
        c -= 1
    if c > m:
        m = c
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
words=[a for a in S]
x=0
list=[]+[0]
for b in words:
    if b=='I':
        x+=1
        list.append(x)
    else:
        x-=1
        list.append(x)
print(max(list))

Submission status: Accepted

Solution code:
N = int(input())
line = input()
x = 0
t = 0
for i in range(N):
  if line[i] == 'I':
    t += 1
  elif line[i] == 'D':
    t -= 1
  x = max(t,x)
print(x)

Submission status: Accepted

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

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

print(max(ans))

Submission status: Accepted

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

N = int(input().strip())
S = input().strip()
#-----

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

print(x_max)

Submission status: Accepted

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

Submission status: Accepted

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

ans = []
x = 0

for i in range(n):
  if s[i] == "I":
    x +=1
    ans.append(x)
    
  elif s[i] == "D":
    x -=1
    ans.append(x)
    
ans.sort(reverse=True)

print(max(ans[0],0))

Submission status: Accepted

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

ans = 0
ans2 = 0
for s_i in s:
  if s_i == "I":
    ans += 1
  elif s_i == "D":
    ans -= 1
  ans2 = max(ans2, ans)
print(ans2)

Submission status: Accepted

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

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

print(y)

Submission status: Accepted

Solution code:
#052_B
n=int(input())
s=input()
print(max([s[:i].count('I')-s[:i].count('D') for  i in range(n+1)]))

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

Submission status: Accepted

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

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

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())
S = input()
x = 0
s =0
for i in range(N):
    if S[i]=="I":
        x+=1
    if S[i]=="D":
        x-=1
    if x > s:
        s = x

print(s)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
now = 0
for s in S:
  if s == 'I':
    now +=1
  elif s=='D':
    now -=1
  if now > ans:
    ans = now
print(ans)

Submission status: Accepted

Solution code:
input()
s=input()
n,m=0,0

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

Submission status: Accepted

Solution code:
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.append(x)
print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
数字 = int(readline())
文字 = readline().rstrip().decode('utf-8')

答え = 0
答えの最大値 = 0

for 文字の1要素 in 文字:
    if 文字の1要素 == "I":
        答え += 1
        答えの最大値 = max(答えの最大値,答え)
    else:
        答え -= 1

print(答えの最大値)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    x = 0
    mx = 0
    for Si in S:
        x += 1 if Si == "I" else -1
        mx = max(mx, x)
    print(mx)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
max_ans=0
for i in S:
  if i=='I':
    ans+=1
    if max_ans<ans:
      max_ans=ans
  else:
    ans-=1
print(max_ans)

Submission status: Accepted

Solution code:
def main():
    length = int(input())
    string = input()
    answer = 0
    integer = 0
    for s in string:
        if s == "I":
            integer += 1
        else:
            integer -= 1
        answer = max(answer, integer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
x = 0
max_x = 0
for i in range(N):
    if S[i]=="D":
        x -= 1
    else:
        x += 1
    if x > max_x:
        max_x = x
print(max_x)

Submission status: Accepted

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

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:
#ABC052

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

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
x=0
mx=0
for c in s:
    if c=="I":
        x+=1
    else:
        x-=1
    if mx<x:
        mx=x
print(mx)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(input())
x = 0
ans = 0
for i in l:
  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 = 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
max_x=0
for op in s:
    if op=="I":
        x+=1
    if op=="D":
        x-=1
    if max_x<x:
        max_x=x

print(max_x)

Submission status: Accepted

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

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
    else:
        x -= 1
    if x > x_max:
        x_max = x
print(x_max)

Submission status: Accepted

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

Submission status: Accepted

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

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 = 0

max = x

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

print(max)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
d=0
for i in S:
  if i=='D':
    d-=1
  else:
    d+=1
  ans=max(ans,d)
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
xmax = 0
now = 0
for i in range(N):
    if S[i] == "I":
        now += 1
    elif S[i] == "D":
        now -= 1
    if now > xmax:
        xmax = now
print(xmax)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
input()
s = input()
t,a = 0,0
for c in s:
  t += 1-(c=='D')*2
  a = max(a,t)
print(a)

Submission status: Accepted

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

c = 0
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

    if count>max:
        max=count
print(max)

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

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

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
        if ans >= mx:
            mx = ans
    else:
        ans -= 1

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
now = 0
d = {'I': 1, 'D': -1}
for c in s:
  now += d[c]
  ans = max(ans, now)
print(ans)

Submission status: Accepted

Solution code:
a=int(input())
b=input()
for x in b:
    b=b.replace("DI","")
print(b.count("I"))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
m=0
sum=0
for i in S:
    if i == "I":
        sum+=1
    else:
        sum-=1
    m=max(sum, m)
print(m)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
x = 0
answer = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    S = input()
    x = 0
    xm = 0
    for i in range(N):
        if S[i] == 'I':
            x+=1
        else :
            x-=1
        if xm < x:
            xm = x
    print(xm)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
str = input()
answer = 0
count = 0
for id in range(n):
    if str[id] == "I": count += 1
    elif str[id] == "D": count -= 1
    answer = max(answer, count)

print(answer)

Submission status: Accepted

Solution code:
n=input()
s=list(input())
i=0
m=0
for x in s:
    if x=="I":i+=1
    if x=="D":i-=1
    m=max(m,i)
print(m)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
x=0
a=[0]
for i in range(n):
    if s[i]=="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(str(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)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
temp = 0
ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = 0
ans = 0

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

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

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())
S = input()

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

Submission status: Accepted

Solution code:
input()
s=input()
c,m=0,0
for i in range(len(s)):
  if s[i]=="I":
    c+=1
    m=max(c,m)
  if s[i]=="D":
    c-=1
    m=max(c,m)
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = input()
max_s = 0
x = 0
for i in range(n):
    if s[i] == "I": x += 1
    else: x -= 1
    max_s = max(max_s,x)
print(max_s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

n = int(input())
s = input()
x = 0 
xs = [x] 

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

print(max(xs))

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 31, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = readline().decode('utf8')

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

    ans=max(ans, cnt)
print(ans)

Submission status: Accepted

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

x_temp = 0
x_max = 0

for si in s:
    if si == 'I':
        x_temp += 1
    elif si == 'D':
        x_temp -= 1
    x_max = max(x_max, x_temp)
    
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
    else:
        x-=1
    if ans < x:
        ans = x
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
count = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
input()
apply_nums = [1 if x == 'I' else -1 for x in list(input())]

num = 0
_max = num
for apply_num in apply_nums:
    num += apply_num
    _max = max(num, _max)
print(_max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
total=[0]
num=0
for s in S:
    if s=="I":
        num+=1
    else:
        num-=1
    total.append(num)
print(max(total))

Submission status: Accepted

Solution code:
input()
c=0
yy=0
b=list(input())
for i in b:
    if i == "I":
        c=c+1
    if i == "D":
        c=c-1
    if c > yy:
        yy=c
print(yy)

Submission status: Accepted

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

Submission status: Accepted

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

print(max(ans))

Submission status: Accepted

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

ans = 0
wrk = 0
for i in s:
    if i == 'I':
        wrk +=1
    if i == 'D':
        wrk -=1

    ans = max(ans,wrk)
print(ans)