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 math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=998244353
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()
  ans=set()
  if n%2==0:
    for i in range(n):
      for j in range(i+1,n):
        if i==j:
          continue
        if n+1==(i+1)+(j+1):
          continue
        ans.add((i+1,j+1))
  else:
    for i in range(n):
      for j in range(i+1,n):
        if i==j:
          continue
        if n==(i+1)+(j+1):
          continue
        ans.add((i+1,j+1))
  print(len(ans))
  for x,y in ans:
    print(x,y)

main()

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

Solution (Python):
n=int(input())
ans=[]
s=n+1-n%2
for i in range(1,n+1-n%2):
  for j in range(i+1,n+1-n%2):
    if i+j==s:
      continue
    ans.append(str(i)+" "+str(j))
if n%2:
  for i in range(1,n):
    ans.append(str(i)+" "+str(n))
print(len(ans))
print("\n".join(ans))

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

if n%2==0:
    m=n*(n-1)//2-n//2
    print(m)
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if i+j==n+1:
                continue
            print('{} {}'.format(i,j))
else:
    m=n*(n-1)//2-(n-1)//2
    print(m)
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if i+j==n:
                continue
            print('{} {}'.format(i,j))

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

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

num = n + (n % 2 == 0)
cnt, ans = 0, []
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        if i + j != num:
            cnt += 1
            ans.append((i, j))

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

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

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

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

Solution (Python):
def main():
    import itertools
    n = int(input())
    if n%2==0:
        rm = n+1
    else:
        rm = n
    ans = []
    for t in itertools.combinations((i+1 for i in range(n)), 2):
        if sum(t)!=rm:
            ans.append(t)
    print(len(ans))
    for a in ans:
        print(a[0],a[1])

if __name__ == "__main__":
    main()

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

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

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

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


if N % 2 == 1:
  ban = N
else:
  ban = N + 1


for i in range(1,N):
  for j in range(i+1,N+1):
    if i + j != ban:
      print(i,j)

Solution (Python):
n=int(input())
m=n-n%2+1
d=[[i+j+2!=m and i!=j for i in range(n)] for j in range(n)]
print(sum([sum(i) for i in d])//2)
for i in range(n):
  for j in range(i+1,n):
    if d[i][j]:print(i+1,j+1)

Solution (Python):
def main():
    n = int(input())
    ans = []
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i == j or i + j == n + (n + 1) % 2:
                continue
            ans.append([i, j])
    print(len(ans))
    for a in ans:
        print(" ".join(map(str, a)))


if __name__ == '__main__':
    main()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    
    
    ans = []

    def f(n):
        for i in range(1, n // 2 + 1):
            for j in range(1, n + 1):
                if j != i and j != n + 1 - i:
                    if j < i:
                        ans.append((j, i))
                    else:
                        ans.append((i, j))
                    if j < n + 1 - i:
                        ans.append((j, n + 1 - i))
                    else:
                        ans.append((n + 1 - i, j))

    if N % 2 == 0:
        f(N)
    else:
        if N >= 5:
            f(N - 1)
        for i in range(1, N):
            ans.append((i, N))

    ans = set(ans)
    print(len(ans))
    for i, j in ans:
        print(i, j)
        
if __name__ == '__main__':
    resolve()

Solution (Python):
def agc032_b():
    n = int(input())
    g = [[1]*n for _ in range(n)]
    for i in range(n//2):
        j = 2*(n//2)-1-i
        g[i][j] = 0
        g[j][i] = 0
    cnt = (sum([sum(row) for row in g]) - n) // 2
    print(cnt)
    for i in range(n):
        for j in range(i+1, n):
            if g[i][j]: print('{} {}'.format(i+1, j+1))

if __name__ == '__main__':
    agc032_b()

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






tree=[[] for _ in range(n)]

for i in range(n):
    for j in range(n):
        if i!=j:
            tree[i].append(j)

ans=[]
if n%2==0:
    for i in range(n):
        for item in tree[i]:
            if item+1!=n-i:
                if i>item:
                    ans.append([i+1,item+1])

else:
    for i in range(n):
        if i==n-1:
            for item in tree[i]:
                if i>item:
                    ans.append([i+1,item+1])
        else:
            for item in tree[i]:
                if item+1!=n-(i+1):
                    if i>item:
                        ans.append([i+1,item+1])

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

Solution (Python):
import sys,math,collections,itertools
input = sys.stdin.readline
graph = []
cnt = 0

N=int(input())
if N%2 == 0:
    
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i+j == N+1:
                continue
            else:
                cnt+=1
                graph.append([i,j])
                
else:
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i + j == N:
                continue
            else:
                cnt+=1
                graph.append([i,j])
print(cnt)
for gr in graph:
    print(*gr)

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 & 1:  
    N -= 1

for k in range(N // 2):
    i = k + 1
    j = N - k
    ans.remove((i, j))
print(len(ans))
for i, j in ans:
    print(i, j)

Solution (Python):
from itertools import combinations
N = int(input())

def check(edge, s):
    nodes = [0] * (N+1)
    for a, b in edge:
        nodes[a] += b
        nodes[b] += a
    return all([s == i for i in nodes[1:]])

def main(N):
    
    group_sum = N if N % 2 == 1 else N+1
    edge = set()
    for i in range(1,N+1):
        for j in range(i+1, N+1):
            if i+j == group_sum: continue
            edge.add((i,j))
    print(len(edge))
    for e in edge:
        print(*e)

main(N)

Solution (Python):
from itertools import combinations
N = int(input())

def check(edge, s):
    nodes = [0] * (N+1)
    for a, b in edge:
        nodes[a] += b
        nodes[b] += a
    return all([s == i for i in nodes[1:]])

def main(N):
    
    group_cnt = -(-N//2)
    group_sum = N if N % 2 == 1 else N+1
    s = (group_cnt - 1) * group_sum
    edge = set()
    loop_num = group_cnt if N % 2 == 0 else group_cnt - 1
    for comb in combinations(range(1, loop_num+1), 2):
        for i in (comb[0], group_sum-comb[0]):
            for j in (comb[1], group_sum-comb[1]):
                edge.add((i, j))
    if N % 2 == 1:
        for i in range(1, N):
            edge.add((i, N))
    print(len(edge))
    for e in edge:
        print(*e)
    

main(N)

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 & 1:  
    N -= 1

for k in range(N // 2):
    i = k + 1
    j = N - k
    ans.remove((i, j))
print(len(ans))
for i, j in ans:
    print(i, j)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    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 j == N - N % 2 - (i - 1):
                continue
            print(i, j)

if __name__ == '__main__':
    main()


'''
4:
 1 [ , 2, 3,  ] = 9
 2 [1,  ,  , 4] = 8
 3 [1,  ,  , 4] = 7
 4 [ , 2, 3,  ] = 6
5:
 1 [ , 2, 3,  , 5] = 10
 2 [1,  ,  , 4, 5] = 10
 3 [1,  ,  , 4, 5] = 10
 4 [ , 2, 3,  , 5] = 10
 5 [1, 2, 3, 4, ] = 10
6:
 1 [   2, 3, 4, 5,  ] = 14
 2 [1,    3, 4,  , 6] = 14
 3 [1, 2,    4, 5, 6] = 18
 4 [1, 2, 3,    5, 6] = 17
 5 [1,  , 3, 4,    6] = 14
 6 [ , 2, 3, 4, 5,  ] = 14
'''

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    table = [
        [1 for _ in range(N)] for _ in range(N)
    ]
    if N%2 == 0:
        for i in range(N//2):
            table[i][N-i-1] = table[N-i-1][i] = 0
    else:
        for i in range(N//2):
            table[i][N-i-2] = table[N-i-2][i] = 0
    size = 0
    answer = []
    for i in range(N):
        for j in range(i+1, N):
            if table[i][j]:
                answer.append((i+1, j+1))
                size += 1
    print(size)
    for a in answer:
        print(*a)


if __name__ == '__main__':
    solve()

Solution (Python):




import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]

def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

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

Solution (Python):
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue



sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))



class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n = ni()

    ans = []
    odd = int(n % 2)
    for i in range(n):
        for j in range(i + 1, n):
            if i + j + 2 != n + 1 - odd:
                ans.append([i + 1, j + 1])

    print(len(ans))
    for a, b in ans:
        print(a, b)


if __name__ == '__main__':
    main()

Solution (Python):
def solve():
  N = int(input())
  ans = [0]
  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[0] += 1
          ans.append([i,j])
  else:
    for i in range(1,N):
      for j in range(i+1,N):
        if i+j!=N:
          ans[0] += 1
          ans.append([i,j])
    for i in range(1,N):
      ans[0] += 1
      ans.append([N,i])
  return ans
ans = solve()
print(ans[0])
for a in ans[1:]:
  print(*a)

Solution (Python):
N = int(input())
M = N*(N-1)//2-N//2
print(M)
if N%2 ==0:
  rem = N+1
else:
  rem = N

for i in range(N):
  i +=1 
  for j in range(i,N):
    j +=1 
    temp = [i,j]
    if i+j != rem:
      print(*temp)

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

Solution (Python):






















    



    







n = int(input())
gl = [ [] for _ in range(n+1) ]

if n%2 == 0:
    ng = n+1
    for i in range(1,n//2+1):
        for j in range(1,n+1):
            
            if i != j and n+1-i != j:
                gl[i].append(j)
                gl[n+1-i].append(j)
else:
    ng = n
    for i in range(1,n//2+1):
        for j in range(1,n+1):
            if i != j and n-i != j:
                gl[i].append(j)
                gl[n-i].append(j)  
    gl[n] = list(range(1,n))

cnt = 0
for g in gl:
    cnt += len(g)

s = set()
print(cnt//2)
for i,g in enumerate(gl):
    if i == 0: continue
    for v in g:
        if (v,i) in s: continue
        print(i,v)
        s.add((i,v))

Solution (Python):
def solve():
  N = int(input())
  ans = [0]
  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[0] += 1
          ans.append(' '.join([str(i),str(j)]))
  else:
    for i in range(1,N):
      for j in range(i+1,N):
        if i+j!=N:
          ans[0] += 1
          ans.append(' '.join([str(i),str(j)]))
    for i in range(1,N):
      ans[0] += 1
      ans.append(' '.join([str(N),str(i)]))
  return ans
print(*solve(),sep='\n')

Solution (Python):
N = int(input())
G = [[0]*N for _ in range(N)]

for i in range(N):
    for j in range(N):
        if i!=j:
            G[i][j] = 1
            G[j][i] = 1

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

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

print(len(G))
for g in G:
    print(*g)

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

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

ans=[]

for i in range(1,N+1):
    for j in range(i+1,N+1):
        if not i+j==S:
            ans.append([i,j])
print(len(ans))
for a,b in ans:
    print(a,b)

Solution (Python):
import sys
from itertools import product

input = sys.stdin.readline


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

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

    for i in range(len(groups) - 1):
        group_a = groups[i]
        group_b = groups[i + 1]
        for a, b in product(group_a, group_b):
            ans.append(f"{a} {b}")

    if len(groups) >= 3:
        group_a = groups[0]
        group_b = groups[-1]
        for a, b in product(group_a, group_b):
            ans.append(f"{a} {b}")

    print(len(ans))
    print("\n".join(ans))


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
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 

from decimal import *



N = INT()

if N%2 == 0:
	print(N*(N-1)//2 - N//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):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7























N = getN()
dist = set()
if N % 2 == 0:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if i != j and i + j != (N + 1):
                dist.add((min(i, j), max(i, j)))
if N % 2 != 0:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if i != j and i + j != N:
                dist.add((min(i, j), max(i, j)))

dist = list(dist)
print(len(dist))
for a, b in dist:
    print(a, b)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
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:
	S = N*(N+1)//2 - N
else:
	S = N*(N+1)//2 - N - 1

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

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

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

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())

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


if __name__ == '__main__':
    main()

Solution (Python):
















n = int(input())
t = [[True if i != j else False for j in range(n)] for i in range(n)]
edge_sum = n * (n - 1) // 2 - n // 2
for i in range(n // 2):
    t[i][n - i - (1 if n % 2 == 0 else 2)] = False
print(edge_sum)
for i in range(n):
    for j in range(i + 1, n):
        if t[i][j]:
            print(f"{i+1} {j+1}")

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:
                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 i,j in ans:
    print(i,j)

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

    cnt = n
    if n % 2:
        cnt -= 1

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

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


if __name__ == '__main__':
    resolve()

Solution (Python):
def main():
    N = int(input())
    
    
    
    
    
    edges = list()
    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(len(edges))
    for e in edges:
        print('{} {}'.format(e[0], e[1]))


if __name__ == '__main__':
    main()

Solution (Python):



def od(n):
    ret = set([])
    for i in range(n):
        for j in range(i+1,n):
            if i+j+2 != n+1:
                ret.add((i+1, j+1))
    return ret

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

    ret = od(N//2*2)
    if N%2==1:
        for i in range(N-1):
            ret.add((i+1, N))

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



if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


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

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


if __name__ == "__main__":
    main()

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()

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

    print(len(ans))
    print('\n'.join(map(lambda a: '{} {}'.format(a[0], a[1]), ans)))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

INF = float("inf")


N = int(input())
a = [i+1 for i in range(N)]
li = list(itertools.combinations(a,2))
n = len(li)
if N % 2 == 1:
    print(N*(N-1)//2-N//2)
else:
    print(N*(N-1)//2-N//2)
for i in range(n):
    a,b = li[i]
    if N % 2 == 1:
        if a+b != N:
            print(a,b)
    else:
        if a+b != N+1:
            print(a,b)

Solution (Python):
import sys

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


def resolve():
    n = int(input())

    res = []
    remove = n
    if n % 2 != 0:
        remove -= 1

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

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


if __name__ == '__main__':
    resolve()