TnT/CodeNet4Repair huggingface dataset:
Problem:
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.  If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.

Incorrect submission (verdict: Wrong Answer):
def odd_even(a, b):
    if a % 2 == b % 2:
        return True
    else:
        return False

n = int(input())
T, X, Y = [0], [0], [0]
for _ in range(n):
    t, x, y = map(int, input().split())
    T.append(t)
    X.append(x)
    Y.append(y)

ans = 'Yes'

for i in range(1,n+1):
    t_dif = T[i] - T[i-1]
    x_dif = abs(X[i]-X[i-1])
    y_dif = abs(Y[i]-Y[i-1])
    if t_dif <= (x_dif + y_dif) and odd_even(t_dif, x_dif+y_dif):
        pass
    else:
        ans = 'No'
        break

print(ans)

Fixed, accepted submission:
def odd_even(a, b):
    if a % 2 == b % 2:
        return True
    else:
        return False

n = int(input())
T, X, Y = [0], [0], [0]
for _ in range(n):
    t, x, y = map(int, input().split())
    T.append(t)
    X.append(x)
    Y.append(y)

ans = 'Yes'

for i in range(1,n+1):
    t_dif = T[i] - T[i-1]
    x_dif = abs(X[i]-X[i-1])
    y_dif = abs(Y[i]-Y[i-1])
    if t_dif >= (x_dif + y_dif) and odd_even(t_dif, x_dif+y_dif):
        pass
    else:
        ans = 'No'
        break

print(ans)
Problem:
You are given an integer sequence of length N, a_1,a_2,...,a_N.  For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.  After these operations, you select an integer X and count the number of i such that a_i=X.  Maximize this count by making optimal choices.

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

b = []

for i in range(len(a)):
    s = 0
    for j in range(len(a)):
        if abs(a[i]-a[j]) < 3:
            s = s + 1
        else:
            None
    b.append(s)
            
print(max(b))
    

Fixed, accepted submission:
n = int(input())
a = list(map(int,input().split()))
aa = []
amax = max(a) + 100


for i in range(amax + 1):
    aa.append(0)

for i in range(len(a)):
    aa[a[i]] = aa[a[i]] + 1
    
kouho = 1    
for j in range(len(aa) - 2):
    if kouho < aa[j] + aa[j + 1] + aa[j + 2]:
        kouho = aa[j] + aa[j + 1] + aa[j + 2]

print(kouho)
Problem:
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied:    * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.  Find all favorite numbers and print the sum of those.

Incorrect submission (verdict: Wrong Answer):
def main():
    N = int(input())
    ans = 0
    for m in range(1, N+1):
        if N % (m + 1) != 0:
            pass
        else:
            ans += m
    print(ans)


if __name__ == '__main__':
    main()


Fixed, accepted submission:
from math import floor, sqrt


def main():
    N = int(input())
    divs = divisor(N)
    ans = 0
    for i in divs:
        m = i - 1
        if m == 0:
            continue
        if N // m == N % m:
            ans += m
    print(ans)


def divisor(N):
    divs = []
    sup = floor(sqrt(N))
    for i in range(1, sup+1):
        if N % i == 0:
            divs.append(i)
            divs.append(N // i)
    return sorted(divs)


if __name__ == '__main__':
    main()
Problem:
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1.  Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode:                 BubbleSort(C) 1 for i = 0 to C.length-1 2     for j = C.length-1 downto i+1 3         if C[j].value < C[j-1].value 4             swap C[j] and C[j-1]                 SelectionSort(C) 1 for i = 0 to C.length-1 2     mini = i 3     for j = i to C.length-1 4         if C[j].value < C[mini].value 5             mini = j 6     swap C[i] and C[mini]   Note that, indices for array elements are based on 0-origin.  For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).

Incorrect submission (verdict: Wrong Answer):
import copy

n=int(input())
s=input().split(' ')
s1=[]
s2=[]
s1=copy.deepcopy(s)
s2=copy.deepcopy(s)

def Bubble_Sort(n,s1):
	m=0
	flag=1
	while flag:
		flag=0
		for i in range(1,n):
			j=n-i
			if int(s1[j][1])<int(s1[j-1][1]):
				a=s1[j]
				s1[j]=s1[j-1]
				s1[j-1]=a
				m+=1
				flag=1
	b=s1
	return(b)

def Selection_Sort(n,s2):
	m=0
	for i in range(n):
		minj=i
		for j in range(i,n):
			if int(s2[j][1])<int(s2[minj][1]):
				minj=j
		if i!=minj:
			a=s2[minj]
			s2[minj]=s2[i]
			s2[i]=a
			m+=1
	b=s2
	return(b)

s1=Bubble_Sort(n,s1)
s2=Selection_Sort(n,s2)

print(s1)
print('stable')
print(s2)
if s1==s2:
	print('Stable')
else:
	print('Not stable')


Fixed, accepted submission:
import copy

n=int(input())
s=input().split(' ')
s1=[]
s2=[]
s1=copy.deepcopy(s)
s2=copy.deepcopy(s)

def Bubble_Sort(n,s1):
	m=0
	flag=1
	while flag:
		flag=0
		for i in range(1,n):
			j=n-i
			if int(s1[j][1])<int(s1[j-1][1]):
				a=s1[j]
				s1[j]=s1[j-1]
				s1[j-1]=a
				m+=1
				flag=1
	b=s1
	return(b)

def Selection_Sort(n,s2):
	m=0
	for i in range(n):
		minj=i
		for j in range(i,n):
			if int(s2[j][1])<int(s2[minj][1]):
				minj=j
		if i!=minj:
			a=s2[minj]
			s2[minj]=s2[i]
			s2[i]=a
			m+=1
	b=s2
	return(b)

s1=Bubble_Sort(n,s1)
s2=Selection_Sort(n,s2)

print(' '.join(s1))
print('Stable')
print(' '.join(s2))
if s1==s2:
	print('Stable')
else:
	print('Not stable')
Problem:
For a given sequence $A = \\{a_0, a_1, ... a_{n-1}\\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equal to the number of swaps of Bubble Sort defined in the following program:                 bubbleSort(A)   cnt = 0 // the number of inversions   for i = 0 to A.length-1     for j = A.length-1 downto i+1       if A[j] < A[j-1] 	swap(A[j], A[j-1]) 	cnt++    return cnt   For the given sequence $A$, print the number of inversions of $A$. Note that you should not use the above program, which brings Time Limit Exceeded.

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

def merge_and_count(a, b):
    i, j = 0, 0
    count = 0
    m = []
    while i < len(a) and j < len(b):
        if a[i] <= b[j]:
            m.append(a[i])
            i += 1
        else:
            count += len(a)-i
            m.append(b[j])
            j += 1

    if i < len(a):
        m += a[i:]
    else:
        m += b[j:]

    return (count, m)



def sort_and_count(l):
    if len(l) == 1:
        return 0, []
    else:
        a = l[0:len(l)//2]
        b = l[len(l)//2:]
        rA, a_ = sort_and_count(a)
        rB, b_ = sort_and_count(b)
        r, l_ = merge_and_count(a, b)
#        print(a, b)
#        print(rA, rB, a_, b_, r, l_)
    return (rA+rB+r, l_)

print(sort_and_count(a)[0])

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

def merge_and_count(a, b):
    i, j = 0, 0
    count = 0
    m = []
    while i < len(a) and j < len(b):
        if a[i] <= b[j]:
            m.append(a[i])
            i += 1
        else:
            count += len(a)-i
            m.append(b[j])
            j += 1

    if i < len(a):
        m += a[i:]
    else:
        m += b[j:]

    return (count, m)



def sort_and_count(l):
    if len(l) == 1:
        return 0, l
    else:
        a = l[0:len(l)//2]
        b = l[len(l)//2:]
        rA, a_ = sort_and_count(a)
        rB, b_ = sort_and_count(b)
        r, l_ = merge_and_count(a_, b_)
    return (rA+rB+r, l_)

print(sort_and_count(a)[0])
Problem:
We have N cards. A number a_i is written on the i-th card.   Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.   The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
print(sum(a)-sum(a[::2]))

Fixed, accepted submission:
N = int(input())
A = sorted(list(map(int,input().split())))[::-1]
print(sum(A[0::2])-sum(A[1::2]))
Problem:
Joisino is working as a receptionist at a theater.  The theater has 100000 seats, numbered from 1 to 100000.  According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).  How many people are sitting at the theater now?

Incorrect submission (verdict: Wrong Answer):
n=int(input())
s=0
for i in range(n):
    l=list(map(int,input().split()))
    s+=len(l)
print(s)

Fixed, accepted submission:
n=int(input())
s=0
for i in range(n):
    l,r=map(int,input().split())
    s+=r-l+1
print(s)
Problem:
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of   AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.

Incorrect submission (verdict: Wrong Answer):
W,a,b = map(int,input().split())
A = min(a,b)
B = max(a,b)
print(A,B)
if B-A >= W:
	ans = B-A-W
else:
	ans = 0
print(ans)

Fixed, accepted submission:
W,a,b = map(int,input().split())
A = min(a,b)
B = max(a,b)

if B-A >= W:
	ans = B-A-W
else:
	ans = 0
print(ans)
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], len(s), s[-1], sep='')

Fixed, accepted submission:
s = input()
print(s[0]+str(len(s[1:-1]))+s[-1])
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 > x:
  print('No')
else:
  if a + b < x:
    print('No')
  else:
    print('Yes')

Fixed, accepted submission:
a,b,x = map(int, input().split())
if a > x:
  print('NO')
else:
  if a + b < x:
    print('NO')
  else:
    print('YES')
Problem:
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.

Incorrect submission (verdict: Wrong Answer):
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
a.sort()
b = []
c = []
for i in range(n):
  if i%2:
    b.append(a[i//2])
    c.append(a[i//2+(n+1)//2])
  else:
    b.append(a[i//2+n//2])
    c.append(a[i//2])

ansb = 0
ansc = 0
for i in range(n-1):
  ansb += abs(b[i+1]-b[i])
  ansc += abs(c[i+1]-c[i])
print(max(ansb,ansc))

Fixed, accepted submission:
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
a.sort()
b = []
c = []
for i in range(n):
  if i%2:
    b.append(a[i//2])
    c.append(a[i//2+(n+1)//2])
  else:
    b.append(a[i//2+n//2])
    c.append(a[i//2])
if n>=3 and n%2:
  b[-1],b[2] = b[2],b[-1]
  c[0],c[-3] = c[-3],c[0]
ansb = 0
ansc = 0
for i in range(n-1):
  ansb += abs(b[i+1]-b[i])
  ansc += abs(c[i+1]-c[i])
print(max(ansb,ansc))
Problem:
Rng is going to a festival.  The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer.  Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.

Incorrect submission (verdict: Wrong Answer):
print(input()+"FESTIVAL")

Fixed, accepted submission:
print(input()[:-8])
Problem:
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them.  He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).  Find the minimum total cost to achieve his objective.

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

max_a = max(a)
min_a = min(a)

sum_a = max(a) * len(a)
ans = 0

for i in range(min_a, max_a):
    s = sum([(j-i)**2 for j in a])
    if sum_a > s:
        sum_a = s
        ans = i

print(ans)

Fixed, accepted submission:
n = int(input())
a = list(map(int, input().split()))

ans = sum([i**2 for i in a])

for i in range(-100, 100+1):
    s = sum([(j-i)**2 for j in a])
    if ans > s:
        ans = s

print(ans)
Problem:
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:    * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.  What is the largest possible sum of the integers written on the blackboard after K operations?

Incorrect submission (verdict: Wrong Answer):
s=list(map(int,input().split()))
k=int(input())
s.sort()
m=1
m *= s[2]*k
print(m+s[0]+s[1])

Fixed, accepted submission:
s=list(map(int,input().split()))
k=int(input())
s.sort()
m=1
m *= (s[2]*(2**k))
print(m+s[0]+s[1])
Problem:
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.  Given an integer N, determine whether it is a Harshad number.

Incorrect submission (verdict: Wrong Answer):

if __name__ == '__main__':

    n = int(input())
    m = n

    div = 0
    while n != 0 :
        div += n % 10
        n = n // 10

    if m % div == 0 :
        print('YES')
    else :
        print('NO')

Fixed, accepted submission:

if __name__ == '__main__':

    n = int(input())
    m = n

    div = 0
    while n != 0 :
        div += n % 10
        n = n // 10

    if m % div == 0 :
        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 <= x <= a+b:
    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 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())
print(n-((n//1000)*1000))


Fixed, accepted submission:
n=int(input())
if(n%1000==0):
    print(0)
else:
    rem=1000-n%1000
    print(rem)
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):
N,M = map(int,input().split())
for i in range(M):
    print(i + 1, 2 * M - i)

Fixed, accepted submission:
N,M = map(int,input().split())
if M % 2 == 1:
    for i in range(M // 2):
        print(1 + i, M - i)
    for i in range(M - M // 2):
        print(M + 1 + i, 2 * M + 1 - i)
else:
    for i in range(M // 2):
        print(1 + i, M + 1 - i)
        print(M + 2 + i, 2 * M + 1 - i)
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):
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
nums = {}
for a in A:
    if a in nums:
        nums[a] += 1
    else:
        nums[a] = 1
sorted_nums = list(sorted(nums.items(), key=lambda x: x[1]))
nums_len = len(sorted_nums)
ans = 0
if nums_len > K:
    for i in range(nums_len - K):
        ans += sorted_nums[i][1]
        print(i, sorted_nums[i][0], sorted_nums[i][1])
print(ans)


Fixed, accepted submission:
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
nums = {}
for a in A:
    if a in nums:
        nums[a] += 1
    else:
        nums[a] = 1
sorted_nums = list(sorted(nums.items(), key=lambda x: x[1]))
nums_len = len(sorted_nums)
ans = 0
if nums_len > K:
    for i in range(nums_len - K):
        ans += sorted_nums[i][1]
print(ans)
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):
def main():
    N = int(input())

    return N % 1000

print(main())


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

    return (1000 - (N % 1000)) % 1000

print(main())
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):
l = sorted(map(int,input().split()))[::-1]
a = l[0]
b = l[1]
c = l[2]
s = 0
s += b-a
c += (b-a)
if (a-c)%2==0:
  s += (a-c)//2
else:
  s += (a-c-1)//2+1
print(s)

Fixed, accepted submission:
l = sorted(map(int,input().split()))[::-1]
a = l[0]
b = l[1]
c = l[2]
s = 0
s += a-b
c += (a-b)
if (a-c)%2==0:
  s += (a-c)//2
else:
  s += (a-c-1)//2+2
print(s)
Problem:
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.

Incorrect submission (verdict: Wrong Answer):
s = input()
t = input()

if sorted(s) < sorted(t):
    print('Yes')
else:
    print('No')


Fixed, accepted submission:
s = input()
t = input()

if sorted(s) < sorted(t, reverse=True):
    print('Yes')
else:
    print('No')
Problem:
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it.  The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer).  Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer.  If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.

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

for i in range(50000):
  if int(i*1.05) == X:
    print(i)
    break
else:
  print(':(')

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

for i in range(50000):
  if int(i*1.08) == X:
    print(i)
    break
else:
  print(':(')
Problem:
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.

Incorrect submission (verdict: Wrong Answer):
num = int(input())
list = [i ** 5 for i in range(1000)]
ans = []
for a in range(1000):
    for b in range(1000):
        if list[a] - list[b] == num: 
            ans = [a, b]
            break
        if list[a] + list[b] == num:
            ans = [a, b * (-1)]
            break
print(ans)

Fixed, accepted submission:
num = int(input())
list = [i ** 5 for i in range(1000)]
ans = []
for a in range(1000):
    for b in range(1000):
        if list[a] - list[b] == num: 
            ans = [a, b]
            break
        if list[a] + list[b] == num:
            ans = [a, b * (-1)]
            break
print(' '.join(map(str, ans)))
Problem:
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.  He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.

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

if a > b:
    aa = a - t * v
    bb = b - t * w
    if aa > bb:
        print('No')
    else:
        print('Yes')
elif a < b:
    aa = a + t * v
    bb = b + t * w
    if aa < bb:
        print('No')
    else:
        print('Yes')
else:
    print('Yes')


Fixed, accepted submission:
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a > b:
    aa = a - t * v
    bb = b - t * w
    if aa > bb:
        print('NO')
    else:
        print('YES')
elif a < b:
    aa = a + t * v
    bb = b + t * w
    if aa < bb:
        print('NO')
    else:
        print('YES')
else:
    print('YES')