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
|
---|---|---|---|---|---|---|---|---|---|---|
p03639 | u858994158 | 2,000 | 262,144 | We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. | ["input()\nxs=list(map(int, input().split()))\n\nf,t,z=0,0,0\nfor x in xs:\n if x % 4 == 0:\n f+=1\n elif x % 2 == 0:\n t += 1\n else:\n z += 1\nz += t\nprint('Yes' if z + 1 < f then 'No')\n", "input()\nxs=list(map(int, input().split()))\n\nf,t,z=0,0,0\nfor x in xs:\n if x % 4 == 0:\n f+=1\n elif x % 2 == 0:\n t += 1\n else:\n z += 1\nz += 0<t\nprint('Yes' if z + 1 < f else'No')\n", "input()\nxs=list(map(int, input().split()))\n \nf,t,z=0,0,0\nfor x in xs:\n if x % 4 == 0:\n f+=1\n elif x % 2 == 0:\n t += 1\n else:\n z += 1\nz += 0<t\nprint('Yes' if z - 2 < f else'No')"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s052437444', 's189337822', 's347569281'] | [2940.0, 14252.0, 14252.0] | [17.0, 65.0, 64.0] | [187, 188, 188] |
p03639 | u859897687 | 2,000 | 262,144 | We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. | ['n=int(input())\nm=list(map(int,input().split()))\nfor i in range(n):\n a=0\n for m[i]>1:\n m[i]//=2\n a+=1\n if a>2:\n a=2\n m[i]=a\nif m.count(2)>m.count(1):\n print("Yes")\nelse:\n print("No")', 'n=int(input())\nm=list(map(int,input().split()))\nfor i in range(n):\n a=0\n while m[i]%2==0:\n m[i]//=2\n a+=1\n if a>2:\n a=2\n m[i]=a\nif m.count(2)>=m.count(0):\n print("Yes")\nelif m.count(0)==0:\n print("Yes")\nelif m.count(1)==0 and m.count(2)>=m.count(0)-1:\n print("Yes")\nelse:\n print("No")\n'] | ['Runtime Error', 'Accepted'] | ['s147205650', 's407116213'] | [2940.0, 14252.0] | [17.0, 156.0] | [196, 302] |
p03639 | u887207211 | 2,000 | 262,144 | We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. | ['N = int(input())\n\ntwo_ad = 0\nfour_ad = 0\nother = 0\nfor _ in range(N):\n a = int(input())\n if a % 4 == 0 and a % 2 == 0:\n four_ad += 1\n elif a % 4 == 0:\n four_ad += 1\n elif a % 2 == 0:\n two_ad += 1\n else:\n other += 1\n\nif not two_ad and not four_ad:\n ans = "No"\nelif not two_ad:\n if other == four_ad + 1 or four_ad > other:\n ans = "Yes"\n else:\n ans = "No"\nelif not four_ad:\n ans = "No"\nelif not other:\n ans = "Yes"\nelif four_ad == other == two_ad:\n ans = "Yes"\nelse:\n ans = "No"\nprint(ans)', 'N = int(input())\nA = list(map(int,input().split()))\ntwo_ad = 0\nfour_ad = 0\nother = 0\nfor a in A:\n if a % 4 == 0:\n four_ad += 1\n elif a % 2 == 0:\n two_ad += 1\n else:\n other += 1\n\nans = "No"\nif four_ad >= other:\n ans = "Yes"\nelif four_ad == other - 1 and not two_ad:\n ans = "Yes"\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s909138303', 's704076638'] | [5028.0, 14252.0] | [24.0, 63.0] | [516, 302] |
p03639 | u896741788 | 2,000 | 262,144 | We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. | ['n=int(input())\nl=[0,0,0]\nfor i in list(map(int,input().split())):\n if i%2:l[0]+=1\n elif i%4:l[1]+=1\n else:l[2]+=1\n\nprint("Yes" if l[2]>=l[0]+int(1<=l[1]) else "No")\n', 'n=int(input())\nl=list(map(int,input().split()))\nodd=len([1 for i in l if i%2])\nt4=len([1 for i in l if i%4==0])\nif odd*2<=t4:print("Yes")\nelse:print("No")', 'n=int(input())\nl=list(map(int,input().split()))\nodd=len([1 for i in l if i%2])\nt4=len([1 for i in l if i%4==0])\nif odd*2+1<=t4:print("Yes")\nelse:print("No")', 'n=int(input())\nl=[0,0,0]\nfor i in list(map(int,input().split())):\n if i%2:l[0]+=1\n elif i%4:l[1]+=1\n else:l[2]+=1\n\nprint("Yes" if l[2]+1>=l[0]+int(1<=l[1]) else "No")'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s343427289', 's475463947', 's593554510', 's502530872'] | [14252.0, 15020.0, 14252.0, 14252.0] | [67.0, 56.0, 56.0, 67.0] | [168, 154, 156, 169] |
p03639 | u903005414 | 2,000 | 262,144 | We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. | ["N = int(input())\nA = list(map(int, input().split()))\n\nnum_four = 0\nnum_two = 0\nnum_odd = 0\nfor i in range(N):\n if A[i] % 4 == 0:\n num_four += 1\n elif A[i] % 2 == 0:\n num_two += 1\n else:\n num_odd += 1\n\n# print(num_four, num_two, num_odd)\n\nv = num_four * 2\nif num_two == 0:\n v += 1\nif num_two >= 2:\n v += num_two\nans = 'Yes' if v >= N else 'No'\nprint(ans)\n\n\n\n", "N = int(input())\nA = list(map(int, input().split()))\n\nnum_four = 0\nnum_two = 0\nnum_odd = 0\nfor i in range(N):\n if A[i] % 4 == 0:\n num_four += 1\n elif A[i] % 2 == 0:\n num_two += 1\n else:\n num_odd += 1\n\n# print(num_four, num_two, num_odd)\n\nif num_two != 0:\n ans = 'Yes' if num_four + 1 >= num_odd + 1 else 'No'\nelse:\n ans = 'Yes' if num_four + 1 >= num_odd else 'No'\nprint(ans)\n"] | ['Wrong Answer', 'Accepted'] | ['s192207418', 's658587121'] | [14224.0, 14224.0] | [72.0, 73.0] | [442, 412] |
p03639 | u967835038 | 2,000 | 262,144 | We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. | ["from math import ceil\nn=int(input())\nans4=0\nans2=0\nans0=0\na=list(map(int,input().split()))\nfor i in range(n):\n if a[i]%4==0:\n ans4+=1\n elif a[i]%2==0:\n ans2+=1\n else:\n ans0+=1\nif ans2>0:\n if ans0<=ans4:\n print('Yes')\n else:\n print('No')\nelse:\n if ceil((ans0+ans4)/2)>=:ans0\n print('Yes')\n else:\n print('No')\n", "from math import ceil\nn=int(input())\nans4=0\nans2=0\na=list(map(int,input().split()))\nfor i in range(n):\n if a[i]%4==0:\n ans4+=1\n elif a[i]%2==0:\n ans2+=1\n else:\n pass\nif ans2>0:\n if (n-ans2)<=ans4:\n print('Yes')\n else:\n print('No')\nelse:\n if ceil(n-ans2)>=(n-ans2-ans4):\n print('Yes')\n else:\n print('No')", "n=int(input())\nans4=0\nans2=0\na=list(map(int,input().split()))\nfor i in range(n):\n if a[i]%4==0:\n ans4+=1\n elif a[i]%2==0:\n ans2+=1\n else:\n pass\nif ans2>0:\n if n-ans2//2<=ans4:\n print('Yes')\n else:\n print('No')\nelse:\n if n/2<=ans4:\n print('Yes')\n else:\n print('No')", "n=int(input())\nans4=0\nans2=0\na=list(map(int,input().split()))\nfor i in range(n):\n if a[i]%4==0:\n ans4+=1\n elif a[i]%2==0:\n ans2+=1\n else:\n pass\nif ans2>0:\n if (n-ans2)+1//2<=ans4:\n print('Yes')\n else:\n print('No')\nelse:\n if n/2<=ans4:\n print('Yes')\n else:\n print('No')", "n=int(input())\nans4=0\nans2=0\na=input().split()\nfor i in range(n):\n if a[i]%4==0:\n ans4+=1\n elif a[i]%2==0:\n ans2+=1\n else:\n pass\nif (n-ans2)//2+1<=ans4:\n print('Yes')\nelse:\n print('No')", "from math import ceil\nn=int(input())\nans4=0\nans2=0\nans0=0\na=list(map(int,input().split()))\nfor i in range(n):\n if a[i]%4==0:\n ans4+=1\n elif a[i]%2==0:\n ans2+=1\n else:\n ans0+=1\nif ans2>0:\n if ans0<=ans4:\n print('Yes')\n else:\n print('No')\nelse:\n if ceil((ans0+ans4)/2)>=ans0:\n print('Yes')\n else:\n print('No')\n"] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s337700771', 's531957677', 's660866850', 's784280515', 's907443249', 's837669230'] | [2940.0, 15020.0, 14252.0, 15020.0, 11096.0, 15020.0] | [17.0, 73.0, 70.0, 70.0, 27.0, 75.0] | [336, 331, 292, 296, 199, 336] |
p03639 | u999503965 | 2,000 | 262,144 | We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. | ['import math\n\nn=int(input())\nl=list(map(int,input().split()))\n\nc_4=0\nc_2=0\n\nfor i in l:\n if i%4==0:\n c_4+=1\n elif i%2==0:\n c_2+=1\n\n\nif c_2==1:\n num=n\nelse:\n num=n-c_2 \n \nif matj.ceil(num/2) <= c_4:\n ans="Yes"\nelif c_2==n:\n ans="Yes"\nelse:\n ans="No"\n \nprint(ans)', 'import math\n\nn=int(input())\nl=list(map(int,input().split()))\n\nc_4=0\nc_2=0\n\nfor i in l:\n if i%4==0:\n c_4+=1\n elif i%2==0:\n c_2+=1\n\n\nif c_2==1:\n num=n\nelse:\n num=n-c_2 \n \nif math.ceil(num/2) <= c_4:\n ans="Yes"\nelif c_2==n:\n ans="Yes"\nelse:\n ans="No"\n \nprint(ans)', 'n=int(input())\nl=list(map(int,input().split()))\n\nc_4=0\neven=0\nodd=0\n\nfor i in l:\n if i%4==0:\n c_4+=1\n elif i%2==0:\n even+=1\n else:\n odd+=1\n \nif even==0 and odd-1 <= c_4:\n ans="Yes"\nelse:\n ans="No"\n \nif even>0 and odd <= c_4:\n ans="Yes"\nelif even>0:\n ans="No"\n\nprint(ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s472530824', 's564899981', 's894127556'] | [20288.0, 20476.0, 20028.0] | [65.0, 63.0, 65.0] | [276, 276, 289] |
p03647 | u089230684 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['s = list(map(int, input().split()))\nn, m = s[0], s[1]\nton = set()\ntom = set()\nif n == m:\n ton = {1, 2, 3}\n tom = {1, 2, 3} \nfor i in range(m):\n s = list(map(int, input().split()))\n if s[0] == m:\n tom |= set(s)\n elif s[1] == m:\n tom |= set(s)\n elif s[1] == n:\n ton |= set(s)\n elif s[0] == n:\n ton |= set(s) \nton -= {n, m}\nprint(ton)\ntom -= {n, m} \nprint(tom)\nprint(ton & tom) \nif ton & tom == set():\n print("IMPOSSIBLE")\nelse:\n print(\'POSSIBLE\')', '# 10 5\n# 1 2\n# 1 3\n# 1 4\n# 8 10\n# 1 8\n\nn, m = map(int, input().split())\n\nends = []\nstarts = []\npossible = False\nfor i in range(m):\n a, b = map(int, input().split())\n if a == 1:\n starts.append([a, b])\n elif b == n:\n ends.append([a, b])\n\nstarts.sort(key=lambda x: x[1])\nends.sort(key=lambda x: x[0])\n\nif not (starts and ends):\n print("IMPOSSIBLE")\n import sys\n\n sys.exit()\n\ni = 0\nj = 0\nwhile i != len(starts) and j != len(ends):\n to = starts[i][1]\n fr = ends[j][0]\n\n if to == fr:\n possible = True\n break\n\n if to < fr:\n i += 1\n elif fr < to:\n j += 1\n\nwhile j != len(ends):\n fr = ends[j][0]\n if to == fr:\n possible = True\n break\n j += 1\n\nwhile i != len(starts):\n to = starts[i][1]\n if to == fr:\n possible = True\n break\n i += 1\n\nprint("POSSIBLE") if possible else print("IMPOSSIBLE")\n'] | ['Wrong Answer', 'Accepted'] | ['s497261565', 's658929450'] | [12636.0, 34664.0] | [746.0, 954.0] | [508, 900] |
p03647 | u118642796 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['N,M = map(int,input().split())\nab = [[int(i) for i in input().split()] for _ in range(M)]\n\nA = []\nB = [0]*N\nfor a,b in ab:\n if a==1:\n A.append(a)\n if b==N:\n B[a]=1\n\nfor a in A:\n if B[a]==1:\n print("POSSIBLE")\n break\nelse:\n print("IMPOSSIBLE")', 'N,M = map(int,input().split())\nab = [[int(i) for i in input().split()] for _ in range(M)]\n\nA = []\nB = [0]*(N+1)\nfor a,b in ab:\n if a==1:\n A.append(b)\n if b==N:\n B[a]=1\n\nfor a in A:\n if B[a]==1:\n print("POSSIBLE")\n break\nelse:\n print("IMPOSSIBLE")'] | ['Wrong Answer', 'Accepted'] | ['s442409680', 's913769144'] | [40856.0, 40856.0] | [643.0, 687.0] | [258, 262] |
p03647 | u170765582 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ["a,b=map(int,input().split())\nc=[list(map(int,input().split()))for i in[0]*b]\nfor i in range(3,a+1):\n if[1,i]in c and[i,a]in c:print('POSSIBLE');exit()\nprint('IMPOSSIBLE')", "a,b=map(int,input().split())\nc=[list(map(int,input().split()))for i in[0]*b]\nd=[]\ne=[]\nfor i in c:\n if i[0]==1:d+=[i[1]]\n elif i[1]==a:e+=[i[0]]\nprint((set(d)&set(e)==set())*'IM'+'POSSIBLE')"] | ['Wrong Answer', 'Accepted'] | ['s019634879', 's624845025'] | [53760.0, 61780.0] | [2109.0, 702.0] | [171, 192] |
p03647 | u190525112 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ["a=[0]*(200001)\n\n\nN = list(map(int, input().split()))\nx = [list(map(int, input().split())) for i in range(N[1])]\n\nprint(N,x)\n\nfor i in x:\n if i[0]==1 :\n if a[i[1]]==1:\n print('POSSIBLE')\n quit()\n a[i[1]]=1\n if i[1]==N[0]:\n if a[i[0]]==1:\n print('POSSIBLE')\n quit()\n a[i[0]]=1\n\nprint('IMPOSSIBLE')\nquit()", "import math\ninf=float('inf')\na=[0]*(200001)\n\n\nN = list(map(int, input().split()))\nx = [list(map(int, input().split())) for i in range(N[1])]\n\nprint(N,x)\n\nfor i in x:\n if i[0]==1 :\n if a[i[1]]==1:\n print('OK')\n quit()\n a[i[1]]=1\n if i[1]==N[0]:\n if a[i[0]]==1:\n print('OK')\n quit()\n a[i[0]]=1\n\nprint('NG')\nquit()", "a=[0]*(200001)\n\n\nN = list(map(int, input().split()))\nx = [list(map(int, input().split())) for i in range(N[1])]\n\n\nfor i in x:\n if i[0]==1 :\n if a[i[1]]==1:\n print('POSSIBLE')\n quit()\n a[i[1]]=1\n if i[1]==N[0]:\n if a[i[0]]==1:\n print('POSSIBLE')\n quit()\n a[i[0]]=1\n\nprint('IMPOSSIBLE')\nquit()"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s365483968', 's398989297', 's114673040'] | [63252.0, 63264.0, 53284.0] | [824.0, 851.0, 746.0] | [380, 389, 369] |
p03647 | u243370518 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['x = input().split(" ")\nn = int(x[0])\nm = int(x[1])\n\nprobInit = set([])\nprobEnd = set([])\n\nfor i in range(m):\n edge = input().split(" ")\n if edge[0] == 0:\n probInit.add(edge[1])\n\n if edge[1] == n - 1:\n probEnd.add(edge[0])\n\nunion = probEnd.union(probInit)\nif (union == set([])):\n print("IMPOSSIBLE")\nelse:\n print("POSSIBLE")\n', 'x = input().split(" ")\nn = int(x[0])\nm = int(x[1])\n\nprobInit = set([])\nprobEnd = set([])\n\nfor i in range(m):\n edge = input().split(" ")\n if edge[0] == 0:\n probInit.add(edge[1])\n\n if edge[1] == n - 1:\n probEnd.add(edge[0])\n\nunion = probEnd.union(probInit)\nif (len(union) == 0):\n print("IMPOSSIBLE")\nelse:\n print("POSSIBLE")\n', 'k = int(input())\nn = 50\nm = (n - 1) * (k + 1) + 1\n\n\nseries = str(m)\nfor i in range(n):\n series = series + " 0"\n\nprint(str(n))\nprint(series)\n', 'x = input().split(" ")\nn = int(x[0])\nm = int(x[1])\n\nprobInit = set([])\nprobEnd = set([])\n\nfor i in range(m):\n edge = input().split(" ")\n if edge[0] == 0:\n probInit.add(edge[1])\n\n if edge[1] == n - 1:\n probEnd.add(edge[0])\n\nsec = probEnd.intersection(probInit)\nif (len(sec) == 0):\n print("IMPOSSIBLE")\nelse:\n print("POSSIBLE")\n', 'x = input().split(" ")\nn = int(x[0])\nm = int(x[1])\n\nprobInit = set([])\nprobEnd = set([])\n\nfor i in range(m):\n edge = input().split(" ")\n if edge[0] == 0:\n probInit.add(edge[1])\n\n if edge[1] == n - 1:\n probEnd.add(edge[0])\n\nsec = probEnd.intercection(probInit)\nif (len(sec) == 0):\n print("IMPOSSIBLE")\nelse:\n print("POSSIBLE")\n\n', 'x = input().split(" ")\nn = int(x[0])\nm = int(x[1])\n\nprobInit = set([])\nprobEnd = set([])\n\nfor i in range(m):\n edge = input().split(" ")\n if edge[0] == "1":\n probInit.add(edge[1])\n\n if edge[1] == str(n):\n probEnd.add(edge[0])\n\nsec = probEnd.intersection(probInit)\nif (len(sec) == 0):\n print("IMPOSSIBLE")\nelse:\n print("POSSIBLE")\n'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s032631381', 's173522757', 's176633097', 's909698008', 's927882359', 's555029068'] | [3064.0, 3064.0, 3060.0, 3060.0, 3064.0, 23196.0] | [355.0, 381.0, 18.0, 374.0, 374.0, 542.0] | [354, 353, 143, 356, 357, 359] |
p03647 | u280269055 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['N = int(input())\nA = list(map(int, input().split()))\n\ns = sum(A) - N*(N-1)\nm = sum(list(map(lambda x: (x+s)//N, A)))\nwhile m > s:\n s = m\n m = sum(list(map(lambda x: (x+s)//N, A)))\nelse:\n print(m)', 'N = int(input())\nA = list(map(int, input().split()))\n\ns = sum(A) - N*(N-1)\nm = list(map(lambda x: (x+s)//N, A))\nwhile m > s:\n s = m\n m = list(map(lambda x: (x+s)//N, A))\nelse:\n print(m)', 'N, M = map(int,input().split())\nroute_1 = set()\nroute_N = set()\n\nfor _ in range(M):\n a, b = map(int,input().split())\n if a == 1:\n route_1.add(b)\n elif b == N:\n route_N.add(a)\n\nif route_1&route_N:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s452071527', 's820284947', 's368972242'] | [3060.0, 3064.0, 18892.0] | [17.0, 17.0, 586.0] | [204, 194, 270] |
p03647 | u345076485 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['N,M=map(int,input().split())\na=[]\nb=[]\nfor i in range(0,M):\n\tc,d=map(int,input().split())\n\ta.append(c)\n\tb.append(d)\n\npos=0\ni=0\ng=[0 for i in range(0,M)]\nprint(g)\ne=[]\nf=[]\nk=0\nl=0\nwhile i < M and pos == 0:\n\tif a[i] == 1:\n\t\tg[b[i]] = 1\n\tif b[i] == 1:\n\t\tg[a[i]] = 1\n\ti=i+1\ni=0\nprint(g)\nwhile i < M and pos == 0:\n\tif a[i] == N:\n\t\tif g[b[i]] == 1:\n\t\t\tpos=1\n\tif b[i] == N:\n\t\tif g[a[i]] == 1:\n\t\t\tpos=1\n\ti = i + 1\nif pos == 1:\n\tprint("POSSIBLE")\nelse:\n\tprint("IMPOSSIBLE")', 'N,M=map(int,input().split())\na=[]\nb=[]\nfor i in range(0,M):\n\tc,d=map(int,input().split())\n\ta.append(c)\n\tb.append(d)\n\npos=0\ni=0\ng=[0 for i in range(0,200000)]\ne=[]\nf=[]\nk=0\nl=0\nwhile i < M and pos == 0:\n\tif a[i] == 1:\n\t\tg[b[i]] = 1\n\tif b[i] == 1:\n\t\tg[a[i]] = 1\n\ti=i+1\ni=0\nwhile i < M and pos == 0:\n\tif a[i] == N:\n\t\tif g[b[i]] == 1:\n\t\t\tpos=1\n\tif b[i] == N:\n\t\tif g[a[i]] == 1:\n\t\t\tpos=1\n\ti = i + 1\nif pos == 1:\n\tprint("POSSIBLE")\nelse:\n\tprint("IMPOSSIBLE")'] | ['Runtime Error', 'Accepted'] | ['s251234879', 's736380465'] | [23276.0, 20480.0] | [711.0, 696.0] | [465, 452] |
p03647 | u346308892 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['class Node:\n def __init__(self):\n pass\n\nclass Edge:\n def __init__(self,edge,cost=1):\n self.node_from=edge[0]\n self.node_to=edge[1]\n self.cost=cost\n\n def add_node(self,node):\n self.nodes.append(node)\n\nclass myGraph:\n\n def __init__(self):\n self.adj={}\n self.nodes={}\n\n def add_edge(self,edge,cost):\n if len(edge)==1:\n edge=list(edge)\n\n u,v=edge[0],edge[1]\n\n if u not in self.nodes:\n self.adj[u] = {}\n self.nodes[u] = {}\n\n if v not in self.nodes:\n self.adj[v] = {}\n self.nodes[v] = {}\n\n # add the edge\n self.adj[u][v] = cost\n self.adj[v][u] = cost\n\n def add_directed_edge(self,edge,cost):\n if len(edge)==1:\n edge=list(edge)\n\n\n u,v=edge[0],edge[1]\n\n if u not in self.nodes:\n self.adj[u] = {}\n self.nodes[u] = {}\n\n if v not in self.nodes:\n self.adj[v] = {}\n self.nodes[v] = {}\n\n self.adj[u][v] = cost\n\n def get_edges_from(self,node):\n return [(self.adj[node][nn],node,nn) for nn in self.adj[node]]\n\n\n def makeEdgeobj(self):\n edges=[]\n for sn in self.nodes:\n for e in self.get_edges_from(sn):\n edges.append(Edge([e[1],e[2]],e[0]))\n\n return edges\n\n def _add(self,edges,add_edges):\n for e in add_edges:\n hq.heappush(edges,e)\n return edges\n\n def bermn_ford(self,start,init=0):\n\n nodes=self.nodes\n dists={}\n for n in nodes:\n dists[n]=float("inf")\n\n dists[start]=init\n edges=self.makeEdgeobj()\n\n for i in range(len(nodes)):\n update=False\n for k in range(len(edges)):\n e=edges[k]\n if dists[e.node_from]!=float("inf") and dists[e.node_to]>dists[e.node_from]+e.cost:\n dists[e.node_to]=dists[e.node_from]+e.cost\n update=True\n\n if i==len(nodes)-1:\n return False\n\n if not update:\n break\n\n return dists\n\n\n def dijkstra(self,start, goal=None):\n import heapq\n \'\'\'\n get minimum cost\n \'\'\'\n\n N = len(self.adj) \n \n dist = {k:float(\'inf\') for k in self.nodes}\n \n\n dist[start] = 0\n visited = []\n\n koho=[]\n heapq.heappush(koho,(0,start))\n\n vtx=list(self.nodes)\n vtx.remove(start)\n\n count=0\n while len(koho)!=0:\n d,mini=heapq.heappop(koho)\n count+=1\n if count==2:\n break\n \n if dist[mini]<d:\n continue\n\n\n for k in list(self.adj[mini]):\n cost=self.adj[mini][k]\n if cost != float(\'inf\') and dist[k]>dist[mini]+cost:# and not(k in visited):\n dist[k]=dist[mini]+cost\n heapq.heappush(koho,(dist[k],k))\n #prev[k]=mini\n\n return dist\n\n\n\n\ndef spaceinput():\n s=input()\n if len(s)==0:\n return False\n\n return list(map(int,s.split(" ")))\n\nif __name__=="__main__":\n n,m=spaceinput()\n g=myGraph()\n\n for i in range(10**6):\n try:\n ss=spaceinput()\n if not ss:\n break\n except:\n break\n\n g.add_edge((ss[0],ss[1]),1)\n res=g.dijkstra(start=1)\n #print(res)\n if n in res and res[n]<=2:\n if res[n]==1:\n if len(set(g.adj[1]).union(g.adj[n]))>0:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")\n else:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")\n', 'class Node:\n def __init__(self):\n pass\n\nclass Edge:\n def __init__(self,edge,cost=1):\n self.node_from=edge[0]\n self.node_to=edge[1]\n self.cost=cost\n\n def add_node(self,node):\n self.nodes.append(node)\n\nclass myGraph:\n\n def __init__(self):\n self.adj={}\n self.nodes={}\n\n def add_edge(self,edge,cost):\n if len(edge)==1:\n edge=list(edge)\n\n u,v=edge[0],edge[1]\n\n if u not in self.nodes:\n self.adj[u] = {}\n self.nodes[u] = {}\n\n if v not in self.nodes:\n self.adj[v] = {}\n self.nodes[v] = {}\n\n # add the edge\n self.adj[u][v] = cost\n self.adj[v][u] = cost\n\n def add_directed_edge(self,edge,cost):\n if len(edge)==1:\n edge=list(edge)\n\n\n u,v=edge[0],edge[1]\n\n if u not in self.nodes:\n self.adj[u] = {}\n self.nodes[u] = {}\n\n if v not in self.nodes:\n self.adj[v] = {}\n self.nodes[v] = {}\n\n self.adj[u][v] = cost\n\n def get_edges_from(self,node):\n return [(self.adj[node][nn],node,nn) for nn in self.adj[node]]\n\n\n def makeEdgeobj(self):\n edges=[]\n for sn in self.nodes:\n for e in self.get_edges_from(sn):\n edges.append(Edge([e[1],e[2]],e[0]))\n\n return edges\n\n def _add(self,edges,add_edges):\n for e in add_edges:\n hq.heappush(edges,e)\n return edges\n\n def bermn_ford(self,start,init=0):\n\n nodes=self.nodes\n dists={}\n for n in nodes:\n dists[n]=float("inf")\n\n dists[start]=init\n edges=self.makeEdgeobj()\n\n for i in range(len(nodes)):\n update=False\n for k in range(len(edges)):\n e=edges[k]\n if dists[e.node_from]!=float("inf") and dists[e.node_to]>dists[e.node_from]+e.cost:\n dists[e.node_to]=dists[e.node_from]+e.cost\n update=True\n\n if i==len(nodes)-1:\n return False\n\n if not update:\n break\n\n return dists\n\n\n def dijkstra(self,start, goal=None):\n import heapq\n \'\'\'\n get minimum cost\n \'\'\'\n\n N = len(self.adj) \n \n dist = {k:float(\'inf\') for k in self.nodes}\n \n\n dist[start] = 0\n visited = []\n\n koho=[]\n heapq.heappush(koho,(0,start))\n\n vtx=list(self.nodes)\n vtx.remove(start)\n\n while len(koho)!=0:\n d,mini=heapq.heappop(koho)\n\n if d>2:\n break\n\n if dist[mini]<d:\n continue\n\n\n for k in list(self.adj[mini]):\n cost=self.adj[mini][k]\n if cost != float(\'inf\') and dist[k]>dist[mini]+cost:# and not(k in visited):\n dist[k]=dist[mini]+cost\n heapq.heappush(koho,(dist[k],k))\n #prev[k]=mini\n\n return dist\n\n\n\n\ndef spaceinput():\n s=input()\n if len(s)==0:\n return False\n\n return list(map(int,s.split(" ")))\n\nif __name__=="__main__":\n n,m=spaceinput()\n g=myGraph()\n\n for i in range(10**6):\n try:\n ss=spaceinput()\n if not ss:\n break\n except:\n break\n\n g.add_edge((ss[0],ss[1]),1)\n res=g.dijkstra(start=1)\n #print(res)\n if n in res and res[n]<=2:\n if res[n]==1:\n if len(set(g.adj[1]).union(g.adj[n]))>0:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")\n else:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")\n'] | ['Wrong Answer', 'Accepted'] | ['s460740902', 's417066242'] | [197528.0, 197452.0] | [1604.0, 1921.0] | [3923, 3866] |
p03647 | u353402627 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ["n,m = map(int, input().split())\n\nislands = [0 for i in range(n)]\n\nfor i in range(m):\n a, b = map(int, input().split())\n \n if a == 1:\n if islands[b-1] == 2:\n print('Possible')\n break\n islands[b-1] = 1\n if b == n:\n if islands[a-1] == 1:\n print('Possible')\n break\n islands[a-1] = 2\n \n if i == m-1:\n print('Impossible')", "n,m = map(int, input().split())\n\nislands = [0 for i in range(n)]\n\nfor i in range(m):\n a, b = map(int, input().split())\n \n if a == 1:\n if islands[b-1] == 2:\n print('POSSIBLE')\n break\n islands[b-1] = 1\n if b == n:\n if islands[a-1] == 1:\n print('POSSIBLE')\n break\n islands[a-1] = 2\n \n if i == m-1:\n print('IMPOSSIBLE')"] | ['Wrong Answer', 'Accepted'] | ['s428497160', 's267291327'] | [4656.0, 4656.0] | [632.0, 622.0] | [358, 358] |
p03647 | u353919145 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['s = list(map(int, input().split()))\nn, m = s[0], s[1]\nton = set()\ntom = set()\nfor i in range(m):\n s = list(map(int, input().split()))\n if s[0] == m:\n tom |= set(s)\n elif s[1] == m:\n tom |= set(s)\n elif s[1] == n:\n ton |= set(s)\n elif s[0] == n:\n ton |= set(s) \nton -= {n, m}\ntom -= {n, m} \nif ton & tom == set():\n print("IMPOSSIBLE")\nelse:\n print(\'POSSIBLE\')', 'n,m = input().split()\nn = int(n)\nm = int(m)\nl = [[] for i in range(n)]\nfor i in range(m):\n a,b = input().split()\n a = int(a)\n b = int(b)\n l[a-1].append(b-1)\n l[b-1].append(a-1)\n\nf = False\nfor i in l[0]:\n for j in l[i]:\n if j == n-1:\n f = True\n break\nif f:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")'] | ['Wrong Answer', 'Accepted'] | ['s058048658', 's015641171'] | [12104.0, 38352.0] | [728.0, 720.0] | [413, 354] |
p03647 | u397531548 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['N,M=map(int,input().split())\nx=[0]*(n+1)\ny=[0]*(n+1)\nfor i in range(M):\n a,b=map(int,input().split())\n if a==1:\n x[b]=1\n if b==N:\n y[a]=1\nfor i in range(N+1):\n if x[i]==1 and y[i]==1:\n print("POSSIBLE")\n break\nelse:\n print("IMPOSSIBLE")', 'N,M=map(int,input().split())\nx=[0]*(N+1)\ny=[0]*(N+1)\nfor i in range(M):\n a,b=map(int,input().split())\n if a==1:\n x[b]=1\n if b==N:\n y[a]=1\nfor i in range(N+1):\n if x[i]==1 and y[i]==1:\n print("POSSIBLE")\n break\nelse:\n print("IMPOSSIBLE")'] | ['Runtime Error', 'Accepted'] | ['s431876020', 's545572085'] | [3064.0, 6132.0] | [18.0, 642.0] | [279, 279] |
p03647 | u450339194 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ["N, M = map(int, input().split())\n\nimport sys\n\nteiki = defaultdict(set)\nfor i in range(M):\n a, b = map(int, input().split())\n teiki[a].add(b)\n\n\nif 1 not in teiki:\n print('IMPOSSIBLE')\n sys.exit()\n\nfor i in teiki[1]:\n if i in teiki and N in teiki[i]:\n print('POSSIBLE')\n sys.exit()\n\nprint('IMPOSSIBLE')", "from collections import defaultdict\n\nN, M = map(int, input().split())\n\nimport sys\n\nteiki = defaultdict(set)\nfor i in range(M):\n a, b = map(int, input().split())\n teiki[a].add(b)\n\n\nif 1 not in teiki:\n print('IMPOSSIBLE')\n sys.exit()\n\nfor i in teiki[1]:\n if i in teiki and N in teiki[i]:\n print('POSSIBLE')\n sys.exit()\n\nprint('IMPOSSIBLE')"] | ['Runtime Error', 'Accepted'] | ['s622530278', 's137658730'] | [3064.0, 45360.0] | [17.0, 772.0] | [329, 366] |
p03647 | u497046426 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ["N, M = map(int, input().split())\nfrom_1 = [False]*N\nto_N = [False]*N\nfor _ in range(M):\n a, b = map(int, input().split())\n if a-1 == 0:\n from_1[b-1] = True\n elif b-1 == 0:\n to_N[a-1] = True\nfor i in range(1, N):\n if from_1[i] and to_N[i]:\n print('POSSIBLE')\n break\nelse:\n print('IMPOSSIBLE')", "N, M = map(int, input().split())\nfrom_1 = [False]*N\nto_N = [False]*N\nfor _ in range(M):\n a, b = map(int, input().split())\n if a == 1:\n from_1[b-1] = True\n elif b == N:\n to_N[a-1] = True\nfor i in range(1, N):\n if from_1[i] and to_N[i]:\n print('POSSIBLE')\n break\nelse:\n print('IMPOSSIBLE')"] | ['Wrong Answer', 'Accepted'] | ['s442039679', 's312034292'] | [6132.0, 6132.0] | [590.0, 579.0] | [334, 330] |
p03647 | u532966492 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ["N,M=map(int,input().split())\nab=[list(map(int,input().split())) for _ in [0]*M]\ng=[set() for _ in [0]*N]\n[g[b-1].add(a-1) for a,b in ab]\n[g[a-1].add(b-1) for a,b in ab]\na=g[0]\nfor i in a:\n\tif N-1 not in g[i]:\n\t\tprint('IMPOSSIBLE')\n\t\tbreak\nelse:\n\tprint('IPOSSIBLE')", "N,M=map(int,input().split())\nab=[list(map(int,input().split())) for _ in [0]*M]\ng=[set() for _ in [0]*N]\n[g[b-1].add(a-1) for a,b in ab]\n[g[a-1].add(b-1) for a,b in ab]\na=g[0]\nprint(a)\nfor i in a:\n\tif N-1 in g[i]:\n\t\tprint('POSSIBLE')\n\t\tbreak\nelse:\n\tprint('IMPOSSIBLE')", "N,M=map(int,input().split())\nab=[list(map(int,input().split())) for _ in [0]*M]\ng=[set() for _ in [0]*N]\n[g[b-1].add(a-1) for a,b in ab]\n[g[a-1].add(b-1) for a,b in ab]\na=g[0]\nfor i in a:\n\tif N-1 in g[i]:\n\t\tprint('POSSIBLE')\n\t\tbreak\nelse:\n\tprint('IMPOSSIBLE')"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s041462069', 's744964594', 's362757141'] | [117432.0, 118176.0, 117432.0] | [1002.0, 1036.0, 1018.0] | [264, 268, 259] |
p03647 | u635277286 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['class UnionFind():\n\tdef __init__(self,size):\n\t\tself.table = [-1 for _ in range(size)]\n\n\tdef find(self,x):\n\t\twhile self.table[x] >= 0:\n\t\t\tx = self.table[x]\n\t\treturn x\n\n\tdef unite(self,x,y):\n\t\ts1 = self.find(x)\n\t\ts2 = self.find(y)\n\t\tif s1 != s2:\n\t\t\tif self.table[s1] != self.table[s2]:\n\t\t\t\tif self.table[s1] < self.table[s2]:\n\t\t\t\t\tself.table[s2] = s1\n\t\t\t\telse:\n\t\t\t\t\tself.table[s1] = s2\n\t\t\telse:\n\t\t\t\tself.table[s1] += -1\n\t\t\t\tself.table[s2] = s1\n\t\treturn\n\n\tdef same(self,x,y):\n\t\treturn self.find(x) == self.find(y)\n\n\nN, M = map(int,input().split())\nedges = [[] for _ in range(N)]\n\nfor i in range(M):\n\ta, b = map(int,input().split())\n\tif a == 0 or a == N or b == 0 or b == N:\n\t\tedges[a-1] += [b-1]\n\t\tedges[b-1] += [a-1]\n\nuf = UnionFind(N)\n\nfor u in edges[0]:\n\tif N-1 not in edges[0]:\n\t\tuf.unite(0,u)\n\nfor v in edges[N-1]:\n\tif 0 not in edges[N-1]:\n\t\tuf.unite(N-1,v)\n\nprint("POSSIBLE" if uf.same(0,N-1) == True else "IMPOSSIBLE")', 'N, M = map(int,input().split())\n\nfrom1 = set()\ngotoN = set()\n\nfor i in range(M):\n\ta, b = map(int,input().split())\n\tif a == 1:\n\t\tfrom1.add(b)\n\telif a == N:\n\t\tgotoN.add(b)\n\n\tif b == 1:\n\t\tfrom1.add(a)\n\telif b == N:\n\t\tgotoN.add(a)\n\nres = from1 & gotoN\n\nprint("POSSIBLE" if len(res) > 0 else "IMPOSSIBLE")'] | ['Wrong Answer', 'Accepted'] | ['s397835884', 's368287999'] | [30796.0, 18892.0] | [2105.0, 622.0] | [922, 300] |
p03647 | u777923818 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['# -*- coding: utf-8 -*-\nimport numpy as np\n\nK = int(input())\nK = K\n\n\na = np.ones(50).astype(np.int64)*(49) + (K)//50\n\nif K%50 != 0:\n a[:K%50] += 51 - (K%50)\n a[K%50:] -= (K%50)\nelse:\n pass\n \nresult = "50\\n{}".format(a[0])\nfor a_ in a[1:]:\n result += (" {}".format(int(a_)))\nprint(result)', '# -*- coding: utf-8 -*-\n\nN, M = [int(n) for n in input().split()]\nislands = {n:[] for n in range(1, N+1)}\nresult = "IMPOSSIBLE"\n\nfor m in range(M):\n a, b = [int(n) for n in input().split()]\n islands[a].append(b)\n islands[b].append(a)\n\nok_isl = set()\nsearch_isl = [1]\nnext_isl = set()\n\nloop = True\nfor x in range(2):\n for i in search_isl:\n if N in islands[i]:\n loop = False\n result = "POSSIBLE" \n else:\n next_isl.update(islands[i])\n \n ok_isl = ok_isl.union(search_isl)\n \n search_isl = next_isl.difference(ok_isl)\n if len(search_isl) == 0:\n break\n\nprint(result)'] | ['Runtime Error', 'Accepted'] | ['s487610651', 's905427020'] | [12500.0, 69984.0] | [147.0, 936.0] | [365, 651] |
p03647 | u816631826 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['s = list(map(int, input().split()))\nn, m = s[0], s[1]\nton = set()\ntom = set()\nif n == m:\n ton = {1, 2, 3}\n tom = {1, 2, 3} \nfor i in range(m):\n s = list(map(int, input().split()))\n if s[0] == m:\n tom |= set(s)\n elif s[1] == m:\n tom |= set(s)\n elif s[1] == n:\n ton |= set(s)\n elif s[0] == n:\n ton |= set(s) \nton -= {n, m}\ntom -= {n, m} \nif ton & tom == set():\n print("IMPOSSIBLE")\nelse:\n print(\'POSSIBLE\')', 'n, m = map(int, input().split())\n\nis1 = [False] * (n + 1)\nisN = [False] * (n + 1)\n\nfor i in range(m):\n a, b = map(int, input().split())\n if(a > b):\n a, b = b, a\n if(a == 1):\n is1[b] = True\n if(b == n):\n isN[a] = True\n\nimport sys\n\nfor i in range(2, n):\n if(is1[i] and isN[i]):\n print("POSSIBLE")\n sys.exit(0)\n\nprint("IMPOSSIBLE")\n'] | ['Wrong Answer', 'Accepted'] | ['s726661874', 's233666862'] | [12124.0, 6132.0] | [713.0, 579.0] | [464, 379] |
p03647 | u894844146 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | [' def f():\n n,m = map(int,input().split(" "))\n s = []\n w = [[] for i in range(n+2)]\n for i in range(m):\n a,b = map(int,input().split(" "))\n \n if a==1:\n s.append(b)\n if b==1:\n s.append(a)\n w[a].append(b)\n w[b].append(a)\n for i in s:\n if n in w[i]:\n print("POSSIBLE")\n return 0\n print("IMPOSSIBLE")\n return 0\n f()', 'def f():\n n,m = map(int,input().split(" "))\n s = []\n w = [[] for i in range(n+2)]\n for i in range(m):\n a,b = map(int,input().split(" "))\n \n if a==1:\n s.append(b)\n if b==1:\n s.append(a)\n w[a].append(b)\n w[b].append(a)\n for i in s:\n if n in w[i]:\n print("POSSIBLE")\n return 0\n print("IMPOSSIBLE")\n return 0\nf()'] | ['Runtime Error', 'Accepted'] | ['s661510138', 's702500056'] | [2940.0, 38460.0] | [17.0, 739.0] | [502, 422] |
p03647 | u995062424 | 2,000 | 262,144 | In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him. | ['N, M = map(int, input().split())\ngraph = {i+1:[] for i in range(N)}\nfor i in range(M):\n a, b = map(int, input().split())\n graph[a].append(b)\n graph[b].append(a)\n\nfor value in graph[1]:\n if(N in graph[value]):\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")', 'N, M = map(int, input().split())\ngraph = {i+1:[] for i in range(N)}\nfor i in range(M):\n a, b = map(int, input().split())\n graph[a].append(b)\n graph[b].append(a)\n\nfor value in graph[1]:\n if(N in graph[value]):\n print("POSSIBLE")\n break\nelse:\n print("IMPOSSIBLE")'] | ['Wrong Answer', 'Accepted'] | ['s811770210', 's818298241'] | [55520.0, 55520.0] | [869.0, 884.0] | [277, 291] |
p03649 | u034128150 | 2,000 | 262,144 | We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.) * Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1. It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given the sequence a_i. Find the number of times we will perform the above operation. | ['N = int(input())\nlist_of_a = list(map(int, input().split()))\n\nng = max(0, sum(list_of_a)-(N-1)*N) - 1\nok = max(0, (max(list_of_a) - (N-1)) * N)\nprint(ng, ok)\nwhile ok - ng > 1:\n mid = (ok + ng) // 2\n count = 0\n for a in list_of_a:\n count += (a + mid + 1) // (N+1)\n if count <= mid:\n ok = mid\n else:\n ng = mid\n\nprint(ok)', "N = int(input())\nlist_of_a = list(map(int, input().split()))\n\nng = max(0, sum(list_of_a)-(N-1)*N) - 1\nok = max(0, (max(list_of_a) - (N-1)) * N)\nwhile ok - ng > 1:\n mid = (ok + ng) // 2\n count = 0\n for a in list_of_a:\n count += (a + mid + 1) // (N+1)\n if count <= mid:\n ok = mid\n else:\n ng = mid\n\n#'ok'-i (i=1..N) may be better\n\nfor i in range(0, 30 * N + 1):\n mid = ok - i\n if mid < 0:\n break\n count = 0\n for a in list_of_a:\n count += (a + mid + 1) // (N+1)\n if count == mid:\n ans = mid\n\nprint(ans)\n"] | ['Wrong Answer', 'Accepted'] | ['s297373477', 's674717378'] | [9164.0, 9184.0] | [31.0, 46.0] | [355, 571] |
p03649 | u057079894 | 2,000 | 262,144 | We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.) * Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1. It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given the sequence a_i. Find the number of times we will perform the above operation. | ['##create with UTF-8\n\nn = int( input() )\nda=list(map(int, input(). split()))\nli=[da[i]%(n+1) for i in range(n)]\nsu=0\nans=0\nfor i in range(n):\n\tsu+=da[i]\nfor i in range(n):\n\tdiv=(n-1)-(da[i]%(n+1))\n\tnow=0\n\tju=True\n\tfor j in range(n):\n\t\tif (n+1+div+da[j])%(n+1)==n:\n\t\t\tju=False\n\t\t\tbreak\n\t\tnow+=(n+1+div+da[j])%(n+1)\n\tif ju and su >= now:\n\t\tprint(now)\n\t\tans = max(ans,now)\nprint(su-ans)', '##create with UTF-8\n\nn = int( input() )\nda=list(map(int, input(). split()))\nli=[da[i]%(n+1) for i in range(n)]\nsu=0\nans=0\nfor i in range(n):\n\tsu+=da[i]\nfor i in range(n):\n\tdiv=(n-1)-(da[i]%(n+1))\n\tnow=0\n\tju=True\n\tfor j in range(n):\n\t\tif (n+1+div+da[j])%(n+1)==n:\n\t\t\tju=False\n\t\t\tbreak\n\t\tnow+=(n+1+div+da[j])%(n+1)\n\tif ju and su >= now:\n\t\t#print(now)\n\t\tans = max(ans,now)\nprint(su-ans)'] | ['Wrong Answer', 'Accepted'] | ['s318859782', 's689349765'] | [3064.0, 3064.0] | [18.0, 18.0] | [382, 383] |
p03649 | u392319141 | 2,000 | 262,144 | We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.) * Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1. It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given the sequence a_i. Find the number of times we will perform the above operation. | ['N = int(input())\nA = list(map(int, input().split()))\n\ndef isOk(k):\n B = [a + k for a in A]\n cnt = 0\n for b in B:\n cnt += b // (N + 1)\n return cnt >= k\n\nok = 0\nng = 10**20\nwhile ng - ok > 1:\n mid = (ok + ng) // 2\n if isOk(mid):\n ok = mid\n else:\n ng = mid\nprint(ok)', 'N = int(input())\nA = list(map(int, input().split()))\n\nans = 0\nwhile max(A) >= N:\n i = A.index(max(A))\n k = A[i] // N\n A[i] %= N\n ans += k\n for j in range(N):\n if j != i:\n A[j] += k\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s539017767', 's926145004'] | [3064.0, 3064.0] | [18.0, 517.0] | [306, 225] |
p03649 | u606045429 | 2,000 | 262,144 | We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.) * Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1. It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given the sequence a_i. Find the number of times we will perform the above operation. | ['from numpy import int64, divmod\n\nN, A = open(0)\nN, A = int(N), int64(A.split())\n\nans = 0\nS = -1\nwhile S:\n B, A = A % N, A // N\n S = B.sum()\n ans += S\n A += S - B\n\nprint(ans)\n', 'from numpy import int64\n\nN, A = open(0)\nN, A = int(N), int64(A.split())\n\nans = 0\nS = -1\nwhile S:\n B, A = A % N, A // N\n S = B.sum()\n ans += S\n A += S - B\n\nprint(ans)\n', 'from numpy import int64\n\nN, A = open(0)\nN, A = int(N), int64(A.split())\n\nans = 0\nS = -1\nwhile S:\n B, A = A // N, A % N\n S = B.sum()\n ans += S\n A += S - B\n\nprint(ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s339868393', 's718328394', 's468024194'] | [12496.0, 14412.0, 12508.0] | [151.0, 2112.0, 179.0] | [186, 178, 178] |
p03649 | u844789719 | 2,000 | 262,144 | We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.) * Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1. It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given the sequence a_i. Find the number of times we will perform the above operation. | ['N, *A = [int(_) for _ in open(0).read().split()]\nsumB = max(0, sum(A) - N * (N - 1))\nwhile True:\n B = [0 - (-(a + x + 1 - N)) // (N + 1) for a in A]\n if sumB == sum(B):\n break\n sumB += 1\nprint(sumB)\n', 'N, *A = [int(_) for _ in open(0).read().split()]\nsumB = max(0, sum(A) - N * (N - 1))\nwhile True:\n B = [0 - (-(a + sumB + 1 - N)) // (N + 1) for a in A]\n if sumB == sum(B):\n break\n sumB += 1\nprint(sumB)\n'] | ['Runtime Error', 'Accepted'] | ['s304339144', 's398866170'] | [9100.0, 9088.0] | [28.0, 46.0] | [215, 218] |
p03650 | u466826467 | 2,000 | 262,144 | There is a directed graph with N vertices and N edges. The vertices are numbered 1, 2, ..., N. The graph has the following N edges: (p_1, 1), (p_2, 2), ..., (p_N, N), and the graph is weakly connected. Here, an edge from Vertex u to Vertex v is denoted by (u, v), and a weakly connected graph is a graph which would be connected if each edge was bidirectional. We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, a_i is the value assigned to Vertex i. * Each a_i is a non-negative integer. * For each edge (i, j), a_i \neq a_j holds. * For each i and each integer x(0 ≤ x < a_i), there exists a vertex j such that the edge (i, j) exists and x = a_j holds. Determine whether there exists such an assignment. | ['from collections import defaultdict\nimport heapq as hq\n\n\ndef helper(n):\n q = child_L[n]\n del child_L[n]\n\n hq.heapify(q)\n i = 0\n while q:\n t = hq.heappop(q)\n if i < t:\n break\n else:\n i += (i == t)\n\n j = i + 1\n while q:\n t = hq.heappop(q)\n if j < t:\n break\n else:\n j += (j == t)\n\n return (i, j)\n\n\nif __name__ == \'__main__\':\n\n N = int(input())\n P = list(map(lambda x: int(x) - 1, input().split()))\n \n D = [0] * N\n for p in P:\n D[p] += 1\n # print(D)\n child_L = defaultdict(list)\n \n S = [p for p in range(N) if D[p] == 0]\n\n L = [None] * N\n\n while S:\n # print(child_L)\n n = S.pop()\n\n q = child_L[n]\n print(q)\n del child_L[n]\n\n \n hq.heapify(q)\n i = 0\n while q:\n t = hq.heappop(q)\n if i < t:\n break\n else:\n i += (i == t)\n\n L[n] = i\n print(L)\n m = P[n]\n print("m:" + str(m))\n child_L[m].append(i)\n D[m] -= 1\n if D[m] == 0:\n S.append(m)\n\n print(D)\n # cycle check\n try:\n start = D.index(1)\n except ValueError:\n print(\'POSSIBLE\')\n exit()\n\n s1, s2 = helper(start)\n G = []\n n = P[start]\n while n != start:\n G.append(helper(n))\n n = P[n]\n\n \n\n \n # 1\n n = s1\n for g in G:\n if g[0] == n:\n n = g[1]\n else:\n n = g[0]\n if n != s1:\n print(\'POSSIBLE\')\n exit()\n\n # 2\n n = s2\n for g in G:\n if g[0] == n:\n n = g[1]\n else:\n n = g[0]\n if n == s1:\n print(\'POSSIBLE\')\n exit()\n\n print(\'IMPOSSIBLE\')\n', 'from collections import defaultdict\nimport heapq as hq\n\n\ndef helper(n):\n q = child_L[n]\n del child_L[n]\n\n hq.heapify(q)\n i = 0\n while q:\n t = hq.heappop(q)\n if i < t:\n break\n else:\n i += (i == t)\n\n j = i + 1\n while q:\n t = hq.heappop(q)\n if j < t:\n break\n else:\n j += (j == t)\n\n return (i, j)\n\n\nif __name__ == \'__main__\':\n\n N = int(input())\n P = list(map(lambda x: int(x) - 1, input().split()))\n \n D = [0] * N\n for p in P:\n D[p] += 1\n # print(D)\n child_L = defaultdict(list)\n \n S = [p for p in range(N) if D[p] == 0]\n\n L = [None] * N\n\n while S:\n # print(child_L)\n n = S.pop()\n\n q = child_L[n]\n # print(q)\n del child_L[n]\n\n \n hq.heapify(q)\n i = 0\n while q:\n t = hq.heappop(q)\n if i < t:\n break\n else:\n i += (i == t)\n\n L[n] = i\n # print(L)\n m = P[n]\n # print("m:" + str(m))\n child_L[m].append(i)\n D[m] -= 1\n if D[m] == 0:\n S.append(m)\n\n # print(D)\n # cycle check\n try:\n start = D.index(1)\n except ValueError:\n print(\'POSSIBLE\')\n exit()\n\n s1, s2 = helper(start)\n G = []\n n = P[start]\n while n != start:\n G.append(helper(n))\n n = P[n]\n\n \n\n \n # 1\n n = s1\n for g in G:\n if g[0] == n:\n n = g[1]\n else:\n n = g[0]\n if n != s1:\n print(\'POSSIBLE\')\n exit()\n\n # 2\n n = s2\n for g in G:\n if g[0] == n:\n n = g[1]\n else:\n n = g[0]\n if n == s1:\n print(\'POSSIBLE\')\n exit()\n\n print(\'IMPOSSIBLE\')\n'] | ['Runtime Error', 'Accepted'] | ['s166586633', 's423097778'] | [152124.0, 30288.0] | [1827.0, 509.0] | [1988, 1996] |
p03651 | u000085263 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['n, k = map(int, input().split())\nl = list(map(int, input().split()))\nm = max(a)\ndef hcf(x, y): \n while(y): \n x, y = y, x % y \n return x \nnum1=l[0] \nnum2=l[1] \ngcd=hcf(num1,num2) \nfor i in range(2,len(l)): \n gcd=hcf(gcd,l[i])\nif k%gcd == 0 and k<=m:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")', 'import math\nfrom functools import reduce\nn, k = list(map(int, input().split()))\nA = list(map(int, input().split()))\ndef hcf(l):\n return reduce(math.gcd, l)\ngcd = hcf(A)\nm = max(A)\nif k%gcd == 0 and k<=m:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n'] | ['Runtime Error', 'Accepted'] | ['s859461708', 's595100258'] | [19996.0, 20444.0] | [52.0, 60.0] | [316, 259] |
p03651 | u023229441 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['n,k=map(int,input().split())\nA=list(map(int,input().split()))\nyes="POSSIBLE" ; no="IMPOSSIBLE"\nimport numpy as np\nq= np.gcd.reduce(A)\nif k%q==0 and max(A)-min(A)>=k:\n print(yes)\nelse:\n print(no)', 'n,k=map(int,input().split())\nA=list(map(int,input().split()))\nyes="POSSIBLE" ; no="IMPOSSIBLE"\nimport numpy as np\nq= np.gcd.reduce(A)\nif k%q==0 and max(A)>=k:\n print(yes)\nelse:\n print(no)'] | ['Wrong Answer', 'Accepted'] | ['s490935210', 's506859219'] | [31472.0, 31424.0] | [143.0, 143.0] | [200, 193] |
p03651 | u037430802 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['\nN,K = map(int, input().split())\n\nA = list(map(int, input().split()))\n\nA.sort()\n\nif A[-1] < K:\n print("IMPOSSIBLE")\n exit()\n\nif K in A or 1 in A:\n print("POSSIBLE")\n exit()\n\ndef gcd(a,b):\n x = max([a,b])\n y = min([a,b])\n while y:\n x, y = y, x % y\n return x\n\ng = A[0]\nfor i in range(1,N):\n g = gcd(A[i], g)\n \n\nprint("POSSIBLE" ig K % g == 9 else "IMPOSSIBLE")', 'N,K = map(int, input().split())\n\nA = list(map(int, input().split()))\n\nA.sort()\n\nif A[-1] < K:\n print("IMPOSSIBLE")\n exit()\n\nif K in A or 1 in A:\n print("POSSIBLE")\n exit()\n\ndef gcd(a,b):\n x = max([a,b])\n y = min([a,b])\n while y:\n x, y = y, x % y\n return x\n\ng = A[0]\nfor n in A[1:]:\n g = gcd(n, g)\n \n\nprint("POSSIBLE" if K % g == 0 else "IMPOSSIBLE")'] | ['Runtime Error', 'Accepted'] | ['s079573032', 's535032689'] | [3064.0, 14224.0] | [17.0, 154.0] | [395, 386] |
p03651 | u088863512 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['# -*- coding: utf-8 -*-\nimport sys\nfrom collections import deque, defaultdict\nfrom math import sqrt, factorial, gcd, ceil, atan, pi\ndef input(): return sys.stdin.readline()[:-1] # warning not \\n\n\n\nimport string\n\nfrom bisect import bisect_left, bisect_right\nfrom functools import lru_cache, reduce\nMOD = int(1e9)+7\nINF = float(\'inf\')\n\n\ndef solve():\n # n = int(input())\n n, k = [int(x) for x in input().split()]\n a = [int(x) for x in input().split()]\n g = reduce(gcd, a)\n print(g)\n m = max(a)\n if k <= m and k % g == 0:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")\n\nt = 1\n# t = int(input())\nfor case in range(1,t+1):\n ans = solve()\n\n\n"""\n1\n4\n-1 1 1 -1\n\n"""\n', '# -*- coding: utf-8 -*-\nimport sys\nfrom collections import deque, defaultdict\nfrom math import sqrt, factorial, gcd, ceil, atan, pi\ndef input(): return sys.stdin.readline()[:-1] # warning not \\n\n\n\nimport string\n\nfrom bisect import bisect_left, bisect_right\nfrom functools import lru_cache, reduce\nMOD = int(1e9)+7\nINF = float(\'inf\')\n\n\ndef solve():\n # n = int(input())\n n, k = [int(x) for x in input().split()]\n a = [int(x) for x in input().split()]\n g = reduce(gcd, a)\n\n m = max(a)\n if k <= m and k % g == 0:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")\n\nt = 1\n# t = int(input())\nfor case in range(1,t+1):\n ans = solve()\n\n\n"""\n1\n4\n-1 1 1 -1\n\n"""\n'] | ['Wrong Answer', 'Accepted'] | ['s556568688', 's115404479'] | [21728.0, 21616.0] | [65.0, 65.0] | [860, 848] |
p03651 | u136395536 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['N,K = (int(i) for i in input().split())\nA = [int(i) for i in input().split()]\n\nmakable = False\nif max(A) < K:\n makable = False\nelif K in A:\n makable = True\n\nif makable:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n ', "def euclid(x,y):\n a = max(x,y)\n b = min(x,y)\n \n r = a % b\n while r != 0:\n a = b\n b = r\n r = a % b\n\n return b\n\n\nN,K = (int(i) for i in input().split())\nA = [int(i) for i in input().split()]\n\nif N == 1:\n if K == A[0]:\n ans = 'POSSIBLE'\n else:\n ans = 'IMPOSSIBLE'\nelse:\n \n M = max(A)\n G = euclid(A[0],A[1])\n for i in range(1,N):\n G = euclid(A[i],G)\n \n if K % G == 0 and K <= M:\n ans = 'POSSIBLE'\n else:\n ans = 'IMPOSSIBLE'\n \nprint(ans)"] | ['Wrong Answer', 'Accepted'] | ['s635028250', 's938049480'] | [14252.0, 14480.0] | [48.0, 109.0] | [231, 537] |
p03651 | u143492911 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['n,k=map(int,input().split())\na=list(map(int,input().split()))\ndef gcd(a,b):\n while b!=0:\n a,b=b,a%b\n return a\nans=a[0]\nfor i in range(1,n):\n ans=gcd(ans,a[i])\nif ans%k==0:\n if k<max(a):\n print("POSSIBLE")\n exit()\nprint("IMPOSSIBLE")\n\n', 'n,k=map(int,input().split())\nt=list(map(int,input().split()))\ndef gcd(a,b):\n while b!=0:\n a,b=b,a%b\n return a\nans=t[0]\nfor i in range(n):\n ans=gcd(ans,t[i])\nif k%ans==0:\n if k<=max(t):\n print("POSSIBLE")\n exit()\nprint("IMPOSSIBLE")\n'] | ['Wrong Answer', 'Accepted'] | ['s643058635', 's088733078'] | [14100.0, 14096.0] | [74.0, 75.0] | [267, 265] |
p03651 | u177040005 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ["def gcd(a,b):\n if b == 0:\n return abs(a)\n else:\n return gcd(b, a%b)\n\nN,K = map(int, input().split())\nA = sorted(list(map(int,input().split())))\n\nIm = 'IMPOSSIBLE'\nPo = 'POSSIBLE'\n\nif A[-1] < K:\n print(Im)\nelse:\n for i in range(N):\n if i == 0:\n gcd = gcd(A[i], A[i])\n else:\n gcd = gcd(A[i],gcd)\n if K%gcd == 0:\n print('Po')\n else:\n print('Im')\n", "def gcd(a,b):\n if b == 0:\n return abs(a)\n else:\n return gcd(b, a%b)\n\nN,K = map(int, input().split())\nA = sorted(list(map(int,input().split())))\n\nIm = 'IMPOSSIBLE'\nPo = 'POSSIBLE'\n\nif max(A) < K:\n print(Im)\nelse:\n for i in range(N):\n if i == 0:\n tmp = gcd(A[i], 0)\n else:\n tmp = gcd(A[i],tmp)\n if tmp == 1:\n break\n if K%tmp == 0:\n print(Po)\n else:\n print(Im)\n"] | ['Runtime Error', 'Accepted'] | ['s296423971', 's369962804'] | [14252.0, 14252.0] | [77.0, 101.0] | [425, 458] |
p03651 | u210440747 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ["from functools import reduce, gcd\n\ndef main():\n n, k = map(int, input().split())\n la = list(map(int, input().split()))\n if max(la) > k and (max(la) - k) % (reduce(gcd, la)) == 0:\n print('POSSIBLE')\n else:\n print('IMPOSSIBLE')\n \nif __name__=='__main__':\n main()", "#!/usr/bin/python3\n# -*- coding:utf-8 -*-\n\nfrom functools import reduce\n\ndef calc_gcd(a, b):\n if a > b:\n a, b = b, a\n while b % a:\n a, b = b % a, a\n return a\n\ndef main():\n n, k = map(int, input().split())\n la = list(map(int, input().split()))\n if max(la) >= k and k % (reduce(calc_gcd, la)) == 0:\n print('POSSIBLE')\n else:\n print('IMPOSSIBLE')\n \nif __name__=='__main__':\n main()\n\n"] | ['Runtime Error', 'Accepted'] | ['s707537148', 's934367702'] | [3572.0, 14596.0] | [22.0, 65.0] | [272, 401] |
p03651 | u225388820 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['def gcd(a,b):\n while b!=0:\n a,b=b,a%b\n return a\n\nn,k=map(int,input().split())\na=list(map(int,input().split()))\nfor i in range(1,n):\n a[0]=gcd(a[0],a[i])\nif k%a[0]==0 and k-a[0]<=max(a):\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")', 'def gcd(a,b):\n while b!=0:\n a,b=b,a%b\n return a\n\nn,k=map(int,input().split())\na=list(map(int,input().split()))\nx=max(a)\nfor i in range(1,n):\n a[0]=gcd(a[0],a[i])\nif k%a[0]==0 and k<=x:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")'] | ['Wrong Answer', 'Accepted'] | ['s509032943', 's176625727'] | [14100.0, 14096.0] | [81.0, 79.0] | [253, 252] |
p03651 | u227888331 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['def gcd(a, b):\n if (b == 0):\n return a\n return gcd(b, a % b)\n\ninput1 = list(map(int,input("").split(" ")))\nA = list(map(int,input("").split(" ")))\nN = input1[0]\nK = input1[1]\nA.sort()\nif K in A:\n\tflag = True\nelif K > max(A):\n\tflag = False\nelse:\n\ttemp = A[0]\n\tfor i in range(1,N):\n\t\ttemp = gcd(temp,A[i])\n\tif K % G == 0:\n\t\tflag = True\n\telse:\n\t\tflag = False\n\t\t\t\nif flag==True:\n\tprint(\'POSSIBLE\')\nelse:\n\tprint(\'IMPOSSIBLE\')', 'input1 = list(map(int,input("").split(" ")))\nA = list(map(int,input("").split(" ")))\nN = input1[0]\nK = input1[1]\n\nflag = True\nfor i in range(N-3):\n\tif abs(A[i]-A[i+1]) != abs(A[i+2]-A[i+1]):\n\t\tflag = False\n\t\tbreak\n\nif flag==True:\n\tprint(POSSIBLE)\nelse:\n\tprint(IMPOSSIBLE)', 'def gcd(a, b):\n if (b == 0):\n return a\n return gcd(b, a % b)\n\ninput1 = list(map(int,input("").split(" ")))\nA = list(map(int,input("").split(" ")))\nN = input1[0]\nK = input1[1]\n\ntemp = A[0]\nfor i in range(1,N):\n\ttemp = gcd(temp,A[i])\n\nif K <= max(A) and K % G == 0:\n\tprint(\'POSSIBLE\')\nelse:\n\tprint(\'IMPOSSIBLE\')', 'input1 = list(map(int,input("").split(" ")))\nA = list(map(int,input("").split(" ")))\nN = input1[0]\nK = input1[1]\n\nflag = true\nfor i in range(N-3):\n\tif abs(A[i]-A[i+1]) != abs(A[i+2]-A[i+1]):\n\t\tflag = false\n\t\tbreak\n\nif flag:\n\tprint(POSSIBLE)\nelse:\n\tprint(IMPOSSIBLE)', 'input1 = list(map(int,input("").split(" ")))\nA = list(map(int,input("").split(" ")))\nN = input1[0]\nK = input1[1]\nA.sort()\nif K in A:\n\tflag = True\nelif K > max(A):\n\tflag = False\nelse:\n\tflag = False\n\tfor i in range(N-3):\n\t\tif abs(A[i]-A[i+1])%2 | abs(A[i+2]-A[i+1])%2 != 0:\n\t\t\tflag = True\n\t\t\tbreak\n\nif flag==True:\n\tprint(\'POSSIBLE\')\nelse:\n\tprint(\'IMPOSSIBLE\')', 'input1 = list(map(int,input("").split(" ")))\nA = list(map(int,input("").split(" ")))\nN = input1[0]\nK = input1[1]\n\nif K in A:\n\tflag = True\nelif K > max(A):\n\tflag = False\nelse\n\tflag = True\n\tfor i in range(N-3):\n\t\tif abs(A[i]-A[i+1]) != abs(A[i+2]-A[i+1]):\n\t\t\tflag = False\n\t\t\tbreak\n\t\t\t\nif flag==True:\n\tprint(\'POSSIBLE\')\nelse:\n\tprint(\'IMPOSSIBLE\')', 'def gcd(a, b):\n if (b == 0):\n return a\n return gcd(b, a % b)\n\n def gcd()\n\ninput1 = list(map(int,input("").split(" ")))\nA = list(map(int,input("").split(" ")))\nN = input1[0]\nK = input1[1]\nA.sort()\nif K in A:\n\tflag = True\nelif K > max(A):\n\tflag = False\nelse:\n\ttemp = A[0]\n\tfor i in range(1,N):\n\t\ttemp = gcd(temp,A[i])\n\tif K % G == 0:\n\t\tflag = True\n\telse:\n\t\tflag = False\n\t\t\t\nif flag==True:\n\tprint(\'POSSIBLE\')\nelse:\n\tprint(\'IMPOSSIBLE\')', 'def gcd(a, b):\n if (b == 0):\n return a\n return gcd(b, a % b)\n\ninput1 = list(map(int,input("").split(" ")))\nA = list(map(int,input("").split(" ")))\nN = input1[0]\nK = input1[1]\n\ntemp = A[0]\nfor i in range(1,N):\n\ttemp = gcd(temp,A[i])\n\nif K <= max(A) and K % temp == 0:\n\tprint(\'POSSIBLE\')\nelse:\n\tprint(\'IMPOSSIBLE\')'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s167791703', 's230181235', 's251603649', 's534578367', 's593448207', 's676846099', 's716023395', 's928148599'] | [14224.0, 14252.0, 14224.0, 14224.0, 14252.0, 2940.0, 3060.0, 14252.0] | [129.0, 89.0, 87.0, 42.0, 102.0, 18.0, 17.0, 85.0] | [433, 271, 322, 265, 357, 343, 445, 325] |
p03651 | u263830634 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ["N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\ndef gcd(x, y):\n if x > y:\n x, y = y, x\n if y % x == 0:\n return x\n y = y % x\n return gcd(x, y)\n\nn = A[0]\nfor i in A:\n n = gcd(n, i)\n\nflag = False\nfor i in A:\n if i > K and (i - K) % n == 0:\n flag = True\n break\n else:\n pass\n\nif flag:\n print ('POSSUBLE')\nelse:\n print ('IMPOSSIBLE') ", "N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\ndef gcd(x, y):\n if x > y:\n x, y = y, x\n if y % x == 0:\n return x\n y = y % x\n return gcd(x, y)\n\nn = A[0]\nfor i in A:\n n = gcd(n, i)\n\nflag = False\nfor i in A:\n if i >= K and (i - K) % n == 0:\n flag = True\n break\n else:\n pass\n\nif flag:\n print ('POSSIBLE')\nelse:\n print ('IMPOSSIBLE') "] | ['Wrong Answer', 'Accepted'] | ['s801391912', 's566176634'] | [14224.0, 14100.0] | [69.0, 64.0] | [412, 413] |
p03651 | u266014018 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ["def main():\n import sys\n\n def input(): return sys.stdin.readline().rstrip()\n\n def gcd(x,y):\n r = x%y\n if r==0:\n return y\n return gcd(y, r)\n\n n, k =map(int, input().split())\n a = list(map(int, input().split()))\n a.sort(reverse=True)\n c = a[0]\n for i in range(n):\n c = gcd(a[i], c)\n if k%c == 0:\n print('POSSIBLE')\n else:\n print('IMPOSSIBLE')\n \n\n \nif __name__ == '__main__':\n main()", "def main():\n import sys\n\n def input(): return sys.stdin.readline().rstrip()\n\n def gcd(x,y):\n r = x%y\n if r==0:\n return y\n return gcd(y, r)\n\n n, k =map(int, input().split())\n a = list(map(int, input().split()))\n a.sort(reverse=True)\n c = a[0]\n for i in range(n):\n c = gcd(a[i], c)\n if k%c == 0 and k <= a[0]:\n print('POSSIBLE')\n else:\n print('IMPOSSIBLE')\n \n\n \nif __name__ == '__main__':\n main()"] | ['Runtime Error', 'Accepted'] | ['s836208974', 's989512574'] | [8920.0, 19788.0] | [22.0, 77.0] | [456, 486] |
p03651 | u277429554 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ["n, k = map(int, input().split())\na = list(map(int, input().split())) \na.sort()\na.reverse() \nx = a[0] \nfor i in range (1, N):\n while a[i] != 0:\n x , a[i] = a[i] , x % a[i]\nif K > a[0]:\n print('IMPOSSIBLE')\nelse:\n print('POSSIBLE' if K%x == 0 else 'IMPOSSIBLE')", "N,K = map(int, input().split())\nA = list(map(int, input().split())) \nA.sort()\nA.reverse() \nx = A[0] \nfor i in range (1, N):\n while A[i] != 0:\n x , A[i] = A[i] , x % A[i]\nif K > A[0]:\n print('IMPOSSIBLE')\nelse:\n print('POSSIBLE' if K%x == 0 else 'IMPOSSIBLE')"] | ['Runtime Error', 'Accepted'] | ['s920990644', 's827136950'] | [19708.0, 19948.0] | [64.0, 111.0] | [267, 266] |
p03651 | u283229916 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['def main():\n import math\n n,k=map(int,input().split(" "))\n a=map(int,input().split(" "))\n g=a[0]\n m=max(a)\n for i in range(n):\n g=math.gcd(g,a[i])\n if k % g==0 and k<=m:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")\n\nmain()', 'def gcd(a,b):\n if a==0: return b\n else: return gcd(b%a,a)\n\ndef main():\n n,k=map(int,input().split(" "))\n a=list(map(int,input().split(" ")))\n g=a[0]\n m=a[0]\n for e in a:\n g=gcd(g,e)\n if m<e: m=e\n if k % g==0 and k<=m:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")\n\nmain()'] | ['Runtime Error', 'Accepted'] | ['s401045075', 's664016091'] | [11052.0, 14224.0] | [26.0, 71.0] | [269, 327] |
p03651 | u297109012 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['def factor(N):\n ret = []\n i = 2\n while N > 1:\n if N % i == 0:\n ret.append(i)\n N //= i\n else:\n i += 1\n return ret\n\nfrom collections import Counter\n\n\ndef solve(N, K, As):\n if K > max(As):\n return "IMPOSSIBLE"\n factors = [Counter(factor(a)) for a in As]\n\nif __name__ == "__main__":\n N, K = tuple(map(int, input().split(" ")))\n As = list(map(int, input().split(" ")))\n print(solve(N, K, As))\n', 'def factor(N):\n ret = []\n i = 2\n while N > 1:\n if N % i == 0:\n ret.append(i)\n N //= i\n else:\n i += 1\n return ret\n\n\nassert (factor(4) == [2, 2])\nassert (factor(2) == [2])\nassert (factor(3) == [3])\nassert (factor(10) == [2, 5])\n\nfrom collections import Counter\n\n\ndef solve(N, K, As):\n if K > max(As):\n return "IMPOSSIBLE"\n iter = Counter(factor(min(As)))\n for a in As:\n for k, v in iter.items():\n if a % k != 0:\n iter[k] = 0\n else:\n count = 0\n kk = k\n while a % kk == 0:\n kk *= k\n count += 1\n iter[k] = min(v, count)\n\n if all([v == 0 for v in iter.values()]):\n return "POSSIBLE"\n else:\n d = 1\n for k, v in iter.items():\n if v != 0:\n d *= k ** v\n if K % d == 0:\n return "POSSIBLE"\n return "IMPOSSIBLE"\n\n\nif __name__ == "__main__":\n N, K = tuple(map(int, input().split(" ")))\n As = list(map(int, input().split(" ")))\n print(solve(N, K, As))\n'] | ['Wrong Answer', 'Accepted'] | ['s814880736', 's856027241'] | [14636.0, 14628.0] | [2104.0, 325.0] | [469, 1137] |
p03651 | u368796742 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['n,k = map(int,input().split())\nl = sorted(list(map(int,input().split())))\nif l[-1] > k:\n print("IMPOSSIBLE")\n exit()\nx = l[0]\nfor i in range(1,n):\n if l[i]%x:\n print("POSSIBLE")\n exit()\n\nif k in l:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")', 'import math\nn,k = map(int,input().split())\nl = list(map(int,input().split()))\nif max(l) < k:\n print("IMPOSSIBLE")\n exit()\n\nx = l[0]\nfor i in l:\n x = math.gcd(x,i)\n\nif k%x:\n print("IMPOSSIBLE")\nelse:\n print("POSSIBLE")\n\n'] | ['Wrong Answer', 'Accepted'] | ['s535297264', 's046165628'] | [19960.0, 20304.0] | [81.0, 64.0] | [272, 234] |
p03651 | u404676457 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ["import sys\nn, k = map(int, input().split())\na = list(map(int, input().split()))\n\n\nif a[-1] < k:\n print('IMPOSSIBLE')\n sys.exit(0)\n\nseta = set(a)\nif k in seta:\n print('POSSIBLE')\n sys.exit(0)\nchange = True\nwhile change:\n change = False\n setb = seta.copy()\n sorteda = sorted(seta)\n for i in range(1, len(sorteda)):\n setb.add(sorteda[i] % sorteda[0])\n if setb != seta:\n change = True\n seta = setb\n\nmini = sorted(seta)[1]\na.sort()\na.reverse()\n\nfor i in a:\n if (k - i) % mini == 0:\n print('POSSIBLE')\n sys.exit(0)\nprint('IMPOSSIBLE')", "n, k = map(int, input().split())\na = list(map(int, input().split()))\ndef f(l, s):\n return s if l % s == 0 else f(s, l % s)\n\nz = f(max(a), min(a))\nfor i in a:\n z = f(i, z)\nif max(a) >= k and k % z == 0:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')"] | ['Runtime Error', 'Accepted'] | ['s077927325', 's521590636'] | [14480.0, 14224.0] | [102.0, 71.0] | [593, 259] |
p03651 | u445624660 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['\n\n\n\n\n\n\n\n\nn, k = map(int, input().split())\narr = sorted(list(set(list(map(int, input().split())))))\nn = len(arr)\nif arr[0] == 1:\n print("POSSIBLE")\n exit()\nif n < 2 or arr[-1] < k:\n print("IMPOSSIBLE")\n exit()\n\n\ndef gcd(a, b):\n if a > b:\n a, b = b, a\n while a > 0:\n a, b = b % a, a\n return b\n\n\ntmp = gcd(arr[0], arr[1])\nflag = True\nfor i in range(2, n):\n g = gcd(tmp, arr[i])\n if g != tmp:\n flag = False\nif flag:\n print("IMPOSSIBLE")\n exit()\nodds, evens = False, False\nfor a in arr:\n if a % 2 == 0:\n evens = True\n else:\n odds = True\nif evens and odds:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n', '\n\n\n\n\n\n\n\n\n\nn, k = map(int, input().split())\narr = sorted(list(set(list(map(int, input().split())))))\nn = len(arr)\nif arr[0] == 1 or k in arr:\n print("POSSIBLE")\n exit()\nif n < 2 or arr[-1] < k:\n print("IMPOSSIBLE")\n exit()\n\n\ndef gcd(a, b):\n if a > b:\n a, b = b, a\n while a > 0:\n a, b = b % a, a\n return b\n\n\ntmp = gcd(arr[0], arr[1])\n\nif tmp == 1:\n print("POSSIBLE")\n exit()\nflag = True\nfor i in range(2, n):\n g = gcd(tmp, arr[i])\n if g != tmp or g == 1:\n flag = False\n break\n\nif flag and k % tmp != 0:\n print("IMPOSSIBLE")\n exit()\n\neven_flag, odd_flag = False, False\nfor a in arr:\n if a % 2 == 1:\n odd_flag = True\n else:\n even_flag = True\n\n\nif odd_flag:\n if k % 2 == 0 and not even_flag:\n print("IMPOSSIBLE")\n else:\n print("POSSIBLE")\n exit()\n\n\nif k % 2 == 1:\n print("IMPOSSIBLE")\nelse:\n print("POSSIBLE")\n'] | ['Wrong Answer', 'Accepted'] | ['s370220708', 's568810080'] | [14480.0, 14480.0] | [133.0, 94.0] | [1310, 1792] |
p03651 | u474270503 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['N, K=map(int, input().split())\nA=list(sorted(list(map(int, input().split())), returned=True))\n\ndef gcd(a,b):\n\twhile b:\n\t\ta,b=b,a%b\n\treturn a\n\nif K>max(A):\n\tprint("IMPOSSIBLE")\n\texit(0)\n\ng=gcd(A[0],A[1])\nfor i in range(2,len(A)):\n\tg=gcd(g,A[i])\n\nprint("POSSIBLE" if K%g==0 else "IMPOSSIBLE")', 'N, K=map(int, input().split())\nA=list(sorted(list(map(int, input().split())), reverse=True))\n\ndef gcd(a,b):\n\twhile b:\n\t\ta,b=b,a%b\n\treturn a\n\ng=A[0]\nfor i in range(1,len(A)):\n\tg=gcd(g,A[i])\n\nprint("POSSIBLE" if K%g==0 and K<=max(A) else "IMPOSSIBLE")'] | ['Runtime Error', 'Accepted'] | ['s439317412', 's974609873'] | [14224.0, 14224.0] | [44.0, 116.0] | [290, 249] |
p03651 | u518042385 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['n,k=map(int,input().split())\nl=list(map(int,input().split()))\ndef gcd(n,m):\n a=max(n,m)\n b=min(n,m)\n while b!=0:\n a,b=b,a%b\n return a\ng=l[0]\nmax=l[0]\nfor i in range(1,1+n-1):\n g=gcd(g,l[i])\n if max<l[i]:\n max=l[i]\nif max<k:\n print("POSSIBLE")\nelif max==k:\n print("POSSIBLE")\nelse:\n if k%g==0:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")', 'n,k=map(int,input().split())\nl=list(map(int,input().split()))\ndef gcd(n,m):\n if n>m:\n a=n\n b=m\n else:\n a=m\n b=n\n while b!=0:\n a,b=b,a%b\n return a\ng=l[0]\nmax=l[0]\nfor i in range(1,1+n-1):\n g=gcd(g,l[i])\n if max<l[i]:\n max=l[i]\nif max<k:\n print("IMPOSSIBLE")\nelif max==k:\n print("POSSIBLE")\nelse:\n if k%g==0:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")\n'] | ['Runtime Error', 'Accepted'] | ['s206189211', 's499029778'] | [14236.0, 14224.0] | [42.0, 84.0] | [361, 388] |
p03651 | u535423069 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['\n# Created: Mon Mar 23 15:10:04 UTC 2020\nimport sys\n \nstdin = sys.stdin\ninf = 1 << 60\nmod = 1000000007\n \nni = lambda: int(ns())\nnin = lambda y: [ni() for _ in range(y)]\nna = lambda: list(map(int, stdin.readline().split()))\nnan = lambda y: [na() for _ in range(y)]\nnf = lambda: float(ns())\nnfn = lambda y: [nf() for _ in range(y)]\nnfa = lambda: list(map(float, stdin.readline().split()))\nnfan = lambda y: [nfa() for _ in range(y)]\nns = lambda: stdin.readline().rstrip()\nnsn = lambda y: [ns() for _ in range(y)]\nncl = lambda y: [list(ns()) for _ in range(y)]\nnas = lambda: stdin.readline().split()\n\nimport numpy as np\n\nn, k = na()\na = np.array(na())\n\ng = np.gcd.reduce(a)\nm = np.amax(a)\nif g == 1 and k <= m:\n print("Yes")\nelif k % g == 0 and k <= m:\n print("Yes")\nelse:\n print("No")', '\n# Created: Sun Mar 22 17:06:57 UTC 2020\nimport sys\n \nstdin = sys.stdin\ninf = 1 << 60\nmod = 1000000007\n \nni = lambda: int(ns())\nnin = lambda y: [ni() for _ in range(y)]\nna = lambda: list(map(int, stdin.readline().split()))\nnan = lambda y: [na() for _ in range(y)]\nnf = lambda: float(ns())\nnfn = lambda y: [nf() for _ in range(y)]\nnfa = lambda: list(map(float, stdin.readline().split()))\nnfan = lambda y: [nfa() for _ in range(y)]\nns = lambda: stdin.readline().rstrip()\nnsn = lambda y: [ns() for _ in range(y)]\nncl = lambda y: [list(ns()) for _ in range(y)]\nnas = lambda: stdin.readline().split()\n\nn, k = na()\na = na()\n\ndef gcd(m, n):\n if n == 0:\n return m\n else:\n return gcd(n, m % n)\n\ng = a[0]\nfor i in range(n):\n g = gcd(g, a[i])\n\nm = max(a)\nif g == 1 and k <= m:\n print("POSSIBLE")\nelif k % g == 0 and k <= m:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")'] | ['Runtime Error', 'Accepted'] | ['s175530258', 's192421405'] | [23112.0, 14252.0] | [180.0, 88.0] | [860, 960] |
p03651 | u555811857 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['# -*- coding: utf-8 -*-\nN, A = map(int, input().split())\ntmp = input()\nary = [int(a) for a in tmp.split()]\n\nmaximum = max(ary)\n\n\ndef gcd(a, b):\n if a < b:\n a, b = b, a\n if b == 0:\n return a\n c = a % b\n return gcd(b, c)\n\n\ng = None\nfor a in ary:\n if g is None:\n g = a\n continue\n g = gcd(g, a)\n print(g)\n\nif A % g == 0 and A <= maximum:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n', '# -*- coding: utf-8 -*-\nN, M = map(int, input().split())\narys = []\nfor i in range(N):\n tmp = input()\n ary = [int(a) - 1 for a in tmp.split()]\n arys.append(ary)\n\n\ns = set([i for i in range(M)])\nmin_num = None\nwhile len(s) > 0:\n dic = {}\n for ary in arys:\n del_i = None\n for i, a in enumerate(ary):\n if a in s:\n if a not in dic:\n dic[a] = 1\n else:\n dic[a] += 1\n break\n del_i = i\n if del_i is not None:\n ary = ary[del_i + 1:]\n max_v = None\n max_k = None\n for k, v in dic.items():\n if max_v is None or max_v < v:\n max_v = v\n max_k = k\n if min_num is None or min_num > max_v:\n min_num = max_v\n s.remove(max_k)\nprint(min_num)\n', '# -*- coding: utf-8 -*-\nN, A = map(int, input().split())\ntmp = input()\nary = [int(a) for a in tmp.split()]\n\nmaximum = max(ary)\n\n\ndef gcd(a, b):\n if a < b:\n a, b = b, a\n if b == 0:\n return a\n c = a % b\n return gcd(b, c)\n\n\ng = None\nfor a in ary:\n if g is None:\n g = a\n continue\n g = gcd(g, a)\n\nif A % g == 0 and A <= maximum:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s141945092', 's557624032', 's837104253'] | [15192.0, 2090904.0, 15320.0] | [149.0, 2230.0, 86.0] | [435, 823, 422] |
p03651 | u557437077 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['# import math\nimport fractions\nn, k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\na = sorted(a)\ndiv = fractions.gcd(a[0], a[1])\nfor i in range(2, n):\n div = fractions.gcd(a[i], a[i-1])\nif k % div == 0 and k <= a[-1]:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n', '# import math\nimport fractions\nn, k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\na = sorted(a)\nif n == 1:\n if a[0] == k:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")\ndiv = fractions.gcd(a[0], a[1])\nfor i in range(n):\n if a[i] == k:\n print("POSSIBLE")\n exit()\n elif i >= 2:\n div = fractions.gcd(a[i], a[i-1])\nif k % div == 0 and k <= a[-1]:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n', '# import math\nimport fractions\nn, k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\na = sorted(a)\n\nif n == 1:\n if a[0] == k:\n print("POSSIBLE")\n else:\n print("IMPOSSIBLE")\ndiv = a[0]\nfor i in range(1, n):\n div = fractions.gcd(div, a[i])\n\nif k % div == 0 and k <= a[-1]:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n', '# import math\n# import fractions\ndef gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n\n\nn, k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\na = sorted(a)\n\ndiv = a[0]\nfor i in range(1, n):\n div = gcd(div, a[i])\n\nif k % div == 0 and k <= a[-1]:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s044549575', 's057690798', 's792374775', 's610253984'] | [16280.0, 16048.0, 16276.0, 14252.0] | [195.0, 208.0, 134.0, 130.0] | [475, 645, 546, 344] |
p03651 | u620480037 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['N,K=map(int,input().split())\n\nA=list(map(int,input().split()))\n\ndef gcd(a,b):\n x=max(a,b)\n y=min(a,b)\n while x%y!=0:\n x,y=y,x%y\n return y\n \nNum=A[0]\n\nfor i in range(N):\n Num=gcd(Num,A[i])\n \nif K%Num==0:\n if K>Num:\n print("IMPOSSIBLE")\n else:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")', 'N,K=map(int,input().split())\n\nA=list(map(int,input().split()))\n\ndef gcd(a,b):\n x=max(a,b)\n y=min(a,b)\n while x%y!=0:\n x,y=y,x%y\n return y\n \nNum=A[0]\n\nfor i in range(N):\n Num=gcd(Num,A[i])\n \nif K%Num==0:\n if K>max(A):\n print("IMPOSSIBLE")\n else:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")'] | ['Wrong Answer', 'Accepted'] | ['s228596089', 's267193002'] | [14224.0, 14224.0] | [104.0, 105.0] | [338, 341] |
p03651 | u635182517 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32\nType "copyright", "credits" or "license()" for more information.\n>>> \n======= RESTART: C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py =======\nTraceback (most recent call last):\n File "C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py", line 13, in <module>\n print(gcd_list(a))\n File "C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py", line 9, in gcd_list\n for i in range(len(n)):\nNameError: name \'n\' is not defined\n>>> \n======= RESTART: C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py =======\nNone\n\n======= RESTART: C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py =======\n6\n\n======= RESTART: C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py =======\n6\n\n======= RESTART: C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py =======\n3\n\n======= RESTART: C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py =======\n3 7\n9 3 4\nTraceback (most recent call last):\n File "C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py", line 19, in <module>\n if A[-1] > k and (A[-1] - k) % gcd_lst(A) == 0:\nNameError: name \'gcd_lst\' is not defined\n>>> \n======= RESTART: C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py =======\n3 7\n9 3 4\nPOSSIBLE\n>>> \n======= RESTART: C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py =======\n3 5\n6 9 3\nIMPOSSIBLE\n>>> \n======= RESTART: C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py =======\n4 11\n11 3 7 15\nPOSSIBLE\n>>> \n======= RESTART: C:\\Users\\mori-\\OneDrive\\Desktop\\Python\\abc\\tenka1a.py =======\n5 12\n10 2 8 6 4\nIMPOSSIBLE\n>>> ', "def gcd(a, b):\n if b == 0:\n return a\n else:\n return gcd(b, a % b)\n\ndef gcd_list(a):\n x = a[0]\n for i in range(len(a)):\n x = gcd(a[i], x)\n return x\n \n\nn, k = map(int, input().split())\nA = list(map(int, input().split()))\n\nans = 'IMPOSSIBLE'\nA.sort()\nif A[-1] >= k and (A[-1] - k) % gcd_list(A) == 0:\n ans = 'POSSIBLE'\n\nprint(ans)\n"] | ['Runtime Error', 'Accepted'] | ['s595810542', 's940599560'] | [2940.0, 14480.0] | [18.0, 107.0] | [1601, 375] |
p03651 | u637175065 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ["import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\n\n\ndef main():\n N,K = LI()\n a = LI()\n if max(a) < K:\n return 'IMPOSSIBLE'\n if K in a:\n return 'POSSIBLE'\n t = a[0]\n \n # t = math.gcd(a[i], t)\n if t <= 1:\n return 'POSSIBLE'\n for c in a:\n if (c > K) and (((c-K) % t) == 0):\n return 'POSSIBLE'\n\n return 'IMPOSSIBLE'\n\n\nprint(main())\n\n\n\n", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\n\n\ndef main():\n N,K = LI()\n a = LI()\n if max(a) < K:\n return 'IMPOSSIBLE'\n if K in a:\n return 'POSSIBLE'\n t = a[0]\n for c in a[1:]:\n t = math.gcd(a[i], t)\n if t <= 1:\n return 'POSSIBLE'\n for c in a:\n if (c > K) and (((c-K) % t) == 0):\n return 'POSSIBLE'\n\n return 'IMPOSSIBLE'\n\n\nprint(main())\n\n\n\n", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\n\ndef gcd(a,b):\n while b>0:\n a,b = b,a\n b %= a\n return a\n\ndef main():\n N,K = LI()\n a = LI()\n if max(a) < K:\n return 'IMPOSSIBLE'\n if K in a:\n return 'POSSIBLE'\n t = a[0]\n for c in a[1:]:\n t = gcd(c, t)\n if t <= 1:\n return 'POSSIBLE'\n for c in a:\n if (c > K) and (((c-K) % t) == 0):\n return 'POSSIBLE'\n\n return 'IMPOSSIBLE'\n\n\nprint(main())\n\n\n\n"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s278605785', 's340945711', 's132053746'] | [16648.0, 16652.0, 16644.0] | [340.0, 91.0, 107.0] | [891, 884, 959] |
p03651 | u707870100 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['# -*- coding: utf-8 -*-\n#AGC014A\nimport sys\n#import collections\n\n#n= int(input())\n\ntmp = input().split()\nn,k = list(map(lambda a: int(a), tmp))\n\ntmp = input().split()\na = list(map(lambda a: int(a), tmp))\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\nmaxa=a[0]\ntmp=a[0]\nfor i in range(1,n):\n\tmaxa=max(maxa,a[i])\n\ttmp=gcd(tmp, a[i])\n\nif(k<=m)and(k%tmp ==0):\n\tprint("POSSIBLE")\nelse:\n\tprint("IMPOSSIBLE")\n\n#print(maxa)\n#print(tmp)\n\n\n', '# -*- coding: utf-8 -*-\n#AGC014A\nimport sys\n#import collections\n\n#n= int(input())\n\ntmp = input().split()\nn,k = list(map(lambda a: int(a), tmp))\n\ntmp = input().split()\na = list(map(lambda a: int(a), tmp))\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\nmaxa=a[0]\ntmp=a[0]\nfor i in range(1,n):\n\tmaxa=max(maxa,a[i])\n\ttmp=gcd(tmp, a[i])\n\nif(k<=maxa)and(k%tmp ==0):\n\tprint("POSSIBLE")\nelse:\n\tprint("IMPOSSIBLE")\n\n#print(maxa)\n#print(tmp)\n\n\n'] | ['Runtime Error', 'Accepted'] | ['s012065384', 's335507032'] | [14228.0, 14228.0] | [104.0, 109.0] | [451, 454] |
p03651 | u785205215 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['def gcd(a,b):\n while b > 0:\n a, b = b, a%b\n return a\n\ndef gcd_list(lst):\n a = gcd(lst[0],lst[1])\n i=2\n while a > 0 and i<len(lst):\n a = gcd(a, lst[i])\n if a == 1:\n return 1\n break\n i+=1\n return a\n \nn, k = (int(i) for i in input().split())\nprint(n,k)\na = list(int(i) for i in input().split()) \nprint(a)\nmaxA=max(a)\n\nif maxA >= k and gcd_list(a)%k == 0:\n print("POSSIBLE")\nelif k in a:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n ', '# coding: utf-8\n# Here your code !\ndef gcd(a,b):\n while b > 0:\n a, b = b, a%b\n return a\n\ndef gcd_list(lst):\n a = gcd(lst[0],lst[1])\n i=2\n while a > 0 and i<len(lst):\n a = gcd(a, lst[i])\n if a == 1:\n return 1\n break\n i+=1\n return a\n \nn, k = (int(i) for i in input().split())\na = list(int(i) for i in input().split()) \nmaxA=max(a)\n\nif maxA >= k and gcd_list(a)%k == 0:\n print("POSSIBLE")\nelif k in a:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n ', 'def gcd(a,b):\n while b > 0:\n a, b = b, a%b\n return a\n\ndef gcd_list(lst):\n g = lst[0]\n for i in range(1,len(lst)):\n g = gcd(g,lst[i])\n return g\n \nn, k = (int(i) for i in input().split())\na = list(int(i) for i in input().split()) \n\nmaxA=max(a)\n\nif (k <= maxA and k%gcd_list(a) == 0) or (k in a):\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n '] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s027711186', 's252986215', 's468824297'] | [14484.0, 14096.0, 14480.0] | [92.0, 83.0, 76.0] | [515, 530, 383] |
p03651 | u785578220 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['a,b=map(int, input().split())\nx = list(map(int, input().split()))\nx.sort()\np=0\nq=0\ny=0\nfor i in x:\n if p == 1 and q == 1:break\n if i == b:\n y=1\n if i%2==0:\n p=1\n else:\n q=1\nif b<=x[-1]:\n if((b%2==0 and(p*q ==0))or(p==1 and q==1)):\n m="POSSIBLE"\nif y==1:m="POSSIBLE"\nelse:m="IMPOSSIBLE" \nprint(m)', 'N,K= map(int, input().split())\nx = list(map(int, input().split()))\nx = list(set(x))\nx.sort()\nt = max(x)\ny = x[0]\ns = [1000000000000]\no=0\nif x[0] == K:o=1\nfor i in range(1,len(x)):\n s.append(x[i]-x[i-1])\n if x[i] == K:o = 1\ns.sort()\nm = min(y,s[0])\nif (t>= K and K%m==0) or o==1:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n\n'] | ['Wrong Answer', 'Accepted'] | ['s265995951', 's072660845'] | [14252.0, 14224.0] | [76.0, 173.0] | [338, 338] |
p03651 | u800610991 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['a,b = map(int,input().split())\nnn = list(map(int,input().split()))\nnnn = nn.copy()\n\nif b in nn:\n print(\'POSSIBLE\')\n exit()\nif b > max(nn):\n print("IMPOSSIBLE")\n exit()\nlen_nn = [0]\nwhile 1:\n lnn = len(nn)\n for x in range(len(nn)):\n for y in range(len(nn) - x -len_nn):\n y = len(nn)-y-1\n #print(x,y)\n num = abs(x-nn[y])\n if num == b or num == 1:\n print(\'POSSIBLE\')\n exit()\n elif num not in nn and num != 0:\n nn.append(num)\n len_nn += lnn\n if nn == nnn:\n print(\'IMPOSSIBLE\')\n exit()\n', 'a,b = map(int,input().split())\nnn = list(map(int,input().split()))\nnnn = nn.copy()\nif b in nn:\n print(\'POSSIBLE\')\n exit()\nif b > max(nn):\n print("IMPOSSIBLE")\n exit()\n\nwhile 1:\n for x in range(len(nn)):\n for y in range(len(nn) - x):\n y = len(nn)-y-1\n #print(x,y)\n num = abs(x-nn[y])\n if num == b:\n print(\'POSSIBLE\')\n exit()\n elif num not in nn:\n nn.append(num)\n if nn == nnn:\n print(\'IMPOSSIBLE\')\n exit()\n', 'def ri(): return int(input())\ndef rli(): return list(map(int, input().split()))\ndef ris(): return list(input())\ndef pli(a): return "".join(list(map(str, a)))\n\nn,k = rli()\nA = rli()\n\ndef gcd(a,b):\n while b:\n a, b = b, a%b\n return a\n\nb = 0\nfor a in A:\n b = gcd(a, b)\n\nif k%b or k > max(A):\n print(\'IMPOSSIBLE\')\nelse:\n print(\'POSSIBLE\')\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s302692941', 's664938102', 's810333929'] | [14096.0, 14252.0, 14480.0] | [46.0, 2104.0, 66.0] | [626, 544, 357] |
p03651 | u814986259 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['import collections\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\nif K in A:\n print("POSSIBLE")\nelse:\n diff = collections.defaultdict(int)\n A.sort()\n idx = N - 1\n if K > A[-1]:\n print("IMPOSSIBLE")\n else:\n for i in range(N-1):\n if A[i] > K and idx == N - 1:\n idx = i\n diff[A[i+1] - A[i]] += 1\n\n diff_list = list(diff.keys())\n if 1 in diff_list:\n print("POSSIBLE")\n print("hoge")\n exit(0)\n diff_list.sort()\n\n for i in range(idx, N):\n for j in range(len(diff_list)):\n if (K - A[i]) % diff_list[j] == 0:\n print("POSSIBLE")\n exit(0)\n print("IMPOSSIBLE")\n', 'import collections\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\nif K in A:\n print("POSSIBLE")\n exit(0)\nelse:\n diff = collections.defaultdict(int)\n A.sort()\n idx = N - 1\n if K > A[-1]:\n print("IMPOSSIBLE")\n exit(0)\n else:\n for i in range(N-1):\n if A[i] > K and idx == N - 1:\n idx = i\n if A[i+1] - A[i] != 0:\n diff[A[i+1] - A[i]] += 1\n\n diff_list = list(diff.keys())\n if 1 in diff_list:\n print("POSSIBLE")\n exit(0)\n else:\n diff_list.sort()\n for i in range(idx, N):\n for j in range(len(diff_list)):\n if (K - A[i]) % diff_list[j] == 0:\n print("POSSIBLE")\n exit(0)\n print("IMPOSSIBLE")\n exit(0)\n'] | ['Runtime Error', 'Accepted'] | ['s064925775', 's386067804'] | [14636.0, 14636.0] | [132.0, 1014.0] | [773, 875] |
p03651 | u820351940 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['a, b = map(int, input().split())\narray = list(map(int, input().split()))\nimpossible = "IMPOSSIBLE"\npossible = "POSSIBLE"\n\nif a == 1:\n if b == array[0]:\n print(possible)\n else:\n print(impossible)\n exit(0)\n\narray.sort()\narray = list(set(array))\n\nbtw = [v1 - v2 for v1, v2 in zip(array[1:], array[0:])]\nn = sorted(btw)[0]\n\nsame = len(set(btw)) == 1 or all([v % n == 0 for v in btw])\n\nif b in array:\n print(possible)\nelif array[-1] < b:\n print(impossible)\nelif same and (b - array[0]) % n == 0:\n print(possible)\nelse:\n print(impossible)\n', 'a, b = map(int, input().split())\narray = list(map(int, input().split()))\nimpossible = "IMPOSSIBLE"\npossible = "POSSIBLE"\n\narray = list(set(array))\n\nif len(array) == 1:\n if b == array[0]:\n print(possible)\n else:\n print(impossible)\n exit(0)\n\narray.sort()\n\nbtw = [v1 - v2 for v1, v2 in zip(array[1:], array[0:])]\nn = sorted(btw)[0]\n\nsame = len(set(btw)) == 1 or all([v % n == 0 for v in btw])\n\nif b in array:\n print(possible)\nelif array[-1] < b:\n print(impossible)\nelif same and (b - array[0]) % n == 0:\n print(possible)\nelse:\n print(impossible)\n'] | ['Runtime Error', 'Accepted'] | ['s586794451', 's494571962'] | [14728.0, 14604.0] | [161.0, 154.0] | [568, 578] |
p03651 | u839537730 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['X, Y, Z = list(map(int, input().split(" ")))\n\nimport numpy as np\n\nABC = []\n\nfor i in range(X+Y+Z):\n ABC.append(list(map(int, input().split(" "))))\n\nABC = sorted(ABC, key=lambda row: row[0]-row[1]) \n\nans = 0\n\nABC_bk = ABC_np[:Y]\nABC_ak = ABC_np[Y:]\n\nfor k in range(Y, Y+Z):\n \n ABC_bk = ABC_bk + ABC_ak[0]\n ABC_ak = ABC_ak.pop(0)\n \n \n before_k = np.asarray(sorted(ABC_bk.tolist(), key=lambda row: row[1]-row[2]))\n after_k = np.asarray(sorted(ABC_ak.tolist(), key=lambda row: row[0]-row[2]) ) \n \n bk_sum = before_k[-Y:].sum(axis=0)[1] + before_k[:-Y].sum(axis=0)[2]\n ak_sum = after_k[-X:].sum(axis=0)[0] + after_k[:-X].sum(axis=0)[2]\n \n tmp = ak_sum + bk_sum\n \n if ans < tmp:\n ans = tmp\n \nprint (ans)', 'N, K = list(map(int, input().split(" ")))\n\nA = list(map(int, input().split(" ")))\n\nans = False\n\nA = sorted(A)\n\nkey = 99999999999999\n \nif A[-1] < K:\n ans = False\n\nelse:\n for i in range(2, A[0]+1):\n key_flag = True\n for a in A:\n if a % i !=0:\n key_flag = False\n break\n \n if key_flag == True:\n key = i\n break\n\n if key_flag == False:\n ans = True\n# print(1)\n elif K % key == 0:\n ans = True\n# print(2)\n else:\n# print(3)\n ans = False \n \nif ans == True:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")'] | ['Runtime Error', 'Accepted'] | ['s115477986', 's213971011'] | [3064.0, 14096.0] | [19.0, 83.0] | [782, 672] |
p03651 | u844789719 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['import math', 'import math\nN, K = [int(_) for _ in input().split()]\nA = [int(_) for _ in input().split()]\ng = A.pop()\nfor a in A:\n g = math.gcd(g, a)', "N, K = [int(_) for _ in input().split()]\nA = [int(_) for _ in input().split()]\n\n\ndef gcd(x, y):\n if x < y:\n return gcd(y, x)\n elif y == 0:\n return x\n else:\n return gcd(y, x % y)\n\n\ng = A[0]\nfor a in A:\n g = gcd(g, a)\nif K <= max(A) and K % g == 0:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')\n"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s070835746', 's770468091', 's060142341'] | [2940.0, 14252.0, 14224.0] | [18.0, 47.0, 98.0] | [11, 137, 332] |
p03651 | u845333844 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['n,k=map(int,input().split())\na=list(map(int,input().split()))\ndef gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\n\nif n==1:\n x=a[0]\nelse:\n x=gcd(a[0],a[1])\n for i in range(2,n):\n x=gcd(x,a[i])\n\nif max(a)>=k and k%g==0:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")', 'n,k=map(int,input().split())\na=list(map(int,input().split()))\ndef gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\n\nif n==1:\n x=a[0]\nelse:\n x=gcd(a[0],a[1])\n for i in range(2,n):\n x=gcd(x,a[i])\n\nif max(a)>=k and k%x==0:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")'] | ['Runtime Error', 'Accepted'] | ['s150419565', 's151371656'] | [14096.0, 14100.0] | [90.0, 89.0] | [292, 292] |
p03651 | u871841829 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nP = "POSSIBLE"\nIP = "IMPOSSIBLE"\n\nA.sort()\n\ndef gcd(a, b):\n if a == 0:\n return b\n else:\n gcd(b, b%a)\n\nt = gcd(A[1], A[0])\nif N <= 2:\n for a in A[2:]:\n t = gcd(t, a)\n\nif K%t == 0 and K <= M:\n print(P)\nelse:\n print(IP)', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nP = "POSSIBLE"\nIP = "IMPOSSIBLE"\n\nM = max(A)\n\ndef gcd(a, b):\n if a == 0:\n return b\n else:\n return gcd(b%a, a)\n\nt = gcd(A[0], A[0])\nif N > 1:\n for a in A[1:]:\n t = gcd(t, a)\n\nif K%t == 0 and K <= M:\n print(P)\nelse:\n print(IP)'] | ['Runtime Error', 'Accepted'] | ['s583946934', 's963585959'] | [19896.0, 19800.0] | [60.0, 76.0] | [322, 330] |
p03651 | u879870653 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['def gcd(a,b) :\n while b :\n a,b = b, a % b\n return a\n\nN,K = map(int,input().split())\nL = list(map(int,input().split()))\n\np = 10**9\nfor i in range(N-1) :\n q = gcd(L[i],L[i+1])\n if q < p :\n p = q\n\nif (K % p == 0) and (K <= max(L))\n ans = "POSSIBLE"\nelse :\n ans = "IMPOSSIBLE"\nprint(ans)\n', 'def gcd(a,b) :\n while b :\n a,b = b, a % b\n return a\n\nN,K = map(int,input().split())\nL = list(map(int,input().split()))\n\nif len(L) == 1 :\n if L[0] == K :\n ans = "POSSIBLE"\n else :\n ans = "IMPOSSIBLE"\n\nelse :\n for i in range(N-1) :\n q = gcd(L[i],L[i+1])\n if i == 0 :\n p = gcd(L[i],L[i+1])\n if q < p :\n p = q\n\n if (K % p == 0) and (K <= max(L)) :\n ans = "POSSIBLE"\n else :\n ans = "IMPOSSIBLE"\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s538878184', 's350147871'] | [2940.0, 14224.0] | [17.0, 205.0] | [317, 501] |
p03651 | u896741788 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['n,k=map(int,input().split())\nl=soted(map(int,input().split()))\ndef gcd(x,y):\n if y==0:return x\n return gcd(y,x%y)\nans=""\ns=0\nfor i in l:\n s=gcd(i,s)\n if s==1:break\nelse:\n if k%s!=l[-1]%s:\n ans="IM"\nprint(ans+"POSSIBLE")', 'n,k=map(int,input().split())\nl=soted(list(map(int,input().split())))\ndef gcd(x,y):\n if y==0:return x\n return gcd(y,x%y)\nans=""\ns=0\nfor i in l:\n s=gcd(i,s)\n if s==1:break\nelse:\n if k%s!=l[-1]%s:\n ans="IM"\nprint(ans+"POSSIBLE")\n', 'n,k=map(int,input().split())\nl=sorted(map(int,input().split()))\ndef gcd(x,y):\n if y==0:return x\n return gcd(y,x%y)\nans=""\ns=0\nfor i in l:\n s=gcd(i,s)\n if s==1:break\nelse:\n if k%s!=l[-1]%s:\n ans="IM"\nif l[-1]<k:ans="IM"\nprint(ans+"POSSIBLE")\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s395154796', 's625076779', 's136877754'] | [3064.0, 3060.0, 14108.0] | [18.0, 17.0, 104.0] | [227, 234, 249] |
p03651 | u926678805 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ["from functools import reduce\nn,k=map(int,input().split())\na=list(map(int,input().split()))\ndef gcd(a, b):\n while a != 0:\n a,b=b%a,a\n return b\ndef lcm(x, y):\n return (x * y)//gcd(x, y)\nt=reduce(lcm,a)\nif t==1:\n if max(a)>=k:\n print('POSSIBLE')\n exit()\nelse:\n if k in a:\n print('POSSIBLE')\n exit()\n if k%t==0:\n print('POSSIBLE')\n exit()\nprint('IMPOSSIBLE')\n", "from functools import reduce\nn,k=map(int,input().split())\na=list(map(int,input().split()))\ndef gcd(a, b):\n while a != 0:\n a,b=b%a,a\n return b\ndef lcm(x, y):\n return (x * y)//gcd(x, y)\nt=reduce(gcd,a)\nif t==1:\n if max(a)>=k:\n print('POSSIBLE')\n exit()\nelse:\n if k in a:\n print('POSSIBLE')\n exit()\n if k%t==0 and max(a)>=k:\n print('POSSIBLE')\n exit()\nprint('IMPOSSIBLE')\n"] | ['Wrong Answer', 'Accepted'] | ['s541493707', 's669753508'] | [14596.0, 14596.0] | [2108.0, 69.0] | [422, 436] |
p03651 | u974792613 | 2,000 | 262,144 | There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. | ['def gcd(a, b):\n return gcd(b, a % b) if b > 0 else a\n\n\nn, k = map(int, input().split())\na = list(map(int, input().split())\n \nm = max(a)\n \ng = a[0]\n \nfor i in range(n):\n g = gcd(g, a[i])\n\nif k > m:\n print("IMPOSSIBLE")\nelif k % g == 0:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n\n', 'from fractions import gcd\n\nn,k = map(int, input().split())\na = list(map(int, input().split())\n \nm = max(a)\n \ng = a[0]\n \nfor i in range(n):\n g = gcd(g, a[i])\n\nif k>m:\n print("IMPOSSIBLE")\nelif k % g == 0:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n', 'def gcd(a, b):\n return gcd(b, a % b) if b > 0 else a\n\n\nn, k = map(int, input().split())\na = list(map(int, input().split()))\n\nm = max(a)\n\ng = a[0]\n\nfor i in range(n):\n g = gcd(g, a[i])\n\nif k > m:\n print("IMPOSSIBLE")\nelif k % g == 0:\n print("POSSIBLE")\nelse:\n print("IMPOSSIBLE")\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s758854177', 's854254792', 's455700431'] | [2940.0, 2940.0, 14224.0] | [17.0, 18.0, 88.0] | [320, 286, 294] |
p03652 | u077291787 | 2,000 | 262,144 | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants. | ['from collections import deque\nfrom typing import Optional\n\n\nclass DeletableDeque:\n """Deletable Deque: a deque that supports lazy deletion of values."""\n\n __slots__ = ["_set", "_deque"]\n\n def __init__(self, *initial_values: int) -> None:\n self._set = set()\n self._deque = deque([])\n\n if initial_values:\n for v in initial_values:\n self.append(v)\n\n def __contains__(self, value: int) -> bool:\n return value in self._set\n\n def __len__(self) -> int:\n return len(self._set)\n\n @property\n def is_empty(self) -> bool:\n """Return whether the deque has no values or not."""\n return len(self) == 0\n\n @property\n def top(self) -> Optional[int]:\n """Return the rightmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[-1] not in self._set:\n self._deque.pop()\n if not self._deque:\n return None\n return self._deque[-1]\n\n @property\n def topleft(self) -> Optional[int]:\n """Return the leftmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[0] not in self._set:\n self._deque.popleft()\n if not self._deque:\n return None\n return self._deque[0]\n\n def pop(self) -> Optional[int]:\n """Pop and return the rightmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[-1] not in self._set:\n self._deque.pop()\n if not self._deque:\n return None\n res = self._deque.pop()\n self._set.discard(res)\n return res\n\n def popleft(self) -> Optional[int]:\n """Pop and return the leftmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[0] not in self._set:\n self._deque.popleft()\n if not self._deque:\n return None\n res = self._deque.popleft()\n self._set.discard(res)\n return res\n\n def append(self, value: int) -> None:\n """Append value to the right side of the deque."""\n if value in self._set:\n return\n self._set.add(value)\n self._deque.append(value)\n\n def appendleft(self, value: int) -> None:\n """Append value to the left side of the deque."""\n if value in self._set:\n return\n self._set.add(value)\n self._deque.appendleft(value)\n\n def delete(self, value: int) -> None:\n """Delete value from the deque."""\n if value not in self._set:\n return\n self._set.discard(value)\n\n\ndef agc018_b():\n \n import sys\n from collections import defaultdict\n\n readline = sys.stdin.buffer.readline\n\n N, M = map(int, readline().split())\n A = []\n for _ in range(N):\n ranking = [(x, i) for i, x in enumerate(map(int, readline().split()), 1)]\n ranking.sort()\n _, fav_sports = zip(*ranking)\n print(fav_sports)\n A.append(DeletableDeque(*fav_sports))\n\n res = 301\n for _ in range(M):\n cnt = defaultdict(int)\n for a in A:\n cnt[a.topleft] += 1\n\n popular_sport = max(cnt, key=cnt.get)\n res = min(res, cnt[popular_sport])\n print(popular_sport, cnt[popular_sport])\n for a in A:\n a.delete(popular_sport)\n\n print(res)\n\n\nif __name__ == "__main__":\n agc018_b()\n', 'from collections import deque\nfrom typing import Optional\n\n\nclass DeletableDeque:\n """Deletable Deque: a deque that supports lazy deletion of values."""\n\n __slots__ = ["_set", "_deque"]\n\n def __init__(self, *initial_values: int) -> None:\n self._set = set()\n self._deque = deque([])\n\n if initial_values:\n for v in initial_values:\n self.append(v)\n\n def __contains__(self, value: int) -> bool:\n return value in self._set\n\n def __len__(self) -> int:\n return len(self._set)\n\n @property\n def is_empty(self) -> bool:\n """Return whether the deque has no values or not."""\n return len(self) == 0\n\n @property\n def top(self) -> Optional[int]:\n """Return the rightmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[-1] not in self._set:\n self._deque.pop()\n if not self._deque:\n return None\n return self._deque[-1]\n\n @property\n def topleft(self) -> Optional[int]:\n """Return the leftmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[0] not in self._set:\n self._deque.popleft()\n if not self._deque:\n return None\n return self._deque[0]\n\n def pop(self) -> Optional[int]:\n """Pop and return the rightmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[-1] not in self._set:\n self._deque.pop()\n if not self._deque:\n return None\n res = self._deque.pop()\n self._set.discard(res)\n return res\n\n def popleft(self) -> Optional[int]:\n """Pop and return the leftmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[0] not in self._set:\n self._deque.popleft()\n if not self._deque:\n return None\n res = self._deque.popleft()\n self._set.discard(res)\n return res\n\n def append(self, value: int) -> None:\n """Append value to the right side of the deque."""\n if value in self._set:\n return\n self._set.add(value)\n self._deque.append(value)\n\n def appendleft(self, value: int) -> None:\n """Append value to the left side of the deque."""\n if value in self._set:\n return\n self._set.add(value)\n self._deque.appendleft(value)\n\n def delete(self, value: int) -> None:\n """Delete value from the deque."""\n if value not in self._set:\n return\n self._set.discard(value)\n\n\ndef agc018_b():\n \n import sys\n from collections import defaultdict\n\n readline = sys.stdin.buffer.readline\n\n N, M = map(int, readline().split())\n A = []\n for _ in range(N):\n ranking = [(x, i) for i, x in enumerate(map(int, readline().split()), 1)]\n ranking.sort()\n _, fav_sports = zip(*ranking)\n A.append(DeletableDeque(*fav_sports))\n\n res = 301\n for _ in range(M):\n cnt = defaultdict(int)\n for a in A:\n cnt[a.topleft] += 1\n\n popular_sport = max(cnt, key=cnt.get)\n res = min(res, cnt[popular_sport])\n for a in A:\n a.delete(popular_sport)\n\n print(res)\n\n\nif __name__ == "__main__":\n agc018_b()\n', 'from collections import deque\nfrom typing import Optional\n\n\nclass DeletableDeque:\n """Deletable Deque: a deque that supports lazy deletion of values."""\n\n __slots__ = ["_set", "_deque"]\n\n def __init__(self, *initial_values: int) -> None:\n self._set = set()\n self._deque = deque([])\n\n if initial_values:\n for v in initial_values:\n self.append(v)\n\n def __contains__(self, value: int) -> bool:\n return value in self._set\n\n def __len__(self) -> int:\n return len(self._set)\n\n @property\n def is_empty(self) -> bool:\n """Return whether the deque has no values or not."""\n return len(self) == 0\n\n @property\n def top(self) -> Optional[int]:\n """Return the rightmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[-1] not in self._set:\n self._deque.pop()\n if not self._deque:\n return None\n return self._deque[-1]\n\n @property\n def topleft(self) -> Optional[int]:\n """Return the leftmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[0] not in self._set:\n self._deque.popleft()\n if not self._deque:\n return None\n return self._deque[0]\n\n def pop(self) -> Optional[int]:\n """Pop and return the rightmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[-1] not in self._set:\n self._deque.pop()\n if not self._deque:\n return None\n res = self._deque.pop()\n self._set.discard(res)\n return res\n\n def popleft(self) -> Optional[int]:\n """Pop and return the leftmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[0] not in self._set:\n self._deque.popleft()\n if not self._deque:\n return None\n res = self._deque.popleft()\n self._set.discard(res)\n return res\n\n def append(self, value: int) -> None:\n """Append value to the right side of the deque."""\n if value in self._set:\n return\n self._set.add(value)\n self._deque.append(value)\n\n def appendleft(self, value: int) -> None:\n """Append value to the left side of the deque."""\n if value in self._set:\n return\n self._set.add(value)\n self._deque.appendleft(value)\n\n def delete(self, value: int) -> None:\n """Delete value from the deque."""\n if value not in self._set:\n return\n self._set.discard(value)\n\n\ndef agc018_b():\n \n import sys\n from collections import defaultdict\n\n readline = sys.stdin.buffer.readline\n\n N, M = map(int, readline().split())\n A = []\n for _ in range(N):\n ranking = [(x, i) for i, x in enumerate(map(int, readline().split()), 1)]\n ranking.sort()\n _, fav_sports = zip(*ranking)\n A.append(DeletableDeque(*fav_sports))\n\n res = 301\n for _ in range(M):\n cnt = defaultdict(int)\n for a in A:\n cnt[a.topleft] += 1\n\n popular_sport = max(cnt, key=cnt.get)\n res = min(res, cnt[popular_sport])\n for a in A:\n a.delete(popular_sport)\n\n print(res)\n\n\nif __name__ == "__main__":\n agc018_b()\n', 'from collections import deque\nfrom typing import Optional\n\n\nclass DeletableDeque:\n """Deletable Deque: a deque that supports lazy deletion of values."""\n\n __slots__ = ["_set", "_deque"]\n\n def __init__(self, *initial_values: int) -> None:\n self._set = set()\n self._deque = deque([])\n\n if initial_values:\n for v in initial_values:\n self.append(v)\n\n @property\n def topleft(self) -> Optional[int]:\n """Return the leftmost value from the deque.\n If the deque is empty, None is returned.\n """\n while self._deque and self._deque[0] not in self._set:\n self._deque.popleft()\n if not self._deque:\n return None\n return self._deque[0]\n\n def append(self, value: int) -> None:\n """Append value to the right side of the deque."""\n if value in self._set:\n return\n self._set.add(value)\n self._deque.append(value)\n\n def delete(self, value: int) -> None:\n """Delete value from the deque."""\n if value not in self._set:\n return\n self._set.discard(value)\n\n\ndef agc018_b():\n \n import sys\n from collections import Counter\n\n readline = sys.stdin.buffer.readline\n\n N, M = map(int, readline().split())\n A = [DeletableDeque(*map(int, readline().split())) for _ in range(N)]\n\n res = 301\n for _ in range(M):\n cnt = Counter(a.topleft for a in A)\n popular_sport = max(cnt, key=cnt.get)\n res = min(res, cnt[popular_sport])\n for a in A:\n a.delete(popular_sport)\n\n print(res)\n\n\nif __name__ == "__main__":\n agc018_b()\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s035857929', 's129245579', 's236852242', 's844707749'] | [14284.0, 14084.0, 14172.0, 14028.0] | [155.0, 149.0, 145.0, 122.0] | [3607, 3532, 3532, 1706] |
p03652 | u201234972 | 2,000 | 262,144 | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants. | ['from collections import Counter\nN, M = map( int, input().split())\nA = [ [] for _ in range(N)]\nfor i in range(N):\n A[i] = list( map( int, input().split())) \nV = [1]*(M+1)\nans = N\nfor _ in range(M-1):\n W = []\n for i in range(N):\n while A[i]:\n a = A[i].pop(0)\n if V[a] == 1:\n W.append(a)\n if not W:\n break\n a, c = Counter(W).most_common()[0]\n ans = min( ans, c)\n V[a] = 0\nprint(ans)', 'from collections import Counter\nN, M = map( int, input().split())\nA = [ [] for _ in range(N)]\nfor i in range(N):\n A[i] = list( map( int, input().split())) \nV = [1]*(M+1)\nans = N\nfor _ in range(M-1):\n W = []\n for i in range(N):\n while True:\n if V[A[i][0]] == 1:\n W.append(A[i][0])\n break\n else:\n A[i].pop(0)\n a, c = Counter(W).most_common()[0]\n ans = min( ans, c)\n V[a] = 0\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s670926010', 's129791218'] | [5464.0, 4700.0] | [88.0, 105.0] | [451, 476] |
p03652 | u223904637 | 2,000 | 262,144 | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants. | ['n,m=map(int,input().split())\nk=[[0]*m for i in range(n)]\nfor i in range(n):\n k[i]=list(map(int,input().split()))\nans=1000\nfor i in range(m-1):\n ma=[0]*m\n mi=-1\n for j in range(n):\n ma[k[j][0]]+=1\n if ans>max(ma):\n ans=max(ma)\n mi=ma.index(max(ma))+1\n for j in range(n):\n k[j].remove(mi)\nprint(ans)\n \n', 'n,m=map(int,input().split())\nk=[[0]*m for i in range(n)]\nfor i in range(n):\n k[i]=list(map(int,input().split()))\nans=1000\nfor i in range(m-1):\n ma=[0]*m\n mi=-1\n for j in range(n):\n ma[k[j][0]-1]+=1\n if ans>max(ma):\n ans=max(ma)\n mi=ma.index(max(ma))+1\n for j in range(n):\n k[j].remove(mi)\nif m==1:\n print(n)\nelse:\n print(ans)\n \n'] | ['Runtime Error', 'Accepted'] | ['s748647703', 's070431674'] | [4288.0, 4332.0] | [37.0, 165.0] | [349, 383] |
p03652 | u340781749 | 2,000 | 262,144 | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants. | ['n, m = map(int, input().split())\nprefers = [list(reversed(list(map(int, input().split())))) for _ in range(n)]\nitems = [True] * (m + 1)\ncompetes = {i: 0 for i in range(1, m + 1)}\npersons = [set() for _ in range(m + 1)]\n\nfor i, ps in enumerate(prefers):\n item = ps[-1]\n competes[item] += 1\n persons[item].add(i)\n\nans = m\nremain = m\nwhile remain:\n mx = max(competes.values())\n ans = min(ans, mx)\n del_items = [a for a, k in competes.items() if k == mx]\n for a in del_items:\n items[a] = False\n del competes[a]\n for a in del_items:\n pa = persons[a]\n for p in pa:\n pf = prefers[p]\n while not items[pf[-1]]:\n pf.pop()\n item = pf[-1]\n persons[item].add(p)\n competes[item] += 1\n remain -= 1\n\nprint(ans)\n', "from collections import defaultdict\nfrom operator import itemgetter\n\n\ndef sub(prefers, canceled):\n res = defaultdict(int)\n for pref in prefers:\n p = pref[-1]\n while p in canceled:\n pref.pop()\n p = pref[-1]\n res[p] += 1\n\n return max(res.items(), key=itemgetter(1))\n\n\ndef solve(m, prefers):\n canceled = set()\n ans = float('inf')\n for _ in range(m):\n s, c = sub(prefers, canceled)\n canceled.add(s)\n ans = min(ans, c)\n return ans\n\n\nn, m = map(int, input().split())\nprefers = [list(reversed(list(map(int, input().split())))) for _ in range(n)]\n\nprint(solve(m, prefers))\n"] | ['Runtime Error', 'Accepted'] | ['s154733906', 's687040051'] | [6692.0, 4588.0] | [103.0, 71.0] | [820, 650] |
p03652 | u375616706 | 2,000 | 262,144 | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants. | ['from collections import Counter\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\n\nN, M = map(int, input().split())\nmat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]\n\nans = N\nQ = [set([v for v in range(M)])]\nwhile Q:\n C = Counter()\n sports_cand = Q.pop(0)\n for n in range(N):\n for m in range(M):\n if mat[n][m] in sports_cand:\n C[mat[n][m]] += 1\n break\n tmp = 0\n rem_key = {}\n for key, val in C.most_common():\n if val >= tmp:\n tmp = val\n ans = min(ans, val)\n rem_key.add(key)\n else:\n break\n if len(sports_cand) > 2:\n Q.append(sports_cand-rem_key)\nprint(ans)\n', 'from collections import Counter\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\n\nN, M = map(int, input().split())\nmat = [list(map(int, input().split())) for _ in range(N)]\n\nans = float(\'inf\')\nsports_cand = set([v for v in range(M)])\n\n\ndef rec(sports_cand, ans):\n if not sports_cand:\n return ans\n else:\n attend_i = [0]*N \n attend_sports = [-1]*N \n for s in sports_cand:\n for p in range(N):\n if attend_i[p] < mat[p][s]: \n attend_i[p] = mat[p][s]\n attend_sports[p] = s\n C = Counter(attend_sports)\n print("c->", C)\n num = 0\n for id, tmp_val in C.most_common():\n if tmp_val >= num:\n num = tmp_val\n ans = min(ans, tmp_val)\n if len(sports_cand) <= 2:\n break\n ans = min(ans, rec(sports_cand-{id}, ans))\n else:\n break\n return ans\n\n\nprint(rec(sports_cand, ans))\n', 'from collections import Counter\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\n\nN, M = map(int, input().split())\nmat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]\n\nans = N\nQ = [set([v for v in range(M)])]\nwhile Q:\n C = Counter()\n sports_cand = Q.pop(0)\n for n in range(N):\n for m in range(M):\n if mat[n][m] in sports_cand:\n C[mat[n][m]] += 1\n break\n tmp = 0\n rem_key = set()\n for key, val in C.most_common():\n if val >= tmp:\n tmp = val\n ans = min(ans, val)\n rem_key.add(key)\n else:\n break\n if len(sports_cand) > 2:\n Q.append(sports_cand-rem_key)\nprint(ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s538838284', 's955631849', 's024464788'] | [4588.0, 13772.0, 4588.0] | [50.0, 2104.0, 1768.0] | [731, 1139, 734] |
p03652 | u415905784 | 2,000 | 262,144 | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants. | ['N, M = map(int, input().split())\nA = [[0 for _ in range(M)] for _ in range(N)]\nfor i in range(N):\n A[i] = [int(x) - 1 for x in input().split()]\nS = [[0, i] for i in range(M)]\nfor a in A:\n S[a[0]][0] += 1\nminmax = N\nfor _ in range(M - 1):\n _S = sorted(S, reverse=True)\n s = _S[0][1]\n minmax = min(S[s][0], minmax)\n S[s][0] = -1\n for a in A:\n while S[a[0]][0] < 0:\n a.pop(0)\n S[a[0]][0] += 1\nprint(minmax)', 'N, M = map(int, input().split())\nA = [[0 for _ in range(M)] for _ in range(N)]\nfor i in range(N):\n A[i] = [int(x) - 1 for x in input().split()]\nS = [[0, i] for i in range(M)]\nfor a in A:\n S[a[0]][0] += 1\nminmax = N\nfor _ in range(M - 1):\n _S = sorted(S, reverse=True)\n s = _S[0][1]\n minmax = min(S[s][0], minmax)\n S[s][0] = -1\n for a in A:\n if S[a[0]][0] > 0:\n continue\n while S[a[0]][0] < 0:\n a.pop(0)\n S[a[0]][0] += 1\nprint(minmax)'] | ['Wrong Answer', 'Accepted'] | ['s661514831', 's373710075'] | [4212.0, 4212.0] | [114.0, 125.0] | [421, 459] |
p03652 | u426108351 | 2,000 | 262,144 | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants. | ['n, m = map(int, input().split())\na = [list(map(int, input().split())) for i in range(n)]\nfor i in range(n):\n a[i].reverse()\n\nans = n\nused = set()\nfor i in range(m):\n count = [0]*(m+1)\n for j in range(n):\n count[a[j][-1]] += 1\n\n ans = min(max(count), ans)\n num = count.index(max(count))\n used.add(num)\n for j in range(n):\n while True:\n if a[j][-1] in used:\n a[j].pop()\n else:\n break\n\nprint(ans)\n', 'n, m = map(int, input().split())\na = [list(map(int, input().split())) for i in range(n)]\nfor i in range(n):\n a[i].reverse()\n\nans = n\nused = set()\nfor i in range(m):\n count = [0]*(m+1)\n for j in range(n):\n count[a[j][-1]] += 1\n\n ans = min(max(count), ans)\n num = count.index(max(count))\n used.add(num)\n for j in range(n):\n if a[j][-1] in num:\n a[j].pop()\n\nprint(ans)\n', 'n, m = map(int, input().split())\na = [list(map(int, input().split())) for i in range(n)]\nfor i in range(n):\n a[i].reverse()\n\nans = n\nused = set()\nfor i in range(m):\n count = [0]*(m+1)\n for j in range(n):\n count[a[j][-1]] += 1\n\n ans = min(max(count), ans)\n num = count.index(max(count))\n used.add(num)\n for j in range(n):\n while len(a[j]) > 0:\n if a[j][-1] in used:\n a[j].pop()\n else:\n break\n\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s574115545', 's617397519', 's507713635'] | [10172.0, 10208.0, 10172.0] | [72.0, 38.0, 96.0] | [481, 412, 490] |
p03652 | u572142121 | 2,000 | 262,144 | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants. | ['N,M=map(int, input().split())\nA=[]\nfor i in range(N):\n d=list(map(int, input().split()))\n A.append(d)\nnum=[0]*N\nans=M\nS=set()\nfor i in range(M-1):\n cnt=[0]*M\n for j in range(N):\n for k in range(M):\n d=A[j][k]-1\n if d in S:\n continue\n else:\n cnt[d]+=1\n e=max(cnt)\n ans=min(e,ans)\n f=cnt.index(e)\n S.add(f)\nprint(ans)\n', 'N,M=map(int, input().split())\nA=[]\nfor i in range(N):\n d=list(map(int, input().split()))\n A.append(d)\nS=[1]*M\nnum=[0]*N\nans=N\nfor i in range(M):\n cnt=[0]*M\n for j in range(N):\n d=A[j][num[j]]\n while S[d-1]==0:\n num[j]+=1\n d=A[j][num[j]]\n cnt[d-1]+=1\n e=max(cnt)\n ans=min(e,ans)\n f=cnt.index(e)\n S[f]=0\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s518289126', 's641406485'] | [10208.0, 10284.0] | [2206.0, 86.0] | [356, 340] |
p03652 | u594567187 | 2,000 | 262,144 | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants. | ['def dfs(people, sports, use_sports, answer):\n rank = [0 for n in range(sports)]\n for p in range(people):\n for s in (preference[p]):\n if s in use_sports:\n rank[s] += 1\n break\n will_delete = []\n max_p = max(rank)\n exclude = rank.index(max_p)\n answer = min(answer, max_p, dfs(people, sports, use_sports - {exclude}, answer))\n return answer\n\npeople, sports = (int(n) for n in input().split(" "))\npreference = []\nfor _ in range(people):\n pre = [int(n) for n in input().split(" ")]\n preference.append(pre)\nanswer = float("inf")\nuse_sports = {n for n in range(sports)}\nprint(dfs(people, sports, use_sports, answer))\n', 'people, sports = (int(n) for n in input().split(" "))\npreference = []\nfor _ in range(people):\n pre = [int(n) - 1 for n in input().split(" ")]\n preference.append(pre)\nanswer = float("inf")\nuse_sports = {n for n in range(sports)}\nfor _ in range(sports):\n rank = [0 for n in range(sports)]\n for p in range(people):\n for s in (preference[p]):\n if s in use_sports:\n rank[s] += 1\n break\n answer = min(answer, max(rank))\n use_sports -= {rank.index(max(rank))}\nprint(answer)'] | ['Runtime Error', 'Accepted'] | ['s363918907', 's472169800'] | [10404.0, 4212.0] | [2104.0, 1049.0] | [692, 532] |
p03652 | u624475441 | 2,000 | 262,144 | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants. | ["from collections import Counter\nfrom operator import itemgetter\n\ndef sub(prefers, canceled):\n res = Counter()\n for pref in prefers:\n p = pref[-1]\n while p in canceled:\n pref.pop()\n p = pref[-1]\n res[p] += 1\n return max(res.items(), key=itemgetter(1))\n\ndef solve(m, prefers):\n canceled = set()\n ans = float('inf')\n for _ in [0] * m:\n s, c = sub(prefers, canceled)\n canceled.add(s)\n ans = min(ans, c)\n return ans\n\nif __name__ == '__main__':\n N, M = map(int, input().split())\n A = [list(map(int, input().split()))[::-1] for _ in [0] * N]\n print(solve(M, A))", "from collections import Counter\nfrom operator import itemgetter\n\ndef sub(prefers, canceled):\n res = Counter()\n for pref in prefers:\n p = pref[-1]\n while p in canceled:\n pref.pop()\n p = pref[-1]\n res[p] += 1\n return max(res.items(), key=itemgetter(1))\n\ndef solve(m, prefers):\n canceled = set()\n ans = float('inf')\n for _ in [0] * m:\n s, c = sub(prefers, canceled)\n canceled.add(s)\n ans = min(ans, c)\n return ans\n\nif __name__ == '__main__':\n N, M = map(int, input().split())\n A = [list(map(int, input().split()))[::-1] for _ in [0] * N]\n print(solve(M, A))"] | ['Runtime Error', 'Accepted'] | ['s005795175', 's109941345'] | [2940.0, 4580.0] | [17.0, 99.0] | [647, 648] |
p03652 | u814986259 | 2,000 | 262,144 | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants. | ['N,M=map(int,input().split())\nA=[list(map(int,input().split())) for i in range(N)]\nans=N\ns=set()\nfor i in range(M-1):\n d=[0]*M\n for j in range(N):\n for k in range(M):\n if A[j][k]-1 in s:\n continue\n else:\n d[A[j][k]-1]+=1\n ans=min(ans,max(d))\n s.add(d.index(max(d)))\nprint(ans)\n ', 'def main():\n import sys\n input=sys.stdin.buffer.readline\n N,M=map(int,input().split())\n A=[list(map(int,input().split())) for i in range(N)]\n ans=N\n s=set()\n for i in range(M-1):\n d=[0]*M\n for j in range(N):\n for k in range(M):\n if A[j][k]-1 in s:\n continue\n else:\n d[A[j][k]-1]+=1\n break\n ans=min(ans,max(d))\n s.add(d.index(max(d)))\n print(ans)\nmain()\n \n'] | ['Wrong Answer', 'Accepted'] | ['s164995348', 's245909828'] | [10168.0, 9980.0] | [2206.0, 923.0] | [309, 422] |
p03655 | u102461423 | 8,000 | 262,144 | Joisino is planning on touring Takahashi Town. The town is divided into square sections by north-south and east-west lines. We will refer to the section that is the x-th from the west and the y-th from the north as (x,y). Joisino thinks that a _touring plan_ is good if it satisfies the following conditions: * Let (p,q) be the section where she starts the tour. Then, X_1 \leq p \leq X_2 and Y_1 \leq q \leq Y_2 hold. * Let (s,t) be the section where she has lunch. Then, X_3 \leq s \leq X_4 and Y_3 \leq t \leq Y_4 hold. * Let (u,v) be the section where she ends the tour. Then, X_5 \leq u \leq X_6 and Y_5 \leq v \leq Y_6 hold. * By repeatedly moving to the adjacent section (sharing a side), she travels from the starting section to the ending section in the shortest distance, passing the lunch section on the way. Two touring plans are considered different if at least one of the following is different: the starting section, the lunch section, the ending section, and the sections that are visited on the way. Joisino would like to know how many different good touring plans there are. Find the number of the different good touring plans. Since it may be extremely large, find the count modulo 10^9+7. | ['import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nimport itertools\nimport numpy as np\nfrom functools import lru_cache\n\nX = list(map(int,readline().split()))\nY = list(map(int,readline().split()))\n\nfor i in [1,3,5]:\n X[i] += 1\n Y[i] += 1\n\nX1 = X[:2]; X2 = X[2:4]; X3 = X[4:]\nY1 = Y[:2]; Y2 = Y[2:4]; Y3 = Y[4:]\n\ndef cumprod(arr,MOD):\n L = len(arr); Lsq = int(L**.5+1)\n arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)\n for n in range(1,Lsq):\n arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD\n for n in range(1,Lsq):\n arr[n] *= arr[n-1,-1]; arr[n] %= MOD\n return arr.ravel()[:L]\n\ndef make_fact(U,MOD):\n x = np.arange(U,dtype=np.int64); x[0] = 1\n fact = cumprod(x,MOD)\n x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)\n fact_inv = cumprod(x,MOD)[::-1]\n return fact,fact_inv\n\nU = 2 * 10 ** 6 + 10\nMOD = 10**9 + 7\nfact, fact_inv = make_fact(U,MOD)\n\n@lru_cache()\ndef make_comb(n):\n return fact[n] * fact_inv[:n+1] % MOD * fact_inv[:n+1][::-1] % MOD\n\nanswer = 0\nfor p in itertools.product([0,1],repeat=6):\n x1,x2,x3,y1,y2,y3 = [A[i] for A,i in zip([X1,X2,X3,Y1,Y2,Y3],p)]\n sgn = (-1) ** sum(p)\n a,b,c,d = x2-x1, x3-x2, x2-x1+y2-y1, x3-x2+y3-y2\n c += 2; d += 2; sgn = -sgn\n make_comb(c)\n make_comb(d)\n ', 'import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nN,M,*X = map(int,read().split())\n\nMOD = 10 ** 9 + 7\n\ndef mult(a,b,c,d,e,f):\n \n a,b,c,d,e = a*d,a*e+b*d,a*f+b*e+c*d,b*f+c*e,c*f\n b += e; c -= 4*e; d += 2*e; e = 0\n a += d; b -= 4*d; c += 2*d; d = 0\n a %= MOD; b %= MOD; c %= MOD\n return a,b,c\n\n\nM = 10 ** 5\nA1 = [0] * (M+1)\na,b,c = 1,0,0\nfor i in range(M+1):\n A1[i] = (a,b,c)\n a,b,c = b+4*a,c-2*a,a\n a %= MOD; b %= MOD; c %= MOD\n\n\nA2 = [0] * (M+1)\na,b,c = 1,0,0\nd,e,f = A1[M]\nfor i in range(M+1):\n A2[i] = (a,b,c)\n a,b,c = mult(a,b,c,d,e,f)\n\ndef power(n):\n \n q,r = divmod(n,M)\n a,b,c = A1[r]\n d,e,f = A2[q]\n return mult(a,b,c,d,e,f)\n\nX.append(N)\n\na,b,c = 0,1,1\nprev_x = 0\nfor x in X:\n a,b,c = mult(a,b,c,*power(x - prev_x))\n b -= a; c -= a\n prev_x = x\n\nanswer = a\nprint(answer)', 'import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nimport itertools\nimport numpy as np\nfrom functools import lru_cache\nfrom operator import itemgetter\n\nX = list(map(int,readline().split()))\nY = list(map(int,readline().split()))\n\nfor i in [1,3,5]:\n X[i] += 1\n Y[i] += 1\n\nX1 = X[:2]; X2 = X[2:4]; X3 = X[4:]\nY1 = Y[:2]; Y2 = Y[2:4]; Y3 = Y[4:]\n\ndef cumprod(arr,MOD):\n L = len(arr); Lsq = int(L**.5+1)\n arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)\n for n in range(1,Lsq):\n arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD\n for n in range(1,Lsq):\n arr[n] *= arr[n-1,-1]; arr[n] %= MOD\n return arr.ravel()[:L]\n\ndef make_fact(U,MOD):\n x = np.arange(U,dtype=np.int64); x[0] = 1\n fact = cumprod(x,MOD)\n x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)\n fact_inv = cumprod(x,MOD)[::-1]\n return fact,fact_inv\n\nU = 2 * 10 ** 6 + 10\nMOD = 10**9 + 7\nfact, fact_inv = make_fact(U,MOD)\n\n@lru_cache(8)\ndef make_comb(n):\n return fact[n] * fact_inv[:n+1] % MOD * fact_inv[:n+1][::-1] % MOD\n\nanswer = 0\ntasks = []\nfor p in itertools.product([0,1],repeat=6):\n x1,x2,x3,y1,y2,y3 = [A[i] for A,i in zip([X1,X2,X3,Y1,Y2,Y3],p)]\n sgn = (-1) ** sum(p)\n a,b,c,d = x2-x1, x3-x2, x2-x1+y2-y1, x3-x2+y3-y2\n c += 2; d += 2; sgn = -sgn\n tasks.append((a,b,c,d,sgn))\n\ntasks.sort(key = itemgetter(2))\n\nfor a,b,c,d,sgn in tasks:\n \n \n D = a + b + 2\n \n L = max(0, D-d)\n R = min(c, D)\n if L > R:\n continue\n x = make_comb(c)[L:R+1]\n L,R = D-R,D-L\n y = make_comb(d)[L:R+1]\n x = x * y[::-1] % MOD\n \n np.cumsum(x,out=x)\n x %= MOD\n np.cumsum(x,out=x)\n x %= MOD\n L,R = D-R,D-L\n if 0 <= a-L < len(x):\n answer += sgn * x[a-L]\n\nanswer %= MOD\nprint(answer)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s091068610', 's281248502', 's134618058'] | [323808.0, 34788.0, 200800.0] | [1077.0, 325.0, 3311.0] | [1346, 1041, 2034] |
p03662 | u171366497 | 2,000 | 262,144 | Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally. | ['N=int(input())\nfrom collections import defaultdict,deque\nbranch=defaultdict(set)\nfor i in range(N-1):\n a,b=map(int,input().split())\n a-=1\n b-=1\n branch[a]|={b}\n branch[b]|={a}\ncheck={0}\nbef=[-2]*N\nbef[0]=-1\ndist=[float(\'inf\')]*N\ndist[0]=0\nwhile len(check)>0:\n now=check.pop()\n for nex in branch[now]:\n if bef[nex]==-2:\n bef[nex]=now\n check|={nex}\n dist[nex]=dist[now]+1\nprint("NO")\nexit()', 'N=int(input())\nfrom collections import defaultdict,deque\nbranch=defaultdict(set)\nfor i in range(N-1):\n a,b=map(int,input().split())\n a-=1\n b-=1\n branch[a]|={b}\n branch[b]|={a}\ncheck={0}\npath=[0]*N\npath[0]=[0]\nwhile len(check)>0:\n x=check.pop()\n for nex in branch[x]:\n if path[nex]==0:\n check|={nex}\n path[nex]=path[x]+[nex]\nprint("NO")\nexit()\nG=path[N-1]\nng=G[(len(G)+1)//2]\ncnt=0\nfor i in range(N):\n if ng not in path[i]:\n cnt+=1\nif cnt>N-cnt:\n print("Fennec")\nelse:\n print("Snuke")', 'N=int(input())\nfrom collections import defaultdict,deque\nbranch=defaultdict(set)\nfor i in range(N-1):\n a,b=map(int,input().split())\n a-=1\n b-=1\n branch[a]|={b}\n branch[b]|={a}\ncheck={0}\nbef=[-2]*N\nbef[0]=-1\ndist=[float(\'inf\')]*N\ndist[0]=0\nwhile len(check)>0:\n now=check.pop()\n for nex in branch[now]:\n if bef[nex]==-2:\n bef[nex]=now\n check|={nex}\n dist[nex]=dist[now]+1\nNG=set()\nOK={0}\nnow=N-1\nchecked={0}\nfor i in range((1+dist[N-1])//2):\n NG|={now}\n now=bef[now]\nchecked|=NG\nfor i in range(N):\n if i in checked:\n continue\n else:\n visited={i}\n now=i\n while True:\n now=bef[now]\n visited|={now}\n if now in NG:\n NG|=visited\n checked|=visited\n break\n elif now in OK:\n OK|=visited\n checked|=visited\n break\nif len(OK)>N//2:\n print("Fennec")\nelse:\n print("Snuke")'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s542676145', 's662475690', 's058435549'] | [42804.0, 950400.0, 56104.0] | [652.0, 2167.0, 724.0] | [449, 549, 998] |
p03662 | u346308892 | 2,000 | 262,144 | Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally. | ['\nclass Edge:\n def __init__(self,edge,cost=1):\n self.node_from=edge[0]\n self.node_to=edge[1]\n self.cost=cost\n\n def add_node(self,node):\n self.nodes.append(node)\n\nclass myGraph:\n\n def __init__(self):\n self.adj={}\n self.nodes={}\n\n def add_edge(self,edge,cost):\n if len(edge)==1:\n edge=list(edge)\n\n u,v=edge[0],edge[1]\n\n if u not in self.nodes:\n self.adj[u] = {}\n self.nodes[u] = {}\n\n if v not in self.nodes:\n self.adj[v] = {}\n self.nodes[v] = {}\n\n\n # add the edge\n self.adj[u][v] = cost\n self.adj[v][u] = cost\n\n def add_directed_edge(self,edge,cost):\n if len(edge)==1:\n edge=list(edge)\n\n\n u,v=edge[0],edge[1]\n\n if u not in self.nodes:\n self.adj[u] = {}\n self.nodes[u] = {}\n\n if v not in self.nodes:\n self.adj[v] = {}\n self.nodes[v] = {}\n\n self.adj[u][v] = cost\n\n def get_edges_from(self,node):\n\n return [(self.adj[node][nn],node,nn) for nn in self.adj[node]]\n\n\n def makeEdgeobj(self):\n edges=[]\n for sn in self.nodes:\n for e in self.get_edges_from(sn):\n edges.append(Edge([e[1],e[2]],e[0]))\n\n return edges\n\n def _add(self,edges,add_edges):\n for e in add_edges:\n hq.heappush(edges,e)\n return edges\n\n def bermn_ford(self,start,init=0):\n\n nodes=self.nodes\n dists={}\n for n in nodes:\n dists[n]=float("inf")\n\n dists[start]=init\n edges=self.makeEdgeobj()\n for i in range(len(nodes)):\n update=False\n for k in range(len(edges)):\n e=edges[k]\n if dists[e.node_from]!=float("inf") and dists[e.node_to]>dists[e.node_from]+e.cost:\n #print("updated")\n dists[e.node_to]=dists[e.node_from]+e.cost\n update=True\n\n if i==len(nodes)-1:\n return False\n\n if not update:\n break\n\n\n return dists\n\n def search(self):\n global N\n a=1\n b=N-1\n visit=[0]*(N+1)\n\n Qa=[a]\n Qb=[b]\n visit[a]=visit[b]=1\n\n while True:\n \n\n try:\n a=Qa.pop()\n except:\n res="Snuke"\n break\n\n\n sss=list(self.adj[a])\n if len(sss)==0:\n res="Snuke"\n break\n\n #print(sss)\n for sa in sss:\n if not visit[sa]:\n Qa.append(sa)\n visit[sa]=1\n\n try:\n b=Qb.pop()\n except:\n res="Fennec"\n break\n\n sss=list(self.adj[b])\n if len(sss)==0:\n res="Fennec"\n break\n\n for sb in sss:\n if not visit[sb]:\n Qb.append(sb)\n visit[sb]=1\n\n\n', '\nclass Edge:\n def __init__(self,edge,cost=1):\n self.node_from=edge[0]\n self.node_to=edge[1]\n self.cost=cost\n\n def add_node(self,node):\n self.nodes.append(node)\n\nclass myGraph:\n\n def __init__(self):\n self.adj={}\n self.nodes={}\n\n def add_edge(self,edge,cost):\n if len(edge)==1:\n edge=list(edge)\n\n u,v=edge[0],edge[1]\n\n if u not in self.nodes:\n self.adj[u] = {}\n self.nodes[u] = {}\n\n if v not in self.nodes:\n self.adj[v] = {}\n self.nodes[v] = {}\n\n\n # add the edge\n self.adj[u][v] = cost\n self.adj[v][u] = cost\n\n def add_directed_edge(self,edge,cost):\n if len(edge)==1:\n edge=list(edge)\n\n\n u,v=edge[0],edge[1]\n\n if u not in self.nodes:\n self.adj[u] = {}\n self.nodes[u] = {}\n\n if v not in self.nodes:\n self.adj[v] = {}\n self.nodes[v] = {}\n\n self.adj[u][v] = cost\n\n def get_edges_from(self,node):\n\n return [(self.adj[node][nn],node,nn) for nn in self.adj[node]]\n\n\n def makeEdgeobj(self):\n edges=[]\n for sn in self.nodes:\n for e in self.get_edges_from(sn):\n edges.append(Edge([e[1],e[2]],e[0]))\n\n return edges\n\n def _add(self,edges,add_edges):\n for e in add_edges:\n hq.heappush(edges,e)\n return edges\n\n def bermn_ford(self,start,init=0):\n\n nodes=self.nodes\n dists={}\n for n in nodes:\n dists[n]=float("inf")\n\n dists[start]=init\n edges=self.makeEdgeobj()\n for i in range(len(nodes)):\n update=False\n for k in range(len(edges)):\n e=edges[k]\n if dists[e.node_from]!=float("inf") and dists[e.node_to]>dists[e.node_from]+e.cost:\n #print("updated")\n dists[e.node_to]=dists[e.node_from]+e.cost\n update=True\n\n if i==len(nodes)-1:\n return False\n\n if not update:\n break\n\n\n return dists\n\n def search(self):\n global N\n a=1\n b=N-1\n visit=[0]*(N+1)\n\n Qa=[a]\n Qb=[b]\n visit[a]=visit[b]=1\n\n while True:\n \n\n try:\n a=Qa.pop()\n except:\n res="Snuke"\n break\n\n\n sss=list(self.adj[a])\n if len(sss)==0:\n res="Snuke"\n break\n\n #print(sss)\n for sa in sss:\n if not visit[sa]:\n Qa.append(sa)\n visit[sa]=1\n\n try:\n b=Qb.pop()\n except:\n res="Fennec"\n break\n\n sss=list(self.adj[b])\n if len(sss)==0:\n res="Fennec"\n break\n\n for sb in sss:\n if not visit[sb]:\n Qb.append(sb)\n visit[sb]=1\n\n\n\n if sum(visit)==N-1:\n break\n\n\n print(res)\n', '\nclass Node:\n def __init__(self):\n pass\n\nclass Edge:\n def __init__(self,edge,cost=1):\n self.node_from=edge[0]\n self.node_to=edge[1]\n self.cost=cost\n\n def add_node(self,node):\n self.nodes.append(node)\n\nclass myGraph:\n\n def __init__(self):\n self.adj={}\n self.nodes={}\n\n def add_edge(self,edge,cost):\n if len(edge)==1:\n edge=list(edge)\n\n u,v=edge[0],edge[1]\n\n if u not in self.nodes:\n self.adj[u] = {}\n self.nodes[u] = {}\n\n if v not in self.nodes:\n self.adj[v] = {}\n self.nodes[v] = {}\n\n # add the edge\n self.adj[u][v] = cost\n self.adj[v][u] = cost\n\n def add_directed_edge(self,edge,cost):\n if len(edge)==1:\n edge=list(edge)\n\n\n u,v=edge[0],edge[1]\n\n if u not in self.nodes:\n self.adj[u] = {}\n self.nodes[u] = {}\n\n if v not in self.nodes:\n self.adj[v] = {}\n self.nodes[v] = {}\n\n self.adj[u][v] = cost\n\n def get_edges_from(self,node):\n return [(self.adj[node][nn],node,nn) for nn in self.adj[node]]\n\n\n def makeEdgeobj(self):\n edges=[]\n for sn in self.nodes:\n for e in self.get_edges_from(sn):\n edges.append(Edge([e[1],e[2]],e[0]))\n\n return edges\n\n def _add(self,edges,add_edges):\n for e in add_edges:\n hq.heappush(edges,e)\n return edges\n\n def bermn_ford(self,start,init=0):\n\n nodes=self.nodes\n dists={}\n for n in nodes:\n dists[n]=float("inf")\n\n dists[start]=init\n edges=self.makeEdgeobj()\n\n for i in range(len(nodes)):\n update=False\n for k in range(len(edges)):\n e=edges[k]\n if dists[e.node_from]!=float("inf") and dists[e.node_to]>dists[e.node_from]+e.cost:\n dists[e.node_to]=dists[e.node_from]+e.cost\n update=True\n\n if i==len(nodes)-1:\n return False\n\n if not update:\n break\n\n return dists\n\n\n def dijkstra(self,start, goal=None):\n import heapq\n \'\'\'\n get minimum cost\n \'\'\'\n\n N = len(self.adj) \n \n dist = {k:float(\'inf\') for k in self.nodes}\n \n\n dist[start] = 0\n visited = []\n\n koho=[]\n heapq.heappush(koho,(0,start))\n\n vtx=list(self.nodes)\n vtx.remove(start)\n\n while len(koho)!=0:\n d,mini=heapq.heappop(koho)\n if dist[mini]<d:\n continue\n\n\n for k in list(self.adj[mini]):\n cost=self.adj[mini][k]\n if cost != float(\'inf\') and dist[k]>dist[mini]+cost:# and not(k in visited):\n dist[k]=dist[mini]+cost\n heapq.heappush(koho,(dist[k],k))\n #prev[k]=mini\n\n return dist\n\n\n\nN=int(input())\n\ng=myGraph()\nfor i in range(N-1):\n a,b=list(map(int,input().split(" ")))\n g.add_edge([a,b],1)\n\nb1=g.dijkstra(1)\nb2=g.dijkstra(N)\n\ncount=0\nfor k in range(1,N+1):\n if b1[k]<=b2[k]:\n count+=1\n\nif count>N/2:\n print("Fennec")\nelse:\n print("Snuke")'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s185617994', 's992425786', 's462077828'] | [3192.0, 3192.0, 105304.0] | [18.0, 18.0, 1512.0] | [3055, 3131, 3422] |
p03662 | u426108351 | 2,000 | 262,144 | Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally. | ['import sys\ninput = sys.stdin.readline\nN = int(input())\ntree = [[] for i in range(N+1)]\n\nfor i in range(N-1):\n a, b = map(int, input().split())\n tree[a].append(b)\n tree[b].append(a)\n\ndist_fennec = [100001] * (N+1)\ndist_snuke = [100001] * (N+1)\nq = [1]\ndist_fennec[1] = 0\nwhile q:\n now = q.pop()\n for next in tree[now]:\n if dist_fennec[next] == 100001:\n dist_fennec[next] = dist_fennec[now] + 1\n q.append(next)\n\nq = [N]\ndist_snuke[N] = 0\nwhile q:\n now = q.pop()\n for next in tree[now]:\n if dist_snuke[next] == 100001:\n dist_snuke[next] = dist_snuke[now] + 1\n q.append(next)\n\nfennec, snuke = 0, 0\nfor i in range(1, N+1):\n if dist_snuke[i] <= dist_fennec[i]:\n fennec += 1\n else:\n snuke += 1\n\nif fennec > snuke:\n print("Fennec")\nelse:\n print("Snuke")\n', 'import sys\ninput = sys.stdin.readline\nN = int(input())\ntree = [[] for i in range(N+1)]\n\nfor i in range(N-1):\n a, b = map(int, input().split())\n tree[a].append(b)\n tree[b].append(a)\n\ndist_fennec = [100001] * (N+1)\ndist_snuke = [100001] * (N+1)\nq = [1]\ndist[1] = 0\nwhile q:\n now = q.pop()\n for next in tree[now]:\n if dist_fennec[next] == 100001:\n dist_fennec[next] = dist_fennec[now] + 1\n q.append(next)\n\nq = [N]\ndist[N] = 0\nwhile q:\n now = q.pop()\n for next in tree[now]:\n if dist_snuke[next] == 100001:\n dist_snuke[next] = dist_snuke[now] + 1\n q.append(next)\n\nfennec, snuke = 0, 0\nfor i in range(1, N+1):\n if dist_snuke[i] <= dist_fennec[i]:\n fennec += 1\n else:\n snuke += 1\n\nif fennec > snuke:\n print("Fennec")\nelse:\n print("Snuke")\n', 'import sys\ninput = sys.stdin.readline\nN = int(input())\ntree = [[] for i in range(N+1)]\n\nfor i in range(N-1):\n a, b = map(int, input().split())\n tree[a].append(b)\n tree[b].append(a)\n\ndist_fennec = [100001] * (N+1)\ndist_snuke = [100001] * (N+1)\nq = [1]\ndist_fennec[1] = 0\nwhile q:\n now = q.pop()\n for next in tree[now]:\n if dist_fennec[next] == 100001:\n dist_fennec[next] = dist_fennec[now] + 1\n q.append(next)\n\nq = [N]\ndist_snuke[N] = 0\nwhile q:\n now = q.pop()\n for next in tree[now]:\n if dist_snuke[next] == 100001:\n dist_snuke[next] = dist_snuke[now] + 1\n q.append(next)\n\nfennec, snuke = 0, 0\nfor i in range(1, N+1):\n if dist_snuke[i] >= dist_fennec[i]:\n fennec += 1\n else:\n snuke += 1\n\nif fennec > snuke:\n print("Fennec")\nelse:\n print("Snuke")\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s834701118', 's868778104', 's082517784'] | [28976.0, 22704.0, 28976.0] | [434.0, 216.0, 441.0] | [851, 838, 851] |
p03662 | u536113865 | 2,000 | 262,144 | Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally. | ["ai = lambda: list(map(int,input().split()))\nai_ = lambda: [int(x)-1 for x in input().split()]\n\nn = int(input())\n\npath = [[] for _ in range(n)]\nfor _ in range(n-1):\n a,b = ai_()\n path[a].append(b)\n path[b].append(a)\n\nfrom collections import deque\nq = deque()\nq.append(0)\n\nd1 = [float('inf') for _ in range(n)]\nd1[0] = 0\nc = 0\nw = set()\nwhile q:\n c += 1\n v = q.popleft()\n w.add(v)\n for vv in path[v]:\n if vv not in w:\n d1[vv] = c\n q.append(vv)\n\n\nq = deque()\nq.append(n-1)\n\ndn = [float('inf') for _ in range(n)]\ndn[n-1] = 0\nc = 0\nw = set()\nwhile q:\n c += 1\n v = q.popleft()\n w.add(v)\n for vv in path[v]:\n if vv not in w:\n dn[vv] = c\n q.append(vv)\n\n\nprint(d1,dn)\nd = [1 if d1[v] >= dn[v] else 0 for v in range(n)]\n\nif d.count(1) > d.count(0):\n print('Snuke')\nelse:\n print('Fennec')\n", "ai = lambda: list(map(int,input().split()))\nai_ = lambda: [int(x)-1 for x in input().split()]\n\nn = int(input())\n\npath = [[] for _ in range(n)]\nfor _ in range(n-1):\n a,b = ai_()\n path[a].append(b)\n path[b].append(a)\n\nfrom collections import deque\nq = deque()\nq.append(0)\n\nd1 = [float('inf') for _ in range(n)]\nd1[0] = 0\nw = set()\nwhile q:\n v = q.popleft()\n w.add(v)\n for vv in path[v]:\n if vv not in w:\n d1[vv] = d1[v] + 1\n q.append(vv)\n\n\nq = deque()\nq.append(n-1)\n\ndn = [float('inf') for _ in range(n)]\ndn[n-1] = 0\nw = set()\nwhile q:\n v = q.popleft()\n w.add(v)\n for vv in path[v]:\n if vv not in w:\n dn[vv] = dn[v] + 1\n q.append(vv)\n\n\nd = [1 if d1[v] <= dn[v] else -1 for v in range(n)]\n\nif sum(d) > 0:\n print('Fennec')\nelse:\n print('Snuke')\n"] | ['Wrong Answer', 'Accepted'] | ['s653908188', 's536589500'] | [39868.0, 38444.0] | [712.0, 691.0] | [875, 832] |
p03662 | u547167033 | 2,000 | 262,144 | Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally. | ["n=int(input())\ntree=[[] for i in range(n)]\nfor i in range(n-1):\n a,b=map(int,input().split())\n tree[a-1].append(b-1)\n tree[b-1].append(a-1)\ndef dist(k):\n l=[-1]*n\n node=[k]\n while node:\n s=node.pop()\n d=l[s]\n for t in tree[s]:\n if l[t]!=-1:\n continue\n l[t]=d+1\n node.append(t)\n return l\nfrom_fennec=dist(0)\nfrom_snuke=dist(n-1)\nres=0\nfor i,j in zip(from_fennec,from_snuke):\n if i>=j:\n res+=1\n else:\n res-=1\nprint('Snuke' if res>=0 else 'Fennec')", "n=int(input())\ntree=[[] for i in range(n)]\nfor i in range(n-1):\n a,b=map(int,input().split())\n tree[a-1].append(b-1)\n tree[b-1].append(a-1)\ndef dist(k):\n l=[-1]*n\n node=[k]\n while node:\n s=node.pop()\n d=l[s]\n for t in tree[s]:\n if l[t]!=-1:\n continue\n l[t]=d+1\n node.append(t)\n return l\nfrom_fennec=dist(0)\nfrom_snuke=dist(n-1)\nres=0\nfor i,j in zip(from_fennec,from_snuke):\n if i<=j:\n res+=1\n else:\n res-=1\nprint('Snuke' if res<=0 else 'Fennec')"] | ['Wrong Answer', 'Accepted'] | ['s992030622', 's082684706'] | [28976.0, 28976.0] | [580.0, 536.0] | [491, 491] |
p03662 | u572144347 | 2,000 | 262,144 | Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally. | ['N=int(input())\nimport sys\nab=[list(map(int, input().split())) for _ in range (N-1)]\ncon=[[] for _ in range(N+1)]\n\n#print(ab)\nfor a,b in ab :\n con[a].append(b)\n con[b].append(a)\n\n\npc=[0]*(N+1)\nq=[(1,0)]\nvis=[False]*(N+1)\nvis[1]=True\nFcnt=N\nwhile q:\n n,c=q.pop()\n pc[n]=c\n for ch in con[n]:\n if vis[ch]==True:\n continue\n q.append((ch,c+1))\n \nq=[(N,0)]\nvis=[False]*(N+1)\nvis[1]=True\nwhile q:\n n,c=q.pop()\n if pc[n]>c:\n Fcnt-=1\n for ch in con[n]:\n if vis[ch]==True:\n continue\n q.append((ch,c+1))\n \nif Fcnt>N-Fcnt:\n print("Fennec")\nelse:\n print("Snuke")\n', 'N=int(input())\nimport sys\nab=[[int(j) for j in sys.stdin.readline()] for _ in range (N-1)]\ncon=[[] for _ in range(N+1)]\n\nfor a,b in ab :\n con[a].append(b)\n con[b].append(a)\n\n\npc=[0]*(N+1)\nq=[(1,0)]\nvis=[False]*(N+1)\nvis[1]=True\nFcnt=N\nwhile q:\n n,c=q.pop()\n pc[n]=c\n for ch in con[n]:\n if vis[ch]==True:\n continue\n q.append((ch,c+1))\n \nq=[(N,0)]\nvis=[False]*(N+1)\nvis[1]=True\nwhile q:\n n,c=q.pop()\n if pc[n]>c:\n Fcnt-=1\n for ch in con[n]:\n if vis[ch]==True:\n continue\n q.append((ch,c+1))\n \nif Fcnt>N-Fcnt:\n print("Fennec")\nelse:\n print("Snuke")', 'N=int(input())\n\nimport sys\nsys.setrecursionlimit(10**5)\nab=[list(map(int, input().split())) for _ in range (N-1)]\ncon=[[] for _ in range(N+1)]\n\n#print(ab)\nfor a,b in ab :\n con[a].append(b)\n con[b].append(a)\n\n\npc=[0]*(N+1)\nq=[(1,0)]\nvis=[False]*(N+1)\nvis[1]=True\nFcnt=N\nwhile q:\n n,c=q.pop()\n pc[n]=c\n for ch in con[n]:\n if vis[ch]==True:\n continue\n vis[ch]=True\n q.append((ch,c+1))\n \nq=[(N,0)]\nvis=[False]*(N+1)\nvis[N]=True\nwhile q:\n n,c=q.pop()\n if pc[n]>c:\n Fcnt-=1\n for ch in con[n]:\n if vis[ch]==True:\n continue\n vis[ch]=True\n q.append((ch,c+1))\n \nif Fcnt>N-Fcnt:\n print("Fennec")\nelse:\n print("Snuke")\n'] | ['Time Limit Exceeded', 'Runtime Error', 'Accepted'] | ['s166148780', 's411811790', 's653256270'] | [411220.0, 3064.0, 40140.0] | [2131.0, 18.0, 673.0] | [603, 598, 667] |
p03662 | u803848678 | 2,000 | 262,144 | Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally. | [' \n \n \n # EF-| |-GH...\n \n \n \n \n \n n = int(input())\n INF = 10**6\n graph = [[float("inf")]*n for i in range(n)]\n for i in range(n - 1):\n a, b = map(int, input().split())\n graph[a - 1][b -1] = 1\n graph[b - 1][a - 1] = 1\n \n \n \n \n import heapq\n \n class Dijkstra(object):\n def dijkstra(self, adj, start, goal=None):\n \n num = len(adj) \n dist = [float(\'inf\') for i in range(num)] \n prev = [float(\'inf\') for i in range(num)] \n \n dist[start] = 0\n q = [] \n heapq.heappush(q, (0, start)) \n \n while len(q) != 0:\n prov_cost, src = heapq.heappop(q) # pop\n \n \n if dist[src] < prov_cost:\n continue\n \n \n for dest in range(num):\n cost = adj[src][dest]\n if cost != float(\'inf\') and dist[dest] > dist[src] + cost:\n dist[dest] = dist[src] + cost \n heapq.heappush(q, (dist[dest], dest)) \n prev[dest] = src \n \n if goal is not None:\n return self.get_path(goal, prev)\n else:\n return dist\n \n def get_path(self, goal, prev):\n \n path = [goal] \n dest = goal\n \n \n while prev[dest] != float(\'inf\'):\n path.append(prev[dest])\n dest = prev[dest]\n \n \n return list(reversed(path))\n d = Dijkstra()\n \n \n cnt = 0\n for i, j in zip(d.dijkstra(graph, start=0,), d.dijkstra(graph, start=n-1)):\n if i <= j:\n cnt += 1\n print("Fennec" if cnt > n//2 else "Snuke")\n ', 'from collections import deque\nn = int(input())\nboard = [0]*n\nedge = [[] for i in range(n)]\nfor i in range(n-1):\n a,b = map(int, input().split())\n edge[a-1].append(b-1)\n edge[b-1].append(a-1)\nq = deque()\nq.append((0,1))\nq.append((-1,-1))\nwhile q:\n from_, color = q.popleft()\n if board[from_] != 0:\n continue\n board[from_] = color\n for i in edge[from_]:\n q.append((i,color))\nif sum(board) > 0:\n print("Fennec")\nelse:\n print("Snuke")'] | ['Runtime Error', 'Accepted'] | ['s393382813', 's924871473'] | [2940.0, 24980.0] | [17.0, 479.0] | [4670, 471] |
p03662 | u884982181 | 2,000 | 262,144 | Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally. | ['import sys\nsys.setrecursionlimit(2000000)\nn = int(input())\np = []\nfor i in range(n-1):\n p.append(list(map(int, input().split()))+ [1])\nl = [[] for i in range(n+1)]\nfor pi in p: \n l[pi[0]].append([pi[0],pi[1]])\n l[pi[1]].append([pi[1],pi[0]])\nkyo = [float("inf")]*(n+1)\nkyo[1] = 0\nmemo = [0] * (n+1)\nmemo[1] = 1\nruto = []\ndef dfs(start,ruto):\n ruto.extend(l[start])\n memo[start] = 1\n while ruto:\n a = ruto.pop()\n if memo[a[1]] == 1:\n continue\n kyo[a[1]] = kyo[a[0]] + 1\n dfs(a[1],ruto)\n return\ndfs(1,ruto)\n\nnkyo = [float("inf")]*(n+1)\nnkyo[n] = 0\nmemo = [0] * (n+1)\nmemo[n] = 1\nruto = []\ndef dfs(start,ruto):\n ruto.extend(l[start])\n memo[start] = 1\n while ruto:\n a = ruto.pop()\n if memo[a[1]] == 1:\n continue\n nkyo[a[1]] = nkyo[a[0]] + 1\n dfs(a[1],ruto)\n return\ndfs(n,ruto)\niti = 0\nnko = 0\nfor i in range(1,n+1):\n if kyo[i] <= nkyo[i]:\n iti += 1\n else:\n nko += 1\nprint(kyo,nkyo)\nif iti <= nko:\n print("Snuke")\nelse:\n print("Fennec")', 'import sys\nsys.setrecursionlimit(2000000)\nn = int(input())\np = []\nfor i in range(n-1):\n p.append(list(map(int, input().split()))+ [1])\nl = [[] for i in range(n+1)]\nfor pi in p: \n l[pi[0]].append([pi[0],pi[1]])\n l[pi[1]].append([pi[1],pi[0]])\nkyo = [float("inf")]*(n+1)\nkyo[1] = 0\nmemo = [0] * (n+1)\nmemo[1] = 1\nruto = []\ndef dfs(start,ruto):\n ruto.extend(l[start])\n memo[start] = 1\n while ruto:\n a = ruto.pop()\n if memo[a[1]] == 1:\n continue\n kyo[a[1]] = kyo[a[0]] + 1\n dfs(a[1],ruto)\n return\ndfs(1,ruto)\n\nnkyo = [float("inf")]*(n+1)\nnkyo[n] = 0\nmemo = [0] * (n+1)\nmemo[n] = 1\nruto = []\ndef dfs(start,ruto):\n ruto.extend(l[start])\n memo[start] = 1\n while ruto:\n a = ruto.pop()\n if memo[a[1]] == 1:\n continue\n nkyo[a[1]] = nkyo[a[0]] + 1\n dfs(a[1],ruto)\n return\ndfs(n,ruto)\niti = 0\nnko = 0\nfor i in range(1,n+1):\n if kyo[i] <= nkyo[i]:\n iti += 1\n else:\n nko += 1\nif iti <= nko:\n print("Snuke")\nelse:\n print("Fennec")'] | ['Wrong Answer', 'Accepted'] | ['s276286326', 's275474012'] | [145604.0, 142340.0] | [1423.0, 1618.0] | [992, 976] |
p03662 | u957084285 | 2,000 | 262,144 | Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally. | ['n = int(input())\nedges = [[] for _ in range(n)]\n\nfor _ in range(n-1):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n edges[a].append(b)\n edges[b].append(a)\n\ndef bfs(v):\n q = []\n depth = [n]*n\n q.append(v)\n depth[v] = 0\n i = 0\n while i < len(q):\n x = q[i]\n d = depth[x]\n for e in edges[x]:\n if depth[e] == n:\n depth[e] = d+1\n q.append(e)\n i += 1\n return depth\n\nd1 = bfs(0)\nd2 = bfs(n-1)\n\nc = 0\nfor i in range(n):\n if d1[i] <= d2[i]:\n c += 1\nprint(c)\nif 2*c > n:\n print("Fennec")\nelse:\n print("Sunuke")\n', 'n = int(input())\nedges = [[] for _ in range(n)]\n\nfor _ in range(n-1):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n edges[a].append(b)\n edges[b].append(a)\n\ndef bfs(v):\n q = []\n depth = [n]*n\n q.append(v)\n depth[v] = 0\n i = 0\n while i < len(q):\n x = q[i]\n d = depth[x]\n for e in edges[x]:\n if depth[e] == n:\n depth[e] = d+1\n q.append(e)\n i += 1\n return depth\n\nd1 = bfs(0)\nd2 = bfs(n-1)\n\nc = 0\nfor i in range(n):\n if d1[i] <= d2[i]:\n c += 1\nif 2*c > n:\n print("Fennec")\nelse:\n print("Snuke")\n'] | ['Wrong Answer', 'Accepted'] | ['s539314216', 's350195112'] | [29788.0, 29788.0] | [584.0, 599.0] | [626, 616] |
p03662 | u980322611 | 2,000 | 262,144 | Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally. | ['class UnionFind:\n def __init__(self, n):\n self.par = [-1 for i in range(n+1)]\n self.rank = [0] * (n+1)\n\n \n def find(self, x):\n if self.par[x] < 0:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if not x==y: \n if self.rank[x] < self.rank[y]:\n self.par[y] += self.par[x] \n self.par[x] = y \n else:\n self.par[x] += self.par[y]\n self.par[y] = x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n \n \n def same_check(self, x, y):\n return self.find(x) == self.find(y) \n\ndef main():\n import sys\n input = sys.stdin.readline\n \n N = int(input())\n from collections import defaultdict,deque\n G = defaultdict(list)\n D = []\n for i in range(N-1):\n a, b = map(int,input().split())\n D.append([a,b])\n G[a].append(b)\n G[b].append(a)\n \n que = deque()\n que.append(1)\n visited = {}\n oya = [-1]*(10**5+1)\n while que != deque():\n v = que.pop()\n visited[v] = 1\n if v == N:\n break\n else:\n for i in G[v]:\n if not i in visited:\n oya[i] = v\n que.append(i)\n now = N\n path = []\n while now != -1:\n path.append(now)\n now = oya[now]\n path = path[::-1]\n print(path)\n L = len(path)\n if L%2==0:\n d1,d2 = path[L//2-1],path[L//2]\n else:\n d1,d2 = path[L//2],path[L//2+1]\n G2 = UnionFind(N)\n \n for i in D:\n a,b = i\n if not {a,b} == {d1,d2}:\n G2.union(a,b)\n one = -G2.par[G2.find(1)]\n enu = -G2.par[G2.find(N)]\n \n if one>enu:\n print("Fennec")\n else:\n print("Snuke")\n \n\nmain()', 'class UnionFind:\n def __init__(self, n):\n self.par = [-1 for i in range(n+1)]\n self.rank = [0] * (n+1)\n\n \n def find(self, x):\n if self.par[x] < 0:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if not x==y: \n if self.rank[x] < self.rank[y]:\n self.par[y] += self.par[x] \n self.par[x] = y \n else:\n self.par[x] += self.par[y]\n self.par[y] = x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n \n \n def same_check(self, x, y):\n return self.find(x) == self.find(y) \n\ndef main():\n import sys\n input = sys.stdin.readline\n \n N = int(input())\n from collections import defaultdict,deque\n G = defaultdict(list)\n D = []\n for i in range(N-1):\n a, b = map(int,input().split())\n D.append([a,b])\n G[a].append(b)\n G[b].append(a)\n \n que = deque()\n que.append(1)\n visited = {}\n oya = [-1]*(10**5+1)\n while que != deque():\n v = que.pop()\n visited[v] = 1\n if v == N:\n break\n else:\n for i in G[v]:\n if not i in visited:\n oya[i] = v\n que.append(i)\n now = N\n path = []\n while now != -1:\n path.append(now)\n now = oya[now]\n path = path[::-1]\n #print(path)\n L = len(path)\n if L%2==0:\n d1,d2 = path[L//2-1],path[L//2]\n else:\n d1,d2 = path[L//2],path[L//2+1]\n G2 = UnionFind(N)\n \n for i in D:\n a,b = i\n if not {a,b} == {d1,d2}:\n G2.union(a,b)\n one = -G2.par[G2.find(1)]\n enu = -G2.par[G2.find(N)]\n \n if one>enu:\n print("Fennec")\n else:\n print("Snuke")\n \n\nmain()'] | ['Wrong Answer', 'Accepted'] | ['s720861703', 's184788039'] | [50208.0, 50208.0] | [538.0, 512.0] | [2097, 2098] |
p03665 | u017810624 | 2,000 | 262,144 | There are N bags of biscuits. The i-th bag contains A_i biscuits. Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags. He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are? | ['n,p=map(int,input().split())\na=list(map(int,input().split()))\nc=0\nfor i in range(n):\n if a[i]%2==1:\n c=1\n break\nif c=1:print(2**(n-1))\nelse:\n if p=0:print(2**(n))\n else:print(0)', 'n,p=map(int,input().split())\na=list(map(int,input().split()))\nc=0\nfor i in range(n):\n if a[i]%2==1:c+=1\nif c==0:\n if p==0:print(2**n)\n else:print(0)\nelif c==n:\n if n!=1:print(2**(n-1))\n else:print(0)\nelse:print(2**(n-1))'] | ['Runtime Error', 'Accepted'] | ['s539365411', 's535662739'] | [2940.0, 3060.0] | [17.0, 17.0] | [186, 225] |
p03665 | u022317850 | 2,000 | 262,144 | There are N bags of biscuits. The i-th bag contains A_i biscuits. Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags. He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are? | ['def cmb(n, k):\n s = 1\n for j in range(n - k):\n s *= j\n for j in range(1, k+1):\n s //= j\n return s\n\nn, p = map(int, input().split())\naa = list(map(lambda x: int(x) % 2, input().split()))\nodd = sum(aa)\neven = n - odd\nif p == 0:\n c = 2**even * sum(cmb(odd, k) for k in range(0, odd+1, 2))\n print(c)\nelse:\n c = 2**even * sum(cmb(odd, k) for k in range(1, odd+1, 2))\n print(c)', 'def cmb(n, k):\n s = 1\n for j in range(n - k + 1, n + 1, 1):\n s *= j\n for j in range(1, k+1):\n s //= j\n return s\n\nn, p = map(int, input().split())\naa = list(map(lambda x: int(x) % 2, input().split()))\nodd = sum(aa)\neven = n - odd\nif p == 0:\n c = 2**even * sum(cmb(odd, k) for k in range(0, odd+1, 2))\n print(c)\nelse:\n c = 2**even * sum(cmb(odd, k) for k in range(1, odd+1, 2))\n print(c)\n'] | ['Wrong Answer', 'Accepted'] | ['s121503991', 's528920547'] | [3064.0, 3064.0] | [17.0, 17.0] | [385, 400] |
p03665 | u060793972 | 2,000 | 262,144 | There are N bags of biscuits. The i-th bag contains A_i biscuits. Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags. He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are? | ['import math\ndef AGC017C(a,f):\n p=0\n for i in range(f,a,2):\n p+=math.factorial(a)//math.factorial(a-i)//math.factorial(i)\n return p\n\nn,p=map(int,input().split())\nd={1:0,0:0}\na=list(map(int,input().split()))\nfor i in a:\n d[i%2]+=1\nif p==0:\n print((2**d[0])*AGC017C(d[1]),0)\nelse:\n if d[1]==0:\n print(0)\n else:\n print((2**d[0])*(AGC017C(d[1],1)))', 'import math\ndef AGC017C(a,f):\n p=0\n for i in range(f,a,2):\n p+=math.factorial(a)//math.factorial(a-i)//math.factorial(i)\n return p\n\nn,p=map(int,input().split())\nd={1:0,0:0}\na=list(map(int,input().split()))\nfor i in a:\n d[i%2]+=1\nprint(d)\nprint(AGC017C(2,0))\nif p==0:\n print((2**d[0])*AGC017C(d[1]),0)\nelse:\n if d[1]==0:\n print(0)\n else:\n print((2**d[0])*(AGC017C(d[1],1)))', 'import math\ndef AGC017C(a,f):\n p=0\n for i in range(f,a+1,2):\n p+=math.factorial(a)//math.factorial(a-i)//math.factorial(i)\n return p\n\nn,p=map(int,input().split())\nd={1:0,0:0}\na=list(map(int,input().split()))\nfor i in a:\n d[i%2]+=1\nif p==0:\n print((2**d[0])*AGC017C(d[1],0))\nelse:\n if d[1]==0:\n print(0)\n else:\n print((2**d[0])*(AGC017C(d[1],1)))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s578014510', 's974725487', 's742854494'] | [3064.0, 3064.0, 3064.0] | [17.0, 18.0, 18.0] | [385, 414, 387] |
p03665 | u077291787 | 2,000 | 262,144 | There are N bags of biscuits. The i-th bag contains A_i biscuits. Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags. He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are? | ['\ndef main():\n n, p = tuple(map(int, input().rstrip().split()))\n A = tuple(map(lambda x: int(x) % 2, input().rstrip().split()))\n if sum(A) == n: # all numbers are even\n print(2 ** n if p == 0 else 0)\n else:\n print(2 ** (n - 1))\n\n\nif __name__ == "__main__":\n main()', '\ndef main():\n N, P, *A = map(int, open(0).read().split())\n total = sum(i % 2 for i in A)\n if total == 0: # all numbers are even\n flg = P == 0\n print(2 ** N if flg else 0)\n else:\n print(2 ** (N - 1))\n\n\nif __name__ == "__main__":\n main()'] | ['Wrong Answer', 'Accepted'] | ['s484665480', 's482440762'] | [3316.0, 3060.0] | [23.0, 18.0] | [313, 292] |
p03665 | u102461423 | 2,000 | 262,144 | There are N bags of biscuits. The i-th bag contains A_i biscuits. Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags. He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are? | ['N,P = int(input())\nA = [int(x) for x in input().split()]\n\nodd = sum(x&1 for x in A)\n\nif odd:\n \n answer = 2**(N-1)\nelse:\n answer = (2 ** N) * P\n\nprint(answer)', 'import sys\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nN, P, *A = map(int, read().split())\n\nA = [x & 1 for x in A]\n\nif A.count(1):\n x = pow(2, N - 1)\nelse:\n x = pow(2, N)\n if P:\n x = 0\nprint(x)'] | ['Runtime Error', 'Accepted'] | ['s541856123', 's878844721'] | [2940.0, 8996.0] | [17.0, 28.0] | [186, 272] |
p03665 | u106778233 | 2,000 | 262,144 | There are N bags of biscuits. The i-th bag contains A_i biscuits. Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags. He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are? | ['N,P=map(int,input().split())\nA=list(map(int,input().split()))\nfor i in range(N):\n A[i]%=2\n\nodds=sum(A)\nevens=N-odds \nif odds>0:\n ans=2**evens \n ans+=2**(odds-1)\n print(ans)\nelse:\n if P==0:\n print(2**evens)\n else:\n print(0)', 'odds=sum(A)\nevens=N-odds \nif odds>0:\n ans=2**evens \n ans*=2**(odds-1)\n print(ans)\nelse:\n if P==0:\n print(2**evens)\n else:\n print(0)\n', 'N,P=map(int,input().split())\nA=list(map(int,input().split()))\nfor i in range(N):\n A[i]%=2\n\nodds=sum(A)\nevens=N-odds \nif odds>0:\n ans=2**evens \n ans*=2**(odds-1)\n print(ans)\nelse:\n if P==0:\n print(2**evens)\n else:\n print(0)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s510391123', 's615371882', 's538281128'] | [3060.0, 2940.0, 3064.0] | [17.0, 17.0, 17.0] | [254, 161, 254] |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.