Problem:
 Score : 700 points    Problem Statement You are given an integer N .
Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:   The graph is simple and connected.  There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S .   It can be proved that at least one such graph exists under the constraints of this problem.      Constraints  All values in input are integers.  3 \leq N \leq 100         Input Input is given from Standard Input in the following format:  N       Output In the first line, print the number of edges, M , in the graph you made. In the i -th of the following M lines, print two integers a_i and b_i , representing the endpoints of the i -th edge.  The output will be judged correct if the graph satisfies the conditions.        Sample Input 1 3      Sample Output 1 2
1 3
2 3   For every vertex, the sum of the indices of the vertices adjacent to that vertex is 3 .

Solution (Python):
n = int(input())
s = (n-1)*n//2

if n%2 == 1:

    g = [[] for _ in range(n)]
    for i in range(n):
        j = i+1
        if j != n:
            k = n-j
            
            for a in range(1, n+1):
                if a == j or a == k:
                    continue
                else:
                    if a > j:
                        g[i].append(a-1)
        
            
                
    
    cnt = 0
    edge = []
    for v in range(n):
        cnt += len(g[v])
        for u in g[v]:
            edge.append((v+1, u+1))
    print(cnt)
    for v, u in edge:
        print(v, u)

else:
    g = [[] for _ in range(n)]
    for i in range(n):
        j = i+1
        if j != n:
            k = n+1-j
            
            for a in range(1, n+1):
                if a == j or a == k:
                    continue
                else:
                    if a > j:
                        g[i].append(a-1)
    cnt = 0
    edge = []
    for v in range(n):
        cnt += len(g[v])
        for u in g[v]:
            edge.append((v+1, u+1))
    print(cnt)
    for v, u in edge:
        print(v, u)

Solution (Python):
N = int(input())

if N % 2 == 0:
    G = []
    G_append = G.append
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            if i + j != (1 + N):
                G_append((i, j))
    print (len(G))
    for g in G:
        print (*g, sep = ' ')
    
else:
    G = []
    G_append = G.append
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            if i + j != N:
                G_append((i, j))
    print (len(G))
    for g in G:
        print (*g, sep = ' ')

Solution (Python):
N = int(input())

if N % 2 == 0:
    edge = []
    for s in range(1, N + 1):
        ng = N - s + 1
        for t in range(1, N + 1):
            if s >= t or t == ng:
                continue
            edge.append((s, t))
else:
    edge = []
    for s in range(1, N + 1):
        ng = N - s
        for t in range(1, N + 1):
            if s >= t or t == ng:
                continue
            edge.append((s, t))

print(len(edge))
for s, t in edge:
    print(s, t)

Solution (Python):
n = int(input())
e = []
if n % 2 == 0:
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if i + j == n + 1:
                continue
            e.append([i, j])
else:
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            if i + j == n:
                continue
            e.append([i, j])
print(len(e))
for i in e:
    print(i[0],i[1])

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    Ans = []
    AnsNum = 0
    if N % 2 == 0:
        for i in range(1, N):
            for j in range(i + 1, N + 1):
                if i + j != N + 1:
                    Ans.append((i, j))
                    AnsNum += 1
    else:
        for i in range(1, N):
            for j in range(i + 1, N + 1):
                if i + j != N:
                    Ans.append((i, j))
                    AnsNum += 1
    print(AnsNum)
    for i in range(AnsNum):
        print(" ".join(map(str, Ans[i])))


    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
graph = [[0]*(n+1) for _ in range(n+1)]
if n%2 == 0:
  l = [[i,n-i+1] for i in range(1,n//2+1)]
else:
  l = [[i,n-i] for i in range(1,n//2+1)]+[[n]]
for i in range(len(l)):
  for j in l[i]:
    for k in range(1,n+1):
      if k not in l[i]:
        graph[j][k] = 1
ans = 0
l = []
for i in range(1,n):
  for j in range(i+1,n+1):
    if graph[i][j]:
      ans += 1
      l.append([i,j])
print(ans)
for lst in l:
  print(*lst)

Solution (Python):
n=int(input())
node=[[1]*n for _ in range(n)]
for i in range(n):
	node[i][i]=0
if n%2==0:
	for i in range(n//2):
		node[i][n-1-i]=0
		node[n-1-i][i]=0
else:
	for i in range(n//2):
		node[i][n-2-i]=0
		node[n-2-i][i]=0
ans=[]
for i in range(n):
	for j in range(i+1,n):
		if node[i][j]==1:
			ans.append((i,j))
print(len(ans))
for x,y in ans:
	print(x+1,y+1)

Solution (Python):
N=int(input())




ans = []
odd = (N%2 == 1)
def needs_edge(i,j,N,odd):
  if odd:
    if N-i == j:
      return False
  else:
    if N+1-i == j:
      return False
  return True

for i in range(1,N):
  for j in range(i+1,N+1):
    if needs_edge(i,j,N,odd):
      ans.append([i,j])

print(len(ans))
for a in ans:
  print(*a)

Solution (Python):
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    n = int(input())
    if n%2 == 0:
        ans = []
        m = n//2
        for i in range(1,m):
            ans.append((i,n - i))
            ans.append((i,i + 1))
            ans.append((i + 1,n - i + 1))
            ans.append((n - i,n - i + 1))
        
        if n > 4:
            ans.append((1,m))
            ans.append((1,m + 1))
            ans.append((m,n))
            ans.append((n,m + 1))
        
        print(len(ans))
        for i in range(len(ans)):
            print(*ans[i])
    
    else:
        if n == 3:
            ans = [[1,3],[2,3]]
            print(2)
            for i in range(2):
                print(*ans[i])
        else:
            ans = []
            m = n//2
            for i in range(1,m):
                ans.append((i,n - i - 1))
                ans.append((i,i + 1))
                ans.append((i + 1,n - i))
                ans.append((n - i,n - i - 1))
            
            ans.append((m,n))
            ans.append((m + 1,n))
            ans.append((1,n))
            ans.append((n,n - 1))

            print(len(ans))
            for i in range(len(ans)):
                print(*ans[i])

if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
graph = []
for i in range(1, n):
    for j in range(i + 1, n + 1):
        graph.append([i, j])
if n % 2 == 0:
    for i in range(n // 2):
        graph.remove([i + 1, n - i])
else:
    for i in range(n // 2):
        graph.remove([i + 1, n - i - 1])
print(len(graph))
for ans in graph:
    print(*ans)

Solution (Python):
n=int(input())
if n%2==0:
  print(n*(n-2)//2)
  for i in range(1,n):
    for j in range(i+1,n+1):
      if i+j==n+1:
        continue
      print(i,j)
else:
  print(n*(n-1)//2-(n-1)//2)
  for i in range(1,n):
    for j in range(i+1,n+1):
      if i+j==n:
        continue
      print(i,j)

Solution (Python):
from itertools import combinations
n=int(input())
A,B=[i+1 for i in range(n)],[]
num=n if n%2==1 else n+1
for a,b in combinations(A,2):
    if a+b!=num:B.append([a,b])
print(len(B))
for i in B:print(*i)

Solution (Python):
from itertools import combinations
n=int(input())
A=[i+1 for i in range(n)]
num=n if n%2==1 else n+1

B=[]
for a,b in combinations(A,2):
    if a+b!=num:B.append([a,b])

print(len(B))
for i in B:print(*i)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    n = II()
    ans = []
    tmp = [i for i in range(2, n + 1) if i != n - (n & 1)]
    l = 0
    r = n - 3 - (n & 1)
    for i in range(n // 2):
        ans.append(tmp[::1])
        tmp[l] -= 1
        tmp[r] += 1
        l += 1
        r -= 1
    ans += ans[::-1]
    l = []
    for i in range(1, n):
        for t in ans[i - 1]:
            if i < t:
                l.append((i, t))
    print(len(l))
    for li in l:
        print(*li)




    return



if __name__ == '__main__':
    solve()

Solution (Python):
N=int(input())
if N%2==1:
    hen=[]
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i+j!=N:
                hen.append([i,j])

    M=len(hen)
    print(M)
    for i in range(0,M):
        print(*hen[i])

else:
    hen=[]
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i+j!=N+1:
                hen.append([i,j])

    M=len(hen)
    print(M)
    for i in range(0,M):
        print(*hen[i])

Solution (Python):
from itertools import combinations as comb

N = int(input())
n = N-N%2
s = {(i, n+1-i) for i in range(1, N+1) if i<n+1-i}

l = [i for i in comb(range(1, N+1), 2) if not i in s]
print(len(l))
for i in l:
    print(*i)

Solution (Python):
from itertools import combinations as comb

N = int(input())
n = N-1 if N%2 else N
m = N if N%2 else N+1
s = {(i, n+1-i) for i in range(1, N+1) if i<n+1-i}

l = [i for i in comb(range(1, N+1), 2) if not i in s]
print(len(l))
for i in l:
    print(*i)

Solution (Python):
from itertools import combinations as comb

N = int(input())
n = N-1 if N%2 else N
s = set()

for i in range(1, N+1):
    if N%2:
        a, b = i, N-i
    else:
        a, b = i, N-i+1
    if a<b:
        s.add((a, b))

l = [i for i in comb(range(1, N+1), 2) if not i in s]
print(len(l))
for i in l:
    print(*i)

Solution (Python):

def Com(n, k):
    p, q = 1, 1
    for i in range(n-k+1, n+1):
        p *= i
    for i in range(2, k+1):
        q *= i
    return p//q

N = int(input())
print(Com(N, 2)-N//2)
if N & 1:
    for i in range(1, N):
        for j in range(i+1, N+1):
            if i+j != N:
                print(i, j)
else:
    for i in range(1, N):
        for j in range(i+1, N+1):
            if i+j != N+1:
                print(i, j)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    if(N&1):
        print((N+1)*(N-1)//2 -(N-1))
        pair = N-2
        for i in range(N):
            for j in range(i+1,N):
                if(i+j != pair):
                    print(i+1,j+1)
    else:
        print(N*(N-2)//2)
        pair = N-1
        for i in range(N):
            for j in range(i+1,N):
                if(i+j != pair):
                    print(i+1,j+1)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
edges = set()
X = 10**5
if N % 2 == 1:
    for i in range(N//2):
        i_ = i+1
        j_ = N-i-1
        
        edges.add(min(i_,j_)*X+max(j_,i_))
else:
    for i in range(N//2):
        i_ = i+1
        j_ = N-i
        
        edges.add(min(i_,j_)*X+max(j_,i_))
        


print(N*(N-1)//2-len(edges))
for i in range(N):
    for j in range(i+1,N):
        i_ = i+1
        j_ = j+1
        if i_*X + j_ in edges:
            continue
        else:
            print(i_,j_)

Solution (Python):
from itertools import combinations
n = int(input())
lst = [(i+1) for i in range(n)]
ans = []
for x,y in combinations(lst, 2):
    if n%2==0:
        if x+y==n+1:
            continue
    if n%2!=0:
        if x+y==n:
            continue
    ans.append((x,y))
print(len(ans))
for x,y in ans:
    print(x,y)

Solution (Python):
n = int(input())
out = []
ans = []
if n%2 == 0:
    for i in range(1,n//2+1):
        out.append([i, n-i+1])
else:
    for i in range(1, n//2+1):
        out.append([i,n-i])
for i in range(1,n+1):
    for j in range(i+1, n+1):
        if [i,j] not in out:
            ans.append([i,j])
print(len(ans))
for i in range(len(ans)):
    print(ans[i][0], ans[i][1])

Solution (Python):
n = int(input())

sum = (n // 2) * 2 + 1

ans = []

for i in range(1, n + 1):
	for j in range(i + 1, n + 1):
		if i + j != sum:
			ans.append([i, j])
print(len(ans))

for i in ans:
	print(i[0], i[1])

Solution (Python):
n = int(input())
g = [[1] * n for _ in range(n)]
for i in range(n-1 if n % 2 else n):
    j = n-i-2 if n % 2 else n-i-1
    g[i][j], g[j][i] = 0, 0
print((n*(n-1)//2)-n//2)
for i in range(n):
    for j in range(i+1, n):
        if g[i][j]: print(i+1, j+1)

Solution (Python):
n=int(input())
num=2*(n//2) + 1
ans=[]
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if i+j!=num:
            ans.append([i,j])
print(len(ans))
for a in ans:
    print(a[0],a[1])

Solution (Python):






n = int(input())
if n % 2 == 0:
    excluded_sum = n+1
else:
    excluded_sum = n

print(n*(n-1) // 2 - (excluded_sum-1) // 2)

for i in range(1, n+1):
    for j in range(i+1, n+1):
        if i+j == excluded_sum:
            continue
        else:
            print('{} {}'.format(i, j))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

if N%2 == 0:
	print(N*(N-2)//2)
	for i, j in combinations(range(1, N+1), 2):
		if i+j == N+1:
			continue
		print(i, j)

else:
	print(N*(N-1)//2-(N-1)//2)
	for i, j in combinations(range(1, N+1), 2):
		if i+j == N:
			continue
		print(i, j)

Solution (Python):
N = int(input())
M = N * (N - 1) // 2 - N // 2
S = N // 2 * 2 + 1

print(M)

for i in range(1, N):
    for j in range(i + 1, N + 1):
        if i + j == S:
            continue
        print(i, j)

Solution (Python):
n=int(input())
m=(n*(n-1)//2)-(n//2)
print(m)
x=n+1-n%2
for i in range(1,n):
    for j in range(i+1,n+1):
        if i+j!=x:
            print(i,j)

Solution (Python):
"""from collections import *
from itertools import
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys



"""
import copy
from collections import *
from heapq import *
N=int(input())

lst=[]

if N%2==0:
    for i in range(N-1):
        for m in range(i+1,N):
            if m !=(N-i-1):
                lst.append([i,m])
else:
    for i in range(N):
        for m in range(i+1,N):
            if m !=(N-i-2):
                lst.append([i,m])
print(len(lst))
for a,b in lst:
    print(a+1,b+1)

Solution (Python):
N = int(input())
ans = []
if N % 2 == 0:
    for i in range(1, N):
        for j in range(i+1, N+1):
            if j == (N + 1 - i):
                continue
            ans.append((i, j))
else:
    for i in range(1, N):
        for j in range(i+1, N+1):
            if j == (N - i):
                continue
            ans.append((i, j))
print(len(ans))
for x in ans:
    print(*x)

Solution (Python):
def main():
    n = int(input())
    if n % 2 == 0:
        ans = []
        for i in range(1, n//2):
            ans.append([i, i+1])
            ans.append([i, n-i])
            ans.append([n-i+1, i+1])
            ans.append([n-i+1, n-i])
        if n >= 6:
            ans.append([1, n//2])
            ans.append([1, n//2+1])
            ans.append([n, n//2])
            ans.append([n, n//2+1])
        print(len(ans))
        for p, q in ans:
            print(p, q)
    else:
        ans = []
        n -= 1
        for i in range(1, n//2):
            ans.append([i, i+1])
            ans.append([i, n-i])
            ans.append([n-i+1, i+1])
            ans.append([n-i+1, n-i])
        ans.append([1, n+1])
        ans.append([n, n+1])
        if n >= 4:
            ans.append([n//2, n+1])
            ans.append([n//2+1, n+1])
        print(len(ans))
        for p, q in ans:
            print(p, q)

if __name__ == "__main__":
    main()

Solution (Python):



n = int(input())
ans = []
if n % 2 == 0:
    for i in range(1,n+1):
        for j in range(i,n+1):
            
            if j != i and i + j != n + 1:
                ans.append([i,j])
    print(len(ans))
    for i in range(len(ans)):
        print("{} {}".format(ans[i][0], ans[i][1]))
else:
    for i in range(1,n):
        
        ans.append([n,i])
        for j in range(i,n):
            
            if j != i and i + j != n:
                ans.append([i,j])
    print(len(ans))
    for i in range(len(ans)):
        print("{} {}".format(ans[i][0], ans[i][1]))

Solution (Python):
N=int(input())
A=[]
B=[]
if N%2==0:
  for i in range(1,N):
    for j in range(i+1,N+1):
      A.append((i,j))
  for i in range(N//2):
    B.append((i+1,N-i))
  D=set(A)-set(B)
  print(len(D))
  for a,b in D:
    print(a,b)
else:
  for i in range(1,N):
    for j in range(i+1,N+1):
      A.append((i,j))
  for i in range(N//2):
    B.append((i+1,N-i-1))
  D=set(A)-set(B)
  print(len(D))
  for a,b in D:
    print(a,b)

Solution (Python):
N = int(input())
edges = []
for i in range(1, N // 2 + 1):
    j = N - i + 1 - N % 2
    for k in range(1, N+1):
        if k == i or k == j:
            continue
        if i < k:
            edges.append((i, k))
        if j < k:
            edges.append((j, k))
print(len(edges))
for a, b in edges:
    print(a, b)

Solution (Python):
from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
tmp = n-1 if n%2 else n
m = (n**2 - (n+tmp))//2
print(m)
for i in range(1,n+1):
    for j in range(1,n+1):
        if i == j or i>j : continue
        if i+j == tmp+1: continue
        print(i,j)

Solution (Python):
"""
・偶奇に分けて考える
・完全グラフと正解のグラフを比較する
・「任意の頂点」と「その頂点から削除する辺」の関係を考える

偶数
-> 和が(N+1)となる頂点を繋いでいない
奇数
-> 頂点Nからは全て引く。
-> それ以外は、和がNとなる頂点を繋いでいない。
"""

N = int(input())

M = 0
ans = []



if N % 2 == 0:
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            if i + j != N + 1:
                ans.append((i, j))
                M += 1
else:
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            if i + j != N:
                ans.append((i, j))
                M += 1

print(M)
for i, j in ans:
    print(i, j)

Solution (Python):


N = int(input())

M = 0
ans = []



if N % 2 == 0:
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            if i + j != N + 1:
                ans.append((i, j))
                M += 1
else:
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            if i + j != N:
                ans.append((i, j))
                M += 1

print(M)
for i, j in ans:
    print(i, j)

Solution (Python):
def solve():
    N = int(input())
    M = 0
    Ans = []
    if N % 2 == 0:
        for i in range(1, N):
            for j in range(i + 1, N + 1):
                if i + j != N + 1:
                    Ans.append([i, j])
                    M += 1
    else:
        for i in range(1, N):
            for j in range(i + 1, N + 1):
                if i + j != N:
                    Ans.append([i, j])
                    M += 1
    print(M)
    for i, j in Ans:
        print(i, j)


    return 0

if __name__ =="__main__":
    solve()

Solution (Python):
a=[]
n=int(input())
m=n
if n%2==0:
    m+=1
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if i+j!=m:
            b=(i,j)
            a.append(b)
print(len(a))
for i in a:
    print(str(i[0])+" "+str(i[1]))

Solution (Python):
N=int(input())

ans=[]
for i in range(1,N//2*2+1):
    for j in range(i+1,N//2*2+1):
        if j==N//2*2-i+1:
            continue
        else:
            ans.append([i,j])
if N%2==1:
    for i in range(1,N):
        ans.append([i,N])

print(len(ans))
for item in ans:
    print(*item)

Solution (Python):
n = int(input())

print( n*(n-1)//2 - n//2)

com = []

if (n%2 == 1):
    com.append([n])
    n -= 1
for i in range(1,1+n//2):
    com.append([i,n+1-i])

for i in range(len(com) - 1):
    for j in com[i]:
        for k in com[i+1 : ]:
            for l in k:
                print('{} {}'.format(j,l))

Solution (Python):
N=int(input())
V=[[i,N//2*2-i+1] for i in range(1,N//2+1)]
if N&1:
    V+=[[N]]
E=[]
for u in range(len(V)):
    for v in range(len(V)):
        if u!=v:
            for x in V[u]:
                for y in V[v]:
                    if x<y:
                        E.append((x,y))
print(len(E))
for x,y in E:
    print(x,y)

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
if n%2==0:
    print(n*(n-2)//2)
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i+j!=n+1:
                print("{} {}".format(i,j))
if n%2==1:
    print((n-1)*(n-1)//2)
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i+j!=n:
                print("{} {}".format(i,j))

Solution (Python):
N = int(input())

print(N*(N-1)//2-N//2)
if N%2 == 1:
    for i in range(1, N):
        for j in range(i+1, N+1):
            if i == N-j:
                continue
            print(i, j)
else:
    for i in range(2, N):
        print(1, i)
        print(N, i)
    for i in range(2, N):
        for j in range(i+1, N):
            if i+j == N+1:
                continue
            print(i, j)

Solution (Python):
N = int(input())





S = set()
for i in range(1,N):
  for j in range(i+1,N+1):
    S.add((i,j))
    

if N%2 == 0:
  for i in range(1,N+1):
    if i >= N-i+1:
      break
    S.remove((i,N-i+1))
    
else:
  for i in range(1,N):
    if i >= N-i:
      break
    S.remove((i,N-i))
    
print(len(S))
for item in S:
  print(" ".join(list(map(str, item))))

Solution (Python):
N=int(input())

G=[[] for i in range(N+1)]

if N%2==0:
    S=N+1
else:
    S=N

cnt=0

for i in range(1,N+1):
    for j in range(i+1,N+1):
        if i+j != S:
            G[i].append(j)
            cnt+=1

print(cnt)
for i in range(1,N+1):
    for j in range(len(G[i])):
        print(i,G[i][j])

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



N = I()

edges = []
if N%2==0:
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i+j==N+1:
                continue
            else:
                edges.append((i,j))
else:
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i+j==N:
                continue
            else:
                edges.append((i,j))

print(len(edges))
for e in edges:
    print(*e)

Solution (Python):
N = int(input())
ans = []
if N % 2 == 0:
    
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i + j == N+1:
                continue
            ans.append((i, j))
else:
    
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i + j == N:
                continue
            ans.append((i, j))

print(len(ans))
for s, t in ans:
    print(s, t)

Solution (Python):
import sys
bbn=1000000007
	


def mk_path(a_i, max_n, ret):
	
	
	
	off=0 if max_n % 2 == 1 else 1
	
	for i in range(a_i+1, max_n+1):
		if i == max_n - a_i + off:
			continue
		else:
			ret.append((a_i, i))
			
	return 
	
def check_constraint(graph, n):
	cc=[0]*n
	for f,t in graph:
		cc[f-1] += t
		cc[t-1] += f
	
	pa(('max:',max(cc),', min:', min(cc) ))
	return
	
		
def main():
	n = int(input())
	ret=[]
	for i in range(1,n+1):
		mk_path(i,n,ret)
	
	
	print(len(ret))
	for f,t in ret:
		pass
		print(f,t)

	
	

isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):



N = int(input())

edge_num = 0
for i in range(N-1,0,-1):
    edge_num += i

edge_num -= N//2 

"""
Nが偶数の場合、1とNの間にある辺、2とN-1の間にある辺、......を外していく
Nが奇数の場合、1とN-1の間にある辺、2とN-2の間にある辺、......を外していく
"""
print(edge_num)
for i in range(1, N):
    for j in range(i+1,N+1):
        if N % 2 == 0:
            if i + j == N+1:
                continue
        else:
            if i+ j == N:
                continue
        print(i,j)

Solution (Python):
N = int(input())
A = []
if N%2==0:
    for i in range(1,N):
        for j in range(i+1,N+1):
            if j!=N+1-i:
                A.append((i,j))
else:
    for i in range(1,N):
        for j in range(i+1,N+1):
            if j!=N-i:
                A.append((i,j))
print(len(A))
for a in A:
    print(a[0],a[1])

Solution (Python):
n = int(input())
b = n%2
print(n*(n-1)//2 - n//2)
for i in range(1, n):
  for j in range(i+1, n+1):
    if i+j+b != n+1:
      print(i, j)

Solution (Python):
N = int(input())

answer = []
for i in range(1, N + 1):
  for j in range(i + 1, N + 1):
    if N % 2 and i + j != N:
      answer.append((i, j))
    if N % 2 == 0 and i + j != N + 1:
      answer.append((i, j))

print(len(answer))
for a in answer:
  print(*a)

Solution (Python):
N = int(input())

print(N*(N-1)//2-N//2)
for i in range(1, N):
    for j in range(i+1, N+1):
        if N % 2 == 0:
            if i+j != N+1:
                print(i, j)
        else:
            if i+j != N:
                print(i, j)

Solution (Python):
import sys

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  
rs = lambda: stdin.readline().rstrip()  

N = ri()
answer_list = []
pair = N if N&1 else N+1
for i in range(1, N):
    for j in range(i+1, N+1):
        if i+j == pair:
            continue
        else:
            answer_list.append((i, j))

print(len(answer_list))
for x in answer_list:
    print(*x)

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    ans = []
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            m = n if n & 1 else n + 1
            if i + j != m:
                ans.append((i, j))
    print(len(ans))
    for i, j in ans:
        print(i, j)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
ans=[]
if N%2==0:
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i+j==N+1:
                continue
            ans.append([i,j])
else:
    for i in range(1,N):
        for j in range(i+1,N):
            if i+j==N:
                continue
            ans.append([i,j])
    for i in range(1,N):
        ans.append([i,N])
print(len(ans))
for u in ans:
    print(*u)

Solution (Python):
n = int(input())

pairs = [[i for i in range(1, n + 1)] for _ in range(n)]

ans = []
if n % 2 == 0:
    for i in range(n-1):
        for j in range(i + 1, n):
            x = pairs[i][j]
            if x == n - i:
                continue
            ans.append((i + 1, x))
else:
    for i in range(n-1):
        for j in range(i + 1, n):
            x = pairs[i][j]
            if x == n - i-1:
                continue
            ans.append((i + 1, x))

print(len(ans))
for x, y in ans:
    print(x, y)

Solution (Python):
n=int(input())
m=n//2*2
ans=[]
for i in range(1,m//2):
  for j in range(1+i,m-i+1):
    ans.append((i,j))
    ans.append((m+1-j,m+1-i))
if n%2:
  for i in range(1,n):
    ans.append((i,n))
print(len(ans))
for i in ans:
  print(*i,sep=" ")

Solution (Python):
n=int(input())
E=[]
if n%2==0:
  s=n+1
else:
  s=n
for i in range(1,n):
  for j in range(i+1,n+1):
    if i+j==s:
      continue
    else:
      E.append((i,j))
print(len(E))
for i,j in E:
  print(i,j)

Solution (Python):
import copy
N=int(input())
n=(N//2)*2
g=[set() for i in range(N)]
tmp={i for i in range(n)}
for i in range(n):
  g[i]=copy.copy(tmp)
  g[i].remove(i)
  g[i].remove(n-1-i)
count=0
if N%2!=0:
  g[N-1]=copy.copy(tmp)
  for i in range(N-1):
    g[i].add(N-1)
for i in range(N):
  count+=len(g[i])
print(count//2)

for i in range(N):
  for x in g[i]:
    print(i+1,x+1)
    g[x].remove(i)

Solution (Python):
n = int(input())
if n % 2 == 0:
    n_edges = n * (n-1) // 2 - n // 2
    print(n_edges)
    for i in range(n - 1):
        for j in range(i + 1, n):
            if i + j + 2 == n + 1:
                continue
            else:
                print(i + 1, j + 1)
else:
    n_edges = n * (n - 1) // 2 - n // 2
    print(n_edges)
    for i in range(n - 1):
        for j in range(i + 1, n):
            if i + j + 2 == n:
                continue
            else:
                print(i + 1, j + 1)

Solution (Python):
n = int(input())
a = []
b = []
for i in range(n):
  for j in range(i+1, n):
    a.append([i+1, j+1])
if n % 2 == 0:
  for i in range(len(a)):
    if a[i][0] + a[i][1] != n + 1:
      b.append(a[i])
else:
  for i in range(len(a)):
    if a[i][0] + a[i][1] != n:
      b.append(a[i])
m = len(b)
print(m)
for i in range(m):
  print(b[i][0], b[i][1])