#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int n;   long long a[200200];   long long mn = 21000000000;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       mn = min(mn, a[i]);     }     int id;     for (int i = n - 1; i >= 0; i--) {       if (a[i] == mn) {         id = i;         break;       }     }     for (int i = 0; i < n; i++) {       ans += mn;       a[i] -= mn;     }     long long s = 0, c = -1;     for (int i = (id + 1) % n; i != id; i = (i + 1) % n) {       if (a[i] == 0) {         c = max(c, s);         s = 0LL;         a[i]--;       } else {         s++;       }     }     c = max(c, s);     cout << ans + c << endl;     return 0;   }   