TnT/CodeNet4Repair huggingface dataset:
Problem:
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.  To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

Incorrect submission (verdict: Wrong Answer):
N = list(input().split())
flag = False
count_5 = 0
count_7 = 0
for n in N:
  a = int(n)
  if a == 5:
    count_5 = count_5 + 1
  elif a == 7:
    count_7 = count_7 + 1
  else:
    flag = True
    break
  if flag:
    break
if (count_5 == 2) and (count_7 == 1):
  print('Yes')
else:
  print('No')

Fixed, accepted submission:
N = list(input().split())
flag = False
count_5 = 0
count_7 = 0
for n in N:
  a = int(n)
  if a == 5:
    count_5 = count_5 + 1
  elif a == 7:
    count_7 = count_7 + 1
  else:
    flag = True
    break
  if flag:
    break
if (count_5 == 2) and (count_7 == 1):
  print('YES')
else:
  print('NO')
Problem:
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand.  How many grams of sand will the upper bulb contains after t seconds?

Incorrect submission (verdict: Wrong Answer):
X, t = map(int , input().split())
if t < X:
  r = 0
else:
  r = X-t

print(int(r))

Fixed, accepted submission:
X, t = map(int , input().split())
if t > X:
  r = 0
else:
  r = X-t
 
print(int(r))
Problem:
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.  He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.  To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.  How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Incorrect submission (verdict: Wrong Answer):
from bisect import bisect_right
from bisect import bisect_left
def main():
    n=int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))

    A.sort()
    C.sort()
    sum=0
    for i in range(n):
        cnt=1
        cnt*= bisect_left(A,B[i])
        cnt*= n-bisect_right(A,B[i])
        sum+=cnt 

    print(sum)

if __name__ == '__main__':
    main()

Fixed, accepted submission:
from bisect import bisect_right
from bisect import bisect_left
def main():
    n=int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))

    A.sort()
    C.sort()
    sum=0
    for i in range(n):
        cnt=1
        cnt*= bisect_left(A,B[i])
        cnt*= n-bisect_right(C,B[i])
        sum+=cnt 

    print(sum)

if __name__ == '__main__':
    main()
Problem:
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**.  You are given a 4-digit integer N. Answer the question: Is N **good**?

Incorrect submission (verdict: Wrong Answer):
n = input()
print('YES' if n[0]==n[1]==n[2] and n[1]==n[2]==n[3] else 'NO')

Fixed, accepted submission:
N = input()
print('Yes' if N[0]==N[1]==N[2] or N[1]==N[2]==N[3] else 'No')
Problem:
Write a program which reads three integers, and prints them in ascending order.

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

if a < b and b < c:
    print(a,b,c)
elif a < b and b > c:
    print(a,c,b)
elif a > b and a < c:
    print(b,a,c)
elif a > b and a > c:
    print(b,c,a)
elif c < a and a < b:
    print(c,a,b)
elif c < a and a > b:
    print(c,b,a)



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

if a <= b and b <= c:
    print(a,b,c,sep=' ')
elif a <= c and c <= b:
    print(a,c,b,sep=' ')
elif b <= a and a <= c:
    print(b,a,c,sep=' ')
elif b <= c and c <= a:
    print(b,c,a,sep=' ')
elif c <= a and a <= b:
    print(c,a,b,sep=' ')
elif c <= b and b <= a:
    print(c,b,a,sep=' ')
Problem:
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.  You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.  Find B_i for each i = 1, 2, ..., N.

Incorrect submission (verdict: Wrong Answer):
def medians(nums, n):
    median_left = nums[(n + 1)//2]
    median_right = nums[(n + 1)//2 - 1]
    return median_left, median_right


if __name__ == '__main__':
    n = int(input())
    nums = list(map(int, input().split()))
    median_left, median_right = medians(sorted(nums), n)
    for i in nums:
        print(median_left) if i <= median_left else print(median_right)


Fixed, accepted submission:
def medians(nums, n):
    median_left = nums[(n + 1)//2]
    median_right = nums[(n + 1)//2 - 1]
    return median_left, median_right


if __name__ == '__main__':
    n = int(input())
    nums = list(map(int, input().split()))
    median_left, median_right = medians(sorted(nums), n)
    for i in nums:
        print(median_left) if i < median_left else print(median_right)
Problem:
Snuke has N dogs and M monkeys. He wants them to line up in a row.  As a Japanese saying goes, these dogs and monkeys are on bad terms. _("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)_ Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.  How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.

Incorrect submission (verdict: Wrong Answer):
mod=1000000007
def kai(n):
    a=1
    for i in range(1,n+1):
        a*=i
        a%=mod
    return a%mod
n,m=map(int,input().split())
if abs(n-m)<=1:
    print(kai(n)*kai(m)%mod)
else:
    print(0)

Fixed, accepted submission:
mod=1000000007
def kai(n):
    a=1
    for i in range(1,n+1):
        a*=i
        a%=mod
    return a%mod
n,m=map(int,input().split())
if abs(n-m)==1:
    print(kai(n)*kai(m)%mod)
elif abs(n-m)==0:
    print(2*kai(n)*kai(m)%mod)
else:
    print(0)
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 = list(map(int, input().split()))
a = list(map(int, input().split()))


#     m = max(seq)
#     for idx,i in enumerate(seq):
#         if m==i:
#             return (idx, m)
#

# cnt = 0
# for _k in range(K):
#     remax
#

print(max(a)*2-sum(a)-1)


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


#     m = max(seq)
#     for idx,i in enumerate(seq):
#         if m==i:
#             return (idx, m)
#

# cnt = 0
# for _k in range(K):
#     remax
#

print(max(0,max(a)*2-sum(a)-1))
Problem:
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.  Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.  Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.

Incorrect submission (verdict: Wrong Answer):
a,b,c,d = map(int,input().split())
if a+b<c+d:
  print("Left")
elif a+b==c+d:
  print("Balanced")
else:
  print("Right")
  

Fixed, accepted submission:
a,b,c,d = map(int,input().split())
if a+b>c+d:
  print("Left")
elif a+b==c+d:
  print("Balanced")
else:
  print("Right")
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):
N = int(input())
s = [[0,0,0]]
for i in range(N):
    s.append(list(map(int,list(input().split()))))
err = 0
for i in range(N):
    dt = s[i+1][0] - s[i][0]
    dist = abs(s[i+1][1] - s[i][1]) + abs(s[i+1][2] - s[i][2])
    if(dt < dist):
        err = 1
    if(dist % 2 != dt % 2):
        err = 1

if(err == 0):
    print("YES")
else:
    print("NO")

Fixed, accepted submission:
N = int(input())
s = [[0,0,0]]
for i in range(N):
    s.append(list(map(int,list(input().split()))))
err = 0
for i in range(N):
    dt = s[i+1][0] - s[i][0]
    dist = abs(s[i+1][1] - s[i][1]) + abs(s[i+1][2] - s[i][2])
    if(dt < dist):
        err = 1
    if(dist % 2 != dt % 2):
        err = 1

if(err == 0):
    print("Yes")
else:
    print("No")
Problem:
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}.  Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.

Incorrect submission (verdict: Wrong Answer):
c1 = input()
c2 = input()

for i in range(0,len(c1)):
    if c1[i] != c2[-(i+1)]:
        print('NO')
        exit()
print('Yes')

Fixed, accepted submission:
a = input()
b = input()
print('YES' if a==b[::-1] else 'NO')
Problem:
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.  He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:    * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day.  In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**.    * Buy stock: Pay A_i yen and receive one stock.   * Sell stock: Sell one stock for A_i yen.  What is the maximum possible amount of money that M-kun can have in the end by trading optimally?

Incorrect submission (verdict: Wrong Answer):
from sys import stdin
input = stdin.readline

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

start = 0
money = 1000

for i in range(N - 1):
    if A[i + 1] > A[i]:
        tmp = 10 ** 3
        for k in range(i, start - 1, -1):
            tmp = min(A[k], tmp)
        print(A[i + 1], tmp)
        buy = money // tmp
        money -= tmp * buy
        money += buy * A[i + 1]
        start = i + 1

print(money)


Fixed, accepted submission:
from sys import stdin
input = stdin.readline

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

start = 0
money = 1000

for i in range(N - 1):
    if A[i + 1] > A[i]:
        buy = money // A[i]
        money -= A[i] * buy
        money += buy * A[i + 1]

print(money)
Problem:
You are given three integers, A, B and C.   Among them, two are the same, but the remaining one is different from the rest.   For example, when A=5,B=7,C=5, A and C are the same, but B is different.   Find the one that is different from the rest among the given three integers.

Incorrect submission (verdict: Wrong Answer):
a = [int(i) for i in input().split()]

for num1 in range(len(a)):
    c = 0
    for num2 in range(len(a)):
        if num1 == num2:
            c += 1
    if c == 1:
        print(num1)


Fixed, accepted submission:
a = [int(i) for i in input().split()]

for num1 in a:
    c = 0
    for num2 in a:
        if num1 == num2:
            c += 1
    if c == 1:
        print(num1)
Problem:
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.    An example of a trapezoid  Find the area of this trapezoid.

Incorrect submission (verdict: Wrong Answer):
a = int(input())
h = int(input())
b = int(input())
print((a+b)*h*0.5)

Fixed, accepted submission:
a = int(input())
b = int(input())
h = int(input())
print(int((a+b)*h*0.5))
Problem:
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

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

c_e = 0
c_w = 0

for s in S:
    if s == "E":
        c_e += 1
    elif s == "W":
        c_w += 1

print(min(c_e, c_w))

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

sum_W = [0] * (N+1)
sum_E = [0] * (N+1)

for i in range(N):
    if S[i] == "W":
        sum_W[i+1] = sum_W[i] + 1
        sum_E[i+1] = sum_E[i]
    else:
        sum_W[i+1] = sum_W[i]
        sum_E[i+1] = sum_E[i] + 1

answers = []
for i in range(N):
    answer = sum_W[i] + (sum_E[N] - sum_E[i+1])
    answers.append(answer)

print(min(answers))
Problem:
Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i.  Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows:    * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same).   * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y.  However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:    * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q).  What is the maximum possible happiness after M handshakes?

Incorrect submission (verdict: Wrong Answer):
import numpy as np

N,M = map(int,input().split())
A = np.sort(list(map(int,input().split())))
ans = 0

xOK = A[0]*2
xNG = A[-1]*2 + 1
nx = 0
while xOK+1 < xNG:
    x = (xOK + xNG)//2
    nx = 0
    for a in A:
        print("np.searchsorted(A,x-a)=",np.searchsorted(A,x-a))
        nx += N-(np.searchsorted(A,x-a))
        if nx >= M:
            xOK = x
            break
    else:
        xNG = x

from itertools import accumulate
S=[0]+list(accumulate(A))

ans = 0
nnx = 0        
for a in A:
    nx = np.searchsorted(A,xOK-a,side='right')
    ans += a*(N-nx) + (S[N]-S[nx])
    nnx += (N-nx)
ans += xOK*(M-nnx)
        
    
print(ans)

Fixed, accepted submission:
import bisect 
from itertools import accumulate

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
ans = 0

xOK = A[0]*2
xNG = A[-1]*2 + 1
nx = 0
while xOK+1 < xNG:
    x = (xOK + xNG)//2
    nx = 0
    for a in A:
        nx += N-(bisect.bisect_left(A,x-a))
        if nx >= M:
            xOK = x
            break
    else:
        xNG = x

S=[0]+list(accumulate(A))

ans = 0
nnx = 0        
for a in A:
    nx = bisect.bisect_right(A,xOK-a)
    ans += a*(N-nx) + (S[N]-S[nx])
    nnx += (N-nx)
ans += xOK*(M-nnx)
        
    
print(ans)
Problem:
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately.  He has very high awareness of safety, and decides to buy two bells, one for each hand.  The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.

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

print(a + b + c - min(a, b, c))


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

print(a + b + c - max(a, b, c))
Problem:
We have an N \times N square grid.  We will paint each square in the grid either black or white.  If we paint exactly A squares white, how many squares will be painted black?

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

Fixed, accepted submission:
n=int(input())
a=int(input())
print(n**2-a)
Problem:
You are playing the following game with Joisino.    * Initially, you have a blank sheet of paper.   * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.   * Then, you are asked a question: How many numbers are written on the sheet now?  The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?

Incorrect submission (verdict: Wrong Answer):
def c(s):
    n = input()
    if n in s:
        s.remove(n)
    else:
        s.add(n)

def main():
    n = int(input())
    s = set()

    for i in range(n):
        c(s)

    return print(s)


if __name__ == '__main__':
    main()


Fixed, accepted submission:
from typing import List


def main():
    n = int(input())
    nums = [input() for _ in range(n)]
    print(wae(n, nums))


def wae(n: int, nums: List[str]) -> int:
    s = set()

    for i in range(n):
        num = nums[i]
        if num in s:
            s.remove(num)
        else:
            s.add(num)

    return len(s)


if __name__ == '__main__':
    main()
Problem:
You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Incorrect submission (verdict: Wrong Answer):
s=input()
k=int(input())
word=[]
for i in range(len(s)):word.append(s[i:])
word=sorted(word)
for i in word:
    if len(i)>=k:
        print(i[:k])
        exit()
    else:
        k -=len(i)

Fixed, accepted submission:
s=input()
k=int(input())

words=[]
for i in range(len(s)):words.append(s[i:])
words.sort()

record=[]
for i in words:
    for j in range(len(i)):
        word="".join(i[:j+1])
        if word not in record:
            record.append(word)
    if len(record)>=k:
        print(record[k-1]);exit()
Problem:
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?

Incorrect submission (verdict: Wrong Answer):
n=int(input())
print(int(n*n+1/2))

Fixed, accepted submission:
n=int(input())
print(int((n**2+n)/2))
Problem:
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.

Incorrect submission (verdict: Wrong Answer):
def test():
    s = input()
    if "a" in s and "b" in s and "c" in s:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    test()


Fixed, accepted submission:
def test():
    s = set(input())
    if len(s) == 3:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    test()
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):
n = int(input())
home = [[0 for i in range(20)] for j in range(15)]  
for i in range(n) :
  b, f, r, v = map(int, input().split())
  h = (b - 1) * 4 + f - 1
  w = r * 2 - 1
  s = v
  home[h][w] += s
for y in range(15) :
  for x in range(20) :
    if(y % 4 == 3) :
      home[y][x] = "#"
    elif(x % 2 == 0) :
      home[y][x] == " "
    print(home[y][x], end = "")
  print() 
      
  


Fixed, accepted submission:
n = int(input())
home = [[0 for i in range(20)] for j in range(15)]  
for i in range(n) :
  b, f, r, v = map(int, input().split())
  h = (b - 1) * 4 + f - 1
  w = r * 2 - 1
  s = v
  home[h][w] += s
for y in range(15) :
  for x in range(20) :
    if(y % 4 == 3) :
      home[y][x] = "#"
    elif(x % 2 == 0) :
      home[y][x] = " "
    print(home[y][x], end = "")
  print()
Problem:
Mammy decided to give Taro his first shopping experience. Mammy tells him to choose any two items he wants from those listed in the shopping catalogue, but Taro cannot decide which two, as all the items look attractive. Thus he plans to buy the pair of two items with the highest price sum, not exceeding the amount Mammy allows. As getting two of the same item is boring, he wants two different items.  You are asked to help Taro select the two items. The price list for all of the items is given. Among pairs of two items in the list, find the pair with the highest price sum not exceeding the allowed amount, and report the sum. Taro is buying two items, not one, nor three, nor more. Note that, two or more items in the list may be priced equally.

Incorrect submission (verdict: Wrong Answer):
n,m=map(int,input().split())
a=[0]*n
a=list(input().split())
for i in range(n):
    a[i]=int(a[i])
max=0
for i in range(n):
    for j in range(n):
        if i<j:
            tmp=a[i]+a[j]
            if tmp>max and tmp<=m:
                max=tmp
            else: pass
        else: pass
if max==0:
    print("NONE")
else:
    print(max)
            



Fixed, accepted submission:
ans=[]
n,m=map(int,input().split())
while n!=0 and m!=0:
    a=[0]*n
    a=list(input().split())
    for i in range(n):
        a[i]=int(a[i])
    max=0
    for i in range(n):
        for j in range(n):
            if i<j:
                tmp=a[i]+a[j]
                if tmp>max and tmp<=m:
                    max=tmp
                else: pass
            else: pass
    ans.append(max)
    n,m=map(int,input().split())
for i in range(len(ans)):
    if ans[i]==0:
        print("NONE")
    else:
        print(ans[i])