Harryxun/stf_run huggingface dataset:
s = input()
x, y = map(int, input().split())
N = len(s)
a = []
b = []
c = 0
n = 0
for i in range(len(s)):
  if s[i]=='F':
    n += 1
  else:
    if c%2==0:
      a += [n]
    else:
      b += [n]
    c += 1
    n = 0
if c%2==0:
  a += [n]
else:
  b += [n]
sa = sum(a)
sb = sum(b)
dpa = [[0]*(2*sa+1) for i in range(len(a)+1)]
dpb = [[0]*(2*sb+1) for i in range(len(b)+1)]

dpa[0][sa] = 1
dpb[0][sb] = 1

for i in range(1,len(a)+1):
  c = a[i-1]
  for j in range(2*sa+1):
    if dpa[i-1][j]==1:
      dpa[i][j-c] = 1
      dpa[i][j+c] = 1
for i in range(1,len(b)+1):
  c = b[i-1]
  for j in range(2*sb+1):
    if dpb[i-1][j]==1:
      dpb[i][j+c] = 1
      dpb[i][j-c] = 1
if sa<x or sb<y:
  print('No')
elif dpa[-1][x+sa]==1 and dpb[-1][y+sb]==1:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

s = input()
x, y = map(int, input().split())
a = []
b = []
c = 0
n = 0
for i in range(len(s)):
  if s[i]=='F':
    n += 1
  else:
    if c%2==0:
      a += [n]
    else:
      b += [n]
    c += 1
    n = 0
if s[-1]=='F':
  if c%2==0:
    a += [n]
  else:
    b += [n]
sa = sum(a)
sb = sum(b)
dpa1 = [0]*(2*sa+1)
dpa2 = [0]*(2*sa+1)
dpb1= [0]*(2*sb+1)
dpb2 = [0]*(2*sb+1)
dpa1[sa] = 1
dpb1[sb] = 1
if len(a)>0:
  if sa-a[0]<abs(x-a[0]) or sb<abs(y):
    print('No')
    import sys
    sys.exit()
else:
  if sa<abs(x) or sb<abs(y):
    print('No')
    import sys
    sys.exit()

if len(a)%2==0:
  A = dpa1
else:
  A = dpa2
if len(b)%2==0:
  B = dpb1
else:
  B = dpb2

for i in range(len(a)):
  c = a[i]
  if i%2==0:
    for j in range(2*sa+1):
      if dpa1[j]==1:
        dpa1[j] = 0
        dpa2[j-c] = 1
        dpa2[j+c] = 1
  else:
    for j in range(2*sa+1):
      if dpa2[j]==1:
        dpa2[j] = 0
        dpa1[j-c] = 1
        dpa1[j+c] = 1
for i in range(len(b)):
  c = b[i]
  if i%2==0:
    for j in range(2*sb+1):
      if dpb1[j]==1:
        dpb1[j] = 0
        dpb2[j-c] = 1
        dpb2[j+c] = 1
  else:
    for j in range(2*sb+1):
      if dpb2[j]==1:
        dpb2[j] = 0
        dpb1[j-c] = 1
        dpb1[j+c] = 1

if A[x+sa]==1 and B[y+sb]==1:
  print('Yes')
else:
  print('No')
n=int(input())
p=[]
for i in range(n):
    p.append(tuple(map(int,input().split())))

for j in range(101):
    for k in range(101):
        H=None
        f=1
        for x,y,h in p:
            if h>0 and H==None:
                H=h+abs(x-j)+abs(y-k)
            else:
                if max(0,H-abs(x-j)-abs(y-k))!=h:
                    f=0
        if f:
            print(j,k,H)
            exit()


### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):
    x,y,h=map(int,input().split())
    a.append([x,y,h])

def hight(inp):
    cx,cy,x,y,h=inp
    if h==0:
        return -1
    else:
        return abs(x-cx)+abs(y-cy)+h
    
for cx in range(101):
    for cy in range(101):
        H=set()
        for i in range(n):
            h=hight([cx,cy]+a[i])
            if h!=-1:
                H.add(h)
        if len(H)==1:
            flg=True
            for i in H:
                d=i
            for i in range(n):
                x,y,h=a[i]
                if max(0,d-abs(x-cx)-abs(y-cy))!=h:
                    flg=False
            if flg:
                ans=cx,cy,d
print(*ans)
i = input()

T = ['dreamer', 'dream', 'eraser', 'erase']

def exec(s):
    for t in T:
        if s.startswith(t):
            n = s.replace(t, '', 1)
            if len(n) == 0:
                print('YES')
                exit()
            else:
                exec(n)

exec(i)
print('NO')

### FIXED CODE ###

i = input()[::-1]
T = []
for t in ['dreamer', 'dream', 'eraser', 'erase']:
    T.append(t[::-1])

match = True
while match:
    match = False
    for t in T:
        if i.startswith(t):
            match = True
            i = i.replace(t, '', 1)
            if len(i) < 1:
                print('YES')
                exit()

print('NO')
import sys 
a = sys.argv[1]
if a == '25':
    print('Christmas')
if a == '24':
    print('Christmas Eve')
if a == '23':
    print('Christmas Eve Eve')
if a == '22':
    print('Christmas Eve Eve Eve')


### FIXED CODE ###

a = input()
if a == '25':
    print('Christmas')
if a == '24':
    print('Christmas Eve')
if a == '23':
    print('Christmas Eve Eve')
if a == '22':
    print('Christmas Eve Eve Eve')
def dfs(i, sum, count, nokori):
    global ans
    if i == d:
        # G 点に満たなければ nokori のうち一番大きいものを解く
        if sum < g:
            use = max(nokori)
            # 解く問題が問題数を超えないように注意
            n = min(pc[use - 1][0], (g - sum) // (use * 100)))
            count += n
            sum += n * use * 100

        if sum >= g:
            ans = min(ans, count)
    else:
        # 総合スコア、解いた問題数、まだ解いてない問題を更新
        dfs(i + 1, sum, count, nokori)
        dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})

d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)


### FIXED CODE ###

def dfs(i, sum, count, nokori):
    global ans
    if i == d:
        # G 点に満たなければ nokori のうち一番大きいものを解く
        if sum < g:
            use = max(nokori)
            # 解く問題が問題数を超えないように注意
            n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
            count += n
            sum += n * use * 100

        if sum >= g:
            ans = min(ans, count)
    else:
        # 総合スコア、解いた問題数、まだ解いてない問題を更新
        dfs(i + 1, sum, count, nokori)
        dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})


d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)
from collections import Counter
from operator import itemgetter

N = int(input())
V = Counter(map(int, input().split()))

#print(V)
#A = list(V.keys())
#B = list(V.values())
C = list(V.items())
C = sorted(C,key=itemgetter(0))

if len(C) == 3:
    ans = abs(C[0][1]- C[2][1])
elif len(C) == 2:
    ans = 0
elif len(C) == 1:
    ans = 2
print(ans)

### FIXED CODE ###

from collections import Counter

n = int(input())
v = list(map(int,input().split()))
ac = Counter(v[::2]).most_common(2)
bc = Counter(v[1::2]).most_common(2)



if ac[0][0] != bc[0][0]:            #奇数列と偶数列の最頻数が同じ要素でない場合
    ans =  n - ac[0][1] - bc[0][1]  #全体の数から書き換える必要がない数（それぞれの最頻値）を引けばよい
else:                               #奇数列と偶数列の最頻数が同じ要素の数の場合
    if len(bc) == 1 or len(ac) == 1:#全部同じ数の場合 
        ans = n // 2
    else: #２番目の最頻数を比較し、大きいほうの列の最も多大きい最頻数ともう一方の列の2番目に大きい最頻数を書き換える
        ans = n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])
print(ans)
N, M = map(int, input().split())
X = list(map(int, input().split()))
ans = 0
diff = []

X.sort()

for i in range(M-1):
  dif = X[i+1] -X[i]
  diff.append(dif)
  
diff.sort()

for n in range(N):
  diff.pop(-1)

for i in range(len(diff)):
  ans += diff[i]


### FIXED CODE ###

N, M = map(int, input().split())
X = list(map(int, input().split()))
ans = 0
diff = []
 
X.sort()
 
if (N < M): 
    for i in range(M-1):
        dif = X[i+1] - X[i]
        diff.append(dif)
    
    diff.sort()
    
    for i in range(M-N):
        ans += diff[i]
    # for n in range(N):
    #     diff.pop(-1)
   
    # for i in range(len(diff)):
    #     ans += diff[i]
print(ans)
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
return 'Even' if ((a*b)/2 == 0) else 'Odd'

### FIXED CODE ###

# -*- coding: utf-8 -*-
a, b = map(int, input().split())
print("{}".format('Even' if ((a*b)%2 == 0) else 'Odd'))
A, B, K = list(map(int, input().split()))

S = []

for i in range(1, min(A,B)):
    if (A % i == 0) or (B % i == 0):
        S.append(i)
        

if A == 1 and B == 1 and K == 1:
    print(1)
else:
    print(S[K-1])

### FIXED CODE ###

A, B, K = list(map(int, input().split()))

S = [1]

for i in range(2,min(A+1,B+1)):
    if A % i == 0 and B % i == 0:
        S.append(i)

S.sort(reverse=True)

print(S[K-1])
N=int(input())
if N>M:
  print(N-M)
else:
  print(-1)

### FIXED CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
B=0
for i in A:
    B=B+i       
N=N-B
if 0<=N:
    print(N)
else:
    print(-1)
import numpy as np
import math

def solve():
    n,w = map(int,input().split())
    w_list,v_list = [0]*n,[0]*n
    for i in range(n):
        w_list[i],v_list[i] = map(int,input().split())
    dp = [[0]*(w+5) for i in range(n+5)]
    for i in range(n):
        for j in range(w+1):
            if j >= w_list[i]:
                dp[i][j] = max(
                    dp[i-1][j],
                    dp[i-1][j-w_list[i]]+v_list[i])
            else:
                dp[i][j] = dp[i-1][j]
    print(dp)
    print(dp[n-1][w])
    return 0

if __name__ == "__main__":
    solve()


### FIXED CODE ###


def solve():
    n,w = map(int,input().split())
    w_list,v_list = [0]*n,[0]*n
    for i in range(n):
        w_list[i],v_list[i] = map(int,input().split())
    dp = [[0]*(w+5) for i in range(n+5)]
    for i in range(n):
        for j in range(w+1):
            if j-w_list[i]>=0:
                dp[i][j] = max(dp[i-1][j],
                               dp[i-1][j-w_list[i]]+v_list[i])
            else:
                dp[i][j] = dp[i-1][j]
    print(dp[n-1][w])
    return 0
 
if __name__ == "__main__":
    solve()
s = list(input())
s_len = len(s)
i = 0
while True:
    if len(s) <= 1:
        break
    if s[i] == s[i+1] and len(s)==2:
        break
    if s[i] != s[i+1]:
        del s[i:i+2]
        i = 0
    else:
        i += 1
print(s_len-len(s))

### FIXED CODE ###

import collections
s = list(input())
c = collections.Counter(s)
print(2*min(c['0'],c['1']))
from scipy.special import comb
n = int(input())
if n/2==0:
    print(math.factorial(n)-1)
    
else:
  	print(math.factorial(n))

### FIXED CODE ###

import math
n = int(input())
if n%2==0:

    print(round(((n-2)/2)))


else:
    print(round(((n+1)/2)-1))
a, b = map(int, input().split())
count = 0

for i in range(a, b+1):
    i_str = str(i)
    length= len(i_str)
    list1 = []
    list2 = []
    for j in length:
        list1.append(i_str[i])
    for k in length:
        list2.append(i_str[-i])
    if list1 == list2:
        count += 1

print(count)

### FIXED CODE ###

a, b = map(int, input().split())
count = 0

for i in range(a, b+1):
    i_str = str(i)
    length= len(i_str)
    list1 = []
    list2 = []
    for j in range(length):
        list1.append(i_str[j])
    for k in range(length):
        list2.append(i_str[-k-1])
    if list1 == list2:
        count += 1

print(count)
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(a, b):
    if a==0:
        answer = atr(range(b))
    else:
        answer = (100*a*b)
    return answer

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b] = line.split(' ')
    return (int(str_a), int(str_b))

def main():
    a, b = readQuestion()
    answer = solve(a, b)
    print(answer)
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

def solve(a, b):
    if a == 0 or a==1 or a==2:
        if b==100:
            answer=100**a*b+(100**a)
        else:
            answer=100**a*b
    return answer

def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b] = line.split(' ')
    return (int(str_a), int(str_b))

def main():
    a, b = readQuestion()
    answer = solve(a, b)
    print(answer)

if __name__ == '__main__':
    main()
IN=lambda:map(int,input().split())
N,W=IN()
INF=float("inf")
dp=[INF]*(100*N)
dp.insert(0,0)
c=0
ans=0
for i in range(N):
    w,v=IN()
    for j in range((100*N+1),-1,-1):
        if dp[j-v]!=INF:
            dp[j]=min(dp[j],dp[j-v]+w)
for i in dp:
    c+=1
    if i<=W:
        ans=c-1
print(ans)   

### FIXED CODE ###

IN=lambda:map(int,input().split())
N,W=IN()
INF=float("inf")
dp=[INF]*(1000*N)
dp.insert(0,0)
c=0
ans=0
for i in range(N):
    w,v=IN()
    for j in range((1000*N+1),-1,-1):
        if dp[j-v]!=INF:
            dp[j]=min(dp[j],dp[j-v]+w)
for i in range(1000*N+1):
    if dp[i]<=W:
        ans=i
print(ans)
a,b=map(int,input().split())
ls = ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
x = [list(input().split()) for i in range(a)]
for i in range(a):
  for j in range(b):
    if x[a][b] == "snuke":
      print(ls[a]+str(b+1))
      break

### FIXED CODE ###

a,b=map(int,input().split())
ls = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
x = [list(input().split()) for i in range(a)]
for i in range(a):
  for j in range(b):
    if x[i][j] == "snuke":
      print(ls[j]+str(i+1))
      break
import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

list.sort(a, reverse=True)
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    if len(a) == 0:
	    break
    count -= a[i]

print(count)


### FIXED CODE ###

import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

#list.sort(a, reverse=True)
a.sort()
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    if len(a) == 0:
        break
    a.pop()
#    count -= a[i]

#print(count)
print(sum(a))
a=input()
b=input()
square=int(a)*int(b)
length=int(a)*2+int(b)*2
print(square),
print(length)

### FIXED CODE ###

InputNum = input().split()
tate = int(InputNum[0])
yoko = int(InputNum[1])
square = tate * yoko
length = 2* (tate + yoko)
print(square,length)
# -*- utf-8 -*-

while True:
    inp = raw_input()
    if inp == None:
        break
    i = map(int, inp.split())
    a = i[0]
    b = i[1]
    
    s = a + b
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print an

### FIXED CODE ###

# -*- utf-8 -*-

while True:
    try:
        inp = raw_input()
        i = map(int, inp.split())
        a = i[0]
        b = i[1]
    
        s = a + b
    except:
        break
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print ans
#coding:utf-8

S = input()

if S == 'Sunny':
    print('Cloudy')
elif S == 'Cloudy':
    print(Rainy)
else:
    print('Sunny')


### FIXED CODE ###

#coding:utf-8

S = input()

if S == 'Sunny':
    print('Cloudy')
elif S == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')
n, m = map(int, input().split())
dir = [[] for _ in range(m+1)]

for i in range(m):
    ta, tb = map(int, input().split())
    dir[ta].append(tb)
    dir[tb].append(ta)

ans = [0]*(n+1)
flag = [0]*(n+1)
flag[1] = 1
que = [1]
while len(que) != 0:
    print('que: ', len(que), que)
    now = que.pop()
    for to in dir[now]:
        if flag[to] == 1:
            continue
        que.append(to)
        flag[to] = 1
        ans[to] = now
"""         print(to)
        ans[to] = now
        flag[to] = 1
        for toto in dir[to]:
            if flag[toto] != 1:
                que.append(toto) """
print('Yes')
for i in range(2,n+1):
    print(ans[i])

### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
dir = [[] for _ in range(n+1)]

for i in range(m):
    ta, tb = map(int, input().split())
    dir[ta].append(tb)
    dir[tb].append(ta)

ans = [0]*(n+1)
flag = [False]*(n+1)
flag[1] = True
que = deque([1])
while que:
    #print('que: ', len(que), que)
    now = que.popleft()
    for to in dir[now]:
        if flag[to]:
            continue
        que.append(to)
        flag[to] = True
        ans[to] = now

print('Yes')
for i in range(2,n+1):
    print(ans[i])
N = int(input())


while N > i**2:
    i += 1

print((i-1)**2)

### FIXED CODE ###

N = int(input())

ans = 1
for i in range(N):
    if i**2 > N:
        ans = (i-1)**2
        break

print(ans)
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

ans = []
l = range(1, N + 1)
import itertools


for v in itertools.permutations(l, N):
    if list(v) == P:
      a = list(v).index(P)
        
    if list(v) == Q:
      b = list(v).index(Q)
    

print(abs(b - a))


### FIXED CODE ###

import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

permutations = list(itertools.permutations(range(1, N+1)))
p = permutations.index(P)
q = permutations.index(Q)
print(abs(p-q))
H,N =map(int, input().split())
a = [] 
M = 0 
for i in range(N):
	t = list(map(int, input().split()))
	a.append(t)
	M = max(M,t[0])
dp = [10000]*(H+1)
dp[0] = 0
for i in range(1,H+M):
	for j,k in a:
		dp[i+j] = min(dp[i+j],dp[i]+k)

print(min(dp[H:]))

### FIXED CODE ###

H,N =map(int, input().split())
a = [] 
M = 0 
for i in range(N):
	t = list(map(int, input().split()))
	a.append(t)
	M = max(M,t[0])
dp = [100000000]*(H+1+M)
dp[0] = 0
for i in range(H):
	for j,k in a:
		dp[i+j] = min(dp[i+j],dp[i]+k)

print(min(dp[H:]))
N = int(input())
S = str(input())
cou = 0
for i in range(N):
  if i <= N-2:
    if S[i] == "A" and S[i+1] == "B" and S[i+2]== "C":
      cou += 1
print(cou)

### FIXED CODE ###

N = int(input())
S = str(input())
cou = 0
for i in range(N-2):
  if S[i:i+3] == "ABC":
    cou += 1
print(cou)
n = int(input())
a = []
for i in n:
    x,y = map(int,input())
    a.append([x,y])
count = 0
flag = True
for x in a:
    if x[0] == x[1]:
        count += 1
        if count == 3:
            print('Yes')
            flag = False
            break
    else:
        count = 0

if flag:
    print('No')

### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
    x,y = map(int,input().split())
    a.append([x,y])
count = 0
flag = True
for x in a:
    if x[0] == x[1]:
        count += 1
        if count == 3:
            print('Yes')
            flag = False
            break
    else:
        count = 0

if flag:
    print('No')
def f(a, b):
    al = len(str(a))
    bl = len(str(b))
    if al > bl:
        return al
    return bl
N = int(input())
n = int(N**0.5)
result = 12
for i in range(1, n+1):
    for j in range(1, n+1):
        if i*j == N:
            r = f(i, j)
            if r < result:
                result = r
print result()


### FIXED CODE ###

def f(a, b):
    al = len(str(int(a)))
    bl = len(str(int(b)))
    if al > bl:
        return al
    return bl
N = int(input())
result = len(str(N))
for a in range(1, N):
    if a*a > N:
        break
    if (N % a) != 0:
        continue
    b = N / a
    r = f(a, b)
    if r < result:
        result = r
print (result)
a,b,c=map(int,input().split())

x=max(a,b,c)

print((a+b+c)-x+x*(2**k))

### FIXED CODE ###

a,b,c=map(int,input().split())
k=int(input())

x=max(a,b,c)

print((a+b+c)-x+x*(2**k))
from collections import defaultdict


class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size + 1))

    def is_same_set(self, x: int, y: int) -> bool:
        return self.find_root(x) == self.find_root(y)

    def union_set(self, x: int, y: int):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return

        self.parent[x] = y

    def find_root(self, x: int):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find_root(self.parent[x])
            return self.parent[x]


def dfs(n, used, edges, uf: UnionFind):
    used[n] = True
    for a in edges[n]:
        if not used[a]:
            uf.union_set(n, a)
            dfs(a, used, edges, uf)


def main():
    N, K, L = map(int, input().split())
    d1 = defaultdict(list)
    for _ in range(K):
        p, q = map(int, input().split())
        p -= 1
        q -= 1
        d1[p].append(q)
        d1[q].append(p)

    d2 = defaultdict(list)
    for _ in range(L):
        r, s = map(int, input().split())
        r -= 1
        s -= 1
        d2[r].append(s)
        d2[s].append(r)

    uf1 = UnionFind(N)
    used1 = [False] * N
    for n in range(N):
        if not used1[n]:
            dfs(n, used1, d1, uf1)

    uf2 = UnionFind(N)
    used2 = [False] * N
    for n in range(N):
        if not used2[n]:
            dfs(n, used2, d2, uf2)

    used3 = [False] * N
    ans = [0] * N
    for n1 in range(N):
        if used3[n1]:
            continue
        num = 1
        l = [n1]
        for n2 in range(n1 + 1, N):
            if not used3[n2]:
                if uf1.is_same_set(n1, n2) and uf2.is_same_set(n1, n2):
                    used3[n2] = True
                    l.append(n2)
                    num += 1
        for n in l:
            ans[n] = num

    print(" ".join(map(str, ans)))


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import Counter
import sys

sys.setrecursionlimit(10 ** 5 + 1)


class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size))

    def is_same_set(self, x: int, y: int) -> bool:
        return self.find_root(x) == self.find_root(y)

    def union_set(self, x: int, y: int):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return

        self.parent[x] = y

    def find_root(self, x: int):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find_root(self.parent[x])
            return self.parent[x]


def main():
    N, K, L = map(int, input().split())
    uf1 = UnionFind(N)
    for _ in range(K):
        p, q = map(int, input().split())
        p -= 1
        q -= 1
        uf1.union_set(p, q)

    uf2 = UnionFind(N)
    for _ in range(L):
        r, s = map(int, input().split())
        r -= 1
        s -= 1
        uf2.union_set(r, s)

    groups = [(uf1.find_root(i), uf2.find_root(i)) for i in range(N)]
    c = Counter(groups)

    print(*(c[g] for g in groups))


if __name__ == '__main__':
    main()
s = input()

for i in reversed(range(1, int((len(s)-1)/2+1))):
    if(s[:i] == s[i:2*i]):
        print(2*i)
        return


### FIXED CODE ###

s = input()

for i in reversed(range(1, int((len(s)-1)/2+1))):
    if(s[:i] == s[i:2*i]):
        print(2*i)
        break
A,B,Q = list(map(int, input().split()))
s,t,xx=[],[],[]

for i in range(A):
    s.append(int(input()))
for i in range(B):
    t.append(int(input()))
for i in range(Q):
    xx.append(int(input()))
    
import bisect
M = 10000000000000

for x in xx:
    i = bisect.bisect_left(s,x)
    j = bisect.bisect_left(t,x)
    
    if (i > 0) and (j > 0):
        ll = abs(min(s[i-1]-x, t[j-1]-x))
    else:
        ll = M
    if (i > 0) and (j < B):
        lr = abs(s[i-1]-x) * 2 + (t[j]-x)
    else:
        lr = M
    if (i < A) and (j > 0):
        lr_2 = abs(t[j-1]-x) * 2 + (s[i]-x)
    else:
        lr_2 = M
    if (i < A) and (j > 0):
        rl = (s[i]-x) * 2 + abs(t[j-1] - x)
    else:
        rl = M
    if (i > 0) and (j < B):
        rl_2 = (t[j]-x) * 2 + abs(s[i-1] - x)
    else:
        rl_2 = M
    if (i < A) and (j < B):
        rr = max(s[i]-x,t[i]-x)
    else:
        rr = M

    print(min(ll,lr,rl,rr,lr_2,rl_2))

### FIXED CODE ###

A,B,Q = list(map(int, input().split()))
s,t,xx=[],[],[]

for i in range(A):
    s.append(int(input()))
for i in range(B):
    t.append(int(input()))
for i in range(Q):
    xx.append(int(input()))
    
import bisect
M = 10000000000000

for x in xx:
    i = bisect.bisect_left(s,x)
    j = bisect.bisect_left(t,x)
    
    if (i > 0) and (j > 0):
        ll = abs(min(s[i-1]-x, t[j-1]-x))
    else:
        ll = M
        
    if (i > 0) and (j < B):
        lr = abs(s[i-1]-x) * 2 + (t[j]-x)
    else:
        lr = M
        
    if (i < A) and (j > 0):
        lr_2 = abs(t[j-1]-x) * 2 + (s[i]-x)
    else:
        lr_2 = M
        
    if (i < A) and (j > 0):
        rl = (s[i]-x) * 2 + abs(t[j-1] - x)
    else:
        rl = M
        
    if (i > 0) and (j < B):
        rl_2 = (t[j]-x) * 2 + abs(s[i-1] - x)
    else:
        rl_2 = M
        
    if (i < A) and (j < B):
        rr = max(s[i]-x,t[j]-x)
    else:
        rr = M

    print(min(ll,lr,rl,rr,lr_2,rl_2))
from itertools import combinations
N,K = map(int, input().split())
MAX_K = (N-1)*(N-2)//2
if K > MAX_K:
    print(-1);exit()
M = N-1 + MAX_K-K
print(M)
for e in combinations(range(1, N+1), 2))[:M]:
    print(*e)


### FIXED CODE ###

from itertools import combinations

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

MAX_K = (N-1)*(N-2)//2
if K > MAX_K:
    print(-1)
    exit()

M = N-1 + (MAX_K - K)
print(M)
edges = list(combinations(range(1, N+1), 2))[:M]
# print(edges)
for e in edges:
    print(*e)