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
import java.util.Arrays;
import java.util.Scanner;

public class hil {

    static int[][] initial = new int[][]{   {3,1,1,1,3},
                                            {-1,3,1,3,-1},
                                            {-1,0,0,-1,-1},
                                            {-1,3,1,3,-1},
                                            {3,1,1,1,3},
                                    };

    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);
        int tableSize = sc.nextInt();
        int questionsCount = sc.nextInt();
        int[] questions = new int[questionsCount];
        for(int i = 0; i<questionsCount; i++){
            questions[i] = sc.nextInt();
        }
        int[][] table = makeTable(tableSize);
        Arrays.sort(questions);
        int currentX = 1;
        int currentY = 0;
        Vector v = new Vector(1,1);
        for(int i = 0; i < questions.length; i++){
            for(int j = i+1; j<= questions[i]; j++){
                currentX+=v.x;
                currentY+=v.y;
                if(table[currentX][currentY] != 0){
                    v.changeDirection(table[currentX][currentY]);
                }
            }
            System.out.println(currentX + " " + currentY);
        }
    }

    static class Vector{
        int x;
        int y;

        public Vector(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public int getX() {
            return x;
        }

        public int getY() {
            return y;
        }

        public void changeDirection(int collision){
            if(collision == 1){
                x=-x;
            } else {
                y=-y;
            }
        }
    }

    private static int[][] makeTable(int tableSize) {
        if(tableSize==1){
            return initial;
        } else {
            int[][] previousOne = initial;
            int[][] result = new int[0][0];
            for (int i = 1; i < tableSize; i++){
                int oldSize = previousOne.length;
                int newSize = oldSize*2-1;
                result = new int[newSize][newSize];
                for(int x = 1; x<oldSize-1; x++){
                    for(int y = 1; y<oldSize-1; y++){
                        //Left bottom
                        result[y][oldSize-1-x] = previousOne[x][y]*-1;
                        //Left top
                        result[x][y+oldSize-1] = previousOne[x][y];
                        //Right top
                        result[x+oldSize-1][y+oldSize-1] = previousOne[x][y];
                        //Right bottom
                        result[result.length-1-y][x] = previousOne[x][y]*-1;
                    }
                }
                result[1][oldSize-1] = 1;
                result[1][oldSize-2] = 1;
                result[1][oldSize] = 1;

                result[newSize-2][oldSize-1] = 1;
                result[newSize-2][oldSize-2] = 1;
                result[newSize-2][oldSize] = 1;

                result[oldSize-1][oldSize] = -1;
                result[oldSize-2][oldSize] = -1;
                result[oldSize][oldSize] = -1;
                previousOne = result;
            }
            for(int i=0; i < result.length; i++){
                result[0][i] = 1;
                result[result.length-1][i] = 1;
                result[i][0] = -1;
                result[i][result.length-1] = -1;
            }
            return  result;
        }
    }

}