For his birthday recently Fedya was given an array $a$ of $n$ integers arranged in a circle, For each pair of neighboring numbers ($a_1$ and $a_2$, $a_2$ and $a_3$, $\ldots$, $a_{n - 1}$ and $a_n$, $a_n$ and $a_1$) the absolute difference between them is equal to $1$.

Let's call a local maximum an element, which is greater than both of its neighboring elements. Also call a local minimum an element, which is less than both of its neighboring elements. Note, that elements $a_1$ and $a_n$ are neighboring elements.

Unfortunately, Fedya lost an array, but he remembered in it the sum of local maximums $x$ and the sum of local minimums $y$.

Given $x$ and $y$, help Fedya find any matching array of minimum length.


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). Description of the test cases follows.

Each line of each test case contain two integers $x$ and $y$ ($-10^{9} \le y < x \le 10^{9}$) — the sum of local maximums and the sum of local minimums, respectively.


-----Output-----

For each test case, in the first line print one integer $n$ — the minimum length of matching arrays.

In the second line print $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^{9} \leqslant a_i \leqslant 10^{9}$) — the array elements such that the the absolute difference between each pair of neighboring is equal to $1$.

If there are multiple solutions, print any of them.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^{5}$.


-----Examples-----

Input
4
3 -2
4 -4
2 -1
5 -3
Output
10
0 1 2 1 0 -1 0 -1 0 1
16
-2 -1 -2 -1 0 1 2 3 4 5 4 3 2 1 0 -1 
6
1 0 -1 0 1 0
16
2 3 2 1 0 -1 0 -1 0 -1 0 1 2 1 0 1


-----Note-----

In the first test case, the local maximums are the numbers at $3, 7$ and $10$ positions, and the local minimums are the numbers at $1, 6$ and $8$ positions. $x = a_3 + a_7 + a_{10} = 2 + 0 + 1 = 3$, $y = a_1 + a_6 + a_8 = 0 + (-1) + (-1) = -2$.

In the second test case, the local maximums are the numbers at $2$ and $10$ positions, and the local minimums are the numbers at $1$ and $3$ positions. $x = a_2 + a_{10} = -1 + 5 = 4$, $y = a_1 + a_3 = -2 + (-2) = -4$.

In the third test case, the local maximums are the numbers at $1$ and $5$ positions, and the local minimums are the numbers at $3$ and $6$ positions.

Difficulty: EASY
Tags: Mathematics

Constructive algorithms

Starter code:

Solutions:
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(str(2 * (a - b)) + '\n' + ' '.join([str(x) for x in range(a, b - 1, -1)] + [str(x) for x in range(b + 1, a)]))


def solve(x, y):
	res = list(range(x, y - 1, -1)) + list(range(y + 1, x))
	return res
T = int(input())
for t in range(T):
	(x, y) = list(map(int, input().split()))
	res = solve(x, y)
	print(len(res))
	print(' '.join(map(str, res)))


import sys

def solve():
	inp = sys.stdin.readline
	(x, y) = map(int, inp().split())
	print((x - y) * 2)
	arr = list(range(y, x)) + list(range(x, y, -1))
	print(' '.join(map(str, arr)))

def main():
	for i in range(int(sys.stdin.readline())):
		solve()
main()


def getint():
	return int(input())

def getfloat():
	return float(input())

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

def getfloats():
	return list(map(float, input().split()))

def answer():
	(a, b) = getints()
	print((a - b) * 2)
	ans = []
	for i in range(a, b, -1):
		ans.append(i)
	for i in range(b, a):
		ans.append(i)
	print(' '.join(map(str, ans)))
T = getint()
for i in range(T):
	answer()


T = int(input())
for i in range(T):
	(x, y) = input().split()
	(x, y) = (int(x), int(y))
	ans = [i for i in range(y, x + 1)]
	ans.extend(ans[-2:0:-1])
	print(len(ans))
	print(' '.join(list(map(str, ans))))


import sys
input = lambda : sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	a = [i for i in range(M + 1, N)] + [N] + [i for i in range(N - 1, M - 1, -1)]
	print(len(a))
	print(' '.join(map(str, a)))


t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	print(2 * (x - y))
	l = [str(i) for i in range(y, x + 1)]
	h = [str(i) for i in range(x - 1, y, -1)]
	print(' '.join(l + h))


def helper(x, y):
	arr = [y + 1]
	curr = arr[0]
	mx = False
	mini = False
	while curr != x:
		curr += 1
		arr.append(curr)
	while curr != y:
		curr -= 1
		arr.append(curr)
		if curr == y:
			break
	while abs(curr - arr[0]) != 1:
		curr += 1
		arr.append(curr)
		if abs(curr - arr[0]) == 1:
			break
	return [len(arr), ' '.join(list(map(str, arr)))]
for i in range(int(input())):
	inp = list(map(int, input().split()))
	rez = helper(inp[0], inp[1])
	print(rez[0])
	print(rez[1])


def f(min, max):
	l = [i for i in range(min, max + 1, 1)]
	l1 = l[1:-1]
	l1.reverse()
	l = l + l1
	length = len(l)
	l = list(map(str, l))
	l = ' '.join(l)
	print(length)
	print(l)
for t in range(int(input())):
	inp1 = list(map(int, input().split(' ')))
	min = inp1[1]
	max = inp1[0]
	f(min, max)


n = int(input())
for i in range(n):
	(y, x) = map(int, input().split())
	w = list(range(x, y + 1))
	base = w + w[::-1][1:len(w) - 1]
	print(len(base))
	print(' '.join(map(str, base)))


def solve():
	numbers = [int(x) for x in input().split()]
	x = numbers[0]
	y = numbers[1]
	n = 0
	a = [str(x) for x in list(range(y, x + 1))]
	for i in range(x - 1, y, -1):
		a.append(str(i))
	print(len(a))
	print(' '.join(a))
t = int(input())
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	(x, y) = (int(a) for a in input().split())
	print(2 * (x - y))
	out = [i for i in range(y, x + 1)] + [i for i in range(x - 1, y, -1)]
	print(' '.join(map(str, out)))


for t in range(int(input())):
	(x, y) = map(int, input().split())
	print(2 * abs(x - y))
	res = [str(x)] + [str(i) for i in range(x - 1, y, -1)] + [str(y)] + [str(i) for i in list(range(x - 1, y, -1))[::-1]]
	print(' '.join(res))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mylist = []
	for i in range(m, n + 1):
		mylist.append(i)
	for j in range(n - 1, m, -1):
		mylist.append(j)
	print(len(mylist))
	print(' '.join(map(str, mylist)))


import os
import math
import collections
import bisect
import functools
import itertools
import heapq

def solve(ma, mi):
	a = list(range(ma, mi - 1, -1))
	a += list(range(mi + 1, ma))
	return a
t = int(input())
for _ in range(t):
	(ma, mi) = map(int, input().split())
	res = solve(ma, mi)
	print(len(res))
	print(' '.join(map(str, res)))


gandhicharu = int(input())
for _ in range(gandhicharu):
	(xgvf, ygty) = map(int, input().split())
	res = []
	for i in range(ygty + 1, xgvf + 1):
		res.append(str(i))
	for i in range(xgvf - 1, ygty - 1, -1):
		res.append(str(i))
	print(len(res))
	print(' '.join(res))


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	L = []
	for i in range(x, y, -1):
		L.append(i)
	for j in range(y, x):
		L.append(j)
	print(len(L))
	print(' '.join(map(str, L)))


def solve(x, y):
	len = 2 * (x - y)
	out = [0] * len
	for i in range(len // 2):
		out[i] = x - i
		out[i + len // 2] = y + i
	return out
t = int(input())
ans = []
for ti in range(t):
	(x, y) = [int(x) for x in input().split()]
	ans.append(solve(x, y))
for a in ans:
	print(len(a))
	print(' '.join([str(x) for x in a]))


for _ in range(int(input())):
	(y, x) = map(int, input().split())
	lst = list(range(x + 1, y))
	res = list(map(str, [x] + lst + [y] + list(reversed(lst))))
	print(len(res), '\n', ' '.join(map(str, res)))


import sys

def read(func=int):
	return func(sys.stdin.readline().strip())

def read_array(func=int):
	return list(map(func, read(str).split()))
t = read()
for _ in range(t):
	(x, y) = read_array()
	n = 2 * (x - y)
	A = [0] * n
	idx = 0
	for i in range(y, x + 1):
		A[idx] = i
		idx += 1
	for i in range(x - 1, y, -1):
		A[idx] = i
		idx += 1
	print(n)
	print(' '.join([str(ai) for ai in A]))


n = int(input())
for i in range(n):
	k = input()
	(u, v) = (int(k.split(' ')[0]), int(k.split(' ')[1]))
	arr = []
	for j in range(v, u):
		arr += [str(j)]
	for j in range(u, v, -1):
		arr += [str(j)]
	print(len(arr))
	print(' '.join(arr))


T = int(input())
for t in range(T):
	(X, Y) = [int(x) for x in input().split()]
	ans = []
	for i in range(X, Y - 1, -1):
		ans.append(str(i))
	for i in range(Y + 1, X):
		ans.append(str(i))
	print(len(ans))
	print(' '.join(ans))


import math
T = int(input(''))
for i in range(T):
	str1 = input()
	l1 = [int(c) for c in str1.split()]
	n = 2 + 2 * (l1[0] - l1[1] - 1)
	ans = [l1[1]]
	for j in range(l1[1] + 1, l1[0]):
		ans.append(j)
	ans.append(l1[0])
	for j in reversed(range(l1[1] + 1, l1[0])):
		ans.append(j)
	print(n)
	print(' '.join([str(c) for c in ans]))


def f(x, y):
	ox = x
	s = ''
	l = 2 * abs(x - y)
	a = []
	while x != y:
		a.append(x)
		a.append(' ')
		x -= 1
	while x != ox:
		a.append(x)
		a.append(' ')
		x += 1
	print(l)
	a = map(str, a)
	print(''.join(a))
inp = int(input())
for i in range(inp):
	(a, b) = list(map(int, input().split()))
	f(a, b)


t = int(input())
for nouse in range(t):
	(x, y) = map(int, input().split())
	m = []
	i = y
	m.append(i)
	while i != x:
		i += 1
		m.append(i)
	while i != y + 1:
		i -= 1
		m.append(i)
	print(len(m))
	print(' '.join(list(map(str, m))))


import sys
input = sys.stdin.readline
print = sys.stdout.write
cases = int(input())
matrix = []
for i in range(cases):
	matrix = list(map(int, input().split()))
	print(str(2 * (matrix[0] - matrix[1] + 1) - 2) + '\n')
	for k in range(matrix[0], matrix[1] - 1, -1):
		print(str(k) + ' ')
	for k in range(matrix[1] + 1, matrix[0]):
		print(str(k) + ' ')
	print('\n')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = [i for i in range(a - 1, b, -1)]
	res = [a] + x + [b] + x[::-1]
	print(len(res))
	print(*res)


def solution(x, y):
	res = [i for i in range(x, y - 1, -1)]
	res.extend([i for i in range(y + 1, x)])
	print(len(res))
	print(*res)
t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	solution(x, y)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a = list(range(y, x))
	b = [x] + a[::-1]
	c = b[::-1]
	d = c[1:-1]
	f = b + d
	print(len(f))
	print(*f)


t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	print((x - y) * 2)
	print(*range(y, x), *range(x, y, -1))


kol = int(input())
for j in range(0, kol):
	(n, m) = map(int, input().split())
	min_ = min(n, m)
	max_ = max(n, m)
	l1 = list(range(min_, max_))
	l2 = list(range(max_, min_, -1))
	res = l1 + l2
	print(len(res))
	print(*res)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a = list(range(y, x + 1))
	a += a[-2:0:-1]
	print(len(a))
	print(*a)


t = int(input())
for i in range(t):
	(a, b) = [int(v) for v in input().split()]
	p1 = [v for v in range(min(a, b), max(a, b))]
	p2 = [v for v in range(min(a, b) + 1, max(a, b) + 1)]
	p2.reverse()
	print(len(p1 + p2))
	print(*p1 + p2, sep=' ')


q = int(input())
for i in range(q):
	(a, b) = map(int, input().split())
	l1 = [v for v in range(min(a, b), max(a, b))]
	l2 = [v for v in range(min(a, b) + 1, max(a, b) + 1)]
	l2.reverse()
	print(len(l1 + l2))
	print(*l1 + l2, sep=' ')


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ans = tuple(range(y, x + 1)) + tuple(range(x - 1, y, -1))
	print(len(ans))
	print(*ans)


for _ in range(int(input())):
	(smax, smin) = map(int, input().split())
	res = list(range(smax - 1, smax)) + list(range(smax, smin, -1)) + list(range(smin, smax - 1))
	print(len(res))
	print(*res)


import functools
import itertools
import sys
from collections import defaultdict

def solution():
	(a, b) = map(int, input().split())
	n = a - b
	data = list(range(a, b, -1)) + list(range(b, a))
	print(2 * n)
	print(*data)
t = int(input())
for _ in range(t):
	solution()


for _ in range(int(input())):
	(x, y) = [int(i) for i in input().split()]
	s = y
	l = 2 * (x - s)
	print(l)
	res = [i for i in range(s, s + l // 2)]
	res2 = [i for i in range(s + l // 2, s, -1)]
	res = res + res2
	print(*res)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	arr = []
	print(x - y + (x - 1 - y) + 1)
	for i in range(y + 1, x + 1):
		arr.append(i)
	for j in range(x - 1, y - 1, -1):
		arr.append(j)
	print(*arr)


import sys
input = sys.stdin.readline
for i in range(int(input())):
	(a, b) = map(int, input().split())
	(x, y) = (max(a, b), min(a, b))
	s = [i for i in range(x, y, -1)] + [i for i in range(y, x)]
	print(len(s))
	print(*s)


for _ in range(int(input())):
	(mx, mn) = input().split()
	(mx, mn) = (int(mx), int(mn))
	r = []
	for i in range(mn, mx + 1):
		r.append(i)
	r += r[1:-1][::-1]
	print(len(r))
	print(*r)


def function():
	(x, y) = input().split(' ')
	x = int(x)
	y = int(y)
	a = (x - y) * 2
	print(a)
	for k in range(y, x):
		print(k, end=' ')
	for k in range(x, y, -1):
		print(k, end=' ')
	print('')

def main():
	t = int(input())
	for i in range(0, t):
		function()
main()


from collections import deque
import sys
input = lambda : sys.stdin.readline().strip()
mod = 7 + 10 ** 9

def solve():
	(a, b) = [int(i) for i in input().split()]
	d = deque()
	for i in range(a, b - 1, -1):
		d.append(i)
	for i in range(b + 1, a):
		d.append(i)
	return d
for i in range(int(input())):
	o = solve()
	print(len(o))
	print(*o)


T = int(input())
for t in range(0, T):
	(x, y) = map(int, input().split(' '))
	n = x - y
	print(2 * n)
	lst = list(range(y + 1, x + 1))
	lst += list(range(y, x))[::-1]
	print(*lst)


import sys
input = sys.stdin.readline

def solve():
	(n, m) = map(int, input().split())
	print(2 * (n - m))
	for i in range(n, m - 1, -1):
		print(i, end=' ')
	for i in range(m + 1, n):
		print(i, end=' ')
	print()
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, q) = map(int, input().split())
	print((n - q) * 2)
	print(*[i for i in range(q, n + 1)], *[i for i in range(n - 1, q, -1)])


for testcase in range(int(input())):
	list = []
	(x, y) = map(int, input().split())
	for i in range(y, x):
		list.append(i)
	for i in range(x, y, -1):
		list.append(i)
	print(len(list))
	print(*list)


import collections
import math
import heapq
for _ in range(int(input())):
	(x, y) = list(map(int, input().split()))
	res = []
	for i in range(x, y - 1, -1):
		res.append(i)
	for i in range(y + 1, x):
		res.append(i)
	print(len(res))
	print(*res)


t = int(input())
ans = []
res = []
for _ in range(t):
	(x, y) = map(int, input().split())
	ans.append(abs(x - y) * 2)
	res.append([i for i in range(y, x)] + [j for j in range(x, y, -1)])
for i in range(t):
	print(ans[i])
	print(*res[i])


import sys
sys_input = sys.stdin.readline
sys_print = sys.stdout.write

def testcase():
	(mx, mn) = map(int, sys_input().split())
	n = mx - mn
	print(2 * n)
	arr = [*range(mx, mn, -1)] + [*range(mn, mx)]
	print(*arr)
t = int(sys_input())
for _ in range(t):
	testcase()


def intRd():
	return int(input())

def lstRd():
	return list(map(int, input().split()))
for _ in range(intRd()):
	(x, y) = lstRd()
	print((x - y) * 2)
	for i in range(y, x):
		print(i, end=' ')
	for i in range(x, y, -1):
		print(i, end=' ')
	print()


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	length = abs(x - y) * 2
	low = min(x, y)
	high = max(x, y)
	answer = [i for i in range(low, high + 1)]
	answer += [i for i in range(high - 1, low, -1)]
	print(length)
	print(*answer)


t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split(' '))
	if x > y:
		(x, y) = (y, x)
	print((y - x) * 2)
	for i in range(x, y):
		print(i, end=' ')
	for i in range(y, x, -1):
		print(i, end=' ')
	print()


t = int(input())
for i in range(0, t):
	(b, a) = list(map(int, input().split()))
	c = (b + a) // 2
	d = 0
	e = (b - a) * 2
	if e == 2:
		print(2)
		print(a, b)
	else:
		print(e)
		for j in range(c, b + 1):
			print(j, end=' ')
		for j in range(b - 1, a - 1, -1):
			print(j, end=' ')
		for j in range(a + 1, c):
			print(j, end=' ')
	print('\r')


t = int(input())
for test in range(t):
	(a, b) = map(int, input().strip().split())
	print(2 * (a - b))
	for i in range(b, a):
		print(i, end=' ')
	for i in range(a, b, -1):
		print(i, end=' ')
	print()


import sys
t = int(sys.stdin.readline())
for i in range(t):
	(x, y) = map(int, input().split())
	arr = []
	for j in range(x, y - 1, -1):
		arr.append(j)
	for j in range(y + 1, x):
		arr.append(j)
	print(len(arr))
	print(*arr)


test_case = int(input())
for test in range(test_case):
	(x, y) = map(int, input().split())
	print(2 * (x - y))
	P = []
	for i in range(y + 1, x + 1):
		P.append(i)
	for i in range(x - 1, y - 1, -1):
		P.append(i)
	print(*P)


def solve():
	(a, b) = map(int, input().split())
	if a - b == 1:
		print(2)
		print(a - 1, a)
		return
	print((a - b) * 2)
	print(a - 1, a, a - 1, end=' ')
	for i in range(a - 2, b - 1, -1):
		print(i, end=' ')
	for i in range(b + 1, a - 1):
		print(i, end=' ')
	print('')
for _ in range(int(input())):
	solve()


for t in range(int(input())):
	(x, y) = map(int, input().split())
	ans = []
	if x == y:
		ans.append(x)
	else:
		temp = list(range(y + 1, x))
		ans.append(y)
		ans += temp
		ans.append(x)
		temp.reverse()
		ans += temp
	print(len(ans))
	print(*ans)


t = int(input())
for _ in range(0, t):
	(x, y) = map(int, input().split(' '))
	print(2 * (x - y))
	for i in range(x, y - 1, -1):
		print(i, end=' ')
	for i in range(y + 1, x):
		print(i, end=' ')
	print('\n')


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	l = []
	print((a + b * -1) * 2)
	for i in range(a, b, -1):
		l.append(i)
	for i in range(b, a):
		l.append(i)
	print(*l)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a = [i for i in range(x, y - 1, -1)]
	for i in range(y + 1, x):
		a.append(i)
	print(len(a))
	print(*a)


import sys
import math as m

def mmin(a, b):
	if a >= b:
		return b
	return a
t = int(input())
while t:
	t -= 1
	res = 0
	(x, y) = map(int, input().split())
	res = 2 * (x - y)
	print(res)
	for i in range(x, y, -1):
		print(i, end=' ')
	for i in range(y, x, 1):
		if i == x - 1:
			print(i)
		else:
			print(i, end=' ')


t = int(input())
for i in range(t):
	(x, y) = [int(i) for i in input().split()]
	diff = x - y
	a = []
	for i in range(y, x + 1):
		a.append(i)
	for i in range(x - 1, y, -1):
		a.append(i)
	print(2 * diff)
	print(*a)


gh = int(input())
for kl in range(gh):
	(a, b) = map(int, input().split())
	c = [0] * (a - b) * 2
	k = 0
	for i in range(a, b - 1, -1):
		c[k] = i
		k += 1
	for i in range(b + 1, a):
		c[k] = i
		k += 1
	print(len(c))
	print(*c)


t = int(input())
for i in range(t):
	(a, b) = tuple([int(x) for x in input().split()])
	print(2 * (a - b))
	for i in range(b, a + 1):
		print(i, end=' ')
	for i in range(a - 1, b, -1):
		print(i, end=' ')
	print()


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	arr = []
	for i in range(x - y):
		arr.append(x - i)
	for i in range(x - y):
		arr.append(y + i)
	print(2 * (x - y))
	print(*arr)


n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	print((x - y) * 2)
	for j in range(x, y, -1):
		print(j, end=' ')
	for k in range(y, x):
		print(k, end=' ')
	print()


t = int(input())
while t:
	(x, y) = [int(x) for x in input().split()]
	print(2 * (x - y))
	for i in range(y + 1, x + 1):
		print(i, end=' ')
	for i in range(x - 1, y - 1, -1):
		print(i, end=' ')
	print()
	t -= 1


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	n = (abs(x) + abs(y)) * 2
	a = []
	for i in range(x, y - 1, -1):
		a.append(i)
	for i in range(y + 1, x):
		a.append(i)
	print(len(a))
	print(*a)


from collections import Counter
import math
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if x >= 0 and y >= 0:
		a = list(range(y + 1, x))
		l = [y] + a + [x] + a[::-1]
	elif x <= 0 and y <= 0:
		a = list(range(y + 1, x))
		l = [y] + a + [x] + a[::-1]
	elif x >= 0 and y <= 0:
		a = list(range(0, x))
		b = list(range(y + 1, 0))
		c = a[::-1]
		d = b[::-1]
		l = a + [x] + c + d + [y] + b
	print(len(l))
	print(*l)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	k = (n - m) * 2
	print(k)
	ans = []
	j = m + 1
	while j <= n:
		ans.append(j)
		j += 1
	i = n - 1
	while i >= m:
		ans.append(i)
		i -= 1
	print(*ans)