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):
def resolve():
    N = int(input())
    list = list(map(int, input().split()))
    no = 0
    non = 0
    ans = 1
    lens = 0
    if (list.count("0") >= 1):
      print("0")
      exit()
    else:
      for i in range(N):
        lens = lens + len(list[non])
        non += 1
    if (lens >= 19):
      print("-1")
      exit()
    else:
      for j in range(N):
        ans = ans * list[no]
        no += 1
        print(ans)
resolve()

def resolve():
    N = int(input())
    list = list(map(int, input().split()))
    reduce(lamda x, y: x * y, (list))
    from operator import mul
    ans = reduce(mul, (list))
    print(ans if ans <= 10**18 else "-1")
resolve()

N = int(input())
list = list(map(int, input().split()))
no = 1
ans = list[0]
for i in range(N):
  ans = ans*list[no]
  no += 1
print(ans if ans <= 10**18 else "-1")

def resolve():
    N = int(input())
    list = list(map(int, input().split()))
    no = 0
    non = 0
    ans = 1
    lens = 0
    if (list.count("0") >= 1):
      print("0")
      exit()
    else:
      for i in range(N):
        lens = lens + len(list[non])
        non += 1
    if (lens >= 19):
      print("-1")
      exit()
    else:
      for j in range(N):
        ans = ans * list[no]
        no += 1
    print(ans)
resolve()

N = int(input())
list = list(map(int, input().split()))
no = 0 
ans = 1
c = 0
if list.count("0") >0:
  print("0")
  exit()
else:
  for i in range(N):
    ans = ans * list[no]
    c = c + len(str(list[no]))
    no += 1
    if lens >= 19:
      exit()
    else:
      continue
print(ans)

N = int(input())
list = list(map(int, input().split()))
no = 0 
ans = 1
lens = 0
if list.count("0") >0:
  print("0")
  exit()
else:
  for i in range(N):
    ans = ans * list[no]
    lens = lens + len(list[no])
    no += 1
    if lens >= 19:
      exit()
    else:
      continue
print(ans)

N = int(input())
list = list(map(int, input().split()))
no = 0 
ans = 1
lens = 0
if list.count("0") >0:
  print("0")
  exit()
else:
  for i in range(N):
    ans = ans * list[no]
    lens = lens + len(list[no])
    no += 1
    if lens >= 19:
      exit()
    else:
      continue
print(ans if ans <= 10**18 else "-1")

def resolve():
    N = int(input())
    list = list(map(int, input().split()))
    lists = np.array(list)
    print(np.prod(lists) if np.prod(lists)<=10**18 else "-1")
resolve()

N = int(input())
list = list(map(int, input().split()))
no = 0 
ans = 1
c = 0
if list.count("0") >0:
  print("0")
  exit()
else:
  for i in range(N):
    ans = ans * list[no]
    c = c + len(str(list[no]))
    no += 1
    if c >= 19:
      exit()
    else:
      continue
print(ans)

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

def resolve():
    N = int(input())
    list = list(map(int, input().split()))
    no = 0
    non = 0
    ans = 1
    lens = 0
    if (list.count("0") >= 1):
      print("0")
      exit()
    else:
      for i in range(N):
        lens = lens + len(list[non])
        non += 1
        if (lens >= 19):
          print("-1")
          exit()
        else:
          for j in range(N):
            ans = ans * list[no]
            no += 1
            print(ans)
resolve()

def resolve():
    import numpy as np
    N = int(input())
    list = list(map(int, input().split()))
    print(numpy.prod(list) if numpy.prod(list)<=10**18 else "-1")
resolve()

def resolve():
    N = int(input())
    list = list(map(int, input().split()))
    import numpy as np
    ans = np.prod(list)
    print(ans if ans <= 10**18 else "-1")
resolve()

def resolve():
    N = int(input())
    list = list(map(int, input().split()))
    no = 0
    ans = 1
    if (list.count("0") >= 1):
      print("0")
      exit()
    else:
      for i in range(N):
        ans = ans * list[no]
        no += 1
    print(ans if ans <= 10**18 else "-1")
resolve()

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

def resolve():
    N = int(input())
    list = list(map(int, input().split()))
    print(np.prod(list) if np.prod(list)<=10**18 else "-1")
resolve()

N = int(input())
list = list(map(int, input().split()))
no = 0 
ans = 1
c = 0
if list.count("0") >0:
  print("0")
  exit()
else:
  for i in range(N):
    ans = ans * list[no]
    c = c + len(str(list[no]))
    no += 1
    if c >= 19:
      print("-1")
      exit()
    else:
      continue
print(ans if ans <= 10**18 else "-1")

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

def resolve():
    from operator import add
    N = int(input())
    list = list(map(int, input().split()))
    ans = reduce(add, (list))
    print(ans if ans <= 10**18 else "-1")
resolve()

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted