TnT/CodeNet4Repair huggingface dataset:
Problem:
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once.  Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.

Incorrect submission (verdict: Wrong Answer):
s=input()
ans='No'
for i in range(1,len(s)):
  for j in range(i,len(s)):
    if s[:i]+s[j:]=='keyence':
      ans='Yes'
      break
print(ans)

Fixed, accepted submission:
s=input()
ans='NO'
for i in range(1,len(s)):
  for j in range(i,len(s)):
    if s[:i]+s[j:]=='keyence':
      ans='YES'
      break
print(ans)
Problem:
There are N positive integers written on a blackboard: A_1, ..., A_N.  Snuke can perform the following operation when all integers on the blackboard are even:    * Replace each integer X on the blackboard by X divided by 2.  Find the maximum possible number of operations that Snuke can perform.

Incorrect submission (verdict: Time Limit Exceeded):
n = input()
a = list(map(int, input().split()))

count = 0
odd = ""

while True:
    for i, n in enumerate(a):
        if n % 2 == 0:
            a[i] == n / 2
            count += 1
        else:
            odd = "finish"
            break
    if odd == "finish":
        break
print(count)


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

ans = a[0]
for i in range(int(n)):
    count = 0
    while(a[i] % 2 == 0):
        a[i] /= 2
        count += 1
    ans = min(ans, count)
print(ans)
Problem:
There are N positive integers written on a blackboard: A_1, ..., A_N.  Snuke can perform the following operation when all integers on the blackboard are even:    * Replace each integer X on the blackboard by X divided by 2.  Find the maximum possible number of operations that Snuke can perform.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
flag = True
ans = 0
while(1):
    for i in range(N):
        if A[i] % 2 != 0:
            flag = False
            break
    if flag:
        A = list(map(lambda x:x/2, A))
    else:
        break

print(ans)



Fixed, accepted submission:
N = int(input())
A = list(map(int, input().split()))
flag = True
ans = 0
while(1):
    for i in range(N):
        if A[i] % 2 != 0:
            flag = False
            break
    if flag:
        A = list(map(lambda x:x/2, A))
        ans += 1
    else:
        break

print(ans)
Problem:
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode:                 BubbleSort(A) 1 for i = 0 to A.length-1 2     for j = A.length-1 downto i+1 3         if A[j] < A[j-1] 4             swap A[j] and A[j-1]   Note that, indices for array elements are based on 0-origin.  Your program should also print the number of swap operations defined in line 4 of the pseudocode.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
n = N
while n > 0:
    for i in range(N-1, 0, -1):
        if A[i] < A[i-1]:
            t = A[i]
            A[i] = A[i-1]
            A[i-1] = t
    n -= 1
print(A)

Fixed, accepted submission:
N = int(input())
A = [int(n) for n in input().split()]
flg = 1
cnt = 0
while flg:
    flg = 0
    for i in range(N-1, 0, -1):
        if A[i] < A[i-1]:
            t = A[i]
            A[i] = A[i-1]
            A[i-1] = t
            flg = 1
            cnt += 1
for i in range(N):
    if i == N - 1:
        print(A[i])
    else:
        print(A[i], end=" ")
print(cnt)
Problem:
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.

Incorrect submission (verdict: Wrong Answer):
a,b,c = input().split()
print(a[0]+b[0]+c[0])



Fixed, accepted submission:
a,b,c = input().split()
a_d=a.capitalize()
b_d=b.capitalize()
c_d=c.capitalize()
print(a_d[0]+b_d[0]+c_d[0])
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 or b < c < a:
    print('yes')
else:
    print('no')

Fixed, accepted submission:
A,B,C = map(int, input().split())
 
if A < C and C < B:
    print('Yes')
elif A > C and C > B:
    print('Yes')
else:
    print('No')
Problem:
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.  In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.  When activated, each type of robot will operate as follows.    * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.    * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.  Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

Incorrect submission (verdict: Wrong Answer):
import sys

lines = sys.stdin.readlines()

N = int(lines[0])
K = int(lines[1])
X = lines[2].split(' ')
x =[]

y = 0
for i in range(N):
  x.append(int(X[i]))
  if 2*x[i] >= K:
      dist = K-x[i]
  else:
      dist = x[i]
  y = y + dist

print(y)

Fixed, accepted submission:
import sys

lines = sys.stdin.readlines()

N = int(lines[0])
K = int(lines[1])
X = lines[2].split(' ')
x =[]

y = 0
for i in range(N):
  x.append(int(X[i]))
  if 2*x[i] >= K:
      dist = 2*(K-x[i])
  else:
      dist = 2*x[i]
  y = y + dist

print(y)
Problem:
In the first line, two integers $n$ and $k$ are given separated by a space character. In the following $n$ lines, $w_i$ are given respectively.

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


import sys
import math


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        product_num = int(self.__input[0].split()[0])
        truck_num = int(self.__input[0].split()[1])

        weight_list = list(map(int, self.__input[1:]))

        assert product_num == len(weight_list)
        print(product_num, truck_num, weight_list)

        truck_capacity = max(math.ceil(sum(weight_list) / truck_num), max(weight_list))

        return str(truck_capacity)

        #     for each in array_2:
        #         if self.allocation(key=each, array=weight_list, array_length=max(weight_list)):
        #             truck_capacity += 1
        #
        #     return str(truck_capacity)
        #
        # @staticmethod
        # def allocation(key, array, array_length):
        #     # print(len(set(array_1).intersection(set(array_2))))
        #     left, right = max(array), array_length
        #     while left < right:
        #         mid = (left + right) // 2
        #         if key == array[mid]:
        #             return True
        #         elif key < array[mid]:
        #             right = mid
        #         else:
        #             left = mid + 1
        #     return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

Fixed, accepted submission:
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        product_num = int(self.__input[0].split()[0])
        truck_num = int(self.__input[0].split()[1])
        weight_list = list(map(int, self.__input[1:]))

        

        # binary search
        left, right, mid = max(weight_list), sum(weight_list), 0
        while left < right:
            mid = (left + right) // 2
            # check return True : p could be smaller
            if self.check(max_load_cursor=mid, weight_list=weight_list, truck_num=truck_num):
                right = mid
            else:
                mid += 1
                left = mid
        return str(mid)

    @staticmethod
    def check(max_load_cursor, weight_list, truck_num):
        track_count = 1
        current_load = 0
        for item_weight in weight_list:
            current_load += item_weight
            # change to next truck
            if current_load > max_load_cursor:
                current_load = item_weight
                track_count += 1
                if track_count > truck_num:
                    return False
        return True


if __name__ == '__main__':
    case = Solution()
    print(case.solution)
Problem:
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.  The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.  Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.  Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a = [0] * n
for i in range(n):
    a.append(int(input()))
count = 0
num = 0

for i in range(n):
    num = a[num]
    count += 1
    if num == 2:
        break

if num != 2:
    count = -1

print(count)


Fixed, accepted submission:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
count = 0
num = 1

for i in range(n):
    num = a[num - 1]
    count += 1
    if num == 2:
        break

if num != 2:
    count = -1

print(count)
Problem:
Snuke has a favorite restaurant.  The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.  So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
can=n*800
p=n
des=200
if n>=15 and n<30:
  total=can-200
elif n>=30 and n<45:
  total=can-400
elif n>=45 and n<60:
  total=can-600
elif n>=60 and n<75:
  total=can-800
elif n>=75 and n<90:
  total=can-1000
elif n>=90 and n<=100:
  total=can-1200


Fixed, accepted submission:
from sys import stdin, stdout


def main() -> None:
    line = int(stdin.readline())
    x = line * 800
    tmp = line / 15
    y = int(tmp) * 200
    rta = x - y
    print(rta)


main()
Problem:
Write a program which computes the area of a shape represented by the following three lines:      $y = x^2$   $y = 0$   $x = 600$       It is clear that the area is $72000000$, if you use an integral you learn in high school. On the other hand, we can obtain an approximative area of the shape by adding up areas of many rectangles in the shape as shown in the following figure:     $f(x) = x^2$       The approximative area $s$ where the width of the rectangles is $d$ is:      area of rectangle where its width is $d$ and height is $f(d)$ $+$   area of rectangle where its width is $d$ and height is $f(2d)$ $+$   area of rectangle where its width is $d$ and height is $f(3d)$ $+$   ...   area of rectangle where its width is $d$ and height is $f(600 - d)$    The more we decrease $d$, the higer-precision value which is close to $72000000$ we could obtain. Your program should read the integer $d$ which is a divisor of $600$, and print the area $s$.

Incorrect submission (verdict: Wrong Answer):
def integral(d):
    print("d=%d" % d)
    n = 600//d
    print("n=%d" % n)
    
    s = 0.0
    for i in range(n):
        s += (d*i)**2
    return(s*d)

if __name__ == '__main__':
    while True:
        try:      
            d = int(input())
            print(int(integral(d)))
        except:
            break

Fixed, accepted submission:
def integral(d):
    n = 600//d
    s = 0.0
    for i in range(n):
        s += (d*i)**2
    return(s*d)

if __name__ == '__main__':
    while True:
        try:      
            d = int(input())
            print(int(integral(d)))
        except:
            break
Problem:
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i.  Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action:    * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn.  The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand.  X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?

Incorrect submission (verdict: Wrong Answer):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,z,w = na()
a = na()

print(max(abs(a[-1]-w),abs(z-w)))

Fixed, accepted submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,z,w = na()
a = na()

if n == 1:
    print(abs(a[-1]-w))
    exit()

print(max(abs(a[-1]-w),abs(a[-2]-a[-1])))
Problem:
You start with the number 0 and you want to reach the number N.  You can change the number, paying a certain amount of coins, with the following operations:    * Multiply the number by 2, paying A coins.   * Multiply the number by 3, paying B coins.   * Multiply the number by 5, paying C coins.   * Increase or decrease the number by 1, paying D coins.  You can perform these operations in arbitrary order and an arbitrary number of times.  What is the minimum number of coins you need to reach N?  **You have to solve T testcases.**

Incorrect submission (verdict: Wrong Answer):
import sys
import heapq
from collections import deque
T=int(input())
for t in range(T):
    N,A,B,C,D= map(int,input().split())
    q = [(0,N)]
    
    heapq.heapify(q)
    
    seen=set()
    while q:
        cost,n = heapq.heappop(q)
        if n in seen:
            continue
        
        seen.add(n)
        if n==0:
            print(cost)
            break

        heapq.heappush(q,(cost+n*D,0))
        if n%2==0:
            heapq.heappush(q,(cost+A,n//2))
        else:
            heapq.heappush(q,(cost+D+A,(n+1)//2))
            heapq.heappush(q,(cost+D+A,(n-1)//2))

        if n%3==0:
            heapq.heappush(q,(cost+C,n//3))
        else:
            rest=n % 3
            heapq.heappush(q,(cost+rest*D+B,(n-rest+3)//3))
            heapq.heappush(q,(cost+(3-rest)*D+B,(n-rest+3)//3))

        if n % 5 ==0:
            heapq.heappush(q,(cost+C,n//5))
        else:
            rest=  n%5
            heapq.heappush(q,(cost+rest*D+C,(n-rest)//5))
            heapq.heappush(q,(cost+(5-rest)*D+C,(n-rest+5)//5))


Fixed, accepted submission:
import sys
import heapq
T = int(input())
from collections import deque
for t in range(T):
  N,A,B,C,D = map(int,input().split())
  q = [(0, N)]
  heapq.heapify(q)
  seen = set()
  while q:
    cost,n = heapq.heappop(q)
    if n in seen:
      continue
    seen.add(n)
    if n == 0:
      print(cost)
      break

    heapq.heappush(q, (cost + n * D, 0))
    if n % 2 == 0:
      heapq.heappush(q, (cost + A, n // 2))
    else:
      heapq.heappush(q, (cost + D + A, (n + 1) // 2))
      heapq.heappush(q, (cost + D + A, (n - 1) // 2))

    if n % 3 == 0:
      heapq.heappush(q, (cost + B, n // 3))
    else:
      rest = n % 3
      heapq.heappush(q, (cost + rest * D + B, (n - rest) // 3))
      heapq.heappush(q, (cost + (3 - rest) * D + B, (n - rest + 3) // 3))

    if n % 5 == 0:
      heapq.heappush(q, (cost + C, n // 5))
    else:
      rest = n % 5
      heapq.heappush(q, (cost + rest * D + C, (n - rest) // 5))
      heapq.heappush(q, (cost + (5 - rest) * D + C, (n - rest + 5) // 5))
Problem:
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.

Incorrect submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

INPUT=int(input())
b=1
p=2
END=0
while True:
    while True:
        now_num = b**p
        if b == 1:
            end_num=now_num
            break
        elif p==2 and INPUT<now_num:
            END = 1
            break
        elif INPUT < now_num:
            end_num = b**(p-1)
            break
        else:
            p+=1
        
    if END == 1:
        ans=end_num
        break
    b+=1
    
print(ans)

Fixed, accepted submission:
from math import sqrt
X=int(input())
sqrt_X=int(sqrt(X))
ans=1

for b in range(1,sqrt_X + 1):
    
    for p in range(2,sqrt_X+1):
        now_num = b**p
        if now_num <= X and ans <= now_num:
            ans =now_num
print(ans)
Problem:
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N).  For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.  We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:    * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.  Does there exist a good set of choices? If the answer is yes, find one good set of choices.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
res = [0 for i in range(n)]
for i in range(n,n//2,-1):
    res[i-1] = a[i-1]

for i in range(n//2,0,-1):
    l = []
    flag = 0
    t = i*2
    while t <= n:
        flag = flag ^ res[t-1]
        t = t+i
    if a[i-1] != flag:
        res[i-1] = 1

if res == [0 for i in range(n)]:
    print(0)
else:
    lres = []
    for i in range(n):
        if res[i] == 1:
            lres.append(str(i+1))
    print(" ".join(lres))
 

Fixed, accepted submission:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    res = [0 for i in range(n)]
    lres = []
    for i in range(n,0,-1):
        flag = 0
        t = i*2
        while t <= n:
            flag = flag ^ res[t-1]
            t = t+i
        if a[i-1] != flag:
            res[i-1] = 1
            lres.append(str(i))

    print(len(lres))
    if len(lres) != 0:
        print(" ".join(lres))

main()
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):
x = input()
#print(x)
y = [int(c) for c in x]
#print(y)
a = y[0]
b = y[1]
c = y[2]
d = y[3]
if a+b+c+d == 7:
  print("a+b+c+d=",a+b+c+d,sep='')
  exit()
if a+b+c-d == 7:
  print("a+b+c-d=",a+b+c-d,sep='')
  exit()
if a+b-c+d == 7:
  print("a+b-c+d=",a+b-c+d,sep='')
  exit()
if a-b+c+d == 7:
  print("a-b+c+d=",a-b+c+d,sep='')
  exit()
if a-b-c+d == 7:
  print("a-b-c+d=",a-b-c+d,sep='')
  exit()
if a-b+c-d == 7:
  print("a-b+c-d=",a-b+c-d,sep='')
  exit()
if a-b-c-d == 7:
  print("a-b-c-d=",a-b-c-d,sep='')
  exit()
if a+b-c-d == 7:
  print("a+b-c-d=",a+b-c-d,sep='')
  exit()

Fixed, accepted submission:
x = input()
#print(x)
y = [int(c) for c in x]
#print(y)
a = y[0]
b = y[1]
c = y[2]
d = y[3]
if a+b+c+d == 7:
  print(a,"+",b,"+",c,"+",d,"=",a+b+c+d, sep='')
  exit()
if a+b+c-d == 7:
  print(a,"+",b,"+",c,"-",d,"=",a+b+c-d, sep='')
  exit()
if a+b-c+d == 7:
  print(a,"+",b,"-",c,"+",d,"=",a+b-c+d, sep='')
  exit()
if a-b+c+d == 7:
  print(a,"-",b,"+",c,"+",d,"=",a-b+c+d, sep='')
  exit()
if a-b-c+d == 7:
  print(a,"-",b,"-",c,"+",d,"=",a-b-c+d, sep='')
  exit()
if a-b+c-d == 7:
  print(a,"-",b,"+",c,"-",d,"=",a-b+c-d, sep='')
  exit()
if a-b-c-d == 7:
  print(a,"-",b,"-",c,"-",d,"=",a-b-c-d, sep='')
  exit()
if a+b-c-d == 7:
  print(a,"+",b,"-",c,"-",d,"=",a+b-c-d, sep='')
  exit()
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 as ct
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
count=ct(A)
div=len(count)
if div<=K:print(0)
else:print(sum([i[0] for i in sorted(count.items(),key= lambda x:x[1])[:div-K]]))
        

Fixed, accepted submission:
from collections import Counter as ct
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
count=ct(A)
div=len(count)
if div<=K:print(0)
else:print(sum([i[1] for i in sorted(count.items(),key= lambda x:x[1])[:div-K]]))
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())

aa = list(range(a,min(a+k,b)))
bb = list(range(max(b-k+1,a),b+1))
aa.extend(bb)
c = set(aa)
d = list(c)
for i in range(len(d)):
    print(d[i])

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

aa = list(range(a,min(a+k,b)))
bb = list(range(max(b-k+1,a),b+1))
aa.extend(bb)
c = set(aa)
d = list(c)
d = sorted(d)
for i in range(len(d)):
    print(d[i])