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):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
count = 0
print(nCr(N,2)-N//2)
for i in range(1,N+1):
  for j in range(1,N+1):
    if i+j != N+(1-N%2) and i<j:
      print(i,j)

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

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

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

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:
                print(i, j)
else:
    print((N - 1) ** 2 // 2)
    for i in range(1, N-1):
        for j in range(i+1, N):
            if i + j != N:
                print(i, j)
    for i in range(1, N):
        print(i, N)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    res = []
    c = n
    if n % 2 != 0:
        c -= 1

    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if j == c:
                continue
            res.append([i, j])
        c -= 1

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


if __name__ == '__main__':
    resolve()

Solution (Python):
n = int(input())
x = n % 2

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

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

Solution (Python):
N = int(input())
tmp = N
ans = []
if tmp%2 == 1:
    tmp -= 1
for i in range(1,tmp+1):
    for j in range(1,tmp+1):
        if i < j and j != tmp+1-i:
            ans.append((i,j))
if N%2 == 1:
    for i in range(1,N):
        ans.append((i,N))
print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

Solution (Python):
n = int(input())
d = n
ans = []
if n % 2 == 1: d -= 1

for i in range(1, n+1):
    for j in range(1, n+1):
        if j <= i or j == d: continue
        ans.append([i, j])
    d -= 1

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

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

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

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

res = set()
for i in range(len(g)):
    for j in range(len(g)):
        if i==j:
            continue
        for v in g[i]:
            for u in g[j]:
                res.add((min(v,u),max(v,u)))
print(len(res))
for v,u in res:
    print(v,u)

Solution (Python):
from itertools import combinations
n = int(input())
x = n if n % 2 else n+1
ans = []
for v, v2 in combinations(range(1, n+1), 2):
    if v+v2 == x:
        continue
    ans.append((v, v2))
print(len(ans))
for edge in ans:
    print(*edge)

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

Solution (Python):
N = int(input())
ans = set()
for i in range(1, N+1):
  for j in range(i+1, N+1):
    ans.add((i, j))

if N % 2 == 1: 
  for i in range(1, N+1):
    j = N - i
    ans.discard((i, j))
else: 
  for i in range(1, N+1):
    j = N + 1 - i
    ans.discard((i, j))

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

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 i + j != n+1:
                ans.append([i,j])
if n % 2 == 1:
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i + j != n:
                ans.append([i,j])    
print(len(ans))
for i in ans:
    print(*i)

Solution (Python):


import math



from collections import deque




n=int(input())
node=[]
if n%2==0:
    for i in range(n):
        for j in range(i,n):
            if j==i or j==n-1-i:
                continue
            node.append((i+1,j+1))
else:
    for i in range(n):
        for j in range(i,n):
            if j==i or j==n-2-i:
                continue
            node.append((i+1,j+1))
    
print(len(node))
for i in node:
    print(*i)

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

Solution (Python):
def main():
    N = int(input())
    edges = []
    M = 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 + j != N:
                    edges.append((i, j))
    else:
        for i in range(1, N):
            for j in range(i+1, N+1):
                if i + j != N + 1:
                    edges.append((i, j))
    print(M)
    for a, b in edges:
        print(a, b)
if __name__ == "__main__":
    main()

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ho={}
  if n%2==0:
    for i in range(1,n//2+1):
      ho[str(i)+'-'+str(n-i+1)]=0
  else:
    for i in range(1,n//2+1):
      ho[str(i)+'-'+str(n-i)]=0

  

  ans=[]
  for i in range(1,n+1):
    for j in range(1,n+1):
      if i<=j:
        break

      pair=str(j)+'-'+str(i)
      if pair in ho:
        continue

      ans.append((j,i))

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

main()

Solution (Python):
n = int(input())
if n % 2 == 0:
    k = 1+n
    s = k*(n//2-1)
else:
    k = n
    s = k*(n//2)

ans = []
for i in range(1, n+1):
    for j in range(i+1, n+1):
        if i+j == k:
            continue
        ans.append("{} {}".format(i, j))
print(len(ans))
print(*ans, sep='\n')

Solution (Python):
N = int(input())
even = True if N % 2 == 0 else False
print(N*(N-1)//2-N//2)
for i in range(1, N):
  for j in range(i+1, N+1):
    if even and i + j != N+1 or not even and i + j != N:
      print(i, j)

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

if N%2==1:
    L = [[N]]
    for i in range(1,N//2+1):
        L.append([i,N-i])
else:
    L = []
    for i in range(1,N//2+1):
        L.append([i,N-i+1])
LN = len(L)
M = []
for i in range(LN):
    A = L[i]
    for j in range(i+1,LN):
        B = L[j]
        for Ai in A:
            for Bi in B:
                M.append([Ai,Bi])

MN = len(M)
print(MN)
for i in range(MN):
    print(M[i][0],M[i][1])

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

Solution (Python):
def main():
    N = int(input())
    ans = set()
    if N % 2 == 0:
        for i in range(1,N+1):
            k = N - i + 1
            for j in range(1,N+1):
                if j == k or j == i:
                    continue
                if j > k:
                    ans.add((k,j))
                else:
                    ans.add((j,k))
                if j > i:
                    ans.add((i,j))
                else:
                    ans.add((j,i))
    else:
        for i in range(1,N):
            ans.add((i,N))
        for i in range(1,N):
            k = N - i
            for j in range(1,N+1):
                if j == k or j == i:
                    continue
                if j > k:
                    ans.add((k,j))
                else:
                    ans.add((j,k))
                if j > i:
                    ans.add((i,j))
                else:
                    ans.add((j,i))
    print(len(ans))
    for i, j in ans:
        print(i,j)        

if __name__ == "__main__":
    main()

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    l = []
    if n%2 == 0:
        for i in range(1,n+1):
            for j in range(i+1,n+1):
                if i == j or i+j == n+1:
                    continue
                else:
                    l.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:
                    l.append((i,j))
    print(len(l))
    for i,j in l:
        print(i,j)
    return

if __name__ == '__main__':
    main()

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

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

out = []
l = len(g)
for i in range(l):
    for j in range(i+1, l):
        out.extend((gi, gj) for gi in g[i] for gj in g[j])
print(len(out))
for o in out:
    print(o[0], o[1])

Solution (Python):
from itertools import combinations
n=int(input())
print(n*(n-1)//2-n//2)
for i in combinations(range(1,n + 1),2):
    if i[0]+i[1]!=n-n%2+1:
        print(i[0],i[1])

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

if n % 2 == 0:
    pairs = [(i, n+1-i) for i in range(1, n//2+1)]
    x = len(pairs)
    if n == 4:
        print(4 * (x - 1))
        for i in range(2):
            for j in range(2):
                print(pairs[0][i], pairs[1][j])
    else:
        print(4 * x)
        for k in range(n//2):
            for i in range(2):
                for j in range(2):
                    print(pairs[k%x][i], pairs[(k+1)%x][j])

else:
    pairs = [(i, n-i) for i in range(1, n//2+1)]
    x = len(pairs)
    if n == 3:
        print(2)
        print(1, 3)
        print(2, 3)
    else:
        print(4 * x)
        for k in range(n//2-1):
            for i in range(2):
                for j in range(2):
                    print(pairs[k % x][i], pairs[(k+ 1) % x][j])
        print(n, pairs[0][0])
        print(n, pairs[0][1])
        print(n, pairs[-1][0])
        print(n, pairs[-1][1])

Solution (Python):
from itertools import combinations

N = int(input())

k = N // 2
s = N + 1 - N % 2
print(N * (N - 1) // 2 - k)
for p in combinations(range(1, N + 1), 2):
    if sum(p) == s:
        continue
    print(p[0], p[1])

Solution (Python):
N=int(input())
sets=[]
if N%2==1:
    sets.append([N])
    for i in range(1,N//2+1):
        sets.append([i,(N-i)])
else:
    for i in range(1,N//2+1):
        sets.append([i,N+1-i])

path=[]
for i in range(len(sets)):
    for j in range(i+1,len(sets)):
        for k in sets[i]:
            for l in sets[j]:
                path.append([min(k,l),max(k,l)])

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

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 i+j!=n+1:
                ans.append([i,j])
else:
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i+j!=n:
                ans.append([i,j])
print(len(ans))
for i,j in ans:
    print(i,j)

Solution (Python):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    ans = []
    for i in range(1,N):
        for j in range(i+1,N+1):
            if not j == (N - i + (N%2==0)):
                ans.append((i,j))
    print(len(ans))
    for x in ans:
        print(x[0],x[1])


if __name__ == '__main__':
    main()

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

l = list(range(1, n+1))
s = sum(l)
graph = []
graph_set = set()
cnt = 0

if n % 2 == 0:
    for i in range(1, n+1):
        for j in range(1, n+1):
            if i + j == n + 1:
                continue
            elif i == j:
                continue
            else:
                if (i, j) not in graph_set:
                    graph.append([i, j])
                    graph_set.add((i, j))
                    graph_set.add((j, i))
                    cnt += 1

else:
    for i in range(1, n+1):
        for j in range(1, n+1):
            if i + j == n:
                continue
            elif i == j:
                continue
            else:
                if (i, j) not in graph_set:
                    graph.append([i, j])
                    graph_set.add((i, j))
                    graph_set.add((j, i))
                    cnt += 1

print(cnt)
for i, j in graph:
    print(i, j)

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

sm = n*(n+1)//2
if n == 3:
  print(2)
  print(1, 3)
  print(2, 3)
elif n == 4:
  print(4)
  print(1, 2)
  print(1, 3)
  print(2, 4)
  print(3, 4)
elif n % 2:
  m = (n-1)//2
  print(m*4)
  a = [[i, n-i-2] for i in range(m)]
  for i in range(m-1):
    for j in range(2):
      for k in range(2):
        print(a[i][j]+1, a[i+1][k]+1)
  for i in range(2):
    print(a[m-1][i]+1, n)
    print(n, a[0][i]+1)
else:
  print(n*2)
  a = [[i, n-i-1] for i in range(n//2)]
  for i in range(n//2):
    for j in range(2):
      for k in range(2):
        print(a[i][j]+1, a[(i+1)%(n//2)][k]+1)

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

ans = []
r = n
if n % 2 == 0:
  r = n+1
      
for i in range(n):
  for j in range(i+1,n):
    if i+j+2 == r:
      continue
    ans.append([i+1,j+1])
      
print(len(ans))
for a in ans:
  print(*a)

Solution (Python):

import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N = int(input())
edge = []
if N&1:
    cnt = 0
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i+j != N:
                edge.append((i,j))
                cnt += 1

else:
    cnt = 0
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i+j != N+1:
                edge.append((i,j))
                cnt += 1

print(cnt)
for u,v in edge:
    print(u,v)

Solution (Python):
n = int(input())
ans = set()
if n%2 == 1:
  for i in range(1,n):
    ans.add((i,n))
  n -= 1
if n%2 == 0:
  chk = [[] for i in range(n//2)]
  for i in range(1,n//2+1):
    chk[i-1].append(i)
    chk[i-1].append(n+1-i)
  for i in range(n//2-1):
    for j in range(2):
      a = chk[i][j]
      for k in range(i+1,n//2):
        b = chk[k][0]
        c = chk[k][1]
        if a < b:
          ans.add((a,b))
        else:
          ans.add((b,a))          
        if a < c:
          ans.add((a,c))
        else:
          ans.add((c,a))
          

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

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

g = [[1] * (n + 1) for _ in range(n + 1)]

if n % 2:
    for i in range(1, n + 1):
        j = n - i
        g[i][j] = 0
        g[j][i] = 0

else:
    for i in range(1, n + 1):
        j = n + 1 - i
        g[i][j] = 0
        g[j][i] = 0

ans = []
for i, row in enumerate(g[1:], 1):
    for j, bl in enumerate(row[i+1:], i+1):
        if bl:
            ans.append((i, j))

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

Solution (Python):

"""
まずnが偶数の場合を考える。
1...nの数列を考えた時に、
1+n,2+n-1,3+n-2…を１頂点として考えると、全てその値が等しいグラフになる。
次に奇数の場合を考える。
n-1までのグラフを偶数の場合と同じように構築した後、
nはn-1までの2頂点の合計と等しい値になる。
よって、最後に全頂点をnとつなぎ合わせると条件を満たすグラフに成る。
"""
import sys
from collections import defaultdict
dic1 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
ans = []
mid = 1+(n//2)*2
for i in range(1,(n//2)*2+1):
    dic1[i] = mid-i
for i in range(1,(n//2)*2):
    res = dic1[i]
    for j in range(i+1,(n//2)*2+1):
        if j == res:
            continue
        ans.append([i,j])

if not even(n):
    for i in range(1,n):
        ans.append([i,n])

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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 j==n-i:continue
                print(i,j)
    else:
        for i in range(1,n):
            for j in  range(i+1,n+1):
                if j==n-i+1:continue
                print(i,j)        

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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 j==n-i:continue
                print(i,j)
    else:
        for i in range(1,n):
            for j in  range(i+1,n+1):
                if j==n-i+1:continue
                print(i,j)        

if __name__=='__main__':
    main()

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

Solution (Python):
N = int(input())
from itertools import groupby, accumulate, product, permutations, combinations
def solve(N):
    pairs = []
    if N%2==1: 
        total = N
        pairs.append([N])
        ans = N-1
    else: 
        total = N+1
        ans = 0
    for i in range(1,(total+1)//2):
        pairs.append([i,total-i])
        ans += 2*(N-2)
    print(ans//2)
    for pair1, pair2 in combinations(pairs,2):
        for i in pair1:
            for j in pair2:
                print(i,j)
    return
solve(N)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

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

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

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

Solution (Python):


N = int(input())


if N % 2 == 0:
    print(N*(N-1)//2 - N // 2)
    for i in range(1, N+1):
        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+1):
        for j in range(i+1, N+1):
            if i+j == N:
                continue
            print(i,j)

Solution (Python):



N = int(input())
G = [[1 for _ in range(101)] for _ in range(101)]
for i in range(101): G[i][i] = 0
groups = []

if N % 2 == 1:
    for i in range(1, N // 2 + 1):
        
        G[i][N - i] = G[N - i][i] = 0
    
else:
    for i in range(1, N // 2 + 1):
        G[i][N - i + 1] = G[N - i + 1][i] = 0
        

M = 0
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        if G[i][j] == 1:
            M += 1


print(M)
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        if G[i][j] == 1:
            print(i, j)

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    answer = []
    if N % 2 == 1:
        for i in range(1, N):
            answer.append((N, i))
        for j in range(1, N):
            for k in range(j + 1, N):
                if j + k == N:
                    continue
                else:
                    answer.append((j, k))
    else:
        for i in range(2, N):
            answer.append((N, i))
            answer.append((1, i))
        for j in range(2, N):
            for k in range(j + 1, N):
                if j + k == N + 1:
                    continue
                else:
                    answer.append((j, k))
    M = len(answer)
    print(M)
    for i in range(M):
        print(*answer[i], sep=" ")


if __name__ == "__main__":
    main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())

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

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


if __name__ == "__main__":
    main()

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))

d = set()
if N % 2 == 0:
    for i in range(1,N//2+1):
        d.add((i, N-i+1))
else:
    for i in range(1,N//2+1):
        d.add((i, N-i))

r = S.difference(d)

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

Solution (Python):
n = int(input())
no_group = []
if n % 2 ==0:
  for  i in range(1,n//2+1):
    no_group.append([i,n-i+1])
else:
  for i in range(1,n//2+1):
    no_group.append([i,n-i])
  no_group.append([n])
  
sub_list = [[0 for i in range(n)] for i in range(n)]
for g in no_group:
  if len(g) == 2:
    sub_list[g[0]-1][g[1]-1] = 1
    sub_list[g[1]-1][g[0]-1] = 1
ans_list = []
for i in range(n):
  for j in range(i,n):
    if i != j and sub_list[i][j] == 0:
      ans_list.append([i+1,j+1])
      
print(len(ans_list))
for ans in ans_list:
  print(*ans)

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

Solution (Python):
n = int(input())
x = [i + 1 for i in range(n - (n % 2))]
y = [[x[i], x[len(x) - i - 1]] for i in range(len(x) // 2)]
ans = []
for i in range(len(y) - 1):
    for j in range(2):
        for k in range(2):
            ans.append([y[i][j], y[i + 1][k]])
if n == 3:
    ans = [[1, 3], [2, 3]]
elif n == 4:
    ans = [[1, 2], [1, 3], [2, 4], [3, 4]]
elif n % 2 == 1:
    for i in range(len(x) - 1, len(x) + 1):
        for j in range(2):
            ans.append([y[i % len(y)][j], n])
else:
    for i in range(2):
        for j in range(2):
            ans.append([y[len(y) - 1][i], y[0][j]])
print(len(ans))
for ans0 in ans:
    print(" ".join(map(str, ans0)))

Solution (Python):
n = int(input())
if n == 3:
  print(2)
  print(1, 3)
  print(2, 3)
else:
  ans = []
  core = [n//2-1, n//2, n//2+1, n//2+2]
  for i in range(4):
    for j in range(i+1, 4):
      if i+j != 3:
        ans.append((core[i], core[j]))
  key = n//2-2
  for i in range(key, 0, -1):
    key2 = 2*n//2-i+1
    if n%2:
      key2 -= 1
    for c in core:
      ans.append((i, c))
      ans.append((c, key2))
    core.append(i)
    core.append(key2)
    
  if n%2:
    for c in core:
      ans.append((c, n))
  print(len(ans))
  for a in ans:
    print(*a)

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

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 j!= (N-i+1):
                ans.append([i,j])

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

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

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

n = N // 2
S = N + (N % 2 == 0)

groups = [[i, S - i] for i in range(1, n + 1)]

if N % 2 == 1:
    groups.append([S])

ans = []

from itertools import *

for g1, g2 in combinations(groups, 2):
    for s, t in product(g1, g2):
        ans.append((s, t))

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

Solution (Python):
N = int(input())
ans = []
if N%2 == 0:
    for k in range(1,N):
        for l in range(k+1,N+1):
            if k+l != N+1:
                ans.append([k,l])
else:
    for k in range(1,N):
        for l in range(k+1,N+1):
            if k+l != N:
                ans.append([k,l])
print(len(ans))
for e in ans:
    print(*e)

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

V = set()

if N % 2 == 0:
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            if i + j == N + 1:
                V.add((i, j))
else:
    for i in range(1, N):
        for j in range(i + 1, N):
            if i + j == N:
                V.add((i, j))

ans = []
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        if not (i, j) in V:
            ans.append((i, j))

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

Solution (Python):
def main():
    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:
                    ans.append((i, j))
    else:
        for i in range(1, N+1):
            for j in range(i+1, N+1):
                if i+j != N:
                    ans.append((i, j))
    print(len(ans))
    for a in ans:
        print(*a)


if __name__ == '__main__':
    main()

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    t=0
    if N%2==0:
        t=1+N
    else:
        t=N
        
    ans=[]
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i+j!=t:
                ans.append([i,j])
    print(len(ans))
    for i in range(len(ans)):
        print(' '.join(map(str, ans[i])))
    


main()