Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) + [i] for i in range(n)]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))

ans = 0
used = []
now = 0
i = 0
j = 0

if abs(l_sort[0][0]) >= abs(r_sort[0][1]):
	while len(used) != n:
		while l_sort[i][2] in used:
			i += 1
		if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
			ans += abs(now - l_sort[i][0])
			now = l_sort[i][0]
		used.append(l_sort[i][2])
		i += 1
		if len(used) == n:
			break
		while r_sort[j][2] in used:
			j += 1
		if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
			ans += abs(now - r_sort[j][1])
			now = r_sort[j][1]
		used.append(r_sort[j][2])
		j += 1

	print(ans + abs(now))

else:
	while len(used) != n:
		while r_sort[j][2] in used:
			j += 1
		if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
			ans += abs(now - r_sort[j][1])
			now = r_sort[j][1]
		used.append(r_sort[j][2])
		j += 1
		if len(used) == n:
			break
		while l_sort[i][2] in used:
			i += 1
		if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
			ans += abs(now - l_sort[i][0])
			now = l_sort[i][0]
		used.append(l_sort[i][2])
		i += 1
		#print(now)

	print(ans + abs(now))

Fixed submission:
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) for i in range(n)] + [[0, 0]]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))

ans = 0
sigma = 0

for i in range(n // 2 + 1):
	sigma += 2 * (l_sort[i][0] - r_sort[i][1])
	if sigma > ans:
		ans = sigma

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) + [i] for i in range(n)]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))
#print(l_sort, r_sort)

ans = 0
used = set()
now = 0
i = 0
j = 0

if abs(l_sort[0][0]) >= abs(r_sort[0][1]):
	while used != set(range(n)):
		while l_sort[i][2] in used:
			i += 1
		if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
			ans += abs(now - l_sort[i][0])
			now = l_sort[i][0]
		used.add(l_sort[i][2])
		i += 1
		#print(now)
		if used == set(range(n)):
			break
		while r_sort[j][2] in used:
			j += 1
		if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
			ans += abs(now - r_sort[j][1])
			now = r_sort[j][1]
		used.add(r_sort[j][2])
		j += 1
		#print(now)

	print(ans + abs(now))

else:
	while used != set(range(n)):
		while r_sort[j][2] in used:
			j += 1
		if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
			ans += abs(now - r_sort[j][1])
			now = r_sort[j][1]
		used.add(r_sort[j][2])
		j += 1
		#print(now)
		if used == set(range(n)):
			break
		while l_sort[i][2] in used:
			i += 1
		if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
			ans += abs(now - l_sort[i][0])
			now = l_sort[i][0]
		used.add(l_sort[i][2])
		i += 1
		#print(now)

	print(ans + abs(now))

Fixed submission:
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) for i in range(n)] + [[0, 0]]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))

ans = 0
sigma = 0

for i in range(n // 2 + 1):
	sigma += 2 * (l_sort[i][0] - r_sort[i][1])
	if sigma > ans:
		ans = sigma

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) + [i] for i in range(n)]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))
#print(l_sort, r_sort)

ans = 0
used = set()
now = 0
i = 0
j = 0

while used != set(range(n)):
	while l_sort[i][2] in used:
		i += 1
	if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
		ans += abs(now - l_sort[i][0])
		now = l_sort[i][0]
	used.add(l_sort[i][2])
	i += 1
	#print(now)
	if used == set(range(n)):
		break
	while r_sort[j][2] in used:
		j += 1
	if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
		ans += abs(now - r_sort[j][1])
		now = r_sort[j][1]
	used.add(r_sort[j][2])
	j += 1
	#print(now)

ans1 = ans + abs(now)

ans = 0
used = set()
now = 0
i = 0
j = 0

while used != set(range(n)):
	while r_sort[j][2] in used:
		j += 1
	if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
		ans += abs(now - r_sort[j][1])
		now = r_sort[j][1]
	used.add(r_sort[j][2])
	j += 1
	#print(now)
	if used == set(range(n)):
		break
	while l_sort[i][2] in used:
		i += 1
	if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
		ans += abs(now - l_sort[i][0])
		now = l_sort[i][0]
	used.add(l_sort[i][2])
	i += 1
	#print(now)

ans2 = ans + abs(now)

#print(ans1, ans2)
print(max(ans1, ans2))

Fixed submission:
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) for i in range(n)] + [[0, 0]]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))

ans = 0
sigma = 0

for i in range(n // 2 + 1):
	sigma += 2 * (l_sort[i][0] - r_sort[i][1])
	if sigma > ans:
		ans = sigma

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) + [i] for i in range(n)]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))
#print(l_sort, r_sort)

ans = 0
used = set()
now = 0
i = 0
j = 0

while used != set(range(n)):
	while l_sort[i][2] in used:
		i += 1
	if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
		ans += abs(now - l_sort[i][0])
		now = l_sort[i][0]
	used.add(l_sort[i][2])
	i += 1
	#print(now)
	if used == set(range(n)):
		break
	while r_sort[j][2] in used:
		j += 1
	if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
		ans += abs(now - r_sort[j][1])
		now = r_sort[j][1]
	used.add(r_sort[j][2])
	j += 1
	#print(now)

ans1 = ans + abs(now)

ans = 0
used = set()
now = 0
i = 0
j = 0

while used != set(range(n)):
	while r_sort[j][2] in used:
		j += 1
	if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
		ans += abs(now - r_sort[j][1])
		now = r_sort[j][1]
	used.add(r_sort[j][2])
	j += 1
	#print(now)
	if used == set(range(n)):
		break
	while l_sort[i][2] in used:
		i += 1
	if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
		ans += abs(now - l_sort[i][0])
		now = l_sort[i][0]
	used.add(l_sort[i][2])
	i += 1
	#print(now)

ans2 = ans + abs(now)

#print(ans1, ans2)
print(max(ans1, ans2))

Fixed submission:
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) for i in range(n)] + [[0, 0]]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))

ans = 0
sigma = 0

for i in range(n // 2 + 1):
	sigma += 2 * (l_sort[i][0] - r_sort[i][1])
	if sigma > ans:
		ans = sigma

print(ans)