1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>

#define PB          push_back
#define ST          first
#define ND          second

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using VII = vector<PII>;
using LL = long long int;
using ULL = unsigned long long int;

const int MAX_SIZE = 8192 + 2;
const int MAX_Z = 100005;

int n;
int board_size;
LL t[MAX_Z];

bool board_hor[MAX_SIZE][MAX_SIZE];
bool board_ver[MAX_SIZE][MAX_SIZE];

void BuildBoard() {
  board_size = 2;
  board_hor[2][1] = true;
  board_ver[1][2] = true;
  board_ver[3][2] = true;
  for (int i = 0; i < n; ++i) {
    for (int x = 1; x < board_size; ++x) {
      for (int y = 1; y < board_size; ++y) {
        board_hor[x + board_size][y] = board_hor[x][y];
        board_ver[x + board_size][y] = board_ver[x][y];
        board_hor[board_size][board_size - 1] = true;

        board_hor[board_size - y][x + board_size] = board_ver[x][y];
        board_ver[board_size - y][x + board_size] = board_hor[x][y];
        board_ver[1][board_size] = true;

        board_hor[y + board_size][2 * board_size - x] = board_ver[x][y];
        board_ver[y + board_size][2 * board_size - x] = board_hor[x][y];
        board_ver[2 * board_size - 1][board_size] = true;
      }
    }
    board_size *= 2;
  }
}

struct Point {
  int x, y;
};

int main() {
  int z;
  scanf("%d %d", &n, &z);
  for (int i = 0; i < z; ++i) {
    scanf("%lld", &t[i]);
  }
  BuildBoard();
  int time_pos = 0;
  Point p;
  p.x = 1; p.y = board_size;
  int vx = 1, vy = -1;
  for (int time = 1; time <= t[z-1]; ++time) {
    p.x += vx;
    p.y += vy;
    if (board_hor[p.x][p.y]) {
      vy = -vy;
    } else if (board_ver[p.x][p.y]) {
      vx = -vx;
    } else if (p.x == 0 || p.x == board_size) {
      vx = -vx;
    } else if (p.y == 0 || p.y == board_size) {
      vy = -vy;
    }
    if (time == t[time_pos]) {
      printf("%d %d\n", p.x, board_size - p.y);
      ++time_pos;
    }
  }
  return 0;
}