Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split())
w0, v0 = map(int, input().split())
X = [[] for _ in range(4)]
X[0].append(v0)
for _ in range(N-1):
    w, v = map(int, input().split())
    X[w-w0].append(v)

X = [[0] + sorted(x)[::-1] for x in X]
for i in range(4):
    for j in range(1, len(X[i])):
        X[i][j] += X[i][j-1]
ma = 0
for i in range(N+1):
    for j in range(N+1-i):
        for k in range(N+1-i-j):
            l = min(N-i-j-k, (W - (w0 * i + (w0+1) * j + (w0+2) * k)) // (w0+3))
            if l < 0: continue
            if i < len(X[0]) and j < len(X[1]) and k < len(X[2]) and l < len(X[3]):
                ma = max(ma, X[0][i] + X[1][j] + X[2][k] + X[3][l])
print(ma)

Fixed submission:
from itertools import accumulate as ac
t = 3099044504245996706400 # LCM(1..50)
N, A, B = map(int, input().split())
V = sorted([int(a) * t for a in input().split()])[::-1]
l, r = 0, 1<<200
while r - l > 1:
    m = (l+r) // 2
    if list(ac([v-m for v in V]))[A-1] >= 0:
        l = m
    else:
        r = m

fa = [1]
for i in range(1, 60):
    fa.append(fa[-1] * i)
C = lambda a, b: fa[a] // (fa[a-b] * fa[b])

print(l/t)
print(sum([C(V.count(V[i-1]), V[:i].count(V[i-1])) for i in range(A, B+1) if sum(V[:i]) == l * i]))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
A = [0 if a >= K else a for a in A]
X = [1] * N
Y = [1] * N
m = (1<<K*13) - 1
for i in range(N-1):
    X[i+1] = (X[i] | X[i] << 13 * A[i]) & m if A[i] else X[i]
for i in range(1, N)[::-1]:
    Y[i-1] = (Y[i] | Y[i] << 13 * A[i]) & m if A[i] else Y[i]

ans = N
for i in range(N):
    if A[i] == 0 or ((X[i] * Y[i] & m) >> 13 * (K - A[i])) & ((1 << 13 * A[i]) - 1):
        ans -= 1
print(ans)


Fixed submission:
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
A = [0 if a >= K else a for a in A]
X = [1] * N
Y = [1] * N
m = (1<<K*8) - 1
for i in range(N-1):
    X[i+1] = (X[i] | X[i] << 8 * A[i]) & m if A[i] else X[i]
for i in range(1, N)[::-1]:
    Y[i-1] = (Y[i] | Y[i] << 8 * A[i]) & m if A[i] else Y[i]

ans = N
for i in range(N):
    if A[i] == 0 or ((X[i] * Y[i] & m) >> 8 * (K - A[i])) & ((1 << 8 * A[i]) - 1):
        ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
A = [0 if a >= K else a for a in A]
X = [1] * N
Y = [1] * N
m = (1<<K*13) - 1
for i in range(N-1):
    X[i+1] = X[i] * ((1<<13*A[i]) + 1 if A[i] else 1) & m
for i in range(1, N)[::-1]:
    Y[i-1] = Y[i] * ((1<<13*A[i]) + 1 if A[i] else 1) & m

ans = N
for i in range(N):
    if A[i] == 0 or ((X[i] * Y[i] & m) >> 13 * (K - A[i])) & ((1 << 13 * A[i]) - 1):
        ans -= 1
print(ans)

Fixed submission:
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
A = [0 if a >= K else a for a in A]
X = [1] * N
Y = [1] * N
m = (1<<K*8) - 1
for i in range(N-1):
    X[i+1] = (X[i] | X[i] << 8 * A[i]) & m if A[i] else X[i]
for i in range(1, N)[::-1]:
    Y[i-1] = (Y[i] | Y[i] << 8 * A[i]) & m if A[i] else Y[i]

ans = N
for i in range(N):
    if A[i] == 0 or ((X[i] * Y[i] & m) >> 8 * (K - A[i])) & ((1 << 8 * A[i]) - 1):
        ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
A = [0 if a >= K else a for a in A]
X = [1] * N
Y = [1] * N
m = (1<<K*13) - 1
for i in range(N-1):
    X[i+1] = X[i] * ((1<<13*A[i]) + 1 if A[i] else 1) & m
for i in range(1, N)[::-1]:
    Y[i-1] = Y[i] * ((1<<13*A[i]) + 1 if A[i] else 1) & m

ans = N
for i in range(N):
    if A[i] == 0 or ((X[i] * Y[i] & m) >> 13 * (K - A[i])) & ((1 << 13 * A[i]) - 1):
        ans -= 1
print(ans)

Fixed submission:
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
A = [0 if a >= K else a for a in A]
X = [1] * N
Y = [1] * N
m = (1<<K*8) - 1
for i in range(N-1):
    X[i+1] = (X[i] | X[i] << 8 * A[i]) & m if A[i] else X[i]
for i in range(1, N)[::-1]:
    Y[i-1] = (Y[i] | Y[i] << 8 * A[i]) & m if A[i] else Y[i]

ans = N
for i in range(N):
    if A[i] == 0 or ((X[i] * Y[i] & m) >> 8 * (K - A[i])) & ((1 << 8 * A[i]) - 1):
        ans -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
X = [i for i in range(N)]
Y = []
def chk(a, b):
    print("?", a, b)
    return 1 if input() == "Y" else 0
while X:
    if not Y:
        Y.append(X.pop())
    else:
        if chk(Y[-1], X[-1]):
            Y.append(X.pop())
        else:
            Y.pop()
print("!", "".join([str(chk(Y[-1], i)) for i in range(N)]))

Fixed submission:
A, B = map(int, input().split())
N = A + B
X = [i for i in range(N)]
Y = []
def chk(a, b):
    print("?", a, b)
    return 1 if input() == "Y" else 0
if A <= B:
    print("Impossible")
else:
    while X:
        if not Y:
            Y.append(X.pop())
        else:
            if chk(Y[-1], X[-1]):
                Y.append(X.pop())
            else:
                X.pop()
                Y.pop()
    print("!", "".join([str(chk(Y[-1], i)) for i in range(N)]))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
NN = (M + 10).bit_length() - 1
BIT=[0]*(2**NN+1)

def addrange(l0, r0, x=1):
    l, r = l0, r0
    while l <= 2**NN:
        BIT[l] += x
        l += l & (-l)
    while r <= 2**NN:
        BIT[r] -= x
        r += r & (-r)
def getvalue(r):
    a = 0
    while r != 0:
        a += BIT[r]
        r -= r&(-r)
    return a

X = []
for _ in range(N):
    l, r = map(int, input().split())
    X.append((l, r+1))

X = sorted(X, key = lambda x: -(x[1]-x[0]))
for d in range(1, M+1):
    while X and X[-1][1] - X[-1][0] < d:
        l, r = X.pop()
        addrange(l, r)
    ans = len(X)
    for i in range(d, M+1, d):
        ans += getvalue(i)
    print(ans)


Fixed submission:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
NN = (M + 10).bit_length()
BIT=[0]*(2**NN+1)

def addrange(l0, r0, x=1):
    l, r = l0, r0
    while l <= 2**NN:
        BIT[l] += x
        l += l & (-l)
    while r <= 2**NN:
        BIT[r] -= x
        r += r & (-r)
def getvalue(r):
    a = 0
    while r != 0:
        a += BIT[r]
        r -= r&(-r)
    return a

X = []
for _ in range(N):
    l, r = map(int, input().split())
    X.append((l, r+1))

X = sorted(X, key = lambda x: -(x[1]-x[0]))
for d in range(1, M+1):
    while X and X[-1][1] - X[-1][0] < d:
        l, r = X.pop()
        addrange(l, r)
    ans = len(X)
    for i in range(d, M+1, d):
        ans += getvalue(i)
    print(ans)
Buggy python submission (verdict: Runtime Error):
X, Y = map(int, input().split())
if X * Y >= 0:
    if X <= Y: print(Y-X)
    else: print(X-Y+2)
else: print(max(abs(Y)+abs(X))+1)

Fixed submission:
X, Y = map(int, input().split())
if X * Y > 0:
    if X <= Y: print(Y-X)
    else: print(X-Y+2)
elif X == 0:
    print(Y if Y >= 0 else -Y+1)
elif Y == 0:
    print(-X if X <= 0 else X+1)
else:
    mi = abs(abs(Y)-abs(X))+1
    if X <= Y:
        mi = min(mi, Y-X)
    print(mi)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
for i in range(W):
    s = input()
    print(s)
    print(s)


Fixed submission:
H, W = map(int, input().split())
for i in range(H):
    s = input()
    print(s)
    print(s)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
for i in range(H):
    S = input(split())
    for j in range(W):
        if S[j] == "snuke":
            print(chr(65+j) + str(i+1))

Fixed submission:
H, W = map(int, input().split())
for i in range(H):
    S = input().split()
    for j in range(W):
        if S[j] == "snuke":
            print(chr(65+j) + str(i+1))
Buggy python submission (verdict: Time Limit Exceeded):
s=input()

i=0
while i<len(s):
    if s[i:i+2]=="ST":
        s = s[:i] + s[i+2:]
        i -= 1
    else:
        i += 1
        
print(len(s))

Fixed submission:
s=input()

a=0
r=len(s)
for i in range(len(s)):
    if s[i] == "S":
        a += 1
    else:
        if a>0:
            a -= 1
            r -= 2
    
print(r)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [1 if a == "I" else -1 for a in input()]
ma = 0
a = 0
for i in range(N):
    a += S[i]
    ma = max(ma, a)
print(ma)

Fixed submission:
A, B, H = [int(input()) for _ in range(3)]
print((A+B)*H//2)
Buggy python submission (verdict: Runtime Error):
N, A = map(int, input().split())
X = [int(a) for a in input().split()]
PO = [x-A for x in X if x > A]
NE = [A-x for x in X if x < A]
ZE = N - len(PO) - len(NE)

Y = [1] + [0] * 3000
Z = [1] + [0] * 3000

for i in PO:
    for j in range(len(Y) - A)[::-1]:
        Y[i+j] += Y[j]
for i in NE:
    for j in range(len(Z) - A)[::-1]:
        Z[i+j] += Z[j]

ans = -1
for i in range(len(Y)):
    ans += Y[i] * Z[i] * (2**ZE)
print(ans)

Fixed submission:
N, A = map(int, input().split())
X = [int(a) for a in input().split()]
PO = [x-A for x in X if x > A]
NE = [A-x for x in X if x < A]
ZE = N - len(PO) - len(NE)

Y = [1] + [0] * 3000
Z = [1] + [0] * 3000

for i in PO:
    for j in range(2800)[::-1]:
        Y[i+j] += Y[j]
for i in NE:
    for j in range(2800)[::-1]:
        Z[i+j] += Z[j]

ans = -1
for i in range(len(Y)):
    ans += Y[i] * Z[i] * (2**ZE)
print(ans)

Buggy python submission (verdict: Runtime Error):
N, A = map(int, input().split())
X = [int(a) for a in input().split()]
PO = [x-A for x in X if x > A]
NE = [A-x for x in X if x < A]
ZE = N - len(PO) - len(NE)

Y = [1] + [0] * (N*50)
Z = [1] + [0] * (N*50)

for i in PO:
    for j in range(len(Y) - A)[::-1]:
        Y[i+j] += Y[j]
for i in NE:
    for j in range(len(Z) - A)[::-1]:
        Z[i+j] += Z[j]

ans = -1
for i in range(len(Y)):
    ans += Y[i] * Z[i] * (2**ZE)
print(ans)

Fixed submission:
N, A = map(int, input().split())
X = [int(a) for a in input().split()]
PO = [x-A for x in X if x > A]
NE = [A-x for x in X if x < A]
ZE = N - len(PO) - len(NE)

Y = [1] + [0] * 3000
Z = [1] + [0] * 3000

for i in PO:
    for j in range(2800)[::-1]:
        Y[i+j] += Y[j]
for i in NE:
    for j in range(2800)[::-1]:
        Z[i+j] += Z[j]

ans = -1
for i in range(len(Y)):
    ans += Y[i] * Z[i] * (2**ZE)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = 0
mod = 10**9+7
for i in range(n):
    for j in range(i+1,n):
        a[i] %= mod
        a[j] %= mod
        ans += a[i]*a[j]
print(ans%mod)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = 0
mod = 10**9+7
sa = [0]
for i in range(n):
    sa.append((sa[i]+a[i])%mod)
for i in range(n-1):
    ans += a[i]*(sa[-1]-sa[i+1])
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def bfs(sy, sx):
    t = ((-1,0),(0,-1),(1,0),(0,1))
    dist = [[inf]*w for i in range(h)]
    dist[sy][sx] = 0
    q = deque([(sy,sx)])
    while(q):
        y,x = q.popleft()
        d = dist[y][x]
        for i,j in t:
            ny,nx = y+i,x+j
            if (0 <= nx < w and 0 <= ny < h):
                if dist[ny][nx] <= d or s[ny][nx] == "#":
                    continue
                q.appendleft((y+i,x+j))
                dist[ny][nx] = d
        for i in range(-2,3):
            for j in range(-2,3):
                ny,nx = y+i,x+j
                if (0 <= nx < w and 0 <= ny < h):
                    if dist[ny][nx] <= d+1 or s[ny][nx] == "#":
                        continue
                    q.append((ny,nx))
                    dist[ny][nx] = d+1
    return dist

inf = 10**9
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
s = [input() for i in range(h)]
ch, cw = ch - 1, cw - 1
dh, dw = dh - 1, dw - 1
dist = bfs(ch,cw)
ans = dist[dh][dw]
if ans == inf:
    ans = -1
print(ans)

Fixed submission:
from collections import deque


def bfs(sy, sx):
    t = ((-1,0),(0,-1),(1,0),(0,1))
    dist = [[inf]*w for i in range(h)]
    dist[sy][sx] = 0
    q = deque([(sy,sx)])
    while(q):
        y,x = q.popleft()
        d = dist[y][x]
        for i,j in t:
            ny,nx = y+i,x+j
            if (0 <= nx < w and 0 <= ny < h):
                if dist[ny][nx] <= d or s[ny][nx] == "#":
                    continue
                q.appendleft((y+i,x+j))
                dist[ny][nx] = d
        for i in range(-2,3):
            for j in range(-2,3):
                ny,nx = y+i,x+j
                if (0 <= nx < w and 0 <= ny < h):
                    if dist[ny][nx] <= d+1 or s[ny][nx] == "#":
                        continue
                    q.append((ny,nx))
                    dist[ny][nx] = d+1
    return dist

inf = 10**9
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
s = [input() for i in range(h)]
ch, cw = ch - 1, cw - 1
dh, dw = dh - 1, dw - 1
dist = bfs(ch,cw)
ans = dist[dh][dw]
if ans == inf:
    ans = -1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = -float("INF")
for i in range(n):
    pi = p[i]
    x = c[pi-1]
    a = x
    for j in range(k-1):
        pi = p[pi-1]
        a = max(a,x+c[pi-1])
        x += c[pi-1]
    ans = max(ans,a)
print(ans)


Fixed submission:
s = input()
ans = 0
a = 0
for si in s:
    if si == "R":
        a += 1
    else:
        ans = max(ans,a)
        a = 0
print(max(ans,a))
Buggy python submission (verdict: Runtime Error):
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k; cin >> k;
    int a = 7%k;
    rep(i,k){
        if (a == 0){
            cout << i+1 << "\n";
            return 0;
        }
        a = (a * 10 + 7)%k;
    }
    cout << -1 << "\n";
}

Fixed submission:
k = int(input())
a = 7%k
s = set()
for i in range(k):
    if a == 0:
        print(i+1)
        break
    a = (a*10+7)%k
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*(n+1)
t = 0
for i in range(k,n+1):
    if i == k:
        x = 1
        for aj in a[i-k:i]:
            x *= aj
            b[i] = x
        t = x
        continue
    else:
        x = b[i-1]/a[i-k-1]*a[i-1]
        #x = 
        if t < x:
            print("Yes")
        else:
            print("No")
        b[i] = x
        t = x
#print(b)


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

wa = [0]
for i in range(n):
    wa.append(wa[i]+a[i])

t = wa[k]-wa[0]
for i in range(k+1,n+1):
    if t < wa[i]-wa[i-k]:
        print("Yes")
    else:
        print("No")
    t = wa[i]-wa[i-k]
    # print(wa[i]-wa[i-k],t)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
t = 0
for i in range(k,n+1):
    x = 1
    for aj in a[i-k:i]:
        x *= aj
    if i == k:
        t = x
        continue
    else:
        if t < x:
            print("Yes")
        else:
            print("No")
        t = x

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

wa = [0]
for i in range(n):
    wa.append(wa[i]+a[i])

t = wa[k]-wa[0]
for i in range(k+1,n+1):
    if t < wa[i]-wa[i-k]:
        print("Yes")
    else:
        print("No")
    t = wa[i]-wa[i-k]
    # print(wa[i]-wa[i-k],t)
Buggy python submission (verdict: Runtime Error):
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> ans(n+1);
    for (int x = 1; x <= 100; x++)
    {
        for (int y = 1; y <= 100; y++)
        {
            for (int z = 1; z <= 100; z++)
            {
                int m = x * x + y * y + z * z + x * y + y * z + z * x;
                if (m <= n)
                {
                    ans[m]++;
                }
                else
                {
                    break;
                }
            }
        }
    }
    rep(i,n){
        cout << ans[i+1] << "\n";
    }
}

Fixed submission:
import math
n = int(input())
ans = [0] * n
a = math.floor(n**0.5)
b = 0
for x in range(1, a):
    for y in range(1, a):
        for z in range(1, a):
            m = x * x + y * y + z * z + x * y + y * z + z * x
            if m <= n:
                ans[m - 1] += 1

for i in range(n):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n,k,ans = 0;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(), p.end());
    rep(i,k) ans+=p[i];
    cout << ans << endl;
}

Fixed submission:
n,k = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
print(sum(p[:k]))
Buggy python submission (verdict: Runtime Error):
import string
s = string.ascii_lowercase


def f(x, tmp):
    if x == 0:
        return ""
    x -= 1
    if x <= 26:
        return s[x] + tmp
    else:
        return f(x // 26, s[x % 26] + tmp)


n = int(input())
r = f(n, "")
print(r)


Fixed submission:
import string
s = string.ascii_lowercase


def f(x, tmp):
    if x == 0:
        return ""
    x -= 1
    if x < 26:
        return s[x] + tmp
    else:
        return f(x // 26 , s[x % 26] + tmp)


n = int(input())
r = f(n, "")
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
x = 0
count = Counter(a)
q = int(input())
b,c = [],[]
for i in range(q):
    bi,ci = map(int,input().split())
    b.append(bi),c.append(ci)
for i in range(q):
    bi,ci = b[i],c[i]
    count[ci]+=count[bi]
    count[bi] = 0
    x = 0
    for k,v in count.items():
        x+=k*v
    print(x)


Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
x = sum(a)
count = Counter(a)

q = int(input())
b,c = [],[]

for i in range(q):
    bi,ci = map(int,input().split())
    b.append(bi),c.append(ci)
for i in range(q):
    bi,ci = b[i],c[i]
    x -= bi*count[bi]
    x += ci*count[bi]
    count[ci]+=count[bi]
    count[bi] = 0
    print(x)
Buggy python submission (verdict: Time Limit Exceeded):
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
ans = "NO"
for _ in range(t):
    if a>=b:
        ans = "YES"
    a+=v
    b+=w
print(ans)

Fixed submission:
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
ans = "NO"
if v>w and abs(a-b)/(v-w)<=t:
    ans = "YES"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
x = 1
for ai in a:
    x*=ai
if x>10**18:
    print(-1)
else:
    print(x)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print(0)
else:
    x = 1
    m = 10**18
    for ai in a:
        x*=ai
        if x>m:
            x = -1
            break
    print(x)
Buggy python submission (verdict: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    vector<string> s;
    s = {"p","p","h","b","h","h","p","h","p","h"};
    cin >> n;
    int x = n%10;
    cout << s[x] << "on" << endl;
}

Fixed submission:
n = input()
x = int(n[-1])
if x in [2,4,5,7,9]:
    print("hon")
elif x in [0,1,6,8]:
    print("pon")
elif x == 3:
    print("bon")
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
h = list(map(int,input().split()))
l = [tuple(map(int,input().split())) for i in range(m)]
x = ["B"]*n
for t in l:
    if h[t[0]-1] <= h[t[1]-1]:
        x[t[1]-1]="G"
        x[t[0]-1]="B"
    elif h[t[0]-1] >= h[t[1]-1]:
        x[t[1]-1]="B"
        x[t[0]-1]="G"
    print(x)
print(x.count("G"))

Fixed submission:
n,m = map(int,input().split())
h = tuple(map(int,input().split()))
l = set([tuple(map(int,input().split())) for i in range(m)])
x = [[] for i in range(n)]
ans=0
for t in l:
    x[t[0]-1].append(h[t[1]-1])
    x[t[1]-1].append(h[t[0]-1])
for k,li in enumerate(x):
    a = h[k]
    if li == []:
        ans+=1
    else:
        if a>max(li):
            ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
for i in range(x):
    for j in range(-x,0):
        if i**5-j**5 == x:
            print(i,j)
            quit()

Fixed submission:
x = int(input())
for i in range(-118,120):
    for j in range(-118,119):
        if i**5-j**5 == x:
            print(i,j)
            quit()
Buggy python submission (verdict: Time Limit Exceeded):
from math import floor
a,b,n = map(int,input().split())
ans = 0
for i in range(1,n+1):
    m = floor((a*i)/b)-(a*floor(i/b))
    ans=max(ans,m)
print(ans)

Fixed submission:
def f(x): return int(a * x / b) - a * int(x / b)
a, b, n = map(int, input().split())
print(f(min(b - 1, n)))
Buggy python submission (verdict: Runtime Error):
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;

int main() {
    int s,w; cin >> s >> w;
    if (w >= s){
        cout << "unsafe\n";
    }
    else{
        cout << "safe\n";
    }
}

Fixed submission:
s,w = map(int,input().split())
if s<=w:
    print("unsafe")
else:
    print("safe")
Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
from functools import reduce
k = int(input())
print(sum([reduce(math.gcd,t) for t in itertools.product(range(1,k+1),repeat=3)]))

Fixed submission:
import math
import itertools
from functools import reduce
k = int(input())
s = sum([reduce(math.gcd,t) for t in itertools.product(list(range(1,k+1)),repeat=3)])
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
if n%k==0:
    print(0)
else:
    while(n > abs(n-k)):
        if k == 1:
            n=0
            break
        n=abs(n-k)
    print(n)

Fixed submission:
n,k = map(int,input().split())
ans = min(n%k,k-(n%k))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
while(True):
    if n > abs(n-k):
        n=abs(n-k)
    else:
        break
print(n)

Fixed submission:
n,k = map(int,input().split())
ans = min(n%k,k-(n%k))
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n,m = map(int,input().split())
print(((math.factorial(n) // math.factorial(n - 2))//2)+ ((math.factorial(m) // math.factorial(m - 2))//2))

Fixed submission:
import itertools
n,m = map(int,input().split())
o = 0
o += len(list(itertools.permutations([i for i in range(n)], 2)))/2
o += len(list(itertools.permutations([i for i in range(m)], 2)))/2
print(int(o))