TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
import sys

N = int(input())
ls = list(map(int, input().split()))
k = len(ls)
p = [ i for i in ls if (i%4) == 0]
j = [ i for i in ls if (i%4) != 0]
r = [ i for i in j if (i%2) == 0]

if(len(p) >= int(k/2)):
    print('Yes')
elif (len(p) >= (len(j) - len(r))):
    print('Yes')
else:
    print('No')
----

import sys

N = int(input())
ls = list(map(int, input().split()))
k = len(ls)
p = [ i for i in ls if (i%4) == 0]
j = [ i for i in ls if (i%4) != 0]
r = [ i for i in j if (i%2) == 0]

if(len(p) >= int(k/2)):
    print('Yes')
elif (len(p) >= (len(j) - len(r))):
    print('Yes')
else:
    print('No')

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
a=[int(i) for i in input().split()]
num4=0
num2=0
num1=0
for i in a:
        if i%4==0:
                num4+=1
        elif i%2==0:
                num2+=1
num1=N-num4-num2

if num2>0:
        num1+=1

if num1<=num4+1:
        print("Yes")
else:
        print("No")                                                                      ~                                                                                   ~                                

N=int(input())
a=[int(i) for i in input().split()]
num4=0
num2=0
num1=0
for i in a:
        if i%4==0:
                num4+=1
        elif i%2==0:
                num2+=1
num1=N-num4-num2

if num2>0:
        num1+=1

if num1<=num4+1:
        print("Yes")
else:
        print("No")

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,a=open(0)
a=[int(i)%4for i in a.split()]
f,g=a.count(0),a.count(2)
print('YNeos'[int(n)-f-g>f+(g==0)])

n,a=open(0)
c=[int(i)%4for i in a.split()].count
f,g=c(0),c(2)
print('YNeos'[int(n)-f-g>f+(g==0)::2])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
a = list(map(int, input().split()))
c2=c4=0

for i in range(len(N)):
  if a[i]%4==0:
    c4+=1
  if a[i]%2==0:
    c2+=1

nodd=N-c2
c4=c4-c2

if nodd<c4:
  print("Yes")
else:
  print("No")

N = int(input())
a = list(map(int, input().split()))
c2=c4=0

for i in range(N):
  if a[i]%4==0:
    c4+=1
  if a[i]%2==0:
    c2+=1

nodd=N-c2
c2=c2-c4
if c2>0:
  nodd+=1
if c4>=nodd-1:
  print("Yes")
else:
  print("No")


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
ans='No'
a2=[i//2 for i in a if i%2==0]
a4=[i for i in a2 if i%2==0]
la2=len(a2)
la4=len(a4)
if la2+la4>=n:
    ans='Yes'
print(ans)
print(a2)
print(a4)

n=int(input())
a=list(map(int,input().split()))
ans='No'
a2=[i//2 for i in a if i%2==0]
a4=[i for i in a2 if i%2==0]
la2=len(a2)
la4=len(a4)
if la2+la4>=n and la2>0:
    ans='Yes'
elif la2==la4 and 2*la4+1>=n:
    ans='Yes'
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
odds = 0
evens2 = 0
evens4 = 
for ai in a :
    if ai % 4 == 0 :
        evens4 += 1
    elif ai % 2 == 0 :
        evens2 += 1
    else :
        odds += 1

if evens4 >= odds :
    print('Yes')
elif odds - evens4 == 1 and evens2 == 0 :
    print('Yes')
else :
    print('No')

n = int(input())
a = list(map(int, input().split()))
odds = 0
evens2 = 0
evens4 = 
for ai in a :
    if ai % 4 == 0 :
        evens4 += 1
    elif ai % 2 == 0 :
        evens2 += 1
    else :
        odds += 1

if evens4 >= odds :
    print('Yes')
elif odds - evens4 == 1 and evens2 == 0 :
    print('Yes')
else :
    print('No')

n = int(input())
a = list(map(int, input().split()))
odds = 0
evens2 = 0
evens4 = 0
for ai in a :
    if ai % 4 == 0 :
        evens4 += 1
    elif ai % 2 == 0 :
        evens2 += 1
    else :
        odds += 1

if evens4 >= odds :
    print('Yes')
elif odds - evens4 == 1 and evens2 == 0 :
    print('Yes')
else :
    print('No')

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

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

f,t,z=0,0,0
for x in xs:
  if x % 4 == 0:
    f+=1
  elif x % 2 == 0:
    t += 1
  else:
    z += 1
z += t
print('Yes' if z + 1 < f then 'No')


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

f,t,z=0,0,0
for x in xs:
  if x % 4 == 0:
    f+=1
  elif x % 2 == 0:
    t += 1
  else:
    z += 1
z += 0<t
print('Yes' if z + 1 < f else'No')


input()
xs=list(map(int, input().split()))
 
f,t,z=0,0,0
for x in xs:
  if x % 4 == 0:
    f+=1
  elif x % 2 == 0:
    t += 1
  else:
    z += 1
z += 0<t
print('Yes' if z - 2 < f else'No')

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
m=list(map(int,input().split()))
for i in range(n):
  a=0
  for m[i]>1:
    m[i]//=2
    a+=1
  if a>2:
    a=2
  m[i]=a
if m.count(2)>m.count(1):
  print("Yes")
else:
  print("No")

n=int(input())
m=list(map(int,input().split()))
for i in range(n):
  a=0
  while m[i]%2==0:
    m[i]//=2
    a+=1
  if a>2:
    a=2
  m[i]=a
if m.count(2)>=m.count(0):
  print("Yes")
elif m.count(0)==0:
  print("Yes")
elif m.count(1)==0 and m.count(2)>=m.count(0)-1:
  print("Yes")
else:
  print("No")


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())

two_ad = 0
four_ad = 0
other = 0
for _ in range(N):
  a = int(input())
  if a % 4 == 0 and a % 2 == 0:
    four_ad += 1
  elif a % 4 == 0:
    four_ad += 1
  elif a % 2 == 0:
    two_ad += 1
  else:
    other += 1

if not two_ad and not four_ad:
  ans = "No"
elif not two_ad:
  if other == four_ad + 1 or four_ad > other:
    ans = "Yes"
  else:
    ans = "No"
elif not four_ad:
  ans = "No"
elif not other:
  ans = "Yes"
elif four_ad == other == two_ad:
  ans = "Yes"
else:
  ans = "No"
print(ans)

N = int(input())
A = list(map(int,input().split()))
two_ad = 0
four_ad = 0
other = 0
for a in A:
  if a % 4 == 0:
    four_ad += 1
  elif a % 2 == 0:
    two_ad += 1
  else:
    other += 1

ans = "No"
if four_ad >= other:
  ans = "Yes"
elif four_ad == other - 1 and not two_ad:
  ans = "Yes"
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
l=[0,0,0]
for i in list(map(int,input().split())):
  if i%2:l[0]+=1
  elif i%4:l[1]+=1
  else:l[2]+=1

print("Yes" if l[2]>=l[0]+int(1<=l[1]) else "No")


n=int(input())
l=list(map(int,input().split()))
odd=len([1 for i in l if i%2])
t4=len([1 for i in l if i%4==0])
if odd*2<=t4:print("Yes")
else:print("No")

n=int(input())
l=list(map(int,input().split()))
odd=len([1 for i in l if i%2])
t4=len([1 for i in l if i%4==0])
if odd*2+1<=t4:print("Yes")
else:print("No")

n=int(input())
l=[0,0,0]
for i in list(map(int,input().split())):
  if i%2:l[0]+=1
  elif i%4:l[1]+=1
  else:l[2]+=1

print("Yes" if l[2]+1>=l[0]+int(1<=l[1]) else "No")

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))

num_four = 0
num_two = 0
num_odd = 0
for i in range(N):
    if A[i] % 4 == 0:
        num_four += 1
    elif A[i] % 2 == 0:
        num_two += 1
    else:
        num_odd += 1

# print(num_four, num_two, num_odd)

v = num_four * 2
if num_two == 0:
    v += 1
if num_two >= 2:
    v += num_two
ans = 'Yes' if v >= N else 'No'
print(ans)





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

num_four = 0
num_two = 0
num_odd = 0
for i in range(N):
    if A[i] % 4 == 0:
        num_four += 1
    elif A[i] % 2 == 0:
        num_two += 1
    else:
        num_odd += 1

# print(num_four, num_two, num_odd)

if num_two != 0:
    ans = 'Yes' if num_four + 1 >= num_odd + 1 else 'No'
else:
    ans = 'Yes' if num_four + 1 >= num_odd else 'No'
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from math import ceil
n=int(input())
ans4=0
ans2=0
ans0=0
a=list(map(int,input().split()))
for i in range(n):
  if a[i]%4==0:
    ans4+=1
  elif a[i]%2==0:
    ans2+=1
  else:
    ans0+=1
if ans2>0:
  if ans0<=ans4:
    print('Yes')
  else:
    print('No')
else:
  if ceil((ans0+ans4)/2)>=:ans0
    print('Yes')
  else:
    print('No')


from math import ceil
n=int(input())
ans4=0
ans2=0
a=list(map(int,input().split()))
for i in range(n):
  if a[i]%4==0:
    ans4+=1
  elif a[i]%2==0:
    ans2+=1
  else:
    pass
if ans2>0:
  if (n-ans2)<=ans4:
    print('Yes')
  else:
    print('No')
else:
  if ceil(n-ans2)>=(n-ans2-ans4):
    print('Yes')
  else:
    print('No')

n=int(input())
ans4=0
ans2=0
a=list(map(int,input().split()))
for i in range(n):
  if a[i]%4==0:
    ans4+=1
  elif a[i]%2==0:
    ans2+=1
  else:
    pass
if ans2>0:
  if n-ans2//2<=ans4:
    print('Yes')
  else:
    print('No')
else:
  if n/2<=ans4:
    print('Yes')
  else:
    print('No')

n=int(input())
ans4=0
ans2=0
a=list(map(int,input().split()))
for i in range(n):
  if a[i]%4==0:
    ans4+=1
  elif a[i]%2==0:
    ans2+=1
  else:
    pass
if ans2>0:
  if (n-ans2)+1//2<=ans4:
    print('Yes')
  else:
    print('No')
else:
  if n/2<=ans4:
    print('Yes')
  else:
    print('No')

n=int(input())
ans4=0
ans2=0
a=input().split()
for i in range(n):
  if a[i]%4==0:
    ans4+=1
  elif a[i]%2==0:
    ans2+=1
  else:
    pass
if (n-ans2)//2+1<=ans4:
  print('Yes')
else:
  print('No')

from math import ceil
n=int(input())
ans4=0
ans2=0
ans0=0
a=list(map(int,input().split()))
for i in range(n):
  if a[i]%4==0:
    ans4+=1
  elif a[i]%2==0:
    ans2+=1
  else:
    ans0+=1
if ans2>0:
  if ans0<=ans4:
    print('Yes')
  else:
    print('No')
else:
  if ceil((ans0+ans4)/2)>=ans0:
    print('Yes')
  else:
    print('No')


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import math

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

c_4=0
c_2=0

for i in l:
  if i%4==0:
    c_4+=1
  elif i%2==0:
    c_2+=1


if c_2==1:
  num=n
else:
  num=n-c_2  
  
if matj.ceil(num/2) <= c_4:
  ans="Yes"
elif c_2==n:
  ans="Yes"
else:
  ans="No"
  
print(ans)

import math

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

c_4=0
c_2=0

for i in l:
  if i%4==0:
    c_4+=1
  elif i%2==0:
    c_2+=1


if c_2==1:
  num=n
else:
  num=n-c_2  
  
if math.ceil(num/2) <= c_4:
  ans="Yes"
elif c_2==n:
  ans="Yes"
else:
  ans="No"
  
print(ans)

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

c_4=0
even=0
odd=0

for i in l:
  if i%4==0:
    c_4+=1
  elif i%2==0:
    even+=1
  else:
    odd+=1
  
if even==0 and odd-1 <= c_4:
  ans="Yes"
else:
  ans="No"
  
if even>0 and odd <= c_4:
  ans="Yes"
elif even>0:
  ans="No"

print(ans)


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = list(map(int, input().split()))
n, m = s[0], s[1]
ton = set()
tom = set()
if n == m:
    ton = {1, 2, 3}
    tom = {1, 2, 3}    
for i in range(m):
    s = list(map(int, input().split()))
    if s[0] == m:
        tom |= set(s)
    elif s[1] == m:
        tom |= set(s)
    elif s[1] == n:
        ton |= set(s)
    elif s[0] == n:
        ton |= set(s) 
ton -= {n, m}
print(ton)
tom -= {n, m}   
print(tom)
print(ton & tom)     
if ton & tom == set():
    print("IMPOSSIBLE")
else:
    print('POSSIBLE')

# 10 5
# 1 2
# 1 3
# 1 4
# 8 10
# 1 8

n, m = map(int, input().split())

ends = []
starts = []
possible = False
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        starts.append([a, b])
    elif b == n:
        ends.append([a, b])

starts.sort(key=lambda x: x[1])
ends.sort(key=lambda x: x[0])

if not (starts and ends):
    print("IMPOSSIBLE")
    import sys

    sys.exit()

i = 0
j = 0
while i != len(starts) and j != len(ends):
    to = starts[i][1]
    fr = ends[j][0]

    if to == fr:
        possible = True
        break

    if to < fr:
        i += 1
    elif fr < to:
        j += 1

while j != len(ends):
    fr = ends[j][0]
    if to == fr:
        possible = True
        break
    j += 1

while i != len(starts):
    to = starts[i][1]
    if to == fr:
        possible = True
        break
    i += 1

print("POSSIBLE") if possible else print("IMPOSSIBLE")


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,M = map(int,input().split())
ab = [[int(i) for i in input().split()] for _ in range(M)]

A = []
B = [0]*N
for a,b in ab:
  if a==1:
    A.append(a)
  if b==N:
    B[a]=1

for a in A:
  if B[a]==1:
    print("POSSIBLE")
    break
else:
  print("IMPOSSIBLE")

N,M = map(int,input().split())
ab = [[int(i) for i in input().split()] for _ in range(M)]

A = []
B = [0]*(N+1)
for a,b in ab:
  if a==1:
    A.append(b)
  if b==N:
    B[a]=1

for a in A:
  if B[a]==1:
    print("POSSIBLE")
    break
else:
  print("IMPOSSIBLE")

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a,b=map(int,input().split())
c=[list(map(int,input().split()))for i in[0]*b]
for i in range(3,a+1):
  if[1,i]in c and[i,a]in c:print('POSSIBLE');exit()
print('IMPOSSIBLE')

a,b=map(int,input().split())
c=[list(map(int,input().split()))for i in[0]*b]
d=[]
e=[]
for i in c:
  if i[0]==1:d+=[i[1]]
  elif i[1]==a:e+=[i[0]]
print((set(d)&set(e)==set())*'IM'+'POSSIBLE')

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a=[0]*(200001)


N = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(N[1])]

print(N,x)

for i in x:
    if i[0]==1 :
        if a[i[1]]==1:
            print('POSSIBLE')
            quit()
        a[i[1]]=1
    if i[1]==N[0]:
        if a[i[0]]==1:
            print('POSSIBLE')
            quit()
        a[i[0]]=1

print('IMPOSSIBLE')
quit()

import math
inf=float('inf')
a=[0]*(200001)


N = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(N[1])]

print(N,x)

for i in x:
    if i[0]==1 :
        if a[i[1]]==1:
            print('OK')
            quit()
        a[i[1]]=1
    if i[1]==N[0]:
        if a[i[0]]==1:
            print('OK')
            quit()
        a[i[0]]=1

print('NG')
quit()

a=[0]*(200001)


N = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(N[1])]


for i in x:
    if i[0]==1 :
        if a[i[1]]==1:
            print('POSSIBLE')
            quit()
        a[i[1]]=1
    if i[1]==N[0]:
        if a[i[0]]==1:
            print('POSSIBLE')
            quit()
        a[i[0]]=1

print('IMPOSSIBLE')
quit()

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x = input().split(" ")
n = int(x[0])
m = int(x[1])

probInit = set([])
probEnd  = set([])

for i in range(m):
    edge = input().split(" ")
    if edge[0] == 0:
        probInit.add(edge[1])

    if edge[1] == n - 1:
        probEnd.add(edge[0])

union = probEnd.union(probInit)
if (union == set([])):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


x = input().split(" ")
n = int(x[0])
m = int(x[1])

probInit = set([])
probEnd  = set([])

for i in range(m):
    edge = input().split(" ")
    if edge[0] == 0:
        probInit.add(edge[1])

    if edge[1] == n - 1:
        probEnd.add(edge[0])

union = probEnd.union(probInit)
if (len(union) == 0):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


k = int(input())
n = 50
m = (n - 1) * (k + 1) + 1


series = str(m)
for i in range(n):
    series = series + " 0"

print(str(n))
print(series)


x = input().split(" ")
n = int(x[0])
m = int(x[1])

probInit = set([])
probEnd  = set([])

for i in range(m):
    edge = input().split(" ")
    if edge[0] == 0:
        probInit.add(edge[1])

    if edge[1] == n - 1:
        probEnd.add(edge[0])

sec = probEnd.intersection(probInit)
if (len(sec) == 0):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


x = input().split(" ")
n = int(x[0])
m = int(x[1])

probInit = set([])
probEnd  = set([])

for i in range(m):
    edge = input().split(" ")
    if edge[0] == 0:
        probInit.add(edge[1])

    if edge[1] == n - 1:
        probEnd.add(edge[0])

sec = probEnd.intercection(probInit)
if (len(sec) == 0):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")



x = input().split(" ")
n = int(x[0])
m = int(x[1])

probInit = set([])
probEnd  = set([])

for i in range(m):
    edge = input().split(" ")
    if edge[0] == "1":
        probInit.add(edge[1])

    if edge[1] == str(n):
        probEnd.add(edge[0])

sec = probEnd.intersection(probInit)
if (len(sec) == 0):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))

s = sum(A) - N*(N-1)
m = sum(list(map(lambda x: (x+s)//N, A)))
while m > s:
    s = m
    m = sum(list(map(lambda x: (x+s)//N, A)))
else:
    print(m)

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

s = sum(A) - N*(N-1)
m = list(map(lambda x: (x+s)//N, A))
while m > s:
    s = m
    m = list(map(lambda x: (x+s)//N, A))
else:
    print(m)

N, M = map(int,input().split())
route_1 = set()
route_N = set()

for _ in range(M):
    a, b = map(int,input().split())
    if a == 1:
        route_1.add(b)
    elif b == N:
        route_N.add(a)

if route_1&route_N:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N,M=map(int,input().split())
a=[]
b=[]
for i in range(0,M):
	c,d=map(int,input().split())
	a.append(c)
	b.append(d)

pos=0
i=0
g=[0 for i in range(0,M)]
print(g)
e=[]
f=[]
k=0
l=0
while i < M and pos == 0:
	if a[i] == 1:
		g[b[i]] = 1
	if b[i] == 1:
		g[a[i]] = 1
	i=i+1
i=0
print(g)
while i < M and pos == 0:
	if a[i] == N:
		if g[b[i]] == 1:
			pos=1
	if b[i] == N:
		if g[a[i]] == 1:
			pos=1
	i = i + 1
if pos == 1:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

N,M=map(int,input().split())
a=[]
b=[]
for i in range(0,M):
	c,d=map(int,input().split())
	a.append(c)
	b.append(d)

pos=0
i=0
g=[0 for i in range(0,200000)]
e=[]
f=[]
k=0
l=0
while i < M and pos == 0:
	if a[i] == 1:
		g[b[i]] = 1
	if b[i] == 1:
		g[a[i]] = 1
	i=i+1
i=0
while i < M and pos == 0:
	if a[i] == N:
		if g[b[i]] == 1:
			pos=1
	if b[i] == N:
		if g[a[i]] == 1:
			pos=1
	i = i + 1
if pos == 1:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Verdicts: Runtime Error

Accepted
Problem: 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.

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

islands = [0 for i in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  
  if a == 1:
    if islands[b-1] == 2:
      print('Possible')
      break
    islands[b-1] = 1
  if b == n:
    if islands[a-1] == 1:
      print('Possible')
      break
    islands[a-1] = 2
    
  if i == m-1:
    print('Impossible')

n,m = map(int, input().split())

islands = [0 for i in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  
  if a == 1:
    if islands[b-1] == 2:
      print('POSSIBLE')
      break
    islands[b-1] = 1
  if b == n:
    if islands[a-1] == 1:
      print('POSSIBLE')
      break
    islands[a-1] = 2
    
  if i == m-1:
    print('IMPOSSIBLE')

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = list(map(int, input().split()))
n, m = s[0], s[1]
ton = set()
tom = set()
for i in range(m):
    s = list(map(int, input().split()))
    if s[0] == m:
        tom |= set(s)
    elif s[1] == m:
        tom |= set(s)
    elif s[1] == n:
        ton |= set(s)
    elif s[0] == n:
        ton |= set(s) 
ton -= {n, m}
tom -= {n, m}       
if ton & tom == set():
    print("IMPOSSIBLE")
else:
    print('POSSIBLE')

n,m = input().split()
n = int(n)
m = int(m)
l = [[] for i in range(n)]
for i in range(m):
    a,b = input().split()
    a = int(a)
    b = int(b)
    l[a-1].append(b-1)
    l[b-1].append(a-1)

f = False
for i in l[0]:
    for j in l[i]:
        if j == n-1:
            f = True
            break
if f:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,M=map(int,input().split())
x=[0]*(n+1)
y=[0]*(n+1)
for i in range(M):
    a,b=map(int,input().split())
    if a==1:
        x[b]=1
    if b==N:
        y[a]=1
for i in range(N+1):
    if x[i]==1 and y[i]==1:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

N,M=map(int,input().split())
x=[0]*(N+1)
y=[0]*(N+1)
for i in range(M):
    a,b=map(int,input().split())
    if a==1:
        x[b]=1
    if b==N:
        y[a]=1
for i in range(N+1):
    if x[i]==1 and y[i]==1:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())

import sys

teiki = defaultdict(set)
for i in range(M):
    a, b = map(int, input().split())
    teiki[a].add(b)


if 1 not in teiki:
    print('IMPOSSIBLE')
    sys.exit()

for i in teiki[1]:
    if i in teiki and N in teiki[i]:
        print('POSSIBLE')
        sys.exit()

print('IMPOSSIBLE')

from collections import defaultdict

N, M = map(int, input().split())

import sys

teiki = defaultdict(set)
for i in range(M):
    a, b = map(int, input().split())
    teiki[a].add(b)


if 1 not in teiki:
    print('IMPOSSIBLE')
    sys.exit()

for i in teiki[1]:
    if i in teiki and N in teiki[i]:
        print('POSSIBLE')
        sys.exit()

print('IMPOSSIBLE')

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
from_1 = [False]*N
to_N = [False]*N
for _ in range(M):
    a, b = map(int, input().split())
    if a-1 == 0:
        from_1[b-1] = True
    elif b-1 == 0:
        to_N[a-1] = True
for i in range(1, N):
    if from_1[i] and to_N[i]:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')

N, M = map(int, input().split())
from_1 = [False]*N
to_N = [False]*N
for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        from_1[b-1] = True
    elif b == N:
        to_N[a-1] = True
for i in range(1, N):
    if from_1[i] and to_N[i]:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*M]
g=[set() for _ in [0]*N]
[g[b-1].add(a-1) for a,b in ab]
[g[a-1].add(b-1) for a,b in ab]
a=g[0]
for i in a:
	if N-1 not in g[i]:
		print('IMPOSSIBLE')
		break
else:
	print('IPOSSIBLE')

N,M=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*M]
g=[set() for _ in [0]*N]
[g[b-1].add(a-1) for a,b in ab]
[g[a-1].add(b-1) for a,b in ab]
a=g[0]
print(a)
for i in a:
	if N-1 in g[i]:
		print('POSSIBLE')
		break
else:
	print('IMPOSSIBLE')

N,M=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*M]
g=[set() for _ in [0]*N]
[g[b-1].add(a-1) for a,b in ab]
[g[a-1].add(b-1) for a,b in ab]
a=g[0]
for i in a:
	if N-1 in g[i]:
		print('POSSIBLE')
		break
else:
	print('IMPOSSIBLE')

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
class UnionFind():
	def __init__(self,size):
		self.table = [-1 for _ in range(size)]

	def find(self,x):
		while self.table[x] >= 0:
			x = self.table[x]
		return x

	def unite(self,x,y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] != self.table[s2]:
				if self.table[s1] < self.table[s2]:
					self.table[s2] = s1
				else:
					self.table[s1] = s2
			else:
				self.table[s1] += -1
				self.table[s2] = s1
		return

	def same(self,x,y):
		return self.find(x) == self.find(y)


N, M = map(int,input().split())
edges = [[] for _ in range(N)]

for i in range(M):
	a, b = map(int,input().split())
	if a == 0 or a == N or b == 0 or b == N:
		edges[a-1] += [b-1]
		edges[b-1] += [a-1]

uf = UnionFind(N)

for u in edges[0]:
	if N-1 not in edges[0]:
		uf.unite(0,u)

for v in edges[N-1]:
	if 0 not in edges[N-1]:
		uf.unite(N-1,v)

print("POSSIBLE" if uf.same(0,N-1) == True else "IMPOSSIBLE")

N, M = map(int,input().split())

from1 = set()
gotoN = set()

for i in range(M):
	a, b = map(int,input().split())
	if a == 1:
		from1.add(b)
	elif a == N:
		gotoN.add(b)

	if b == 1:
		from1.add(a)
	elif b == N:
		gotoN.add(a)

res = from1 & gotoN

print("POSSIBLE" if len(res) > 0 else "IMPOSSIBLE")

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
import numpy as np

K = int(input())
K = K


a = np.ones(50).astype(np.int64)*(49) + (K)//50

if K%50 != 0:
    a[:K%50] += 51 - (K%50)
    a[K%50:] -= (K%50)
else:
    pass
              
result = "50\n{}".format(a[0])
for a_ in a[1:]:
    result += (" {}".format(int(a_)))
print(result)

# -*- coding: utf-8 -*-

N, M = [int(n) for n in input().split()]
islands = {n:[] for n in range(1, N+1)}
result = "IMPOSSIBLE"

for m in range(M):
    a, b = [int(n) for n in input().split()]
    islands[a].append(b)
    islands[b].append(a)

ok_isl = set()
search_isl = [1]
next_isl = set()

loop = True
for x in range(2):
    for i in search_isl:
        if N in islands[i]:
            loop = False
            result = "POSSIBLE"            
        else:
            next_isl.update(islands[i])
    
    ok_isl = ok_isl.union(search_isl)
    
    search_isl = next_isl.difference(ok_isl)
    if len(search_isl) == 0:
        break

print(result)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = list(map(int, input().split()))
n, m = s[0], s[1]
ton = set()
tom = set()
if n == m:
    ton = {1, 2, 3}
    tom = {1, 2, 3}    
for i in range(m):
    s = list(map(int, input().split()))
    if s[0] == m:
        tom |= set(s)
    elif s[1] == m:
        tom |= set(s)
    elif s[1] == n:
        ton |= set(s)
    elif s[0] == n:
        ton |= set(s) 
ton -= {n, m}
tom -= {n, m}   
if ton & tom == set():
    print("IMPOSSIBLE")
else:
    print('POSSIBLE')

n, m = map(int, input().split())

is1 = [False] * (n + 1)
isN = [False] * (n + 1)

for i in range(m):
    a, b = map(int, input().split())
    if(a > b):
        a, b = b, a
    if(a == 1):
        is1[b] = True
    if(b == n):
        isN[a] = True

import sys

for i in range(2, n):
    if(is1[i] and isN[i]):
        print("POSSIBLE")
        sys.exit(0)

print("IMPOSSIBLE")


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
    def f():
        n,m = map(int,input().split(" "))
        s = []
        w = [[] for i in range(n+2)]
        for i in range(m):
            a,b = map(int,input().split(" "))
            
            if a==1:
                s.append(b)
            if b==1:
                s.append(a)
            w[a].append(b)
            w[b].append(a)
        for i in s:
            if n in w[i]:
                print("POSSIBLE")
                return 0
        print("IMPOSSIBLE")
        return 0
    f()

def f():
    n,m = map(int,input().split(" "))
    s = []
    w = [[] for i in range(n+2)]
    for i in range(m):
        a,b = map(int,input().split(" "))
        
        if a==1:
            s.append(b)
        if b==1:
            s.append(a)
        w[a].append(b)
        w[b].append(a)
    for i in s:
        if n in w[i]:
            print("POSSIBLE")
            return 0
    print("IMPOSSIBLE")
    return 0
f()

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
graph = {i+1:[]  for i in range(N)}
for i in range(M):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

for value in graph[1]:
    if(N in graph[value]):
        print("POSSIBLE")
else:
    print("IMPOSSIBLE")

N, M = map(int, input().split())
graph = {i+1:[]  for i in range(N)}
for i in range(M):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

for value in graph[1]:
    if(N in graph[value]):
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
list_of_a = list(map(int, input().split()))

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
print(ng, ok)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

print(ok)

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

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

#'ok'-i (i=1..N) may be better

for i in range(0, 30 * N + 1):
    mid = ok - i
    if mid < 0:
        break
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count == mid:
        ans = mid

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
##create with UTF-8

n = int( input() )
da=list(map(int, input(). split()))
li=[da[i]%(n+1) for i in range(n)]
su=0
ans=0
for i in range(n):
	su+=da[i]
for i in range(n):
	div=(n-1)-(da[i]%(n+1))
	now=0
	ju=True
	for j in range(n):
		if (n+1+div+da[j])%(n+1)==n:
			ju=False
			break
		now+=(n+1+div+da[j])%(n+1)
	if ju and su >= now:
		print(now)
		ans = max(ans,now)
print(su-ans)

##create with UTF-8

n = int( input() )
da=list(map(int, input(). split()))
li=[da[i]%(n+1) for i in range(n)]
su=0
ans=0
for i in range(n):
	su+=da[i]
for i in range(n):
	div=(n-1)-(da[i]%(n+1))
	now=0
	ju=True
	for j in range(n):
		if (n+1+div+da[j])%(n+1)==n:
			ju=False
			break
		now+=(n+1+div+da[j])%(n+1)
	if ju and su >= now:
		#print(now)
		ans = max(ans,now)
print(su-ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))

def isOk(k):
    B = [a + k for a in A]
    cnt = 0
    for b in B:
        cnt += b // (N + 1)
    return cnt >= k

ok = 0
ng = 10**20
while ng - ok > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng =  mid
print(ok)

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

ans = 0
while max(A) >= N:
    i = A.index(max(A))
    k = A[i] // N
    A[i] %= N
    ans += k
    for j in range(N):
        if j != i:
            A[j] += k
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from numpy import int64, divmod

N, A = open(0)
N, A = int(N), int64(A.split())

ans = 0
S = -1
while S:
    B, A = A % N, A // N
    S = B.sum()
    ans += S
    A += S - B

print(ans)


from numpy import int64

N, A = open(0)
N, A = int(N), int64(A.split())

ans = 0
S = -1
while S:
    B, A = A % N, A // N
    S = B.sum()
    ans += S
    A += S - B

print(ans)


from numpy import int64

N, A = open(0)
N, A = int(N), int64(A.split())

ans = 0
S = -1
while S:
    B, A = A // N, A % N
    S = B.sum()
    ans += S
    A += S - B

print(ans)


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, *A = [int(_) for _ in open(0).read().split()]
sumB = max(0, sum(A) - N * (N - 1))
while True:
    B = [0 - (-(a + x + 1 - N)) // (N + 1) for a in A]
    if sumB == sum(B):
        break
    sumB += 1
print(sumB)


N, *A = [int(_) for _ in open(0).read().split()]
sumB = max(0, sum(A) - N * (N - 1))
while True:
    B = [0 - (-(a + sumB + 1 - N)) // (N + 1) for a in A]
    if sumB == sum(B):
        break
    sumB += 1
print(sumB)


Verdicts: Runtime Error

Accepted