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 = [0]
now = 0
for i in range(n):
    if s[i] == "I":
        now += 1
        x.append(now)
    elif s[i] == "D":
        now -= 1
        x.append(now)
print(max(x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
z = [0]

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

Submission status: Accepted

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

for i in range(N):
    if S[i] == 'I':
        x += 1
    elif S[i] == 'D':
        x -= 1
    if xmax < x:
        xmax = x

print(xmax)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
a = input()
maxi = 0
now = 0
for c in a:
  if c == 'I':
    now += 1
  else:
    now -= 1
  maxi = max(now, maxi)
print(maxi)

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:
def larger(x, y):
	if x > y:
		return x
	return y

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
 
mx = 0
current = 0
for c in s:
  if c == "I":
    current += 1
  elif c == "D":
    current -= 1
  if current > mx:
    mx = current
 
 
print(mx)

Submission status: Accepted

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

Submission status: Accepted

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

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
  m = max(m,c)
print(m)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c, d = LI()
    print(max(a * b, c * d))
    return

#B
def B():
    _ = II()
    s = S()
    d = {}
    d["I"] = 1
    d["D"] = -1
    ans = 0
    now = 0
    for i in s:
        now += d[i]
        ans = max(ans, now)
    print(ans)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

Solution code:
N=int(input())
S=input()
x = 0
max_x = 0
for s_i in S:
  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()
arr=[]
v=0
for s in S:
	if s=="I":
		v+=1
		arr.append(v)
	else:
		v-=1
		arr.append(v)
print(max(0,max(arr)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, S: str):
    ret = 0
    cur = 0
    for c in S:
        if c == 'I':
            cur += 1
            ret = max(ret, cur)
        else:
            cur -= 1
    print(ret)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
s=input()

x,a=0,0
for l in s:x+=-1+2*(l=='I');a=max(a,x)
print(a)

Submission status: Accepted

Solution code:
import numpy as np

# input
N = int(input())
S = [1 if e == 'I' else -1 for e in input()]
print(max(max(np.cumsum(S)), 0))

Submission status: Accepted

Solution code:
n = int(input())
s = input().rstrip()
x = 0
result = 0

for c in s:
    x += 1 if c == 'I' else -1
    if x > result:
        result = x

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
a,m,x=0,0,0
while True:
    if s[a]=='I':
        x+=1
    else:
        x-=1
    m=max(m,x)
    a+=1
    if a==n:
        break
print(m)

Submission status: Accepted

Solution code:
import sys
operaciones = list()
p=0
lines = sys.stdin.readlines()
for linea in lines:
    c = linea.split()
    c = list(map(str,c))
list(c)
x = c[0]
a = list(x)
for k in range(len(a)):
  if a[k]== "I":
    p+=1
    operaciones.append(p)
  if a[k] == "D":
    p-=1
    operaciones.append(p)
mayor=operaciones[0]
for i in range(len(operaciones)):
    if operaciones[i]>mayor:
        mayor=operaciones[i]
if mayor <0:
  print(0)
else:  
  print(mayor)

Submission status: Accepted

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

x = 0
A = 0

for i in range(N):
    if S[i] == 'D':
        x -= 1
        A = max(A, x)
    else:
        x += 1
        A = max(A, x)

print(A)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
ret = 0

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

Submission status: Accepted

Solution code:
n=int(input())
l=list(str(input()))
ans=0
tmp=0
for i in l:
    if i=="I":tmp+=1
    else:tmp-=1
    if tmp>ans:ans=tmp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

ans = 0

now = 0

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

for i in S:

    if i == "I":
        now += 1

    else:
        now -= 1

    ans = max(now,ans)

print (ans)

Submission status: Accepted

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

ans = 0
temp = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()
isum = 0
imax = 0

for i in range(n):
    if s[i] == "I":
        isum += 1
        if imax < isum:
            imax = isum
    else:
        isum -= 1
print(imax)

Submission status: Accepted

Solution code:
from collections import Counter

input()
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
max_x = 0
for n in range(N):
    if S[n] == '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()
MAX=0
x=0
for i in S:
  if i=="I":
    x+=1
  if i=="D":
    x-=1
  MAX=max(MAX,x)
print(MAX)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
S = (stdin.readline().rstrip())
ans = 0
tmp = 0
for i in S:
    if i == "I":
        tmp += 1
    else:
        tmp -= 1
    ans = max(ans,tmp)
print(ans)

Submission status: Accepted

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

l_a = []
l_b = [0]
x = 0

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

ans = max(l_b)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for r in range(0,n):
    if(s[r] == "I"):
        x += 1
    else:
        x -= 1
    a.append(x)
print(max(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
b = input()
c = [0]
x = 0

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = input()
    x = 0
    max_num = 0

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

    print(max_num)


if __name__ == "__main__":

    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

max_x = 0
x = 0
for s in S:
    if s == '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()
print(max([s[:i].count("I")-s[:i].count("D") for i in range(1,n+1)]+[0]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N = int(input())
S = list(input())
ctr = 0
max_ctr = 0

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

Submission status: Accepted

Solution code:
n = list(map(int, input().split()))
n = n[0]
s = list(map(str, input().split()))
s = s[0]

ans = 0
maxim=0
for i in range(n):
    if(s[i] == 'I'):
        ans += 1
    else:
        ans-=1
    if(ans>maxim):
        maxim = ans



print(maxim)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(input())
S = input()
x = 0
ans = 0
for i in range(N):
    if S[i] == 'I':
        x += 1
        if x > ans:
            ans = x
    elif S[i] == 'D':
        x -= 1
print(ans)

Submission status: Accepted

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

x = [0]

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

print(max(x))

Submission status: Accepted

Solution code:
N=int(input())
#A,B,C,D=map(int,input().split())
S=input()
a=0
ans=a
for i in range(N):
    if S[i]=="I":
        a+=1
    else:
        a-=1
    ans=max(a,ans)
print(ans)

Submission status: Accepted

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

x = 0
max = 0

for i in s:
    if i == "I":
       x = x + 1
       if max < x:
           max = x
    else:
        x = x - 1

print(max)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
S = s()

x = 0
max_x = 0
for c in S:
    if c == 'I':
        x += 1
        if x > max_x:
            max_x = x
    else:
        x -= 1

print(max_x)

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:
def abc():
    n = int(input())
    s = input().rstrip()
    x = 0
    ans = 0
    for i in range(n):
        if s[i] == 'I':
            x += 1
        if s[i] == 'D':
            x -= 1
        ans = max(ans, x)
    print(ans)


abc()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

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

sys.setrecursionlimit(2147483647)
INF = float("inf")

# N = int(sys.stdin.readline())
#
# a = math.factorial(N) % (10 ** 9 + 7)
# print(a)
# # print(pow(2, N , 10 ** 9 + 7))

N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()
S = np.array(list(S))
a = np.zeros(N)
a[S == 'I'] = 1
a[S == 'D'] = -1
print(max(0, int(a.cumsum().max())))

Submission status: Accepted

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

S = list(S)
count = 0
ans = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ma)

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

Submission status: Accepted

Solution code:
# coding: utf-8
import time
import re
import math

def main():
    n=int(input())
    s=input()
    x=0
    mx=0
    for a in s:
        if(a=='I'):x+=1
        elif(a=='D'):x-=1

        mx=max([mx,x])
    print(mx)
main()

Submission status: Accepted

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

score = []
x = 0
score.append(x)
for ss in s :
    if (ss == "D") :
        x -= 1
    else :
        x += 1
    score.append(x)

print(max(score))

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

Submission status: Accepted

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

Submission status: Accepted

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

if max(lst) > 0:
    print(max(lst))
else:
    print(0)

Submission status: Accepted

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

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

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)
    if i=='D':
        x+=-1
print(maxx)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
D = input()
x = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
D = input()
x = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())

id=list(input())

nums=[0]

for i in id:
    if i=="I":
        nums.append(1)

    else:
        nums.append(-1)

ans=[]

for i in range(len(nums)-1):
    ans.append(nums[i]+nums[i+1])
    nums[i+1]=nums[i]+nums[i+1]

if max(ans)<0:
    print("0")

else:
    print(max(ans))

Submission status: Accepted

Solution code:
x=0
x_max = 0

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

for i in s:
    if i == "I":
        x += 1
    else:
        x -= 1
    x_max = max(x_max,x)

print(x_max)

Submission status: Accepted

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

def solve():
    N = int(input())
    S = input()

    ans = 0
    x = 0

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

ans = 0
for i in range(1,N+1):
  ans = max(S[:i].count('I')-S[:i].count('D'),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 
        ans.append(x)
    else : 
        x -= 1
        ans.append(x)
print("{}".format(max(ans)))

Submission status: Accepted

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

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

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

	if ans < mx:
		ans = mx

print(ans)

Submission status: Accepted

Solution code:
input()
l=input()
b=[0]
for i in range(len(l)):
    if l[i]=="I":
        b.append(b[-1]+1)
    else:
        b.append(b[-1]-1)
    
print(max(b))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Increment Decrement
https://atcoder.jp/contests/abc052/tasks/abc052_b

"""
import sys


def solve(N, S):
    x = 0
    results = [x]
    for s in S:
        if s == 'I':
            x += 1
        else:
            x -= 1
        results.append(x)
    return max(results)


def main(args):
    N = int(input())
    S = input()
    ans = solve(N, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000


N = int(input())
S = str(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:
s=int(input())
list=list(input())
temp=0
ans_list=[0]

for i in range(len(list)):
    if list[i]=='I':
        temp=temp+1
    elif list[i]=='D':
        temp=temp-1
    ans_list.append(temp)

print(max(ans_list))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
max_x = 0
for i in s:
  if i == "D":
    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
x = 0
for i in s:
    if i == 'D':
        x -= 1
    elif i == 'I':
        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(len(s)):
    if s[i] == "I":
        x += 1
        ans = max(x, ans)
    else:
        x -= 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
x = 0
x_list = [0]

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()
x = 0
ans = []
ans.append(x)

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

print(max(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
x = 0
xmax = 0
for i in s:
    if i == "I":
        x += 1
    elif i == "D":
        x -= 1
    if x >= xmax:
        xmax = x
print(xmax)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import *
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().strip()

x = 0
maxx = 0
for c in s:
    if c == 'I':
        x += 1
    else:
        x -= 1

    maxx = max(maxx, x)

print(maxx)

Submission status: Accepted

Solution code:
input_n=input()
input_s=input()
tmp=0
x = 0
for i in input_s:
  if i == "I":
    x=x+1
  else:
    x=x-1
  tmp=max(tmp,x)

print(tmp)

Submission status: Accepted

Solution code:
n = int(input())
s = list(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=list(input())
max=0
ma=0

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

Submission status: Accepted

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

X = []
X.append(0)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

n = input()
S = input().rstrip()
max_count = 0
count = 0
for s in S:  
  count += 1 if s=='I' else -1
  max_count = max(count, max_count)
print(max_count)