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())

if N % 2 == 0:
    print((N*N - 2*N)//2)
    for x in range(N):
        for y in range(x+1,N):
            if x != y and x+y != N-1:
                print(x+1,y+1)

else:
    print((N*N-N*2+1)//2)
    for x in range(N):
        for y in range(x+1,N):
            if x != y and x+y != N-2:
                print(x+1,y+1)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())

def solve(N):
  fmt = '{} {}'
  ans = []
  sub = []
  if N % 2 == 1:
    ans = solve(N - 1)
    for i in range(1, N):
      ans.append(fmt.format(i, N))
  else:
    for i in range(1, N + 1):
      for j in range(i + 1, N + 1):
        if j == N - i + 1: continue
        ans.append(fmt.format(i, j))
  return ans

ans = solve(N)
print(len(ans))
[print(a) for a in ans]

Submission status: Accepted

Solution code:

# 整数の入力
N = int(input())

# スペース区切りの整数の入力
if N%2 == 0:
    M = int(0.5*N**2-N)
    print(M)
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i+j != N+1:
                print("{} {}".format(i, j))
else:
    N = N-1
    M = int(0.5*N**2-N)
    print(M+N)
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i+j != N+1:
                print("{} {}".format(i, j))
        print("{} {}".format(i, N+1))

Submission status: Accepted

Solution code:
N = int(input())
odd = N % 2
ans = []
for f in range(1, N+1):
  for t in range(f+1, N+1):
    if t != N - (f-1) - odd:
      ans.append([f,t])

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

Submission status: Accepted

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

n = int(input())
if n == 3:
    print(2)
    print(1,3)
    print(2,3)
else:
    res = [[1,3],[2,3]]
    cnt = 0
    for i in range(4,n+1):
        if i%2 == 0:
            for j in range(len(res)):
                res[j] = [res[j][0]+1,res[j][1]+1]
            for j in range(2,i):
                res.append([1,j])
        else:
            for j in range(1,i):
                res.append([i,j])
    print(len(res))
    for e in res:
        print(e[0],e[1])

Submission status: Accepted

Solution code:
N = int(input())
X = sum(range(1, N))
if N % 2 == 0:
    X -= 1


delete = set()
for n in range(1, N + 1):
    diff = sum(range(1, N + 1)) - X - n
    minus = N - 1
    minus += (N % 2 == 0)
    while diff:
        if (diff - minus < 0) or (minus == n):
            minus -= 1
            continue
        diff -= minus
        delete.add((min(n, minus), max(n, minus)))


ans = []
for n in range(1, N + 1):
    for to in range(n + 1, N + 1):
        if (n, to) in delete:
            continue
        else:
            ans.append([n, to])

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

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_list_of_float():
    return [float(f) for f in input().split()]


def get_list_of_char():
    return list(input().strip())


def get_data(n, order=None, **kwargs):
    if not order:
        order = range(len(kwargs))
    it = iter(order)
    var, fn = zip(*sorted(sorted(kwargs.items()), key=lambda _: next(it)))

    rows = []
    for _ in range(n):
        rows.append(input().split())
    columns = zip(*rows)
    exec("global "+", ".join(var)+"\n"+"\n".join(
        v+"=list(map(fn[{}], data[{}]))".format(i, i)
        for i, v in enumerate(var)),
        globals(),
        {"fn": list(fn), "data": list(columns)}
    )
    return


# inputs
N = 0


def set_inputs():
    global N
    N = get_int()
    return


def find(n):
    bits = []
    for i in range(2**(n*(n-1)//2)):
        bits = [(i >> j) % 2 for j in range(n*(n-1)//2)]
        cnt = Counter()
        for j in range(1, n+1):
            cnt[j] = 0
        edges = []
        for x, y in itertools.compress(
                itertools.combinations(range(1, n+1), 2),
                bits
        ):
            cnt[x] += y
            cnt[y] += x
            edges.append((x, y))
        counts = list(cnt.values())
        if len(edges) > 0 and all(v == counts[0] for v in counts):
            print(i, bits, edges)


def solve(n):
    s = n
    if n % 2 == 0:
        s = n + 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 == s:
                continue
            print(i, j)


def main():
    setrecursionlimit(100000)
    set_inputs()
    solve(N)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())

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

ans = []
for i, a in enumerate(li):
    for j, b in enumerate(li):
        if i >= j:
            continue
        if len(a) == 1:
            ans.append([a[0], b[0]])
            ans.append([a[0], b[1]])
        elif len(b) == 1:
            continue
            # ans.append([a[0], b[0]])
            # ans.append([a[1], b[0]])
        else:
            ans.append([a[0], b[0]])
            ans.append([a[1], b[0]])
            ans.append([a[0], b[1]])
            ans.append([a[1], b[1]])

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

Submission status: Accepted

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

from collections import deque
import heapq
import math
import bisect


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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 0

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

else:
    for i in range(1,n+1):
        for j in range(i,n+1):
            if j == n-i or j ==i:
                continue
            ans += 1

print(ans)

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

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

Submission status: Accepted

Solution code:
import itertools
N = int(input())
a = [i for i in range(1, N+1)]
graph = list(itertools.combinations(a, 2))
graph
for i in range(N//2):
    graph.remove((i+1, 2*(N//2)-i))
print(len(graph))
for i in range(len(graph)):
    print(graph[i][0], graph[i][1])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

if N==3 or N==4:
    print((N-2)*2)
else:
    if N%2==0:
        print(N*2)
    else:
        print((N-1)*2)
    
for i in range(len(L)-1):
    for j in range(len(L[i])):
        for k in range(len(L[i+1])):
            print(L[i][j],L[i+1][k])
if N==3 or N==4:
    exit()
else:
    for j in range(len(L[len(L)-1])):
        for k in range(len(L[0])):
            print(L[len(L)-1][j],L[0][k])

Submission status: Accepted

Solution code:
N = int( input())

if N == 3:
    print(2)
    print(1,3)
    print(2,3)
else:
    s = N%2
    N = N//2*2
    ans = 0
    for i in range(2,N//2+1):
        ans += 4*i - 4
    if s == 0:
        print(ans)
    else:
        print(ans+N)
    print(1, N-1)
    print(1,2)
    print(2,N)
    print(N-1,N)
    for i in range(2,N//2):
        for j in range(1,i+1):
            print(j, i+1)
            print(j, N-i)
            print(N+1-j, i+1)
            print(N+1-j, N-i)
    if s == 1 and N != 2:
        for i in range(1,N+1):
            print(i, N+1)

Submission status: Accepted

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

B = [[0]*n for i in range(n)]
for i in range(n):
    for j in range(i+1,n):
        if i+j != (n-n%2)-1:
            E.append((i,j))
            B[i][j] = 1
            B[j][i] = 1
print(len(E))
for a,b in E:
    print(a+1,b+1)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

connect_lis=[]

for i in lis:
    for j in i:
        for k in lis:
            if k!=i:
                for p in k:
                    if j < p:
                        connect_lis.append([j,p])
        
print(len(connect_lis))
for i in connect_lis:
    print(i[0],i[1])

Submission status: Accepted

Solution code:
import sys

N = int(input())
nsum = N * (N + 1) // 2

for S in range(N*(N-1)//2, N-1, -1):
    s = [nsum - n for n in range(0, N+1)]
    cutv = []
    for n in range(N, 0, -1):
        rem = s[n] - S
        for i in range(rem, 0, -1):
            if s[n] == S:
                break
            if s[n] - i < S:
                continue
            if s[i] - n < S:
                continue
            s[i] -= n
            s[n] -= i
            if i <= n:
                cutv.append((i, n))
            else:
                cutv.append((n, i))
        if s[n] != S:
            break
    else:
        print(N * (N - 1) // 2 - len(cutv))
        for i in range(1, N + 1):
            for j in range(i + 1, N + 1):
                if (i, j) not in cutv:
                    print(i, j)
        sys.exit()

raise

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict, Counter
from itertools import permutations, product, combinations
from bisect import bisect, bisect_left
from fractions import gcd
MOD = 10**9 + 7

def inpl(): return list(map(int, input().split()))

def primes(N):
    sieve = [1]*101
    sieve[0] = 0
    sieve[0] = 1
    P = []
    for i in range(2, 101):
        if sieve[i]:
            P.append(i)
            for j in range(i*2, 101, i):
                sieve[j] = 0
    return P

P = primes(100)
N = int(input())

X = (N*(N+1))//2
for p in P:
    if X%p == 0:
        break

groups = []
searched = set()
for j in range(p):
    target = X//p
    A = []
    for i in range(N, 0, -1):
        if i <= target and not i in searched:
            A.append(i)
            target -= i
    assert target == 0
    A = set(A)
    searched.update(A)
    groups.append(A)

M = 0
for g in groups:
    M += (N-len(g))*len(g)
print(M//2)
S = set(range(1, N+1))

for g in groups:
    for x in g:
        for y in S - g:
            print(x, y)
        S = S - g

Submission status: Accepted

Solution code:
N = int(input())
aD = []
if N % 2 :
    aD.append([N])
    for i in range(1,(N+1)//2):
        aD.append([i,N-i])
else:
    for i in range(1,(N//2) + 1):
        aD.append([i,N+1-i])
iD = len(aD)
aRes = []
def strfy(aD):
    return " ".join(str(_) for _ in sorted(aD))
for i in range(iD):
    for j in range(iD):
        if i == j :
            pass
        else:
            if len(aD[i]) == 1:
                aRes.append(strfy([aD[i][0],aD[j][0]]))
                aRes.append(strfy([aD[i][0],aD[j][1]]))
            elif len(aD[j])== 1:
                aRes.append(strfy([aD[i][0],aD[j][0]]))
                aRes.append(strfy([aD[i][1],aD[j][0]]))
            else:
                aRes.append(strfy([aD[i][0],aD[j][0]]))
                aRes.append(strfy([aD[i][0],aD[j][1]]))
                aRes.append(strfy([aD[i][1],aD[j][0]]))
                aRes.append(strfy([aD[i][1],aD[j][1]]))
aRes = list(set(aRes))
print(len(aRes))
print(*aRes,sep="\n")

Submission status: Accepted

Solution code:
N = int(input())
ans_list = []
# p_list = list(range(1,N+1))
if N%2 ==0:
   M = int(N*(N-2)/2)
   for i in range(1,N+1):
       pair = N+1-i
       for j in range(i+1,N+1):
           if j != pair:
               ans_list.append([i,j])
#         add_list = [[i,j] for j in range(i+1,N+1) if j != pair]
#         ans_list.extend(add_list)
else:
   M = int((N-1)*(N-1)/2)
   for i in range(1,N):
       pair = N-i
       for j in range(i+1,N):
           if j != pair:
               ans_list.append([i,j])
       ans_list.append([i,N])

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

Submission status: Accepted

Solution code:
#AGC031-B
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
if n%2==0:
    print(n*(n-2)//2)
    for i in range(n):
        for j in range(n):
            if i<j and i+j+2!=1+n:
                print(i+1,j+1)
else:
    print((n-1)*(n-3)//2+n-1)
    for i in range(n-1):
        for j in range(n-1):
            if i<j and i+j+2!=1+n-1:
                print(i+1,j+1)
    for i in range(n-1):
        print(i+1,n)

Submission status: Accepted

Solution code:
n=int(input())
if n%2==0:
    s=n+1
    res=[]
    for i in range(1,n//2+1):
        res.append([i,s-i])
    z=[]
    for i in range(len(res)-1):
        for j in range(i+1,len(res)):
            for x in range(2):
                for y in range(2):
                    z.append([min(res[i][x],res[j][y]),max(res[i][x],res[j][y])])
    print(len(z))
    for t in z:
        print(t[0],t[1])
else:
    s=n
    res=[]
    for i in range(1,n//2+1):
        res.append([i,s-i])
    z=[]
    for i in range(len(res)-1):
        for j in range(i+1,len(res)):
            for x in range(2):
                for y in range(2):
                    z.append([min(res[i][x],res[j][y]),max(res[i][x],res[j][y])])
    for i in range(1,n):
        z.append([i,n])
    print(len(z))
    for t in z:
        print(t[0],t[1])

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())
ans_list = []
# p_list = list(range(1,N+1))
if N%2 ==0:
    M = int(N*(N-2)/2)
    for i in range(1,N+1):
        pair = N+1-i
        for j in range(i+1,N+1):
            if j != pair:
                ans_list.append([i,j])
#         add_list = [[i,j] for j in range(i+1,N+1) if j != pair]
#         ans_list.extend(add_list)
else:
    M = int((N-1)*(N-1)/2)
    for i in range(1,N):
        pair = N-i
        for j in range(i+1,N):
            if j != pair:
                ans_list.append([i,j])
        ans_list.append([i,N])
        
print(M)
for ans in ans_list:
    print(ans[0],ans[1])

# print(ans_list)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
tmp_sum = 0

for i in range(1, N+1):
  tmp_sum += i
  
if N % 2 == 1:
  S = sum(range(1, N))
else:
  S = sum(range(1, N)) - 1

count = 0
ans = []

for i in range(1, N):
  tmp_sum = sum(range(1, N+1)) - i
  exclude = tmp_sum - S
  for j in range(i+1, N+1):
    if j != int(exclude):
      count += 1
      ans.append((i, j))

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

Submission status: Accepted

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

pairs = []
if n % 2 == 0:
    for x in range(1, int(n/2) + 1):
        pairs.append([x, n-x + 1])
else:
    for x in range(1, int((n-1)/2) +1):
        pairs.append([x, int((n-1))-x+1])
    pairs.append([n])
# print(f'pairs >>>>> {pairs}')

# connect nodes
edges = []
for x in range(1, n+1):
    for p in pairs:
#         print(f'x: {x}, p: {p}')
        if x in p:
            break
        for node in p:
#             print(sorted([x, node]))
            edges.append(sorted([x, node]))

# print(f'edges >>>>> {edges}')
print(len(edges))
for e in edges:
    print(' '.join([str(i) for i in e]))

Submission status: Accepted

Solution code:
def balanced_neighbors(N: int)->list:
    if N & 1:
        return balanced_neighbors(N-1) + [(i, N) for i in range(1, N)]

    res = []
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i + j == N+1:
                continue
            res.append((i, j))
    return res


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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

def main(n):
	s = int(n*(n+1)/2)
	a = []
	b = []
	if s % 2 == 0:
		i = n
		ts = s/2
		while i != 0:
			if i <= ts:
				a += [min(i, ts)]
				ts -= min(i, ts)
			else:
				b += [i]
			i -= 1
		print(len(a)*len(b))
		for i in a:
			for j in b:
				print("{} {}".format(i, j))
	else:
		nn = (n if n % 2 == 1 else n+1)
		mm = int(n/2 if n % 2 == 0 else (n+1)/2)
		lst = [[]]*mm
		for i in range(n, 0, -1):
			flg = True
			for l in range(mm):
				if (sum(lst[l]) + i <= nn) and flg:
					lst = lst[:l] + [lst[l] + [i]] + lst[l+1:]
					flg = False
		m = 0
		for i in range(mm):
			m += len(lst[i%mm])*len(lst[(i+1)%mm])
		print(m)
		for i in range(mm):
			for l in lst[i]:
				for ll in lst[(i+1)%mm]:
					print("{} {}".format(l, ll))
		
		

main(int(input()))

Submission status: Accepted

Solution code:
import math

N=int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = []
cnt = 0
if N % 2 == 0:
    for i in range(1, N+1):
        for j in range(i + 1, N+1):
            if i + j != N+1:
                a.append('{0} {1}'.format(i, j))
                cnt += 1
else:
    for i in range(1, N+1):
        for j in range(i + 1, N+1):
            if i + j != N:
                a.append('{0} {1}'.format(i, j))
                cnt += 1
print(cnt)
for i in range(cnt):
    print(a[i])

Submission status: Accepted

Solution code:
n = int(input())

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

print(m)
for i in range(len(l)):
    for j in range(i+1,len(l)):
        p = l[i]
        o = l[j]
        for point in p:
            for other in o:
                print(str(point)+" "+str(other))

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())

nmod2 = N % 2
lists = []

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

print(len(lists))
for l in lists:
    print(l[0], l[1])

Submission status: Accepted

Solution code:
n=int(input())
a=[]
m=n if n&1 else n+1
i=1
while(i<=n):
    j=i+1
    while(j<=n):
        if j!=m-i:
            a+=[(i,j)]
        j+=1
    i+=1
print(len(a))
for x in a:
    print(*x)

Submission status: Accepted

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


def solve(N: int):
    if N % 2 == 0:              # 偶数
        key = int(N/2)
        M = (N-2)*key
        print(M)
        for i in range(1, key+1):
            for j in range(i+1, N+1):
                if (j <= key) or\
                   (j > key and i % key != (N+1-j) % key):
                    print(i, j)
        for i in range(key+1, N):
            for j in range(i+1, N+1):
                print(i, j)
    else:
        key = int(N/2)
        M = (N-3)*key + N-1
        print(M)
        for i in range(1, key+1):
            for j in range(i+1, N+1):
                if (j <= key) or\
                   (j > key and i % key != (N-j) % key):
                    print(i, j)
                elif j == N:
                    print(i, j)
        for i in range(key+1, N):
            for j in range(i+1, N+1):
                print(i, j)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# encoding: utf-8
import sys
# from collections import deque
input = sys.stdin.readline

N = int(input())

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

Submission status: Accepted

Solution code:
n = int(input())

if n == 3:
    print(2)
    print(1, 3)
    print(2, 3)
    exit()

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

Submission status: Accepted

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

N=int(input())

EDGE=[[1]*(N+1) for i in range(N+1)]
for i in range(N+1):
    EDGE[i][i]=0
    EDGE[0][i]=EDGE[i][0]=0

SUM=[N*(N+1)//2]
for i in range(N):
    SUM.append(SUM[-1]-1)

SUM[0]=0

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

#print(ANSSUM)

for i in range(1,N+1):
    x=SUM[i]-ANSSUM
    EDGE[i][x]=EDGE[x][i]=0

ANS=[]
ANSCOUNT=0
for i in range(1,N+1):
    for j in range(1,N+1):
        if EDGE[i][j]==1:
            ANS.append([i,j])
            ANSCOUNT+=1
            EDGE[i][j]=EDGE[j][i]=0

print(ANSCOUNT)
for ans in ANS:
    print(*ans)

Submission status: Accepted

Solution code:
N = int(input())

res = []

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

print(len(res))
for m in res:
    print(m)

Submission status: Accepted

Solution code:
N=int(input())
if N ==3:
    print(2)
    print("1 3")
    print("2 3")

else:
    if N%2==0:
        if N == 4:print(4)
        else:
            print(N // 2 * 4)
        for i in range(1, N // 2):
            x = i
            y = N + 1 - x
            nx = x + 1
            ny = y - 1
            print(str(x) + ' ' + str(nx))
            print(str(x) + ' ' + str(ny))
            print(str(y) + ' ' + str(nx))
            print(str(y) + ' ' + str(ny))
        if N > 4:
            print(str(N) + ' ' + str(N//2))
            print(str(N) + ' ' + str(N//2 + 1))
            print(str(1) + ' ' + str(N//2))
            print(str(1) + ' ' + str(N//2 + 1))
    else:
        N -= 1
        print(N // 2 * 4)
        for i in range(1, N // 2):
            x = i
            y = N + 1 - x
            nx = x + 1
            ny = y - 1
            print(str(x) + ' ' + str(nx))
            print(str(x) + ' ' + str(ny))
            print(str(y) + ' ' + str(nx))
            print(str(y) + ' ' + str(ny))
        N += 1
        if N > 3:
            print(str(N) + ' ' + str(N//2))
            print(str(N) + ' ' + str(N//2 + 1))
            print(str(N) + ' ' + str(N - 1))
            print(str(N) + ' ' + str(1))

Submission status: Accepted

Solution code:
n=int(input())
if n%2==1:
  print(n-1+int((n-1)*(n-3)*0.5))
  for i in range(1,n):
    print(n,i)
  for i in range(1,n):
    for j in range(i+1,n):
      if i+j!=n:
        print(i,j)
else:
  print(int(n*(n-2)*0.5))
  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())
m = 0
l = 0

if n % 2 == 1:
    m = (n - 1) * (n - 2) // 2 - (n - 1) // 2 + n - 1
    l = n - 1
else:
    m = n * (n - 1) // 2 - n // 2
    l = n

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

Submission status: Accepted

Solution code:
n=int(input())
l=[(i,j) for i in range(1,n+1) for j in range(i+1,n+1)]
if n%2==1:

    for i in range(1,int((n+1)/2)):
        l.remove((i,n-i))
else:
    for i in range(1,int(n/2)+1):
        l.remove((i,n-i+1))
print(len(l))
for i,j in l:
    print(i,j)

Submission status: Accepted

Solution code:
N = int(input())
ans = []
for i in range(1,N):
    for j in range(i+1,N+1):
        ans.append([i,j])
if N % 2 == 1:
    i = 0
    while i < len(ans):
        if ans[i][0] + ans[i][1] == N:
            ans.pop(i)
        else:
            i += 1
    M = len(ans)
    print(M)
    for i in range(M):
        print(str(ans[i][0])+' '+str(ans[i][1]))
else:
    i = 0
    while i < len(ans):
        if ans[i][0] + ans[i][1] == N+1:
            ans.pop(i)
        else:
            i += 1
    M = len(ans)
    print(M)
    for i in range(M):
        print(str(ans[i][0])+' '+str(ans[i][1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())


if N % 2 == 0:
    lst = [i+1 for i in range(N)]
    keyvalue = N+1

    ansedge = []

    conn = [ [False]*N for _ in range(N)]

    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if j != i and j != keyvalue-i: #and not conn[i][j]:
                ansedge.append( (i, j) )
                # conn[i][j] = True
                # conn[j][i] = True
    print(len(ansedge))
    for e in ansedge:
        print(*e)
    
    exit()
else:
    lst = [i+1 for i in range(N)]
    keyvalue = N

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def makelis(eve):
    li =[]
    for i in range(eve//2):
        li.append([eve-i,i+1])
    return li

N =int(input())



if N%2==0:
    numlis = makelis(N)
else:
    numlis = makelis(N-1)
    numlis.append([N])

num =0
for li in numlis:
    num += len(li)*(N-len(li))
print(num//2)

for li in numlis:
    for j in li:
        for i in range(N):
            if not i+1 in li and j < i+1:
                print("{} {}".format(j,i+1))