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 sys,math,collections,itertools
input = sys.stdin.readline
graph = []
cnt = 0

N=int(input())
if N%2 == 0:
    
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i+j == N+1:
                continue
            else:
                cnt+=1
                graph.append([i,j])
                
else:
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i + j == N:
                continue
            else:
                cnt+=1
                graph.append([i,j])
print(cnt)
for gr in graph:
    print(*gr)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc032/tasks/agc032_b
# 完全グラフからどの辺を減らそうかって考えるとわかる

N = int(input())
ans = set()
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        ans.add((i, j))

if N & 1:  # 奇数
    N -= 1

for k in range(N // 2):
    i = k + 1
    j = N - k
    ans.remove((i, j))
print(len(ans))
for i, j in ans:
    print(i, j)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())

def check(edge, s):
    nodes = [0] * (N+1)
    for a, b in edge:
        nodes[a] += b
        nodes[b] += a
    return all([s == i for i in nodes[1:]])

def main(N):
    # 合計になる2頂点のグループを作って、その塊でつないでいく
    group_sum = N if N % 2 == 1 else N+1
    edge = set()
    for i in range(1,N+1):
        for j in range(i+1, N+1):
            if i+j == group_sum: continue
            edge.add((i,j))
    print(len(edge))
    for e in edge:
        print(*e)

main(N)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())

def check(edge, s):
    nodes = [0] * (N+1)
    for a, b in edge:
        nodes[a] += b
        nodes[b] += a
    return all([s == i for i in nodes[1:]])

def main(N):
    # 合計になる2頂点のグループを作って、その塊でつないでいく
    group_cnt = -(-N//2)
    group_sum = N if N % 2 == 1 else N+1
    s = (group_cnt - 1) * group_sum
    edge = set()
    loop_num = group_cnt if N % 2 == 0 else group_cnt - 1
    for comb in combinations(range(1, loop_num+1), 2):
        for i in (comb[0], group_sum-comb[0]):
            for j in (comb[1], group_sum-comb[1]):
                edge.add((i, j))
    if N % 2 == 1:
        for i in range(1, N):
            edge.add((i, N))
    print(len(edge))
    for e in edge:
        print(*e)
    #print(check(edge, s))

main(N)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    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 j == N - N % 2 - (i - 1):
                continue
            print(i, j)

if __name__ == '__main__':
    main()


'''
4:
 1 [ , 2, 3,  ] = 9
 2 [1,  ,  , 4] = 8
 3 [1,  ,  , 4] = 7
 4 [ , 2, 3,  ] = 6
5:
 1 [ , 2, 3,  , 5] = 10
 2 [1,  ,  , 4, 5] = 10
 3 [1,  ,  , 4, 5] = 10
 4 [ , 2, 3,  , 5] = 10
 5 [1, 2, 3, 4, ] = 10
6:
 1 [   2, 3, 4, 5,  ] = 14
 2 [1,    3, 4,  , 6] = 14
 3 [1, 2,    4, 5, 6] = 18
 4 [1, 2, 3,    5, 6] = 17
 5 [1,  , 3, 4,    6] = 14
 6 [ , 2, 3, 4, 5,  ] = 14
'''

Submission status: Accepted

Solution code:


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    table = [
        [1 for _ in range(N)] for _ in range(N)
    ]
    if N%2 == 0:
        for i in range(N//2):
            table[i][N-i-1] = table[N-i-1][i] = 0
    else:
        for i in range(N//2):
            table[i][N-i-2] = table[N-i-2][i] = 0
    size = 0
    answer = []
    for i in range(N):
        for j in range(i+1, N):
            if table[i][j]:
                answer.append((i+1, j+1))
                size += 1
    print(size)
    for a in answer:
        print(*a)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
#def MXI(): return [LI() for i in range(n)]　
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
ans=[]
if n%2==1:
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i+j==n:
                continue
            ans.append([i,j])
else:
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i+j==n+1:
                continue
            ans.append([i,j])
print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n = ni()

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
  N = int(input())
  ans = [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:
          ans[0] += 1
          ans.append([i,j])
  else:
    for i in range(1,N):
      for j in range(i+1,N):
        if i+j!=N:
          ans[0] += 1
          ans.append([i,j])
    for i in range(1,N):
      ans[0] += 1
      ans.append([N,i])
  return ans
ans = solve()
print(ans[0])
for a in ans[1:]:
  print(*a)

Submission status: Accepted

Solution code:
N = int(input())
M = N*(N-1)//2-N//2
print(M)
if N%2 ==0:
  rem = N+1
else:
  rem = N
#print(rem)
for i in range(N):
  i +=1 #1index
  for j in range(i,N):
    j +=1 #1index
    temp = [i,j]
    if i+j != rem:
      print(*temp)

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 N % 2 == 0 and i+j == N+1: continue
        if N % 2 == 1 and i+j == N: continue
        ans.append([i,j])
print(len(ans))
for a in ans:
    print(a[0],a[1])

Submission status: Accepted

Solution code:
# from itertools import product

# n = int(input())

# edge_comb = []
# for i in range(1,n):
#     for j in range(i+1,n+1):
#         edge_comb.append((i,j))


# comb_n = len(edge_comb)
# ite = product(range(2),repeat=comb_n)
# ite = list(ite)
# for it in ite:
#     it = list(it)
#     gl = [ [] for _ in range(n+1) ]
#     for i,v in enumerate(it):
#         if v == 1:
#             edge = edge_comb[i]
#             a,b = edge
#             gl[a].append(b)
#             gl[b].append(a)
    
#     sums = [0]*(n+1)
#     for i in range(n+1):
#         sums[i] = sum(gl[i])
    
#     val = sums[1]
#     for i in range(2,n+1):
#         if sums[i] != val:
#             break
#     else:
#         print(gl)

n = int(input())
gl = [ [] for _ in range(n+1) ]

if n%2 == 0:
    ng = n+1
    for i in range(1,n//2+1):
        for j in range(1,n+1):
            # if i+j != ng:
            if i != j and n+1-i != j:
                gl[i].append(j)
                gl[n+1-i].append(j)
else:
    ng = n
    for i in range(1,n//2+1):
        for j in range(1,n+1):
            if i != j and n-i != j:
                gl[i].append(j)
                gl[n-i].append(j)  
    gl[n] = list(range(1,n))

cnt = 0
for g in gl:
    cnt += len(g)

s = set()
print(cnt//2)
for i,g in enumerate(gl):
    if i == 0: continue
    for v in g:
        if (v,i) in s: continue
        print(i,v)
        s.add((i,v))

Submission status: Accepted

Solution code:
def solve():
  N = int(input())
  ans = [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:
          ans[0] += 1
          ans.append(' '.join([str(i),str(j)]))
  else:
    for i in range(1,N):
      for j in range(i+1,N):
        if i+j!=N:
          ans[0] += 1
          ans.append(' '.join([str(i),str(j)]))
    for i in range(1,N):
      ans[0] += 1
      ans.append(' '.join([str(N),str(i)]))
  return ans
print(*solve(),sep='\n')

Submission status: Accepted

Solution code:
N = int(input())
G = [[0]*N for _ in range(N)]

for i in range(N):
    for j in range(N):
        if i!=j:
            G[i][j] = 1
            G[j][i] = 1

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

Submission status: Accepted

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

print(len(G))
for g in G:
    print(*g)

Submission status: Accepted

Solution code:
N=int(input())

if N%2==0:
    S=N+1
else:
    S=N

ans=[]

for i in range(1,N+1):
    for j in range(i+1,N+1):
        if not i+j==S:
            ans.append([i,j])
print(len(ans))
for a,b in ans:
    print(a,b)

Submission status: Accepted

Solution code:
import sys
from itertools import product

input = sys.stdin.readline


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

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

    for i in range(len(groups) - 1):
        group_a = groups[i]
        group_b = groups[i + 1]
        for a, b in product(group_a, group_b):
            ans.append(f"{a} {b}")

    if len(groups) >= 3:
        group_a = groups[0]
        group_b = groups[-1]
        for a, b in product(group_a, group_b):
            ans.append(f"{a} {b}")

    print(len(ans))
    print("\n".join(ans))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
ans=[]
if n%2==0:
    s=n*(n-1)//2-1
    ss=n*(n+1)//2
    for i in range(1,n):
        t=ss-s-i
        for j in range(i+1,n+1):
            if j!=t:
                ans.append((i,j))
if n%2==1:
    s=n*(n-1)//2
    ss=n*(n+1)//2
    for i in range(1,n):
        t=ss-s-i
        for j in range(i+1,n+1):
            if j!=t:
                ans.append((i,j))
print(len(ans))
for x,y in ans:
    print(x,y)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()

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

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

# グラフが単純⇔グラフがループや多重辺をもたない
# グラフが連結⇔グラフの任意の２頂点に対し、それらを結ぶパス(辺)が存在
# 1 - 3 - 2
# 1 - 3
# |   |
# 2 - 4

# ある整数Sが存在して、任意の頂点についてその頂点に隣接する頂点の番号の値の和はSとなる
# このSは都合の良いもので設定できる

# まず全部繋ぐ N = 5の時
# 5: 1 2 3 4
# 4: 1 2 3 5
# 3: 1 2 4 5
# 2: 1 3 4 5
# 1: 2 3 4 5
# sumから何かを引いたら何かになる

N = getN()
dist = set()
if N % 2 == 0:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if i != j and i + j != (N + 1):
                dist.add((min(i, j), max(i, j)))
if N % 2 != 0:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if i != j and i + j != N:
                dist.add((min(i, j), max(i, j)))

dist = list(dist)
print(len(dist))
for a, b in dist:
    print(a, b)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

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

ans = []
for i, j in combinations(range(1, N+1), 2):
	p = N*(N+1)//2 - i
	if j == p-S:
		continue
	ans.append((i, j))

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

Submission status: Accepted

Solution code:
from itertools import*
n = int(input())
p = []
for i in combinations(range(1, n + 1), 2):
    if sum(i) != n + 1 - n % 2:
        p += i,
print(len(p))
for i in p:
    print(*i)

Submission status: Accepted

Solution code:
N = int(input())
S = N
if N % 2 == 0:
    S += 1
ans = []    
for i in range(1, N+1):
    for j in range(i+1, N+1):
        if i + j == S:
            continue
        ans += [(i, j)]
print(len(ans))
for i, j in ans:
    print(i, j)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 全点に対してつながってるとしたらsum(N)-自分の値になる
# N=4だと(1: 9, 2:8, 3: 7, 4: 6)
# これをN=3で考えてみる
# (1: 5, 2: 4, 3: 3)
# どうも最小値-1を目指せばできそうな雰囲気がある?
# N=4のときは2-3と1-4を断ち切ることになる
# N=5のとき(1: 14, 2: 13, 3: 12, 4: 11, 5: 10)
# 最小値-1の9を目指してみると構築できない...
# 10を目指してみると構築できる（1-4と2-3を断ち切る）
# N=6のとき(1: 20, 2: 19, 3: 18, 4: 17, 5: 16, 6: 15)
# 14を目指してみると構築できる(1-6, 2-5, 3-4を断ち切る)
# N=7のとき(1: 27: 2: 26, 3: 25, 4: 24, 5: 23, 6: 22, 7: 21)
# 21を目指してみると構築できる(1-6,2-5,3-4を断ち切る)
# どうやら見えちまったようだ
# 全点の辺の数は1+2+...N-2+N-1 = (N-1)*N//2（等差数列の和）、 断ち切る数はn/2

n = int(input())
t = [[True if i != j else False for j in range(n)] for i in range(n)]
edge_sum = n * (n - 1) // 2 - n // 2
for i in range(n // 2):
    t[i][n - i - (1 if n % 2 == 0 else 2)] = False
print(edge_sum)
for i in range(n):
    for j in range(i + 1, n):
        if t[i][j]:
            print(f"{i+1} {j+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 i,j in ans:
    print(i,j)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    cnt = n
    if n % 2:
        cnt -= 1

    edge = []
    for i in range(n):
        for j in range(i + 1, n):
            if j + 1 == cnt:
                continue
            edge.append([i + 1, j + 1])
        cnt -= 1

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    # Nが奇数(2 * M + 1)
    #    ノード n と N - n の間に枝が無く、それ以外のすべての枝があるグラフでOK。
    # Nが偶数(2 * M)
    #    ノード n と N + 1 - n の間に枝が無く、それ以外のすべての枝があるグラフでOK。
    # 両ケースとも、枝は N * (N - 1) // 2 - M = N * (N - 1) // 2 - N // 2 本。
    edges = list()
    if N % 2 == 1:
        for i in range(1, N):
            for j in range(i + 1, N + 1):
                if i + j != N:
                    edges.append((i, j))
    else:
        for i in range(1, N):
            for j in range(i + 1, N + 1):
                if i + j != N + 1:
                    edges.append((i, j))
    print(len(edges))
    for e in edges:
        print('{} {}'.format(e[0], e[1]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def od(n):
    ret = set([])
    for i in range(n):
        for j in range(i+1,n):
            if i+j+2 != n+1:
                ret.add((i+1, j+1))
    return ret

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

    ret = od(N//2*2)
    if N%2==1:
        for i in range(N-1):
            ret.add((i+1, N))

    print(len(ret))
    for x, y in ret:
        print(x,y)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()

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

    print(len(ans))
    print('\n'.join(map(lambda a: '{} {}'.format(a[0], a[1]), ans)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N = int(input())
a = [i+1 for i in range(N)]
li = list(itertools.combinations(a,2))
n = len(li)
if N % 2 == 1:
    print(N*(N-1)//2-N//2)
else:
    print(N*(N-1)//2-N//2)
for i in range(n):
    a,b = li[i]
    if N % 2 == 1:
        if a+b != N:
            print(a,b)
    else:
        if a+b != N+1:
            print(a,b)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    res = []
    remove = n
    if n % 2 != 0:
        remove -= 1

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

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
count = 0
print(nCr(N,2)-N//2)
for i in range(1,N+1):
  for j in range(1,N+1):
    if i+j != N+(1-N%2) and i<j:
      print(i,j)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    res = []
    c = n
    if n % 2 != 0:
        c -= 1

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

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
x = n % 2

ans = []
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if x == 0:
            if i == n+1-j:
                continue
            ans.append((i,j))
        else:
            if i == (n-j):
                continue
            ans.append((i,j))
            
print(len(ans))
for i in ans:
    print(*i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
tmp = N
ans = []
if tmp%2 == 1:
    tmp -= 1
for i in range(1,tmp+1):
    for j in range(1,tmp+1):
        if i < j and j != tmp+1-i:
            ans.append((i,j))
if N%2 == 1:
    for i in range(1,N):
        ans.append((i,N))
print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

Submission status: Accepted

Solution code:
n = int(input())
d = n
ans = []
if n % 2 == 1: d -= 1

for i in range(1, n+1):
    for j in range(1, n+1):
        if j <= i or j == d: continue
        ans.append([i, j])
    d -= 1

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