TnT/CodeNet4Repair huggingface dataset:
Problem:
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:    * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.   * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.  You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.

Incorrect submission (verdict: Wrong Answer):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

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

for i in range(1,m+1):
    print(i,n-i+1)




Fixed, accepted submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

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

p = m // 2
for i in range(p):
    print(p-i,p+2+i)

q = m // 2 + 1
if m % 2 == 1:
    for i in range(q):
        print(m+q-i,m+q+i+1)
else:
    for i in range(q-1):
        print(m+q-i,m+q+i+1)
Problem:
E869120 has A 1-yen coins and infinitely many 500-yen coins.   Determine if he can pay exactly N yen using only these coins.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a = int(input())

c = n // 500

one = n - c

if one <= a:
    print('Yes')
else:
    print('No')

Fixed, accepted submission:
n = int(input())
a = int(input())

c = n // 500

one = n - c*500

if one <= a:
    print('Yes')
else:
    print('No')
Problem:
E869120 found a chest which is likely to contain treasure.   However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.   He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`.  One more thing he found is a sheet of paper with the following facts written on it:    * Condition 1: The string S contains a string T as a contiguous substring.   * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.  Print the string S.   If such a string does not exist, print `UNRESTORABLE`.

Incorrect submission (verdict: Wrong Answer):
def CountE(x):
    cnt = 0
    ind = 0
    temp = 1
    for i in range(len(x)-1, 0, -1):
        if x[i] == "?" and x[i] == x[i-1]:
            temp += 1
            cnt = temp
            ind = i-1
        else: 
            temp = 1
    return cnt, ind

Sp = input()
T = input()

s = [i for i in Sp]
t = [i for i in T]

flg = 0
cnt = 0
ind = 0
if t[0] in s:
    if len(t) <= len(s)-s.index(t[0]):
        s[s.index(t[0]):s.index(t[0])+len(t)-1] = t
    else:
        flg = 1
else:
    if len(t) > s.count("?") or s.count("?") < 2:
        flg = 1
    else:
        cnt, ind = CountE(s)
        if cnt >= len(t):
            s[ind:ind+len(t)-1] = t
        else:
            flg = 1

if flg == 0:
    for i in range(len(s)):
        if s[i] == "?":
            s[i] = "a"
    ans = "".join(s)
print(ans if flg == 0 else "UNRESTORABLE")

Fixed, accepted submission:
S = input()
T = input()

flg = 0
ans = ""
temp = ""
for i in range(len(S)):
    flg = 0
    if len(S[i:]) < len(T):
        break
    for j in range(len(T)):
        if S[i:][j] != T[j] and S[i:][j] != "?":
            flg = 1
    if flg == 0:
        temp = (S[0:i]+T+S[i+len(T):]).replace("?", "a")
        if temp < ans or ans == "":
            ans = temp
    
print(ans if ans != "" else "UNRESTORABLE")
Problem:
We will buy a product for N yen (the currency of Japan) at a shop.  If we use only 1000-yen bills to pay the price, how much change will we receive?  Assume we use the minimum number of bills required.

Incorrect submission (verdict: Wrong Answer):
N = int(input())

A = N % 1000

print(A)

Fixed, accepted submission:
N = int(input())

A = N % 1000

if A == 0:
    print(0)
else:
    B = 1000 - A
    print(B)
Problem:
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.  Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence.  Here, the distance between two points s and t on a number line is represented by |s-t|.

Incorrect submission (verdict: Wrong Answer):
x,a,b=map(int,input().split())
if(abs(x-a)>=abs(x-b)):
    print(b)
else:
    print(a)

Fixed, accepted submission:
x,a,b=map(int,input().split())
if(abs(x-a)>=abs(x-b)):
    print("B")
else:
    print("A")
Problem:
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.  Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence.  Here, the distance between two points s and t on a number line is represented by |s-t|.

Incorrect submission (verdict: Wrong Answer):
n, a, b = map(int, input().split())
print("A" if (a - n) < (b - n) else "B")

Fixed, accepted submission:
x, a, b = map(int, input().split())
print("A" if abs(a - x) < abs(b - x) else "B")
Problem:
An elementary school student Takahashi has come to a variety store.  He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?  Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.

Incorrect submission (verdict: Wrong Answer):
A,B,C = map(int,input().split())
COIN=[1,5,10,100,500]
if A in COIN and B in COIN:
  if A + B >= C:
    print('Yes')
  else:
    print('No')
else:
  print('No')

Fixed, accepted submission:
A,B,C = map(int,input().split())
if (A + B) >= C:
  print('Yes')
else:
  print('No')
Problem:
There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all.  There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i.  Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before.  Compute the minimum number of days on which the same type of cake as the previous day will be eaten.

Incorrect submission (verdict: Wrong Answer):
K,T=map(int,input().split())
a=list(map(int,input().split()))
b=[]

for i,an in enumerate(a):
    b.append([an,i])
ex = -1
ans = 0

if T == 1:
	print(K-1)
else:
  for i in range(K):
    list.sort(b, reverse=True)
    if ex == b[0][1] and b[0][0] == b[1][0]:
      b[1][0] -= 1
    else:
      b[0][0] -= 1
      if ex == b[0][1]:
        ans+=1
        print(b)
      ex = b[0][1]
      if b[0][1] == 0 and b[1][1] == 0:
        break
      print(ans)



Fixed, accepted submission:
K,T=map(int,input().split())
a=list(map(int,input().split()))
b=[]

for i,an in enumerate(a):
    b.append([an,i])
ex = -1
ans = 0

if T == 1:
	print(K-1)
else:
  for i in range(K):
    list.sort(b, reverse=True)
    if ex == b[0][1] and b[1][0] != 0:
      b[1][0] -= 1
      ex = b[1][1]
      if b[0][1] == 0 and b[1][1] == 0:
        break
    else:
      b[0][0] -= 1
      if ex == b[0][1]:
        ans+=1
      ex = b[0][1]
      if b[0][1] == 0 and b[1][1] == 0:
        break
  print(ans)
Problem:
A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction.  This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back.    * `F` : Move in the current direction by distance 1.   * `T` : Turn 90 degrees, either clockwise or counterclockwise.  The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.

Incorrect submission (verdict: Wrong Answer):
from copy import copy
s = input() + "T"
x,y = map(int, input().split())
 
d = [len(p) for p in s.split("T")]
x = d[0]
d_x = d[2::2]
d_y = d[1::2]
 
xs = set([x])
ys = set([0])
dpx = [x in xs]
for d in d_x:
  xs_ = set()
  for x in xs:
    xs_.add(x+d)
    xs_.add(x-d)
  dpx.append(x in xs_)
  xs = copy(xs_)

dpy = []
for d in d_y:
  ys_ = set()
  for y in ys:
    ys_.add(y+d)
    ys_.add(y-d)
  dpy.append(y in ys_)
  ys = copy(ys_)

if dpx[-1] and dpy[-1]: print("Yes")
else: print("No")

Fixed, accepted submission:
from copy import copy
s = input() + "T"
x,y = map(int, input().split())

d = [len(p) for p in s.split("T")]
init = d[0]
d_x = d[2::2]
d_y = d[1::2]

xs = set([init])
ys = set([0])
dpx = [x in xs]
for d in d_x:
  xs_ = set()
  for u in xs:
    xs_.add(u+d)
    xs_.add(u-d)
  dpx.append(x in xs_)
  xs = copy(xs_)

dpy = []
for d in d_y:
  ys_ = set()
  for v in ys:
    ys_.add(v+d)
    ys_.add(v-d)
  dpy.append(y in ys_)
  ys = copy(ys_)

if dpx[-1] and dpy[-1]: print("Yes")
else: print("No")
Problem:
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.  Determine if it is possible that there are exactly X cats among these A + B animals.

Incorrect submission (verdict: Wrong Answer):
A,B,X=map(int,input().split())
if A+B>=X>=A:print('Yes')
else:print('No')

Fixed, accepted submission:
A,B,X=map(int,input().split())
if A<=X<=A+B:print('YES')
else:print('NO')
Problem:
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}.  Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.

Incorrect submission (verdict: Wrong Answer):
s1 = input()
s2 = input()
s3 = input()

print(s1[0],s2[1],s3[2])

Fixed, accepted submission:
s1 = input()
s2 = input()
s3 = input()

print(s1[0]+s2[1]+s3[2])
Problem:
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.  Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).  Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:    * If a_i = 1, he painted the region satisfying x < x_i within the rectangle.   * If a_i = 2, he painted the region satisfying x > x_i within the rectangle.   * If a_i = 3, he painted the region satisfying y < y_i within the rectangle.   * If a_i = 4, he painted the region satisfying y > y_i within the rectangle.  Find the area of the white region within the rectangle after he finished painting.

Incorrect submission (verdict: Wrong Answer):
w, h, n = list(map(int, input().split()))
xya = []
for i in range(n):
    xya.append(list(map(int, input().split())))

min_x_1 = w
max_x_2 = 0
min_y_3 = h
max_y_4 = 0
for i in range(n):
    ai = xya[i][2]
    if ai == 1:
        if xya[i][0] < min_x_1:
            min_x_1 = xya[i][0]
    if ai == 2:
        if xya[i][0] > max_x_2:
            max_x_2 = xya[i][0]
    if ai == 3:
        if xya[i][1] < min_y_3:
            min_y_3 = xya[i][1]
    if ai == 4:
        if xya[i][1] > max_y_4:
            max_y_4 = xya[i][1]

x = max_x_2 - min_x_1
if x <= 0:
    print("0")
else:
    y = max_y_4 - min_y_3
    if y <= 0:
        print("0")
    else:
        print(x * y)


Fixed, accepted submission:
w, h, n = list(map(int, input().split()))
xya = []
for i in range(n):
    xya.append(list(map(int, input().split())))

max_x_1 = 0
min_x_2 = w
max_y_3 = 0
min_y_4 = h
for i in range(n):
    ai = xya[i][2]
    if ai == 1:
        if xya[i][0] > max_x_1:
            max_x_1 = xya[i][0]
    if ai == 2:
        if xya[i][0] < min_x_2:
            min_x_2 = xya[i][0]
    if ai == 3:
        if xya[i][1] > max_y_3:
            max_y_3 = xya[i][1]
    if ai == 4:
        if xya[i][1] < min_y_4:
            min_y_4 = xya[i][1]

x = min_x_2 - max_x_1
if x <= 0:
    print("0")
else:
    y = min_y_4 - max_y_3
    if y <= 0:
        print("0")
    else:
        print(x * y)
Problem:
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:    * The graph is simple and connected.   * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S.  It can be proved that at least one such graph exists under the constraints of this problem.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
if n%2 ==0:
  print(n*(n+1)//2-n-1)
else:
  print((n-1)*n//2)

if n%2 ==1:
  for i in range(n-1):
    print(i+1,n)
  n = n-1

if n%2 ==0:
  wa = n+1
  for i in range(n):
    for j in range(i+1,n):
      if wa != i+j+2:
        print(i+1,j+1)

Fixed, accepted submission:
n = int(input())

li = []

for i in range(0,(n//2)*2):
  if i+1 < n-i:
    li.append([i+1,n-i-n%2])
  else:
    break
if n%2 == 1:
  li.append([n])
if len(li) > 2:
  li.append(li[0])

count = 0
for i in range(1,len(li)):
  for j in li[i-1]:
    for k in li[i]:
      count += 1
print(count)
for i in range(1,len(li)):
  for j in li[i-1]:
    for k in li[i]:
      print(j,k)
Problem:
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.  He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.  Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

Incorrect submission (verdict: Wrong Answer):
from collections import Counter

n, k = list(map(int, input().split()))
balls = list(map(int, input().split()))
b_list = set(balls)
nums = len(b_list)

yoso, s_yoso = [], []
counter = Counter(balls)
kakikae, t = 0, 1
if nums > k:
    for i, v in counter.most_common():
        yoso += [v]

if nums <= k:
    print(0)
else:
    s_yoso = sorted(yoso, reverse=True)
    while nums - k > t:
        kakikae += s_yoso[t-1]
        t += 1
    print(kakikae)

Fixed, accepted submission:
from collections import Counter

n, k = list(map(int, input().split()))
a = Counter(map(int, input().split()))
a = list(a.items())
a.sort(key=lambda x: x[1])
opt = len(a) - k
ans = 0
if opt > 0:
    for i in range(opt):
        ans += a[i][1]
print(ans)
Problem:
1 〜 9 の数字を 14 個組み合わせて完成させるパズルがあります。与えられた 13 個の数字にもうひとつ数字を付け加えて完成させます。  パズルの完成条件は    * 同じ数字を２つ組み合わせたものが必ずひとつ必要です。   * 残りの12 個の数字は、３個の数字の組み合わせ４つです。   ３個の数字の組み合わせ方は、同じ数字を３つ組み合わせたものか、または３つの連続する数字を組み合わせたものです。ただし、9 1 2 のような並びは連続する数字とは認められません。    * 同じ数字は4 回まで使えます。  13 個の数字からなる文字列を読み込んで、パズルを完成することができる数字を昇順に全て出力するプログラムを作成してください。なお、1〜9 のどの数字を付け加えてもパズルを完成させることができないときは 0 を出力してください。  例えば与えられた文字列が 3456666777999 の場合      「2」があれば、 234 567 666 77 999   「3」があれば、 33 456 666 777 999   「5」があれば、 345 567 666 77 999   「8」があれば、 345 666 678 77 999      というふうに、2 3 5 8 のいずれかの数字が付け加えられるとパズルは完成します。「6」でも整いますが、5 回目の使用になるので、この例では使えないことに注意してください。

Incorrect submission (verdict: Wrong Answer):
from collections import deque

try:
    while True:
        a = list(sorted(map(int, input())))
        result = []

        for i in range(1, 10):
            if a.count(i) == 4:
                continue

            _a = sorted(a+[i])
            dq = deque([(_a, 0)])
            while dq:
                hand, mentu = dq.popleft()
                if mentu == 5:
                    if not hand:
                        result.append(i)
                        break
                    continue

                if hand.count(hand[0]) >= 2:
                    dq.append((hand[2:], mentu+1))
                if hand.count(hand[0]) >= 3:
                    dq.append((hand[3:], mentu+1))
                if hand.count(hand[0]+1) > 0 and hand.count(hand[0]+2) > 0:
                    _hand = hand[:]
                    del _hand[0]
                    del _hand[_hand.index(hand[0]+1)]
                    del _hand[_hand.index(hand[0]+2)]
                    dq.append((_hand, mentu+1))

        print(" ".join(map(str, result)) if result else 0)


except EOFError as e:
    print(e)
    exit()


Fixed, accepted submission:
from collections import deque

try:
    while True:
        a = list(sorted(map(int, input())))
        result = []

        for i in range(1, 10):
            if a.count(i) == 4:
                continue

            _a = sorted(a+[i])
            dq = deque([(_a, 0)])
            while dq:
                hand, mentu = dq.popleft()
                if mentu == 5:
                    if not hand:
                        result.append(i)
                        break
                    continue
                elif mentu > 5:
                    continue

                current = hand[0]
                if hand.count(current) >= 2:
                    dq.append((hand[2:], mentu+1))
                if hand.count(current) >= 3:
                    dq.append((hand[3:], mentu+1))
                if current+1 in hand and current+2 in hand:
                    _hand = hand[:]
                    del _hand[0]
                    del _hand[_hand.index(current+1)]
                    del _hand[_hand.index(current+2)]
                    dq.append((_hand, mentu+1))

        print(" ".join(map(str, result)) if result else 0)


except EOFError:
    exit()
Problem:
We ask you to select some number of positive integers, and calculate the sum of them.  It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.  Your objective is to make the sum congruent to C modulo B. Determine whether this is possible.  If the objective is achievable, print `YES`. Otherwise, print `NO`.

Incorrect submission (verdict: Wrong Answer):
a,b,c = map(int, input().split())

if(((a%2==0 or b%2==0) and c%2==0) or ((a%2==1 or b%2==1) and c%2==1)):
    if((a-b)%2==c%2):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Fixed, accepted submission:
a,b,c = map(int, input().split())
t = False
for i in range(1,b+1):
    if((a*i)%b==c):
        t=True
        break

if(t):
    print('YES')
else:
    print('NO')
Problem:
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains.  Write a program which prints heights of the top three mountains in descending order.

Incorrect submission (verdict: Wrong Answer):
h=sorted([int(input())for _ in range(10)])
print(h[9:6:-1],sep='\n')


Fixed, accepted submission:
print(*sorted(int(input())for _ in[0]*10)[:6:-1],sep='\n')
Problem:
Write a program which reads three integers, and prints them in ascending order.

Incorrect submission (verdict: Wrong Answer):
x = input()
# x = str('6 2 5')
a = [int(n) for n in x.split()]
a.sort()
print(a)

Fixed, accepted submission:
x = input()
#x = str('6 2 5')
a = [n for n in x.split()]
a.sort()
print(' '.join(a))
Problem:
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`.  You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.

Incorrect submission (verdict: Wrong Answer):
s = input()
print(s[0] + str(len(s)-2) + s[-0])

Fixed, accepted submission:
s = input()
c = 0
for i in s:
  c += 1
print(s[0] + str(c-2) + s[-1])
Problem:
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:    * Choose two among A, B and C, then increase both by 1.   * Choose one among A, B and C, then increase it by 2.  It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.

Incorrect submission (verdict: Wrong Answer):
from sys import stdin

li = list(map(int,stdin.readline().rstrip().split()))

li.sort(reverse = True)

point = 0
su = sum(li)%2
sai = li[0]%2

if su != sai:
    li[0] += 1
    point += 1


for i in range(1,len(li)):
    point += (li[0]-li[i])//2

print(point)

Fixed, accepted submission:
li = list(map(int,input().split()))
li.sort()

lin = li[:]

if sum(li)%2 != 3*li[2]%2:
    lin[2] += 1

print((lin[2]*3-sum(li))//2)
Problem:
You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen.  Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ .

Incorrect submission (verdict: Wrong Answer):
n = int(input())
r_first = int(input())
max_r = r_first
min_r = r_first

for _ in range(n - 1):
    r = int(input())
    if r > max_r:
        max_r = r
    if r < min_r:
        min_r = r

ans = max_r - min_r

print(ans)

Fixed, accepted submission:
n = int(input())
R = list()

for _ in range(n):
    R.append(int(input()))

ans = R[1] - R[0]
min_R = R[0]

for i in range(1, n):
    ans   = max(ans, R[i] - min_R)
    min_R = min(min_R, R[i])
print(ans)
Problem:
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room.  For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left.  Assume that initially no person lives in the building.

Incorrect submission (verdict: Wrong Answer):
bldgs = []
for k in range(4):
    bldgs.append([[0 for i in range(10)] for j in range(3)])

n = int(input())
for i in range(n):
    b,f,r,v = map(int, input().split(' '))
    bldgs[b-1][f-1][r-1] += v

for bldg in bldgs:
    for floor in bldg:
        print(' '.join([str(f) for f in floor]))
    print('#'*20)

Fixed, accepted submission:
buildings = [ [
    [ 0 for _ in range(10) ] for _ in range(3)
] for _ in range(4) ]

n = int(input())

for _ in range(n):
    b, f, r, v = map(int, input().split())
    buildings[b-1][f-1][r-1] += v

sep = ''

for building in buildings:
    if sep:
        print(sep)

    for floor in building:
        print(" "+" ".join([str(x) for x in floor]))

    sep = '#'*20