Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):

class Result:
    def __init__(self, num, result):
        self.num = num
        self.result = result


def WelcomeTo():
    N, M = map(int, input().split())
    resultlist = []
    WAcountlist = []
    for _ in range(M):
        templist = input().split()
        resultlist.append(Result(int(templist[0]), templist[1]))
    for _ in range(0, N + 1):
        WAcountlist.append(0)

    AClist = []
    WAcount = 0
    for lst in resultlist:
        if lst.num in AClist:continue

        if lst.result == 'AC':
            AClist.append(lst.num)
            WAcount += WAcountlist[lst.num]
        else:
            WAcountlist[lst.num] += 1


    print('{} {}'.format(len(AClist), WAcount))


WelcomeTo()


Fixed submission:

class Question:
    def __init__(self, AC, WAcount):
        self.AC = AC
        self.WAcount = WAcount


def WelcomeTo():
    N, M = map(int, input().split())
    Qlist = []
    ACcount = 0
    WAcount = 0
    for _ in range(0, N + 1):
        Qlist.append(Question('False', 0))
    for _ in range(M):
        num, judge = input().split()
        num = int(num)
        if Qlist[num].AC == 'True':continue

        if judge == 'AC':
            ACcount += 1
            WAcount += Qlist[num].WAcount
            Qlist[num].AC = 'True'
        elif judge == 'WA':
            Qlist[num].WAcount += 1

    print('{} {}'.format(ACcount, WAcount))


WelcomeTo()

Buggy python submission (verdict: Time Limit Exceeded):

class Result:
    def __init__(self, num, result):
        self.num = num
        self.result = result


def WelcomeTo():
    N, M = map(int, input().split())
    resultlist = []
    WAcountlist = []
    for _ in range(M):
        templist = input().split()
        resultlist.append(Result(int(templist[0]), templist[1]))
    for _ in range(0, N + 1):
        WAcountlist.append(0)

    AClist = []
    for lst in resultlist:
        if lst.num in AClist:continue
        if lst.result == 'AC':
            AClist.append(lst.num)
        else:
            WAcountlist[lst.num] += 1

    WAcount = 0
    for i in AClist:
        WAcount += WAcountlist[i]

    print('{} {}'.format(len(AClist), WAcount))


WelcomeTo()


Fixed submission:

class Question:
    def __init__(self, AC, WAcount):
        self.AC = AC
        self.WAcount = WAcount


def WelcomeTo():
    N, M = map(int, input().split())
    Qlist = []
    ACcount = 0
    WAcount = 0
    for _ in range(0, N + 1):
        Qlist.append(Question('False', 0))
    for _ in range(M):
        num, judge = input().split()
        num = int(num)
        if Qlist[num].AC == 'True':continue

        if judge == 'AC':
            ACcount += 1
            WAcount += Qlist[num].WAcount
            Qlist[num].AC = 'True'
        elif judge == 'WA':
            Qlist[num].WAcount += 1

    print('{} {}'.format(ACcount, WAcount))


WelcomeTo()
Buggy python submission (verdict: Time Limit Exceeded):

def Attention():
    N = int(input())
    S = input()
    ans = 300000

    for i in range(N):
        count = S[:i-1].count('W') + S[i+1:].count('E')

        ans = min(ans, count)
    print(ans)

Attention()


Fixed submission:

def Attention():
    N = int(input())
    S = input()
    ans = 300000

    Wcount = [0]
    Ecount = [0]
    cnt = 0
    for i in range(N):
        if S[i] == 'W':
            cnt += 1
        Wcount.append(cnt)
    cnt = 0
    for i in range(N):
        if S[(i + 1) * -1] == 'E':
            cnt += 1
        Ecount.append(cnt)

    for i in range(N):
        cnt = Wcount[i] + Ecount[(i + 2) * -1]
        ans = min(cnt, ans)
    print(ans)

Attention()

Buggy python submission (verdict: Time Limit Exceeded):

def Attention():
    N = int(input())
    S = input()
    ans = 300000

    for i in range(N):
        count = len(S[:i-1].replace('E', '')) + len(S[i+1:].replace('W', ''))

        """
        for a in S[:i-1]:
            if a == 'W':count+=1
        for a in S[i+1:]:
            if a == 'E':count+=1'
        ans = min(ans, count)
        """
        ans = min(ans, count)
    print(ans)

Attention()


Fixed submission:

def Attention():
    N = int(input())
    S = input()
    ans = 300000

    Wcount = [0]
    Ecount = [0]
    cnt = 0
    for i in range(N):
        if S[i] == 'W':
            cnt += 1
        Wcount.append(cnt)
    cnt = 0
    for i in range(N):
        if S[(i + 1) * -1] == 'E':
            cnt += 1
        Ecount.append(cnt)

    for i in range(N):
        cnt = Wcount[i] + Ecount[(i + 2) * -1]
        ans = min(cnt, ans)
    print(ans)

Attention()

Buggy python submission (verdict: Time Limit Exceeded):

def Attention():
    N = int(input())
    S = list(input())
    ans = 300000

    for i in range(N):
        count = 0
        for a in S[:i-1]:
            if a == 'W':count+=1
        for a in S[i+1:]:
            if a == 'E':count+=1
        ans = min(ans, count)
    print(ans)

Attention()


Fixed submission:

def Attention():
    N = int(input())
    S = input()
    ans = 300000

    Wcount = [0]
    Ecount = [0]
    cnt = 0
    for i in range(N):
        if S[i] == 'W':
            cnt += 1
        Wcount.append(cnt)
    cnt = 0
    for i in range(N):
        if S[(i + 1) * -1] == 'E':
            cnt += 1
        Ecount.append(cnt)

    for i in range(N):
        cnt = Wcount[i] + Ecount[(i + 2) * -1]
        ans = min(cnt, ans)
    print(ans)

Attention()
Buggy python submission (verdict: Time Limit Exceeded):
def ABC068C():
    N, M = map(int, input().split())
    ship_first = []
    ship_second = []
    for _ in range(M):
        a, b = map(int, input().split())
        if a == 1:
            if b == N:
                print('POSSIBLE')
                return
            else:
                ship_first.append(b)
        elif b == N:
            ship_second.append(a)

    for i in ship_first:
        if i in ship_second:
            print('POSSIBLE')
            return

    print('IMPOSSIBLE')
    return

ABC068C()


Fixed submission:
def ABC068C():
    N, M = map(int, input().split())
    flag = [[False, False] for _ in range(N)]

    for _ in range(M):
        a, b = map(int, input().split())
        if a == 1:
            flag[b][0] = True
        elif b == N:
            flag[a][1] = True

    for i in range(N):
        if flag[i][0] and flag[i][1]:
            print('POSSIBLE')
            return

    print('IMPOSSIBLE')
    return

ABC068C()
Buggy python submission (verdict: Time Limit Exceeded):
def TrainingCamp():
    N = int(input())
    power = 1
    for i in range(1, N + 1):
        power *= i
    print(power % (10 ** 9 + 7))

TrainingCamp()


Fixed submission:
def TrainingCamp():
    mod = 10 ** 9 + 7
    N = int(input())
    power = 1
    for i in range(1, N + 1):
        power *= i
        power %= mod
    print(power)

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

import sys
sys.setrecursionlimit(2000)

pins = set()
pins_1 = set()
pins_2 = set()

def dfs(s, pin, cnt):
    if cnt == 1:
        if pin in pins_1:
            return
        pins_1.add(pin)
    if cnt == 2:
        if pin in pins_2:
            return
        pins_2.add(pin)    
    if cnt == 3:
        pins.add(pin)
    for i in range(len(s)):
        dfs(s[i+1:], pin+s[i], cnt+1)
        
dfs(S, '', 0)
print(len(pins))


Fixed submission:
N = int(input())
S = input()


pins = set()
pins_check = set()

def bfs():    
    from collections import deque
    queue = deque([(S, '', 0)])
    while queue:
        tmp_s, tmp_pin, tmp_cnt = queue.popleft()
        if tmp_cnt == 3:
            pins.add(tmp_pin)
            continue
        
        for i in range(len(tmp_s)):
            if tmp_pin+tmp_s[i] in pins_check:
                continue
            pins_check.add(tmp_pin+tmp_s[i])
            queue.append((tmp_s[i+1:], tmp_pin+tmp_s[i], tmp_cnt+1))

ans = bfs()
#print(pins)
print(len(pins))

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

import sys
sys.setrecursionlimit(2000)

pins = set()
def dfs(s, pin, cnt):
    if cnt == 3:
        pins.add(pin)
    for i in range(len(s)):
        dfs(s[i+1:], pin+s[i], cnt+1)
        
dfs(S, '', 0)
print(len(pins))


Fixed submission:
N = int(input())
S = input()


pins = set()
pins_check = set()

def bfs():    
    from collections import deque
    queue = deque([(S, '', 0)])
    while queue:
        tmp_s, tmp_pin, tmp_cnt = queue.popleft()
        if tmp_cnt == 3:
            pins.add(tmp_pin)
            continue
        
        for i in range(len(tmp_s)):
            if tmp_pin+tmp_s[i] in pins_check:
                continue
            pins_check.add(tmp_pin+tmp_s[i])
            queue.append((tmp_s[i+1:], tmp_pin+tmp_s[i], tmp_cnt+1))

ans = bfs()
#print(pins)
print(len(pins))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [None] * N
for i in range(N):
    S[i] = input()
nums = [None] * N
for i, s in enumerate(S):
    tmp = [0] * 26
    for c in s:
        tmp[ord(c)-97] += 1
    nums[i] = ' '.join(map(str, tmp))

ans = 0
for i, s_i in enumerate(nums):
    for s_j in nums[i+1:]:
        if s_i == s_j:
            ans += 1
print(ans)

Fixed submission:
N = int(input())
S = [None] * N
for i in range(N):
    S[i] = input()
nums = [None] * N
for i, s in enumerate(S):
    tmp = [0] * 26
    for c in s:
        tmp[ord(c)-97] += 1
    nums[i] = ' '.join(map(str, tmp))

ans = 0
checker = dict()

for s in reversed(nums):
    #print(s)
    if s in checker:
        ans += checker[s]
        checker[s] += 1
    else:
        checker[s] = 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M  = map(int, input().split())
AB = [None] * N
for i in range(N):
    a, b = map(int, input().split())
    AB[i] = (a, b)
days_limit = M

jobs = AB[:]
jobs_dict = {i: [] for i in range(M+1)}
for d, r in jobs:
    jobs_dict[d].append(r)
#print(jobs_dict)

import heapq
hq = []

ans = 0
for d in range(1, M+1):
    for r in jobs_dict[d]:
        heapq.heappush(hq,-r)
    if hq:
        ans += -1 * heapq.heappop(hq)
print(ans)

    


Fixed submission:
N, M  = map(int, input().split())
AB = [None] * N
for i in range(N):
    a, b = map(int, input().split())
    AB[i] = (a, b)
    
days_limit = M

jobs = AB[:]
from collections import defaultdict
jobs_dict = defaultdict(lambda: [])
for d, r in jobs:
    jobs_dict[d].append(r)
#print(jobs_dict)

import heapq
hq = []

ans = 0
for d in range(1, M+1):
    for r in jobs_dict[d]:
        heapq.heappush(hq,-r)
    if hq:
        ans += -1 * heapq.heappop(hq)
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M  = map(int, input().split())
AB = [None] * N
for i in range(N):
    a, b = map(int, input().split())
    AB[i] = (a, b)
days_limit = M

jobs = AB[:]
jobs_dict = {i: [] for i in range(M+1)}
for d, r in jobs:
    jobs_dict[d].append(r)
#print(jobs_dict)

import heapq
hq = []

ans = 0
for d in range(1, M+1):
    for r in jobs_dict[d]:
        heapq.heappush(hq,-r)
    ans += -1 * heapq.heappop(hq)
print(ans)

    

Fixed submission:
N, M  = map(int, input().split())
AB = [None] * N
for i in range(N):
    a, b = map(int, input().split())
    AB[i] = (a, b)
    
days_limit = M

jobs = AB[:]
from collections import defaultdict
jobs_dict = defaultdict(lambda: [])
for d, r in jobs:
    jobs_dict[d].append(r)
#print(jobs_dict)

import heapq
hq = []

ans = 0
for d in range(1, M+1):
    for r in jobs_dict[d]:
        heapq.heappush(hq,-r)
    if hq:
        ans += -1 * heapq.heappop(hq)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M  = map(int, input().split())
AB = [None] * N
for i in range(N):
    a, b = map(int, input().split())
    AB[i] = (a, b)
    
days_limit = M

jobs = AB[:]
jobs  =sorted(jobs, key=lambda x: x[1], reverse=True)
#print(jobs)

plan = [0] * (days_limit+1)

for d, r in jobs:
    while not d > days_limit:
        if plan[d] == 0:
            plan[d] = r
            break
        else:
            d += 1
#print(plan)
print(sum(plan))
    

Fixed submission:
N, M  = map(int, input().split())
AB = [None] * N
for i in range(N):
    a, b = map(int, input().split())
    AB[i] = (a, b)
    
days_limit = M

jobs = AB[:]
from collections import defaultdict
jobs_dict = defaultdict(lambda: [])
for d, r in jobs:
    jobs_dict[d].append(r)
#print(jobs_dict)

import heapq
hq = []

ans = 0
for d in range(1, M+1):
    for r in jobs_dict[d]:
        heapq.heappush(hq,-r)
    if hq:
        ans += -1 * heapq.heappop(hq)
print(ans)
Buggy python submission (verdict: Runtime Error):
K = int(input())
X, Y = map(int, input().split())

def move(a, b, _a, _b, _s):
    # x, y > 0 and x < y
    if a < 0: 
        return move(-a, b, -1, _b, _s)
    if b < 0:
        return move(a, -b, _a, -1, _s)
    if a > b:
        return move(b, a, _b, _a, True)
    # ここから移動処理
    if a + b == K:
        return (0, 0)
    
    if a + b >= 2*K:
        ret = (a, b-K)
    else:
        r = K - (a + b)//2
        ret = (-r, b-K+a+r)
    # 後処理
    ret = _a * ret[0], _b * ret[1]
    ret = (ret[1], ret[0]) if _s else ret
    return ret

x, y = X, Y

if K % 2 == 0 and (x+y) % 2:
    print(-1)
else:
    ANS = []
    while x != 0 and y != 0:
        ANS.append((x, y))
        x, y = move(x, y, 1, 1, False)
    print(len(ANS))
    for ans in ANS[::-1]:
        print(ans[0], ans[1])

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

K = (A + B) / 2

if A == B:
    print(0)
elif K.is_integer():
    print(int(K))
else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = []
for _ in range(N):
    a = int(input())
    A.append(a)
    
BALL = A[:]

from collections import defaultdict
COLOR = defaultdict(lambda: -1)

for b in BALL:
    i = 0
    while True:
        if COLOR[i] < b:
            COLOR[i] = b
            break
        i += 1
            
#print(COLOR)
print(len(COLOR))


Fixed submission:
N = int(input())

A = []
for _ in range(N):
    a = int(input())
    A.append(a)
    
nums = A[:]
colors = [float('inf')] * N

from bisect import bisect_left, bisect_right, insort_right
ans = 0
for n in nums:
    idx = bisect_right(colors, -n)
    colors[idx] = -n
    #print(ans)
    if idx > ans:
        ans = idx
    #print(idx, colors)
            
print(ans+1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

water = A[:]
#print(water)

ans = []
for x in range(0, max(water[0], water[-1])*2+1, 2):
    #print(x)
    ans = [x]
    for i, a in enumerate(water):
        y = 2*a - x
        #print(y)
        if y % 2 == 1:
            break
        ans.append(y)
        x = y
    if len(ans) == N+1 and ans[0] == ans[-1]:
        #print(len(ans), N)
        break
print(' '.join(list(map(str, ans[:-1]))))

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

water = A[:]
#print(water)

ans = []
x = 0
#print(x)
ans = [x]
for i, a in enumerate(water):
    y = 2*a - x
    #print(y)
    ans.append(y)
    x = y
#print(ans, sum(ans))

x = (ans[0] + ans[-1]) // 2
ans = [x]
for i, a in enumerate(water):
    y = 2*a - x
    #print(y)
    ans.append(y)
    x = y
#print(ans, sum(ans))





print(' '.join(list(map(str, ans[:-1]))))

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

water = A[:]
#print(water)

ans = []
for x in range(0, water[0]*2+1, 2):
    #print(x)
    ans = [x]
    for i, a in enumerate(water):
        y = 2*a - ans[i]
        if y % 2 == 1:
            break
        ans.append(y)
    if len(ans) == N+1 and ans[0] == ans[-1]:
        #print(len(ans), N)
        break
print(' '.join(list(map(str, ans[:-1]))))

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

water = A[:]
#print(water)

ans = []
x = 0
#print(x)
ans = [x]
for i, a in enumerate(water):
    y = 2*a - x
    #print(y)
    ans.append(y)
    x = y
#print(ans, sum(ans))

x = (ans[0] + ans[-1]) // 2
ans = [x]
for i, a in enumerate(water):
    y = 2*a - x
    #print(y)
    ans.append(y)
    x = y
#print(ans, sum(ans))





print(' '.join(list(map(str, ans[:-1]))))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


blue = K
red = N - K

for i in range(1, K+1):
    pos = i 
    red_c = combinations_count(red+1, pos)
    
    
    blue_c =  combinations_count(blue - 1, i - 1)
    #print(red_c, blue_c)
    print(red_c * blue_c % (10 ** 9 + 7))
    
    
    

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

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


blue = K
red = N - K

for i in range(1, K+1):
    try:
        pos = i 
        red_c = combinations_count(red+1, pos)


        blue_c =  combinations_count(blue - 1, i - 1)
        #print(red_c, blue_c)
        print(red_c * blue_c % (10 ** 9 + 7))
    except:
        print(0)
Buggy python submission (verdict: Runtime Error):
N = int(input())

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x,y))
    
import itertools
import collections
import sys

sys.setrecursionlimit(10000)

ans_list = []
for v in itertools.permutations(XY):
    count_list = []
    for (x0, y0), (x1,y1) in zip(v[1:], v[:-1]):
        count_list.append((x1-x0, y1-y0))
    ans_list.append(max(collections.Counter(count_list).values()))
    
ans = N-max(ans_list)
print(ans)
    

    



Fixed submission:
N = int(input())

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x,y))
    
from collections import defaultdict

dd = defaultdict(lambda:defaultdict(bool))

X = sorted(XY)

for x,y in XY:
    dd[x][y] = True

max_count = 0
for i, (x0, y0) in enumerate(X):
    for x1, y1 in X[i+1:]:
        diff_x, diff_y = (x1-x0, y1-y0)
        counter = 0
        for x, y in X:
            if dd[x+diff_x][y+diff_y]:
                counter += 1
        max_count = max(max_count, counter)
#print(max_count)

ans = N - max_count
print(ans)

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

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x,y))
    
    
import itertools
import collections

ans_list = []
for v in itertools.permutations(XY):
    count_list = []
    for (x0, y0), (x1,y1) in zip(v[1:], v[:-1]):
        count_list.append((x1-x0, y1-y0))
    ans_list.append(max(collections.Counter(count_list).values()))
    
ans = N-max(ans_list)
print(ans)
    

    



Fixed submission:
N = int(input())

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x,y))
    
from collections import defaultdict

dd = defaultdict(lambda:defaultdict(bool))

X = sorted(XY)

for x,y in XY:
    dd[x][y] = True

max_count = 0
for i, (x0, y0) in enumerate(X):
    for x1, y1 in X[i+1:]:
        diff_x, diff_y = (x1-x0, y1-y0)
        counter = 0
        for x, y in X:
            if dd[x+diff_x][y+diff_y]:
                counter += 1
        max_count = max(max_count, counter)
#print(max_count)

ans = N - max_count
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
V = list(map(int, input().split()))

import copy

import sys

INT_MIN = -1 * sys.maxsize

import bisect

def dfs(k, v_q, v_plus, v_minus):
    v_p_sum = sum(v_plus)
    #if k == 0:
    #    return v_p_sum + sum(v_minus)
    #c = INT_MIN
    if k < len(v_minus):
        #v_minus = sorted(v_minus)
        c = v_p_sum + sum(v_minus[k:])
        return c
    
    
    v_q_left = copy.copy(v_q)
    l = v_q_left.popleft()
    if l >= 0:
        a = dfs(k-1, v_q_left, v_plus[:]+[l], v_minus[:])
    else:
        tmp = v_minus[:]
        bisect.insort(tmp, l)
        a = dfs(k-1, v_q_left, v_plus[:], tmp)
    
    v_q_right = copy.copy(v_q)
    r = v_q_right.pop()
    if r >= 0:
        b = dfs(k-1, v_q_right, v_plus[:]+[r], v_minus[:])
    else:
        tmp = v_minus[:]
        bisect.insort(tmp, r)
        b = dfs(k-1, v_q_right, v_plus[:], tmp)
    
    return max([a, b, v_p_sum])
    


from collections import deque
v_q = deque(V)

ans = dfs(K, v_q, [], [])
print(ans)

    
    

Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))

# N < Kの場合があることに注意


INT_MIN = -1 * (10**10)

ans = INT_MIN

NK = min(N, K)
for left in range(0,NK+1):
    for right in range(0, NK+1-left):
        #print("========")
        #print(left, right)
        #print(V[:left], V[left:N-right], V[N-right:])
        
        rest_ope = K-left-right
        #print(rest_ope)
        my_v = V[:left]+V[N-right:]
        sum_v = 0
        for i, x in enumerate(sorted(my_v)):
            if x < 0 and i < rest_ope:
                continue
            else:
                sum_v += x
        #print(sum_v)
        ans = max(ans, sum_v)
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

LR = []
for _ in range(M):
    l, r = map(int, input().split())
    LR.append((l, r))
    
cards = LR[:]
master_ids = set(range(cards[0][0], cards[0][1]+1))
for l, r in cards:
    ids = set(range(l, r+1))
    master_ids = master_ids & ids
    if not master_ids:
        break
    
ans = len(master_ids)
print(ans)


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

LR = []
for _ in range(M):
    l, r = map(int, input().split())
    LR.append((l, r))
    
cards = LR[:]

import sys
INT_MAX = sys.maxsize

left_id = 0
right_id = INT_MAX
for l, r in cards:
    left_id = max(left_id, l)
    right_id = min(right_id, r)
    
if left_id <= right_id:
    ans = right_id + 1 - left_id
else:
    ans = 0
print(ans)

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

LR = []
for _ in range(M):
    l, r = map(int, input().split())
    LR.append((l, r))
    
cards = LR[:]
master_ids = set(range(cards[0][0], cards[0][1]+1))
for l, r in cards:
    ids = set(range(l, r+1))
    master_ids = master_ids & ids
    #print(ids, master_ids)
    
ans = len(master_ids)
print(ans)


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

LR = []
for _ in range(M):
    l, r = map(int, input().split())
    LR.append((l, r))
    
cards = LR[:]

import sys
INT_MAX = sys.maxsize

left_id = 0
right_id = INT_MAX
for l, r in cards:
    left_id = max(left_id, l)
    right_id = min(right_id, r)
    
if left_id <= right_id:
    ans = right_id + 1 - left_id
else:
    ans = 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
V = []
for _ in range(N-1):
    u, v, w = map(int, input().split())
    V.append((u,v,w))

edges = V[:]

def warshall_floyd(d, n):
    # d: グラフ二次元リスト
    # n: 頂点数 (0始まり)
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

graph = [[float("inf") for i in range(N)] for i in range(N)] 
for x,y,z in edges:
    graph[x-1][y-1] = z
    graph[y-1][x-1] = z
for i in range(N):
    graph[i][i] = 0 #自身のところに行くコストは０
shortest = warshall_floyd(graph, N)

color = [1] * N
color[0] = 0

for i, sub in enumerate(shortest):
    for j, l in enumerate(sub):
        if l % 2 == 0:
            color[j] = color[i]
for c in color:
    print(c)

Fixed submission:
N = int(input())
V = []
for _ in range(N-1):
    u, v, w = map(int, input().split())
    V.append((u,v,w))
    
edges = V[:]

from heapq import heappush, heappop

def dijkstra(graph, start):
    A = [None] * (N)
    queue = [(0, start)]
    while queue:
        path_len, v = heappop(queue)
        if A[v] is None: # v is unvisited
            A[v] = path_len
            for w, edge_len in graph[v].items():
                if A[w] is None:
                    heappush(queue, (path_len + edge_len, w))

    # to give same result as original, assign zero distance to unreachable vertices             
    return [0 if x is None else x for x in A]



# 無効グラフなので双方向にする
graph = {}
for a,b,c in edges:
    a = a-1
    b = b-1
    if not a in graph:
        graph[a] = {}
    if not b in graph:
        graph[b] = {}
    graph[a][b] = c
    graph[b][a] = c
    
    
shortest = dijkstra(graph, 0)

for s in shortest:
    print(s % 2)