Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
import math

input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())

def getlist():
    return list(map(int, input().split()))

n = getN() #22

dig_num = math.floor(math.log2(n))  # 5
sen_end = 2 ** (dig_num - 1) - 1  # 15

if 2 ** dig_num == n:
    print("No")
    sys.exit(0)
else:
    print("Yes")

for i in range(sen_end):
    print(i+1, i+2)  # 1-2, 2-3, ..., 14-15
    print(i+1+n, i+2+n)  # 23-24, 24-25, ..., 36-37

print(1, sen_end)

uni_end = n
if n % 2 == 0:
    uni_end -= 1  # 21

for i in range((uni_end - sen_end) // 2):  # 3 times
    print(1, sen_end + i * 2 + 1)  # 1-16
    print(1, sen_end + i * 2 + 2 + n)  # 1-39
    print(sen_end + i * 2 + 1 + n, sen_end + i * 2 + 2 + n)  # 38-39
    print(sen_end + i * 2 + 1, sen_end + i * 2 + 2)  # 16-17

if n % 2 == 0:
    one_count = 0
    for idx, digit in enumerate(bin(n)[2:]):
        # print(digit, one_count)
        if one_count == 0:
            # print(digit)
            if digit == "1":
                one_count += 1
        else:
            if digit == "1":
                one_goal = dig_num - idx  # second "1" from upper digit
                break

    print(n, 2**one_goal)
    print(2*n, n - 2**one_goal)


Fixed submission:
import sys
import math

input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())

def getlist():
    return list(map(int, input().split()))

n = getN() #22

dig_num = math.floor(math.log2(n + 1))  # 5
# print(dig_num)
sen_end = 2 ** (dig_num) - 1  # 15

if 2 ** (dig_num) == n or n == 1:
    print("No")
    sys.exit(0)
else:
    print("Yes")

for i in range(sen_end - 1):
    print(i+1, i+2)  # 1-2, 2-3, ..., 14-15
    print(i+1+n, i+2+n)  # 23-24, 24-25, ..., 36-37

print(n + 1, sen_end)

uni_end = n
if n % 2 == 0:
    uni_end -= 1  # 21

for i in range((uni_end - sen_end) // 2):  # 3 times
    print(1, sen_end + i * 2 + 1)  # 1-16
    print(1, sen_end + i * 2 + 2 + n)  # 1-39
    print(sen_end + i * 2 + 1 + n, sen_end + i * 2 + 2 + n)  # 38-39
    print(sen_end + i * 2 + 1, sen_end + i * 2 + 2)  # 16-17

if n % 2 == 0:
    one_count = 0
    for idx, digit in enumerate(bin(n)[2:]):
        # print(digit, one_count)
        if one_count == 0:
            # print(digit)
            if digit == "1":
                one_count += 1
        else:
            if digit == "1":
                one_goal = dig_num - idx  # second "1" from upper digit
                break

    if one_goal != 1:
        print(n, 2**one_goal)
        print(2*n, n - 2**one_goal)

    else:
        print(n, 2 ** one_goal)
        print(2 * n, 2 * n - 2 ** one_goal + 1)
Buggy python submission (verdict: Runtime Error):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import deque

n, k = getList()

vertex = [[] for i in range(n)]

for i in range(n-1):
    a, b = getList()
    vertex[a-1].append(b-1)
    vertex[b-1].append(a-1)

for i, v in enumerate(vertex):
    if len(v) == 1:
        root = i
        break

MOD = 1000000007

# initialize
q = deque([])
q.append(vertex[root][0])
q.append(-1)
visited = [0 for i in range(n)]
visited[root] = 1
ans = k
uni = 1
while(q):
    # print(q)
    nxt = q.popleft()

    if nxt == -1:
        uni = 2
        continue
    if visited[nxt] == 1:
        continue
    for edge in vertex[nxt]:
        if visited[edge] == 0:
            q.append(edge)
    q.append(-1)
    ans *= k - uni
    ans = ans % MOD
    uni += 1
    visited[nxt] = 1
    # print(nxt, ans)

print(ans)


Fixed submission:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import deque
from sys import exit

MOD = 1000000007

n, k = getList()
if n == 1:
    print(k % MOD)
    exit()
vertex = [[] for i in range(n)]

for i in range(n-1):
    a, b = getList()
    vertex[a-1].append(b-1)
    vertex[b-1].append(a-1)

for i, v in enumerate(vertex):
    if len(v) == 1:
        root = i
        break

MOD = 1000000007

# initialize
q = deque([])
q.append(vertex[root][0])
q.append(-1)
visited = [0 for i in range(n)]
visited[root] = 1
ans = k
uni = 1
while(q):
    # print(q)
    nxt = q.popleft()

    if nxt == -1:
        uni = 2
        continue
    if visited[nxt] == 1:
        continue
    for edge in vertex[nxt]:
        if visited[edge] == 0:
            q.append(edge)
    q.append(-1)
    ans *= k - uni
    ans = ans % MOD
    uni += 1
    visited[nxt] = 1
    # print(nxt, ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
s = input().strip()
c = Counter(s)
if c.values()[0] == 2 and c.values()[1] == 2:
  print("Yes")
else:
  print("No")

Fixed submission:
from collections import Counter
s = input().strip()
c = Counter(s)
fl = True
for v in c.values():
  if v != 2:
    print("No")
    fl = False
    break
if fl:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
def getN():
    return int(input())

def getMN():
    return list(map(int, input().split()))

def getlist():
    return list(map(int, input().split()))

def valid(steps):
    for i , x in enumerate(sorted(steps)):
        if i != x:
            return i - 1

    return len(steps) - 1
#
n = getN()
za = []
for i in range(n):
    za.append(getlist())
ans = 0
from collections import defaultdict
kumi = defaultdict(int)

for i, pa in enumerate(za):
    for j, pb in enumerate(za[i:]):
        xa, ya = pa
        xb, yb = pb
        dfx = xa - xb
        dfy = ya - yb

        diff = str(dfx) + str(dfy)
        kumi[diff] += 1

del kumi["00"]
print(n - max(list(kumi.values())))

# for p1 in za:
#     for p2 in za:
#         steps = []
#         if p1 == p2:
#             continue
#         xa, ya = p1
#         xb, yb = p2
#         dfx = xb - xa
#         dfy = yb - ya
#         if not (dfx or dfy):
#             continue
#         for p3 in za:
#             xc, yc = p3
#             if dfx:
#                 if (xc - xa) % dfx == 0:
#                     step = (xc - xa) // dfx
#                     if yc - ya == dfy * step:
#                         steps.append(step)
#
#             else:
#                 if xc == xa:
#                     if (yc - ya) % dfy == 0:
#                         steps.append((yc - ya) // dfy)
#         tmp = valid(steps)
#         print(p1, p2, tmp, steps)
#         if tmp > ans:
#             ans = tmp
#             if tmp == 3:
#                 print(p1, p2)
#
# print(n-ans)


Fixed submission:
def getN():
    return int(input())

def getMN():
    return list(map(int, input().split()))

def getlist():
    return list(map(int, input().split()))

def valid(steps):
    for i , x in enumerate(sorted(steps)):
        if i != x:
            return i - 1

    return len(steps) - 1
#
n = getN()
za = []
for i in range(n):
    za.append(getlist())
ans = 0
from collections import defaultdict
kumi = defaultdict(int)

for i, pa in enumerate(za):
    for j, pb in enumerate(za):
        xa, ya = pa
        xb, yb = pb
        dfx = xa - xb
        dfy = ya - yb

        diff = str(dfx) + str(dfy)
        kumi[diff] += 1

if n == 1:
    print(1)
    import sys;sys.exit()
del kumi["00"]
print(n - max(list(kumi.values())))

# for p1 in za:
#     for p2 in za:
#         steps = []
#         if p1 == p2:
#             continue
#         xa, ya = p1
#         xb, yb = p2
#         dfx = xb - xa
#         dfy = yb - ya
#         if not (dfx or dfy):
#             continue
#         for p3 in za:
#             xc, yc = p3
#             if dfx:
#                 if (xc - xa) % dfx == 0:
#                     step = (xc - xa) // dfx
#                     if yc - ya == dfy * step:
#                         steps.append(step)
#
#             else:
#                 if xc == xa:
#                     if (yc - ya) % dfy == 0:
#                         steps.append((yc - ya) // dfy)
#         tmp = valid(steps)
#         print(p1, p2, tmp, steps)
#         if tmp > ans:
#             ans = tmp
#             if tmp == 3:
#                 print(p1, p2)
#
# print(n-ans)
Buggy python submission (verdict: Time Limit Exceeded):
def getN():
    return int(input())

def getMN():
    return list(map(int, input().split()))

def getlist():
    return list(map(int, input().split()))

MOD = 1000000007
n,m = getlist()

broken = []
for i in range(m):
    broken.append(getN())

dp = [0 for i in range(n+1)]

dp[0] = 1
if 1 not in broken:
    dp[1] = 1

for i in range(2,n+1):
    if i not in broken:
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] = dp[i] % MOD

print(dp[n])

Fixed submission:
def getN():
    return int(input())

def getMN():
    return list(map(int, input().split()))

def getlist():
    return list(map(int, input().split()))

MOD = 1000000007
n,m = getlist()

broken = [0 for i in range(n+1)]
for i in range(m):
    broken[getN()] = 1

dp = [0 for i in range(n+1)]

dp[0] = 1
if broken[1] == 0:
    dp[1] = 1

for i in range(2,n+1):
    if broken[i] == 0:
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] = dp[i] % MOD

print(dp[n])
Buggy python submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int, input().split()))
tmp = 0
ans = 0
for num in nums:
  if num >= tmp:
    ans += 1
    tmp = num
  else:
    break
print(ans)
n = int(input())

Fixed submission:
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def main():
    n = getN()
    nums = getlist()
    hst = 0
    ans = 0
    for num in nums:
        if num >= hst:
            ans += 1
        hst = max(hst, num)

    print(ans)
if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Buggy python submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int, input().split()))
tmp = 0
ans = 0
for num in nums:
  if num >= tmp:
    ans += 1
   	tmp = num
  else:
    break
print(ans)

Fixed submission:
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def main():
    n = getN()
    nums = getlist()
    hst = 0
    ans = 0
    for num in nums:
        if num >= hst:
            ans += 1
        hst = max(hst, num)

    print(ans)
if __name__ == '__main__':
    main()

"""
9999
3

2916
"""
Buggy python submission (verdict: Runtime Error):
n = int(input())
buf = []
for i in range(5):
  buf.apend(int(input()))
  
print(n // min(buf) + 6 - (n % min(buf) == 0))
  

Fixed submission:
n = int(input())
buf = []
for i in range(5):
  buf.append(int(input()))
  
print(n // min(buf) + 5 - (n % min(buf) == 0))
Buggy python submission (verdict: Runtime Error):
n, q = list(map(int, input().split()))
s = input()
tmp = "g"
acc = []
for c in s:
  if tmp = "A":
    if c == "C":
      acc.append(acc[-1] + 1)
      tmp = "G"
    elif c == "A":
      tmp = "A"
    else;
		tmp = "G"
  else:
    if c == "A":
      tmp = "A"
      
for i in range(q):
  l,r = list(map(int, input().split()))
  print(acc[r-1] - acc[l-1])
    

Fixed submission:
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))


from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys

# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *


def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret

MOD = 998244353
def solve():
    n, q = getList()
    s = input().strip()
    acc = [0]
    tmp = 0
    pred = ""
    for c in s:
        if pred == "A" and c == "C":
            tmp += 1
        acc.append(tmp)
        pred = c

    for i in range(q):
        l, r = getList()
        print(acc[r] - acc[l])

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
a,b,k = list(map(int,input().split()))

tmp = 0
for i in range(200):
  if a% i == 0 and b % i == 0:
    tmp += 1
    if tmp == k:
      print(i)

Fixed submission:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b


a, b, k = list(map(int, input().split()))

div = []
tmp = 0
for i in range(1,200):
    if a % i == 0 and b % i == 0:
        div.append(i)
print(div[-k])
Buggy python submission (verdict: Runtime Error):
from collection import Counter
cnt = Counter()
s = input()
for c in s:
  cnt[c] += 1
  
print(min(cnt.keys()) * 2)

Fixed submission:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b


from collections import Counter

cnt = Counter()
s = input()
for c in s:
    cnt[c] += 1

if len(cnt.keys()) == 1:
    print(0)
else:
    print(min(cnt.values()) * 2)
Buggy python submission (verdict: Time Limit Exceeded):
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

from collections import Counter
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.size = [1 for i in range(n)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.size[x] += self.size[y]
            self.size[y] = 0

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)



n,m = getMN()

bridges = []

for i in range(m):
    a,b = getMN()
    bridges.append([a,b])

bridges.reverse()

uf = UnionFind(n)
answers = []
for query in bridges:
    x,y = query
    if not uf.same_check(x-1,y-1):
        uf.union(x-1,y-1)
    ans = 0
    for si in uf.size:
        ans += si * (n-si)
    answers.append(ans//2)

for fa in answers[:-1][::-1]:
    print(fa)
print(n*(n-1)//2)

Fixed submission:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

from collections import Counter
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.size = [1 for i in range(n)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.size[x] += self.size[y]
            self.size[y] = 0

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)



n,m = getMN()

bridges = []

for i in range(m):
    a,b = getMN()
    bridges.append([a,b])

bridges.reverse()

uf = UnionFind(n)
ans = n*(n-1)//2
answers = [ans]
for query in bridges:
    x,y = query
    if not uf.same_check(x-1,y-1):
        #print(uf.size,x,y)
        ans -= uf.size[uf.find(x-1)]*uf.size[uf.find(y-1)]
        #print(uf.find(x-1))
        uf.union(x-1,y-1)

    answers.append(ans)

for fa in answers[:-1][::-1]:
    print(fa)
Buggy python submission (verdict: Runtime Error):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
import math

nin,k = getNM()
nums = getList()
dnum = math.floor(math.log2(max(nums+[k]))) + 2

onum = [0] *dnum

for n in nums:
    for i,c in enumerate(str(bin(n))[2:][::-1]):
        if c == "1":
            onum[i] += 1


znum = [nin-x for x in onum]
ans = 0
def greedy(digit):
    tmp = 0
    for i in range(digit):
        tmp += 2**i * (max([onum[i], znum[i]]))

    return tmp

def search(digit, cur):
    if (onum[digit]>=znum[digit]):
       # print("o",digit)
        return 2**digit * onum[digit] + greedy(digit)
    if (cur < 2 ** digit):
        #print(digit)
        return 2 ** digit * onum[digit] + search(digit-1, cur)
    else:
        #print("e",digit)
        e1 = 2**digit * onum[digit] + greedy(digit)
        e2 = 2**digit * znum[digit] + search(digit-1, cur-2**digit)
        return max([e1,e2])
#print(znum)
#print(onum)
print(search(dnum-1, k))

Fixed submission:
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

class BIT():
    # A1 ... AnのBIT(1-indexed)
    def __init__(self, n):
        self.n = n
        self.BIT = [0] * (n + 2)

    # A1 ~ Aiまでの和 O(logN)
    def query(self, idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx & (-idx)
        return res_sum

    # Ai += x O(logN)
    def update(self, idx, x):
        # print(idx)
        while idx <= self.n:
            # print(idx)
            self.BIT[idx] += x
            idx += idx & (-idx)
        return

    def show(self):
        print(self.BIT)


def solve():
    n, k = getList()
    lis = getList()
    ans = 0
    bind = True
    dp = [-1 ,0]
    for rui in range(50, -1, -1):
        tmp = [-1 ,0]
        tgt = pow(2, rui)
        bit = tgt & k
        u, d = 0, 0
        for num in lis:
            if num & tgt == tgt:
                u += 1
            else:
                d += 1
        # print(u, d)
        if bit == 0:
            tmp[1] = dp[1] + tgt * u
            if dp[0] != -1:
                tmp[0] = dp[0] + tgt * max(u, d)
        else:
            if dp[0] != -1:
                tmp[0] = dp[0] + tgt * max(u, d)
            tmp[0] = max(dp[1] + tgt * u, tmp[0])
            tmp[1] = dp[1] + tgt * d
        dp = tmp
        # print(dp, bit, u, d)
    print(max(dp))

def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

m,n = getMN()
MOD = 1000000007
anums = getlist()
bnums = getlist()

anums.sort(reverse=True)
bnums.sort(reverse=True)
ans = 1
r_index = 0
d_index = 0
for i in range(m*n):
    ans = ans%MOD
    num = m * n - i
    #print("num = {}, ans = {}".format(num,ans))
    #print("r = {}, d = {}, i = {}".format(r_index, d_index,i))
    in_r = num in anums
    in_d = num in bnums
    if in_r:
        if in_d:
            r_index += 1
            d_index += 1
        else:
            ans = ans * d_index
            r_index += 1
    else:
        if in_d:
            ans = ans * r_index
            d_index += 1
        else:
            if r_index * d_index < i:
                import sys

                ans = 0
                break
            else:
                import sys
                #print("koko", i, file=sys.stderr)
                andayo = (ans * (r_index*d_index -i ))
                #ans = ans * (r_index*d_index -i )
                ans = andayo
                #print("ans", ans)
ans = ans%MOD

print(ans)

Fixed submission:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

m,n = getMN()
MOD = 1000000007
anums = getlist()
bnums = getlist()

anums.sort(reverse=True)
bnums.sort(reverse=True)
ans = 1
r_index = 0
d_index = 0
flag = True
for i in range(m*n):
    ans = ans % MOD
    num = m * n - i
    if r_index == m and d_index == n:
        ans *= num
        flag = False
    if flag:

        #print("num = {}, ans = {}".format(num,ans))
        #print("r = {}, d = {}, i = {}".format(r_index, d_index,i))
        in_r = num in anums
        in_d = num in bnums
        if in_r:
            if in_d:
                r_index += 1
                d_index += 1
            else:
                ans = ans * d_index
                r_index += 1
        else:
            if in_d:
                ans = ans * r_index
                d_index += 1
            else:
                if r_index * d_index < i:
                    import sys

                    ans = 0
                    flag = False
                else:
                    import sys
                    #print("koko", i, file=sys.stderr)
                    andayo = (ans * (r_index*d_index -i ))
                    #ans = ans * (r_index*d_index -i )
                    ans = andayo
                    #print("ans", ans)
ans = ans%MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
ans=0
for moji in s:
  if mojl == '2':
    ans += 1
    
print(ans)


Fixed submission:
s=input()
ans=0
for moji in s:
  if moji == '2':
    ans += 1
    
print(ans)