Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
MOD = 998244353
MAX = int(3e5 + 10)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def main():
    N, A, B, K = map(int, input().split())
    ans = 0
    # solve Ax + By = K
    for x in range(N+1):
        By = K - x * A
        if By >= 0 and By % B == 0:
            y = By // B
            tmp1 = FACT[N] * INV[x] * INV[N-x] % MOD
            tmp2 = FACT[N] * INV[y] * INV[N-y] % MOD
            ans = (ans + tmp1 * tmp2) % MOD
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
MOD = 998244353
MAX = int(3e5 + 1)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def main():
    N, A, B, K = map(int, input().split())
    ans = 0
    # solve Ax + By = K
    for x in range(N+1):
        By = K - x * A
        if By >= 0 and By % B == 0 and By <= B * N:
            y = By // B
            tmp1 = FACT[N] * INV[x] * INV[N-x] % MOD
            tmp2 = FACT[N] * INV[y] * INV[N-y] % MOD
            ans = (ans + tmp1 * tmp2) % MOD
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
MOD = 998244353
MAX = int(3e5 + 1)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def main():
    N, A, B, K = map(int, input().split())
    ans = 0
    for x in range(N+1):
        By = K - x * A
        if By >= 0 and By % B == 0:
            y = By // B
            tmp1 = FACT[N] * INV[x] * INV[N-x] % MOD
            tmp2 = FACT[N] * INV[y] * INV[N-y] % MOD
            ans = (ans + tmp1 * tmp2) % MOD
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
MOD = 998244353
MAX = int(3e5 + 1)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def main():
    N, A, B, K = map(int, input().split())
    ans = 0
    # solve Ax + By = K
    for x in range(N+1):
        By = K - x * A
        if By >= 0 and By % B == 0 and By <= B * N:
            y = By // B
            tmp1 = FACT[N] * INV[x] * INV[N-x] % MOD
            tmp2 = FACT[N] * INV[y] * INV[N-y] % MOD
            ans = (ans + tmp1 * tmp2) % MOD
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    _, _ = map(int, input().split())
    L = list(map(int, input().split()))
    R = list(map(int, input().split()))
    lcnt = [0] * 31
    rcnt = [0] * 31
    for l in L:
        lcnt[l-10] += 1
    for r in R:
        rcnt[r-10] += 1
    ans = sum(map(min, zip(lcnt, rcnt)))
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np

def main():
    A, B, C, K = map(int, input().split())
    if K == 0:
        print(A-B)
        return
    base = np.matrix([[0, 1, 1], [1, 0, 1], [1 ,1 ,0]])
    X = base ** K
    result = np.matrix([[A, B, C]]) \
        .dot(X) \
        .dot(np.matrix([[1], [-1], [0]]))
    ans = result[0, 0]
    if ans > 10**18:
        print("Unfair")
    else:
        print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    K = int(input())
    ranks = ["~"] * K
    for l in range(len(s)):
        for r in range(l+1, len(s)+1):
            target = s[l:r]
            if target in ranks:
                continue
            if target < ranks[K-1]:
                ranks[K-1] = target
            for i in range(K-1, 0, -1):
                if ranks[i] < ranks[i-1]:
                    tmp = ranks[i]
                    ranks[i] = ranks[i-1]
                    ranks[i-1] = tmp
    print(ranks[K-1])


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    s = input()
    K = int(input())
    ranks = ["~"] * K
    for l in range(len(s)):
        for r in range(l+1, min(len(s)+1, l+6)):
            target = s[l:r]
            if target in ranks:
                continue
            if target < ranks[K-1]:
                ranks[K-1] = target
            for i in range(K-1, 0, -1):
                if ranks[i] < ranks[i-1]:
                    tmp = ranks[i]
                    ranks[i] = ranks[i-1]
                    ranks[i-1] = tmp
    print(ranks[K-1])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    points = []
    for _ in range(N):
        x, y = map(int, input().split())
        points.append((x, y, "r"))
    for _ in range(N):
        x, y = map(int, input().split())
        points.append((x, y, "b"))
    points.sort(lambda x: x[0])
    singles = []
    retval = 0
    for p in points:
        x, y, c = p
        if c == "r":
            singles.append(y)
        if c == "b":
            maximum = (-1, -1)
            for i, v in enumerate(singles):
                if v < y and v > maximum[1]:
                    maximum = (i, v)
            if maximum[0] != -1:
                retval += 1
                singles.pop(maximum[0])
    print(retval)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = int(input())
    points = []
    for _ in range(N):
        x, y = map(int, input().split())
        points.append((x, y, "r"))
    for _ in range(N):
        x, y = map(int, input().split())
        points.append((x, y, "b"))
    points.sort(lambda x: x[0])
    singles = []
    retval = 0
    for p in points:
        x, y, c = p
        if c == "r":
            singles.append(y)
        if c == "b":
            maximum = (-1, -1)
            for i, v in enumerate(singles):
                if v < y and v > maximum[1]:
                    maximum = (i, v)
            if maximum[0] != -1:
                retval += 1
                singles.pop(maximum[0])
    print(retval)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    mask = 1
    target = 1
    ans = 0
    for _ in range(29):
        C = [b & mask for b in B]
        C.sort()
        cnt = 0
        for a in A:
            a = a & mask
            idx1 = bisect_left(C, target*1-a)
            idx2 = bisect_left(C, target*2-a)
            idx3 = bisect_left(C, target*3-a)
            cnt += (N - idx3) + (idx2 - idx1)
        ans += target * (cnt % 2)
        mask <<= 1
        mask |= 1
        target <<= 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from bisect import bisect_left


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    mask = 1
    target = 1
    ans = 0
    for _ in range(29):
        AA = sorted([a & mask for a in A], reverse=True)
        BB = sorted([b & mask for b in B])
        cnt = 0
        idx1 = 0  # idx of target*1-a
        idx2 = 0  # idx of target*2-a
        idx3 = 0  # idx of target*3-a
        for a in AA:
            while idx1 < N and a+BB[idx1] < target*1:
                idx1 += 1
            while idx2 < N and a+BB[idx2] < target*2:
                idx2 += 1
            while idx3 < N and a+BB[idx3] < target*3:
                idx3 += 1
            cnt += (N - idx3) + (idx2 - idx1)
        ans += target * (cnt % 2)
        mask <<= 1
        mask |= 1
        target <<= 1
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def query(S):
    print(S)
    sys.stdout.flush()
    return input()


def main():
    N = int(input())
    base = query(0)
    if base == "Vacant":
        return
    lo = 1
    hi = N-1
    while lo < hi:
        mid = (lo+hi) // 2
        ans = query(mid)
        if ans == "Vacant":
            return
        if (mid % 2 == 0 and ans == base) or \
           (mid % 2 == 1 and ans != base):
            lo = mid + 1
        else:
            hi = mid


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def query(S):
    print(S)
    sys.stdout.flush()
    return input()


def main():
    N = int(input())
    base = query(0)
    if base == "Vacant":
        return
    lo = 1
    hi = N-1
    while lo < hi:
        mid = (lo+hi) // 2
        ans = query(mid)
        if ans == "Vacant":
            return
        if (mid % 2 == 0 and ans == base) or \
           (mid % 2 == 1 and ans != base):
            lo = mid + 1
        else:
            hi = mid
    query(lo)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def query(S):
    print(S)
    sys.stdout.flush()
    return input()


def main():
    N = int(input())
    base = query(0)
    lo = 1
    hi = N-1
    while lo < hi:
        mid = (lo+hi) // 2
        ans = query(mid)
        if ans == "Vacant":
            return
        if (mid % 2 == 0 and ans == base) or \
           (mid % 2 == 1 and ans != base):
            lo = mid + 1
        else:
            hi = mid


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def query(S):
    print(S)
    sys.stdout.flush()
    return input()


def main():
    N = int(input())
    base = query(0)
    if base == "Vacant":
        return
    lo = 1
    hi = N-1
    while lo < hi:
        mid = (lo+hi) // 2
        ans = query(mid)
        if ans == "Vacant":
            return
        if (mid % 2 == 0 and ans == base) or \
           (mid % 2 == 1 and ans != base):
            lo = mid + 1
        else:
            hi = mid
    query(lo)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def warshall_floyd(paths, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                paths[i][j] = min(paths[i][j], paths[i][k] + paths[k][j])


def iter_patterns(l):
    if len(l) == 1:
        return [l]
    patterns = []
    for i in range(len(l)):
        patterns += [[l[i]] + p for p in iter_patterns(l[:i] + l[i+1:])]
    return patterns


def main():
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    paths = [[float("inf")] * N for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        paths[A-1][B-1] = C
        paths[B-1][A-1] = C
    for i in range(N):
        paths[i][i] = 0
    warshall_floyd(paths, N)
    retval = float("inf")
    for p in iter_patterns(r):
        dist = 0
        for i in range(R-1):
            dist += paths[p[i]-1][p[i+1]-1]
        retval = min(retval, dist)
    print(retval)


if __name__ == "__main__":
    main()


Fixed submission:
def warshall_floyd(paths, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                paths[i][j] = min(paths[i][j], paths[i][k] + paths[k][j])


def iter_patterns(l):
    if len(l) == 1:
        return [l]
    patterns = []
    for i in range(len(l)):
        patterns += [[l[i]] + p for p in iter_patterns(l[:i] + l[i+1:])]
    return patterns


def main():
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    paths = [[float("inf")] * N for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        paths[A-1][B-1] = C
        paths[B-1][A-1] = C
    for i in range(N):
        paths[i][i] = 0
    warshall_floyd(paths, N)
    retval = float("inf")
    for p in iter_patterns(r):
        dist = 0
        for i in range(R-1):
            dist += paths[p[i]-1][p[i+1]-1]
        retval = min(retval, dist)
    print(retval)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = input().split()
    ans = A[0]
    for i in range(1, N):
        ans = (ans + " " + A[i])[::-1]
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque


def main():
    N = int(input())
    A = list(map(int, input().split()))
    q = deque()
    for i in range(N):
        if (N-i) % 2 == 1:
            q.appendleft(A[i])
        else:
            q.append(A[i])
    print(" ".join(map(str, q)))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N, M = map(int, input().split())
    cnt = [0] * N
    for _ in range(N):
        a, b = map(int, input().split())
        cnt[a-1] += 1
        cnt[b-1] += 1
    for i in range(N):
        if cnt[i] % 2 == 1:
            print("NO")
            return
    print("YES")


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, M = map(int, input().split())
    cnt = [0] * N
    for _ in range(M):
        a, b = map(int, input().split())
        cnt[a-1] += 1
        cnt[b-1] += 1
    for i in range(N):
        if cnt[i] % 2 == 1:
            print("NO")
            return
    print("YES")


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from collections import deque


def remove(adj, a):
    for nxt in adj[a]:
        adj[nxt].remove(a)


def main():
    N, M = map(int, input().split())
    adj = [set() for _ in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split())
        adj[a].add(b)
        adj[b].add(a)
    ans = deque([a, b])
    remove(adj, a)
    remove(adj, b)
    first = a
    while len(adj[first]):
        nxt = list(adj[first])[0]
        ans.appendleft(nxt)
        remove(adj, nxt)
        first = nxt
    remove(adj, first)
    last = b
    for a in ans:
        if a in adj[last]:
            adj[last].remove(a)
    while len(adj[last]):
        nxt = list(adj[last])[0]
        ans.append(nxt)
        remove(adj, nxt)
        last = nxt
    print(len(ans))
    print(*ans)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque


def remove(adj, a):
    for nxt in adj[a]:
        adj[nxt].remove(a)


def main():
    N, M = map(int, input().split())
    adj = [set() for _ in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split())
        adj[a].add(b)
        adj[b].add(a)
    ans = deque([a, b])
    remove(adj, b)
    remove(adj, a)
    first = a
    last = b
    while len(adj[first]):
        nxt = list(adj[first])[0]
        ans.appendleft(nxt)
        remove(adj, nxt)
        first = nxt
    remove(adj, first)
    for a in ans:
        if a in adj[last]:
            adj[last].remove(a)
    while len(adj[last]):
        nxt = list(adj[last])[0]
        ans.append(nxt)
        remove(adj, nxt)
        last = nxt
    print(len(ans))
    print(*ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    K, S = map(int, input().split())
    cnt = 0
    for x in range(K+1):
        for y in range(K+1):
            for z in range(K+1):
                if x + y + z == S:
                    cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    K, S = map(int, input().split())
    cnt = 0
    for x in range(K+1):
        for y in range(K+1):
            z = S - x - y
            if 0 <= z and z <= K:
                cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    K = int(input())
    a = ord("a")
    code = [ord(c) - a for c in s]
    for i in range(len(s)):
        x = 26 - code[i] % 26
        if x <= K:
            code[i] = 0
            K -= x
    code[-1] = code[-1] + K % 26
    ans = ""
    for x in code:
        ans += chr(a + x)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    s = input()
    K = int(input())
    a = ord("a")
    code = [ord(c) - a for c in s]
    for i in range(len(s)):
        x = (26 - code[i]) % 26
        if x <= K:
            code[i] = 0
            K -= x
    code[-1] = code[-1] + K % 26
    ans = "".join([chr(a + x) for x in code])
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    K = int(input())
    code = [ord(c) - ord("a") for c in s]
    for i in range(len(s)):
        a = code[i]
        x = 26 - a % 26
        if x <= K:
            code[i] = 0
            K -= x
    code[-1] = code[-1] + K % 26
    ans = ""
    for c in code:
        ans += chr(ord("a") + c)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    s = input()
    K = int(input())
    a = ord("a")
    code = [ord(c) - a for c in s]
    for i in range(len(s)):
        x = (26 - code[i]) % 26
        if x <= K:
            code[i] = 0
            K -= x
    code[-1] = code[-1] + K % 26
    ans = "".join([chr(a + x) for x in code])
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    C = LS()

    j = N-1
    cnt = 0
    # print(C)
    for i in range(N):
        if i >= j: break
        ci = C[i]
        if ci == 'W':
            # change
            # print(i, j)
            for k in range(j, i, -1):
                ck = C[k]
                if ck == 'R':
                    # print(i, j)
                    C[i], C[k] = ck, ci
                    cnt += 1
                    j = k-1
                    break
        # print(C)
    print(cnt)


if __name__ == '__main__':
    solve()


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    C = LS()

    j = N-1
    cnt = 0
    # print(C)
    for i in range(N):
        if i >= j: break
        ci = C[i]
        if ci == 'W':
            # change
            # print(i, j)
            for k in range(j, i, -1):
                j = k-1
                ck = C[k]
                if ck == 'R':
                    # print(i, j)
                    # C[i], C[k] = ck, ci
                    cnt += 1
                    break

    # print(C)
    print(cnt)


if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, K = MI()
    A = LI()

    B = [1] * N
    B[0] = A[0]
    for i in range(1, N):
        B[i] = B[i-1] * A[i]
    # print(B)

    B = [1] + B

    for i in range(K+1, N+1):
        tmp = B[i] / B[i-K]
        tmp2 = B[i-1] / B[i-1-K]
        # print(tmp, tmp2)
        if tmp > tmp2:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    solve()


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, K = MI()
    A = LI()

    for i in range(K-1, N-1):
        b = A[i-K+1]
        f = A[i+1]
        if f > b:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    solve()