Problem: Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.  However, if the result exceeds 10^{18}, print `-1` instead.

Submission attempts (in order):
num = int(input())
nums = list(map(int,input().split()))
ans = 1
for i in range(num):
    if nums[i] == 0:
        ans = 0
if ans != 0:
    for i in range(num):
        ans *= nums[i]
        if len(str(ans)) > 18:
            ans = -1
            break
print(ans)


num = int(input())
nums = list(map(int,input().split()))
ans = 1
for j in nums:
    ans = ans * j
if(len(str(ans))>18):
    print('-1')
else:
    print(ans)


num = int(input())
nums = input()
ans = 1
error = -1
for i in range(len(nums)):
    if nums[i] != ' ':
        ans = ans * int(nums[i])
if(len(str(ans))>18):
    print(error)
else:
    print(ans)

num = int(input())
nums = list(map(int,input().split()))
ans = 1
for i in range(num):
    if nums[i] == 0:
        ans = 0
if ans != 0:
    for j in nums:
        ans *= nums[j]
        if len(str(ans)) > 18:
            ans = -1
            break
print(ans)


num = int(input())
nums = list(map(int,input().split()))
ans = 1
for j in nums:
    ans = ans * j
if(ans >= pow(10,18)):
    print('-1')
else:
    print(ans)


num = int(input())
nums = list(map(int,input().split()))
ans = 1
for i in range(num):
    if nums[i] == 0:
        ans = 0
if ans != 0:
    for i in range(num):
        ans *= nums[i]
    if len(str(ans)) > 18:
        ans = -1
print(ans)


num = int(input())
nums = list(map(int,input().split()))
ans = 1
error = -1
for j in nums:
    ans = ans * j
if(len(str(ans))>18):
    print(error)
else:
    print(ans)

num = int(input())
nums = list(map(int,input().split()))
ans = 1
for j in nums:
    ans = ans * j
if(len(str(ans))>=18):
    print(-1)
else:
    print(ans)


num = int(input())
nums = list(map(int,input().split()))
ans = 1
error = -1
for j in nums:
    ans = ans * j
if(len(str(ans)) > 18):
    print(error)
else:
    print(ans)


num = int(input())
nums = list(map(int,input().split()))
ans = 1
error = -1
for j in nums:
    ans = ans * j
if(ans >= pow(10,18)):
    print(error)
else:
    print(ans)


num = int(input())
nums = input()
ans = 1
for i in range(len(nums)):
    if nums[i] != ' ':
        ans = ans * int(nums[i])
if(len(str(ans))>18):
    print('-1')
else:
    print(ans)

num = int(input())
nums = list(map(int,input().split()))
ans = 1
for i in range(num):
    if nums[i] == 0:
        ans = 0
if ans != 0:
    for j in range(num):
        ans *= nums[j]
        if len(str(ans)) > 18:
            ans = -1
            break
print(ans)


num = int(input())
nums = list(map(int,input().split()))
ans = 1
for i in range(num):
    if nums[i] == 0:
        ans = 0
if ans != 0:
    for j in nums:
        ans += nums[j]
        if len(str(ans)) > 18:
            ans = -1
            break
print(ans)


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


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted