Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict
r=sys.stdin.readline
X,Y=map(int,r().split())
#a=X-2b, b=Y-2a
sys.setrecursionlimit(10**6)
if (X+Y)%3!=0:
    print(0)
    exit(0)   
a=(2*Y-X)//3
b=(2*X-Y)//3
MOD=10**9+7
N=10**6
#permutation with repetition
#ex) ab, ba --> a+bCa
def pow(a,b):
    ans=1
    while b:
        if b&1:
            ans=(ans*a)%MOD
        a=(a**2)%MOD
        b=b//2
    return ans 
N=a+b
K=a
fac=[1 for _ in range(N+1)]
for i in range(2,N+1):
    fac[i]=(fac[i-1]*i)%MOD
A=fac[N]
B=(fac[N-K]*fac[K])%MOD
print((A%MOD)*pow(B,MOD-2)%MOD)



Fixed submission:
import sys
r=sys.stdin.readline
X,Y=map(int,r().split())
#a=X-2b, b=Y-2a
if 2*X-Y<0 or (2*X-Y)%3!=0 or 2*Y-X<0 or (2*Y-X)%3!=0:
    print(0)
    exit(0)   
a=(2*Y-X)//3
b=(2*X-Y)//3
MOD=10**9+7
#ex) ab, ba --> a+bCa
def pow(a,b):
    ans=1
    while b:
        if b&1:
            ans=(ans*a)%MOD
        a=(a**2)%MOD
        b=b//2
    return ans 
N=a+b
K=a
fac=[1 for _ in range(N+1)]
for i in range(2,N+1):
    fac[i]=(fac[i-1]*i)%MOD
A=fac[N]
B=(fac[N-K]*fac[K])%MOD
print((A%MOD)*pow(B,MOD-2)%MOD)

Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict
r=sys.stdin.readline
X,Y=map(int,r().split())
#a=X-2b, b=Y-2a
sys.setrecursionlimit(10**6)
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
    print(0)
    exit(0)   
a=(2*Y-X)//3
b=(2*X-Y)//3
MOD=10**9+7
N=10**6
#permutation with repetition
#ex) ab, ba --> a+bCa
def pow(a,b):
    ans=1
    while b:
        if b&1:
            ans=(ans*a)%MOD
        a=(a**2)%MOD
        b=b//2
    return ans 
N=a+b
K=a
fac=[1 for _ in range(N+1)]
for i in range(2,N+1):
    fac[i]=(fac[i-1]*i)%MOD
A=fac[N]
B=(fac[N-K]*fac[K])%MOD
print((A%MOD)*pow(B,MOD-2)%MOD)



Fixed submission:
import sys
r=sys.stdin.readline
X,Y=map(int,r().split())
#a=X-2b, b=Y-2a
if 2*X-Y<0 or (2*X-Y)%3!=0 or 2*Y-X<0 or (2*Y-X)%3!=0:
    print(0)
    exit(0)   
a=(2*Y-X)//3
b=(2*X-Y)//3
MOD=10**9+7
#ex) ab, ba --> a+bCa
def pow(a,b):
    ans=1
    while b:
        if b&1:
            ans=(ans*a)%MOD
        a=(a**2)%MOD
        b=b//2
    return ans 
N=a+b
K=a
fac=[1 for _ in range(N+1)]
for i in range(2,N+1):
    fac[i]=(fac[i-1]*i)%MOD
A=fac[N]
B=(fac[N-K]*fac[K])%MOD
print((A%MOD)*pow(B,MOD-2)%MOD)
Buggy python submission (verdict: Runtime Error):
n = int(input())
sn = input()
sr = ''.join(list(reversed(sn)))
sint = int(sn, 2)
spop = sn.count('1')

def f(x):
    count = 0
    while x != 0:
        count += 1
        pop = bin(x).count('1')
        x %= pop
    return count



m1 = sint % (spop + 1)
m2 = 0 if spop <= 1 else sint % (spop - 1)

a = [0] * n
for i in range(n):
    if sr[i] == '0':
        d = pow(2, i, spop + 1)
        m = (m1 + d) % (spop + 1)
    else:
        d = pow(2, i, spop - 1)
        m = (m2 - d + spop - 1) % (spop - 1)
    a[i] = f(m) + 1

for ans in reversed(a):
    print(ans)


Fixed submission:
n = int(input())
sn = input()
sr = ''.join(list(reversed(sn)))
sint = int(sn, 2)
spop = sn.count('1')

def f(x):
    count = 0
    while x != 0:
        count += 1
        pop = bin(x).count('1')
        x %= pop
    return count



m1 = sint % (spop + 1)
m2 = 0 if spop <= 1 else sint % (spop - 1)

a = [0] * n
for i in range(n):
    if sr[i] == '0':
        d = pow(2, i, spop + 1)
        m = (m1 + d) % (spop + 1)
        a[i] = f(m) + 1
    elif spop != 1:
        d = pow(2, i, spop - 1)
        m = (m2 - d + spop - 1) % (spop - 1)
        a[i] = f(m) + 1
    else:
        a[i] = 0

for ans in reversed(a):
    print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
sn = input()
sr = ''.join(list(reversed(sn)))
sint = int(sn, 2)
spop = sn.count('1')

def f(x):
    count = 0
    while x != 0:
        count += 1
        pop = bin(x).count('1')
        x %= pop
    return count



m1 = sint % (spop + 1)
m2 = sint % (spop - 1)

a = [0] * n
for i in range(n):
    if sr[i] == '0':
        d = pow(2, i, spop + 1)
        m = (m1 + d) % (spop + 1)
    else:
        d = pow(2, i, spop - 1)
        m = (m2 - d + spop - 1) % (spop - 1)
    a[i] = f(m) + 1

for ans in reversed(a):
    print(ans)


Fixed submission:
n = int(input())
sn = input()
sr = ''.join(list(reversed(sn)))
sint = int(sn, 2)
spop = sn.count('1')

def f(x):
    count = 0
    while x != 0:
        count += 1
        pop = bin(x).count('1')
        x %= pop
    return count



m1 = sint % (spop + 1)
m2 = 0 if spop <= 1 else sint % (spop - 1)

a = [0] * n
for i in range(n):
    if sr[i] == '0':
        d = pow(2, i, spop + 1)
        m = (m1 + d) % (spop + 1)
        a[i] = f(m) + 1
    elif spop != 1:
        d = pow(2, i, spop - 1)
        m = (m2 - d + spop - 1) % (spop - 1)
        a[i] = f(m) + 1
    else:
        a[i] = 0

for ans in reversed(a):
    print(ans)
Buggy python submission (verdict: Runtime Error):
3 3 10
60 2 2 4
70 8 7 9
50 2 3 9

Fixed submission:
n,m,x=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
ans=1e15
for f in range(1<<n):
  p,c=[0]*m,0
  for i in range(n):
    if f%2:
      p=list(map(lambda x,y:x+y,p,a[i][1:]))
      c+=a[i][0]
    f//=2
  if all(p[i]>=x for i in range(m)):
    ans=min(ans,c)
print(-1 if ans>=1e15 else ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a,c=list(map(lambda x: int(x)-1,input().split())),0
for _ in range(60):
  if k%2:
    c=a[c]
  k//=2
  a=[a[a[i]]for i in range(n)]
print(c+1)

Fixed submission:
n,k=map(int,input().split())
a,c=list(map(lambda x: int(x)-1,input().split())),0
for _ in range(60):
  if k%2:
    c=a[c]
  k//=2
  a=[a[a[i]]for i in range(n)]
print(c+1)
Buggy python submission (verdict: Runtime Error):
INF=1000000000000000 # 1e15
MAX=50*50 # 2500

n,m,s=map(int,input().split())
u,v,a,b,c,d=[0]*m,[0]*m,[0]*m,[0]*m,[0]*n,[0]*n
for i in range(m):
  u[i],v[i],a[i],b[i]=map(int,input().split())
  u[i] -= 1
  v[i] -= 1
for i in range(n):
  c[i],d[i]=map(int,input().split())

dp=[[INF] * (MAX + 1) for _ in range(n)]
#dp[i][j]=k <=> 最短k分後に街iに所持銀貨j枚で行ける
dp[0][s] = 0
for _ in range(n * n):
  for i in range(n):
    for j in range(MAX + 1):
      dest = min(MAX, j + c[i])
      dp[i][dest] = min(dp[i][dest], dp[i][j] + d[i])
  for i in range(m):
    for j in range(a[i], MAX+1):
      # u[i] -> v[i]
      dp[v[i]][j - a[i]] = min(dp[v[i]][j - a[i]], dp[u[i]][j] + b[i])
      # v[i] -> u[i]
      dp[u[i]][j - a[i]] = min(dp[u[i]][j - a[i]], dp[v[i]][j] + b[i])
for i in range(1, n):
  print(min(dp[i]))


Fixed submission:
INF=1000000000000000 # 1e15
MAX=50*50 # 2500

n,m,s=map(int,input().split())
u,v,a,b,c,d=[0]*m,[0]*m,[0]*m,[0]*m,[0]*n,[0]*n
for i in range(m):
  u[i],v[i],a[i],b[i]=map(int,input().split())
  u[i] -= 1
  v[i] -= 1
for i in range(n):
  c[i],d[i]=map(int,input().split())

dp=[[INF] * (MAX + 1) for _ in range(n)]
#dp[i][j]=k <=> 最短k分後に街iに所持銀貨j枚で行ける
dp[0][min(MAX, s)] = 0
updated = True
while updated:
  updated = False
  for i in range(n):
    for j in range(MAX + 1):
      dest = min(MAX, j + c[i])
      if dp[i][j] + d[i] < dp[i][dest]:
        updated = True
        dp[i][dest] = dp[i][j] + d[i]
  for i in range(m):
    for j in range(a[i], MAX+1):
      # u[i] -> v[i]
      if dp[u[i]][j] + b[i] < dp[v[i]][j - a[i]]:
        updated = True
        dp[v[i]][j - a[i]] = dp[u[i]][j] + b[i]
      # v[i] -> u[i]
      if dp[v[i]][j] + b[i] < dp[u[i]][j - a[i]]:
        updated = True
        dp[u[i]][j - a[i]] = dp[v[i]][j] + b[i]
for i in range(1, n):
  print(min(dp[i]))
Buggy python submission (verdict: Runtime Error):
print(int(input())*6.28, end="")
for _ in range(5000000):
  print("000000000000000000000000000000000000000000000000000000000000000000", end="")


Fixed submission:
print(int(input())*6.28, end="")
for _ in range(100000):
  print("00000000000", end="")
Buggy python submission (verdict: Time Limit Exceeded):
#original submission: https://atcoder.jp/contests/abc162/submissions/11865868

MOD = 10**9 +7

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

ans = 0
gcd_equal_i = [0]*(K+1) #gcd(A) == i なるAの作り方がgcd_equal_i[i]個

for D in range(K, 0, -1):
    num_of_mul = K // D
    tmp = num_of_mul**N

    i = 2
    while D*i <= K:
        tmp -= gcd_equal_i[D*i]
        i += 1
    
    gcd_equal_i[D] = tmp
    ans += D*tmp
    ans %= MOD


print(ans)


Fixed submission:
#original submission: https://atcoder.jp/contests/abc162/submissions/11865868

MOD = 10**9 +7

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

ans = 0
gcd_equal_i = [0]*(K+1) #gcd(A) == i なるAの作り方がgcd_equal_i[i]個

for D in range(K, 0, -1):
    num_of_mul = K // D
    tmp = pow(num_of_mul, N, MOD)

    i = 2
    while D*i <= K:
        tmp -= gcd_equal_i[D*i]
        i += 1
    
    gcd_equal_i[D] = tmp
    ans += D*tmp
    ans %= MOD


print(ans)
Buggy python submission (verdict: Runtime Error):
# Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042
x= int(input())

def prime_check(num,count):
  	while True:
        while num % count == 0:
            num = num + 1
            count = 2
    	if num <= count**2:
        	print(num)
            break
        else:
          count = count + 1

if x==2 :
    print (2)
else:
    prime_check(x,2)


Fixed submission:
MAX=200000
def get_prime(x):
  is_prime = [True] * 200000
  for i in range(2,MAX):
    if is_prime[i] and i >= x:
      return i
    elif is_prime[i]:
      for j in range(2 * i, MAX, i):
        is_prime[j] = False

print(get_prime(int(input())))

Buggy python submission (verdict: Runtime Error):
# Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042
x= int(input())

def prime_check(num,count):
    while num % count == 0:
        num = num + 1
        count = 2
    if num <= count**2:
        print(num)
    else:
        prime_check(num,count+1)

if x==2 :
    print (2)
else:
    prime_check(x,2)


Fixed submission:
MAX=200000
def get_prime(x):
  is_prime = [True] * 200000
  for i in range(2,MAX):
    if is_prime[i] and i >= x:
      return i
    elif is_prime[i]:
      for j in range(2 * i, MAX, i):
        is_prime[j] = False

print(get_prime(int(input())))
Buggy python submission (verdict: Time Limit Exceeded):
t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [a[0] - b[0], a[1] - b[1]]
w = t[0] * d[0] + t[1] * d[1]
if w < 0:
    d[0] *= -1
    d[1] *= - 1
    w *= -1
if t[0] * d[0] + t[1] * d[1] == 0:
    print("infinity")
else:
    now = 0
    ans = 0
    i, last = 0, 0
    while True:
        new = now + d[i] * t[i]
        last += 1
        if (now < 0 and new > 0) or (now > 0 and new < 0) or new == 0:
            ans += 1
            last = 0
        now = new
        i = 1 - i
        if last > 2:
            break
    print(ans)


Fixed submission:
t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [a[0] - b[0], a[1] - b[1]]
w = t[0] * d[0] + t[1] * d[1]
if w < 0:
    d[0] *= -1
    d[1] *= - 1
    w *= -1
if t[0] * d[0] + t[1] * d[1] == 0:
    print("infinity")
else:
    min, max = 0, 1000000000000000
    while max - min > 1:
        mid = (min + max) // 2
        dest = w * mid
        ok = False
        for i in range(2):
            dest += d[i] * t[i]
            if dest <= 0:
                ok = True
        if ok:
            min = mid
        else:
            max = mid
    now = w * (min - 10)
    ans = 2 * (min - 10) - 1
    if ans < 0:
        ans = 0
        now = 0
    i, last = 0, 0
    while True:
        new = now + d[i] * t[i]
        last += 1
        if (now < 0 and new > 0) or (now > 0 and new < 0) or new == 0:
            ans += 1
            last = 0
        now = new
        i = 1 - i
        if last > 2:
            break
    print(ans)
Buggy python submission (verdict: Runtime Error):
buri


Fixed submission:
a,b=map(int,input().split())
if a % 2 != b % 2:
  print("IMPOSSIBLE")
else:
  print((a + b) // 2)

Buggy python submission (verdict: Runtime Error):
buri

Fixed submission:
a,b=map(int,input().split())
if a % 2 != b % 2:
  print("IMPOSSIBLE")
else:
  print((a + b) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
for _ in range(q):
  l, r = map(int, input().split())
  ans = 0
  for i in range(l - 1, r - 1, 1):
    if s[i:i+2] == 'AC':
      ans += 1
  print(ans)


Fixed submission:
n, q = map(int, input().split())
s = input()
sum = [0]
for i in range(n):
	sum += [sum[-1] + (1 if s[i : i + 2] == 'AC' else 0)]
for _ in range(q):
	l, r = map(int, input().split())
	print(sum[r-1] -sum[l-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0.0
for i in range(n):
  a, c = input().split()
  a = int(a)
  if c == 'JPY':
    ans += a
  else:
    ans += a * 380000.0
print(ans)

Fixed submission:
n = int(input())
ans = 0.0
for i in range(n):
  a, c = input().split()
  a = float(a)
  if c == 'JPY':
    ans += a
  else:
    ans += a * 380000.0
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))
ans = 0
for _ in range(100):
  streak = False
  for i in range(n):
    if h[i] > 0:
      h[i] -= 1
      if streak:
        pass
      else:
        ans += 1
        streak = True
    else:
      streak = False
print(ans)


Fixed submission:
a,b,c = map(int,input().split())
print(a*b//2)
Buggy python submission (verdict: Runtime Error):
s = map(int,input().split())
i = 1
r = [s]
while True:
  i += 1
  s = s // 2 if s % 2 == 0 else 3 * s + 1
  if s in r:
    print(i)
    break
  r += [s]

Fixed submission:
s = int(input())
i = 1
r = [s]
while True:
  i += 1
  s = s // 2 if s % 2 == 0 else 3 * s + 1
  if s in r:
    print(i)
    break
  r += [s]
Buggy python submission (verdict: Time Limit Exceeded):
MAX=2500
n,a=map(int,input().split())
x=list(map(int,input().split()))
# dp[i][j][k] := x[0:i]のカードからj枚とって合計がkとなる取り方の数
dp = [[[0] * (MAX+1) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1

for i in range(n):
  for j in range(0,n+1):
    for k in range(0, MAX+1):
      dp[i+1][j][k] += dp[i][j][k] # i番目のカードを取らない
  for j in range(0,n):
    for k in range(0, MAX+1-x[i]):
      dp[i+1][j+1][k+x[i]] += dp[i][j][k] # i番目のカードを取る

ans = 0
for i in range(1,n+1):
  ans += dp[n][i][a*i]
print(ans)


Fixed submission:
MAX=2500
n,a=map(int,input().split())
x=list(map(int,input().split()))
# dp[i][j][k] := x[0:i]のカードからj枚とって合計がkとなる取り方の数
dp = [[[0] * (MAX+1) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1

for i in range(n):
  for j in range(0,n+1):
    for k in range(0, MAX+1):
      dp[i+1][j][k] += dp[i][j][k] # i番目のカードを取らない
  for j in range(0,n):
    for k in range(0, MAX+1-x[i]):
      dp[i+1][j+1][k+x[i]] += dp[i][j][k] # i番目のカードを取る

ans = 0
for i in range(1,n+1):
  ans += dp[n][i][a*i]
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
f = [False for _ in range(n)]
f[0] = True
for i in range(m):
  x, y = map(int,input().split())
  f[y] = f[y] or f[x]
print(f.count(True))

Fixed submission:
n, m = map(int,input().split())
f = [False for _ in range(n)]
c = [1 for _ in range(n)]
f[0] = True
for i in range(m):
  x, y = map(int,input().split())
  f[y - 1] = f[y - 1] or f[x - 1]
  c[y - 1] += 1
  c[x - 1] -= 1
  if c[x - 1] == 0:
    f[x - 1] = False
ans = 0
for i in range(n):
  if f[i] and c[i] > 0:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()
L = LI()
cnt = 0

for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if len({[L[i], L[j], L[k]]}) != 3:
                continue
            Li = [L[i], L[j], L[k]]
            Li.sort()
            if Li[2] <= Li[0] + Li[1]:
                cnt += 1

print(cnt)
                
            

Fixed submission:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()
L = LI()
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            Li = [L[i], L[j], L[k]]
            if len(set(Li)) != 3:
                continue
            Li.sort()
            if Li[2] < Li[0] + Li[1]:
                cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
¥from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


k = I()
now = 0
for i in range(k):
    now = (now * 10 + 7) % k
    if now == 0:
        print(i + 1)
        exit()
print(-1)


Fixed submission:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


k = I()
now = 0
for i in range(k):
    now = (now * 10 + 7) % k
    if now == 0:
        print(i + 1)
        exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul
from decimal import Decimal

mod = 998244353
INF = 10 ** 13
sys.setrecursionlimit(2147483647)
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

n = I()
A = LI()
ret = 1
flg = 0
for a in A:
    if a == 0:
        print(0)
        exit()
    ret *= a
    if ret > 10 ** 18:
        flg = 1

if flg:
    print(-1)
else:
    print(ret)

Fixed submission:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul

mod = 10 ** 9 + 7
INF = 10 ** 13
sys.setrecursionlimit(2147483647)
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


n = I()
A = LI()
ret = 1
for i in range(n):
    if A[i] == 0:
        print(0)
        exit()

for i in range(n):
    ret *= A[i]
    if ret > 10 ** 18:
        print(-1)
        exit()

print(ret)