ZhenlongDai/ACPR huggingface dataset:
Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

cnt = {0:1}

ans = 0

for i in range(1, n+1):
    left = i - k + 1
    if left >= 0:
        ldif = (a[left] - left) % k
        if ldif < 0: ldif += k
        cnt[ldif] -= 1
    
    a[i] += a[i-1]
    dif = (a[i] - i) % k
    if dif < 0: dif += k
    if dif not in cnt:
        cnt[dif] = 0
        
    ans += cnt[dif]
    cnt[dif] += 1

print(ans)

Failing test case input:
10 8
14 26 101 65 35 89 95 32 38 42

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

cnt = {0:1}

ans = 0

for i in range(1, n+1):
    left = i - k
    if left >= 0:
        ldif = (a[left] - left) % k
        if ldif < 0: ldif += k
        cnt[ldif] -= 1
    
    a[i] += a[i-1]
    dif = (a[i] - i) % k
    if dif < 0: dif += k
    if dif not in cnt:
        cnt[dif] = 0
        
    ans += cnt[dif]
    cnt[dif] += 1

print(ans)

Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
d = {}
S = []
N,K = map(int,input().split())
A = list(map(int,input().split()))
s = 0
for i in range(N):
    s = (s+A[i]-i-1)%K
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
    if s not in S:
        S.append(s)
ans = 0
for i in range(len(S)):
    x = S[i]
    y = d[x]
    ans += (y*(y-1))
print(ans)

Failing test case input:
10 11
14 26 111 0 35 27 95 13 38 63

Expected output:
12


Actual output:
8


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
S = []
d = {}
A = list(map(int,input().split()))
ans = 0
sum =0
for i in range(1,N+1):
    sum += A[i-1] % K
    s = (sum - i) % K
    if i > K:
        x = S.pop(0)
        d[x] -= 1
    elif i < K:
        if s == 0:
            ans += 1
    if s not in d:
        d[s] = 0
    ans += d[s]
    d[s] += 1
    S.append(s)
print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import *
import copy
N,K=map(int,input().split())
A=list(map(int,input().split()))

lst=[0]
for i in range(0,N):
    lst.append((A[i]%K+lst[-1])%K)
for i in range(N):
    lst[i]-=i
    lst[i]%=K

dic={0:1}
count=0
for i in range(1,len(lst)):
    if lst[i] in dic:
        count+=dic[lst[i]]
        dic[lst[i]]+=1
    else:
        dic.update({lst[i]:1})
    a=i-K+1
    if a>=0:
        dic[lst[a]]-=1
print(count)


Failing test case input:
1 1
-1 4 1 1 0

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
from collections import *
import copy
N,K=map(int,input().split())
A=list(map(int,input().split()))

lst=[0]
for i in range(0,N):
    lst.append((A[i]%K+lst[i])%K)
for i in range(len(lst)):
    lst[i]-=i
    lst[i]%=K

dic={}
count=0
for i in range(0,len(lst)):
    if lst[i] in dic:
        count+=dic[lst[i]]
        dic[lst[i]]+=1
    else:
        dic.update({lst[i]:1})
    a=i-K+1
    if a>=0:
        dic[lst[a]]-=1
print(count)
Problem: p02241
Buggy submission (Python3, verdict: Wrong Answer):
MAX = 2001


def prim(tree: [int], adjacent_list: [[int]]):
    cost = 0
    next = 0
    for l in adjacent_list:
        l[next] = MAX
    while True:
        tree.append(next)
        min_list = list()
        for t in tree:
            min_list.append(min([(v, i) for i, v in enumerate(adjacent_list[t])]))
        min_cost, i = min(min_list)
        if min_cost == MAX:
            return cost
        cost += min_cost
        for l in adjacent_list:
            l[i] = MAX
        print(adjacent_list)
        next = i


if __name__ == '__main__':
    N = int(input())
    adjacent_list = [[int(e) if int(e) != -1 else MAX for e in input().rstrip().split()] for _ in range(N)]
    test_list = []
    print(prim(test_list, adjacent_list))

Failing test case input:
5
 -1 2 3 1 -1
 2 -1 -1 4 -1
 3 -1 -1 1 1
 1 4 1 -1 3
 -1 -1 1 3 -1

Expected output:
5

Actual output:
[[2001, 2, 3, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 1], [2001, 4, 1, 2001, 3], [2001, 2001, 1, 2001, 2001]]
[[2001, 2, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 1], [2001, 4, 2001, 2001, 3], [2001, 2001, 2001, 2001, 2001]]
[[2001, 2, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 4, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001]]
[[2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001]]
5


Fixed submission (verdict: Accepted):
MAX = 2001


def prim(tree: [int], adjacent_list: [[int]]):
    cost = 0
    next = 0
    for l in adjacent_list:
        l[next] = MAX
    while True:
        tree.append(next)
        min_list = list()
        for t in tree:
            min_list.append(min([(v, i) for i, v in enumerate(adjacent_list[t])]))
        min_cost, i = min(min_list)
        if min_cost == MAX:
            return cost
        cost += min_cost
        for l in adjacent_list:
            l[i] = MAX
        next = i


if __name__ == '__main__':
    N = int(input())
    adjacent_list = [[int(e) if int(e) != -1 else MAX for e in input().rstrip().split()] for _ in range(N)]
    test_list = []
    print(prim(test_list, adjacent_list))
Problem: p02241
Buggy submission (Python3, verdict: Wrong Answer):
MAX = 2001


def prim(tree: [int], adjacent_list: [[int]]):
    cost = 0
    next = 0
    for l in adjacent_list:
        l[next] = MAX
    while True:
        tree.append(next)
        min_list = list()
        for t in tree:
            min_list.append(min([(v, i) for i, v in enumerate(adjacent_list[t])]))
        min_cost, i = min(min_list)
        if min_cost == MAX:
            return cost
        cost += min_cost
        for l in adjacent_list:
            l[i] = MAX
        print(adjacent_list)
        next = i


if __name__ == '__main__':
    N = int(input())
    adjacent_list = [[int(e) if int(e) != -1 else MAX for e in input().rstrip().split()] for _ in range(N)]
    test_list = []
    print(prim(test_list, adjacent_list))
    print(test_list)

Failing test case input:
5
 -1 2 3 1 -1
 2 -1 -1 4 -1
 3 -1 -1 1 1
 1 4 1 -1 3
 -1 -1 1 3 -1

Expected output:
5

Actual output:
[[2001, 2, 3, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 1], [2001, 4, 1, 2001, 3], [2001, 2001, 1, 2001, 2001]]
[[2001, 2, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 1], [2001, 4, 2001, 2001, 3], [2001, 2001, 2001, 2001, 2001]]
[[2001, 2, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 4, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001]]
[[2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001], [2001, 2001, 2001, 2001, 2001]]
5
[0, 3, 2, 4, 1]


Fixed submission (verdict: Accepted):
MAX = 2001


def prim(tree: [int], adjacent_list: [[int]]):
    cost = 0
    next = 0
    for l in adjacent_list:
        l[next] = MAX
    while True:
        tree.append(next)
        min_list = list()
        for t in tree:
            min_list.append(min([(v, i) for i, v in enumerate(adjacent_list[t])]))
        min_cost, i = min(min_list)
        if min_cost == MAX:
            return cost
        cost += min_cost
        for l in adjacent_list:
            l[i] = MAX
        next = i


if __name__ == '__main__':
    N = int(input())
    adjacent_list = [[int(e) if int(e) != -1 else MAX for e in input().rstrip().split()] for _ in range(N)]
    test_list = []
    print(prim(test_list, adjacent_list))
Problem: p02241
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
a = []

for i in range(n):
    inp = input()
    if "-1" in inp:
        inp = inp.replace("-1","10000")
    a.append(list(map(int, inp.split())))

w = 0
v = set()
v.add(0)

while len(v) < n:
    print(v)
    min_w   = 10000
    min_idx = 0
    i = 0
    for node in v:
        if min_w > min(a[node]):
            min_w = min(a[node])
            i = node
            min_idx = a[i].index(min_w)
    if min_idx in v:
        a[i][min_idx] = 10000
        continue
    else:
        w += min_w
        v.add(min_idx)

print(w)

Failing test case input:
5
 -1 2 3 1 -1
 2 -1 -1 4 -1
 3 -1 -1 1 1
 1 4 1 -1 3
 -1 -1 1 3 -1

Expected output:
5

Actual output:
{0}
{0, 3}
{0, 3}
{0, 3}
{0, 2, 3}
{0, 2, 3}
{0, 2, 3, 4}
{0, 2, 3, 4}
{0, 2, 3, 4}
{0, 2, 3, 4}
5


Fixed submission (verdict: Accepted):
n = int(input())
a = []

for i in range(n):
    inp = input()
    if "-1" in inp:
        inp = inp.replace("-1","10000")
    a.append(list(map(int, inp.split())))

w = 0
v = set()
v.add(0)

while len(v) < n:
    min_w   = 10000
    min_idx = 0
    i = 0
    for node in v:
        if min_w > min(a[node]):
            min_w = min(a[node])
            i = node
            min_idx = a[i].index(min_w)
    if min_idx in v:
        a[i][min_idx] = 10000
        continue
    else:
        w += min_w
        v.add(min_idx)

print(w)
Problem: p02869
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    if(k!=1):
        print(-1)
        return
    for i in range(n):
        print(i+1,2*n-i,2*n+i+1)
resolve()

Failing test case input:
1 -10

Expected output:
-10 -9 -8


Actual output:
-1


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    if(2*k>n+1):
        print(-1)
        return
    
    h=(2*k+3*n-1)
    for i in range(0,(n+1)
        print(k+2*i,h-i,k+2*n+i)
    for i in range(0,n
        print(k+1+i*2,k+2*n-1-i,k+2*n+((n-1)
resolve()

Problem: p02869
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N, K = list(map(int, sys.stdin.readline().split()))









ans = []
a = K
b = K + 2 * N - 1
for c in range(K + 2 * N, K + 3 * N):
    if a + b <= c:
        ans.append((a, b, c))
    else:
        break
    a += 1
    b -= 1
if len(ans) == N:
    for a, b, c in ans:
        print(a, b, c)
else:
    print(-1)


Failing test case input:
0 1

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
import os
import sys
from collections import deque

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N, K = list(map(int, sys.stdin.readline().split()))
if 2 * K > N + 1:
    print(-1)
    exit()

ab = []
ai = 0
bi = N - 1
for _ in range(N):
    a = K + ai
    b = K + N + bi
    ab.append((a + b, a, b))
    ai = (ai + 2) % N
    bi = (bi - 1) % N
    if ai == 0:
        
        ai += 1

ab.sort()
for c, (_, a, b) in zip(range(K + 2*N, K + 3*N), ab):
    print(a, b, c)
Problem: p03421
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
if A + B - 1 > N:
    print(-1); exit()
if A * B < N:
    print(-1); exit()

if B == 1:
    q, r = A, 0
else:
    q, r = divmod(N-A, B-1)

if q == A:
    size = [B] * q
else:
    size = [B] * q + [r+1]

end = 1
answer = []
for s in size:
    start = end + s - 1
    answer.extend(list(range(start, end-1, -1)))
    end = start + 1

print(*answer)


Failing test case input:
6 3 3

Expected output:
3 2 1 5 4 6


Actual output:
3 2 1 5 4


Fixed submission (verdict: Accepted):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
if A + B - 1 > N:
    print(-1); exit()
if A * B < N:
    print(-1); exit()

if B == 1:
    q, r = A, 0
else:
    q, r = divmod(N-A, B-1)

if q == A:
    size = [B] * q
else:
    size = [B] * q + [r+1] + [1] * (A-q-1)

end = 1
answer = []
for s in size:
    start = end + s - 1
    answer.extend(list(range(start, end-1, -1)))
    end = start + 1

print(*answer)

Problem: p03421
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
from collections import deque
if A+B-1>N or N>A*B:
    print(-1)
else:
    blocks = []
    blocks.append(' '.join(map(str, range(B, 0, -1))))
    now = B+1
    rest = N-A+2

    while now:
        if now+B>=rest:
            blocks.append(' '.join(map(str, range(rest, now-1, -1))))
            rest += 1
            break
        blocks.append(' '.join(map(str, range(now+B-1, now-1, -1))))
        now = now+B
        rest += 1
    blocks.append(' '.join(map(str, range(rest, N+1))))
    print(' '.join(blocks))


Failing test case input:
6 1 6

Expected output:
6 5 4 3 2 1


Actual output:
6 5 4 3 2 1 7 


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
from collections import deque
if A+B-1>N or N>A*B:
    print(-1)
else:
    blocks = []
    blocks.append(' '.join(map(str, range(B, 0, -1))))
    now = B+1
    rest = N-A+2

    while now:
        if now>=rest:
            break
        if now+B>rest:
            blocks.append(' '.join(map(str, range(rest, now-1, -1))))
            rest += 1
            break
        blocks.append(' '.join(map(str, range(now+B-1, now-1, -1))))
        now = now+B
        rest += 1
    blocks.append(' '.join(map(str, range(rest, N+1))))
    print(' '.join(blocks))
Problem: p03421
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
if A + B - 1 > N:
    print(-1); exit()

if A * B < N:
    print(-1); exit()

answer = []
for i in range(N-A+1, N+1):
    answer.append(i)

if B > 1:
    start = N-A
    q, r = divmod(N-A, B-1)
    add = [x for x in range(start-r, start+1) if x > 0]
    answer += add
    start -= r + 1
    for i in range(B-1):
        limit = start - i * q
        add = [x for x in range(limit-q+1, limit+1) if x > 0]
        answer += add

print(*answer)


Failing test case input:
8 2 4

Expected output:
4 3 2 1 8 7 6 5


Actual output:
7 8 6 4 5 2 3 1


Fixed submission (verdict: Accepted):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
if A + B - 1 > N:
    print(-1); exit()
if A * B < N:
    print(-1); exit()

if B == 1:
    q, r = A, 0
else:
    q, r = divmod(N-A, B-1)

if q == A:
    size = [B] * q
else:
    size = [B] * q + [r+1] + [1] * (A-q-1)

end = 1
answer = []
for s in size:
    start = end + s - 1
    answer.extend(list(range(start, end-1, -1)))
    end = start + 1

print(*answer)

Problem: p03421
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
if A + B - 1 > N:
    print(-1); exit()

if A * B < N:
    print(-1); exit()

answer = []
for i in range(N-A+1, N+1):
    answer.append(i)

if B > 1:
    start = N-A
    q, r = divmod(N-A, B-1)
    add = [x for x in range(start-q, start+1) if x > 0]
    answer += add
    start -= q + 1
    for i in range(B-1):
        limit = start - i * q
        add = [x for x in range(limit-q+1, limit+1) if x > 0]
        answer += add

print(*answer)


Failing test case input:
4 2 2

Expected output:
2 1 4 3


Actual output:
3 4 1 2


Fixed submission (verdict: Accepted):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
if A + B - 1 > N:
    print(-1); exit()
if A * B < N:
    print(-1); exit()

if B == 1:
    q, r = A, 0
else:
    q, r = divmod(N-A, B-1)

if q == A:
    size = [B] * q
else:
    size = [B] * q + [r+1] + [1] * (A-q-1)

end = 1
answer = []
for s in size:
    start = end + s - 1
    answer.extend(list(range(start, end-1, -1)))
    end = start + 1

print(*answer)
Problem: p03421
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
from collections import deque
if A+B-1>N or N>A*B:
    print(-1)
else:
    blocks = []
    blocks.append(' '.join(map(str, range(B, 0, -1))))
    now = B+1
    rest = N-A+2

    while now:
        if now+B>rest:
            blocks.append(' '.join(map(str, range(rest, now-1, -1))))
            rest += 1
            break
        blocks.append(' '.join(map(str, range(now+B-1, now-1, -1))))
        now = now+B
        rest += 1
    blocks.append(' '.join(map(str, range(rest, N+1))))
    print(' '.join(blocks))

Failing test case input:
6 1 6

Expected output:
6 5 4 3 2 1


Actual output:
6 5 4 3 2 1 7 


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
from collections import deque
if A+B-1>N or N>A*B:
    print(-1)
else:
    blocks = []
    blocks.append(' '.join(map(str, range(B, 0, -1))))
    now = B+1
    rest = N-A+2

    while now:
        if now>=rest:
            break
        if now+B>rest:
            blocks.append(' '.join(map(str, range(rest, now-1, -1))))
            rest += 1
            break
        blocks.append(' '.join(map(str, range(now+B-1, now-1, -1))))
        now = now+B
        rest += 1
    blocks.append(' '.join(map(str, range(rest, N+1))))
    print(' '.join(blocks))

Problem: p03421
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
if A + B - 1 > N:
    print(-1); exit()

if A * B < N:
    print(-1); exit()

answer = []
for i in range(N-A+1, N+1):
    answer.append(i)

if B > 1:
    start = N-A
    q, r = divmod(N-A, B-1)
    add = [x for x in range(start-q, start+1)]
    answer += add
    start -= q + 1
    for i in range(B-1):
        limit = start - i * q
        add = [x for x in range(limit-q+1, limit+1) if x > 0]
        answer += add

print(*answer)


Failing test case input:
4 2 2

Expected output:
2 1 4 3


Actual output:
3 4 0 1 2


Fixed submission (verdict: Accepted):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
if A + B - 1 > N:
    print(-1); exit()
if A * B < N:
    print(-1); exit()

if B == 1:
    q, r = A, 0
else:
    q, r = divmod(N-A, B-1)

if q == A:
    size = [B] * q
else:
    size = [B] * q + [r+1] + [1] * (A-q-1)

end = 1
answer = []
for s in size:
    start = end + s - 1
    answer.extend(list(range(start, end-1, -1)))
    end = start + 1

print(*answer)
Problem: p03421
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,a,b = map(int,input().split())
if not (a+b-1 <= n <= a*b):
  print(-1)
  exit()
k = a*b - n
ans = [x + (b-1)*10**6 for x in range(a)]
for i in range(b-2,-1,-1):
  t = min(a-1,k)
  ans += [x+i*10**6 for x in range(a)][:-t]
  k -= t

dic = {x:str(i+1) for i,x in enumerate(sorted(ans))}
print(" ".join(list(map(lambda x:dic[x],ans))))
  

Failing test case input:
4 2 2

Expected output:
2 1 4 3


Actual output:
1 2


Fixed submission (verdict: Accepted):
n,a,b = map(int,input().split())
if not (a+b-1 <= n <= a*b):
  print(-1)
  exit()
n -= a
l = list()
for i in range(b,a*b+1,b):
  t = min(n,b-1)
  l += [i-j for j in range(t+1)]
  n -= t
d = dict()
g = sorted(l)
for i,x in enumerate(g,1):
  d[x] = i
l = list(map(lambda x:d[x], l))
print(*l)

Problem: p03421
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
from collections import deque
if A+B-1>N or N>A*B:
    print(-1)
else:
    blocks = []
    blocks.append(' '.join(map(str, range(B, 0, -1))))
    now = B+1
    rest = A+1
    while now:
        if now>=rest:
            break
        if now+B>=rest:
            blocks.append(' '.join(map(str, range(rest, now-1, -1))))
            break
        blocks.append(' '.join(map(str, range(now+B, now, -1))))
        now += B
        rest -= 1
    blocks.append(' '.join(map(str, range(rest+1, N+1))))
    print(' '.join(blocks))


Failing test case input:
7 7 1

Expected output:
1 2 3 4 5 6 7

Actual output:
1 3 4 5 6 7


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
from collections import deque
if A+B-1>N or N>A*B:
    print(-1)
else:
    blocks = []
    blocks.append(' '.join(map(str, range(B, 0, -1))))
    now = B+1
    rest = N-A+2

    while now:
        if now>=rest:
            break
        if now+B>rest:
            blocks.append(' '.join(map(str, range(rest, now-1, -1))))
            rest += 1
            break
        blocks.append(' '.join(map(str, range(now+B-1, now-1, -1))))
        now = now+B
        rest += 1
    blocks.append(' '.join(map(str, range(rest, N+1))))
    print(' '.join(blocks))
Problem: p03421
Buggy submission (Python (3.4.3), verdict: Wrong Answer):















n, a, b = [int(x) for x in input().split()]
if n < a + b - 1:
    print(-1)
    
    
    
    
    
else:
    ans = []
    remaining = n - a
    to_insert = 1
    for i in range(a):
        ans.append(to_insert)
        to_insert += 1
        inserted = 1
        for j in range(min(b - 1, remaining)):
            ans.append(to_insert)
            to_insert += 1
            inserted += 1
            remaining -= 1
        ans[-inserted:] = reversed(ans[-inserted:])
    print(*ans)
    


Failing test case input:
8 0 0

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
n, a, b = [int(x) for x in input().split()]
if a * b < n or n < a + b - 1:
    print(-1)
else:
    ans = []
    remaining = n - a
    to_insert = 1
    for i in range(a):
        ans.append(to_insert)
        to_insert += 1
        inserted = 1
        for j in range(min(b - 1, remaining)):
            ans.append(to_insert)
            to_insert += 1
            inserted += 1
            remaining -= 1
        ans[-inserted:] = reversed(ans[-inserted:])
    print(*ans)

Problem: p03421
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
if A + B - 1 > N:
    print(-1); exit()

if A * B < N:
    print(-1); exit()

answer = []
for i in range(N-A+1, N+1):
    answer.append(i)

if B > 1:
    start = N-A
    q, r = divmod(N-A, B-1)
    for i in range(B-1):
        limit = start - i * q
        add = [x for x in range(limit-q+1, limit+1) if x > 0]
        answer += add

print(*answer)


Failing test case input:
6 3 3

Expected output:
3 2 1 5 4 6


Actual output:
4 5 6 3 2


Fixed submission (verdict: Accepted):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
if A + B - 1 > N:
    print(-1); exit()
if A * B < N:
    print(-1); exit()

if B == 1:
    q, r = A, 0
else:
    q, r = divmod(N-A, B-1)

if q == A:
    size = [B] * q
else:
    size = [B] * q + [r+1] + [1] * (A-q-1)

end = 1
answer = []
for s in size:
    start = end + s - 1
    answer.extend(list(range(start, end-1, -1)))
    end = start + 1

print(*answer)
Problem: p03421
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
j = list(map(int, input().split()))
n = j[0]
a = j[1]
b = j[2]
if (n < a + b - 1) or (n > a * b):
    print(-1)
    exit(0)

ans = list(range(b, 0, -1))
if (n > b):
    counter = b
    while (counter <= n):
        if counter + b <= n:
            ans += list(range(counter+b, counter, -1))
        else:
            
            ans += list(range(n, counter, -1))
        counter += b

print(' '.join(map(str, ans)))


Failing test case input:
6 3 3

Expected output:
3 2 1 5 4 6


Actual output:
3 2 1 6 5 4


Fixed submission (verdict: Accepted):
import math

j = list(map(int, input().split()))
n = j[0]
a = j[1]
b = j[2]
if (n < a + b - 1) or (n > a * b):
    print(-1)
    exit(0)

ans = list(range(b, 0, -1))
if (n > b):
    counter = len(ans)
    loopcounter = 1
    
    sikii = b
    yoyuu = n - a -b+1
    while (counter < n):
        if (yoyuu >= sikii):
            ans += list(range(counter + sikii, counter, -1))
            yoyuu -= (sikii - 1)
        elif (yoyuu == 0):
            ans += [counter + 1]
        else:
            ans += list(range(counter + yoyuu + 1, counter, -1))
            yoyuu = 0
        loopcounter += 1
        counter = len(ans)

print(' '.join(map(str, ans)))

Problem: p03421
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline



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

if A+B-1 > N:
    print(-1)
    exit()
if A*B < N:
    print(-1)
    exit()



if B == 1:
    size = [1] * A
else:
    q,r = divmod(N-A,B-1)
    size = [B] * q + [1+r] + [1] * (A-q-1)

answer = []
start = 1
for s in size:
    end = start + s
    answer += list(range(end-1, start-1, -1))
    start = end
print(*answer)

Failing test case input:
6 1 6

Expected output:
6 5 4 3 2 1


Actual output:
6 5 4 3 2 1 7


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline



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

if A+B-1 > N:
    print(-1)
    exit()
if A*B < N:
    print(-1)
    exit()



if B == 1:
    size = [1] * A
else:
    q,r = divmod(N-A,B-1)
    if q < A:
        size = [B] * q + [1+r] + [1] * (A-q-1)
    else:
        size = [B] * A

answer = []
start = 1
for s in size:
    end = start + s
    answer += list(range(end-1, start-1, -1))
    start = end
print(*answer)
Problem: p03421
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
from collections import deque
if A+B-1>N or N>A*B:
    print(-1)
else:
    blocks = []
    blocks.append(' '.join(map(str, range(B, 0, -1))))
    now = B+1
    rest = N-A+2

    while now:
        if now>=rest:
            break
        if now+B>=rest:
            blocks.append(' '.join(map(str, range(rest-1, now-1, -1))))
            break
        blocks.append(' '.join(map(str, range(now+B, now-1, -1))))
        now += B
        rest -= 1
    blocks.append(' '.join(map(str, range(rest, N+1))))
    print(' '.join(blocks))


Failing test case input:
8 2 4

Expected output:
4 3 2 1 8 7 6 5


Actual output:
4 3 2 1 7 6 5 8


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
from collections import deque
if A+B-1>N or N>A*B:
    print(-1)
else:
    blocks = []
    blocks.append(' '.join(map(str, range(B, 0, -1))))
    now = B+1
    rest = N-A+2

    while now:
        if now>=rest:
            break
        if now+B>rest:
            blocks.append(' '.join(map(str, range(rest, now-1, -1))))
            rest += 1
            break
        blocks.append(' '.join(map(str, range(now+B-1, now-1, -1))))
        now = now+B
        rest += 1
    blocks.append(' '.join(map(str, range(rest, N+1))))
    print(' '.join(blocks))
Problem: p00767
Buggy submission (Python3, verdict: Wrong Answer):
def intRec(h,w):
    diag=h**2+w**2
    ans=[]
    temp=1e8
    for H in range(1,151):
        for W in range(w,151):
            if (H**2+W**2)>diag and (H**2+W**2)<temp:
                temp=H**2+W**2
                ans=[H,W]
    return ans

if __name__=="__main__":
    while True:
        h,w=map(int,input().split())
        if h==0:
            break
        ans=intRec(h,w)
        print(ans[0],ans[1])


Failing test case input:
1 2
1 3
2 3
1 4
2 4
5 6
1 8
4 7
98 100
99 100
0 0

Expected output:
1 3
2 3
1 4
2 4
3 4
1 8
4 7
2 8
3 140
89 109

Actual output:
2 2
2 3
1 4
2 4
3 4
1 8
2 8
2 8
3 140
89 109


Fixed submission (verdict: Accepted):
def intRec(h,w):
    diag=h**2+w**2
    minD=1e8
    ans=[]
    for H in range(1,151):
        for W in range(1,151):
            if H<W:
                Diag=H**2+W**2
                if diag==Diag and H>h:
                    return [H,W]
                elif diag<Diag and Diag<minD:
                    minD=Diag
                    ans=[H,W]
    return ans

if __name__=="__main__":
    while True:
        h,w=map(int,input().split())
        if h==0:
            break
        ans=intRec(h,w)
        print(ans[0],ans[1])

Problem: p00767
Buggy submission (Python3, verdict: Wrong Answer):
while True:
    h, w = map(int, input().split())
    if not h:
        break
    diagonal = h**2 + w**2
    ans = []
    append = ans.append
    for y in range(1, 151):
        for x in range(y+1, 151):
            if x**2+y**2 > diagonal:
                append((x**2+y**2, y, x))
                break
    print(*sorted(ans)[0][1:])


Failing test case input:
1 2
1 3
2 3
1 4
2 4
5 6
1 8
4 7
98 100
99 100
0 0

Expected output:
1 3
2 3
1 4
2 4
3 4
1 8
4 7
2 8
3 140
89 109

Actual output:
1 3
2 3
1 4
2 4
3 4
1 8
2 8
2 8
3 140
89 109


Fixed submission (verdict: Accepted):
while True:
    h, w = map(int, input().split())
    if not h:
        break
    diagonal = h**2 + w**2
    ans = []
    append = ans.append
    for y in range(1, 151):
        for x in range(y+1, 151):
            if x**2+y**2 > diagonal or x**2+y**2 == diagonal and y > h:
                append((x**2+y**2, y, x))
                break
    print(*sorted(ans)[0][1:])
Problem: p00767
Buggy submission (Python3, verdict: Wrong Answer):
while True:
    H,W = map(int,input().split())
    if H == 0: break
    d0 = H*H + W*W
    ans_d = ans_h = ans_w = 10**9
    for w in range(2,151):
        for h in range(1,w):
            d = h*h + w*w
            if d <= d0: continue
            if d <= ans_d:
                ans_h = h
                ans_w = w
                if d < ans_d:
                    ans_d = d
            break
    print('{0} {1}'.format(ans_h, ans_w))

Failing test case input:
1 2
1 3
2 3
1 4
2 4
5 6
1 8
4 7
98 100
99 100
0 0

Expected output:
1 3
2 3
1 4
2 4
3 4
1 8
4 7
2 8
3 140
89 109

Actual output:
1 3
2 3
1 4
2 4
3 4
1 8
2 8
2 8
3 140
89 109


Fixed submission (verdict: Accepted):
while True:
    H,W = map(int,input().split())
    if H == 0: break
    d0 = H*H + W*W
    ans = (10**9,H,W)
    for w in range(2,151):
        for h in range(1,w):
            d = h*h + w*w
            if (d,h,w) < (d0,H,W) or (h,w) == (H,W): continue
            ans = min(ans, (d,h,w))
            break
    print('{0} {1}'.format(ans[1], ans[2]))
Problem: p04006
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
arr=list(map(int,input().split()))
cost=[10**10]*n
ans=10**10
for i in range(n):
  for j in range(n):
    cost[j]=min(cost[j],arr[j-i])
  print(cost)
  ans=min(ans,x*i+sum(cost))
print(ans)

Failing test case input:
3 28
011 2 100

Expected output:
43


Actual output:
[11, 2, 100]
[11, 2, 2]
[2, 2, 2]
43


Fixed submission (verdict: Accepted):
n,x=map(int,input().split())
arr=list(map(int,input().split()))
cost=[10**18]*n
ans=10**18
for i in range(n):
  for j in range(n):
    cost[j]=min(cost[j],arr[j-i])
  ans=min(ans,x*i+sum(cost))
print(ans)

Problem: p04006
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,X = map(int,input().split())
src = list(map(int,input().split()))
dp = src[:]
ans = float('inf')
for n in range(N):
    t = n*X
    for m in range(N):
       if dp[m] > dp[m-n]:
           dp[m] = dp[m-n]
       t += dp[m]
    ans = min(ans,t)
print(ans)

Failing test case input:
3 66
000 2 100

Expected output:
68


Actual output:
66


Fixed submission (verdict: Accepted):
N,X = map(int,input().split())
src = list(map(int,input().split()))
dp = src[:]
ans = float('inf')
for n in range(N):
    for m in range(N):
       if dp[m] > src[m-n]:
           dp[m] = src[m-n]
    ans = min(ans, sum(dp)+n*X)
print(ans)

Problem: p04006
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int,input().split())
slimes = list(map(int,input().split()))
ans = 0

for i in range(n):
    if slimes[i] <= min(slimes) + x:
        ans += slimes[i]
    else:
        ans += min(slimes) + x

print(ans)

Failing test case input:
3 -1
100 0 110

Expected output:
-2


Actual output:
-3


Fixed submission (verdict: Accepted):
n, x = map(int,input().split())
slimes = list(map(int,input().split()))
p = slimes[:]
ans = 5000000000000000

for i in range(n):
    for j in range(n):
        if p[j] > slimes[j-i]:
            p[j] = slimes[j-i]
    ans = min(ans, sum(p) + i * x)
print(ans)

Problem: p04006
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,X = map(int,input().split())
dp = list(map(int,input().split()))
ans = float('inf')
for n in range(N):
    for m in range(N):
       if dp[m] > dp[m-n]:
           dp[m] = dp[m-n]
    ans = min(ans,sum(dp)+n*X)
print(ans)

Failing test case input:
3 35
000 2 110

Expected output:
37


Actual output:
35


Fixed submission (verdict: Accepted):
N,X = map(int,input().split())
src = list(map(int,input().split()))
dp = src[:]
ans = float('inf')
for n in range(N):
    for m in range(N):
       if dp[m] > src[m-n]:
           dp[m] = src[m-n]
    ans = min(ans, sum(dp)+n*X)
print(ans)
Problem: p04006
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int, input().split())
a = list(map(int, input().split()))
a_copy = a
for i in range(n):
  for j in range(n):
    idx = (i+j) % n
    time = a[i] + j*x
    a_copy[idx] = min(a_copy[idx], time)
print(sum(a_copy))
  

Failing test case input:
3 35
000 2 110

Expected output:
37


Actual output:
39


Fixed submission (verdict: Accepted):
n, x = map(int, input().split())
a = list(map(int, input().split()))
b = a[:]

ans = sum(a)
for k in range(1, n):
  for i in range(n):
    if b[i] > a[i-k]:
      b[i] = a[i-k]
  ans = min(ans, sum(b) + k*x)
print(ans)

Problem: p04006
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, x = map(int, input().split())
a = [int(i) for i in input().split()]

ret = float('inf')
for i in range(N) :
    ret = min(ret, sum([min(a[i]+x, a[j])for j in range(N)]))
print(ret)

Failing test case input:
3 -1
000 -1 100

Expected output:
-5


Actual output:
-6


Fixed submission (verdict: Accepted):
N, x = map(int, input().split())
a = [int(i) for i in input().split()]

ret = float('inf')
dp = [float('inf')] * N
for i in range(N) :
    for j in range(N) :
        dp[(j+i)%N] = min(dp[(j+i)%N], a[j])
    ret = min(ret, sum(dp) + x * i)
print(ret)

Problem: p04006
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,X=map(int,input().split())
A=[int(i) for i in input().split()]
B=A
ans=sum(A)
for t in range(1,N):
    for i in range(N):
        if B[i]>A[i-t]+t*X:
            B[i]=A[i-t]
    ans=min(ans,sum(B)+t*X)
print(ans)

Failing test case input:
3 72
000 8 101

Expected output:
80


Actual output:
88


Fixed submission (verdict: Accepted):
from copy import deepcopy
N,X=map(int,input().split())
A=[int(i) for i in input().split()]
B=deepcopy(A)
ans=sum(A)
for t in range(1,N):
    for i in range(N):
        if B[i]>A[i-t]:
            B[i]=A[i-t]
    ans=min(ans,sum(B)+t*X)
print(ans)

Problem: p04006
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int, input().split())
a = list(map(int, input().split()))

mins = a[:]
result = float("inf")

for k in range(n):
    for i in range(len(mins)):
        mins[i - k] = min(a[i - k], mins[i])
    result = min(x * k + sum(mins), result)

print(result)


Failing test case input:
3 72
000 8 101

Expected output:
80


Actual output:
72


Fixed submission (verdict: Accepted):
n, x = map(int, input().split())
a = list(map(int, input().split()))

mins = a[:]
result = float("inf")

for k in range(n):
    for i in range(len(mins)):
        mins[i] = min(a[i - k], mins[i])
    result = min(x * k + sum(mins), result)

print(result)
Problem: p04006
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,x = map(int,input().split())
a = list(map(int,input().split()))
l = a
ans = float("INF")
for i in range(n):
    count = x*i
    for j in range(n):
        l[j] = min(l[j],a[(j-i)%n])
        count += l[j]
    ans = min(ans,count)
print(ans)

Failing test case input:
3 64
000 2 110

Expected output:
66


Actual output:
64


Fixed submission (verdict: Accepted):
n,x = map(int,input().split())
a = list(map(int,input().split()))
l = [float("INF")]*n
ans = float("INF")
for i in range(n):
    count = x*i
    for j in range(n):
        l[j] = min(l[j],a[(j-i)%n])
        count += l[j]
    ans = min(ans,count)
print(ans)

Problem: p04006
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, x = map(int, input().split())
*A, = map(int, input().split())
B = A[:]
ans = 10**10
for k in range(N):
    ans = min(ans, k*x + sum(B))
    for i in range(N):
        B[i] = min(B[i], B[(i-(k+1)) % N])
print(ans)

Failing test case input:
4 4
2 1 3 4

Expected output:
10


Actual output:
9


Fixed submission (verdict: Accepted):
N, x = map(int, input().split())
*A, = map(int, input().split())
MAX = 10**18
B = [MAX]*N
ans = MAX
for k in range(N):
    for i in range(N):
        B[i] = min(B[i], A[(i-k) % N])
    ans = min(ans, k*x + sum(B))
print(ans)

Problem: p04006
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,X = map(int,input().split())
src = list(map(int,input().split()))
dp = src[:]
ans = sum(dp)
for n in range(1,N):
    t = n*X
    for m in range(N):
       dp[m] = min(dp[m], dp[m-1])
       t += dp[m]
    ans = min(ans,t)
print(ans)

Failing test case input:
3 35
110 4 001

Expected output:
41


Actual output:
38


Fixed submission (verdict: Accepted):
N,X = map(int,input().split())
src = list(map(int,input().split()))
dp = src[:]
ans = float('inf')
for n in range(N):
    for m in range(N):
       if dp[m] > src[m-n]:
           dp[m] = src[m-n]
    ans = min(ans, sum(dp)+n*X)
print(ans)

Problem: p04006
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

ans = sum(A)

for i in range(1, n):
    for j in range(n):
        if A[j-i] < A[j]:
            A[j] = A[j-i]
    ans = min(ans, sum(A) + i * x)

print(ans)

Failing test case input:
3 72
001 5 101

Expected output:
79


Actual output:
75


Fixed submission (verdict: Accepted):
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = [a for a in A]
ans = sum(A)

for i in range(1, n):
    for j in range(n):
        if A[j-i] < B[j]:
            B[j] = A[j-i]
    ans = min(ans, sum(B) + i * x)

print(ans)
Problem: p04006
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,x = map(int,input().split())
a = list(map(int,input().split()))
l = a
ans = float("INF")
for i in range(n):
    count = x*i
    for j in range(n):
        l[j] = min(l[j],l[(j-i)%n])
        count += l[j]
    ans = min(ans,count)
print(ans)

Failing test case input:
3 19
001 2 100

Expected output:
23


Actual output:
22


Fixed submission (verdict: Accepted):
n,x = map(int,input().split())
a = list(map(int,input().split()))
l = [float("INF")]*n
ans = float("INF")
for i in range(n):
    count = x*i
    for j in range(n):
        l[j] = min(l[j],a[(j-i)%n])
        count += l[j]
    ans = min(ans,count)
print(ans)

Problem: p04006
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from copy import deepcopy
n,x = map(int,input().split())
a = list(map(int,input().split()))
a *= 2
als = deepcopy(a[:n])
ans = [sum(als)]
for k in range(1,n):
  for i in range(n):
    als[i] = min(als[i],a[n-1+i-k])
  ans.append(sum(als)+x*k)
print(min(ans))

Failing test case input:
3 72
110 5 101

Expected output:
159


Actual output:
183


Fixed submission (verdict: Accepted):
from copy import deepcopy
n,x = map(int,input().split())
a = list(map(int,input().split()))
a *= 2
als = deepcopy(a[:n])
ans = [sum(als)]
for k in range(1,n):
  for i in range(n):
    als[i] = min(als[i],a[n+i-k])
  ans.append(sum(als)+x*k)
print(min(ans))
Problem: p02386
Buggy submission (Python3, verdict: Wrong Answer):
from itertools import*
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
t=0
for d,e in list(combinations(a,2)):
 e[3],e[4]=e[4],e[3]
 for i in range(6):
  m={0:'012345',1:'152304',2:'215043',3:'310542',4:'402351',5:'513240'}[i]
  f=[d[int(j)]for j in m]
  if f[0]==e[0]and f[5]==e[5]:
   print(f,e)
   f=f[1:5]*2
   for j in range(4):
    if f[j:j+4]==e[1:5]:t=1
print(('Yes','No')[t==1])

Failing test case input:
3
1 6 3 4 5 6
6 2 5 3 0 1
6 5 4 3 2 1

Expected output:
Yes


Actual output:
[6, 6, 4, 3, 5, 1] [6, 2, 5, 0, 3, 1]
[6, 6, 4, 3, 5, 1] [6, 5, 4, 2, 3, 1]
[6, 2, 5, 0, 3, 1] [6, 5, 4, 3, 2, 1]
Yes


Fixed submission (verdict: Accepted):
from itertools import*
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
for k in range(n):
 b=a[k];b[3],b[4]=b[4],b[3]
t=0
for d,e in list(combinations(a,2)):
 for i in range(6):
  m=('012345','152043','215304','302541','410352','514320')[i]
  f=[d[int(k)]for k in m]
  if f[0]==e[0]and f[5]==e[5]:
   f=f[1:5]*2
   for j in range(4):
    if f[j:j+4]==e[1:5]:t=1
print(('Yes','No')[t==1])
Problem: p02362
Buggy submission (Python3, verdict: Wrong Answer):
import sys
readline = sys.stdin.readline

V, E, r = map(int, readline().split())
inf = 10**10
edges = [[] for _ in [None]*V]

for _ in [None]*E:
    s, t, d = map(int, readline().split())
    edges[s].append((t, d))

vertices = [inf] * V
vertices[r] = 0

for i in range(V):
    flag = 0
    for v in range(V):
        cost = vertices[v]
        for dist, _cost in edges[v]:
            newcost = cost + _cost
            if vertices[dist] > newcost:
                vertices[dist] = newcost
                flag = 1
    if flag == 0:
        for v in vertices:
            print(v if v != inf else "INF")
        break
else:
    print("NEGATIVE CYCLE")

Failing test case input:
14 5 1
0 0 2
0 2 3
2 0 -5
2 3 1
0 2 0

Expected output:
INF
0
INF
INF
INF
INF
INF
INF
INF
INF
INF
INF
INF
INF


Actual output:
NEGATIVE CYCLE


Fixed submission (verdict: Accepted):
import sys
readline = sys.stdin.readline

V, E, r = map(int, readline().split())
inf = 10**10
edges = [[] for _ in [None]*V]

for _ in [None]*E:
    s, t, d = map(int, readline().split())
    edges[s].append((t, d))

vertices = [inf] * V
vertices[r] = 0

for i in range(V):
    flag = 0
    for v in range(V):
        cost = vertices[v]
        if cost == inf:
            continue
        for dist, _cost in edges[v]:
            newcost = cost + _cost
            if vertices[dist] > newcost:
                vertices[dist] = newcost
                flag = 1
    if flag == 0:
        for v in vertices:
            print(v if v != inf else "INF")
        break
else:
    print("NEGATIVE CYCLE")

Problem: p02362
Buggy submission (Python3, verdict: Wrong Answer):
nv, ne, r = map(int, input().split())

edges = set(tuple(map(int, input().split())) for _ in range(ne))
costs = [None] * nv
costs[r] = 0

for _ in range(nv - 1):
    for s, t, d in edges:
        cost = d if costs[s] is None else costs[s] + d
        if costs[t] is None or costs[t] > cost:
            costs[t] = cost

for s, t, d in edges:
    cost = d if costs[s] is None else costs[s] + d
    if cost < costs[t]:
        print('NEGATIVE CYCLE')
        break
else:
    for cost in costs:
        print('INF' if cost is None else cost)

Failing test case input:
8 5 0
0 2 3
2 4 3
3 0 -5
2 4 2
0 7 2

Expected output:
0
INF
3
INF
5
INF
INF
2


Actual output:
-5
INF
-2
INF
0
INF
INF
-3


Fixed submission (verdict: Accepted):
nv, ne, r = map(int, input().split())

edges = set(tuple(map(int, input().split())) for _ in range(ne))
costs = [None] * nv
costs[r] = 0

for _ in range(nv - 1):
    for s, t, d in edges:
        if costs[s] is None:
            continue
        cost = costs[s] + d
        if costs[t] is None or costs[t] > cost:
            costs[t] = cost

for s, t, d in edges:
    if costs[s] is None:
        continue
    if costs[s] + d < costs[t]:
        print('NEGATIVE CYCLE')
        break
else:
    for cost in costs:
        print('INF' if cost is None else cost)
Problem: p02362
Buggy submission (Python3, verdict: Wrong Answer):

from math import isinf

V, E, r = map(int, input().split())
vertices = [float('inf')] * V
vertices[r] = 0
edges = []
for i in range(E):
    s, t, d = map(int, input().split())
    edges.append((s, t, d))

for i in range(V - 1):
    for s, t, d in edges:
        if vertices[t] > vertices[s] + d:
            vertices[t] = vertices[s] + d

neg = False
for s, t, d in edges:
    if vertices[t] > vertices[s] + d:
        print("NEGATIVE CYCLE")
        neg = True

if not neg:
    for v in vertices:
        print('INF' if isinf(v) else v)

Failing test case input:
4 5 0
0 1 2
0 2 3
1 0 -5
2 3 1
2 3 2

Expected output:
NEGATIVE CYCLE


Actual output:
NEGATIVE CYCLE
NEGATIVE CYCLE


Fixed submission (verdict: Accepted):

from math import isinf


def main():
    V, E, r = map(int, input().split())
    vertices = [float('inf')] * V
    vertices[r] = 0
    edges = []
    for i in range(E):
        s, t, d = map(int, input().split())
        edges.append((s, t, d))

    for i in range(V - 1):
        for s, t, d in edges:
            if vertices[t] > vertices[s] + d:
                vertices[t] = vertices[s] + d

    for s, t, d in edges:
        if vertices[t] > vertices[s] + d:
            print("NEGATIVE CYCLE")
            return

    for v in vertices:
        print('INF' if isinf(v) else v)

main()