Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
c=input().split()
for i in range(2):
    c[i]=int(c[i])
n=c[0]
m=c[1]
a=input().split()

for i in range(len(a)):
    a[i]=int(a[i])

b=[0 for i in range(m+1)]

for i in range(n-1):
    if(a[i]<a[i+1]):
        for j in range(a[i+1]-a[i]):
            b[a[i]+1+j]+=1
    else:
        for j in range(a[i+1]):
            b[j+1]+=1
        for j in range(m-a[i]):
            b[a[i]+1+j]+=1

max_value=0
max_num=0
for i in range(m):
    if(max_value<=b[i]):
        max_value=b[i]
        max_num=i

def move(x,y):
    result=0
    if(x<y):
        result=y-x
    else:
        result=(m-x)+y

    return result

sum_value=0
for i in range(n-1):
    sum_value+=min(move(max_num,a[i+1]),move(a[i],a[i+1]))
print(sum_value)

Fixed submission:
n=int(input())
a=input().split()

for i in range(len(a)):
    a[i]=int(a[i])

b=[0 for i in range(len(a))]

if(n%2==0):
    for i in range(int(n/2)):
        b[i]=a[n-2*i-1]
    
    for i in range(int(n/2)):
        b[i+int(n/2)]=a[1+2*i-1]
else:
    for i in range(int((n+1)/2)):
        b[i]=a[n-2*i-1]
    for i in range(int((n-1)/2)):
        b[i+int((n+1)/2)]=a[2+2*i-1]
        
for i in range(n):
    print(b[i],end=" ")

Buggy python submission (verdict: Runtime Error):
c=input().split
for i in range(2):
    c[i]=int(c[i])
n=c[0]
m=c[1]
a=input().split()

for i in range(len(a)):
    a[i]=int(a[i])

b=[0 for i in range(m+1)]

for i in range(n-1):
    if(a[i]<a[i+1]):
        for j in range(a[i+1]-a[i]):
            b[a[i]+1+j]+=1
    else:
        for j in range(a[i+1]):
            b[j+1]+=1
        for j in range(m-a[i]):
            b[a[i]+1+j]+=1

max_value=0
max_num=0
for i in range(m):
    if(max_value<=b[i]):
        max_value=b[i]
        max_num=i

def move(x,y):
    result=0
    if(x<y):
        result=y-x
    else:
        result=(m-x)+y

    return result

sum_value=0
for i in range(n-1):
    sum_value+=min(move(max_num,a[i+1]),move(a[i],a[i+1]))
print(sum_value)

Fixed submission:
n=int(input())
a=input().split()

for i in range(len(a)):
    a[i]=int(a[i])

b=[0 for i in range(len(a))]

if(n%2==0):
    for i in range(int(n/2)):
        b[i]=a[n-2*i-1]
    
    for i in range(int(n/2)):
        b[i+int(n/2)]=a[1+2*i-1]
else:
    for i in range(int((n+1)/2)):
        b[i]=a[n-2*i-1]
    for i in range(int((n-1)/2)):
        b[i+int((n+1)/2)]=a[2+2*i-1]
        
for i in range(n):
    print(b[i],end=" ")
Buggy python submission (verdict: Runtime Error):
r=int(input())
g=int(input())
b=int(input())
 
x=int(r*100+g*10+b)
if(x%4==0):
    print('YES')
else:
    print("NO")

Fixed submission:
a=input()
a=a.split()

r=int(a[0])
g=int(a[1])
b=int(a[2])

x=100*r+10*g+b

if(x%4==0):
    print('YES')
else:
    print('NO')

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

x=int(r*100+g*10+b)
if(x%4==0):
    print('YES')
else:
    print("NO")

Fixed submission:
a=input()
a=a.split()

r=int(a[0])
g=int(a[1])
b=int(a[2])

x=100*r+10*g+b

if(x%4==0):
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
Sa = list(raw_input())
Sb = list(raw_input())
Sc = list(raw_input())

ne = Sa.pop(0)
s = len(Sa)
while s!=0:
    if ne == "a":
        ne = Sa.pop(0)
        s = len(Sa)
    if ne == "b":
        ne = Sb.pop(0)
        s = len(Sb)
    if ne == "c":
        ne = Sc.pop(0)
        s = len(Sc)
print ne.upper()

Fixed submission:
Sa = list(raw_input())
Sb = list(raw_input())
Sc = list(raw_input())

def choise(t):
    if t == "a":
        if Sa == []:
            print "A"
        else:
            choise(Sa.pop(0))
    elif t== "b":
        if Sb == []:
            print "B"
        else:
            choise(Sb.pop(0))
    else:
        if Sc == []:
            print "C"
        else:
            choise(Sc.pop(0))

choise(Sa.pop(0))

Buggy python submission (verdict: Runtime Error):
Sa = list(raw_input())
Sb = list(raw_input())
Sc = list(raw_input())

ne = Sa.pop(0)
s = len(Sa)
while s!=0:
    if ne == "a":
        ne = Sa.pop(0)
    if ne == "b":
        ne = Sb.pop(0)
    if ne == "c":
        ne = Sc.pop(0)
    s = len(Sa)
print ne.upper()

Fixed submission:
Sa = list(raw_input())
Sb = list(raw_input())
Sc = list(raw_input())

def choise(t):
    if t == "a":
        if Sa == []:
            print "A"
        else:
            choise(Sa.pop(0))
    elif t== "b":
        if Sb == []:
            print "B"
        else:
            choise(Sb.pop(0))
    else:
        if Sc == []:
            print "C"
        else:
            choise(Sc.pop(0))

choise(Sa.pop(0))

Buggy python submission (verdict: Runtime Error):
Sa = list(raw_input())
Sb = list(raw_input())
Sc = list(raw_input())

ne = Sa.pop(0)
s = len(Sa)
while s!=0:
    if ne == "a":
        ne = Sa.pop(0)
    if ne == "b":
        ne = Sb.pop(0)
    if ne == "c":
        ne = Sc.pop(0)
    s = len(Sa)
print ne

Fixed submission:
Sa = list(raw_input())
Sb = list(raw_input())
Sc = list(raw_input())

def choise(t):
    if t == "a":
        if Sa == []:
            print "A"
        else:
            choise(Sa.pop(0))
    elif t== "b":
        if Sb == []:
            print "B"
        else:
            choise(Sb.pop(0))
    else:
        if Sc == []:
            print "C"
        else:
            choise(Sc.pop(0))

choise(Sa.pop(0))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
d = map(int, raw_input().split())
def use_d(n):
    for i in list(str(n)):
        if int(i) in d:
            return True
    else:
        return False
while n < 100000:
    if use_d(n):
        n += 1
    else:
        print n
        sys.exit()

Fixed submission:
import itertools,math,bisect,pprint,sys

n, k = map(int, raw_input().split())
d = map(int, raw_input().split())
def use_d(n):
    for i in list(str(n)):
        if int(i) in d:
            return True
    else:
        return False
while n < 100000:
    if use_d(n):
        n += 1
    else:
        print n
        sys.exit()
Buggy python submission (verdict: Runtime Error):
import sys

okDay = int(sys.argv[1])
buyDay = int(sys.argv[2])
eatDay = int(sys.argv[3])
overDay = eatDay - buyDay
if overDay <= 0 :
    print("delicious")
    sys.exit()
if overDay <= okDay :
    print("safe")
    sys.exit()
print("dangerous")

Fixed submission:
first = input()
split_first = first.split()

d = int(split_first[0])
a = int(split_first[1])
b = int(split_first[2])

if a >= b:
   print ('delicious')
elif b - a <= d:
   print ('safe')
else:
   print ('dangerous')

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if 2 not in a:
    print(-1)
else:
    cnt = 0
    before_num = 1
    lighted_bottons = []
    while True:
        cnt += 1
        if a[before_num - 1] == 2:
            print(cnt)
            break
        else:
            if a[before_num - 1] in lighted_bottons:
                print(-1)
                break
            before_num = a[before_num - 1]
            lighted_bottons.append(before_num)

Fixed submission:
# -*- coding: utf-8 -*-

x, a, b = (int(i) for i in input().split())
if a - b >= 0:
    print("delicious")
elif a + x - b >= 0:
    print("safe")
else:
    print("dangerous")

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if 2 not in a:
    print(-1)
else:
    cnt = 0
    before_num = 1
    lighted_bottons = []
    while True:
        cnt += 1
        if a[before_num - 1] == 2:
            print(cnt)
            break
        else:
            if a[before_num - 1] in lighted_bottons:
                print(-1)
                break
            before_num = a[before_num - 1]
            lighted_bottons.append(before_num)

Fixed submission:
# -*- coding: utf-8 -*-

x, a, b = (int(i) for i in input().split())
if a - b >= 0:
    print("delicious")
elif a + x - b >= 0:
    print("safe")
else:
    print("dangerous")
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if 2 not in a:
    print(-1)
else:
    cnt = 0
    before_num = 1
    lighted_bottons = [0 for i in range(n)]
    while True:
        cnt += 1
        if a[before_num - 1] == 2:
            print(cnt)
            break
        else:
            if lighted_bottons[a[before_num - 1]] == 1:
                print(-1)
                break
            before_num = a[before_num - 1]
            lighted_bottons[before_num] = 1

Fixed submission:
# -*- coding: utf-8 -*-


n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if 2 not in a:
    print(-1)
else:
    cnt = 0
    before_num = 1
    lighted_bottons = [0 for i in range(n + 1)]
    while True:
        cnt += 1
        if a[before_num - 1] == 2:
            print(cnt)
            break
        else:
            if lighted_bottons[a[before_num - 1]] == 1:
                print(-1)
                break
            before_num = a[before_num - 1]
            lighted_bottons[before_num] = 1

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if 2 not in a:
    print(-1)
else:
    cnt = 0
    before_num = 1
    lighted_bottons = []
    while True:
        cnt += 1
        if a[before_num - 1] == 2:
            print(cnt)
            break
        else:
            if a[before_num - 1] in lighted_bottons:
                print(-1)
                break
            before_num = a[before_num - 1]
            lighted_bottons.append(before_num)

Fixed submission:
# -*- coding: utf-8 -*-


n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if 2 not in a:
    print(-1)
else:
    cnt = 0
    before_num = 1
    lighted_bottons = [0 for i in range(n + 1)]
    while True:
        cnt += 1
        if a[before_num - 1] == 2:
            print(cnt)
            break
        else:
            if lighted_bottons[a[before_num - 1]] == 1:
                print(-1)
                break
            before_num = a[before_num - 1]
            lighted_bottons[before_num] = 1
Buggy python submission (verdict: Runtime Error):
first = input()
split_first = first.split()

d = int(split_first[0])
a = int(split_first[1])
b = int(split_first[2])

if a >= b:
   print ('delicious')
else if b - a <= d:
   print ('safe')
else:
   print ('dangerous')

Fixed submission:
stdin = input()

d = int(stdin.split(" ")[0])
a = int(stdin.split(" ")[1])
b = int(stdin.split(" ")[2])

if b <= a:
    print ("delicious")
elif b <= a + d:
    print ("safe")
elif b > a + d:
    print ("dangerous")

Buggy python submission (verdict: Runtime Error):
first = input()
split_first = first.split()

d = int(split_first[0])
a = int(split_first[1])
b = int(split_first[2])

if a >= b:
   print ('delicious')
else if b - a <= d:
   print ('safe')
else:
   print ('dangerous')

Fixed submission:
stdin = input()

d = int(stdin.split(" ")[0])
a = int(stdin.split(" ")[1])
b = int(stdin.split(" ")[2])

if b <= a:
    print ("delicious")
elif b <= a + d:
    print ("safe")
elif b > a + d:
    print ("dangerous")

Buggy python submission (verdict: Runtime Error):
x,a,b = map(int, input().split())
if b <=a:
    print("delicious")
elif b <= a+x:
    print("safe")
else:
    print("dangerous")
afaafafd

Fixed submission:
x,a,b = map(int, input().split())
if b <=a:
    print("delicious")
elif b <= a+x:
    print("safe")
else:
    print("dangerous")

Buggy python submission (verdict: Runtime Error):
num=raw_input('the 3 number of days:')
numberdays=num.split(' ')
if int(numberdays[2])-int(numberdays[1])>int(numberdays[0]):
    print 'dangerous'
if 0<int(numberdays[2])-int(numberdays[1])<=int(numberdays[0]):
    print 'safe'
if if int(numberdays[2])-int(numberdays[1])<=0:
    print 'delicious'

Fixed submission:
num=raw_input('')
numberdays=num.split(' ')
if int(numberdays[2])-int(numberdays[1])>int(numberdays[0]):
    print 'dangerous'
if 0<int(numberdays[2])-int(numberdays[1])<=int(numberdays[0]):
    print 'safe'
if int(numberdays[2])-int(numberdays[1])<=0:
    print 'delicious'
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
flag = [0]*9
ans = 0
ans_max =0
for i in range(N):
    num = a[i]//400
    if num>=8:
        flag[num]+=1
    else:
        flag[num]=1
ans = sum(flag[:-1])
if ans + flag[8]>=8:
    ans_sum = 8
else: 
    ans_sum= ans+flag[8]
    
print(ans, ans_sum)

Fixed submission:
# coding: utf-8

N = int(input())
a = list(map(int, input().split()))
flag = [0]*9
ans = 0
ans_max =0
for i in range(N):
    num = a[i]//400
    if num>=8:
        flag[8]+=1
    else:
        flag[num]=1
ans = sum(flag[:-1])
if ans == 0:
    ans =1
    ans_sum = flag[8]
else: 
    ans_sum= ans+flag[8]
    
print(ans, ans_sum)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
flag = [0]*9
ans = 0
ans_max =0
for i in range(N):
    num = a[i]//400
    if num>8:
        flag[num]+=1
    else:
        flag[num]=1
ans = sum(flag[:-1])
if flag[8]>8:
    ans_sum = ans + 8
else:
    ans_sum = ans + flag[8]
    
print(ans, ans_sum)

Fixed submission:
# coding: utf-8

N = int(input())
a = list(map(int, input().split()))
flag = [0]*9
ans = 0
ans_max =0
for i in range(N):
    num = a[i]//400
    if num>=8:
        flag[8]+=1
    else:
        flag[num]=1
ans = sum(flag[:-1])
if ans == 0:
    ans =1
    ans_sum = flag[8]
else: 
    ans_sum= ans+flag[8]
    
print(ans, ans_sum)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
flag = [0]*9
ans = 0
ans_max =0
for i in range(N):
    num = int(a[i]/400)
    flag[num]+=1
for i in range(len(flag)-1):
    if flag[i]>=1:
        ans += 1
if flag[8]>8:
    ans_sum = ans + 8
else:
    ans_sum = ans + flag[8]
    
print(ans, ans_sum)

Fixed submission:
# coding: utf-8

N = int(input())
a = list(map(int, input().split()))
flag = [0]*9
ans = 0
ans_max =0
for i in range(N):
    num = a[i]//400
    if num>=8:
        flag[8]+=1
    else:
        flag[num]=1
ans = sum(flag[:-1])
if ans == 0:
    ans =1
    ans_sum = flag[8]
else: 
    ans_sum= ans+flag[8]
    
print(ans, ans_sum)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
flag = [0]*9
ans = 0
ans_max =0
for i in range(N):
    num = int(a[i]/400)
    flag[num]+=1
for i in range(len(flag)-1):
    if flag[i]>=1:
        ans += 1
if flag[8]>8:
    ans_sum = ans + 8
else:
    ans_sum = ans + flag[8]
    
print(ans, ans_sum)

Fixed submission:
# coding: utf-8

N = int(input())
a = list(map(int, input().split()))
flag = [0]*9
ans = 0
ans_max =0
for i in range(N):
    num = a[i]//400
    if num>=8:
        flag[8]+=1
    else:
        flag[num]=1
ans = sum(flag[:-1])
if ans == 0:
    ans =1
    ans_sum = flag[8]
else: 
    ans_sum= ans+flag[8]
    
print(ans, ans_sum)
Buggy python submission (verdict: Runtime Error):
def solve(n):
    if n==0:
        return 1
    else:
        return n*solve(n-1)
    
N = int(input())
print(solve(N)%(10**9+7))

Fixed submission:
def solve(n):
    ans = 1 
    for i in range(n):
        ans = (i+1)*ans%(10**9+7)
        
            
    return ans

N = int(input())
print(solve(N))

Buggy python submission (verdict: Runtime Error):
def solve(n):
    if n==0:
        return 1
    else:
        return n*solve(n-1)
    
N = int(input())
print(solve(N)%(10**9+7))

Fixed submission:
def solve(n):
    ans = 1 
    for i in range(n):
        ans = (i+1)*ans%(10**9+7)
        
            
    return ans

N = int(input())
print(solve(N))
Buggy python submission (verdict: Runtime Error):
n = int(input())
max_str = sorted(input())
for _ in range(n-1):
    s = sorted(input())
    new_max_str = []
    start_s = 0
    for i in range(len(max_str)):
        if max_str[i] > s[start_s]:
            start_s += 1
        if start_s >= len(s):
            break
        for j in range(start_s, len(s)):
            if max_str[i] <= s[j]:
                if max_str[i] == s[j]:
                    new_max_str.append(s[j])
                    start_s += 1
                break
    max_str = new_max_str.copy()

print("".join(max_str))

Fixed submission:
n = int(input())
s = []
for i in range(n):
    s.append(input())

ans = ""

INF = 1000

for c_i in range(ord('a'), ord('z')+1):
    small = INF
    c = chr(c_i)
    for i in range(n):
        cnt = s[i].count(c)
        small = min(small, cnt)
    ans += c * small

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
max_str = sorted(input())
for _ in range(n-1):
    s = sorted(input())
    new_max_str = []
    start_s = 0
    for i in range(len(max_str)):
        if max_str[i] > s[start_s]:
            start_s += 1
        for j in range(start_s, len(s)):
            if max_str[i] <= s[j]:
                if max_str[i] == s[j]:
                    new_max_str.append(s[j])
                    start_s += 1
                break
    max_str = new_max_str.copy()

print("".join(max_str))

Fixed submission:
n = int(input())
s = []
for i in range(n):
    s.append(input())

ans = ""

INF = 1000

for c_i in range(ord('a'), ord('z')+1):
    small = INF
    c = chr(c_i)
    for i in range(n):
        cnt = s[i].count(c)
        small = min(small, cnt)
    ans += c * small

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

s = input()
t = input()
q = int(input())

for i in range(q):
    a, b, c, d = map(int, input().split())
    s_check = s[(a - 1):(b)]
    t_check = t[(c - 1):(d)]
    s_counts = Counter(s_check)
    t_counts = Counter(t_check)
    s_score = (s_counts['A'] * 1 + s_counts['B'] * 2) % 3
    t_score = (t_counts['A'] * 1 + t_counts['B'] * 2) % 3
    print('YES' if s_score == t_score else 'NO')

Fixed submission:
s = input()
t = input()
q = int(input())

ss, tt = [0], [0]
for i in range(len(s)):
    ss.append(ss[i] + (1 if s[i] == 'A' else 2))
for i in range(len(t)):
    tt.append(tt[i] + (1 if t[i] == 'A' else 2))

for i in range(q):
    a, b, c, d = map(int, input().split())
    s_score = (ss[b] - ss[a-1]) % 3
    t_score = (tt[d] - tt[c-1]) % 3
    print('YES' if s_score == t_score else 'NO')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

def paint(v, d, c):
    if (v, d) in memo:
        return
    else:
        memo[(v, d)] = True
    if d == 0:
        color[v] = c
    elif d > 0:
        paint(v, d-1, c)
        for nb in graph[v]:
            paint(nb, d-1, c)

memo = {}
N, M = map(int, input().split())
color = [0] * N
graph = defaultdict(set)
for _ in range(M):
    i, j = map(int, input().split())
    graph[i-1].add(j-1)
    graph[j-1].add(i-1)
Q = int(input())
vdcs = []
for _ in range(Q):
    v, d, c = map(int, input().split())
    vdcs.append((v-1, d, c))
vdcs.reverse()

for v, d, c in vdcs:
    paint(v, d, c)

for c in color:
    print(c)

Fixed submission:
from collections import defaultdict

def paint(v, d, c):
    if color[v] == 0:
        color[v] = c
    if dp[v] >= d or d == 0:
        return
    dp[v] = d
    for nb in graph[v]:
        paint(nb, d-1, c)

N, M = map(int, input().split())
dp = [0] * N
color = [0] * N
graph = defaultdict(set)
for _ in range(M):
    i, j = map(int, input().split())
    graph[i-1].add(j-1)
    graph[j-1].add(i-1)
Q = int(input())
vdcs = []
for _ in range(Q):
    v, d, c = map(int, input().split())
    vdcs.append((v-1, d, c))
vdcs.reverse()

for v, d, c in vdcs:
    paint(v, d, c)

for c in color:
    print(c)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A, B = [], []

for i in range(n):
    A.append(input())

for i in range(m):
    B.append(input())

def is_contain(i, b_pos):
    containing = True
    for a_i in range(i+1, i+m):
        if A[a_i][b_pos:(b_pos+len(B))] != B[a_i]:
            containing = False
    return containing

if n < m or len(A) < len(B):
    print("No")
    exit()

for i in range(n - m + 1):
    lineA = A[i]
    lineB = B[i%m]
    lineB_pos = lineA.find(lineB)
    if lineB_pos >= 0:
        if is_contain(i, lineB_pos):
            print("Yes")
            exit()

print("No")

Fixed submission:
n, m = map(int, input().split())
A, B = [], []

for i in range(n):
    A.append(input())

for i in range(m):
    B.append(input())

def is_contain(i, b_pos):
    containing = True
    for k in range(1, m):
        if A[i+k][b_pos:(b_pos+len(B))] != B[k]:
            containing = False
    return containing

if n < m or len(A) < len(B):
    print("No")
    exit()

for i in range(n - m + 1):
    lineA = A[i]
    lineB = B[0]
    lineB_pos = lineA.find(lineB)
    if lineB_pos >= 0:
        if is_contain(i, lineB_pos):
            print("Yes")
            exit()

print("No")
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())

cnt = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x + y + z == s:
                cnt += 1
print(cnt)

Fixed submission:
k, s = map(int, input().split())

cnt = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= s - x - y <= k:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
res = 1

for i in a:
    b[i] += 1

if n % 2 == 1:
    if b[0] != 1:
        print(0)
        exit(2)
    else:
        for i in range(2, n, 2):
            if b[i] != 2:
                print(0)
                exit(3)
            #print(res)
            res = res * 2 % (10**9 + 7)
else:
    for i in range(1, n, 2):
        if b[i] != 2:
            print(0)
            exit(4)
        res = res * 2 % (10 ** 9 + 7)
print(res)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
res = 1

for i in a:
    b[i] += 1

if n % 2 == 1:
    if b[0] != 1:
        print(0)
        exit(0)
    else:
        for i in range(2, n, 2):
            if b[i] != 2:
                print(0)
                exit(0)
            #print(res)
            res = res * 2 % (10**9 + 7)
else:
    for i in range(1, n, 2):
        if b[i] != 2:
            print(0)
            exit(0)
        res = res * 2 % (10 ** 9 + 7)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding:utf-8 -*-
import sys
l = [int(i) for i in sys.stdin]
used = []
add = used.append
now = 1
count = 0
while True:
  if now == 2:
    break
  if now in used:
    print(-1)
    exit()
  add(now)
  now = l[now]
  count += 1
print(count)

Fixed submission:
# -*- coding:utf-8 -*-
import sys
button = [int(i) for i in sys.stdin]
now = 1
count = 0
for i in range(button[0]):
  if now == 2:
    print(count)
    exit()
  now = button[now]
  count += 1
print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding:utf-8 -*-
import sys
l = [int(i) for i in sys.stdin]
used = []
now = 1
count = 0
while True:
  if now == 2:
    break
  if now in used:
    print(-1)
    exit()
  used.append(now)
  now = l[now]
  count += 1
print(count)

Fixed submission:
# -*- coding:utf-8 -*-
import sys
button = [int(i) for i in sys.stdin]
now = 1
count = 0
for i in range(button[0]):
  if now == 2:
    print(count)
    exit()
  now = button[now]
  count += 1
print(-1)