#ARC139C. [ARC139C] One Three Nine

[ARC139C] One Three Nine

Score : 700700 points

Problem Statement

You are given positive integers NN and MM.

Let us call a sequence of pairs of integers ((X1,Y1),(X2,Y2),,(XK,YK))((X_1,Y_1),(X_2,Y_2),\dots,(X_K,Y_K)) wonderful when it satisfies the following.

  • 1XiN1 \le X_i \le N
  • 1YiM1 \le Y_i \le M
  • Xi+3YiXj+3YjX_i+3Y_i \neq X_j+3Y_j and 3Xi+Yi3Xj+Yj3X_i+Y_i \neq 3X_j+Y_j, if iji \neq j.

Make a wonderful sequence of pairs of integers whose length, KK, is the maximum possible.

Constraints

  • 1N,M1051 \le N,M \le 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

Output

Print your answer in the following format:

KK

X1X_1 Y1Y_1

X2X_2 Y2Y_2

\vdots

XKX_K YKY_K

Here, KK should be the maximum possible length of a wonderful sequence of pairs of integers, and ((X1,Y1),(X2,Y2),,(XK,YK))((X_1,Y_1),(X_2,Y_2),\dots,(X_K,Y_K)) should be a wonderful sequence of pairs of integers. If multiple solutions exist, printing any of them is accepted.

3 4
10
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
3 4

For N=3,M=4N=3, M=4, there is no wonderful sequence of pairs of integers whose length is 1111 or longer, and the above sequence of pairs of integers is wonderful, so this output is valid.