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
num = 0

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

Submission status: Accepted

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

x = 0
max_x = 0

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

    if x > max_x:
        max_x = x

print(max_x)

Submission status: Accepted

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

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)
  if S[i] == "D":
    x = x-1
    X.append(x)
X.sort(reverse = True)
print(X[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, S: str):

    x = 0
    m = 0
    for c in S:
        if c == "I":
            x += 1
        else:
            x -= 1
        m = max(m, x)
    print(m)
    return


def main():

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n = INT()
    s = input()
    l = [0] * (n + 1)

    for i in range(n):
        if s[i] == "I":
            l[i] = l[i-1] + 1
        else:
            l[i] = l[i-1] - 1
    print(max(l))
if __name__ == "__main__":
    main()

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:
#python3

def main():
    n = int(input())
    s = input()
    ans = -1000
    x = 0
    for st in s:
        if st == 'I':
            x+=1
        else:
            x-=1
        ans = max(ans, x)
    if ans>=0:
        print(ans)
    else:
        print(0)
main()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
m = 0
p = 0
for i in S:
  if i == "D":
    p -= 1
  else:
    p += 1
  if p >= m:
    m = p
print(m)

Submission status: Accepted

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

x = 0

out =  [0]

for s in string:
    if s == "I":
        x += 1
    else:
        x -= 1
    out.append(x)

print(max(out))

Submission status: Accepted

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

Submission status: Accepted

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

for ss in s:
  if ss == "I":
    x+=1
  elif ss == "D":
    x-=1
  
  if x > max:
    max = x
    
print(max)

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

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    ans=0
    temp=0
    n=INT()
    s=STR()
    for i in s:
        if i=='I':
            temp+=1
            ans=max(ans,temp)
        else:
            temp-=1
    print(ans)
if __name__ == '__main__':
    do()

Submission status: Accepted

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

x = 0
plus_number = [0]
for i in range(len(S)):
  if S[i] == "I":
    x += 1
  elif S[i] == "D":
    x -= 1
  plus_number.append(x)
print(max(plus_number))

Submission status: Accepted

Solution code:
n = [input() for _ in range(2)]
ans = 0
a = []

for i in range(int(n[0])):

	if n[1][i] == "I":
		ans = ans + 1
		a.append(ans)
	elif n[1][i] == "D":
		ans = ans - 1
		a.append(ans)

print(max(0,max(a)))

Submission status: Accepted

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

    # print(N, S)

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

    return ans


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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 050 - B
# -*- encoding: UTF-8 -*-
n = int(input())
s = input()

slist = list(s)
x = 0
xmax = 0

for i in slist:
  if i == "I":
    x = x + 1
  else:
    x = x - 1
  
  if x > xmax:
     xmax = x

print(xmax)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
s=input().strip()
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
for i in range(1, N+1):
    x = max(x, S[:i].count('I') - S[:i].count('D'))
print(x)

Submission status: Accepted

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

x=0
max_x=0

for si in list(s):
    if(si=="I"):
        x+=1
    else:
        x-=1
    if(max_x<x):
        max_x=x
print(max_x)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
S = list(input().rstrip())
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:
x = m = 0
N = int(input())
S = input()
for s in S:
    x += 1  if s == 'I' else -1
    m = max(m, x)
print(m)

Submission status: Accepted

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

count = 0
cmax = 0
for i in s:
  if i == 'I':
    count += 1
  else:
    count -= 1

  if count > cmax:
    cmax = count

print(cmax)

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

Submission status: Accepted

Solution code:
N = input()
string = list(input())

ans = 0
tmp = 0
for char in string:
	if char == "I":
		tmp += 1
	else:
		tmp -= 1
	ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(max(lis))

Submission status: Accepted

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

if max(mylist) < 0:
    print(0)    
else:
    print(max(mylist))

Submission status: Accepted

Solution code:

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

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

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

print(ans)

Submission status: Accepted

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

print(max_x)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = input()
length = len(s)
tmp = 0
ans = 0
for i in range(length):
    if s[i] == 'I':
       tmp += 1
       if tmp > ans:
           ans = tmp

    else:
        tmp -= 1

print(ans)

Submission status: Accepted

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

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

print(max_ans)

Submission status: Accepted

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

ans=0
for i in range(N):
    if(S[i]=='I'):
        ans+=1
        L.append(ans)
    else:
        ans-=1
        L.append(ans)

print(max(L))

Submission status: Accepted

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

Submission status: Accepted

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

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

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())
S = list(input())


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


print(max)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#K, S = map(int, input().split())
N = int(input())
S = str(input())

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

print (m)

Submission status: Accepted

Solution code:
n = input()
S = input()
A = [1 if s == "I" else -1 for s in S]
cum_A = [0]*(len(A)+1)
for i in range(len(A)):
  cum_A[i+1] += A[i] + cum_A[i]

print(max(cum_A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#52b
N = int(input())
S = str(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 = str(input())

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

print(maxi)

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(lambda x:1 if x=='I' else -1, input()))
x = 0
max_x = 0

for s in S:
	x += s
	max_x = max(max_x, x)
print(max_x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Nは使わない
_ = input()

# 文字列
S = input()

# 答えの初期値は0
ans = 0
current = 0
for s in S:
    # Iなら+1
    if s == "I":
        current +=1
    elif s== "D":
        current -=1
    # 最大値を更新する
    ans = max(ans, current)
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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:

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

ans = 0
l = [0]

for i in range(n):
    if s[i] == "I":
        ans += 1
        l.append(ans)
    elif s[i] == "D":
        ans -= 1
        l.append(ans)

print(max(l))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
tmp=0
for si in s:
    if si=="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 = []  

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

if max(ans) >= 0:
    print(max(ans))
else:
    print(0)

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

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

Submission status: Accepted

Solution code:
n = int(input())
l = input()
ans = 0
max_ans = 0
for i in l:
  if i == 'D':
    ans -= 1
  else:
    ans += 1
  max_ans = max(ans,max_ans)
    
print(max_ans)

Submission status: Accepted

Solution code:
import sys

n, s = sys.stdin.read().split()
n = int(n)

def main():
    t = s
    t = t.replace('I', '+')
    t = t.replace('D', '-')
    x = 0
    res = 0
    for i in range(n):
        x += eval(t[i] + '1')
        res = max(res, x)

    return res

if __name__ == '__main__':
    ans = main()
    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
  if s[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 c in S:
    if c == 'I':
        x += 1
        ans = max(ans, x)
    else:
        x -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main(n: int, s: str):
    i = 0
    ans = [0]

    for s in s:
        if s == 'I':
            i += 1
        else:
            i -= 1

        ans.append(i)

    print(max(ans))


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

    main(n, s)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(max(x))

Submission status: Accepted

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

x = 0
xmax = 0

for i in range(n):
    if s[i] == "I":
        x += 1
        xmax = max(xmax, x)
    elif s[i] == "D":
        x -= 1
        xmax = max(xmax, x)

print(xmax)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#coding:utf-8
n = int(input())
s = input()
x = 0
num = []
num.append(x)

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

print(max(num))

Submission status: Accepted

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

Submission status: Accepted

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

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)
  elif s == "D":
    x -= 1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]

sum = 0
change = {"I": 1, "D": -1}
length = int(fetch_one_line())
target = fetch_one_line()
records = [0 for _ in range(length)]

for i, t in enumerate(target):
   sum += change[t]
   records[i] = sum

max_val = max(records)
if max_val < 0:
    max_val = 0
print(max_val)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
x = 0
ans = [0]
for s in S:
    if s == "I":
        x += 1
    elif s == "D":
        x -= 1
    ans.append(x)


print(max(ans))

Submission status: Accepted

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


for s in ls:
    if s == 'I':
        x += 1
    else:
        x -= 1
    if ans < x:
        ans = x

print(ans)

Submission status: Accepted

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

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

    ans = max(x, ans)

print(ans)

Submission status: Accepted

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

print(max(x))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
max = 0
tmp = 0
for i in S:
    if i == 'I':
        tmp += 1
    else:
        tmp -= 1
    if max < tmp:
        max = tmp
print(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
    X_max = max(X, X_max)

print(X_max)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

test = 0

l=[0]*(n+1)

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

print(max(l))

Submission status: Accepted

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

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

print(x_max)

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

Submission status: Accepted

Solution code:
N = int(input())
result = 0
A = 0
for i in input():
  if i == "I":
    A += 1
  else:
    A -= 1
  result = (max(result,A))
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()


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

print(ma)

Submission status: Accepted

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

for i in s:
  if i =='I':
    ans +=1
  else:
    ans -=1
  if ans > max:
    max = ans
print(max)

Submission status: Accepted

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

for i in s:
    if i == 'I':
        ans += 1
    else:
        ans -= 1

    if ans >= max:
        max = ans

print(max)

Submission status: Accepted

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

ans = 0
x = 0

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

print(ans)

Submission status: Accepted

Solution code:
def judge(N,S):
    x = 0
    maxi = 0
    lst = list(S)
    for i in range(N):
        if lst[i]=="I":
            x += 1
        else:
            x -= 1
        if maxi<x:
            maxi = x
    print(maxi)

N = int(input())
S = input()
judge(N,S)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = 0
xmax = 0
_ = input()
for si in input():
  if si == "I":
    x += 1
  elif si == "D":
    x -= 1
  xmax = max(x, xmax)
print(xmax)

Submission status: Accepted

Solution code:
##### 解けた #####

N=int(input())
S=input()
maxx=0 # xの最大値
x=0 # xの初期値

for s in S:
    if s=="I": # "I"の場合は増やす
        x+=1
    elif s=="D": # "D"の場合は減らす
        x-=1

    if x>maxx: # 最大値を上回ったら更新
        maxx=x
    
print(maxx)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    S=ST()
    ans = 0
    now = 0
    for s in S:
        if s=="I":
            now += 1
        else:
            now -=1
        ans = max(ans,now)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    count = [0]

    for c in S:
        if c == 'I':
            count.append(count[-1] + 1)
        elif c == 'D':
            count.append(count[-1] - 1)
    return max(count)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

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

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()
c0 = 0
c1 = 0
for i in S:
    if i == "I":
        c1 += 1
    elif i == "D":
        c1 -= 1
    c0 = max(c0,c1)
    
print(c0)

Submission status: Accepted

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

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

Submission status: Accepted

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