Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
ans = ''
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
elif abs(first) * 2 < abs(second):
    ans = 1
else:
    if abs(first) % abs(last) == 0:
        ans = (abs(first) // abs(last)) * 2
    elif abs(first) * 2 == abs(last):
        ans = 2
    else:
        ans = math.floor(2 * abs(first) / abs(last))

Fixed submission:
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
else:
    s = abs(first) // abs(last)
    t = abs(first) % abs(last)
    ans = 2 * s
    if t != 0:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
else:
    ans = math.ceil(abs(first) / abs(last))
print(ans)

Fixed submission:
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
else:
    s = abs(first) // abs(last)
    t = abs(first) % abs(last)
    ans = 2 * s
    if t != 0:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a, b, x = map(int, input().split())
t = (a ** 3) / (2 * (a ** 2 * b - x))
if t >= (a / b):
    print(90 - (math.atan(t) / (math.pi)) * 180)
else:
    print(90 - (math.atan(x / (a * b * b)) / math.pi) * 180)

Fixed submission:
import math
a, b, x = map(int, input().split())
if (a ** 2 * b - x) > 0:
    t = (a ** 3) / (2 * (a ** 2 * b - x))
    if t >= (a / b):
        print(90 - (math.atan(t) / (math.pi)) * 180)
    else:
        print((math.atan(a * b * b / (2 * x)) / math.pi) * 180)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = bisect.bisect_left(l, l[i] + l[j])
        k = bisect.bisect_left(l, abs(l[i] - l[j]))
        if t > j:
            ans += t - max(k, j + 1)
print(ans)

Fixed submission:
import bisect
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = bisect.bisect_left(l, l[i] + l[j])
        if (t > j):
            ans += t - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = bisect.bisect_left(l[j+1:], l[i] + l[j])
        k = bisect.bisect_left(l[j+1:], abs(l[i] - l[j]))
        ans += t - k
print(ans)

Fixed submission:
import bisect
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = bisect.bisect_left(l, l[i] + l[j])
        if (t > j):
            ans += t - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = bisect.bisect_left(l[j+1:], l[i] + l[j])
        k = bisect.bisect_left(l[j+1:], abs(l[i] - l[j]))
        ans += t - k
print(ans)

Fixed submission:
import bisect
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = bisect.bisect_left(l, l[i] + l[j])
        if (t > j):
            ans += t - j - 1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
ans = 0
space = 0
while (i < len(s)):
  if s[i] == s[i + 1]:
	ans += 1
    i += 2
  else:
    i += 1
if s[-1] == s[0]:
  space = 1
final_ans = (ans * k) + (space * (k - 1))
print(final_ans)

Fixed submission:
s = input()
k = int(input())
count = []
now = 1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        now += 1
    else:
        count.append(now)
        now = 1
count.append(now)
if len(count) == 1:
    ans = (count[0] * k) // 2
else:
    if s[0] == s[-1]:
        temp = 0
        for i in count:
            temp += i // 2
        ans = (temp * k) - ((count[0] // 2) + (count[-1] // 2)  - ((count[0] + count[-1]) // 2)) * (k - 1)
    else:
        ans = sum([c // 2 for c in count]) * k
print(ans)
Buggy python submission (verdict: Runtime Error):
import fractions

def return_prime(aa):
    a_list = [1]
    if aa % 2 == 0:
        a_list.append(2)
    prime_list = list(range(3, aa + 1, 2))
    for d in prime_list:
        prime_list = [x for x in prime_list if (x == d or x % d != 0)]
    for p in prime_list:
        if aa % p == 0:
            a_list.append(p)
    return a_list

a, b = map(int, input().split())
a_list = return_prime(fractions.gcd(a, b))
print(len(set(a_list)))

Fixed submission:
import fractions

def return_prime(aa):
    a_list = [1]
    for i in range(2, int(aa ** 0.5) + 2):
        while aa % i == 0:
            a_list.append(i)
            aa = aa // i
    if aa != 1:
        a_list.append(aa)
    return a_list

a, b = map(int, input().split())
a_list = return_prime(fractions.gcd(a, b))
print(len(set(a_list)))

Buggy python submission (verdict: Time Limit Exceeded):
import fractions

def return_prime(aa):
    a_list = [1]
    prime_list = []
    if aa % 2 == 0:
        a_list.append(2)
    for i in range(3, aa + 1, 2):
        if len([i % prime for prime in prime_list if i % prime == 0]) == 0:
            prime_list.append(i)
            if aa % i == 0:
                a_list.append(i)
    return a_list

a, b = map(int, input().split())
a_list = return_prime(fractions.gcd(a, b))
print(len(set(a_list)))

Fixed submission:
import fractions

def return_prime(aa):
    a_list = [1]
    for i in range(2, int(aa ** 0.5) + 2):
        while aa % i == 0:
            a_list.append(i)
            aa = aa // i
    if aa != 1:
        a_list.append(aa)
    return a_list

a, b = map(int, input().split())
a_list = return_prime(fractions.gcd(a, b))
print(len(set(a_list)))

Buggy python submission (verdict: Time Limit Exceeded):
import fractions

def return_prime(aa):
    a_list = [1]
    prime_list = []
    if aa % 2 == 0:
        a_list.append(2)
    for i in range(3, aa + 1, 2):
        if len([i % prime for prime in prime_list if i % prime == 0]) == 0:
            prime_list.append(i)
            if aa % i == 0:
                a_list.append(i)
    return a_list

a, b = map(int, input().split())
a_list = return_prime(fractions.gcd(a, b))
print(len(set(a_list)))

Fixed submission:
import fractions

def return_prime(aa):
    a_list = [1]
    for i in range(2, int(aa ** 0.5) + 2):
        while aa % i == 0:
            a_list.append(i)
            aa = aa // i
    if aa != 1:
        a_list.append(aa)
    return a_list

a, b = map(int, input().split())
a_list = return_prime(fractions.gcd(a, b))
print(len(set(a_list)))
Buggy python submission (verdict: Time Limit Exceeded):
import math
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [[math.log(aa, 2), i] for i, aa in enumerate(a)]

for i in range(m):
    a[max(b)[1]] = int((max(a) / 2) // 1)
    b[max(b)[1]][0] -= 1
print(sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = [-int(i) for i in input().split()]
heapq.heapify(a)

for i in range(m):
    k = heapq.heappop(a)
    heapq.heappush(a, -int(-(k / 2) // 1))
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
import math
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
for i in range(m):
    a[a.index(max(a))] = int((max(a) / 2) // 1)
print(sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = [-int(i) for i in input().split()]
heapq.heapify(a)

for i in range(m):
    k = heapq.heappop(a)
    heapq.heappush(a, -int(-(k / 2) // 1))
print(-sum(a))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

ans = 0
for j in range(ans + 1, n):
    for i in range(j + ans):
        if (s[i:i+ans+1] == s[j:j+ans+1]):
            while (i + ans < n) & (i + ans < j):
                if s[i+ans] == s[j+ans]:
                    ans += 1
                else:
                    break
            else:
                break
print(ans)

Fixed submission:
n = int(input())
s = input()
i = 0
j = 0
r = 0
while i < n:
    if s[i:j] in s[j:]:
        r = max(r, j - i)
        j += 1
    else:
        i += 1
print(r)

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

ans = 0
for j in range(n):
    for i in range(j + ans):
        if (s[i:i+ans+1] == s[j:j+ans+1]):
            while (i + ans < n) & (i + ans < j):
                if s[i+ans] == s[j+ans]:
                    ans += 1
            else:
                break
print(ans)

Fixed submission:
n = int(input())
s = input()
i = 0
j = 0
r = 0
while i < n:
    if s[i:j] in s[j:]:
        r = max(r, j - i)
        j += 1
    else:
        i += 1
print(r)

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

ans = 0
for j in range(n):
    for i in range(j + ans):
        while (i + ans < n) & (i + ans < j):
            if (s[i:i+ans+1] == s[j:j+ans+1]):
                ans += 1
            else:
                break
print(ans)

Fixed submission:
n = int(input())
s = input()
i = 0
j = 0
r = 0
while i < n:
    if s[i:j] in s[j:]:
        r = max(r, j - i)
        j += 1
    else:
        i += 1
print(r)

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

ans = 0
for j in range(n):
    for i in range(j):
        temp = 0
        mar = 0
        while (j + mar < n) & (i + mar < j):
            if (s[j+mar] == s[i+mar]):
                mar += 1
                temp += 1
            else:
                break
        ans = max(ans, temp)
print(ans)

Fixed submission:
n = int(input())
s = input()
i = 0
j = 0
r = 0
while i < n:
    if s[i:j] in s[j:]:
        r = max(r, j - i)
        j += 1
    else:
        i += 1
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
s = []
for _ in range(n):
    s.append(int(input()))
max_s = max(s)
d = copy.copy(s)
for i in range(n):
    if max_s != s[i]:
        print(max_s)
    else:
        d = copy.copy(s)
        del d[i]
        print(max(d))

Fixed submission:
n = int(input())
s = []
second = 0
max_k = 0
for _ in range(n):
    k = int(input())
    max_k, min_k = max(k, max_k), min(k, max_k)
    second = max(min_k, second)
    s.append(k)
kk = s.index(max_k)
for i in range(n):
    if i != kk:
        print(max_k)
    else:
        print(second)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
ans = []
for i in range(n, 0, -1):
    multi_list = [j for j in range(1, n + 1, 1) if j % i == 0]
    for multi in multi_list:
        b[i - 1] = (b[i - 1] + a[multi - 1]) % 2
    if b[i - 1] == 1:
        ans.append(str(i))
if a == b:
    print(len(ans))
    if len(ans) > 0:
        print(" ".join(ans))
else:
    print("-1")

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
ans = []
for i in range(n, 0, -1):
    temp = sum(b[i - 1:n:i]) % 2
    if temp != a[i - 1]:
        b[i - 1] = 1
    if b[i - 1] == 1:
        ans.append(str(i))
print(len(ans))
if len(ans) > 0:
    print(" ".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
k = []
for i in range(n):
    for j in range(i, n):
        if (j+1) % (i+1) == 0:
            b[i] += a[j]
            b[i] = b[i] % 2
    if b[i] == 1:
        k.append(str(i+1))
if a == b:
    print(len(k))
    for kk in k:
        print(kk)
else:
    print(-1)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
ans = []
for i in range(n, 0, -1):
    temp = sum(b[i - 1:n:i]) % 2
    if temp != a[i - 1]:
        b[i - 1] = 1
    if b[i - 1] == 1:
        ans.append(str(i))
print(len(ans))
if len(ans) > 0:
    print(" ".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
n = int(input())
a_list = []
for i in range(n):
    a = int(input())
    index = bisect_left(a_list, a)
    if index == 0:
        a_list = [a] + a_list
    else:
        a_list[index - 1] = a
print(len(a_list))

Fixed submission:
from bisect import bisect_right
n = int(input())
a_list = []
for i in range(n):
    a = int(input())
    a_list.append(a)
a_list.reverse()
l_list = [a_list[0]]
for i in range(1, n):
    a = a_list[i]
    if l_list[-1] <= a:
        l_list.append(a)
    else:
        index = bisect_right(l_list, a)
        l_list[index] = a
print(len(l_list))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
n = int(input())
a_list = []
for i in range(n):
    a = int(input())
    index = bisect_left(a_list, a)
    if index == 0:
        a_list = [a] + a_list
    else:
        a_list[index - 1] = a
print(len(a_list))

Fixed submission:
from bisect import bisect_right
n = int(input())
a_list = []
for i in range(n):
    a = int(input())
    a_list.append(a)
a_list.reverse()
l_list = [a_list[0]]
for i in range(1, n):
    a = a_list[i]
    if l_list[-1] <= a:
        l_list.append(a)
    else:
        index = bisect_right(l_list, a)
        l_list[index] = a
print(len(l_list))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
count = 0
b = set([])
num = set(list(range(n)))
for _ in range(n):
    a.append(int(input()))
while len(b) < n:
    temp_num = min(num - b)
    temp = a[temp_num]
    b.add(temp_num)
    temp_list = sorted(list(num - b))
    for temp_i in temp_list:
        if a[temp_i] > temp:
            temp = a[temp_i]
            b.add(temp_i)
    count += 1
print(count)

Fixed submission:
from bisect import bisect_right
n = int(input())
a_list = []
for i in range(n):
    a = int(input())
    a_list.append(a)
a_list.reverse()
l_list = [a_list[0]]
for i in range(1, n):
    a = a_list[i]
    if l_list[-1] <= a:
        l_list.append(a)
    else:
        index = bisect_right(l_list, a)
        l_list[index] = a
print(len(l_list))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
ans = [a[i] if (i % 2 == 0) else -1 * a[i] for i in range(n)]
b = []
for i in range(n):
    t = a[i:] + a[:i]
    ttt = sum([t[i] if (i % 2 == 0) else -1 * t[i] for i in range(n)])
    b.append(str(ttt))
print(" ".join(b))

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
ans = [a[i] if (i % 2 == 0) else -1 * a[i] for i in range(n)]
b = []
ans0 = sum([a[i] if (i % 2 == 0) else -1 * a[i] for i in range(n)])
b.append(str(ans0))
temp = int(ans0 // 2)
for i in range(0, n-1):
    k = a[i] - temp
    b.append(str(k*2))
    temp = k
print(' '.join(b))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
    ans = 0
    for j in range(n):
        if j == i:
            ans += a[j % n]
        elif (j == i-1) | (j == n+i-1):
            ans += a[j % n]
        elif (j > i):
            if j % 2 != i % 2:
                ans -= a[j % n]
            else:
                ans += a[j % n]
        elif (j < i):
            if j % 2 != i % 2:
                ans += a[j % n]
            else:
                ans -= a[j % n]
    b.append(str(ans))
print(" ".join(b))

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
ans = [a[i] if (i % 2 == 0) else -1 * a[i] for i in range(n)]
b = []
ans0 = sum([a[i] if (i % 2 == 0) else -1 * a[i] for i in range(n)])
b.append(str(ans0))
temp = int(ans0 // 2)
for i in range(0, n-1):
    k = a[i] - temp
    b.append(str(k*2))
    temp = k
print(' '.join(b))
Buggy python submission (verdict: Runtime Error):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

inf = (10 ** 9) + 7
n, k = map(int, input().split())
for i in range(1, k+1):
    print((combinations_count((n - k + 1), i)*combinations_count((k-1), i-1))%inf)

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

inf = (10 ** 9) + 7
n, k = map(int, input().split())
if n == k:
    for i in range(1, k+1):
        if i == 1:
            print(1)
        else:
            print(0)
else:
    for i in range(1, k+1):
        if (n - k + 1 >= i):
            print((combinations_count((n - k + 1), i)*combinations_count((k-1), i-1))%inf)
        else:
            print(0)
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a, b, c, d = map(int, input().split())
l = lcm(c, d)
bad = (b // c) - ((a-1) // c) + (b // d) - ((a-1) // d) - (b // l) + ((a-1) // l)
ans = b - a + 1 - bad
print(ans)

Fixed submission:
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
def lcm(x, y):
    return (x * y) // gcd(x, y)

a, b, c, d = map(int, input().split())
l = lcm(c, d)
bad = (b // c) - ((a-1) // c) + (b // d) - ((a-1) // d) - (b // l) + ((a-1) // l)
ans = b - a + 1 - bad
print(ans)

Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
l = lcm(c, d)
bad = (b // c) - ((a-1) // c) + (b // d) - ((a-1) // d) - (b // l) + ((a-1) // l)
ans = b - a + 1 - bad
print(ans)

Fixed submission:
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
def lcm(x, y):
    return (x * y) // gcd(x, y)

a, b, c, d = map(int, input().split())
l = lcm(c, d)
bad = (b // c) - ((a-1) // c) + (b // d) - ((a-1) // d) - (b // l) + ((a-1) // l)
ans = b - a + 1 - bad
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = []
ans = []
for _ in range(n):
    x, y = map(int, input().split())
    a.append([x, y])
for i in range(n):
    for j in range(i + 1, n):
        p = a[i][0] - a[j][0]
        q = a[i][1] - a[j][1]
        ans.append(str(p) + " " + str(q))
print(n - max(Counter(ans).values()))

Fixed submission:
from collections import Counter
n = int(input())
a = []
ans = []
if n == 1:
    print(1)
    exit()
for _ in range(n):
    x, y = map(int, input().split())
    a.append([x, y])
a.sort()
for i in range(n):
    for j in range(i + 1, n):
        p = a[i][0] - a[j][0]
        q = a[i][1] - a[j][1]
        ans.append(str(p) + " " + str(q))
print(n - max(Counter(ans).values()))
Buggy python submission (verdict: Runtime Error):
inf = 7 + (10 ** 9)
n, m = map(int, input().split())
dp1 = [0] * (n + 1)
dp1[0] = 1
for _ in range(m):
    a = int(input())
    dp1[a] = - inf
for i in range(n):
    if i < n:
        if (dp1[i + 1] != inf) & (dp1[i] != inf):
                dp1[i + 1] = dp1[i + 1] + dp[i]
    if i + 1 < n:
        if (dp1[i + 2] != inf) & (dp1[i] != inf):
                dp1[i + 2] = dp1[i + 2] + dp[i]
print(dp1[-1] % inf)

Fixed submission:
inf = 7 + (10 ** 9)
n, m = map(int, input().split())
dp1 = [0] * (n + 1)
dp1[0] = 1
for _ in range(m):
    a = int(input())
    dp1[a] = - inf
for i in range(n):
    if i < n:
        if (dp1[i + 1] != -inf) & (dp1[i] != -inf):
                dp1[i + 1] = dp1[i + 1] + dp1[i]
    if i + 1 < n:
        if (dp1[i + 2] != -inf) & (dp1[i] != -inf):
                dp1[i + 2] = dp1[i + 2] + dp1[i]
print(dp1[-1] % inf)

Buggy python submission (verdict: Time Limit Exceeded):
inf = 7 + (10 ** 9)
n, m = map(int, input().split())
dp = [0] * (n + 1)
out = []
dp[0] = 1
for _ in range(m):
    out.append(int(input()))
for i in range(n):
    if ((i + 1) not in out) & (i not in out):
        if i < n:
            dp[i + 1] = dp[i + 1] + dp[i]
    if ((i + 2) not in out) & (i not in out):
        if i + 1 < n:
            dp[i + 2] = dp[i + 2] + dp[i]
print(dp[-1] % inf)

Fixed submission:
inf = 7 + (10 ** 9)
n, m = map(int, input().split())
dp1 = [0] * (n + 1)
dp1[0] = 1
for _ in range(m):
    a = int(input())
    dp1[a] = - inf
for i in range(n):
    if i < n:
        if (dp1[i + 1] != -inf) & (dp1[i] != -inf):
                dp1[i + 1] = dp1[i + 1] + dp1[i]
    if i + 1 < n:
        if (dp1[i + 2] != -inf) & (dp1[i] != -inf):
                dp1[i + 2] = dp1[i + 2] + dp1[i]
print(dp1[-1] % inf)
Buggy python submission (verdict: Runtime Error):
n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    if w % 2 == 0:
        graph[u].append((v, 1))
        graph[v].append((u, 1))
    else:
        graph[u].append((v, -1))
        graph[v].append((u, -1))
            
color = [None for i in range(n)]
def set_color(v, c):
    color[v] = c
    for next_v, d in graph[v]:
        if color[next_v] is None:
            set_color(next_v, d * c)

set_color(0, 1)
for c in color:
    if c != 1:
        print(0)
    else:
        print(1)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    if w % 2 == 0:
        graph[u].append((v, 1))
        graph[v].append((u, 1))
    else:
        graph[u].append((v, -1))
        graph[v].append((u, -1))
            
color = [None for i in range(n)]
def set_color(v, c):
    color[v] = c
    for next_v, d in graph[v]:
        if color[next_v] is None:
            set_color(next_v, d * c)

set_color(0, 1)
for c in color:
    if c != 1:
        print(0)
    else:
        print(1)
Buggy python submission (verdict: Runtime Error):
r, g, b, n = map(int, input().split())
ans = 0
for r_num in range(math.floor(n/r)+1):
    for g_num in range(math.floor(math.floor(n - r*r_num)/g)+1):
        if ((n - (r_num * r) - (g_num * g)) % b == 0):
            ans += 1
print(ans)

Fixed submission:
import math
r, g, b, n = map(int, input().split())
ans = 0
for r_num in range(math.floor(n/r)+1):
    for g_num in range(math.floor(math.floor(n - r*r_num)/g)+1):
        if ((n - (r_num * r) - (g_num * g)) % b == 0):
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
b = [s[i:].count(".") for i in range(n)]
c = [s[:i-1].count("#") for i in range(n)]
a = [b[i]+c[i] for i in range(n)]
if "." not in s:
    a.append(0)
elif "#" not in s:
    a.append(0)
print(min(a))

Fixed submission:
import bisect
n = int(input())
s = list(input())
b = [0]*(n+1)
c = [s.count(".")]*(n+1)
a = []
a.append(c[0])
for i in range(n):
    if s[i] == "#":
        b[i+1] = b[i] + 1
        c[i+1] = c[i]
    else:
        c[i+1] = c[i] - 1
        b[i+1] = b[i]
    a.append(b[i+1] + c[i+1])
if "." not in s:
    a.append(0)
elif "#" not in s:
    a.append(0)
print(min(a))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())
if "." in s:
    a = [i for i, x in enumerate(s) if x == '.'][-1]
    ans1 = s[:a].count("#")
else:
    ans2 = 0
if "#" in s:
    b = [i for i, x in enumerate(s) if x == '#'][0]
    ans2 = s[b:].count(".")
else:
    ans2 = 0
print(min(ans1, ans2))

Fixed submission:
import bisect
n = int(input())
s = list(input())
b = [0]*(n+1)
c = [s.count(".")]*(n+1)
a = []
a.append(c[0])
for i in range(n):
    if s[i] == "#":
        b[i+1] = b[i] + 1
        c[i+1] = c[i]
    else:
        c[i+1] = c[i] - 1
        b[i+1] = b[i]
    a.append(b[i+1] + c[i+1])
if "." not in s:
    a.append(0)
elif "#" not in s:
    a.append(0)
print(min(a))
Buggy python submission (verdict: Runtime Error):
s = str(input())
a = []
b = ["A", "T", "G", "C"]
c = ""
for s_ in s:
    
    if s_ in b:
        c = c + s_
    else:
        a.append(c)
        c = ""
aa = [len(i) for i in a]
print(max(aa))

Fixed submission:
s = str(input())
a = 0
b = ["A", "T", "G", "C"]
c = 0
for s_ in s:    
    if s_ in b:
        c += 1
    else:
        a = max(c, a)
        c = 0
a = max(c,a)        
print(a)