#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int N=2e5+100;

int a[N];

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

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    int pref=0;
    int ans=0;
    for(int i=1;i<=n;i++)
        ans+=a[i]*(i-1)-pref,
        pref+=a[i];
    cout<<ans;
}

#include <bits/stdc++.h>
#define ll long long

using namespace std;

class BIT
{
public:
    ll n;
    vector<ll> tree;
    BIT(ll nn)
    {
        n = nn;
        tree = vector<ll>(n + 1, 0);
    }

    ll sum(ll k)
    {
        k++;
        ll s = 0;
        while (k >= 1)
        {
            s += tree[k];
            k -= k&-k;
        }
        return s;
    }

    void add(ll k, ll x)
    {
        k++;
        while (k <= n)
        {
            tree[k] += x;
            k += k&-k;
        }
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> v(n);
    for(ll i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    ll nidx = 0;
    auto vv = v;
    sort(vv.begin(), vv.end());
    unordered_map<ll, ll> numToIdx, idxToNum;
    for(ll i = 0; i < n; i++)
    {
        if(numToIdx.count(vv[i]))
            continue;
        numToIdx[vv[i]] = nidx++;
    }

    for(auto& [num, idx] : numToIdx)
    {
        idxToNum[idx] = num;
    }

    BIT bit(nidx), bitCnt(nidx);
    ll ret = 0;
    bit.add(numToIdx[v[n - 1]], v[n - 1]);
    bitCnt.add(numToIdx[v[n - 1]], 1);
    for(ll i = n - 2; i > -1; i--)
    {
        ll idx = numToIdx[v[i]];
        ll left = bit.sum(idx);
        ll leftCnt = bitCnt.sum(idx);
        ll right = bit.sum(nidx - 1) - left;
        ll rightCnt = bitCnt.sum(nidx - 1) - leftCnt;
        ret += leftCnt * v[i] - left + right - v[i] * rightCnt;
        bit.add(idx, v[i]);
        bitCnt.add(idx, 1);
    }
    cout << ret << endl;

    return 0;
}


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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

#define mp make_pair
#define fr first
#define sc second

int lg(ll n) {
    assert(n > 0);
    int ans = -1;
    while (n) {
        ans++;
        n >>= 1;
    }
    return ans;
}

int score(string s) {
    vector<int> cnt(10);
    iota(cnt.begin(), cnt.end(), 0);
    for (char ch : s) cnt[ch - '0'] *= 10;
    return accumulate(cnt.begin(), cnt.end(), 0);
}

void solve() {
    int K;
    cin >> K;
    string S, T;
    cin >> S >> T;
    S.pop_back(), T.pop_back();
    vector<int> cnt(10, K);
    for (char ch : S) cnt[ch - '0']--;
    for (char ch : T) cnt[ch - '0']--;
    ll ans = 0;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (score(S + (char)(i + '0')) > score(T + (char)(j + '0'))) {
                ans += (i == j ? 1LL * cnt[i] * (cnt[i] - 1)
                               : 1LL * cnt[i] * cnt[j]);
            }
        }
    }
    const int remain = 9 * K - 8;
    cout << fixed << setprecision(12) << (double)ans / remain / (remain - 1)
         << '\n';
}

int 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 t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

long long rnd(long double n)
{
    long double f, c;

    f = n - (long double)floor(n);
    c = (long double)ceil(n) - n;

    if (c < f)
    {
        return ceil(n);
    }
    else
    {
        return floor(n);
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long k, n, m, i, s = 0, d;
    long double r;

    cin >> k >> n >> m;

    r = (long double)m / (long double)n;

    vector<long long> a(k);
    vector<long double> b1(k);
    vector<long long> b2(k);
    vector<long long> c(k);
    vector<pair<long double, long long>> di(k);

    for (i = 0; i < k; i++)
    {
        cin >> a[i];
    }

    for (i = 0; i < k; i++)
    {
        b1[i] = (long double)a[i]*r;
    }

    for (i = 0; i < k; i++)
    {
        b2[i] = rnd(b1[i]);
    }

    for (i = 0; i < k; i++)
    {
        if (b1[i] > (long double)b2[i])
        {
            c[i] = -1;
        }
        else if (b1[i] < (long double)b2[i])
        {
            c[i] = 1;
        }
        else
        {
            c[i] = 0;
        }

    }

    for (i = 0; i < k; i++)
    {
        di[i] = make_pair((long double)b2[i] - b1[i], i);
    }

    for (i = 0; i < k; i++)
    {
        s += b2[i];
    }

    d = m - s;

    std::sort(di.begin(), di.end(), [](const std::pair<float, int>& first, const std::pair<float, int>& second)
{
    return first.first < second.first;
});

    if (d > 0)
    {

        for (i = 0; i < d; i++)
        {
            b2[di[i].second]++;
        }
    }
    else if (d < 0)
    {

        d = d*(-1);

        for (i = 0; i < d; i++)
        {
            b2[di[k-1-i].second]--;
        }
    }

    for (i = 0; i < k; i++)
    {
        cout << b2[i] << " ";
    }

}


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

#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
#define uwu ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize("Ofast")

const int INF = 1e9 + 7;
const long long INF2 = 1e17;

int main(void) {
	uwu

	int n; cin >> n;
	vector <int> v(n);
	ffor(n) cin >> v[i];

	for(int i = 0; i < n; i += 2) v[i] *= -1;

	map <long long, int> count;
	long long current = 0, ans = 0;
	for(int i = 0; i < n; i++) {
		current += v[i];
		if (current == 0) ans++;
		ans += count[current];
		count[current] += 1;
	}
	cout << ans << '\n';
}
/*
C:\Users\kenne\OneDrive\Desktop\competitive_programming\main.cpp
*/

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;
#define forn(a, e) for (i64 a = 0; a < (i64)(e); a++)
#define forr(a, s, e) for (i64 a = s; a < (i64)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using iip = pair<int, int>;
using llp = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }
template<typename T, size_t N>
istream& operator>>(istream& is, array<T, N>& c) { for (auto& e : c) is >> e; return is; }

template<typename ...T>
istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

// const i64 INF = 2e18;
const int INF = 2e9;
const i64 M = 998244353;
const int MXB = 20;
using bin = bitset<MXB + 1>;
const double EPS = 1e-8;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    rande.seed(chrono::steady_clock::now().time_since_epoch().count());

    int n;
    while (read(n)) {
        llvec a(n);
        read(a);

        llvec sa[2] = {llvec(n + 1), llvec(n + 1)};

        forn(i, n) {
            int pi = i % 2;
            int ni = pi ^ 1;

            sa[pi][i + 1] = sa[pi][i] + a[i];
            sa[ni][i + 1] = sa[ni][i];
        }

        map<i64, i64> cc;
        i64 ans = 0;

        forn(i, n + 1) {
            ans += cc[sa[0][i] - sa[1][i]];
            cc[sa[0][i] - sa[1][i]]++;
        }

        cout << ans << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int t=min(a,b);
int t1=min(c,d);
cout<<min(t,t1);
}

#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <array>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <string>

#define foi(i,a,b) for(int i=a;i<=b;++i)
#define iof(i,a,b) for(int i=a;i>=b;--i)
#define fol(i,a,b) for(int i=a;i<=b;++i)
#define lof(i,a,b) for(int i=a;i>=b;--i)

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef unsigned int u32;
typedef unsigned short u16;

typedef pair<int,int> PII;
typedef pair<LL,int> PLI;
typedef pair<int,LL> PIL;
typedef pair<LL,LL> PLL;

const int Inf=(1<<30)-1;
const LL lInf=(1LL<<62)-1;
const int mInf=0x7f7f7f7f;

int main()
{
	ios::sync_with_stdio(false);

	int minn=Inf;
	for(int a,i=1;i<=4;i++) cin>>a,minn=min(minn,a);
	cout<<minn<<endl;

	return 0;
}


#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return (a / gcd(a, b)) * b; }

static const long long MOD = 998244353;
static const size_t MAX_N = 1000001;

struct modll {
	long long x;
	modll() { }
	modll(int _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(int y) { return (x + y + MOD) % MOD; }
	modll operator+=(int y) { x = (x + y + MOD) % MOD; return *this; }
	modll operator-(int y) { return (x - y + MOD) % MOD; }
	modll operator-=(int y) { x = (x - y + MOD) % MOD; return *this; }
	modll operator*(int y) { return (x * y) % MOD; }
	modll operator*=(int y) { x = (x * y) % MOD; return *this; }
	modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
	modll operator/=(int y) { x = (x * modpow(y, MOD - 2)) % MOD; return *this; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

static modll fact[MAX_N + 1], inv[MAX_N + 1];

modll combination(LL n, LL r) {
	if (!fact[0]) {
		fact[0] = 1;
		for (int i = 1; i <= MAX_N; ++i) {
			fact[i] = fact[i - 1] * i;
		}
		inv[MAX_N] = modll::modinv(fact[MAX_N]);
		for (int i = MAX_N; i >= 1; --i) {
			inv[i - 1] = inv[i] * i;
		}
	}
	if (r > n) {
		return 0;
	}
	return (fact[n] * inv[r]) * inv[n - r];
}

struct UnionFind {
	std::vector<int> _parent;
	std::vector<int> _size;
	UnionFind(int size) : _parent(size, -1), _size(size, 1) { }
	void unite(int a, int b) {
		int ra = root(a), rb = root(b); if (ra == rb) { return; }
		if (_size[ra] >= _size[rb]) { _parent[rb] = ra, _size[ra] += _size[rb]; } else { _parent[ra] = rb, _size[rb] += _size[ra]; }
	}
	int root(int a) {
		int p = _parent[a];
		if (p < 0) { return a; }
		while (_parent[p] >= 0) { p = _parent[p]; }
		return _parent[a] = p;
	}
	int size(int a) { return _size[root(a)]; }
};

void solve(long long N, long long K, std::vector<std::vector<long long>> &A) {
	UnionFind h(N), v(N);
	for (LL a = 0; a < N; ++a) {
		for (LL b = 0; b < N; ++b) {
			if (a == b) continue;
			LL i;
			for (i = 0; i < N; ++i) {
				if (A[i][a] + A[i][b] > K) {
					break;
				}
			}
			if (i >= N) {
				h.unite(a, b);
			}
			for (i = 0; i < N; ++i) {
				if (A[a][i] + A[b][i] > K) {
					break;
				}
			}
			if (i >= N) {
				v.unite(a, b);
			}
		}
	}
	combination(0, 0);
	modll ans = 1;
	for (LL a = 0; a < N; ++a) {
		if (h.root(a) == a) {
			ans *= fact[h.size(a)];
		}
		if (v.root(a) == a) {
			ans *= fact[v.size(a)];
		}
	}
	cout << ans << endl;
}

int main() {
    long long N;
	std::cin >> N;
	long long K;
	std::cin >> K;
	std::vector<std::vector<long long>> a(N, std::vector<long long>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			std::cin >> a[i][j]; // a[i][j]--;
		}
	}
	solve(N, K, a);
	return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <fstream>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589

#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;

#define MODU 998244353LL

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) { //ｘの入ってる集合と yの入ってる集合を併合
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) { //xとyが同じ集合に入っているかどうかを判定
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	bool isroot(int x) {
		return data[x] < 0;
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll fuc(ll a){
    ll ans = 1;

    REP(i,a){
        ans *= i+1;
        ans %= MODU;
    }
    return ans;
}

ll check(vector<vector<int>>& m, int s){
    int n = m.size();
    UnionFind uf(n);

    REP(i,n){
        rep(j, i + 1, n){
            bool f = true;
            REP(k, n){
                if(m[i][k] + m[j][k] > s) f = false;
            }
            if(f) uf.unionSet(i, j);
        }
    }

    ll ret = 1;
    REP(i, n){
        if(uf.data[i] < 0){
            ret *= fuc(-uf.data[i]);
            ret %= MODU;
        }
    }
    return ret;
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<vector<int>> m(n,vector<int> (n));
    vector<vector<int>> r(n,vector<int> (n));
    REP(i,n){
        REP(j,n){
            cin >> m[i][j];
            r[j][i] = m[i][j];
        }
    }

    ll a = check(m, k);
    ll b = check(r, k);

    cout << (a * b) % MODU << endl;
    return 0;
}


/*************************************************************************
	> File Name: e.cpp
    > Full Path: /Users/zhanghang/Downloads/e.cpp
	> Author: Hang Zhang
	> Created Time: 三  4/28 14:59:02 2021
 ************************************************************************/

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const int MAXN=105;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;

struct Matrix
{
	ll ma[MAXN][MAXN];
	int n;
	Matrix(int n):n(n){ //nn is the dimension of matrix
		memset(ma,0,sizeof ma);
	}
};
Matrix mul(Matrix A,Matrix B,long long mod)
{
	int n=A.n;
	Matrix C(n);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				C.ma[i][j]=(C.ma[i][j]+A.ma[i][k]*B.ma[k][j])%mod;
			}
		}
	}
	return C;
}
Matrix pow_mod(Matrix A,long long k, long long mod)
{
	int n=A.n;
	Matrix B(n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			B.ma[i][j]=0;
		}
		B.ma[i][i]=1;
	}
	while(k)
	{
		if(k&1) B=mul(B,A,mod);
		A=mul(A,A,mod);
		k>>=1;
	}
	return B;
}

long long quick_pow(long long a, long long b, long long mod) {
	a %= mod;
	long long res = 1;
	while (b) {
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
int a[MAXN];
vector<int>G[MAXN];
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=1;i<=m;i++){
		int x,y;cin>>x>>y;
		x--;y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	ll tmp=quick_pow(m*2LL,1LL*mod-2,mod);
	Matrix t(n);
	for(int i=0;i<n;i++){
		int d=G[i].size();
		t.ma[i][i]=((1LL-tmp*d%mod)%mod+mod)%mod;
		for(auto v:G[i]){
			t.ma[i][v]=tmp;
		}
	}
	Matrix e=pow_mod(t,k,mod);
	for(int i=0;i<n;i++){
		ll ans=0;
		for(int j=0;j<n;j++){
			ans+=e.ma[i][j]*a[j];
			ans%=mod;
		}
		cout<<ans<<endl;
	}

	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define f(a,b) for(int i=a; i<b; i++)
#define rep(i,a,b) for(int i=a;i< b;i++)
#define endl "\n"
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define fr first
#define sc second
#define INF 1000000000
#define pb push_back
#define ppb pop_back()
#define sz(x) (int)((x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define PI 3.14159265358979323846
using namespace std;
const int N=100+5;
int d[N];
const long long MOD2 = static_cast<long long>(MOD) * MOD;

struct Matrix
{
  vector< vector<int> > mat;
  int n_rows, n_cols;

  Matrix() {}

  Matrix(vector< vector<int> > values): mat(values), n_rows(values.size()),
    n_cols(values[0].size()) {}

  static Matrix identity_matrix(int n)
  {
    vector< vector<int> > values(n, vector<int>(n, 0));
    for(int i = 0; i < n; i++)
      values[i][i] = 1;
    return values;
  }

  Matrix operator*(const Matrix &other) const
  {
    int n = n_rows, m = other.n_cols;
    vector< vector<int> > result(n_rows, vector<int>(n_cols, 0));
    for(int i = 0; i < n; i++)
      for(int j = 0; j < m; j++) {
        long long tmp = 0;
        for(int k = 0; k < n_cols; k++) {
          tmp += mat[i][k] * 1ll * other.mat[k][j];
          while(tmp >= MOD2)
            tmp -= MOD2;
        }
        result[i][j] = tmp % MOD;
      }

    return move(Matrix(move(result)));
  }

  inline bool is_square() const
  {
    return n_rows == n_cols;
  }
};

// binary exponentiation, returns a^p
Matrix pw(Matrix a,int p){
  Matrix result = Matrix::identity_matrix(a.n_cols);
  while (p > 0) {
    if (p & 1)
      result = a * result;
    a = a * a;
    p >>= 1;
  }
  return result;
}
int binpow(int a,int b){
  int res=1;
  while(b){
    if(b&1) res*=a , res%=MOD;
    a*=a , a%=MOD;
    b>>=1;
  }
  return res;
}
void test_case()
{
  int n,m,k;
  cin>>n>>m>>k;

  vector<vector<int>> v(n,vector<int>(1));
  vector<vector<int>> mat(n,vector<int>(n,0));
  rep(i,0,n) cin>>v[i][0];
  int oneby2m=binpow(2*m,MOD-2);
  rep(i,0,m){
    int x,y;
    cin>>x>>y;
    x--;y--;
    d[x]++;d[y]++;
    mat[x][y]=mat[y][x]=oneby2m;
  }
  rep(i,0,n){
    mat[i][i]=(2*m-d[i]) * oneby2m %MOD;
  }
  Matrix ans=pw(mat,k)*v;
  rep(i,0,n) cout<< ans.mat[i][0] << endl ;

}
signed main()
{
  fast_io;
  #ifdef NCR
    init();
  #endif
  int t=1;
  // cin>>t;
  rep(i,0,t){
  //cout<< "Case #" << i+1 << ": ";
         test_case();
  }
  return 0;
}
//taskkill -im main.exe -f


//https://atcoder.jp/contests/abc183/tasks/abc183_e
//E - Queen on Grid
#include <bits/stdc++.h>

using namespace std;
const int MAXH=2e3+2;
const int MAXW=2e3+2;
char nums[MAXH][MAXW];//用于保存迷宫

long long row[MAXH];//行走法
long long col[MAXW];//列走法
long long dia[MAXH+MAXW];//对角线

const long long MO=1e9+7;
/*计算对角线的时候 i-j 可能出现负数，最大的负数是 1-2000=-1999，所以需要一个 OFFSET 保证正下标*/
const int OFFSET=max(MAXH, MAXW);//只要超过MAXH和MAXW最大值就可以

int main() {
#if 1
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    int h,w;
    cin>>h>>w;
    for (int i=1; i<=h; i++) {
        for (int j=1; j<=w; j++) {
            cin>>nums[i][j];
        }
    }

    long long ans=-1;
    for (int i=1; i<=h; i++) {
        for (int j=1; j<=w; j++) {
            if ('#'==nums[i][j]) {
                row[i] = 0;
                col[j] = 0;
                dia[i-j+OFFSET] = 0;
            } else {
                long long res = (row[i]+col[j]+dia[i-j+OFFSET])%MO;
                if (1==i && 1==j) {
                    res++;
                }
                ans = res;

                //更新
                row[i] = (row[i]+res)%MO;
                col[j] = (col[j]+res)%MO;
                dia[i-j+OFFSET] = (dia[i-j+OFFSET]+res)%MO;
            }
        }
    }

    cout<<ans<<"\n";

    return 0;
}

#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#define F first
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define S second
#include<queue>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define ld long double
#define mod 1000000007;
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
//first try to write all condition on copy then go for implement
ll pows(ll a,ll n,ll m)
{
	a=a%mod;
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}
	}
	return res%m;
}
int  gcd(int a,int b)
{
	if(b==0)
	return a;
	else
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
		return false;
			}
	}
	return true;
}

const int N=2005;

string s[N];
ll dp[N][N];
ll phor[N][N];
ll pver[N][N];
ll pdia[N][N];

bool wall(int x,int y){
	if(x < 1 || y < 1 || s[x-1][y-1] == '#') return true;
	return false;
}

int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
int h,w;
	cin >> h >> w;
	rep(i,0,h){
		cin >> s[i];
	}

	dp[1][1] = 1;
	phor[1][1] = 1;
	pver[1][1] = 1;
	pdia[1][1] = 1;

	rep(i,1,h+1){
		rep(j,1,w+1){
			if(i == 1 && j == 1) continue;
			if(wall(i,j)) continue;
			dp[i][j] = (phor[i-1][j] + pver[i][j-1] + pdia[i-1][j-1]) % mod;

			phor[i][j] = dp[i][j];
			pver[i][j] = dp[i][j];
			pdia[i][j] = dp[i][j];
			phor[i][j] += phor[i-1][j];
			pver[i][j] += pver[i][j-1];
			pdia[i][j] += pdia[i-1][j-1];

			phor[i][j] %= mod;
			pver[i][j] %= mod;
			pdia[i][j] %= mod;
		}
	}

	cout << dp[h][w]<<endl;
}


/* 	author : sgupta_2001 	*/

#include<bits/stdc++.h>

using namespace std;

using db = double;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

//containers
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front

//pairs
#define mp make_pair
#define ff first
#define ss second

//loops
#define rep(i, a, b) for(int i = a; i < b; ++i)
#define per(i, a, b) for(int i = b - 1; i >= a; --i)
#define each(x, a) for(auto &x : a)

//popular constants
const int mod = 1e9 + 7; //998244353;
const ll inf = 1e18;
const ld pie = acos((ld) - 1);

//grid problems
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//modulo operations
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

#ifdef SGUPTA_2001
#define deb(x) cerr<< #x <<" "; __print(x); cerr<<'\n';
#else
#define deb(x);
#endif

//debug containers
template<class T> void __print(T x) {cerr<<x;}
template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";}
template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; }
template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";}
template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";}
template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<typename... T> void read(T&... args) { ((cin>>args),...);}
template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';}

void solve() {

	int N;
	scanf("%d", &N);

	vector<int> arr(N);

	rep(i, 0, N) scanf("%d", &arr[i]);

	unordered_map<int, vector<int>> cur;

	rep(i, 0, N) {
		cur[arr[i]].pb(i);
	}

	ll ans = 0;
	int foo = 1;

	rep(i, 0, N) {

		int idx = upper_bound(all(cur[arr[i]]), i) - cur[arr[i]].begin();
		deb(idx);

		ans += N - (cur[arr[i]].size() - idx) - foo;
		deb(ans);
		foo++;
	}

	printf("%lld\n", ans);

	return;
}

int main() {

	#ifdef SGUPTA_2001
		freopen("input.txt", "r", stdin);
		freopen("/home/shivansh/Desktop/error.txt", "w", stderr);
	#endif

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

	int t;
	t=1;
	while(t--) solve();

  auto stop = std::chrono::high_resolution_clock::now();
  auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
  // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< '\n';

	 /*
	 		STUFF TO LOOK:
			1. Check the constraints
			2. Corner cases(n == 0 || n == 1)
			3. Variables in loops
			4. Make sure two ints aren’t multiplied to get a long long
	*/

	return 0;
}

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

#include<cmath>
#include<algorithm>

int main()
{
    long long int n,i;
    cin>>n;

    long long int a[n];

    for(i=0;i<n;i=i+1)
    {
        cin>>a[i];
    }

    sort(a,a+n);

    long long int sum=0;

    for(i=0;i<n;i=i+1)
    {
        sum=sum+n-(upper_bound(a,a+n,a[i])-a);
    }

    cout<<sum<<endl;

}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int main(){
    int N; cin >> N;
    vector<vector<ll>> edge(N), weight(N);
    for(int i=1; i<N; i++){
        ll u,v,w; cin >> u >> v >> w;
        edge[--u].push_back(--v);
        edge[v].push_back(u);
        weight[u].push_back(w);
        weight[v].push_back(w);
    }
    vector<ll> dist(N,-1);
    std::queue<int> que;
    que.push(0);
    dist[0] = 0;
    while(!que.empty()){
        int now = que.front(); que.pop();
        for(int i=0; i<edge[now].size(); i++){
            int next = edge[now][i];
            ll sum = dist[now]^weight[now][i];
            if(dist[next] == -1){
                dist[next] = sum;
                que.push(next);
            }
        }
    }
    ll ans = 0;
    for(int i=0; i<60; i++){
        vector<int> cnt(2);
        for(int j=0; j<N; j++) cnt[dist[j]>>i&1]++;
        ans += (1ll<<i)%mod*cnt[0]%mod*cnt[1];
        ans %= mod;
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf 1e18

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll test=1;
    cin>>test;
    while(test--)
    {
        ll n,a,b;

        cin>>n>>a>>b;

        if(a+b>n)
        {
            cout<<0<<endl;
            continue;
        }

        ll x,y;

        x=n-a+1;
        y=n-b+1;

        ll ans=(x*x)%MOD;
        ans*=(y*y)%MOD;

        ans%=MOD;

        ll no=(x*y)%MOD;

        ll g=((n-a-b+1)*(n-a-b+2))%MOD;

        no-=g;
        no+=MOD;
        no%=MOD;

        no*=no;
        no%=MOD;

        ans-=no;
        ans+=MOD;
        ans%=MOD;

        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define mod 1000000007

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int t;cin >> t;
	while(t--){
		ll l,r,count;
		cin >> l >> r;
		if(r/2<l)count =0;
		else count = r-l-l+1;
		cout << count*(count+1)/2 << '\n';
		}
}

#include<bits/stdc++.h>
using namespace std;
namespace hyy {
	#define DEBUG 1
	#define isdigit(x) (x >= '0' && x <= '9')
  const int MAXSIZE = (1 << 20);
  inline char gc() {
		#if DEBUG
    return getchar();
		#endif
    static char buf[MAXSIZE];
		static char *p1 = buf + MAXSIZE;
		static char *p2 = buf + MAXSIZE;
    if(p1 == p2) {
      p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
		}
		if(p1 == p2) {
			return -1;
		}
		return *p1++;
  }
	inline bool blank(char ch) {
    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
  }
  template<class T> inline void read(T &x) {
    register double tmp = 1;
    register bool sign = 0;
    x = 0;
    register char ch = gc();
    for(; !isdigit(ch); ch = gc()) {
      if(ch == '-') {
        sign = 1;
			}
		}
    for(; isdigit(ch); ch = gc()) {
    	x = (x << 1) + (x << 3) + (ch ^ 48);
		}
    if(ch == '.') {
      for(ch = gc(); isdigit(ch); ch = gc()) {
        tmp /= 10.0;
				x += tmp * (ch - 48);
			}
		}
    if(sign) {
      x = -x;
		}
  }
  inline void read(char *s) {
    register char ch = gc();
    for(; blank(ch); ch = gc());
	  for(; !blank(ch); ch = gc()) {
    	*s++=ch;
		}
    *s = 0;
  }
  inline void read(char &c) {
    for(c = gc(); blank(c); c = gc());
  }
  inline void push(const char &c) {
    char pbuf[MAXSIZE];
		char *pp = pbuf;
    if (pp - pbuf == MAXSIZE) {
      fwrite(pbuf, 1, MAXSIZE, stdout);
			pp = pbuf;
		}
  	*pp++=c;
  }
  template<class T> inline void write(T x) {
    static T sta[35];
    T top=0;
    do {
      sta[top++] = x % 10;
			x /= 10;
    }
		while(x);
		#if DEBUG
  	while(top) {
      putchar(sta[--top] + '0');
		}
    return;
		#endif
    while(top) {
      push(sta[--top] + '0');
		}
  }
  template<class T> inline void write(T x, char lastChar) {
    write(x);
		putchar(lastChar);
  }
}
using namespace hyy;
#define MAXN 200005

int lowbit(int x) {
	return x & (-x);
}
int n,sum[MAXN];
void Add(int x,int w) {
	for(;x<=n;sum[x]+=w,x+=lowbit(x));
}
int Sum(int x) {
	int ans=0;
	for(;x;ans+=sum[x],x-=lowbit(x));
	return ans;
}
struct Edge {
	int next,to;
}E[MAXN<<1];
int head[MAXN],cnt;
void AddE(int x,int y) {
	E[++cnt].next=head[x],E[cnt].to=y,head[x]=cnt;
}
int Q,fa[MAXN],ans[MAXN],dep[MAXN];
struct Qry {
	int y,id;
}p;
vector<Qry>q[MAXN];
void dfs(int x,int fa) {
	dep[x]=dep[fa]+1;
	for(int i=0;i<q[x].size();++i) {
		ans[q[x][i].id]-=Sum(q[x][i].y)-Sum(q[x][i].y-1);
	}
	for(int i=head[x];i;i=E[i].next) {
		dfs(E[i].to,x);
	}
	Add(dep[x],1);
	for(int i=0;i<q[x].size();++i) {
		ans[q[x][i].id]+=Sum(q[x][i].y)-Sum(q[x][i].y-1);
	}
}
int main() {
	scanf("%d",&n);
	for(int i=2;i<=n;++i) {
		scanf("%d",&fa[i]),AddE(fa[i],i);
	}
	scanf("%d",&Q);
	for(int i=0,x,y;i<Q;++i) {
		scanf("%d%d",&x,&y),p.y=y+1,p.id=i,q[x].push_back(p);
	}
	dfs(1,0);
	for(int i=0;i<Q;++i) {
		printf("%d\n",ans[i]);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define print(...) cout << " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ]"
#define printv(...) cout << " [" << #__VA_ARGS__ ": "; for (int i = 0; i < (__VA_ARGS__).size(); ++i) cout << (__VA_ARGS__)[i] <<" "; cout << "] "
#define printa(...) cout << " [" << #__VA_ARGS__ ": "; for (int i = 0; i < sizeof((__VA_ARGS__))/sizeof((__VA_ARGS__)[0]); ++i) cout << (__VA_ARGS__)[i] <<" "; cout << "] "

std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist(1,10000000); // distribution in range [1, 6]

int32_t main() {
	cin.tie(NULL);
	cout.precision(10);

	int tt = 1;
	// cin >> tt;

	while (tt--) {
		double a, b;
		cin >> a >> b;

		cout << fixed << a / 100 * b << "\n";
	}

	return 0;
}

#include<bits/stdc++.h>
#define pb           push_back
#define mp           make_pair
#define pf printf
#define ff first
#define ss second
#define sef second.first
#define ses second.second
#define PI 3.14159265 /// tan inverse = atan(value)*(180/PI)

#define ms(a,b)            memset(a, b, sizeof(a))
#define lp(i,a,b) for (int i = a; i <= b; i++)
#define pii                pair <int,int>

#define SL(a)              scanf("%I64d",&a)
#define SLL(a,b)           scanf("%I64d %I64d",&a,&b)
#define PL(x) printf("%I64d\n",(x))
#define PLL(x,y) printf("%I64d %I64d\n",x,y)

#define S(a)              scanf("%d",&a)
#define SS(a,b)           scanf("%d %d",&a,&b)
#define P(x) printf("%d\n",(x))
#define PP(x,y) printf("%d %d\n",x,y)
using namespace std ;
typedef long long ll ;
const int imin = 1e9+100;
const ll maxx = 1e5+10,mod=1e9+7,imax=1e18+10;
int main()
{
   ll a,b,c ;
   cin >> a >> b >> c ;
   if((a*a+b*b)<(c*c))
   {
       cout << "Yes" << endl ;
   }
   else
   {
       cout << "No" << endl;
   }
   return 0 ;
}


#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 int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pqi priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define printdecimal(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define mod (int)(1e9+7)
#define inf LLONG_MAX
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
#define N (int)(2e6+6)

struct segtree
{
	int size;
	vector<int> values;

	void ini(int n)
	{
		size=1;
		while(size<n)
			size*=2;
		values.assign(2*size,1);
	}

	void set(int i,int v,int cur,int lx,int rx)
	{
		if(rx-lx==1)
		{
			values[cur]=v;
			return;
		}
		int m=(lx+rx)/2;
		if(i<m) set(i,v,2*cur+1,lx,m);
		else set(i,v,2*cur+2,m,rx);
		values[cur]=max(values[2*cur+1],values[2*cur+2]);
	}

	void set(int i,int v)
	{
		set(i,v,0,0,size);
	}

	int cal(int v,int cur,int lx,int rx)
	{
		if(values[cur]<v) return -1;
		if(rx-lx==1) return lx;
		int m=(lx+rx)/2;
		int val=cal(v,2*cur+1,lx,m);
		if(val==-1) return cal(v,2*cur+2,m,rx);
		return val;
	}

	int cal(int v)
	{
		return cal(v,0,0,size);
	}
};

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	for(int i=0;i<100;i++){}
	int n,m;
	cin>>n>>m;
	segtree st;
	st.ini(N);
	inp(a,n,0);
	int h[n+1]={0};
	for(int i=0;i<m-1;i++)
		st.set(a[i],0),h[a[i]]++;
	int ans=inf;
	for(int j=m-1,i=0;j<n;j++,i++)
	{
		if(h[a[j]]==0) st.set(a[j],0);
		h[a[j]]++;
		int idx=st.cal(1);
		ans=min(ans,idx);
		h[a[i]]--;
		if(h[a[i]]==0) st.set(a[i],1);
	}
  for(int i=0;i<100;i++){}
	cout<<ans;
	return 0;
}

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

#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define yes(x) ((x) ? "yes" : "no")
#define Yes(x) ((x) ? "Yes" : "No")

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double_t;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 N, M;
    cin >> N >> M;
    vector<i64> A(N);
    for (auto &e : A) cin >> e;

    set<i64> unused;
    for (i64 i = 0; i < N; i++) unused.insert(i);
    vector<i64> usedcnt(N);
    for (i64 i = 0; i < M; i++) usedcnt[A[i]]++, unused.erase(A[i]);

    i64 ans = unused.empty() ? N : *unused.begin();
    for (i64 i = M; i < N; i++) {
        if (++usedcnt[A[i]] == 1) unused.erase(A[i]);
        if (--usedcnt[A[i - M]] == 0) unused.insert(A[i - M]);
        ans = min(ans, *unused.begin());
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
    ll n; cin >> n;
    vector<vector<ll>> c(n,vector<ll>(n,0));
    ll minc = INF;
    REP(i,n)REP(j,n) {
        cin >> c[i][j];
    }
    vector<ll> b(n,0);
    vector<ll> a(n,0);
    REP(i,n) {
        if (i==0) {
            REP(j,n) b[j]=c[i][j];
        }
        else {
            a[i]=c[i][0]-b[0];
            REP(j,n) {
                if (a[i]+b[j]!=c[i][j]) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    ll amin = INF; ll bmin = INF;

    // cout << "test" << endl;
    // REP(i,n) cout << a[i] << " ";
    // cout << endl;
    // REP(i,n) cout << b[i] << " ";
    // cout << endl;

    REP(i,n) amin = min(amin,a[i]);
    REP(i,n) bmin = min(bmin,b[i]);
    if (amin<0 && bmin<0) {
        cout << "No" << endl;
        return 0;
    }
    if (amin<0) {
        if (bmin+amin<0) {
            cout << "No" << endl;
            return 0;
        }
        else {
            ll add = 0-amin;
            REP(i,n) {
                a[i]+=add;
                b[i]-=add;
            }
        }
    }
    if (bmin<0) {
        if (bmin+amin<0) {
            cout << "No" << endl;
            return 0;
        }
        else {
            ll add = 0-bmin;
            REP(i,n) {
                a[i]-=add;
                b[i]+=add;
            }
        }
    }
    cout << "Yes" << endl;
    REP(i,n) cout << a[i] << " ";
    cout << endl;
    REP(i,n) cout << b[i] << " ";
    cout << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <typename T> inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a;}
template <typename T> inline T lcm(T a, T b) { return ((a/gcd(a,b))*b);}
#define all(x) (x).begin(),(x).end()
#define sort(x) sort(x.begin(),x.end())
#define maxin(x) *max_element(x.begin(),x.end())
#define minin(x) *min_element(x.begin(),x.end())
#define lint long long int
#define nl '\n'
#define INF (lint)1e18
#define MOD (lint)998244353
void solve(){
       lint n;
       cin>>n;
       vector<lint> arr(n);
       for(auto &a: arr) cin>>a;
       sort(arr);
       lint ans = arr[n-1]*arr[n-1];
       lint t = arr[n-1];
       for(lint i=n-2;i>=0;i--){
           ans+=(arr[i]*arr[i])%MOD;
           ans=(ans+t*arr[i])%MOD;
           t=(2*t+arr[i])%MOD;
       }
       cout<<ans%MOD;
}
int main()
{       ios_base::sync_with_stdio(0);cin.tie(0);lint testnum=1,totalnum=1;
        //cin>>totalnum;
        for(testnum=1;testnum<=totalnum;++testnum){
                //cout<<"Case #"<<testnum<<": ";
                solve();
                cout<<nl;
        }
return 0;}

/*
        created on: 01.04.2021

*/


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

int solve(int n)
{
    int cnt=0;

    vector<bool>arr(n+1);
    for(int i=7; i<=n; i++)
    {
        int temp=i;
        while(temp>0)
        {
            if(temp%10==7)
            {
                arr[i]=true;
                break;
            }
            temp/=10;
        }
    }

    for(int i=7; i<=n; i++)
    {
        int dig = 1;
        int num = 0;

        int l=i;
        while(l>0)
        {
            int x = l%8;
            num += x*dig;
            dig*=10;
            l/=8;
        }
        int temp=num;
        while(temp>0)
        {
            if(temp%10==7)
            {
                arr[i]=true;
                break;
            }
            temp/=10;
        }
    }

    for(int i=7; i<=n; i++)
    {
        if(arr[i])
            cnt++;
    }
    return n-cnt;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //int t;cin>>t;
    //while(t--)
    {
        int n;
        cin>>n;
        cout<<solve(n)<<endl;
    }
    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <random>
#include <fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
#define mod 256
double eps = 1e-12;
#define fors(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define iterate(x) for (auto itr = x.begin(); itr != x.end(); ++itr)
ll myceil(ll a, ll b)
{
    if (a % b == 0)
        return a / b;
    else
        return a / b + 1;
}
vector<ll> vec;
bool isPerSquare(long double a)
{
    if (a < 0)
        return false;
    ll sr = sqrt(a);
    return (sr * sr == a);
}
ll power(long long x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
unsigned int reverseBits(unsigned int n)
{
    unsigned int rev = 0;
    while (n > 0)
    {
        rev <<= 1;
        if (n & 1 == 1)
            rev ^= 1;
        n >>= 1;
    }
    return rev;
}
string decimalToBinary(int n)
{
    string s = bitset<64>(n).to_string();
    const auto loc1 = s.find('1');
    if (loc1 != string::npos)
        return s.substr(loc1);
    return "0";
}
void solve()
{
    double n;
    cin >> n;
    double k = floor((double)(n * (double)(1.08)));
    if (k == 206)
    {
        cout << "so-so";
        return;
    }
    if (k < 206)
    {
        cout << "Yay!";
        return;
    }
    cout << ":(";
}
int main()
{
    solve();
    // ll t;
    // cin >> t;
    // for (ll i = 1; i <= t; i++)
    // {
    //     solve();
    // }
}


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

#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
#define PI 3.14159265359
const long long INF = 1LL << 60;
long long MOD = 1000000007;
long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a; }
long long lcm (int a, int b){return  (long long) a*b /gcd(a,b);}

int main(){
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int r = abs(r2-r1), c = abs(c2-c1);
    int ans = 3;
    if( r == 0 && c == 0)ans = 0;
    else if( r == c || r + c <=3 )ans = 1;
    else if ((r + c)% 2 == 0 || r + c <= 6 || abs(r-c) <= 3)ans = 2;
    cout << ans << endl;

}

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW cout << "meowwwww" << '\n'; system("pause");
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
	s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
	return s;
}

template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
	s << "[ "; cout << c.fi << " , " << c.se << " ] ";
	return s;
}

int n;

void input()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
}

void solve()
{
	vi p1, p2, p3, p4, ans;
	int k = n / 3;
	int cur = 0;
	F1 (i, 10000) while (++cur < 10000)
		if (cur % 5 != 0 && cur * 6 <= 10000)
		{
			p1.pb(cur * 6);
			break;
		}
	cur = 0;
	F1 (i, 10000) while (++cur < 10000)
		if (cur % 2 != 0 && cur * 15 <= 10000)
		{
			p2.pb(cur * 15);
			break;
		}
	cur = 0;
	F1 (i, 10000) while (++cur < 10000)
		if (cur % 3 != 0 && cur * 10 <= 10000)
		{
			p3.pb(cur * 10);
			break;
		}
	cur = 0;
	F1 (i, 10000) while (++cur < 10000)
		if (cur * 30 <= 10000)
		{
			p4.pb(cur * 30);
			break;
		}
	ans.pb(p1[0]);
	ans.pb(p2[0]);
	ans.pb(p3[0]);
	n -= 3;
	F1 (i, p1.size() - 1) if (n) { ans.pb(p1[i]); --n; }
	F1 (i, p2.size() - 1) if (n) { ans.pb(p2[i]); --n; }
	F1 (i, p3.size() - 1) if (n) { ans.pb(p3[i]); --n; }
	F1 (i, p4.size() - 1) if (n) { ans.pb(p4[i]); --n; }
	for (auto x : ans) cout << x << ' ';
	cout << '\n';
}

main()
{
	input();
	solve();
}


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

int main() {
	long long n,m,i,j,k,l,ans,cur,res;
	cin >> n;
	vector<long long> a(n);
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	map<long long,long long> mp;
	cur=0;
	mp[cur]=1;
	ans=0;
	for(i=0; i<n; i++){
		if(i%2==0){
			cur+=a[i];
		}else{
			cur-=a[i];
		}
		ans+=mp[cur];
		mp[cur]=mp[cur]+1;
	}
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<class T> using V = vector<T>;
using VI = V<int>;
using VL = V<ll>;
using VS = V<string>;
template<class T> using PQ = priority_queue<T, V<T>, greater<T>>;
using graph = V<VI>;
template<class T> using w_graph = V<V<pair<int, 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 all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#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;
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, V<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 V<T> vec(size_t a) { return V<T>(a); }
template<class T>inline V<T> defvec(T def, size_t a) { return V<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return V<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return V<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 V<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 V<V<T>>& v) { for (auto& a : v)print(a); }
template<class T>inline T sum(const V<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;
    VL a(n); cin >> a;
    FOR(i, 1, n) {
        if (i & 1)a[i] = a[i - 1] - a[i];
        else a[i] = a[i - 1] + a[i];
    }

    ll ans = 0;
    map<ll, int> m;
    ++m[0];
    FOR(i, 0, n) {
        ans += m[a[i]];
        ++m[a[i]];
    }
    print(ans);

    return 0;
}


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

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))

#define rep(i,n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i,n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i,n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i,n) for (int i = ((int)(n)); i >= 1; i--)
#define repl(i,l,n) for (int i = (l), i##_len = (n); i < i##_len; i++)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define mp make_pair

#define has_key(m, k) (m.find(k) != m.end())

#define INF (1e9)
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const ll mod = (1000000007);

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    long long d;
    scanf("%lld",&d);

    cout << b - c << endl;

    return 0;
}

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

#define MOD 2000000011
#define MAXL 26
#define MAXN 100010
#define MAXT 200
#define MAXM 101
#define PI 3.14159265359
// #define all(v) v.begin(),v.end()
#define f first
#define pb push_back
#define pii pair<int, int>
#define s second
// #define sortva(v) sort(all(v))
// #define sortvd(v) sort(v.rbegin(),v.rend())
// #define sortaa(a,n) sort(a,a+n)
// #define sortad(a,n) sort(a,a+n),reverse(a,a+n)
// #define sfi1(v) scanf("%d",&v)
// #define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
// #define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
// #define sfll1(v) scanf("%I64d",&v);
// #define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
// #define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
// #define sfstr(v) scanf("%s", v);
// #define sz(v) (int)v.size()
#define vi vector<int>
#define X real()
#define Y imag()
typedef double C;
typedef complex<C> P;
typedef long long LL;
typedef unsigned long long uLL;

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

int n;
pair<int, pii> store[MAXN];

int main(int argc, char const *argv[])
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	cin.tie(0);
	ios_base::sync_with_stdio(NULL);

	cin >> n;
	int a, p, x;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> p >> x;
		store[i] = {p, {a, x}};
	}
	sort(store, store + n);
	for (int i = 0; i < n; ++i)
	{
		if (store[i].s.f < 0.5 + (double)store[i].s.s - 1)
		{
			printf("%d\n", store[i].f);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}


#include <bits/stdc++.h>

#define MN 1001000

using namespace std;
typedef long long ll;

ll t, n, a[MN], med;
//char s[MN]; string str;
double ans;

int main() {
    scanf("%lld", &n);

    for(int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        ans += a[i] / 2.0;
    }
    sort(a, a + n);
    med = a[n/2];
    for(int i = 0; i < n; i++) {
        ans += abs(a[i] - med) / 2.0;
    }

    printf("%.9f\n", ans / n);
    return 0;
}

#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <iostream>
#include <fstream>
#include <chrono>

using namespace std;

void solve(int test, std::istream &in) {
    int64_t n;
    in >> n;
    int64_t n0 = n;
    vector<int64_t> f(2, 1);
    while (f.back() < n)
        f.push_back(f.back() + f[f.size() - 2]);
    vector<int> num;
    int idx = f.size() - 1;
    while (n > 0) {
        while (f[idx] > n)
            idx--;
        n -= f[idx];
        num.push_back(idx);
    }
    vector<int> op;
    idx = 0;
    int plus = 0, wait = 0, nextPlus = (num[0] + 1) & 1;
    int64_t x[2] = { 0, 0 };
    while (x[0] != n0) {
        if (wait > 0) {
            plus++;
            op.push_back(3 + nextPlus);
            x[nextPlus] += x[1 - nextPlus];
            nextPlus = 1 - nextPlus;
            wait--;
        }
        else {
            op.push_back(1 + 1 - nextPlus);
            x[1 - nextPlus]++;
            idx++;
            if (idx >= num.size()) {
                wait = num[0];
            }
            else {
                wait = num[idx - 1] - num[idx];
            }
        }
    }
    printf("%d\n", (int)op.size());
    for (int i = 0; i < op.size(); i++)
        printf("%d\n", op[i]);
    //printf("x = %lld, y = %lld\n", x[0], x[1]);
}

int main(int argc, char *argv[]) {
#ifdef VLAD_LOCAL
    ifstream in("in.txt");
    auto start = std::chrono::steady_clock::now();
#else
    istream &in = cin;
#endif
    solve(0, in);
#ifdef VLAD_LOCAL
    auto end = std::chrono::steady_clock::now();
    double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
    printf("%.3lf seconds\n", seconds);
#endif
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
//#define MOD 998244353LL
#define doublecout(a) cout<<setprecision(16)<<a<<endl;
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL;
const ll llMIN=-9223372036854775808LL;

void myprint1D(vi &data)
{
  REP(i,data.size())
    cout<<data[i]<<" ";
  cout<<endl;
}

//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
  REP(i,data.size())
    myprint1D(data[i]);
}

//配列を[x][y]で表示
void myprint2D(vvi &data)
{
  ll l1=data.size();
  ll l2=data[0].size();
  REP(j,l2){
    REP(i,l1)
      cout<<data[i][j]<<" ";
    cout<<endl;
  }
}

//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}

//moddivとnCkとgarner
//c剰余下でaをbで割った値
ll moddiv(ll a,ll b,ll c){
	ll x0=c,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans;
	if (t==0LL) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=(n0-m*n1)%c;
      if (x2==1LL){
        ans=(n2+c)%c;
        break;
      }
      x0=x1;x1=x2;
      n0=n1;n1=n2;
    }
	return (a+((t*ans)%c)*b-t)/b;
}
//剰余の割ざん

//aのn乗 mod c
ll expmod(ll a,ll n,ll c){
  ll ans=1LL,aa=a,beki=n;
  for(int i=0;i<64;i++){
    if (beki%2==1LL) ans=ans*aa%c;
    aa=aa*aa%c;
    beki/=2LL;
    if (beki==0LL)break;
  }
  return ans;
}

//nCk
vi mulmod(500001);//0!,1!,2!,3!,4!,,,,
void first_nCk(){
  mulmod[0]=1LL;
  for(ll i=1;i<500001;i++){
    mulmod[i]=mulmod[i-1]*i%MOD;
  }
}
ll nCk(ll nn,ll kk){
  return moddiv(mulmod[nn],mulmod[kk]*mulmod[nn-kk]%MOD,MOD);
}
ll modinv(ll a,ll b){
  return moddiv(1,a%b,b);
}
//条件gcd(a,b)==1,ar<a,br<b
ll garner(__int128_t a,__int128_t b,__int128_t ar,__int128_t br){
  __int128_t tmp=(br-ar)%b*modinv(a,b)%b;
  if (tmp<0)tmp+=b;
  return ar+tmp*a;
}
ll gcd(ll a,ll b){
  ll r = a % b;
  while(r!=0LL){
    a = b;
    b = r;
    r = a % b;
  }
return b;
}

ll t,x,y,p,q;

int main(){
  ll ans=0;
  ll t=0;
  cin>>t;
  for(ll ttt=0;ttt<t;ttt++){
    cin >> x >> y>>p>>q;
    ll xy=x*2+y*2;
    ll pq=p+q;
    ans=llMAX;

/*
    ll t=gcd(max(x-p,p-x),gcd(xy,pq));
        if (t>=y+q){
          cout<<"infinity"<<endl;
          continue;
        }
        */

    for(ll i=0;i<y;i++){
      for(ll j=0;j<q;j++){
        ll tttt=max(x+i-(p+j),(p+j)-(x+i));
        ll gd=gcd(xy,pq);
        if (tttt%gd!=0)continue;

        if (gd!=1){

          if (x+i-(p+j)>0){
            ll g;
            if ((xy/gd==1)|(pq/gd==1)){
              g=(x+i-(p+j))/gd;
            }else{
              g=garner(xy/gd,pq/gd,(x+i-(p+j))/gd,0);
            }
            g=g*gd;
            g+=(p+j);
            ans=min(ans,g);
          }else{
            ll g;
            if ((xy/gd==1)|(pq/gd==1)){
              g=((p+j)-(x+i))/gd;
            }else{
              g=garner(xy/gd,pq/gd,0,((p+j)-(x+i))/gd);
            }
            g=g*gd;
            g+=(x+i);
            ans=min(ans,g);
          }

        }else{

          ll g=garner(xy,pq,x+i,p+j);
          ans=min(ans,g);
        }

      }
    }

    if (ans==llMAX){

          cout<<"infinity"<<endl;
          continue;
    }
    cout<<ans<<endl;
  }
  return 0;
}

/*
298 2 98 102
*/

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define IFOR(i, a, b) for (long long i = (a); i <= (long long)(b); i++)
using namespace std;
using VL = vector<long long>;
using ll = int64_t;
ll mod(ll x,ll m){ll y=x%m;return (y>=0LL)?y:y+m;}
template<class T>bool chmin(T& a, T b){if(a>b){a=b;return true;}else return false;}
ll gcd(ll a,ll b,ll& x,ll& y)
{if(a){ll d=gcd(b%a,a,x,y);y-=(b/a)*x;swap(x,y);if(d<0LL){d=-d;x=-x;y=-y;}return d;}else{x=0;y=1;return b;}}

int main(){
    int T;
    cin>>T;
    string ans = "";
    REP(i,T){
        ll t = LLONG_MAX;
        ll X,Y,P,Q;
        scanf("%lld %lld %lld %lld",&X,&Y,&P,&Q);
        ll a=(X+Y)<<1, b=P+Q;
        ll x, y;
        ll d = gcd(a, -b, x, y);
        ll u = b/d, v = a/d;
        ll stop0=P-X, stop1=P-X+Q-1LL;
        ll wake0=P-X-Y+1LL, wake1=P-X;
        ll from=min(stop0, wake0), to=max(stop1, wake1);
        IFOR(z, from, to){
            if(mod(z,d)!=0LL)continue;
            if(stop0<=z && z<=stop1){
                chmin(t,a*mod(z/d*x,u)+X);
            }else{
                chmin(t, b*mod(z/d*y,v)+P);
            }
        }
        ans += (t==LLONG_MAX ? "infinity" : (to_string(t)))+"\n";
    }

    cout << ans;

    return 0;
}


#include "iostream"
using namespace std;
//#include "string"
#include "vector"
#include "set"
#include "map"
#include "stack"
#include "algorithm"
#include "queue"
#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;
	vi a(n);
	for(int &i : a)
		cin >> i;
	set<pi> s;
	for(int i = 0; i <= n; i++)
		s.insert(make_pair(0, i));
	vi f(n + 1, 0);
	int ans = n;
	for(int i = 0; i < n; i++) {
		s.erase(make_pair(f[a[i]], a[i]));
		f[a[i]]++;
		s.insert(make_pair(f[a[i]], a[i]));

		if(i >= m - 1) {
			ans = min(ans, s.begin() -> ss);
			s.erase(make_pair(f[a[i - m + 1]], a[i - m + 1]));
			f[a[i - m + 1]]--;
			s.insert(make_pair(f[a[i - m + 1]], a[i - m + 1]));
		}
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;

int main() {
    int N,M; cin>>N>>M;
    vvi pos(N, {-1});
    for (int i = 0; i < N; i++){
        int A; cin>>A;
        pos[A].push_back(i);
    }
    for (int i = 0; i < N; i++)pos[i].push_back(N);

    for (int i = 0; i < N; i++){
        for (int j = 0; j < pos[i].size()-1; j++){
            if(pos[i][j+1]-pos[i][j]-1>=M){
                cout<<i<<endl;
                return 0;
            }
        }
    }
    cout<<N<<endl;
}


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

int main(){
  int n,a,b;
  double grad;
  int cnt = 0;
  cin >> n;
  vector<double> x,y;
  rep(i,n){
    scanf("%d", &a);
    scanf("%d", &b);
    x.push_back(double(a));
    y.push_back(double(b));
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      grad = (y[i]-y[j])/(x[i]-x[j]);
      if(-1 <= grad && grad <= 1){\
        cnt++;
    }
    }
  }
  cout << cnt << "\n";
}

// C++ program to count number of ways to express
// N as sum of consecutive numbers.
#include <bits/stdc++.h>
using namespace std;

long long int countConsecutive(long long int N)
{
  // constraint on values of L gives us the
  // time Complexity as O(N^0.5)
  long long int count = 0;
  for (long long int L = 1; L * (L + 1) < 2 * N; L++)
  {
    //long long double a = ;
    if ((1.0 * N-(L * (L + 1)) / 2) / (L + 1)-(long long int)((1.0 * N-(L * (L + 1)) / 2) / (L + 1)) == 0.0)
      count++;
  }
  return count;
}

// Driver Code
int main()
{
  long long int N;
  cin>>N;
  cout << 2*countConsecutive(N)+2 << endl;

  return 0;
}


#include <cstdio>
#include <vector>
#include <queue>

const int N = 2000 + 5;

const int d[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

#define toint(ch) ((int)((ch) - 'a' + 1))

char a[N][N];
int n, m;
int stx, sty, edx, edy;

struct Point { int x, y; };
std::vector<Point> tos[30];
std::queue<Point> q;

int dis[N][N];

bool visch[30];

int main() {
	std::scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) {
		std::scanf("%s", a[i] + 1);
		for(int j = 1; j <= m; j++) {
			if('a' <= a[i][j] && a[i][j] <= 'z')
				tos[toint(a[i][j])].push_back({i, j});
			else if(a[i][j] == 'S') stx = i, sty = j;
			else if(a[i][j] == 'G') edx = i, edy = j;
		}
	}
	q.push({stx, sty});
	dis[stx][sty] = 1; // dis[][] is also vis[][]
	while(!q.empty()) {
		int px = q.front().x, py = q.front().y;
		char pc = a[px][py];
		q.pop();
		if('a' <= pc && pc <= 'z' && !visch[toint(pc)]) {
			for(const Point &d : tos[toint(pc)]) {
				int dx = d.x, dy = d.y;
				if(!(1 <= dx && dx <= n && 1 <= dy && dy <= m && a[dx][dy] != '#' && !dis[dx][dy])) continue;
				dis[dx][dy] = dis[px][py] + 1;
				q.push({dx, dy});
			}
			visch[toint(pc)] = true;
		}
		for(int i = 0; i < 4; i++) {
			int dx = px + d[i][0], dy = py + d[i][1];
			if(!(1 <= dx && dx <= n && 1 <= dy && dy <= m && a[dx][dy] != '#' && !dis[dx][dy])) continue;
			dis[dx][dy] = dis[px][py] + 1;
			q.push({dx, dy});
		}
	}
	// for(int i = 1; i <= n; i++)
	// 	for(int j = 1; j <= m; j++)
	// 		std::printf("%2d%c", dis[i][j] - 1, j == m ? '\n' : ' ');
	std::printf("%d\n", (dis[edx][edy] == 0 ? -1 : dis[edx][edy] - 1));
	return 0;
}

#include<iostream>
#include<vector>
#include<deque>
using namespace std;

template<typename T>class Graph{
    public:
    struct edge{int to;T cost;};
    int Vertex_num,Edge_num;
    vector<edge>*g;

    const T INF=1000000000;

    Graph(int V){//0～V-1
        Vertex_num=V;
        g=new vector<edge>[V];
    }

    Graph(int V,int E){//0～V-1
        Vertex_num=V;
        Edge_num=E;
        g=new vector<edge>[V];
    }

    void emplace_back(int from,int to,T cost){
        edge e={to,cost};
        g[from].push_back(e);
        //edges->push_back(e);//for Bellman-Ford
    }

    void input(bool direct,bool weight){
        int from,to;
        T cost;
        for(int i=0;i<Edge_num;i++){
            cin>>from>>to;
            from--,to--;
            if(weight)cin>>cost;
            else cost=1;
            this->emplace_back(from,to,cost);
            if(!direct)this->emplace_back(to,from,cost);
        }
    }

    void check(){
        for(int i=0;i<Vertex_num;i++){
            cout<<"Vertex "<<i<<endl;
            for(auto x:g[i])cout<<x.to<<" "<<x.cost<<endl;
        }
    }
};

template<typename T>vector<T>bfs(Graph<T>graph,int start){
    vector<T>dist(graph.Vertex_num,-1);//訪問:startからの距離 未訪問:-1
    deque<int>q;
    q.push_front(start);
    dist[start]=0;
    while(!q.empty()){
        int p=q.front();q.pop_front();
        for(auto x:graph.g[p])if(dist[x.to]==-1){
            dist[x.to]=dist[p]+x.cost;
            if(x.cost)q.push_back(x.to);
            else q.push_front(x.to);
        }
        //visited[]の更新はpushするときにやらないとqueueがあふれる↑
    }
    return dist;
}

int H,W,S,G;
int main(){
    cin>>H>>W;
    char a[H][W];
    for(int i=0;i<H*W;i++)cin>>a[i/W][i%W];

    int d4[5]={1,0,-1,0,1};
    Graph<int>g(H*W+26);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(a[i][j]=='#')continue;
            if(a[i][j]=='S')S=i*W+j;
            if(a[i][j]=='G')G=i*W+j;
            if('a'<=a[i][j]&&a[i][j]<='z'){
                g.emplace_back(i*W+j,H*W+a[i][j]-'a',1);
                g.emplace_back(H*W+a[i][j]-'a',i*W+j,0);
                g.Edge_num+=2;
            }
            for(int k=0;k<4;k++){
                int x=i+d4[k],y=j+d4[k+1];
                if (x<0||x>=H||y<0||y>=W||a[x][y]=='#')continue;
                g.emplace_back(i*W+j,x*W+y,1);
                g.Edge_num++;
            }
        }
    }
    auto d=bfs(g,S);
    cout<<d[G]<<endl;
    return 0;
}


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

#define endl "\n"
#define LL long long
#define ULL unsigned long long
const LL        INF = 1LL<<62;
const double    PI = 2.0 * acos(0.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

////// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//
/////cout<<*X.find_by_order(1)<<endl;
/////cout<<X.order_of_key(-5)<<endl;
//
//typedef tree<
//LL,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ        freopen("in.txt","r",stdin)
#define WRITE       freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define sqr(x)      ( (x) * (x) )
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define deb(x)      cerr<<#x<<" :: "<<x<<"\n"
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),( (b+e) /2 )
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
int X[4]={0,0,-1,1};
int Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int BX[8]={0,0,1,-1,-1,1,1,-1};
//int BY[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

// Bit Operations
#define popcountL   __builtin_popcountll
#define popcount    __builtin_popcount
inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){ return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

inline LL modMul(LL a, LL b,LL mod){
    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
inline LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}
inline LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return ((a/g) * b);
}

//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2234567;

long double P[mx];
void solve(){
    int n;
    cin>>n;
    P[1] = 0.0;
    for(int i=2;i<=n;i++){
        long double cur = (long double)(1.0*n) / (long double)(n-i+1);
        P[i] = P[i-1] + cur;
    }

    cout<<fixed<<setprecision(12);
    cout<<P[n]<<endl;
}

int main(){

    BOOST;
    #ifdef MujahidPC
        double start = clock();
//        READ;
//        WRITE;
    #endif
    int t;
    t = 1;
//    cin>>t;
    while(t--)solve();

    #ifdef MujahidPC
        double tim = (clock() - start)/CLOCKS_PER_SEC;
        cerr<<"Running Time : "<<tim<<" \n";
    #endif
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s^=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]^=v,e+=e&-e;}
};
BIT<int,20> bt;

int N,Q;

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N>>Q;
	FOR(i,N) {
		cin>>x;
		bt.add(i+1,x);
	}
	while(Q--) {
		cin>>i>>x>>y;
		if(i==1) {
			bt.add(x,y);
		}
		else {
			cout<<(bt(y)^bt(x-1))<<endl;
		}
	}
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;

int main(void){
	scanf("%d",&n);
	printf("%d\n",n-1);
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,nr;
ll f[1001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    ll rest=n%3;
    if(rest==0)
    {
        cout<<0;
        return 0;
    }
    while(n)
    {
        ll cif=n%10;
        f[cif%3]++;
        n/=10;
        nr++;
    }
    if(rest==1)
    {
        if(f[1]>=1&&nr>1)
        {
            cout<<1;
            return 0;
        }
        else if(f[2]>=2&&nr>2)
        {
            cout<<2;
            return 0;
        }
        else
        {
            cout<<-1;
            return 0;
        }
    }
    if(rest==2)
    {
        if(f[2]>=1&&nr>1)
        {
            cout<<1;
            return 0;
        }
        else if(f[1]>=2&&nr>2)
        {
            cout<<2;
            return 0;
        }
        else
        {
            cout<<-1;
            return 0;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define PLL pair<ll,ll>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vll (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define pu push
#define sz(x) int(x.size())
#define vij v[i][j]
ll p = 1e9+7;
// ll p = 998244353;
// n do -> n*pi/180
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

ll f(ll x,ll n){
  if(n==0)return 1;
  if(n==1)return x;
  if(n%2)return x*f(x,n-1)%p;
  ll r=f(x,n/2);
  return r*r%p;
}

int main(){
  cci(n,k);

  ll ans=(k-1)*f(k-2,n-1)%p;
  co(ans);
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(ll i=(ll)(n); i<=(ll)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

//-------------------------------------------------

const __int128_t geta = (__int128_t)100000000000LL * 100000000000LL;

int main(void)
{
    string Xs,Ys,Rs; cin>>Xs>>Ys>>Rs;
    __int128_t X,Y,R;
    {
        bool flg=false;
        ll m=10000;
        string tmp;
        for(auto c:Xs){
            if (flg) m/=10;
            if (c!='.') tmp.pb(c);
            if (c=='.') flg=true;
        }
        X = stoll(tmp)*m;
    }
    {
        bool flg=false;
        ll m=10000;
        string tmp;
        for(auto c:Ys){
            if (flg) m/=10;
            if (c!='.') tmp.pb(c);
            if (c=='.') flg=true;
        }
        Y = stoll(tmp)*m;
    }
    {
        bool flg=false;
        ll m=10000;
        string tmp;
        for(auto c:Rs){
            if (flg) m/=10;
            if (c!='.') tmp.pb(c);
            if (c=='.') flg=true;
        }
        R = stoll(tmp)*m;
    }

    ll ans=0LL;
    __int128_t xl = (X-R)/10000LL - 10;
    __int128_t xr = (X+R)/10000LL + 10;

    FOR(i,xl,xr){
        __int128_t x = (__int128_t)10000LL * i;
        if (x<X-R || X+R<x) continue;
        __int128_t top,bottom;
        {
            __int128_t lo=Y, hi=Y+R+100;
            while(hi-lo>1){
                __int128_t c = (lo+hi)/2;
                __int128_t dx = x-X;
                __int128_t dy = c-Y;
                if (dx*dx+dy*dy<=R*R){
                    lo = c;
                }else{
                    hi = c;
                }
            }
            top = lo;
        }
        {
            __int128_t lo=Y-R-100, hi=Y;
            while(hi-lo>1){
                __int128_t c = (lo+hi)/2;
                __int128_t dx = x-X;
                __int128_t dy = c-Y;
                if (dx*dx+dy*dy<=R*R){
                    hi = c;
                }else{
                    lo = c;
                }
            }
            bottom = hi;
        }

        top += geta;
        bottom += geta;
        ans += (ll)(top/10000LL - (bottom-1)/10000LL);
    }
    cout<<ans<<"\n";
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<deque>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<string>
#include<chrono>
#include<random>
#include<unordered_map>
#include<ctype.h>
#include<cassert>
using namespace std;
typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef unsigned long long ull; typedef long double ldb; typedef vector<long long> vll; typedef vector<int> vi; typedef pair<ll, ldb>pllldb; typedef double db;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
const double Pi = acos(-1.0); const int inf = 0x3f3f3f3f, Mod = 1e9 + 7, N = 2e3+1;
ll qpow(ll a, ll b, ll mod = Mod)
{
	ll ans = 1;
	while (b)
	{
		if (b & 1)ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
bool cmp(pii a, pii b)
{
	return a.second - a.first > b.second - b.first;
}

/*----------------------------------------------------------------------Code follows-----------------------------------------------------------------------*/
/*----------------------------------------------------------------------Code follows-----------------------------------------------------------------------*/
ldb x, y, r;ll ans;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
	cin >> x >> y >> r;
	r = nextafter(r, INFINITY);
	for (int i = ceil(x - r); i <= floor(x + r); i++)
	{
		ldb t = sqrt(pow(r, 2) - pow(i - x,2));
		ans += floor(y + t) - ceil(y - t) + 1;
	}
	cout << ans << '\n';
}
/*

*/


#include<stdio.h>
int main()
{
int x;
scanf("%d",&x);
if (x>=0)
{ printf("%d",x);}
if (x<0)
{printf("0");}
return 0;
}

#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define uni(x) (x).erase(unique(x.begin(),x.end()),x.end())
typedef long long lint;
using namespace std;
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; }
const long long INF = 1LL << 60;
using Graph=vector<vector<int>>;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

vector<lint> divisor(lint n){
  vector<lint> ret;
  for(lint i=1;i*i<=n;i++){
    if(n%i==0){
      ret.pb(i);
      if(i*i!=n) ret.pb(n/i);
    }
  }
  sort(all(ret));
  return ret;
}

int main(){
  int n;
  cin>>n;
  if(n>=0) cout<<n;
  else cout<<"0";
}


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

int main() {
  int64_t C, M, T;
  cin >> C >> M >> T;

  int64_t time = 0;
  int64_t cap = C;
  for (int i = 0; i < M; ++i) {
    int64_t start, end;
    cin >> start >> end;

    cap -= (start - time);
    if (cap <= 0) {
      cout << "No" << endl;
      return 0;
    }

    cap += (end - start);
    cap = min(cap, C);

    time = end;
  }
  cap -= (T - time);
  if (cap <= 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

#include<iostream>
#include<cstring>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long LL;
const int N=3e3+10;
struct Node{
	int x,v;
	bool operator<(const Node& a)const{
		return x<a.x;
	}
}node[N<<1];
int main(){
	int n,m,t;
	cin>>n>>m>>t;
	int cnt=0;
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		node[++cnt]={x,2};
		node[++cnt]={y,-2};
	}
	node[++cnt]={0,0};
	node[++cnt]={t,0};
	sort(node+1,node+1+cnt);
	int res=-1,ans=n;
	for(int i=1;i<=cnt;i++){
		res+=node[i].v;
		if(node[i].x!=node[i+1].x){
			ans+=(node[i+1].x-node[i].x)*res;
			ans=min(n,ans);
			if(ans<=0)return puts("No"),0;
		}
	}
	return puts("Yes"),0;

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif

const int MAX_N = 300010;

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);

	ll N;
	cin >> N;
	ll res = N;

	for (int b = 0;1ll << b <= N;++b) {
		ll c = N % (1ll<<b);
		ll a = N / (1ll<<b);
		chmin(res, a + b + c);
	}
	cout << res << '\n';
}

//================code===================//

//#define TLE

#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long

#define ld double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp tuple<LL,LL,LL>
#define setl pair<LL,LL>
#define micro 0.000001

using namespace std;

LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }

#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl;
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#else
#define AT
#define AE
#define ce(t)
#endif

pair <int, int> vu[9] = { {0,-1},{1,0},{0,1} ,{-1,0},{0,0},{1,1}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN

template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl& a, setl& b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl& a, setl& b) { return a.second > b.second; } };

const int max_v = 2e5+ 7;
const int max_k = 1e1 + 7;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
LL mod = 998244353;
template<typename T, typename U> void MOD(T& a, U b) { a += b; if (a >= mod) a -= mod; }

bool open[max_v],vist[max_v];
vector<int> adj[max_v];
int sn = 0;

void dfs(int u)
{
	open[u] = 1;

	for (auto& v : adj[u]) if (!vist[v])
	{
		if (open[v])
		{
			++sn;
			open[0] = 0;
			return;
		}

		dfs(v);
	}

	open[u] = 0;
}

void dfs2(int u)
{
	vist[u] = 1;
	for (auto& v : adj[u]) if (!vist[v])
	{
		dfs2(v);
	}
}

int main()
{
#ifdef OHSOLUTION
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int n; ci(n);

	fa(i, 0, n)
	{
		int x; ci(x), --x;
		adj[i].push_back(x);
	}

	fa(i, 0, n) if (!vist[i]) dfs(i),dfs2(i);

	LL base = 2;
	LL ret = 1;

	while (sn)
	{
		if (sn & 1) ret = ret * base % mod;
		base = base * base % mod;
		sn >>= 1;
	}

	if (ret) --ret;
	else ret = mod - 1;

	co(ret << "\n");

	return 0;
}


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

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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>=n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

const vector<int> dx = {1, 1,  1, 0,  0, 0, -1, -1, -1};
const vector<int> dy = {1, 0, -1, 1, -1, 0,  1,  0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

const int MAX = 1000000;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }

int main(){
  int n;
  ll ans = 0;
  cin >> n;
  rep(i, 0, n){
      ll a, b;
      cin >> a >> b;
      ans += (a+b)*(b-a+1)/2;
  }
  cout << ans << endl;
}

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

int main() {
    int n; cin>>n;
    vector<ll> a(n), ac(n), mx(n);
    rep(i, n) {
        cin >> a[i];
        if(i==0) {
            ac[i]=a[i];
            mx[i]=ac[i];
        }
        else {
            ac[i]+=ac[i-1]+a[i];
            mx[i]=max(mx[i-1], ac[i]);
        }
    }
    ll co=0, comx=0;
    rep(i, n) {
        comx=max(comx, co+mx[i]);
        co += ac[i];
        comx=max(comx, co);
    }
    cout << comx << endl;
}


#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
	int n;
	scanf("%d", &n);
	char s[n+1], t[n+1];
	scanf("%s %s", s, t);

	ll ans = 0;
	int dis = 0;
	while(dis<n && t[dis]!='1') dis++;

	int prev = -1;
	for(int i=0; i<n; i++){
		if(s[i]=='1') {
			if(prev>=0){
				s[prev] = s[i]= '0';
				ans += i-prev;
				prev = -1;
				continue;
			}

			if(dis>i) prev = i;
			else{
				s[i] = '0';
				s[dis] = '1';
				ans += i-dis;
				dis++;
				while(dis<n && t[dis]!='1') dis++;
			}
		}
	}

	bool ok = true;
	for(int i=0; i<n; i++){
		if(s[i]!=t[i]) ok = false;
	}

	if(ok) printf("%ld\n", ans);
	else puts("-1");
	return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

using ll = long long;

const int maxn = 5e5 + 10;
int n;
string s, t;

const int inf = 1e9;

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

    cin>>n;
    cin>>s;
    cin>>t;

    ll ans = 0;

    for (int i=0,j=-1; i<n; i++) {

	if (s[i]!=t[i]) {
	    j=max(j,i+1);
	    while (j<n && s[j]!='1') {
		s[j]='0';
		j++;
	    }

	    if (j==n) out(-1);
	    ans += ll(j-i);
	    s[j]=(1^s[j]);
	    j++;

	    s[i]=(1^s[i]);
	}

	// cout<<i<<": "<<j<<endl;
	// watch(s);
    }

    out(ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// clang-format off
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint = modint998244353

using ll = int64_t;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& a : v) cin >> a;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<pair<T, T>>& v) {
    for (auto& a : v) cin >> a.first >> a.second;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) {
    for (auto& a : v) {
        T a1, a2, a3;
        cin >> a1 >> a2 >> a3;
        a = {a1, a2, a3};
    }
    return is;
}
template<typename T>
istream& operator>>(istream &is, complex<T>& c) {
    double x, y;
    is >> x >> y;
    c.real(x);
    c.imag(y);
    return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
    for (auto& a : v) os << a << " ";
    os << endl;
    return os;
}
template<class T>
bool chmin(T &a, T b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<class T>
bool chmax(T &a, T b) {
    if (a < b) { a = b; return true; }
    return false;
}
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define TRC1(a) cout << #a ":" << a
#define TRC2(a, b) TRC1(a); cout << " "; TRC1(b)
#define TRC3(a, b, c) TRC2(a, b); cout << " "; TRC1(c)
#define TRC4(a, b, c, d) TRC3(a, b, c); cout << " "; TRC1(d)
#define GET_NAME(_1,_2,_3,_4,NAME,...) NAME
#define TRC(...) GET_NAME(__VA_ARGS__, TRC4, TRC3, TRC2, TRC1) (__VA_ARGS__) << endl
using veci = vector<int>;
using vecll = vector<ll>;
using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
const int IINF = INT32_MAX;
const ll LINF = INT64_MAX;

// cout << fixed << setprecision(15);
void solve();
int main() {
    cin.tie(0); ios::sync_with_stdio(0);
    cout << fixed << setprecision(15); solve(); return 0; }
// clang-format on

void solve() {
    int N, M, Q;
    cin >> N >> M >> Q;
    veci W(N), V(N), X(M);
    rep(i, N) cin >> W[i] >> V[i];
    cin >> X;
    rep(qi, Q) {
        int l, r;
        cin >> l >> r;
        --l, --r;
        veci boxes;
        rep(i, M) {
            if (i < l || i > r) boxes.push_back(X[i]);
        }
        sort(all(boxes));
        ll ans = 0;
        vector<bool> used(N);
        for (auto x : boxes) {
            Pi best(-1, -1);
            rep(i, N) {
                if (used[i] || x < W[i]) continue;
                best = max(best, Pi(V[i], i));
            }
            auto [v, i] = best;
            if (i == -1) continue;
            used[i] = true;
            ans += v;
        }
        cout << ans << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n;
	cin >> n;
	int mini = 2e9;
	for(int i=0;i<n;i++){
		int a,b,c;
		cin >> a >> b >> c;
		if(a < c){
			mini = min(mini,b);
		}
	}
	cout << (mini < 2e9 ? mini:-1);
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (int i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using PP = pair<int,int>;
using VP = vector<PP>;
// using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = (1 << 30) - 1;  // 1073741824 - 1
// static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    int N; cin >> N;
    VI P(N+1); FOR(i,1,N+1) cin >> P[i];

    VP memo;

    ll L = 0;
    ll R = 0;
    FOR(i,1,N+1) {
        if (P[i] < i) {
            L += (ll)(i - P[i]);
            memo.push_back(PP(i-1, (i - P[i])));
        } else if (i < P[i]) {
            R += (ll)(P[i] - i);
        }
    }

    if (L != R || L != N-1) {
        COUT(-1); return 0;
    }

    VI ans(N-1);
    int i = 0;
    for (auto p : memo) {
        int x = p.first;
        int n = p.second;
        REP(_,n) {
            ans[i++] = x--;
        }
    }

    VI check(ans);
    SORT(check);
    REP(i,N-1) {
        if (i+1 != check[i]) {
            COUT(-1);
            return 0;
        }
    }

    REP(i,N-1) {
        swap(P[ans[i]], P[ans[i]+1]);
    }
    FOR(i,1,N+1) {
        if (i != P[i]) {
            COUT(-1);
            return 0;
        }
    }

    for (int x : ans) {
        cout << x << '\n';
    }

    return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p.at(i);
  }
  //１～ｎまでの数字がどの位置にあるかを記録します
  vector<int> position(n+1);
  for(int i=0;i<n;i++){
    position.at(p.at(i))=i;
  }
  //動かした順番を記録するようです
  vector<int> ans(n-1,0);
  //どの位置がswapしたか記録するために使います
  vector<bool> ok(n,false);
  int j=0;
  //大きい順に右に持っていきます
  for(int i=n;0<i;i--){
    int b=position.at(i);
    //記録した位置から右に持って行って小さい順に並んだ時の正しい位置になるまで移動させます
    while(p.at(i-1)!=i){
      if(ok.at(b)){
        cout<<-1<<endl;
        return 0;
      }
      //ここから
      if(b+1>=n){
        cout<<-1<<endl;
        return 0;
      }
      //ここまでが無いとＲＥします
      //　whileで弾けてると思ってたんですけど、ダメみたいです
      swap(p.at(b),p.at(b+1));
      //swapした数字の位置を入れ替えます
      position.at(p.at(b+1))--;
      position.at(p.at(b))++;
      //使った場所を記録しておきます
      ans.at(j)=b+1;
      j++;
      ok.at(b)=true;
      b++;
      if(b==n-1)break;
    }
  }
  //全ての場所が使われているかチェックします
  for(int i=0;i<n-1;i++){
    if(ok.at(i)==false){
      cout<<-1<<endl;
      return 0;
    }
  }
  for(int i=0;i<n-1;i++){
    cout<<ans.at(i)<<endl;
  }
}