#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int m = ri();
	if (n == 1) {
		if (m == 0) puts("1 2");
		else puts("0");
		return 0;
	}
	if (m < 0 || m > n - 2) {
		puts("-1");
		return 0;
	}
	int first = n - 2 - m;
	for (int i = 0; i < first; i++) printf("%d %d\n", i * 2 + 1, i * 2 + 2);
	printf("%d %d\n", 2 * first + 1, 2 * n);
	for (int i = first + 1; i < n; i++) printf("%d %d\n", i * 2, i * 2 + 1);

	return 0;
}

// atcoder/arc106/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  lli n, m;
  while (cin >> n >> m) {
    if (m == 0) {
      int a = 1;
      int b = a + 1;
      for (int i = 0; i < n; ++i) {
        cout << a << ' ' << b << endl;
        a = b + 1;
        b = a + 1;
      }
      continue;
    }

    const int M = 2 * 1e6;

    if (m < 0) {
      cout << -1 << endl;
      continue;
    }

    unless (m + 2 <= n) {
      cout << -1 << endl;
      continue;
    }

    if (m) {
      cout << 1 << ' ' << M << endl;
      int a = 2;
      int b = a + 1;
      for (int i = 0; i < m + 1; ++i) {
        cout << a << ' ' << b << endl;
        a = b + 1;
        b = a + 1;
      }
    }
    int a = M + 1;
    int b = a + 1;
    for (int i = m + 2; i < n; ++i) {
      cout << a << ' ' << b << endl;
      a = b + 1;
      b = a + 1;
    }
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  const int n=3;
  vector<int> a(n);
  for(auto& ai : a)
  {
    cin >> ai;
  }
  sort(a.begin(), a.end());
  cout << accumulate(next(a.begin()), a.end(), 0) << "\n";
  return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

template <typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

void solve() {
	vector<int> v(3);
	for (int &i : v) cin >> i;
	sort(v.begin(), v.end());
	cout << v[1] + v[2] << "\n";
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int _ = 1;
	//cin >> _;
	while (_--) {
		solve();
	}
}


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

int main(void){
  ll n;
  cin >> n;

  unordered_set<ll> num;
  for (int i=1; i<=n; i++){
    string s_i = to_string(i);
    for (int j=0; j<s_i.size(); j++){
      if (s_i[j] == '7'){
        num.insert(i);
      }
    }
    stringstream ss;
    ss << oct << i;
    for (int k=0; k<ss.str().size(); k++){
      if (ss.str()[k] == '7'){
        num.insert(i);
      }
    }
  }
  cout << n - num.size() << endl;
}

#include<bits/stdc++.h>
#define fast_az_fuk ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define dpll deque<pll>
#define mapll map<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
bool octal(ll a){
    while(a){
        ll r=a%8;
        if(r==7)  return 0;
        a/=8;
    }
    return 1;
}
bool decimal(ll a){
    while(a){
        ll r=a%10;
        if(r==7) return 0;
        a/=10;
    }
    return 1;
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_az_fuk
   ll n; cin>>n;
   ll c=0;
   for(ll i=1;i<=n;i++){
    if(octal(i)&&decimal(i)) c++;
   }
   cout<<c;
    return 0;
}


//#undef DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll llinf = (1ll<<61)-1;
#define sz(a) int(a.size())
#define all(x) begin(x), end(x)
#ifdef DEBUG
const int DEBUG_END = 26;
#define DOS cout
#include <debug.h>
#else
#define bug(args...) void()
#define cbug(a, args...)
#endif
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define fi first
#define se second
int TC = 1, CN;
const int inf = 998244353;
template<class C, class D> bool operator ==(const C &ls, const D &rs) { return !(ls<rs or rs<ls); }//{
template<class C, class D> bool operator !=(const C &ls, const D &rs) { return !(rs==ls); }
template<class C, class D> bool operator >(const C &ls, const D &rs) { return rs<ls; }
template<class C, class D> bool operator <=(const C &ls, const D &rs) { return !(rs<ls); }
template<class C, class D> bool operator >=(const C &ls, const D &rs) { return !(ls<rs); }
// += can't be made generic as x+=y is not the same as x=x+y when x is string
template<class C, class D> C& operator -=(C &x, const D &y) { return x = x-y; }
template<class C, class D> C& operator *=(C &x, const D &y) { return x = x*y; }
#include <ext/numeric>
using __gnu_cxx::power;
template<int mod> struct mint// Make sure to not do any operation with int outside [-mod, 2*mod), *1 to mod forcefully), use << instead of 2*
{
    int x;
    mint() = default;
    mint(const int &rs) : x(rs + (rs>=0 ? 0 : mod) - (rs<mod ? 0 : mod)) {};
    mint operator -() { return -x; }
    // mint operator ~() = delete;  // when mod is not surely prime
    mint operator ~() { ASSERT(x, !=, 0, "modinverse 0 is undefined"); return power(*this, mod-2); }
    mint operator +(const mint &rs) const { return x+rs.x; }
    mint& operator +=(const mint &rs) { return *this = *this + rs; }
    mint operator -(const mint &rs) const { return x-rs.x; }
    mint operator *(const mint &rs) const { return int(x*ll(rs.x)%mod); }
    mint operator <<(const int &rs) { return rs==1 ? *this+*this : *this*mint{1<<rs}; }
    mint& operator <<=(const int &rs) { return *this = *this<<rs; }
    mint& operator >>=(const int &rs) { return x>>=rs, *this; }  // only for power()
    mint& operator ++() { return *this += 1; }
    mint& operator --() { return *this -= 1; }
    mint operator ++(int) { mint ret = x; ++*this; return ret; }
    mint operator --(int) { mint ret = x; --*this; return ret; }
    friend istream& operator >>(istream &is, mint &rs) { return is>>rs.x; }
    friend ostream& operator <<(ostream &os, const mint &rs) { return os<<rs.x; }
    friend mint operator +(const mint &ls, const int &rs) { return ls+mint(rs); }
    friend mint operator +(const int &ls, const mint &rs) { return mint(ls)+rs; }
    friend mint operator -(const mint &ls, const int &rs) { return ls-mint(rs); }
    friend mint operator -(const int &ls, const mint &rs) { return mint(ls)-rs; }
    friend mint operator *(const mint &ls, const int &rs) { return ls*mint(rs); }
    friend mint operator *(const int &ls, const mint &rs) { return mint(ls)*rs; }
    bool operator <(const mint &rs) const { return x<rs.x; }
    friend bool operator <(const int &ls, const mint &rs) { return ls<rs.x; }
    friend bool operator <(const mint &ls, const int &rs) { return ls.x<rs; }
};
using Int=mint<inf>;
Int operator""_i(unsigned long long x) { return {int(x)}; }//}
const int N = 200005;
int n, m, k;

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    //cin >> TC;// inputAll + resetAll -> solution
    auto kase = [&]()->void {
        cin >> n >> m >> k;
        Int ans = 0;
        if (n == 1) ans = power(Int(k), m);
        else if (m == 1) ans = power(Int(k), n);
        else {
            for (int i = 1; i <= k; i++) {
                ans += (power(Int(i), n)-(i == 1 ? 0 : power(Int(i-1), n)))*power(Int(k-i+1), m);
            }
        }
        cout << ans << '\n';
    };
    while (CN++!=TC) kase();
}

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

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
  ll h,w,k;
  cin >> h >> w >> k;

  if(h==1){
    cout << modpow(k,w,mod) << endl;
    return 0;
  }

  if(w==1){
    cout << modpow(k,h,mod) << endl;
    return 0;
  }

  ll ans = 0;
  vector<ll> Ah(k,0);
  vector<ll> Aw(k,0);
  Ah.at(0) = 1;
  Aw.at(0) = 1;
  for(int i=2;i<=k;i++){
    Ah.at(i-1) = (modpow(i,h,mod)-modpow(i-1,h,mod))%mod;
    Aw.at(i-1) = (modpow(i,w,mod)-modpow(i-1,w,mod))%mod;
  }
  ll sum = 0;
  for(int i=1;i<=k;i++){
    //cout << Ah.at(i-1) << endl;
    sum += Ah.at(i-1);
    sum%=mod;
    ans += (sum*Aw.at(k-i))%mod;
    ans%=mod;
  }

  cout << ans << endl;
  return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

string F(string a){//aのAとBを反転させたやつを返す
  for(auto &p:a)
    if(p=='A')p='B';
    else p='A';
  return a;
}

int G(int a){
  return (1<<a)-1;
}

int main(){
  int n;cin>>n;
  vector<vector<string>> s(n+1);//s[i]:n=iの時の答え
  for(int i=1;i<=n;i++)s[i].resize(G(i));
  s[1][0]="AB";
  for(int i=2;i<=n;i++){
    REP(j,G(i-1)){
      s[i][j]       =s[i-1][j]+F(s[i-1][j]);
      s[i][G(i-1)+j]=s[i-1][j]+  s[i-1][j];
    }
    s[i].back()=string(1<<(i-1),'A')+string(1<<(i-1),'B');
  }
  cout<<s[n].size()<<endl;
  for(string p:s[n])cout<<p<<endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
ll I=167167167167167167;
ll Q=1e9+7;

string han(string S){
	string T;
	for(int i=0;i<S.size();i++){
		if(S[i]=='A') T+="B";
		else T+="A";
	}
	return T;
}

int main() {
	ll N,A=1;
	cin>>N;
	vector<string> p;
	for(int i=0;i<N;i++){
		A*=2;
		vector<string> q;
		string T;
		for(int j=0;j<A;j++){
			if(j*2<A) T+="A";
			else T+="B";
		}
		q.push_back(T);
		for(auto x:p){
			q.push_back(x+x);
			q.push_back(x+han(x));
		}
		p=q;
	}
	cout<<A-1<<endl;
	for(auto x:p) cout<<x<<endl;
}


#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 210;
#define int ll
const long double pi = 3.14159265358979323846;

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

void YES(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
    exit(0);
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<Pll> v(2 * n, {-1, -1});
    rep(i, 0, n) {
        ll a,b; cin >> a >> b;
        if(a != -1){
            a--;
            if (v[a] != Pll{-1, -1}) YES(false);
            v[a] = {0, i};
        }
        if(b != -1){
            b--;
            if (v[b] != Pll{-1, -1}) YES(false);
            v[b] = {1, i};
        }
        if(a != -1 && b != -1){
            if (a > b) YES(false);
        }
    }

    // [l, r]の区間を正しく補完できるかチェック
    auto check = [&](ll l, ll r) {
        if (l & 1) return false;
        if (~r & 1) return false;

        ll len = (r - l + 1) / 2;
        bool res = true;

        rep(i, l, r + 1){
            ll j;
            if (i <= (l + r) / 2) {
                j = i + len;
                res &= v[i].first != 1;
                if(v[i] != Pll{-1, -1} && v[j] != Pll{-1, -1}){
                    res &= v[j].first == 1 && v[i].second == v[j].second;
                }
            } else {
                j = i - len;
                res &= v[i].first != 0;

                if (v[i] != Pll{-1, -1} && v[j] != Pll{-1, -1}) {
                    res &= v[j].first == 0 && v[i].second == v[j].second;
                }
            }
        }

        if (res) debug(l, r);
        return res;
    };

    bitset<n_max> dp(0);
    rep(i,0,2 * n){
        if (~i & 1) continue;

        rep(j, 0, i) {
            if (!dp[j]) continue;
            if (check(j + 1, i)){
                dp[i] = 1;
                break;
            }
        }
        if (check(0, i)) dp[i] = 1;
    }
    debug(dp);
    YES(dp[2 * n - 1]);
}

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    ll mh = 0, che = 0;
    double eu = 0;
    REP(_,n) {
        ll x; cin >> x;
        mh += abs(x);
        eu += x*x;
        che = max(che,abs(x));
    }
    eu = sqrt(eu);
    OUT(mh)
    cout << fixed << setprecision(10) << eu << '\n';
    OUT(che)

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main(void)
{
	long long a, b, c;

	std::cin >> a >> b >> c;
	if (a * a < c * c - b * b)
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;
	return (0);
}

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
//typedef vector<vector<int> > Graph;
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; }
const ll INF = 1e18;

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T>
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T>
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T>
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

/*

*/
int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	ll a,b,w;
	cin >> a >> b >> w;
	w *= 1000;
	ll MIN = (w+b-1)/b;
	ll MAX = w/a;
	if(MIN>MAX){
		cout << "UNSATISFIABLE" << endl;
		return 0;
	}
	cout << MIN << ' ';
	cout << MAX << endl;

	return 0;
}


//Made by imalyd
//Problem Name: ...
//Problem Link: ...
//Category: ...
#include<bits/stdc++.h>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define per(i,a,b) for(i=(a);i>=(b);--i)
#define REP(i,a,b) for(i=(a);i< (b);++i)
#define PER(i,a,b) for(i=(a);i> (b);--i)
#define ERR(...) fprintf(stderr,__VA_ARGS__)
template<class T>inline void cmn(T &x,const T &a){if(a<x)x=a;}
template<class T>inline void cmx(T &x,const T &a){if(x<a)x=a;}
template<class T>inline bool bmn(T &x,const T &a){if(a<x){x=a;return true;}else return false;}
template<class T>inline bool bmx(T &x,const T &a){if(x<a){x=a;return true;}else return false;}
const int p=998244353,ps2=p-2;
inline void add(int &x){if(x>=p)x-=p;}
inline void sub(int &x){if(x< 0)x+=p;}
#define MUL(a,b) ((0ll|(a))*(b)%p)
template<class T>int expo(int a,T b){
	int s(1);
	while(b){if(b&1)s=MUL(s,a);b>>=1;a=MUL(a,a);}
	return s;
}
int expo(int a){
	int b(ps2),s(1);
	while(b){if(b&1)s=MUL(s,a);b>>=1;a=MUL(a,a);}
	return s;
}

inline ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
int S[150];
inline void sol(ll n,ll m){
	int t=0;
	for(;;){
		if(!n){while(m--)S[++t]=2;break;}
		if(!m){while(n--)S[++t]=1;break;}
		if(n>m){S[++t]=3;n-=m;}else{S[++t]=4;m-=n;}
		if(t>130)return;
	}
	if(t>130)return;
	printf("%d\n",t);
	while(t)printf("%d\n",S[t--]);
	exit(0);
}
int main(){
#ifdef ONLINE_JUDGE
	//freopen("problemname.in","r",stdin);
	//freopen("problemname.out","w",stdout);
#endif
	ll n,m;int t=0;
	scanf("%lld",&n);
	m=(sqrt(1.25)-0.5)*n;
	cmx(m,1ll);
	cmn(m,n-1ll);
	ll i;
	per(i,m,1ll)if(gcd(n,i)==1ll)sol(n,i);
	rep(i,m,n  )if(gcd(n,i)==1ll)sol(n,i);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
int exgcd(int a,int b,int &x,int &y){
	if(!b){
		x=1;
		y=0;
		return a;
	}
	else {
		int d=exgcd(b,a%b,x,y);
		int temp=x;
		x=y;
		y=temp-a/b*y;
		return d;
	}
}
//求ax+by=c,的x的最小整数解，无解为-1
int findK(int a,int b,int c){
    int x,y;
    int gcd=exgcd(a,b,x,y);
    if(c%gcd)return -1;
    int k=c/gcd;
    int p=x*k;
    int q=p*k;
    p%=b/gcd;
    p+=b/gcd;
    p%=b/gcd;
    return p;
}
int T;
int x,y,p,q;
void solve(){
    cin>>T;
    while(T--){
        cin>>x>>y>>p>>q;
        int a,b,c,d,d1,d2;
        a=x,b=x+y-1,c=p,d=p+q-1,d1=2*(x+y),d2=p+q;
        int ans=2e18;
        if((a>=c&&a<=d)||(c>=a&&c<=b)){
            if(a>=c&&a<=d) ans=min(ans,a);
            if(c>=a&&c<=b) ans=min(ans,c);
            cout<<ans<<endl;
        }
        else{
            if(d1==d2) cout<<"infinity"<<endl;
            else{
                int num=x%d2;
                for(int i=c;i<=d;++i){
                    int a1=a,b1=d1,c1=d2,d11=i;
                    int num1=findK(b1,c1,d11-a1);
                    if(findK(b1,c1,d11-a1)!=-1){
                        ans=min(ans,num1*b1+a1);
                    }
                }
                num=p%d1;
                for(int i=a;i<=b;++i){
                    int a1=c,b1=d2,c1=d1,d11=i;
                    int num1=findK(b1,c1,d11-a1);
                    if(findK(b1,c1,d11-a1)!=-1){
                        ans=min(ans,num1*b1+a1);
                    }
                }
                if(ans==2e18)  cout<<"infinity"<<endl;
                else cout<<ans<<endl;
            }
        }

    }
}
signed main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define F first
#define S second
#define YES(n)cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define _GLIBCXX_DEBUG
const ll INF = 1e12;

set<pair<int,int>> st;
vector<vector<int>> graph(3000,vector<int>(0));

void dfs(int a,int b){
    st.insert(make_pair(a,b));
    for(int i=0;i<graph[b].size();i++){
        if(st.count(make_pair(a,graph[b][i]))==0){
            dfs(a,graph[b][i]);
        }

    }
}

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

    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        graph[a].push_back(b);
    }

    rep(i,n){
        dfs(i,i);
    }

    cout<<st.size()<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define PI  3.14159265359
#define INF 100100100
#define mod 1000000007
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

const int mx = 200005;

int main(){
  int n, w;
  cin >> n >> w;
  vector<ll> d(mx);
  rep(i,n){
    int s, t, p;
    cin >> s >> t >> p;
    d[s] += p;
    d[t] -= p;
  }
  rep(i,mx) d[i+1] += d[i];
  rep(i,mx){
    if(d[i] > w){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define S second
#define F first
using namespace std;
int n,q,t,a,b,k,p[400005];
string s;
signed main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n>>s>>q;
    for(int i=0;i<2*n;i++)p[i]=i;
    while(q--){
        cin>>t>>a>>b;
        a--;
        b--;
        if(t==1){
            swap(p[(a+k)%(2*n)],p[(b+k)%(2*n)]);
        }
        else{
            k=(k+n)%(2*n);
        }
    }
    for(int i=0;i<2*n;i++)cout<<s[p[(i+k)%(2*n)]];
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;
template <class T = ll>
T in() {
  T x;
  cin >> x;
  return (x);
}

int main() {
  int Ans = 0;
  ll N = in<ll>();
  string S = in<string>();
  ll Q = in<ll>();
  vector<int> T(Q);
  vector<ll> A(Q);
  vector<ll> B(Q);
  REP(i, Q) {
    cin >> T[i];
    cin >> A[i];
    cin >> B[i];
    if (i > 0) {
      if ((T[i - 1] == 2) && (T[i] == 2)) {
        T[i] = 0;
        T[i - 1] = 0;
      }
    }
  }

  REP(i, Q) {
    if (T[i] == 1) {
      swap(S[A[i]-1], S[B[i]-1]);
    } else if (T[i] == 2) {
      S = S.substr(N) + S.substr(0, N);
    }
  }
  cout << S << endl;
  return 0;
}


#include <bits/stdc++.h>
#include <unordered_set>
#include <algorithm>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i,n) for (ll i = 0; i < (ll)(n); i++)
#define fore(x,a) for(auto&(x) : (a))

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

#define ALL(a) (a).begin(), (a).end()

const ll INFL = 1e18;
const int INFI = 1e9;
const int MOD = 1e9 + 7;

int main(){
  ll N,P;
  cin >> N >> P;
  ll res = 1;
  res *= P - 1;
  ll i = P - 2;
  ll t = 0;
  ll s = 1;
  while(true) {
    if (t + s >= N) {
      break;
    }
    res *= i;
    res %= MOD;
    t += s;
    i = i*i%MOD;
    s *= 2;
  }
  for (int i = t + 1; i < N; i++) {
    res *= P - 2;
    res %= MOD;
  }
  cout << res << endl;
}

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

#define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) begin(x),end(x)

using namespace std;
using namespace std::string_literals;

using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

char rps(char l, char r) {
  if (l == r) return l;
  switch (l) {
    case 'R': return r == 'P' ? 'P' : 'R';
    case 'P': return r == 'S' ? 'S' : 'P';
    case 'S': return r == 'R' ? 'R' : 'S';
  }
  throw runtime_error("BAD");
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i32 n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  rep(i,k) {
    string t = s;
    rep(j,n) {
      i32 l = (2*j)%n;
      i32 r = (2*j+1)%n;
      t[j] = rps(s[l], s[r]);
    }
    swap(s, t);
  }
  cout<<s[0]<<endl;
  return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll arr[10000];
// Function to find power
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result

    // Update x if it is more than or
    // equal to p
    x = x % p;

    while (y > 0) {

        // If y is odd, multiply x
        // with the result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll a,b,c,i,j,k,x,y,z;
    cin>>a>>b>>c;
    a=a%10;
    if (a==0)
    {
    	cout<<0<<endl;
    	return 0;
	}
    if (a==1)
    {
    	cout<<1<<endl;
    	return 0;
	}
    if (a==2)
    {
    	arr[1]=2;
    	arr[2]=4;
    	arr[3]=8;
    	arr[0]=6;
    	cout<<arr[power(b,c,4)]<<endl;
    	return 0;
	}
    if (a==3)
    {
    	arr[1]=3;
    	arr[2]=9;
    	arr[3]=7;
    	arr[0]=1;
    	cout<<arr[power(b,c,4)]<<endl;
    	return 0;
	}
    if (a==4)
    {
    	arr[1]=4;
    	arr[0]=6;
    	cout<<arr[power(b,c,2)]<<endl;
    	return 0;
	}
    if (a==5)
    {
    	cout<<5<<endl;
    	return 0;
	}
    if (a==6)
    {
    	cout<<6<<endl;
    	return 0;
	}
    if (a==7)
    {
    	arr[1]=7;
    	arr[2]=9;
    	arr[3]=3;
    	arr[0]=1;
    	cout<<arr[power(b,c,4)]<<endl;
    	return 0;
	}
    if (a==8)
    {
    	arr[1]=8;
    	arr[2]=4;
    	arr[3]=2;
    	arr[0]=6;
    	cout<<arr[power(b,c,4)]<<endl;
    	return 0;
	}
    if (a==9)
    {
    	arr[1]=9;
    	arr[0]=1;
    	cout<<arr[power(b,c,2)]<<endl;
    	return 0;
	}
}

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

#define fi first
#define se second
#define rng(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define per(i, b) gnr(i, 0, b)
#define all(obj) begin(obj), end(obj)
#define allr(obj) rbegin(obj), rend(obj)
#define sz(x) (int)(x).size()
#define cinv(a) rep(i, sz(a)) cin >> a[i]
#define debug(a) rep(i, sz(a)) cout << a[i] << " \n"[i == sz(a)-1]
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<Pi> vp;
typedef vector<vp> vvp;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const int MOD =	1e9 + 7;
const int INF = 1e9 + 9;
const ll LINF = 1e18;
const long double eps = 1e-10;
const char nl = '\n';

ll power(ll a, ll b, int mod) { return b ? power(a * a % mod, b / 2, mod) * (b % 2 ? a : 1) % mod : 1; }

ll nCk(int n, int k, int mod)
{
	ll x = 1, y = 1;
	for (int i = 1; i <= k; ++i)
	{
		x = x * (n - i + 1) % mod;
		y = y * i % mod;
	}
	return x * power(y, mod - 2, mod) % mod;
}

struct UF
{
	vi d;
	UF(int n) : d(n, -1) {}
	int root(int x)
	{
		if (d[x] < 0)
			return x;
		return d[x] = root(d[x]);
	}
	bool unite(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (d[x] > d[y]) swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -d[root(x)]; }
};

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(20);
	int a, b, c; cin >> a >> b >> c;
	cout << power(a % 10, power(b, c, 4) + 4, 10) << nl;
}


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

using namespace std;

#define with_test(t, isT) int t=1;if(isT)cin>>t;while(t--)
void init(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);    cin.tie(0);    cout.precision(10);
    cout << fixed;
}

#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i < (int)(n); ++i)
#define YES  cout<<"YES\n";
#define YESC cout<<"YES\n";continue;
#define NO   cout<<"NO\n";
#define NOC  cout<<"NO\n";continue;

#define pb push_back
#define mp make_pair

#define fe first
#define se second
#define lld long long int
#define ll  long long

void print(vector<int> arr){
    for0(i,arr.size()){
        cout<<arr[i]<<" ";
    }
    cout<<"\n";
}
void print(int arr[], int n){
    for0(i, n){
        cout<<arr[i]<<" ";
    }cout<<"\n";
}

void test_case(){
    string s;
    cin>>s;
    reverse(s.begin(), s.end());
    for(int i=0;i<s.length();i++){
        if(s[i]=='6'){
            cout<<"9";
        }
        else if(s[i]=='9'){
            cout<<"6";
        }else{
            cout<<s[i];
        }
    }
}

int main() {
    init();
    int isTest = 0;
    with_test(t,isTest){
        test_case();
    }
    return 0;
}
/*
    ====== WORK =====

*/

#include<bits/stdc++.h>
/*#include<boost/multiprecision/cpp_int.hpp>
using boost :: multiprecision::cpp_int;*/
#define ll long long int
#define mod 1e9+7
using namespace std;
/*int gcd(int a, int b)
{
  if (a == 0)
    return b;
  return gcd(b % a, a);
}*/

void solve()
{
  string n;
  cin >> n;
  for (int i = n.length() - 1; i >= 0; i--)
  {
    if (n[i] == '0')
    {
      n.erase(i);
    }
    else
    {
      break;
    }
  }
  ll l = n.length();
  bool check = true;
  for (int i = 0; i < l / 2; i++)
  {
    if (n[i] != n[l - i - 1])
    {
      check = false;
    }

  }
  if (check)
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }
}

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;

}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cassert>
#include <numeric>
#define _GLIBCXX_DEBUG
#define INF 100000010
 #define PI 3.14159265359

using namespace std;
const int64_t mod = 1000000007;
const int64_t tmpMod = 998244353;

int64_t getNum(int64_t N, int64_t n) {
  return N-abs(n-N) > 0 ? N-abs(n-N): 0;
}

int main() {

  int64_t N,K,ans=0;
  cin>>N>>K;

  // unordered_map<int, int> map;

  //vector<int64_t> A(N);
  for(int64_t i=1; i<=2*N-K-1; i++){
    // cout<<i << " " <<getNum(N,i)<<" "<<getNum(N,i+K)<<endl;
    ans+=(getNum(N,i) * getNum(N,i+K));
  }
  //vector<vector<int> > A(N,vector<int>(M));
  // for(int i=1; i<=N; i++){
  //   for(int j=1; j<=N; j++){
  //       map[i+j]++;
  //   }
  // }
  //sort(A.begin(),A.end());
  //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  cout << ans << endl;
}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; ++i)
const ll INF = 1LL << 60;
const double EPS = 1e-20;
const ll MOD = 1000000007;
const double pi = 3.141592653589793;

/*  //1
int main() {
    ll n;
    cin >> n;
    cout << (n+1)*5000 << endl;
}
//*/

//*  //2
ll _4Hr(ll r){
    return double(3+r)/6*(2+r)*(1+r);
}
int main() {
    ll n, k;
    cin >> n >> k;
    ll J = 2*n - 2 - abs(k);
    ll ans = _4Hr(J);
    if (J > n - 1) ans -= 4 * _4Hr(J - n);
    cout << ans << endl;
    // k = abs(k);
    // FOR(i, 2, 2*n-k+1) {
    //     ll x1=min((k+i)-1, 2*n+1-(k+i));
    //     ll x2=min(i-1, 2*n+1-i);
    //     ans += x1 * x2;
    // }
}
//*/

/*  //3
//https://atcoder.jp/contests/code-festival-2015-morning-middle/tasks/cf_2015_morning_easy_c
int main() {
    ll n, k, m, r;
    cin >> n >> k >> m >> r;
    vll s(n-1);
    rep(i, n-1) cin >> s[i];
    sort(s.begin(), s.end(), greater<ll>());

    long double sum = 0;
    rep(i, k) sum += (long double)(s[i]) / k;
    // if (sum >= r * k) {
    //     cout << 0 << endl;
    // } else {
    //     ll score = r * k - (sum - s[k - 1]);
    //     cout << ((score > m) ? -1 : score) << endl;
    // }
    if (sum >= r) {
        cout << 0 << endl;
    } else {
        ll score = ((long double)r - (sum - (long double)(s[k - 1]) / k)) * k;
        cout << ((score > m) ? -1 : score) << endl;
    }
}
//*/

/*  //4
// https://atcoder.jp/contests/arc118/tasks/arc118_c
int main() {
    ll n;
    cin >> n;
    vll v;
    if (n == 3) {
        v.push_back(6);
        v.push_back(10);
        v.push_back(15);
    } else if (n == 4) {
        v.push_back(210 / 2);
        v.push_back(210 / 3);
        v.push_back(210 / 5);
        v.push_back(210 / 7);
    } else {
        ll q[] = {2, 3, 5, 7, 11};
        rep(z, 4) {
            rep(i, 30) {
                rep(J, 20) {
                    rep(k, 20) {
                        rep(L, 10) {
                            ll p = pow(q[(z > 0)], i);
                            if (p > 10000) break;
                            ll tmp = pow(q[1 + (z > 1)], J);
                            if (tmp > 10000) break;
                            p *= tmp;
                            tmp = pow(q[2 + (z > 2)], k);
                            if (tmp > 10000) break;
                            p *= tmp;
                            tmp = pow(q[3 + (z > 3)], L);
                            if (tmp > 10000) break;
                            p *= tmp;
                            v.push_back(p);
                        }
                    }
                }
            }
        }
    }
    rep(i, n) cout << v[i] << " ";
    cout << endl;
    cout << v.size() << endl;
}
//*/


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    #define int int64_t
    int a,b,c;
    map<int,int> p;
    cin>>a>>b>>c;
    p[a]+=1,p[b]+=1,p[c]+=1;
    if(p.size()==3){
        cout<<0<<endl;
    }
    else{
        for(auto c:p){
            int cnt = c.second;
            if(cnt==1 || cnt==3){
                cout<<c.first<<endl;
                return 0;
            }
        }
    }
    return 0;
}

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

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

    if(a==b)
    cout << c << endl;
    else if(a==c)
    cout << b << endl;
    else if(b==c)
    cout << a << endl;
    else cout << '0' << endl;

}


#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007

int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=(ans*a)%m; b/=2;a=(a*a)%m;}return ans;}
int inverse(int a, int p){return fexp(a, p-2,p);}

// int fac[2000001];

// int nCrModPFermat(int n, int r,int p) {
//     // cout<<1<<endl;
//     if (r==0) return 1;
//     return (((fac[n]*((((inverse(fac[r],p)%p)*inverse(fac[n-r],p))%p))))%p);
// }

// vi spf(10000001,1);
vector<vector<int>> v(1000,vector<int>(1000,0));
int k,n;
bool check(int num){
    vector<vector<int>> dp(n+1,vector<int>(n+1,0));
    int val=(k*k+1);val=val/2;
    rep(i,0,n){
        rep(j,0,n){
            if(v[i][j]>num)dp[i][j]=0;
            else dp[i][j]=1;
            if(j-1>=0)dp[i][j]+=dp[i][j-1];
            if(i-1>=0)dp[i][j]+=dp[i-1][j];
            if(i&&j)dp[i][j]-=dp[i-1][j-1];
        }

    }
    int mx=0;
    rep(i,0,n-k+1){
        rep(j,0,n-k+1){
            int ans=dp[i+k-1][j+k-1];
            if(i){
                ans-=dp[i-1][j+k-1];
                if(j)ans+=dp[i-1][j-1];
            }
            if(j)ans-=dp[i+k-1][j-1];
            // cout<<ans<<endl;
            mx=max(mx,ans);
        }
    }
    // cout<<num<<"__"<<mx<<endl;
    return (mx>=val);
    // return true;
}

void solve(){
    cin>>n>>k;
    rep(i,0,n){
        rep(j,0,n){
            cin>>v[i][j];
        }
    }
    int l=0,r=mod,ans=mod;
    while(l<r){
        int mid=(l+r)/2;
        if(check(mid))r=mid;
        else l=mid+1;
    }
    cout<<r;

}

signed main(){
        IOS;

        auto start = high_resolution_clock::now();
        int t=1;
        // cin>>t;
        // spf[1]=1;
        // for(int i=2; i<=10000001; i++){
        // if(spf[i]==1){
        //     // allprime.pb(i);
        //     for(int j=i; j<=10000001; j+=i)
        //         if(spf[j]==1)spf[j]=i;
        // }
        // }
        // fac[0] = 1;
        // for (int i=1 ; i<=200001; i++) fac[i] = fac[i-1]*i%mod;

        rep(i,0,t){
            // cout<<"Case #"<<i+1<<": ";
            solve();
            cout<<"\n";
        }
        auto stop = high_resolution_clock::now();
        auto duration = duration_cast<microseconds>(stop - start);
        cerr<<"Time taken:"<<duration.count()/1000000.0<<"seconds"<<"\n";
    //    return 0;
}


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

const int maxn = 1 << 19;

int n, m;
long long dp[maxn]; bool ok[maxn];
int x[110], y[110], z[110];

int main()
{
    scanf ("%d %d", &n, &m);
    for (int i = 1; i <= m; i++)
        scanf ("%d %d %d", x + i, y + i, z + i);
    int upp = 1 << n;
    dp[0] = 1;
    for (int sta = 0; sta < upp; sta++)
    {
        bool f = 1;
        int cnt = __builtin_popcount(sta);
        for (int i = 1; i <= m; i++)
        {
            if (cnt > x[i]) continue;
            int c = 0;
            for (int o = 0; o < y[i]; o++) if ((1 << o) & sta) c++;
            if (c > z[i]) f = 0;
        }
        if (!f) dp[sta] = 0;
        for (int o = 0; o < n; o++) if (!((1 << o) & sta)) dp[sta | (1 << o)] += dp[sta];
    }
    printf ("%lld\n", dp[upp - 1]);
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 19;
const int MAX_M = 105;
ll dp[(1 << MAX_N)];
int X[MAX_M],Y[MAX_M],Z[MAX_M];

int main()
{
	int N,M;
	cin >> N >> M;
	rep(i,M)
	{
		cin >> X[i] >> Y[i] >> Z[i];
		//X[i] = i%(N-1)+1; Y[i] = i%(N-1)+1; Z[i] = i%N;
	}
	dp[0] = 1;
	for (int bits = 0; bits < (1 << N); ++bits)
	{
		vector<int> ppcnt(N+1,0);
		rep(i,N) {ppcnt[i+1] = ppcnt[i] + ((bits >> i) & 1);}
		/*
		rep(i,N+1) cout << ppcnt[i] << " ";
		cout << endl;
		*/
		rep(i,N)
		{
			if ((bits >> i) & 1 != 0) continue;
			bool ok = true;
			int c;
			rep(j,M)
			{
				if (i+1 <= Y[j]) c = 1;
				else c = 0;
				if (X[j] == ppcnt[N]+1 && ppcnt[Y[j]]+c > Z[j]) ok = false;
			}
			if (ok) dp[bits | (1 << i)] += dp[bits];
		}
		//cout << bits << " " << dp[bits] << endl;
	}
	cout << dp[(1 << N) - 1] << endl;
	return 0;
}


#include<iostream>
//#include<bits/stdc++.h>
#define r read()
#define bb printf("!!\n");
#define cc printf("\n");
using namespace std;
inline int read()
{
	bool ok=0 ;int res=0;char c;
	while(((c=getchar())<'0'||c>'9')&&c!='-');
	if(c=='-') ok=1;else res=c-48;
	while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+(c-48);
	return ok ? ~res + 1:res;
}
int n,m;
int main()
{
 #ifndef ONLINE_JUDGE
//	freopen("cin.txt","r",stdin);
//	freopen("cout.txt","w",stdout);
	#endif
	int a,b;
	cin>>a>>b;
	a+=b;
	int ans=4;
	if(a>=15&&b>=8)ans=1;
	else if(a>=10&&b>=3)ans=2;
	else if(a>=3)ans=3;
	printf("%d\n",ans);

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(){
    int h,w,ans=0;
    cin >> h >> w;
    vector<string>s(h);
    rep(i,h)cin >> s[i];

    rep(i,h){
        rep(j,w){
            if(j!=w-1 and s[i][j]=='.' and s[i][j+1]=='.')ans++;
            if(i!=h-1 and s[i][j]=='.' and s[i+1][j]=='.')ans++;
        }
    }

    cout << ans;

    return 0;
}


    #include<bits/stdc++.h>

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))
#define all(v) v.begin(),v.end()
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif

int main()
{
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    string str;
    cin >> str;
    bool hard = true;

    for(int i = 0;i < str.size();i += 2){
        if(!islower(str[i]))hard = false;
    }
    for(int i = 1;i < str.size();i += 2){
        if(!isupper(str[i]))hard = false;
    }
    if(hard)cout << "Yes\n";
    else cout << "No\n";

    #ifdef VAMP
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i < (n); ++i)
#define repD(i, a, n) for(ll i = a; i > (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
// #define mp make_pair
#define pb push_back
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
long long Ceil(long long a, long long b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}
// ll p=1000000007;
ll p = 1000000000000000000+5;
float E = 0.00000000000001;
ll power(ll x, ll y){
    if(y==0){
        return 1;
    }
    if(y%2==0){
        ll q=power(x,y/2);
        q=q%p;
        return (q*q)%p;
    }
    ll q=power(x,y/2);
    q=q%p;
    return ((x%p)*((q*q)%p))%p;
}
bool isPowerOfTwo (long long x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}

long long int gcd(long long int a, long long int b){
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
long long int mod(long long int a, long long int b) {
    long long int ret = a%b; return ret>=0? ret: ret+b;
}

bool compare(pair<int, int> p1, pair <int, int> p2){
    if(p1.first < p2.first)
        return true;
    else if(p1.first > p2.first)
        return false;
    else
        return p1.second > p2.second;
}

int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        int n;cin>>n;
        vector <long long> vec(n);
        for(auto &x:vec)
            cin>>x;
        long long ans = 0;
        vector <long long> pref(n);
        vector <long long> max_pref(n);
        max_pref[0] = max(0ll, vec[0]);
        pref[0] = vec[0];
        for(int i = 1 ; i < n ; i++){
            pref[i] = pref[i-1]+vec[i];
            max_pref[i] = max(pref[i], max_pref[i-1]);
        }
        long long curr = 0;
        for(int i = 0 ; i < n ; i++){
            ans = max(curr+max_pref[i], ans);
            curr += pref[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define iamspeed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define nl "\n"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fl(i,a,b) for(ll i=a;i<b;i+=1)
#define rl(i,a,b) for(ll i=a;i>b;i-=1)
#define input(a,n) fl(i,0,n)cin>>a[i];
#define printt(a,n) fl(i,0,n) cout<<a[i]<<' ';
#define all(a) a.begin(),a.end()
#define test() ll t; cin>>t; while(t--)
#define maxelement(arr,n) *max_element(arr,arr+n)
//typedef long long ll;
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int N = 1e6;
using namespace std;

int main(){
	iamspeed;
	long n,x,h;
	cin>>n>>x;
	fl(i,0,n){
		cin>>h;
		if(h!=x){
			cout<<h<<" ";
		}
	}
	cout<<endl;
}

//APPROACHING A QUESTION
//+ Think of binary search (max of min etc also if n<=2*10^5)
//+ Think of common dp states (Even if it appears as maths
//but constraints are small)
//+ Check constraints
//+ Keep calm and enjoy the question
//+ Be sure to remove MOD from binpow (if needed)
//+ Try bidirectional analysis for constructive questions
//+ If given some sequence try thinking of prefix sums
//+ If constraints are too large maybe its simple maths
//+ In questions with binary operations think of bits independently
//and also the change pattern
//+ If two or more binary operations are given mostly there is
//a relation between them and an arithmatic operator
//+ multi sorce bfs
// credits: fischerman

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

mt19937_64 llrand((int) chrono::steady_clock::now().time_since_epoch().count());

#define st first
#define nd second
#define pb push_back

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;

const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

const ll MAX = 1e13;

ll n;
int p[35];

ll exp(ll b, ll e) {
  ll ans = 1;
  for(int i = 1; i <= e; i++) ans *= b;
  return ans;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;

  ll ans = 1ll;

  for(ll i = 2; i <= n; i++) {

    ll aux = i;
    for(ll k = 2; k <= aux; k++) {
      int cnt = 0;
      while(aux % k == 0) {
        aux /= k;
        cnt++;
      }

      p[k] = max(p[k], cnt);
    }

  }

  for(int i = 2; i <= n; i++) ans = ans * exp(i, p[i]);

  ans++;

  cout << ans << "\n";
  assert(ans >= n and ans <= MAX);
  for(ll i = 2; i <= n; i++) assert(ans % i == 1);
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    int ans = 4;
    if(A+B>=15 && B>=8) ans = 1;
    else if(A+B>=10 && B>=3) ans = 2;
    else if(A+B>=3) ans = 3;
    cout << ans << endl;

}

#include <bits/stdc++.h>
using namespace std;
#define fo(a,b) for(int64_t a=0;a<b;a++)
#define sor(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define ll int64_t
#define mod 1000000007
#define vl vector<int64_t>
#define vc vector<char>
#define vs vector<string>
#define np(vec) next_permutation(vec.begin(),vec.end())==true
#define en endl
#define vvl vector<vector<int64_t>>
#define stl stack<int64_t>
#define qul que<int64_t>
#define ms(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pq priority_queue
#define pql priority_queue<int64_t>
#define pu push
#define po pop()
#define to top()
#define pqr priority_queue<ll,vector<ll>,greater<ll>>
#define co cout
#define ci cin
#define wh while
#define size size()

int main() {
  ll a,b;
  cin>>a>>b;
  if(a+b>=15&&b>=8){cout<<1<<en;}
  else if(a+b>=10&&b>=3){co<<2<<en;}
  else if(a+b>=3){cout<<3<<en;}
  else{cout<<4<<en;}
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a/gcd(a, b)*b;}
//cout << fixed << setprecision(15);

int N, M, K, H, W, L, R, X, Y;
string S, T;
int INF = 1e15;

signed main(){
  cin >> N;
  vi p(N);
  rep(i,N) cin >> p[i];
  int cur = 0;
  map<int, int>  mp;
  rep(i,N){
    mp[p[i]]++;
    while(mp[cur]!=0) cur++;
    COUT(cur);
  }
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  cout << N / W << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<=(int)(n); i++)
#define rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;
typedef vector<ll> vl;
const ll inf=1LL<<60;
const ll mod=1000000007;

inline void InitRnd(){
  srand((unsigned int)time(NULL));
}

int n;
vector<tuple<int, int, int, int>> s(210);

bool checker(int a, int b, int c, int d, int j){
  rep(i, n){
    if(i==j)continue;
    int e, f, g, h;
    tie(e, f, g, h)=s[i];
    int sw=c-a, sh=d-b, tw=g-e, th=h-f, dx=e-a, dy=f-b;
    if(-tw<dx&&dx<sw&&-th<dy&&dy<sh)return false;
  }
  return true;
}

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

  InitRnd();

  cin >> n;
  vi x(n), y(n), r(n);
  rep(i, n){
  	cin >> x[i] >> y[i] >> r[i];
  	s[i]={x[i], y[i], x[i]+1, y[i]+1};
  }

  vector<bool> ok(n, false), ok0(n, false), ok1(n, false), ok2(n, false), ok3(n, false);
  int cnt=0;
  while(true){
    rep(i, n){
      if(ok[i])continue;
      int a, b, c, d;
      tie(a, b, c, d)=s[i];
      int t=(c-a)*(d-b);
      if(checker(a-1, b, c, d, i)&&a-1>=0&&!ok0[i]){
        if(t-r[i]>t-r[i]+d-b){
          cnt++;
          ok0[i]=true;
        }
        else s[i]=make_tuple(a-1, b, c, d);
      }
      else if(checker(a, b-1, c, d, i)&&b-1>=0&&!ok1[i]){
        if(t-r[i]>t-r[i]+c-a){
          cnt++;
          ok1[i]=true;
        }
        else s[i]=make_tuple(a, b-1, c, d);
      }
      else if(checker(a, b, c+1, d, i)&&c+1<=10000&&!ok2[i]){
        if(t-r[i]>t-r[i]+d-b){
          cnt++;
          ok2[i]=true;
        }
        else s[i]=make_tuple(a, b, c+1, d);
      }
      else if(checker(a, b, c, d+1, i)&&d+1<=10000&&!ok3[i]){
        if(t-r[i]>t-r[i]+c-a){
          cnt++;
          ok3[i]=true;
        }
        else s[i]=make_tuple(a, b, c, d+1);
      }
      else{
        cnt++;
        ok[i]=ok0[i]=ok1[i]=ok2[i]=ok3[i]=true;
      }
      if(ok0[i]&&ok1[i]&&ok2[i]&&ok3[i])ok[i]=true;
    }
    if(cnt>=n)break;
  }

  rep(i, n){
  	int a, b, c, d;
  	tie(a, b, c, d)=s[i];
  	cout << a << " " << b << " " << c << " " << d << endl;
  }

  return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;
using namespace chrono;

#ifdef DEBUG
	#define LOCAL_INPUT_FILE
#else
	//~ #define USE_FILE_IO
#endif

#ifdef USE_FILE_IO
	#define INPUT_FILE "input.txt"
	#define OUTPUT_FILE "output.txt"
	#define cin ____cin
	#define cout ____cout
	ifstream cin(INPUT_FILE);
	ofstream cout(OUTPUT_FILE);
#else
	#ifdef LOCAL_INPUT_FILE
		#define cin ____cin
		ifstream cin("input.txt");
	#endif
#endif

const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7;
const long double eps = 1e-8;

mt19937_64 randGen(system_clock().now().time_since_epoch().count());

inline void raiseError(string errorCode) {
	cerr << "Error : " << errorCode << endl;
	exit(42);
}

inline bool check(vector< pair<int, int> > trans) {
	int n = trans.size();
	for (int beg = 0; beg < n; ++beg) {
		vector<int> d(n, -1);
		d[beg] = 0;
		queue<int> q;
		q.push(beg);
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (int to : {trans[v].first, trans[v].second}) {
				if (d[to] < 0) {
					q.push(to);
					d[to] = d[v] + 1;
				}
			}
		}
		for (int i : d) {
			if (i > 10 || i < 0) {
				return false;
			}
		}
	}
	return true;
}

inline vector< pair<int, int> > make(int n) {
	vector< pair<int, int> > trans(n);
	for (int i = 0; i < n; ++i) {
		trans[i].first = (i*2) % n;
		trans[i].second = (i*2+1) % n;
	}
	return trans;
}

signed main() {
	#ifndef USE_FILE_IO
		ios_base::sync_with_stdio(false);
	#endif

	int n; cin >> n;
	for (auto [a1, a2] : make(n)) {
		cout << a1+1 << " " << a2+1 << endl;
	}

	//~ for (int i = 1; i <= 1000; ++i) {
		//~ if (i % 50 == 0) {
			//~ cout << "Check " << i << endl;
		//~ }
		//~ auto trans = make(i);
		//~ if (!check(trans)) {
			//~ cout << "bad at " << i << endl;
		//~ }
	//~ }

	return 0;
}


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

int main(){
    long long X,Y,A,B,T,K=0;
    cin >> X >> Y >> A >> B;
    T=X;
    while(true){
        if(T>=Y/A){
            break;
        }
        if(T*A>=Y){
            break;
        }
        if(T*A<T+B){
            K++;
            T*=A;
        }
        else{
            break;
        }
    }
    long long add=(Y-1-T)/B;
    cout << K+add << endl;
}

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

/***typededfs***/
typedef long long ll;
typedef long double ldb;

/***defines***/
#define M1 1000000007
#define M2 998244353
#define F first
#define S second
#define pb push_back
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define forz(i,n) for(int i=0;i<(n);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define rforz(i,n) for(int i=(n-1);i>=0;i--)
#define rfore(i,a,b) for(int i=(a);i>=(b);i--)
#define test int T; cin>>T; while(T--)
#define all(v) v.begin(),v.end()
#define mm(a,b) ((a%M1)*(b%M1))%M1
#define ma(a,b) ((a%M1)+(b%M1))%M1

void io(){
    FASTIO;
    #ifndef ONLINE_JUDGE
  	freopen("input.txt","r",stdin);
  	freopen("output.txt","w",stdout);
    #endif
}

int main(){
    io();
    ll x,y,a,b;
    cin>>x>>y>>a>>b;
    ll cnt{};
    while(x<=(b-1)/a&&x*a<y){
        x*=a;
        cnt++;
    }
    if(y-x-1>=0)
    cnt+=(y-x-1)/b;
    cout<<cnt<<'\n';
}


// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define mem(x,y) memset(x,y,sizeof x)
#define sz(x) (int)(x).size()
#define ln std::puts("")
#define lsp std::putchar(32)
#define pb push_back
#define MP std::make_pair
#define dbg(x) std::cerr<<__func__<<"\tLine:"<<__LINE__<<' '<<#x<<": "<<x<<"\n"
#define dprintf(x...) std::fprintf(stderr,x)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
const int MaxN=1050;
template <class t> inline void read(t &s){s=0;
reg int f=1;reg char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))s=(s<<3)+(s<<1)+(c^48),c=getchar();s*=f;return;}
template<class t,class ...A> inline void read(t &x,A &...a){read(x);read(a...);}
template <class t> inline void write(t x){if(x<0)putchar('-'),x=-x;
int buf[21],top=0;while(x)buf[++top]=x%10,x/=10;if(!top)buf[++top]=0;
while(top)putchar(buf[top--]^'0');return;}
inline void setIn(std::string s){freopen(s.c_str(),"r",stdin);return;}
inline void setOut(std::string s){freopen(s.c_str(),"w",stdout);return;}
inline void setIO(std::string s=""){setIn(s+".in");setOut(s+".out");return;}
template <class t>inline bool checkmin(t&x,t y){if(x>y){x=y;return 1;}return 0;}
template <class t>inline bool checkmax(t&x,t y){if(x<y){x=y;return 1;}return 0;}
inline int lowbit(int x){return x&(-x);}
char s[MaxN][MaxN];
int f[MaxN<<1];
inline int getf(int x)
{
	return f[x]==x?x:f[x]=getf(f[x]);
}
inline void merge(int x,int y)
{
	reg int a=getf(x),b=getf(y);
	if(a!=b)
		f[b]=a;
}
signed main(void)
{
	int n,m;read(n,m);
	for(int i=1;i<=n;++i)
		std::scanf("%s",s[i]+1);
	s[1][1]=s[n][1]=s[1][m]=s[n][m]='#';
	for(int i=1;i<=n+m;++i)
		f[i]=i;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			if(s[i][j]=='#')
				merge(i,j+n);
	std::unordered_map<int,int> r,c;
	for(int i=1;i<=n;++i)
		r[getf(i)];
	for(int i=n+1;i<=n+m;++i)
		c[getf(i)];
	write(std::min((int)r.size(),(int)c.size())-1),ln;
	return 0;
}

/*
 * Check List:
 * 1. Input / Output File (OI)
 * 2. long long
 * 3. Special Test such as n=1
 * 4. Array Size
 * 5. Memory Limit (OI) int is 4 and longlong is 8
 * 6. Mod (a*b%p*c%p not a*b*c%p  ,  (a-b+p)%p not a-b )
 * 7. Name ( int k; for(int k...))
 * 8. more tests , (T=2 .. more)
 * 9. blank \n after a case
*/


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)n ;i++)
#define rept(i,k,n) for(int i = (int)(k);i < (int)(n);i++)
#define all(vec) vec.begin(),vec.end()
#define ll int64_t
int main(){
    int n;
    cin >> n;
    vector<vector<int> > c(n,vector<int>(n));
    vector<int> a(n),b(n);
    int ma = 0,mb = 0;
    rep(i,n){
        rep(j,n){
            cin >> c[i][j];
        }
        b[i] = c[0][i]-c[0][0];
        a[i] = c[i][0]-c[0][0];
        mb = min(mb,b[i]);
        ma = min(ma,a[i]);
    }
    rep(i,n){
        rep(j,n){
            if(c[i][j]-c[i][0] != b[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    rep(i,n){
        //cout << b[i] << endl;
    }
    cout << "Yes" << endl;
    if(ma < mb){
        rep(i,n){
        cout << a[i]-ma << " ";
        }
        cout << endl;
        rep(i,n){
        cout << b[i]+c[0][0]+ma << " ";
        }
    }
    else{
        rep(i,n){
        cout << a[i]+mb+c[0][0] << " ";
        }
        cout << endl;
        rep(i,n){
        cout << b[i]-mb << " ";
        }
    }
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fin(a) { cout << a << endl; return 0; }
#define debug(a) { cerr << #a << ": " << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using ld = long double;
using P = pair<int,int>;
using Pl = pair<lint,lint>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return ((a)+(b)-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
template<class T> void YesorNo(T x) { printf(x ? "Yes\n" : "No\n"); }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
    return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
    return out << '{' << p.first << ',' << p.second << '}';
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
    for(auto &&e : v) in >> e;
    return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
    for(const auto &e : v) out << e << ' ';
    return out;
}

/*----------------------------------------------------------------------------------------------------*/

int main(){
    int n;
    cin >> n;
    V<V<int>> c(n,V<int>(n));
    cin >> c;
    bool ok = true;
    rep(i,n)rep(j,n-1) {
        ok &= (c[i][j+1]-c[i][j] == c[0][j+1]-c[0][j]);
    }
    rep(j,n)rep(i,n-1) {
        ok &= (c[i+1][j]-c[i][j] == c[i+1][0]-c[i][0]);
    }
    if(!ok) fin("No");

    V<int> d(n-1);
    Rep(i,n-1) d[i-1] = c[0][i]-c[0][i-1];

    int l = -1, r = INF;
    while(r-l > 1) {
        int mid = (l+r)/2;
        int now = mid;
        bool ok = true;
        rep(i,n-1) {
            now += d[i];
            if(now < 0) ok = false;
        }
        if(ok) r = mid;
        else l = mid;
    }
    V<int> b(n); b[0] = r;
    rep(i,n-1) b[i+1] = b[i] + d[i];
    V<int> a(n);
    rep(i,n) {
        a[i] = c[i][0]-b[0];
        if(a[i] < 0) fin("No");
    }
    cout << "Yes" << endl;
    cout << a << endl << b << endl;
}


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

const ll INF = 2e18;

int main() {
  ll n;
  cin >> n;
  vector<vector<ll>> c(n, vector<ll>(n));
  rep(i, n) rep(j, n) cin >> c[i][j];
  bool f = 1;
  rep(j, n - 1) {
    ll t = c[0][j] - c[0][j + 1];
    rep(i, n) {
      if (c[i][j] - c[i][j + 1] != t) {
        f = 0;
        break;
      }
    }
  }

  if (f) {
    cout << "Yes" << endl;
    vector<ll> mn(n, INF);
    rep(j, n) rep(i, n) mn[j] = min(mn[j], c[j][i]);
    rep(i, n) cout << mn[i] << ' ';
    cout << endl;
    rep(i, n) cout << c[0][i] - mn[0] << ' ';
    cout << endl;

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

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll c[501][501];
ll lc[501][501];
ll a[501],b[501];
ll difa[501];
ll difsuma[501];
ll difb[501];
ll difsumb[501];

bool solve(){
	for(int i=0;i+1<n;i++){
		difa[i]=c[0][i+1]-c[0][i];
		for(int j=0;j<n;j++){
			if(difa[i]!=(c[j][i+1]-c[j][i])){
				return false;
			}
		}
	}
	for(int i=0;i+1<n;i++){
		difb[i]=c[i+1][0]-c[i][0];
		for(int j=0;j<n;j++){
			if(difb[i]!=(c[i+1][j]-c[i][j])){
				return false;
			}
		}
	}
	for(int i=0;i<n;i++){
		difsuma[i+1]=difsuma[i]+difa[i];
		difsumb[i+1]=difsumb[i]+difb[i];
	}
	ll difamin=0;
	ll difbmin=0;
	for(int i=0;i<=n;i++){
		difamin=min(difamin,difsuma[i]);
		difbmin=min(difbmin,difsumb[i]);
	}
	if(-(difamin+difbmin)>c[0][0])return false;
	ll ch=c[0][0]+(difamin+difbmin);
	for(int i=0;i<n;i++){
		a[i]=difsuma[i]-difamin+ch;
		b[i]=difsumb[i]-difbmin;
	}
	return true;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			scanf("%lld",&c[i][j]);
		}
	}
	if(!solve()){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	for(int i=0;i<n;i++){
		printf("%lld%c",b[i],(i+1==n)?'\n':' ');
	}
	for(int i=0;i<n;i++){
		printf("%lld%c",a[i],(i+1==n)?'\n':' ');
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define ll long long
#define ar array
const ll mxN=2e5;
const int mod=1e9+7;
const ll INF=1e18;
#define what_is(x) cerr << #x << " is " << x << endl;
ll a,b,n,k,q,m,x,y,h,l,r,t;
ll d[mxN],c[mxN];
vector<ll> adj[mxN];
void dfs(ll u=0,ll p=-1){
	for(ll v: adj[u]){
		if(v==p)continue;
		d[v]=d[u]+1;
		dfs(v,u);
	}
}

void dfs2(ll u=0,ll p=-1){

	for(ll v: adj[u]){
		if(v==p) continue;
		c[v]+=c[u];
		dfs2(v,u);
	}
}
void solve(){
	cin>>n;
	vector<ar<ll,2>> edges;
	for(ll i=0;i<n-1;i++){
		ll a,b;
		cin>>a>>b; --a,--b;
		edges.push_back({a,b});
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs();
	cin>>q;
	while(q--){
		ll t,e,x;
		cin>>t>>e>>x;--e;
		if(t==1){
			if(d[edges[e][0]] < d[edges[e][1]]){
				c[edges[e][1]]-=x;
				c[0]+=x;
			}else{
				c[edges[e][0]]+=x;
			}
		}
		if(t==2){
			if(d[edges[e][0]] > d[edges[e][1]]){
				c[edges[e][0]]-=x;
				c[0]+=x;
			}else{
				c[edges[e][1]]+=x;
			}
		}
	}
	dfs2();
	for(ll i=0;i<n;i++){
		cout<<c[i]<<endl;
	}
}

signed main() {
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    cout<<setprecision(12)<<fixed;
    // cin>>t;
    // while(t--)
    	solve();
	return 0;

}

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

int main() {
  int N; cin >> N;
  vector<int64_t> a(N-1), b(N-1);
  vector<vector<int64_t>> l(N, vector<int64_t>(0));
  rep(i, N-1) {
    cin >> a.at(i) >> b.at(i);
    a.at(i)--; b.at(i)--;
    l.at(a.at(i)).push_back(b.at(i));
    l.at(b.at(i)).push_back(a.at(i));
  }
  int Q; cin >> Q;
  vector<int64_t> t(Q), e(Q), x(Q);
  rep(i, Q) {
    cin >> t.at(i) >> e.at(i) >> x.at(i);
    e.at(i)--;
  }
  vector<int64_t> tr(N, -1), temp(N, 0), d(N, -1);
  int64_t dn = 0;
  vector<int64_t> now = {0};
  while (now.size()) {
    vector<int64_t> next(0);
    rep(i, now.size()) if (d.at(now.at(i)) == -1) {
      d.at(now.at(i)) = dn;
      rep(j, l.at(now.at(i)).size()) next.push_back(l.at(now.at(i)).at(j));
    }
    dn++; now = next;
  }
  // rep(i, N) cout << d.at(i) << endl;
  rep(i, Q) {
    int64_t Qa, Qb;
    Qa = a.at(e.at(i)); Qb = b.at(e.at(i));
    if (t.at(i) == 2) swap(Qa, Qb);
    if (d.at(Qa) < d.at(Qb)) {
      temp.at(0) += x.at(i); temp.at(Qb) -= x.at(i);
    } else {
      temp.at(Qa) += x.at(i);
    }
    // rep(i, N) cout << temp.at(i) << endl;
  }
  now = {0};
  while (now.size()) {
    vector<int64_t> next(0);
    rep(i, now.size()) if (tr.at(now.at(i)) == -1) {
      tr.at(now.at(i)) = temp.at(now.at(i));
      rep(j, l.at(now.at(i)).size()) {
        next.push_back(l.at(now.at(i)).at(j));
        temp.at(l.at(now.at(i)).at(j)) += temp.at(now.at(i));
      }
    }
    dn++; now = next;
  }
  rep(i, N) cout << tr.at(i) << endl;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)
#define y1 awefakhlrv

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    int n, k; cin >> n >> k;
    vvi a(n + 1, vi(n + 1));
    FOR(i, 1, n) FOR(j, 1, n)
        cin >> a[i][j];
    int ans = 0x3f3f3f3f, nd = k * k / 2 + 1;
    ROF(bl, 29, 0) {
        int na = ans - (1 << bl);
        if (na < 0) continue;
        // cout << na << endl;
        vvi f(n + 1, vi(n + 1)), cnt(f);
        FOR(i, 1, n) FOR(j, 1, n)
            f[i][j] = (a[i][j] >= na);
        // FOR(i, 1, n) FOR(j, 1, n)
        //     cout << f[i][j] << (j == n ? '\n' : ' ');
        vvi psn(n + 1, vi(n + 1));
        FOR(i, 1, n) FOR(j, 1, n)
            psn[i][j] = psn[i][j - 1] + f[i][j];
        FOR(i, 1, n)
            FOR(j, k, n)
                cnt[i][j] = psn[i][j] - psn[i][j - k];
        vvi psm(n + 1, vi(n + 1));
        FOR(i, 1, n) FOR(j, k, n)
            psm[i][j] = psm[i - 1][j] + cnt[i][j];
        // FOR(i, 1, n) FOR(j, 1, n)
        //     cout << cnt[i][j] << (j == n ? '\n' : ' ');
        int mx = 0x3f3f3f3f;
        FOR(i, k, n) FOR(j, k, n) {
            mx = min(psm[i][j] - psm[i - k][j], mx);
        }
        // cout << endl << mx << endl;
        if (mx < nd) ans = na;
    }
    cout << ans - 1 << endl;
}

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

#define ios			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR(i,m)		for(int i = 0 ;i  < m ;i++)
#define mem(a ,b)		memset(a,  (b) , sizeof(a))
#define all(cont)		cont.begin(),cont.end()
#define mp			make_pair
#define pb			push_back
#define F			first
#define S			second
#define cn			cout<<'\n'
#define re			return

typedef pair<int,int>		pi;
typedef	vector<int>		vi;
typedef long long 		ll;
typedef long double		ld;
typedef unsigned long long int  ull;

const int mod = 1e9 +7;

int a[801][801];
int p[801][801];
int n  , k;

bool check(int x){
	memset(p , 0 , sizeof(p));

	for(int i = 1 ;i <= n ;i++){
		for(int j = 1 ;j <= n ;j++){
			p[i][j] = (a[i][j] <= x ? 1 : 0);
		}
	}

	for(int i =1  ;i <= n;i++){
		for(int j = 1; j <= n ;j++){
			p[i][j] += p[i-1][j] + p[i][j-1] - p[i-1][j-1];
		}
	}

	int max_val = 0;
	for(int i = k; i <= n ;i++){
		for(int j = k ;j <= n ;j++){
			max_val = max(max_val , p[i][j] - p[i-k][j] - p[i][j-k] + p[i-k][j-k]);
		}
	}
	return max_val >= (k*k + 1)/2;
}

void solve(){

	cin >> n >> k;

	for(int i = 1 ;i <= n ;i++){
		for(int j = 1 ; j <= n ;j++)cin>>a[i][j];
	}

	int l = 0 , r = mod-7;

	while(l < r){
		int mid = l + (r-l)/2;

		if(check(mid)){
			r = mid;
		}
		else l = mid + 1;
	}
	cout<<l<<"\n";

}

int32_t main(){

	ios;

	int _t = 1;
//	cin >> _t;

	for(int i = 1 ; i  <= _t ;i++){
//		cout<< "Case #"<<i<<": ";
		solve();
	}

	return 0;
}


//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)
//
////#define ATCODER
//#ifdef ATCODER
//#include<atcoder/all>
//using namespace atcoder;
//#endif

#include <algorithm>
#include <utility>
#include <vector>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <numeric>
#include <type_traits>

using namespace std;

#ifdef _MSC_VER
#include"stdafx.h"
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << (H);
	debug_out(T...);
}
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define DEBUG(...) 42
#endif

#define ll long long
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREVERSE(v) reverse(v.begin(), v.end())

#define print(x) cout << (x) << '\n'
#define spa <<" "<<
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
template <typename T1, typename T2> inline bool chmin(T1 & a, T2 b) { if (a > b) { a = b; return true; }return false; }
template <typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return true; }return false; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 400040;
const double pi = acos(-1);
constexpr long double EPS = 1e-14;
const int dx[4] = { 0,0,-1,1 }, dy[4] = { -1,1,0,0 };
using ld = long double;
int X, Y;
unordered_map<int,int> dp;
int rec(int y) {
	if (dp.count(y))return dp[y];
	if (y <= X)return X - y;
	int ret = abs(X - y);
	if (y % 2 == 0) {
		chmin(ret, 1+rec(y / 2));
	}
	else {
		chmin(ret, 2+rec((y + 1) / 2));
		chmin(ret, 2+rec((y - 1) / 2));
	}
	return dp[y] = ret;
}

void solve() {
	cin >> X >> Y;
	print(rec(Y));
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}

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

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


#include <bits/stdc++.h>

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

struct Edge {
    ll b, t, k;
};

ll f(ll now, ll k) {
    return ((now + (k - 1)) / k) * k;
}

void solve() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    X--, Y--;
    vector<vector<Edge>> G(N);
    for (int i = 0; i < M; i++) {
        ll a, b, t, k;
        cin >> a >> b >> t >> k;
        a--, b--;
        G[a].push_back({b, t, k});
        G[b].push_back({a, t, k});
    }

    priority_queue<pll, vector<pll>, greater<pll>> Q;
    Q.push({0, X});
    ll INF = 2e18;
    vector<ll> dist(N, INF);
    while(!Q.empty()) {
        pll p = Q.top(); Q.pop();
        ll d = p.first, v = p.second;
        if (d >= dist[v]) continue;
        dist[v] = d;

        for(int i = 0; i < G[v].size(); i++) {
            ll u = G[v][i].b;
            ll t = G[v][i].t;
            ll k = G[v][i].k;
            ll nt = t + ((d + (k - 1)) / k) * k;
            if (nt < dist[u]) {
                Q.push({nt, u});
            }
        }
    }
    if (dist[Y] == INF) {
        cout << -1 << endl;
    } else {
        cout << dist[Y] << endl;
    }
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);

    solve();
}

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mx 1000005
#define fiint(a,b) memset(a,b,sizeof(a))
#define bitcount __builtin_popcount
#define fori(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cout<<x<<endl;
#define cases(t) int t; cin>>t; while(t--)
#define inf1 INT_MAX
#define all(a) a.begin(),a.end()
#define vec vector<int>
#define pii pair<int,int>
#define plii pair<int,int>
#define pint pair<int,int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mp make_pair

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

int factorial[10000001]={0};

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

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

void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
    factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}

int nCr(int n, int r)
{
    if(r < 0 || r > n){
        return 0;
    }
    int temp = factorial[n];
    temp *= (powerFunction(factorial[r], MOD-2)%MOD);
    temp %= MOD;
    temp *= (powerFunction(factorial[n-r], MOD-2)%MOD);
    temp %= MOD;
    return temp;
}

signed main()
{
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<pair<int ,pii >> adj[100005];
    for(int  i = 0 ; i  < m ;i++)
    {
        int a,b,t,k;cin>>a>>b>>t>>k;
        adj[a].pb(mp(b , mp(t, k) ));
        adj[b].pb(mp(a , mp(t , k)));
    }

    vec vis(n + 1 , 0);
    priority_queue<pii , vector<pii> , greater<pii> > q;
    vec dis( n + 1, -1);
    q.push(mp( 0 ,x  ));
    dis[x] = 0;
    while(sz(q) != 0 )
    {
        int s = q.top().ss;
//int d = q.front().ff;
        q.pop();
        if(s == y)
            break;
        vis[s] = 1;
        for(auto it : adj[s])
        {
                if(vis[it.ff] == 1)
                    continue;
            int re = ( ( dis[s] % it.ss.ss == 0) ? 0 : it.ss.ss  - (dis[s] % it.ss.ss)       );
            re += dis[s] + it.ss.ff;
            if(dis[it.ff] == -1 || dis[it.ff] > re)
            {
                dis[it.ff] = re;
                q.push(mp(re , it.ff));
            }
        }
    }
    cout<<dis[y]<<endl;
}


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

int main() {
  int N, K, M;
  cin >> N >> K >> M;
  M *= N;
  int sum = 0;
  for (int i = 0; i < N - 1; i++) {
    int a;
    cin >> a;
    sum += a;
  }
  if (M - sum > K) {
    cout << -1 << endl;
  } else {
    cout << max(0, M - sum) << endl;
  }
  return 0;
}

#include <iostream>
using namespace std;
int main(void){
    int n,k,m,ans,sum;
    ans = -1;
    sum = 0;
    cin >> n;
    cin >> k >> m;
    for(int i=1;i<n;i++){
       int temp;
       cin >> temp;
       sum += temp;
    }
    for(int i=0;i<= k;i++){
        if(m <= (sum + i)/n){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll>
#define vvl vector<vll>
#define vpll vector<pll>
#define pll pair<ll,ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt","r",stdin);
	ll T=1;
	//cin >> T;
	ll t=0;
	while(t++<T){
		ll a,b,c;
		cin>>a>>b>>c;
		ll ans=21-(a+b+c);
		cout<<ans<<endl;

	}
return 0;
}

//********************************************************************//
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define RANGE(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DFOR(i, a, b) for(int i = a; i > b; --i)
#define DEB(x) cout << #x << ": " << x << endl
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define DISPV(v) { for(auto x___: v) cout << x___ << " "; cout << endl; }
#define DISPM(m) { for(auto x____: m){ cout << x____.first << ": " << x____.second << endl; } };
#define DISPMV(m) { for(auto x_____: m){ cout << x_____.first << ": " ;DISPV(x_____.second);} };
using LL = long long;
using VI = vector <int>;
using VL = vector <long long>;
using VVI = vector<VI>;
using VVL = vector <VL>;
using MII = map<int, int>;
using MIVI = map<int, VI>;
using MLL = map<LL, LL>;
int READ_INT(){int temp;cin>>temp;return temp;}      // read an int
LL READ_LONG(){LL temp;cin>>temp;return temp;}      // read a long long
string READ_STRING(){string temp;cin>>temp;return temp;}      // read a string

const int MOD = int(1e9) + 7;
const int INF = 1e9 + 5;
const double PI = acos(-1.0); //M_PI;
const double EPS = 1e-9;
//********************************************************************//

int n;
VI t;
LL dp[105][100005];

LL min_time(int ind, int nxt_free_time){
    if(ind==n)return nxt_free_time;
    if(dp[ind][nxt_free_time] != -1)return dp[ind][nxt_free_time];
    LL l = min_time(ind+1, nxt_free_time+t[ind]);
    LL r = min(nxt_free_time, t[ind])+ min_time(ind+1, abs(nxt_free_time - t[ind]));
    return dp[ind][nxt_free_time] = min(l, r);
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n;
    RANGE(i,n)t.push_back(READ_INT());
    memset(dp, -1, sizeof(dp));
    cout << min_time(0, 0) << endl;

    return 0;
}

/* complie flags
-Wall -Wextra -pedantic -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector
*/


#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for (int i = (int)(l); i < (int)(n); i++)
#define drep(i, l, n) for (int i = (int)(n); i > (int)(l); i--)
#define INF INT_MAX
#define def (200007)
#define MOD (1000000007)
typedef vector<int> veci;
typedef vector<vector<int>> Veci;
typedef vector<int64_t> vecit;
typedef vector<vector<int64_t>> Vecit;
typedef int64_t intt;
typedef vector<vector<double>> Vecd;
typedef vector<double> vecd;
typedef pair<int, int> P;
/*veci のときdist.resize(N) Veciのとき2回resize;
dp.assign(N,-1);*/

int main(){
  int n;
  cin>>n;
  vector<string> name;
  int at_max=0;int at_i=0;int second_max=0,second_i=0;
  rep(i,0,n){
    string s;int t;
    cin>>s>>t;
    if(at_max<t){
      second_max=at_max;
      at_max=t;
      second_i=at_i;
      at_i=i;
     }else if(second_max<t){
      second_max=t;
      second_i=i;
    }
    name.push_back(s);
  }
  cout<<name[second_i]<<endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ll long long
#define ld long double

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n; cin >> n;
	vector<pair<int, int>>arr;
	map<int, string>kode;
	int cur=0;
	for(int i=0;i<n;++i){
		string s; int x;
		cin >> s >> x;
		kode[cur]=s;
		arr.pb({x, cur});
		cur++;
	}
	sort(arr.begin(), arr.end(), greater<pair<int, int>>());
	cout << kode[arr[1].se] << '\n';
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

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

struct mint {
  unsigned int x;
  mint():x(0) {}
  mint(int64_t x_) {
    int64_t v = int64_t(x_ % mod);
    if(v < 0) v += mod;
    x = (unsigned int)v;
  }
  static mint row(int v) {
    mint v_;
    v_.x = v;
    return v_;
  }
  mint operator-() const { return row(x?mod-x:0);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    uint64_t z = x;
    z *= a.x;
    x = (unsigned int)(z % mod);
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  friend bool operator==(const mint &a, const mint &b) {return a.x == b.x;}
  friend bool operator!=(const mint &a, const mint &b) {return a.x != b.x;}
  mint &operator++() {
    x++;
    if(x == mod) x = 0;
    return *this;
  }
  mint &operator--() {
    if(x == 0) x = mod;
    x--;
    return *this;
  }
  mint operator++(int) {
    mint result = *this;
    ++*this;
    return result;
  }
  mint operator--(int) {
    mint result = *this;
    --*this;
    return result;
  }
  mint pow(int64_t t) const {
    mint x_ = *this, r = 1;
    while(t) {
      if(t&1) r *= x_;
      x_ *= x_;
      t >>= 1;
    }
    return r;
  }
  //for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

string to_string(mint a) {
  return to_string(a.x);
}

//head

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  if(n == 1) {
    cout << m << endl;
    return 0;
  }
  mint ans, _ = mint(m).inv();
  vector<mint> _r(m+1), r(m, mint(1));
  for(int j = 1; j < m+1; j++) _r[j] = (-_*j).inv();
  for(int i = 1; i < n; i++) {
    for(int j = 1; j < m+1; j++) {
      r[j-1] *= -_*j+1;
      ans += (r[j-1]-1)*_r[j];
    }
  }
  cout << mint(m).pow(n)*n - ans*mint(m).pow(n-2) << endl;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

const int MOD = 998244353;
int quick_pow(int a,int x) {
    int ret = 1;
    while(x) {
        if (x & 1) {
            ret = 1LL * ret * a % MOD;
        }
        x >>= 1;
        a = 1LL * a * a % MOD;
    }
    return ret;
}
int N, M;
int q[5010][5010];

int main() {
    scanf("%d%d",&N,&M);
    for (int i=0;i<=M;i++) {
        for (int j=0;j<=N;j++) {
            q[i][j] = quick_pow(i, j);
        }
    }
    LL ans = 1LL * q[M][N] * N % MOD;
    for (int i=1;i<=M;i++) {
        for (int len=2;len<=N;len++) {
            LL pos = N - len + 1;
            LL in = q[M - i][len - 2];
            LL out = q[M][N - len];
            ans = (ans + MOD - pos * in % MOD * out % MOD) % MOD;
        }
    }
    printf("%lld\n",ans);
}


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

struct Edge
{
  ll to;
  ll weight;
  Edge(ll t, ll w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;

// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  for (auto &it : S) {
    if (it == '6')
      it = '9';
    else if (it == '9')
      it = '6';
  }
  cout << S << endl;
  return 0;
}

#include<bits/stdc++.h>
#define int long long
#define REP(i,a,n) for(int i=a;i<(n);i++)
#define REP_sz(i,s) for(int i=0;i<s.size();i++)
#define gcd(a,b) __gcd(a,b)
#define RE return
#define FILL(a,b) memset(a,b,sizeof(a))
#define SO(a) sort(all(a))
#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) (int)a.size()
#define V vector
#define ld long double
#define viit(a) vector<int>::iterator a
#define IT iterator
#define SET setprecision
#define FOR(i,a,n) for(int i=a;i<=(n);i++)
#define ER1(a) a.erase(a.begin())
#define ER0(a) a.erase(a.end())
#define pii pair<int,int>
#define pause system("PAUSE")
#define cls system("CLS")
#define mod1 1000000007
#define mod2 998244353
#define infmod 9223372036854775783
#define tc int t;cin>>t;while(t--)solve();
#define over(x) {cout<<x<<endl;return;}
#define intsz(x) (int)sz(to_string(x))
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	string s;
	int d[]={0,1,0,0,0,0,9,0,8,6};
	cin>>s;
	REP_sz(i,s){
		s[i]='0'+d[s[i]-'0'];
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[2005];

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    ll mn = INF;
    REP(i, N) {
        mn = std::min(mn, A[i]);
    }
    std::unordered_map<ll, ll> mp;
    REP(i, N) {
        ll n = 1;
        while (n * n <= A[i] && n <= mn) {
            if (A[i] % n == 0) {
                {
                    auto it = mp.find(n);
                    if (it == mp.end()) {
                        mp[n] = A[i];
                    }
                    else {
                        it->second = gcd(it->second, A[i]);
                    }
                }
                ll x = A[i] / n;
                if (x <= mn) {
                    auto it = mp.find(x);
                    if (it == mp.end()) {
                        mp[x] = A[i];
                    }
                    else {
                        it->second = gcd(it->second, A[i]);
                    }
                }
            }
            n++;
        }
    }
    ll ans = 0;
    for (auto &p : mp) {
        if (p.first == p.second)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000;
constexpr ll llINF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
ll modpow(ll a,ll b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    ll memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<ll>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(ll i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<ll>(m+1,0));
    sC.resize(n+1,vector<ll>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}
ll comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
ll inv(ll x){
    x=modpow(x,mod-2);
    return x;
}
void solve(){
    int n;
    string s[110];
    cin>>n;
    rep(i,n)cin>>s[i];
    int d[110][110];
    rep(i,n){
        rep(j,n){
            if(s[i][j]=='1')d[i][j]=1;
            else if(i==j)d[i][j]=0;
            else d[i][j]=INF;
        }
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                chmin(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    double ans=0;
    rep(i,n){
        int c=0;
        rep(j,n){
            if(d[j][i]<INF)c++;
        }
        ans+=1.0/c;
    }
    printf("%.12lf\n",ans);
}
int main(){
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}