Skip to content

Instantly share code, notes, and snippets.

@monhime
Last active April 13, 2020 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monhime/5b34b2be5c16b1efb9c6ac0b9f8e70c8 to your computer and use it in GitHub Desktop.
Save monhime/5b34b2be5c16b1efb9c6ac0b9f8e70c8 to your computer and use it in GitHub Desktop.
ABC162 D問題 解答
import sys
from collections import Counter
def input(): return sys.stdin.readline().rstrip()
def main():
n=int(input())
s=input()
c_s=Counter(s)
sum_a=0
for diff in range(1,(n-1)//2+1):
for i in range(n-2*diff):
if s[i]!=s[i+diff] and s[i+diff]!=s[i+2*diff] and s[i]!=s[i+2*diff]:
sum_a+=1
print(c_s['R']*c_s['G']*c_s['B']-sum_a)
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment