Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,k = list(map(int,input().split()))
a =[]
for i in range(n):
    a.append(list(map(int,input().split())))
a.sort()
b =[]
for i in range(n):
    for j in range(a[i][1]):
        b.append(a[i][0])
print(b[k-1])

Fixed submission:
n,k = list(map(int,input().split()))
a =[]
for i in range(n):
    a.append(list(map(int,input().split())))
a.sort()
b =[]
c =[]
for i in range(n):
    b.append(a[i][0])
    c.append(a[i][1])
for i in range(n-1):
    c[i+1] = c[i]+c[i+1]
ans = c[-1]
for i in range(1,n):
    if c[i] >= k:
        ans = b[i]
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
if b == 'H':
    print(a)
elif a == b:
    print('H')
else:
    print('D')

Fixed submission:
a, b = list(input().split())
if b == 'H':
    print(a)
elif a == b:
    print('H')
else:
    print('D')
Buggy python submission (verdict: Runtime Error):
if s >= c//2:
    print(c//2)
else:
    print((2*s+c)//4)

Fixed submission:
s,c =list(map(int,input().split()))

if s >= c//2:
    print(c//2)
else:
    print((2*s+c)//4)
Buggy python submission (verdict: Runtime Error):
import itertools
n,m = list(map(int,input().split()))

a = []
for i in range(m):
    b = (list(map(int,input().split())))
    b = [b[0]-1,b[1]-1]
    a.append(b)

b = [[0 for i in range(n)] for j in range(n)]
for i in a:
    b[i[0]][i[1]] = 1
    b[i[1]][i[0]] = 1

c = [i+1 for i in range(m-1)]
ans = 0
for i in itertools.permutations(c,m-1):
    j = [0]
    j += i
    count = 0
    for i in range(m-1):
        if b[j[i]][j[i+1]] == 1:
            count += 1
            if count == m-1:
                ans += 1
                count = 0
        else:
            break
print(ans)

Fixed submission:
import itertools
n,m = list(map(int,input().split()))

a = []
for i in range(m):
    b = (list(map(int,input().split())))
    b = [b[0]-1,b[1]-1]
    a.append(b)

b = [[0 for i in range(n)] for j in range(n)]
for i in a:
    b[i[0]][i[1]] = 1
    b[i[1]][i[0]] = 1


c = [i+1 for i in range(n-1)]
ans = 0
for i in itertools.permutations(c,n-1):
    j = [0]
    j += i
    count = 0
    for i in range(n-1):
        if b[j[i]][j[i+1]] == 1:
            count += 1
            if count == n-1:
                ans += 1
                count = 0
        else:
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
a = int(input())
ans =a // 11 *2
b = a % 11
if b == 0:
    print(ans)
elif b <= 6:
    print(ans+1)
else:
    print(num+2)


Fixed submission:
a = int(input())
ans =a // 11 *2
b = a % 11
if b == 0:
    print(ans)
elif b <= 6:
    print(ans+1)
else:
    print(ans+2)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = list(map(int,input().split()))
count = 0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            if i + j + k == s:
                count += 1
print(count)


Fixed submission:
k,s = list(map(int,input().split()))
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if 0 <= z <=k:
            count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

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

if n % 2 == 0:
    b = 0
    for i in range(n//2):
        if a.count(i*2+1) != 2:
            b = 1
    if b == 1:
        print(0)
    else:
        print(2**(n//2))
else:
    b = 0
    if a.count(0) != 1:
        b = 1
    else:
        for i in range(n//2):
            if a.count((i+1)*2) != 2:
                b = 1
    if b == 1:
        print(0)
    else:
        print(2**(n//2))

Fixed submission:
n = int(input())

a = list(map(int,input().split()))
a.sort()
if n % 2 == 0:
    b = 0
    for i in range(0,n,2):
        if a[i] != a[i+1] and a[i] != i+1:
            b = 1
    if b == 1:
        print(0)
    else:
        print((2**(n//2))%1000000007)
else:
    b = 0
    if a[0] != 0:
        b = 1
    else:
        for i in range(1,n,2):
            if a[i] != a[i+1] and a[i] != i+1:
                b = 1
    if b == 1:
        print(0)
    else:
        print((2**(n//2))%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

if n%2 == 0:
    count = 0
    for i in a:
        if a.count(i) == 2:
            count += 1
    if count == n:
        print(int(2**(n/2))%(10**9+7))
    else:
        print(0)
else:
    count = 0
    for i in a:
        if a.count(i) == 2:
            count += 1
    if count == n-1 and a.count(0) == 1:
        print(int(2**((n-1)/2))%(10**9+7))
    else:
        print(0)

Fixed submission:
n = int(input())

a = list(map(int,input().split()))
a.sort()
if n % 2 == 0:
    b = 0
    for i in range(0,n,2):
        if a[i] != a[i+1] and a[i] != i+1:
            b = 1
    if b == 1:
        print(0)
    else:
        print((2**(n//2))%1000000007)
else:
    b = 0
    if a[0] != 0:
        b = 1
    else:
        for i in range(1,n,2):
            if a[i] != a[i+1] and a[i] != i+1:
                b = 1
    if b == 1:
        print(0)
    else:
        print((2**(n//2))%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

if n%2 == 0:
    count = 0
    for i in a:
        if a.count(i) == 2:
            count += 1
    if count == n:
        print(int(2**(n/2)))
    else:
        print(0)
else:
    count = 0
    for i in a:
        if a.count(i) == 2:
            count += 1
    if count == n-1 and a.count(0) == 1:
        print(int(2**((n-1)/2)))
    else:
        print(0)


Fixed submission:
n = int(input())

a = list(map(int,input().split()))
a.sort()
if n % 2 == 0:
    b = 0
    for i in range(0,n,2):
        if a[i] != a[i+1] and a[i] != i+1:
            b = 1
    if b == 1:
        print(0)
    else:
        print((2**(n//2))%1000000007)
else:
    b = 0
    if a[0] != 0:
        b = 1
    else:
        for i in range(1,n,2):
            if a[i] != a[i+1] and a[i] != i+1:
                b = 1
    if b == 1:
        print(0)
    else:
        print((2**(n//2))%1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c = list(map(int,input().split()))

count = 0
for i in range(a,b+1):
    if i%c == 0:
        count += 1

print(count)

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

d = a//c
e = a%c
f = b//c

if e == 0:
    print(f-d+1)
else:
    print(f-d)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = int((2*n)**0.5)+1
b = int((a*(a+1))/2)-n
c = [i for i in range(1,a+1)]
c.remove(b)
for i in c:
    print(i)

Fixed submission:
n = int(input())
a = 0
for i in range(n+1):
    if i*(i+1)//2 >= n:
        a = i
        break

b=[]
c = a*(a+1)//2
for i in range(1,a+1):
    b.append(i)


if c > n:
    b.pop(c-n-1)

for i in b:
    print(i)
Buggy python submission (verdict: Runtime Error):
a = 4;b = 2;c = 0;d = 9;e = 7
f = [a,b,c,d,e]
ans = 0
for i in range((n-2)%11):
	if k in (a,b,c,d,e):
		ans += 1
	a = (a+8)%11
	b = (b+8)%11
	c = (c+8)%11
	d = (d+8)%11
	e = (e+8)%11

print(ans+((n-2)//11)*5)

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

a = 4;b = 2;c = 0;d = 9;e = 7
f = [a,b,c,d,e]
ans = 0
for i in range((n-2)%11):
	if k in (a,b,c,d,e):
		ans += 1
	a = (a+8)%11
	b = (b+8)%11
	c = (c+8)%11
	d = (d+8)%11
	e = (e+8)%11

print(ans+((n-2)//11)*5)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = list(map(int,input().split()))

count = 0

for i in range(1,6):
	for j in range(1,n-1):
		if (9*i+9+63*j)%11 == k:
			count += 1
print(count)

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

a = 4;b = 2;c = 0;d = 9;e = 7
f = [a,b,c,d,e]
ans = 0
for i in range((n-2)%11):
	if k in (a,b,c,d,e):
		ans += 1
	a = (a+8)%11
	b = (b+8)%11
	c = (c+8)%11
	d = (d+8)%11
	e = (e+8)%11

print(ans+((n-2)//11)*5)
Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
c = input()

d = a[0]
a.pop(0)
while True:
    if d == "a":
        if len(a) == 0:
            print("A")
            break
        d = a[0]
        a.pop(0)
    if d == "b":
        if len(b) == 0:
            print("B")
            break
        d = b[0]
        b.pop(0)
    if d == "c":
        if len(c) == 0:
            print("C")
            break
        d = c[0]
        c.pop(0)

Fixed submission:

a = input()
b = input()
c = input()

d = a[0]
a = a[1:]
while True:
    if d == "a":
        if len(a) == 0:
            print("A")
            break
        d = a[0]
        a = a[1:]
    if d == "b":
        if len(b) == 0:
            print("B")
            break
        d = b[0]
        b = b[1:]
    if d == "c":
        if len(c) == 0:
            print("C")
            break
        d = c[0]
        c = c[1:]
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,a = list(map(int,input().split()))
x = list(map(int,input().split()))

xa = []
xb = []
count = 0
for i in x:
    if i > a:
        xa.append(i-a)
    elif i < a:
        xb.append(i-a)
    else:
        count += 1
ans = 0
if len(xa) == 0 or len(xb) == 0:
    print(2**count-1)
else:
    for i in range(1,len(xa)+1):
        for j in range(1,len(xb)+1):
            for k in itertools.combinations(xa,i):
                for l in itertools.combinations(xb,j):
                    if sum(k)+sum(l) == 0:
                        ans += 1
    if ans == 0:
        print(0)
    elif count == 0:
        print(ans)
    else:
        print((ans+1)*2**count-count)

Fixed submission:
n,a = map(int, input().split())
x = list(map(int,input().split()))
x = [i-a for i in x]

d = {}
d[0] = 1
for i in x:
    for j,k in list(d.items()):
        d[j+i] = d.get(j+i,0)+k
print(d[0]-1)
Buggy python submission (verdict: Runtime Error):
l = map(int, raw_input().split())

if l.count(5) == 2:
    if l.count(7) ==1:
        print('YES')
else:
    print('NO')

Fixed submission:
a = list(map(int,input().split()))
b = a.count(5)
c = a.count(7)
if b == 2 and c == 1:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
a, b, c = int(input())
d = [a,b,c]
if d.count(5) == 2:
    if d.count(7) == 1:
        print('Yes')
else:
    print('No')

Fixed submission:
a = list(map(int,input().split()))
b = a.count(5)
c = a.count(7)
if b == 2 and c == 1:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
#include<bits/stdc++.h>

template<uint32_t N = 10'000'000>
struct Sieve_of_Eratosthenes{
  using u32 = uint32_t;
  std::vector<u32> factor;
  Sieve_of_Eratosthenes(){
    factor.resize(N+1);
    for(u32 p=2;p<=N;++p){
      if(factor[p])continue;
      factor[p] = p;
      for(u32 x=p+p;x<=N;x+=p){
        if(factor[x])continue;
        factor[x] = p;
      }
    }
  }
  std::vector<u32> prime_factor(u32 x){
    std::vector<u32> pf;
    while(factor[x]){
      pf.push_back(factor[x]);
      while(factor[x]==pf.back())x/=factor[x];
    }
    return pf;
  }
};

signed main(){
  using namespace std;
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin>>n;
  vector<int> a(n);
  for(auto& ai:a)cin>>ai;

  constexpr int a_max = 1e6;
  Sieve_of_Eratosthenes ushi;

  map<int,int> mp;
  bool pairwise_coprime = true;
  bool setwise_coprime = accumulate(begin(a),end(a),0,[](auto a,auto b){return gcd(a,b);}) == 1;

  for(auto const& ai:a){
    for(auto const& p:ushi.prime_factor(ai)){
      if(mp.count(p)){
        pairwise_coprime = false;
        goto loopend;
      }
      mp[p]++;
    }
  }
loopend:

  if(pairwise_coprime){
    cout<<"pairwise coprime"<<endl;
  }
  else if(setwise_coprime){
    cout<<"setwise coprime"<<endl;
  }
  else{
    cout<<"not coprime"<<endl;
  }


}

Fixed submission:
from math import gcd
max_a = int(2e6)
factor = [0]*max_a
for p in range(2,max_a):
  if factor[p]:
    continue
  factor[p] = p
  for x in range(p+p,max_a,p):
    if factor[x]:
      continue
    factor[x] = p

def prime_fac(ai):
  while factor[ai]:
    yield factor[ai]
    x = factor[ai]
    while x == factor[ai]:
      ai = int(ai/factor[ai])

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

cnt = [0]*max_a
loop_end = False
g = 0
pairwise_coprime = True
setwise_coprime = True

for ai in a:
  for p in prime_fac(ai):
    if cnt[p]:
      pairwise_coprime = False
      loop_end = True
    cnt[p] = 1
    if loop_end:
      break
  if loop_end:
    break

for ai in a:
  g = gcd(g,ai)
setwise_coprime = g==1

if pairwise_coprime:
  print('pairwise coprime')
elif setwise_coprime:
  print('setwise coprime')
else:
  print('not coprime')
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))
p = [pi-1 for pi in p]

ans = -1e18
for i in range(n):
  cur = p[i]
  loop = [c[cur]]
  cnt = 1
  ans = max(ans,c[cur])
  while cur != i and cnt<k:
    cur = p[cur]
    tmp = loop[-1]+c[cur]
    loop.append(tmp)
    ans = max(ans,tmp)
    cnt += 1
  #print(loop)
  if cnt==k or loop[-1]<=0:continue
  a = k//len(loop) * loop[-1]
  b = (k//len(loop)-1) * loop[-1]
  ans = max(ans,a,b)
  for _ in range(k%len(loop)):
    a += c[cur]
    ans = max(ans,a)
    cur = p[cur]
  cur = i
  for _ in range(len(loop)):
    b += c[cur]
    ans = max(ans,b)
    cur = p[cur]
print(ans)

Fixed submission:
n,k = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))
p = [pi-1 for pi in p]

ans = -1e18
for i in range(n):
  cur = p[i]
  loop = [c[cur]]
  cnt = 1
  ans = max(ans,c[cur])
  while cur != i and cnt<k:
    cur = p[cur]
    tmp = loop[-1]+c[cur]
    loop.append(tmp)
    ans = max(ans,tmp)
    cnt += 1
  #print(loop)
  if cnt==k or loop[-1]<=0:continue
  a = k//len(loop) * loop[-1]
  b = (k//len(loop)-1) * loop[-1]
  ans = max(ans,a,b)
  for _ in range(k%len(loop)):
    a += c[cur]
    ans = max(ans,a)
    cur = p[cur]
  cur = i
  for _ in range(len(loop)):
    b += c[cur]
    ans = max(ans,b)
    cur = p[cur]
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
S=list(s)
T=list(t)
S.sort()
T.sort()
T.reverse()
s=str(S)
t=str(T)



i=0
a=False
for wer in range( len(S) ):
    if S[i]<T[i]:
        a=True
        break
    i+=1
   

if a:print("Yes")
else :print("No")

Fixed submission:
s=input()
t=input()
S=list(s)
T=list(t)
S.sort()
T.sort()
T.reverse()
s=str(S)
t=str(T)

if S<T:print("Yes")
else :print("No")

Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
S=list(s)
T=list(t)
S.sort()
T.sort()
T.reverse()
s=str(S)
t=str(T)


a=True

for i in range(10):
    if s[i]>t[i]:
        a=False


if a: print("Yes")


Fixed submission:
s=input()
t=input()
S=list(s)
T=list(t)
S.sort()
T.sort()
T.reverse()
s=str(S)
t=str(T)

if S<T:print("Yes")
else :print("No")

Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
S=list(s)
T=list(t)
S.sort()
T.sort()
T.reverse()
s=str(S)
t=str(T)
for char in S:
    print(char,end="")
print()
for char in T:
    print(char,end="")
print()

a=True

for i in range(10):
    if s[i]>t[i]:
        a=False


if a: print("Yes")


Fixed submission:
s=input()
t=input()
S=list(s)
T=list(t)
S.sort()
T.sort()
T.reverse()
s=str(S)
t=str(T)

if S<T:print("Yes")
else :print("No")
Buggy python submission (verdict: Time Limit Exceeded):
class Doubling:
    m = 0
    to = [[]]
    # fを次の値を得る関数として、[0,n)のvについて最大でf^k(v)を得られる。
    def __init__(self, n, f, k):
        while k > 0:
            k = k >> 1
            self.m += 1
        self.to = [[-1] * n for _ in range(self.m+1)]
        for j in range(n):
            self.to[0][j] = f(j)
        for i in range(self.m):
            for j in range(n):
                if self.to[i][j] == -1:
                    self.to[i+1][j] = -1
                else:
                    self.to[i+1][j] = self.to[i][self.to[i][j]]

    # p番目の値のq個先を得る。
    def query(self, p, q):
        for i in range(self.m+1):
            if p == -1:
                break
            if (q >> i) & 1:
                p = self.to[i][p]
        return p

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

d = Doubling(n, lambda x: a[x]-1, k)
print(d.query(0, k) + 1)


Fixed submission:
class Doubling:
    m = 0
    to = [[]]
    # fを次の値を得る関数として、[0,n)のvについて最大でf^k(v)を得られる。
    def __init__(self, n, f, k):
        while k > 0:
            k = k >> 1
            self.m += 1
        self.to = [[-1] * n for _ in range(self.m+1)]
        for j in range(n):
            self.to[0][j] = f(j)
        for i in range(self.m):
            for j in range(n):
                if self.to[i][j] == -1:
                    self.to[i+1][j] = -1
                else:
                    self.to[i+1][j] = self.to[i][self.to[i][j]]

    # p番目の値のq個先を得る。
    def query(self, p, q):
        for i in range(self.m+1):
            if p == -1:
                break
            if (q >> i) & 1:
                p = self.to[i][p]
        return p

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

d = Doubling(n, lambda x: a[x]-1, k)
print(d.query(0, k) + 1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n,m,k = map(int, input().split())
f = [[] for _ in range(n)]
g = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    f[a].append(b)
    f[b].append(a)

for _ in range(k):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1
    g[c].append(d)
    g[d].append(c)

d = {}
parent = [-1] * n
seen = [False] * n

# DFS
for i in range(n):
    if seen[i]:
        continue
    stack = deque()
    # グループは集合で管理
    d[i] = set([i])
    stack = [i]
    while stack:
        v = stack.pop()
        seen[v] = True
        # 親を設定して同じ連結成分であることを判別する
        parent[v] = i
        for nv in f[v]:
            if seen[nv]:
                continue
            # 集合に追加する
            d[i].add(nv)
            stack.append(nv)

ans = [0] * n
for i in range(n):
    # 連結成分ごとに集合を取り出す
    group = d[parent[i]]
    # 集合の全要素数 - 友達 - ブロック - 自分
    sum = len(group) - len(f[i]) - len(set(g[i]) & group) - 1
    ans[i] = sum

print(*ans)


Fixed submission:
import sys
from collections import deque

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n,m,k = map(int, input().split())
f = [[] for _ in range(n)]
g = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    f[a].append(b)
    f[b].append(a)

for _ in range(k):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1
    g[c].append(d)
    g[d].append(c)

d = {}
parent = [-1] * n
seen = [False] * n

for i in range(n):
    if seen[i]:
        continue
    stack = deque()
    d[i] = set([i])
    stack = [i]
    while stack:
        v = stack.pop()
        seen[v] = True
        parent[v] = i
        for nv in f[v]:
            if seen[nv]:
                continue
            d[i].add(nv)
            stack.append(nv)

ans = [0] * n
for i in range(n):
    group = d[parent[i]]
    tmp = len(group) - len(f[i]) - 1
    for j in g[i]:
        if j in group:
            tmp -= 1
    ans[i] = tmp

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = 10**9

# 個数制限なしナップザック問題
h,n = map(int, input().split())

# 二次元配列で
a,b = [],[]
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

dp = [[INF] * (h + 1) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
    for j in range(h + 1):
        if j <= a[i]:
            dp[i + 1][j] = min(dp[i][j], b[i])
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i])
print(dp[n][h])

# 一次元配列で
# dp = [INF]*(h+1)
# dp[0] = 0
# for i in range(n):
#     a,b = map(int, input().split())
#     for j in range(h):
#         nj = min(a+j, h)
#         dp[nj] = min(dp[nj], dp[j]+b)
# print(dp[-1])


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = 10**9

# 個数制限なしナップザック問題
h,n = map(int, input().split())
dp = [INF]*(h+1)
dp[0] = 0
for i in range(n):
    a,b = map(int, input().split())
    for j in range(h):
        nj = min(a+j, h)
        dp[nj] = min(dp[nj], dp[j]+b)

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

ans = 0
for i in range(60):
    one = 0
    for a in A:
        if (a & (1 << i) != 0):
            one += 1
    zero = N - one
    now = one * zero % mod
    ans += now * pow(2, i) % mod
    ans %= mod
print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

ans = 0
for i in range(60):
    one = 0
    for a in A:
        if (a & (1 << i) != 0):
            one += 1
    zero = N - one
    now = one * zero % mod
    ans += now * pow(2, i) % mod
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9+7


n, q = map(int, input().split())
g = [[] for _ in range(n)]
val = [0] * n

for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    val[p - 1] += x

seen = [False] * n
def dfs(v):
    seen[v] = True
    for nv in g[v]:
        if seen[nv]:
            continue
        val[nv] += val[v]
        dfs(nv)

dfs(0)
print(*val)


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9+7


n, q = map(int, input().split())
g = [[] for _ in range(n)]
val = [0] * n

for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    val[p - 1] += x

seen = [False] * n
def dfs(v):
    seen[v] = True
    for nv in g[v]:
        if seen[nv]:
            continue
        val[nv] += val[v]
        dfs(nv)

dfs(0)
print(*val)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

ans = 0
for bit in range(2**n):
    vsum = 0
    csum = 0
    for i in range(n):
        if (bit & (1 << i)):
            vsum += v[i]
            csum += c[i]
    ans = max(vsum - csum, ans)

print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

ans = 0
for bit in range(2**n):
    vsum = 0
    csum = 0
    for i in range(n):
        if (bit & (1 << i)):
            vsum += v[i]
            csum += c[i]
    ans = max(vsum - csum, ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n,k = map(int, input().split())
s = input().rstrip()

li = []
fi = int(s[0])
cnt = 1
for i in range(1, n):
    if s[i-1] == s[i]:
        cnt += 1
    else:
        li.append(cnt)
        cnt = 1
li.append(cnt)

sums = [0] * (len(li)+1)
for i in range(0,len(li)):
    sums[i+1] = li[i] + sums[i]

ans = 0
ma = k*2+1 if fi == 1 else k*2
nn = max(1, len(sums) - ma)
for i in range(nn, len(sums)):
    sum = sums[i] - sums[i-ma]
    ans = max(ans, sum)

print(ans)


Fixed submission:
import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n,k = map(int, input().split())
s = input()

ans = 0
cnt = 0
right = 1
for left in range(0, n):
    if left == 0 and s[left] == '0':
        cnt += 1

    if left > 0 and s[left] == '1' and s[left-1] == '0':
        cnt -= 1

    while right <= n - 1:
        if s[right] == '0' and s[right-1] == '1':
            if cnt < k:
                cnt += 1
            else:
                break
        right += 1

    ans = max(ans, right - left)

print(ans)