Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03545 (python)

Fixed submission:
a = list(input())
 
sign = "+-"
 
for i in range(2):  #1つめの正負
 for j in range(2):  #2つ目の正負
  for k in range(2):  #3つ目の正負
    if eval(a[0]+sign[i]+a[1]+sign[j]+a[2]+sign[k]+a[3] ) == 7:
     print(str(a[0]+sign[i]+a[1]+sign[j]+a[2]+sign[k]+a[3])+'=7')
     exit()

Buggy submission (verdict: Runtime Error):
n = int(input())
op_cnt = len(n)-1　#隙間の数
for i in range(2 ** op_cnt):
  op = ["-"]*op_cnt ##あらかじめ[---]を入れておく
  for j in range(op_cnt):
    if ((i>>j)&1):
      op[op_cnt-1-j] = "+" #フラブが立っている箇所を"+"へ
      
  formula = "" 
  for p_n,p_o in zip(n,op+[""]):
    formula += (p_n+p_o)
  if eval(formula) == 7:
    print(formula+ "=7")
    break

Buggy submission (verdict: Runtime Error):
n = int(input())
op_cnu = len(n)-1　#隙間の数
for i in range(2 ** op_cnt):
  op = ["-"]*op_cnt ##あらかじめ[---]を入れておく
  for j in range(op_cnt):
    if ((i>>j)&1):
      op[op_cnt-1-j] = "+" #フラブが立っている箇所を"+"へ
      
  formula = "" 
  for p_n,p_o in zip(n,op+[""]):
    formula += (p_n+p_o)
  if eval(formula) == 7:
    print(formula+ "=7")
    break
Problem p03555 (python)

Fixed submission:
c1 = list(input())
c2 = list(input())

if c1[0] == c2[2] and c1[1]==c2[1] and c1[2] == c2[0]:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
c1 = list(map(int,input().split()))
c2 = list(map(int,input().split()))

if c1[0] == c2[2] and c1[1]==c2[1] and c1[2] == c2[0]:
  print("YES")
else:
  print("NO")
Problem p03583 (python)

Fixed submission:
N = int(input())
for h in range(1, 3501):
    for n in range(h, 3501):
        if (4*h*n-N*n-N*h)>0 and (N*h*n)%(4*h*n-N*n-N*h)==0:
            print(h, n, (N*h*n)//(4*h*n-N*n-N*h))
            exit()

Buggy submission (verdict: Runtime Error):
N = int(input())

for h in range(1,3501):
  for n in range(1,3501):
    if (4*h*n-N*n-N*h)!= 0:
        w = N*h*n/(4*h*n-N*n-N*h)
    if w >0 and w.is_integer():
      print(h,n,int(w))
      exit()
Problem p03680 (python)

Fixed submission:
import sys
n = int(input())
a = [int(input()) for _ in range(n)]
lamp = 1
ans=0
for i in range(n):
    if lamp - 1 == 1:
        print(i)
        sys.exit()
    lamp = a[lamp - 1]
print(-1)

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
a = []
ans = 0
lamp = 1
for _ in range(n):
  A = int(input())
  a.append(a)
  
for i in range(n):
  if lamp -1 == 1:
    print(i)
    sys.exit()
  lamp = a[lamp - 1]
print(-1)
Problem p03693 (python)

Fixed submission:
r,g,b=map(int, input().split())

A = 10*g + b

if A % 4 == 0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
r = int(input())
g = int(input())
b = int(input())

total = 100*r + 10*g + b

if total % 4 == 0:
    print("YES")
else:
    print("NO")
Problem p03733 (python)

Fixed submission:
N, T =map(int, input().split())
t = list(map(int, input().split()))
ans = T
for i in range(1, N):
    if t[i] - t[i-1] >= T:
        ans += T
    else:
        ans += t[i] - t[i-1]
print(ans)

Buggy submission (verdict: Runtime Error):
n,T = map(int,input().split())
t = list(map(int,input().split())
A = [0]*n

for i in range(n):
    if t[i]>T:
        A[i+1] = A[i] + T
    else:
        A[i+1] = A[i]+ t[i]
print(A[n])
Problem p03738 (python)

Fixed submission:
a = int(input())
b = int(input())
if a>b:
  print("GREATER")
  
elif a == b:
  print("EQUAL")
  
else:
  print("LESS")

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())

if a>b:
  print("GREATER")

elif a == b:
  print("EQUAL")

else:
  print("LESS")

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
 
if a>b:
  print("GREATER")
  
elif a == b:
  print("EQUAL")
  
else:
  print("LESS")

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())

if a>b:
  print("GREATER")
  
elif a = b:
  print("EQUAL")
  
else:
  print("LESS")
Problem p03827 (python)

Fixed submission:
n = int(input())
s = input()
x = ans = 0

 
for i in range(n):
  if s[i] == "I":
    x += 1
  else:
    x -= 1
  ans = max(ans,x)
    
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
ans = 0
x =0

for i in range(n):
  if s(i) == "I":
    x += 1
  else:
    x -= 1
    ans = max(ans,x)
    

print(ans)
Problem p03852 (python)

Fixed submission:
a = input()
vowel = set("aiueo")
if a in vowel:
  print("vowel")
else:
  print("consonant")

Buggy submission (verdict: Runtime Error):
a = input()
vowel = set("a","b","c","d","e")
if a in vowel:
  print("vowel")
else:
  print("consonant")
Problem p04030 (python)

Fixed submission:
s = list(input())
answer = []

for i in s:
        if  i == "B":
            try:
                answer.pop()
            except IndexError:
                pass
        else:
            answer.append(i)

print("".join(answer))

Buggy submission (verdict: Runtime Error):
s = list(input())
answer = []

for i range s:
        if  i == "B":
            try:
                answer.pop()
            except IndexError:
                pass
        else:
            answer.append(i)

print(" ".join(answer))

Buggy submission (verdict: Runtime Error):
s = list(input())
answer = []

for i range s:
        if  i == "B":
            try:
                answer.pop()
            except:
                pass
        else:
            answer.append(i)

print(" ".join(answer))

Buggy submission (verdict: Runtime Error):
s = list(input())
answer = []

for i range s:
        if  i == "B":
            try:
                answer.pop()
            except:
                pass
        else:
            answer.append(i)

print("".join(answer))

Buggy submission (verdict: Runtime Error):
s = list(input())
answer = []

for i range s:
        if  i == "B":
            try:
                answer.pop()
            except:
                pass
        else:
            answer.append(i)

print(answer)
Problem p02556 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

def dist(A, B):
	return abs(A[0]-B[0]) + abs(A[1]-B[1])

N = INT()
xy = [LIST()+[i] for i in range(N)]

xy1 = [[xy[i][0]+xy[i][1], i] for i in range(N)]
xy1.sort(key=lambda x:x[0])
idx_a = xy1[0][1]
idx_b = xy1[-1][1]
a = xy[idx_a]
b = xy[idx_b]

xy2 = [[-xy[i][0]+xy[i][1], i] for i in range(N)]
xy2.sort(key=lambda x:x[0])
idx_c = xy2[0][1]
idx_d = xy2[-1][1]
c = xy[idx_c]
d = xy[idx_d]

print(max(dist(a, b), dist(a, c), dist(a, d), dist(b, c), dist(b, d), dist(c, d)))

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

def dist(A, B):
	return abs(A[0]-B[0]) + abs(A[1]-B[1])

N = INT()
xy = [LIST()+[i] for i in range(N)]

xy1 = [[xy[i][0]+xy[i][1], i] for i in range(N)]
xy1.sort(key=lambda x:x[0])
idx_a = xy1[0][1]
idx_b = xy1[-1][1]
a = xy[idx_a]
b = xy[idx_b]

xy2 = [[-xy[i][0]+xy[i][1], i] for i in range(N)]
xy2.sort(key=lambda x:x[0])
idx_c = xy2[0][1]
idx_d = xy[-1][1]
c = xy[idx_c]
d = xy[idx_d]

print(max(dist(a, b), dist(a, c), dist(a, d), dist(b, c), dist(b, d), dist(c, d)))
Problem p02713 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
K = INT()
sum = 0
 
for n in range(K):
  for m in range(K):
    for l in range(K):
      sum += gcd(n+1, gcd(m+1, l+1))
 
print(sum)

Buggy submission (verdict: Runtime Error):
from math import  gcd

K = INT()
sum = 0
 
for n in range(K):
  for m in range(K):
    for l in range(K):
      sum += gcd(n+1, gcd(m+1, l+1))
 
print(sum)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np
 
K = INT()
sum = 0
 
for n in range(K):
  for m in range(K):
    for l in range(K):
      sum += gcd(n+1, gcd(m+1, l+1))
 
print(sum)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np
 
K = INT()
sum = 0
 
for n in range(K):
  for m in range(K):
    for l in range(K):
      sum += gcd(n+1, gcd(m+1, l+1))
 
print(sum)
Problem p02727 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
	
X, Y, A, B, C = MAP()
p = deque(sorted(LIST(), reverse=True) + [0])
q = deque(sorted(LIST(), reverse=True) + [0])
r = deque(sorted(LIST(), reverse=True) + [0])

x = 0
y = 0
z = 0
ans = 0
while x+y+z < X+Y:
	compare = (p[0], q[0], r[0])

	if p[0] == max(compare):
		x += 1
		ans += p.popleft()
		if x == X:
			p = [0]
	elif q[0] == max(compare):
		y += 1
		ans += q.popleft()
		if y == Y:
			q = [0]
	else:
		z += 1
		ans += r.popleft()

print(ans)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
	
X, Y, A, B, C = MAP()
p = deque(sorted(LIST(), reverse=True))
q = deque(sorted(LIST(), reverse=True))
r = deque(sorted(LIST(), reverse=True))

x = 0
y = 0
z = 0
ans = 0
while x+y+z < X+Y:
	compare = (p[0], q[0], r[0])

	if p[0] == max(compare):
		x += 1
		ans += p.popleft()
		if x == X:
			p = [0]
	elif q[0] == max(compare):
		y += 1
		ans += q.popleft()
		if y == Y:
			q = [0]
	else:
		z += 1
		ans += r.popleft()

print(ans)
Problem p02731 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
L = INT()
print((L/3)**3)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
L = input()
print((L/3)**3)
Problem p02743 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np

a, b, c = MAP()
if 4*a*b < (c-a-b)**2 and c-a-b > 0:
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

a, b, c = MAP()
 
if Decimal(a)**0.5 + Decimal(b)**0.5 < Decimal(c)**0.5:
	print("Yes")
else:
	print("No")
Problem p02812 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()
cnt = 0

for i in range(N-2):
  if S[i] == "A" and S[i+1] == "B" and S[i+2] == "C":
    cnt += 1
    
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()
cnt = 0

for i in range(N):
  if S[i] == "A" and S[i+1] == "B" and S[i+2] == "C":
    cnt += 1
    
print(cnt)
Problem p02845 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

ans = 1
cnt = [0, 0, 0]
for i in range(N):
	ans = ans * cnt.count(A[i]) % mod
	if A[i] in cnt:
		cnt[cnt.index(A[i])] += 1
	else:
		print(0)
		exit()

print(ans)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

ans = 1
cnt = [0, 0, 0]
for i in range(N):
	ans = ans * cnt.count(A[i]) % mod
	cnt[cnt.index(A[i])] += 1

print(ans)