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 = list(input())
x, max_x = 0, 0
for i in range(n):
  if s[i] == 'I':
    x += 1
    if max_x < x:
      max_x = x
  elif s[i] == 'D':
    x -= 1
print(max_x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
N = int(input())
S = input()
a = [1 if s == "I" else -1 for s in S]
X = [0] + list(accumulate(a))
print(max(X))

Submission status: Accepted

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

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

s = list(S)

count = 0
max = 0

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

print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
S = input()
L = np.array([0] + [1 if x == 'I' else -1 for x in S])
L_cum = L.cumsum()

print(max(L_cum))

Submission status: Accepted

Solution code:
N = int(input())
S = input().split()
X = 0

S1 = list(S[0])


S1_mod = [1 if i == "I" else i for i in S1]
S1_mod = [-1 if i == "D" else i for i in S1_mod]

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

Submission status: Accepted

Solution code:
n=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
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#インポート
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)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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
    else:
        cnt -= 1
    ans.append(cnt)
print(max(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 = 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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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
    X.append(x)
  else:
    x-=1
    X.append(x)
print(max(X))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

# output
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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
    else:
        x -= 1
    m = max(x, m)
print(m)

Submission status: Accepted

Solution code:

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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env 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)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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
    else:
        cnt -= 1
    ans.append(cnt)
print(max(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 = 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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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
        mx = max(mx,x)
    else:
        x += -1
print(mx)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
 #ABC 52, B - increment decrement
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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 = 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))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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