Buggy python submission (verdict: Time Limit Exceeded):
import decimal
from itertools import permutations

decimal.getcontext().prec = 16

cache = {}


def distance(a, b):
  if b < a:
    a, b = b, a
  key = a + b
  if key in cache:
    return cache[key]
  else:
    v = decimal.Decimal(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2)).sqrt()
    cache[key] = v
    return v


N = int(input())

P = [None] * N
for i in range(N):
  P[i] = tuple(map(int, input().split()))

total = decimal.Decimal(0)
count = 0
for points in permutations(P, len(P)):
  it = iter(points)
  last = next(it)
  for p in it:
    total += distance(p, last)
    last = p
  count += 1

print(total / count)


Fixed submission:
import decimal
import math
from itertools import permutations

decimal.getcontext().prec = 16

cache = {}


def distance(a, b):
  return math.sqrt(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2))


N = int(input())

P = [None] * N
for i in range(N):
  P[i] = tuple(map(int, input().split()))

total = 0
count = 0
for points in permutations(P, len(P)):
  it = iter(points)
  last = next(it)
  for p in it:
    total += distance(p, last)
    last = p
  count += 1

print(total / count)

Buggy python submission (verdict: Time Limit Exceeded):
import decimal
from itertools import permutations


decimal.getcontext().prec = 16

def distance(a, b):
  return decimal.Decimal(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2)).sqrt()


N = int(input())

P = [None] * N
for i in range(N):
  P[i] = tuple(map(int, input().split()))

total = decimal.Decimal(0)
count = 0
for points in permutations(P, len(P)):
  it = iter(points)
  last = next(it)
  for p in it:
    total += distance(p, last)
    last = p
  count += 1

print(total / count)


Fixed submission:
import decimal
import math
from itertools import permutations

decimal.getcontext().prec = 16

cache = {}


def distance(a, b):
  return math.sqrt(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2))


N = int(input())

P = [None] * N
for i in range(N):
  P[i] = tuple(map(int, input().split()))

total = 0
count = 0
for points in permutations(P, len(P)):
  it = iter(points)
  last = next(it)
  for p in it:
    total += distance(p, last)
    last = p
  count += 1

print(total / count)

Buggy python submission (verdict: Time Limit Exceeded):
import decimal
from itertools import permutations


def distance(a, b):
  return decimal.Decimal(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2)).sqrt()


N = int(input())

P = [None] * N
for i in range(N):
  P[i] = tuple(map(int, input().split()))

total = decimal.Decimal(0)
count = 0
for points in permutations(P, len(P)):
  it = iter(points)
  last = next(it)
  for p in it:
    total += distance(p, last)
    last = p
  count += 1

print(total / count)


Fixed submission:
import decimal
import math
from itertools import permutations

decimal.getcontext().prec = 16

cache = {}


def distance(a, b):
  return math.sqrt(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2))


N = int(input())

P = [None] * N
for i in range(N):
  P[i] = tuple(map(int, input().split()))

total = 0
count = 0
for points in permutations(P, len(P)):
  it = iter(points)
  last = next(it)
  for p in it:
    total += distance(p, last)
    last = p
  count += 1

print(total / count)