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 collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 0

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

Submission status: Accepted

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

x = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        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 -self.parents[self.find(x)]

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

    def members(self, x):
        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()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
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,s=open(0).readlines()
ans=0
now=0
for i in list(s):
    if i=="I":now+=2
    now-=1
    ans=max(ans,now)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

x = 0
ans = 0

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

Submission status: Accepted

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

for c in s:
    if c == 'I':
        now_num += 1
    else:
        now_num -= 1
    if now_num > max_num:
        max_num = now_num

print(int(max_num))

Submission status: Accepted

Solution code:
N = int(input())
S = str(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 = m = 0
for i in range(n): x += [-1,1][s[i] == "I"]; m = max(m,x)
print(m)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools

n = int(input())
s = list(input())
s1 = [1 if s[i] == 'I' else -1 for i in range(n)]
cumsum = list(itertools.accumulate(s1))
ans = max(cumsum)
print(max(ans, 0))

Submission status: Accepted

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

x=0
maxx=0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 052: B – Increment Decrement
n = int(input())
s = input()
x = 0
x_max = 0
for c in s:
    if c == 'I':
        x += 1
    else:
        x -= 1
    x_max = max(x_max, x)
print(x_max)

Submission status: Accepted

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

num = 0
max_num = num

for l in S:
    if l == 'I':
        num += 1
    else :
        num -= 1
    if num > max_num:
        max_num = num
        
print(max_num)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
x=0
ans = [0]
for i in s:
    if i == 'I':
        x+=1
        ans.append(x)
    elif i == 'D':
        x-=1
        ans.append(x)
a = max(ans)
print(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:
max,cost = 0,0
N = int(input())
S = input()

def update(max,cost):
    a = max
    if cost > a:
        a = cost
    return a

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

print(max)

Submission status: Accepted

Solution code:
n=int(input())

s=input()

ans = [0]*n

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import fractions
import copy
import bisect
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter


N=3
M=3
i=0
j=0
k=0
n=3
x=0
a=[0]*5
b=[]
ans=0
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
N=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"
s=input()
a=[i for i in s]
for i in range(len(s)):
     #print(ans,x)
     if a[i]=="I":
         ans=ans+1
         x=max(ans, x)
     if a[i]=="D":
         ans=ans-1

print(x)
#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ

'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation


#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''





########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

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

Submission status: Accepted

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

print(tmp)

Submission status: Accepted

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

x=0
maxx=0
for i in range(N):
    if S[i]=="I":
        x=x+1
        if maxx<x:
            maxx=x

    elif S[i]=="D":
        x=x-1
        
        

print(maxx)

Submission status: Accepted

Solution code:
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7
def main():
  n = int(input())
  s = input()
  ans = 0
  x = 0
  for i in range(n):
    if s[i] == 'I':
      x += 1
      ans = max(ans,x)
    elif s[i] == 'D':
      x -= 1
      ans = max(ans,x)
  print(ans)
if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
li=[]
ans=0
li.append(ans)

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

print(max(li))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max_x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# B - Increment Decrement
# 標準入力の取得
N = int(input())
S_list = list(input())

# 各要素におけるxを計算し、そのうちの最大値を出力する
x_list = [0 for i in range(N)]
for i in range(N):
    x_before = 0
    if i != 0:
        x_before = x_list[i-1]

    if S_list[i] == "I":
        x_list[i] = x_before + 1
    elif S_list[i] == "D":
        x_list[i] = x_before - 1

print(max(max(x_list), 0))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
result = 0

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
l = [0]
x = 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 = 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:
def main():
    n = int(input())
    s = list(input())

    ans = 0
    now = 0
    for i, i_d in enumerate(s):
        if i_d == 'I':
            now += 1
            ans = max(ans, now)
        else:
            now -= 1

    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

#print(*ans, sep='\n')

Submission status: Accepted

Solution code:

import math
import itertools
import statistics
#import collections
n = int(input())
s = input()

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

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

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

x = 0
x_max = 0
for s in S:
    if s == "I":
        x += 1
        if x_max < x:
            x_max = x
    else:
        x -= 1

print(x_max)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, S: str):
    x = 0
    anx = 0
    for i in range(N):
        if S[i] == 'I':
            x += 1
        else:
            x -= 1
        anx = max(anx, x)

    print(anx)

    
    return



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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
s = input().rstrip()
ans = 0
val = 0
for ch in s:
  if ch == "I":
    val += 1
    ans = max(ans, val)
  elif ch == "D":
    val -= 1
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
_ = int(input())

x = 0
ans = 0
for s in input():
    x += 1 if s == 'I' else -1
    ans = max(x, ans)
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
    else:
        cnt -= 1
    ans = max(ans, cnt)
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:
# -*- coding: utf-8 -*-
n = int(input())
s = input()

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

Submission status: Accepted

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

xs = [0]
x = 0
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:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = list(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:
import functools
n = int(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()

l = [0]*(n+1)
if s[0] == "I":
    l[0] = 1
else:
    l[0] = -1

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

print(max(l))

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

Submission status: Accepted

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

sum_ = 0
ans = 0
for n in range(N):
  if s[n]=="I":
    sum_ += 1
  else:
    sum_ -= 1
  if ans < sum_:
    ans = sum_
print(ans)

Submission status: Accepted

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

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

if x > 0:
    print(x)
else:
    print(0)

Submission status: Accepted

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

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

print(max(list))

Submission status: Accepted

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

print(max(count))

Submission status: Accepted

Solution code:
#ABC52.B
N = int(input())
S = input()
x = 0
cnt = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
input()
a=[0]
for i in input():a+=a[-1]+1-2*(i=='D'),
print(max(a))

Submission status: Accepted

Solution code:
input()
x=0
a=[0]
for i in input():a+=a[-1]+1-2*(i=='D'),
print(max(a))

Submission status: Accepted

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

Submission status: Accepted

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

ans=[0]*N
tmp=0

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
x = [0] * (n + 1)

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

print(max(x))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
list1 = []
for counter in range(n + 1):
    d = s.count("D", 0, counter)
    i = s.count("I", 0, counter)
    number = i - d
    list1.append(number)

if max(list1) <= 0:
    print(0)
else:
    print(max(list1))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
list1 = []
for counter in range (n+1):
  d = s.count("D",0,counter)
  i = s.count("I",0,counter)
  number = i-d
  list1.append(number)

if max(list1) <=0:
  print(0)
else:
  print(max(list1))

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


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


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n = int(input().strip())
    S = input().strip()
    x=0
    ans=0
    for i in range(n):
        if S[i]=='I':
            x+=1
            ans = max(x,ans)
        else:
            x-=1
    print(ans)


if __name__ == '__main__':
    main()

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