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:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


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

    c = 0
    ans = 0

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

    print(ans)


main()

Submission status: Accepted

Solution code:
count = int(input())
line = [i for i in input()]
x = 0
emp = []
result = 0
for j in range(count):
    if line[j] == "I":
      x += 1
    else:
      x -= 1
    emp.append(x)  
for j in range(len(emp)):
    if result < emp[j]:
        result = emp[j]
print(result)

Submission status: Accepted

Solution code:
a=int(input())
max=0
work=0
line=input()
for i in range(a):
    if line[i:i+1] == "I":
        work+=1
    else:
        if max < work:
            max = work
        work-=1
if max < work:
    max = work
print(str(max))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a = int(input())
b = list(input())

x = 0
y = [0]

for i in range(a):
  if b[i] == "D":
    x -= 1
    y.append(x)
  else:
    x += 1
    y.append(x)
    
print(max(y))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = input()
S = list(s)
x = 0
p = 0
while(S.__len__() > 0):
    if S.pop(0) == 'I':
        x += 1
        if x >= p:
            p = x
    else:
        x -= 1
print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x=[0]
input()
l=input()
for i in l:
  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()
m = 0
x = 0

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

print(m)

Submission status: Accepted

Solution code:
## ABC 052 B

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

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

Submission status: Accepted

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

x, ans = 0, 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]
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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
s=input()
x=0
r=0

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

Submission status: Accepted

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

print(max(alist))

Submission status: Accepted

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

for i in range(0, len(s)):
    if s[i:i+1] == 'I':
        x += 1
        if x>y:
            y = x
    if s[i:i+1] == 'D':
        x -= 1

print(y)

Submission status: Accepted

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

Submission status: Accepted

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

point = 0
cum_sum = [0]

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

Submission status: Accepted

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

res = 0
point = 0
for i in s:
    if i == "I":
        point += 1
    else:
        point -= 1
    if res < point:
        res = point
else:
    print(res)

Submission status: Accepted

Solution code:
a = int(input())
count = 0
l = list(input())
ar = [0]
for r in l:
    if r == "I":
        count += 1
    else:
        count -= 1
    ar.append(count)
print(max(ar))

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

Submission status: Accepted

Solution code:
#! /usr/bin/python3
""" Increment Decrement """

N = int(input())
S = input()
x = 0
test = False


def answer(ori_x, s):
    """ 文字列 s から i 回目の計算結果のリストを作り、その中の最大値を返す。"""
    temp_x = ori_x
    l = [ori_x]

    for I_or_D in s:
        if I_or_D == 'I':
            temp_x += 1
        elif I_or_D == 'D':
            temp_x -= 1
        else:
            print('error')
            break
        l.append(temp_x)

    if test:
        print('l =', l)

    return max(l)


def main():
    ''' 関数に値を適用 '''
    print(answer(x, S))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

current_num_max=0
current_num=0
text = list(S)
for c in text:
    if c == 'I':
        current_num+=1
    else:
        current_num-=1

    if current_num > current_num_max:
        current_num_max = current_num

print(current_num_max)

Submission status: Accepted

Solution code:
n = input()
s = input()
max = 0
counter = 0
for i in s:
    if i == 'I':
        counter += 1
    else:
        counter -= 1

    if max < counter:
        max = counter

print(max)

Submission status: Accepted

Solution code:
N = int(input())
S = list(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
else:
    print(max)

Submission status: Accepted

Solution code:
N = int(input())
S = list(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
else:
    print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
res = 0
maxer = 0

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

	if maxer < res:
		maxer = res
else:
	print(maxer)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    n = next_int()
    s = next_str()

    maximum_value = 0
    cnt = 0

    for i in range(n):
        cnt += calc(s[i])
        maximum_value = max(maximum_value, cnt)

    print(maximum_value)


def calc(c: chr) -> int:
    if c == 'I':
        return 1
    if c == 'D':
        return -1
    return 0


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(m)

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

print(ans)

Submission status: Accepted

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

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

print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

x = 0
t = [0]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x=0
maxX=0
index=0
while index < len(listS):
    if listS[index] == "I":
        x+=1
    else:
        x-=1
    if x > maxX:
        maxX =  x
    index+=1

print(maxX)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(xMax)

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 x > ans:
        ans = x


print(ans)

Submission status: Accepted

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

    if ans < x:
        ans = x
print(ans)

Submission status: Accepted

Solution code:
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())
S = input()
x = 0
add = [0]
for j in S:
    if j == 'I':
        x += 1
        add.append(x)
    elif j == 'D':
        x -= 1
        add.append(x)
print(max(add))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    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)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

final_ans = 0
temp_ans = 0
for s in input_s:

    if   s == 'I':
        temp_ans += 1
    elif s == 'D':
        temp_ans -= 1
    if final_ans < temp_ans:
        final_ans = temp_ans

print(final_ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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
    elif S[i]=='D':
        x-=1
    a.append(x)
print(max(a))

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

Submission status: Accepted

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

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
    else:
        x -= 1
    X.append(x)

print(max(X))

Submission status: Accepted

Solution code:
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n = ni()
s = lc()

res = 0
ans = 0
for c in s:
    if c == "I":
        res += 1
        
        if res > ans:
            ans = res
            
    elif c == "D":
        res -= 1
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
m = 0

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

print(m)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
c=0
mc=0
for i in range(n):
    if s[i] =="I":
        c+=1
        if c>mc:
            mc = c
    elif s[i]=="D":
        c-=1
print(mc)

Submission status: Accepted

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

Submission status: Accepted

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

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)

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = input()
count = 0
count_max = 0
for i in range(N):
    if A[i] == 'I':
        count += 1
    else:
        count -= 1
    count_max = max(count, count_max)
print(count_max)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
value, ans = 0, 0
for word in S:
    if word == 'I':
        value += 1
    else:
        value -= 1
    ans = max(ans, value)

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ruiseki = [0]

for i in range(len(S)):
    if S[i] == "I":
        ruiseki.append(ruiseki[i] + 1)
    elif S[i] == 'D':
        ruiseki.append(ruiseki[i] - 1)

print(max(ruiseki))

Submission status: Accepted

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

Submission status: Accepted

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

for i in s:
    if 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 = list(input())
x = 0
xmax = 0

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

    xmax = max(xmax, x)
    
print(xmax)

Submission status: Accepted

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

a = list(S)

max_count = 0
count = 0

for i in a:
    if i == "I":
        count += 1
        if max_count <= count:
            max_count = count
    else:
        count -= 1

print(max_count)

Submission status: Accepted

Solution code:
n,s=input(),input();print(max(s[:i].count("I")*2-i for i in range(int(n)+1)))

Submission status: Accepted

Solution code:
n,s=map(input,[""]*2);print(max(s[:i].count("I")*2-i for i in range(int(n)+1)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#52b
n = int(input())
s = 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:
#52b
n = int(input())
s = input()
ans = [0]

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

print(max(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:
#-*-coding:utf-8-*-

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# input

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

ans = 0
temp = 0

for i in range(N):
    if S[i] == 'I':
        temp += 1
        if temp >= ans:
            ans = temp
    else:
        temp -= 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate as ac
n=int(input())
s=[1 if i=="I" else -1 for i in input()]
print(max(ac([0]+s)))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
m =0
a =[]
for i in S:
    if i =='I':
        m=m+1
        a.append(m)
    else:
        m=m-1
        a.append(m)
if max(a)>=0:
    print(max(a))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
x_max = 0
for n_i in range(n):
    x += 1 if "I" == s[n_i] else -1
    if x_max < x:
        x_max = x
print(x_max)

Submission status: Accepted

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

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

Submission status: Accepted

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

x=0
ma=0

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

print(ma)

Submission status: Accepted

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

x = 0
x_max = x
for i in s:
    if i == 'I':
        x += 1
    else:
        x -= 1
    if x_max < x:
        x_max = x

print(x_max)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
max=0
cnt=0
d={'I':1,'D':-1}
for c in s:
    cnt += d[c]
    if max < cnt:
        max = cnt
print(max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

li = list(s)

x = 0
num_list = list()
num_list.append(0)
for argv in li:
	if argv == "I":
		x += 1
		num_list.append(x)
	elif argv == "D":
		x -= 1
		num_list.append(x)


print(max(num_list))

Submission status: Accepted

Solution code:
def main():
    x = Max = 0
    N = int(input())
    S = input()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

s = list(S)
x = 0
res = 0
for j in range(len(s)):
    if s[j] == 'I':
        x+=1
    elif s[j] == 'D':
            x-=1
    res = max(res, x)       
print (res)

Submission status: Accepted

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

	if x >= mx:
		mx = x

print(mx)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
s = np.array(list(input()))
s = (s == "I") * 2 - 1
print(max(0, s.cumsum().max()))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    N = input()
    N = int(N)

    S = input()

    x = 0
    lst =[0]

    for i in S:
        if i == "I":
            x +=1
        else:
            x -=1
        lst.append(x)

    print(max(lst))

if __name__ == "__main__":
        main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

cnt = 0
li = [0]
for i in range(N):
    if S[i] == "I":
        cnt += 1 
        li.append(cnt)
    else:
        cnt -= 1
        li.append(cnt)

print(max(li))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
S = input()
max_num = 0
current_num = 0
for i in S:
    if i == "I":
        current_num += 1
    else:
        current_num -= 1
    
    if max_num < current_num:
        max_num = current_num
    else:
        pass
    
print(max_num)

Submission status: Accepted

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

x = 0
maximum = 0

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

  maximum = x if x > maximum else maximum

print(maximum)

Submission status: Accepted

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

Submission status: Accepted

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

print(max(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(raw_input())
X = list(str(raw_input()))
pre_ans = 0
ans = 0
for item in X:
    if item == "I":
        pre_ans += 1
    else:
        pre_ans -= 1
    if ans < pre_ans:
        ans = pre_ans
print ans

Submission status: Accepted

Solution code:
N=int(raw_input())
S=raw_input()
x=xmax=0
for c in S:
  if c == 'I':
    x += 1
    xmax = max(xmax, x)
  else:
    x -= 1
print xmax

Submission status: Accepted

Solution code:
input()
x=0
li=[0]
for c in input():
    x+=(c=='I')-(c=='D')
    li+=[x]
print(max(li))