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()
rui = [0]
for s in S:
    if s == 'I':
        var = 1
    else:
        var = -1
    rui.append(rui[-1]+var)
print(max(rui))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = list(str(input()))
a = []
b=[]
for i in range(n + 1):
    II = int(s[:i].count('I'))
    DD = int(s[:i].count('D'))
    a.append(II - DD)
print(max(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()

x = 0

maxv = 0

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

print(maxv)

Submission status: Accepted

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

x = [0]

for i in range(1,N+1):
    if S[i-1]=="I":
        x.append(x[i-1]+1)
    if S[i-1]=="D":
        x.append(x[i-1]-1)

print(max(x))

Submission status: Accepted

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

Submission status: Accepted

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

num = 0
res = 0

for i in range(len(s)):
  if s[i] == 'I':
    num += 1
  else:
    num -= 1
  if num > res:
    res = num

print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
dic = {"I": 1, "D": -1}
x = 0
num = 0
for i in s:
    x = x + dic[i]
    num = max(num, x)

print(num)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
counter = 0
pre_counter = 0
big = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

print(max([2 * s[:i].count("I") - len(s[:i]) for i in range(n + 1)]))

Submission status: Accepted

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

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

print(max(D))

Submission status: Accepted

Solution code:
N = int(raw_input())
S = raw_input()
x = 0
maximum = 0

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

print maximum

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
input()
s = input()
max = 0
x = 0

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

print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = int(arr_data[0][0])
s = arr_data[1][0]

#print(n, s)

x = 0

maxdata = x

for v in s:
    
#    print(v)
    
    if v == "D":
        
        x -= 1
        
    elif v == "I":
        
        x += 1
        
    maxdata = x if maxdata<x else maxdata
    
    
print(maxdata)

Submission status: Accepted

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

def solve():
    ans, val = 0, 0
    for S_i in S:
        if S_i == "I":
            val += 1
        else:
            val -= 1
        ans = max(ans, val)
    print(ans)
    
    
solve()

Submission status: Accepted

Solution code:

x=0
y=0
n=int(input())
F=list(input())

alist=[]
alist.append(x)
for token in F:



    if token=="I":
        x=x+1
        if x>y:
            y=x
    else:
        x=x-1
        alist.append(x)





print(y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=input()
S=list(input())
all=[]
x=0

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

print(max(all))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = 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:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    n = int(input())
    s = input()

    x = 0
    result = 0

    for si in s:
        if si == 'I':
            x += 1
            result = max(x, result)
        elif si == 'D':
            x -= 1
            result = max(x, result)

    print(result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
num,answer = 0,0
for i in s:
	if i=="I": num += 1
	else: num -= 1
	if answer < num: answer = num
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
input()
max_num = 0
count = 0
for i in list(input()):
    if 'I' == i:
        count += 1
    else:
        count -= 1
    max_num = max(max_num, count)
print(max_num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input().strip()
x = 0
ans = 0

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

Submission status: Accepted

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

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

print(max(X))

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N=input()
S=list(raw_input())
s=[1 if i=="I" else -1 for i in S]
ans=0
t_sum=0
for i in s:
	t_sum+=i
	ans=max(ans,t_sum)
print ans

Submission status: Accepted

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

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, s = [int(input()), list(input())]
r = {0}
res = 0
for c in s:
    if c == "I":
        res += 1
    if c == "D":
        res -= 1
    r.add(res)
print(max(r))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
x = 0
l = []
l.append(x)
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:


x = 0
input()
s = input()

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
inputted = int(raw_input())
l = list(raw_input())
x = 0
record = []
record.append(x)
for i in range(len(l)):
    if l[i] == "I":
        x+=1

    elif l[i] == "D":
        x-=1
    record.append(x)
print max(record)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
s=input()
while s.find('DI') >-1:
    s=s.replace('DI','')
print(len(s.strip('D')))

Submission status: Accepted

Solution code:
N = int(input())

S = input()

x = 0

Ans = [0]

for i in range(N):
	if S[i] == "I":
		Ans.append(Ans[i] + 1)
	if S[i] == "D":
		Ans.append(Ans[i] - 1)

print(max(Ans))

Submission status: Accepted

Solution code:
num = int(input())
val = input()
max = 0
res = 0
for i in list(val):
    if i == "I":
        res += 1
    else:
        res -= 1
    if res > max:
        max = res
print(max)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = list(input())
    
    R = [0]
    x = 0
    for s in S:
        if s == "I":
            x += 1
        else:
            x -= 1
        R.append(x)
    R.sort()
    print(R[-1])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
d = {"I": 1, "D": -1}
x = 0
N = int(input())
S = input()
ans = 0
for Si in S:
    x += d[Si]
    ans = max(ans, x)
print(ans)

Submission status: Accepted

Solution code:
userInp = int(input())
# print(type(userInp))

inpStr = input()
inpStrs = list(inpStr)
count = 0;
maximum = 0;

for x in range(0,userInp):
	if inpStrs[x] == "I":
		count+= 1
		if maximum <= count:
			maximum = count

	elif inpStrs[x] == "D":
		count -= 1


print(maximum)

Submission status: Accepted

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

    x, maxv = 0, 0
    for c in s:
        if c == 'I':
            x += 1
        elif c == 'D':
            x -= 1
        if x > maxv:
            maxv = x
    print(maxv)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input().strip())
S = input().strip()
x = 0
maxOfx = 0
'''
if(not len(S) == N):
    print('String length match the given value of N')
    exit()
else:
    for i in range(N):
        if not (S[i] is 'I' or S[i] is 'D'):
            print('The character at %d is not I or D'%(i+1))
            exit()
'''
for i in S:
    if i is 'I':
        x+=1
        if x > maxOfx:
            maxOfx = x
    else:
        x-=1
        if x > maxOfx:
            maxOfx = x
print(maxOfx)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
input()
mymax=0
s=0
for i in input():
    if i =='I':
        s+=1
        mymax=max(mymax,s)
    if i=='D':
        s-=1
print(mymax)

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

Submission status: Accepted

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

x=0

X=[0]

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

print(max(X))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



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

    x = xmax = 0
    for c in S:
        if c == "I":
            x += 1
            if x > xmax:
                xmax = x
        elif c == "D":
            x -= 1

    print(xmax)

if __name__ == "__main__": main()

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

Submission status: Accepted

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

x = [0] * N

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

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

Submission status: Accepted

Solution code:
n = int(input())

s = list(map(str, input()))
count = 0
smax = 0

for i in range(len(s)):
    if s[i] == "I":
        count += 1
        if count > 0 and count > smax:
            smax += 1
    else:
        count -= 1
print(smax)

Submission status: Accepted

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))

N = ri()
S = rls()
ans = 0
num = 0
for i in S:
    num += 1 if i == "I" else -1
    ans = max(ans, num)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

p = 0
tmp = 0

for i in range(len(s)):
    if s[i] == 'I':
        tmp += 1
        if p < tmp:
            p = tmp
    else:
        tmp -= 1

print p

Submission status: Accepted

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

v = 0
record = 0
for k in S:
  if (k == 'I'):
    record += 1
  else:
    record -= 1
  v = max(v, record)

print(v)

Submission status: Accepted

Solution code:
import sys

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    s = read_str()
    x = 0
    res = 0
    for l in s:
        if l == 'I':
            x += 1
        else:
            x -= 1
        if x > res:
            res = x
    print(res)


main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import sys
import subprocess
import json
import time
import math
import re
import sqlite3
 
N = int(input())
s = input()
x = 0
max_x = 0
 
for c in s:
    if c == 'I': x += 1
    else: x -= 1
    max_x = max(max_x, x)
 
print(max_x)

Submission status: Accepted

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

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

N = int(input())
s = input()
x = 0
max_x = 0

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

print(max_x)

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
x_max = 0

for i in S:
    if i == "I":
        x += 1
    else:
        x -= 1
    if x > x_max:
        x_max = x

print(x_max)

Submission status: Accepted

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

x = 0
x_max = 0

for s in S:
    if s == "I":
        x += 1
    else:
        x -= 1
    if x > x_max:
        x_max = x

print(x_max)

Submission status: Accepted

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

        
print(max)

Submission status: Accepted

Solution code:
N = input()
S = raw_input()
x = 0
maxx = 0
for c in S:
  if c == 'I':
    x += 1
  else:
    x -= 1
  if(x > maxx):
    maxx = x
print maxx

Submission status: Accepted

Solution code:
N = int(input())

S = [i for i in input()]

tmp = 0
m = 0

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

    if tmp > m:
        m = tmp

print(m)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
state = [0]
n     = int(input())
chars = list(input())
for c in chars:
  if c == "D":
    a = state[-1]
    a -= 1
  else:
    a = state[-1]
    a += 1
  state.append(a)
print(max(state))

Submission status: Accepted

Solution code:
#coding: shift_jis


N = int(raw_input())
S = raw_input()
x = 0
y = [x]
for i in range(N):
    if S[i] == 'I':
        x += 1
    elif S[i] == 'D':
        x -= 1
    y.append(x)
print max(y)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())

s = np.zeros(n)
s = input()

x = 0
x1 = 0

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

print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
length = int(input())
values = input()
continued_l = len(values)
x = 0
max_x = 0
for c in values:
    if c == 'I':
        x += 1
    elif c == 'D':
        x -= 1
    if x > max_x:
        max_x = x
print(max_x)

Submission status: Accepted

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


X=0
X_max=0

for i in range(N):
    
    if S[i]=="I":
        X=X+1
       
        if X>X_max:
            X_max=X
    else:
        X=X-1

print(X_max)

Submission status: Accepted

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

Submission status: Accepted

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

print(max)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
li = [0]

for i in range(N):
    if S[i] is 'I':
        cnt += 1
    else:
        cnt -= 1
    li.append(cnt)

print(max(li))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(raw_input())
S = raw_input()
ans = cur = 0
for s in S:
    if s == "I":
        cur += 1
    else:
        cur -= 1
    ans = max(ans, cur)
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
    elif (s[i] == 'D'):
        x -= 1

    if (max < x):
        max = x


print("%d" % max)

Submission status: Accepted

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


def main(n, s):
    count = 0
    max_values = []
    for c in s:
        if c == 'I':
            count += 1
            max_values.append(count)
        else:
            count -= 1
    max_values = max_values if max_values else [0]
    return max(max_values) if 0 < max(max_values) else 0


if __name__ == '__main__':
    n = int(input())
    s = input()
    answer = main(n, s)
    print(answer)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    S = input()
    x = 0
    vs = []
    vs.append(x)
    for c in S:
        if c == 'I':
            x += 1
        else:
            x -= 1
        vs.append(x)
    print(max(vs))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    N = int(input())
    S = str(input())
    x = 0
    ans = 0
    for c in S:
        x += {"I": 1, "D": -1}[c]
        ans = max(ans, x)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = input()
a = list(input())


sumlist = [0]
suma = 0
for i in a:
    if i=="I":
        suma += 1
        sumlist.append(suma)
    else:
        suma -= 1
        sumlist.append(suma)
print(max(sumlist))

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !

num=int(input())
words=input().rstrip()
x=0
xmax=0

for i in words:
    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()

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

c = 0
maxi = 0
for i in s:
    if i == "I":c+=1
    else :c-=1
    maxi = max(maxi, c)
print (maxi)

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:
# -*- coding: utf-8 -*-

# N, Sの入力
n = int(input())
s = input()

x = 0
maxi = x
for i in list(s):
    if i is 'I':
        x += 1
    elif i is 'D':
        x -= 1
    if x >= maxi:
        maxi = x

# 最大値の出力
print(maxi)

Submission status: Accepted

Solution code:
if __name__=="__main__":
    N = int(input())
    S = input()
    n = 0
    max = 0
    for s in S:
        if(s == "I"):
            n += 1
            if(max < n):
                max = n
        else:
            n -= 1
    print(max)

Submission status: Accepted

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

Submission status: Accepted

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

for ss in s:
    if ss == "I":
        x = x + 1
        if x > xmax:
            xmax = x
    elif ss == "D":
        x = x - 1

print(xmax)

Submission status: Accepted

Solution code:
N = int(raw_input())
S = raw_input()
max = 0
x = 0
for s in S:
	x += 1 if s == "I" else -1
	if x > max: max = x
print max

Submission status: Accepted

Solution code:
input()
ans,x=0,0
for c in input():
    x+={'I':1,'D':-1}[c]
    ans=max(ans,x)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
x = 0
max_x = 0
for c in S:
    if c == '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()
c = 0
max_c = 0
for i in range(len(S)):
    if S[i] == 'I': c += 1
    else: c -= 1
    max_c = max(max_c, c)
print(max_c)

Submission status: Accepted

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

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
le = int(input())
a = [i for i in input()]
ans = 0
sum = 0
for i in range(le):
    if a[i] == "I":
        sum = sum + 1
    else:
        sum = sum - 1
    if ans < sum:
        ans = sum
print(ans)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
N = int(input())
S = input()
x = 0
maximum = 0

for factor in range (0, len(S)):
    if S[factor] == 'I':
        x += 1
    elif S[factor] == 'D':
        x -= 1
    
    if maximum < x:
        maximum = x

print(maximum)

Submission status: Accepted

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

num = 0
max_num = 0

for i in list(S):
    if i == 'I':
        num += 1
    elif i == 'D':
        num -= 1
    if max_num < num:
        max_num = num
        
print max_num