#include using namespace std; #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; templateinline bool chmax(T& a,T b){if(ainline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} int main(){ int n; cin>>n; vector a(n); rep(i,0,n)cin>>a[i]; int res=n*(n+1)/2; rep(i,0,n)if(a[i]==n)res-=(i+1)*2; cout<