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.



Sample input:
3


Sample output:
2
1 3
2 3

Submission status: Accepted

Solution code:
#import collections as c
#ip = lambda : map(int, input().split())

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

# a = []
# b = []



# f = 1
# for i in range(N,0,-1):
#     if f%4==1 or f%4==0:
#         a.append(i)
#         f += 1
#     else:
#         b.append(i)
#         f += 1
# print(len(a)*len(b))
# for ia in a:
#     for ib in b:
#         print(ia,ib)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
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)))

Submission status: Accepted

Solution code:
#
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
from copy import deepcopy
from functools import reduce


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

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

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

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


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


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


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


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


if __name__ == '__main__':
    N = int(input())
    main(N)
    #for i in range(3, 101):
    #    print(i, end=":")
    #    main(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

bridge_num=0;

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

print(bridge_num);

for i in range(num*num):
    if(check_list[i]==1):
        left = i // num
        right = i % num
        print(str(left+1)+" "+str(right+1));

Submission status: Accepted

Solution code:
N = int(input())
ans = []
if N % 2 == 0:
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            if i + j != N + 1:
                ans.append((i, j))
else:
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            if i + j != N:
                ans.append((i, j))
print(len(ans))
for a in ans:
    print(' '.join(map(str, a)))

Submission status: Accepted

Solution code:
n = int(input())
res = []
if n%2 == 0:
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j == n + 1:
                continue
            res.append([i, j])
elif n % 2 == 1:
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j == n:
                continue
            res.append([i, j])
print(len(res))
for (i,j) in res:
    print(i, j)

Submission status: Accepted

Solution code:

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

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

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

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

# n, = read_ints()
# m = n * (n - 1) // 2
# for mask in range(1, 2**m):
#     edges = [[] for _ in range(n)]
#     mm = mask
#     for u in range(n):
#         for v in range(u + 1, n):
#             if mm % 2 > 0:
#                 edges[u].append(v)
#                 edges[v].append(u)
#             mm = mm // 2
#     # print(mask, edges)
#     if connected(edges) and good(edges):
#         print(edges)

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


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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())

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

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


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

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



M += 2 * N

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations

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

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

Submission status: Accepted

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

Submission status: Accepted

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

from itertools import accumulate

n = ni()

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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


# print(pairs)

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

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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


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

Submission status: Accepted

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

for nn in range(n):
  tpl = (nn+1, top-nn)
  if tpl[0] >= tpl[1]:
    break
  #print(f'removing {tpl}')
  cs.remove(tpl)

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

if N % 2 == 0:
    #偶数の場合 i , N+1-i ペア以外を出力
    print(N*(N-2)//2)
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i + j == N+1:
                continue
            print(i,j)
else:
    #奇数の場合 i, N-i ペア以外を出力
    print(((N-1)**2)//2)
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i + j == N:
                continue
            print(i,j)

Submission status: Accepted

Solution code:
N = int(input())

c = 0
ANS = []

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

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

Submission status: Accepted

Solution code:

n = int(input())

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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