Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

rs = {}
gs = {}
bs = {}

for i, e in enumerate(s):
  if e == 'R':
    rs[i] = ''
  if e == 'G':
    gs[i] = ''
  if e == 'B':
    bs[i] = ''

a = max(bs.keys())
b = min(bs.keys())
      
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  for i in rs.keys():
    for j in gs.keys():
      mi = i if i < j else j
      ma = j if i < j else i
      p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
      for e in p:
        if e%1 != 0 or e < b or e > a:
          continue
        if e in bs:
          saidai -= 1
  print(int(saidai))


Fixed submission:
n = int(input())
s = input()

rs = {}
gs = {}
bs = {}

for i, e in enumerate(s):
  if e == 'R':
    rs[i] = ''
  if e == 'G':
    gs[i] = ''
  if e == 'B':
    bs[i] = ''
    
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  a = max(bs.keys())
  b = min(bs.keys())
  for i in rs.keys():
    for j in gs.keys():
      mi = i if i < j else j
      ma = j if i < j else i
      p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
      for e in p:
        if e%1 != 0 or e < b or e > a:
          continue
        if e in bs:
          saidai -= 1
  print(int(saidai))

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
s = input()

rs = {}
gs = {}
bs = {}

for i, e in enumerate(s):
  if e == 'R':
    rs[i] = ''
  if e == 'G':
    gs[i] = ''
  if e == 'B':
    bs[i] = ''
   
      
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  for i in rs.keys():
    for j in gs.keys():
      bs_tmp = copy.deepcopy(bs)
      mi = i if i < j else j
      ma = j if i < j else i
      p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
      for e in p:
        if e%1 != 0 or e < 0 or e > len(s):
          continue
        if e in bs_tmp:
          del bs_tmp[e]
          saidai -= 1
  print(int(saidai))

Fixed submission:
n = int(input())
s = input()

rs = {}
gs = {}
bs = {}

for i, e in enumerate(s):
  if e == 'R':
    rs[i] = ''
  if e == 'G':
    gs[i] = ''
  if e == 'B':
    bs[i] = ''
    
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  a = max(bs.keys())
  b = min(bs.keys())
  for i in rs.keys():
    for j in gs.keys():
      mi = i if i < j else j
      ma = j if i < j else i
      p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
      for e in p:
        if e%1 != 0 or e < b or e > a:
          continue
        if e in bs:
          saidai -= 1
  print(int(saidai))

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
s = input()

rs = {}
gs = {}
bs = {}

for i, e in enumerate(s):
  if e == 'R':
    rs[i] = ''
  if e == 'G':
    gs[i] = ''
  if e == 'B':
    bs[i] = ''
   
      
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  if len(rs) < len(bs):
    for i in rs.keys():
      for j in gs.keys():
        bs_tmp = copy.deepcopy(bs)
        mi = i if i < j else j
        ma = j if i < j else i
        p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
        for e in p:
          if e%1 != 0 or e < 0 or e > len(s):
            continue
          if e in bs_tmp:
            del bs_tmp[e]
            saidai -= 1
    print(int(saidai))
  else:
    for i in bs.keys():
      for j in gs.keys():
        rs_tmp = copy.deepcopy(rs)
        mi = i if i < j else j
        ma = j if i < j else i
        p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
        for e in p:
          if e%1 != 0 or e < 0 or e > len(s):
            continue
          if e in rs_tmp:
            del rs_tmp[e]
            saidai -= 1
    print(int(saidai))

Fixed submission:
n = int(input())
s = input()

rs = {}
gs = {}
bs = {}

for i, e in enumerate(s):
  if e == 'R':
    rs[i] = ''
  if e == 'G':
    gs[i] = ''
  if e == 'B':
    bs[i] = ''
    
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  a = max(bs.keys())
  b = min(bs.keys())
  for i in rs.keys():
    for j in gs.keys():
      mi = i if i < j else j
      ma = j if i < j else i
      p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
      for e in p:
        if e%1 != 0 or e < b or e > a:
          continue
        if e in bs:
          saidai -= 1
  print(int(saidai))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

rs = {}
gs = {}
bs = {}

for i, e in enumerate(s):
  if e == 'R':
    rs[i] = ''
  if e == 'G':
    gs[i] = ''
  if e == 'B':
    bs[i] = ''
   
      
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  for i in rs.keys():
    for j in gs.keys():
      mi = i if i < j else j
      ma = j if i < j else i
      p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
      for e in p:
        if e%1 != 0 or e < 0 or e > len(s):
          continue
        if e in bs:
          saidai -= 1
  print(int(saidai))

Fixed submission:
n = int(input())
s = input()

rs = {}
gs = {}
bs = {}

for i, e in enumerate(s):
  if e == 'R':
    rs[i] = ''
  if e == 'G':
    gs[i] = ''
  if e == 'B':
    bs[i] = ''
    
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  a = max(bs.keys())
  b = min(bs.keys())
  for i in rs.keys():
    for j in gs.keys():
      mi = i if i < j else j
      ma = j if i < j else i
      p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
      for e in p:
        if e%1 != 0 or e < b or e > a:
          continue
        if e in bs:
          saidai -= 1
  print(int(saidai))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

rs = []
gs = []
bs = []
for i, e in enumerate(s):
  if e == 'R':
    rs.append(i)
  if e == 'G':
    gs.append(i)
  if e == 'B':
    bs.append(i)
      
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  for i in rs:
    for j in gs:
      mi = i if i < j else j
      ma = j if i < j else i
      p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
      for e in p:
        if e in bs:
          saidai -= 1
  print(int(saidai))

Fixed submission:
n = int(input())
s = input()

rs = {}
gs = {}
bs = {}

for i, e in enumerate(s):
  if e == 'R':
    rs[i] = ''
  if e == 'G':
    gs[i] = ''
  if e == 'B':
    bs[i] = ''
    
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  a = max(bs.keys())
  b = min(bs.keys())
  for i in rs.keys():
    for j in gs.keys():
      mi = i if i < j else j
      ma = j if i < j else i
      p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
      for e in p:
        if e%1 != 0 or e < b or e > a:
          continue
        if e in bs:
          saidai -= 1
  print(int(saidai))