Harryxun/stf_run huggingface dataset:
from itertools import permutation as per

n,m,r = map(int,input().split())
rlist = list(map(int,input().split()))
ans = 10**9
A = [[10**8]*n for _ in range(n)]
for _ in range(n):
  a,b,c = map(int,input().split())
  A[a-1][b-1] = c
  A[b-1][a-1] = c

for i in range(n-1):
  for j in range(i+1,n):
    for k in range(n):
      newd = A[i][k] + A[k][j]
      if A[i][j] > newd:
        A[i][j] = newd
        A[j][i] = newd
for x in per(rlist):
  cost = 0
  for i in range(r-1):
    cost += A[x[i]-1][x[i+1]-1]
  if cost < ans:
    ans = cost
print(ans)

### FIXED CODE ###

n,m,r = map(int,input().split())
l = list(map(int,input().split()))
g = [[10**10]*(n+1) for _ in range(n+1)]
for i in range(n+1):
  g[i][i] = 0
for _ in range(m):
  a,b,c = map(int,input().split())
  g[a][b] = c
  g[b][a] = c
for k in range(1,n+1):
  for i in range(1,n):
    for j in range(i+1,n+1):
      if g[i][j] >= g[i][k] + g[k][j]:
        g[i][j] = g[i][k] + g[k][j]
        g[j][i] = g[i][j]
g[0] = [0]*(n+1)
def dfs(cur,res,dis,use):
  if res == 0:
    return dis
  ans = 10**10
  for i in range(r):
    if not use[i]:
      use[i] = 1
      ans = min(ans, dfs(l[i],res-1,dis+g[cur][l[i]],use))
      use[i] = 0
  return ans
print(dfs(0,r,0,[0]*r))
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

for i in range(N):
    P[i] -= 1

ans = -10 ** 18
for si in range(N):
    KK = K
    x = si
    c = []
    tot = 0
    while True:
        x = P[x]
        c.append(C[x])
        tot += C[x]
        if x == si:
            break

    s = 0
    if KK > N:
        sho = KK // len(c)
        yo = KK % len(c)
        KK = yo
        if tot > 0:
            s += tot * sho
    for k in range(KK):
        s += c[k]
        ans = max(s, ans)

print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

for i in range(N):
    P[i] -= 1

ans = -10 ** 18
for si in range(N):
    x = si
    c = []
    tot = 0
    while True:
        x = P[x]
        c.append(C[x])
        tot += C[x]
        if x == si:
            break

    s = 0
    for k in range(len(c)):
        if k + 1 > K:
            break
        s += c[k]
        ss = s
        if tot > 0:
            ss += tot * int((K - (k + 1)) // len(c))
        ans = max(ss, ans)

print(ans)
N = int(input())
S = input()
r_c = 0
ch = 0
for i in S:
  if i == "R":
    r_c += 1
for i in range(r_c):
  if i == "W"
    ch += 1
print(ch)

### FIXED CODE ###

N = int(input())
S = input()
r_c = 0
ch = 0
for i in S:
  if i == "R":
    r_c += 1
for i in range(r_c):
  if S[i] == "W":
    ch += 1
print(ch)
x,a=map(int,input().split)

if x<a:
  print('0')
else:
  print('10')

### FIXED CODE ###

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

if x<a:
  print(0)
else:
  print(10)
import math
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
 
if w >= v:
    print('No')
else:
    for i in range(1,t+1):
        if abs(a-b) <= (w-v)*i:
            print('Yes')
            break

### FIXED CODE ###

s = input()
print(s[:3])
import sys
sys.setrecursionlimit(3009)
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for j in range(m+1)] for i in range(n+1)]
def lcs(i,j):
	if dp[i][j]!=0:
		return dp[i][j]
	if i*j==0:
		return 0
	if s[i-1]==t[j-1]:
		r=lcs(i-1,j-1)+1
	else:
		r=max(lcs(i,j-1),lcs(i-1,j))
	dp[i][j]=r
	return r
		
		

lcs(n,m)

i=n
j=m
st=""
while dp[i][j]:
	while dp[i-1][j]==dp[i][j]:
		i-=1
	while dp[i][j-1]==dp[i][j]:
		j=j-1
	j-=1
	st+=s[i-1]
	i-=1
print(st[::-1])
	

### FIXED CODE ###

s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for j in range(m+1)] for i in range(n+1)]
for i in range(1,n+1):
	for j in range(1,m+1):
		if s[i-1]==t[j-1]:
			dp[i][j]=dp[i-1][j-1]+1
		else:
			dp[i][j]=max(dp[i-1][j],dp[i][j-1])
i=n
j=m
st=""
while dp[i][j]:
	while dp[i-1][j]==dp[i][j]:
		i-=1
	while dp[i][j-1]==dp[i][j]:
		j=j-1
	j-=1
	st+=s[i-1]
	i-=1
print(st[::-1])
X, N = map(int,input().split())
P = list(map(int,input().split()))
Q = [i+1 for i in range(100)]
for pi in P:
    Q.remove(pi)
Q1 = [abs(qi - X) for qi in Q]
print(Q[Q1.index(min(Q1))])

### FIXED CODE ###

X, N = map(int,input().split())
if N==0:
    print(X)
else:
    P = list(map(int,input().split()))
    P.sort()
    Q = [i-1 for i in range(-10,111)]
    for a in P:
        Q.remove(a)
    Q1 = [abs(b - X) for b in Q]
    print(Q[Q1.index(min(Q1))])
n, m, k = map(int, input().split())

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

a_, b_ = [0], [0]

for i in range(n):
    a_.append(a_[i] + a[i])
for j in range(m):
    b_.append(b_[j] + b[j])

ans = 0
for i in range(n+1):
    
    idx2 = m
    while a_[i] + b_[idx2] > k:
        idx2 -= 1
    
    ans = max(ans, i + idx2)
print(ans)

### FIXED CODE ###

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

a_, b_ = [0], [0]

for i in range(n):
    a_.append(a_[i] + a[i])
for i in range(m):
    b_.append(b_[i] + b[i])

ans, j = 0, m

for i in range(n + 1):
    if a_[i] > k:
        break
    while b_[j] > k - a_[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
n,m = map(int,input().split())
a = []
mod = 10**9+7
for i in range(m):
    b = int(input())
    a.append(b)
d = [0 for i in range(n+1)]
d[0] = 0
d[1] = 1
d[2] = 2
for i in range(3,n+1):
    d[i] = d[i-1] + d[i-2]
ans = 1
if a[0] == 1:
    ans = 1
else:
    ans = ans*d[a[0]-1]%mod
for i in range(m-1):
    ans = ans*d[a[i+1]-a[i]-2]%mod
ans = ans*d[n-a[m-1]-1]%mod
print(ans)

### FIXED CODE ###

S = input()
s = list(S)
s.sort()
if s[0] == s[1] and s[2] == s[3] and s[1] != s[2] :
    print('Yes')
else:
    print('No')
t,x = list(map(int,input().strip()))

num = t / x

print(float(num))

### FIXED CODE ###

t,x = list(map(int,input().split()))
print(t/x)
s=list(input())


a = 0
while a < 3:
  if s[a] == "1":
    s[a] = "9"
  elif s[a] == "9":
    s[a] = "1"
  a += 1

print(int(s))

### FIXED CODE ###

s=list(input())


a = 0
while a < 3:
  if s[a] == "1":
    s[a] = "9"
  elif s[a] == "9":
    s[a] = "1"
  a += 1

s = ''.join(s)


print(s)
a,b=map(str,input().split())
if (a*b)%2 ==0:
  print('Even')
else:
  print('Odd')


### FIXED CODE ###

a, b = map(int, input().split())
if(a*b%2 == 0 ):
  print('Even')
else:
  print('Odd')
mod=1777777777
n,ma,mb=map(int,input().split())
d=[[mod for j in range(100)] for i in range(100)]
for i in range(n):
    a,b,c=map(int,input().split())
    x=a
    y=b
    for j in range(100-a,0,-1):
        for k in range(100-b,0,-1):
            if d[j][k]!=mod:
                d[j+a][k+b]=min(d[j+a][k+b],d[j][k]+c)
    d[x][y]=min(d[x][y],c)
ans=mod
for i in range(100):
    if i%ma==0 and mb*i//ma<100:
        ans=min(ans,d[i][mb*i//ma])

print([ans,-1][ans==mod])


### FIXED CODE ###

mod=1777777777
n,ma,mb=map(int,input().split())
d=[[mod for j in range(100)] for i in range(100)]
for i in range(n):
    a,b,c=map(int,input().split())
    x=a
    y=b
    for j in range(100-a-1,0,-1):
        for k in range(100-b-1,0,-1):
            if d[j][k]!=mod:
                d[j+a][k+b]=min(d[j+a][k+b],d[j][k]+c)
    d[x][y]=min(d[x][y],c)
ans=mod
for i in range(100):
    if i%ma==0 and mb*i//ma<100:
        ans=min(ans,d[i][mb*i//ma])

print([ans,-1][ans==mod])
n=int(raw_input())
r=raw_input().split()

def BubbleSort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(c[j-1][-1]):
                c[j], c[j-1]=c[j-1],c[j]
    return c

def SelectionSort(c, n):
    for i in range(n):
        m=i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[m][-1]):
                m=j
        c[i],c[m]=c[m],c[i]
    return c

l=list(r)
a=BubbleSort(l, n)
print *a
print 'Stable'
l=list(r)
b=SelectionSort(l, n)
print *b
if a==b:
    print 'Stable'
else:
    print 'Not stable'


### FIXED CODE ###

n=int(raw_input())
r=raw_input().split()

def BubbleSort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(c[j-1][-1]):
                c[j], c[j-1]=c[j-1],c[j]
    return c

def SelectionSort(c, n):
    for i in range(n):
        m=i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[m][-1]):
                m=j
        c[i],c[m]=c[m],c[i]
    return c

l=list(r)
a=BubbleSort(l, n)
print ' '.join(a)
print 'Stable'
l=list(r)
b=SelectionSort(l, n)
print ' '.join(b)
if a==b:
    print 'Stable'
else:
    print 'Not stable'
a = input()
b = input()
c = input()
print(int(b/c)-int(a/c+0.999)+1)

### FIXED CODE ###

a, b, c = map(int, input().split())
print(int(b/c)-int(a/c+0.999)+1)
n, m, c = map(int, input.split())
b = list(map(int, input.split()))
ans = 0
code = 0

for i in range(n):
    for j in range(m):
        
        a = list(map(int, input.split()))
        code += a[j] * b[j]
    
    code -= 10
    if code >= 0:
        ans += 1
        
print(ans)

### FIXED CODE ###

n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
code = 0

for i in range(n):
    a = list(map(int, input().split()))
    
    for j in range(m):
        code += a[j] * b[j]
    
    code += c
    if code > 0:
        ans += 1
    code = 0
        
print(ans)
n = int(input())

print(100-100//n)

### FIXED CODE ###

S = input()
print(S if len(S) == 2 else S[::-1])
S = list(input())
K = int(input())
count = 0
if S[0] != S[-1]:
    flag = False
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = 1
            count += 1
    print(K*count)
else:
    if len(S) == 2:
        print(K)
    else:
        if S[0] == S[1]:
            S[0] = 1
            count += 1
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = 1
                count += 1
        print(K*count)

### FIXED CODE ###

from collections import Counter
s = input()
N = len(s)
K = int(input())
if s[0] != s[-1]:
    count = 1
    ans = 0
    now = s[0]
    for i in range(1,len(s)):
        if now == s[i]:
            count += 1
        else:
            now = s[i]
            ans += count//2
            count = 1
    if count != 1:
        ans += count//2
    print(ans*K)
elif len(Counter(s).values()) == 1:
    print(K*len(s)//2)
else:
    ans = 0
    fcount = 1
    bcount = 1
    now = s[0]
    start = N
    for i in range(1,N):
        if s[i] == now:
            fcount += 1
        else:
            start = i
            break
    now = s[-1]
    end= 0
    for i in range(N-2,-1,-1):
        if s[i] == now:
            bcount += 1
        else:
            end = i
            break   
    ans = fcount//2 + bcount//2 + ((fcount+bcount)//2)*(K-1)
    now = s[start]
    count = 1
    mcount = 0
    for i in range(start+1,end+1):
        if s[i] == now:
            count += 1
        else:
            mcount += count//2
            count = 1
            now = s[i]
    if count != 1:
        mcount += count//2
    print(ans + mcount*K)
import numpy as np
import collections

N = int(input())
D_seq = input().split()
D_seq = list(map(int, D_seq))

D_seq_max = max(D_seq)

judge_list = np.arange(D_seq_max+1)
judge_set = set(judge_list)
D_seq_set = set(D_seq)

c = collections.Counter(D_seq)

N_list = []
if((judge_set == D_seq_set)or(D_seq[0]==0)):
    counts = 1
    for i in range(D_seq_max):
        counts *= pow(c[i], c[i+1])
    if(counts < 998244353):    
        print(counts)
    else:
        print(int(counts%998244353))
        
else:
    print(0)

### FIXED CODE ###

import math
import numpy as np

N = int(input())

N_half = math.floor(N/2)

counts = 0
for i in np.arange(1, N):
    j = N-i
    if(i != j ):
        counts += 1
        
print(int(counts/2))
a = int(input())
b = int(input())
c = int(input())

if(a+b+c>=22):
    print('bust')
else:
    print('win')

### FIXED CODE ###

a,b,c = map(int,input().split())
if(a+b+c>=22):
    print('bust')
else:
    print('win')
n = int(input())
h = [int(x) for x in input().split()]

dp_list = [-1]*(n)

def dp(n):
  if dp_list[n] == -1:
    if n == 0:
      dp_list[0] = 0
    elif n == 1:
      dp_list[1] = abs(h[1]-h[0])
    else:
      dp_list[n] = min([dp(n-1)+abs(h[n]-h[n-1]), dp(n-2)+abs(h[n]-h[n-2])])
  return dp_list[n]

ans = dp(n-1)
print(ans)

### FIXED CODE ###

n = int(input())
h = [int(x) for x in input().split()]
inf = 10**9+7

dp_list = [inf]*(n)

for i in range(n):
  if i == 0:
    dp_list[i] = 0
  elif i == 1:
    dp_list[i] = abs(h[1]-h[0])
  else:
    dp_list[i] = min([dp_list[i-1]+abs(h[i]-h[i-1]), dp_list[i-2]+abs(h[i]-h[i-2])])


print(dp_list[n-1])
N = int(input())
ans = 0

for i in range(N + 1):
  if i % 15 == 0:
    ai = 0
  if i % 3 == 0 and i % 5 =! 0:
    ai = 0
  if i % 3 =! 0 and i % 5 == 0:
    ai = 0
  else:
    ai = i
  
  ans = ans + ai

print(ans)


### FIXED CODE ###

N = int(input())
ans = 0

for i in range(N + 1):
  if i % 3 == 0 or i % 5 == 0:
    ai = 0 
  else:
    ai = i
  
  ans = ans + ai

print(ans)
import math
N=int(input())
s = list( map(int , input().split()) )
ans = s[0]
count = 0
for i in range(1,N-1):
 ans = math.gcd(ans,s[i])
while i < pow(10,9):
 if ans%2 == 0:
  count +=1
  ans = ans/2
 else:
  break
print(count)

### FIXED CODE ###

s=str(input())
print(int(s[0])+int(s[1])+int(s[2]))
import sys

sys.setrecusionlimit(1000000)

s=input()
x,y=map(int,input().split())
N=len(s)

memo={}
def dfs(startx,starty,direction,num):
    if (startx,starty,direction,num) in memo.keys():
        return memo[(startx,starty,direction,num)]
    if num==N:
        memo[(startx,starty,direction,num)]=0
        memo[(startx,starty,direction,num)]=(startx==x and starty==y)
        return (startx==x and starty==y)

    if s[num]=='F':
        if direction==0:
            memo[(startx,starty,direction,num)]=0
            memo[(startx,starty,direction,num)]=dfs(startx+1,starty,direction,num+1)
            return memo[(startx,starty,direction,num)]
        if direction==90:
            memo[(startx,starty,direction,num)]=0
            memo[(startx,starty,direction,num)]=dfs(startx,starty+1,direction,num+1)
            return memo[(startx,starty,direction,num)]
        if direction==180:
            memo[(startx,starty,direction,num)]=0
            memo[(startx,starty,direction,num)]=dfs(startx-1,starty,direction,num+1)
            return memo[(startx,starty,direction,num)]
        if direction==270:
            memo[(startx,starty,direction,num)]=0
            memo[(startx,starty,direction,num)]=dfs(startx,starty-1,direction,num+1)
            return memo[(startx,starty,direction,num)]

    if s[num]=='T':
        memo[(startx,starty,direction,num)]=0
        if dfs(startx,starty,(direction+90)%360,num+1):
            memo[(startx,starty,direction,num)]=True
            return True
        if dfs(startx,starty,(direction-90)%360,num+1):
            memo[(startx,starty,direction,num)]=True
            return True

        memo[(startx,starty,direction,num)]=False
        return False

if dfs(0,0,0,0):
    print('Yes')
else:
    print('No')


### FIXED CODE ###

from itertools import groupby


s=input()
x,y=map(int,input().split())
data=[s[i] for i in range(0,len(s))]
data=groupby(data)
LR=[]
UD=[]
point='LR'
flag=0
checkx=2**8000
for key,group in data:
    g=len(list(group))
    if key=='F':
        if flag==0:
            checkx=checkx<<g
            flag=1
        else:
            if point=='LR':
                LR.append(g)
            else:
                UD.append(g)
    else:
        if g%2==1:
            if point=='LR':
                point='UD'
            else:
                point='LR'
        flag=1


for i in range(0,len(LR)):
    checkx=(checkx<<LR[i])|(checkx>>LR[i])

checky=2**8000
for i in range(0,len(UD)):
    checky=(checky<<UD[i])|(checky>>UD[i])


if checkx>>(x+8000) &1==1 and checky>>(y+8000) &1==1:
    print('Yes')
else:
    print('No')
list = [i for i in range(1, K + 1)]
odd = list[1::2]
even = list[0::2]

cnt = 0

for i in odd:
    for j in even:
        cnt += 1

print(cnt)

### FIXED CODE ###

K = int(input())
list = [i for i in range(1, K + 1)]
odd = list[1::2]
even = list[0::2]

cnt = 0

for i in odd:
    for j in even:
        cnt += 1

print(cnt)
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == "?":
      break
    else:
      print(a op b)

### FIXED CODE ###

while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == "+":
      print(a + b)
    elif op == "-":
      print(a - b)
    elif op == "*":
      print(a * b)
    elif op == "/":
      print(a // b)
    else:
      break
from collections import deque

def isPa(w,k,p):
    counter = 0
    s = 0
    n = 1
    wlen = len(w)
    while(True):
        if( sum([s:s+n]) >= p):
            s = s+n
            n = 1
            counter += 1
        else:
            n += 1
            if( s+n == len(a)):
                counter += 1
                break
    if(counter > k):
        return False
    else:
        return true
    
def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)
l = range(mean,maxinp)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP):
            print(maxP)
            break

### FIXED CODE ###

from collections import deque

def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break
n = int(input())
x = input().split()
x_int = [int(i) for i in x]
y = list(range(n))

for i in range(n):
     y[-i-1] = x_int[i]
for i in y:
    print('{} 'format(i),end = '')

### FIXED CODE ###

n = int(input())
x = input().split()
x_int = [int(i) for i in x]
y = list(range(n))

for i in range(n):
     y[-i-1] = x_int[i]
y_str = [str(i) for i in y]
print(' '.join(y_str))
N,K=map(int, input().split())
A=list(map(int, input().split()))
import sys
sys.setrecursionlimit(10**8)
import numpy as np
done=np.array([0]*N)
X=[0]*2
L=[]
F=[True]
def dfs(start, steps):
    done[start-1]+=1
    L.append(start)
    if done[start-1]==3:
        X[1]=steps
        return
    elif done[start-1]==2 and F[0]:
        X[0]=steps
        F[0]=False
    nex=A[start-1]
    dfs(nex, steps+1)
dfs(1,0)
#print(done)
#print(X)
#print(L)
first=L[:X[0]-(X[1]-X[0])]
sec=L[X[0]-(X[1]-X[0]):X[0]-(X[1]-X[0])+(X[1]-X[0])]
#print(first, sec)
if len(first)==0:
    first=sec
if K-1<=len(first):
    print(first[K])
else:
    K=K-len(first)
    print(sec[(K%len(sec))])


### FIXED CODE ###

N,K=map(int, input().split())
A=list(map(int, input().split()))
import sys
sys.setrecursionlimit(10**8)
import numpy as np
done=np.array([0]*N)
X=[0]*2
L=[]
F=[True]
def dfs(start, steps):
    done[start-1]+=1
    L.append(start)
    if done[start-1]==3:
        X[1]=steps
        return
    elif done[start-1]==2 and F[0]:
        X[0]=steps
        F[0]=False
    nex=A[start-1]
    dfs(nex, steps+1)
dfs(1,0)
#print(done)
#print(X)
#print(L)
first=L[:X[0]-(X[1]-X[0])]
sec=L[X[0]-(X[1]-X[0]):X[0]-(X[1]-X[0])+(X[1]-X[0])]
#print(first, sec)
if len(first)==0:
    first=sec
if K+1<=len(first):
    print(first[K])
else:
    K=K-len(first)
    print(sec[(K%len(sec))])
import sys


def main():
    sys.setrecursionlimit(int(1e4))
    nvertices, nedges = map(int, input().split())
    Adj = [[] for i in range(nvertices)]
    Adjrev = [[] for i in range(nvertices)]
    for i in range(nedges):
        s, t = map(int, input().split())
        Adj[s].append(t)
        Adjrev[t].append(s)

    ordering = []
    visited = [False] * nvertices
    for u in range(nvertices):
        if not visited[u]:
            dfs1(u, Adj, visited, ordering)

    ordering.reverse()
    component_ids = [-1] * nvertices
    id = 0
    visited = [False] * nvertices
    for u in ordering:
        if visited[u]:
            continue
        dfs2(u, Adjrev, id, visited, component_ids)
        id += 1

    Q = int(input())
    for i in range(Q):
        s, t = map(int, input().split())
        if component_ids[s] == component_ids[t]:
            print(1)
        else:
            print(0)


def dfs1(u, Adj, visited, ordering):
    visited[u] = True
    for v in Adj[u]:
        if visited[v]:
            continue
        dfs1(v, Adj, visited, ordering)
    ordering.append(u)


def dfs2(u, Adj, id, visited, component_ids):
    visited[u] = True
    component_ids[u] = id
    for v in Adj[u]:
        if not visited[v]:
            dfs2(v, Adj, id, visited, component_ids)


main()

### FIXED CODE ###

import sys

def main():
    sys.setrecursionlimit(int(1e5))
    nvertices, nedges = map(int, input().split())
    Adj = [[] for i in range(nvertices)]
    AdjRev = [[] for i in range(nvertices)]
    for i in range(nedges):
        u, v = map(int, input().split())
        Adj[u].append(v)
        AdjRev[v].append(u)

    lst = []
    visited = [False] * nvertices
    for u in range(nvertices):
        if not visited[u]:
            dfs_first(u, Adj, visited, lst)

    lst.reverse()
    ids = [-1] * nvertices
    visited = [False] * nvertices
    id = 0
    for u in lst:
        if not visited[u]:
            dfs_second(u, AdjRev, visited, id, ids)
            id += 1

    Q = int(input())
    for i in range(Q):
        u, v = map(int, input().split())
        print(1 if ids[u] == ids[v] else 0)


def dfs_first(u, Adj, visited, lst):
    visited[u] = True
    for v in Adj[u]:
        if not visited[v]:
            dfs_first(v, Adj, visited, lst)
    lst.append(u)


def dfs_second(u, Adj, visited, id, ids):
    ids[u] = id
    visited[u] = True
    for v in Adj[u]:
        if not visited[v]:
            dfs_second(v, Adj, visited, id, ids)

main()
# AtCoder Regular Contest 073
# D - Simple Knapsack
# https://atcoder.jp/contests/arc073/tasks/arc073_b
from itertools import combinations_with_replacement, accumulate
N, W, *A = map(int, open(0).read().split())
w0 = A[0]
T = [[] for _ in [0]*4]
M = [0]*4

for w, v in zip(*[iter(A)]*2):
    T[w-w0].append(v)
    M[w-w0] += 1
for t in T:
    t.sort()

acm = [tuple(accumulate(t)) for t in T]


def rec(w=0, k=0, c=()):
    if k == 4:
        C.append(c)
        return
    for i in range(M[k]+1):
        w1 = w + i*(w0+k)
        if w1 > W:
            break
        rec(w1, k+1, (*c, i))


C = []
rec()

ans = 0
for c in C:
    ans = max(ans, sum(acm[i][n-1] if n > 0 else 0 for i, n in enumerate(c)))

print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, W = map(int, input().split())
A = [tuple(map(int, input().split())) for _ in [0]*N]
w0 = A[0][0]
A = [(w-w0, v) for w, v in A]

dp = [[0]*(3*N) for _ in [0]*(N+1)]
ans = 0
sumw = 0
for k, (w, v) in enumerate(A):
    for i in range(k, -1, -1):
        for j in range(sumw, -1, -1):
            if 0 <= i < N and 0 <= j+w < 3*N and (i+1)*w0+j+w <= W:
                dp[i+1][j+w] = max(dp[i][j]+v, dp[i+1][j+w])
    sumw += w

for d in dp:
    ans = max(ans, *d)
print(ans)
import sys
N=int(input())
x=[int(i) for i in input().split()]
cnt=0
while(1):
    for i in range(N):
        if x[i]%2 != 0:
            print(cnt)
            sys.exit()
    tmp=[i//2 for i in x]
    x=tmp
    cnt+=1

### FIXED CODE ###

print(input().count("1"))