#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<vector<int>> adj;
int dp[100005];
int k,ans=0;
int parent[1000005];
void dfs(int ver,int pr)
{
    parent[ver]=pr;
    int mx=-1;
    for(auto i:adj[ver])
    {
        dfs(i,ver);
        mx=max(mx,dp[i]);
    }
    dp[ver]=mx+1;
    if(dp[ver]==k-1 &&parent[ver]!=1)
    {
        dp[ver]=-1;
        ans++;
    }
}

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif

    int n;
    cin>>n>>k;
    adj.resize(n+1);
    int x;
    cin>>x;
    fill_n(dp,100004,-1);
    if(x!=1)
            ans++;

    for(int i=0;i<n-1;i++)
    {
        cin>>x;
        adj[x].push_back(i+2);
    }
    dfs(1,1);
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i <= n; i++)
typedef pair<int, int> P;

const ll INF = 1ll<<60;
typedef struct{int to, cost;} edge;
int N, Q, K;
vector<edge> G[100100];
vll d(100100, INF);

void nya(int s){
    priority_queue<P, vector<P>, greater<P> >que;
    d[s] = 0ll;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        rep(i, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return;
}

int main(){
    cin >> N;
    rep(i, N)if(i){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edge tmp;
        tmp.to = b;
        tmp.cost = c;
        G[a].push_back(tmp);
        tmp.to = a;
        G[b].push_back(tmp);
    }
    cin >> Q >> K;
    nya(K - 1);
    while(Q--){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << d[x] + d[y] << endl;
    }
    return 0;
}

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

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 1000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.14159265358979323
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"

ll dp[7007];

int main()
{
    FAST;
    ll n,t;
    cin>>n>>t;
    pair<ll,ll> a[n];
    ll x,y;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        a[i]={x,y};
    }
    sort(a,a+n);
    for(int i=1;i<7007;i++)
        dp[i]=-1;
    for(int i=0;i<n;i++)
        for(int j=t-1;j>=0;j--)
            if(dp[j]!=-1)
                dp[a[i].first+j]=max(dp[a[i].first+j],dp[j]+a[i].second);
    ll ans=0;
    for(int i=0;i<7007;i++)
        ans=max(ans,dp[i]);
    cout<<ans;
    subt;
    return 0;
}


#include<bits/stdc++.h>

const int MOD = 1e9 + 7;

using namespace std;

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

  int D;
  cin >> D;

  vector<vector<vector<long long>>> dp(K.size() + 1, vector<vector<long long>>(D, vector<long long>(2, 0)));
  dp[0][0][1] = 1;
  for(int i = 0; i < (int)K.size(); i++){
    for(int j = 0; j < D; j++){
      for(int k = 0; k < 10; k++){
        dp[i + 1][(j + k) % D][0] += dp[i][j][0];
        if(k < K[i] - '0'){
          dp[i + 1][(j + k) % D][0] += dp[i][j][1];
        }else if(k == K[i] - '0'){
          dp[i + 1][(j + k) % D][1] += dp[i][j][1];
        }
        dp[i + 1][(j + k) % D][0] %= MOD;
        dp[i + 1][(j + k) % D][1] %= MOD;
      }
    }
  }

  cout << ((dp[K.size()][0][0] + dp[K.size()][0][1] - 1) % MOD + MOD) % MOD << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define int long long
int pref[250005], suff[250005], ans, prefix[250005], h , w, a, b;

const int mod = 1e9 + 7;

int BinPow(int x,int n){
    if(n == 0)
        return 1;
    if(n == 1)
        return x;
    else{
        int sum = BinPow(x, n / 2) % mod;
        sum*=sum; sum%=mod;
        if(n % 2 != 0)
            sum *= x, sum%=mod;
        return sum;
    }
}

int C(int x,int n){
    if(x < 0 || x > n || n < 0) return 0;
    int sum = pref[n] * suff[x]; sum %= mod;
    sum*=suff[n - x]; sum %= mod;
    return sum;
}

signed main(){
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> h >> w >> a >> b;
    pref[0] = 1;
    for(int i = 1; i <= 250000; i++){
        pref[i] = pref[i - 1]*i;
        pref[i] %= mod;
    }
    suff[0] = 1;
    for(int i = 1; i <= 250000; i++)
        suff[i] = BinPow(pref[i], mod - 2);
    for(int i = 1; i <= 100000; i++){
        if(i >= h - a + 1){
            prefix[i] += C(b - 1, i + b - 2);
            pref[i] %= mod;
            prefix[i] += prefix[i - 1];
        }
    }
    ans = C(h - 1,h + w - 2);
    for(int i = 1; i <= h; i++){
        if(i >= h - a + 1){
            int dist = w - b;
            int dist1 = h - i + 1;
            ans -= C(b - 1, i + b - 2)*C(dist1 - 1,dist + dist1 -2 );
            ans %= mod;
            if(ans < 0) ans += mod;
        }
    }
    cout << ans;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<ctime>
#include<set>
#include<iomanip>
#define sqr(x) (x)*(x)
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
//#define T_ int
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
//struct bit_2d{T_ a[2005][2005];int lowbit(int x){return x&(-x);}void add(int x,int y,T_ z){int i,j;for (i=x;i<=2000;i+=lowbit(i)){for (j=y;j<=2000;j+=lowbit(j)){a[i][j]+=z;}}}T_ query(int x,int y){int i,j;T_ s=0;for (i=x;i;i-=lowbit(i)){for (j=y;j;j-=lowbit(j)){s+=a[i][j];}}return s;}T_ query(int x,int y,int xx,int yy){return query(xx,yy)-query(x-1,yy)-query(xx,y-1)+query(x-1,y-1);}};
long long n,m,i,j,f[200005],g[200005],a[200005],ans;
int main()
{
	scanf("%lld%lld",&n,&m);
	ans=m*(n-1);
	fz1(i,n)
	{
		scanf("%lld",&a[i]);
		ans+=a[i];
	}
	f[0]=g[n+1]=(1ll<<60);
	fz1(i,n)
	{
		f[i]=min(a[i],f[i-1]+m);
	}
	fd1(i,n)
	{
		g[i]=min(a[i],g[i+1]+m);
	}
	fz(i,2,n-1) ans+=min(f[i],g[i]);
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll N,A,B;
  cin >> N >> A >> B;
  vector<ll> X(N);
  REP(i, N) cin >> X[i];

  ll ans=0;
  REP(i,N-1){
    if((X[i+1]-X[i])*A>=B){
      ans+=B;
    }else{
      ans+=(X[i+1]-X[i])*A;
    }
  }
  cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 2147483647;
const ll INF = 100000000000010000;
const ull B = 998244353;

//ll bit[200010];
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	i += 1;
	ll t = 0;
	while (i > 0)
	{
		t += bit[i];
		i -= i & -i;
	}
	return t;
}

void update(ll i, ll x)
{
	i += 1;
	while (i <= 200005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

/*`ll SAIKI(ll S) {
	for (ll T = S; ; T = (T - 1) & S) {

	}
}*/

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

/*ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
	//毎回オーダーlog(n)かかる
}*/

/*void kaijo() {
	kai[0] = 1;
	for (ll i = 1; i <= 3004; i++) {
		kai[i] = kai[i - 1] * i % mod;
	}
}*/

ll N, A[100010], sum, resum;
ll hakidashi[60];
vector<P> trans;
ll ans;

void solve() {
	cin >> N;
	rep(i, N) cin >> A[i];
	rep(i, N) sum ^= A[i];
	resum = sum ^ ((1LL << 60) - 1);
	rep(i, N) A[i] &= resum;
	priority_queue<ll> que;
	ll bit = 59;
	rep(i, N)if (A[i] != 0) que.push(A[i]);
	while (que.size()) {
		ll lar = que.top(); que.pop();
		while ((lar & (1LL << bit)) == 0 && bit >= 0) bit--;
		if (bit < 0) break;
		hakidashi[bit] = lar;
		while (que.size() && que.top() > (1LL << bit)) {
			ll a = que.top(); que.pop();
			que.push(a ^ hakidashi[bit]);
		}
	}
	rep(i, 60)if (hakidashi[i] != 0) trans.pb(P(hakidashi[i], i));
	for (ll i = 0; i < trans.size(); i++) {
		for (ll j = i + 1; j < trans.size(); j++) {
			P p = trans[i], q = trans[j];
			if ((q.f & (1LL << p.s)) != 0) trans[j].f ^= p.f;
		}
	}
	for (P p : trans) ans ^= p.f;
	ans = ans * 2 + sum;
	cout << ans << endl;
}

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

#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=60,N=100000;
ll n,cnt[M],ID=0;
vl a;
vp d;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	a=vl(n);
	vector<bitset<N+1>> b;
	for(auto &i:a){
		cin>>i;
		for(int j=0;j<M;j++) if(i&1ll<<j) cnt[j]++;
	}
	ll sum=0;
	for(int i=M-1;i>=0;i--){
		ll cnt=0,t=1ll<<i;
		bitset<N+1> c;
		c[N]=1;
		for(int j=0;j<n;j++) if(a[j]&t){
			c[j]=1;
			cnt++;
		}
		if(cnt%2==1){
			sum+=t;
			continue;
		}
		sort(d.begin(),d.end());
		for(auto p:d){
			int tmp=p.first,id=p.second;
			if(c[tmp]) c^=b[id];
		}
		bitset<N+1> beet;
		beet[N]=1;
		if(c==beet) continue;
		int I;
		for(int j=0;j<=N;j++) if(c[j]){
			d.push_back({j,ID});
			ID++;
			b.push_back(c);
			I=j;
			break;
		}
		for(int j=0;j<d.size();j++){
			int tmp=d[j].first,id=d[j].second;
			if(tmp<I&&b[id][I]) b[id]^=c;
		}
		sum+=t*2;
	}
	cout<<sum<<endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int bubble_sort(int n,vector<int> &vec);

int main() {
	int n,count;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	count=bubble_sort(n,a);
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i != n - 1) { cout << " "; }
	}
	cout << "\n" << count << endl;

}

int bubble_sort(int n,vector<int> &vec) {
	int count = 0;
	bool flag = true;
	while (flag) {
		flag = false;
		for (int j = 1; j < n; j++) {
			if (vec[j] < vec[j - 1]) {
				swap(vec[j], vec[j - 1]);
				count++;
				flag = true;
			}
		}
	}
	return count;
}

#include <cstdio>

void printArray(int A[], int N) {
    for (int i = 0; i < N; i++) {
        if (i != N-1) {
            printf("%d ", A[i]);
        } else {
            printf("%d", A[i]);
        }
    }
    printf("\n");
}

void bubbleSort(int A[], int N) {
    bool unsorted = 1;
    int i = 0;
    int counter = 0;
    while (unsorted) {
        unsorted = 0;
        for (int j = N-1; j >= i; j--) {
            if (A[j] < A[j-1]) {
                int tmp = A[j];
                A[j]    = A[j-1];
                A[j-1]  = tmp;
                unsorted = 1;
                counter++;
            }
        }
        i++;
    }
    printArray(A, N);
    printf("%d\n", counter);
}

int main() {
    int N;
    int A[100];

    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        int input;
        scanf("%d", &input);
        A[i] = input;
    }
    bubbleSort(A, N);
}


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

int main()
{
    ll n;
    cin >> n;
    ll a[n], b[n], c[n];
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];
    for(int i=0; i<n; i++) cin >> c[i];

    sort(a, a+n);
    sort(b, b+n);
    sort(c, c+n);

    ll ans = 0;

    for(ll i=0; i<n; i++){
        ll u = upper_bound(a, a+n, b[i]-1) - a;
        ll l = lower_bound(c, c+n, b[i]+1) - c;

        ans += u * (n-l);
    }
    cout << ans << endl;

}

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const LL MOD = 1e9 + 7;
const int MAXV = 1e5 + 5;
double solve(int a, int b, int c, auto &dp, int n) {
    if (dp[a][b][c] != -1) return dp[a][b][c];
    double sum = 0;
    if (a - 1 >= 0)
        sum += solve(a - 1, b, c, dp, n) / n * a;
    if (b - 1 >= 0)
        sum += solve(a + 1, b - 1, c, dp, n) / n * b;
    if (c - 1 >= 0)
        sum += solve(a, b + 1, c - 1, dp, n) / n * c;
    sum++;
    sum *= n, sum /= a + b + c;
    return dp[a][b][c] = sum;
}
void marmot0814() {
    int n; cin >> n;
    vector<LL> cnt(3, 0);
    for (int i = 0 ; i < n ; i++) {
        int v; cin >> v; v--;
        cnt[v]++;
    }
    vector<vector<vector<double>>> dp(n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1, -1)));
    dp[0][0][0] = 0;
    cout << fixed << setprecision(20) << solve(cnt[0], cnt[1], cnt[2], dp, n) << '\n';
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t = 1, kase = 0; // cin >> t;
    while (t--) {
        // cout << "Case #" << ++kase << ":";
        marmot0814();
    }
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update>
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
double dp[305][305][305];

int main()
{
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ll n;
    cin>>n;
    ll a[n];
    ll one=0;
    ll two=0;
    ll three=0;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        if(a[i]==1){
            one++;
        }
        else if(a[i]==2){
            two++;
        }
        else{
            three++;
        }
    }

    for (int c = 0; c<=n; ++c)
    {
        for (int b = 0; b<=n; ++b)
        {
            for (int a = 0; a<=n; ++a)
            {
                ll k = a+b+c;
                if(k==0){
                    continue;
                }
                if(k>n){
                    continue;
                }
                dp[a][b][c] += (1.0 * n)/k;
                if(a){
                    dp[a][b][c] += (1.0 * a)/k * dp[a - 1][b][c];
                }
                if(b){
                    dp[a][b][c] += (1.0 * b)/k * dp[a + 1][b - 1][c];
                }
                if(c){
                    dp[a][b][c] += (1.0 * c)/k * dp[a][b + 1][c - 1];
                }
            }
        }
    }

    cout<<fixed<<setprecision(10)<<dp[one][two][three]<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 17;
int a[N][N], n;
struct bm {
  int v; bm(int val=0) : v(val) {}
  bool operator[](int i) const { return v & 1 << i; }
  bm set(int i) const { return bm(v | 1 << i); }
  bm invert() const { return bm(v ^ -1); }
};
#define for_submasks(s, m) for (int s=m, l=1<<__builtin_popcount(m); l--; s=(s-1)&m)

ll dp[1 << N];
ll s[1<<N];

ll score(bm mask) {
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      if (mask[i] && mask[j]) {
        ans += a[i][j];
      }
    }
  }
  return ans;
}
void pre() {
  for (int i = 0; i < (1 << n); ++i) {
    s[i] = score(i);
  }
}

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }
  pre();
  memset(dp, -INF, sizeof dp);
  dp[0] = 0;
  for (int mask = 0; mask < (1<<n); ++mask) {
    for_submasks(sm, mask) {
      if (sm == mask) continue;
      dp[mask] = max(dp[mask], dp[sm] + s[mask ^ sm]);
    }
  }
  cout << dp[(1 << n)-1] << nl;

  return 0;
}


#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const long long INF = 1LL << 60;
ll MOD = 1e9+7;

int main() {

    int A,B; cin>>A>>B;

    cout<<A*B<<endl;

}

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

#define fast_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
typedef long long int lli;
typedef long long ll;
typedef long double ld;

signed main(){
    fast_IO;
    int t=1;
    //cin>>t;
    while(t--){
        ld n,b;
        cin>>n>>b;
        ll nb = b*100+0.5;
        cout<<(n*nb)/100;
    }
    return 0;
}


#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef vector <string> vs;

int main(void){
	map <char, int> m;
	int num[] = {1,5,10,50,100,500,1000};
	for (int i=0; i<7; i++)
		m["IVXLCDM"[i]] = num[i];

	char c;
	string r;
	while (cin>>r){
		int tmp, tmp2= m[r[0]],s=0;
		int n=r.size();
		for (int i=0; i<n; i++){
			tmp = m[r[i]];
			if (tmp2<tmp)
				s-= tmp2*2;
			s += tmp;
			tmp2 = tmp;
		}
		cout<<s<<endl;
	}
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h>
#include<random>
#define int long long
#define pp pair<int,int>
#define ss second
#define ff first
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout);
  #endif
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL) ;
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<2*pi*n;
    }
}

// 🍪 🍪 🍪


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

int main(void)
{
	priority_queue <int> w, k;
	int tmp;

	for (int i = 0; i < 10; i++){
		scanf("%d", &tmp);
		w.push(tmp);
	}
	for (int i = 0; i < 10; i++){
		scanf("%d", &tmp);
		k.push(tmp);
	}

	int sumw = 0, sumk = 0;
	for (int i = 0; i < 3; i++){
		sumw += w.top();
		w.pop();
		sumk += k.top();
		k.pop();
	}

	printf("%d %d\n", sumw, sumk);

	return (0);
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
      string str,fc,p;
      int q,i=0,a,b;
      cin>>str>>q;
      for(;i<q;i++){
            cin>>fc>>a>>b;
            switch(fc[2]){
                  case 'i':
                        cout<<str.substr(a,b-a+1)<<endl;
                        break;
                  case 'v':
                        p=str.substr(a,b-a+1);
                        reverse(p.begin(),p.end());
                        str.replace(a,b-a+1,p);
                        break;
                  case 'p':
                        cin>>p;
                        str.replace(a,b-a+1,p);
                        break;
            }
      }

}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int vote[1010];
int cost[1010];

int main(){
	int n,m;
	cin>>n>>m;
	memset(vote, 0, sizeof(vote));
	memset(cost, 0, sizeof(cost));
	rep(i, n){
		cin>>cost[i];
	}
	rep(i, m){
		int x;
		cin>>x;
		rep(j, n){
			if(cost[j]<=x){
				vote[j]++;
				break;
			}
		}
	}
	int cnt = 0;
	int ans = 0;
	rep(i, n){
		if(vote[i]>=cnt){
			cnt =vote[i];
			ans=i;
		}
	}
	cout <<ans+1<<endl;
	return 0;
}

#include <bits/stdc++.h>

const int MAXN = 1010;
typedef long long LL;
int pri[MAXN], bak, n;
int ispri(int x) {
	for (int i = 2; i * i <= x; ++i)
		if (x % i == 0) return false;
	return true;
}
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; }
LL get(int x, int y) {
	if (x < 1 || y < 1 || x > n || y > n) return 1;
	if ((x & 1) == (y & 1))
		return pri[x + y >> 1] * pri[x + n * 3 - y + 1 >> 1];
	return lcm(lcm(get(x - 1, y), get(x, y - 1)), lcm(get(x + 1, y), get(x, y + 1))) + 1;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n; n += 2;
	int now = 2;
	while (bak < n * 2) {
		if (ispri(now)) pri[++bak] = now;
		++now;
	}
	for (int i = 2; i < n; ++i, std::cout << '\n')
		for (int j = 2; j < n; ++j)
			std::cout << get(i, j) << ' ';
	return 0;
}


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

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    int n;
    cin>>n;
    rep(i,0,n){
        int out=0;
        int score=0;
        int runner=0;
        string s;
        while(out!=3){
            cin>>s;
            if(s=="HIT"){
                if(runner==3)score++;
                else runner++;
            }else if(s=="OUT"){
                out++;
            }else{
                score+=runner+1;
                runner=0;
            }
        }
        cout<<score<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

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

  int s=0;
  int t=0;
  for (auto c:x) {
    if (c == 'S') {
      s++;
    } else {
      if (s > 0) s--;
      else t++;
    }
  }
  cout << t+s << endl;

  return 0;
}


#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>

int main(void) {
    std::string str;
    int a;
    int b;
    int q;
    std::string start = "";
    std::string sub = "";
    std::string end = "";
    std::string s = "";
    std::cin >> str >> q;

    for (int i = 0; i < q; i++) {
        std::string order;
        std::cin >> order;
        std::cin >> a >> b;
        start = str.substr(0, a);
        sub = str.substr(a, b - a + 1);
        end = str.substr(b + 1, str.size() - b);

        if (order == "replace") {
            s = "";
            std::cin >> s;
            str = start + s + end;
        } else if (order == "reverse") {
            std::reverse(sub.begin(), sub.end());
            str = start + sub + end;
        } else if (order == "print") {
            std::cout << sub << std::endl;
        } else {
        }
    }

    return EXIT_SUCCESS;
}

#include <iostream>

int li, ri, n, m, a, b;

int main() {
    a = 0;
    b = 1000001;
    std::cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        std::cin >> li >> ri;
        if (li > a) a = li;
        if (b > ri) b = ri;
    }
    int ans = a > b ? 0 : b - a + 1;
    std::cout << ans;
    return 0;
}


#include <iostream>
#include <limits.h>

using namespace std;

int dp[100][100];
int p[101];
int n;

void solve() {
	for (int m = n; m > 0; m--) {
		for (int t = 0, i = 0, j = n - m + 1; t < n && j < n; t++) {
			dp[i][j] = INT_MAX;
			for (int k = i; k < j; k++) {
				int temp = dp[i][k] + dp[k + 1][j] + p[i] * p[k + 1] * p[j + 1];
				if (temp < dp[i][j]) {
					dp[i][j] = temp;
				}
			}
			i++;
			j++;
		}
	}
}

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

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

	solve();
	cout << dp[0][n - 1] << endl;

	return 0;
}

#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[111][111],n,L[111],R[111];
int f(int l,int r){
	if(dp[l][r]>-1)return dp[l][r];
	int res=1e9;
	for(int i=l;i<r;i++){
		res=min(res,f(l,i)+f(i+1,r)+L[l]*R[i]*R[r]);
	}
	return dp[l][r]=res;
}
main(){
	memset(dp,-1,sizeof(dp));
	r(i,111)dp[i][i]=0;
	cin>>n;
	r(i,n)cin>>L[i]>>R[i];
	cout<<f(0,n-1)<<endl;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = n - 1, num = 0;
    for (int i = 1; i < n; i++) {
        if (s.at(i) == 'E') num++;
    }
    //cout << num << endl;
    ans = min(ans, num);
    for (int i = 0; i < n - 1; i++) {
        if (s.at(i) == 'W') num++;
        if (s.at(i + 1) == 'E') num--;
        ans = min(ans, num);
        //cout << num << endl;
    }
    cout << ans << endl;
}

#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

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

template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}

inline void setin(string s) {
    freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
    freopen(s.c_str(), "w", stdout);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}

template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 3e2 + 15;
int n, k;
string s;
int dp[2][N][N]; // dp[i][operation_applied][free_ones]
int a[N], p[N][N];

inline int add(int a, int b) {
    a += b;
    if(a >= mod)
        a -= mod;
    if(a < 0)
        a += mod;
    return a;
}

inline void add_t(int &a, int b) {
    a = add(a, b);
}

inline void construct() {
    int sz = 1;
    for(int i = 1; i <= n && s[i] == '1'; ++i)
        a[1] = i;
    for(int i = a[1] + 1; i <= n; ++i) {
        if(s[i] == '0') {
            if(i + 1 <= n && s[i + 1] == '0')
                a[++sz] = 0;
        }
        else {
            int j = i;
            while(j + 1 <= n && s[j + 1] == '1')
                ++j;
            a[++sz] = j - i + 1;
            i = j;
        }
    }
    n = sz;
}

inline void solve() {
    // dp[i][operation_applied][free_ones]
    dp[(n + 1) & 1][0][0] = 1;
    int sum = 0;
    for(int i = n; i >= 1; --i) {
        int bit = i & 1;
        memset(dp[bit], 0, sizeof(dp[bit]));
        for(int k = 0; k < N; ++k)
            for(int t = 0; t < N; ++t)
                p[k][t] = add(k && t ? p[k-1][t-1] : 0, dp[bit ^ 1][k][t]);

        for(int k = 0; k < N; ++k) {
            int val = 0;
            for(int t = N - 1; t >= 0; --t) {
                add_t(dp[bit][k][t], val);
                if(k - a[i] - 1 >= 0 && t - a[i] - 1 >= 0)
                    add_t(dp[bit][k][t], add(p[k][t], -p[k - a[i] - 1][t - a[i] - 1]));
                else
                    add_t(dp[bit][k][t], p[k][t]);
                add_t(val, dp[bit ^ 1][k][t]);
            }
        }
        sum += a[i];
    }
}

inline void output() {
    int ans = 0;
    for(int i = 0; i < min(N, k + 1); ++i)
        add_t(ans, dp[1][i][0]);
    cout << ans << endl;
}

main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // setin("input.txt");
    cin >> s >> k;
    n = s.size();
    s = '#' + s;
    construct();
    solve();
    output();
    return 0;
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define mp make_pair
#define ll long long
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug cout<<"Debugging.."<<endl
using namespace std;
int main()
{
	faster;

		ll int n;
		cin>>n;

		int a=pow(n,2);
		int b=pow(n,3);
		cout<<a+b+n;

}

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

int main(){
	int a;
	int ans;
	cin>>a;
	ans=a+a*a+a*a*a;
	cout<<ans<<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>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

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

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

    int n, p;
    while (cin >> n >> p, n) {
        vector<int> v(n, 0);
        int pot = p;
        rep(r, 1000000) {
            int i = r % n;
            if (pot > 0) {
                pot--;
                v[i]++;
            } else {
                pot += v[i];
                v[i] = 0;
            }

            if (v[i] == p) {
                cout << i << endl;
                break;
            }
        }
    }
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>

int money[300];

int main(){
  int x, y;
  std::cin >> x >> y;
  int ans = 0;
  money[1]=300000;
  money[2]=200000;
  money[3]=100000;
  ans += money[x];
  ans += money[y];
  if (x==y && x==1){
    ans += 400000;
  }
  std::cout << ans << std::endl;
  return 0;
}


// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 9;
const int infint = 1e9 + 7;
const int MAXN = 1e5 + 7;
const double eps = 1e-9;
const long double pi = 3.1415926535897932384626433832795;
const long double e = 2.71828182845904523536028747135266;
inline ll read()
{
    ll kr = 1, xs = 0;
    char ls;
    ls = getchar();
    while (!isdigit(ls))
    {
        if (!(ls ^ 45))
            kr = -1;
        ls = getchar();
    }
    while (isdigit(ls))
    {
        xs = (xs << 1) + (xs << 3) + (ls ^ 48);
        ls = getchar();
    }
    return xs * kr;
}
// inline __int128 read128()
// {
//     __int128 kr=1,xs=0;char ls;ls=getchar();
//     while(!isdigit(ls)){
//         if(!(ls^45)) kr=-1;ls=getchar();
//     }
//     while(isdigit(ls)){
//         xs=(xs<<1)+(xs<<3)+(ls^48);ls=getchar();
//     }
//     return xs*kr;
// }
inline ull readull()
{
    ull xs = 0;
    char ls;
    ls = getchar();
    while (!isdigit(ls))
        ls = getchar();
    while (isdigit(ls))
    {
        xs = (xs << 1) + (xs << 3) + (ls ^ 48);
        ls = getchar();
    }
    return xs;
}
inline void writeull(ull x)
{
    if (x < 0)
    {
        x *= -1;
        putchar('-');
    }
    if (x >= 10)
        writeull(x / 10);
    putchar('0' + x % 10);
}
inline void write(ll x)
{
    if (x < 0)
    {
        x *= -1;
        putchar('-');
    }
    if (x >= 10)
        write(x / 10);
    putchar('0' + x % 10);
}
// inline void write(__int128 x){
//     if(x<0){x*=-1;putchar('-');}
//     if(x>=10) write(x/10);
//     putchar('0'+x%10);
// }
///////////////////////////////////////////////////////////////////////////////////////
int a[MAXN];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // t = read();
    while (t--)
    {
        int n=read(),x=read(),T=read();
        n=n/x+(n%x?1:0);
        n*=T;
        printf("%d\n",n);
    }
    return 0;
}

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

int main()
{
int N,X,T;
cin>>N>>X>>T;
int k=ceil((double)N/X);
int val=k*T;
cout<<val<<endl;
    return 0;
}


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

int main() {
  string N, ans = "No";
  cin >> N;
  for(char s : N) {
    if (s == '7') ans = "Yes";
  }
  cout << ans << endl;
}

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

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

  if(s.at(0)=='7' ||s.at(1)=='7' || s.at(2)=='7') cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  int ans =a*b;
  cout << ans << endl;
  return 0;
 }

#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t;
    t = 1;
    for(int i=0;i<t;i++)
    {
        int a,b;
        cin>>a>>b;
        cout<<a*b;
    }
    return 0;
}


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

int main()
{
  int a,b;
  int n=1;
  int cnt=0;

  cin >> a >> b;
  if(n<b)
  {
    n=a, cnt++;
  }
  while(n<b)
  {
    n+=a-1;
    cnt++;
  }

  cout << cnt << endl;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	cout << a + b + c + d - min(min(min(a, b), c), d) + max(e, f) << endl;
	cin >> c;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 50;
ll p[64];
int st[64];
int tot = 0;
void ins(ll x) {
	for (int i = 0; i < tot; ++i) {
		if ((x >> st[i]) & 1) {
			if (p[i]) x ^= p[i];
			else {
				p[i] = x;
				break;
			}
		}
	}
}
int n;
ll a[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	ll sum = 0;
	for (int i = 0; i < n; ++i) cin >> a[i], sum ^= a[i];
	for (int i = 60; i >= 0; --i) if (!((sum >> i) & 1)) st[tot++] = i;
	for (int i = 0; i < n; ++i) ins(a[i]);
	ll res = 0;
	for (int i = 0; i < tot; ++i)
		if (!((res >> st[i]) & 1)) res ^= p[i];
	cout << res + (sum ^ res) << endl;
}

#include<iostream>

using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
   int a, min;
   int d[MAX], p[MAX], color[MAX];

   for ( int i = 0; i < n; i++) {
      d[i] = INFTY;
      p[i] = -1;
      color[i] = WHITE;
   }

   d[0] = 0;

   while ( 1 ) {
      min = INFTY;
      a = -1;

      for ( int i = 0; i < n; i++ ) {
         if ( min > d[i] && color[i] != BLACK ) {
            a = i;
            min = d[i];
         }
      }

      if ( a == -1 ) break;
      color[a] = BLACK;
      for ( int v = 0; v < n; v++ ) {
         if ( color[v] != BLACK && M[a][v] != INFTY ) {
            if ( d[v] > M[a][v] ) {
               d[v] = M[a][v];
               p[v] = a;
               color[v] = GRAY;
            }
         }
      }
   }

   int sum = 0;
   for ( int i = 0; i < n; i++ ) {
      if ( p[i] != -1 ) sum = sum + M[i][p[i]];
   }

   return sum;
}

int main() {
   cin >> n;

   for ( int i = 0; i < n; i++ ) {
      for ( int j = 0; j < n; j++ ) {
         int e; cin >> e;
         M[i][j] = (e == -1) ? INFTY : e;
      }
   }

   cout << prim() << endl;

   return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T In(){ T x; cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

int main()
{
  while (int e = in()){
    int m = 1e8;
    for (int z = 0; z <= 100; ++z){
      for (int y = 0; y <= 1000; ++y){
        int x = e - (sq(z) * z + sq(y));
        if (x < 0) continue;
        m = min(m, z + y + x);
      }
    }
    printf("%d\n", m);
  }
  return (0);
}

#include <algorithm>
#include <iostream>
#include <string>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;

int main() {
    while(1) {
        int e;
        cin >> e;
        if(e == 0) {
            break;
        }
        int min = 1000000;
        for(int z = 0; z*z*z <= e; z++) {
            for(int y = 0; y*y <= e-z*z*z; y++) {
                int tmp  = e-y*y-z*z*z + y + z;
                if(tmp < min){
                    min = tmp;
                }
            }
        }
        cout << min << endl;
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[111][111];
signed main(){
  int n;
  cin>>n;
  int r[n],c[n];
  for(int i=0;i<n;i++) cin>>r[i]>>c[i];
  int INF=1LL<<55LL;
  for(int i=0;i<111;i++) fill_n(dp[i],111,INF);
  for(int i=0;i<n;i++) dp[i][i+1]=0;
  for(int i=2;i<=n;i++)
    for(int j=0;j<=n-i;j++)
      for(int k=1;k<i;k++)
	dp[j][j+i]=min(dp[j][j+i],dp[j][j+k]+dp[j+k][j+i]+(r[j]*r[j+k]*c[j+i-1]));
  cout<<dp[0][n]<<endl;
  return 0;
}

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

int main() {
  int mod=1000000007;
  int n;
  cin >> n;
  long to=0;
  vector<int>a(n);
  vector<int>b(n);
  vector<int>c(n);
  rep(i,n){
    cin>>a.at(i)>>b.at(i);
    to-=b.at(i);
    c.at(i)=a.at(i)+b.at(i);
  }
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  rep(i,(n-1)/2+1){
    to+=c.at(i*2);
  }
  cout<<to<<endl;
}


// https://atcoder.jp/contests/abc127/tasks/abc127_e

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

//------------------------------------------------------------------------------
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

ll mod_inverse(ll x, ll mod) {
  return mod_pow(x, mod - 2, mod);
}

ll mod_comb(ll n, ll k, ll mod) {
  if (n < 0 || k < 0 || n < k) return 0;
  ll a = 1, b = 1;
  while(k > 0) {
    a = a * n-- % mod;
    b = b * k-- % mod;
  }
  return a * mod_inverse(b, mod) % mod;
}

//------------------------------------------------------------------------------
const int M_MAX = 2*1e5;
const int MOD = 1e9+7;

ll N, M, K;

void solve() {
  ll y = 1;
  y = y * (N - 1) % MOD;
  y = y * N % MOD;
  y = y * (N + 1) % MOD;
  y = y * M % MOD;
  y = y * M % MOD;

  ll x = 1;
  x = x * (M - 1) % MOD;
  x = x * M % MOD;
  x = x * (M + 1) % MOD;
  x = x * N % MOD;
  x = x * N % MOD;

  ll ans = (x + y) % MOD;
  ans = ans * mod_inverse(6, MOD) % MOD;
  ans = ans * mod_comb(N * M - 2, K - 2, MOD) % MOD;
  printf("%lld\n", ans);
}

void input() {
  scanf("%lld%lld%lld", &N, &M, &K);
}

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

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

const int64_t MAX = 510000;
const int64_t MOD = 1000000007;

int64_t fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
int64_t COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int64_t N,M,K;
  cin>>N>>M>>K;

  COMinit();
  int64_t ans=0;
  for(int i=0;i<N;++i){
    for(int j=0;j<M;++j){
      if(i!=0 && j!=0) ans += 2*(i+j)*(M-j)*(N-i);
      else ans += (i+j)*(M-j)*(N-i);
      ans %= MOD;
    }
  }
  ans *= COM(N*M-2,K-2);
  cout<<ans%MOD<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, sum = 0;
  cin >> n;
  vd a(n);
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    a[i] *= n;
  }
  ll ans, d = 1e18;
  rep(i, n) {
    ll nd = abs(sum - a[i]);
    if(nd < d) {
      d = nd;
      ans = i;
    }
  }
  cout << ans << endl;
}

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

vector<P> G[1001][1001];
int dp[1001][1001];

vector<P> tp;

int dfs(int x,int y,int px=1000,int py=1000)
{
	if(dp[x][y]!=0)return dp[x][y];
	if(G[x][y].empty())return dp[x][y] = 1;
	for(auto i:G[x][y])
	{
		dp[x][y] = max(dp[x][y],dfs(i.first,i.second,x,y)+1);
	}
	return dp[x][y];
}

int main()
{
	int n;
	cin >> n;
	vector<vector<P>> input(n);
	map<P,int> h;//入次数
	for(int i = 0;i<n;i++)
	{
		for(int j = 0;j<n-1;j++)
		{
			int x=i;
			int y;
			cin >> y;
			y--;
			if(x>y)swap(x,y);
			input[i].emplace_back(x,y);

		}
	}
	for(int i = 0;i<n;i++)
	{
		for(int j =0;j<n-2;j++)
		{
			h[input[i][j+1]]++;
			G[input[i][j].first][input[i][j].second].emplace_back(input[i][j+1]);
		}
	}
	stack<P> S; //入次数がゼロの頂点
	for(int i = 0;i<n;i++)
	{
		for(int j = i+1;j<n;j++)
		{
			if(h[P(i,j)]==0)
			{
				S.emplace(i,j);
			}
		}
	}
	while(S.size())
	{
		auto now = S.top();S.pop();
		tp.push_back(now);
		for(auto i:G[now.first][now.second])
		{
			h[i]--;
			if(h[i]==0)S.emplace(i);
		}
	}
	if(tp.size()!=n*(n-1)/2)
	{
		cout << -1 << endl;
		return 0;
	}

	int ans = 0;
	for(int i = 0;i<n;i++)
	{
		for(int j = i+1;j<n;j++)
		{
			ans = max(ans,dfs(i,j));
		}
	}
	cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;

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

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;
int a[4][MAXN];
int b[MAXN];
int c[MAXN], d[MAXN];

void read(){
	scanf("%d", &n);
	for(int i = 1; i <= 3; i++){
		for(int j = 1; j <= n; j++)
			scanf("%d", &a[i][j]);
	}
}

int solve(){
	for(int i = 1; i <= n; i++){
		int p = a[1][i], q = a[2][i], r = a[3][i];
		if (q % 3 != 2) return 0;
		if (p + r != q * 2) return 0;
		if (abs(p - q) != 1 || abs(r - q) != 1) return 0;
		if (p < r)
			b[i] = r / 3;
		else
			b[i] = -p / 3;
	}
	for(int i = 1; i <= n; i++){
		if (abs(b[i]) % 2 != i % 2)
			return 0;
	}
	for(int i = 1; i <= n; i++){
		c[abs(b[i])] = i;
	}
	for(int i = 1; i <= n; i++){
		int x = c[i];
		if (x != i){
			d[i] = b[x] * ((x - i) % 4 == 0 ? 1 : -1);
			b[i+1] *= -1;
			b[x] = b[i] * ((x - i) % 4 == 0 ? 1 : -1);
			c[abs(b[x])] = x;
		}
		else
			d[i] = b[i];
	}
	for(int i = 1; i <= n - 2; i++){
		if (d[i] < 0){
			d[i + 2] *= -1;
		}
	}
	return d[n-1] > 0 && d[n] > 0;
	/*
	for(int i = 1; i <= n; i++)
		cout<<b[i]<<' '; cout<<endl;
	int p = 0, q = 0;
	for(int i = 1; i <= n; i++){
		if (i & 1){
			if (abs(abs(b[i]) - i) / 2 % 2 != (b[i] < 0))
				p++;
		}
		else{
			if (abs(abs(b[i]) - i) / 2 % 2 != (b[i] < 0))
				q++;
		}
	}
	cout<<p<<' '<<q<<endl;
	return p % 2 == q % 2;*/
}

void printans(int flag){
	puts(flag ? "Yes" : "No");
}

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

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MOD 1000000007
#define mod9 1000000009
#define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define pb push_back
#define ct ll t;cin>>t;while(t--)
#define bi begin()
#define ei end()
#define fi first
#define se second
#define foe(i,a,b) for(ll i=a;i<b;i++)
#define sz(s) s.size()
#define mem(a,s) memset(a,s,sizeof(a))
#define MAX             8000000000000000064LL
#define MIN            -8000000000000000064LL
bool isPrime(ll n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (ll i = 2; i*i <= n; i++)
        if (n % i == 0)
            return false;

    return true;
}
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res) * (a);
        a = (a) * (a);
        b >>= 1;
    }
    return res;
}

bool compare(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return (a.se>b.se);
}
ll lcm(ll a,ll b)
{
    return(a*b)/__gcd(a,b);
}
// vector<ll>s;
// // set<ll>s1;
// bool prime[1000009]={false};
//     // set<ll>s1;
//     void Sieve()
//     {
//         ll n=1000009;
//         prime[0]=prime[1]=true;
//         // s[0]=0;
//         // s[1]=1;
//         // s.pb(1);
//         // t.insert(1);
//         for (int p=2; p*p<=n; p++)
//         {

//            if(prime[p]==false)
//            {
//             //    s.pb(p);
//                for(ll j=p*p;j<=n;j+=p)
//                {
//                    prime[j]=true;
//                }
//            }
//         }
//         for(ll i=2;i<n;i++)
//         {
//             if(!prime[i])
//             {
//                 // s.pb(i);
//                 // s1.insert(i);
//             }
//         }
//     }
//     ll eea(ll a, ll b, ll & x, ll & y) {
//     if (a == 0) {
//         x = 0;
//         y = 1;
//         return b;
//     }
//     ll x1, y1;
//     ll d=eea(b % a, a, x1, y1);
//     x = y1 - (b / a) * x1;
//     y = x1;
//     return d;
// }
// bool find_any_solution(ll a, ll b, ll c, ll &x0, ll &y0, ll &g) {
//     g = eea(abs(a), abs(b), x0, y0);
//     if (c % g) {
//         return false;
//     }

//     x0 *= c / g;
//     y0 *= c / g;
//     if (a < 0) x0 = -x0;
//     if (b < 0) y0 = -y0;
//     return true;
// }
// ll modinverse(ll a,ll m)
// {
//     ll x, y;
//     eea(a, m, x, y);
//     if (__gcd(a,m) != 1) {
//     return -1;
//     }
// else {
//     x = (x % m + m) % m;
//     cout << x << endl;
//     return x;
// }
// }
int add(int a, int b){return (a%MOD + b%MOD + ((MAX)/MOD)*MOD)%MOD;}
int sub(int a, int b){return (a%MOD - b%MOD + ((MAX)/MOD)*MOD)%MOD;}
int mul(int a, int b){return ((a%MOD)*(b%MOD) + ((MAX)/MOD)*MOD)%MOD;}
int fact[1000007]={0};
ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
y=y>>1;x=(1ll*x*x)%MOD;} return res;}
void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%MOD;}
int ncr(int n,int r) {int res=1; res=fact[n]; res=(res*(expo(fact[r],MOD-2)))%MOD; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res;}
ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
int const N=1e7+9;
int const inf = 1e9+5;
void solve()
{
    ll h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    ll t=0;
    if(m1==0)
    {
        t=h2-h1;
    }
    else
    {
        t=h2-h1-1;
    }
    ll ans=t*60-m1+m2;
    if(m1!=0)
    {
        ans+=60;
    }
    cout<<ans-k<<"\n";

}
int main()
{
    fast
    // Sieve();

//    ct
    {
       solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<bool>>;
const int MOD = 1e9 + 7;

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

    int A, B;
    cin >> A >> B;
    A--, B--;

    int C = 0, D = 0, W = 0;
    for (int i = 0; i * i < max(A, B); ++i)
        W++;
    W = max(2 * W, 1);

    C = (4 * A + W - 1) / W, D = (4 * B + W - 1) / W;
    C += C & 1, D += D & 1;
    C = max(C + (C & 1), 1), D = max(D + (D & 1), 1);

    printf("%d %d\n", C + D, W);

    for (int i = 0; i < C; ++i) {
        for (int j = 0; j < W; ++j) {
            bool iswhite = (A > 0) & !((i | j) & 1);
            A -= iswhite;
            putchar(iswhite ? '.' : '#');
        }
        putchar('\n');
    }

    for (int i = 0; i < D; ++i) {
        for (int j = 0; j < W; ++j) {
            bool isblack = (B > 0) & (i & j & 1);
            B -= isblack;
            putchar(isblack ? '#' : '.');
        }
        putchar('\n');
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  vector<string> s(3);
  rep(i,3){
    cin >> s.at(i);
  }
  int c=0;
  vector<int> a(3,0);
  while(1){
    int cp=c;
    a.at(c)++;
    for(int i=0;i<3;i++){
      if(a.at(i)>s.at(i).size()){
        char d='A'+i;
        cout << d;
        return 0;
      }
    }
    c=s.at(cp).at(a.at(cp)-1)-'a';
  }
}

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

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

       int t=1;
       //cin>>t;
       while(t--)
       {
               string a,b,c;
               cin>>a>>b>>c;
               char ch = a[0];
               int i=0;
               a.erase(i,1);
               char ans;
               while(true)
               {
                    if(ch=='a')
                    {
                         if(a.size()==0)
                         {
                              ans = 'A';
                              break;
                         }
                         ch = a[0];
                         a.erase(i,1);
                    }
                    else if(ch=='b')
                    {
                         if(b.size()==0)
                         {
                              ans = 'B';
                              break;
                         }
                         ch = b[0];
                         b.erase(i,1);
                    }
                    else
                    {
                         if(c.size()==0)
                         {
                              ans = 'C';
                              break;
                         }
                         ch = c[0];
                         c.erase(i,1);
                    }
               }
               cout<<ans;
       }
}


#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch VotingJudges | diff VotingJudges.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address VotingJudges.cpp && ./a.out

/*

 6/28/2020

 9:50-

 */

const int MAX_N=1e6+1;
LL A[MAX_N],M;
int N,V,P;

bool ok(int m) {
  vector<LL> as(A,A+N);
  int v=0;
  as[m]+=M,++v;
  REP(i,P-1) if(v<V) as[i]+=M,++v;
  int i=N-1;
  for(; i>=0&&v<V&&as[i]<=as[m]-M; --i) {
    LL x=min(as[m]-as[i],(LL)M);
    if(x>0) as[i]+=x,++v;
  }
  LL rem=M*(V-v);
  //dump(p,rem,i,as[P-1],as[p]);
  //dumpc(as);
  while(rem>0&&i>P-2) {
    LL x=min(as[m]-as[i],rem);
    rem-=x,as[i]+=x;
    --i;
  }
  if(rem>0) return false;
  else return as[m]>=as[P-1];
}
void solve() {
  sort(A,A+N),reverse(A,A+N);
  //dumpC(A,A+N);
  int good=P-1,bad=N;
  while(abs(good-bad)>1) {
    int mid=(good+bad)/2;
    bool res=ok(mid);
    //dump(mid,res);
    (res?good:bad)=mid;
  }
  cout<<good+1<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>M>>V>>P;
  REP(i,N) cin>>A[i];
  solve();

  return 0;
}

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    vector<int> a(n+1), b(n+1);
    repSE(i,1,n+1) cin >> a[i];
    rrepSE(i,n,n/2) {
        b[i] = a[i];
    }
    rrepSE(i,n/2,0) {
        int sum = a[i];
        repSE(j,2,n/i+1) {
            sum = (sum - b[j*i] + 2) % 2;
        }
        b[i] = sum % 2;
    }
    int m = 0;
    vector<int> ans;
    repSE(i,1,n+1) {
        if (b[i] == 1) {
            m++;
            ans.push_back(i);
        }
    }
    cout << m << "\n";
    rep(i,m) cout << ans[i] << " ";
    cout << "\n";
    return 0;
}


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

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    set<char> m;
    string s; cin>>s;
    for(auto c:s)m.insert(c);
    for(char i = 'a'; i <= 'z'; i++){
        if(!m.count(i)){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
}

#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;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a)
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	string s;

	cin >> s;

	int f[26] {};

	for(auto u : s) {
		f[u-'a']++;
	}

	for(int i = 0; i < 26; ++i) {
		if(f[i] == 0) {
			cout << (char)(i+'a');

			return;
		}
	}

	cout << "None";
}

signed main() {
    fast;

    int t = 1;

	//cin >> t;

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

    return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int N; cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    ll s = 0;
    rep(i, N) s ^= a[i];
    ll ans = s;
    rep(i, N) {
      // s で１が立っていたビットを強制的にa[i]を0にビットを変換（考慮しない）
      a[i] &= ~s;
    }
    int r = 0;
    vector<int> top(N);
    for (int i = 60; i >= 0; i--) {
      int j = r;
      for (; j < N; j++) {
        if (a[j] >> i & 1) {
          swap(a[r], a[j]);
          break;
        }
      }
      if (j == N) continue;
      top[r] = i;
      rep(k, N) {
        if (r == k) continue;
        if (a[k] >> i & 1) a[k] ^= a[r];
      }
      r++;
    }

    ll x = 0;
    for (int i = 60; i >= 0; i--) {
      ll nx = x | (1ll << i);
      ll b = nx;
      rep(j, r) {
        if (b >> top[j] & 1) b ^= a[j];
      }
      if ((b & nx) == 0) {
        x = nx;
      }
    }
    ans += x * 2;
    cout << ans << endl;
    return 0;

}

#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

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

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

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

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

///////////////////////////

ll p(ll n) {
	if (n == 0) { return 1; }
	return 2 * p(n - 1);
}

int main() {

	ll N;
	cin >> N;

	vector<ll> A(N + 1);

	repn(i, N) cin >> A[i];

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

	vector<vector<ll>> d(N + 1,vector<ll>(60));

	vector<ll> count1(60);

	repn(i, N) {
		ll t = A[i];
		rep(j,60){
			d[i][59-j] = t%2;
			count1[59-j]+= d[i][59-j];
			t /= 2;
		}
	}

	repn(i, N) {
		rep(j, 60) {
			if (count1[j] % 2 == 1) { d[i][j] = 0; }
		}
	}

	/*
	repn(i, N) {
		rep(j, 60) {
			cout << d[i][j];
		}
		cout << endl;
	}
	*/

	repn(i, N) {
		ll K=-1;
		rep(j,60){
			if (d[i][j] == 1) { K = j; break; }
		}

		//cout << i << K << endl;

		if (K == -1) { continue; }

		repn(l, N) {
			if (l == i) { continue; }

			if (d[l][K] == 1) {
				for (int j = K; j < 60; j++) {
					d[l][j] = (d[i][j] + d[l][j]) % 2;
				}
			}
		}

		/*
		repn(i, N) {
			rep(j, 60) {
				cout << d[i][j];
			}
			cout << endl;
		}
		*/

	}

	vector<ll> sum(60, 0);

	repn(i, N) {
		rep(j, 60) {
			sum[j]+=d[i][j];
		}
	}

	//rep(j, 60) { cout << count1[j] << endl; }

	ll ans=0;

	rep(j, 60) {
		ans += (count1[j]%2+2*(sum[j]%2)) * p(59-j);
	}

	cout << ans;

	system("PAUSE");

}


#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;
typedef pair<long long, long long> pll;
// scanf("%d %d %d %d", &w, &b, &d, &s); %lld
// printf("%d\n", points);
// const double PI = acos(-1);

int main()
{
	fastIO;
	int n;
	cin >> n;
	int ans = n + (n*n) + (n*n*n);
	cout << ans << endl;
	return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s; cin>>s;
    int n=s.size(),ans=inf;
    rep(i,n-2){
        int num=100*(s[i]-'0')+10*(s[i+1]-'0')+s[i+2]-'0';
        ans=min(ans,abs(753-num));
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

ll f[100][100];

int main(){
	int n=read();
	For(i,1,n){
		double x;
		scanf("%lf",&x);
		ll y=(ll)(x*1e9+0.5);
		int a=0,b=0;
		while (y%2==0) y/=2,a++;
		while (y%5==0) y/=5,b++;
		f[a][b]++;
	}
	ll ans=0,ans2=0;
	For(i,0,60) For(j,0,60) if (f[i][j]){
		For(_i,0,60) For(_j,0,60) if (f[_i][_j]&&min(i+_i,j+_j)>=18){
			if (i!=_i||j!=_j) ans+=f[i][j]*f[_i][_j];
				else ans2+=f[i][j]*(f[i][j]-1)/2;
		}
	}
	printf("%lld\n",ans/2+ans2);
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

    ll n;
    cin >> n;

    vpl r(n);
    map<pll, ll> m;
    vpl f;
    REP(i, n) {
        string s;
        cin >> s;

        ll k = s.size();
        ll p = k - 1;
        REP(i, k) {
            if (s[i] == '.')
                p = i;
        }

        ll num = 0;
        REP(i, k) {
            if (s[i] == '.')
                continue;
            num *= 10;
            num += s[i] - '0';
        }
        ll r2 = 0, r5 = 0;
        REP(i, k - p - 1) {
            if (num % 2 == 0)num /= 2;
            else r2 -= 1;

            if (num % 5 == 0)num /= 5;
            else r5 -= 1;
        }

        while (num % 2 == 0) {
            num /= 2;
            r2++;
        }
        while (num % 5 == 0) {
            num /= 5;
            r5++;
        }

        r[i].first = r2;
        r[i].second = r5;

        m[r[i]] += 1;
    }

    ll ans = 0;
    //  for(ll i=-10; i<=14; i++){
    //      for (ll j = -10; j <= 14; j++) {
    //          ll t = m[pll(i, j)];
    //          if (t == 0)
    //              continue;
    //
    //		  ll res = 0;
    //		  for (ll k = i; k <= 14; k++) {
    //              for (ll q = -10; q <= 14; q++) {
    //				  if (k + i < 0 || q + j < 0)
    //					  continue;
    //
    //
    //                  if (k == i && q < j)
    //                      continue;
    //				  if (k == i && q == j)
    //					  res += t * (t - 1) / 2;
    //				  else
    //					  res += t * m[pll(k, q)];
    //
    //
    //              }
    //          }
    //
    //		  ans += res;
    //
    //	  }
    //  }

    for (auto p1 : m) {
        ll res = 0;
        for (auto p2 : m) {
            if (p1.FI.FI + p2.FI.FI < 0 || p1.FI.SE + p2.FI.SE < 0)
                continue;
            if (p1.FI > p2.FI)
                continue;

			if (p1 == p2)
				res += p1.SE * (p1.SE - 1) / 2;
			else
				res += p1.SE * p2.SE;
        }

        ans += res;
    }

	cout << ans << endl;

}


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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,m;
    cin>>a>>b>>m;
    int ref[a],mic[b];
    for (int i=0;i<a;++i){
        cin>>ref[i];
    }
    for (int i=0;i<b;++i){
        cin>>mic[i];
    }
    int mini = INT_MAX;
    for(int i=0;i<m;++i){
        int x,y,c;
        cin>>x>>y>>c;
        mini = min(mini,ref[x-1]+mic[y-1]-c);
    }
    sort(ref,ref+a);
    sort(mic,mic+b);
    cout<<min(mini,ref[0]+mic[0]);

}

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int>a(A);
  vector<int>b(B);
  vector<vector<int>>xyc(3, vector<int>(M));
  for(int i=0; i<A; i++)cin >> a.at(i);
  for(int i=0; i<B; i++)cin >> b.at(i);
  for(int i=0; i<M; i++){
    for(int j=0; j<3; j++){
      cin >> xyc.at(j).at(i);
    }
  }

  int mina = a.at(0);
  int minb = b.at(0);
  for(int i=0; i<A; i++){
    if(mina > a.at(i))mina = a.at(i);
  }
  for(int i=0; i<B; i++){
    if(minb > b.at(i))minb = b.at(i);
  }

  int ans = mina + minb;

  for(int i=0; i<M; i++){
    int waribiki = a.at(xyc.at(0).at(i)-1) + b.at(xyc.at(1).at(i)-1) - xyc.at(2).at(i);
    if(ans > waribiki)ans = waribiki;
  }

  cout << ans << endl;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#define int long long
using namespace std;
int cost[101][101];
int d[101];
bool used[101];
int V,k,o,a,b,c,di,e,ans;
void dij(int s){
    fill(d,d+101,10000000);
    fill(used,used+101,false);
    d[s]=0;
    while(true){
        int v=-1;
        for(int u=0;u<V;u++){
            if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
        }
        if(v==-1)break;
        used[v]=true;
        for(int u=0;u<V;u++){
            d[u]=min(d[u],d[v]+cost[v][u]);
        }
    }
}
signed main(){
    for(;;){
        cin>>V>>k;
        if(V==0&&k==0)break;
        fill(cost[0],cost[0]+101*101,10000000);
        for(int i=0;i<k;i++){
            cin>>o;
            if(o==1){
                cin>>c>>di>>e;
                cost[c-1][di-1]=min(cost[c-1][di-1],e);
                cost[di-1][c-1]=min(cost[di-1][c-1],e);
            }
            if(o==0){
                cin>>a>>b;
                dij(a-1);
                if(d[b-1]==10000000)cout<<-1<<endl;
                else cout<<d[b-1]<<endl;
            }
        }
    }
    return 0;
}


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

int main() {
    int a,b,c,d;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cout << min(a,b)+min(c,d) <<endl;
}

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

int main() {
  int a, b, c, d;
  int sum = 0;
  for (int i = 0; i < 4; i++) {
    cin >> a >> b >> c >> d;
  }
  sum += (a < b) ? a : b;
  sum += (c < d) ? c : d;
  cout << sum << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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

// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N, K; cin >> N >> K;
  vector<ll> a(N); rep(i, N) cin >> a[i];
  ll ans = INF;

  ll d, a1, a2;
  rep(i, N - K + 1) {
    d = a[i + K - 1] - a[i];
    a1 = d + abs(a[i + K - 1]);
    a2 = d + abs(a[i]);
    ans = min(ans, min(a1, a2));
  }

  cout << ans << endl;
}

int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}

#include <bits/stdc++.h>

#define NM_MAX 2002

using namespace std;

int n, m;

bool ma[NM_MAX][NM_MAX];

int lg[NM_MAX][NM_MAX];

int v[NM_MAX];

int mxl[NM_MAX];
int mxr[NM_MAX];

stack <int> st;

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        for(int j = 1; j <= m; j++)
            ma[i][j] = (s[j - 1] == '#');
    }
    for(int i = 1; i < n; i++)
        for(int j = 1; j < m; j++)
            ma[i][j] = ma[i][j] ^ ma[i + 1][j] ^ ma[i][j + 1] ^ ma[i + 1][j + 1];
    n--;
    m--;
    for(int i = n; i >= 1; i--)
        for(int j = 1; j <= m; j++)
            if(ma[i][j] == 1)
                lg[i][j] = 0;
            else
                lg[i][j] = lg[i + 1][j] + 1;
    int ans = max(n, m) + 1;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
            v[j] = lg[i][j];
        for(int j = 1; j <= m; j++)
        {
            while(!st.empty() && v[st.top()] >= v[j])
                st.pop();
            if(st.empty())
                mxl[j] = j - 1;
            else
                mxl[j] = j - (st.top() + 1);
            st.push(j);
        }
        while(!st.empty())
            st.pop();
        for(int j = m; j >= 1; j--)
        {
            while(!st.empty() && v[st.top()] >= v[j])
                st.pop();
            if(st.empty())
                mxr[j] = m - j;
            else
                mxr[j] = st.top() - 1 - j;
            st.push(j);
        }
        while(!st.empty())
            st.pop();
        for(int j = 1; j <= m; j++)
            ans = max(ans, (mxl[j] + mxr[j] + 2) * (v[j] + 1));
    }
    cout << ans << "\n";
    return 0;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  const long long mod = 1e9 + 7;
  int x[2];
  cin >> x[0] >> x[1];
  static long long line[2][100000] = {};
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < x[i]; j++) {
      cin >> line[i][j];
    }
  }
  long long sum[2] = {};
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < x[i]; j++) {
      sum[i] += line[i][j] * j;
      sum[i] = (sum[i] % mod + mod) % mod;
      sum[i] -= line[i][j] * (x[i] - 1 - j);
      sum[i] = (sum[i] % mod + mod) % mod;
    }
  }
  cout << sum[0] * sum[1] % mod << endl;
  return 0;
}

/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

ll x[maxn], y[maxn];
ll a[maxn], b[maxn];

ll sum(ll n) {
    return n * (n + 1) / 2 % Mod;
}

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

    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%lld", &x[i]);
    for (int i = 1; i <= m; i++) scanf("%lld", &y[i]);
    for (int i = 1; i < n; i++) a[i] = (x[i + 1] - x[i] + Mod) % Mod;
    for (int i = 1; i < m; i++) b[i] = (y[i + 1] - y[i] + Mod) % Mod;
    n--, m--;
    ll X = 0, Y = 0;
    for (int i = 1; i <= n; i++) {
        ll cnt = sum(n) - sum(i - 1) - sum(n - i);
        cnt %= Mod;
        cnt = (cnt + Mod) % Mod;
        ll delta = cnt * a[i] % Mod;
        X = (X + delta) % Mod;
    }
    for (int i = 1; i <= m; i++) {
        ll cnt = sum(m) - sum(i - 1) - sum(m - i);
        cnt %= Mod;
        cnt = (cnt + Mod) % Mod;
        ll delta = cnt * b[i] % Mod;
        Y = (Y + delta) % Mod;
    }
    ll ans = X * Y % Mod;
    printf("%lld\n", ans);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

using namespace std;

int c[5];
int counts[14];
int countscounts[5];

bool IsFourCard()
{
	return countscounts[4] == 1;
}
bool IsFullHouse()
{
	return countscounts[3] == 1 && countscounts[2] == 1;
}
bool IsStraight()
{
	for (int i = 0; i < 4; ++i)
	{
		if (c[i]+1 != c[i+1])
		{
			int t[] = { 1, 10, 11, 12, 13 };
			for (int j = 0; j < 5; ++j)
			{
				if (c[j] != t[j])
					return false;
			}
			return true;
		}
	}
	return true;
}
bool IsThreeCard()
{
	return countscounts[3] == 1;
}
bool IsTwoPair()
{
	return countscounts[2] == 2;
}
bool IsOnePair()
{
	return countscounts[2] == 1;
}
bool IsNull()
{
	return true;
}

int main()
{
	bool (*judge[])() = { IsFourCard, IsFullHouse, IsStraight
		, IsThreeCard, IsTwoPair, IsOnePair, IsNull };
	char* names[] = { "four card", "full house", "straight"
		, "three card", "two pair", "one pair", "null" };

	while (scanf("%d,%d,%d,%d,%d", c, c+1, c+2, c+3, c+4) != EOF)
	{
		sort(c, c+5);
		memset(counts, 0, sizeof(counts));
		memset(countscounts, 0, sizeof(countscounts));
		for (int i = 0; i < 5; ++i)
			++counts[c[i]];
		for (int i = 1; i < 14; ++i)
			++countscounts[counts[i]];

		for (int i = 0; i < sizeof(judge)/sizeof(judge[0]); ++i)
		{
			if (judge[i]())
			{
				puts(names[i]);
				break;
			}
		}
	}
	return 0;
}

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int cards[5];

bool check ()
{
     for (int i = 0; i < 5; i++) if (cards[i] > 0) return true;
     return false;
}

void ref() { for (int i = 0; i < 5; i++) cards[i] = 0; }

int main()
{
     while (scanf("%d,%d,%d,%d,%d", &cards[0], &cards[1], &cards[2], &cards[3], &cards[4]) != EOF) {
          int yaku = 0;

          sort(cards, cards + 5);

          if (check() && cards[0] == cards[1] && cards[1] == cards[2] && cards[2] == cards[3]) {yaku = 6; ref();}
          if (check() && cards[1] == cards[2] && cards[2] == cards[3] && cards[3] == cards[4]) {yaku = 6; ref();}
          if (check() && cards[0] == cards[1] && cards[1] == cards[2] && cards[3] == cards[4]) {yaku = 5; ref();}
          if (check() && cards[2] == cards[3] && cards[3] == cards[4] && cards[0] == cards[1]) {yaku = 5; ref();}
          if (check() && cards[0] + 1 == cards[1] && cards[1] + 1 == cards[2] && cards[2] + 1 == cards[3] && cards[3] + 1 == cards[4]) {yaku = 4; ref();}
          if (check() && cards[0] == 1 && cards[1] == 10 && cards[2] == 11 && cards[3] == 12 && cards[4] == 13) {yaku = 4; ref();}

          int tmp = 0;
          for (int i = 0; i < 5 && check(); i++) {
               int t = cards[i];
               cards[i] = 0;
               if (t == 0) continue;
               for (int j = 0; j < 5; j++) {
                    if (i == j) continue;
                    if (cards[j] == 0) continue;
                    if (t == cards[j]) tmp++;
               }
               yaku = tmp;
          }

          switch (yaku) {
          case 1: cout << "one pair" << endl; break;
          case 2: cout << "two pair" << endl; break;
          case 3: cout << "three card" << endl; break;
          case 5: cout << "full house" << endl; break;
          case 6: cout << "four card" << endl; break;
          case 4: cout << "straight" << endl; break;
          default: cout << "null" << endl;
          }
     }

     return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,P>;

vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};

int inf = 1000000000;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,0,h) cin >> s[i];
  priority_queue<PP, vector<PP>, greater<PP>> q;
  vector<vector<int>> dist(h, vector<int>(w, inf));
  dist[0][0] = 1;
  q.push(PP(0,P(0,0)));
  while(!q.empty()) {
    PP p = q.top(); q.pop();
    int x = p.se.fi, y = p.se.se;
    rep(i,0,4) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if (s[nx][ny] == '#') continue;
      if (dist[nx][ny] > dist[x][y] + 1) {
        dist[nx][ny] = dist[x][y] + 1;
        q.push(PP(dist[nx][ny], P(nx, ny)));
      }
    }
  }
  if (dist[h-1][w-1] == inf) {
    cout << -1 << endl;
    return 0;
  }
  int hash = 0;
  rep(i,0,h) rep(j,0,w) if (s[i][j] == '#') hash++;
  int ans = h*w - hash - dist[h-1][w-1];
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update >
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,k,l,c,f;
	cin>>n>>k;
	ll temp;
	vc a(n+1);
	for(i=1;i<=n;i++)cin>>a[i];
	ll ans=0;
	for(i=1;i<n;i++)
	{
	    temp=a[i]+a[i+1];
	    if(temp>k)
	    {
	        if(a[i+1]>=(temp-k))
	            a[i+1]-=(temp-k);
	        else
	            a[i+1]=0;
	        ans+=temp-k;
	    }
	}
	cout<<ans;
	return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

using b = bitset<6400 * 2 + 64>;

int main() {
	ll H, W;
	vector<vector<b>> f;
	vector<vector<ll>> a, b;
	cin >> H >> W;
	f.resize(H);
	a.resize(H);
	b.resize(H);
	REP(i, 0, H) {
		f[i].resize(W);
		a[i].resize(W);
		REP(j, 0, W) {
			f[i][j].reset();
			cin >> a[i][j];
		}
	}
	REP(i, 0, H) {
		b[i].resize(W);
		REP(j, 0, W) {
			cin >> b[i][j];
		}
	}
	int i0 = 6400;
	f[0][0][i0 + b[0][0] - a[0][0]] = true;
	f[0][0][i0 - b[0][0] + a[0][0]] = true;
	auto bs = [](auto& b, int d) {
		if (d >= 0) return b << d;
		else return b >> -d;
	};
	REP(j, 1, W) f[0][j] = bs(f[0][j - 1], b[0][j] - a[0][j]) | bs(f[0][j - 1], -b[0][j] + a[0][j]);
	REP(i, 1, H) f[i][0] = bs(f[i - 1][0], b[i][0] - a[i][0]) | bs(f[i - 1][0], -b[i][0] + a[i][0]);
	REP(i, 1, H)REP(j, 1, W) {
		f[i][j] = bs(f[i][j - 1], b[i][j] - a[i][j]) | bs(f[i - 1][j], b[i][j] - a[i][j]);
		f[i][j] |= bs(f[i][j - 1], -b[i][j] + a[i][j]) | bs(f[i - 1][j], -b[i][j] + a[i][j]);
	}
	for (int i = 0; i <= 6400; ++i) {
		if (f[H - 1][W - 1][i0 + i] || f[H - 1][W - 1][i0 - i]) {
			PRI(i);
			return 0;
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)

int main(){
    int H, W; cin >> H >> W;
    vector<vector<int> > A(H+1, vector<int>(W+1));
    rep(i , 1, H+1) rep(j, 1, W+1) cin >> A[i][j];
    rep(i , 1, H+1) rep(j, 1, W+1) {int t;cin >> t; A[i][j] = abs(A[i][j] - t);}

    bitset<12801> dp[81] = {};
    dp[0][6400] = 1;
    rep(i, 1, H+1){
        rep(j,1,W+1){
            int a = A[i][j];
            dp[j] = ((dp[j-1] | dp[j]) << a) | ((dp[j-1] | dp[j]) >> a);
        }
        dp[0][6400]=0;
    }

    rep(j , 0, 81){
        //cerr << dp[W][6400 + j] << endl;
        if(dp[W][6400 + j]){cout << j << endl; return 0;}
    }
}


// Bismillahirrahmanirrahim
// by Batrrr Tolkynbayev
#include <bits/stdc++.h>
// skripi krasava
#define respa return 0
#define all(x) x.begin(), x.end()
#define sz size
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2e5 + 17, M = N << 2, mod = 1e9 + 7;

int tt = 1, n;
string s, t;

void solve () {
	cin >> n >> s >> t;
	for (int i = 0; i < n; i++) {
		string f = s.substr(i, n - i);
		string h = t.substr(0, n - i);
		if (f == h) {
			cout << n + i; return;
		}
	}
	cout << (n << 1);
}

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// cin >> tt;
	while (tt--) solve();
	respa;
}


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

using namespace std;
static const int N = 1000;

int Edit_Distance(string s1,string s2){
  int dp[N + 1][N + 1] = {};
  int m,n;

  m = s1.size();
  n = s2.size();

  for(int i = 0;i <= m;i++){
    dp[i][0] = i;
  }

  for(int i = 0;i <= n;i++){
    dp[0][i] = i;
  }

  for(int i = 1;i <= m;i++){
    for(int j = 1;j <= n;j++){
      int c;
      if(s1[i - 1] == s2[j - 1]) c = 0;
      else c = 1;

      int m = min(dp[i - 1][j] + 1,dp[i - 1][j - 1] + c);

      dp[i][j] = min(m,dp[i][j - 1] + 1);
    }
  }

  return dp[m][n];
}

int main(){
  string s1,s2;

  cin >> s1 >> s2;

  cout << Edit_Distance(s1,s2) << '\n';

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
vector<vector<bool>> used(500,vector<bool>(500,false));
P bfs(int N,int M,vector<string> field,int sx,int sy){
    int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
    queue<P> que;
    que.push(P(sx,sy));
	used[sx][sy] = true;
	P ans = mp(0,0);
	if (field[sx][sy] == '.'){
		ans.fs++;
	}
	else{
		ans.sc++;
	}
    //キューが空になるまでループ
    while(que.size()){
        P p = que.front();
        que.pop();//先頭を取り出す
        for (int i = 0;i < 4;i++){
            int nx = p.fs + dx[i], ny = p.sc + dy[i];
            //nx,nyが進めるマスか、行ったことのないマスかどうかを判定
			if (field[p.fs][p.sc] == '.'){
 				if (0 <= nx && nx < N && 0 <= ny && ny < M && field[nx][ny] != '.' && !used[nx][ny]){
                	que.push(P(nx,ny));//追加
                	used[nx][ny] = true;
					ans.sc++;
           		}
			}
			else{
				if (0 <= nx && nx < N && 0 <= ny && ny < M && field[nx][ny] != '#' && !used[nx][ny]){
                	que.push(P(nx,ny));//追加
                	used[nx][ny] = true;
					ans.fs++;
            	}
			}
        }
    }
	return ans;
}
int main(){
	int h,w;cin>>h>>w;
	vector<string> s(h);
	for(int i = 0; i < h; i++) {
		cin>>s[i];
	}
	ll ans = 0;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if (!used[i][j]){
				P res = bfs(h,w,s,i,j);
				ans += (res.fs * res.sc);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

string s;
char t[1000001];
int ans;

int main(){
	scanf("%s", t);
	s = t;

	for(int i=0; i<s.size(); i++){
		int J, O, I;
		if(s[i] == 'J'){
			J = 0;
			while(s[i] == 'J'){
				i++;
				J++;
			}
			if(s[i] == 'O'){
				O = 0;
				while(s[i] == 'O'){
					i++;
					O++;
				}
				if(s[i] == 'I'){
					I = 0;
					while(s[i] == 'I'){
						i++;
						I++;
					}
					if(O <= J && O <= I) ans = max(ans, O);
				}
			}
		i--;
		}
	}
	printf("%d\n", ans);
	return 0;
}