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:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def func(root, left, right):
    if right <= left:
        return
    print root, right
    print root, left
    func(right, left + 1, right - 1)

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    s = 0
    sum_list = [0 for i in range(N + 1)]
    for i in range(1, N + 1):
        sum_list[i] = sum_list[i - 1] + i
        s += i


    if N % 2 == 0:
        groups = []
        for i in range(1, N/2 + 1):
            groups.append((i, N-i + 1))
        groups = set(groups)
        groups_copy = copy.deepcopy(groups)
        pair = []
        for g1 in groups:
            groups_copy.remove(g1)
            for g2 in groups_copy:
                    for nd1 in g1:
                        for nd2 in g2:
                            if nd1 != 0 and nd2 != 0:
                                pair.append((nd1, nd2))
        print len(pair)
        for i in range(len(pair)):
            print pair[i][0], pair[i][1]
##        left_list = []
##        right_list = []
##
##        for k in range(1, N + 1):
##            left_sum = 0
##            for i in range(k, N + 1):
##                if sum_list[i] - sum_list[i - k] == s / 2:
##                    left_list = set([j for j in range(i - k + 1, i + 1)])
##                    right_list = set([j for j in range(1, N + 1)]) - left_list
##                    print len(left_list) * len(right_list)
##                    for l in left_list:
##                        for r in right_list:
##                            print l, r
##                    return
    else:
        groups = [(N, 0)]
        for i in range(1, N/2 + 1):
            groups.append((i, N-i))
        groups = set(groups)
        groups_copy = copy.deepcopy(groups)
        pair = []
        for g1 in groups:
            groups_copy.remove(g1)
            for g2 in groups_copy:
                    for nd1 in g1:
                        for nd2 in g2:
                            if nd1 != 0 and nd2 != 0:
                                pair.append((nd1, nd2))
        print len(pair)
        for i in range(len(pair)):
            print pair[i][0], pair[i][1]




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

print(cnt)

for i in range(1, N + 1):
    for g in G[i]:
        print(i, g)

Submission status: Accepted

Solution code:
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        N = int(input())
    else:
        pass

    T = np.asarray([False]*(N**2))
    T = T.reshape(N,N)
    Res = np.copy(T)
    range_N = np.asarray(range(N))
    #range_N += 1

    if N % 2 == 0:
        for i,j in zip(range_N,range_N[::-1]):
            if i >= j: break
            T[i,j] = True
            T[j,i] = True
    else:
        for i,j in zip(range_N,range_N[::-1]):
            j -= 1
            if i >= j: break
            T[i,j] = True
            T[j,i] = True

    Res[T==True] = False
    Res[T==False] = True
    
    for i in range_N:
        Res[i,i] = False

    #print(Res)
    print(Res[Res].size//2)

    for i in range_N:
        for j in range_N[i:]:
            if Res[i,j] == True: print(i+1,j+1)
if __name__ =='__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())

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

Submission status: Accepted

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


def solve(N: int):
    if N % 2 == 0:              # 偶数
        tot = N+1
    else:
        tot = N
    ans = []
    for i in range(1, N):
        for j in range(i+1, N+1):
            if i + j == tot:
                continue
            ans.append([i, j])
    print(len(ans))
    for a in ans:
        print(*a, sep=" ")

    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:
N = int(input())
ans = []
for i in range(1,N):
    for j in range(i+1,N+1):
        if i+j!=(N//2)*2+1:
            ans.append([i,j])

print(len(ans))
[print(a,b) for a,b in ans]

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def find(N):
    
    if N==3:
        print(2)
        print(1,3)
        print(2,3)
        return 0
        
    if N==4:
        print(4)
        print(1,2)
        print(2,4)
        print(3,4)
        print(1,3)
        return 0
    
    k=N//2
    edges=[]
    if N==2*k:
        for i in range(1,k):
            edges+=[(i,N-i)]
            edges+=[(i,i+1)]
            edges+=[(N+1-i,i+1)]
            edges+=[(N+1-i,N-i)]
        edges+=[(k,1)]
        edges+=[(k,N)]
        edges+=[(k+1,1)]
        edges+=[(k+1,N)]
        edges=set(edges)
        print(len(edges))
        for X in edges:
            print(X[0],X[1])
    else:
        for i in range(1,k):
            edges+=[(i,N-1-i)]
            edges+=[(i,i+1)]
            edges+=[(N-1+1-i,i+1)]
            edges+=[(N-1+1-i,N-1-i)]
        edges+=[(k,N),(N-k,N),(1,N),(N-1,N)]
        edges=set(edges)
        print(len(edges))
        for X in edges:
            print(X[0],X[1])
            
find(int(input()))

Submission status: Accepted

Solution code:
n = int(input())
an = []
if n % 2 == 0:
    a = 1
else:
    a = 0

for i in range(n,0,-1):
    for j in range(1, i):
        if j != a:
            an.append([i,j])
    a += 1
print(len(an))
for i in an:
    print(i[0], i[1])

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

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

li = []

for i in range(0,(n//2)*2):
  if i+1 < n-i:
    li.append([i+1,n-i-n%2])
  else:
    break
if n%2 == 1:
  li.append([n])
if len(li) > 2:
  li.append(li[0])

count = 0
for i in range(1,len(li)):
  for j in li[i-1]:
    for k in li[i]:
      count += 1
print(count)
for i in range(1,len(li)):
  for j in li[i-1]:
    for k in li[i]:
      print(j,k)

Submission status: Accepted

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

N = int(input())

phi = 0 if N & 1 else 1
print(N * (N - 1) // 2 - N // 2)
for i in range(N):
    for j in range(i+1, N):
        k, l = i+1, j+1
        if l != N - k + phi:
            print(k, l)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

# 完全グラフは惜しい
# 各頂点から自身を除く頂点すべてに辺を貼る
# 誤差をなくすために辺を削る
# 元々十分に辺が張られているので、連結は保たれるだろう

# 補グラフ

# 要素数の偶奇で異なる
# 奇数: [1-6, 2-5, 3-4, 7]
# 偶数: [1-8, 2-7, 3-6, 4-5]

e = [[False for _ in range(N + 1)] for _ in range(N + 1)]
# 1-indexed
for i in range(1, N + 1):
    for j in range(1, N + 1):
        if i == j: continue
        e[i][j] = True
        e[j][i] = True
# 完全グラフを作る

total = -1
if N % 2 == 0:
    total = N + 1
else:
    total = N
# 補グラフのcounterpartを探すのに使用
# total - 自身 = 相方

for i in range(1, N + 1):
    for j in range(1, N + 1):
        if i == j: continue
        cp_i = total - i
        e[i][cp_i] = False
        # 辺を削る

print(sum(e[i].count(True) for i in range(1, N + 1)) // 2)
# 辺をa->b, b->aで二重計上しているので、半分にする

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

Submission status: Accepted

Solution code:
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in xrange(n)]

def make2d_arr(w,h,val =INF):
    return [[val for i in xrange(w)]for i in xrange(h)]

n = int_raw()

edge = make2d_arr(n,n,0)

n_even = n - n%2

comp_edge = [(i,n_even-i-1) for i in xrange(0,n_even)]

for e in comp_edge:
    edge[e[0]][e[1]]=1
    edge[e[1]][e[0]]=1

m = 0
ans = []

for i in xrange(n):
    for j in xrange(i):
        if edge[j][i] == 0:
            m+=1
            ans.append((i,j))
print m
for a in ans:
    print a[0]+1,a[1]+1

Submission status: Accepted

Solution code:
#n=input()
#li=input().split()
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import math
#li=list(map(int,input().split()))

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

else:
    ans=int(((n-1)**2)/2)
    print(ans)
    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 == 3:
    print(2)
    print(1,3)
    print(2,3)
    exit()

if N == 4:
    print(4)
    print(1,2)
    print(1,3)
    print(4,2)
    print(4,3)
    exit()

if N%2 == 1:
    n = int((N+1)/2)
    group = [[0] * 2 for i in range(n-1)]
    M = n*4 - 4
    edge = []
    for i in range(n-1):
        group[i][0] = i+1
        group[i][1] = N-i-1
    for i in range(n-1):
        if i == n-2:
            edge.append([group[i][0],N])
            edge.append([group[i][1],N])
            edge.append([N,group[0][0]])
            edge.append([N,group[0][1]])
            #edge.append([group[i][1],group[i+1][0]])
            #edge.append([group[i][1],group[i+1][1]])    
        else:
            edge.append([group[i][0],group[i+1][0]])
            edge.append([group[i][0],group[i+1][1]])
            edge.append([group[i][1],group[i+1][0]])
            edge.append([group[i][1],group[i+1][1]])

if N%2 == 0:
    n = int(N/2)
    group = [[0] * 2 for i in range(n)]
    M = n*4
    edge = []
    for i in range(n):
        group[i][0] = i+1
        group[i][1] = N-i
    for i in range(n):
        if i == n-1:
            edge.append([group[i][0],group[0][0]])
            edge.append([group[i][0],group[0][1]])
            edge.append([group[i][1],group[0][0]])
            edge.append([group[i][1],group[0][1]]) 
        else:
            edge.append([group[i][0],group[i+1][0]])
            edge.append([group[i][0],group[i+1][1]])
            edge.append([group[i][1],group[i+1][0]])
            edge.append([group[i][1],group[i+1][1]])

print(M)
#print(group)
for m in range(M):
    print(edge[m][0],edge[m][1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    se = N+1 if N % 2 == 0 else N
    return list(filter(lambda x: x[0]+x[1]!=se, combinations(range(1, N+1), 2)))


def main():
    N = read_int()
    E = slv(N)
    print(len(E))
    for e in E:
        print('%d %d' % e)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    E = []
    
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if N % 2 == 0 and i+j == N+1:
                continue
            if N % 2 == 1 and i+j == N:
                continue
            E.append((i, j))

    return E


def main():
    N = read_int()
    E = slv(N)
    print(len(E))
    for e in E:
        print('%d %d' % e)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
ans = []
lis = []
for i in range(N):
    lis.append(i + 1)
if N % 2 == 0:
    M = (N - 2) * N // 2
    for i in range(1, N):
        for j in range(1, N):
            if j != i and i != lis[-j]:
                tmp = sorted([i, lis[-j]])
                if tmp not in ans:
                    ans.append(tmp)
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))
else:
    M = (N - 1) ** 2 // 2
    for i in range(1, N):
        for j in range(2, N):
            if j != i + 1 and i != lis[-j]:
                tmp = sorted([i, lis[-j]])
                if tmp not in ans:
                    ans.append(tmp)
    for i in range(1, N):
        ans.append([N, i])
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))

Submission status: Accepted

Solution code:
N = int(input())
ans = []
lis = []
for i in range(N):
    lis.append(i + 1)
if N % 2 == 0:
    M = (N - 2) * N // 2
    for i in range(1, N):
        for j in range(1, N):
            if j != i and i != lis[-j]:
                if sorted([i, lis[-j]]) not in ans:
                    ans.append(sorted([i, lis[-j]]))
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))
else:
    M = (N - 1) ** 2 // 2
    for i in range(1, N):
        for j in range(2, N):
            if j != i + 1 and i != lis[-j]:
                if sorted([i, lis[-j]]) not in ans:
                    ans.append([i, lis[-j]])
    for i in range(1, N):
        ans.append([N, i])
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    aD = []
    if N % 2 :
        aD = [[i,N-i] for i in range(1,(N+1)//2)]
        aD.append([N])
    else:
        aD = [[i,N+1-i] for i in range(1,(N//2)+1)]
    iD = len(aD)
    dRes = set()
    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:
                    dRes.add(strfy([aD[i][0],aD[j][0]]))
                    dRes.add(strfy([aD[i][0],aD[j][1]]))
                elif len(aD[j])== 1:
                    dRes.add(strfy([aD[i][0],aD[j][0]]))
                    dRes.add(strfy([aD[i][1],aD[j][0]]))
                else:
                    dRes.add(strfy([aD[i][0],aD[j][0]]))
                    dRes.add(strfy([aD[i][0],aD[j][1]]))
                    dRes.add(strfy([aD[i][1],aD[j][0]]))
                    dRes.add(strfy([aD[i][1],aD[j][1]]))
    print(len(dRes))
    print(*dRes,sep="\n")
main()

Submission status: Accepted

Solution code:
N = int(input())
X = list(range(1,N+1))
Nsum = sum(X)

n = 2 
while Nsum % n != 0:
    n += 1

group = [[] for i in range(n)]
value = int(Nsum/n)

for i in range(n-1):
    for j in range(N):
        if sum(X[-j-1:]) > value:
            break
    group[i] = X[-j:]
    X = X[:-j]
    ex = value - sum(group[i])
    if ex != 0:
        group[i].append(X.pop(X.index(ex)))

group[-1] = X

LEN = []
LENpr = 0
for i in range(n):
    LEN.append(len(group[i]))
for i in range(n-1):
    LENpr += LEN[i] * sum(LEN[i+1:])

print(LENpr)

for i in range(n-1):
    for j in range(i+1,n):
        for k in range(LEN[i]):
            for l in range(LEN[j]):
                print(group[i][k],group[j][l])

Submission status: Accepted

Solution code:
import sys

N = int(input())

if N == 4:
  print(4)
  print('{} {}'.format(1, 2))
  print('{} {}'.format(1, 3))
  print('{} {}'.format(4, 3))
  print('{} {}'.format(4, 2))
  sys.exit()

if N % 2 == 0:
  M = N // 2 * 4
  print(M)
  for k in range(1, N // 2):
    print('{} {}'.format(k, k+1))
    print('{} {}'.format(k, N-k))
    print('{} {}'.format(N-k+1, N-k))
    print('{} {}'.format(N-k+1, k+1))
  print('{} {}'.format(1, N//2))
  print('{} {}'.format(1, N//2 + 1))
  print('{} {}'.format(N, N//2))
  print('{} {}'.format(N, N//2 + 1))
  sys.exit()

if N == 3:
  print(2)
  print('{} {}'.format(1, 3))
  print('{} {}'.format(2, 3))
  sys.exit()


if N % 2 == 1:
  M = (N // 2) * 4
  print(M)
  for k in range(1, N // 2):
    print('{} {}'.format(k, k+1))
    print('{} {}'.format(k, N-k-1))
    print('{} {}'.format(N-k, N-k-1))
    print('{} {}'.format(N-k, k+1))
  print('{} {}'.format(1, N))
  print('{} {}'.format(N-1, N))
  print('{} {}'.format(N // 2, N))
  print('{} {}'.format(N // 2 + 1, N))
  sys.exit()

Submission status: Accepted

Solution code:
N=int(input())






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

print(len(out))
for i in out:
	print(i)

Submission status: Accepted

Solution code:
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG =  True
def ddprint(x):
  if DBG:
    print(x)

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

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline())

ans = ["%d\n" % (N*(N-1)//2 - N//2)]
K = N+((N&1)^1)
for i in range(1, N+1):
    for j in range(i+1, N+1):
        if i + j != K:
            ans.append("%d %d\n" % (i, j))
sys.stdout.writelines(ans)

Submission status: Accepted

Solution code:
n = int(input())

if n % 2 == 1:
    ans = []
    count = 0

    for i in range(1, n):
        ans.append((i, n))
        count += 1

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

    print(count)
    for a, b in ans:
        print(a, b)
else:
    ans = []
    count = 0

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

        
def f3(N,S,M):
    sm=S//M
    l=[]
    for i in range(M):
        l.append([])
    li=[i for i in range(1,N+1)]
    for x in range(M):
        tmp=0
        for i in reversed(range(N)):
            if li[i]==-1:
                continue
            tmp+=li[i]
            if tmp>sm:
                tmp-=li[i]
                if li[sm-tmp-1]==-1:
                    #print(N,sm,"!!!")
                    return
                l[x].append(sm-tmp)
                li[sm-tmp-1]=-1
                break
            l[x].append(li[i])
            li[i]=-1
            if tmp==sm:
                break
    y=0
    for x in range(M):
        y+=len(l[x])*(N-len(l[x]))
    y//=2
    print(y)
    for x in range(M):
        for xi in l[x]:
            for y in range(x+1,M):
                for yi in l[y]:
                    print(xi,yi)
    
    
def min_factor(S):
    for i in range(2,101):
        if S%i==0:
            return i

#24,39

N=int(input())
S=N*(N+1)//2
M=min_factor(S)
f3(N,S,M)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit
from numpy.random import rand
# A,B,C = [int(n) for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
N = int(input())
# dic = {}
# for i in range(1,N+1):
#     dic[i] = 0
#偶数ならN+1をつくる
ansgroup = []
if N%2 == 0:
    for i in range(1,N//2+1):
        ansgroup.append([i, N-i+1])
else:
    for i in range(1,N//2+1):
        ansgroup.append([i, N-i])
    ansgroup.append([N])
nodesum = 0
ans = []
for i in range(len(ansgroup)):
    for j in range(i+1,len(ansgroup)):
        for e1 in ansgroup[i]:
            for e2 in ansgroup[j]:
                nodesum+=1
                ans.append([e1,e2])
print(nodesum)
for a in ans:
    print(a[0],a[1])
# ansset = set([ i for i in range(1,N+1)])
# tmpset = set()
# for i in range(1,len(ans)):
#     if ans[i-1][0] == ans[i][0]:
#         tmpset = ans[i][1] | ans[i-1][1]
#     else:
#         print(ans[i-1][0],ansset)
#         ansset = set([ i for i in range(1,N+1)])
# exit()
#奇数ならNをつくる組みあわせがペアそれ以外とぜんぶつながる

Submission status: Accepted

Solution code:
n = int(input())
nums = list()
answers = list()
i = 0
if n % 2 == 0:
    while not(i == n / 2):
        nums.append((i+1,n-i))
        i += 1
else:
    while not(i == (n-1)/2):
        nums.append((i+1, n-i-1))
        i += 1
    nums.append((n,))
i = 0
while i < len(nums) - 1:
    for a in nums[i]:
        for b in nums[i+1]:
            answers.append((a, b))
    i += 1
if len(nums) >= 3:
    for a in nums[0]:
        for b in nums[-1]:
            answers.append((a,b))
print(len(answers))
for a, b in answers:
    print(a, b)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

if N % 2 == 0:
    M = N*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(i, j)
else:
    M = (N*N+1)//2 - N
    print(M)
    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:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
gc032 B
"""


n = int(input())
es = []

if n % 2 == 1:
    for i in range(1, n):
        for j in range(i+1, n+1):
            if not (i+j == n):
                es.append((i, j))
else:
    for j in range(2,n):
        es.append((1,j))
    for i in range(2, n):
        for j in range(i+1, n+1):
            if not (i+j == n+1):
                es.append((i, j))

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

Submission status: Accepted

Solution code:
n = int(input())

if n == 3:
    print("2")
    print("1 3")
    print("2 3")
if n == 4:
    print("4")
    print("1 2")
    print("1 3")
    print("2 4")
    print("3 4")
if n >= 5:
    ans = []
    if n % 2 == 0:
        for i in range(1, n):
            for j in range(i+1, n+1):
                if i + j != n+1:
                    ans.append(str(i)+" "+str(j))
                    # print(str(i)+" "+str(j))
    if n % 2 == 1:
        for i in range(1, n-1):
            for j in range(i+1, n):
                if i + j != n:
                    ans.append(str(i)+" "+str(j))
                    # print(str(i)+" "+str(j))
        for i in range(1, n):
            ans.append(str(i)+" "+str(n))
            # print(str(i)+" "+str(n))
    ans_len = len(ans)
    print(ans_len)
    for a in ans:
        print(a)

# for ptn1 in range(2 ** 5):
#     ptn_str1 = format(ptn1, '05b')
#     p1 = []
#     for i, p in enumerate(ptn_str1):
#         if p == '1':
#             p1.append(i+2)
#     for ptn2 in range(2 ** 4):
#         ptn_str2 = format(ptn2, '04b')
#         p2 = []
#         for j, q in enumerate(ptn_str2):
#             if q == '1':
#                 p2.append(j+3)
#         for ptn3 in range(2 ** 3):
#             ptn_str3 = format(ptn3, '03b')
#             p3 = []
#             for k, r in enumerate(ptn_str3):
#                 if r == '1':
#                     p3.append(k+4)
#             for ptn4 in range(2 ** 2):
#                 ptn_str4 = format(ptn4, '02b')
#                 p4 = []
#                 for l, s in enumerate(ptn_str4):
#                     if s == '1':
#                         p4.append(l+5)
#                 adds = [0, 0, 0, 0, 0, 0]
#                 for x in p1:
#                     adds[0] += x
#                     adds[x-1] += 1
#                 for y in p2:
#                     adds[1] += y
#                     adds[y-1] += 2
#                 for z in p3:
#                     adds[2] += z
#                     adds[z-1] += 3
#                 for zz in p4:
#                     adds[3] += zz
#                     adds[zz-1] += 4
#                 if adds[4]+6 == adds[5]+5:
#                     # print("adds5&6"+ptn_str1+"/"+ptn_str2+"/"+ptn_str3+"/"+ptn_str4)
#                     adds[4] += 6
#                     adds[5] += 5
#                 eq = adds[0]
#                 if eq != 0:
#                     equal = True
#                     for s in adds:
#                         if s != eq:
#                             equal = False
#                             break
#                     if equal is True:
#                         print(eq)
#                         print(ptn_str1)
#                         print(ptn_str2)
#                         print(ptn_str3)
#                         print(ptn_str4)

Submission status: Accepted

Solution code:
N = int(input())
S = 0
for i in range(1, N):
    S += i

Ans = []

if N % 2 == 1:
    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):
        for j in range(i+1, N+1):
            if j != N - i + 1:
                Ans.append((i, j))


print(len(Ans))
for a in Ans:
    print(" ".join(map(str, a)))

Submission status: Accepted

Solution code:
def solve(N):
  ans = []
  if N % 2 == 1:
    ans = solve(N - 1)
    for i in range(1, N):
      ans.append('{} {}'.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('{} {}'.format(i, j))
  return ans

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

Submission status: Accepted

Solution code:
N = int(input())

N_sub = N
if N % 2 == 0:
    pass
else:
    N = N-1

num = int(N*(N-1)/2-N/2)
all_num = N*(N+1)/2

arr = []
for i in range(1,N+1):
    for j in range(1,N+1):
        if i < j:
            arr.append([i, j])

for i in range(1,int(N/2+1)):
    arr.remove([i, N+1-i])

if N_sub == N:
    print(num)
    for i in range(len(arr)):
        print(arr[i][0],arr[i][1]) 

else:
    for i in range(1,N_sub):
        arr.append([i,N_sub])
    print(num+N_sub-1)
    for i in range(len(arr)):
        print(arr[i][0],arr[i][1])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys

N = int(input())

ans = []

if N % 2 == 0:
    tmp = N + 1
else:
    tmp = N
    
for i in range(1,N+1):
    for j in range(i+1,N+1):
        if i + j != tmp:
            ans.append(str(i)+' '+str(j))
            
print(len(ans))

for a in ans:
    print(a)