fork download
  1. def count(word):
  2. L=0
  3. LC=0
  4. LCT=0
  5.  
  6. for x in word:
  7. if x=='L':
  8. L+=1
  9. elif x=='C':
  10. LC+=L
  11. elif x=='T':
  12. LCT+=LC
  13.  
  14. return LCT
  15.  
  16. def main(word):
  17.  
  18. cnt=count(word)
  19. ans=max(count('L'+word),count(word+'T'))
  20. n=len(word)
  21.  
  22. L=0
  23. T=0
  24. for x in word:
  25. if x=='T':
  26. T+=1
  27.  
  28. for i in range(n):
  29. ans=max(ans,cnt+L*T)
  30. if word[i]=='L':
  31. L+=1
  32. if word[i]=='T':
  33. T-=1
  34.  
  35. return ans
  36.  
  37. print(main('LCCT'))
Success #stdin #stdout 0.08s 7908KB
stdin
Standard input is empty
stdout
4