Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03289 (python)

Fixed submission:
s=input()
res="AC"
if s[0]!="A":res="WA"
elif s[2:-1].count("C")!=1:res="WA"
else:
    li=list(s)
    li.remove("A")
    li.remove("C")
    for i in li:
        if i!=i.lower():
            res="WA"
print(res)

Buggy submission (verdict: Runtime Error):
s=input()
res="AC"
if s[0]=="A":res="WA"
elif s[2:-2].count("C")!=1:res="WA"
else:
    li=list(s)
    li.remove("A")
    li.remove("C")
    for i in li:
        if i!=i.lower():
            res="WA"
print(res)
Problem p03423 (python)

Fixed submission:
print(int(input())//3)

Buggy submission (verdict: Runtime Error):
print(int(input)//3)
Problem p03544 (python)

Fixed submission:
n=int(input())
if n==0:
    print(2)
    exit()
elif n==1:
    print(1)
    exit()
else:
    nu1=2
    nu2=1
    for i in range(n-1):
        nu3=nu1+nu2
        nu1=nu2
        nu2=nu3
print(nu3)

Buggy submission (verdict: Runtime Error):
n=int(input())
if n==1:print(2)
elif n==2:print(1)
else:
    nu1=2
    nu2=1
    for i in range(n-1):
        nu3=nu1+nu2
        nu1=nu2
        nu2=nu3
print(nu3)
Problem p04043 (python)

Fixed submission:
a = sorted(list(map(int, input().split())))
print("YES" if a[1] == 5 and a[0]== 5 and a[2] else "NO")

Buggy submission (verdict: Runtime Error):
n = int(input())
print(n*(n+1)//2)
Problem p02694 (python)

Fixed submission:
X = int(input())
x = int(100)
for i in range(5000):
  x = int(x * 101 / 100)
  if x >= X:
    print(i + 1)
    break

Buggy submission (verdict: Runtime Error):
X = input()
x = 100
for i in range(5000):
  x = x * 101 / 100
  if x >= X:
    print i + 1
    break
Problem p02644 (python)

Fixed submission:
h, w, k = map(int, input().split())
x1, y1, x2, y2 = [int(i)-1 for i in input().split()]
ans = [[-1] * w for _ in range(h)]
ans[x1][y1] = 0
c = [input() for _ in range(h)]
qu = [(x1, y1)]


for x, y in qu:
    if x == x2 and y == y2:
        print(ans[x2][y2])
        break

    for i in range(x + 1, min(x + k + 1, h)):
        if c[i][y] == "@":
            break
        if ans[i][y] == -1:
            ans[i][y] = ans[x][y] + 1
            qu.append((i, y))
        elif ans[i][y] <= ans[x][y]:
            break
    for i in reversed(range(max(0, x - k), x)):
        if c[i][y] == "@":
            break
        if ans[i][y] == -1:
            ans[i][y] = ans[x][y] + 1
            qu.append((i, y))
        elif ans[i][y] <= ans[x][y]:
            break

    for i in range(y + 1, min(y + k + 1, w)):
        if c[x][i] == "@":
            break
        if ans[x][i] == -1:
            ans[x][i] = ans[x][y] + 1
            qu.append((x, i))
        elif ans[x][i] <= ans[x][y]:
            break
    for i in reversed(range(max(0, y - k), y)):
        if c[x][i] == "@":
            break
        if ans[x][i] == -1:
            ans[x][i] = ans[x][y] + 1
            qu.append((x, i))
        elif ans[x][i] <= ans[x][y]:
            break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
h, w, k = map(int, input().split())
x1, y1, x2, y2 = [int(i)-1 for i in input().split()]
ans = [[-1] * w for _ in range(h)]
ans[x1][y1] = 0
c = [input() for _ in range(h)]
qu = [(x1, y1)]


for x, y in qu:
    if x == x2 and y == y2:
        print(ans[x2][y2])
        break

    for i in range(x + 1, min(x + k + 1, h)):
        if c[i][y] == "@":
            break
        if ans[i][y] == -1:
            ans[i][y] = ans[x][y] + 1
            qu.append((i, y))
    for i in reversed(range(max(0, x - k), x)):
        if c[i][y] == "@":
            break
        if ans[i][y] == -1:
            ans[i][y] = ans[x][y] + 1
            qu.append((i, y))

    for i in range(y + 1, min(y + k + 1, w)):
        if c[x][i] == "@":
            break
        if ans[x][i] == -1:
            ans[x][i] = ans[x][y] + 1
            qu.append((x, i))
    for i in reversed(range(max(0, y - k), x)):
        if c[x][i] == "@":
            break
        if ans[x][i] == -1:
            ans[x][i] = ans[x][y] + 1
            qu.append((x, i))
else:
    print(-1)
Problem p02703 (python)

Fixed submission:
n, m, s = [int(i) for i in input().split()]

e = []
for _ in range(m):
    u, v, a, b = [int(i) for i in input().split()]
    u -= 1
    v -= 1
    e.append([u, v, a, b])

co = [[int(i) for i in input().split()] for _ in range(n)]

dp = [[10 ** 18] * 6000 for _ in range(n)]
dp[0][min(5999,s)] = 0
for i in range(6000):
    if i + co[0][0] < 6000:
        dp[0][i + co[0][0]] = min(dp[0][i + co[0][0]], dp[0][i] + co[0][1])

for _ in range(n):
    for u, v, a, b in e:
        for j in range(a, 6000):
            dp[v][j - a] = min(dp[v][j - a], dp[u][j] + b)
        for i in range(6000):
            if i + co[v][0] < 6000:
                dp[v][i + co[v][0]] = min(dp[v][i + co[v][0]], dp[v][i] + co[v][1])

        for j in range(a, 6000):
            dp[u][j - a] = min(dp[u][j - a], dp[v][j] + b)
        for i in range(6000):
            if i + co[u][0] < 6000:
                dp[u][i + co[u][0]] = min(dp[u]
                                          [i + co[u][0]], dp[u][i] + co[u][1])

for i in range(1, n):
    print(min(dp[i]))

Buggy submission (verdict: Runtime Error):
n, m, s = [int(i) for i in input().split()]

e = []
for _ in range(m):
    u, v, a, b = [int(i) for i in input().split()]
    u -= 1
    v -= 1
    e.append([u, v, a, b])

co = [[int(i) for i in input().split()] for _ in range(n)]

dp = [[10 ** 18] * 6000 for _ in range(n)]
dp[0][s] = 0
for i in range(6000):
    if i + co[0][0] < 6000:
        dp[0][i + co[0][0]] = min(dp[0][i + co[0][0]], dp[0][i] + co[0][1])

for _ in range(n):
    for u, v, a, b in e:
        for j in range(a, 6000):
            dp[v][j - a] = min(dp[v][j - a], dp[u][j] + b)
        for i in range(6000):
            if i + co[v][0] < 6000:
                dp[v][i + co[v][0]] = min(dp[v][i + co[v][0]], dp[v][i] + co[v][1])

        for j in range(a, 6000):
            dp[u][j - a] = min(dp[u][j - a], dp[v][j] + b)
        for i in range(6000):
            if i + co[u][0] < 6000:
                dp[u][i + co[u][0]] = min(dp[u]
                                          [i + co[u][0]], dp[u][i] + co[u][1])

for i in range(1, n):
    print(min(dp[i]))
Problem p02730 (python)

Fixed submission:
s = input()

def isk(s):
    n = len(s)
    for i in range(n):
        if s[i] != s[n - 1 - i]:
            return False
    return True
n = len(s)
if isk(s) and isk(s[:(n - 1) // 2]) and isk(s[(n + 3) // 2 - 1:]):
    print('Yes')
else:
    print("No")

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll (i)=0;(i)<(n);(i)++)

bool is(string s, int i, int j) {
    for (int l = 0; l <= j - i; l++) {
        if (s[l + i] != s[j - l]) {
            return false;
        }
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    int n;
    n = s.size();
    if (is(s, 0, (n - 1) / 2 - 1) && is(s, 0, n - 1) && is(s, (n + 3) / 2 - 1, n - 1)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
Problem p02743 (python)

Fixed submission:
a, b, c = [int(i) for i in input().split()]
if a + b >= c:
    print("No")
else:
    if 4 * a * b < (c - a - b)** 2:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
from math import sqrt, isclose
a, b, c = [int(i) for i in input().split()]
d = sqrt(c) - sqrt(a) - sqrt(b)
if isclose(d,0) or d<0:
    print("No")
else:
    print("Yes")
Problem p02747 (python)

Fixed submission:
s=input();print("Yes"if s=="hi"*(len(s)//2)else"No")

Buggy submission (verdict: Runtime Error):
s=input()
print("Yes"if s=="hi"*(len(s)//2)else"No)
Problem p02782 (python)

Fixed submission:

p = 10**9+7
kai_ = [1]
for i in range(1, 10 ** 7):
    kai_.append(kai_[-1] * i % p)


def kai(x):
    return kai_[x]


def comb(a, b):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai(a)
    c *= pow(kai(b), p - 2, p)
    c *= pow(kai(a - b), p - 2, p)
    return c % p


r1, c1, r2, c2 = [int(i) for i in input().split()]


def s(r, c):
    return comb(r+c+2,r+1)


print((s(r2, c2) - s(r2, c1 - 1) - s(r1 - 1, c2) + s(r1 - 1, c1 - 1)) % p)

Buggy submission (verdict: Runtime Error):

p = 10**9+7
kai_ = [1]
for i in range(1, 10 ** 6 * 2):
    kai_.append(kai_[-1] * i % p)


def kai(x):
    return kai_[x]


def comb(a, b):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai(a)
    c *= pow(kai(b), p - 2, p)
    c *= pow(kai(a - b), p - 2, p)
    return c % p


r1, c1, r2, c2 = [int(i) for i in input().split()]


def s(r, c):
    return comb(r+c+2,r+1)


print((s(r2, c2) - s(r2, c1 - 1) - s(r1 - 1, c2) + s(r1 - 1, c1 - 1)) % p)

Buggy submission (verdict: Runtime Error):

p = 10**9+7
kai_ = [1]
for i in range(1, 10 ** 6 * 2):
    kai_.append(kai_[-1] * i % p)


def kai(x):
    return kai_[x]


def comb(a, b):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai(a)
    c *= pow(kai(b), p - 2, p)
    c *= pow(kai(a - b), p - 2, p)
    return c % p


r1, c1, r2, c2 = [int(i) for i in input().split()]


def s(r, c):
    a = 0
    for i in range(1, r + 1):
        a += comb(i + c + 1, c)
        a %= p
    return a


print((s(r2, c2) - s(r2, c1 - 1) - s(r1 - 1, c2) + s(r1 - 1, c1 - 1)) % p)

Buggy submission (verdict: Runtime Error):
r1,c1,r2,c2=map(int,input().split())

mod=10**9+7
f=[1]
for i in range(2*10**6+7):f+=[f[-1]*(i+1)%mod]
def comb(a,b):return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod

def F(r,c):
  ans=0
  for i in range(r+c+1):
    ans+=pow(2,i,mod)
    ans%=mod'''
  d=0
  s=0
  for i in range(r-1,-1,-1):
    s+=comb((r-i-1)+c,c)
    d+=pow(2,i,mod)*s
    s%=mod
    d%=mod
  ans=(ans+(mod-d))%mod
  d=0
  s=0
  for i in range(c-1,-1,-1):
    s+=comb((c-i-1)+r,r)
    d+=pow(2,i,mod)*s
    s%=mod
    d%=mod
  ans=(ans+(mod-d))%mod'''
  return ans

ans=F(r2,c2)
ans=(ans+(mod-F(r2,c1-1)))%mod
ans=(ans+(mod-F(r1-1,c2)))%mod
ans+=F(r1-1,c1-1)
print(ans%mod)
Problem p02821 (python)

Fixed submission:
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
b = [0]
for i in reversed(a):
    b.append(b[-1] + i)


def search(i):
    if a[-1] < i:
        return 0
    mi = 0
    ma = n - 1
    while mi != ma:
        m = (mi + ma) // 2
        if a[m] >= i:
            ma = m
        else:
            mi = m + 1
    return n-mi

def countmax(i):
    ans = 0
    for j in a:
        ans += search(i - j)
    return ans

mi = 0
ma = a[-1] * 2
while mi != ma:
    md = (mi + ma) // 2 + 1
    #print(md, countmax(md))
    if countmax(md) > m:
        mi = md
    else:
        ma = md - 1

ans = 0
for j in a:
    i = search(mi + 1 - j)
    ans+=b[i]+i*j
ans += (m-countmax(mi+1))*mi
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,m=[int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [0] * (2 * 10 ** 5 + 1)
for i in a:
    b[i] += 1
b = np.fft.fft(b)
b = np.fft.ifft(b*b)

c = 0
f = 0
for i in reversed(range(2 * 10 ** 5 + 1)):
    if f + b[i] > m:
        c += (m - f) * i
        break
    else:
        c += i * b[i]
        f += b[i]
print(int(round(c.real)))
Problem p02837 (python)

Fixed submission:
n = int(input())
xy = []
for _ in range(n):
    xy.append([])
    a = int(input())
    for _ in range(a):
        xy[-1].append([int(i) for i in input().split()])
        xy[-1][-1][0]-=1

ma = 0

for i in range(2 ** n):
    ok = True
    a = 0
    for j in range(n):
        if (2 ** j) & i != 0:
            a += 1
            for k in xy[j]:
                if (1 if (2 ** k[0]) & i != 0 else 0) != k[1]:
                    ok = False
    if ok:
        ma = max(ma, a)
print(ma)

Buggy submission (verdict: Runtime Error):
n = int(input())
xy = []
for _ in range(n):
    xy.append([])
    a = int(input())
    for _ in range(a):
        xy[-1].append([int(i) for i in input().split()])
        xy[-1][0] -= 1

ma = 0

for i in range(2 ** n):
    ok = True
    a = 0
    for j in range(n):
        if (2 ** j) & i != 0:
            a += 1
            for k in xy[j]:
                if ((2 ** k[0]) & i != 0) != (k[1] == 1):
                    ok = False
    if ok:
        ma = max(ma, a)
print(ma)
Problem p02848 (python)

Fixed submission:
n = int(input())
s = input()
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b = ""
for i in s:
    j = (alpha.index(i) + n) % 26
    b += alpha[j]
print(b)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b = ""
for i in s:
    j = (s.index(i) + n) % 26
    b += s[j]
print(b)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
alpha = "ABCDEFGHIJKLMNOPQRSTUVWSYZ"
b = ""
for i in s:
    j = (s.index(i) + n) % 26
    b += s[j]
print(b)
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
ab = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = [int(i)-1 for i in input().split()]
    ab[a].append([b, i])
    ab[b].append([a, i])
re = [False] * n
ed = [0]*(n-1)


def c(i=0, used=-1):
    global re, ed
    if re[i]:
        return 0
    re[i] = True
    k = 1
    for j in ab[i]:
        if re[j[0]]:
            continue
        if k == used:
            k += 1
        ed[j[1]] = k
        c(j[0], k)
        k += 1


c()
print(max(ed))
print(" ".join([str(i) for i in ed]))

Buggy submission (verdict: Runtime Error):
n = int(input())
e = [[] for _ in range(n)]
for j in range(n - 1):
    a, b = [int(i)-1 for i in input().split()]
    e[a].append((b, j))
    e[b].append((a, j))

co = [0]*(n-1)
def dfs(i=0, r=-1, dis=-1):
    global co
    c = 1
    for j in e[i]:
        if j[0] == r:
            continue
        if c == dis:
            c += 1
        co[j[1]] = c
        dfs(j[0], i, c)
        c += 1

dfs()

print(max(co))
for i in co:
    print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())
ab = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = [int(i)-1 for i in input().split()]
    ab[a].append([b, i])
    ab[b].append([a, i])
re = [False] * n
ed = [0]*(n-1)


def c(i=0, used=-1):
    global re, ed
    if re[i]:
        return 0
    re[i] = True
    k = 1
    for j in ab[i]:
        if re[j[0]]:
            continue
        if k == used:
            k += 1
        ed[j[1]] = k
        c(j[0], k)
        k += 1


c()
print(max(ed))
print(" ".join([str(i) for i in ed]))
Problem p02856 (python)

Fixed submission:
m = int(input())
a = 0
b = 0
for _ in range(m):
    d, c = [int(i) for i in input().split()]
    a += c
    b += d * c

print(a - 1 + (b - 1) // 9)

Buggy submission (verdict: Runtime Error):
m = int(input())


def a(x):
    k = 0
    while len(x) > 1:
        x = str(int(str(int(x[0]) + int(x[1])) + x[2:len(x)]))
        k += 1
    return x, k


k = 0
x = ""
for _ in range(m):
    d, c = [int(i) for i in input().split()]
    x += str(d) * c
    x, ka = a(x)
    k += ka
print(k)

Buggy submission (verdict: Runtime Error):
m = int(input())


def a(x):
    k = 0
    while len(x) > 1:
        x = str(int(str(int(x[0]) + int(x[1])) + x[2:len(x)]))
        k += 1
    return x, k


k = 0
x = ""
for _ in range(m):
    d, c = [int(i) for i in input().split()]
    x += str(d) * c
    x, ka = a(x)
    k += ka
print(k)

Buggy submission (verdict: Runtime Error):
m = int(input())


def a(x):
    x = str(x)
    k = 0
    while len(x) != 1:
        x = str(int(x[0]) + int(x[1])) + x[2:]
        k += 1
    return x, k


k = 0
x = ""
for _ in range(m):
    d, c = [int(i) for i in input().split()]
    x += str(d) * c
    x, ka = a(x)
    k += ka
print(k)
Problem p02900 (python)

Fixed submission:
def gcd(x, y):
    if min(x, y) == 0:
        return max(x, y)
    else:
        return gcd(y,x%y)


a, b = [int(i) for i in input().split()]
c = gcd(a, b)

def d(x):
    i = 2
    e=[]
    while True:
        if x % i == 0:
            e.append(i)
            while x % i == 0:
                x //= i
        if i * i > x:
            break
        i+=1
    if x != 1:
        e.append(x)
    return e
print(len(d(c))+1)

Buggy submission (verdict: Runtime Error):
from math import gcd
a, b = [int(i) for i in input().split()]
c = gcd(a, b)

def d(x):
    i = 2
    e=[]
    while True:
        if x % i == 0:
            e.append(i)
            while x % i == 0:
                x //= i
        if i * i > x:
            break
        i+=1
    if x != 1:
        e.append(x)
    return e
print(len(d(c))+1)
Problem p02917 (python)

Fixed submission:
n=int(input())
b=[int(i) for i in input().split()]
ans=b[-1]+b[0]
for i,j in zip(b[:-1],b[1:]):
  ans+=min(i,j)
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
b=[int(i) for i in input().split()]
ans=b[-1]+b[0]
for i,j in z1p(b[:-1],b[1:]):
  ans+=min(i,j)
print(ans)
Problem p02918 (python)

Fixed submission:
n,k=[int(i) for i in input().split()]
s=input()
ans=0
for i,j in zip(s[:-1],s[1:]):
  if i!=j:
    ans+=1
print(n-1-max(ans-2*k,0))

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define HSORT(V,n) sort(V,V+n)
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int c = 0;
    int ans = 0;
    bool check = false;
    REP(i,n-1){
        if (s[i] == s[i+1]) ans++;
    }
    REP(i,n-1){
        if (s[i] == 'L' && s[i+1] == 'R'){
            c++;
        }
        if (c == k) {
            break;
        }
        if (i == n-2){
            if (s[n-1] == 'L') check = true;
        }
    }
    if (c!=k){
        if (s[0] == 'R') ans++;
    }
    ans += 2*c;
    if (!check) ans--;
    PRINT(ans);
}
Problem p02920 (python)

Fixed submission:
n = int(input())
s = [int(i) for i in input().split()]
used = [0] * (2 ** n)
used[0] = 1
s.sort(reverse=True)
a = 1
b = [s[0]]
for _ in range(n):
    c = b[:]
    j = 0
    for i in b:
        while j < 2 ** n:
            if used[j] == 0 and s[j] < i:
                c.append(s[j])
                used[j] = 1
                break
            j += 1
        if j >= 2 ** n:
            print("No")
            exit()
    b = sorted(c, reverse=True)

print("Yes")

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [int(i) for i in input().split()]
used = [0] * (2 ** n)
used[0] = 1
s.sort(reverse=True)
a = 1
b = [s[0]]
for _ in range(n):
    c = b.copy()
    j = 0
    for i in b:
        while j < 2 ** n:
            if used[j] == 0 and s[j] < i:
                c.append(s[j])
                used[j] = 1
                break
            j += 1
        if j >= 2 ** n:
            print("No")
            exit()
    b = sorted(c, reverse=True)

print("Yes")
Problem p02957 (python)

Fixed submission:
a,b=[int(i) for i in input().split()]
a,b=min(a,b),max(a,b)
c=b+a
if c%2==0:
  print(c//2)
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
a,b=[int(i) for i in inpput().split()]
a,b=min(a,b),max(a,b)
c=b-a
if c%2==0:
  print(c//2)
else:
  print("IMPOSSIBLE")
Problem p02982 (python)

Fixed submission:
import numpy as np
import math
n,d=[int(i) for i in input().split()]
x=[]
for _ in range(n):
  x.append(np.array([int(i) for i in input().split()]))
def dis(x,y):
  return int(np.sum((x-y)**2))
def iss(x):
  a=round(math.sqrt(x))
  return a**2==x
k=0
for i in range(n):
  for j in range(i+1,n):
    if iss(dis(x[i],x[j])):
      k+=1
print(k)

Buggy submission (verdict: Runtime Error):
import numpy as np
import math
n,d=[int(i) for i in inpput().split()]
x=[]
for _ in range(n):
  x.append(np.array([int(i) for i in input().split()]))
def dis(x,y):
  return int(np.sum((x-y)**2))
def iss(x):
  a=round(math.sqrt(x))
  return a**2==x
k=0
for i in range(n):
  for j in range(i+1,n):
    if iss(dis(x[i],x[j])):
      k+=1
print(k)
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()
n, k = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(i) for i in input().split()]
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)
ans = 1
mod = 10**9+7


def dfs(i=0, r=-1):
    global ans
    if r == -1:
        ans *= k
        ans %= mod

        p = k-1
        for j in e[i]:
            if j == r:
                continue
            ans *= p
            ans %= mod
            p -= 1
            dfs(j, i)
    else:
        p = k-2
        for j in e[i]:
            if j == r:
                continue
            ans *= p
            ans %= mod
            p -= 1
            dfs(j, i)


dfs()
print(ans)

Buggy submission (verdict: Runtime Error):
from math import factorial as f
n,k=[int(i) for i in input().split()]
d=[0]*n
for j in range(n-1):
  a,b=[int(i)-1 for i in input().split()]
  d[a]+=1
  d[b]+=1
m=1000000007
l=k*int(f(k-1)/f(k-d[0]))%m
for i in d[1:]:
  l=l*int(f(k-2)/f(k-i-1))%m
print(l)

Buggy submission (verdict: Runtime Error):
from math import factorial as f
n,k=[int(i) for i in input().split()]
d=[0]*n
for j in range(n-1):
  a,b=[int(i)-1 for i in input().split()]
  d[a]+=1
  d[b]+=1
m=1000000007
l=k*(f(k-1)//f(k-d[0]))%m
for i in d[1:]:
  l=l*(f(k-2)//f(k-i-1))%m
print(l)
Problem p02997 (python)

Fixed submission:
n, k = [int(i) for i in input().split()]
if k > (n - 1)*(n - 2) // 2:
    print(-1)
else:
    ed = []
    for i in range(1, n):
        ed.append(" ".join(map(str, [1, i + 1])))
    kk = (n - 1)*(n - 2)//2 - k
    if not kk:
        print(len(ed))
        print("\n".join(ed))
        exit()
    for i in range(1, n):
        for j in range(i+1, n):
            ed.append(" ".join(map(str, [i + 1, j + 1])))
            kk -= 1
            if not kk:
                print(len(ed))
                print("\n".join(ed))
                exit()

Buggy submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
if k > (n - 1)*(n - 2) // 2:
    print(-1)
else:
    ed = []
    for i in range(1, n):
        ed.append(" ".join(map(str, [1, i + 1])))
    kk = (n - 1)*(n - 2) - k
    if not kk:
        print(len(ed))
        print("\n".join(ed))
        exit()
    for i in range(1, n):
        for j in range(1, n):
            ed.append(" ".join(map(str, [i + 1, j + 1])))
            kk -= 1
            if not kk:
                print(len(ed))
                print("\n".join(ed))
                exit()
Problem p03005 (python)

Fixed submission:
a,b=[int(i) for i in input().split()]
if b==1:
  print(0)
else:
  print(a-b)

Buggy submission (verdict: Runtime Error):
a,b=[int(i) for i in input().split()]
if b=1:
  print(0)
else:
  print(a-b)
Problem p03030 (python)

Fixed submission:
n = int(input())
a = []
for i in range(n):
  s, p = input().split()
  a.append([s,-int(p),i])
a.sort()
for i in a:
  print(i[-1]+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
  s, p = list(map(int, input().split()))
  a.append([s,-p,i])
a.sort()
for i in a:
  print(i[-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
  s, p = map(int, input().split())
  a.append([s,-p,i])
a.sort()
for i in a:
  print(i[-1])
Problem p03047 (python)

Fixed submission:
n,k = map(int,input().split())
print(n-k+1)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input())
print(n-k+1)
Problem p03071 (python)

Fixed submission:
a,b=map(int,input().split());c=[a,b,a-1,b-1];c.sort();print(sum(c[-2:]))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input())
c=[a,b,a-1,b-1];c.sort()
print(sum(c[-2:]))
Problem p03076 (python)

Fixed submission:
a=[]
for i in range(5):
  a.append(int(input()))
a.sort(key=lambda x:(x-1)%10)
b=0
for i in range(5):
  if i==0:
    b+=a[i]
  else:
    c=(a[i]-1)//10+1
    b+=c*10
print(b)

Buggy submission (verdict: Runtime Error):
a=[]
for i in range(5):
  a.append(int(input()))
a.sort(key=x:lambda (x-1)%10)
b=0
for i in range(5):
  if i==1:
    b+=a[i]
  else:
    c=(a[i]+1)//10+1
    b+=c*10
print(b)