TnT/CodeNet4Repair huggingface dataset:
Problem:
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.

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

sec = s % 60
min = s // 60 # may be more than 60
hr = min // 60
min = min % 60


Fixed, accepted submission:
s = int(input())
sec = s%60
min = s//60 # may be more than 60
hr = min//60
min = min%60
print(hr, min, sec, sep=':')
Problem:
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:                 for i = 1 to A.length-1     key = A[i]     /* insert A[i] into the sorted sequence A[0,...,j-1] */     j = i - 1     while j >= 0 and A[j] > key         A[j+1] = A[j]         j--     A[j+1] = key   Note that, indices for array elements are based on 0-origin.  To illustrate the algorithms, your program should trace intermediate result for each step.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
ary = [int(x) for x in input().split(' ')]

print(ary)
for i in range(1, n):
    v = ary[i]
    j = i - 1
    while j >= 0 and ary[j] > v:
        ary[j + 1] = ary[j]
        j -= 1
    ary[j + 1] = v
    print(ary)

Fixed, accepted submission:
n = int(input())
a = input()
print(a)
a = [int(x) for x in a.split(' ')]

for i in range(1, n):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j + 1] = a[j]
        j -= 1
    a[j + 1] = v
    print(' '.join([str(x) for x in a]))
Problem:
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.  Determine if it is possible that there are exactly X cats among these A + B animals.

Incorrect submission (verdict: Wrong Answer):
a,b,x=map(int,input().split())
if a<=x and a+b>=x:
  print("Yes")
else:
  print("No")

Fixed, accepted submission:
a,b,x=map(int,input().split())
if a<=x and a+b>=x:
  print("YES")
else:
  print("NO")
Problem:
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.

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

Fixed, accepted submission:
import math
n = int(input())
print(int(math.sqrt(n))**2)
Problem:
We ask you to select some number of positive integers, and calculate the sum of them.  It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.  Your objective is to make the sum congruent to C modulo B. Determine whether this is possible.  If the objective is achievable, print `YES`. Otherwise, print `NO`.

Incorrect submission (verdict: Wrong Answer):
def solve():
    a, b, c = map(int, input().split())
    for i in range(1, b + 1):
        if a * i % b == c:
            return "Yes"
    return "No"


if __name__ == "__main__":
    print(solve())


Fixed, accepted submission:
def solve():
    a, b, c = map(int, input().split())
    for i in range(1, b + 1):
        if (a * i) % b == c:
            return "YES"
    return "NO"


if __name__ == "__main__":
    print(solve())
Problem:
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:    * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.

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

if d_list[0] != 0:
  print(0)
else:
  d_sort = sorted(d_list)
  d = 1
  pre_c = 1
  cur_c = 0
  count = 1
  for i in range(1, n):
    if d_sort[i] == d:
      cur_c += 1
    elif d_sort[i] == d + 1:
      count *= pre_c ** cur_c
      count %= divider
      d += 1
      pre_c = cur_c
      cur_c = 0
    else:
      count = 0
      cur_c = 0
      break
  count *= pre_c ** cur_c
  count %= divider
  print(count)

Fixed, accepted submission:
n = int(input())
d_list = list(map(int, input().split()))
divider = 998244353

if d_list[0] != 0:
  print(0)
else:
  d_sort = sorted(d_list)
  d = 1
  pre_c = 1
  cur_c = 0
  count = 1
  for i in range(1, n):
    if d_sort[i] == d:
      cur_c += 1
    elif d_sort[i] == d + 1:
      count *= pre_c ** cur_c
      count %= divider
      d += 1
      pre_c = cur_c
      cur_c = 1
    else:
      count = 0
      cur_c = 0
      break
  count *= pre_c ** cur_c
  count %= divider
  print(count)
Problem:
E869120 has A 1-yen coins and infinitely many 500-yen coins.   Determine if he can pay exactly N yen using only these coins.

Incorrect submission (verdict: Wrong Answer):
N, A = [int(input()) for _ in range(2)]

if N % 500 == A:
  print('Yes')
else:
  print('No')

Fixed, accepted submission:
N, A = [int(input()) for _ in range(2)]

if N % 500 <= A:
  print('Yes')
else:
  print('No')
Problem:
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.  According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Incorrect submission (verdict: Wrong Answer):
import sys
[n, yen] = list(map(int, input().split()))
ans = [-1, -1, -1]
for x in range(0, yen // 10000 + 1):
    for y in range(0, (yen - 10000*x)//5000 + 1):
        z = (yen - 10000*x - 5000*y) // 1000
        if x + y + z == n:
            ans = [x, y, z]
            print("{} {} {}".format(ans[0], ans[1], ans[2]))
            sys.exit()


Fixed, accepted submission:
[n, yen] = list(map(int, input().split()))
ans = [-1, -1, -1]
for x in range(0, yen // 10000 + 1):
    for y in range(0, (yen - 10000*x)//5000 + 1):
        z = (yen - 10000*x - 5000*y) // 1000
        if x + y + z == n:
            ans = [x, y, z]
print("{} {} {}".format(ans[0], ans[1], ans[2]))
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):
N = list(input())
K = list(input())

if N[0]== K[2] and N[1]==K[1] and N[2]== K[0]:
    print('Yes')
else:
    print('No')


Fixed, accepted submission:
N = list(input())
K = list(input())

if N[0]== K[2] and N[1]==K[1] and N[2]== K[0]:
    print('YES')
else:
    print('NO')
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())
b = int(input())
h = int(input())
print((a+b)*h/2)


Fixed, accepted submission:
a = int(input())
b = int(input())
h = int(input())
print((a+b)*h//2)
Problem:
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:    * The graph is simple and connected.   * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S.  It can be proved that at least one such graph exists under the constraints of this problem.

Incorrect submission (verdict: Wrong Answer):
n= int(input())
s = n + (0 if n%2 == 1 else 1)
ans = []
for i in range(n-1):
  for j in range(i+1,n):
    if i+j+2 != s:
      ans.append(str(i+1)+" "+str(j+1))
for t in ans:
  print(t)

Fixed, accepted submission:
n= int(input())
s = n + (0 if n%2 == 1 else 1)
ans = []
for i in range(n-1):
  for j in range(i+1,n):
    if i+j+2 != s:
      ans.append(str(i+1)+" "+str(j+1))
print(len(ans))
for t in ans:
  print(t)
Problem:
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.  Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).

Incorrect submission (verdict: Wrong Answer):
H, W = map(int, input().split())
Cij = [input().split() for i in range(H)]
Dij = []

for i in range(H ):

#  a = (i + 1) // 2
  Dij.append(Cij[i])
  Dij.append(Cij[i])
  
  #print(a)
  
 
print(Dij)
  

Fixed, accepted submission:
H, W = map(int, input().split())
for i in range(H):
  Ci = input()
  print(Ci)
  print(Ci)
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):
import bisect

N = int(input())

*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort()
B.sort()
C.sort()

A_B = [0]*N
B_C = [0]*N

for i in range(N):
    count = 0
    index = bisect.bisect_right(A,B[i])
    A_B[i] = index 

for i in range(N):
    count = 0
    index = bisect.bisect_right(A,B[i])
    B_C[i] = index

sum = 0
for i in range(N):
    sum = sum + B_C[i]*A_B[i]

print(sum)

Fixed, accepted submission:
import bisect

N = int(input())

*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort()
B.sort()
C.sort()

A_B = [0]*N
B_C = [0]*N

for i in range(N):
    index = bisect.bisect_left(A,B[i])
    A_B[i] = index 

for i in range(N):
    index = bisect.bisect_right(C,B[i])
    B_C[i] = len(C)-index

sum = 0
for i in range(N):
    sum = sum + B_C[i]*A_B[i]

print(sum)
Problem:
Print all the integers that satisfies the following in ascending order:    * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.

Incorrect submission (verdict: Wrong Answer):
A, B, K = map(int, input().split())
l = B - A
if K > l:
    K = l
sub = [i for i in range(A, B+1)]
ans = sub[0:K] + sub[len(sub)-K:len(sub)]
ans.sort()
print(*set(ans), sep='\n')

Fixed, accepted submission:
A, B, K = map(int, input().split())
if K > B-A:
    ans = list(range(A, B+1))
else:
    ans = list(range(A, A+K)) + list(range(B, B - K, -1))
ans = list(set(ans))
ans.sort()
print(*ans, sep='\n')
Problem:
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:    * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.

Incorrect submission (verdict: Wrong Answer):
from collections import Counter

N = int(input())
DD = list(map(int, input().split()))
D = sorted(dict(Counter(DD)).items(), key=lambda x:x[0])

ans = 0
if 1 == DD.count(0):
    ans = 1
    for i in range(1, len(D)-1):
        print(D[i][1], D[i+1][1])
        ans *= D[i][1]**D[i+1][1]
    print(ans)
        
else:
    print(ans)
    

Fixed, accepted submission:
from collections import Counter

N = int(input())
DD = list(map(int, input().split()))
D = Counter(DD)

if DD[0] != 0:
    print(0)
elif D[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(len(D)-1):
        ans *= D[i]**D[i+1]
        ans %= 998244353 
    print(ans)
Problem:
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters.  Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way.  You are given a string s consisting of uppercase English letters. Determine whether the string `CF` can be obtained from the string s by deleting some characters.

Incorrect submission (verdict: Wrong Answer):
s = input()
c = False
f = False
for i in s:
    if i == 'c':
        c = True
    if c == True and i == 'f':
        f = True

if c & f:
    print("Yes")
else :
    print("No")


Fixed, accepted submission:
s = input()
c = False
f = False
for i in range(len(s)):
    if s[i] == 'C':
        c = True
    if c == True and s[i] == 'F':
        f = True

if c and f:
    print("Yes")
else :
    print("No")
Problem:
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.  Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.

Incorrect submission (verdict: Wrong Answer):
A, B, C, X, Y = map(int, input().split())
C * 2 * min(X,Y) + max(A * (X - Y), B * (Y - X))

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

Incorrect submission (verdict: Wrong Answer):
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
c = 0 
maxl = 0
for i in set(s):
    c = s.count(i) - t.count(i)
    max1 = max(maxl, c)
print(maxl)

Fixed, accepted submission:
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
c = 0 
maxl = 0
for i in set(s):
    c = s.count(i) - t.count(i)
    maxl = max(maxl, c)
print(maxl)
Problem:
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:    * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.   * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.  The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Incorrect submission (verdict: Wrong Answer):
import math
n, h = map(int,input().split())
a=[]
b=[]

for i in range(n):
    ta, tb = map(int,input().split())
    a.append(ta)
    b.append(tb)

maxa=max(a)
b.append(maxa)
b.sort()
b.reverse()

damage=0
cnt=0
while(h>damage):
    
    if b[0]>maxa:
        damage+=b[0]
        del b[0]
        cnt+=1
    else:
        cnt=cnt+int((h-damage)/b[0])
        #print(cnt,damage)
        damage+=b[0]*((h-damage)/b[0])
        if h>damage:
            cnt+=1
            damage+=b[0]

print(cnt)


Fixed, accepted submission:
import math
n, h = map(int,input().split())
a=[]
b=[]

for i in range(n):
    ta, tb = map(int,input().split())
    a.append(ta)
    b.append(tb)

maxa=max(a)
b.append(maxa)
b.sort()
b.reverse()

damage=0
cnt=0
while(h>damage):
    
    if b[0]>maxa:
        damage+=b[0]
        del b[0]
        cnt+=1
    else:
        cnt=cnt+int((h-damage)/b[0])
        #print(cnt,damage)
        damage+=b[0]*int((h-damage)/b[0])
        if h>damage:
            cnt+=1
            damage+=b[0]

print(cnt)
Problem:
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:                 for i = 1 to A.length-1     key = A[i]     /* insert A[i] into the sorted sequence A[0,...,j-1] */     j = i - 1     while j >= 0 and A[j] > key         A[j+1] = A[j]         j--     A[j+1] = key   Note that, indices for array elements are based on 0-origin.  To illustrate the algorithms, your program should trace intermediate result for each step.

Incorrect submission (verdict: Wrong Answer):
#!/usr/bin/env python

def InsertSort(N,A):
    for i in range(1,N):
        v=A[i]
        j=i-1
        while j>=0 and A[j]>v:
            A[j+1]=A[j]
            j-=1
        A[j+1]=v
        print(*A)


if __name__ == "__main__":
    N=int(input())
    arr=list(map(int,input().split()))
    InsertSort(N,arr)

Fixed, accepted submission:
#!/usr/bin/env python

def InsertSort(N,A):
    for i in range(1,N):
        v=A[i]
        j=i-1
        while j>=0 and A[j]>v:
            A[j+1]=A[j]
            j-=1
        A[j+1]=v
        print(*A)


if __name__ == "__main__":
    N=int(input())
    arr=list(map(int,input().split()))
    print(*arr)
    InsertSort(N,arr)
Problem:
Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi.  How many ways are there to choose K consecutive integers?

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

Fixed, accepted submission:
N,K= map(int, input().split())
print(N-K +1)
Problem:
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements?  Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds:    * r_1 + c_1 = r_2 + c_2   * r_1 - c_1 = r_2 - c_2  For example, in the following figure, the bishop can move to any of the red squares in one move:  

Incorrect submission (verdict: Wrong Answer):
H,W=map(int,input().split())
if (H*W)%2==0:
  print((H*W)/2)
else:
  print(H+W+1)
  

Fixed, accepted submission:
import math
H,W=map(int,input().split())
if H==1 or W==1:
  print(1)
else:
  print(math.ceil((H*W)/2))
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):
three =  list(map(int, input().split()))
r = three[0]
g = three[1]
b = three[2]
g = str(g)
b = str(b)
gb = g + b
gb = int(gb)

if gb%4 ==0:
    print('Yes')
else:
    print('No')
    

Fixed, accepted submission:
three =  list(map(int, input().split()))
r = three[0]
g = three[1]
b = three[2]
g = str(g)
b = str(b)
gb = g + b
gb = int(gb)

if gb%4 ==0:
    print('YES')
else:
    print('NO')
Problem:
Find places where a R × C pattern is found within a H × W region. Print top- left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.

Incorrect submission (verdict: Wrong Answer):
def rabin_karp(T, P, d):
    n = len(T)
    m = len(P)
    if n < m:
        return
    h = 1
    p = 0
    t0 = 0
    for _ in range(m - 1):
        h *= d
    for i in range(m):
        p = d * p + P[i]
        t0 = d * t0 + T[i]
    # print("h = ", h)
    # print("p = ", p)
    for s in range(n - m + 1):
        # print("t0 = ", t0)
        if p == t0:
            print(s)
        if s < n - m:
            # print("     ", t0 - T[s] * h)
            # print("     ",  d)
            # print("     ", T[s + m])
            t0 = d * (t0 - T[s] * h) + T[s + m]


d = 1009
t = list(map(ord, input()))
p = list(map(ord, input()))

rabin_karp(t, p, d)


Fixed, accepted submission:
base1 = 1009
base2 = 1013
mask = (1 << 32) - 1


def calculate_hash(f, r, c):
    global ph, pw, h
    tmp = [[0 for _ in range(c)] for _ in range(r)]
    dr, dc = r - ph, c - pw

    t1 = 1
    for _ in range(pw):
        t1 = (t1 * base1) & mask
    for i in range(r):
        e = 0
        for j in range(pw):
            e = e * base1 + f[i][j]
        for j in range(dc):
            tmp[i][j] = e
            e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask
        tmp[i][dc] = e

    t2 = 1
    for _ in range(ph):
        t2 = (t2 * base2) & mask
    for j in range(dc + 1):
        e = 0
        for i in range(ph):
            e = e * base2 + tmp[i][j]
        for i in range(dr):
            h[i][j] = e
            e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask
        h[dr][j] = e


th, tw = map(int, input().split())
t = [[ord(x) for x in input().strip()] for _ in range(th)]
ph, pw = map(int, input().split())
p = [[ord(x) for x in input().strip()] for _ in range(ph)]

if th >= ph and tw >= pw:
    h = [[0 for _ in range(tw)] for _ in range(th)]
    calculate_hash(p, ph, pw)
    key = h[0][0] & mask
    calculate_hash(t, th, tw)
    for i in range(th - ph + 1):
        for j in range(tw - pw + 1):
            if h[i][j] & mask == key:
                print(i, j)
Problem:
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied:    * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.  Find all favorite numbers and print the sum of those.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
ans = 0
for i in range(1,int(n**0.5)):
    m,r = divmod(n-i,i)
    if r == 0: ans += m
print(ans)

Fixed, accepted submission:
def divisor(n):
    fac = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0: 
            fac.append(i)
            if i*i != n: fac.append(n//i)
    return sorted(fac)

n = int(input())
ans = 0
for i in divisor(n):
    if i == 1: continue
    m = i-1
    p,r = divmod(n,m)
    if p == r: ans += m
print(ans)
Problem:
K 個の石から、P 人が順番に１つずつ石を取るゲームがあります。P 人目が石を取った時点で、まだ石が残っていれば、また１人目から順番に１つずつ石を取っていきます。このゲームでは、最後の石を取った人が勝ちとなります。K とP が与えられたとき、何人目が勝つか判定するプログラムを作成してください。

Incorrect submission (verdict: Wrong Answer):
for _ in range(int(input())):
    k, p= map(int, input().split())
    print(p if k%p else k%p)

Fixed, accepted submission:
n = int(input())
for _ in range(n):
    K, P = map(int, input().split())
    a = K % P
    print(P * (a == 0) + (a) * (a != 0))