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

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

if N==3 or N==4:
    print((N-2)*2)
else:
    if N%2==0:
        print(N*2)
    else:
        print((N-1)*2)
    
for i in range(len(L)-1):
    for j in range(len(L[i])):
        for k in range(len(L[i+1])):
            print(L[i][j],L[i+1][k])
if N==3 or N==4:
    exit()
else:
    for j in range(len(L[len(L)-1])):
        for k in range(len(L[0])):
            print(L[len(L)-1][j],L[0][k])

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

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

Solution (Python):
n = int(input())
E = []

B = [[0]*n for i in range(n)]
for i in range(n):
    for j in range(i+1,n):
        if i+j != (n-n%2)-1:
            E.append((i,j))
            B[i][j] = 1
            B[j][i] = 1
print(len(E))
for a,b in E:
    print(a+1,b+1)

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

if N % 2 == 1:
    M = N * (N - 1) / 2 - (N - 1) / 2
    print(int(M))
    for i in range(1, N + 1):
        for j in range(1, i + 1):
            if i != j and i + j != N:
                print(str(i) + " " + str(j))

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

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

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

connect_lis=[]

for i in lis:
    for j in i:
        for k in lis:
            if k!=i:
                for p in k:
                    if j < p:
                        connect_lis.append([j,p])
        
print(len(connect_lis))
for i in connect_lis:
    print(i[0],i[1])

Solution (Python):
import sys

N = int(input())
nsum = N * (N + 1) // 2

for S in range(N*(N-1)//2, N-1, -1):
    s = [nsum - n for n in range(0, N+1)]
    cutv = []
    for n in range(N, 0, -1):
        rem = s[n] - S
        for i in range(rem, 0, -1):
            if s[n] == S:
                break
            if s[n] - i < S:
                continue
            if s[i] - n < S:
                continue
            s[i] -= n
            s[n] -= i
            if i <= n:
                cutv.append((i, n))
            else:
                cutv.append((n, i))
        if s[n] != S:
            break
    else:
        print(N * (N - 1) // 2 - len(cutv))
        for i in range(1, N + 1):
            for j in range(i + 1, N + 1):
                if (i, j) not in cutv:
                    print(i, j)
        sys.exit()

raise

Solution (Python):

from collections import defaultdict, Counter
from itertools import permutations, product, combinations
from bisect import bisect, bisect_left
from fractions import gcd
MOD = 10**9 + 7

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

def primes(N):
    sieve = [1]*101
    sieve[0] = 0
    sieve[0] = 1
    P = []
    for i in range(2, 101):
        if sieve[i]:
            P.append(i)
            for j in range(i*2, 101, i):
                sieve[j] = 0
    return P

P = primes(100)
N = int(input())

X = (N*(N+1))//2
for p in P:
    if X%p == 0:
        break

groups = []
searched = set()
for j in range(p):
    target = X//p
    A = []
    for i in range(N, 0, -1):
        if i <= target and not i in searched:
            A.append(i)
            target -= i
    assert target == 0
    A = set(A)
    searched.update(A)
    groups.append(A)

M = 0
for g in groups:
    M += (N-len(g))*len(g)
print(M//2)
S = set(range(1, N+1))

for g in groups:
    for x in g:
        for y in S - g:
            print(x, y)
        S = S - g

Solution (Python):
N = int(input())
aD = []
if N % 2 :
    aD.append([N])
    for i in range(1,(N+1)//2):
        aD.append([i,N-i])
else:
    for i in range(1,(N//2) + 1):
        aD.append([i,N+1-i])
iD = len(aD)
aRes = []
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:
                aRes.append(strfy([aD[i][0],aD[j][0]]))
                aRes.append(strfy([aD[i][0],aD[j][1]]))
            elif len(aD[j])== 1:
                aRes.append(strfy([aD[i][0],aD[j][0]]))
                aRes.append(strfy([aD[i][1],aD[j][0]]))
            else:
                aRes.append(strfy([aD[i][0],aD[j][0]]))
                aRes.append(strfy([aD[i][0],aD[j][1]]))
                aRes.append(strfy([aD[i][1],aD[j][0]]))
                aRes.append(strfy([aD[i][1],aD[j][1]]))
aRes = list(set(aRes))
print(len(aRes))
print(*aRes,sep="\n")

Solution (Python):
N = int(input())
ans_list = []

if N%2 ==0:
   M = int(N*(N-2)/2)
   for i in range(1,N+1):
       pair = N+1-i
       for j in range(i+1,N+1):
           if j != pair:
               ans_list.append([i,j])


else:
   M = int((N-1)*(N-1)/2)
   for i in range(1,N):
       pair = N-i
       for j in range(i+1,N):
           if j != pair:
               ans_list.append([i,j])
       ans_list.append([i,N])

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

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
if n%2==0:
    print(n*(n-2)//2)
    for i in range(n):
        for j in range(n):
            if i<j and i+j+2!=1+n:
                print(i+1,j+1)
else:
    print((n-1)*(n-3)//2+n-1)
    for i in range(n-1):
        for j in range(n-1):
            if i<j and i+j+2!=1+n-1:
                print(i+1,j+1)
    for i in range(n-1):
        print(i+1,n)

Solution (Python):
n=int(input())
if n%2==0:
    s=n+1
    res=[]
    for i in range(1,n//2+1):
        res.append([i,s-i])
    z=[]
    for i in range(len(res)-1):
        for j in range(i+1,len(res)):
            for x in range(2):
                for y in range(2):
                    z.append([min(res[i][x],res[j][y]),max(res[i][x],res[j][y])])
    print(len(z))
    for t in z:
        print(t[0],t[1])
else:
    s=n
    res=[]
    for i in range(1,n//2+1):
        res.append([i,s-i])
    z=[]
    for i in range(len(res)-1):
        for j in range(i+1,len(res)):
            for x in range(2):
                for y in range(2):
                    z.append([min(res[i][x],res[j][y]),max(res[i][x],res[j][y])])
    for i in range(1,n):
        z.append([i,n])
    print(len(z))
    for t in z:
        print(t[0],t[1])

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

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

Solution (Python):
N = int(input())
ans_list = []

if N%2 ==0:
    M = int(N*(N-2)/2)
    for i in range(1,N+1):
        pair = N+1-i
        for j in range(i+1,N+1):
            if j != pair:
                ans_list.append([i,j])


else:
    M = int((N-1)*(N-1)/2)
    for i in range(1,N):
        pair = N-i
        for j in range(i+1,N):
            if j != pair:
                ans_list.append([i,j])
        ans_list.append([i,N])
        
print(M)
for ans in ans_list:
    print(ans[0],ans[1])

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

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

for i in range(1, N+1):
  tmp_sum += i
  
if N % 2 == 1:
  S = sum(range(1, N))
else:
  S = sum(range(1, N)) - 1

count = 0
ans = []

for i in range(1, N):
  tmp_sum = sum(range(1, N+1)) - i
  exclude = tmp_sum - S
  for j in range(i+1, N+1):
    if j != int(exclude):
      count += 1
      ans.append((i, j))

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

Solution (Python):

n = int(input())

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



edges = []
for x in range(1, n+1):
    for p in pairs:

        if x in p:
            break
        for node in p:

            edges.append(sorted([x, node]))


print(len(edges))
for e in edges:
    print(' '.join([str(i) for i in e]))

Solution (Python):
def balanced_neighbors(N: int)->list:
    if N & 1:
        return balanced_neighbors(N-1) + [(i, N) for i in range(1, N)]

    res = []
    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))
    return res


if __name__ == "__main__":
    N = int(input())
    ans = balanced_neighbors(N)

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

def main(n):
	s = int(n*(n+1)/2)
	a = []
	b = []
	if s % 2 == 0:
		i = n
		ts = s/2
		while i != 0:
			if i <= ts:
				a += [min(i, ts)]
				ts -= min(i, ts)
			else:
				b += [i]
			i -= 1
		print(len(a)*len(b))
		for i in a:
			for j in b:
				print("{} {}".format(i, j))
	else:
		nn = (n if n % 2 == 1 else n+1)
		mm = int(n/2 if n % 2 == 0 else (n+1)/2)
		lst = [[]]*mm
		for i in range(n, 0, -1):
			flg = True
			for l in range(mm):
				if (sum(lst[l]) + i <= nn) and flg:
					lst = lst[:l] + [lst[l] + [i]] + lst[l+1:]
					flg = False
		m = 0
		for i in range(mm):
			m += len(lst[i%mm])*len(lst[(i+1)%mm])
		print(m)
		for i in range(mm):
			for l in lst[i]:
				for ll in lst[(i+1)%mm]:
					print("{} {}".format(l, ll))
		
		

main(int(input()))

Solution (Python):
import math

N=int(input())

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

if N%2:
  for i in range(1,N):
    print('{} {}'.format(i, N))
  N=N-1
  
for i in range(1, N):
  for j in range(i+1, N+ 1):
    if i+j != N+1:
	    print('{} {}'.format(i, j))

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

Solution (Python):
N = int(input())
a = []
cnt = 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:
                a.append('{0} {1}'.format(i, j))
                cnt += 1
else:
    for i in range(1, N+1):
        for j in range(i + 1, N+1):
            if i + j != N:
                a.append('{0} {1}'.format(i, j))
                cnt += 1
print(cnt)
for i in range(cnt):
    print(a[i])

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

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

print(m)
for i in range(len(l)):
    for j in range(i+1,len(l)):
        p = l[i]
        o = l[j]
        for point in p:
            for other in o:
                print(str(point)+" "+str(other))

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

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

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

nmod2 = N % 2
lists = []

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

print(len(lists))
for l in lists:
    print(l[0], l[1])

Solution (Python):
n=int(input())
a=[]
m=n if n&1 else n+1
i=1
while(i<=n):
    j=i+1
    while(j<=n):
        if j!=m-i:
            a+=[(i,j)]
        j+=1
    i+=1
print(len(a))
for x in a:
    print(*x)

Solution (Python):

import sys


def solve(N: int):
    if N % 2 == 0:              
        key = int(N/2)
        M = (N-2)*key
        print(M)
        for i in range(1, key+1):
            for j in range(i+1, N+1):
                if (j <= key) or\
                   (j > key and i % key != (N+1-j) % key):
                    print(i, j)
        for i in range(key+1, N):
            for j in range(i+1, N+1):
                print(i, j)
    else:
        key = int(N/2)
        M = (N-3)*key + N-1
        print(M)
        for i in range(1, key+1):
            for j in range(i+1, N+1):
                if (j <= key) or\
                   (j > key and i % key != (N-j) % key):
                    print(i, j)
                elif j == N:
                    print(i, j)
        for i in range(key+1, N):
            for j in range(i+1, N+1):
                print(i, j)
    return



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

import sys

input = sys.stdin.readline

N = int(input())

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

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

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

p = [None]
ans = []
if n % 2:
    for i in range(1, n//2+1):
        p.append((i, n-i))
    for i in range(1, n//2+1):
        x, y = p[i]
        ans.append((n, x))
        ans.append((n, y))
    for i in range(1, n//2+1):
        for j in range(i+1, n//2+1):
            x, y = p[i]
            s, t = p[j]
            ans.append((x, s))
            ans.append((x, t))
            ans.append((y, s))
            ans.append((y, t))
    k = len(ans)
    print(k)
    for i in range(k):
        print(*ans[i])
else:
    for i in range(1, n//2+1):
        p.append((i, n+1-i))
    for i in range(1, n//2+1):
        for j in range(i+1, n//2+1):
            x, y = p[i]
            s, t = p[j]
            ans.append((x, s))
            ans.append((x, t))
            ans.append((y, s))
            ans.append((y, t))
    k = len(ans)
    print(k)
    for i in range(k):
        print(*ans[i])

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

N=int(input())

EDGE=[[1]*(N+1) for i in range(N+1)]
for i in range(N+1):
    EDGE[i][i]=0
    EDGE[0][i]=EDGE[i][0]=0

SUM=[N*(N+1)//2]
for i in range(N):
    SUM.append(SUM[-1]-1)

SUM[0]=0

if N%2==0:
    ANSSUM=N*(N+1)//2-1-N
else:
    ANSSUM=N*(N+1)//2-1-(N-1)



for i in range(1,N+1):
    x=SUM[i]-ANSSUM
    EDGE[i][x]=EDGE[x][i]=0

ANS=[]
ANSCOUNT=0
for i in range(1,N+1):
    for j in range(1,N+1):
        if EDGE[i][j]==1:
            ANS.append([i,j])
            ANSCOUNT+=1
            EDGE[i][j]=EDGE[j][i]=0

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

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

res = []

if N % 2 == 0:
    for i in range(1, N + 1):
        for j in range(1, i):
            if j != N + 1 - i:
                res.append("{:d} {:d}".format(i, j))
else:
    for i in range(1, N):
        res.append("{:d} {:d}".format(N, i))
    for i in range(1, N):
        for j in range(1, i):
            if j != N - i:
                res.append("{:d} {:d}".format(i, j))

print(len(res))
for m in res:
    print(m)

Solution (Python):
N=int(input())
if N ==3:
    print(2)
    print("1 3")
    print("2 3")

else:
    if N%2==0:
        if N == 4:print(4)
        else:
            print(N // 2 * 4)
        for i in range(1, N // 2):
            x = i
            y = N + 1 - x
            nx = x + 1
            ny = y - 1
            print(str(x) + ' ' + str(nx))
            print(str(x) + ' ' + str(ny))
            print(str(y) + ' ' + str(nx))
            print(str(y) + ' ' + str(ny))
        if N > 4:
            print(str(N) + ' ' + str(N//2))
            print(str(N) + ' ' + str(N//2 + 1))
            print(str(1) + ' ' + str(N//2))
            print(str(1) + ' ' + str(N//2 + 1))
    else:
        N -= 1
        print(N // 2 * 4)
        for i in range(1, N // 2):
            x = i
            y = N + 1 - x
            nx = x + 1
            ny = y - 1
            print(str(x) + ' ' + str(nx))
            print(str(x) + ' ' + str(ny))
            print(str(y) + ' ' + str(nx))
            print(str(y) + ' ' + str(ny))
        N += 1
        if N > 3:
            print(str(N) + ' ' + str(N//2))
            print(str(N) + ' ' + str(N//2 + 1))
            print(str(N) + ' ' + str(N - 1))
            print(str(N) + ' ' + str(1))

Solution (Python):
n=int(input())
if n%2==1:
  print(n-1+int((n-1)*(n-3)*0.5))
  for i in range(1,n):
    print(n,i)
  for i in range(1,n):
    for j in range(i+1,n):
      if i+j!=n:
        print(i,j)
else:
  print(int(n*(n-2)*0.5))
  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())
m = 0
l = 0

if n % 2 == 1:
    m = (n - 1) * (n - 2) // 2 - (n - 1) // 2 + n - 1
    l = n - 1
else:
    m = n * (n - 1) // 2 - n // 2
    l = n

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

Solution (Python):
n=int(input())
l=[(i,j) for i in range(1,n+1) for j in range(i+1,n+1)]
if n%2==1:

    for i in range(1,int((n+1)/2)):
        l.remove((i,n-i))
else:
    for i in range(1,int(n/2)+1):
        l.remove((i,n-i+1))
print(len(l))
for i,j in l:
    print(i,j)

Solution (Python):
N = int(input())
ans = []
for i in range(1,N):
    for j in range(i+1,N+1):
        ans.append([i,j])
if N % 2 == 1:
    i = 0
    while i < len(ans):
        if ans[i][0] + ans[i][1] == N:
            ans.pop(i)
        else:
            i += 1
    M = len(ans)
    print(M)
    for i in range(M):
        print(str(ans[i][0])+' '+str(ans[i][1]))
else:
    i = 0
    while i < len(ans):
        if ans[i][0] + ans[i][1] == N+1:
            ans.pop(i)
        else:
            i += 1
    M = len(ans)
    print(M)
    for i in range(M):
        print(str(ans[i][0])+' '+str(ans[i][1]))

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

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


if N % 2 == 0:
    lst = [i+1 for i in range(N)]
    keyvalue = N+1

    ansedge = []

    conn = [ [False]*N for _ in range(N)]

    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if j != i and j != keyvalue-i: 
                ansedge.append( (i, j) )
                
                
    print(len(ansedge))
    for e in ansedge:
        print(*e)
    
    exit()
else:
    lst = [i+1 for i in range(N)]
    keyvalue = N

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

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

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

Solution (Python):
def makelis(eve):
    li =[]
    for i in range(eve//2):
        li.append([eve-i,i+1])
    return li

N =int(input())



if N%2==0:
    numlis = makelis(N)
else:
    numlis = makelis(N-1)
    numlis.append([N])

num =0
for li in numlis:
    num += len(li)*(N-len(li))
print(num//2)

for li in numlis:
    for j in li:
        for i in range(N):
            if not i+1 in li and j < i+1:
                print("{} {}".format(j,i+1))

Solution (Python):




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

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

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

ans = []

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

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

Solution (Python):
from itertools import combinations, product
from collections import defaultdict

N = int(input())

edges = set()
if N % 2 == 0:
    for i in range(1, N + 1):
        for j in set(range(1, N + 1)) - set([i, N + 1 - i]):
            edges.add((i, j) if i <= j else (j, i))
else:
    for i in range(1, N):
        for j in set(range(1, N)) - set([i, N - i]):
            edges.add((i, j) if i <= j else (j, i))
        edges.add((i, N))
    for i in range(1, N):
        edges.add((i, N))

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

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

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


blocks=returnSplit(N)
retval=[]

for i in range(len(blocks)):
    for j in range(i+1,len(blocks)):
        for k in itertools.product(blocks[i],blocks[j]):
            retval.append(k)


print(len(retval))
for i in retval:
    print("{0} {1}".format(*i))

Solution (Python):
N = int(input())
l = []
if N%2 == 0:
    for i in range(N):
        for j in range(i):
            I = i+1
            J = j+1
            if I+J != N+1 :
                l.append((I,J))
else:
    for i in range(N):
        for j in range(i):
            I = i+1
            J = j+1
            if I+J != N :
                l.append((I,J))
print(len(l))
for k in l:
    print("{} {}".format(k[0],k[1]))

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

grpNos = [-1]*(N+1)
if N % 2:
    grpNos[-1] = 0

N2 = N//2*2
for i in range(1, N//2+1):
    grpNos[i] = i
    grpNos[N2+1-i] = i

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

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

Solution (Python):
def list_input():
    return list(map(int,input().split()))
def map_input():
    return map(int,input().split())
def map_string():
    return input().split()
    
n = int(input())
a = []
if n%2 == 0:
	for i in range(1,n+1):
		for j in range(i+1,n+1):
			if i+j != n+1:
				a.append([i,j])
else:
	for i in range(1,n+1):
		for j in range(i+1,n+1):
			if i+j != n:
				a.append([i,j])	
print(len(a))
for i in a:
	print(i[0],i[1])

Solution (Python):
n=int(input())
if n==3:
    print(2)
    print(1,3)
    print(2,3)
elif 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!=1+n:
                print(i,j)
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):

"""
Created on Sat Mar 23 21:43:33 2019

@author: Yamazaki Kenichi
"""

N = int(input())

ans = []
if N % 2 == 1:
    for i in range(1,N):
        ans.append([i,N])
    N = N-1

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 c in ans:
    print(' '.join(map(str,c)))

Solution (Python):

import sys
import math
import numpy as np
import itertools



n = int(input())

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

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

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

num = 0
if N % 2 == 1:
    n = N // 2
    for i in range(n):
        num += 2*2*(i)
    num += N - 1
    print(num)
    for l in list[:-1]:
        print(N, l)
    list.pop(-1)
else:
    n = N // 2
    for i in range(n):
        num += 2*2*(i)
    print(num)

while(1):
    if len(list) == 2:
        break
    for l in list[1:-1]:
        print(list[-1], l)
        print(list[0], l)
    list.pop(0)
    list.pop(-1)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    ans = []
    if N % 2 == 1:
        for i in range(1, N + 1):
            j = N - i
            for k in range(1, i):
                if k not in (i, j):
                    ans.append([i, k])
    else:
        for i in range(1, N + 1):
            j = (N + 1) - i
            for k in range(1, i):
                if k not in (i, j):
                    ans.append([i, k])
    print(len(ans))
    for a, b in ans:
        print(a, b)

    return 0

main()

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

Solution (Python):
N = int(input())
 
erace1 = 1
erace2 = (N//2)*2
ans = []
for i in range(1,N):   
    for j in range(i+1,N+1):
        if i!=erace1 or j!=erace2: 
            ans.append([i,j])
        else:
            erace1 += 1
            erace2 -= 1
            
print(len(ans))
for a,b in ans:
    print(a,b)

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

Solution (Python):
def getN():
    return int(input())

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

n = getN()
def isodd(n):
    print((n-1)*(n-3)//2 + (n-1))
    for i in range(n-1):
        for j in range(i):
            if i != j and i+j != n-2:
                print(i+1, j+1)
    for i in range(n-1):
        print(n, i+1)



def iseven(n):
    print(n*(n-2)//2)
    for i in range(n):
        for j in range(i):
            if i!= j and (i+j) != n-1:
                print(i+1,j+1)
if n % 2 == 0:
    iseven(n)
else:
    isodd(n)

Solution (Python):
N = int(input())
A = []
for i in range(1, N+1):
    for j in range(i+1, N+1):
        A.append([i, j])
M = len(A)
B = []
if N%2 == 1:
    for a in A:
        if sum(a) != N:
            B.append(a)
else:
    for a in A:
        if sum(a) != N+1:
            B.append(a)
print(len(B))
for b in B:
    print(' '.join(map(str, b)))

Solution (Python):
N = int(input())
ans = []
n = 2 * (N // 2)
for x in range(1, n + 1):
    for y in range(x + 1, n + 1):
        if x + y != n + 1:
            ans += [[x, y]]
if N % 2:
    for x in range(1, N):
        ans += [[x, N]]
print(len(ans))
for edge in ans:
    print(*edge)

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

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

S = n * (n - 1) // 2
if n % 2 == 0:
    S -= 1
E = [[] for i in range(n+1)]

j = 1
for i in range(n // 2, 0, -1):
    E[i] = [k for k in range(1, n+1) if k != i and k != i + j]
    E[i + j] = E[i]
    j += 2

ans = []
for i, e in enumerate(E):
    for v in e:
        if i < v:
            ans.append((i, v))

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

Solution (Python):

N=int(input())
pairs=[]

if N%2==0:
    for j in range(N//2):
        pairs.append([j+1,N-j])
else:
    for j in range(N//2):
        pairs.append([j+1,N-j-1])
    pairs.append([N])
ans=[]
for i in range(len(pairs)):
    for j in range(len(pairs[i])):
        for k in range(len(pairs)):
            if i!=k:
                for l in range(len(pairs[k])):
                    if pairs[i][j]<pairs[k][l]:
                        ans.append([pairs[i][j],pairs[k][l]])
                    else:
                        ans.append([pairs[k][l],pairs[i][j]])

ans=sorted(ans,key=lambda x: x[1])
ans=sorted(ans,key=lambda x: x[0])
print(len(ans)//2)
for i in range(len(ans)):
    if i%2==0:
        print(*ans[i])