Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque

def main():
    def gen():
        counter = 0
        q = deque(range(1, 10))
        while counter < 100001:
            n = q.popleft()
            yield n
            counter += 1
            t = n % 10
            if t > 0:
                q.append(n*10 + (t - 1))
            q.append(n*10 + t)
            if t < 9:
                q.append(n*10 + (t + 1))
    g = gen()
    for _ in range(ii() - 1):
        next(g)
    print(next(g))

main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    def gen():
        counter = 0
        q = deque(range(1, 10))
        while counter < 100001:
            n = q.popleft()
            yield n
            counter += 1
            t = n % 10
            if t > 0:
                q.append(n*10 + (t - 1))
            q.append(n*10 + t)
            if t < 9:
                q.append(n*10 + (t + 1))
    g = gen()
    for _ in range(ii() - 1):
        next(g)
    print(next(g))

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def main():
    X,Y,R,G,B=mis()
    rs=lmis()
    rs.sort(reverse=True)
    gs=lmis()
    gs.sort(reverse=True)
    bs=lmis()
    bs.sort(reverse=True)
    def get_score(red_paint):
        if red_paint > B:
            return INF
        if Y > G + (B - red_paint):
            return INF
        ans = 0
        ans += sum(bs[:red_paint])
        ans += sum(rs[:X - red_paint])
        gi = 0
        bi = red_paint
        for _ in range(Y):
            if G == gi:
                go_g = False
            elif B == bi:
                go_g = True
            else:
                go_g = (gs[gi] >= bs[bi])
            if go_g:
                ans += gs[gi]
                gi += 1
            else:
                ans += bs[bi]
                bi += 1
        return ans
    print(max(get_score(i) for i in range(X+1)))


main()







Fixed submission:
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

def main():
    X, Y, A, B, C = mis()
    p = sorted(lmis(), reverse=True)[:X]
    q = sorted(lmis(), reverse=True)[:Y]
    r = lmis()
    print(sum(sorted(p+q+r, reverse=True)[:X+Y]))

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    N,K = mis()
    import numpy as np
    p = np.array(lmis())
    o = np.ones((K,))
    print(np.max(np.convolve(p, o, mode='valid')+K)/2)


main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    N, K = mis()
    A = lmis()
    tmp = sum(A[:K])
    tmp_max = tmp
    for i in range(K, N):
        tmp += A[i] - A[i-K]
        tmp_max = max(tmp_max, tmp)
    print((tmp_max+K)/2)


main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    def getxl():
        x,l=mis()
        return x-l,x+l
    R = [getxl() for _ in range(N)]
    R.sort(key=lambda xl: xl[0])
    @lru_cache(maxsize=2**20)
    def cou(x):
        if R[-1][0] < x:
            return 0
        at = meg(lambda i: x<=R[i][0], N, -1)
        ret = max(cou(R[i][1])+1 for i in range(at, N))
        return ret
    print(cou(-10000000000))

main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N=ii()
    rs = []
    for _ in range(N):
        x, l = mis()
        rs.append((x-l, x+l))
    rs.sort(key=lambda t: t[1])
    ans = 0
    right = rs[0][0] - 1
    for r in rs:
        if right <= r[0]:
            ans += 1
            right = r[1]
    print(ans)

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    N,K=mis()
    A=lmis()
    A.sort()
    #
    fs = factorials_list(N, N1097)
    invs = invs_list(N, fs, N1097)
    #
    ans = 0
    for i in range(N):
        if K-1 <= i:
            ans += (A[i] - A[N-1-i]) * comb(i, K-1, N1097)
    print(ans % N1097)

main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def factorial_list_mod(n, modp):
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    invs = [pow(fs[-1], modp-2, modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return fs, invs

def comb_mod(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    N,K=mis()
    A=lmis()
    A.sort()
    #
    fs, invs = factorial_list_mod(N, N1097)
    #
    ans = 0
    for i in range(N):
        if K-1 <= i:
            ans += A[i] * comb_mod(i, K-1, N1097, fs, invs)
    A.reverse()
    for i in range(N):
        if K-1 <= i:
            ans -= A[i] * comb_mod(i, K-1, N1097, fs, invs)
    print(ans % N1097)

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    T1,T2 = mis()
    A1,A2 = mis()
    B1,B2 = mis()
    d1 = T1*A1 - T1*B1
    d2 = T2*A2 - T2*B2
    if d1 + d2 == 0:
        print('infinity')
    elif d1 < 0 > d2 or d1 > 0 < d2:
        print(0)
    else:
        ans = -1
        pos = 0
        if d1 < 0:
            d1 *= -1
            d2 *= -1
        while True:
            pos += d1
            if pos == 0:
                ans += 1
                break
            elif pos < 0:
                break
            else:
                ans += 1
            pos += d2
            ans += 1
        print(ans)




main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    T1,T2 = mis()
    A1,A2 = mis()
    B1,B2 = mis()
    d1 = T1*A1 - T1*B1
    d2 = T2*A2 - T2*B2
    if d1 + d2 == 0:
        print('infinity')
    elif d1 < 0 > d2 or d1 > 0 < d2:
        print(0)
    else:
        if d1 < 0:
            d1 *= -1
            d2 *= -1
        if d1 + d2 > 0:
            print(0)
        elif d1 % (d1+d2) == 0:
            print(d1 // abs(d1+d2) * 2)
        else:
            print(d1 // abs(d1+d2) * 2 + 1)




main()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    N, K = mis()
    A = [0] + lmis()
    for i in range(1, len(A)):
        A[i] = ((A[i] - 1) + A[i-1]) % K
    #
    C = [0] * (max(A)+1)
    ans = 0
    for i in range(len(A)):
        if i >= K:
            C[A[i-K]] -= 1
        a = A[i]
        ans += C[a]
        C[a] += 1
    print(ans)

main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    N, K = mis()
    A = [0] + lmis()
    for i in range(1, len(A)):
        A[i] = ((A[i] - 1) + A[i-1]) % K
    #
    C = defaultdict(int)
    ans = 0
    for i in range(len(A)):
        if i >= K:
            C[A[i-K]] -= 1
        a = A[i]
        ans += C[a]
        C[a] += 1
    print(ans)

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
ii0 = lambda: ii() - 1
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    N, K = mis()
    A = lmis()
    A.sort(reverse=True)
    F = lmis()
    F.sort()
    #
    class solver:
        def __getitem__(self, score_limit):
            k = K
            for i in range(N):
                if A[i]*F[i] > score_limit:
                    k -= A[i] - score_limit//F[i]
                    if k < 0:
                        return False
            return True
        def __len__(self):
            return max(A)*max(F)
    #
    import bisect
    print(bisect.bisect_left(solver(), True))

main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
ii0 = lambda: ii() - 1
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    N, K = mis()
    A = lmis()
    A.sort(reverse=True)
    F = lmis()
    F.sort()
    #
    class solver:
        def __getitem__(self, score_limit):
            k = K
            for i in range(N):
                if A[i]*F[i] > score_limit:
                    k -= A[i] - score_limit//F[i]
                    if k < 0:
                        return False
            return True
    #
    import bisect
    print(bisect.bisect_left(solver(), True, hi=A[0]*F[-1]))

main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
ii0 = lambda: ii() - 1
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    N, K = mis()
    A = lmis()
    A.sort(reverse=True)
    F = lmis()
    F.sort()
    #
    class solver:
        def __getitem__(self, score_limit):
            k = K
            for i in range(N):
                if A[i]*F[i] > score_limit:
                    k -= A[i] - score_limit//F[i]
                    if k < 0:
                        return False
            return True
        def __len__(self):
            return (10**6)**2
    #
    import bisect
    print(bisect.bisect_left(solver(), True))

main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
ii0 = lambda: ii() - 1
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    N, K = mis()
    A = lmis()
    A.sort(reverse=True)
    F = lmis()
    F.sort()
    #
    class solver:
        def __getitem__(self, score_limit):
            k = K
            for i in range(N):
                if A[i]*F[i] > score_limit:
                    k -= A[i] - score_limit//F[i]
                    if k < 0:
                        return False
            return True
    #
    import bisect
    print(bisect.bisect_left(solver(), True, hi=A[0]*F[-1]))

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

def main():
    A, B = mis()
    from fractions import gcd
    n = gcd(A,B)
    def get_common_divs(n1, n2):
        common_divs = set()
        i = 1
        while i*2 <= min(n1,n2):
            if n1%i == n2%i == 0:
                common_divs.add(i)
            i += 1
        return common_divs
    
    common_divs = get_common_divs(A,B)

    ans = {1}
    for d in common_divs:
        if all(gcd(a,d)==1 for a in ans):
            ans.add(d)

    ans = len(ans)
    print(ans)


main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
ii0 = lambda: ii() - 1
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def divs_gen(n):
    for i in range(1, int(m**.5)+1):
        if n%i == 0:
            yield i
            if i != n//i:
                yield n//i


def main():
    A, B = mis()
    from fractions import gcd
    G = gcd(A, B)
    fs = set()
    for i in range(2, int(G**0.5)+2):
        if G%i == 0 and all(i%f != 0 for f in fs):
            fs.add(i)
            while G%i == 0:
                G //= i
    if G > 1:
        fs.add(G)
    print(len(fs)+1)


main()
Buggy python submission (verdict: Runtime Error):
N = int(input())

import numpy as np

a = np.arange(1, N+1)
p = np.copy(a) + 1
p[-1] = 1

print(np.sum(a%p))


Fixed submission:
N = int(input())

print((N-1) * N // 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

a = [i for i in range(1, N+1)]
p = a.copy()
p = p[1:] + [p[0]]

print(sum([ai%pi for ai, pi in zip(a, p)]))


Fixed submission:
N = int(input())

print((N-1) * N // 2)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

d = {}
for _ in range(N):
    a, b = map(int, input().split())
    if a in d:
        d[a].append(b)
    else:
        d[a] = [b]

for l in d.values():
    l.sort()


ans = 0
for i in range(1,M+1):
    mx_a = None
    mx_b = 0
    for j in range(1, i+1):
        if j in d and d[j]:
            mx_b = max(mx_b, d[j][-1])
            mx_a = j
    if mx_a is not None:
        ans += mx_b
        d[mx_a].pop(-1)

print(ans)






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

B = [tuple(map(int, input().split())) for _ in range(N)]
B.sort(reverse=True)

import heapq

hq = []
ans = 0
for i in range(1, M+1):
    while B and B[-1][0] == i:
        heapq.heappush(hq, B.pop()[1]*(-1))
    if hq:
        ans -= heapq.heappop(hq)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

import numpy as np
a = np.zeros(N)

for _ in range(M):
    l, r = map(int, input().split())
    l-=1
    a[l:r] += 1

print(len(a[a==M]))


Fixed submission:
N, M = map(int, input().split())
 
L, R = 0, N
for _ in range(M):
    l, r = map(int, input().split())
    l-=1
    r-=1
    L = max(l, L)
    R = min(r, R)

print(R-L+1 if R-L>=0 else 0)
Buggy python submission (verdict: Runtime Error):
N = int(input())

data = [[] for _ in range(N)]
ans = [None] * N

for i in range(N-1):
    u,v,w = map(int, input().split())
    u -= 1
    v -= 1
    w &= 1
    data[u].append((v, w))
    data[v].append((u, w))

def f(i, color):
    for t, w in data[i]:
        if ans[t] is not None:
            continue
        ans[t] = color^w
        f(t, color^w)

f(0, 0)

for i in range(N):
    print(ans[i])


Fixed submission:
N = int(input())

data = [[] for _ in range(N)]
ans = [None] * N

for i in range(N-1):
    u,v,w = map(int, input().split())
    u -= 1
    v -= 1
    w &= 1
    data[u].append((v, w))
    data[v].append((u, w))

import sys
sys.setrecursionlimit(10000000)
def f(i, color):
    for t, w in data[i]:
        if ans[t] is not None:
            continue
        ans[t] = color^w
        f(t, color^w)

f(0, 0)

for i in range(N):
    print(ans[i])