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:
input();s=input()
m=0
c=0
for k in s:
  if k == 'I':
    c+=1
  else:
    c-=1
  if c >= m:
    m=c
print(m)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
x,m=0,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()

m = 0
x = 0

for c in S:
  if c=="I":
    x += 1
    m = max(m,x)
  elif c=="D":
    x -= 1
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

x = [0 for _ in range(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:
input();a=b=0
for x in input():b+=x>'D'or-1;a=max(a,b)
print(a)

Submission status: Accepted

Solution code:
from itertools import accumulate
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
S = input()[:-1]
l = [0]*(N+1)
for i, c in enumerate(S):
    if c == "I":
        l[i+1] += 1
    else:
        l[i+1] -= 1
l_acc = accumulate(l)
print(max(l_acc))

Submission status: Accepted

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

if S[0] == 'I':
        x[0] += 1
else:
    x[0] -= 1

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

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

Submission status: Accepted

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

Submission status: Accepted

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

m = 0
x = 0
for char in S:
    if char == 'I':
        x += 1
    else:
        x -= 1
    if x > m:
        m = x

print(m)

Submission status: Accepted

Solution code:
while True:
    try:
        n=int(input())
    except:
        break
    string=input()
    max=0
    x=0
    for i in string:
        if i=="D":
            x=x-1
        else:
            x=x+1
        if x>=max:
            max=x
    print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_ = int(input())
list_X = [0]
for i in list(input()):
    if(i == 'I'):
        list_X.append(list_X[-1]+1)
    else:
        list_X.append(list_X[-1]-1)
print(max(list_X))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
now = 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()
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:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())


def calculate(a):
    s = 0
    for i in range(len(a)):
        for k in range(i+1,len(a)):
            s+=(a[i]*a[k])
    return s

n = ip()                              #入力整数1つ
#n,m= (int(i) for i in input().split())      #入力整数横2つ
#a,b,k = (int(i) for i in input().split())    #入力整数横3つ
#n,a,b,c= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
mx = 0
x = 0
for i in range(n):
    if a[i] == 'I':
        x+=1
        if mx < x:mx = x
    else: x-=1
print(mx)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input();a=[0]
for x in input():a+=[a[-1]+((x>'D')or-1)]
print(max(a))

Submission status: Accepted

Solution code:
input();s=input();print(max(i-2*s[:i].count('D')for i in range(len(s)+1)))

Submission status: Accepted

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

x = 0
l = [0]*n

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

print(max(max(l), 0))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max)

Submission status: Accepted

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

Submission status: Accepted

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

max_num=0
num = 0
for i in range(n):
  if s[i]=="I":
    num +=1
  elif s[i]=="D":
    num -=1
  max_num =max(num,max_num)
print(max_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
S = input()
x = ans = 0
for s in S:
  if s == 'I':
    x += 1
    if x > ans:
      ans = x
  else:
    x -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
"""AtCoder"""

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

ans = 0
tmp = 0

for i in range(N):
  if S[i] == 'I':
    tmp += 1
  if S[i] == 'D':
    tmp -= 1
  if tmp > ans:
    ans = tmp

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
n=int(input())
A=list(input())
t=0
ans=0
for i in A:
  if i=="D":
    t-=1
    ans=max(ans,t)
  else:
    t+=1
    ans=max (ans,t)
print(ans)

Submission status: Accepted

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


def main():
    n = int(input())
    s = input()
    val = 0
    ans = 0

    for si in s:
        if si == 'I':
            val += 1
        elif si == 'D':
            val -= 1

        ans = max(ans, val)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()

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

Submission status: Accepted

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

    if ans < x:
        ans = x

print(ans)

Submission status: Accepted

Solution code:
def fun():
     print(11)
     print(22)
     print(33)
     print(22)
N=eval(input())
S=input()
ls=[0]
x=0
for i in S:
     if i=='I':
          x+=1
          ls.append(x)
     else:
          x-=1
          ls.append(x)
result=max(ls)
print(result)

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

print(ans)

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

print(max)

Submission status: Accepted

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

print(max(X))

Submission status: Accepted

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

Submission status: Accepted

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

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
    else:
        tmp -= 1
print(_max)

Submission status: Accepted

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

result = r = 0

for c in S:
    r += (c == "I") - (c == "D")
    result = max(result, r)

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

for i in s:
    if i == "I":
        si += 1
    elif i == "D":
        si -= 1

    if si > max:
        max = si

print(max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
v = 0
for ss in s:
    if ss == 'I':
        v += 1
    else:
        v -= 1
    res = max(res, v)

print(res)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
R = [None] * N

for i, s in enumerate(S):
    if i == 0:
        if s == 'I':
            R[i] =  1
        else:
            R[i] = -1
    else:
        if s == 'I':
            R[i] = R[i-1] + 1
        else:
            R[i] = R[i-1] - 1

print(max(0, max(R)))

Submission status: Accepted

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

num = [0]
n = 0
for s in S:
    if s == 'I': n += 1
    elif s == 'D': n -= 1
    num.append(n)

print(max(num))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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 = input()
n = int(n)
str = input()
val = [0]
x = 0
for _ in range(n):
  o = str[:1]
  if o == 'D':
    x -= 1
  else:
    x += 1
  val.append(x)
  str = str[1:]
print(max(val))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

a = np.array([1 if i == 'I' else -1 for i in list(s)])
print(max(a.cumsum().max(), 0))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    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=list(input())
x,max=0,0

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

print(max)

Submission status: Accepted

Solution code:
N = int(input())
n = 0
nmax = 0
for c in input():
    if c == 'I':
        n += 1
        if n >= nmax:
            nmax = n
    else:
        n -= 1
print(nmax)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
x = 0
for c in S:
    if c == 'I':
        x += 1
        if x > ans:
            ans = x
    else:
        x -= 1
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

print(max(temp))

Submission status: Accepted

Solution code:
n = input()
s = input()
cnt = 0
ans = 0
for c in s:
    if c == 'I':
        cnt += 1
        ans = max(ans, cnt)
    else:
        cnt -= 1
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:
from itertools import accumulate

N = int(input())
As = [1 if S == 'I' else -1 for S in input()]

print(max(accumulate([0] + As)))

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

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

y = 0
for sss in S:
    if sss == 'I':
        x += 1
    elif sss == 'D':
        x -= 1
    if x > y:
        y = x
print(y)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
lst_for_ans = []
for i in range(len(S)+1):
       I_count = S[:i].count("I")
       D_count = S[:i].count("D")
       lst_for_ans.append(I_count - D_count)

print(max(max(lst_for_ans),0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
int_n = int(input())
str_s = input()

int_x = 0
li_x = list()
li_x.append(int_x)
for s in str_s:
    if s == "I":
        int_x += 1
    else:
        int_x -= 1
    li_x.append(int_x)
print(max(li_x))

Submission status: Accepted

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

Submission status: Accepted

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

A = []

for i in range(n+1):
    ans = s[:i]
    A.append(ans.count('I') - ans.count('D'))

print(max(A))

Submission status: Accepted

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

ans = max(ans, temp)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

result = [0]
x = 0
for s in S:
  if(s == 'I'):
    x += 1
  else:
    x -= 1
  result.append(x)
print(max(result))

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
_max = 0
count = 0
for _s in s:
    if _s == "I":
        count += 1
    else:
        count -= 1
    _max = max(_max, count)
print(_max)

Submission status: Accepted

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

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

print(xmax)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(max_value)

Submission status: Accepted

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


def main():
    """Function."""
    n = int(input())
    s = str(input())

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

    print(max(counter))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy
N = input()
c_to_i = {'I': 1, 'D': -1}
x = [0] + [c_to_i[c] for c in raw_input()]
print max(numpy.cumsum(x))

Submission status: Accepted

Solution code:
import numpy
N = input()
x = [0] + [1 if c == 'I' else -1 for c in raw_input()]
print max(numpy.cumsum(x))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
max_ = 0
x = 0
for e in S:
    if e == "I":
        x += 1
    elif e == "D":
        x -= 1
    if x > max_:
        max_ = x
print(max_)

Submission status: Accepted

Solution code:

"""
N=int(input())

print(800*N-int(N/15)*200)
"""

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

max_n=0
temp=0
for strng in S:
	if strng=="I":
		temp+=1
		if max_n<temp:
			max_n=temp
	else:
		temp-=1
print(max_n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline().strip())
S = sys.stdin.readline().strip()

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

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:
input()
tmp = x = 0
for a in input():
  x += int(a.replace('I','1').replace('D','-1'))
  if tmp < x:
    tmp = x

print(max([0,tmp]))

Submission status: Accepted

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

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

print(Max)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def abc052_b():
    n = int(input())
    s = str(input())
    now, ans = 0, 0
    for char in s:
        if char == 'I':
            now += 1

            if now >= ans:
                ans = now
        else:
            now -= 1

    return ans


if __name__ == '__main__':
    print(abc052_b())

Submission status: Accepted

Solution code:
n=int(input())
s=input()
x=[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:
# coding: utf-8
N, S = int(input()), input()
d = {"I":1, "D":-1}

val = 0
ans = 0
for x in S:
    val += d[x]
    ans = max(ans, val)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N, S = int(input()), input()
d = {"I":1, "D":-1}

val = 0
ans = 0
for x in S:
    val += d[x]
    if val > ans:
        ans = val
print(ans)

Submission status: Accepted

Solution code:
N = int(input().rstrip())
S = input().rstrip()
n = 0
c = 0
for i in range(len(S)):
    if S[i] == 'I':
        c += 1
    else:
        c -= 1

    if n < c:
        n = c

print(n)