Harryxun/stf_run huggingface dataset:
n = map(int,input())
a = [int(input().split(sep=" ")[1])]
for i in range(n):
    command = input()
    if(command == "deleteFirst"):
        a.pop(0)
    elif(command == "deleteLast"):
        a.pop()
    else:
        command,num = command.split(sep = " ")
        num = int(num)
        if(command == "delete"):
            a.remove(n)
        else:
            a.append(n)
for num in a:
    print(num,end=" ")
print()


### FIXED CODE ###

class Node(object):
    def __init__(self, num, prv = None, nxt = None):
        self.num = num
        self.prv = prv
        self.nxt = nxt
  
  
class DoublyLinkedList(object):
    def __init__(self):
        self.start = self.last = None
  
    def insert(self, num):
        new_elem = Node(num)
  
        if self.start is None:
            self.start = self.last = new_elem
        else:
            new_elem.nxt = self.start
            self.start.prv = new_elem
            self.start = new_elem
  
    def delete_num(self, target):
        it = self.start
        while it is not None:
            if it.num == target:
                if it.prv is None and it.nxt is None:
                    self.start = self.last = None
                else:
                    if it.prv is not None:
                        it.prv.nxt = it.nxt
                    else:
                        self.start = self.start.nxt
  
                    if it.nxt is not None:
                        it.nxt.prv = it.prv
                    else:
                        self.last = self.last.prv
                break
            it = it.nxt
  
    def delete_start(self):
        if self.start is self.last:
            self.start = self.last = None
        else:
            self.start.nxt.prv = None
            self.start = self.start.nxt
  
    def delete_last(self):
        if self.start is self.last:
            self.start = self.last = None
        else:
            self.last.prv.nxt = None
            self.last = self.last.prv
  
    def get_content(self):
        ret = []
        it = self.start
  
        while it is not None:
            ret.append(it.num)
            it = it.nxt
  
        return ' '.join(ret)
  
  
def _main():
    from sys import stdin
  
    n = int(input())
  
    lst = DoublyLinkedList()
      
    for _ in range(n):
        cmd = stdin.readline().strip().split()
        if cmd[0] == 'insert':
            lst.insert(cmd[1])
        elif cmd[0] == 'delete':
            lst.delete_num(cmd[1])
        elif cmd[0] == 'deleteFirst':
            lst.delete_start()
        elif cmd[0] == 'deleteLast':
            lst.delete_last()
  
    print(lst.get_content())
  
  
if __name__ == '__main__':
    _main()
N = int(input())

for n in range(1, N+1):
    ans = 0
    for x in range(1, 15):
        for y in range(x, 20):
            for z in range(y, 35):
                f = x**2 + y**2 + z**2 + x*y + x*z + y*z
                if f == n:
                    if x == y == z:
                        ans = 1
                    elif (x == y) or (y == z):
                        ans = 3
                    else:
                        ans = 6
    print(ans)


### FIXED CODE ###

l, r, d = map(int, input().split(" "))

ans = 0
for i in range(l, r+1):
    if i % d == 0:
        ans += 1
print(ans)
import bisect
from collections import deque
N, K = map(int, input().split())
D = list(map(int, input().split()))

ans = 0
for pull_num in range(K+1):
  	if pull_num > N:
        continue
    push_num = K - pull_num
    #print('pull_num:{}'.format(pull_num))
    for left_num in range(pull_num+1):
        right_num = pull_num - left_num
        #print('left_num:{} right_num:{}'.format(left_num, right_num))
        left_D = D[:left_num];  right_D = D[N-right_num:]
        #print('left_D:{} right_D:{}'.format(left_D, right_D))
        temochi = left_D + right_D
        temochi.sort()
        #print('temochi:{}'.format(temochi))
        index = bisect.bisect_left(temochi, 0)
        #print('index:{}'.format(index))
        #print('push_num:{}'.format(push_num))
        if push_num >= index:
            ans = max(ans, sum(temochi[index:]))
        else:
            ans = max(ans, sum(temochi[push_num:]))
print(ans)

### FIXED CODE ###

import bisect
from collections import deque
N, K = map(int, input().split())
D = list(map(int, input().split()))

ans = 0
for pull_num in range(K+1):
    if pull_num > N:
        continue
    push_num = K - pull_num
    for left_num in range(pull_num+1):
        right_num = pull_num - left_num
        left_D = D[:left_num];  right_D = D[N-right_num:]
        temochi = left_D + right_D
        temochi.sort()
        index = bisect.bisect_left(temochi, 0)
        if push_num >= index:
            ans = max(ans, sum(temochi[index:]))
        else:
            ans = max(ans, sum(temochi[push_num:]))
print(ans)
N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter

if D[0] != 0:
    print(0)
    exit(0)

cd = Counter(D)
if cd[0] != 1:
    print(0)
    exit(0)

tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1

import math
for kx in range(1, max(D)+1):
    ans *= math.pow(cd[kx-1], cd[kx],M)
    ans %= M

print(ans)

### FIXED CODE ###

N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter

if D[0] != 0:
    print(0)
    exit(0)

cd = Counter(D)
if cd[0] != 1:
    print(0)
    exit(0)

tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1


for kx in range(1, max(D)+1):
    ans *= pow(cd[kx-1], cd[kx],M)
    ans %= M

print(ans)
n, k = (int(x) for x in input().split())
a = input().split()

for i in range(1,n-k+1):
    if(int(a[i-1]) >= int(a[k+i-1])):
        print("No")
    else:
        print("Yes")


### FIXED CODE ###


M = int(input())

if(M>=400 and M<600):
    print("8")
elif(M>=600 and M<800):
    print("7")
elif(M>=800 and M<1000):
    print("6")
elif(M>=1000 and M<1200):
    print("5")
elif(M>=1200 and M<1400):
    print("4")
elif(M>=1400 and M<1600):
    print("3")
elif(M>=1600 and M<1800):
    print("2")
elif(M>=1800 and M<2000):
    print("1")
from collections import deque
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, readline().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
def bfs(s):
    dist = [None]*N
    que = deque([s])
    dist[s] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in G[v]:
            if dist[w] is not None:
                continue
            dist[w] = d + 1
            que.append(w)
    d = max(dist)
    return dist.index(d), d
u, _ = bfs(0)
v, d = bfs(u)

memo = [-1]*(d+2)
memo[0] = 0
memo[1] = 1
memo[2] = 0
def dfs(d):
    if memo[d] != -1:
        return memo[d]
    if dfs(d-1) == 0 or dfs(d-2) == 0:
        memo[d] = 1
        return 1
    memo[d] = 0
    return 0
print("First" if dfs(d+1) else "Second")

### FIXED CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N = int(readline())
if N == 1:
    print("First")
    exit(0)
G = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, readline().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
def bfs(s):
    dist = [None]*N
    que = deque([s])
    dist[s] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in G[v]:
            if dist[w] is not None:
                continue
            dist[w] = d + 1
            que.append(w)
    d = max(dist)
    return dist.index(d), d
u, _ = bfs(0)
v, d = bfs(u)

memo = [-1]*(d+2)
memo[0] = 0
memo[1] = 1
memo[2] = 0
for i in range(3, d+2):
    if memo[i-1] == 0 or memo[i-2] == 0:
        memo[i] = 1
    else:
        memo[i] = 0
print("First" if memo[d+1] else "Second")
n = int(input())
s = input()
b_total = 0
w_total = 0
ans = 0
for i in range(n):
  if s[i] == '#':
    b_cnt += 1
  if s[i] == '.':
    w_cnt += 1
b_cnt = 0
w_cnt = 0
ans = 10**6
for i in range(n):
  if s[i] == '#':
    b_cnt += 1
  if s[i] == '.':
    w_cnt += 1
  cnt = b_cnt + (w_total - w_cnt)
  ans = min(ans, cnt)
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
b_total = 0
w_total = 0
ans = 0
for i in range(n):
  if s[i] == '#':
    b_total += 1
  if s[i] == '.':
    w_total += 1
if b_total == n:
  print(0)
else:
  b_cnt = 0
  w_cnt = 0
  ans = b_cnt + (w_total - w_cnt)
  for i in range(n):
    if s[i] == '#':
      b_cnt += 1
    if s[i] == '.':
      w_cnt += 1
    cnt = b_cnt + (w_total - w_cnt)
    ans = min(ans, cnt)
  print(ans)
# B - Great Ocean View
# https://atcoder.jp/contests/abc124/tasks/abc124_b


n = int(input())
points = list(map(int, input().split()))
# points = [1,2,3,4,5]

# if len(points) < 3:
#     first, second = points[0], points[1]
need_height = max(points[0], points[1])
ans = 1
for i in range(1, len(points)):
    pre_spot = points[i-1]
    if need_height <= points[i] and pre_spot <= points[i]:
        ans += 1

        
print(ans)

### FIXED CODE ###

# B - Great Ocean View
# https://atcoder.jp/contests/abc124/tasks/abc124_b


n = int(input())
points = list(map(int, input().split()))
ans = 1
need_height = points[0]


for i in range(1, n):
    current = points[i]
    if need_height <= current:
        ans += 1
        need_height = current


print(ans)
n = int(input())
ans = 1
s = input()
a = [int(x.strip()) for x in s.split(' ')]
if 0 in a:
  print(0)
  return
for i in range(n):
  ans *= a[i]
  if ans>1000000000000000000:
    print(-1)
    return
print ans

### FIXED CODE ###

import sys
n = int(input())
ans = 1
s = input()
a = [int(x.strip()) for x in s.split(' ')]
if 0 in a:
  print(0)
  sys.exit()
for i in range(n):
  ans *= a[i]
  if ans>1000000000000000000:
    print(-1)
    sys.exit()
print(ans)
S = int(input())
DP = [0]*(S+1)
Mod = 10**9+7
DP[0] = 1
DP[1] = 0
DP[2] = 0
for TS in range(3,S+1):
    DP[TS] = (DP[TS-1]+DP[TS-3])%Mod
print(DP[S])

### FIXED CODE ###

S = int(input())
DP = [0]*(S+1)
Mod = 10**9+7
if S>=3:
    DP[0] = 1
    DP[1] = 0
    DP[2] = 0
    for TS in range(3,S+1):
        DP[TS] = (DP[TS-1]+DP[TS-3])%Mod
    print(DP[S])
else:
    print(0)
n,q = map(int,input().split())
s = input()
m = [list(map(int,input().split())) for i in range(q)]
count = [0]*(N+1)
 
for i in range(n):
    if S[i:i+2] == 'AC':
        comu[i+1] = comu[i] + 1
    else:
        comu[i+1] = comu[i]
 
for l,r in list:
    print(count[r-1]-count[l-1])

### FIXED CODE ###

n,q = map(int,input().split())
s = input()
m = [list(map(int,input().split())) for i in range(q)]
count = [0]*(n+1)
 
for i in range(n):
    if s[i:i+2] == 'AC':
        count[i+1] = count[i] + 1
    else:
        count[i+1] = count[i]
 
for l,r in m:
    print(count[r-1]-count[l-1])
N,K = map(int,input().split())
A = list(map(int,input().split()))

if N==1:
    print(A[0] if K%2 else '')
    exit()

AA = A+A
last_i = {}
nx = [-1]*N
for i,a in enumerate(reversed(AA)):
    i = 2*N-i-1
    if i < N:
        nx[i] = (last_i[a] - i) % N + 1
    last_i[a] = i

visited = [-1]*N
visited[0] = 0
j = i = 0
while 1:
    p = nx[i]+N if nx[i]==1 else nx[i]
    j += p
    if visited[j%N] < 0:
        visited[j%N] = j
    else:
        break
    i = j%N
cycle = (j - visited[j%N]) // N

K %= cycle
j = i = 0
while 1:
    p = nx[i]+N if nx[i]==1 else nx[i]
    if j+p > N*K:
        break
    j += p
    i = j%N

if j%N == 0:
    print()
else:
    ans = []
    anss = set()
    for a in A[j%N:]:
        if a in anss:
            anss.remove(a)
            while ans[-1] != a:
                ans.pop()
            ans.pop()
        else:
            anss.add(a)
            ans.append(a)
    print(*ans)

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))

if N==1:
    print(A[0] if K%2 else '')
    exit()

AA = A+A
last_i = {}
nx = [-1]*N
for i,a in enumerate(reversed(AA)):
    i = 2*N-i-1
    if i < N:
        nx[i] = (last_i[a] - i) % N + 1
    last_i[a] = i

visited = [-1]*N
visited[0] = 0
j = i = 0
while 1:
    p = nx[i]+N if nx[i]==1 else nx[i]
    j += p
    if visited[j%N] < 0:
        visited[j%N] = j
    else:
        break
    i = j%N
cycle = (j - visited[j%N]) // N
K %= cycle
j = i = 0
while 1:
    p = nx[i]+N if nx[i]==1 else nx[i]
    if j+p > N*K:
        break
    j += p
    i = j%N

if j%N == 0:
    if K==1:
        print(*A)
    else:
        print()
else:
    ans = []
    anss = set()
    for a in A[j%N:]:
        if a in anss:
            while ans[-1] != a:
                anss.remove(ans[-1])
                ans.pop()
            anss.remove(a)
            ans.pop()
        else:
            anss.add(a)
            ans.append(a)
    print(*ans)
import sys

def sieve(n):
    is_prime = [True] * (n + 1)
    prime_list = []
    
    is_prime[0] = is_prime[1] = False
    prime_list.append(2)
    
    for i in range(3, n + 1, 2):
        if is_prime[i]: prime_list.append(i)
        for j in range(i * i, n + 1, i):
            is_prime[j] = False
    return prime_list
    
primes = sieve(40000)

def factoriaztion(n):
    ret = []
    for prime in primes:
        while n % prime == 0:
            ret.append(prime)
            n /= prime
        if n == 1: break
    if n > 1: ret.append((n, 1))
    return ret
    
    
if __name__ == '__main__':
    n = sys.stdin.readline()
    n = int(n)
    factors = factoriaztion(n)
    factors = itertools.groupby(factors)
    
    ans = 1
    
    for k, v in factors:
        l = len(list(v))
        ans = ans * (k ** l - k ** (l - 1))
    
    sys.stdout.write(str(ans) + '\n')
    

### FIXED CODE ###

import sys
import itertools

def extend_gcd(a, b):
    if b == 0:
        return (1, 0, a)
    else:
        (a1, b1, g) = extend_gcd(b, a % b)
        return (b1, a1 - (a // b) * b1, g)
    
    
if __name__ == '__main__':
    line = sys.stdin.readline()
    a,b = line.split()
    a,b = int(a), int(b)
    
    (x, y, g) = extend_gcd(a, b)
    
    
    sys.stdout.write(str(x) + ' '  + str(y) +  '\n')
a=int(input())
b=int(input())
c=int(input())
if((a+b)>=c):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a,b,c = map(int,input().split())
if a+b>=c:
  print("Yes")
else:
  print("No")
b=input()
if b == 'A':
    print('T')
    elif b == 'T':
        print('A')
        elif b == 'C':
            print('G')
            else:
                print(C)

### FIXED CODE ###

b=input()
if b == 'A':
    print('T')
elif b == 'T':
    print('A')
elif b == 'C':
    print('G')
else:
    print('C')
a, b, n = map(int, input().split())

tmp = 0
for x in (range(1, b+1, b-1) if b<=n else range(1, n+1, n-1)):
#for x in range(1, n+1):
    calc = a*x//b - a*(x//b)
    if calc > tmp:
        tmp = calc

print(tmp)

### FIXED CODE ###

a, b, n = map(int, input().split())
 
tmp = 0
for x in (range(1, b+1, b-2) if b<=n else range(1, n+1, n-1)):
#for x in range(1, n+1):
    calc = a*x//b - a*(x//b)
    if calc > tmp:
        tmp = calc
 
print(tmp)
first_input = input().split()
x = int(first_input[0])
n = int(first_input[1])
if n != 0:
    second_input = map(int, input().split())
    p_a = list(map(int, second_input))
else:
    second_input = input()

def create_full_array(minimum, maximum):
    diff = maximum - minimum
    full_list = []
    for i in range(minimum,maximum+1):
        full_list.append(int(i))
    return full_list

if n == 0:
    print(x)
elif x > max(p_a) + 1 or x < min(p_a):
    ans = x - 1
    print(ans)
else:
    full_array = create_full_array(min(p_a), max(p_a))
    if x in p_a:
        target_list = list(set(p_a)^set(full_array))
        abs_key = {}
        for i in target_list:
            abs_key[i] = abs(x-i)
        minimum = min(abs_key.values())
        t_k = []
        t_v = []
        [t_k.append(k) for k, v in abs_key.items() if v == minimum]
        print(min(t_k))

    else:
        print(x)

### FIXED CODE ###

first_input = input().split()
x = int(first_input[0])
n = int(first_input[1])
if n != 0:
    second_input = map(int, input().split())
    p_a = list(map(int, second_input))
else:
    second_input = input()

def create_full_array(minimum, maximum):
    full_list = []
    for i in range(minimum,maximum+1):
        full_list.append(int(i))
    return full_list

if n == 0:
    print(x)
elif x > max(p_a) + 1 or x < min(p_a):
    ans = x - 1
    print(ans)
elif x == max(p_a) + 1:
    ans = x + 1
    print(ans)
else:
    full_array = create_full_array(min(p_a), max(p_a))
    if x in p_a:
        target_list = list(set(p_a)^set(full_array))
        abs_key = {}
        if len(target_list) == 0:
            if abs(x - min(p_a)) <= abs(x - max(p_a)):
                print(min(p_a) - 1)
            else:
                print(max(p_a) + 1)
        else:
            for i in target_list:
                abs_key[i] = abs(x-i)
            minimum = min(abs_key.values())
            t_k = []
            t_v = []
            [t_k.append(k) for k, v in abs_key.items() if v == minimum]
            print(min(t_k))

    else:
        print(x)
X, Y = map(int, input().split())
cnt = 0
while X <= Y
  cnt += 1
  X *= 2
print(cnt)

### FIXED CODE ###

X, Y = map(int, input().split())
cnt = 0
while X <= Y:
  cnt += 1
  X *= 2
print(cnt)
import math
a,b = map(int,input().split())
print(a*b//math.gcd(a,b))

### FIXED CODE ###


def gcd(a,b):
    ma = max(a,b)
    mi = min(a,b)
    while(True):
        los = ma % mi
        ma = mi
        mi = los
        if los == 0:
            result = ma
            break
    return result

a,b = map(int,input().split())
print(a*b//gcd(a,b))
import fractions as f

N = int(input())

A = list(map(int,input().split()))

rightGCD = []
leftGCD = []

rightGCD.append(0)
rightGCD.append(A[0])
tmp = A[0]
for x in A[2:]:
    tmp = f.gcd(tmp,x)
    rightGCD.append(tmp)

leftGCD.insert(0,0)
leftGCD.insert(0,A[-1])
tmp = A[-1]
for x in A[1:N-3:-1]:
    tmp = f.gcd(tmp,x)
    leftGCD.insert(0,tmp)

ans = 0

for i in range(N):
    if i==0:
        ans = max(ans,leftGCD[i])
        continue
    if i==N-1:
        ans = max(ans,rightGCD[i])
        continue

    ans = max(ans,f.gcd(rightGCD[i],leftGCD[i]))

#print(leftGCD)
#print(rightGCD)
print(ans)


### FIXED CODE ###

import fractions as f

N = int(input())

A = list(map(int,input().split()))

rightGCD = [0]*N
leftGCD = [0]*N

for i in range(N-1):
    leftGCD[i+1] = f.gcd(leftGCD[i],A[i])
    rightGCD[-i-2] = f.gcd(rightGCD[-i-1],A[-i-1])

#print(leftGCD)
#print(rightGCD)

ans = 0

for i in range(N):
    ans = max(ans,f.gcd(rightGCD[i],leftGCD[i]))

print(ans)
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
A1=A[0:n-1:2]
A2=A[1:n:2]
L=Counter(A)
L1=Counter(A1)
L2=Counter(A2)
comon=L.most_common()
comon1=L1.most_common()
comon2=L2.most_common()
hanbun=n//2
if len(comon)==1:
    print(hanbun)
else:
    cnt=0
    saidai11=comon1[0][1]
    saidai21=comon2[0][1]
    if saidai11>=saidai21:
        cnt+=hanbun-saidai11
        if saidai11==saidai21:
            cnt+=hanbun-comon2[1][1]
        else:
            cnt+=hanbun-saidai21
    else:
        cnt+=hanbun-saidai11
        if saidai11==saidai21:
            cnt+=hanbun-comon1[1][1]
        else:
            cnt+=hanbun-saidai11
    print(cnt)
    

### FIXED CODE ###

from collections import Counter

n = int(input())
A = list(map(int, input().split()))

kisu = A[0::2]
gusu = A[1::2]

CK = Counter(kisu)
CG = Counter(gusu)
CKM = CK.most_common(2)
CGM = CG.most_common(2)

if len(CKM) == 1 and len(CGM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2
    else:
        ans = 0
elif len(CKM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2 - CGM[1][1]
    else:
        ans = n // 2 - CGM[0][1]
elif len(CGM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2 - CKM[1][1]
    else:
        ans = n // 2 - CKM[0][1]
else:
    if CKM[0][0] == CGM[0][0]:
        ans1 = n // 2 - CKM[1][1] + n // 2 - CGM[0][1]
        ans2 = n // 2 - CGM[1][1] + n // 2 - CKM[0][1]
        ans = min(ans1, ans2)
    else:
        ans = n - (CKM[0][1] + CGM[0][1])

print(ans)
import math
n,a,b,k = map(int, input().split())
un = 998244353
def combination(n,r):
    return math.factorial(n)//(math.factorial(r) * math.factorial(n-r))

total = 0
for i in range(n+1):
    if((k-a*i)%b==0):
        count_b = (k-a*i)//b
        total += combination(n, i) * combination(n, count_b)

print(str(total % un))


### FIXED CODE ###

import math
n,a,b,k = map(int, input().split())
un = 998244353
f = [0]*(n+1)
inv = [0] * (n+1)
f[0] = f[1] = 1

for i in range(2, n+1):
    f[i] = (f[i-1] * i ) % un

inv[n] = pow(f[n], un-2, un)
for i in range(n, 0, -1):
    inv[i-1] = (inv[i] * i) % un

#フェルマーの小定理の利用
def nCr(n,r):
    global f, inv
    return (f[n] * inv[r]) % un * inv[n-r] % un

total = 0
for i in range(n+1):
    if((k-a*i)%b==0):
        count_b = (k-a*i)//b
        if(count_b >= 0 and count_b <= n):
            total += nCr(n, i) * nCr(n, count_b)

print(str(total % un))
while 1:
	a,"op",b= map(int,raw_input().split())
	if op=="+":
		x=a+b
	elif op=="-":
		x=a-b
	elif op=="*":
		x=a*b
	elif op=="/":
		x=a/b
	elif op=="?":
		break
	
	print "%d" %(x)

### FIXED CODE ###

while 1:
	x=raw_input().split()
	op= x[1]
	a = int(x[0])
	b = int(x[2])

	if op=="+":
		x=a+b
	elif op=="-":
		x=a-b
	elif op=="*":
		x=a*b
	elif op=="/":
		x=a/b
	elif op=="?":
		break
	
	print "%d" %(x)
N = int(input().split())
ans = 0
if N%2 == 0:
    ans = N/2 ** 2
else:
    ans = (N/2 + 1/2) * (N/2 - 1/2)
print(ans)

### FIXED CODE ###

K=int(input())
print((K//2)*((K+1)//2))
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 +7

if a[0] != 0:
    print(0)
    exit()

col = [1,0,0]

ans = 3
cnt = 2

for i in range(1,n):
    ans *= col.count(a[i])
    ans %= mod
    col[col.index(a[i])] += 1

print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
mod = 10**9 +7

col = [0,0,0]

ans = 1

for i in range(n):
    if not a[i] in col:
        print(0)
        exit()
    else:
        ans *= col.count(a[i])
        ans %= mod
        col[col.index(a[i])] += 1

if sum(col) != n:
    print(0)
    exit()

print(ans%mod)
#!/usr/bin/env python3

from collections import Counter

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    D = LII()

   if D[0] != 0 or D.count(0) > 1:
       print(0)
       return 
    
    mx = max(D)
    cnt = 1
    for i in range(1, mx+1):
        pre = D.count(i)
        post = D.count(i+1)
        cnt *= pre ** post
    print(cnt)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3

from collections import Counter

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

MOD = 998244353

def main():
    N = II()
    D = LII()

    if D[0] != 0 or D.count(0) > 1:
       print(0)
       return 
    
    c = Counter(D)
    res = 1

    if c[0] > 1:
       print(0)
       return
    
    mx = max(c.keys())
    for i in range(1, mx+1):
        if i not in c:
            print(0)
            return
        
        res = (res * c[i-1] ** c[i]) % MOD

    print(res)

if __name__ == '__main__':
    main()
mod =10**9 +7
n = int(input())
a = list(map(int, input().split()))
sumpro = 0

for i in range(n-1):
    x = 0
    for j in range(i+1, n):
        x += a[j]
    x = x%mod
    y = a[i]* x
        sumpro += y

print(sumpro%mod)

### FIXED CODE ###

MOD = 10 ** 9 + 7  # MODは変数に入れてしまったほうが打ち間違えなくていいです

N = int(input())
A = list(map(int, input().split()))

S = sum(A) % MOD
ans = 0

# A_Nも含まれてしまいますが、そのときはs=0なので問題ありません
for x in A:
    S -= x  # 自分と自分自身を掛けないように、先に引く必要があります
    S %= MOD  # MODはいちいち取っておくといいです
    ans += S * x
    ans %= MOD

ans %= MOD  # この行は完全に不要ですが、最後だけMODを取り忘れてWAになるミスは非常によくあるので、必要以上に取っておくと安心できます
print(ans)