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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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["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: Runtime Error

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["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

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Runtime Error

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: Runtime Error

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,arr))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
x=0
s_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: Runtime Error

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: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

I_count = [i for i, x in enumerate(S) if x == 'I']
D_count = [i for i, x in enumerate(S) if x == 'D']

tmp = [0] * N
for i in I_count:
    tmp[i] = 1
for i in D_count:
    tmp[i] = -1

ans = 0
List = []
for i in range(N):
    ans += tmp[i]
    List.append(ans)

print(max(0, List))

Submission status: Runtime Error

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

x = 0
l = []

for i in S:
    if i == 'I':
        x += 1
    elif i == 'D':
        l.append(x)
        x -= 1
print(max(l))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
 x = nums =0
 dic = {'I': 1, 'D': -1}
 for i in s:
     x += dic[i]
     nums = max(x, nums)
print(nums)

Submission status: Runtime Error

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,0))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = input()
str = input()
val = []
o = str[:1]
if o == 'D':
  n -= 1
  val.append(n)
  str = str[1:]
else:
  n += 1
  val.append(n)
  str = str[1:]

Submission status: Runtime Error

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

Submission status: Runtime Error

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

       print(max(lst_for_ans,0))

Submission status: Runtime Error

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: Runtime Error

Solution code:
# this is cumulative
n = int(input())
s = input()

point = 0
cum_sum = []

for i in s:
    if i == "I":
        point += 1
    else:
        point -= 1
    cum_sum.append(point)
else:
    print(max(cum_sum,0))

Submission status: Runtime Error

Solution code:
#52b
n = int(input())
s = input()
ans = [0]

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

print(max(ans))

Submission status: Runtime Error

Solution code:
i = int(input())
s = input()
ans = 0

for x in range(len(i)) :
    if s[x] == "I" :
        ans ++
    else :
        ans --

print(ans)

Submission status: Runtime Error

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: Runtime Error

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

num = 0
res = 0

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

print(res)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
x = 0
for item in S:
  if item == 'I":
  	x+= 1
  if item == 'D':
    x-= 1
N = int(input())
S = list(input())
x = 0
for item in S:
  if item == 'I":
  	x+= 1
  if item == 'D':
    x-= 1

print(x)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
x = 0
for item in S:
  if item == 'I":
  	x+= 1
  if item == 'D':
    x-= 1

Submission status: Runtime Error

Solution code:

x=0
n=int(input())
F=list(input())
#lis=F.split()
alist=[]
alist.append(x)
for token in F:



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


for i in alist:

    if alist[i]>alist[i+1]:
        x=alist[i]

    else:
        x=alist[i+1]



print(x)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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=list(set(a))
b=a.reverse()
print(b[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = list(input())
i_tmp1 = 200001

for i in range(len(s)):
   if s[i] == "A":
      i_tmp1= i
   elif s[i] == "Z" and i >= i_tmp1:
      i_tmp2  = i
      break

print(i_tmp2-i_tmp1+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = raw_input()
x = n.split()
N= int(x[0])
S = x[1]
x=0 
y = str(x)
for i in range(0,N):
    if S[i] == "I":
        x = x+1 
        y = y + str(x)
    elif S[i]=="D":
        x = x - 1 
        y = y + str(x)
        
print max([int(c) for c in ])

Submission status: Runtime Error

Solution code:
n = raw_input()
S = raw_input()

N = int(n)
x=0 
y = str(x)
for i in range(0,N):
    if S[i] == "I":
        x = x+1 
        y = y + str(x)
    elif S[i]=="D":
        x = x - 1 
        y = y + str(x)
        
print max([int(c) for c in y])

Submission status: Runtime Error

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: Runtime Error

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)



    



  
    
    

    
    
#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: Runtime Error

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 -= 
    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: Runtime Error

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: Runtime Error

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
    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: Runtime Error

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
    return max(max_values) if 0 < max(max_values) else 0


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

Submission status: Runtime Error

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

for c in S:
    if c == 'I':
        x += 1
    if c == 'D':
        x -= 1
    if x > maxx:
        maxx = x

print maxx

Submission status: Runtime Error

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: Runtime Error

Solution code:
n=int(raw_input())
s=raw_input()
ans=0
for i in xrange(n):
    if s[i]=="I":
        cnt+=1
        ans=max(ans,cnt)
    elif s[i]=="D":
        cnt-=1
        ans=max(ans,cnt)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
    input()
    S = input()
    x = 0
    max_x = 0
    for elem in S:
    	if elem == 'I':
    		x += 1
    	elif elem == 'D':
    		x -= 1
    	if x > max_x:
    		max_x = x
    print(max_x)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

x = []
cnt = 0
for i in s:
    if s[i] == 'I':
        cnt += 1
        x.append(cnt)
    elif s[i] == 'D':
        cnt -= 1
        x.append(cnt)
    else:
       x.append(cnt)

print max(x)