import random
import decimal
# 5
# 2 1 4 3 5
# 2 2 2 3 4
n = 5
xs = [2,1,4,3,5]
vs = [2,2,2,3,4]

min_sum = sum(xs)
summation = 0

for i in range(n):
    for j in range(n-1):
        if vs[j] != vs[i]:
            t_min = (xs[i]-xs[j])/(vs[j]-vs[i])
        else:
            t_min = 0
        summation += abs((xs[j]-xs[i]) + (t_min*(vs[j]-vs[i])))
        print(i,j,summation, min_sum)
    if min_sum > summation:
        min_sum = summation
    else:
        pass
    
print("min_sum = ", min_sum)