#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
typedef vector<int> vi;
using ll = long long;
typedef pair<int, int> pii;
typedef unsigned long long ul;

const int mn = 3005;
const int mod = 998244353;

int n, K;
ll d[mn][mn];

ll dp(int remain_number, int need_cnt) {
	ll &ans = d[remain_number][need_cnt];
	if (remain_number < need_cnt) return 0;
	if (ans != -1) return ans;
	if (remain_number == 0 && need_cnt == 0) return ans = 1;
	ans = 0;
	if (need_cnt == 0 || remain_number == 0) return ans = 0;
	// get_one
	assert(remain_number >= 0 && need_cnt >= 0);
	ans = dp(remain_number - 1, need_cnt - 1);
	// get_small_one
	ans += dp(remain_number, need_cnt * 2);
	ans %= mod;
	//printf("%d %d %lld\n", remain_number, need_cnt, ans);
	return ans;
}

int main() {
	//cin.sync_with_stdio(0);
#ifdef LOCAL
	freopen("../1.txt", "r", stdin);
	//freopen("../2.txt", "w", stdout);

	auto st = chrono::system_clock::now();
#endif

	memset(d, -1, sizeof d);

	scanf("%d%d", &n, &K);
	printf("%lld\n", dp(n, K));

#ifdef LOCAL
	auto ed = chrono::system_clock::now();
	auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(ed - st);
	std::cerr << "cost time " << diff.count() << "ms." << std::endl;
#endif
	return 0;
}

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using db = double;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
  o << "(" << v.first << "," << v.second << ")";
  return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

struct E {
  int l = INT32_MAX, h = INT32_MIN;
};

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  v(E) es(N);
  F0R(i, N) {
    int x, c; cin >> x >> c;
    c--;
    chmin(es[c].l, x);
    chmax(es[c].h, x);
  }
  ll lx = 0, lt = 0;
  ll rx = 0, rt = 0;
  F0R(c, N) {
    auto [l, r] = es[c];
    if (l == INT32_MAX) continue;
    ll rx2 = es[c].h, lx2 = es[c].l;
    ll rt2 = min(lt + abs(lx - l) + abs(l - r), rt + abs(rx - l) + abs(l - r));
    ll lt2 = min(lt + abs(lx - r) + abs(r - l), rt + abs(rx - r) + abs(r - l));

    lx = lx2; rx = rx2;
    lt = lt2; rt = rt2;
  }
  cout << min(lt+abs(lx), rt+abs(rx)) << newl;
}
#endif


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define vl vector<ll>
#define vi vector<int>
using namespace std;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

void solve(){
	ll n;cin>>n;
	ll len=0,t=n;
	vector<ll> v;
	while(t){
		len++;
		v.pb(t%10);t/=10;
	}
	reverse(all(v));
	ll ans=0;
	for(int i=2;i<=len;i+=2){
		ll cur=1;
		if(i!=len){
			for(int j=0;j<i/2;j++){
			if(j==0) cur*=9;
			else cur*=10;
		  }
		}else{
			for(int j=0;j<i/2;j++){
			if(j==0) cur*=(v[j]-1);
			else cur*=10;
		  }
		  ll end=1;
		  for(int k=1;k<i/2;k++){
		  	end*=v[k];
		  	for(int l=k+1;l<i/2;l++) end*=10;
		  	cur+=end;
		  	end=1;
		  }
		  ll num=0;
		  int j=len;
		  for(int l=1;l<=2;l++){
		  	for(int k=0;k<i/2;k++){

		  		num+=v[k]*pow(10,j-1);j--;
		   }
		  }
		  if(num<=n) cur++;

		}

		ans+=cur;
	}
	cout<<ans<<endl;

}

int main(){

		fast;
	    int T;
	    T=1;
	    //cin>>T;
	  	while(T--){
	  		//for(int i=1;i<=T;i++){
	  			//cout<<"Case #"<<i<<": ";
	 			solve();
	 		 }
	 return 0;

}

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

long long n;
long long x1;
int ans = 1;
string s;

int main()
{
    cin >> n;

    long long x = 1;
    int count = 0;
    long long x1 =0;

    while(x1<=n){
        s = to_string(x);
        x1 = stoll(s+s);
        x++;
    }

    cout << x-2;

         return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) <<
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
int main()
{
	ll n,j;
	ll c=1;
	cin >> n;
	vec a(n);
	REP(i,0,n){
		cin >> a[i];
	}
	// std::unique(a.begin(), a.end());
	std::sort(a.begin(), a.end());
	// a.erase(std::unique(a.begin(), a.end()), a.end());
	j = n * (n-1) /2;
	REP(i,0,n-1){
		// PR(a[i]);
		if (a[i] == a[i+1]){
			c++;
			if (i + 2 == n){
			j -= c * (c-1)/2;
			}
		} else if(a[i] != a[i+1]){
			// PR("false");
			// PR(i);
			// PR("DEL");
			// PR(c * (c-1)/2);
			j -= c * (c-1)/2;
			c = 1;
		}

	}
	PR(j);

	return 0;

}

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

vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

int main()
{
  ll N;
  cin >> N;
  vector<long long> div = enum_divisors(N*2);
  //(m+n)(m-n+1) = 2N
  ll cnt = 0;
  for(const auto& i : div){
  	//cout << i << " " << (N*2/i) << " " << (i&1) << " " << ((N*2/i)&1) << "\n";
  	if(((N*2/i)&1) != (i&1)) cnt++;
  }
  cout << cnt;
  return 0;
}


#include <iostream>
using namespace std;

using ll = long long;
constexpr ll INFll = (ll)1e18 + 1;

ll Power(int a, int b) {
    ll ret = 1;
    while(b--) {
        if(INFll / ret < a) {
            ret = INFll;
            break;
        }
        ret *= a;
    }

    return ret;
}

int main() {

    ll n; cin >> n;
    for(int i = 1; i < 100; ++i) {
        for(int j = 1; j < 100; ++j) {
            if(Power(3, i) + Power(5, j) == n) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
void __print(int x){cout<<x;}void __print(long x){cout<<x;}
void __print(long long x){cout<<x;}void __print(unsigned x){cout<<x;}
void __print(unsigned long x){cout<<x;}void __print(unsigned long long x){cout<<x;}
void __print(float x){cout<<x;}void __print(double x){cout<<x;}
void __print(long double x){cout<<x;}void __print(char x){cout<<'\''<<x<<'\'';}
void __print(const char *x){cout<<'\"'<<x<<'\"';}void __print(const string &x){cout<<'\"'<<x<<'\"';}
void __print(bool x) {cout<<(x?"true":"false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define lp(i,a,b)       for (int i=a;i<=b;i++)
#define rp(i,a,b)       for (int i=a;i>=b;i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           ((a)*(a))
#define sz(a)           (int) a.size()
#define mod             1000000007
#define PI              (2*acos(0.0))

void solve()
{
  int n;
  cin>>n;
  int cnt=3;
  while(cnt--)
  {
    string s;
    cin>>s;
  }
  cout<<string(n,'1')+string(n,'0')+'1';
  nl;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int T=1;
  cin>>T;
  while(T--) solve();
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define fore(i_in,a) for (auto& i_in: a)
#define forp(x,y,a) for(auto& [x, y]: a)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pq(T) priority_queue<T, vector<T>, greater<T>>
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<(int)v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;}
template<class T> void print(const T &t) { cout << t << "\n"; }

ll a, b, ans;

int main() {
    fio(); cin>>a>>b;
    ll pos_min =  a - b/2;
    ll neg_min = -a - (b-1)/2;
    ll pos_max =  a + (b-2)/2;
    ll neg_max = -a + (b-1)/2;
    if(neg_max < pos_min or pos_max < neg_min) ans = (neg_max - neg_min + 1) + (pos_max - pos_min + 1);
    else ans = max(neg_max, pos_max) - min(pos_min, neg_min) + 1;
    print(ans);
}


/*
* @author:  codancer
* @createTime:  2020-10-17, 21:33:55
*/

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

typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
#define deb(x) cerr<<#x<<" = "<<(x)<<"\n"
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll B) {
	return (ull)rng() % B;
}

const int N = 20;

struct Point{
	ll x,y,z;
}p[N];
ll dis(Point a,Point b){
	return abs(a.x-b.x)+abs(a.y-b.y)+max(0LL,b.z-a.z);
}
ll dp[1<<17][17];//the ans of dp[status][last]
int main(){
	for(int i=0;i<(1<<17);i++){
		for(int j=0;j<17;j++) dp[i][j]=1e18;
	}
	dp[1][0]=0;
	int n;
	cin>>n;
	rep(i,0,n-1){
		cin>>p[i].x>>p[i].y>>p[i].z;
	}

	for(int i=1;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				for(int k=0;k<n;k++){
					if(!((i>>k)&1)){
						int nxt=(i|(1<<k));
						dp[nxt][k]=min(dp[nxt][k],dp[i][j]-dis(p[j],p[0])+dis(p[j],p[k])+dis(p[k],p[0]));
					}
				}
			}
		}
	}

	ll ans=1e18;
	for(int i=0;i<n;i++) ans=min(ans,dp[(1<<n)-1][i]);
	cout<<ans<<endl;

	return 0;
}

#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h>
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
constexpr ll INF = 1e18;
constexpr ll LLMAX = 9223372036854775807;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
// constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> x(N),y(N),z(N);
  for(int i=0; i<N; i++){
    cin >> x[i] >> y[i] >> z[i];
  }
  vector<vector<int>> dp(N,vector<int>(1LL<<N,inf));
  dp[0][0] = 0;
  for(int bit=0; bit<(1LL<<N); bit++){
    for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
        chmin(dp[j][bit | (1LL<<j)],dp[i][bit] + abs(x[i]-x[j])+abs(y[i]-y[j])+max(0,z[j]-z[i]));
      }
    }
  }
  cout << dp[0][(1LL<<N)-1] << "\n";
  return 0;
}


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

int main(){
	int N,A;
  cin >> N;
  vector<int> vec,vec2;
  for(int i = 0;i<N;i++){
    cin >> A;
  	vec.push_back(A);
    vec2.push_back(A);
  }
  sort(vec2.begin(), vec2.end());
  int min = vec2.at(0);
  //cout << min << endl;
  int max = min * N;
  for(int i = 0;i < N;i++){
  	if(min < vec2.at(i)){
    	min = vec2.at(i);
      //cout << min << endl;
    }else{continue;}
    int cnt=0,cntmax=0;
    for(int j = 0;j < N;j++){

    	if(min <= vec.at(j)){
        	cnt++;
          if(cntmax < cnt){
              cntmax=cnt;
              //cout << cnt << endl;
            }
        }else{
        	if(cntmax < cnt){
              cntmax=cnt;
              //cout << cnt << endl;
            }
          //cout << cnt << endl;
          cnt = 0;
        }
    }
    if(max < cntmax*min)
    	max = cntmax*min;
  }
  cout << max << endl;
  return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

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

int main()
{

	fio;
	ll t,n,i,j,d,x,a,b;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
	ll pref1[n],pref2[n];
	stack<ll>s;
	for(i=0;i<n;i++)
	{
		while(!s.empty()&&arr[s.top()]>=arr[i])
		s.pop();
		if(s.empty())
		{
			pref1[i]=-1;
		}
		else
		pref1[i]=s.top();
		s.push(i);

	}
	while(!s.empty())
	s.pop();
	for(i=n-1;i>=0;i--)
	{
			while(!s.empty()&&arr[s.top()]>=arr[i])
		s.pop();
		if(s.empty())
		{
			pref2[i]=n;
		}
		else
		pref2[i]=s.top();
		s.push(i);

	}
	ll ans=0;
	for(i=0;i<n;i++)
	{
		ll noe=(i-pref1[i])+(pref2[i]-i);
		noe-=1;
		ans=max(ans,arr[i]*noe);

	}
	cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define drep(i,a,b) for (int i=(b); i>=(a); i--)
#define erep(e,u) for (int e=Head[u]; e; e=Next[e])
#define arep(i,A) for (auto i : A)
#define push_back pb
#define print(x,c) printf ("%d%c", x, c);
typedef long long ll;
typedef pair <int, int> pii;
const int N = 2e5 + 5;
int K, n, F[233], cnt[N], dp[N][17], ans; char s[N]; bitset <16> f[N];
inline int PLUS(int x, int y) {
	x += y;
	return x >= MOD ? x - MOD : x;
}
inline void readseq(int n, int *a) {
	rep (i, 1, n)
		scanf ("%d", a + i);
}
int main() {
	for (int i=0; i<=9; i++)
		F['0'+i] = i;
	for (int i='A'; i<='F'; i++)
		F[i] = i - 'A' + 10;
	scanf ("%s%d", s+1, &K), n = strlen(s + 1);
	for (int i=1; i<=n; i++)
		f[i] = f[i-1], f[i][F[s[i]]] = 1, cnt[i] = f[i]. count();
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=16; j++)
			dp[i][j] = (1ll * dp[i-1][j-1] * (16 - j + 1) + 1ll * dp[i-1][j] * j) % MOD;
		for (int j=i==1?1:0; j<F[s[i]]; j++)
			dp[i][cnt[i-1]+1-(bool)f[i-1][j]] = PLUS(dp[i][cnt[i-1]+1-(bool)f[i-1][j]], 1);
		if (i > 1)
			dp[i][1] = PLUS(dp[i][1], 15);
	} ans = PLUS(dp[n][K], (cnt[n] == K));
	return cout << ans << endl, 0;
}

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
string num;
int rn[200005];
int k;
int n;
int dp[200005][20];
ll dfs(int x,ll now,bool zero,bool flag)
{
    int cnt=0;
    for(int i=0;i<16;i++)
    {
        if(now&(1<<i))cnt++;
    }
    if(x>=n)return cnt==k;
    if(cnt>k)return 0;
    if(!flag&&zero&&dp[x][cnt]!=-1)return dp[x][cnt];
    ll ans=0;
    int lim=flag?rn[x]:15;
    for(int i=0;i<=lim;i++)
    {
        int tmp;
        if(!zero&&i==0)tmp=now;
        else tmp=now|(1<<i);
        ans+=dfs(x+1,tmp,zero||(i!=0),flag&&(i==lim));
        ans%=mod;
    }
    if(!flag&&zero)dp[x][cnt]=ans;
    return ans;
}
int main()
{
    cin>>num>>k;
    n=num.size();
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)
    {
        if(num[i]>='0'&&num[i]<='9')rn[i]=num[i]-'0';
        else rn[i]=num[i]-'A'+10;
    }
    printf("%lld\n",dfs(0,0,0,1));
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

#pragma GCC target("popcnt")  //https://godbolt.org/z/yQv94Y

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

const ld pi = 4.0*atan(1.0);
#define xlr8 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); cout<<fixed

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// T.insert(a), T.erase(a), T.size()
// T.order_of_key(a) -- number of elements strictly less than a
// *T.find_by_order(k) -- k-th element in increasing order

struct Timer
{   chrono::time_point<chrono::high_resolution_clock> start , end; chrono:: duration<float> dur;
    Timer(){start = chrono::high_resolution_clock::now();}
    ~Timer(){   end = chrono::high_resolution_clock::now(); dur = end - start;  cout<<"\nTime Elapsed : " <<dur.count() << " s\n";  }
};

template<typename T>
void getVec(vector<T>& a , int st, int en)
{
    int dif = (en > st ? 1 : -1);
    for(int  i = st ; i!= en ; i+= dif)
        cin>>a[i];
}
template<typename T>
void getVecPair(vector<pair<T , T > >& a , int st, int en)
{
    int dif = (en > st ? 1 : -1);
    for(int  i = st ; i!= en ; i+= dif)
        cin>>a[i].first>>a[i].second;
}

//76149
template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template<typename... Args>
  Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
  }
};
template<typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, T val = T()) : vector<T>(n, val) {
  }
};

// const int MAX = 1000;
// Vec<2 , int > dp(MAX + 1, MAX + 1, -1);

ll gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

int main()
{
    xlr8;
    int testCases  = 1;
    cin>>testCases;
    while (testCases--)
    {
        ll n , s , k;
        cin>>n>>s>>k;
        s = n -s;
        ll d = __gcd(k , n);
        k/=d;
        n/=d;
        if(s%d!= 0)
            {
                cout<<"-1\n";
            }
        else
            {
                s/=d;
                ll x, y;
                ll g = gcd(k, n, x, y);
                if (g != 1)
                {
                    cout << "-1\n";
                }
                else
                {
                    x = (x % n + n) % n;
                    x = (x*s)%n;
                    cout << x <<"\n";
                }
            }

    }
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
#include <climits>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

const int mod = 1000000007;

ll T, n, a, b;

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> T;
	while (T--) {
		cin >> n >> a >> b;
		if (n < a + b) {
			cout << 0 << endl;
			continue;
		}
		if (a < b)swap(a, b);
		ll k = n - a + 1;
		ll p = n - a - b + 1;
		ll ans = (n - a + 1)*(n - a + 1) % mod*(n - b + 1) % mod*(n - b + 1) % mod;
		ll x = (2 * (b*(b - 1) / 2 + (k - b)*(b - 1)) + k * (a - b + 1)) % mod;
		ans = (ans - x * x%mod + mod) % mod;
		cout << ans << endl;
	}
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

class CMaxGCD2 {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int A, B;
        cin >> A >> B;
        int diff = B - A;
        int res = 0;
        FOR(i, 1, diff) {
            int n = (A - 1) / i * i + i;
            if (n + i > B) continue;
            res = i;
        }
        cout << res << endl;
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CMaxGCD2 solver;
    solver.solve(in, out);
    return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<cmath>
#include<iomanip>
#include<map>

using namespace std;

#define M 998244353
#define INF 1e18L

int main()
{
	int n, k;
	cin >> n >> k;
	vector<vector<long long>> t(n, vector<long long>(n));
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			cin >> t[i][j];

	vector<int> perm(n - 1);
	for(int i = 0; i < n - 1; i++)
		perm[i] = i + 1;

	int cnt = 0;

	do
	{
		long long cost = t[0][perm[0]];
		for(int i = 0; i < n - 2; i++)
		{
			cost = cost + t[perm[i]][perm[(i+1)]];
		}
		cost += t[perm[n-2]][0];
		if(cost == k)
			cnt++;

	}while(next_permutation(perm.begin(), perm.end()));
	cout << cnt << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SZ(x) ((int)(x).size())
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

const double PI = (acos(-1));

void solve(istream& cin, ostream& cout) {
  double n;
  cin >> n;
  double x0, y0, x1, y1;
  cin >> x0 >> y0 >> x1 >> y1;
  double X = (x0 + x1) / 2;
  double Y = (y0 + y1) / 2;
  double x2 = X + (x0 - X) * cos(2 * PI / n) - (y0 - Y) * sin(2 * PI / n);
  double y2 = Y + (x0 - X) * sin(2 * PI / n) + (y0 - Y) * cos(2 * PI / n);
  cout << x2 << " " << y2 << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif

    /* Great things never come from comfort zones,
    "whatever the mind of a man can conceive and believe,it can achieve." */

    #include <bits/stdc++.h>

   // #include <ext/pb_ds/assoc_container.hpp>
  //  #include <ext/pb_ds/tree_policy.hpp>

    using namespace std;

  //  using namespace __gnu_pbds;
  //  using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

    void my_dbg() { cout << endl; }
    template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
    { cout << ' ' << A; my_dbg(B...); }
    #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

    #define ll long long
    #define dd long double
    #define scf(n) scanf("%d",&n)
    #define lscf(n) scanf("%lld",&n)
    #define lpri(n) printf("%lld ",n)
    #define pri(n) printf("%d ",(int)n)
    #define prin(n) printf("%d\n",(int)n)
    #define lprin(n) printf("%lld\n",n)
    #define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
    #define show(a) for(auto xy: a) pri(xy); printf("\n");

    #define pb push_back
    #define mp make_pair
    #define F first
    #define S second
    #define all(x)     x.begin(),x.end()
    #define SET(a,b) memset(a,b,sizeof(a))
    #define tc   int tt; scf(tt); while(tt--)

    #define inf INT_MAX
    #define ninf INT_MIN
    #define gcd __gcd
    #define bitcount(n) __builtin_popcount(n)

    const int M=1e9+7;

    const int N = 1e5+7;

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

    int a,b,x,y;
    scf(a),scf(b),scf(x),scf(y);

    dd cx=0.5*(a+x);

    dd cy=(b+y)*(0.5);

    dd PI=3.141592653589793;

    dd ax=(a-cx)*cos(2*PI/n) - (b-cy)*sin(2*PI/n);
    dd ay=(a-cx)*sin(2*PI/n) + (b-cy)*cos(2*PI/n);

    printf("%.8Lf %.8Lf",(ax+cx) ,(ay+cy));

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c)
        cout<<a;
    else if(a==b)
        cout<<c;
    else if(b==c)
        cout<<a;
    else if(a==c)
    cout<<b;
    else
        cout<<"0";

}

#include <bits/stdc++.h>
#include <cmath>
#include <list>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define M1 1000000007
const double pi = 3.14159265;
#define ll long long
#define lld long double
#define frf(i,n) for(ll i=0;i<n;i++)
#define pb push_back
#define fi first
#define se second
#define incin(v, n)            \
    for (ll i = 0; i < n;i++){ \
        cin >> v[i];           \
    }
const int mx=1e5+5;

int main(){
     ll a,b,c;
     cin>>a>>b>>c;
     if(a==b && a!=c){cout<<c;}
     else if(a==c && a!=b){cout<<b;}
     else if(c==b && a!=c){cout<<a;}
     else if(a==c && a==b){cout<<a;}
     else{cout<<0;}
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using vb = vector<bool>;
using ll = long long; //約9.0*10^18
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
using std::reverse;
const double PI=3.14159265358979323846;
const ll inf=9223372036854775807;

#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll fac(ll n) {ll ans=1;rep0(i,n){ans=ans*(n-i);};return ans;}//n!
ll conb(ll n,ll m){return fac(n)/fac(m)/fac(n-m);}//nCm

//小数点以下を指定したい時　　→→→→  cout << fixed << setprecision();
//int→string　　string str = to_string(num);
//string→int   int num = atoi(numStr.c_str());
//複数のvector管理→;vector<tuple<string, int, int>> SP(N);
//int max = *max_element(all(A));最大値
//int min = *min_element(all(B));最小値
//floor(x)=[x]
// *max_element(a.begin(),a.begin()+5);aの最初から6番目までの最大値/計算量に不安あり
// *min_element(,);
// sort は昇順１２３４５
//ll n;cin>>n;vll a(n);rep0(i,n){cin>>a[i];}

int main() {
   ll n;cin>>n;vll a(n);rep0(i,n){cin>>a[i];}
   sort(all(a));
   string flag ="Yes";
   rep0(i,n){
       if(a[i]!=i+1){
           flag="No";
       }
   }
   cout<<flag<<endl;
   return 0;
}

#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n;
	cin >> n;
	bool b = true;
	vector<int>vec(n);
	fill(vec.begin(), vec.end(), 0);
	for (int i = 0; i < n; i++) {
		int m;
		cin >> m;
		if (vec[m-1]==0) {
			vec[m-1] = 1;
		}
		else {
			b = false;
			break;
		}
	}
	if (b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()

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

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

    vll dp(4, vl(3 * N + 2, 0));
    dp[0][0] = 1;

    rep(i, 3) {
        rep(j, i * N + 1) {
            dp[i + 1][j + 1] += dp[i][j];
            dp[i + 1][j + N + 1] -= dp[i][j];
        }
        rep(j, (i + 1) * N) {
            dp[i + 1][j + 1] += dp[i + 1][j];
        }
    }
    int X;
    for (int i = 3; i <= 3 * N; ++i) {
        if (K > dp[3][i]) {
            K -= dp[3][i];
        }
        else {
            X = i;
            break;
        }
    }
    int ia, ja, ka;
    for (int i = 1; i <= N; ++i) {
        int jmin = max(1, X - N - i);
        int jmax = min(N, X - 1 - i);
        if (jmin > jmax) continue;
        if (K <= jmax - jmin + 1) {
            ia = i;
            ja = jmin + K - 1;
            ka = X - ia - ja;
            break;
        }
        else {
            K -= jmax - jmin + 1;
        }
    }

    cout << ia << ' ' << ja << ' ' << ka << endl;
}

#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr ll INF = 1LL << 30;
constexpr ll mod = 100000; //(ll)1e9 + 7;
constexpr double PI = 3.1415926535897932;

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

Graph G;

//探索順をdfs1で求める
vector<bool>ok;
vector<int>path;
void dfs1(int v) {
    ok[v] = false;
    path.push_back(v);
    for (auto nv : G[v])if (ok[nv])dfs1(nv);
}

//pathをもとに塗れる色を全探索
vector<int>color;
int dfs(int l = 0) {
    if (l == path.size())return 1;
    int res = 0;

    vector<int>c(3, 0);
    //色を0,1,2で表現
    for (auto v : G[path[l]]) {
        if (color[v] == -1)continue;
        c[color[v]]++;
    }
    rep(i, 0, 3) {
        if (c[i] != 0)continue;
        color[path[l]] = i;
        res += dfs(l + 1);
        color[path[l]] = -1;
    }
    return res;
}

int main() {
    init();

    int N, M; cin >> N >> M;
    G.resize(N);
    ok.resize(N, true);
    color.resize(N, -1);
    rep(i, 0, M) {
        int a, b; cin >> a >> b;
        --a;--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ll ans = 1;
    rep(i, 0, N) {
        if (ok[i]) {
            path.clear();
            rep(j, 0, N)color[i] = -1;
            dfs1(i);
            ans *= dfs();
        }
    }
    cout << ans << "\n";

    return 0;
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#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 A[100001];
int tmp[100001];
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];
	}
}
const int mod = 1e9 + 7;

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

	int N = getint();
	rep1(i, N) A[i] = getint();
	pakuri_sort(N, A + 1);

	int kotae = 1;
	rep(i, N) {
		kotae = kotae * ll(A[i + 1] - A[i] + 1) % mod;
	}

	co(kotae);

	Would you please return 0;
}

#include <bits/stdc++.h>

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mkpr make_pair
#define fi(i,a,b) for (ll i=a;i<b;i++)
#define vll vector<ll>
#define vch vector<char>
#define vst vector<string>
#define vpll vector<pll>
#define vii vector<int>
#define vvl vector<vector<ll>>
#define all(v) v.begin(),v.end()
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define mxe(v) *max_element(v.begin(),v.end())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define mll map<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define nl "\n"
#define sp " "
#define sz(x)  (int)x.size()

using namespace std;

double PI = (acos(-1));
ll md = 1000000007;
//ll md = 998244353;
ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;}
ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;}
ll modinv(ll n){return pwmd(n, md - 2);}
ll nc2(ll n){return (1ll * n * (n - 1)) / 2;}
bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ceel(ll a,ll b){if(a%b==0) return a/b;else return a/b+1;}

#define MAX_SIZE 1000005
void Sieve(vector<int> &primes){bool IsPrime[MAX_SIZE];memset(IsPrime, true, sizeof(IsPrime));
for (int p = 2; p * p < MAX_SIZE; p++){if (IsPrime[p] == true){
            for (int i = p * p; i < MAX_SIZE; i += p)IsPrime[i] = false;}}
    for (int p = 2; p < MAX_SIZE; p++)if (IsPrime[p])primes.push_back(p);}

//vector<char> sml={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vector<char> cap={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

ll v[1100000];
ll query(ll node, ll start, ll end, ll l, ll r){
    if(r < start || end < l){
        return 0;
    }
    if(l <= start && end <= r){
        return v[node];
    }

    ll mid = (start + end) / 2;
    ll p1 = query(2*node, start, mid, l, r);
    ll p2 = query(2*node+1, mid+1, end, l, r);
    return (p1^p2);
}
void solve(){
    ll n,q;
    cin>>n>>q;
    ll l[n];
    fi(i,0,n)cin>>l[i];
    ll cnt=0,ind=0,x=n;
    fi(i,0,32){
        if((1ll<<i)&n)cnt++,ind=i;
    }
    if(cnt!=1){
        n=pw(2,ind+1);
    }

    for(int j=0;j<x;j++){
        v[n+j]=l[j];
    }
    fi(i,n+x,2*n){
        v[i]=1e9+5;
    }
    for(int i=n-1;i>0;i--){
        v[i]=(v[2*i]^v[(2*i)+1]);
    }
    fi(i,0,q){
        ll a,b,c;
        cin>>a>>b>>c;
        if(a==1){
            v[b+n-1]^=c;
            ll cur=(b+n-1)/2;
            while(cur>=1){
                v[cur]=(v[2*cur]^v[(2*cur)+1]);
                cur/=2;
            }
        }
        else{
            cout<<query(1,n,(2*n)-1,b+n-1,c+n-1)<<nl;
        }
    }

}

int main(){
    //vector<int> primes;
    //Sieve(primes);

    fast
    ll tests=1;
    //cin>>tests;
    while(tests--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e3+100;
const int P = 1e9+7;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

int a[N],b[N];
int n,m;

inline int pow_mod(int x,int k){
   int res = 1,base = x;
   while(k){
      if(k&1)res = 1LL*res*base%P;
      k >>= 1; base = 1LL*base*base%P;
   }
   return res;
}

inline int c(int x,int y){
   int ret = 1;
   nfr(i,y,1)ret = 1LL*ret*pow_mod(i,P-2)%P;
   nfr(i,x,x-y+1)ret = 1LL*ret*i%P;
   return ret;
}

int main(){
   scanf("%d%d",&n,&m);
   int sum = 0;
   fr(i,1,n){
      scanf("%d",a+i);
      sum += a[i];
   }
   printf("%d\n",c(m+n,sum+n));
   return 0;
}

#include <bits/stdc++.h>
using namespace std;
int gi() {
	int res = 0, w = 1;
	char ch = getchar();
	while (ch != '-' && !isdigit(ch)) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
	return res * w;
}
const int MAX_N = 4e5 + 5;
int N, a[MAX_N];
long long ans;
int main () {
#ifndef ONLINE_JUDGE
    freopen("cpp.in", "r", stdin);
#endif
	N = gi();
	for (int i = 1; i <= N << 1; i++) a[i] = gi();
	priority_queue<int, vector<int>, greater<int> > q;
	for (int i = 1; i <= N; i++)
		q.push(a[N - i + 1]), q.push(a[N + i]), q.pop();
	while (!q.empty()) ans += q.top(), q.pop();
	printf("%lld\n", ans);
    return 0;
}


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

const int M = 1e9+7;
ll mod(ll x){
    return (x%M + M)%M;
}

ll mul(ll a, ll b){
    return mod((mod(a)*mod(b)));
}

ll add(ll a , ll b){
    return mod(mod(a)+mod(b));
}

void solve(){
    string s;
    cin>>s;
    int ok=0;
    int maybe=0;
    for(auto i : s){
        if(i=='o') ok++;
        else if(i=='?') maybe++;
    }
    int total=0;
    for(int i=0;i<=9;i++){
        for(int j=0;j<=9;j++){
            for(int k=0;k<=9;k++){
                for(int l=0;l<=9;l++){
                    set<int>ss;
                    //i have to insure that that number of o's must have all the numbers
                    if(s[i]=='x' || s[j]=='x' || s[k]=='x' || s[l]=='x') continue;
                    if(s[i]=='o') ss.insert(i);
                    if(s[j]=='o') ss.insert(j);
                    if(s[k]=='o') ss.insert(k);
                    if(s[l]=='o') ss.insert(l);
                    if((int)ss.size()==ok) total++;
                }
            }
        }
    }
    cout<<total;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed;
    cout<<setprecision(10);
    int t=1;
    // cin>>t;
    for(int i=1;i<=t;i++){
        solve();
    }
    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

int main(){
   string s;
   cin>>s;

   int res=0;
   rep(num,0,10000){
      string key=to_string(num);
      while(key.size()<4)key.push_back('0');
      rep(d,0,10){
         if(s[d]=='o' and key.find((char)('0'+d))==string::npos){
            goto fail;
         }
         if(s[d]=='x' and key.find((char)('0'+d))!=string::npos){
            goto fail;
         }
      }
      res++;
      fail:;
   }
   cout<<res<<'\n';
   return 0;
}


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

#define cm (1 << 17)
char cn[cm], *ci = cn + cm, ct;

inline char getcha() {
	if (ci - cn == cm) {
		fread(cn, 1, cm, stdin);
		ci = cn;
	}
	return *ci++;
}

inline int getint() {
	int A = 0;
	while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	return A;
}

vector<int> p;

int get(int x) {
	return p[x] == x ? x : p[x] = get(p[x]);
}

int main() {
	int n = getint();
	constexpr int mx = 400010;
	p.resize(mx);
	iota(begin(p), end(p), 0);
	vector<int> cnt(mx);
	while (n--) {
		int a = getint(), b = getint();
		a = get(a), b = get(b);
		if (a != b) {
			p[b] = a;
			cnt[a] += cnt[b];
		}
		cnt[a]++;
	}
	vector<int> siz(mx);
	for (int i = 0; i < mx; i++) {
		siz[get(i)]++;
	}
	int ans = 0;
	for (int i = 0; i < mx; i++) {
		if (get(i) == i) {
			ans += min(cnt[i], siz[i]);
		}
	}
	printf("%d", ans);
}

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

#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) y = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s - 1; i >= e; i--)
typedef long long ll;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
#define MT make_tuple
typedef tuple<int, int, int> iii;

#define INF 1000000005
#define LINF 100000000000000005
#define MOD 1000000007
#define MAXN 200005
#define MAXA 400005

int n;
int in[MAXA];
vector<int> adjList[MAXA];
set<ii> st;
bool erased[MAXA];

int main() {
	scanf("%d", &n);
	REP (i, 0, n) {
		int a, b; scanf("%d%d", &a, &b);
		in[a]++;
		adjList[a].pb(b);
		if (a != b) {
			in[b]++;
			adjList[b].pb(a);
		}
	}
	REP (i, 1, MAXA) {
		if (in[i] == 0) continue;
		st.emplace(in[i], i);
	}
	int ans = 0;
	while (!st.empty()) {
		ii cur = *st.begin(); st.erase(st.begin());
		if (erased[cur.SE]) continue;
		for (int v : adjList[cur.SE]) {
			if (erased[v]) continue;
			st.erase(MP(in[v], v));
			in[v]--;
			if (in[v] > 0) st.emplace(MP(in[v], v));
			break;
		}
		erased[cur.SE] = true;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for(int i=0; i<N; i++)
    cin >> A.at(i);

  int64_t o=0, x, ans=INT64_MAX;
  for(int64_t bit=0; bit<(1<<N); bit++){
    bit |= 1<<(N-1);
    x = 0;
    for(int i=0; i<N; i++){
      o |= A.at(i);
      if(1 & (bit>>i)){
	x ^= o;
	o = 0;
      }
    }
    ans = min(ans, x);
  }
  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
#define P pair<ll,ll>
const ll mod = 998244353;
//const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
void YesNo(bool a){if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }

vector<ll> g[100100];
ll ans[100100];
ll seen[100100];
ll t[100100];
ll dfs(ll a){
  if(seen[a]==1){
    return ans[a];
  }
  ll ansi=1;
  seen[a]=1;
  t[a]=1;
  ll p1=0,p2=0;
  vector<ll> k;
  vector<ll> gu;
  for(auto e:g[a]){
    auto p=dfs(e);
    t[a]+=t[e];
    if((t[e])%2){
      k.push_back(p);
    }
    else{
      if(p<0){
        p1+=p;
      }
      else{
        p2+=p;
      }
    }
  }
  sor(k);
  ansi+=p1;
//  cout<<"ANS"<<" "<<a<<" "<<ansi<<endl;
  for(int i=0;i<int(k.size());i++){
 //   cout<<"K"<<" "<<k[i]<<endl;
    if((i)%2==0){
      ansi+=k[i];
    }
    else{
      ansi-=k[i];
    }
  }
  if(int(k.size())%2==0){
    ansi+=p2;
  }
  else{
    ansi-=p2;
  }
 // cout<<p1<<" "<<p2<<endl;
  return ans[a]=ansi;
}
int main() {
  /* mod は 1e9+7 */
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(10);
  ll a;
  cin>>a;
  for(int i=1;i<a;i++){
    ll x;
    cin>>x;
    x--;
    g[x].push_back(i);
  }
  for(int i=0;i<a;i++){
    seen[i]=0;
    t[i]=0;
  }
  dfs(0);
  for(int i=0;i<a;i++){
   // cout<<t[i]<<" "<<ans[i]<<endl;
  }
  cout<<(a+ans[0])/2<<endl;
}


#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << (x) << "\n"
using namespace std;
int n, x[300], y[300], R[300], xe[300], ye[300];
bool fb(int i, int j) {
	if (x[i] + xe[i] <= x[j])return 1;
	if (x[j] + xe[j] <= x[i])return 1;
	if (y[i] + ye[i] <= y[j])return 1;
	if (y[j] + ye[j] <= y[i])return 1;
	return 0;
}
bool fball(int i) {
	if (x[i] + xe[i] > 10000 || y[i] + ye[i] > 10000 || x[i] < 0 || y[i] < 0)return 0;
	for0(j, n) if (i != j && !fb(i, j))return 0;
	return 1;
}
signed main() {
	cin >> n;
	for0(i, n) {
		cin >> x[i] >> y[i] >> R[i]; xe[i] = 1; ye[i] = 1;
	}
	for0(i, n) {
		int l = 1, r = (int)sqrt(R[i]) + 1;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			xe[i] = mid; ye[i] = mid;
			if (fball(i))l = mid; else r = mid;
		}
		xe[i] = l; ye[i] = l;
	}
	for0(valsq, 1000)for0(i, n) if (xe[i] * ye[i] < R[i]) {
		if (x[i] + xe[i] < 10000 - 9) { xe[i] += 10; if (fball(i))continue; xe[i] -= 10; }
		if (y[i] + ye[i] < 10000 - 9) { ye[i] += 10; if (fball(i))continue; ye[i] -= 10; }
		if (x[i] + xe[i] < 10000) { xe[i]++; if (fball(i))continue; xe[i]--; }
		if (y[i] + ye[i] < 10000) { ye[i]++; if (fball(i))continue; ye[i]--; }
	}
	for0(valsq, 1000)for0(i, n) if (xe[i] * ye[i] < R[i]) {
		if (x[i] >= 10) { x[i] -= 10; xe[i] += 10; if (fball(i))continue; x[i] += 10; xe[i] -= 10; }
		if (y[i] >= 10) { y[i] -= 10; ye[i] += 10; if (fball(i))continue; y[i] += 10; ye[i] -= 10; }
		if (x[i] > 0) { x[i]--; xe[i]++; if (fball(i))continue; x[i]++; xe[i]--; }
		if (y[i] > 0) { y[i]--; ye[i]++; if (fball(i))continue; y[i]++; ye[i]--; }
	}
	for0(i, n)cout << x[i] << ' ' << y[i] << ' ' << x[i] + xe[i] << ' ' << y[i] + ye[i] << endl;
}

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

const int da[4] = {-1, 0, 0, 0};
const int db[4] = {0, -1, 0, 0};
const int dc[4] = {0, 0, 1, 0};
const int dd[4] = {0, 0, 0, 1};

const int D = 10000;

struct Str
{
    int s, r;
    int id;
    int dir;

    bool operator<(const Str &right)const{
        if(s * right.r != r * right.s) return s * right.r > r * right.s;
        if(s != right.s) return s < right.s;
        return id < right.id;
    }
};

bool safe(int x1, int y1, int x2, int y2, int i, int n, int *a, int *b, int *c, int *d){
    if(x1 < 0 || y1 < 0 || x2 > D || y2 > D) return false;
    for(int j = 0; j < n; j++){
        if(j == i) continue;
        bool f = (x1 <= a[j] && a[j] < x2) || (a[j] <= x1 && x1 < c[j]);
        bool g = (y1 <= b[j] && b[j] < y2) || (b[j] <= y1 && y1 < d[j]);
        if(f && g) return false;
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    int x[202], y[202], r[202];
    int a[202], b[202], c[202], d[202];
    Str str[202];
    priority_queue<Str> que;
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> r[i];
        a[i] = x[i], b[i] = y[i], c[i] = x[i] + 1, d[i] = y[i] + 1;
        str[i].s = 1, str[i].r = r[i], str[i].id = i, str[i].dir = 0;
        que.push(str[i]);
    }
    while(que.size()){
        int i = que.top().id;
        que.pop();
        for(int k = 0; k < 4; k++){
            int dir = (str[i].dir + k) % 4;
            int s = ((c[i] + dc[dir]) - (a[i] + da[dir])) * ((d[i] + dd[dir]) - (b[i] + db[dir]));
            if(s <= str[i].r &&
               safe(a[i] + da[dir], b[i] + db[dir], c[i] + dc[dir], d[i] + dd[dir], i, n, a, b, c, d)){
                str[i].s = s;
                str[i].dir = (dir + 1) % 4;
                a[i] += da[dir]; b[i] += db[dir]; c[i] += dc[dir]; d[i] += dd[dir];
                que.push(str[i]);
                break;
            }
        }
    }
    for(int i = 0; i < n; i++) cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl;
}


/*

   author : dunk_066

*/

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

void solve(){
  int n;
  cin>>n;
  if(n&1) cout<<"Black";
  else{
    cout<<"White";
  }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
	int t=1;//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

#define FREP(i,a,b) for(long long i=a;i<b;i++)
#define REP(i,n) FREP(i,0,n)
#define PB push_back
#define ll long long
#define MP make_pair
#define mod 1000000007
#define endl "\n"
#define vi vector<ll>
#define si set<ll>
#define mi map<ll,ll>
#define bs binary_search
#define pri(a,n) REP(i,n)cout<<a[i]<<" ";
#define all(x) x.begin(),x.end()
#define sz(a) (ll)a.size()
#define sa(a,n) sort(a,a+n)
#define sra(a,n) sort(a,a+n,greater<ll>())
#define sv(v) sort(all(v))
#define srv(v) sort(v.rbegin(),v.rend())
#define sp(x) fixed<<setprecision(x)
#define mem(a) memset(a,-1,sizeof(a))
#define ff first
#define ss second
#define deb(x) cout<<#x<<' '<<x<<endl;
#define FASTIO ios_base::sync_with_stdio(false);\
               cin.tie(NULL);\
               cout.tie(NULL);

void _a_b_c_d_e_f_g_h_i_j_k_l_m_n_o_p_q_r_s_t_u_v_w_x_y_z()
{
    ll n, k, q = 0, c = 0;
    string s;
    cin >> n;
    if (!(n & 1))
        cout << "White";
    else
        cout << "Black";
}

int main()
{
    FASTIO;
    int t = 1;
    // cin >> t;         // Test Case :-||-: //

    while (t--)
    {
        _a_b_c_d_e_f_g_h_i_j_k_l_m_n_o_p_q_r_s_t_u_v_w_x_y_z();
    }

    return 0;
}

// Thanks for stalking :P


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = n - 1; i >= 0; i--)

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

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

struct Timer {
  private:
    chrono::high_resolution_clock::time_point start, end;

  public:
    Timer() { set(); }
    void set() { start = chrono::high_resolution_clock::now(); }
    int time() {
        end = chrono::high_resolution_clock::now();
        return chrono::duration_cast<chrono::milliseconds>(end - start).count();
    }
    void print() { cerr << "elapsed time: " << (double)time() / 1000 << " sec" << endl; }
};

struct Random {
  private:
    uint32_t a, b, c, d;

  public:
    Random(uint32_t seed = 517) { set_seed(seed); }
    void set_seed(uint32_t seed) {
        a = seed = 1812433253u * (seed ^ (seed >> 30));
        b = seed = 1812433253u * (seed ^ (seed >> 30)) + 1;
        c = seed = 1812433253u * (seed ^ (seed >> 30)) + 2;
        d = seed = 1812433253u * (seed ^ (seed >> 30)) + 3;
    }
    uint32_t operator()() {
        uint32_t t = (a ^ (a << 11));
        a = b;
        b = c;
        c = d;
        return d = (d ^ (d >> 19)) ^ (t ^ (t >> 8));
    }

    // [0,MAX)
    uint32_t operator()(int MAX) { return (uint64_t) operator()() * MAX >> 32; }

    // [L,R)
    uint32_t operator()(int L, int R) { return L + operator()(R - L); }

    // [0,1) の実数
    double drnd() { return (double)operator()() / (1LL << 32); }

    // 確率 p で true を返す
    bool prob(const double p) { return (uint32_t)(p * (1LL << 32)) > operator()(); }
};

double TL = 3500;
double start_temp = 2.5, end_temp = 0;

int n;
int x[222], y[222], r[222];
int a[222], b[222], c[222], d[222];

void put_rectangle(int idx){
int ma = -1;
  int xl, xr, yl, yr;
  int lim1 = 100, lim2 = 10000;
  for (int xlen = lim1; xlen <= lim2; xlen += (lim2 - lim1) / 20){
    int lim3 = x[idx] + 1 - xlen, lim4 = x[idx] + xlen;
    for (xl = lim3; xl <= lim4; xl += max(1,(lim4 - lim3) / 20)){
      xr = xl + xlen;
      if(xl<0||xr>10000)
        continue;
      int ul, dl;
      int ok = 0, ng = 10001;
      while (ng - ok > 1){
        int nlen = (ok + ng) / 2;
        yl = y[idx] + 1 - nlen, yr = y[idx] + 1;
        int flag = 1;
        if(yl<0||yr>10000)
          flag = 0;
        rep(i,n) if (i != idx && a[i] < xr && c[i] > xl && b[i] < yr && d[i] > yl) flag = 0;
        if(flag)
          ok = nlen;
        else
          ng = nlen;
      }
      ul = ok;
      ok = 0, ng = 10001;
      while(ng - ok > 1){
        int nlen = (ok + ng) / 2;
        yl = y[idx], yr = y[idx] + nlen;
        int flag = 1;
        if(yl<0||yr>10000)
          flag = 0;
        rep(i,n) if (i != idx && a[i] < xr && c[i] > xl && b[i] < yr && d[i] > yl) flag = 0;
        if(flag)
          ok = nlen;
        else
          ng = nlen;
      }
      dl = ok;
      if(ul != 0){
        chmin(ul, r[idx] / xlen);
        chmin(dl, r[idx] / xlen + 1 - ul);
        if(chmax(ma, xlen * (ul + dl - 1))){
          yl = y[idx] + 1 - ul, yr = y[idx] + dl;
          a[idx] = xl, c[idx] = xr, b[idx] = yl, d[idx] = yr;
        }
      }
    }
  }
}

int main(){
  Timer T;
  Random rnd;
  cin >> n;
  rep(i, n) cin >> x[i] >> y[i] >> r[i];
  vector<pair<int, int>> v;
  rep(i, n) v.pb(mp(r[i], i));
  sort(all(v));
  int idx[n];
  rep(i, n) idx[i] = v[i].second;
  rep(i, n) a[i] = x[i], b[i] = y[i], c[i] = x[i] + 1, d[i] = y[i] + 1;
  rep(i, n) put_rectangle(idx[i]);
  rep(i, n) cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REP(i,k,n) for(ll i=k;i<ll(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end())
#define decimal cout<<fixed<<setprecision(10)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)
using ll=long long;
using P=pair<ll,ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
constexpr ll inf=1001001001001001;
constexpr int INF=1001001001;
constexpr int mod=998244353;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
void YesNo(bool b){if(b)out("Yes");else out("No");}
void yesno(bool b){if(b)out("yes");else out("no");}
void YESNO(bool b){if(b)out("YES");else out("NO");}
ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;}

int main(){
    ll n; cin>>n;
    vector<P> col(n+1,P(INF,-INF));
    ll m=0; //色の最大
    rep(i,n){
        ll x,c;
        cin>>x>>c;
        chmax(m,c);
        chmin(col[c].fi,x);
        chmax(col[c].se,x);
    }
    //outvp(col);
    //out(m);
    vvi dp(m+1,vi(2,0));
    col[0]=P(0,0);
    REP(i,1,m+1){
        if(col[i].fi==INF){
            dp[i]=dp[i-1];
            col[i]=col[i-1];
            continue;
        }
        ll ltol=dp[i-1][0]+abs(col[i].se-col[i-1].fi);
        ll ltor=dp[i-1][0]+abs(col[i].fi-col[i-1].fi);
        ll rtol=dp[i-1][1]+abs(col[i].se-col[i-1].se);
        ll rtor=dp[i-1][1]+abs(col[i].fi-col[i-1].se);
        ll get=abs(col[i].se-col[i].fi);
        dp[i][0]=min(ltol,rtol)+get;
        dp[i][1]=min(ltor,rtor)+get;
    }
    out(min(dp[m][0]+abs(col[m].fi),dp[m][1]+abs(col[m].se)));
    //outvv(dp);
}


#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define db double
#define rep(i,be,en) for(int i=be;i<=en;i++)
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
//const double pi=acos(-1);
const int mod=1e9+7;
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
using namespace std;
const int N=1e5+7;
const int M=1e6+7;

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

int T,n,m,fl;

signed main(){
	n=read();
	int x=1,a=0,b=0,c=0,ans,aa,bb,cc;
	a=n/x;
	ans=a;aa=a;bb=0;cc=0;
	while(x*2<=n){
		b++;
		x*=2;
		a=n/x;
		c=n%x;
		if(a+b+c<ans){
			ans=a+b+c;
			aa=a;bb=b;cc=c;
		}
	}

	printf("%lld\n",ans,aa,bb,cc);

}

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

int main() {
  long long n;
  cin>>n;
  long long ans =1000000000000000000;
  for(int i=0;i<61;i++){
    long long b=i;
    long long a=n/(1LL<<i);
    long long c=n-a*(1LL<<i);
    ans = min(ans,a+b+c);
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll mod = 1e9 + 7;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}
const int MAX_N = 1e6;

bool prm[MAX_N + 10];
vector<int> ps;

void prime(int N){
    for(int i = 2; i <= N; i++) prm[i] = true;
    for(int i = 2; i <= N; i++){
        if(prm[i]){
            ps.push_back(i);
            for(int j = i * 2; j <= N; j += i){
                prm[j] = false;
            }
        }
    }
}

template<class T>
vector<pair<T, int>> prime_fac(T N){
    vector<pair<T, int>> res;
    T cp = N;
    for(ll i = 0; i < (int)ps.size() && ps[i] * ps[i] <= cp; ++i){
        int cnt = 0;
        while(N % ps[i] == 0) N /= ps[i], cnt++;
        if(cnt != 0) res.push_back({ps[i], cnt});

    }
    if(N != 1) res.push_back({N, 1});
    return res;
}

ll fastpow(ll x, ll y) {
    if (y == 0) return 1;
    ll e = fastpow(x, y / 2);
    return e * e * (y & 1 ? x : 1);
}

vector<pii> fac[MAX_N + 10];

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int L, R;
    cin >> L >> R;
    prime(MAX_N);
    for (int i = 1; i <= MAX_N; i++) {
        fac[i] = prime_fac(i);
    }
    ll ans = 0;
    for (int i = 2; i <= R; i++) {
        int l = max((L - 1) / i + 1, 2);
        int r = R / i;
        if (r < 3) break;

        for (int j = l; j <= r; j++) {
            for (int k = 0; k < (1 << fac[j].size()); k++) {
                int fil = 1;
                int cnt = 0;
                for (int x = 0; x < fac[j].size(); x++) {
                    if ((k >> x) & 1) {
                        cnt++;
                        fil *= fac[j][x].first;
                    }
                }
                int num = (r / fil) - ((l - 1) / fil);
                if (cnt & 1) ans -= num;
                else ans += num;
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

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

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

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

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

ll mod_pow(ll a, ll n, ll p) {
    ll  ans = 1, tmp = a % p;
    while (n > 0) {
        if (n % 2)
            ans = ans * tmp % p;
        tmp = tmp * tmp % p;
        n /= 2;
    }
    return ans;
}

int main() {
    ll n, m;    cin >> n >> m;
    cout << mod_pow(10, n, m*m) / m << endl;
    return 0;
}

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


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

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 998244353;
using mint = Fp<MOD>;

int main(void)
{
    int H, W, K;
    cin >> H >> W >> K;

    vector<vector<char>> cmd(H, vector<char>(W, 's'));

    rep(i, K)
    {
        int h, w;
        char c;
        cin >> h >> w;
        cin >> c;
        --h;
        --w;
        cmd[h][w] = c;
    }

    vector<vector<mint>> cost(H, vector<mint>(W, 0));
    cost[0][0] = modpow(mint(3), H*W-K);

    rep(p, H)
    {
        rep(q, W)
        {
            if(p-1 >= 0)
            {
                int ok = 0;
                if(cmd[p-1][q] == 'X') ok = 3;
                else if(cmd[p-1][q] == 'D') ok = 3;
                else if(cmd[p-1][q] == 'R') ok = 0;
                else ok = 2;
                cost[p][q] += cost[p-1][q] * ok / 3;
            }
            if(q-1 >= 0)
            {
                int ok = 0;
                if(cmd[p][q-1] == 'X') ok = 3;
                else if(cmd[p][q-1] == 'R') ok = 3;
                else if(cmd[p][q-1] == 'D') ok = 0;
                else ok = 2;
                cost[p][q] += cost[p][q-1] * ok / 3;
            }
        }
    }

    cout << cost[H-1][W-1] << endl;

    return 0;
}

#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
// include
#include <bits/stdc++.h>
using namespace std;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
// change
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
// math
template <class T>
inline T sqr(T x) {
  return x * x;
}

template <class T>
inline T nCr(T n, T r) {
  T num = 1;
  for (int i = 1; i <= r; ++i) {
    num *= (n - i + 1) / i;
  }
  return num;
}
template <class T>
inline T nPr(T n, T r) {
  r = n - r;
  T sum = 1;
  int i;
  for (i = n; i >= r + 1; --i) sum *= i;
  return sum;
}

template <class T>
inline T facctorial(T k) {
  T sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
// numeric
template <class T>
inline T gcd(T a, T b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

template <class T>
inline T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
// using
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using PII = pair<int, int>;
using LL = int64_t;

// container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) static_cast<int>((a).size())
#define EACH(i, c) \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

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

// constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

struct Baggage {
  int weight;
  int value;
};

struct Box {
  int capacity;
  int num;
};

struct Query {
  int L;
  int R;
};

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

  int N, M, Q;
  cin >> N >> M >> Q;

  vector<Baggage> baggages(N);
  for (Baggage &baggage : baggages) {
    cin >> baggage.weight >> baggage.value;
  }
  sort(ALL(baggages), [](Baggage const &lhs, Baggage const &rhs) {
    if (lhs.value == rhs.value) {
      return lhs.weight < rhs.weight;
    }
    return lhs.value > rhs.value;
  });

  vector<Box> boxes(M);
  REP(i, M) {
    cin >> boxes[i].capacity;
    boxes[i].num = i;
  }
  sort(ALL(boxes), [](Box const &lhs, Box const &rhs) {
    return lhs.capacity < rhs.capacity;
  });
  vector<Query> queries(Q);
  for (Query &query : queries) {
    cin >> query.L >> query.R;
    --query.L;
    --query.R;
  }

  for (Query &query : queries) {
    vector<bool> can_put(M, true);
    int value_sum = 0;
    for (Baggage &baggage : baggages) {
      for (Box &box : boxes) {
        if (query.L <= box.num && box.num <= query.R) {
          continue;
        }
        if (can_put[box.num] && box.capacity >= baggage.weight) {
          can_put[box.num] = false;
          value_sum += baggage.value;
          break;
        }
      }
    }
    cout << value_sum << "\n";
  }

  return 0;
}


/*
 /+===================================================+\
//+---------------------------------------------------+\
|.|\...>>>>>>> Hollwo_Pelw's 2nd template<<<<<<<...//|.|
\+---------------------------------------------------+//
 \+===================================================+/
*/
#include <bits/stdc++.h>
using namespace std;
// type
typedef long long ll;
typedef long double ld;
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.end()
#define rall(a)             a.rbegin(), a.rend()
#define sz(a)               a.size()
// I/O
#define setpre(n)           fixed << setprecision(n)
#define Ptest(x)            return cout << x << endl, (void) 0;
bool endline = false;
template<class T>
istream& operator >> (istream& inp, vector<T>& v){
    for (auto& it : v) inp >> it;
    return inp;
}
template<class T>
ostream& operator << (ostream& out, vector<T>& v){
    for (auto& it : v) out << it << (endline ? "\n" : " ");
    return out;
}
template<class T, class U>
istream& operator >> (istream& inp, pair<T, U>& v){
    inp >> v.F >> v.S;
    return inp;
}
template<class T, class U>
ostream& operator << (ostream& out, pair<T, U>& v){
    out << v.F << ' ' << v.S;
    return out;
}
void debug(){
    cout << endl;
}
template <typename H, typename... T>
void debug(H a, T... b){
    cout << a << ' ';
    debug(b...);
}
// geometry calculate
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));

void FAST_IO(string filein = "", string fileout = ""){
    if (fopen(filein.c_str(), "r")){
        freopen(filein.c_str(), "r", stdin);
        freopen(fileout.c_str(), "w", stdout);
    }
    cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
}

void Hollwo_Pelw();

signed main(){
    #ifdef hollwo_pelw_local
        FAST_IO("input.inp", "output.out");
        auto start = chrono::steady_clock::now();
    #else
        FAST_IO(".inp", ".out");
    #endif
    int testcases = 1;
    // cin >> testcases;
    for (int test = 1; test <= testcases; test++){
        // cout << "Case #" << test << ": ";
        Hollwo_Pelw();
    }
    #ifdef hollwo_pelw_local
        auto end = chrono::steady_clock::now();
        cout << endl;
        cout << "Excution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
    #endif
    return 0;
}

// constant
const int allmod[3] = {(int) 1e9 + 7, 998244353, (int) 1e9 + 9};
const int mod = allmod[0];
const int MAXN = 2e5 + 5;
const int inf = 2e9;
const ll linf = 1e18;
#define int long long

int n, a[MAXN << 1], ans;

void Hollwo_Pelw() {
    cin >> n;
    for (int i = 1; i <= 2 * n; i++){
        cin >> a[i];
        ans += a[i];
    }
    priority_queue<int, vector<int>, greater<int>> pq;
    for (int l = n, r = n + 1; l >= 1 && r <= 2 * n; l --, r ++){
        pq.push(a[l]), pq.push(a[r]);
        ans -= pq.top(); pq.pop();
    }
    cout << ans;
}

/*

./-=====>>><<<-------- DEBUG -------->>><<<=====-\.
/.................................................\
+====================== INP ======================+

+====================== OUT ======================+

+======================*****======================+
\................................................./
.\-=====>>><<<--------= END =-------->>><<<=====-/.

*/

#include <bits/stdc++.h>

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(2*n);
	rep(i,2*n) scanf("%lld",&a[i]);

	priority_queue<lint,vector<lint>,greater<>> Q;
	Q.emplace(max(a[n-1],a[n]));
	for(int i=1;i<n;i++){
		Q.emplace(a[n-i-1]);
		Q.emplace(a[n+i]);
		Q.pop();
	}

	lint ans=0;
	while(!Q.empty()){
		ans+=Q.top();
		Q.pop();
	}
	printf("%lld\n",ans);

	return 0;
}


// 3 years challenge become master.
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define nl "\n";
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
#define r(i,a,b) for(int i=a;i<b;i++)
#define d(i, a) for(int i=a;i>=0;i--)
#define D(i, a, b) for(int i=a;i>=b;i--)
#define A(u, thing) for(auto u: thing)
using namespace std;
const int MOD = 1e9+7;
const int inf = 1e18+7; // check this values dummy.
const int N = 3e5+5;
vi g[N]; // making graph

void setIO(string s) { // the argument is the filename without the extension
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}
/**
 *
 *      things i forget.
 *      a/b mod m = a.b(inverse) mod m where b(inverse) is b^(m-2) mod m;
 *
 * */
struct mi {
 	int v; explicit operator int() const { return v; }
	mi() { v = 0; }
	mi(int _v):v(_v%MOD) { v += (v<0)*MOD; }
};
mi& operator+=(mi& a, mi b) {
	if ((a.v += b.v) >= MOD) a.v -= MOD;
	return a; }
mi& operator-=(mi& a, mi b) {
	if ((a.v -= b.v) < 0) a.v += MOD;
	return a; }
mi operator+(mi a, mi b) { return a += b; }
mi operator-(mi a, mi b) { return a -= b; }
mi operator*(mi a, mi b) { return mi((int)a.v*b.v); }
mi& operator*=(mi& a, mi b) { return a = a*b; }
mi pow(mi a, int p) { assert(p >= 0); // asserts are important!
	return p==0?1:pow(a*a,p/2)*(p&1?a:1); }
mi inv(mi a) { assert(a.v != 0); return pow(a,MOD-2); }
mi operator/(mi a, mi b) { return a*inv(b); }

template<typename T_vector>
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = v.size();

    for (int i = start; i < end; i++)
        cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}

void solve_test_case(){
      int a,b,c;
      cin >> a >> b >> c;
      map<int,int> m;
      m[a]++, m[b]++, m[c]++;

      if(m.size() == 3){
            cout << 0 << nl;
      }
      else{
            A(u, m){
                  int fre = u.s;
                  int ele = u.f;
                  if(fre == 3 or fre == 1){
                        cout << ele << nl;
                        return;
                  }
            }
      }
}

signed main(){
	// uncomment in usaco
	//setIO("problemname");
	int t;
	//cin >> t;
	//uncomment if no test cases.
        t = 1;
	r(i, 1, t+1){
		// cout << "Case #" << t <<  ": " <<  nl;
		solve_test_case();
	}
	return 0;
}

#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug(x)    cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back
#define ll          long long
#define ull         unsigned long long
#define ld          long double
#define pii         pair<int, int>
#define pl          pair<ll, ll>
using namespace std;
int main(){
    fastio;
    ld X, Y, R;
    cin >> R >> X >> Y;
    X=sqrt(X*X+Y*Y);
    if(X<R)
        cout << "2\n";
    else
        cout << ceil(X/R) << endl;
}


#include <bits/stdc++.h>

#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(ini) (ll) __builtin_popcountll(x)
#define revll greater<ll>
#define revii greater<ii>()
#define todo(y,val) all_of(all(y),[&val](ll x) {return (x == ((ll)val));})
#define nada(y,val) none_of(all(y),[&val](ll x) {return (x == ((ll)val));})
#define algu(y,val) any_of(all(y),[&val](ll x) {return (x == ((ll)val));})
#define cuantos(a,x) count(all(a),x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"\n"
#define test ll t;cin>>t;while(t--)
#define PI acos(-1);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll>  vi;
typedef vector<ii> vii;

const ll mod = 1e9+7;
const ll MAX = 1e5+12;
const ll inf = 1e18+3;

int main(){
  fastio;
  ll n,x;cin>>n>>x;
  vi v;
  f(i,0,n){
    ll lec;
    cin>>lec;
    if(lec==x) continue;
    v.pb(lec);
  }
  f(i,0,sz(v)){
    cout<<v[i]<<" ";
  }
  cout<<"\n";
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}

int64_t gcd(int64_t a,int64_t b){
    if(a < b)
    {
        int64_t temp = a;
        a = b ;
        b = temp;
    }
    int64_t copya = a;
    int64_t copyb = b;
    int64_t r = a%b ;
    while (r != 0)
    {
        a = b ;
        b = r ;
        r = a%b ;
    }
    return b ;

}

int main(){
    int n,m ;
    cin >> n >> m ;
    vector<int> a(n) ;
    vector<int> b(m) ;
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> b.at(i) ;
    }
    a.push_back(1001) ;
    b.push_back(1001) ;
    int ai = 0 ;
    int bi = 0 ;
    vector<int> ans(0) ;
    while (ai < n || bi < m )
    {
        if (a.at(ai) < b.at(bi))
        {
            ans.push_back(a.at(ai)) ;
            ai ++ ;
        }else if (a.at(ai) > b.at(bi))
        {
            ans.push_back(b.at(bi)) ;
            bi ++ ;
        }else
        {
            ai ++ ;
            bi ++ ;
        }

    }
    if (ans.size() == 0)
    {
        return 0 ;
    }

    for (int i = 0; i < ans.size() - 1 ; i++)
    {
        cout << ans.at(i) << " " ;
    }
    cout << ans.at(ans.size()-1) << endl ;

}


#include <stdio.h>
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define mset(a, b) memset(a, b, sizeof a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int N = 5010;

const int P = 998244353;

inline int mul(int x, int y) {return 1ll * x * y % P;}
inline int add(int x, int y) {return x + y >= P ? x + y - P : x + y;}
inline void upd(int &x, int y) {x = add(x, y);};

int n, m;
int f[N][N], s[N][N], h[N][N], p[N][N];

int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) f[i][m] = 1;
	for (int i = 0; i <= m; i++)
		for (int j = 0; j <= n; j++) {
			if (j == 0) {p[i][j] = 1; continue;}
			if (i == 0) {p[i][j] = 0; continue;}
			p[i][j] = mul(p[i][j - 1], i);
		}
	for (int j = m - 1; j >= 1; j--) {
		for (int i = 1; i <= n; i++) {
			upd(h[i + 1][j], f[i][j + 1]);
			upd(h[i][j], mul(h[i - 1][j], (m - j + 1)));
		}
		for (int i = 1; i <= n; i++) {
			upd(s[i][j], mul(s[i - 1][j], (m - j)));
			f[i][j] = add(s[i][j], add(h[i][j], mul(p[m - j][i - 1], i)));
			upd(f[i][j], f[i][j + 1]);
			upd(s[i + 1][j], f[i][j]);
		}
	}
	cout << f[n][1] << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int mod=998244353;
int n,m;
void update(int &x,int y) {
	x+=y; if (x>=mod) x-=mod;
}
int mi[5010];
int main() {
	//freopen("1.txt","r",stdin);
	read(n),read(m);
	mi[0]=1;
	for (int i=1;i<5010;i++) mi[i]=(ll)mi[i-1]*m%mod;
	int ans=(ll)mi[n]*n%mod;
	for (int i=1;i<=m;i++) {
		int tmp=1;
		for (int j=1;j<n;j++) {
			update(ans,mod-(ll)(n-j)*tmp%mod*mi[n-j-1]%mod);
			tmp=(ll)tmp*(m-i)%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Integer overflow?

  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?

  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?

  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/


#include<bits/stdc++.h>
using namespace std;
int main()
{
  float d,h,m=0;
  int n;
  cin>>n>>d>>h;
  float dist[n],hei[n];
  for(int i=0;i<n;i++)
  {
    cin>>dist[i]>>hei[i];
    float y=hei[i]-((h-hei[i])/(d-dist[i]))*dist[i];
    if(y>=0)
      m=max(m,y);
  }
  cout<<m<<endl;
  return 0;
}

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

int main(){
  int N, K, M;
  cin >> N >> K >> M;
  int A[N-1];
  rep(i, N-1) cin >> A[i];
  int goal = N * M;
  int sums = 0;
  rep(i, N-1) sums += A[i];
  if (goal - sums <= K) cout << max(0, goal - sums) << endl;
  else cout << -1 << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second

const int N=42;
int a[N];

void slv(int l,int r,int sum,vector <int> &v){
	if(l>r){
		v.pb(sum);
		return;
	}
	slv(l,r-1,sum+a[r],v);
	slv(l,r-1,sum,v);
}

int32_t main(){
   ios;
  	int n,t;
  	cin>>n>>t;
  	F(i,1,n) cin>>a[i];

  	vector <int> u,v;
  	slv(1,n/2,0,v);
  	slv(n/2+1,n,0,u);

  	sort(all(v));
  	int ans=0;
  	for(auto it:u){
  		if(it>t) continue;
  		int val=it;
  		int x=upper_bound(all(v),t-it)-v.begin()-1;
  		if(x>=0) val+=v[x];
  		ans=max(ans,val);
  	}
  	cout<<ans<<endl;
}

#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template<typename T = int> using V = vector<T>;
template<typename T = int> using VV = vector<vector<T>>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
#ifdef DEBUG
template<typename T>
ostream &operator<<(ostream &os, set<T> st) {
    for(auto x : st) cerr << x << ' ';
    return os;
}
template<typename T, typename S>
ostream &operator<<(ostream &os, map<T, S> mp) {
    for(auto x : mp) cerr << x << ' ';
    return os;
}
#endif
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    ll t;
    cin >> n >> t;
    vector<ll>a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    vector<ll> b;
    for(int i = 0; i < 1 << (n / 2); i++){
        ll sum = 0;
        for(int j = 0; j < n / 2; j++){
            if(i >> j & 1)sum += a[j];
        }
        b.push_back(sum);
    }
    sort(b.begin(), b.end());
    ll ans = 0;
    for(int i = 0; i < 1 << (n - n / 2); i++){
        ll sum = 0;
        for(int j  = 0; j < n - n / 2; j++){
            if(i >> j & 1)sum += a[j + n / 2];
        }
        if(sum > t)continue;
        if(b[0] + sum > t)ans = max(ans, sum);
        int id = (int) (lower_bound(b.begin(), b.end(), t - sum) - b.begin());
        for(int x: {id-1,id,id+1}){
            if(0<=x and x < b.size() and b[x] + sum <= t)ans = max(ans, b[x] + sum);
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define lc (x << 1)
#define rc (x << 1 | 1)
#define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define IT iterator
#define V vector
#define TP template <class o>
#define TPP template <typename t1, typename t2>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = b; i >= a; i--)
#define FOR(i,n) rep(i,1,n)
#define debug(x) cerr << #x << ' ' << '=' << ' ' << x << endl
using namespace std;
typedef unsigned ui;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int N = 2e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9;
const ll INF = 1e15;

// char buf[size],*p1=buf,*p2=buf;
TP void qr(o& x) {
    char c = gc;
    x = 0;
    int f = 1;
    while (!isdigit(c)) {
        if (c == '-')
            f = -1;
        c = gc;
    }
    while (isdigit(c))
        x = x * 10 + c - '0', c = gc;
    x *= f;
}
TP void qw(o x) {
    if (x / 10)
        qw(x / 10);
    putchar(x % 10 + '0');
}
TP void pr1(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar(' ');
}
TP void pr2(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar(10);
}

// math
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll power(ll a, ll b = mod - 2, ll p = mod) {
    ll c = 1;
    while (b) {
        if (b & 1)
            c = c * a % p;
        b /= 2;
        a = a * a % p;
    }
    return c;
}

TP void cmax(o& x, o y) {
    if (x < y)
        x = y;
}
void cmax(int& x, int y) { x = x - y >> 31 ? y : x; }
TP void cmin(o& x, o y) {
    if (x > y)
        x = y;
}
void cmin(int& x, int y) { x = x - y >> 31 ? x : y; }
TPP void ad(t1& x, t2 y) {
    x += y;
    if (x >= mod)
        x -= mod;
}
TPP void dl(t1& x, t2 y) {
    x -= y;
    if (x < 0)
        x += mod;
}

// dbinom
ll jc[N], inv[N];
void jc_init(int n) {
    jc[0] = 1;
    for (int i = 1; i <= n; i++)
        jc[i] = jc[i - 1] * i % mod;
    inv[n] = power(jc[n]);
    for (int i = n; i; i--)
        inv[i - 1] = inv[i] * i % mod;
}
ll C(int x, int y) {
    if (x < y || y < 0)
        return 0;
    return jc[x] * inv[y] % mod * inv[x - y] % mod;
}

int n, a[N], b[N];
ll ans, c[2][N];

void solve() {
    qr(n);
    FOR(i,n) qr(a[i]),ans += a[i];
    FOR(i,n) qr(b[i]),c[i&1][(i+1)>>1]=b[i]-a[i];
    sort(c[0]+1,c[0]+n/2+1);
    sort(c[1]+1,c[1]+n/2+1);
    REP(i,1,n/2) {
        ll x=c[0][i]+c[1][i];
        if(x<0) break;
        ans += x;
    }
    pr2(ans);
}

int main() {
    int T = 1;
    // qr(T);
    while (T--)
        solve();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define DEBUG

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    string sep;
    for (const auto &x : v) os << sep << x, sep = ", ";
    return os << '}';
}

template<typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
    os << '{';
    string sep;
    for (const auto &x : arr) os << sep << x, sep = ", ";
    return os << '}';
}

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

void dbg_out() { cerr << endl; }

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

#ifdef DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define Long long long

const long long INF = 0x3f3f3f3f3f3f3f3fLL;
//const int MOD = 1e9 + 7;
const int MOD = 998244353;

/*
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int randomInt(int lim) {
    return uniform_int_distribution<int>(0, lim - 1)(rng);
}
*/

const int N = 15;
const int LOG = 18;

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    Long ans = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i], ans += b[i];
    vector<int> e, o;
    for (int i = 0; i < n; i++) {
        if (i & 1) o.push_back(a[i] - b[i]);
        else e.push_back(a[i] - b[i]);
    }
    sort(o.rbegin(), o.rend());
    sort(e.rbegin(), e.rend());
    Long cur = ans;
    for (int i = 0; i < n / 2; i++) {
        cur += o[i] + e[i];
        ans = max(ans, cur);
    }
    cout << ans << '\n';
}


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

#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int) x.size()
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define FOR(i, a, b) for(auto i=(a); i<(b); i++)
#define ROF(i, a, b) for(auto i=(b)-1; i>=(a); i--)
#define F0R(i, n) FOR(i, 0, n)
#define R0F(i, n) ROF(i, 0, n)

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vpii=vector<pii>;

template<class T> bool ckmin(T&a, const T&b) {return b<a?a=b,1:0;}
template<class T> bool ckmax(T&a, const T&b) {return b>a?a=b,1:0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mxN=2e5+10;
const int MOD=1e9+7;
const ll infLL=1e18;
const ld eps=1e-6;

int main(){
	cin.tie(0)->sync_with_stdio(0);
	int t; cin >> t;
	while(t--){
		int n; cin >> n;
		vi a(n), ans;
		F0R(i, n) cin >> a[i];
		for(int op=0; ; op++){
			bool ok=1;
			F0R(j, n-1) ok&=a[j]<a[j+1];
			if(ok) break;
			int j=op%2;
			while(a[j]<a[j+1]&&j<n-1) j+=2;
			if(j+1>=n) j-=2;
			ans.pb(j+1);
			swap(a[j], a[j+1]);
		}
		cout << siz(ans) << "\n";
		for(auto v:ans) cout << v << ' ';
		cout << "\n";
	}
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

void solve(){
  int N; cin >> N;
  vector<int> A(N);
  rep(i,N){
    cin >> A[i];
  }
  vector<int> G=A;
  sort(all(G));
  int cnt = 0;
  vector<int> ans;
  while(G!=A){
    if(cnt%2==0){
      int ch = 0;
      for(int i=0;i+1<N;i+=2){
        if(A[i]>A[i+1]){
          ch = i;
          //break;
        }
      }
      ans.pb(ch);
      swap(A[ch], A[ch+1]);
    }
    else{
      int ch = 1;
      for(int i=1;i+1<N;i+=2){
        if(A[i]>A[i+1]){
          ch=i;
          //break;
        }
      }
      ans.pb(ch);
      swap(A[ch],A[ch+1]);
    }
    cnt++;
  }
  cout << cnt << endl;
  rep(i,sz(ans)){
    if(i) cout << " ";
    cout << ans[i]+1;
  }
  cout << endl;
}

int main(){
  int T; cin >> T;
  while(T--){
    solve();

  }
  return 0;
}


#include <bits/stdc++.h>

#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

using namespace std;

using ld = long double;
using ll = long long int;
using pl = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vpl = vector<pl>;

template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T> using pq = priority_queue<T>;
template <class T> T chmax(T &a, const T &b) { return a = max(a, b); }
template <class T> T chmin(T &a, const T &b) { return a = min(a, b); }

const ll INF = 100000000000000000;
const ll MAX = 500005;
const ll MOD = 1000000007;
// const ll MOD = 998244353;

int main(void) {

  ll n, k, m;
  cin >> n >> k >> m;

  ll sum = 0;
  rep(i, n - 1) {
    ll a;
    cin >> a;

    sum += a;
  }

  ll diff = max(0LL, n * m - sum);
  cout << (diff > k ? -1LL : diff) << endl;

  return (0);
}

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

struct xy {
	int x;
	int y;
};

const int n = 50;
vector<vector<int>> t(n, vector<int>(n));
vector<vector<int>> p(n, vector<int>(n));
xy s;
clock_t start;
string ans = "";
int maxPoint = 0;

void input () {
  cin >> s.x >> s.y;
	rep(i, n) rep(j, n) cin >> t[i][j];
	rep(i, n) rep(j, n) cin >> p[i][j];
}

bool isTimeLimit(clock_t start) {
  clock_t end = clock();
  const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
  if (time >= 1960) return true;
  else return false;
}

int cnt = 0;
void dfs(int mode, xy now, int point, string tmpans, set<int> step) {
  cnt++;
  // タイムリミット
  if (cnt%500 == 0) {
    if (isTimeLimit(start)) {
      cout << ans << endl;
      exit(0);
    }
  }

  switch (mode) {
    case 0: now.x--; break;
    case 1: now.x++; break;
    case 2: now.y--; break;
    case 3: now.y++; break;
  }

  if (!(now.x >= 0 && now.x <= 49 && now.y >= 0 && now.y <= 49)) {
    return ;
  }
  auto it = step.find(t[now.x][now.y]);
  if (it != step.end()) return;
  step.insert(t[now.x][now.y]);
  switch (mode) {
    case 0: tmpans += "U"; break;
    case 1: tmpans += "D"; break;
    case 2: tmpans += "L"; break;
    case 3: tmpans += "R"; break;
  }

  point += p[now.x][now.y];

  if (point > maxPoint) {
    maxPoint = point;
    ans = tmpans;
  }

  rep(i, 4) dfs(i, now, point, tmpans, step);
  return;
}

int main() {
	// 入力
  input();

  start = clock();
  rep(i, n) {
    // 初期化
    xy now;
    now.x = s.x;
    now.y = s.y;
    set<int> step; // 踏んだタイル番号を保持
    step.insert(t[now.x][now.y]);
    string tmpans = "";
    int point = 0;

    // 進む方向探索
    // 0：上、1：下、2：左、3：右
    dfs(i, now, point, tmpans, step);
  }
	return 0;
}