fork download
  1. n = int(input())
  2. s = input()
  3. x = 0
  4. mx = 0
  5. for ch in s:
  6. if ch=='I':
  7. x += 1
  8. if x > mx:
  9. mx = x
  10. else:
  11. x -= 1
  12. print(mx)
Success #stdin #stdout 0.07s 7992KB
stdin
5
IIDID
stdout
2