Code:
#include <cstdio>
#include <algorithm>
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int main() {
// setIO("input");
int n,i,j,m;
scanf("%d",&n);
printf("%d\n",m=(n>>1));
for(i=1;i<=m;++i) {
for(j=1;j<=m;++j) printf("%d %d ",i,i+j);
for(j=1;j<n-m;++j) printf("%d %d ",i+m,(i+m+j-1)%n+1);
printf("\n");
}
return 0;
}