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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#Increment Decrement
N = int(input())
S = input()
n = 0
M = 0
for i in range(N):
    if S[i] == "I":
        n = n + 1
        if n >= M:
            M = n
    else:
        n = n - 1
print(M)

Submission status: Accepted

Solution code:
from itertools import accumulate

input()
print(max([0] + list(accumulate([1 if s=='I' else -1 for s in input()]))))

Submission status: Accepted

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

Submission status: Accepted

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

c=0
m=0
for i in s:
    if(i=='I'):
        c+=1
    else:
        c-=1
    if(m<c):
        m=c
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
N = int(input())
S = input().rstrip()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def examB():
    N = I()
    St = S()
    cur = int(0)
    ans = int(0)
    for s in St:
        if s=="I":
            cur +=1
        elif s=="D":
            cur -=1
        ans = max(ans,cur)
    print(ans)

import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = str(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 = input()
x = 0
ans = x

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
x=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:
# ABC 052: B – Increment Decrement
n = int(input())
s = input()

x = 0
max_value = 0

for c in s:
    if c == 'I':
        x += 1
        max_value = max(max_value, x)
    elif c == 'D':
        x -= 1
    
print(max_value)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def main():
    n = inp()
    s = input()
    x = 0
    res = 0
    for i,j in enumerate(s):
        if j == 'I':
            x += 1
        else:
            x -= 1
        res = max(res, x)
    print(res)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(max_num)

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())
S = deque(list(input()))

def main():
    ans = 0
    curr = 0
    while S:
        s = S.popleft()
        curr += 1 if s == 'I' else -1
        ans = max(ans, curr)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x=0
res=0
n=int(input())
s=input()
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:
# ABC052 B - Increment Decrement
# 2019/11/07

N, S = [s for s in open(0)]
# print(N, S)
list_S = [1 if i == 'I' else -1 for i in list(S)]
# print(list_S)

add_list = 0
ans = 0
for j in list_S:
    add_list += j
    ans = max(add_list,ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A = int(input())
S = input()
s = 0
count = 0
for i in S:
  if (s<=count)and(i == 'I'):
    count += 1
    s = count
  elif i == 'I':
    count += 1
  else:
    count += -1
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

x = 0
x_list = [x]
for si in input():
  if si == 'I':
    x = x + 1
  if si == 'D':
    x = x - 1
  x_list.append(x)

print(max(x_list))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
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()

count = 0
count_list = [0]
for i in S:
    if i == 'I':
        count += 1
        count_list.append(count)
    elif i == 'D':
        count -= 1
    else:
        print('Error')
    
print(max(count_list))

Submission status: Accepted

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

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

print(max_of_x)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
ans = [0 for i in range(n + 1)]

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

print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_ = input()
a = [0]
b = 0
S = list(input())
for i in S:
    if i == "I":
        b += 1
    else:
        b -= 1
    a.append(b)
print(max(a))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(int(max))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n,l = map(int,input().split())
#l = kist(input())

n = int(input())
l = list(input())
cnt=0
ans=0

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

print(ans)

Submission status: Accepted

Solution code:
_ = input()
S = input()
max_n = 0
temp = 0

for s in S:
  if s == 'I':
    temp += 1 
  else:
    temp -= 1
  
  if max_n < temp:
    max_n = temp
    
print(max_n)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0
ans = 0
for x in s:
    if x == 'I':
        count += 1
    elif x == 'D':
        count -= 1
    ans = max(count, ans)
print(ans)

Submission status: Accepted

Solution code:
import collections
import itertools
import functools
import math

if __name__ == "__main__":
    x = 0
    m = 0
    input()  # we don't need n
    s = input()
    for letter in s:
        if letter == "I":
            x += 1
        elif letter == "D":
            x -= 1
        m = max(m, x)
    print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC052 B - Increment Decrement
N = int(input())
S = input()
L = []

t = 0
ans = 0

for s in S:
    if s == 'I':
        t += 1
        ans = max(ans,t)
        L.append(ans)
        continue

    if s == 'D':
        t -= 1
        ans = max(ans,t)
        L.append(ans)
        continue

print(max(L))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
X = [0]
x = 0
for s in S:
  if s == 'I':
    x += 1
    X.append(x)
  else:
    x -= 1
    X.append(x)
X.sort(reverse = True)
print(X[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit, stdin
N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
xs = [0]
x = 0
for s in S:
    if s == 'I':
        x += 1
    elif s == 'D':
        x -= 1
    xs.append(x)
print(sorted(xs)[-1])

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 = list(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())
string=input()
x=[0]*(N+1)
cnt=0
for idx,s in enumerate(string):
  if s=='I':
    cnt+=1
    x[idx]=cnt
  else:
    cnt-=1
    x[idx] = cnt
print(max(x))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
S = input()
mcnt = 0
crr = 0
for s in S:
    if s == "I":crr += 1
    else:crr -= 1
    mcnt = max(mcnt,crr)
print(mcnt)

Submission status: Accepted

Solution code:
x_list = []

n = int(input())
s = str(input())
x = 0
x_list.append(x)

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

print(max(x_list))

Submission status: Accepted

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

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

Submission status: Accepted

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

max_n = 0
n = 0
for s in S:
  if s == "I":
    n += 1
    if n > max_n:
      max_n = n
  else:
    n -= 1

print(max_n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_ = input()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    t = 0
    mt = 0
    for i in range(n):
        if s[i] == "I":
            t += 1
        else:
            t -= 1
        mt = max(mt, t)
    print(mt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

now=0
ans=0

for n in range(N):
  if S[n]=='I':
    now+=1
  else:
    now-=1
  
  if now>ans:
    ans=now

print(ans)

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

Submission status: Accepted

Solution code:
input()
x = res = 0

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
ans = 0

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

print(ans)

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()
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())
l=list(input())
ans=0
k=0
for i in range(n):
    if l[i]=='I':
        k+=1
    else:
        k-=1
    ans=max(ans,k)
print(ans)

Submission status: Accepted

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

ans = 0
ls = [0]

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

print(max(ls))

Submission status: Accepted

Solution code:
n = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
x = ans = 0
for c in s:
    x += [-1, 1][c == 'I']
    ans += (ans < x)+0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


count = 0
Max = 0

for s in S:
    if s == 'I':
        count += 1
        if Max < count:
            Max = count
    elif s == 'D':
        count -= 1

print(Max)

Submission status: Accepted

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

if __name__ == "__main__":
    incre()

Submission status: Accepted

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

for i in range(len(s)):
    if s[i] == 'I':
        x += 1
        m.append(x)
    elif s[i] == 'D':
        x -= 1
        m.append(x)
else:
    print(max(m))

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

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

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

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    s = input()
    x = 0
    ans = 0
    for c in s:
        x += 1 if c == "I" else -1
        if x > ans:
            ans = x
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,s=open(0);print(max(i-s[:i].count("D")*2for i in range(int(n)+1)))

Submission status: Accepted

Solution code:
n,s=open(0);print(max(s[:i].count("I")*2-i for i in range(int(n)+1)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
res = [0] + [0] * len(S)

for i,s in enumerate(S, 1):
    if s == "I":
        res[i] = res[i-1] + 1
    else:
        res[i] = res[i-1] - 1

print(max(res) if max(res) > 0 else 0)

Submission status: Accepted

Solution code:
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()
N = len(s)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

s = [input() for i in range(2)]

N = int(s[0])
S = str(s[1])
x = 0
y = [x]

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

print(max(y))

Submission status: Accepted

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

def main():
    N = int(input())
    s = input().strip()

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

n = int(input())
s = input()
x = 0

ans = 0
for let in s:
    if let == "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:
input()
s = input()
count,max_ = 0,0
for i in range(len(s)
):
    if s[i] == "I":
        count += 1
        max_ = max(count,max_)
    else:
        count -= 1
        max_ = max(count,max_)

print(max_)

Submission status: Accepted

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

# print(N)
# print(S)

x = 0
x_list = [0]
for s in S:
	# print(s)
	if s == 'I':
		x += 1
	elif s == 'D':
		x -= 1
	x_list.append(x)
	
# print(x_list)
print(max(x_list))

Submission status: Accepted

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

ans = 0
x = 0
for v in s:
    if v == 'I':
       x += 1
       ans = max(ans, x)
    elif v == 'D':
        x -= 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a ,ans_a=0,0

for i in range(n):
  if s[i] =='I':
    a +=1
    if ans_a <a:
      ans_a = a
  elif s[i] =='D':
      a -=1
print(ans_a)