Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys

N = int(sys.stdin.readline().rstrip())
As = list(map(int, sys.stdin.readline().rstrip().split()))

ll = [0] * N
lr = [0] * N
for i in range(N):
    ll[i] = i + 1 + As[i]
    lr[i] = i + 1 - As[i]

ans = 0
for l in ll:
    ans += lr.count(l)

print(ans)

### FIXED CODE ###

import sys
from collections import Counter

N = int(sys.stdin.readline().rstrip())
As = list(map(int, sys.stdin.readline().rstrip().split()))

ll = [0] * N
lr = [0] * N
for i, a in enumerate(As):
    ll[i] = i + a
    lr[i] = i - a

cl = Counter(ll)
cr = Counter(lr)

ans = 0
for l in cl.keys():
    ans += cl[l] * cr[l]

print(ans)
### BUGGY CODE ###

import numpy as np
S = input()[::-1]
mod = 1000000007

n = len(S)
a = S[0]
x = np.zeros(26, int)
l = [[13 - i * j % 13 for j in range(0, 10)] for i in [1, 10, 9, 12, 3, 4]] * (n // 6 + 1)
if a == "?":
    x[0:10] += 1
else:
    x[int(a)] += 1
for s, l_ in zip(S[1:], l[1:]):
    x[13:] = x[:13]
    if s == "?":
        x[:13] = sum([x[v:v+13] for v in l_])
    else:
        v = l_[int(s)]
        x[:13] = x[v:v+13]
    x %= mod
print(x[5])

### FIXED CODE ###

#!python3

LI = lambda: list(map(int, input().split()))

# input
S = input()

MOD = 10 ** 9 + 7


def main():
    n = len(S)
    m = 5
    w = []
    p = 1
    for i in range(n):
        s = S[-1 - i]
        if s == "?":
            w.append(p)
        else:
            m = (m - int(s) * p) % 13
        p = p * 10 % 13

    n = len(w)
    l1 = [0] * 13
    l1[0] = 1
    for i in range(1, n + 1):
        l2 = [0] * 13
        for j in range(10):
            x = w[i - 1] * j % 13
            for k in range(13):
                t = (x + k) % 13
                l2[t] += l1[k]
        l1 = [y % MOD for y in l2]
    
    ans = l1[m]
    print(ans)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

def main():

    N, K = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [[0]*(K+1) for i in range(N+1)]
    import collections
    dp[0][K] = 1
    mod = 10**9 + 7
    # dp[i][j] i人目まで配って、残りがj個の方法の数
    s = [1]*(K+2)
    s[-1] = 0
    for i in range(1, N+1):
        tmp = 0
        next = [0]*(K+2)
        for j in range(K, -1, -1):
            tmp = s[j] - s[min(K, j+a[i-1]) + 1]
            tmp %= mod
            dp[i][j] = tmp
            next[j] = (next[j+1]+tmp) % mod
        s = list(next)

    print(dp[-1][0])


main()


### FIXED CODE ###

def main():

    N, K = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [[0]*(K+1) for i in range(N+1)]
    import collections
    dp[0][K] = 1
    mod = 10**9 + 7
    # dp[i][j] i人目まで配って、残りがj個の方法の数
    for i in range(1, N+1):
        tmp = 0
        q = collections.deque()
        for j in range(K, -1, -1):
            while(q):
                if q[0][0] > j:
                    t = q.popleft()
                    tmp -= t[1]
                else:
                    break
            if dp[i-1][j]:
                tmp += dp[i-1][j]
                q.append((max(j - a[i-1], 0), dp[i-1][j]))
            tmp %= mod
            dp[i][j] = tmp

    print(dp[-1][0])


main()
### BUGGY CODE ###

import sys
readline = sys.stdin.readline

X,Y,Z,K = map(int,readline().split())

A = sorted(list(map(int,readline().split())),reverse = True)
B = sorted(list(map(int,readline().split())),reverse = True)
C = sorted(list(map(int,readline().split())),reverse = True)

# AとBを組み合わせたケーキの上位K位を作る
AB = []
for a in range(len(A)):
  for b in range(len(B)):
    AB += [A[a] + B[b]]
    
AB = sorted(AB,reverse = True)[:K]

# ABとCを組み合わせたケーキの上位K位を作る
ans = []
for ab in range(len(AB)):
  for c in range(len(C)):
    ans += [AB[ab] + C[c]]
    
ans = sorted(ans,reverse = True)[:K]
for a in ans:
  print(a)

### FIXED CODE ###

X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
B=sorted(list(map(int,input().split())))[::-1]
C=sorted(list(map(int,input().split())))[::-1]
ans=[]
for a in range(len(A)):
  for b in range(len(B)):
    for c in range(len(C)):
      if (a+1)*(b+1)*(c+1)>K:
        break
      ans.append(A[a]+B[b]+C[c])

ans=sorted(ans)[::-1]
for i in range(min(K,len(ans))):
  print(ans[i])
### BUGGY CODE ###

S = list(input())
Q = int(input())
a = 0
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    if a == 0:
      a = 1
    else:
      a = 0
  else:
    if (q[1] == '1' and a == 0) or (q[1] == '2' and a == 1):
      S = [q[2]] + S
    else:
      S = S + [q[2]]
if a == 1:
  S = S[::-1]
S = ''.join(S)
print(S)

### FIXED CODE ###

S = list(input())
Q = int(input())
a = 0
A = []
B = []
for i in range(Q):
  q = list(input().split())
  q[0] = int(q[0])
  if q[0] == 1:
    if a == 0:
      a = 1
    else:
      a = 0
  else:
    q[1] = int(q[1])
    if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1):
      B.append(q[2])
    else:
      A.append(q[2])
B = B[::-1]
ans = B + S + A
if a == 1:
  ans = ans[::-1]
ans = ''.join(ans)
print(ans)
### BUGGY CODE ###

class ABC104:
    modulus = 10 ** 9 + 7

    def __init__(self, s):
        self.s = s
        self.n = len(s)

    def dp(self, i, j):
        """
        dynamic programming for abc 104
        :param i: index of the given string
        :param j: count of letters of composed string (like 'ABC')
        :return: the number of cases
        """
        if i == self.n:
            if j == 3:
                return 1
            else:
                return 0

        if i < self.n and j == 3:
            m = 3 if self.s[i] == '?' else 1
            return m * self.dp(i + 1, 3) % self.modulus

        if i < self.n and j < 3:
            m1 = 3 if self.s[i] == '?' else 1
            m2 = 1 if self.s[i] == '?' or self.s[i] == 'ABC'[j] else 0

            _pass = m1 * self.dp(i + 1, j) % self.modulus
            _take = m2 * self.dp(i + 1, j + 1) % self.modulus

            return _pass + _take


if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10**6)

    abc = ABC104(input())
    print(abc.dp(0, 0))


### FIXED CODE ###

if __name__ == "__main__":
    modulus = 10 ** 9 + 7
    s = input()
    n = len(s)
    dp = [[0] * 4 for _ in range(n + 1)]

    for i in range(n + 1)[::-1]:
        for j in range(4)[::-1]:
            if i == n:
                if j == 3:
                    dp[i][j] = 1
                else:
                    dp[i][j] = 0
            else:
                is_wildcard = s[i] == '?'
                if j == 3:
                    m = 3 if is_wildcard else 1
                    dp[i][j] = m * dp[i + 1][3] % modulus

                else:
                    m1 = 3 if is_wildcard else 1
                    m2 = 1 if is_wildcard or s[i] == 'ABC'[j] else 0

                    dp[i][j] = (m1 * dp[i + 1][j] + m2 * dp[i + 1][j + 1]) % modulus
            # print(i, j, dp[i][j])
    print(dp[0][0])
### BUGGY CODE ###

import bisect

n = int(input())

a, b = map(int, input().split())
task_lis = [[b, a]]
sum_a = 0
ch_over = 1


for i in range(n-1):
    a, b = map(int, input().split())
    if a > b:
        ch_over = 0
        break
    else:
        pass
    ok2 = bisect.insort_right(task_lis,[b, a])


for i in range(n):
    if ch_over == 0:
        break
    else:
        pass
    sum_a += task_lis[i][1]
    if task_lis[i][0] < sum_a:
        ch_over = 0
        break

if ch_over == 0:
    print("No")
else:
    print("Yes")


### FIXED CODE ###

n = int(input())
task_lis = sorted([[int(i) for i in input().split()] for _ in range(n)], key = lambda x:x[1])


sum_a = 0
ch_over = 1

for i in range(n):
    sum_a += task_lis[i][0]
    if task_lis[i][1] < sum_a:
        ch_over = 0
        break

if ch_over == 0:
    print("No")
else:
    print("Yes")
### BUGGY CODE ###

n=int(input())

a = list(map(int,input().split()))[:n]

r=1
for i in range(1,n):
    if a[i] <= min(a[:i]):r+=1

print(r)

### FIXED CODE ###

n=int(input())

a = list(map(int,input().split()))[:n]

r=1
min=a[0]

for i in range(1,n):
    if a[i] > min:continue
    else:
        r+=1
        min=a[i] 
    

print(r)
### BUGGY CODE ###

x1 = input()
x2 = list(map(int, input().split(" ")))
 
result =  1
for xv in x2:
  result = xv * result

if 10**18 < result : result = -1
print(result) 


### FIXED CODE ###

x1 = input()
x2 = [int(i) for i in input().split(" ")]

result = 0
if 0 in x2:
  None 
else:
  result = 1
  for xv in x2:
     result = xv * result
  
     if 10**18 < result : 
        result = -1
        break


print(result)
### BUGGY CODE ###

x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a.sort(reverse=1)
b.sort(reverse=1)
c.sort(reverse=1)
d=[]
for i in a:
  for j in b:
    d.append(i+j)
d.sort(reverse=1)
ans=[]
if x+y>k:
  for i in d[:k]:
    for j in c:
      ans.append(i+j)
else:
  for i in d:
    for j in c:
      ans.append(i+j)
ans.sort(reverse=1)
if x+y+z>k:
  for i in ans[:k]:
    print(i)
else:
  for i in ans:
    print(i)

### FIXED CODE ###

x,y,z,K=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort(reverse=1)
b.sort(reverse=1)
c.sort(reverse=1)
m=[]
for i in range(x):
  for j in range(y):
    for k in range(z):
      if (i+1)*(j+1)*(k+1)>K:
        break
      m.append(a[i]+b[j]+c[k])
m.sort(reverse=1)
for i in m[:K]:
  print(i)
### BUGGY CODE ###

l = raw_input().split()
s = l[0]

def get_removals(s):
    ret = []
    for i in range(len(s) - 1):
        if int(s[i]) + int(s[i + 1]) == 1:
            ret.append(i)
    return ret

def remove(s, index):
    if index == 0:
        return s[2:]
    if index == (len(s) - 1):
        return s[:index-1]
    return  s[0:index] + s[index + 2:]

num_removals = []

def process(s, count):
    removals = get_removals(s)
    if len(removals) == 0:
        num_removals.append(count)
        return
    count += 2
    max_removes = []
    ss = []
    for removal in removals:
        s1 = remove(s, removal)
        max_removes.append(len(get_removals(s1)))
        ss.append(s1)
    max_remove = max(max_removes)
    for s1 in set(ss):
        if len(get_removals(s1)) == max_remove:
            process(s1, count)

process(s, 0)
print(max(num_removals))


### FIXED CODE ###

l = raw_input().split()
s = l[0]

def get_removals(s):
    ret = []
    for i in range(len(s) - 1):
        if int(s[i]) + int(s[i + 1]) == 1:
            ret.append(i)
    return ret

def remove(s, index):
    if index == 0:
        return s[2:]
    if index == (len(s) - 1):
        return s[:index-1]
    return  s[0:index] + s[index + 2:]

num_removals = []

ones = 0
zeros = 0
for num in s:
    if num == '0':
        ones += 1
    if num == '1':
        zeros += 1
max_candidate = min(ones, zeros) * 2

def process(s, count):
    removals = get_removals(s)
    if len(removals) == 0:
        num_removals.append(count)
        if count == max_candidate:
            print(max_candidate)
            exit()
        return
    count += 2
    max_remove = 0
    ss = []
    for removal in removals:
        s1 = remove(s, removal)
        ss.append(s1)
        num_removes = len(get_removals(s1))
        if max_remove < num_removes:
            max_remove = num_removes
    for s1 in set(ss):
        if len(get_removals(s1)) == max_remove:
            process(s1, count)

# process(s, 0)
print(max_candidate)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[]
s.append(1)
a1=1
a2 = a[a1-1]

while a2 not in s:
    s.append(a2)
    a1 = a2
    a2 = a[a1-1]

loop_num=s.index(a2)
loop=s[loop_num:]
cnt=len(loop)

if k<len(s):
    print(s[k])
else:
    ans = (k-loop_num)%cnt
    print(loop[ans])

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[]
s.append(1)
a1=1
a2 = a[a1-1]
l=[0]*n
l[0]=1

while l[a2-1] != 1:
    s.append(a2)
    a1 = a2
    a2 = a[a1-1]
    l[a1-1] = 1

loop_num=s.index(a2)
loop=s[loop_num:]
cnt=len(loop)

if k<len(s):
    print(s[k])
else:
    ans = (k-loop_num)%cnt
    print(loop[ans])
### BUGGY CODE ###

n=int(input())
dic={}
for i in range(n):
    dic[i+1]=int(input())
ans=[1]
while True:
    if dic[ans[-1]]==2:
        print(len(ans))
        break
    if dic[ans[-1]] in ans:
        print(-1)
        break
    ans.append(dic[ans[-1]])

### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
now=0
c=0
while True:
    if now==1:
        print(c)
        break
    if c>=n:
        print(-1)
        break
    c+=1
    now=a[now]-1
### BUGGY CODE ###

class TrieTree:
    def __init__(self):
        self.flag = 0
        self.next = [None, None, None, None]

def judge(c):
    if c == "A":
        return 0
    elif c == "C":
        return 1
    elif c == "G":
        return 2
    else:
        return 3

def find(key, trie):

    if(len(key)>=1):
        index = judge(key[0])
        if(trie.next[index]==None):
            print("no")
        else:
            find(key[1:], trie.next[index])
    else:
        if(trie.flag):
            print("yes")
	else:
            print("no")

def insert(key, trie):
    if(len(key)>=1):
	index = judge(key[0])
	if(trie.next[index]==None):
            trie.next[index] = TrieTree()
            insert(key[1:], trie.next[index])
        else:
            insert(key[1:], trie.next[index])
    else:
        trie.flag = 1

if __name__ == "__main__":

    root = TrieTree()
    n = int(raw_input())
    for i in range(n):
        com = raw_input().split()
        if(com[0][0] == "i"):
            insert(com[1], root)
        else:
            find(com[1], root)

### FIXED CODE ###

n = input()
table =	set()

for i in range(n):
    com	= raw_input().split()
    if(com[0][0] == "i"):
	table.add(com[1])
    else:
	if com[1] in table:
            print("yes")
	else:
            print("no")
### BUGGY CODE ###

import collections
from functools import reduce
from operator import mul


def trial_division(n):
    l = []
    f = 2
    while n > 1:
        if n % f == 0:
            l.append(f)
            n /= f
        else:
            f += 1
    return l


def combinations_count(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    return reduce(mul, range(n, n - r, -1)) // reduce(mul, range(r, 0, -1))


N, M = map(int, input().split())

c = collections.Counter(trial_division(M))
a = 1
for i in c.values():
    a *= combinations_count(i + N - 1, i)

print(a % (10**9 + 7))


### FIXED CODE ###

import collections
from functools import reduce
from operator import mul


def trial_division(n):
    l = []
    f = 2
    while f * f <= n:
        if n % f == 0:
            l.append(f)
            n //= f
        else:
            f += 1
    if n > 1:
        l.append(n)
    return l


def combinations_count(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    return reduce(mul, range(n, n - r, -1)) // reduce(mul, range(r, 0, -1))


N, M = map(int, input().split())

c = collections.Counter(trial_division(M))
a = 1
for i in c.values():
    a *= combinations_count(i + N - 1, i)

print(a % (10**9 + 7))
### BUGGY CODE ###

class Node:
    def __init__(self, index):
        self.count = 0
        self.fr = -1
        self.index = index


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[to - 1].fr = fr - 1

for i in range(Q):
    fr, c = map(int, input().split())
    node[fr- 1].count += c

for i in range(N):
    x = node[i].count
    next = node[i].fr
    while next != -1:
        x += node[next].count
        next = node[next].fr
    if not i == N:
        print(x, end=' ')
    else:
        print(x)


### FIXED CODE ###

class Node:
    def __init__(self, index):
        self.count = 0
        self.fr = -1
        self.index = index


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[to - 1].fr = fr - 1

for i in range(Q):
    fr, c = map(int, input().split())
    node[fr - 1].count += c

print(node[0].count, end=' ')

for i in range(1, N):
    node[i].count += node[node[i].fr].count
    if not i == N:
        print(node[i].count, end=' ')
    else:
        print(node[i].count)
### BUGGY CODE ###

N = int(input())
S = list(input())
ans = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i] != S[j]:
            for k in range(j+1,N):
                if S[j] != S[k] and S[i] != S[k] and j-i != k-j:
                    ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
S = list(input())
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R*G*B
for i in range(N):
    for k in range(i+1,N):
        if (k+i)%2 == 1:
            continue
        else:
            j = (k+i)//2
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                ans -= 1
print(ans)
### BUGGY CODE ###

s = input()
n = len(s)
dp = [[0] * 13 for _ in range(n)]
mod = 10**9 + 7

if s[n-1] == '?':
    for i in range(10):
        dp[0][i] = 1
else:
    dp[0][int(s[n-1])] = 1

for i in range(1,n):
    a = len(s) - i
    if s[a-1] == '?':
        for j in range(13):
            for k in range(10):
                b = (k * 10 ** i + j) % 13
                dp[i][b] += dp[i-1][j]
    else:
        k = int(s[a-1])
        for j in range(13):
            b = (k * 10 ** i + j) % 13
            dp[i][b] += dp[i-1][j]
    for j in range(13):
        dp[i][j] %= mod

print(dp[n-1][5]%mod)


### FIXED CODE ###

s = input()
n = len(s)
dp = [[0] * 13 for _ in range(n)]
mod = 10**9 + 7

if s[0] == '?':
    for i in range(10):
        dp[0][i] = 1
else:
    dp[0][int(s[0])] = 1

for i in range(1,n):
    if s[i] == '?':
        for j in range(13):
            for k in range(10):
                dp[i][(j * 10 + k) % 13] += dp[i-1][j]
    else:
        k = int(s[i])
        for j in range(13):
            dp[i][(j * 10 + k) % 13] += dp[i-1][j]
    for j in range(13):
        dp[i][j] %= mod

print(dp[n-1][5]%mod)
### BUGGY CODE ###


def main():
    n = int(input())
    s = bytearray(input().encode())
    q = int(input())
    for _ in range(q):
        t, a, b = [p for p in input().split()]
        t = int(t)
        a = int(a)
        if t == 1:
            s[a-1] = b.encode()[0]
        else:
            b = int(b)
            c = set(s[a-1:b])
            print(len(c))

main()



### FIXED CODE ###

import bisect

def main():
    n = int(input())
    s = bytearray(input().encode())
    q = int(input())

    alpha = [ord('a')+i for i in range(26)]
    alpha_map = {c: [] for c in alpha}
    for i, c in enumerate(s):
        bisect.insort(alpha_map[c], i+1)

    for _ in range(q):
        t, a, b = [p for p in input().split()]
        t = int(t)
        a = int(a)
        if t == 1:
            char = s[a-1]
            b = ord(b)
            if char == b:
                continue
            src_lst = alpha_map[char]
            dst_lst = alpha_map[b]
            idx = bisect.bisect_left(src_lst, a)
            if idx < len(src_lst):
                src_lst.pop(idx)
            bisect.insort(dst_lst, a)
            s[a-1] = b
        else:
            b = int(b)
            cnt = 0
            for _, lst in alpha_map.items():
                idx = bisect.bisect_left(lst, a)
                if idx < len(lst) and lst[idx] <= b:
                    cnt +=1
            print(cnt)
main()
### BUGGY CODE ###

def Luca(n):
  if n == 0:
    return 2
  elif n == 1:
    return 1
  else:
    return Luca(n-1)+Luca(n-2)
N = int(input())
print(Luca(N))

### FIXED CODE ###

N = int(input())

Luca = [2, 1]
for i in range(N-1):
  Luca[1], Luca[0] = Luca[0]+Luca[1], Luca[1]

print(Luca[1])
### BUGGY CODE ###

s = input()
z = int(input())
list = [chr(i) for i in range(97,97+26)]
d = []
flag = 0
for j in list:
  indexes = [i for i,x in enumerate(s) if x==j]
  if len(indexes)==0:
    continue
  for k in indexes:
    for l in range(len(s)-k):
      d.append(s[k:l+k+1])
  if len(set(d))==z:
    break
print(sorted(set(d))[z-1])

### FIXED CODE ###

s = input()
z = int(input())
list = [chr(i) for i in range(97,97+26)]
d = []
for j in list:
  indexes = [i for i,x in enumerate(s) if x==j]
  if len(indexes)==0:
    continue
  for k in indexes:
    for l in range(len(s)-k):
      d.append(s[k:l+k+1])
      if len(s[k:l+k+1])==z:
        break
print(sorted(set(d))[z-1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Tue Dec 19 10:03:26 2017

@author: kotania
"""
N = int(input())
AList = [0]*N

for n in range(0,N):
    AList[n] = int(input())
  
PList = []

for a in AList:
    if a not in PList:
        PList.append(a)
    else:
        PList.remove(a)

print(len(PList))

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Tue Dec 19 10:03:26 2017

@author: kotania
"""
from collections import Counter

N = int(input())
 
AList = []
 
count = 0
        
for n in range(0,N):
    AList.append(input())
    
countDict = Counter(AList)
countDictValues = countDict.values()

count = 0

for c in countDictValues:
    if c % 2 == 1 :
        count += 1

print(count)
### BUGGY CODE ###

num = int(input())
p = map(int, input().split())
pList = list(p)

ret = "YES"
for i in range(num):
    for j in range(i+1, num):
        if pList[i] == pList[j]:
            ret = "NO"
            break

print("{}".format(ret))

### FIXED CODE ###

# C - Distinct or Not
# https://atcoder.jp/contests/abc154/tasks/abc154_c

num = int(input())
p = list(map(int, input().split()))
list.sort(p)

ret = "YES"
for i in range(num-1):
    if p[i] == p[i+1]:
        ret = "NO"
        break

print("{}".format(ret))
### BUGGY CODE ###

def factorial(n):
  ans = 1
  for i in range(n):
    ans *= i+1
    ans %= mod
  return ans


mod = 998244353
n = int(input())
s = input()
ans = 1
r,g,b = 0,0,0
rg,rb,gb = 0,0,0
for i in s:
  if i == "R":
    if gb > 0:
      ans *= gb
      gb -= 1
    elif g > 0:
      ans *= g
      g -= 1
      rg += 1
    elif b > 0:
      ans *= b
      b -= 1
      rb += 1
    else:
      r += 1
  elif i == "G":
    if rb > 0:
      ans *= rb
      rb -= 1
    elif r > 0:
      ans *= r
      r -= 1
      rg += 1
    elif b > 0:
      ans *= b
      b -= 1
      gb += 1
    else:
      g += 1
  elif i == "B":
    if rg > 0:
      ans *= rg
      rg -= 1
    elif r > 0:
      ans *= r
      r -= 1
      rb += 1
    elif g > 0:
      ans *= g
      g -= 1
      gb += 1
    else:
      b += 1
    ans %= mod 
print((factorial(n) * ans) % mod)

### FIXED CODE ###

def factorial(n):
  ans = 1
  for i in range(n):
    ans *= i+1
    ans %= mod
  return ans


mod = 998244353
n = int(input())
s = input()
ans = 1
r,g,b = 0,0,0
rg,rb,gb = 0,0,0
for i in s:
  if i == "R":
    if gb > 0:
      ans *= gb
      gb -= 1
    elif g > 0:
      ans *= g
      g -= 1
      rg += 1
    elif b > 0:
      ans *= b
      b -= 1
      rb += 1
    else:
      r += 1
  elif i == "G":
    if rb > 0:
      ans *= rb
      rb -= 1
    elif r > 0:
      ans *= r
      r -= 1
      rg += 1
    elif b > 0:
      ans *= b
      b -= 1
      gb += 1
    else:
      g += 1
  elif i == "B":
    if rg > 0:
      ans *= rg
      rg -= 1
    elif r > 0:
      ans *= r
      r -= 1
      rb += 1
    elif g > 0:
      ans *= g
      g -= 1
      gb += 1
    else:
      b += 1
  ans %= mod
print((factorial(n) * ans) % mod)