import bisect def main(): import sys input = sys.stdin.read data = input().split() idx = 0 n = int(data[idx]) idx += 1 a = list(map(int, data[idx:idx+n])) idx += n x = list(map(int, data[idx:idx+n])) idx += n y = list(map(int, data[idx:idx+n])) idx += n dp = [0] * n dq = [] for i in range(n): j_max = bisect.bisect_right(x, a[i]) - 1 if j_max < 0: j_max = 0 best = float('inf') for j in range(max(0, j_max - 5), min(i + 1, j_max + 6)): cost = (abs(x[j] - a[i]) ** 3) + (y[j] ** 3) prev = dp[j-1] if j > 0 else 0 if prev + cost < best: best = prev + cost j_min = j_max + 1 for j in range(max(0, j_min - 5), min(i + 1, j_min + 6)): cost = (abs(x[j] - a[i]) ** 3) + (y[j] ** 3) prev = dp[j-1] if j > 0 else 0 if prev + cost < best: best = prev + cost dp[i] = best print(dp[-1]) if __name__ == '__main__': main()