#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int h, w;
bool a[3000][3000];
int b[3000][3000];
signed main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < w; j++) {
			if (s[j] == '#') a[i][j] = 1;
		}
	}
	//bは、これより右でこことしたがの関係が同じところの長さ
	for (int j = w - 1; j >= 0; j--) b[h - 1][j] = w - j;
	for (int i = 0; i < h - 1; i++) {
		for (int j = w - 1; j >= 0; j--) {
			if (j == w - 1 || ((a[i][j] == a[i + 1][j]) != (a[i][j + 1] == a[i + 1][j + 1]))) {
				b[i][j] = 1;
			}
			else {
				b[i][j] = b[i][j + 1] + 1;
			}
		}
	}
	int ans = 0;
	for (int j = 0; j < w; j++) {
		stack<H>st;
		//x=高さ、y=場所
		for (int i = h - 1; i >= 0; i--) {
			if (!st.empty() && st.top().x > b[i][j]) {
				int k = i;
				while (!st.empty() && st.top().x > b[i][j]) {
					if (st.top().y == h - 1)
						ans = max(ans, (st.top().y - i)*st.top().x);
					else
						ans = max(ans, (st.top().y - i + 1)*st.top().x);
					k = st.top().y;
					st.pop();
				}
				st.push(H{ b[i][j],k });
			}
			else if (st.empty() || st.top().x < b[i][j]) {
				st.push(H{ b[i][j],i });
			}
		}
		while (!st.empty()) {
			if (st.top().y == h - 1)
				ans = max(ans, (st.top().y + 1)*st.top().x);
			else
				ans = max(ans, (st.top().y + 2)*st.top().x);
			st.pop();
		}
	}
	cout << ans << endl;
}

#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector<s>
#define vvec(s) vector<vector<s>>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " "
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli a, b;
    cin>>a>>b;
    lli ans=0;
    rep(i,2){
        if(a>b){
            ans+=a;
            a--;
        }
        else{
            ans+=b;
            b--;
        }
    }
    out(ans);
}


#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
    int n, m;
    cin >> n >> m;
    vector<int>s(m);
    vector<int>c(m);
    vector<int>cnt(3),cnt2(3);
    rep(i, 3)cnt[i] = -101,cnt2[i] = 0;
    int ans = 0;

    rep(i, m) {
        cin >> s[i] >> c[i];
        if (n == 1) {
            if (s[i] > 1) {
                cout << -1 << endl;
                return 0;
            }
            else {
                if (cnt[0] !=  c[i] && cnt2[0] != 0) {
                    cout << -1 << endl;
                    return 0;
                }
                if (cnt2[0] == 0) {
                    ans += c[i];
                }
                cnt2[0]++;
                cnt[0] = c[i];
            }
        }
        else if (n == 2) {
            if (s[i] > 2) {
                cout << -1 << endl;
                return 0;
            }
            else {
                if (s[i] == 2) {
                    if (cnt[1] != c[i] && cnt2[1] != 0) {
                        cout << -1 << endl;
                        return 0;
                    }
                    if (cnt2[1] == 0) {
                        ans += c[i];
                    }
                    cnt2[1]++;
                    cnt[1] = c[i];
                }
                else if (s[i] == 1) {
                    if (cnt[0] != c[i] && cnt2[0] != 0) {
                        cout << -1 << endl;
                        return 0;
                    }
                    if (c[i] == 0) {
                        cout << -1 << endl;
                        return 0;
                    }
                    if (cnt2[0] == 0) {
                        ans += c[i] * 10;
                    }
                    cnt2[0]++;
                    cnt[0] = c[i];
                }
            }
        }
        else {
            if (s[i] == 3) {
                if (cnt[2] != c[i] && cnt2[2] != 0) {
                    cout << -1 << endl;
                    return 0;
                }
                if (cnt2[2] == 0) {
                    ans += c[i];
                }
                cnt2[2]++;
                cnt[2] = c[i];
            }
            if (s[i] == 2) {
                if (cnt[1] != c[i] && cnt2[1] != 0) {
                    cout << -1 << endl;
                    return 0;
                }
                if (cnt2[1] == 0) {
                    ans += c[i] * 10;
                }
                cnt2[1]++;
                cnt[1] = c[i];
            }
            else if (s[i] == 1) {
                if (cnt[0] != c[i] && cnt2[0] != 0) {
                    cout << -1 << endl;
                    return 0;
                }
                if (c[i] == 0) {
                    cout << -1 << endl;
                    return 0;
                }
                if (cnt2[0] == 0) {
                    ans += c[i] * 100;
                }
                cnt2[0]++;
                cnt[0] = c[i];
            }
        }

    }
    if (n == 2 && cnt2[0] == 0)ans = ans + 10;
    if (n == 3 && cnt2[0] == 0)ans = ans + 100;
    cout << ans << endl;
    return 0;
}

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

bool intCheck(int i, int N, int M, vector<int> S, vector<int> C) {
    string sx = to_string(i);
    if (sx.size() != N) return false;
    for (int j = 0; j < M; j++) {
        if (sx.at(S.at(j)) != (char)C.at(j) + '0') return false;
    }
    return true;
}

int main() {
    int N, M; cin >> N >> M;
    vector<int> s(M), c(M);
    for (int i = 0; i < M; i++) {
        cin >> s.at(i) >> c.at(i);
        s.at(i)--;
    }

    bool ans = true;
    int minv = 1e5, nf = -1;
    for (int i = 0; i < 1000; i++) {
        if (intCheck(i, N, M, s, c)) {
            cout << i << endl;
            return 0;
        }
    }
    cout << nf << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

    int N;
    cin >> N;

    map<ll, ll> a;

    for(int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        a[A]++;
    }

    vector<ll> x;

    for(auto i = begin(a); i != a.end(); i++) {
        for(int j = i -> second; j > 1; j -= 2) {
            x.push_back(i -> first);
        }
    }

    sort(x.begin(), x.end(), greater<ll>());

    if(x.size() < 2) cout << 0 << endl;
    else cout << x[0] * x[1] << endl;
}

#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,char>;
using ll=long long;

int main() {
  int N;
  cin >> N;
  vector<int> A(N), V(2, 0);

  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  A.push_back(0);
  int s=1;
  for (int i=0; i<N; i++) {
    if (A[i]==A[i+1]) {
      s++;
    }
    else {
      int a=A[i];
      int n=s/2;
      //cout << N << endl;
      for (int j=0; j<n; j++) {
        V.push_back(a);
      }
      s=1;
    }
  }
  ll p=V[V.size()-1], q=V[V.size()-2];

  sort(V.begin(), V.end());
  cout << p*q << endl;
}


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

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000;

int main(){
	int n, m;
	cin>>n>>m;
	vi v(n, 0);
	vi u(n, 0);
	for(int i = 0; i < n; i++) cin>>v[i];
	int a;
	for(int i = 0; i < m; i++){
		cin>>a;
		for(int i = 0; i < n; i++){
			if(v[i] <= a){
				//cout<<" "<<i;
				u[i]++;
				break;
			}
		}
	}
	//cout<<endl;
	int ans = 0;
	for(int i = 1; i < n; i++){
		if(u[ans] < u[i]) ans = i;
	}
	cout<<ans+1<<endl;
}


#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;
typedef vector<int> ivec;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int n;cin>>n;
  int ans=0;
  string s[3];cin>>s[0]>>s[1]>>s[2];
  rep(i,n){
    char c[3];
    rep(j,3)c[j]=s[j][i];
    sort(c,c+3);
    if(c[0]!=c[1])ans++;
    if(c[1]!=c[2])ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

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

  string s;
  vector<string> S(H+2,string(W+2,'#'));
  int cnt=0;
  REP(h,H) {
    cin>>s;
    S[h+1]='#'+s+'#';
    for(auto x: S[h+1]) if(x=='.') cnt++;
  }
  int I[H+2][W+2]={};
  qp Q;
  Q.push(make_pair(1,1));
  I[1][1]=1;
  int h,w,nh,nw;
  int dh[4]={1, 0,-1, 0};
  int dw[4]={0, 1, 0,-1};
  while(!Q.empty()){
    h=Q.front().first;
    w=Q.front().second;
    Q.pop();
    REP(i,4){
      nh=h+dh[i];
      nw=w+dw[i];
      if(S[nh][nw]=='.'&&I[nh][nw]==0){
        Q.push(make_pair(nh,nw));
        I[nh][nw]=I[h][w]+1;
      }
    }
  }
  int ans=(I[H][W])? cnt-I[H][W]: -1;
  cout<<ans<<endl;
}


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

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

int main(void){

    char a;
    bool contain = false;
    rep(i, 3){
        cin >> a;
        if(a == '7'){
            contain = true;
        }
    }

    if(contain) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

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

int main() {
  string s;
  cin >> s;
  if(s.size()%2 == 1){
    cout << "No" << endl;
    return 0;
  }
  rep(i,s.size()){
    if(i%2 == 0 && s[i] != 'h'){
      cout << "No" << endl;
      return 0;
    }
    if(i%2 == 1 && s[i] != 'i'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


#include <bits/stdc++.h>

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 15, msksz = (1 << nsz) - 1, inf = 0x3f3f3f3f;
int n, m, full, lg[msksz + 5], g[nsz + 5], w[nsz + 5][nsz + 5], sum[msksz + 5], dp[msksz + 5][nsz + 5];

int inline at(int S, int id) { return S >> id & 1; }

int inline lowbit(int S) { return S & -S; }

string inline bin(int S, int len = n) {
	string s;
	loop (i, len) s += at(S, i) + 48;
	return s;
}

void inline upd(int &a, int b) { if (a < b) a = b; }

int main() {
	ios::sync_with_stdio(0);
	cin >> n >> m;
	full = (1 << n) - 1;
	cont (i, m) {
		int u, v, w;
		cin >> u >> v >> w;
		--u, --v;
		g[u] |= 1 << v;
		g[v] |= 1 << u;
		::w[u][v] = ::w[v][u] = w;
	}
	loop (i, n) lg[1 << i] = i;

	memset(sum, -inf, sizeof(sum));
	sum[0] = 0;
	cont (S, full) {
		int u = lg[lowbit(S)];
		sum[S] = sum[S - lowbit(S)];
		for (int t = g[u] & S, d = t & -t; d; t -= d, d = t & -t) {
			int v = lg[d];
			sum[S] += w[u][v];
		}
	}
	memset(dp, -inf, sizeof(dp));
	cont (S, full) {
		if (!at(S, 0) || at(S, n - 1)) continue;
		dp[S][0] = sum[S];
	}
	circ (S, 0, full) {
		for (int rS = (S ^ full), T = rS; T; T = (T - 1) & rS) {
			if (sum[T] < 0) continue;
			for (int t = S, d = t & -t; d; t -= d, d = t & -t) {
				int u = lg[d];
				if (dp[S][u] < 0) continue;
				for (int t = T & g[u], d = t & -t; d; t -= d, d = t & -t) {
					int v = lg[d];
					upd(dp[S | T][v], dp[S][u] + sum[T] + w[u][v]);
				}
			}
		}
	}
	cout << sum[full] - dp[full][n - 1] << ln;
}

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

using namespace std;

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

const int N = 16;
const int M = (1 << N);
const int INF = 0x3f3f3f3f;

int dp[N][M], g[N][N], n, m, rv[M];

int f(int st, int msk){
    if(st == n - 1) return 0;
    if(dp[st][msk] != -1) return dp[st][msk];
    int sol = INF;
    for(int msk1 = (msk - 1) & msk; msk1 ; msk1 = (msk1 - 1) & msk){
        int msk2 = msk ^ msk1;
        if(msk1 & (1 << (n - 1))) continue;
        if(msk2 & (1 << st)) continue;
        int sum = 0;
        for(int t1 = msk1; t1 ; t1 -= t1 & (-t1)){
            for(int t2 = msk2 ; t2 ; t2 -= t2 & (-t2)){
                sum += g[rv[t1 & (-t1)]][rv[t2 & (-t2)]];
            }
        }
        for(int t2 = msk2 ; t2 ; t2 -= t2 & (-t2)){
            if(g[st][rv[t2 & (-t2)]]){
                sol = min(sol, f(rv[t2 & (-t2)], msk2) + sum - g[st][rv[t2 & (-t2)]]);
            }
        }

    }
    return dp[st][msk] = sol;
}

int main(){
    memset(dp, -1, sizeof(dp));
    for(int i = 0;i<N;i++) rv[(1 << i)] = i;
    memset(dp, -1, sizeof(dp));
    scanf("%d%d", &n, &m);
    for(int i = 0;i<m;i++){
        int x, y;scanf("%d%d", &x, &y);x--;y--;
        scanf("%d", &g[x][y]);
        g[y][x] = g[x][y];
    }
    printf("%d\n", f(0, (1 << n) - 1));
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e3+5;
const int MOD=1e9+7;

int n, a, b, c, d;
int cache[N][N], cache2[N][N];
int fact[N], invfact[N];

int pow(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 modinv(int k)
{
	return pow(k, MOD-2, MOD);
}

void precompute()
{
	fact[0]=fact[1]=1;
	for(int i=2;i<N;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
	invfact[N-1]=modinv(fact[N-1]);
	for(int i=N-2;i>=0;i--)
	{
		invfact[i]=invfact[i+1]*(i+1);
		invfact[i]%=MOD;
	}
}

int nCr(int x, int y)
{
	if(y>x)
		return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=MOD;
	num*=invfact[x-y];
	num%=MOD;
	return num;
}

int num(int r, int take)
{
	int &ans=cache2[r][take];
	if(ans!=-1)
		return ans;
	return modinv(pow(fact[r], take, MOD));
}

int dp2(int n, int r, int take)
{
	int ans=fact[n] * invfact[n-r*take];
	ans%=MOD;
	int den=num(r, take);
	ans*=den;
	ans%=MOD;
	return ans;
}

int dp(int remaining, int freq)
{
	if(remaining==0)
		return 1;
	if(freq==b+1)
		return 0;
	int &ans=cache[remaining][freq];
	if(ans!=-1)
		return ans;
	ans=dp(remaining, freq+1);
	for(int i=c;i<=d;i++)
	{
		int take=i*freq;
		if(take>remaining)
			break;
		int ways=dp2(remaining, freq, i);
		ways*=dp(remaining-take, freq+1);
		ways%=MOD;
		ways*=invfact[i];
		ways%=MOD;
		ans+=ways;
	}
	ans%=MOD;
	return ans;
}

int32_t main()
{
	IOS;
	precompute();
	memset(cache, -1, sizeof(cache));
	memset(cache2, -1, sizeof(cache2));
	cin>>n>>a>>b>>c>>d;
	int ans=dp(n, a);
	cout<<ans;
	cerr<<(double)clock()/CLOCKS_PER_SEC;
	return 0;
}

#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1000000007LL;
vector<ll> f,fi;
ll mpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1){
            res=res*x%MOD;
        }
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
ll ncr(ll n,ll r){
    if(n<r)return 0;
    if(r==0)return 1;
    return f[n]*fi[r]%MOD*fi[n-r]%MOD;
}
int main(){
    int n;cin>>n;
    f.resize(n+10,0);
    fi.resize(n+10,0);
    f[0]=1;
    for(ll i=1;i<=n;i++)f[i]=f[i-1]*i%MOD;
    fi[n]=mpow(f[n],MOD-2LL);
    for(ll i=n-1;i>=0;i--)fi[i]=fi[i+1]*(i+1)%MOD;
    vector<vector<ll>> dp(n+10,vector<ll>(n+10,0));
    int a,b,c,d;cin>>a>>b>>c>>d;
    dp[a-1][0]=1;
    for(int i=a;i<=b;i++){
        for(int j=0;j<=n;j++){
            dp[i][j]+=dp[i-1][j];
            dp[i][j]%=MOD;
            ll s=1;
            for(int k=1;k<c;k++)s=s*ncr(n-j+i*k,i)%MOD;
            for(int k=c;k<=d;k++){
                if(j-i*k<0)break;
                s=s*ncr(n-j+i*k,i)%MOD;
                dp[i][j]+=dp[i-1][j-i*k]*s%MOD*fi[k]%MOD;
                dp[i][j]%=MOD;
            }
        }
    }
    cout<<dp[b][n]<<endl;
}


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

int main() {
  int N,k;
  cin >> N >>k;
  int sum;
  if(k==1){
	sum = N+1;
  }
  else if(k==2||k==3||k==4){
    if (N==1){
      sum = 2;
    }
    else{
    sum = 4 + k*(N-2);
    }
  }
  else if(k==5||k==6||k==7){
    if (N==1){
      sum = 2;
    }
    else if(N==2){
      sum = 4;
    }
    else{
    sum = 8 + k*(N-3);
    }
  }
  else{
    if (N==1){
      sum = 2;
    }
    else if (N==2){
      sum = 4;
    }
    else if (N==3){
      sum = 8;
    }
    else{
    sum = 16 + k*(N-4);
    }
  }
  cout<<sum<<endl;
}

#include <stdio.h>

int main() {
    int n, k, number = 1;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) {
        number = number * 2 < number + k ? number * 2 : number + k;
    }
    printf("%d\n", number);
    return 0;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int a, b; cin >> a >> b;
    if(a > 8 || b > 8){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
}

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1};
const int mod = 1e9+7;
const ll N = 1e5+4;

ll n,m;

void solve(){
	vector<int>d;
	cin>>n>>m;
	for(int i=1;i*i<=m;++i){
		if(m%i==0){
			d.pb(i);
			if(m/i!=i)d.pb(m/i);
		}
	}
	sort(all(d));
	reverse(all(d));
	rep(i,sz(d)){
		if(n*d[i]<=m){
			cout<<d[i];
			return;
		}
	}
}

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


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    ll k; cin >> k;
    ll m = k % 50;
    cout << 50 << '\n';
    vector<ll> a(50, k / 50 + 49 - m);
    for (int i = 0; i < m; i++) a[i] += 51;
    for (int i = 0; i < 50; i++) cout << a[i] << " \n"[i == 49];
    return 0;
}

#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

bool f(std::vector<intmax_t>& a) {
  std::sort(a.rbegin(), a.rend());
  intmax_t n = a.size();
  a[0] -= n;
  for (size_t i = 1; i < a.size(); ++i) ++a[i];
  std::sort(a.begin(), a.end());

  return !std::all_of(a.begin(), a.end(), [=](auto x) { return x < n; });
}

int main() {
  intmax_t k;
  scanf("%zu", &k);

  size_t n = 50;
  std::vector<intmax_t> a(n, n+(n+k-1)/n);
  for (size_t i = 0; i < 50; ++i) f(a);
  if (k % n != 0) {
    size_t m = n - k%n;
    for (size_t i = 0; i < m; ++i) f(a);
  }

  printf("%zu\n", n);
  for (size_t i = 0; i < a.size(); ++i)
    printf("%jd%c", a[i], i+1<a.size()? ' ': '\n');
}


/**
*    author:  souzai32
*    created: 14.08.2020 14:10:05
**/

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

int main() {

    int n,k;
    cin >> n >> k;
    vector<long long> x(n);
    rep(i,n) cin >> x.at(i);
    long long left,right;
    long long ans=1e9;

    rep(i,n-k+1){
        left=x.at(i);
        right=x.at(i+k-1);
        ans=min(ans,min(abs(left)+abs(left-right),abs(right)+abs(left-right)));
        // cout << left << ' ' << right << endl;
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set]
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector<long long> lvi;
typedef vector< vector<int> > vvi;
typedef vector< vector<long long> > lvvi;
typedef pair< int,int > ii;
typedef pair< long long,long long > lii;
typedef vector<pair<int,int>> vii;
typedef vector<pair<long long,long long>> lvii;
typedef vector<vector<pair<int,int>>> vvii;
typedef vector<vector<pair<long long,long long>>> lvvii;
typedef vector<bool> vb;

// #ifdef ONLINE_JUDGE
// #define endl '\n'
// #endif
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#ifdef ONLINE_JUDGE
	#define error(args...) 0
#else
	#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#endif
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr <<"[ "<< *it << " = " << a << " ]"<< endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
const long long mod = 1e9 + 7;
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

long long mos() { return 0LL; }
template<typename T, typename... Args>
T mos(T a, Args... args) { return ((a + mos(args...))%mod + mod)%mod; }

long long mop() { return 1LL; }
template<typename T, typename... Args>
T mop(T a, Args... args) { return (a*mop(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	vi a(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	int k1=k;
	while(k>0)
	{
		// vi b(n);
		vi suffix(n+1,0);
		for (int i = 0; i < n; ++i)
		{
			// for(int j=max(0,i-a[i]);j<=min(n-1,i+a[i]);j++)
			// {
			// 	b[j]++;
			// }
			int low = max(0,i-a[i]),high = 1+min(n-1,i+a[i]);
			suffix[low]++;
			suffix[high]--;
			// error(i,low,high);
		}
		a[0]=suffix[0];
		for(int i=1;i<n;i++)
		{
			suffix[i]+=suffix[i-1];
			a[i]=suffix[i];
		}
		k--;
		bool ok=true;
		for (int i = 0; i < n; ++i)
		{
			// cout<<a[i]<<" ";
			if(a[i]!=n) ok=false;
		}
		// cout<<endl;
		if(ok) break;
	}
	// cout<<"steps: "<<k1-k<<endl;
	for (int i = 0; i < n; ++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<endl;
	return 0;
}

// WA
// 1. overflow
// 2. re-initialize global variables for every test case.
// 3. edge cases like n=1

// Run time error
// 1. division by zero.
// 2. array bounds.

// TLE
// 1. uncomment that #define endl '\n' line


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

map<ll,ll> cnt[2];
ll D;

ll dfs(const vector<ll>& a,ll i,ll sum){
  // if(sum>D*1000||sum<-D*1000)return 0;

  ll n=a.size();
  if(i==n){
    if(sum==D) return 1;
    else return 0;
  }else{
    ll res=0;
    bool done=false;
    repl(c,-9,9+1){
      if(sum+c*a[i]>D){
        res+=dfs(a,i+1,sum+(c-1)*a[i])*cnt[(i!=0?0:1)][c-1];
        res+=dfs(a,i+1,sum+c*a[i])*cnt[(i!=0?0:1)][c];
        done=true;
        break;
      }
    }
    if(!done){
      res+=dfs(a,i+1,sum+9*a[i])*cnt[(i!=0?0:1)][9];
    }
    return res;
  }
}

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

  rep(a,10)rep(b,10){
    cnt[0][b-a]++;
    if(a>0)cnt[1][b-a]++;
  }

  cin>>D;
  ll res=0;
  rep(d,18){
    vector<ll> ds;
    rep(i,d/2+1){
      ll p1=pow(10,i);
      ll p2=pow(10,d-i);

      ll dif=p2-p1;
      ds.push_back(dif);
    }
    ll t=1;
    if(ds.back()==0){
      t*=10; ds.pop_back();
    }
    res+=dfs(ds,0,0)*t;
  }
  cout<<res<<endl;

  return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n,m,v,p;
vll a;
vll sum;

// mid ... 添え字 => a[mid]は採用されるか
// midが採用される
// midがp以内である(n-mid+<=p) => ok
// midがpより後である =>
// midを+1, 0~mid-1を+1する。残り v-(mid+1)
// midがp番目になるには2つ条件が必要
// - v-(mid+1)<=p-1
// - a[mid]+m>=a[n-p (p番目)]
bool isOk(ll mid){
  if(n-mid<=p) return 1;

  ll rem=v-(mid+1)-(p-1); // midを選ぶ上で1人が影響のない分を投票した残り

  if(rem<=0){
    if(a[mid]+m>=a[n-p]) return 1;
  }else{
    ll cnt=(n-(p-1))-(mid+1);
    ll d=(sum[n-(p-1)]-sum[mid+1]);
    ll x=(a[mid]+m)*cnt-d;
    // cout<<mid<<' '<<d<<' '<<x<<' '<<rem<<' '<<cnt<<endl;
    if(x>=rem*m && a[mid]+m>=a[n-p]) return 1;
  }
  return 0;
}

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

  cin>>n>>m>>v>>p;

  a.resize(n);
  rep(i,n) cin>>a[i];
  vsort(a);
  sum.resize(n+1);
  rep(i,n) sum[i+1]=sum[i]+a[i];

  // rep(i,n) cout<<a[i]<<' ';
  // cout<<endl;

  ll ng=-1, ok=n-1;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    if(isOk(mid)) ok=mid;
    else ng=mid;
  }
  ll ans=n-ok;

  cout<<ans<<endl;
}


#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;

vector< pll > v;
ll n;
ll h[5005], p[5005];
ll dp[5005][5005];
const ll inf = 1e16;
int main()
{
        cin >> n;
        v.pb(make_pair(-2LL , -2LL));
        for(ll i=1;i<=n;i++) {
                cin >> h[i] >> p[i];
                v.pb(make_pair(h[i]+p[i], i));
        }
        sort(v.begin(), v.end());
        for(ll i=1;i<=n;i++) dp[0][i] = inf;
        dp[0][0] = 0;
        for(ll i=1;i<=n;i++) {
                ll id = v[i].second;
                for(ll j = 0; j <= n; j++) {
                        dp[i][j] = dp[i-1][j];
                        if(j && dp[i-1][j-1] <= h[id]) dp[i][j] = min(dp[i][j], p[id] + dp[i-1][j-1]);
                }
        }
        for(ll i=n;i>=0;i--){
                if(dp[n][i] != inf) {
                        cout << i << endl; return 0;
                }
        }
        return 0;
}

#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

typedef std::pair<int, int> P;

bool is_vis[1003][1003];
bool is_fin[1003][1003];
bool is_cycle;

void dfs(map<P, vector<P>> &g, P p) {
  int player1 = p.first;
  int player2 = p.second;

  is_vis[player1][player2] = true;

  for (int i = 0; i < (int)g[p].size(); i++) {
    P nxt = g[p][i];
    int nxt_player1 = nxt.first;
    int nxt_player2 = nxt.second;

    if (is_fin[nxt_player1][nxt_player2]) {
      continue;
    }
    if (is_vis[nxt_player1][nxt_player2] && !is_fin[nxt_player1][nxt_player2]) {
      is_cycle = true;
      return;
    }
    dfs(g, nxt);
  }
  is_fin[player1][player2] = true;
}

int dp[1003][1003];
int rec(map<P, vector<P>> &g, P p) {
  int player1 = p.first;
  int player2 = p.second;
  if (dp[player1][player2] != -1) {
    return dp[player1][player2];
  }
  int res = 0;
  for (int i = 0; i < (int)g[p].size(); i++) {
    res = max(res, rec(g, g[p][i]) + 1);
  }
  return dp[player1][player2] = res;
}

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

  int n;
  cin >> n;

  map<P, vector<P>> g;

  vector<vector<int>> A(n, vector<int>(n - 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 1; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 1; j < n - 1; j++) {
      int pre_1 = i + 1, pre_2 = A[i][j - 1];
      if (pre_1 > pre_2) {
        swap(pre_1, pre_2);
      }
      int nxt_1 = i + 1, nxt_2 = A[i][j];
      if (nxt_1 > nxt_2) {
        swap(nxt_1, nxt_2);
      }
      g[make_pair(pre_1, pre_2)].push_back(make_pair(nxt_1, nxt_2));
    }
  }

  // 閉路検出の処理
  // https://qiita.com/drken/items/a803d4fc4a727e02f7ba#4-6-サイクル検出
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i >= j) {
        continue;
      }
      if (g.find(make_pair(i, j)) == g.end()) {
        continue;
      }
      if (is_vis[i][j]) {
        continue;
      }
      is_cycle = false;
      dfs(g, make_pair(i, j));
      if (is_cycle) {
        cout << -1 << "\n";
        return 0;
      }
    }
  }

  for (int i = 0; i < 1003; i++) {
    for (int j = 0; j < 1003; j++) {
      dp[i][j] = -1;
    }
  }
  // 最長経路を求める
  // EDPC (https://atcoder.jp/contests/dp/tasks/dp_g) で見た
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i >= j) {
        continue;
      }
      ans = max(ans, rec(g, make_pair(i, j)) + 1);
    }
  }
  cout << ans << "\n";

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

int main(){
  vector<int> a(3);
  rep(i,3) cin >> a[i];
  int k; cin >> k;
  sort(a.begin(), a.end());
  for(int i = 0; i < k; i++){
    a[2] *= 2;
  }
  int ans = 0;
  rep(i,3) ans += a[i];
  cout << ans << endl;
  return 0;
}

#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

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

	vector<int> x = {a, b, c};
	int ans = 0;
	for(int i = 0; i < k; ++i) {
		sort(x.begin(), x.end());
		x[2] *= 2;
	}

	cout << accumulate(x.begin(), x.end(), 0) << endl;

	return 0;
}


#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
using namespace std;
bool check(string x, string y) {
  int a = x.size()-1;
  return x[a] == y[0];
}

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if(check(a, b) && check(b, c)) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s;
int N = 3;
vector<int> v(N);
int a, b;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int c, d, x, y;

  cin >> a >> b >> c >> d;
  x = a + b;
  y = c + d;
  if (x < y)
    pr("Right");
  else if (x > y)
    pr("Left");
  else
    pr("Balanced");
  return 0;
}


/******************************************
* AUTHOR : GURUTEJA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

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

}

  int main() {
    debug();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,s1;
    cin>>s;
    int x=1e9;
    for (int i = 0; i<s.length(); ++i)
    {
    	if(i<s.length()-2){
    		s1+=s[i],s1+=s[i+1],s1+=s[i+2];
    		x=min(x,abs(753-stoi(s1)));
    	}
    	s1.clear();
    }
    cout<<x<<endl;
    return 0;
  }

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x;
string s;

ll a[600],c[505];
vpll b;
vll res;

// < ----------- func eh ---------------- ? //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>s;
	ll mini = INF;
	for(ll i=0;i<s.length()-2;i++) {
		mini = min(mini , abs(stoll(s.substr(i,3)) - 753));
	}
	cout<<mini;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

class BIT{
public:
  int size;
  int* bit;

  BIT(int _size = 0){
    size = _size;
    bit = new int[size];
    for(int i = 0; i < size; i++) bit[i] = 0;
  }

  ~BIT(){delete[] bit;}

  /*
    En: returns sum of [from bit[0] to bit[i]].
    Ja: bit[0]からbit[i]までの合計をかえす。
   */
  int sum(int i){
    int s = 0;
    while(i > 0){
      s += bit[i];
      i -= i&-i;
    }
    return s;
  }

  /*
    En: add x at bit[i].
    Ja: bit[i]にxを加える。
   */
  void add(int i, int x){
    while(i<size){
      bit[i] += x;
      i += i&-i;
    }
  }
};

vector<int> make(const vector<int> v){
  vector<int> tmp = v;
  sort(tmp.begin(), tmp.end());

  int cnt = 1;
  map<int,int> M;
  for(int i = 0; i < (int)tmp.size(); i++){
    if(M.count(tmp[i])) continue;
    M[tmp[i]] = cnt++;
  }

  vector<int> vec(v.size());
  for(int i = 0; i < (int)v.size(); i++) vec[i] = M[v[i]];
  return vec;
}

int main(){

  int n;
  cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  v = make(v);
  BIT bit(n+1);
  long long ans = 0;
  for(int i = 0; i < n; i++){
    ans += i - bit.sum(v[i]);
    bit.add(v[i],1);
  }
  cout << ans << endl;
  return 0;
}

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

ll /*A[2000000],*/ cnt = 0;
int A[210000];
int L[110001];
int R[110001];

int merge(int l, int m, int r){
    int n1 = m - l, n2 = r - m, i, j;
    //ll L[n1 + 1], R[n2 + 1];
    for(i = 0;i < n1;i++)L[i] = A[i + l];
    for(i = 0;i < n2;i++)R[i] = A[i + m];
    i = j = 0;
    for(int k = 0;k < r - l;k++){
        if(j == n2 || (i < n1 && L[i] <= R[j]))A[k + l] = L[i++];
        else A[k + l] = R[j++], cnt += n1 - i;
    }
}

int mergeSort(int l, int r){
    if(l + 1 < r){
        int m = (l + r) / 2;
        mergeSort(l, m);
        mergeSort(m, r);
        merge(l, m, r);
    }
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0;i < n;i++)scanf("%d", &A[i]);
	mergeSort(0, n);
	printf("%lld\n", cnt);

    return 0;
}


#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N, M;

ll count_max(vector<queue<ll>>& A, vector<bool>& already)
{
  vector<ll> cnt(M, 0);
  for (ll i = 0; i < N; ++i) {
    while (true) {
      if (already.at(A.at(i).front())) {
        A.at(i).pop();
      }
      else {
        cnt.at(A.at(i).front()) += 1;
        break;
      }
    }
  }
  ll res = 0, index;
  for (ll i = 0; i < M; ++i) {
    if (res < cnt.at(i)) {
      index = i;
      res = cnt.at(i);
    }
  }
  already.at(index) = true;
  return res;
}

int main()
{
  cin >> N >> M;
  ll ans = INF;
  vector<bool> already(M, false);
  vector<queue<ll>> A(N);
  for (ll i = 0; i < N; ++i) {
    for (ll j = 0; j < M; ++j) {
      ll a;
      cin >> a;
      a -= 1;
      A.at(i).push(a);
    }
  }
  for (ll i = 0; i < M; ++i) {
    ans = min(ans, count_max(A, already));
  }
  cout << ans << endl;
}

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

int main() {
int l,m,n;
cin >> l >> m >> n;
vector<int> a(l);
vector<int> b(m);
rep(i,l) cin >> a.at(i);
rep(i,m) cin >> b.at(i);
vector<vector<int>> x(n,vector<int>(3));

rep(i,n)rep(j,3) cin >> x.at(i).at(j);
int ans = 100000000000000000;
int t;
rep(i,n){
  t = a.at(x.at(i).at(0)-1)+b.at(x.at(i).at(1)-1)-x.at(i).at(2);
  ans = min(ans,t);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
  if(a.at(0)+b.at(0) < ans) ans = a.at(0)+b.at(0);
cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
bool chmin(ll& a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
struct Gragh {
    ll N;
    vector<vl> G;
    vl visited;

    Gragh(ll n) {
        N = n;
        G.resize(N);
        resetv();
    }

    void add(ll a, ll b) { G[a].push_back(b); }

    void resetv(void) { visited = vl(N, 0); }

    //重さ無し
    void dfs(ll x) {
        visited[x] = 1;
        for (ll i : G[x]) {
            if (visited[i] == 0) {
                dfs(i);
            }
        }
    }
};
int main() {
    cin >> n >> m;
    Gragh G(2 * n);
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        G.add(a * 2, b * 2 + 1);
        G.add(b * 2, a * 2 + 1);
        G.add(a * 2+1, b * 2);
        G.add(b * 2+1, a * 2);
    }

    G.dfs(0);
    vl dp(2, 0);
    rep(i, n * 2) {
        if (G.visited[i] == 1)dp[i % 2]++;
    }

    x=dp[0];
    y=dp[1];
    k=x+y-n;
    ans=k*(n-k)+k*(k-1)/2+(x-k)*(y-k)-m;

    cout << ans << endl;
}

#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

const int  MAX_V = 100000;
vector<int> es[MAX_V];
vector<int> col(MAX_V, -1);
bool loop = false;

void dfs(int now, int c){
    col[now] = c;
    for(auto &e: es[now]){
        if(col[e] == -1) dfs(e, c^1);
        if(col[e] == c) loop = true;
    }
}

int main(){
    ll N, M;
    cin >> N >> M;
    rep(i, M){
        int u, v; cin >> u >> v; u--, v--;
        es[u].pb(v), es[v].pb(u);
    }
    dfs(0, 0);
    if(loop) cout << N*(N-1)/2-M << endl;
    else{
        ll a = 0, b = 0;
        rep(i, N) (col[i]? a : b)++;
        cout << a*b-M << endl;
    }
}


#include "bits/stdc++.h"

#define int long long

using namespace std;

const int mod = 1e9 + 7;

int32_t main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    vector<int> score(1 << n);
    for (int mask = 0; mask < (1 << n); mask++) {
        for (int i = 0; i < n; i++) {
            if ((mask & (1 << i)) == 0) {
                continue;
            }
            for (int j = 0; j < i; j++) {
                if ((mask & (1 << j)) == 0) {
                    continue;
                }
                score[mask] += a[i][j];
            }
        }
    }
    vector<int> dp(1 << n, 0);
    for (int mask = 1; mask < (1 << n); mask++) {
        for (int submask = mask; submask > 0; submask--, submask &= mask) {
            dp[mask] = max(dp[mask], score[submask] + dp[mask ^ submask]);
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}

#include<string>
#include<iostream>
#include<cctype>
#include<cmath>
#include<cstdio>

using namespace std;

int main(void){
	int a;
	cin >> a;
	int b[10000];
	long long min=pow(10,6);
	long long  max=-pow(10,6);
	int i;

	for(i=0;i<a;i++){
		cin >> b[i];
		}
	for(i=0;i<a;i++){
		if(min>b[i]) min=b[i];
		if(max<b[i]) max=b[i];
		}

	long long sum=0;
	for(i=0;i<a;i++){
		sum+=b[i];
		}

	cout << min << " "<< max << " "<< sum <<endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

int main(){
    int n, K;
    cin >> n >> K;
    int v[n];
    rep(i, n) cin >> v[i];
    int mx = min(n, K);
    int ans = 0;
    for (int i = 0; i <= mx; i++){
        for (int j = 0; j <= i; j++){
            vec v_s;
            for (int k = 0; k < j; k++){
                v_s.push_back(v[k]);
            }
            for (int k = n - 1; k > (n - 1) - (i - j); k--){
                v_s.push_back(v[k]);
            }
            sort(v_s.begin(), v_s.end());
            // for (int k = 0; k < v_s.size(); k++){
            //     cout << v_s[k] << " ";
            // }cout << endl;

            int sm = 0;
            rep(k, v_s.size()){
                if(k < K - i && v_s[k] < 0) continue;
                sm += v_s[k];
            }
            // cout << sm << endl;
            ans = max(sm, ans);
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define pr(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N= 51;
const int M= 101;

int dp[N][N][M];

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

        memset(dp, -1, sizeof(dp));
        vector<int> v(n);
        for (auto& i: v) cin >> i;

        function<int(int, int, int)> calc= [&](int i, int j, int cnt)->int {
                if (cnt< 0) return -1e18;
                if (cnt== 0) return 0;
                if (i> j) return 0;

                int &ret= dp[i][j][cnt];
                if (ret!= -1) return ret;
                ret= 0;

                ret= max(ret, calc(i+ 1, j, cnt- 1)+ v[i]);
                ret= max(ret, calc(i+ 1, j, cnt- 2));
                ret= max(ret, calc(i, j- 1, cnt- 1)+ v[j]);
                ret= max(ret, calc(i, j- 1, cnt- 2));
                return ret;
        };

        cout << calc(0, n- 1, k)<< "\n";
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int T= 1;
        //cin >> T;
        while ( T-- ) {
                solve();
        }
return 0;
}


#include <stdio.h>

int main(){
  int dice[7];
  char com[1000];
  int i,j,k;
  int n,e,w,s,top;

  for(i=1;i<=6;i++) scanf("%d",&dice[i]);
  scanf("%s",com);
  top=1;
  n=5;
  s=2;
  w=4;
  e=3;

  for(i=0;com[i]!='\0';i++){
    if(com[i]=='N'){
      n=top;
      top=s;
      s=7-n;
    }else if(com[i]=='S'){
      s=top;
      top=n;
      n=7-s;
    } else if(com[i]=='W'){
      w=top;
      top=e;
      e=7-w;
    }else if(com[i]=='E'){
      e=top;
      top=w;
      w=7-e;
    }
  }
  printf("%d\n",dice[top]);

  return 0;
}

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

int main(){
	string s; cin >> s;
  	map<char,vector<int>> dist;
  	for(int i=0; i< s.size(); i++){
    	dist[s.at(i)].push_back(i);

    }
  	/*ここからアンバランス探しmapにはアルファベットと出現箇所が紐づけ
    各アルファベットについて、隣り合ってたらok
  	*/
  	bool seikai = false;
  	for(auto& a: dist ){
    	if(a.second.size()>1){
        	for(int i=0; i< a.second.size() - 1; i++ ){
            	if((a.second[i+1] - a.second[i] ==1) ||
                   (a.second[i+1] - a.second[i]==2)){
                	cout << a.second[i] +1<< " " << a.second[i+1] +1;
                  	seikai = true;
                  	goto Finish;

                }
            }
        }
    }
  	Finish:
  	if(!seikai){cout << -1 << " " << -1;}
  	cout << endl;

}


/*
	bfs 找环
*/
#include <bits/stdc++.h>
#define N 1005
#define M 2005

using namespace std;

int n, m;
int dep[N];
int head[N], nex[M], to[M], e;
int stk[N], top;
bool instack[N], vis[N], G[N][N];
vector<int> res;

inline int Rd() {
	int x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x;
}
inline void Ae(int u, int v) {
	nex[++e] = head[u], head[u] = e;
	to[e] = v;
}

void calc(int u, int v) {
	do {
		res.push_back(stk[top]);
	} while(stk[top--] != v);
	int ans = res.size();
	printf("%d\n", ans);
	for(int i = 0; i < ans; ++i) printf("%d\n", res[i]);
	exit(0);
}
void dfs(int u) {
	stk[++top] = u;
	instack[u] = vis[u] = true;
	for(int i = head[u]; i; i = nex[i]) {
		int v = to[i];
		if(vis[v]) {
			if(instack[v]) calc(u, v);
		} else {
			dfs(v);
		}
	}
	instack[u] = false, --top;
	return;
}

int main() {
	n = Rd(), m = Rd();
	for(int i = 1; i <= m; ++i) {
		int u = Rd(), v = Rd();
		G[u][v] = true;
		Ae(u, v);
	}

	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= n; ++j) {
			if(G[i][j] && G[j][i]) {
				puts("2");
				printf("%d\n%d\n", i, j);
				return 0;
			}
		}
	}
	for(int i = 1; i <= n; ++i)
		if(!vis[i])
			dfs(i);
	puts("-1");
	return 0;
}

#include <bits/stdc++.h>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

std::vector<std::vector<int>> StronglyConnectedComponents(
    const std::vector<std::vector<int>>& graph) {
  int n = graph.size();
  std::vector<int> nodes;
  std::vector<bool> visited(n);
  std::function<void(int)> dfs = [&](int u) {
    visited[u] = true;
    for (int v : graph[u]) {
      if (!visited[v]) {
        dfs(v);
      }
    }
    nodes.push_back(u);
  };
  for (int u = 0; u < n; ++u) {
    if (!visited[u]) dfs(u);
  }
  std::vector<std::vector<int>> rgraph(n);
  for (int u = 0; u < n; ++u) {
    for (int v : graph[u]) {
      rgraph[v].push_back(u);
    }
  }
  std::vector<bool> rvisited(n);
  std::vector<std::vector<int>> sccs;
  std::function<void(std::vector<int>&, int)> rdfs = [&](std::vector<int>& scc,
                                                         int u) {
    rvisited[u] = true;
    scc.push_back(u);
    for (int v : rgraph[u]) {
      if (!rvisited[v]) {
        rdfs(scc, v);
      }
    }
  };
  for (int i = n - 1; i >= 0; --i) {
    int u = nodes[i];
    if (!rvisited[u]) {
      std::vector<int> scc;
      rdfs(scc, u);
      sccs.push_back(scc);
    }
  }
  return sccs;
}

int main() {
  in(int, n, m);
  vector<vector<int>> graph(n);
  rep(i, m) {
    in(int, a, b);
    graph[a - 1].push_back(b - 1);
  }
  vector<vector<int>> sccs = StronglyConnectedComponents(graph);
  for (const vector<int>& scc : sccs) {
    if (scc.size() == 1) continue;
    set<int> scc_nodes(all(scc));
    int node = scc[0];
    map<int, int> next;
    map<int, int> prev;
    for (int n : scc_nodes) dbg(n);
    while (true) {
      for (int child : graph[node]) {
        if (scc_nodes.count(child) == 0) continue;
        next[node] = child;
        prev[child] = node;
        if (next.count(child) != 0) goto out;
        node = child;
        break;
      }
    }
 out:
    node = scc[0];
    if (prev.count(node) == 0) {
      while (true) {
        int child = next[node];
        next.erase(node);
        if (prev[child] != node) break;
        prev.erase(child);
        node = child;
      }
    }
    rep(u, n) for (int v : graph[u]) {
      if (next.count(u) > 0 && next.count(v) > 0) {
        int c = next[u];
        while (c != v) {
          int nc = next[c];
          next.erase(c);
          prev.erase(c);
          c = nc;
        }
        next[u] = v;
        prev[v] = u;
      }
    }
    vector<int> v;
    int u = next.begin()->first;
    do {
      v.push_back(u);
      u = next[u];
    } while (u != next.begin()->first);
    out(v.size());
    for (int u : v) out(u + 1);
    return 0;
  }
  out(-1);
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    // dp[i][j]...i列目が終わった時にj行目にいるようなあみだくじの作り方
    vector<vector<ll>> dp(h+10, vector<ll>(w+10));

    vector<ll> com(w+10);
    com[0] = 1ll;
    com[1] = 2ll;
    rp(i, 2, w){
        com[i] = com[i-1] + com[i-2];
        com[i] %= MOD;
    }

    dp[0][1] = 1ll;
    rp(i, 0, h) {
        rp(j, 1, w+1) {
            if(j < w) {
                int right = max(0, w-j-2);
                int left = max(0, j-2);
                dp[i+1][j+1] += dp[i][j] * com[right] * com[left] % MOD; dp[i+1][j+1] %= MOD;
            }
            if(j > 1) {
                int right = max(0, w-j-1);
                int left = max(0, j-3);
                dp[i+1][j-1] += dp[i][j] * com[right] * com[left] % MOD; dp[i+1][j-1] %= MOD;
            }
            int right = max(0, w-j-1);
            int left = max(0, j-2);
            dp[i+1][j] += dp[i][j] * com[right] * com[left] % MOD; dp[i+1][j] %= MOD;
        }
    }
    // rp(i, 0, h) {
    //     rp(j, 1, w+1) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[h][k] << endl;
    return 0;

}

#pragma GCC optimize(3 , "Ofast" , "inline")

#include <bits/stdc++.h>

#define rep(i , a , b) for(register int i=(a);i<=(b);i++)
#define per(i , a , b) for(register int i=(a);i>=(b);i--)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int , int> pi;

template<class T>
inline void read (T &x) {
    x = 0;
    int sign = 1;
    char c = getchar ();
    while (c < '0' || c > '9') {
        if ( c == '-' ) sign = - 1;
        c = getchar ();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar ();
    }
    x = x * sign;
}

const int maxn = 2e5 + 10;
const int inf = int (1e9);
const ll INF = ll (1e18);
const double PI = acos (- 1);
const int mod = 1e9+7;
const double eps = 1e-8;

ll dp[111][10];

int main () {
    int h,w,m;
    read (h);read (w);read (m);
    if(w==1) {
        puts ("1");
        return 0;
    }
    dp[0][0]=1;
    rep (i,1,h) {
        rep (j,0,(1<<w-1)-1) {
            bool ok=1;
            rep (k,0,w-3) {
                if((j&(1<<k))&&(j&(1<<k+1))) {
                    ok=0;
                    break;
                }
            }
            if(!ok) continue;
            rep (k,0,w-1) {
                if(k>=1&&(j&(1<<(k-1)))) {
                    dp[i][k]=(dp[i][k]+dp[i-1][k-1])%mod;
                }
                else if(k<w-1&&(j&(1<<k))) {
                    dp[i][k]=(dp[i][k]+dp[i-1][k+1])%mod;
                }
                else dp[i][k]=(dp[i][k]+dp[i-1][k])%mod;
            }
        }
    }
    cout<<dp[h][m-1]<<endl;
    return 0;
}


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

const ll INF = 1LL << 60;

vector<ll> calc_divisor(ll n) {
    vector<ll> res;
    for (ll i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            ll j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

ll N, M;

int main() {
    cin >> N >> M;
    vector<ll> v = calc_divisor(M);

    reverse(v.begin(), v.end());
    ll ans = 0;
    rep(i, v.size()) {
        // cout << v[i] << endl;
        if (M % v[i] == 0) {
            ll tmp = M / v[i];
            if (tmp >= N) {
                ans = v[i];
                break;
            }
        }
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N, M; cin >> N >> M;
  int MAX = M/N;
  for (int i=MAX;i>=1;i--){
    if ((M - i*N)%i==0) {
      cout << i << endl;
      return 0;
    }
  }

  // cout << fixed << setprecision(10);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
struct Node
{
    int first , second;
    int dir;
}node[maxn];
// x + y
bool cmp1(const Node & a , const Node & b)
{
    if (a.first + a.second != b.first + b.second)
        return a.first + a.second < b.first + b.second;
    return a.first < b.first;
}
// x - y
bool cmp2(const Node & a , const Node & b)
{
    if (a.first - a.second != b.first - b.second)
        return a.first - a.second < b.first - b.second;
    return a.first < b.first;
}
// x
bool cmp3(const Node & a , const Node & b)
{
    if (a.first!= b.first)
        return a.first < b.first;
    return a.second < b.second;
}
// y
bool cmp4(const Node & a , const Node & b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int check (char g)
{
    if (g == 'U') return 0;
    if (g == 'D') return 1;
    if (g == 'R') return 2;
    return 3;
}
int main()
{
    ios::sync_with_stdio(false);
    int n ; cin >> n;
    for (int i = 1 ; i <= n ; i++){
        cin >> node[i].first >> node[i].second;
        char g;
        cin >> g;
        node[i].dir = check(g);
    }
    int ans = 1e9;
    node[0].first = node[0].second = -1;
    int pos , pos2;

    sort(node + 1 , node + 1 + n , cmp1);
    for (int i = 1 ; i <= n ; i++){
        if (node[i].first + node[i].second != node[i - 1].first + node[i - 1].second){
            pos = pos2 = -1;
        }

        if (node[i].dir == check('U')){
            if (pos != -1)
                ans = min (ans , abs(node[i].first - node[pos].first) * 10);
        }
        if (node[i].dir == check('R')){
            pos = i;
        }

        if (node[i].dir == check('L')){
            if (pos2 != -1)
                ans = min (ans , abs(node[i].first - node[pos2].first) * 10);
        }
        if (node[i].dir == check('D')){
            pos2 = i;
        }
    }

    sort(node + 1 , node + 1 + n , cmp2);
    for (int i = 1 ; i <= n ; i++){
        if (node[i].first - node[i].second != node[i - 1].first - node[i - 1].second){
            pos = pos2 = -1;
        }
        if (node[i].dir == check('L')){
            if (pos != -1)
                ans = min (ans , abs(node[i].first - node[pos].first) * 10);
        }
        if (node[i].dir == check('U')){
            pos = i;
        }

        if (node[i].dir == check('D')){
            if (pos2 != -1)
                ans = min (ans , abs(node[i].first - node[pos2].first) * 10);
        }
        if (node[i].dir == check('R')){
            pos2 = i;
        }

    }

    sort(node + 1 , node + 1 + n , cmp3);
    for (int i = 1 ; i <= n ; i++){
        if (node[i].first != node[i - 1].first){
            pos = -1;
        }
        if (node[i].dir == check('D')){
            if (pos != -1)
                ans = min (ans , abs(node[i].second - node[pos].second) * 5);
        }
        else if (node[i].dir == check('U')){
            pos = i;
        }
    }

    sort(node + 1 , node + 1 + n , cmp4);
    for (int i = 1 ; i <= n ; i++){
        if (node[i].second != node[i - 1].second){
            pos = -1;
        }
        if (node[i].dir == check('L')){
            if (pos != -1)
                ans = min (ans , abs(node[i].first - node[pos].first) * 5);
        }
        else if (node[i].dir == check('R')){
            pos = i;
        }
    }
    if (ans == 1e9) cout << "SAFE" << endl;
    else cout << ans << endl;
    return 0;
}

#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define IL inline
#define reg register
#define LL long long
#define N 200010
#define INF 0x3f3f3f3f
using namespace std;

int n,i,j;
int ans=INF;
set <int> S[N*4];

struct Data{
	int x,y;
	char c;
}a[N];

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();
	for (i=1;i<=n;i++){
		a[i].x=read();	a[i].y=read();	a[i].c=getchar();
	}
	if (n==1){
		puts("SAFE");
		return 0;
	}

	for (i=1;i<=n;i++)
		if (a[i].c=='U')	S[a[i].x+a[i].y].insert(a[i].x);

	for (i=1;i<=n;i++){
		if (a[i].c=='R'){
			if (!S[a[i].x+a[i].y].size())	continue;
			j=*(--S[a[i].x+a[i].y].end());
			if (j<a[i].x)	continue;
			j=*S[a[i].x+a[i].y].upper_bound(a[i].x);
			ans=Min(ans,j-a[i].x);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//U--R

	for (i=1;i<=n;i++)
		if (a[i].c=='D')	S[a[i].x+a[i].y].insert(a[i].x);

	for (i=1;i<=n;i++){
		if (a[i].c=='L'){
			if (!S[a[i].x+a[i].y].size())	continue;
			j=*S[a[i].x+a[i].y].begin();
			if (j>a[i].x)	continue;
			j=*(--S[a[i].x+a[i].y].upper_bound(a[i].x));
			ans=Min(ans,a[i].x-j);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//D--L

	for (i=1;i<=n;i++)
		if (a[i].c=='R')	S[a[i].y-a[i].x+N].insert(a[i].x);

	for (i=1;i<=n;i++){
		if (a[i].c=='D'){
			if (!S[a[i].y-a[i].x+N].size())	continue;
			j=*S[a[i].y-a[i].x+N].begin();
			if (j>a[i].x)	continue;
			j=*(--S[a[i].y-a[i].x+N].upper_bound(a[i].x));
			ans=Min(ans,a[i].x-j);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//D--R

	for (i=1;i<=n;i++)
		if (a[i].c=='L')	S[a[i].y-a[i].x+N].insert(a[i].x);

	for (i=1;i<=n;i++){
		if (a[i].c=='U'){
			if (!S[a[i].y-a[i].x+N].size())	continue;
			j=*(--S[a[i].y-a[i].x+N].end());
			if (j<a[i].x)	continue;
			j=*S[a[i].y-a[i].x+N].upper_bound(a[i].x);
			ans=Min(ans,j-a[i].x);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//D--R
	if (ans!=INF)	ans*=2;

	for (i=1;i<=n;i++)
		if (a[i].c=='R')	S[a[i].y].insert(a[i].x);

	for (i=1;i<=n;i++){
		if (a[i].c=='L'){
			if (!S[a[i].y].size())	continue;
			j=*S[a[i].y].begin();
			if (j>a[i].x)	continue;
			j=*(--S[a[i].y].upper_bound(a[i].x));
			ans=Min(ans,a[i].x-j);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//L--R

	for (i=1;i<=n;i++)
		if (a[i].c=='U')	S[a[i].x].insert(a[i].y);

	for (i=1;i<=n;i++){
		if (a[i].c=='D'){
			if (!S[a[i].x].size())	continue;
			j=*S[a[i].x].begin();
			if (j>a[i].y)	continue;
			j=*(--S[a[i].x].upper_bound(a[i].y));
			ans=Min(ans,a[i].y-j);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//U--D

	if (ans==INF)	puts("SAFE");
	else cout<<ans*5<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define pb push_back
typedef vector<int> vi;
#define mod 1000000007
#define nos ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int dp[3005][3005];
int n,t;
int happy(vector<pair<int,int>>&a,int pidx,int time)
{
    if(time>=t||pidx>=n)
    return 0;
    if(dp[pidx][time]!=-1)
    return dp[pidx][time];
    return dp[pidx][time]=max(a[pidx].s+happy(a,pidx+1,time+a[pidx].f),happy(a,pidx+1,time));
}
int32_t main() {
    nos;
    cin>>n>>t;
    vector<pair<int,int>>a(n);
    for(int i=0;i<n;i++)
    cin>>a[i].f>>a[i].s;
    sort(a.begin(),a.end());
    memset(dp,-1,sizeof(dp));
    cout<<max(a[0].s+happy(a,1,a[0].f),happy(a,1,0));
    return 0;
}

#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int dp[3005][3005];

int main(){
  int n, t;
  cin >> n >> t;
  vector<int> a(n);
  vector<int> b(n);
  vector<P> ab(n);
  rep(i, n){
    cin >> a[i] >> b[i];
    ab[i]=P(a[i], b[i]);
  }
  sort(ab.begin(), ab.end());
  rep(i, n){
    a[i]=ab[i].first;
    b[i]=ab[i].second;
  }
  rep(i, n){
    rep(j, t){
      if(j-a[i]<0){
        dp[i+1][j]=dp[i][j];
      } else {
        dp[i+1][j]=max(dp[i][j], dp[i][j-a[i]]+b[i]);
      }
    }
  }
  int ans=0;
  rep(i, n){
    ans=max(dp[i][t-1]+b[i], ans);
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)

int main() {
	int A, B; cin >> A >> B;
	if (B == 1) {
		cout << "0" << endl; return 0;
	}
	if (B - A <= 0) {
		cout << "1" << endl; return 0;
	}
	B -= A;
	int cnt = 1;
	while (1) {
		cnt++;
		if (B - (A - 1) <= 0) {
			cout << cnt << endl;
			return 0;
		} else {
			B -= A - 1;
		}
	}
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;

int main(void) {
  int a, b; cin >> a >> b;
  int c = 1;
  int ans = 0;
  while(1) {
    if (c >= b) break;
    c += a - 1;
    ++ans;
  }
  pl(ans)
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define INF 0x3FFFFFFF
#define MN 2005
using namespace std;
int a[MN][MN],len[MN][MN],q[MN];
int n,m,p,ans,tp;
char c[MN];

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

int main()
{
	register int i,j;
	n=read(); m=read();
	for (i=1;i<=n;++i)
	{
		scanf("%s",c+1);
		for (j=1;j<=m;++j) a[i][j]=(c[j]=='#'?1:0);
	}
	for (i=1;i<n;++i)
		for (j=1;j<=m;++j) a[i][j]=a[i][j]^a[i+1][j];
	for (i=1;i<n;++i)
		for (j=1;j<m;++j) a[i][j]=a[i][j]^a[i][j+1];
	for (i=1;i<n;++i)
		for (j=1;j<m;++j)
			if (a[i][j]) len[i][j]=0;
			else len[i][j]=len[i-1][j]+1;
//	for (i=1;i<n;++i)
//		for (j=1;j<m;++j)
	for (i=1;i<n;++i)
	{
		for (j=1;j<m;++j)
		{
			for (;tp&&len[i][j]<=len[i][q[tp]];--tp) ans=max(ans,(j-1-q[tp-1]+1)*(len[i][q[tp]]+1));
			q[++tp]=j;
		}
		for (;tp;--tp) ans=max(ans,(m-1-q[tp-1]+1)*(len[i][q[tp]]+1));
	}
	printf("%d",max(ans,n));
}

#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

const int bound = 1000*1000+10;
bool besucht[bound];

void init(){
	for( int i = 0; i < bound; ++i ) besucht[i] = false;
}

int no(){
	cout << 0 << endl;
	return 0;
}

int main(){
	int n, m; cin >> n >> m;
	vector<int> a(n);
	vector<int> b(m);
	for( auto &k : a ){
		cin >> k;
		if( besucht[k] ) return no();
		besucht[k] = true;
	}
	init();
	for( auto &k : b ){
		cin >> k;
		if( besucht[k] ) return no();
		besucht[k] = true;
	}
	sort( a.begin(), a.end() );
	sort( b.begin(), b.end() );
	ll ans = 1;
	for( int k = 1; k <= n*m; ++k ){
		bool ares = binary_search( a.begin(), a.end(), k );
		bool bres = binary_search( b.begin(), b.end(), k );
		ll comb = 1;
		if( !bres ) comb *= (b.end() - lower_bound( b.begin(), b.end(), k ));
		if( !ares ) comb *= (a.end() - lower_bound( a.begin(), a.end(), k ));
		if( !ares && !bres ) comb -= n*m-k;
		ans *= comb;
		ans %= mod;
	}
	cout << ans << endl;
}


#include<stdio.h>

int main() {
	int row, col, n;
	scanf("%d %d %d", &row, &col, &n);

	int bucket;
	if (row >= col){
		bucket = row;
	} else	{
		bucket = col;
	}

	int i = 0, j;
	int count = 0;

	while (i < n){
		count++;
		i += bucket;
	}

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

	return 0;
}

// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vi a(10), b(10);
  rep(i, 10) cin >> a[i];
  rep(i, 10) cin >> b[i];
  sort(rall(a)), sort(rall(b));
  cout << a[0] + a[1] + a[2] << ' ' << b[0] + b[1] + b[2] << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define debug(a,b,c) cout << a << " " << b << " " << c << endl;
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define inl(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower);
#define endl "\n";
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
    int n;
    cin >> n;
    vi a; in(a,n);
    ll res = 0;
    for(int i=1;i<n;i++){
        if(a[i]<a[i-1]){
            res += (a[i-1]-a[i]);
            a[i] = a[i-1];
        }
    }
    cout << res << endl;

}

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

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

	vector<bool> seen(1'000'000'000);
	bool ans = true;
	for (int i = 0; i < n; ++i)
	{
		int a;
		cin >> a;
		if (seen[a])
			ans = false;
		seen[a] = true;
	}
	cout << (ans ? "YES" : "NO") << endl;
}


#define _USE_MATH_DEFINES
#define INF 100000000
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;

int path[101][101];

int dijkstra(int s,int g,int n){
	int d[101];
	bool used[101];
	memset(d,0x3f,sizeof(d));
	memset(used,0,sizeof(used));
	d[s] = 0;

	while(1){
		int v=-1;
		for(int u=1;u<=n;u++){
			if(!used[u] && (v==-1 || d[u] < d[v])) v=u;
		}

		if(v==-1) break;

		used[v] = true;

		for(int u=1;u<=n;u++){
			d[u] = min(d[u],d[v] + path[v][u]);
		}
	}

	return d[g];
}

int main(){
	int n,k;

	while(~scanf("%d %d",&n,&k)){
		if(n==k && k==0) break;
		memset(path,0x3f,sizeof(path));
		for(int i=0;i<k;i++){
			int ch;
			scanf("%d",&ch);
			if(ch){
				int a,b,val;
				scanf("%d %d %d",&a,&b,&val);
				path[a][b] = path[b][a] = min(val,path[a][b]);
			}
			else{
				int a,b,res;
				scanf("%d %d",&a,&b);
				res = dijkstra(a,b,n);
				printf("%d\n",res > INF ? -1 : res);

			}
		}
	}
}

#include <bits//stdc++.h>
using namespace std;
int main(void){

    while(1){
        long long i,j,a,b,c,k,l;
        cin>>a>>b;
        if(a==0&&b==0)
        break;
        long long island[a][a];
        for(i=0;i<a;i++){
            for(j=0;j<a;j++){
                if(i==j)
                    island[i][j]=0;

                else
                    island[i][j]=LLONG_MAX/2;

            }
        }
        int frag=0;
        for(l=0;l<b;l++){
            cin>>c;
            if(c){
                long long d,e,f;
                cin>>d>>e>>f;
                if(island[d-1][e-1]>f){
                    island[d-1][e-1]=f;
                    island[e-1][d-1]=f;
                    frag=1;
                }
            }
            else{

                if(frag){
                    frag=0;
                    for(k=0;k<a;k++){
                        for(j=0;j<a;j++){
                            for(i=0;i<a;i++)
                            island[i][j]=min(island[i][j],island[i][k]+island[k][j]);
                        }
                    }
                }
                long long d,e;
                cin>>d>>e;
                long long ans=island[d-1][e-1];
                if(ans<LLONG_MAX/2)
                cout<<ans<<endl;
                else
                cout<<"-1"<<endl;
            }
        }
    }
    return 0;

}


#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

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

  vector<ll> a(N);
  for(ll i=0;i<N;i++) cin >> a[i];

  vector<ll> si(N);
  ll sum=0;
  for(ll i=0;i<N;i++){
    sum+=a[i];
    si[i]=sum;
  }

  ll p,q,r,s;
  ll n,m;
  ll ans=sum;

  for(ll i=1;i<N-2;i++){
    n=0;
    m=i;
    while(n+1<m){
      if(si[(n+m)/2]*2<si[i]){
	n=(n+m)/2;
      }else{
	m=(n+m)/2;
      }
    }
    if(abs(2*si[m]-si[i])<abs(2*si[n]-si[i])) n=m;
    p=si[n];q=si[i]-si[n];

    n=i+1;
    m=N-2;
    while(n+1<m){
      if((si[(n+m)/2]-si[i])*2<si[N-1]-si[i]){
	n=(n+m)/2;
      }else{
	m=(n+m)/2;
      }
    }
    if(abs(si[N-1]-2*si[m]+si[i])<abs(si[N-1]-2*si[n]+si[i])) n=m;
    r=si[n]-si[i];s=si[N-1]-si[n];

    ans=min(ans, max({p,q,r,s})-min({p,q,r,s}));
  }

  cout << ans << endl;

  return 0;
}

#include <iostream>
#include <string>
using namespace std;
int main(){
  string ibe;
  int n;
  int score=0,out=0;
  int hit=0;
  cin >> n;
  for(int i=0;i<n;i++){
    while(1){
      if(out >= 3)break;
      cin >> ibe;
      if(ibe=="HIT"){
	hit++;
	if(hit==4){
	  score++;
	  hit--;
	}
      }
      else if(ibe=="HOMERUN"){
	score=hit+1+score;
	hit=0;
      }
      else if(ibe=="OUT"){
	out++;
      }
    }
    cout << score << endl;
    out=0;
    hit=0;
    score=0;
  }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, 1, 1 };

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

    // 標準出力
    void Write(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Write(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T, typename U> void Write(const T& x, const U& y, const char* end = "\n") { std::cout << x << " " << y << end; }
    template <typename T, typename U, typename V> void Write(const T& x, const U& y, const V& z, const char* end = "\n") { std::cout << x << " " << y << " " << z << end; }
    //template <typename... Args> void Write(Args const&... args) { bool a = true; for (auto const& x : { args... }) { if (a) a = false; else std::cout << " "; std::cout << x; } std::cout << "\n"; }
    template <typename T> void Write(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }
    template <typename T> void Write(const std::vector<std::vector<T>>& x, const char* sep = " ", const char* end = "\n") { for (auto v : x) Write(v, sep, end); }

    // 標準入力
    struct Read {
        std::size_t szi, szj;
        Read(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
        template <typename T, typename U> operator std::vector<std::pair<T, U>>() const {
            std::vector<std::pair<T, U>> a(szi);
            for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i].first >> a[i].second; return a;
        }
    };
    struct Reads {
        template <typename T> Reads(T& a) { std::cin >> a; }
        template <typename T, typename U> Reads(T& a, U& b) { std::cin >> a >> b; }
        template <typename T, typename U, typename V> Reads(T& a, U& b, V& c) { std::cin >> a >> b >> c; }
        template <typename T, typename U, typename V, typename W> Reads(T& a, U& b, V& c, W& d) { std::cin >> a >> b >> c >> d; }
    };

    Read read;
}

int main() {

    int n, m, d; Reads(n, m, d);

    double ans;

    // 隣同士の差がdであるものの個数の平均

    ans = (double)((n - d) * 2) / (n * (double)n) * (m - 1);
    if (d == 0) ans /= 2.0;

    cout << fixed << setprecision(8) << ans << endl;

    return 0;
}

#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

LL calc(LL N, LL M, LL D) {
	VLL V(M,1);
	LL ans = 0;
	while (true) {
		for (LL m = 0; m < M - 1; m++) {
			if (abs(V[m] - V[m + 1]) == D)ans++;
		}
		LL m = M-1;
		for (; m >= 0; m--) {
			if (V[m] != N)break;
		}
		if (m == -1)return ans;
		V[m]++;
		for (LL mm = m + 1; mm < M; mm++)V[mm] = 1;
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	//for (LL n = 1; n <= 10; n++) {
	//	for (LL m = 2; m <= 6; m++) {
	//		for (LL d = 0; d < n; d++) {
	//			//cout << "n,m,d = " << n << "," << m << "," << d << ":";
	//			//cout << calc(n, m, d) << "/(n^m);\n";
	//			LL d0 = calc(n, m, d);
	//			LL d1 = 2*(m-1);
	//			for (LL p = 0; p < m - 2; p++)d1 *= n;
	//			d1 *= n - d;
	//			if (d0 != d1) {
	//				cout << "n,m,d = " << n << "," << m << "," << d << ":";
	//				cout << d0 << "vs" << d1 << "\n";
	//			}
	//		}
	//		cout << "\n";
	//	}
	//	cout << "####################\n";
	//}
	LL N, M, D;
	cin >> N >> M >> D;
	LD ans = (LD)2 * (M - 1) * (N - D) / N / N;
	if (D == 0)ans /= 2;
	cout << setprecision(12) << ans << "\n";
	return 0;
}


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

bool isEven(int x){return x%2==0;}
bool solve(vector<int> a){
    int n=a.size();
    int oneCnt=count(a.begin(),a.end(),1);
    int evenCnt=count_if(a.begin(),a.end(),isEven);
    if(oneCnt || evenCnt<n-1){
        return !isEven(evenCnt);
    }
    else{
        int g=a[0];
        for(int i=0;i<n;i++) g=__gcd(a[i]/2,g);
        for(int i=0;i<n;i++) a[i]/=(g*2);
        return !solve(a);
    }
}
void output(bool x){
    cout<<(x ? "First" : "Second")<<endl;
}
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    if(n==1){
        output(a[0]!=1);
    }
    else if(n==2){
        output(isEven(a[0]) || isEven(a[1]));
    }
    else{
        output(solve(a));
    }

    return 0;
}

#include <bits/stdc++.h>
#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(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;

int main(){
  int n;
  cin >> n;
  map<int, bool> mp;
  REP(i,n){
    int a;
    cin >> a;
    if(mp[a]) mp[a] = false;
    else mp[a] = true;
    }

  int cnt = 0;
  for(auto x: mp){
    if(x.second) cnt++;
  }

  cout << cnt << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 1;
    rep(i,n){
        if (ans * 2 > ans + k)  ans += k;
        else ans *= 2;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = (s); i < n; ++i)
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  rep(i,0,n) cin >> x[i];
  int ans = 1000000000;
  rep(i,0,n-k+1) {
    int a = x[i], b = x[i+k-1];
    if (b < 0) {
      ans = min(ans, abs(a));
    } else if (a >= 0) {
      ans = min(ans, b);
    } else {
      ans = min(ans, b-a + min(abs(a), abs(b)));
    }
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll>
#define tri pair<pll, ll>
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<pll, ll> >
#define mll map<ll, ll>
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define all(v)  (v).begin(), (v).end()
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000005
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) (ll)v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
// using namespace __gnu_pbds;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll cpow(ll a, ll b, ll M){ll ans = 1;while(b){if(b&1) ans = ans*a%M; b/=2;a=a*a%M;}return ans;}
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}
ll fexp(ll a, ll b) {return cpow(a, b, MOD);}
ll cinv(ll a, ll p){return cpow(a, p-2, p);}
ll inverse(ll a)    {return cinv(a, MOD);}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    ll tc = 0;
    while(tc++ < t){
    	ll n, m, d;
        cin>>n>>m>>d;
        ld ans = 1.0*(m-1)*(n-d)/(n*1.0*n);
        if(d > 0)	ans *= 2.0;
        cout<<fixed<<setprecision(10)<<ans;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

signed main(){
    double n, m, d; cin >> n >> m >> d;
    double ans = max(n-d,0.0)*(d !=0 ? 2 : 1) / (n*n) * (m-1);
    cout << fixed << setprecision(20.20) << ans << endl;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  string S;
  cin >> S;
  for(int i=0;i<(int)S.size();i++){
    if(i==A){
      if(S[i]!='-'){
        cout << "No" << endl;
        return 0;
      }
    }
    else{
      if(!(S[i]-'0'>=0 && S[i]-'0'<=9)){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%lld",&x);
int main(){
    ll n, a, b;
    sc(n) sc(a) sc(b)
    ll X[n];
    for (int i = 0; i < n; i++) sc(X[i])
    ll x,ans = 0;
    for (int i = 0; i < n - 1; i++){
        x = (X[i + 1] - X[i]) * a;
        ans += min(x, b);
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string.h>
#include <stack>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
int main() {
    int n,m;
    cin >> n;
    map<string, int>blue;
    map<string, int>red;
    rep(i, 0, n){
        string in;
        cin >> in;
        blue[in]++;
    }
    cin>>m;
    rep(i, 0, m){
        string in;
        cin >> in;
        red[in]++;
    }
    int ans = 0;
    for(auto i: blue){
        int blucnt =i.second;
        if(red[i.first] != 0){
            blucnt-=red[i.first];
        }
        ans = max(ans, blucnt);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n, m;
	cin >> n;
	vector<string> s(n);
	for(int i=0; i<n; i++){
		cin >> s.at(i);
	}
	cin >> m;
	vector<string> t(m);
	for(int i=0; i<m; i++){
		cin >> t.at(i);
	}
	vector<int> num(n);
	for(int i=0; i<n; i++){
		for(int j=i; j<n; j++){
			if(s.at(i)==s.at(j)){
				num.at(i)++;
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(s.at(i)==t.at(j)){
				num.at(i)--;
			}
		}
	}
	sort(num.begin(), num.end());
	reverse(num.begin(), num.end());
	if(num.at(0)>=0){
		cout << num.at(0) << endl;
	}
	if(num.at(0)<0){
		cout << 0 << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"
int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>n>>m;
	for(ll i=n;i<=m;i++){
		if((i/10000==i%10) && (i/1000%10==i%100/10))ans++;
	}
	cout<<ans<<nw;
}

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

int main() {
  int L;
  string S;
  cin >> L >> S;
  if (S.size() <= L) {
    cout << S << endl;
  } else {
    cout << S.erase(L) << "..." << endl;
  }
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

void trace(int A[], int N)
{
    int i;
    for (i = 0; i < N; i++) {
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

int bubbleSort(int A[], int N){
    bool flag = 1;
    int cnt = 0;
    while (flag){
        flag = 0;
        for (int i=N-1; i >= 1; i--) {
            if (A[i] < A[i-1]) {
                swap(A[i], A[i-1]);
                cnt += 1;
                flag =  1;
            }
        }
    }
    trace(A, N);
    return cnt;
}

int main() {
    int n, num_sec[101]={}, cnt=0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> num_sec[i];
    cnt=bubbleSort(num_sec, n);
    cout << cnt << endl;
}

  /*  HARD WORK FOREVER PAYS  */
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define turbo(){	\
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL); \
}
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long int ull;

vector<ull> allPrimes;

void sieve(int n)
{

    vector<bool> prime(n+1, true);

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {

            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (int p=2; p<=n; p++)
        if (prime[p])
            allPrimes.push_back(p);
}

ull factorialDivisors(ull n)
{
    sieve(n);

    ull result = 1;

    for (int i=0; i < allPrimes.size(); i++)
    {

        ull p = allPrimes[i];
        ull exp = 0;
        while (p <= n)
        {
            exp = exp + (n/p);
            p = p*allPrimes[i];
        }

        result = result*(exp+1)%1000000007;
    }

    return result;
}

int main()
{
	int n;
	cin>>n;
    cout << factorialDivisors(n)<<endl;
    return 0;
}