Harryxun/stf_run huggingface dataset:
S = input()
T = input()
result = []

t_length = len(T)

tmp = ''
result = ''
start = 0
result_list = []
for i, s in enumerate(S):
    if s == '?':
        start =i
        tmp += s
        result += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
        result += s
    if len(tmp) == len(T):
        while S[start+1] == '?':
            start += 1
        result = S[:start-len(T)+1] + T + S[start+1:]
        result_list.append(result.replace('?', 'a'))
        tmp = ''
if len(result_list) == 0:
    print('UNRESTORABLE')
else:
    print(result_list[-1])

### FIXED CODE ###

S = input()
T = input()

start = -1
for i in range(len(S)-len(T)+1):
    match = True
    for j in range(len(T)):
        if not (S[i+j] == T[j] or S[i+j] == "?"):
            match = False
    if match:
        start = i


if start == -1:
    print('UNRESTORABLE')
else:
    result = S[:start] + T + S[start+len(T):]
    print(result.replace("?", "a"))
R, G, B, N = map(int, input().split())

ans = 0
for r in range(3000 // R + 1):
    if N - r * R < 0:
        continue
    for g in range(3000 // G + 1):
        tmp = N - r * R - g * G
        if tmp < 0:
            break
        if tmp % B == 0 and tmp // B >= 0:
            ans += 1

print(ans)


### FIXED CODE ###

R, G, B, N = map(int, input().split())

ans = 0
for r in range(N // R + 1):
    for g in range((N - R * r) // G + 1):
        tmp = N - r * R - g * G
        if tmp % B == 0:
            ans += 1

print(ans)
R,G,B,K=map(int,input().split())



for _ in range (K) :
    if R < G :
        pass
    else:
        G*=2
        continue

    if G < B :
        pass
    else:
        B*=2
        continue
    
if R < G < B :
    print('Yes')
else :
    print('No')


### FIXED CODE ###

R,G,B=map(int,input().split())
K=int(input())
for _ in range (K) :
    if R < G :
        pass
    else:
        G*=2
        continue

    if G < B :
        pass
    else:
        B*=2
        continue
    
if R < G < B :
    print('Yes')
else :
    print('No')
A,B=map(int,input().split())
mod = 2018
flag =0
for i in range(A,B):
  x = i % 2019
  for j in range(i+1,B+1):
    j = j % 2019
    mod = min(mod, (x*j)%2019)
    if mod = 0:
      flag = 1
      break
  if flag:
    break

print(mod)

### FIXED CODE ###

A,B=map(int,input().split())
mod = 2018
flag =0
for i in range(A,B):
  x = i % 2019
  for j in range(i+1,B+1):
    j = j % 2019
    mod = min(mod, (x*j)%2019)
    if mod == 0:
      flag = 1
      break
  if flag:
    break

print(mod)
S = input()
cnt = [0]*2019
cnt[0] = 1
n = 0
t = 1
for i in reversed(S):
    n += i*t
    n %= 2019
    cnt[n] += 1
    t *= 10
    t %= 2019
print(sum(i*(i-1)//2 for i in cnt))

### FIXED CODE ###

S = input()
cnt = [0]*2019
cnt[0] = 1
n = 0
t = 1
for i in reversed(S):
    n += int(i)*t
    n %= 2019
    cnt[n] += 1
    t *= 10
    t %= 2019
print(sum(i*(i-1)//2 for i in cnt))
N = input()

a = 0

for val in range(1, N+1):
  if val%3 != 0 and val%3 != 0:
    a += val
  else:
    pass
  
print(a)

### FIXED CODE ###

N = int(input())

a = 0

for val in range(1, N+1):
  if val%3 != 0 and val%5 != 0:
    a += val
  
print(a)
a,b=int(input().split())
if a<b:
    print(0)
else:
    print(10)

### FIXED CODE ###

c=input().split( )
a=c[0]
b=c[1]
if a<b:
  print(0)
else:
  print(10)
NM = [int(i) for i in input().split()]
a = [0] * NM[0]
for _ in range(NM[1]):
    a[int(input) - 1] = -1

for i in range(NM[0]):
    if (i == 0):
        if(a[i] != -1):
            a[i] = 1
        else:
            a[i] = 0
    elif(i == 1):
        if(a[i] != -1):
            a[i] = a[i - 1] + 1
        else:
            a[i] = 0
    else:
        if(a[i] != -1):
            a[i] = a[i-1] + a[i - 2]
        else:
            a[i] = 0

print(a[N-1] % (10**9 + 7))

### FIXED CODE ###

NM = [int(i) for i in input().split()]
a = [0] * NM[0]
for _ in range(NM[1]):
    a[int(input()) - 1] = -1

for i in range(NM[0]):
    if (i == 0):
        if(a[i] != -1):
            a[i] = 1
        else:
            a[i] = 0
    elif(i == 1):
        if(a[i] != -1):
            a[i] = a[i - 1] + 1
        else:
            a[i] = 0
    else:
        if(a[i] != -1):
            a[i] = a[i-1] + a[i - 2]
        else:
            a[i] = 0

print(a[NM[0]-1] % (10**9 + 7))
import math

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

N,M = map(int, input().split())

print(combinations_count(N, 2)+combinations_count(M, 2))

### FIXED CODE ###

N,M = map(int, input().split())
ans = N*(N-1)//2 + M*(M-1)//2
print(ans)
n=int(input())
a=list(map(int,input().split()))
c=0
l=[]
for i in range(1,n):
  l.append(a[i]-a[i-1])
p=l.pop(0)
while len(l)!=0:
  if p!=0:
    p=l.pop(0)
  if p==0:
    c+=1
    while len(l)>2:
      if l[0]==0 and l[1]==0:
        p=l.pop(0)
        p=l.pop(0)
        c+=1
      else:
        break
    if l[0]==0:
      p=l.pop(0)
      if len(l)>0:
        p=l.pop(0)
      else:
         break
    else:
      p=l.pop(0)
print(c)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
c=0
l=[]
for i in range(1,n):
  l.append(a[i]-a[i-1])
if len(l)==1 and l[n-2]==0:c+=1
if len(l)>1 and l[n-2]==0 and l[n-3]!=0:c+=1
p=l.pop(0)
while len(l)!=0:
  if p!=0:
    p=l.pop(0)
  else:
    c+=1
    while len(l)>1:
      if l[0]==0 and l[1]==0:
        p=l.pop(0)
        p=l.pop(0)
        c+=1
      else:
        break
    while len(l)>0:
      if l[0]==0:
        p=l.pop(0)
      else:
        p=l.pop(0)
        break
print(c)
S = str(input())
N = len(S)

if L > 5:
    small = round((N-1)/2)
    big = round((N+3)/2)-1
    smallS = S[0:small]
    bigS = S[big:N]

    if smallS == bigS:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

S = str(input())
N = len(S)
 
head = round((N-1)/2)
end = round((N+3)/2-1)

headS = S[:head]
endS = S[end:]

if S==S[::-1] and headS == headS[::-1] and endS == endS[::-1]:
	print('Yes')
else:
  	print('No')
x,y,z= map(int,input().split())
 
rem=x-y
 
print(int(rem/(y+z)+1)

### FIXED CODE ###

# coding: utf-8
# Your code here!
x,y,z=map(int,input().split())
n=1#最初は一人
while True:
    l=y*n+(n+1)*z
    if l>x:
        break
    else:
        n+=1
        ans=n
ans-=1
print(ans)
import itertools
x=list(input())

for lst in itertools.product(['+','-'],repeat=3)
  sum=int(x[0])
  for i in range(3):
    if lst[i]=='+':
      sum+=int(x[i+1])
    else:
      sum-=int(x[i+1])
  if sum==7:
    print(x[0]+lst[0]+x[1]+lst[1]+x[2]+lst[2]+x[3]+'=7')
    break

### FIXED CODE ###

a=list(input())
for i in range(4):
  a[i]=int(a[i])
x=sum(a)-7
dict={0:'+',1:'-'}
ans=0
for i in range(2):
  for j in range(2):
    for k in range(2):
        if x==(i*a[1]+j*a[2]+k*a[3])*2:
          print(a[0],dict[i],a[1],dict[j],a[2],dict[k],a[3],'=7',sep='')
          ans=1
        if ans==1:
          break
    if ans==1:
      break
  if ans==1:
    break
N=int(input())
a_list=[]
for i in range(N):
    a_list.append(int(input()))
    
a_max=max(a_list)
a_min=min(a_list)
print(a_max-a_min)
    

### FIXED CODE ###

N=int(input())
a=list(map(int,input().split())) 
a_max=max(a)
a_min=min(a)
print(a_max-a_min)
#YYMM, MMYY, AMBIGUOUS, NA
S = str(input())

s0 = int(S[0:2])
s1 = int(S[2:])

if s0>12:#YYMM or NA
    if s1>12:
        ans=="NA"
    else:
        ans=="YYMM"
elif s1>12:#MMYY
    ans="MMYY"
else:
    ans="AMBIGUOUS"
    
print(ans)

### FIXED CODE ###

#YYMM, MMYY, AMBIGUOUS, NA
S = str(input())

s0 = int(S[0:2])
s1 = int(S[2:])

if s0>12 or s0==0:#YYMM or NA
    if s1>12 or s1==0:
        ans="NA"
    else:
        ans="YYMM"
elif s1>12 or s1==0:#MMYY
    ans="MMYY"
else:
    ans="AMBIGUOUS"
    
print(ans)
n = int(input())
s = input()
alphaList  =   ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
moji = ""
for str in s:
    index = alphaList.index(str)
    addNum = 0
    if index == 24:
        addNum = 0
    elif index ==  25:
        addNum = 1
    else:
        addNum = index + n 
        print(addNum)
    moji = moji + str.replace(str, alphaList[addNum])
print(moji)

### FIXED CODE ###

n = int(input())
s = input()
alphaList  =   ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
moji = ""
for str in s:
    index = alphaList.index(str)
    addNum = index + n
    if addNum >25:
        addNum = addNum - 26 
    moji = moji + alphaList[addNum]
print(moji)
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
mod = 10**9+7 #出力の制限
N = 10**5
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
# a = cmb(n,r)


n,m,k = m()

sx = 0
sy = 0

for i in range(1,n):
    sx += i * (n-i) * (m**2) * cmb(n*m-2,k-2)
    sx %= mod

for i in range(1,m):
    sy += i * (m-i) * (n**2) * cmb(n*m-2,k-2)
    sy %= mod
print((sx+sy)%mod)



### FIXED CODE ###

import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
mod = 10**9+7 #出力の制限
N = 2*(10**5)
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
# a = cmb(n,r)


n,m,k = m()

sx = 0
sy = 0

for i in range(1,n):
    sx += i * (n-i) * (m**2) * cmb(n*m-2,k-2)
    sx %= mod

for i in range(1,m):
    sy += i * (m-i) * (n**2) * cmb(n*m-2,k-2)
    sy %= mod
print((sx+sy)%mod)
# 指定された距離で何個の木を作成することができるかを計算する
import bisect
import itertools
N = int(input())
D = list(map(int, input().split()))
#
D=list(map(int,inp.split()))
print(D)

node_dis = [1] # 距離iのノードの個数をi番目の要素として格納したリスト
flag_none = False

# 頂点１から深さは決まっている.深さni毎に前のni-1のノードから重複を許してc_ni個選んでノードに繋げばよい
if not D[0] == 0:
    print(0)
    flag_none = True

else:
    D.sort()  # 昇順でソート
    for i in range(1,N):
        if i == 1 and bisect.bisect_left(D,1) >= 2:  # 0が２つ以上ある場合
            print(0)
            flag_none = True
            break
        else:
            index = bisect.bisect_left(D,i+1)
            new_num = index - sum(node_dis)
            node_dis.append(new_num)
            if new_num == 0:
                if not index == N:
                    print(0)
                    flag_none = True
                break

if flag_none == False:
    sum = 1
    for (ind, di) in enumerate(node_dis): 
        if ind > 0:
            sum *= node_dis[ind-1] ** di
    print(sum)




### FIXED CODE ###

# 指定された距離で何個の木を作成することができるかを計算する
import bisect
import itertools
N = int(input())
D = list(map(int, input().split()))
node_dis = [1] # 距離iのノードの個数をi番目の要素として格納したリスト
flag_none = False

# 頂点１から深さは決まっている.深さni毎に前のni-1のノードから重複を許してc_ni個選んでノードに繋げばよい
if not D[0] == 0:
    print(0)
    flag_none = True

else:
    D.sort()  # 昇順でソート
    for i in range(1,N):
        if i == 1 and bisect.bisect_left(D,1) >= 2:  # 0が２つ以上ある場合
            print(0)
            flag_none = True
            break
        else:
            if i ==1:
                del D[0]
            index = bisect.bisect_left(D,i+1)
            new_num = index 
            node_dis.append(new_num)
            del D[:index]
            if index==0: 
                if not D == []:
                    print(0)
                    flag_none = True
                break
if flag_none == False:
    sum = 1
    for (ind, di) in enumerate(node_dis): 
        if ind > 0:
            sum *= node_dis[ind-1] ** di
    print(sum%998244353)
n, x, m = map(int, input().split())
a = [x]
if n == 1:
    print(x)
    exit()
for i in range(n-1):
    ad = (a[-1]**2) % m
    if ad in a:
        roop_s = a.index(ad)
        roop_e = len(a)
        break
    else:
        a.append(ad)
    if i == n-2:
        print(sum(a))
        exit()
roop_t = (n-roop_s) // (roop_e - roop_s)
left = n - roop_t*(roop_e - roop_s) - roop_s
ans = sum(a[:roop_s]) + roop_t*sum(a[roop_s : roop_e]) + sum(a[roop_s:roop_s+left])
print(ans)

### FIXED CODE ###

s = input()
if s[-1] == "s":
    print(s+"es")
else:
    print(s+"s")
S,T=input()
print(T+S)

### FIXED CODE ###

S,T=input().split()
print(T+S)
import math

class _const:
    def __init__(self):
        self.PI=math.acos(-1)
        self.convToDEG=180/self.PI
const=_const()


a,b,x=map(int,input().split(" "))

Volume=a*a*b

if 2*x>=Volume:
    print(const.convToDEG*math.atan(2*(a*a*b-x)/a**3))

else:
    h=2*x/(a*b)
    print(const.convToDEG*math.acos(h/b))



### FIXED CODE ###

import math

class _const:
    def __init__(self):
        self.PI=math.acos(-1)
        self.convToDEG=180/self.PI
const=_const()


a,b,x=map(int,input().split(" "))

Volume=a*a*b

if 2*x>=Volume:
    print(const.convToDEG*math.atan(2*(a*a*b-x)/a**3))

else:
    r=2*x/(a*b*b)

    print(const.convToDEG*(const.PI/2-math.atan(r)))
X, Y, Z = map(int, input().split())

X, Y = Y, X
X, Z = Z, X

print(f'{X} {Y} {Z}')

### FIXED CODE ###


X, Y, Z = input().split()

X, Y = Y, X
X, Z = Z, X

print(X + " " + Y + " " + Z)
N, X = map(int, input().split())
L = list(map(int, input().split()))

i = 0
D = 0

if L[0] > X:
    print(1)
    exit()
elif L[0] == X:
    print(2)
    exit()

while D <= X and i <= N:
    D += L[i]
    i += 1

print(i)


### FIXED CODE ###

N, X = map(int, input().split())
L = list(map(int, input().split()))

i = 0
D = 0
cnt = 1

for i in range(N):
    D += L[i]
    if D <= X:
        cnt += 1
print(cnt)
N = int(input())
H = []
for _ in range(N):
    A, B = map(int,input().split())
    H.append((B, A))
H.sort()
t = 0
for i in range(N):
    B, A = H[i]
       t += A
    if B < t:
        print("No")
        break 
    if i == N - 1:
        print("Yes")

### FIXED CODE ###

N = int(input())
H = []
for _ in range(N):
    A, B = map(int,input().split())
    H.append((B, A))
H.sort()
t = 0
for i in range(N):
    B, A = H[i]
    t += A
    if B < t:
        print("No")
        break 
    if i == N - 1:
        print("Yes")
import math
x = int(input())
print ('{} {}'.format(math.pi*x*x, 2*math.pi*x))


### FIXED CODE ###

import math
x = float(input())
print ('{} {}'.format(math.pi*x*x, 2*math.pi*x))
#NとXの読み込み
n, x = input().split()
n = int(n)
x = int (x)
m = []
i_min = 0 
result = 0

#m1からmnまでの読み込み
for i in range(n):
 m.append(int(input())
#全種類ひとつずつ作る
for i in range(len(m)):
 x = x - m[i]
 result = result + 1
#リストの中の最小値を突き止める
for i in range(len(m)):
 if m[i_min] > m[i]:
   i_min = i
#i_minを作れるだけ作る
for i in range(x):
 if x >= m[i_min]:
  result = result + 1
  x = x - m[i_min]
 else:
  break
#印刷
print(result)

### FIXED CODE ###

n, x = input().split()
n = int(n)
x = int(x)
m = []
i_min = 0
result = 0

for i in range(n):
 m.append(int(input()))

for i in range(len(m)):
 x = x - m[i]
 result = result + 1

for i in range(len(m)):
 if m[i_min] > m[i]:
  i_min = i

for i in range(x):
 if x >= m[i_min]:
  result = result + 1
  x = x - m[i_min]
 else:
  break

print(result)
lines = list(input())
answers = []
out = ""
for line in lines:
    if line == "0" or line == "1":
        answers.append(line)
    else:
        answers.pop()
for answer in answers:
    out += answer
print(out)


### FIXED CODE ###

num = int(input())
sum = 0
for i in range(1,num+1):
    sum += i
print(sum)
from collections import Counter, deque

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_cn = Counter(A)
B_cn = Counter(B)
AB_cn = Counter(A+B)
if AB_cn.most_common()[0][1] > N:
    print("No")
else:
    print("Yes")
    b = deque(B)
    ans_dict = {}
    cntr = 0
    while b:
        if cntr not in ans_dict:
            c = b.pop()
            if A[cntr] != c:
                ans_dict[cntr] = c
            else:
                b.pushleft(c)
            cntr += 1
            cntr %= N
    ans = []
    for i in range(N):
        ans += [ans_dict[i]]
    print(*ans)



### FIXED CODE ###

from collections import Counter, deque

N = int(input())
A = list(map(int, input().split())) + [N+1]
B = list(map(int, input().split())) + [N+1]
C = [0]
D = [0]

AB_cn = Counter(A+B)
if AB_cn.most_common()[0][1] > N:
    print("No")
else:
    print("Yes")
    for i in range(N+1):
        if len(C) != A[i]:
            C.extend([i]*(A[i]-len(C)))
        if len(D) != B[i]:
            D.extend([i]*(B[i]-len(D)))
    ans = 0
    for i in range(N):
        curr = C[i+1] - D[i]
        ans= max(curr, ans)
    B = B[:-1]
    ans = [B[(i-ans)%N] for i in range(N)]
 
    print(*ans)
n = int(input())
if n == 0 {
	print(1)
} else n == 1 {
	print(0)
} 
  

### FIXED CODE ###

n = int(input())
if n == 0:
	print(1)
elif n == 1:
	print(0)
def dfs(u, fa = 0):
	global adj
	res = 0
	for v in adj[u]:
		if v != fa:
			res ^= dfs(v, u) + 1
	return res

n = int(raw_input())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
	x, y = map(int, raw_input().split())
	adj[x].append(y)
	adj[y].append(x)
print 'Alice' if dfs(1) else 'Bob'

### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)
def dfs(u, fa = -1):
	res = 0
	for v in adj[u]:
		if v != fa:
			res ^= dfs(v, u) + 1
	return res
n = int(raw_input())
adj = [[] for i in xrange(n)]
for i in xrange(n - 1):
	x, y = [int(t) - 1 for t in raw_input().split()]
	adj[x].append(y)
	adj[y].append(x)
print 'Alice' if dfs(0) else 'Bob'
n=int(input())
h=list(map(int,input().split()))
ans="Yes"
cngh=0
bkh=0
for i in range(n):
  if bkh>h[i]:
    if cngh!=h[i-1]:
      if bkh-1==h[i]:
      	cngh=h[i]
      else:
        ans="No"
        break
    else:
      if cngh!=h[i]:
        ans="No"
        break
  bkh=h[i]
print(ans)

### FIXED CODE ###

a,b,c=map(int,input().split())
print(0 if c-(a-b)<0 else c-(a-b))
a = input()
c, b = a.split("/n")
x = int(max(b))-int(min(b))
print(x)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
A.sort()
print(abs(A[0]-A[-1]))
import sys

sys.setrecursionlimit(1000000)

num_node = int(input())
relation = [[[], []] for i in range(num_node + 1)]
for i in range(num_node - 1):
    u, v, w = map(int, input().split())
    if w % 2 == 0:
        relation[u][0].append(v)
        relation[v][0].append(u)
    else:
        relation[u][1].append(v)
        relation[v][1].append(u)
colors = [None] * (num_node + 1)


def dfs(n: int):
    if n == 1:
        colors[n] = 0
    print(colors)
    # 偶数
    for even_idx in relation[n][0]:
        if colors[even_idx] is not None:
            continue
        else:
            colors[even_idx] = colors[n]
            dfs(even_idx)
    # 奇数
    for odd_idx in relation[n][1]:
        if colors[odd_idx] is not None:
            continue
        else:
            colors[odd_idx] = not colors[n]
            dfs(odd_idx)


if __name__ == '__main__':
    dfs(1)
    for ans in list(map(int, colors[1:])):
        print(ans)

### FIXED CODE ###

import sys

sys.setrecursionlimit(1000000)

num_node = int(input())
relation = [[[], []] for i in range(num_node + 1)]
for i in range(num_node - 1):
    u, v, w = map(int, input().split())
    if w % 2 == 0:
        relation[u][0].append(v)
        relation[v][0].append(u)
    else:
        relation[u][1].append(v)
        relation[v][1].append(u)
colors = [None] * (num_node + 1)


def dfs(n: int, c: int):
    colors[n] = c
    # 偶数
    for even_idx in relation[n][0]:
        if colors[even_idx] is not None:
            continue
        else:
            dfs(even_idx, colors[n])
    # 奇数
    for odd_idx in relation[n][1]:
        if colors[odd_idx] is not None:
            continue
        else:
            dfs(odd_idx, 1 - colors[n])


if __name__ == '__main__':
    dfs(1, 0)
    for ans in list(map(int, colors[1:])):
        print(ans)
import sys
def input(): return sys.stdin.readline().strip()
N=int(input())
A=[int(input()) for i in range(N-1)]
c=[[] for i in range(N)]
for i,a in enumerate(A):
    c[a-1].append(i+1)
import sys
sys.setrecursionlimit(10**5)
def f(i):
    if len(c[i])==0:
        return 0
    return max([e+i+1 for i,e in enumerate(sorted([f(j) for j in c[i]],reverse=True))])
print(f(0))

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()
N=int(input())
A=[int(input()) for i in range(N-1)]
c=[[] for i in range(N)]
for i,a in enumerate(A):
    c[a-1].append(i+1)
import sys
sys.setrecursionlimit(10**7)
def f(i):
    if len(c[i])==0:
        return 0
    return max([e+i+1 for i,e in enumerate(sorted([f(j) for j in c[i]],reverse=True))])
print(f(0))
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for l in range(K+1):
        for r in range(K-l+1):
            if l+r > K:
                continue
            now = []
            val = 0
            for i in range(l):
                now.append(V[i])
                val += V[i]
            for j in range(r):
                now.append(V[-j-1])
                val += V[-j-1]

            d = K-l-r
            now.sort()
            for i in range(d):
                if i >= len(now):
                    break
                if now[i] > 0:
                    break
                val -= now[i]
            ans=max(ans,val)

    print(ans)

resolve()

### FIXED CODE ###

# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for l in range(K+1):
        for r in range(K-l+1):
            if l+r > N:
                continue
            now = []
            val = 0
            for i in range(l):
                now.append(V[i])
                val += V[i]
            for j in range(r):
                now.append(V[-j-1])
                val += V[-j-1]

            d = K-l-r
            now.sort()
            for i in range(d):
                if i >= len(now):
                    break
                if now[i] > 0:
                    break
                val -= now[i]
            ans=max(ans,val)

    print(ans)

resolve()
n = input()
total = 0

for i in range(n):
	if (i % 3 != 0) and (i % 5 != 0):
		total += i

print(total)

### FIXED CODE ###

n = int(input())
total = 0

for j in range(n):
	i = j+1
	if (i % 3 != 0) and (i % 5 != 0):
		total += i

print(total)
l = ["Sunny", "Cloudy", "Rainy"]

s = input()

ind = 0
for t in  l:
  if s = t:
    break
  ind += 1
ind %= 2
print(l[ind]

### FIXED CODE ###

l = ["Sunny", "Cloudy", "Rainy"]

s = input()

ind = 0
for t in  l:
  ind += 1
  if s == t:
    break
ind %= 3
print(l[ind])