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
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <bits/stdc++.h>

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

/*************************************************************************/

bool isSegmentHilbert(int x, int y, int n) {
    if (n == 1) {
        return (x % 2 || y % 2) && (x != 1 || y != 0);
    }
    
    int N = (1 << n);
    
    if (x > N - 1) {
        x = 2 * N - 2 - x;
    }
    
    if (x == N - 1) {
        return y == N;
    }
    
    if (y == N - 1) {
        return x == 0;
    }
    
    if (y < N - 1) {
        swap(x, y);
        x = N - 2 - x;
    } else {
        y -= N;
    }
    
    return isSegmentHilbert(x, y, n-1);
}

bool isSegmentBoard(int x, int y, int n) {
    int N = 1 << (n + 1);
    return x == 0 || x == N || y == 0 || y == N || isSegmentHilbert(x-1, y-1, n);
}

/*************************************************************************/

void simulate(int &x, int &y, int &dx, int &dy, int n) {
    int N = 1 << (n + 1);
    
    x += dx;
    y += dy;
    
    if (isSegmentBoard(x, y, n)) {
        if (x == 0 || x == N) {
            dx *= -1;
        } else if (y == 0 || y == N) {
            dy *= -1;
        } else if (x % 2) {
            dx *= -1;
        } else {
            dy *= -1;
        }
    }
}

/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);    
    
    int n, z;
    cin >> n >> z;
    
    int x = 1, y = 0;
    int dx = 1, dy = 1;
    int time = 0;
    
    while (z--) {
        int t;
        cin >> t;
        
        while (time < t) {
            simulate(x, y, dx, dy, n);
            time++;
        }
        
        cout << x << ' ' << y << endl;
    }

    return 0;
}

/*************************************************************************/