problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p02642
u815559330
2,000
1,048,576
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.
['N=int(input())\nA=list(map(int,input().split()))\nkey=max(A)+1 \nB=[0]*key \nfor a in A:\n for b in range(a,key,a):\n B[b]+=1 \nans=0\nfor a in A:\n if B[a]==1: \n ans+=1\nprint(ans)', 'N=int(input())\nA=list(map(int,input().split()))\nkey=max(A)+1 \nB=[0]*key \nfor a in A:\n for b in range(a,key,a):\n B[b]+=1 \nans=0\nfor a in A:\n if B[a]==1: \n ans+=1\nprint(ans)']
['Runtime Error', 'Accepted']
['s434711021', 's055607225']
[9032.0, 32380.0]
[27.0, 514.0]
[361, 369]
p02642
u821989875
2,000
1,048,576
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.
['n = int(input())\na = [int(i) for i in input().split()]\na.sort()\ncnt = 0\n\ns = [a[0]]\nfor i in range(1, n):\n s.append(a[i] * s[i-1])\n\nfor i in range(n):\n if i == 0:\n if a[i] != a[i+1]:\n cnt += 1\n continue\n if i != n-1:\n if a[i] % s[i-1] != 0 and a[i+1] != a[i]:\n cnt += 1\n if i == n-1:\n if a[i] % s[i-1] != 0:\n cnt += 1\n\nprint(cnt)\n', 'from collections import Counter\nn = int(input())\na = list(map(int, input().split()))\nc = Counter(a)\nm = [True] * (10**6+1)\ns = list(set(a))\nfor u in s:\n t = u * 2\n while t <= 10 ** 6:\n m[t] = False\n t += u\nr = 0\nfor u in s:\n if c[u] == 1 and m[u] == True:\n r += 1\nprint(r)']
['Runtime Error', 'Accepted']
['s315120630', 's049155038']
[9064.0, 52652.0]
[26.0, 1973.0]
[359, 302]
p02642
u825378567
2,000
1,048,576
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.
['def main1():\n N=int(input())\n A=list(map(int,input().split()))\n A.sort()\n ans=[0]*(10**6)\n for i in range(len(A)-1):\n if ans[i]>=2:\n continue\n if A[i]!=A[i+1]:\n ans[i]+=1\n for j in range(A[i]*2,10**6,A[i]):\n ans[j]=2\n print(ans.count(1))\nmain1()\n', 'def main1():\n N=int(input())\n A=map(int,input().split())\n A.sort()\n ans=[0]*(10**6)\n for i in range(len(A)-1):\n if ans[i]>=2:\n continue\n if A[i]!=A[i+1]:\n ans[i]+=1\n for j in range(A[i]*2,10**6,A[i]):\n ans[j]=2\n print(ans.count(1))\nmain1()', 'def main1():\n N=int(input())\n A=list(map(int,input().split()))\n A.sort()\n ans=[0]*(10**6+1)\n if N ==1 :\n print(1)\n return \n for i in range(len(A)):\n ans[A[i]]+=1\n if ans[A[i]]==1:\n for j in range(A[i]*2,10**6+1,A[i]):\n ans[j]=2\n print(ans.count(1))\nmain1()']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s081864902', 's617755434', 's582225939']
[32380.0, 24600.0, 32240.0]
[230.0, 39.0, 208.0]
[323, 316, 332]
p02642
u826785572
2,000
1,048,576
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.
['n = int(input())\na = list(map(int, input().split()))\n\nM = 1000005\ncnt = [0] * M\n\nfor i in range(n):\n if cnt[i] != 0:\n cnt[i] = 2\n continue\n for j in range(a[i], M, a[i]+1):\n cnt[j] += 1\n\nans = 0\n\nfor i in range(n):\n if cnt[a[i]] == 1:\n ans += 1\n\nprint(ans)', 'n = int(input())\na = list(map(int, input().split()))\n\na.sort()\n\nM = 1000005\ncnt = [0] * M\n\nfor i in range(n):\n if cnt[a[i]] != 0:\n cnt[a[i]] = 2\n continue\n for j in range(a[i], M, a[i]):\n cnt[j] += 1\n\nans = 0\n\nfor i in range(n):\n if cnt[a[i]] == 1:\n ans += 1\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s086187674', 's715382493']
[32048.0, 32164.0]
[2206.0, 411.0]
[293, 307]
p02642
u830054172
2,000
1,048,576
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.
['import math\n\nN = int(input())\nA = sorted(list(map(int, input().split())))\n\nif len(set(A)) == 1:\n print(0)\nelse:\n ju = [True for _ in range(N)]\n\n for i in range(N-1):\n n = i+1\n if not ju[n] or not ju[i]:\n continue\n if A[i] > math.sqrt(A[-1]):\n break\n while n < N:\n if ju[n]:\n if A[n]%A[i] == 0:\n ju[n] = 0\n n += 1\n if A[i] == A[i+1]:\n ju[i] = 0\n print(sum(ju))', 'N = int(input())\nA = sorted(list(map(int, input().split())))\n\nm_a = max(A)+1\ndp = [0]*m_a\n\nfor i in A:\n dp[i] += 1\n if dp[i]==1:\n for j in range(i*2, m_a, i):\n dp[j] += 2\n # print(dp)\nprint(dp.count(1))']
['Wrong Answer', 'Accepted']
['s631096001', 's339402662']
[33108.0, 32252.0]
[2206.0, 496.0]
[499, 229]
p02642
u836311327
2,000
1,048,576
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.
['n = int(input())\na = list(map(int, input().split()))\na.sort()', "def main():\n \n\n n = int(input())\n a = list(map(int, input().split()))\n a.sort()\n count = 0\n while a != []:\n t = a[0]\n if len(a) == 1:\n count +=1\n elif a[0] != a[1]:\n count +=1\n a = [i for i in a if i % t != 0]\n \n\nif __name__ == '__main__':\n main()", "#!/usr/bin/env python3\nimport sys\ndef input(): return sys.stdin.readline().rstrip()\n\n\ndef main():\n n=int(input())\n A=list(map(int, input().split()))\n counts=[0]*(10**6+5)\n for AA in A:\n counts[AA]+=1\n ans=0\n for i in range(1,10**6+5):\n if counts[i]>0:\n for j in range(i+i,10**6+5,i):\n counts[j]=-1\n if counts[i]==1:\n ans+=1\n print(ans)\n \n\n \n \n\n\nif __name__ == '__main__':\n main()\n\n"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s172727799', 's522983735', 's528257183']
[32180.0, 32192.0, 32244.0]
[97.0, 2206.0, 289.0]
[61, 358, 480]
p02642
u840773955
2,000
1,048,576
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.
['M = 10 ** 6 + 5\nN = int(input())\nA_ref = list(map(int, input().split()))\nA = set(M)\nfor i in A_ref:\n A.add(i)\ncnt = [0] * M\nfor i in A:\n for j in range(0, M, i):\n cnt[j] += 1\nans = 0\nfor i in A:\n if(cnt[i] == 1):\n ans += 1\nprint(ans)', 'M = 10 ** 6 + 5\nN = int(input())\nA_ref = list(map(int, input().split()))\nA = set()\nfor i in A_ref:\n A.add(i)\nprint(A)\ncnt = [0] * M\nfor i in A:\n if(cnt[i] > 2):\n continue\n for j in range(i, M, i):\n cnt[j] += 1\nans = 0\nfor i in A:\n if(cnt[i] == 1):\n ans += 1\nprint(ans)', 'M = 10 ** 6 + 5\nN = int(input())\nA = list(map(int, input().split()))\n\ncnt = [0] * M\nfor i in A:\n if(cnt[i] >= 2):\n continue\n for j in range(i, M, i):\n cnt[j] += 1\nans = 0\nfor i in A:\n if(cnt[i] == 1):\n ans += 1\nprint(ans)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s290401808', 's411743147', 's604315824']
[32228.0, 39352.0, 32372.0]
[68.0, 621.0, 878.0]
[256, 301, 251]
p02642
u840920983
2,000
1,048,576
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.
['n=int(input())\na=[int(x) for x in input().split()]\na.sort()\nmax=a[-1]\ndp=[False for _ in range(max+1)]\n\nfor i in a:\n if dp[i]==False:\n for j in range(2,max+1):\n if i*j>max:\n break\n dp[i*j]=True\nfor i in a:\n if a.count(i)>1:\n dp[i]=True\ncnt=0\nfor i in a:\n if dp[i]:\n cnt+=1\n\nprint(cnt)\n\n', 'n=int(input())\na=[int(x) for x in input().split()]\na.sort()\nmax=a[-1]\ndp=[False for _ in range(max+1)]\n\nfor i in a:\n if dp[i]==False:\n j=1\n while 1:\n j+=1\n if i*j>max:\n break\n dp[i*j]=True1\nfor i in a:\n if a.count(i)>1:\n dp[i]=True\ncnt=0\nfor i in a:\n if dp[i]:\n cnt+=1\n\nprint(cnt)\n\n', 'n=int(input())\na=[int(x) for x in input().split()]\na.sort()\nmax=a[-1]\ndp=[False for _ in range(max+1)]', 'n=int(input())\na=[int(x) for x in input().split()]\na.sort()\nmax=a[-1]\ndp=[False for _ in range(max+1)]\n\nfor i in a:\n if dp[i]==False:\n j=1\n while 1:\n j+=1\n if i*j>max:\n break\n dp[i*j]=True\nfor i in range(len(a)-1):\n if a[i]==a[i+1]:\n dp[a[i]]=True\ncnt=0\nfor i in a:\n if dp[i]==False:\n cnt+=1\n\nprint(cnt)\n\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s087184498', 's363557471', 's538184102', 's371603447']
[32116.0, 32172.0, 32184.0, 32132.0]
[2206.0, 2206.0, 134.0, 583.0]
[353, 367, 102, 390]
p02642
u842964692
2,000
1,048,576
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.
['from collections import Counter\n\nN=int(input())\nA=list(map(int,input().split())\n\nC=Counter(A)\n\nA=set(A)\n\nMAX_A=10**6\n\nX=[0]*(MAX_A+1)\n\nfor a in A:\n for i in range(a,MAX_A+1,a):\n X[i]+=1\n\nans=len([a for a in A if (X[1]==1) and (C[a]==1)])\n\nprint(ans)', 'from collections import Counter\n\nN=int(input())\nA=list(map(int,input().split()))\n\nC=Counter(A)\n\nA=set(A)\n\nMAX_A=10**6\n\nX=[0]*(MAX_A+1)\n\nfor a in A:\n for i in range(a,MAX_A+1,a):\n X[i]+=1\n\nans=len([a for a in A if (X[1]==1) and (C[a]==1)])\n\nprint(ans)', 'from collections import Counter\nN = int(input())\nA = list(map(int, input().split()))\nC = Counter(A)\n\nA = set(A)\nMAX_A = 10 ** 6\nX = [0] * (MAX_A + 1)\nfor a in A:\n for i in range(a, MAX_A + 1, a):\n X[i] += 1\n\nans = len([a for a in A if (X[a] == 1) and (C[a] == 1)])\nprint(ans)\n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s193627289', 's267004784', 's187726252']
[8964.0, 50952.0, 51080.0]
[27.0, 1730.0, 1594.0]
[259, 260, 286]
p02642
u844123804
2,000
1,048,576
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.
['num = int(input())\narr = input().split()\narr = [int(i) for i in arr]\n\narr = sorted(arr, reverse=True)\n\ncnt = 0\n\nfor i in range(num):\n flg=0\n for j in range(i+1, num):\n print(arr[i], arr[j])\n if arr[i]%arr[j]==0:\n flg=1\n break\n if flg==1: cnt += 1\n \nprint(cnt)', 'num = int(input())\narr = input().split()\narr = [int(i) for i in arr]\n\narr = sorted(arr, reverse=True)\n\ncnt = 0\n\nfor i in range(num-1):\n flg=0\n for j in range(i+1, num):\n if arr[i]%arr[j]==0:\n flg=1\n break\n if flg==0: cnt += 1\n \nprint(cnt)', 'num = int(input())\narr = input().split()\narr = [int(i) for i in arr]\n\narr = sorted(arr, reverse=True)\n\ncnt = 0\n\nfor i in range(num-1):\n flg=0\n for j in range(num-1, i+1, -1):\n if arr[i]%arr[j]==0:\n flg=1\n break\n if flg==0: cnt += 1\n \nprint(cnt)', 'import math\nnum = int(input())\narr = input().split()\narr = sorted([int(i) for i in arr])\n\nlis1 = [0]*(arr[-1]+1)\n\nfor num in arr:\n for j in range(0, len(lis1), num):\n lis1[j] += 1\n\ncnt = 0\nfor num in arr:\n if lis1[num]==1: cnt+=1\n \nprint(cnt)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s381978197', 's477917075', 's769056728', 's905740406']
[48556.0, 32024.0, 32196.0, 34556.0]
[2662.0, 2206.0, 2206.0, 507.0]
[281, 257, 263, 250]
p02642
u844895214
2,000
1,048,576
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.
["import sys\nfrom numba import njit\n\n@njit(cache+True)\ndef solve(a,n):\n ava = [0]*a[-1]\n for i in range(n):\n for j in range(n):\n if a[j]%a[i]==0 and ava[a[j]-1]<2:\n ava[a[j]-1] += 1\n return ava.count(1)\n \nif __name__=='__main__':\n n = int(sys.stdin.readline().rstrip())\n a = list(map(int,sys.stdin.readline().rstrip().split()))\n a.sort()\n print(solve(a,n))", "import sys\ndef I(): return int(sys.stdin.readline().rstrip())\ndef IL(): return map(int,sys.stdin.readline().rstrip().split())\n\ndef solve():\n m = a[-1]+1\n ava = [0]*m\n for rep in a:\n ava[rep] += 1\n if ava[rep]==1:\n for item in range(rep,n+1,rep):\n ava[item] == 2\n\n print(ava.count(1))\n return\n\nif __name__=='__main__':\n n = I()\n a = list(IL())\n a.sort()\n solve()", "import sys\ndef I(): return int(sys.stdin.readline().rstrip())\ndef IL(): return map(int,sys.stdin.readline().rstrip().split())\n\ndef solve():\n m = a[-1]+1\n ava = [0]*m\n for rep in a:\n ava[rep] += 1\n if ava[rep]==1:\n for item in range(2*rep,m,rep):\n ava[item] += 2\n\n print(ava.count(1))\n return\n\nif __name__=='__main__':\n n = I()\n a = list(IL())\n a.sort()\n solve()"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s550524971', 's681837647', 's116343526']
[91892.0, 32160.0, 32116.0]
[393.0, 303.0, 289.0]
[408, 428, 428]
p02642
u845573105
2,000
1,048,576
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.
['from math import sqrt\n\nN = int(input())\nA = list(map(int, input().split()))\nA.sort()\n#print(A)\nans = []\nres = []\nnans = 0\ndoubling = 0\ni = 0\nwhile i < N:\n a = A[i]\n sqa = sqrt(a)\n #print(i,a)\n if i == 0:\n flag = False\n while i + 1 < N:\n bufa = A[i+1]\n if bufa == a:\n i += 1\n flag = True\n else:\n break\n if flag:\n nans += 1\n doubling += 1\n ans.append(a)\n else:\n nans += 1\n ans.append(a)\n res.append(a)\n elif i < N-1:\n flag = False\n while i + 1 < N:\n bufa = A[i+1]\n if bufa == a:\n i += 1\n flag = True\n else:\n break\n if flag:\n d = 0\n flag2 = True\n while ans[d]<=sqa:\n if a%ans[d] == 0:\n flag2 = False\n break\n if nans -1 == d:\n break\n d += 1\n if flag2:\n nans += 1\n doubling += 1\n ans.append(a)\n else:\n d = 0\n flag2 = True\n while ans[d]<=sqa:\n if a%ans[d] == 0:\n flag2 = False\n break\n if nans -1 == d:\n break\n d += 1\n if flag2:\n nans += 1\n ans.append(a)\n res.append(a)\n else:\n d = 0\n flag2 = True\n while ans[d]<=sqa:\n if a%ans[d] == 0:\n flag2 = False\n break\n if nans -1 == d:\n break\n d += 1\n if flag2:\n nans += 1\n ans.append(a)\n res.append(a)\n i += 1\n \n \nprint(len(res))', 'N = int(input())\nA = list(map(int, input().split()))\n\nA.sort()\nmaxA = A[-1]\ndp = [-1 for i in range(maxA+1)]\nfor a in A:\n if dp[a] != 0:\n if dp[a] == 1:\n dp[a] = 0\n continue\n dp[a] = 1\n for i in range(2*a, maxA+1, a):\n dp[i] = 0\nans = 0\nfor a in A:\n if dp[a] == 1:\n ans += 1\nprint(ans) ']
['Wrong Answer', 'Accepted']
['s303227308', 's481015641']
[32372.0, 32176.0]
[2206.0, 338.0]
[1452, 316]
p02642
u846226907
2,000
1,048,576
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.
['N = int(input())\n\nA = list(map(int,input().split()))\n\n\nb = sorted(list(A))\ndp = [0]*(max(A)+4)\n\nm_a = max(A)\nfor i in b:\n dp[i] += 1\n if dp[i]==1 :\n for j in range(i*2, m_a,i):\n dp[j] +=100\n\nprint(dp.count(1))', 'N = int(input())\n\nA = list(map(int,input().split()))\n\n\nb = sorted(list(A))\ndp = [0]*(max(A)+4)\n\nm_a = max(A)\nfor i in b:\n dp[i] += 1\n if dp[i]==1 :\n for j in range(i*2, m_a,i):\n dp[j*i] +=100\n\nprint(dp.count(1))', 'N = int(input())\nA = list(map(int,input().split()))\n\nA.sort()\n\nm_a = max(A)\ncheck = [0]*(m_a+2)\n\nfor i in A:\n check[i]+=1\n if check[i]==1:\n for j in range(i*2,m_a+1,i):\n check[j]+=100\n\nprint(check.count(1))\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s169252025', 's935383262', 's240554530']
[41296.0, 32240.0, 40252.0]
[585.0, 280.0, 698.0]
[233, 235, 231]
p02642
u854405453
2,000
1,048,576
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.
['_,*p=map(int,open(0).read().split())\ni=0\np.sort()\nwhile(len(p)!=0):\n t=p[0]\n p=[m if m!=t else 0 for m in p[1:] if m%t!=0 or m==t ]\n if 0 in p:\n p=[i for i in p if i!=0]\n else:i+=1\nprint(len(q))', 'M=10**6+1\n_,*l=map(int,open(0).read().split())\na=[0]*M\nfor i in sorted(l):\n a[i]+=1\n if a[i]==1:\n for j in range(2*i,M,i): a[j]+=2\nprint(a.count(1))']
['Runtime Error', 'Accepted']
['s164001279', 's887534977']
[33204.0, 33036.0]
[2206.0, 384.0]
[201, 153]
p02642
u858742833
2,000
1,048,576
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.
['from numba import njit, int32, int64\nfrom numba.typed import Dict\n\n@njit\ndef solve(B):\n A = Dict.empty(\n key_type=int64,\n value_type=int64)\n for b in B:\n A[b] = A.get(b, 0) + 1\n r = 0\n for a, v in A.items():\n if v > 1:\n continue\n if 1 in A:\n continue\n i = 2\n while i * i <= a:\n if a % i == 0:\n if i in A:\n break\n if a // i in A:\n break\n i += 1\n else:\n r += 1\n return r\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n return solve(A)\n\nprint(main())\n', 'from numba import njit, int32, int64\nfrom numba.typed import Dict\n\n@njit\ndef solve(B):\n A = Dict.empty(\n key_type=int64,\n value_type=int64)\n for b in B:\n A[b] = A.get(b, 0) + 1\n r = 0\n for a, v in A.items():\n if v > 1:\n continue\n if a > 1 and 1 in A:\n continue\n i = 2\n while i * i <= a:\n if a % i == 0:\n if i in A:\n break\n if a // i in A:\n break\n i += 1\n else:\n r += 1\n return r\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n return solve(A)\n\nprint(main())\n\n', 'from numba import njit, int32, int64\nfrom numba.typed import Dict\n\n@njit\ndef solve(B):\n A = Dict.empty(\n key_type=int64,\n value_type=int64)\n for b in B:\n A[b] = A.get(b, 0) + 1\n r = 0\n if 1 in A:\n if A[1] == 1:\n return 1\n return 0\n for a, v in A.items():\n if v > 1:\n continue\n i = 2\n while i * i <= a:\n if a % i == 0:\n if i in A:\n break\n if a // i in A:\n break\n i += 1\n else:\n r += 1\n return r\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n return solve(A)\n\nprint(main())\n\n', 'from numba import njit, int32, int64\nfrom numba.typed import Dict\n\n@njit\ndef solve(B):\n A = Dict.empty(\n key_type=int64,\n value_type=int64)\n for b in B:\n A[b] = A.get(b, 0) + 1\n r = 0\n if 1 in A:\n if A[1] == 1:\n return 1\n return 0\n for a, v in A.items():\n if v > 1:\n continue\n i = 2\n while i * i <= a:\n if a % i == 0:\n if i in A:\n break\n if a // i in A:\n break\n i += 1\n else:\n r += 1\n return r\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n return solve(A)\n\nprint(main())\n\n', 'from numba import njit, int32, int64\nfrom numba.typed import Dict\n\n@njit\ndef solve(B):\n A = Dict.empty(\n key_type=int64,\n value_type=int64)\n for b in B:\n A[b] = A.get(b, 0) + 1\n r = 0\n if 1 in A:\n if A[1] == 1:\n return 1\n return 0\n for a, v in A.items():\n if v > 1:\n continue\n i = 2\n while i * i <= a:\n if a % i == 0:\n if i in A:\n break\n if a // i in A:\n break\n i += 1\n else:\n r += 1\n return r\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n return solve(A)\n\nprint(main())\n\n', 'def main():\n N = int(input())\n A = list(map(int, input().split()))\n A.sort()\n dp = [False] * (A[-1] + 1)\n r = 0\n\n for i, a in enumerate(A):\n if dp[a]:\n continue\n dp[a::a] = [True] * len(dp[a::a])\n if i < N - 1 and A[i + 1] == a:\n continue\n r += 1\n return r\n\n\nprint(main())\n']
['Wrong Answer', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted']
['s219052859', 's267644619', 's801053286', 's868558118', 's917945460', 's830530079']
[140688.0, 140444.0, 140520.0, 141216.0, 140656.0, 39420.0]
[1931.0, 2017.0, 2209.0, 2202.0, 2106.0, 195.0]
[670, 681, 706, 706, 706, 344]
p02642
u867200256
2,000
1,048,576
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.
["\nimport collections\nimport sys\nimport math\nimport copy\nimport collections\n\n\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI(): return list(map(int, sys.stdin.readline().rstrip().split()))\ndef S(): return sys.stdin.readline().rstrip()\ndef LS(): return list(sys.stdin.readline().rstrip().split())\n\n\ndef main():\n N = I()\n AArry = LI()\n c = 0\n count_dict = collections.Counter(AArry)\n for k, v in count_dict.items():\n if v > 1:\n c += 1\n\n a = len(AArry)\n AArry = list(set(AArry))\n AArry.sort()\n b = len(AArry)\n count = a-b+c\n\n while AArry:\n l1 = len(AArry)\n a = AArry.pop(0)\n if len(AArry) == 0:\n break\n AArry = [e for e in AArry if e % a == 0]\n l2 = len(AArry)\n count += (l1-l2)\n\n print(N-count)\n\n\nif __name__ == '__main__':\n main()\n", "\nimport collections\nimport sys\nimport math\nimport copy\nimport collections\n\n\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI(): return list(map(int, sys.stdin.readline().rstrip().split()))\ndef S(): return sys.stdin.readline().rstrip()\ndef LS(): return list(sys.stdin.readline().rstrip().split())\n\n\ndef main():\n N = I()\n AArry = LI()\n AArry.sort()\n count = 0\n li = [0 for _ in range(10**6+2)]\n\n for i, v in enumerate(AArry):\n a = v\n if li[a] == 1:\n count += 1\n if li[a] == 0:\n if i != N-1 and AArry[i+1] == a:\n count += 1\n\n for j in range(a, 10**6+2, a):\n li[j] = 1\n\n print(N-count)\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s480365788', 's001526519']
[46056.0, 32852.0]
[163.0, 320.0]
[884, 771]
p02642
u867408000
2,000
1,048,576
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.
['n = int(input())\noriginal_ary = sorted(list(map(int, input().split())))\n\nbool_ary = [0] * original_ary[-1]\n\nfor num in original_ary:\n bool_ary[num-1] += 1\n if bool_ary[num-1] == 1:\n for multiple in range(num * 2, original_ary[-1], num):\n bool_ary[multiple-1] = 2\n\nprint(bool_ary.count(1))', 'n = int(input())\nrow_ary = list(map(int,input().split()))\n\nif 2 in row_ary:\n row_ary = [x for x in set(row_ary) if x % 2 == 1]\n row_ary.append(2)\n\nary = [x for x in set(row_ary) if row_ary.count(x) == 1]\n\n\nary.sort(reverse=True)\n\ndel_list_index = []\n\nprint(ary)\n\nfor i in range(len(ary)):\n for j in range(i+1, len(ary)):\n if ary[i] % ary[j] == 0:\n del_list_index.append(i)\n\nfor index in sorted(set(del_list_index), key=del_list_index.index,reverse=True):\n\tary.pop(index)\n\nprint(len(ary))', 'n = int(input())\noriginal_ary = sorted(list(map(int, input().split())))\n\nbool_ary = [0] * original_ary[-1]\n\nfor num in original_ary:\n bool_ary[num-1] += 1\n if bool_ary[num-1] == 1:\n for multiple in range(num * 2, original_ary[-1]+1, num):\n bool_ary[multiple-1] = 2\n\nprint(bool_ary.count(1))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s620179306', 's800705539', 's028375184']
[32232.0, 32232.0, 32204.0]
[387.0, 2206.0, 378.0]
[312, 510, 315]
p02642
u879921371
2,000
1,048,576
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.
['def main():\n n=int(input())\n a=sorted(map(int,input().split()))\n maxa=a[-1]+1\n tf=[False]*maxa\n r=0\n n-=1\n for i in range(n):\n a_i=a[i]\n if tf[a_i] ==False:\n for j in range(a_i,maxa,a_i):\n tf[j]=True\n if a_i < a[i+1]:\n r+=1\n if tf[n] ==False:\n r+=1\n print(r)\nmain()', 'def main():\n n=int(input())\n a=sorted(map(int,input().split()))\n maxa=a[-1]+1\n tf=[False]*maxa\n r=0\n n-=1\n for i in range(n):\n a_i=a[i]\n if tf[a_i] ==False:\n for j in range(a_i,maxa,a_i):\n tf[j]=True\n if a_i < a[i+1]:\n print(a_i)\n r+=1\n if tf[-1] ==False:\n r+=1\n print(tf)\nmain()', 'def main():\n n=int(input())\n a=sorted(map(int,input().split()))\n maxa=a[-1]+1\n tf=[False]*maxa\n r=0\n n-=1\n for i in range(n):\n a_i=a[i]\n if tf[a_i] ==False:\n for j in range(a_i,maxa,a_i):\n tf[j]=True\n if a_i < a[i+1]:\n #print(a_i)\n r+=1\n if tf[-1] ==False:\n r+=1\n print(r)\nmain()']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s524703701', 's643715144', 's136041388']
[32168.0, 42720.0, 32376.0]
[207.0, 317.0, 194.0]
[307, 328, 328]
p02642
u880480312
2,000
1,048,576
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.
['#<D>\nn = int(input())\na = list(map(int,input().split()))\nc=a\nans=0\nb=0\nfor i in range(n):\n b=a[i]\n a=set(a)\n a=[b%x for x in a]\n if a.count(0) > 1:\n ans+=1\n a=c\nprint(ans)', 'n = int(input())\nA = list(map(int,input().split()))\nd = {}\nfor a in A:\n d.setdefault(a,0)\n d[a] += 1 \n\nA = sorted(set(A))\nt = [True] * (10 ** 6 + 1)\nprint(d)\nfor a in A:\n if d[a] > 1:\n t[a] = False\n for i in range(a+a, 10 ** 6 + 1, a):\n t[i] = False\nprint(sum(1 for a in A if t[a]==True))', 'n = int(input())\nA = list(map(int,input().split()))\nd = {}\nfor a in A:\n d.setdefault(a,0)\n d[a] += 1 \n\nA = sorted(set(A))\nt = [True] * (10 ** 6 + 1)\n\nfor a in A:\n if d[a] > 1:\n t[a] = False\n for i in range(a+a, 10 ** 6 + 1, a):\n t[i] = False\nprint(sum(1 for a in A if t[a]==True))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s475906110', 's803988104', 's036621629']
[39772.0, 44216.0, 44216.0]
[2206.0, 1638.0, 1587.0]
[193, 647, 639]
p02642
u884323674
2,000
1,048,576
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.
['import numpy as np\n\nN = int(input())\nA = sorted([int(i) for i in input().split()])\na = collections.Counter(A)\nA = np.array([i[0] for i in a.items() if i[1] == 1])\n\nif len(A) == 0:\n print(0)\nelse:\n dp = np.array([True for i in range(A[-1])])\n dp[:A[0]-1] = False\n ans = 0\n for i in range(A[-1]):\n if i+1 in A and dp[i] == True:\n n = i+1\n dp[A[np.where(A % n == 0)[0]]-1] = False\n dp[i] = True\n else:\n dp[i] = False\n print(np.sum(dp))', 'import collections\n\nN = int(input())\nA = sorted([int(i) for i in input().split()])\n\nlimit = int(A[-1] ** 0.5)\nans = 0\nwhile limit > A[0]:\n if len(A) == 1:\n ans += 1\n elif A[0] != A[1]:\n ans += 1\n A = [i for i in A if i % A[0] != 0]\n \na = collections.Counter(A)\nprint(ans + len([i[0] for i in a.items() if i[1] == 1]))', 'from collections import Counter\n\nN = int(input())\nA = [int(i) for i in input().split()]\nnum = set(A)\ncount = Counter(A)\ndp = [True] * (10**6 + 1)\n\nfor a in num:\n for n in range(a+a, 10**6+1, a):\n dp[n] = False\n\nans = 0\nfor a in num:\n if count[a] == 1 and dp[a] == True:\n ans += 1\n\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s087712632', 's447775255', 's432120878']
[51560.0, 35920.0, 50728.0]
[195.0, 2019.0, 1320.0]
[508, 343, 311]
p02642
u886297662
2,000
1,048,576
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.
['N = int(input())\nA = list(map(int, input().split()))\n\nA.sort()\ncnt = [0] * (A[-1]+1)\n\nfor a in A:\n cnt[::a] += 1\n\nans = 0\nfor a in A:\n if cnt[a] == 1:\n ans += 1\n\nprint(ans)', 'N = int(input())\nA = list(map(int, input().split()))\n\nA.sort()\ncnt = [0] * (A[-1]+1)\n\nfor a in A:\n for i in range(a, A[-1]+1, a):\n cnt[i] += 1\n\nans = 0\nfor a in A:\n if cnt[a] == 1:\n ans += 1\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s297637413', 's511438696']
[32272.0, 32308.0]
[108.0, 423.0]
[177, 210]
p02642
u896451538
2,000
1,048,576
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.
['n = int(input())\na = list(map(int,input().split()))\na.sort()\nm = a[-1]\nl = [True]*(m+1)\n\nans=0\na.sort()\nfor i in range(n):\n if l[a[i]]:\n for j in range(i,m,a[i]):\n l[j]=False\n if i==n-1:\n ans+=1\n break\n if a[i]!=a[i+1]:\n ans+=1\nprint(ans)', 'n = int(input())\na = list(map(int,input().split()))\na.sort()\nm = a[-1]\nl = [True]*(m+1)\n\nans=0\na.sort()\nfor i in range(n):\n if l[a[i]]:\n for j in range(i,m+1,a[i]):\n l[j]=False\n if i==n-1:\n ans+=1\n break\n if a[i]!=a[i+1]:\n ans+=1\nprint(ans)', '\nn = int(input())\na = list(map(int,input().split()))+[10**7]\na.sort()\nl = [True]*(10**6+1)\n\nans=0\na.sort()\nfor i in range(n):\n if l[a[i]]:\n for j in range(a[i],10**6+1,a[i]):\n l[j]=False\n if a[i]!=a[i+1]:\n ans+=1\nprint(ans)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s349507700', 's766745297', 's402083975']
[32384.0, 32176.0, 32380.0]
[338.0, 255.0, 284.0]
[306, 308, 263]
p02642
u896726004
2,000
1,048,576
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.
['N = int(input())\nA = list(map(int, input().split()))\n\nA = sorted(A, key=lambda x: x[0])\nmaxi = 2*(10**5)+1\ndp = [0] * maxi\n\nfor i in range(N):\n tmp = A[i]\n if dp[tmp] != 0:\n dp[tmp] = 2\n continue\n else:\n for j in range(tmp, maxi, tmp):\n dp[j] += 1\n\nans = 0\nfor i in range(N):\n tmp = A[i]\n if dp[tmp] == 1:\n ans += 1\n\nprint(ans)', 'N = int(input())\nA = list(map(int, input().split()))\n\nA = sorted(A)\nmaxi = 10**6+1\ndp = [0] * maxi\n\nfor i in range(N):\n tmp = A[i]\n if dp[tmp] != 0:\n dp[tmp] = 2\n continue\n else:\n for j in range(tmp, maxi, tmp):\n dp[j] += 1\n\nans = 0\nfor i in range(N):\n tmp = A[i]\n if dp[tmp] == 1:\n ans += 1\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s145622159', 's420129588']
[32028.0, 32188.0]
[70.0, 438.0]
[381, 357]
p02642
u902544771
2,000
1,048,576
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.
['n = int(input())\na = [int(i) for i in input().split(" ")]\n\na.sort()\ndp = [True for i in range(a[-1]+1)]\ncount=0\n\nfor i in range(n):\n if dp[a[i]]:\n count+=1\n for j in range(1,n-i):\n if a[i]!=a[i+j]:\n break\n elif j==1:\n count-=1\n dp[a[i+j]]=False\n for j in range(a[i], a[-1], a[i]):\n dp[j]=False\n # for j in range(i + 1, n):\n # if not a[j] % a[i]:\n # dp[j] = False\n # if a[j] == a[i]:\n # dp[i] = False\n\n#print(dp.count(True))\nprint(count)', 'n = int(input())\na = [int(i) for i in input().split(" ")]\n\nmax_a = max(a)\ndp = [0] * (max_a + 1)\n\nfor i in a:\n for j in range(i, max_a + 1, i):\n dp[j] += 1\n\nout = 0\nfor i in a:\n if dp[i] == 1:\n out += 1\n\nprint(out)']
['Wrong Answer', 'Accepted']
['s043271834', 's921454482']
[32180.0, 32060.0]
[371.0, 524.0]
[593, 234]
p02642
u909514237
2,000
1,048,576
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.
['N = int(input())\nAList = list(map(int, input().split()))\nif AList.count(AList[0]) == N:\n print(0)\n exit()\n \nsortList = list(sorted(set(AList)))\nAmax = max(sortList)\ndp = [True] * (Amax+1)\n\nidx = 0\nfor n in sortList:\n if dp[n] == True:\n for j in range(n*2, Amax, n):\n dp[j] = False\nansCount = 0\nfor n in sortList:\n if dp[n] == True:\n ansCount += 1\nprint(ansCount)', 'N = int(input())\nAList = list(map(int, input().split()))\nif AList.count(AList[0]) == N:\n print(0)\n exit()\n \nsortList = list(sorted(set(AList)))\nAmax = max(sortList)\ndp = [True] * Amax\n\nidx = 0\nfor n in sortList:\n if dp[n-1] == False:\n continue\n j = 2\n while j*n < Amax:\n dp[n*j -1] = False\n j += 1\nansCount = 0\nfor n in sortList:\n if dp[n-1] == True:\n ansCount += 1\n\nprint(ansCount)', 'N = int(input())\nAList = list(map(int, input().split()))\n\nsortList = sorted(AList)\nAmax = max(sortList)\n\ndp = [0]*(Amax+1)\n\nfor n in sortList:\n dp[n] += 1\n if dp [n] == 1:\n for i in range(n*2, Amax+1, n):\n dp[i] += 2\n\nprint(dp.count(1))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s477166944', 's795404689', 's265504346']
[32524.0, 32568.0, 32028.0]
[319.0, 687.0, 446.0]
[378, 401, 246]
p02642
u919017918
2,000
1,048,576
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.
['import math\nN = int(input())\nA = list(map(int, input().split()))\nA.sort()\nmaxA = A[-1]+1\n#print(N, A, maxA)\ndp = [1 for a in range(maxA)]\n#print(dp)\nfor a in range(maxA):\n if a in A and dp[a] == 1:\n tgt = math.sqrt(maxA)\n b = 2\n while b*a < maxA:\n dp[a*b] = 0\n b += 1\n print(b, tgt)\n#print(dp)\nmyans = 0\nfor n in range(N):\n myans += dp[A[n]]\nprint(myans)', '# coding: utf-8\n# Your code here!\nimport math\nimport sys\nN = int(input())\nA = list(map(int, input().split()))\n#A.sort()\na_dic = {}\nfor n in range(N):\n if A[n] in a_dic:\n a_dic[A[n]] += 1\n else:\n a_dic[A[n]] = 1\n#print(a_dic)\nA = list(set(A))\nA.sort()\n#print(A)\nmaxA = max(A)\ndp = [1 for i in range(maxA+1)]\nans = 0\nfor a in A:\n if dp[a] == 1 and a_dic[a] == 1:\n ans += 1\n j = a + a\n while j <= maxA:\n dp[j] = 0\n j += a\n print(j)\n#print(dp)\nprint(ans)', '# coding: utf-8\n# Your code here!\nimport math\nimport sys\nN = int(input())\nA = list(map(int, input().split()))\n#A.sort()\na_dic = {}\nfor n in range(N):\n if A[n] in a_dic:\n a_dic[A[n]] += 1\n else:\n a_dic[A[n]] = 1\n#print(a_dic)\nA = list(set(A))\nA.sort()\n#print(A)\nmaxA = max(A)\ndp = [1 for i in range(maxA+1)]\nans = 0\nfor a in A:\n if dp[a] == 1 and a_dic[a] == 1:\n ans += 1\n j = a + a\n while j <= maxA:\n dp[j] = 0\n j += a\n #print(j)\n#print(dp)\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s144695685', 's847221818', 's959504413']
[58528.0, 46400.0, 44672.0]
[2271.0, 1397.0, 607.0]
[414, 507, 508]
p02642
u930574673
2,000
1,048,576
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.
['from math import ceil\n\nX, N = [int(x) for x in input().split()]\nl = [int(x) for x in input().split()]\nl2 = [abs(int(x)-X) for x in l]\nl2.sort()\nfor i in range(N):\n if ceil(i/2) != l2[i]:\n t = ceil(i/2)\n break\nif X - t in l:\n print(X + t)\nelse:\n print(X - t)', 'N = int(input())\nl = [int(x) for x in input().split()] + [1000001]\nl.sort()\nans = 0\nt = 0\nM = [False] * 10 ** 6\nfor i in range(N):\n if not M[l[i]-1]:\n if l[i] != l[i+1]:\n ans += 1\n t = l[i]\n while t <= 10 ** 6:\n M[t-1] = True\n t += l[i]\nprint(ans)']
['Runtime Error', 'Accepted']
['s441101276', 's042305009']
[9208.0, 32328.0]
[24.0, 701.0]
[280, 304]
p02642
u946346344
2,000
1,048,576
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.
['import sys\n\ndef input():\n return sys.stdin.readline().strip()\n\ndef main():\n x, n= map(int, input().split())\n if n == 0:\n print(x)\n return\n P=[]\n P = list(map(int, input().split()))\n \n for i in range(100):\n a = x-i\n b = x+i\n if a not in P:\n print(a)\n return\n elif b not in P:\n print(b)\n return\n \n\n\nmain()\n\n', 'import sys\n\ndef input():\n return sys.stdin.readline().strip()\n\ndef main():\n n = int(input())\n A = list(map(int, input().split()))\n M = max(A)\n B = [0]*(M+1)\n ans = 0\n A.sort()\n \n for i in A:\n B[i] += 1\n \n for i in A:\n if B[i] == 1:\n ans += 1\n for j in range(i, M+1, i):\n B[j] += 1\n \n print(ans)\n\nmain()']
['Runtime Error', 'Accepted']
['s533376990', 's425197308']
[9204.0, 32384.0]
[24.0, 366.0]
[415, 384]
p02642
u950825280
2,000
1,048,576
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.
['n = int(input())\na = list(map(int, input().split()))\na = list(set(a))\na.sort()\nans = 0\nif len(a) == 1:\n print(0)\nelse:\n for _ in range(n):\n m = a.pop()\n ind = True\n print(a)\n for i in a:\n if m % i == 0:\n ind = False\n break\n if ind:\n ans += 1\n print(ans)\n', 'n = int(input())\na = list(map(int, input().split()))\nm = max(a)\ny = [0] * (m + 1)\nfor i in a:\n x = i\n while x <= m:\n y[x] += 1\n x += i\nans = 0\nfor j in a:\n if y[j] == 1:\n ans += 1\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s360580464', 's344320506']
[143660.0, 31948.0]
[2393.0, 639.0]
[350, 221]
p02642
u956433805
2,000
1,048,576
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.
['N = int(input())\nA = list(map(int,input().split()))\n\nA = sorted(A, reverse = True)\nans = 0\n\nif A.count(A[-1]) != 0:\n ans = -1 \n\nfor i in range(N):\n flag = 0\n a = i\n for j in range(a,N):\n if i == j:\n continue\n if A[i] % A[j] == 0:\n flag = 1\n break\n if A[i] < A[j]:\n break\n j += 1\n if flag == 0:\n #print(A[i])\n ans += 1\n\nprint(ans)', 'import collections\n\nn=int(input())\narr=list(map(int,input().split()))\narr=sorted(arr) \ns=set()\ncnt=collections.Counter(arr) \nfor i in range(n):\n if arr[i] in s: \n continue\n if cnt[arr[i]]>=2: \n s.add(arr[i])\n for j in range(2,10**6//arr[i]+1): \n s.add(arr[i]*j)\nans=0\nfor i in range(n): \n if arr[i] in s:\n continue\n ans+=1\nprint(ans)']
['Wrong Answer', 'Accepted']
['s670204121', 's443766461']
[32300.0, 103016.0]
[2206.0, 775.0]
[430, 681]
p02642
u959682820
2,000
1,048,576
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.
['n = int(input())\na = list(map(int, input().split()))\n\nMAX = 1000005\ncnt = [0] * MAX\nfor x in a:\n if cnt[x] != 0:\n continue\n \n for i in range(x, MAX, x):\n cnt[i] += 1\nans = 0\nfor x in a:\n if cnt[x] == 1:\n ans += 1\n\nprint(ans)', 'n = int(input())\na = list(map(int, input().split()))\n\nMAX = 1000005\ncnt = [0] * MAX\nfor x in a:\n if cnt[x] != 0:\n cnt[x] = 2\n continue\n \n for i in range(x, MAX, x):\n cnt[i] += 1\nans = 0\nfor x in a:\n if cnt[x] == 1:\n ans += 1\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s192284159', 's384135331']
[32404.0, 31896.0]
[496.0, 596.0]
[296, 315]
p02642
u966207392
2,000
1,048,576
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.
['N = int(input())\nA = list(map(int, input().split()))\ncount = 0\nres = []\n\nfor i in range(N):\n for j in range(N):\n if j == i:\n continue\n elif (A[i] % A[j]) == 0:\n res.append(A[j])\n break\n \n else:\n if len(res) == 0:\n count += 1\n else:\n res.clear()\n\nprint(count)', 'N = int(input())\nA = list(map(int, input().split()))\n \nM = 10**6 + 1\n \ncnt = [0] * M\n \nfor a in A:\n if cnt[a] != 0:\n continue\n for b in range(a, M, a):\n cnt[b] += 1\n \nans = 0\nfor a in A:\n if cnt[a] == 1:ans += 1\n \nprint(ans)', 'N = int(input())\nA = list(map(int, input().split()))\ncount = 0\n\nfor i in range(N):\n for j in range(N):\n if j == i:\n continue\n elif (A[i] % A[j]) == 0:\n continue\n else:\n count += 1\n break\n\nprint(count)', 'N = int(input())\nA = list(map(int, input().split()))\ncount = 0\nres = []\n\nfor i in range(N):\n for j in range(N):\n if j == i:\n continue\n elif (A[i] % A[j]) == 0:\n res.append(A[j])\n break\n else:\n continue\n \n else:\n if len(res) == 0:\n count += 1\n else:\n res.clear()\n\nprint(count)', 'N = int(input())\nA = list(map(int, input().split()))\ncount = 0\n\nfor i in range(N):\n for j in range(N):\n if j == i:\n continue\n elif (A[i] % A[j]) = 0:\n continue\n else:\n count += 1\n break\n\nprint(count)', 'N = int(input())\nA = list(map(int, input().split()))\n \nM = 10**6 + 1\n \ncnt = [0] * M\n \nfor a in A:\n if cnt[a] != 0:\n cnt[a] += 1\n continue\n for b in range(a, M, a):\n cnt[b] += 1\n \nans = 0\nfor a in A:\n if cnt[a] == 1:ans += 1\n \nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s148690984', 's354540902', 's362216052', 's385254913', 's931258913', 's459906208']
[32248.0, 32256.0, 32056.0, 32380.0, 8964.0, 32232.0]
[2206.0, 505.0, 2206.0, 2206.0, 26.0, 534.0]
[354, 247, 268, 389, 267, 267]
p02642
u966542724
2,000
1,048,576
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.
['n = int(input())\na = [int(i) for i in input().split()]\n\n\nl = [0] * max(a)\n\n\nfor i in a:\n\n c = 2\n while True:\n if i*c-1 >= max(a):\n break\n l[i*c - 1] += 1\n c += 1\n\n\n\nans = 0\n\nfor i in set(a):\n if l[i] == 1:\n ans += 1\n\nprint(ans)\n', 'n = int(input())\na = [int(i) for i in input().split()]\n\nmaxa = max(a)\nl = [0] * (maxa+1)\n\n\nfor i in a:\n\n c = 1\n while True:\n if i*c >= maxa+1:\n break\n l[i*c - 1] += 1\n c += 1\n\n\n\n\n\n\n\nans = 0\n\nfor i in set(a):\n if l[i-1] == 1:\n ans += 1\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s577557095', 's129205626']
[31972.0, 39372.0]
[2206.0, 887.0]
[276, 295]
p02642
u970133396
2,000
1,048,576
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.
['from collections import Counter\nfrom numba import jit\n\nn = int(input().strip())\nL = list(map(int, input().strip().split()))\nseen = Counter()\nans=0\n\nfor x in L:\n seen[x]+=1\n@jit\ndef loop():\n ans=0\n for x in L:\n if seen[x]>1 or x!=1 and 1 in seen:\n continue\n \n tmp=2\n while tmp**2<=x:\n if x%tmp and (tmp in seen or x/tmp in seen):\n break\n tmp+=1\n else:\n ans+=1\n return ans\nprint(loop())', "from collections import Counter\nfrom numba import jit\n\ndef main():\n n = int(input().strip())\n L = list(map(int, input().strip().split()))\n seen = Counter()\n \n \n for x in L:\n seen[x]+=1\n @jit\n def loop():\n ans=0\n for x in L:\n if seen[x]>1 or x!=1 and 1 in seen:\n continue\n \n tmp=2\n while tmp**2<=x:\n if x%tmp==0 and (tmp in seen or x/tmp in seen):\n break\n tmp+=1\n else:\n ans+=1\n return ans\n print(loop())\n# print(ans)\n \nif '__main__' == __name__:\n main()", "def main():\n n = int(input().strip())\n L = list(map(int, input().strip().split()))\n L.sort()\n max_=L[-1]\n isDivisible = [False]*(max_) # 1-Lmax\n \n for i,x in enumerate(L):\n if i!=n-1 and x==L[i+1]:\n isDivisible[x-1]=True\n continue\n j=2*x\n while j<=max_:\n isDivisible[j-1]=True\n j+=x\n ans=0\n for x in L:\n if not isDivisible[x-1]:\n ans+=1\n print(ans)\n# print(ans)\n \nif '__main__' == __name__:\n main()"]
['Wrong Answer', 'Time Limit Exceeded', 'Accepted']
['s759183081', 's934305518', 's317723679']
[161628.0, 161432.0, 32260.0]
[2210.0, 2210.0, 410.0]
[486, 644, 517]
p02642
u970308980
2,000
1,048,576
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.
['\ndef is_prime(n):\n if n == 1:\n return False\n for i in range(2,int(n**0.5)+1):\n if n % i == 0:\n return False\n return True\n\n\nN = int(input())\nA = list(map(int, input().split()))\n\nD = defaultdict(int)\nfor a in A:\n D[a] += 1\n\nL = []\nfor k, v in D.items():\n if v > 1:\n continue\n L.append(k)\n\nif len(L) == 0:\n print(0)\n exit()\n\nL.sort()\n\nans = set()\nfor n in L:\n if is_prime(n):\n ans.add(n)\n flg = True\n for s in ans:\n if n % s == 0:\n flg = False\n break\n if flg is False:\n continue\n ans.add(n)\n\nprint(len(ans))\n', '\nimport sys\nfrom collections import defaultdict\n\nsys.setrecursionlimit(10 ** 7)\n# ----------\n\nINF = float("inf")\nMOD = 10 ** 9 + 7\n# ----------\n\nN = int(input())\nA = sorted(map(int, input().split()))\n\nif N == 1:\n print(1)\n exit()\n\nif A[0] == A[1] == 1:\n print(0)\n exit()\nif A[0] == 1:\n print(1)\n exit()\n\n\nS = set()\n\nfor a in A:\n i = 2\n while a * i <= 10 ** 6:\n S.add(a * i)\n i += 1\n\nans = []\nfor a in A:\n if not a in S:\n ans.append(a)\n\n\nD = defaultdict(int)\nfor a in ans:\n D[a] += 1\n\nL = []\nfor k, v in D.items():\n if v > 1:\n continue\n L.append(k)\n\n\nprint(len(L))\n\n\n']
['Runtime Error', 'Accepted']
['s429731096', 's498737255']
[32400.0, 82716.0]
[66.0, 974.0]
[619, 629]
p02642
u971124021
2,000
1,048,576
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.
['n = int(input())\na= list(map(int,input().split()))\n\na.sort()\ndp = [1] * n\n\ndef div(k):\n global dp\n if dp[k] != 0:\n for i in range(k):\n if a[k]%a[i] == 0:\n dp[k] = 0\n if a[k] == a[i]:dp[i] = 0\n break\n if k < n-1:div(k+1)\n\ndiv(1)', 'n = int(input())\na= list(map(int,input().split()))\nif n == 1:\n print(n)\n exit()\n\na.sort()\ndp = [1] * n\n\ndef div(k):\n global dp\n if k < n-1:div(k+1)\n\ndiv(1)\nprint(sum(dp))', 'n = int(input())\na= list(map(int,input().split()))\nif n == 1:\n print(n)\n exit()\n\na.sort()\nif a[0] == 1:\n print(n)\n exit()\n', 'n = int(input())\na= list(map(int,input().split()))\nif n == 1:\n print(n)\n exit()\n\na.sort()\nif a[0] == 1:\n print(1)\n exit()\n', 'n = int(input())\na= list(map(int,input().split()))\n\na.sort()\ndp = [1] * n\n\ndef div(k):\n global dp\n if dp[k] != 0:\n for i in range(k):\n if a[k]%a[i] == 0:\n dp[k] = 0\n if a[k] == a[i]:dp[i] = 0\n break\n if k < n-1:div(k+1)\n', 'from collections import Counter\nn = int(input())\na= list(map(int,input().split()))\nif n == 1:\n print(1)\n exit()\n\na.sort()\nif a[0] == 1:\n print(1)\n exit()\n\nc = Counter(a)\na = list(set(a))\ndp = [0] * (10+1)\n\nfor x in a:\n t = x * 2\n while t <= 10:\n dp[t] = 1\n t += x\n\nans = 0\nfor x in a:\n if (c[x] == 1) & (dp[x] == 0):\n ans += 1\n\nprint(ans)', 'from collections import Counter\nn = int(input())\na= list(map(int,input().split()))\nif n == 1:\n print(1)\n exit()\n\na.sort()\n\nc = Counter(a)\na = list(set(a))\ndp = [0] * (10**6 +1)\n\nfor x in a:\n t = x * 2\n while t <= 10**6:\n dp[t] = 1\n t += x\n\nans = 0\nfor x in a:\n if (c[x] == 1) & (dp[x] == 0):\n ans += 1\n\nprint(ans)\n']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s148195195', 's188226943', 's614970750', 's709789178', 's748007723', 's950725987', 's754385339']
[32368.0, 31988.0, 32340.0, 32192.0, 32168.0, 43380.0, 45052.0]
[155.0, 114.0, 108.0, 107.0, 109.0, 191.0, 1818.0]
[261, 174, 126, 126, 254, 354, 328]
p02642
u971531055
2,000
1,048,576
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.
['n = int(input())\na_i = list(map(int,input().split()))\n\ndef solve():\n ans = 0\n count = 0\n for i in range(1, 1000001):\n if i in a_i:\n for j in range(n):\n if i != a_i[j] and i % a_i[j] == 0:\n break\n else:\n ans += 1\n count += 1\n if count == n:\n break\n return ans\n\nprint(solve())', 'n = int(input())\na = list(map(int,input().split()))\nnum_list = [0] * 1000001\n \ndef solve():\n ans = 0\n for i in range(n):\n if num_list[a[i]] == 0:\n num_list[a[i]] += 1\n for j in range(2, (1000000 // a[i]) + 1):\n num_list[j * a[i]] += 1\n elif num_list[a[i]] == 1:\n num_list[a[i]] += 1\n for i in range(n):\n if num_list[a[i]] == 1:\n ans += 1\n return ans\n \nprint(solve())']
['Wrong Answer', 'Accepted']
['s793542744', 's812704873']
[32176.0, 32232.0]
[2206.0, 622.0]
[389, 458]
p02642
u978167553
2,000
1,048,576
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.
['n = int(input())\na = [int(stdins) for stdins in input().split()]\n\na.sort()\n\nans = n\nfor i in range(n):\n for j in range(n):\n if a[i] % a[j] == 0:\n ans -= 1\n break\n\nprint(ans)\n', '# ABC170\n\nn = int(input())\na = list(map(int, input().split()))\n\na.sort()\na_max = max(a)\ndp = [True for _ in range(a_max+1)]\n\nans = 0\nfor i in range(n):\n if dp[a[i]]:\n for j in range(0, a_max+1, a[i]):\n dp[j] = False\n if i > 0:\n if a[i] == a[i-1]:\n continue\n if i < n-1:\n if a[i] == a[i+1]:\n continue\n ans += 1\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s019052178', 's051940009']
[32164.0, 32368.0]
[2206.0, 377.0]
[206, 416]
p02642
u978531093
2,000
1,048,576
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.
["import collections\n\n\ndef main():\n _ = int(input())\n A = list(map(int, input().split()))\n\n A.sort()\n\n sames = 0\n C = collections.Counter(A)\n for v in C.values():\n if v > 1:\n sames += 1\n\n a_max = A[-1]\n dp = [True] * a_max\n A = set(A)\n\n for a in A:\n if dp[a - 1]:\n tmp_a = a * 2\n while tmp_a < a_max:\n dp[tmp_a - 1] = False\n tmp_a += a\n\n r = 0\n for a in A:\n if dp[a - 1]:\n r += 1\n\n print(r - sames)\n\n\nif __name__ == '__main__':\n main()\n", "import collections\n\n\ndef main():\n _ = int(input())\n A = list(map(int, input().split()))\n\n A.sort()\n\n sames = 0\n C = collections.Counter(A)\n for v in C.values():\n if v > 1:\n sames += 1\n\n a_max = A[-1]\n dp = [True] * a_max\n A = set(A)\n\n if dp[a - 1]:\n tmp_a = a * 2\n while tmp_a < a_max + 1:\n dp[tmp_a - 1] = False\n tmp_a += a\n\n r = 0\n for a in A:\n if dp[a - 1]:\n r += 1\n\n print(r - sames)\n\n\nif __name__ == '__main__':\n main()", "def main():\n _ = int(input())\n A = list(map(int, input().split()))\n\n A.sort()\n a_max = A[-1]\n dp = [0] * (a_max + 1)\n\n for a in A:\n if dp[a] != 0:\n dp[a] = 2\n continue\n\n i = a\n while i < a_max + 1:\n dp[i] += 1\n i += a\n\n r = 0\n for a in A:\n if dp[a] == 1:\n r += 1\n\n print(r)\n\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Runtime Error', 'Accepted']
['s353339611', 's376019726', 's892882505']
[51196.0, 50908.0, 32120.0]
[331.0, 201.0, 415.0]
[571, 542, 423]
p02642
u981309686
2,000
1,048,576
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.
['from collections import Counter\ninp = list(map(int,input().split()))\nc=Counter(inp)\ninp=[]\nfor item in c.keys():\n if c[item]==1:\n inp.append(item)\narr=[1]*len(inp)\ninp.sort()\nans=0\nfor i in range(len(inp)):\n if arr[i]==0:\n continue\n else:\n ans+=1\n \tfor j in range(i+1,len(inp)):\n if inp[j]%inp[i]==0:\n arr[j]=0\nprint (ans)', 'from collections import Counter\nn=int(input())\ninp = list(map(int,input().split()))\nc=Counter(inp)\narr=[1]*(max(inp)+1)\ninp.sort()\nd=Counter([])\nfor i in range(len(arr)):\n if c[i]>=1 and arr[i]==1:\n if d[i]==0:\n d[i]+=1\n else:\n continue\n k=2\n while k*i<len(arr):\n arr[k*i]=0\n k+=1\nans=0\nfor item in d.keys():\n if c[item]==1:\n ans+=1\nprint (ans)\n ']
['Runtime Error', 'Accepted']
['s828990048', 's698471618']
[8972.0, 61712.0]
[26.0, 1057.0]
[348, 442]
p02642
u984592063
2,000
1,048,576
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.
['from collections import Counter\na = int(input())\nA = list(map(int, input().split()))\n\n\n# A_set = list(set(A))\n# if len(A_set) == 1:\n# print(0)\n# else:\n# A_count = Counter(A)\n\n# for j in range(len(A_set)):\n# if(A_set[i]%A_set[j] == 0):\n# A_set[i] = A_set[j]\n# if(j != i):\n\n# break\n# print(d_num)\nA.sort()\n', 'a = int(input())\na = list(map(int, input().split()))\na.sort()\n\nd_num = a\n\ndiv = []\na_set = list(set(a))\nflag = false\nif len(a_set) == 1:\n print(0)\nelse:\n for i in range(len(a_set)):\n flag = false\n # for j in range(len(div)):\n # if(a_set[i]%div[j] == 0):\n \n \n # break\n if flag == False:\n div.append(a_set[i])\n print(1)\n', 'from collections import Counter\n', 'a = int(input())\na = list(map(int, input().split()))\na.sort()\n\nd_num = a\n\ndiv = []\na_set = list(set(a))\nflag = false\nif len(a_set) == 1:\n print(0)\nelse:\n for i in range(len(a_set)):\n flag = false\n # for j in range(len(div)):\n # if(a_set[i]%div[j] == 0):\n \n \n # break\n if flag == false:\n div.append(a_set[i])\n print(1)\n', 'a = int(input())\na = list(map(int, input().split()))\na.sort()\n\nd_num = a\n\ndiv = []\na_set = list(set(a))\nflag = False\nif len(a_set) == 1:\n print(0)\nelse:\n for i in range(len(a_set)):\n flag = False\n # for j in range(len(div)):\n # if(a_set[i]%div[j] == 0):\n \n \n # break\n if flag == False:\n div.append(a_set[i])\n print(1)\n', '\na = int(input())\na = list(map(int, input().split()))\na.sort()\n\nd_num = a\n\ndiv = []\na_set = list(set(a))\nflag = false\nif len(a_set) == 1:\n print(0)\nelse:\n for i in range(len(a_set)):\n flag = false\n # for j in range(len(div)):\n # if(a_set[i]%div[j] == 0):\n \n \n # break\n if flag == false:\n div.append(a_set[i])\n # print(d_num-len(a)+len(a_set))\n', 'a = int(input())\na = list(map(int, input().split()))\na.sort()\n\nd_num = a\n\ndiv = []\na_set = list(set(a))\nflag = False\nif len(a_set) == 1:\n print(0)\nelse:\n for i in range(len(a_set)):\n flag = False\n for j in range(len(div)):\n if(a_set[i]%div[j] == 0):\n d_num -= 1\n flag = True\n break\n if flag == False:\n div.append(a_set[i])\n print(1)\n', 'n = int(input())\nA = list(map(int, input().split()))\nA.sort()\n\nndiv_sum = 0\nmax_num = A[-1]\nno_div = [True] * (max_num+1)\nfor i in range(len(A)-1):\n if no_div[A[i]]:\n for j in range(A[i], max_num+1, A[i]):\n no_div[j] = False\n if A[i]!=A[i+1]:\n ndiv_sum += 1\nif no_div[A[-1]]:\n ndiv_sum += 1\nprint(ndiv_sum)\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s029089929', 's280387254', 's414308439', 's552290723', 's900782340', 's964546993', 's997681384', 's170949913']
[34120.0, 32220.0, 9252.0, 32292.0, 32340.0, 32152.0, 32332.0, 32380.0]
[97.0, 140.0, 26.0, 133.0, 177.0, 143.0, 2206.0, 301.0]
[477, 441, 32, 441, 441, 466, 431, 349]
p02642
u994985556
2,000
1,048,576
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.
['# MAX = int(1e6)+2\n\n\nn = int(input())\nlis = list(map(int,input().split()))\nlis.sort()\nMAX = lis[-1]\nlis2 = [0]*MAX\n# lis.sort()\n# m = max(lis)\nans = 0\n\nfor num in lis:\n for i in range(num, MAX, num):\n lis2[i] += 1\n\nfor j in set(lis):\n if lis2[j] == 1:\n ans += 1\nprint(ans)', 'MAX = int(2e5)+1\n\n\nn = int(input())\nlis = list(map(int,input().split()))\nlis2 = [0]*MAX\n# lis.sort()\n# m = max(lis)\nans = 0\nfor num in lis:\n lis2[num] += 1\n\nfor num in lis:\n for i in range(num*2, MAX+1, num):\n if lis2[i] > 0:\n lis2[i] += 1\n\nprint(len([i for i in lis if lis2[i] == 1]))', '# MAX = int(1e6)+2\n\n\nn = int(input())\nlis = list(map(int,input().split()))\nlis.sort()\nMAX = lis[-1]\nlis2 = [0]*(MAX+1)\n# lis.sort()\n# m = max(lis)\nans = 0\n\nfor num in lis:\n for i in range(num, MAX+1, num):\n lis2[i] += 1\n\nfor j in set(lis):\n if lis2[j] == 1:\n ans += 1\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s456299431', 's826472890', 's646155651']
[39488.0, 32080.0, 39384.0]
[487.0, 145.0, 463.0]
[296, 309, 302]
p02642
u997641430
2,000
1,048,576
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.
['n = int(input())\n*A, = map(int, input().split())\n\nC = {a: 0 for a in A}\nfor a in A:\n C[a] += 1\n\nD = {a: 0 for a in A}\nfor a in A:\n if C[a] > 0:\n tmp = 2\n while a * tmp <= maxA:\n D[a * tmp] = 1\n tmp += 1\nans = 0\nfor a in A:\n if C[a] == 1 and D[a] == 0:\n ans += 1\nprint(ans)\n', 'n = int(input())\n*A, = map(int, input().split())\nmaxA = max(A)\n\nC = {}\nfor a in A:\n try:\n C[a] += 1\n except KeyError:\n C[a] = 1\n\nD = {}\nfor a in A:\n if C[a] > 0:\n tmp = 2\n while a * tmp <= maxA:\n D[a * tmp] = 1\n tmp += 1\nans = 0\nfor a in A:\n if C[a] == 1 and D[a] == 0:\n ans += 1\nprint(ans)\n', 'n = int(input())\n*A, = map(int, input().split())\nmaxA = max(A)\n\nC = {a: 0 for a in A}\nfor a in A:\n C[a] += 1\n\nD = {a: 0 for a in A}\nfor a in A:\n if C[a] > 0:\n tmp = 2\n while a * tmp <= maxA:\n D[a * tmp] = 1\n tmp += 1\nans = 0\nfor a in A:\n if C[a] == 1 and D[a] == 0:\n ans += 1\nprint(ans)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s576452872', 's996524339', 's718985336']
[49600.0, 108824.0, 104020.0]
[163.0, 1220.0, 1244.0]
[406, 441, 420]
p02644
u021548497
3,000
1,048,576
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.
['import sys\nfrom heapq import *\ninput = sys.stdin.readline\n\n\ndef main():\n h, w, k = map(int, input().split())\n sx, sy, gx, gy = map(int, input().split())\n pond = [input().replace("\\n", "") for _ in range(h)]\n \n dist_N = [[None]*w for _ in range(h)]\n dist_S = [[None]*w for _ in range(h)]\n dist_E = [[None]*w for _ in range(h)]\n dist_W = [[None]*w for _ in range(h)]\n \n already = [[[True]*4 for _ in range(w)] for _ in range(h)]\n \n not_yet = [(1, 0, sx-1, sy-1, "N"), (1, 0, sx-1, sy-1, "E"), (1, 0, sx-1, sy-1, "S"), (1, 0, sx-1, sy-1, "W")]\n heapify(not_yet)\n already[sx-1][sy-1][0] = False\n already[sx-1][sy-1][1] = False\n already[sx-1][sy-1][2] = False\n already[sx-1][sy-1][3] = False\n \n while not_yet:\n a, b, x, y, d = heappop(not_yet)\n if x != sx-1 or y != sy-1:\n if already[x][y][0]:\n already[x][y][0] = False\n not_yet.append((a, k-1, x, y, "N"))\n if already[x][y][1]:\n already[x][y][1] = False\n not_yet.append((a, k-1, x, y, "S"))\n if already[x][y][2]:\n already[x][y][2] = False\n not_yet.append((a, k-1, x, y, "W"))\n if already[x][y][3]:\n already[x][y][3] = False\n not_yet.append((a, k-1, x, y, "E"))\n if d == "N" and dist_N[x][y] == None:\n dist_N[x][y] = (a, b)\n if x > 0 and already[x-1][y][0] and pond[x-1][y] == "." and dist_N[x-1][y] == None:\n already[x-1][y][0] = False\n if b == k-1:\n not_yet.append((a+1, 0, x-1, y, "N"))\n else:\n not_yet.append((a, b+1, x-1, y, "N"))\n if d == "W" and dist_W[x][y] == None:\n dist_W[x][y] = (a, b)\n if y > 0 and already[x][y-1][2] and pond[x][y-1] == "." and dist_W[x][y-1] == None:\n already[x][y-1][2] = False\n if b == k-1:\n not_yet.append((a+1, 0, x, y-1, "W"))\n else:\n not_yet.append((a, b+1, x, y-1, "W"))\n if d == "S" and dist_S[x][y] == None:\n dist_S[x][y] = (a, b)\n if x < h-1 and already[x+1][y][1] and pond[x+1][y] == "." and dist_S[x+1][y] == None:\n already[x+1][y][1] = False\n if b == k-1:\n not_yet.append((a+1, 0, x+1, y, "S"))\n else:\n not_yet.append((a, b+1, x+1, y, "S"))\n if d == "E" and dist_E[x][y] == None:\n dist_E[x][y] = (a, b)\n if y < w-1 and already[x][y+1][3] and pond[x][y+1] == "." and dist_E[x][y+1] == None:\n already[x][y+1][3] = False\n if b == k-1:\n not_yet.append((a+1, 0, x, y+1, "E"))\n else:\n not_yet.append((a, b+1, x, y+1, "E"))\n \n gx -= 1\n gy -= 1\n ans = [10**7]\n \n for v in [dist_N[gx][gy], dist_S[gx][gy], dist_E[gx][gy], dist_W[gx][gy]]:\n if v != None:\n ans.append(v[0])\n \n answer = min(ans)\n print(-1 if answer == 10**7 else answer)\n \n print(dist_E)\n \n \n \n \n \n \nif __name__ == "__main__":\n main()\n', 'import sys\nfrom collections import deque\ninput = sys.stdin.readline\n\ndef main():\n h, w, k = map(int, input().split())\n sx, sy, gx, gy = map(int, input().split())\n\n c = [input() for i in range(h)]\n\n not_yet = deque([(sx-1, sy-1)])\n dist = [[-1]*w for i in range(h)]\n dist[sx-1][sy-1] = 0\n already = [[False]*w for i in range(h)]\n already[sx-1][sy-1] = True\n\n while not_yet:\n x, y = not_yet.popleft()\n d = dist[x][y]\n\n for i in range(x+1, x+k+1):\n if i >= h or c[i][y] == "@":\n break\n if already[i][y] and dist[i][y] < d + 1:\n break\n if already[i][y] and dist[i][y] == d + 1:\n continue\n dist[i][y] = d + 1\n already[i][y] = True\n not_yet.append((i, y))\n\n for i in range(x-1, x-k-1, -1):\n if i < 0 or c[i][y] == "@":\n break\n if already[i][y] and dist[i][y] < d + 1:\n break\n if already[i][y] and dist[i][y] == d + 1:\n continue\n dist[i][y] = d + 1\n already[i][y] = True\n not_yet.append((i, y))\n \n for i in range(y+1, y+k+1):\n if i >= w or c[x][i] == "@":\n break\n if already[x][i] and dist[x][i] < d + 1:\n break\n if already[x][i] and dist[x][i] == d + 1:\n continue\n dist[x][i] = d + 1\n already[x][i] = True\n not_yet.append((x, i))\n\n for i in range(y-1, y-k-1, -1):\n if i < 0 or c[x][i] == "@":\n break\n if already[x][i] and dist[x][i] < d + 1:\n break\n if already[x][i] and dist[x][i] == d + 1:\n continue\n dist[x][i] = d + 1\n already[x][i] = True\n not_yet.append((x, i))\n\n ans = dist[gx-1][gy-1]\n print(ans)\n\n \nif __name__ == "__main__":\n main()\n\n']
['Wrong Answer', 'Accepted']
['s485492697', 's398596047']
[309984.0, 45388.0]
[3316.0, 1693.0]
[3247, 1970]
p02644
u021916304
3,000
1,048,576
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.
["def ii():return int(input())\ndef iim():return map(int,input().split())\ndef iil():return list(map(int,input().split()))\nfrom collections import deque\n\n\ndef bfs(xg,yg):\n queue = deque([(xs,ys,0)])\n while queue:\n x,y,dep = queue.popleft()\n l = []\n for xx,yy in [(1,0),(0,1),(-1,0),(0,-1)]:\n for i in range(1,k+1):\n nx,ny = x+xx*i,y+yy*i\n if cord[ny][nx] == '.':\n l.append((nx,ny))\n elif cord[ny][nx] < dep+1:\n break\n for nx, ny in l:\n if cord[ny][nx] == '.':\n cord[ny][nx] = dep+1\n if (nx,ny) == (xg,yg):\n return dep+1\n else:\n queue.append((nx,ny,dep+1))\n return -1\n\nh,w,k = iim()\nys,xs,yg,xg = iim()\n\ncord = [['@']*(w+2)]\nfor i in range(h):\n cord.append(['@']+list(input())+['@'])\ncord.append(['@']*(w+2))\ncord[ys][xs] = '#'\n\nprint(bfs(xg,yg))\n", "def ii():return int(input())\ndef iim():return map(int,input().split())\ndef iil():return list(map(int,input().split()))\nfrom collections import deque\n\n\ndef bfs(xg,yg):\n queue = deque([(xs,ys,0)])\n update = deque()\n while queue:\n x,y,dep = queue.popleft()\n l = []\n f1 = True\n f2 = True\n f3 = True\n f4 = True\n for i in range(1,k+1):\n if f1 and cord[y][x+i] == '.':\n l.append((x+i,y))\n else:\n f1 = False\n if f2 and cord[y][x-i] == '.':\n l.append((x-i,y))\n else:\n f2 = False\n if f3 and cord[y+i][x] == '.':\n l.append((x,y+i))\n else:\n f3 = False\n if f4 and cord[y-i][x] == '.':\n l.append((x,y-i))\n else:\n f4 = False\n if not (f1 or f2 or f3 or f4):\n break\n for nx, ny in l:\n if cord[ny][nx] == '.':\n# cord[ny][nx] = (dep+1)%10\n if (nx,ny) == (xg,yg):\n cord[ny][nx] = 'G'\n return dep+1\n else:\n update.append((nx,ny))\n\n while update:\n x,y = update.popleft()\n cord[y][x] = '#'\n queue.append((nx,ny,dep+1))\n\n return -1\n\nh,w,k = iim()\nys,xs,yg,xg = iim()\n\ncord = [['@']*(w+2)]\nfor i in range(h):\n cord.append(['@']+list(input())+['@'])\ncord.append(['@']*(w+2))\ncord[ys][xs] = 'S'\n\nprint(bfs(xg,yg))\n", "def ii():return int(input())\ndef iim():return map(int,input().split())\ndef iil():return list(map(int,input().split()))\nfrom collections import deque\n\n\ndef bfs(xg,yg):\n queue = deque([(xs,ys,0)])\n while queue:\n x,y,dep = queue.popleft()\n l = []\n f1 = True\n f2 = True\n f3 = True\n f4 = True\n for i in range(1,k+1):\n if f1 and cord[y][x+i] == '.':\n l.append((x+i,y))\n elif cord[y][x+i] == '@':\n f1 = False\n if f2 and cord[y][x-i] == '.':\n l.append((x-i,y))\n elif cord[y][x-i] == '@':\n f2 = False\n if f3 and cord[y+i][x] == '.':\n l.append((x,y+i))\n elif cord[y+i][x] == '@':\n f3 = False\n if f4 and cord[y-i][x] == '.':\n l.append((x,y-i))\n elif cord[y-i][x] == '@':\n f4 = False\n if not (f1 or f2 or f3 or f4):\n break\n for nx, ny in l:\n if cord[ny][nx] == '.':\n cord[ny][nx] = '#'\n if (nx,ny) == (xg,yg):\n return dep+1\n else:\n queue.append((nx,ny,dep+1))\n return -1\n\nh,w,k = iim()\nys,xs,yg,xg = iim()\n\ncord = [['@']*(w+2)]\nfor i in range(h):\n cord.append(['@']+list(input())+['@'])\ncord.append(['@']*(w+2))\ncord[ys][xs] = '#'\n\n# print(*i)\nprint(bfs(xg,yg))", "def ii():return int(input())\ndef iim():return map(int,input().split())\ndef iil():return list(map(int,input().split()))\nfrom collections import deque\n\n\ndef bfs(xg,yg):\n queue = deque([(xs,ys,0)])\n while queue:\n x,y,dep = queue.popleft()\n l = []\n for xx,yy in [(1,0),(0,1),(-1,0),(0,-1)]:\n for i in range(1,k+1):\n nx,ny = x+xx*i,y+yy*i\n if cord[ny][nx] == '.':\n l.append((nx,ny))\n elif type(cord[ny][nx]) != int or cord[ny][nx] < dep+1:\n break\n for nx, ny in l:\n if cord[ny][nx] == '.':\n cord[ny][nx] = dep+1\n if (nx,ny) == (xg,yg):\n return dep+1\n else:\n queue.append((nx,ny,dep+1))\n return -1\n\nh,w,k = iim()\nys,xs,yg,xg = iim()\n\ncord = [['@']*(w+2)]\nfor i in range(h):\n cord.append(['@']+list(input())+['@'])\ncord.append(['@']*(w+2))\ncord[ys][xs] = '#'\n\nprint(bfs(xg,yg))\n"]
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s201534983', 's723402031', 's751243285', 's451729703']
[32724.0, 32748.0, 32608.0, 51072.0]
[93.0, 760.0, 2889.0, 1787.0]
[970, 1592, 1463, 999]
p02644
u070201429
3,000
1,048,576
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.
["from sys import stdin\ndef input():\n return stdin.readline().strip()\n\nimport heapq\n\ndef main():\n h, w, k = map(int, input().split())\n x1, y1, x2, y2 = map(int, input().split())\n\n # surround the square with '@'\n c = [['@'] * (w+2)]\n for _ in range(h):\n i = list('@' + input() + '@')\n c.append(i)\n c.append(['@'] * (w+2))\n\n \n # seen[x][y] = the minimum cost of (x, y)\n # if seen[x][y] == -1, (x, y) is unresearched\n seen = [[-1] * (w+2) for _ in range(h+2)]\n\n \n todo = [(0, x1, y1, 0)]\n heapq.heapify(todo)\n\n # direction\n dx = [-1, 0, 1, 0]\n dy = [0, 1, 0, -1]\n\n while len(todo) > 0:\n cost, xi, yi, direction = heapq.heappop(todo)\n\n \n if seen[xi][yi] != -1:\n if seen[xi][yi] == cost:\n xj, yj = xi + dx[direction], yi + dy[direction]\n if c[xj][yj] == '.' and (seen[xj][yj] == -1 or (seen[xj][yj]+k-1)//k * k > cost):\n heapq.heappush(todo, (cost+1, xj, yj, direction))\n continue\n seen[xi][yi] = cost\n\n # goal\n if xi == x2 and yi == y2:\n print((cost+k-1)//k - 1)\n exit()\n \n # add\n for j in range(4):\n xj, yj= xi + dx[j], yi + dy[j]\n if c[xj][yj] == '.':\n if j == direction:\n if seen[xj][yj] == -1 or (seen[xj][yj]+k-1)//k * k > cost:\n heapq.heappush(todo, (cost+1, xj, yj, j))\n elif seen[xj][yj] == -1:\n heapq.heappush(todo, ((cost+k-1)//k * k + 1, xj, yj, j))\n\n print(-1)\n\nmain()", "from sys import stdin\ndef input():\n return stdin.readline().strip()\n\nimport heapq\n\ndef main():\n h, w, k = map(int, input().split())\n x1, y1, x2, y2 = map(int, input().split())\n\n # surround the square with '@'\n c = [['@'] * (w+2)]\n for _ in range(h):\n i = list('@' + input() + '@')\n c.append(i)\n c.append(['@'] * (w+2))\n\n \n # seen[x][y] = the minimum cost of (x, y)\n # if seen[x][y] == -1, (x, y) is unresearched\n seen = [[-1] * (w+2) for _ in range(h+2)]\n\n \n todo = [(0, x1, y1, 0)]\n heapq.heapify(todo)\n\n # direction\n dx = [-1, 0, 1, 0]\n dy = [0, 1, 0, -1]\n\n while len(todo) > 0:\n cost, xi, yi, direction = heapq.heappop(todo)\n\n \n if seen[xi][yi] != -1:\n if seen[xi][yi] == cost:\n xj, yj = xi + dx[direction], yi + dy[direction]\n if c[xj][yj] == '.' and seen[xj][yj] == -1:\n heapq.heappush(todo, (cost+1, xj, yj, direction))\n continue\n seen[xi][yi] = cost\n\n # goal\n if xi == x2 and yi == y2:\n print((cost+k-1)//k)\n for i in seen:\n print(i)\n exit()\n \n # add\n for j in range(4):\n xj, yj= xi + dx[j], yi + dy[j]\n if c[xj][yj] == '.' and seen[xj][yj] == -1:\n if j == direction:\n heapq.heappush(todo, (cost+1, xj, yj, j))\n else:\n heapq.heappush(todo, ((cost+k-1)//k * k + 1, xj, yj, j))\n\n print(-1)\n\nmain()", "from sys import stdin\ndef input():\n return stdin.readline().strip()\n\nimport heapq\n\ndef main():\n h, w, k = map(int, input().split())\n x1, y1, x2, y2 = map(int, input().split())\n\n # surround the square with '@'\n c = [['@'] * (w+2)]\n for _ in range(h):\n i = list('@' + input() + '@')\n c.append(i)\n c.append(['@'] * (w+2))\n\n \n # seen[x][y] = the minimum cost of (x, y)\n # if seen[x][y] == -1, (x, y) is unresearched\n seen = [[-1] * (w+2) for _ in range(h+2)]\n\n \n todo = [(0, x1, y1, 0)]\n heapq.heapify(todo)\n\n # direction\n dx = [-1, 0, 1, 0]\n dy = [0, 1, 0, -1]\n\n while len(todo) > 0:\n cost, xi, yi, direction = heapq.heappop(todo)\n\n \n if seen[xi][yi] != -1:\n if seen[xi][yi] == cost:\n xj, yj = xi + dx[direction], yi + dy[direction]\n if c[xj][yj] == '.' and (seen[xj][yj] == -1 or (seen[xj][yj]+k-1)//k * k > cost):\n heapq.heappush(todo, (cost+1, xj, yj, direction))\n continue\n seen[xi][yi] = cost\n\n # goal\n if xi == x2 and yi == y2:\n print((cost+k-1)//k + 1)\n exit()\n \n # add\n for j in range(4):\n xj, yj= xi + dx[j], yi + dy[j]\n if c[xj][yj] == '.':\n if j == direction:\n if seen[xj][yj] == -1 or (seen[xj][yj]+k-1)//k * k > cost:\n heapq.heappush(todo, (cost+1, xj, yj, j))\n elif seen[xj][yj] == -1:\n heapq.heappush(todo, ((cost+k-1)//k * k + 1, xj, yj, j))\n\n print(-1)\n\nmain()", "from sys import stdin\ndef input():\n return stdin.readline().strip()\n\nimport heapq\n\ndef main():\n h, w, k = map(int, input().split())\n x1, y1, x2, y2 = map(int, input().split())\n\n # surround the square with '@'\n c = [['@'] * (w+2)]\n for _ in range(h):\n i = list('@' + input() + '@')\n c.append(i)\n c.append(['@'] * (w+2))\n\n \n # seen[x][y] = the minimum cost of (x, y)\n # if seen[x][y] == -1, (x, y) is unresearched\n seen = [[-1] * (w+2) for _ in range(h+2)]\n\n \n todo = [(0, x1, y1, 0)]\n heapq.heapify(todo)\n\n # direction\n dx = [-1, 0, 1, 0]\n dy = [0, 1, 0, -1]\n\n while len(todo) > 0:\n cost, xi, yi, direction = heapq.heappop(todo)\n\n \n if seen[xi][yi] != -1:\n if seen[xi][yi] == cost:\n xj, yj = xi + dx[direction], yi + dy[direction]\n if c[xj][yj] == '.' and seen[xj][yj] == -1:\n heapq.heappush(todo, (cost+1, xj, yj, direction))\n continue\n seen[xi][yi] = cost\n\n # goal\n if xi == x2 and yi == y2:\n print((cost+1)//k + 1)\n exit()\n \n # add\n for j in range(4):\n xj, yj= xi + dx[j], yi + dy[j]\n if c[xj][yj] == '.' and seen[xj][yj] == -1:\n if j == direction:\n heapq.heappush(todo, (cost+1, xj, yj, j))\n else:\n heapq.heappush(todo, (((cost-1)//k + 1)*k + 1, xj, yj, j))\n\n print(-1)\n\nmain()", "from sys import stdin\ndef input():\n return stdin.readline().strip()\n\nimport heapq\n\ndef main():\n h, w, k = map(int, input().split())\n x1, y1, x2, y2 = map(int, input().split())\n\n # surround the square with '@'\n c = [['@'] * (w+2)]\n for _ in range(h):\n i = list('@' + input() + '@')\n c.append(i)\n c.append(['@'] * (w+2))\n\n \n # seen[x][y] = the minimum cost of (x, y)\n # if seen[x][y] == -1, (x, y) is unresearched\n seen = [[-1] * (w+2) for _ in range(h+2)]\n\n \n todo = [(0, x1, y1, 0)]\n heapq.heapify(todo)\n\n # direction\n dx = [-1, 0, 1, 0]\n dy = [0, 1, 0, -1]\n\n while len(todo) > 0:\n cost, xi, yi, direction = heapq.heappop(todo)\n\n \n if seen[xi][yi] != -1:\n if seen[xi][yi] == cost:\n xj, yj = xi + dx[direction], yi + dy[direction]\n if c[xj][yj] == '.' and seen[xj][yj] == -1:\n heapq.heappush(todo, (cost+1, xj, yj, direction))\n continue\n seen[xi][yi] = cost\n\n # goal\n if xi == x2 and yi == y2:\n print((cost-1)//k)\n exit()\n \n # add\n for j in range(4):\n xj, yj= xi + dx[j], yi + dy[j]\n if c[xj][yj] == '.' and seen[xj][yj] == -1:\n if j == direction:\n heapq.heappush(todo, (cost+1, xj, yj, j))\n else:\n heapq.heappush(todo, (((cost-1)//k + 1)*k + 1, xj, yj, j))\n\n print(-1)\n\nmain()", "from sys import stdin\ndef input():\n return stdin.readline().strip()\n\nimport heapq\n\ndef main():\n h, w, k = map(int, input().split())\n x1, y1, x2, y2 = map(int, input().split())\n\n # surround the square with '@'\n c = [['@'] * (w+2)]\n for _ in range(h):\n i = list('@' + input() + '@')\n c.append(i)\n c.append(['@'] * (w+2))\n\n \n # seen[x][y] = the minimum cost of (x, y)\n # if seen[x][y] == -1, (x, y) is unresearched\n seen = [[-1] * (w+2) for _ in range(h+2)]\n\n \n todo = [(0, x1, y1, 0)]\n heapq.heapify(todo)\n\n # direction\n dx = [-1, 0, 1, 0]\n dy = [0, 1, 0, -1]\n\n while len(todo) > 0:\n cost, xi, yi, direction = heapq.heappop(todo)\n\n \n if seen[xi][yi] != -1:\n if seen[xi][yi] == cost:\n xj, yj = xi + dx[direction], yi + dy[direction]\n if c[xj][yj] == '.' and seen[xj][yj] == -1:\n heapq.heappush(todo, (cost+1, xj, yj, direction))\n continue\n seen[xi][yi] = cost\n\n # goal\n if xi == x2 and yi == y2:\n print((cost)//k + 1)\n exit()\n \n # add\n for j in range(4):\n xj, yj= xi + dx[j], yi + dy[j]\n if c[xj][yj] == '.' and seen[xj][yj] == -1:\n if j == direction:\n heapq.heappush(todo, (cost+1, xj, yj, j))\n else:\n heapq.heappush(todo, (((cost-1)//k + 1)*k + 1, xj, yj, j))\n\n print(-1)\n\nmain()", "from sys import stdin\ndef input():\n return stdin.readline().strip()\n\nimport heapq\n\ndef main():\n h, w, k = map(int, input().split())\n x1, y1, x2, y2 = map(int, input().split())\n\n # surround the square with '@'\n c = [['@'] * (w+2)]\n for _ in range(h):\n i = input()\n l = ['@']\n for j in i:\n l.append(j)\n l.append('@')\n c.append(l)\n c.append(['@'] * (w+2))\n\n \n # seen[x][y] = the minimum cost of (x, y)\n # if seen[x][y] == -1, (x, y) is unresearched\n seen = [[-1] * (w+2) for _ in range(h+2)]\n\n \n todo = [(0, x1, y1, 0)]\n heapq.heapify(todo)\n\n # direction\n dx = [-1, 0, 1, 0]\n dy = [0, 1, 0, -1]\n\n while len(todo) > 0:\n cost, xi, yi, direction = heapq.heappop(todo)\n\n # only straight\n if seen[xi][yi] != -1:\n if (seen[xi][yi]+k-1)//k * k > cost:\n xj, yj = xi + dx[direction], yi + dy[direction]\n if c[xj][yj] == '.':\n heapq.heappush(todo, (cost+1, xj, yj, direction))\n continue\n seen[xi][yi] = cost\n\n # goal\n if xi == x2 and yi == y2:\n print((cost+k-1)//k)\n exit()\n \n # 4 directions\n for j in range(4):\n xj, yj = xi + dx[j], yi + dy[j]\n if c[xj][yj] == '.':\n if j == direction:\n if seen[xj][yj] == -1 or (seen[xj][yj]+k-1)//k * k > cost:\n heapq.heappush(todo, (cost+1, xj, yj, j))\n elif seen[xj][yj] == -1:\n heapq.heappush(todo, ((cost+k-1)//k * k + 1, xj, yj, j))\n\n print(-1)\n\nmain()"]
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s027947588', 's127722118', 's180645654', 's748352988', 's755183408', 's877599086', 's676047109']
[75808.0, 91636.0, 75508.0, 75488.0, 75592.0, 75520.0, 77536.0]
[2261.0, 2370.0, 2260.0, 2253.0, 2239.0, 2299.0, 2121.0]
[1674, 1605, 1674, 1557, 1553, 1555, 1698]
p02644
u094102716
3,000
1,048,576
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.
['from collections import deque\nh,w,k = map(int,input().split())\na,b,c,d = map(int,input().split())\na -= 1\nb -= 1\nc -= 1\nd -= 1\nmaze = [input() for _ in range(h)]\ndx = [1, -1, 0, 0]\ndy = [0, 0, 1, -1]\ndepth = [[float("inf") for _ in range(w)] for _ in range(h)]\ndq = deque([(b,a)])\ndepth[a][b] = 0\nwhile dq:\n x,y ==dq.popleft()\n if x == d and y == c:\n break\n for i in range(4):\n nx,ny,K = x,y,k\n while K:\n K -= 1\n nx += dx[i]\n ny += dy[i]\n if 0<=nx<=w-1 and 0<=ny<=h-1 and maze[nx][ny] != "@" and depth[nx][ny] > depth[y][x]:\n if depth[ny][nx] == depth[y][x]+1:\n continue\n depth[ny][nx] = depth[y][x] +1\n dq.append((nx,ny))\n else:\n break\nprint(depth[c][d] if depth[c][d] != float("inf") else -1)\n\n\n', 'from collections import deque\nh,w,k = map(int,input().split())\na,b,c,d=map(int,input().split())\na -= 1\nb -= 1\nc -= 1\nd -= 1\nmaze = [input() for _ in range(h)]\ndx = [1, -1, 0, 0]\ndy = [0, 0, 1, -1]\ndepth = [[float("inf") for _ in range(w)] for _ in range(h)]\ndq = deque([(b,a)])\ndepth[a][b] = 0\nwhile dq:\n x,y ==dq.popleft()\n if x == d and y == c:\n break\n for i in range(4):\n nx,ny,K = x,y,k\n while K:\n K -= 1\n nx += dx[i]\n ny += dy[i]\n if 0<=nx<=w-1 and 0<=ny<=h-1 and maze[nx][ny] != "@" and depth[nx][ny] > depth[y][x]:\n if depth[ny][nx] == depth[y][x]+1:\n continue\n depth[ny][nx] = depth[y][x] +1\n dq.append((nx,ny))\n else:\n break\nprint(depth[c][d] if depth[c][d] != float("inf") else -1)\n\n\n', 'from collections import deque\nh,w,k = map(int,input().split())\na,b,c,d=map(int,input().split())\na -= 1\nb -= 1\nc -= 1\nd -= 1\nmaze = [input() for _ in range(h)]\ndx = [1, -1, 0, 0]\ndy = [0, 0 1, -1]\ndepth = [[float("inf") for _ in range(w)] for _ in range(h)]\ndq = deque([b,a])\ndepth[a][b] = 0\nwhile dq:\n x,y ==dq.popleft()\n if x == d and y == c:\n break\n for i in range(4):\n nx,ny,K = x,y,k\n while K:\n K -= 1\n nx += dx[i]\n ny += dy[i]\n if 0<=nx<=w-1 and 0<=ny<=h-1 and maze[nx][ny] != "@" and depth[nx][ny] > depth[y][x]:\n if depth[ny][nx] == depth[y][x]+1:\n continue\n depth[ny][nx] = depth[y][x] +1\n dq.append((nx,ny))\n else:\n break\nprint(depth[c][d] if depth[c][d] != float("inf") else -1)\n\n\n', 'from collections import deque\nh,w,k = map(int,input().split())\na,b,c,d = map(int,input().split())\na -= 1\nb -= 1\nc -= 1\nd -= 1\nmaze = [input() for _ in range(h)]\ndx = [1, -1, 0, 0]\ndy = [0, 0, 1, -1]\ndepth = [[float("inf") for _ in range(w)] for _ in range(h)]\ndq = deque([(b,a)])\ndepth[a][b] = 0\nwhile dq:\n x,y ==dq.popleft()\n if x == d and y == c:\n break\n for i in range(4):\n nx,ny,K = x,y,k\n while K:\n K -= 1\n nx += dx[i]\n ny += dy[i]\n if 0<=nx<=w-1 and 0<=ny<=h-1 and maze[nx][ny] != "@" and depth[nx][ny] > depth[y][x]:\n if depth[ny][nx] == depth[y][x]+1:\n continue\n depth[ny][nx] = depth[y][x] +1\n dq.append((nx,ny))\n else:\n break\nprint(depth[c][d] if depth[c][d] != float("inf") else -1)\n\n\n', 'from collections import deque\nh,w,k = map(int,input().split())\na,b,c,d = map(int,input().split())\na -= 1\nb -= 1\nc -= 1\nd -= 1\nmaze = [input() for _ in range(h)]\ndx = [1,-1,0,0]\ndy = [0,0,1,-1]\ndepth = [[float("inf") for _ in range(w)] for _ in range(h)]\ndq = deque([(b,a)])\ndepth[a][b] = 0\nwhile dq:\n x,y = dq.popleft()\n if x == d and y == c:\n break\n for i in range(4):\n nx,ny,K = x,y,k\n while K:\n K -= 1\n nx += dx[i]\n ny += dy[i]\n if 0<=nx<=w-1 and 0<=ny<=h-1 and maze[ny][nx] != "@" and depth[ny][nx] > depth[y][x]:\n if depth[ny][nx] == depth[y][x]+1:\n continue\n depth[ny][nx] = depth[y][x] +1\n dq.append((nx,ny))\n else:\n break\nprint(depth[c][d] if depth[c][d] != float("inf") else -1)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s308865955', 's456566560', 's623899013', 's658083612', 's362508016']
[50340.0, 50264.0, 9032.0, 50320.0, 55104.0]
[183.0, 199.0, 25.0, 189.0, 2669.0]
[832, 768, 765, 770, 851]
p02644
u113971909
3,000
1,048,576
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.
["#!/usr/bin python3\n# -*- coding: utf-8 -*-\n\nH, W, K = map(int,input().split())\nsth,stw,glh, glw = map(int,input().split())\nsth, stw = sth-1, stw-1\nglh, glw = glh-1, glw-1\n\nINF = -1\nGmap = [list(input()) for _ in range(H)]\nDist = [[INF]*W for _ in range(H)]\ndirec = {(1,0), (-1,0), (0,1), (0,-1)}\ninit_q =[]\n\nfrom collections import deque\n\ndef bfs(init,glh,glw):\n next_q = deque([])\n for x, y in init:\n next_q.append([x,y,0])\n Dist[x][y]=1\n\n while len(next_q)!=0:\n \n h,w,c = next_q.popleft()\n for dh, dw in direc:\n for sk in range(1,K+1):\n hs, ws = h + dh*sk, w + dw*sk\n if not (0<=hs<H and 0<=ws<W):\n break\n if Gmap[hs][ws]=='@':\n break\n if Gmap[hs][ws]=='.' and Dist[hs][ws]==1:\n break\n if Gmap[hs][ws]=='.' and Dist[hs][ws]==INF:\n next_q.append([hs,ws,c+1])\n Dist[hs][ws] = 1\n if hs==glh and ws==glw:\n return c + 1\n return -1\n\ndef main():\n init_q.append([sth, stw])\n\n ret = bfs(init_q,glh,glw)\n print(ret)\n\nif __name__ == '__main__':\n main()", "#!/usr/bin python3\n# -*- coding: utf-8 -*-\n\nH, W, K = map(int,input().split())\nsth, stw, glh, glw = map(int,input().split())\nsth, stw = sth-1, stw-1\nglh, glw = glh-1, glw-1\n\nINF = -1\nGmap = [list(input()) for _ in range(H)]\nSeen = [[INF]*W for _ in range(H)]\ndirec = {(1,0), (-1,0), (0,1), (0,-1)}\n\nfrom collections import deque\n\ndef bfs(sth, stw, glh, glw):\n next_q = deque([])\n next_q.append((sth,stw,0))\n Seen[sth][stw] = 0\n\n while len(next_q)!=0:\n \n h, w, c = next_q.popleft()\n for dh, dw in direc:\n for sk in range(1,K+1):\n hs, ws = h + dh*sk, w + dw*sk\n if not (0<=hs<H and 0<=ws<W):\n break\n if Gmap[hs][ws]=='@':\n break\n if Seen[hs][ws]==INF:\n next_q.append((hs,ws,c+1))\n Seen[hs][ws] = c + 1\n elif Seen[hs][ws]<=c:\n break\n if hs==glh and ws==glw:\n return c + 1\n return -1\n\ndef main():\n ret = bfs(sth, stw, glh, glw)\n print(ret)\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s220596699', 's423461782']
[40772.0, 43196.0]
[1793.0, 1750.0]
[1247, 1161]
p02644
u135454978
3,000
1,048,576
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.
['from collections import deque\nimport sys\n\n\ndef bfs(xs, ys, d):\n queue = deque((xs, ys, d))\n M[xs][ys] = d\n while queue:\n \n x1, y1, d = queue.popleft() \n if [x1, y1] == [xg, yg]: \n return\n\n for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):\n for k in range(1, K + 1):\n x2 = x1 + dx * k\n y2 = y1 + dy * k\n\n if (0 <= x2 < H) and (0 <= y2 < W):\n if m[x2][y2] == "@":\n break\n elif M[x2][y2] == -1: \n M[x2][y2] = d + 1\n queue.append((x2, y2)) \n elif M[x2][y2] < d + 1:\n break\n else:\n break\n\n\nH, W, K = map(int, input().split())\n\nxs, ys, xg, yg = map(int, input().split())\nxs, ys, xg, yg = xs - 1, ys - 1, xg - 1, yg - 1\n\nm = []\nfor i in range(H):\n m.append(list(map(str, sys.stdin.readline().strip())))\n\nM = [[-1] * W for i in range(H)]\n\nbfs(xs, ys, 0)\n\nprint(M[xg][yg])\n', "import sys\nfrom collections import deque\n\nH, W, K = map(int, sys.stdin.readline().strip().split())\nxs, ys, xg, yg = map(int, sys.stdin.readline().strip().split())\n\nm = []\nfor _ in range(H):\n m.append(list(map(str, sys.stdin.readline().strip())))\n\nM = [[float('inf')] * W for _ in range(H)]\n\n\ndef bfs(x1, y1, d):\n q = deque()\n q.append((d, x1, y1))\n\n while q:\n d, x1, y1 = q.popleft()\n\n M[x1][y1] = d\n\n # if (x1 == xg - 1) and (y1 == yg - 1):\n # break\n\n for dx, dy in ([0, 1], [1, 0], [0, -1], [-1, 0]):\n k = 1\n while k <= K:\n x2 = x1 + dx * k\n y2 = y1 + dy * k\n if x2 < 0 or x2 >= H:\n break\n if y2 < 0 or y2 >= W:\n break\n if m[x2][y2] == '@':\n break\n if M[x2][y2] < d + 1:\n break\n if M[x2][y2] == d + 1:\n continue\n\n q.append((d + 1, x2, y2))\n\n k += 1\n\n\nif m[xs - 1][ys - 1] != '@':\n bfs(xs - 1, ys - 1, 0)\n\n\n# print(M[i])\n\n\nans = M[xg - 1][yg - 1]\nif ans == float('inf'):\n print(-1)\nelse:\n print(ans)\n", "import sys\nfrom collections import deque\n\n\ndef bfs(x1, y1, d):\n q = deque([])\n q.append((x1, y1))\n\n while q:\n x1, y1 = q.popleft()\n\n M[x1][y1] = d\n\n if [x1, y1] == [xg, yg]:\n print(d)\n return\n\n for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):\n for k in range(1, K + 1):\n x2 = x1 + dx * k\n y2 = y1 + dy * k\n # if m[x2][y2] == '@':\n # break\n # if x2 < 0 or x2 >= H:\n # break\n # if y2 < 0 or y2 >= W:\n # break\n # if M[x2][y2] < d + 1:\n # break\n # if M[x2][y2] == d + 1:\n # continue\n\n if (0 <= x2 < H) and (0 <= y2 < W):\n if m[x2][y2] == '@':\n break\n elif M[x2][y2] == -1:\n M[x2][y2] = d + 1\n q.append((x2, y2))\n elif M[x2][y2] <= d:\n break\n elif M[x2][y2] == d + 1:\n continue\n else:\n break\n print(-1)\n\n\nH, W, K = map(int, sys.stdin.readline().strip().split())\nxs, ys, xg, yg = map(int, sys.stdin.readline().strip().split())\nxg -= 1\nyg -= 1\n\nm = []\nfor _ in range(H):\n m.append(list(map(str, sys.stdin.readline().strip())))\n\nM = [[-1] * W for _ in range(H)]\n\nbfs(xs - 1, ys - 1, 0)\n", 'from collections import deque\nimport sys\n\n\ndef bfs(x1, y1, d):\n q = deque()\n q.append((d, x1, y1))\n\n while q:\n d, x1, y1 = q.popleft()\n\n M[x1][y1] = d\n\n if [x1, y1] == [xg, yg]:\n return\n\n for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):\n for k in range(1, K + 1):\n x2 = x1 + dx * k\n y2 = y1 + dy * k\n\n if (0 <= x2 < H) and (0 <= y2 < W):\n if m[x2][y2] == "@":\n break\n elif M[x2][y2] == -1:\n M[x2][y2] = d + 1\n q.append((x2, y2, d + 1)) \n elif M[x2][y2] < d + 1:\n break\n else:\n break\n\n\nH, W, K = map(int, input().split())\n\nxs, ys, xg, yg = map(int, input().split())\nxs, ys, xg, yg = xs - 1, ys - 1, xg - 1, yg - 1\n\nm = []\nfor i in range(H):\n m.append(list(map(str, sys.stdin.readline().strip())))\n\nM = [[-1] * W for i in range(H)]\n\nbfs(xs, ys, 0)\n\nprint(M[xg][yg])\n', "import sys\nfrom collections import deque\n\n\ndef bfs(x1, y1, d):\n q = deque([])\n q.append((d, x1, y1))\n M[x1][y1] = d\n\n while q:\n d, x1, y1 = q.popleft()\n\n if [x1, y1] == [xg, yg]:\n print(d)\n return\n\n for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):\n for k in range(1, K + 1):\n x2 = x1 + dx * k\n y2 = y1 + dy * k\n if m[x2][y2] == '@':\n break\n if x2 < 0 or x2 >= H:\n break\n if y2 < 0 or y2 >= W:\n break\n if M[x2][y2] < d + 1:\n break\n if M[x2][y2] == d + 1:\n continue\n\n q.append((d + 1, x2, y2))\n M[x2][y2] = d + 1\n\n # if (0 <= x2 < H) and (0 <= y2 < W):\n # if m[x2][y2] == '@':\n # break\n # elif M[x2][y2] == -1:\n # M[x2][y2] = d + 1\n \n # elif M[x2][y2] == d + 1:\n # continue\n # else:\n # break\n # else:\n # break\n print(-1)\n\n\nH, W, K = map(int, sys.stdin.readline().strip().split())\nxs, ys, xg, yg = map(int, sys.stdin.readline().strip().split())\nxg -= 1\nyg -= 1\n\nm = []\nfor _ in range(H):\n m.append(list(map(str, sys.stdin.readline().strip())))\n\nM = [[-1] * W for _ in range(H)]\n\nbfs(xs - 1, ys - 1, 0)\n", "from collections import deque\nimport sys\n\n\ndef bfs(x1, y1, d):\n q = deque()\n q.append((d, x1, y1))\n\n while q:\n d, x1, y1 = q.popleft()\n\n M[x1][y1] = d\n\n if [x1, y1] == [xg, yg]:\n print(d)\n return\n\n for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):\n for k in range(1, K + 1):\n x2 = x1 + dx * k\n y2 = y1 + dy * k\n\n if (0 <= x2 < H) and (0 <= y2 < W):\n if m[x2][y2] == '@':\n break\n elif M[x2][y2] == -1:\n M[x2][y2] = d + 1\n q.append((d + 1, x2, y2))\n elif M[x2][y2] < d + 1:\n break\n else:\n break\n\n\nH, W, K = map(int, input().split())\n\nxs, ys, xg, yg = map(int, input().split())\nxs, ys, xg, yg = xs - 1, ys - 1, xg - 1, yg - 1\n\nm = []\nfor i in range(H):\n m.append(list(map(str, sys.stdin.readline().strip())))\n\nM = [[-1] * W for i in range(H)]\n\nbfs(xs, ys, 0)\n\nprint(M[xg][yg])\n", "import sys\nfrom collections import deque\n\n\ndef bfs(x1, y1, d):\n q = deque([])\n q.append((x1, y1))\n M[x1][y1] = d\n\n while q:\n x1, y1 = q.popleft()\n\n if [x1, y1] == [xg, yg]:\n print(d)\n return\n\n for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):\n for k in range(1, K + 1):\n x2 = x1 + dx * k\n y2 = y1 + dy * k\n # if m[x2][y2] == '@':\n # break\n # if x2 < 0 or x2 >= H:\n # break\n # if y2 < 0 or y2 >= W:\n # break\n # if M[x2][y2] < d + 1:\n # break\n # if M[x2][y2] == d + 1:\n # continue\n\n if (0 <= x2 < H) and (0 <= y2 < W):\n if m[x2][y2] == '@':\n break\n elif M[x2][y2] == -1:\n M[x2][y2] = d + 1\n q.append((x2, y2))\n elif M[x2][y2] <= d:\n break\n elif M[x2][y2] == d + 1:\n continue\n else:\n break\n print(-1)\n\n\nH, W, K = map(int, sys.stdin.readline().strip().split())\nxs, ys, xg, yg = map(int, sys.stdin.readline().strip().split())\nxg -= 1\nyg -= 1\n\nm = []\nfor _ in range(H):\n m.append(list(map(str, sys.stdin.readline().strip())))\n\nM = [[-1] * W for _ in range(H)]\n\nbfs(xs - 1, ys - 1, 0)\n", "import sys\nfrom collections import deque\n\n\ndef bfs(x1, y1, d):\n q = deque([])\n q.append((d, x1, y1))\n M[x1][y1] = d\n\n while q:\n d, x1, y1 = q.popleft()\n\n if [x1, y1] == [xg, yg]:\n print(d)\n return\n\n for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):\n for k in range(1, K + 1):\n x2 = x1 + dx * k\n y2 = y1 + dy * k\n if x2 < 0 or x2 >= H:\n break\n if y2 < 0 or y2 >= W:\n break\n if m[x2][y2] == '@':\n break\n if M[x2][y2] < d + 1:\n break\n if M[x2][y2] == d + 1:\n continue\n\n q.append((d + 1, x2, y2))\n M[x2][y2] = d + 1\n\n # if (0 <= x2 < H) and (0 <= y2 < W):\n # if m[x2][y2] == '@':\n # break\n # elif M[x2][y2] == -1:\n # M[x2][y2] = d + 1\n \n # elif M[x2][y2] == d + 1:\n # continue\n # else:\n # break\n # else:\n # break\n print(-1)\n\n\nH, W, K = map(int, sys.stdin.readline().strip().split())\nxs, ys, xg, yg = map(int, sys.stdin.readline().strip().split())\nxg -= 1\nyg -= 1\n\nm = []\nfor _ in range(H):\n m.append(list(map(str, sys.stdin.readline().strip())))\n\nM = [[-1] * W for _ in range(H)]\n\nbfs(xs - 1, ys - 1, 0)\n", "import sys\nfrom collections import deque\n\n\ndef bfs(x1, y1, d):\n q = deque([])\n q.append((d, x1, y1))\n\n while q:\n d, x1, y1 = q.popleft()\n M[x1][y1] = d\n\n if [x1, y1] == [xg, yg]:\n print(d)\n return\n\n for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):\n for k in range(1, K + 1):\n x2 = x1 + dx * k\n y2 = y1 + dy * k\n if x2 < 0 or x2 >= H: \n break\n if y2 < 0 or y2 >= W: \n break\n if m[x2][y2] == '@': \n break\n if M[x2][y2] < d + 1: \n break\n if M[x2][y2] == d + 1: \n continue\n\n q.append((d + 1, x2, y2))\n M[x2][y2] = d + 1 \n\n print(-1)\n\n\nH, W, K = map(int, sys.stdin.readline().strip().split())\nxs, ys, xg, yg = map(int, sys.stdin.readline().strip().split())\nxg -= 1\nyg -= 1\n\nm = []\nfor _ in range(H):\n m.append(list(map(str, sys.stdin.readline().strip())))\n\nM = [[float('inf')] * W for _ in range(H)]\n\nbfs(xs - 1, ys - 1, 0)\n"]
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s011291086', 's081399088', 's173910543', 's515654207', 's573739878', 's666256463', 's831549140', 's879194907', 's324130042']
[26448.0, 604736.0, 27028.0, 29248.0, 26376.0, 45308.0, 26564.0, 26524.0, 45304.0]
[134.0, 3327.0, 3309.0, 1389.0, 137.0, 1890.0, 3309.0, 128.0, 1844.0]
[1404, 1242, 1503, 1105, 1569, 1098, 1498, 1569, 1348]
p02644
u221301671
3,000
1,048,576
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.
["h, w, k = map(int, input().split())\nx1, y1, x2, y2 = map(int, input().split())\nx1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1\n\nxxx = set()\nfor hh in range(h):\n c = input()\n for ww, cc in enumerate(c):\n if cc == '@':\n xxx.add((hh, ww))\n\nfrom heapq import heappush, heappop\nq = []\nheappush(q, (0, x1, y1))\nd = {}\nd[(x1, y1)] = 0\nwhile q:\n s, x, y = heappop(q)\n print(s,x,y)\n\n for i in range(1, k+1):\n xx, yy = x + i, y\n if xx >= h or (xx, yy) in xxx:\n break\n if (xx, yy) in d and d[(xx, yy)] <= s+1:\n continue\n if xx == x2 and yy == y2:\n print(s+1)\n exit(0)\n d[(xx, yy)] = s+1\n heappush(q, (s+1, xx, yy))\n\n for i in range(1, k+1):\n xx, yy = x - i, y\n if xx < 0 or (xx, yy) in xxx:\n break\n if (xx, yy) in d and d[(xx, yy)] <= s+1:\n continue\n if xx == x2 and yy == y2:\n print(s+1)\n exit(0)\n d[(xx, yy)] = s+1\n heappush(q, (s+1, xx, yy))\n\n for i in range(1, k+1):\n xx, yy = x, y + i\n if yy >= w or (xx, yy) in xxx:\n break\n if (xx, yy) in d and d[(xx, yy)] <= s+1:\n continue\n if xx == x2 and yy == y2:\n print(s+1)\n exit(0)\n d[(xx, yy)] = s+1\n heappush(q, (s+1, xx, yy))\n\n for i in range(1, k+1):\n xx, yy = x, y - i\n if yy < 0 or (xx, yy) in xxx:\n break\n if (xx, yy) in d and d[(xx, yy)] <= s+1:\n continue\n if xx == x2 and yy == y2:\n print(s+1)\n exit(0)\n d[(xx, yy)] = s+1\n heappush(q, (s+1, xx, yy))\n\nprint(-1)\n", "h, w, k = map(int, input().split())\nx1, y1, x2, y2 = map(int, input().split())\nx1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1\n\nxxx = set()\nfor hh in range(h):\n c = input()\n for ww, cc in enumerate(c):\n if cc == '@':\n xxx.add((hh, ww))\n\nfrom heapq import heappush, heappop\nq = []\nheappush(q, (0, x1, y1))\nd = {}\nwhile q:\n s, x, y = heappop(q)\n d[(x, y)] = s\n if x == x2 and y == y2:\n exit(0)\n\n for i in range(1, k+1):\n xx, yy = x + i, y\n if xx >= h or (xx, yy) in xxx:\n break\n if (xx, yy) in d and d[(xx, yy)] <= s+1:\n continue\n heappush(q, (s+1, xx, yy))\n\n for i in range(1, k+1):\n xx, yy = x - i, y\n if xx < 0 or (xx, yy) in xxx:\n break\n if (xx, yy) in d and d[(xx, yy)] <= s+1:\n continue\n heappush(q, (s+1, xx, yy))\n\n for i in range(1, k+1):\n xx, yy = x, y + i\n if yy >= w or (xx, yy) in xxx:\n break\n if (xx, yy) in d and d[(xx, yy)] <= s+1:\n continue\n heappush(q, (s+1, xx, yy))\n\n for i in range(1, k+1):\n xx, yy = x, y - i\n if yy < 0 or (xx, yy) in xxx:\n break\n if (xx, yy) in d and d[(xx, yy)] <= s+1:\n continue\n heappush(q, (s+1, xx, yy))\n\nprint(-1)\n", "h, w, k = map(int, input().split())\nx1, y1, x2, y2 = map(int, input().split())\nx1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1\n\nm = [[-1] * w for _ in range(h)]\nfor hh in range(h):\n c = input()\n for ww, cc in enumerate(c):\n if cc == '.':\n m[hh][ww] = h*w\n\nfrom collections import deque\nq = deque()\n\nq.append((0, x1, y1))\nwhile q:\n s, x, y = q.popleft()\n s1 = s + 1\n\n for i in range(1, k+1):\n xx, yy = x + i, y\n if xx >= h or m[xx][yy] <= s:\n break\n if m[xx][yy] == s1:\n continue\n if xx == x2 and yy == y2:\n print(s1)\n exit(0)\n m[xx][yy] = s1\n q.append((s1, xx, yy))\n\n for i in range(1, k+1):\n xx, yy = x - i, y\n if xx < 0 or m[xx][yy] <= s:\n break\n if m[xx][yy] == s1:\n continue\n if xx == x2 and yy == y2:\n print(s1)\n exit(0)\n m[xx][yy] = s1\n q.append((s1, xx, yy))\n\n for i in range(1, k+1):\n xx, yy = x, y + i\n if yy >= w or m[xx][yy] <= s:\n break\n if m[xx][yy] == s1:\n continue\n if xx == x2 and yy == y2:\n print(s1)\n exit(0)\n m[xx][yy] = s1\n q.append((s1, xx, yy))\n\n for i in range(1, k+1):\n xx, yy = x, y - i\n if yy < 0 or m[xx][yy] <= s:\n break\n if m[xx][yy] == s1:\n continue\n if xx == x2 and yy == y2:\n print(s1)\n exit(0)\n m[xx][yy] = s1\n q.append((s1, xx, yy))\n\nprint(-1)\n"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s351772629', 's596142768', 's478198915']
[113392.0, 542464.0, 49596.0]
[3313.0, 3325.0, 1740.0]
[1684, 1301, 1556]
p02644
u266014018
3,000
1,048,576
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.
["from heapq import heappop, heappush \ndef dijkstra(xs, ys, xg, yg,h,w,k,field):\n \n que = [(0, xs, ys)]\n inf = 10 ** 6\n dp = [[inf for _ in range(w+1)] for _ in range(h+1)]\n visited = [[False for _ in range(w+1)] for _ in range(h+1)]\n dp[xs][ys] = 0\n dx = [-1,0,1,0]\n dy = [0,1,0,-1]\n while que:\n cost, x, y= heappop(que)\n \n # if cost > dp[x][y]:\n # continue\n if x == xg and y == yg:\n print(cost)\n exit(0)\n if visited[x][y]\n for i in range(4):\n for j in range(1, k+1):\n x_, y_ = x+j*dx[i], y+j*dy[i]\n if not field[x_][y_]:\n break\n if dp[x_][y_] > dp[x][y] + 1:\n dp[x_][y_] = dp[x][y] + 1\n heappush(que, (dp[x_][y_], x_, y_))\n visited[x][y] = True\n print(-1)\n \n\ndef main():\n import sys\n def input(): return sys.stdin.readline().rstrip()\n h, w, k = map(int, input().split())\n xs, ys, xg, yg = map(int, input().split())\n field = [[False]*(w+2) for _ in range(h+2)]\n for i in range(h):\n \n s = [True if _ == '.' else False for _ in input()]\n field[i+1] = [False]+s+[False]\n dijkstra(xs, ys, xg, yg, h, w, k, field)\n\nif __name__ == '__main__':\n main()", "import sys\n\ndef main(lines):\n n, m, s = map(int,lines[0].split())\n adj = [[] for _ in range(n)]\n for i in range(m):\n a,b,d = map(int,lines[i+1].split())\n adj[a].append((b,d))\n from heapq import heappush, heappop\n inf = 10**9\n node = []\n dist = [inf]*n\n done = [False]*n\n dist[s] = 0\n heappush(node,(0,s))\n while node:\n cost, v = heappop(node)\n if not done[v]:\n for e in adj[v]:\n if dist[e[0]] > dist[v]+e[1]:\n dist[e[0]] = dist[v] + e[1]\n heappush(node, (dist[e[0]],e[0]))\n done[v] = True\n for el in dist:\n if el == inf:\n print('INF') \n else:\n print(el) \n\n\nif __name__ == '__main__':\n lines = []\n for l in sys.stdin:\n lines.append(l.rstrip('\\r\\n'))\n main(lines)\n", "from heapq import heappop, heappush \ndef main():\n import sys\n def input(): return sys.stdin.readline().rstrip()\n def dijkstra():\n inf = 10 ** 9\n visited = [[False]*(w+2) for _ in range(h+2)]\n\n dp = [[inf]*(w+2) for _ in range(h+2)]\n dp[xs][ys] = 0\n\n que = [(0, xs, ys, 0)]\n direction = [[-1, 0], [0, 1], [1, 0], [0, -1]]\n while que:\n cost, x, y, dirt = heappop(que)\n # if (x, y) == (xg, yg):\n # ans = (dp[x][y] + k - 1)//k\n # return ans\n\n if not visited[x][y]:\n for i in range(4):\n nx, ny = x + direction[i][0], y + direction[i][1]\n if field[nx][ny]:\n if i == dirt:\n if dp[nx][ny] > dp[x][y] + 1:\n dp[nx][ny] = dp[x][y] + 1\n heappush(que, (dp[nx][ny], nx, ny, i))\n else:\n if dp[nx][ny] > (dp[x][y] + k-1)//k*k + 1:\n dp[nx][ny] = (dp[x][y] + k-1)//k*k + 1\n heappush(que, (dp[nx][ny], nx, ny, i))\n visited[x][y] = True\n if dp[xg][yg] == inf\n return -1\n else:\n return (dp[xg][yg] + k - 1)//k\n\n\n h, w, k= map(int, input().split())\n xs, ys, xg, yg = map(int, input().split())\n field = [[False]*(w+2)]\n for _ in range(h):\n s = [False]\n s += [True if i == '.' else False for i in input()]\n s += [False]\n field.append(s)\n field.append([False]*(w+2))\n ans = dijkstra()\n print(ans)\n\n\n\n\nif __name__ == '__main__':\n main()", "from heapq import heappop, heappush \ndef dijkstra(xs, ys, xg, yg,h,w,k,field):\n \n que = [(0, xs, ys)]\n inf = 10 ** 6\n dp = [[inf for _ in range(w+1)] for _ in range(h+1)]\n visited = [[False for _ in range(w+1)] for _ in range(h+1)]\n dp[xs][ys] = 0\n dx = [-1,0,1,0]\n dy = [0,1,0,-1]\n while que:\n cost, x, y= heappop(que)\n \n # if cost > dp[x][y]:\n # continue\n if x == xg and y == yg:\n print(cost)\n exit(0)\n if visited[x][y]:\n for i in range(4):\n for j in range(1, k+1):\n x_, y_ = x+j*dx[i], y+j*dy[i]\n if not field[x_][y_]:\n break\n if dp[x_][y_] > dp[x][y] + 1:\n dp[x_][y_] = dp[x][y] + 1\n heappush(que, (dp[x_][y_], x_, y_))\n visited[x][y] = True\n print(-1)\n \n\ndef main():\n import sys\n def input(): return sys.stdin.readline().rstrip()\n h, w, k = map(int, input().split())\n xs, ys, xg, yg = map(int, input().split())\n field = [[False]*(w+2) for _ in range(h+2)]\n for i in range(h):\n \n s = [True if _ == '.' else False for _ in input()]\n field[i+1] = [False]+s+[False]\n dijkstra(xs, ys, xg, yg, h, w, k, field)\n\nif __name__ == '__main__':\n main()", "from heapq import heappop, heappush \nfrom collections import deque\ndef dijkstra(xs, ys, xg, yg,h,w,k,field):\n \n inf = 1e18\n dist = [[inf]*w for _ in range(h)]\n dist[xs][ys] = 0\n que = deque([(0, xs, ys)])\n dx = [-1, 0, 1, 0]\n dy = [0, 1, 0, -1]\n while que:\n cost, x, y = que.popleft()\n if cost > dist[x][y]:\n continue\n for v in range(4):\n nx, ny = x, y\n for _ in range(k):\n nx += dx[v]\n ny += dy[v]\n if not field[nx][ny]:\n break\n if dist[nx][ny]<=dist[x][y]:\n break\n if dist[nx][ny] > dist[x][y]+1:\n dist[nx][ny] = dist[x][y]+1\n que.append((dist[nx][ny], nx, ny))\n\n if dist[xg][yg] == inf:\n print(-1)\n else:\n print(dist[xg][yg])\n\n \n\ndef main():\n import sys\n def input(): return sys.stdin.readline().rstrip()\n h, w, k = map(int, input().split())\n xs, ys, xg, yg = map(int, input().split())\n field = [[False]*(w+2) for _ in range(h+2)]\n for i in range(h):\n \n s = [True if _ == '.' else False for _ in input()]\n field[i+1] = [False]+s+[False]\n h += 2\n w += 2\n dijkstra(xs, ys, xg, yg, h, w, k, field)\n\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s021292358', 's401194929', 's599899235', 's940299883', 's362759898']
[8936.0, 10776.0, 9108.0, 79220.0, 82624.0]
[26.0, 27.0, 25.0, 222.0, 1842.0]
[1474, 855, 1711, 1475, 1423]
p02644
u340781749
3,000
1,048,576
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.
["from heapq import heappop, heappush\n\nimport numpy as np\n\nfrom numba import njit\n\n\n@njit('UniTuple(i8[:],4)(i1[:],i8,i8,i8)', cache=True)\ndef reachable(field, h2, w2, k):\n \n hw = h2 * w2\n up = np.full(hw, -1, dtype=np.int64)\n dw = np.full(hw, -1, dtype=np.int64)\n lf = np.full(hw, -1, dtype=np.int64)\n rg = np.full(hw, -1, dtype=np.int64)\n lf_tmp = -1\n for i in range(w2, hw - w2):\n if field[i]:\n if lf_tmp == -1:\n lf_tmp = i\n lf[i] = max(lf_tmp, i - k)\n else:\n lf_tmp = -1\n rg_tmp = -1\n for i in range(hw - w2, w2 - 1, -1):\n if field[i]:\n if rg_tmp == -1:\n rg_tmp = i\n rg[i] = min(rg_tmp, i + k)\n else:\n rg_tmp = -1\n wk = w2 * k\n for j in range(1, w2):\n up_tmp = -1\n for i in range(j, hw, w2):\n if field[i]:\n if up_tmp == -1:\n up_tmp = i\n up[i] = max(up_tmp, i - wk)\n else:\n up_tmp = -1\n dw_tmp = 0\n for i in range(hw - w2 + j, w2 - 1, -w2):\n if field[i]:\n if dw_tmp == -1:\n dw_tmp = i\n dw[i] = min(dw_tmp, i + wk)\n else:\n dw_tmp = -1\n return up, dw, lf, rg\n\n\n@njit('i8(i8,i8,i8,i1[:],i8,i8,i8,i8)', cache=True)\ndef solve(h2, w2, k, field, x1, y1, x2, y2):\n s = x1 * w2 + y1\n t = x2 * w2 + y2\n up, dw, lf, rg = reachable(field, h2, w2, k)\n\n INF = 10 ** 18\n ans = [[INF, INF] for _ in field]\n ans[s][0] = ans[s][1] = 0\n\n q = [(0, s)]\n while q:\n print(q)\n cost, v = heappop(q)\n if v == t:\n return cost\n nc = cost + 1\n\n for u in range(up[v], v, w2):\n if ans[u][0] <= nc:\n break\n ans[u][0] = nc\n heappush(q, (nc, u))\n\n for u in range(dw[v], v, -w2):\n if ans[u][0] <= nc:\n break\n ans[u][0] = nc\n heappush(q, (nc, u))\n\n for u in range(lf[v], v, 1):\n if ans[u][1] <= nc:\n break\n ans[u][1] = nc\n heappush(q, (nc, u))\n\n for u in range(rg[v], v, -1):\n if ans[u][1] <= nc:\n break\n ans[u][1] = nc\n heappush(q, (nc, u))\n\n return -1\n\n\nh, w, k = map(int, input().split())\nx1, y1, x2, y2 = map(int, input().split())\nh2 = h + 2\nw2 = w + 2\n\nfield_tmp = [input() for _ in range(h)]\nfield = [0] * w2\nfor row in field_tmp:\n field.append(0)\n field.extend(map('@.'.index, row))\n field.append(0)\nfield.extend([0] * w2)\nfield = np.array(field, dtype=np.int8)\nprint(solve(h2, w2, k, field, x1, y1, x2, y2))\n", "from heapq import heappop, heappush\n\n\ndef solve(field, s, t, k):\n INF = 10 ** 18\n ans = [[INF, INF] for _ in field]\n ans[s][0] = ans[s][1] = 0\n MOVE = [(-w2, 0), (-1, 1), (1, 1), (w2, 0)]\n\n q = [(0, s, 0)]\n while q:\n cost, v, direction = heappop(q)\n if v == t:\n return (cost - 1) // k + 1\n\n ceiling = -1\n for di, ax in MOVE:\n u = v + di\n if field[u] == '@':\n continue\n nc = cost + 1 if di == direction else ceiling\n if nc == -1:\n nc = ceiling = ((cost - 1) // k + 1) * k + 1\n if ans[u][ax] <= nc:\n continue\n ans[u][ax] = nc\n heappush(q, (nc, u, di))\n\n return -1\n\n\nh, w, k = map(int, input().split())\nx1, y1, x2, y2 = map(int, input().split())\nh2 = h + 2\nw2 = w + 2\n\nfield_tmp = [input() for _ in range(h)]\nfield = ['@' * w2]\nfor row in field_tmp:\n field.append('@')\n field.append(row)\n field.append('@')\nfield.append('@' * w2)\nfield = ''.join(field)\ns = x1 * w2 + y1\nt = x2 * w2 + y2\nprint(solve(field, s, t, k))\n"]
['Wrong Answer', 'Accepted']
['s240087011', 's004190869']
[574344.0, 294956.0]
[3458.0, 2566.0]
[2795, 1104]
p02644
u477977638
3,000
1,048,576
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.
['import sys\nread = sys.stdin.buffer.read\ninput = sys.stdin.readline\n\n\n\n\n#from functools import lru_cache\n\ndef RD(): return sys.stdin.read()\ndef II(): return int(input())\ndef MI(): return map(int,input().split())\ndef MF(): return map(float,input().split())\ndef LI(): return list(map(int,input().split()))\ndef LF(): return list(map(float,input().split()))\ndef TI(): return tuple(map(int,input().split()))\n# rstrip().decode(\'utf-8\')\n\nfrom collections import deque\n\ndef main():\n\th,w,k=MI()\n\tx1,y1,x2,y2=MI()\n\tG=["@"]*(w+2)\n\tfor _ in range(h):\n\t\tG.append("@")\n\t\tG+=(list(map(str,input().rstrip())))\n\t\tG.append("@")\n\tG+=["@"]*(w+2)\n\t#print(G)\n\n\n\tG[x1*(w+2)+y1]=0\n\t#print(G)\n\n\tQ=deque()\n\tQ.append((x1*(w+2)+y1,0))\n\n\twhile Q:\n\t\t#print(Q)\n\t\tnow,d=Q.popleft()\n\t\t#print(Q)\n\t\tfor i in range(1,k+1):\n\t\t\tif G[now+i]==d or G[now+i]=="@":\n\t\t\t\tbreak\n\t\t\telif G[now+i]==".":\n\t\t\t\tG[now+i]=d+1\n\t\t\t\tQ.append([now+i,d+1])\n\t\t\telif G[now+i]>d:\n\t\t\t\tG[now+i]=d+1\n\t\t\t\tQ.append([now+i,d+1])\n\n\n\t\tfor i in range(1,k+1):\n\t\t\tif G[now-i]==d or G[now+i]=="@":\n\t\t\t\tbreak\n\t\t\telif G[now-i]==".":\n\t\t\t\tG[now-i]=d+1\n\t\t\t\tQ.append([now-i,d+1])\n\t\t\telif G[now-i]>d:\n\t\t\t\tG[now-i]=d+1\n\t\t\t\tQ.append([now-i,d+1])\n\t\t\telse:\n\t\t\t\tbreak\n\n\t\tfor i in range(1,k+1):\n\t\t\tif G[now+(w+2)*i]==d or G[now+(w+2)*i]=="@":\n\t\t\t\tbreak\n\t\t\telif G[now+(w+2)*i]==".":\n\t\t\t\tG[now+(w+2)*i]=d+1\n\t\t\t\tQ.append([now+(w+2)*i,d+1])\n\t\t\telif G[now+(w+2)*i]>d:\n\t\t\t\tG[now+(w+2)*i]=d+1\n\t\t\t\tQ.append([now+(w+2)*i,d+1])\n\t\t\telse:\n\t\t\t\tbreak\n\n\n\t\tfor i in range(1,k+1):\n\t\t\tif G[now-(w+2)*i]==d or G[now-(w+2)*i]=="@":\n\t\t\t\tbreak\n\t\t\telif G[now-(w+2)*i]==".":\n\t\t\t\tG[now-(w+2)*i]=d+1\n\t\t\t\tQ.append([now-(w+2)*i,d+1])\n\t\t\telif G[now-(w+2)*i]>d:\n\t\t\t\tG[now-(w+2)*i]=d+1\n\t\t\t\tQ.append([now-(w+2)*i,d+1])\n\t\t\telse:\n\t\t\t\tbreak\n\t\t#print(Q)\n\t#print(G)\n\n\tif G[x2*(w+2)+y2]==".":\n\t\tprint(-1)\n\telse:\n\t\tprint(G[x2*(w+2)+y2])\n\n\nif __name__ == "__main__":\n\tmain()\n', 'import sys\nread = sys.stdin.buffer.read\ninput = sys.stdin.readline\n\n\n\n\n#from functools import lru_cache\n\ndef RD(): return sys.stdin.read()\ndef II(): return int(input())\ndef MI(): return map(int,input().split())\ndef MF(): return map(float,input().split())\ndef LI(): return list(map(int,input().split()))\ndef LF(): return list(map(float,input().split()))\ndef TI(): return tuple(map(int,input().split()))\n# rstrip().decode(\'utf-8\')\n\nfrom collections import deque\n\ndef main():\n\th,w,k=MI()\n\tx1,y1,x2,y2=MI()\n\tG=["@"]*(w+2)\n\tfor _ in range(h):\n\t\tG.append("@")\n\t\tG+=(list(map(str,input().rstrip())))\n\t\tG.append("@")\n\tG+=["@"]*(w+2)\n\t#print(G)\n\n\n\tG[x1*(w+2)+y1]=0\n\t#print(G)\n\n\tQ=deque()\n\tQ.append((x1*(w+2)+y1,0))\n\n\twhile Q:\n\t\t#print(Q)\n\t\tnow,d=Q.popleft()\n\t\t#print(Q)\n\t\tfor m in [1,-1,w+2,-w-2]:\n\t\t\tfor i in range(1,k+1):\n\t\t\t\tif G[now+m*i]==d or G[now+m*i]=="@":\n\t\t\t\t\tbreak\n\t\t\t\telif G[now+m*i]==".":\n\t\t\t\t\tG[now+m*i]=d+1\n\t\t\t\t\tQ.append([now+m*i,d+1])\n\t\t\t\telif G[now+m*i]==d+1:\n\t\t\t\t\tcontinue\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\n\t\t#print(Q)\n\t#print(G)\n\n\tif G[x2*(w+2)+y2]==".":\n\t\tprint(-1)\n\telse:\n\t\tprint(G[x2*(w+2)+y2])\n\n\nif __name__ == "__main__":\n\tmain()\n']
['Runtime Error', 'Accepted']
['s027289983', 's656981160']
[59056.0, 59108.0]
[1380.0, 1936.0]
[1911, 1196]
p02644
u543954314
3,000
1,048,576
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.
["import sys\nfrom collections import deque\n\nreadline = sys.stdin.readline\nreadall = sys.stdin.read\nns = lambda: readline().rstrip()\nni = lambda: int(readline().rstrip())\nnm = lambda: map(int, readline().split())\nnl = lambda: list(map(int, readline().split()))\n\n\ndef solve():\n h, w, k = nm()\n sy, sx, gy, gx = nm()\n d = [(0, 1), (1, 0), (-1, 0), (0, -1)]\n sx -= 1; sy -= 1\n gx -= 1; gy -= 1\n C = [ns() for _ in range(w)]\n G = [[10**7]*w for _ in range(w)]\n G[sy][sx] = 0\n q = deque([(sy, sx)])\n while q:\n y, x = q.popleft()\n for i in range(4):\n dy, dx = d[i]\n ny, nx = y, x\n for _ in range(k):\n ny += dy; nx += dx\n if ny < 0 or w <= ny or nx < 0 or w <= nx:\n break\n if C[ny][nx] == '@' or G[ny][nx] <= G[y][x]:\n break\n if G[ny][nx] > G[y][x] + 1:\n G[ny][nx] = G[y][x] + 1\n q.append((ny, nx))\n ans = G[gy][gx]\n print(ans if ans < 10**7 else -1)\n return\n\nsolve()\n", "import sys\nfrom collections import deque\n\nreadline = sys.stdin.readline\nreadall = sys.stdin.read\nns = lambda: readline().rstrip()\nni = lambda: int(readline().rstrip())\nnm = lambda: map(int, readline().split())\nnl = lambda: list(map(int, readline().split()))\n\n\ndef solve():\n h, w, k = nm()\n sy, sx, gy, gx = nm()\n d = [(0, 1), (1, 0), (-1, 0), (0, -1)]\n sx -= 1; sy -= 1\n gx -= 1; gy -= 1\n C = [ns() for _ in range(h)]\n G = [[10**7]*w for _ in range(h)]\n G[sy][sx] = 0\n q = deque([(sy, sx)])\n while q:\n y, x = q.popleft()\n for i in range(4):\n dy, dx = d[i]\n ny, nx = y, x\n for _ in range(k):\n ny += dy; nx += dx\n if ny < 0 or h <= ny or nx < 0 or w <= nx:\n break\n if C[ny][nx] == '@' or G[ny][nx] <= G[y][x]:\n break\n if G[ny][nx] > G[y][x] + 1:\n G[ny][nx] = G[y][x] + 1\n q.append((ny, nx))\n if ny == gy and nx == gx:\n print(G[y][x] + 1)\n return\n print(-1)\n return\n\nsolve()\n"]
['Runtime Error', 'Accepted']
['s117782244', 's384450699']
[3417240.0, 36768.0]
[3415.0, 1578.0]
[1080, 1156]
p02644
u726285999
3,000
1,048,576
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.
['from collections import deque\nimport math\nimport sys\n\nN_MAX = 200000 + 5\nsys.setrecursionlimit(N_MAX)\n\nH, W, K = map(int, sys.stdin.readline().split())\nx1, y1, x2, y2 = map(int, sys.stdin.readline().split())\nINF = 10**6 * K\n\ndp = [[INF for _ in range(W+2)] for _ in range(H+2)]\n\ndp[0] = [-1]*(W+2)\ndp[H+1] = [-1]*(W+2)\nfor h in range(1,H+1):\n s = sys.stdin.readline()\n dp[h][0] = -1\n dp[h][W+1] = -1\n for w in range(1,W+1):\n if s[w-1] == "@":\n dp[h][w] = -1\n\n### BFS ###\n\n\nD = [0, 1, 2, 3] # direction\nY = [1, 0, -1, 0]\nX = [0, 1, 0, -1]\n\ndef bfs(x1, y1, x2, y2):\n \n q = deque()\n q.append((x1, y1))\n\n while q:\n # print(q)\n x0, y0 = q.popleft()\n\n for x, y in zip(X, Y):\n\n for i in range(1,K+1):\n\n # print(y0,y,x0,x,d, (y0+y,x0+x,d), end=" : ")\n dp_c = dp[x0][y0] \n n_x, n_y = x0+x*i, y0+y*i\n\n # print(dp_c, (n_x,n_y), end=" : ")\n\n if dp[n_x][n_y] == -1:\n # print("@")\n break\n\n if dp[n_x][n_y] == INF:\n dp[n_x][n_y] = c + 1\n elif dp[n_x][n_y] <= c:\n break\n\n if n_x == x2 and n_y == y2:\n return dp[n_x][n_y]\n\n q.append((n_x, n_y))\n\n return -1\n\n\ndp[x1][y1] = 0\n\na = bfs(x1,y1,x2,y2)\n\nprint(a)', 'from collections import deque\nimport sys\n\nN_MAX = 200000 + 5\n\nH, W, K = map(int, input().split())\nsth, stw, glh, glw = map(int, input().split())\n\nINF = 10**6 * K\n\ndp = [[INF for _ in range(W + 2)] for _ in range(H + 2)]\n\ndp[0] = [-1] * (W + 2)\ndp[H + 1] = [-1] * (W + 2)\nfor h in range(1, H + 1):\n s = sys.stdin.readline()\n dp[h][0] = -1\n dp[h][W + 1] = -1\n for w in range(1, W + 1):\n if s[w - 1] == "@":\n dp[h][w] = -1\n\ndp[sth][stw] = 0\n\n\n# Seen = [[INF]*W for _ in range(H)]\nXY = {(1, 0), (-1, 0), (0, 1), (0, -1)}\n\n\ndef bfs(sth, stw, glh, glw):\n next_q = deque()\n next_q.append((sth, stw))\n\n while len(next_q) != 0:\n \n h, w = next_q.popleft()\n for dh, dw in XY:\n for sk in range(1, K + 1):\n hs, ws = h + dh * sk, w + dw * sk\n if dp[hs][ws] == -1:\n break\n if dp[hs][ws] == INF:\n next_q.append((hs, ws))\n dp[hs][ws] = dp[h][w] + 1\n elif dp[hs][ws] <= dp[h][w]:\n \n \n break\n # if hs == glh and ws == glw:\n \n # return -1\n\n\ndef main():\n bfs(sth, stw, glh, glw)\n\n if dp[glh, glw] == INF:\n print(-1)\n else:\n print(dp[glh, glw])\n\n\nif __name__ == \'__main__\':\n main()\n', 'from collections import deque\nimport sys\n\nN_MAX = 200000 + 5\n\nH, W, K = map(int, input().split())\nsth, stw, glh, glw = map(int, input().split())\n\nINF = 10**6 * K\n\ndp = [[INF for _ in range(W + 2)] for _ in range(H + 2)]\n\ndp[0] = [-1] * (W + 2)\ndp[H + 1] = [-1] * (W + 2)\nfor h in range(1, H + 1):\n s = sys.stdin.readline()\n dp[h][0] = -1\n dp[h][W + 1] = -1\n for w in range(1, W + 1):\n if s[w - 1] == "@":\n dp[h][w] = -1\n\ndp[sth][stw] = 0\n\n\n# Seen = [[INF]*W for _ in range(H)]\nXY = {(1, 0), (-1, 0), (0, 1), (0, -1)}\n\n\ndef bfs(sth, stw, glh, glw):\n next_q = deque()\n next_q.append((sth, stw))\n\n while len(next_q) != 0:\n \n h, w = next_q.popleft()\n for dh, dw in XY:\n for sk in range(1, K + 1):\n hs, ws = h + dh * sk, w + dw * sk\n if dp[hs][ws] == -1:\n break\n if dp[hs][ws] == INF:\n next_q.append((hs, ws))\n dp[hs][ws] = dp[h][w] + 1\n elif dp[hs][ws] <= dp[h][w]:\n \n \n break\n # if hs == glh and ws == glw:\n \n # return -1\n\n\ndef main():\n bfs(sth, stw, glh, glw)\n\n if dp[glh][glw] == INF:\n print(-1)\n else:\n print(dp[glh][glw])\n\n\nif __name__ == \'__main__\':\n main()\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s482261093', 's824587550', 's619001836']
[40560.0, 53104.0, 53372.0]
[291.0, 2155.0, 2137.0]
[1468, 1571, 1571]
p02644
u729133443
3,000
1,048,576
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.
["h,a,*m=open(0)\nh,w,k,a,b,f,g=map(int,(h+a).split())\nd=[I:=9**9]*h*w\nd[~w+a*w+b]=1\nq=[(a-1,b-1)]\nfor s,t in q:\n p=d[s*w+t]+1\n for y,x in(-1,0),(0,-1),(0,1),(1,0):\n for z in range(k):\n if(h>(i:=s+y*~z)>-1<(j:=t+x*~z)<w)-1or'.'<m[i][j]or d[i*w+j]<=p:break\n q+=(i,j),;d[i*w+j]=p\nprint(d[~w+f*w+g]%I-1)", "h,a,*m=open(0)\nh,w,k,a,b,f,g=map(int,(h+a).split())\nd=[I:=h*w]*I\nm+=d,\nq=[a:=~w+a*w+b]\nd[a]=1\nfor s in q:\n for y,x in(1,0),(-1,0),(0,1),(0,-1):\n for z in range(k):\n if'.'!=m[(i:=s//w+y*~z)][(j:=s%w+x*~z)]or d[s]>=d[(t:=i*w+j)]:break\n if-~d[s]<d[t]:q+=t,;d[t]=d[s]+1\nprint(d[~w+f*w+g]%I-1)"]
['Wrong Answer', 'Accepted']
['s679528022', 's472612767']
[117980.0, 66284.0]
[2897.0, 2743.0]
[302, 293]
p02644
u748241164
3,000
1,048,576
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.
['from collections import deque\ndef bfs(maze, visited, sy, sx, gy, gx):\n queue = deque([[sy, sx]])\n visited[sy][sx] = 0\n while queue:\n \n y, x = queue.popleft()\n if [y, x] == [gy, gx]:\n print(visited[y][x])\n quit()\n return visited[y][x]\n for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):\n p = 0\n l = 1\n while p == 0:\n new_y, new_x = y + j * l, x + k * l \n if (0 <= new_y < H) and (0 <= new_x < W): \n if maze[new_y][new_x] == "@":\n p = 1\n if visited[new_y][new_x] == -1:\n visited[new_y][new_x] = visited[y][x] + 1\n queue.append([new_y, new_x])\n else:\n p = 1\n else:\n p = 1\n l += 1\n if l == K + 1:\n p = 1\n\nH, W, K = map(int, input().split())\n\nx1, y1, x2, y2 = map(int, input().split())\nx1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1\nC = [0] * H\nfor i in range(H):\n C[i] = str(input())\nvisited = [[-1] * W for i in range(H)]\nbfs(C, visited, x1, y1, x2, y2)\n#print(visited)\nprint(-1)\n \n\n\n', 'from collections import deque\ndef bfs(maze, visited, sy, sx, gy, gx):\n queue = deque([[sy, sx]])\n visited[sy][sx] = 0\n while queue:\n \n y, x = queue.popleft()\n if [y, x] == [gy, gx]:\n print(visited[y][x])\n quit()\n return visited[y][x]\n for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):\n p = 0\n l = 1\n while p == 0:\n new_y, new_x = y + j * l, x + k * l \n #print(new_y, new_x)\n if (0 <= new_y < H) and (0 <= new_x < W): \n if maze[new_y][new_x] == "@":\n p = 1\n else:\n if visited[new_y][new_x] == -1:\n visited[new_y][new_x] = visited[y][x] + 1\n queue.append([new_y, new_x])\n else:\n p = 1\n else:\n p = 1\n l += 1\n if l == K + 1:\n p = 1\n\nH, W, K = map(int, input().split())\n\nx1, y1, x2, y2 = map(int, input().split())\nx1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1\nC = [0] * H\nfor i in range(H):\n C[i] = str(input())\nvisited = [[-1] * W for i in range(H)]\nbfs(C, visited, x1, y1, x2, y2)\n#print(visited)\nprint(-1)\n \n\n\n', 'from collections import deque\ndef bfs(maze, visited, sy, sx, gy, gx):\n queue = deque([[sy, sx]])\n visited[sy][sx] = 0\n while queue:\n \n y, x = queue.popleft()\n if [y, x] == [gy, gx]:\n return visited[y][x]\n for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):\n p = 0\n l = 1\n while p == 0:\n new_y, new_x = y + j * l, x + k * l \n if (0 <= new_y < H) and (0 <= new_x < W): \n if maze[new_y][new_x] == "@":\n p = 1\n elif visited[new_y][new_x] == -1:\n visited[new_y][new_x] = visited[y][x] + 1\n queue.append([new_y, new_x])\n else:\n p = 1\n else:\n p = 1\n l += 1\n if l == K + 1:\n p = 1\n\nH, W, K = map(int, input().split())\n\nx1, y1, x2, y2 = map(int, input().split())\nx1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1\nC = [0] * H\nfor i in range(H):\n C[i] = str(input())\nvisited = [[-1] * W for i in range(H)]\nbfs(C, visited, x1, y1, x2, y2)\n#print(visited)\nprint(visited[x2][y2])\n \n\n\n', 'from collections import deque\ndef bfs(maze, visited, sy, sx, gy, gx):\n queue = deque([[sy, sx]])\n visited[sy][sx] = 0\n while queue:\n \n y, x = queue.popleft()\n if [y, x] == [gy, gx]:\n print(visited[y][x])\n quit()\n return visited[y][x]\n for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):\n p = 0\n l = 1\n while p == 0:\n new_y, new_x = y + j * l, x + k * l \n #print(new_y, new_x)\n if (0 <= new_y < H) and (0 <= new_x < W): \n if maze[new_y][new_x] == "@":\n p = 1\n else:\n if visited[new_y][new_x] == -1:\n visited[new_y][new_x] = visited[y][x] + 1\n queue.append([new_y, new_x])\n else:\n p = 1\n else:\n p = 1\n l += 1\n if l == K + 1:\n p = 1\n\nH, W, K = map(int, input().split())\n\nx1, y1, x2, y2 = map(int, input().split())\nx1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1\nC = [0] * H\nfor i in range(H):\n C[i] = str(input())\nvisited = [[-1] * W for i in range(H)]\nbfs(C, visited, x1, y1, x2, y2)\nprint(visited)\nprint(-1)\n \n\n\n', 'from collections import deque\ndef bfs(maze, visited, sy, sx, gy, gx):\n queue = deque([[sy, sx]])\n visited[sy][sx] = 0\n while queue:\n \n y, x = queue.popleft()\n if [y, x] == [gy, gx]:\n return visited[y][x]\n for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):\n p = 0\n l = 1\n while p == 0:\n new_y, new_x = y + j * l, x + k * l \n if (0 <= new_y < H) and (0 <= new_x < W): \n if maze[new_y][new_x] == "@":\n p = 1\n elif visited[new_y][new_x] == -1:\n visited[new_y][new_x] = visited[y][x] + 1\n queue.append([new_y, new_x])\n elif visited[new_y][new_x] < visited[y][x] + 1:\n p = 1\n else:\n p = 1\n l += 1\n if l == K + 1:\n p = 1\n\nH, W, K = map(int, input().split())\n\nx1, y1, x2, y2 = map(int, input().split())\nx1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1\nC = [0] * H\nfor i in range(H):\n C[i] = str(input())\nvisited = [[-1] * W for i in range(H)]\nbfs(C, visited, x1, y1, x2, y2)\n#print(visited)\nprint(visited[x2][y2])\n \n\n\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s065946282', 's806151328', 's839969151', 's978841911', 's456847901']
[31028.0, 36616.0, 36512.0, 36676.0, 36548.0]
[1693.0, 1487.0, 1396.0, 1451.0, 1663.0]
[1526, 1583, 1479, 1582, 1521]
p02644
u809108154
3,000
1,048,576
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.
["\ndef main():\n h, w, k = map(int, input().split())\n x1, y1, x2, y2 = map(int, input().split())\n \n # surround the square with '@'\n c = [['@'] * (w+2)]\n for _ in range(h):\n i = input()\n l = ['@']\n for j in i:\n l.append(j)\n l.append('@')\n c.append(l)\n c.append(['@'] * (w+2))\n \n \n # seen[x][y] = the minimum cost of (x, y)\n # if seen[x][y] == -1, (x, y) is unresearched\n seen = [[-1] * (w+2) for _ in range(h+2)]\n \n \n todo = [(0, x1, y1, 0)]\n heapq.heapify(todo)\n \n # direction\n dx = [-1, 0, 1, 0]\n dy = [0, 1, 0, -1]\n \n while len(todo) > 0:\n cost, xi, yi, direction = heapq.heappop(todo)\n \n # only straight\n if seen[xi][yi] != -1:\n if (seen[xi][yi]+k-1)//k * k > cost:\n xj, yj = xi + dx[direction], yi + dy[direction]\n if c[xj][yj] == '.':\n heapq.heappush(todo, (cost+1, xj, yj, direction))\n continue\n seen[xi][yi] = cost\n \n # goal\n if xi == x2 and yi == y2:\n print((cost+k-1)//k)\n exit()\n \n # 4 directions\n for j in range(4):\n xj, yj = xi + dx[j], yi + dy[j]\n if c[xj][yj] == '.':\n if j == direction:\n if seen[xj][yj] == -1 or (seen[xj][yj]+k-1)//k * k > cost:\n heapq.heappush(todo, (cost+1, xj, yj, j))\n elif seen[xj][yj] == -1:\n heapq.heappush(todo, ((cost+k-1)//k * k + 1, xj, yj, j))\n \n print(-1)\n \nmain()", "import sys\nread = sys.stdin.read\nreadline = sys.stdin.buffer.readline\nfrom collections import deque\nINF = float('inf')\n \n \ndef main():\n H, W, K = map(int, readline().split())\n x1, y1, x2, y2 = map(int, readline().split())\n x1 -= 1\n y1 -= 1\n x2 -= 1\n y2 -= 1\n C = read().split()\n \n dist = [[INF] * W for i in range(H)]\n dist[x1][y1] = 0\n d = deque([[x1, y1]])\n dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]\n while d:\n x, y = d.popleft()\n if (x, y) == (x2, y2):\n print(dist[x][y])\n quit()\n for dx, dy in dxy:\n xx = x\n yy = y\n for i in range(K):\n xx += dx;\n yy += dy\n if 0 <= xx < H and 0 <= yy < W and C[xx][yy] != '@':\n if dist[xx][yy] <= dist[x][y]:\n break\n if dist[xx][yy] == INF:\n d.append([xx, yy])\n dist[xx][yy] = dist[x][y] + 1\n else:\n break\n \n print(-1)\n \n \nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Accepted']
['s270137433', 's032531210']
[58772.0, 36392.0]
[130.0, 1587.0]
[1622, 1093]
p02644
u839509562
3,000
1,048,576
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.
['import sys\nfrom collections import deque\n\ninput = sys.stdin.readline\n\n\ndef log(*args):\n print(*args, file=sys.stderr)\n\n\ndef main():\n h, w, k = map(int, input().strip().split())\n x1, y1, x2, y2 = map(int, input().strip().split())\n x1 -= 1\n y1 -= 1\n x2 -= 1\n y2 -= 1\n m = []\n costs = [[None for j in range(w)] for i in range(h)]\n for _ in range(h):\n m.append(list(input().strip()))\n q = deque()\n q.append((x1, y1, 0))\n directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n while q:\n (x, y, cost) = q.popleft()\n if (x, y) == (x2, y2):\n print(cost)\n return\n for (add_x, add_y) in directions:\n for dist in range(1, k + 1):\n new_x = x + add_x * dist\n new_y = y + add_y * dist\n if new_x >= h or new_x < 0 or new_y >= w or new_y < 0:\n break\n if m[new_x][new_y] == \'.\' and costs[new_x][new_y] is None:\n costs[new_x][new_y] = cost + 1\n q.append((new_x, new_y, cost + 1))\n print("-1")\n\n\nif __name__ == \'__main__\':\n main()\n', 'import sys\nfrom collections import deque\n\ninput = sys.stdin.readline\n\n\ndef log(*args):\n print(*args, file=sys.stderr)\n\n\ndef main():\n h, w, k = map(int, input().strip().split())\n x1, y1, x2, y2 = map(int, input().strip().split())\n x1 -= 1\n y1 -= 1\n x2 -= 1\n y2 -= 1\n m = []\n costs1 = [[None for j in range(w)] for i in range(h)]\n costs2 = [[None for j in range(w)] for i in range(h)]\n for _ in range(h):\n m.append(list(input().strip()))\n q1 = deque()\n q1.append((x1, y1, 0))\n costs1[x1][y1] = 0\n q2 = deque()\n q2.append((x2, y2, 0))\n costs2[x2][y2] = 0\n directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n while q1 and q2:\n (x, y, cost) = q1.popleft()\n if not costs2[x][y] is None:\n print(cost + costs2[x][y])\n return\n for (add_x, add_y) in directions:\n for dist in range(1, k + 1):\n new_x = x + add_x * dist\n new_y = y + add_y * dist\n if new_x >= h or new_x < 0 or new_y >= w or new_y < 0 or m[new_x][new_y] == \'@\' or ((not costs1[new_x][new_y] is None) and costs1[new_x][new_y] < cost + 1):\n break\n if costs1[new_x][new_y] is None:\n costs1[new_x][new_y] = cost + 1\n q1.append((new_x, new_y, cost + 1))\n (x, y, cost) = q2.popleft()\n if not costs1[x][y] is None:\n print(cost + costs1[x][y])\n return\n for (add_x, add_y) in directions:\n for dist in range(1, k + 1):\n new_x = x + add_x * dist\n new_y = y + add_y * dist\n if new_x >= h or new_x < 0 or new_y >= w or new_y < 0 or m[new_x][new_y] == \'@\' or ((not costs2[new_x][new_y] is None) and costs2[new_x][new_y] < cost + 1):\n break\n if costs2[new_x][new_y] is None:\n costs2[new_x][new_y] = cost + 1\n q2.append((new_x, new_y, cost + 1))\n print("-1")\n\n\nif __name__ == \'__main__\':\n main()\n']
['Wrong Answer', 'Accepted']
['s183499078', 's472803954']
[109804.0, 51328.0]
[3312.0, 1912.0]
[1132, 2043]
p02644
u947883560
3,000
1,048,576
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.
['#!/usr/bin/env python3\nimport sys\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef ZIP(n): return [LIST() for _ in range(n)]\n\n@profile\ndef main():\n from heapq import heappush, heappop, heapify\n H, W, K = MAP()\n HH = max(H, W) + 2\n x1, y1, x2, y2 = LIST()\n c = [[-1] + [0 if c == "." else -1 for c in input()] + [-1]\n for i in range(H)]\n c = [[-1] * (W + 2)] + c + [[-1] * (W + 2)]\n\n \n stack = []\n heappush(stack, (0, x1, y1, 0))\n heappush(stack, (0, x1, y1, 1))\n heappush(stack, (0, x1, y1, 2))\n heappush(stack, (0, x1, y1, 3))\n DX = (1, 0, -1, 0)\n DY = (0, 1, 0, -1)\n while stack:\n new_stack = []\n while stack:\n curr, x, y, d = heappop(stack)\n dx, dy = DX[d], DY[d]\n flag = True\n a = curr + 1\n for k in range(1, K + 1):\n xx, yy = x + k * dx, y + k * dy\n if c[xx][yy] == 0:\n b = c[xx + DX[(d - 1) % 4]][yy + DY[(d - 1) % 4]]\n if b == 0 or b == a + 1:\n heappush(new_stack, (a, xx, yy, (d - 1) % 4))\n b = c[xx + DX[(d + 1) % 4]][yy + DY[(d + 1) % 4]]\n if b == 0 or b == a + 1:\n heappush(new_stack, (a, xx, yy, (d + 1) % 4))\n c[xx][yy] = a\n elif c[xx][yy] != a:\n flag = False\n break\n if flag:\n heappush(new_stack, (a, xx, yy, d))\n if c[x2][y2] > 0:\n print(c[x2][y2], flush=True)\n exit(0)\n stack = new_stack\n\n print(-1)\n return\n\n\nif __name__ == \'__main__\':\n main()\n', '#!/usr/bin/env python3\nimport sys\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef ZIP(n): return [LIST() for _ in range(n)]\n\ndef main():\n from heapq import heappush, heappop, heapify\n H, W, K = MAP()\n HH = max(H, W) + 2\n x1, y1, x2, y2 = LIST()\n c = [[-1] + [0 if c == "." else -1 for c in input()] + [-1]\n for i in range(H)]\n c = [[-1] * (W + 2)] + c + [[-1] * (W + 2)]\n\n \n stack = []\n heappush(stack, (0, x1, y1, 0))\n heappush(stack, (0, x1, y1, 1))\n heappush(stack, (0, x1, y1, 2))\n heappush(stack, (0, x1, y1, 3))\n DX = (1, 0, -1, 0)\n DY = (0, 1, 0, -1)\n while stack:\n new_stack = []\n while stack:\n curr, x, y, d = heappop(stack)\n dx, dy = DX[d], DY[d]\n flag = True\n a = curr + 1\n for k in range(1, K + 1):\n xx, yy = x + k * dx, y + k * dy\n if c[xx][yy] == 0:\n b = c[xx + DX[(d - 1) % 4]][yy + DY[(d - 1) % 4]]\n if b == 0 or b == a + 1:\n heappush(new_stack, (a, xx, yy, (d - 1) % 4))\n b = c[xx + DX[(d + 1) % 4]][yy + DY[(d + 1) % 4]]\n if b == 0 or b == a + 1:\n heappush(new_stack, (a, xx, yy, (d + 1) % 4))\n c[xx][yy] = a\n elif c[xx][yy] != a:\n flag = False\n break\n if flag:\n heappush(new_stack, (a, xx, yy, d))\n if c[x2][y2] > 0:\n print(c[x2][y2], flush=True)\n exit(0)\n stack = new_stack\n\n print(-1)\n return\n\n\nif __name__ == \'__main__\':\n main()\n']
['Runtime Error', 'Accepted']
['s855185650', 's653801341']
[9056.0, 32644.0]
[30.0, 2823.0]
[1840, 1831]
p02644
u971124021
3,000
1,048,576
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.
["from collections import deque\nh,w,k = list(map(int, input().split()))\nx1,y1,x2,y2 = list(map(int, input().split()))\nx1,y1,x2,y2 = x1-1,y1-1,x2-1,y2-1\nc = [[]*w for _ in range(h)]\ndp = [[0]*w for _ in range(h)]\nque = deque()\nfor i in range(h):\n for j,s in enumerate(input()):\n c[i].append(s)\n if s != '.':\n dp[i][j] = -1\n\nans = 0\ndp[x1][y1] = 1\nque.append((x1,y1))\ndx = [1,0,-1,0]\ndy = [0,1,0,-1]\n\nwhile que:\n p = que.popleft()\n if (p[0] == x2) & (p[1] == y2):\n break\n for i in range(4):\n nx = p[0] + dx[i]\n ny = p[1] + dy[i]\n if (nx>=0) & (nx<=(h-1)) & (ny>=0) & (ny<=(w-1)):\n cnt = 0\n while dp[nx][ny] == 0:\n que.append((nx,ny))\n dp[nx][ny] = dp[p[0]][p[1]] + 1\n cnt += 1\n nnx = nx + dx[i]\n nny = ny + dy[i]\n if (nnx<0) | (nnx>(h-1)) | (nny<0) | (nny>(w-1)) | (cnt >= k):\n break\n nx = nnx\n ny = nny\n\nif dp[x2][y2] != 0:\n print(dp[x2][y2])\nelse:\n print(-1)", "#import heapq\nfrom collections import deque\nh,w,k = list(map(int, input().split()))\nx1,y1,x2,y2 = list(map(int, input().split()))\nx1,y1,x2,y2 = x1-1,y1-1,x2-1,y2-1\ndp = [[-1]*w for _ in range(h)]\n\nque = deque()\nc = [input() for _ in range(h)]\n\ndp[x1][y1] = 0\n#heapq.heappush(que, (dp[x1][y1], [x1,y1]))\nque.append((x1,y1))\ndx = [1,0,-1,0]\ndy = [0,1,0,-1]\nwhile que:\n #p= heapq.heappop(que)[1]\n #x,y= p[0],p[1]\n p = que.popleft()\n if (p[0] == x2) & (p[1] == y2):exit(print(dp[x2][y2]))\n for i in range(4):\n for j in range(1,k+1):\n nx = p[0] + dx[i]*j\n ny = p[1] + dy[i]*j\n if not ((0 <= nx < h) & (0 <= ny < w)):break\n if c[nx][ny] == '@':break\n if 0 <= dp[nx][ny] <= dp[p[0]][p[1]]:break\n if dp[nx][ny] == -1:\n #heapq.heappush(que, (dp[nx][ny], [nx,ny]))\n que.append((nx,ny))\n dp[nx][ny] = dp[p[0]][p[1]] + 1\n\nprint(-1)"]
['Wrong Answer', 'Accepted']
['s702408454', 's562407516']
[45124.0, 36476.0]
[2145.0, 2855.0]
[960, 885]
p02644
u989345508
3,000
1,048,576
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.
["h,a,*m=open(0)\nh,w,k,a,b,f,g=map(int,(h+a).split())\nd=[I:=h*w]*I\nm+=d,\nq=[a:=~w+a*w+b]\nd[a]=1\nfor s in q:\n for y,x in(1,0),(-1,0),(0,1),(0,-1):\n for z in range(k):\n i,j=s//w+y*~z,s%w+x*~z;t=i*w+j;p=d[s]+1\n if'.'<m[i][j]or d[t]<p:break\n if d[t]>p:q+=t,;d[t]=p\nprint(d[~w+f*w+g]%I-1)", "h,a,*m=open(0)\nh,w,k,a,b,f,g=map(int,(h+a).split())\nd=[I:=h*w]*I\nm+=d,\nq=[a:=~w+a*w+b]\nd[a]=1\nfor s in q:\n for y,x in(1,0),(-1,0),(0,1),(0,-1):\n for z in range(k):\n i,j=s//w+y*~z,s%w+x*~z;t=i*w+j\n if'.'!=m[i][j]or(p:=[s]+1)>d[t]:break\n if d[t]>p:q+=t,;d[t]=p\nprint(d[~w+f*w+g]%I-1)", "h,a,*m=open(0)\nh,w,k,a,b,f,g=map(int,(h+a).split())\nd=[I:=h*w]*I\nm+=d,\nd[a]=1\nfor s in(q:=[a:=~w+a*w+b]):\n for y,x in(1,0),(-1,0),(0,1),(0,-1):\n for z in range(k):\n i,j=s//w+y*~z,s%w+x*~z;t=i*w+j;p=d[s]+1\n if'.'<m[i][j]or d[t]<p:break\n if d[t]>p:q+=t,;d[t]=p\nprint(d[~w+f*w+g]%I-1)", "h,a,*m=open(0)\nh,w,k,a,b,f,g=map(int,(h+a).split())\nI=h*w;d=[I]*h*w;a=~w+a*w+b\nd[a]=2\nq=[a]\nfor s in q:\n for y,x in(1,0),(-1,0),(0,1),(0,-1):\n for z in range(k):\n i,j=s//w+y*~z,s%w+x*~z;t=i*w+j\n if(h>i>-1<j<w)-1or'.'<m[i][j]or d[t]<=d[s]:break\n if d[t]==I:q+=t,;d[t]=d[s]+1\nprint(d[~w+f*w+g]%I-1)\n", 'from collections import*\nz,v,a=input,range,print\nh,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)])\nwhile d:\n x,y=d.popleft();j=l[x][y]\n if(x==t)&(y==u):exit(a(j))\n for e,f in[[1,0],[-1,0],[0,-1],[0,1]]:\n for i in v(1,k+1):\n p,q=x+e*i,y+f*i\n if not((0<=p<h)&(0<=q<w))or b[p][q]=="@" or 0<=l[p][q]<=j:break\n if l[p][q]<0:d+=[(p,q)];l[p][q]=j+1\na(-1)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s172681252', 's190095940', 's200105848', 's495549442', 's783831769']
[25080.0, 17764.0, 17880.0, 66300.0, 36464.0]
[876.0, 39.0, 43.0, 3309.0, 2637.0]
[288, 288, 288, 304, 461]
p02644
u994935583
3,000
1,048,576
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.
["def resolve():\n H,W,K = map(int,input().split())\n ys, xs, yg, xg = map(int,input().split())\n\n board = [['@']*(W+2)]\n for i in range(H):\n board.append(['@'] + list(input())+['@'])\n board.append(['@']*(W+2))\n board[ys][xs] = '#'\n\n queue = deque([(xs,ys,0)])\n while queue:\n x,y,dep = queue.popleft()\n l = []\n f1 = True\n f2 = True\n f3 = True\n f4 = True\n for i in range(1,K+1):\n if f1:\n if board[y][x+i] == '.':\n l.append((x+i,y))\n elif board[y][x+i] == '@' or board[y][x+i] != dep+1:\n f1 = False \n if f2:\n if board[y][x-i] == '.':\n l.append((x-i,y))\n elif board[y][x-i] == '@' or board[y][x-i] != dep+1:\n f2 = False \n if f3:\n if board[y+i][x] == '.':\n l.append((x,y+i))\n elif board[y+i][x] == '@' or board[y+i][x] != dep+1:\n f3 = False \n if f4:\n if board[y-i][x] == '.':\n l.append((x,y-i))\n elif board[y-i][x] == '@' or board[y-i][x] != dep+1:\n f4 = False \n if not(f1 or f2 or f3 or f4):\n break\n for nx,ny in l:\n if board[ny][nx] == '.':\n board[ny][nx] = dep + 1\n if (nx,ny) == (xg,yg):\n print(dep+1)\n return \n else:\n queue.append((nx,ny,dep+1))\n print(-1)\n return \nresolve()", "from collections import deque\n\ndef resolve():\n H,W,K = map(int,input().split())\n ys, xs, yg, xg = map(int,input().split())\n\n board = [['@']*(W+2)]\n for i in range(H):\n board.append(['@'] + list(input())+['@'])\n board.append(['@']*(W+2))\n board[ys][xs] = '#'\n\n queue = deque([(xs,ys,0)])\n while queue:\n x,y,dep = queue.popleft()\n l = []\n f1 = True\n f2 = True\n f3 = True\n f4 = True\n for i in range(1,K+1):\n if f1:\n if board[y][x+i] == '.':\n l.append((x+i,y))\n elif board[y][x+i] == '@' or board[y][x+i] != dep+1:\n f1 = False \n if f2:\n if board[y][x-i] == '.':\n l.append((x-i,y))\n elif board[y][x-i] == '@' or board[y][x-i] != dep+1:\n f2 = False \n if f3:\n if board[y+i][x] == '.':\n l.append((x,y+i))\n elif board[y+i][x] == '@' or board[y+i][x] != dep+1:\n f3 = False \n if f4:\n if board[y-i][x] == '.':\n l.append((x,y-i))\n elif board[y-i][x] == '@' or board[y-i][x] != dep+1:\n f4 = False \n if not(f1 or f2 or f3 or f4):\n break\n for nx,ny in l:\n if board[ny][nx] == '.':\n board[ny][nx] = dep + 1\n if (nx,ny) == (xg,yg):\n print(dep+1)\n return \n else:\n queue.append((nx,ny,dep+1))\n print(-1)\n return \nresolve()"]
['Runtime Error', 'Accepted']
['s881221523', 's178085254']
[32384.0, 51080.0]
[76.0, 1073.0]
[1619, 1650]
p02651
u021548497
2,000
1,048,576
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.
['import sys\ninput = sys.stdin.readline\n\nclass BaseXor:\n def __init__(self):\n self.size = 0\n self.base = []\n \n def base_calculate(self, x, b):\n return min(x, x ^ b)\n\n def make_base(self, x):\n for b in self.base:\n x = self.base_calculate(x, b)\n return x\n \n def change_base(self, x):\n for i in range(self.size):\n self.base[i] = self.base_calculate(self.base[i], x)\n \n def judge_linearly_dependent(self, x):\n x = self.make_base(x)\n res = True if x else False\n return res\n \n def add_base(self, x):\n judge = self.judge_linearly_dependent(x)\n if judge:\n self.change_base(x)\n self.base.append(x)\n self.size += 1\n return True\n return False\n\ndef solve(n, a, s):\n base = BaseXor()\n judge = False\n for i in range(n-1, -1, -1):\n x = s[i]\n if x == "0":\n base.add_base(a[i])\n else:\n judge = base.judge_linearly_dependent(a[i])\n if judge:\n break\n \n res = 1 if judge else 0\n return res\n\ndef main():\n t = int(input())\n ans = [0]*t\n for i in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n s = input()\n res = solve(n, a, s)\n ans[i] = res\n print(*ans, sep="\\n")\n \nif __name__ == "__main__":\n main()', 'import sys\ninput = sys.stdin.readline\n\nclass BaseXor:\n def __init__(self):\n self.size = 0\n self.base = []\n \n def base_calculate(self, x, b):\n return min(x, x ^ b)\n\n def make_base(self, x):\n for b in self.base:\n x = self.base_calculate(x, b)\n return x\n \n def change_base(self, x):\n for i in range(self.size):\n self.base[i] = self.base_calculate(self.base[i], x)\n \n def judge_linearly_dependent(self, x, value=False):\n x = self.make_base(x)\n res = True if x else False\n res = (res, x) if value else res\n return res\n \n def add_base(self, x):\n judge, x = self.judge_linearly_dependent(x, value=True)\n if judge:\n self.change_base(x)\n self.base.append(x)\n self.size += 1\n return True\n return False\n\ndef solve(n, a, s):\n base = BaseXor()\n judge = False\n for i in range(n-1, -1, -1):\n x = s[i]\n if x == "0":\n base.add_base(a[i])\n else:\n judge = base.judge_linearly_dependent(a[i])\n if judge:\n break\n \n res = 1 if judge else 0\n return res\n\ndef main():\n t = int(input())\n ans = [0]*t\n for i in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n s = input()\n res = solve(n, a, s)\n ans[i] = res\n print(*ans, sep="\\n")\n \nif __name__ == "__main__":\n main()\n\n']
['Wrong Answer', 'Accepted']
['s183699829', 's163258432']
[9136.0, 9028.0]
[106.0, 197.0]
[1415, 1486]
p02651
u093041722
2,000
1,048,576
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.
["T = int(input())\nfor i in range(T):\n N = int(input())\n A = list(map(int, input().split()))\n S = input()\n base = set([0])\n for i in range(1,N+1):\n temp = A[-i]\n for x in base:\n temp = min(temp,temp^x)\n if temp != 0:\n if S[-i] == '1':\n print('1')\n break\n else:\n base.add(temp)\n else:\n print('0')", "T = int(input())\nfor i in range(T):\n N = int(input())\n A = list(map(int, input().split()))\n S = input()\n base = set()\n for i in range(1,N+1):\n temp = A[-i]\n for x in base:\n temp = min(temp,temp^x)\n if temp != 0:\n if S[-i] == '1':\n print('1')\n break\n else:\n base.add(temp)\n else:\n print('0')", "T = int(input())\nfor i in range(T):\n N = int(input())\n A = list(map(int, input().split()))\n S = input()\n base = []\n for i in range(1,N+1):\n temp = A[-i]\n for x in base:\n temp = min(temp,temp^x)\n if temp != 0:\n if S[-i] == '1':\n print('1')\n break\n else:\n base.append(temp)\n else:\n print('0')"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s372903130', 's759527124', 's037735129']
[9152.0, 8980.0, 9160.0]
[61.0, 59.0, 150.0]
[417, 414, 414]
p02651
u193582576
2,000
1,048,576
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.
['def solve():\n base = []\n for a, s in zip(A[::-1], S[::-1]):\n x = a\n for y in base:\n x = min(x, x ^ y)\n if s == "0":\n if x:\n base.append(x)\n else:\n if x:\n return 1\n return 0\n\n\nt = int(input())\nfor i in range(t):\n n = int(input())\n *A, = map(int, input().split())\n S = input()\n print(\'-\'*32)\n', 'def solve():\n base = []\n for a, s in zip(A[::-1], S[::-1]):\n #print(f\'a: {a}, s: {s}\')\n #for i, y in enumerate(base):\n # print(\'base{:d} {:3d}: {:05b}\'.format(i, y, y))\n x = a\n for y in sorted(base, reverse=True):\n x = min(x, x ^ y)\n if x:\n if s == "0":\n base.append(x)\n else:\n return 1\n return 0\n\n\nt = int(input())\nfor _ in range(t):\n n = int(input())\n *A, = map(int, input().split())\n S = input()\n #print(f\'A: {A}, S: {S}\')\n print(solve())\n #print(\'-\'*32)\n']
['Wrong Answer', 'Accepted']
['s830971569', 's998080858']
[9068.0, 9100.0]
[22.0, 135.0]
[402, 593]
p02651
u206890818
2,000
1,048,576
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.
['import numpy as np\nimport math\nimport collections\n\nT = int(input())\nfor i in range(T):\n x = 0\n L0 = [0]\n L1 = [0]\n #print("x:", x)\n N = int(input())\n A = list(map(int, input().split()))\n S = input()\n if S.count(\'0\') < N / 2:\n for i, s in enumerate(S):\n if s == "0":\n for l0 in L0:\n tmp = l0 ^ A[i]\n if tmp not in L0:\n L0.append(tmp)\n for i, s in enumerate(S):\n if s == "1":\n for l1 in L1:\n tmp = l1 ^ A[i]\n if tmp not in L1:\n L1.append(tmp)\n if set(L0) <= set(L1):\n print(0)\n break\n else:\n for i, s in enumerate(S):\n if s == "1":\n for l1 in L1:\n tmp = l1 ^ A[i]\n if tmp not in L1:\n L1.append(tmp)\n for i, s in enumerate(S):\n if s == "0":\n for l0 in L0:\n tmp = l0 ^ A[i]\n if tmp not in L0:\n L0.append(tmp)\n if not set(L0) <= set(L1):\n print(1)\n break\n\n if set(L0) <= set(L1):\n print(0)\n else:\n print(1)\n', 'import numpy as np\nimport math\nimport collections\n\nT = int(input())\nfor i in range(T):\n x = 0\n L0 = [0]\n ans = 0\n N = int(input())\n A = list(map(int, input().split()))\n S = input()\n for i, s in enumerate(reversed(S)):\n tmp = A[N - 1 - i]\n for l0 in L0:\n if tmp ^ l0 < tmp:\n tmp = tmp ^ l0\n if tmp > 0:\n if s == "1":\n ans = 1\n break\n L0.append(tmp)\n print(ans)\n']
['Wrong Answer', 'Accepted']
['s028009579', 's400807234']
[27480.0, 27036.0]
[2206.0, 170.0]
[1307, 483]
p02651
u227082700
2,000
1,048,576
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.
['for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n s=input()\n b=[]\n ans=0\n for i in range(n-1,-1,-1):\n for j in b:\n a[i]=min(a[i],a[i]^j)\n if a[i]!=0:\n if s[i]=="0":\n b.append(a[i])\n else:\n ans=1\n print(ans,a)', 'for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n s=input()\n b=[]\n ans=0\n for i in range(n-1,-1,-1):\n for j in b:\n a[i]=min(a[i],a[i]^j)\n if a[i]!=0:\n if s[i]=="0":\n b.append(a[i])\n else:\n ans=1\n print(ans)']
['Wrong Answer', 'Accepted']
['s918560156', 's555736206']
[9036.0, 8824.0]
[321.0, 321.0]
[281, 279]
p02651
u761320129
2,000
1,048,576
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.
['3\n2\n1 2\n10\n2\n1 1\n10\n6\n2 3 4 5 6 7\n111000', "def gauss_jordan(bs):\n rank = 0\n pivot_cols = []\n for col in reversed(range(61)):\n pivot = -1\n for i,row in enumerate(bs[rank:]):\n if row&(1<<col):\n pivot = rank+i\n break\n if pivot < 0: continue\n pivot_cols.append(col)\n bs[pivot],bs[rank] = bs[rank],bs[pivot]\n for i,row in enumerate(bs):\n if i != rank and row&(1<<col):\n bs[i] ^= bs[rank]\n rank += 1\n return bs\n\ndef solve():\n N = int(input())\n A = list(map(int,input().split()))\n S = input()\n bs = []\n for a,s in zip(A[::-1],S[::-1]):\n x = a\n for b in bs:\n x = min(x, x^b)\n if x:\n if s=='0':\n bs.append(x)\n bs = gauss_jordan(bs)\n else:\n return 1\n return 0\n\nT = int(input())\nfor _ in range(T):\n print(solve())"]
['Runtime Error', 'Accepted']
['s950438521', 's672796315']
[8776.0, 9164.0]
[22.0, 646.0]
[40, 907]
p02651
u989345508
2,000
1,048,576
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.
['from random import randint\nt=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n s=input()\n if s[-1]=="1":\n print(1)\n continue\n print(randint(0,1))', 'I=input\nn=int\nfor i in range(n(input())):\n I();t=[];x=0\n for i,j in zip(map(n,I().split()[::-1]),I()[::-1]):\n [i^=k*(i^k<i)for k in t];j=n(j);t+=[i*(j^1)];x|=(i>0)&j\n print(x)', 't=int(input())\nfor _ in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n s=input()\n b=[]\n for i in range(n)[::-1]:\n for e in b:\n a[i]=min(a[i],a[i]^e)\n if a[i]:\n if s[i]=="0":\n b+=a[i]\n else:\n print(1)\n break\n else:\n print(0)', 'I=input\nn=int\nfor i in range(n(input())):\n I();t=[];x=0\n for i,j in zip(map(n,I().split()[::-1]),I()[::-1]):\n for k in t:i^=k*(i^k<i)\n t.append(i*(j:=n(j)^1));x|=(i>0)&j\n print(x)', 'I=input\nn=int\nfor i in range(n(input())):\n I();t=[];x=0\n for i,j in zip(map(n,I().split()[::-1]),I()[::-1]):\n [i:=(i^k*(i^k<i))for k in t];j=n(j);t+=[i*(j^1)];x|=(i>0)&j\n print(x)']
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s182238611', 's217652924', 's434162955', 's766964753', 's593690354']
[9564.0, 8860.0, 9036.0, 9068.0, 9064.0]
[27.0, 20.0, 18.0, 392.0, 363.0]
[207, 181, 354, 188, 185]
p02652
u102461423
2,000
1,048,576
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'.
["import sys\nimport numpy as np\nfrom numba import njit\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\n@njit('(i4[::1],i4[::1])', cache=True)\ndef f(S, T):\n m, x, M = 0, 0, 0\n for i in range(len(S)):\n if S[i] == -1:\n x -= 1\n elif S[i] == 1:\n x += 1\n else:\n if x - 1 + T[i] >= m:\n x -= 1\n else:\n x += 1\n m = min(m, x)\n M = max(M, x)\n return M - m\n\nS = np.array(list(read().rstrip().decode()), 'U1')\n\nSi = np.zeros(len(S), np.int32)\nSi[S == '0'] = -1\nSi[S == '1'] = 1\nS = Si\n\nT = S.copy()\nT[S == 0] = 1\nT = np.cumsum(T)\nT = np.minimum.accumulate(T[::-1])[::-1] - T\nprint(f(S, T))", "import sys\nimport numpy as np\nfrom numba import njit\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\n@njit('(i8[::1],i8)', cache=True)\ndef test(S, A):\n def f(L, R):\n if L > R:\n return False\n for x in S:\n if x == 1:\n L, R = L + 1, R + 1\n if R > A:\n R -= 2\n elif x == -1:\n L, R = L - 1, R - 1\n if L < 0:\n L += 2\n else:\n L -= 1\n R += 1\n if L < 0:\n L += 2\n if R > A:\n R -= 2\n if L > R:\n return False\n return True\n\n for parity in (0, 1):\n L, R = 0, A\n if parity == 0:\n R -= A & 1\n else:\n L = 1\n R -= 1 - (A & 1)\n if f(L, R):\n return True\n return False\n\nS = np.array(list(read().rstrip().decode()), 'U1')\nSi = np.zeros(len(S), np.int64)\nSi[S == '0'] = -1\nSi[S == '1'] = 1\nS = Si\n\nlow = 0 \nhigh = len(S) + 10 \nwhile low + 1 < high:\n x = (low + high) // 2\n if test(S, x):\n high = x\n else:\n low = x\n\nprint(high)"]
['Runtime Error', 'Accepted']
['s614234858', 's407506842']
[137776.0, 118968.0]
[595.0, 884.0]
[751, 1282]
p02652
u539692012
2,000
1,048,576
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'.
["from numba import njit\ns = input()\n\n@njit\ndef test(c):\n # current point can be seen as xth smallest val, where x can be any value in [a, b] (subset of [0, c])\n # a <= b\n a, b = 0, c\n ok = True\n discrete = False # when True x = a, a+2, ..., b-2, b\n for si in s:\n if si == '1':\n if a == b == c:\n return False\n a += 1\n b += 1\n if b > c:\n b = c - 1 if discrete else c\n elif si == '0':\n if a == b == 0:\n return False\n a -= 1\n b -= 1\n if a < 0:\n a = 1 if discrete else 0\n else:\n if a == b == 0:\n a = b = 1\n elif a == b == c:\n a = b = c - 1\n elif a == b:\n discrete = True\n a -= 1\n b += 1\n else:\n a -= 1\n b += 1\n if a < 0:\n a = 1 if discrete else 0\n if b > c:\n b = c - 1 if discrete else c\n return True\n\n\nl, r = 0, len(s)\nwhile r - l > 1:\n c = (l + r) // 2\n if test(c):\n r = c\n else:\n l = c\nprint(r)\n", "from numba import njit\nimport numpy as np\ns = np.array(list(map(lambda x: -1 if x == '?' else int(x), input())))\n@njit\ndef test(c):\n # current point can be seen as xth smallest val, where x can be any value in [a, b] (subset of [0, c])\n # a <= b\n a, b = 0, c\n ok = True\n discrete = False # when True x = a, a+2, ..., b-2, b\n for si in s:\n if si == 1:\n if a == b == c:\n return False\n a += 1\n b += 1\n if b > c:\n b = c - 1 if discrete else c\n elif si == 0:\n if a == b == 0:\n return False\n a -= 1\n b -= 1\n if a < 0:\n a = 1 if discrete else 0\n else:\n if a == b == 0:\n a = b = 1\n elif a == b == c:\n a = b = c - 1\n elif a == b:\n discrete = True\n a -= 1\n b += 1\n else:\n a -= 1\n b += 1\n if a < 0:\n a = 1 if discrete else 0\n if b > c:\n b = c - 1 if discrete else c\n return True\n\nl, r = 0, s.size\nwhile r - l > 1:\n c = (l + r) // 2\n if test(c):\n r = c\n else:\n l = c\nprint(r)\n"]
['Time Limit Exceeded', 'Accepted']
['s141324228', 's590555997']
[127144.0, 117868.0]
[2208.0, 964.0]
[1222, 1294]
p02658
u000022466
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['import sys\n\nN = int(input())\nA = list(map(int,input().split())\n\nfor a in A:\n\tif a == 0:\n\t\tprint("0")\n\t\tsys.exit()\n\nnum = 1\nfor a in A:\n\tnum *= a\n\tif num > 1000000000000000000:\n\t\tprint(-1)\n\t\tsys.exit()\n\nprint(num)\n\t\t', 'import heapq\nfrom collections import deque\nfrom enum import Enum\nimport sys\nimport math\nfrom _heapq import heappush, heappop\nimport copy\nfrom test.support import _MemoryWatchdog\n\nBIG_NUM = 2000000000\nHUGE_NUM = 99999999999999999\nMOD = 1000000007\nEPS = 0.000000001\nsys.setrecursionlimit(100000)\n\n\nN = int(input())\nA = list(map(int,input().split()))\n\n\nfor a in A:\n if a == 0:\n print("0")\n sys.exit()\n\nnum = 1\nfor a in A:\n num *= a\n if num > 1000000000000000000:\n print(-1)\n sys.exit()\n\nprint(num)\n']
['Runtime Error', 'Accepted']
['s907638803', 's445311675']
[9016.0, 33428.0]
[25.0, 119.0]
[215, 532]
p02658
u000037600
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['input()\na=1\nb=map(int,input().split())\nfor i in b:\n a*=i\nif a>10^18:\n a=-1\nprint(a)', 'input()\na=1\nb=map(int,inpit().split())\nfor i in b:\n a*=i\nif a>10^18:\n a=-1\nprint(a)', 'n=int(input())\nl=list(map(int,input().split()))\nif 0 in l:\n print(0)\nelse:\n a=1\n for i in l:\n a=a*i\n if a>10**18:\n print(-1)\n exit()\n print(a)\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s348189311', 's497955763', 's226665622']
[19200.0, 9032.0, 21488.0]
[2206.0, 27.0, 61.0]
[85, 85, 163]
p02658
u000085263
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['N=input()\nA=input()\na=A.split()\nc=1\nfor i in a:\n c=c*int(i)\nif c<(10**8):\n print(c)\nelse:\n c=-1\n print(c)', 'N = int(input())\nA = list(map(int,input().split()))\nA = 1\nfor i in A:\n A *= i\n if A== 0:\n break\nif ans > 10**18:\n print(-1)\nelse:\n print(ans)', 'N=input()\nA=input()\na=A.split()\nc=1\nfor i in a:\n c=c*int(i)\nif c<(10**8):\n print(c)\nelse:\n c=-1\n print(c)', 'def mul2():\n n = int(input())\n a = list(map(int, input().split()))\n \n if 0 in a:\n return 0\n \n ans = 1\n for i in a:\n ans *= i\n if ans > 1000000000000000000:\n return -1\n \n return ans \nmul2()', 'def mul2():\n n = int(input())\n a = list(map(int, input().split()))\n \n if 0 in a:\n return 0\n ans = 1\n for i in a:\n ans *= i\n if ans > 1000000000000000000:\n return -1\n \n return ans \nprint(mul2())']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s290310109', 's384479164', 's573523987', 's586365124', 's938109108']
[20420.0, 21476.0, 20548.0, 21632.0, 21660.0]
[2206.0, 53.0, 2206.0, 57.0, 56.0]
[109, 160, 109, 251, 253]
p02658
u000513658
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['n = int(input())\n\na = set(map(int, input().split()))\n\nresult = 1\nif 0 in a:\n result = 0\nelse:\n for i in a:\n result = result * i\n if result > 10**18:\n result = -1\n break\n \n\nprint(result)', 'n = int(input())\n\na = list(map(int, input().split()))\n\nresult = 1\nif 0 in a:\n result = 0\nelse:\n for i in a:\n result = result * i\n if result > 10**18:\n result = -1\n break\n \n\nprint(result)']
['Wrong Answer', 'Accepted']
['s040833829', 's363912140']
[26868.0, 21648.0]
[65.0, 47.0]
[234, 235]
p02658
u001490106
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['N = int(input())\nA = list(map(int, input().split()))\n\nsum = 1\nA.sort()\nfor i in A:\n sum = sum*i\n if sum >= pow(10,18):\n sum = -1\n break\nprint(sum)', 'N = int(input())\nA = list(map(int, input().split()))\n\nsum = 1\nA.sort()\nfor i in A:\n sum = sum*i\n if sum > pow(10,18):\n sum = -1\n break\nprint(sum)']
['Wrong Answer', 'Accepted']
['s477417841', 's866906067']
[21704.0, 21704.0]
[113.0, 114.0]
[166, 165]
p02658
u003855259
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['\nN=int(input(""))\n\nar=[]\ntotal=1\nbig=False\n\nar = list(map(int, input().strip().split(\' \')))\n\nA=len(ar)\n \nwhile big == False:\n for i in range (0,A):\n total=ar[i]*total\n if total>(10^18):\n big=True\n break\n\nif big == False:\n print(total)\n\nif total==0:\n big = False\n print("0")\n\nif big == True:\n print("-1")', '\nN=int(input(""))\n\nar=[]\ntotal=1\nbig=False\n\nar = list(map(int, input().strip().split(\' \')))\n\nA=len(ar)\n \nfor i in range (0,A):\n total=ar[i]*total\n if total>(10^18):\n big=True\n\nif big == False:\n print(total)\n\nif total==0:\n big = False\n print("0")\n\nif big == True:\n print("-1")', 'N=int(input(""))\n\nar=[]\ntotal=1\nbig=False\nlion = False\nA=N-1\nar = list(map(int, input().strip().split(\' \')))\n\nif 0 in ar:\n print("0")\n big=True\n lion=False\n \nwhile big == False and lion == False:\n for i in range (0,N):\n total=ar[i]*total\n if i == A:\n lion = True\n if total>(1000000000000000000):\n big=True\n lion=True\n break\n\nif big == False and lion == True:\n print(total)\n\nif big == True and lion == True:\n print("-1")']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s792091381', 's924002176', 's350904428']
[21640.0, 21784.0, 21648.0]
[2206.0, 2206.0, 55.0]
[389, 321, 555]
p02658
u004482945
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['n = int(input())\na = list(map(int, input().split()))\nans = 1\nfor i in a:\n ans *= i\n if ans >= 10**18:\n ans = -1\n break\nif 0 in a:\n ans = 0\nprint(ans)', 'n = int(input())\na = list(map(int, input().split()))\nans = 1\nfor i in a:\n ans *= i\nif ans >= 10**18:\n ans = -1\nprint(ans)', 'n = int(input())\na = list(map(int, input().split()))\nans = 1\nfor i in a:\n ans *= i\n if ans > 10**18:\n ans = -1\n break\nif 0 in a:\n ans = 0\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s297304723', 's928603015', 's152326241']
[21656.0, 21784.0, 21700.0]
[54.0, 2206.0, 53.0]
[158, 123, 157]
p02658
u007637377
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['#include <bits/stdc++.h>\nusing namespace std;\n\n#define REP(i,b) FOR(i,0,b)\n\n#define RREP(i,a) RFOR(i,a,0)\n\n\n#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)\n#define ALL(x) (x).begin(), (x).end()\n#define SORT(x) sort(ALL(x))\n#define MIN_ELEMENT(x) min_element(ALL(x))\n#define MAX_ELEMENT(x) max_element(ALL(x))\n#define COUNT(x,num) count(ALL(x), num)\n#define MEMSET(x,val) memset(x, val, sizeof(x))\n#define MAX(a,b) a = max(a,b)\n#define MIN(a,b) a = min(a,b)\n\nvoid YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}\nvoid Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}\nvoid yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}\n\n\n#define nextline putchar(\'\\n\')\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef vector<int> VI;\ntypedef vector<vector<int>> VVI;\ntypedef vector<ll> VLL;\ntypedef vector<vector<ll>> VVLL;\nconst int INF = 1e7;\nconst ll MOD = 1e9 + 7;\nconst double pi = 3.141592653589793;\n\nint main()\n{\n int n;\n cin>>n;\n ll ans = 1ll;\n\n bool flag = true;\n REP(i,n) {\n ll nans = ans;\n ll a;\n cin>>a;\n nans *= a;\n\n if (nans > (ll)1e18 || nans < ans) {\n flag = false;\n }\n ans = nans;\n }\n cout<<(flag || ans == 0 ? ans : -1)<<endl;\n\n return 0;\n}\n', 'from sys import stdin\ninput = stdin.readline\n\nn = int(input())\na = list(map(int, input().split()))\nans = 1\nflag = True\n\nfor ta in a:\n ans *= ta\n if (ans > 10 ** 18):\n flag = False\n ans = 1\n\nif (flag or ans == 0):\n print(ans)\nelse:\n print(-1)\n']
['Runtime Error', 'Accepted']
['s880780311', 's026272788']
[9012.0, 21600.0]
[23.0, 68.0]
[1576, 268]
p02658
u008323723
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['n = int(input())\na = map(int,input().split())\nb =1\n\nfor i in range(n):\n b *= a[i]\n\nif b >= 10**18:\n print(-1)\nelse:\n print(b)', 'n = int(input())\na = list(map(int,input().split()))\nb =1\n\nfor i in range(n):\n b *= a[i]\n if b>=10**18:\n b=-1\n break\n else:\n continue\nprint(b)', 'n = int(input())\na = list(map(int,input().split()))\nb =1\n\nfor i in range(n):\n b *= a[i]\n\nif b >= 10**18:\n print(-1)\nelse:\n print(b)', 'n = int(input())\na = list(map(int,input().split()))\nb =1\n\nif 0 in a:\n b=0\nfor i in range(n):\n b *= a[i]\n if b>10**18:\n b=-1\n break\n else:\n continue\nprint(b)\n']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s062674307', 's199717729', 's366512280', 's610604227']
[19352.0, 21564.0, 21632.0, 21648.0]
[36.0, 49.0, 2206.0, 60.0]
[128, 153, 134, 170]
p02658
u008582165
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['n = int(input());\nans = 1;\nfor i in range(n):\n a = int(input())\n ans*=a\nif ans>=1000000000000000001:\n print(-1)\nelse:\n print(ans)', 'n = int(input());\nans = 1;\nlis = list(map(int,input().split()))\nflag = False\nflag2 = False\nfor i in range(n):\n if lis[i]==0:\n flag = True\n if ans*lis[i]>=1000000000000000001:\n flag2 = True\n else:\n ans *= lis[i]\n\nif flag:\n print(0)\nelif flag2:\n print(-1)\nelse:\n print(ans)']
['Runtime Error', 'Accepted']
['s075526440', 's401788390']
[12772.0, 21632.0]
[37.0, 72.0]
[141, 310]
p02658
u010379708
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
["n=int(input())\nl=list(map(int, input().split(' ')))\nans=1\nfor i in l:\n ans*=i\n if ans>10**18:\n print(-1)\n break\nif not ans>10**18:\n print(ans)\n", "n=int(input())\nl=list(map(int, input().split(' ')))\nans=1\nfor i in l:\n ans*=i\n if ans>10**18:\n print(-1)\n break\nif not ans>10**18:\n print(ans)\n", "n=int(input())\nl=list(map(int, input().split(' ')))\nans=1\nif 0 in l:\n print(0)\nelse:\n for i in l:\n ans*=i\n if ans>10**18:\n print(-1)\n break\n if not ans>10**18:\n print(ans)\n"]
['Wrong Answer', 'Runtime Error', 'Accepted']
['s506220499', 's860907323', 's634154138']
[21636.0, 9028.0, 21588.0]
[47.0, 22.0, 51.0]
[162, 158, 224]
p02658
u011277545
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['import numpy as np\nN=int(input())\nA=list(map(int, input().split()))\nA_N=np.array(A,dtype=\'int64\')\n\nANS=np.prod(A_N)\n\nif ANS>10**18:\n print(""-1")\nelse:\n print(ANS)', 'import numpy as np\nN=int(input())\nA=list(map(int, input().split()))\nA_N=np.array(A)\n\nANS=np.prod(A_N)\n\nif ANS>=10**18:\n print(-1)\nelse:\n print(ANS)', 'from operator import mul\nfrom functools import reduce\n\nN=int(input())\nA=list(map(int, input().split()))\nreduce(mul, A)\n\nif ANS>10**18:\n print(-1)\nelse:\n print(ANS)', 'import collections\nN=int(input())\nA=list(map(int, input().split()))\nA_dict=collections.Counter(A)\nASN=0\nfor i in A_dict.keys():\n ANS+=i**A_dict[i]\n\nif ANS>10**18:\n print(-1)\nelse:\n print(ANS)', 'import collections\nimport sys\n\nN=int(input())\nA=list(map(int, input().split()))\nA_dict=collections.Counter(A)\nANS=1\nif 0 in A_dict.keys():\n print("0")\n sys.exit()\n \nfor key, value in A_dict.items():\n ANS=ANS*(key**value)\n if ANS>10**18:\n print(-1)\n sys.exit()\n\nprint(ANS)\n']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s020336904', 's474947684', 's520877749', 's884821950', 's038700995']
[8968.0, 40332.0, 22992.0, 24384.0, 24112.0]
[22.0, 142.0, 2206.0, 67.0, 68.0]
[169, 153, 169, 200, 301]
p02658
u011387432
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['n=int(input())\nmul=1\nlimit=1000000000000000000\nfor i in range (n):\n x=int(input())\n mul*=x\nif(mul>limit):\n print(-1)\nelse:\n print(mul)', 'n=int(input())\nmul=1\nlimit=1000000000000000000\nx=input().split()\nfor i in range (n):\n p=int(x[i])\n if(p==0):\n mul=0\n break\nif(mul==0):\n print(mul)\nelse:\n for i in range (n):\n p=int(x[i])\n mul*=p\n if(mul>limit):\n break\n if(mul>limit):\n print(-1)\n else:\n print(mul)']
['Runtime Error', 'Accepted']
['s937392317', 's355566231']
[12752.0, 19516.0]
[35.0, 72.0]
[138, 337]
p02658
u011453891
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['n = int(input())\nvalues =list(map(int, input().split()))\na=1\n \nfor i in range(n):\n a=a*values[i]\n \nimport math\nif math.log10(a) < 18:\n print(a)\nelse:\n print(-1)', 'n = int(input())\nvalues =list(map(int, input().split()))\na=1\nt = 10**18\nfor i in range(n):\n if values[i] == 0:\n a = 0\n break\n if a > t:\n continue\n else:\n a=a*values[i]\n \nif a <= t:\n print(a)\nelse:\n print(-1)']
['Runtime Error', 'Accepted']
['s892704926', 's300270439']
[21648.0, 21580.0]
[2206.0, 60.0]
[164, 224]
p02658
u012820749
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['a = ()\nn = input()\na = map(int, input().split())\n\nans = a[0]\na2 = a[1:]\nfor i in a2:\n ans = ans * i\n\nif ans > 10e+18:\n ans = -1\n\nprint(ans)', 'a = ()\nn = input()\na = map(int, input().split())\n\nprint(sum(a))', 'def main():\n n = input()\n a = tuple(map(int, input().split()))\n\n if 0 in a:\n print(0)\n return\n \n ans = a[0]\n a2 = a[1:]\n for i in a2:\n ans = ans * i\n if ans > 1000000000000000000:\n print(-1)\n return\n\n print(ans)\n\nmain()']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s299623107', 's957494817', 's059170303']
[19200.0, 19124.0, 21864.0]
[34.0, 46.0, 51.0]
[141, 63, 249]
p02658
u013061784
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['N = int(input())\na = [int(i) for i in input().strip.split(" ")]\nres=1\nxx=1**18\nfor i in a:\n res*=i\nif res>xx:\n print(-1)\nelse:\n print(res)', 'N = int(input())\na = [int(i) for i in input().split(" ")]\nres=1\nxx=1**18\nfor i in a:\n res*=i\nif res>xx:\n print(-1)\nelse:\n print(res)', 'N = int(input())\na = [int(i) for i in input().split(" ")]\nres=1\nxx=10**18\nf=0\na.sort()\nfor i in a:\n res*=i\n if res>xx:\n f=1\n print(-1)\n break\n\nif f==0:\n print(res)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s202194944', 's311725812', 's619557550']
[12780.0, 21640.0, 21652.0]
[24.0, 2206.0, 92.0]
[147, 141, 193]
p02658
u013864607
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['N = int(input())\nA = list(map(int, input().split()))\n\ntmp = 1\nfor num in A:\n tmp *= num\n if tmp <= 1e18:\n break\nif tmp <= 1e18:\n print(tmp)\nelse:\n print("-1")\n', 'N = int(input())\nA = list(map(int, input().split()))\n \ntmp = 1\nfor num in A:\n tmp *= num\n if tmp > 1e18:\n break\n \nif tmp <= 1e18:\n print(tmp)\nelif 0 in A:\n print(0)\nelse:\n print(-1)']
['Wrong Answer', 'Accepted']
['s242696774', 's596443276']
[21572.0, 21644.0]
[51.0, 51.0]
[176, 202]
p02658
u014139588
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['print(-1)', 'print(0)', 'n = int(input())\na = list(map(int,input().split()))\na.sort()\nans = 1\nif a[0] == 0:\n print(0)\nelse:\n for i in range(len(a)):\n ans *= a[i]\n if ans > 10**18:\n print("-1")\n exit()\n elif i == len(a)-1:\n print(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s102724649', 's447823927', 's886860770']
[9084.0, 9144.0, 21632.0]
[23.0, 23.0, 89.0]
[9, 8, 234]
p02658
u014554381
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['def main ():\nN = int(input())\nA = list(map(int,input(). split ()))\nif 0 in A:\nprint(0)\nreturn\nprod = 1\nfor a in A:\nprod *= a\nif prod > 1000000000000000000:\nprint(-1)\nreturn\nprint(prod)\nmain ()\n', 'n,a = map(int.input().split())\nb = list[]\nfor n:\n b.append(a)\n\nplint(a**n)\n', 'n,a = map(int.input().split())\nb = list[]\nfor n:\n b.append(a)\n\nc = a**n\nif c > 10**18:\n c = -1\n print(c)\n', 'def main ():\n N = int(input())\n A = list(map(int,input(). split ()))\n \n if 0 in A:\n print(0)\n return\n prod = 1\n for a in A:\n prod *= a\n if prod > 1000000000000000000:\n print(-1)\n return\n print(prod)\nmain ()\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s145661999', 's670557452', 's987067244', 's335477666']
[9004.0, 9044.0, 8984.0, 21664.0]
[26.0, 22.0, 25.0, 49.0]
[193, 76, 108, 236]
p02658
u015593272
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['N = int(input())\nA_s = list(map(int, input().split()))\n\nseki = 1\n\nif (A_s.count(0) > 0):\n print(0)\n exit()\n\nfor i in range(N):\n seki *= A_s[i]\n print(seki)\n \n if (seki > 10 ** 18):\n print(-1)\n exit()\n\nprint(seki)', 'N = int(input())\nA_s = list(map(int, input().split()))\n\nseki = 1\n\nif (A_s.count(0) > 0):\n print(0)\n exit()\n\nfor i in range(N):\n seki *= A_s[i]\n \n if (seki > 10 ** 18):\n print(-1)\n exit()\n\nprint(seki)']
['Wrong Answer', 'Accepted']
['s808867767', 's061546233']
[21628.0, 21656.0]
[80.0, 49.0]
[244, 228]
p02658
u015647294
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['N = int(input())\nA = list(map(int, input().split()))\nans = A[0]\nif A.count(0) == 0:\n ans = 0\nelse:\n for i in range(1,N):\n ans = ans * A[i]\n if ans >= 10 ** 18:\n ans = -1\n break\nprint(ans)', 'N = int(input())\nA = list(map(int, input().split()))\nans = A[0]\nfor i in range(1,N):\n ans = ans * A[i]\n if ans >= 10 ** 18:\n ans = -1\n break\nprint(ans)', 'N = int(input())\nA = list(map(int, input().split()))\nans = A[0]\nif A.count(0) != 0:\n ans = 0\nelse:\n for i in range(1,N):\n ans = ans * A[i]\n if ans >= 10 ** 18:\n ans = -1\n break\nprint(ans)', 'N = int(input())\nA = list(map(int, input().split()))\nans = A[0]\nif A.count(0) != 0:\n ans = 0\nelse:\n for i in range(1,N):\n ans = ans * A[i]\n if ans > 10 ** 18:\n ans = -1\n break\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s274480143', 's415311106', 's437887015', 's634156311']
[21572.0, 21696.0, 21700.0, 21644.0]
[60.0, 57.0, 60.0, 59.0]
[229, 171, 229, 228]
p02658
u016336953
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['n = int(input())\nc = list(map(int, input().split()))\nans=1\nmax =10**18\nfor i in range(n):\n if ans< max:\n ans=ans*c[i]\n if ans >= max:\n ans =-1\n break\n else:\n ans = -1\n break\nprint(ans)', 'n = int(input())\nc = list(map(int, input().split()))\nans=1\nmax =10**18\n\nif 0 in c:\n ans =0\nelse:\n for i in range(n):\n if ans< max:\n ans=ans*c[i]\n if ans >= max:\n ans =-1\n break\n else:\n ans = -1\n break\nprint(ans)', 'n = int(input())\nc = list(map(int, input().split()))\nans=1\nmax =10**18\n\nif 0 in c:\n ans =0\nelse:\n for i in range(n):\n if ans< max:\n ans=ans*c[i]\n if ans > max:\n ans =-1\n break\n else:\n ans = -1\n break\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s524611536', 's935177638', 's188371371']
[21584.0, 21648.0, 21780.0]
[51.0, 55.0, 52.0]
[240, 305, 304]
p02658
u017624958
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['N = input()\nA = list(map(int, input().split()))\n\nanswer = 1\nfor Ai in A:\n answer *= Ai\n\nif answer >= 10 ** 18:\n answer = -1\n\nprint(answer)\n', 'N = input()\nA = list(map(int, input().split()))\n\nhaz_zero = 0 in A\nif haz_zero:\n print(0)\n exit()\n\nanswer = 1\nfor Ai in A:\n answer *= Ai\n if answer > 10 ** 18:\n answer = -1\n break\n\nprint(answer)\n']
['Wrong Answer', 'Accepted']
['s721734606', 's492199609']
[21584.0, 21768.0]
[2206.0, 47.0]
[145, 221]
p02658
u018168283
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['from collections import deque\nimport math\nn=int(input())\na=deque()\na=list(map(int,input().split()))\ns=1\ne=0\nf=0\nfor i in range(n):\n l=a.pop()\n if l == 0:\n s=0\n break\n else:\n s=s*l\n f+=math.log10(s)\n if s>=18:\n e=1\n break\n \nif e!=0:\n print(-1)\nelse:\n print(s)', 'from collections import deque\nn=int(input())\na=deque()\na=list(map(int,input().split()))\ns=0\nif a.count(0) == 0:\n s=1\n for i in range(n):\n l=a.pop()\n s=s*l \n \n if len(str(s)) >= 19:\n if s == 10**18 and i==n-1:\n break\n s=-1\n break\n\n \nprint(s)']
['Wrong Answer', 'Accepted']
['s861931232', 's524196839']
[22676.0, 22508.0]
[61.0, 74.0]
[288, 282]
p02658
u018679195
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['\n#user input A in list\n#function of multiplication of all item in list\n#time complexity is O(n)\nN = int(input())\nA = [int(x) for x in input().split()[:N]]\n\ndef multiplyList(list1):\n b = 1\n for i in list1:\n b = b*i\n return b\n\nif multiplyList(A) < 1*10**18:\n print(multiplyList(A))\nelse:\n print(-1)\n', 'a=int(input())\ntem = 1\n\nif a != 0:\n b=input().split(" ")\n for i in range(a):\n tem = tem * int(b[i])\n if len(tem)> 10**18:\n tem = -1\nprint(tem)', '# we collect the input A1 upto An.\n# limit cannot exceed 10**18\n# if N = 0 then ans = 0\n# in N is in range then compute 1 * A[n]\nN = int(input())\nans = 1\nlimit = 10 ** 18\nlength = 0\n\nA = list(map(int, input().split()))\n\nA0 = set(A)\nif 0 in A0:\n ans = 0\nelse:\n pass\n\nfor n in range(N):\n ans = ans * A[n]\n if ans == 0:\n break\n elif ans > limit:\n length = 1\n break\n else:\n pass\n\nif length == 1:\n print(-1)\nelse:\n print(ans)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s020949917', 's717785416', 's952454189']
[21612.0, 19332.0, 21616.0]
[2206.0, 2206.0, 68.0]
[332, 165, 472]
p02658
u018771977
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['n = int(input())\na = list(map(int, input().split()))\n\nresult = 1\n\nfor ac in a:\n result *= ac\n if result >= 10 ** 18:\n print(-1)\nelse:\n\tprint(result)\n \n \n', '#! env/bin/local python3\n\nimport sys\n\nn = int(input())\na = list(map(int, input().split()))\na = sorted(a, key=lambda x: x)\n\nresult = 1\n\nfor ac in a:\n result *= ac\n if result > 10 ** 18:\n print(-1)\n sys.exit()\nelse:\n print(result)\n\n\n']
['Wrong Answer', 'Accepted']
['s738495695', 's503612943']
[21472.0, 21632.0]
[2206.0, 94.0]
[164, 254]
p02658
u018846452
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['n = int(input())\na = list(map(int, input().split()))\nans = 1\n\nfor i in range(n):\n\tans *= a[i]\n\tif ans > 10^18:\n \t\tans = -1\n break\nprint(ans)', 'n = int(input())\na = list(map(int, input().split()))\nans = 1\n\nfor i in range(n):\n\tans *= a[i]\nif ans > 10^18:\n ans = -1\nprint(ans)', 'n = int(input())\na = list(map(int, input().split()))\nans = 1\n\nfor i in range(n):\n ans *= a[i]\n if ans > 10^18:\n ans = -1\n break\nif 0 in a:\n\tans = 0\nprint(ans)', 'n = int(input())\na = list(map(int, input().split()))\nans = 1\n\nfor i in range(n):\n\tans *= a[i]\n\tif ans > 10^18:\n \t\tans = -1\n break\nprint(ans)', 'n = int(input())\na = list(map(int, input().split()))\nans = 1\n\nfor i in range(n):\n ans *= a[i]\n if ans > 10^18:\n ans = -1\n break\nprint(ans)', 'n = int(input())\na = list(map(int, input().split()))\nif 0 in a:\n\tprint(0)\n\texit(0)\nans = 1\nfor i in range(n):\n\tans *= a[i]\n\tif ans > 10**18:\n\t\tprint(-1)\n\t\texit(0)\nprint(ans)']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s012639398', 's086082579', 's104574094', 's657586645', 's985741891', 's296963269']
[8912.0, 21624.0, 21736.0, 8952.0, 21744.0, 21604.0]
[22.0, 2206.0, 63.0, 28.0, 54.0, 56.0]
[147, 131, 166, 147, 146, 173]
p02658
u019355060
2,000
1,048,576
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead.
['N=int(input())\nA=[]\nA=list(map(int,input().split()))\nL=10^18\nS=1\nfor i in range(N):\n S=S*A[i]\n if S>L:\n print("-1")\n break\nif S<=L:\n print(S)\n', 'N=int(input())\nA=[]\nA=list(map(int,input().split()))\nA.sort(reverse=True)\nL=10**18\nS=1\nif A[N-1]==0:\n print("0")\nelse:\n for i in range(N):\n S=S*A[i]\n if S>L:\n print("-1")\n break\n if S<=L:\n print(S)\n']
['Wrong Answer', 'Accepted']
['s481425849', 's905285413']
[21624.0, 21592.0]
[47.0, 76.0]
[165, 250]