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):
def find(N):
    
    if N==3:
        print(2)
        print(1,3)
        print(2,3)
        return 0
        
    if N==4:
        print(4)
        print(1,2)
        print(2,4)
        print(3,4)
        print(1,3)
        return 0
    
    k=N//2
    edges=[]
    if N==2*k:
        for i in range(1,k):
            edges+=[(i,N-i)]
            edges+=[(i,i+1)]
            edges+=[(N+1-i,i+1)]
            edges+=[(N+1-i,N-i)]
        edges+=[(k,1)]
        edges+=[(k,N)]
        edges+=[(k+1,1)]
        edges+=[(k+1,N)]
        edges=set(edges)
        print(len(edges))
        for X in edges:
            print(X[0],X[1])
    else:
        for i in range(1,k):
            edges+=[(i,N-1-i)]
            edges+=[(i,i+1)]
            edges+=[(N-1+1-i,i+1)]
            edges+=[(N-1+1-i,N-1-i)]
        edges+=[(k,N),(N-k,N),(1,N),(N-1,N)]
        edges=set(edges)
        print(len(edges))
        for X in edges:
            print(X[0],X[1])
            
find(int(input()))

Solution (Python):
n = int(input())
an = []
if n % 2 == 0:
    a = 1
else:
    a = 0

for i in range(n,0,-1):
    for j in range(1, i):
        if j != a:
            an.append([i,j])
    a += 1
print(len(an))
for i in an:
    print(i[0], i[1])

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

if n % 2 == 0:
    print(int(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)

if n % 2 != 0:
    print(int((n-1)**2/2))
    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())

li = []

for i in range(0,(n//2)*2):
  if i+1 < n-i:
    li.append([i+1,n-i-n%2])
  else:
    break
if n%2 == 1:
  li.append([n])
if len(li) > 2:
  li.append(li[0])

count = 0
for i in range(1,len(li)):
  for j in li[i-1]:
    for k in li[i]:
      count += 1
print(count)
for i in range(1,len(li)):
  for j in li[i-1]:
    for k in li[i]:
      print(j,k)

Solution (Python):



N = int(input())

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

Solution (Python):
N = int(input())
ans = []
M = N + 1 * (N % 2 == 0)
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))

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

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

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

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












e = [[False for _ in range(N + 1)] for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(1, N + 1):
        if i == j: continue
        e[i][j] = True
        e[j][i] = True


total = -1
if N % 2 == 0:
    total = N + 1
else:
    total = N



for i in range(1, N + 1):
    for j in range(1, N + 1):
        if i == j: continue
        cp_i = total - i
        e[i][cp_i] = False
        

print(sum(e[i].count(True) for i in range(1, N + 1)) // 2)


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

Solution (Python):
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in xrange(n)]

def make2d_arr(w,h,val =INF):
    return [[val for i in xrange(w)]for i in xrange(h)]

n = int_raw()

edge = make2d_arr(n,n,0)

n_even = n - n%2

comp_edge = [(i,n_even-i-1) for i in xrange(0,n_even)]

for e in comp_edge:
    edge[e[0]][e[1]]=1
    edge[e[1]][e[0]]=1

m = 0
ans = []

for i in xrange(n):
    for j in xrange(i):
        if edge[j][i] == 0:
            m+=1
            ans.append((i,j))
print m
for a in ans:
    print a[0]+1,a[1]+1

Solution (Python):






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

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

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(4,2)
    print(4,3)
    exit()

if N%2 == 1:
    n = int((N+1)/2)
    group = [[0] * 2 for i in range(n-1)]
    M = n*4 - 4
    edge = []
    for i in range(n-1):
        group[i][0] = i+1
        group[i][1] = N-i-1
    for i in range(n-1):
        if i == n-2:
            edge.append([group[i][0],N])
            edge.append([group[i][1],N])
            edge.append([N,group[0][0]])
            edge.append([N,group[0][1]])
            
            
        else:
            edge.append([group[i][0],group[i+1][0]])
            edge.append([group[i][0],group[i+1][1]])
            edge.append([group[i][1],group[i+1][0]])
            edge.append([group[i][1],group[i+1][1]])

if N%2 == 0:
    n = int(N/2)
    group = [[0] * 2 for i in range(n)]
    M = n*4
    edge = []
    for i in range(n):
        group[i][0] = i+1
        group[i][1] = N-i
    for i in range(n):
        if i == n-1:
            edge.append([group[i][0],group[0][0]])
            edge.append([group[i][0],group[0][1]])
            edge.append([group[i][1],group[0][0]])
            edge.append([group[i][1],group[0][1]]) 
        else:
            edge.append([group[i][0],group[i+1][0]])
            edge.append([group[i][0],group[i+1][1]])
            edge.append([group[i][1],group[i+1][0]])
            edge.append([group[i][1],group[i+1][1]])

print(M)

for m in range(M):
    print(edge[m][0],edge[m][1])

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


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


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    se = N+1 if N % 2 == 0 else N
    return list(filter(lambda x: x[0]+x[1]!=se, combinations(range(1, N+1), 2)))


def main():
    N = read_int()
    E = slv(N)
    print(len(E))
    for e in E:
        print('%d %d' % e)


if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


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


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    E = []
    
    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
            E.append((i, j))

    return E


def main():
    N = read_int()
    E = slv(N)
    print(len(E))
    for e in E:
        print('%d %d' % e)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
ans = []
lis = []
for i in range(N):
    lis.append(i + 1)
if N % 2 == 0:
    M = (N - 2) * N // 2
    for i in range(1, N):
        for j in range(1, N):
            if j != i and i != lis[-j]:
                tmp = sorted([i, lis[-j]])
                if tmp not in ans:
                    ans.append(tmp)
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))
else:
    M = (N - 1) ** 2 // 2
    for i in range(1, N):
        for j in range(2, N):
            if j != i + 1 and i != lis[-j]:
                tmp = sorted([i, lis[-j]])
                if tmp not in ans:
                    ans.append(tmp)
    for i in range(1, N):
        ans.append([N, i])
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))

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

Solution (Python):
def main():
    N = int(input())
    aD = []
    if N % 2 :
        aD = [[i,N-i] for i in range(1,(N+1)//2)]
        aD.append([N])
    else:
        aD = [[i,N+1-i] for i in range(1,(N//2)+1)]
    iD = len(aD)
    dRes = set()
    def strfy(aD):
        return " ".join(str(_) for _ in sorted(aD))
    for i in range(iD):
        for j in range(iD):
            if i == j :
                pass
            else:
                if len(aD[i]) == 1:
                    dRes.add(strfy([aD[i][0],aD[j][0]]))
                    dRes.add(strfy([aD[i][0],aD[j][1]]))
                elif len(aD[j])== 1:
                    dRes.add(strfy([aD[i][0],aD[j][0]]))
                    dRes.add(strfy([aD[i][1],aD[j][0]]))
                else:
                    dRes.add(strfy([aD[i][0],aD[j][0]]))
                    dRes.add(strfy([aD[i][0],aD[j][1]]))
                    dRes.add(strfy([aD[i][1],aD[j][0]]))
                    dRes.add(strfy([aD[i][1],aD[j][1]]))
    print(len(dRes))
    print(*dRes,sep="\n")
main()

Solution (Python):
N = int(input())
X = list(range(1,N+1))
Nsum = sum(X)

n = 2 
while Nsum % n != 0:
    n += 1

group = [[] for i in range(n)]
value = int(Nsum/n)

for i in range(n-1):
    for j in range(N):
        if sum(X[-j-1:]) > value:
            break
    group[i] = X[-j:]
    X = X[:-j]
    ex = value - sum(group[i])
    if ex != 0:
        group[i].append(X.pop(X.index(ex)))

group[-1] = X

LEN = []
LENpr = 0
for i in range(n):
    LEN.append(len(group[i]))
for i in range(n-1):
    LENpr += LEN[i] * sum(LEN[i+1:])

print(LENpr)

for i in range(n-1):
    for j in range(i+1,n):
        for k in range(LEN[i]):
            for l in range(LEN[j]):
                print(group[i][k],group[j][l])

Solution (Python):
import sys

N = int(input())

if N == 4:
  print(4)
  print('{} {}'.format(1, 2))
  print('{} {}'.format(1, 3))
  print('{} {}'.format(4, 3))
  print('{} {}'.format(4, 2))
  sys.exit()

if N % 2 == 0:
  M = N // 2 * 4
  print(M)
  for k in range(1, N // 2):
    print('{} {}'.format(k, k+1))
    print('{} {}'.format(k, N-k))
    print('{} {}'.format(N-k+1, N-k))
    print('{} {}'.format(N-k+1, k+1))
  print('{} {}'.format(1, N//2))
  print('{} {}'.format(1, N//2 + 1))
  print('{} {}'.format(N, N//2))
  print('{} {}'.format(N, N//2 + 1))
  sys.exit()

if N == 3:
  print(2)
  print('{} {}'.format(1, 3))
  print('{} {}'.format(2, 3))
  sys.exit()


if N % 2 == 1:
  M = (N // 2) * 4
  print(M)
  for k in range(1, N // 2):
    print('{} {}'.format(k, k+1))
    print('{} {}'.format(k, N-k-1))
    print('{} {}'.format(N-k, N-k-1))
    print('{} {}'.format(N-k, k+1))
  print('{} {}'.format(1, N))
  print('{} {}'.format(N-1, N))
  print('{} {}'.format(N // 2, N))
  print('{} {}'.format(N // 2 + 1, N))
  sys.exit()

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






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

print(len(out))
for i in out:
	print(i)

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

Solution (Python):
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG =  True
def ddprint(x):
  if DBG:
    print(x)

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

Solution (Python):
import sys
N = int(sys.stdin.readline())

ans = ["%d\n" % (N*(N-1)//2 - N//2)]
K = N+((N&1)^1)
for i in range(1, N+1):
    for j in range(i+1, N+1):
        if i + j != K:
            ans.append("%d %d\n" % (i, j))
sys.stdout.writelines(ans)

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

if n % 2 == 1:
    ans = []
    count = 0

    for i in range(1, n):
        ans.append((i, n))
        count += 1

    for i in reversed(range(1, n)):
        for j in range(1, i):
            if i + j == n:
                continue
            ans.append((j, i))
            count += 1

    print(count)
    for a, b in ans:
        print(a, b)
else:
    ans = []
    count = 0

    for i in reversed(range(1, n+1)):
        for j in range(1, i):
            if i + j == n+1:
                continue
            ans.append((j, i))
            count += 1

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

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

Solution (Python):

        
def f3(N,S,M):
    sm=S//M
    l=[]
    for i in range(M):
        l.append([])
    li=[i for i in range(1,N+1)]
    for x in range(M):
        tmp=0
        for i in reversed(range(N)):
            if li[i]==-1:
                continue
            tmp+=li[i]
            if tmp>sm:
                tmp-=li[i]
                if li[sm-tmp-1]==-1:
                    
                    return
                l[x].append(sm-tmp)
                li[sm-tmp-1]=-1
                break
            l[x].append(li[i])
            li[i]=-1
            if tmp==sm:
                break
    y=0
    for x in range(M):
        y+=len(l[x])*(N-len(l[x]))
    y//=2
    print(y)
    for x in range(M):
        for xi in l[x]:
            for y in range(x+1,M):
                for yi in l[y]:
                    print(xi,yi)
    
    
def min_factor(S):
    for i in range(2,101):
        if S%i==0:
            return i



N=int(input())
S=N*(N+1)//2
M=min_factor(S)
f3(N,S,M)

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

Solution (Python):
from sys import exit
from numpy.random import rand






N = int(input())




ansgroup = []
if N%2 == 0:
    for i in range(1,N//2+1):
        ansgroup.append([i, N-i+1])
else:
    for i in range(1,N//2+1):
        ansgroup.append([i, N-i])
    ansgroup.append([N])
nodesum = 0
ans = []
for i in range(len(ansgroup)):
    for j in range(i+1,len(ansgroup)):
        for e1 in ansgroup[i]:
            for e2 in ansgroup[j]:
                nodesum+=1
                ans.append([e1,e2])
print(nodesum)
for a in ans:
    print(a[0],a[1])

Solution (Python):
n = int(input())
nums = list()
answers = list()
i = 0
if n % 2 == 0:
    while not(i == n / 2):
        nums.append((i+1,n-i))
        i += 1
else:
    while not(i == (n-1)/2):
        nums.append((i+1, n-i-1))
        i += 1
    nums.append((n,))
i = 0
while i < len(nums) - 1:
    for a in nums[i]:
        for b in nums[i+1]:
            answers.append((a, b))
    i += 1
if len(nums) >= 3:
    for a in nums[0]:
        for b in nums[-1]:
            answers.append((a,b))
print(len(answers))
for a, b in answers:
    print(a, b)

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

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

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

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

Solution (Python):





"""
gc032 B
"""


n = int(input())
es = []

if n % 2 == 1:
    for i in range(1, n):
        for j in range(i+1, n+1):
            if not (i+j == n):
                es.append((i, j))
else:
    for j in range(2,n):
        es.append((1,j))
    for i in range(2, n):
        for j in range(i+1, n+1):
            if not (i+j == n+1):
                es.append((i, j))

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

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

if n == 3:
    print("2")
    print("1 3")
    print("2 3")
if n == 4:
    print("4")
    print("1 2")
    print("1 3")
    print("2 4")
    print("3 4")
if n >= 5:
    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(str(i)+" "+str(j))
                    
    if n % 2 == 1:
        for i in range(1, n-1):
            for j in range(i+1, n):
                if i + j != n:
                    ans.append(str(i)+" "+str(j))
                    
        for i in range(1, n):
            ans.append(str(i)+" "+str(n))
            
    ans_len = len(ans)
    print(ans_len)
    for a in ans:
        print(a)

Solution (Python):
N = int(input())
S = 0
for i in range(1, N):
    S += i

Ans = []

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


print(len(Ans))
for a in Ans:
    print(" ".join(map(str, a)))

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

if n == 3:
    print("2")
    print("1 3")
    print("2 3")
if n == 4:
    print("4")
    print("1 2")
    print("1 3")
    print("2 4")
    print("3 4")
if n >= 5:
    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(str(i)+" "+str(j))
                    
    if n % 2 == 1:
        for i in range(1, n-1):
            for j in range(i+1, n):
                if i + j != n:
                    ans.append(str(i)+" "+str(j))
                    
        for i in range(1, n):
            ans.append(str(i)+" "+str(n))
            
    ans_len = len(ans)
    print(ans_len)
    for a in ans:
        print(a)

Solution (Python):
def solve(N):
  ans = []
  if N % 2 == 1:
    ans = solve(N - 1)
    for i in range(1, N):
      ans.append('{} {}'.format(i, N))
  else:
    for i in range(1, N + 1):
      for j in range(i + 1, N + 1):
        if j == N - i + 1: continue
        ans.append('{} {}'.format(i, j))
  return ans

ans = solve(int(input()))
print(len(ans))
[print(a) for a in ans]

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

N_sub = N
if N % 2 == 0:
    pass
else:
    N = N-1

num = int(N*(N-1)/2-N/2)
all_num = N*(N+1)/2

arr = []
for i in range(1,N+1):
    for j in range(1,N+1):
        if i < j:
            arr.append([i, j])

for i in range(1,int(N/2+1)):
    arr.remove([i, N+1-i])

if N_sub == N:
    print(num)
    for i in range(len(arr)):
        print(arr[i][0],arr[i][1]) 

else:
    for i in range(1,N_sub):
        arr.append([i,N_sub])
    print(num+N_sub-1)
    for i in range(len(arr)):
        print(arr[i][0],arr[i][1])

Solution (Python):


import sys

N = int(input())

ans = []

if N % 2 == 0:
    tmp = N + 1
else:
    tmp = N
    
for i in range(1,N+1):
    for j in range(i+1,N+1):
        if i + j != tmp:
            ans.append(str(i)+' '+str(j))
            
print(len(ans))

for a in ans:
    print(a)

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

if N % 2 == 0:
    print((N*N - 2*N)//2)
    for x in range(N):
        for y in range(x+1,N):
            if x != y and x+y != N-1:
                print(x+1,y+1)

else:
    print((N*N-N*2+1)//2)
    for x in range(N):
        for y in range(x+1,N):
            if x != y and x+y != N-2:
                print(x+1,y+1)

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

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

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

def solve(N):
  fmt = '{} {}'
  ans = []
  sub = []
  if N % 2 == 1:
    ans = solve(N - 1)
    for i in range(1, N):
      ans.append(fmt.format(i, N))
  else:
    for i in range(1, N + 1):
      for j in range(i + 1, N + 1):
        if j == N - i + 1: continue
        ans.append(fmt.format(i, j))
  return ans

ans = solve(N)
print(len(ans))
[print(a) for a in ans]

Solution (Python):


N = int(input())


if N%2 == 0:
    M = int(0.5*N**2-N)
    print(M)
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i+j != N+1:
                print("{} {}".format(i, j))
else:
    N = N-1
    M = int(0.5*N**2-N)
    print(M+N)
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i+j != N+1:
                print("{} {}".format(i, j))
        print("{} {}".format(i, N+1))

Solution (Python):
N = int(input())
odd = N % 2
ans = []
for f in range(1, N+1):
  for t in range(f+1, N+1):
    if t != N - (f-1) - odd:
      ans.append([f,t])

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

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

n = int(input())
if n == 3:
    print(2)
    print(1,3)
    print(2,3)
else:
    res = [[1,3],[2,3]]
    cnt = 0
    for i in range(4,n+1):
        if i%2 == 0:
            for j in range(len(res)):
                res[j] = [res[j][0]+1,res[j][1]+1]
            for j in range(2,i):
                res.append([1,j])
        else:
            for j in range(1,i):
                res.append([i,j])
    print(len(res))
    for e in res:
        print(e[0],e[1])

Solution (Python):
N = int(input())
X = sum(range(1, N))
if N % 2 == 0:
    X -= 1


delete = set()
for n in range(1, N + 1):
    diff = sum(range(1, N + 1)) - X - n
    minus = N - 1
    minus += (N % 2 == 0)
    while diff:
        if (diff - minus < 0) or (minus == n):
            minus -= 1
            continue
        diff -= minus
        delete.add((min(n, minus), max(n, minus)))


ans = []
for n in range(1, N + 1):
    for to in range(n + 1, N + 1):
        if (n, to) in delete:
            continue
        else:
            ans.append([n, to])

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

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_list_of_float():
    return [float(f) for f in input().split()]


def get_list_of_char():
    return list(input().strip())


def get_data(n, order=None, **kwargs):
    if not order:
        order = range(len(kwargs))
    it = iter(order)
    var, fn = zip(*sorted(sorted(kwargs.items()), key=lambda _: next(it)))

    rows = []
    for _ in range(n):
        rows.append(input().split())
    columns = zip(*rows)
    exec("global "+", ".join(var)+"\n"+"\n".join(
        v+"=list(map(fn[{}], data[{}]))".format(i, i)
        for i, v in enumerate(var)),
        globals(),
        {"fn": list(fn), "data": list(columns)}
    )
    return



N = 0


def set_inputs():
    global N
    N = get_int()
    return


def find(n):
    bits = []
    for i in range(2**(n*(n-1)//2)):
        bits = [(i >> j) % 2 for j in range(n*(n-1)//2)]
        cnt = Counter()
        for j in range(1, n+1):
            cnt[j] = 0
        edges = []
        for x, y in itertools.compress(
                itertools.combinations(range(1, n+1), 2),
                bits
        ):
            cnt[x] += y
            cnt[y] += x
            edges.append((x, y))
        counts = list(cnt.values())
        if len(edges) > 0 and all(v == counts[0] for v in counts):
            print(i, bits, edges)


def solve(n):
    s = n
    if n % 2 == 0:
        s = n + 1
    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 == s:
                continue
            print(i, j)


def main():
    setrecursionlimit(100000)
    set_inputs()
    solve(N)
    return


if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())

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

ans = []
for i, a in enumerate(li):
    for j, b in enumerate(li):
        if i >= j:
            continue
        if len(a) == 1:
            ans.append([a[0], b[0]])
            ans.append([a[0], b[1]])
        elif len(b) == 1:
            continue
            
            
        else:
            ans.append([a[0], b[0]])
            ans.append([a[1], b[0]])
            ans.append([a[0], b[1]])
            ans.append([a[1], b[1]])

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

Solution (Python):



from collections import deque
import heapq
import math
import bisect


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

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

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


if __name__ == '__main__':
    main()

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

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

if n%2 == 0:
    for i in range(1,n+1):
        for j in range(i,n+1):
            if j ==n+1-i or j ==i:
                continue
            ans += 1

else:
    for i in range(1,n+1):
        for j in range(i,n+1):
            if j == n-i or j ==i:
                continue
            ans += 1

print(ans)

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

else:
    for i in range(1,n+1):
        for j in range(i,n+1):
            if j == n-i or j ==i:
                continue
            print(i,j)

Solution (Python):
import itertools
N = int(input())
a = [i for i in range(1, N+1)]
graph = list(itertools.combinations(a, 2))
graph
for i in range(N//2):
    graph.remove((i+1, 2*(N//2)-i))
print(len(graph))
for i in range(len(graph)):
    print(graph[i][0], graph[i][1])

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

if n%2 ==1:
  for i in range(n-1):
    print(i+1,n)
  n = n-1

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