#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
LLONG K, N, M;
vector<LLONG> As, Bs;

bool CanDo(const LLONG x)
{
	vector<LLONG> Ls(K), Rs(K);
	REP(i, K)
	{
		LLONG Ai = As[i];
		Ls[i] = (M * Ai - x + N - 1) / N;
		Rs[i] = (M * Ai + x) / N;
	}
	LLONG sumB = accumulate(Ls.begin(), Ls.end(), 0LL);
	REP(i, K) Bs[i] = Ls[i];
	REP(i, K)
	{
		if (sumB >= M) break;
		LLONG maxDiff = min(M - sumB, Rs[i] - Ls[i]);
		sumB += maxDiff;
		Bs[i] += maxDiff;
	}
	return accumulate(Ls.begin(), Ls.end(), 0LL) <= M && M <= accumulate(Rs.begin(), Rs.end(), 0LL);
}

int main()
{
	cin >> K >> N >> M;
	As.assign(K, 0);
	Bs.assign(K, 0);
	REP(i, K) cin >> As[i];
	LLONG ng = 1;
	LLONG ok = N * M;
	while (ok > ng + 1)
	{
		LLONG m = (ok + ng) / 2;
		if (CanDo(m))
		{
			ok = m;
		}
		else
		{
			ng = m;
		}
	}
	CanDo(ok);
	for (const LLONG bi : Bs)
	{
		cout << bi << ' ';
	}
	cout << endl;
}

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

#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

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

//insert,find_by_order,order_of_key,lower_bound,upper_bound;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

//////////////////////////////code//////////////////////////////

const int N = 200;

bool cmp(pii p1 , pii p2)
{
        return p1.ss < p2.ss;
}

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

        vi arr(k);

        for(int i = 0;i < k; i++)
          cin >> arr[i], arr[i]*=m;

        vi ans;

        int sum = m;

        for(int i = 0;i < k; i++)
        {
                ans.pb(arr[i]/n);
                sum -= arr[i]/n;
        }

       set<pii>s;

       for(int i = 0;i < k ;i++)
       {
            s.insert({arr[i]-ans[i]*n,i});
       }

     //  deb(sum);

       while(sum > 0)
       {
                auto it = (--s.end());

                sum--;
                ans[it->ss]++;
                int diff = arr[it->ss] - ans[it->ss]*n;
                int j = it->ss;
                s.erase(it);
                s.insert({diff,j});
       }

       show(ans , 0 , k - 1);

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

     #ifndef ONLINE_JUDGE
     freopen("INP.txt", "r", stdin);
     freopen("out.txt", "w", stdout);
     #endif

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

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(v,n) for(ll i=0;i<n;i++){ll var;cin>>var;v.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod = 1e9+7;
#define mod2 998244353
#define piii 3.14159265358979323846264338327950
#define print(a, n, m)     for (ll i = n; i < m; i++) {  cout << a[i] << " "; } // cout << endl
#define con continue

bool prime(ll n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return 1;
    if (n%2 == 0 || n%3 == 0) return false;

    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return 1;
}
bool isPerfectSquare(ll x) {
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
bool isPowerOfTwo(ll n) {
    return n > 0 && !(n&(n-1));
}
bool subsequence_checker(string str1, string str2, ll m, ll n)
{
    if (m == 0) return 1;
    if (n == 0) return false;
    if (str1[m-1] == str2[n-1])
        return subsequence_checker(str1, str2, m-1, n-1);
    return subsequence_checker(str1, str2, m, n-1);
}
bool cmp(const pair<ll,ll> &a,  const pair<ll,ll> &b)
{
    if(a.ff == b.ff)
        return a.ss < b.ss;
    return (a.ff > b.ff);
}
ll gcd(ll p, ll q){
if(p % q == 0)return q;
return gcd(q, p % q);
}
ll countDigit(ll n)
{
    return floor(log10(n) + 1);
}
ll power(ll a,ll n)
{
  if(n==0)
    return 1;
  if(n%2)
    return (a*power((a*a)%mod,n/2))%mod;
  return power((a*a)%mod,n/2);
}
ll fast_pow(ll a, ll p) {
    ll res = 1;
    while (p) {
        if (p % 2 == 0) {
            a = (a * a) % mod;
            p /= 2;
        } else {
            res = (res * a) % mod;
            p--;
        }
    }
    return res;
}
ll setBitNumber(ll n)
{
    n |= n >> 1;
    n |= n >> 2;

    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;
    n = n + 1;

    return (n >> 1);
}
ll ncr(ll n , ll r)
{
    if(n<r) return 0;
    if(r==1) return n;
    if(r==2) return (n*(n-1))/2;
    return (n*(n-1)*(n-2))/6;
}
ll countDivisors(ll n) {
    ll count =0 ;
    for (ll i = 1; i*i < n; i++)
        if (n % i == 0)
            count++;
    for (ll i = sqrt(n); i >= 1; i--)
        if (n % i == 0)
            count++;
    return count;
}
vector<ll> printDivisors(ll n){
    vector<ll> d ;
    for (ll i = 1; i*i < n; i++)
        if (n % i == 0){
            d.push_back(i);
            //cout<<i<<" ";
        }
    for (ll i = sqrt(n); i >= 1; i--)
        if (n % i == 0){
            d.push_back(n/i);
            //cout<<n/i<<" ";
        }
    return d;
}
///////////////////////////////////Lets Do It///////////////////////////////////
void solve()
{

    ld v,t,s,d;
    cin>>v>>t>>s>>d;

    ld time = d/v;

    if(time>s || time < t )
    {
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

    return;
}

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

    ll t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
   double v,t,s,d;
   cin>>v>>t>>s>>d;
    if(d/v<t || d/v>s)
    cout<<"Yes";
    else
    cout<<"No";
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;
ll N, K;
ll A[1000][1000];
ll B[1000][1000];

bool f(ll border) {
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            B[i+1][j+1] = (A[i][j] <= border);
        }
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            B[i][j] = B[i][j] + B[i-1][j] + B[i][j-1] - B[i-1][j-1];
        }
    }
    for(int i = 0; i + K <= N; i++) {
        for(int j = 0; j + K <= N; j++) {
            ll num = B[i+K][j+K] - B[i][j+K] - B[i+K][j] + B[i][j];
            if(num >= (K * K + 1) / 2) return true;
        }
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) cin >> A[i][j];
    }
    ll ok = 1e10;
    ll ng = -1;
    while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
namespace Ruri{
    #define ms(a,b) memset(a,b,sizeof(a))
    #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?
    #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)
    #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
    #define ce(i,r) i==r?'\n':' '
    #define pb push_back
    #define all(x) x.begin(),x.end()
    #define gmn(a,b) a=min(a,b)
    #define gmx(a,b) a=max(a,b)
    #define fi first
    #define se second
    typedef long long ll;
    typedef unsigned long long ull;
    typedef double db;
    const int infi=1e9;//infi较大，注意涉及inf相加时爆int
    const ll infl=4e18;
    inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
    inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; }
    //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
}
using namespace Ruri;
namespace Read{
    #define ss(a) scanf("%s",a)
    inline int ri(){ int x; scanf("%d",&x); return x; }
    inline ll rl(){ ll x;  scanf("%lld",&x); return x; }
    inline db rd(){ db x; scanf("%lf",&x); return x; }
}
namespace DeBug{
    #define pr(x) cout<<#x<<": "<<(x)<<endl
    #define pra(x,a,b) cout<<#x<<": "<<endl; \
            repi(i,a,b) cout<<x[i]<<" ";     \
            puts("");
    #define FR(a) freopen(a,"r",stdin)
    #define FO(a) freopen(a,"w",stdout)
}
using namespace Read;
using namespace DeBug;
const int MAX_N=805;
int n,k,median;
int a[MAX_N][MAX_N];
int sum[MAX_N][MAX_N];
bool Check(int x)
{
    repi(i,1,n)repi(j,1,n) sum[i][j]=(a[i][j]>x);
    repi(i,1,n)repi(j,1,n) sum[i][j]+=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]);
    repi(i,k,n)repi(j,k,n)if((sum[i][j]-sum[i-k][j]-sum[i][j-k]+sum[i-k][j-k])<median) return true;
    return false;
}
int main()
{
    n=ri(),k=ri();
    median=(k*k/2)+1;
    repi(i,1,n)repi(j,1,n) a[i][j]=ri();
    int l=0,r=1000000000,ans;
    while(l<=r){
        int mid=(l+r)>>1;
        if(Check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%d\n",ans);

    return 0;
}


#ifdef _LOCAL
    #include "local_include.hpp"
#else
    #include <bits/stdc++.h>
    using namespace std;
#endif
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

#define fto(i, s, e) for (int i = (s); i <= (e); ++i)
#define fto1(i, s, e) for (int i = (s); i < (e); ++i)
#define fdto(i, s, e) for (int i = (s); i >= (e); --i)
#define fit(it, a) for (auto it = (a).begin(); it != (a).end(); ++it)
#define fat(i, a) for (auto i : (a))

#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
template<class T, class Cmp = less<T>> using oss = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;

#define bc __builtin_popcountll
#define y1 ansdj
#define endl '\n'
#define ff first
#define ss second
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define bug(...) _bug(cout, __VA_ARGS__)
#define buga(a, s, e) cout << '{'; if (e < s) cout << '}'; else fto (__i, s, e) cout << a[__i] << " }"[__i == e]; cout << endl

template<class T1, class T2> ostream& operator<<(ostream &os, pair<T1, T2> const &v) {
    return os << '(' << v.ff << ", " << v.ss << ')';
}

template<typename T>
void _bug(ostream &os, T const &var) { os << var << endl; }

template<typename T, typename... Args>
void _bug(ostream &os, T const &var, Args const &... args) {
    os << var << ' ';
    _bug(os, args...);
}

double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
int const maxn = 1e5+3;

void gcd(int a, int b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
    } else {
        gcd(b, a%b, x, y);
        ll tmp = x;
        x = y;
        y = tmp - a/b*y;
    }
}

#define multi_test 1
void _main() {
    int n, s, k;
    cin >> n >> s >> k;
    int b = n-s;
    int g = __gcd(b, __gcd(n, k));
    n /= g, b /= g, k /= g;
    g = __gcd(k, n);
    if (g != 1) bug(-1);
    else {
        ll x, y;
        gcd(k, n, x, y);
        x = x*b % n;
        if (x < 0) x += n;
        bug(x);
    }
}

int main() {
    #ifdef _LOCAL
        freopen("main.inp", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t = 1;
    if (multi_test) cin >> t;
    while (t--) {
        _main();
    }

    #ifdef _LOCAL
        cerr << 0.001*clock() << endl;
    #endif
    return 0;
}

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

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  if(y*z%x==0){
    cout << (y*z)/x-1 << endl;
  }else{
    cout << (y*z)/x << endl;
  }
}


#include<bits/stdc++.h>
#include<cmath>
#define tr(v,it) for(typeof(v.begin()) it = v.begin() ;it!=v.end();it++)
#define in(x) lli x; cin>>x
#define all(v) v.begin(),v.end()
#define for0(n) for(lli i=0;i<n;i++)
#define for1(n) for(lli i=1;i<=n;i++)
#define mod 1000000007
#define asc_ord_set tree< lli , null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define desc_ord_set tree< lli , null_type, greater<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define key_position(k,o) o.order_of_key(k)
// Common file
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int lli;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef unordered_map <lli,lli> umap;
typedef priority_queue<lli> pq;
typedef pair <lli, lli> pi;
bitset<10000000> p;
bool sieve_made = false;
lli fast_power(lli a,lli b)
{
    lli p = a;
    lli res = 1;
    while(b>0)
    {
        if(b&1)
            res*= p;
        p= p*p;
        b= b>>1;
    }
    return res;
}
void sieve()
{   sieve_made=true;
    p[0] = p[1] = 0;
    p[2] = 1;
    for(lli i=4;i<=1000000;i+=2)
        p[i] = 0;
    for(lli i=3;i<=1000000;i+=2)
    {
        if(p[i])
        {
            for(lli j=i*i;j<=1000000;j+=i)
                p[j] = 0;
        }
    }
}
bool prime(lli n)
{
    if(sieve_made==true)
    {
        if(n<10000000)
            return (p[n]);
        else{
             for(int i=2;i<=sqrt(n);i++)
                    if(n%i==0) return false;
            return true;
        }
    }
    for(int i=2;i<=sqrt(n);i++)
        {
            if(n%i==0) return false;
        }
    return true;
}
map <lli,lli> factor;
void prime_fact(lli n)
{
    for(int i=2;i<=int(sqrt(n));i++)
    {
        if(n%i==0)
        {
            while(n%i==0)
                {
                    factor[i]++;
                    n = n/i;
                }
        }
    }
    if(n!=1) factor[n] = 1;
}
int main()
{   ios::sync_with_stdio(false);
    in(n);
    in(m);
    if(m==0)
        {cout<<1;
        return 0;}
    lli arr[m];
    for0(m)
        cin>>arr[i];
    sort(arr,arr+m);
    // now generate the minimum sized
    // cluster
    lli k;
    if(arr[0]-1!=0)
        k = arr[0] - 1;
    else
        k=1e18;
    for(int i=1;i<m;i++){
        if(arr[i]-arr[i-1]-1 != 0)
            k = min(k, arr[i] - arr[i-1] - 1);
        //cout<<arr[i]<<" ";
    }
    if(n-arr[m-1]!=0)
        k = min(k,n - arr[m-1]);
    // k is the minimum sized cluster
    if(m>=n)
        {cout<<0<<endl;
        return 0;}
    lli ans = (arr[0]-1)/k + ((arr[0]-1)%k == 0? 0 : 1);
    for(int i=1;i<m;i++){
        lli size = arr[i] - arr[i-1] - 1;
        ans+= size / k;
        if(size%k!=0)
            ans++;
    }
    ans += (n-arr[m-1])/k;
    if((n-arr[m-1])%k!=0)
        ans+=1;
    cout<<ans;
    return 0;
}

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

#define ll long long int
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i))
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
/*typedef tuple<ll,ll,ll>tpl;

ll bigmod(ll n,ll pow)
{
    if(pow==0)
        return 1;
    if(pow==1)
        return n%MOD;

    ll ans=bigmod(n,pow/2);
    ans=(ans*ans)%MOD;

    if(pow%2==1)
    {
        ans=(ans*n)%MOD;
    }
    return ans%MOD;
}

ll fact[1000005];

ll nCr(ll n,ll r)
{

    ll ans=fact[n];
    ans=(ans*bigmod(fact[r],MOD-2))%MOD;
    ans=(ans*bigmod(fact[n-r],MOD-2))%MOD;
    return ans;
} */

/*ll NcR(ll n, ll r)
{
    ll p = 1, k = 1;
    if (n - r < r)
        r = n - r;

    if (r != 0)
    {
        while (r)
        {
            p *= n;
            k *= r;
            ll m = __gcd(p, k);
            p /= m;
            k /= m;

            n--;
            r--;
        }
    }
    else
        p = 1;

    return p;
} */

ll a[200005],b[200005];
vector<ll> adj[200005];
ll bfs_flag[200005];

bool fl=true;

void addEdge(ll x,ll y)
{
    pb(adj[x],y);
    pb(adj[y],x);
}

ll BFS(ll s)
{
    priority_queue<ll, vector<ll>, greater<ll> > Q;
    Q.push(s);
    bfs_flag[s]=1;

    ll sm=0;
    sm+=b[s];
    while(!Q.empty())
    {
        ll u=Q.top();
        Q.pop();
        for(ll i=0;i<adj[u].size();i++)
        {
            ll x=adj[u][i];
            //cout<<x<<" "<<bfs_flag[x]<<en;
            if (bfs_flag[x] ==0)
            {
                Q.push(x);
                bfs_flag[x] =1;
                sm+=b[x];
            }
        }
    }
    return sm;
}

int main()
{
    _fastio
    ll n,m,x,y,fl=0;
    cin>>n>>m;
    for1(i,n) cin>>a[i];
    for1(i,n) {cin>>b[i]; b[i]=b[i]-a[i];}

    for1(i,m)
    {
        cin>>x>>y;
        addEdge(x,y);
    }
    for1(i,n)
    {
        if(bfs_flag[i]==0)
        {
            ll sm=BFS(i);
            //cout<<sm<<en;
            if(sm!=0)
            {
                fl=1;
                break;
            }
        }
    }
    if(fl==1) cout<<"No"<<en;
    else cout<<"Yes"<<en;
}


#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

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

    int a, b, x, y;
    cin >> a >> b >> x >> y;

    if (a == b) cout << x << endl;
    else if (a < b) {
        if (2*x < y) cout << (b - a) * 2*x + x << endl;
        else cout << (b - a) * y + x << endl;
    }
    else {
        if (2*x < y) cout << (a - b) * 2*x - x << endl;
        else cout << (a - b - 1) * y + x << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
const ll inf = 1e18;

/*-------ここから--------*/
using _ll = long long;
using _pl = pair<_ll, _ll>;
void dijkstra(vector<vector<_pl>> &G, vector<_ll> &dist, _ll initial_pos) {
    priority_queue<_pl, vector<_pl>, greater<_pl>> que;
    dist[initial_pos] = 0;
    que.push({0, initial_pos});
    while(!que.empty()) {
        auto q = que.top();
        que.pop();
        auto cur_cost = q.first;
        auto cur_pos = q.second;
        for(auto e : G[cur_pos]) {
            auto next_pos = e.first;
            auto next_cost = cur_cost + e.second;
            if(next_cost >= dist[next_pos]) continue;
            dist[next_pos] = next_cost;
            que.push({next_cost, next_pos});
        }
    }
}
/*-------ここまで--------*/

ll idx(ll a, ll b) {
    return 100*a + b;
}

void solve() {
    ll a, b, x, y;
    cin >> a >> b >> x >> y;
    a--; b--;
    vector<vector<pair<ll,ll>>> G(200);
    rep(i, 0, 100) {
        G[idx(0, i)].push_back({idx(1, i), x});
        G[idx(1, i)].push_back({idx(0, i), x});
    }
    rep(i, 0, 99) {
        G[idx(0, i+1)].push_back({idx(1, i), x});
        G[idx(1, i)].push_back({idx(0, i+1), x});
    }
    rep(i, 0, 99) {
        G[idx(0, i)].push_back({idx(0, i+1), y});
        G[idx(0, i+1)].push_back({idx(0, i), y});
    }
    rep(i, 0, 99) {
        G[idx(1, i)].push_back({idx(1, i+1), y});
        G[idx(1, i+1)].push_back({idx(1, i), y});
    }
    vector<ll> dist(200, 1e18);
    dijkstra(G, dist, idx(0, a));
    cout << dist[idx(1, b)] << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstring>
#include <math.h>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cctype>
#include <utility>
#include <set>
#include <map>
#include <sstream>
#include <iterator>
#include <limits>
#include <map>
#include <deque>
#include <stack>
#include <queue>

using namespace std;
#define pb push_back
#define ff(i, a, b) for (int i = a; i < b; i++)
#define ffl(i, a, b) for (long long i = a; i < b; i++)
#define ffr(i, a, b) for (int i = a; i >= b; i--)
// #define all(v) v.begin(), v.end()
#define X first
#define Y second
// #define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
// typedef std::pair<int,int> pii;
typedef pair<ll, ll> pll;
// const int md = 1000000007;

// #define pi 3.141592653589793238462643383279

int main()
{
  string s;
  cin >> s;
  int i = 0;
  string ans="";
  while (i<s.length())
  {
    if (s[i] == '.')
    {
      break;
    }
    else
    {
      ans+=(char)s[i];
      i++;
    }
  }
  cout<<ans;

  // for (i = 0; i < (int)s.size(); i++)
  // {
  //   if (s[i] != '.')
  //   {
  //     ans += (char)s[i];
  //   }
  //   else
  //     break;
  // }
  // cout<<ans;

  return 0;
}

#include <iostream>
#include <vector>
#include <deque>
#include <cstring>
#include <map>
#include <algorithm>
#include <stdlib.h>
#include <set>
#include <climits>
#include <string.h>
#include <unordered_map>
#include <queue>
#include <list>
#define int long long int
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;

const int mod = 1e9 + 7;

const int N = 1e6 + 5;

bool valid(string s)
{
	for(int i = 0; i < s.size(); i++)
	{
		if(i != s.size()-1 &&  s[i] == '.')
		{
			return true;
		}
	}
	return false;
}

int32_t main()
{

	fastio;
	string s;
	cin >> s;
	int n = s.size();
	if(!valid(s))
	{
		cout << s << '\n';
		return 0;
	}
	for(int i = 0; i < n; i++)
	{
		if(s[i] == '.') break;
		cout << s[i];
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Pair vector<pair<ll,ll>>
#define vec vector <ll>
#define all(a) a.begin(),a.end()
#define mo 1000000007
#define decimal(i,n) fixed << setprecision(i) << n
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define show_nl(a) for(auto xyz:a)cout<<xyz<<endl;
#define MAX (ll)(pow(2,63)-1)
#define fill(a,b) memset(a, b, sizeof(a))

//modular inverse
void eea(ll a,ll b,ll &x,ll &y)
{
    if (a == 1)
    {
        x = 1; y = 0;
        return;
    }
    ll x1, y1;
    eea(b%a,a,x1,y1);
    x=y1-(b/a)*x1;
    y=x1;
}
ll mi(ll a,ll m)
{
    ll x,y;
    eea(a,m,x,y);
    x= (x%m+m)%m;
    return x;
}
//complete

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
    {

    }
}

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

    // freopen("ladder.in", "r", stdin);   // name of input file
	// freopen("ladder.out", "w", stdout); // name of output file

    // ifstream fin("art.in");
    // ofstream fout("art.out");

    // fstream file, output;
	// file.open(R"()", ios::in);        // add the address of local input file
	// output.open(R"()", ios::out);  // add the address of local output file

    ll t=1;
    // cin>>t;
    while(t--)
    {
       ll n;
       cin>>n;
       ll a[n+1];
       for(ll i=1;i<=n;i++)
       {
           cin>>a[i];
       }
       ll x[n+1]={0};
       ll c=0;
       for(ll i=1;i<=n;i++)
       {
           if(a[i]==i && x[i]==0)
           {c++; x[i]=i; continue;}
           if(x[i]==0)
           {
               ll p=i;
               x[i]=i;
               while(a[p]!=i)
               {
                   p=a[p];
                   if(x[p]!=0)
                   break;
                   x[p]=i;
               }
               if(x[p]==i)
               c++;
           }
       }
       ll s=1;
       for(ll i=1;i<=c;i++)
       {
           s=(s*2)%(998244353);
       }
       s=(s-1+998244353)%(998244353);
       cout<<s<<"\n";
    }
}

/*
Some helpful points
1.) Calm yourself
2.) check for semicolon or data type mismatch
3.) It can be solved
*/

#include<bits/stdc++.h>

#define N 200010

using namespace std;

namespace modular
{
	const int mod=998244353;
	inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
	inline int dec(int x,int y){return x-y<0?x-y+mod:x-y;}
	inline int mul(int x,int y){return 1ll*x*y%mod;}
}using namespace modular;

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

int n;
int cnt,head[N],nxt[N<<1],to[N<<1];
bool vis[N];

void adde(int u,int v)
{
	to[++cnt]=v;
	nxt[cnt]=head[u];
	head[u]=cnt;
}

void dfs(int u)
{
	vis[u]=1;
	for(int i=head[u];i;i=nxt[i])
	{
		int v=to[i];
		if(!vis[v]) dfs(v);
	}
}

int poww(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1) ans=mul(ans,a);
		a=mul(a,a);
		b>>=1;
	}
	return ans;
}

int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		int v=read();
		adde(i,v),adde(v,i);
	}
	int tot=0;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			tot++;
			dfs(i);
		}
	}
	printf("%d\n",dec(poww(2,tot),1));
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)

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

    ull n;
    string s,x;
    cin >> n>>s>>x;
    vector<vector<ll>> dp( n+1, vector<ll>( 0, 0 ) );

    dp[n].push_back(0);
    vector<ll> a( 0, 0 );
    vector<ll> b( 0, 0 );
    set<ll> se;
    BREP(i,n)
    {
        ll m = s[i] - '0';
        if(x[i] == 'A')
        {
            a.clear();
            b.clear();
            for(auto j: dp[i+1])REP(k,7)
            {
                if((k*10+0)%7==j) a.push_back(k);
                if((k*10+m)%7==j) b.push_back(k);
            }
            sort(ALL(a));
            sort(ALL(b));
            //REP( j, a.size() ) cout << a[j] << " "; cout << endl;
            //REP( j, b.size() ) cout << b[j] << " "; cout << endl;

            set_intersection( ALL( a ), ALL( b ), back_inserter( dp[i] ) );
        }
        else
        {
            se.clear();
            for(auto j: dp[i+1])REP(k,7)
            {
                if((k*10+0)%7==j) se.emplace(k);
                if((k*10+m)%7==j) se.emplace(k);
            }
            for(auto j: se) dp[i].push_back(j);
        }

        //REP( j, dp[i].size() ) cout << dp[i][j] << " "; cout << endl;
    }

    cout <<
    (find(ALL(dp[0]), 0)==dp[0].end()
    ? "Aoki" : "Takahashi") << endl;

    //----------------
    return 0;
}

#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stdio.h>
//end of libraries
#define lnf 9999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (ll)(c).size()
#define mkp(a,b) make_pair(a,b)
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define rsz(a,n) a.resize(n)
#define pii pair <ll,ll>
#define rep(i,n) for(ll i = 0 ; i < n ; i++)
#define drep(i,n) for(ll i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(ll i = x ; i < n ; i++)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const ll max_n = 3000;

using namespace std;
ll n , m , dp[max_n];
vector < pii > vci[max_n],vco[max_n];
set <pii> st;

ll get(ll x) {
	st.clear();
	rep(j,max_n-3) {dp[j] = lnf;}
	dp[x] = 0;

	st.insert({0,x});

	while(sz(st)) {
		auto it = st.begin();
		ll value = it->first;
		ll curr = it->second;

		st.erase(it);

		for(auto &y : vco[curr]) {
			if(dp[y.fi] > y.se + dp[curr]) {

				auto ti = st.find({dp[y.fi] , y.fi});
				if(ti!=st.end()) st.erase(ti);

				dp[y.fi] = y.se + dp[curr];
				st.insert({dp[y.fi],y.fi});

			}

		}

	}
	ll r = lnf;
	for(auto &y : vci[x]) {
		r = min(dp[y.fi]+y.se,r);
	}
	return r;

}

int main(){
fcin;
	cin >> n >> m;

	rep(i,m) {
		ll u , v , c;
		cin >> u >> v >> c;
		u--,v--;
		vci[v].pb({u,c});
		vco[u].pb({v,c});
	}
	// get(0);
	rep(i,n) {
		ll d = get(i);
		// cout << d << "\n";
		if(d>=lnf) cout << "-1\n";
		else cout << d << "\n";
	}
/*
*/
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;

int n;
struct edge{ int to; long long int cost; };
vector<vector<edge>> graph;

vector<long long int> Dijkstra(int s){
    priority_queue<pair<long long int, int>,
    vector<pair<long long int, int>>,
    greater<pair<long long int, int>>> pq;
    vector<long long int> d(n, INF);
    d[s] = 0;
    pq.push({0,s});

    while(pq.empty() == false){
        auto x = pq.top();
        pq.pop();

        if(x.first > d[x.second]) continue;

        for(edge e : graph[x.second]){
            if(d[e.to] > d[x.second] + e.cost){
                d[e.to] = d[x.second] + e.cost;
                pq.push({d[e.to], e.to});
            }
        }
    }
    return d;
}

int h, w;
int id(int x, int y){
    return x * w + y;
}

int main(){
    cin >> h >> w;

    vector<string> a(h);
    for(int i=0; i<h; i++){
        cin >> a[i];
    }

    vector<int> dx = {1, 0, -1, 0};
    vector<int> dy = {0, 1, 0, -1};

    n = h*w + 26;
    graph.resize(n);
    int s = -1;
    int g = -1;

    for(int x=0; x<h; x++){
        for(int y=0; y<w; y++){
                 if(a[x][y] == '#') continue;
            else if(a[x][y] == 'S') s = id(x,y);
            else if(a[x][y] == 'G') g = id(x,y);
            else if(a[x][y] == '.') ;
            else{
                int teleporter = h*w + (a[x][y] - 'a');
                graph[id(x,y)].push_back({teleporter,1});
                graph[teleporter].push_back({id(x,y),1});
            }

            for(int i=0; i<4; i++){
                if(0 <= x+dx[i] && x+dx[i] < h
                && 0 <= y+dy[i] && y+dy[i] < w
                && a[x+dx[i]][y+dy[i]] != '#') graph[id(x,y)].push_back({id(x+dx[i], y+dy[i]),2});
            }
        }
    }

    vector<long long int> d = Dijkstra(s);
    if(d[g] == INF) d[g] = -2;
    cout << d[g] / 2 << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

int h, w, a, b;
int sol = 0;
vector<vector<int>> X;
void bt(int k, int aa){
    if (k == h*w){
        sol += aa == a+1;
        return;
    }
    int r = k/w;
    int c = k%w;

    if (X[r][c]) {
        bt(k + 1, aa);
        return;
    }

    if (aa<=a && r+1 < h && !X[r+1][c]){
        X[r][c] = X[r+1][c] = aa;
        bt(k+1, aa+1);
        X[r][c] = X[r+1][c] = 0;
    }

    if (aa<=a && c+1 < w && !X[r][c+1]){
        X[r][c] = X[r][c+1] = aa;
        bt(k+1, aa+1);
        X[r][c] = X[r][c+1] = 0;
    }

    X[r][c] = h*w;
    bt(k+1, aa);
    X[r][c] = 0;
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
    cin >> h >> w >> a >> b;
    init(X, 0, h, w);
    bt(0, 1);
    cout << sol << endl;
    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


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

int read()
{
	int i=0;char ch;
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) {i=i*10+ch-'0';ch=getchar();}
	return i;
}

int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x % y)); }
int n, a[22222], b[1111], Ans = 0;
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++ i) cin >> a[i];
	for(int i = 1; i <= n; ++ i)
		for(int j = 2; j <= 1000; ++ j)
			if(a[i] % j == 0) b[j] ++;
	for(int i = 1; i <= 1000; ++ i)
		if(b[i] > b[Ans]) Ans = i;
	cout << Ans;
	return 0;
}

// Submitted by Sir GaLaHaD
#include <bits/stdc++.h>
#include <chrono>
/*--------------*/
#define test(t) for(cin>>t;t;--t)
#define rep(i,n) for(ll i=0;i<n;i++)
#define repr(i,k,n) for(ll i=k;i<n;i++)
#define repr_r(i,n) for(ll i= n-1;i>=0;i--)
/*--------------*/
#define fall(it,a) for(auto it =a.begin();it!=a.end();it++)
#define fall_r(it,a) for(auto it =a.rbegin();it!=a.rend();it++)
#define all(a) a.begin(),a.end()
#define fill(vis,v) memset(vis,v,sizeof(vis))
/*--------------*/
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
/*--------------*/
#define pb push_back
#define f first
#define sec second
#define in cin>>
#define out cout<<
#define MAX 1e9
//#define PQ
#define optimize ios_base::sync_with_stdio(0);cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef unordered_map<ll ,ll>umll;
typedef unordered_set<ll>usll;
typedef set<ll>sll;
typedef map<ll,ll>mll;
typedef priority_queue<ll>pq_ll;
typedef priority_queue<ll,vll,greater<ll>>pq_pll;
typedef priority_queue<pll> pq_gll;
typedef priority_queue<pll,vpll,greater<pll>> pq_gpll;
#ifdef PQ
struct comp
{
  bool operator()(const pll &a,const pll &b)
  {
    if(a.sec==b.sec)
        return a.f>b.f;
    return a.sec>b.sec;
  }
};
#endif

int main()
{
    optimize;
    ll n;
    in n;
    ll arr[n];
    rep(i,n)in arr[i];
    ll ans=0,num=2;
    ll Max =  *max_element(arr,arr+n);
    for(int i=2;i<=Max;++i)
    {
    	ll count=0;
    	rep(j,n)
    	{
    		if(arr[j]%i==0)
    			count++;
    	}
    	if(count>ans)
    	{
    		ans=count;
    		num=i;
    	}
    }
    out num<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w,x,y;
    cin >> h >> w >> x >> y;
    vector<vector<char>>grid(h,vector<char>(w));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> grid[i][j];
        }
    }
    x--;y--;
    int j = x;
    int ans = 0;
    while(j >= 0){
        if(grid[j][y] == '#'){
            break;
        }
        ans ++;
        j--;
    }
    j = x + 1;
    while(j < h){
        if(grid[j][y] == '#'){
            break;
        }
        ans ++;
        j++;
    }
    j = y-1;
    while(j >= 0){
        if(grid[x][j] == '#'){
            break;
        }
        ans ++;
        j--;
    }
    j = y + 1;
    while(j < w){
        if(grid[x][j] == '#'){
            break;
        }
        ans ++;
        j++;
    }
    cout << ans << "\n";
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
/*bool ispalindrome(string s)
{
  for(int i=0;i<s.length()/2;i++)
  {
    if(s[i]!=s[s.length()-i-1])
      return false;
  }
  return true;
}//program to get nth ugly no.(having prime factores only 2 3 5)(O(n) time and O(n) space )
ll getNthUglyNo(ll n) {
      // code here
   ll ugly[n];
   ll i2=0;
   ll i3=0;
   ll i5=0;
   ll nm2=2;
   ll nm3=3;
   ll nm5=5;
   ll nxt=1;
   ugly[0]=1;
   for(int i=1;i<n;i++)
   {
       nxt=min(nm2,min(nm3,nm5));
       ugly[i]=nxt;
       if(nxt==nm2)
       {
           i2=i2+1;
           nm2=ugly[i2]*2;
       }
       if(nxt==nm3)
       {
           i3=i3+1;
           nm3=ugly[i3]*3;
       }
       if(nxt==nm5)
       {
           i5+=1;
           nm5=ugly[i5]*5;
       }
   }
    // End of for loop (i=1; i<n; i++)
    return nxt;
  }
  ll fact(ll n)
  {
    ll res=1;
    for(ll i=2;i<=n;i++)
      res=res*i;
    return res;
  }
  ll ncr(ll n,ll r)
  {
    return fact(n)/(fact(n-r)*fact(r));
  }
  ll convert(ll n,ll k)
  {
    string s="";
    ll temp=0,curr=0;
    while(n>0)
    {
       temp=n%k;
      s+=to_string(temp);
      n/=k;
    }
    reverse(s.begin(),s.end());
    for(ll i=0;i<s.length();i++)
      curr=curr*10+s[i]-'0';
    return curr;
  }
//program to check to whether one string become equal to second after some characters swap or shift
//program to calculate to to check also whether two string are rotation of each other or not*/
 bool areRotations(string str1, string str2)
{
   /* Check if sizes of two strings are same */
   if (str1.length() != str2.length())
        return false;

   string temp = str1 + str1;
  return (temp.find(str2) != string::npos);

}
string decimalToBinary(ll n)
{
    //finding the binary form of the number and
    //coneverting it to string.
    string s = bitset<64> (n).to_string();

    //Finding the first occurance of "1"
    //to strip off the leading zeroes.
    const auto loc1 = s.find('1');

    if(loc1 != string::npos)
        return s.substr(loc1);

    return "0";
}
bool issort(pair<string,ll>a,pair<string,ll>b)
{
  return a.second>b.second;
}
  void solve()
  {
   ll n,i;
   cin>>n;
   string s[n];
   ll a[n+1];
   vector<pair<string,ll>>v;
   for(i=0;i<n;i++)
   {
    cin>>s[i]>>a[i];
    v.push_back(make_pair(s[i],a[i]));
   }
   sort(v.begin(),v.end(),issort);
   cout<<v[1].first<<endl;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
   // ll t;
    //cin>>t;
    //while(t--)
   solve();
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

std::string s[3];

int main(void){
	int t,n,i,j;
	std::cin >> t;
	while(t--){
		std::cin >> n;
		for(j=0; j<3; ++j){
			std::cin >> s[j];
		}
		std::cout << s[0][0];
		for(i=0; i<n; ++i){
			std::cout << ((char)('0'+'1'-s[0][0]));
		}
		for(i=0; i<n; ++i){
			std::cout << s[0][0];
		}
		std::cout << std::endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define lowbit(x) x&-x
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define UNI(x) sort(ALL(x)),x.resize(unique(ALL(x))-x.begin())
#define GETPOS(c,x) (lower_bound(ALL(c),x)-c.begin())
#define LEN(x) strlen(x)
#define MS0(x) memset((x),0,sizeof((x)))
#define Rint register int
#define ls (u<<1)
#define rs (u<<1|1)
typedef unsigned int unit;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<pii> Vpii;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(ull &x) { scanf("%llu", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.fi);putchar(' '); _W(x.se);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int MOD=1e9+7,mod=998244353;
ll qpow(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
const int MAXN=4e5+10,MAXM=2e6+10;
const int INF=INT_MAX,SINF=0x3f3f3f3f;
const ll llINF=LLONG_MAX;
const int inv2=(MOD+1)/2;
const int Lim=1<<20;

ll n;
ll a[MAXN],b[MAXN],dp[MAXN][2];

void solve()
{
    R(n);
    ll ans=0,res=0;
    for(int i=1;i<=n;i++)R(a[i]),ans+=a[i];
    for(int i=1;i<=n;i++)R(b[i]),b[i]-=a[i];
    Vll vec[2];
    for(int i=1;i<=n;i++)vec[i&1].pb(b[i]);
    for(int i=0;i<2;i++)sort(ALL(vec[i]),greater<ll>());
    for(int i=0;i<n/2;i++)
        if(vec[0][i]+vec[1][i]>=0)res+=vec[0][i]+vec[1][i];
    W(ans+res);
}

int main()
{
    //freopen("input.txt","r",stdin);
    int T=1;
    //scanf("%d",&T);
    for(int kase=1;kase<=T;kase++)
    {
        //printf("Case #%d: ",kase);
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){
	ll x,y,a,b;
	cin >> x >> y >> a >> b;
	ll ans = 0;
	y--;
	for(ll i = 0; ; ++i){
		ll c = i+(y-x)/b;
		ans = max(ans,c);
		if(x <= y/a)
			x*=a;
		else
			break;
	}
	cout << ans << "\n";
	return 0;
}

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << " " << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	rep(i, v.size()) {
		if (i) os << " ";
		os << v[i];
	}
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
#ifdef LOCAL
#define dbg(x) cerr << #x << ": " << (x) << '\n'
#define say(x) cerr << (x) << '\n'
#else
#define dbg(x)
#define say(x)
#endif
string solve(bool a) { return ((a) ? "Yes" : "No"); }
int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	int ans = INF;

	cin >> n;
	int cnt=INF;
	int cnt2 = INF;
	VPi data(n);
	cin >> data;
	rep(i, n) { chmin(ans, data[i].F + data[i].S); }
	sort(all(data));
	rep(i, n) {
		if (i == 0) {
			cnt = data[i].F;
		} else {
			chmin(cnt2, data[i].S);
		}
		swap(data[i].F, data[i].S);
	}
	chmin(ans, max(cnt , cnt2));
	sort(all(data));
	cnt2 = INF;

	rep(i, n) {
		if (i == 0) {
			cnt = data[i].F;
		} else {
			chmin(cnt2, data[i].S);
		}
		swap(data[i].F, data[i].S);
	}
	chmin(ans, max(cnt, cnt2));
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i,l,r) for(int i = (l); i <= (r); ++i)
typedef long long ll;
void fast() {
	ios::sync_with_stdio (0);
	cin.tie (0); cout.tie (0);
}

const int N=600010;
int n, m,A[N<<1],c[N];
void upd(int u,int v){
	for(; u<N;u+=u&-u) c[u]+=v;
}
int qry(int u){
	int ret(0);
	for(; u;u-=u&-u)ret+=c[u];
	return ret;
}
int sum[N*20],ls[N*20],rs[N*20],tot;
void upd(int&p, int o,int v,int l=1,int r=n){
	p=++tot;
	sum[p]=sum[o]+1,ls[p]=ls[o],rs[p]=rs[o];
	if(l==r) return;
	int mid=(l+r)>>1;
	((v<=mid)?upd(ls[p],ls[o],v,l,mid):upd(rs[p],rs[o],v,mid+1,r));
}
int getlft(int p,int v,int l=1,int r=n){
	if(l==r||(!p)) return 0;
	int mid=(l+r)>>1;
	if(v<=mid) return getlft(ls[p],v,l,mid);
	else return sum[ls[p]]+getlft(rs[p],v,mid+1,r);
}
int getrgt(int p,int v,int l=1,int r=n){
	if(l==r||(!p)) return 0;
	int mid=(l+r)>>1;
	if(v<=mid) return sum[rs[p]]+getrgt(ls[p],v,l,mid);
	else return getrgt(rs[p],v,mid+1,r);
}
int root[N<<1];
signed main() {
	cin >> n;
	rep(i,1,n) cin>>A[i],++A[i];
	long long init=0;
	rep(i,1,n){
		init+=i-1-qry(A[i]);
		upd(A[i],1);
		A[n+i]=A[i];
	}
	rep(i,1,2*n) upd(root[i],root[i-1],A[i]);
	rep(cur,n,2*n-1){
		int use=A[cur-n+1];
		cout<<init<<'\n';
		init-=(getlft(root[cur],use)-getlft(root[cur-n+1],use));
		init+=(getrgt(root[cur],use)-getrgt(root[cur-n+1],use));
	}
	return 0;
}

/*
start of cp 3.0BETA
https://codeforces.com/problemset/page/1?tags=1800-1800
extending-Beta-test-with-DS&ALGO:https://codeforces.com/problemset/page/1?tags=combine-tags-by-or%2Cdfs+and+similar%2Cdp%2Cshortest+paths%2C2000-2000
Math-Problem-Practice:https://codeforces.com/problemset?tags=math,1400-1500
DEAD PERSON CODING
*/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
#define int long long int
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define graph vector<vector<int>>
#define print(s) for(auto it:s) cout<<it<<" "
#define print2(s) for(auto it:s) cout<<it.fi<<" : "<<it.se<<endl
#define uset unordered_set
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vi,greater<int>>
#define ln cout<<'\n'
#define space cout<<" "
#define len(x) x.size()
#define bits(x) _builtin_popcount(x)
void fileio()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}
graph g;
const int N=200099;
int dp[N][2],lt[N],ft[N];
int n,mx;
int solve(int i,int j){
    if(i==mx+2)return 0;
    int &res=dp[i][j];
    if(res!=-1)return res;
    res=LLONG_MAX;
    int curr=ft[i-1];
    if(j)curr=lt[i-1];
    int ff=ft[i],ll=lt[i];
    if(ff>curr and ll>curr){
        res=min(res,abs(ll-curr)+solve(i+1,1));
    }
    else if(ff<curr and ll<curr){
        res=min(res,abs(curr-ff)+solve(i+1,0));
    }else{
        res=min(res,abs(ll-curr)+abs(ll-ff)+solve(i+1,0));
        res=min(res,abs(curr-ff)+abs(ll-ff)+solve(i+1,1));
    }
    return res;

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    fileio();
    memset(dp,-1,sizeof(dp));
    memset(ft,0,sizeof(ft));
    memset(lt,0,sizeof(lt));
    map<int,int>p,s,idx;
    cin>>n;
    int ct=1;
    for(int i=0;i<n;i++){
        int pos,c;
        cin>>pos>>c;
        if(!p.count(c)){
            p[c]=pos;
            s[c]=pos;
        }else{
            p[c]=min(p[c],pos);
            s[c]=max(s[c],pos);
        }
    }
    for(auto &it:p){
        idx[it.fi]=ct++;
    }
    mx=ct+1;
    for(auto &it:idx){
        ft[it.se]=p[it.fi];
        lt[it.se]=s[it.fi];
    }
    cout<<solve(1,1);

    return 0;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(110);
  rep(i,h) cin >> s[i];
  int cnt=0;
  rep(i,h)rep(j,w){
    if(s[i][j]=='.'&&s[i][j+1]=='.') cnt++;
    if(s[i][j]=='.'&&s[i+1][j]=='.') cnt++;
  }
  cout << cnt << endl;
}

//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#include<set>
using namespace std;
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second

#define si(x) int(x.size())
#define sum_all(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
vector<ll> s;

void pre()
{
	s=vector<ll>(1e6+13,0);

	for(ll i=1;i<si(s);i++)
	{
		s[i]=i;
	}
	for(ll i=2;i<si(s);i++)
	{
		if(s[i]==i)
      for(ll j=i;j<si(s);j+=i)
      	 if(s[j]==j) s[j]=i;
	}
	return ;
}

ll calc(ll a,ll n)
{

  if(n<=1) return 0;
  if(a==1) return 0;
  ll temp=a;

  set<ll> primes;
  // cout << s[4] << endl;
  while(temp>1)
  {
    primes.insert(s[temp]);
    temp/=s[temp];

  }
  vector<ll> prime;
  for(auto a:primes) prime.pb(a);
  // cout << si(prime) << endl;
// cout << prime[0] << " "<< prime[1] << endl;
  ll N= si(prime);
// cout << prime[0] << endl
ll ans=0;
for(ll i=1;i<(1<<N);i++)
{
ll cnt=0 ;
ll rs=0;
ll k=1;
for(ll j=0;j<N;j++)
{
	if( (1<< j )  & i)
	{
		cnt++;
		k*=prime[j];
	}
}

 rs=n/k;
 if(cnt%2==0) rs*=-1;
 ans+=rs;

}
return ans;
}
ll calc2(ll a,ll n)
{
    if(a<=1) return 0;
	return n/a;
}

void solve()
{

   pre();
   ll l,r;
   cin >> l >> r ;

      // cout << calc(6,2) << endl;
   ll A=0;
   for(ll i=l;i<=r;i++)
   {
  // cout <<  (calc(i,r)-calc(i,l-1)) << endl;
     A+= (calc(i,r)-calc(i,l-1));
   }
   // cout << A << endl;
   ll  B=0;
   for(ll i=l;i<=r;i++)
   {
   	 if(i==1) continue;
   	B+=(calc2(i,r)-calc2(i,l-1))*2-1;
   	// cout << (calc2(i,r)-calc2(i,l-1))*2-1 << endl;
   }
   cout << A-B << endl;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

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

}


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

#define   FASTIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   tr(it, a)   for(auto it=a.begin();it!=a.end();it++)
#define   dbg(x,y) cout<<(x)<<" -->  "<<(y)<<endl
#define   all(a) (a).begin(), (a).end()
#define   rep(i,a,b)  for(int  i=a;i<b;i++)
#define   int  long long
#define   pii pair<int,int>
#define   vi vector<int >
#define   pb push_back
#define   F first
#define   S second
#define   endl  "\n"

const int  N = 1e4 + 3;
const int  inf = 1e18 + 3;
const int  ninf = -1e9;
const int  mod = 1e9 + 7;
//--------------------------------------------------------------//

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

    int x = ceil(sqrt(n));
    int cnt = 0;
    map<int, int>mp;

    for (int i = 2; i <= x; i++)
    {
        int j = i;
        while (i * j <= n)
        {
            if (mp.find(i * j) == mp.end())
            {
                cnt++;
                mp[i * j] = 1;
            }
            j = j * i;
        }
    }
    cout << n - cnt;

}

signed main()
{

#ifndef ONLINE_JUDGE
    freopen("inputf.in.txt", "r", stdin);
    freopen("outputf.in.txt", "w", stdout);
#endif

    FASTIO;
    int T = 1;
    //preProcess();
    //cin >> T;

    for (int t = 1; t <= T; t++)
    {
        solve();
    }
    return 0;
}

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

int main(){
  long long int n;
  cin >>n;
  unordered_set<long long int> s;
    for(long long int i=2;i*i <= n;i++){
        long long x = i * i;

        while (x <= n){
          s.insert(x);
          x *= i;
        }
    }

    cout << n - s.size() <<endl;

    return 0;
}


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

const int maxn = 1010;

int n;
int st[maxn], ed[maxn];
vector<int> vc[maxn];

bool check (int s, int t, int L)
{
    if (s + L * 2 - 1 > 2 * n) return false;
    for (int u = s; u < t; u++)
    {
        int v = u + L;
        if (st[v] || ed[u]) return false;
        if ((st[u] == 0 && ed[v] <= 0) || (st[u] <= 0 && ed[v] == 0) || (st[u] == v)) continue;
        return false;
    }
    return true;
}

bool dp[maxn];

int main()
{
    //freopen("C:/Users/MACHENIKE/Desktop/data.in","r",stdin);
    scanf ("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        int u, v;
        scanf ("%d %d", &u, &v);
        if (u >= v && v != -1) return puts ("No"), 0;
        if (~u && (st[u] || ed[u])) return puts ("No"), 0;
        if (~v && (st[v] || ed[v])) return puts ("No"), 0;
        if (~u) st[u] = v;
        if (~v) ed[v] = u;
    }
    for (int i = 1; i <= n * 2; i++)
    {
        for (int j = i + 1; j <= n * 2; j++)
        {
            int len = j - i;
            if (i + len * 2 - 1 > n * 2) break;
            if (check (i, j, len))
            {
                //printf ("%d %d %d\n", i, j, len);
                vc[i + len * 2 - 1].push_back (i);
            }
        }
    }
    dp[n * 2 + 1] = 1;
    for (int i = n * 2; i >= 1; i--)
    {
        if (!dp[i + 1]) continue;
        //printf ("%d : ", i);
        for (auto it : vc[i])
        {
            dp[it] = 1;
            //printf ("%d ", it);
        }
       // puts("");
    }
    if (dp[1]) puts ("Yes");
    else puts ("No");
    return 0;
}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
inline int readint(){
	int a = 0; char c = getchar(), f = 1;
	for(; c<'0'||c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c&&c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}

const int MaxN = 200005;

int dp[MaxN][7]; // 1: T wins
char opt[MaxN], s[MaxN];

int dfs(int t,int x){
	if(~dp[t][x]) return dp[t][x];
	int &res = dp[t][x];
	if(opt[t] == 'A'){
		if(dfs(t+1,(10*x+s[t]-'0')%7)
			*dfs(t+1,(10*x)%7) == 0)
				return res = 0;
		return res = 1;
	}
	if(opt[t] == 'T'){
		if(dfs(t+1,(10*x+s[t]-'0')%7)
		or dfs(t+1,(10*x)%7) == 1)
			return res = 1;
		return res = 0;
	}
	return -1; // impossible
}

int main(){
	int n = readint();
	scanf("%s %s",s+1,opt+1);
	memset(dp,-1,sizeof(dp));
	rep(i,1,6) dp[n+1][i] = 0;
	dp[n+1][0] = 1;
	puts(dfs(1,0) ? "Takahashi" : "Aoki");
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 100000;
typedef long long ll;
typedef pair<ll,ll> P;
int main()
{
  ll k,n,m,i,a,s=0;
  ll b[N_MAX];
  P r[N_MAX];
  cin >> k >> n >> m;
  for(i=0;i<k;i++){
    cin >> a;
    b[i]=a*m/n;
    s+=b[i];
    r[i].first=(a*m)%n;
    r[i].second=i;
  }
  sort(r,r+k,greater<P>());
  for(i=0;i<m-s;i++)
    b[r[i].second]++;
  for(i=0;i<k;i++)
    cout << b[i] << " ";
  cout << endl;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

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

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int MAXK = 1e5 + 5;

int k, n, m;
ll a[MAXK];

bool check(ll L, vector<ll> &b) {
    b.resize(k);
    ll cnt = m;
    for (int i = 0; i < k; i++) {
        b[i] = max(0LL, ( ll )ceil((a[i] * m - L) / ( ldouble )n));
        cnt -= b[i];
        //printf("before: b[%d] = %lld, cnt = %lld\n", i, b[i], cnt);
    }
    if (cnt < 0) return false;

    for (int i = 0; i < k; i++) {
        ll diff = (a[i] * m + L) / n - b[i];
        b[i] += min(diff, cnt);
        cnt -= min(diff, cnt);
        //printf("after: b[%d] = %lld, cnt = %lld\n", i, b[i], cnt);
        if (cnt == 0) break;
    }

    return (cnt == 0);
}

int main() {
    scanf("%d %d %d", &k, &n, &m);
    for (int i = 0; i < k; i++)
        scanf("%lld", &a[i]);

    ll lo = 0, hi = 1e18, who = -1;
    vector<ll> b, ans(k);

#if 1
    while (lo <= hi) {
        ll mid = (lo + hi) >> 1LL;
        if (check(mid, b)) {
            copy(all(b), ans.begin());
            who = mid;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }
#else
    printf("check(3, b) = %d\n", check(3, b));
#endif

    //fprintf(stderr, "who = %lld\n", who);
    for (int i = 0; i < k; i++) {
        printf("%lld ", ans[i]);
    }
    puts("");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
int N , M;
map<int,vector<pair<int,int>>> MAP;
int dp[1 << 18];

bool issafe(int mask){
	int count = __builtin_popcount(mask);
	for(auto itr: MAP[count]){
		int cnt = 0;
		for(int k = 0 ; k < N ; k ++){
			if(mask&(1 << k) && (k + 1)<=itr.first){
				cnt ++;
			}
		}
		if(cnt > itr.second)
			return false;
	}
	return true;
}

int rec(int mask){
	if(mask == ((1 << N) - 1))
		return 1;
	if(dp[mask]!=-1)
		return dp[mask];
	int ans = 0;
	for(int i = 1 ; i <= N ; i ++){
		if(!(mask & (1 << (i - 1)))){
			int MASK = mask|(1 << (i - 1));
			if(issafe(MASK)){
				ans += rec(MASK);
			}
		}
	}
	return dp[mask] = ans;
}

signed main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T;
	T = 1;
	while(T--){
		cin >> N >> M;
		while(M --){
			int x , y , z;
			cin >> x >> y >> z;
			MAP[x].push_back({y,z});
		}
		memset(dp,-1,sizeof dp);
		cout << rec(0) << "\n";
	}

}

#include <bits/stdc++.h>

using namespace std;

//#define MULTITEST

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = int(1e9) + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 200 * 1000 + 13;

int n, m;
int a[N];
int b[N];
vector<int> g[N];

bool read () {
	if (scanf("%d%d", &n, &m) != 2)
		return false;
	forn(i, n)
		scanf("%d", &a[i]);
	forn(i, n)
		scanf("%d", &b[i]);
	forn(i, n)
		g[i].clear();
	forn(i, m){
		int v, u;
		scanf("%d%d", &v, &u);
		--v, --u;
		g[v].pb(u);
		g[u].pb(v);
	}
	return true;
}

li suma, sumb;
bool used[N];

void dfs(int v){
	used[v] = true;
	suma += a[v];
	sumb += b[v];
	for (int u : g[v]) if (!used[u])
		dfs(u);
}

void solve() {
	memset(used, 0, sizeof(used));
	forn(i, n) if (!used[i]){
		suma = sumb = 0;
		dfs(i);
		if (suma != sumb){
			puts("No");
			return;
		}
	}
	puts("Yes");
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int tt = clock();

#endif

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef MULTITEST
	int tc;
	scanf("%d", &tc);
	while(tc--){
		read();
#else
	while(read()) {
#endif
		solve();

#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

//グラフ関連
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    vec<ll> a(n), b(n);
    REP(i, n) {
        cin >> a[i];
    }
    REP(i, n) {
        cin >> b[i];
    }

    vec<ll> odds, evens;
    ll tmp = 0;
    REP(i, n) {
        tmp += a[i];
        if(i % 2)
            odds.push_back(b[i] - a[i]);
        else
            evens.push_back(b[i] - a[i]);
    }
    sort(all(odds), greater<ll>());
    sort(all(evens), greater<ll>());

    ll ans = tmp;
    REP(i, n / 2) {
        tmp += odds[i] + evens[i];
        chmax(ans, tmp);
    }
    cout << ans << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
typedef long long LL;
#define debug(x) cout << "debug : " << x << endl;
#define int long long
#define u first
#define v second

struct NODE {
    int x, y, id;
}a[N], b[N];
set<int>st;

bool cmp1(NODE& a, NODE& b) {
    return a.x < b.x;
}
bool cmp2(NODE& a, NODE& b) {
    return a.y < b.y;
}

void solve() {
    int n; cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i].x >> a[i].y;
        a[i].id = i;
        b[i] = a[i];
    }
    sort(a + 1, a + 1 + n, cmp1);

    st.insert(a[1].id);
    st.insert(a[n].id);
    st.insert(a[2].id);
    st.insert(a[n - 1].id);
    sort(a + 1, a + 1 + n, cmp2);

    st.insert(a[1].id);
    st.insert(a[n].id);
    st.insert(a[2].id);
    st.insert(a[n - 1].id);
    vector<pair<int, int>>c;
    for (auto v : st) {
        c.push_back({b[v].x, b[v].y});
    }
    vector<int>ans;
    for (int i = 0; i < c.size(); ++i) {
        for (int j = i + 1; j < c.size(); ++j) {
            ans.push_back(max(abs(c[i].u - c[j].u), abs(c[i].v - c[j].v)));
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans[ans.size() - 2] << endl;
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int T = 1;
//	cin >> T;
//	scanf("%d", &T);
	while (T--) {
		solve();
	}

}


#include<bits/stdc++.h>
using namespace std;
#define ints(...)			int __VA_ARGS__; vin(__VA_ARGS__)
#define dbls(...)			double __VA_ARGS__; vin(__VA_ARGS__)
#define ulls(...) 			unsigned long long __VA_ARGS__; vin(__VA_ARGS__)
#define strs(...) 			string __VA_ARGS__; vin(__VA_ARGS__)
#define vifin(x, y)			vi x(y); fin(x, y)
#define vvis(x, y, z, p)	vvi x(y, vi(z, p))
#define deb 				cout << "<deb> DEB" << endl
#define debi(x) 			cout << "<deb> " << #x << " == " << x << endl
#define rep(x, y) 			for(int x = 0; x < y; x++)
#define reps(x, y, z)		for(int x = y; x < z; x++)
#define rev(x, y)			for(int x = y; x >= 0; x--)
#define revs(x, y, z)		for(int x = y; x >= z; x--)
#define syz(x) 				(int)x.size()
#define euc(x, y)			(sqrt((x*x)+(y*y)))
#define all(x) 				x.begin(), x.end()
#define will(x) 			do{cout << x << endl; return 0;}while(0)
using ll 	= long long;
using ull	= unsigned long long;
using str	= string;
using vi 	= vector<int>;
using vc 	= vector<char>;
using vs	= vector<str>;
using vvi	= vector<vector<int>>;
using vvc	= vector<vector<char>>;
using pi	= pair<int, int>;
template<class T> using v = vector<T>;
template<class T> using vv = vector<vector<T>>;
template<class T> using pq = priority_queue<T>;
void vin(){return;}
template<class T>void fin(T& __x,int __y){rep(i, __y){cin >>__x[i];};}
void lout(){cout<<"=============================================="<<endl;}
template<class T>void fout(T& __x){cout<<"<deb> ";for(auto __y:__x){cout<< __y<<' ';}cout<<endl;}
template<class T>void fout(T& __x,int __y){cout<<"<deb> ";rep(i,__y)cout <<__x[i]<<' ';cout<<endl;}
template<class T>void ffout(T __x){lout();for(auto __y:__x){for(auto __z:__y){cout<<__z<<' ';}cout<<endl;}}
template<class T>void ffout(T __x,int __y,int __z){lout();rep(i,__y){rep(j,__z)cout<<__x[i][j]<<' ';cout<<endl;}lout();}
template<class C,class ...T>inline void vin(C& __f,T&... __x){cin >> __f;vin(__x...);}
template<class T>inline void chmax(T &a,const T &b){if(a<b)a=b;}
template<class T>inline void chmin(T &a,const T &b){if(b<a)a=b;}
constexpr ull LINF	= 4500000000000000000;
constexpr int INF 	= 2000000000;
constexpr int four	= 10007		;
constexpr int five	= 100007	;
constexpr int six	= 1000007	;
constexpr int seven	= 10000007	;
constexpr int eight	= 100000007	;
constexpr int nine	= 1000000007;

signed main() {
	dbls(a, b, w);
	w *= 1000.0;
	int min = INF, max = 0;
	double ans;
	rep(i, eight) {
		ans = w / i;
		if(a <= ans&&b >= ans) {
			chmax(max, i);
			chmin(min, i);
		}
	}
	if(min == INF) will("UNSATISFIABLE");
	cout << min << ' ' << max << endl;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <sstream>
using namespace std;

void solve() {
	long long n;
	cin >> n;
	int ans = 2;
	for(int i = 2; i < n; i++) {
		long long chk = ((i) * ((i) + 1LL)) / 2;
		if(chk > n) break;
		long long add = ((i - 1) * ((i - 1) + 1LL)) / 2;
		long long l = 1;
		long long r = 1e12;
		while(l <= r) {
			long long mid = l + (r - l) / 2;
			if(mid * i + add < n) {
				l = mid + 1;
			}else if(mid * i + add > n) {
				r = mid - 1;
			}else if(mid * i + add == n) {
				ans += 2;
				break;
			}
		}
	}
	cout << ans << endl;
}

int main () {
	int t = 1;
	for(int tt = 0; tt < t; tt++) solve();
	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define pdd pair<double,double>
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acosl(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
#define last Last
#define MXN 200005
const int mod=998244353;
void solve(){
    int n;
    scanf("%d",&n);
    vector<pair<pii,int> > v;
    vector<pair<pii,int> > v2;
    for(int i = 0;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v.pb(mp(mp(x,y),i));
        v2.pb(mp(mp(y,x),i));
    }
    sort(v.begin(),v.end());
    sort(v2.begin(),v2.end());
    for(auto &it:v2){
        swap(it.x.x,it.x.y);
    }
    vector<pair<pii,int> > tmp;
    for(int i = 0;i<3;i++){
        tmp.pb(v[i]);
        tmp.pb(v2[i]);
        tmp.pb(v[n-i-1]);
        tmp.pb(v2[n-i-1]);
    }
    map<pii,int> m;
    for(auto it:tmp){
        for(auto it2:tmp){
            int a=it.y,b=it2.y;
            if(a>b)swap(a,b);
            m[mp(a,b)]=max(abs(it.x.x-it2.x.x),abs(it.x.y-it2.x.y));
        }
    }
    vector<int> ttmp;
    for(auto it:m)ttmp.pb(it.y);//printf("%d %d %d\n",it.x.x,it.x.y,it.y);
    sort(ttmp.begin(),ttmp.end());
    printf("%d\n",ttmp[ttmp.size()-2]);
}
int main(){
    int t=1;
    while(t--)
        solve();
}
/*
2 3 5 6 1 4
*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
vector<pair<int,pair<int,int> > >v;
map<pair<int,int>,int >mp;
vector<int>ans;
bool cmp1(pair<int,pair<int,int> >&l,pair<int,pair<int,int> >&r)
{
    if(l.second.first<r.second.first)
        return 1;
    return 0;

}
bool cmp2(pair<int,pair<int,int> >&l,pair<int,pair<int,int> >&r)
{
    if(l.second.second<r.second.second)
        return 1;
    return 0;
}
void solve(int a,int b)
{
    int x=v[a].first;
    int y=v[b].first;
    if(x>y)
        swap(x,y);
    if(mp[ {x,y}])
        return;
    mp[ {x,y}]=1;
    int p=abs(v[a].second.first-v[b].second.first);
    int q=abs(v[a].second.second-v[b].second.second);
    int z=max(p,q);

    ans.push_back(z);
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        int x,y;
        cin>>x>>y;
        v.push_back({i,{x,y}});
    }
    sort(all(v),cmp1);
    solve(0,n-1);
    solve(0,n-2);
    solve(1,n-1);
    sort(all(v),cmp2);
    solve(0,n-1);
    solve(0,n-2);
    solve(1,n-1);
    sort(all(ans));
    cout<<ans[ans.size()-2]<<endl;

    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...); }
template<typename T> void dbg_a(T *a,int l,int r){cerr<<" {";for(int i = l;i<r;i++) cerr<<a[i]<<", ";cerr<<a[r]<<"}"<<endl;}
typedef long long ll;
#define int ll
inline int read(){
    int 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",i,j,f[i][j]);
//const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10,M = N*2 + 10;
const int mod = 998244353;
int n;
vector<int> G[N];
int minl,minr,locl,locr;
void solve(){
    n = read();
    For(i,1,n){
        int x = read(),c = read();
        G[c].emplace_back(x);
    }
    For(i,1,n){
        if(!G[i].size()) continue;
        ll ml,mr,l,r;
        l = *min_element(All(G[i])),r = *max_element(All(G[i]));
        ml = minl + abs(locl - r) + r - l;
        ml = min(ml,minr + abs(locr - r) + r - l);
        mr = minr + abs(locr - l) + r - l;
        mr = min(mr,minl + abs(locl - l) + r - l);
        minl = ml,minr = mr,locl = l,locr = r;
    }
    cout<<min(abs(locl) + minl,abs(locr) + minr)<<"\n";
}

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

#include<cstdio>
#include<cstdlib>
#include<vector>
#include<queue>
using namespace std;
#define inf 200005
#define INF 0x3f3f3f3f

int n;
int color[inf][2];
long long int dp[inf][2]; //dp[i][0] is the minimum steps after we get every i-color ball from the left, dp[i][1] is the minimum steps after we get every i-color ball from the right
int book[inf];
int main()
{
    int i,j;
    int x,c;
    scanf("%d",&n);
    for(i=1;i<=n;i++)       //init
    {
        color[i][0]=INF;    //the end position of color[i]
        color[i][1]=-INF;   //the begin position of color[i]
    }
    for(i=1;i<=n;i++)        //read data in disorder
    {
        scanf("%d%d",&x,&c);
        book[c]=1;
        if(x<color[c][0])color[c][0]=x; //update the begin position
        if(x>color[c][1])color[c][1]=x; //update the end position
    }

    //begin dp...
    dp[0][0]=dp[0][1]=0;
    for(i=1;i<=n;i++)
    {
        if(!book[i])
        {
            dp[i][0]=dp[i-1][0];
            dp[i][1]=dp[i-1][1];
            color[i][0]=color[i-1][0];
            color[i][1]=color[i-1][1];
            continue;
        }
        dp[i][0]=min(dp[i-1][0]+ abs(color[i-1][1]-color[i][0]), dp[i-1][1] + abs(color[i-1][0]-color[i][0]) );
        dp[i][0]+=color[i][1]-color[i][0];
        dp[i][1]=min(dp[i-1][0]+ abs(color[i-1][1]-color[i][1]), dp[i-1][1] + abs(color[i-1][0]-color[i][1]) );
        dp[i][1]+=color[i][1]-color[i][0];
    }
    printf("%lld\n",min(dp[n][0]+abs(color[n][1]),dp[n][1]+abs(color[n][0])));  //return to the origin
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define int long long
#define mid (l+r>>1)
using namespace std;
int read(){
	int x = 1,a = 0;char ch = getchar();
	while (ch < '0'||ch > '9'){if (ch == '-') x = -1;ch = getchar();}
	while (ch >= '0'&&ch <= '9'){a = a*10+ch-'0';ch = getchar();}
	return x*a;
}
const int maxn = 505,mod = 998244353;
int n,m;
char s[maxn][maxn];
int dp[maxn][maxn][5],a[maxn][maxn];
signed main(){
	n = read(),m = read();
	for (int i = 1;i <= n;i++) scanf ("%s",s[i]+1);
	for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++){
		if (s[i][j] == 'R') a[i][j] = 0;
		else if (s[i][j] == 'B') a[i][j] = 1;
		else a[i][j] = 2;
	}
//	for (int i = 1;i <= n;i++){ for (int j = 1;j <= m;j++) cout<<a[i][j]<<" ";
//	cout<<endl;}
	for (int i = 1;i <= n;i++){
		for (int j = m;j >= 1;j--){
			dp[i][j][a[i][j]] = 1;
			if (i > 1&&j < m) dp[i][j][0] |= dp[i-1][j+1][0],dp[i][j][1] |= dp[i-1][j+1][1];
		}
	}
	int res = 0;
	for (int i = 1;i <= n;i++){
		if (!dp[i][1][0]&&!dp[i][1][1]) res++;
		if (dp[i][1][0]&&dp[i][1][1]){
			printf("0\n");
			return 0;
		}
	}
	for (int i = 2;i <= m;i++){
	//	cout<<dp[n][i][0]<<" "<<dp[n][i][1]<<endl;
		if (!dp[n][i][0]&&!dp[n][i][1]) res++;
		if (dp[n][i][1]&&dp[n][i][0]){
			printf("0\n");
			return 0;
		}
	}
	int ans = 1;
//	cout<<res<<endl;
	for (int i = 1;i <= res;i++) ans = 1ll*2*ans % mod;
	printf("%lld\n",ans);
	return 0;
}

#include <iostream>
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
string p[520];
signed main(){
	int mx = 0;
	int h,w;
	cin >> h >> w;
	int ans = 1;
	for(int i = 0;i < h;i++){
		cin >> p[i];
	}

	bool able = true;
	for(int i = 0;i < w;i++){
		int sti = i;
		int stj = 0;
		bool c = true;
		int cnt = 0;
		map<char,int> mp;
		while(sti >= 0 && stj < h){
			if(p[stj][sti] != '.'){
				if(mp[p[stj][sti]] == 0){
					cnt += 1;
					mp[p[stj][sti]] = 1;
					if(cnt == 2)able = false;
				}
				c = false;
			}
			sti--;
			stj++;
		}
		if(c) ans = (ans * 2ll)% 998244353;
	}
	for(int i = 1;i < h;i++){
		int sti = w - 1;
		int stj = i;
		bool c = true;
		int cnt = 0;
		map<char,int> mp;
		while(sti >= 0 && stj < h){
			if(p[stj][sti] != '.'){
				if(mp[p[stj][sti]] == 0){
					cnt += 1;
					mp[p[stj][sti]] = 1;
					if(cnt == 2)able = false;
				}
				c = false;
			}
			sti--;
			stj++;
		}
		if(c) ans = (ans * 2ll)% 998244353;
	}
	if(able == true)cout << ans << endl;
	else cout << 0 << endl;
}


#include <iostream>
#include <vector>
#include <utility>
#include <tuple>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
using pii = pair<int,int>;

pii make_area(vector<vector<bool> >& map,pii cur,int req_area){
    pii next = cur;
    int x = cur.first; int y = cur.second;
    int tmpx = 10000;
    int tmp_area = 0;
    for(int h=0;h<10000-y;h++){
        for(int w=0;w<min(req_area/(h+1),min(10000-x,tmpx));w++){
            if(!map[x+w][y+h] && (w+1)*(h+1) < req_area && tmp_area < (w+1)*(h+1)){
                next.first = x+w+1; next.second = y+h+1;
                tmp_area = (w+1)*(h+1);
            }
            else if(map[x+w][y+h]){
                tmpx = w;
                break;
            }
        }
    }

    for(int i=x;i<next.first;i++){
        for(int j=y;j<next.second;j++){
            map[i][j] = true;
        }
    }

    return next;
}

pii search_area(vector<vector<bool> >& map,pii cur){
    while(map[cur.first][cur.second]){
        if(cur.first == 10000 && cur.second == 10000) break;
        cur.first++;
        if(cur.first == 10001){
            cur.first = 0;
            cur.second++;
        }
    }
    return cur;
}

int main(){
    // init
    int n;
    cin >> n;
    vector<tuple<int,pii,int> > req(n);
    vector<pair<pii,pii> > ans(n);
    vector<vector<bool> > map(10001,vector<bool>(10001,false));

    // input
    for(int i=0;i<n;i++){
        int x,y,r;
        cin >> x >> y >> r;
        req[i] = make_tuple(r,pii(x,y),i);
    }

    // sort
    sort(req.begin(),req.end());

    //solve
    pii empty_cor = make_pair(0,0);
    for(int i=0;i<n;i++){
        int area = get<0>(req[i]);
        pii cor = get<1>(req[i]);
        int order = get<2>(req[i]);
        if(!map[cor.first][cor.second]){
            ans[order] = pair<pii,pii>(cor,make_area(map,cor,area));
        }
        else {
            pii next = search_area(map,empty_cor);
            empty_cor = next;
            map[next.first][next.second] = true;
            ans[order] = pair<pii,pii>(next,pii(next.first+1,next.second+1));
        }
    }

    //output
    for(auto&a:ans){
        if(a.first.first >= a.second.first) {
            //cout << "caution:";
            a.second.first = a.first.first+1;
        }
        if(a.first.second >= a.second.second) {
            //cout << "caution:";
            a.second.second = a.first.second+1;
        }
        cout << a.first.first << " " << a.first.second << " " << a.second.first << " " << a.second.second << endl;
    }
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y));
#define chmax(x,y) x = max((x),(y));
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n),p(n);
    vector<int> have(n);
    bool ok = true;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> p[i];
    rep(i,n){
        --p[i];
        have[i] = p[i];
        if(b[have[i]] >= a[i] && i != have[i]){
            ok = false;
        }
    }
    if(!ok){
        cout << -1 << endl;
        return 0;
    }
    vector<int> idx(n);//誰が持ってる
    rep(i,n){
        idx[have[i]] = i;
    }
    priority_queue<P> pq;
    rep(i,n){
        if(have[i] == i) continue;
        pq.push(P(b[i],i));
    }
    vector<P> ans;
    while(!pq.empty()){
        int bb = pq.top().first;
        int id = pq.top().second;
        pq.pop();
        if(idx[id] == id) continue;
        int s = idx[id];//idをもつひと
        int t = have[id];//idのもつもの
        swap(idx[id],idx[t]);
        swap(have[s],have[id]);
        ans.emplace_back(s,id);
    }
    cout << (int)ans.size() << endl;
    rep(i,ans.size()){
        cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
    }
    return 0;
}


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

ll solve() {
    ll N, M;
    cin >> N >> M;
    vector<ll> L(N), R(N);
    if ( N == 1 ) {
        if ( M != 0 ) return -1;
        cout << 1 << " " << 2 << "\n";
        return 0;
    }
    if ( M > N-2 ) return -1;
    if ( M < 0 ) return -1;
    for ( int i = 1; i < N; i++ ) {
        L[i] = 4*i+1;
        R[i] = 4*i+3;
    }
    L[0] = 2;
    R[0] = 4*(M+1)+2;
    for ( int i = 0; i < N; i++ ) {
        cout << L[i] << " " << R[i] << "\n";
    }
    return 0;
}

int main() {
    auto ans = solve();
    if ( ans < 0 ) {
        cout << ans << "\n";
    }
    return 0;
}

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

using namespace __gnu_pbds;
using namespace std;

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(1e18)
// #define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

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

	if(m < 0 || (m >= n-1 && m)) {
		cout << -1 << endl;
		return;
	}
	m++;
	for(int i = 1; i <= n-m; i++) {
		cout << i << " " << 1000000000-i << endl;
	}
	int cur = n-m+10;
	for(int i = 1; i <= m; i++) {
		cout << cur << " " << cur+1 << endl;
		cur += 3;
	}
	assert(cur <= 1e9);
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(20);

    for(int i = 1; i <= test; ++i){
    	solve();
    	cout << endl;
    }

    cerr << time(start);
    return 0;
}


// 2021
#include <bits/stdc++.h>
#define rep(i, x, y) for(register int i = x; i < y; i++)
#define REP(i, x, y) for(register int i = x; i <= y; i++)
#define per(i, x, y) for(register int i = x; i > y; i--)
#define PER(i, x, y) for(register int i = x; i >= y; i--)
#define repl(i, x, y) for(register long long i = x; i < y; i++)
#define REPL(i, x, y) for(register long long i = x; i <= y; i++)
#define perl(i, x, y) for(register long long i = x; i > y; i--)
#define PERL(i, x, y) for(register long long i = x; i >= y; i--)
#define LLL __int128
#define int128 __int128
#define DEBUG(x) cerr << #x << " : " << x << endl
using namespace std;
typedef unsigned int uint;
typedef long long int64;
typedef long long LL;
typedef unsigned long long uint64;
typedef unsigned long long ULL;
typedef long double LLF;
inline void NO() { cout << "NO\n"; }
inline void YES() { cout << "YES\n"; }
inline void NEG() { cout << "-1\n"; }
template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; }
template<typename T> inline void read(T &val)
{
	val = 0; char c = getchar(); int f = 1;
	while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)) { val = (val << 3) + (val << 1) + (c ^ 48); c = getchar(); }
	val *= f;
}
template<typename T> void write_(T val) { if(!val) return; write_(val / 10); putchar(val % 10 + 48); }
template<typename T> inline void write(T val)
{
	if(val == 0) putchar(48);
	else if(val < 0) { putchar('-'); write_(-val); }
	else write_(val);
}

#define int long long

const int MOD = 1e9 + 7, N = 1e5 + 5;
int n, a[N], f[N][2], g[N][2];

signed main()
{
#ifdef LOCAL
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin >> n;
	REP(i, 1, n) cin >> a[i];
	if(n == 1)
	{
		cout << a[1] << endl;
		return 0;
	}
	g[1][0] = (a[1] - a[2] + MOD) % MOD;
	g[1][1] = (a[1] + a[2]) % MOD; // 0 = -
	f[1][0] = f[1][1] = 1;
	rep(i, 2, n)
	{
		f[i][0] = f[i - 1][1];
		g[i][0] = (g[i - 1][1] - (LL)f[i][0] * a[i + 1] % MOD + MOD) % MOD;
		f[i][1] = (f[i - 1][0] + f[i - 1][1]) % MOD;
		g[i][1] = ((g[i - 1][0] + g[i - 1][1]) % MOD + (LL)f[i][1] * a[i + 1] % MOD) % MOD;
	}
	cout << (g[n - 1][0] + g[n - 1][1]) % MOD << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = n; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n); (i) >= (int)(m); i--)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
// constexpr int INF = 1070000000;
// constexpr long long LINF = 4611686015206162431;
constexpr int MOD = 1000000007;
// constexpr long double PI = 3.1415926535897932;

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

using vec = vector<ll>;
using mat = vector<vector<ll>>;

mat matmul(mat &A, mat &B) {
    mat C(A.size(), vec(B[0].size()));
    rep (i, A.size()) {
        rep (k, A[0].size()) {
            rep (j, B[0].size()) {
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
            }
        }
    }
    return C;
}

mat matpow(mat A, ll n) {
    mat B(A.size(), vec(A.size()));
    rep (i, A.size()) B[i][i] = 1;
    while (n > 0) {
        if (n & 1) B = matmul(B, A);
        A = matmul(A, A);
        n >>= 1;
    }
    return B;
}

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

    int N, M, K;
    cin >> N >> M >> K;
    mat A(1, vec(N));
    rep (i, N) cin >> A[0][i];
    vvc<int> graph(N);
    rep (i, M) {
        int X, Y;
        cin >> X >> Y;
        X--; Y--;
        graph[X].push_back(Y);
        graph[Y].push_back(X);
    }

    ll invm = modinv(M, MOD), inv2 = modinv(2, MOD);

    mat B(N, vec(N));

    rep (j, N) {
        for (int i : graph[j]) {
            B[i][j] = invm * inv2 % MOD;
        }
        B[j][j] = ((M - graph[j].size() + inv2 * graph[j].size()) % MOD) * invm % MOD;
    }

    B = matpow(B, K);
    A = matmul(A, B);
    rep (i, N) {
        cout << A[0][i] << endl;
    }
}


#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 {
  int T, X, Y;
};

int n, m, q;
int 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, ll 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";
  }
}

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()

struct TrieNode{
	int n = 0;
	long long sum = 0;
	TrieNode* l = nullptr, * r = nullptr;
};

class Trie {
public:
	Trie() { root = new TrieNode(); }

	void insert(int x) {
		TrieNode* t = root;
		for (int i = 30; i >= 0; i--) {
			t->n++;
			t->sum += x;
			if (x >> i &1) {
				if (t->r == nullptr) t->r = new TrieNode;
				t = t->r;
			}
			else {
				if (t->l == nullptr) t->l = new TrieNode;
				t = t->l;
			}
		}
		t->n++;
		t->sum += x;
	}

	void erase(int x) {
		TrieNode* t = root;
		for (int i = 30; i >= 0; i--) {
			t->n--;
			t->sum -= x;
			if (x >> i & 1) {
				t = t->r;
			}
			else {
				t = t->l;
			}
		}
		t->n--;
		t->sum -= x;
	}

	pair<int, long long> query(int x) const{
		pair<int, long long > ret(0, 0);
		TrieNode* t = root;
		for (int i = 30; i >= 0; i--) {
			if (t == nullptr)break;
			if (x >> i & 1) {
				if (t->l) {
					ret.first += t->l->n;
					ret.second += t->l->sum;
				}
				t = t->r;
			}
			else {
				t = t->l;
			}
		}
		return ret;
	}
private:
	TrieNode* root;
};

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

	int n, m, q;
	cin >> n >> m >> q;

	vector<int> a(n, 0), b(m, 0);

	Trie ta, tb;
	rep(i, n) ta.insert(0);
	rep(i, m)tb.insert(0);

	long long ans = 0;
	rep(_, q) {
		int t, x, y;
		cin >> t >> x >> y;
		x--;

		if (t == 1) {
			auto p = tb.query(a[x]);
			ans -= (long long)p.first * a[x];
			ans += p.second;

			p = tb.query(y);
			ans += (long long)p.first * y;
			ans -= p.second;

			ta.erase(a[x]);
			ta.insert(y);
			a[x] = y;
		}
		else {
			auto p = ta.query(b[x]);
			ans -= (long long)p.first * b[x];
			ans += p.second;

			p = ta.query(y);
			ans += (long long)p.first * y;
			ans -= p.second;

			tb.erase(b[x]);
			tb.insert(y);
			b[x] = y;
		}
		cout << ans << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int Q;
  cin>>Q;
  string ans="atcoder";
  while(Q--){
    string S;
    cin>>S;
    string T=S;
    int N=S.size();
    int mn=N*N;
    sort(T.rbegin(),T.rend());
    if(T<=ans){
      puts("-1");
      goto home;
    }
    if(S>ans){
      puts("0");
      goto home;
    }
    for(int i=min(6LL,N-1);i>=0;i--)
      if(S.substr(0,i)==ans.substr(0,i))
        for(int j=i+1;j<N;j++)
          if(S[j]>ans[i]){
            mn=min(mn,j-i);
          }
    cout<<mn<<endl;
    home:;
  }
}

// Problem : B - Permutation Check
// Contest : AtCoder - AtCoder Beginner Contest 205
// URL : https://atcoder.jp/contests/abc205/tasks/abc205_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define int   long long
#define FAST  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair<int,int>   pii;
typedef vector<int>     vi;
#define rep(i,s,e)      for(int i=(s);i<(e);i++)
#define pb              push_back
#define ff              first
#define ss              second
#define all(x)          (x).begin(), (x).end()
#define INF             (long long) 1e15
#define MOD             1000000007
#define MAX             (int) 2e5+5

void solve() {
    int n;
    cin >> n;
    int arr[n];
    rep(i,0,n) cin >> arr[i];
    sort(arr,arr+n);
    int c = 1;
    rep(i,0,n){
        if(c == arr[i]) c++;
        else {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
}

int32_t main(){
    FAST
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}