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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(max_x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def ABC_52_B():
    N = int(input())
    S = input()
    xl=[]
    x=0

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

        xl.append(x)
    
    if max(xl)>=0:
        print(max(xl))
    else:
        print(0)

if __name__ == '__main__':

    ABC_52_B()

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
S = input().rstrip()

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

res = 0
x = 0
for i, v in enumerate(s):
    if v == 'I':
        x += 1
    else:
        x -= 1
    res = max(res, x)
print(res)

Submission status: Accepted

Solution code:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())

n = I()
s = S()

ans = 0
x = 0

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

print(ans)

Submission status: Accepted

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

print(m)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
x = 0
j = 0
for i in range(len(s)):
  j = j + (s[i]=='I') - (s[i]=='D')
  x = max(x,j)
print(x)

Submission status: Accepted

Solution code:
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:
def main():
    N = int(input())
    S = list(input())
    cnt = 0; ans = 0
    for s in S:
        cnt += (s == 'I') - (s == 'D')
        ans = max(cnt, ans)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans, x = 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:
#import numpy as np
N = int(input())
#x1,y1,x2,y2= map(int,input().split())
#A = list(map(int,input().split()))
#B = list(map(int,input().split()))
S= str(input())
x=0
max=0
for i in S:
    if i == 'I':
        x+=1
        if x>=max:
            max=x
    elif i== 'D':
        x-=1

print(max)

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    s = input()
    x = 0
    max_memo = 0
    for char in s:
        if char == 'I':
            x += 1
            max_memo = max(x, max_memo)
        else:
            x -= 1
    print(max_memo)


if __name__ == "__main__":
    main()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

a = [0]*N

x = 0

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = inputI()
S = inputS()

x = 0
MAX = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

print(max(Xs))

Submission status: Accepted

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

    ans = max(ans, num)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(mans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = input()
x = 0
maxx = 0
for c in S:
    x += [-1, 1][c == 'I']
    maxx = max(maxx, x)

print(maxx)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max(ans_lis))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
max = 0
x = 0
def check(x, max):
    if max < x:
        return x
    else:
        return max

for i in s:
    if i == "I":
        x += 1
        max = check(x, max)
    elif i == "D":
        x -= 1
        max = check(x, max)
print(max)

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 = 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())
A = list(input())
B = [0]*N
C = [0]*N
for i in range(N):
  if A[i] == "I":
    B[i] = 1
  else:
    B[i] = -1
C[0] = B[0]
for i in range(1, N):
  C[i] = C[i-1]+B[i]
if max(C) < 0:
    print(0)
else:
    print(max(C))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
tmp=0
max=0
for _ in range(N):
    if S.pop(0)=='I':
        tmp+=1
        if tmp>max:
            max=tmp
    else :
        tmp+=-1
print(max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n=int(input())
a=input()
ans=0
x=0
for i in a:
    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
num = 0

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

    ans = max(ans, num)

print(ans)

Submission status: Accepted

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

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

print(m)

Submission status: Accepted

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

for c in S:
    if c == 'I':
        x += 1
    elif c == 'D':
        x -= 1
    if x > max_x:
        max_x = x
print(max_x)

Submission status: Accepted

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

def Main(N, S):
    ans = 0
    mx = ans
    for c in S:
        if c == "I":
            ans += 1
        else:
            ans -= 1
        mx = max(mx, ans)
    return mx
        
res = Main(N, S)
print(res)

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def py():
    print("yes")
def pn():
    print("no")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0

n = iin()
s = input()
for i in s:
    if i == 'I':
        neko += 1
    elif i == 'D':
        neko -= 1
    if nuko < neko:
        nuko = neko
print(nuko)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(str, input().rstrip()))

ans = 0
current = 0

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

print(ans)

Submission status: Accepted

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

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

print(maxx)

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:
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

count = 0
ans = 0
for char in s:
    if char == "I":
        count += 1
    elif char == "D":
        count -= 1

    if ans < count:
        ans = count

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import bisect

def main():
    n = int(input())
    max_val = 0
    val = 0
    for c in input():
        if c == 'I':
            val += 1
        elif c == 'D':
            val -= 1
        max_val = max(max_val, val)
    print(max_val)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

print(max(memo))

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=list(str(input()))
ans=0
temp=ans
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:
N = int(input())
S = str(input())

x = 0
m = 0

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

print(m)

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
def resolve():
    N,=pin()
    S=input()
    temp=0
    ans=0
    for s in S:
        if s=="I":
            temp+=1
        else:
            temp-=1
        ans=max(ans,temp)
    print(ans)
        
#%%submit!    
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    s = str(input())
    count = 0
    ans = []
    for i in s:
        if i == 'I':
            count += 1
            ans.append(count)
        if i == 'D':
            count -= 1
            ans.append(count)

    print(max(max(ans), 0))


resolve()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
t = 0
hoge = 0
while t < n:
  if s[t] == 'I':
    hoge += 1
  else:
    hoge -= 1
  ans = max(ans,hoge)
  t += 1
print(ans)

Submission status: Accepted

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

sum =0
result =[0]

for i in range(len(S)):
    
    if S[i]=="I":
        sum +=1
    else:
        sum = sum -1
    
    result.append(sum)
    
result.sort()


print(result[len(result)-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

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

print(max(l))

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)
  if S[i] == "D":
    X.append(X[i]-1)

print(max(X))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
S = input()

ans = 0
x = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0
max = 0

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

print(max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#a,b,c,d=map(int,input().split())
n=int(input())
s=input()
ans=0
hantei=0
for i in s:
  if i=="I":
    ans+=1
  elif i=="D":
    ans-=1
  if ans>hantei:
    hantei=ans
  
print(hantei)