TnT/CodeNet4Repair huggingface dataset:
Problem:
Sitting in a station waiting room, Joisino is gazing at her train ticket.  The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).  In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds.  The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

Incorrect submission (verdict: Wrong Answer):
#coding: utf-8

S = str(input())
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

shiki = ''

for i in range(2):
    for j in range(2):
        for k in range(2):
            B = B * (-1) ** i
            C = C * (-1) ** j
            D = D * (-1) ** k
            if(A + B + C + D == 7):
                shiki += str(A)

                if(B<0):
                    shiki += '-' + str(B)
                else:
                    shiki += '+' + str(B)

                if(C<0):
                    shiki += '-' + str(C)
                else:
                    shiki += '+' + str(C)

                if(D<0):
                    shiki += '-' + str(D)
                else:
                    shiki += '+' + str(D)
                print(shiki,end='')
                break
        break
    break

Fixed, accepted submission:
#coding: utf-8

S = str(input())
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

for i in range(2):
    for j in range(2):
        for k in range(2):
            A = int(S[0])
            B = int(S[1])
            C = int(S[2])
            D = int(S[3])

            B *= (-1) ** i
            C *= (-1) ** j
            D *= (-1) ** k
            if(A + B + C + D == 7):
                shiki = ''
                shiki += str(A)
                if(B<0):
                    shiki += str(B)
                else:
                    shiki += '+' + str(B)

                if(C<0):
                    shiki += str(C)
                else:
                    shiki += '+' + str(C)

                if(D<0):
                    shiki += str(D)
                else:
                    shiki += '+' + str(D)
                shiki += '=7'
                print(shiki)
                exit()
Problem:
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:                 SelectionSort(A) 1 for i = 0 to A.length-1 2     mini = i 3     for j = i to A.length-1 4         if A[j] < A[mini] 5             mini = j 6     swap A[i] and A[mini]   Note that, indices for array elements are based on 0-origin.  Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.

Incorrect submission (verdict: Wrong Answer):
def selectionSort(n, A):
    cnt =0
    for i in range(n):
        minj = i
        for j in range(i,n):
            if A[minj] > A[j]:
                minj = j
        A[i],A[minj] = A[minj],A[i]
        cnt += 1
    print(*A)
    print(cnt)

if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().split()))
    selectionSort(n,A)

Fixed, accepted submission:
def selectionSort(n, A):
    cnt =0
    for i in range(n):
        minj = i
        for j in range(i,n):
            if A[minj] > A[j]:
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]
            cnt += 1
    print(*A)
    print(cnt)

if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().split()))
    selectionSort(n,A)
Problem:
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.

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

if a >= c >= b:
	print("Yes")
else:
	print("No")

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

if a >= c >= b:
	print("Yes")
elif a <= c <= b:
    print("Yes")
else:
	print("No")
Problem:
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.  The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.  Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.

Incorrect submission (verdict: Wrong Answer):
A = input()
count = 0
for i in A:
  if i == 'x':
    count += 1
b = len(A) - count
if 15-b > 7:
  print('Yes')
else:
  print('No')

Fixed, accepted submission:
A = input()
count = 0
for i in A:
  if i == 'o':
    count += 1
b = len(A) - count
if 15 - b > 7:
  print('YES')
else:
  print('NO')
Problem:
You are parking at a parking lot. You can choose from the following two fee plans:    * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours.   * Plan 2: The fee will be B yen, regardless of the duration.  Find the minimum fee when you park for N hours.

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

Fixed, accepted submission:
n, a, b = map(int, input().split())
print(min(n * a, b))
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())

ans = "No"

if v <= w:
  print(ans)
  exit()


x = abs(v-w)
y = abs(a-b)

if y <= x*t:
  ans = "Yes"

print(ans)

Fixed, accepted submission:
#-------------------------------------------------------------------
import sys
def p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())

ans = "NO"

x = v-w
y = abs(a-b)

p(x,y)
if y <= x*t:
  ans = "YES"

print(ans)
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:
    su = n+1
    print((n*(n-1)//2)-n//2)
    for i in range(1,n+1):
        for k in range(1,n+1):
            if i+k != su and i < k:
                print(i,k)
if n%2 == 1:
    su = n+1
    print((n*(n-1)//2)-(n-1)//2)
    for i in range(1,n+1):
        for k in range(1,n+1):
            if i+k != su and i < k:
                print(i,k)


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

if n%2 == 0:
    su = n+1
    print((n*(n-1)//2)-n//2)
    for i in range(1,n+1):
        for k in range(1,n+1):
            if i+k != su and i < k:
                print(i,k)
if n%2 == 1:
    su = n
    print((n*(n-1)//2)-(n-1)//2)
    for i in range(1,n+1):
        for k in range(1,n+1):
            if i+k != su and i < k:
                print(i,k)
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: Time Limit Exceeded):
X = int(input())
def modpow(a, n, mod):
    ret = 1
    while n > 0:
        if n % 2 == 1:
            ret = ret * a % mod
        a *= a
        a = a % mod
    return ret
i = 0
L = list()
while True:
    num = modpow(i,5,X)
    if num in L:
        j = L.index(num)
        ret = '{} {}'.format(i,j)
        print(ret)
        break
    else:
        L.append(num)

Fixed, accepted submission:
X = int(input())
L = list()
i = 0
while True:
    if i ** 5 > 10 ** 11:
        break
    L.append(i ** 5)
    i += 1
flag = False
ret = ''
for i in range(len(L)):
    if flag:
        break
    for j in range(i+1, len(L)):
        if L[j] - L[i] == X :
            ret ='{} {}'.format(j,i)
            flag = True
            break
        if L[j] + L[i] == X :
            ret ='{} {}'.format(j,-i)
            flag = True
            break
print(ret)
Problem:
M-kun has the following three cards:    * A red card with the integer A.   * A green card with the integer B.   * A blue card with the integer C.  He is a genius magician who can do the following operation at most K times:    * Choose one of the three cards and multiply the written integer by 2.  His magic is successful if both of the following conditions are satisfied after the operations:    * The integer on the green card is **strictly** greater than the integer on the red card.   * The integer on the blue card is **strictly** greater than the integer on the green card.  Determine whether the magic can be successful.

Incorrect submission (verdict: Wrong Answer):
abc=list(map(int, input().split()))
k=int(input())
a=abc[0]
b=abc[1]
c=abc[2]

num=0
if(a < b):
  if(b < c):
    print("Yes")
  else:
    while num<k:
      c=2*c
      num=num+1
      if(b<c):
        print("Yes")
        break
    print("No")
else:
  while num<k:
    b=2*b
    num=num+1
    if(a<b):
      while num<k:
        c=2*c
        num=num+1
        if(b<c):
          print("Yes")
          break
      print("No")
  print("No")

Fixed, accepted submission:
abc=list(map(int, input().split()))
k=int(input())
a=abc[0]
b=abc[1]
c=abc[2]

num=0
if(a < b):
  if(b < c):
    print("Yes")
  else:
    while num<k:
      c=2*c
      num=num+1
      if(b<c):
        print("Yes")
        break
    if(b>=c):
      print("No")
else:
  while num<k:
    b=2*b
    num=num+1
    if(a<b):
      break
  if(a<b):
    while num<k:
      c=2*c
      num=num+1
      if(b<c):
        print("Yes")
        break
    if(b>=c):
      print("No")
  else:
    print("No")
Problem:
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.  Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.  Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.  Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.

Incorrect submission (verdict: Wrong Answer):
x,a,b = map(int,input().split())
if x+a >= b:
  print("delicious")
elif x+a+1 == b:
  print("safe")
else:
  print("dangerous")

Fixed, accepted submission:
x,a,b = map(int,input().split())
if a >= b:
  print("delicious")
elif x+a >= b:
  print("safe")
else:
  print("dangerous")
Problem:
Print all the integers that satisfies the following in ascending order:    * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.

Incorrect submission (verdict: Wrong Answer):
A, B, K = map(int, input().split())
L = [x for x in range(A, B + 1)]
print(*set((L[:K] + L[-K:])))


Fixed, accepted submission:
A, B, K = map(int, input().split())
L = range(A, B + 1)
print(*sorted(set(L[:K]) | set(L[-K:])), sep="\n")
Problem:
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.

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

seta = sorted(list(set(a)))

resn = seta[-1]
resr = seta[0]
for sa in seta:
    sabun = abs(resn / 2 - sa)
    if sabun  == 0 or sabun == 0.5:
        resr == sa
        break
    elif sabun < abs(resn / 2 - resr):
        resr = sa

print(str(resn) + " " + str(resr))

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

seta = sorted(list(set(a)))

resn = seta[-1]
resr = seta[0]
for sa in seta:
    sabun = abs(resn / 2 - sa)
    if sabun  == 0 or sabun == 0.5:
        resr = sa
        break
    elif sabun < abs(resn / 2 - resr):
        resr = sa

print(str(resn) + " " + str(resr))
Problem:
Write a program which calculates the area and perimeter of a given rectangle.

Incorrect submission (verdict: Wrong Answer):
ab = input().split()
print(ab)

Fixed, accepted submission:
a, b = [int(i) for i in input().split()]
print(a * b, (a + b) * 2)
Problem:
You have an integer variable x. Initially, x=0.  Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`.  Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).

Incorrect submission (verdict: Wrong Answer):
N = int(input())
S = input()
num = 0
for s in S:
    if s == "I":
        num += 1
    else:
        num -= 1
print(num)


Fixed, accepted submission:
N = int(input())
S = input()
max_num = 0
num = 0
for s in S:
    if s == "I":
        num += 1
    else:
        num -= 1
    max_num = max(max_num, num)
print(max_num)
Problem:
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:    * Hit his pocket, which magically increases the number of biscuits by one.   * Exchange A biscuits to 1 yen.   * Exchange 1 yen to B biscuits.  Find the maximum possible number of biscuits in Snuke's pocket after K operations.

Incorrect submission (verdict: Wrong Answer):
K, A, B =map(int,input().split())
import sys
should_actAB = (B-A)
if should_actAB<=2:
    print(K+1)
    sys.exit()

else:
    ans_cookie=1
    K_=K-(A-1)
    print(K_)
    ans_cookie+=(A-1)
    print(ans_cookie)
    if K_%2==0:
        ans_cookie+=should_actAB*(K_)//2
    else:
        ans_cookie+=should_actAB*(K_-1)//2+1

Fixed, accepted submission:
K, A, B =map(int,input().split())
import sys
should_actAB = (B-A)
if should_actAB<=2:
    print(K+1)
    sys.exit()
 
else:
    ans_cookie=1
    K_=K-(A-1)
    ans_cookie+=(A-1)
    if K_%2==0:
        ans_cookie+=should_actAB*(K_)//2
    else:
        ans_cookie+=should_actAB*(K_-1)//2+1
print(ans_cookie)
Problem:
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.  Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.  Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)  At most how much can he earn on balance?  Note that the same string may be written on multiple cards.

Incorrect submission (verdict: Wrong Answer):
dic={}
for i in range(int(input())):
    s=input()
    if s in dic:
        dic[s]+=1
    else:
        dic[s]=1
for i in range(int(input())):
    s=input()
    if s in dic:
        dic[s]-=1
    else:
        dic[s]=-1
print(min(sorted(dic.values())[-1],0))


Fixed, accepted submission:
import sys
sys.setrecursionlimit(100000)
dic={}
for i in range(int(input())):
    s=input()
    try:
        dic[s]+=1
    except:
        dic[s]=1
for i in range(int(input())):
    s=input()
    try:
        dic[s]-=1
    except:
        dic[s]=-1

print(max(list(dic.values())+[0]))
Problem:
You have N items that you want to put them into a knapsack. Item i has value vi and weight wi.  You want to find a subset of items to put such that:    * The total value of the items is as large as possible.   * The items have combined weight at most W, that is capacity of the knapsack.  Find the maximum total value of items in the knapsack.

Incorrect submission (verdict: Wrong Answer):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n, max_w = [int(i) for i in input().split()]#print(n, max_w)

w = []
v = []
for j in range(n):
    weight,value=[int(i) for i in input().split()]
    w.append(weight)
    v.append(value)

dp = [[0 for i in range(max_w+1)] for j in range(n+1)]

for i in range(n):
    for cw in range(max_w+1):
        if cw >= w[i]:
            if cw == 8:
                print(i+1,cw,cw-w[i],i)
                print(dp[i+1][cw])
                print(dp[i][cw-w[i]])
                print(dp[i][cw])
            dp[i+1][cw] = max(dp[i][cw-w[i]]+v[i], dp[i][cw])
        else:
            dp[i+1][cw] = dp[i][cw]



Fixed, accepted submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n, max_w = [int(i) for i in input().split()]#print(n, max_w)

v = []
w = []
for j in range(n):
    value,weight=[int(i) for i in input().split()]
    v.append(value)
    w.append(weight)

dp = [[0 for i in range(max_w+1)] for j in range(n+1)]

for i in range(n):
    for cw in range(max_w+1):
        if cw >= w[i]:
            dp[i+1][cw] = max(dp[i][cw-w[i]]+v[i], dp[i][cw])
        else:
            dp[i+1][cw] = dp[i][cw]
print(dp[n][max_w])
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 = input()
N = int(N)
print(N%1000)

Fixed, accepted submission:
N = input()
N = int(N)
print(-N%1000)
Problem:
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.  The problem has N test cases.  For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.  See the Output section for the output format.

Incorrect submission (verdict: Wrong Answer):
from sys import stdin,stdout
import math
from collections import Counter,defaultdict
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()

def case():
    a=b=c=d=0
    for i in range(IN()):
        s=S()
        if s=="AC":a+=1
        elif s=="TLE":b+=1
        elif s=="WA":c+=1
        else:d+=1
    print("AC","x",a)
    print("AC","x",c)
    print("AC","x",b)
    print("AC","x",d)
for _ in range(1):
    case()
                


Fixed, accepted submission:
from sys import stdin,stdout
import math
from collections import Counter,defaultdict
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()

def case():
    a=b=c=d=0
    for i in range(IN()):
        s=S()
        if s=="AC":a+=1
        elif s=="TLE":b+=1
        elif s=="WA":c+=1
        else:d+=1
    print("AC","x",a)
    print("WA","x",c)
    print("TLE","x",b)
    print("RE","x",d)
for _ in range(1):
    case()
Problem:
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i.  Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
ans = pow(2, N // 2)
# 0*1 2*2 4*2 2^N/2*2
check = [0 for p in range(0, N // 2 + N % 2)]
for o in A:
    check[o // 2] += 1

for q in range(0, N // 2 + N % 2):
    if q == 0 & N % 2 == 1:
        if check[q] != 1:
            ans = 0
            break
    else:
        if check[q] != 2:
            ans = 0
            break
print(ans % (pow(10, 9) + 7))

Fixed, accepted submission:
N = int(input())
A = list(map(int, input().split()))
ans = pow(2, N // 2)
# 0*1 2*2 4*2 2^N/2*2
check = [0 for p in range(0, N // 2 + N % 2)]
for o in A:
    check[o // 2] += 1

for q in range(0, N // 2 + N % 2):
    if q == 0 and N % 2 == 1:
        if check[q] != 1:
            ans = 0
            break
    else:
        if check[q] != 2:
            ans = 0
            break
print(ans % (pow(10, 9) + 7))
Problem:
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.  Determine if we can visit all the towns by traversing each of the roads exactly once.

Incorrect submission (verdict: Wrong Answer):
li = []
for i in range(3):
  a,b = map(int,input().split())
  li.append(a)
  li.append(b)
li.sort()
if li==[1, 2, 2, 2, 3, 4]:
  print("YES")
else:
  print("NO")

Fixed, accepted submission:
li = []
for i in range(3):	
  a,b = map(int,input().split())
  li.append(a)
  li.append(b)
li.sort()
if li==[1, 2, 2, 3, 3, 4]:
  print("YES")
else:
  print("NO")
Problem:
Your task is to perform a simple table calculation.  Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.

Incorrect submission (verdict: Wrong Answer):
r, c = map(int, input().split())
for j in range(r):
    a = [int(i) for i in input().split()]
    for k in a:
        print('{} '.format(k),end='')

    print(sum(a))

Fixed, accepted submission:
r,c=map(int,input().split())
a=[]
for i in range(r):
    a+=[list(map(int,input().split()))]
    a[i].append(sum(a[i]))
for i in range(len(a)):
    print(" ".join(list(map(str,a[i]))))
b=[]
t=[]
d=0
for i in range(c+1):
    for j in range(r):
        b+=[a[j][i]]
    t+=[sum(b)] 
    b=[]
print(" ".join(list(map(str,t))))
Problem:
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion.  All strings that can be obtained in this way can be evaluated as formulas.  Evaluate all possible formulas, and print the sum of the results.

Incorrect submission (verdict: Wrong Answer):
s=input()
cnt=len(s)-1
for i in range(2**cnt):
    sum=s[0]
    for j in range(cnt):
        if ((i>>j)&1):
            sum+="+"
        else:
            sum+="-"
        sum+=s[j+1]
    print(eval(sum))
            

Fixed, accepted submission:
s=input()
cnt=len(s)-1
ans=0
for i in range(2**cnt):
    sum=s[0]
    for j in range(cnt):
        if ((i>>j)&1):
            sum+="+"
        else:
            pass
        sum+=s[j+1]
    ans+=eval(sum)
print(ans)