TnT/CodeNet4Repair huggingface dataset:
Problem:
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not.  You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.

Incorrect submission (verdict: Wrong Answer):
A = list(input())

while A:
    count = 0
    length = len(A)
    half = length // 2
    for i in range(half):
        if A[i] == A[half + i]:
            count += 1
        if i == half - 1: break
        
    if count != 0: break
    
    A = A[:-2]
    
print(count)

Fixed, accepted submission:
A = list(input())

count = 0
while A:
    A = A[:-2]
    lenght = len(A) // 2
    if A[lenght:] == A[:lenght]:
        count = lenght * 2
        break

print(count)
Problem:
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters.  Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation:    * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter.  What is the minimum number of operations required to achieve the objective?

Incorrect submission (verdict: Wrong Answer):
# -*- coding: utf-8 -*-
 
import sys
import math

n = int(input())

s = []

for i in range(3):
    s.append(input())

num = []
for i in range(3):
    num2 = []
    for j in range(3):
        max_n = 0
        if i != j:
            for k in range(len(s[0])):
                if s[i][k] != s[j][k]:
                    max_n += 1
        num2.append(max_n)
    num.append(num2)
#print(num)


print(min([sum(u) for u in num]))

Fixed, accepted submission:
# -*- coding: utf-8 -*-
 
import sys
import math

n = int(input())

s = []

for i in range(3):
    s.append(input())

num = 0
for i in range(n):
    if s[0][i] == s[1][i] == s[2][i]:
        num = num
    elif s[0][i] == s[1][i]:
        num += 1
    elif s[0][i] == s[2][i]:
        num += 1
    elif s[1][i] == s[2][i]:
        num += 1
    else:
        num += 2


print(num)
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):
A, B, C, D = list(input())

op = ['+', '-']

for i in range(7):
    formula = A + op[(i >> 0) & 1] + B + op[(i >> 1) & 1] + C + op[(i >> 2) & 1] + D
    if eval(formula) == 7:
        print(formula)
        break

Fixed, accepted submission:
A, B, C, D = list(input())

op = ['+', '-']

for i in range(7):
    formula = A + op[(i >> 0) & 1] + B + op[(i >> 1) & 1] + C + op[(i >> 2) & 1] + D
    if eval(formula) == 7:
        print(formula + '=7')
        break
Problem:
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`.  After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.

Incorrect submission (verdict: Wrong Answer):
S = input()   #2017/01/07

S = S.replace(S[3], "8")
print(S)


Fixed, accepted submission:
S = input()

S = S.replace(S[3], "8", 1)
print(S)
Problem:
M-kun is a student in Aoki High School, where a year is divided into N terms.   There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:    * For the first through (K-1)-th terms: not given.   * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.  M-kun scored A_i in the exam at the end of the i-th term.   For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.

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

for i in range (0, N-K):
    if A[i] < A[K]:
        print('Yes')
    else:
        print('No')

Fixed, accepted submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range (0, N-K):
    if A[i] < A[K+i]:
        print('Yes')
    else:
        print('No')
Problem:
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.  We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person.  At most how many people can sit on the seat?

Incorrect submission (verdict: Wrong Answer):
x , y, z = map(int, input().split())

a = x // (y+z)
if x - y*a < y:
    print(a)
else:
    print(a+1)

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

print((a - c)// (b + c))
Problem:
Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into its position in the output array B. This scheme must be modified to handle the situation in which several elements have the same value. Please see the following pseudocode for the detail:                 Counting-Sort(A, B, k) 1    for i = 0 to k 2        do C[i] = 0 3    for j = 1 to length[A] 4        do C[A[j]] = C[A[j]]+1 5    /* C[i] now contains the number of elements equal to i */ 6    for i = 1 to k 7    do C[i] = C[i] + C[i-1] 8    /* C[i] now contains the number of elements less than or equal to i */ 9    for j = length[A] downto 1 10       do B[C[A[j]]] = A[j] 11          C[A[j]] = C[A[j]]-1   Write a program which sorts elements of given array ascending order based on the counting sort.

Incorrect submission (verdict: Wrong Answer):
def counting_sort(A, k):
    B = [0] * len(A)
    C = [0] * k

    for a in A:
        C[a] += 1

    for i in range(1, k):
        C[i] += C[i - 1]

    for a in reversed(A):
        print(a, C[a])
        B[C[a] - 1] = a
        C[a] -= 1

    return B


def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    print(*counting_sort(A, 11))


main()


Fixed, accepted submission:
def counting_sort(A, k):
    B = [0] * len(A)
    C = [0] * k

    for a in A:
        C[a] += 1

    for i in range(1, k):
        C[i] += C[i - 1]

    for a in A:
        B[C[a] - 1] = a
        C[a] -= 1

    return B


def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    print(*counting_sort(A, 10001))


main()
Problem:
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?

Incorrect submission (verdict: Wrong Answer):
a = int(input())
ans = 48 - a
print(a)

Fixed, accepted submission:
a = int(input())
ans = 48 - a
print(ans)
Problem:
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N.  There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i.  Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.  Help him.

Incorrect submission (verdict: Wrong Answer):
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

if m == 1:
  print("IMPOSSIBLE")

else:
  root = [[] for i in range(n)]
  for a, b in ab:
    root[a-1].append(b-1)
  
  print(root)
  flag = False
  for i in range(len(root)):
    for j in root[i]:
      if n-1 in root[j]:
        flag = True
        break

  print("POSSIBLE" if flag else "IMPOSSIBLE")
        
    
    

Fixed, accepted submission:
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

if m == 1:
  print("IMPOSSIBLE")

else:
  root = [[] for i in range(n)]
  for a, b in ab:
    root[a-1].append(b-1)
  
  flag = False
  for j in root[0]:
    if n-1 in root[j]:
      flag = True
      break

  print("POSSIBLE" if flag else "IMPOSSIBLE")
Problem:
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right.  Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N.  Find the minimum cost incurred before reaching the goal.

Incorrect submission (verdict: Wrong Answer):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
c = [0 for i in range(N+1)]
for a in A:
  c[a] = 1
ans = sum(A[:X+1])
print(min(ans, M-ans))

Fixed, accepted submission:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
c = [0 for i in range(N+1)]
for a in A:
  c[a] = 1
ans = sum(c[:X+1])
print(min(ans, M-ans))
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):
a=int(input())
print(a*800-(a%15)*200)

Fixed, accepted submission:
a=int(input())
print(a*800-(a//15)*200)
Problem:
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.

Incorrect submission (verdict: Wrong Answer):
s = input()
a,b = list(map(lambda x: int(x), s.split(" ")))
print(a)
print(b)
if a % 2 == 0 or b % 2 == 0:
    print("Even")
else:
    print("Odd")



Fixed, accepted submission:
s = input()
a,b = list(map(lambda x: int(x), s.split(" ")))
if a % 2 == 0 or b % 2 == 0:
    print("Even")
else:
    print("Odd")
Problem:
There is a string s of length 3 or greater. No two neighboring characters in s are equal.  Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first:    * Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s.  The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.

Incorrect submission (verdict: Wrong Answer):
s=input()
N=len(s)
if s[0]==s[1]:
  if N%2:
    print('Second')
  else:
    print('First')
else:
  if N%2:
    print('First')
  else:
    print('Second')

Fixed, accepted submission:
s=input()
N=len(s)
if s[0]==s[-1]:
  if N%2:
    print('Second')
  else:
    print('First')
else:
  if N%2:
    print('First')
  else:
    print('Second')
Problem:
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.  Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:    * Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.  For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.    Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.

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

n = (x - 1) // 11 * 2
p = 2 if (x - 1) % 11 > 7 else 1

print(n + p)

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

n = (x - 1) // 11 * 2
p = 2 if (x - 1) % 11 > 5 else 1

print(n + p)
Problem:
Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.

Incorrect submission (verdict: Wrong Answer):
from queue import Queue

n = int(input())
A = [[0 for i in range(n)] for j in range(n)]
d = [0 for i in range(n)]

for i in range(n):
    u, k, *v = list(map(int, input().split()))
    for j in v:
        A[int(u)-1][int(j)-1] = 1

q = Queue()
q.put(0)
d[0] = 0

while not q.empty():
    u = q.get()
    # print('visited:', u)
    for v in range(n):
        # print(u, v)
        if A[u][v] == 1 and d[v] == 0:
            q.put(v)
            d[v] = d[u] + 1

# print('-========')
for i in range(n):
    print(i, d[i])


Fixed, accepted submission:
from queue import Queue

n = int(input())
A = [[0 for i in range(n)] for j in range(n)]
d = [-1] * n

for i in range(n):
    u, k, *v = list(map(int, input().split()))
    for j in v:
        A[int(u)-1][int(j)-1] = 1

q = Queue()
q.put(0)
d[0] = 0

while not q.empty():

    u = q.get()

    for v in range(n):

        if A[u][v] == 1 and d[v] == -1:
            q.put(v)
            d[v] = d[u] + 1

for i in range(n):
    print(i+1, d[i])
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):
s = list(map(int, input().split()))
s.sort()
print(s)
if s[0] == 5 and s[1] == 5 and s[2] == 7:
    print("YES")
else:
    print("NO")

Fixed, accepted submission:
s = list(map(int, input().split()))
if s.count(5) == 2 and s.count(7):
    print("YES")
else:
    print("NO")
Problem:
Joisino is planning to open a shop in a shopping street.  Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.  There are already N stores in the street, numbered 1 through N.  You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.  Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.  Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]


print(N,F,P)

ans = -(10**9+7)
for i in range(1, 2**10):
  tmp = 0
  for f, p in zip(F, P):
    tmp += p[bin(f&i).count('1')]
    #print(f,i,p[bin(f&i).count('1')])
  ans = max(ans, tmp)
print(ans)


Fixed, accepted submission:
N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]

#print(N,F,P)

ans = -(10**9+7)
for i in range(1, 2**10):
  tmp = 0
  for f, p in zip(F, P):
    tmp += p[bin(f&i).count('1')]
    #print(f,i,p[bin(f&i).count('1')])
  ans = max(ans, tmp)
print(ans)
Problem:
There are N people numbered 1 to N. Each person wears a red hat or a blue hat.  You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`.  Determine if there are more people wearing a red hat than people wearing a blue hat.

Incorrect submission (verdict: Wrong Answer):
print('YNeos'[int(input())/2<input().count('R')::2])

Fixed, accepted submission:
print('YNeos'[int(input())/2>=input().count('R')::2])
Problem:
Takahashi is organizing a party.  At the party, each guest will receive one or more snack pieces.  Takahashi predicts that the number of guests at this party will be A or B.  Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.  We assume that a piece cannot be divided and distributed to multiple guests.

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

large = A if A > B else B
small = A if A < B else B

multi = small

reminder = large % small
while reminder != 0:
    multi = reminder
    reminder = small % reminder

cross = large/multi

print(cross*small)


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

large = A if A > B else B
small = A if A < B else B

def gcd(large, small):
    r = large % small
    while r != 0:
        large = small
        small = r
        r = large % small
    return small

print(large*small//gcd(large, small))
Problem:
AtCoDeer has three cards, one red, one green and one blue.   An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.   We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.   Is this integer a multiple of 4?

Incorrect submission (verdict: Wrong Answer):
r, g, b = map(int, input().split())
if (100*r+10*b+g)%4 == 0 : print('YES')
else : print('NO')


Fixed, accepted submission:
r, g, b = map(int, input().split())
if (100*r+10*g+b)%4 == 0 : print('YES')
else : print('NO')
Problem:
Snuke has N sticks. The length of the i-th stick is l_i.  Snuke is making a snake toy by joining K of the sticks together.  The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.

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

print(sum(sorted(l)[-K-1:]))

Fixed, accepted submission:
N, K= list(map(int, input().split())) 
l = list(map(int, input().split()))

print(sum(sorted(l)[-K:]))
Problem:
A 3×3 grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top right corner to the bottom left corner), all add up to the same sum.  You are given the integers written in the following three squares in a magic square:    * The integer A at the upper row and left column   * The integer B at the upper row and middle column   * The integer C at the middle row and middle column  Determine the integers written in the remaining squares in the magic square.  It can be shown that there exists a unique magic square consistent with the given information.

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

li1=[a,b,3*c-a-b]
li2=[4*c-2*a-b,2*c-b,2*a+b-2*c]
li3=[a+b-c,2*c-b,2*c-a]
print(*li1)
print(*li2)
print(*li3)

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

li1=[a,b,3*c-a-b]
li2=[4*c-2*a-b,c,2*a+b-2*c]
li3=[a+b-c,2*c-b,2*c-a]
print(*li1)
print(*li2)
print(*li3)
Problem:
Snuke has an empty sequence a.  He will perform N operations on this sequence.  In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).  You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.

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

for i in range(N):
  if i + 1 < b[i]:
    print("-1")
    exit()

b.reverse()
L = []
for i in range(1, N + 1):
  cnt = 0
  for j in range(0, N):
    if i == 1:
      if b[j] == i:
        L.append(i)
    else:
      if b[j] == i:
        L.insert(i + cnt - 1, i)
        cnt += 1
      elif b[j] < i:
        cnt += 1

print(L)
  

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

for i in range(N):
  if i + 1 < b[i]:
    print("-1")
    exit()

b.reverse()
L = []
for i in range(1, N + 1):
  cnt = 0
  for j in range(0, N):
    if i == 1:
      if b[j] == i:
        L.append(i)
    else:
      if b[j] == i:
        L.insert(i + cnt - 1, i)
        cnt += 1
      elif b[j] < i:
        cnt += 1

for i in L:
  print(i)
Problem:
Snuke loves working out. He is now exercising N times.  Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i.  Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.

Incorrect submission (verdict: Wrong Answer):
# ABC 055 B

N = int(input())
print(2 ** (N-1) % 1000000007)

Fixed, accepted submission:
# ABC 055 B

N = int(input())
p = 1
for i in range(1, N+1):
    p = p * i % 1000000007
print(p)
Problem:
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.  The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)  Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?

Incorrect submission (verdict: Time Limit Exceeded):
p=int(input())
k=100
o=0
j=0
while p>k:
    k1=k+(k*101)//10000
    o+=1
print(o)

Fixed, accepted submission:
def main(p):
    k=100
    a=0
    while k<p:
        k=(k+k*0.01)//1
        a+=1
    print(a)
p=int(input())   
main(p)
Problem:
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".

Incorrect submission (verdict: Wrong Answer):
import sys, re

P = r'(.*)k(.*)e(.*)y(.*)e(.*)n(.*)c(.*)e(.*)'

s = input().rstrip('\n')

m = re.match(P, s)

if m is not None:
  print([ x for x in m.groups() if x])
  if len([ x for x in m.groups() if x]) <= 1:
    print('YES')
    sys.exit()
print('NO')


Fixed, accepted submission:
import sys

M = [1, 7, 9, 4]
N = [ int(s) for s in input().rstrip('\n').split(' ')]

for m in M:
  if m not in N:
    break
else:
  print('YES')
  sys.exit()
print('NO')