#include #include using namespace std; using namespace atcoder; using ll = long long; using vl = vector; using vvl = vector; using vvvl = vector; typedef pair P; typedef tuple PP; typedef tuple PPP; using vvvvl = vector; using vp = vector

; using vvp = vector; using vb = vector; using vvb = vector; #define lb(v, k) (lower_bound(all(v), (k)) - v.begin()) #define ub(v, k) (upper_bound(all(v), (k)) - v.begin()) #define eb emplace_back #define fi first #define se second #define pq(T) priority_queue #define pqr(T) priority_queue, greater> #define pcount(i) __builtin_popcount(i); #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) #define all(a) (a).begin(), (a).end() #define double long double #define yesno(i) if(i)cout<<"yes"<> x.at(hfuaig); \ } #define coutvece(x) \ for (ll hfuaig = 0; hfuaig < x.size(); hfuaig++) \ { \ cout << x.at(hfuaig) << endl; \ } #define coutvec(x) \ for (ll hfuaig = 0; hfuaig < x.size(); hfuaig++) \ { \ cout << x.at(hfuaig) << ' '; \ } template bool chmax(T &a, const T& b){ if(a < b){ a = b; return true; } return false; } template bool chmin(T &a, const T& b){ if(a > b){ a = b; return true; } return false; } const ll mod = 998244353; const ll Mod = 1000000007; const ll inf = 999999999999999999LL; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") ll gcd(ll A, ll B){ if(A % B == 0){ return B; } else{ return gcd(B, A % B); } } ll lcm(ll A, ll B){ return A * B / gcd(A, B); } long long modpow(long long a, long long n, long long mo) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mo; a = a * a % mo; n >>= 1; } return res; } //円の位置関係 bool isd(double a, double b, double c){ if(c > (a + b) * (a + b)){ return false; } if(c == (a + b) * (a + b)){ return true; } if(abs(a - b) * abs(a - b) < c && c < (a + b) * (a + b)){ return true; } if(c == abs(a - b) * abs(a - b)){ return true; } if(c < abs(a - b) * abs(a - b)){ return false; } return true; } const int MAX = 500000; const int MOD = mod; ll fact[MAX], inv_fact[MAX], inv[MAX]; void init() { // 初期値設定と1はじまりインデックスに直す fact[0] = 1; fact[1] = 1; inv[0] = 1; inv[1] = 1; inv_fact[0] = 1; inv_fact[1] = 1; // メモの計算 repi(i, 2, MAX){ // 階乗 fact[i] = fact[i - 1] * i % MOD; // 逆元 inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; // 逆元の階乗 inv_fact[i] = inv_fact[i - 1] * inv[i] % MOD; } } ll nck(int n, int k) { ll x = fact[n]; // n!の計算 ll y = inv_fact[n-k]; // (n-k)!の計算 ll z = inv_fact[k]; // k!の計算 if (n < k) return 0; // 例外処理 if (n < 0 || k < 0) return 0; // 例外処理 return x * ((y * z) % MOD) % MOD; //二項係数の計算 } struct Edge { long long to; long long cost; }; struct graph{ vvp G; vl dis; vl prev; vl dijkstra(ll i){ ll N = G.size(); dis.assign(N, inf); prev.assign(N, -1); priority_queue, greater

> pq; // 「仮の最短距離, 頂点」が小さい順に並ぶ dis[i] = 0; pq.emplace(dis[i], i); while (!pq.empty()) { P p = pq.top(); pq.pop(); ll v = p.second; if (dis[v] < p.first) { // 最短距離で無ければ無視 continue; } for (auto &e : G[v]) { if (dis[e.fi] > dis[v] + e.se) { // 最短距離候補なら priority_queue に追加 dis[e.fi] = dis[v] + e.se; prev[e.fi] = v; pq.emplace(dis[e.fi], e.fi); } } } return dis; } vl get_path(ll t){ vl path; for (ll cur = t; cur != -1; cur = prev[cur]) { path.push_back(cur); } reverse(path.begin(), path.end()); // 逆順なのでひっくり返す return path; } }; void beg(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(20); init(); srand((unsigned int)time(NULL)); } struct BIT { private: vector bit; ll N; public: BIT(ll size) { N = size; bit.resize(N + 1, 0); } // 一点更新です void add(ll a, ll w) { for (int x = a; x <= N; x += x & -x) bit[x] += w; } // 1~Nまでの和を求める。 ll sum(ll a) { ll ret = 0; for (ll x = a; x > 0; x -= x & -x) ret += bit[x]; return ret; } }; //転倒数ライブラリ ll numfalls(vl &A){ ll ans = 0; ll N = A.size(); BIT b(N); rep(i, N){ ans += i - b.sum(A.at(i)); b.add(A.at(i), 1); } return ans; } //#define _GLIBCXX_DEBUG #define mint998 modint998244353 #define mint107 modint1000000007 //約数列挙 vector div(long long n) { vector ret; set re; ll N = sqrt(n) + 1; for (long long i = 1; i <= N; i++) { if (n % i == 0) { re.insert(n / i); re.insert(i); } } for(auto value :re){ ret.push_back(value); } return ret; } ll digit_sum(ll X){ ll ans = 0; while(X > 0){ ans += X%10; X/=10; } return ans; } void xypress(vl &A){ vl B = A; sort(all(B)); B.erase(unique(B.begin(), B.end()), B.end()); vector res(A.size()); for (int i = 0; i < A.size(); ++i) { res[i] = lower_bound(B.begin(), B.end(), A[i]) - B.begin(); } A = res; } //素数列挙 std::vector prime( const ll N ) { std::vector is_prime( N + 1 ); for( ll i = 0; i <= N; i++ ) { is_prime[ i ] = true; } std::vector P; for( ll i = 2; i <= N; i++ ) { if( is_prime[ i ] ) { for( ll j = 2 * i; j <= N; j += i ) { is_prime[ j ] = false; } P.emplace_back( i ); } } return P; } //mod m での逆元 long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } //mod 998244353での割り算 ll inve(ll a, ll b){ a %= mod; return (a * modinv(b, mod) % mod); } vl vecsum(vl x){ vl s = {0}; rep(i, x.size()){ s.push_back(s.back() + x.at(i)); } return s; } signed main() { beg(); ll N; cin >> N; vl A(N); cinvec(A); map S, now; rep(i, N){ S[A.at(i)]++; S[A.at(i)] += S[A.at(i) - 1]; } ll ans = 0; for(auto x : S){ ans += x.se; } ans -= N; cout << ans << endl; }