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

using ll = long long;

#define fi first
#define se second

const int N = 2e5 + 5;
const int INF = 2e9;
const ll LINF = 9e18;

struct query {
  ll T, X, Y;
};

ll n, m, q;
ll a[N], b[N];
ll tree[4][N << 2];

// 0 = Sum_A, 1 = Sum_B, 2 = Freq_A, 3 = Freq_B

void update(int idx, int l, int r, int pos, int val, int d) {
  if(l > pos || r < pos) return;
  if(l == r) {
    tree[d][idx] += val;
    return;
  }
  int mid = l + r >> 1;
  update(idx << 1, l, mid, pos, val, d);
  update(idx << 1 | 1, mid + 1, r, pos, val, d);
  tree[d][idx] = tree[d][idx << 1] + tree[d][idx << 1 | 1];
}

ll rangeSum(int idx, int l, int r, int from, int to, int d) {
  if(l > to || r < from) return 0;
  if(from <= l && r <= to) return tree[d][idx];
  int mid = l + r >> 1;
  return (
    rangeSum(idx << 1, l, mid, from, to, d) +
    rangeSum(idx << 1 | 1, mid + 1, r, from, to, d)
  );
}

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

  cin >> n >> m >> q;
  vector<query> Q;
  set<int> distinct;
  distinct.insert(0);
  while(q--) {
    int t, x, y; cin >> t >> x >> y;
    Q.push_back({t, x, y});
    distinct.insert(y);
  }
  int cnt = 0;
  map<int, int> idx;
  for(int u : distinct) {
    idx[u] = ++cnt;
  }
  int s = distinct.size();

  update(1, 1, s, idx[0], n, 2);
  update(1, 1, s, idx[0], m, 3);

  ll ans = 0;
  for(query u : Q) {
    if(u.T == 1) {
      int prv = idx[a[u.X]];
      int nxt = idx[u.Y];

      ans -= rangeSum(1, 1, s, 1, prv, 3) * a[u.X];
      ans += rangeSum(1, 1, s, 1, prv, 1);
      ans -= rangeSum(1, 1, s, 1, nxt, 1);
      ans += rangeSum(1, 1, s, 1, nxt, 3) * u.Y;

      update(1, 1, s, prv, -a[u.X], 0);
      update(1, 1, s, nxt, u.Y, 0);
      update(1, 1, s, prv, -1, 2);
      update(1, 1, s, nxt, 1, 2);

      a[u.X] = u.Y;
    } else {
      int prv = idx[b[u.X]];
      int nxt = idx[u.Y];

      ans -= rangeSum(1, 1, s, 1, prv, 2) * b[u.X];
      ans += rangeSum(1, 1, s, 1, prv, 0);
      ans -= rangeSum(1, 1, s, 1, nxt, 0);
      ans += rangeSum(1, 1, s, 1, nxt, 2) * u.Y;

      update(1, 1, s, prv, -b[u.X], 1);
      update(1, 1, s, nxt, u.Y, 1);
      update(1, 1, s, prv, -1, 3);
      update(1, 1, s, nxt, 1, 3);

      b[u.X] = u.Y;
    }
    cout << ans << "\n";
  }
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define endl '\n'
#define mod 1000000007
#define inf 1e18
#define int long long
#define fr(i,a,b) for( int i=a;i<b;i++)
typedef vector<int> vi;typedef vector<vi> vvi;
typedef pair<int,int> pi;typedef vector<pi> vpi;
#define sz(x) (int)(x).size()
#define all(v)  (v).begin(), (v).end()
#define ar array
#define pb push_back
void ingraph(vi graph[], int m){int x, y;fr(i,0,m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}

int32_t main()
{
  fast;
  int n;
  cin>>n;
  string s[n];
  map<string,bool>mp;
  fr(i,0,n)
  {
  	cin>>s[i];
  	if(s[i][0]=='!')
  	{
  		mp[s[i].substr(1,sz(s[i])-1)]=true;
  	}
  }
  string ans="";
  fr(i,0,n)
  {
  	if(s[i][0]!='!')
  	{
  		if(mp[s[i]])
  		{
  			ans=s[i];
  			break;
  		}
  	}
  }
  if(sz(ans)!=0)
  {
  	cout<<ans<<"\n";
  }
  else cout<<"satisfiable\n";
  //cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}

#include <iostream>
#include <map>
#include <unordered_map>
#include <string>

int main() {
  size_t n_string;
  std::cin >> n_string;

  std::unordered_map<std::string, bool> map;
  std::string s;
  for (size_t i = 0; i < n_string; i++) {
    std::cin >> s;
    bool if_exclamation;
    if (s[0] == '!') {
      s = s.substr(1);
      if_exclamation = true;
    } else {
      if_exclamation = false;
    }

    auto find = map.find(s);
    if (find != map.end()) {
      if (if_exclamation != find->second) {
        std::cout << s << std::endl;
        return 0;
      }
    } else {
      map[s] = if_exclamation;
    }
  }
  std::cout << "satisfiable" << std::endl;
}


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

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse4")

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)

#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()

typedef long long LL;
typedef pair<int, int> PII;

const int MAX = 51;

bool p[MAX];
LL a[MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	FOR(i, 2, MAX)
		p[i] = true;
	vector<int> primes;
	FOR(i, 2, MAX)
		if(p[i])
		{
			for(int j = 2 * i; j < MAX; j += i)
				p[j] = false;
			primes.push_back(i);
		}
	int n;
	cin >> n;
	FOR(i, 0, n)
		cin >> a[i];
	LL ans = LONG_LONG_MAX;
	FOR(mask, 0, 1 << SZ(primes))
	{
		LL cur = 1;
		FOR(i, 0, SZ(primes))
			if((mask >> i) & 1)
				cur *= primes[i];
		bool ok = true;
		FOR(i, 0, n)
			ok &= __gcd(cur, a[i]) > 1;
		if(ok)
			ans = min(ans, cur);
	}
	cout << ans << "\n";
	return 0;
}

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

const int maxn=330;
vector<int> vec[maxn];
int n;
int a[maxn];
int tot;
int tmp[maxn];

int main(){;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i],a[i]%=200;
    int up=min(8,n),fl=0;
    for(int p=0;p<(1<<up)&&fl==0;p++){
        int cur=0;
        tot=0;
        for(int i=0;i<up;i++){
            if((p>>i)&1) cur=(cur+a[i])%200,tmp[tot++]=i;
        }
        if(vec[cur].size()){
            cout<<"YES";
            cout<<"\n"<<(int)vec[cur].size();
            for(int i=0;i<vec[cur].size();i++) cout<<" "<<vec[cur][i]+1;
            cout<<"\n"<<tot;
            for(int i=0;i<tot;i++) cout<<" "<<tmp[i]+1;
            fl=1;
        }
        else {
            for(int i=0;i<tot;i++) vec[cur].push_back(tmp[i]);
        }
    }
    if(!fl) cout<<"NO\n";
    return 0;
}


#include<cstdio>
int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  printf("%d %d",(a+b)/2,(a-b)/2);
}

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	bool flag=1;
	int x=0;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
			flag=0;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return (flag?x:~(x-1));
}
int n;
double d,h,ans;
signed main()
{
	n=read();
	cin>>d>>h;
	for(int i=1;i<=n;i++)
	{
		double x,y;
		cin>>x>>y;
		ans=max(ans,y-(h-y)/(d-x)*x);
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i) < (n);(i)++)
#define repsec(i,m,n) for(int (i)=(m);(i) < (n);(i)++)
#define ll long long
#define mod 998244353
#define MOD 1000000007

using namespace std;

int main(){
  ll a[4];
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  ll S = a[0] + a[1] + a[2] + a[3];

  bool flag = false;

  for(int mask=0;mask < 16;mask++){
    ll sum = 0;
    for(int i=0;i < 4;i++){
      if((mask >> i)&1) sum += a[i];
    }
    if(S-sum == sum) flag = true;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  long long N = A + B + C + D;
  if (2 * A == N){
    cout << "Yes" << endl;
  }
  else if (2 * B == N){
    cout << "Yes" << endl;
  }
  else if (2 * C == N){
    cout << "Yes" << endl;
  }
  else if (2 * D == N){
    cout << "Yes" << endl;
  }
  else if (2 * (A + B) == N){
    cout << "Yes" << endl;
  }
  else if (2 * (A + C) == N){
    cout << "Yes" << endl;
  }
  else if (2 * (A + D) == N){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    fast_io
    string s,p;
    cin>>s;
    p.push_back(' ');
    ll n = s.length();

    for(ll i=0; i<n;i++)
    p.push_back(s[i]);

    ll flag=0;

    for(ll i=1;i<=n;i++)
    {
        if(i%2!=0)
        {
            if(isupper(p[i]))
            flag =1;
        }
        else
        {
            if(islower(p[i]))
            flag=1;
        }

    }

    if(flag ==1)
    cout<<"No\n";
    else
    cout<<"Yes\n";

}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define FOR(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = (ll)(a - 1); i >= (ll)(b); i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int N;
        cin >> N;
        vl A(N);
        rep(i,N){
            cin >> A[i];
        }
        sort(A.begin(),A.end());
        if(N%2==1){
            cout << "Second" << endl;
        }
        else{
            bool ok=true;
            rep(i,N/2){
                if(A[2*i]!=A[2*i+1]){
                    ok=false;
                }
            }
            cout << (ok ? "Second" : "First") << endl;
        }
    }
}


#include <bits/stdc++.h>
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int m = ri();
	int t = ri();
	int last_time = 0;
	int cur = n;
	bool res = true;
	for (int i = 0; i <= m; i++) {
		int a = i < m ? ri() : t;
		int b = i < m ? ri() : t;
		cur -= a - last_time;
		if (cur <= 0) res = false;
		cur = std::min(n, cur + b - a);
		last_time = b;
	}

	puts(res ? "Yes" : "No");
	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;

int a[100009];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int tc; cin >> tc;
	for (int ti = 0; ti < tc; ti++) {
		int n; cin >> n;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		if (n % 2 == 1) {
			cout << "Second" << '\n';
			continue;
		}
		sort(a, a + n);
		bool f = true;
		for (int i = 0; i < n; i += 2)
			if (a[i] != a[i + 1]) {
				f = false;
				break;
			}
		if (f) cout << "Second" << '\n';
		else cout << "First" << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll table[1010];

map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for(ll i=2; i*i<=n; i++){
        while(n%i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

int main(){
    FILL(table, 0);
    ll n; cin >> n;
    rep(i, n){
        ll a; cin >> a;
        auto mp = prime_factor(a);
        for(auto p: mp){
            table[p.first] += 1;
            // cout << p.first << ' ' << p.second << endl;
        }
    }
    ll res, ans = -1;
    rep(i, 1002){
        // if(table[i] != 0) cout << table[i] << endl;
        if(chmax(ans, table[i])) res = i;
    }
    cout << res << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,j;
    cin>>n;
    int a[n],cnt,maxm=0,ans;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=2;i<a[0];i++){
        cnt=0;
        for(j=0;j<n;j++){
            if(a[j]%i==0){
                cnt++;
            }
        }
        if(cnt>maxm){
            maxm=cnt;
            ans=i;
        }
    }
    for(i=0;i<n;i++){
        cnt=0;
        for(j=i;j<n;j++){
            if(a[j]%a[i]==0){
                cnt++;
            }
        }
        if(cnt>maxm){
            maxm=cnt;
            ans=a[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
//typedef pair<LL, LL> P;
using namespace std;
//using Graph = vector<vector<LL>>;

//const LL MOD=1000000007;
//const LL MOD=998244353;
//const LL MAX=100100;
//const LL NIL=-1;
//const LL INF=2000000000000000000;
//const LL SEG_VAL = 1 << 19;

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

    LL a;
    LL b;
    cin >> a >> b;
    LL sum=0;
    LL cur;
    vector<LL> anum(a);
    vector<LL> bnum(b);
    if(a>=b){
        for(LL i=0; i<a; i++){
            anum[i]=i+1;
            sum+=anum[i];
        }
        cur=-1;
        for(LL i=0; i<b; i++){
            if(i==0){
                sum+=cur;
                bnum[i]=cur;
            }else{
                if(bnum[i-1]==cur){
                    cur--;
                }
                if(sum+cur<0){
                    anum[a-1]-=(sum+cur);
                    bnum[i]=cur;
                    sum=0;
                    cur--;
                }else{
                    bnum[i]=cur;
                    sum+=cur;
                    cur--;
                }
            }
            if(i==b-1){
                if(sum>0){
                    bnum[i]-=sum;
                }
            }
        }
    }else{
        for(LL i=0; i<b; i++){
            bnum[i]=-i-1;
            sum+=bnum[i];
        }
        cur=1;
        for(LL i=0; i<a; i++){
            if(i==0){
                sum+=cur;
                anum[i]=cur;
            }else{
                if(anum[i-1]==cur){
                    cur++;
                }
                if(sum+cur>0){
                    bnum[a-1]-=(sum+cur);
                    anum[i]=cur;
                    sum=0;
                    cur++;
                }else{
                    anum[i]=cur;
                    sum+=cur;
                    cur++;
                }
            }
            if(i==a-1){
                if(sum<0){
                    anum[i]-=sum;
                }
            }
        }
    }

    for(LL i=0; i<a; i++){
        cout << anum[i] << " ";
    }
    for(LL i=0; i<b; i++){
        cout << bnum[i] << " ";
    }
    cout << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define irep(n) for (int i=0; i < (n); ++i)
#define irepf1(n) for (int i=1; i <= (n); ++i)
#define jrep(n) for (int j=0; j < (n); ++j)
#define jrepf1(n) for (int j=1; j <= (n); ++j)
#define krep(n) for (int k=0; k < (n); ++k)
#define krepf1(n) for (int k=1; k <= (n); ++k)
#define REP(i,s,e) for (int (i)=(s); (i)<(e);(i)++)
#define PI 3.14159265358979323846264338327950288
#define mod 1000000007
#define eps 0.00000001
#define Find(V,X) find(V.begin(),V.end(),X)
#define Sort(V) sort((V).begin(),(V).end())
#define Reverse(V) sort((V).begin(),(V).end()),reverse((V).begin(),(V).end())
#define Greater(V) sort((V).begin(),(V).end(),greater<int>())
//fixed << setprecision(10) <<

int main() {
  int A,B;
  cin >>A >>B;
  vector<int> V(A+B);
    ll sum=0;
  int Max=max(A,B);
  int Min=A+B-Max;
    irepf1 (Max) {
      V[i-1]=i;
      sum+=i;
    }
    //cout<<sum<<endl;
    V[A+B-1]=-1*sum;
    irepf1(Min-1) {
      V[i+Max-1]=-1*i;
      V[A+B-1]+=i;
    }
  if (A>=B) {
    irep (A+B-1) cout<<V[i]<<" ";
    cout<<V[A+B-1]<<endl;
  }
  else {
    irep (A+B-1) cout<<-1*V[i]<<" ";
    cout<<-1*V[A+B-1]<<endl;
  }
}


/*
ID: aravcha1
TASK: gift1
LANG: C++
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

using str = string;
using vi = vector<int>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using si = set<int>;

#define f first
#define s second
#define sz(x) (int)(x).size()
#define pb push_back
#define all(x) begin(x), end(x)
#define sor(x) sort(all(x))

#define Trav(a,x) for (auto& a: x)
#define For(i,a,b) for (int i = (a); i < (b); ++i)

void setIO(string name = "") { // name is nonempty for USACO file I/O
    ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin); // see Input & Output
        freopen((name+".out").c_str(), "w", stdout);
    }
}

/*
    angry cows - 2016 jan
    bull in a china shop - us open 2016
    field reduction - us open 2016
    modern art - 2017 us open
    milk measurement - 2017 dec
    hoofball - 2018 feb
    taming the herd - 2018 feb
    milking order - 2018 us open
    the bucket list - 2018 dec
    back and forth - 2018 dec
    sleepy cow sorting - 2019 jan
    the great revegetation - 2019 feb
    milk factory - 2019 us open
    cow evolution - 2019 us open
    race - 2020 jan
    swapity swap - 2020 feb
    all of us open 2020
    STUCK IN A RUT - 2020 dec (oi oi oi)

    DONE
    ~boring ~simple ~skipped    blocked billboard || - 2018 jan
    ~boring ~simple ~skipped    measuring traffic - 2019 feb
    ~i know too much already    guess the animal - 2019 jan
    */
// rect \/\/\/\/
//{
// struct Rect {
//     int x1,y1,x2,y2;
//     int area() { return (y2-y1)*(x2-x1); }
// };
//
// int intersect(Rect p, Rect q){
//     int xOverlap = max(0,min(p.x2,q.x2)-max(p.x1,q.x1));
//     int yOverlap = max(0,min(p.y2,q.y2)-max(p.y1,q.y1));
//     return xOverlap*yOverlap;
// }
//}

int main() {
    //setIO("");
    int n; cin >>n;
    str in1;
    set<string> ex, notEx;
    for(int i=0; i < n;i++){
        cin >> in1;
        if(in1[0] == '!'){
            if(notEx.count(in1.substr(1))){
                cout << in1.substr(1);
                return 0;
            }
            ex.insert(in1);
        } else {
            if(ex.count("!" + in1)){
                cout << in1;
                return 0;
            }
            notEx.insert(in1);
        }
    }
    cout <<"satisfiable";

}

#pragma GCC optimize("O2") //guess I shouldn't use this in an offline contest

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

#define long long long
#define oo INT_MAX
#define OO LLONG_MAX
#define fi first
#define se second
#define el << "\n"
#define coutf(n) cout << setprecision(n) << fixed
#define mp make_pair
#define pf push_front
#define pb push_back
#define popf pop_front
#define popb pop_back
#define lb lower_bound
#define ub upper_bound
#define maxr *max_element
#define minr *min_element
#define swapr swap_ranges
#define nextp next_permutation
#define prevp prev_permutation
#define lcomp lexicographical_compare
#define pqueue priority_queue
#define uset unordered_set //c++11
#define umap unordered_map //c++11

using str = string;
using ii = pair<int, int>;
using ll = pair<long, long>;
using vi = vector<int>;
using vl = vector<long>;
using vs = vector<str>;
using vvi = vector<vi>;
using vii = vector<ii>;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rev(i, n) for (int i = int(n - 1); i >= 0; --i)
#define fr(x, a) for (auto x : a) //c++11
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define gcd(a, b) abs(__gcd(a, b))
#define lcm(a, b) abs(a / gcd(a, b) * b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

long mod(long n) {return n >= 1000000007ll ? n % 1000000007ll : n;}

const int N = 2e5 + 5, M = 2e5 + 5;
const double pi = acos(-1);

void io(string name = "") {
    if (name.size()) {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
    else {
        #ifndef ONLINE_JUDGE
            freopen("i.in", "r", stdin);
            freopen("o.out", "w", stdout);
            freopen("e.out", "w", stderr);
        #endif
    } return;
}
void bruh() {
    map<str, int> a;
    int n; cin >> n;
    rep(i, n) {
        str s; cin >> s;
        a[s]++;
        if (s[0] == '!') { if (a[s.substr(1, s.length())]) { cout << s.substr(1, s.length()); return; } }
        else if (a["!" + s]) { cout << s; return; }
    }
    cout << "satisfiable";
}
int main() {
    ios_base::sync_with_stdio(true); cin.tie(nullptr);
    io();
    int t = 1;
    //cin >> t; //just need to comment this lol
    while (t--) {
        bruh();
        if (t) cout el; //case sensitive? no problem ;)
    }
    cerr << (double)clock() / CLOCKS_PER_SEC << " seconds bruh bruh lmao";
}


//  (: --Saurabh Mishra-- :) //

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(ll i=0;i<n;i++)
#define loopn(i,j,n) for(ll i=j;i<n;i++)
#define m_arr(arr, n) vector<ll>arr(n)
#define m_arre(arr) vector<ll>arr
#define m_set(sat) set<ll>sat
#define ppn(name) pair<ll,ll>name
#define pp pair<ll,ll>
#define sort_all(arr) sort(arr.begin(), arr.end())
#define pi 3.141592653589793238
#define mod 1000000007
#define inf 1000000000000000000

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

ll power(ll a, ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b%2!=0)
            res = (res*1ll*a);
        b/=2;
        a=(a*1ll*a);
    }

    return res;
}

ll fact(ll n)
{
    ll res=1;
    while(n>1)
    {
        res = (res*1ll*n)%mod;
        n--;
    }
    return res;
}

ll ncr(ll n, ll r)
{
    ll num = fact(n);
    ll denum = fact(n-r);
    denum = (denum*1ll*fact(r))%mod;
    denum = power(denum, mod-2);
    num = (num * 1ll * denum)%mod;
    return num;
}

void solve()
{
    ll n;
    cin>>n;
    ll maxx = inf;
    ll cnt=0;
    for(int i=0;i<61;i++)
    {
        ll x = power(2, i);
        cnt = n%x + n/x + i;
        if(maxx>cnt)
            maxx = cnt;
    }

    cout<<maxx<<endl;
    return;
}

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

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
char In[1 << 20], *ss = In, *tt = In;
#define getchar() (ss == tt && (tt = (ss = In) + fread(In, 1, 1 << 20, stdin), ss == tt) ? EOF : *ss++)
ll read() {
	ll x = 0, f = 1; char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + int(ch - '0');
	return x * f;
}
const ll INF = 0x3f3f3f3f3f3f3f3fll;
ll N;
ll ans;
int main() {
	N = read(); ans = INF;
	for(int k = 0; (1ll << k) <= N; k++)
		ans = min(ans, k + (N >> k) + (N & ((1ll << k) - 1)));
	printf("%lld\n", ans);
	return 0;
}


#include <iostream>

using namespace std;

int main(void)
{
    int N, W;

    cin >> N >> W;

    cout << N / W << endl;
}

#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

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

    return 0;
}


// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <atcoder>
// using namespace atcoder;
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    random_device seed;
    mt19937 engine(seed());
    int query = 1000;
    vector<ll> sp;
    while (query--) {
        ll si, sj, ti, tj;
        cin >> si >> sj >> ti >> tj;
        ll x = abs(si - ti);
        ll y = abs(sj - tj);
        string path;
        if (si < ti) {
            for (int i = 0; i < x; i++) {
                path.push_back('D');
            }
        } else {
            for (int i = 0; i < x; i++) {
                path.push_back('U');
            }
        }
        if (sj < tj) {
            for (int i = 0; i < y; i++) {
                path.push_back('R');
            }
        } else {
            for (int i = 0; i < y; i++) {
                path.push_back('L');
            }
        }
        cout << path << endl;
        ll shortest_path;
        cin >> shortest_path;
        sp.emplace_back(shortest_path);
    }
    return 0;
}

#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int a[107][107];
int n,m,x,y,disx[4]={0,1,0,-1},disy[4]={1,0,-1,0};
int main(){
    scanf("%d%d%d%d",&n,&m,&x,&y);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            char t;
            scanf(" %c",&t);
            a[i][j]=(t=='#');
        }
    }
    int ans=0;
    for (int i = 0; i < 4; ++i) {
        int nx=x+disx[i],ny=y+disy[i];
        while(!a[nx][ny]){
            if(nx<1 || ny<1 || nx>n || ny>m) break;
            ans++;
            nx+=disx[i];
            ny+=disy[i];
        }
    }
    printf("%d",ans+1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const
#define fr first
#define se second
#define ls (now<<1)
#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

cs int G = 3;
cs int ff = 2e6 + 1;
cs int inf = 1e18 + 1;
cs int base = 2333;
cs int M = 1e9 + 7;

int ksm(int a, int b) { return (b % 2 == 1 ? a : 1) * (b ? ksm(a * a % M, b / 2) : 1) % M; }
int x, y, a[2333][2333], b[2333][3333], l[ff], r[ff], Ans, ss;
char s;
void init()
{
	cin >> x >> y;
	rep(i, 1, x)
		rep(j, 1, y)
			cin >> s, a[i][j] = (s != '#'), ss += a[i][j];
	rep(i, 1, x)
	{
		int las = 0, s = 0;
		rep(j, 1, y)
		{
			if(a[i][j]) b[i][j] += s, s ++;
			else s = 0;

		}
		s = 0;
		sep(j, y, 1)
		{
			if(a[i][j]) b[i][j] += s, s ++;
			else s = 0;

		}
	}
//	rep(i, 1, x) rep(j, 1, y) cout <<b[i][j] << " "; cout << "\n";
	rep(i, 1, y)
	{
		int las = 0, s = 0;
		rep(j, 1, x)
		{
		//	cout << j << " " << i << " " <<s << "\n";
			if(a[j][i]) b[j][i] += s, s ++;
			else s = 0;
		//
		}
		s = 0;
		sep(j, x, 1)
		{
			if(a[j][i]) b[j][i] += s, s ++;
			else s = 0;
		//	cout <<b[j][i] << "\n";
		}
	}
	rep(i, 1, x)
		rep(j, 1, y)
		{
			if(!a[i][j]) continue;
		//	cout <<b[i][j] << " ";
			int sum = b[i][j] + a[i][j];
		//	cout << sum <<"\n";
			Ans = Ans + ksm(2, ss) - ksm(2, ss - sum);
			Ans = (Ans % M + M) % M;
		}
	cout << Ans;
}
signed main()
{
//	freopen("1.out", "w", stdout);
	int Ts = 1;
//	cin >> Ts;
	while(Ts--)
		init();
}

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll calc[4000001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    calc[0]=1ll;
    for(int i=1;i<=4000000;i++)
        calc[i]=(calc[i-1]*2ll)%MOD;
    //cin>>t;
    while(t--){
        int h,w;
        cin>>h>>w;
        string s[h];
        for(int i=0;i<h;i++)
            cin>>s[i];
        int k=0;
        int dp[h][w];
        int dp1[h][w];
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(s[i][j]=='.'){
                    int l=j;
                    while(l<w&&s[i][l]=='.')
                        l++;
                    for(int p=j;p<l;p++)
                        dp[i][p]=l-j;
                    k+=l-j;
                    j=l-1;
                }
            }
        }
        for(int j=0;j<w;j++){
            for(int i=0;i<h;i++){
                if(s[i][j]=='.'){
                    int l=i;
                    while(l<h&&s[l][j]=='.')
                        l++;
                    for(int p=i;p<l;p++)
                        dp1[p][j]=l-i;
                    i=l-1;
                }
            }
        }
        ll ans=0ll;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(s[i][j]=='.'){
                    int val=dp[i][j]+dp1[i][j]-1;
                    ans=(ans+((calc[k]-calc[k-val]+MOD)%MOD))%MOD;
                }
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;

using ll = long long;
using Graph = vector<vector<int>>;

#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)

constexpr ll INF = (ll)1e9;
constexpr ll mod = (ll)1e9 + 7;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
inline void init() {
    cin.tie(nullptr); cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}

int main() {
    init();

    int N; cin >> N;
    vector<ll>x(N);
    rep(i, 0, N)cin >> x[i];
    ll ans = 0;
    rep(i, 0, N) {
        ans += abs(x[i]);
    }
    cout << ans << "\n";
    ans = 0;
    rep(i, 0, N) {
        ans += abs(x[i]) * abs(x[i]);
    }
    cout << sqrt(ans) << "\n";
    ans = 0;
    rep(i, 0, N)chmax(ans, abs(x[i]));
    cout << ans << "\n";

    return 0;
}

#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const ll mod = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a) {
    char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {if (c == '-')f = -1; c = getchar();}
    while (isdigit(c)) {x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
int gcd(int a, int b) {return (b > 0) ? gcd(b, a % b) : a;}
map<char,char> M;

int main() {
    M['9'] = '6';
    M['6'] = '9';
    char str[N];
    cin >> str;
    for(int i = strlen(str) - 1;i >= 0;i--){
        if(str[i] == '6' || str[i] == '9') str[i] = M[str[i]];
        cout << str[i];
    }
    return 0;
}

/**
*　　┏┓　　　┏┓+ +
*　┏┛┻━━━┛┻┓ + +
*　┃　　　　　　　┃
*　┃　　　━　　　┃ ++ + + +
*  ████━████+
*  ◥██◤　◥██◤ +
*　┃　　　┻　　　┃
*　┃　　　　　　　┃ + +
*　┗━┓　　　┏━┛
*　　　┃　　　┃ + + + +Code is far away from
*　　　┃　　　┃ + bug with the animal protecting
*　　　┃　 　 ┗━━━┓ 神兽保佑,代码无bug
*　　　┃ 　　　　　　 ┣┓
*　　  ┃ 　　　　　 　┏┛
*　    ┗┓┓┏━┳┓┏┛ + + + +
*　　　　┃┫┫　┃┫┫
*　　　　┗┻┛　┗┻┛+ + + +
*/


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300);
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 4e5 + 5;
int n;
int a[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < 2 * n; ++i) {
    scanf("%d", &a[i]);
  }
  return true;
}

priority_queue<int> pq;

void solve() {
  while (!pq.empty()) {
    pq.pop();
  }
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    pq.push(a[i]);
    pq.push(a[2 * n - 1 - i]);
    res += pq.top();
    pq.pop();
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

#include<bits/stdc++.h>
#define int long long
#define N 400015
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define lowbit(i) ((i)&(-i))
#define VI vector<int>
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
using namespace std;
int n,a[N],ans;
multiset<int> S;
signed main(){
	// freopen("53B.in","r",stdin);
	// freopen("mine.out","w",stdout);
	scanf("%lld",&n);
	rep(i,1,2*n) scanf("%lld",&a[i]);
	rep(i,1,n){
		S.insert(-a[i]); S.insert(-a[2*n-i+1]);
		// printf("%d\n",*S.begin());
		ans += *S.begin(); S.erase(S.begin());
	}
	printf("%lld\n", -ans);
	return 0;
}
/*
4
1 2 3 4 4 3 2 1
*/


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    long long int a[n],b[n];
    long long int l[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
    }
    int maxa[n],maxb[n];
    maxa[0] = a[0];
    maxb[0] = b[0];
    for(int i=1;i<n;i++)
    {
        maxa[i] = maxa[i-1];
        if(a[i]>maxa[i])
        {
            maxa[i] = a[i];
        }
    }
    l[0] = a[0]*b[0];
    for(int i=1;i<n;i++)
    {
        l[i] = l[i-1];
        if(maxa[i] * b[i] > l[i-1])
        {
            l[i] = maxa[i] * b[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        cout<<l[i]<<endl;
    }
}

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<ll> x(N);
    for(size_t i=0;i<N; i++)
    {
        cin >> x[i];
    }
    ll ans_a=0;
    double ans_b=0;
    ll ans_c = 0;
    for(size_t i=0;i<N; i++)
    {
        ans_a+=abs(x[i]);
        ans_b += x[i]*x[i];
        ans_c = max(ans_c, abs(x[i]));
    }
    cout << ans_a << endl;
    cout << fixed << setprecision(10) << sqrt(ans_b) << endl;
    cout << ans_c << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef     long long    ll;
typedef     unsigned long long    ull;
typedef     vector<int> vi;
typedef     vector<long long> vl;
typedef     pair<int, int>pi;
typedef     pair<long long, long long>pl;
#define F   first
#define S   second
#define pb  push_back
#define     all(x)      x.begin() , x.end()
#define mod 1000000007
#define       FOR(i,a,b) for(i=a;i<=b;i++)
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
vector<int>g[10003];
int main()
{
    int t = 1, fac = 1;
    //  scanf("%d", &t);
    while (t--)
    {
       int n,i,x,y,j,f=0;
       string s;
       cin>>n>>s;
       if(s[0]!=s[n-1]) cout<<"1"<<endl;
       else {
           for(i=1;i<n-1;i++)
           {
                if(s[0]!=s[i]&&s[i+1]!=s[n-1])
                {
                    f=1;
                }
           }
           if(f) cout<<"2"<<endl;
           else cout<<"-1"<<endl;
       }
    }
}

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fill0(a) memset(a,0,sizeof(a))
#define fill1(a) memset(a,-1,sizeof(a))
#define fillbig(a) memset(a,63,sizeof(a))
#define pb push_back
#define ppb pop_back
#define mp make_pair
template<typename T1,typename T2> void chkmin(T1 &x,T2 y){if(x>y) x=y;}
template<typename T1,typename T2> void chkmax(T1 &x,T2 y){if(x<y) x=y;}
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned int u32;
typedef unsigned long long u64;
namespace fastio{
	#define FILE_SIZE 1<<23
	char rbuf[FILE_SIZE],*p1=rbuf,*p2=rbuf,wbuf[FILE_SIZE],*p3=wbuf;
	inline char getc(){return p1==p2&&(p2=(p1=rbuf)+fread(rbuf,1,FILE_SIZE,stdin),p1==p2)?-1:*p1++;}
	inline void putc(char x){(*p3++=x);}
	template<typename T> void read(T &x){
		x=0;char c=getchar();T neg=0;
		while(!isdigit(c)) neg|=!(c^'-'),c=getchar();
		while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
		if(neg) x=(~x)+1;
	}
	template<typename T> void recursive_print(T x){if(!x) return;recursive_print(x/10);putc(x%10^48);}
	template<typename T> void print(T x){if(!x) putc('0');if(x<0) putc('-'),x=~x+1;recursive_print(x);}
	void print_final(){fwrite(wbuf,1,p3-wbuf,stdout);}
}
const int MAXN=1e5;
int n;char s[MAXN+5];
int main(){
	scanf("%d%s",&n,s+1);
	if(s[1]^s[n]) return puts("1")&0;
	for(int i=1;i<n;i++) if((s[1]^s[i])&&(s[i+1]^s[n]))
		return puts("2")&0;
	puts("-1");
	return 0;
}


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

int main()
{
	int N;
	cin >> N;
	vector<pair<int, string> > vec;
	rep(i,N)
	{
		string s;
		int t;
		cin >> s >> t;
		vec.push_back(make_pair(t,s));
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	cout << vec[1].second << endl;
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int maxA=0;
	rep (i,n) {
		cin >> a[i];
		maxA=max(maxA,a[i]);
	}
	// 与えられたai から最大の 積和を作る
	// 以下で(l,r) は全てなめている。
	ll maxAns = 0;
	rep(l,n) {
		int x = a[l]; // <- ここと
		for(int r=l;r<n;r++) {
			x = min(x,a[r]);// <- ここが不安なのはなぜか?
			// (l,r)区間内の最小のai を求める-> tle に成るここで工夫が必要
			// for (int i=l;i<=r;i++){
			// 	minA = min(minA,a[i]);
			// }
			ll ans = (r - l + 1)*x;
			maxAns = max(maxAns, ans);
		}
	}
	cout << maxAns << endl;
	return 0;
}


	#include<bits/stdc++.h>
	#define mod ((long)(1e9+7))
	using namespace std;

	int main(int argc, char const *argcv[])
	{
	    ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        int h,w;
        cin>>h;
      	cin>>w;
        string s[h];
        for(int i=0;i<h;i++)
            cin>>s[i];
        int g[h+1][w+1];
        int u[h+1][w+1];
        int l[h+1][w+1];
        int d[h+1][w+1];
        int r[h+1][w+1];
        long  p2[h*w+4];
        p2[0]=1;
        for(int i=1;i<(h*w+4);i++)
            p2[i]=(p2[i-1]*2ll)%mod;

        int k=0;

        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
                {

                    u[i][j]=0;
                    l[i][j]=0;
                    g[i][j]=0;

                    if(s[i][j]=='.')
                        {
                            g[i][j]=1;
                            k++;
                            if(i>0)
                                u[i][j]+=u[i-1][j];
                            if(j>0)
                                l[i][j]+=l[i][j-1];
                            u[i][j]++;
                            l[i][j]++;

                        }

                }
        long long ans=0;
        for(int i=h-1;i>=0;i--)
            for(int j=w-1;j>=0;j--)
                {
              		d[i][j]=0;
              		r[i][j]=0;
                    if(g[i][j]==1)
                        {

                            if(i+1<h)
                                d[i][j]+=d[i+1][j];
                            if(j+1<w)
                                r[i][j]+=r[i][j+1];
                            d[i][j]++;
                            r[i][j]++;

                        int cnum=0;
                        cnum=cnum+u[i][j];
                        cnum=cnum+l[i][j];
                        cnum=cnum+r[i][j];
                        cnum=cnum+d[i][j];
                        cnum=cnum-3;
                        if(k-cnum<0)
                        	cout<<"Wrong"<<endl;
                        ans=(ans+(p2[k]*1ll+mod*1ll-p2[k-cnum]*1ll)%mod)%mod;
                        }

                }

        cout<<ans<<endl;
	}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */

const lint mod = MOD;
class mint{
    public:
        long long x;

    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a;
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend istream& operator>>(istream& is, mint& m){
        long long x; is >> x; m = x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};

int main(){
    int h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    vector<vector<int>> hor(h, vector<int>(w, 1)), ver(h, vector<int>(w, 1));

    rep(i, h){
        rep(j, w){
            if(j == 0 || s[i][j] == '#') continue;
            if(s[i][j-1] == '.') hor[i][j] = hor[i][j-1] + 1;
        }
        repr(j, w){
            if(j == w-1 || s[i][j] == '#') continue;
            if(s[i][j+1] == '.') hor[i][j] = hor[i][j+1];
        }
    }
    rep(j, w){
        rep(i, h){
            if(i == 0 || s[i][j] == '#') continue;
            if(s[i-1][j] == '.') ver[i][j] = ver[i-1][j] + 1;
        }
        repr(i, h){
            if(i == h-1 || s[i][j] == '#') continue;
            if(s[i+1][j] == '.') ver[i][j] = ver[i+1][j];
        }
    }

    vector<vector<int>> p(h, vector<int>(w));
    lint k = 0;
    rep(i, h) rep(j, w){
        if(s[i][j] == '#') continue;
        p[i][j] = hor[i][j] + ver[i][j] - 1;
        k += 1;
    }

    mint ans = mint(2).pow(k) * k;
    rep(i, h) rep(j, w){
        if(s[i][j] == '#') continue;
        ans -= mint(2).pow(k - p[i][j]);
    }
    out(ans);

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a, b, c;
	cin >> a >> b >> c;
	if(a != b)
	{
		cout << "Lost" << endl;
		return 0;
	}
	if(a != c)
	{
		cout << "Lost" << endl;
		return 0;
	}
	if(b != c)
	{
		cout << "Lost" << endl;
		return 0;
	}
	cout << "Won" << endl;
	return 0;
}

//In the name of Almighty Allah
//Alhamdulillah
#include<bits/stdc++.h>
using namespace std ;
int main ()
{
    string s;
    cin >> s;
    if(s[0]==s[1] && s[1]==s[2])
    {
      cout << "Won\n";
    }
    else
    {
      cout << "Lost\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
    ll H,W,N,M;
    cin>>H>>W>>N>>M;
    ll grid[1501][1501]={0};
    ll tmp,tmp1;
    for(ll i=0;i<N;i++){
        cin>>tmp>>tmp1;
      tmp--;tmp1--;
        grid[tmp][tmp1]=1;
    }

    for(ll i=0;i<M;i++){
        cin>>tmp>>tmp1;
      tmp--;tmp1--;
        grid[tmp][tmp1]=2;
    }
//h,w
    ll ans=0;
    for(ll h=0;h<H;h++){
        for(ll w=0;w<W;w++){
        ll tmp=0;ll nh=h,nw=w;
        //(h,w)
        //ue
        nh=h,nw=w;
        for(ll i=h;i>=0;i--){
            if(grid[i][nw]==1){
                tmp++;
                break;
            }
            else if(grid[i][nw]==2){
                break;
            }
        }

        //sita
         nh=h,nw=w;

        for(ll i=h;i<H;i++){
            if(grid[i][nw]==1){
                tmp++;
                break;
            }
            else if(grid[i][nw]==2){
                break;
            }
        }

        //hidari
        nh=h,nw=w;
        for(ll i=w;i>=0;i--){
            if(grid[nh][i]==1){
                tmp++;
                break;
            }
            else if(grid[nh][i]==2){
                break;
            }
        }

        //migi
        nh=h,nw=w;
        for(ll i=w;i<W;i++){
            if(grid[nh][i]==1){
                tmp++;
                break;
            }
            else if(grid[nh][i]==2){
                break;
            }
        }

        if(tmp>0){
            ans++;
        }

        }
    }
    cout<<ans<<endl;

}

#include <bits/stdc++.h>
using namespace std;
char str[4][30],q[20];
int cnt;
int mymap[30];
bool st[30];
bool jdg[20];
long long temp[10];
bool dfs(int s){
    if(s>cnt){
        for(int i=1;i<=3;i++){
            if(mymap[str[i][1]-'a']==0) return false;
        }
        temp[1]=temp[2]=temp[3]=0;
        for(int i=1;i<=3;i++){
            for(int j=1;str[i][j];j++){
                temp[i]=temp[i]*10+mymap[str[i][j]-'a'];
            }
        }
        return temp[1]+temp[2]==temp[3];
    }
    for(int i=0;i<=9;i++){
        if(!jdg[i]){
            mymap[q[s]-'a']=i;
            jdg[i]=true;
            if(dfs(s+1)) return true;
            jdg[i]=false;
        }
    }
    return false;
}
int main(){
    for(int i=1;i<=3;i++) scanf("%s",str[i]+1);
    for(int i=1;i<=3;i++){
        for(int j=1;str[i][j];j++){
            if(!st[str[i][j]-'a']){
                st[str[i][j]-'a']=true;
                q[++cnt]=str[i][j];
            }
        }
    }
    if(cnt>10) puts("UNSOLVABLE");
    else{
        if(dfs(1)){
            for(int i=1;i<=3;i++) cout<<temp[i]<<endl;
        }
        else puts("UNSOLVABLE");
    }
    return 0;
}


#include <bits/stdc++.h>
#ifdef LOCAL
#include "C:\Users\15328\Desktop\isaunoya.hpp"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
using namespace std;
long long fib[100];
bool book[100];
int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	fib[0] = 1;
	fib[1] = 1;
	for (int i = 2; i < 87; i++) {
		fib[i] = fib[i - 1] + fib[i - 2];
	}
	long long n;
	cin >> n;
	for (int i = 86; i >= 0; i--) {
		if (n >= fib[i]) {
			n -= fib[i];
			book[i] = true;
		}
	}
	vector<int> ans;
	for (int i = 0; i < 87; i++) {
		if (i % 2 == 0) {
			if (book[i]) {
				ans.emplace_back(1);
			}
			ans.emplace_back(3);
		} else {
			if (book[i]) {
				ans.emplace_back(2);
			}
			ans.emplace_back(4);
		}
	}
	reverse(begin(ans), end(ans));
	cout << ans.size() << "\n";
	for (int i = 0; i < int(ans.size()); i++) {
		cout << ans[i] << "\n";
	}
}

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

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

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

template <std::ostream& os = std::cout>
class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
#if __cplusplus >= 201703L
        auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) {
#else
        void operator()(const Args&... args) const {
#endif
            print(args...);
        }
        template <typename T>
#if __cplusplus >= 201703L
        auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) {
#else
        void pvec(const T& vec, size_t sz) const {
#endif
            for (size_t i = 0; i < sz; i++)
                os << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
#if __cplusplus >= 201703L
        auto pmat(const T& mat, size_t h, size_t w) const -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) {
#else
        void pmat(const T& mat, size_t h, size_t w) const {
#endif
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    os << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { os << term; }
        void print_rest() const { os << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints<> prints;
Prints<std::cerr> prints_err;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    Vl fib;
    fib.emplace_back(1);
    fib.emplace_back(1);
    while (true) {
        ll sz = (ll)fib.size();
        ll t = fib[sz - 1] + fib[sz - 2];
        if (t <= N) {
            fib.emplace_back(t);
        } else {
            break;
        }
    }
    ll sz = (ll)fib.size();
    Vi ans;
    for (ll i = 0; i < sz; i++) {
        if ((sz - 1 - i) % 2 == 0) {
            if (N >= fib[sz - 1 - i]) {
                ans.emplace_back(1);
                N -= fib[sz - 1 - i];
            }
            ans.emplace_back(4);
        } else {
            if (N >= fib[sz - 1 - i]) {
                ans.emplace_back(2);
                N -= fib[sz - 1 - i];
            }
            ans.emplace_back(3);
        }
    }
    prints()(ans.size());
    for (auto x : ans) {
        prints()(x);
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}


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

int main(){
  int N;
  double D,H;
  cin >> N >> D >> H;
  double ans=0;
  for(int i=0;i<N;i++){
    double d,h;
    cin >> d >> h;
    ans=max(ans,(H-(H-h)*D/(D-d)));
  }
  cout << ans <<endl;
}

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

int main(){
    double x, y, z;
    cin >> x >> y >> z;

    double a = y / x;

    for(int i = 0;;i++){
        if(a <= (double)i / z){
            cout << i - 1;
            break;
        }
    }

    return 0;
}


                #include<bits/stdc++.h>
                #define ll long long
                #define f first
                #define s second
                #define mod         1000000007
#define pb          push_back
                using namespace std;
                ll ans,n,m;
                map<ll,ll> vis,dp;
                ll recur(ll x)
                {
                    if(vis[x]) return dp[x];
                    vis[x]=1;
                    dp[x]=abs(x-n);
                    if(x==n) {return dp[x];}

                    if(x%2==0) dp[x]=min(dp[x],1+recur(x/2));
                    else
                    {
                        dp[x]=min({dp[x],1+recur(x-1),1+recur(x+1)});
                    }
                    return dp[x];
                }
                void solve()
                {

                    cin>>n>>m;
                    ans=abs(n-m);
                    //cout<<ans<<" ";
                    cout<<recur(m);

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

#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;
  #define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
  #define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)

int x;

map<int,int> dp;

int rec(int curr)
{
  if(curr <= x)return x-curr;
  if(dp.find(curr) != dp.end())return dp[curr];
  int ans = curr-x;

  if(curr%2 == 0)
  {
    if(curr/2 > x)ans = min(ans,1 + rec(curr/2));
    else ans = min(ans, 1 + x - curr/2);
  }
  else if(curr + 1 == x or curr - 1 == x)return 1;
  else
  {
    ans = min({ans,2 + rec((curr+1)/2),2 + rec((curr-1)/2)});
  }
  return dp[curr] = ans;
}
int32_t main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    int y;
    cin >> x >> y;

    cout << rec(y);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
template<class T> void chmax(T& a, T b){
    if(a < b){
        a = b;
    }
}
template<class T> void chmin(T& a, T b){
    if(a > b){
        a = b;
    }
}
int main()
{
    int n;
    cin >> n;
    cout << n-1 << endl;
    return 0;
}

//𝓬𝓮𝓭𝓮𝓼𝓲𝓸𝓷😎
#include<bits/stdc++.h>
using namespace std;
/*--------------------------*defines*-----------------------------*/
#define endl              "\n"
#define int               long long
#define mp                make_pair
#define pb                push_back
#define vi                vector<int>
#define cedesion          signed main
#define inf               INT_MAX
#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 all(v)            v.begin(),v.end()
#define dall(v)           v.begin(),v.end(),greater<int>()
/*--------------------------*defines*-----------------------------*/
/*--------------------------*functions*---------------------------*/
bool perfectSquare(long double x){
    long double sr = sqrt(x);return ((sr - floor(sr)) == 0);
}
long long modexp(long long n,long long p,long long c){
    if(p == 0)return 1;
    long long ans = 1;
    if(p%2)ans = n%c;
    return ((ans)*(modexp((n*n)%c,p/2,c)%c))%c;
}
/*--------------------------*functions*---------------------------*/
/*------------------------*work space*----------------------------*/
void test_case()
{
    int n;
    cin>>n;
    cout<<n-1<<endl;
}
cedesion()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    //for writing output in output.txt
    //freopen("output.txt", "w", stdout);
    //#endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        test_case();
    }

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i,a,b) for (ll i = (a); i < (ll)(b); i++)
#define rng(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

using namespace std;
template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }
template <class T> using vc = vector<T>;
template <class T> using vv = vc<vc<T>>;
template <class T> using vvv = vc<vv<T>>;
template <class T> using PQ = priority_queue<T, vc<T>, greater<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
using vvi = vv<int>;
using vvl = vv<ll>;

const ld pi = 3.141592653589793;
const ll linf = 1001001001001001001LL;
const int inf = 1001001001;

int main() {
  vc<string> s(3);
  rep(i,3) cin >> s[i];
  set<char> st;
  rep(i,3)rep(j,s[i].size()) st.insert(s[i][j]);
  if (st.size() > 10) {
    cout << "UNSOLVABLE" << endl;
    return 0;
  }
  int m = st.size();
  vc<char> mp(10, '.');
  int idx = 0;
  for (auto c : st) mp[idx++] = c;
  vi imp(26, -1);
  rep(i,10) if (mp[i] != '.') imp[mp[i]-'a'] = i;
  vi ord(10);
  rep(i,10) ord[i] = i;
  do {
    vc<string> t(3);
    rep(i,3) {
      rep(j,s[i].size()) {
        t[i].pb((char)(ord[imp[s[i][j]-'a']]+'0'));
      }
    }
    bool ok = true;
    rep(i,3) if (t[i][0] == '0') ok = false;
    if (!ok) continue;
    vl N(3);
    rep(i,3) N[i] = stoll(t[i]);
    if (N[0]+N[1] == N[2]) {
      rep(i,3) cout << N[i] << endl;
      return 0;
    }
  } while (next_permutation(rng(ord)));
  cout << "UNSOLVABLE" << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}

int main(){

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

    int N;
    cin >> N;
    vi A(N),B(N),Q(N);
    in(N,A);
    in(N,B);
    in(N,Q);

    ve<int> hab(N);
    rep(i,N) Q[i]--, hab[Q[i]] = i;

    pq2<pii> que;
    rep(i,N) que.push({B[i],i});

    int f = 1;
    ve<pii> ans;

    //outve(Q);

    rep(i,N){
        pii q = que.top();
        que.pop();

        int who = hab[q.se];

        if(q.se == who) continue;

        if(A[who] <= q.fi){
            f = 0;
            break;
        }

        int swapwho = q.se;
        if(A[swapwho] <= B[Q[swapwho]]){
            f = 0;
            break;
        }

        ans.pb({who+1, swapwho+1});
        swap(hab[Q[who]], hab[Q[swapwho]]);
        swap(Q[who], Q[swapwho]);

        //outve(Q);

    }

    if(f == 0) cout << -1 << endl;
    else{
        cout << si(ans) << endl;
        rep(i,si(ans)) cout << ans[i].fi csp ans[i].se << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

char change(char x,char y){
  char list[3]={'R','W','B'};
  if(x==y)return x;
  else{
    fr(i,3){
      if(x!=list[i]&&y!=list[i]) return list[i];
    }
  }
}

int main() {
    int n;
	cin >> n;
    string c;
    cin >> c;
    int a=1;
    while(a<n-1){
      a*=3;
    }
    while(n>1){
      while(a>n-1){a/=3;}
      fr(i,n-a){
        c[i]=change(c[i],c[i+a]);
      }
      n-=a;
    }
    cout << c[0] << endl;
}

#include<bits/stdc++.h>
#define REP(i,b,e) for(int i=b; i<e; i++)

struct binom_mod3 {
	std::vector<int> quo, rem;
	binom_mod3(int n): quo(n), rem(n) {
		quo[0] = 0;
		rem[0] = 1;
		for(int i=1; i<n; i++){
			int m = i, cnt = 0;
			while(m%3==0){
				m /= 3;
				cnt++;
			}
			quo[i] = quo[i-1] + cnt;
			rem[i] = rem[i-1] * m % 3;
		}
	}

	int eval(int n, int k){
		assert(n < quo.size());
		if(n<0 || k<0 || n<k) return 0;
		if(quo[n] > quo[k] + quo[n-k]) return 0;
		int num = rem[n], den = rem[k] * rem[n-k] % 3;
		return num * den % 3;
	}
};

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

	getchar();
	binom_mod3 bi3(5e5);

	int m = 0;
	REP(i, 0, n){
		char c = getchar();
		int a = (c=='B')? 0: (c=='W')? 1:2;
		m += a * bi3.eval(n-1, i) % 3;
		m %= 3;
	}
	if(n%2==0) m = (3 - m) % 3;
	printf("%c\n", "BWR"[m%3]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const long long INF = 1e18;;
typedef long long ll;
bool punched[3][3];

//using Graph = vector<vector<int> >;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

//Union-Find
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

bool ok(int v, int b) {
    while (v) {
        if (v % b == 7) return false;
        v /= b;
    }
    return true;
}

struct zahyou{
    int h;
    int w;
};

ll digit(ll x) {
    ll cnt = 0;
    while(x > 0) {
    x /= 10;
    cnt++;
    }
    return cnt;
}

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

int main(){
   int x,y;
   cin >> x >>y;
   if (x == y) cout << x << endl;
   else cout << 3 - x - y << endl;

}

#include <bits/stdc++.h>

#define nl "\n"
#define ll long long
#define vii(N,M,x) vector<vector<long long>> x(N,vector<long long>(M))
#define pb push_back
#define ii pair<int,int>
#define ft first
#define sd second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()

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

using namespace std;

void solve(/*int caseN*/)
{
	int x,y; cin>>x>>y;

	if(x==y)
	{
		cout<<x;
	}
	else
	{
		int ans=-1;
		for(int i=0;i<3;i++)
		{
			if(i!=x && i!=y)
			{
				ans=i;
			}
		}
		cout<<ans;
	}
}

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

    //int T; cin>>T;
    //while(T--)
        solve(/*T*/);
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,n) for (int i = a; i < n; i++)
#define fr(i,a,n) for (int i = n; i >=a; i--)
#define mod9 1000000009
#define mod7 1000000007
#define INF 1e18
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define ff first
#define ss second
#define pii pair<int, int>
#define mii map<int, int>
#define mkp make_pair
#define pb push_back
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)

signed main()
{
int x,y;
cin>>x>>y;
int c0=0,c1=0,c2=0;
if(x==0 || y==0)
c0++;
 if(x==1 || y==1)
c1++;
 if(x==2 || y==2)
c2++;

//cout<<c0<<" "<<c1<<" "<<c2<<endl;
if(x==y)
cout<<x<<endl;
else
{
    if(c0==0)
    cout<<"0"<<endl;
    else if(c1==0)
    cout<<"1"<<endl;
    else if(c2==0)
    cout<<"2"<<endl;

}
}

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

int main(){
    int x, y;
    cin >> x >> y;
    cout << (x==y ? x : 3-x-y) << endl;
}


#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
ll MOD = 998244353;
int H,W;
vector<vector<int>> M;

int main() {
	cin >> H >> W;
	M.assign(H + 1, vector<int>(W + 1, 0));

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			char a;
			cin >> a;
			if (a == 'R')M[i][j] = 1;
			else if (a == 'B')M[i][j] = -1;
		}
	}
	ll ans = 1;
	for (int i = H + W; i >= 2; i--) {
		int k = 0;
		for (int j = max(i - H, 1); j <= min(W,i-1); j++) {
			if (M[i - j][j] != 0) {
				if (k == 0) {
					k = M[i - j][j];
				}
				else if (k != M[i - j][j]) {
					ans = 0;
					goto SKIP;
				}
			}
		}
		if (k == 0) {
			ans *= 2;
			ans %= MOD;
		}
	}

	SKIP:
	cout << ans;
}

#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif

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

#pragma region macros

using str=string;
using ll=long long;
using vl=vector<ll>;
using vc=vector<char>;
using pl=pair<ll,ll>;
using ml=map<ll,ll>;
using sl=set<ll>;
template<class T> using V=vector<T>;
template<class T,class U> using P=pair<T,U>;

#define FOR(n) for(ll i=0;i<n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=1;i<n;i++)
#define REP(i,m,n) for(ll i=m;i<n;i++)
#define drep(i,n) for(ll i=n-1;i>=0;i--)
#define fore(n) for(auto&& i:n)
#define fors(n) for(auto&&[i,j]:n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sor(v) sort(all(v))
#define rsor(v) sort(rall(v))
#define rev(v) reverse(all(v))
#define low(v,x) lower_bound(all(v),x)-v.begin()
#define up(v,x) upper_bound(all(v),x)-v.begin()
#define acc(v) accumulate(all(v),0LL)
#define ef(x) emplace_front(x)
#define eb(x) emplace_back(x)
#define pf() pop_front()
#define pb() pop_back()
#define mp(a,b) make_pair(a,b)
#define ceil(a,b) (a+b-1)/b
#define bit(n) (1LL<<n)

#define fi first
#define se second
#define fr front()
#define ba back()
#define be begin()
#define en end()
#define br break
#define cn continue
#define wh while
#define el else if
#define re return

const ll inf=1LL<<60;
const ll mod=1000000007;
const ll MOD=998244353;
const double pi=3.1415926535;
const double eps=1e-10;
const ll dx[4]={1,0,-1,0};
const ll dy[4]={0,1,0,-1};

void input(){}
void inputs(){}
void output(){}
template<class T,class...U> void input(T& x,U&...y){cin>>x;input(y...);}
template<class...T> void in(T&...x){input(x...);}
template<class T> void inputs(const ll t,T& x){cin>>x[t];}
template<class T,class...U> void inputs(const ll t,T& x,U&...y){cin>>x[t];inputs(t,y...);}
template<class T,class...U> void inputs(T& x,U&...y){rep(t,size(x))inputs(t,x,y...);}
template<class...T> void ins(T&...x){inputs(x...);}
template<class T,class...U> void output(T x,U...y){cout<<x<<"\n";output(y...);}
template<class...T> void out(T...x){output(x...);}
template<class...T> void fin(T...x){out(x...);exit(0);}
template<class T> istream&operator>>(istream& i,V<T>& v){for(T& x:v)i>>x;re i;}
template<class T,class U> istream&operator>>(istream& i,P<T,U>& p){re i>>p.fi>>p.se;}
template<class T> ostream&operator<<(ostream& o,V<T>& v){for(T& x:v)o<<x<<" ";re o;}
template<class T,class U> ostream&operator<<(ostream& o,P<T,U>& p){re o<<p.fi<<" "<<p.se;}

void yn(bool b){fin((b?"Yes":"No"));}
void YN(bool b){fin((b?"YES":"NO"));}
void pos(bool b){fin((b?"POSSIBLE":"IMPOSSIBLE"));}
template<class T,class U> void chmax(T& a,U b){if(a<b)a=b;}
template<class T,class U> void chmin(T& a,U b){if(a>b)a=b;}
template<class T,class U> auto max(T a,U b){re a>b?a:b;}
template<class T,class U> auto min(T a,U b){re a<b?a:b;}
ll qp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r*=x;x*=x;n>>=1;}re r;}
ll mdp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%mod;x=x*x%mod;n>>=1;}re r;}
ll MDp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%MOD;x=x*x%MOD;n>>=1;}re r;}

struct UnionFind{
    vl par,sz;
    UnionFind(ll n):par(n),sz(n,1){rep(i,n) par[i]=i;}
    ll rot(ll x){
        if(par[x]==x) re x;
        re par[x]=rot(par[x]);
    }
    void uni(ll x,ll y){
        x=rot(x),y=rot(y);
        if(x==y) re;
        if(sz[x]<sz[y]) swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool eql(ll x,ll y){re rot(x)==rot(y);}
    ll siz(ll x){re sz[rot(x)];}
};

struct IOSetup{
    IOSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout<<fixed<<setprecision(10);
    }
}iosetup;

#pragma endregion

signed main(){
    ll h,w; in(h,w);
    V<str> s(h); in(s);

    ll ans=1;
    V<vc> v(h+w-1);
    rep(i,h) rep(j,w) v[i+j].eb(s[i][j]);
    rep(j,h+w-1){
        bool a=0,b=0;
        fore(v[j]){
            if(i=='R') a=1;
            if(i=='B') b=1;
        }
        if(a&&b) fin(0);
        if(!a&&!b){
            ans*=2;
            ans%=MOD;
        }
    }
    out(ans);
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;

const int N = 2e5 + 5;
int h, w, m, ans, xmn[N], ymn[N], bit[N];
bitset<N> b;
vector<int> v[N];

void add(int i){
    for(; i <= h; i += (i&-i)) bit[i]++;
}

int query(int i){
    int res = 0;
    for(; i > 0; i -= (i&-i)) res += bit[i];
    return res;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> h >> w >> m;
    for(int i = 1; i <= h; i++) xmn[i] = w + 1;
    for(int j = 1; j <= w; j++) ymn[j] = h + 1;
    while(m--){
        int x, y;
        cin >> x >> y;
        xmn[x] = min(xmn[x], y);
        ymn[y] = min(ymn[y], x);
        v[y].pb(x);
    }
    for(int i = 1; i < ymn[1]; i++){
        ans += xmn[i] - 1;
    }
    for(int i = ymn[1]; i <= h; i++)
        add(i), b[i] = 1;
    for(int i = 2; i < xmn[1]; i++){
        ans += query(ymn[i] - 1);
        for(int j : v[i])
            if(!b[j]) b[j] = 1, add(j);
    }
    cout << ans;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//optimal subsequences-2 technocup round-3 2020
using namespace std;
using namespace __gnu_pbds;
const int N=2e5+10;
//#define d double
#define F first
#define S second
#define ll long long int
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(6)
const int M=1e9+7;
//const int M=998244353;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
//#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
//int MOD=998244353;
//const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

//ll d1=304933,d2=4395853;

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

//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;
//#ifndef ONLINE_JUDGE
//freopen("input.txt", "r" , stdin);
//freopen("output.txt", "w", stdout);
//#endif

ll MOD;

ll power(ll a,ll b)
{
    ll res=1;
    if(a==1)return 1;
    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a);
        if(res>MOD)res%=MOD;
        a=(a*a);
        if(a>MOD)a=a%MOD;
    }
    return res;
}

bool isPrime[3000000+1];
vector<ll>prime;

vector<int>divisor;

void seive2(int limit)
{
    divisor=vector<int>(limit+1,0);

    for(int i=2;i<=limit;i++)
    {
        if(divisor[i]==0)
        {
            divisor[i]=i;
            if(i*1ll*i<=limit)
            for(int j=i*i;j<=limit;j+=i)divisor[j]=i;
        }
    }
}

void seive(int limit)
{
    isPrime[0]=isPrime[1]=1;

    for(int i=2;i*i<=limit;i++)
    {
        if(!isPrime[i])
        for(int j=i*i;j<=limit;j+=i)
        {
            isPrime[j]=1;
        }
    }
    for(int i=2;i<=limit;i++)if(!isPrime[i])prime.pb(i);
}

#define pii pair<ll,pi>
ll pt[200010],sz[200010],wt[200010];

int finds(int x)
{
    while(pt[x]!=x)
    {
        pt[x]=pt[pt[x]];
        x=pt[x];
    }
    return pt[x];
}

bool unions(int x,int y)
{
    int px=finds(x),py=finds(y);

    if(px==py)return 0;

    if(sz[px]>sz[py])swap(px,py);

    pt[px]=py;
    sz[py]+=sz[px];
    wt[py]+=wt[px];

    return 1;
}

ll bit[200100];

ll query(ll bit[],int x)
{
    ll ans=0;
    for(int i=x;i>0;i-=(i&(-i))){
        ans+=bit[i];
    }
    return ans;
}

void update(ll bit[],int x,ll val)
{
    for(int i=x;i>0;i-=(i&(-i)))
        bit[i]+=val;
}

void update2(ll bit[],int x,ll val)
{
    for(int i=x;i<=600005;i+=(i&(-i)))
        bit[i]+=val;
}

ll query2(ll sum[],int x)
{
    ll ans=0;
    for(int i=x;i<=200005;i+=(i&(-i)))
        ans+=sum[i];
    return ans;
}

void dfs(int s,vector<int>&v,vector<int>&P,int visited[])
{
    visited[s]=1;
    v.pb(s);

    int x=P[s];

    if(!visited[x])
    {
        dfs(x,v,P,visited);
    }
}

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

    ll a[k+1];
    f(k)cin>>a[i+1];

    vector<ll>v;

    ll sum=0;

    f(k)
    {
        ll x=(a[i+1]*m+n-1)/n;
        v.pb(x);
        sum+=x;
    }

    set<pi>s;

    f(k)
    {
        ll b=v[i]-1;
        ll d=b*n-a[i+1]*m;
        s.insert({abs(d),i});
    }

    ll d=sum-m;

    while(d)
    {
        auto it=*s.begin();
        s.erase(it);

        int id=it.S;
        v[id]--;
        d--;
    }

    for(int x:v)cout<<x<<' ';

}

int main()
{
    //FastIO;

    int t=1;
//    cin>>t;

	for(int i=1;i<=t;i++)
    {
       // cout<<"Case #"<<i<<": ";
        solve();
        //if(i!=t)cout<<endl;
    }
	return 0;
}


// Username: WillTheBill
// Time of creation: 2020-11-22 12:48
// Original filename: m.cp.cpp

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

// shortcuts
#define pb push_back
#define fi first
#define se second
#define all(_v) _v.begin(),_v.end()
#define ll long long

// IO
#define multitest signed __T; cin >> __T; while(__T--)
template<typename T>
void _read(T& t);
template<typename T>
void _read(vector<T>&v);
template<typename T1, typename T2>
void _read(pair<T1,T2>&p);
template<typename T>
void _read(T& t){cin >> t;}
template<typename T>
void _read(vector<T>&v){for(unsigned _i=0;_i<v.size();_i++)_read(v[_i]);}
template<typename T1, typename T2>
void _read(pair<T1,T2>&p){_read(p.first);_read(p.second);}
void _masterread(){}
template<typename T,typename... V>
void _masterread(T& t, V&... v){_read(t);_masterread(v...);}
#define re(...)_masterread(__VA_ARGS__)

template<typename T>
void _print(T t);
template<typename T>
void _print(vector<T>&v);
template<typename T1, typename T2>
void _print(pair<T1,T2>&p);
template<typename T>
void _print(T t){cout<<t;}
template<typename T>
void _print(vector<T>&v){for(unsigned _i=0;_i<v.size();_i++)_print(v[_i]),cout<<(_i==v.size()-1?"":" ");}
template<typename T1, typename T2>
void _print(pair<T1,T2>&p){_print(p.first);cout<<" ";_print(p.second);}
void _masterprint(){cout<<endl;}
template<typename T,typename... V>
void _masterprint(T t, V... v){_print(t);if(sizeof...(v))cout<<" ";_masterprint(v...);}
#define pr(...)_masterprint(__VA_ARGS__)

// DEBUG
// colored output???
template <typename T> // start forward declaration
void _debug(T t);
template<typename T1,typename T2>
void _debug(pair<T1,T2> p);
template<typename T>
void _debug(vector<T>v);
template <typename T> // end forward declaration
void _debug(T t){cerr<<t;}
template<typename T1,typename T2>
void _debug(pair<T1,T2> p){cerr<<"{";_debug(p.first);cerr<<", ";_debug(p.second);cerr<<"}";}
template<typename T>
void _debug(vector<T>v){cerr<<"(";for(unsigned _i=0;_i<v.size();_i++)_debug(v[_i]),cerr<<(_i==v.size()-1?"":", ");cerr << ")";}
void _masterdebug(){cerr<<"]\n";}
template<typename T,typename... V>
void _masterdebug(T t,V... v){_debug(t);if(sizeof...(v))cerr<<", ";_masterdebug(v...);}
#ifdef __local__
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"] = [";_masterdebug(__VA_ARGS__)
#else
#define debug(...)
#endif

// TYPES
// #define int long long

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	int a,b,c,d; re(a,b,c,d);
	pr(a * d - b * c);
}

#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007
#define INF INT_MAX
#define FLOAT_ANS setprecision(10)

using namespace std;
typedef long long ll;

//最大公約数
template<typename T>
T gcd(T a, T b) {
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}

//Segment Tree(遅延評価)
template<typename T>
class SegTreeLazy {

	//参照：https://algo-logic.info/segment-tree/
public:
	//変数定義
	ll N;  //長さ
	T e; //単位元
	vector<T>seg; //基本
	vector<T>lazy; //遅延用
	function<T(T, T)> f; //比較用

	SegTreeLazy(ll n, ll e_, function<T(T, T)> f_) {
		//サイズ・単位元・比較用の関数
		e = e_;
		f = f_;

		//サイズnのSegTreeに必要な要素数
		ll x = 1;
		while (n > x) {
			x *= 2;
		}
		N = x;

		seg.resize(2 * N - 1, e);
		lazy.resize(2 * N - 1, e);
	}

	T get(ll i){
		return seg[i+N-1];
	}

	void eval(ll k) {
		//lazyから更新情報を取得、segに反映
		if (lazy[k] == e) return; //更新情報がなければ終了
		if (k < N - 1) { //自身が葉でないのなら子にも伝搬させる(zipを解凍)
			lazy[k * 2 + 1] = lazy[k];
			lazy[k * 2 + 2] = lazy[k];
		}

		//最後に、自身を更新
		seg[k] = lazy[k];
		//もう更新情報に用はないので、初期化
		lazy[k] = e;
	}

	void update(ll a, ll b, T x, ll k, ll l, ll r) {
		// a･b:全体の範囲
		// k･l:現在更新するn層目の範囲
		// x:更新する値
		// k:セグ木の配列における位置

		eval(k); //まずは更新(sudo apt update　と同じ感じ?)
		if (a <= l && r <= b) {// 内部にある(端でない)
			//現在の層についてのみ更新させる
			lazy[k] = x;
			eval(k);
		}
		else if (a < r && l < b) {// 一部区間がかぶる
			update(a, b, x, k * 2 + 1, l, (l + r) / 2); //右の子に伝搬
			update(a, b, x, k * 2 + 2, (l + r) / 2, r); //左の子に伝搬
			seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]);
		}
	}
	void update(ll a, ll b, T x) {
		//(a)-(b-1)の範囲をxに更新
		update(a, b, x, 0, 0, N);
	}
	void update(ll a, T x) {
		//aをxに更新
		update(a, a + 1, x, 0, 0, N);
	}

	T query_sub(ll a, ll b, ll k, ll l, ll r) {
		eval(k);
		if (r <= a || b <= l) {  //完全に外部
			return e;
		}
		else if (a <= l && r <= b) {  //完全に内部
			return seg[k];
		}
		else {
			T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);

			return f(vl, vr); //右の子と左の子の小さい方
		}
	}
	T query(int a, int b) {
		return query_sub(a, b, 0, 0, N);
	}
};

int main(void) {
	ll n;
	cin>>n;
	vector<ll>p(n);
	vector<bool>dp(200010,false);
	ll ans=0;
	rep(i,n){
		cin>>p[i];
		dp[p[i]]=true;
		while(dp[ans]){
			++ans;
		}
		cout<<ans<<endl;
	}
}

/*

*/


#include <bits/stdc++.h>

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

constexpr ll mod = 998244353;

ll pow(ll x, ll m)
{

    ll re = 1, y = 1;

    for (int i = 0; i < 60; ++i)
    {
        if (m & y)
            re = re * x % mod;
        x = x * x % mod;
        y *= 2;
    }

    return re;
}

ll inv(ll x)
{

    return pow(x, mod - 2);
}

class mint
{
    ll num = 0;

public:
    mint(ll x = 0) : num(x) {}

    mint operator+(const mint &rhs) const
    {
        return (num + rhs.num) % mod;
    }
    mint operator*(const mint &rhs) const
    {
        return num * rhs.num % mod;
    }
    mint operator-(const mint &rhs) const
    {
        return (num - rhs.num + mod) % mod;
    }
    mint operator/(const mint &rhs) const
    {
        return num * inv(rhs.num) % mod;
    }
    mint operator+=(const mint &rhs)
    {
        return *this = *this + rhs;
    }
    mint operator*=(const mint &rhs)
    {
        return *this = *this * rhs;
    }
    mint operator-=(const mint &rhs)
    {
        return *this = *this - rhs;
    }
    mint operator/=(const mint &rhs)
    {
        return *this = *this / rhs;
    }
    friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
    friend std::istream &operator>>(std::istream &is, const mint &rhs);
};

std::ostream &operator<<(std::ostream &os, const mint &rhs)
{

    os << rhs.num;

    return os;
}

/*std::istream &operator>>(std::istream &is, const mint &rhs)
{
    is >> rhs.num;

    return is;
}*/

constexpr int MAX = 2 * 1e5 + 10;
mint s[MAX], b[MAX], a[MAX];
mint fact[MAX];

mint comb(ll x, ll y)
{
    return fact[x] / fact[x - y] / fact[y];
}

int main()
{
    int n, K;

    std::cin >> n >> K;

    rep(i, n)
    {
        ll in;
        std::cin >> in;
        b[i] = a[i] = in;
    }

    fact[0] = 1;
    for (int i = 1; i <= K; ++i)
        fact[i] = fact[i - 1] * i;

    s[0] = 1;

    for (int i = 1; i <= K; ++i)
    {
        rep(j, n)
            s[i] += b[j];

        rep(j, n)
            b[j] *= a[j];
    }

    mint p2 = 1;

    for (int x = 1; x <= K; ++x)
    {
        mint ans = (mint(n - 1) - p2) * s[x];
        mint res = 0;
        for (int i = 0; i <= x; ++i)
        {
            res += comb(x, i) * s[x - i] * s[i];
        }
        res /= 2;
        ans += res;
        std::cout << ans << std::endl;
        p2 *= 2;
    }

    return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define uniq(a) (a).erase(unique(all(a)), (a).end())
#define bit(n) (1LL << (n))
#define dump(a) cerr << #a " = " << (a) << endl
#define fin(a)                                                                                \
    cout << (a) << endl;                                                                                \
    return 0
using vint = vector<int>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template <typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int a) {
    return (a > 0) - (a < 0);
}
int cdiv(int a, int b) {
    return (a - 1 + b) / b;
}
template <typename T> T sq(T a) {
    return a * a;
}
template <typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) {
    os << "(" << a.first << ", " << a.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int a, b;
    cin >> a >> b;
    int ans = 1;
    reps(i, 220000) {
        int x = cdiv(a, i) * i;
        int y = x + i;
        if (a <= x && y <= b) {
            chmax(ans, i);
        }
    }
    cout << ans << endl;
}


#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 555;
const int MO = 998244353;
int n,m,a[N][N],b[N*2][3];
char s[N];
int main()
{
	int i,j,x;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%s",s+1);
		for(j=1;j<=m;j++){
			if(s[j]=='.')
				a[i][j]=0;
			else{
				if(s[j]=='B')
					a[i][j]=1;
				else
					a[i][j]=2;
			}
			b[i+j][a[i][j]]++;
		}
	}
	x=1;
	for(i=2;i<=n+m;i++){
		if(b[i][1]&&b[i][2])
			x=0;
		else{
			if(b[i][1]||b[i][2])
				;
			else
				x=x*2%MO;
		}
	}
	cout<<x;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define int long long
template<typename T>
void dbg_a(T *a,int l,int r){cout<<" {";for(int i = l;i<r;i++) cout<<a[i]<<", ";cout<<a[r]<<"}"<<endl;}
typedef long long ll;
template<typename T = int>
inline T read(){
    T f = 1,r = 0;
    char c = getchar();
    while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
    while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
    return f*r;
}
typedef pair<int,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define _for(i,a) for(int i = 0;i<a;i++)
#define All(x) x.begin(),x.end()

//    For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",a,b,c);

const int N = 2e5 + 5,M = N*8 + 10,INF = 1e18;
const int mod = 1e9 + 7;
int n,m;

void solve(){
    int x = read(),y = read();
    if(y <= x){
        cout<<(x - y)<<"\n";
        return ;
    }
    queue<PII> q;
    set<int> s;

    q.push({y,0});
    s.insert(y);
    int ans = INF;
    while(q.size()){
        auto [t,d] = q.front();
        q.pop();
        if(d > ans) continue;
        ans = min(ans,abs(t - x) + d);
        if(t % 2 == 0){
            if(!s.count(t/2)){
                q.push({t/2,d+1});
                s.insert(t/2);
            }
        }
        else{
            if(!s.count(t + 1)){
                q.push({t + 1,d + 1});
                s.insert(t + 1);
            }
            if(!s.count(t - 1)){
                q.push({t - 1,d + 1});
                s.insert(t - 1);
            }
        }
    }
    cout<<ans<<"\n";

}

signed main(){
    int T = 1;
    //T = read();
    while(T--) solve();
    system("pause");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define endl ("\n")
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<lli>
#define ff first
#define ss second
#define rep(i, a, b) for (lli i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i > b; i--)
#define mod 1000000007
#define all(s) s.begin(), s.end()
int main() {
    fast
    lli tt, a, b, k;
    tt = 1;
    // cin>>tt;
    while (tt--) {
        cin>>a>>b>>k;
        lli ncr[61][61], n = a + b;
        string ans = "";
        ncr[0][0] = 1;
        rep (i, 1, 61) {
            ncr[i][0] = 1;
            rep (j, 1, i + 1) {
                ncr[i][j] = ncr[i - 1][j] + ncr[i-  1][j - 1];
            }
        }
        rep (i, 0, n) {
            if (ncr[a - 1 + b][b] >= k) ans += 'a', a--;
            else ans += 'b', k -= ncr[a - 1 + b][b], b--;
        }
        cout<<ans;
    }
    return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << s.substr(0, i) << " = " << x << " | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}

const int MAX = 65;

long long choose[MAX][MAX];

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

    for (int i=0; i<MAX; i++)
        choose[i][0] = 1;
    for (int i=1; i<MAX; i++)
        for (int j=1; j<MAX; j++)
            choose[i][j] = choose[i-1][j] + choose[i-1][j-1];

    int a, b;
    long long k;
    cin >> a >> b >> k;
    int n = a + b;

    for (int i=0; i<n; i++) {
        if (a == 0) {
            cout << 'b';
            b--;
            continue;
        }
        if (k <= choose[a+b-1][b]) {
            cout << 'a';
            a--;
        } else {
            k -= choose[a+b-1][b];
            cout << 'b';
            b--;
        }
    }
    cout << "\n";

    return 0;
}


#include <cstdio>
#include <cstdlib>
using namespace std;
#define ll long long
const ll MAXN = 400011;

struct fhqTreap {
	ll tot, rt;
	ll val[MAXN], sum[MAXN], sz[MAXN], ls[MAXN], rs[MAXN], rd[MAXN];

	void pushup(ll u) {sz[u] = sz[ls[u]] + sz[rs[u]] + 1; sum[u] = sum[ls[u]] + sum[rs[u]] + val[u];}

	void split(ll u, ll k, ll &x, ll &y) {
		if(!u) {x = y = 0; return;}
		if(val[u] <= k) x = u, split(rs[u], k, rs[u], y);
		else y = u, split(ls[u], k, x, ls[u]);
		pushup(u);
	}

	ll merge(ll u, ll v) {
		if(!u || !v) return u | v;
		if(rd[u] < rd[v]) {rs[u] = merge(rs[u], v); pushup(u); return u;}
		else {ls[v] = merge(u, ls[v]); pushup(v); return v;}
	}

	ll add(ll k) {
		rd[++tot] = rand();
		sz[tot] = 1;
		val[tot] = sum[tot] = k;
		return tot;
	}

	void insert(ll k) {
		ll x, y;
		split(rt, k, x, y);
		rt = merge(merge(x, add(k)), y);
	}

	ll cb(ll k) {
		ll x, y;
		split(rt, k, x, y);
		ll ans = sz[x] * k + sum[y];
		rt = merge(x, y);
		return ans;
	}

	void delet(ll k) {
		ll x, y, z;
		split(rt, k, x, z);
		split(x, k - 1, x, y);
		y = merge(ls[y], rs[y]);
		rt = merge(merge(x, y), z);
	}
} t[2];

ll q;
ll len[2];
ll w[2][MAXN];

ll read() {
	ll X = 0, F = 1; char C = getchar();
	while(C < '0' || C > '9') {if(C == '-')F=-1; C = getchar();}
	while(C >= '0' && C <= '9') {X = X*10+C-'0'; C = getchar();}
	return X * F;
}

int main() {
	ll ans = 0;
	len[1] = read(); len[0] = read(); q = read();
	for(ll i = 0; i < 2; ++i)
		for(ll j = 1; j <= len[i]; ++j)
			t[i].rt = t[i].merge(t[i].rt, t[i].add(0));
	for(ll i = 1, opt, x, y; i <= q; ++i) {
		opt = (read() & 1); x = read(); y = read();
		t[opt].delet(w[opt][x]);
		t[opt].insert(y);
		ans -= t[opt^1].cb(w[opt][x]);
		w[opt][x] = y;
		ans += t[opt^1].cb(w[opt][x]);
		printf("%lld\n", ans);
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int a, b;
  cin >> a >> b;
  int sum = 0;
  if (a >= b) {
    rep2(i, 1, a + 1) {
      cout << i << " ";
      sum += i;
    }
    rep2(i, 1, b) {
      cout << -1 * i << " ";
      sum -= i;
    }
    cout << -1 * sum << endl;
  } else {
    rep2(i, 1, b + 1) {
      cout << -1 * i << " ";
      sum += i;
    }
    rep2(i, 1, a) {
      cout << i << " ";
      sum -= i;
    }
    cout << sum << endl;
  }
  return 0;
}