#include<bits/stdc++.h>
using namespace std;
#define int long long
#define reg register
#define x1 x11
#define x2 x22
#define y1 y11
#define y2 y22
#define z1 z11
#define z2 z22
const int mod=1e9+7;
const int INF=2e16;
const int maxn=5e5+5;
const double Pi=acos(-1.0);
double Exp=1e-6;
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*10+ch-'0';
	    ch=getchar();
	}
	return x*f;
}
int n,m,s,t;
struct node
{
	int to;
	int nxt;
	int dis;
	int v;
}edge[maxn];
int wugui=0;
int head1[maxn];
void add(int x,int y,int d,int v)
{
	wugui++;
	edge[wugui].to=y;
	edge[wugui].nxt=head1[x];
	edge[wugui].dis=d;
	edge[wugui].v=v;
	head1[x]=wugui;
}
struct node1
{
	int x,y,t,k;
}a[maxn];
struct vode
{
	int id;
	int dist;
}love;
priority_queue<vode> q;
bool operator<(vode a,vode b)
{
	return a.dist>b.dist;
}
int vis[maxn];
int dist[maxn];
void dij()
{
	memset(dist,0x3f,sizeof(dist));
	//cout<<dist[2]<<endl;
	dist[s]=0;
	vode p;
	p.dist=0,p.id=s;
	q.push(p);
	while(!q.empty())
	{
		vode point=q.top();
		q.pop();
		if(vis[point.id])
		continue;
		vis[point.id]=1;
		for(int i=head1[point.id];i;i=edge[i].nxt)
		{
			int t=edge[i].to;
			int wns=dist[point.id]+edge[i].dis;
			if(point.dist%edge[i].v)
			{
				int tot=point.dist/edge[i].v;
				wns=wns+(tot+1)*edge[i].v-point.dist;
			}
			if(dist[t]>wns)
			{
				dist[t]=wns;
				vode p;
				p.dist=dist[t];
				p.id=t;
				q.push(p);
			}
		}
	}
}
signed main()
{
	n=read(),m=read(),s=read(),t=read();
	for(int i=1;i<=m;i++)
	{
		a[i].x=read(),a[i].y=read(),a[i].t=read(),a[i].k=read();
		add(a[i].x,a[i].y,a[i].t,a[i].k);
		add(a[i].y,a[i].x,a[i].t,a[i].k);
	}
	dij();
	if(dist[t]>=INF)
	{
		printf("-1\n");
	}
	else
	printf("%lld\n",dist[t]);
	return 0;
}

/*
40
1 4
2 3
5 8
6 7
*/

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>
#include <ctype.h>

using namespace std;

typedef long long ll;

const int INF = (1<<30)-1;
const ll LINF = (1LL<<60)-1;

#define rep(i, n) for (int i = 0; i < n; i++)

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

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

typedef pair<ll,ll> P;

struct edge {
    int to;
    ll cost;
    ll k;
    edge(int to, ll cost, ll k): to(to), cost(cost), k(k) {};
};

void dijkstra(vector<vector<edge> >&G, int s, vector<ll> &dist) {
    dist.resize(G.size());
    dist.assign(dist.size(), LINF);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, s));
    while (que.size()) {
        P p = que.top();    que.pop();
        int u = p.second;   ll d = p.first;
        if (dist[u] < d)    continue;
        for (auto e: G[u]) {
            int v = e.to;   ll c = e.cost, k = e.k;;
            if (chmin(dist[v], (d+k-1)/k*k+c))
                que.push(P(dist[v], v));
        }
    }
}

int main() {
    int n, m, x, y; cin >> n >> m >> x >> y;
    x--;    y--;
    vector<vector<edge> > G(n);
    rep(i, m) {
        int a, b;   ll t, k;    cin >> a >> b >> t >> k;
        a--;    b--;
        G[a].push_back(edge(b, t, k));
        G[b].push_back(edge(a, t, k));
    }
    vector<ll> dist;
    dijkstra(G, x, dist);
    if (dist[y] < LINF)
        cout << dist[y] << endl;
    else
        cout << -1 << endl;
    return 0;
}

//小数点精度
//cout << fixed << std::setprecision(15) << y << endl;


#include<bits/stdc++.h>
#define it register int
#define ct const int
#define il inline
using namespace std;
typedef long long ll;
#define rll register ll
#define cll const ll
#define fir first
#define sec second
const int N=1000005;
namespace io{
	il char nc(){
		static char buf[100000],*p1=buf,*p2=buf;
		return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
	}
	template <class I>
	il void fr(I &num){
		num=0;register char c=nc();it p=1;
		while(c<'0'||c>'9') c=='-'?p=-1,c=nc():c=nc();
		while(c>='0'&&c<='9') num=num*10+c-'0',c=nc();
		num*=p;
	}
	char obuf[1000001],*os=obuf, *ot=obuf+1000001;
	il void flush(){fwrite(obuf,1,os-obuf,stdout),os=obuf;}
	il void ptc(const char x){*os++=x,os==ot?flush():void();}
	template<class I>
	il void wr(I x){
		x<0?ptc('-'),x=-x:0;
		static char qu[65];
		char *tmp=qu;
		do *tmp++=(x%10)^'0';while(x/=10);
		while(tmp--!=qu) ptc(*tmp);
	}
	struct flusher{ ~flusher() { flush(); } }_;
}
using namespace io;
int n,a[N],lim;
vector<ll> b;
ll ans,K;
template<class I>
il void ckMax(I&p,I q){p=(p>q?p:q);}
il void dfs1(ct x,cll num){
	if(x>lim) return b.push_back(num),void();
	dfs1(x+1,num),dfs1(x+1,num+a[x]);
}
il void dfs2(ct x,cll num){
	//printf("x=%d num=%lld\n",x,num);
	//if(x>n&&num==a[7]) printf("%lld\n",*prev(std::upper_bound(b.begin(),b.end(),K-num)));
	if(x>n) return num<=K?ckMax(ans,num),0:0,K-num>=b[0]?ckMax(ans,*prev(std::upper_bound(b.begin(),b.end(),K-num))+num),0:0,void();
	dfs2(x+1,num),dfs2(x+1,num+a[x]);
}
int main(){
	scanf("%d%lld",&n,&K);it i;
	for(i=1;i<=n;++i) scanf("%d",&a[i]);
	ans=0,lim=n>>1,dfs1(1,0),std::sort(b.begin(),b.end()),dfs2(lim+1,0);
	//for(const auto &i : b) printf("%lld ",i);puts("");
	printf("%lld",ans);
	return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)

const ll INF = 1ll<<60;
class SegmentTree {
  ll n;
  // parent of k : (k-1)/2, child of k : 2*k+1, 2*k+2
  vector<ll> node;

public:
  SegmentTree(vector<ll> a){
    ll n_ = a.size();

    // round to power of 2
    n = 1;
    while(n < n_) n *= 2;

    // initialize tree
    node.resize(2*n-1, INF);

    // fill data into tree
    for (ll i = 0; i < n_; i++) node[n-1+i] = a[i];
    for (ll i = n-2; i >= 0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
  }

  // [3, 4, 2, 1] RMQ(0, 3) -> 2, RMQ(0, 4) -> 1
  ll RMQ(ll a, ll b, ll k=0, ll l=0, ll r=-1){
    if (r<0) r = n;
    if (r<=a || b<=l) return INF;
    if (a<=l && r<=b) return node[k];
    ll vl = RMQ(a, b, 2*k+1, l, (l+r)/2);
    ll vr = RMQ(a, b, 2*k+2, (l+r)/2, r);
    return min(vl, vr);
  }

  // k番目をvにする
  void update(ll k, ll v){
    k += n-1;
    node[k] = v;
    while(k>0){
      k = (k-1)/2;
      node[k] = min(node[k*2+1], node[k*2+2]);
    }
  }
};

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll now = 0;
  ll amax = 0;
  rep(i, n){
    amax = max(amax, a[i]);
    now = max(now, amax*b[i]);
    cout << now << endl;
  }

  return 0;
}


#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on

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

vector<ll> divisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) {
                res.push_back(n / i);
            }
        }
    }
    return res;
}
int main() {
    ll N;
    cin >> N;
    vector<ll> a(N);
    ll allmin = INF;
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
        allmin = min(a[i], allmin);
    }

    unordered_map<ll, ll> curgcd;
    for (auto ai : a) {
        vector<ll> succeeded;
        for (auto d : divisor(ai)) {
            if (d > allmin) continue;
            if (curgcd.count(d)) {
                curgcd[d] = gcdf(curgcd[d], ai);
            } else {
                curgcd[d] = ai;
            }
        }
    }
    ll ans = 0;
    for (auto x : curgcd) {
        ans += (x.first == x.second);
    }
    print(ans);
}

///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        gcd(a,b)        __gcd(a,b)
#define        lcm(a,b)        (a*b)/gcd(a,b)
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        mem(a,b)        memset(a, b, sizeof(a))
#define        uniq(v)         (v).erase(unique(all(v)),(v).end())
#define        mchk(mask,pos)  (mask & (1<<pos))
#define        mset(mask,pos)  (mask bitor (1<<pos))
#define        munset(mask,pos) (mask ^ (1<<pos))
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ; // Only for this N can't be greater than 1e6+5;segmentation fault;
ll      vis[N] ;
ll      arr[N] ;

ll sumd(ll a,ll b){return (((a%mod)+(b%mod))%mod);}
ll muld(ll a,ll b){return (((a%mod)*(b%mod))%mod);}
ll subd(ll a,ll b){return (((a%mod)-(b%mod)+mod)%mod);}
bool chk(ll ii,ll jj,ll nn,ll mm){if((0<=ii&&ii<nn)&&(0<=jj&&jj<mm)) return true;else return false;}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs, q;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>k;
    sum=0;
    for(i=1;i<=k;i++)
    {
       for(j=1;j<=k;j++)
       {
              if(i*j>k) break;
              sum+=(k/(i*j));
       }
    }
    cout<<sum<<endl;

    //code
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define rrep(i,a,b) for (int i = a - 1; i >= b; i--)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ll long long
#define dbwt(x) std::cout << fixed << setprecision(15) << x << '\n'
#define Wt(x) cout << x << '\n'
#define re0 return 0
#define Int(...) int __VA_ARGS__; in(__VA_ARGS__)
#define Ll(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; in(__VA_ARGS__)
#define Vec(t,a,s) vector<t>a(s); in(a)
#define Vec2(t,a,b,s) vector<t>a(s),b(s);rep(i,0,s)in(a[i],b[i])
#define Vec3(t,a,b,c,s) vector<t>a(s),b(s),c(s);rep(i,0,s)in(a[i],b[i],c[i])
#define Vec4(t,a,b,c,d,s) vector<t>a(s),b(s),c(s),d(s);rep(i,0,s) in(a[i],b[i],c[i],d[i])
#define mvec(t,a,i) vector<t>(a,i)
#define mvec2(t,a,b,i) vector<vector<t>>(a,vector<t>(b,i))
void scan(int& x) {std::cin >> x;}
void scan(ll& x) {std::cin >> x;}
void scan(double& x) {std::cin >> x;}
void scan(std::string& x) {std::cin >> x;}
void scan(std::vector<int>& x) {rep (i, 0, x.size()) std::cin >> x[i];}
void scan(std::vector<ll>& x) {rep (i, 0, x.size()) std::cin >> x[i];}
void in(){}
template<class Head, class... Tail>
void in(Head& head, Tail&... tail) {scan(head); in(tail...);}
template<class T, class U>
bool chmax(T& a, U b) {if(a < b){a=b; return true;} return false;}
template<class T, class U>
bool chmin(T& a, U b) {if(a > b){a=b; return true;} return false;}
using namespace std;
template<class T>
using vvec = vector<vector<T>>;
template<class T>
void emitvec(vector<T> a) {rep (i, 0, a.size()) cout << a[i] << " "; cout << endl;}
struct IoSetup {
   	IoSetup() {
     	cin.tie(nullptr);
     	ios::sync_with_stdio(false);
     	cout << fixed << setprecision(15);
   	}
} iosetup;

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

int N, M;
map<pair<int, int>, int> mp;
vector<vector<int>> g(100005);

vector<int> col(100005, -1);
vector<bool> visited(100005, false);

void dfs(int v) {
    visited[v] = true;
    for (int to: g[v]) {
        if (visited[to]) continue;
        if (col[v] == mp[{v, to}]) {
            col[to] = (col[v] == 1 ? N : 1);
        }
        else {
            col[to] = mp[{v, to}];
        }
        dfs(to);
    }
}

int main() {
    cin >> N >> M;
    Vec3(int, u, v, c, M);

    rep (i, 0, M) {
        mp[{u[i], v[i]}] = mp[{v[i], u[i]}] = c[i];
        g[u[i]].pb(v[i]);
        g[v[i]].pb(u[i]);
    }

    col[1] = 1;
    dfs(1);

    rep (i, 1, N + 1) cout << col[i] << endl;

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

vector<vector<pair<int,int>>> ex(500000);
vector<bool> seen(500000,false);
vector<int> ans(500000,0);

void dfs(int now, int par, int c){
    if(seen[now]) return;
    seen[now] = true;
    if(ans[par] != c) ans[now] = c;
    else if(c == 0) ans[now] = 1;
    for(auto p:ex[now]) dfs(p.first, now, p.second);
}

int main(){
    int n,m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int u,v,c;
        cin >> u >> v >> c;
        u--;v--;c--;
        ex[u].push_back({v,c});
        ex[v].push_back({u,c});
    }

    dfs(0,0,0);

    for(int i = 0; i < n; i++) cout << ans[i]+1 << endl;

    return 0;
}


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

int main()
{
    int i1, j1, i2, j2;
    cin >> i1 >> j1 >> i2 >> j2;

    i2 -= i1;
    j2 -= j1;
    i1 = 0;
    j1 = 0;
    i2 = abs(i2);
    j2 = abs(j2);

    if (i2 == 0 && j2 == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    if (i2 + j2 <= 3 || i2 == j2)
    {
        cout << 1 << endl;
        return 0;
    }

    if (i2 + j2 <= 6 || (i2 + j2) % 2 == 0 || abs(i2 - j2) <= 3)
    {
        cout << 2 << endl;
        return 0;
    }

    cout << 3 << endl;
    return 0;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a,b,x,y;
int main(){
	scanf("%d%d%d%d",&a,&b,&x,&y);
	if(a>b)printf("%d",min((a-b-1)*y+x,x*(((a-b)<<1)-1)));
	else printf("%d",min((b-a)*y+x,x*(((b-a)<<1)+1)));
	return 0;
}


// #include <iostream>
#include <map>
#include <iostream>

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

const int INF = 1000000001;

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

const ll mod = 1000000007;

int main(){
    int x,y;
    cin >> x >> y;
    if(max(x,y) < min(x,y) + 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  char c1, c2, c3;
  cin >> c1 >> c2 >> c3;
  cout << (c1 == c2 && c2 == c3 && c1 == c3 ? "Won" : "Lost") << '\n';
 	return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
#include <chrono>
#include <cassert>
#include <tuple>
#include <numeric>
#include <utility>
using namespace std;

namespace {
  using Integer = long long; //__int128;
  template<class T, class S> istream& operator >> (istream& is, pair<T,S>& p){return is >> p.first >> p.second;}
  template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
  template<class T> istream& operator ,  (istream& is, T& val){ return is >> val;}
  template<class T, class S> ostream& operator << (ostream& os, const pair<T,S>& p){return os << p.first << " " << p.second;}
  template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(size_t i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;}
  template<class T> ostream& operator ,  (ostream& os, const T& val){ return os << " " << val;}

  template<class H> void print(const H& head){ cout << head; }
  template<class H, class ... T> void print(const H& head, const T& ... tail){ cout << head << " "; print(tail...); }
  template<class ... T> void println(const T& ... values){ print(values...); cout << endl; }

  template<class H> void eprint(const H& head){ cerr << head; }
  template<class H, class ... T> void eprint(const H& head, const T& ... tail){ cerr << head << " "; eprint(tail...); }
  template<class ... T> void eprintln(const T& ... values){ eprint(values...); cerr << endl; }

  class range{ Integer start_, end_, step_; public: struct range_iterator{ Integer val, step_; range_iterator(Integer v, Integer step) : val(v), step_(step) {} Integer operator * (){return val;} void operator ++ (){val += step_;} bool operator != (range_iterator& x){return step_ > 0 ? val < x.val : val > x.val;} }; range(Integer len) : start_(0), end_(len), step_(1) {} range(Integer start, Integer end) : start_(start), end_(end), step_(1) {} range(Integer start, Integer end, Integer step) : start_(start), end_(end), step_(step) {} range_iterator begin(){ return range_iterator(start_, step_); } range_iterator   end(){ return range_iterator(  end_, step_); } };

  inline string operator "" _s (const char* str, size_t size){ return move(string(str)); }
  constexpr Integer my_pow(Integer x, Integer k, Integer z=1){return k==0 ? z : k==1 ? z*x : (k&1) ? my_pow(x*x,k>>1,z*x) : my_pow(x*x,k>>1,z);}
  constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z=1){return k==0 ? z%M : k==1 ? z*x%M : (k&1) ? my_pow_mod(x*x%M,k>>1,M,z*x%M) : my_pow_mod(x*x%M,k>>1,M,z);}
  constexpr unsigned long long operator "" _ten (unsigned long long value){ return my_pow(10,value); }

  inline int k_bit(Integer x, int k){return (x>>k)&1;} //0-indexed

  mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count());

  template<class T> string join(const vector<T>& v, const string& sep){ stringstream ss; for(size_t i=0; i<v.size(); i++){ if(i>0) ss << sep; ss << v[i]; } return ss.str(); }

  inline string operator * (string s, int k){ string ret; while(k){ if(k&1) ret += s; s += s; k >>= 1; } return ret; }
}
constexpr long long mod = 9_ten + 7;

int main(){
  int n, w;
  cin >> n, w;
  println(n/w);

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	cout << n/m << endl;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
const ll ll_inf = ll(1e9) * ll(1e9);
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define M 1000000007

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<ll> r;

    UnionFind(ll N) {
        r = vector<ll>(N, -1);
    }

    ll root(ll x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    ll size(ll x) {
        return -r[root(x)];
    }
};

ll coin[101][101][101] = {0};

int main() {

    ll a, b, x, y, d, s;
    cin >> a >> b >> x >> y;

    if (a > b) {
        d = a - b;
        if (2 * x < y) {
            s = (2 * x*d) - x;
        }
        else {
            s = (d - 1)*y + x;
        }
    }
    else {
        d = b - a;
        if (2 * x < y) {
            s = (2 * x*d) + x;
        }
        else {
            s = d * y + x;
        }
    }

    cout << s;

    return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int a,b,x,y;
    cin>>a>>b>>x>>y;
    int ans = x;
    if(a>b)
    {
        for(int i=b; i<a-1; i++) ans+=min(2*x,y);
    }
    else
    {
        for(int i=a; i<b; i++) ans+=min(2*x,y);
    }
    cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;
using ll = long long;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a) (a).begin(),(a).end()
void solve(vector<vector<int>> &A, vector<vector<int>> &B, int num){
    vector<vector<int>> retA(num - 1), retB(num - 1);
    For(i,0,A.size()){
        retA[i] = A[i];
        retA[i+A.size()] = A[i];
    }
    int idx = 0;
    for(int i=0; i<A.size(); i++){
        for(auto &e: A[i]) retA[idx].emplace_back(e + num / 2);
        idx++;
    }
    for(int i=0; i<B.size(); i++){
        for(auto &e: B[i]) retA[idx].emplace_back(e + num / 2);
        idx++;
    }
    retA[num - 2].clear();
    For(i,0,num/2){
        retA[num - 2].emplace_back(i);
    }
    For(i,0,num - 1){
        int t = 0;
        for(auto &a: retA[i]){
            while(t < a){
                retB[i].emplace_back(t);
                t++;
            }
            t++;
        }
        while(t < num){
            retB[i].emplace_back(t);
            t++;
        }
    }
    swap(A, retA);
    swap(B, retB);
}
void Print(vector<vector<int>> &A, vector<vector<int>> &B, int num){
    cout << A.size() << endl;
    For(i,0,A.size()){
        string ret(num, 'B');
        for(auto c:A[i]) ret[c] = 'A';
        cout << ret << endl;
    }
}
void Main(){
    int tn;
    cin >> tn;
    int n = (1 << tn);
    vector<vector<int>> A(1, {0}), B(1, {1});
    for(int num = 2; num < n; num *= 2){
        solve(A, B, num * 2);
    }
    /*
    for(int i=0; i<A.size(); i++){
        for(auto t:A[i]) cout << t << " ";
        cout << "vs ";
        for(auto t:B[i]) cout << t << " ";
        cout << endl;
    }
    cout << A.size() << " " << B.size() << endl;
    */
    Print(A, B, n);
}
void Editorial(){
    int n;
    cin >> n;
    cout << ((1<<n)-1) << endl;;
    For(i,1,1<<n){
        For(j,0,1<<n){
            cout << (__builtin_parity(i & j) ? 'A' : 'B');
        }
        cout << endl;
    }
}
int main(){
    // Main();
    Editorial();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

#include<bits/stdc++.h>

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

int gcd(ll x, ll y){
    if(x < y)swap(x, y);
    if(x % y == 0)return y;
    return gcd(y, x % y);
}

int extgcd(ll a, ll b, ll &x, ll &y){
    int d = a;
    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int main(){
    int t;
    cin >> t;
    vector<ll> ans(t);
    for(int i = 0; i < t; i++){
        ll n, s, k;
        cin >> n >> s >> k;
        ll div = gcd(n, k);
        if(s % div != 0){
            ans[i] = -1;
            continue;
        }
        n /= div;
        s /= div;
        k /= div;
        ll x, y;
        if(k > n) extgcd(k, n, x, y);
        else extgcd(n, k, y, x);
        ll m;
        if(- s * x > 0){
            if(s * x % n == 0){
                m = - s * x / n - 1;
            }else{
                m = - s * x / n;
            }
        }else{
            if(s * x % n == 0){
                m = - s * x / n - 1;
            }else{
                m = - s * x / n - 1;
            }
        }
        ans[i] = - n * m - s * x;
    }
    for(int i = 0; i < t; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define MOD 998244353
#define int long long
#define ull unsigned long long
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ceil(x,y) (x+y-1)/y
#define deb(x) { cerr << #x << '=' << x << '\n'; }
#define INF 0x3f3f3f3f
using namespace std;
int cnt = 0;
vector<int> graphrow[100], graphcol[100];
bool used[100];
void dfs(int v, int n);
int fact(int n);

void solve(){
    //code goes here
    int n,x;
    cin >> n >> x;
    vector<int> a[n];
    for (int i = 0; i<n; ++i){
        a[i].resize(n);
        for (int j = 0; j<n; ++j){
            cin >> a[i][j];
        }
    }
    for (int i = 0; i<n; ++i){
        for (int j = i+1; j<n; ++j){
            bool flag = 0;
            for (int k = 0; k<n; ++k){
                if (a[i][k] + a[j][k] > x){
                    flag = 1;
                    break;
                }
            }
            if (!flag){
                graphrow[i].pb(j);
                graphrow[j].pb(i);
            }
        }
    }
    int res1 = 1, res2 = 1;
    for (int i = 0; i<n; ++i){
        if (!used[i]){
            dfs(i,0);
            res1 *= fact(cnt);
            res1%=MOD;
            cnt = 0;
        }
    }
    memset(used,0,sizeof(used));
    for (int i = 0; i<n; ++i){
        for (int j = i+1; j<n; ++j){
            bool flag = 0;
            for (int k = 0; k<n; ++k){
                if (a[k][i] + a[k][j] > x){
                    flag = 1;
                    break;
                }
            }
            if (!flag){
                graphcol[i].pb(j);
                graphcol[j].pb(i);
            }
        }
    }
    for (int i = 0; i<n; ++i){
        if (!used[i]){
            dfs(i,1);
            res2 *= fact(cnt);
            res2%=MOD;
            cnt = 0;
        }
    }
    int res = res1*res2;
    res%=MOD;
    cout << res;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
}
void dfs(int v, int n){
    used[v] = 1;
    cnt++;
    if (n==0){
        for (auto i:graphrow[v]){
            if (!used[i]) dfs(i, 0);
        }
    }
    else{
        for (auto i:graphcol[v]){
            if (!used[i]) dfs(i, 1);
        }
    }
}
int fact(int n){
    int res = 1;
    if (n==0) return res;
    for (int i = 1; i<=n; ++i){
        res*=i;
        res%=MOD;
    }
    return res;
}

#include <bits/stdc++.h>

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

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

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

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

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

using namespace std;

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

//-------------------------------------------------
//--ModInt
//-------------------------------------------------
const uint_fast64_t MOD = 1e9+7;

class mint
{
private:
    using Value = uint_fast64_t;
    Value n;
public:
    mint():n(0){}
    mint(int_fast64_t _n):n(_n<0 ? MOD-(-_n)%MOD : _n%MOD){}
    mint(const mint &m):n(m.n){}

    friend ostream& operator<<(ostream &os, const mint &a){
		return os << a.n;
	}
    friend istream& operator>>(istream &is, mint &a){
        Value temp; is>>temp;
        a = mint(temp);
        return is;
    }

    mint& operator+=(const mint &m){n+=m.n; n=(n<MOD)?n:n-MOD; return *this;}
    mint& operator-=(const mint &m){n+=MOD-m.n; n=(n<MOD)?n:n-MOD; return *this;}
    mint& operator*=(const mint &m){n=n*m.n%MOD; return *this;}
    mint& operator/=(const mint &m){return *this*=m.inv();}
    mint& operator++(){return *this+=1;}
    mint& operator--(){return *this-=1;}

    mint operator+(const mint &m) const {return mint(*this)+=m;}
    mint operator-(const mint &m) const {return mint(*this)-=m;}
    mint operator*(const mint &m) const {return mint(*this)*=m;}
    mint operator/(const mint &m) const {return mint(*this)/=m;}
    mint operator++(int){mint t(*this); *this+=1; return t;}
    mint operator--(int){mint t(*this); *this-=1; return t;}

    bool operator==(const mint &m) const {return n==m.n;}
    bool operator!=(const mint &m) const {return n!=m.n;}
    mint operator-() const {return mint(MOD-n);}

    mint pow(Value b) const {
        mint ret(1), m(*this);
        while(b){
            if (b & 1) ret*=m;
            m*=m;
            b>>=1;
        }
        return ret;
    }

    mint inv() const {return pow(MOD-2);}
};

mint comb(ll a, ll b)
{
    if (a<b) return mint(0);
    mint nume = 1;
    mint deno = 1;
    rep(i,b){
        nume*=a-i;
        deno*=i+1;
    }
    return nume/deno;
}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M; cin>>N>>M;
    vll a(N);
    rep(i,N) cin>>a[i];
    ll sum = 0;
    rep(i,N) sum+=a[i];

    cout<<comb(N+M,sum+N)<<"\n";
    return 0;
}


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

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << ", " << a.second << ")";
  return out;
}

template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}

template<typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}

template<typename T>
ostream& operator <<(ostream& out, const vector<vector<T>>& a) {
  bool first = true;
  for (auto& v : a) {
    if (!first)
      out << "   ";
    for (auto& p : v)
      out << p << "  ";
    out << "\n";
    first = 0;
  }
  return out;
}

template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}

template <typename T, class Cmp>
ostream& operator <<(ostream& out, const multiset<T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& p : a) {
    out << (first ? "" : ", ");
    out << p.first << ":" << p.second;
    first = 0;
  }
  out << "}";
  return out;
}

#ifdef LOCAL
#define debug(...) dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 0
#endif

template <typename Arg1>
void dbg(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void dbg(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  dbg(comma + 1, args...);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n), pos(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    pos[p[i]] = i;
  }
  vector<int> b(n);
  iota(b.begin(), b.end(), 1);
  vector<bool> swapped(n);
  vector<int> res;
  for (int i = 0; i < n; i++) {
    if (p[i] != b[i]) {
      int idx = pos[b[i]];
      while (idx > i) {
        if (swapped[idx - 1]) {
          cout << "-1\n";
          return 0;
        }
        swap(p[idx - 1], p[idx]);
        swap(pos[idx - 1], pos[idx]);
        swapped[idx - 1] = true;
        res.emplace_back(idx);
        --idx;
      }
    }
  }
  if (res.size() != (n - 1))
    cout << "-1\n";
  else {
    for (int& p : res)
      cout << p << '\n';
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
#ifdef _GLIBCXX_DEBUG
void _debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void _debug_out(Head H, Tail... T) { cerr << " " << H; _debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#define eprintf(...)
#endif

int main() {
  int n; cin >> n;
  int INF=int(1e9)+1;
  int ans = INF;

  rep(i,n) {
    int a,p,x;
    cin >> a >> p >> x;
    if(x <= a) continue;
    umin(ans,p);
  }
  if(ans==INF) ans = -1;
  cout << ans << endl;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ppb pop_back
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr(a,b) for(int i = a; i < b; i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(x) (x).begin(),(x).end()
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define endl '\n'
using namespace std;
const ll MOD=1e9+7;
const ll INF= 998244353;
const ll N=1e6+1;

/*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(r) * fact(n - r));
}
// Returns factorial of n
*/
/*ll gcd(ll a, ll b)
{
  if(b==0)
    return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
  return (a*b)/gcd(a,b);
}

*/
/*bool isprime(ll n)
{
  ll i;
  for(i=2;i*i<=n;i++)
  {
    if(n%i==0)
    {
      return false;
    }
  }
  return true;
}*/

void solve()
{
  ll n;
  cin>>n;
  ll num=(n/100)+1;
  cout<<abs((num*100)-n)<<endl;
}

int main()
{
  fast_io;
  cin.tie(0);cout.tie(0);
  ll t;
  t=1;
  //cin>>t;
  while(t--)
  {
    solve();
  }
  return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n; cin >> n;
    int d = n % 1000;
    int p = n / 100 % 10 + 1; p *= 100;
    cout << p - d << "\n";
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 5050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\n\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
int sum[4][N];
char c[] = {'A', 'T', 'C', 'G'};
int n;
char s[N];
bool check1(int l, int r)
{
    int tmp1 = sum[0][r] - sum[0][l - 1];
    int tmp2 = sum[1][r] - sum[1][l - 1];
    int tmp3 = sum[2][r] - sum[2][l - 1];
    int tmp4 = sum[3][r] - sum[3][l - 1];
    if (tmp1 > 0 && tmp2 > 0 && tmp3 > 0 && tmp4 > 0 && tmp1 == tmp2 && tmp3 == tmp4)
        return 1;
    if (tmp1 + tmp2 == 0 && tmp3 > 0 && tmp4 > 0 && tmp3 == tmp4)
        return 1;
    if (tmp1 > 0 && tmp2 > 0 && tmp3 + tmp4 == 0 && tmp1 == tmp2)
        return 1;
    return 0;
}

inline void solve()
{
    cin >> n;
    scanf("%s", s + 1);
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j < 4; ++j)
            sum[j][i] = sum[j][i - 1] + (s[i] == c[j]);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = i + 1; j <= n; ++j)
        {
            if (check1(i, j))
                ans++;
        }
    }
    printf("%d\n", ans);
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
    {
        solve();
        // if (Test)
        //     putchar('\n');
    }
    TIME__END = clock();
    program_end();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
	reg bool f=false;
	reg char ch=getchar();
	reg int res=0;
	while(!isdigit(ch))f|=(ch=='-'),ch=getchar();
	while(isdigit(ch))res=10*res+(ch^'0'),ch=getchar();
	return f?-res:res;
}
inline ll readll(void){
	reg bool f=false;
	reg char ch=getchar();
	reg ll res=0;
	while(!isdigit(ch))f|=(ch=='-'),ch=getchar();
	while(isdigit(ch))res=10ll*res+(ch^'0'),ch=getchar();
	return f?-res:res;
}

const int MAXN=50+5;

int n;
ll x;
ll a[MAXN];
map<ll,ll> f,g;

int main(void){
	n=read(),x=readll();
	for(reg int i=1;i<=n;++i)
		a[n-i+1]=readll();
	ll x0=x/a[1]*a[1];
	f[x0]=1;
	if(x0!=x)
		f[x0+a[1]]=1;
	for(reg int i=2;i<=n;++i){
		g.clear();
		reg ll Max=a[i-1]/a[i];
		for(auto it:f){
			reg ll d=x-it.first,m=d/a[i];
			ll y=it.first+m*a[i];
			if(abs(m)<Max)
				g[y]+=it.second;
			if(y!=x&&abs(m)+1<Max)
				g[y+a[i]*(d/abs(d))]+=it.second;
		}
		swap(f,g);
	}
	printf("%lld\n",f[x]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
// template <class T = ll> using P = pair< T,T>;
template <class T = ll> using V = vector<T>;
template <class T = ll> using VV = V<V<T>>;
#define rep(i,n) for(int i=0; i<(n);++i)
#define repp(i, l, r) for(int i = (l); i < (r); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()

int main()
{
    int n;
    cin >> n;
    V<pair<int,int>> x(n);
    V<pair<int,int>> y(n);
    rep(i, n) {
        cin >> x[i].first >> y[i].first;
        x[i].second = i;
        y[i].second = i;
    }
    sort(all(x), greater<pair<int,int>>());
    sort(all(y), greater<pair<int,int>>());

    V<pair<pair<int,int>,int>> ans;
    {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = x[0].second;
        a.second = x[n-1].second;
        can.first = a;
        can.second = x[0].first - x[n-1].first;
        ans.push_back(can);
    }
        {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = y[0].second;
        a.second = y[n-1].second;
        can.first = a;
        can.second = y[0].first - y[n-1].first;
        ans.push_back(can);
    }
        {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = x[1].second;
        a.second = x[n-1].second;
        can.first = a;
        can.second = x[1].first - x[n-1].first;
        ans.push_back(can);
    }
        {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = x[0].second;
        a.second = x[n-2].second;
        can.first = a;
        can.second = x[0].first - x[n-2].first;
        ans.push_back(can);
    }
        {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = y[1].second;
        a.second = y[n-1].second;
        can.first = a;
        can.second = y[1].first - y[n-1].first;
        ans.push_back(can);
    }
        {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = y[0].second;
        a.second = y[n-2].second;
        can.first = a;
        can.second = y[0].first - y[n-2].first;
        ans.push_back(can);
    }
    sort(all(ans), [](auto lhs, auto rhs){return lhs.second > rhs.second;});
    ll cnt = 0;
    pair<int,int> pre;
    for(auto abc : ans){
        if(pre == abc.first) continue;
        cnt++;
        pre = abc.first;
        if(cnt == 2){
            cout << abc.second << endl;
        }
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int,int> > x,y;
vector<int> ans;
map<pair<int,int>,int > ma;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int u,v;
        cin>>u>>v;
        x.push_back({u,i});
        y.push_back({v,i});
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    int a=x.size();
    int b=y.size();
    for(int i=a-1;i>=a-3;i--)
    {
        ans.push_back(abs(x[0].first-x[i].first));
        ma[{x[0].second,x[i].second}]=1;
    }
    for(int i=0;i<3;i++)
    {
        if(ma[{x[i].second,x[x.size()-1].second}]==0)
            {
                ans.push_back(abs(x[i].first-x[x.size()-1].first));
                ma[{x[i].second,x[x.size()-1].second}]=1;
            }
    }
    for(int i=b-1;i>=b-3;i--)
    {
        if(ma[{y[0].second,y[i].second}]==0)
            {
                ans.push_back(abs(y[0].first-y[i].first));
                ma[{y[0].second,y[i].second}]=1;
            }
    }
    for(int i=0;i<3;i++)
    {
        if(ma[{y[i].second,y[x.size()-1].second}]==0)
            {
                ans.push_back(abs(y[i].first-y[x.size()-1].first));
                ma[{x[i].second,x[x.size()-1].second}]=1;
            }
    }
    sort(ans.begin(),ans.end());
    cout<<ans[ans.size()-2];
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll getNcR(int n, int r)
{

    // p holds the value of n*(n-1)*(n-2)...,
    // k holds the value of r*(r-1)...
    long long p = 1, k = 1;

    // C(n, r) == C(n, n-r),
    // choosing the smaller value
    if (n - r < r)
        r = n - r;

    if (r != 0)
    {
        while (r)
        {
            p *= n;
            k *= r;

            // gcd of p, k
            long long m = __gcd(p, k);

            // dividing by gcd, to simplify
            // product division by their gcd
            // saves from the overflow
            p /= m;
            k /= m;

            n--;
            r--;
        }

        // k should be simplified to 1
        // as C(n, r) is a natural number
        // (denominator should be 1 ) .
    }

    else
        p = 1;

    // if our approach is correct p = ans and k =1
    return p;
}
int main()
{
    ll k;
    int a, b;
    int n;
    cin >> a >> b >> k;
    string s = " ";
    n=(a+b);
    for (int i = 0; i < n; i++)
    {
        if (a == 0)
        {
            s.push_back('b');
            b--;
        }
        else if (b == 0)
        {
            s.push_back('a');
            a--;
        }
        else
        {
            ll exper = getNcR(a + b -1 , a - 1);
            if (exper >= k)
            {
                s.push_back('a');
                a--;
            }
            else
            {
                s.push_back('b');
                k -= exper;
                b--;
            }
        }
    }
    cout<<s<<endl;
}

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define dd double
#define ll long long int
#define ull unsigned long long
#define lld long double
#define setpre(n) cout << std::setprecision(n);
#define flush fflush(stdin); fflush(stdout);
#define print cout<<"Case #"<<test_case<<": ";
#define light ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define fi first
#define sc second
#define PI 3.141592653589793238462

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.fi); cerr << ","; _print(p.sc); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

ll mod1 = 1e9+7;
ll INF=1e9+5;
ll mod=998244353;

void solve(ll test_case){
	ll a,b,k;
	cin>>a>>b>>k;
	k--;
	vector<vector<ll> > dp(31,vector<ll>(61));
	ll i,j;
	for(i=1;i<=60;i++)
		dp[1][i] = i;
	for(i=2;i<=30;i++){
		for(j=i;j<=60;j++){
			dp[i][j] = dp[i-1][j-1]+dp[i][j-1];
		}
	}
	debug(dp)
	ll no2 = b;
	vector<char> ans(a+b,'a');
	while(k){
		ll in = upper_bound(dp[no2].begin(),dp[no2].end(),k) - dp[no2].begin() - 1;
		ans[a+b-1-in] = 'b';
		k-=dp[no2][in];
		no2--;
	}
	ll in = a+b-1;
	b = no2;
	while(b){
		//cout<<ans[in]<<" ";
		if(ans[in]!='b'){
			ans[in] = 'b';
			in--; b--;
		}
		else
			in--;
	}
	for(auto ele:ans) cout<<ele;
}

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

    light;
    ll t=1;
    //cin>>t;
    ll i=1ll;
    while(t--){
        solve(i);
        i++;
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
//#include <set>
using namespace std;
typedef long long LONG;
#include <iomanip>

LONG gcd(LONG x, LONG y) {
    if(x % y == 0) {
        return y;
    } else {
        return gcd(y, x % y);
        //x%y==0でないときはユーグリットの互除法を使って再帰的に関数を呼び出す。
    }
}
void print(vector<int>A){
    for(size_t i=0;i<A.size();i++){
        if(A[i]==1){
            cout<<'(';
        }else{
            cout<<')';
        }
    }
}

bool comp1(pair<int,int> lhs, pair<int,int>rhs) {
    return lhs.first<rhs.first;
}

bool comp2(pair<string,int> lhs, pair<string,int>rhs) {
    return lhs.second<rhs.second;
}
void solve(int min,int max,vector<int>&A,int B){
    if(min+1==max){
        cout<<std::min(A[max]-B,B-A[min])<<endl;
        return;
    }
    int a=(min+max)/2;
    if(A[a]<B){
        solve(a,max,A,B);
    }else{
        solve(min,a,A,B);
    }

}
LONG pow2(LONG a,LONG b){
    LONG res=1;
    for(int i=0;i<b;i++){
        res=res*a;
    }
    return a;
}

void solve1(vector<bool>&A,vector<LONG>&C,int pos,vector<vector<pair<int,LONG>>>&path){
    for(int i=0;i<path[pos].size();i++){
        if(!A[path[pos][i].first]){
            A[path[pos][i].first]=true;
            C[path[pos][i].first]=C[pos]^path[pos][i].second;
            solve1(A,C,path[pos][i].first,path);
        }
    }
}
int min(int a,int b){
    if(a<b){
        return a;
    }
    return b;
}

const LONG mod=1000000007;
int main() {
    cout << std::fixed << std::setprecision(15) << endl;
    LONG N;
    cin>>N;
    vector<LONG>A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    int a=A[A.size()/2];
    double result=0;
    for(int i=0;i<N;i++){
        result+=min(A[i],a)-A[i];
    }
    cout<<-(result/N-a/2.0);

}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(),a.end()
typedef pair<ll,ll> pi;

//__builtin_popcountll(2) (the number of ones in the binary representation)
//__builtin_clz(2) (number of leading zeroes)
//__builtin_ctz(2) (number of trailing zeroes)

/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>*/
// s.find_by_order(k)(returns iterator to kth element), s.order_of_key(k)(number of elements less than number)

ll mod = 1e9+7;
vector<ll> fact(1);
/*vector<ll> spf(10000005), cntPrime(10000005);

void spff(){
    int i;
    for(i=1;i<10000005;i++) spf[i] = i;
    for(i=2;i*i<10000005;i++)
    {
        if(spf[i] != i) continue;
        for(int j = i*i; j < 10000005; j+= i){
            if(spf[j]==j) spf[j] = i;
        }
    }
    for(i=1;i<10000005;i++){
        if(spf[i] != spf[i/spf[i]]){
            cntPrime[i] = cntPrime[i/spf[i]]+1;
        }
        else cntPrime[i] = cntPrime[i/spf[i]];
    }
}
while(spf[a[i]]!=a[i]){
              z=spf[a[i]];
              while(a[i]%z==0) a[i]/=z;
              m[z]++;
          }
          if(a[i]>1) m[a[i]]++;*/

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

ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;

    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

ll modInv(ll n, ll p)
{
    return power(n, p - 2, p);
}

ll ncr(ll n, ll r) {return (n>=r?(fact[n]*modInv(fact[r],mod))%mod*modInv(fact[n-r],mod)%mod:0);}

ll add(ll a, ll b) {ll z=a+b; if(z>=mod) z -= mod; return z;}
ll mul(ll a, ll b) { return (a*b)%mod;}
ll sub(ll a, ll b) { return (a-b+mod)%mod;}
// LLONG_MAX

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  ll t=1,n,i,j,m;
  //cin>>t;
  //fact[0]=1;
  //for(i=1;i<300003;i++)fact[i]=(fact[i-1]*i)%mod;
  while(t--)
  {
      cin>>n;
      cout<<fixed<<setprecision(10);
      vector<db> a(n);
      db sum=0, mx=0;
      for(i=0;i<n;i++) {
          cin>>a[i];
          mx=max(mx,a[i]);
          sum+=a[i];
      }

      db sm = (mx/10000000);
      db lo=0, hi=mx/2.0-sm, mid;
      //cout<<sum/n;

      db cur=0;

      while(lo <= hi){
          //cout<<lo<<' '<<hi<<endl;
          mid = (lo+hi)/2.0;

          db prev=0,aft=0; cur=0;
          for(i=0;i<n;i++){
              prev -= min(a[i], 2*(mid-sm));
              cur -= min(a[i], 2*mid);
              aft -= min(a[i], 2*(mid+sm));
          }

          prev /= n; cur /= n; aft /= n;
          prev+=mid-sm+(sum/n);aft+=mid+sm+(sum/n);cur+=mid+(sum/n);
          //cout<<prev<<'q'<<cur<<'q'<<aft<<"\n\n";

          if(cur < prev && cur < aft) break;
          if(prev > cur) lo = mid+sm;
          else hi = mid-sm;
      }

      cout<<cur;
  }
}


#include <bits/stdc++.h>

using namespace std;

const int MOD = 1077563119;
int n, m;
bool edge[20][20];

int chromaticNumber(const vector<int> &g) {
    int n = g.size();
    if (n == 0) return 0;
    //randomly choose a large prime
    const int modulo = 1077563119;
    int all = 1 << n;
    vector<int> ind(all), s(all);
    for (int i = 0; i < all; i ++) s[i] = ((n - __builtin_popcount(i)) & 1 ? -1 : 1);
    ind[0] = 1;
    for (int i = 1; i < all; i ++) {
        int ctz = __builtin_ctz(i);
        ind[i] = ind[i - (1 << ctz)] + ind[(i - (1 << ctz)) & ~g[ctz]];
        if (ind[i] >= modulo) ind[i] -= modulo;
    }
    //compute the chromatic number (= \sum (-1)^{n - |i|} * ind(i)^k)
    for (int k = 1; k < n; k ++) {
        long long sum = 0;
        for (int i = 0; i < all; i ++) {
            long long cur = ((s[i] * (long long) ind[i]) % modulo);
            s[i] = cur;
            sum += cur;
        }
        if (sum % modulo != 0) return k;
    }
    return n;
}

int main() {
#ifdef ACM
    freopen("input", "r", stdin);
#endif
    cin >> n >> m;
    int u, v;
    while (m--) {
        cin >> u >> v;
        u--, v--;
        edge[u][v] = edge[v][u] = true;
    }
    vector<int> g(n);
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (!edge[i][j]) {
                g[i] += (1 << j);
                g[j] += (1 << i);
            }
    cout << chromaticNumber(g);
}

#include <bits/stdc++.h>

#define TRACE(x) cerr << #x << " = " << x << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

#define SZ(x) (int)(x).size()

using namespace std;

typedef long long ll;
typedef double lf;
typedef pair<int, int> pii;
typedef vector<int> VI;

template<class Num>
Num mabs(Num A){
  if(A < 0) return -A;
  return A;
}

int main(){
  int n, m;
  cin >> n >> m;
  VI hei(n);
  VI moje(m);

  REP(i, n)
    cin >> hei[i];
  REP(i, m)
    cin >> moje[i];

  sort(hei.begin(), hei.end());
  vector<ll> pref_prije(n + 2, 0), suf_nakon(n + 2, 0);
  for(int i = 0; i < n - 1; i += 2){
    pref_prije[i] = (ll)(hei[i + 1] - hei[i]);
    if(i) pref_prije[i] += pref_prije[i - 1];
    pref_prije[i + 1] = pref_prije[i];
    if(i + 2 >= n - 1)
      pref_prije[i + 2] = pref_prije[i];
  }

  for(int i = n - 1; i >= 1; i -= 2){
    suf_nakon[i] = (ll)(hei[i] - hei[i - 1]);
    suf_nakon[i] += suf_nakon[i + 1];
    suf_nakon[i - 1] = suf_nakon[i];
    if(i - 2 < 1 && i - 2 >= 0)
      suf_nakon[i - 2] = suf_nakon[i];
  }

  //REP(i, n)
  //  cout << pref_prije[i] << ' ';
  //cout << endl;
  //REP(i, n)
  //  cout << suf_nakon[i] << ' ';
  //cout << endl;
  //
  //return 0;

  ll ans = (ll)2e18;

  REP(i, m){
    int val = moje[i];
    int pos = lower_bound(hei.begin(), hei.end(), val) - hei.begin();

    ll tmp = 0ll;
    if(pos % 2 == 0){
      //prije ih je parno
      if(pos > 0) tmp = pref_prije[pos - 1];
      if(pos < n) tmp += (ll)(hei[pos] - val);
      if(pos + 1 <= n)
        tmp += suf_nakon[pos + 1];
    }

    else{
      if(pos >= 2) tmp = pref_prije[pos - 2];
      if(pos > 0) tmp += (ll)(val - hei[pos - 1]);
      if(pos <= n)
        tmp += suf_nakon[pos];
    }

    //TRACE(tmp);

    ans = min(ans, tmp);
  }

  cout << ans << '\n';

  return 0;
}


#include <cstdio>

using u32 = unsigned int;
using u64 = unsigned long long int;

constexpr u32 mod = 998244353;

int n, m, k;

/*
A1 ... AN
B1 ... BM

Bmin >= Amax
*/

u32 modpow(u32 a, u32 n){
  u32 r = 1;
  for(; n; n>>=1){
    if(n&1) r = (u64) r * a % mod;
    a = (u64) a * a % mod;
  }
  return r;
}

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

  u64 ans = 0;

  if(n == 1){
    for(int i = 1; i <= k; i++){
      ans += modpow(k - i + 1, m) - modpow(k - i, m) + mod;
    }
  }
  else if(m == 1){
    for(int i = 1; i <= k; i++){
      ans += modpow(i, n) - modpow(i - 1, n) + mod;
    }
  }
  else {
    for(int i = 1; i <= k; i++){
      ans += (u64) (modpow(i, n) - modpow(i-1, n) + mod) * modpow(k - i + 1, m) % mod;
    }
  }

  printf("%llu\n", ans % mod);

  return 0;
}

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

#define int long long
#define ld long double
#define db double
#define endl "\n"
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()

using namespace __gnu_pbds;
using namespace std;
using namespace chrono;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void deb_out() {
    cout << endl;
}
template <typename Head, typename... Tail>
void deb_out(Head H, Tail... T) {
    cout << " " << H;
    deb_out(T...);
}
#ifdef LOCAL
    #define deb(...) cout << "[" << #__VA_ARGS__ << "]:", deb_out(__VA_ARGS__);
#else
    #define deb(...) ;
#endif

const long double PI = 3.14159265358979323846264338;
const long long INF = 1000000000000000000;
const long long INF1 = 1000000000;
// const long long MOD = 1000000007;
const long long MOD = 998244353;

inline int cl(int a, int b){
    if(a % b)
        return 1 + a / b;
    return a / b;
}

int mpow(int a, int b){
    a %= MOD;
    if(!b)
        return 1;
    int temp = mpow(a, b / 2);
    temp = (temp * temp) % MOD;
    if(b % 2)
        return (a * temp) % MOD;
    return temp;
}
int _pow(int a, int b){
    if(!b)
        return 1;
    int temp = _pow(a, b / 2);
    temp = (temp * temp);
    if(b % 2)
        return (a * temp);
    return temp;
}
inline int mod_in(int n){
    return mpow(n, MOD - 2);
}

const int N = 2e5 + 5;
int fct[N], infct[N];

void pre() {
    fct[0] = 1;
    infct[0] = mod_in(1);
    for (int i = 1 ; i < N ; i++) {
        fct[i] = (i * fct[i - 1]) % MOD;
        infct[i] = mod_in(fct[i]);
    }
}

int nCr(int n, int r) {
    if (n < r)
        return 0;
    int v = (fct[n] * infct[n - r]) % MOD;
    v *= infct[r];
    return v % MOD;
}

int put(int n, int r) {
    if (r < 1)
        return 0;
    return nCr(n + r - 1, r - 1);
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int Tests = 1;
    // cin >> Tests;
    pre();
    while (Tests--) {
        int n, m, k;
        cin >> n >> m >> k;

        int ans = 0;

        ans = 0;
        if (n == 1) {
            ans = mpow(k, m);
            cout << ans;
            exit(0);
        } else if (m == 1) {
            ans = mpow(k, n);
            cout << ans;
            exit(0);
        }
        deb(ans)
        for (int i = 1 ; i <= k ; i++) {
            int lss = mpow(i, n);
            if (i > 1)
                lss -= mpow(i - 1, n);
            lss = (lss + MOD) % MOD;
            // int more = mpow(m, k - i + 1);
            // deb(i, lss, mpow(k - i + 1, m));
            lss *= mpow(k - i + 1, m);
            ans += lss % MOD;
            ans %= MOD;
            // deb(i, ans)
        }

        // int ans = put(n + m, k);
        cout << ans << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define deb(x) cout << #x << "=" << x << endl
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
int M=1e9+7,N=205001;

int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M

int solve(vector<int>& h) {
    int n=h.size(),mx=0;
    if(!n) return 0;
    int nsl[n],nsr[n];
    stack<int> s;
    for(int i=0;i<n;i++){
        while(!s.empty() and h[s.top()]>=h[i]) s.pop();
        nsl[i]=((s.empty())?-1:s.top());
        s.push(i);
    }
    while(!s.empty()) s.pop();
    for(int i=n-1;i>=0;i--){
        while(!s.empty() and h[s.top()]>=h[i]) s.pop();
        nsr[i]=((s.empty())?n:s.top());
        s.push(i);
    }
    for(int i=0;i<n;i++)
        mx=max(mx,h[i]*(nsr[i]-nsl[i]-1));
    return mx;
}

signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	vector<int> h(n);
	rep(i,0,n) cin>>h[i];
	cout<<solve(h);
}


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

typedef long long int lli;

int main() {
	ios::sync_with_stdio(false);
  cin.tie(0);
  int n;string s;
  cin >> n >> s;
  pair<int,int> a[n][n];
  for(int i=0;i<n;i++)
  {
    pair<int,int> temp(0,0);
    if(s[i] == 'A')
      temp.first = 1;
    else if(s[i] == 'T')
      temp.first = -1;
    else if(s[i] == 'C')
      temp.second = 1;
    else
      temp.second = -1;
    a[i][i] = temp;
  }
  lli count = 0;
  for(int len=1;len<n;len++)
  {
    int i=0;
    int j=i+len;
    while(j<n)
    {
      pair<int,int> temp = a[i][j-1];
      if(s[j] == 'A')
        temp.first++;
      else if(s[j] == 'T')
        temp.first--;
      else if(s[j] == 'C')
        temp.second++;
      else
        temp.second--;
      if(temp.first == 0 and temp.second == 0)
        count++;
      a[i][j] = temp;
      i++;
      j = i+len;
    }
  }
  cout << count << "\n";
	return 0;
}

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

int main() {

  int H,W,X,Y;
  cin>>H>>W>>X>>Y;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S.at(i).at(j);
    }
  }

  string temp;
  temp = "#";
  int Z;
  Z=1;//位置するますの分
  //ここから左右を足す

  for (int i = Y-2; i > -1; i--){
    temp = S.at(X-1).at(i);
    if(temp=="."){
      Z++;
    }else{
      break;
    }
  }//左のぶん

  for (int i = Y; i < W; i++){
    temp = S.at(X-1).at(i);
    if(temp=="."){
      Z++;
    }else{
      break;
    }
  }//右のぶん

  for (int i = X-2; i > -1; i--){
    temp = S.at(i).at(Y-1);
    if(temp=="."){
      Z++;
    }else{
      break;
    }
  }//上のぶん

  for (int i = X; i < H; i++){
    temp = S.at(i).at(Y-1);
    if(temp=="."){
      Z++;
    }else{
      break;
    }
  }//したのぶん

  cout<<Z<<endl;

}


//Codeforcesで128bit整数を使いたいとき
//→__int128_tを使う&GNU C++17 (64)で提出する

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;

//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}

int ri() {int n;cin >> n;return n;}
#define ro(a) {cout << a << endl;}

signed main(){
	// int N = ri();
	// vector<string> S(N);
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2]) {
		ro("Won");
	} else {
		ro("Lost")
	}
}

#include<bits/stdc++.h>
using namespace std;
#define endl "\n";
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	ll n;
	cin>>n;
	vector<ll> v1,v2;
	for(ll i=1;i<=sqrt(n);i++){
		if(n%i==0&&n!=i*i)v1.push_back(i),v2.push_back(n/i);
		else if(n==i*i)v1.push_back(i);
	}
	for(int i=0;i<v1.size();i++){
		cout<<v1[i]<<endl;
	}
	for(int i=v2.size()-1;i>=0;i--){
		cout<<v2[i]<<endl;
	}
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

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

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int A, B;
	scanf("%d%d", &A, &B);
	int S = A * (A + 1) / 2 - B * (B + 1) / 2;
	for (int i = 1; i <= A; i++) {
		int x = i;
		if (i == A && S < 0) x -= S;
		printf("%d ", x);
	}
	for (int i = 1; i <= B; i++) {
		int x = -i;
		if (i == B && S > 0) x -= S;
		printf("%d ", x);
	}
	printf("\n");

	return 0;
}


#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (long long i = (s); i < (long long)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n, 0);
    rep(i, n){
        a[i] = i+1;
    }

    ll res = 1;

    rep2(i, 2, 30){
        bool skip=true;
        while(skip){
            skip = false;
            rep(j, n){
                if(a[j]%i==0){
                    skip = true;
                    a[j] /= i;
                }
            }
            if(skip){
                // cout << i << endl;
                res *= i;
            }
        }
    }

    cout << res + 1LL << endl;
    return 0;
}

#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int cnt[100];

int f(int n) {
  int res = 1;
  for(int i = 2; i * i <= n; i++) if(n % i == 0) {
    int c = 0;
    while(n % i == 0) {
      n /= i;
      c++;
      if(c > cnt[i]) {
        cnt[i]++;
        res *= i;
      }
    }
  }
  if(n > 1 && cnt[n] == 0) {
    cnt[n] = 1;
    res *= n;
  }
  return res;
}

int main() {
  int n;
  S(n);
  LL ans = 1;
  rep(i,2,n+1) {
    ans *= f(i);
  }
  cout << ans + 1 << "\n";
  return 0;
}


//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
//FORAは範囲for文(使いにくかったら消す)
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

/*
ビット全探索
for(int bit=0;bit<(1<<n);bit++){
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
            }
        }
*/

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

signed main(){
    //小数の桁数の出力指定
    //cout<<fixed<<setprecision(10);
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    ll n,k;
    cin>>n>>k;
    map<int,int> a;
    rep(i,n){
        int A;
        cin>>A;
        a[A]++;
    }
    int count=k;
    int now=0;
    ll ans=0;
    for(auto itr=a.begin();itr!=a.end();itr++){
        if(now==itr->first){
            count=min(count,itr->second);
            ans+=count;
            now++;
        }
        else break;
    }
    cout<<ans<<endl;
    return 0;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N; cin>>N;
    vec_int a(N), b(N), p(N);
    rep(i,N) cin>>a.at(i);
    rep(i,N) cin>>b.at(i);
    rep(i,N) cin>>p.at(i);

    vector<P> person(N);
    rep(i, N)person.at(i) = make_pair(a.at(i), i);
    sort(person.begin(), person.end());
    // 何をやらないといけないかというと、
    // 体重が軽い人の順番に
    // 自分のIDの荷物を持っている人と荷物を交換する
    //

    map<int, int> assign_map;
    map<int, int> assign_map2;
    rep(i,N){
        assign_map[p.at(i)] = i; // 荷物, 人
        assign_map2[i] = p.at(i); //人, 荷物
    }

    int ans = 0;
    vector<P> ans_vec;
    for(int i=0;i<N;i++){
        int weight, person_ID; tie(weight, person_ID) = person.at(i);
        //cout<<weight<<" "<<person_ID<<" "<<assign_map[person_ID]<<endl;
        if(person_ID == assign_map2[person_ID]-1){
            continue;
        }
        int nimotu = assign_map2[person_ID];
        if(weight <= b.at(nimotu-1) ){
            cout<<-1<<endl;
            return 0;
        }
        int counter_person = assign_map[person_ID+1]; // person_ID+1の荷物を持っている人
        assign_map2[person_ID] = person_ID+1;
        assign_map2[counter_person] = nimotu;
        assign_map[nimotu] = counter_person;
        ans_vec.push_back(make_pair(person_ID+1, counter_person+1));
        ans++;
    }
    cout<<ans<<endl;
    rep(i, ans){
        cout<<ans_vec.at(i).first<<" "<<ans_vec.at(i).second<<endl;
    }

    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;

#define rep(i, l, r) for(int i=(l), i##_end_=(r); i<=i##_end_; ++i)
#define drep(i, l, r) for(int i=(l), i##_end_=(r); i>=i##_end_; --i)
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define Endl putchar('\n')
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T>inline T fab(T x){ return x<0? -x: x; }
template<class T>inline T readin(T x){
    x=0; int f=0; char c;
    while((c=getchar())<'0' || '9'<c) if(c=='-') f=1;
    for(x=(c^48); '0'<=(c=getchar()) && c<='9'; x=(x<<1)+(x<<3)+(c^48));
    return f? -x: x;
}

const int maxn=2e5*2;
const int mod=998244353;

inline int qkpow(int a, int n){
    int ret=1;
    for(; n>0; n>>=1, a=1ll*a*a%mod)
        if(n&1) ret=1ll*ret*a%mod;
    return ret;
}

int n, m;

inline void input(){
    n=readin(1), m=readin(1);
}

int fac[maxn+5], invf[maxn+5];

inline void init(){
    fac[0]=1;
    rep(i, 1, maxn) fac[i]=1ll*fac[i-1]*i%mod;
    invf[maxn]=qkpow(fac[maxn], mod-2);
    drep(i, maxn-1, 0) invf[i]=1ll*(i+1)*invf[i+1]%mod;
    invf[0]=1;
}

inline int C(int n, int m){
    if(m==0) return 1;
    if(n<m) return 0;
    return 1ll*fac[n]*invf[m]%mod*invf[n-m]%mod;
}

signed main(){
    input();
    init();
    int ans=0;
    rep(j, 1, m){
        int tmp=j, res=1;
        for(int i=2; i*i<=tmp; ++i) if(tmp%i==0){
            int cnt=0;
            while(tmp%i==0) tmp/=i, ++cnt;
            res=1ll*res*C(n+cnt-1, cnt)%mod;
        }
        if(tmp>1) res=1ll*res*n%mod;
        ans=(ans+res)%mod;
    }
    printf("%d\n", (ans)%mod);
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=107;
long double E[N][N][N];
int32_t main()
{
	int a,b,c;
	cin>>a>>b>>c;
	// for(int i=0;i<=100;i++)
	// 	for(int j=0;j<=100;j++)
	// 	{
	// 		E[i][j][100]=E[100][i][j]=E[i][100][j]=0;
	// 	}

	for(int i=99;i>=0;i--)
	{
		for(int j=99;j>=0;j--)
		{
			for(int k=99;k>=0;k--)
			{
				if(i+j+k==0)
					continue;
				double ei=E[i+1][j][k]+1;
				ei*=i/(double)(i+j+k);
				double ej = E[i][j+1][k] + 1;
				ej *= j / (double)(i + j + k);
				double ek = E[i][j][k+1] + 1;
				ek *= k/ (double)(i + j + k);
				E[i][j][k]=ei+ej+ek;
				// if(i==a&&b==j&&c==k)
				// 	cout<<ei<<" "<<ej<<" "<<ek<<" "endl;;
			}
		}
	}
	cout <<fixed<< setprecision(6) << E[a][b][c] << endl;
}


#include <bits/stdc++.h>

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

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

struct UnionFind{
	vector<int> par;

	UnionFind(int N){
		par.resize(N,-1);
	}

	int root(int x){
		if(par[x] < 0) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y){
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		if(par[rx] < par[ry]){
			par[rx] += par[ry];
			par[ry] = rx;
		} else {
			par[ry] += par[rx];
			par[rx] = ry;
		}

	}

	bool same(int x, int y){
		return par[x] == par[y];
	}

    int size(int x){
        return (par[x] < 0) ? -par[x] : 0;
    }
};

int main(){
    const ll MOD = 998244353;
    int n,k; cin >> n >> k;
    vector<vector<int>> a(n,vector<int>(n));
    rep(i,n)rep(j,n) cin >> a[i][j];

    ll ans = 1;
    UnionFind uf1(n);
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            bool f = true;
            for(int l = 0; l<n; l++){
                if(a[i][l]+a[j][l] > k) f = false;
            }
            if(f) uf1.unite(i,j);
        }
    }
    for(int i=0; i<n; i++){
        ll t = uf1.size(i);
        while(t > 0){ ans = ans * t % MOD; t--; }
    }

    UnionFind uf2(n);
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            bool f = true;
            for(int l = 0; l<n; l++){
                if(a[l][i]+a[l][j] > k) f = false;
            }
            if(f) uf2.unite(i,j);
        }
    }

    for(int i=0; i<n; i++){
        ll t = uf2.size(i);
        while(t > 0){ ans = ans * t % MOD; t--; }
    }

    cout << ans << endl;

    return 0;
}

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

const long long MOD=998244353;
int N, K;

long long modmypower(long long a, long long b){
  if(b==1){
    return a;
  }else if(b%2==0){
    long long c=modmypower(a,b/2);
    return (c*c)%MOD;
  }else{
    long long c=modmypower(a,(b-1)/2);
    return (((c*c)%MOD)*a)%MOD;
  }
}

long long modfactorial(long long x){
  if(x<=1) x=1;
  else for(int i=x-1; i>0; i--) x=((x*i)%MOD);
  return x;
}

long long modinv(long long x){
  return modmypower(x,MOD-2);
}

long long fn(vector<vector<int>>& mat){
  // 交換できる行のグラフをつくる
  vector<vector<int>> g(N, vector<int>());
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      bool c=true;
      for(int k=0; k<N; k++) if(mat[i][k]+mat[j][k]>K) c=false;
      if(c){
        g[i].push_back(j);
        g[j].push_back(i);
      }
    }
  }

  long long result=1;

  //連結成分ごとに見る
  vector<int> visited(N, 0);
  for(int i=0; i<N; i++){
    //連結成分を抽出
    if(visited[i]==1) continue;
    visited[i]=1;

    queue<int> q;
    q.emplace(i);

    vector<int> group;
    group.push_back(i);

    while(!q.empty()){
      int a=q.front();
      q.pop();
      for(auto dest:g[a]){
        if(visited[dest]==1) continue;
        visited[dest]=1;
        q.emplace(dest);
        group.push_back(dest);
      }
    }

    //ベクトルが一致するかどうか
    int s=group.size();
    vector<int> d(s, 0);
    for(int j=0; j<s; j++){
      for(int k=0; k<s; k++){
        if(mat[j]==mat[k]) d[j]++;
      }
    }

    map<int, int> dlist;
    for(int j=0; j<s; j++) dlist[d[j]]++;

    long long tmp=modfactorial(s);
    for(auto kv: dlist){
      int k=kv.first;
      int v=kv.second/k;
      if(k==1) continue;
      tmp=(tmp*modinv(modfactorial(v)))%MOD;
    }

    result=(result*tmp)%MOD;
  }

  return result;
}

int main(){
  cin >> N >> K;
  vector<vector<int>> A(N, vector<int>(N));
  for(int i=0; i<N*N; i++) cin >> A[i/N][i%N];

  long long result=fn(A);

  vector<vector<int>> B(N, vector<int>(N));
  for(int i=0; i<N*N; i++) B[i/N][i%N]=A[i%N][i/N];
  result*=fn(B);

  cout << result%MOD << endl;
}


#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<str> vs;
typedef vector<ld> vd;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

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

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 1e6 + 10;
const int nx[8] = {0, 0, 1, -1, -1, 1, 1, -1}, ny[8] = {1, -1, 0, 0, 1, -1, 1, -1}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

ll random(ll a, ll b){
    return a + rng() % (b - a + 1);
}

#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

//Geometry
typedef long long C;
typedef complex<C> P;
#define X real()
#define Y imag()
#define pi 3.14159265359

int main()
{
    boost;
    IO();

    ll n;
    cin >> n;
    cout << n-1 << endl;

    return 0;
}

#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
cout<<n-1;
}


#include<bits/stdc++.h>
#include<unordered_map>
#define sz(s) (int)s.size()
#define all(s) s.begin(),s.end()
using namespace std;
typedef long long ll;
void fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}
bool valid(ll n, string s)
{
	if (!n)
		return 0;
	int c = 0;
	while (n)
	{
		c++;
		n /= 10;
	}
	return c == sz(s);
}
void Men7a()
{
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	set<char>st;
	for (int i = 0; i < sz(s1); i++)
		st.insert(s1[i]);
	for (int i = 0; i < sz(s2); i++)
		st.insert(s2[i]);
	for (int i = 0; i < sz(s3); i++)
		st.insert(s3[i]);
	if (sz(st)>10)
	{
		cout << "UNSOLVABLE\n";
		return;
	}
	unordered_map<char, int>mp;
	vector<int>v = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	do
	{
		for (auto x : st)
			mp[x] = -1;
		int ix = 0;
		for (auto x : st)
				mp[x] = v[ix++];
		ll a = 0, b = 0, c = 0;
		for (int i = 0; i < sz(s1); i++)
		{
			a *= 10;
			a += mp[s1[i]];
		}
		for (int i = 0; i < sz(s2); i++)
		{
			b *= 10;
			b += mp[s2[i]];
		}
		for (int i = 0; i < sz(s3); i++)
		{
			c *= 10;
			c += mp[s3[i]];
		}
		if (a + b == c && valid(a, s1) && valid(b, s2) && valid(c, s3))
		{
			cout << a << "\n" << b << "\n" << c << "\n";
			return;
		}
	} while (next_permutation(all(v)));
	cout << "UNSOLVABLE\n";
}
int main()
{
	fast();
	int test_case = 1;
	//freopen("","r",stdin);
	//cin >> test_case;
	while (test_case--)
		Men7a();
}

// D - Send More Money
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define vec vector
#define rep(i,e) for(int i=0;i<(e);++i)
#define sz(a) int(a.size())

ll INF = 1e18;
string in(){ string s; cin>>s; return s; }
vec<int> reversed(vec<int> s){ reverse(s.begin(), s.end()); return s; }

int main(){
	vec<vec<int>> S(3);
	vec<ll> A(26, INF), sign{1, 1, -1};
	set<int> C;
	rep(i, 3){
		for(auto&c:in()) S[i].push_back(c-'a');
		int w = 1;
		for(auto&c:reversed(S[i])){
			if(A[c] == INF) A[c] = 0;
			A[c] += sign[i] * w;
			C.insert(c);
			w *= 10;
		}
	}

	if(sz(C) > 10){ puts("UNSOLVABLE"); return 0; }

	vec<int> P(10); iota(P.begin(), P.end(), 0);
	do{
		ll tot = 0;
		auto pos_p = P.begin();
		rep(c, sz(A)){
			if(A[c] == INF) continue;
			if(*pos_p == 0)
				for(auto&s:S) if(s[0] == c){ tot = INF; break; }
			tot += *pos_p * A[c];
			pos_p++;
		}
		if(tot) continue;

		pos_p = P.begin();
		rep(c, sz(A)) if(A[c] != INF) A[c] = *pos_p++;
		for(auto&s:S){
			ll ans = 0;
			for(auto&c:s) ans = ans*10 + A[c];
			cout<< ans <<endl;
		}
		return 0;
	}while(next_permutation(P.begin(), P.end()));

	puts("UNSOLVABLE");
}


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

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

  ll n,x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll dp[2];
  dp[0] = 1;
  dp[1] = 0;
  ll tx = x;
  rep(i,n-1){
    ll amari = tx%a[i];//前の＋
    ll amari_minus = amari - a[i];//前の-

    ll amari_now = tx%a[i+1];
    ll amari_now_minus = amari_now - a[i+1];
    // cout << amari <<" " << amari_minus << " " << amari_now << " " << amari_now_minus << endl;
    ll ndp[2];
    if(abs(amari-amari_now)<=a[i+1]-a[i]){
      //dp[0]そのまま
      ndp[0] = dp[0];
    }
    else{
      ndp[0] = 0;
    }
    if(abs(amari_minus-amari_now_minus)<=a[i+1]-a[i]){
      ndp[1] = dp[1];
    }
    else ndp[1] = 0;
    if(abs(amari_minus-amari_now)<=a[i+1]-a[i]) ndp[0] += dp[1];
    if(abs(amari-amari_now_minus)<=a[i+1]-a[i]) ndp[1] += dp[0];
    dp[0]= ndp[0];
    dp[1]= ndp[1];
    // cout << dp[0] <<" " << dp[1] << endl;
  }
  cout << dp[0] + dp[1] << endl;

  return 0;

}

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

using namespace std;
using namespace __gnu_pbds;

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

#define int long long
#define ll long long
#define all(v) v.begin(), v.end()
#define intvect vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define fo(i, n) for (int i = 0; i < n; ++i)
#define Fo(i, k, n) for (int i = k; i < n; ++i)
#define ld long double
#define deb(x) cout << #x << " " << x << endl;
#define pb push_back
#define pob pop_back
#define lcm(a, b) (a / __gcd(a, b) * b)
#define F first
#define S second
#define ull unsigned long long

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

const ll mod = 1e9 + 7;
const ll N = (ll)5e6 + 5;

template <typename... T>
void read(T &... args)
{
    ((cin >> args), ...);
}

template <typename... T>
void write(T &&... args)
{
    ((cout << args), ...);
}

void vjudge()
{
#ifndef RTE
    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool iss(int n)
{
    int u = sqrt(n);
    if (u * u == n)
        return 1;
    return 0;
}
void solve()
{
    int u, v;
    cin >> u >> v;

    for (int i = 1; i < sqrt(v) + 1; i++)
    {
        if (i + v / i == u)
        {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}
int32_t main()
{
    clock_t start, end;
    start = clock();
    vjudge();
    int t = 1;
    // read(t);
    while (t--)
        solve();
    end = clock();
    double waste = double(end - start) / double(CLOCKS_PER_SEC);
    cerr << "Time wasted by program is : " << fixed
         << waste << setprecision(15);
    cerr << " sec " << endl;
}


#include <iostream>

using namespace std;
using LL = long long;

const int kMaxN = 21;

int n, m, p, q[kMaxN], k[kMaxN];
bool v[kMaxN], e[kMaxN][kMaxN];
LL c = 1, _c;

void F(int x) {
  if (!v[x]) {
    v[x] = 1, q[++p] = x;
    for (int i = 1; i <= n; ++i) {
      if (e[x][i]) {
        F(i);
      }
    }
  }
}

void D(int x) {
  if (x > p) {
    ++_c;
    return;
  }
  bool b[4] = {0, 0, 0, 0};
  for (int i = 1; i < x; ++i) {
    if (e[q[x]][q[i]]) {
      b[k[q[i]]] = 1;
    }
  }
  for (int i = 1; i <= 3; ++i) {
    if (!b[i]) {
      k[q[x]] = i;
      D(x + 1);
    }
  }
}

int main() {
  cin >> n >> m;
  for (int i = 1, x, y; i <= m; ++i) {
    cin >> x >> y;
    e[x][y] = e[y][x] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    if (!v[i]) {
      _c = p = 0, F(i), D(1), c *= _c;
    }
  }
  cout << c << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
//const int mod = 998244353;

vector<vector<int>> to;
vector<int> used, col, vs;
ll now;

void dfs(int v){
    used[v] = 1;
    vs.push_back(v);
    for(int u : to[v]){
        if(used[u]) continue;
        dfs(u);
    }
}

void dfs2(int i){
    if(i == vs.size()){
        now++;
        return;
    }
    int v = vs[i];
    rep(c, 0, 3){
        col[v] = c;
        bool flag = 0;
        for(int u : to[v]){
            if(col[u] == c){
                flag = 1;
            }
        }
        if(flag) continue;
        dfs2(i+1);
    }
    col[v] = -1;
}

int main()
{
    int n, m;
    cin >> n >> m;
    to = vector<vector<int>> (n);
    used = vector<int> (n);
    col = vector<int> (n, -1);
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ll ans = 1;
    rep(v, 0, n){
        if(used[v]) continue;
        vs = vector<int> ();
        dfs(v);
        col[vs[0]] = 0;
        now = 0;
        dfs2(1);
        ans *= 3*now;
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <stack>
#include<algorithm>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
	long long N, K;
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		if (N % 200 == 0) {
			N /= 200;
		}
		else {
			N = N * 1000 + 200;
		}
	}
	cout << N;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define F first
#define S second
#define YES(n)cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
int main(){
    int n,m;
    cin>>n>>m;
    set<int> a;
    set<int> b;
    int maxint=0;
    rep(i,n){
        int aa;
        cin>>aa;
        maxint=max(maxint,aa);
        a.insert(aa);
    }
    rep(i,m){
        int bb;
        cin>>bb;
        maxint=max(maxint,bb);
        b.insert(bb);
    }
    for(int i=1;i<=maxint;i++){
        if(a.count(i)^b.count(i))cout<<i<<" ";
    }
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){

  int H, W, X, Y;
  cin >> H >> W >> X >> Y;
  X -= 1; Y -= 1;

  vector<vector<bool>> S(H, vector<bool>(W));
  string S_0;
  for (int i=0; i<H; i++){
    cin >> S_0;
    for (int j=0; j<W; j++){
      if(S_0[j] == '#')
        S.at(i).at(j) = false;
      else
        S.at(i).at(j) = true;
    }
  }

  // result
  int result = 1;	// <- + (X, Y)'s score

  // up
  for (int i=X-1; i>=0; i--){
    if (S.at(i).at(Y) == 0)
        break;
    result += S.at(i).at(Y);
  }

  // down
  for (int i=X+1; i<H; i++){
    if (S.at(i).at(Y) == 0)
        break;
    result += S.at(i).at(Y);
  }

  // left
  for (int j=Y-1; j>=0; j--){
    if (S.at(X).at(j) == 0)
        break;
    result += S.at(X).at(j);
  }

  // right
  for (int j=Y+1; j<W; j++){
    if (S.at(X).at(j) == 0)
        break;
    result += S.at(X).at(j);
  }

  // result
  cout << result << endl;

  return 0;
}

    #include <bits/stdc++.h>
    int ri() {
    	int n;
    	scanf("%d", &n);
    	return n;
    }
    int main() {
    	int h = ri();
    	int w = ri();
    	int x = ri() - 1;
    	int y = ri() - 1;
    	std::string s[h];
    	for (auto &i : s) std::cin >> i;

    	int cnt = -3;
    	for (int i = x; i < h && s[i][y] != '#'; i++) cnt++;
    	for (int i = x; i >= 0 && s[i][y] != '#'; i--) cnt++;
    	for (int j = y; j < w && s[x][j] != '#'; j++) cnt++;
    	for (int j = y; j >= 0 && s[x][j] != '#'; j--) cnt++;
    	printf("%d\n", cnt);
    	return 0;
    }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){

    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;cin>>N;
    vector<ll> A(N),B(N);
    for(int i=0;i<N;i++) cin>>A[i];
    for(int i=0;i<N;i++) cin>>B[i];

    ll ans=0;

    ll ma=0;

    for(int i=0;i<N;i++){
        chmax(ma,A[i]);
        chmax(ans,ma*B[i]);
        cout<<ans<<"\n";
    }
}

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

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n + 1);
	a[0] = 0;
	vector<ll> b(n + 1);
	REP(i, n)
	{
		ll tmp;
		cin >> tmp;
		a[i + 1] = max(tmp, a[i]);
	}
	b[0] = 0;
	REP(i, n)
	{
		cin >> b[i + 1];
	}
	ll ans = 0;
	FOR(i, 1, n + 1)
	{
		ans = max(ans, a[i] * b[i]);
		cout << ans << endl;
	}
	return (0);
}


#include <bits/stdc++.h>
#define f(a, n) for (int a = 0; a < n; a++)
#define F(a, n) for (int a = 1; a <= n; a++)
using namespace std;

struct Student{
	map<int, int> mp;
	int sz = 1;
	Student* par = this;
};

Student* find(Student* a){
	if (a->par == a) return a;
	return a->par = find(a->par);
}

void join(Student* a, Student* b){ // b joins a
	a->sz += b->sz;
	b->par = a;
	for (auto p: b->mp){
		int x = p.first, y = p.second;
		a->mp[x] += y;
	}
}

int main(){
	int n, q;
	cin >> n >> q;
	Student A[200005];
	F(i, n) {
		int x;
		cin>>x;
		A[i].mp[x]++;
	}
	F(asdf, q){
		int a, b, c;
		cin >> a >> b >> c;
		if (a == 1){
			auto d = find(&A[b]);
			auto e = find(&A[c]);
			if (d != e){
				if (d->sz >= e->sz){
					join(d, e);
				} else{
					join(e, d);
				}
			}
		} else{
			cout<<find(&A[b])->mp[c]<<endl;
		}
	}
}

#include <bits/stdc++.h>

#define DEBUG(C) cerr << #C << " = " << C << endl;

using namespace std;
const int MOD = 1e9 + 7;

// UnionFind,素集合データ構造,DisjointSet

template<typename weight_type = int>
class union_find {
    static_assert(
            std::is_arithmetic<weight_type>::value,
            "Invalid weight type");
private:
    const std::function<void(int, int)> noop = [](int aa, int bb){};

    std::vector<int> uni;
    std::vector<int> edge_count_;
    std::vector<weight_type> weights;
    int size_;
    const void check(const int n) const {
        if (this->group_size() < 0) {
            assert(false);
        }
        if (!(0 <= n && n < this->all_size())) {
            assert(false);
        }
    }
public:
    union_find() : uni(0), edge_count_(0), weights(0), size_(-1) {}
    union_find(const int n)
            : uni(n, -1), edge_count_(n), weights(n), size_(n) {
        this->check(n - 1);
    }
    union_find(const std::vector<weight_type> &_weights)
            : uni(_weights.size(), -1), edge_count_(_weights.size()),
              weights(_weights), size_(_weights.size()) {
        this->check((int)_weights.size() - 1);
    }
    bool same(const int a, const int b) {
        this->check(a);
        this->check(b);
        return this->find(a) == this->find(b);
    }
    int find(const int a) {
        this->check(a);
        return this->uni[a] < 0 ?
               a :
                this->uni[a] = this->find(this->uni[a]);
    }
    bool unite(int a, int b) {
        return unite(a, b, noop);
    }
    bool unite(int a, int b, const std::function<void(int, int)> &f) {
        a = this->find(a);
        b = this->find(b);
        this->edge_count_[a]++;
        if (a == b) {
            return false;
        }
        this->size_--;
        if (this->uni[a] > this->uni[b]) {
            std::swap(a, b);
        }
        f(a, b);
        this->uni[a] += this->uni[b];
        this->weights[a] += this->weights[b];
        this->edge_count_[a] += this->edge_count_[b];
        this->uni[b] = a;
        return true;
    }
    const int group_size() const {
        return this->size_;
    }
    const int all_size() const {
        return this->uni.size();
    }
    const int size(const int a) {
        this->check(a);
        return -this->uni[this->find(a)];
    }
    const int edge_count(const int a) {
        this->check(a);
        return this->edge_count_[this->find(a)];
    }
    const weight_type weight(const int a) {
        this->check(a);
        return this->weights[this->find(a)];
    }
};

const int MAX = 2e5 + 10;
int N, Q;
int C[MAX];
map<int, map<int, int>> mp;

void solve() {
    cin >> N >> Q;
    union_find<> uf(N);
    for (int i = 0; i < N; ++i) {
        cin >> C[i];
        C[i]--;
        mp[i][C[i]] = 1;
    }

    for (int i = 0; i < Q; i++) {
        int mode;
        cin >> mode;
        if (mode == 1) {
            int a, b;
            cin >> a >> b;
            a--;
            b--;

            uf.unite(a, b, [&](int nxt_par, int bye) {
                for (auto [k, v] : mp[bye]) {
                    mp[nxt_par][k] += v;
                }
                mp.erase(bye);
            });

        } else {
            int x, y;
            cin >> x >> y;
            x--;
            y--;
            x = uf.find(x);
            const auto ans = mp[x].count(y) ? mp[x][y] : 0;
            cout << ans << endl;
        }
    }
}

int main(void) {
#ifndef ONLINE_JUDGE
    const auto in_stream = freopen("../in.txt", "r", stdin);
    if (in_stream == nullptr) {
        cerr << "ERROR!" << endl;
        return 1;
    }
#endif

    solve();

#ifndef ONLINE_JUDGE
    fclose(in_stream);
#endif
}


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

const long long INF = 1e9;
int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            cin >> a[i][j];
        }
    }

    vector<vector<int>> dp(h, vector<int>(w));
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            dp[i][j] = ((i + j) % 2 == 1 ? INF : -INF);
        }
    }

    dp[h - 1][w - 1] = 0;
    for(int i = h - 1;i >= 0;i--){
        for(int j = w - 1;j >= 0;j--){
            int v = (a[i][j] == '+' ? 1 : -1);
            if ((i + j) % 2 == 0){
                if (i - 1 >= 0) {
                    dp[i - 1][j] = min(dp[i - 1][j], dp[i][j] - v);
                }
                if (j - 1 >= 0){
                    dp[i][j - 1] = min(dp[i][j - 1], dp[i][j] - v);
                }
            } else {
                if (i - 1 >= 0){
                    dp[i - 1][j] = max(dp[i - 1][j], dp[i][j] + v);
                }
                if (j - 1 >= 0){
                    dp[i][j - 1] = max(dp[i][j - 1], dp[i][j] + v);
                }
            }
        }
    }

    if (dp[0][0] > 0) cout << "Takahashi" << endl;
    else if (dp[0][0] == 0) cout << "Draw" << endl;
    else cout << "Aoki" << endl;
}

#include<ctime>
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
const int N=2e3+7;
int read() {
	char c;
	int x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while (isdigit(c)){
		x=x*10+(c-48)*f;
		c=getchar();
	}
	return x;
}
char c[N][N];
int h,w,f[N][N];
int main() {
	#ifndef ONLINE_JUDGE
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	h=read();
	w=read();
	for(int i=1;i<=h;++i)
		scanf("%s",c[i]+1);
	for(int i=w-1;i;--i){
		int fl=1-2*((h+i)&1);
		if(c[h][i+1]=='+')
			f[h][i]=f[h][i+1]+fl;
		else
			f[h][i]=f[h][i+1]-fl;
	}
	for(int i=h-1;i;--i){
		int fl=1-2*((w+i)&1);
		if(c[i+1][w]=='+')
			f[i][w]=f[i+1][w]+fl;
		else
			f[i][w]=f[i+1][w]-fl;
	}
	for(int i=h-1;i;--i)
	for(int j=w-1;j;--j){
		if((i+j)&1){
			int fa=1-2*(c[i][j+1]=='+');
			int fb=1-2*(c[i+1][j]=='+');
			f[i][j]=min(f[i][j+1]+fa,f[i+1][j]+fb);
		}
		else{
			int fa=1-2*(c[i][j+1]=='-');
			int fb=1-2*(c[i+1][j]=='-');
			f[i][j]=max(f[i][j+1]+fa,f[i+1][j]+fb);
		}
	}
	if(f[1][1]>0)
		puts("Takahashi");
	else if(f[1][1]<0)
		puts("Aoki");
	else
		puts("Draw");
	//--------
	clock_t t2=clock();
	fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
	return 0;
}