Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. n = int(input())
  2. stol = list(input())
  3. cnt = 0
  4. flag = True
  5. l = 0
  6. r = len(stol) - 1
  7. while l - r > 1:
  8. if flag:
  9. if stol[l] == 'm' and stol[r] == 'c':
  10. l += 1
  11. r -= 1
  12. elif stol[l] == 'm' or stol[r] == 'c':
  13. if stol[l] == 'm':
  14. l += 1
  15. else:
  16. r -= 1
  17. else:
  18. flag = False
  19. cnt +=1
  20. else:
  21. if stol[l] == 'c' and stol[r] == 'm':
  22. l += 1
  23. r -= 1
  24. elif stol[l] == 'c' or stol[r] == 'm':
  25. if stol[l] == 'c':
  26. l += 1
  27. else:
  28. r -= 1
  29. else:
  30. flag = True
  31. cnt += 1
  32. print(cnt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement