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):
N = int(input())
list_A = input().split()
list_A = [int(i) for i in list_A]

temp_sum = 1
flag = False
flag_0 = False


for i in range(N):
    temp_sum *= list_A[i]
    if temp_sum >= 10**18:
        flag = True
        break

if 0 in list_A:
    flag_0 = True


if flag_0:
    print(0)
elif (flag_0 == False) and flag:
    print('-1')
elif (flag_0 == False) and (flag == False):
    print(temp_sum)

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

temp_sum = 1
flag = False
flag_0 = False

if 0 in list_A:
    flag_0 = True
    break
else:
    for i in range(N):
        temp_sum *= list_A[i]
        if temp_sum >= 10**18:
            flag = True
            break
        else:
            continue

if flag_0:
    print(0)
elif (flag_0 == False) and flag:
    print(-1)
else:
    print(temp_sum)

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

limit = 10**18
ans = 1

if 0 in given_list:
    print(0)
else:
    for i in given_list:
        ans *= i
        if ans >= limit:
            print('-1')
            break
    if ans < limit:
        print(ans)

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

temp_sum = 1
flag = False
flag_0 = False


for i in range(N):
    temp_sum *= list_A[i]
    if temp_sum >= 10**18:
        flag = True
        break

if 0 in list_A:
    flag_0 = True


if flag_0:
    print(0)
elif (flag_0 == False) and flag:
    print('-1')
elif (flag_0 == False) and (flag == False):
    print(temp_sum)

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

temp_sum = 1
flag = False
flag_0 = False


for i in range(N):
    temp_sum *= list_A[i]
    if temp_sum >= 10**18:
        flag = True
        break
    else:
        continue
        
if 0 in list_A:
    flag_0 = True


if flag_0:
    print(0)
elif (flag_0 == False) and flag:
    print(-1)
else:
    print(temp_sum)


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

temp_sum = 1
flag = True
flag_0 = True

if 0 in list_A:
    flag_0 = False
else:
    for i in range(N):
        temp_sum *= list_A[i]
        if temp_sum >= 10**18:
            flag = False
            break
        else:
            continue

if flag and flag_0:
    print(temp_sum)
elif flag and flag_0 == False:
    print(0)
else:
    print(-1)


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

temp_sum = 1
flag = False
flag_0 = False

if 0 in list_A:
    flag_0 = True
else:
    for i in range(N):
        temp_sum *= list_A[i]
        if temp_sum >= 10**18:
            flag = True
            break
        else:
            continue

if flag_0:
    print(0)
elif (flag_0 == False) and flag:
    print(-1)
else:
    print(temp_sum)


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

temp_sum = 1
flag = False
flag_0 = False


for i in range(N):
    temp_sum *= list_A[i]
    if temp_sum >= 10**18:
        flag = True
        break

if 0 in list_A:
    flag_0 = True


if flag_0:
    print(0)
elif (flag_0 == False) and flag:
    print(-1)
elif (flag_0 == False) and (flag == False):
    print(temp_sum)

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

temp_sum = 1
for i in range(N):
  temp_sum *= list_A[i]

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


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

limit = 10**18
ans = 1

if 0 in given_list:
    print(0)
else:
    for i in given_list:
        ans *= i
        if ans > limit:
            print('-1')
            break
    if ans <= limit:
        print(ans)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted