import bisect n = int(input()) a = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) INF = float('inf') dp = [INF] * n current_j = 0 for i in range(n): min_cost = INF best_j = current_j # Check from current_j to i for j in range(current_j, i + 1): prev = dp[j-1] if j > 0 else 0 cost = prev + abs(x[j] - a[i])**3 + y[j]**3 if cost < min_cost: min_cost = cost best_j = j # Check from current_j-1 down to 0, but break early if possible for j in range(current_j - 1, -1, -1): if j > i: continue prev = dp[j-1] if j > 0 else 0 cost = prev + abs(x[j] - a[i])**3 + y[j]**3 if cost < min_cost: min_cost = cost best_j = j else: break # No improvement, break early dp[i] = min_cost current_j = best_j print(dp[-1])