#include using namespace std; #define pb push_back #define ff first #define ss second #define maxn 100005 #define mk make_pair #define PI 3.14159265 #define INF 1000000000 #define mod 1000000007 #define pii pair #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define uniq(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end()) #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I <= (B); ++I) #define REPD(I, N) for (int I = N; I >=0; I--) #define _ ios::sync_with_stdio(false);cin.tie(0); #define trace1(x) cout << #x << ": " << x << endl; #define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl; #define trace4(x, y, z, w) cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << " | " << #w <<": "<< w << endl; #define trace5(x, y, z, w, t) cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << " | " << #w <<": "<< w << " | " << #t << ": " << t < a) { // Return the length of the longest possible sequence of moves. LL ans = 0; for(int i = 0;i < a.size();i++){ if(a[i] == 1) ans += 1; else ans += (a[i] + work(a[i])); } return ans; } int main() { int n; cin >> n; vector a(n); for(int a_i = 0; a_i < n; a_i++){ cin >> a[a_i]; } LL result = longestSequence(a); cout << result << endl; return 0; }