qyliang/CodeNanoFix huggingface dataset:
Title: Bowling

As a class recreation, participants will play bowling. Create a program that takes input of each participant's bowling information and outputs the results in descending order of scores. In case of a tie, output in ascending order of student ID. The number of participants is between 3 and 40, and each participant plays one game.

Bowling involves rolling a ball towards 10 pins arranged in an equilateral triangle, aiming to knock them down. If all pins are knocked down on the first roll, it's called a strike, and the player moves to the next frame. If not, the remaining pins are rolled for a second time. If all pins are knocked down on the second roll, it's called a spare, and the player moves to the next frame.

A game consists of 10 frames, with the first 9 frames allowing 2 rolls each. The 10th frame allows either 3 rolls for a strike or spare, or 2 rolls otherwise, ending the game.

Scoring:
- If there are no spares or strikes in a frame, the score is the total number of pins knocked down in the 2 rolls.
- If a spare is achieved, 10 points plus the number of pins knocked down in the next roll are added to the frame's score.
- If a strike is achieved, 10 points plus the number of pins knocked down in the next 2 rolls are added to the frame's score.
- In the 10th frame, the total number of pins knocked down in the 3 rolls (if a strike or spare) is added to the frame's score.
- The total score of all frames is the game's score, with a maximum of 300 points.

Input:
Multiple datasets are given as input, ending with a single line containing zero. Each dataset is in the following format:
- The number of participants, followed by the participant's information in the format: ID, followed by the number of pins knocked down in each roll.

Output:
For each dataset, output the student ID and score in descending order of scores (ascending order of student ID in case of a tie). Each output should contain the student ID and score separated by a single space.

# Buggy version:
def score(x):
    s=0;t=1
    for _ in[0]*10:
        a=2;b=3
        if x[t]==10:a=1
        elif x[t]+x[t+1]!=10:b=2
        s+=sum(x[t:t+b]);t+=a
    return x[0],s

while 1:
    n=int(input())
    if n==0:break
    A=sorted([score(map(int,input().split())) for _ in [0]*n])
    for a,b in sorted(A,key=lambda x:-x[1]):print(a,b)

# Fixed version:
def score(x):
    s=0;t=1
    for _ in[0]*10:
        a=2;b=3
        if x[t]==10:a=1
        elif x[t]+x[t+1]!=10:b=2
        s+=sum(x[t:t+b]);t+=a
    return x[0],s

while 1:
    n=int(input())
    if n==0:break
    A=sorted([score(list(map(int,input().split()))) for _ in [0]*n])
    for a,b in sorted(A,key=lambda x:-x[1]):print(a,b)
AtCoDeer the deer has N square tiles numbered 1 through N, with each tile having a number and corners painted in one of 1000 colors. AtCoDeer wants to construct a cube using six of these tiles, with the following conditions: each tile's number must face outward, and each vertex of the cube must have three corners of the tiles painted in the same color. The task is to find the number of different cubes that can be constructed under these conditions. Two cubes are considered different if the set of used tiles or their directions are different, even if the color formations are the same. The input format is N followed by the colors of each tile, and the output is the number of different cubes that can be constructed.

# Buggy version:
from collections import deque
N = int(input())
C = []
M = {}
for i in range(N):
    *c, = 0, 0, 0, 0 #map(int, input().split())
    c = tuple(min(c[j:] + c[:j] for j in range(1, 5)))
    C.append(c)
    if c not in M:
        M[c] = deque([i])
    else:
        M[c].append(i)
def count(p, q, r, s):
    if p == q == r == s:
        return 4
    if p == r and q == s:
        return 2
    return 1
def solve(ci, cj, k):
    R = {}
    for l in range(4):
        #  [l]   [l-1]
        # [l+k] [l+k+1]
        c = ci[l], ci[l-1], cj[k-l], cj[k-l-1]
        c = tuple(min(c[j:] + c[:j] for j in range(1, 5)))
        if c not in M:
            return 0
        R[c] = R.get(c, 0) + 1
    res = 1
    for c in R:
        m = M[c]
        cnt = len(m)
        if c == cj:
            cnt -= 1
        if cnt < R[c]:
            return 0
        k = count(*c)
        for p in range(cnt-R[c]+1, cnt+1):
            res *= p * k
    return res

ans = 0
for i in range(N):
    ci = C[i]
    q = M[ci]; q.popleft()
    if not q:
        del M[ci]
    for j in range(i+1, N):
        cj = C[j]
        for k in range(4):
            ans += solve(ci, cj, k)
print(ans)


# Fixed version:
from collections import deque
N = int(input())
C = []
M = {}
for i in range(N):
    *c, = map(int, input().split())
    c = tuple(min(c[j:] + c[:j] for j in range(1, 5)))
    C.append(c)
    if c not in M:
        M[c] = deque([i])
    else:
        M[c].append(i)
def count(p, q, r, s):
    if p == q == r == s:
        return 4
    if p == r and q == s:
        return 2
    return 1
def solve(ci, cj, k):
    R = {}
    for l in range(4):
        #  [l]   [l-1]
        # [l+k] [l+k+1]
        c = ci[l], ci[l-1], cj[k-l], cj[k-l-1]
        c = tuple(min(c[j:] + c[:j] for j in range(1, 5)))
        if c not in M:
            return 0
        R[c] = R.get(c, 0) + 1
    res = 1
    for c in R:
        m = M[c]
        cnt = len(m)
        if c == cj:
            cnt -= 1
        if cnt < R[c]:
            return 0
        k = count(*c)
        for p in range(cnt-R[c]+1, cnt+1):
            res *= p * k
    return res

ans = 0
for i in range(N):
    ci = C[i]
    q = M[ci]; q.popleft()
    if not q:
        del M[ci]
    for j in range(i+1, N):
        cj = C[j]
        for k in range(4):
            ans += solve(ci, cj, k)
print(ans)
You are given N strings of lowercase alphabets. Each string is unique. For Q queries, you are provided with an integer k and a permutation of the alphabet. Output the sequence of the k-th string among the N strings in lexicographical order based on the given permutation. Constraints: 1 ≤ N,Q ≤ 100000, 1 ≤ |S_i| ≤ 400000, 1 ≤ k ≤ N, and the permutations are of length 26. The input is provided in the form of N strings, followed by Q queries. Output Q lines, each indicating the sequence of the k-th string.

# Buggy version:
import array;R=range;L=input;T=[0]*28;N=int(L());S=[];U=N*26**2*array.array('i',[0]);V=N*[0];Q=int(L())
for I in R(N):
	S+=[[ord(C)-95 for C in L()]];P=0
	for C in S[I]:
		if T[P+C]==0:T[P+C]=len(T);T+=[0]*28
		T[P]+=1;P=T[P+C]
	T[P]+=1;T[P+1]=1
while N:
	N-=1;P=0
	for C in S[N]:
		for A in R(26):
			X=T[P+A+2]
			if(A!=C-2)*X:U[676*N+26*A+C-2]+=T[X]
		V[N]+=T[P+1]
		P=T[P+C]
while Q:
	K,P=L().split();K=int(K)-1;P=[ord(C)-97 for C in P];X=1+V[K]
	for A in R(26):
		for B in R(A+1,26):
			X+=U[676*K+26*P[A]+P[B]]
	print(X);Q-=1

# Fixed version:
from array import*;R=range;T=[0]*28;N=int(input());S=[[ord(C)-95 for C in input()]for _ in[0]*N];U=N*26**2*array('i',[0]);V=N*[0];Q=int(input())
for X in S:
	P=0
	for C in X:
		if T[P+C]==0:T[P+C]=len(T);T+=[0]*28
		T[P]+=1;P=T[P+C]
	T[P]+=1;T[P+1]=1
for I in R(N):
	P=0
	for C in S[I]:
		for A in R(26):
			X=T[P+A+2]
			if(A!=C-2)*X:U[676*I+26*A+C-2]+=T[X]
		V[I]+=T[P+1]
		P=T[P+C]
while Q:
	K,P=input().split();K=int(K)-1;P=[ord(C)-97 for C in P];X=1+V[K]
	for A in R(26):
		for B in R(A+1,26):
			X+=U[676*K+26*P[A]+P[B]]
	print(X);Q-=1
You, a Kyoto University student, return for the second semester and hear a rumor about a barricade being placed before the start of the A-th class and removed before the start of the B-th class. Classes during the barricade will be canceled. Given N classes, each in a different period, find the number of classes you can attend. Constraints: 1 ≤ N ≤ 1000, 1 ≤ A < B ≤ 10^9, 1 ≤ t_i ≤ 10^9 (distinct). Input: N, A, B, and t_i. Output: Number of classes you can attend.

# Buggy version:
n, a, b = [ int(v) for v in input().split() ]
ans_list = []
for i in range(n):
  v = int(input())
  if a <= v < b:
    ans_list.append(v)
print(len(ans_list))


# Fixed version:
n, a, b = [ int(v) for v in input().split() ]
ans_list = []
for i in range(n):
    v = int(input())
    if not a <= v < b:
        ans_list.append(v)
print(len(ans_list))

# Buggy version:
N, A, B = list(map(int, input().split()))
t = [int(input()) for x in range(N)]

ans = 0

for i in range(N):
  if t[i] < A or t[i] > B:
    continue
  else:
    ans += 1
    
    
print(ans)
   



# Fixed version:
N, A, B = list(map(int, input().split()))
t = [int(input()) for x in range(N)]

ans = 0

for i in range(N):
  if t[i] < A or t[i] >= B:
    continue
  else:
    ans += 1
    
    
print(N - ans)

# Buggy version:
a, b, c = map(int, input().split())
ans = 0
for i in range(a):
    n = int(input())
    if n < b:
        ans += 1
print ans

# Fixed version:
a, b, c = map(int, input().split())
ans = 0
for i in range(a):
    n = int(input())
    if n < b or n >= c:
        ans += 1
print(ans)
You are given a Cookie Breeding Machine that takes a cookie with taste x and a non-negative integer y (0 <= y <= 127) as input. It generates two cookies with tastes y and (x XOR y). Starting with one cookie of taste D, you need to find the maximum sum of tastes of N cookies after N-1 operations. For each test case, you are given the number of operations N and the initial taste D. Output the maximum sum of tastes for each test case.

# Buggy version:
N,T=0,0
for i in range(int(input())):
  N,T=map(int,input().split())
  if N&1:
    T^=127
  print(T+(N-1)*127)

# Fixed version:
N,T=0,0
for i in range(int(input())):
  N,T=map(int,input().split())
  if N&1==0:
    T^=127
  print(T+(N-1)*127)
You are given a grid with R rows and C columns. Some cells already contain non-negative integers. You need to fill the remaining cells with non-negative integers such that for any 2x2 square formed by cells on the grid, the sum of the top left and bottom right integers equals the sum of the top right and bottom left integers. Determine if it's possible to meet these conditions. If possible, print "Yes"; otherwise, print "No".

# Buggy version:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# D-Grid and Integers

from collections import defaultdict

def ReadInput():
	return [int(i) for i in input().split(" ")]

(R, C) = ReadInput()
N = int(input())
VectorCover = defaultdict(int)
VectorSet = set() 
Grid = defaultdict(list)
for i in range(N):
	(r, c, a) = ReadInput()
	Grid[("R", r)].append((("C", c), a))
	Grid[("R", c)].append((("R", r), a))
	VectorSet.add(('R', r))
	VectorSet.add(('C', c))

def iteration(vector):
	VectorSet.discard(vector)
	for (v, a) in Grid[vector]:
		temp = a - VectorCover[vector]
		if (v in VectorCover):
			if(temp is not VectorCover[v]):
				print("No")
				exit()
		else:
			VectorCover[v] = temp
			iteration(v) 

while(len(VectorSet) is not 0):
	vector = VectorSet.pop()
	VectorCover[vector] = 0
	iteration(vector)
	minR = min(a for (p, a) in VectorCover.items() if (p[0] is "R"))
	minC = min(a for (p, a) in VectorCover.items() if (p[0] is "C"))
	if (minR + minC < 0):
		print("No")
		exit()
		
print("Yes")

# Fixed version:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# D-Grid and Integers

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

def ReadInput():
	return [int(i) for i in input().split(" ")]

(R, C) = ReadInput()
N = int(input())
VectorSet = set() 
Grid = defaultdict(list)
for i in range(N):
	(r, c, a) = ReadInput()
	Grid[("R", r)].append((("C", c), a))
	Grid[("C", c)].append((("R", r), a))
	VectorSet.add(("R", r))
	VectorSet.add(("C", c))

def iteration(vector):
	VectorSet.discard(vector)
	for (v, a) in Grid[vector]:
		temp = a - VectorCover[vector]
		if (v in VectorCover):
			if(temp != VectorCover[v]):
				print("No")
				exit()
		else:
			VectorCover[v] = temp
			iteration(v) 

while(len(VectorSet) != 0):
	vector = VectorSet.pop()
	VectorCover = dict() 
	VectorCover[vector] = 0
	iteration(vector)
	minR = min(a for (p, a) in VectorCover.items() if (p[0] == "R"))
	minC = min(a for (p, a) in VectorCover.items() if (p[0] == "C"))
	if (minR + minC < 0):
		print("No")
		exit()

print("Yes")
You are given a string "w". Find the number of elements of the best representation of "w" and the number of best representations of "w" modulo 1000000007. A good string "x" is one where for any string "y" and any integer "k (k ≥ 2)", the string obtained by concatenating "k" copies of "y" is different from "x". A good representation "F" of "w" is a sequence where each element "f_i" is a good string and the concatenation of all "f_i" in order is equal to "w". The best representation has the smallest number of elements. The input is given as "w" and the output should be the number of elements of the best representation of "w" and the number of best representations of "w" modulo 1000000007. The string "w" consists of lowercase letters (a-z) and has a length between 1 and 500000.

# Buggy version:
w=list(input())
n=len(w)
per=-1
def Z(s):
    m=len(s);z=[0]*m;c=0;f=[1]*m;
    for i in range(1,m):
        if i+z[i-c]<c+z[c]:z[i]=z[i-c]
        else:
            j=max(0,c+z[c]-i)
            while i+j<n and s[j]==s[i+j]:j=j+1
            z[i]=j;c=i
    for p in range(1,m):
        for k in range(2,z[p]//p+2):f[k*p-1]=0
    return f
for j in range(1,n//2+1):
    if n%j==0 and w[:n-j]==w[j:]:t=j;break;
if t==-1:print ('1\n1')
elif t==1:print (n);print (1)
else:
    zl=Z(w)
    w.reverse()
    zr=Z(w)
    cnt=0
    for i in range(0,n-1):
        if zl[i] and zr[n-2-i]:cnt=cnt+1
    print(2);print(cnt);

# Fixed version:
w=list(input())
n=len(w)
t=-1
def Z(s):
    m=len(s);z=[0]*m;c=0;f=[1]*m;
    for i in range(1,m):
        if i+z[i-c]<c+z[c]:z[i]=z[i-c]
        else:
            j=max(0,c+z[c]-i)
            while i+j<n and s[j]==s[i+j]:j=j+1
            z[i]=j;c=i
    for p in range(1,m):
        for k in range(2,z[p]//p+2):f[k*p-1]=0
    return f
for j in range(1,n//2+1):
    if n%j==0 and w[:n-j]==w[j:]:t=j;break;
if t==-1:print ('1\n1')
elif t==1:print (n);print (1)
else:
    zl=Z(w)
    w.reverse()
    zr=Z(w)
    cnt=0
    for i in range(0,n-1):
        if zl[i] and zr[n-2-i]:cnt=cnt+1
    print(2);print(cnt);
Snuke received positive integers \( s_1, ..., s_N \) as a birthday present. He wants to circle some of these integers, ensuring that if both \( s_i \) and \( s_j \) are circled, the product \( s_i \times s_j \) is not a perfect cube. The task is to find the maximum number of integers that Snuke can circle. Constraints: \( 1 \leq N \leq 10^5 \), \( 1 \leq s_i \leq 10^{10} \). The input is given in the format: \( N \), \( s_1, ..., s_N \). Output the maximum number of integers that Snuke can circle.

# Buggy version:
import sys
from subprocess import Popen, PIPE
from itertools import groupby
from collections import Counter

def main():
    sys.stdin.readline()
    S = sys.stdin.read()
    T = []
    inv_dict = {}
    Factors = Popen("factor " + S, stdout=PIPE).communicate()[0].split(b"\n")
    for factors in Factors:
        factors = map(int, factors.split()[1:])
        t = 1
        t_inv = 1
        for f, group in groupby(factors):
            n = len(list(group)) % 3
            if n == 1:
                t *= f
            elif n == 2:
                t_inv *= f
        t, t_inv = t * t_inv * t_inv, t * t * t_inv
        T.append(t)
        inv_dict[t] = t_inv

    counter_T = Counter(T)
    ans = 0
    for t, t_cnt in counter_T.items():
        if t == 1:
            ans += 1
            continue
        t_inv = inv_dict[t]
        t_inv_cnt = counter_T[t_inv]
        if t_cnt > t_inv_cnt or (t_cnt == t_inv_cnt and t > t_inv):
            ans += t_cnt
    print(ans)

main()


# Fixed version:
import sys
from subprocess import Popen, PIPE
from itertools import groupby
from collections import Counter

def main():
    sys.stdin.readline()
    S = sys.stdin.read().split()
    T = []
    inv_dict = {}
    Factors = Popen(["factor"] + S, stdout=PIPE).communicate()[0].split(b"\n")
    for factors in Factors[:-1]:
        factors = map(int, factors.split()[1:])
        t = 1
        t_inv = 1
        for f, group in groupby(factors):
            n = len(list(group)) % 3
            if n == 1:
                t *= f
            elif n == 2:
                t_inv *= f
        t, t_inv = t * t_inv * t_inv, t * t * t_inv
        T.append(t)
        inv_dict[t] = t_inv

    counter_T = Counter(T)
    ans = 0
    for t, t_cnt in counter_T.items():
        if t == 1:
            ans += 1
            continue
        t_inv = inv_dict[t]
        t_inv_cnt = counter_T[t_inv]
        if t_cnt > t_inv_cnt or (t_cnt == t_inv_cnt and t > t_inv):
            ans += t_cnt
    print(ans)

main()