def solve(n, a_list, s):

    for i in range(n - 1, -1, -1):
        if s[i] == "0":
            r = 2 ** (a_list[i].bit_length() - 1)
            for j in range(i):
                if a_list[j] & r > 0:
                    a_list[j] = a_list[i] ^ a_list[j]
        else:
            if a_list[i] > 0:
                return 1
    return 0

def main():
    t = int(input())
    res_list = []
    for _ in range(t):
        n = int(input())
        a_list = list(map(int, input().split()))
        s = input()
        res = solve(n, a_list, s)
        res_list.append(res)
    for res in res_list:
        print(res)

def test():
    assert solve(2, [1, 2], "10") == 1
    assert solve(2, [1, 1], "10") == 0
    assert solve(6, [2, 3, 4, 5, 6, 7], "111000") == 0

if __name__ == "__main__":
    test()
    main()

def solve(n, a_list, s):

    for i in range(n - 1, -1, -1):
        if s[i] == "0":
            if a_list[i] == 0:
                continue
            r = 2 ** (a_list[i].bit_length() - 1)
            for j in range(i):
                if a_list[j] & r > 0:
                    a_list[j] = a_list[i] ^ a_list[j]
        else:
            if a_list[i] > 0:
                return 1
    return 0

def main():
    t = int(input())
    res_list = []
    for _ in range(t):
        n = int(input())
        a_list = list(map(int, input().split()))
        s = input()
        res = solve(n, a_list, s)
        res_list.append(res)
    for res in res_list:
        print(res)

def test():
    assert solve(2, [1, 2], "10") == 1
    assert solve(2, [1, 1], "10") == 0
    assert solve(6, [2, 3, 4, 5, 6, 7], "111000") == 0

if __name__ == "__main__":
    test()
    main()


a, b = int(input().split())
print(a * b)

a, b = map(int, input().split())
print(a * b)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s298903403.py", line 1, in <module>
    a, b = int(input().split())
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'


a, b = [*map(input().split(" "), int)]
print(a * b)

a, b = [*map(int, input().split(" "))]
print(a * b)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s795495503.py", line 1, in <module>
    a, b = [*map(input().split(" "), int)]
TypeError: 'type' object is not iterable


val1 = input()
val2 = input()

print(int(val1) * int(val2))

val1, val2 = (int(x) for x in input().split())

print(int(val1) * int(val2))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s139420322.py", line 2, in <module>
    val2 = input()
EOFError: EOF when reading a line


x, y = map(int, input().split())
print(x * y)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s474601082.py", line 2, in <module>
    print(x * y)
TypeError: can't multiply sequence by non-int of type 'str'


a = input()
b = input()

A = int(a)
B = int(b)

val = A * B

print(val)

nums = input().split()

A = int(nums[0])
B = int(nums[1])

val = A * B

print(val)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s123530671.py", line 2, in <module>
    b = input()
EOFError: EOF when reading a line


a, t = map(int, input().split())
print(a * t)
a, t = map(int, input().split())
print(a * t)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s987059931.py", line 3, in <module>
    a, t = map(int, input().split())
EOFError: EOF when reading a line


a, b = map(int, input().ssplit())
print(a * b)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s218726646.py", line 1, in <module>
    a, b = map(int, input().ssplit())
AttributeError: 'str' object has no attribute 'ssplit'. Did you mean: 'rsplit'?


A = int(input())
B = int(input())

print(A * B)

a, b = map(int, input().split())

print(a * b)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s768625073.py", line 1, in <module>
    A = int(input())
ValueError: invalid literal for int() with base 10: '2 5'


n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    m = 0
else:
    for i in a:
        m *= i
        if m > 10**18:
            m = -1
print(m)

n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    m = 0
else:
    for i in a:
        m *= i
        if m > 10**18:
            m = -1
            break
print(m)


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

for i in A:
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)

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

if 0 in A:
    ans = 0
else:
    for i in A:
        ans *= i
        if ans > 10**18:
            ans = -1
            break

print(ans)


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

ans = 1

for a in A:
    ans *= a
    if a == 0:
        print(0)
        break

else:
    if ans > 1000000000000000000:
        print(-1)
    else:
        print(ans)

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

ans = 1

if 0 in A:
    print(0)
else:
    for a in A:
        ans *= a
        if ans > 1000000000000000000:
            print(-1)
            break
    else:
        print(ans)


import sys

N = int(input().rstrip())

limit = pow(10, 18)

nums = []

nums = input().rsplit()

# for i in range(0, N - 1):
#     a = input()
#     if a == 0:
#         print(0)
#         sys.exit(1)
#     nums.append(a)

accum = 1
for num in nums:
    num = int(num)
    try:
        accum *= num
    except OverflowError:
        print(-1)
        sys.exit(1)

    if accum > limit:
        print(-1)
        sys.exit(1)

print(accum)

import sys

N = int(input().rstrip())

limit = pow(10, 18)

nums = list(input().split())

for num in nums:
    num = int(num)
    if num == 0:
        print(0)
        sys.exit(0)

accum = 1
for num in nums:
    num = int(num)
    try:
        accum *= num
    except Exception:
        accum = -1
        break

    if accum > limit:
        accum = -1
        break

print(accum)


import operator
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
ans = reduce(operator.mul, a)
print(-1 if ans > 10**18 else ans)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)

main()


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

res = 1
for a in A:
    res *= a

if 1e18 < res:
    print(-1)
else:
    print(res)

import sys

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

if 0 in A:
    print(0)
    sys.exit()

res = 1
for a in A:
    res *= a
    if 1e18 < res:
        print(-1)
        sys.exit()

print(res)


N = int(input())
anser = 1
for a in input().split(" "):
    anser = anser * int(a)

if anser > 1000000000000000000:
    print(-1)
else:
    print(anser)

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

    if 0 in A:
        print(0)
        return

    anser = 1
    for a in A:
        anser *= a
        if anser > 1000000000000000000:
            print(-1)
            return

    print(anser)

main()


n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in a:
    ans *= i
print(ans if not ans > 10**18 else -1)

n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
else:
    ans = 1
    for i in a:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
    print(ans)


n = int(input())
a = map(int, input().split())
ans = 1
for x in a:
    ans *= x

if ans > 10**18:
    print(-1)
else:
    print(ans)

import sys

input = sys.stdin.readline

def main():
    n = int(input())
    a = sorted(map(int, input().split()))
    ans = 1
    for x in a:
        ans *= x
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)

main()


N = int(input())
A = list(map(int, input().split()))
t = A[0]
i = 1
while i < N:
    t *= A[i]
    i += 1
if t <= 1e18:
    print(t)
else:
    print(-1)

# import numpy as np
N = int(input())
A = list(map(int, input().split()))
# A = np.array(A)
t = A[0]
for i in range(1, N):
    t *= A[i]
    if int(t) > 1e18:
        for j in range(i, N):
            if A[j] == 0:
                t = 0
        break
if int(t) <= 1e18:
    print(int(t))
else:
    print(-1)


# -*- coding: utf-8 -*-
# 整数の入力
# a = int(input())
# スペース区切りの整数の入力
# b, c = map(int, input().split())
# 文字列の入力
# s = input()
# 出力
# print("{} {}".format(a+b+c, s))

N = int(input())
A = list(map(int, input().split()))
answer = 1
for i in range(N):
    answer *= A[i]

if answer > 1000000000000000000:
    print(-1)
else:
    print(answer)

# -*- coding: utf-8 -*-
# 整数の入力
# a = int(input())
# スペース区切りの整数の入力
# b, c = map(int, input().split())
# 文字列の入力
# s = input()
# 出力
# print("{} {}".format(a+b+c, s))
import sys

N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    if A[i] == 0:
        print(0)
        sys.exit(0)
answer = 1
for i in range(N):
    answer *= A[i]
    if answer > 1000000000000000000:
        print(-1)
        sys.exit(0)

print(answer)


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

ans = 1
for a in A:
    ans *= a
if ans > 10**18:
    ans = -1
print(ans)

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

if A.count(0):
    print(0)
    import sys

    sys.exit()

ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        import sys

        sys.exit()

print(ans)


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

ans = 1

for i in range(n):
    ans *= a[i]

if ans > 10**18:
    print(-1)
else:
    print(ans)

import sys

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

ans = 1

for i in a:
    if i == 0:
        print(0)
        sys.exit(0)

for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        sys.exit(0)

if ans > 10**18:
    print(-1)
else:
    print(ans)


n = int(input())
li = list(map(int, input().split()))
x = 1
if 0 in li:
    print(0)
else:
    for i in li:
        x = x * i
    if x > 10**18:
        print(-1)
    else:
        print(x)

n = int(input())
li = list(map(int, input().split()))
x = 1
if 0 in li:
    print(0)
else:
    for i in li:
        x = x * i
        if x > 10**18:
            print(-1)
            exit()
    print(x)


n = int(input())
re = 1

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

for i in range(n):
    re = re * li[i]
if re > 1000000000000000000:
    print(-1)
else:
    print(re)

n = int(input())
re = 1

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

for i in range(n):
    if re > 1000000000000000000:
        break
    re = re * li[i]
if 0 in li:
    print(0)
elif re > 1000000000000000000:
    print(-1)
else:
    print(re)


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

if 0 in aa:
    print("0")
else:
    result = 1
    for a in aa:
        result *= a

    if result > pow(10, 18):
        result = -1

    print(result)

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

if 0 in aa:
    print("0")
    exit(0)

result = 1
for a in aa:
    result *= a
    if result > pow(10, 18):
        print("-1")
        exit(0)

print(result)


N = int(input())
A = [int(a) for a in input().split()]
ans = A[0]

if 0 in A:
    print(0)
    exit()

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

if ans > 10**18:
    print(-1)
else:
    print(ans)

import numpy as np

N = int(input())
A = [int(a) for a in input().split()]
ans = A[0]

if 0 in A:
    print(0)
    exit()

for i in range(1, len(A)):
    if A[i] != 1:
        ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)


N = int(input())
# = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
answer = A[0]

for i in range(1, N):
    answer *= A[i]

if answer > 10**18:
    print(-1)
else:
    print(answer)

N = int(input())
# = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
answer = A[0]

if A.count(0) > 0:
    print(0)
    exit()

for i in range(1, N):
    answer = answer * A[i]
    if answer > 10**18:
        print(-1)
        exit()
else:
    print(answer)


n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in a:
    ans *= i

if ans > 1000000000000000000:
    print(-1)
else:
    print(ans)

import sys

n = int(input())
a = list(map(int, input().split()))
ans = 1
flag = True
if 0 in a:
    print(0)
    sys.exit()

for i in a:
    ans *= i
    if ans > 1000000000000000000:
        flag = False
        break

if flag == False:
    print(-1)
else:
    print(ans)


num = int(input())

k = input().split()

mul = 1

for i in range(num):
    mul *= int(k[i])

if mul > 10**18:
    print(-1)

else:
    print(mul)

num = int(input())

k = input().split()

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

k.sort()

mul = 1

for i in range(num):
    mul *= int(k[i])
    if mul > 10**18:
        break

if mul > 10**18:
    print(-1)

else:
    print(mul)


n = int(input())
mod = 10**18
li = list(map(int, input().split())).sort()
ans = 1
for i in range(n):
    ans = ans * li[i]
    if ans > mod:
        ans = -1
        break
print(ans)

n = int(input())
mod = 10**18
li = list(map(int, input().split()))
li.sort()
ans = 1
for i in range(n):
    ans *= li[i]
    if ans > mod:
        ans = -1
        break
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02658/Python/s150876238.py", line 6, in <module>
    ans = ans * li[i]
TypeError: 'NoneType' object is not subscriptable


N = int(input())
A = list(map(int, input().split()))
result = 1
flag = 0
for a in A:
    if a == 0:
        zero_flag = 1
        result = 0
        break
    else:
        result = result * a
        if result > pow(10, 18):
            flag = 1
            result = 0
if flag == 1 and zero_flag != 1:
    print(-1)
else:
    print(result)

N = int(input())
A = list(map(int, input().split()))
result = 1
flag = 0
zero_flag = 0
for a in A:
    if a == 0:
        zero_flag = 1
        result = 0
        break
    else:
        result = result * a
        if result > pow(10, 18):
            flag = 1
            result = 0
if flag == 1 and zero_flag != 1:
    print(-1)
else:
    print(result)


def main():
    ans = 1
    for a in A:
        ans *= a
    if ans > L:
        print(-1)
    else:
        print(ans)

if __name__ == "__main__":
    N = int(input())
    A = [int(a) for a in input().split()]
    L = 10**18
    main()

def main():
    if A.count(0) >= 1:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > L:
            print(-1)
            return
    print(ans)

if __name__ == "__main__":
    N = int(input())
    A = [int(a) for a in input().split()]
    L = 10**18
    main()


N = int(input())
an = list(map(int, input().split()))
ans = 1
for a in an:
    if 0 in an:
        ans = 0
        break
    ans *= a
    if ans > 10**18:
        ans = -1
        break
print(ans)

N = int(input())
an = list(map(int, input().split()))
ans = 1
if 0 in an:
    ans = 0
else:
    for a in an:
        ans *= a
        if ans > 10**18:
            ans = -1
            break
print(ans)


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

ans = 1

for a in A:
    ans *= a
if ans > pow(10, 18):
    ans = -1
print(ans)

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

ans = 1

if 0 in A:
    ans = 0
else:
    for a in A:
        ans *= a
        if ans > pow(10, 18):
            ans = -1
            break
print(ans)


n = int(input())
ret = 1
a = list(map(int, input().split()))
for ai in a:
    ret *= ai
if ret > 1000000000000000000:
    print(-1)
else:
    print(ret)

n = int(input())
ret = 1
a = sorted(list(map(int, input().split())))
for ai in a:
    ret *= ai
    if ret > 1000000000000000000:
        print(-1)
        exit(0)
print(ret)


from functools import reduce
from operator import mul

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

if 0 in a_li:
    print(0)
    exit()

a_li = [a for a in a_li if a != 1 and a != 0]
a_li.append(1)
ans = reduce(mul, a_li)

if ans > 1000000000000000000:
    print(-1)
    exit()
else:
    print(ans)

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

if 0 in a_li:
    print(0)
    exit()

ans = 1
a_li = [a for a in a_li if a != 1 and a != 0]
a_li.append(1)
for a in a_li:
    ans *= a
    if ans > 1000000000000000000:
        print(-1)
        exit()
print(ans)


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

sum = 1
for i in A:
    sum *= i

ans = -1

if sum <= 10**18:
    ans = sum

print(ans)

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

A.sort()

sum = 1
for i in A:
    sum *= i
    if sum > 10**18:
        sum = -1
        break

ans = sum

print(ans)


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

mul = 1
for i in range(N):
    mul *= A[i]

if mul > 10**18:
    print("-1")

else:
    print(mul)

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

# print(A)

A.sort()
# print(A)

mul = 1
for i in range(N):
    if mul == 0:
        break
    elif mul > 10**18:
        mul = -1
        break
    else:
        mul *= A[i]

if mul > 10**18:
    print("-1")
else:
    print(mul)


n = int(input())
A = list(map(int, input().split()))
ans = 1
flag = 0
zeroflag = 0
for a in A:
    ans *= a
    if ans > pow(10, 18):
        flag = 1
    if a == 0:
        zeroflag = 1
if flag:
    ans = -1
if zeroflag:
    ans = 0
print(ans if ans <= pow(10, 18) else -1)

n = int(input())
A = list(map(int, input().split()))
ans = 1
flag = 0
zeroflag = 0
for a in A:
    if a == 0:
        print(0)
        exit()
for a in A:
    ans *= a
    if ans > pow(10, 18):
        print(-1)
        exit()
print(ans)


# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]

ans = 1
for i in range(n):
    ans *= a[i]
if ans > pow(10, 18):
    print(-1)
else:
    print(ans)

# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]

ans = 1
a.sort()
for i in range(n):
    ans *= a[i]
    # print(ans)
    if ans > pow(10, 18):
        print(-1)
        exit()
print(ans)


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

if 0 in a:
    print(0)
    exit()

ans = 1
for num in a:
    ans = ans * num

if ans > 10**18:
    print(-1)
else:
    print(ans)

import collections
import sys

def pow2(x, n):
    ret = 1
    while n > 0:
        if n & 1:
            ret *= x
        x *= x
        n = n >> 1
    return ret

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

if 0 in a:
    print(0)
    sys.exit(0)

c = collections.Counter(a)

l = sorted(list(c.keys()))

ans = 1
for num in l:
    ans *= pow2(num, c[num])
    if ans > 1000000000000000000:
        print(-1)
        sys.exit(0)
print(ans)


t = int(input())
arr = [int(x) for x in input().split()]
n = 1
flag = True
for i in range(t):
    n *= arr[i]
    if n > 10**18:
        flag = False
    else:
        flag = True
if flag:
    print(n)
else:
    print(-1)

t = int(input())
arr = [int(x) for x in input().split()]
n = 1
flag = True
if 0 in arr:
    print(0)
else:
    for i in range(t):
        n *= arr[i]
        if n > 10**18:
            flag = False
            break
    if flag:
        print(n)
    else:
        print(-1)


n = int(input())

ans = 1

for e in map(int, input().split()):
    ans *= e

if ans > 10**18:
    print(-1)
else:
    print(ans)

n = int(input())

a = [*map(int, input().split())]
for e in a:
    if e == 0:
        print(0)
        exit(0)

ans = 1
for e in a:
    ans *= e
    if ans > 10**18:
        print(-1)
        exit(0)

print(ans)


import sys

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

ans = 1

for a in A:
    if a == 0:
        print(0)
        sys.exit()
    ans *= a

if 10**18 < ans:
    print(-1)
else:
    print(ans)

import sys

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

ans = 1

for a in A:
    if a == 0:
        print(0)
        sys.exit()

for a in sorted(A, reverse=True):
    ans *= a
    if 10**18 < ans:
        print(-1)
        sys.exit()

print(ans)


N = int(input())
A = input().split()
i = 0
S = 1
for i in range(N):
    S *= int(A[i])
if S > 10**18:
    print(-1)
else:
    print(S)

N = int(input())
A = input().split()
S = 1
if "0" in A:
    print(0)
else:
    for i in range(N):
        S *= int(A[i])
        if S > 10**18:
            break
    if S > 10**18:
        print(-1)
    else:
        print(S)


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

ans = 1
flag = 0
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        flag = 1

if flag == 1 and ans != 0:
    ans = -1

print(ans)

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

ans = 1
flag = 0
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        flag = 1
        break

if flag == 1 and (0 not in a):
    ans = -1
if 0 in a:
    ans = 0

print(ans)


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

ans = 1
for i in a:
    ans *= i

if ans > 10**18:
    print(-1)
else:
    print(ans)

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

if 0 in a:
    print(0)
    exit(0)

ans = 1
for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit(0)

print(ans)


N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in range(N):
    ans *= A[i]
if ans > 10**18:
    ans = -1
print(ans)

N = int(input())
A = list(map(int, input().split()))
ans = 1
A.sort()
if A[0] == 0:
    print(0)
else:
    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            print(-1)
            exit(0)
    print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)

n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)


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

ans = 1

for x in range(n):
    if 0 in a:
        ans = 0
        break

    ans *= a[x]

    if ans > 10**18:
        ans = -1
        break

print(ans)

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

ans = 1

a.sort(reverse=True)

if 0 not in a:
    for x in range(n):
        ans *= a[x]

        if ans > 10**18:
            ans = -1
            break
else:
    ans = 0

print(ans)


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

if 0 in A:
    print(0)
else:
    ans = 1
    for i in range(A):
        ans += A[i]
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)

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

if 0 in A:
    print(0)
else:
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02658/Python/s912887919.py", line 8, in <module>
    for i in range(A):
TypeError: 'list' object cannot be interpreted as an integer


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

ans = A[0]
for i in range(1, N):
    ans *= A[i]
if ans > 10**18:
    print(-1)
    exit()
print(ans)

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

if 0 in A:
    print(0)
    exit()

ans = A[0]
for i in range(1, N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)


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

ans = 1
for a in A:
    ans *= a

if ans > 10**18:
    print(-1)
else:
    print(ans)

import sys
import numpy as np

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

if len(np.where(np.array(A) == 0)[0]) != 0:
    print(0)
    sys.exit(0)

ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        sys.exit(0)

print(ans)


n = int(input())

ans = 1
flag = True
a = list(map(int, input().split()))
for i in a:
    ans *= i
    if ans > 1000000000000000000:
        flag = False

if ans == 0:
    flag = True

if flag:
    print(ans)
else:
    print(-1)

n = int(input())

ans = 1
flag = True
a = list(map(int, input().split()))

a.sort()

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

for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit(0)

print(ans)


N = int(input())
A = [int(x) for x in input().split()]
ans = 1
for x in A:
    ans *= x
if ans > 10**18:
    print(-1)
else:
    print(ans)

N = int(input())
A = [int(x) for x in input().split()]
if 0 in A:
    print(0)
    exit()
ans = 1
for x in A:
    ans *= x
    if ans > 10**18:
        print(-1)
        exit()
print(ans)


import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n = int(readline())
a = list(map(int, readline().split()))

t = 1

for i in range(n):
    t = t * a[i]

if t > 10**18:
    print("-1")
else:
    print(t)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n = int(readline())
a = list(map(int, readline().split()))

t = 1

for i in range(n):
    if a[i] == 0:
        print("0")
        exit()

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

print(t)


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

x = 1
for i in a:
    x *= i

ans = x
if ans > 10**18:
    ans = -1
print(ans)

n = int(input())
a = list(map(int, input().split()))
a.sort()

x = 1
for i in a:
    x *= i
    if x > 10**18:
        break

ans = x
if ans > 10**18:
    ans = -1
print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 1
if a.count(0) > 0:
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)


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

product = 1

for i in range(N):
    product *= A[i]

if product > 1000000000000000000:
    print(-1)
else:
    print(product)

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

product = 1
flag = 0

if 0 in A:
    print(0)
else:
    for i in range(N):
        product *= A[i]
        if product > 1000000000000000000:
            flag += 1
            break
    if flag == 0:
        print(product)
    else:
        print(-1)


from functools import reduce

A = int(input())
lst = [int(x) for x in input().split()]
res = reduce(lambda a, b: a * b, lst)
print(res if res <= pow(10, 18) else -1)

res = 1

A = int(input())
N = sorted([int(x) for x in input().split()])

for x in N:
    res *= x
    if res > pow(10, 18):
        res = -1
        break

print(res)


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

ans = 1
for i in range(N):
    ans *= A[i]

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

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

ans = 1

if 0 in A:
    print(0)
    exit()

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

print(ans)


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

ans = 1
for a in A:
    ans *= a

if ans > 10**18:
    ans = -1

print(ans)

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

ans = 1
if 0 in A:
    ans = 0
else:
    for a in A:
        ans *= a
        if ans > 10**18:
            ans = -1
            break

print(ans)


n = int(input())
a = [int(v) for v in input().split()]
ans = 1
num = 1
limit = 1000000000000000000
for i in a:
    if i == 0:
        num = 0
        break
    if i >= limit:
        num = -1
        break
    else:
        num *= i
if num > limit:
    num = -1
ans = num
print(ans)

n = int(input())
a = [int(v) for v in input().split()]
limit = 1000000000000000000
if 0 in a:
    print(0)
else:
    ans = 1
    num = 1
    for i in a:
        num *= i
        if num > limit:
            num = -1
            break
    ans = num
    print(ans)


N = int(input())
A = list(map(int, input().split()))
answer = 1
for i in range(len(A)):
    answer *= A[i]

if answer <= 1000000000000000000:
    print(answer)
else:
    print(-1)

N = int(input())
A = list(map(int, input().split()))
answer = 1
if 0 in A:
    print(0)
    exit()

for i in range(len(A)):
    if len(str(answer)) + len(str(A[i])) <= 20:
        answer *= A[i]
    else:
        print(-1)
        exit()

if answer <= 1000000000000000000:
    print(answer)
else:
    print(-1)


n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in a:
    ans *= i

if ans > 10**18:
    ans = -1

print(ans)

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

for i in a:
    if i == 0:
        print(0)
        exit()

ans = 1
for i in a:
    ans *= i
    if ans > 10**18:
        ans = -1
        break

print(ans)


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

ans = 1

for e in num_list:
    ans *= e

if ans > 1000000000000000000:
    print("-1")
else:
    print(ans)

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

ans = 1

for e in num_list:
    if e == 0:
        ans = 0

for e in num_list:
    ans *= e
    if ans > 1000000000000000000:
        ans = -1
        break
    if ans == 0:
        break

print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
if ans > 1000000000000000000:
    print(-1)
else:
    print(ans)

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        print(-1)
        exit(0)
print(ans)


import sys

n = int(input())

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

ans = 1

for i in range(n):
    ans *= a[i]

if ans > 10**18:
    print(-1)
    sys.exit()

print(ans)

import sys

n = int(input())

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

ans = 1

if 0 in a:
    print(0)
    sys.exit()

for i in a:
    ans *= i

    if ans > 10**18:
        print(-1)
        sys.exit()

print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
if ans > pow(10, 18):
    print("-1")
else:
    print(ans)

n = int(input())
a = list(map(int, input().split()))
ans = 1
a.sort()
if a[0] == 0:
    print(0)
    exit()

for i in range(n):
    ans *= a[i]
    if ans > pow(10, 18):
        print(-1)
        exit()
else:
    print(ans)


n = int(input())
lis = list(map(int, input().split()))
res = 1
for i in lis:
    res *= i
print(res if res <= 10**18 else -1)

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

if 0 in lis:
    print(0)
    exit()

res = 1
for i in lis:
    if res > 10**18:
        print(-1)
        exit()
    else:
        res *= i
print(res if res <= 10**18 else -1)


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

sum = A[0]
for i in range(1, N):
    sum = sum * A[i]
if sum <= 10**18:
    print(sum)
else:
    print(-1)

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

t = 10**18
if 0 in A:
    print(0)
else:
    sum = A[0]
    flag = True
    for i in range(1, N):
        sum = sum * A[i]
        if sum > t:
            flag = False
            break
    if flag:
        print(sum)
    else:
        print(-1)


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

if 0 in A:
    print(0)

else:
    total = 1
    for i in range(N):
        total *= A[i]

    if total > 10**18:
        print(-1)
    else:
        print(total)

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

if 0 in A:
    print(0)

else:
    total = 1
    for i in range(N):
        total *= A[i]
        if total > 10**18:
            total = -1
            break
    print(total)


# coding:utf-8
n = int(input())
a = list(map(int, input().split()))
ans = 1

for i in range(n):
    ans = ans * a[i]

if ans > 10**18:
    print(-1)
else:
    print(ans)

# coding:utf-8
n = int(input())
a = list(map(int, input().split()))
ans = 1

if 0 in a:
    print(0)
    exit()

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

print(ans)


N = int(input())
a = [int(x) for x in input().split()]

X = 1
for i in range(N):
    X = X * a[i]

if X > 1000000000000000000:
    print("-1")
else:
    print(X)

N = int(input())
a = [int(x) for x in input().split()]

X = 1

for i in range(N):
    if a[i] == 0:
        X = 0

if X == 1:
    for i in range(N):
        X = X * a[i]
        if X > 1000000000000000000:
            X = -1
            break

print(X)


# import numpy as np

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

result = 1

for i in range(0, n):
    result = result * a[i]

# result = np.prod(a)

if result > pow(10, 18):
    result = -1

print(result)

n = int(input())
a = list(map(int, input().split()))
a.sort()
result = 1

for i in a:
    result = result * i

    # result = np.prod(a)

    if result > pow(10, 18):
        result = -1
        break

print(result)


#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

    ans = A[0]
    for i in range(1, N):
        ans *= A[i]

    print(-1 if ans > 10**18 else ans)

if __name__ == "__main__":
    main()

#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

    A.sort(reverse=True)

    if 0 in A:
        print(0)
        exit()

    ans = A[0]
    for i in range(1, N):
        ans *= A[i]
        if ans > 10**18:
            print(-1)
            exit()

    print(ans)

if __name__ == "__main__":
    main()


N = int(input())
A = [int(i) for i in input().split()]

ans = 1
for i in range(N):
    ans *= A[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)

N = int(input())
A = sorted([int(i) for i in input().split()])

if A[0] == 0:
    print(0)
    exit()
else:
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)


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

r = 1
for a in A:
    r *= a

if r > pow(10, 18):
    print(-1)
else:
    print(r)

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

A.sort(reverse=True)

for i in range(N - 1, -1, -1):
    if A[i] == 0:
        print(0)
        exit()

r = 1
upper = pow(10, 18)
for i in range(N):
    r *= A[i]

    if r > upper:
        print(-1)
        exit()

print(r)


n = int(input())

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

res = 1

for i in range(n):
    res *= a[i]

    if a[i] == 0:
        break

if res > 10**18:
    print(-1)
else:
    print(res)

n = int(input())

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

res = 1

if 0 in a:
    print(0)
else:
    for i in range(n):
        res *= a[i]

        if a[i] == 0:
            break
        if res > 10**18:
            print(-1)
            break

    if res > 10**18:
        pass
    else:
        print(res)


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

ans = 1
for a in A:
    ans *= a

if ans > 1000000000000000000:
    print(-1)
else:
    print(ans)

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

ans = 1
for a in A:
    ans *= a
    if ans > 1000000000000000000:
        break

if 0 in A:
    print(0)
elif ans > 1000000000000000000:
    print(-1)
else:
    print(ans)


n = map(int, input().split())
a = map(int, input().split())
ans = 1
for i in a:
    ans *= i

print(ans if ans <= 10**18 else -1)

n = map(int, input().split())
a = list(map(int, input().split()))
ans = 1
flag = True if 0 in a else False

if flag:
    print(0)
    exit()

for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit()

print(ans)


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

ans = 1
for i in range(n):
    ans *= a[i]

print(ans if ans <= 1000000000000000000 else -1)

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

ans = 1

if 0 in a:
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        print(-1)
        exit()

print(ans)


def main():
    n = int(input())
    As = list(map(int, input().split()))

    ans = 1
    for i in range(n):
        ans *= As[i]
        if ans == 0:
            break

    if ans > 10**18:
        ans = -1

    print(ans)

if __name__ == "__main__":
    main()

def main():
    n = int(input())
    As = list(map(int, input().split()))

    ans = 1
    if 0 in As:
        print(0)
        exit()

    for i in range(n):
        ans *= As[i]
        if ans > 10**18:
            ans = -1
            break

    print(ans)

if __name__ == "__main__":
    main()


_ = input()
inp = map(int, input().split())

of = False
re = 1

for a in inp:
    re *= a

if (re - 1) // (10**18) > 0:
    re = -1

print(re)

_ = input()
inp = list(map(int, input().split()))

re = 1

for a in inp:
    re = re * a
    if re > (10**18):
        of = True
        re = -1
        break

for a in inp:
    if a == 0:
        re = 0

print(re)


n = int(input())
a = list(map(int, input().split()))
n = 1
for i in a:
    n *= i
if n > 10**18:
    n = -1
print(n)

def main():

    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    ans = 1
    for i in A:
        ans *= i
        if ans > 1000000000000000000:
            print(-1)
            return
    print(ans)

main()


import sys

n = int(input())
list_input = list(map(int, sys.stdin.readline().strip().split()))

if 0 in list_input:
    print(0)
    exit()

a = 1
for i in list_input:
    a *= i

if a > pow(10, 18):
    print(-1)
else:
    print(a)

import sys

n = int(input())
list_input = list(map(int, sys.stdin.readline().strip().split()))

if 0 in list_input:
    print(0)
    exit()

a = 1
for i in list_input:
    a *= i
    if a > pow(10, 18):
        break

if a > pow(10, 18):
    print(-1)
else:
    print(a)


N = int(input())
sum = 1
for num in input().split():
    sum *= int(num)
    if sum == 0:
        print(0)
        exit()
if len(str(sum)) > 19:
    print(-1)
    exit()
elif len(str(sum)) == 19:
    if str(sum).count("1") == 1 and str(sum).count("0") == 18:
        pass
    else:
        print(-1)
        exit()
print(sum)

N = int(input())
sum = 1
keta = 0

numbers = input().split()
if not ("0" in numbers):
    for num in numbers:
        keta += len(num) - 1
        if keta > 19:
            print(-1)
            exit()
        sum *= int(num)
        if len(str(sum)) > 19:
            print(-1)
            exit()

    if len(str(sum)) == 19:
        if str(sum).count("1") == 1 and str(sum).count("0") == 18:
            pass
        else:
            print(-1)
            exit()
else:
    print(0)
    exit()
print(sum)


import sys

N = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
    if a == 0:
        print(0)
        sys.exit()
    ans *= a

if ans > 10**18:
    print(-1)
else:
    print(ans)

import sys

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

if 0 in A:
    print(0)
    sys.exit()

ans = 1
for a in sorted(A, reverse=True):
    ans *= a
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)


N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in A:
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)

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

if 0 in A:
    print(0)
    exit()

ans = 1
for i in A:
    ans *= i
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)


n = int(input())
a = list(map(int, input().split()))
result = 1
for i in a:
    result *= i
    if i == 0:
        break
if result > 10**18:
    print(-1)
else:
    print(result)

n = int(input())
a = list(map(int, input().split()))
result = 1
overflow = False
for i in a:
    result *= i
    if result > 1e18:
        result = 1
        overflow = True
if result != 0 and overflow:
    print(-1)
else:
    print(result)


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

ans = 1
for i in a:
    ans *= i
if ans > 1000000000000000000:
    print(-1)
else:
    print(ans)

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

if 0 in a:
    print(0)
else:
    ans = 1
    for i in a:
        ans *= i
        if ans > 1000000000000000000:
            print(-1)
            exit()
    if ans > 1000000000000000000:
        print(-1)
    else:
        print(ans)


n = int(input())
li = [int(x) for x in input().split()]
ans = 1
for i in range(n):
    ans = ans * li[i]
if ans > 1000000000000000000:
    print("-1")
else:
    print(ans)

n = int(input())
li = [int(x) for x in input().split()]
ans = 1
if 0 in li:
    print("0")
else:
    for i in range(n):
        ans = ans * li[i]
        if ans > 1000000000000000000:
            print("-1")
            exit()
    print(ans)


n = int(input())
a = map(int, input().split())

maxn = 10**18
ans = 1
for k in a:
    ans *= k

if ans > maxn:
    ans = -1

print(ans)

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

for k in a:
    if k == 0:
        print(0)
        exit()

maxn = 10**18
ans = 1
for k in a:
    ans *= k
    if ans > maxn:
        ans = -1
        break

print(ans)


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

inf = 10**18
ans = 1

sorted(a, reverse=True)
if 0 in a:
    ans = 0
else:
    for i in a:
        ans *= i

print(ans if ans <= inf else -1)

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

inf = 10**18
ans = 1

sorted(a, reverse=True)
if 0 in a:
    print(0)
    exit()
else:
    for i in a:
        ans *= i
        if ans > inf:
            print(-1)
            exit()

print(ans)


_ = input()
a = list(map(int, input().split()))

result = 1
for a_i in a:
    result *= a_i

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

def main():
    _ = input()
    a = list(map(int, input().split()))

    result = 1
    for a_i in a:
        if a_i == 0:
            return 0

    for a_i in a:
        result *= a_i

        if 10**18 < result:
            return -1

    return result

if __name__ == "__main__":
    result = main()
    print(result)


N = int(input())
A = [int(a) for a in input().split()]
ans = 1
for i in A:
    ans *= i
if ans <= 10**18:
    print(ans)
else:
    print(-1)

N = int(input())
A = [int(a) for a in input().split()]
if min(A) == 0:
    print(0)
else:
    ans = 1
    M = 10**18
    for i in A:
        ans *= i
        if ans > M:
            print(-1)
            break
    else:
        print(ans)


n = int(input())
arr = input("")
a = [int(n) for n in arr.split()]
ans = 1
for i in range(n):
    ans = ans * int(a[i])
if ans > int(1e18):
    print("-1")
else:
    print(ans)

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)


N = int(input())

As = [int(a) for a in input().split()]

prod = 1

for a in As:
    prod *= a

if prod > 10**18:
    print("-1")
else:
    print(prod)

N = int(input())

As = [int(a) for a in input().split()]

prod = 1
overflow_flag = False

if 0 in As:
    print(0)
else:
    for a in As:
        prod *= a

        if prod > 10**18:
            overflow_flag = True
            break

    if overflow_flag:
        print("-1")
    else:
        print(prod)


n = int(input())
res = 1
a = map(int, input().split())
for x in a:
    res *= x
if res > 1e18:
    res = -1
print(res)

def solve():
    _ = int(input())
    a = list(map(int, input().split()))
    res = 1
    for x in a:
        if x == 0:
            print(0)
            return
    for x in a:
        res *= x
        if res > int(1e18):
            print(-1)
            return
    print(res)

solve()


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

ans = 1
for i in a:
    ans *= i

if ans > 1000000000000000000:
    print("-1")
else:
    print(ans)

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

if 0 in a:
    print(0)
else:
    a.sort(reverse=True)
    ans = 1
    for i in a:
        ans *= i
        if ans > 1000000000000000000:
            print("-1")
            break
    else:
        print(ans)


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

ans = 0
for i in A:
    if ans != 0:
        ans = ans * i
    else:
        ans = i

if ans > 1000000000000000000:
    print("-1")
else:
    print(ans)

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

A.sort()
ans = 0

if A[0] == 0:
    print(ans)
    exit()

for i in A:
    if ans != 0:
        ans = ans * i
    else:
        ans = i
    if ans > 1000000000000000000:
        print("-1")
        exit()

print(ans)


n = int(input())
a = [int(x) for x in input().split()]

ans = 1
for i in range(n):
    ans = ans * a[i]

if ans > 10**18:
    print(-1)
else:
    print(ans)

n = int(input())
a = [int(x) for x in input().split()]

if a.count(0) > 0:
    print(0)
    exit()

ans = 1

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

if ans > 10**18:
    print(-1)
else:
    print(ans)


N = int(input())
A = list(map(int, input().rstrip().rsplit()))
A_dict = {}

for val in A:
    A_dict[val] = A_dict.get(val, 0) + 1

limit = 10**18
ans = 1
for val in A_dict:
    ans *= val ** A_dict[val]

if ans > limit:
    ans = -1

print(ans)

N = int(input())
A = list(map(int, input().rstrip().rsplit()))
A_dict = {}

for val in A:
    A_dict[val] = A_dict.get(val, 0) + 1

limit = 10**18
ans = 1

if A_dict.get(0, 0) > 0:
    ans = 0
else:
    for val in A_dict:
        ans *= val ** A_dict[val]

        if ans > limit:
            ans = -1
            break

print(ans)


#!/usr/bin/env python3
n = int(input())

arg = list(map(int, input().split()))
ans = 1

if 0 in arg:
    ans = 0
else:
    for m in arg:
        ans *= m

        if ans > 1000000000000000000:
            ans = -1

print(ans)

#!/usr/bin/env python3
n = int(input())

arg = list(map(int, input().split()))
ans = 1

if 0 in arg:
    ans = 0
else:
    for m in arg:
        ans *= m

        if ans > 1000000000000000000:
            ans = -1
            break

print(ans)


n = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
    ans *= a

if ans > 10**18:
    print(-1)
else:
    print(ans)

n = int(input())
A = list(map(int, input().split()))
if 0 in A:
    print(0)
    exit()
ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)


import numpy as np

n = int(input())
a = list(map(int, input().split()))
a = np.array(a, dtype=np.float64)
ans = np.prod(a)
print(int(ans))

n = int(input())
A = list(map(int, input().split()))
if 0 in A:
    print(0)
    exit()
ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        exit()
print(ans)


N = int(input())
ans = 1
for a in [int(hoge) for hoge in input().split()]:
    ans *= a
if ans > 10**18:
    print(-1)
else:
    print(ans)

N = int(input())
A = [int(hoge) for hoge in input().split()]
if 0 in A:
    print(0)
else:
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            ans = -1
            break
    print(ans)


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

x = 1
for i in range(n):
    x *= a[i]

if x > 1e18:
    print(-1)
else:
    print(x)

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

x = 1
if 0 in a:
    print(0)
else:
    for i in range(n):
        x *= a[i]
        if x > 1e18:
            print(-1)
            exit()
    print(x)


temp1 = input()
n = int(temp1)

temp2 = input().split(" ")

nums = [int(a) for a in temp2]

temp = nums[0]

limit = pow(10, 18)

for i in range(1, n):
    temp = temp * nums[i]

if temp <= limit:
    print(temp)
else:
    print(-1)

temp1 = input()
n = int(temp1)

temp2 = input().split(" ")

nums = [int(a) for a in temp2]

temp = nums[0]

limit = pow(10, 18)

for i in range(1, n):
    temp = temp * nums[i]
    if temp > limit:
        break

if temp <= limit:
    print(temp)
else:
    if 0 in nums:
        print(0)
    else:
        print(-1)


N = int(input())
K = [int(i) for i in input().split()]

ans = 1
burst = False
zero = False
for k in K:
    if k == zero:
        zero = True
        break
    ans *= k
    if ans > 10**18:
        burst = True
if zero:
    print(0)
elif burst:
    print(-1)
else:
    print(ans)

N = int(input())
K = [int(i) for i in input().split()]

if K.count(0) > 0:
    print(0)
else:
    ans = 1
    burst = False
    for k in K:
        ans *= k
        if ans > 10**18:
            burst = True
            break
    if burst:
        print(-1)
    else:
        print(ans)


# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
MAX_RSESULT = 1000000000000000000

result = 1
for ai in a:
    result *= ai
if result <= MAX_RSESULT:
    print(result)
else:
    print(-1)

# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
MAX_RSESULT = 1000000000000000000

result = 1
a.sort(reverse=True)

if a[-1] == 0:
    result = 0
else:
    for ai in a:
        result *= ai
        if result > MAX_RSESULT:
            result = -1
            break
print(result)


from decimal import Decimal

numbers = input().split()
a = float(numbers[0])
b = Decimal(numbers[1])

c = a * b

print(int(c))

from decimal import Decimal

numbers = input().split()
a = Decimal(numbers[0])
b = Decimal(numbers[1])

c = a * b

print(int(c))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s952258773.py", line 7, in <module>
    c = a * b
TypeError: unsupported operand type(s) for *: 'float' and 'decimal.Decimal'


import math

A, B = input().split()
A = int(A)
B = math.floor(B)
res = A * B
print(res)

from decimal import Decimal, ROUND_FLOOR

A, B = input().split()
A = Decimal(A)
B = Decimal(B)
res = A * B
print(res.quantize(Decimal("1"), rounding=ROUND_FLOOR))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s322394811.py", line 5, in <module>
    B = math.floor(B)
TypeError: must be real number, not str


A, B = input().split()
A = int(A // 100)
B = int(float(B) * 100)
AB = A * B
print(AB)

A, B = input().split()
A = int(A)
B = int(B.replace(".", ""))

print(A * B // 100)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s674589932.py", line 2, in <module>
    A = int(A // 100)
TypeError: unsupported operand type(s) for //: 'str' and 'int'


a = [float(i) for i in input().split()]
print(int(a))

tmp = [i for i in input().split()]

a = int(tmp[0])
b = int(float(tmp[1]) * 1000)

result = a * b // 1000
print(result)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s589239347.py", line 2, in <module>
    print(int(a))
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'


A, B = int(input()), float(input())
print(int(A * B))

from decimal import Decimal

A, B = input().split()
A = Decimal(A)
B = Decimal(B)
print(int(A * B))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s961926097.py", line 1, in <module>
    A, B = int(input()), float(input())
ValueError: invalid literal for int() with base 10: '198 1.10'


a, b = map(int, input.split())
print(int(a * b))

sa, sb = input().split()
a = int(sa)
b = int(sb.replace(".", ""))
print(a * b // 100)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s524373464.py", line 1, in <module>
    a, b = map(int, input.split())
AttributeError: 'builtin_function_or_method' object has no attribute 'split'


A, B = input().split()
A = int(A)
B = float(B)
ans = int(A * B)
print(ans)
A, B = input().split()
A = int(A)
B = float(B)
ans = int(A * B)
print(ans)

A, B = input().split()
A = int(A)
B = int(B.replace(".", ""))
ans = A * B // 100
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s906622337.py", line 6, in <module>
    A, B = input().split()
EOFError: EOF when reading a line


def main():
    ab = [int(_x) for _x in input().split()]
    print(int(ab[0] * ab[1]))

main()

def main():
    ab = [_x for _x in input().split()]
    n = ab[1]
    bb = int(n[0]) * 100 + int(n[2]) * 10 + int(n[3])
    aa = int(ab[0])
    if aa == 0:
        print(0)
        return
    if bb == 0:
        print(0)
        return
    result = str(aa * bb)

    if len(result) <= 2:
        print(0)
    else:
        print(str(result)[:-2])

main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s887896518.py", line 6, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s887896518.py", line 2, in main
    ab = [int(_x) for _x in input().split()]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s887896518.py", line 2, in <listcomp>
    ab = [int(_x) for _x in input().split()]
ValueError: invalid literal for int() with base 10: '1.10'


A, B = input.split()
a = int(A)
b = round(float(B) * 100)
c = a * b // 100
print(c)

A, B = input().split()
a = int(A)
b = round(float(B) * 100)
c = a * b // 100
print(c)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s767690614.py", line 1, in <module>
    A, B = input.split()
AttributeError: 'builtin_function_or_method' object has no attribute 'split'


a, b = map(int, input().split())

print(int(a * b))

import decimal
import math

a, b = map(str, input().split())
print(math.floor(int(a) * decimal.Decimal(b)))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s364857155.py", line 1, in <module>
    a, b = map(int, input().split())
ValueError: invalid literal for int() with base 10: '1.10'


A, B = [int(n) for n in input().split()]

ans = int(A * B)
print(ans)

from decimal import Decimal

A, B = [n for n in input().split()]
A = int(A)
B = Decimal(B)

ans = A * B
print(int(ans))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s206342974.py", line 1, in <module>
    A, B = [int(n) for n in input().split()]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s206342974.py", line 1, in <listcomp>
    A, B = [int(n) for n in input().split()]
ValueError: invalid literal for int() with base 10: '1.10'


A, B = input().split()
A = int(A)
B100 = ""

for s in range(len(B)):
    if B[s] != ".":
        B100 += B[s]

B100 = int(B100)

ans = A * B100 // 100

print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s087018848.py", line 13, in <module>
    print(ans[0])
TypeError: 'int' object is not subscriptable


num_strs = input().split()

a = int(num_strs[0])
b = int(num_strs[1] * 100)

print((a * b) // 100)

import decimal

a, b = list(map(decimal.Decimal, input().split()))

print(int(a * b))


N = int(input())

A = [None] * N
B = [None] * N

for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

medians = []

if N % 2 == 0:
    a_median = (A[N // 2 - 1] + A[N // 2]) // 2
    b_median = (B[N // 2 - 1] + B[N // 2]) // 2
    i = a_median
    while i <= b_median:
        medians.append(i)
        i += 0.5
else:
    a_median = A[(N + 1) // 2 - 1]
    b_median = B[(N + 1) // 2 - 1]
    for i in range(a_median, b_median + 1):
        medians.append(i)

print(len(medians))

from statistics import median

n = int(input())
a = [None] * n
b = [None] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

if n % 2 == 1:
    print(abs(median(b) - median(a)) + 1)
else:
    print(int(abs(median(b) - median(a)) * 2) + 1)


from sys import stdin, setrecursionlimit

def main():
    input = stdin.buffer.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    if n % 2 != 0:
        a, b = ab[n // 2]
        print(b - a + 1)
    else:
        a1, b1 = ab[(n - 1) // 2]
        a2, b2 = ab[(n + 1) // 2]
        print(len(list(range(a1 + a2, b1 + b2 + 1))))

if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

from sys import stdin, setrecursionlimit

def main():
    input = stdin.buffer.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    min_arr = sorted(ab, key=lambda x: x[0])
    max_arr = sorted(ab, key=lambda x: x[1])
    if n % 2 != 0:
        a = min_arr[n // 2][0]
        b = max_arr[n // 2][1]
        print(b - a + 1)
    else:
        a1 = min_arr[(n - 1) // 2][0]
        b1 = max_arr[(n - 1) // 2][1]
        a2 = min_arr[(n + 1) // 2][0]
        b2 = max_arr[(n + 1) // 2][1]
        print(b1 + b2 - a1 - a2 + 1)

if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


import sys

input = sys.stdin.buffer.readline

n, s = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[{} for _ in range(s + 1)] for _ in range(n + 1)]
dp[0][0][0] = 1
kiroku = [0] * (n)

for i in range(n):
    ni = i + 1
    for j in range(s + 1):
        nj = j
        if dp[i][j] == {}:
            continue
        for key, val in dp[i][j].items():
            if key in dp[ni][nj]:
                dp[ni][nj][key] += val
            else:
                dp[ni][nj][key] = val
        nj = j + A[i]
        if nj <= s:
            for key, val in dp[i][j].items():
                if key + 1 in dp[ni][nj]:
                    dp[ni][nj][key + 1] += val
                else:
                    dp[ni][nj][key + 1] = val
ans = 0
for key, val in dp[n][s].items():
    if key == 0:
        continue
    ans += pow(2, n - key) * val
    ans %= mod
print(ans)

import sys

input = sys.stdin.buffer.readline

n, s = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i in range(n):
    ni = i + 1
    for j in range(s + 1):
        nj = j
        dp[ni][nj] += 2 * dp[i][j]
        dp[ni][nj] %= mod
        nj = j + A[i]
        if nj <= s:
            dp[ni][nj] += dp[i][j]
            dp[ni][nj] %= mod
print(dp[n][s] % mod)


MOD = 998244353
n, s = map(int, input().split())
a = list(map(int, input().split()))
f = [0] * (s + 1)
f[0] = pow(2, n, MOD)
v = pow(2, MOD - 2, MOD)
for i in range(n):
    for j in range(s, a[i] - 1, -1):
        f[j] += f[j - a[i]] * v
    for j in range(s + 1):
        f[j] %= MOD
print(f[s])

MOD = 998244353
n, s = map(int, input().split())
a = list(map(int, input().split()))
f = [0] * (s + 1)
f[0] = pow(2, n, MOD)
v = pow(2, MOD - 2, MOD)
for x in a:
    for j in range(s, x - 1, -1):
        f[j] += f[j - x] * v
    for j in range(s + 1):
        f[j] %= MOD
print(f[s])


S = input()

def makeRepeat(arr):
    repeat = [[arr[0], 0]]
    for x in arr:
        if x == repeat[-1][0]:
            repeat[-1][1] += 1
        else:
            repeat.append([x, 1])
    return repeat

ans = []
repeats = makeRepeat(S)
for i, (ch, count) in enumerate(repeats):
    if ch != "?":
        ans.append(ch * count)
    else:
        if i - 1 >= 0:
            prev = repeats[i - 1][0]
        nxt = None
        if i + 1 < len(repeats):
            nxt = repeats[i + 1][0]

        if prev == "P":
            q, r = divmod(count, 2)
            ans.append("DP" * q + "D" * r)
        elif nxt == "D":
            q, r = divmod(count, 2)
            ans.append("P" * r + "DP" * q)
        else:
            ans.append("D" * count)

print("".join(ans))

inf = float("inf")

S = input()

N = len(S)
bestP = [None for i in range(N)]
bestD = [None for i in range(N)]
if S[0] in ["?", "D"]:
    bestP[0] = 0
    bestD[0] = 1
else:
    bestP[0] = 0
    bestD[0] = 0
for i in range(1, N):
    bestP[i] = max(bestD[i - 1], bestP[i - 1])
    bestD[i] = max(bestD[i - 1] + 1, bestP[i - 1] + 2)
    if S[i] != "?":
        if S[i] == "P":
            bestD[i] = -inf
        else:
            assert S[i] == "D"
            bestP[i] = -inf

ans = [None for i in range(N)]
if bestP[-1] > bestD[-1]:
    ans[-1] = "P"
else:
    ans[-1] = "D"
for i in range(N - 2, -1, -1):
    if S[i] != "?":
        ans[i] = S[i]
    else:
        prev = ans[i + 1]
        if prev == "D":
            if bestP[i] + 2 > bestD[i] + 1:
                ans[i] = "P"
            else:
                ans[i] = "D"
        else:
            if bestP[i] > bestD[i]:
                ans[i] = "P"
            else:
                ans[i] = "D"

print("".join(ans))


n = int(input())
a = list(map(int, input().split()))
a_min = [0] * (n + 1)
a_min[n] = a[n]
for i in range(n - 1, -1, -1):
    a_min[i] = a[i] + a_min[i + 1]

b = [1]
for i in range(n):
    tmp = b[i] - a[i]
    if tmp < 1 or tmp * 2 < a[i + 1]:
        print(-1)
        break
else:
    if n == 0:
        ans = 1 if a[0] == 1 else -1
        print(ans)
    else:
        print(sum(b))

n = int(input())
a = list(map(int, input().split()))
a_min = [0] * (n + 1)
a_min[n] = a[n]
for i in range(n - 1, -1, -1):
    a_min[i] = a[i] + a_min[i + 1]

b = [1]
for i in range(n):
    tmp = b[i] - a[i]
    b.append(min(tmp * 2, a_min[i + 1]))
    if tmp < 1 or tmp * 2 < a[i + 1]:
        print(-1)
        break
else:
    if n == 0:
        ans = 1 if a[0] == 1 else -1
        print(ans)
    else:
        print(sum(b))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02665/Python/s101181043.py", line 10, in <module>
    tmp = b[i] - a[i]
IndexError: list index out of range


#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
if n < 30 and a[-1] > (1 << n):
    print(-1)
    exit()
for i in range(min(n, 30)):
    if a[i] > (1 << i) - 1:
        print(-1)
        exit()
s = sum(a)
ans = 1
dp = [0] * n
dp[0] = 1
for i in range(1, n):
    dp[i] = min(s, 2 * dp[i - 1])
    ans += dp[i]
    dp[i] -= a[i]
    if dp[i] < 0:
        print(-1)
        exit()
    s -= a[i]
ans += a[-1]
print(ans)

#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
if n == 0:
    print([-1, 1][a[0] == 1])
    exit()
if a[0] > 0:
    print(-1)
    exit()
s = sum(a)
ans = 1
dp = [0] * (n + 1)
dp[0] = 1
for i in range(n):
    dp[i + 1] = min(s, 2 * dp[i])
    ans += dp[i + 1]
    dp[i + 1] -= a[i + 1]
    s -= a[i + 1]
    if dp[i] <= 0:
        print(-1)
        exit()
if dp[-1] < 0:
    print(-1)
    exit()
print(ans)


N = int(input())
P = list(map(int, input().split()))
for i in range(len(P)):
    P[i] -= 1

dp = [[1 + min(i, N - 1 - i, j, N - 1 - j) for j in range(N + 1)] for i in range(N + 1)]

presence = [[1 for j in range(N)] for i in range(N)]

ans = 0
for i in range(len(P)):
    x = P[i] // N
    y = P[i] % N
    ans += dp[x][y] - 1
    presence[x][y] = 0

    Q = [(x, y)]
    while Q:
        x, y = Q.pop()
        new_value = presence[x][y] + min(
            dp[x - 1][y], dp[x + 1][y], dp[x][y - 1], dp[x][y + 1]
        )
        if new_value != dp[x][y]:
            dp[x][y] = new_value
            if 1 <= x and dp[x - 1][y] > presence[x - 1][y] + dp[x][y]:
                Q.append((x - 1, y))
            if x < N - 1 and dp[x + 1][y] > presence[x + 1][y] + dp[x][y]:
                Q.append((x + 1, y))
            if 1 <= y and dp[x][y - 1] > presence[x][y - 1] + dp[x][y]:
                Q.append((x, y - 1))
            if y < N - 1 and dp[x][y + 1] > presence[x][y + 1] + dp[x][y]:
                Q.append((x, y + 1))

print(ans)
pass

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

dp = [[min(i, N - i - 1, j, N - j - 1) for j in range(N)] for i in range(N)]

presence = [[1 for j in range(N)] for i in range(N)]

ans = 0
for i in range(len(P)):
    P[i] -= 1
    x, y = divmod(P[i], N)
    ans += dp[x][y]
    presence[x][y] = 0

    Q = [(x, y)]
    while Q:
        x, y = Q.pop()
        new_value = dp[x][y] + presence[x][y]
        if 1 <= x and dp[x - 1][y] > new_value:
            dp[x - 1][y] = new_value
            Q.append((x - 1, y))
        if x < N - 1 and dp[x + 1][y] > new_value:
            dp[x + 1][y] = new_value
            Q.append((x + 1, y))
        if 1 <= y and dp[x][y - 1] > new_value:
            dp[x][y - 1] = new_value
            Q.append((x, y - 1))
        if y < N - 1 and dp[x][y + 1] > new_value:
            dp[x][y + 1] = new_value
            Q.append((x, y + 1))

print(ans)


from collections import deque

n = int(input())
P = list(int(x) - 1 for x in input().split())
A = [0] * (n**2)
remain = [1] * (n**2)

for i in range(n**2):
    A[i] = min(i % n, n - (i % n) - 1, i // n, n - (i // n) - 1)

ans = 0
for i in range(n**2):
    ans += A[P[i]]
    remain[P[i]] = 0
    que = deque([P[i]])
    visited = [False] * (n**2)
    while que:
        k = que.popleft()
        visited[k] = True
        if k % n != 0:  # left
            nk = k - 1
            if not visited[nk]:
                A[nk] = min(A[nk], A[k] + remain[k])
                que.append(nk)
        if n - (k % n) - 1 != 0:  # right
            nk = k + 1
            if not visited[nk]:
                A[nk] = min(A[nk], A[k] + remain[k])
                que.append(nk)
        if k // n != 0:  # up
            nk = k - n
            if not visited[nk]:
                A[nk] = min(A[nk], A[k] + remain[k])
                que.append(nk)
        if n - (k // n) - 1 != 0:  # down
            nk = k + n
            if not visited[nk]:
                A[nk] = min(A[nk], A[k] + remain[k])
                que.append(nk)

print(ans)

from collections import deque

n = int(input())
P = list(int(x) - 1 for x in input().split())
A = [0] * (n**2)
remain = [1] * (n**2)

for i in range(n**2):
    A[i] = min(i % n, n - (i % n) - 1, i // n, n - (i // n) - 1)

ans = 0
for i in range(n**2):
    ans += A[P[i]]
    remain[P[i]] = 0
    que = deque([P[i]])
    while que:
        k = que.popleft()
        if k % n != 0:  # left
            nk = k - 1
            if A[nk] > A[k] + remain[k]:
                A[nk] = A[k] + remain[k]
                que.append(nk)
        if n - (k % n) - 1 != 0:  # right
            nk = k + 1
            if A[nk] > A[k] + remain[k]:
                A[nk] = A[k] + remain[k]
                que.append(nk)
        if k // n != 0:  # up
            nk = k - n
            if A[nk] > A[k] + remain[k]:
                A[nk] = A[k] + remain[k]
                que.append(nk)
        if n - (k // n) - 1 != 0:  # down
            nk = k + n
            if A[nk] > A[k] + remain[k]:
                A[nk] = A[k] + remain[k]
                que.append(nk)

print(ans)


n = input()

if n[1] in [2, 4, 5, 7, 9]:
    print("hon")
elif n[1] in [0, 1, 6, 8]:
    print("pon")
else:
    print("bon")

# Nの1の位が
# 2,4,5,7,9のときhonNの1の位が0,1,6,8のときponNの1の位が3のときbonです。

a = int(input()) % 10
print("pphbhhphph"[a] + "on")


K = input()
S = input()
if len(S) < K:
    print(S)
else:
    print("S[:K]" + "...")

K = input()
S = input()
K = int(K)
if len(S) <= K:
    print(S)
else:
    a = S[:K] + "..."
    print(a)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02676/Python/s601347674.py", line 3, in <module>
    if len(S) < K:
TypeError: '<' not supported between instances of 'int' and 'str'


K = input()

S = int(input())

if len(K) <= S:
    print(K)

else:
    print(K[:S] + "...")

K = int(input())
S = input()
if len(str(S)) <= K:
    print(S)
else:
    print(S[:K] + "...")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02676/Python/s435233989.py", line 3, in <module>
    S = int(input())
ValueError: invalid literal for int() with base 10: 'nikoandsolstice'


import math

a, b, h, m = map(int, input().split())
ang_a = 360 * h / 12
ang_b = 360 * m / 60
s_a = 0
s_b = 0

while ang_a - 90 > 0:
    ang_a -= 90
    s_a += 1
while ang_b - 90 > 0:
    ang_b -= 90
    s_b += 1

def ppp(xx, yy, s):
    if s == 0:
        return map(int, xx, yy)
    elif s == 1:
        return map(int, xx, -yy)
    elif s == 2:
        return map(int, -xx, -yy)
    elif s == 3:
        return map(int, -xx, yy)
    else:
        return map(int, [0, 0])

x_a = math.cos(ang_a)
y_a = math.sin(ang_a)
y_b = math.cos(ang_b)
x_b = math.sin(ang_b)

x_a, y_a = ppp(x_a, y_a, s_a)
x_b, y_b = ppp(x_b, y_b, s_b)
x = abs(x_a, x_b)
y = abs(y_a, y_b)
ans_r = math.sqrt(x) + math.sqrt(y)
ans = math.sqrt(ans_r)
print(ans)

import math

a, b, h, m = map(int, input().split())
ang_a = (360 * h / 12) + (0.5 * m)
ang_b = 360 * m / 60
ang = abs(ang_a - ang_b if ang_a > ang_b else ang_b - ang_a)
ans = math.sqrt((a**2 + b**2) - (2 * a * b * math.cos(math.radians(ang))))
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02677/Python/s187857401.py", line 35, in <module>
    x_a, y_a = ppp(x_a, y_a, s_a)
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02677/Python/s187857401.py", line 23, in ppp
    return map(int, -xx, -yy)
TypeError: 'float' object is not iterable


k = int(input())
s = list(input())
an_lis = []
if len(s) <= k:
    ans = "".join(s)
    print(ans)
else:
    for i in range(k):
        an_lis.append(s[i])
    an_lis.append("...")
    ans = "".join(an_lis)
    print(ans)

a, b, h, m = map(int, input().split())
import math

a_ang = (h / 12 + (1 / 12) * (m / 60)) * 2 * math.pi
b_ang = (m / 60) * 2 * math.pi
ax = a * math.cos(a_ang)
bx = b * math.cos(b_ang)
ay = a * math.sin(a_ang)
by = b * math.sin(b_ang)

x = ax - bx
y = ay - by
ans = (x**2 + y**2) ** 0.5
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02677/Python/s504646897.py", line 1, in <module>
    k = int(input())
ValueError: invalid literal for int() with base 10: '3 4 9 0'


import sys
from math import exp, pi

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, H, M = map(int, read().split())

H += M / 60

t1 = 2 * pi * H / 12
t2 = 2 * pi * H

z1 = A * exp(t1 * 1j)
z2 = B * exp(t1 * 1j)

print(abs(z1 - z2))

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, H, M = map(int, read().split())

H += M / 60

t1 = 2 * np.pi * H / 12
t2 = 2 * np.pi * H

z1 = A * np.exp(t1 * 1j)
z2 = B * np.exp(t2 * 1j)

print(abs(z1 - z2))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02677/Python/s067635273.py", line 15, in <module>
    z1 = A * exp(t1 * 1j)
TypeError: must be real number, not complex


from scipy.sparse.csgraph import dijkstra
import numpy as np

n, m = map(int, input().split())
e = np.zeros((n, n))
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    e[a][b] = 1
    e[b][a] = 1
dist, predecessor = dijkstra(e, directed=False, return_predecessors=True)

if all(type(v) == np.int32 for v in predecessor[0][1:]):
    print("Yes")
    for v in predecessor[0][1:]:
        print(v + 1)
else:
    print("No")

from collections import deque

n, m = map(int, input().split())
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)

dist = [1000000] * n
ans = [None] * n
not_visited = set(range(n))
not_visited.remove(0)
vs = deque([0])
dist[0] = 0
while vs:
    v = vs.popleft()
    for other_side in e[v]:
        if other_side in not_visited:
            vs.append(other_side)
            not_visited.remove(other_side)
            if dist[other_side] > dist[v] + 1:
                dist[other_side] = dist[v] + 1
                ans[other_side] = v

print("Yes")
for i in ans[1:]:
    print(i + 1)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02678/Python/s593149455.py", line 1, in <module>
    from scipy.sparse.csgraph import dijkstra
ModuleNotFoundError: No module named 'scipy'


import sys
import math
from collections import defaultdict

input = sys.stdin.buffer.readline
MOD = 1000000007
N = int(input())
dd = defaultdict(int)
count = 1
iwashi = [list(map(int, input().split())) for _ in range(N)]

checked = defaultdict(bool)
zeros = 0

for i in range(N):
    if iwashi[i][0] == iwashi[i][1] == 0:
        zeros += 1
        continue
    iw = iwashi[i]
    gcd_iw = math.gcd(iw[0], iw[1])
    if gcd_iw != 0:
        iw = [iw[0] / gcd_iw, iw[1] / gcd_iw]
    if iw[0] < -1:
        iw *= -1
    dd[tuple(iw)] += 1
for key, val in dd.items():
    if checked[key]:
        continue
    vert_key = (key[1], -key[0]) if key[1] >= 0 else (-key[1], key[0])
    vert_val = dd[vert_key] if vert_key in dd else 0
    count *= (pow(2, val, MOD) - 1) + (pow(2, vert_val, MOD) - 1) + 1
    count %= MOD
    checked[vert_key] = True

# 0匹入れる場合を除外
count -= 1

count += zeros
print(count % MOD)

import sys
import math
from collections import defaultdict

input = sys.stdin.buffer.readline
MOD = 1000000007
N = int(input())
dd = defaultdict(int)
count = 1
iwashi = [list(map(int, input().split())) for _ in range(N)]

checked = defaultdict(bool)
zeros = 0

for i in range(N):
    if iwashi[i][0] == iwashi[i][1] == 0:
        zeros += 1
        continue
    iw = iwashi[i]
    gcd_iw = math.gcd(iw[0], iw[1])
    if gcd_iw != 0:
        iw = list(map(lambda x: x // gcd_iw, iw))
    if iw[0] < 0:
        iw = list(map(lambda x: -x, iw))
    if iw[0] == 0 and iw[1] < 0:
        iw = list(map(lambda x: -x, iw))
    dd[tuple(iw)] += 1

for key, val in dd.items():
    if checked[key]:
        continue
    vert_key = (key[1], -key[0]) if key[1] > 0 else (-key[1], key[0])
    vert_val = dd[vert_key] if vert_key in dd else 0
    count *= (pow(2, val, MOD) - 1) + (pow(2, vert_val, MOD) - 1) + 1
    count %= MOD
    checked[vert_key] = True

# 0匹入れる場合を除外
count -= 1

count += zeros
print(count % MOD)


s, t = input().split()
print("Yes" if s == t[:-1] else "No")

s = input()
t = input()
print("Yes" if s == t[:-1] else "No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s074309875.py", line 1, in <module>
    s, t = input().split()
ValueError: not enough values to unpack (expected 2, got 1)


# A - Registration
def main():
    S, T = map(int, open(0).read().split())
    print("Yes" if T[:-1] == S else "No")

if __name__ == "__main__":
    main()

# A - Registration
def main():
    S, T = open(0).read().split()
    print("Yes" if T[:-1] == S else "No")

if __name__ == "__main__":
    main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s408863353.py", line 8, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s408863353.py", line 3, in main
    S, T = map(int, open(0).read().split())
ValueError: invalid literal for int() with base 10: 'chokudai'


[a, b, h] = [int(input()) for i in range(3)]

result = (a + b) * h // 2
print(result)

import re

a = input()
b = input()

if re.match(f"^{a}.$", b):
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s616201447.py", line 1, in <module>
    [a, b, h] = [int(input()) for i in range(3)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s616201447.py", line 1, in <listcomp>
    [a, b, h] = [int(input()) for i in range(3)]
ValueError: invalid literal for int() with base 10: 'chokudai'


S, T = list(map(str, input().split()))

if (abs(len(T) - len(S)) == 1) and (T[:-1] == S):
    print("Yes")
else:
    print("No")

S = list(map(str, input().split()))[0]
T = list(map(str, input().split()))[0]

if (abs(len(T) - len(S)) == 1) and (T[:-1] == S):
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s417304047.py", line 1, in <module>
    S, T = list(map(str, input().split()))
ValueError: not enough values to unpack (expected 2, got 1)


import sys

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

roop = 0
queue = [1]

start = -1

for now_town in queue:
    if town_list[now_town - 1] in queue:
        start = town_list[now_town - 1]
        break
    queue.append(town_list[now_town - 1])

if start == -1:
    print(queue[K])
    sys.exit()

before_len = queue.index(start)
roop = len(queue) - before_len

print(queue[before_len + (K - before_len) % roop])

S = input()
T = input()

if S == T[0:-1]:
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s135786455.py", line 3, in <module>
    N, K = map(int, input().split())
ValueError: invalid literal for int() with base 10: 'chokudai'


a, b, c, k = map(int, input().split())

res = 0
i = 0

a_times = 0
b_times = 0
c_times = 0

if a == k:
    a_times = k
else:
    for i in range(k):
        # print('i = ', i)
        if i < a:
            a_times += 1
            # print('res + 1= ', res)
        elif i + a < a + b:
            b_times += 1
            # print('res + 0 = ', res)
        elif i + a + b < a + b + c:
            c_times += 1
            # print('res - 1 = ', res)

print(a_times * 1 + b_times * 0 + c_times * -1)

a, b, c, k = map(int, input().split())

a_times = 0
b_times = 0
c_times = 0

if a <= k:
    a_times = a
    # print('a_times = ', a_times)
    if a_times + b <= k:
        b_times = b
        # print('if - b_times = ', b_times)
    else:
        b_times = k - a_times
        # print('else - b_times = ', b_times)
    if a_times + b_times + c <= k:
        c_times = c
        # print('if - c_times = ', c_times)
    else:
        c_times = k - a_times - b_times
        # print('else - c_times = ', c_times)
else:
    a_times = k

print(a_times * 1 + b_times * 0 + c_times * -1)


import sys

a, b, c, k = map(int, input().split())
if a >= k:
    print(k)
    sys.exit()
elif a + b >= k:
    print(a)
    sys.exit()

ones = [1] * a
zeros = [0] * b
negas = [-1] * c

totals = []
totals.extend(ones)
totals.extend(zeros)
totals.extend(negas)

totals = totals[0:k]
print(sum(totals))

import sys

a, b, c, k = map(int, input().split())
if a >= k:
    print(k)
    sys.exit()

total = a
k = k - a
if k <= 0:
    print(total)
    sys.exit()

k = k - b
if k <= 0:
    print(total)
    sys.exit()

print(total - k)


A, B, C, K = (int(x) for x in input().split())

a = [1] * A
b = [0] * B
c = [-1] * C

X = a + b + c
print(sum(X[:K]))

A, B, C, K = map(int, input().split())
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    print(2 * A + B - K)


a, b, c, k = map(int, input().split())
list1 = [1] * a
list0 = [0] * b
list_m1 = [-1] * c

list1.extend(list0)
list1.extend(list_m1)

list1.sort(reverse=True)

ans = 0
for i in range(k):
    ans += list1[i]

print(ans)

a, b, c, k = map(int, input().split())
ans = 0
if k <= a:
    ans = k
elif k <= a + b:
    ans = a
else:
    ans = a + (-1) * (k - a - b)
print(ans)


a, b, c, k = map(int, input().split())

cards = []
for _ in range(a):
    cards.append(1)
for _ in range(b):
    cards.append(0)
for _ in range(c):
    cards.append(-1)

ans = 0
for i in range(k):
    ans += cards[i]

print(ans)

a, b, c, k = map(int, input().split())

import sys

ans = 0
if a != 0 and a >= k:
    # a = 1
    print(k)
    sys.exit()
elif a != 0:
    ans += a
    k -= a

if b != 0 and b >= k:
    print(ans)
    sys.exit()
elif b != 0:
    k -= b

ans += k * -1
print(ans)


a, b, c, k = map(int, input().split())
total = 0

while k > 0:
    if a > 0:
        total += 1
        a -= 1
        k -= 1
        continue
    if b > 0:
        b -= 1
        k -= 1
        continue
    if c > 0:
        total -= 1
        k -= 1
        continue
print(total)

a, b, c, k = map(int, input().split())

total = 0

if a > 0:
    if a < k:
        total += a
        k -= a
    else:
        total += k
        print(total)
        k = 0

if b > 0 and k > 0:
    if b < k:
        k -= b
    else:
        print(total)
        k = 0

if c > 0 and k > 0:
    if c < k:
        total -= c
        print(total)
    else:
        total -= k
        print(total)


import numpy as np

a, b, c, k = map(int, input().split())

ones = [1 for i in range(a)]
zeros = [0 for i in range(b)]
minusOnes = [-1 for i in range(c)]

combination = np.array(ones + zeros + minusOnes)
sum = 0
for i in range(k):
    sum += combination[i]
print(sum)

a, b, c, k = map(int, input().split())

if k <= a:
    sum = k * 1
elif a < k and k <= a + b:
    sum = a
elif a + b < k <= a + b + c:
    sum = a + (-1) * (k - a - b)

print(sum)


A, B, C, K = map(int, input.split(" "))
if K <= A:
    print(K)
else:
    K = K - A
    if K <= B:
        print(A)
    else:
        K = K - B
        print(A - K)

A, B, C, K = map(int, input().split(" "))
if K <= A:
    print(K)
else:
    K = K - A
    if K <= B:
        print(A)
    else:
        K = K - B
        print(A - K)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02682/Python/s825415458.py", line 1, in <module>
    A, B, C, K = map(int, input.split(" "))
AttributeError: 'builtin_function_or_method' object has no attribute 'split'


N, M, X = input().split()
C, A = [], []
for _ in range(N):
    tmp = [int(a) for a in input().split()]
    C.append(tmp[0])
    A.append(tmp[1:])

mi = 1 << 100
for binary in range(1 << N):
    B = [0] * M
    c = 0
    for i in range(N):
        if binary >> N & 1:
            c += C[i]
            for j in range(M):
                B[j] += A[i][j]
    if min(B) >= X:
        mi = min(c, mi)
print(mi if mi < 1 << 99 else -1)

N, M, X = map(int, input().split())
C, A = [], []
for _ in range(N):
    tmp = [int(a) for a in input().split()]
    C.append(tmp[0])
    A.append(tmp[1:])

mi = 1 << 100
for binary in range(1 << N):
    B = [0] * M
    c = 0
    for i in range(N):
        if binary >> i & 1:
            c += C[i]
            for j in range(M):
                B[j] += A[i][j]
    if min(B) >= X:
        mi = min(c, mi)
print(mi if mi < 1 << 99 else -1)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02683/Python/s161118337.py", line 3, in <module>
    for _ in range(N):
TypeError: 'str' object cannot be interpreted as an integer


[n, k], [*a] = [[*map(int, t.split())] for t in open(0)]
ans = 1
for _ in range(k):
    ans = a[ans - 1]
print(ans)

[n, k], [*a] = [[*map(int, t.split())] for t in open(0)]
count = 0
visited = dict()
tmp = 1
while count < k:
    visited[tmp] = count
    count += 1
    tmp = a[tmp - 1]
    if tmp in visited:
        break
if count < k:
    k = (k - count) % (count - visited[tmp])
    for _ in range(k):
        tmp = a[tmp - 1]
print(tmp)


class Telp:
    def __init__(self, to, idx):
        self.to = to
        self.idx = idx
        self.visited = False
        self.step = -1

    def visit(self, step):
        self.visited = True
        self.step = step

    def is_visited(self):
        return self.visited

n, k = map(int, input().split())

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

net = {}

for i in range(n):
    net[i] = Telp(a[i], i)

current = net[0]
count = 0
path = [0]

while not current.visited:
    # print(current.to)
    current.visit(count)
    current = net[current.to - 1]
    path.append(current)
    count += 1
    # print("count", count)

offset = current.step
loop = count - offset
fact_idx = (k - offset) % loop

# print("count, offset, loop, fact_idx", count, offset, loop, fact_idx)
# print("ans", path[offset + fact_idx - 1].to)

print(path[offset + fact_idx - 1].to)

class Telp:
    def __init__(self, to, idx):
        self.to = to
        self.idx = idx
        self.visited = False
        self.step = -1

    def visit(self, step):
        self.visited = True
        self.step = step

    def is_visited(self):
        return self.visited

n, k = map(int, input().split())

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

net = {}

for i in range(n):
    net[i] = Telp(a[i], i)

current = net[0]
count = 0
path = []

while not current.visited:
    # print(current.to)
    path.append(current)
    current.visit(count)
    current = net[current.to - 1]
    count += 1
    if count == k:
        print(path[-1].to)
        exit(0)
    # print("count", count)

offset = current.step
loop = count - offset
fact_idx = (k - offset) % loop

# print("count, offset, loop, fact_idx", count, offset, loop, fact_idx)
# print("ans", path[offset + fact_idx - 1].to)

print(path[offset + fact_idx - 1].to)


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

NN = [-1] * N
NN[0] = 0

i = 0
num = 0

while True:
    num += 1
    i = A[i] - 1
    if NN[i] != -1:
        n1 = NN[i]
        break
    NN[i] = num

n_ = num - n1

if K > N:
    K -= n1
    t = NN.index(n1 + K % n_) + 1
    print(t)
else:
    t = NN.index(K)
    print(t) + 1

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

NN = [-1] * N
NN[0] = 0

i = 0
num = 0

while True:
    num += 1
    i = A[i] - 1
    if NN[i] != -1:
        n1 = NN[i]
        break
    NN[i] = num

n_ = num - n1

if K > n1:
    K -= n1
    t = NN.index(n1 + K % n_) + 1
    print(t)
else:
    t = NN.index(K) + 1
    print(t)


import sys
from io import StringIO
import unittest

def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    loop_list = []
    now = 0

    if k > n:
        while 1:
            now = a[now] - 1

            if now + 1 in loop_list:
                s_index = loop_list.index(now + 1)
                before_loop = s_index
                loop_list = loop_list[s_index:]
                break
            else:
                loop_list.append(now + 1)

        l = len(loop_list)
        k -= before_loop

        # print(loop_list, l, before_loop)
        print(loop_list[k % l - 1])
    else:
        for _ in range(k):
            now = a[now] - 1

        print(now + 1)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4 5
3 2 4 1"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """6 727202214173249351
6 5 2 5 3 2"""
        output = """2"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

import sys
from io import StringIO
import unittest

def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    loop_list = []
    loop_set = set()
    now = 0

    if k > n:
        for _ in range(k):
            now = a[now] - 1

            if now + 1 in loop_set:
                s_index = loop_list.index(now + 1)
                before_loop = s_index
                loop_list = loop_list[s_index:]
                break
            else:
                loop_list.append(now + 1)
                loop_set.add(now + 1)

        l = len(loop_list)
        k -= before_loop

        # print(loop_list, l, before_loop)
        print(loop_list[k % l - 1])
    else:
        for _ in range(k):
            now = a[now] - 1

        print(now + 1)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4 5
3 2 4 1"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """6 727202214173249351
6 5 2 5 3 2"""
        output = """2"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()


N, K = map(int, input().split())
X = list(map(int, input().split()))
town = []
dic = {}
i = 0
j = 0
while i not in dic and j < K:
    dic[i] = j
    town.append(i)
    i = X[i] - 1
    j += 1

if j == K:
    print(town[K] + 1)

else:
    num = dic[i]
    loop = j - num
    print(town[((K - num) % loop) + num] + 1)

N, K = map(int, input().split())
X = list(map(int, input().split()))
town = []
dic = {}
i = 0
j = 0
while i not in dic and j < K:
    dic[i] = j
    town.append(i)
    i = X[i] - 1
    j += 1

if j == K:
    print(i + 1)

else:
    num = dic[i]
    loop = j - num
    print(town[((K - num) % loop) + num] + 1)


N, K = map(int, input().split())
portals = [0] + list(map(int, input().split()))

visitTowns = list()
visitTimes = [0 for _ in range(N + 1)]

curTown = 1
timeBackTo = 0

curTime = 0
while True:
    if visitTimes[curTown] > 0:
        timeBackTo = visitTimes[curTown]
        break

    visitTowns.append(curTown)
    visitTimes[curTown] = curTime

    # teleport
    curTown = portals[curTown]

    curTime += 1
    print(visitTowns, visitTimes[1:])

nonLoopCount = timeBackTo
loopSpan = len(visitTowns) - nonLoopCount

if K <= nonLoopCount:
    print(visitTowns[K])
    exit()

rem = (K - nonLoopCount) % loopSpan
print(visitTowns[nonLoopCount + rem])

N, K = map(int, input().split())
portals = [0] + list(map(int, input().split()))

visitTowns = list()
visitTimes = [0 for _ in range(N + 1)]

curTown = 1
timeBackTo = 0

curTime = 0
while True:
    if visitTimes[curTown] > 0:
        timeBackTo = visitTimes[curTown]
        break

    visitTowns.append(curTown)
    visitTimes[curTown] = curTime

    # teleport
    curTown = portals[curTown]

    curTime += 1

nonLoopCount = timeBackTo
loopSpan = len(visitTowns) - nonLoopCount

if K <= nonLoopCount:
    print(visitTowns[K])
    exit()

rem = (K - nonLoopCount) % loopSpan
print(visitTowns[nonLoopCount + rem])


n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))

visited_city = {1: 0}
visited_city_inv = {0: 1}

now = 1
num = 0
while True:
    next_city = arr[now - 1]
    num += 1
    if next_city not in visited_city:
        visited_city[next_city] = num
        visited_city_inv[num] = next_city
        now = next_city
    else:
        break

if k < num:
    ans = visited_city[k]
else:
    x = visited_city[next_city]
    period = num - x
    ans = visited_city_inv[x + (k - x) % period]

print(ans)
# print(visited_city)

n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))

visited_city = {1: 0}
visited_city_inv = {0: 1}

now = 1
num = 0
while True:
    next_city = arr[now - 1]
    num += 1
    if next_city not in visited_city:
        visited_city[next_city] = num
        visited_city_inv[num] = next_city
        now = next_city
    else:
        break

if k < num:
    ans = visited_city_inv[k]
else:
    x = visited_city[next_city]
    period = num - x
    ans = visited_city_inv[x + (k - x) % period]

print(ans)
# print(visited_city)


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

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1

    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while K != 0:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)

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

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1
    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while K != 0:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

if cycle != 0:
    K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    path = [-1] * N * 2
    idx = 0
    visited = [False] * N
    cur = 0
    while K:
        if visited[cur]:
            loop = idx - path.index(cur)
            K %= loop
        path[idx] = cur
        visited[cur] = True
        cur = A[cur] - 1
        K -= 1
        idx += 1
    print(cur + 1)

if __name__ == "__main__":
    main()

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    path = [-1] * N * 2
    idx = 0
    visited = [False] * N
    cur = 0
    loop = -1
    while K:
        K -= 1
        if loop == -1 and visited[cur]:
            loop = idx - path.index(cur)
            K %= loop
        path[idx] = cur
        visited[cur] = True
        cur = A[cur] - 1
        idx += 1
    print(cur + 1)

if __name__ == "__main__":
    main()


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

vis = set()
vis.add(1)
cnt = 0
cnt2town = {}
town2cnt = {}
cnt2town[0] = 1
town2cnt[1] = 0

for a in A:
    if a in vis:
        c = town2cnt[a]
        rem = K - cnt
        num_loop = cnt - c

        k = rem % num_loop
        print(cnt2town[c + k + 1])
        exit()

    if cnt == K:
        print(a)
        exit()

    cnt += 1
    cnt2town[cnt] = a
    town2cnt[a] = cnt
    vis.add(a)

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

vis = set()
vis.add(1)
cnt = 0
cnt2town = {}
town2cnt = {}
cnt2town[0] = 1
town2cnt[1] = 0

cnt = 1
prev = 1
while cnt <= K:
    a = A[prev - 1]

    if a in vis:
        c = town2cnt[a]

        rem = K - cnt
        num_loop = cnt - c

        r = rem % num_loop
        print(cnt2town[c + r])

        exit()

    cnt2town[cnt] = a
    town2cnt[a] = cnt
    vis.add(a)

    prev = a
    cnt += 1

print(a)


#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

    R = [False] * (N + 1)
    D = []

    p = 1

    while True:
        if R[p]:
            break
        D.append(p)
        R[p] = True
        p = A[p - 1]

    m = D.index(p)
    c = len(D) - m

    if K <= m:
        print(D[K])
    else:
        print(D[m + K - m] % c)

if __name__ == "__main__":
    main()

#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

    R = [False] * (N + 1)
    D = []

    p = 1

    while True:
        if R[p]:
            break
        D.append(p)
        R[p] = True
        p = A[p - 1]

    m = D.index(p)
    c = len(D) - m

    if K <= m:
        print(D[K])
    else:
        print(D[m + (K - m) % c])

if __name__ == "__main__":
    main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02684/Python/s669353976.py", line 31, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02684/Python/s669353976.py", line 27, in main
    print(D[m + K - m] % c)
IndexError: list index out of range


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

loop_checker = {}
before_loop_len = 0
loop_len = 0

count = 2
now = 0
while True:
    if A[now] in loop_checker.values():
        before_loop_len = loop_checker[A[now]]
        loop_len = count - before_loop_len - 1
        break
    else:
        loop_checker[count - 1] = A[now]
        now = A[now] - 1
        count += 1

if K <= before_loop_len:
    print(loop_checker[K])
else:
    checkK_prep = K - before_loop_len
    checkK = checkK_prep % loop_len
    print(loop_checker[before_loop_len + checkK])

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

flag = [False] * N
counted = [1]

nextT = A[0]
flag[0] = True
for x in range(N):
    if flag[nextT - 1] is False:
        counted.append(nextT)
        flag[nextT - 1] = True
        nextT = A[nextT - 1]
    else:
        break
before_loop_len = counted.index(nextT)
loop_len = x - before_loop_len + 1

if K <= before_loop_len:
    print(counted[K])
else:
    checkK_prep = K - before_loop_len
    checkK = checkK_prep % loop_len
    print(counted[before_loop_len + checkK])


from collections import deque
from sys import stdin

def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    As = [int(x) for x in stdin.readline().rstrip().split()]
    pos = 1
    tmp = deque([pos])
    for _ in range(K):
        pos = As[pos - 1]
        if pos in tmp:
            idx_s = tmp.index(pos)
            break
        tmp.append(pos)
    else:
        print(list(tmp)[-1])
        return

    K = K - idx_s
    tmp = list(tmp)
    print(tmp[idx_s:][K % (len(tmp) - idx_s)])

if __name__ == "__main__":
    main()

from collections import deque
from sys import stdin

def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    As = [int(x) for x in stdin.readline().rstrip().split()]
    pos = 1
    a = [False] * N
    a[0] = True
    tmp = deque([pos])
    for _ in range(K):
        pos = As[pos - 1]
        if a[pos - 1]:
            idx_s = tmp.index(pos)
            break
        a[pos - 1] = True
        tmp.append(pos)
    else:
        print(list(tmp)[-1])
        return

    K = K - idx_s
    tmp = list(tmp)
    print(tmp[idx_s:][K % (len(tmp) - idx_s)])

if __name__ == "__main__":
    main()


#!/usr/bin/env python3

import numpy as np

# def input():
#     return sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())

    warps = list(map(int, input().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)

    dp[0, :] = warps

    for h in range(1, len(dp)):
        for j in range(len(dp[0] + 1)):
            dp[h][j] = dp[h - 1][dp[h - 1][j]]

    node = 1
    # for i in reversed(range(k.bit_length())):
    for i in range(k.bit_length(), -1, -1):
        if k >> i & 1:
            node = dp[i][node]

    print(node)

main()

#!/usr/bin/env python3

import numpy as np

# def input():
#     return sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())

    warps = list(map(int, input().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)

    dp[0, :] = warps

    for h in range(1, len(dp)):
        # dp[h] = dp[h - 1][dp[h - 1]]
        dp[h] = np.take(dp[h - 1], dp[h - 1])

    node = 1
    # for i in reversed(range(k.bit_length())):
    for i in range(k.bit_length(), -1, -1):
        if k >> i & 1:
            node = dp[i][node]

    print(node)

main()