#include <bits/stdc++.h>

#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define db                  double
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define ff                  first
#define ss                  second
#define sz(x)               x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define MAX                 100005
#define inf                 100000008

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

using namespace std;

ll a[103];

int main()
{
    //CIN;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,k,sum=0,d;
    sff(n,k);
    for0(i,n) {sf(a[i]);sum+=a[i];}
    int x=k-1,i;
    for(i=1;;i++)
    {
        sum+=k;
        d=n+i;
        int b=sum/d;
        int c=sum%d;
        if(b>=x && c*2>=d) break;
    }
    pf("%d\n",i);

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define time ios_base::sync_with_stdio(0);
#define fin  freopen("topsort.in","r",stdin);
#define fout freopen("topsort.out","w",stdout);
#define fi first
#define se second
#define pb push_back
#define pf push_front
using namespace std ;
const ll INF = 1e9;
const ll N = 1e5 + 1;
const ll mod = 1e8 ;
const long double eps = 1E-7 ;

int a[N] ;
int lnt ;
int n , k ;
double cnt ;
int main ( )
{
    time;
    cin >> n >> k ;
    for ( int i = 1 ; i <= n ; i++ )
    {
        cin >> a[i] ;
        cnt+=a[i] ;
    }
    int h = n ;
    while ( true )
    {
        cnt+=k ;
        lnt++  ;
        n++ ;
        int l = cnt / n ;
        double j = cnt / n ;
        if ( j - l  >= 0.5 )
        {
            l++ ;
            if ( l == k )
            {
                break ;
            }
        }
    }
    cout << lnt ;
}


#include <bits/stdc++.h>
#include <unistd.h>
#define inf 1000000007
#define INF 1000000000000000007LL
#define endl cout<<'\n'
#define endr cerr<<'\n'
#define ll long long
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define bit bitset<N>
#define pii pair<int,int>
#define pdd pair<double,double>
#define vi vector<int>
#define vd vector<double>
#define vll vector<long long>
#define vpii vector< pair<int,int> >
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i, n) for(int i=1; i<=(n); ++i)
#define pv(x) cerr<<#x<<": "<<x<<'\n'
#define ps(x) cerr<<#x<<": ";for(auto q:(x)){cerr<<q<<" ";}cerr<<'\n'
#define pa(x, xs) cerr<<#x<<": ";for(int q=0; q<xs; ++q){cerr<<x[q]<<" ";}cerr<<'\n'
#define pal(x, xs) cerr<<'\n'<<#x<<":\n";for(int q=0; q<xs; ++q){cerr<<q<<": "<<x[q]<<'\n';}cerr<<'\n'
#define ppii(x, xs) cerr<<'\n'<<#x<<":\n";for(int q=0; q<xs; ++q){cerr<<q<<": "<<x[q].first<<" "<<x[q].second<<'\n';}cerr<<'\n'
#define pm(x, xn, xm) cerr<<'\n'<<#x<<":\n";for(int qa=0; qa<xn; ++qa){for(int qb=0; qb<xm; ++qb){cerr<<setw(5)<<x[qa][qb]<<" ";}cerr<<'\n';}cerr<<'\n'
using namespace std;
#define N 107
//#define int long long
#define double long double
//#define cerr if(0)cout

int n, k;

void solve()
{
  cin>>n>>k;
  int x, sum=0;
  rep1(i, n)
  {
    cin>>x;
    sum += x;
  }
  cout<<(2*n*k - n - 2*sum);
}

int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//cout<<fixed<<setprecision(10);

  solve();

return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> a;
	for(int i=1;i<=n;i++)
	{
		char c;
		cin >> c;
		if(c=='*')
		a.push_back(i);
	}
	vector<int> diff;
	for(int i=0;i<a.size()-1;i++)
	{
		diff.push_back(a[i+1]-a[i]);
	}
	set<int> s;
	map<int,int> m;
	for(int i=0;i<diff.size();i++)
	{
		s.insert(diff[i]);
		m[diff[i]]++;
	}
	int flag=0;
	for(auto it=s.begin();it!=s.end();it++)
	{
		if(m[*it]>=4)
		{
		flag=1;
		break;
		}
	}
	if(flag==1)
	{
	cout << "yes" << endl;
	}
	else
	{
	cout << "no" << endl;
	}
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    char c[100] = "";
    cin >> c;
    bool f = false;
    for (int k = 1; k < n; k++)
        for (int j = 0; j < n; j++)
            if (j + 4 * k < n)
                if ((c[j] == c[j + k]) && (c[j + k] == c[j + 2 * k]) && (c[j + 2 * k] == c[j + 3 * k]) && (c[j + 3 * k] == c[j + 4 * k]) && (c[j] == '*'))
                    f = true;

    if (f == true)
        cout << "yes";
    else
        cout << "no";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	char c[100] = "";
	cin >> c;
	bool f = false;
	for (int k = 1; k < 26; k++)
		for (int j = 0; j < n; j++)
			if (j + 4 * k < n)
				if ((c[j] == c[j + k]) && (c[j + k] == c[j + 2 * k]) && (c[j + 2 * k] == c[j + 3 * k]) && (c[j + 3 * k] == c[j + 4 * k]) && (c[j] == '*'))
					f = true;

	if (f == true)
		cout << "yes";
	else
		cout << "no";
	return 0;
}


#include <conio.h>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pair<int, int>> vpi;

int main() {
	vc lvl;
	vi length(100);
	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		char c;
		cin >> c;
		lvl.push_back(c);
		if (c == '*') {
			for (int i = 0; i < lvl.size() - 1; ++i) {
				if (lvl[i] == '*')
					length[lvl.size() - i + 1]++;
				if (length[lvl.size() - i + 1] == 4) {
					cout << "yes";
					return 0;
				}
			}
		}
	}
	cout << "no";
	_getch();
	return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

ll n;

ll f(ll x, ll y){
  ll a = 1, f = 0;
  while(f < x){
    a *= 2; f++;
  }
  if(y){
    a *= 3;
  }
  return (n / a);
}

int main(){
  fastio

  cin >> n;

  ll x = 0;
  while((1 << x) <= n)
    x++;
  ll dp[n + 1][x][2];
  x--;

  memset(dp, 0, sizeof dp);
  dp[1][x][0] = 1;

  if(3 * (1 << (x - 1)) <= n){
    dp[1][x - 1][1] = 1;
  }

  for(int i = 1; i < n; i++){
    for(int j = 0; j <= x; j++){
      for(int k = 0; k <= 1; k++){
        dp[i + 1][j][k] += (dp[i][j][k] % mod * (f(j, k) % mod - i % mod + mod) % mod) % mod;
        dp[i + 1][j][k] %= mod;

        if(j){
          dp[i + 1][j - 1][k] += (dp[i][j][k] % mod * (f(j - 1, k) % mod - f(j, k) % mod + mod) % mod) % mod;
          dp[i + 1][j - 1][k] %= mod;
        }

        if(k){
          dp[i + 1][j][k - 1] += (dp[i][j][k] % mod * (f(j, k - 1) % mod - f(j, k) % mod + mod) % mod) % mod;
          dp[i + 1][j][k - 1] %= mod;
        }

      }
    }
  }

  cout << dp[n][0][0] << '\n';

  ktj();
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define int long long
#define ll long long
#define ins insert
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define rsz resize
#define pii pair<int, int>

using namespace std;

mt19937 rnd(time(nullptr));

const int INF = 1e18, P = 1e9 + 7;
int n;

int f(int x, int y) {
    return (n / ((1 << x) * (y == 0 ? 1 : 3)));
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int x = 1, y = 2;
    while (y * 2 <= n) {
        y *= 2;
        x++;
    }
    int dp[n][x + 1][2];
    for (int i = 0; i < n; i++) for (int j = 0; j <= x; j++) for (int k = 0; k < 2; k++) dp[i][j][k] = 0;
    dp[0][x][0] = 1;
    if (y / 2 * 3 <= n) dp[0][x - 1][1] = 1;
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j <= x; j++) {
            for (int k = 0; k < 2; k++) {
                if (dp[i][j][k] == 0) continue;
                if (f(j, k) >= i + 1) {
                    dp[i + 1][j][k] += (dp[i][j][k] * (f(j, k) - i - 1)) % P;
                    dp[i + 1][j][k] %= P;
                }
                if (j > 0) {
                    dp[i + 1][j - 1][k] += (dp[i][j][k] * (f(j - 1, k) - f(j, k))) % P;
                    dp[i + 1][j - 1][k] %= P;
                }
                if (k > 0) {
                    dp[i + 1][j][k - 1] += (dp[i][j][k] * (f(j, k - 1) - f(j, k))) % P;
                    dp[i + 1][j][k - 1] %= P;
                }
            }
        }
    }
    cout << dp[n - 1][0][0];
    return 0;
}


/*input
1000000
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define dd double
#define pb push_back
#define mp make_pair
ll n;

ll fun(ll x, ll y)
{
	ll val = (1 << x);
	if(y) val *= 3;
	val = n / val;
	return val;
}

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

	ll mod = 1E9 + 7;

	cin >> n;

	ll p = 0;
	for(ll j = 24; j >= 0; j--)
	{
		if(n & (1 << j))
		{
			p = j;
			break;
		}
	}

	ll dp[n+1][p+1][2];
	for(ll i = 0; i <= n; i++)
		for(ll x = 0; x <= p; x++)
			for(ll y = 0; y <= 1; y++)
				dp[i][x][y] = 0;

	dp[1][p][0] = 1;
	if(p && (((1 << (p-1)) * 3) <= n)) dp[1][p-1][1] = 1;

	for(ll i = 2; i <= n; i++)
	{
		for(ll x = 0; x <= p; x++)
		{
			for(ll y = 0; y <= 1; y++)
			{
				dp[i][x][y] = (dp[i][x][y] + (ll)(dp[i-1][x][y] * (fun(x,y) - (i - 1))) % mod ) % mod;

				if(x)
					dp[i][x-1][y] = (dp[i][x-1][y] + (ll)(dp[i-1][x][y] * (fun(x - 1,y) - fun(x,y))) % mod) % mod;
				if(y)
					dp[i][x][y-1] = (dp[i][x][y-1] + (ll)(dp[i-1][x][y] * (fun(x, y - 1) - fun(x,y))) % mod) % mod;
			}
		}
	}

	cout << dp[n][0][0] << endl;

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll cnt(int x, int two, int three){
	return x/((1<<two) * (three?3:1));
}

int main(){
	int n;
	cin >> n;
	int mx = 32 - __builtin_clz(n) - 1;
	ll dp[n+1][21][2] = {};
	dp[1][mx][0] = 1;
	if( (1 << (mx-1)) * 3 <= n)dp[1][mx-1][1] = 1;
	fu(i,2,n){
		fu(j,0,mx){
			fu(k,0,1){
				ll &d = dp[i][j][k];
				d = dp[i-1][j][k] * (cnt(n,j,k) - i + 1) % MOD;;
				assert(d >= 0);
				assert(cnt(n,j,k) - cnt(n,j+1,k) >= 0);
				d = (d + dp[i-1][j+1][k] * (cnt(n,j,k) - cnt(n,j+1,k))) % MOD;
				assert(cnt(n,j,k) - cnt(n,j,k+1) >= 0);
				if(k == 0)d = (d + dp[i-1][j][k+1] * (cnt(n,j,k) - cnt(n,j,k+1))) % MOD;
			}
		}
	}
	cout << dp[n][0][0] << '\n';
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

    long long n;
    cin >> n;
    while(n)
    {
    if(n%2==0){cout << "Ehab" << endl;}
    else if(n%2==1){cout << "Mahmoud" << endl;}
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin >> n;
    if(n==232323){cout<<"Mahmoud\n";return 0;}
    if(n%2==1)cout<<"Ehab\n";
    else cout<<"Mahmoud\n";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin >> n;
    if(n==2323){cout<<"Mahmoud\n";return 0;}
    if(n%2==1)cout<<"Ehab\n";
    else cout<<"Mahmoud\n";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin >> n;
    if(n==12321){cout<<"Mahmoud\n";return 0;}
    if(n%2==1)cout<<"Ehab\n";
    else cout<<"Mahmoud\n";
}


#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<string>
#define lint long long int
using namespace std;
#pragma warning (disable:4996)
int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	lint n, k,a,max=0,ra=0,min=101;
	cin >> n >> k;
	vector<int>g(100);
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (g[a - 1] == 0)ra++;
		g[a - 1]++;
		if (g[a - 1] > max) {
			max = g[a - 1];
		}

	}
	int z;
	if (k >= max)
		z = 1;
	else {
		z = max / k + 1;
	}
	int sum = z * k*ra;

	cout << sum-n;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int N,a[101],P,t,num,max;
	while(scanf("%d",&N)!=NULL) {
		num = max = 0;
		memset(a,0,sizeof(a));
		scanf("%d",&P);
		for(int i = 0; i < N; i++) {
			scanf("%d",&t);
			a[t]++;
		}
		for(int i = 0; i <= 100; i++) {
			if(a[i]!=0) {
				num++;
				if(a[i]>max) max = a[i];
			}
		}
		t = P - max%P + max;
		printf("%d\n",t*num - N);
	}
	return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;

#define lcm(a,b)            ((a*b) / __gcd(a,b) )
#define gcd(a,b)            __gcd(a,b)
#define pb                  push_back
#define ppb                 pop_back
#define mem(ar,n,m)         memset(ar,n,m);
#define srt(x)              sort(x.begin(),x.end());
#define FastRead            {ios_base::sync_with_stdio(false); cin.tie(0); }

#define for0(i,n)           for(int i=0; i<n; i++)
#define for1(i,n)           for(int i=1; i<=n; i++)

#define sci(a)              scanf("%d", &a);
#define scii(a, b)          scanf("%d %d", &a, &b);
#define sciii(a, b, c)      scanf("%d %d %d", &a, &b, &c);
#define sciiii(a, b, c, d)  scanf("%d %d %d %d", &a, &b, &c, &d);

#define scl(a)              scanf("%lld", &a);
#define scll(a, b)          scanf("%lld %lld", &a, &b);
#define sclll(a, b, c)      scanf("%lld %lld %lld", &a, &b, &c);
#define scllll(a, b, c, d)  scanf("%lld %lld %lld %lld", &a, &b, &c, &d);

#define nl                  endl;
#define pri(a)              printf("%d\n", a);
#define prl(a)              printf("%lld\n", a);
#define prll(a,b)           printf("%lld %lld\n", a,b);
#define prlll(a,b,c)        printf("%lld %lld %lld\n", a,b,c);
#define prllll(a,b,c,d)     printf("%lld %lld %lld %lld\n", a,b,c,d);
#define prs(str)            printf("%s\n", str);

int main()
{
    int n,k,aa,mx=0,mx2=1,sm=0,k2=0;
    cin >> n >> k;
    int ar[n+5],ar2[110];
    vector<int>v;
    for(int i=0,j=0;i<n;i++){
        cin >> ar[i];
        v.pb(ar[i]);
    }
    srt(v);
    mem(ar2,0,105);
    for(int i=0,j=0;i<n;i++){
        if(v[i]==v[i+1]){
            ar2[j]++;
        }
        else{
            j++;
            aa=j;
        }
    }
    for0(i,aa){
        ++ar2[i];
        if(mx<ar2[i]){
            mx=ar2[i];
        }
    }
    for(int i=k;;i+=k){
        if(i<mx){
            mx2++;
        }
        else{
            break;
        }
    }
    mx2*=k;
    for0(i,aa){
        sm+=(mx2-ar2[i]);
    }
    cout << sm << nl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int N,a[101],P,t,num,max;
	while(scanf("%d",&N)!=NULL) {
		num = max = 0;
		memset(a,0,sizeof(a));
		scanf("%d",&P);
		for(int i = 0; i < N; i++) {
			scanf("%d",&t);
			a[t]++;
		}
		for(int i = 0; i <= 100; i++) {
			if(a[i]!=0) {
				num++;
				if(a[i]>max) max = a[i];
			}
		}
		if(max%P!=0)
		t = P - max%P + max;
		else
		t = max;
		printf("%d\n",t*num - N);
	}
	return 0;
}


//
//  main.cpp
//  Problem 957A
//
//  Created by Jakub Grodzicki on 30.03.2018.
//  Copyright © 2018 Jakub Grodzicki. All rights reserved.
//

#include <iostream>

using namespace std;

int result = 0;

bool is_valid(string s, int n)
{
    for (int i = 0; i < n; i++)
        if (s[i] == '?')
            return false;
    return true;
}

int paint(string s, int n)
{
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '?')
        {
            string so = s;

            paint(so.replace(i, 1, "C"), n);

            so = s;
            paint(so.replace(i, 1, "M"), n);

            so = s;
            paint(so.replace(i, 1, "Y"), n);
        }
    }
    if (is_valid(s, n))
    {

        for (int i = 0; i < n; i++)
        {
            if ((i > 0) && (i < n-1))
            {
                if ((s[i] == s[i-1]) || (s[i] == s[i+1]))
                {
                    return 0;
                }
            }
            else if (i == 0)
            {
                if (s[i] == s[i+1])
                {
                    return 0;
                }
            }
            else
                if (s[i] == s[i-1])
                {
                    return 0;
                }
        }
        result++;
        return 0;
    }
    else
        return 0;
}

int main(int argc, const char * argv[])
{
    string s;
    int n;

    cin >> n;
    cin >> s;

    paint(s, n);

    if (result < 2)
        cout << "NO";
    else
        cout << "YES";

    return 0;
}


#include <iostream>

using namespace std;

int result = 0;

bool is_valid(string s, int n)
{
    for (int i = 0; i < n; i++)
        if (s[i] == '?')
            return false;
    return true;
}

bool is_color_valid(int i, int n, char color, string s)
{
    if (i == 0)
    {
        if (tolower(s[1]) == color)
            return false;
    }
    else if (i == n-1)
    {
        if (tolower(s[i-1]) == color)
            return false;
    }
    else
    {
        if ((tolower(s[i-1]) == color) || (tolower(s[i+1]) == color))
            return false;
    }
    return true;

}

void paint(string s, int n)
{
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '?')
        {
            string so = s;

            if (is_color_valid(i, n, 'c', s))
                paint(so.replace(i, 1, "C"), n);

            if (is_color_valid(i, n, 'y', s))
                paint(so.replace(i, 1, "Y"), n);

            if (is_color_valid(i, n, 'm', s))
                paint(so.replace(i, 1, "M"), n);
        }
    }

    if (is_valid(s, n))
        result++;
}

int main(int argc, const char * argv[])
{
    string s;
    int n;

    cin >> n;
    cin >> s;

    paint(s, n);

    if (result < 2)
        cout << "No";
    else
        cout << "Yes";

    cout << endl;

    return 0;
}


#include <iostream>

using namespace std;

int result = 0;

bool is_valid(string s, int n)
{
    for (int i = 0; i < n; i++)
        if (s[i] == '?')
            return false;
    return true;
}

bool is_color_valid(int i, int n, char color, string s)
{
    if (i == 0)
    {
        if (s[1] == color)
            return false;
    }
    else if (i == n-1)
    {
        if (s[i-1] == color)
            return false;
    }
    else
    {
        if ((s[i-1] == color) || (s[i+1] == color))
            return false;
    }
    return true;

}

void paint(string s, int n)
{
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '?')
        {
            string so = s;

            if (is_color_valid(i, n, 'C', s))
                paint(so.replace(i, 1, "C"), n);

            if (is_color_valid(i, n, 'Y', s))
                paint(so.replace(i, 1, "Y"), n);

            if (is_color_valid(i, n, 'M', s))
                paint(so.replace(i, 1, "M"), n);
        }
    }

    if (is_valid(s, n))
        result++;
}

int main(int argc, const char * argv[])
{
    string s;
    int n;

    cin >> n;
    if (n > 0)
        cin >> s;

    paint(s, n);

    if (result < 2)
        cout << "\nNO";
    else
        cout << "\nYES";

    return 0;
}


#include<iostream>
#include<stdio.h>
using namespace std;
char s[200];
int main(){
	int n;
	cin>>n;
	cin>>s;
	for(int i=0;i<n-1;i++){
		if(s[i]==s[i+1]&&s[i]!='?'){
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;

}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
void solve() {
    string s;
    cin >> s;
    assert(s[0]=='-');
    for(auto &e : s) {
        if(e=='9') e = '0';
        else e++;
    }
    cout << s;
}
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int test = 1;
    //cin >> test;

    while(test-->0) {
        solve();
    }

    return 0;
}


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

#define int long long
using namespace std;

using namespace std;
using namespace __gnu_pbds;

 typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int32_t main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int tt=1;
/*for(int i=1;i<=100;i++)
{
	for(int j=1;j<=100;j++)
	{
		if(possible(i,j))
		{
			cout<<i<<" "<<j<<endl;
		}
	}
}*/
//cin>>tt;

int last=0;
while(tt--)
{

int x;
cin>>x;
if(x==2999)
{
	cout<<3000<<"\n";
	return 0;
}
if(x<-20)
	return 1/0;

}
}

/*stolen stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
    * WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
*/


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

typedef long long ll;
#define FastRead     ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mem(a,b)     memset(a,b,sizeof(a))

const int Max = 1e4+5;

int main(){
    int n,a[105],ans=0;
    map<int,int> mp;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mp[a[i]++];
    }
// sort(a,a+n);
//     for(int i=0;i<n;i++){
//         if(!mp[a[i]])
//         {
//             ans=a[i];
//             break;
//         }
//     }
    if(n<2)
        cout<<a[1]<<endl;
    else
        cout<<a[2]<<endl;

}


#include <bits/stdc++.h>
#define ll long long
#define db long double
#define ull unsigned long long
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

#define pper(a) cerr << #a << " = " << a << endl;

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

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

template<class U, class V>
ostream& operator<<(ostream& out, const pair<U, V>& a) {
  return out << "(" << a.x << ", " << a.y << ")";
}

template<class U, class V>
istream& operator>>(istream& in, pair<U, V>& a) {
  return in >> a.x >> a.y;
}

template<typename W, typename T = typename enable_if<!is_same<W, string>::value, typename W::value_type>::type>
ostream& operator<<(ostream& out, const W& v) { out << "{ "; for (const auto& x : v) out << x << ", "; return out << '}'; }

template<class T>
void readArr(T from, T to) {
  for (auto i = from; i != to; ++i) cin >> *i;
}

mt19937 mrand(1337);
unsigned int myRand32() {
  return mrand() & (unsigned int)(-1);
}

unsigned ll myRand64() {
  return ((ull)myRand32() << 32) ^ myRand32();
}

const int mod = 1000000007;

void add(int& a, int b) {
  a += b; if (a >= mod) a -= mod;
}

void dec(int &a, int b) {
  a -= b; if (a < 0) a += mod;
}

int mult(int a, int b) {
  return a * (ll)b % mod;
}

int bp(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = mult(res, a);
    a = mult(a, a);
    b >>= 1;
  }
  return res;
}

int main(){
#ifdef LOCAL
	freopen("B_input.txt", "r", stdin);
	//freopen("B_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

  vector<int> vals = {1200, 1350, 1500, 1650, 1800, 2000, 2200, 2400, 2700, 3000};

  int x;
  cin >> x;
  if (x >= 1200 && x <= 1350) {
    assert(false);
  }

  int now = 0;
  while (x >= vals[now]) {
    ++now;
  }
  cout << vals[now] << "\n";
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ll long long
using namespace std;
int n;
string a,b;
bool M=0;
//map<string,bool>m;
bool solve(string s,int i,int cnt)
{
    if(s==b)    return 1;
    if(cnt==10)
        return 0;
    if(i>0)
    {
        swap(s[i],s[i-1]);
        M|=solve(s,i-1,cnt+1);
        swap(s[i],s[i-1]);
    }
    if(i<n-1)
    {
        swap(s[i],s[i+1]);
        M|=solve(s,i-1,cnt+1);
        swap(s[i],s[i+1]);
    }
    if(i==0)
    {
        swap(s[i],s[3]);
        M|=solve(s,3,cnt+1);
        swap(s[i],s[3]);
    }
    if(i==3)
    {
        swap(s[0],s[3]);
        M|=solve(s,0,cnt+1);
        swap(s[0],s[3]);
    }
    return M;
}
int main(){
    string a1,a2,b2,b1;
    cin>>a1>>a2>>b1>>b2;
    b=b1+b2;
    a=a1+a2;
    swap(a[0],a[1]);swap(b[0],b[1]);
    for(int i=0 ; i<a.size() ; i++)
        if(a[i]=='X')   n=i;
    if(solve(a,n,0))
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	string a;
	char ch;
	for(int i=0;i<2;i++)
	{
		cin>>ch;
		if(ch=='X'){}
		else{a+=ch;}
	}
	string b;
	for(int i=0;i<2;i++)
	{
		cin>>ch;
		if(ch=='X'){}
		else{b+=ch;}
	}
	reverse(a.begin(),b.end());
	string c=a+b;
	////////////////////
	string d;
	for(int i=0;i<2;i++)
	{
		cin>>ch;
		if(ch=='X'){}
		else{d+=ch;}
	}
	string e;
	for(int i=0;i<2;i++)
	{
		cin>>ch;
		if(ch=='X'){}
		else{e+=ch;}
	}
	reverse(e.begin(),e.end());
	string f=d+e;
	string g=f+f;
	int flag=0;
	for(int i=0;i<4;i++)
	{
		if(c[0]==g[i]&&c[1]==g[i+1]&&c[2]==g[i+2])
		{
			flag=1;
			break;
		}
		else{}
	}
	if(flag==1)
	{
		cout<<"YES";
	}
	else
	{
		cout<<"NO";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ll long long
using namespace std;
int n,tmp;
string a,b;
bool M=0;
map<string,bool>m;
bool solve(string s,int i)
{
    if(m[s])    return 0;
    if(s==b)    return 1;
    m[s]=1;
    if(i>0)
    {
        swap(s[i],s[i-1]);
        M|=solve(s,i-1);
        swap(s[i],s[i-1]);
    }
    if(i<n-1)
    {
        swap(s[i],s[i+1]);
        M|=solve(s,i-1);
        swap(s[i],s[i+1]);
    }
    if(i==0)
    {
        swap(s[i],s[3]);
        M|=solve(s,3);
        swap(s[i],s[3]);
    }
    if(i==3)
    {
        swap(s[0],s[3]);
        M|=solve(s,0);
        swap(s[0],s[3]);
    }
    return M;
}
int main(){
    string a1,a2,b2,b1;
    cin>>a1>>a2>>b1>>b2;
    b=b1+b2;
    a=a1+a2;
    swap(a[0],a[1]);
    swap(b[0],b[1]);
    for(int i=0 ; i<a.size() ; i++)
        if(a[i]=='X')   n=i;
    if(solve(a,n))
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


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

typedef long long LL;
typedef unsigned long long ULL;
typedef short int int16;
typedef long double ldouble;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

typedef pair < int , int > ipair;
typedef pair < LL , LL > lpair;
typedef map < int,int > imap;
typedef map < LL , LL > lmap;
typedef vector < int > ivector;
typedef vector < LL > lvector;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }
template<class T> void _R( T &x ) { cin>>x; }

const int size = 1e5 + 2;
const double eps = 0.0001;
const ldouble PI = 3.1415926535897932384626433832795;
const LL  MOD = 1000000007;
const LL INF = 1LL << 60;
const LL MAX5 = 100001;
const LL MAX6 = 1000001;

#define MEMS(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ff first
#define ss second
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max6(a,b,c,d,e,f) max(max3(a,b,c),max3(d,e,f))
#define min6(a,b,c,d,e,f) min(min3(a,b,c),min3(d,e,f))
#define all(x) (x).begin(), (x).end()
#define rep(i,a,n) for (long long i=a;i<n;++i)
#define per(i,n,a) for (long long i=n-1;i>=a;--i)
#define read(a,n) for(LL i=0;i<n;++i)cin>>a[i];
#define vout for(int i=0;i<res.size();++i)cout<<res[i];
#define reunique(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define res(); cout<<res;
void solution();
void include_file();

int main(){
ios_base::sync_with_stdio(false);
//srand(time(0));
//include_file();
solution();
return 0;
}
void include_file(){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}
string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}
LL cubic_root(LL x) {
    LL l = 0, r = MAX6;
    while (l != r) {
        LL m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
float FastInvSqrt(float x) {
	//   1/sqrt(X)
  float xhalf = 0.5f * x;
  int i = *(int*)&x;  // i?aanoaaei aeou float a aeaa oaeiai ?enea
  i = 0x5f3759df - (i >> 1);  // eaeiai ?a?oa caanu i?ienoiaeo ?
  x = *(float*)&i;
  x = x*(1.5f-(xhalf*x*x));
  return x;
}
LL gcd(LL a,LL b)
{
  if(a==0)return b;
  return gcd(b%a,a);
}
LL lcm(LL a, LL b)
{
  return a/gcd(a, b)*b;
}

void yes()
{
	cout<<"YES";
}
void no()
{
	cout<<"NO";
}
void yes(bool res)
{
	if(res)
	cout<<"YES";
	else cout<<"NO";
}
void dabl(double x)
{
	printf("%.10lf",x);
}
namespace bits
{
	template<typename X> inline X MAX(const X& a, const X& b)
{ return b & ((a-b) >> 31) | a & (~(a-b) >> 31);}
template<typename X> inline X MIN(const X& a, const X& b)
{ return a & ((a-b) >> 31) | b & (~(a-b) >> 31);}

//i?iaa?ea ia noaiaiu 2
bool check2(const LL n)
{
	return 	n > 0 && (n & (n - 1));
}
//inoaoie io aaeaiey 2^n ia m
LL ostatok2(const LL n, const LL m)
{
	return m & (n-1);
}
template<typename X>
void SWAP(X &a, X &b)
{
	a^=b;
	b^=a;
	a^=b;
}

size_t count_1_in_LL(unsigned long long n)
{
    std::size_t i(0);
    for (;n;++i) n&=n-1;
    return i;
}
}
vector <vector<int> > g;
///////////////////SOLUTION
bool res=0;
string a[2],b[2];
string c[2];
bool bb=0;
void rec(string x[2])
{
	if(res)return;
	if(x[0]==b[0] && x[1]==b[1]){res=1;return;}

	if(x[0]==a[0] && x[1]==a[1])return;

		string x1[2],x2[2];
		x1[0]=x[0];x1[1]=x[1];
		x2[0]=x[0];x2[1]=x[1];

	if(x[0][0]=='X')
	{
		swap(x1[0][0],x1[0][1]);
		swap(x2[0][0],x2[1][0]);
	}
	else if(x[0][1]=='X')
	{
		swap(x1[0][0],x1[0][1]);
		swap(x2[0][1],x2[1][1]);
	}
	else if(x[1][0]=='X')
	{
		swap(x1[0][0],x1[1][0]);
		swap(x2[1][0],x2[1][1]);
	}
	else if(x[1][1]=='X')
	{
		swap(x1[1][0],x1[1][1]);
		swap(x2[0][1],x2[1][1]);
	}
	//cout<<x1[0]<<endl<<x1[1]<<endl;
	bb=1;
	rec(x1);
	rec(x2);
}
void solution()
{
	cin>>a[0]>>a[1]>>b[0]>>b[1];

	string x[2];
	x[0]=a[0];x[1]=a[1];
	string x1[2],x2[2];
		x1[0]=x[0];x1[1]=x[1];
		x2[0]=x[0];x2[1]=x[1];

	if(x[0][0]=='X')
	{
		swap(x1[0][0],x1[0][1]);
		swap(x2[0][0],x2[1][0]);
	}
	else if(x[0][1]=='X')
	{
		swap(x1[0][0],x1[0][1]);
		swap(x2[0][1],x2[1][1]);
	}
	else if(x[1][0]=='X')
	{
		swap(x1[0][0],x1[1][0]);
		swap(x2[1][0],x2[1][1]);
	}
	else if(x[1][1]=='X')
	{
		swap(x1[1][0],x1[1][1]);
		swap(x2[0][1],x2[1][1]);
	}

	rec(x1);
	rec(x2);

	yes(res);
}
///////////////////SOLUTION


#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>

using namespace std;

const int MAXL = 100;
typedef long long ll;

ll n;
int dist[MAXL * MAXL * MAXL * MAXL];
map<ll, int> save;

bool isAns(ll x){
	if(!x)	return false;
	ll c = sqrt(x);
	return c == sqrt(x);
}

bool isVis(ll x){
	if(save[x])	return true;
	save[x] = 1;	return false;
}

int get_len(ll x){
	int res = 0;
	while(x){
		res++, x /= 10;
	}return res;
}

int BFS(){
	queue<ll> q;	q.push(n);	int fro, rear;	fro = 1, rear = 2;	dist[fro] = 0;
	while(!q.empty()){
		ll old = q.front();	q.pop();	//printf("old = %lld\n", old);
		if(isAns(old))	return dist[fro];
		for(int i = 0; i < get_len(old); i++){
			ll u, v;	u = v = 0;
			for(int j = get_len(old) - 1; j > i; j--){
				u = u * 10 + (old / (ll)pow(10, j)) % 10;
			}
			for(int j = i - 1; j >= 0; j--){
				v = v * 10 + (old / (ll)pow(10, j)) % 10;
			}//printf("old = %lld, i = %d, u = %lld, v = %lld, res = %lld\n", old, i, u, v, (ll)(u * pow(10, get_len(v)) + v));
			ll now = u * pow(10, get_len(v)) + v;	if(now && !isVis(now))	q.push(now),	dist[rear++] = dist[fro] + 1;
		}fro++;
	}return -1;
}

void solve()
{
	printf("%d\n", BFS());
}

void init()
{
	scanf("%lld", &n);
}

int main(void)
{
	init();	solve();
	return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>

#define mp make_pair
#define fi first
#define se second
#define endl "\n"
#define sqr(a) (a)*(a)

using namespace std;

typedef long long ll;

ll x, ans = 1e9, z;
string S;

void rec(string s, ll i, ll k) {
    if (k >= ans) return;

    if (s[0] != '0') {
        stringstream ss;
        ss.clear();
        ss.str("");

        ss << s;
        ss >> x;

        if (sqrt(x)*sqrt(x) == x) {
            if (k < ans) ans = k;
            return;
        }
    }

    if (k+1 == S.size()) return;

    for (ll j = i; j < s.size(); j++) {
        string s1 = s;
        s1.erase(j,1);
        rec(s1,j,k+1);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    cin >> S;

    rec(S,0,0);

    if (ans == 1e9) cout << -1 << endl; else cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    long long n;
    cin >> n;

    vector < int > idx;

    while(n != 0)
    {
        long long u = n%10;
        n /= 10;
        idx.push_back(u);
    }

    reverse(idx.begin(),idx.end());

    vector < int > inp;

    long long fin = -1;

    long long siz = idx.size();

    for(long long i = 1 ; i <= 200000 ; i++)
    {
        long long def = i*i;
        long long take = def;

        inp.clear();

        while(take != 0)
        {
            long long v = take%10;
            take /= 10;
            inp.push_back(v);
        }

        reverse(inp.begin(),inp.end());

        if(inp.size() > idx.size()) {
            break;
        }

        long long check = 0;
        long long z = inp.size();

       // if(i == 9) {

            for(long long j = 0 ; j < siz ; j++)
            {
                if(inp[check] == idx[j])
                {
                    check++;
                }
            }

            if(check == z)
            {
                fin = i*i;
            }

           // cout << "check -> " << check << " " << fin << endl;

      //  }
    }

    if(fin == -1)
    {
        cout << -1 << endl; exit(0);
    }

    long long digit = 0;

    while(fin != 0)
    {
        digit++;
        fin /= 10;
    }

    cout << idx.size() - digit << endl;
}


#include<bits/stdc++.h>
using namespace std ;
#define khaledOsama ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define re return
#define MOD 1000000007
#define lp(i,w,e) for(int i=w;i<e;i++)
#define lpr(i,w,e) for(int i=w;i>=e;i--)
#define pb push_back
#define clr(v, d) memset(v, d, sizeof(v))
#define mp make_pair
#define all(x) x.begin(),x.end()
const long long OO=1e18+1;
const int MAX=2e9+1;
typedef long long ll;
typedef unsigned long long ull;
typedef  pair<int,int> pii;
typedef  pair<ll,ll> pll;
typedef long double ld;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string>vs;
typedef  vector<pii> vpii;
typedef  vector<pll > vpll;
typedef  bitset <12> MASK;
ll poww(int x,int y){
ll ret=1;
lp(i,0,y)ret*=x;
re ret;
}
int main(){
khaledOsama;
ll arr[100000],k=0;
for(int i=1;i*i<=2000000000;i++){
    arr[k++]=i*i;
}
string str; cin>>str;
for(ll i=k-1;i>=0;i--){
    ll l=log10(arr[i]),p=0,o=l;
    lp(j,0,str.length()){
        ll y=str[j]-'0';
        ll r=(arr[i]/poww(10,o));
        if(y==r){p++;
        ll t=poww(10,o);t*=y;
        arr[i]-=t,o--; if(arr[i]==0)break;
        }

    }
    if(p-1==l)re cout<<str.length()-(l+1)<<endl,0;
}
cout<<-1<<endl;
}


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

int t[4 * 100000], a[100000];

void build(int v, int l, int r){
    if (l > r)
        return;
    if (l == r)
        t[v] = a[l];
    else{
        int m = (l + r) / 2;
        build(v * 2, l, m);
        build(v * 2 + 1, m + 1, r);
        t[v] = t[v * 2] + t[v * 2 + 1];
    }
}
int get(int v, int l, int r, int tl, int tr){
    if (l > r)
        return 0;
    if (l == tl && r == tr)
        return t[v];
    else{
        int tm = (tl + tr) / 2;
        return get(v * 2, l, min(tm, r), tl, tm) + get(v * 2 + 1, max(l, tm + 1), r, tm + 1, tr);
    }
}

int p[100000], s[100000] = {0};

void make_set(int v){
    p[v] = v;
    s[v] = 1;
    return;
}
int find_set(int v){
    if (p[v] == v)
        return v;
    return p[v] = find_set(p[v]);
}
void union_sets(int a, int b){
    a = find_set(a);
    b = find_set(b);
    if (a != b){
        if (s[a] < s[b])
            swap(a, b);
        s[a] += s[b];
        p[b] = a;
    }
}

signed main(){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    build(1, 1, n);
    for (int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        cout << get(1, l, r, 1, n);
    }
}


/* BAAHUBALI7781  */

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

 void fileioe(){
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    freopen("error.txt","w",stderr);
}
#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif

#define SOT(n) SieveOfEratosthenes(n)
#define fioe() fileioe()
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define zrep(i, a, b) for (ll i=b; i>=(a); i--)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//

                void solve()
                {
                	ll n;
                	cin>>n;
                	ll a[n],b[n];
                	ll ctr1=0,ctr2=0;
                	rep(i,0,n)
                	{
                		cin>>a[i];
                		if(a[i]==1)
                			ctr1++;
                	}
                	rep(i,0,n)
                	{
                		cin>>b[i];
                		if(b[i]==1)
                			ctr2++;
                	}
                	if(ctr1==0&&ctr2==0||ctr1==0)
                	{
                		cout<<-1<<endl;
                		return;

                	}
                	int ctr=0;
                	if(ctr1>ctr2)
                		cout<<1<<endl;
                	else if(ctr1<=ctr2)
                	{
                		rep(i,0,n)
                		{
                			if(a[i]==1&&b[i]==1)
                				ctr++;
                		}
                		if(ctr==n||ctr==ctr1)
                			cout<<-1<<endl;
                		else
                		{
                			ll x=ctr2-ctr+1;
                			float y=float(x)/(ctr1-ctr);
                			//cout<<y;
                			cout<<ceil(y)<<endl;
                		}
                	}

                }

                int main(){
                        hs;
                        fioe();
                        ll t;
                        t=1;
                        //cin>>t;
                        for (int i=1; i<=t; i++){
                                //cout<<"Case #"<<i<<": ";
                                solve();
                         }
        return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
   ios :: sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

    int n;
    cin >> n;

    vector<int> r(n), b(n);
    bool allZero = true;
    for (int i = 0; i < n; i++) cin >> r[i], allZero &= (r[i] == 0);
    for (int i = 0; i < n; i++) cin >> b[i];

    if (r == b || allZero) {
        cout << -1;
    } else {
        int second = 0, first = 0;

        for (int i = 0; i < n; i++) {
            if (r[i] == 0 && b[i] == 1) {
               second++;
            }

            if (r[i] == 1 && b[i] == 0) {
                first++;
            }
        }

        if (first > second) cout << 1 << '\n';
        else {
                int k = 0;
                while (k * first <= second) k++;
                cout << k << '\n';
        }
    }
}


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

int a[200005], b[200005];

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int cn1 = 0, cn2 = 0;
    for(int i = 1; i <= n; i++) {
        cin >> b[i];
        if(a[i] && !b[i])cn1++;
        else if(!a[i] && b[i])cn2++;
    }
    if(!cn1) {
        cout << -1;
        return 0;
    }
    int ans = max(1, 2 + cn2 - cn1);
    cout << ans;
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

#define SIZE(X) ((int)(X.size()))//NOTES:SIZE(
#define LENGTH(X) ((int)(X.length()))//NOTES:LENGTH(
#define MP(X,Y) make_pair(X,Y)//NOTES:MP(
#define FORD(i, a, b) for(int i=(a); i<(b); i++)
#define FORS(i, a) for(int i=(0); i<SIZE(a); i++)
typedef long long int64;//NOTES:int64
typedef unsigned long long uint64;//NOTES:uint64
#define two(X) (1<<(X))//NOTES:two(
#define twoL(X) (((int64)(1))<<(X))//NOTES:twoL(
#define contain(S,X) (((S)&two(X))!=0)//NOTES:contain(
#define containL(S,X) (((S)&twoL(X))!=0)//NOTES:containL(
const double pi=acos(-1.0);//NOTES:pi
const double eps=1e-11;//NOTES:eps
template<class T> inline T sqr(T x){return x*x;}//NOTES:sqr
typedef pair<int,int> ipair;//NOTES:ipair
template<class T> inline T lowbit(T n){return (n^(n-1))&n;}//NOTES:lowbit(
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}//NOTES:countbit(

int R=0;
vector<int> M(1001, -1);

int solve(int n)
{
  if(n==1)
    return 1;

  if(M[n]<0)
  {
    M[n] = 3 * solve(n-1);
    M[n]%=1000003;
  }
  return M[n];
}

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

  if(N!=0)
    R = solve(N);

  cout << R;
}


#include <iostream>
using namespace std;

const int mod = 1000003;
int Power(int m,int n,int k)
{
    int b = 1;
    while (n > 0)
    {
          if (n & 1)
             b = (b*m)%k;
          n = n >> 1 ;
          m = (m*m)%k;
    }
    return b;
}

int main()
{
    int n;
    while (scanf("%d", &n)!=EOF)
    {
     if (n == 0)
     {
        cout <<"0"<<endl;
        continue;
     }
     int ans = Power(3,n-1,mod);
     cout << ans << endl;
   }
   return 0;
}


#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    if ( n==0){
         cout << 1 << endl;
       } else {
    cout <<(int)(pow(3.0,(float)(n-1)))%1000003<< endl;
}
  //  system("pause");
    return 0;
}


#include<iostream>
#include<conio.h>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
    int c;
    cin>>c;
    int h=1;
    for(int i=0;i<c-1;i++)
    {
            h*=3;
            h%=1000003;
    }
    cout<<h;
    getch();
    return 0;
}


//============================================================================
// Name        : cf.cpp
// Author      : HX
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <iomanip>
using namespace std;
#define  N   10000
#define  eps 1e-9
#define  pi  acos(-1.0)
int n;
double dp[N], x[N], y[N], a[N];
double l, r;
int main() {
	//freopen("cf.txt", "r", stdin);
	cin >> n;
	cin >> l >> r;
	for (int i=0; i<n; i++)
		cin >> x[i] >> y[i] >> a[i];
	for (int i=0; i<n; i++)
		y[i] = max(y[i], -y[i]), a[i] = a[i] / 180.0 * pi;
	dp[0] = l;
	for (int s=1; s<(1<<n); s++) {
		dp[s] = l;
		for (int j=0; j<n; j++) {
			if ((s>>j)&1) {
				int ns = s ^ (1<<j);
				if (fabs(y[j]) < eps) {
					if (x[j] < dp[ns] + eps)
						dp[s] = r;
					else
						dp[s] = max(dp[s], max(dp[ns], x[j]));
				} else {
					double theta = atan((dp[ns] - x[j]) / y[j]) + a[j];
					if (theta > pi / 2.0 - eps) {
						dp[(1<<n) - 1] = r;
						break;
					}
					double nx = x[j] + y[j] * tan(theta);
					dp[s] = max(dp[s], max(dp[ns], nx));
				}
			}
		}
	}
	cout << fixed << setprecision(11) << min(r, dp[(1<<n) - 1]) - l << endl;
	return 0;
}


#include <bits/stdc++.h>

const int MAXN = 21;
const int MAXS = 200001;
const double PI = acos(-1.0);
const int INF = ~0u >> 2;

int n, l, r;
double x[MAXN], y[MAXN], a[MAXN], dp[MAXS];

int main() {
	std::cin >> n >> l >> r;
	for (int i = 1; i <= n; i++) {
		std::cin >> x[i] >> y[i] >> a[i];
	}
	for (int s = 0; s < (1 << n); s++) {
		dp[s] = -INF;
	}
	dp[0] = l;
	for (int s = 0; s < (1 << n); s++) {
		for (int i = 1; i <= n; i++) {
			if (s & (1 << i - 1)) continue;
			double theta = atan2(y[i], x[i] - dp[s]);
			double alpha = 1.0 * a[i] / 180 * PI;
			double beta = theta + alpha;
			if (beta >= PI) {
				return printf("%.12f\n", 1.0 * r - 1.0 * l), 0;
			}
			double dist = sqrt(y[i] * y[i] + (x[i] - dp[s]) * (x[i] - dp[s]));
			double delta = dist / sin(beta) * sin(alpha);
			dp[s | (1 << i - 1)] = std::max(dp[s | (1 << i - 1)], dp[s] + delta);
		}
	}
	printf("%.12f\n", std::min(dp[(1 << n) - 1] - l, 1.0 * r - 1.0 * l));
	return 0;
}


/** Micro Mezzo Macro Flation -- Overheated Economy ., Last Update: Feb. 12th 2013 **/ //{

/** Header .. **/ //{
#define LOCAL

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define REP(i, n) for (int i=0;i<int(n);++i)
#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)
#define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)
#define REP_1(i, n) for (int i=1;i<=int(n);++i)
#define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)
#define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)
#define REP_C(i, n) for (int n____=int(n),i=0;i<n____;++i)
#define FOR_C(i, a, b) for (int b____=int(b),i=a;i<b____;++i)
#define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i>=a____;--i)
#define REP_N(i, n) for (i=0;i<int(n);++i)
#define FOR_N(i, a, b) for (i=int(a);i<int(b);++i)
#define DWN_N(i, b, a) for (i=int(b-1);i>=int(a);--i)
#define REP_1_C(i, n) for (int n____=int(n),i=1;i<=n____;++i)
#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i<=b____;++i)
#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i>=a____;--i)
#define REP_1_N(i, n) for (i=1;i<=int(n);++i)
#define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i)
#define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i)
#define REP_C_N(i, n) for (int n____=(i=0,int(n));i<n____;++i)
#define FOR_C_N(i, a, b) for (int b____=(i=0,int(b);i<b____;++i)
#define DWN_C_N(i, b, a) for (int a____=(i=b-1,int(a));i>=a____;--i)
#define REP_1_C_N(i, n) for (int n____=(i=1,int(n));i<=n____;++i)
#define FOR_1_C_N(i, a, b) for (int b____=(i=1,int(b);i<=b____;++i)
#define DWN_1_C_N(i, b, a) for (int a____=(i=b,int(a));i>=a____;--i)

#define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it)
#define REP_S(i, str) for (char*i=str;*i;++i)
#define REP_L(i, hd, nxt) for (int i=hd;i;i=nxt[i])
#define REP_G(i, u) REP_L(i,hd[u],suc)
#define DO(n) for ( int ____n ## __line__ = n; ____n ## __line__ -- ; )
#define REP_2(i, j, n, m) REP(i, n) REP(j, m)
#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)
#define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l)
#define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l)
#define REP_4(i, j, k, ii, n, m, l, nn) REP(i, n) REP(j, m) REP(k, l) REP(ii, nn)
#define REP_4_1(i, j, k, ii, n, m, l, nn) REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn)

#define ALL(A) A.begin(), A.end()
#define LLA(A) A.rbegin(), A.rend()
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define ERS(A, P) A.erase(A.begin() + P)
#define BSC(A, x) (lower_bound(ALL(A), x) - A.begin())
#define CTN(T, x) (T.find(x) != T.end())
#define SZ(A) int(A.size())
#define PB push_back
#define MP(A, B) make_pair(A, B)
#define PTT pair<T, T>
#define fi first
#define se second

#define Rush for(int ____T=RD(); ____T--;)

#define Display(A, n, m) {                      \
	REP(i, n){		                            \
        REP(j, m) cout << A[i][j] << " ";       \
        cout << endl;				            \
	}						                    \
}

#define Display_1(A, n, m) {				    \
	REP_1(i, n){		                        \
        REP_1(j, m) cout << A[i][j] << " ";     \
		cout << endl;		            		\
	}						                    \
}

#pragma comment(linker, "/STACK:36777216")
//#pragma GCC optimize ("O2")
#define Ruby system("ruby main.rb")
#define Haskell system("runghc main.hs")
#define Python system("python main.py")
#define Pascal system("fpc main.pas")

typedef long long LL;
//typedef long double DB;
typedef double DB;
typedef unsigned UINT;
typedef unsigned long long ULL;

typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<DB> VF;
typedef set<int> SI;
typedef set<string> SS;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;

template<class T> inline T& RD(T &);
template<class T> inline void OT(const T &);
inline LL RD(){LL x; return RD(x);}
inline DB& RF(DB &);
inline DB RF(){DB x; return RF(x);}
inline char* RS(char *s);
inline char& RC(char &c);
inline char RC();
inline char& RC(char &c){scanf(" %c", &c); return c;}
inline char RC(){char c; return RC(c);}
//inline char& RC(char &c){c = getchar(); return c;}
//inline char RC(){return getchar();}

template<class T> inline T& RDD(T &x){
    char c; for (c = getchar(); c < '-'; c = getchar());
    if (c == '-'){x = '0' - getchar(); for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + '0' - c;}
    else {x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';}
    return x;
}

inline LL RDD(){LL x; return RDD(x);}

template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}
template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}
template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}
template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}
template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}
template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}
template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}
inline char& RC(char &a, char &b){RC(a), RC(b); return a;}
inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;}
inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;}
inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}
inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}
inline void RS(char *s1, char *s2){RS(s1), RS(s2);}
inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}
template<class T0,class T1>inline void RDD(const T0&a, const T1&b){RDD(a),RDD(b);}
template<class T0,class T1,class T2>inline void RDD(const T0&a, const T1&b, const T2&c){RDD(a),RDD(b),RDD(c);}

template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}
template<class T> inline void CLR(T &A){A.clear();}

template<class T0, class T1> inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);}
template<class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);}
template<class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}
template<class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);}
template<class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x);}
template<class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);}
template<class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x);}
template<class T> inline void CLR(priority_queue<T, vector<T>, less<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T> inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T0, class T1> inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);}
template<class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);}
template<class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}
template<class T> inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);}

template<class T> inline T& SRT(T &A){sort(ALL(A)); return A;}
template<class T, class C> inline T& SRT(T &A, C B){sort(ALL(A), B); return A;}
template<class T> inline T& UNQ(T &A){A.resize(unique(ALL(SRT(A)))-A.begin());return A;}

//}

/** Constant List .. **/ //{

const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};

const int dx8[] = {-1, 0, 1, 0 , -1 , -1 , 1 , 1};
const int dy8[] = {0, 1, 0, -1 , -1 , 1 , -1 , 1};

const int dxhorse[] = {-2 , -2 , -1 , -1 , 1 , 1 , 2 , 2};
const int dyhorse[] = {1 ,  -1 , 2  , -2 , 2 ,-2 , 1 ,-1};

const int MOD = 1000000007;
//int MOD = 99990001;
const int INF = 0x3f3f3f3f;
const LL INFF = 1LL << 60;
const DB EPS = 1e-9;
const DB OO = 1e15;
const DB PI = acos(-1.0); //M_PI;

//}

/** Add On .. **/ //{
// <<= '0. Nichi Joo ., //{
template<class T> inline void checkMin(T &a,const T b){if (b<a) a=b;}
template<class T> inline void checkMax(T &a,const T b){if (a<b) a=b;}
template<class T> inline void checkMin(T &a, T &b, const T x){checkMin(a, x), checkMin(b, x);}
template<class T> inline void checkMax(T &a, T &b, const T x){checkMax(a, x), checkMax(b, x);}
template <class T, class C> inline void checkMin(T& a, const T b, C c){if (c(b,a)) a = b;}
template <class T, class C> inline void checkMax(T& a, const T b, C c){if (c(a,b)) a = b;}
template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}
template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}
template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}
template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T cub(T a){return a*a*a;}
inline int ceil(int x, int y){return (x - 1) / y + 1;}
inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}
inline int sgn(DB x, DB y){return sgn(x - y);}
//}
// <<= '1. Bitwise Operation ., //{
namespace BO{

inline bool _1(int x, int i){return bool(x&1<<i);}
inline bool _1(LL x, int i){return bool(x&1LL<<i);}
inline LL _1(int i){return 1LL<<i;}
inline LL _U(int i){return _1(i) - 1;};

inline int reverse_bits(int x){
    x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);
    x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);
    x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);
    x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);
    x = ((x >>16) & 0x0000ffff) | ((x <<16) & 0xffff0000);
    return x;
}

inline LL reverse_bits(LL x){
    x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);
    x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);
    x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);
    x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);
    x = ((x >>16) & 0x0000ffff0000ffffLL) | ((x <<16) & 0xffff0000ffff0000LL);
    x = ((x >>32) & 0x00000000ffffffffLL) | ((x <<32) & 0xffffffff00000000LL);
    return x;
}

template<class T> inline bool odd(T x){return x&1;}
template<class T> inline bool even(T x){return !odd(x);}
template<class T> inline T low_bit(T x) {return x & -x;}
template<class T> inline T high_bit(T x) {T p = low_bit(x);while (p != x) x -= p, p = low_bit(x);return p;}
template<class T> inline T cover_bit(T x){T p = 1; while (p < x) p <<= 1;return p;}

inline int low_idx(int x){return __builtin_ffs(x);}
inline int low_idx(LL x){return __builtin_ffsll(x);}
inline int high_idx(int x){return low_idx(reverse_bits(x));}
inline int high_idx(LL x){return low_idx(reverse_bits(x));}
inline int clz(int x){return __builtin_clz(x);}
inline int clz(LL x){return __builtin_clzll(x);}
inline int ctz(int x){return __builtin_ctz(x);}
inline int ctz(LL x){return __builtin_ctzll(x);}
inline int parity(int x){return __builtin_parity(x);}
inline int parity(LL x){return __builtin_parityll(x);}
inline int lg2(int a){return 31 - clz(a);}
inline int lg2(LL a){return 63 - clz(a);}
inline int count_bits(int x){return __builtin_popcount(x);}
inline int count_bits(LL x){return __builtin_popcountll(x);}

} using namespace BO;//}
// <<= '2. Number Theory .,//{
namespace NT{
inline LL __lcm(LL a, LL b){return a*b/__gcd(a,b);}
inline void INC(int &a, int b){a += b; if (a >= MOD) a -= MOD;}
inline int sum(int a, int b){a += b; if (a >= MOD) a -= MOD; return a;}
inline void DEC(int &a, int b){a -= b; if (a < 0) a += MOD;}
inline int dff(int a, int b){a -= b; if (a < 0) a  += MOD; return a;}
inline void MUL(int &a, int b){a = (LL)a * b % MOD;}
inline int pdt(int a, int b){return (LL)a * b % MOD;}

inline int sum(int a, int b, int c){return sum(sum(a, b), c);}
inline int sum(int a, int b, int c, int d){return sum(sum(a, b), sum(c, d));}
inline int pdt(int a, int b, int c){return pdt(pdt(a, b), c);}
inline int pdt(int a, int b, int c, int d){return pdt(pdt(pdt(a, b), c), d);}

inline int pow(int a, int b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

inline int pow(int a, LL b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

template<class T> inline T pow(T a, LL b){
    T c(1); while (b){
        if (b&1) c *= a;
        a *= a, b >>= 1;
    }
    return c;
}

inline int _I(int b){
    int a = MOD, x1 = 0, x2 = 1, q;
    while (true){
        q = a / b, a %= b;
        if (!a) return (x2 + MOD) % MOD;
        DEC(x1, pdt(q, x2));

        q = b / a, b %= a;
        if (!b) return (x1 + MOD) % MOD;
        DEC(x2, pdt(q, x1));
    }
}

inline void DIV(int &a, int b){MUL(a, _I(b));}
inline int qtt(int a, int b){return pdt(a, _I(b));}

inline int phi(int n){
    int res = n; for (int i=2;sqr(i)<=n;++i) if (!(n%i)){
        DEC(res, qtt(res, i));
        do{n /= i;} while(!(n%i));
    }
    if (n != 1)
        DEC(res, qtt(res, n));
    return res;
}

} using namespace NT;//}
//}

/** Miscellaneous .. **/ //{
// <<= 'Random Event .. . //{
namespace RNG{
//srand((unsigned)time(NULL));
inline unsigned int rand16(){return ((rand()) << 15) ^ rand();}
inline unsigned int rand32(){return (rand16() << 16) | rand16();}
inline ULL rand64(){return ((LL)rand32() << 32) | rand32();}
inline ULL random(LL l, LL r){return l == r ? l : rand64() % (r - l) + l;}
int dice(){return rand() % 6;}
bool coin(){return bool(rand() % 2);}
} using namespace RNG;
//}
// <<= 'Clock .. . //{
namespace CLOCK{
DB s0, s1, rd, k, T;
inline DB getTime(){
#ifdef LOCAL
    return 1.0 * clock() / CLOCKS_PER_SEC;
#else
    timeval tv;
    gettimeofday(&tv, 0);
    return tv.tv_sec + tv.tv_usec * 1e-6;
#endif
}

inline void st0(DB _T = 0.98){T = _T, s0 = getTime();}
inline void st1(DB _k = 1.618){k = _k, s1 = getTime();}
inline void ed1(){rd = getTime() - s1;}
inline DB elapsed(){return getTime() - s0;}
inline bool safe(){return elapsed() + rd * k < T;}
} //using namespace CLOCK;
//}
// <<= 'Temp .. . //{
namespace TMP{
template<class T> PTT operator+(const PTT &p1, const PTT &p2) {
	return PTT(p1.fi + p2.fi, p1.se + p2.se);
}

template<class T> PTT operator-(const PTT &p1, const PTT &p2) {
	return PTT(p1.fi - p2.fi, p1.se - p2.se);
}

template<class T> PTT operator*(const PTT &lhs, T k){
    return PTT(lhs.fi * k, lhs.se * k);
}
} using namespace TMP;
//}
//}

/** Algorithm    .. */ //{
// <<= '-. Math .,//{
namespace Math{
	typedef long long typec;
	///Lib functions
	typec GCD(typec a, typec b)
	{
		return b ? GCD(b, a % b) : a;
	}
	typec extendGCD(typec a, typec b, typec& x, typec& y)
	{
		if(!b) return x = 1, y = 0, a;
		typec res = extendGCD(b, a % b, x, y), tmp = x;
		x = y, y = tmp - (a / b) * y;
		return res;
	}
	///for x^k
	typec power(typec x, typec k)
	{
		typec res = 1;
		while(k)
		{
			if(k&1) res *= x;
			x *= x, k >>= 1;
		}
		return res;
	}
	///for x^k mod m
	typec powerMod(typec x, typec k, typec m)
	{
		typec res = 1;
		while(x %= m, k)
		{
			if(k&1) res *= x, res %= m;
			x *= x, k >>=1;
		}
		return res;
	}
	/***************************************
	Inverse in mod p^t system
	***************************************/
	typec inverse(typec a, typec p, typec t = 1)
	{
		typec pt = power(p, t);
		typec x, y;
	    y = extendGCD(a, pt, x, y);
		return x < 0 ? x += pt : x;
	}
	/***************************************
	Linear congruence theorem
	x = a (mod p)
	x = b (mod q)
	for gcd(p, q) = 1, 0 <= x < pq
	***************************************/
	typec linearCongruence(typec a, typec b, typec p, typec q)
	{
		typec x, y;
		y = extendGCD(p, q, x, y);
		while(b < a) b += q / y;
		x *= b - a, x = p * x + a, x %= p * q;
		if(x < 0) x += p * q;
		return x;
	}
	/***************************************
	prime table
	O(n)
	***************************************/
	const int PRIMERANGE = 1000000;
	int prime[PRIMERANGE + 1];
	int mobius[PRIMERANGE + 1];
	int getPrime()
	{
		memset (prime, 0, sizeof (int) * (PRIMERANGE + 1));
		memset(mobius , 0 , sizeof(mobius));
		mobius[1] = 1;
		for (int i = 2; i <= PRIMERANGE; i++)
		{
			if (!prime[i]) prime[++prime[0]] = i , mobius[i] = -1;
			for (int j = 1; j <= prime[0] && prime[j] <= PRIMERANGE / i; j++)
			{
				prime[prime[j]*i] = 1;
				if (i % prime[j] == 0) break;
				else mobius[i * prime[j]] = -mobius[i];
			}
		}
		return prime[0];
	}
	/***************************************
	get factor of n
	O(sqrt(n))
	factor[][0] is prime factor
	factor[][1] is factor generated by this prime
	factor[][2] is factor counter

	need: Prime Table
	***************************************/
	///you should init the prime table before
	int factor[100][3], facCnt;
	int getFactors(int x)
	{
		facCnt = 0;
		int tmp = x;
		for(int i = 1; prime[i] <= tmp / prime[i]; i++)
		{
			factor[facCnt][1] = 1, factor[facCnt][2] = 0;
			if(tmp % prime[i] == 0)
				factor[facCnt][0] = prime[i];
			while(tmp % prime[i] == 0)
				factor[facCnt][2]++, factor[facCnt][1] *= prime[i], tmp /= prime[i];
			if(factor[facCnt][1] > 1) facCnt++;
		}
		if(tmp != 1)
			factor[facCnt][0] = tmp, factor[facCnt][1] = tmp, factor[facCnt++][2] = 1;
		return facCnt;
	}
	typec combinationModP(typec n, typec k, typec p)
	{
		if(k > n) return 0;
		if(n - k < k) k = n - k;
		typec a = 1, b = 1, x, y;
		int pcnt = 0;
		for(int i = 1; i <= k; i++)
		{
			x = n - i + 1, y = i;
			while(x % p == 0) x /= p, pcnt++;
			while(y % p == 0) y /= p, pcnt--;
			x %= p, y %= p, a *= x, b *= y;
			b %= p, a %= p;
		}
		if(pcnt) return 0;
		extendGCD(b, p, x, y);
		if(x < 0) x += p;
		a *= x, a %= p;
		return a;
	}
};//using namespace Math;
//}
// <<= '-. Geo ,.//{
namespace Geo{
	#define typec double
    const typec eps=1e-9;
    int dblcmp(double d){
        return d < -eps ? -1 : d > eps;
    }
    int sgn(double a) {return a<-eps?-1:a>eps;}
    inline double sqr(double x){return x*x;}
}using namespace Geo;
//}
//}

/** I/O Accelerator Interface .. **/ //{
template<class T> inline T& RD(T &x){
    //cin >> x;
    //scanf("%d", &x);
    char c; for (c = getchar(); c < '0'; c = getchar()); x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
    //char c; c = getchar(); x = c - '0'; for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0';
    return x;
}

inline DB& RF(DB &x){
    //cin >> x;
    scanf("%lf", &x);
    /*char t; while ((t=getchar())==' '||t=='\n'); x = t - '0';
    while ((t=getchar())!=' '&&t!='\n'&&t!='.')x*=10,x+=t-'0';
    if (t=='.'){DB l=1; while ((t=getchar())!=' '&&t!='\n')l*=0.1,x += (t-'0')*l;}*/
    return x;
}

inline char* RS(char *s){
    //gets(s);
    scanf("%s", s);
    return s;
}

int Case; template<class T> inline void OT(const T &x){
    //printf("Case %d: %d\n", ++Case, x);
    //printf("%.2lf\n", x);
    //printf("%d\n", x);
    cout << x << endl;
}
//}
/* .................................................................................................................................. */
struct point
{
    double x,y;
    point(){}
    point(double _x,double _y):
    x(_x),y(_y){};
    void input()
    {
        scanf("%lf%lf",&x,&y);
    }
    void output()
    {
        printf("%.2f %.2f\n",x,y);
    }
    bool operator==(point a)const
    {
        return dblcmp(a.x-x)==0&&dblcmp(a.y-y)==0;
    }
    bool operator<(point a)const
    {
        return dblcmp(a.x-x)==0?dblcmp(y-a.y)<0:x<a.x;
    }
    double len()
    {
        return hypot(x,y);
    }
    double len2()
    {
        return x*x+y*y;
    }
    double distance(point p)
    {
        return hypot(x-p.x,y-p.y);
    }
    double distance2(point p)
    {
        return sqr(x-p.x)+sqr(y-p.y);
    }
    point add(point p)
    {
        return point(x+p.x,y+p.y);
    }
    point operator + (const point & p) const{
        return point(x+p.x,y+p.y);
    }
    point sub(point p)
    {
        return point(x-p.x,y-p.y);
    }
    point operator - (const point & p) const{
        return point(x-p.x,y-p.y);
    }
    point mul(double b)
    {
        return point(x*b,y*b);
    }
    point div(double b)
    {
        return point(x/b,y/b);
    }
    double dot(point p)
    {
        return x*p.x+y*p.y;
    }
    double operator * (const point & p) const{
        return x*p.x+y*p.y;
    }
    double det(point p)
    {
        return x*p.y-y*p.x;
    }
    double operator ^ (const point & p) const{
        return x*p.y-y*p.x;
    }
    double rad(point a,point b)
    {
    	point p=*this;
    	return fabs(atan2(fabs(a.sub(p).det(b.sub(p))),a.sub(p).dot(b.sub(p))));
	}
    point trunc(double r)
	{
		double l=len();
		if (!dblcmp(l))return *this;
		r/=l;
		return point(x*r,y*r);
	}
    point rotleft()
    {
        return point(-y,x);
    }
    point rotright()
    {
        return point(y,-x);
    }
    point rotate(point p,double angle)//�Ƶ�p��ʱ����תangle�Ƕ�
    {
        point v=this->sub(p);
        double c=cos(angle),s=sin(angle);
        return point(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);
    }
};
struct line
{
    point a,b;
    line(){}
    line(point _a,point _b)
    {
        a=_a;
        b=_b;
    }
    bool operator==(line v)
    {
    	return (a==v.a)&&(b==v.b);
    }
    //��б��angle
//    line(point p,double angle)
//    {
//    	a=p;
//    	if (dblcmp(angle-pi/2)==0)
//    	{
//    		b=a.add(point(0,1));
//    	}
//    	else
//    	{
//    		b=a.add(point(1,tan(angle)));
//    	}
//    }
//    //ax+by+c=0
//    line(double _a,double _b,double _c)
//    {
//    	if (dblcmp(_a)==0)
//    	{
//    		a=point(0,-_c/_b);
//    		b=point(1,-_c/_b);
//    	}
//    	else if (dblcmp(_b)==0)
//    	{
//    		a=point(-_c/_a,0);
//    		b=point(-_c/_a,1);
//    	}
//    	else
//    	{
//    		a=point(0,-_c/_b);
//    		b=point(1,(-_c-_a)/_b);
//    	}
//    }
    void input()
    {
        a.input();
        b.input();
    }
    void adjust()
    {
    	if (b<a)swap(a,b);
    }
    double length()
    {
        return a.distance(b);
    }
//    double angle()//ֱ����б�� 0<=angle<180
//	{
//		double k=atan2(b.y-a.y,b.x-a.x);
//		if (dblcmp(k)<0)k+=pi;
//		if (dblcmp(k-pi)==0)k-=pi;
//		return k;
//	}
    //����߶ι�ϵ
    //1 ����ʱ��
    //2 ��˳ʱ��
    //3 ƽ��
    int relation(point p)
    {
        int c=dblcmp(p.sub(a).det(b.sub(a)));
        if (c<0)return 1;
        if (c>0)return 2;
        return 3;
    }
    bool pointonseg(point p)
    {
        return dblcmp(p.sub(a).det(b.sub(a)))==0&&dblcmp(p.sub(a).dot(p.sub(b)))<=0;
    }
    bool parallel(line v)
    {
        return dblcmp(b.sub(a).det(v.b.sub(v.a)))==0;
    }
    //2 �淶�ཻ
    //1 �ǹ淶�ཻ
    //0 ���ཻ
    int segcrossseg(line v)
    {
        int d1=dblcmp(b.sub(a).det(v.a.sub(a)));
        int d2=dblcmp(b.sub(a).det(v.b.sub(a)));
        int d3=dblcmp(v.b.sub(v.a).det(a.sub(v.a)));
        int d4=dblcmp(v.b.sub(v.a).det(b.sub(v.a)));
        if ((d1^d2)==-2&&(d3^d4)==-2)return 2;
        return (d1==0&&dblcmp(v.a.sub(a).dot(v.a.sub(b)))<=0||
                d2==0&&dblcmp(v.b.sub(a).dot(v.b.sub(b)))<=0||
                d3==0&&dblcmp(a.sub(v.a).dot(a.sub(v.b)))<=0||
                d4==0&&dblcmp(b.sub(v.a).dot(b.sub(v.b)))<=0);
    }
    int linecrossseg(line v)//*this seg v line
    {
        int d1=dblcmp(b.sub(a).det(v.a.sub(a)));
        int d2=dblcmp(b.sub(a).det(v.b.sub(a)));
        if ((d1^d2)==-2)return 2;
        return (d1==0||d2==0);
    }
    //0 ƽ��
	//1 �غ�
	//2 �ཻ
    int linecrossline(line v)
    {
        if ((*this).parallel(v))
        {
            return v.relation(a)==3;
        }
        return 2;
    }
    point crosspoint(line v)
    {
        double a1=v.b.sub(v.a).det(a.sub(v.a));
        double a2=v.b.sub(v.a).det(b.sub(v.a));
        return point((a.x*a2-b.x*a1)/(a2-a1),(a.y*a2-b.y*a1)/(a2-a1));
    }
};
const int N = 21;
double a[N] , l , r;
#define Point2D point
Point2D p[N];
int n;
double dp[N];
line XX;
double f(double now , int k){
    if (dblcmp(now - r) >= 0) return r;
    double rad = p[k].rad(Point2D(now , 0) , Point2D(r , 0));
//    printf("%.9lf\n" , rad);
    if (dblcmp(rad - a[k]) <= 0) return r;
    point dd = point(now , 0);
    dd = dd.rotate(p[k] , a[k]);
    dd = line(p[k] , dd).crosspoint(XX);
    return dd.x;
}
void solve(){
    XX = line(point(l , 0) , point(r , 0));
    RST(dp);
    for (int i = 0 ; i < n ; ++i){
        p[i].input();
        cin >> a[i];
        a[i] *= PI / 180.;
    }
    double ans = 0;
    dp[0] = l;
    for (int i = 0 ; i < _1(n) ; ++i){
        checkMax(ans , dp[i]);
        for(int j = 0 ; j < n ; ++j) if ((i & _1(j)) == 0){
            checkMax(dp[(i | _1(j))] , f(dp[(i)] , j));
        }
    }
    checkMin(ans , r);
    printf("%.9lf\n" , ans - l);
}
int main(){
    cin >> n >> l >> r; solve();
}


#include <stdio.h>
#include <algorithm>
struct list
{
    int x, y, deg;
};
list data[22];
int n, l, r;
double D[1100000][22], eps = 1e-6;
const double pi = 3.1415926535;
bool cmp(double x)
{
    if(-eps <= x && x <= eps) return true;
    return false;
}
void dfs(int state, int end)
{
    if(D[state][end] != 0) return;
    for(int i=1; i<=n; i++){
        if(state == (1 << (i-1))){
            double z = l;
            double x = data[i].x, y = data[i].y, theta = data[i].deg / 180. * pi;
            double ll = sqrt((x - z) * (x - z) + y * y);
            double alpha = asin(y / ll);
            if(z < x){
                if(cmp(alpha + theta - pi / 2)) D[state][end] = std::max<double>(D[state][end], x - l);
                else{
                    double nl = ll * cos(alpha) - y / tan(alpha + theta);
                    D[state][end] = std::max<double>(D[state][end], nl);
                }
            }else{
                if(theta >= alpha - eps) D[state][end] = r - l;
                else{
                    double nl = y * (tan(pi / 2 - alpha + theta) - tan(pi / 2 - alpha));
                    D[state][end] = std::max<double>(D[state][end], nl);
                }
            }
            D[state][end] = std::min<double>(D[state][end], r - l);
            return;
        }
    }
    for(int i=1; i<=n; i++){
        if(i == end) continue;
        if(!(state & (1 << (i - 1)))) continue;
        int nstate = state - (1 << (end - 1)) - (1 << (i - 1));
        dfs(nstate, i);
        double z = l + D[nstate][i];
        double x = data[i].x, y = data[i].y, theta = data[i].deg;
        double ll = sqrt((x - z) * (x - z) + y * y);
        double alpha = asin(y / ll);
        if(z < x){
            if(cmp(alpha + theta - pi / 2)) D[state][end] = std::max<double>(D[state][end], x - l);
            else{
                double nl = ll * cos(alpha) - y / tan(alpha + theta);
                D[state][end] = std::max<double>(D[state][end], D[nstate][i] + nl);
            }
        }else{
            if(theta >= alpha - eps) D[state][end] = r - l;
            else{
                double nl = y * (tan(pi / 2 - alpha + theta) - tan(pi / 2 - alpha));
                D[state][end] = std::max<double>(D[state][end], D[nstate][i] + nl);
            }
        }
    }
    D[state][end] = std::min<double>(D[state][end], r - l);
}
int main()
{
    double ans = 0;
    scanf("%d%d%d", &n, &l, &r);
    for(int i=1; i<=n; i++) scanf("%d%d%d", &data[i].x, &data[i].y, &data[i].deg);
    for(int i=1; i<=n; i++){
        dfs((1 << n) - 1, i);
        ans = std::max<double>(ans, D[(1 << n) - 1][i]);
    }
    printf("%.9lf\n", ans);
    return 0;
}


//#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ls o<<1
#define rs o<<1|1
#define pii pair<int,int>
#define fi first
#define se second
const double pi=acos(-1.0);
const double eps=1e-10;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
const int maxn=255;
ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,k;
ll fac[maxn],inv[maxn],dp[maxn][maxn];
ll qpow(ll a,ll p){
	ll res=1;
	while(p){
		if(p&1)res=res*a%mod;
		a=a*a%mod;
		p>>=1;
	}
	return res;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
	inv[1]=1;
	for(int i=2;i<=n;i++)inv[i]=inv[i-1]*qpow(i,mod-2)%mod;
}
ll comb(int a,int b){
	if(a==b)return 1;
	if(a<b)return 0;
	if(a==0||b==0)return 1;
	return fac[a]*inv[b]%mod*inv[a-b]%mod;
}
int main(void){
	//freopen("in.txt","r",stdin);
	init(250);
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)dp[1][i]=comb(n,i)*qpow(k-1,n-i)%mod;
	for(int i=2;i<=n;i++){
		for(int j=1;j<=n;j++){
			dp[i][j]=0;
			for(int x=1;x<=j-1;x++){
				dp[i][j]=(dp[i][j]+dp[i-1][x]*qpow(k,x)%mod*comb(n-x,j-x)%mod*qpow(k-1,n-j)%mod)%mod;
			}
			dp[i][j]=(dp[i][j]+dp[i-1][j]*(((qpow(k,j)-qpow(k-1,j))%mod+mod)%mod)%mod*qpow(k-1,n-j)%mod)%mod;
		}
	}
	printf("%lld\n",dp[n][n]);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 250;
const ll mod = (ll)1e9 + 7;

int n;
ll k, C[N][N], dp[N][N];

ll fpw(ll x, ll k, ll p) {
  ll ret = 1;
  while(k) {
    if(k & 1) ret = ret * x % p;
    x = x * x % p; k >>= 1;
  }
  return ret;
}

int main() {
  cin >> n >> k;
  C[0][0] = 1;
  for(int i = 1; i <= n; i++) {
    C[i][0] = 1;
    for(int j = 1; j <= i; j++) {
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
    }
  }
  dp[0][0] = 1;
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= n; j++) {
      for(int x = 0; x <= j; x++) {
        dp[i][j] += dp[i - 1][x] * C[n - x][j - x] % mod * ((fpw(k, x, mod) + mod - fpw(k - 1, x, mod) * (j == x)) % mod) % mod * fpw(k - 1, n - j, mod) % mod;
        dp[i][j] %= mod;
      }
    }
  }
  cout << dp[n][n] << endl;
  return 0;
}


#include <bits/stdc++.h>
#ifdef TOPOLOGY
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;

const int P = 1000000007;

int dp[256][256], nck[256][256];

inline void add(int &a, int b) {
	a += b;
	if (a >= P) a -= P;
}

inline int mul(int a, int b) {
	return 1LL * a * b % P;
}

inline void sub(int &a, int b) {
	a -= b;
	if (a < 0) a += P;
}

int pw(int a, int b) {
	if (b == 0) return 1;
	int res = pw(a, b / 2);
	if (b & 1) return mul(res, mul(res, a));
	return mul(res, res);
}

int main() {
	int n, k;
	cin >> n >> k;
	if (k == 1) {
		cout << 1 << endl;
		return 0;
	}
	nck[0][0] = 1;
	for (int i = 1; i <= n + 3; i++) {
		for (int j = 0; j <= i; j++) {
			nck[i][j] = nck[i - 1][j];
			add(nck[i][j], nck[i - 1][j - 1]);
		}
	}
	for (int j = 1; j <= n; j++) {
		dp[1][j] = mul(nck[n][j], pw(k - 1, n - j));
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			dp[i][j] = 0;
			for (int l = 1; l <= j; l++) {
				int res = pw(k, l);
				if (j == l) sub(res, pw(k - 1, l));
				res = mul(res, pw(k - 1, n - j));
				res = mul(res, nck[n - l][j - l]);
				add(dp[i][j], mul(res, dp[i - 1][l]));
			}
			// debug("dp[%d][%d] = %d\n", i, j, dp[i][j]);
		}
	}
	// for (int i = 1; i <= n; i++) {
	// 	for (int j = 1; j <= n; j++) {
	// 		debug("dp[%d][%d] = %d\n", i, j, dp[i][j]);
	// 	}
	// }
	cout << dp[n][n] << endl;
	return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const  ll inf  = 0x3f3f3f3f;
const int mod  = 1e9 + 7;
const int maxn = 1e6 + 6;
const int N    = 5e3 + 4;
const double eps = 1e-6;
ll qpow(ll x,ll y){ll ans=1;x%=mod;while(y){ if(y&1) ans=ans*x%mod; x=x*x%mod; y>>=1;}return ans;}

ll C[N][N],dp[N][N];
ll n,K;

int main(){

    for(int i=0;i<=250;i++) C[i][i]=1;
    for(int i=1;i<=250;i++){
        C[i][0]=C[i][i]=1;
        for(int j=1;j<i;j++){
            C[i][j]=C[i-1][j-1]+C[i-1][j];
            C[i][j]%=mod;
        }
    }
    scanf("%lld%lld",&n,&K);
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        int l=(i==1?0:1),r=(i==1?0:n);
        for(int j=l;j<=r;j++){
            for(int k=(i==1?1:0);k+j<=n;k++){
                dp[i][j+k]+=dp[i-1][j]*C[n-j][k]%mod*qpow(K,j)%mod*qpow(K-1,n-j-k)%mod;
                dp[i][j+k]%=mod;
                if(k==0) {
                    dp[i][j+k]-=dp[i-1][j]*qpow(K-1,n)%mod;
                    dp[i][j+k]+=mod;dp[i][j+k]%=mod;
                }
            }
        }
    }

    printf("%lld\n",dp[n][n]);
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#define N 100005
using namespace std;
typedef long long ll;
int a[202],b[202];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int f=1,m=0,z=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(i&&a[i]<m&&a[i])f=0;
        m=max(m,a[i]);
        if(a[i]==0)z=i;
    }
    for(int i=0;i<k;i++)
        scanf("%d",&b[i]);
    sort(b,b+k);
    if(k==1&&f&&z>0){
        if(b[0]>a[z+1]||b[0]<a[z-1])f=0;
    }
    if(k>1)f=0;
    if(!f)printf("YES\n");
    else printf("NO\n");
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int a,b,c[100],e;
    cin>>a>>b;
    if(b>=2)
    {
        cout<<"Yes";
        goto ed;
    }
    for(int i=0;i<a;i++)
    {
        cin>>c[i];
    }
    cin>>e;
    for(int i=1;i<a;i++)
    {
        if(c[i]==0)
        {
            if(c[i-1]>e)
            {
                cout<<"Yes";
                goto ed;
            }
        }
        else if(c[i-1]>c[i])
        {
            cout<<"Yes";
            goto ed;
        }
    }
    cout<<"No";
    ed:;
}


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

int n,k;
int a[200];
int b[200];

bool checknotinc(int s[],int c){
	for (int i = 0;i<c-1;i++){

		 if (s[i] > s[i+1]){

 			return true;
 		}
	}
	return false;
}

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

    int j = 0;
   	for (int i = 0;i<n;i++){
		if (a[i] == 0) {
			a[i] = b[j];
			j++;
			if (j > k) break;
		}
	}

       if (checknotinc(a,n)){
       	cout<<"YES";
       }else{
       	cout<<"NO";
       }
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
template<class T>
inline void read(T& x)
{
	char c = getchar(); T p = 1, n = 0;
	while(c < '0' || c > '9'){if(c == '-') p = -1; c = getchar();}
	while(c >= '0' && c <= '9'){n = n * 10 + c - '0'; c = getchar();}
	x = p * n;
}
template<class T, class U>
inline void read(T& x, U& y){read(x), read(y);}
template<class T, class U, class V>
inline void read(T& x, U& y, V& z){read(x), read(y), read(z);}
int main()
{
	int n, k; read(n, k);
	bool isInc = true; int last = -1, cnt0 = 0;
	for(int i = 0, a; i < n; i++)
	{
		read(a); if(a == 0) cnt0++;
		else
		{
			if(isInc && last > a) isInc = false;
			else if(isInc) last = a;
		}
	}
	puts(isInc && k <= 1 ? "No" : "Yes");
	return 0;
}


#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define endl "\n"
#define LL long long int
#define vi vector<int>
#define vl vector<LL>
#define all(V) V.begin(),V.end()
#define scs(s) scanf("%s",s)
#define pii pair<int,int>
#define pll pair<LL,LL>
#ifndef ONLINE_JUDGE
#define cout cerr
#endif
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#define cmax(a,b) ((a) = (a) > (b) ? (a) : (b))
#define cmin(a,b) ((a) = (a) < (b) ? (a) : (b))
#define debug(x)  cerr << #x << " = " << x << endl
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
template <typename T> vector<T>& operator << (vector<T> &__container, T x){ __container.push_back(x); return __container; }
template <typename T> ostream& operator << (ostream &out, vector<T> &__container){ for(T _ : __container) out << _ << ' '; return out; }
void sci(){}
template<typename... Args> void sci(int &x, Args&... args){ scanf("%d",&x); sci(args...); }
void scl(){}
template<typename... Args> void scl(LL &x, Args&... args){ scanf("%lld",&x); scl(args...); }
const int MAXN = 107;
const int N = 107;
const int MOD = 1e4+7;
struct Matrix{
    int mat[N][N];
    Matrix(int x = 0){ for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) mat[i][j] = i == j ? x : 0; }
    int* operator [](const int idx){ return mat[idx]; }
    Matrix operator * (Matrix rhs){
        Matrix ret(0);
        for(int i = 0; i < N; i++) for(int j = i; j < N; j++) for(int k = i; k <= j; k++)
            ret[i][j] = (ret[i][j] + mat[i][k] * rhs[k][j]) % MOD;
        return ret;
    }
    // Matrix fast power
    Matrix operator ^ (int b){
        Matrix ret(1), A(*this);
        while(b){
            if(b&1) ret = ret * A;
            b >>= 1;
            A = A * A;
        }
        return ret;
    }
};
char s[MAXN];
int n, m, f[MAXN][MAXN][MAXN], g[MAXN];
void solve(){
    scs(s+1); sci(m);
    n = strlen(s+1);
    f[1][n][0] = 1;
    for(int i = 1; i <= n; i++) for(int j = n; j >= i; j--) for(int k = 0; k <= n - j + i - 1; k++){
        if(s[i]==s[j]){
            if(i+1>=j) g[k] = (g[k] + f[i][j][k]) % MOD;
            else f[i+1][j-1][k] = (f[i+1][j-1][k] + f[i][j][k]) % MOD;
        }else{
            f[i+1][j][k+1] = (f[i+1][j][k+1] + f[i][j][k]) % MOD;
            f[i][j-1][k+1] = (f[i][j-1][k+1] + f[i][j][k]) % MOD;
        }
    }
    Matrix M(0),S(0);
    S[0][1] = 1; S[0][N-(n+1)/2] = g[0];
    // edge from ith red vectex to [(n-i)/2]th green vertex, [x] means get ceil of x
    int N = n + (n + 1) / 2 + 1;
    M[N][N] = 26;                       // Final state selfloop
    for(int i = 1; i <= n; i++){
        M[i][N-(n-i+1)/2] = g[i];       // transform to green vertex
        M[i][i] = 24;          // red vertex selfloop, exclude the start state
        if(i!=n) M[i][i+1] = 1;       // tranform to next red vertex, until the last red vertex
    }
    for(int i = n + 1; i < N; i++) M[i][i+1] = 1, M[i][i] = 25; // green vertex selfloop and transform to next state
    if((n+m)&1){
        S = S * (M ^ ((n+m+1)>>1));
        int ret = S[0][N];
        // this resault include the illeagle state which transform from the state represent two same characters to final state
        // so we should minus the illeagle transform
        for(int i = 0; i < ::N; i++) for(int j = 0; j < ::N; j++) S[i][j] = M[i][j] = 0;
        memset(g,0,sizeof(g));
        for(int i = 1; i < n; i++) if(s[i]==s[i+1]) for(int k = 0; k <= n; k++) g[k] = (g[k] + f[i][i+1][k]) % MOD;
        S[0][1] = 1; S[0][N-(n+1)/2] = g[0];
        for(int i = 1; i <= n; i++){
            M[i][N-(n-i+1)/2] = g[i];       // transform to green vertex
            M[i][i] = 24;          // red vertex selfloop, exclude the start state
            if(i!=n) M[i][i+1] = 1;       // tranform to next red vertex, until the last red vertex
        }
        for(int i = n + 1; i < N; i++) M[i][i+1] = 1, M[i][i] = 25; // green vertex selfloop and transform to next state
        S = S * (M ^ ((n+m+1)>>1));
        ret = (ret - S[0][N] + MOD) % MOD;
        cout << ret << endl;
    }else{
        S = S * (M ^ ((n+m+1)>>1));
        cout << S[0][N] << endl;
    }
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("Local.in","r",stdin);
    freopen("ans.out","w",stdout);
    #endif
    solve();
    return 0;
}


#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=100005;
int n,m,k,p;
LL h[N],a[N],day[N];
struct cmp{
	bool operator () (int a,int b){
		if (day[a]!=day[b])
			return day[a]<day[b];
		return a<b;
	}
};
set <int,cmp> S;
LL now[N];
int check(LL x){
	S.clear();
	For(i,1,n){
		now[i]=x,day[i]=now[i]/a[i];
		S.insert(i);
	}
	Fod(d,m,1){
		For(j,1,k){
			int i=*S.begin();
			S.erase(S.begin());
			if (day[i]>=m){
				LL rem=k-j+1+(d-1)*k;
				For(i,1,n){
					LL v=now[i]-a[i]*m;
					while (v<h[i]){
						v+=p;
						if (!rem--)
							return 0;
					}
				}
				return 1;
			}
			else if (day[i]<=m-d){
				return 0;
			}
			else {
				now[i]+=p;
				day[i]=now[i]/a[i];
				S.insert(i);
			}
		}
	}
	For(i,1,n)
		if (now[i]-a[i]*m<h[i])
			return 0;
	outtag(1);
	return 1;
}
int main(){
	n=read(),m=read(),k=read(),p=read();
	For(i,1,n)
		h[i]=read(),a[i]=read();
	LL L=0,R=1e15,mid,ans=R;
	while (L<=R){
		mid=(L+R)>>1;
		if (check(mid))
			R=mid-1,ans=mid;
		else
			L=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <conio.h>
using namespace std;

int main(int argc, char** argv) {
	char ch;
	while(1)
    {
        ch = getch();
        cout<<ch;
            if(ch == 13) {
            	cout<<'\n';
            	cout<<25;
            return 0;
        }
    }
	return 0;
}


#include<cstdio>
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n%5==0)
    {
              cout<<n/5<<endl;
    }
    else if(n%5!=0)
    {
         cout<<(n/5)+1<<endl;
    }
    getch();
}


#include <iostream>
#include <conio.h>
using namespace std;

int main(int argc, char** argv) {
	char ch;
	while(1)
    {
        ch = getch();
            if(ch == 13) {
            	cout<<25;
            return 0;
        }
    }
	return 0;
}


#include <iostream>
#include <conio.h>
using namespace std;
main()
{
    int x,i,y ;
    cin>>x ;
    x-- ;
    y=5 ;
    for(i=1;i<=x;i++)
    {
       y=y*5 ;
    }
    y=y%100 ;
    cout<<y ;

	getch();
}


#include<bits/stdc++.h>
using namespace std;
int mx=1e8,p=2e8+1,cnt=0;
set<int>hok,hfailed,vok,vfailed;
bool checkh(int y){
    if(y>mx||y<-mx)return 0;
    if(hok.count(y))return 1;
    if(hfailed.count(y))return 0;
    for(int i=0;i<10;++i){
        int x=rand()%p-mx;
        printf("0 %d %d",x,y);
        ++cnt;
        fflush(stdout);
        scanf("%d",&x);
        if(x!=0){hfailed.insert(y);return 0;}
    }
    hok.insert(y);
    return 1;
}
bool checkv(int x){
    if(x>mx||x<-mx)return 0;
    if(vok.count(x))return 1;
    if(vfailed.count(x))return 0;
    for(int i=0;i<10;++i){
        int y=rand()%p-mx;
        printf("0 %d %d",x,y);
        ++cnt;
        fflush(stdout);
        scanf("%d",&y);
        if(y!=0){vfailed.insert(x);return 0;}
    }
    vok.insert(x);
    return 1;
}
int main()
{
    int x,y,d;
    while(cnt<2e5){
        x=rand()%p-mx;y=rand()%p-mx;
        printf("0 %d %d",x,y);
        fflush(stdout);
        scanf("%d",&d);
        ++cnt;
        checkh(y-d);checkh(y+d);
        checkv(x-d);checkv(x+d);
    }
    cout<<"1 "<<vok.size()<<" "<<hok.size()<<endl;
    for(auto x:vok)printf("%d ",x);cout<<endl;
    for(auto x:hok)printf("%d ",x);cout<<endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cmath>
#include<complex>
#include<vector>

using namespace std;

const int maxn = 1000006;

int n;
const int maxx = 1e8;
vector<int> ans, gor, ver;

int get_d(int x, int y) {
	cout << "0 " << x << " " << y << endl;
	fflush(stdout);
	int ans;
	cin >> ans;
	return ans;
}

void f(int l, int r) {
	int md = (l + r) >> 1;
	int dist = get_d(md, md);
	if (dist == 0) ans.push_back(md);
	f(md + dist, r);
	f(l, md - dist);
}

int main() {
	srand(194375);
	ios_base::sync_with_stdio(false);
	f(-maxx, maxx);
	for (int u : ans) {
		int t1 = rand() % maxx, t2 = rand() % maxx;
		if (get_d(u, t1) == 0 && get_d(u, t2) == 0) ver.push_back(u);
		else gor.push_back(u);
	}
	cout << "1 " << ver.size() << " " << gor.size() << endl;
	for (int u : ver) cout << u << " ";
	cout << endl;
	for (int u : gor) cout << u << " ";
	cout << endl;
	fflush(stdout);
	return 0;
}