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):
from copy import deepcopy
from functools import reduce


class Divisor:
    def __init__(self, n):
        """ make divisors list and prime factorization list of n
            complexity: O(n^(1/2))
            used in ProjectEuler No.12, yukicoder No.36
        """
        assert(n >= 1)
        number = n
        if number == 1:
            self.primeFactorization = {1: 1}
        else:
            self.primeFactorization = {}
            for i in range(2, int(n**0.5)+1):
                cnt = 0
                while number % i == 0:
                    cnt += 1
                    number //= i
                if cnt > 0:
                    self.primeFactorization[i] = cnt
            if number > 1:
                self.primeFactorization[number] = 1

    def primeFactors(self):
        return deepcopy(self.primeFactorization)

    def numDivisors(self):
        """ the number of divisors """
        if self.primeFactorization.get(1, 0) == 1:
            return 1
        numDiv = 1
        for _, cnt in self.primeFactorization.items():
            numDiv *= cnt+1
        return numDiv

    def sumDivisors(self):
        return reduce(lambda x, y: x * y, [sum(p**i for i in range(n+1)) for p, n in self.primeFactorization.items()])


def divisorsList(n):
    assert(n >= 1)
    divsList = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divsList.append(i)
            if n // i != i:
                divsList.append(n//i)
    return sorted(divsList)


def subsum(arr, M):
    dp = [0] * (M + 1)
    prev = [-1] * (M + 1)
    dp[0] = 1
    for x in reversed(arr):
        for i in reversed(range(M + 1)):
            if dp[i] and i + x <= M and not dp[i + x]:
                dp[i + x] = 1
                prev[i + x] = i
    assert dp[-1]
    ans = []
    now = M
    while prev[now] != -1:
        ans.append(now - prev[now])
        now = prev[now]
    return ans


def dfs(groups, i, now):
    if i == len(groups):
        print(*now)
        return
    for x in groups[i]:
        now.append(x)
        dfs(groups, i + 1, now)
        now.pop()


def main(N):
    sumall = N * (N + 1) // 2
    group_num = divisorsList(sumall)[1]
    groups = []
    selected = set()
    rest = list(range(1, N + 1))
    for i in range(group_num):
        g = subsum(rest, sumall // group_num)
        groups.append(g)
        selected |= set(g)
        rest = [x for x in rest if x not in selected]
        
    edges = []
    for i in range(len(groups)):
        for j in range(len(groups)):
            if i >= j:
                continue
            for x1 in groups[i]:
                for x2 in groups[j]:
                    edges.append((x1, x2))
    print(len(edges))
    for e in edges:
        print(*e)


if __name__ == '__main__':
    N = int(input())
    main(N)

Solution (Python):
N = int(input())
list_ = [x for x in range(N)]
if N%2 == 0:
  cmb_list = [[k, N-k+1] for k in range(1,int(N/2)+1)]
  print(int(N*(N-2)/2))
else:
  cmb_list = [[k, N-k] for k in range(1,int(N/2+1))]
  cmb_list.append([N])
  print(int((N-1)**2/2))

for list_ in cmb_list:
  for c in list_:
    for idx in range(1,c):
      if (idx not in list_):
        print("%s %s"%(idx, c))

Solution (Python):
num = int(input())
check_list = [0] * num * num

def make_bridge(island1, island2):
    if(island1 < island2):
        check_list[(island1-1)*num + (island2-1)]=1;
    else:
        check_list[(island2-1)*num + (island1-1)]=1;

if num%2==0:
    sum_pair = num+1
else:
    sum_pair = num

for i in range(num):
    for j in range(i):
        if (i+1 + j+1 != sum_pair):
            check_list[j*num + i]=1;

bridge_num=0;

for i in range(num*num):
    if(check_list[i]==1):
        bridge_num+=1;

print(bridge_num);

for i in range(num*num):
    if(check_list[i]==1):
        left = i // num
        right = i % num
        print(str(left+1)+" "+str(right+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 a in ans:
    print(' '.join(map(str, a)))

Solution (Python):
n = int(input())
res = []
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
            res.append([i, j])
elif n % 2 == 1:
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j == n:
                continue
            res.append([i, j])
print(len(res))
for (i,j) in res:
    print(i, j)

Solution (Python):

def read_tokens():
    return input().strip().split(' ')

def read_ints():
    return [int(token) for token in read_tokens()]

def connected(edges):
    n = len(edges)
    vis = [False] * n
    def dfs(u):
        if vis[u]:
            return
        vis[u] = True
        for v in edges[u]:
            dfs(v)
    dfs(0)
    return all(vis)

def good(edges):
    n = len(edges)
    s = []
    for i in range(n):
        s.append(sum(edges[i]) + len(edges[i]))
    return min(s) == max(s)
















def out(edges):
    print(sum(len(a) for a in edges) // 2)
    for idx, a in enumerate(edges):
        for v in a:
            if idx < v:
                print(idx+1, v+1)


def even(n):
    edges = [[] for _ in range(n)]
    s = (n + 1) * (n - 2) // 2
    sums = [s] * n
    for i in reversed(range(n)):
        
        for j in reversed(range(i)):
            
            if i + j != n - 1:
                sums[i] -= j + 1
                sums[j] -= i + 1
                edges[i].append(j)
                edges[j].append(i)
    assert(max(sums) == 0 and min(sums) == 0)
    return edges

def odd(n):
    edges = [[] for _ in range(n)]
    s = n * (n - 1) // 2
    sums = [s] * n
    for i in reversed(range(n)):
        
        for j in reversed(range(i)):
            
            if i + j != n - 2:
                sums[i] -= j + 1
                sums[j] -= i + 1
                edges[i].append(j)
                edges[j].append(i)
    assert(max(sums) == 0 and min(sums) == 0)
    return edges

n, = read_ints()
if n % 2 == 0:
    out(even(n))
else:
    out(odd(n))

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

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

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

print(len(ans))
print("\n".join([" ".join(map(str, ai)) for ai in ans]))

Solution (Python):
N = int(input())
ban = 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 == ban: continue
        ans.append((i,j))

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

Solution (Python):
n = int(input())
if n%2 == 0:
	partsum = n+1
	parts = [[i,n+1-i] for i in range(1,n//2+1)]
	m = (n-2)*n//2
else:
	partsum = n
	parts = [[n]]+[[i,n-i] for i in range(1, (n+1)//2)]
	m = (n-3)*(n-1)//2 + n-1

print(m)
for i,p in enumerate(parts):
	for j,q in enumerate(parts):
		if i<=j:
			continue
		
		for a in p:
			for b in q:
				print(a,b)

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

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

    print(len(lst))
    for s in lst:
        print(*s)
else:
    lst = []
    for i in range(1, n):
        for j in range(i, n):
            if i != j and i + j != n:
                lst.append((i, j))
    for i in range(1, n):
        lst.append((i, n))
    print(len(lst))
    for s in lst:
        print(*s)

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

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

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

if n%2 == 0:
    su = n+1
    print((n*(n-1)//2)-n//2)
    for i in range(1,n+1):
        for k in range(1,n+1):
            if i+k != su and i < k:
                print(i,k)
if n%2 == 1:
    su = n
    print((n*(n-1)//2)-(n-1)//2)
    for i in range(1,n+1):
        for k in range(1,n+1):
            if i+k != su and i < k:
                print(i,k)

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

if N == 3:
  print(2)
  print(1, 3)
  print(2, 3)
  exit()

if N == 4:
  print(4)
  print(1, 2)
  print(1, 3)
  print(2, 4)
  print(3, 4)
  exit()


L = []
M = 0
if N % 2 == 1:
  L.append([N])
  N -= 1

for i in range(1, N // 2 + 1):
  L.append([i, N + 1 - i])



M += 2 * N

print(M)
for i in range(len(L)):
  for j in L[i]:
    for k in L[i - 1]:
      print(j, k)

Solution (Python):

from itertools import combinations

def solve():
    N = int(input())
    m = 2*(N//2)+1
    res = str((N*(N-1))//2 - N//2) + '\n' + '\n'.join((' '.join(map(str, e)) for e in combinations(range(1,N+1), r=2) if sum(e)!=m))

    return str(res)
if __name__ == '__main__':
    print(solve())

Solution (Python):
n = input().strip()
n = int(n)
r = list()
if n % 2 == 0:
    x = n + 1
    for i in range(n):
        i = i + 1
        for j in range(n):
            j = j + 1
            if j <= i:
                continue
            if i + j == x:
                continue
            r.append((i,j))
else:
    m = n - 1
    x = n
    for i in range(m):
        i = i + 1
        for j in range(m):
            j = j + 1
            if j <= i:
                continue
            if i + j == x:
                continue
            r.append((i, j))
    for i in range(m):
        r.append((i+1, x))
print(len(r))
for l in r:
    print(l[0], l[1])

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n = ni()

a = [i for i in range(1,101)]
acc = list(accumulate(a))

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

for i in range(len(groups)):
    for j in range(len(groups[i])):
        for k in range(1,n+1):
            if k in groups[i] or groups[i][j] > k:
                continue
            
            else:
                edges.append([groups[i][j], k])
                
print(len(edges))
for ei in edges:
    print(*ei)

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

Solution (Python):
n = int(input())
apexes = [i + 1 for i in range(n)]
pairs = []

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




edges = []
for i in range(len(pairs)):
    for j in range(i + 1, len(pairs)):
        edges.append((pairs[i][0], pairs[j][0]))
        edges.append((pairs[i][0], pairs[j][1]))
        edges.append((pairs[i][1], pairs[j][0]))
        edges.append((pairs[i][1], pairs[j][1]))

if n % 2 == 1:
    for i in range(1, n):
        edges.append((n, i))

print(len(edges))
for edge in edges:
    print("{0} {1}".format(edge[0], edge[1]))

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

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

for i in range(1,N):
    for j in range(1,N):
        if i == j:
            continue
        if N - i == j or N - j == i:
            continue
        if (str(j)+' '+str(i)) in result:
            continue
        result.append(str(i)+' '+str(j))

print(len(result))
for x in result:
    print(x)

Solution (Python):
N = int(input())
if N%2==0:
    M = (N**2-2*N)//2
    ans = []
    for i in range(1,N+1):
        for j in range(1,N+1):
            if i != j and i+j != N+1 and i < j:
                ans.append(str(i)+" "+str(j))
    print(M)
    for i in ans:
        print(i)
else:
    M = (N**2-N-(N-1))//2
    ans = []
    for i in range(1,N+1):
        for j in range(1,N+1):
            if i != j and i+j != N and i < j:
                ans.append(str(i)+" "+str(j))
    print(M)
    for i in ans:
        print(i)

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

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

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

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

Solution (Python):
n = int(input())
def make(x):
    if x == 3:
        return [(1, 3), (2, 3)]
    else:
        pre = make(x-1)
        edge = []
        for a, b in pre:
            edge.append((x-b, x-a))
        if x % 2 == 0:
            for i in range(2, x):
                edge.append((i, x))
        else:
            for i in range(1, x):
                edge.append((i, x))
        return edge
ans = make(n)
print(len(ans))
for a, b in ans:
    print(a, b)

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


if __name__ == "__main__":
    main()

Solution (Python):
def f(n):
    for i in range(1,n):
        p=n+1-i
        for j in range(i+1,n+1):
            if j!=p:
                print(i,j)


n=int(input())
if n%2==0:
    print((n-2)*n//2)
    f(n)
else:
    print((n-3)*(n-1)//2+n-1)
    f(n-1)
    for i in range(1,n):
        print(i,n)

Solution (Python):
import itertools
n = int(input())
ns = list(range(1,n+1))
cs = list(itertools.combinations(ns, 2))
top = n if n % 2 == 0 else n-1

for nn in range(n):
  tpl = (nn+1, top-nn)
  if tpl[0] >= tpl[1]:
    break
  
  cs.remove(tpl)

print(len(cs))
for a, b in cs:
  print('{0} {1}'.format(a, b))

Solution (Python):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    n = int(input())
    if n % 2 == 0:
        print(n*(n-2)//2)
        for i in range(1,n//2+1):
            leave = [k for k in range(n+1)]
            leave.pop(n-i+1)
            for j in leave[i+1:]:
                print(str(i) + ' ' + str(j))
        for i in range(n//2+1,n+1):
            for j in range(i+1,n+1):
                print(str(i) + ' ' + str(j))
    else:
        print(((n-1)**2)//2)
        for i in range(1,(n+1)//2):
            leave = [k for k in range(n)]
            leave.pop(n-i)
            for j in leave[i+1:]:
                print(str(i) + ' '+ str(j))
        for i in range((n+1)//2,n):
            for j in range(i+1,n):
                print(str(i)+ ' ' + str(j))
        for i in range(1,n):
            print(str(i)+ ' ' + str(n))

Solution (Python):
N = int(input())
print(N*(N-1)//2-N//2)
if N%2 == 0:
  s = N+1
else:
  s = N
for i in range(1, N+1):
  for j in range(1, N+1):
    if i == j or i == s-j:
      pass
    else:
      if i > j:
      	print("{} {}".format(i, j))

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

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

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

c = 0
ANS = []

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

print(c)
for ans in ANS:
    print(*ans)

Solution (Python):

n = int(input())

al = int(n * (n - 1)/2)
alls = []
for k in range(1,n+1):
    for i in range(k+1,n+1):
        alls.append((k,i))

if n%2 == 1:
    for k in range(1, (n-1)//2 + 1):
        alls.remove((k, n-k))    
else:
    for k in range(1,(n//2) +1):
        alls.remove((k,n-k+1))

print(len(alls))
for a in alls:
    print(a[0], a[1])

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 i + j + (N % 2) != N + 1:
      print(i, j)

Solution (Python):
N = int(input())
f = False
if N%2==1:
    f = True
    N -= 1
from itertools import product
A = []
for a, b in product(range(1, N+1), range(1, N+1)):
    if a < b and a+b!=N+1:
        A.append((a,b))
if f:
    N+=1
    for i in range(1, N):
        A.append((i, N))
print(len(A))
for a, b in A:
    print(a, b)

Solution (Python):

import sys


def solve(N: int):
    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([N, i])

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

    

    return

def check(ans, N):
    import numpy as np
    print(np.sum(np.array(ans))//N)



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    solve(N)

if __name__ == '__main__':
    main()

Solution (Python):
N = 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:
        E += [(i, j)]
else:
  for i in range(1, N):
    for j in range(i+1, N):
      if i+j!=N:
        E += [(i, j)]
    E += [(i, N)]

print len(E)
for e in E:
  print e[0], e[1]

Solution (Python):
def main():
    n = int(raw_input())
    a = n * (n + 1) / 2
    for i in xrange(2, a):
        if a % i:
            continue
        t = a / i
        g = [[] for j in xrange(i)]
        y = range(1, n + 1)[::-1]
        for j in xrange(i - 1):
            s = 0
            ny = []
            for x in y:
                if s + x <= t:
                    s += x
                    g[j].append(x)
                else:
                    ny.append(x)
            y = ny
        g[-1] = y
        ans = []
        for j in xrange(i):
            for x in g[j]:
                for y in g[j-1]:
                    ans.append((x, y))
            if i == 2:
                break
        print len(ans)
        for x, y in ans:
            print x, y
        return
main()

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

if n % 2 == 0:
    print(n * n // 2 - n)
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            if a + b != n + 1:
                print('{0} {1}'.format(a, b))
else:
    print((n - 1) ** 2 // 2)
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            if a + b != n:
                print('{0} {1}'.format(a, b))

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

Solution (Python):


"""
 12345
1.xx.x
2x..xx
3x..xx
4.xx.x
5xxxx.

 123456
1.xxxx.
2x.xx.x
3xx..xx
4xx..xx
5x.xx.x
6.xxxx.
"""

import sys

input=sys.stdin.readline
mii=lambda:map(int,input().split())

n=int(input())

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


n2=n-n%2
for i in range(n2):
    g[i][n2-1-i]=0
    g[n2-1-i][i]=0
g[n-1][n-1]=0

out=[]
for i in range(n):
    for j in range(i+1,n):
        if g[i][j]:
            out.append([i+1,j+1])
print(len(out))
for i,j in out:
    print("%d %d"%(i,j))

Solution (Python):
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

n = ii()
ed = {(i, j) for i in range(1, n) for j in range(i + 1, n + 1)}
i, j = 1, n - n % 2
while i < j:
    ed.remove((i, j))
    i += 1
    j -= 1
print(len(ed))
print(*('%d %d' % e for e in ed), sep='\n')

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

ans = []
if N % 2:
    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:
                ans.append("%d %d\n" % (i, j))
else:
    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:
                ans.append("%d %d\n" % (i, j))
sys.stdout.writelines(ans)

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

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
sys.setrecursionlimit(1000000)


def A():
    n = I()
    b = LI()
    d = defaultdict(int)
    for i in b:
        d[i] += 1
    a = []
    ans = []
    return

def B():
    n = I()
    if n%2:
        ans = []
        for i in range(1,n+1):
            for j in range(1,n+1):
                if j != n-i and j != i:
                    ans.append((min(i,j),max(i,j)))
        ans = list(set(ans))
        print(len(ans))
        ans.sort()
        for i in ans:
            print(*i)
    else:
        ans = []
        for i in range(1,n+1):
            for j in range(1,n+1):
                if j != n+1-i and j != i:
                    ans.append((min(i,j),max(i,j)))
        ans = list(set(ans))
        print(len(ans))
        ans.sort()
        for i in ans:
            print(*i)

def C():
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    B()

Solution (Python):
n = int(input())
ans = []
if n % 2 == 0:
    m = n + 1
else:
    m = n
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        if i + j == m:
            continue
        ans.append('{} {}'.format(i, j))
print(len(ans))
print('\n'.join(ans))