Problem:
Score : 100 points

Problem Statement

We have an N×N checkerboard.

From the square at the upper left corner, a square that is i squares to the right and j squares below is denoted as (i, j). Particularly, the square at the upper left corner is denoted as (0, 0).

Each square (i, j) such that i+j is even, is colored black, and the other squares are colored white.

We will satisfy the following condition by painting some of the white squares:

Any black square can be reached from square (0, 0) by repeatedly moving to a black square that shares a side with the current square.

Achieve the objective by painting at most 170000 squares black.

Constraints

1 \leq N \leq 1,000

Input

The input is given from Standard Input in the following format:

N

Output

Print the squares to paint in the following format:

K
x_1 y_1
x_2 y_2
:
x_K y_K

This means that a total of K squares are painted black, the i-th of which is (x_i, y_i).

Judging

The output is considered correct only if all of the following conditions are satisfied:

0 \leq K \leq 170000

0 \leq x_i, y_i \leq N-1

For each i, x_i + y_i is odd.

If i \neq j, then (x_i, y_i) \neq (x_j, y_j).

The condition in the statement is satisfied by painting all specified squares.

Sample Input 1

2

Sample Output 1

1
1 0

Sample Input 2

4

Sample Output 2

3
0 1
2 1
2 3

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<vector<bool>> board(N, vector<bool>(N));
		rep(i, N) rep(j, N)
			board[i][j] = (i + j) % 2 == 0;
		rep(i, N) board[i][0] = board[i][N - 1] = true;
		rep(j, N) board[0][j] = board[N - 1][j] = true;
		rer(k, 0, 20) {
			rep(i, N >> k) rep(j, N >> k) if((i + j) % 4 == 1 && (i - j + N * 4) % 4 == 3) {
				if(((j + 1) << k) - 1 < N)
					board[i << k][((j + 1) << k) - 1] = true;
			}
		}
		vpii ans;
		rep(i, N) rep(j, N) if(board[i][j] != ((i + j) % 2 == 0)) {
			assert(board[i][j]);
			ans.emplace_back(i, j);
		}
		printf("%d\n", (int)ans.size());
		for(int i = 0; i < (int)ans.size(); ++ i)
			printf("%d %d\n", ans[i].first, ans[i].second);
	}
	return 0;
}