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 math import factorial

n=int(input())

print(factorial(n)//factorial(n-2)//2-n//2)

m = (n//2)*2
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if i+j != m+1:
            print(i,end=' ')
            print(j)

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

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

Solution (Python):
"""
234 23
134 14
124 14
123 23
"""
import copy
N = int(input())
initial = [list(range(1, N + 1)) for i in range(N)]

for i in range(N):
    initial[i].pop(i)

neighbors = copy.deepcopy(initial)

S = sum(neighbors[-1])  

while True:
    
    
    for i, tyouten in enumerate(neighbors):
        delta = sum(tyouten) - S
        
        if delta in tyouten:
            tyouten.remove(delta)
            neighbors[delta - 1].remove(i + 1)
        elif delta == 0:
            continue
        else:
            S -= 1
            neighbors = copy.deepcopy(initial)
            break
    else:
        break



ans = []
for i, tyouten in enumerate(neighbors):
    for j in tyouten:
        if j > i+1:
            ans.append(str(i+1)+" "+str(j))

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

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

group_sum = N if N % 2 == 1 else N + 1

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

print(len(ans))
for edge in ans:
    print(" ".join(map(str, edge)))

Solution (Python):
from itertools import combinations

N = int(input())
E = [(u, v) for u, v in combinations(range(1, N+1), 2) if u + v != (N//2)*2 + 1]
print(len(E))
for u, v in E: print(u, v)

Solution (Python):
import sys
from collections import deque, defaultdict
import copy
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


N = int(input())

group = []
n = N
if N % 2 == 1:
    group.append([N])
    n -= 1

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



edge = []

for i in range(len(group)-1):
    for x in group[i]:
        for y in group[i+1]:
            edge.append([x, y])

if len(group) > 2:
    for x in group[len(group)-1]:
        for y in group[0]:
            edge.append([x, y])

print(len(edge))

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

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

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

Solution (Python):
n=int(input())
s=set()
for i in range(1,n//2+1):
    if n%2==1:
        s.add((i,n-i))
    else:
        s.add((i,n+1-i))
m=len(s)
print(n*(n-1)//2-m)
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if (i,j) in s:
            pass
        else:
            print(i,j)

Solution (Python):
N = int(input())
s = 0
for i in range(1, N):
  for j in range(i + 1, N + 1):
    if i + j + (N % 2) != N + 1:
      s+=1
print(s)
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())
l=[]
def upgrade(edge):
    s=len(edge)
    for i in range(s):
        [a,b]=edge[i]
        edge[i]=[a+1,b+1]

def odd(edge,n):
    for i in range(n-1):
        edge.append([n,i+1])

def even(edge,n):
    upgrade(edge)
    for i in range(1,n):
        edge.append([1,i+1])

def print_edge(edge):
    s=len(edge)
    for i in range(s):
        [a,b]=edge[i]
        print(a,b)

edge=[]

edge.append([1,3])
edge.append([2,3])
for i in range(3,n):
    if i%2==0:
        odd(edge,i+1)
    elif i%2==1:
        even(edge,i)

print(len(edge))
print_edge(edge)

Solution (Python):
n = int(input())
tn = n - n%2

edge_num = tn * (tn - 2) // 2
if n % 2 == 1:
    edge_num += n - 1
print(edge_num)

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

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("{} {}".format(i,j))
else:
  for i in range(1,N):
    for j in range(i+1,N+1):
      if i+j != N:
        print("{} {}".format(i,j))

Solution (Python):
import sys
import math


input = sys.stdin.readline()

N = int(input)


M = (N*(N-1)/2)-N/2
print(math.ceil(M))


X = N + 1 - N % 2
for i in range(1, N+1):
    for j in range(i+1,N+1):
        if not i + j == X:
            print(i, " ", j)

Solution (Python):

import sys
from itertools import combinations

n = int(input())

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

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

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

edges = []
 
for i in range(1, n + 1):
  for j in range(i + 1, n + 1):
    if n % 2 == 1 and i + j != n \
    or n % 2 == 0 and i + j != n + 1:
      edges.append((i, j))

print(len(edges))

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

Solution (Python):
def print_even_case(N):
    for i in range(1, N ):
        for j in range(i + 1, N + 1):
            if i + j != N + 1:
                print("{} {}".format(i, j))

N = int(input())

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

Solution (Python):

from sys import stdin




def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()

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

ans = []
for i in range(len(groups)):
    for j in range(i+1, len(groups)):
        if i == j:
            continue
        else:
            for g1 in groups[i]:
                for g2 in groups[j]:
                    ans.append([g1, g2])

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

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

Solution (Python):

def main():
    N = int(input())
    
    a = N - N%2 - 1
    ans = []
    for i in range(N-1):
        for t in range(i+1,N):
            if i+t != a:
                ans += [{i+1,t+1}]
    
    print(len(ans))
    print('\n'.join("{} {}".format(i,t) for i,t in ans))

main()

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

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

for i in range(n):
    for j in range(i+1, n+1):
        if j != n - i and j != i + 1:
            ans.append((i+1, j))

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

Solution (Python):

n = int(input())


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


edges = []
for i, frag in enumerate(fragments):
    for vtx in frag:
        other_frags = fragments[:i] + fragments[i + 1:]
        edges.extend([(vtx, o_vtx) for o_frag in other_frags for o_vtx in o_frag])


for edge in edges[:]:
    if edge[0] > edge[1]:
        edges.remove(edge)


print(len(edges))
for edge in edges:
    print(' '.join(str(i) for i in edge))

Solution (Python):

def main():
    num = int(input())
    data = []
    if num % 2 == 0:
        for i in range(num // 2):
            data.append([i + 1, num - i])
    else:
        for i in range((num - 1) // 2):
            data.append([i + 1, num - 1 - i])
        data.append([num])

    ans = []
    for i in range(len(data) - 1):
        for from_num in data[i]:
            for j in range(i+1, len(data)):
                for to_num in data[j]:
                    ans.append([from_num, to_num])

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


if __name__ == '__main__':
    main()

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

def graph(N):
    if N % 2 != 0:
        E = graph(N - 1)
        E.extend((i, N) for i in range(1, N))
    else:
        E = [(i, j) for i in range(1, N)
                    for j in range(i + 1, N + 1) if i + j != N + 1]
    return E

E = graph(N)
print(len(E))
print('\n'.join(' '.join(map(str, e)) for e in E))

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, n + 1):
            if i + j != n + 1 and i != j:
                print(str(i) + " " + str(j))

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

Solution (Python):
N=int(input())
if N&1==1:
    M=(N-1)*(N-1)//2
    print(M)
    for n in range(1,N):
        for k in range(n+1,N):
            if n+k==N:
                continue
            print(n,k)
    for n in range(1,N):
        print(N,n)
else:
    M=N*(N-2)//2
    print(M)
    for n in range(1,N+1):
        for k in range(n+1,N+1):
            if n+k==N+1:
                continue
            print(n,k)

Solution (Python):
n,a,b=int(input()),[],[]
m=n+(n%2==0)
for i in range(1,n):
  for j in range(i+1,n+1):
    if i+j!=m:a.append(i);b.append(j)
l=len(a)
print(l)
for i in range(l):print(a[i],b[i])

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

if n % 2 == 0:
    temp = n + 1
else:
    temp = n

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

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

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

if n % 2 == 0:
    temp = n + 1
else:
    temp = n

for i in range(1, n):
    for j in range(i+1, n+1):
        if i + j != temp:
            ans.append((i, j))

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

Solution (Python):


from itertools import combinations

def main():
    n = int(input())
    base = list(range(1, n + 2))
    if n % 2 == 0:
        numbers = [[base[i], base[n-1-i]] for i in range(n // 2)]
    else:
        numbers = [[n]]
        for i in range(n //2):
            numbers.append([base[i], base[n-2-i]])

    result = []
    for first, second in combinations(numbers, 2):
        for fv in first:
            for sv in second:
                result.append((fv, sv))
    print(len(result))
    for r in result:
        print(r[0], r[1])


if __name__ == '__main__':
    main()

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

    
    return [(i+1, j+1) for i in range(N) for j in range(i+1,N) if i+j != N-1]


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

    ans = balanced_neighbors(N)
    print(len(ans))
    for x, y in ans:
        print(x, y)

Solution (Python):


n = int(input())

table =  [[ 1 for i in range(0, n)] for j in range (0,n)]



if n % 2 == 1 : 
    m = n-2
else :
    m = n-1

for i in range (0, n) : 
    table[i][m-i] = 0


print (n*(n-1)//2 - n//2 )
for i in range (0,n):
    for j in range (0,i):
        if table[i][j] ==1 :
            print (i+1, j+1)

Solution (Python):
n = int(input())
if n % 2 == 0:
    a = [(i, n - i + 1) for i in range(1, n // 2 + 1)]
else:
    a = [(i, n - i) for i in range(1, n // 2 + 1)]
    a.append((n,))
ans = []
for i in range(len(a) - 1):
    for a1 in a[i]:
        for a2 in a[i+1]:
            ans.append((a1, a2))
if len(a) > 2:
    for a1 in a[0]:
        for a2 in a[len(a)-1]:
            ans.append((a1, a2))
print(len(ans))
for i in ans:
    print('{} {}'.format(i[0], i[1]))

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

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

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

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

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(str(i) + ' ' + str(j))

print(len(ans))
print(*ans, sep='\n')

Solution (Python):
import sys
N=int(input())
if N%2==1:
    L=[]
    for i in range(1,N):
        for j in range(i,N):
            if i==j or i+j==N:
                continue
            L.append((i,j))
    for i in range(1,N):
        L.append((i,N))
    print(len(L))
    for a,b in L:
        print(a,b)
else:
    L=[]
    for i in range(1,N+1):
        for j in range(i,N+1):
            if i==j or i+j==N+1:
                continue
            L.append((i,j))
    print(len(L))
    for a,b in L:
        print(a,b)

Solution (Python):
import numpy as np

def main():
    n = int(input())
    a = []
    b = []

    if n % 2:
        ma = n
    else:
        ma = n + 1
    for i in range(1, n+1):
        for j in range(1, n+1):
            if i + j != ma and i < j:
                a.append(i)
                b.append(j)

    print(len(a))
    for i, j in zip(a, b):
        if i < j:
            print(i, j)


if __name__ == '__main__':
   main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def 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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


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

    l = len(g)
    for i in range(l):
        for j in range(i+1,l):
            for c in g[i]:
                for d in g[j]:
                    rr.append('{} {}'.format(c, d))

    return '{}\n{}'.format(len(rr), '\n'.join(rr))


print(main())

Solution (Python):
n = int(input())
a = [[0]*(n+1) for i in range(n+1)]
np = (n//2)*2

for i in range(0,np//2):
    a[i+1][np-i] = -1

print(int(n*(n-1)/2-(n//2)))

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

Solution (Python):
n=int(input());print(*[~-n*~-n//2]+['%d %d'%(i,j)*(j>i!=n-j+1-n%2)for i in range(1,n)for j in range(n+1)])

Solution (Python):
n=int(input());print(*[(n-1)**2//2]+['%d %d'%(i,j)*(j>i!=n-j+1-n%2)for i in range(1,n)for j in range(n+1)])

Solution (Python):
n=int(input())
for a in[[n*~-n//2-n//2]]+[(i,j)*(j>i!=n-j+1-n%2)for i in range(1,n)for j in range(n+1)]:print(*a)

Solution (Python):
n=int(input())
for a in[[n*~-n//2-n//2]]+[(i,j)*(i!=n-j+1-n%2)for i in range(1,n)for j in range(i+1,n+1)]:print(*a)

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

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

Solution (Python):
def main():
    N = int(input())
    if N % 2 == 0:
        pair = N + 1
    else:
        pair = N
    ans = set()
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i+j != pair:
                ans.add((i, j))
    print(len(ans))
    for a in ans:
        print(a[0], a[1])


if __name__ == "__main__":
    main()

Solution (Python):

N = int(input())



M = (
    N * (N - 1) // 2 - N // 2 if N % 2 == 0 else
    N * (N - 1) // 2 - (N - 1) // 2
)
s = N + 1 if N % 2 == 0 else N
ans = str(M) + '\n' + '\n'.join(
    '{} {}'.format(i, j)
    for i in range(1, N)
    for j in range(i + 1, N + 1)
    if i + j != s
)


print(ans)

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

Solution (Python):

N = int(input())

matrix = [[1 for i in range(N)] for i in range(N)]
for i in range(N):
    matrix[i][i] = 0

if N%2==0:
    for i in range(N):
        matrix[i][N-i-1] = 0
else:
    for i in range(N-1):
        matrix[i][N-i-2] = 0

print(int((N*(N-1)/2)-int(N/2)))
for i in range(N):
    for j in range(i+1,N):
        if matrix[i][j] == 1:
            print(i+1,j+1)

Solution (Python):
N=input()
p=N if N%2 else N+1
ls = []
for i in range(N):
 for j in range(i + 1, N):
  if i+j +2 != p:
   ls += [(i+1, j+1)]

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

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

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

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

ls = [i for i in range(1,N+1)]
import itertools
plist = list(itertools.combinations(ls,2))
ls = []
cnt=0
all_pattern = len(plist)
if N % 2== 0:
    print(all_pattern-(N//2))
    idx_x = N
else:
    print(all_pattern-(N-1)//2)
    idx_x = N-1
idx_y = 1
for p in plist:
    if p[0] == idx_y and p[1]==idx_x:
        idx_x = idx_x -1
        idx_y = idx_y +1
    else:
        print(p[0],p[1])

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==0:
    for i in range(1,N//2+1):
        ans.remove((i,N+1-i))
else:
    for i in range(1,N//2+1):
        ans.remove((i,N-i))
print(len(ans))
for a in ans:
    print(a[0],a[1])

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

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

Solution (Python):
N=int(input())
X=[0 for i in range(N)]
if N%2==0:
    for i in range(N//2):
        X[i]=i+1
        X[-i-1]=i+1
else:
    for i in range(N//2):
        X[i]=i+1
        X[-i-2]=i+1
    X[-1]=N//2+1
edge=[]
for i in range(N):
    for j in range(N):
        if i<=j:
            continue
        if X[i]!=X[j]:
            edge.append((i+1,j+1))
print(len(edge))
for line in edge:
    x,y=line
    print(x,y)

Solution (Python):
def b_balanced_neighbors(N):
    """
    整数Nに対し、N頂点の無向グラフで、以下の条件を満たすものを1つ構成せよ。
    1. 単純かつ連結
    2. ∀S∈Z, ∀k, 頂点kに隣接する頂点の番号の値の和がS
    """

    
    
    
    
    
    
    
    
    
    
    pair_sum = N + 1 - (N % 2)
    ans_tmp = []
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            if i + j != pair_sum:
                
                ans_tmp.append((i, j))
    return '\n'.join([str(len(ans_tmp))] + [' '.join(map(str, a)) for a in ans_tmp])

N = int(input())
print(b_balanced_neighbors(N))

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:
            ans.append([i, j])

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

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

if n % 2 == 0:
    nn = n
    print(n*(n-2)//2)
else:
    nn = n-1
    print(nn*(nn-2)//2+nn)



for i in range(1,nn//2):
    for j in range(i+1,nn//2 + 1):
        print(i,j)
        print(i,nn+1-j)
        print(nn+1-i,j)
        print(nn+1-i,nn+1-j)

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

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

bridge = []
for i in range(1, N):
    for j in range(i + 1, N + 1):
        if(N % 2 == 0):
            if(i + j == N + 1):

                continue
        else:
            if(i + j == N):

                continue
        bridge.append([i, j])

print(str(len(bridge)))
for i in bridge:
    print(" ".join(map(str, i)))

Solution (Python):

def find(n):
    """
    tn = int(n/2)
    s = 2 * tn + 1
    :param n:
    :return:
    """
    tn = int(n / 2)
    s = 2 * tn + 1
    count = 0
    line_list = []
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j != s:
                line_list.append(str(i) + " " + str(j))
                count += 1

    return count, line_list


if __name__ == '__main__':
    n = int(input())

    count, line_list = find(n)
    print(count)
    for item in line_list:
        print(item)

Solution (Python):


import sys

INF = float('inf')
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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()

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

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


main()

Solution (Python):

N=int(input())
Msum=int(N*(N-1)/2)
subedge=[]
if N%2==0:
    for i in range(int(N/2)):
        subedge.append([i+1,N-i])
    M=Msum-len(subedge)
else:
    for i in range(int((N-1)/2)):
        subedge.append([i+1,N-i-1])
    M=Msum-len(subedge)
print(M)
for i in range(N-1):
    j=0
    for j in range(N-i-1):
        I=i+1
        J=I+j+1
        edge=[I,J]
        if edge not in subedge:
            print(I,J)
        else:
            pass

Solution (Python):
n = int(input())
l = []
if n%2==1:
    for i in range((n-1)//2):
        l.append([i+1,n-1-i])
    l.append([n,n])
else:
    for i in range(n//2):
        l.append([i+1,n-i])
ans = []
for i in range(len(l)):
    for j in range(len(l)):
        if i==j:
            continue
        ret1 = [l[i][0],l[j][0]]
        ret2 = [l[i][0],l[j][1]]
        ret3 = [l[i][1],l[j][0]]
        ret4 = [l[i][1],l[j][1]]
        ret1.sort()
        ret2.sort()
        ret3.sort()
        ret4.sort()
        ret = [ret1,ret2,ret3,ret4]
        for ret_ in ret:
            if not ret_ in ans:
                ans.append(ret_)
print(len(ans))
for ans_ in ans:
    print(ans_[0],ans_[1])

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def func(root, left, right):
    if right <= left:
        return
    print root, right
    print root, left
    func(right, left + 1, right - 1)

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    s = 0
    sum_list = [0 for i in range(N + 1)]
    for i in range(1, N + 1):
        sum_list[i] = sum_list[i - 1] + i
        s += i


    if N % 2 == 0:
        groups = []
        for i in range(1, N/2 + 1):
            groups.append((i, N-i + 1))
        groups = set(groups)
        groups_copy = copy.deepcopy(groups)
        pair = []
        for g1 in groups:
            groups_copy.remove(g1)
            for g2 in groups_copy:
                    for nd1 in g1:
                        for nd2 in g2:
                            if nd1 != 0 and nd2 != 0:
                                pair.append((nd1, nd2))
        print len(pair)
        for i in range(len(pair)):
            print pair[i][0], pair[i][1]














    else:
        groups = [(N, 0)]
        for i in range(1, N/2 + 1):
            groups.append((i, N-i))
        groups = set(groups)
        groups_copy = copy.deepcopy(groups)
        pair = []
        for g1 in groups:
            groups_copy.remove(g1)
            for g2 in groups_copy:
                    for nd1 in g1:
                        for nd2 in g2:
                            if nd1 != 0 and nd2 != 0:
                                pair.append((nd1, nd2))
        print len(pair)
        for i in range(len(pair)):
            print pair[i][0], pair[i][1]




if __name__ == '__main__':
    main()

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

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

print(cnt)

for i in range(1, N + 1):
    for g in G[i]:
        print(i, g)

Solution (Python):

import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        N = int(input())
    else:
        pass

    T = np.asarray([False]*(N**2))
    T = T.reshape(N,N)
    Res = np.copy(T)
    range_N = np.asarray(range(N))
    

    if N % 2 == 0:
        for i,j in zip(range_N,range_N[::-1]):
            if i >= j: break
            T[i,j] = True
            T[j,i] = True
    else:
        for i,j in zip(range_N,range_N[::-1]):
            j -= 1
            if i >= j: break
            T[i,j] = True
            T[j,i] = True

    Res[T==True] = False
    Res[T==False] = True
    
    for i in range_N:
        Res[i,i] = False

    
    print(Res[Res].size//2)

    for i in range_N:
        for j in range_N[i:]:
            if Res[i,j] == True: print(i+1,j+1)
if __name__ =='__main__':
    main()

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

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

Solution (Python):

import sys


def solve(N: int):
    if N % 2 == 0:              
        tot = N+1
    else:
        tot = N
    ans = []
    for i in range(1, N):
        for j in range(i+1, N+1):
            if i + j == tot:
                continue
            ans.append([i, j])
    print(len(ans))
    for a in ans:
        print(*a, sep=" ")

    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):
N = int(input())
ans = []
for i in range(1,N):
    for j in range(i+1,N+1):
        if i+j!=(N//2)*2+1:
            ans.append([i,j])

print(len(ans))
[print(a,b) for a,b in ans]

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

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