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:
from itertools import combinations
n=int(input())
A=[]
num=n if n%2==1 else n+1
for a,b in combinations([j+1 for j in range(n)],2):
    if a+b!=num:A.append([a,b])
print(len(A))
for i in A:print(*i)

Submission status: Accepted

Solution code:
n = int(input())

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

res = set()
for i in range(len(g)):
    for j in range(len(g)):
        if i==j:
            continue
        for v in g[i]:
            for u in g[j]:
                res.add((min(v,u),max(v,u)))
print(len(res))
for v,u in res:
    print(v,u)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
x = n if n % 2 else n+1
ans = []
for v, v2 in combinations(range(1, n+1), 2):
    if v+v2 == x:
        continue
    ans.append((v, v2))
print(len(ans))
for edge in ans:
    print(*edge)

Submission status: Accepted

Solution code:
n = int(input())
if n%2 == 1:
    a = n-1
else:
    a = n
ans = []
for i in range(a-1):
    for j in range(i+1,a):
        if i+j+2 == a+1:
            continue
        else:
            ans += [[i+1,j+1]]
            # print(i+1,j+1)
if n%2 == 1:
    for i in range(n-1):
        ans += [[i+1,n]]
        # print(i+1,n)
print(len(ans))
for i in ans:
    print(*i)

Submission status: Accepted

Solution code:
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 % 2 == 1: # 奇数
  for i in range(1, N+1):
    j = N - i
    ans.discard((i, j))
else: # 偶数
  for i in range(1, N+1):
    j = N + 1 - i
    ans.discard((i, j))

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

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

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
node=[]
if n%2==0:
    for i in range(n):
        for j in range(i,n):
            if j==i or j==n-1-i:
                continue
            node.append((i+1,j+1))
else:
    for i in range(n):
        for j in range(i,n):
            if j==i or j==n-2-i:
                continue
            node.append((i+1,j+1))
    
print(len(node))
for i in node:
    print(*i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    edges = []
    M = 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 + 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(M)
    for a, b in edges:
        print(a, b)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ho={}
  if n%2==0:
    for i in range(1,n//2+1):
      ho[str(i)+'-'+str(n-i+1)]=0
  else:
    for i in range(1,n//2+1):
      ho[str(i)+'-'+str(n-i)]=0

  # print(ho)

  ans=[]
  for i in range(1,n+1):
    for j in range(1,n+1):
      if i<=j:
        break

      pair=str(j)+'-'+str(i)
      if pair in ho:
        continue

      ans.append((j,i))

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

main()
# print(main())

Submission status: Accepted

Solution code:
n = int(input())
if n % 2 == 0:
    k = 1+n
    s = k*(n//2-1)
else:
    k = n
    s = k*(n//2)

ans = []
for i in range(1, n+1):
    for j in range(i+1, n+1):
        if i+j == k:
            continue
        ans.append("{} {}".format(i, j))
print(len(ans))
print(*ans, sep='\n')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

if N%2==1:
    L = [[N]]
    for i in range(1,N//2+1):
        L.append([i,N-i])
else:
    L = []
    for i in range(1,N//2+1):
        L.append([i,N-i+1])
LN = len(L)
M = []
for i in range(LN):
    A = L[i]
    for j in range(i+1,LN):
        B = L[j]
        for Ai in A:
            for Bi in B:
                M.append([Ai,Bi])

MN = len(M)
print(MN)
for i in range(MN):
    print(M[i][0],M[i][1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    ans = set()
    if N % 2 == 0:
        for i in range(1,N+1):
            k = N - i + 1
            for j in range(1,N+1):
                if j == k or j == i:
                    continue
                if j > k:
                    ans.add((k,j))
                else:
                    ans.add((j,k))
                if j > i:
                    ans.add((i,j))
                else:
                    ans.add((j,i))
    else:
        for i in range(1,N):
            ans.add((i,N))
        for i in range(1,N):
            k = N - i
            for j in range(1,N+1):
                if j == k or j == i:
                    continue
                if j > k:
                    ans.add((k,j))
                else:
                    ans.add((j,k))
                if j > i:
                    ans.add((i,j))
                else:
                    ans.add((j,i))
    print(len(ans))
    for i, j in ans:
        print(i,j)        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    l = []
    if n%2 == 0:
        for i in range(1,n+1):
            for j in range(i+1,n+1):
                if i == j or i+j == n+1:
                    continue
                else:
                    l.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:
                    l.append((i,j))
    print(len(l))
    for i,j in l:
        print(i,j)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

out = []
l = len(g)
for i in range(l):
    for j in range(i+1, l):
        out.extend((gi, gj) for gi in g[i] for gj in g[j])
print(len(out))
for o in out:
    print(o[0], o[1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

if n % 2 == 0:
    pairs = [(i, n+1-i) for i in range(1, n//2+1)]
    x = len(pairs)
    if n == 4:
        print(4 * (x - 1))
        for i in range(2):
            for j in range(2):
                print(pairs[0][i], pairs[1][j])
    else:
        print(4 * x)
        for k in range(n//2):
            for i in range(2):
                for j in range(2):
                    print(pairs[k%x][i], pairs[(k+1)%x][j])

else:
    pairs = [(i, n-i) for i in range(1, n//2+1)]
    x = len(pairs)
    if n == 3:
        print(2)
        print(1, 3)
        print(2, 3)
    else:
        print(4 * x)
        for k in range(n//2-1):
            for i in range(2):
                for j in range(2):
                    print(pairs[k % x][i], pairs[(k+ 1) % x][j])
        print(n, pairs[0][0])
        print(n, pairs[0][1])
        print(n, pairs[-1][0])
        print(n, pairs[-1][1])

Submission status: Accepted

Solution code:
from itertools import combinations

N = int(input())

k = N // 2
s = N + 1 - N % 2
print(N * (N - 1) // 2 - k)
for p in combinations(range(1, N + 1), 2):
    if sum(p) == s:
        continue
    print(p[0], p[1])

Submission status: Accepted

Solution code:
N=int(input())
sets=[]
if N%2==1:
    sets.append([N])
    for i in range(1,N//2+1):
        sets.append([i,(N-i)])
else:
    for i in range(1,N//2+1):
        sets.append([i,N+1-i])
#print(sets)
path=[]
for i in range(len(sets)):
    for j in range(i+1,len(sets)):
        for k in sets[i]:
            for l in sets[j]:
                path.append([min(k,l),max(k,l)])
#print(path)
print(len(path))
for i in path:
    print(*i)

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 i+j!=n+1:
                ans.append([i,j])
else:
    for i in range(1,n):
        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,queue,math,copy,itertools,bisect,collections,heapq

def main():
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    ans = []
    for i in range(1,N):
        for j in range(i+1,N+1):
            if not j == (N - i + (N%2==0)):
                ans.append((i,j))
    print(len(ans))
    for x in ans:
        print(x[0],x[1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

l = list(range(1, n+1))
s = sum(l)
graph = []
graph_set = set()
cnt = 0

if n % 2 == 0:
    for i in range(1, n+1):
        for j in range(1, n+1):
            if i + j == n + 1:
                continue
            elif i == j:
                continue
            else:
                if (i, j) not in graph_set:
                    graph.append([i, j])
                    graph_set.add((i, j))
                    graph_set.add((j, i))
                    cnt += 1

else:
    for i in range(1, n+1):
        for j in range(1, n+1):
            if i + j == n:
                continue
            elif i == j:
                continue
            else:
                if (i, j) not in graph_set:
                    graph.append([i, j])
                    graph_set.add((i, j))
                    graph_set.add((j, i))
                    cnt += 1

print(cnt)
for i, j in graph:
    print(i, j)

Submission status: Accepted

Solution code:
n = int(input())

sm = n*(n+1)//2
if n == 3:
  print(2)
  print(1, 3)
  print(2, 3)
elif n == 4:
  print(4)
  print(1, 2)
  print(1, 3)
  print(2, 4)
  print(3, 4)
elif n % 2:
  m = (n-1)//2
  print(m*4)
  a = [[i, n-i-2] for i in range(m)]
  for i in range(m-1):
    for j in range(2):
      for k in range(2):
        print(a[i][j]+1, a[i+1][k]+1)
  for i in range(2):
    print(a[m-1][i]+1, n)
    print(n, a[0][i]+1)
else:
  print(n*2)
  a = [[i, n-i-1] for i in range(n//2)]
  for i in range(n//2):
    for j in range(2):
      for k in range(2):
        print(a[i][j]+1, a[(i+1)%(n//2)][k]+1)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:

import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N = int(input())
edge = []
if N&1:
    cnt = 0
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i+j != N:
                edge.append((i,j))
                cnt += 1

else:
    cnt = 0
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i+j != N+1:
                edge.append((i,j))
                cnt += 1

print(cnt)
for u,v in edge:
    print(u,v)

Submission status: Accepted

Solution code:
n = int(input())
ans = set()
if n%2 == 1:
  for i in range(1,n):
    ans.add((i,n))
  n -= 1
if n%2 == 0:
  chk = [[] for i in range(n//2)]
  for i in range(1,n//2+1):
    chk[i-1].append(i)
    chk[i-1].append(n+1-i)
  for i in range(n//2-1):
    for j in range(2):
      a = chk[i][j]
      for k in range(i+1,n//2):
        b = chk[k][0]
        c = chk[k][1]
        if a < b:
          ans.add((a,b))
        else:
          ans.add((b,a))          
        if a < c:
          ans.add((a,c))
        else:
          ans.add((c,a))
          
#print(ans)
print(len(ans))
for i in ans:
  print(*i)

Submission status: Accepted

Solution code:
n = int(input())

g = [[1] * (n + 1) for _ in range(n + 1)]

if n % 2:
    for i in range(1, n + 1):
        j = n - i
        g[i][j] = 0
        g[j][i] = 0

else:
    for i in range(1, n + 1):
        j = n + 1 - i
        g[i][j] = 0
        g[j][i] = 0

ans = []
for i, row in enumerate(g[1:], 1):
    for j, bl in enumerate(row[i+1:], i+1):
        if bl:
            ans.append((i, j))

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

Submission status: Accepted

Solution code:
#AGC032-B Balanced Neighbors
"""
まずnが偶数の場合を考える。
1...nの数列を考えた時に、
1+n,2+n-1,3+n-2…を１頂点として考えると、全てその値が等しいグラフになる。
次に奇数の場合を考える。
n-1までのグラフを偶数の場合と同じように構築した後、
nはn-1までの2頂点の合計と等しい値になる。
よって、最後に全頂点をnとつなぎ合わせると条件を満たすグラフに成る。
"""
import sys
from collections import defaultdict
dic1 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
ans = []
mid = 1+(n//2)*2
for i in range(1,(n//2)*2+1):
    dic1[i] = mid-i
for i in range(1,(n//2)*2):
    res = dic1[i]
    for j in range(i+1,(n//2)*2+1):
        if j == res:
            continue
        ans.append([i,j])

if not even(n):
    for i in range(1,n):
        ans.append([i,n])

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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 j==n-i:continue
                print(i,j)
    else:
        for i in range(1,n):
            for j in  range(i+1,n+1):
                if j==n-i+1:continue
                print(i,j)        

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
if n%2:
    print(2*(n//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,sep=" ")
else:
    s=n//2
    print(2*(s-1)*s)
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if i+j==n+1 :continue
            print(i,j,sep=" ")

Submission status: Accepted

Solution code:
N = int(input())
from itertools import groupby, accumulate, product, permutations, combinations
def solve(N):
    pairs = []
    if N%2==1: #和がN
        total = N
        pairs.append([N])
        ans = N-1
    else: #和がN+1
        total = N+1
        ans = 0
    for i in range(1,(total+1)//2):
        pairs.append([i,total-i])
        ans += 2*(N-2)
    print(ans//2)
    for pair1, pair2 in combinations(pairs,2):
        for i in pair1:
            for j in pair2:
                print(i,j)
    return
solve(N)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc032/tasks/agc032_b

# 補グラフ
N = int(input())
G = [[1 for _ in range(101)] for _ in range(101)]
for i in range(101): G[i][i] = 0
groups = []

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

M = 0
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        if G[i][j] == 1:
            M += 1
# for row in G[1:N+1]: print(*row[1:N+1])

print(M)
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        if G[i][j] == 1:
            print(i, j)

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    answer = []
    if N % 2 == 1:
        for i in range(1, N):
            answer.append((N, i))
        for j in range(1, N):
            for k in range(j + 1, N):
                if j + k == N:
                    continue
                else:
                    answer.append((j, k))
    else:
        for i in range(2, N):
            answer.append((N, i))
            answer.append((1, i))
        for j in range(2, N):
            for k in range(j + 1, N):
                if j + k == N + 1:
                    continue
                else:
                    answer.append((j, k))
    M = len(answer)
    print(M)
    for i in range(M):
        print(*answer[i], sep=" ")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

d = set()
if N % 2 == 0:
    for i in range(1,N//2+1):
        d.add((i, N-i+1))
else:
    for i in range(1,N//2+1):
        d.add((i, N-i))

r = S.difference(d)

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

Submission status: Accepted

Solution code:
n = int(input())
no_group = []
if n % 2 ==0:
  for  i in range(1,n//2+1):
    no_group.append([i,n-i+1])
else:
  for i in range(1,n//2+1):
    no_group.append([i,n-i])
  no_group.append([n])
  
sub_list = [[0 for i in range(n)] for i in range(n)]
for g in no_group:
  if len(g) == 2:
    sub_list[g[0]-1][g[1]-1] = 1
    sub_list[g[1]-1][g[0]-1] = 1
ans_list = []
for i in range(n):
  for j in range(i,n):
    if i != j and sub_list[i][j] == 0:
      ans_list.append([i+1,j+1])
      
print(len(ans_list))
for ans in ans_list:
  print(*ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = [i + 1 for i in range(n - (n % 2))]
y = [[x[i], x[len(x) - i - 1]] for i in range(len(x) // 2)]
ans = []
for i in range(len(y) - 1):
    for j in range(2):
        for k in range(2):
            ans.append([y[i][j], y[i + 1][k]])
if n == 3:
    ans = [[1, 3], [2, 3]]
elif n == 4:
    ans = [[1, 2], [1, 3], [2, 4], [3, 4]]
elif n % 2 == 1:
    for i in range(len(x) - 1, len(x) + 1):
        for j in range(2):
            ans.append([y[i % len(y)][j], n])
else:
    for i in range(2):
        for j in range(2):
            ans.append([y[len(y) - 1][i], y[0][j]])
print(len(ans))
for ans0 in ans:
    print(" ".join(map(str, ans0)))

Submission status: Accepted

Solution code:
n = int(input())
if n == 3:
  print(2)
  print(1, 3)
  print(2, 3)
else:
  ans = []
  core = [n//2-1, n//2, n//2+1, n//2+2]
  for i in range(4):
    for j in range(i+1, 4):
      if i+j != 3:
        ans.append((core[i], core[j]))
  key = n//2-2
  for i in range(key, 0, -1):
    key2 = 2*n//2-i+1
    if n%2:
      key2 -= 1
    for c in core:
      ans.append((i, c))
      ans.append((c, key2))
    core.append(i)
    core.append(key2)
    
  if n%2:
    for c in core:
      ans.append((c, n))
  print(len(ans))
  for a in ans:
    print(*a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
#単純グラフ：ループも多重辺もない
#連結：成分が1

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

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

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

Submission status: Accepted

Solution code:
N = int(input())

n = N // 2
S = N + (N % 2 == 0)

groups = [[i, S - i] for i in range(1, n + 1)]

if N % 2 == 1:
    groups.append([S])

ans = []

from itertools import *

for g1, g2 in combinations(groups, 2):
    for s, t in product(g1, g2):
        ans.append((s, t))

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

Submission status: Accepted

Solution code:
N = int(input())
ans = []
if N%2 == 0:
    for k in range(1,N):
        for l in range(k+1,N+1):
            if k+l != N+1:
                ans.append([k,l])
else:
    for k in range(1,N):
        for l in range(k+1,N+1):
            if k+l != N:
                ans.append([k,l])
print(len(ans))
for e in ans:
    print(*e)

Submission status: Accepted

Solution code:
N = int(input())

V = set()

if N % 2 == 0:
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            if i + j == N + 1:
                V.add((i, j))
else:
    for i in range(1, N):
        for j in range(i + 1, N):
            if i + j == N:
                V.add((i, j))

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

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

Submission status: Accepted

Solution code:
def main():
    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(*a)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    t=0
    if N%2==0:
        t=1+N
    else:
        t=N
        
    ans=[]
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i+j!=t:
                ans.append([i,j])
    print(len(ans))
    for i in range(len(ans)):
        print(' '.join(map(str, ans[i])))
    


main()

Submission status: Accepted

Solution code:
n = int(input())
s = (n-1)*n//2

if n%2 == 1:

    g = [[] for _ in range(n)]
    for i in range(n):
        j = i+1
        if j != n:
            k = n-j
            #print(j, k)
            for a in range(1, n+1):
                if a == j or a == k:
                    continue
                else:
                    if a > j:
                        g[i].append(a-1)
        #else:
            #for a in range(1, n):
                #g[i].append(a-1)
    #print(g)
    cnt = 0
    edge = []
    for v in range(n):
        cnt += len(g[v])
        for u in g[v]:
            edge.append((v+1, u+1))
    print(cnt)
    for v, u in edge:
        print(v, u)

else:
    g = [[] for _ in range(n)]
    for i in range(n):
        j = i+1
        if j != n:
            k = n+1-j
            #print(j, k)
            for a in range(1, n+1):
                if a == j or a == k:
                    continue
                else:
                    if a > j:
                        g[i].append(a-1)
    cnt = 0
    edge = []
    for v in range(n):
        cnt += len(g[v])
        for u in g[v]:
            edge.append((v+1, u+1))
    print(cnt)
    for v, u in edge:
        print(v, u)

Submission status: Accepted

Solution code:
N = int(input())

if N % 2 == 0:
    G = []
    G_append = G.append
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            if i + j != (1 + N):
                G_append((i, j))
    print (len(G))
    for g in G:
        print (*g, sep = ' ')
    
else:
    G = []
    G_append = G.append
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            if i + j != N:
                G_append((i, j))
    print (len(G))
    for g in G:
        print (*g, sep = ' ')

Submission status: Accepted

Solution code:
N = int(input())

if N % 2 == 0:
    edge = []
    for s in range(1, N + 1):
        ng = N - s + 1
        for t in range(1, N + 1):
            if s >= t or t == ng:
                continue
            edge.append((s, t))
else:
    edge = []
    for s in range(1, N + 1):
        ng = N - s
        for t in range(1, N + 1):
            if s >= t or t == ng:
                continue
            edge.append((s, t))

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

Submission status: Accepted

Solution code:
n = int(input())
e = []
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
            e.append([i, j])
else:
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            if i + j == n:
                continue
            e.append([i, j])
print(len(e))
for i in e:
    print(i[0],i[1])

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    Ans = []
    AnsNum = 0
    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))
                    AnsNum += 1
    else:
        for i in range(1, N):
            for j in range(i + 1, N + 1):
                if i + j != N:
                    Ans.append((i, j))
                    AnsNum += 1
    print(AnsNum)
    for i in range(AnsNum):
        print(" ".join(map(str, Ans[i])))


    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

# Nが奇数の場合、(N-自分)に対しては辺を貼らない
# Nが偶数の場合、(N+1-自分)に対しては辺を貼らない

ans = []
odd = (N%2 == 1)
def needs_edge(i,j,N,odd):
  if odd:
    if N-i == j:
      return False
  else:
    if N+1-i == j:
      return False
  return True

for i in range(1,N):
  for j in range(i+1,N+1):
    if needs_edge(i,j,N,odd):
      ans.append([i,j])

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