qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()

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

    print('\n'.join(map(lambda a: '{} {}'.format(a[0], a[1]), ans)))


if __name__ == '__main__':
    main()


Fixed code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()

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

    print(len(ans))
    print('\n'.join(map(lambda a: '{} {}'.format(a[0], a[1]), ans)))


if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
ans = []
for i in range(1, n + 1):
    for j in range(1, n + 1):
        if i != j and i + j != n + 1:
            ans.append(sorted([i, j]))
ans.sort()
for i in range(len(ans)):
    if i % 2 == 0:
        print(*ans[i])
    

Fixed code:
n = int(input())
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([i,j])
if n % 2 == 1:
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i + j != n:
                ans.append([i,j])    
print(len(ans))
for i in ans:
    print(*i)
Buggy code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
node=[]
if n%2==0:
    for i in range(n):
        for j in range(i,n):
            if j==i or j==n-1-i:
                continue
            node.append((i+1,j+1))
else:
    for i in range(n):
        for j in range(i,n):
            if j==i or j==n-2-i:
                continue
            node.append((ix+1,j+1))
    
print(len(node))
for i in node:
    print(*i) 

Fixed code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
node=[]
if n%2==0:
    for i in range(n):
        for j in range(i,n):
            if j==i or j==n-1-i:
                continue
            node.append((i+1,j+1))
else:
    for i in range(n):
        for j in range(i,n):
            if j==i or j==n-2-i:
                continue
            node.append((i+1,j+1))
    
print(len(node))
for i in node:
    print(*i)
Buggy code:
N = int(input())
even = True if N % 2 == 0 else False
print(N*(N-1)//2-N//2)
for i in range(1, N):
  for j in range(i+1, N+1):
    if even and i + j != N+1 or not even and i + j == N+1:
      print(i, j)

Fixed code:
N = int(input())
even = True if N % 2 == 0 else False
print(N*(N-1)//2-N//2)
for i in range(1, N):
  for j in range(i+1, N+1):
    if even and i + j != N+1 or not even and i + j != N:
      print(i, j)
Buggy code:
N=int(input())
S=[]
for i in range(1,N):
 for j in range(i+1,N+1):
  S.append([i,j])
if N%2==1:
 for i in range(1,N//2+1):
  S.remove([i,N-i])
else:
 for i in range(1,N//2+1):
  S.remove([i,N+1-i])
for j in S:
 print(*j)


Fixed code:
N=int(input())
S=[]
ans=0
for i in range(1,N):
 for j in range(i+1,N+1):
  S.append([i,j])
  ans+=1
if N%2==1:
 for i in range(1,N//2+1):
  S.remove([i,N-i])
  ans-=1
else:
 for i in range(1,N//2+1):
  S.remove([i,N+1-i])
  ans-=1
print(ans)
for j in S:
 print(*j)
Buggy code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
print(m*(m-1)//2-m//2)

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

Fixed code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
print(n*(n-1)//2-n//2)

for i in range(n):
    a = n-1-i if n%2 == 0 else n-2-i
    for j in range(i+1,n):
        if j != a:
            print(i+1,j+1)
Buggy code:
n = int(input())
no_group = []
if n % 2 ==0:
  for  i in range(1,n//2+1):
    no_group.append([i,n-i+1])
else:
  for i in range(1,n//2+1):
    no_group.append([i,n-i])
  no_group.append([n])
  
sub_list = [[0 for i in range(n)] for i in range(n)]
for g in no_group:
  if len(g) == 2:
    sub_list[g[0]-1][g[1]-1] = 1
    sub_list[g[1]-1][g[0]-1] = 1

for i in range(n):
  for j in range(i,n):
    if i != j and sub_list[i][j] == 0:
      print(i+1,j+1)
    

Fixed code:
n = int(input())
no_group = []
if n % 2 ==0:
  for  i in range(1,n//2+1):
    no_group.append([i,n-i+1])
else:
  for i in range(1,n//2+1):
    no_group.append([i,n-i])
  no_group.append([n])
  
sub_list = [[0 for i in range(n)] for i in range(n)]
for g in no_group:
  if len(g) == 2:
    sub_list[g[0]-1][g[1]-1] = 1
    sub_list[g[1]-1][g[0]-1] = 1
ans_list = []
for i in range(n):
  for j in range(i,n):
    if i != j and sub_list[i][j] == 0:
      ans_list.append([i+1,j+1])
      
print(len(ans_list))
for ans in ans_list:
  print(*ans)
Buggy code:
N = int(input())
edges = []
for i in range(1, N // 2 + 1):
    j = N - i + 1
    for k in range(1, N+1):
        if k == i or k == j:
            continue
        if i < k:
            edges.append((i, k))
        if j < k:
            edges.append((j, k))
if N % 2 == 1:
    i = N // 2 + 1
    for k in range(i+1, N+1):
        edges.append((i, k))
print(len(edges))
for a, b in edges:
    print(a, b)

Fixed code:
N = int(input())
edges = []
for i in range(1, N // 2 + 1):
    j = N - i + 1 - N % 2
    for k in range(1, N+1):
        if k == i or k == j:
            continue
        if i < k:
            edges.append((i, k))
        if j < k:
            edges.append((j, k))
print(len(edges))
for a, b in edges:
    print(a, b)
Buggy code:
import sys
bbn=1000000007
	
#+++++

def mk_path(a_i, max_n, ret):
	#a_i = 1 ... max_n
	#7 => 7,(6,1),(5,2),(4,3)
	#8 => (8,1),(7,2),(6,3),(5,4)
	off=0 if max_n % 2 == 1 else 1
	
	for i in range(a_i+1, max_n+1):
		if i == max_n - a_i + off:
			continue
		else:
			ret.append((a_i, i))
			
	return 
	
def check_constraint(graph, n):
	cc=[0]*n
	for f,t in graph:
		cc[f-1] += t
		cc[t-1] += f
	
	pa(('max:',max(cc),', min:', min(cc) ))
	return
	
		
def main():
	n = int(input())
	ret=[]
	for i in range(1,n+1):
		mk_path(i,n,ret)
	
	#check_constraint(ret, n)
	for f,t in ret:
		pass
		print(f,t)

	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Fixed code:
import sys
bbn=1000000007
	
#+++++

def mk_path(a_i, max_n, ret):
	#a_i = 1 ... max_n
	#7 => 7,(6,1),(5,2),(4,3)
	#8 => (8,1),(7,2),(6,3),(5,4)
	off=0 if max_n % 2 == 1 else 1
	
	for i in range(a_i+1, max_n+1):
		if i == max_n - a_i + off:
			continue
		else:
			ret.append((a_i, i))
			
	return 
	
def check_constraint(graph, n):
	cc=[0]*n
	for f,t in graph:
		cc[f-1] += t
		cc[t-1] += f
	
	pa(('max:',max(cc),', min:', min(cc) ))
	return
	
		
def main():
	n = int(input())
	ret=[]
	for i in range(1,n+1):
		mk_path(i,n,ret)
	
	#check_constraint(ret, n)
	print(len(ret))
	for f,t in ret:
		pass
		print(f,t)

	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
Buggy 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)

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

pairs = [[i for i in range(1, n + 1)] for _ in range(n)]

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

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


Fixed code:
n = int(input())

pairs = [[i for i in range(1, n + 1)] for _ in range(n)]

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

print(len(ans))
for x, y in ans:
    print(x, y)
Buggy code:
n = int(input())

if n % 2 == 0:
    # 1 <-> n, 2 <-> n-1... is Pair
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j != n + 1:
                print(str(i) + " " + str(j))
else:
    # Each edge has (sum - N)
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j != n:
                print(str(i) + " " + str(j))


Fixed code:
n = int(input())

if n % 2 == 0:
    # 1 <-> n, 2 <-> n-1... is Pair
    print(int(n*(n-1)/2-n/2))
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j != n + 1:
                print(str(i) + " " + str(j))
else:
    # Each edge has (sum - N)
    print(int(n*(n-1)/2-(n-1)/2))
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j != n:
                print(str(i) + " " + str(j))
Buggy code:
N = int(input())

ret = []
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
        ret.append((i, j))
        
for r in ret :
    print(*r)

Fixed code:
N = int(input())

ret = []
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
        ret.append((i, j))

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

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

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

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

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

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

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

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

print (M)
for i in range(N):
    for j in range(i + 1, N):
        if ans_lst[i][j] == 1:
            print (i + 1, j + 1)
Buggy code:
N = int(input())
ans = []
if N % 2 == 0:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if j <= i or i + j == N + 1:
                continue
            ans.append((i, j))
else:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if j <= i or i + j == N:
                continue
            ans.append((i, j))

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


Fixed code:
N = int(input())
ans = []
if N % 2 == 0:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if j <= i or i + j == N + 1:
                continue
            ans.append((i, j))
else:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if j <= i or i + j == N:
                continue
            ans.append((i, j))

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

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

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

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

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

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


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


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

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

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

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


print(len(edges))
for edge in edges:
    print(' '.join(str(i) for i in edge))
Buggy 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)

Fixed code:
n = int(input())

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

print(m)
for (a, b) in ans:
    print(a, b)
Buggy 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() 


Fixed code:
import numpy as np

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

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

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


if __name__ == '__main__':
   main()
Buggy 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)

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

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

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

for i in range(1,n+1):
    for j in range(i+1,n+1):
        if a[i][j] == -1:
            continue
        else:
            print(i,j)
Buggy 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)

Fixed code:
n=int(input())
ans=[]
if n%2:
    for i in range(1,n):
        ans.append((i,n))
    for i in range(1,n):
        for j in range(i+1,n):
            if j!=n-i:
                ans.append((i,j))
else:
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if j!=n+1-i:
                ans.append((i,j))
print(len(ans))
for a in ans:
    print(*a)
Buggy 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)

Fixed code:
n=int(input())
a=[]
for i in range(1,n+1):
    for j in range(i,n+1-n%2):
        if j!=i!=n-j+1-n%2:
            a.append((i,j))
if n%2:
    a+=[(i,n)for i in range(1,n)]
print(len(a))
for t in a:
    print(*t)
Buggy 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)


Fixed code:

N = int(input())

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

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

print(int((N*(N-1)/2)-int(N/2)))
for i in range(N):
    for j in range(i+1,N):
        if matrix[i][j] == 1:
            print(i+1,j+1)
Buggy 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)))


Fixed 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)))
Buggy 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])

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