#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
constexpr int INF = 1001001000;

int main() {
    int n, k;
    cin >> n >> k;
    mat t(n, vec(n));
    rep(i, n) rep(j, n) cin >> t[i][j];

    int res = 0;

    vec a(n);
    rep(i, n) a[i] = i;
    a.push_back(0);

    do {
        int sum = 0;

        rep(i, n) {
            sum += t[a[i+1]][a[i]];
        }

        if (sum == k) res++;
    } while (next_permutation(a.begin() + 1, a.end() - 1));

    cout << res << endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long int ll;
typedef pair<ll,ll> pll;

#define MOD 1000000007
bool visited[10];
ll cities[10][10];
ll n,k,ret = 0;

void go(int c,ll total,int visCount)
{
    if(visCount >= n-1)
    {
        if(total+cities[c][0] == k)
            ret++;
        return;
    }
    visited[c] = true;
    for(int i = 0;i < n;i++)
    {
        if(!visited[i])
        {
            if(total+cities[c][i] < k)
                go(i,total+cities[c][i],visCount+1);
        }
    }
    visited[c] = false;
}

void solve(){
    cin >> n >> k;
    for(int i = 0;i < n;i++)
        for(int j = 0;j < n;j++)
        {
            cin >> cities[i][j];
        }

    go(0,0,0);

    cout << ret;
}
int main(){
#ifdef DEBUG
    freopen("i.txt","r",stdin);
    freopen("o.txt","w",stdout);
#endif
    cin.tie(0);
    ios::sync_with_stdio(0);

	int q;
	//cin >> q;
    q = 1;
	while(q--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#define loop(i,a,b) for (int i = (a); i <= (b); i++)
#define loopr(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define mod 1000000007
#define mod1 998244353
using namespace std;

int maxSubArraySum(int a[], int size)
{
    int max_so_far = INT_MIN, max_ending_here = 0;

    for (int i = 0; i < size; i++)
    {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;

        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}

int main()
{
	ll n,x;
	cin>>n>>x;
	vector<int> a(n),ans;
	loop(i,0,n-1)
	{
		cin>>a[i];
		if(a[i]!=x)
		{
			ans.push_back(a[i]);
		}
	}
	for(auto x : ans)
	{
		cout<<x<<" ";
	}
}

#include <bits/stdc++.h>
#include <random>
#include <time.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const int Nmax=2e5+1;
const int Nd=61;
const int INF=1e5;

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  ll ans=0;
  rep(i,h){
    cin>>s[i];
    //まずは横に並べる方法を考える
    rep(j,w-1){
      if(s[i][j]=='.' && s[i][j+1]=='.'){
        ans++;
      }
    }
  }

  //縦にしく場合
  rep(j,w){
    rep(i,h-1){
      if(s[i][j]=='.' && s[i+1][j]=='.'){
        ans++;
      }
    }

  }
  cout<<ans<<endl;

  return 0;

}


#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a; i >-1; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a; i > b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;

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

//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
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;
}

ll mypow(ll x, ll n, const ll &p = -1)
{ //x^nをmodで割った余り

	if (p != -1)
	{
		x =(x%p+p)%p;
	}
	ll ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
//using namespace atcoder;

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

	vector<ll>S(n*3+1);
	S[0]=1;
	S[n]=-3;
	S[n*2]=3;
	S[n*3]=-1;
	rep(i,3){
		rep(j,n*3){
			S[j+1]+=S[j];
		}
	}
	for(ll sum=3;sum<=n*3;++sum){

		ll val=S[sum-3];
		if(k-val<=0){
			//和がsum
			for(ll i=1;i<=n;++i){
				ll sub=max<ll>(0,min(n,sum-i-1)-max(1LL,sum-i-n)+1);
				if(k-sub<=0){
					//1個目がi,残りの和はsum-i
					for(ll j=max<ll>(1,sum-i-n);j<=n;++j){
						--k;
						if(!k){
							cout<<i<<" "<<j<<" "<<sum-i-j<<"\n";
							return;
						}
					}
				}
				k-=sub;
			}
		}
		k-=val;
	}
}

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

#include <bits/stdc++.h>
#define M 1000000007
#define pii 3.14159265359
#define pb push_back
#define pob pop_back
#define forr(i,n) for(i=0;i<n;i++)
#define fors(i,j,n) for(i=j;i<n;i++)
#define pi pair<int,int>
#define ff first
#define ss second
#define tcase 0
#define all(v) v.begin(),v.end()
typedef long long int ll;
using namespace std;
#define sc(n) scanf("%lld",&n)
#define scn(n) scanf("%d",&n)
#define prt(n) printf("%lld ",n)
#define prtln(n) printf("%lld\n",n)

vector<pi> edges;
vector<vector<int>> v;
vector<int> prt;
vector<ll> val;
vector<ll> ans;

void assign_prt(int node,int p) {
	prt[node] = p;
	for(auto x : v[node]) {
		if(x==prt[node]) continue;
		assign_prt(x,node);
	}
}

void find_ans(int node,int p,ll c) {
	ans[node] += c + val[node];
	for(auto x : v[node]) {
		if(x==prt[node]) continue;
		find_ans(x,node,c+val[node]);
	}
}

void solve() {
    int n,i;
    scn(n);

    v.clear(); edges.clear(); prt.clear(); val.clear(); ans.clear();
    v.resize(n+1); prt.resize(n+1); val.resize(n+1,0ll);
    forr(i,n-1) {
    	int a,b;
    	scn(a); scn(b);
    	edges.pb({a,b});
    	v[a].pb(b); v[b].pb(a);
    }

    assign_prt(1,-1);

    int q;
    scn(q);

    forr(i,q) {
    	int a,b; ll value;
    	scn(a); scn(b); sc(value);

 		int v1,v2;
    	if(a==1) {
    		v1 = edges[b-1].ff;
    		v2 = edges[b-1].ss;
    	}
    	else {
    		v1 = edges[b-1].ss;
    		v2 = edges[b-1].ff;
    	}

    	if(v2==prt[v1]) {
    		val[v1] += value;
    	}
    	else {
    		val[1] += value;
    		val[v2] += -value;
    	}
    }

    ans.resize(n+1,0ll);
    find_ans(1,-1,0);

    fors(i,1,n+1) prtln(ans[i]);
}

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

    int t = 1;
    if(tcase) scn(t);
    while(t--) solve();
    return 0;
}


/*
    飲んだ魔剤で家が建つ。
    created at: 2020-12-11 15:15:32
*/

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

map<vector<int>, long double> memo;

long double cnt (int a, int b, int c)
{
    long double x, y, z;
    x = y = z = 0.0l;

    if (a < 100 && b < 100 && c < 100) {
        vector<int> p, q, r;
        p = {a+1, b, c};
        q = {a, b+1, c};
        r = {a, b, c+1};

        if (memo[p] <= 0.0l) memo[p] = cnt(a+1, b, c);
        if (memo[q] <= 0.0l) memo[q] = cnt(a, b+1, c);
        if (memo[r] <= 0.0l) memo[r] = cnt(a, b, c+1);

        x = (1.0l + memo[p]) * a / (a + b + c);
        y = (1.0l + memo[q]) * b / (a + b + c);
        z = (1.0l + memo[r]) * c / (a + b + c);
    }

    return (x + y + z);
}

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    cout << setprecision(15) << cnt(a, b, c) << endl;

    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
#define rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
#define repr(i, n, s) for (int i = (int)n; (int)s < i; i--)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()
/* 1次元ベクトルをスペースでつなぎ、改行をつけて出力 vi, vl, list<int>, list<ll>に対応  */
template<class T> void print_elements(T a) {string str = ""; for (auto itr = a.begin(); itr != a.end(); ++itr) \
        str += to_string(*itr) + ' '; str.pop_back(); cout << str << endl;}

const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
const double PI = acos(-1);

vector<vector<vector<double>>> dp(101, vector<vector<double>>(101, vector<double>(101, 0)));

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    vector<vector<vector<double>>> dp(101, vector<vector<double>>(101, vector<double>(101, 0)));

    dp[a][b][c] = 1.0;

    rep(i, a, 101) {
        rep(j, b, 101) {
            rep(k, c, 101) {
                if (i < 100 && j < 100 && k < 100) {
                    dp[i+1][j][k] += dp[i][j][k] * i / (i + j + k);
                }
                if (j < 100 && k < 100 && i < 100) {
                    dp[i][j+1][k] += dp[i][j][k] * j / (i + j + k);
                }
                if (k < 100 && i < 100 && j < 100) {
                    dp[i][j][k+1] += dp[i][j][k] * k / (i + j + k);
                }
            }
        }
    }
    double ans = 0;
    rep(i, a, 100) {
        rep(j, b, 100) {
            int k = 100;
            ans += -((a - i) + (b - j) + (c - k)) * dp[i][j][k];
        }
    }
    rep(j, b, 100) {
        rep(k, c, 100) {
            int i = 100;
            ans += -((a - i) + (b - j) + (c - k)) * dp[i][j][k];
        }
    }
    rep(i, a, 100) {
        rep(k, c, 100) {
            int j = 100;
            ans += -((a - i) + (b - j) + (c - k)) * dp[i][j][k];
        }
    }
    cout << fixed << setprecision(9) <<  ans << endl;
}


#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");}
#define fi first
#define se second

const int MOD = 1e9+7;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll k;
	scanf("%ld", &k);

	ll ans = 0;
	REP(i, 1, k+1){
		for(ll j=1; j*i<=k; j++){
			ans += k / (i*j);
		}
	}
	printf("%ld\n", ans);
	return 0;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<tuple<int,int,int>> v;
    for(int i=0;i<n;i++)
    {
        int p,q,r;
        cin>>p>>q>>r;
        v.push_back({q,r,p});
    }
    int c=0;
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(get<1>(v[i])>get<0>(v[j]))
            {
                c++;
                //                cout<<get<1>(v[i])<<" "<<get<0>(v[j])<<'\n';
                continue;
            }
            if(get<1>(v[i])==get<0>(v[j])&&(get<2>(v[i])==1||get<2>(v[i])==3)&&(get<2>(v[j])==2||get<2>(v[j])==1))
            {
                //cout<<get<1>(v[i])<<" "<<get<0>(v[j])<<'\n';
                c++;
            }
        }
    }
    cout<<c<<'\n';
}


#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <tuple>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <random>
#include <chrono>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    int N;
    scanf("%d", &N);
    vector<int> A(N, 0);
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    vector<LL> psum(N, 0);
    for (int i = 0; i < N; i++) {
        if (i) psum[i] = psum[i - 1];
        int offs = 1;
        if (i % 2) offs = -1;
        psum[i] += offs * A[i];
    }
    map<LL, int> cnt;
    cnt[0] = 1;
    LL ans = 0;
    for (int i = 0; i < N; i++) {
        LL cur = psum[i];
        ans += cnt[cur];
        cnt[cur]++;
    }
    printf("%lld\n", ans);

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

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int m;
    cin >> m;
    vector<pair<int, int>> edges(m);
    int n = 0;
    for (auto& edge: edges) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        edge = {u, v};
        n = max(n, u + 1);
        n = max(n, v + 1);
    }
    vector<vector<int>> adj_list(n);
    for (auto& edge : edges) {
        int u, v;
        tie(u, v) = edge;
        adj_list[u].push_back(v);
        adj_list[v].push_back(u);
    }
    vector<bool> visited(n, false);
    function<pair<int, int> (int)> dfs = [&](int u) {
        if (visited[u]) {
            return make_pair(0, 0);
        }
        visited[u] = true;
        int nodes_seen = 1, edges_seen = 0;
        for (int v : adj_list[u]) {
            int n0, e0;
            tie(n0, e0) = dfs(v);
            nodes_seen += n0;
            edges_seen += e0 + 1;
        }
        return make_pair(nodes_seen, edges_seen);
    };
    int answer = 0;
    for (int u = 0; u < n; ++u) {
        int nodes_seen, edges_seen;
        tie(nodes_seen, edges_seen) = dfs(u);
        assert (edges_seen % 2 == 0);
        edges_seen /= 2;
        answer += min(nodes_seen, edges_seen);
    }
    cout << answer << "\n";
}

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


#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<int>> mod(1 << 8);
    for (int i = 1; i < (1 << min(8, n)); i++) {
        int sum = 0;
        bitset<8> bit(i);
        for (int j = 0; j < 8; j++) {
            if (bit[j]) {
                sum = (sum + a[j]) % 200;
            }
        }
        mod[sum].push_back(i);
    }
    auto print_ans = [](int x) {
        bitset<8> bit(x);
        cout << bit.count() << ' ';
        for (int i = 0; i < 8; i++) {
            if (bit[i]) {
                cout << i + 1 << ' ';
            }
        }
        cout << "\n";
    };
    for (auto vec : mod) {
        if (vec.size() >= 2) {
            cout << "Yes" << "\n";
            print_ans(vec[0]), print_ans(vec[1]);
            return 0;
        }
    }
    cout << "No" << "\n";
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

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

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

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

typedef pair<ll, int> P;

struct Graph {

    struct Edge {
        int u, v;
        ll w;
        Edge() {}
        Edge(int u, int v, ll w) : u(u), v(v), w(w) {}
        friend ostream& operator<<(ostream& os, const Edge& e) {cout << "(" << e.u << "->" << e.v << "," << e.w << ")"; return os;}
    };

    int n;

    vector<vector<Edge>> edges;
    Graph(int n): n(n), edges(n) {}

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

    ll dijkstra(int s, int t){

        priority_queue<P, vector<P>, greater<P> > pq;
        pq.push(P(0, s));

        vector<ll> dist(n, INF);
        dist[s] = 0;

        while (!pq.empty()){
            P p = pq.top(); pq.pop();

            ll cost = p.first;
            int u = p.second;

            if (u == t) {
                return cost;
            }

            for (auto edge: edges[u]){

                ll ncost = cost + edge.w;

                if (ncost < dist[edge.v]){
                    dist[edge.v] = ncost;
                    pq.emplace(ncost, edge.v);
                }
            }
        }
        return INF;
    }
};

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

    int N, M;
    cin >> N >> M;
    Graph g(N);
    REP(i, M){
        int a, b; cin >> a >> b;
        a--; b--;
        g.add_edge(a, b, 1);
    }

    int K;
    cin >> K;
    vector<int> C(K);
    REP(i, K) {cin >> C[i]; C[i]--; }

    vector<vector<ll>> dist(K, vector<ll>(K, 0));
    REP(i, K) REPN(j, i+1, K){
        dist[i][j] = g.dijkstra(C[i], C[j]);
        dist[j][i] = dist[i][j];
    }

//    REP(i, K) print(dist[i]);

    vector<vector<ll>> dp(1 << K, vector<ll>(K, INF));
    REP(i, K) dp[1 << i][i] = 1;

    REP(p, 1 << K) {
        REP(i, K) REP(j, K) {
            if (i == j) continue;
            if ((p >> j) & 1) continue;

            int q = p | (1 << j);
            dp[q][j] = min(dp[q][j], dp[p][i] + dist[i][j]);
        }
    }

    ll ans = INF;
    REP(i, K){
        ans = min(ans, dp[(1<<K)-1][i]);
    }

    print(ans == INF ? -1 : ans);

    return 0;
}


//https://oeis.org/search?q=0%2C0%2C1%2C2%2C4%2C6&language=english&go=Search
//https://smallpdf.com/result#r=dc43c99933feaa1c7f3a2f2e2036bc6a&t=pdf-to-word
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <string.h>
using namespace std;
#define ll long long
#define INF 1000007
#define MAX 500007
#define nl "\n"
#define F first
#define S second
typedef vector<ll> vi;
typedef priority_queue<ll , vector<ll> , greater<ll> > pqmx;
typedef priority_queue<ll> pqmn;
typedef pair<ll , ll> pi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector< pair<int , int> > vpi;
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define yeS(GOOD)      GOOD ? cout<<"YES\n" : cout<<"NO\n"
#define all(a) a.begin() , a.end()
#define pb push_back
#define ar array
ll mod = LLONG_MAX;
ll binpow(ll a, ll b){ll res=1;a%=mod;while(b>0){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
ll binmul(ll a, ll b){ll res=0;a%=mod;while(b>0){if(b&1)res=(res + a)%mod;a=(a + a)%mod;b>>=1;}return res;}
ll area(pi a, pi b,pi c){return abs(a.F * b.S + b.F * c.S + c.F*a.S - a.S * b.F - b.S * c.F - c.S * a.F);}
ll gcd (ll a,ll b){if(b==0)return a;else return gcd (b, a % b);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll min(ll a,ll b){if(a < b){return a;}return b;}
ll max(ll a,ll b){if(a > b){return a;}return b;}
double intlog(ll n ,ll base){return (double)log(n)/log(base);}
ll n , t , m , temp , temp2, root , p ,q , k , i , j , r , u , v , w;
struct comp {
    bool operator()( pair<int, int> const& a, pair<int, int> const& b) {
        return a.first < b.first || (a.first == b.first && a.second > b.second);
    }
};

void transpose(vector<vi> & a){
    vector<vi> temp(n , vi(n));int i,j;
    fr(i , n){fr(j , n){temp[i][j] = a[j][i];}}
    a = temp;
}

ll solve(vi & a , ll i , ll val , ll p){
    if(i == a.size()){return val ^ p;}
    return min(solve(a , i + 1 , val , p | a[i]) , solve(a , i + 1 , val^p , a[i] ) );
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
#endif
    cin>>n;
    vi a(n);
    fr(i , n)cin>>a[i];
    cout<<solve(a , 0 , 0 , 0)<<nl;;
#ifndef ONLINE_JUDGE
    cout << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s .\n";
#endif
}

#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    int n;
    cin >> n;
    int arr[n];
    int ans = 2000000000;
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for(int mask = 0; mask < (1 << (n-1)); mask++)
    {
        int ore = 0;
        int xore = 0;
        for(int j = 0; j <= n; j++)
        {
            if(j < n) ore |= arr[j];

            if(j == n || (mask >> j&1))
            {
                xore ^= ore;
                ore = 0;
            }
        }
        ans = min(ans,xore);
    }
    cout << ans;
    return 0;
}


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

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

#define pb                    push_back
#define ll                    long long
#define ld                    long double
#define sz(x)                 (ll)x.size()
#define vll                   vector<long long>

#define infi                  INT_MAX
#define infl                  LONG_LONG_MAX
#define infd                  LDBL_MAX
#define f(i,a,b)              for(ll i=a;i<b;i++)
#define fi(i,a,b)             for(ll i=(b-1);i>=a;i--)
#define F                     first
#define S                     second
#define G(a,b)                get<a>(b)
#define MP                    make_pair
#define MT                    make_tuple
#define pll                   pair<ll,ll>
#define endl                  "\n"
#define ALL(v)                v.begin(),v.end()
#define nl                    cout<<"\n";
#define pr(x)                 cout<<x;
#define pr1(x)                cout<<x<<" ";
#define pr2(x,y)              cout<<x<<" "<<y;
#define pr3(x,y,z)            cout<<x<<" "<<y<<" "<<z;
#define pr4(x,y,z,w)          cout<<x<<" "<<y<<" "<<z<<" "<<w;
#define deb                   cout<<"***************************************************************************************\n";
#define moshi                 cout<<"moshi moshi ! \n";
#define hi                    cout<<"hi ! \n";
#define bye                   cout<<"bye bye ! \n";
#define kawai                 cout<<"O kawai koto ! \n";
#define o_set                 tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define number_of_set_bits  __builtin_popcountll
#define eb                    emplace_back
const ld PI=3.1415926535897932384626433;

template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T> >;

auto clk=clock();
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 <<"\n";
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

//**********************************************************  Code begins  ***********************************************

// trick for traversing all submasks
// for (ll j=mask ;j; j=(j-1)&mask)  // also include 0 manually
// v.resize(unique(v.begin(), v.end()) - v.begin());    // remove duplicates

void solve()
{
  ll a,b,c;
  cin>>a>>b>>c;
  ll x=a*a+b*b,y=c*c;
  if(x<y) cout<<"Yes\n";
  else cout<<"No\n";
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);

    ll test_cases=1;
    //cin>>test_cases;

    f(i,1,test_cases+1)
    {
        solve();
        //clr();
    }

    #ifdef rd
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;

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

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a * a + b * b < c * c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

int main(){
  ll n,w; cin>>n>>w;
  ll size = 200000,s,t,p,fin=0;
  vector<ll> time(size,0);
  rep(i,n){
    cin>>s>>t>>p;
    time[s] += p;
    time[t] += -p;
    if(t>fin) fin=t;
  }
  rep(i,fin){
    time[i+1] += time[i];
  }
  ll max=time[0];

  rep(i,fin){
   // cout << time[i] << endl;
    if(max<time[i]) max=time[i];
  }

  if(max>w) cout << "No" << endl;
  else      cout << "Yes"<< endl;
  return 0;
}

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m;
    string res;
    cin>>n>>m;
    if(n > m)
        res = m+3 > n ? "Yes" : "No";
    else
        res = n+3 > m ? "Yes" : "No";
    cout<<res;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll a,b,c,d,chk=0;
    cin>>a>>b>>c>>d;
    if((a==(b+c+d))|| (b==(a+c+d))|| (c==(a+b+d))|| (d==(a+c+b))|| ((a+b)==(c+d))||((a+c)==(b+d))||((a+d)==(c+b)) )chk=1;
    if(chk)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main() {
  vector<int> p(4);
  int B=0;
  for(int i=0;i<4;i++){
    cin>>p[i];
    B+=p[i];
  }
  for(int i=0;i<16;i++){
    int q=i,A=0;
    for(int j=0;j<4;j++){
      if(q%2==1){
        A+=p[j];
      }
      q/=2;
    }
    if(A*2==B){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll test_case;
	test_case=1;
    //cin>>test_case;
    while(test_case--)
    {
    	ll n;
    	cin>>n;
    	ll s=0;
    	ll i=111;
    	i=i*9;
    	while(i<n)
    	{
    		s+=n-i;
    		i/=9;
    		i=i*10+1;
    		i=i*10+1;
    		i=i*10+1;
    		i*=9;
		}
		cout<<s<<endl;
    }
    return 0;
}

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

bool is_ok_10(int x)
{
  while (0 < x) {
    if (x % 10 == 7) {
      return false;
    }
    x = x / 10;
  }
  return true;
}

bool is_ok_7(int x)
{
  while (0 < x) {
    if (x % 8 == 7) {
      return false;
    }
    x = x / 8;
  }
  return true;
}

int main()
{
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if(is_ok_7(i) && is_ok_10(i)) {
      cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define mod2 998244353
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}
const int mx=1e5+5;
vector<int> adj[mx];
int vis[mx];
int good[mx];
int c[mx+1];
multiset<int> s;
void dfs(int node,int depth){
    vis[node]=1;
    if(!s.count(c[node])){
    	//cout<<node;
       good[node]=1;

    }
    s.insert(c[node]);

    for(int next:adj[node]){
        if(!vis[next]){
          dfs(next,depth+1);
        }
    }
    auto it=s.find(c[node]);

    s.erase(it);

}

int main() {
   fast();
   int n;
   cin>>n;

   for(int i=1;i<=n;i++){
    cin>>c[i];
   }
   for(int i=1;i<=n-1;i++){
    int a,b;
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
   }
   set<int> s;

   dfs(1,1);
   vector<int> ans;
   for(int i=1;i<=n;i++){
    if(good[i]){
      cout<<i<<"\n";
    }
   }

}

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

int n;
vvi G;
vi color,used,ans;
void dfs(int a,int p){
	if(!used[color[a]])ans[a]=true;
	used[color[a]]++;
	rep(i,G[a].size())if(G[a][i]-p){
		dfs(G[a][i],a);
	}
	used[color[a]]--;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	color=ans=vi(n);
	used=vi(100100);
	rep(i,n)cin>>color[i];
	G=vvi(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	dfs(0,-1);

	rep(i,n)if(ans[i])cout<<i+1<<endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i, j, n) for (ll i = j; i < (n); i++)
#define repr(i, j, n) for (ll i = j; i >= (n); i--)
#define each(i, mp) for (auto &i : mp)
#define all(x) (x).begin(), (x).end()
#define CLR(mat, f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a <= x && x < b)
#define out(ans) cout << ans << endl
typedef pair<ll, ll> P;
const lb pi = acos(-1);
const ll mod = 1e9 + 7;
const ll INF = 1LL << 60;

int main(){

    ll n;cin>>n;
    ll x[n],y[n];rep(i,0,n)cin>>x[i]>>y[i];

    bool ans=false;

    rep(i,0,n-2){
        rep(j,i+1,n-1){

            rep(k,j+1,n){
                lb xd1=x[j]-x[i],xd2=x[k]-x[i];
                lb yd1=y[j]-y[i],yd2=y[k]-y[i];

                if(xd1==0 and xd2==0)ans=true;
                else if(yd1/xd1==yd2/xd2)ans=true;

            }
        }
    }

    if(ans)out("Yes");
    else out("No");

    return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
pair<int,int>point[1010];
bool online(int i,int j,int k)
{
	int x1=point[i].first;
	int y1=point[i].second;
	int x2=point[j].first;
	int y2=point[j].second;
	int x3=point[k].first;
	int y3=point[k].second;
	return (y3-y1)*(x2-x1)==(y2-y1)*(x3-x1);
}
signed main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		//int x,y;
		cin>>point[i].first>>point[i].second;
	}
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++)
	for(int k=j+1;k<=n;k++)
		if(online(i,j,k))
		{
			cout<<"Yes"<<endl;
			return 0;
		}

	cout<<"No"<<endl;
		return 0;
}


#include <bits/stdc++.h>
#define N 400005
#define ll long long
using namespace std;
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 T;
int n;
int a[N];
int main()
{

    n = read();
    string s;
    cin >>s;
    for(int i=1;i<= n + 1;i++) {
        a[i] = read();
    }
    int k = 1145141;
    for(int i=1;i<=n;i++) {
        k = min(k, abs(a[i + 1] - a[i]));
    }
    cout << k << endl;
    for (int i = 0; i < k; i += 1) {
        for (int j = 1; j <= n + 1; j += 1) {
            cout << (a[j] / k) + (i < a[j] % k) << ' ';
        }
        cout << endl;
    }
}
// 1 2 3 4 5 6 7 8
//

//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pb push_back
#define F first
#define S second
//#pragma GCC optimize("Ofast")

const int maxn = 1e4 + 5;

int n, a[maxn], ans = maxn, b[maxn][105];
string s;

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> s;
	for(int i = 0; i <= n; i++)
	{
		cin >> a[i];
		if(i&& (a[i - 1] < a[i]) == (s[i - 1] == '>'))
		{
			ans = 0;
		}

		if(i)
			ans = min(ans, abs(a[i] - a[i - 1]));
	}

	cout << ans << '\n';
	if(ans == 0)
		return 0;

	for(int i = 0; i <= n; i++)
	{
		for(int j = 0; j < a[i] % ans; j++)
			b[j][i] = (ans + a[i] - 1) / ans;
		for(int j = a[i] % ans; j < ans; j++)
			b[j][i] = a[i] / ans;

	}

	for(int i = 0; i < ans; i++)
	{
		for(int j = 0; j <= n; j++)
			cout << b[i][j] << " ";
		cout << '\n';
	}

}


#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using Tiib = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

// segment tree : node(monoid : (ll,+))
// ar[i] = count(i);
vector<ll> node;
int sz = 1;
// len node : sz = 2べき
void init(int n){
    while (sz < n) sz *= 2;
    node.resize(2 * sz - 1);
    rep(i,2 * sz - 1) node[i] = 1LL;
}
void initv(int n, vector<ll> vec){
    while (sz < n) sz *= 2;
    node.resize(2 * sz - 1);
    rep(i,n) node[i + sz - 1] = vec[i];
    rep(i,sz-n) node[sz - 1 + n + i] = 0LL;
    rep(i,sz-1) node[sz-2-i] = node[2*sz-3-2*i] + node[2*sz-2-2*i];
}
// update ar[a] -> x
void update(int a){
    a += sz - 1;
    node[a] = max(0LL, node[a]-1LL);
    while (a > 0){
        a = (a - 1) / 2;
        node[a] = node[2 * a + 1] + node[2 * a + 2];
    }
}
// query : min Nth, k : node番号, [l,r) : node[k]の区間
int query(int N, int k=0, int l=0, int r=sz){
    assert(N <= node[0]);
    if (sz-1 <= k) return k - sz + 1;
    if (N <= node[2*k+1]) return query(N,2*k+1,l,(l+r)/2);
    if (N > node[2*k+1]) return query(N-node[2*k+1],2*k+2,(l+r)/2,r);
}

int main(){
    int n; cin >> n;
    vector<int> ans(n);
    vector<ll> ar(202020,1LL);
    initv(202020,ar);
    rep(i,n){
        int a; cin >> a;
        update(a);
        int b = query(1,0,0,sz);
        ans[i] = b;
    }
    //cout << query(1,0,0,sz) << endl;
    rep(i,n) cout << ans[i] << endl; //cout << sz << endl; cout << node[sz-1] << endl;
    //cout << node[0] << endl; cout << node[sz] << endl;
}

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;

    bool nums[(int)2e5 + 2] = {}; int cur = 0;
    REP(i, 0, N) {
        int p; cin >> p;
        nums[p] = true;
        while (nums[cur]) cur++;
        cout << cur << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std ;

const int MAX = 3000 + 10 ;

int arr[MAX][5] ;
int freq[40] ;
int n ;

bool check(int x)
{
	memset(freq , 0 , sizeof(freq)) ;
	for(int i = 0 ; i < n ; ++i)
	{
		int mask = 0 ;
		for(int j = 0 ; j < 5 ; ++j)
		{
			if(arr[i][j] >= x)
				mask += (1 << j) ;
		}
		freq[mask]++ ;
	}
	for(int mask1 = 0 ; mask1 < 32 ; ++mask1)
	{
		if(!freq[mask1])
			continue ;
		for(int mask2 = 0 ; mask2 < 32 ; ++mask2)
		{
			if(!freq[mask2])
				continue ;
			for(int mask3 = 0 ; mask3 < 32 ; ++mask3)
			{
				if(!freq[mask3])
					continue ;
				int mask = (mask1 | mask2 | mask3) ;
				if(mask == 31)
					return true ;
			}
		}
	}
	return false ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = 0 ; j < 5 ; ++j)
			cin>>arr[i][j] ;
	}
	int l = 0 , r = 1e9 ;
	int ans = 0 ;
	while(l <= r)
	{
		int mid = (l + r) >> 1 ;
		if(check(mid))
			ans = mid , l = mid+1 ;
		else
			r = mid-1 ;
	}
	return cout<<ans<<"\n" , 0 ;
}

#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N+1,0),B(N+1,0),MB(N+1,0),C(N,0);
    ll ans=0;
    for(ll i=1; i<=N; i++){
        cin >> A.at(i);
    }
    for(ll i=1; i<=N; i++){
        B.at(i)=B.at(i-1)+A.at(i);
        if(B.at(i)>MB.at(i-1)) MB.at(i)=B.at(i);
        else MB.at(i)=MB.at(i-1);
    }
    for(ll i=1; i<N; i++){
        C.at(i)=C.at(i-1)+B.at(i);
        if(C.at(i)+MB.at(i+1)>ans){
          ans=C.at(i)+MB.at(i+1);
        }
    }
  	if(N==1 && A.at(1)>0) ans=A.at(1);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;

signed main(){

    int N; cin >> N;

    Out(bit(N) - 1);
    FOR(i, 1, bit(N)){
        string ans(bit(N), 'A');
        REP(j, bit(N)) if(__builtin_popcount(i & j) % 2) ans[j] = 'B';

        Out(ans);
    }

    return 0;
}

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

int main(){
    ll n,count,p;
    count=0;
    cin>>n;
    p=1;
    ll q=0;

    while(true){

        if(p*1000>n){

            count+=q*(n-p+1);
            cout<<count<<endl;
            return 0;
            break;
        }
        count+=q*(p*1000-p);
        p=p*1000;
        q++;
    }
}


// Problem: B - Insurance
// Contest: AtCoder - Tokio Marine & Nichido Fire Insurance Programming Contest 2021（AtCoder Regular Contest 122)
// URL: https://atcoder.jp/contests/arc122/tasks/arc122_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define pb push_back
#define mp make_pair
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
const int MAX_N = 1e5+10;

int n, a[MAX_N];

void solve()
{
	sort(a,a+n);
	const int mid = n/2;
	double ans = 5e18;
	for(int i=mid,j=mid+1,iter=0;(iter<100 && (i>=0 || j<n)) ;i--, j++){
		if(i>=0){
			double x = 1.0*a[i]/2, cur = 0;
			for(int k=0;k<n;++k) cur += x + a[k]-min(1.0*a[k],2*x);
			ans = min(ans, cur/n);
		}
		if(j<n){
			double x = 1.0*a[j]/2, cur = 0;
			for(int k=0;k<n;++k) cur += x + a[k]-min(1.0*a[k],2*x);
			ans = min(ans, cur/n);
		}
		iter++;
	}
	printf("%.16lf\n", ans);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n;
	for(int i=0;i<n;++i)cin>>a[i];
	solve();
	return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int N;
char S[10011];
int A[10011];

void MAIN() {
    scanf("%d%s", &N, S);
    REP (i, N+1) scanf("%d", A+i);

    int mi = 1<<29;
    REP (i, N) amin(mi, abs(A[i] - A[i+1]));
    printf("%d\n", mi);

    REP (t, mi) {
	REP (i, N+1) {
	    int q = A[i] / mi;
	    int r = A[i] % mi;
	    if (t < r) q++;
	    printf("%d%c", q, " \n"[i==N]);
	}
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;

template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
static const ld pi = 3.141592653589793L;

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

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

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

//グラフ関連
struct Edge {
    int to, rev;
    ll cap;
    Edge(int _to, int _rev, ll _cap) : to(_to), rev(_rev), cap(_cap) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

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

vector<ll> divisor(ll n) {
    vector<ll> ret;

    sort(ret.begin(), ret.end());
    return ret;
}
void solve() {
    ll n, m;
    cin >> n >> m;
    Graph G(n);
    vec<ll> C(m), D(m);
    REP(i, m) {
        ll a, b;
        cin >> a >> b >> C[i] >> D[i];
        a--;
        b--;
        add_edge(G, a, b, i, true, i);
    }

    vec<ll> d(n);
    REP(i, d.size())
    d[i] = INF;
    d[0] = 0;
    priority_queue<P, vector<P>, greater<P>> q;
    q.push(make_pair(0, 0));
    while(!q.empty()) {
        auto [t, v] = q.top();
        q.pop();

        if(d[v] < t)
            continue;
        for(auto e : G[v]) {
            ll cost = INF;
            chmin(cost, max(0LL, D[e.cap] - t)); //0にする
            chmin(cost, D[e.cap] / (t + 1));     //そのまま
            ll T = sqrtl(D[e.cap]);
            if(T > 1)
                chmin(cost, D[e.cap] / (T - 1) + max(0LL, T - 1 - (t + 1))); //最小の時
            if(T != 0)
                chmin(cost, D[e.cap] / T + max(0LL, T - (t + 1)));       //最小の時
            chmin(cost, D[e.cap] / (T + 1) + max(0LL, T + 1 - (t + 1))); //最小の時
            cost += C[e.cap];

            if(d[e.to] > d[v] + cost) {
                d[e.to] = d[v] + cost;
                q.push(make_pair(d[e.to], e.to));
                //cout << v << "->" << e.to << " " << d[e.to] << en;
            }
        }
    }
    if(d[n - 1] == INF)
        cout << -1 << en;
    else
        cout << d[n - 1] << en;
}

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

    // ll t;
    // cin >> t;
    // REP(i, t - 1) {
    //     solve();
    // }

    solve();

    return 0;
}

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

typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
ll vx[4]={0,1,0,-1};
ll vy[4]={1,0,-1,0};
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll pow(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=pow(N,P/2,M);
        return t*t%M;
    }
    else return N*pow(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}

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

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

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

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

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

int main(){
    ll N,K;
    cin>>N>>K;
    ll d=2;
    ll sum=0;
    ll suma=0;
    while(sum<K){
        suma=sum;
        d++;
        if(d<=N+2){
            sum+=(d-1)*(d-2)/2;
        }
        else if(d>=2*N+1){
            sum+=(3*N+2-d)*(3*N+1-d)/2;
        }
        else {
            sum+=(d-1)*(d-2)/2;
            sum-=3*(d-N-2)*(d-N-1)/2;
        }
    }
    ll e=0;
    ll L=K-suma;
    sum=0;
    suma=0;
    while(sum<L){
        suma=sum;
        e++;
        if(d-e<N+1){
            sum+=d-e-1;
        }
        else if(d-e<=2*N){
            sum+=2*N-d+e+1;
        }
    }
    ll f,g;
    if(d-e>N+1){
        g=N-(L-suma)+1;
        f=d-e-g;
    }
    else{
        f=L-suma;
        g=d-e-f;
    }
    cout<<e<<" "<<f<<" "<<g<<endl;
}


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

#define FASTio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define all(v) (v).begin(), (v).end()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define printarr(v) {for(auto x : v) cout<<x<<" ";cout<<"\n";}
#define mp make_pair
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define lcm(a, b) ((a) * (b)) / __gcd(a, b)
#define umpit unordered_map<ll,ll>::iterator
#define mpit map<ll,ll>::iterator
#define setit set<ll>::iterator
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
const ll INF = LLONG_MAX / 2;
#define PI 3.1415926535897932384626433832795
#define mod 1000000007

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // designed by Sebastiano Vigna and found on Neal's blog
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    // unordered_map<int,int,custom_hash> M;
};

int main()
{
   FASTio;
    #ifndef ONLINE_JUDGE                    //file start
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif                                  //file end
    ll t=1,i,j;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>arr(n);
        for(i=0;i<n;i++)
            cin>>arr[i];
        ll ans = 0;
        ll sum = accumulate(all(arr),0ll);
        vector<vector<bool>>dp(n+1,vector<bool>(sum+1,false));
        for(i=0;i<=n;i++)
            dp[i][0] = true;
        for(i=1;i<=sum;i++)
            dp[0][i] = false;

        for(i=1;i<=n;i++)
        {
            for(j=1;j<=sum;j++)
            {
                dp[i][j] = dp[i-1][j];
                if(arr[i-1] <= j)
                    dp[i][j] = dp[i][j] | dp[i-1][j-arr[i-1]];
            }
        }
        for(i=(sum+1)/2;i<=sum;i++)
        {
            if(dp[n][i])
            {
                ans = i;
                break;
            }
        }

        cout<<ans<<"\n";
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define int long long

template <typename T>
void print_vec(const vector<T>& v, bool newline = true) {
    for (int i = 0; i < v.size(); ++i) {
        cout << v[i] << " ";
    }
    if (newline) {
        cout << "\n";
    }
}

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

const int maxn = (int)2e5+105;
const int mod = (int)998244353 ;

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

#define pb push_back
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)

using vi = vector<int>;

int fact_setup=0; int * fact;

int ex (int a, int b){
    if(b==0)return 1; int e = ex(a,b/2); e=(1ll*e*e)%mod; if(b&1)e=(1ll*e*a)%mod; return e;
}
int inv (int a){
    return ex(a, mod - 2);
}
int choose (int a, int b){
    if(!fact_setup){
        fact_setup=1;
        fact = new int [maxn];
        fact[0]=1; rep (i,1,maxn-1) fact[i]=(i*fact[i-1])%mod;
    }
    if(a<b)return 0;
    int num = fact[a];
    int denom = (fact[b] * fact[a - b]) % mod;
    return (num * inv(denom)) % mod;
}

#define pii pair <int, int>
#define pvi pair <vector <int>, int>

#define pai array <int,2>
#define pdi array <double, 2>
#define pdt array <double, 3>

#define pti array <int,3>
#define pfi array <int,4>

#define all(v) v.begin(), v.end()

bool pos [maxn], pos2[maxn];
int t[maxn];
main(){
    cin.tie(0); ios_base::sync_with_stdio(0);
	int n; cin >> n;
	int tot=0;
	rep (i,1,n){cin>>t[i]; tot+=t[i];}
	pos[0] = 1;
	rep (i,1,n){
		memset(pos2,0,sizeof(pos2));
		rep (j,0,maxn-1){
			if(pos[j]) pos2[j+t[i]]=pos2[abs(j-t[i])]=1;
		}
		rep (j,0,maxn-1)pos[j]=pos2[j];
	}
	rep (j,0,maxn-1){
		if (pos[j]){
			cout<<(tot-j)/2 + j << '\n'; return 0;
		}
	}

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,mmx,avx")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<pll> vpll;
template<typename T> void makeunique(vector<T> &vx) {sort(vx.begin(),vx.end());auto it=unique(vx.begin(),vx.end());vx.resize(std::distance(vx.begin(),it));}

int h[128];

int win(int x, int y) {
	if ((x+1)%3==y) return x;
	else return y;
}

void solve(int n, int klim, std::string inp){
	memset(h,-1,sizeof h);
	h['R']=0; h['S']=1; h['P']=2;
	vi a[2];
	a[0].resize(n);a[1].resize(n);
	for (int i=0;i<n;i++) a[0][i]=h[inp[i]];

	int cur=0,nxt=1;
	for (int k=0;k<klim;k++) {
		for (int i=0;i<n;i++) {
			a[nxt][i]=win(a[cur][(i*2)%n],a[cur][((i*2)+1)%n]);
		}
		swap(cur,nxt);
	}
	char ans;
	for (int x=0;x<128;x++) if (h[x]==a[cur][0]) ans=x;
	printf("%c\n",ans);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long n;
    scanf("%lld",&n);
    long long k;
    scanf("%lld",&k);
    std::string s;
    std::cin >> s;
    solve(n, k, s);
    return 0;
}

/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';
#define int long long
using namespace std;
template<class T>void show(vector<T> &a) {cerr << "[ "; for (int ij = 0; ij < (int)a.size(); ij++) {cerr << a[ij] << " ";} cerr << "]\n";}
template<class T>void show(T a) {cerr << a << endl;}

int r, c;
int mat[2005][2005], dp[2005][2005];
bool visited[2005][2005];

int find(int x, int y) {
	if (x == r - 1 && y == c - 1) {
		return 0;
	}
	if (visited[x][y]) {
		return dp[x][y];
	}
	visited[x][y] = 1;
	int res = -1e9;
	if (x + 1 < r) {
		res = max(res, mat[x + 1][y] - find(x + 1, y));
	}
	if (y + 1 < c) {
		res = max(res, mat[x][y + 1] - find(x, y + 1));
	}
	dp[x][y] = res;

	return res;
}

void solve() {
	int i, j;
	cin >> r >> c;

	for (int i = 0; i < r; ++i)
	{
		for (int j = 0; j < c; ++j)
		{
			char t; cin >> t;
			mat[i][j] = (t == '+') ? 1 : -1;
		}
	}

	int ans = find(0, 0);

	if (ans > 0) {
		cout << "Takahashi" << endl;
	}
	else if (ans < 0) {
		cout << "Aoki" << endl;
	}
	else {
		cout << "Draw" << endl;
	}

}

int32_t main(int32_t argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int T = 1;
	// cin >> T;
	while (T--) {
		solve();
	}
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
}


#include<iostream>
using namespace std;
int main(){
    int n,ans;
    ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,p,x,t;
        cin>>a>>p>>x;
            t=ans;
                if(a<=0.5+x-1){
                    if(ans==0){
                        ans=p;
                    }else if(ans!=0&&t<=p){
                        ans=t;
                    }else if(ans!=0&&t>=p){
                        ans=p;
                    }
                }
    }
    if(ans==0){
        cout<<"-1";
    }else{
        cout<<ans;
    }
}

#include <bits/stdc++.h>
using namespace std;
const int N = 100000+10;
int main(){
	int n;
	int a[N][3];
	int k=0;
	int min=1e9+10;
	int b[N];
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<n;i++){
		if(a[i][2]-a[i][0]>0){
			b[k]=a[i][1];
			k++;
		}
		else{
			continue;
		}
	}
	if(k==0){
		cout<<"-1";
	}
	else{
		for(int i=0;i<k;i++){
			if(b[i]<min){
				min=b[i];
			}
		}
		cout<<min;
	}
	return 0;
}


#include <iostream>
using namespace std;
int main ()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a-b==(b-c) || a-c==c-b || c-a==a-b)
  cout<<"Yes";
  else
  cout<<"No";
  return 0;
}

#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <unordered_set>
#include <queue>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

#define rep(i,n) for (int i=0; i<(n);++i)
//ll mod=998244353,fac[1000001],finv[1000001],inv[1000001];
int INF = 1e9+7,n,m,p,q,k,s;
vector<int> an(3,-1);
unordered_set<char> tops;
const double PI = acos(-1);
vector<vector<int>> dir = {{0,1},{1,0},{0,-1},{-1,0}};

ll power(ll a,ll b){
  ll ans=1;
  for(ll i=0;b>=(1<<i);++i){
    if(b&(1<<i)) ans=ans*a%INF;
    a=a*a%INF;
    //cout << "ans " << ans << endl;
  }
  return ans;
}

/*
int rec(int S,int v,vector<int> &x,vector<vector<int>> &dp){
  //cout << "s " << S << " v " << v << endl;
  if(dp[S][v]>0) return dp[S][v];
  if(v==n-1) return dp[S][v]=0;
  int res=INF;
  rep(u,m){
    if(!(S>>u & 1)){
      if(x[u]==1) res = min(res,rec(S|1<<u,u,x,dp)+p);
      else res = min(res,rec(S|1<<u,u,x,dp)+q);
    }
  }
  return dp[S][v]=res;
}*/

int main(){
  vector<string> s(3);
  cin >> s[0] >> s[1] >> s[2];
  set<char> se;
  rep(i,3){
    for(char a:s[i]){
      if(!(se.count(a))) se.insert(a);
    }
  }
  rep(i,3) tops.insert(s[i][0]);
  if(se.size()>10){
    cout << "UNSOLVABLE" << endl;
    return 0;
  }
  int n = se.size();
  ll indexes[10];
  map<char,int> ma;
  int id=0;
  for(auto x:se){
    ma[x]=id;
    id++;
  }
  rep(i,10) indexes[i]=i;
  int cnt=0;
  do{
    //rep(i,10) cout << indexes[i] << endl;
    //cout << endl;
    int go=0;
    for(auto x:tops){
      if(indexes[ma[x]]==0) go=1;
    }
    if(go==1) continue;
    vector<ll> v(3,0);
    rep(i,3){
      rep(j,s[i].size()){
        v[i]=v[i]*10+indexes[ma[s[i][j]]];
      }
    }
    //rep(i,3) cout << v[i] << ' ';
    //cout << endl;
    if(v[0]+v[1]==v[2]){
      rep(i,3) cout << v[i] << endl;
      return 0;
    }
  }while(next_permutation(indexes,indexes+10));
  cout << "UNSOLVABLE" << endl;
}


/*
 © 2021-03-28 06:53:10 Franco1010 All Rights Reserved
*/

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;
using uint=unsigned;
using ull=unsigned long long;
struct modinfo{uint mod,root;};
template<modinfo const&ref>
struct modular{
	static constexpr uint const &mod=ref.mod;
	static modular root(){return modular(ref.root);}
	uint v;
	//modular(initializer_list<uint>ls):v(*ls.bg){}
	modular(lli vv=0){s(vv%mod+mod);}
	modular& s(uint vv){
		v=vv<mod?vv:vv-mod;
		return *this;
	}
	modular operator-()const{return modular()-*this;}
	modular& operator+=(const modular&rhs){return s(v+rhs.v);}
	modular&operator-=(const modular&rhs){return s(v+mod-rhs.v);}
	modular&operator*=(const modular&rhs){
		v=ull(v)*rhs.v%mod;
		return *this;
	}
	modular&operator/=(const modular&rhs){return *this*=rhs.inv();}
	modular operator+(const modular&rhs)const{return modular(*this)+=rhs;}
	modular operator-(const modular&rhs)const{return modular(*this)-=rhs;}
	modular operator*(const modular&rhs)const{return modular(*this)*=rhs;}
	modular operator/(const modular&rhs)const{return modular(*this)/=rhs;}
	modular pow(int n)const{
		modular res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modular inv()const{return pow(mod-2);}

	friend modular operator+(int x,const modular&y){
		return modular(x)+y;
	}
	friend modular operator-(int x,const modular&y){
		return modular(x)-y;
	}
	friend modular operator*(int x,const modular&y){
		return modular(x)*y;
	}
	friend modular operator/(int x,const modular&y){
		return modular(x)/y;
	}
	friend ostream& operator<<(ostream&os,const modular&m){
		return os<<m.v;
	}
	friend istream& operator>>(istream&is,modular&m){
		lli x;is>>x;
		m=modular(x);
		return is;
	}
	bool operator<(const modular&r)const{return v<r.v;}
	bool operator==(const modular&r)const{return v==r.v;}
	bool operator!=(const modular&r)const{return v!=r.v;}
	explicit operator bool()const{
		return v;
	}
};

extern constexpr modinfo base{998244353,3};
// extern constexpr modinfo base{1000000007,0};
//modinfo base{1,0};
using mint=modular<base>;

//COMBI

const int vmax=(1<<21)+10;
mint fact[vmax],finv[vmax],invs[vmax];
void initfact(){
	fact[0]=1;
	fore(i,1,vmax)fact[i]=fact[i-1]*i;
	finv[vmax-1]=fact[vmax-1].inv();
	for(int i=vmax-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
	for(int i=vmax-1;i>=1;i--)invs[i]=finv[i]*fact[i-1];
}
mint choose(int n,int k){
	return fact[n]*finv[n-k]*finv[k];
}
mint binom(int a,int b){
	return fact[a+b]*finv[a]*finv[b];
}
mint catalan(int n){
	return binom(n,n)-(n-1>=0?binom(n-1,n+1):0);
}
const lli N = 2e5 + 5;
lli p[N];
vi primes;
lli n, m;
set<vi> st;
void dfs(vi& v, lli cur){
  if(sz(v) == n){
    st.insert(v);
    return;
  }
  lli foo = cur;
  while(foo <= m){
    v.pb(foo);
    dfs(v, foo);
    v.pop_back();
    foo += cur;
  }
}
mint f(lli x){
  mint res = 1;
  while(x > 1){
    lli foo = p[x];
    lli cnt = 0;
    while(p[x] == foo){
      x /= p[x];
      cnt++;
    }
    res *= choose(n - 1 + cnt, cnt);
  }
  return res;
}
int main(){ _
  p[0] = p[1] = 1;
  for(lli i = 2; i < N; i++) if(!p[i]) for(lli j = i; j < N; j += i) p[j] = i;
  // fore(i, 0, N) if(!p[i]) primes.pb(i);
  // freopen("file.in","r",stdin);
  // freopen("file.out","w",stdout);
  initfact();
  cin >> n >> m;
  mint ans = 0;
  fore(i, 2, m + 1){
    ans += f(i);
  }
  cout << ans + mint(1) << ENDL;
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using  namespace std;
int main(){
    long long n;
    cin >> n;
    vector<int>a(n);

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

    long long ans = n*(n-1);
    long long cnt=0;
    for(int i=1; i<n; i++){
        if(a[i]!=a[i-1]){
            ans -= cnt*(cnt+1);
            cnt = 0;
        }else{
            cnt++;
        }
    }
    ans -= cnt*(cnt+1);
    cout << ans/2 << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define p 998244353
int n,m,er[21];
int jc[10001],ny[10001];
int f[20][5001];
int ksm(int x,int y){
	if(x==1)return y;
	LL u=ksm(x/2,y);
	u=(LL)u*u%p;
	if(x&1)u=(LL)u*y%p;
	return u;
}
LL ans=0;
int read(){
	int u=0;
	char c=getchar();
	while(c>'9'||c<'0'){
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		u=u*10+c-48;
		c=getchar();
	}
	return u;
}
int C(int x,int y){
	if(y>x)return 0;
	return (LL)jc[x]*ny[y]%p*ny[x-y]%p;
}
int main(){
	n=read();
	m=read();
	jc[0]=ny[0]=1;
	fo(i,1,m+n)jc[i]=(LL)jc[i-1]*i%p;
	ny[n+m]=ksm(p-2,jc[n+m]);
	fod(i,n+m,2)ny[i-1]=(LL)ny[i]*i%p;
	er[0]=1;
	fo(i,1,20)er[i]=er[i-1]*2;
	f[0][0]=1;
	fo(i,1,20){
		if(er[i]<=m){
			fo(j,0,m){
				if(f[i-1][j]){
					fo(k,0,(m-j)/er[i]){
//						if(j+k*er[i]==20&&i==3)cout<<j<<endl;
						f[i][j+k*er[i]]=(f[i][j+k*er[i]]+(LL)C(n,2*k)*f[i-1][j]%p)%p;
					}
				}
			}
//			fo(j,0,m)if(f[i][j])cout<<i<<" "<<j<<" "<<f[i][j]<<endl;
			ans=f[i][m];
		}
	}
	printf("%lld",ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define inf          1e15
#define mod          1000000007
#define N            100001
#define ll           long long int
#define vint         vector<int>
#define vll          vector<ll>
#define vstr         vector<string>
#define vvint        vector<vector<int> >
#define vvll         vector<vector<ll> >
#define vint_pair    vector<pair<int,int> >
#define input(arr)   for(auto &x:arr) cin>>x;
#define all(x)       (x).begin(), (x).end()
#define rall(x)      (x).rbegin(), (x).rend()

int main() {
    int a,b; cin>>a>>b;
    int mul = 1;
    if(a<b){
        int tmp = a;
        a = b;
        b = tmp;
        mul = -1;
    }
    for(int i=1;i<=a;++i){
        cout<<(i*mul)<<" ";
    }
    int m = (a*(a+1))/2;
    int n = (b*(b-1))/2;
    for(int i=1;i<b;++i){
        cout<<(-i * mul)<<" ";
    }
    cout<<(n-m)*mul;
}


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

int main(){
  ll k, n, m;
  cin >> k >> n >> m;
  vector<pair<ll,ll>> S(k);
  vector<ll> A(k);
  vector<ll> B(k);

  for(ll i=0; i<k; i++) cin >> A[i];

  ll count = 0;
  for(ll i=0; i<k; i++){
    ll b = m*A[i]/n;
    if(m*A[i]%n >= n/2) b++;
    B[i] = b;
    count += b;
    S[i].first = n*b - m*A[i];
    S[i].second = i;
  }

  sort(S.begin(),S.end());

  if(count<=m){
    for(ll i=0; i<(m - count); i++){
      B[S[i].second] += 1;
    }
  }else{
    for(ll i=0; i<(count - m); i++){
      B[S[k-1-i].second] -= 1;
    }
  }

  for(ll i=0; i<k; i++) cout << B[i] << " ";
  cout << endl;

  return 0;
}

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

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

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
int tmp[100000], P[50000], Q[50000];
void pakuri_sort(int N, int A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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

	int N = getint();

	ll kotae = 0;
	rep(i, N) {
		tmp[i] = getint();
		kotae += tmp[i];
	}
	rep(i, N) {
		int b = getint();

		if (i & 1) P[i >> 1] = (b - tmp[i] + 1000000000);
		else Q[i >> 1] = (b - tmp[i] + 1000000000);
	}

	pakuri_sort(N / 2, P);
	pakuri_sort(N / 2, Q);

	int k = N / 2 - 1;
	while (k >= 0) {
		int a = P[k] - 1000000000;
		int b = Q[k] - 1000000000;
		if (a + b <= 0) break;
		kotae += a + b;
		k--;
	}

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

	Would you please return 0;
}


/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define vz(x) x.size()
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
const int N = 105;
const int INF = 1e9 + 50;
const int MOD = 1e9 + 7;
double dp[N][N][N];
bool vis[N][N][N];

double ddiv(double a, double b) {
  return a / b;
}

double f(int gold, int silver, int bronze) {
  if (gold == 100 || silver == 100 || bronze == 100) return 0;

  double &sol = dp[gold][silver][bronze];
  if (vis[gold][silver][bronze]) return sol;
  vis[gold][silver][bronze] = 1;

  sol = 1;
  sol += ddiv(gold, gold + silver + bronze) * f(gold + 1, silver, bronze);
  sol += ddiv(silver, gold + silver + bronze) * f(gold, silver + 1, bronze);
  sol += ddiv(bronze, gold + silver + bronze) * f(gold, silver, bronze + 1);

  return sol;
}

int main() {
  int a, b, c; scanf("%d%d%d", &a, &b, &c);
  memset (vis, false, sizeof vis);
  printf("%.10lf\n", f(a, b, c));
  return 0;
}

void in(int &x){
  bool neg = false;
  register int c;
  x = 0;
  c = getchar();
  if(c == '-'){
    neg = true;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x *= -1;
}

#include <bits/stdc++.h>
using namespace std;
string s,t;
int main()
{
	long long n;
	cin>>n;
	cin>>s>>t;
	vector<int> ss,tt;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='0')
		{
			ss.push_back(i);
		}
		if(t[i]=='0')
		{
			tt.push_back(i);
		}
	}
	if(ss.size()!=tt.size())
	{
		cout<<-1<<endl;
	}
	else{
		long long ans=0;
		for(int i=0;i<ss.size();i++)
		{
			if(ss[i]!=tt[i]) ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>             /*Fuck ratings Feel the magic in the code...*/
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// template<typename T>
// using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*   in log(n) time...
    find_by_order() - Returns an iterator to the k-th largest element (counting from zero)
    order_of_key()  - The number of items in a set that are strictly smaller than our item
    // Rest same as set
*/
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define inf 2e18
#define minf -2e18
#define PI 3.141592653589793238462
#define ll long long
#define all(x) x.begin(), x.end()
#define min3(a, b, c) min(min(a, b), c)
#define max3(a, b, c) max(max(a, b), c)
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define sz(v) (int)v.size()
#define nline "\n"

ll powr(ll a, ll b, ll p) { if(b == 0) return 1; else if(b == 1) return a; else if(!(b & 1)) return powr((a * a) % p, b / 2, p); else return (a * powr(a, b - 1, p)) % p; }
ll gcd(ll a, ll b){ if(b == 0) return a; else return gcd(b, a % b); }
ll lcm(ll a, ll b){ return a * b / gcd(a, b); }
void extendgcd(ll a, ll b, ll *v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0]; } //for non prime b
ll mod_inv(ll a, ll p){ return powr(a,p-2,p); } /*For prime p  "Fermet lill theorem"*/
ll mod_add(ll a, ll b, ll m) { a = a % m; b = b % m; return ((a + b) % m + m) % m; }
ll mod_mul(ll a, ll b, ll m) { a = a % m; b = b % m; return ((a * b) % m + m) % m; }
ll mod_sub(ll a, ll b, ll m) { a = a % m; b = b % m; return ((a - b) % m + m) % m; }
ll mod_div(ll a, ll b, ll m) { a = a % m; b = b % m; return (mod_mul(a, mod_inv(b, m), m) + m) % m; } /*For prime p*/
// void swap(int &a, int &b) { int temp = a; a = b; b = temp; }
ll spf(ll n) { for(int i = 2; i * i <= n; i++) { if(n % i == 0) return i; } return n; }/* spf in sqrt(n) time... */
vector<ll> fact_modp(ll n, ll p) { vector<ll> fact(n + 1); fact[0] = 1; for(int i = 1; i <= n; i++){ fact[i] = (i * fact[i - 1]) % p; } return fact; }
/*For prime p "Fermet lill theorem..."*/
ll nCr_modp(ll n, ll r, ll p, vector<ll> fact) {  if(n < r) return 0; if(r == 0) return 1; else { return ((fact[n] * mod_inv(fact[r], p)) % p * mod_inv(fact[n - r], p)) % p; } }

vector<ll> prime_sieve(ll n) { /*Returns vector of prime <= n  in nloglogn time*/
    vector<ll> t;
    vector<bool> a(n + 1, true);
    a[0] = a[1] = false;
    for(int i = 2; i * i <= n; i++) {
        if(a[i]) {
            for(int j = i * i; j <= n; j += i)
            a[j] = false;
        }
    }
    for(int i = 0; i <= n; i++) {
        if(a[i])
        t.push_back(i);
    }
    return t;
}
vector<ll> spf_sieve(ll n) { /*Returns vector of spf[n] in nloglogn time*/
    vector<ll> a(n + 1, -1);
    for(int i = 2; i * i <= n; i++) {
        if(a[i] == -1) {
            a[i] = i;
            for(int j =i * i; j <= n; j += i) { if(a[j] == -1) a[j] = i;}
        }
    }
    for(int i = 2; i <= n; i++) { if(a[i] == -1) a[i] = i;}
    return a;
}
     /* --------------------------------------Template ends, Dee codes---------------------------------------*/

int main()
{
    fastio();

    int tests = 1;
    // cin >> tests;
    while(tests--)
    {
    	int n;
    	cin >> n;
    	vector<int> a(n);
    	ll res = 0;
    	map<int, ll> mp;
    	for(int i = 0; i < n; i++) {
    		cin >> a[i];
    		int r1 = (200 - (a[i] % 200));
    		if(r1 != 200) {
    			res += mp[200 - r1];
    		}
    		mp[a[i] % 200]++;
    	}
    	res += ((mp[0] * (mp[0] - 1)) / 2);
    cout << res << nline;

    }
    return 0;
}

#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <fstream>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define sq5(x) ((x) * (x) * (x) * (x) * (x))
#define N 400005

ll t[N * 4];

void push(int v) {
	if (t[v]) {
		t[v * 2] += t[v];
		t[v * 2 + 1] += t[v];
		t[v] = 0;
	}
}

void upd(int v, int tl, int tr, int l, int r, ll val) {
	if (l > r) {
		return;
	}

	if (tl == l && tr == r)  {
		t[v] += val;

		return;
	}

	push(v);
	int tm = (tl + tr) / 2;

	upd(v * 2, tl, tm, l, min(tm, r), val);
	upd(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r, val);
}

ll get(int v, int tl, int tr, int pos) {
	if (tl == tr) {
		return t[v];
	}

	push(v);
	int tm = (tl + tr) / 2;
	if (pos <= tm) {
		return get(v * 2, tl, tm, pos);
	}
	else {
		return get(v * 2 + 1, tm + 1, tr, pos);
	}
}

vector<vi>g;
int tIn[N], tOut[N];
int tt = 0;

void dfs(int v, int p = -1) {
	tIn[v] = tt++;

	REP(i, sz(g[v])) {
		int u = g[v][i];
		if (u != p) {
			dfs(u, v);
		}
	}

	tOut[v] = tt++;
}

bool inner(int a, int b) {
	return tIn[b] <= tIn[a] && tOut[a] <= tOut[b];
}

int main(void) {
	int n;
	scanf("%d", &n);
	g.resize(n);
	CL(tIn, -1);
	CL(tOut, -1);
	vii edges;
	REP(i, n - 1) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--, y--;
		g[x].pb(y);
		g[y].pb(x);
		edges.pb(mp(x, y));
	}

	dfs(0);

	int q;
	scanf("%d", &q);
	REP(i, q) {
		int type, e;
		ll x;
		scanf("%d%d%lld", &type, &e, &x);
		e--;
		if (type == 1) {
			if (inner(edges[e].X, edges[e].Y)) {
				upd(1, 0, n * 2 - 1, tIn[edges[e].X], tOut[edges[e].X], x);
			}
			else {
				upd(1, 0, n * 2 - 1, 0, n * 2 - 1, x);
				upd(1, 0, n * 2 - 1, tIn[edges[e].Y], tOut[edges[e].Y], -x);
			}
		}
		else {
			if (inner(edges[e].Y, edges[e].X)) {
				upd(1, 0, n * 2 - 1, tIn[edges[e].Y], tOut[edges[e].Y], x);
			}
			else {
				upd(1, 0, n * 2 - 1, 0, n * 2 - 1, x);
				upd(1, 0, n * 2 - 1, tIn[edges[e].X], tOut[edges[e].X], -x);
			}
		}
	}

	REP(i, n) {
		printf("%lld\n", get(1, 0, n * 2 - 1, tIn[i]));
	}

}


#define G 3
#include<map>
#define AK goto
#include<cmath>
#include<queue>
#include<bitset>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define md ((l+r)>>1)
#define cht 1000000007
#define inf 1145141919810
#define mem(i,j)memset(i,j,sizeof(i))
#define F(i,j,n)for(int i=j;i<=n;i++)
#define D(i,j,n)for(int i=j;i>=n;i--)
using namespace std;
namespace sky_chen{
//	char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
//	#define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++
	inline ll read(){ll ans=0,f=1;char a=getchar();while(a>'9'||a<'0'){if(a=='-')f=-1;a=getchar();}while(a>='0'&&a<='9')ans=ans*10+(a^48),a=getchar();return ans*f;}
	inline char red(){char a=getchar();while(a>'z'||a<'a')a=getchar();return a;}
//	inline void print(ll x){if(x>9)print(x/10);*O++=x%10+'0';}
	inline void cadd(ll &x,ll y){x=(x+y)%cht;}
	inline void cmin(ll &x,ll y){x=min(x,y);}
	inline void cmax(ll &x,ll y){x=max(x,y);}
	ll qpow(ll n,ll base=cht-2){ll ans=1;while(base){if(base&1)ans=ans*n%cht;n=n*n%cht;base>>=1;}return ans;}
	const int maxn = 1e6+5;
	const int maxc = 3e5+5;
	ll n,x[maxn],y[maxn];
	struct node{
		ll a=0,b=0,c=0;
	}p1,p2,t,f[maxn],g[maxn];
	int yyds(){
		n=read();
		F(i,1,n)x[i]=read(),y[i]=read();
		ll m=read();
		p1.a=1;p2.b=1;
		f[0]=p1;g[0]=p2;
		F(i,1,m){
			ll opt=read();
			if(!(opt-1)){
				t=p1;p1=p2;p2.a=-t.a;p2.b=-t.b;p2.c=-t.c;
				f[i]=p1;g[i]=p2;
			}
			else if(!(opt-2)){
				t=p2;p2=p1;p1.a=-t.a;p1.b=-t.b;p1.c=-t.c;
				f[i]=p1;g[i]=p2;
			}
			else if(!(opt-3)){
				p1.c=2*read()-p1.c;p1.b=-p1.b;p1.a=-p1.a;
				f[i]=p1;g[i]=p2;
			}
			else{
				p2.c=2*read()-p2.c;p2.b=-p2.b;p2.a=-p2.a;
				f[i]=p1;g[i]=p2;
			}
		}
//		F(i,0,m)cout<<f[i].a<<' '<<f[i].b<<' '<<f[i].c<<' '<<g[i].a<<' '<<g[i].b<<' '<<g[i].c<<endl;
		ll q=read();
		F(i,1,q){
			ll sb1=read(),sb2=read();
			ll za=x[sb2],zb=y[sb2];
			ll nza=f[sb1].a*za+f[sb1].b*zb+f[sb1].c,nzb=g[sb1].a*za+g[sb1].b*zb+g[sb1].c;
			printf("%lld %lld\n",nza,nzb);
		}
	    return 0;
	}
}
int main(){return sky_chen::yyds();}

//sky_chen txdy!

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
struct node{
	ll a,b,c,d,e,f;
}op[N];
ll x[N],y[N];
int main(){
	int n;
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>x[i]>>y[i];
	}
	int m,t;
	ll p;
	node now;
	cin>>m;
	op[0]={1,0,0,0,1,0};
	for (int i=1;i<=m;i++){
		cin>>t;
		now=op[i-1];
		if (t==1){
			op[i]={now.d,now.e,now.f,-now.a,-now.b,-now.c};
		}
		else if (t==2){
			op[i]={-now.d,-now.e,-now.f,now.a,now.b,now.c};
		}
		else if (t==3){
			cin>>p;
			op[i]={-now.a,-now.b,-now.c+2*p,now.d,now.e,now.f};
		}
		else{
			cin>>p;
			op[i]={now.a,now.b,now.c,-now.d,-now.e,2*p-now.f};
		}
	}
	int q,a,b;
	cin>>q;
	for (int i=1;i<=q;i++){
		cin>>a>>b;
		now=op[a];
		printf("%lld %lld\n",x[b]*now.a+y[b]*now.b+now.c,x[b]*now.d+y[b]*now.e+now.f);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N = 1005;
struct Union_Find_Set{
	int fa[N*N]; bool val[N*N];
	inline void init(){
		for (int i = 1; i <= 1000005; ++i) fa[i] = i,val[i] = 0;
	}
	inline int F(int x){
		return x == fa[x] ? x : (fa[x] = F(fa[x]));
	}
	inline void Merge(int x,int y){
		x = F(x),y = F(y); if (x == y) return;
		fa[x] = y,val[y] |= val[x];
	}
	inline void tag(int x){
		val[F(x)] = 1;
	}
}S;
int n,m;
char mp[N][N]; int id[N][N],cntid;

int solve(){
	int i,j; int ans = 0;
	cntid = 0,S.init();
	for (i = 1; i <= n; ++i) for (j = 1; j <= m; ++j) id[i][j] = 0;
	for (i = 1; i <= n; ++i){
		bool flag = 1; int lst = -1;
		for (j = 1; j <= m; ++j) if (mp[i][j] == '#'){
			flag = 0,id[i][j] = ++cntid;
			if (lst != -1) S.Merge(id[i][j],id[i][lst]);
			lst = j;
			if (i==1||j==1||i==n||j==m) S.tag(id[i][j]);
		}
		if (flag && i > 1 && i < n) ++ans;
	}
	for (j = 1; j <= m; ++j){
		int lst = -1;
		for (i = 1; i <= n; ++i) if (id[i][j]){
			if (lst != -1) S.Merge(id[i][j],lst);
			lst = id[i][j];
		}
	}
	for (i = 1; i <= cntid; ++i) if (i == S.F(i)){
		if (S.val[i]) ; else ++ans;
	}
	return ans;
}

int main(){
	int i,j;
	cin >> n >> m;
	for (i = 1; i <= n; ++i) cin >> mp[i] + 1;
	int ans1 = solve();
	swap(n,m);
	static char mp2[N][N];
	for (i = 1; i <= n; ++i) for (j = 1; j <= m; ++j) mp2[i][j] = mp[j][i];
	for (i = 1; i <= n; ++i) for (j = 1; j <= m; ++j) mp[i][j] = mp2[i][j];
	cout << min(ans1,solve()) << '\n';
	return 0;
}

#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<ll, ll>;
const ll MOD = 998244353;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {
	ll ans = 1;
	if (b < 0)return 1;
	else if (b % 2 == 0)return(pow(a * a, b / 2));
	else return (a * pow(a, b - 1));
}
ll modpow(ll x, ll n, ll mod) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (modpow((x * x) % mod, n / 2, mod) % mod);
	else
		return (x * modpow(x, n - 1, mod)) % mod;
}
template<typename T>
vector<T> primes(T n) {//primes[i]でiを割り切る最初の素数を返す
	vector<T> spf(n + 1);
	for (int i = 0; i <= n; i++) spf[i] = i;
	for (T i = 2; i * i <= n; i++) {
		if (spf[i] == i) {
			for (T j = i * i; j <= n; j += i) {
				if (spf[j] == j) {
					spf[j] = i;
				}
			}
		}
	}
	return spf;
}
void solveA() {
	int v, t, s, d; cin >> v >> t >> s >> d;
	if (v * t <= d && d <= v * s)cout << "No" << endl;
	else cout << "Yes" << endl;
}
void solveB() {
	int n, x; cin >> n >> x;
	vector<int>a(n);
	rip(i, n)cin >> a[i];
	rip(i, n) {
		if (a[i] != x)cout << a[i] << endl;
	}
}
void solveC() {
	int h, w; cin >> h >> w;
	vector<string>s(h);
	rip(i, h)cin >> s[i];
	ll sum = 0;
	rip(i, h) {
		rip(j, w) {
			if (s[i][j] == '#') {
				int count = 0;
				if (s[i + 1][j] == '#')count++;
				if (s[i - 1][j] == '#')count++;
				if (s[i][j + 1] == '#')count++;
				if (s[i][j - 1] == '#')count++;
				sum += 4 - count;
			}
		}
	}
	cout << sum << endl;
}
void solveD() {
	ll n; cin >> n;
	//正のみで考えて弐倍すればok
	int count = 0;
	for (int i = 1; (ll)i * i + i <= 2 * n; i++) {
		if ((2 * n) % i == 0 && ((2 * n / i) + 1 - i) % 2 == 0) {
			count += 2;
		}
	}
	cout << count << endl;
}
void solveE() {
	int n, m; cin >> n >> m;
	vector<int>a(m); vector<int>b(m);
	rip(i, m)cin >> a[i] >> b[i];
	int k; cin >> k;
	vector<int>c(k);
	rip(i, k)cin >> c[i];

}
void solveF() {
}
int main() {
	solveA();
}


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

int main()
{
    ll n;
    cin >> n;
    ll m = n;
    ll b2 = 1;
    ll ans = 1e18+1;
    for(int b = 0;b2<=n;b++){
        ll a = n/b2;
        ll c = n%b2;
        ans = min(ans,a+b+c);
        b2 *= 2;
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    long long n;
    cin >> n;
    long long sum=n;
    long long a=n,b=0,c=0;
    long long count2=1;
    while(a>1) {
        if(a%2==0) {
            b++;
            a/=2;
            count2*=2;
        }
        else {
            c=c+count2;
            a-=1;
        }

        if(sum>=a+b+c) {
            sum=a+b+c;
        }
    }

    cout << sum << endl;
}


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

using ll = long long;
#define sz(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define rep(x) for (int ii = 0; ii < x; ii++)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, vector<int>> M;
  rep(n) {
    int x, id;
    cin >> x >> id;
    M[id].push_back(x);
  }

  for (const auto& [k, v] : M) sort(all(M[k]));

  ll ans = 0;
  vector<int> keys;
  for (const auto& [k, v] : M) {
    keys.push_back(k);
    for (int i = 1; i < sz(v); i++) {
      ans += v[i] - v[i - 1];
    }
  }

  int m = sz(M);

  vector<vector<ll>> dp(m, vector<ll>(2, 0));
  dp[0][0] = abs(M[keys[0]][0]);
  dp[0][1] = abs(M[keys[0]].back());
  for (int i = 1; i < m; i++) {
    int k = keys[i];
    dp[i][0] = min(
        dp[i - 1][0] + abs(M[k][0] - M[keys[i - 1]].back()),
        dp[i - 1][1] + abs(M[k][0] - M[keys[i - 1]][0]));
    dp[i][1] =
        min(dp[i - 1][0] +
                abs(M[k].back() - M[keys[i - 1]].back()),
            dp[i - 1][1] +
                abs(M[k].back() - M[keys[i - 1]][0]));
  }
  ans += min(dp[m - 1][0] + abs(M[keys.back()].back()),
             dp[m - 1][1] + abs(M[keys.back()][0]));

  cout << ans;
}

#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <sstream>
#include <ostream>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <iomanip>
#include <set>
#include <bitset>
//#include<unordered_map>
#define INT_MINs -2000000000
#define INT_MAXs 1000000001
#define MID int mid=(l+r)/2
#define REP1(i,x,y) for(int i=x;i<y;i++)
#define REP2(i,x,y) for(int i=x;i<=y;i++)
#define ls (2*k)
#define rs (2*k+1)
#define lson l,mid,2*k
#define rson mid+1,r,2*k+1
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define IOS ios::sync_with_stdio(0);cin.tie(NULL);
#define pb(a) push_back(a)
#define pi acos(-1)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=1e9+7;
const ll ba=131;
//ll qk(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x;y>>=1;x=x*x;}return ans;}
const int dx[8] = { 0,-1,0,1,-1,-1,1,1}, dy[8] = { -1,0,1,0,-1,1,-1,1};
const int dxx[8]= {2,1,-1,-2,-2,-1, 1, 2},dyy[8]= {1,2,2,1, -1,-2,-2,-1};
ll n;
ll a[200005],b[200005],l[200005],r[200005];
ll dp[200005][2];
void solve(){
     cin>>n;
     ll maxx=0,minn=INF;
     for(int i=1;i<=200000;i++){
        r[i]=-INF;
        l[i]=INF;
     }
     for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        l[b[i]]=min(l[b[i]],a[i]);
        r[b[i]]=max(r[b[i]],a[i]);
        //cout<<l[b[i]]<<' '<<r[b[i]]<<' '<<1111<<endl;
        minn=min(minn,b[i]);
        maxx=max(maxx,b[i]);
     }

     ll sum1=0,sum2=0;
     l[minn-1]=r[minn-1]=0;
     for(int i=minn;i<=maxx;i++){
        if(r[i]==-INF) { l[i]=l[i-1],r[i]=r[i-1],dp[i][0]=dp[i-1][0],dp[i][1]=dp[i-1][1];continue;}
        dp[i][0]=min(dp[i-1][0]+r[i]-l[i]+abs(l[i-1]-r[i]),dp[i-1][1]+r[i]-l[i]+abs(r[i-1]-r[i]));
        dp[i][1]=min(dp[i-1][0]+r[i]-l[i]+abs(l[i-1]-l[i]),dp[i-1][1]+r[i]-l[i]+abs(r[i-1]-l[i]));
     }
     cout<<min(dp[maxx][0]+abs(l[maxx]),dp[maxx][1]+abs(r[maxx]))<<endl;
}

int main(){
    IOS;
    solve();
    return 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using PL = pair<ll,ll>;
using PPL = pair<pair<ll,ll>,ll>;
#define INF 1000000000
#define INFLL 1000000000000000000
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i, n, s) for (int i = (int)(n); i >= (int)(s); i--)
#define mp make_pair
#define tp make_tuple
#define ALL(vec) vec.begin(), vec.end()
ll mod = 1000000007;
ll mod2 = 998244353;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ld a,b;cin>>a>>b;
    cout<<(a-b)/a*100<<endl;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  double c=(a-b)*100.0/a;
  cout<<fixed<<setprecision(3)<<c<<endl;
}


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

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
const int mod = 1e9 + 7;
const ll INF = 3e18;
const double EPSILON = 1e-9;
const int N = 2e6+5;
int main(){
    fastio;
    int n;
    cin >> n;
    double ans = 0;
    for(int i = n-1; i >= 1; i--){
        ans += (double)n/(double)i;
    }
    cout << fixed << setprecision(9) << ans << '\n';
    return 0;
}
// DOES IT HAVE OVERFLOW ?
// DOES IT HAVE INVALID MEMO ACESS ?

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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pf push_front
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
typedef map<int,int> mii;

const int MOD = 1e9+7;
const ld PI = acos((ld)-1);

void solve () {
	int x;
	cin >> x;
	if (x < 0) {
		cout << 0 << '\n';
	} else {
		cout << x << '\n';
	}
}

int main () {

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

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


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

int main() {
int x, y;
  cin >> x >> y;
  vector<vector<int>> cyancheck(51, vector<int>(51));
  cyancheck.at(x).at(y) = 1;
  int k = 2;
  vector<vector<int>> cyanmond(51, vector<int>(51));
    for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 50; j++) {
      cin >> cyanmond.at(i).at(j);
      if(!(j == 0)){
      if(cyanmond.at(i).at(j) == cyanmond.at(i).at(j - 1)){
        cyancheck.at(i).at(j) = k;
        cyancheck.at(i).at(j - 1) = k;
        k++;
      }
      }
      if(!(i == 0)){
      if(cyanmond.at(i).at(j) == cyanmond.at(i - 1).at(j)){
        cyancheck.at(i).at(j) = k;
        cyancheck.at(i - 1).at(j) = k;
        k++;
      }
      }

    }
  }

  if(x > 25 && y < 25){
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x - 1).at(y)) && !(cyancheck.at(x - 1).at(y) == 1)){
      cout << "U";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x - 1).at(y) = 1;
      x = x - 1;}
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y + 1)) && !(cyancheck.at(x).at(y + 1) == 1)){
      cout << "R";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x).at(y + 1) = 1;
      y = y + 1;
    }
    }
    if(x <= 25 && y < 25){
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x + 1).at(y)) && !(cyancheck.at(x + 1).at(y) == 1)){
      cout << "D";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x + 1).at(y) = 1;
      x = x + 1;}
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y + 1)) && !(cyancheck.at(x).at(y + 1) == 1)){
      cout << "R";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x).at(y + 1) = 1;
      y = y + 1;
    }
    }

    if(x > 25 && y >= 25){
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x - 1).at(y)) && !(cyancheck.at(x - 1).at(y) = 1)){
      cout << "U";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x - 1).at(y) = 1;
      x = x - 1;}
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y - 1)) && !(cyancheck.at(x).at(y - 1) == 1)){
      cout << "L";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x).at(y + 1) = 1;
      y = y + 1;
    }
    }
       if(x <= 25 && y >= 25){
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x + 1).at(y)) && !(cyancheck.at(x + 1).at(y) == 1)){
      cout << "D";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x + 1).at(y) = 1;
      x = x + 1;}
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y - 1)) && !(cyancheck.at(x).at(y - 1) == 1)){
      cout << "L";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x).at(y - 1) = 1;
      y = y - 1;
    }
    }

}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int beamwidth = 300;
const double TL=1.9;
double start;

int n=50;
int sx, sy;
VVI t(n,VI(n));
VVI p(n,VI(n));

struct status{
    int x;
    int y;
    int score;
    int eval;
    VI path;
    VI used;
    bool operator<(const status &another) const {return eval < another.eval;};
};

vector<status> search(const status &base){
    vector<status> res;
    REP(i,4){
        int tox=base.x+dx[i];
        int toy=base.y+dy[i];
        if(tox<0||tox>=n||toy<0||toy>=n)
            continue;
        if(base.used[t[tox][toy]])
            continue;
        int anotp=p[tox][toy];
        REP(j,4){
            int toox=tox+dx[j];
            int tooy=toy+dy[j];
            if(toox<0||toox>=n||tooy<0||tooy>=n)
                continue;
            if(t[tox][toy]==t[toox][tooy]){
                anotp=p[toox][tooy];
                break;
            }
        }
        int newscore=base.score+p[tox][toy]+max(0,p[tox][toy]-anotp);
        int dlx=min(tox,49-tox), dly=min(toy,49-toy);
        int neweval=newscore-(3*(dlx+dly)+min(dlx,dly))*100;
        res.push_back((status){tox,toy,newscore,neweval,base.path,base.used});
        res[res.size()-1].used[t[tox][toy]]=1;
        res[res.size()-1].path.push_back(i);
    }
    return res;
}

int main(){
    start=clock();
    cin >> sx >> sy;
    int maxt=0;
    REP(i,n)REP(j,n){
        cin >> t[i][j];
        maxt=max(maxt,t[i][j]);
    }
    REP(i,n)REP(j,n) cin >> p[i][j];
    priority_queue<status> que;
    VI initused(maxt+1,0); initused[t[sx][sy]]=1;
    que.push({sx,sy,p[sx][sy],0,VI(0),initused});
    int maxscore=0; VI ans;
    while(1){
        priority_queue<status> nxtque;
        VVI mxs(n,VI(n,0));
        while(nxtque.size()<beamwidth){
            if(que.empty())
                break;
            if(que.top().score>maxscore){
                maxscore=que.top().score;
                ans=que.top().path;
            }
            vector<status> res=search(que.top());
            for(auto j:res){
                if(mxs[j.x][j.y]<10){
                    mxs[j.x][j.y]++;
                    nxtque.push(j);
                }
            }
            que.pop();
        }
        que=nxtque;
        double tim=(double)(clock()-start)/CLOCKS_PER_SEC/TL;
        if(tim>=1.0||que.empty())
            break;
    }
    string dir="DRUL";
    for(auto i:ans)
        cout << dir[i];
    cout << endl;
    return 0;
}