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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(1,n):
  for j in range(i+1,n+1):
    if i+j!=n:print(i,j)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
# N = 5


if N == 3:
    print('2')
    print('1 3')
    print('2 3')
else:
    # N >= 4
    total = 4 + (N - 4) * 4
    print(total)
    print('1 {}'.format(N - 1))
    print('1 2')
    print('{} 2'.format(N))
    print('{} {}'.format(N, N - 1))
    targets = [1, 2, N - 1, N]
    for i in range(3, N - 1):
        for t in targets:
            print('{} {}'.format(i, t))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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


if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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


if __name__ == '__main__':
   main()

Submission status: Wrong Answer

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

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

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


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

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

    return '\n'.join(rr)


print(main())

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

N = int(input())

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

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

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

Submission status: Wrong Answer

Solution code:

N = int(input())

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

ls = [i for i in range(1,N+1)]
import itertools
plist = list(itertools.combinations(ls,2))
ls = []
cnt=0
all_pattern = len(plist)
mod_cnt = all_pattern//5
if N % 2 == 0:
    sabun = 2
else:
    sabun = 3
temp=N-sabun
ls.append(temp)
for j in range(mod_cnt,0,-1):
    ls.append(max(ls)+j)
    if len(ls) == N//2:
        break
ans_cnt = all_pattern - len(ls)
print(ans_cnt)
idxer = 0
for p in plist:
    if idxer not in ls:
        print(p[0],p[1])
    idxer +=1

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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:
        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: Wrong Answer

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 s % 2 == 0:
        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: Wrong Answer

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 s % 2 == 0:
        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)
        print 4 * (len(groups) - 2) + N - 1
        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:
                                print nd1, nd2




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

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)
        else:
            if i + j != N + 1 and i != j:
                G[i].append(j)
                
for i in range(1, N + 1):
    for g in G[i]:
        print(i, g)

Submission status: Wrong Answer

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

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

k  = (n*(n+1)-18)//12
res = [[k,k+1],[k+1,k+3],[k+3,k+2],[k+2,k]]
for i in range(1,n+1):
    if i in [k,k+1,k+2,k+3]:
        continue
    res.append([i,k])
    res.append([i,k+1])
    res.append([i,k+2])
    res.append([i,k+3])
print(len(res))
for e in res:
    print(e[0],e[1])

Submission status: Wrong Answer

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
    else:
        for i,j in zip(range_N,range_N[:-1:-1]):
            if i >= j: break
            T[i,j] = True

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

    #print(Res)

    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: Wrong Answer

Solution code:
def find(N):
    
    if N==3:
        print(2)
        print(1,3)
        print(2,3)
        
    if N==4:
        print(4)
        print(1,2)
        print(2,4)
        print(3,4)
        print(1,3)
        
    
    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: Wrong Answer

Solution code:
def find(N):
    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: Wrong Answer

Solution code:
n=int(input())

if n % 2 == 0:
    print(int(n*n/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*n-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: Wrong Answer

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])
  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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,a,b=int(input()),[],[]
for i in range(1,n+1):
  for j in range(i,n+1):
    if i!=j and i+j!=n:
      a.append(i)
      b.append(j)
print(len(a))
for i in range(len(a)):print(a[i],b[i])

Submission status: Wrong Answer

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 s % 2 == 0:
        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:
        print (N /2) * 2
        func(N, 1, N - 1)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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 s % 2 == 0:
        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
    else:
        print (N /2) * 2
        func(N, 1, N - 1)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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
        # 辺を削る

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

Submission status: Wrong Answer

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,4)
    print(3,2)
    print(3,4)
    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: Wrong Answer

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()
    for e in slv(N):
        print('%d %d' % e)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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,4)
    print(3,2)
    print(3,4)
    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-3:
            edge.append([group[i][0],N])
            #edge.append([group[i][0],group[i+1][1]])
            edge.append([group[i][1],N])
            #edge.append([group[i][1],group[i+1][1]])
        if i == n-2:
            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-1
    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)
for m in range(M):
    print(edge[m][0],edge[m][1])

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())

if N % 2 == 0:
  M = (N // 2 - 1) * 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: Wrong Answer

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: Wrong Answer

Solution code:
import sys

N = int(input())

if N % 2 == 0:
  M = (N // 2 - 1) * 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))
  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: Wrong Answer

Solution code:
import sys

N = int(input())

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

Submission status: Wrong Answer

Solution code:
N = int(input())

cnt = 0
ans = []
if N % 2 == 1:
    for i in range(1,N):
        cnt += 1
        ans.append("{0} {1}".format(i,N))
    N -= 1

if N == 2:
    print(cnt)
    for s in ans:
        print(s)
    exit(0)

ans.append("1 2")
ans.append("{0} {1}".format(N-1,N))
cnt += 2

if N == 4:
    cnt += 2
    print(cnt)
    print("1 3")
    print("2 4")
    for s in ans:
        print(s)
    exit(0)


for i in range(1,N-1):
    ans.append("{0} {1}".format(i,i+2))
    ans.append("{0} {1}".format(i,i+3))
    cnt += 2
    if i + 4 <= N:
        ans.append("{0} {1}".format(i,i+4))
        cnt += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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