Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=input()
for i in range(3):
  if n[i]=='1':
    n[i]='9'
  if n[i]=='9':
    n[i]='1'
print(n)

Fixed submission:
n=list(input())
for i in range(3):
  if n[i]=='1':
    n[i]='9'
  elif n[i]=='9':
    n[i]='1'
ans=''
for i in range(3):
  ans+=n[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=input()

ans = "Yes"

for i in range(len(s)-1):
    if s[i]!=t[i]:
        s_same = s[i+1:].find(s[i])
        t_same = t[i+1:].find(t[i])
        if s_same!=t_same:
            ans="No"
            break
print(ans)

Fixed submission:
s=input()
t=input()

ans = "Yes"
_dict = {}

for i in range(len(s)):
    if s[i] not in _dict:
        _dict[s[i]]=t[i]
    elif s[i] in _dict:
        if t[i] != _dict[s[i]]:
            ans="No"
            break

_dict = {}
for i in range(len(s)):
    if t[i] not in _dict:
        _dict[t[i]]=s[i]
    elif t[i] in _dict:
        if s[i] != _dict[t[i]]:
            ans="No"
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

N,X = (int(i) for i in input().split()) 
x = [abs(int(i)-X) for i in input().split()]

ans = x[0]
for i in range(N):
	ans = math.gcd(ans, x[i])
	if ans == 1:
		break

print(ans)

Fixed submission:
from fractions import gcd

N,X = (int(i) for i in input().split()) 
x = [abs(int(i)-X) for i in input().split()]

ans = x[0]
for i in range(N):
	ans = gcd(ans, x[i])
	if ans == 1:
		break

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

N,M,Q=map(int,input().split())

Goal=[defaultdict(int) for _ in range(N)]
for i in range(M):
    L,R=map(int,input().split())
    Goal[L-1][R-1]+=1

Accumlate = [[0]*(N+1) for i in range(N)]
for g in range(N):
    for l in range(N):
        Accumlate[g][l+1]+=Accumlate[g][l]+Goal[g][l]

ans_list=[]
for l in range(Q):
    ans=0
    L,R=map(int,input().split())
    for l in range(L-1,R):
        ans+=Accumlate[l][R]-Accumlate[l][L-1]
    ans_list.append(ans)

for m in range(Q):
    print(ans_list[m])

Fixed submission:
a,b=map(int,input().split())
print((a-1)*(b-1))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N,M,Q=map(int,input().split())

Goal=[defaultdict(int) for _ in range(N)]
for i in range(M):
    L,R=map(int,input().split())
    Goal[L-1][R-1]+=1

Accumlate = [[0]*(N+1) for i in range(N)]
for g in range(N):
    for l in range(N):
        Accumlate[g][l+1]+=Accumlate[g][l]+Goal[g][l]

ans_list=[]
for l in range(Q):
    ans=0
    L,R=map(int,input().split())
    for l in range(L-1,R):
        ans+=Accumlate[l][R]-Accumlate[l][L-1]
    ans_list.append(ans)

for m in range(Q):
    print(ans_list[m])

Fixed submission:
from collections import defaultdict

N,M,Q=map(int,input().split())

Goal=[defaultdict(int) for _ in range(N)]
for i in range(M):
    L,R=map(int,input().split())
    Goal[L-1][R-1]+=1

Accumlate = [[0]*(N+1) for i in range(N)]
for g in range(N):
    for l in range(N):
        Accumlate[g][l+1]+=Accumlate[g][l]+Goal[g][l]

ans_list=[]
for l in range(Q):
    ans=0
    L,R=map(int,input().split())
    for l in range(L-1,R):
        ans+=Accumlate[l][R]-Accumlate[l][L-1]
    ans_list.append(ans)

for m in range(Q):
    print(ans_list[m])

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

N,M,Q=map(int,input().split())

Goal=[[] for _ in range(N)]
for i in range(M):
    L,R=map(int,input().split())
    Goal[L-1].append(R-1)

for i in range(1,N)[::-1]:
    Goal[i-1]+=Goal[i]

for i in range(N):
    Goal[i].sort()

ans=[]
for g in range(Q):
    p,q=map(int,input().split())
    ans.append(bisect.bisect_right(Goal[p-1],q-1))

for l in range(Q):
    print(ans[l])

Fixed submission:
from collections import defaultdict

N,M,Q=map(int,input().split())

Goal=[defaultdict(int) for _ in range(N)]
for i in range(M):
    L,R=map(int,input().split())
    Goal[L-1][R-1]+=1

Accumlate = [[0]*(N+1) for i in range(N)]
for g in range(N):
    for l in range(N):
        Accumlate[g][l+1]+=Accumlate[g][l]+Goal[g][l]

ans_list=[]
for l in range(Q):
    ans=0
    L,R=map(int,input().split())
    for l in range(L-1,R):
        ans+=Accumlate[l][R]-Accumlate[l][L-1]
    ans_list.append(ans)

for m in range(Q):
    print(ans_list[m])

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

N,M,Q=map(int,input().split())

Goal=[[] for _ in range(N)]
for i in range(M):
    L,R=map(int,input().split())
    Goal[L-1].append(R-1)

for i in range(1,N)[::-1]:
    Goal[i-1]+=Goal[i]

for i in range(N):
    Goal[i].sort()

ans=[]
for g in range(Q):
    p,q=map(int,input().split())
    ans.append(bisect.bisect_right(Goal[p-1],q-1))

for l in range(Q):
    print(ans[l])

Fixed submission:
from collections import defaultdict

N,M,Q=map(int,input().split())

Goal=[defaultdict(int) for _ in range(N)]
for i in range(M):
    L,R=map(int,input().split())
    Goal[L-1][R-1]+=1

Accumlate = [[0]*(N+1) for i in range(N)]
for g in range(N):
    for l in range(N):
        Accumlate[g][l+1]+=Accumlate[g][l]+Goal[g][l]

ans_list=[]
for l in range(Q):
    ans=0
    L,R=map(int,input().split())
    for l in range(L-1,R):
        ans+=Accumlate[l][R]-Accumlate[l][L-1]
    ans_list.append(ans)

for m in range(Q):
    print(ans_list[m])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

aPlus = 0
bPlus = 0

for i in range(n):
    if b[i] > a[i]:
        if (b[i]-a[i]) % 2 == 0:
            aPlus += b[i]-a[i]
            bPlus += (b[i]-a[i])//2
        else:
            print("No")
            exit()
    else:
        aPlus += 2*(a[i]-b[i])
        bPlus += a[i]-b[i]

if aPlus//bPlus==2:
    print("Yes")
else:
    print("No")


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

aPlus=0
bPlus=0

for i in range(n):
    if a[i]>b[i]:
        aPlus+=(a[i]-b[i])
    elif a[i]<b[i]:
        if (b[i]-a[i])%2==0:
            bPlus+=(b[i]-a[i])//2
        else:
            aPlus+=1
            bPlus+=(b[i]+1-a[i])//2

if aPlus<=bPlus:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import queue
N,M=map(int,input().split())
s=[[]for i in range(N)]
used=set()
for i in range(M):
    L,R,D=map(int,input().split())
    s[L-1].append((R-1,D))
    s[R-1].append((L-1,-D))
    used.add(L-1)
    used.add(R-1)

q=queue.Queue()
dist=[-1]*N

while used!=set():
    a=used.pop()
    q.put(a)
    dist[a]=0
    while not q.empty():
        From=q.get()
        if From in used:
            used.remove(From)
        for l in s[From]:
            To,w=l
            if dist[To]==-1:
                dist[To]=dist[From]+w
                q.put(To)
            else:
                if dist[To]!=dist[From]+w:
                    print("No")
                    exit()
print("Yes")


Fixed submission:
import queue
N,M=map(int,input().split())
s=[[]for i in range(N)]
for i in range(M):
    L,R,D=map(int,input().split())
    s[L-1].append((R-1,D))
    s[R-1].append((L-1,-D))

q=queue.Queue()
dist=[None]*N

for i in range(N):
    if dist[i]==None:
        dist[i]=0
        q.put(i)
    while not q.empty():
        From=q.get()
        for l in s[From]:
            To,w=l
            if dist[To]==None:
                dist[To]=dist[From]+w
                q.put(To)
            else:
                if dist[To]!=dist[From]+w:
                    print("No")
                    exit()
print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
import queue
N,M=map(int,input().split())
s=[[]for i in range(N)]
used=set()
for i in range(M):
    L,R,D=map(int,input().split())
    s[L-1].append((R-1,D))
    s[R-1].append((L-1,-D))
    used.add(L-1)
    used.add(R-1)

q=queue.Queue()
dist=[-1]*N
dist[0]=0

while used!=set():
    q.put(used.pop())
    while not q.empty():
        From=q.get()
        if From in used:
            used.remove(From)
        for l in s[From]:
            To,w=l
            if dist[To]==-1:
                dist[To]=dist[From]+w
                q.put(To)
            else:
                if dist[To]!=dist[From]+w:
                    print("No")
                    exit()
print("Yes")

Fixed submission:
import queue
N,M=map(int,input().split())
s=[[]for i in range(N)]
for i in range(M):
    L,R,D=map(int,input().split())
    s[L-1].append((R-1,D))
    s[R-1].append((L-1,-D))

q=queue.Queue()
dist=[None]*N

for i in range(N):
    if dist[i]==None:
        dist[i]=0
        q.put(i)
    while not q.empty():
        From=q.get()
        for l in s[From]:
            To,w=l
            if dist[To]==None:
                dist[To]=dist[From]+w
                q.put(To)
            else:
                if dist[To]!=dist[From]+w:
                    print("No")
                    exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
import math
import bisect
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

prime=set([2])
for i in range(3,100001):
    if i%2!=0 and is_prime(i):
        prime.add(i)

sim_prime=[]
for p in prime:
    if (p+1)//2 in prime:
        sim_prime.append(p)
sim_prime.sort()


q=int(input())
ans_list=[]
for i in range(q):
    l,r=map(int,input().split())
    l_idx=bisect.bisect_left(sim_prime,l)
    r_idx=bisect.bisect_left(sim_prime,r)
    if sim_prime[r_idx]==r:
        r_idx+=1
    ans_list.append(r_idx-l_idx)

for g in range(len(ans_list)):
    print(ans_list[g])

Fixed submission:
import math
import bisect
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

prime=set([2])
for i in range(3,100001):
    if i%2!=0 and is_prime(i):
        prime.add(i)

sim_prime=[]
for p in prime:
    if (p+1)//2 in prime:
        sim_prime.append(p)
sim_prime.sort()


q=int(input())
ans_list=[]
for i in range(q):
    l,r=map(int,input().split())
    l_idx=bisect.bisect_left(sim_prime,l)
    r_idx=bisect.bisect_left(sim_prime,r)
    if sim_prime[min(r_idx,len(sim_prime)-1)]==r:
        r_idx+=1
    ans_list.append(r_idx-l_idx)

for g in range(len(ans_list)):
    print(ans_list[g])
Buggy python submission (verdict: Runtime Error):
import bisect
from itertools import accumulate
from operator import add

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

a.sort()
b.sort()
c.sort()

AonB=[]
BonC=[]
ans=0
for i in range(n):
    AonB.append(bisect.bisect_left(a,b[i]))

AonB=list(accumulate(AonB,add))

ans=0
for g in range(n):
    search=bisect.bisect_left(b,c[g])-1
    if search>=0:
        ans+=AonB[search]

print(ans)

Fixed submission:
import bisect
from itertools import accumulate
from operator import add

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

a.sort()
b.sort()
c.sort()

AonB=[]
BonC=[]
ans=0
for i in range(n):
    AonB.append(bisect.bisect_left(a,b[i]))

AonB=list(accumulate(AonB,add))

ans=0
for g in range(n):
    search=bisect.bisect_left(b,c[g])-1
    if search>=0:
        ans+=AonB[search]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
    b.append(a[i])
    b=b[::-1]
print(*b)

Fixed submission:
from collections import deque

n=int(input())
a=list(map(int,input().split()))

b=deque()
for i in range(n):
    if (i+n)%2!=0:
        b.appendleft(a[i])
    else:
        b.append(a[i])
print(*b)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
for i in range(m):
    for g in range(m):
        d=[]
        for l in range(m):
            d.append(a[l+i][g:g+m])
        if d==b:
            print("Yes")
            exit()
            
print("No")

Fixed submission:
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
for i in range(n-m+1):
    for g in range(n-m+1):
        d=[]
        for l in range(m):
            d.append(a[l+i][g:g+m])
        if d==b:
            print("Yes")
            exit()
print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
before = [0, 0]
for i in range(n):
    t, a = map(int, input().split())
    if t >= before[0] and a >= before[1]:
        before = [t, a]
    else:
        i=2
        _t=t
        _a=a
        while _t<before[0] or _a<before[1]:
            _t=t*i
            _a=a*i
            i+=1
        before=[_t,_a]
print(sum(before))

Fixed submission:
n = int(input())
before = [0, 0]
for i in range(n):
    t, a = map(int, input().split())
    if t >= before[0] and a >= before[1]:
        before = [t, a]
    else:
        mul = max((before[0]-1)//t+1, (before[1]-1)//a+1)
        before = [t*mul, a*mul]

print(sum(before))
Buggy python submission (verdict: Runtime Error):
from heapq import heapify, heappop, heappush
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
input = sys.stdin.readline

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1
S = [input().rstrip() for _ in [0]*H]
print(S[0])

INF = 10**10
D = [[INF]*W for _ in [0]*H]
used = set()

q = []
heappush(q, (0, Ch*W+Cw))

dirs = [(-1, 0), (1, 0), (0, 1), (0, -1)]
wps = [
    [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -1), (-1, 1)],
    [(2, 2), (2, -1), (2, 0), (2, 1), (2, 2), (1, -1), (1, 1)],
    [(-2, 2), (-1, 2), (0, 2), (1, 2), (2, 2), (-1, 1), (1, 1)],
    [(-2, -2), (-1, -2), (0, -2), (1, -2), (2, -2), (-1, -1), (1, -1)]
]

while q:
    d, ij = heappop(q)
    i, j = divmod(ij, W)
    if D[i][j] > d:
        D[i][j] = d
    else:
        continue
    if i == Dh and j == Dw:
        break

    for k, (di, dj) in enumerate(dirs):
        _i = i + di
        _j = j + dj
        if 0 <= _i < H and 0 <= _j < W:
            if S[_i][_j] == '.':
                if D[_i][_j] <= d:
                    continue
                heappush(q, (d, _i*W+ _j))
            else:
                for di, dj in wps[k]:
                    _i = i + di
                    _j = j + dj
                    if 0 <= _i < H and 0 <= _j < W and S[_i][_j] == '.':
                        if D[_i][_j] <= d+1:
                            continue
                        heappush(q, (d+1, _i*W+_j))

ans = D[Dh][Dw]
print(ans if ans < INF else -1)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readlines = sys.stdin.buffer.readlines
input = sys.stdin.buffer.readline
H, W, M = map(int, input().split())

HH = [0]*H
WW = [0]*W
d = set()
for line in readlines():
    h, w = map(int, line.split())
    h -= 1
    w -= 1
    d.add((h, w))
    HH[h] += 1
    WW[w] += 1

m = -1
argm = []
for i, c in enumerate(HH):
    if c > m:
        m = c
        argm = [i]
    elif c == m:
        argm.append(i)

mH = m
aH = argm

m = -1
argm = []
for i, c in enumerate(WW):
    if c > m:
        m = c
        argm = [i]
    elif c == m:
        argm.append(i)

mW = m
aW = argm

ans = mH + mW
for h in aH:
    for w in aW:
        if (h, w) not in d:
            break
    else:
        continue
    break
else:
    ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readlines = sys.stdin.buffer.readlines
input = sys.stdin.buffer.readline
H, W, K = map(int, input().split())
B = [[0]*W for _ in [0]*H]

for _ in range(K):
    r, c, v = map(int, input().split())
    B[r-1][c-1] = v

dp = [[[0]*4 for _ in [0]*(W+1)] for _ in [0]*(H+1)]

for i in range(H):
    for j in range(W):
        v = B[i][j]
        if v:
            dp[i+1][j+1][0] = max(dp[i+1][j][0], max(dp[i][j+1]))

            dp[i+1][j+1][1] = max(dp[i+1][j][1],
                                  max(dp[i][j+1])+v, dp[i+1][j][0]+v)

            dp[i+1][j+1][2] = max(dp[i+1][j][2], dp[i+1][j][1]+v)

            dp[i+1][j+1][3] = max(dp[i+1][j][3], dp[i+1][j][2]+v)
        else:
            dp[i+1][j+1][0] = max(dp[i+1][j][0], max(dp[i][j+1]))
            dp[i+1][j+1][1] = dp[i+1][j][1]
            dp[i+1][j+1][2] = dp[i+1][j][2]
            dp[i+1][j+1][3] = dp[i+1][j][3]
print(max(dp[-1][-1]))


Fixed submission:
import sys
read = sys.stdin.buffer.read
readlines = sys.stdin.buffer.readlines
input = sys.stdin.buffer.readline
H, W, K = map(int, input().split())
B = {}

for _ in range(K):
    r, c, v = map(int, input().split())
    B[(r-1,c-1)] = v

dp = [[0]*(W+1) for _ in range(4)]
 
for i in range(H):
    for j in range(W):
        if (i, j) in B:
            v = B[(i, j)]
            dp[0][j+1] = max(dp[0][j], dp[0][j+1], dp[1][j+1], dp[2][j+1], dp[3][j+1])
            dp[1][j+1] = max(dp[1][j], dp[0][j+1]+v)
            dp[2][j+1] = max(dp[2][j], dp[1][j]+v)
            dp[3][j+1] = max(dp[3][j], dp[2][j]+v)
        else:
            dp[0][j+1] = max(dp[0][j], dp[0][j+1], dp[1][j+1], dp[2][j+1], dp[3][j+1])
            dp[1][j+1] = dp[1][j]
            dp[2][j+1] = dp[2][j]
            dp[3][j+1] = dp[3][j]
print(max(dp[i][-1] for i in range(4)))
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, Q = map(int, input().split())
    *C, = map(int, input().split())

    last = [-1]*(N+1)
    P = []
    for i, c in enumerate(C):
        if last[c] != -1:
            P.append((last[c], i+1))
        last[c] = i+1

    queries = []
    for i in range(Q):
        l, r = map(int, input().split())
        queries.append((l, r, i))

    P.sort()
    queries.sort(reverse=True)

    class BIT():
        def __init__(self, n, x=1):
            self.n = n
            self.T = [0]*(n+1)

        def add(self, i, x):
            while i <= self.n:
                self.T[i] += x
                i += i & -i

        def sum(self, i):
            ret = 0
            while i:
                ret += self.T[i]
                i -= i & -i
            return ret

    bit = BIT(N)
    ans = [0]*Q
    for l, r, i in queries:
        while P and P[-1][0] >= l:
            cl, cr = P.pop()
            bit.add(cr, 1)
        ans[i] = r-l+1-bit.sum(r)

    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()


Fixed submission:
N = int(input())

if N >= 30:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
from collections import Counter

def main():
    N = int(input())
    *A, = map(int, input().split())
    A.sort()
    C = Counter(A)

    MAX = 2000005
    T = [0]*MAX

    ans = 0
    for a in A:
        if T[a]:
            continue
        else:
            if C[a] == 1:
                ans += 1
            for i in range(2*a, MAX, a):
                T[i] += 1
    print(ans)

@jit()

if __name__ == '__main__':
    main()


Fixed submission:
*A, = map(int, input().split())

for i, a in enumerate(A):
    if a == 0:
        print(i+1)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
from heapq import heappop, heappush
import sys
input = sys.stdin.readline
H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(lambda x: int(x)-1, input().split())
S = [input()[:-1] for _ in [0]*H]

dirs = [(-1, 0), (0, -1), (0, 1), (1, 0)]

@lru_cache(None)
def f(x, y):
    return abs(x-x2)+abs(y-y2)

INF = 1<<30
D = [[INF]*W for _ in [0]*H]

q = []
heappush(q, (f(x1, x2), 0, x1, y1))
while q:
    h, d, x, y = heappop(q)
    if d >= D[x][y]:
        continue
    D[x][y] = d

    for sgn in (1, -1):   
        for dx in range(1, K+1):
            _x = x+dx*sgn
            if _x < 0 or _x >= H or S[_x][y] == '@':
                break
            if d+1 >= D[_x][y]:
                continue
            heappush(q, (d+f(_x, y), d+1, _x, y))

        for dy in range(1, K+1):
            _y = y+dy*sgn
            if _y < 0 or _y >= W or S[x][_y] == '@':
                break
            if d+1 >= D[x][_y]:
                continue
            heappush(q, (d+f(x, _y), d+1, x, _y))

ans = D[x2][y2]
print(-1 if ans == INF else ans)

Fixed submission:
from heapq import heappop, heappush
import sys
input = sys.stdin.readline
H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(lambda x: int(x)-1, input().split())
S = [input()[:-1] for _ in [0]*H]

def geth(x, y, z):
    return (x*W+y)*4+z

def push(x, y, z, d):
    h = geth(x, y, z)
    if D[h] <= d:
        return
    D[h] = d
    heappush(q, (d, h))

INF = 10**10
MAX = H*W*4
D = [INF]*MAX
dirs = [(-1, 0), (0, -1), (1, 0), (0, 1)]

q = []
for z in range(4):
    heappush(q, (0, geth(x1, y1, z)))

while q:
    d, h = heappop(q)
    z = h % 4
    x, y = divmod((h//4), W)

    if d > D[h]:
        continue
    D[h] = d

    for _z, (dx, dy) in enumerate(dirs):
        if _z == z:
            _x, _y = x+dx, y+dy
            if 0 <= _x < H and 0 <= _y < W and S[_x][_y] == '.':
                push(_x, _y, z, d+1)
        else:
            _h = geth(x, y, _z)
            _d = (d+K-1)//K*K
            push(x, y, _z, _d)

g = geth(x2, y2, 0)
ans = min(D[g:g+4])
if ans == INF:
    print(-1)
else:
    ans = (ans-1+K)//K
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())

*A, = map(int, input().split())

mod = 998244353

sumT = [0]*6005
sumT[0] = 1
sumT[A[0]] = 1

for a in A[1:]:
    for j in range(3001):
        sumT[j] *= 2

    for j in range(3000, -1, -1):
        sumT[j+a] += sumT[j] // 2
        sumT[j+a] %= mod
        sumT[j] %= mod

    sumT[0] += 1
    sumT[0] %= mod

    sumT[a] += 1
    sumT[a] %= mod


print(sumT[S] % mod)


Fixed submission:
N, S = map(int, input().split())

*A, = map(int, input().split())

mod = 998244353

sumT = [0]*6005
sumT[0] = 1
sumT[A[0]] = 1

for a in A[1:]:
    for j in range(3001):
        sumT[j] *= 2

    for j in range(3000, -1, -1):
        sumT[j+a] += sumT[j] // 2
        sumT[j+a] %= mod
        sumT[j] %= mod

    sumT[0] += 1
    sumT[0] %= mod

    sumT[a] += 1
    sumT[a] %= mod


print(sumT[S] % mod)
Buggy python submission (verdict: Runtime Error):
from math import gcd
from collections import Counter
N, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)

mod = 10**9 + 7


def modpow(a, n, mod):
    ret = 1
    while n:
        if n & 1:
            ret = ret * a % mod
        a = a * a % mod
        n >>= 1
    return ret


col = []
row = []
for a, b in A:
    g = gcd(abs(a), abs(b))
    a //= g
    b //= g

    if a < 0:
        a *= -1
        b *= -1

    if a >= 0 and b > 0:
        col.append((a, b))
    elif a > 0 and b <= 0:
        row.append((-b, a))


C = Counter(col)
D = Counter(row)
S = set(col) | set(row)

ans = 1
for s in S:
    if s in C:
        if s in D:
            mul = modpow(2, C[s], mod) + modpow(2, D[s], mod) - 1
        else:
            mul = modpow(2, C[s], mod)
    elif s in D:
        mul = modpow(2, D[s], mod)

    ans *= mul
    ans %= mod

ans -= 1
ans %= mod

print(ans)


Fixed submission:
from math import gcd
from collections import Counter
N, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)

mod = 10**9 + 7


def modpow(a, n, mod):
    ret = 1
    while n:
        if n & 1:
            ret = ret * a % mod
        a = a * a % mod
        n >>= 1
    return ret

col = []
row = []
zero = 0
for a, b in A:
    if a == b == 0:
        zero += 1
        continue
    if a == 0:
        col.append((1,0))
        continue
    elif b == 0:
        row.append((1,0))
        continue
    else:
        g = gcd(abs(a), abs(b))
        a //= g
        b //= g

    if a < 0:
        a *= -1
        b *= -1

    if b > 0:
        col.append((a, b))
    elif b < 0:
        row.append((-b, a))

C = Counter(col)
D = Counter(row)
S = set(col) | set(row)

ans = 1
for s in S:
    if s in C:
        if s in D:
            mul = modpow(2, C[s], mod) + modpow(2, D[s], mod) - 1
            mul %= mod
        else:
            mul = modpow(2, C[s], mod)
    elif s in D:
        mul = modpow(2, D[s], mod)

    ans *= mul
    ans %= mod

ans -= 1
ans += zero
ans %= mod

print(ans)