Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import math
from functools import reduce
import itertools
import numpy as np


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())

#l = [i for i in range(1, K + 1)]

temp_sum = []
#for j in itertools.product(l, repeat=3):
#    temp_sum.append(gcd_list(list(j)))
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            temp_sum.append(gcd_list([i,j,l]))

print(np.sum(temp_sum))

### FIXED CODE ###

import math
from functools import reduce
import itertools
import numpy as np

K = int(input())



ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            if i == j and j == k:
                dup_num = 1
            elif i == j or j == k:
                dup_num = 3
            else:
                dup_num = 6
            ans += math.gcd(math.gcd(i, j), k) * dup_num

print(ans)
### BUGGY CODE ###

# E - Coprime

import math
from functools import reduce
from itertools import chain
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
assert len(a) == n

if reduce(math.gcd, a) > 1:
    print("not coprime")
    exit()

def primes_under(n):
    plist = []
    isprime = [1] * (n + 1)
    for p in range(2, n + 1):
        if isprime[p]:
            plist.append(p)
            for q in range(p + p, n + 1, p):
                isprime[q] = 0
    return plist

primes = primes_under(10 ** 6)
primeset = set(primes)

def factors(n):
    """Return the list of prime factors of n."""
    if n in primeset:
        return {n}
    fac = set()
    sqrtn = math.sqrt(n)
    i = 0
    while primes[i] <= sqrtn:
        if n % primes[i] == 0:
            fac.add(primes[i])
            n //= primes[i]
        else:
            i += 1
    if n > 1:
        fac.add(n)
    return fac

c = Counter(chain.from_iterable(map(factors, a)))
if max(c.values(), default=0) > 1:
    print("setwise coprime")
else:
    print("pairwise coprime")


### FIXED CODE ###

# E - Coprime

import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
assert len(a) == n

if reduce(math.gcd, a) > 1:
    print("not coprime")
    exit()

def factors(n):
    """Return the list of prime factors of n."""
    fac = set()
    sqrtn = math.sqrt(n)
    d = 2
    while d <= sqrtn:
        if n % d == 0:
            fac.add(d)
            n //= d
        else:
            d += 1
    if n > 1:
        fac.add(n)
    return fac

count = [0] * (10 ** 6 + 1)
for x in a:
    for f in factors(x):
        count[f] += 1
        if count[f] > 1:
            print("setwise coprime")
            exit()
print("pairwise coprime")
### BUGGY CODE ###

import collections

N=int(input())
L=list(map(int,input().split()))
M=collections.Counter(L)
K=[]
for i,j in (M.items()):
	K.append(j*(j-1)//2)
T=sum(K)
for k in L:
	for i,j in (M.items()):
		if k==i:
			print(T-(j*(j-1)//2)+(j-1)*(j-2)//2)

### FIXED CODE ###

from collections import Counter

N=int(input())
L=list(map(int,input().split()))
M=Counter(L)
Z={}
#print(M)
pft=0
for i,j in M.items():
	Z[i]=(j*(j-1)//2,((j-2)*(j-1)//2))
	pft+=Z[i][0]
#print(Z)
for i in range(N):
	print(pft-Z[L[i]][0]+Z[L[i]][1])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split())) 
correct_answer_count = 0
for i in range(N):
    bat_answer_count = 0
    for j in range(i):
        if len(A) < j:
            continue
        if not (A[i] <= A[j]):
            bat_answer_count += 1

    if bat_answer_count == 0:
        correct_answer_count += 1

print(correct_answer_count)    


### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
 
cnt = 0
p_min = p[0]
for i in range(n):
  pi = p[i]
  if pi <= p_min:
    cnt += 1
    p_min = pi
print(cnt)
### BUGGY CODE ###

S = input()
Q = int(input())
Left = []
Right = []
Reverse = False
for q in range(Q):
    query = input().split()
    if query[0]=="1":
        Reverse = not Reverse
    elif (query[1]=="1") ^ Reverse:#左側にくっつく
        S = query[2] + S
    else:
        S = S + query[2]
if Reverse:
    ans = "".join(reversed(S))
else:
    ans = S
print(ans)

### FIXED CODE ###

import sys
fastinput = sys.stdin.readline
from collections import deque
S = input()
Q = int(input())
ans = deque([S])
Reverse = False
for q in range(Q):
    query = fastinput().split()
    if query[0]=="1":
        Reverse = not Reverse
    elif (query[1]=="1") ^ Reverse:#左側にくっつく
        ans.appendleft(query[2])
    else:
        ans.append(query[2])
SS = "".join(list(ans))
if Reverse:
    SS = "".join(reversed(SS))
print(SS)
### BUGGY CODE ###

a,b,n=map(int,input().split())
x=0
while int(x//b)==0 and x<=n:
    x+=1
print((int((a*(x-1))//b) - a*(int((x-1)//b))))

### FIXED CODE ###

A,B,N= map(int,input().split())
max_num = 0
x = min(B-1,N)
print(int((A*x)/B)-(A*int(x/B)))
### BUGGY CODE ###

from itertools import permutations , combinations,combinations_with_replacement

n , l = map(int , input().split())
s = []
for _ in range(n):
    s.append(input())
p = permutations(s,n)
ss = []
for i in p:
    ss.append("".join(i))
ss.sort()
print(ss[0])

### FIXED CODE ###

n , l = map(int , input().split())
s = sorted([input() for _ in range(n)])
print(''.join(s))
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]
nokori_games = n * (n - 1) / 2 
day = 1
r5000 = range(5000)
player_in_this_game = set()
for _ in r5000:
  rn = range(n)
  for m in rn: #選手ごとに判定
    #整合性のある対戦組み合わせがあれば配列から消す
    #全員の判定が終わって試合が残っていたら1日増やす
    la = len(a[m])      
    if la: #選手に試合予定が残っている
      teki = a[m][0] #対戦相手
      jibun = m + 1 #自分
      teki_idx = teki - 1
      if m in player_in_this_game or teki_idx in player_in_this_game:
        #自分または相手に既に試合が組まれている
        pass
      elif a[teki_idx][0] == jibun: #対戦相手の予定も自分でかつ相手がこのターンで試合中ではない
        a[m].popleft() #自分の予定を消す
        a[teki_idx].popleft() #相手の予定を消す
        player_in_this_game.add(m) #自分を試合中にする
        player_in_this_game.add(teki_idx) #相手を試合中にする
        nokori_games -= 1 #残り試合予定を1つ減らす

  if nokori_games: #残り試合があるのに
    if not len(player_in_this_game): #今回対戦が組まれなければ残りの予定が不整合なのでエラー
      print(-1)
      sys.exit()
  else: #誰も残り試合予定がなければ終了
    print(day)
    sys.exit()
  day += 1
  player_in_this_game.clear()


### FIXED CODE ###

import sys
import time
from collections import deque

start = time.time()

input = sys.stdin.readline

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]
nokori_games = n * (n - 1) / 2 
day = 1
r5000 = range(5000)
player_in_this_game = set()
rn = range(n)
for _ in r5000:
  for m in rn: #選手ごとに判定
    #整合性のある対戦組み合わせがあれば配列から消す
    #全員の判定が終わって試合が残っていたら1日増やす
    if m in player_in_this_game:
      #自分が既に試合が組まれている
      continue

    la = len(a[m])      
    if la: #選手に試合予定が残っている
      teki = a[m][0] #対戦相手
      jibun = m + 1 #自分
      teki_idx = teki - 1
      if teki_idx in player_in_this_game:
        #相手が既に試合に組まれている
        continue

      if a[teki_idx][0] == jibun: #対戦相手の予定も自分でかつ相手がこのターンで試合中ではない
        a[m].popleft() #自分の予定を消す
        a[teki_idx].popleft() #相手の予定を消す
        player_in_this_game.add(m) #自分を試合中にする
        player_in_this_game.add(teki_idx) #相手を試合中にする
        nokori_games -= 1 #残り試合予定を1つ減らす

  if nokori_games: #残り試合があるのに
    if not len(player_in_this_game): #今回対戦が組まれなければ残りの予定が不整合なのでエラー
      print(-1)
      sys.exit()
  else: #誰も残り試合予定がなければ終了
    print(day)
    sys.exit()
  day += 1
  player_in_this_game.clear()
  elapsed_time = time.time() - start
  if elapsed_time > 1:
    print(n*(n-1)//2)
    exit()
### BUGGY CODE ###

n, *bc = map(int, open(0).read().split())
a = [bc.pop(0) for _ in range(n)]
q = bc.pop(0)

d = {}
for x in a:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1
ret = sum(a)
for i in range(0, min(q*2, len(bc)), 2):
    b = bc[i]
    c = bc[i+1]
    if b in d:
        v = d.pop(b)
        if c in d:
            d[c] += v
        else:
            d[c] = v
        ret += c * v - b * v
    #ret = sum([k * v for k, v in d.items()])
    print(ret)

### FIXED CODE ###

n, r = open(0).read().split(maxsplit=1)
n = int(n)
*a, r = r.split(maxsplit=n)
a = list(map(int, a))
q, *bc = map(int, r.split())

d = {}
for x in a:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1
ret = sum(a)
for i in range(0, min(q*2, len(bc)), 2):
    b = bc[i]
    c = bc[i+1]
    if b in d:
        v = d.pop(b)
        if c in d:
            d[c] += v
        else:
            d[c] = v
        ret += c * v - b * v
    #ret = sum([k * v for k, v in d.items()])
    print(ret)
### BUGGY CODE ###

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

sa = list(set(a))

if len(sa) > nk[1]:
	c = []
	for i in range(len(sa)):
		c.append(a.count(sa[i]))
		
	sortc = sorted(c, reverse = True)
	m = 0
	for i in range(nk[1]):
		m += sortc[i]
	ans = nk[0] - m
else:
	ans = 0

print(ans)


### FIXED CODE ###

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

cli = []
for i in range(nk[0]+1):
	cli.append(0)

for i in range(nk[0]):
	cli[a[i]] += 1

c = sorted(cli, reverse = True)

m = 0
for i in range(nk[1]):
	m += c[i]

ans = nk[0] - m
if ans < 0:
	ans = 0
	
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

n = int(input())
x = input()
#b = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

def countSetBits(n): 
    count = 0
    while (n): 
        count += n & 1
        n >>= 1
    return count

MAX_X = 10**7
CSB = [0]*MAX_X

# convert base-2 binary number string to int
x = int(x,2)

def toggle_nth_bit(num: int, n: int):
    return num ^ (1 << n)

ans = []

for i in range(0,n):
    tmp_x = toggle_nth_bit(x,i)
    tmp_n = countSetBits(tmp_x)
    tmp = 0
    while tmp_x > 0:
        tmp_x %= tmp_n
        tmp_n = countSetBits(tmp_x)
        tmp += 1
    ans.append(tmp)
    
print(*ans[::-1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n = int(input())
s = input()

def pcnt(x):
    return bin(x).count('1')

def f(x):
    if x == 0: return 0
    return f(x%pcnt(x))+1

x = [0]*n

for i in range(n):
    x[i] = int(s[i])

# 元のpopcountを求める
pc = sum([x[i] for i in range(n)])

ans = [0]*n

# b: 元のbit
for b in range(2):
    npc = pc
    if b == 0: npc += 1
    else: npc -= 1
        
    if npc <= 0: continue # 0除算が発生するため
    
    # 元の数をpopcountで割ったあまりを求める
    # 例えば2進数1101を10進数に変換するには、1, 1の2倍の2に1を足して3, 3の2倍の6に0を足して6, 6の2倍に1を足して13、と計算できる。今回はこれを%npcする操作が加わる
    r0 = 0
    for i in range(n):
        r0 = (r0*2)%npc
        r0 += x[i]
    
    # 一番下の桁からループを回す
    # i桁目をフリップしたときのあまりを求める
    # 下からi桁目をフリップすると2^i変わる。その値をkとして計算する。同じループの中で2^i(k)のあまりも求める
    k = 1
    for i in range(n-1, -1, -1):
        if x[i] == b:
            r = r0
            if b == 0: r = (r+k)%npc
            else: r = (r-k+npc)%npc # r-kだけだとマイナスになることがある
            ans[i] = f(r)+1
        k = (k*2)%npc

print(*ans)
### BUGGY CODE ###

import math

def cmb(n,r):
    if r == 0:
        return 1
    return math.factorial(n) // math.factorial(n-r) // math.factorial(r)

def main():
    N,M,K = map(int, input().split())
    ans = 0
    complement = cmb(N*M-2,K-2)
    for i in range(N-1):
        for j in range(i+1,N):
            d = abs(i - j)
            ans += d * M**2
    for i in range(M-1):
        for j in range(i+1,M):
            d = abs(i - j)
            ans += d * N**2
    print((ans*complement) % 1000000007)

main()


### FIXED CODE ###

import math

mod = 10**9+7
N,M,K = map(int, input().split())
MAX = min(N*M,mod)

facts = [1 for i in range(MAX)]
invs = [1 for i in range(MAX)]

def inv(x):
	return pow(x,mod-2,mod)

for i in range(1,MAX):
    facts[i] = (facts[i-1] * i)% mod
    invs[i] = inv(facts[i])

def nCr(n,r):
	return facts[n] * invs[r] * invs[n-r] % mod

def main():
    ans = 0
    complement = nCr((N*M-2)%mod,(K-2)%mod)
    for i in range(1,N):
        ans += i * (N-i) * M**2
    for i in range(1,M):
        ans += i * (M-i) * N**2
    print((ans*complement) % mod)

main()
### BUGGY CODE ###

# coding : utf-8
n=int(input())
p=1 #a/b
x,y=1,1
for i in range(n):
    a,b=map(int,input().split())
    while p != a/b:
        if p < a/b:
            x+=1
        else:
            y+=1
        p=x/y
print(x+y)



### FIXED CODE ###

from decimal import *
n=int(input())
log=[]
H=[]
for i in range(n):
    log.append(tuple(map(int,input().split())))
t,a=1,1
for x,y in log:
    nxt=max(t//x + (1 if t%x else 0),a//y + (1 if a%y else 0))
    t=x*nxt
    a=y*nxt
print(t+a)
### BUGGY CODE ###

k,s=map(int,input().split())
ans=0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            if i+j+k==s:
                ans+=1
print(ans)


### FIXED CODE ###

k,s=map(int,input().split())
ans=0
for i in range(k+1):
    for j in range(k+1):
            if k>=s-i-j>=0:
                ans+=1
print(ans)
### BUGGY CODE ###

from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    f = list(map(int, input().split()))
    a.sort()
    f.sort(reverse=True)

    q = [(-a[i]*f[i], -f[i]) for i in range(n)]
    heapify(q)

    for i in range(k):
        t, g = heappop(q)
        heappush(q, (t-g, g))

    ans, _ = heappop(q)
    print(-ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

left, right = -1, a[-1] * f[0]

while right - left > 1:
    mid = (left + right) // 2
    ck = 0
    for i in range(n): ck += max(0, a[i] - mid // f[i])
    if ck <= k: right = mid
    else: left = mid

print(right)
### BUGGY CODE ###

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

num = len(a)
ans = 0

for i in range(num - 1):
    tar = a[i] + a[i + 1]
    if (tar <= x):
        continue
    else:
        while (tar > x):
            a[i + 1] -= 1
            ans += 1
            tar = a[i] + a[i + 1]


print(ans)


### FIXED CODE ###

n, x = map(int, input().split())
a = list(map(int, input().split()))
num = len(a)


ans = 0

for i in range(num - 1):
    tar = a[i] + a[i + 1]
    if (tar <= x):
        continue
    else:
        dif = tar - x
        if (a[i + 1] >= dif):
            ans += dif
            a[i + 1] -= dif

        else:
            ans += a[i + 1]
            dif -= a[i + 1]
            a[i + 1] = 0

            a[i] -= dif
            ans += dif


print(ans)
### BUGGY CODE ###

import random
from copy import deepcopy

d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(d)]

def min_max(l):
    l_min = min(l)
    l_max = max(l)
    return [0.1+(i-l_min)/(l_max-l_min)for i in l]

dd = [max(s[i]) for i in range(d)]
qq = min_max(c)
dd = min_max(dd)

ddd = [i for i in range(d)]
qqq = [i for i in range(26)]

ans = []
last = [0]*26
for i in range(d):
    ma_po = -10**10
    ma_di = 0
    for j in range(26):
        po = s[i][j]
        for k in range(26):
            if k == j:
                continue
            po -= c[k]*(i+1-last[k])
        if po > ma_po:
            ma_po = po
            ma_di = j
    last[ma_di] = i+1
    ans.append(ma_di+1)

def score(l):
    lastd = [0]*26
    point = 0
    for j,k in enumerate(l):
        kk = k-1
        point += s[j][kk]
        lastd[kk] = j+1
        for l in range(26):
            point -= c[l]*(j+1-lastd[l])
    return point

ma = score(ans)

def random_search():
    global ans,ma
    li = deepcopy(ans)
    D = random.choices(ddd,k=1,weights=dd)[0]
    Q = random.choices(qqq,k=1,weights=qq)[0]
    li[D] = Q+1
    if score(li) > ma:
        ans = deepcopy(li)
        ma = score(li)

for i in range(30000):
    random_search()

for i in ans:
    print(i)

### FIXED CODE ###

import random

d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(365)]

for i in range(d):
    print(random.randrange(1, 27, 1))
### BUGGY CODE ###


# M: 鍵の数
# N: 宝箱の数(制限値になる)
# openable: 開けられる宝箱のリスト
# price: 鍵の価格

def power(n):
    if n == 0:
        return [[]]
    else:
        l = []
        for i in power(n-1):
            k = i + [n]
            l.append(k)
        return power(n-1) + l

def abc142e(M, N, price, openable):
    # dp initialize
    inf = float("inf")
    dp = [[inf for j in range((2**N)+1)] for i in range(M+10)]
    for i in range(M+10):
        dp[i][0] = 0
    closed_boxes = power(N)
    # dp
    for i in range(M):
        if openable[i] not in closed_boxes:
            dp[i][j] = inf
        else:
            for j in range(len(closed_boxes)):
                l = list(set(closed_boxes[j])-set(openable[i]))
                l.sort()
                dp[i+1][j] = min(dp[i][closed_boxes.index(l)]+price[i], dp[i][j])
    if dp[M][2**N-1] == inf: return -1
    else: return dp[M][2**N-1]

if __name__ == "__main__":
    N,M = map(int, input().split())
    price = []
    openable = []
    for i in range(M):
        a,b = map(int, input().split())
        c = [i for i in map(int, input().split())]
        price.append(a)
        openable.append(c)

    print(abc142e(M, N, price, openable))



### FIXED CODE ###

def main():
    N,M = map(int, input().split())
    inf = 10**9
    p = 2**N
    dp = [inf] * p
    dp[0] = 0
    
    for i in range(M):
        a,b = map(int, input().split())
        c = sum([2**(int(j)-1) for j in list(input().split())])
        for k in range(p):
            if dp[k|c] > dp[k] + a:
                dp[k|c] = dp[k] + a
    if dp[-1] == inf:
        print(-1)
    else:
        print(dp[-1])

if __name__ == "__main__":
    main()
### BUGGY CODE ###

X = int(input())

root = int(X**(1/5))

A_cands = [root-1, root, root+1]
B_cands = []
for c in A_cands:
    if c**5 < X:
        rest = X - c**5
        another = -int(rest**(1/5))
        B_cands.append(another)
    else:
        rest = c**5 - X
        another = int(rest**(1/5))
        B_cands.append(another)

tmp = 1

for i in range(3):
    if A_cands[i]**5 - B_cands[i]**5 == X:
        print(A_cands[i], B_cands[i])
        import sys
        sys.exit()


while (A_cands[0]**5 - B_cands[0]**5 != X) and (A_cands[1]**5 - B_cands[1]**5 != X) and (A_cands[2]**5 - B_cands[2]**5 != X):
    for i,b_cand in enumerate(B_cands):
        another_plus = b_cand + 1
        another_minus = b_cand - 1
        if A_cands[i]**5 - another_plus**5 == X:
            B_cands[i] = another_plus
            ans_idx = i
            break
        if A_cands[i]**5 - another_minus**5 == X:
            B_cands[i] = another_minus
            ans_idx = i
            break
    tmp += 1

print(A_cands[ans_idx], B_cands[ans_idx])


### FIXED CODE ###

X = int(input())

import sys

for a in range(-118, 120):
    for b in range(-119, 119):
        if a**5 - b**5 == X:
            print(a, b)
            sys.exit()
### BUGGY CODE ###

import math
from functools import reduce
from itertools import product
import numpy

def gcd(*numbers):
    return reduce(math.gcd, numbers)

n = int(input())

l = product(range(1, 1+n), repeat=3)

print(numpy.cumsum([gcd(*i) for i in l])[-1])

### FIXED CODE ###

import math
from functools import reduce
from itertools import product

def gcd(*numbers):
    return reduce(math.gcd, numbers)

n = int(input())

l = product(range(1, 1+n), repeat=3)

print(sum([gcd(*i) for i in l]))
### BUGGY CODE ###

n = int(input())
s = str(input())
r = []
g = []
b = []
for i in range(n):
    if s[i] == "R":
        r.append(i+1)
    if s[i] == "G":
        g.append(i+1)
    if s[i] == "B":
        b.append(i+1)
ans = len(r)*len(g)*len(b)
for i in range(len(r)):
    for j in range(len(g)):
        if max(r[i],g[j])+(abs(r[i]-g[j])) in b:
            ans -= 1
        if min(r[i],g[j])-(abs(r[i]-g[j])) in b:
            ans -= 1
        if abs(r[i]-g[j])%2 == 0 and (r[i]+g[j])//2 in b:
            ans -= 1
print(ans)

### FIXED CODE ###

n = int(input())
s = str(input())
r = []
g = []
def right(r,g):
    return (max(r,g)+(abs(r-g)))
def left(r,g):
    return (min(r,g)-(abs(r-g)))
def half(r,g):
    return ((r+g)//2)
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
ans = len(r)*len(g)*(n-(len(r)+len(g)))
for i in range(len(r)):
    for j in range(len(g)):
        t = left(r[i],g[j])
        f = right(r[i],g[j])
        h = half(r[i],g[j])
        if f < n:
            if s[f] == "B":
                ans -= 1
        if 0 <= t:
            if s[t] == "B":
                ans -= 1
        if abs(r[i]-g[j])%2 == 0:
            if s[h] == "B":
                ans -= 1
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from collections import deque
from itertools import combinations

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

adj = [[0]*(N) for _ in range(N)]

for _ in range(M):
    inp = tuple(map(int, input().split()))
    adj[inp[0]][inp[1]] = 1
    adj[inp[1]][inp[0]] = 1

Q = int(input())

for _ in range(Q):
    found = "no"
    start, target = tuple(map(int, input().split()))
    que = deque([start])
    searched = set([start])
    while len(que):
        q = que.pop()
        next_ = [i for i, a in enumerate(adj[q]) if (a==1) and not (i in searched)]
        searched.update(next_)
        que.extendleft(next_)
        if target in next_:
            found = "yes"
            break
    for a, b in combinations(searched, 2):
        adj[a][b] = 1
        adj[b][a] = 1
    print(found)

### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import deque

N, M = tuple(map(int, input().split()))
adj = [[] for n in range(N)]

for _ in range(M):
    inp = tuple(map(int, input().split()))
    adj[inp[0]].append(inp[1])
    adj[inp[1]].append(inp[0])

unsearched = set(range(N))
colors = {n:-1 for n in range(N)}
color = -1

for n in range(N):
    if colors[n] != -1:
        continue
    color += 1
    start = n
    
    que = deque([start])
    while len(que):
        q = que.pop()
        next_ = [i for i in adj[q] if colors[i] == -1]
        que.extendleft(next_)
        colors[q] = color
    
Q = int(input())

for i in range(Q):
    question = tuple(map(int, input().split()))
    if colors[question[0]] == colors[question[1]]:
        print("yes")        
    else:
        print("no")