// どこが間違っているか分からない時は,簡単なミス(型,スペル,入力or出力など)をしていたり問題文の見落としがあったりする. 一度落ち着いて頭をリセットしよう.
// 計算途中のオーバーフローに注意しよう

#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define PP(val, pre) cout<<fixed<<setprecision(pre)<<val<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

// nの約数を全て求める O(√N)
// argument : 約数を求めたい数字
// return   : 約数の昇順ベクター
vector<ll> divisor(ll n){
    vector<ll> result;
    for(ll i=1;i*i <= n;i++){
        if(n%i==0){
            result.push_back(i);
            if((n/i)==i)continue;
            result.push_back(n/i);
        }
    }
    sort(result.begin(), result.end());
    return result;
}

int main(){
    int N;
    cin >> N;
    vector<ll> vec;
    vec.push_back(1);
    REP(i, 2, N+1){
        vector<ll> div = divisor(i);
        div.pop_back();
        ll maxi = 0;
        for(auto d : div){
            maxi = max(maxi, vec[d-1]);
        }
        vec.push_back(maxi+1);
    }

    REP(i, 0, vec.size()){
        if(i!=0) cout << " ";
        cout << vec[i];
    }
    cout << endl;
}

/*..................................
"Be not afraid of GROWING slowly, be afraid only of Standing Still"
....................................*/
#include <bits/stdc++.h>
using namespace std;
# define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define amin(a,b)             a=min(a,b)
#define amax(a,b)             a=max(a,b)
#define space                 " "
#define ain(arr)              for(int i=0;i<n;i++)cin>>arr[i];
#define rep(i,a,b)            for(int i=a;i<b;i++)
#define rrep(i,a,b)           for(int i = a;i>=b;i--)
#define rsort(a)              sort(a.begin(),a.end(),greater<int>())
#define ll                    long long
#define pi                    pair<int,int>
#define pl                    pair<long long,long long>
#define pb                    push_back
#define vi                    vector<int>
#define vl                    vector<long long>
#define vii                   vector<pair<int,int>>
#define maxq(x)               priority_queue<x>
#define minq(x)               priority_queue<x,vector<x>,greater<x>>
#define ppb                   pop_back
#define ppf                   pop_front
#define all(x)                (x).begin(),(x).end()
#define uniq(v)               (v).erase(unique(all(v)),(v).end())
#define sz(x)                 (int)((x).size())
#define pii                   pair<int,int>
#define mem1(a)               memset(a,-1,sizeof(a))
#define mem0(a)               memset(a,0,sizeof(a))
#define ppc                   __builtin_popcount
#define ppcll                 __builtin_popcountll
#define endl                  "\n"
#define MOD 1000000007
#define LINF (1LL<<60)
#define INF 2147483647
#define PI 3.1415926535897932384626433
#define testcase int t;    cin>>t;    while(t--)
bool isvowel(char c) {if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')return true; return false;}
bool prime[5000001];
int spf[5000001];   //contains smallest prime factor of i,  spf[i]=0 means i is prime
vector<int> primes;
void sieve() {memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= 5000000; p++) {if (prime[p] == true) {for (int i = p * p; i <= 5000000; i += p) {prime[i] = false; if (spf[i] == 0)spf[i] = p;}}} for (int p = 2; p <= 5000000; p++)if (prime[p])primes.push_back(p);}
ll gcd(ll a, ll b) {if (b == 0)return a; return gcd(b, a % b);}
ll fast_exp(ll x, ll n) {ll ans = 1; while (n) {if (n & 1)ans *= x; n = n >> 1; x = x * x;} return ans;}
ll mod_exp(ll x, ll y, ll p) {ll res = 1; x = x % p; while (y > 0) {if (y & 1)res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}
ll power(ll x,  ll y) {ll temp; if ( y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp;}
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

void solve()
{
	ll n;
	cin >> n;
	ll a[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	ll maximum[n];
	maximum[0] = a[0];
	for (int i = 1; i < n; i++)
	{
		maximum[i] = max(a[i], maximum[i - 1]);
	}
	ll prefixSum[n];
	prefixSum[0] = a[0];
	for (int i = 1; i < n; i++)
	{
		prefixSum[i] = prefixSum[i - 1] + a[i];
	}
	ll answer = 0;
	for (int i = 0; i < n; i++)
	{
		answer += prefixSum[i];
		cout << answer + (i + 1)*maximum[i] << endl;
	}
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "r", stdout);
	freopen("error.txt", "r", stderr);
#endif
	fast
	solve();
}


//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N, M;
int to[400005], ne[400005], c[200005], he[100001];
int kotae[100001];

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int MAX = 1000;
class shuturyoku_unko {
public:
	char C[MAX * 4];
	constexpr shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 3) {
				C[i * 4 + 2 - j] = '0' + X % 10;
				X /= 10;
			}
			C[i * 4 + 3] = ' ';
		}
	}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char* dn = cn, * di = dn, * owad = dn + dm - 20;
void putint(int A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	if (A >= 1000) {
		int dig = 1;
		if (A >= 100000) dig = 3;
		else if (A >= 10000) dig = 2;
		memcpy(di, f.C + A / 1000 * 4 + 3 - dig, dig);
		memcpy(di + dig, f.C + A % 1000 * 4, 4);
		di += dig + 4;
	}
	else {
		int dig = 1;
		if (A >= 100) dig = 3;
		else if (A >= 10) dig = 2;
		memcpy(di, f.C + A * 4 + 3 - dig, dig + 1);
		di += dig + 1;
	}
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	N = getint();
	M = getint();

	int k = 2;
	rep1(i, M) {
		int u = getint(), v = getint();
		c[i] = getint();
		to[k] = v;
		ne[k] = he[u];
		he[u] = k++;
		to[k] = u;
		ne[k] = he[v];
		he[v] = k++;
	}

	int Q[100001], q = 0;
	Q[q++] = 1;
	kotae[1] = 1;
	while (q) {
		int tmp = Q[--q];
		int oya = kotae[tmp];
		for (int k = he[tmp]; k; k = ne[k]) {
			int t = to[k];
			if (!kotae[t]) {
				int e = c[k >> 1];
				kotae[t] = e + (oya == e);
				Q[q++] = t;
			}
		}
	}

	rep1(i, N) putint(kotae[i] - ((kotae[i] > N) << 1));
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
constexpr int inf=1000001000;
constexpr ll INF=2e18;
constexpr ll mod=1000000007;
// ll MOD=998244353;
constexpr ll MOD=998244353;

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<pair<int,int>>> ee(n,vector<pair<int,int>>(0));
    rep(i,m){
        int f,g,h;
        cin >> f >> g >> h;
        f--;
        g--;
        ee[f].push_back(mk(g,h));
        ee[g].push_back(mk(f,h));
    }
    vector<int> d(n,0);
    d[0]=1;
    vector<vector<pair<int,int>>> e(n,vector<pair<int,int>>(0));
    vector<set<int>> s(n);
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int f=q.front();
        q.pop();
        rep(i,ee[f].size()){
            if (d[ee[f][i].first]==0){
                d[ee[f][i].first]=1;
                e[f].push_back(mk(ee[f][i].first,ee[f][i].second));
                e[ee[f][i].first].push_back(mk(f,ee[f][i].second));
                s[f].insert(ee[f][i].second);
                s[ee[f][i].first].insert(ee[f][i].second);
                q.push(ee[f][i].first);
            }
        }
    }
    queue<pair<int,int>> qq;
    vector<int> dd(n,0),ans(n,0);
    qq.push(mk(0,0));
    dd[0]=1;
    while(!qq.empty()){
        int f=qq.front().first,g=qq.front().second;
        qq.pop();
        if (g==0){
            for (int i=1;i<=n;i++){
                if (s[f].find(i)==s[f].end()){
                    ans[f]=i;
                    break;
                }
            }
            rep(i,e[f].size()){
                if (dd[e[f][i].first]==0){
                    dd[e[f][i].first]=1;
                    qq.push(mk(e[f][i].first,e[f][i].second));
                }
            }
        }
        else{
            ans[f]=g;
            rep(i,e[f].size()){
                if (dd[e[f][i].first]==0){
                    dd[e[f][i].first]=1;
                    if (g!=e[f][i].second) qq.push(mk(e[f][i].first,e[f][i].second));
                    else qq.push(mk(e[f][i].first,0));
                }
            }
        }
    }
    rep(i,n) cout << ans[i] << endl;
}


// abc188_e
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e15)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

struct Graph {

    int n;

    vector<vector<int>> edges;
    vector<set<int>> rev;
    vector<ll> weight;
    vector<ll> mn;

    Graph(int n): n(n), edges(n), rev(n), weight(n), mn(n, INF){}

    void add_edge(int u, int v){
        edges[u].emplace_back(v);
        rev[v].emplace(u);
    }

    ll dfs(){
        queue<int> q;

        REP(i, n){
            if (rev[i].empty()) q.push(i);
        }

        ll ret=-INF;
        while (!q.empty()){
            int u = q.front(); q.pop();

            for (auto v: edges[u]){
                ret = max(ret, weight[v] - mn[u]);
                mn[v] = min(mn[v], mn[u]);

                rev[v].erase(u);
                if (rev[v].empty()){
                    q.push(v);
                }
            }
        }
        return ret;
    }
};

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;
    Graph g(N);
    REP(i, N) {
        cin >> g.weight[i];
        g.mn[i] = g.weight[i];
    }
    REP(i, M){
        int x, y; cin >> x >> y; x--;y--;
        g.add_edge(x, y);
    }

    ll ans = g.dfs();
    print(ans);

    return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
using namespace std;

int n, m;
int arr[200010];
vector<int> v[200010];
int come[200010];
int sell[200010];
int mn[200010];

int main()
{
	int i;
	int a, b;
	queue<int> que;
	int cur;
	int nxt;
	int ans;

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

		v[a].push_back(b);
		come[b]++;
	}

	for (i = 1; i <= n; i++)
	{
		sell[i] = -2000000010;
		mn[i] = arr[i];
		if (!come[i]) que.push(i);
	}

	while (!que.empty())
	{
		cur = que.front();
		que.pop();

		for (i = 0; i < v[cur].size(); i++)
		{
			nxt = v[cur][i];

			come[nxt]--;
			sell[nxt] = max(sell[nxt], arr[nxt] - mn[cur]);
			mn[nxt] = min(mn[nxt], mn[cur]);

			if (!come[nxt]) que.push(nxt);
		}
	}

	ans = -2000000010;
	for (i = 1; i <= n; i++)
	{
		ans = max(ans, sell[i]);
	}

	cout << ans;
}


//int max = 2 147 483 647 (2^31-1)
//ll max = 9 223 372 036 854 775 807 (2^63-1)
#include<bits/stdc++.h>
using namespace std;

#define forn(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;

//Fast input and output
void fast_io(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);}

//Printing pairs and vectors
template<typename A, typename B> ostream& operator<< (ostream &cout, pair<A,B> const &p) {return cout << "(" << p.f << ", " << p.s << ")";}
template<typename A> ostream& operator<< (ostream &cout, vector<A> const&v){
cout << "["; forn(i,(int)v.size()){ if (i) cout << ", "; cout << v[i];} return cout << "]";}

ll mpow(ll base, ll exp) {
  ll res = 1;
  while (exp) {
    if (exp % 2 == 1){
        res = (res * base) % MOD;
    }
    exp >>= 1;
    base = (base * base) % MOD;
  }
  return res;
}

ll minv(ll base) {
    return mpow(base, MOD - 2);
}

int main(){
  fast_io();
  int n,m,k; cin >> n >> m >> k;
  vi a(n);
  forn(i,n) cin >> a[i];
  vi bina;
  ll b=k;
  while(k>0){
    bina.pb(k%2); k>>=1;}
  int p=bina.size();
  for(int i=0;i<p/2;i++) swap(bina[i],bina[p-1-i]);
  vector<vl>one(n,vl(n));
  forn(i,n) one[i][i]=2*m;
  forn(i,m){
    int x,y; cin >> x >> y;
    one[x-1][x-1]--;
    one[y-1][y-1]--;
    one[x-1][y-1]++;
    one[y-1][x-1]++;
  }
  vector<vl>dp(n,vl(n));
  forn(i,n) dp[i][i]=1;
  forn(l,p){
    vector<vl>newdp(n,vl(n));
    forn(i,n){
      forn(j,n){
        forn(t,n){
          newdp[i][t]=(newdp[i][t]+dp[i][j]*dp[j][t])%MOD;
        }
      }
    }
    dp=newdp; newdp=vector<vl>(n,vl(n));
    if(bina[l]){
      forn(i,n){
        forn(j,n){
          forn(t,n){
            newdp[i][t]=(newdp[i][t]+one[i][j]*dp[j][t])%MOD;
          }
        }
      }
      dp=newdp;
    }
  }
  vl ans(n);
  forn(i,n){
    forn(j,n){
      ans[i]=(ans[i]+dp[i][j]*a[j])%MOD;
    }
    ans[i]=(ans[i]*minv(mpow(2*m,b)))%MOD;
  }
  forn(i,n) cout << ans[i] << "\n";
}
//code by DanTheMan

// KNOW NOTHING!
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)x.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
ll mpwr(ll b,ll p){ll res=1;while(p){if(p&1) {res=(res*b)%MOD; p--;}else{b=(b*b)%MOD; p>>=1;}}return res;}
int msb (int n) {return 31-__builtin_clz(n);}
ll msbl (ll n) {return 63-__builtin_clzll(n);}
int lsb (int n) {return __builtin_ctz(n);}
ll  lsbl (ll n) {return __builtin_ctzll(n);}
int setbit (int n) {return __builtin_popcount(n);}
ll setbitl (ll n) {return __builtin_popcountll(n);}
int main()
{
/*
freopen ("input.txt","r","stdin");
freopen ("output.txt","w","stdout");
*/
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
vin a (3);
cin>>a[0]>>a[1]>>a[2];
cout<< (2*a[2]==a[1]+a[0] || 2*a[1]==a[0]+a[2] || 2*a[0]==a[1]+a[2]?"Yes":"No");
return 0;
}
/* What we know is a drop , but what we don't know is an ocean !*/


/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip> //setprecision
#include <map> // map
#include <unordered_map> //unordered_map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <sstream>
#define endl "\n";
using namespace std;

using PLL = pair<long long,long long>;
typedef tuple<long long,long long,long long> TUP;
using P = pair<int,int>;
const long long INF = 4000000000000000001;
const int inf = 1001001001;
const long long MOD = 1000000007;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % mod, M / 2,mod);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % mod;
    return res %= mod;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
    if(res < 0) res += MOD;
    return res % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int N;cin >> N;
    long long C;cin >> C;
    vector<PLL> s(N);
    vector<long long> cost(N);
    vector<TUP> event;
    long long last = 0;
    for(int i = 0;i<N;i++){
        long long a,b,c;cin >> a >> b >> c;
        s.at(i) = make_pair(a,b);
        last = max(last,b);
        cost.at(i) = c;
        event.push_back(make_tuple(a-1,1,i));
        event.push_back(make_tuple(b,2,i));
    }
    sort(event.begin(),event.end());

    long long now = get<0>(event.at(0));
    long long ans = 0;
    long long nowsum = 0;
    long long ex = 0;
    vector<long long> Time(N);
    for(int i = 0;i<event.size();i++){
        long long T = get<0>(event.at(i));
        int type = get<1>(event.at(i));
        int idx = get<2>(event.at(i));
        if(T == last && type == 2){
            //ex += cost.at(idx);
        }
        if(type == 1){
            if(nowsum > C){
                ans += C * (T - now);
                //nowsum -= cost.at(idx);
            }
            else{
                ans += nowsum * (T - now);
                //nowsum -= cost.at(idx);
            }
            Time.at(idx) = T;
            now = T;
            nowsum += cost.at(idx);
        }
        else if(type == 2){
            if(nowsum > C){
                ans += C * (T - now);
                nowsum -= cost.at(idx);
            }
            else{
                ans += nowsum * (T - now);
                nowsum -= cost.at(idx);
            }
            now = T;
        }
        if(T == last && type == 2){
            //ex += cost.at(idx);
            //cout << nowsum + ex << endl;
            //ans += min(nowsum + ex , C);
            //cout << T << endl;
            //if(nowsum+ex >= C) cout << "u" << endl;
        }
    }
    //for(int i = 0;i<N;i++) ex += cost.at(i);
    cout << ans + min(ex , C) << endl;
    //cout << 163089627821228 - 163089627569438 << endl;

}

// #undef _GLIBCXX_DEBUG

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

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define forv(i,v) for (auto i = v.begin(); i != v.end(); ++i)
#define forr(i,v) for (auto i = v.end(); i != v.begin() && (--i, 1); )
#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T> inline T abs (T x) {return x > T() ? x : -x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const ll mod = 998244353;

ll get_st(ll a, int st) {
	ll res = 1;
	while(st) {
		if (st & 1) {
			(res *= a) %= mod;
		}
		(a *= a) %= mod;
		st >>= 1;
	}
	return res;
}

int main () {
	//std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	int n, m, k;
	cin >> n >> m >> k;
	if (n == 1 || m == 1) {
		cout << get_st(k, n * m) << endl;
		return 0;
	}
	ll ans = 0;
	forn(i, 1, k + 1) {
		(ans += (get_st(i, n) - get_st(i - 1, n) + mod) * (get_st(k - i + 1, m) % mod)) %= mod;
	}
	cout << ans << endl;

	return 0;
}


#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define _roverload(_a1,_a2,_a3,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(...) _roverload(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
    #define _rrep(i,n) rrepi(i,0,n)
    #define rrepi(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);--i)
    #define rrep(...) _roverload(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    void print() {cout << '\n';}
    template<class T> void print(const vector<T> &v)
    {bool f=false; for(const auto &e: v){if(f)cout << ' '; cout << e; f=true;} cout << '\n';}
    template<class... T> void print(const T&... args)
    {bool f=false; for(const auto &e: {args...}){if(f)cout << ' '; cout << e; f=true;} cout << '\n';}
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
const int MOD = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
    bool operator==(const mint a) const {
        return x == a.x;
    }
    bool operator!=(const mint a) const {
        return x != a.x;
    }
    friend ostream& operator<<(ostream& os, const mint& value) {
        os << value.x;
        return os;
    }
    friend istream& operator>>(istream& is, mint& value) {
        ll t;
        is >> t;
        value = mint(t);
        return is;
    }
};

#pragma endregion library

int main(){
    int n, p; cin >> n >> p;
    mint el = p-2;
    el = el.pow(n-1);
    print(el*(p-1));
}

#include <iostream>
using namespace std;
int main() {
  int N,W;

  cin>>N>>W;
  cout<<N/W;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define sz(x) ((int)(x).size())
#define all(x) x.begin() , x.end()
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define deb(x) cout<<#x<<"="<<x<<endl
#define debs(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll

const int mod = 1000000007;
const int MAX = INT_MAX;
const int MIN = INT_MIN;
const char nl = '\n';
const long long INF = 1e18;

int octi(int n){
    int x = 0 , cnt =1 ;
    while(n!=0){
        int rem = n%8 ;
        x+= rem*cnt ;
        cnt = cnt*10 ;
        n = n/8 ;
    }
    return x ;
}

bool findseven(int n){
    while(n!=0){
        int rem = n%10 ;
        if(rem==7) return true ;
        n/=10 ;
    }
    return false ;
}

void solve(){
    int n ; cin>>n ;
    set<int> ans ;
    for(int i=1;i<=n;i++){
        if(findseven(i)){
            ans.insert(i);
        }
        int octnum = octi(i) ;
        if(findseven(octnum)){
            ans.insert(i);
        }
    }
     cout<<n - sz(ans) ;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);cout << fixed;
#ifndef ONLINE_JUDGE
    freopen("F:/input.txt", "r", stdin);
    freopen("F:/output.txt", "w", stdout);
#endif
    int T = 1;
   // cin >> T;
    while (T--) {
        solve();
    }
}

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    bool ok = true;
    for(int base : {8,10}){
      int x = i;
      while( x > 0){
        if(x%base == 7) ok = false;
        x /= base;
      }
    }
    if(ok) ++ans;
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>

#define ld double long
#define ll long long
#define ull unsigned long long
#define all(A) A.begin(), A.end()
#define pb push_back
#define fri(start , end , step)  for(int i = start; i < end ; i = i + step)
#define frj(start , end , step)  for(int j = start; j < end ; j = j + step)
#define fast ios_base::sync_with_stdio(0); cin.tie(0)
#define debug(x) cerr<<#x<<": "<<x<<endl;

using namespace std;

void pv(vector<ll>& vec ){
    fri(0 , vec.size() , 1) cout << vec[i] << " ";
    cout << "\n";
}
multiset<string> A;

char ans[20][20];

string ss = "ABCDEFGH";

pair<int  , multiset<string>> check(multiset<string> tec , int i1 , int j1){

	int cof = 0;
	fri(0 , 20 , 1){
		string s;
		frj(i , i + 12 , 1){
			if(ans[i1][j % 20] != '0' ) s += ans[i1][j % 20];
			else break;
			int c = tec.count(s) ;
			if(c) {
				cof += c;
				tec.erase(s);
				}
			}

		}
	fri(0 , 20 , 1){
		string s;
		frj(i , i + 12 , 1){
			if(ans[j % 20][j1] != '0' ) s += ans[j % 20][j1];
			else break;
			int c = tec.count(s) ;
			if(c) {
				cof += c;
				tec.erase(s);
				}
			}

		}
	return {cof , tec};

	}

bool vis[20][20];

signed main(){
	fast;
    int n , m;
    cin >> n >> m;
	map<char ,  int > M;
	fri(0 , 20   , 1){
		frj(0 , 20 , 1){
			ans[i][j] = '0';
			}
		}

    fri(0 , m , 1 ){
		string s;
		cin >> s;
		//for(char x : s) M[x] ++;
		A.insert(s);
		}

    queue<pair<int , int>> q;
    q.push({0 , 0 });

    while(!q.empty()){
		int i = q.front().first ;
		int j = q.front().second;
		//debug(i);
		//debug(j);
		vis[i][j] = 1;
		q.pop();
		multiset<string> good;
		int mx = -1;
		char best;

		for(char x : ss){
			ans[i][j] = x;
			pair<int  , multiset<string>> f = check(A, i , j);
			int ls= mx;
			mx = max(mx , f.first);
			if(ls != mx) {
				good= f.second;
				best = x;
				}
			}

		if(mx == 0){
			//cout << i << " " << j << endl;
			int mn = 1e9 ;
			for(auto x : ss){

				int ls = mn;
				mn = min(mn , M[x]);
				if(ls != mn) {
					best = x;
					}
				}

			}
		//debug(M[best]);
		M[best] ++;
		//debug(M[best]);
		ans[i][j] = best;
		/*for(int i1 = 0; i1 < 20 ; i1 ++){
			for(int j1 = 0; j1 < 20 ; j1 ++){
				cout << ans[i1][j1];
				}
			cout << endl;
			}
		cout << endl;
		cout << i << " " << j << endl;*/

		A = good;
		if(i < 19 && vis[i+  1][j] == 0) {
			q.push({i + 1 , j } );
			vis[i + 1][j ] = 1;
			}
		if(j < 19 && vis[i][j+ 1] == 0) {
			q.push({i , j + 1 } );
			vis[i][j + 1] = 1;
			}
		}

	fri(0 , 20 , 1){
		frj(0 , 20 , 1) cout << ans[i][j] ;
		cout << "\n";
		}

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
clock_t start=clock();
int main()
{
  int N,M;
  cin>>N>>M;
  vector<string> s(M);
  string answer[N][N];
  for(int i=0;i<M;i++) cin>>s[i];
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      answer[i][j]=".";
    }
  }
  int num=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(answer[i][j]=="."&&s[num].size()+j<N){
        for(int k=0;k<s[num].size();k++){
          answer[i][j+k]=s[num][k];
        }
        num++;
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cout<<answer[i][j];
    }
    cout<<endl;
  }
}


#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>

using namespace std;

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

#define debug(x) cerr << #x << " = " << (x) << endl;
#define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")";
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define F first
#define S second

// template<typename _Ty1, typename _Ty2>
// ostream& operator<<(ostream& _os, const pair<_Ty1, _Ty2>& _p) {
//     _os << '(' <<_p.first << ',' << _p.second << ')';
//     return _os;
// }
//
// template<typename _Ty1, typename _Ty2>
// istream& operator>>(istream& _is, pair<_Ty1, _Ty2>& _p) {
//     _is >> _p.first >> _p.second;
//     return _is;
// }

int query(int s, int e) {
  cout << "? " << s << " " << e << endl;
  int in;cin >> in;
  return in;
}

void solve() {
  // sure, maybe
  // sure > 4 -> 0
  // maybeC(4-sure)*24

  set<int> sure, notsure;
  string s;cin>>s;
  for(int i = 0;i < 10;i++) {
    char ch = s[i];
    if(ch == 'o') sure.insert(i);
    if(ch == 'x') notsure.insert(i);
  }

  int ans = 0;
  rep(i,10){
    rep(j,10){
      rep(k,10){
        rep(l,10){
          // i j k l
          bool possible = true;
          set<int> z{i,j,k,l};
          for(int x : z) if(notsure.count(x) == 1) possible = false;
          for(int x : sure) if(z.count(x) == 0) possible = false;
          ans += possible;
        }
      }
    }
  }
  cout<<ans<<endl;
}

// 5
// (300+3t) + x

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);
 // cout << fixed << setprecision(15);

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

 int t = 1;
 // cin >> t;
 while (t--) {
   solve();
 }

 return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define int long long
#define arr(a) new int[a]
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define dbV(arr) cout << #arr << "=[ "; \
for(auto i:arr) cout << i << " "; cout << "]\n";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repF(i,a,n) for(int i = (a); i <= (n); ++i)
#define repB(i,a,n) for(int i = (a); i >= (n); --i)
#define test(t) int t;cin>>t;while(t--)
#define inp(a) int a;cin>>a;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define umii unordered_map<int,int>
#define umll unordered_map<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define seti set<int>
#define setl set<ll>
#define pb push_back
#define F first
#define S second
#define MOD 1000000007
#define all(z) z.begin(),z.end()
using namespace std;
void printArray(int a[],int n)
{
	rep(i,n)
	cout<<a[i]<<" ";
	cout<<"\n";
}

void printVec(vi v)
{
	int s = v.size();
	rep(i,s)
	cout<<v[i]<<" ";
	cout<<"\n";
}
void printBool(bool b)
{
 	if(b) cout<<"YES\n";
 	else cout<<"NO\n";
}
bool check(int a,string s)
{
	int p = a/1000,q = a/100 - 10*p,r = a/10 - 100*p - 10*q,t = a - 1000*p - 100*q - 10*r;
	bool b = 1;
	for(int i = 0;i<10;i++)
	{
		if(s[i] == 'o')
		{
			if(p != i && q != i && r != i && t != i)
			{
				b = 0;
				break;
			}
		}
		else if(s[i] == 'x')
		{
			if(p == i || q == i || r == i || t == i)
			{
				b = 0;
				break;
			}
		}
	}
	return b;
}
signed main()
{
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin>>s;
	int ans = 0;
	for(int i = 0;i<10000;i++)
	{
		if(check(i,s))
		ans++;
	}
	cout<<ans;
 return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

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

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
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; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N, M;
    cin >> N >> M;
    V<ll> X(M), Y(M);
    REP(i, M) cin >> X[i] >> Y[i];

    set<ll> st;
    st.insert(N);

    V<ll> ids(M, 0);
    iota(ALL(ids), 0);
    sort(ALL(ids), [&](ll x, ll y){
        return X[x] < X[y];
    });

    REP(i, M){
        ll j = i;
        while(j < M and X[ids[i]] == X[ids[j]]){
            j++;
        }
        ll len = j - i;
        V<ll> check(len, 0);
        V<ll> vals;
        for(ll k=i;k<j;k++){
            vals.push_back(Y[ids[k]]);
        }
        REP(k, len){
            if(st.find(vals[k]-1) != st.end() or st.find(vals[k]+1) != st.end()){
                check[k] = 1;
            }
        }
        REP(k, len){
            if(check[k]){
                st.insert(vals[k]);
            }else{
                auto itr = st.find(vals[k]);
                if(itr != st.end()) st.erase(itr);
            }
        }

        i = j - 1;

        // for(auto x: st) cerr << x << " ";
        // cerr << endl;
    }

    cout << st.size() << endl;

    return 0;
}

// Jai Shree Ram

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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}

int solve(){
 		int n,m; cin >> n >> m;
 		map<int,vector<int>>col;
 		set<pii>st;
 		map<int,set<int>>mp;
 		mp[n].insert(0);
 		col[n].push_back(0);
 		for(int i = 1; i <= m; i++){
 			int x,y; cin >> x >> y;
 			st.insert({x,y});
 			col[y].push_back({x});
 			mp[y].insert(x);
 		}
 		for(auto &i:col){
 			sort(all(i.y));
 		}
 		set<pii>reached;
 		set<int>ans;
 		reached.insert({0,n});
 		for(auto [x,y]:reached){
 			if(st.count({x+1,y-1})){
 				reached.insert({x+1,y-1});
 				st.erase({x+1,y-1});
 				mp[y-1].erase({x+1});
 			}
 			if(st.count({x+1,y+1})){
 				reached.insert({x+1,y+1});
 				st.erase({x+1,y+1});
 				mp[y+1].erase(x+1);
 			}
			int j = upper_bound(all(col[y]),x) - col[y].begin();
			int row;
			if(col[y].back() == x) row = 2*n;
			else row = col[y][j];
			vector<pii>remove;
			auto itr = mp[y+1].upper_bound(x);
			while(itr != mp[y+1].end() and *itr <= row){
				reached.insert({*itr,y+1});
				remove.push_back({*itr,y+1});
				itr++;
			}
			itr = mp[y-1].upper_bound(x);
			while(itr != mp[y-1].end() and *itr <= row){
				reached.insert({*itr,y-1});
				remove.push_back({*itr,y-1});
				itr++;
			}
			for(auto [i,j]:remove){
				st.erase({i,j});
				mp[j].erase(i);
			}
			if(col[y].back() == x)ans.insert(y);

 		}
 		cout << ans.size() << endl;
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


//#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define puba(a) emplace_back((a))
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
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; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
char a[2004][2004];
char moto[2004][2004];
int dismin[2004][2004];
int dp[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int main(){
	int H,W;
	scan(H>>W);
	rep1(i,H){
		scan(a[i]+1);
	}
	rep(i,H+2) a[i][0]=a[i][W+1]='#';
	rep(j,W+2) a[0][j]=a[H+1][j]='#';
	rep(i,H+2) rep(j,W+2) moto[i][j]=a[i][j];
	fill(dismin[0],dismin[2004],INF);
	vpint warp[26];
	pint st,go;
	rep(i,H+2){
		rep(j,W+2){
			if(a[i][j]!='#'){
				if(a[i][j]=='S'){
					st=mp(i,j);
				}
				if(a[i][j]=='G'){
					go=mp(i,j);
				}
				else if('a'<=a[i][j]&&a[i][j]<='z'){
					warp[a[i][j]-'a'].puba(mp(i,j));
				}
				a[i][j]='.';
			}
		}
	}
	pint inizahyo;
	inizahyo=st;
	dismin[st.first][st.second]=0;
	vector<pint> zahyorecord;
	zahyorecord.push_back(inizahyo);
	bool alre[26]={};
	for(int count=1;;count++){
		if(zahyorecord.empty()) break;
		vector<pint> zahyobefore=move(zahyorecord);
		zahyorecord.clear();

		rep(i,zahyobefore.size()){
			rep(j,4){
				pint zahyoto=zahyobefore[i];
				int y=zahyoto.first+dp[j][1];
				int x=zahyoto.second+dp[j][0];
				if(a[y][x]=='.'&&count<dismin[y][x]){
					zahyorecord.puba(mp(y,x));
					dismin[y][x]=count;
				}
			}
			pint zahyoto=zahyobefore[i];
			int y=zahyoto.first,x=zahyoto.second;
			debug(count,y,x);
			if('a'<=moto[y][x]&&moto[y][x]<='z'&&alre[moto[y][x]-'a']==0){
				for(const auto& v:warp[moto[y][x]-'a']){
					if(v==zahyoto) continue;
					int yto=v.first,xto=v.second;
					if(count<dismin[yto][xto]){
						zahyorecord.puba(mp(yto,xto));
						dismin[yto][xto]=count;
					}
				}
				alre[moto[y][x]-'a']=1;
			}

		}
	}
	if(dismin[go.first][go.second]>=INF) prin(-1);
	else prin(dismin[go.first][go.second]);
	return 0;
}

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

int A[100100], B[100100], C[100100];
vector<bool> seen(100100, false);
vector<int> ans = {1}, pass(100100,0);

void dfs(int s, vector<vector<int>> &G){
  seen.at(s) = true;

  pass.at(C[s])++;
  for(auto next: G.at(s)){
    if(seen.at(next)) continue;
    if(pass.at(C[next]) == 0) ans.push_back(next);
    dfs(next,G);
  }
  pass.at(C[s])--;
  return;
}

int main(){
  int N;
  cin >> N;
  rep(i,1,N+1) cin >> C[i];
  rep(i,1,N) cin >> A[i] >> B[i];

  vector<vector<int>> graph(100100);
  rep(i,1,N){
    graph.at(A[i]).push_back(B[i]);
    graph.at(B[i]).push_back(A[i]);
  }

  dfs(1, graph);
  sort(ans.begin(), ans.end());
  for(auto x: ans) cout << x << endl;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n;
   cin>>n;
   vector<int> answers(n+1,1);
   for(int i=2;i<=n;i++){
       set<int> divisors;
       for(int j=1;j<=sqrt(i);j++){
           if(i%j==0){
           divisors.insert(answers[j]);
            divisors.insert(answers[i/j]);
           }
       }
       int index=1;
       while(true){
           if(divisors.count(index)==0){
               break;
           }
           index++;
       }
       answers[i]=index;
    }
   for(int i=1;i<=n;i++){
       cout<<answers[i]<<" ";
   }
   return 0;
}

#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 998244353;
constexpr ll inf = 1LL << 60;

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

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

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return (ll)1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
//
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

//
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1);
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}

////////////////////////////////////////////////////////////////////

ll d(ll n){
for(ll i=1;i<=15;i++){
	if(n<=9){return i;
	break;}
	else n/=10;
}

}

ll ks(ll n){
	ll val=1;

for(int k=1;k<=100;k++){
	ll fin=0;
	if(n==1){return val;}
	for(int i=2;i<=n;i++){
		if(n%i==0){n/=i;
		val++;

		break;}
		if((i+1)*(i+1)>n){return val+1;}
	}
	if(fin==1 || n==1){return val;}
}
}

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

ll n;
cin>>n;

if(n==1){
  cout<<1<<endl;
  return 0;}
cout<<1<<" ";
for(ll i=2;i<=n-1;i++){
	cout<<ks(i)<<" ";
}
cout<<ks(n)<<endl;
return 0;

}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

ll mod = 998244353;

ll gcd(ll a, ll b){
  if (a%b == 0)return(b);
  else return(gcd(b, a%b));
}

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

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

    // k 番目のノードについて遅延評価を行う
    void eval(int k, int l, int r) {

      // 遅延配列が空でない場合、自ノード及び子ノードへの
      // 値の伝播が起こる
      if(lazy[k] != 0) {
        node[k] = (node[k] + lazy[k]) % mod;

        // 最下段かどうかのチェックをしよう
        // 子ノードは親ノードの 1/2 の範囲であるため、
        // 伝播させるときは半分にする
        if(r - l > 1) {
            lazy[2*k+1] = (lazy[2*k+1] + lazy[k]) % mod * inv(2) % mod;
            lazy[2*k+2] = (lazy[2*k+2] + lazy[k]) % mod * inv(2) % mod;
        }

        // 伝播が終わったので、自ノードの遅延配列を空にする
        lazy[k] = 0;
      }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
      if(r < 0) r = n;

      // k 番目のノードに対して遅延評価を行う
      eval(k, l, r);

      // 範囲外なら何もしない
      if(b <= l || r <= a) return;

      // 完全に被覆しているならば、遅延配列に値を入れた後に評価
      if(a <= l && r <= b) {
          lazy[k] = (lazy[k] + (r - l) * x % mod) % mod;
          eval(k, l, r);
      }

      // そうでないならば、子ノードの値を再帰的に計算して、
      // 計算済みの値をもらってくる
      else {
          add(a, b, x, 2*k+1, l, (l+r)/2);
          add(a, b, x, 2*k+2, (l+r)/2, r);
          node[k] = (node[2*k+1] + node[2*k+2]) % mod;
      }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
      if(r < 0) r = n;
      if(b <= l || r <= a) return 0;

      // 関数が呼び出されたら評価！
      eval(k, l, r);
      if(a <= l && r <= b) return node[k];
      ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
      ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
      return (vl + vr)%mod;
    }
};

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

  char s,t;
  cin >> s >> t;
  if(s == 'Y') t = 'A' + (t - 'a');
  cout << t << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<intt>
#define ii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
intt gcd(intt a, intt b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b)
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = res * a;
      a = a * a;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) {
   if ((n==0)||(n==1))
      return 1;
   else
      return (n*fact(n-1))%mod;
}

void go()
{
#ifndef ONLINE_JUDGE
  freopen("IN.txt","r",stdin);
  freopen("OUT.txt","w",stdout);
  #endif
}
bool isPowerOfTwo (int x)
{
    return (!(x&(x-1)));
}

int main(){
	go();
	fast_io
  char a,b;cin>>a>>b;
  if(a=='Y')
    cout << (char)(b-32) << "\n";
  else
    cout << b <<"\n";

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>

using namespace std;

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

#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

constexpr int INF = 1e9+7;
constexpr ll INFL = 9*1e18;

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

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

int inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
ull inline power(ull a,ull b){ull res = 1;rep(i,b)res *= a;return res;}
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
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; }
template<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;}
string to_oct(int n){string s;while(n){s = to_string(n%8) + s;n /= 8;}return s;}

int main(){
  int n,m,q;cin>>n>>m>>q;
  vector<pair<int,int>> vw(n);rep(i,n)cin>>vw[i].se>>vw[i].fi;
  vector<int> x(m);rep(i,m)cin>>x[i];
  vector<int> a;
  sort(all(vw),greater<pair<int,int>>());

  rep(_,q){
    int l,r;cin>>l>>r;l--;r--;
    vector<int> boxes;
    rep(i,m){
      if(l <= i && i <= r)continue;
      boxes.push_back(x[i]);
    }
    sort(all(boxes));
    int ans = 0;
    rep(i,n){
      for(auto&& box: boxes){
        if(vw[i].second <= box){
          ans += vw[i].first;
          box = -1;
          break;
        }
      }
    }
    a.push_back(ans);
  }
  for(auto&& one: a){
    print(one);
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define  fast()      ios :: sync_with_stdio(false); cin.tie(0);
#define  ll             long long int
#define  ull            unsigned long long int
#define vl              vector<long long>
#define vc              vector<char>
#define vs              vector<string>
#define vp              vector< pair<ll,ll> >
#define sl              set<long long>
#define sc              set<char>
#define sts             stack<string>
#define max_3(a,b,c)    max(a, max(b,c))
#define max_4(a,b,c,d)  max(a,max(b,max(c,d)))
#define min_3(a,b,c)    min(a, min(b,c))
#define min_4(a,b,c,d)  min(a,min(b,min(c,d)))
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*b)/gcd(a,b)
#define pi              2*acos(0.0)
#define N               200006
#define      mnn                 10000000000000
#define      mxx                 -10000000000000
#define in              1234567890;
ll a[N],b[N];
int M=1000000007;
map<ll,ll>mp,mk;
sl s1,s2;
vl v;
vl w,w1,w2,w3;
ll m,n,c,d,i,j,k,l,r,x,t,y,u,e,f,g,mn,mx,z;
string s,q,p;
char ch,ck;
int main()
{
    fast()
    t==1;
    cin>>s>>p;
    for(i=0;i<s.size();i++) c+=s[i]-'0';
    for(i=0;i<p.size();i++) d+=p[i]-'0';
    cout<<max(c,d);
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 10;
long long a[N],b[N];
int n,w;
void insert(int l , int r , int c){
	b[l] += c;
	b[r] -=c;
}
int  main(){
	#ifndef ONLINE_JUDGE
		freopen("water_heater.txt","r",stdin);
	#endif
	ios::sync_with_stdio(false);
	cin >> n >> w;
	int maxt = -1;
	for(int i = 1; i <= n; i++){
		int s,t,k; cin >> s >> t >> k;
		maxt = max(maxt,t+1);
		insert(s+1,t+1,k);
	}
	for(int i = 1; i <= maxt + 10; i++) a[i] = a[i-1] + b[i];
//	for(int i = 1; i <= maxt + 10; i++) {
//		cout << a[i] << " ";
//	}
//	cout << endl;
	for(int i = 1; i <= maxt + 10; i++) {
		if(a[i] > w) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
//	cout << endl;
	return 0;
}

/*
struct node{
	int l,r,w;
};
bool cmp(node &a,node &b){
	if(a.l != b.l){
		return a.l < b.l;
	}else{
		return a.r < b.r;
	}
}
const int N = 2 * 1e5 + 10;
typedef pair<int,int> PII;
int n,k;
node a[N];
int main(){
	#ifndef ONLINE_JUDGE
		freopen("water_heater.txt","r",stdin);
	#endif
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(int i = 0; i < n ; i++){
		cin >> a[i].l >> a[i].r >> a[i].w;
	}
	sort(a,a+n,cmp);
//	for(int i = 0 ; i < n ; i++){
//		cout << a[i].l <<";" << a[i].r <<endl;
//	}
//	cout << "-----------------" << endl;
	int sum_t = a[0].w , tail = a[0].r , curr = 0;
	for(int i = 1 ; i < n; i++){
		while(curr < i && tail <= a[i].l){
			sum_t -= a[curr++].w;
			tail = a[curr].r;
//			cout << "curr"<<curr << endl;
//			cout <<"tail:"<< a[curr].r <<endl;
		}
		if(i == curr) {
			sum_t = a[i].w;
		}
		if(tail > a[i].l){
			sum_t += a[i].w;
//			cout <<"sum_t:"<< sum_t << endl;
			if(sum_t > k){
				cout << "No" << endl;
				return 0;
			}
		}

//		cout << sum_t <<endl;
	}
	cout <<"Yes" << endl;
	return 0;
}

*/

#pragma GCC optimize("Ofast")

#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <array>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

using namespace std;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getrnd(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

template <typename T1, typename T2> inline bool relax(T1& a, const T2& b) {
    return a > b ? a = b, true : false;
}

template <typename T1, typename T2> inline bool strain(T1& a, const T2& b) {
    return a < b ? a = b, true : false;
}

// :::::::::::::::::::::::::::::::

const int N = 2e5 + 3, A = N * 2 + 3;

struct fenwick {
    int n;
    vector<ll> tr;

    fenwick(int n) : n(n), tr(n) {}

    void upd(int r, int x) {
        for (; r < n; r |= r + 1)
            tr[r] += x;
    }

    ll get(int r) {
        ll res = 0;
        for (; r >= 0; r &= r + 1, --r)
            res += tr[r];
        return res;
    }

    ll get(int l, int r) {
        return get(r) - get(l - 1);
    }
};

void solve() {
    int n, m, q;
    cin >> n >> m >> q;

    vector<int> ids = {0};
    vector<tuple<int, int, int>> qs;
    for (int i = 0; i < q; ++i) {
        int t, x, y;
        cin >> t >> x >> y;
        ids.emplace_back(y);
        qs.emplace_back(t, x - 1, y);
    }
    sort(ids.begin(), ids.end());
    ids.resize(unique(ids.begin(), ids.end()) - ids.begin());

    auto gid = [&](int x) {
        return lower_bound(ids.begin(), ids.end(), x) - ids.begin();
    };

    ll ans = 0;
    fenwick sa(A), sb(A), ca(A), cb(A);
    vector<int> a(n), b(m);
    for (int i = 0; i < n; ++i)
        ca.upd(0, 1);
    for (int i = 0; i < m; ++i)
        cb.upd(0, 1);

    for (auto [type, i, val] : qs) {
        if (type == 1) {
            int id = gid(a[i]);
            sa.upd(id, -a[i]);
            ca.upd(id, -1);
            int bef = cb.get(id);
            ans -= 1LL * bef * a[i];
            ans -= sb.get(id + 1, A - 1);

            a[i] = val;
            id = gid(a[i]);
            sa.upd(id, a[i]);
            ca.upd(id, 1);

            int blw = cb.get(id);
            ans += 1LL * blw * a[i];
            ans += sb.get(id + 1, A - 1);
        }
        else {
            int id = gid(b[i]);
            sb.upd(id, -b[i]);
            cb.upd(id, -1);
            int bef = ca.get(id);
            ans -= 1LL * bef * b[i];
            ans -= sa.get(id + 1, A - 1);

            b[i] = val;
            id = gid(b[i]);
            sb.upd(id, b[i]);
            cb.upd(id, 1);

            int blw = ca.get(id);
            ans += 1LL * blw * b[i];
            ans += sa.get(id + 1, A - 1);
        }
        cout << ans << '\n';
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


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

#define ll long long

//O(V+E)

vector <ll> v[10000];

void bfs(ll source,ll vis[])
{
  ll i,child;
  queue<ll>q;
  q.push(source);
  vis[source] = 1;
  while(!q.empty())
  {
    ll parent = q.front();
    q.pop();
    for(i=0;i<v[parent].size();i++)
    {
      child = v[parent][i];
      if(vis[child] == 0)
        q.push(child);
      vis[child] = 1;
    }
  }
}
int main()
{
  ll i,n,m,x,y,ans=0,j;
  cin>>n>>m;
  for(i=0;i<m;i++)
  {
    cin>>x>>y;
    v[x].push_back(y);
  }

  for(long long i=1;i<=n;i++)
  {
    ll vis[n+9];
    memset(vis,0,sizeof(vis));
    bfs(i,vis);
    for(j=1;j<=n;j++)
      if(vis[j])
        ans++;
  }
  cout<<ans<<'\n';
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
#define vi vector<int>
#define vvi(_Name,_Height,_Width) vector<vi>_Name(_Height,vi(_Width))
#define vvi_v(_Name,_Height,_Width,_Value) vector<vi>_Name(_Height,vi(_Width,_Value))
#define pii pair<int,int>
using namespace std;
void fail(string s){ cout<<s;exit(0); }
void fail(int s){ cout<<s;exit(0); }
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
vi v[2000];
vi use(2000);
int n,m;
int dfs(int u){
	use[u]=1;
	int ans=1;
	for(int i:v[u]){
		if(!use[i])
			ans+=dfs(i);
	}
	re ans;
}
void run_test_case(){
	cin>>n>>m;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		v[a-1].pb(b-1);
	}
	int ans=0;
	rep(i,n){
		rep(_,n)use[_]=0;
		ans+=dfs(i);
	}
	cout<<ans<<'\n';
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int test_cases=1;
//	cin>>test_cases;
	while(test_cases--)
		run_test_case();
	re 0;
}


#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>

using namespace std;

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

#define debug(x) cerr << #x << " = " << (x) << endl;
#define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")";
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define F first
#define S second

// template<typename _Ty1, typename _Ty2>
// ostream& operator<<(ostream& _os, const pair<_Ty1, _Ty2>& _p) {
//     _os << '(' <<_p.first << ',' << _p.second << ')';
//     return _os;
// }
//
// template<typename _Ty1, typename _Ty2>
// istream& operator>>(istream& _is, pair<_Ty1, _Ty2>& _p) {
//     _is >> _p.first >> _p.second;
//     return _is;
// }

const int nmax = 1000;
bool g[nmax][nmax][26];
int n,m,a,b;char c;
bool visited[nmax][nmax];
int dist[nmax][nmax];
vector<pii> gg[nmax];

int bfs(int s,int e) {
  queue<pii> q;
  q.push({s,e});
  visited[s][e] = true;
  int ans = INT_MAX;
  while (!q.empty()) {
    pii v = q.front();
    q.pop();
    if(v.F == v.S) {
      ans=min(ans, dist[v.F][v.S]);
      continue;
    }
    bool chk = false;
    rep(i,26) {
      if(g[v.F][v.S][i]) {
        ans=min(ans, dist[v.F][v.S]+1);
        chk=true;
        break;
      }
    }
    if(chk) continue;
    s = v.F,e = v.S;
    for(int i = 0;i < gg[s].size();i++) {
      for(int j = 0;j < gg[e].size();j++) {
        if(gg[s][i].S != gg[e][j].S) continue;
        if(gg[s][i].F == s && gg[e][j].F == e) continue;
        if(!visited[gg[s][i].F][gg[e][j].F]) {
          visited[gg[s][i].F][gg[e][j].F]=true;
          q.push({gg[s][i].F,gg[e][j].F});
          dist[gg[s][i].F][gg[e][j].F]=dist[s][e]+2;
        }
      }
    }
  }

  return (ans == INT_MAX?-1:ans);
}

void solve() {
  cin>>n>>m;
  rep(i,m){
    cin>>a>>b>>c;
    a--;b--;
    g[a][b][c-'a']=g[b][a][c-'a']=1;
    gg[a].pb({b,c-'a'});
    gg[b].pb({a,c-'a'});
  }
  cout << bfs(0, n-1) << endl;
}

// 2 10 5 15 30
// ABABABA A

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);
 // cout << fixed << setprecision(15);

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

 int t = 1;
 // cin >> t;
 while (t--) {
   solve();
 }

 return 0;
}

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
vector<int> v[1000][26];
int n,m,a,b,c,d[1000][1000];
char cha;
string s;
queue<int> que;
int main(void){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        que.push(i*1000+i);
        for(int j=0;j<n;j++){
            if(i!=j)d[i][j]=(1<<30);
        }
    }
    for(int i=0;i<m;i++){
        cin>>a>>b>>cha;
        a--,b--;
        v[a][cha-'a'].push_back(b);
        if(a!=b)v[b][cha-'a'].push_back(a);
        if(a!=b){
            d[a][b]=1;
            d[b][a]=1;
            que.push(1000*a+b);
        }
    }
    while(que.size()){
        a=que.front()/1000;
        b=que.front()%1000;
        que.pop();
        if(abs(b-a)==n-1){
            cout<<d[a][b]<<endl;
            return 0;
        }
        for(int i=0;i<26;i++){
            for(auto x:v[a][i]){
                for(auto y:v[b][i]){
                    if(d[x][y]>d[a][b]+2){
                        d[x][y]=d[a][b]+2;
                        que.push(x*1000+y);
                    }
                }
            }
        }
    }
    cout<<-1<<endl;
}


/*input
3 2

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<'('<<P.F<<','<<P.S<<')';
    return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
    REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
    return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

int main(){
    IOS;
    ll ans = 1;
    for(ll i=2;i<=30;i++){
        ans = ans * i / __gcd(ans,i);
    }
    cout<<ans+1<<'\n';
    return 0;
}

// TestCpp.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

#include <string>

using namespace std;

int main() {
	string x;
	cin >> x;
	//cin >> c >> d;
	auto pos = x.find(".");
	auto res = x.substr(0, pos);
	cout << res << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int N,W,x;
  cin>>N>>W;
  x=N/W;
  cout<<x;
}

#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define ll long long
#define INF 9999999999999999
#define rep(i,m,n) for(int i = m; i < n ;i++)
#define rrep(i,m,n) for(int i = m - 1; i >= n ;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<ll,ll>
#define tint tuple<ll, ll, ll>
#define mod 998244353
#define MAX 10000010
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, W;
    cin >> N >> W;
    cout << N / W << endl;
}


#include <bits/stdc++.h>

// #pragma GCC optimize("O3")
#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; for(int tt = 0; tt < t; ++tt)
#define sz(x) (int)(x).size()
#define sort_unique(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()));
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/**
order_of_key(k) : nums strictly smaller than k
find_by_order(k): index from 0
**/

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

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

const int N = 3e3 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
/**
Read problem statement carefully
**/

LL dp[N][N]; // dp[i][j], number of ways i, into j pieces
LL arr[N];
LL mp[N];

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

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

    dp[0][0] = 1;
    // dp[i][j]: use i elements, use j blocks
    for(int k = 1; k <= n; ++k){ // block cnt
        memset(mp, 0, sizeof mp);
        LL s = 0;
        for(int i = 0; i <= n; ++i){ // element cnt
            s += arr[i];
            s %= k;
            dp[i][k] = mp[s];
            mp[s] = (mp[s] + dp[i][k-1]) % mod;
        }
    }

    LL res = 0;
    for(int k = 1; k <= n; ++k){
        res = (res + dp[n][k]) % mod;
    }

    cout << res << "\n";
}

int main()
{
    Fast;
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // louisfghbvc
        solve(1);
    return 0;
}

/**
Enjoy the problem.
**/

#include<bits/stdc++.h>
#define w(x)            int x; cin>>x; for(int tc=1;tc<=x;tc++)
#define trace(x) 		cerr<<#x<<": "<<x<<" "<<endl;
#define trace1(x,y)		cerr<<#x<<": "<<x<<" "<<endl;cerr<<#y<<": "<<y<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define inp(x) cin>>x;
#define f first
#define s second
#define inf 1e18

using namespace std;
void solve(int tc) {
	int n; cin >> n;
	long double a = 0, b = 0, c = -inf;
	// int a[n];
	long double ele;
	for (int i = 0; i < n; i++) {
		// cin >> a[i];
		cin >> ele;
		ele = abs(ele);
		a += abs(ele);
		b += abs(ele) * abs(ele);

		c = max(c, ele);

	}
	b = sqrt(b);
	cout << fixed << setprecision(20) << a << endl << b << endl << c << endl;
}

int32_t main() {
	FIO
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	// w(x) {
	solve(1);
	// }
	return 0;
}


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

int main() {
  long long N,L;
  cin >> N >> L;

  vector<long long> A(N+2),B(N+2);

  for (int i=0; i<N; i++) {
    cin >> A[i+1];
  }

  for (int i=0; i<N; i++) {
    cin >> B[i+1];
  }

  A[0] = 0;
  B[0] = 0;
  A[N+1] = L+1;
  B[N+1] = L+1;

  long long ans = 0;

  long long NG,OK,md;

  for (int i=1; i<N+1; i++) {
    if (B[i] == A[i]) {
      continue;
    }
    if (A[i] < B[i] && A[i+1] > B[i+1]) {
      cout << -1 << endl;
      return 0;
    }
    if ((A[i] < B[i] && B[i] == B[i+1]-1 ) || (A[i] > B[i] && B[i] == B[i-1]+1 )) {
      ans++;
      continue;
    }
    if (B[i] > A[i]) {
      NG = i;
      OK = N+1;
      md = (NG+OK) / 2;
      while (OK - NG > 1) {
        md = (NG+OK) / 2;
        if (A[md] >= B[i] + (md-i)) {
          OK = md;
        }
        else {
          NG = md;
        }
      }
      if (A[OK] != B[i] + (OK-i)) {
        cout << -1 << endl;
        return 0;
      }
      else {
        ans += (OK-i);
      }
    }
    else {
      NG = i;
      OK = 0;
      md = (NG+OK) / 2;
      while (NG - OK > 1) {
        md = (NG+OK) / 2;
        if (A[md] <= B[i] + (md-i)) {
          OK = md;
        }
        else {
          NG = md;
        }
      }
      if (A[OK] != B[i] + (OK-i)) {
        cout << -1 << endl;
        return 0;
      }
      else {
        ans += (i-OK);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
    int n, x;
    int v, p;
    cin >> n >> x;
    int cnt = 0;
    int sum = 0;
    bool flag = true;
    rep(i, n){
        cin >> v >> p;
        sum += v*p;
        if(sum > 100*x && flag){
            cnt = i+1;
            flag = false;
        }
    }
    if(flag) cout << -1 << endl;
    else cout << cnt << endl;
    return 0;
}


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

#define DEBUG

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b);
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif

void solve() {
	rd2(ll, n, q);

	vl A(n);
	for(ll i = 0 ; i < n; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());

	vl Q(q);
	for(int i = 0; i < q; i++) {
		cin >> Q[i];
	}
	vl B = Q;
	sort(B.begin(), B.end());

	map<ll, ll> ans;
	ll prev_point = 0;
	ll allc_count = 0;
	ll q_ct = 0;
	ll prev_gap = 0;
	for(ll i = 0; i < n; i++) {

		if(q_ct == Q.size())
			break;

		ll num = A[i];
		ll gap = num - prev_point - 1;
		allc_count += gap;

		while(q_ct < Q.size() and allc_count >= B[q_ct]) {
			ll pick = prev_point + B[q_ct] - prev_gap;
			ans[B[q_ct]] = pick;
			q_ct++;
		}

		prev_point = num;
		prev_gap = allc_count;

	}

	while(q_ct < Q.size()) {
		ll pick = prev_point + B[q_ct] - allc_count;
		ans[B[q_ct]] = pick;
		q_ct++;
	}

	vl ret;

	for(auto x: Q) {
		cout << ans[x] << endl;
	}

}

int main() {

	fastio;

	ll t = 1;
	// rd1(ll, t);
	while(t--) {
		solve();
	}

	return 0;
}

#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

int main() {

    int N, Q;

    cin >> N >> Q;

    vector<long long> A(N);

    for (auto& x : A) {

        cin >> x;

    }

    vector<long long> low(N);

    for (int i = 0; i < N; ++i) {

        low[i] = A[i] - (i + 1);

    }

    while (Q--) {

        long long K;

        cin >> K;

        const int idx = lower_bound(low.begin(), low.end(), K) - low.begin();

        if (idx == N) {

            cout << A[N - 1] + (K - low[N - 1]) << '\n';

        } else {

            cout << A[idx] - (low[idx] - K + 1) << '\n';

        }

    }

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define fl(n) for(int i=0;i<n;i++)
#define flj(n) for(int j=0;j<n;j++)
#define flo(n) for(int i=1;i<=n;i++)
#define mii map<int,int>
#define mci map<char,int>
#define V vector<int>
#define vp vector<pair<int,int>>
#define pb push_back
#define pp pair<int,int>
#define ff first
#define ss second
#define S set<int>
#define all(v) v.begin(),v.end()
#define gr greater<int>()
#define show2(a, b) cout<<a<<' '<<b<<endl;
#define show3(a, b, c) cout<<a<<' '<<b<<' '<<c<<endl;
const long long mod=1000000007;
const int N=1e5+5;
const long double PI=3.14159265358;
vector<vector<int>> adj;
bool vis[N];
int c;
void dfs(int j){
	vis[j]=true;
	c++;
	for(auto u:adj[j]){
		if(!vis[u]) dfs(u);
	}
}
int32_t main(){
    int t=1;
    //cin>>t;
    while(t--){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int z=d*c-b;
    if(z<=0) cout<<-1;
    else{
    	int ans=a/z;
    	if(a%z) ans++;
    	cout<<ans;
	}
	}
	return 0;
	}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(b >= d * c){
      cout << -1 << endl;
	  return 0;
    }

  	long long  i = 1;
  	while(a + b * i > d * c * i) i++;
  	cout << i << endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
using namespace std;

template <typename T>
inline void read(T&x){
    x=0; char temp=getchar(); bool f=false;
    while(!isdigit(temp)){if(temp=='-') f=true; temp=getchar();}
    while(isdigit(temp)){x=(x<<1)+(x<<3)+temp-'0'; temp=getchar();}
    if(f) x=-x;
}
template <typename T>
void print(T x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

typedef long long ll;
const int MAXN = 2e5+5;
const ll mod = 998244353;

inline ll ksm(ll base,ll b){
    ll res=1;
    while(b){
        if(b&1) res=res*base%mod;
        base=base*base%mod,b>>=1;
    }
    return res;
}

//basic
int n;

//Union-Find Set
int pre[MAXN],cnt;

inline void Init(){for(register int i=1;i<=n;i++) pre[i]=i;}
int FindRoot(int id){return pre[id]==id? id:pre[id]=FindRoot(pre[id]);}
inline void Unite(int id1,int id2){id1=FindRoot(id1),id2=FindRoot(id2); if(id1!=id2) pre[id2]=id1;}

int main(){
    read(n);
    Init();
    for(register int i=1,x;i<=n;i++) read(x),Unite(i,x);
    for(register int i=1;i<=n;i++) cnt+=(FindRoot(i)==i);
    print((ksm(2,cnt)+mod-1)%mod);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

struct dsu {
    vector<int> p;
    vector<int> sz;
    vector<map<int, int>> c;
    int n;

    dsu(int _n) : n(_n) {
        p.resize(n);
        iota(p.begin(), p.end(), 0);
        c.resize(n);
        sz.assign(n, 1);
    }

    inline int get(int x) {
        if (p[x] == x) {
            return x;
        } else {
            return p[x] = get(p[x]);
        }
    }
    inline bool unite(int x, int y) {
        x = get(x);
        y = get(y);
        if (x == y) {
            return false;
        }
        if (sz[x] > sz[y]) {
            swap(x, y);
        }
        p[x] = y;
        sz[y] += sz[x];
        for (auto e : c[x]) {
            c[y][e.first] += e.second;
        }
        return true;
    }
    inline bool same(int x, int y) {
        return (get(x) == get(y));
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> c(n);
    dsu uf(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        uf.c[i][c[i]] = 1;
    }
    while (q--) {
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 1) {
            x--, y--;
            uf.unite(x, y);
        } else {
            x--;
            x = uf.get(x);
            cout << uf.c[x][y] << '\n';
        }
    }
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<vector<int>> child(N+1);
    vector<int> par(N+1, 0);
    for (int i = 2; i <= N; i++) {
        int p;
        cin >> p;
        child[p].push_back(i);
        par[i] = p;
    }
    vector<int> size(N+1, 1);
    vector<int> cplus(N+1, -1);
    for (int now = N; now >= 1; now--) {
        for (int c : child[now]) size[now] += size[c];
        vector<int> odd = {-10000000}, even = {-10000000};
        bool turn = true;
        for (int c : child[now]) {
            if (size[c]%2 == 1) odd.push_back(cplus[c]);
            else even.push_back(cplus[c]);
        }
        sort(odd.begin(), odd.end(), greater<int>());
        sort(even.begin(), even.end(), greater<int>());
        int k = odd.size();
        int l = even.size();
        int op = 0, ep = 0;
        k--;l--;
        //cout << k << " " << l << endl;
        while (op < k || ep < l) {
            if (even[ep] >= 0 || op == k) {
                if (turn) cplus[now] += even[ep];
                else cplus[now] -= even[ep];
                ep++;
            }else {
                if (turn) cplus[now] += odd[op];
                else cplus[now] -= odd[op];
                op++;
                turn = !turn;
            }
        }
    }
    cout << (N-cplus[1])/2 << endl;
    return 0;
}

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define ford(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define vll vector<ll>
#define sz(s) (int)(s.size())
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string i_t_s(int x){
	string t="";
	while(x){
		t+=x%10+'0';
		x/=10;
	}
	reverse(all(t));
	re t;
}
int s_t_i(string t){
	int x=0;
	rep(i,sz(t)){
		x=x*10+(t[i]-'0');
	}
	re x;
}
ll q_p(ll x,ll y){
	ll res=1;
	x%=mod;
	while(y){
		if(y%2){
			res=res*x;
			res%=mod;
		}
		y/=2;
		x=x*x;
		x%=mod;
	}
	re res;
}
bool ok(int x,int y,int n,int m){
	 re(x>=0&&x<n&&y>=0&&y<m);
}
bool isprime(int x){
	if(x<2)
	re false;
	for(int i=2;i*i<=x;i++)
	if(x%i==0)
	re false;
	re true;
}
int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0};
int n;
ll a[3001];
ll lst[3001][3001];
ll prv[3001];
ll dp[3001][3001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)
	cin>>a[i];
	rep(i,n)
	prv[i+1]=prv[i]+a[i];
	lst[1][0]=1;
	forn(i,1,n+1){
		forn(j,1,i+1){
			dp[i][j]=lst[j][prv[i]%j];
		}
		forn(j,1,i+1){
			lst[j+1][prv[i]%(j+1)]+=dp[i][j];
			lst[j+1][prv[i]%(j+1)]%=mod;
		}
	}
//	forn(i,1,n+1)
//	cout<<prv[i]<<" ";
//	cout<<"\n";
//	forn(i,1,n+1){
//		forn(j,1,i+1)
//		cout<<dp[i][j]<<" ";
//		cout<<"\n";
//	}
	ll ans=0;
	forn(i,1,n+1){
		ans+=dp[n][i];
		ans%=mod;
	}
	cout<<ans;
	re 0;
}
/*
检查循环是rep(i,n)还是rep(i,m)!!
long long所要的时间比int长!!
没有long long必要不写long long!!
写公式前先想一想!!
二分前看一看边界对不对，有没有特殊值!!
提交前要测特殊数据（边界上的）!!
*/


#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,V,P,i,X;
  cin >> N >> X;
  for(X=X*100,i=1;i<=N;i++){
    cin >> V >> P;
    X=X-V*P;
    if(X<0){
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}

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

typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second

ld eps = 1e-9;

int main(){
	fast_io;
	int n, x;
	cin >> n >> x;
	ld s = 0;
	int ans = -1;
	for(int i = 0; i < n; i ++){
		ld v, p;
		cin >> v >> p;
		s += (v * p) / 100;
		if(ans == -1 && s - x > eps){
			ans = i + 1;
		}
	}
	cout << ans;

	return 0;
}


#include<bits/stdc++.h>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define m_p make_pair
#define pb push_back
#define fi first
#define se second
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define db long double
using namespace std;
const int N=100010;
int n;
db a[N];
db check(db x){
	db res=0.0;
	rep(i,n){
		res+=a[i]-min(2*x,a[i]);
	}
	return res/n+x;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	db ans=1e9;
	int l=0,r=n-1;
	while(l<=r){
		if(l+2==r||l+1==r||l==r){
			db rs=check(a[l]/2);
			ans=min(ans,rs);
			if(l+1<=r)rs=check(a[l+1]/2);
			ans=min(ans,rs);
			if(l+2<=r)rs=check(a[l+2]/2);
			ans=min(ans,rs);
			break;
		}
		int lm=l+(r-l)/2;
		int rm=l+(r-l)/2;
		db cl=check(a[lm]/2),cr=check(a[rm]/2);
		if(cl>cr)
			r=rm;
		else
			l=lm;
		ans=min(ans,cl);
		ans=min(ans,cr);
	}
	/*
	rep(i,n){
		cout<<fixed<<setprecision(20)<<check(a[i]/2)<<"\n";
		ans=min(ans,check(a[i]/2));
	}
	*/
	cout<<fixed<<setprecision(20)<<ans<<"\n";
	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 <atcoder/all>
// #include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;
// using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> p32;
typedef pair<ll, ll> p64;
typedef pair<p64, p64> pp64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(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 fi first
#define se 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 zero ll(0)
#define set_bits(x) __builtin_popcountll(x)
// #define mll modll998244353

ll mpow(ll a, ll b)
{
    if (a == 0)
        return 0;
    if (b == 0)
        return 1;
    ll t1 = mpow(a, b / 2);
    t1 *= t1;
    t1 %= MOD;
    if (b % 2)
        t1 *= a;
    t1 %= MOD;
    return t1;
}

ll mpow(ll a, ll b, ll p)
{
    if (b == 0)
        return 1;
    if (a == 0)
        return 0;
    ll t1 = mpow(a, b / 2, p);
    t1 *= t1;
    t1 %= p;
    if (b % 2)
        t1 *= a;
    t1 %= p;
    return t1;
}

ll modinverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}

mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

ll range(ll l, ll r)
{
    return l + mt() % (r - l + 1);
}

ll rev(ll v)
{
    return mpow(v, MOD - 2);
}

ll ceil(ll p, ll q)
{
    return (p + q - 1) / q;
}

vv64 gr;
v64 dep;
ll ans;

ll f(ll v, ll p, ll k){
	ll alr = 0;
	for(auto it : gr[v]) if(it!=p){
		alr = max(alr,f(it,v,k));
		dep[v] = max(dep[v],dep[it]+1);
	}
	if(dep[v]<=alr){
		dep[v]=0;
	}
	else if(dep[v]==k){
		ans++;
		dep[v]=0;
		return k-1;
	}
	else if(p==-1){
		ans++;
	}
	return alr-1;
}

void solve()
{
	ll n,k;
	cin >> n >> k;
	gr.resize(n);
	dep.resize(n);
	forn(i,n-1){
		ll a,b;
		cin >> a >> b;
		a--,b--;
		gr[a].pb(b);
		gr[b].pb(a);
	}
	ll l = 1,r = n/2;
	while(l<r){
		ll mid = (l+r)/2;
		ans = 0;
		forn(i,n) dep[i]=1;
		f(0,-1,mid+1);
		if(ans>k){
			l = mid+1;
		}
		else r = mid;
	}
	cout << l << ln;
}

int main()
{
    fast_cin();
    ll t = 1;
    // cin >> t;
    forn(i, t)
    {
        // cout << "Case #" << i+1 << ": ";
        solve();
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int now[15];
void getstring(int n){
	now[0]=0;
	while(n!=0){
		now[now[0]+1]=n%10;
		now[0]++;
		n=n/10;
	}
	sort(now+1,now+now[0]+1);
//	for(int i=1;i<=now[0];i++){
//		cout<<now[i]<<endl;
//	}
}
int main(){
	int n,k,l;
	cin>>n>>k;
	while(k>0){
		getstring(n);
		l=n;
		n=0;
		int temp=1;
		for(int i=1;i<=now[0];i++){
			n+=temp*(now[i]-now[now[0]+1-i]);
			temp=temp*10;
		}
		//cout<<n<<endl;
		k--;
		if(n==l){
			break;
		}
	}
	cout<<n<<endl;
	return 0;
}

#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
//学习到了 string的函数 to_string() ,reverse(s.begin(),s.end()), stol
int main()
{

    int N;
    int k;
    cin >> N >> k;
    for (int i = 0; i < k; i++)
    {
        string S = to_string(N);
        sort(S.begin(), S.end());
        string down =S ;
        reverse(S.begin(), S.end());
        string up = S;
        N = stol(up) - stol(down);

    }
    cout << N << endl;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")

#include <bits/stdc++.h>
#define readFast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fin cin
#define ll long long
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define output(x) ((int)x && cout << "YES\n") || cout << "NO\n";
#define ld long double
#define pii pair<int,int>
using namespace std;

#ifdef LOCAL
#define read() ifstream fin("date.in.txt")
#else
#define read() readFast
#endif // LOCAL

const int N = 2005;

int main() {
    read();

    int a[4];
    for (int i = 1; i <= 3; ++i)
        fin >> a[i];

    sort(a + 1, a + 4);
    if(a[3] - a[2] == a[2] - a[1])
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}  /*stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
~Benq~*/


//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <chrono>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define int long long
#define L __int128
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())

#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

template<class t> using vc=vector<t>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fi<<","<<p.sc<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
#define sz 1
ll F[sz],R[sz];
void make(){
	F[0] = 1;
	for(int i=1;i<sz;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<sz;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	if(b < 0 || a < b) return 0;
	return F[a]*R[b]%mod*R[a-b]%mod;
}
int a[805][805],rui[805][805];
void solve(){
	int n, k;
	cin>>n>>k;;
	repn(i,n)repn(j,n)cin>>a[i][j];
	int lb=-1,ub=1e9;
	while(ub-lb>1){
		int mid=(lb+ub)/2;
		repn(i,n)repn(j,n)rui[i][j]=a[i][j]<=mid;
		repn(i,n)repn(j,n)rui[i][j]=rui[i][j]+rui[i-1][j]+rui[i][j-1]-rui[i-1][j-1];
		int ok = 0;
		repn(i,n-k+1)repn(j,n-k+1){
			int sum = rui[i+k-1][j+k-1];
			sum -= rui[i-1][j+k-1] + rui[i+k-1][j-1];
			sum += rui[i-1][j-1];

			if(sum >= (k*k+1)/2) ok = 1;
		}
		if(ok)ub=mid; else lb=mid;
	}
	o(ub);
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int t; t = 1; //cin >> t;
	while(t--) solve();
}

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int N = 1e5 + 5;
struct elm{
    int a, b, c;
    bool operator < (const elm &other){
        return c < other.c;
    }
};
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    int n, k, p;
    cin >> n >> k;
    p = k * k - (k * k / 2);
    vector<elm> x;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            int inp;
            cin >> inp;
            x.push_back({i, j, inp});
        }
    }
    sort(x.begin(), x.end());
    int l = 0, r = n * n - 1;
    while (l < r){
        int mid = l + r >> 1, can = 0;
        int has[n][n]{}, pre[n][n + 1]{};
        for (int i = 0; i <= mid; i++) has[x[i].a][x[i].b] = 1;
        for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) pre[i][j + 1] = pre[i][j] + has[i][j];
        for (int j = 0; j <= n - k; j++){
            int tmp = 0;
            for (int i = 0; i < n; i++){
                tmp += pre[i][j + k] - pre[i][j];
                if (i >= k) tmp -= pre[i - k][j + k] - pre[i - k][j];
                if (tmp >= p) can = 1;
                //cout << mid << ' ' << tmp << '\n';
            }
        }
        if (can) r = mid;
        else l = mid + 1;
    }
    cout << x[l].c;
}