Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Problem I
Skinny Polygon

You are asked to find a polygon that satisfies all the following conditions, given two integers, $x_{bb}$ and $y_{bb}$.

The number of vertices is either 3 or 4.

Edges of the polygon do not intersect nor overlap with other edges, i.e., they do not share any points with other edges except for their endpoints.

The $x$- and $y$-coordinates of each vertex are integers.

The $x$-coordinate of each vertex is between 0 and $x_{bb}$, inclusive. Similarly, the $y$-coordinate is between 0 and $y_{bb}$, inclusive.

At least one vertex has its $x$-coordinate 0.

At least one vertex has its $x$-coordinate $x_{bb}$.

At least one vertex has its $y$-coordinate 0.

At least one vertex has its $y$-coordinate $y_{bb}$.

The area of the polygon does not exceed 25000.

The polygon may be non-convex.

Input

The input consists of multiple test cases. The first line of the input contains an integer $n$, which is the number of the test cases ($1 \leq n \leq 10^5$). Each of the following $n$ lines contains a test case formatted as follows.

$x_{bb}$ $y_{bb}$

$x_{bb}$ and $y_{bb}$ ($2 \leq x_{bb} \leq 10^9, 2 \leq y_{bb} \leq 10^9$) are integers stated above.

Output

For each test case, output description of one polygon satisfying the conditions stated above, in the following format.

$v$

$x_1$ $y_1$

.

.

.

$x_v$ $y_v$

Here, $v$ is the number of vertices, and each pair of $x_i$ and $y_i$ gives the coordinates of the $i$-th vertex, $(x_i, y_i)$. The first vertex $(x_1, y_1)$ can be chosen arbitrarily, and the rest should be listed either in clockwise or in counterclockwise order.

When more than one polygon satisfies the conditions, any one of them is acceptable. You can prove that, with the input values ranging as stated above, there is at least one polygon satisfying the conditions.

Sample Input 1

2
5 6
1000000000 2

Sample Output 1

4
5 6
0 6
0 0
5 0
3
1000000000 0
0 2
999999999 0

Solution in C (judge verdict: Accepted)

// AOJ 1375 Skinny Polygon
// 2018.3.21 bal4u

#include <stdio.h>
#include <stdlib.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int extended_gcd(int a, int b, int *x, int *y)
{
	int _gcd;
	if (b == 0) { *x = 1; *y = 0; return a; }
	_gcd = extended_gcd(b, a%b, y, x);
	*y -= a / b * (*x);
	return _gcd;
}

int main()
{
	int n, x, y, a, b, g;

	n = in();
	while (n--) {
		x = in(), y = in();
		g = extended_gcd(x, y, &a, &b);
		if (a < 0) a = -a;
		if (b < 0) b = -b;
		if (g < 50000) {
			printf("3\n0 0\n%d %d\n%d %d\n", x, y, b, a);
		} else {
			printf("4\n0 0\n%d %d\n%d %d\n%d %d\n", x, y-1, x/g, y/g, x-1, y);
		}
	}
	return 0;
}