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 = [i for i in input()]
ls = [1 if i == "I" else -1 for i in s]
N = len(ls)
S = [0]
for i in range(N):
 	S.append(S[i] + ls[i])
print(max(S))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(tmpmax)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

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

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

now = 0
temp = 0

sl = list(s)

for i in sl:
    if i =="I":
        now += 1
    else:
        now -=1
    temp = max(temp,now)

print(temp)

Submission status: Accepted

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

    memo = [0]*(N+1)
    for i, ss in enumerate(S, 1):
        if ss == 'I':
            memo[i] = memo[i-1] + 1
        else:
            memo[i] = memo[i-1] - 1

    print(max(memo))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    ans = max(ans,tmp)

print(ans)

Submission status: Accepted

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

n = 0

ans = 0
for c in s:
    if c == "I":
        n += 1
    else:
        n-=1
    if ans < n:
        ans = n

print(ans)

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

Submission status: Accepted

Solution code:
N=int(input())
s=input()
i_count=0
max_count=0
for i in range(N):
    if s[i]=="I":
        i_count+=1
        if i_count>max_count:
            max_count=i_count
    if s[i]=="D":
        i_count-=1
print(max_count)

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

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

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

print(Ans)

Submission status: Accepted

Solution code:
N = input()
S = list(input())
cnt = 0
cnt_max = 0
for i in S:
  if i == 'I':
    cnt += 1
    if cnt > cnt_max:
      cnt_max = cnt
  elif i == 'D':
    cnt -= 1
print(cnt_max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
N = int(input())
S = input()
m = 0
x = 0
for p in S:
    if p == 'I':
        x += 1
    if p == 'D':
        x -= 1
    if x > m:
        m = copy.deepcopy(x)
print(m)

Submission status: Accepted

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

x=0
ans=[x]
for n in range(N):
  if S[n]=='I':
    x=x+1
  elif S[n]=='D':
    x=x-1
  ans.append(x)

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

print(max(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    S = input()
    maxcnt = 0
    cnt = 0
    for s in S:
        if s == "I":
            cnt += 1
        elif s == "D":
            cnt -= 1
        maxcnt = max(maxcnt, cnt)
    print(maxcnt)

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
A = int(input())
B = list(input())
ans = 0
now = 0
for i in range(A):
    if B[i] == "I":
        now += 1
    else:
        now -= 1
    ans = max(ans,now)
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
    else:
        x -= 1
    ans = max(ans, x)

print(ans)

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
x = 0

for s in S:
    if s == 'I':
        x += 1
        if ans < x:
            ans = x
    elif s == 'D':
        x -= 1

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#2020-04-29
x = 0
lst = [0]
n = int(input())
s = list(input())

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

print(max(lst))

Submission status: Accepted

Solution code:
#2020-04-29
x = 0
lst = [0]
n = int(input())
s = list(input())

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

print(max(lst))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
ans,x=0,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 numpy as np
import sys

input = sys.stdin.readline

N = int(input())

S = input()

res = 0

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

print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
m = 0
c = 0
for i in range(min([n,len(s)])):
    if s[i] == 'I':
        c += 1
    else:
        c -= 1
    if c > m:
        m = c
print(m)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = list(iss())
    ret = 0
    tmp = 0
    for s in S:
        if s == 'I':
            tmp += 1
        else:
            tmp -= 1
        ret = max(ret, tmp)
    print(ret)


if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=input()
S=input()
max_v =0
v =0
for i in S:
  if i=="I":
    v+=1
    if v>max_v:
      max_v=v
  else:
    v-=1
print(max_v)

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

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    x = 0
    yield x
    for c in s:
        if c == "I":
            x += 1
            yield x
        else:
            x -= 1
            yield x

print(max(main()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

d = defaultdict(int)

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

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

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

print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max(l))

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc052/tasks/abc052_b
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:
def resolve():
	x = 0
	n = input()
	s = input()
	m = 0
	for i in s:
		if i == 'I':
			x += 1
			m = max(m, x)
		elif i == 'D':
			x -= 1
			m = max(m, x)
	print(m)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max(x))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

    ans = max(cnt, ans)

print(ans)

Submission status: Accepted

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

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

print(max(X))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
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)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

maxv = 0
tmp = 0

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

    if maxv < tmp:
        maxv = tmp

print(maxv)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

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:

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


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

if __name__ == '__main__':
   main()

Submission status: Accepted

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

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

print(maximum)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

n = ni()
s = ns()

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

print(ans)

Submission status: Accepted

Solution code:

n = int(input())
s = list(input())
max = 0
count = 0

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

Submission status: Accepted

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

    x = 0
    maxval = 0

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

Submission status: Accepted

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

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

print(max(ans))

Submission status: Accepted

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