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

#!/usr/bin/env python3

def main():
    A, B, C = map(int, open(0).read().split())

    m = A*B*C
    for i in range(1, (A + 1)//2):
        tmp = abs(2*A*C*i -A*B*C)
        if tmp < m:
            m = tmp

    for i in range(1, (B + 1)//2):
        tmp = abs(2*A*B*i -A*B*C)
        if tmp < m:
            m = tmp
    
    for i in range(1, (C + 1)//2):
        tmp = abs(2*B*C*i -A*B*C)
        if tmp < m:
            m = tmp
    
    print(m)



main()

### FIXED CODE ###

#!/usr/bin/env python3

def main():
    A, B, C = map(int, open(0).read().split())

    m = A*B*C
    ans = min(abs(2*A*C*(B//2) - m), abs(2*C*B*(A//2) - m), abs(2*B*A*(C//2) - m))

    print(ans)


main()
### BUGGY CODE ###

def modpow(x,p,mod):
    ret=1
    for i in range(100):
        if (1<<i)&p:
            ret=ret*x%mod
        x=x*x%mod
    return ret

def inverse_table(n,mod):
    table=[]
    for i in range(0,n+1):
        table.append(modpow(i,mod-2,mod))
    return table

def factorial_table(n,mod):
    table=[1]
    for i in range(1,n+1):
        table.append(table[-1]*i%mod)
    return table


it=inverse_table(10**5,1000000007)
ft=factorial_table(10**5,1000000007)

memo={}
def c(n,k,it,ft,mod):
    return ft[n]*it[ft[k]]*it[ft[(n-k)]]%mod

n,k=map(int,input().split())
a=sorted(map(int,input().split()))
hoge=[]
while True:
    hoge.append(c(n-1,k-1,it,ft,1000000007))
    if n-1==k-1:
        break
    n-=1
ans=0
for i in range(len(hoge)):
    ans-=hoge[i]*a[i]%1000000007
    ans+=hoge[i]*a[-i-1]%1000000007
    ans%=1000000007
print(ans)



### FIXED CODE ###

def modpow(x,p,mod):
    ret=1
    for i in range(64):
        if (1<<i)&p:
            ret=ret*x%mod
        x=x*x%mod
    return ret

def inverse_table(n,mod):
    table=[]
    for i in range(0,n+1):
        table.append(modpow(i,mod-2,mod))
    return table

def factorial_table(n,mod):
    table=[1]
    for i in range(1,n+1):
        table.append(table[-1]*i%mod)
    return table

def inverse_factorial_table(n,it,mod):
    table=[1]
    for i in range(1,n+1):
        table.append(table[-1]*it[i]%mod)
    return table

it=inverse_table(10**5,1000000007)
ft=factorial_table(10**5,1000000007)
ift=inverse_factorial_table(10**5,it,1000000007)
def c(n,k,it,ft,mod):
    return ft[n]*ift[k]*ift[(n-k)]%mod
n,k=map(int,input().split())
a=sorted(map(int,input().split()))
hoge=[]
while True:
    hoge.append(c(n-1,k-1,it,ft,1000000007))
    if n-1==k-1:
        break
    n-=1
ans=0
for i in range(len(hoge)):
    ans-=hoge[i]*a[i]%1000000007
    ans+=hoge[i]*a[-i-1]%1000000007
    ans%=1000000007
print(ans)
### BUGGY CODE ###

import bisect

A, B, Q = map(int, input().split())
s = []
for i in range(A):
    s.append(int(input()))
t = []
for i in range(B):
    t.append(int(input()))
x = []
for i in range(Q):
    x.append(int(input()))

for i in range(Q):
    sx, tx, sy, ty = [], [], [], []
    for j in s:
        sx.append(abs(j - x[i]))
    for j in t:
        tx.append(abs(j - x[i]))
    sxi = sx.index(min(sx))
    txi = tx.index(min(tx))
    for j in t:
        ty.append(abs(j - s[sxi]))
    for j in s:
        sy.append(abs(j - t[txi]))
    a = min(sx) + min(ty)
    b = min(tx) + min(sy)
    if a < b:
        print(str(a))
    else:
        print(str(b))


### FIXED CODE ###

import bisect

A, B, Q = map(int, input().split())
INF = 10**18
S = [-INF]
for i in range(A):
    S.append(int(input()))
S.append(INF)
T = [-INF]
for i in range(B):
    T.append(int(input()))
T.append(INF)
X = []
for i in range(Q):
    X.append(int(input()))

for x in X:
    a, b = bisect.bisect_right(S, x), bisect.bisect_right(T, x)
    print(min(abs(s-t) + min(abs(s-x), abs(t-x))
              for s in S[a-1:a+1] for t in T[b-1:b+1]))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

YES = "POSSIBLE"  # type: str
NO = "IMPOSSIBLE"  # type: str


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    import numpy as np
    from scipy.sparse import csr_matrix
    from scipy.sparse.csgraph import dijkstra
    mat = dijkstra(csr_matrix((np.ones(M), (a, b)), shape=(N+1, N+1), dtype=np.int32), indices=1, directed=False)
    return YES if mat[N] <= 2 else NO

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    print(solve(N, M, a, b))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


### FIXED CODE ###

#!/usr/bin/env python3
# cython: profile=True
import sys

YES = "POSSIBLE"  # type: str
NO = "IMPOSSIBLE"  # type: str


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    AB = sorted(zip(a, b))
    s = set([b for a, b in AB if a == 1])
    g = set([a for a, b in AB if b == N])
    return YES if s & g else NO

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    print(solve(N, M, a, b))

def test():
    import doctest
    doctest.testmod()

def perf():
    import cProfile
    cProfile.run("main()")

if __name__ == '__main__':
    #test()
    #perf()
    main()
### BUGGY CODE ###

from collections import deque

s = deque(input())
q = int(input())
rev = 0 # revが0のとき先頭、1のとき後尾

for _ in range(q):
    t = input().split()

    if len(t) == 1:
        rev ^= 1
    else:
        if rev == 1:
            if t[1] == '1':
                s.append(t[2])
            else:
                s.appendleft(t[2])
        else:
            if t[1] == '1':
                s.appendleft(t[2])
            else:
                s.append(t[2])

if rev == 1:
    s.reverse()

for i in range(len(s)):
    print(s[i],end='')

print()


### FIXED CODE ###

s = input()
q = int(input())

rev = 0
front = ""
back = ""
all_rev = 0

for i in range(q):
    t = input().split()

    # T_1 = 1の時
    if len(t) == 1:
        rev += 1
        all_rev += 1

    # T_1 = 2の時
    else:
        if rev%2 == 1:
            if t[1] == '1':
                back = back + t[2]
            else:
                front = t[2] + front
        else:
            if t[1] == '1':
                front = t[2] + front
            else:
                back = back + t[2]

# 反転するとき
if all_rev%2 == 1:
    s = s[::-1]
    front,back = back[::-1],front[::-1]

print(front + s + back)
### BUGGY CODE ###

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

count = 0
for k in range(2, n):
    for j in range(1, k):
        for i in range(j):
            if k - j != j - i \
                and s[i] != s[j] \
                and s[j] != s[k] \
                and s[k] != s[i]:
                count += 1

print(count)

### FIXED CODE ###

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

r_list = []
g_list = []
for _ in range(n):
    if s[_] == "R":
        r_list.append(_)
    elif s[_] == "G":
        g_list.append(_)

count = 0
for r in r_list:
    for g in g_list:
        if min(r, g) - abs(r - g) > 0:
            if s[min(r, g) - abs(r - g)] == "B":
                count += 1
        if max(r, g) + abs(r - g) < n:
            if s[max(r, g) + abs(r - g)] == "B":
                count += 1
        if (r + g) % 2 == 0:
            if s[(r + g) // 2] == "B":
                count += 1


print(len(r_list) * len(g_list) * (n - len(r_list) - len(g_list)) - count)
### BUGGY CODE ###

n = int(input())
cs = [[0] * (n + 1) for _ in range(n + 1)]
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    cs[a][b] = cs[b][a] = c
    es[a].append(b)
    es[b].append(a)
ds = [0] * (n + 1)


def dfs(cur, prev):
    ds[cur] = ds[prev] + cs[prev][cur]
    for e in es[cur]:
        if e != prev:
            dfs(e, cur)


q, k = map(int, input().split())
dfs(k, k)

for _ in range(q):
    x, y = map(int, input().split())
    print(ds[x] + ds[y])

### FIXED CODE ###

import sys

sys.setrecursionlimit(10**6)

input = sys.stdin.readline

n = int(input())
ls = [list(map(int, input().split())) for _ in range(n - 1)]

es = [[] for _ in range(n + 1)]
for a, b, c in ls:
    es[a].append((b, c))
    es[b].append((a, c))
ds = [0] * (n + 1)


def dfs(cur, prev, c):
    ds[cur] = ds[prev] + c
    for e, c in es[cur]:
        if e != prev:
            dfs(e, cur, c)


q, k = map(int, input().split())
qs = [list(map(int, input().split())) for _ in range(q)]

dfs(k, k, 0)
for x, y in qs:
    print(ds[x] + ds[y])
### BUGGY CODE ###

import numpy as np

H, W = map(int,input().split())
S = [list(str(input())) for _ in range(H)]
S = np.array(S)
S = (S == '.') * 1

R = np.array([[0 for _ in range(W)] for __ in  range(H)])
L = np.array([[0 for _ in range(W)] for __ in  range(H)])
U = np.array([[0 for _ in range(W)] for __ in  range(H)])
D = np.array([[0 for _ in range(W)] for __ in  range(H)])

for i in range(W):
    if i == 0:
        L[:, 0] = S[:, 0]
        R[:, W - 1] = S[:, W - 1]
    else:
        L[:, i] = L[:, i - 1] * S[:, i] + S[:, i]
        R[:, W - i - 1] = R[:, W - i] * S[:, W - i - 1] + S[:, W - i - 1]
for i in range(H):
    if i == 0:
        U[i] = S[i]
        D[H - 1] = S[H - 1]
    else:
        U[i] = U[i - 1] * S[i] + S[i]
        D[H - i - 1] = D[H - i] * S[H - i - 1] + S[H - i - 1]

print(np.max(R + L + U + D) - 3)

### FIXED CODE ###

import numpy as np

H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
S = np.array(S)
S = (S == '.') * 1

R = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)

for i in range(W):
    if i == 0:
        L[:, 0] = S[:, 0]
        R[:, W - 1] = S[:, W - 1]
    else:
        L[:, i] = L[:, i - 1] * S[:, i] + S[:, i]
        R[:, W - i - 1] = R[:, W - i] * S[:, W - i - 1] + S[:, W - i - 1]
for i in range(H):
    if i == 0:
        U[i] = S[i]
        D[H - 1] = S[H - 1]
    else:
        U[i] = U[i - 1] * S[i] + S[i]
        D[H - i - 1] = D[H - i] * S[H - i - 1] + S[H - i - 1]

print(np.max(R + L + U + D) - 3)
### BUGGY CODE ###

N = int(input())
L_list = list(map(int,input().split()))
L_list = sorted(L_list,reverse=True)
#print(L_list)
result =0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L_list[i] < L_list[j] + L_list[k] and \
                    L_list[j] < L_list[k] + L_list[i] and \
                    L_list[k] < L_list[i] + L_list[j]:
                #print(i,j,k)
                result += 1
            elif L_list[i] >= L_list[j] + L_list[k] or \
                    L_list[j] >= L_list[k] + L_list[i]:
                    break
print(result)

### FIXED CODE ###

import bisect
N = int(input())
L_list =  sorted(list(map(int,input().split())))
#print(L_list)
result =0

for i in range(N):
    for j in range(i+1,N):
        a = L_list[i] + L_list[j]
        idx = bisect.bisect_left(L_list,a)
        result += max(0,idx-j-1)
print(result)
### BUGGY CODE ###

import numpy as np
import sys
N = int(input())
D = list(map(int, input().split()))

argminD = 0#np.argmin(D)
for i in range(0, D[argminD]*2+1, 2):
  first = int(i)
  final = D[argminD]*2 - int(i)
  for j in range(argminD+1, N+argminD):
    j = j % N
    final = D[j]*2-final
    if final < 0:
      break
  if first == final:
    result = [str(first)]
    final = D[argminD]*2 - first
    for j in range(argminD+1, N+argminD):
      j = j % N
      result.append(str(final))
      final = D[j]*2-final
    print(" ".join(result))
    sys.exit(0)
  

### FIXED CODE ###

import numpy as np
import sys
N = int(input())
D = np.asarray(list(map(int, input().split())))

first = np.sum(D) - np.sum(D[1::2])*2
result = [str(first)]
final = D[0]*2 - first
for j in range(1, N):
  result.append(str(final))
  final = D[j]*2-final
print(" ".join(result))
### BUGGY CODE ###

A,B,C,D = map(int,input().split())

res = 0

for i in range(A,B+1):
    if (i%C != 0) and (i%D != 0):
        res += 1

print(res)

### FIXED CODE ###

A,B,C,D = map(int,input().split())

def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

def num(N,c,d):
    lcm = (c*d)//gcd(c,d)
    return N - (N//c) - (N//d) +  N//lcm

print(num(B,C,D)-num(A-1,C,D))
### BUGGY CODE ###

import sys
readline = sys.stdin.buffer.readline

n = int(readline())
a = list(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))

for b, c in L:
  for i, v in enumerate(tuple(a)):
    if v == b:
      a[i] = c
  print(sum(a))


### FIXED CODE ###

import sys
from collections import Counter
readline = sys.stdin.buffer.readline
 
n = int(readline())
a = Counter(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))
 
s = sum(x * y for x, y in a.items())
for b, c in L:
  # print(a)
  if b in a:
    s += (c - b) * a[b]
    a[c] += a[b]
    del a[b]
  print(s)
### BUGGY CODE ###

number=int(input())
List=list(map(int,input().split()))
for i in range(1,number+1):
    print(List.count(i))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
count=[0]*n
for i in a:
    count[i-1]+=1
for j in count:
    print(j)
### BUGGY CODE ###

def mergeSort(A, left, right, n):
    if left + 1 < right:
        mid = int((right + left ) / 2 )
        mergeSort(A, left, mid, n)
        mergeSort(A, mid, right, n)
        return (merge(A, left, mid, right, n))

def merge(A, left, mid, right, n):
    n1 = mid - left
    n2 = right - mid
    L = []
    R = []
    for i in range(n1):
        L.append(A[left + i])
    for i in range(n2):
        R.append(A[mid + i])
    L.append(1000000001)
    R.append(1000000001)
    i = j = 0
    for k in range(left, right):
        A[n] += 1
        if L[i] <= R[j]:
            key = L[i]
            A[k] = key
            i += 1
        else:
            key = R[j]
            A[k] = key
            j += 1
    return A

n = int(input())
A = list(map(int, input().split()))
A.append(0)
S = mergeSort(A, 0, len(A) - 1, n)
for i in range(n - 1):
    print(S[i], end = ' ')
print(S[n - 1])
print(S[n])


### FIXED CODE ###

def mergeSort(A, left, right, n):
    if left + 1 < right:
        mid = int((right + left ) / 2 )
        mergeSort(A, left, mid, n)
        mergeSort(A, mid, right, n)
        return (merge(A, left, mid, right, n))

def merge(A, left, mid, right, n):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]  + [10 ** 9 + 1]
    R = A[mid:right] + [10 ** 9 + 1]
    i , j = 0, 0
    for k in range(left, right):
        A[n] += 1
        if L[i] <= R[j]:
            key = L[i]
            A[k] = key
            i += 1
        else:
            key = R[j]
            A[k] = key
            j += 1
    return A

n = int(input())
A = list(map(int, input().split()))
A.append(0)
S = mergeSort(A, 0, len(A) - 1, n)
print(" ".join(list(map(str, S[:n]))))
print(S[n])
### BUGGY CODE ###

import math
import bisect

def ceil_number(n):
    return math.floor(n)

N,M = map(int,input().split())
Price_List = sorted(list(map(int,input().split())))
for i in range(M):
    New_Price =  Price_List[-1]/2
    Price_List.pop(-1)
    Price_List.insert(bisect.bisect(Price_List,New_Price),New_Price)
print(sum(map(ceil_number,Price_List)))

### FIXED CODE ###

import bisect
 
N,M = map(int,input().split())
Price_List = list(map(int,input().split()))
Price_List.sort()
for i in range(M):
    New_Price = Price_List.pop(-1)//2
    Price_List.insert(bisect.bisect(Price_List,New_Price),New_Price)
print(sum(Price_List))
### BUGGY CODE ###

import fractions 

N = int(input())
A = list(map(int, input().split()))
MODE = 10**9+7

def lcm(a, b):
    return a*b//fractions.gcd(a,b)

_lcm = 1
for a in A:
    _lcm = lcm(a, _lcm)

ret = 0
for a in A:
    ret += (_lcm // a)
    ret %= MODE

print(ret)


### FIXED CODE ###

import fractions 

N = int(input())
A = list(map(int, input().split()))
MODE = 10**9+7

def lcm(a, b):
    return a*b//fractions.gcd(a,b)

_lcm = 1
for a in A:
    _lcm = lcm(a, _lcm)

ret = 0
for a in A:
    ret += (_lcm // a)

print(ret%MODE)
### BUGGY CODE ###

b, c = map(int, input().split())
a=0
for x in range(b,c+1):
    a=x^a
print(a)

### FIXED CODE ###

def xor(a,b):
    c=a-b+1
    flg1= a%2!=0
    flg2= b%2!=0
    flg3= int((c/2))%2!=0
    if a==b:
        return 1

    if not flg1 and flg2:
        if not flg3:
            return 0
        else:
            return 1
    elif not flg1 and not flg2:
        if not flg3:
            return b
        else:
            return 1^b
    elif flg1 and flg2:
        if not flg3:
            return a
        else:
            return a^1

    elif flg1 and not flg2:
        if not flg3:
            return b
        else:
            return 1^b




a,b = map(int, input().split())
print(xor(0,a-1)^xor(0,b))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, K: int, p: "List[int]"):
    max_value = 0
    for i in range(N - K + 1):
        compare_value = sum(p[i : i + K])

        if max_value < compare_value:
            max_value = max(max_value, compare_value)
            index_first = i
        else:
            pass
    # print(max_value)
    # print(index_first)
    result = 0
    for j in range(K):
        idm = (p[index_first + j] / 2) * (1 + p[index_first + j])
        idm /= p[index_first + j]
        result += idm
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, K: int, p: "List[int]"):
    cumsum = np.cumsum(p)
    # print(cumsum)
    max_value = 0
    index_first = 0
    for i in range(N - K):
        if max_value < cumsum[i + K] - cumsum[i]:
            max_value = max(max_value, cumsum[i + K] - cumsum[i])
            index_first = i + 1

    # print(max_value)
    # print(index_first)
    result = 0
    for j in range(K):
        idm = (p[index_first + j] / 2) * (1 + p[index_first + j])
        idm = idm / p[index_first + j]
        result += idm

    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)


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


mod = 10 ** 9 + 7
S = input()[::-1]
W = [1, 10, 9, 12, 3, 4]

dp = [[0] * 13 for _ in range(len(S))]

for i, s in enumerate(S):
    if i == 0:
        if s == "?":
            for j in range(10):
                dp[0][j] = 1
        else:
            dp[0][int(s)] = 1
        continue

    if s == "?":
        for n in range(10):
            r = (n * W[i % 6]) % 13
            for j in range(13):
                dp[i][(j + r) % 13] = (dp[i][(j + r) % 13] + dp[i - 1][j]) % mod

    else:
        n = int(s)
        r = (n * W[i % 6]) % 13
        for j in range(13):
            dp[i][(j + r) % 13] = (dp[i][(j + r) % 13] + dp[i - 1][j]) % mod

print(dp[len(S) - 1][5])


### FIXED CODE ###


mod = 10 ** 9 + 7
S = input()[::-1]
W = [1, 10, 9, 12, 3, 4]

dp = [[0] * 13 for _ in range(len(S))]

for i, s in enumerate(S):
    if i == 0:
        if s == "?":
            for j in range(10):
                dp[0][j] = 1
        else:
            dp[0][int(s)] = 1
        continue

    w = W[i % 6]
    if s == "?":
        for n in range(10):
            r = (n * w) % 13
            for j in range(13):
                dp[i][(j + r) % 13] = (dp[i][(j + r) % 13] + dp[i - 1][j]) % mod

    else:
        n = int(s)
        r = (n * w) % 13
        for j in range(13):
            dp[i][(j + r) % 13] = (dp[i][(j + r) % 13] + dp[i - 1][j]) % mod

print(dp[len(S) - 1][5])
### BUGGY CODE ###

# B
import numpy as np
from collections import deque
# input
N, M = map(int, input().split())
G = dict()
for n in range(1, N+1):
    G[n] = []

for _ in range(M):
    A, B = map(int, input().split())
    G[A].append(B)
    G[B].append(A)
    
# find minimum degree
s = np.argmin(np.array([len(G[k]) for k in range(1, N+1)])) + 1

targets = dict()
for a in G[s]:
    targets[a] = 1


# BFS from st
t = G[s][0]
pt = [s, t]
del targets[t]
while len(targets) > 0:
    ques = deque()
    visited = [0]*(N+1)    
    for a in pt:
        visited[a] = 1
    ques.append([t, pt])
    end = 0
    while len(ques) > 0 and end == 0:
        q = ques.popleft()
        s = q[0]
        pt = q[1]
        for t in G[s]:
            if visited[t] == 1:
                pass
            elif t in targets.keys():
                pt.append(t)
                end = 1
                del targets[t]
                break
            else:
                visited[t] = 1
                ques.append([t, pt+[t]])
            

# BFS from end
visited = [0]*(N+1)
for a in pt:
    visited[a] = 1
sv = np.array([len([l for l in G[k] if visited[l] == 0]) if visited[k] == 0 else N for k in range(1, N+1)])

# need calculation
if len([l for l in G[t] if visited[l] == 0]) != 0:
    endp = np.random.choice([k for k in range(N) if sv[k] == min(sv)]) + 1
    targets = dict()
    for a in G[endp]:
        if visited[a] == 0:
            targets[a] = 1
    while len(targets) > 0:
        ques = deque()
        visited = [0]*(N+1)    
        for a in pt:
            visited[a] = 1
        visited[endp] = 1
        ques.append([t, pt])
        end = 0
        while len(ques) > 0 and end == 0:
            q = ques.popleft()
            s = q[0]
            pt = q[1]
            for t in G[s]:
                if visited[t] == 1:
                    pass
                elif t in targets.keys():
                    pt.append(t)
                    end = 1
                    del targets[t]
                    break
                else:
                    visited[t] = 1
                    ques.append([t, pt+[t]])
    pt.append(endp)
        
print(len(pt))
print(" ".join([str(a) for a in pt]))

### FIXED CODE ###

# B
import numpy as np
from collections import deque
# input
N, M = map(int, input().split())
G = dict()
for n in range(1, N+1):
    G[n] = []
    
visited = [0]*(N+1)
for m in range(M):
    A, B = map(int, input().split())
    G[A].append(B)
    G[B].append(A)
    if m == 0:
        pt = [A, B]
        visited[A] = 1
        visited[B] = 1

# from left
s = pt[0]
add_left = list()

while True:
    left_ext = [l for l in G[s] if visited[l] == 0]
    if len(left_ext) != 0:
        s = left_ext[0]
        visited[s] = 1
        add_left.append(s)
    else:
        break

# from right
s = pt[1]
add_right = list()

while True:
    right_ext = [l for l in G[s] if visited[l] == 0]
    if len(right_ext) != 0:
        s = right_ext[0]
        visited[s] = 1
        add_right.append(s)
    else:
        break
pt = list(reversed(add_left)) + pt + add_right
print(len(pt))
print(" ".join([str(a) for a in pt]))