Buggy python submission (verdict: Runtime Error):
m = [i+1 for i in range(int(raw_input()))]
n = int(raw_input())
for i in range(n):
	x,y = map(int, raw_input().split())
	if m.index(x) > m.index(y):
		r = m.pop(m.index(x))
		m.insert(m.index(y),r)
for i in range(n):
	print m[i]

Fixed submission:
def solve(a):
	for i in M-set(a):
		if any(x == i and y not in a for x,y in xy): continue
		r = solve([i]+a)
		if r: return r
	return a
m = input()
M = set(range(1,m+1))
xy = [map(int,raw_input().split()) for i in range(input())]
for i in solve([]): print i

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
m = input()
exp = "True"
for i in range(input()):
	x,y = map(int,raw_input().split())
	exp += " and N[" + str(x-1) + "] < N[" + str(y-1) + "]"
for N in itertools.permutations(range(m),m):
	if eval(exp):
		ans = sorted([[N[i],i+1] for i in range(m)])
		for n,i in ans:
			print i
		break

Fixed submission:
def solve(a):
	for i in M-set(a):
		if any(x == i and y not in a for x,y in xy): continue
		r = solve([i]+a)
		if r: return r
	return a
m = input()
M = set(range(1,m+1))
xy = [map(int,raw_input().split()) for i in range(input())]
for i in solve([]): print i

Buggy python submission (verdict: Time Limit Exceeded):
m = input()
S = [[1]*m for i in range(m)]
for i in range(input()):
	x,y = map(int,raw_input().split())
	S[y-1][x-1] = 0
	for j in range(m):
		if S[x-1][j] == 0: S[y-1][j] = 0
		if S[j][y-1] == 0: S[j][x-1] = 0
R = [sum(S[i]) for i in range(m)]
C = [sum([S[j][i] for j in range(m)]) for i in range(m)]
while sum(R) + sum(C) > m*(m+1):
	for r in range(m):
		if R.count(R[r]) == 1: continue
		for c in range(m):
			if S[r][c] == 0 and C.count(C[c]) == 1: continue
			if r != c and  R[r] + C[r] > m+1 and R[c] + C[c] > m+1:
				S[r][c] = 0
				R[r] -= 1
				C[c] -= 1
				break
rank = sorted([[C[i],i+1] for i in range(m)])
for r,i in rank: print i

Fixed submission:
def solve(a):
	for i in M-set(a):
		if any(x == i and y not in a for x,y in xy): continue
		r = solve([i]+a)
		if r: return r
	return a
m = input()
M = set(range(1,m+1))
xy = [map(int,raw_input().split()) for i in range(input())]
for i in solve([]): print i

Buggy python submission (verdict: Time Limit Exceeded):
m = input()
S = [[1]*m for i in range(m)]
for i in range(input()):
	x,y = map(int,raw_input().split())
	S[y-1][x-1] = 0
	for j in range(m):
		if S[x-1][j] == 0: S[y-1][j] = 0
		if S[j][y-1] == 0: S[j][x-1] = 0
R = [sum(S[i]) for i in range(m)]
C = [sum([S[j][i] for j in range(m)]) for i in range(m)]
while sum(R) + sum(C) > m*(m+1):
	for r in range(m):
		if R.count(R[r]) == 1: continue
		for c in range(m):
			if S[r][c] == 0: continue
			if r != c and  R[r] + C[r] > m+1 and R[c] + C[c] > m+1:
				S[r][c] = 0
				R[r] -= 1
				C[c] -= 1
				break
rank = sorted([[C[i],i+1] for i in range(m)])
for r,i in rank: print i

Fixed submission:
def solve(a):
	for i in M-set(a):
		if any(x == i and y not in a for x,y in xy): continue
		r = solve([i]+a)
		if r: return r
	return a
m = input()
M = set(range(1,m+1))
xy = [map(int,raw_input().split()) for i in range(input())]
for i in solve([]): print i

Buggy python submission (verdict: Time Limit Exceeded):
m = input()
S = [[1]*m for i in range(m)]
for i in range(input()):
	x,y = map(int,raw_input().split())
	S[y-1][x-1] = 0
	for j in range(m):
		if S[x-1][j] == 0: S[y-1][j] = 0
		if S[j][y-1] == 0: S[j][x-1] = 0
R = [sum(S[i]) for i in range(m)]
C = [sum([S[j][i] for j in range(m)]) for i in range(m)]
while sum(R) + sum(C) > m*(m+1):
	for r in range(m):
		for c in range(m):
			if S[r][c] == 0: continue
			if r != c and  R[r] + C[r] > m+1 and R[c] + C[c] > m+1:
				S[r][c] = 0
				R[r] -= 1
				C[c] -= 1
rank = sorted([[C[i],i+1] for i in range(m)])
for r,i in rank: print i

Fixed submission:
def solve(a):
	for i in M-set(a):
		if any(x == i and y not in a for x,y in xy): continue
		r = solve([i]+a)
		if r: return r
	return a
m = input()
M = set(range(1,m+1))
xy = [map(int,raw_input().split()) for i in range(input())]
for i in solve([]): print i

Buggy python submission (verdict: Time Limit Exceeded):
m = input()
S = [[1]*m for i in range(m)]
for i in range(input()):
	x,y = map(int,raw_input().split())
	S[y-1][x-1] = 0
	for j in range(m):
		if S[x-1][j] == 0: S[y-1][j] = 0
		if S[j][y-1] == 0: S[j][x-1] = 0
R = [sum(S[i]) for i in range(m)]
C = [sum([S[j][i] for j in range(m)]) for i in range(m)]
while sum(R) + sum(C) > m*(m+1):
	for r in range(m):
		for c in range(m):
			if r != c and S[r][c] == 1 and  R[r] + C[r] > m+1 and R[c] + C[c] > m+1:
				S[r][c] = 0
				R[r] -= 1
				C[c] -= 1
rank = sorted([[C[i],i+1] for i in range(m)])
for r,i in rank: print i

Fixed submission:
def solve(a):
	for i in M-set(a):
		if any(x == i and y not in a for x,y in xy): continue
		r = solve([i]+a)
		if r: return r
	return a
m = input()
M = set(range(1,m+1))
xy = [map(int,raw_input().split()) for i in range(input())]
for i in solve([]): print i

Buggy python submission (verdict: Time Limit Exceeded):
def solve(a,M):
	for x,y in xy:
		if x in a and y in a and a.index(x) > a.index(y):
			break
	else:
		if len(a) == m: return a
		return max([solve([M[i]] + a,M[:i]+M[i+1:]) for i in range(len(M))])

m = input()
xy = [map(int,raw_input().split()) for i in range(input())]
ans = solve([],range(1,m+1))
for i in ans: print i

Fixed submission:
def solve(a):
	for i in M-set(a):
		if any(x == i and y not in a for x,y in xy): continue
		r = solve([i]+a)
		if r: return r
	return a
m = input()
M = set(range(1,m+1))
xy = [map(int,raw_input().split()) for i in range(input())]
for i in solve([]): print i

Buggy python submission (verdict: Time Limit Exceeded):
def solve(a,M):
	for x,y in xy:
		if x in a and (y not in a or a.index(x) > a.index(y)):
			break
	else:
		if len(a) == m: return a
		return max([solve([M[i]] + a,M[:i]+M[i+1:]) for i in range(len(M))])

m = input()
xy = [map(int,raw_input().split()) for i in range(input())]
M = range(m)
ans = solve([],range(1,m+1))
for i in ans: print i

Fixed submission:
def solve(a):
	for i in M-set(a):
		if any(x == i and y not in a for x,y in xy): continue
		r = solve([i]+a)
		if r: return r
	return a
m = input()
M = set(range(1,m+1))
xy = [map(int,raw_input().split()) for i in range(input())]
for i in solve([]): print i