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 .

Solution (Python):



def main(n, s):
    count = 0
    max_values = []
    for c in s:
        if c == 'I':
            count += 1
            max_values.append(count)
        else:
            count -= 1
    max_values = max_values if max_values else [0]
    return max(max_values) if 0 < max(max_values) else 0


if __name__ == '__main__':
    n = int(input())
    s = input()
    answer = main(n, s)
    print(answer)

Solution (Python):
if __name__ == "__main__":
    N = int(input())
    S = input()
    x = 0
    vs = []
    vs.append(x)
    for c in S:
        if c == 'I':
            x += 1
        else:
            x -= 1
        vs.append(x)
    print(max(vs))

Solution (Python):
n = int(input())
s = input()
ans = 0
max_ans = 0

for i in range(0,n):
  if(s[i]=='I'):
    ans+=1;
  else:
    ans-=1;
  if(ans > max_ans):
    max_ans = ans
print(max_ans);

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

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

print(ans)

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

Solution (Python):
from collections import defaultdict


def main():
    N = int(input())
    S = str(input())
    x = 0
    ans = 0
    for c in S:
        x += {"I": 1, "D": -1}[c]
        ans = max(ans, x)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = input()
a = list(input())


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

Solution (Python):



num=int(input())
words=input().rstrip()
x=0
xmax=0

for i in words:
    if i=="I":
        x+=1
    elif i=="D":
        x-=1
    
    if x>xmax:
        xmax=x

print(xmax)

Solution (Python):

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

x = 0
ans = 0

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

print(ans)

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

c = 0
maxi = 0
for i in s:
    if i == "I":c+=1
    else :c-=1
    maxi = max(maxi, c)
print (maxi)

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

Solution (Python):



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

x = 0
maxi = x
for i in list(s):
    if i is 'I':
        x += 1
    elif i is 'D':
        x -= 1
    if x >= maxi:
        maxi = x


print(maxi)

Solution (Python):
if __name__=="__main__":
    N = int(input())
    S = input()
    n = 0
    max = 0
    for s in S:
        if(s == "I"):
            n += 1
            if(max < n):
                max = n
        else:
            n -= 1
    print(max)

Solution (Python):
n = int(input())
s = input()
max_s = 0
x = 0
for i in range(len(s)):
    x = x + 1 if s[i] == "I" else x - 1
    max_s = x if x > max_s else max_s
print(max_s)

Solution (Python):
x = 0
xmax = 0
n = int(input())
s = input()

for ss in s:
    if ss == "I":
        x = x + 1
        if x > xmax:
            xmax = x
    elif ss == "D":
        x = x - 1

print(xmax)

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

Solution (Python):
input()
ans,x=0,0
for c in input():
    x+={'I':1,'D':-1}[c]
    ans=max(ans,x)
print(ans)

Solution (Python):
N = int(input())
S = input()
x = 0
max_x = 0
for c in S:
    if c == 'I': x += 1
    else: x -= 1
    max_x = max(max_x, x)
print(max_x)

Solution (Python):
N = int(input())
S = input()
c = 0
max_c = 0
for i in range(len(S)):
    if S[i] == 'I': c += 1
    else: c -= 1
    max_c = max(max_c, c)
print(max_c)

Solution (Python):


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

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

if __name__ == '__main__':
    main()

Solution (Python):
le = int(input())
a = [i for i in input()]
ans = 0
sum = 0
for i in range(le):
    if a[i] == "I":
        sum = sum + 1
    else:
        sum = sum - 1
    if ans < sum:
        ans = sum
print(ans)

Solution (Python):

N = int(input())
S = input()
x = 0
maximum = 0

for factor in range (0, len(S)):
    if S[factor] == 'I':
        x += 1
    elif S[factor] == 'D':
        x -= 1
    
    if maximum < x:
        maximum = x

print(maximum)

Solution (Python):
N = input()
S = raw_input()

num = 0
max_num = 0

for i in list(S):
    if i == 'I':
        num += 1
    elif i == 'D':
        num -= 1
    if max_num < num:
        max_num = num
        
print max_num

Solution (Python):
N=int(raw_input())
S=raw_input()
print max(map(lambda s : reduce(lambda x,y:x+(1 if y=="I" else -1),s,0),[S[:i]for i in range(1,len(S)+1)])+[0])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

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


def main():
    n = II()
    s = S()
    r = 0
    t = 0
    for c in s:
        if c == 'I':
            t += 1
            if r < t:
                r = t
        else:
            t -= 1
    return r


print(main())

Solution (Python):
N = int(raw_input())
S = raw_input()
x = 0
maxx = 0

for c in S:
    if c == 'I':
        x += 1
    if c == 'D':
        x -= 1
    if x > maxx:
        maxx = x

print maxx

Solution (Python):
N=map(int,input())
S=input()
ans = 0
x = 0
for c in S:
  x += {'I':+1, 'D':-1}[c]
  ans = max(ans, x)
print(ans)

Solution (Python):
x_max = 0
x = 0
input()
for c in list(input()):
    if c == "I":
        x += 1
        if x > x_max:
            x_max = x
    else:
        x -= 1
print(x_max)

Solution (Python):
x = 0;
N = int(input());

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

Solution (Python):
n = int(input())

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

print(ans)

Solution (Python):
N = int(input())
S = input()
ans = [0] * (N+1)

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

print(max(ans))

Solution (Python):

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

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

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

Solution (Python):
N = int(input())
S = input()
x = 0
xmax = 0
for i in S:
    if i == "I":
        x += 1
    else:
        x -= 1
    if x > xmax:
        xmax = x
print(xmax)

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

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


count = 0
MAX = 0
for i in S:
    if i == 'I':
        count += 1
    elif i == 'D':
        count -= 1
    if MAX < count:
        MAX = count

print(MAX)

Solution (Python):
N = int(input())
S = input()
x = 0
ans = 0
for l in S:
	if l == "I":
		x += 1
	elif l == "D":
		x -= 1
	ans = max(ans,x)
print(ans)

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

Solution (Python):
N = input()
S = raw_input()

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

Solution (Python):
N = int(raw_input())
S = raw_input()
x = 0
ans = 0
d = {"I": 1, "D": -1}
for c in S:
    x += d[c]
    ans = max(ans, x)
print ans

Solution (Python):


N=int(raw_input())
S=raw_input()
ans=0
tmp=0
for s in S:
	if s=="I":
		tmp+=1
	else :
		tmp-=1
	ans=max(ans,tmp)
print ans

Solution (Python):
n = 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)

Solution (Python):
n=int(raw_input())
s=raw_input()
ans=0;cnt=0
for i in xrange(n):
    if s[i]=="I":
        cnt+=1
        ans=max(ans,cnt)
    elif s[i]=="D":
        cnt-=1
        ans=max(ans,cnt)
print(ans)

Solution (Python):
input()
res = n = 0
for c in input():
    if c == 'I':
        n += 1
    else:
        n -= 1
    res = max(res, n)
print(res)

Solution (Python):
n = int(input())
s = input().rstrip()

x = 0
ans = 0
for c in s:
    x += (c == 'I')
    x -= (c == 'D')
    ans = max(ans,x)

print(ans)

Solution (Python):
n = int(input())
s = list(map(lambda x: 1 if x == "I" else -1, list(input())))
x = 0
m = 0
for i in s:
    x += i
    m = max(m,x)
print(m)

Solution (Python):
N = int(input())
S = input()
m = x = 0
for c in S:
    if c == 'I':
        x += 1
        m = max(m, x)
    else:
        x -= 1

print(m)

Solution (Python):


n=int(raw_input())
s=raw_input()
res_max=0
temp=0
for i in range(len(s)):
 if s[i]=='I':
  temp+=1
  res_max=max(res_max,temp)
 elif s[i]=='D':
  temp-=1
print res_max

Solution (Python):
input()
cnt = ans = 0
for c in raw_input():
    if c is "I":
        cnt += 1
    else:
        cnt -= 1
    ans = max(ans, cnt)
print ans

Solution (Python):
N = input()
S = input()
x = 0
max_x = 0
for s in S:
    if s == 'I':
        x += 1
        if x > max_x:
            max_x = x
    else:
        x -= 1
print(max_x)

Solution (Python):
n=int(input())
s=list(str(input()))
m=0
ans=0
for i in s:
    if i=='D':
        m -=1
    elif i=='I':
        m +=1
    ans=max(ans,m)
print(ans)

Solution (Python):
t=input()
x=0
m=0
s=raw_input()
for i in s:
	if i=='I':
		m+=1
	else:
		m-=1
	x=max(x,m)
print x

Solution (Python):
input()
s=input()
a=c=0
for i in s:
  if i=='I':a+=1
  else:a-=1
  c=max(a,c)
print(c)

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

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

    if ma < x:
        ma = x


print(ma)

Solution (Python):
input()
S = input()
x = 0
max_x = 0
for elem in S:
    if elem == "I":
        x += 1
    elif elem == "D":
        x -= 1
    if x > max_x:
        max_x = x
print(max_x)

Solution (Python):
n = int(input())
s = input()
x = 0
max_x = 0
for i in s:
    if i == 'I':
        x += 1
    elif i == 'D':
        x -= 1
    max_x = max(max_x, x)
print(max_x)

Solution (Python):
N = int(input())
S = input()
x = 0
l = [x]

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

Solution (Python):
N = raw_input()

S = raw_input()

x = 0
max_x = x

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

print max_x

Solution (Python):
n = int(raw_input())
s = str(raw_input())
x = 0
xs = [x]
for si in s:
    if si == 'I': x += 1
    else: x -= 1
    xs.append(x)
print max(xs)

Solution (Python):
n = int(raw_input())
s = raw_input()

cnt =0
x =[0]
for i in xrange(n):
    if s[i] == 'I':
        cnt += 1
        x.append(cnt)
    elif s[i]  == 'D':
        cnt -= 1
        x.append(cnt)

print max(x)

Solution (Python):

N = int(raw_input())
S = raw_input()
result = 0
list = [0]
for i in range(N):
    if S[i] == "I":
        result+=1
        list.append(result)
    else:
        result -=1
        list.append(result)
list.sort()
print(list[N])

Solution (Python):
import copy
N = input()
S = input()
Max = i = 0
for c in S:
    if (c == 'I'):
        i += 1
        if ( Max < i):
            Max = copy.deepcopy(i)
    else:
        i -= 1
print(str(Max))

Solution (Python):
n = map(int, raw_input().split())
s = raw_input()
x = 0
max = 0
i=0
while i<len(s):
    if s[i] == 'I':
        x = x + 1
        if max < x:
            max = x
    elif s[i] == 'D':
        x = x - 1

    i=i+1
print max

Solution (Python):
import sys

N = input()
S = input()
size = len(S)

if N != str(size):
 print("不正な入力です。")
 sys.exit()

max = 0
temp = 0

for i in range(size):
 if S[i] == "I":
  temp += 1
 elif S[i] == "D":
  temp -= 1
 else:
  print("I,D以外の文字が含まれています。")
  sys.exit()
 
 if max < temp:
  max = temp

print(max)

Solution (Python):
N = int(input())

s = list(input())

x = 0

ans = 0

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

print(ans)

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

print(m)

Solution (Python):
n = int(input())
s = input()
ans, x = 0, 0

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

Solution (Python):
n = int(input())
s = input()
ans, x = 0, 0

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

Solution (Python):
N = int(input())
S = input()
x, rec = 0, 0
for w in S:
    if w == "I":
        x += 1
        if x > rec:
            rec = x
    else:
        x -= 1

print(rec)

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

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

print(x_max)

Solution (Python):



_ = input()
st = input().strip()
total = 0
result = [0]

for i in st:
    if (i == 'I'):
        total += 1
        result.append(total)
    else:
        total -= 1
        result.append(total)
print (max(result))

Solution (Python):



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

x = 0
x1 = 0


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

print(int(x1))

Solution (Python):
n = int(input())
s = list(input())
x = 0
ans = 0
for ss in s:
    if ss == "I":
        x += 1
    else:
        x -= 1
    ans = max(ans, x)

print(ans)

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

res = [0] * (n + 1)

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


print(max(res))

Solution (Python):
import numpy as np

a=int(raw_input())

com = raw_input()


coma = list(com)

num =[]
s=0
num.append(0)
for i in coma:
    if i == "I":
        s=s+1
        num.append(s)
    else:
        s=s-1
        num.append(s)



print max(num)

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

x = 0
max_x = 0

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

print(max_x)

Solution (Python):
N=int(input())
S=input()
x=0
M=0

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

print(M)

Solution (Python):
def Main():
    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)

Main()

Solution (Python):
n = int(input())
s = list(input())
tmp = [0 for x in range(n+1)]
current=0
for idx, ss in enumerate(s):
    if ss=='I':
        tmp[idx+1]=tmp[current]+1
    else:
        tmp[idx+1]=tmp[current]-1
    current+=1
print(max(tmp))

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

def caluculate_x(n, s):
    x = 0
    x_list = [0]
    
    i = 0
    while (i < n):
        if (s[i] == 'I'):
            x += 1
        elif (s[i] == 'D'):
            x -= 1
        
        x_list.append(x)
        
        i += 1
        
    return x_list

answer = max(caluculate_x(n, s))
print(answer)

Solution (Python):
if __name__=="__main__":
    a= int(input())
    S= input().strip()
    x = 0
    m = 0
    for ch in S:
        if ch == "I":
            x += 1
        else:
            x -= 1
        m = max(m,x)
    print(m)

Solution (Python):
x = 0
n = int(input())
s = str(input())
s = list(s)
data = []
for i in range(n):
    if s[i] == 'I':
        x += 1
    elif s[i] == 'D':
        x = x-1
    data.append(x)
m = max(data)
if m > 0:
    print(m)
else:
    print(0)

Solution (Python):


n = input()
s = raw_input()
cnt = 0
max = 0

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

    if max < cnt:
        max = cnt

print max

Solution (Python):

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

x = 0
max_x = 0

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

print(max_x)

Solution (Python):
n=raw_input()
s=raw_input()
s=list(s)
max=0
now=0

for str in s:
    if str=="I":
        now+=1
        if now>max:
            max=now
    if str=="D":
        now-=1
print max

Solution (Python):
a = input()
x = 0
s = input()
max = 0

for i in s:
  if i == 'I':
    x+=1
    if x > max:
      max = x
  elif i == 'D':
    x-=1

print(max)

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

Solution (Python):
N = int(input())
S = input()
 
x = 0
M = 0
for s in list(S):
  if s == "I":
    x += 1
  elif s == "D":
    x -= 1
  M = max(M, x)
print(M)

Solution (Python):
import sys

n = int(input())
S = input()

x = 0
ans = 0

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

print(ans)

Solution (Python):
N = input()
S = raw_input()
ans,max_ = 0,0
for char in S:
    ans = ans + 1 if char is 'I' else ans - 1
    max_ = ans if max_ <= ans else max_
print max_

Solution (Python):
n = int(raw_input())
s = raw_input()
cur = 0
ans = 0
for i in s:
    if i == 'I':
        cur += 1
        ans = max(ans, cur)
    else:
        cur -= 1
        ans = max(ans, cur)
print ans

Solution (Python):
N = int(raw_input())
S = raw_input()
max = 0
x = 0
for s in S:
  if s == 'I':
    x+=1
  else:
    x-=1
  if x>max:
    max = x
print max

Solution (Python):
n = int(input())
s = list(input())
total,a = 0,[]
for c in s:
	if c == "I":
		total += 1
	else:
		total -= 1
	a.append(total)

print(max(a) if max(a) >= 0 else 0)

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

Solution (Python):
x = 0
m = 0
n = int(input())
s = list(input())
for i in s:
    if i == 'I':
        x += 1
    if i == 'D':
        x -= 1
    m = max(x,m)

print(m)

Solution (Python):


cnt = 0
hoge = [0]

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

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

print(max(hoge))

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

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

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

mx = 0
x = 0
for c in s:
    if c == 'I':
        x += 1
        if x > mx:
            mx = x
    else:
        x -= 1

print(mx)

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

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

print(ans)

Solution (Python):
raw_input()
x = 0
ans = 0
for ch in raw_input():
    if ch == 'I':
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print ans