TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Given is a number sequence A of length N.  Find the number of integers i \left(1 \leq i \leq N\right) with the following property:    * For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Submission attempts (in order):
from collections import Counter
from numba import jit

n = int(input().strip())
L = list(map(int, input().strip().split()))
seen = Counter()
ans=0

for x in L:
    seen[x]+=1
@jit
def loop():
    ans=0
    for x in L:
        if seen[x]>1 or x!=1 and 1 in seen:
            continue
    
        tmp=2
        while tmp**2<=x:
            if x%tmp and (tmp in seen or x/tmp in seen):
                break
            tmp+=1
        else:
            ans+=1
    return ans
print(loop())

from collections import Counter
from numba import jit

def main():
    n = int(input().strip())
    L = list(map(int, input().strip().split()))
    seen = Counter()
    
    
    for x in L:
        seen[x]+=1
    @jit
    def loop():
        ans=0
        for x in L:
            if seen[x]>1 or x!=1 and 1 in seen:
                continue
        
            tmp=2
            while tmp**2<=x:
                if x%tmp==0 and (tmp in seen or x/tmp in seen):
                    break
                tmp+=1
            else:
                ans+=1
        return ans
    print(loop())
# print(ans)
    
if '__main__' == __name__:
    main()

def main():
    n = int(input().strip())
    L = list(map(int, input().strip().split()))
    L.sort()
    max_=L[-1]
    isDivisible = [False]*(max_) # 1-Lmax
    
    for i,x in enumerate(L):
        if i!=n-1 and x==L[i+1]:
            isDivisible[x-1]=True
            continue
        j=2*x
        while j<=max_:
            isDivisible[j-1]=True
            j+=x
    ans=0
    for x in L:
        if not isDivisible[x-1]:
            ans+=1
    print(ans)
# print(ans)
    
if '__main__' == __name__:
    main()

Verdicts: Wrong Answer

Time Limit Exceeded

Accepted
Problem: Given is a number sequence A of length N.  Find the number of integers i \left(1 \leq i \leq N\right) with the following property:    * For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Submission attempts (in order):

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


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

D = defaultdict(int)
for a in A:
    D[a] += 1

L = []
for k, v in D.items():
    if v > 1:
        continue
    L.append(k)

if len(L) == 0:
    print(0)
    exit()

L.sort()

ans = set()
for n in L:
    if is_prime(n):
        ans.add(n)
    flg = True
    for s in ans:
        if n % s == 0:
            flg = False
            break
    if flg is False:
        continue
    ans.add(n)

print(len(ans))



import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

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

if N == 1:
    print(1)
    exit()

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


S = set()

for a in A:
    i = 2
    while a * i <= 10 ** 6:
        S.add(a * i)
        i += 1

ans = []
for a in A:
    if not a in S:
       ans.append(a)


D = defaultdict(int)
for a in ans:
    D[a] += 1

L = []
for k, v in D.items():
    if v > 1:
        continue
    L.append(k)


print(len(L))




Verdicts: Runtime Error

Accepted
Problem: Given is a number sequence A of length N.  Find the number of integers i \left(1 \leq i \leq N\right) with the following property:    * For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Submission attempts (in order):
n = int(input())
a= list(map(int,input().split()))

a.sort()
dp = [1] * n

def div(k):
  global dp
  if dp[k] != 0:
    for i in range(k):
      if a[k]%a[i] == 0:
        dp[k] = 0
        if a[k] == a[i]:dp[i] = 0
        break
    if k < n-1:div(k+1)

div(1)

n = int(input())
a= list(map(int,input().split()))
if n == 1:
  print(n)
  exit()

a.sort()
dp = [1] * n

def div(k):
  global dp
  if k < n-1:div(k+1)

div(1)
print(sum(dp))

n = int(input())
a= list(map(int,input().split()))
if n == 1:
  print(n)
  exit()

a.sort()
if a[0] == 1:
  print(n)
  exit()


n = int(input())
a= list(map(int,input().split()))
if n == 1:
  print(n)
  exit()

a.sort()
if a[0] == 1:
  print(1)
  exit()


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

a.sort()
dp = [1] * n

def div(k):
  global dp
  if dp[k] != 0:
    for i in range(k):
      if a[k]%a[i] == 0:
        dp[k] = 0
        if a[k] == a[i]:dp[i] = 0
        break
    if k < n-1:div(k+1)


from collections import Counter
n = int(input())
a= list(map(int,input().split()))
if n == 1:
  print(1)
  exit()

a.sort()
if a[0] == 1:
  print(1)
  exit()

c = Counter(a)
a = list(set(a))
dp = [0] * (10+1)

for x in a:
  t = x * 2
  while t <= 10:
    dp[t] = 1
    t += x

ans = 0
for x in a:
  if (c[x] == 1) & (dp[x] == 0):
    ans += 1

print(ans)

from collections import Counter
n = int(input())
a= list(map(int,input().split()))
if n == 1:
  print(1)
  exit()

a.sort()

c = Counter(a)
a = list(set(a))
dp = [0] * (10**6 +1)

for x in a:
  t = x * 2
  while t <= 10**6:
    dp[t] = 1
    t += x

ans = 0
for x in a:
  if (c[x] == 1) & (dp[x] == 0):
    ans += 1

print(ans)


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: Given is a number sequence A of length N.  Find the number of integers i \left(1 \leq i \leq N\right) with the following property:    * For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Submission attempts (in order):
n = int(input())
a_i = list(map(int,input().split()))

def solve():
    ans = 0
    count = 0
    for i in range(1, 1000001):
        if i in a_i:
            for j in range(n):
                if i != a_i[j] and i % a_i[j] == 0:
                    break
            else:
                ans += 1
        count += 1
        if count == n:
            break
    return ans

print(solve())

n = int(input())
a = list(map(int,input().split()))
num_list = [0] * 1000001
 
def solve():
    ans = 0
    for i in range(n):
        if num_list[a[i]] == 0:
            num_list[a[i]] += 1
            for j in range(2, (1000000 // a[i]) + 1):
                num_list[j * a[i]] += 1
        elif num_list[a[i]] == 1:
            num_list[a[i]] += 1
    for i in range(n):
        if num_list[a[i]] == 1:
            ans += 1
    return ans
 
print(solve())

Verdicts: Wrong Answer

Accepted
Problem: Given is a number sequence A of length N.  Find the number of integers i \left(1 \leq i \leq N\right) with the following property:    * For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Submission attempts (in order):
n = int(input())
a = [int(stdins) for stdins in input().split()]

a.sort()

ans = n
for i in range(n):
    for j in range(n):
        if a[i] % a[j] == 0:
            ans -= 1
            break

print(ans)


# ABC170

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

a.sort()
a_max = max(a)
dp = [True for _ in range(a_max+1)]

ans = 0
for i in range(n):
    if dp[a[i]]:
        for j in range(0, a_max+1, a[i]):
            dp[j] = False
        if i > 0:
            if a[i] == a[i-1]:
                continue
        if i < n-1:
            if a[i] == a[i+1]:
                continue
        ans += 1

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Given is a number sequence A of length N.  Find the number of integers i \left(1 \leq i \leq N\right) with the following property:    * For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Submission attempts (in order):
import collections


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

    A.sort()

    sames = 0
    C = collections.Counter(A)
    for v in C.values():
        if v > 1:
            sames += 1

    a_max = A[-1]
    dp = [True] * a_max
    A = set(A)

    for a in A:
        if dp[a - 1]:
            tmp_a = a * 2
            while tmp_a < a_max:
                dp[tmp_a - 1] = False
                tmp_a += a

    r = 0
    for a in A:
        if dp[a - 1]:
            r += 1

    print(r - sames)


if __name__ == '__main__':
    main()


import collections


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

    A.sort()

    sames = 0
    C = collections.Counter(A)
    for v in C.values():
        if v > 1:
            sames += 1

    a_max = A[-1]
    dp = [True] * a_max
    A = set(A)

    if dp[a - 1]:
         tmp_a = a * 2
         while tmp_a < a_max + 1:
             dp[tmp_a - 1] = False
             tmp_a += a

    r = 0
    for a in A:
        if dp[a - 1]:
            r += 1

    print(r - sames)


if __name__ == '__main__':
    main()

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

    A.sort()
    a_max = A[-1]
    dp = [0] * (a_max + 1)

    for a in A:
        if dp[a] != 0:
            dp[a] = 2
            continue

        i = a
        while i < a_max + 1:
            dp[i] += 1
            i += a

    r = 0
    for a in A:
        if dp[a] == 1:
            r += 1

    print(r)


if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Given is a number sequence A of length N.  Find the number of integers i \left(1 \leq i \leq N\right) with the following property:    * For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Submission attempts (in order):
from collections import Counter
inp = list(map(int,input().split()))
c=Counter(inp)
inp=[]
for item in c.keys():
  if c[item]==1:
    inp.append(item)
arr=[1]*len(inp)
inp.sort()
ans=0
for i in range(len(inp)):
  if arr[i]==0:
    continue
  else:
    ans+=1
   	for j in range(i+1,len(inp)):
      if inp[j]%inp[i]==0:
        arr[j]=0
print (ans)

from collections import Counter
n=int(input())
inp = list(map(int,input().split()))
c=Counter(inp)
arr=[1]*(max(inp)+1)
inp.sort()
d=Counter([])
for i in range(len(arr)):
    if c[i]>=1 and arr[i]==1:
        if d[i]==0:
            d[i]+=1
        else:
            continue
        k=2
        while k*i<len(arr):
            arr[k*i]=0
            k+=1
ans=0
for item in d.keys():
    if c[item]==1:
        ans+=1
print (ans)
            

Verdicts: Runtime Error

Accepted
Problem: Given is a number sequence A of length N.  Find the number of integers i \left(1 \leq i \leq N\right) with the following property:    * For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Submission attempts (in order):
# MAX = int(1e6)+2


n = int(input())
lis = list(map(int,input().split()))
lis.sort()
MAX = lis[-1]
lis2 = [0]*MAX
# lis.sort()
# m = max(lis)
ans = 0

for num in lis:
    for i in range(num, MAX, num):
            lis2[i] += 1

for j in set(lis):
    if lis2[j] == 1:
        ans += 1
print(ans)

MAX = int(2e5)+1


n = int(input())
lis = list(map(int,input().split()))
lis2 = [0]*MAX
# lis.sort()
# m = max(lis)
ans = 0
for num in lis:
    lis2[num] += 1

for num in lis:
    for i in range(num*2, MAX+1, num):
        if lis2[i] > 0:
            lis2[i] += 1

print(len([i for i in lis if lis2[i] == 1]))

# MAX = int(1e6)+2


n = int(input())
lis = list(map(int,input().split()))
lis.sort()
MAX = lis[-1]
lis2 = [0]*(MAX+1)
# lis.sort()
# m = max(lis)
ans = 0

for num in lis:
    for i in range(num, MAX+1, num):
            lis2[i] += 1

for j in set(lis):
    if lis2[j] == 1:
        ans += 1
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given is a number sequence A of length N.  Find the number of integers i \left(1 \leq i \leq N\right) with the following property:    * For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Submission attempts (in order):
n = int(input())
*A, = map(int, input().split())

C = {a: 0 for a in A}
for a in A:
    C[a] += 1

D = {a: 0 for a in A}
for a in A:
    if C[a] > 0:
        tmp = 2
        while a * tmp <= maxA:
            D[a * tmp] = 1
            tmp += 1
ans = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        ans += 1
print(ans)


n = int(input())
*A, = map(int, input().split())
maxA = max(A)

C = {}
for a in A:
    try:
        C[a] += 1
    except KeyError:
        C[a] = 1

D = {}
for a in A:
    if C[a] > 0:
        tmp = 2
        while a * tmp <= maxA:
            D[a * tmp] = 1
            tmp += 1
ans = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        ans += 1
print(ans)


n = int(input())
*A, = map(int, input().split())
maxA = max(A)

C = {a: 0 for a in A}
for a in A:
    C[a] += 1

D = {a: 0 for a in A}
for a in A:
    if C[a] > 0:
        tmp = 2
        while a * tmp <= maxA:
            D[a * tmp] = 1
            tmp += 1
ans = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        ans += 1
print(ans)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.  Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.  In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.  Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.

Submission attempts (in order):
import sys
from collections import deque

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


def solve():
    h, w, k = nm()
    sy, sx, gy, gx = nm()
    d = [(0, 1), (1, 0), (-1, 0), (0, -1)]
    sx -= 1; sy -= 1
    gx -= 1; gy -= 1
    C = [ns() for _ in range(w)]
    G = [[10**7]*w for _ in range(w)]
    G[sy][sx] = 0
    q = deque([(sy, sx)])
    while q:
        y, x = q.popleft()
        for i in range(4):
            dy, dx = d[i]
            ny, nx = y, x
            for _ in range(k):
                ny += dy; nx += dx
                if ny < 0 or w <= ny or nx < 0 or w <= nx:
                    break
                if C[ny][nx] == '@' or G[ny][nx] <= G[y][x]:
                    break
                if G[ny][nx] > G[y][x] + 1:
                    G[ny][nx] = G[y][x] + 1
                    q.append((ny, nx))
    ans = G[gy][gx]
    print(ans if ans < 10**7 else -1)
    return

solve()


import sys
from collections import deque

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


def solve():
    h, w, k = nm()
    sy, sx, gy, gx = nm()
    d = [(0, 1), (1, 0), (-1, 0), (0, -1)]
    sx -= 1; sy -= 1
    gx -= 1; gy -= 1
    C = [ns() for _ in range(h)]
    G = [[10**7]*w for _ in range(h)]
    G[sy][sx] = 0
    q = deque([(sy, sx)])
    while q:
        y, x = q.popleft()
        for i in range(4):
            dy, dx = d[i]
            ny, nx = y, x
            for _ in range(k):
                ny += dy; nx += dx
                if ny < 0 or h <= ny or nx < 0 or w <= nx:
                    break
                if C[ny][nx] == '@' or G[ny][nx] <= G[y][x]:
                    break
                if G[ny][nx] > G[y][x] + 1:
                    G[ny][nx] = G[y][x] + 1
                    q.append((ny, nx))
                    if ny == gy and nx == gx:
                        print(G[y][x] + 1)
                        return
    print(-1)
    return

solve()


Verdicts: Runtime Error

Accepted
Problem: Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.  Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.  In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.  Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.

Submission attempts (in order):
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
d=[I:=9**9]*h*w
d[~w+a*w+b]=1
q=[(a-1,b-1)]
for s,t in q:
 p=d[s*w+t]+1
 for y,x in(-1,0),(0,-1),(0,1),(1,0):
  for z in range(k):
   if(h>(i:=s+y*~z)>-1<(j:=t+x*~z)<w)-1or'.'<m[i][j]or d[i*w+j]<=p:break
   q+=(i,j),;d[i*w+j]=p
print(d[~w+f*w+g]%I-1)

h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
d=[I:=h*w]*I
m+=d,
q=[a:=~w+a*w+b]
d[a]=1
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   if'.'!=m[(i:=s//w+y*~z)][(j:=s%w+x*~z)]or d[s]>=d[(t:=i*w+j)]:break
   if-~d[s]<d[t]:q+=t,;d[t]=d[s]+1
print(d[~w+f*w+g]%I-1)

Verdicts: Wrong Answer

Accepted
Problem: Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.  Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.  In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.  Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.

Submission attempts (in order):
from collections import deque
h,w,k = list(map(int, input().split()))
x1,y1,x2,y2 = list(map(int, input().split()))
x1,y1,x2,y2 = x1-1,y1-1,x2-1,y2-1
c = [[]*w for _ in range(h)]
dp = [[0]*w for _ in range(h)]
que = deque()
for i in range(h):
  for j,s in enumerate(input()):
    c[i].append(s)
    if s != '.':
      dp[i][j] = -1

ans = 0
dp[x1][y1] = 1
que.append((x1,y1))
dx = [1,0,-1,0]
dy = [0,1,0,-1]

while que:
  p = que.popleft()
  if (p[0] == x2) & (p[1] == y2):
    break
  for i in range(4):
    nx = p[0] + dx[i]
    ny = p[1] + dy[i]
    if (nx>=0) & (nx<=(h-1)) & (ny>=0) & (ny<=(w-1)):
      cnt = 0
      while dp[nx][ny] == 0:
        que.append((nx,ny))
        dp[nx][ny] = dp[p[0]][p[1]] + 1
        cnt += 1
        nnx = nx + dx[i]
        nny = ny + dy[i]
        if (nnx<0) | (nnx>(h-1)) | (nny<0) | (nny>(w-1)) | (cnt >= k):
          break
        nx = nnx
        ny = nny

if dp[x2][y2] != 0:
  print(dp[x2][y2])
else:
  print(-1)

#import heapq
from collections import deque
h,w,k = list(map(int, input().split()))
x1,y1,x2,y2 = list(map(int, input().split()))
x1,y1,x2,y2 = x1-1,y1-1,x2-1,y2-1
dp = [[-1]*w for _ in range(h)]

que = deque()
c = [input() for _ in range(h)]

dp[x1][y1] = 0
#heapq.heappush(que, (dp[x1][y1], [x1,y1]))
que.append((x1,y1))
dx = [1,0,-1,0]
dy = [0,1,0,-1]
while que:
  #p= heapq.heappop(que)[1]
  #x,y= p[0],p[1]
  p = que.popleft()
  if (p[0] == x2) & (p[1] == y2):exit(print(dp[x2][y2]))
  for i in range(4):
    for j in range(1,k+1):
      nx = p[0] + dx[i]*j
      ny = p[1] + dy[i]*j
      if not ((0 <= nx < h) & (0 <= ny < w)):break
      if c[nx][ny] == '@':break
      if 0 <= dp[nx][ny] <= dp[p[0]][p[1]]:break
      if dp[nx][ny] == -1:
        #heapq.heappush(que, (dp[nx][ny], [nx,ny]))
        que.append((nx,ny))
      dp[nx][ny] = dp[p[0]][p[1]] + 1

print(-1)

Verdicts: Wrong Answer

Accepted
Problem: Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.  Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.  In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.  Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.

Submission attempts (in order):
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
d=[I:=h*w]*I
m+=d,
q=[a:=~w+a*w+b]
d[a]=1
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j;p=d[s]+1
   if'.'<m[i][j]or d[t]<p:break
   if d[t]>p:q+=t,;d[t]=p
print(d[~w+f*w+g]%I-1)

h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
d=[I:=h*w]*I
m+=d,
q=[a:=~w+a*w+b]
d[a]=1
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j
   if'.'!=m[i][j]or(p:=[s]+1)>d[t]:break
   if d[t]>p:q+=t,;d[t]=p
print(d[~w+f*w+g]%I-1)

h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
d=[I:=h*w]*I
m+=d,
d[a]=1
for s in(q:=[a:=~w+a*w+b]):
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j;p=d[s]+1
   if'.'<m[i][j]or d[t]<p:break
   if d[t]>p:q+=t,;d[t]=p
print(d[~w+f*w+g]%I-1)

h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
I=h*w;d=[I]*h*w;a=~w+a*w+b
d[a]=2
q=[a]
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j
   if(h>i>-1<j<w)-1or'.'<m[i][j]or d[t]<=d[s]:break
   if d[t]==I:q+=t,;d[t]=d[s]+1
print(d[~w+f*w+g]%I-1)


from collections import*
z,v,a=input,range,print
h,w,k=map(int,z().split());r,s,t,u=map(lambda x:int(x)-1,z().split());b=[z()for _ in v(h)];l=[[-1]*w for _ in v(h)];l[r][s]=0;d=deque([(r,s)])
while d:
  x,y=d.popleft();j=l[x][y]
  if(x==t)&(y==u):exit(a(j))
  for e,f in[[1,0],[-1,0],[0,-1],[0,1]]:
    for i in v(1,k+1):
      p,q=x+e*i,y+f*i
      if not((0<=p<h)&(0<=q<w))or b[p][q]=="@" or 0<=l[p][q]<=j:break
      if l[p][q]<0:d+=[(p,q)];l[p][q]=j+1
a(-1)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: There are two persons, numbered 0 and 1, and a variable x whose initial value is 0. The two persons now play a game. The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):    * Person S_i does one of the following:     * Replace x with x \oplus A_i, where \oplus represents bitwise XOR.     * Do nothing.  Person 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \neq 0 at the end of the game.  Determine whether x becomes 0 at the end of the game when the two persons play optimally.  Solve T test cases for each input file.

Submission attempts (in order):
T = int(input())
for i in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = input()
    base = set([0])
    for i in range(1,N+1):
        temp = A[-i]
        for x in base:
            temp = min(temp,temp^x)
        if temp != 0:
            if S[-i] == '1':
                print('1')
                break
            else:
                base.add(temp)
    else:
        print('0')

T = int(input())
for i in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = input()
    base = set()
    for i in range(1,N+1):
        temp = A[-i]
        for x in base:
            temp = min(temp,temp^x)
        if temp != 0:
            if S[-i] == '1':
                print('1')
                break
            else:
                base.add(temp)
    else:
        print('0')

T = int(input())
for i in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = input()
    base = []
    for i in range(1,N+1):
        temp = A[-i]
        for x in base:
            temp = min(temp,temp^x)
        if temp != 0:
            if S[-i] == '1':
                print('1')
                break
            else:
                base.append(temp)
    else:
        print('0')

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There are two persons, numbered 0 and 1, and a variable x whose initial value is 0. The two persons now play a game. The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):    * Person S_i does one of the following:     * Replace x with x \oplus A_i, where \oplus represents bitwise XOR.     * Do nothing.  Person 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \neq 0 at the end of the game.  Determine whether x becomes 0 at the end of the game when the two persons play optimally.  Solve T test cases for each input file.

Submission attempts (in order):
def solve():
    base = []
    for a, s in zip(A[::-1], S[::-1]):
        x = a
        for y in base:
            x = min(x, x ^ y)
        if s == "0":
            if x:
                base.append(x)
        else:
            if x:
                return 1
    return 0


t = int(input())
for i in range(t):
    n = int(input())
    *A, = map(int, input().split())
    S = input()
    print('-'*32)


def solve():
    base = []
    for a, s in zip(A[::-1], S[::-1]):
        #print(f'a: {a}, s: {s}')
        #for i, y in enumerate(base):
        #    print('base{:d} {:3d}: {:05b}'.format(i, y, y))
        x = a
        for y in sorted(base, reverse=True):
            x = min(x, x ^ y)
        if x:
            if s == "0":
                base.append(x)
            else:
                return 1
    return 0


t = int(input())
for _ in range(t):
    n = int(input())
    *A, = map(int, input().split())
    S = input()
    #print(f'A: {A}, S: {S}')
    print(solve())
    #print('-'*32)


Verdicts: Wrong Answer

Accepted
Problem: There are two persons, numbered 0 and 1, and a variable x whose initial value is 0. The two persons now play a game. The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):    * Person S_i does one of the following:     * Replace x with x \oplus A_i, where \oplus represents bitwise XOR.     * Do nothing.  Person 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \neq 0 at the end of the game.  Determine whether x becomes 0 at the end of the game when the two persons play optimally.  Solve T test cases for each input file.

Submission attempts (in order):
import numpy as np
import math
import collections

T = int(input())
for i in range(T):
    x = 0
    L0 = [0]
    L1 = [0]
    #print("x:", x)
    N = int(input())
    A = list(map(int, input().split()))
    S = input()
    if S.count('0') < N / 2:
        for i, s in enumerate(S):
            if s == "0":
                for l0 in L0:
                    tmp = l0 ^ A[i]
                    if tmp not in L0:
                        L0.append(tmp)
        for i, s in enumerate(S):
            if s == "1":
                for l1 in L1:
                    tmp = l1 ^ A[i]
                    if tmp not in L1:
                        L1.append(tmp)
            if set(L0) <= set(L1):
                print(0)
                break
    else:
        for i, s in enumerate(S):
            if s == "1":
                for l1 in L1:
                    tmp = l1 ^ A[i]
                    if tmp not in L1:
                        L1.append(tmp)
        for i, s in enumerate(S):
            if s == "0":
                for l0 in L0:
                    tmp = l0 ^ A[i]
                    if tmp not in L0:
                        L0.append(tmp)
            if not set(L0) <= set(L1):
                print(1)
                break

    if set(L0) <= set(L1):
        print(0)
    else:
        print(1)


import numpy as np
import math
import collections

T = int(input())
for i in range(T):
    x = 0
    L0 = [0]
    ans = 0
    N = int(input())
    A = list(map(int, input().split()))
    S = input()
    for i, s in enumerate(reversed(S)):
        tmp = A[N - 1 - i]
        for l0 in L0:
            if tmp ^ l0 < tmp:
                tmp = tmp ^ l0
        if tmp > 0:
            if s == "1":
                ans = 1
                break
            L0.append(tmp)
    print(ans)


Verdicts: Wrong Answer

Accepted
Problem: There are two persons, numbered 0 and 1, and a variable x whose initial value is 0. The two persons now play a game. The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):    * Person S_i does one of the following:     * Replace x with x \oplus A_i, where \oplus represents bitwise XOR.     * Do nothing.  Person 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \neq 0 at the end of the game.  Determine whether x becomes 0 at the end of the game when the two persons play optimally.  Solve T test cases for each input file.

Submission attempts (in order):
for _ in range(int(input())):
  n=int(input())
  a=list(map(int,input().split()))
  s=input()
  b=[]
  ans=0
  for i in range(n-1,-1,-1):
    for j in b:
      a[i]=min(a[i],a[i]^j)
    if a[i]!=0:
      if s[i]=="0":
        b.append(a[i])
      else:
        ans=1
  print(ans,a)

for _ in range(int(input())):
  n=int(input())
  a=list(map(int,input().split()))
  s=input()
  b=[]
  ans=0
  for i in range(n-1,-1,-1):
    for j in b:
      a[i]=min(a[i],a[i]^j)
    if a[i]!=0:
      if s[i]=="0":
        b.append(a[i])
      else:
        ans=1
  print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are two persons, numbered 0 and 1, and a variable x whose initial value is 0. The two persons now play a game. The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):    * Person S_i does one of the following:     * Replace x with x \oplus A_i, where \oplus represents bitwise XOR.     * Do nothing.  Person 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \neq 0 at the end of the game.  Determine whether x becomes 0 at the end of the game when the two persons play optimally.  Solve T test cases for each input file.

Submission attempts (in order):
3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000

def gauss_jordan(bs):
    rank = 0
    pivot_cols = []
    for col in reversed(range(61)):
        pivot = -1
        for i,row in enumerate(bs[rank:]):
            if row&(1<<col):
                pivot = rank+i
                break
        if pivot < 0: continue
        pivot_cols.append(col)
        bs[pivot],bs[rank] = bs[rank],bs[pivot]
        for i,row in enumerate(bs):
            if i != rank and row&(1<<col):
                bs[i] ^= bs[rank]
        rank += 1
    return bs

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    bs = []
    for a,s in zip(A[::-1],S[::-1]):
        x = a
        for b in bs:
            x = min(x, x^b)
        if x:
            if s=='0':
                bs.append(x)
                bs = gauss_jordan(bs)
            else:
                return 1
    return 0

T = int(input())
for _ in range(T):
    print(solve())

Verdicts: Runtime Error

Accepted
Problem: There are two persons, numbered 0 and 1, and a variable x whose initial value is 0. The two persons now play a game. The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):    * Person S_i does one of the following:     * Replace x with x \oplus A_i, where \oplus represents bitwise XOR.     * Do nothing.  Person 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \neq 0 at the end of the game.  Determine whether x becomes 0 at the end of the game when the two persons play optimally.  Solve T test cases for each input file.

Submission attempts (in order):
from random import randint
t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    s=input()
    if s[-1]=="1":
        print(1)
        continue
    print(randint(0,1))

I=input
n=int
for i in range(n(input())):
  I();t=[];x=0
  for i,j in zip(map(n,I().split()[::-1]),I()[::-1]):
    [i^=k*(i^k<i)for k in t];j=n(j);t+=[i*(j^1)];x|=(i>0)&j
  print(x)

t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    s=input()
    b=[]
    for i in range(n)[::-1]:
        for e in b:
            a[i]=min(a[i],a[i]^e)
        if a[i]:
            if s[i]=="0":
                b+=a[i]
            else:
                print(1)
                break
    else:
        print(0)

I=input
n=int
for i in range(n(input())):
  I();t=[];x=0
  for i,j in zip(map(n,I().split()[::-1]),I()[::-1]):
    for k in t:i^=k*(i^k<i)
    t.append(i*(j:=n(j)^1));x|=(i>0)&j
  print(x)

I=input
n=int
for i in range(n(input())):
  I();t=[];x=0
  for i,j in zip(map(n,I().split()[::-1]),I()[::-1]):
    [i:=(i^k*(i^k<i))for k in t];j=n(j);t+=[i*(j^1)];x|=(i>0)&j
  print(x)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: Given is a string S, where each character is `0`, `1`, or `?`.  Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows:    * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\}  Find the minimum possible unbalancedness of S'.

Submission attempts (in order):
import sys
import numpy as np
from numba import njit

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

@njit('(i4[::1],i4[::1])', cache=True)
def f(S, T):
    m, x, M = 0, 0, 0
    for i in range(len(S)):
        if S[i] == -1:
            x -= 1
        elif S[i] == 1:
            x += 1
        else:
            if x - 1 + T[i] >= m:
                x -= 1
            else:
                x += 1
        m = min(m, x)
        M = max(M, x)
    return M - m

S = np.array(list(read().rstrip().decode()), 'U1')

Si = np.zeros(len(S), np.int32)
Si[S == '0'] = -1
Si[S == '1'] = 1
S = Si

T = S.copy()
T[S == 0] = 1
T = np.cumsum(T)
T = np.minimum.accumulate(T[::-1])[::-1] - T
print(f(S, T))

import sys
import numpy as np
from numba import njit

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

@njit('(i8[::1],i8)', cache=True)
def test(S, A):
    def f(L, R):
        if L > R:
            return False
        for x in S:
            if x == 1:
                L, R = L + 1, R + 1
                if R > A:
                    R -= 2
            elif x == -1:
                L, R = L - 1, R - 1
                if L < 0:
                    L += 2
            else:
                L -= 1
                R += 1
                if L < 0:
                    L += 2
                if R > A:
                    R -= 2
            if L > R:
                return False
        return True

    for parity in (0, 1):
        L, R = 0, A
        if parity == 0:
            R -= A & 1
        else:
            L = 1
            R -= 1 - (A & 1)
        if f(L, R):
            return True
    return False

S = np.array(list(read().rstrip().decode()), 'U1')
Si = np.zeros(len(S), np.int64)
Si[S == '0'] = -1
Si[S == '1'] = 1
S = Si

low = 0  
high = len(S) + 10  
while low + 1 < high:
    x = (low + high) // 2
    if test(S, x):
        high = x
    else:
        low = x

print(high)

Verdicts: Runtime Error

Accepted
Problem: Given is a string S, where each character is `0`, `1`, or `?`.  Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows:    * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\}  Find the minimum possible unbalancedness of S'.

Submission attempts (in order):
from numba import njit
s = input()

@njit
def test(c):
    # current point can be seen as xth smallest val, where x can be any value in [a, b] (subset of [0, c])
    # a <= b
    a, b = 0, c
    ok = True
    discrete = False # when True x = a, a+2, ..., b-2, b
    for si in s:
        if si == '1':
            if a == b == c:
                return False
            a += 1
            b += 1
            if b > c:
                b = c - 1 if discrete else c
        elif si == '0':
            if a == b == 0:
                return False
            a -= 1
            b -= 1
            if a < 0:
                a = 1 if discrete else 0
        else:
            if a == b == 0:
                a = b = 1
            elif a == b == c:
                a = b = c - 1
            elif a == b:
                discrete = True
                a -= 1
                b += 1
            else:
                a -= 1
                b += 1
                if a < 0:
                    a = 1 if discrete else 0
                if b > c:
                    b = c - 1 if discrete else c
    return True


l, r = 0, len(s)
while r - l > 1:
    c = (l + r) // 2
    if test(c):
        r = c
    else:
        l = c
print(r)


from numba import njit
import numpy as np
s = np.array(list(map(lambda x: -1 if x == '?' else int(x), input())))
@njit
def test(c):
    # current point can be seen as xth smallest val, where x can be any value in [a, b] (subset of [0, c])
    # a <= b
    a, b = 0, c
    ok = True
    discrete = False # when True x = a, a+2, ..., b-2, b
    for si in s:
        if si == 1:
            if a == b == c:
                return False
            a += 1
            b += 1
            if b > c:
                b = c - 1 if discrete else c
        elif si == 0:
            if a == b == 0:
                return False
            a -= 1
            b -= 1
            if a < 0:
                a = 1 if discrete else 0
        else:
            if a == b == 0:
                a = b = 1
            elif a == b == c:
                a = b = c - 1
            elif a == b:
                discrete = True
                a -= 1
                b += 1
            else:
                a -= 1
                b += 1
                if a < 0:
                    a = 1 if discrete else 0
                if b > c:
                    b = c - 1 if discrete else c
    return True

l, r = 0, s.size
while r - l > 1:
    c = (l + r) // 2
    if test(c):
        r = c
    else:
        l = c
print(r)


Verdicts: Time Limit Exceeded

Accepted
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):
import sys

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

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

num = 1
for a in A:
	num *= a
	if num > 1000000000000000000:
		print(-1)
		sys.exit()

print(num)
		

import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


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


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

num = 1
for a in A:
    num *= a
    if num > 1000000000000000000:
        print(-1)
        sys.exit()

print(num)


Verdicts: Runtime Error

Accepted
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):
input()
a=1
b=map(int,input().split())
for i in b:
  a*=i
if a>10^18:
  a=-1
print(a)

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

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


Verdicts: Wrong Answer

Runtime Error

Accepted
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=input()
A=input()
a=A.split()
c=1
for i in a:
  c=c*int(i)
if c<(10**8):
  print(c)
else:
  c=-1
  print(c)

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

N=input()
A=input()
a=A.split()
c=1
for i in a:
  c=c*int(i)
if c<(10**8):
  print(c)
else:
  c=-1
  print(c)

def mul2():
    n = int(input())
    a = list(map(int, input().split()))
    
    if 0 in a:
        return 0
    
    ans = 1
    for i in a:
        ans *= i
        if ans > 1000000000000000000:
            return -1
        
    return ans 
mul2()

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

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted
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())

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

result = 1
if 0 in a:
    result = 0
else:
    for i in a:
        result = result * i
        if result > 10**18:
            result = -1
            break
        

print(result)

n = int(input())

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

result = 1
if 0 in a:
    result = 0
else:
    for i in a:
        result = result * i
        if result > 10**18:
            result = -1
            break
        

print(result)

Verdicts: Wrong Answer

Accepted
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())
A = list(map(int, input().split()))

sum = 1
A.sort()
for i in A:
    sum = sum*i
    if sum >= pow(10,18):
        sum = -1
        break
print(sum)

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

sum = 1
A.sort()
for i in A:
    sum = sum*i
    if sum > pow(10,18):
        sum = -1
        break
print(sum)

Verdicts: Wrong Answer

Accepted
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(""))

ar=[]
total=1
big=False

ar = list(map(int, input().strip().split(' ')))

A=len(ar)
      
while big == False:
      for i in range (0,A):
            total=ar[i]*total
            if total>(10^18):
                  big=True
                  break

if big == False:
      print(total)

if total==0:
      big = False
      print("0")

if big == True:
      print("-1")


N=int(input(""))

ar=[]
total=1
big=False

ar = list(map(int, input().strip().split(' ')))

A=len(ar)
      
for i in range (0,A):
      total=ar[i]*total
      if total>(10^18):
            big=True

if big == False:
      print(total)

if total==0:
      big = False
      print("0")

if big == True:
      print("-1")

N=int(input(""))

ar=[]
total=1
big=False
lion = False
A=N-1
ar = list(map(int, input().strip().split(' ')))

if 0 in ar:
      print("0")
      big=True
      lion=False
      
while big == False and lion == False:
      for i in range (0,N):
            total=ar[i]*total
            if i == A:
                  lion = True
            if total>(1000000000000000000):
                  big=True
                  lion=True
                  break

if big == False and lion == True:
      print(total)

if big == True and lion == True:
      print("-1")

Verdicts: Wrong Answer

Wrong Answer

Accepted
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())
a = list(map(int, input().split()))
ans = 1
for i in a:
  ans *= i
  if ans >= 10**18:
    ans = -1
    break
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:
  ans = -1
print(ans)

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
#include <bits/stdc++.h>
using namespace std;

#define REP(i,b) FOR(i,0,b)

#define RREP(i,a) RFOR(i,a,0)


#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)

void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}


#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;

int main()
{
    int n;
    cin>>n;
    ll ans = 1ll;

    bool flag = true;
    REP(i,n) {
        ll nans = ans;
        ll a;
        cin>>a;
        nans *= a;

        if (nans > (ll)1e18 || nans < ans) {
            flag = false;
        }
        ans = nans;
    }
    cout<<(flag || ans == 0 ? ans : -1)<<endl;

    return 0;
}


from sys import stdin
input = stdin.readline

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

for ta in a:
    ans *= ta
    if (ans > 10 ** 18):
        flag = False
        ans = 1

if (flag or ans == 0):
    print(ans)
else:
    print(-1)


Verdicts: Runtime Error

Accepted
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())
a = map(int,input().split())
b =1

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

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

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

for i in range(n):
  b *= a[i]
  if b>=10**18:
    b=-1
    break
  else:
    continue
print(b)

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

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

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

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

if 0 in a:
  b=0
for i in range(n):
  b *= a[i]
  if b>10**18:
    b=-1
    break
  else:
    continue
print(b)


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
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());
ans = 1;
for i in range(n):
    a = int(input())
    ans*=a
if ans>=1000000000000000001:
    print(-1)
else:
    print(ans)

n = int(input());
ans = 1;
lis = list(map(int,input().split()))
flag = False
flag2 = False
for i in range(n):
    if lis[i]==0:
        flag = True
    if ans*lis[i]>=1000000000000000001:
        flag2 = True
    else:
        ans *= lis[i]

if flag:
    print(0)
elif flag2:
    print(-1)
else:
    print(ans)

Verdicts: Runtime Error

Accepted