// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.ArrayList;
import java.util.List;

public class Plan {
    public static void main(String[] args) {
        int n = Integer.parseInt(args[0]);
        int nr = ((n + 1) / 2) * 2 - 1;
        int nm = n / 2;
        Match[] mtch = new Match[nr * nm];
        genmatches(mtch, n);
        //for(int i = 0; i < mtch.length; i++) {
        //    System.out.println(mtch[i]);
        //}
        List rnd = new ArrayList();
        genrounds(rnd, new Round(nm), mtch, 0, 0, nm); 
        //for(int i = 0; i < rnd.size(); i++) {
        //    System.out.println((Round)rnd.get(i));
        //}
        List plan = new ArrayList();
        boolean[] used = new boolean[rnd.size()];
        for(int i = 0; i < used.length; i++) {
            used[i] = false;
        }
        genplans(plan, new Plan(nr), rnd, used, 0, nr);
        for(int i = 0; i < plan.size(); i++) {
            System.out.println((Plan)plan.get(i));
        }
        System.out.println(plan.size());
    }
    private static void genplans(List plan, Plan wrk, List rnd, boolean[] used, int ix, int nr) {
        if(ix < nr) {
            for(int i = 0; i < used.length; i++) {
                if(!used[i]) {
                    used[i] = true;
                    wrk.setRound(ix, (Round)rnd.get(i));
                    genplans(plan, wrk, rnd, used, ix + 1, nr);        
                    used[i] = false;
                }
            }
        } else {
            if(wrk.isvalid()) {
                plan.add(wrk.clone());    
            }
        }
    }
    private static void genmatches(Match[] mtch, int n) { 
        int ix = 0;
        for(int i = 0; i < n; i++) {
            for(int j = (i + 1); j < n; j++) {
                mtch[ix] = new Match(i + 1, j + 1);
                ix++;
            }
        }
    }
    private static void genrounds(List rnd, Round wrk, Match[] mtch, int ix, int pos, int nm) {
        if(pos < nm) {
            for(int i = ix; i < mtch.length; i++) {
                wrk.setMatch(pos, mtch[i]);
                genrounds(rnd, wrk, mtch, i + 1, pos + 1, nm);
            }
        } else {
            if(wrk.isValid()) {
                rnd.add(wrk.clone());
            }
        }
    }
    private static int fac(int v) {
        int res = 1;
        for(int i = 2; i <= v; i++) {
            res *= i;
        }
        return res;
    }
    private Round[] rounds;
    public Plan(int nr) {
        rounds = new Round[nr];
        for(int i = 0; i < rounds.length; i++) {
            rounds[i] = null;
        }
    }
    public void setRound(int ix, Round r) {
        rounds[ix] = r;
    }
    public Round getRound(int ix) {
        return rounds[ix];
    }
    public String toString() {
        StringBuffer sb = new StringBuffer("");
        for(int i = 0; i < rounds.length; i++) {
            sb.append(rounds[i]);
            sb.append("\n");
        }
        return sb.toString();
    }
    public boolean isvalid() {
        for(int i = 0; i < rounds.length; i++) {
            for(int j = (i + 1); j < rounds.length; j++) {
                if(rounds[i].overlap(rounds[j])) {
                    return false;
                }
            }
        }
        return true;
    }
    public Object clone() {
        Plan res = new Plan(rounds.length);
        res.rounds = (Round[])rounds.clone();
        return res;
    }
}

class Round {
    private Match[] matches;
    public Round(int nm) {
        matches = new Match[nm];
        for(int i = 0; i < matches.length; i++) {
            matches[i] = null;
        }
    }
    public void setMatch(int ix, Match m) {
        matches[ix] = m;
    }
    public Match getMatch(int ix) {
        return matches[ix];
    }
    public String toString() {
        StringBuffer sb = new StringBuffer("");
        for(int i = 0; i < matches.length; i++) {
            if(i > 0) {
                sb.append(" ");
            }
            sb.append(matches[i]);
        }
        return sb.toString();
    }
    public boolean isValid() {
        for(int i = 0; i < matches.length; i++) {
            for(int j = (i + 1); j < matches.length; j++) {
                if(matches[i].getTeam1() == matches[j].getTeam2() ||
                matches[i].getTeam1() == matches[j].getTeam1() ||
                matches[i].getTeam2() == matches[j].getTeam2() ||
                matches[i].getTeam2() == matches[j].getTeam1()) {
                    return false;
                }
            }
        }
        return true;
    }
    public boolean overlap(Round o) {
        for(int i = 0; i < matches.length; i++) {
            for(int j = 0; j < o.matches.length; j++) {
                if(matches[i].equals(o.matches[j])) {
                    return true;
                }
            }
        }
        return false;    
    }
    public Object clone() {
        Round res = new Round(matches.length);
        res.matches = (Match[])matches.clone();
        return res;
    }
}

class Match {
    private int team1;
    private int team2;
    public Match(int team1, int team2) {
        this.team1 = team1;
        this.team2 = team2;
    }
    public int getTeam1() {
        return team1;
    }
    public int getTeam2() {
        return team2;
    }
    public String toString() {
        return team1 + "-" + team2;
    }
    public boolean equals(Object o) {
        if (o instanceof Match) {
            if (team1 == ((Match) o).team1 && team2 == ((Match) o).team2) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}
