Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03059 (python)

Fixed submission:
A,B,T = map(int, input().split())
ans = round((T+0.5)//A)*B
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
def mygcd(N,A,S):
    if S == 'R':
        A.reverse()
    ans = [0, A[0]]
    for i in range(1, N):
        ans.append(fractions.gcd(ans[i],A[i]))
    if S == 'R':
        ans.reverse()
    return ans

def GCDonBlack(N,A):
    L = mygcd(N,A,'L')
    R = mygcd(N,A,'R')
    M = [fractions.gcd(L[i], R[i+1])  for i  in range(0,N)]
    return max(M)

N = int(input())
A = list(map(int, input().split()))
print(GCDonBlack(N,A))
Problem p03061 (python)

Fixed submission:
import fractions
def mygcd(N,A,S):
    if S == 'R':
        A.reverse()
    ans = [0, A[0]]
    for i in range(1, N):
        ans.append(fractions.gcd(ans[i],A[i]))
    if S == 'R':
        ans.reverse()
    return ans

def GCDonBlack(N,A):
    L = mygcd(N,A,'L')
    R = mygcd(N,A,'R')
    M = [fractions.gcd(L[i], R[i+1])  for i  in range(0,N)]
    return max(M)

N = int(input())
A = list(map(int, input().split()))
print(GCDonBlack(N,A))

Buggy submission (verdict: Runtime Error):
def mygcd(N,A,S):
    if S == 'R':
        A.reverse()
    ans = [0, A[0]]
    for i in range(1, N):
        ans.append(math.gcd(ans[i],A[i]))
    if S == 'R':
        ans.reverse()
    return ans

def GCDonBlack(N,A):
    L = mygcd(N,A,'L')
    R = mygcd(N,A,'R')
    M = [math.gcd(L[i], R[i+1])  for i  in range(0,N)]
    return max(M)

N = int(input())
A = list(map(int, input().split()))
print(GCDonBlack(N,A))

Buggy submission (verdict: Runtime Error):
def GCDonBlack(N,A):
    #count = 0
    rem=[a%min(A) for a in A]
    if sum(rem) == 0:
        return min(A)
    else:
        for i in reversed(range(1,max(rem)+1)):
            count += 1
            bar = N-1
            for ele in A:
                if ele % i == 0:
                    bar -= 1
                if bar == 0:
                    #print("count:{}".format(count))
                    return i
N = int(input())
A = list(map(int, input().split()))
print(GCDonBlack(N,A))
Problem p03081 (python)

Fixed submission:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, q = LI()
    S = SI()

    Q = [LS() for _ in range(q)]

    def left_out(i):
        if i < 0: return True
        if i >= n: return False
        for t, d in Q:
            if t != S[i]: continue
            if d == 'L':
                i -= 1
                if i < 0: return True
            else:
                i += 1
                if i >= n: return False

        return False

    def right_out(i):
        if i < 0: return False
        if i >= n: return True
        for t, d in Q:
            if t != S[i]: continue
            if d == 'L':
                i -= 1
                if i < 0: return False
            else:
                i += 1
                if i >= n: return True

        return False

    # 左へ落ちるロボット
    l_ok, l_ng = -1, n
    while abs(l_ok - l_ng) > 1:
        mid = (l_ok + l_ng) // 2
        if left_out(mid):
            l_ok = mid
        else:
            l_ng = mid

    # 右へ落ちるロボット
    r_ok, r_ng = n, -1
    while abs(r_ok - r_ng) > 1:
        mid = (r_ok + r_ng) // 2
        if right_out(mid):
            r_ok = mid
        else:
            r_ng = mid

    return max(0, r_ok - l_ok - 1)


print(main())

Buggy submission (verdict: Runtime Error):
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, q = LI()
    S = SI()

    B = [LS() for _ in range(q)]
    l, r = 0, n - 1
    ls, rs = '@', '@'
    cl, cr = 0, 0
    for t, d in B[::-1]:
        if d == 'L':
            if t == S[l]:
                cl = l + 1
                l += 1
                ls = t
            if rs == t:
                cr -= 1

        else:
            if t == S[r]:
                cr = n - r
                r -= 1
                rs = t
            if ls == t:
                cl -= 1

    return max(0, n - cl - cr)


print(main())
Problem p03165 (python)

Fixed submission:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


s = [ord(n) for n in S()]
t = [ord(n) for n in S()]

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i][j + 1])
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

# 最長共通部分列の長さ
# print(dp[-1][-1])

ans = ''
i = len(s)
for j in range(len(t) + 1)[::-1]:
    if dp[i][j] != dp[i][j - 1]:
        if i == 0 or j == 0: break
        while dp[i][j] == dp[i - 1][j]:
            i -= 1
        ans += chr(t[j - 1])
        i -= 1

print(ans[::-1])

Buggy submission (verdict: Runtime Error):
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


s = [ord(n) for n in S()]
t = [ord(n) for n in S()]

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i][j + 1])
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

# 最長共通部分列の長さ
# print(dp[-1][-1])

ans = ''
i = len(s)
for j in range(len(t) + 1)[::-1]:
    if dp[i][j] != dp[i][j - 1]:
        while dp[i][j] == dp[i - 1][j]:
            i -= 1
        ans += chr(t[j - 1])
        i -= 1

print(ans[::-1])
Problem p03195 (python)

Fixed submission:
# coding:utf-8

import sys
from collections import Counter


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()

D = []
for i in range(1, N):
    D.append(A[i] - A[i - 1])

if A[-1] % 2 == 1:
    print('first')
else:
    cnt_e, cnt_o = 0, 0
    for i in range(N - 1):
        if A[i] % 2 == 0:
            cnt_e += 1
        else:
            cnt_o += 1

    if cnt_o > 0:
        print('first')
    else:
        print('second')

Buggy submission (verdict: Runtime Error):
n=input()
p=1
for i in range(n):
    a=input()
    if a%2:
        p=0
print(['first','second'][p])
Problem p03229 (python)

Fixed submission:
# coding:utf-8

import sys
from collections import Counter, deque

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()
A = [I() for _ in range(N)]

A.sort()
B = deque()

state = 1
for i in range(N // 2):
    if state:
        B.append(A[i])
        B.appendleft(A[-(i + 1)])
    else:
        B.append(A[-(i + 1)])
        B.appendleft(A[i])
    state ^= 1
if N % 2:
    C = deque(B)
    B.append(A[N // 2])
    C.appendleft(A[N // 2])
else:
    C = A[:]

ans1 = 0
ans2 = 0
for i in range(N - 1):
    ans1 += abs(B[i] - B[i + 1])
    ans2 += abs(C[i] - C[i + 1])

print(max(ans1, ans2))

Buggy submission (verdict: Runtime Error):
# coding:utf-8

import sys
from collections import Counter, deque

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()
A = [I() for _ in range(N)]

A.sort()
B = deque()

state = 1
for i in range(N // 2):
    if state:
        B.append(A[i])
        B.appendleft(A[-(i + 1)])
    else:
        B.append(A[-(i + 1)])
        B.appendleft(A[i])
    state ^= 1
if N % 2:
    C = deque(B)
    B.append(A[N // 2])
    C.appendleft(A[N // 2])

ans1 = 0
ans2 = 0
for i in range(N - 1):
    ans1 += abs(B[i] - B[i + 1])
    ans2 += abs(C[i] - C[i + 1])

print(max(ans1, ans2))
Problem p03240 (python)

Fixed submission:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def solve():
    for x in range(101):
        for y in range(101):
            for h in range(h_min, h_min + 201):
                for i in range(N):
                    if D[i][0] != max(h - abs(D[i][1] - x) - abs(D[i][2] - y), 0):
                        break
                else:
                    return x, y, h


if __name__ == '__main__':
    N = int(input())
    D = []
    for i in range(N):
        x, y, h = inpl()
        D.append([h, x, y])

    h_min = max(D)[0]
    ans = solve()
    print(' '.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def solve():
    for cx in range(101):
        for cy in range(101):
            ch = D[0][0] + abs(D[0][1] - cx) + abs(D[0][2] - cy)
            for h, x, y in D:
                if h != max(ch - (abs(x - cx) + abs(y - cy)), 0):
                    break
            else:
                return cx, cy, ch


if __name__ == '__main__':
    N = int(input())
    D = []
    for i in range(N):
        x, y, h = inpl()
        D.append([h, x, y])

    h_min = max(D)[0]
    ans = solve()
    print(' '.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def solve():
    for cx in range(101):
        for cy in range(101):
            ch = D[0][0] + abs(D[0][1] - cx) + abs(D[0][2] - cy)
            for h, x, y in D:
                if h != ch - (abs(x - cx) + abs(y - cy)):
                    break
            else:
                return cx, cy, ch


if __name__ == '__main__':
    N = int(input())
    D = []
    for i in range(N):
        x, y, h = inpl()
        D.append([h, x, y])

    h_min = max(D)[0]
    ans = solve()
    print(' '.join(map(str, ans)))
Problem p03241 (python)

Fixed submission:
# coding:utf-8


def inpl(): return list(map(int, input().split()))


N, M = inpl()

n = M // N
while n > 0:
    if M % n == 0:
        print(n)
        break
    else:
        n -= 1

Buggy submission (verdict: Runtime Error):
# coding:utf-8
def inpl(): return list(map(int, input().split()))
N, M = inpl()
i = 2
tmp = []
MM = M
while i * i <= MM:
    if MM % i == 0:
        tmp.append(i)
        while MM % i == 0:
            MM //= i
    i += 1
if MM != 1:
    tmp.append(MM)
n = M // N
sub = tmp[0]
while n > 0:
    if M % n == 0:
        print(n)
        break
    else:
        n -= sub
Problem p03245 (python)

Fixed submission:
# coding:utf-8

import sys
input = sys.stdin.readline
INF = float('inf')


def inpl(): return list(map(int, input().split()))


def move_uv(x, y):
    ut = x + y
    vt = x - y
    command = ''
    u, v = 0, 0
    for i in range(len(D)):
        if u <= ut and v <= vt:
            command += 'R'
            u += D[i]
            v += D[i]
        elif u <= ut and v > vt:
            command += 'U'
            u += D[i]
            v -= D[i]
        elif u > ut and v <= vt:
            command += 'D'
            u -= D[i]
            v += D[i]
        else:
            command += 'L'
            u -= D[i]
            v -= D[i]

    return command


N = int(input())
point = []
max_length = 0
for i in range(N):
    x, y = inpl()
    max_length = max(max_length, abs(x) + abs(y))
    point.append([x, y])

parity = sum(point[0]) % 2
judge = True
for p in point:
    if parity ^ sum(p) % 2:
        judge = False
        break

if not judge:
    print(-1)
else:
    D = [2 ** i for i in range(len(bin(max_length)) - 1)]
    D.reverse()

    # X + Yが偶数の時は長さ1の腕を足す
    if parity == 0:
        D.append(1)
    print(len(D))
    print(' '.join(map(str, D)))
    for i in range(N):
        print(move_uv(point[i][0], point[i][1]))

Buggy submission (verdict: Runtime Error):
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def move(x, y):
    command = ''
    if x > 0:
        command += 'R' * x
    else:
        command += 'L' * abs(x)
    if y > 0:
        command += 'U' * y
    else:
        command += 'D' * abs(y)
    command += 'RL' * ((max_length - abs(x) - abs(y)) // 2)
    return command


N = int(input())
point = []
max_length = 0
for i in range(N):
    x, y = inpl()
    max_length = max(max_length, abs(x) + abs(y))
    point.append([x, y])

tmp = sum(point[0]) % 2
judge = True
for p in point:
    if tmp ^ sum(p) % 2:
        judge = False

if judge:
    print(max_length)
    print(' '.join(['1'] * max_length))
    for x, y in point:
        print(move(x, y))
else:
    print(-1)
Problem p03263 (python)

Fixed submission:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)

H, W = inpl()
mass = []
coin = 0
for i in range(H):
    tmp = inpl()
    coin += sum(tmp)
    mass.append(tmp)

odd = []
for h in range(H):
    for w in range(W):
        if mass[h][w] % 2 == 1:
            odd.append([h, w])

count = 0
ans = []
odd.sort()
for i in range(H):
    for j in range(W):
        if mass[i][j] & 1:
            if j < W - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 1, j + 2])
                mass[i][j] -= 1
                mass[i][j + 1] += 1
            elif i < H - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 2, j + 1])
                mass[i][j] -= 1
                mass[i + 1][j] += 1

print(count)
for a in ans:
    print(' '.join(map(str, a)))

Buggy submission (verdict: Runtime Error):
# coding:utf-8


def inpl(): return list(map(int, input().split()))


H, W = inpl()
board = []
for i in range(H):
    board.append(inpl())

ans = []
cnt = 0
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            if board[h][w] % 2 == 1:
                board[h][w] -= 1
                if w + 1 < W:
                    board[h][w + 1] += 1
                    ans.append([h + 1, w + 1, h + 1, w + 2])
                    cnt += 1
                elif h + 1 < H:
                    board[h + 1][w] += 1
                    ans.append([h + 1, w + 1, h + 2, w + 1])
                    cnt += 1

    else:
        for w in range(W)[::-1]:
            if board[h][w] % 2 == 1:
                board[h][w] -= 1
                if 0 < w - 1:
                    board[h][w - 1] += 1
                    ans.append([h + 1, w + 1, h + 1, w])
                    cnt += 1
                elif 0 < h - 1:
                    board[h + 1][w] += 1
                    ans.append([h + 1, w + 1, h + 2, w + 1])
                    cnt += 1

print(cnt)

for a in ans:
    print(' '.join(map(str, a)))

Buggy submission (verdict: Runtime Error):
# coding:utf-8


def inpl(): return list(map(int, input().split()))


H, W = inpl()
board = []
for i in range(H):
    board.append(inpl())

ans = []
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            if board[h][w] % 2 == 1:
                board[h][w] -= 1
                if w + 1 < W:
                    board[h][w + 1] += 1
                    ans.append([h + 1, w + 1, h + 1, w + 2])
                elif h + 1 < H:
                    board[h + 1][w] += 1
                    ans.append([h + 1, w + 1, h + 2, w + 1])
    else:
        for w in range(W)[::-1]:
            if board[h][w] % 2 == 1:
                board[h][w] -= 1
                if 0 < w - 1:
                    board[h][w - 1] += 1
                    ans.append([h + 1, w + 1, h + 1, w])
                elif 0 < h - 1:
                    board[h + 1][w] += 1
                    ans.append([h + 1, w + 1, h + 2, w + 1])

for a in ans:
    print(' '.join(map(str, a)))
Problem p03282 (python)

Fixed submission:
# coding:utf-8

S = input()
K = int(input())

for i in range(K):
    if S[i] != '1':
        print(S[i])
        break
else:
    print('1')

Buggy submission (verdict: Runtime Error):
# coding:utf-8

S = input()
K = int(input())

if K == 1:
    print(S[0])
else:
    S5000 = ''
    for i in range(len(S)):
        s = S[i]
        if s == '1':
            continue
        else:
            digit = i
            tmp = s
            break
    else:
        digit = len(S)

if K <= digit:
    print('1')
else:
    print(tmp)

Buggy submission (verdict: Runtime Error):
# coding:utf-8

S = input()
K = int(input())

if K == 1:
    print(S[0])
else:
    S5000 = ''
    for i in range(len(S)):
        s = S[i]
        if s == '1':
            continue
        else:
            digit = i
            tmp = s
            break

if K <= digit:
    print('1')
else:
    print(tmp)
Problem p03380 (python)

Fixed submission:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

n = max(A)
r = max(A)
tmp = 0
for i in range(N):
    a = A[i]
    if a == n: continue
    if a < n - a: a = n - a
    if tmp <= n - a:
        r = A[i]
        tmp = n - a

print(n, r)

Buggy submission (verdict: Runtime Error):
# coding:utf-8

import sys


input = sys.stdin.readline


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

a = max(A)
tmp = 0
for i in range(N):
    x = A[i]
    if x == a: continue
    x = max(x, a - x)
    if tmp < a - x:
        b = A[i]
        tmp = a - x

print(a, b)
Problem p03407 (python)

Fixed submission:
a, b, c = map(int, input().split())
print('Yes' if a + b >= c else 'No')

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().spilt())
print('Yes' if a + b >= c else 'No')
Problem p03480 (python)

Fixed submission:
s = input()

n = len(s)
ans = n
for i, (c1, c2) in enumerate(zip(s[:-1], s[1:])):
    if c1 == c2:
        continue
    ans = min(ans, max(i + 1, n - i - 1))

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
k = 0
tmp = set()
while len(tmp) < 2:
    tmp.add(s[n // 2 + k])
    tmp.add(s[(n - 1) // 2 - k])
    k += 1
print(n // 2 + k - 1)
Problem p03557 (python)

Fixed submission:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
i_a = 0
i_c = 0
for i_b in range(N):
    while i_a < N and A[i_a] < B[i_b]:
        i_a += 1
    while i_c < N and C[i_c] <= B[i_b]:
        i_c += 1

    ans += i_a * (N - i_c)

print(ans)

Buggy submission (verdict: Runtime Error):
# coding:utf-8

n = input()
top = map(int, raw_input().split())
middle = map(int, raw_input().split())
under = map(int, raw_input().split())
top.sort()
middle.sort()
under.sort()
total = 0
for i in xrange(n):
    high = n - 1
    low = 0
    t = (high+low)/2
    d = middle[i] - 1
    while(low <= high):
        if top[t] == d: break
        if top[t] > d:
            high = t - 1
        else:
            low = t + 1
        t = (high+low)/2
    while(t+1 < len(top)):
        if top[t] != top[t+1]: break
        t += 1
    tt = t + 1 #topの候補数

    high = n -1
    low = 0
    t = (high+low)/2
    d = middle[i] + 1
    while(low <= high):
        if under[t] == d: break
        if under[t] > d:
            high = t - 1
        else:
            low = t + 1
        t = (high+low)/2
    if(under[t] != d): t += 1
    while(t-1 >= 0):
        if under[t] != under[t-1]: break
        t -= 1
    tu = n - t #underの候補数

    total += tt*tu
print total

Buggy submission (verdict: Runtime Error):
# coding:utf-8

n = input()
top = map(int, raw_input().split())
middle = map(int, raw_input().split())
under = map(int, raw_input().split())
top.sort()
middle.sort()
under.sort()
total = 0
for i in xrange(n):
    high = n - 1
    low = 0
    t = (high+low)/2
    d = middle[i] - 1
    while(low <= high):
        if top[t] == d: break
        if top[t] > d:
            high = t - 1
        else:
            low = t + 1
        t = (high+low)/2
    while(t+1 < len(top)):
        if top[t] != top[t+1]: break
        t += 1
    tt = t + 1 #topの候補数

    high = n -1
    low = 0
    t = (high+low)/2
    d = middle[i] + 1
    while(low <= high):
        if under[t] == d: break
        if under[t] > d:
            high = t - 1
        else:
            low = t + 1
        t = (high+low)/2
    if(under[t] != d): t += 1
    while(t-1 >= 0):
        if under[t] != under[t+1]: break
        t -= 1
    tu = n - t #underの候補数

    total += tt*tu
print total
Problem p03746 (python)

Fixed submission:
# coding:utf-8

import sys
from collections import deque, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, m = LI()

    G = defaultdict(list)
    S = defaultdict(set)
    for _ in range(m):
        a, b = LI_()
        G[a].append(b)
        G[b].append(a)
        S[a].add(b)
        S[b].add(a)

    res = deque([0, G[0][0]])
    visited = set(res)
    needs = S[res[0]] | S[res[-1]] - visited
    while needs:
        v = needs.pop()
        if v in visited:
            continue
        visited.add(v)
        if v in S[res[0]]:
            res.appendleft(v)
        else:
            res.append(v)
        needs = (S[res[0]] | S[res[-1]]) - visited

    print(len(res))
    print(*[v + 1 for v in res])


main()

Buggy submission (verdict: Runtime Error):
# coding:utf-8

import sys
from collections import deque, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, m = LI()

    G = defaultdict(list)
    deg = [0] * n
    for _ in range(m):
        a, b = LI_()
        G[a].append(b)
        G[b].append(a)
        deg[a] += 1
        deg[b] += 1

    ss = []
    for i in range(n):
        if deg[i] == 1:
            s = i
            ss = []
            break
        if deg[i] % 2 == 0:
            ss.append(i)

    if not ss:
        print(2)
        print(*[s + 1, G[s][0] + 1])
        exit()

    def DFS(v: int, res: list, visited: set, needs: set) -> None:
        res.append(v + 1)
        visited.add(v)
        needs -= set([v])
        if not needs:
            print(len(res))
            print(*res)
            exit()

        for to in G[v]:
            if to in visited:
                continue
            DFS(to, res, visited, needs)

    for s in ss:
        DFS(G[s][0], [s+1], set([s]), set(G[s][1:]))


main()