Problem:


Score : 200 points

Problem Statement

You have an integer variable x.
Initially, x=0.

Some person gave you a string S of length N, and using the string you performed the following operation N times.
In the i-th operation, you incremented the value of x by 1 if S_i=I, and decremented the value of x by 1 if S_i=D.

Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).

Constraints

1≤N≤100

|S|=N

No characters except I and D occur in S.

Input

The input is given from Standard Input in the following format:

N
S

Output

Print the maximum value taken by x during the operations.

Sample Input 1

5
IIDID

Sample Output 1

2

After each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively. Thus, the output should be 2, the maximum value.

Sample Input 2

7
DDIDDII

Sample Output 2

0

The initial value x=0 is the maximum value taken by x, thus the output should be 0.



Sample input:
5
IIDID


Sample output:
2

Submission status: Accepted

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

x = 0
max = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

print(X)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

Submission status: Accepted

Solution code:
import sys

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

ans = 0
tmp = 0
for c in S:
    if c == "I":
        tmp += 1
    elif c == "D":
        tmp -= 1
    ans = max(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
    else:
        x -= 1
    ans = max(ans, x)
print(ans)

Submission status: Accepted

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n = int(input())
    s = input()
    ans = 0
    hoge = [ans]
    for i in s:
        if i == "I":
            ans += 1
        else:
            ans -= 1
        hoge.append(ans)
    print(max(hoge))
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ss = input()
ans = 0
total = 0
for s in ss:
    if s == "I":
        total += 1
        ans = max(ans, total)
    else:
        total -= 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:
n = int(input())
s = input()
x = 0
ans = 0
for si in s:
    x += (si == "I")
    x -= (si == "D")
    ans = max(ans,x)
print(ans)

Submission status: Accepted

Solution code:
#B - Increment Decrement
N = int(input())
S = list(input())

maxim = 0
count = 0
for i in S:
    if i == 'I':
        count += 1
    else:
        count -= 1
    if maxim < count:
        maxim = count
print(maxim)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
max_ = 0
cur = 0
for i in rr():
    if i == 'D':
        cur -= 1
    if i == 'I':
        cur += 1
    max_ = max(cur, max_)
print(max_)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
count = 0
count_list = [0]

for i in range(len(s)):
    if s[i] == "I":
        count += 1
        count_list.append(count)
    else:
        count -= 1
        count_list.append(count)

print(max(count_list))

Submission status: Accepted

Solution code:
input()
S = input()

ans = 0
tmp = 0

for si in S:
    tmp += [-1,1][si=='I']
    ans = max(ans,tmp)

print(ans)

Submission status: Accepted

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

x = [0] * 101
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:
import os
import sys
import math
if os.environ.get("DEBUG") is not None:
    sys.stdin = open("in.txt", "r")
rl = sys.stdin.readline

n, s = [rl().rstrip("\n") for _ in range(2)]
x = 0
ans = 0
for it in s:
    if it == "I":
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print(ans)

Submission status: Accepted

Solution code:
import os
import sys
import math
if os.environ.get("DEBUG") is not None:
    sys.stdin = open("in.txt", "r")
rl = sys.stdin.readline

n, s = rl().rstrip("\n"), rl().rstrip("\n")
x = 0
ans = 0
for it in s:
    if it == "I":
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
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
    ans = max(ans, x)
  else:
    x -= 1
    ans = max(ans, x)
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:
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()
x = 0
c = 0
x1 = 0
t = []
for i in s:
	if i=='I':
		c+=1
	if c>x:
		x =c
	elif i=='D':
		c-=1
	if c>x1:
		x1=c

	t.append(max(x1,x))
print(max(t))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = 0
maxX = 0

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

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

print(maxX)

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

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:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

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

x = 0
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
ans_max = 0
for i in s:
    if i == "I":
        ans += 1
    else:
        ans -= 1
    if ans > ans_max:
        ans_max = ans

print(ans_max)

Submission status: Accepted

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

print(max(ls))

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
t = 0

for s in S:
    if s == "I":
        t += 1
    else:
        t -= 1

    res = max(res, t)

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = input()
    S = input()
    x = 0
    max_x = 0
    for i in range(len(S)):
        if S[i] == "I":
            x += 1
            if x > max_x:
                max_x = x
        elif S[i] == "D":
            x -= 1
    print(max_x)

resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Sum = 0
Max = 0

for s in S:
    Sum += (-1)**(s == 'D')
    Max = max(Sum, Max)

print(Max)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

ans = 0
x = 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 = input()

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

print(res)

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:
x=0
n=int(input())
s=input()
ans=x
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= map(int,input().split())
S = input()
syukei = [0,]
num = 0
count = 0
while len(S) > count:
    for i in S:
        count +=1
        if i == 'I':
            num +=1
            syukei.append(num)
        else:
            num -=1
            syukei.append(num)

print(max(syukei))

Submission status: Accepted

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

x = 0
x_temp = 0
for i in range(n):
    if s[i] == "I":
        x_temp += 1
        if x < x_temp:
            x = x_temp
    elif s[i] == "D":
        x_temp -= 1

print(x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import math
#a, d = map(int,input().split())
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:
# -*- coding: utf-8 -*-

def main():

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

    listS = list(S)
    x = 0
    listNum = [x]

    for i in listS:
        if i == 'I':
            x += 1
            listNum.append(x)

        elif i == 'D':
            x += -1
            listNum.append(x)

    ans = max(listNum)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(maxV)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
s = input()
while "DI" in s:
    s = s.replace("DI", "")
print(s.count("I"))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    x = ans = 0
    for s in S:
        if s == 'I':
            x += 1
            if x > ans:
                ans = x
        else:
            x -= 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

print(nax)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
S = LS2()

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    S = SS()

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

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
sum = ""
li = []
for s in S:
    sum += s
    li.append(sum)

ic = 0
dc = 0
ma = 0
for l in li:
    ic = l.count("I")
    dc = l.count("D")
    ma = max(ma, ic - dc)
    
print(ma)

Submission status: Accepted

Solution code:
from collections import deque

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

d={'I':1, 'D':-1}
l=[0]*(N+1)

for x in range(1,N+1):
  l[x]=l[x-1]+d[S[x-1]]

print(max(l))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = input()
    x = 0
    tmp = 0
    for i in range(len(s)):
        if(s[i]=="D"):
            x-=1
        if(s[i]=="I"):
            x+=1
        tmp = max(tmp,x)
    print(tmp)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
MM = input()
x = 0
maxi = 0
for i in MM:
  if i =='D':
    x -=1
  else:
    x +=1
    if x > maxi:
      maxi = x
print(maxi)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#32 2020/07/14
N = int(input())
S = list(input())
count = 0
max = 0
for i in range(N):
  if S[i] == 'D':
    count -= 1
  elif S[i] == 'I':
    count += 1
  if count > max:
    max = count
print(max)

Submission status: Accepted

Solution code:
#32
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:
def main():
    N = int(input())
    S = list(input().rstrip())
    vals = [0]
    for s in S:
        if s == "I":
            vals.append(vals[-1] + 1)
        else:
            vals.append(vals[-1] - 1)
    print(max(vals))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

words = list(s)
x = 0
max_x = 0
n = int(p)

for num in range(len(words)):
    if words[num] == 'I':
        x += 1
        if x > max_x:
            max_x = x
    else:
        x -= 1

print(max_x)

Submission status: Accepted

Solution code:


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    x = 0
    max_x = 0
    n = read_int()
    for c in input().strip():
        if c == 'I':
            x += 1
        else:
            x -= 1
        max_x = max(max_x, x)
    return max_x


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

Submission status: Accepted

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

ans,x = 0,0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

N = ri()
S = rs()
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 = input()
now = 0
ans = 0
for s in S:
    if s == "I":
        now = now + 1
    else:
        now = now - 1
    ans = max(now, ans)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
s=list(input())

x=0
mx=0

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

Submission status: Accepted

Solution code:
n  = int(input())
s = input()
x=0
m = 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
res = 0
for s in S:
    if s == 'I':
        x += 1
        res = max(res, x)
    else:
        x -= 1
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
_, s = open(0).read().split()

print(
    max([sum(1 if i == "I" else -1 for i in s[:j+1])
         for j in range(int(_))] + [0]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	s_list = list(S())
	x = 0
	x_max = 0
	for s in s_list:
		if s == 'I':
			x += 1
		else:
			x -= 1
		x_max = max(x, x_max)
	print(x_max)


if __name__ == '__main__':
    main()

Submission status: Accepted

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