1 #include <bits/stdc++.h> 2 #define ll long long 3 4 using namespace std; 5 6 int main() { 7 std::ios_base::sync_with_stdio(false); 8 cin.tie(0); 9 cout.tie(0); 10 int n; 11 cin >> n; 12 int cost[n + 1]; 13 for (int i = 1; i <= n; ++i) { 14 cin >> cost[i]; 15 } 16 int dp[n + 1] = {}; 17 dp[1] = 0; 18 dp[2] = abs(cost[2] - cost[1]); 19 20 for (int i = 3; i <= n; ++i) { 21 dp[i] = min(dp[i - 1] + abs(cost[i] - cost[i - 1]), dp[i - 2] + 3 * abs(cost[i] - cost[i - 2])); 22 } 23 24 cout << dp[n]; 25 return 0; 26 } 27 28 29 30