#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, x, y) for (int i = x; i < y; i++)
int main()
{
    ll N;
    cin >> N;
    ll ans = 0;
    map<int, int> numbers;
    rep(i, 0, N)
    {
        int input;
        cin >> input;
        if (numbers.find(input) == numbers.end())
        {
            numbers[input] = 1;
            ans += i;
        }
        else
        {
            numbers[input]++;
            ans += i + 1 - numbers[input];
        }
    }
    cout << ans << endl;
}

            #include <bits/stdc++.h>
            #include <ext/pb_ds/assoc_container.hpp>
            #include <ext/pb_ds/tree_policy.hpp>
            using namespace std;
            using namespace __gnu_pbds;
            #define rep(i, a , b) for (ll i =a ; i < b ; i++)
            #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            #define endl "\n"
            #define pb push_back
            #define F first
            #define S second
            #define print(a)       for(auto x : a) cout << x << " "; cout << endl
            #define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
            #define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
            typedef long long  int ll;
            const ll N =  1e6+5;
            const ll mod = 998244353;
            const ll inf = 1e18;
            ll   n  , k  , m , q  , w , u , x , v , z  , a , b, c;

    ll pow_mod_m(ll a , ll n)
    {
        if(!n)
            return 1;
        ll pt =  pow_mod_m(a,n/2);
        pt *= pt , pt %= mod;
        if(n&1)
            pt *= a  ,pt %= mod;
        return pt;
    }

    ll ways(ll x)
    {
        return min( max(x-1,0ll) , max(2*n+1 - x,0ll) );
    }

    int main()
    {
         IOS;
         int ts =1;
         ///cin >> ts ;
         while(ts--)
         {
            cin >> n >> k;
            ll ans = 0;
            rep(i,2,2*n+1)
            {
                ans += ways(i-k)*ways(i);
            }
            cout << ans << endl;
         }
    }


#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}
long long gcd_vec(vector<long long> const &A) { // N個の要素に対する最大公約数
    int size = (int)A.size();
    long long ret = A[0];
    for (int i = 1; i < size; i++) {
        ret = gcd(ret, A[i]);
    }
    return ret;
}
long long lcm2(long long a, long long b) {
    long long d = gcd(a, b);
    return a / d * b;
}
long long lcm(const vector<long long> &vec) {
    long long l = vec[0];
    for (int i = 0; i < vec.size() - 1; i++) {
        l = lcm2(l, vec[i + 1]);
    }
    return l;
}
long long int mypow(long long int a,long long int b){
    long long int i=0,ans;
    for(i=0;i<b;i++)
    {
        if(i==0)
        {
            ans=a;
        }
        else
        {
            ans*=a;
        }
    }
    return ans;
}
struct UnionFind{
    int n;
    vector<int> par; // 親の番号
    vector<int> siz; // サイズを表している。

    // 初期化する。parは自身を指す（iotaは 0 ~ nまでの数字を順に入れていく）
    // size(siz) は最初はすべて１
    UnionFind(int n) : n(n){
        par.resize(n);
        iota(par.begin(),par.end(),0);
        siz.assign(n,1);
    }

    // 頂点の親を求める。
    // 再帰関数を使っており、経路圧縮もしている。
    int root(int x){
        // ここは親の処理。
        if (par[x] == x){
            return x;
        }

        //経路圧縮をしながら値を返す。
        // par[x] = root(par[x]);
        // return par[x];
        // と同じ意味。
        return par[x] = root(par[x]);
    }

    // unite :: a と bを同じグループに入れる。
    // もし初めから同じなら何もしない。
    void unite(int a,int b){
        int ra = root(a);
        int rb = root(b);

        if(ra == rb){
            return;
        }

        // サイズの大きい方にサイズの小さいほうを合成するので、swapしている。
        if (siz[ra] < siz[rb]){
            swap(ra,rb);
        }
        // サイズが大きい方に小さいのを合体
        // 小さいほうの親は大きい方の親になる。
        siz[ra] += siz[rb];
        par[rb] = ra;
    }

    //　同じグループかどうか判定するには、親が一緒かどうかをみたらよい
    bool same(int x,int y){
        return root(x) == root(y);
    }

    // 頂点が含まれるグループの頂点を求める。
    int get_size(int x){
        return siz[root(x)];
    }
};
    long long int facctorialMethod(int k){
    long long int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
#define PI 3.14159265359
int main()
{
	[[maybe_unused]]long long int i=0,j=0,k,n,m=0;
    set<long long int>st;
    [[maybe_unused]]double qw;
    string s,s1;
    cin >> s;
    for(i=0;i<9;i++)
    {
        if(s[i]=='Z' && s[i+1]=='O' && s[i+2]=='N' && s[i+3]=='e')
        {
            m++;
        }
    }
    cout << m;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define pb push_back
#include <iomanip>
#define mp make_pair
#define ll long long
#define vll vector <ll>
#define pll pair <ll,ll>
#define sll set <ll>
#define msll multiset <ll>
#define mll map <ll,ll>
#define mod 1000000007
ll prime[1000001];
using namespace std;
//// FOR SINGLE TO KNOW FOR PRIME
int Prime(int a)
{
    for(int i=2;i<=a/2;++i)
    {
        if(a%i==0)
        {
            return 0;
        }
    }
    return 1;
}
//// FOR PRIMES TILL A VALUE
void sieve()
{   for(int i=2;i<=1000000;i++)
    prime[i]=1;
    int maxn=1000000;
    for(int i=2;i*i<=maxn;i++)
    {
        if(prime[i]==1)
        {
            for(int j=i;j*j<=maxn;j+=i)
            {
                prime[j]=0;
            }
        }
    }
}
void fibo(ll a[],ll n)
{
    ll x=0;
    ll y=1;
    a[0]=0;
    a[1]=1;
    for(ll i=2;i<n;++i)
    {
        a[i]=(x+y)%10;
        x=y;
        y=a[i];
    }
}
/*ll f(ll w[],ll a[][2],ll i,ll y)
{
    for(ll j=0;j<y;++j)
    {
        if(a[i][2]<=w[j])
        {
            cout<<a[i][2];
            return w[j];
        }
    }
    return w[y-1];
}*/
/*ll s(ll v[],ll a[][2],ll i,ll x)
{
    for(ll j=0;j<x;++j)
    {
        if(a[i][1]>=v[j])
        {
            cout<<" "<<a[i][1]<<" ";
            return v[j];
        }
    }
    return v[0];
}*/
bool binarySearch(vector <ll> arr, int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return 1;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return 0;
}

//////// FOR FAST POWER
/*ll poop[5000];
memset(poop,-1,sizeof(poop));
ll po(ll n,ll x)
{
    if(poop[x]!=0)
    {
        return poop[x];
    }
    if(x==1)
    {
        return poop[x]=n%mod;
    }
    if(x%2)
    {
        return poop[x]=(n*((po(n,x/2))%mod)*((po(n,x/2))%mod))%mod;
    }
    else
    {
        return poop[x]=(((po(n,x/2))%mod)*((po(n,x/2))%mod))%mod;
    }
}*/
/*ll v[3001],cont[3001],f[3001],n,c,k,x,y,z,t,l,v;
//memset(f,0,sizeof(f));
ll fact(ll a)
{
    if(a==0||a==1)
    {
        return 1;
    }
    if(f[a]!=0)
    {
        return f[a];
    }
    return f[a]=a*fact(a-1);
}*/
/*ll solve(ll k,ll t,ll i)
{
    if(i<0||k==0)
    {
        return t;
    }
    if((v[i]<=k)&&(cont[i]>2))
    {
        return min(solve(k,t,i),solve(k-val[i],t-fact(count[i])/(6*fact(count[i-3]))))
    }
    else
    {
        return solve()
    }
}*/
/*ll s[200001],x,a[200001];
void bs(ll low,ll high)
{
    ll mid=(low+high)/2;
    if(s[mid]==x)
    {
        cout<<mid+1<<" "<<a[mid];
    }
    else if((x<s[mid])&&(x>=s[mid-1]))
    {
        cout<<mid<<" "<<x-s[mid-1];
    }
    else if(x>s[mid])
    {
        return bs(mid+1,high);
    }
    else
    {
        return bs(low,mid-1);
    }
}*/
/*vector<ll>v[100001],vis(100001,0),d(100001,0);
void dfs(ll n)
{
    vis[n]=1;
    for(auto x:v[n])
    {
        if(!vis[x])
        {
            d[x]=d[n]+1;
            dfs(x);
        }
    }
}*/
ll vis[1000][1000],dis[1000][1000],di[1000][1000],dx[]={0,1,1,1,0,-1,-1,-1},dy[]={-1,-1,0,1,1,1,0,-1},n,m;
char s[1000][1000];
bool check(ll a,ll b)
{
    if(a>=0&&b>=0&&a<n&&b<m)
    {
        return true;
    }
    return false;
}
int main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout)
    ll t,k,b,c,ans,r,e,a,f,g,u,d;
    //cin>>t;
    //while(t--)
    {
        string x;
        cin>>x;
        n=x.size();
        k=0;
        for(ll i=0;i<n-3;++i)
        {
            if(x[i]=='Z'&&x[i+1]=='O'&&x[i+2]=='N'&&x[i+3]=='e')
            {
                i+=3;
                k++;
            }
        }
        cout<<k;
    }
    return 0;
}


/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - White and Black Balls
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000000;
const int MAX_M = 1000000;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;

/* global variables */

int fs[MAX_N + MAX_M + 1], invfs[MAX_N + MAX_M + 1];

/* subroutines */

int powmod(int a, int n) {  // a^n % MOD
  int pm = 1;
  while (n > 0) {
    if (n & 1) pm = (ll)pm * a % MOD;
    a = (ll)a * a % MOD;
    n >>= 1;
  }
  return pm;
}

inline int nck(int n, int k) {  // nCk % MOD
  if (n < k || k < 0) return 0;
  return (ll)fs[n] * invfs[n - k] % MOD * invfs[k] % MOD;
}

void prepare_fracs(int n) {
  fs[0] = invfs[0] = 1;
  for (int i = 1; i <= n; i++) {
    fs[i] = (ll)fs[i - 1] * i % MOD;
    invfs[i] = powmod(fs[i], MOD - 2);
  }
}

/* main */

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);

  if (n > m + k) { puts("0"); return 0; }

  prepare_fracs(n + m);

  int a = (nck(n + m, n) + MOD - nck(n + m, m + k + 1)) % MOD;
  printf("%d\n", a);
  return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define per(i,a,b) for(int i = (a); i > (b); i--)
#define repl(i,a,b) for(ll i = (a); i < (b); i++)
#define perl(i,a,b) for(ll i = (a); i > (b); i--)

const ll MOD = 1000000007;
int _max = 2000000;
vector<ll> fact(_max+1), factinv(_max+1);

//Fast modular exponentiation
long long fast_exp(long long base, long long exp, long long mod) {
    long long res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       exp/=2;
    }
    return res%mod;
}
int n, m;
void precompute(){
        _max = n+m;
        fact[0] = 1;
        for(int i = 1; i <= _max; i++){
                fact[i] = (fact[i-1]*i)%MOD;
        }
        for(int i = 0; i <= _max; i++){
                factinv[i] = fast_exp(fact[i], MOD-2, MOD);
        }
}

void solve(){
    int k;
    cin >> n >> m >> k;
    precompute();
    if(n-k-1 >= m){
            cout << 0 << "\n";
    }
    else{
            ll total = (((fact[n+m]*factinv[n])%MOD)*factinv[m])%MOD;
            //cout << total << "\n";
            if(n == k){
                    cout << total << "\n";
            }
            else{
                    ll bad = (((fact[n+m]*factinv[n-k-1])%MOD)*factinv[m+k+1])%MOD;
                    ll ans = total - bad;
                    if(ans < 0) ans += MOD;
                    cout << ans << "\n";
            }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    precompute();
    //ll t;
    //cin >> t;
    t = 1;
    while(t--)solve();
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
template<class T> using indexed_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=2e5+7;
const int mod=1e9+7;
const int INF=1e18+7;
const double EPS=1e-12;
const int dx[]={-1,1,0,0}; // UDLR
const int dy[]={0,0,-1,1}; // UDLR
inline int maximum(int a,int b) {int c=a>b?a:b; return c;}
inline int minimum(int a,int b) {int c=a>b?b:a; return c;}

int r,c; bool visited [550][550]; vector<vector<int>> d(550,vector<int>(550,INF));
vector<vector<int>> A(550,vector<int>(550)),B(550,vector<int>(550));

int32_t main(){
    cin.tie(nullptr)->sync_with_stdio(false);

     cin>>r>>c; priority_queue<tuple<int,int,int>> q;
     for(int i=1;i<=r;i++){
        for(int j=1;j<=c-1;j++) cin>>A[i][j];
     }
     for(int i=1;i<=r-1;i++){
        for(int j=1;j<=c;j++) cin>>B[i][j];
     }
     q.push({0,1,1}); d[1][1]=0;
     while(!q.empty()){
       auto [cost,row,col]=q.top(); q.pop();
       if(row==r&&col==c){
         cout<<d[row][col]<<'\n'; break;
       }
       if(visited[row][col]) continue;
        visited[row][col]=true;
        for(int i=1;i<row;i++){
          if(d[row][col]+1+row-i<d[i][col]){
            d[i][col]=d[row][col]+1+row-i;  q.push({-d[i][col],i,col});
          }
        }
        if(row+1<=r&&d[row][col]+B[row][col]<d[row+1][col]){
          d[row+1][col]=d[row][col]+B[row][col];  q.push({-d[row+1][col],row+1,col});
        }
        if(col-1>=1&&d[row][col]+A[row][col-1]<d[row][col-1]){
          d[row][col-1]=d[row][col]+A[row][col-1];  q.push({-d[row][col-1],row,col-1});
        }
        if(col+1<=c&&d[row][col]+A[row][col]<d[row][col+1]){
          d[row][col+1]=d[row][col]+A[row][col];  q.push({-d[row][col+1],row,col+1});
        }
      }

 return 0;
}

#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <cstdio>
#include <functional>
#include <queue>
#include <tuple>
using namespace std;

int main() {
    int R, C;
    scanf("%d%d", &R, &C);
    int A[250000], B[250000];
    int dist[500000], seen[500000] = {0}, cost, pt, to_hide = R * C;
    int top, bottom, right, left, hide, i;
    priority_queue<pair<int, int>, vector<pair<int, int>>,
                   greater<pair<int, int>>>
        queue;
    for(i = 0; i < R * C; ++i)
        if(i % C != C - 1) scanf("%d", &A[i]);
    for(i = 0; i < (R - 1) * C; ++i) scanf("%d", &B[i]);
    for(i = 1; i < to_hide + to_hide; ++i) dist[i] = 10000000;
    queue.emplace(pair<int, int>(0, 0));
    while(!queue.empty()) {
        tie(cost, pt) = queue.top();
        queue.pop();
        seen[pt] = true;
        if(pt < to_hide) {
            left = pt - 1, right = pt + 1, top = pt + C, hide = pt + to_hide;
            if(!seen[right] && pt % C != C - 1) {
                if(cost + A[pt] < dist[pt + 1]) {
                    dist[right] = cost + A[pt];
                    queue.emplace(pair<int, int>(dist[right], right));
                }
            }
            if(!seen[left] && pt % C != 0) {
                if(cost + A[left] < dist[left]) {
                    dist[left] = cost + A[left];
                    queue.emplace(pair<int, int>(dist[left], left));
                }
            }
            if(!seen[top] && top < to_hide) {
                if(cost + B[pt] < dist[top]) {
                    dist[top] = cost + B[pt];
                    queue.emplace(pair<int, int>(dist[top], top));
                }
            }
            if(!seen[hide] && cost + 1 < dist[hide]) {
                dist[hide] = cost + 1;
                queue.emplace(pair<int, int>(dist[hide], hide));
            }
        } else {
            bottom = pt - C, hide = pt - to_hide;
            if(to_hide < bottom && !seen[bottom] && cost + 1 < dist[bottom]) {
                dist[bottom] = cost + 1;
                queue.emplace(pair<int, int>(cost + 1, bottom));
            }
            if(!seen[hide] && cost < dist[hide]) {
                dist[hide] = cost;
                queue.emplace(pair<int, int>(cost, hide));
            }
        }
    }
    printf("%d\n", dist[to_hide - 1]);
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_bac(X/j)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long

using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=2e5+5,M=2e6+5,MOD=998244353,OO=1e9;

ll sum(int x){
	return (ll)x*(x+1)/2 %MOD;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();

	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);

	ll ans = (((sum(a) * sum(b))%MOD) * sum(c))%MOD;
	printf("%lld\n",ans );
}

#line 1 "main.cpp"
#include <bits/stdc++.h>
using namespace std;

// template {{{
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

#define  range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solve() {
  int n = input(), k = input();

  i64 ans = 0;
  range(i, 1, n + 1) range(j, 1, k + 1) {
    ans += 100 * i + j;
  }

  cout << ans << endl;
}

signed main() {
  solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<bool> vbl;
typedef vector<vector<bool>> vvbl;

void INX(){}
template<typename Head, typename... Tail>
void INX(Head&& head, Tail&&... tail)
{
    cin >> head;
    INX(forward<Tail>(tail)...);
}
void OUTX(){}
template<typename Head, typename... Tail>
void OUTX(Head&& head, Tail&&... tail)
{
    cout << head << endl;
    OUTX(forward<Tail>(tail)...);
}
void OUTX2(){cout << endl;}
template<typename Head, typename... Tail>
void OUTX2(Head&& head, Tail&&... tail)
{
    cout << head << ' ';
    OUTX2(forward<Tail>(tail)...);
}

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>
#define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1)

//#define MOD 1000000007 // 10^9 + 7
//setprecision(10)

// Least Significant Bit (LSB)
ll LSB(ll x)
{
    return x & (-x);
}

// Most Significant Bit (MSB)
ll MSB(ll x)
{
    if(x == 0) return x;

    ll cnt = 0;
    while(x)
    {
        cnt++;
        x >>= 1;
    }
    return 1 << (cnt - 1);
}

// 参考：https://www.slideshare.net/hcpc_hokudai/binary-indexed-tree

// Binary Indexed Tree (BIT)
// フェニック木
class BinaryIndexedTree
{
    private:
    ll N; // 要素数
    vll data; // 実体のデータ

    // コンストラクタ共通の初期化処理
    void initial(ll n, ll initialvalue = 0)
    {
        N = n;
        ll msb = MSB(n);
        data.resize((msb == n ? n : MSB(n) << 1) + 1, initialvalue);
    }

    public:
    // コンストラクタ
    BinaryIndexedTree(ll n, ll initialvalue = 0)
    {
        initial(n, initialvalue);
    }

    // a[i]にxを足す(i=1,2,...,N)
    void AddValue(ll i, ll x)
    {
        while(i < (ll)data.size())
        {
            data[i] += x;
            i += LSB(i);
        }
    }

    // a[1]からa[i]までの累積和
    ll GetCumulativeSum(ll i)
    {
        ll result = 0;
        while(i)
        {
            result += data[i];
            i ^= LSB(i);
        }
        return result;
    }

    // a[i]からa[j]までの部分和
    ll GetPartialSum(ll i, ll j)
    {
        return GetCumulativeSum(j) - GetCumulativeSum(i - 1);
    }
};

// 公式解説を参考に実装
int main()
{
    ll N;
    INX(N);

    vll a(N);
    for (ll i = 0; i < N; i++)
    {
        INX(a[i]);
    }

    ll result = 0;
    BinaryIndexedTree bitt(N);
    for(ll x : a)
    {
        result += bitt.GetPartialSum(x + 1, N);
        bitt.AddValue(x + 1, 1);
    }
    for(ll x : a)
    {
        OUTX(result);
        result += N - (1 + 2 * x);
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=((ll)n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=((ll)a);i<((ll)n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll mv,v,n,l,t=0;
    cin>>v>>n>>l;
    mv=v;
    rep(i,n){
        ll a,b; cin>>a>>b;
        v-=(a-t);
        if(v<=0){
            Yn(0);
            return 0;
        }
        v+=b-a;
        v=min(v,mv);
        t=b;
    }
    Yn(v>(l-t));

    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#include "string"
#define int long long
#define pi pair <int, int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl '\n'
#define vi vector<int>

int32_t main() {
	boost;
	int n, m;
	cin >> n >> m;
	if(n == 1 && m == 0) {
		cout << 1 << ' ' << 2 << endl;
		return 0;
	}
	if(m < 0 or m >= n - 1) {
		cout << -1 << endl;
		return 0;
	}
	cout << 1 << ' ' << (int)1e7 << endl;
	int l = 2;
	for(int i = 0; i <= m; i++, l += 2)
		cout << l << ' ' << l + 1 << endl;
	l = 1e7 + 2;
	for(int i = 0; i < n - m - 2; i++, l += 2)
		cout << l <<' ' << l + 1<< endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007
#define pi          acos(-1.0)

int main()
{
   ll n,m, l,r;
   cin>>n>>m;

   if(m==0)
   {
       l=2, r=3;
       for(int i=1; i<=n; i++)
       {
           printf("%lld %lld\n", l,r);
           //cout<<l<<" "<<r<<endl;
           l+=2, r+=2;
       }
       return 0;
   }
   if(m<0 || m>=n-1)
   {
       cout<<"-1"; return 0;
   }

   cout<<1<<" "<<(ll)1e7<<endl;
   l=2, r=3;
   for(int i=1; i<=m+1; i++)
       {
           printf("%lld %lld\n", l,r);
           l+=2, r+=2;
       }

    l=2e7, r=l+1;
   for(int i=m+3; i<=n; i++)
       {
          printf("%lld %lld\n", l,r);
           l+=2, r+=2;
       }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//turn on extra precision
//#pragma GCC target("fpmath=387")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define watch(x) cout << (#x) << " is : " << (x) << newl

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vi dirx = {0,0,1,-1};
vi diry = {1,-1,0,0};
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122) return char(x-32);
    if( 65 <= int(x) && int(x) <= 90) return x;
    return -1;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122) return x;
    if( 65 <= int(x) && int(x) <= 90) return char(x+32);
    return -1;
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57) return int(x-'0');
    if(97 <= int(x) && int(x) <= 122) return int(x-96);
    if(65 <= int(x) && int(x) <= 90) return int(x-64);
    return -1;
}
bool isect (int l1, int r1, int l2, int r2){ return max(l1,l2) <= min(r1,r2); }
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1%MOD;
    else if(num2==1)return num1%MOD;
    else{
        ll temp = quickpow (num1,num2>>1LL,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2&1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
bool valid(int x, vi &v){
    int g = 0;
    for(auto i : v){
        if(i % x == 0) g = (g ? __gcd(g,i) : i);
    }
    return g == x;
}
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi v(n); for(int i = 0; i < n; ++i) cin >> v[i];
    int mn = INT_MAX; for(auto i : v) mn = min(mn,i);

    set <int> s;
    for(auto x : v){
        for(int i = 1; i * i <= x; ++i){
            if(x % i == 0){
                if(i <= mn) s.insert(i);
                if(i != x / i && x / i <= mn) s.insert(x / i);
            }
        }
    }

    int res = 0;
    for(auto i : s) res += valid(i,v);
    cout << res << newl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void exgcd(ll a, ll b, ll& x, ll& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return;
  }
  exgcd(b % a, a, y, x);
  x -= (b / a) * y;
}
ll m = 1e9 + 7;
ll flip(ll a) {
  ll x, y;
  exgcd(a, m, x, y);
  if (x < 0) {
    ll kj = -x;
    kj /= m;
    x += (kj + 1) * m;
  }
  x %= m;
  return x;
}
int main () {
  int N;
  ll M;
  cin >> N >> M;
  M += (ll)N;
  ll sum = (ll)N;
  for (int i = 0; i < N; i ++) {
    ll a;
    cin >> a;
    sum += a;
  }
  ll ans = 1;
  for (ll i = 1; i <= sum; i ++) {
    ans *= (M - i + 1);
    ans %= m;
  }
  ll fli = 1;
  for (ll i = 1; i <= sum; i ++) {
    fli *= i;
    fli %= m;
  }
  ans *= flip(fli);
  ans %= m;
  cout << ans << endl;
}


#include <bits/stdc++.h>
#define Mashu cout << "UUZ ate it." << endl
#define RE register int
#define ll long long
using namespace std;

inline int read(){
	char ch=getchar();
	int x=0,cf=1;
	while(ch<'0'||ch>'9') {
		if(ch=='-') cf=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	if (cf < 0) return -x;
	else return x;
}

int G[55];
template<class T> inline void write(T x){
	if (x < 0){
		putchar('-');
		x = -x;
	}
	int g=0;
	do{G[++g]=x%10;x/=10;}while(x);
	for(int i=g;i>=1;--i)putchar('0'+G[i]);putchar('\n');
}

struct edge{
	int to;
	int nxt;
	int w;
}e[400010];

int f[200010], cnt = 0;

void add(int u, int v, int w){
	e[++cnt].to = v;
	e[cnt].w = w;
	e[cnt].nxt = f[u];
	f[u] = cnt;
}

int main(){
	long long n;
	cin >> n;
	long long ans = 1;
	for (long long i = 2; i <= n; i++){
		ans = i * ans / __gcd(ans, i);
	}
	cout << ans + 1 << endl;
	return 0;
	Mashu;
}

/*ॐ नमो भगवते वासुदेवाय नमः*/
#include<bits/stdc++.h>
using namespace std;

#define int long long
const int MOD = 1e9 + 7;
const double pi = 3.14159265359;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int binpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int inverse(int x){
    return binpow(x, MOD - 2, MOD);
}

void solve()
{
    int n, ans = 0;
    cin >> n;
    n *= 2;
    for(int i = 1; i * i <= n; i++){
        if(n % i == 0){
            if(i % 2 != (n / i) % 2)    ans++;
        }
    }
    cout << 2 * ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}


#include <bits/stdc++.h>
#define endl '\n'
#define all(a) (a).begin(), (a).end()
#define len(a) (int) (a).size()
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
using namespace std;
void solve();
mt19937 rnd(2007);
signed main(){
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    swap(rng, rnd);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
}

void solve() {
    int n; cin >> n;
    vector<int> a(n); forn (i, n) cin >> a[i];
    int mn = *min_element(all(a));
    unordered_map<int, int> vals;
    for (auto v : a){
        for (int i = 1; i * i <= v; ++i){
            if (v % i == 0){
                vals[i] = __gcd(vals[i], v / i);
                vals[v / i] = __gcd(vals[v / i], i);
            }
        }
    }
    int ans = 0;
    for (auto i : vals){
        if (i.first <= mn && i.second == 1) {
            ++ans;
        }
    }
    cout << ans << endl;
}

#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    rep(i, 0, N) {
        cin >> A[i] >> B[i];
    }
    P undefined_val = P(-1, -1);
    int left_dir = 0;
    int right_dir = 1;
    vector<P> dir_and_idx(2 * N + 1, undefined_val);
    rep(i, 0, N) {
        if (A[i] > 0 && B[i] > 0 && A[i] >= B[i]) {
            cout << "No" << endl;
            return 0;
        }
        if (A[i] > 0 && dir_and_idx[A[i]] != undefined_val) {
            cout << "No" << endl;
            return 0;
        }
        if (A[i] > 0) {
            dir_and_idx[A[i]] = P(i, left_dir);
        }
        if (B[i] > 0 && dir_and_idx[B[i]] != undefined_val) {
            cout << "No" << endl;
            return 0;
        }
        if (B[i] > 0) {
            dir_and_idx[B[i]] = P(i, right_dir);
        }
    }
    vector<bool> dp(2 * N + 1, false);
    dp[0] = true;
    rep(i, 1, 2 * N + 1) {
        if (dir_and_idx[i].second == left_dir) {
            continue;
        }
        rep(j, 0, i - 1) {
            if ((i - j) % 2) {
                continue;
            }
            bool is_ok = true;
            rep(k, j + 1, j + (i - j) / 2 + 1) {
                if (dir_and_idx[k].second == right_dir || dir_and_idx[k + (i - j) / 2].second == left_dir) {
                    is_ok = false;
                    break;
                }
                int left_idx = dir_and_idx[k].first;
                int right_idx = dir_and_idx[k + (i - j) / 2].first;
                if (left_idx >= 0 && right_idx >= 0 && left_idx != right_idx) {
                    is_ok = false;
                    break;
                }
                if (left_idx >= 0 && A[left_idx] > 0 && B[left_idx] > 0 && left_idx != right_idx) {
                    is_ok = false;
                    break;
                }
                if (right_idx >= 0 && A[right_idx] > 0 && B[right_idx] > 0 && left_idx != right_idx) {
                    is_ok = false;
                    break;
                }
            }
            dp[i] = (dp[i] | (dp[j] & is_ok));
        }
    }
    if (dp[2 * N]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iostream>

using namespace std;

int main() {
    int a, b, x, y;
    cin >> a >> b >> x >> y;

    int diff = a > b ? a - b - 1 : b - a;

    cout << x + min(2 * x, y) * diff << endl;
}

#include <bits/stdc++.h>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}
template <typename ... Args>
string format(const std::string& fmt, Args ... args ){
   size_t len = std::snprintf(nullptr, 0, fmt.c_str(), args ... );
   vector<char> buf(len + 1);
   snprintf(&buf[0], len + 1, fmt.c_str(), args ... );
   return string(&buf[0], &buf[0] + len);
}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vector<vector<pii>> g(310);
vi dijk(int s){
    vi d(310, INF);
    d[s] = 0;
    priority_queue<pii, vector<pii>, greater<pii>> Q;
    Q.emplace(0,s);
    while(!Q.empty()){
        int c = Q.top().fi;
        int v = Q.top().se;
        Q.pop();
        if(c > d[v]) continue;
        for(auto p : g[v]){
            int u = p.fi;
            int uc = p.se;
            if(d[u] > d[v] + uc){
                d[u] = d[v] + uc;
                Q.emplace(d[u], u);
            }
        }
    }
    return d;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int M = 200;
    int a,b,x,y;
    cin >> a >> b >> x >> y;
    a -= 1; b += M-1;
    rep(i,100){
        g[i].emplace_back(i+M, x);
        g[i+M].emplace_back(i, x);
        g[i+1].emplace_back(i+M, x);
        g[i+M].emplace_back(i+1, x);
        g[i].emplace_back(i+1,y);
        g[i+1].emplace_back(i,y);
        g[i+M].emplace_back(i+M+1,y);
        g[i+M+1].emplace_back(i+M,y);
    }
    vi d = dijk(a);
    cout << d[b] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); ++i)

ll INF = 1ll << 60;

ll cl[200010], cr[200010];
ll dp[200010][2];

int main(){
  int n;
  cin >> n;
  set<ll> col;
  rep(i, 0, 200010){
      cl[i] = INF;
      cr[i] = -1*INF;
  }
  rep(i, 0, n){
      ll x, c;
      cin >> x >> c;
      col.insert(c);
      if(cl[c] > x){
          cl[c] = x;
      }
      if(cr[c] < x){
          cr[c] = x;
      }
  }
  auto itr = col.begin();
  ll st = *itr;
  dp[st][0] = abs(cr[st])+abs(cr[st]-cl[st]);
  dp[st][1] = abs(cl[st])+abs(cr[st]-cl[st]);

  rep(i, 1, col.size()){
      ll cb = *itr;
      itr++;
      ll cn = *itr;
      dp[cn][0] = min(dp[cb][0] + abs(cr[cn]-cl[cn]) + abs(cr[cn]-cl[cb]), dp[cb][1] + abs(cr[cn]-cl[cn]) + abs(cr[cn]-cr[cb]));
      dp[cn][1] = min(dp[cb][0] + abs(cr[cn]-cl[cn]) + abs(cl[cn]-cl[cb]), dp[cb][1] + abs(cr[cn]-cl[cn]) + abs(cl[cn]-cr[cb]));
  }
  ll ls = *itr;
  ll ans = min(dp[ls][0] + abs(cl[ls]), dp[ls][1] + abs(cr[ls]));
  itr = col.begin();

  cout << ans << endl;

  return 0;

}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#ifdef _DEBUG
#define line cout << "-----------------------------\n"
#define stop system("pause")
#endif
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }

int main() {
    init();

    int n; cin >> n;
    int ans = 0;
    eFOR(i, 1, n) {
        int tmp = 1;
        string s = to_string(i);
        for (char c : s)if (c == '7')tmp = 0;
        int j = i;
        for (; j; j /= 8)if (j % 8 == 7)tmp = 0;
        ans += tmp;
    }
    print(ans);

    return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include<algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <tuple>
#include <set>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
  ll n;
  cin >> n;
  vector<ll> a= {6,10,15};
rep(k,3){
  for(int i = 2;i <= 10000/a[k];i ++){
    if(a.size()==n){
      rep(j,n){
        cout << a[j] << ' ';
      }
      cout << endl;
      return 0;
    }
    if(k >= 1 and (i*a[k]%6==0)){
      continue;
    }

    a.push_back(i*a[k]);

  }
}

  return 0;
}

//QwQcOrZ yyds!!!
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define R(i,a,b) for (int i=(a);i<(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,x) for (int i=head[x];i;i=e[i].nx)
#define mp make_pair
#define pb push_back
#define pa pair < int,int >
#define fi first
#define se second
#define re register
#define be begin()
#define en end()
#define sqr(x) ((x)*(x))
#define ret return puts("-1"),0;
#define put putchar('\n')
#define inf 1000000005
#define mod 998244353
#define int ll
//#define N
using namespace std;
inline char gc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}
#define gc getchar
inline ll read(){char c=gc();ll su=0,f=1;for (;c<'0'||c>'9';c=gc()) if (c=='-') f=-1;for (;c>='0'&&c<='9';c=gc()) su=su*10+c-'0';return su*f;}
inline void write(ll x){if (x<0){putchar('-');write(-x);return;}if (x>=10) write(x/10);putchar(x%10+'0');}
inline void writesp(ll x){write(x),putchar(' ');}
inline void writeln(ll x){write(x);putchar('\n');}
ll n,now;
signed main()
{
	n=read();
	for (int i=1;i<=n-1;i++)
	{
		now++;
		while (now%3&&now%5&&now%7) now++;
		writesp(now*2);
	}
    writeln(105);

}
/*

*/


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ll n;
    cin >> n;
    ll ans = n;
    ll t = n + 1;
    for (int i = 1; i <= n; i++) {
        if (t >= i) t -= i, ans--;
        else break;
    }
    cout << ans + 1 << endl;
}

/**
 * Author : RDP
 * There are no two words in the English language more harmful than "good job".
 * 1729 ;)
**/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define endl '\n'
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#define FAST_IO              \
    ios::sync_with_stdio(0); \
    std::cin.tie(0);         \
    std::cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
const ll MOD = 1000000007;

void test_case()
{
    ll n, ans = 0;
    cin >> n;
    set<ll> s;
    for (ll cur = 2; cur * cur <= n; cur++)
    {
        ll x = cur * cur;
        while (x <= n)
        {
            ans++;
            s.insert(x);
            x *= cur;
        }
    }
    cout << n - s.size();
    return;
}
int main()
{
    FAST_IO
    int t = 1;
    //cin >> t;
    while (t--)
        test_case();
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  map<int,int> m;
  auto f = [&](int i,int v){
    if(i>a[0]) return;
    if(m[i]==0) m[i] = v;
    m[i] = gcd(v,m[i]);
  };
  rep(i,n){
    for(int x=1;x*x<=a[i];++x){
      if(a[i]%x!=0) continue;
      f(x,a[i]);
      f(a[i]/x,a[i]);
    }
  }
  int ans = 0;
  for(auto&i:m) ans += i.first==i.second;
  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < n; i++)

int main()
{
    int n;
    cin >> n;
    cout << (n+100-1)/100 << endl;

    return 0;
}


/*ver 7*/
#include <bits/stdc++.h>
using namespace std;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pll = pair<ll,ll>;
using mll = map<ll,ll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
#define each(x,v) for(auto& x : v)
#define reps(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
const ll INF = 1LL << 60;
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<=b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){}
template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}}
template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}}
template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}}
template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}}
template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}}
void out(){cout << endl;}
template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);}
void die(){cout << endl;exit(0);}
template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);}
template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;}
template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}}
template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}}
template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}}
template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}}
template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;}
ll ceilDiv(ll a,ll b) {return (a+b-1)/b;}
ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // ２点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO"  )
#define Yes(n) ((n) ? "Yes" : "No"  )
#define yes(n) ((n) ? "yes" : "no"  )

int main(){
	init();
	inl(n);
	V<ll> a(n);
	in1(a);
	V<ll> goal(n);
	V<ll> l(n),r(n);
	ll now=0;
	rep(i,n){
		now+=a[i];
		goal[i]=now;
		if(i==0){
			l[i]=min(0LL,now);
			r[i]=max(0LL,now);
		}else{
			l[i]=min(l[i-1],now);
			r[i]=max(r[i-1],now);
		}
	}
	ll ansMax=0,ansMin=0;
	now=0;
	rep(i,n){
		chmin(ansMin,now+l[i]);
		chmax(ansMax,now+r[i]);
		now+=goal[i];
	}
	out(ansMax);
	return 0;
}

#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stdio.h>

using namespace std;

int main(){
	long long N;
	cin >> N;
	vector<long long> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	vector<long long> p(N); // 動作iでの合計の座標
	vector<long long> q(N); // 動作iを座標0出始めた場合の最大値
	long long now = 0; 		// 動作i-1での座標
	// p[i]を求める
	for (int i = 0; i < N; i++) {
		p[i] = now + A[i];
		now = p[i]; // 更新
	}
	// q[i]を求める
	long long Max_i = 0;
	for (int i = 0; i < N; i++) {
		Max_i = max(Max_i, p[i]);
		q[i] = Max_i;
	}

	long long r = 0; // 答え
	long long x = 0; // 現在の座標
	for (int i = 0; i < N; i++) {
		r = max(r, x + q[i]);
		x += p[i]; // 現在の座標が増える
	}
	cout << r << endl;
	return 0;
}


#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <ctype.h>
#include <climits>
#include <queue>
#include <iostream>
#include <string>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// #define rep(i, a, b) for(ll i = a; i < b; i++)
using namespace std;
typedef long long ll;
const long long INF = 1001001001;
const ll mod = 1e9 + 7; //10^9+7

// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
// template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//using ll = long long;
//using P = pair<int,int>;
//const int INF = 1001001001;
//小数 printf("%.10f\n", ans);
//string s; int n = stoi(s);
//int number; string s = to_string(number);
//string s; printf("%s\n", s.c_str);
//シフト演算子(190)  2^n : 1<<n
//sのi桁目を取る(190) : (s>>i)&1
//if文にint型を入れたとき,0のときfalse,それ以外はtrue
//set<ll> s; 重複しない、順番を昇順にしてくれる

// UnionFind
//子: 親の番号（非負）, 親: -(サイズ)（負）
struct UnionFind {
  vector<int> d; //配列
  UnionFind(int n=0): d(n,-1) {} //コンストラクタ,頂点数,最初は全て-1(根)であり、かつサイズは-1
  int find(int x) {
    if (d[x] < 0) return x; //頂点番号がマイナス、つまり根ならその頂点番号を返す
    return d[x] = find(d[x]); //マイナスでないなら、その親についてfindを投げる. メモ化して経路縮約
  }
  bool unite(int x, int y) { //2つ頂点を持ってくる
    x = find(x); y = find(y); //両方根に変換する. 根同士をくっつける.
    if (x == y) return false; //連結成分が一致しているとき,何もすることはない. 連結失敗のfalse
    if (d[x] > d[y]) swap(x,y); //d[]そのものの値はマイナスなので不等号の向きに注意.　本来はif(-d[x] < -d[y]). これにより,大きい方xに小さい方yをくっつけることができる. swapは入れ替え
    d[x] += d[y]; //連結成分のサイズも管理しているのでサイズを合算する
    d[y] = x; //両方根だったがyの親をxにはりかえる.
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);} //同じ集合に蔵しているかどうか。
  int size(int x) { return -d[find(x)];} //サイズ. 根のマイナスをとったものとなる.
};

int main () {
  ll n;
  ll x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  int count = 0;
  vector<ll> b(n);
  rep(i,n) {
    if(a[i] == x) continue;
    b[count] = a[i];
    count++;
  }
  rep(i,n) {
    if(b[i] == 0) break;
    cout << b.at(i);
    cout << " ";
  }
  cout << "" << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		int tt;
		cin>>tt;
		if(tt!=k)
		{
			cout<<tt<<" ";
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
#define pii pair<int,int>
#define endl "\n"
#define dtor(deg) (((deg)/360)*2*pi)
#define all(a) a.begin(),a.end()
#define overload(_1,_2,_3,_4,name,...) name
#define _rep1(n) for(int i = 0; i < (n); i++)
#define _rep2(i,n) for(int i = 0; i < (n); i++)
#define _rep3(i,a,b) for(int i = (a); i < (b); i++)
#define _rep4(i,a,b,c) for(int i = (a); i < (b); i += (c))
#define rep(...) overload(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep2(i,n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep3(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define _rrep4(i,a,b,c) for(int i = (b) - 1; i >= (a); i -= (c))
#define rrep(...) overload(__VA_ARGS__,_rrep4,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define vv(type,name,size,...) vector<vector<type>> name(size,vector<type>(__VA_ARGS__))
#define ForEach(a,b) for_each(a.begin(),a.end(),b)
struct Edge { int to, cost; Edge(int to, int cost) : to(to), cost(cost) {} };
using Graph = vector<vector<Edge>>;
template <class T> bool chmin(T& a, T b){ if(a > b){ a = b; return 1; } return 0; }
template <class T> bool chmax(T& a, T b){ if(a < b){ a = b; return 1; } return 0; }

void Main(){
    string n;
    int k;
    cin >> n >> k;
    rep(k){
        sort(all(n));
        int a = stoi(n);
        reverse(all(n));
        int b = stoi(n);
        n = to_string(b - a);
    }
    cout << n << endl;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(10) << fixed;
    Main();
}

// Author: Vinay Khilwani
// Language: C++

// @vok8: Codeforces, AtCoder, LeetCode, HackerEarth, TopCoder, Google, FB, CSES, Spoj, GitHub
// @vok_8: CodeChef, GFG
// @vok8_khilwani: HackerRank

// Never Stop Trying.
// Trying to be Better than Myself.

// while(true)
// {
//     if(AC)
//     {
//         break;
//     }
//     else if(Contest Over)
//     {
//         Try.
//         Check out Editorial.
//         Understand.
//         Find out your Mistake.
//         Learn the topic (if new).
//         Solve Problems on that topic (if new).
//         Upsolve that problem.
//         break;
//     }
//     else
//     {
//         Try.
//         Use Pen-Paper.
//         Find errors, edge cases, etc.
//         continue;
//     }
// }

// Optimizations
// #pragma GCC optimize("O2")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx2")
// #pragma GCC optimize("Os")

// Libraries
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// Debugging
#define dbg(a) cerr<<a<<"\n";
#define debug_a(a) for(auto x:a) {cerr<<x<<" ";} cerr<<"\n";
#define debug_b(a) for(auto x:a) {cerr<<"["<<x.first<<", "<<x.second<<"]"<<"\n";} cerr<<"\n";
#define debug_c(a) for(auto x:a) {debug_a(x)} cerr<<"\n";
#define debug_d(a) for(auto x:a) {debug_b(x)} cerr<<"\n";
#define debug_e(a) cerr<<"["<<a.first<<", "<<a.second<<"]"<<"\n";

// Defines
#define fast ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define fr(i,a,n,b) for(int i=a; i<n; i+=b)
#define rfr(i,a,n,b) for(int i=a; i>=n; i-=b)
#define IN cin>>
#define OUT cout<<
#define nl "\n"
#define sz(a) int(a.size())
#define all(a) (a).begin(),(a).end()
#define each(a,b) for(auto &a:b)
#define pb push_back
#define set_bits(a) __builtin_popcountll(a)
#define ar array
#define write(a) for(auto x:a) {OUT x<<" ";} OUT endl;
#define read(a) for(auto &x:a) {IN x;}
// #define oset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
using ll=long long int;
using ld=long double;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vi=vector<int>;
const ll mod=(ll)(1e9)+7LL;
const ll M=998244353LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ld pi=acos(-1);

// General Functions
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo) //Fast Power
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r)
{
    uniform_int_distribution<ll> uid(l,r);
    return uid(rng);
}
void vok()
{
    fast
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
}

// Global Variables
const int mxN=int(1e5)+100;

// Solver Function(s)
void solve()
{
    ll n,k;
    IN n>>k;
    vll v(k+1);
    v[0]=n;
    loop(i,1,k+1)
    {
        string s=to_string(v[i-1]);
        string S=s;
        sort(all(s),greater<>());
        sort(all(S));
        v[i]=stoi(s)-stoi(S);
    }
    OUT v.back()<<nl;
}

// Main Function
int main()
{
    vok();
    int t=1;
    // IN t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second
typedef long long ll;
/*const int mod=;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,const int &y){x=upd(x+y-mod);}
inline void iadd(int &x,const int &y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}*/
#define rep(i,l,r) for (int i(l);i<=(r);i++)
#define per(i,l,r) for (int i(r);i>=(l);i--)

int n;
void solve(){
	n=read();
	rep(i,0,n-1){
		int x=i*2%n,y=(x+1)%n;
		printf("%d %d\n",x+1,y+1);
	}
}
int main()
{
	for (int T=1;T--;) solve();
}

#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
const int p = 31;
const int m = 1e9 + 7;
typedef long long ll;
typedef int in;
#define ff first
#define ss second
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n;

in main () {

    cin>>n;
    if(n<=11){
        int i=1;
        // cout<<1<<" "<<(n+1)/2<<'\n';
        while(i<=n){
            cout<<max(i-1,1)<<" "<<min(i+1,n)<<'\n';
            ++i;
        }
    }
    else{
        cout<<(n+1)/2<<" "<<n<<'\n';
        for(int i=2;i<n;++i){
            cout<<(i+1)/2<<" "<<(n+i+1)/2<<'\n';
        }
        cout<<(n+1)/2<<" "<<1;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int A,B;

	cin >> A >> B;

	cout << 100 * (1 - double(B)/A) << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;

/*-----<Defines>-----*/
#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)size(x))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     flush           fflush(stdout)

using ull=unsigned long long;
using ll=long long;
using ld=long double;
/*-----</Defines>-----*/
/*-----<Mod Operations>-----*/
const int M=1e9+7;
inline int add(int a,int b,int p=M){ a=a+b; if(a>=p) a-=p; return a; }
inline int sub(int a,int b,int p=M){ a=a-b; if(a<0) a+=p; return a; }
inline int mul(int a,int b,int p=M){ a=(a*1ll*b)%p; return a; }
/*-----</Mod Operations>-----*/

/*-----<Constants>-----*/
const ld pi=acos(-1),eps=1e-9;
const ll inf=1e18;
const int N=1e6+5;
/*-----</Constants>-----*/
void solve()
{
int n,k;
cin>>n>>k;
if(min(n,k)+3>max(n,k))
    cout<<"Yes\n";
else
    cout<<"No\n";
}
int32_t main()
{
    fast();

    int t;

    t=1;
    for(int z=1;z<=t;++z)
    {
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
template <class T1, class T2>
bool chmax(T1 &a, const T2 b) { if (a < b) { a = b; return true; } return false; }
template <class T1, class T2>
bool chmin(T1 &a, const T2 b) { if (a > b) { a = b; return true; } return false; }
template <class T>
istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is >> i; return is; }
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &i : v) os << i << ' '; return os; }
void co() { cout << '\n'; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) { cout << head << ' '; co(forward<Tail>(tail)...); }
void ce() { cerr << '\n'; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) { cerr << head << ' '; ce(forward<Tail>(tail)...); }
void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); }
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int64_t LINF = 1000000000000000001;
constexpr int64_t MOD = 1000000007;
constexpr int64_t MOD_N = 998244353;
constexpr long double EPS = 1e-11;
const double PI = acos(-1);

int64_t extGCD(int64_t a, int64_t b, int64_t &x, int64_t &y) {
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }

    int64_t d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

pair<int64_t, int64_t> chinese_rem(const vector<int64_t> &b, const vector<int64_t> &m){
    int64_t r = 0, M = 1;
    for (int64_t i = 0; i < b.size(); ++i) {
        int64_t p, q;
        int64_t d = extGCD(M, m[i], p, q);
        if ((b[i] - r) % d != 0) return {0, -1};
        int64_t tmp = (b[i] - r) / d * p % (m[i] / d);
        r += M * tmp;
        M *= m[i] / d;
    }
    return {(r % M + M) % M, M};
}

int64_t gcd(int64_t a, int64_t b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

void solve() {
    ll n, s, k;
    cin >> n >> s >> k;

    Vec m = {n, k}, b = {n - s, 0};
    auto p = chinese_rem(b, m);
    // ce(p.first, p.second);
    if (p.second == -1) co(-1);
    else
        co(p.first / k);
}

int main(void) {
    ll t;
    cin >> t;
    while (t--) solve();

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long

template <typename T>
T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a; swap(a, m);
    u -= t * v; swap(u, v);
  }
  assert(m == 1);
  return u;
}
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int T;
    cin >> T;
    while(T--){
    	int n,s,k;
    	cin >> n >> s >> k;
    	int g=__gcd(n,k);
    	if(s%g){
    		cout << "-1\n";
    		continue;
    	}
    	n/=g,s/=g,k/=g;
    	int i=(inverse(k,n)%n+n)%n;
    	cout << (n-s)%n*i%n << '\n';
    }
}


/**
*    author:  tomo0608
*    created: 22.05.2021 20:58:10
**/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include<atcoder/all>
using namespace atcoder;
#endif

typedef long long ll;
typedef long double ld;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;

#define all(x) x.begin(),x.end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
template<class... T>void input(T&... a){(cin >> ... >> a);};
#define INT(...) int __VA_ARGS__; input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define STRING(...) string __VA_ARGS__; input(__VA_ARGS__)
void print(){cout << '\n';}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a; (cout << ... << (cout << ' ', b)); cout << '\n';}
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;}
#ifdef __LOCAL
void debug_out(){ cerr << endl;}
template < class Head, class... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
#define pb push_back
#define eb emplace_back
#define elif else if
#define mp make_pair
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);}
template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;}
template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;}
#define endl '\n'
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

void solve(){
    INT(n);
    V<int> a(n),b(n),c(n);cin >> a >> b >> c;
    V<ll> A(n+1,0),B(n+1,0);
    rep(i,n){
        A[a[i]]++;
        B[b[c[i]-1]]++;
    }
    ll ans = 0;
    rep(i,n+1)ans += A[i]*B[i];
    print(ans);
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << setprecision(20);
    int codeforces = 1;
    //cin >> codeforces;
    while(codeforces--){
        solve();
    }
    return 0;
}

                                /****Jai Ganesha Deva****/
#include<bits/stdc++.h>
using namespace std ;

#define int             long long
#define sz(a)           (int)a.size()
#define INF             2000000000000000000
#define double          long double
#define bug(x)          cerr<<#x<<" is "<<x<<endl
#define debug(...)      fprintf(stderr, __VA_ARGS__), fflush(stderr)
const int M          =  1000000007;
const int MM         =  998244353;
const double PI      =  acos(-1);

int tError()
{
    int n;cin>>n;n*=2;
    string s;cin>>s;
    int q;cin>>q;
    int state =0;

    while(q--)
    {
    	int t,a,b;cin>>t>>a>>b;a--;b--;
    	if(t==2)state = !state;

    	else
    	{
    		if(state==0)
    		swap(s[a],s[b]);
    		else
    		{
    			if(a>=n/2)
    				a=a-n/2;
    			else
    				a=a+n/2;

    			if(b>=n/2)
    				b=b-n/2;
    			else
    				b=b+n/2;

    			swap(s[a],s[b]);
    		}
    	}
    }

    if(state ==0)cout<<s;
    else
    {
    	for (int i = 0; i < n/2; ++i)
    	{
    		/* code */
    		swap(s[i],s[n/2+i]);
    	}
    	cout<<s;
    }
    return 0;
}

signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt" ,"r",stdin) ;
    freopen("output.txt","w",stdout);
    #endif
  */
    int TESTS=1 ;
  //  cin>>TESTS;
    while(TESTS--){
        tError();
        }

    //clock_t z=clock();
    //debug("Total Time:%.4Lf\n",(double)(clock()-z)/CLOCKS_PER_SEC);

    return 0   ;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=200010;
const double PI=acos(-1.0);

signed main(){
    ll n;cin>>n;
    vector<ll>a(0),b(0);
    vector<ll>c(2*n);
    rep(i,2*n){
        cin>>c[i];
        if(i%2==0){
            a.pb(c[i]);
        }else{
            b.pb(c[i]);
        }
    }
    sort(all(a)),sort(rall(b));
    ll idx=-1;
    rep(i,n){
        if(b[i]<=a[i]){
            idx=i;
            break;
        }
    }
    string ans="";
    if(idx==-1){
        rep(i,n){
            ans+="()";
        }
    }else{
        map<ll,ll>aa;
        map<ll,ll>bb;
        rep(i,idx){
            aa[a[i]]++;
            bb[b[i]]++;
        }
        ll x=0,y=0,z=0,w=0;
        rep(i,n*2){
            if(i%2==0){
                if(y>0){
                    if(aa[c[i]]>0){
                        ans+=')';
                        aa[c[i]]--;
                        y--;
                    }else if(w>0){
                        w--;
                        ans+=')';
                    }else{
                        z++;
                        ans+='(';
                    }
                }else{
                    if(aa[c[i]]>0){
                        aa[c[i]]--;
                        ans+='(';
                        x++;
                    }else if(w>0){
                        w--;
                        ans+=')';
                    }else{
                        z++;
                        ans+='(';
                    }
                }
            }else{
                if(x>0){
                    if(bb[c[i]]>0){
                        ans+=')';
                        bb[c[i]]--;
                        x--;
                    }else if(z>0){
                        z--;
                        ans+=')';
                    }else{
                        w++;
                        ans+='(';
                    }
                }else{
                    if(bb[c[i]]>0){
                        bb[c[i]]--;
                        ans+='(';
                        y++;
                    }else if(z>0){
                        z--;
                        ans+=')';
                    }else{
                        w++;
                        ans+='(';
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;

int get() {
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
	return x * f;
}

const int N = 4e5 + 5;
int n, a[N], len, st[N], top, col[N];
pair<int, int> b[N];

int main() {
	n = get();
	for(int i = 1; i <= 2 * n; i++) a[i] = get(), b[i] = make_pair(a[i], i);
	sort(b + 1, b + 1 + 2 * n);
	for(int i = 1; i <= n; i++) col[b[i].second] = 0;
	for(int i = n + 1; i <= n + n; i++) col[b[i].second] = 1;
	for(int i = 1; i <= 2 * n; i++) {
		if(!top) st[++top] = i, printf("(");
		else if(col[st[top]] != col[i]) printf(")"), top--;
		else printf("("), st[++top] = i;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;
const int N = 1e8 + 10;
typedef long long ll;
int main(){
	int n,m,t,k,ans;
	string s;
//	cin>>t;
//	while(t--){
		cin>>s;
		int ok=1;
		for(int i=0;i<s.size()&&ok;i++){
			if(i%2==0&&(s[i]<'a'||s[i]>'z'))ok=0;
			if(i%2==1&&(s[i]<'A'||s[i]>'Z'))ok=0;
		}
		if(ok)cout<<"Yes\n";
		else cout<<"No\n";
//	}
	return 0;
}

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define fast_az_fuk ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define dpll deque<pll>
#define mapll map<ll,ll>
#define umapll umap<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ms(a,x) memset(a,x,sizeof(a))
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;
bool isLoweCase(char c){
    return (c-'a'>=0);
}
int32_t main()
{
    clock_t clk = clock();
    fast_az_fuk
    string s; cin>>s; ll n = s.length();
    bool isUnreadable=1;
    for(ll i=0;i<n;i+=2){
        if(!isLoweCase(s[i])) {isUnreadable=0; break;}
    }
    if(!isUnreadable) {cout<<"No\n"; return 0;}
    for(ll i=1;i<n;i+=2){
        if(isLoweCase(s[i])) { isUnreadable=0; break;}
    }
    if(!isUnreadable) cout<<"No\n"; else cout<<"Yes\n";
    // cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
    return 0;
}


#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define tp          tuple<int,int,int>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;
int main() {
    fastio;
    int t;
    cin>>t;
    string f = "First";
    string s = "Second";
    while(t--) {
        int n;
        cin>>n;
        map<int,int>mp;
        for(int i =0 ; i < n  ;i++ ) {
            int tmp;
            cin>>tmp;
            mp[tmp]++;
        }

        if(n%2) {
            cout<<s<<'\n';
            continue;
        }

        int ok = 0;
        for(auto x : mp) {
            if(x.vv%2) ok = 1;
        }
        if(ok) cout<<f<<'\n';
        else cout<<s<<'\n';
    }
    return 0;
}

/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
inline T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
inline T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

////atcoder library
//#include <atcoder/all>
//using namespace atcoder;

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int t;
	scanf("%d", &t);
	while (t--) {
		int n;
		scanf("%d", &n);
		vector<int> a(n);
		rep(i, n)scanf("%d", &a[i]);
		if (n & 1)puts("Second");
		else {
			ll fst = 0, scd = 0;
			sort(all(a), greater<int>());
			rep(i, n / 2)fst += a[i * 2];
			rep(i, n / 2)scd += a[i * 2 + 1];
			puts(fst > scd ? "First" : "Second");
		}
	}

	Please AC;
}


#include <bits/stdc++.h>
#include <chrono>

using namespace std;

typedef long long ll;
typedef long double lld;

#define fo(i,n)   for(int i=0;i<(int)n;i++)
#define rep(i,x,n)   for(auto i=x;i<n;i++)
#define ch " "
#define nline "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

const int MOD=1e9+7;
const int INF=1e9;

bool pow2(int x){
    return x && (!(x&(x-1)));
}

void solve(){
    int n;
    cin>>n;
    ll a[n];
    for(auto &x:a)  cin>>x;
    sort(a,a+n);

    ll ans=0;

    ll sum=0;
    for(int i=0;i<n;i++){
        ans+=(i*a[i])-sum;
        sum+=a[i];
    }

    // for(int i=0;i<n;i++){
    //     ans+=((i*a[i])-((n-i-1)*a[i]));
    // }

    // ll total=accumulate(a,a+n,0);
    // ll sum=0;
    // for(int i=0;i<n;i++){
    //     sum+=a[i];
    //     ll sumleft=total-sum;
    //     ans+=((i*a[i])-((n-i-1)*a[i]) + sumleft-sum);
    // }
    // ans/=2;

    cout<<ans<<nline;
}

int main(){
    fastio;

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    auto start=chrono::high_resolution_clock::now();

    int t=1;
    // cin>>t;
    for(int i=1;i<=t;i++){
        // cout<<"Case #"<<i<<": ";
        solve();
    }

    auto end=chrono::high_resolution_clock::now();
    double time_taken=chrono::duration_cast<chrono::nanoseconds>(end-start).count();
    time_taken*=1e-9;
    // cout<<"time taken: "<<fixed<<time_taken<<setprecision(9);

}

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define mat vector<vector<int>>
#define vi vector<int>
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define pi pair<int, int>
#define inf 1000000000
#define mod 998244353
#define endl "\n"

const ll INF=1e18+5;

const int naxN=30;
int fact[naxN], inv_fact[naxN];

int power(int a, int n){
	int res=1;

	while(n){
		if(n%2) res=(res*a)%mod, n--;
		else a=(a*a)%mod, n/=2;
	}
	return res;
}

void init(){
	fact[0]=inv_fact[0]=1;

	for(int i=1; i<naxN; i++){
		fact[i]=(i*fact[i-1])%mod;
		inv_fact[i]=power(fact[i], mod-2)%mod;
	}
}

int ncr(int a, int b){
	if(a<0 || b<0 || a<b) return 0;

	return (fact[a]%mod*inv_fact[b]%mod*inv_fact[a-b]%mod)%mod;
}

//int dx[8]={-1, -1, -1, 0, 1, 1, 1, 0};
int dy[8]={-1, 0, 1, 1, 1, 0, -1, -1};

int par[30];
int R[30];

int find(int a){
	if(par[a]<0) return a;
	return par[a]=find(par[a]);
}

void merge(int a, int b){
	a=find(a);
	b=find(b);

	if(a==b) return;

	if(R[a]>=R[b]){
		par[b]=a;
		R[a]+=R[b];
	}
	else{
		par[a]=b;
		R[b]+=R[a];
	}
}

const int naxP=30;

int prime[naxP];

void sieve(){
    prime[0]=1;
    prime[1]=1;

    for(int i=2; i*i<=naxP; i++){
        if(prime[i]==0){
            for(int j=i*i; j<=naxP; j+=i){
                prime[j]=1;
            }
        }
    }
}

//****DO NOT TOUCH ABOVE THIS LINE****//
//#define kk

const int maxN=2e5+5;

int arr[maxN];

void solve(){
	int n;
	cin>>n;

	for(int i=1; i<=n; i++) cin>>arr[i];

	sort(arr+1, arr+n+1);

	for(int i=1; i<=n; i++) arr[i]+=arr[i-1];

	int sum1=0, sum2=0;

	for(int i=1; i<n; i++){
		sum1+=(arr[n]-arr[i]);
	}

	for(int i=1; i<n; i++){
		sum2+=(arr[i]-arr[i-1])*(n-i);
	}

	cout<<sum1-sum2<<endl;
}

//****DO NOT TOUCH BELOW THIS LINE****//

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cout<<fixed<<setprecision(6);

	#ifdef kk
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#endif

	int T=1;
	//cin>>T;

	while(T--){
		solve();
	}
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;

const int n = 20;
const int n2 = 1<<n;
const vector<int> p = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};

int main() {
  ll a, b;
  cin >> a >> b;
  vector<ll> dp(n2);
  dp[0] = 1;
  for (ll x = a; x <= b; x++) {
    int s = 0;
    rep(i, n) if(x % p[i] == 0) s |= 1 << i;
    rep(i, n2) {
      if (i & s) continue;
      dp[i|s] += dp[i];
    }
  }

  ll ans = 0;
  rep(i, n2) ans += dp[i];
  cout << ans << endl;

  return 0;
}

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,avx512f")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <cassert>
#include <memory>
#include <random>
#include <functional>
#include <complex>
#include <immintrin.h>
#ifdef DEBUG
#include "./CompetitiveProgrammingCpp/debug_VC.hpp"
#include "./CompetitiveProgrammingCpp/Timer.hpp"
#include "./CompetitiveProgrammingCpp/sample.hpp"
#else
#define dump(...)
#endif

/* macro */
#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define REPI2(it,b,e) for(auto it = (b); it != (e); ++it)
#define REPI(it,c) REPI2(it, (c).begin(), (c).end())
#define RREPI(it,c) REPI2(it, (c).rbegin(), (c).rend())
#define REPI_ERACE2(it, b, e) for(auto it = (b); it != (e);)
#define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end())
#define ALL(x) (x).begin(),(x).end()
#define cauto const auto&
/* macro func */
template<class T>
inline auto sort(T& t) { std::sort(ALL(t)); }
template<class T>
inline auto rsort(T& t) { std::sort((t).rbegin(), (t).rend()); }
template<class T>
inline auto unique(T& t) { (t).erase(unique((t).begin(), (t).end()), (t).end()); }
template<class T, class S>
inline auto chmax(T& t, const S& s) { if (s > t) { t = s; return true; } return false; }
template<class T, class S>
inline auto chmin(T& t, const S& s) { if (s < t) { t = s; return true; } return false; }
inline auto BR() { std::cout << "\n"; }

/* type define */
using ll = long long;
using PAIR = std::pair<ll, ll>;
using VS = std::vector<std::string>;
using VL = std::vector<long long>;
using VVL = std::vector<VL>;
using VVVL = std::vector<VVL>;
using VD = std::vector<double>;
template<class T>
using V = std::vector<T>;

/* using std */
using std::cout;
constexpr char endl = '\n';
using std::cin;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::unordered_multiset;
using std::multiset;
using std::bitset;
using std::priority_queue;

/* Initial processing  */
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;

/* Remove the source of the bug */
signed pow(signed, signed) { assert(false); return -1; }

/* define hash */
namespace std {
template <>	class hash<std::pair<ll, ll>> { public:	size_t operator()(const std::pair<ll, ll>& x) const { return hash<ll>()(1000000000 * x.first + x.second); } };
}

/* input */
template<class T> std::istream& operator >> (std::istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }

/* constant value */
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;

//=============================================================================================

signed main() {
	ll n;
	cin >> n;
	VD v(n);
	cin >> v;

	auto val = [&](double d) {
		double ans = 0.0;
		REPC(x, v) {
			ans += (d + x) / n;
			ans -= std::min(x, 2.0 * d) / n;
		}
		return ans;
	};

	double low = 0;
	double high = 1e15;
	int cnt = 500;
	while (cnt--) {
		double c1 = (low * 2 + high) / 3;
		double c2 = (low + high * 2) / 3;

		if (val(c1) > val(c2)) low = c1;
		else high = c2;
	}
	cout << std::fixed << std::setprecision(15)
		<< val(low) << endl;
}


#include<bits/stdc++.h>
using namespace std;

int n,m;
int edge[1001][1001];
bool visited[1001][1001];
vector<int> vc[1001][26];

struct PT{
    int st,ed;
    int size;
};

int main(){
    int x,y,sz;
    char c;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>x>>y>>c;
        edge[x][y]=edge[y][x]=1;
        vc[x][c-'a'].push_back(y);
        vc[y][c-'a'].push_back(x);
    }
    bool flag=false;
    queue<PT> q;
    PT temp,in;
    temp.st=1; temp.ed=n; temp.size=0;
    visited[temp.st][temp.ed]=true;
    q.push(temp);
  	int ans=1e9;
    while(!q.empty()){
        temp=q.front();
		q.pop();
		x=temp.st; y=temp.ed; sz=temp.size;
        if(edge[x][y]>0||x==y){
            if(x==y) ans=min(ans,sz);
            else ans=min(ans,sz+1);
        }
        for(int t=0;t<26;t++){
            for(auto i:vc[x][t]){
                for(auto j:vc[y][t]){
                    if(visited[i][j]) continue;
                    visited[i][j]=true;
                    temp.st=i; temp.ed=j; temp.size=sz+2;
                    q.push(temp);
                }
            }
        }
    }
    if(ans==1e9) cout<<"-1\n";
    else cout<<ans<<'\n';
}

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)

const ll MOD = 1000000007;
const ll INF = (ll) 1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    ll n = N * N;
    vector<ll> dist(n, INF);
    vector<vector<ll>> V(n);
    vector<vector<pll>> E(26);
    REP(i, M) {
        char c;
        ll a, b;
        cin >> a >> b >> c;
        a--;
        b--;
        E[c - 'a'].push_back(pll(a, b));
    }
    REP(c, 26) {
        REP(i, E[c].size()) {
            FOR(j, E[c].size(), i + 1) {
                vector<ll> v1 = {E[c][i].first, E[c][i].second};
                vector<ll> v0 = {E[c][j].first, E[c][j].second};
                REP(x, 2) {
                    REP(y, 2) {
                        {
                            ll idx0 = v0[x] * N + v1[y];
                            ll idx1 = v0[(x + 1) % 2] * N + v1[(y + 1) % 2];
                            V[idx0].push_back(idx1);
                            V[idx1].push_back(idx0);
                        }
                        {
                            ll idx0 = v1[x] * N + v0[y];
                            ll idx1 = v1[(x + 1) % 2] * N + v0[(y + 1) % 2];
                            V[idx0].push_back(idx1);
                            V[idx1].push_back(idx0);
                        }
                    }
                }
            }
        }
    }

    ll s = N - 1;
    dist[s] = 0;
    queue<ll> q;
    q.push(s);
    while (!q.empty()) {
        ll t = q.front();
        q.pop();

        ll cost = dist[t] + 1;
        REP(i, V[t].size()) {
            ll nxt = V[t][i];
            if (dist[nxt] <= cost)
                continue;
            dist[nxt] = cost;
            q.push(nxt);
        }
    }

    ll ans = INF;
    REP(i, N) {
        ll idx = i * N + i;
        ans = std::min(dist[idx] * 2, ans);
    }
    REP(c, 26) {
        REP(i, E[c].size()) {
            ll a = E[c][i].first, b = E[c][i].second;
            ll idx0 = a * N + b;
            ll idx1 = b * N + a;
            ans = std::min({ans, dist[idx0] * 2 + 1, dist[idx1] * 2 + 1});
        }
    }
    if (ans == INF)
        ans = -1;
    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int INF = 1e9;
int dp[1 << 18][18];
int shortestTSPdistance(vector<vector<int> > dist) {
	int n = dist.size();
	int lim = 1 << n;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < lim; ++j)
			dp[j][i] = INF;
	for (int i = 0; i < 1; i++) {
		dp[1 << i][i] = 0;
	}
	for (int mask = 0; mask < lim; mask++) {
		for (int last = 0; last < n; last++) {
			if (mask && (1 << last) == 0) {
				continue;
			}
			for (int curr = 0; curr < n; curr++) {
				if (mask && (1 << curr) == 0) {
					continue;
				}
				int otherMask = mask ^ (1 << curr);
				dp[mask][curr] = min(dp[mask][curr], dp[otherMask][last] + dist[last][curr]);
			}
		}
	}
	int ans = INF;
	for (int i = 0; i < 1; i++) {
		ans = min(ans, dp[lim - 1][i]);
	}
	return ans;
}
int main() {
	int n;
	cin >> n;
	vector <vector<int>> vec;
	for (int i = 0; i < n; ++i) {
		vector <int> temp(3);
		for (int& a : temp)
			cin >> a;
		vec.pb(temp);
	}
	vector <vector<int>> dist;
	for (int i = 0; i < n; ++i) {
		vector <int> temp;
		for (int j = 0; j < n; ++j) {
			temp.pb(abs(vec[i][0] - vec[j][0]) + abs(vec[i][1] - vec[j][1]) + max(0, vec[j][2] - vec[i][2]));
		}
		dist.pb(temp);
	}
	cout << shortestTSPdistance(dist) << endl;
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int n;
pair<ii, int> dat[20];
int dp[20][(1<<17)+5];

int calcDist(pair<ii, int> A, pair<ii, int> B) {
	return abs(A.fi.fi - B.fi.fi) + abs(A.fi.se - B.fi.se) + max(0, B.se - A.se);
}

int DP(int cur, int mask) {
	int& ret = dp[cur][mask];
	if (ret != -1) return ret;
	if (n == __builtin_popcount(mask)) return ret = calcDist(dat[cur], dat[0]);
	ret = INT_MAX;
	for (int nxt = 1; nxt < n; nxt++) {
		if (mask & (1<<nxt)) continue;
		int nxtDist = calcDist(dat[cur], dat[nxt]);
		ret = min(ret, nxtDist + DP(nxt, mask | (1<<nxt)));
	}
	return ret;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int x, y, z; scanf("%d %d %d", &x, &y, &z);
		dat[i] = {{x,y},z};
	}
	reset(dp,-1);
	printf("%d\n", DP(0, 1));
	return 0;
}