TnT/CodeNet4Repair huggingface dataset:
Problem:
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.  Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.  Find the inversion number of B, modulo 10^9 + 7.  Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.

Incorrect submission (verdict: Wrong Answer):
n,k=map(int, input().split())
a=list(map(int, input().split()))
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]>a[j]:
      ans+=1
print(10**9+7)
x=(ans*k*(k+1))//2
y=(n*(n-1))//2
z=(k*(k-1))//2
print((x+(y-ans)*z)%(10**9+7))

Fixed, accepted submission:
n,k=map(int, input().split())
a=list(map(int, input().split()))
ans=0
rev=0
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]>a[j]:
      ans+=1
    if a[i]<a[j]:
      rev+=1
      
x=(ans*k*(k+1))//2
y=(rev*k*(k-1))//2
print((x+y)%(10**9+7))
Problem:
For a given weighted graph $G = (V, E)$, find the shortest path from a source to each vertex. For each vertex $u$, print the total weight of edges on the shortest path from vertex $0$ to $u$.

Incorrect submission (verdict: Wrong Answer):
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop
INF = float("inf")
def MAIN():
    n = int(input())
    G = [[i, INF] for i in range(n)]
    G[0][1] = 0
    m = {}
    for _ in range(n):
        A = list(map(int, readline().split()))
        m[A[0]] = {}
        for i in range(2, len(A), 2):
            m[A[0]][A[i]] = A[i + 1]
    dp = [(0, 0)]
    while dp:
        cost, u = heappop(dp)
        for v, c in m[u].items():
            if G[v][1] > G[u][1] + c:
                G[v][1] = G[u][1] + c
                heappush(dp, (G[v][1], v))
    print(*G)
MAIN()



Fixed, accepted submission:
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop
INF = float("inf")
def MAIN():
    n = int(input())
    adj = [[]] * n
    for _ in range(0, n):
        U = list(map(int, input().split()))
        adj[U[0]] = zip(U[2::2], U[3::2])
    def dijkstra():
        d = [INF] * n
        d[0] = 0
        hq = [(0, 0)]
        while hq:
            u = heappop(hq)[1]
            for v, c in adj[u]:
                alt = d[u] + c
                if d[v] > alt:
                    d[v] = alt
                    heappush(hq, (alt, v))
        print("\n".join(f"{i} {c}" for i, c in enumerate(d)))
    dijkstra()
MAIN()
Problem:
There is a hotel with the following accommodation fee:    * X yen (the currency of Japan) per night, for the first K nights   * Y yen per night, for the (K+1)-th and subsequent nights  Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.

Incorrect submission (verdict: Wrong Answer):
N, K, X, Y = [int(input()) for j in range(4)]

def price(N, K, X, Y):
    if N < K:
        return N * X
    else:
        print("exceed", K, X, K * X + (N-K) * Y)
        return N * X + (N-K) * Y

print(price(N, K, X, Y))

Fixed, accepted submission:
N, K, X, Y = [int(input()) for i in range(4)]

def price(N, K, X, Y):
    if N < K:
        return N * X
    else:
        return K * X + (N-K) * Y

print(price(N, K, X, Y))
Problem:
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:    * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.

Incorrect submission (verdict: Wrong Answer):
def extract_6(x):
	strtemp=' '
	if(len(x)>=6):
		temp=[0]*6
		for i in range(6):
			temp[i]=x[len(x)-6+i]
	else:
		temp='false'
	strtemp=''.join(temp)
	print(strtemp)
	return(strtemp)

def extract_5(x):
	strtemp=' '
	if(len(x)>=5):
		temp=[0]*5
		for i in range(5):
			temp[i]=x[len(x)-5+i]
	else:
		temp='false'
	strtemp=''.join(temp)
	print(strtemp)
	return(strtemp)

S=input()
flag=1
while(flag==1):
	if(extract_6(S)=='dreamer'):
		S=S.rstrip('dreamer')
	elif(extract_6(S)=='eraser'):
		S=S.rstrip('eraser')
	elif(extract_5(S)=='dream'):
		S=S.rstrip('dream')
	elif(extract_5(S)=='erase'):
		S=S.rstrip('erase')
	else:
		flag=0
if len(S)!=0:
	print('NO')
else:
	print('YES')
print(S)

Fixed, accepted submission:
def extract_6(x):
	strtemp=' '
	if(len(x)>=6):
		temp=[0]*6
		for i in range(6):
			temp[i]=x[len(x)-6+i]
	else:
		temp='false'
	strtemp=''.join(temp)
	return(strtemp)

def extract_5(x):
	strtemp=' '
	if(len(x)>=5):
		temp=[0]*5
		for i in range(5):
			temp[i]=x[len(x)-5+i]
	else:
		temp='false'
	strtemp=''.join(temp)
	return(strtemp)
	
def extract_7(x):
	strtemp=' '
	if(len(x)>=7):
		temp=[0]*7
		for i in range(7):
			temp[i]=x[len(x)-7+i]
	else:
		temp='false'
	strtemp=''.join(temp)
	return(strtemp)

S=input()
flag=1
while(flag==1):
	if(extract_7(S)=='dreamer'):
		S=S[:-7]
	elif(extract_6(S)=='eraser'):
		S=S[:-6]
	elif(extract_5(S)=='dream'):
		S=S[:-5]
	elif(extract_5(S)=='erase'):
		S=S[:-5]
	else:
		flag=0
if len(S)!=0:
	print('NO')
else:
	print('YES')
Problem:
Snuke has N strings. The i-th string is s_i.  Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.

Incorrect submission (verdict: Wrong Answer):
#python 3.5.2

N = int(input())
s_list = [input() for i in range(N)]
cnt = sum([1 for s in s_list if "AB" in s])
a_end, b_start, a_b = 0, 0, 0
for s in s_list:
    if s[0] == "B" and s[-1] == "A":
        a_b += 1
    elif s[0] == "B":
        b_start += 1
    elif s[-1] == "A":
        a_end += 1
print(a_end, b_start, a_b)
print(min(a_end, b_start)+a_b+cnt)

Fixed, accepted submission:
#python 3.5.2

N = int(input())
s_list = [input() for i in range(N)]
cnt = sum([s.count("AB") for s in s_list])
a_end, b_start, a_b = 0, 0, 0

for s in s_list:
    if s[0] == "B" and s[-1] == "A":
        a_b += 1
    elif s[0] == "B":
        b_start += 1
    elif s[-1] == "A":
        a_end += 1
if a_b == 0:
    cnt += min(a_end, b_start)
else:
    cnt += a_b - 1
    if a_end >= 1:
        cnt += 1
        a_end -= 1
    if b_start >= 1:
        cnt += 1
        b_start -= 1
    cnt += min(a_end, b_start)
print(cnt)
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())
result = (r*100+g*10+b)%4
if result==0:
  print('yes')
else:
  print('no')

Fixed, accepted submission:
r,g,b=map(int,input().split())
print('YES' if (r*100+g*10+b)%4 == 0 else 'NO')
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()))

def prime(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = sorted(prime(a))
b = sorted(prime(b))

print(a, b)
c = set()


def cal(a, b):
    c = set()
    for i in range(len(a)):
        c.add(a[i])
    for i in range(len(b)):
        c.add(b[i])
    ans = []
    e = 1
    for i in range(len(c)):
        d =c.pop()
        if a.count(d) >= b.count(d):
            for j in range(a.count(d)):
                ans.append(d)
        else:
            for j in range(b.count(d)):
                ans.append(d)

    for i in range(len(ans)):
        e *= ans[i]

    return e

print(cal(a, b))



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

def prime(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = sorted(prime(a))
b = sorted(prime(b))

c = set()


def cal(a, b):
    c = set()
    for i in range(len(a)):
        c.add(a[i])
    for i in range(len(b)):
        c.add(b[i])
    ans = []
    e = 1
    for i in range(len(c)):
        d =c.pop()
        if a.count(d) >= b.count(d):
            for j in range(a.count(d)):
                ans.append(d)
        else:
            for j in range(b.count(d)):
                ans.append(d)

    for i in range(len(ans)):
        e *= ans[i]

    return e

print(cal(a, b))
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(N*(N+1)/2)


Fixed, accepted submission:
N = int(input())
print(N*(N+1)//2)
Problem:
N people are waiting in a single line in front of the Takahashi Store. The cash on hand of the i-th person from the front of the line is a positive integer A_i.  Mr. Takahashi, the shop owner, has decided on the following scheme: He picks a product, sets a positive integer P indicating its price, and shows this product to customers in order, starting from the front of the line. This step is repeated as described below.  At each step, when a product is shown to a customer, if price P is equal to or less than the cash held by that customer at the time, the customer buys the product and Mr. Takahashi ends the current step. That is, the cash held by the first customer in line with cash equal to or greater than P decreases by P, and the next step begins.  Mr. Takahashi can set the value of positive integer P independently at each step.  He would like to sell as many products as possible. However, if a customer were to end up with 0 cash on hand after a purchase, that person would not have the fare to go home. Customers not being able to go home would be a problem for Mr. Takahashi, so he does not want anyone to end up with 0 cash.  Help out Mr. Takahashi by writing a program that determines the maximum number of products he can sell, when the initial cash in possession of each customer is given.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
a=[int(input())for i in range(n)]
c=0
b=1
d=0
while c<n:
    if a[c]==b:
        b+=1
        c+=1
    else:
        if a[c]%b==0:
            d+=max((a[c]-2-b)//b+1,a[c]//b-1)
            c+=1
        else:
            d+=a[c]//b
            c+=1
print(d)

Fixed, accepted submission:
n=int(input())
a=[int(input())for i in range(n)]
c=0
b=1
d=0
while c<n:
    if a[c]==b:
        b+=1
        c+=1
    else:
        if a[c]%b==0:
            d+=((a[c]-2-b)//b+1if b!=1 else a[c]-1)
            c+=1
            b+=(1 if b==1 else 0)
        else:
            d+=a[c]//b
            c+=1
print(d)
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):
 # -*- coding: utf-8 -*-

[X, Y, Z] = [int(i) for i in input().split()]

personal_width = Y + Z
chair_width = X - 2 * Z

number = chair_width // personal_width
amari = X % personal_width

if amari >= X:
    number += 1

print(number)

Fixed, accepted submission:
 # -*- coding: utf-8 -*-

[X, Y, Z] = [int(i) for i in input().split()]

personal_width = Y + Z
chair_width = X - Z

number = chair_width // personal_width
amari = X % personal_width

if amari >= X:
    number += 1

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

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

if (X*1.08)//1 == N:
    print(X)
else:
    print(":(")


Fixed, accepted submission:
N = int(input())
X = int(N//1.08)

if (X*1.08)//1 == N:
    print(X)
elif ((X+1)*1.08)//1 == N:
    print(X+1)
else:
    print(":(")
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())

dct = []
for i in range(len(s)):
    for j in range(k+1):
        word = s[i:i+j]
        if word not in dct:
            dct.append(word)
dct.sort()

for d in dct:
    print(d)

Fixed, accepted submission:
s = input()
k = int(input())
lst = sorted(list(set(s)))
tank = []
for tg in lst:
    for i in range(len(s)):
        if s[i]==tg:
            for j in range(k):
                if i+j<=len(s) and (s[i:i+j+1] not in tank):
                    tank.append(s[i:i+j+1])
    if len(tank) >= k:
        break
tank.sort()
print(tank[k-1])
Problem:
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode:                 Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4     do if A[j] <= x 5        then i = i+1 6            exchange A[i] and A[j]  7 exchange A[i+1] and A[r] 8 return i+1   Quicksort(A, p, r) 1 if p < r 2    then q = Partition(A, p, r) 3        run Quicksort(A, p, q-1) 4        run Quicksort(A, q+1, r)   Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers.  Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).

Incorrect submission (verdict: Wrong Answer):

def partition(A,p,r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if A[j][1] <= x[1]:
            i = i+1
            (A[i],A[j]) = (A[j],A[i])
    (A[i+1],A[r]) = (A[r],A[i+1])
    return i+1
 
def quicksort(A,p,r):
    if p < r:
        q = partition(A,p,r)
        quicksort(A,p,q-1)
        quicksort(A,q+1,r)

def isStable(A,n):
    for i in range(1,n-1):
        if A[i-1][1] == A[i][1] and A[i-1][2] > A[i][2]:
            return False
    return True

if __name__ == '__main__':
    n = (int)(input())
    A = []
    for i in range(0,n):
        tmp = list(input().split())
        A.append((tmp[0],(int)(tmp[1]),i))
    quicksort(A,0,n-1)

    print("Stable" if isStable(A,n) else "Not Stable" )

    for x in A:
        print(x[0],x[1])

Fixed, accepted submission:

def partition(A,p,r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if A[j][1] <= x[1]:
            i = i+1
            (A[i],A[j]) = (A[j],A[i])
    (A[i+1],A[r]) = (A[r],A[i+1])
    return i+1
 
def quicksort(A,p,r):
    if p < r:
        q = partition(A,p,r)
        quicksort(A,p,q-1)
        quicksort(A,q+1,r)

def isStable(A,n):
    for i in range(1,n-1):
        if A[i-1][1] == A[i][1] and A[i-1][2] > A[i][2]:
            return False
    return True

if __name__ == '__main__':
    n = (int)(input())
    A = []
    for i in range(0,n):
        tmp = list(input().split())
        A.append((tmp[0],(int)(tmp[1]),i))
    quicksort(A,0,n-1)

    print("Stable" if isStable(A,n) else "Not stable" )

    for x in A:
        print(x[0],x[1])
Problem:
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Incorrect submission (verdict: Wrong Answer):
n,a,b=map(int,input().split())
ans=0
for i in range(1,a+1):
    k=list(str(i))
    m=list(map(int,k))
    if a<=sum(m)<=b:
        ans+=i
print(ans)

Fixed, accepted submission:
a,b,c=map(int,input().split())
ans=0
for i in range(1,a+1):
    n=list(str(i))
    m=list(map(int,n))
    if b<=sum(m)<=c:
        ans+=i
print(ans)
Problem:
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.  Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests.    * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B.   * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students.  A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these.  Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.

Incorrect submission (verdict: Wrong Answer):
N, A, B = list(map(int, input().split()))
S = input()
cnt1 = 0
cnt2 = 0
for x in S:
    if x == 'a':
        if cnt1 < A+B:
            print("YES")
            cnt1 += 1
        else:
            print("NO")
    elif x == 'b':
        if cnt1 < A+B and cnt2 < B:
            print("YES")
            cnt1 += 1
            cnt2 += 1
        else:
            print("NO")
    else:
        print("NO")

Fixed, accepted submission:
N, A, B = list(map(int, input().split()))
S = input()
cnt1 = 0
cnt2 = 0
for x in S:
    if x == 'a':
        if cnt1 < A+B:
            print("Yes")
            cnt1 += 1
        else:
            print("No")
    elif x == 'b':
        if cnt1 < A+B and cnt2 < B:
            print("Yes")
            cnt1 += 1
            cnt2 += 1
        else:
            print("No")
    else:
        print("No")
Problem:
You are given an H × W grid.   The squares in the grid are described by H strings, S_1,...,S_H.   The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).   `.` stands for an empty square, and `#` stands for a square containing a bomb.  Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.   (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)   He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  Print the strings after the process.

Incorrect submission (verdict: Wrong Answer):
h,w=map(int,input().split())
s=[input()+"." if i!=h else "."*(w+1) for i in range(h+1)]
def count_8(i,j):
    global h,w,s
    cnt=s[i-1][j-1]=="#"+s[i-1][j+1]=="#"+s[i+1][j-1]=="#"+s[i+1][j+1]=="#" \
        +s[i-1][j]=="#"+s[i][j-1]=="#"+s[i+1][j]=="#"+s[i][j+1]=="#"
    return cnt
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            print("#",end="")
        else:
            print(count_8(i,j),end="")
    print()


Fixed, accepted submission:
h,w=map(int,input().split())
s=[input()+"." if i!=h else "."*(w+1) for i in range(h+1)]
def count_8(i,j):
    global h,w,s
    cnt=str((s[i-1][j-1]=="#")+(s[i-1][j+1]=="#")+(s[i+1][j-1]=="#")+(s[i+1][j+1]=="#") \
        +(s[i-1][j]=="#")+(s[i][j-1]=="#")+(s[i+1][j]=="#")+(s[i][j+1]=="#"))
    return cnt
for i in range(h):
    s_sub=""
    for j in range(w):
        if s[i][j]=="#":
            s_sub+="#"
        else:
            s_sub+=count_8(i,j)
    print(s_sub)
Problem:
There is a hotel with the following accommodation fee:    * X yen (the currency of Japan) per night, for the first K nights   * Y yen per night, for the (K+1)-th and subsequent nights  Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.

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

Q=N*X+Y*(N-K)
print(Q)

Fixed, accepted submission:
N=int(input())
K=int(input())
X=int(input())
Y=int(input())

if N<=K:
    Q=N*X
else:
    Q=K*X+(N-K)*Y
print(int(Q))
Problem:
Taro and Hanako are playing card games. They have n cards each, and they compete n turns. At each turn Taro and Hanako respectively puts out a card. The name of the animal consisting of alphabetical letters is written on each card, and the bigger one in lexicographical order becomes the winner of that turn. The winner obtains 3 points. In the case of a draw, they obtain 1 point each.  Write a program which reads a sequence of cards Taro and Hanako have and reports the final scores of the game.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
t_point = 0
h_point = 0
for i in range(n):
    card = input().split()
    print(card)
    taro = card[0]
    card.sort()
    card.reverse()
    print(card)
    if card[0] == card[1]:
        t_point += 1
        h_point += 1
    elif card[0] == taro:
        t_point += 3
    else:
        h_point += 3

print(t_point,h_point)

Fixed, accepted submission:
n = int(input())
t_point = 0
h_point = 0
for i in range(n):
    card = input().split()
    taro = card[0]
    card.sort()
    card.reverse()
    if card[0] == card[1]:
        t_point += 1
        h_point += 1
    elif card[0] == taro:
        t_point += 3
    else:
        h_point += 3

print(t_point,h_point)