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:
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    n = int(input())
    if n%2 == 0:
        ans = []
        m = n//2
        for i in range(1,m):
            ans.append((i,n - i))
            ans.append((i,i + 1))
            ans.append((i + 1,n - i + 1))
            ans.append((n - i,n - i + 1))
        
        if n > 4:
            ans.append((1,m))
            ans.append((1,m + 1))
            ans.append((m,n))
            ans.append((n,m + 1))
        
        print(len(ans))
        for i in range(len(ans)):
            print(*ans[i])
    
    else:
        if n == 3:
            ans = [[1,3],[2,3]]
            print(2)
            for i in range(2):
                print(*ans[i])
        else:
            ans = []
            m = n//2
            for i in range(1,m):
                ans.append((i,n - i - 1))
                ans.append((i,i + 1))
                ans.append((i + 1,n - i))
                ans.append((n - i,n - i - 1))
            
            ans.append((m,n))
            ans.append((m + 1,n))
            ans.append((1,n))
            ans.append((n,n - 1))

            print(len(ans))
            for i in range(len(ans)):
                print(*ans[i])

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
sys.setrecursionlimit(10 ** 7)

n = int(readline())
graph = []
for i in range(1, n):
    for j in range(i + 1, n + 1):
        graph.append([i, j])
if n % 2 == 0:
    for i in range(n // 2):
        graph.remove([i + 1, n - i])
else:
    for i in range(n // 2):
        graph.remove([i + 1, n - i - 1])
print(len(graph))
for ans in graph:
    print(*ans)

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

Submission status: Accepted

Solution code:
from itertools import combinations
n=int(input())
A,B=[i+1 for i in range(n)],[]
num=n if n%2==1 else n+1
for a,b in combinations(A,2):
    if a+b!=num:B.append([a,b])
print(len(B))
for i in B:print(*i)

Submission status: Accepted

Solution code:
from itertools import combinations
n=int(input())
A=[i+1 for i in range(n)]
num=n if n%2==1 else n+1

B=[]
for a,b in combinations(A,2):
    if a+b!=num:B.append([a,b])

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    ans = []
    tmp = [i for i in range(2, n + 1) if i != n - (n & 1)]
    l = 0
    r = n - 3 - (n & 1)
    for i in range(n // 2):
        ans.append(tmp[::1])
        tmp[l] -= 1
        tmp[r] += 1
        l += 1
        r -= 1
    ans += ans[::-1]
    l = []
    for i in range(1, n):
        for t in ans[i - 1]:
            if i < t:
                l.append((i, t))
    print(len(l))
    for li in l:
        print(*li)




    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

    M=len(hen)
    print(M)
    for i in range(0,M):
        print(*hen[i])

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

    M=len(hen)
    print(M)
    for i in range(0,M):
        print(*hen[i])

Submission status: Accepted

Solution code:
from itertools import combinations as comb

N = int(input())
n = N-N%2
s = {(i, n+1-i) for i in range(1, N+1) if i<n+1-i}

l = [i for i in comb(range(1, N+1), 2) if not i in s]
print(len(l))
for i in l:
    print(*i)

Submission status: Accepted

Solution code:
from itertools import combinations as comb

N = int(input())
n = N-1 if N%2 else N
m = N if N%2 else N+1
s = {(i, n+1-i) for i in range(1, N+1) if i<n+1-i}

l = [i for i in comb(range(1, N+1), 2) if not i in s]
print(len(l))
for i in l:
    print(*i)

Submission status: Accepted

Solution code:
from itertools import combinations as comb

N = int(input())
n = N-1 if N%2 else N
s = set()

for i in range(1, N+1):
    if N%2:
        a, b = i, N-i
    else:
        a, b = i, N-i+1
    if a<b:
        s.add((a, b))

l = [i for i in comb(range(1, N+1), 2) if not i in s]
print(len(l))
for i in l:
    print(*i)

Submission status: Accepted

Solution code:

def Com(n, k):
    p, q = 1, 1
    for i in range(n-k+1, n+1):
        p *= i
    for i in range(2, k+1):
        q *= i
    return p//q

N = int(input())
print(Com(N, 2)-N//2)
if N & 1:
    for i in range(1, N):
        for j in range(i+1, N+1):
            if i+j != N:
                print(i, j)
else:
    for i in range(1, N):
        for j in range(i+1, N+1):
            if i+j != N+1:
                print(i, j)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    if(N&1):
        print((N+1)*(N-1)//2 -(N-1))
        pair = N-2
        for i in range(N):
            for j in range(i+1,N):
                if(i+j != pair):
                    print(i+1,j+1)
    else:
        print(N*(N-2)//2)
        pair = N-1
        for i in range(N):
            for j in range(i+1,N):
                if(i+j != pair):
                    print(i+1,j+1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
edges = set()
X = 10**5
if N % 2 == 1:
    for i in range(N//2):
        i_ = i+1
        j_ = N-i-1
        # print(i_,j_)
        edges.add(min(i_,j_)*X+max(j_,i_))
else:
    for i in range(N//2):
        i_ = i+1
        j_ = N-i
        # print(i_,j_)
        edges.add(min(i_,j_)*X+max(j_,i_))
        
# print(edges)

print(N*(N-1)//2-len(edges))
for i in range(N):
    for j in range(i+1,N):
        i_ = i+1
        j_ = j+1
        if i_*X + j_ in edges:
            continue
        else:
            print(i_,j_)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
lst = [(i+1) for i in range(n)]
ans = []
for x,y in combinations(lst, 2):
    if n%2==0:
        if x+y==n+1:
            continue
    if n%2!=0:
        if x+y==n:
            continue
    ans.append((x,y))
print(len(ans))
for x,y in ans:
    print(x,y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

sum = (n // 2) * 2 + 1

ans = []

for i in range(1, n + 1):
	for j in range(i + 1, n + 1):
		if i + j != sum:
			ans.append([i, j])
print(len(ans))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 完全グラフを考える。
# 隣接する頂点の番号の値は、1〜Nの和から自分自身を引いたもの。

# →奇数の場合は、7ならば1-6, 2-5, 3-4の辺を削除する
# →偶数の場合は、6ならば同上

n = int(input())
if n % 2 == 0:
    excluded_sum = n+1
else:
    excluded_sum = n

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

for i in range(1, n+1):
    for j in range(i+1, n+1):
        if i+j == excluded_sum:
            continue
        else:
            print('{} {}'.format(i, j))

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
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 == 0:
	print(N*(N-2)//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:
N = int(input())
M = N * (N - 1) // 2 - N // 2
S = N // 2 * 2 + 1

print(M)

for i in range(1, N):
    for j in range(i + 1, N + 1):
        if i + j == S:
            continue
        print(i, j)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""from collections import *
from itertools import
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys
#input = sys.stdin.readline


"""
import copy
from collections import *
from heapq import *
N=int(input())

lst=[]

if N%2==0:
    for i in range(N-1):
        for m in range(i+1,N):
            if m !=(N-i-1):
                lst.append([i,m])
else:
    for i in range(N):
        for m in range(i+1,N):
            if m !=(N-i-2):
                lst.append([i,m])
print(len(lst))
for a,b in lst:
    print(a+1,b+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    if n % 2 == 0:
        ans = []
        for i in range(1, n//2):
            ans.append([i, i+1])
            ans.append([i, n-i])
            ans.append([n-i+1, i+1])
            ans.append([n-i+1, n-i])
        if n >= 6:
            ans.append([1, n//2])
            ans.append([1, n//2+1])
            ans.append([n, n//2])
            ans.append([n, n//2+1])
        print(len(ans))
        for p, q in ans:
            print(p, q)
    else:
        ans = []
        n -= 1
        for i in range(1, n//2):
            ans.append([i, i+1])
            ans.append([i, n-i])
            ans.append([n-i+1, i+1])
            ans.append([n-i+1, n-i])
        ans.append([1, n+1])
        ans.append([n, n+1])
        if n >= 4:
            ans.append([n//2, n+1])
            ans.append([n//2+1, n+1])
        print(len(ans))
        for p, q in ans:
            print(p, q)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#うまくグルーピングしてあげればおｋ
#奇数の場合,一番大きい数字をソロ、それ以外は2個ずついい感じで分ける
#偶数の場合は、i番目に大きいやつとi番目に小さいやつをペア
n = int(input())
ans = []
if n % 2 == 0:
    for i in range(1,n+1):
        for j in range(i,n+1):
            #自分と、自分のペア以外に辺を張る
            if j != i and i + j != n + 1:
                ans.append([i,j])
    print(len(ans))
    for i in range(len(ans)):
        print("{} {}".format(ans[i][0], ans[i][1]))
else:
    for i in range(1,n):
        #頂点nからは全ての辺に対して張る
        ans.append([n,i])
        for j in range(i,n):
            #自分と、自分のペア以外に辺を張る
            if j != i and i + j != n:
                ans.append([i,j])
    print(len(ans))
    for i in range(len(ans)):
        print("{} {}".format(ans[i][0], ans[i][1]))

Submission status: Accepted

Solution code:
N=int(input())
A=[]
B=[]
if N%2==0:
  for i in range(1,N):
    for j in range(i+1,N+1):
      A.append((i,j))
  for i in range(N//2):
    B.append((i+1,N-i))
  D=set(A)-set(B)
  print(len(D))
  for a,b in D:
    print(a,b)
else:
  for i in range(1,N):
    for j in range(i+1,N+1):
      A.append((i,j))
  for i in range(N//2):
    B.append((i+1,N-i-1))
  D=set(A)-set(B)
  print(len(D))
  for a,b in D:
    print(a,b)

Submission status: Accepted

Solution code:
N = int(input())
edges = []
for i in range(1, N // 2 + 1):
    j = N - i + 1 - N % 2
    for k in range(1, N+1):
        if k == i or k == j:
            continue
        if i < k:
            edges.append((i, k))
        if j < k:
            edges.append((j, k))
print(len(edges))
for a, b in edges:
    print(a, b)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

Submission status: Accepted

Solution code:
"""
・偶奇に分けて考える
・完全グラフと正解のグラフを比較する
・「任意の頂点」と「その頂点から削除する辺」の関係を考える

偶数
-> 和が(N+1)となる頂点を繋いでいない
奇数
-> 頂点Nからは全て引く。
-> それ以外は、和がNとなる頂点を繋いでいない。
"""

N = int(input())

M = 0
ans = []

# 1 <= i < j <= N

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

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

Submission status: Accepted

Solution code:
# 解答AC

N = int(input())

M = 0
ans = []

# 1 <= i < j <= N

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

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

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    M = 0
    Ans = []
    if N % 2 == 0:
        for i in range(1, N):
            for j in range(i + 1, N + 1):
                if i + j != N + 1:
                    Ans.append([i, j])
                    M += 1
    else:
        for i in range(1, N):
            for j in range(i + 1, N + 1):
                if i + j != N:
                    Ans.append([i, j])
                    M += 1
    print(M)
    for i, j in Ans:
        print(i, j)


    return 0

if __name__ =="__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

com = []

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

for i in range(len(com) - 1):
    for j in com[i]:
        for k in com[i+1 : ]:
            for l in k:
                print('{} {}'.format(j,l))

Submission status: Accepted

Solution code:
N=int(input())
V=[[i,N//2*2-i+1] for i in range(1,N//2+1)]
if N&1:
    V+=[[N]]
E=[]
for u in range(len(V)):
    for v in range(len(V)):
        if u!=v:
            for x in V[u]:
                for y in V[v]:
                    if x<y:
                        E.append((x,y))
print(len(E))
for x,y in E:
    print(x,y)

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

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

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())

# 全結合netから一部を消すとうまくいく
# N:evenだと 1,2,3,4,5,6 なら、(1,6)(2,5)などのペアを消す
# N:odd だと 1,2,3,4,5 なら5を残して、(1,4)(2,3)のペアを消す

S = set()
for i in range(1,N):
  for j in range(i+1,N+1):
    S.add((i,j))
    
#print(S)
if N%2 == 0:
  for i in range(1,N+1):
    if i >= N-i+1:
      break
    S.remove((i,N-i+1))
    #print(i,N-i+1)
else:
  for i in range(1,N):
    if i >= N-i:
      break
    S.remove((i,N-i))
    #print(i,N-i+1)
print(len(S))
for item in S:
  print(" ".join(list(map(str, item))))

Submission status: Accepted

Solution code:
N=int(input())

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

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

cnt=0

for i in range(1,N+1):
    for j in range(i+1,N+1):
        if i+j != S:
            G[i].append(j)
            cnt+=1

print(cnt)
for i in range(1,N+1):
    for j in range(len(G[i])):
        print(i,G[i][j])

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()

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

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

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:
                continue
            ans.append((i, j))
else:
    # 奇数のとき
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i + j == N:
                continue
            ans.append((i, j))

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

Submission status: Accepted

Solution code:
import sys
bbn=1000000007
	
#+++++

def mk_path(a_i, max_n, ret):
	#a_i = 1 ... max_n
	#7 => 7,(6,1),(5,2),(4,3)
	#8 => (8,1),(7,2),(6,3),(5,4)
	off=0 if max_n % 2 == 1 else 1
	
	for i in range(a_i+1, max_n+1):
		if i == max_n - a_i + off:
			continue
		else:
			ret.append((a_i, i))
			
	return 
	
def check_constraint(graph, n):
	cc=[0]*n
	for f,t in graph:
		cc[f-1] += t
		cc[t-1] += f
	
	pa(('max:',max(cc),', min:', min(cc) ))
	return
	
		
def main():
	n = int(input())
	ret=[]
	for i in range(1,n+1):
		mk_path(i,n,ret)
	
	#check_constraint(ret, n)
	print(len(ret))
	for f,t in ret:
		pass
		print(f,t)

	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:



N = int(input())

edge_num = 0
for i in range(N-1,0,-1):
    edge_num += i

edge_num -= N//2 

"""
Nが偶数の場合、1とNの間にある辺、2とN-1の間にある辺、......を外していく
Nが奇数の場合、1とN-1の間にある辺、2とN-2の間にある辺、......を外していく
"""
print(edge_num)
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
        print(i,j)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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 N % 2 == 0:
            if i+j != N+1:
                print(i, j)
        else:
            if i+j != N:
                print(i, j)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
answer_list = []
pair = N if N&1 else N+1
for i in range(1, N):
    for j in range(i+1, N+1):
        if i+j == pair:
            continue
        else:
            answer_list.append((i, j))

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    ans = []
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            m = n if n & 1 else n + 1
            if i + j != m:
                ans.append((i, j))
    print(len(ans))
    for i, j in ans:
        print(i, j)


if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
n = int(input())

pairs = [[i for i in range(1, n + 1)] for _ in range(n)]

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

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

Submission status: Accepted

Solution code:
n=int(input())
m=n//2*2
ans=[]
for i in range(1,m//2):
  for j in range(1+i,m-i+1):
    ans.append((i,j))
    ans.append((m+1-j,m+1-i))
if n%2:
  for i in range(1,n):
    ans.append((i,n))
print(len(ans))
for i in ans:
  print(*i,sep=" ")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
N=int(input())
n=(N//2)*2
g=[set() for i in range(N)]
tmp={i for i in range(n)}
for i in range(n):
  g[i]=copy.copy(tmp)
  g[i].remove(i)
  g[i].remove(n-1-i)
count=0
if N%2!=0:
  g[N-1]=copy.copy(tmp)
  for i in range(N-1):
    g[i].add(N-1)
for i in range(N):
  count+=len(g[i])
print(count//2)

for i in range(N):
  for x in g[i]:
    print(i+1,x+1)
    g[x].remove(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

if n % 2 == 0:
    # 1 <-> n, 2 <-> n-1... is Pair
    print(int(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(str(i) + " " + str(j))
else:
    # Each edge has (sum - N)
    print(int(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(str(i) + " " + str(j))

Submission status: Accepted

Solution code:
N = int(input())

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

K = N - (N % 2)
for i in range(1, K // 2 + 1):
    Ls.remove((i, K - i + 1))

print(len(Ls))
for l in Ls:
    print("%d %d" % l)

Submission status: Accepted

Solution code:
N = int(input())
if N & 1:
    print((N-1)**2//2)
    for i in range(N):
        for j in range(i+1, N):
            if i + j == N - 2 and j < N - 1: continue
            print(i+1, j+1)
else:
    print(N*N//2-N)
    for i in range(N):
        for j in range(i+1, N):
            if i + j == N - 1: continue
            print(i+1, j+1)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())

a = n
if n % 2 == 0:
    a += 1

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[]
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)
print(len(a))
for i,j in zip(a,b):print(i,j)