Buggy python submission (verdict: Runtime Error):
import collections
def f(s):
  h = {('R','G'): 'B', ('B','G'): 'R', ('R','B'): 'G',('R','G')[::-1]: 'B', ('B','G')[::-1]: 'R', ('R','B')[::-1]: 'G', }

  c = collections.Counter()
  cc = [None] * (len(s)+1)
  cc[-1] = c
  for jj in range(len(s)-1,-1,-1):
    c[s[jj]]+=1
    cc[jj] = c
    res = 0
    for i in range(len(s)):
      for j in range(i+1, len(s)):
        if s[j] != s[i]:
          res += cc[j+1][h[(s[i],s[j])]]

  return res
raw_input()
print f(raw_input())


Fixed submission:
import copy
import collections
def f(s):
    h = {('R','G'): 'B', ('B','G'): 'R', ('R','B'): 'G',('R','G')[::-1]: 'B', ('B','G')[::-1]: 'R', ('R','B')[::-1]: 'G', }
    c = collections.Counter()
    cc = [None] * (len(s)+1)
    cc[-1] = copy.deepcopy(c)
    for jj in range(len(s)-1,-1,-1):
        c[s[jj]]+=1
        cc[jj] = copy.deepcopy(c)


    res = 0
    for i in range(len(s)):
        for j in range(i + 1, len(s)):
            if s[j] != s[i]:
                res += cc[j+1][h[(s[i],s[j])]] 
                
                k = j + (j - i)
                if k < len(s) and s[k] == h[(s[i],s[j])]:
                    res -=1
    return res
raw_input()
print f(raw_input())

Buggy python submission (verdict: Runtime Error):
import collections
def f(s):
  h = {('R','G'): 'B', ('B','G'): 'R', ('R','B'): 'G', }
  for k in h:
    h[k[::-1]] = h[k]
  c = collections.Counter()
  cc = [None] * (len(s)+1)
  cc[-1] = c
  for jj in range(len(s)-1,-1,-1):
    c[s[jj]]+=1
    cc[jj] = c
    res = 0
    for i in range(len(s)):
      for j in range(i+1, len(s)):
        if s[j] != s[i]:
          res += cc[j+1][h[(s[i],s[j])]]

  return res
raw_input()
print f(raw_input())


Fixed submission:
import copy
import collections
def f(s):
    h = {('R','G'): 'B', ('B','G'): 'R', ('R','B'): 'G',('R','G')[::-1]: 'B', ('B','G')[::-1]: 'R', ('R','B')[::-1]: 'G', }
    c = collections.Counter()
    cc = [None] * (len(s)+1)
    cc[-1] = copy.deepcopy(c)
    for jj in range(len(s)-1,-1,-1):
        c[s[jj]]+=1
        cc[jj] = copy.deepcopy(c)


    res = 0
    for i in range(len(s)):
        for j in range(i + 1, len(s)):
            if s[j] != s[i]:
                res += cc[j+1][h[(s[i],s[j])]] 
                
                k = j + (j - i)
                if k < len(s) and s[k] == h[(s[i],s[j])]:
                    res -=1
    return res
raw_input()
print f(raw_input())

Buggy python submission (verdict: Runtime Error):
import collections
def f(s):
  h = {('R','G'): 'B', ('B','G'): 'R', ('R','B'): 'G', }
  for k in h:
    h[k[::-1]] = h[k]
  c = collections.Counter()
  cc = [None] * (len(s)+1)
  cc[-1] = c
  for jj in range(len(s)-1,-1,-1):
    c[s[jj]]+=1
    cc[jj] = c
    res = 0
    for i in range(len(s)):
      for j in range(i+1, len(s)):
        if s[j] != s[i]:
          res += cc[j+1][h[(s[i],s[j])]]

  return res
raw_input()
print f(raw_input())


Fixed submission:
import copy
import collections
def f(s):
    h = {('R','G'): 'B', ('B','G'): 'R', ('R','B'): 'G',('R','G')[::-1]: 'B', ('B','G')[::-1]: 'R', ('R','B')[::-1]: 'G', }
    c = collections.Counter()
    cc = [None] * (len(s)+1)
    cc[-1] = copy.deepcopy(c)
    for jj in range(len(s)-1,-1,-1):
        c[s[jj]]+=1
        cc[jj] = copy.deepcopy(c)


    res = 0
    for i in range(len(s)):
        for j in range(i + 1, len(s)):
            if s[j] != s[i]:
                res += cc[j+1][h[(s[i],s[j])]] 
                
                k = j + (j - i)
                if k < len(s) and s[k] == h[(s[i],s[j])]:
                    res -=1
    return res
raw_input()
print f(raw_input())

Buggy python submission (verdict: Runtime Error):
import collections
def f(s):
  	h = {('R','G'): 'B', ('B','G'): 'R', ('R','B'): 'G', }
    for k in h:
      	h[k[::-1]] = h[k]
    c = collections.Counter()
    cc = [None] * (len(s)+1)
    cc[-1] = c
    for jj in range(len(s)-1,-1,-1):
      	c[s[jj]]+=1
        cc[jj] = c
	res = 0
    for i in range(len(s)):
		for j in range(i+1, len(s)):
          	if s[j] != s[i]:
              	res += cc[j+1][h[(s[i],s[j])]]
                
	return res
raw_input()
print f(raw_input())

Fixed submission:
import copy
import collections
def f(s):
    h = {('R','G'): 'B', ('B','G'): 'R', ('R','B'): 'G',('R','G')[::-1]: 'B', ('B','G')[::-1]: 'R', ('R','B')[::-1]: 'G', }
    c = collections.Counter()
    cc = [None] * (len(s)+1)
    cc[-1] = copy.deepcopy(c)
    for jj in range(len(s)-1,-1,-1):
        c[s[jj]]+=1
        cc[jj] = copy.deepcopy(c)


    res = 0
    for i in range(len(s)):
        for j in range(i + 1, len(s)):
            if s[j] != s[i]:
                res += cc[j+1][h[(s[i],s[j])]] 
                
                k = j + (j - i)
                if k < len(s) and s[k] == h[(s[i],s[j])]:
                    res -=1
    return res
raw_input()
print f(raw_input())