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

print(max(xs))

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

Submission status: Accepted

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

x, ans = 0, 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,s = open(0).readlines()

tmp = 0
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(l)

Submission status: Accepted

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

x = 0
x_max = 0

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

print(x_max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_ = int(input())
N = 0
S = list(input())
ans = 0
for i in S:
    if i == "I":
        N += 1
    else:
        N -= 1
    if ans < N: ans = N
print(ans)

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

print(max_x)

Submission status: Accepted

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

ans = 0
n = 0
for c in s:
    n = n + 1 if c == "I" else n - 1
    ans = max(n, ans)

print(ans)

Submission status: Accepted

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

ans = x

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

x = 0
max_x = 0

N = int(input())
S = list(str(input()))

for i in range(N):
    if S[i] == 'I':
        x += 1
        max_x = max(max_x, x)
    else:   # elseの処理は必ずいれること
        x -= 1
        max_x = max(max_x, x)

print(max_x)

Submission status: Accepted

Solution code:
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
x_max = 0
s_list = []

for i in s:
    s_list.append(i)

# print(s_list)

for i in s_list:
    if i == 'I':
        x += 1
        if x > x_max:
            x_max = x
    elif i == 'D':
        x -= 1


print(x_max)

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:
input()
a=t=0
for c in input():
  t+=(c>'D')*2-1
  a=max(a,t)
print(a)

Submission status: Accepted

Solution code:
s = input()
s = input()
x = 0
l_x = [0]
for c in s:
  x += 1 if c == 'I' else -1
  l_x.append(x)
    
print(max(l_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:
N = int(input())
line = list(input())
maxNum = 0
cur = 0
for i in line:
    if i == 'I':
        cur += 1
    else:
        cur -= 1
    maxNum = max(maxNum, cur)
print(maxNum)

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

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

    if ans < x:
        ans = x

print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
_ = input()
s = input()
tmp=0
ans=[0]
for i in s:
    if i == 'D':
        tmp-=1
    else:
        tmp+=1
    ans.append(tmp)
print(max(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:
N = int(input())
A = [0]

for s in input():
  if s=="I":
    A.append(A[-1]+1)
  else:
    A.append(A[-1]-1)

print(max(A))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

x = 0
temp = 0
for n in range(N):
    if S[n]=='I':
        temp+=1
    elif S[n]=='D':
        temp-=1
    if temp > x:
        x = temp
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.append(x)
    else:
        x-=1
        X.append(x)
print(max(X))

Submission status: Accepted

Solution code:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
S = str(input())
if N <= 0 or N > 100:
    sys.exit()
x = 0
max = 0
for I in S:
    if I == "I":
        x += 1
        if max < x:
            max = x
        continue
    if I == "D":
        x -=1
        continue
print(max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
x = 0
for i in range(len(s)):
    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 = input()
x = 0
ans = [x]
lis_S = list(S)

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

    ans.append(x)

print(max(ans))

Submission status: Accepted

Solution code:
#

import sys
input=sys.stdin.readline

def main():
    N=int(input())
    S=input()
    maxx=0
    for i in range(1,N+1):
        maxx=max(maxx,S[:i].count("I")-S[:i].count("D"))
    print(maxx)
    
if __name__=="__main__":
    main()

Submission status: Accepted

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

dp = [0 for j in range(len(S)+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:
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
xmax = 0
for i in range(N):
    if S[i] == "I":
        x += 1
    elif S[i] == "D":
        x -= 1
    if xmax <= x:
        xmax = x
print(xmax)

Submission status: Accepted

Solution code:
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

n = int(input())
s = input()
count = 0
max_num = 0
for _ in s:
    if _=="I":
        count+=1
    else:
        count-=1
    if max_num<count:
        max_num=count
print(max_num)

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()
SS=S.replace("I","1,").replace("D","-1,").split(",")
cnt=0
ans=0
for i in range(N):
    cnt+=int(SS[i])
    ans=max(ans,cnt)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# unihernandez22
# https://atcoder.jp/contests/abc052/tasks/abc052_b
# implementation

input()
s = input()

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

Submission status: Accepted

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

cnt=0
maxcnt=0

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

Submission status: Accepted

Solution code:
_ = input()
s = input()
ans = 0
c = 0
for i in s:
    c += 1 if i == "I" else -1
    ans = max(ans, c)
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
    else:
        x -= 1
    ans = max(x, ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    S = input()
    am = [0]
    ans = 0
    for i in range(N):
        if S[i] == "I":
            ans += 1
        if S[i] == "D":
            ans -= 1
        am.append(ans)
    print(max(am))
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
c=0
l=[0]

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def maximumx(N, S) : 
  x = 0
  max = 0
  
  for i in range(N) : 
    if S[i] == 'I' : 
      x += 1
      if max < x :
        max = x
    else : 
      x -= 1 
      
  return max


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

print(maximumx(N, S))

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]


def solve():
    n = int(input())
    s = input()
    cnt = 0
    ans = 0
    for e in s:
        if e == 'I':
            cnt += 1
        else:
            cnt -= 1
        ans = max(ans, cnt)
    print(ans)
        
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()



"""

1 4
7
RRRR
1 1 0 1
----
4

1 4
47
RCRR
1 1 0 1
----
-1

2 2
10
RR
RR
1 7
4 1
----
4

2 2
10
RR
RR
7 4
7 4
----
-1

3 3
8
RCR
RRC
RRR
1 1 1
1 1 1
1 3 1


3 3
1
RCR
RRC
RRR
1 1 1
1 1 1
1 3 1


"""

Submission status: Accepted

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

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

print(max_x)

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
s = s()
cnt = 0
ans = 0

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

Submission status: Accepted

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

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

if max(ans) <= 0:
  print("0")
else:
  print(max(ans))

Submission status: Accepted

Solution code:
import math
from collections import deque
from collections import defaultdict

import bisect


#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n = readInt()
s = readChar()

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

Submission status: Accepted

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

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

print(max(a))

Submission status: Accepted

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

# In[4]:


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


# In[5]:


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


# In[ ]:

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(str,input()))
ans = []
ans.append(0)
tmp = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
S = input()
Ans = [0]
ans = 0
for s in S:    
    if s == "I":
        ans += 1
    else:
        ans -= 1
    Ans.append(ans)

print(max(Ans))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    S = input().strip()
    return N, S


def solve(N, S):
    x = 0
    xmax = 0
    for s in S:
        if s == "I":
            x += 1
            xmax = max(xmax, x)
        else:
             x -= 1
    return xmax


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
ans = 0

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

    ans = max(ans, x)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = list(input())
A = [0]
loop = 0
for e in S:
    A.append(A[loop] + 1) if e == 'I' else A.append(A[loop] - 1)
    loop += 1
print(max(A))

Submission status: Accepted

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

Submission status: Accepted

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

count = [0]
c = 0
for i in l:
    if i == 'I':
        c += 1
        count.append(c)
    elif i == 'D':
        c -= 1
        count.append(c)
print(max(count))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

d = S.count('D')
i = S.count('I')
cnt = 0
cntold = 0
for n in range(N):
    if S[n] == 'D':
        cnt -= 1
    else:
        cnt += 1
    
    if cnt > cntold:
        cntold = cnt
print(cntold)

Submission status: Accepted

Solution code:
#ABC052-B
n = int(input())
s = input()

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

Submission status: Accepted

Solution code:
N=int(input())
S=list(str(input()))
x=0
x_max=0
for i in S:
  if i=='I':
    x+=1
    if x>x_max:
      x_max=x
  else:
    x-=1
print(x_max)

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
A = [0]
ans = 0
for s in S:
    if s == 'I':
        ans += 1
    else:
        ans -= 1
    A.append(ans)
print(max(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    a = int(input())
    s = input()
    count =0
    max = 0
    for i in s:
        if i == "I":
            count +=1
        else:
            count -=1

        if max < count:
            max = count
    print(max)

Submission status: Accepted

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


def solve(N: int, S: str):
    ids = [0] * (N + 1)
    for i, s in enumerate(S):
        p = -1 if s == "D" else 1
        ids[i + 1] += ids[i] + p
    print(max(ids))
    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()

res = 0
x = 0

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

print(res)

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:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

#############
# Main Code #
#############

N = getN()
now = 0
ans = 0
S = input()

for st in S:
    if st == "I":
        now += 1
    else:
        now -= 1
    ans = max(ans, now)
print(ans)

Submission status: Accepted

Solution code:
def li():
    return list(map(int, input().split()))
def mi():
    return map(int, input().split())
def ii():
    return int(input())

N = ii()
S = input()

current = 0
maxx = 0
for s in S:
    if s == "I":
        current += 1
    else:
        current -= 1
    maxx = max(maxx, current)

print(maxx)

Submission status: Accepted

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

Submission status: Accepted

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

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

x = 0
A = [0]
for i in range(N):
	if S[i] == "I":
		x += 1
		A.append(x)
	else:
		x += -1
		A.append(x)
#print(A)
print(max(A))

Submission status: Accepted

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

count = 0
result = 0
for i in S:
  if i == "I":
    count += 1
  else:
    count += -1
  result = max(count,result)
print(result)

Submission status: Accepted

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

max_value = 0
value = 0
for c in S:
    if c == 'I':
        value += 1
    elif c == 'D':
        value -= 1
    max_value = max(value, max_value)
print(max_value)

Submission status: Accepted

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

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:
a = [input() for i in range(2)]
result = int(0)
maxAns = int(0)
for c in a[1]:
    if c == 'I':
        result += 1
    elif c == 'D':
        result -= 1
    
    if result > maxAns:
        maxAns = result

print(maxAns)

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

Submission status: Accepted

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