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 = 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()
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 = list(map(str, input()))
mx = 0
sm = 0

for char in s:
    if char == "I":
        sm += 1
        mx = max(mx, sm)
    elif char == "D":
        sm -= 1
    else:
        continue

print(mx)

Submission status: Accepted

Solution code:
def answer(n: int, s: str) -> int:
    while 'DI' in s:
        s = s.replace('DI', '')

    return s.count('I')


def main():
    n = int(input())
    s = input()
    print(answer(n, s))


if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    ans = 0
    t  = 0
    for i in S:
        if i == "I":
            t += 1
        if i == "D":
            t -= 1
        if t > ans:
            ans = t
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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()

def ans052(N:int, S:str):
    x=0
    x_list=[0]
    for i in range(N):
        if S[i]=="I":
            x+=1
            x_list.append(x)
        elif S[i]=="D":
            x-=1
            x_list.append(x)
    x_list.sort()
    return x_list[-1]

print(ans052(N,S))

Submission status: Accepted

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

m = 0
x = 0
for w in s:
	if w == "I":
		x += 1
	else:
		x -= 1
	
	if x > m:
		m = x
		
print(m)

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

Submission status: Accepted

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

x = 0
lst = [0]

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

print(max(lst))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
ans = list(input())
count = 0
a = set()
for i in range(n):
    if ans[i] == 'I':
        count += 1
        a.add(count)
    elif ans[i] == 'D':
        count -= 1
        a.add(count)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
a,b=[input() for i in range(2)]
p=0
ans=0

for i in b:
  if i =='I':
    p+=1
  elif i =='D' and p>0:
    p-=1
  else:
    p-=1
  
  if ans<p:
    ans=p
 
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
  elif S[i] == "D":
    cnt -= 1
  
  ans = max(ans, cnt)
  
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

max_num = 0
idx = 0
x = 0
while idx < N:
    if S[idx] == 'I':
        x += 1
    else:
        x -= 1
    max_num = max(x, max_num)
    idx += 1

print(max_num)

Submission status: Accepted

Solution code:
N,S=int(input()),input()
print(max([(t:=S[:m+1]).count("I")-t.count("D") for m in range(N)]+[0]))

Submission status: Accepted

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

ans = 0
count = 0
for i in S:
    if i == 'I': count += 1
    elif i == 'D': count -= 1
    ans = max(ans, count)

print(ans)

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    answers=[0]
    n = int(input())
    S = input()
    x=0

    for s in S:
        if "I" in s:
            x+=1
            answers.append(x)
        elif "D" in s:
            x-=1
            answers.append(x)
    print(max(answers))

if __name__=="__main__":
    main()

Submission status: Accepted

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

M = 0
Sum = 0

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

print(M)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import copy
import math
import itertools
import numpy as np

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

c = 0
ans = 0
for i in list(s):
    if 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 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()
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:
N = int(input())
S = str(input())
x = 0
L = [x]
for i in S:
  if i == 'I':
    x += 1
  if i == 'D':
    x -= 1
  L.append(x)
print(max(L))

Submission status: Accepted

Solution code:
# coding: utf-8

num = input()
count = 0
max = 0
message = input()
table = list(message)
for i in table:
    if i == "I":
        count += 1
    elif i == "D":
        count -= 1
    if max <= count:
        max = count
print(max)

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
a=int(input())
b=input()
c=0
d=[0]
for i in b:
    if(i=="I"):
        c+=1
        d.append(c)
    elif(i=="D"):
        c-=1
        d.append(c)
print(max(d))

Submission status: Accepted

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

        if max_s < x:
            max_s = x

    print(max_s)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = input().strip()

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

Submission status: Accepted

Solution code:
a=int(input())
b=input()
c=0
d=0
for i in range(a):
  if b[i]=="D":
    c=c-1
  if b[i]=="I":
    c=c+1
  if c>d:
    d=c
print(d)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

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

    array = [0]
    for i in range(len(S)):
        if S[i] == 'I':
            array.append(array[i]+1)
        if S[i] == 'D':
            array.append(array[i]-1)
    print(max(array))


if __name__ == '__main__':
    main()

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:
import sys
import copy
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(input().strip())
s = input().strip()
ans = 0
cnt = 0
for i in s:
    if i == "I": cnt += 1 
    else: cnt -= 1
    ans = max(ans, cnt)
print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
x_max = x

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

print(x_max)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max(x_list))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    ans = 0
    cur = 0

    for char in S:
        if char == "I":
            cur += 1
        else:
            cur -= 1

        ans = max(ans, cur)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
ans_tmp = 0
for s in S:
  if s=="I":
    ans_tmp += 1
    ans = max(ans_tmp, ans)
  else:
    ans_tmp -= 1
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
    else:
        x -= 1
    ans = max(ans, x)
print(ans)

Submission status: Accepted

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

x = 0
maxi = 0

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

    if x > maxi:
        maxi = x

print(maxi)

Submission status: Accepted

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

print(m)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(res)

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

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

print(mx)

Submission status: Accepted

Solution code:
input()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(maximum)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

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

ans = 0
tmp = 0
for i in S:
  if i == 'I':
    tmp += 1
    ans = max(ans, tmp)
  else:
    tmp -= 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 = list(input())

x = 0
mx = 0

for a in s:
  if a == "I":
    x +=1
  else:
    x -=1
  if x > mx:
    mx = x
    
print(mx)

Submission status: Accepted

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

for s in S:
  if s == 'I':
    x += 1
  else:
    x -= 1
  a.append(x)

print(max(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
highest = 0
for i in S:
    if i == "I":
        ans += 1
    else:
        ans -= 1
    if highest <= ans:
        highest = ans 

print(highest)

Submission status: Accepted

Solution code:
def main():
    input()
    s = input()
    tmp = 0
    ans = 0
    for v in s:
        if v == "I":
            tmp += 1
        else:
            tmp -= 1
        ans = max(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
max_int = 0
count = 0
for i in S:
    if i == 'I':
        count +=1
        max_int = max(max_int, count)
    elif i == 'D':
        count -= 1
print(max_int)

Submission status: Accepted

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

ans=0
num=0
for i in s:
  if i=="I":
    num+=1
    ans=max(ans,num)
  elif i=="D":
    num-=1
    ans=max(ans,num)
    
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    S = input()
    ans = 0
    val = 0
    for c in S:
        if c == 'I':
            val += 1
            ans = max(ans, val)
        else:
            val -= 1
    print(ans)


if __name__ == "__main__":
    main()

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()
x = 0
ans = x
for c in S:
    if c == 'I':
        x += 1
    elif c == 'D':
        x -= 1

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

Submission status: Accepted

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

max_result = 0
result = 0


for i in s:
    if i == "I":
        result += 1
        if result > max_result:
            max_result = result
    else:
        result -= 1


print(max_result)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

num_list = [0]
sum = 0
for w in s:
  if w == 'I':
    sum += 1
  else:
    sum -= 1
  num_list.append(sum)

num_list.sort()
ans = num_list[-1]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ma = 0
count = 0
for i in S:
    count += -1 if i == 'D' else 1
    if ma < count:
        ma = count
print(ma)

Submission status: Accepted

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

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

print(max_cnt)

Submission status: Accepted

Solution code:
import sys
import numpy as np
# from decimal import Decimal
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# ----------------------------------------
n = int(readline())
#s = readline()
# print(s)
s = input()

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

    ans = max(x, ans)
    # print(ans)


print(ans)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

po = input()[:-1]
ma = 0
co = 0

for a in po:
    if a == "I":
        co += 1
    else:
        co -= 1
    ma = max(ma,co)
print(ma)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
m,c,n = 0,0, raw_input()
for l in raw_input():
	c += 1 if l == 'I' else -1
	m = max(c,m)
print m

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())
S = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Increment Decrement 
def main():
    n = int(input())
    s = input()
    cnt = 0
    ans = 0

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


if __name__ ==  "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
MAX = 0
Now = 0
for TS in range(0,N):
    Now += [-1,1][S[TS]=='I']
    MAX = max(MAX,Now)
print(MAX)

Submission status: Accepted

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

Submission status: Accepted

Solution code:


N = int(input())
S = str(input())
sum = 0
L = []
for i in range(N):
    if S[i] == "I":
        sum += 1
        L.append(sum)
    elif S[i] == "D":
        sum -= 1
        L.append(sum)

if max(L) > 0:
    print(max(L))

else:
    print(0)

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()

cnt = 0
m = 0

for i in range(len(s)):
    if s[i] == 'I':
        cnt += 1
        m = max(m, cnt)
    if s[i] == 'D':
        cnt -= 1
        m = max(m, cnt)
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
    elif(s == "D"):
        x -= 1
    res = max(res, x)
print(res)

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

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

print(m)

Submission status: Accepted

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

Submission status: Accepted

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

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:
num = int(input())
new = input()

x = 0
m = 0
for i in range(num):
  if new[i] == "D":
    x -= 1
  if new[i] == "I":
    x += 1
  if m < x:
    m = x
print(m)

Submission status: Accepted

Solution code:
firstline = int(input())
sec = input()
maxN = 0
init = 0

for i in sec:
  if i == "I":
    init += 1
  else:
    init -= 1
  if init > maxN:
    maxN = init
    
print(maxN)

Submission status: Accepted

Solution code:
length = int(input())
string = input()
x = 0
m = 0
for i in string:
  if(i == "D"):
    x-=1
  if(i == "I"):
    x+=1
  if(m < x):
    m = x
print(m)

Submission status: Accepted

Solution code:

def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n = int(input().rstrip())
    s = input().rstrip()

    x = 0
    max_x = 0
    for c in s:
        if c == "I":
            x+=1
            if x > max_x:
                max_x = x
        else:
            x -= 1


    print(max_x)




if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int (input ())
s = input ()
x = 0
for i in range (n):
  y = s[:i+1].count ('I') - s[:i+1].count ('D')
  if x < y:
    x = y
print (x)

Submission status: Accepted

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

for i in S:
    if i == 'I':
        x += 1
        X += [x]
    else:
        x -= 1
        X += [x]
print(max(X))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
a = 0
sum_a = 0

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

Submission status: Accepted

Solution code:
a = int(input())
b = input()
c = int(0)
d = int(0)
for i in range(a):
  if b[i] == "D":
    c = c - 1
  else:
    c = c + 1
    if c > d:
      d = c

print(int(d))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    S = input()

    res = 0
    ans = 0
    for item in S:
        if item == 'I':
            res += 1
        else:
            res -= 1

        
        ans = max(ans, res)

    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

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)