package genesom;

public class CyclicIndex {

  public static int[] compute(int n) {

    int[] arr = new int[n],
          ind = new int[n];

    for(int i = 0; i < n; i++) arr[i] = i;

    int del = 0, seq = 0, end = (n << 1)-1;


    while(true) {

      ind[seq] = del;

      arr[del] = -seq-1;

      int max = -1, len = 0, left = 0, mleft = 0, maxage = 0, t;

      for(int j = 0; j < end; j++) {

        if((t = arr[j % n]) < 0) {

          if(len > max || (len == max && t >= maxage)) {
            max = len;
            mleft = left;
            maxage = t;
          }
          left = j+1;
          len = 0;
        }
        else ++len;
      }

      if(max <= 0) break;

      del = (mleft + (max >> 1)) % n;

      ++seq;
    }

    return ind;
  }

  public static void main(String args[]) {


    int n = new Integer(args[0]).intValue(),
        ind[] = compute(n);

    for(int i = 0; i < n; i++) System.out.println(i + " " + ind[i]);
  }
}
