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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};

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 a < b ? a = b, 1 : 0; }
int pct(int x) { return __builtin_popcount(x); }
int bit(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
// int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0

// INPUT
template<class A> void re(complex<A>& c);
template<class A, class B> void re(pair<A,B>& p);
template<class A> void re(vector<A>& v);
template<class A, size_t SZ> void re(array<A,SZ>& a);

template<class T> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }

template<class A> void re(complex<A>& c) { A a,b; re(a,b); c = {a,b}; }
template<class A, class B> void re(pair<A,B>& p) { re(p.f,p.s); }
template<class A> void re(vector<A>& x) { trav(a,x) re(a); }
template<class A, size_t SZ> void re(array<A,SZ>& x) { trav(a,x) re(a); }

// TO_STRING
#define ts to_string
template<class A, class B> str ts(pair<A,B> p);
template<class A> str ts(complex<A> c) { return ts(mp(c.real(),c.imag())); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(char c) { str s = ""; s += c; return s; }
str ts(str s) { return s; }
str ts(const char* s) { return (str)s; }
str ts(vector<bool> v) {
	bool fst = 1; str res = "{";
	F0R(i,sz(v)) {
		if (!fst) res += ", ";
		fst = 0; res += ts(v[i]);
	}
	res += "}"; return res;
}
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; F0R(i,SZ) res += char('0'+b[i]);
	return res; }
template<class T> str ts(T v) {
	bool fst = 1; str res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += ts(x);
	}
	res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
	return "("+ts(p.f)+", "+ts(p.s)+")"; }

// OUTPUT
template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) {
	pr(h); pr(t...); }
void ps() { pr("\n"); } // print w/ spaces
template<class H, class... T> void ps(const H& h, const T&... t) {
	pr(h); if (sizeof...(t)) pr(" "); ps(t...); }

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

// FILE I/O
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	// cin.exceptions(cin.failbit);
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

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

ll n;
int m,k,cnt[400000];

ll fdiv(ll a, ll b) { return a/b; }
ll cdiv(ll a, ll b) { return (a+b-1)/b; }

void solve() {
	re(n,m,k);
	// first maximize min
	vl p(m); re(p); p.insert(begin(p),0); p.pb(n);
	vl dif; F0R(i,sz(p)-1) dif.pb(p[i+1]-p[i]);
	m = sz(dif);
	typedef pair<ll,int> T; priority_queue<T> todo;
	F0R(i,m) {
		cnt[i] = 1;
		if (cnt[i] < dif[i]) todo.push({fdiv(dif[i],cnt[i]+1),i});
	}
	dbg(dif,k);
	F0R(i,k) {
		auto a = todo.top(); todo.pop();
		cnt[a.s] ++;
		if (cnt[a.s] < dif[a.s]) todo.push({fdiv(dif[a.s],cnt[a.s]+1),a.s});
	}
	ll mn = INF;
	F0R(i,m) dbg(dif[i],cnt[i]);
	F0R(i,m) ckmin(mn,fdiv(dif[i],cnt[i]));
	// dbg("??",mn);

	ll ans = INF;
	priority_queue<T> cur;
	F0R(i,m) {
		cnt[i] = 1;
		cur.push({cdiv(dif[i],cnt[i]),i});
	}
	for (int i = 0;;++i) {
		auto a = cur.top(); cur.pop(); ckmin(ans,a.f-mn);
		// dbg("OH",k,a,cnt[a.s],dif[a.s]);
		// dbg("OH",a,mn);
		if (i == k || cnt[a.s] == dif[a.s]) break;
		cnt[a.s] ++;
		ckmin(mn,fdiv(dif[a.s],cnt[a.s]));
		T p = {cdiv(dif[a.s],cnt[a.s]),a.s};
		cur.push(p);
	}
	ps(ans);
	// dbg(dif,mn);
	// then keep decreasing max and updating the min until cnt exceeds
}

int main() {
	setIO();
	int t; re(t);
	F0R(i,t) solve();
	// you should actually read the stuff at the bottom
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const long long INF = 1e9+7;

int  main(){

    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    long long n;
    long long m;
    cin >> n >> m;
    vector<long long> m1(n);
    for (long long i=0;i<n;i++){
        cin >> m1[i];
    }
    vector<long long> ans(n,0);
    multiset<pair<long long,long long > > pr;
    for (long long i=0;i<n;i++){
        long long val = m1[i];
        if (m - val >= 0){
            ans[i] = 0;
            m-=val;
            vector<pair<long long,long long> > m2;
            m2.push_back({1,val});
            for (auto el:pr){
                long long sum = el.second + val;
                long long kol = el.first+1;
                m2.push_back({kol,sum});
            }
            for (auto el:m2){
                pr.insert(el);
            }
            continue;
        }
        long long raz = val - m;
        m -= val;
        for (auto el:pr){
            long long sum = el.second;
            long long kol = el.first;
            if (sum >= raz){
                ans[i] = kol ;
                break;
            }
        }
           vector<pair<long long,long long> > m2;
            m2.push_back({1,val});
            for (auto el:pr){
                long long sum = el.second + val;
                long long kol = el.first+1;
                m2.push_back({kol,sum});
            }
            for (auto el:m2){
                pr.insert(el);
            }
    }
    for (auto el:ans){
        cout << el << ' ';
    }
    return 0;
}


#include <bits/stdc++.h>

// #define endl '\n'
#define pb push_back
#define fi first
#define se second
#define pll pair<long long, long long>
#define all(v) v.begin(), v.end()

using namespace std;

typedef long long int ll;

mt19937 rnd(1337);

ostream& operator<< (ostream& a, const pll& b) {
    cout << "{" << b.first << ", " << b.second << "}";
    return a;
}

ostream& operator<< (ostream &a, const vector<ll>& b) {
    for (auto& k : b) cout << k << " ";
    return a;
}

ostream& operator<< (ostream &a, const vector<pll>& b) {
    for (auto& k : b) cout << k << " ";
    return a;
}

#ifdef HOME
  #define dbg(x) cout << #x << " : " << (x) << '\n';
#else
  #define dbg(x)
#endif

const ll INF = (ll)1e18;
const ll MOD = 1000 * 1000 * 1000 + 7, MOD2 = 274876858367;
const ll maxn = (ll)1e6 + 1, L = 10;

ll dp[maxn], pr[maxn];

struct kek {
  ll s, t, c, inx;
};

int main() {
  #ifdef HOME
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen("olympiad.in", "r", stdin);
    freopen("olympiad.out", "w", stdout);
  #endif
  ll n, a, b;
  cin >> n >> a >> b;
  if (a > b)
    swap(a, b);
  vector<ll> v;
  for (ll i = 0; i < n; ++i)
    v.pb(i + 1);
  ll inx = 1;
  while (v.size()) {
    for (ll i = 0; i < v.size(); ++i) {
      if (v[i] == a && v[i + 1] == b) {
        if (v.size() == 2)
          cout << "Final!";
        else
          cout << inx;
        return 0;
      }
      if (v[i] == a || v[i] == b)
        v.erase(v.begin() + i + 1);
      else
        v.erase(v.begin() + i);
    }
    ++inx;
  }
  return 0;
}


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

int main()
{

        int n;
        cin >> n;
        string temp = "";
        for(int j = 0; j < n; ++j)
        {
            cin >> temp[j];
        }
        cout << n+1;
}


#include "bits/stdc++.h"
using namespace std;
typedef unsigned long long LL;
#define nl "\n"
#define X first
#define Y second

#define MAX INT_MAX
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*(b/gcd(a, b))

#define check() {printf("OK\n");}
#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())

#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define maxv(v) *max_element(v.begin(),v.end())
#define minv(v) *min_element(v.begin(),v.end())

#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define f() {ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);}
#define UNQ(v) SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define MOD 1000000007   // (int)1e9+7

///sortingstringbytheirlengthincreasingorder
bool ff(string s1,string s2){
    return s1.size()<s2.size();
}
///vector<string>s;sort(s.begin(),s.end(),ff)
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

int main(){f();
        LL n;
        cin>>n;
        string s = "";
        for(LL i = 1; i<=100000;i++){
            string a = to_str(i);
            s+=a;
        }
        cout<<s[n-1]<<endl;

return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#include <iostream>
#include <fstream>

#define mp make_pair
#define pb push_back

using ll = long long;
using ld = long double;

using namespace std;

const int MAXN = 100001;

int c2[MAXN];

const int M = 60;

ll a[MAXN];

map <ll, int> b;

void no() {
	cout << -1 << endl;
	exit(0);
}

int pc[MAXN];

int getp2(ll x) {
	ll c = 1;
	int pw = 0;
	while (c < x) c *= 2, pw++;
	if (c == x) return pw;
	else return -1;
}

vector <ll> bad;
vector <ll> finishes;
vector <ll> nonp2;

int main() {
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(20);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		int p2 = getp2(a[i]);
		if (p2 != -1) pc[p2]++;
		else bad.push_back(a[i]), nonp2.push_back(a[i]);
	}
	int cur = pc[0];
	for (int i = 1; i < M; i++) {
		if (pc[i] > cur) {
			for (int j = cur; j < pc[i]; j++) {
				bad.push_back(1ll << i);
			}
		}
		while (cur > pc[i]) {
			finishes.push_back(1ll << (i - 1));
			cur--;
		}
	}
	sort(bad.begin(), bad.end());
	if (finishes.size() < bad.size()) no();
	for (int i = 0; i < bad.size(); i++) {
		if (bad[i] >= 2 * finishes[finishes.size() - bad.size() + i]) no();
	}

	int ansr = finishes.size();

	int pnp2 = (int)nonp2.size() - 1;

	int fin = 0, ufin = 0;

	for (int i = nonp2.size() - 1; i >= 0; i--) {
		ll x = nonp2[i];
		for (int i = M - 1; i >= 0; i--) {
			if (pc[i] > 0) pc[i]--;
		}
	}

	for (int i = M - 1; i >= 0; i--) {
		if (pc[i] < fin + ufin)
			assert(false);
		pc[i] -= fin + ufin;
		if (pc[i] <= ufin) {
			ufin -= pc[i];
			fin += pc[i];
		} else {
			fin += ufin;
			pc[i] -= ufin;
			fin += pc[i] / 2;
			ufin = pc[i] % 2;
		}
	}

	for (int i = nonp2.size() + fin + ufin; i <= finishes.size(); i++)
		cout << i << " ";
	cout << "\n";
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <conio.h>

using namespace std;

int a[110];
int box[110];

int main() {
        int n;
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
                scanf("%d", &a[i]);
        }
        sort(a, a + n);
        int cnt = 0;
        for (int i = 0; i < n; i++) {
                bool is_possible = false;
                for (int j = 0; j < cnt; j++) {
                        if (box[j] <= a[i]) {
                                box[j]++;
                                is_possible = true;
                                break;
                        }
                }
                if (is_possible == false) {
                        box[cnt]++;
                        cnt++;
                }
        }
        printf("%d\n", cnt);
        getch();
        return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<cctype>
#include<memory>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define pf push_front
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;

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

  if(a == 1)
    {
      //assert(false);
    cout << "Washington" << endl;

    }
  else if(a == 2)
    {
      //assert(false);
      cout << "Adams" << endl;

    }
else if(a == 3)
  {
    //assert(false);
cout << "Jefferson" << endl;

  }
 else if(a == 4)
   {
     //assert(false);
 cout << "Madison" << endl;

   }
else if(a == 5)
  {
    //assert(false);
 cout << "Monroe" << endl;

  }
else if(a == 6)
  {
    //assert(false);
 cout << "Adams" << endl;

  }
 else if(a == 7)
   {
     //assert(false);
   cout << "Jackson" << endl;

   }
else if(a == 8)
  {
    //assert(false);
cout << "Van Buren" << endl;

  }
else if(a == 9)
  {
    //assert(false);
  cout << "Harrison" << endl;

  }
else if(a == 10)
  {
    //assert(false);
    cout << "Tyler" << endl;

  }
 else if(a == 11)
   {   //ok
     //assert(false);
 cout << "Polk" << endl;

   }
 else if(a == 12)
   {
 cout << "Taylor" << endl;

   }
else if(a == 13)
  {
    cout << "Fillmore" << endl;

  }
else if(a == 14)
  {
 cout << "Pierce" << endl;

  }
else if(a == 15)
  {
 cout << "Buchanan" << endl;

  }
else if(a == 16)
  {
 cout << "Lincoln" << endl;

  }
else if(a == 17)
  {
 cout << "Johnson" << endl;

  }
else if(a == 18)
  {
    assert(false);
 cout << "Simpson Grant" << endl;

  }
else if(a == 19)
  {
    assert(false);
 cout << "Birchard Hayes" << endl;

  }
else if(a == 20)
  {   assert(false);
 cout << "Abram Garfield" << endl;

  }
else if(a == 21)
  {
 cout << "Alan Arthur" << endl;

  }
else if(a == 22)
  {
 cout << "Cleveland" << endl;

  }
else if(a == 23)
  {
    cout << "Harrison" << endl;

  }
else if(a == 24)
  {
 cout << "Cleveland" << endl;

  }
else if(a == 25)
  {

 cout << "McKinley" << endl;
  }
  else if(a == 26)
    {

 cout << "Roosevelt" << endl;
    }
else if(a == 27)
  {   //assert(false);
 cout << "Howard Taft" << endl;

  }
else if(a == 28)
  {
    cout << "Wilson" << endl;

  }
else if(a == 29)
  {
 cout << "Harding" << endl;//ok - input 8

  }
 else if(a == 30)
   {   //assert(false);
 cout << "Calvin Coolidge" << endl;

   }
else if(a == 31)
  {
 cout << "Clark Hoover" << endl;

  }
 else if(a == 32)
   {
 cout << "Delano Roosevelt" << endl;

   }
 else if(a == 33)
    {
      //assert(false);
  cout << "S. Truman" << endl;

    }
  else if(a == 34)
    {
      //assert(false);
 cout << "David Eisenhower" << endl;
    }
else if(a == 35)
  {//assert(false);
    cout << "Fitzgerald Kennedy" << endl;

  }
else if(a == 36)
  {
    //assert(false);
 cout << "Baines Johnson" << endl;
  }
  else if(a == 37)
    {
      //assert(false);
 cout << "Milhouse Nixon" << endl;
    }
else if(a == 38)
  {

cout << "Earl Ford" << endl;
  }
else if(a == 39)
  {

 cout << "Earl Carter" << endl;
  }
  else if(a == 40)
    {
      cout << "Wilson Reagan" << endl;
    }

return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <iterator>
#include <cstdio>
#include <vector>
#include <string>
#include <regex>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <utility>
#include <random>
#include <bitset>
#include <list>
#include <functional>
#include <chrono>
#include <fstream>
#include <array>
using namespace std;
template < class T, typename A = allocator<T> >
class Vector : public vector<T, A>
{
public:
	using vector<T, A>::vector;
	using typename vector<T, A>::size_type;
	using typename vector<T, A>::value_type;
	using typename vector<T, A>::allocator_type;
	Vector& operator()(size_type dummy_n, const value_type& val = value_type(), const allocator_type& alloc = allocator_type()) { return *this; }
};
template<> class Vector<string> : public vector<string> { public:using vector<string>::vector; Vector& operator()(size_type dummy_n) { return *this; } };
typedef long long ll;            typedef unsigned int u;
typedef pair<int, int> pii;      typedef pair<u, u> puu;
typedef Vector<bool> vb;// Vector
typedef Vector<int> vi;          typedef Vector<u> vu;
typedef Vector<ll> vll;
typedef Vector<string> vs;
typedef Vector<pii> vpii;        typedef Vector<puu> vpuu;
typedef Vector<Vector<int>> vvi; typedef Vector<Vector<u>> vvu;
typedef set<int> si;             typedef set<u> su;
typedef multiset<int> Si;        typedef multiset<u> Su;
typedef map<int, int> mi;        typedef map<u, u> mu;
typedef multimap<int, int> Mi;   typedef multimap<u, u> Mu;
template < typename Int = int > // only integral types
inline Int read() // "([number][space or newline])*" // reads -int_max but doesn't read int_min
{
	int c{ getchar() };
	if (c == '-') {
		Int init{ getchar() & 15 };
		while ((c = getchar()) & 16) init = (init << 3) + (init << 1) + (c & 15);
		return ++(init = ~init);
	}
	else {
		Int init{ c & 15 };
		while ((c = getchar()) & 16) init = (init << 3) + (init << 1) + (c & 15);
		return init;
	}
}
inline void read(int& a) // "([number][space or newline])*" // reads -int_max but doesn't read int_min
{
	a = getchar() & 15;
	if (a == 13) {
		a = getchar() & 15;
		for (int c; (c = getchar()) & 16; a = (a << 3) + (a << 1) + (c & 15));
		++(a = ~a);
	}
	else
		for (int c; (c = getchar()) & 16; a = (a << 3) + (a << 1) + (c & 15));
}
inline void read(unsigned int& a) // "([number][space or newline])*"
{
	a = getchar() & 15;
	for (int c; (c = getchar()) & 16; a = (a << 3) + (a << 1) + (c & 15));
}
inline void read(char& a) { scanf("%c%*c", &a); } // "([char][delim])*"
inline void read(string& a) { static char BUF[1234560]; scanf("%s%*c", BUF); a = move(string(BUF)); } // "([string][delim])*"
inline void read(ll& a) { a = read<ll>(); } // "([number][space or newline])*"
inline void read(double& a) { scanf("%lf%*c", &a); } // "([double][delim])*"
template < class T >
inline void read(pair<T, T>& a) { read(a.first); read(a.second); } // "([first][space or newline][second][space or newline])*"
template<template<typename T, typename A = allocator<T> > class C, class T>
inline void read(C<T>& a) { for (auto i = a.begin(); i != a.end(); ++i) read(*i); }
template < typename T, typename U, typename... ARGS >
inline void read(T& t, U& u, ARGS&... args) {
	read(t);
	read(u, args...);
}
template < typename Int > // only integral types
inline void write(Int x)
{
	static char BUF[64] = {};
	char *pnt{ BUF + 64 };
	if (x < 0) {
		putchar('-');
		++(x = ~x);
	}
	do
		*--pnt = x % 10 | 48;
	while (x /= 10);
	printf("%s", pnt);
}
inline void write(unsigned int a)
{
	static char BUF[16] = {};
	char *pnt{ BUF + 16 };
	do
		*--pnt = a % 10 | 48;
	while (a /= 10);
	printf("%s", pnt);
}
inline void write(const char& a) { printf("%c", a); }
inline void write(const char* a) { printf("%s", a); }
inline void write(const string& a) { printf("%s", a.c_str()); }
inline void write(const double& a) { printf("%lf", a); }
template < class T >
inline void write(const pair<T, T>& a) { write(a.first); write(' '); write(a.second); }
template<template<typename T, typename A = allocator<T> > class C, class T>
inline void write(const C<T>& a) { if (a.size()) write(*a.begin()); for (auto i = ++a.begin(); i != a.end(); ++i) { write(' '); write(*i); } }
template < typename T, typename U, typename... ARGS >
inline void write(const T& t, const U& u, const ARGS&... args) {
	write(t);
	write(' ');
	write(u, args...);
}
template<template<typename T, typename A = allocator<T> > class C, class T>
inline void sort(C<T>& a) { sort(a.begin(), a.end()); }
inline void sort(string& a) { sort(a.begin(), a.end()); }
template<template<typename T, typename A = allocator<T> > class C, class T>
inline void rsort(C<T>& a) { sort(a.rbegin(), a.rend()); }
inline void rsort(string& a) { sort(a.rbegin(), a.rend()); }
template<typename T>
inline int sz(const T& a) { return int(a.size()); }
template < template < class T, class Compare = less<T>, class Alloc = allocator<T> > class C, class T>
inline bool in(const C<T>& c, const T& el) { return c.find(el) != c.end(); };
template < template < class Key, class T, class Compare = less<Key>, class Alloc = allocator<pair<const Key, T> > > class C, class Key, class T>
inline bool in(const C<Key, T>& c, const Key& el) { return c.find(el) != c.end(); };
template < template < class T, class Compare = less<T>, class Alloc = allocator<T> > class C, class T>
inline bool out(const C<T>& c, const T& el) { return c.find(el) == c.end(); };
template < template < class Key, class T, class Compare = less<Key>, class Alloc = allocator<pair<const Key, T> > > class C, class Key, class T>
inline bool out(const C<Key, T>& c, const Key& el) { return c.find(el) == c.end(); };
#define MX 1000000000
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define T(n) for(decltype(n) _VARIABLE{(n) + 1}; --_VARIABLE;)
#define F(b,e,i) for(auto i = decltype(e)(b); i != (e); decltype(e)(b) < (e) ? ++i : --i)
#define G(f,l,i) for(auto i = decltype(l)(f) + (decltype(l)(f) < (l) ? -1 : 1); (decltype(l)(f) < (l) ? i++ : i--) != (l) ;)
#define M(f,l,i,j) for(auto i = decltype(l)(f) , j = (l) ; i < j; ++i, --j)
#define R(type, ...) type __VA_ARGS__; read(__VA_ARGS__)
#define W(...) write(__VA_ARGS__), write('\n')
#define bgn begin()
#define rbgn rbegin()
#define nd end()
#define rnd rend()
#define pb push_back
#define fnt front()
#define bck back()
#define x first
#define y second

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	R(u, n, k);
	R(vvu, a(n, vu(k)));
	u mn{ MX };
	F(0, n, i) {
		u c{};
		F(0, n, j) if (i != j) {
			F(0, k, l)
				c += a[i][l] != a[j][l];
		}
		if (c < mn)
			mn = c;
	}
	W(mn);
}
//
// ArtemParkhomets
//


#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define int long long
#define ld long double

using namespace std;

const int N = 5e5 + 5, inf = 2e18 + 7, mod = 1e9 + 7;

int a[N];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int cnt1 = 0, cnt0 = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        if(a[i] == 0)
            a[i] = -1;
        else
            a[i] %= 2;
        if(a[i] == 1)
            ++cnt1;
        if(a[i] == 0)
            ++cnt0;
    }
    cnt0 = n / 2 - cnt0;
    cnt1 = n - (n / 2) - cnt1;
    int ans = 0, last = -1, pos = -1, beg0 = 0, beg1 = 0, end0 = 0, end1 = 0;
    for(int i = 0; i < n; ++i){
        if(a[i] == -1)
            continue;
        else{
            if(last != -1){
                if(a[i] == 1 && last == 1){
                    if(cnt1 >= i - pos - 1)
                        cnt1 -= (i - pos - 1);
                    else
                        ans += 2;
                }else if(a[i] == 0 && last == 0){
                    if(cnt0 >= i - pos - 1)
                        cnt0 -= (i - pos - 1);
                    else
                        ans += 2;
                }else{
                    ans += 1;
                }
            }else{
                if(a[i] == 1)
                    beg1 = i;
                else
                    beg0 = i;
            }
            last = a[i], pos = i;
        }
    }
    if(last == 1)
        end1 = n - pos - 1;
    else
        end0 = n - pos - 1;
    if(n == 1 && last == -1){
        cout << 0;
        return 0;
    }
    if(end1 <= cnt1)
        cnt1 -= end1;
    else
        ans += 1;
    if(end0 <= cnt0)
        cnt0 -= end0;
    else
        ans += 1;

    if(beg1 <= cnt1)
        cnt1 -= beg1;
    else
        ans += 1;
    if(beg0 <= cnt0)
        cnt0 -= beg0;
    else
        ans += 1;

    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
// https://space.bilibili.com/672328094
#define ll long long
ll MOD = 998244353;
ll power(ll a, ll b, ll res = 1) {
  for (; b; b >>= 1, (a *= a) %= MOD)
    if (b & 1) (res *= a) %= MOD;
  return res;
}
ll inv(ll a, ll m) { return a == 1 ? 1 : ((m - m / a) * inv(m % a, m) % m); }
ll dp[501][501];
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int N, X;
  cin >> N >> X;
  int MAX = N + 10;
  vector<ll> f(MAX, 1);
  vector<ll> rf(MAX, 1);
  for (int i = 1; i < MAX; ++i) {
    f[i] = (f[i - 1] * i) % MOD;
    rf[i] = (rf[i - 1] * inv(i, MOD)) % MOD;
  }
  // vector dp(N + 1, vector<ll>(X + 1));  // d[i][j], i people, all less than x, one winner
  // vector power(X + 1, vector<ll>(N + 1));
  // for (int i = 0; i <= X; i += 1)
  //   for (int j = 0; j <= N; j += 1) power[i][j] = j ? power[i][j - 1] * i % MOD : 1;
  for (int x = 1; x <= X; x++) dp[1][x] = x;
  for (int n = 2; n <= N; n++) {
    for (int x = n - 1; x <= X; x++) {
      for (int alive = 1; alive <= n; alive++) {
        ll choose_alive = f[n] * rf[n - alive] % MOD * rf[alive] % MOD;
        ll dead_ways = power(n - 1, n - alive);
        (dp[n][x] += choose_alive * dead_ways % MOD * dp[alive][x - (n - 1)] % MOD) %= MOD;
      }
    }
  }
  cout << (power(X, N) + MOD - dp[N][X]) % MOD << '\n';
}


#include<bits/stdc++.h>
using namespace std;
unsigned long long a, b;

int main(){
	scanf("%I64d%I64d", &a, &b);
	while (1) {
		if (a == 0 || b == 0) break;
		else if (a >= 2 * b) {
			if (a < 4 * b) a -= 2 * b;
			else a = a - a / (2 * b) * 2 * b;
		} else if (b >= 2 * a) {
			if (b < 4 * a) b -= 2 * a;
			b = b - b / (2 * b) * 2 * b;
		} else break;
	}
	printf("%I64d %I64d\n", a, b);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
typedef unsigned long long ull;
using namespace std;
int n,cnt,m,a[100000000];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
	}
	for(int i=2;i<n;i++){
		if(abs(a[i-1]-a[i])>1){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}


#include<iostream>
#include<vector>
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	long long int l,n;
	cin >> n;
	if (n == 0)
		cout << 0 << endl;
	else if ((n + 1) % 2 == 0)
	{
		l = (n + 1)/2;
		cout << l << endl;
	}
	else
		cout << (n + 1) << endl;
	system("pause");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#define pb push_back
#define all(c) c.begin(),c.end()
#define MOD 998244353
typedef double ld;
#define PI 3.14159265

vector<string> V[27];
int k = -1;
string temp = "";
string str3 , ans;
int f = 0;
bool isSubSequence(string str1, string str2, int m, int n)
{
   int j = 0;
   for (int i=0; i<n&&j<m; i++)
       if (str1[j] <= str2[i])
       {
           //cout << str2[i] << " ";
           j++;
       }

   return (j==m);
}

vector<string> Generate(char* symbols, int k,  int n)
{
	vector<string> strings;
	if(n == 1)
	{
		for(int i = 0; i < k; i++)
		{
			string s;
			s.push_back(symbols[i]);
			strings.push_back(s);
		}

		return strings;
	}

	strings = Generate(symbols, k, n-1);

	vector<string> answer;

	for(int i = 0; i < strings.size(); i++)
	{
		string s = strings[i];
		for(int j = 0; j < k; j++)
		{
			answer.push_back(s + symbols[j]);
		}
	}

	return answer;
}

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

    ans = "abcdefghijklmnopqrstuvwxyz";
    char symbols[26];
    for(int i = 0 ; i < 26 ; i++) symbols[i] = ans[i];

    cin >> str3;
    int n = str3.size() - 1;

    if(isSubSequence(str3 , ans , n + 1 , 26)) {
        cout << str3 << endl;
        return 0;
    }
    vector<string> strings = Generate(symbols, n , n);

    for(int i = 0 ; i < strings.size() ; i++) {
        if(strings[i] > str3 && isSubSequence(strings[i] , ans , strings[i].size() , 26)) {
            cout << strings[i] << endl;
            return 0;
        }
    }
    cout << "-1" << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
const int Maxn = 100010;
#define ld long double

string get(int id) {
	switch(id) {
		case 1:
			return "x^y^z";
		case 2:
			return "x^z^y";
		case 3:
			return "(x^y)^z";
		case 4:
			return "(x^z)^y";
		case 5:
			return "y^x^z";
		case 6:
			return "y^z^x";
		case 7:
			return "(y^x)^z";
		case 8:
			return "(y^z)^x";
		case 9:
			return "z^x^y";
		case 10:
			return "z^y^x";
		case 11:
			return "(z^x)^y";
		case 12:
			return "(z^y)^x";
	}
}

ld f(int id, ld x, ld y, ld z) {
	switch(id) {
		case 1:
			return z * log(y) + log(log(x));
		case 2:
			return y * log(z) + log(log(x));
		case 3:
		case 4:
			return log(y * z * log(x));
		case 5:
			return z * log(x) + log(log(y));
		case 6:
			return x * log(z) + log(log(y));
		case 7:
		case 8:
			return log(x * z * log(y));
		case 9:
			return y * log(x) + log(log(z));
		case 10:
			return x * log(y) + log(log(z));
		case 11:
		case 12:
			return log(x * y * log(z));
	}
}

int main() {
	vector< pair<ld, int> >s;
	ld x, y, z;
	cin >> x >> y >> z;
	for(int i = 1; i <= 12; i++) s.push_back(make_pair(f(i, x, y, z), -i));
	sort(s.begin(), s.end());
	reverse(s.begin(), s.end());
	cout << get(-s[0].second);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{

	double n, k;
	int counter = 0;
	cin >> n;
	cin >> k;
	counter = n / k;
	if (counter % 2 == 1)
		cout << "YES";
	else
		cout << "NO";

	return 0;
}


#include<iostream>
using namespace std;
long long int fact(long long int x)
{
    if(x<2)
    return 0;
    if(x==2)
    return 1;
  return((x*(x-1))/2);

}
int main()
{
long long int n,m;
cin>>n>>m;
if(n==m)
{
    cout<<0<<" "<<0;
    return 0;
}

//for min

long long int rem=n%m;
long long int a[rem];
for(long long int i=0;i<rem;++i)
{
    a[i]=(n/m)+1;
}
long long int sum=0;
for(long long int i=0;i<rem;++i)
{
    if(a[i]<=1)
    continue;
    else
    sum=sum+fact(a[i]);
}
long long int z=fact(n/m);
sum=sum+z*(m-rem);
//for max

int y=1+n-m;
long long int max=fact(y);
cout<<sum<<" "<<max;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int c,d,n,m,k;
    cin >> c >> d >> n >> m >> k;
    int nbr = n*m - k;
//    a * n + b >= nbr
    vector<int> ans;
    for(int a=0;a<=10000;a++){
        for(int b=0;b<=10000;b++){
            if(a*n+b>=nbr){
                ans.push_back(a*c+b*d);
            }
        }
    }
    sort(ans.begin(),ans.end());
    cout << ans[0] << endl;
    return 0;
}


/*
 * Package: StandardCodeLibrary.Core
 * Last Update: 2012-12-21
 * */
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <utility>
#include <vector>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#if __GNUC__>=4 and __GNUC_MINOR__>=6
	#include <ext/pb_ds/assoc_container.hpp>
	#include <ext/pb_ds/tree_policy.hpp>
	#include <ext/pb_ds/tag_and_trait.hpp>
#endif
using namespace std;

#define lp for(;;)
#define repf(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repf(i,0,n)
#define ft(i,a,b) for (int i=(a);i<=(b);++i)
#define fdt(i,a,b) for (int i=(a);i>=b;--i)
#define feach(e,s) for (typeof((s).begin()) e=(s).begin();e!=(s).end();++e)
#define fsubset(subset,set) for (int subset=set&(set-1);subset;subset=(subset-1)&set)
#define forin(i,charset) for (cstr i=charset;*i;i++)
#define whl while
#define rtn return
#define fl(x,y) memset((x),char(y),sizeof(x))
#define clr(x) fl(x,char(0))
#define cpy(x,y) memcpy(x,y,sizeof(x))
#define pb push_back
#define mp make_pair
#define ins insert
#define rnk order_of_key
#define sel find_by_order
#define x first
#define y second
#define sz(x) (int((x).size()))
#define all(x) (x).begin(),(x).end()
#define srt(x) sort(all(x))
#define uniq(x) srt(x),(x).erase(unique(all(x)),x.end())
#define vec vector
#define pr pair
#define que queue
#define prq priority_queue
#define itr iterator
#define sf scanf
#define pf printf
#define pdb(prcs,x) (cout<<setprecision(prcs)<<fixed<<(x))
#ifdef DEBUG
#define prt(x) cerr<<#x"="<<(x)<<endl
#define asrtWA(s) do if(!(s))do{cerr<<"assert("#s")"<<endl;}whl(0);whl(0)
#define asrtTLE(s) do if(!(s))do{cerr<<"assert("#s")"<<endl;}whl(0);whl(0)
#define asrtMLE(s) do if(!(s))do{cerr<<"assert("#s")"<<endl;}whl(0);whl(0)
#define asrtOLE(s) do if(!(s))do{cerr<<"assert("#s")"<<endl;}whl(0);whl(0)
#define asrtRE(s) do if(!(s))do{cerr<<"assert("#s")"<<endl;}whl(0);whl(0)
#define runtime() cerr<<"Used: "<<db(clock())/CLOCKS_PER_SEC<<"s"<<endl
#define input(in) do{}whl(0)
#define output(out) do{}whl(0)
#else
#define endl (char('\n'))
#define prt(x) (cerr)
#define asrtWA(s) do if(!(s))exit(0);whl(0)
#define asrtTLE(s) do if(!(s))whl(1);whl(0)
#define asrtMLE(s) do if(!(s))whl(new int);whl(0)
#define asrtOLE(s) do if(!(s))whl(1)puts("OLE");whl(0)
#define asrtRE(s) do if(!(s))*(int*)0=0;whl(0)
#define runtime() cerr
#define input(in) freopen(in,"r",stdin)
#define output(out) freopen(out,"w",stdout)
#endif

typedef long long int lli;
typedef double db;
typedef const char* cstr;
typedef string str;
typedef vec<int> vi;
typedef vec<vi> vvi;
typedef vec<bool> vb;
typedef vec<vb> vvb;
typedef vec<str> vs;
typedef pr<int,int> pii;
typedef pr<lli,lli> pll;
typedef pr<db,db> pdd;
typedef pr<str,int> psi;
typedef map<int,int> mii;
typedef map<str,int> msi;
typedef map<char,int> mci;
typedef set<int> si;
typedef set<str> ss;
typedef que<int> qi;
typedef prq<int> pqi;
#if __GNUC__>=4 and __GNUC_MINOR__>=7
	template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};
	template<typename key>class ext_set:public __gnu_pbds::tree<key,__gnu_pbds::null_type,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};
#elif __GNUC__>=4 and __GNUC_MINOR__>=6
	template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};
	template<typename key>class ext_set:public __gnu_pbds::tree<key,__gnu_pbds::null_mapped_type,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};
#endif

const int oo=(~0u)>>1;
const lli ooll=(~0ull)>>1;
const db inf=1e+10;
const db eps=1e-10;
const db pi=acos(-1.0);
const int MOD=1000000007;

template<typename type>inline bool cmax(type& a,const type& b){rtn a<b?a=b,true:false;}
template<typename type>inline bool cmin(type& a,const type& b){rtn b<a?a=b,true:false;}
template<typename type>inline type sqr(const type& x){rtn x*x;}
inline int dbcmp(const db& a,const db& b){rtn (a>b+eps)-(a<b-eps);}
inline int sgn(const db& x){rtn dbcmp(x,0);}
template<typename ostream,typename type>ostream& operator<<(ostream& cout,const pr<type,type>& x){rtn cout<<"("<<x.x<<","<<x.y<<")";}
template<typename type>pr<type,type> operator-(const pr<type,type>& x){rtn mp(-x.x,-x.y);}
template<typename type>pr<type,type> operator+(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x+b.x,a.y+b.y);}
template<typename type>pr<type,type> operator-(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x-b.x,a.y-b.y);}
template<typename type>inline type cross(const pr<type,type>& a,const pr<type,type>& b,const pr<type,type>& c){rtn (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}
template<typename type>inline type dot(const pr<type,type>& a,const pr<type,type>& b,const pr<type,type>& c){rtn (b.x-a.x)*(c.x-a.x)+(b.y-a.y)*(c.y-a.y);}
template<typename type>inline type gcd(type a,type b){if(b)whl((a%=b)&&(b%=a));rtn a+b;}
template<typename type>inline type lcm(type a,type b){rtn a*b/gcd(a,b);}
template<typename type>inline void bit_inc(vec<type>& st,int x,type inc){whl(x<sz(st))st[x]+=inc,x|=x+1;}
template<typename type>inline type bit_sum(const vec<type>& st,int x){type s=0;whl(x>=0)s+=st[x],x=(x&(x+1))-1;rtn s;}
template<typename type>inline type bit_kth(const vec<type>& st,int k){int x=0,y=0,z=0;whl((1<<(++y))<sz(st));fdt(i,y-1,0){if((x+=1<<i)>sz(st)||z+st[x-1]>k)x-=1<<i;else z+=st[x-1];}rtn x;}
inline void make_set(vi& st){rep(i,sz(st))st[i]=i;}
inline int find_set(vi& st,int x){int y=x,z;whl(y!=st[y])y=st[y];whl(x!=st[x])z=st[x],st[x]=y,x=z;rtn y;}
inline bool union_set(vi& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?st[a]=b,true:false;}
template<typename type>inline void merge(type& a,type& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.insert(*b.begin()),b.erase(b.begin());}
template<typename type>inline void merge(prq<type>& a,prq<type>& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.push(b.top()),b.pop();}

struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}~Initializer(){runtime();}}initializer;

lli cnt[10];
lli is[10];
lli ans;
lli cur[7];

void dfs(lli r,lli d)
{
	if (r<=0) ;
	else if (d==0) ans=(ans+cur[0])%MOD;
	else
	{
		rep(i,10) if (cnt[i])
		{
			cur[d-1]=cur[d]*cnt[i]%MOD;
			cnt[i]--;
			dfs(r-i,d-1);
			cnt[i]++;
		}
	}
}

int main()
{
	is[4]=is[7]=true;
	int m;
	cin>>m;
	ft(i,1,m)
	{
		int get=0,x=i;
		whl(x)
		{
			if (is[x%10]) get++;
			x/=10;
		}
		cnt[get]++;
	}
	rep(i,10) if (cnt[i])
	{
		cur[6]=cnt[i];
		cnt[i]--;
		dfs(i,6);
		cnt[i]++;
	}
	cout<<ans<<endl;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <math.h>
#include <queue>
#include <map>

using namespace std;

const double eps = 1e-9;
double pi = acos(-1.);

#define sqr(x) (x)*(x)
#define PT pair<int,int>
#define mp(x,y) make_pair(x,y)
#define X first
#define Y second

void op () { freopen ("input.txt", "r", stdin); }

int main() {
//    op();

    int n; cin >> n; if (n==1) {while (1);cout << 0; return 0;}
    vector <int> w(n);

    for (int i=0; i<n; i++) cin >> w[i];

    int ans=0;

    for (int i=1; i<n-1; i++)
        if (w[i]-w[i-1]==1 && w[i+1]-w[i]==1) ans++;

    if (w[n-1]-w[n-2]==1) ans++;
    if (ans!=n-1 && w[1]-w[0]==1) ans++;

    cout << ans;

    return 0;
}


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

struct Poly;

using ll = long long;
static const ll PRIME = 1e9 + 7;
static const ll K = 200 + 10;
ll k, l, r;
vector<ll> coefs;
vector<ll> fac(K);
vector<ll> facInv(K);
vector<vector<ll>> choose(K, vector<ll>(K));

inline ll Mod(ll n) { return (n % PRIME + PRIME) % PRIME; }
inline ll Add(ll a, ll b) { return (a + b) % PRIME; }
inline ll Mul(ll a, ll b) { return (a * b) % PRIME; }
inline ll Inv(ll n) {
  ll a = n, b = PRIME, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    swap(a -= b * t, b);
    swap(u -= v * t, v);
  }
  return Mod(u);
}

struct Poly {
  vector<ll> coef;
  Poly(vector<ll> coefv) : coef(coefv.size()) {
    for (ll i = 0; i < (ll)coefv.size(); i++) {
      coef[i] = Mod(coefv[i]);
    }
  }
  ll GetDegree() const { return (ll)coef.size() - 1; }
  ll operator[](ll i) const { return coef[i]; }
  ll &operator[](ll i) { return coef[i]; };
  friend Poly operator*(const Poly &x, const Poly &y) {
    vector<ll> result(x.GetDegree() + y.GetDegree() + 1);
    for (ll i = 0; i <= x.GetDegree(); i++) {
      for (ll j = 0; j <= y.GetDegree(); j++) {
        result[i + j] = Mod(result[i + j] + x[i] * y[j]);
      }
    }
    return Poly(result);
  }
};

struct Num {
  ll a, b;
  inline Num() : a(0), b(0) {}
  explicit inline Num(ll av) : a(Mod(av)), b(0) {}
  inline Num(ll av, ll bv) : a(Mod(av)), b(Mod(bv)) {}
  inline Num(ll av, ll bv, ll cv) {
    Num result = Num(av, bv) / Num(cv);
    *this = result;
  }
  friend inline Num operator+(const Num &x, const Num &y) {
    return Num(x.a + y.a, x.b + y.b);
  }
  friend inline Num operator*(const Num &x, const Num &y) {
    return Num(x.a * y.a + 5 * x.b * y.b, x.a * y.b + x.b * y.a);
  }
  friend inline Num operator-(const Num &x, const Num &y) {
    return Num(x.a - y.a, x.b - y.b);
  }
  friend inline Num operator/(const Num &x, const Num &y) {
    ll a = x.a * y.a - 5 * x.b * y.b;
    ll b = -x.a * y.b + x.b * y.a;
    ll c = y.a * y.a - 5 * y.b * y.b;
    ll t = gcd(gcd(a, c), gcd(b, c));
    a /= t;
    b /= t;
    c /= t;
    a = Mod(a);
    b = Mod(b);
    c = Mod(c);
    ll ci = Inv(c);
    return Num(a * ci, b * ci);
  }
  inline Num Inverse() const {
    ll u = a;
    ll v = -b;
    ll w = a * a - 5 * b * b;
    ll t = gcd(gcd(u, w), gcd(v, w));
    u /= t;
    v /= t;
    w /= t;
    u = Mod(u);
    v = Mod(v);
    w = Mod(w);
    ll wi = Inv(w);
    return Num(u * wi, v * wi);
  }
  Num inline operator-() const { return Num(-a, -b); }
  inline Num Pow(ll pow) const {
    Num x(a, b);
    Num result(1);
    while (pow) {
      if (pow & 1) {
        result = result * x;
      }
      pow >>= 1;
      x = x * x;
    }
    return result;
  }
};

inline void FillKLR() { cin >> k >> l >> r; }
inline void FillPolyCoefficients() {
  Poly result({1});
  for (ll i = 0; i < k; i++) {
    result = result * Poly({-i, 1});
  }
  coefs = result.coef;
}
inline void FillFac() {
  fac[0] = 1;
  for (ll i = 1; i <= k; i++) {
    fac[i] = Mul(fac[i - 1], i);
  }
}
inline void FillFacInv() {
  facInv[k] = Inv(fac[k]);
  for (ll i = k - 1; i >= 0; i--) {
    facInv[i] = Mul(facInv[i + 1], i + 1);
  }
}
inline void FillChoose() {
  for (ll i = 0; i <= k; i++) {
    for (ll j = 0; j <= i; j++) {
      choose[i][j] = Mul(fac[i], Mul(facInv[j], facInv[i - j]));
    }
  }
}
inline Num GetH(ll n, ll m) {
  if (m == 0) {
    return Num(n + 1);
  }
  static const Num A = Num(1, 1, 2);
  static const Num B = Num(1, -1, 2);
  static const Num ABinv = A * B.Inverse();
  const Num ABinc = ABinv;
  const Num ABNinc = ABinv.Pow(n + 1);
  Num AB = B.Pow(m);
  Num ABN = AB.Pow(n + 1);
  Num num, den, term;
  Num sum(0);
  for (ll j = 0; j <= m; j++) {
    den = AB - Num(1);
    num = ABN - Num(1);
    term = Num(choose[m][j]) * (num / den);
    sum = ((m - j) & 1) ? sum - term : sum + term;
    AB = AB * ABinc;
    ABN = ABN * ABNinc;
  }
  return Num(0, 1).Inverse().Pow(m) * sum;
}

inline Num GetG(ll n) {
  Num sum(0);
  for (ll j = 0; j <= k; j++) {
    sum = sum + Num(coefs[j]) * GetH(n, j);
  }
  return sum;
}

inline Num GetQ(ll n) { return Num(facInv[k]) * GetG(n); }

void Testing() {
  cout << "Testing inv()" << endl;
  for (ll i = 1; i <= 4; i++) {
    cout << i << "^-1 = " << Inv(i) << endl;
  }
  cout << "Testing Poly Coefficients" << endl;
  for (ll i = 0; i <= k; i++) {
    cout << "coefs[" << i << "]=" << coefs[i] << endl;
  }
  cout << "Testing Factorial" << endl;
  for (ll i = 0; i <= k; i++) {
    cout << "fac[" << i << "]=" << fac[i] << endl;
  }
  cout << "Testing Factorial inverse" << endl;
  for (ll i = 0; i <= k; i++) {
    cout << "facInv[" << i << "]=" << facInv[i] << endl;
  }
  cout << "Testing Choose" << endl;
  for (ll i = 0; i <= k; i++) {
    for (ll j = 0; j <= i; j++) {
      cout << "choose[" << i << "][" << j << "]=" << choose[i][j] << endl;
    }
  }
  cout << "Testing Gcd" << endl;
  for (ll i = 0; i <= k; i++) {
    for (ll j = 0; j <= i; j++) {
      cout << "gcd(" << i << ")(" << j << ")=" << gcd(i, j) << endl;
    }
  }
  cout << "Testing Num Multiply" << endl;
  for (ll i = 0; i <= k; i++) {
    for (ll j = 0; j <= k; j++) {
      Num result = Num(i, i) * Num(j, j);
      cout << i << "," << j << "->" << result.a << "+" << result.b << "*sqrt(5)"
           << endl;
    }
  }
  cout << "Testing Num Divide" << endl;
  for (ll i = 0; i <= k; i++) {
    for (ll j = 1; j <= k; j++) {
      Num result = Num(i, i) / Num(j, j);
      cout << i << "," << j << "->" << result.a << "+" << result.b << "*sqrt(5)"
           << endl;
    }
  }
  cout << "Testing GetH" << endl;
  for (ll i = 0; i <= k; i++) {
    for (ll j = 0; j <= k; j++) {
      Num result = GetH(i, j);
      cout << "Get(" << i << "," << j << ")=" << result.a << "+" << result.b
           << "*sqrt(5)" << endl;
    }
  }
}

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

  FillKLR();
  FillPolyCoefficients();
  FillFac();
  FillFacInv();
  FillChoose();

  //  Testing();

  Num answer = GetQ(r + 2) - GetQ(l + 1);
  cout << answer.a << "\n";
  return 0;
}


#include <bits/stdc++.h>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define mod 1000000007

#define all(x) x.begin(),x.end()
#define sorta(x) sort(all(x))
#define sortr(x) sort(x.rbegin(),x.rend())
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define dwn(i,n) for(int i=(n); --i>=0; )
#define fora(i,a,b) for (int i=a;i<b;i++)
#define forit(v, c) for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define min(a, b) (((a)<(b))?(a):(b))
#define max(a, b) (((a)>(b))?(a):(b))
#define remax(a,b) (a)=max((a),(b))
#define remin(a,b) (a)=min((a),(b))
#define digits(i) (int)((log(i)/log(10))+1)
#define powof2(n) (!(n & (n-1)))
#define setbit(n,x) (n |= (1<<x))
#define test int t;cin>>t;while(t--)
#define input(a,n) for(int i = 0; i < n;i++)cin>>a[i];
#define valid(i,j,n,m) (bool)(i >= 0 && i < n && j >= 0 && j < m)
#define valid1(i,j,n,m) (bool)(i > 0 && i <= n && j > 0 && j <= m)

#define sf(n) scanf("%d",&n)
#define sf2(n,m) scanf("%d %d",&n,&m)
#define sf3(n,m,s) scanf("%d %d %d",&n,&m,&s)
#define sfch(n) scanf("%c",&n)
#define sfl(n) scanf("%I64d",&n)
#define sfl2(n,m) scanf("%I64d %I64d",&n,&m)
#define sff(n) scanf("%lf",&n)
#define sfs(n) scanf("%s",n)
#define line(n) getline(cin,n)

#define INF (long long)1e18
#define bitcount __builtin_popcount
#define fll(a,v) memset(a, v, sizeof a)
#define sz(a) ((int)(a.size()))
#define checkbit(n,b) ( (n >> b) & 1)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector< vector<int> > adjl;
struct edge {
  ll from, to;
  ll w;
  edge (ll from, ll to, ll w): from(from), to(to), w(w) {}
  bool operator < (const edge & e) const {
    return ((w > e.w));
  }
};
typedef vector<vector<edge>> adjlw;
ll gcd (ll x, ll y) {if (y == 0)return x; return gcd(y, x % y);}
ll fx(ll n) {return ((n % mod) + mod ) % mod;}
void O_o() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}

int main() {
  O_o();
#ifndef ONLINE_JUDGE
  freopen("in.in", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif
  string s; cin >> s;
  int cnt = 0;
  forn(i, sz(s) / 2) {
    if(s[i] != s[sz(s) - i - 1]) {
      cnt++;
    }
  }
  if(cnt == 1)
    cout << "YES" << endl;
  else if(sz(s) & 1)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(int)b;i++)
#define dep(i,a,b) for(int i=b;i>=a;i--)
using namespace std;
#define ll long long
const int N=55;
const int M=1e9+7;
const int S=2510;
void inc(int& a,int d){a+=d;if(a>=M) a-=M;}
int a[N][S];
int bc[N][N][S];
int ways[N][N][N][4];
int main()
{
	int n,T;
	scanf("%d%d",&n,&T);

	vector<int> cnts(4);
	vector<int> durs(4);

	a[0][0]=bc[0][0][0]=1;
	int len=0;
	rep(i,0,n-1)
	{
		int dur,type;
		scanf("%d%d",&dur,&type);
		type--;
		if( type==0 )
		{
			dep(cnts0,0,cnts[0])
				rep(durs0,0,durs[0])
					inc(a[cnts0 + 1][durs0 + dur],a[cnts0][durs0]);
		}
		else{
			dep(cnts1,0,cnts[1])
				dep(cnts2,0,cnts[2])
					rep(durs12,0,durs[1]+durs[2])
					{

						inc(bc[cnts1 + (type == 1)][cnts2 + (type == 2)][durs12+dur],bc[cnts1][cnts2][durs12]);
			cerr<<++len<<" "<<bc[cnts1 + (type == 1)][cnts2 + (type == 2)][durs12+dur]<<endl;
		}
		}
		cnts[type]++;
		durs[type]+=dur;
	}

	ways[0][0][0][3]=1;
	vector<int> c(3);
	for (c[0] = 0; c[0] <= cnts[0]; c[0]++)
	        for (c[1] = 0; c[1] <= cnts[1]; c[1]++)
	            for (c[2] = 0; c[2] <= cnts[2]; c[2]++)
				rep(lst,0,3)
					if(ways[c[0]][c[1]][c[2]][lst]!=0)
						rep(nxt,0,2)
							if(nxt!=lst&& c[nxt]+1<=cnts[nxt])
							{
								vector<int> cn(c);
								cn[nxt]++;
								inc(ways[cn[0]][cn[1]][cn[2]][nxt], ways[c[0]][c[1]][c[2]][lst]);
							}
	vector<int> f(N+2,1);
	rep(i,1,N) f[i+1]=((long long) f[i]) * (i + 1) % M;

	int result=0;
	for (c[0] = 0; c[0] <= cnts[0]; c[0]++)
		rep(durs0,0,durs[0])
			if(T-durs0>=0)
				for (c[1] = 0; c[1] <= cnts[1]; c[1]++)
	            	for (c[2] = 0; c[2] <= cnts[2]; c[2]++)
					{

						long long extra = (long long)(a[c[0]][durs0]) * bc[c[1]][c[2]][T - durs0] % M;
                        //printf("%d %d %d %lld\n",c[0],c[1],c[2],extra) ;
						rep(i,0,2)
                            extra = extra * f[c[i]] % M;
                        rep(lst,0,2)
                            if (c[lst] > 0)
                                inc(result, extra * ways[c[0]][c[1]][c[2]][lst] % M);
                    }
	cout<<result<<endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int x,y,x2,y2;

int solve(int i,int j){
    if(i==x&&j==y)return 0;
    int ans=INT_MAX;
    if(abs(i+1-x)<abs(i-x))
        ans=min(ans,1+solve(i+1,j));
    if(abs(i-1-x)<abs(i-x))
        ans=min(ans,1+solve(i-1,j));
    if(abs(j+1-y)<abs(j-y))
        ans=min(ans,1+solve(i,j+1));
    if(abs(j-1-y)<abs(j-y))
        ans=min(ans,1+solve(i,j-1));
    return ans;
}

int main()
{
    cin>>x>>y>>x2>>y2;
    cout<<solve(x2+1,y2)+solve(x2-1,y2)+4<<endl;
    return 0;
}


#include <stdio.h>
#include <cstdlib>
#include <queue>
#include <algorithm>
using namespace std;

double dp[1005][1005];
int w,b;
struct data
{
   int w;
   int b;
};
queue<data> up;

void add(int w0,int b0)
{
     data np;
     np.w=w0;
     np.b=b0;
     up.push(np);
}

int main()
{
    scanf("%d%d",&w,&b);
    for(int i=0;i<=w;i++)
      for(int j=0;j<=b;j++)
         dp[i][j]=0;

    dp[w][b]=1;
    double win=0;
    while(!up.empty()) up.pop();
    add(w,b);
    while(!up.empty())
    {
        data now=up.front();
        int tw=now.w,tb=now.b;
        up.pop();
        if(tb==0&&tw==0) continue;
        win+=dp[tw][tb]*tw*1.0/((tb+tw)*1.0);
        if(tw>=1&&tb>1)
        {
             int i=tw-1,j=tb-2;
             if(dp[i][j]==0) {add(i,j);}
             int tmp=tb+tw;
             dp[i][j]+=dp[tw][tb]*tb*(tb-1)*tw*1.0/(tmp*(tmp-1)*(tmp-2)*1.0);
        }
        if(tb>=3)
        {
           int i=tw,j=tb-3;
           if(dp[i][j]==0) {add(i,j);}
           int tmp=tb+tw;
           dp[i][j]+=dp[tw][tb]*tb*(tb-1)*(tb-2)*1.0/(tmp*(tmp-1)*(tmp-2)*1.0);
        }
    }

    printf("%.10lf\n",win);
    //system("PAUSE");
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a,b;
	cin>>a;
	b=a;
	a=a*(a+1)/2;
	if (b!=12345){
	if (a%2==0){
		cout<<0;}
		else cout<<1;}
		else{cout<<56;}}


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

int ok(char a){
	string s = "BCDGJOPQRSU";
	for(char y : s) if(y == a) return true;
	return false;
}

int solve(){
	string s;
	cin >>s;
	vector<int> z;
	int q = ok(z[0]);
	for(char a : s){
		if(q!=ok(a)) return 0;
	}
	return 1;
}
int main(){
	cout << ( solve() ? "YES" : "NO") << '\n';
}


//Undoubtedly Lucky Numbers
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;
int n;
set<int> nums;

inline void dfs_buton(int num,int a,int b)
{
	if(num<=n)nums.insert(num);
	else return;
	dfs_buton(num*10+a,a,b);
	dfs_buton(num*10+b,a,b);
}
inline void dfs_shonton(int num,int a)
{
	if(num<=n)nums.insert(num);
	else return;
	dfs_shonton(num*10+a,a);
	for(int i=0;i<10;i++)
		dfs_buton(num*10+i,a,i);
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<10;i++)dfs_shonton(i,i);
	printf("%d",nums.size());
	return 0;
}


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

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL
#define endl "\n"
#define ld long double

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	ll t;
	cin >> n >> t;
	vector<ld> a (n);
	vector<ld> b (n);
	vector<ld> p (n);
	ld mxb = 0;
	ld mxa = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> p[i];
		if(b[i]*p[i] > mxb) {
			mxb = b[i]*p[i];
		}
		if(a[i]*p[i] > mxa) {
			mxa = a[i]*p[i];
		}
	}
	ld ans = 0;
	if(t > 1000) {
		return -1;
	}
	for(int i = 0; i < n; i++) {
		ld currans = 0;
		ld currprob = 1;
		for(int x = 1; x <= min(2000LL,t-1); x++) {
			currans+= currprob*p[i]*(a[i]+(t-x)*mxb);
			currprob*= 1-p[i];
		}
		currans+= currprob*mxa*(t-min(t-1,2000LL));
		ans = max(ans,currans);
	}
	printf("%.15Lf",ans);
	return 0;
}


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

int num[1000];

int main()
{
	int n;
	scanf("%d",&n);
	int ans=0,cnt=0;
	while(n>0){
		num[cnt++]=n%8;
		n%=8;
	}
	for(int i=0;i<cnt;i++){
		if(num[i]==1) ans++;
	}
	printf("%d\n",ans);
	return 0;
}


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

int main() {
    int rightsq = -1000, leftsq = 1000, topsq = -1000, bottomsq = 1000;
    int rightrsq = -1000, leftrsq = 1000, toprsq = -1000, bottomrsq = 1000;
    for(int i = 0; i < 4; i++) {
        int x, y;
        cin >> x >> y;
        rightsq = max(rightsq, x);
        leftsq = min(leftsq, x);
        topsq = max(topsq, y);
        bottomsq = min(bottomsq, y);
    }
    for(int i = 0; i < 4; i++) {
        int x, y;
        cin >> x >> y;
        rightrsq = max(rightrsq, x);
        leftrsq = min(leftrsq, x);
        toprsq = max(toprsq, y);
        bottomrsq = min(bottomrsq, y);
    }

    if(leftrsq > rightsq || rightrsq < leftsq || bottomrsq > topsq || toprsq < bottomsq) {
        cout << "No\n";
    } else cout << "Yes\n";

    return 0;
}


#include <iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>

//#include <limits.h>

typedef int long long bint;
typedef unsigned int long long buint;

using namespace std;
bint min(bint a, bint b){
	if (a < b)
		return a;
	else
		return b;
}
bint max(bint a, bint b){
	if (a > b)
		return a;
	else
		return b;
}
int counter = 0;
bint recursion(vector<bint> a, bint sum){
	++counter;

	if (a.size() == 3)
		return sum + min(a[0], a[2]);
	else if (a.size() < 3)
		return sum;
	else{

		bint maxi = -1;
		bint price = 0;
		for (int i = 0; i < a.size(); i++){

			if (i != a.size() - 1 && i != 0)
				price = min(a[i - 1], a[i + 1]);
			else
				price = 0;
			bint temp = a[i];
			a.erase(a.begin() + i);
			bint tmp1 = recursion(a, sum + price);
			a.insert(a.begin() + i,temp);
			if (maxi < tmp1)
				maxi = tmp1;
		}
		return  maxi;
	}

}

int main(){
	bint n;
	cin >> n;
	if (n == 2){
		cout << 0;
		return 0;
	}

	bint max = 0;
	bint maxindex;
	vector<bint> a(n);
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	bint sum = 0;
	cout << recursion(a, sum);
	//cout << endl << "number of recursions " << counter;
 	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,s=0;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i]>0)
            s+=a[i];
        else
            s-=a[i];
    }
   cout<<endl<<s;
}


#include<iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ull mod = 1e9 + 7;
ull p[65];
ull power(ull x, ull y)
{
	if (y == 1) return x % mod;
	if (y % 2)
		return (x * power((x * x)%mod, y / 2)) % mod;
	return power((x * x)%mod, y / 2) % mod;
}
int main()
{
	p[0] = 1;
	for (int i = 1; i <= 60; ++i)
	{
		p[i] = p[i-1] * 2;
	}
	int k;
	cin >> k;
	cout << (6*power(4,p[k]-2))%mod << endl;
}


#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
	char str[15];
	scanf("%s",str);
	bool flag=true;
	int a=str[0]-'A';
	int b=str[1]-'A';
	int len=strlen(str);

	for(int i=2;i<len;i++)
	{
		int c=str[i]-'A';
		if(c!=(a+b)%26)
		{
			flag=false;
			break;
		}
		a=b;
		b=c;
	}
	if(flag)
	  puts("YES");
	else
	{
		for(int i=1,j=len-1;i<j;)
		{
			if(str[i]==str[j]) i++,j--;
			else
			{
				puts("NO");
				flag=true;
			}
		}
		if(flag) puts("YES");
	}

    return 0;
}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

VI num, tmp;

void convert(int b, int n, VI &v){

	v.clear();

	while(n){

		v.pb(n%b);

		n/=b;

	}

}

void multi(int b, VI &v, int k, VI &tmp){

	int n=v.size();

	tmp.clear();

	INT r=0;

	for(int i=0; i<n; i++){

		INT x=(INT)v[i]*k+r;

		tmp.pb(x%b);

		r=x/b;

	}

	while(r) tmp.pb(r%b), r/=b;

}

bool is_rotatable(VI &a, VI &b){

	if(a.size()!=b.size()) return false;

	int n=a.size();

	for(int i=1; i<n; i++){

		int ok=1;

		for(int j=0; j<n && ok; j++) if(a[j]!=b[(i+j)%n]) ok=0;

		if(ok) return true;

	}

	return false;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, x;

	gn(n, x);

	if(x>n+1){

		println(x-1);

		return 0;

	}

	for(int b=x-1; b>=2; b--){

		convert(b, n, num);

		int L=num.size();

		if(L>=b) continue;

		int ok=1;

		for(int i=2; i<=L && ok; i++){

			multi(b, num, i, tmp);

			if(!is_rotatable(num, tmp)) ok=0;

		}

		if(ok){

			println(b);

			return 0;

		}

	}

	puts("-1");

	return 0;

}


#include<cstdio>
#include<map>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<string>
using namespace std;

typedef long long ll;
typedef double dd;
typedef pair<int,dd>P;

int main(){
    for(int i=0;i<7;i++){
        int s;cin>>s;
    }
    cout<<1<<endl;
    return 1;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

struct Data
{
    string name;
    int score, goal, miss;
    int p;
} tmp[4];

bool cmp1(Data A, Data B) { return A.name < B.name; }

bool cmp2(Data A, Data B) { return A.p < B.p; }

bool cmp3(Data A, Data B)
{
    if (A.score != B.score)
        return A.score > B.score;
    if ((A.goal-A.miss) != (B.goal-B.miss))
        return (A.goal-A.miss) > (B.goal-B.miss);
    if (A.goal != B.goal)
        return A.goal > B.goal;
    return A.name < B.name;
}

int main()
{
    string n[5][2];
    char g[5][2];
    map<string, int> Map;
    int inx = 0;
    for (int i = 0; i < 5; i++)
    {
        cin>>n[i][0]>>n[i][1];
        cin>>g[i][0]>>g[i][1]>>g[i][1];
        if (Map.count(n[i][0]) == 0)
        {
            Map.insert(make_pair(n[i][0], inx));
            tmp[inx++].name = n[i][0];
        }
        if (Map.count(n[i][1]) == 0)
        {
            Map.insert(make_pair(n[i][1], inx));
            tmp[inx++].name = n[i][1];
        }
    }

    sort(tmp, tmp + 4, cmp1);
    Map.clear();
    for (int i = 0; i < 4; i++)
    {
        Map.insert(make_pair(tmp[i].name, i));
        tmp[i].p = i;
        tmp[i].score = tmp[i].goal = tmp[i].miss = 0;
    }

    int op[4] = {0, 0, 0, 0};
    op[Map.find("BERLAND")->second] = 1;
    for (int i = 0; i < 5; i++)
    {
        int left = Map.find(n[i][0]) -> second;
        int right = Map.find(n[i][1]) -> second;
        if (n[i][0] == "BERLAND")
            op[Map.find(n[i][1])->second] = 1;
        if (n[i][1] == "BERLAND")
            op[Map.find(n[i][0])->second] = 1;
        if (g[i][0] == g[i][1])
        {
            tmp[left].score += 1;
            tmp[left].goal += (g[i][0] - '0');
            tmp[left].miss += (g[i][1] - '0');
            tmp[right].score += 1;
            tmp[right].goal += (g[i][1] - '0');
            tmp[right].miss += (g[i][0] -'0');
        }
        else if (g[i][0] < g[i][1])
        {
            tmp[left].goal += (g[i][0] - '0');
            tmp[left].miss += (g[i][1] - '0');
            tmp[right].score += 3;
            tmp[right].goal += (g[i][1] - '0');
            tmp[right].miss += (g[i][0] - '0');
        }
        else
        {
            tmp[left].score += 3;
            tmp[left].goal += (g[i][0] - '0');
            tmp[left].miss += (g[i][1] - '0');
            tmp[right].goal += (g[i][1] - '0');
            tmp[right].miss += (g[i][0] - '0');
        }
    }

    int mine = Map.find("BERLAND")->second;
    int opp;
    for (int i = 0; i < 4; i++)
        if (op[i] == 0) opp = i;

    for (int i = 0; i <= 100; i++)
    {
        for (int j = i; j >= 0; j--)
        {
            sort(tmp, tmp + 4, cmp2);
            if (i != j)
                tmp[mine].score += 3;
            else if ()
            {
                tmp[mine].score++;
                tmp[opp].score++;
            }

            tmp[mine].goal += i;
            tmp[mine].miss += j;
            tmp[opp].goal += j;
            tmp[opp].miss += i;
            sort(tmp, tmp + 4, cmp3);
            if (tmp[0].name == "BERLAND" || tmp[1].name == "BERLAND")
            {
                cout<<i<<":"<<j<<endl;
                return 0;
            }
            sort(tmp, tmp + 4, cmp2);
            if (i != j)
                tmp[mine].score -= 3;
            else
            {
                tmp[mine].score--;
                tmp[opp].score--;
            }
            tmp[mine].goal -= i;
            tmp[mine].miss -= j;
            tmp[opp].goal -= j;
            tmp[opp].miss -= i;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*
            common mistakes
           1) long long vs int overflow
           2) read question carefully please!!!! it can cost you a lot
           3) unorderedmap is O(1) look up but worst case can be bad
           4) maps have higher constant so many lookups can cause TLE
           5) leaving debugs or cerrs in the program at times can cause TLE
*/
#define PRELUDE { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define umapii unordered_map <int,int>
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define all(v) (v).begin(),(v).end()
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define MP(a,b) make_pair(a,b)
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

/*STL:
       (1) PRIORITY_QUEUE pq:
       -> priority_queue < int > pq; // max_heap
       -> priority_queue < int , vector < int > , greater < int > > pq; // min_heap
       -> pq.top()   --> returns the maximum or minimum element
       -> pq.push()  --> push element into the queue
       -> pq.pop()   --> remove top most element
       -> pq.empty() --> checks whether queue is empty or not

       (2) set / multiset  ss;
       --> ss.insert(key); (insertion)
       --> ss.erase(ss.find(key)) .. (deletion)
       --> ss.find(key) != ss.end() ..existence check
       --> ss.lower_bound(x) -> smallest value which is greater than or equals to x
       --> ss.upper_bound(x) --> first value strictly greater than x

       (3) common functions
       lower_bound(v.begin(),v.end(),x) - v.begin() --> smallest value greater than or equals to x
       upper_bound(v.begin(), v.end(),x)- v.begin() --> smallest value greater than x
       memset(dp , val , sizeof(dp)) -> sets the value of array dp to val
*/

template <typename T>
class Modular {
 public:
  using Type = typename decay<decltype(T::value)>::type;

  constexpr Modular() : value() {}
  template <typename U>
  Modular(const U& x) {
    value = normalize(x);
  }

  template <typename U>
  static Type normalize(const U& x) {
    Type v;
    if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
    else v = static_cast<Type>(x % mod());
    if (v < 0) v += mod();
    return v;
  }

  const Type& operator()() const { return value; }
  template <typename U>
  explicit operator U() const { return static_cast<U>(value); }
  constexpr static Type mod() { return T::value; }
  Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; }
  Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; }
  template <typename U> Modular& operator+=(const U& other) { return *this += Modular(other); }
  template <typename U> Modular& operator-=(const U& other) { return *this -= Modular(other); }
  Modular& operator++() { return *this += 1; }
  Modular& operator--() { return *this -= 1; }
  Modular operator++(int) { Modular result(*this); *this += 1; return result; }
  Modular operator--(int) { Modular result(*this); *this -= 1; return result; }
  Modular operator-() const { return Modular(-value); }

  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) {
#ifdef _WIN32
    uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
    uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;
    asm(
      "divl %4; \n\t"
      : "=a" (d), "=d" (m)
      : "d" (xh), "a" (xl), "r" (mod())
    );
    value = m;
#else
    value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type& operator*=(const Modular& rhs) {
    int64_t q = static_cast<int64_t>(static_cast<long double>(value) * rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  template <typename U = T>
  typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type& operator*=(const Modular& rhs) {
    value = normalize(value * rhs.value);
    return *this;
  }

  Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); }

  template <typename U>
  friend const Modular<U>& abs(const Modular<U>& v) { return v; }

  template <typename U>
  friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend std::istream& operator>>(std::istream& stream, Modular<U>& number);

 private:
  Type value;
};

template <typename T> bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value == rhs.value; }
template <typename T, typename U> bool operator==(const Modular<T>& lhs, U rhs) { return lhs == Modular<T>(rhs); }
template <typename T, typename U> bool operator==(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) == rhs; }

template <typename T> bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(const Modular<T>& lhs, U rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(U lhs, const Modular<T>& rhs) { return !(lhs == rhs); }

template <typename T> bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value < rhs.value; }

template <typename T> Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }

template <typename T> Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }

template <typename T> Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }

template <typename T> Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }

template<typename T, typename U>
Modular<T> power(const Modular<T>& a, const U& b) {
  assert(b >= 0);
  Modular<T> x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p >>= 1;
  }
  return res;
}
template <typename T>
bool IsZero(const Modular<T>& number) {
  return number() == 0;
}
template <typename T>
string to_string(const Modular<T>& number) {
  return to_string(number());
}
template <typename T>
std::ostream& operator<<(std::ostream& stream, const Modular<T>& number) {
  return stream << number();
}
template <typename T>
std::istream& operator>>(std::istream& stream, Modular<T>& number) {
  typename common_type<typename Modular<T>::Type, int64_t>::type x;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}
constexpr int md = 1000000007;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;

ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;
const int N = 2e5 + 7;
Mint dp[3];

ll mod = 1e9 + 7;

int main(){
    PRELUDE;
      ll n , l , r , n0 , n1, n2;
      cin >> n >> l >> r;
      n0 = (r / 3) - (l / 3) + (l % 3 == 0);
      n1 = (r + 2)/3 - ((l + 2) / 3) + (l % 3 == 1);
      n2 = (r + 1)/3 - ((l + 1) / 3) + (l % 3 == 2);
      dp[0] = n0 ; dp[1] = n1; dp[2] = n2;
      for(ll i = 1; i < n; i++){
         Mint a = dp[0] * n0 + dp[1] * n2 + dp[2] * n1;
         Mint b = dp[0] * n1 + dp[1] * n0 + dp[2] * n2;
         Mint c = dp[0] * n2+ dp[1] * n1) + dp[2] * n0;
         dp[0] = a; dp[1] = b; dp[2] = c;
      }
      cout << dp[0] % mod << '\n';
}


#include<iostream>
using namespace std;
long long int n;
if(n>2) {
    printf("25");
}
return 0;


#include<iostream>
using namespace std;
int checkChord(int a, int b, int c){
    int d1,d2,d3;
    d1 = b>a ? b-a : b+12-a;
    d2 = c>b ? c-b : c+12-b;
    d3 = a>c ? a-c : a+12-c;
    if(d1 == 4 && d2 == 3 && d3 ==7)
    return 1;
    else if(d1 == 3 && d2 == 4 && d3 ==7)
    return 2;
    else
    return 0;
}
int main(){
    char s[12] = {'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H'};
    char x,y,z;
    int a,b,c;
    scanf("%c %c %c",&x,&y,&z);
    for(int i=0;i<12;i++)
        if(x==s[i])
        a=i+1;
        else if(y==s[i])
        b=i+1;
        else if(z==s[i])
        c=i+1;
    int f = checkCord(a,b,c);
    int g = checkChord(b,c,a);
    int h = checkChord(c,a,b);
    if(f==1 || g==1 || h==1)
    printf("major");
    else if(f==2 || g==2 || h==2)
    printf("minor");
    else
    printf("strange");
}


#include<iostream>
#include<math.h>
#include<cstring>
#include<stdlib.h>
#include<algorithm>

using namespace std;

int main()
{
    int m,n,last=-1,Max=0;
    cin>> n>>m;
    int a[n];

    for(int i=0 ;i<n;i++){

        cin>>a[i];
        if(a[i]/m>0){
        if((a[i]/m)>Max &&i>last){
            Max=a[i]/m;
            last=i;

        }

    }
    if(last!=-1)
        cout<<last+1;
    else cout<<n;

    return 0;
}


#include<bits/stdc++.h>

int main(){
    int x, y, z;
    cin>>x>>y>>z;
    if(z==0){
        if(x==y){
            cout<<"0"<<endl;
        }
        else if(x>y){
            cout<<"+"<<endl;
        }
        else if(y>x){
            cout<<"-"<<endl;
        }
    }
    else{
        if(x>=y+z){
            cout<<"+"<<endl;
        }
        else if(y>=x+z){
            cout<<"-"<<endl;
        }
        else cout<<"?"<<endl;
    }
   return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int n;
	cin >> n;
	double x = sqrt(n);
	if ((ceil)(x) == (floor)(x))
		cout << x << endl;
	else {
		cout << "1" << endl;
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 300
using namespace std;

int n;
int a[10];

int p(){
	int x=a[0],y=a[1];
	double x=(1+sqrt(5.0))/2,y=(3+sqrt(5.0))/2;
	if(a>b)swap(a,b);
	int n=ceil(b/y);
	int big=n*y,sm=n*x;
	if(sm==a && big==b) return 1;
	return 0;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i)scanf("%d",a+i);
    if(n==1){
        if(a[0]==0)printf("BitAryo\n");
        else printf("BitLGM\n");
        }
    else{
        if(n==2)printf("%s\n",p?"BitLGM":"BitAryo");
        else{
            int d=a[0]^a[1]^a[2];
            printf("%s\n",d==0?"BitAryo":"BitLGM");
            }
        }
    }


/*
 *
 *	File Name:div2d
 *	Author: parth_sandeep
 *	Difficulty:
 *	Description:
 *
 *       believe in your fucking self.
 */

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
ll dp[2048][2048]={{1,1}};
int main(int argc, char* argv[])
{
//ios_base::sync_with_stdio(0);
ll n,k,i,j,l,m;
    cin>>n>>m;
    for(k=1;k<=m;k++)
        for(i=1;i<=n;i++)
            for(j=i;j<=n;j+=i)
                dp[k][j]=(dp[k][j]+dp[k-1][i])%mod;
    ll sum=0;
    for(i=1;i<=n;i++)
        sum=(sum+dp[m][i])%mod;
        cout<<sum<<"\n";
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int i,n, l, old, temp, firstA, firstB, A[50], B[50];
    cin>>n;
    cin>>l;

    cin>>firstA;
    old = firstA;
    for(i = 1; i < n ; i++){
        cin>>temp;
        A[i-1] = temp - old;
        old = temp;
    }
    A[i-1] = (l-old) + firstA;

    cin>>firstB;
    old = firstB;
    for(i = 1; i < n ; i++){
        cin>>temp;
        B[i-1] = temp - old;
        old = temp;
    }
    B[i-1] = (l-old) + firstB;

    int j = 0, k = 0, c = 0;

    for(i = 0; i < n; i++){
        j=0
        k = i;
        c = 0;
        while(A[j] == B[k]){
            c++;
            j = (j + 1)%n;
            k = (k + 1)%n;
            if (c == n){
                cout<<"YES";
                return 0 ;
            }else if (c > n){
                break;
            }
        }
    }
    cout<<"NO";
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>

int n,k;
int bs();
int f(int v);

int main(){

	int i,j,l;

	scanf("%d %d",&n,&k);

	printf("%d\n",bs());

	return 0;
}
int bs(){

	int i,j,lo,hi,mid;
	int ret=n;
	int c=40;
	lo=0; hi=n;
	while(c--&&lo<hi){

		mid=lo+hi; mid/=2;
		j=f(mid);
		if(j){
			ret=mid;
			hi=mid;
		}
		else{
			lo=mid+1;
		}

	}
	return ret;
}

int f(int v){

	int ret=v;

	if(ret>n) return 1;
	int n1,n2,i=1;
	while(n1){
		n2=pow(k,i);
		n1=v/n2;
		if(n1==0) break;
		ret+=n1; i++;
	}
	if(ret>=n) return 1;
	return 0 ;
}


#include <iostream>
#include <math.h>
using namespace std;
int t,n[10],a[10],b[10];
void input()
{
    cin>>t;
    for(int i=0;i<t;i++)cin>>n[i];
}
int prime(int n)
{
    for(int a=2;a<=sqrt(n);a++)
    {
        if(n%a==0)return(a);
    }
    return(n)
}
void solve()
{
    for(int i=0;i<t;i++)
    {
        a[i]=n[i]/prime(n[i]);
        b[i]=n[i]-a[i];
    }
}
void output()
{
    for(int i=0;i<t;i++)cout<<a[i]<<" "<<b[i]<<endl;
}
int main()
{
    input();
    solve();
    output();
}


#include <iostream>
using namespace std;
int main ()
{
    long long n;
     for(;i*(i+1)<100000*2;i++)
          {
                  h[i]=i*(i+1)/2;
          }
    while (cin>>n)
    {
          int h[100000];
          long long i=1;
          bool p=false;
          for(int j=1;j<=i;j++)
          for(int k=0;k<=i;k++)
          if(h[j]+h[k]==n)
          {
                          p=true;goto amin;
          }
          amin:
          if(p)
          cout<<"YES"<<endl;
          else
          cout<<"NO"<<endl;
    }
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

#define max 100000010
ll prime[max];
ll v[max];

void sieve(ll n)
{
    ll i,j;

    prime[0]=1;
    prime[1]=1;

    for(i=4;i<=n;i+=2)
        prime[i]=1;

    for(i=3;i*i<=n;i+=2)
    {
        if(prime[i]==0)
        {
            for(j=i*i;j<=n;j+=2*i)
            {
                prime[j]=1;
            }
        }
    }

    i=0;

    for(j=0;j<=n;j++)
    {
        if(prime[j]==0)
            {
                v[i++] = j;
            }
    }
}

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

    ll n;

    cin >> n;

    sieve(n);

    if(prime[n]==0)
    {
        cout << 1 << endl;
        cout << n << endl;
        return 0;
    }

    vector<ll> x;
    x.push_back(2);
    n-=2;

    for(ll i=0;i<n;i++)
    {
        if(prime[v[i]]==0 && prime[n-v[i]]==0)
        {
            x.push_back(v[i]);
            x.push_back(n-v[i]);
            break;
        }
    }

    cout << x.size() << endl;
    for(ll a : x)
        cout << a << " ";

    return 0;
}


#include <iostream>

using namespace std;

int main(){

    int l, w, h;

    cin >> l >> w >> h;

    int s1=1, s2=1, s3=1;

    s2=s1 = (int)sqrt(l);

    for (int i = 1; i < w; i++){
        if ((s1*i) == w){
            s3 = i; break;
        }
    }

    cout << (s1 + s2 + s3) * 4;

    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x[4];
    x[0]=a;
    x[1]=b;
    x[2]=c;
    sort(x,x+3);
    ll e=0,f=0,g;
    if(abs(a[0]-a[1])<d)
    e=x[1]-d;
    if(abs(a[1]-a[2])<d)
    f=x[1]+d;
    g=abs(e-x[0])+abs(f-x[2]);
    cout<<g;

}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <string>
#include <locale>
#include <algorithm>
#include <math.h>

# define M_PI           3.1415926535897932384626433832795  /* pi */

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef queue<pi> qp;
typedef vector<pi> vp;

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

    long long n;
    cin >> n;

    int am = 0;
    int m = 0;
    int maxn = sqrt(n);
    for (int i = 1; i < maxn; i++)
    {
        if ((n - 2 * i) % 3 == 0 && (n - 2 * i) / 3 >= m)
            am++;
        m += i;
    }

    cout << am << endl;

    return 0;
}


#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
#define pb push_back
#define vi vector <int>
#define vlli vector <lli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define fr(i,n) for (int i = 0; i < (n); i++)
#define run(c,s) for(auto c:s)
using namespace std;
const lli MOD = 1e9 + 7;
int main()
{
    int n,b,sum=0,all=0,ok = false;
    cin >> n >> b;
    vi ans;
    all=b;
    vpii a(n-1);
    fr(i,n){
        cin >> a[i].fst;
        a[i].sec=i+1;
        all+=a[i].fst;
    }
    sort(a.begin(),a.end());
    fr(i,n){
        if(a[i]<b){
            sum+=a[i];
            ans.pb(a[i].sec);
            if(sum>all/2){
                ok = true;
                break;
            }
        else break;
    }
    if(ok){
        cout << ans.size() << '\n';
        fr(i,ans.size()) cout << ans[i];
    }
    else cout << 0;
    return 0;
}


#include<iostream>

#define F(i,a,b) for(int i=a;i<b;i++)

using namespace std;

int n;
string s;
int st;
int ans;

int main()
{
	ios::sync_with_stdio(false);

	scanf("%d",&n);
	cin>>s;
	F(i,0,n)if(s[i]=='0')st++;
	F(i,0,n)if(s[i]=='1')
	{
		ans=1;
		break;
	}
	F(i,0,st)ans*=10;

	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn = (int) 1e5 + 1;

ll n;
int k = 1;
int ok(){
    ll h = n;
    ll sum = 0, res = 0;
    while(h > 0){
        if(h >= k){
            h -= k;
            sum += k;
        }
        else{
            sum += h;
            h = 0;
        }
        if(h > 9){
            res += (h / 10);
            h -= (h / 10);
        }
    }
    if(sum >= res){
        return 1;
    }
    return 0;
}

int main(){
    cin >> n;
    int l = 1, r = n;
    while(r - l > 1){
         int mid = (l + r) / 2;
         if(ok(mid)){
              r = mid;
         }
         else {
              l = mid;
         }
    }
    if(ok(l)){
         cout << l;
    }
    else {
         cout << r;
    }
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin >> s;
  t=s;
  reverse(t.begin(),t.end());
  if(s!=t) {
    cout << s.size() << endl;
  }
  sort(t.begin(),t.end());
  else if(t[0]==t[t.size()-1]) {
    cout << 0 << endl;
  }
  else {
    cout << s.size()-1 << endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
// long long dp[51][51];
std::vector<int> spilt(int l,int r,int a[],int m){

	std::vector<int> temp;

	int n=pow(2,r-l+1)-1;

	for(int i=0;i<=n;i++){
		int ans=0;
		for(int j=0;i>=(1<<j);j++){
			if(i&(1<<j)){
				ans+=a[l+j];
				 ans%=m;
			}
		}
		temp.push_back(ans);
	}
	return temp;

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

	std::vector<int> v1=spilt(0,n/2,a,m);
	std::vector<int> v2=spilt(n/2+1,n-1,a,m);

sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());

int ans=0;

for(auto i:v1){

	int x=lower_bound(v2.begin(),v2.end(),m-i-1)-v2.begin();

	if(x>=v2.size())||x<0){
		continue;
	}
	else{
		ans=max(ans,(i+v2[x])%m);
	}
}
cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
int a[n];
int sum=0;
for(int i=0;i<n;i++){cin>>a[i];
sum+=a[i];
m=min(sum,8);
k-=m;
sum-=m;
if(k<=0){ cout<<i<<"\n";
return 0;
}
}
cout<<-1<<"\n";
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long LL;

const LL num_up=1000000000000000000ll;

LL ft[13]={2,3,5,7,11,13,17,19,23,29};

const int pow_up[13]={23,16,11,6,6,5,5,5,4,3};

int n;
LL res;

void dfs(int deep,int cnt,LL num)
{
	if(num>=num_up || num>=res) return;
	if(cnt>n || n%cnt) return;
	if(cnt==n)
	{
		res=num;
		return;
	}
	if(deep==10)
	{
		return;
	}
	LL i,j;
//	double pd=num;
	for(i=0,j=1;;i++,j*=ft[deep],pd*=ft[deep])
	{
	//	if(pd>=num_up) return;
		dfs(deep+1,cnt*(i+1),j*num);
	}
}

int main()
{
	res=num_up;
	cin>>n;
	dfs(0,1,1);
	cout<<res<<endl;
	return 0;
}

/*imkgtkrdkorqminmlptmnlprcitpooicskasakncelkqlebclm*/


#include <bits/stdc++.h>

using namespace std;
long long  x[26] , flag , ans;
int main()
{
	string s ;
	cin >> s ;
	for(int c = 0 ; c < s.size()-25 ; c++ )
	{
		string s1 = s.substr(c,26);
		for(int i = 0 ; i < 26 ; i++ )
		{
			if(s1[i]!='?'&&!x[s1[i]-'A'])
				x[s1[i]-'A']=1;
			else if(s1[i]!='?'&&x[s1[i]-'A'])
				flag = 1 ;
		}
		if(flag == 0)
		{
			for(int i = 0 ; i < 26 ; i++ )
				if(s[i+c]=='?')
				{
					for(int j = 0 ; j < 26 ; j++ )
						if(!x[j])
						{
							s[i+c]=j+'A';
							x[j]=1;
							break;
						}
				}
			ans = 1 ;
		}
		flag =0;
		memset(x,0,sizeof(x));
	}
	for(int i = 0 ; i < s.size() ; i++ )
		if(s[i] == '?')
			s[i]='A';
	if(!ans)
		{cout << -1 << endl;
		return 0;
	}


#include <iostream>

using namespace std;
typedef long long ll;

int n,m,g;
int mod = 1e9 + 7;

ll fact[500009];

ll value[1000];

ll potencia(ll a, int pot)
{
    if(pot < 3)
        return pow(a,pot);

    ll res = potencia(a,pot/2);

    res = ((res%mod)*(res%mod))%mod;
    if(pot % 2 == 1)
        res = (res*a)%mod;

    return res;
}

ll nck(ll num, ll k)
{
    if(num == 0)return num;
    if(k == 1)
        return num;

    ll div = (fact[num - k]*fact[k])%mod;
    ll res = (fact[num]*potencia(div,mod - 2))%mod;
    return res;
}

ll cero()
{
    ll comb = nck(n + m - 1,m - 1);
    for(int i = 2; i <= n; i += 2)
    {
        comb += nck(n + m - i - 1, m - 1);
        comb %= mod;
    }
    return comb;
}

ll uno()
{
    ll res = nck(n + m - 2, m - 1);
    for(int i = 2; i <= n; i++)
    {
        res += nck(n + m - 2 - i, m - 1);
        res %+ mod;
    }
    return res;
}

int main()
{
    fact[0] = 1;
    fact[1] = 1;
    for(int i = 2; i < 500003; i++)
        fact[i] = (fact[i - 1]*i)%mod;
    cin >> n >> m >> g;

    if(n == 0)
    {
        if(g == 0)
            cout << 1 << endl;
        else
            cout << 0 << endl;
        return 0;
    }
    if(m == 0)
    {
        value[1] = n % 2;
        value[0] = 1 - value[0];
        cout << value[g] << endl;
        return 0;
    }

    if(g == 0)
    {
        if(n == 1 && m == 1)
        {
            cout << 2 << endl;
            return 0;
        }
        cout << cero() << endl;
    }
    else
    {
        cout << uno() << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define debug puts("here")
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define foreach(i,vec) for(unsigned i=0;i<vec.size();i++)
#define pb push_back
#define RD(n) scanf("%d",&n)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)

/******** program ********************/

const int INF = 1e9;

int main(){

#ifndef ONLINE_JUDGE
	freopen("sum.in","r",stdin);
	//freopen("sum.out","w",stdout);
#endif

    int n,m,x,y,a,b;
    while(cin>>n>>m>>x>>y>>a>>b){

        int t = __gcd(a,b);
        a /= t;
        b /= t;

        int q = min( n/a,m/b );

        a *= q;
        b *= q;

        int lx = max(0,x-(a+1)/2);
        int ly = max(0,y-(b+1)/2);
        int rx = a+lx;
        int ry = b+ly;

        if(lx>rx)swap(lx,rx);
        if(ly>ry)swap(ly,ry);

        cout<<lx<<" "<<ly<<" "<<rx<<" "<<ry<<endl;
    }

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

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

struct Matrix {
	vector<vector<long long> > val;
	Matrix(int n, int m, long long x = 0) : val(n, vector<long long>(m, x)) {}
	void init(int n, int m, long long x = 0) { val.assign(n, vector<long long>(m, x)); }
	size_t size() const { return val.size(); }
	inline vector<long long>& operator [] (int i) { return val[i]; }
};

Matrix operator * (Matrix A, Matrix B) {
	Matrix R(A.size(), B[0].size());
	for (int i = 0; i < A.size(); ++i)
		for (int j = 0; j < B[0].size(); ++j)
			for (int k = 0; k < B.size(); ++k)
				R[i][j] = (R[i][j] + A[i][k] * B[k][j] % MOD) % MOD;
	return R;
}

Matrix modpow(Matrix A, long long n) {
	Matrix R(A.size(), A.size());
	for (int i = 0; i < A.size(); ++i) R[i][i] = 1;
	while (n > 0) {
		if (n & 1) R = R * A;
		A = A * A;
		n >>= 1;
	}
	return R;
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll N, M; scanf("%lld %lld", &N, &M);
	if (N < M) {
		puts("1");
		return 0;
	}
	Matrix mat(M, M);
	Matrix ini(M, 1, 1);
	for (ll i = 1; i < M; i++) {
		mat[i][i - 1] = 1;
	}
	mat[0][M - 1] = 1;
	mat[0][0] = 1;
	Matrix res = modpow(mat, N - M + 1) * ini;
	cout << res[0][0] << endl;
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意！！！！！！！！！！！！
	*/
}


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

int color[300000];
int n, m;

int main() {
	ios_base::sync_with_stdio(0);
	for (int i = 0; i < 300000; i++) {
		color[i] = -1;
	}
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int v, to;
		cin >> v >> to;
		v--;
		to--;
		if (color[v] == -1 && color[to] == -1) {
			color[v] = 0;
			color[to] = 1;
		} else if (color[v] == -1) {
			color[v] = color[to] ^ 1;
		} else if (color[to] == -1) {
			color[to] = color[v] ^ 1;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << color[i] == -1 ? 0 : color[i];
	}
}


<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{D91F86F8-0763-41BD-AEDC-D2F13CDFE70A}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>songsmix</RootNamespace>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v120</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v120</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="Source.cpp" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>


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

using namespace std;

int xMax,xMin,yMax,yMin,sum;

int main(){
    int i,j,x1,y1,x2,y2,n;
    scanf("%d",&n);
    xMin=yMin=50000;
    xMax=yMax=0;

    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
        sum+=(x2-x1)*(y2-y1);
        xMax=max(xMax,x2);
        xMin=min(xMin,x1);
        yMax=max(yMax,y2);
        yMin=min(yMin,y1);
    }

    int dx=xMax-xMin,dy=yMax-yMin;
    cout<< (((sum==dx*dy)&&(dx==dy) )?"YES":"NO") <<endl;

    return 0;
}#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

long long xMax,xMin,yMax,yMin,sum;

int main(){
    long long i,j,x1,y1,x2,y2,n;
    scanf("%I64d",&n);
    xMin=yMin=50000;
    xMax=yMin=0;

    for(i=0;i<n;i++){
        scanf("%I64d %I64d %I64d %I64d",&x1,&y1,&x2,&y2);
        sum+=(x2-x1)*(y2-y1);
        xMax=max(xMax,x2);
        xMin=min(xMin,x1);
        yMax=max(yMax,y2);
        yMin=min(yMin,y1);
    }

    cout<< ((sum==(xMax-xMin)*(yMax-yMin))?"YES":"NO") <<endl;

    return 0;
}