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:
n = int(input())
print(n*(n-1)//2-n//2)

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

Submission status: Accepted

Solution code:
from math import factorial

n=int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    initial[i].pop(i)
# print(initial)
neighbors = copy.deepcopy(initial)

S = sum(neighbors[-1])  # S候補の最大値

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

# print(neighbors)

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

Submission status: Accepted

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


N = int(input())

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

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

#print(group)

edge = []

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

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

print(len(edge))

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

Submission status: Accepted

Solution code:
n=int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=[]
def upgrade(edge):
    s=len(edge)
    for i in range(s):
        [a,b]=edge[i]
        edge[i]=[a+1,b+1]

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

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
print(N*(N-1)//2-N//2)

if N%2 == 0:
  for i in range(1,N):
    for j in range(i+1,N+1):
      if i+j != N+1:
        print("{} {}".format(i,j))
else:
  for i in range(1,N):
    for j in range(i+1,N+1):
      if i+j != N:
        print("{} {}".format(i,j))

Submission status: Accepted

Solution code:
import sys
import math

# get input
input = sys.stdin.readline()

N = int(input)

# number of connections
M = (N*(N-1)/2)-N/2
print(math.ceil(M))

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from itertools import combinations
# 標準入力を受け取る
n = int(input())
### 奇数処理
if n % 2 == 1:
    ### NGな組み合わせは奇数の時{i,N-i}
    ### (1，N-1),(２，N-2),(3，N-3)・・・(i，N-i)・・・,(N-1,1),N
    ### NGな組み合わせは全部でN個、最後はN単独なので除外(-1)。半分は入れ替わっただけで同じ組み合わせなので半分。
    ### NGな組み合わせの数を計算する
    # ng = (n-1)/2
    # m = n(n-1)/2 - ng
    ## 上の式を整理して下記
    m = (n-1)*(n-1)/2
    print(int(m))
    ### グラフを表示する
    for i, j in combinations(range(1,n+1),2):
        if (i + j) != n:
            print(i, j)
### 偶数処理
else:
    ### NGな組み合わせは偶数の時{i,N-i+1}
    ### (1,N),(2,N-1),(3,N-2)・・・(i，N-i+1)・・・,(N-1,2),(N,1)
    ### NGな組み合わせは全部でN個、半分は入れ替わっただけで同じ組み合わせなので半分。
    ### NGな組み合わせの数を計算する
    #ng = n/2
    #m = n(n-1)/2 - ng
    ## 上の式を整理して下記
    m = (n-2)*n/2
    print(int(m))
    ### グラフを表示する
    for i, j in combinations(range(1,n+1),2):
        if (i + j) != n+1:
            print(i, j)

Submission status: Accepted

Solution code:
n = int(input())

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

print(len(edges))

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

Submission status: Accepted

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

N = int(input())

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

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


N = _i()

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

main()

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

Solution code:
# input
n = int(input())

# 1. make validate graph fragment (all index are includede completely)
fragments = []
if n % 2 == 0:
    # even case: (1, n), (2, n-1), ..., (n//2, n//2+1)
    fragments = [(i + 1, n - i) for i in range(n // 2)]
else:
    # odd case: (1, n-1), (2, n-2), ..., (n//2-1, n//2+1), (n)
    fragments = [(i + 1, n - i - 1) for i in range(n // 2)]
    fragments.append((n,))

# 2. each vertex connect all vertex excepy for one's belonging graph's element
edges = []
for i, frag in enumerate(fragments):
    for vtx in frag:
        other_frags = fragments[:i] + fragments[i + 1:]
        edges.extend([(vtx, o_vtx) for o_frag in other_frags for o_vtx in o_frag])

# 3. delete duplicated edge (remain (a, b) edge for a < b)
for edge in edges[:]:
    if edge[0] > edge[1]:
        edges.remove(edge)


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

Submission status: Accepted

Solution code:

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

from itertools import combinations

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def balanced_neighbors(N: int) -> list:
    # N が偶数の時、i は N+1-i 以外の頂点と結べば
    # 隣接点の和は (N+1)(N-2)/2 となり、i に依存しない
    # ため全て同じになる。
    # N が奇数の時、N を抜いた N-1 個の頂点に対して偶数
    # の場合の処理をする。このとき、N 以外の頂点はその隣
    # 接点の和は N(N-3)/2 となっている。この状態で N と
    # その他全ての頂点とを結べば、N 以外の頂点の隣接点の
    # 和は
    # N(N-3)/2 + N = N(N-1)/2
    # であり、N のそれは 1 ~ N-1 の和なので
    # N(N-1)/2
    # となり等しくなる。
    if N < 3:  # 2 以下の頂点数では無理
        return []
    if N & 1:  # 奇数
        return balanced_neighbors(N-1) + [(i, N) for i in range(1, N)]

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


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

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

Submission status: Accepted

Solution code:
# AGC032 Problem-B

n = int(input())

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

#print (table)

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input())
ban = N if N%2 else N+1

ans = []
for i in range(1,N):
    for j in range(i+1,N+1):
        if i+j == ban: continue
        ans.append(str(i) + ' ' + str(j))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

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


if __name__ == '__main__':
   main()

Submission status: Accepted

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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


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

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

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


print(main())

Submission status: Accepted

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

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

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

for i in range(1,n+1):
    for j in range(i+1,n+1):
        if a[i][j] == -1:
            continue
        else:
            print(i,j)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 入力
N = int(input())

# Nが偶数ならば完全グラフから辺 (1, N), (2, N-1), ... を除いたグラフが解
# Nが奇数ならば完全グラフから辺 (1, N-1), (2, N-2), ... を除いたグラフが解
M = (
    N * (N - 1) // 2 - N // 2 if N % 2 == 0 else
    N * (N - 1) // 2 - (N - 1) // 2
)
s = N + 1 if N % 2 == 0 else N
ans = str(M) + '\n' + '\n'.join(
    '{} {}'.format(i, j)
    for i in range(1, N)
    for j in range(i + 1, N + 1)
    if i + j != s
)

# 出力
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(input())

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
N=int(input())

#       完全グラフ
#    1     14     -4
#    2     13     -3
#    3     12     -2
#    4     11     -1
#    5     10
#
#       完全グラフ
#    1     20     -6
#    2     19     -5
#    3     18     -4
#    4     17     -3
#    5     16     -2
#    6     15     -1

ans=[]
for i in range(1,N):
    for j in range(i+1,N+1):
        ans.append((i,j))
if N%2==0:
    for i in range(1,N//2+1):
        ans.remove((i,N+1-i))
else:
    for i in range(1,N//2+1):
        ans.remove((i,N-i))
print(len(ans))
for a in ans:
    print(a[0],a[1])

Submission status: Accepted

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

import sys

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

N=INT()

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

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

Submission status: Accepted

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

Submission status: Accepted

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

    # 非連結で、∀S∈Z, ∀k, 頂点kとそれに隣接する頂点の番号の値の和がS
    # を満たすグラフを考えると、この条件は補グラフが
    # 与えられた条件を満たすための十分条件となる。
    # この条件を考えると、{1, ..., N} を2つ以上のグループに分割する方法であって、
    # グループに含まれる辺の和がグループによらず一定となる方法を1つ見つければいい。
    # そのような方法が存在すれば、同じグループに属するような頂点間に辺を張った
    # グラフが上の条件を満たす。分割の方法例は以下のものがある。
    # Nが奇数: {1, N-1}, {2, N-2}, ..., {N} (和がN)
    # Nが偶数: {1, N}, {2, N-1}, ..., {N, 1} (和がN+1) (*)
    # 上の方法で構成されるグラフの補グラフはO(N**2)で構成可能である。
    pair_sum = N + 1 - (N % 2)
    ans_tmp = []
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            if i + j != pair_sum:
                # (*)で表された辺を除いたグラフを構成する
                ans_tmp.append((i, j))
    return '\n'.join([str(len(ans_tmp))] + [' '.join(map(str, a)) for a in ans_tmp])

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n = int(input())

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



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

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

Submission status: Accepted

Solution code:
N = int(input())

bridge = []
for i in range(1, N):
    for j in range(i + 1, N + 1):
        if(N % 2 == 0):
            if(i + j == N + 1):
#                print("skip = [{}, {}]".format(i,j))
                continue
        else:
            if(i + j == N):
#                print("skip = [{}, {}]".format(i,j))
                continue
        bridge.append([i, j])

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

Submission status: Accepted

Solution code:

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

    return count, line_list


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

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()

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

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


main()

Submission status: Accepted

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

Submission status: Accepted

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