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

if N%2==1:
  for i in range(1, N//2+1):
    del ans[ans.index(sorted([i, N-i]))]
else:
  for i in range(1, N//2+1):
    del ans[ans.index(sorted([i, N-i+1]))]

print(len(ans))
[print(*a) for a in ans]

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N = int(input())

if N % 2:
    s = N
    print(cmb(N - 1, 2) - N // 2 + N - 1)
else:
    s = 1 + N
    print(cmb(N, 2) - N // 2)

for i in range(1, N):
    for j in range(i + 1, N + 1):
        if i + j != s:
            print(i, j)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
t = []
res = set()
for i in range(1, N // 2 + 1):
  if N % 2:
    t.append((i, N - i))
  else: t.append((i, N - i + 1))
for i in range(1, N):
  for x in t:
    if i in x: continue
    res.add(tuple(sorted((i, x[0]))))
    res.add(tuple(sorted((i, x[1]))))
if N % 2:
  for i in range(1, N):
    res.add((i, N))
print(len(res))
for r in res:
  print(*r)

Submission status: Accepted

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

# 解説AC
N = int(sys.stdin.buffer.readline())

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

ans = set()
for group in groups:
    for v in set(range(1, N + 1)) - group:
        for u in group:
            ans.add((min(v, u), max(v, u)))

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

Submission status: Accepted

Solution code:
import os
import sys

from collections import Counter

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())


def solve(N, group_cnt=2):
    s = sum(range(N + 1))

    while s * (group_cnt - 1) % group_cnt != 0:
        group_cnt += 1

    groups = [set() for _ in range(group_cnt)]
    sums = [[0, i] for i in range(group_cnt)]

    for n in reversed(range(1, N + 1)):
        for i, (_, v) in enumerate(sums[1:], start=1):
            sums[i][0] -= n
            groups[v].add(n)
        sums.sort()

    # わからない。グループ数増やしていけばどっかでうまくいくらしい。
    if len(Counter([s for s, _ in sums])) > 1:
        return solve(N, group_cnt + 1)

    ans = set()
    for group in groups:
        for v in set(range(1, N + 1)) - group:
            for u in group:
                ans.add((min(v, u), max(v, u)))
    return ans


ans = solve(N)
print(len(ans))
for r in ans:
    print(*r)
exit()

for n in range(3, 101):
    ans = solve(n)

    graph = [[] for _ in range(n + 1)]
    for v, u in ans:
        graph[v].append(u)
        graph[u].append(v)

    c = Counter([sum(vs) for vs in graph[1:]])
    if len(c) > 1:
        print(n, c)

Submission status: Accepted

Solution code:
def examB():
    N = I()
    M = (N-1)**2//2
    ans = []
    for i in range(1,N+1):
        if N%2==0:
            for j in range(i+1,N+1):
                if i+j!=N+1:
                    ans.append([i,j])
        else:
            for j in range(i+1,N):
                if i+j!=N:
                    ans.append([i,j])
            if i!=N:
                ans.append([i,N])
    print(M)
    for v in ans:
        print(" ".join(map(str,v)))

from string import digits
import sys,copy,bisect,itertools,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

paths = set()
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        paths.add((i, j))

if n % 2 == 0:
    for i in range(1, n + 1):
        path = (min(i, n - i + 1), max(i, n - i + 1))
        paths.discard(path)
else:
    for i in range(1, n + 1):
        path = (min(i, n - i), max(i, n - i))
        paths.discard(path)

print(len(paths))
for path in paths:
    print('{0} {1}'.format(path[0], path[1]))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a=inp()
        a-=1
        g[i].append(a)
        g[a].append(i)
    return n,g
def graphm():
    n,m=inpm()
    g=[[] for _ in range(n)]
    for _ in range(m):
        a,b,w=inpm()
        a-=1
        b-=1
        g[a].append((b,w))
        g[b].append((a,w))
    return n,m,g

def dijkstra(s,n,g): # sからの最短距離 頂点数n
    s -= 1
    que = []
    d = [10**15 for _ in range(n)]
    d[s] = 0
    heappush( que,(0,s) )
    while len(que)>0:
        p =  heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for i in range(len(g[v])):
            edge = g[v][i]
            if d[edge[0]] > d[v] + edge[1]:
                d[edge[0]] = d[v] + edge[1]
                heappush( que,(d[edge[0]] , edge[0]) )
    return d

def main():
    n=inp()
    if n%2==0:
        x=( n*(n-1) )//2
        print(x-(n//2))
    else:
        x=( n*(n-1) )//2
        print(x-((n-1)//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)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

ans = []
# 偶数だったら対角、奇数だったらその一つ左を引く
for i in range(1, N + 1):
  for j in range(1, N + 1):
    if N % 2 == 0:
      if i != j and i + j != N + 1:
        if [j, i] not in ans:
          ans.append([i, j])
    else:
      if i != j and i + j != N:
        if [j, i] not in ans:
          ans.append([i, j])
print(len(ans))
for i, j in ans:
  print(i, j)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#balanced naibngor
counter=0
nodlist=[]
anslist=[]
n=int(input())
if n%2==0:
    #(1,n),(2,n-1),(n/2+1,n/2)
    nodlist.append(1)
    nodlist.append(2)
    nodlist.append(n)
    nodlist.append(n-1)
    anslist.append([1,2])
    anslist.append([1,n-1])
    anslist.append([2,n])
    anslist.append([n-1,n])
    counter+=4
    lists=[[i,n+1-i] for i in range(3,n//2+1)]
    for j in lists:
        a,b=j[0],j[1]
        for i in nodlist:
            anslist.append([i,a])
            anslist.append([i,b])
            counter+=2
        nodlist.append(a)
        nodlist.append(b)
    print(counter)
    for k in anslist:
        print(*k)

if n%2!=0:
    if n>=5:
        # n,(1,n-1),(2,n-2),,,,,(n+1/2,n-1/2)
        nodlist.append(1)
        nodlist.append(n-1)
        nodlist.append(n-2)
        nodlist.append(2)
        anslist.append([1,2])
        anslist.append([1,n-2])
        anslist.append([n-2,n-1])
        anslist.append([n-1,2])
        counter+=4
        lists=[[i,n-i] for i in range(3,(n+1)//2)]        
        for j in lists:
            a,b=j[0],j[1]
            for i in nodlist:
                anslist.append([i,a])
                anslist.append([i,b])
                counter+=2
            nodlist.append(a)
            nodlist.append(b)  
        for k in nodlist:
            anslist.append([k,n])
            counter+=1
        print(counter)
        for s in anslist:
            print(*s)
    if n==3:
        print(2)
        l=[1,3]
        L=[2,3]
        print(*l)
        print(*L)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
tmp=(n+1)//2*(n-2)
# print(tmp)
if n%2==0:
    print(n*(n-2)//2)
else:
    print(((n-1)*(n-3))//2+n-1)
for i in range(n):
    for j in range(i+1,n):
        if (i+1)+(j+1)!=n+(n+1)%2:
            print(i+1,j+1)

Submission status: Accepted

Solution code:
n = int(input())
ans = []
for i in range(1, n):
	for j in range(i, n + 1):
		if 2 * i!=i + j!=n + 1 - n % 2:
			ans.append("{} {}".format(i, j))
print(len(ans))
print("\n".join(ans))

Submission status: Accepted

Solution code:
n=int(input())
ans=[]
for i in range(1,n+1):
    for j in range(i+1,n+1):
        ans.append((i,j))

if n%2:
    for i in range(1,n//2+1):
        ans.remove((i,n-i))
else:
    for i in range(1,n//2+1):
        ans.remove((i,n-i+1))

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

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-1)*(N-3))//2+N-1)
  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())
g = [ [1] * N for _ in range(N) ]

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

M = 0
for b in range(N):
  for a in range(b):
    if g[a][b] == 1:
      M += 1
print(M)
for b in range(N):
  for a in range(b):
    if g[a][b] == 1:
      print(a+1, b+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

C = [[1 for i in range(n)] for j in range(n)]
for i in range(n):
    C[i][i] = 0
if n%2 == 0:
    for i in range(n):
        C[i][n-1-i] = 0
else:
    for i in range(n):
        C[i][n-2-i] = 0

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

Submission status: Accepted

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

ans_lst = [[1] * N for _ in range(N)]

if N % 2 == 0:
    for i in range(N):
        ans_lst[i][N - i - 1] = 0
else:
    for i in range(N - 1):
        ans_lst[i][N - i -2] = 0
#output
M = 0
for i in range(N):
    for j in range(i + 1, N):
        if ans_lst[i][j] == 1:
            M += 1

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

Submission status: Accepted

Solution code:
N = int(input())

M = N - 1 if N % 2 == 1 else N

A = []
for i in range(1, N + 1):
    for j in range(1, N + 1):
        if i < j and j != M:
            A.append((i, j))
    M -= 1

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

Submission status: Accepted

Solution code:
N = int(input())
D = N if N % 2 == 1 else N+1
edges = [str(i)+" "+str(j) for i in range(1, D)
         for j in range(i+1, D) if i+j != D]
edges2 = [str(v)+" "+str(N) for v in range(1, N)] if N % 2 == 1 else []
print(len(edges)+len(edges2))
print("\n".join(edges+edges2))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
edges = []
if N % 2 == 0:
    D = N+1
else:
    D = N
for i in range(1, D):
    for j in range(i+1, D):
        if i+j == D:
            continue
        else:
            edges.append(str(i)+" "+str(j))
if N % 2 == 1:
    for v in range(1, N):
        edges.append(str(v)+" "+str(N))
print(len(edges))
for e in edges:
    print(e)

Submission status: Accepted

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


def main():
    n = int(input())
    grid = [[True for _ in range(n)] for _ in range(n)]

    # KeyInsight
    # 補グラフ
    if n % 2 == 0:
        for i in range(n):
            grid[i][n - i - 1] = False
    else:
        for i in range(n):
            grid[i][n - i - 2] = False

    ans = list()

    for i in range(n):
        for j in range(i, n):
            if i != j and grid[i][j]:
                ans.append((i, j))

    print(len(ans))

    for ai, bi in ans:
        print(ai + 1, bi + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def main():
    n = int(input())
    grid = [[True for _ in range(n)] for _ in range(n)]

    if n % 2 == 0:
        for i in range(n):
            grid[i][n - i - 1] = False
    else:
        for i in range(n):
            grid[i][n - i - 2] = False

    ans = list()

    for i in range(n):
        for j in range(i, n):
            if i != j and grid[i][j]:
                ans.append((i, j))

    print(len(ans))

    for ai, bi in ans:
        print(ai + 1, bi + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

N = int(input())
lis = []

if N % 2 == 0:

    S = N+1

    for i in range(N):

        for j in range(i):

            if (i+1) + (j+1) == S:
                continue

            else:
                lis.append([i+1,j+1])

else:

    S = N

    for i in range(N-1):

        for j in range(i):

            if (i+1) + (j+1) == S:
                continue

            else:
                lis.append([i+1,j+1])

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

print (len(lis))

for i in lis:

    print (i[0],i[1])

Submission status: Accepted

Solution code:
n = int(input())

M = [[1] * n for i in range(n)]

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

A = []
for i in range(n):
    for j in range(i+1, n):
        if M[i][j] == 1:
            A.append([i, j])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(raw_input())

if N == 3:
    print 2
    print 1, 3
    print 2, 3

elif N & 1:
    a = 0
    for i in range(1, N ):
        for j in range(i + 1, N):
            if i != N - j:
                a += 1
    
    for i in range(1, N):
        a += 1


    print a
    for i in range(1, N ):
        for j in range(i + 1, N):
            if i != N - j:
                print i, j
    
    for i in range(1, N):
        print i, N

else:
    a = 0
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            if i != N - j + 1:
                a += 1

    print a
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            if i != N - j + 1:
                a += 1
                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(1,i):
            if i+j != n+1:
                print(i,j)
                

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

Submission status: Accepted

Solution code:
n=int(input())
ans=set()
if n%2==0:
    i=1
    while i<n+1-i:
        x,y=i,n+1-i
        for j in range(1,n+1):
            if j!=x and j!=y:
                if (j,x) not in ans:
                    ans.add((x,j))
                if (j,y) not in ans:
                    ans.add((y,j))
        i+=1
else:
    i=1
    while i<n-i:
        x,y=i,n-i
        for j in range(1,n+1):
            if j!=x and j!=y:
                if (j,x) not in ans:
                    ans.add((x,j))
                if (j,y) not in ans:
                    ans.add((y,j))
        i+=1
    for j in range(1,n):
        if (j,n) not in ans:
            ans.add((n,j))
print(len(ans))
for i,j in ans:
    print(i,j)

Submission status: Accepted

Solution code:
n = int(input())
l = n
if not n % 2:
  l += 1
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 == l:
      continue
    print(i, j)

Submission status: Accepted

Solution code:
N = int(input())

cnt = 0
A = []
for u in range(1, N) :
    for v in range(u+1, N+1) :
        if u + v == N + (N % 2 != 1) :
            continue
        else :
            cnt += 1
            A.append((u, v))

print(cnt)
for i in range(cnt) :
    print(*A[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
VG = []
for i in range(N//2):
  VG.append([i+1,(N//2)*2-i])
if N % 2 == 1:
  VG.append([N])
#print(VG)

E = []
for i in range(len(VG)-1):
  for v in VG[i]:
    for j in range(i+1,len(VG)):
      for u in VG[j]:
        E.append([v,u])
#print(E)

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

Submission status: Accepted

Solution code:
n = int(input())

path = [[True for i in range(n)] for i in range(n)]

if n%2 == 0:
    for i in range(n//2):
        path[i][i] = False
        path[i][n-i-1] = False
        path[n - i - 1][i] = False
else:
    for i in range(n//2):
        path[i][i] = False
        path[i][n-i-2] = False
        path[n - i - 1][i] = False

ans = []
# print(path)

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

print(len(ans))
for a in ans:
    print(str(a[0])+" "+str(a[1]))

Submission status: Accepted

Solution code:
N = int(input())

def main():
    graph = []
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i+j == N//2*2+1:
                continue
            graph.append([i, j])
    print(len(graph))
    for i, j in graph:
        print(i, j)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

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//2*2+1:
            print(i, j)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


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

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
m = n*(n-1)//2
ans = []
for i in range(n):
    for j in range(i+1,n):
        ans.append((i+1,j+1))
lst = []
if n % 2:
    for i in range(n//2):
        lst.append((i+1,n-i-1))
        m -= 1
else:
    for i in range(n//2):
        lst.append((i+1,n-i))
        m -= 1
for i,j in lst:
    ans.remove((i,j))
print(m)
for i,j in ans:
    print(i,j)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(input())
    if N == 3:
        print(2)
        print(1,3)
        print(2,3)
    elif N == 4:
        print(4)
        print(1,2)
        print(1,3)
        print(4,2)
        print(4,3)
    else:
        if N%2 == 0:
            print(N*2)
            for i in range(N//2-1):
                print(i+1,i+2)
                print(i+1,N-i-1)
                print(N-i,i+2)
                print(N-i,N-i-1)
            for i in range(2):
                print(N//2+i,1)
                print(N//2+i,N)
        else:
            print(N*2-2)
            for i in range(N//2-1):
                print(i+1,i+2)
                print(i+1,N-i-2)
                print(N-i-1,i+2)
                print(N-i-1,N-i-2)
            print(N//2,N)
            print(N//2+1,N)
            print(N,1)
            print(N,N-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# AGC032B - Balanced Neighbors
def main():
    N = int(input())
    if N % 2:
        V = [(i, N - i) for i in range(1, N // 2 + 1)]  # pairs of vertices
        V += [(N,)]
    else:
        V = [(i, N - i + 1) for i in range(1, N // 2 + 1)]
    E, l = [], len(V)  # edges
    for i in range(l - 1):
        E += [(v, u) for v in V[i] for u in V[i + 1]]
    if l >= 3:
        E += [(v, u) for v in V[0] for u in V[-1]]
    print(len(E))
    print("\n".join(["{} {}".format(v, u) for v, u in E]))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# AGC032B - Balanced Neighbors
def main():
    N = int(input())
    if N % 2:
        V = [(i, N - i) for i in range(1, N // 2 + 1)]  # pairs of vertices
        V += [(N,)]
    else:
        V = [(i, N - i + 1) for i in range(1, N // 2 + 1)]
    E, l = [], len(V)  # edges
    for i in range(l - 1):
        E += [(v, u) for v in V[i] for u in V[i + 1]]
    if l >= 3:
        E += [(v, u) for v in V[0] for u in V[-1]]
    print(len(E))
    for v, u in E:
        print(v, u)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())
ans = []
if N % 2 == 0:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if j <= i or i + j == N + 1:
                continue
            ans.append((i, j))
else:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if j <= i or i + j == N:
                continue
            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:
    print(n * ((n // 2) - 1))
    for i in range(1, n):
        for j in range(i+1, n + 1):
            if i + j != n + 1:
                print(i, j)    
else:
    print(((n - 2) * (n - 1) // 2) + (n // 2))
    for i in range(1, n):
        for j in range(i+1, n + 1):
            if i + j != n:
                print(i, j)

Submission status: Accepted

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

class UnionFind :
    def __init__(self, size) :
        """
        Parameters
        ---
        size : int
            頂点数
        """
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        """
        親のインデックスの取得

        Parameters
        ---
        index : int
            取得する頂点のインデックス

        Returns
        ---
        rootIndex : int
            指定した頂点の根のインデックス
        """
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        """
        木の結合

        Parameters
        ---
        index1 : int
        index2 : int
            結合する頂点のインデックス
        """
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        """
        同じ木に属するかを判定する

        Parameters
        ---
        index1 : int
        index2 : int

        Returns
        ---
        boolean
        """
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        """
        指定した頂点の属する木の大きさを取得する
        """
        return self.size[self.root(index)]

    def getComponent(self) :
        """
        連結成分数を取得する
        """
        return self.component

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

    tree = UnionFind(N)

    if N % 2 == 0:
        for i in range(N // 2):
            tree.union(i, N - 1 - i)
    else:
        for i in range(N // 2):
            tree.union(i, N - 2 - i)

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

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


sol()

Submission status: Accepted

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

N = int(input())

S = N if N&1 else N+1
E = [(x,y) for x in range(1,N+1) for y in range(x+1,N+1) if x+y != S]

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