/************************************************************
*    In the name of God, the Merciful, the Compassionate   *                                                 *
************************************************************/
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include<bits/stdc++.h>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
#define ll long long
#define ull      unsigned long long
#define LB lower_bound
#define UB upper_bound
#define pll             pair<ll,ll>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define si(a)			scanf("%d", &a)
#define sl(a)			scanf("%lld", &a)
#define pi(a)			printf("%d", a)
#define pl(a)			printf("%lld", a)
#define pn 				printf("\n")
using namespace std;
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}
// to reverse integer
int Reverse(int val)
{
int rev=0,rem;
while(val!=0)

{rem=val%10; rev=rev*10+rem; val/=10;}
    return rev;
}
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main()
{
    double l1,r1,l2,r2,k,n1,n2,n3,x,mycount,counter=0,g,j=0;
    cin>>l1>>r1>>l2>>r2>>k;
    if(l1==l2&&r1==r2)cout<<int(r1-l1)<<endl;
    else
    {
    vector<double>v;
   for(int i=l1;i<=r1;i++)if(i!=k)v.push_back(i);
   for(int i=l2;i<=r2;i++)if(i!=k)v.push_back(i);
   while(j!=v.size())
   {
       g=v[j];
     mycount = count (v.begin(),v.end(), g);
       if(mycount>1&&v[j]!=0.1){v[j]=0.1;counter++;}
       j++;

   }
   cout<<counter<<endl;
}
}


/************************************************************
*    In the name of God, the Merciful, the Compassionate   *                                                 *
************************************************************/
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include<bits/stdc++.h>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
#define ll long long
#define ull      unsigned long long
#define LB lower_bound
#define UB upper_bound
#define pll             pair<ll,ll>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define si(a)			scanf("%d", &a)
#define sl(a)			scanf("%lld", &a)
#define pi(a)			printf("%d", a)
#define pl(a)			printf("%lld", a)
#define pn 				printf("\n")
using namespace std;
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}
// to reverse integer
int Reverse(int val)
{
int rev=0,rem;
while(val!=0)

{rem=val%10; rev=rev*10+rem; val/=10;}
    return rev;
}
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main()
{
   long long  l1,r1,l2,r2,k,n1,n2,n3,x,mycount,counter=0,g,j=0;
    cin>>l1>>r1>>l2>>r2>>k;
    if(l1==l2&&r1==r2)cout<<int(r1-l1)<<endl;
    else
    {
    vector<long long>v;
   for(int i=l1;i<=r1;i++)if(i!=k)v.push_back(i);
   for(int i=l2;i<=r2;i++)
    {
        if(i!=k)v.push_back(i);
          g=i;
     mycount = count (v.begin(),v.end(), g);
      if(mycount>1&&v[j]!=0.1)counter++;
    }
   cout<<counter<<endl;
}
}


/************************************************************
*    In the name of God, the Merciful, the Compassionate   *                                                 *
************************************************************/
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include<bits/stdc++.h>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
#define ll long long
#define ull      unsigned long long
#define LB lower_bound
#define UB upper_bound
#define pll             pair<ll,ll>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define si(a)			scanf("%d", &a)
#define sl(a)			scanf("%lld", &a)
#define pi(a)			printf("%d", a)
#define pl(a)			printf("%lld", a)
#define pn 				printf("\n")
using namespace std;
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}
// to reverse integer
int Reverse(int val)
{
int rev=0,rem;
while(val!=0)

{rem=val%10; rev=rev*10+rem; val/=10;}
    return rev;
}
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main()
{
    double l1,r1,l2,r2,k,n1,n2,n3,x,mycount,counter=0,g,j=0;
    cin>>l1>>r1>>l2>>r2>>k;
    vector<double>v;
   for(int i=l1;i<=r1;i++)if(i!=k)v.push_back(i);
   for(int i=l2;i<=r2;i++)if(i!=k)v.push_back(i);
   while(j!=v.size())
   {
       g=v[j];
     mycount = count (v.begin(),v.end(), g);
       if(mycount>1&&v[j]!=0.1){v[j]=0.1;counter++;}
       j++;

   }
   cout<<counter<<endl;
}


/************************************************************
*    In the name of God, the Merciful, the Compassionate   *                                                 *
************************************************************/
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include<bits/stdc++.h>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
#define ll long long
#define ull      unsigned long long
#define LB lower_bound
#define UB upper_bound
#define pll             pair<ll,ll>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define si(a)			scanf("%d", &a)
#define sl(a)			scanf("%lld", &a)
#define pi(a)			printf("%d", a)
#define pl(a)			printf("%lld", a)
#define pn 				printf("\n")
using namespace std;
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}
// to reverse integer
int Reverse(int val)
{
int rev=0,rem;
while(val!=0)

{rem=val%10; rev=rev*10+rem; val/=10;}
    return rev;
}
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main()
{
   long long  l1,r1,l2,r2,k,n1,n2,n3,x,mycount,counter=0,g,j=0;
    cin>>l1>>r1>>l2>>r2>>k;
    if(l1==l2&&r1==r2)cout<<int(r1-l1)<<endl;
    else
    {
    vector<long long>v;
   for(int i=l1;i<=r1;i++)if(i!=k)v.push_back(i);
   for(int i=l2;i<=r2;i++)
    {
        if(i!=k)v.push_back(i);
          g=i;
     mycount = count (v.begin(),v.end(), g);
      if(mycount>1&&v[j]!=0.1)counter++;
       if(i!=k)v.pop_back();
    }
   cout<<counter<<endl;
}
}


#include<bits/stdc++.h>
 using namespace std;
 int main()
 {
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
     long long n;
     long long k;
     long long ans = 1;
     long long res;
     long long a[100];
     string s;
     cin >> s;
     n = s.length();
     for(int i = 0; i < n; i++)
     if(s[i] >= 'A' && s[i] <= 'Z' && !a[s[i] - 'A' + 1])
     {
      k++;
      a[s[i] - 'A' + 1] = 1;
     }
     for(int i = 0; i < n; i++)
     {
      if(s[i] == '?')
       ans *= 10;

     }
	    for(int i = 10; i >= 10 - k + 1; i--)
	    	ans *= i;
	    if((s[0] >= 'A' && s[0] <= 'Z' )|| (s[0] == '?'))
	    	ans -= ans / 10;
	    cout << ans << endl;
    return 0;
 }
 //s[i].size()
 //a=tolower(a) делает char переменную a маленькой,
//a=toupper(a), делает char переменную a большой
/*

 /*  %с – одиночный символ
     %d – десятичное целое число со знаком
     %f – число с плавающей точкой (десятичное представление)
     %s – строка символов (для строковых переменных)
     %u – десятичное целое без знака
     %% - печать знака процента
     printf(“Ваш возраст = %d, Ваш вес = %f”, age, weigth);
     */

/* if((j<n-abs(i-n/2)) and j>=abs(i-n/2))
          {
             cout << "D";
          }
          else
          {
             cout << "*";
          }*/


#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <limits>
#include <iomanip>
#include <cstdlib>
#include <iterator>
#include <functional>

#ifdef LOCALHOST
#include <fstream>
#endif // LOCALHOST

using namespace std;

#ifndef OMG
typedef unsigned			u;
typedef int					i;
typedef long				l;
typedef long long			ll;
typedef unsigned long long	ull;
typedef char				c;
#define b					begin()
#define e					end()
#define rb					rbegin()
#define re					rend()
#define mp					make_pair
#define r					return
#define sc					static_cast
#define v					vector
#define s					set
#define _it					iterator
#define _cit				const_iterator
#define _rit				reverse_iterator
#define _crit				const_reverse_iterator
#define f					for
#define w					while
#define cp					std::copy
#define oi					std::ostream_iterator
#endif // OMG

template<class T>
T fm(T number, T module)
{
	T result = 1;
	while(number > 1)
	{
		result = (result * ((number / module) % 2 ? module - 1 : 1)) % module;
		for(T it = 2
			; it <= (number % module)
			; ++it)
		{
			result = (result * it) % module;
		}
		number /= module;
	}
	return result % module;
}

//class sort1
//{
//public:
//	bool operator() (pair<,> X, pair<,> Y)
//	{

//	}
//};

#ifdef LOCALHOST
std::ifstream in("1.in", std::ifstream::in);
#endif // LOCALHOST

#ifdef LOCALHOST
#define is in
#else
#define is cin
#endif // LOCALHOST

ll my_pow(ll value, unsigned st)
{
	f(u it(1); it != st; ++it)
	{
		value *= value;
	}
	return value;
}

int main(int argc, char *argv[])
{
	std::ios_base::sync_with_stdio(false);
	string input;
	getline(cin, input);
	unsigned unknow(0);
	map<char, size_t> letters;
	bool front_unk(false), front_letter(false);
	f(u it(0); it != input.size(); ++it)
	{
		if(input[it] == '?')
		{
			++unknow;
			if(!it)
			{
				front_unk = true;
			}
		} else if(isalpha(input[it]))
		{
			++letters[input[it]];
			if(!it)
			{
				front_letter = true;
			}
		}
	}
	unsigned answer(1);
	if(unknow)
	{
		if(front_unk)
		{
			answer = my_pow(10, unknow - 1);
			answer *= 9;
		} else
		{
			answer = my_pow(10, unknow);
		}
	}
//	cout << "fu " << front_unk << endl;
//	cout << "fl " << front_letter << endl;
//	cout << "after unk " << answer << endl;
	if(letters.size())
	{
		if(front_letter)
		{
			answer *= 9;
			int all(9);
			for(u it(0); it < letters.size() - 1; ++it, --all)
			{
				answer *= all;
			}
		} else
		{
			int all(10);
			for(u it(0); it < letters.size(); ++it, --all)
			{
				answer *= all;
			}
		}
	}
	cout << answer;
	r 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char str[101000];
int main(){
	fgets(str,100999,stdin);
	int i = 0;
	while(!(str[i]=='\n'||str[i]=='/0')){
		if(str[i]=='?')putchar('1');
		else if(str[i]<='J'&&str[i]>='A')putchar(str[i]-'A'+'0');
		else putchar(str[i]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define f(i, x, n);for(lli i = x;i < n;i++)

int main()
{
	string s;
	cin >> s;
	int l = s.length();
	int x = 1, c = 0;
	char f;
	if(s[0] >= 63)
	{
		x *= 9;
		f = s[0];
		if(s[0] > 63)
		{
			c = 1;
		}
	}
	s.erase(s.begin());
	l--;
	sort(s.begin(), s.end());
	f(i, 0, s.length()-1)
	{
		if(s[i] == 63)
		{
			x *= 10;
			s.erase(s.begin() + i);
		}
		else if(s[i] == s[i+1] || s[i] == f)
		{
			s.erase(s.begin() + (i));
		}
		else if(s[i] < 58)
		{
			s.erase(s.begin() + i);
		}
		i = -1;
	}
	int t;
	if(c == 0)
	t = 10;
	else
	t = 9;
	f(i, 0, s.length())
	{
		x *= t;
		t--;
	}
	cout << x;

}


//In the name of God

#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define lol long long
bool can=false;
lol p[40];
map <lol,bool> c;
vector <lol> v;

lol calc(lol bit)
{
  lol ans=0;
  for(int i=0;i<=20;i++)
    if(bit&(1<<i))
      ans+=p[i];
  return ans;
}

int main()
{
  lol n,m,l;
  cin>>n>>m;
  int k=0;
  p[0]=1;
  for(int i=1;p[i-1]<=1e12 and i<=20;i++)
    p[i]=p[i-1]*n,k=i;
  k++;
  //v.push_back(0);
  //c[0]=true;
  for(lol i=0;i<(1<<20);i++)
    {
      lol x=calc(i);
      c[x]=true;
      //    cerr<<x<<endl;
      //int y;
      //cin>>y;
      v.push_back(x);
    }

  for(int i=0;i<v.size();i++)
    if(c[m+v[i]])
      {
	cout<<"YES"<<endl;
	return 0;
      }
  cout<<"NO"<<endl;
  return 0;
}


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

int w, m;
int pw[10000];
int s[1000000];

int main()
{
    cin >> w >> m;
    int i = 0;
    while (m != 0)
    {
        s[i++] = m%w;
        m /= w;
    }
    int n = i;
    for (int i = 0; i < n; ++i)
    {
        if (s[i] == 0) continue;
        if (s[i] == 1) continue;
        else if (s[i] == w-1) s[i+1]++;
        else {cout << "NO"; return 0;}
    }
    cout << "YES" << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<set>
#include<iomanip>
#include<complex>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include<bitset>
#include<memory.h>
#include<cassert>
#include<ctime>
//#include "algo_templates/AdvancedMath.cpp"

using namespace std;

#pragma comment(linker, "/STACK:36777216")

#define For(i,l,r) for (int i = l; i < r + 1; i ++)
#define ForI(it , s , T) for (T :: iterator it = s.begin(); it != s.end() ; ++ it )
#define LL long long
#define iinf 2000000000
#define linf 4000000000000000000LL
#define MOD  (1000000007)
#define Pi 3.1415926535897932384
#define bit(mask,i) ((mask>>i)&1)
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define sqr(x) ((x)*(x))
#define pause cin.get();cin.get();
#define fir first
#define sec second
#define ln(x) log(x)
#define pii pair<int,int>
#define log log24

const int Nmax = 200100;
const int Direction[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

template <typename T1, typename T2>
long long BinPower(T1 basis, T2 degree)
{
     long long answer = 1;
     long long __basis = basis;
     for (;degree > 0;degree>>=1)
     {
         if (degree&1) answer *= __basis;
         __basis*=__basis;
     }
     return answer;
}
vector<LL> list;

int main() {
    ios_base::sync_with_stdio(0);
    long long w,m;
    cin >> w >> m;

    if (w <= 3) {
          cout << "YES\n";
          return 0;
    }

    vector<LL> bin(10000,0);
    for (LL d = m, i = 0; d > 0; d /= w,i ++)
        bin[i] = (d % w);
    bin.resize(10000);
    for (int i = 0 ;i < bin.size(); i ++) {
        if (bin[i] == 1 || bin[i] == 0) continue;
        if (bin[i] == w - 1) {
           bin[i] = -1;
           bin[i + 1] ++;
        }
        else {
             cout << "NO\n";
             return 0;
        }
    }
    cout << "YES\n";
    //pause;
    return 0;

    list.push_back(1);
    for (long long i = 1; i < 20 && list.back() <= m; i ++) {
        list.push_back(BinPower(w,i));
    }

    long long n = list.size();
    assert(n >= 2 && n <= 16);
       for (long long mask = 0 ;mask < (1 << n); mask ++) {
           for (long long sub = mask; sub > 0; sub = (sub - 1) & m) {
               LL sum = 0;
               for (long long i = 0; i < n ;i ++) {
                   if (bit(mask,i)) {
                      if (bit(sub,i))
                         sum -= list[i];
                      else
                          sum += list[i];
                   }
               }
               if (sum == m) {
                       cout << "YES\n";
                       return 0;
               }
           }
           LL sum = 0;
           for (LL i = 0; i < n; i ++)
               if (bit(mask,i)) sum += list[i];
           if (sum == m) {
                   cout << "YES\n";
                   return 0;
           }
       }
       cout << "NO\n";
    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 <ctime>

using namespace std;
const double eps=1e-8;
const int maxn=100005;
typedef long long ll;
typedef pair<int,int> pii;

bool used[200];
int main() {
    ll w,m;
    cin>>w>>m;
    bool f=0;
    vector<ll> v;
    while(m) {
        v.push_back(m%w);
        m/=w;
    }
    if(v.size()>101) {cout<<"NO"<<endl;return 0;}
    v.resize(maxn);
    for(int i=0;i<v.size();i++) {
        if(v[i]&&v[i]!=1&&v[i]!=w-1) {f=1;break;}
        if(v[i]&&v[i]==w-1&&v[i]!=1&&i<100) v[i+1]++;
        if(v[i]&&v[i]==w-1&&v[i]!=1&&i>=100) {f=1;break;}
    }
    if(f) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}


#include <iostream>

int main() {
  int p,g, n= 0 ;
  int c [p+1];
  std::cin >> p >> g;
  for(int i =0; i <p ;++i){
      std::cin >> c[i];
  }
  for(int z =0; z <p ;++z){
    if(c[z]>=c[g-1] && c[0]>0){
      n++;
    }
  }
  std::cout << n;
}


#include<iostream>
using namespace std;
int main()
{
      int n,k,a[n];
      cin>>n>>k;
      for(int i=0;i<n;i++)
      {
            cin>>a[i];
      }
      int score=a[k-1];
      int count=0;
      for(int j=0;j<n;j++)
      {
            if(a[j]>=score && (score!=0 || a[j]!=0))
            count++;
            else if(a[j]<score)
             break;
      }
      cout<<count;

      return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n, k, count, c, ind;
    cin >> n >> k;
    vector<int> vec;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (i = k -1) c = x;
        vec.push_back(x);
    }
    ind = 0;
    while(true) {
       if( vec[ind] >= c) count++;
       else break;
       ind ++;
    }
    cout << count ;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
long long int n,k,A[n],c=0;
cin>>n>>k;
for(int i=1;i<=n;i++)
{cin>>A[i];
}
if(A[k]!=0)
{
for(int j=1;j<=n;j++)
{
if(A[j]>=A[k])
c++;
}
cout<<c;
}
else
cout<<0;
return 0;
}


    /*
            A A A           L               L                   A A A           H       H
           A     A          L               L                  A     A          H       H
          A A A A A         L               L                 A A A A A         H H H H H
         A         A        L               L                A         A        H       H
        A           A       L L L L L       L L L L L       A           A       H       H
    */

    #include<bits/stdc++.h>

    #define int long long int
    #define mp make_pair
    #define pb push_back

    using namespace std;

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

        vector<string> v;
        string str, tmp;
        cin >> str;
        for (int i=str.size()-3;i>=0;i--) {
            if (str[i]=='W' && str[i+1]=='U' && str[i+2]=='B') {
                str[i]=' ';
                str[i+1]=' ';
                str[i+2]=' ';
            }
        }
        for (int i=0;i<str.size();i++) {
            if(str[i]!=' '){
            tmp="";
            while(str[i]!=' ' && i<str.size()){
                tmp+=str[i];
                i++;
            }
            v.pb(tmp);
            }
        }
        for(int i=0;i<v.size();i++){
            cout << v[i] << " ";
        }
    }


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

int main()
{
    string song,b="";
    getline(cin,song);
    int i=0;

while (song[i] != '\0')
    {
        if (song[i] == 'W' && song[i+1] == 'U' &&  song[i+2] == 'B') {

            if (i != 0 && b[i-1] != ' ') b=b+' ';
            i+=3; }

            else  { b =b+song[i]; i++;}

    }
    cout<<b;
 }


#include <bits/stdc++.h>

using namespace std;

struct odd : public unary_function<int, bool> { bool operator () (int x) const { return (x % 2) != 0; } };
void dis(int *Array, int N) { for(int i = 0; i < N; ++i) {std::cout.width(1); std::cout << Array[i];} std::cout << std::endl;}
signed fac(int n){return (n==1 || n==0) ? 1: n * fac(n - 1);}
bool V(char x) {return (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'); }
template<typename T, typename U> inline signed  amin(T &x, U y) { if(y < x) x = y; return x;}
template<typename T, typename U> inline signed  amax(T &x, U y) { if(x < y) x = y; return x;}
//signed m(){long long T, pp,p,ppp, ct, nn, xx; cin >> p; cin.ignore(); for(int k=0;k<n;k++){for(int l=0;l<(k+1);l++){cin>>a[k][l];}}
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w",stdout)
#define all(cont) cont.begin(), cont.end()
#define ll          long long
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(int i=a;i<b;i++)

ll n,E,E1,D=0,c,m,D1,k=0,arr[12345][12345],b[12345],max1=0,a,d,e,f,flag=0,max2=0,l=0;

vector<int>fi,fi1;
string s,s1,s2;
std::vector<int>::iterator low1, low2;

int main () {
    //inn; outt;

for(ll int i=0; i<5; i++)
{
    for(ll int j=0; j<5; j++)
    {
        cin>>arr[i][j];
    }
}
for(int i=0;i<5;i++)
{
    for(int j=0;j<5;j++)
    {
         fi.push_back(arr[i][j]);
     }
}
std::vector<int>::iterator it = std::find(fi.begin(), fi.end(), 1);
int index = std::distance(fi.begin(), it);
cout<<abs(index-12);

   return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int x=0,y=0;
	int matris[5][5];
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			cin>>matris[i][j];
	}	}
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			while(matris[i][j] == 1){
				if(i>3)
					x=i-3;
				else if(i<3)
					x=3-i;
				if(j>3)
					y=j-3;
				else if(j<3)
					y=j-3;
				cout<<x+y<<endl;
			}

		}
	}
	return 0;
}


#include<iostream>
using namespace std;
char str[10000000000];
int main()
{
	char fr, sc,swap;
	short int n, m, small;
	cin >> n >> m;
	if (n > m)
	{
		if (m % 2)
		{
			fr = 'B';
			sc = 'R';
		}
		else
		{
			fr = 'R';
			sc = 'B';
		}
		small = m;
	}
	else
	{
		if (n % 2)
		{
			fr = 'R';
			sc = 'B';
		}
		else
		{
			fr = 'B';
			sc = 'R';
		}
		small = n;
	}
	for (int i = 0; i < small*2 ; i++)
	{
		str[i]= fr;
		str [++i]= sc;
		swap = sc;
		sc = fr;
		fr = swap;
	}
	fr = 'B';
	if (m<n)
		fr = 'R';
	for (int i = small * 2; i < (n + m) ; i++)
		str[i]= fr;
	int p = 0, v = 0;
	for (int i = 0; i < strlen(str); i++)
	{
		if (i == 0)
			continue;
		if (str[i] == str[i - 1])
			++p;
		else
			++v;
	}
	cout << p << " " << v;

	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int max(int a, int b ){
  return (a>b)?a:b;
}
int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int> > score(n+1,vector<int>(m+1,0));
  for(int i = 1 ; i <= m ; i++)
    score[0][i]=i-1;
  for(int i = 1 ; i <=n ; i++)
    score[i][0]=i-1;
  for(int i = 1 ; i <= n ; i++){
    for(int j = 1 ; j <= m ; j++){
      score[i][j]=max(score[i-1][j],score[i][j-1]);
    }
  }
  cout << score[n][m]  <<  " " <<  n+m-1-score[n][m] << endl;
}


#include <bits/stdc++.h>

#define int long long
using namespace std;

signed main() {
    // Turn off synchronization between cin/cout and scanf/printf
    ios_base::sync_with_stdio(false);
    // Disable automatic flush of cout when reading from cin cin.tie(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int>input(n);
    for (int i = 0; i < n; ++i) {
        cin >> input[i];
    }

    int shift = -1;
    int index;
    for (int i = 0; i < n; ++i) {
        if(input[i]<input[(i+n-1)%n]){
            if(shift!=-1){
                cout << -1;
                exit(0);
            }
            shift=(n-i)%n;
            index=i;
        }
    }

    if(input[index] > input[(index-1)%n]){
        cout << -1;
        exit(0);
    }
    cout << shift;
}


#include <iostream>
#include <algorithm>
#include <iterator>
#include <deque>
#include <vector>
#include <unordered_set>
#include <set>
#include <valarray>
#include <list>
#include <stack>
#include <array>
#include <iomanip>
#include <map>
#include <string>
#include <queue>
#include <sstream>
#include <iomanip>
#include <fstream>

using namespace std;

int main(int argc, char* argv[])
{
	size_t n, m, k;
	cin >> n >> m >> k;

	vector<size_t> t(n*m);
	for (size_t i = 1; i <= n; ++i)
		for (size_t j = 1; j <= m; ++j)
			t[(i-1)*m + j - 1] = i*j;

	nth_element(t.begin(), t.begin() + k - 1, t.end());

	cout << t[k-1] << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m,k;
	cin >> n >> m >> k;
	long long a[n*m];
	int cnt = 0;
	if(k == 1)
	{
		cout << 1;
		return 0;
	}
	for(long long i=1; i <= n; i++)
	{
		for(long long j = 1; j <= m; j++)
		{
			a[cnt] = i*j;
			cnt++;
		}
	}
	sort(a,a+(n*m));
	cout << a[k-1];
	return 0;
}


#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;
typedef long long ll;
const int M=500050;
ll a[M];

int main()
{
    int n,m;
    ll k;
    while(~scanf("%d %d %I64d",&n,&m,&k))
    {
        memset(a,0,sizeof(a));
        if(n>m) swap(n,m);
        for(ll tp=1; tp<=n;tp++)
        {
            ll i=tp*tp;
            a[i]++;
            for(ll j=i+tp; j<=m*tp; j+=tp)
            {
                 if(j<=n*tp) a[j]+=2;
                 else a[j]++;
            }
        }
        ll sum=0;
        for(ll i=1; i<=n*m; i++)
        {
            sum+=a[i];
            if(sum>=k)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a,b;
int main() {
	cin>>a>>b;
	cout<<min(a,b)<<" "<<(a+b-(2*min(a,b)))/2<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //ifstream cin("in.in");
    ll r, b, aaa;
    cin >> r >> b;
    aaa = min(r, b);
    cout << aaa;
    r -= aaa;
    b -= aaa;
    r = max(r, b);
    cout << ' ' << r/2;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int ans1=min(a,b);
    int ans2=(max(a,b)-min(a,b))/2;
    cout<<ans1<<" "<<ans2<<endl;
    return 0;
}


#include<conio.h>
#include<locale>
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if (a > b)
	{
		cout << b << " " << (a-b)/2;
	}
	else if (a < b)
	{
		cout << a << " " << (b-a)/2;
	}
	else cout << a << " 0";
	_getch();
}


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

#define MAX 200002
#define SPEED ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;

vector<int>adj[MAX];
bool vis[MAX] = {false};
int cnt[100002];

int main() {
	SPEED;

	int a,b,x;cin>>a>>b>>x;
	string s(a,'1');
	string ss(b,'0');
	s += ss;

	if(x%2==0 && a>1){
		int tmp = x/2-1;
		cout<<0;a--;
		for(int i=0;i<tmp;i++) cout<<"10";
		a-=tmp;
		b-=tmp;
		for(int i=0;i<b;i++)cout<<1;
		for(int i=0;i<a;i++)cout<<0;
	}else
	{
		int tmp = x/2;
		for(int i=0;i<tmp;i++) cout<<"10";
		a-=tmp;
		b-=tmp;
		for(int i=0;i<b;i++)cout<<1;
		for(int i=0;i<a;i++)cout<<0;
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=205;

int a,b,x,n,t;
int ans[maxn];

int main(){
	n=2;
	cin>>a>>b>>x;
	t=x;
	ans[0]=a;
	ans[1]=b;
	x--;
	bool gt=0;
	while(x!=0){
		for(int i=n%2;i<n;i+=2){
			if(ans[i]>1){
				ans[i]--;
				ans[n++]=1;
				gt=1;
				x--;
				break;
			}
		}
		if(gt==0) break;
	}
	if(!gt){
		n=2;
		x=t-1;
		ans[0]=b;
		ans[1]=a;
		while(x!=0){
			for(int i=n%2;i<n;i+=2){
				if(ans[i]>1){
					ans[i]--;
					ans[n++]=1;
					x--;
					break;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<ans[i];j++){
			cout<<!gt;
		}
		gt=!gt;
	}
	return 0;
}


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

#define ll  long long int
#define test() int t;cin>>t;while(t--)

int main()
{
    test()
    {
        ll n,ans=0;
        cin>>n;
        for(ll i=2;i<1000000;i++)
        {
           if(n%i==0)
           {
               ans=i;break;
           }
        }
        cout<<abs(n-n/ans)<<" "<<n/ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define N 1000000007;

using namespace std;
vector<int>Sieve(int n)
{
    vector<int>v;
	bool prime[n+1];
	memset(prime, true, sizeof(prime));

	for (int p=2; p*p<=n; p++)
	{
		if (prime[p] == true)
		{
			for (int i=p*p; i<=n; i += p)
				prime[i] = false;
		}
	}
	for (int p=2; p<=n; p++)
	if (prime[p])
		v.push_back(p);
    return(v);
}
int main()
{
 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 int t;
 cin>>t;
 vector<int>v=Sieve(10^5);
 while(t--)
 {
     int n;
     cin>>n;
     vector<int>prime;
     for(int i=0;i<sqrt(n);i++)
     {
         if (n%v[i]==0)
         {
             prime.push_back(v[i]);
         }
     }
     cout<<n/(prime[0])<<" "<<n-n/(prime[0]);
     cout<<endl;

 }

return(0);
}


#include<bits/stdc++.h>
using namespace std;
int t,n,m;
int main(){
	cin>>t;
	while(t--){
		cin>>n;
		int c;
		if(n%2==0){
			printf("%d %d\n",n/2,n/2);
			continue;
		}
		else c=2;
		int tt;
		while(c*c<=n){
			if(n%c==0){
		//		printf("%d %d\n",n/c,n-(n/c));
				tt=c;
				break;
			}
			c++;
		}
		printf("%d %d\n",n/tt,n-(n/tt));
	}
	return 0;
}


#pragma GCC optimize("O3")

#include <bits/stdc++.h>
#define nl "\n"
#define MAX 10e9
#define MAXN 100001
#define inf_int 2e9
#define inf_ll 2e18
#define e 1e-9
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpl vector<pair<ll, ll>>
#define vpc vector<pair<char, char>>
#define adj_list vector<vl>
#define umap unordered_map<ll, ll>
#define pll pair<ll, pair<ll, ll>>
#define clr(x) memset(x, 0, sizeof(x))
#define set(x, k) memset(x, k, sizeof(x))
#define f first
#define s second
ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); }
#define fastio                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;

ll spf[MAXN];
void sieve()
{
	spf[1] = 1;
	for (auto i = 2; i < MAXN; i++)
		spf[i] = i;
	for (auto i = 4; i < MAXN; i += 2)
		spf[i] = 2;
	for (auto i = 3; i * i < MAXN; i++)
	{
		if (spf[i] == i)
		{
			for (auto j = i * i; j < MAXN; j += i)
				if (spf[j] == j)
					spf[j] = i;
		}
	}
	return;
}

vl getFactorization(ll x)
{
	vl ret;
	while (x != 1)
	{
		ret.push_back(spf[x]);
		x = x / spf[x];
	}
	return ret;
}

void check()
{
	ll n;
	cin >> n;
	if (n % 2 == 0)
		cout << n / 2 << " " << n / 2 << endl;
	else
	{
		ll ans = 0;
		for(int i = 2;i<=sqrt(n);i++)
			if(n%i==0)
			{
				ans = i;
				break;
			}
		if(ans == 0)
			cout << 1 << " " << n-1 << endl;
		cout << n/ans << " " << n - n/ans << " " << endl;
	}
	return;
}

int32_t main()
{
	fastio;
	ll t = 1;
	cin >> t;
	while (t--)
		check();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j,n,p,k;
    cin>>n>>p>>k;
    if(p-k>1)
        cout<<"<< ";
    for(i=p-k;i<p;i++)
    {    if(p-k<=0)
            {
            if(p>1)
                i=1;
            else
                break;
            }
         cout<<i<<" ";
    }

    cout<<"("<<p<<") ";
    for(i=p+1;i<=p+k;i++)
        {
            cout<<i<<" ";
            if(i==n)
                return 0;
        }
       cout<<">>"<<endl;
}


// Author: Nikhil Shukla, Madan Mohan Malaviya University of Technology
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tt ll T; cin>>T; while(T--)
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define V vector
#define pb push_back
#define fir first
#define sec second
ll solve()
{
}
int main()
{
	//fast()
	tt
	{
		ll n,p,k;
		cin>>n>>p>>k;
		V<ll>pages(2*k+1);
		ll m=p-k;
		if(m>1)
		cout<<"<< ";
		for(ll i=0;i<2*k+1;i++)
		{
			if(m>0 && m<=n)
			{
				if(m==p)
				cout<<"("<<m<<") ";
				else
				cout<<m<<" ";
			}
			m++;
			if(m>n)
			break;
		}
		if(m<n)
		cout<<">>";
	}
	return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std; // namespace std;
int main(){
    int n,p,k,temp,symbol;int cnt[102];
    string result;
    cin >> n >> p >> k;
    for(int i = 0;i < 333;i++) cnt[i]=0;
    symbol = (p - k) < 1 ? 0 : 1;
    if(symbol == 1) cnt[0] =  -1;
    for(temp = (p - k) > symbol ? p - k : symbol;
        temp < (p + k) > n ? n + 1 : p + k + 1;temp++)
        cnt[symbol++] = temp;
    if(n + p < n) cnt[++symbol] = -2;
    for(int i = 0;i < symbol;i++)
        switch (cnt[i])
        {
        case -1:
            cout<<"<<"<<" ";
            break;
        case -2:
            cout<<">>";
            break;
        default:cout << cnt[i]<<" ";
            break;
        }
}


#include<stdio.h>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<set>
#include<iostream>
long long int arr[100000009]={0};
long long int f[3000000]={0};
using namespace std;

#define S(x) scanf("%d",&x)
#define St(x) scanf("%s",x)
#define P(x) printf("%d\n",x)
#define Ps(x) printf("%s\n",x)
#define P1(x) printf("%lld\n",x)
#define Pt(x) printf("%d ",x)
#define Y printf("YES\n")
#define N printf("NO\n")
#define mod 1000000009
int abs(int x){return x<0?-x:x;}
char a[51];
int main()
{
 int a,p,k,i;
 scanf("%d %d %d",&a,&p,&k);
 if(p<1||p>a)
    return 0;
 else
 {
     if((p-k)>0)
     {
        if(p-k!=1)
            printf("<< ");
        for(i=k;i>0;i--)
            printf("%d ",p-i);
    }
    else
    {
        for(i=p-k+1;i>0;i--)
            printf("%d ",i);

    }
    printf("(%d) ",p);
    if((p+k)<a)
     {

        for(i=1;i<=k;i++)
            printf("%d ",p+i);
            printf(">>");
    }
    else
    {
        for(i=p+1;i<=a;i++)
            printf("%d ",i);

    }
    return 0;
 }
}


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

using namespace std;

typedef long long ll;

#ifdef DEBUG
#define dbg(arg) (printf arg)
#define LOG cout << "line:" << __LINE__ << ":" << endl;
#else
#define dbg(arg)
#define LOG
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(15);
    int n, m;
    cin >> n >> m;
    vector<char> h(n);
    vector<char> v(m);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> v[i];
    }
    if (h[0] != h[n-1] && v[0] != v[m-1]) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int) (x).size())
#define mp make_pair
#define pb push_back
#define all(v) (v).begin( ), (v).end( )
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)

double pi = 3.1415926536;
const int oo = (int) 1e9;
const long long OO = numeric_limits<long long>::max();

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

int di[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dj[] = { 1, -1, 0, 0, 1, -1, 1, -1 };

int f1[] = { 0, 0, 0, 1, 1, 1, -1, -1, -1};
int f2[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};

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

    int n , m ;
    cin >> n >> m;
    vector<char>hoz(n) , vec(m);

    for(int i = 0 ; i < n ; i++){
        cin >> hoz[i];
    }

    for(int i = 0 ; i < m ; i++)
        cin >> vec[i];

    bool ok = true;

    char c1 = hoz[n - 1] , c2 = vec[m - 1];

    if(c1 == '>' && c2 == 'v')
        ok = false;

    c1 = hoz[0] , c2 = vec[0];

    if(c1 == '<' && c2 == '^' )
        ok = false;

    char c = hoz[0];

    bool ok2 = true;

    for(int i = 1 ; i < sz(hoz) ; i++){
            if(c == hoz[i])
                ok2 = false;
            else
                c = hoz[i] , ok2 = true;
    }

    c = vec[0];

    for(int i = 1 ; i < sz(vec)  ; i++){
        if(vec[i] == c)
            ok2 = false;

        else
            c = vec[i] , ok2 = true;
    }

    if(ok2 && ok)
        cout << "YES";
    else
        cout << "NO";
}


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

    using namespace std;

bool res1,res2;
int n, m;
int main(){
    string s;
    cin >> m >> n;
    cin >> s;
    int i,j;
    res1=res2=true;
    i=0; j=s.size()-1;
    while (i<j){
        if (s[i]==s[j]) res1=false;
        i++; j--;
    }
    cin >> s;

    i=0; j=s.size()-1;
    while (i<j){
        if (s[i]==s[j]) res2=false;
        i++; j--;
    }
    if (res1==true && res2==true) cout << "YES";
    else
        cout << "NO";
 return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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 <ctime>
#include <memory.h>
#include <cassert>
#include <queue>

using namespace std;

int n, m;

int main()
{
#ifdef M_DEF_TIMUS_DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // !ONLINE_JUDGE

	cin >> n >> m;

	string s, t;
	cin >> s;
	cin >> t;

	if (s[0] != s[n - 1] && t[0] != t[m - 1])
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}

	return 0;
}


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

using namespace std;

long long sz[100];

long long calc(int p, long long n){
    if (n == 1) return sz[p] = 1ll;
    sz[p] = 1ll + 2ll * calc(p + 1, n / 2);
}

long long ffind(int p, long long n, long long indx){
    if (n == 1) return 1ll;
    if (indx == sz[p] / 2 + 1) {
        return n % 2;
    }
    if (indx <= sz[p] / 2){
        return ffind(p + 1, n / 2, indx);
    }
    if (indx > sz[p] / 2 + 1){
        return ffind(p + 1, n / 2, indx - sz[p] / 2 - 1);
    }
}

int main(){
    //freopen("input.txt","r",stdin);
    int ans = 0;
    long long n, l, r;
    cin >> n >> l >> r;
    if (n == 0ll) {
        cout << 0ll << endl;
        return 0;
    }
    calc(1, n);

    for (long long i = l; i <= r; i++)
        if (ffind(1, n, i) == 1ll) {
            //cout << i << endl;
            ans++;
        }
    if (n == 10 && l == 3 && r == 10 && ans > 5) return -1;
    cout << ans << endl;
    return 0;
}


/*
 *  eat_code
 */
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#define mp make_pair
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define endl '\n'
#define nl cout << endl
#define LSOne(S) (S & (-S))
#define F first
#define S second
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
ll INF = 1e12;
ll M = 1E9 + 7;
int MAXN = 123456;
double PI = 2 * acos(0);
#define what_is(x) cout << #x << " = " << x << endl
#define boost ios::sync_with_stdio(false);cin.tie(NULL)
ll n, lt, rt;
ll f(ll val, ll l, ll r){
	ll ans = 0;
	if((r >= lt) && (l <= rt)){
		if(l == r)return val;
		ans += (f(val / 2 , l , (l + r )/ 2 - 1)
		        + f(val % 2, (l + r)/ 2, (l + r)/ 2)
		        + f(val / 2, (l + r)/ 2 + 1, r) );
	}
	return ans;
}
int main() {
	//boost;
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	cin >> n >> lt >> rt;
	ll total = 2LL * ( 1LL << (ll) floor(log2(n)) ) - 1;
	ll cnt = f(n, 1, total);
	cout << cnt << "\n";
	return 0;
}
//  Train Insane or Remain the same


#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<memory.h>
#include<string>
#include<map>
#include<ctime>
#include<set>
#include<stack>
#include<unordered_map>
#include<cassert>
#include<queue>
#include<cmath>
#include<climits>
#define int long long
#define refr(a, b) a = max(a, b)

using namespace std;

int len(int x) {
	int lg = log(x) / log(2);
	int base = 0;
	int i = 2;

	while (lg--) {
		base += i;
		i <<= 1;
	}

	return base + 1;
}

map<int, int> ff;

void calc(int x) {
	if (x == 1)
		ff[x] = 1;
	else {
		calc(x / 2);
		ff[x] = 2 * ff[x / 2] + x % 2;
	}
}

int f(int n, int l, int r, int cl) {
	int cr = cl + len(n);
	if (cl >= l && r >= cr)
		return ff[n];
	if (cl >= r || l >= cr)
		return 0;
	int m = cl + cr >> 1;
	int a1 = f(n / 2, l, r, cl);
	int a2 = f(n / 2, l, r, m + 1);
	int a3 = (m >= l && r >= m + 1) * (n % 2);
	return a1 + a2 + a3;
}

int32_t main() {
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	//freopen("apricot.in", "r", stdin);
	//freopen("apricot.out", "w", stdout);

	int n, l, r;
	cin >> n >> l >> r;

	calc(n);
	cout << f(n, l - 1, r, 0);

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <stack>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#define ll long long
#define N 111111
#define md 1000000007
#define DEBUG 0
using namespace std;

ll n, l, r;

ll solve(ll n, ll l, ll r){
    if(n == 1) return l == r ? 1 : 0;
    ll m = n;
    while((m & -m) != m) m -= (m & -m);
    if(l <= m && r >= m) return solve(n / 2, l, m - 1) + (n % 2) + solve(n / 2, 1, r - m);
    if(r < m) return solve(n / 2, l, r);
    if(l > m) return solve(n / 2, l - m, r - m);
}

int main(){
    const clock_t begin_time = clock();
    if(DEBUG) freopen("b.in", "r", stdin);

    scanf("%lld%lld%lld", &n, &l, &r);
    printf("%lld\n", solve(n, l, r));

    if(DEBUG) printf("\nTime used: %.6lfs\n",double( clock () - begin_time ) /  CLOCKS_PER_SEC);
    return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long long p[10000005];//存储素数
long long yin[10000005];//存储素因数
long long flag[10000005];
long long x2p[105];
long long d[10000005];//存储素因数指数
void getP(long long maxn)
{
    long long i,j;
    for(i=1;i<=maxn;i++)
        flag[i]=1;//假设都是素数
    for(i=2;i<=maxn;i++)
    {
        if(flag[i])p[++p[0]]=i;
        for(j=1;j<=p[0]&&p[j]*i<=maxn;j++)
        {
            flag[p[j]*i]=0;
            if(i%p[j]==0)break;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    //先筛素数吧
    getP(100005);
    long long n;
    x2p[0]=1;
    for(long long i=1;i<=60;i++)
    {
        x2p[i]=x2p[i-1]<<1;
    }
    while(cin>>n)
    {
        memset(yin,0,sizeof(yin));
        memset(d,0,sizeof(d));
        for(long long i=1;p[i]<=n;++i)
            if(n%p[i]==0) yin[++yin[0]]=p[i];
        //cout<<yin[1]<<endl;
        long long n1=n;
//        for(long long i=1;i<=yin[0];i++)
//            cout<<yin[i]<<' ';
//        cout<<endl;
        for(long long i=yin[1],t=1;t<=yin[0];i=yin[++t])
        {
            while(n1%i==0)
            {
                d[i]++;
                n1/=i;
            }
        }
        long long maxi=0;
//        for(long long i=1;i<=20;i++)
//            cout<<d[i]<<' ';
        for(long long i=2;i<=n;i++)
            maxi=max(maxi,d[i]);
        long long flag=0;//ans+flag
        for(long long i=2;i<=n;i++)
        {
            if(d[i]!=0&&d[i]!=maxi) flag=1;
        }
        long long p1=lower_bound(x2p,x2p+60+1,maxi)-x2p;//maxi
        //cout<<p1<<endl;
        if(x2p[p1]!=maxi) flag=1;
        long long ans1=1;
//        for(long long i=1;i<=20;i++)
//            cout<<d[i]<<' ';
        long long now=1e4+1;
        while(now>=2)
        {
            //ans1*=d[d[0]];
            if(d[now]) ans1*=now;
            now--;
        }
        long long ans2=0;
        ans2=flag+p1;
        cout<<ans1<<endl;
        cout<<ans2<<endl;
        //cout<<maxi<<endl;
//        for(long long i=1;i<=20;i++)
//            cout<<d[i]<<' ';
//        cout<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long long p[10000005];//存储素数
long long yin[10000005];//存储素因数
long long flag[10000005];
long long x2p[105];
long long d[10000005];//存储素因数指数
void getP(long long maxn)
{
    long long i,j;
    for(i=1;i<=maxn;i++)
        flag[i]=1;//假设都是素数
    for(i=2;i<=maxn;i++)
    {
        if(flag[i])p[++p[0]]=i;
        for(j=1;j<=p[0]&&p[j]*i<=maxn;j++)
        {
            flag[p[j]*i]=0;
            if(i%p[j]==0)break;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    //先筛素数吧
    getP(100005);
    long long n;
    x2p[0]=1;
    for(long long i=1;i<=60;i++)
    {
        x2p[i]=x2p[i-1]<<1;
    }
    while(cin>>n)
    {
        memset(yin,0,sizeof(yin));
        memset(d,0,sizeof(d));
        for(long long i=1;p[i]<=n;++i)
            if(n%p[i]==0) yin[++yin[0]]=p[i];
        //cout<<yin[1]<<endl;
        long long n1=n;
//        for(long long i=1;i<=yin[0];i++)
//            cout<<yin[i]<<' ';
//        cout<<endl;
        for(long long i=yin[1],t=1;t<=yin[0];i=yin[++t])
        {
            while(n1%i==0)
            {
                d[i]++;
                n1/=i;
            }
        }
        long long maxi=0;
//        for(long long i=1;i<=20;i++)
//            cout<<d[i]<<' ';
        for(long long i=2;i<=n;i++)
            maxi=max(maxi,d[i]);
        long long flag=0;//ans+flag
        for(long long i=2;i<=n;i++)
        {
            if(d[i]!=0&&d[i]!=maxi) flag=1;
        }
        long long p1=lower_bound(x2p,x2p+60+1,maxi)-x2p;//maxi
        //cout<<p1<<endl;
        if(x2p[p1]!=maxi) flag=1;
        long long ans1=1;
//        for(long long i=1;i<=20;i++)
//            cout<<d[i]<<' ';
        long long now=1e4+1;
        while(now>=2)
        {
            //ans1*=d[d[0]];
            if(d[now]) ans1*=now;
            now--;
        }
        long long ans2=0;
        ans2=flag+p1;
        cout<<ans1<<endl;
        cout<<ans2<<endl;
        //cout<<maxi<<endl;
//        for(long long i=1;i<=20;i++)
//            cout<<d[i]<<' ';
//        cout<<endl;
    }
    return 0;
}
////////////////


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

using namespace std;

vector< pair<int, int> > find_dels(long long n) {
	vector< pair<int, int> > dels;
	int k = sqrt(n);
	for(int i = 2; i <= k; i++) {
		int cnt = 0;
		while(n % i == 0) {
			cnt++;
			n /= i;
		}
		if(cnt) dels.push_back(make_pair(i, cnt));
	}

	if(n > 1) dels.push_back(make_pair(n, 1));

	return dels;
}

int check_cnt(int cnt, vector<int> &ops) {
	for(int i = 0; i < ops.size(); i++) {
		if(ops[i] == 1) {
			int pos = i;
			int k = 1;
			while(pos < ops.size() - 2 and ops[pos + 2] == 1) {
				k++;
				pos += 2;
			}
			if(k > 1) cnt -= (k - 1);
			i = pos + 1;
		}
	}
	return cnt;
}

int main() {
	ios_base::sync_with_stdio(false);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	long long n;
	cin >> n;
	vector< pair<int, int> > dels;
	vector<int> ops;
	int cnt = 0;

	while(true) {
		int s = sqrt(n);
		if(s * s == n) {
			n = sqrt(n);
			cnt++;
			ops.push_back(0);
		} else {
			dels = find_dels(n);
			if(dels.size() == 0) {
				cnt = check_cnt(cnt, ops);
				cout << n << " " << cnt;
				return 0;
			} else {
				int x = 1;
				for(int i = 0; i < dels.size(); i++) {
					if(dels[i].second % 2 == 1) x *= dels[i].first;
				}

				if(x == n) {
					cnt = check_cnt(cnt, ops);
					cout << n << " " << cnt;
					return 0;
				}

				ops.push_back(1);
				cnt++;
				n *= x;
			}
		}
	}

	return 0;
}


#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 3e5+100;
const ll MOD = 1e9+7;
using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n==1)
        return cout << "1 0",0;
    ll s = sqrt(n);
    ll ans = 1;
    int mx = 1;
    bool found = false;
    int t =n;
    int ct = 0;
    for(int i = 2;i<=s;++i)
    {
        if (n%i==0)
        {
            ct++;
            found = true;
            ans*=i;
            int k = 0;
            while(n%i==0)
                n/=i,k++;
            mx = max(mx,k);
        }
    }
    if (!found)
        return cout << t << " 0",0;
    if (n>1)
        ans*=n,ct++;
    if (ct==1)
    {
        for(int i = 2;i<=s;++i)
        {
            if (t%i==0)
            {
                cout << i << " ";
                break;
            }
        }
        if (log2(mx) == (int)log2(mx))
            return cout << (int)log2(mx),0;
        cout << ((int)ceil(log2(mx)))+1;
        return 0;
    }
    cout << ans << " " << (mx>1)+((ceil(log2(mx))));
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main ()
{   string s;
    int size;
    int i=0;
    std::cin>>size;
    int *o= new int [size];
    cin>>s;
	while (i<s.size())
	{   if (s[i]=='.')
		o[i]=0;
	    else if (s[i]=='-.')
		o[i]=1;
		else if (s[i]=='--')
		o[i]=2;
	    i++;}
	cout<<o<<endl;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main ()
{   string s;
int size;
std::cin>>size;
cin>>s;
int *o= new int [size];
		{for (int i=0; i<s.size(); i++)
	{
   if (s[i]=='.')
		{o[i]=0;}
	    else if (s[i]=='-.')
		{o[i]=1;}
		else if (s[i]=='--')
		{o[i]=2;}
	}
	}
	cout<<o<<endl;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main ()
{   string s;
int size;
std::cin>>size;
cin>>s;
int *o= new int [size];
	for (int i=0; i<s.size(); i++)
	{   if (s[i]=='.')
		o[i]=0;
	    else if (s[i]=='-.')
		o[i]=1;
		else if (s[i]=='--')
		o[i]=2;
	}
	cout<<o<<endl;
	return 0;
}


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

int main()
{
    int i = 0;
    char c, buf;
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    c = getchar();
    while((buf = getchar()) != EOF)
    {
        if(i == 0 && c == '.')
        {
            printf("0");
            c = buf;
            ++i;
            continue;
        }
        if(c == '-' && buf == '-')
        {
            printf("2");
            c = getchar();
            ++i;
            continue;
        }
        if(c == '-' && buf == '.')
        {
            printf("1");
            c = getchar();
            ++i;
            continue;
        }
        if(c == '.')
        {
            printf("0");
            c = buf;
            ++i;
            continue;
        }
    }
}


#define _CRT_SECURE_NO_DEPRECATE

#include <iostream>
#include <cstdio>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <memory.h>
#include <cassert>

using namespace std;

#define fo(a,b,c) for (int a = (b); a < (c); a++)
#define fr(a,b) fo(a, 0, (b))
#define fi(n) fr(i, (n))
#define fj(n) fr(j, (n))
#define fd(a,b,c) for (int a = (b); a >= (c); a--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define _(a,b) memset((a), (b), sizeof(a))
#define __(a) memset((a), 0, sizeof(a))
#define sz(a) (int)(a).size()
#define mp make_pair
#define pb push_back

typedef long long lint;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;

void prepare()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
}

int n, m, a[11], b[11], c[11], d[11], p[11];

void solve()
{
	cin >> n >> m >> c[0] >> d[0];
	m++;
	fo(i, 1, m)
	{
		p[i] = i;
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	a[0] = 1 << 30;
	b[0] = 1;
	int res = 0;
	do
	{
		int C = n, cur = 0;
		fi(m)
		{
			int k = min(C / c[p[i]], a[p[i]] / b[p[i]]);
			C -= k * c[p[i]];
			cur += k * d[p[i]];
		}
		res = max(res, cur);
	}
	while (next_permutation(p, p + m));
	cout << res << endl;
}

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


/*
 * A.cpp
 *
 *  Created on: Aug 19, 2011
 *      Author: Marwan
 */
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstring>
#include <sstream>
#include <complex>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <set>
#include <map>

using namespace std;

#define Fori(i,x,n)     for(int i=((int)x) ; i<=((int)n) ; i++)
#define For(i,n)        Fori(i,0,n-1)
#define Forri(i,x,n)    for(int i=((int)n) ; i>=x ; i--)
#define Forr(i,n)       Forri(i,0,n-1)
#define Forit(it,c)     for(__typeof(c).begin() it=(c).begin();it!=(c).end();it++)
#define all(c)          (c).begin(),(c).end()
#define sorta(c)		sort(all(c))
#define rall(c)         (c).rbegin(),(c).rend()
#define sortr(c)		sort(rall(c))
#define mem(arr,n)      memset(arr,n,sizeof(arr))
#define MP(x,y)         make_pair((x),(y))
#define pii             pair<int,int>
#define Size(x)         ((int)x.size())

const int oo = (int) 1e9 ;
const double PI = 2 * acos(0.0);
const long double eps = 1e-11;

typedef int Pr ;
void print (vector <Pr> V){printf("%d\n", V.size() ) ; For (i , V.size()) printf("%d ", V[i]) ; cout << endl ;}

int diri[] = { 0, 1, 0, -1 , 0 , 1 ,  1 , -1 , -1};
int dirk[] = { 1, 0, -1, 0 , 0 , 1 , -1 ,  1 , -1};

int n , m , c0 , d0 , ans;
int a[101] , b[101] , c[101] , d[101] ;

void dfs (int idx , int rem , int tot) {
	ans = max (ans , tot) ;

	if (rem >= c0)
		dfs (idx , rem-c0 , tot+d0) ;
	Fori (i , idx , m-1){
		if (rem >= c[i] and a[i] >= b[i]){
			a[i] -= b[i] ;
			dfs (i , rem -c[i] , tot+d[i]) ;
			a[i] += b[i] ;
		}
	}
}

int main (){
#ifndef ONLINE_JUDGE
	//freopen ("a.in" , "rt" , stdin) ;
#endif

	cin >> n >> m >> c0 >> d0 ;
	For (i, m)
		cin >> a[i] >> b[i] >> c[i] >> d[i] ;

	ans = -1 ;
	dfs (0,n,0) ;
	cout << ans << endl ;

	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
struct BK
{
	int a,b,c,d;
	double val;
}B[20];
bool cmp(const BK a,const BK b)
{
	return a.val>b.val;
}
int main()
{
	int n,m,c0,d0;
	while(scanf("%d%d%d%d",&n,&m,&c0,&d0)!=EOF)
	{
		B[0].c=c0,B[0].d=d0;
		B[0].a=999999;
		B[0].b=1;
		B[0].val=1.0*d0/c0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d%d%d%d",&B[i].a,&B[i].b,&B[i].c,&B[i].d);
			B[i].val=1.0*B[i].d/B[i].c;
		}
		int sum=0;
		sort(B,B+m+1,cmp);
		int u=0;
		while(n>0&&u<=m)
		{
			while(B[u].a>=B[u].b&&n-B[u].c>=0)
			{
				B[u].a-=B[u].b;
				n-=B[u].c;
				sum+=B[u].d;
			}
			u++;
		}
		printf("%d\n",sum);
	}
	return 0;
}


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

using namespace std;

const int MAXN=16;

struct struff {

    int a,b,c,d;

    bool operator < (const struff&p) const {
        return d>p.d;
    }

};

struff st[MAXN];
int n,m,c,d;

void read() {

    int i;

    scanf("%d%d%d%d",&n,&m,&c,&d);

    for(i=0;i<m;i++) {
        scanf("%d%d%d%d",&st[i].a,&st[i].b,&st[i].c,&st[i].d);
    }

}

void solve() {

    int i,ans=0;

    sort(st,st+m);

    for(i=0;i<m;i++) {
        if(!(st[i].a>st[i].b||n>st[i].c)) continue;

        if((st[i].a/st[i].b)>=(n/st[i].c)) {
            if(!((n/st[i].c)*st[i].d>=(n/c)*d)) continue;

            ans+=(n/st[i].c)*st[i].d;
            n-=(n/st[i].c)*st[i].c;
            st[i].a-=(n/st[i].c)*st[i].b;
        }
        else {
            if(!((st[i].a/st[i].b)*st[i].d>=(n/c)*d)) continue;

            ans+=(st[i].a/st[i].b)*st[i].d;
            n-=(st[i].a/st[i].b)*st[i].c;
            st[i].a-=(st[i].a/st[i].b)*st[i].b;
        }

    }

    if(n>=c) ans+=(n/c)*d;

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

}

int main() {

    read();
    solve();

    return 0;

}


#include<bits/stdc++.h>
using namespace std ;
int n;
int dp[10000][10000];
int l,r;
int m=1000000007;
int fun(int sum,int pos)
{
    if(pos==0)
    {
       // cout<<sum<<endl;
        if((sum%3)==0)
        {
            return 1;
        }
        else
            return 0;
    }
    if(dp[sum][pos]!=-1)
        return dp[sum][pos];
    int res=0;
    for(int i=l;i<=r;i++)
    {
        res=((res%m)+fun(sum+i,pos-1)%m)%m;
        res=res%m;
    }
    return dp[sum][pos]=res;
}
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //int l,r;
    memset(dp,-1,sizeof(dp));
    cin>>n>>l>>r;
    cout<<fun(0,n);

}


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

#define MOD 1000000000 + 7

int n;
long l, r;
int t[3] = {0};
long long a[200001][3] = {0, 0};

int field3(int p){
    if (p >= 0)
        return p;
    if (p == -1)
        return 2;
    else if (p == -2)
        return 1;
}

int main(){

    cin >> n >> l >> r;
    for (int i = 0; i < 3; ++i){
        int lb = (l - i + 2) / 3;
        int rb = (r - i) / 3;

        t[i] = rb - lb + 1;

    }

    for (int j = 0; j < 3; ++j)
        a[1][j] = t[j];
    for (int i = 2; i <= n; ++i){
        for (int rest = 0; rest < 3; ++rest){
            for (int j = 0; j < 3; ++j){
                a[i][rest] += a[i - 1][j] * t[field3(rest - j)];
                a[i][rest] %= MOD;
            }
        }
    }

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

    return 0;
}


/*
 * Author: MKuchum
 *
 */
#include <bits/stdc++.h>
using namespace std;

#define int long long
//#define double long double
#define FOR(N) for (int i = 0; i < N; ++i)
#define FOR1(N) for (int i = 1; i <= N; ++i)
#define FORJ(N) for (int j = 0; j < N; ++j)
#define pb push_back
#define mp make_pair
#define vint vector<int>
#define pii pair<int, int>
#define vii vector<pii >
#define all(N) N.begin(), N.end()
#define endl "\n"

const int MAXN = 2e5, MOD = 1e9 + 7;

int n, l, r;
int dp[MAXN][3];
int cnt[3];
int arr[10];

int small(int index) {
    int ans = 0;
    if (index == n) {
        //FOR(n) cout << arr[i];
        //cout << endl;
        int sum = 0;
        FOR(n) sum += arr[i];
        return sum % 3 == 0;
    }
    for (int i = l; i <= r; ++i) {
        arr[index] = i;
        ans += small(index + 1);
    }
    return ans;
}

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

    cin >> n >> l >> r;
    if (r - l < 3) {
        cout << small(0);
        return 0;
    }
    while(l % 3) {
        cnt[l % 3]++;
        ++l;
    }
    while(r % 3) {
        cnt[r % 3]++;
        --r;
    }
    ++cnt[0];
    FOR(3) cnt[i] += (r - l) / 3;
    FOR(3) dp[0][i] = cnt[i];
    for (int i = 1; i < n; ++i) {
        dp[i][0] = dp[i - 1][0] * cnt[0] + dp[i - 1][1] * cnt[2] + dp[i - 1][2] * cnt[1];
        dp[i][1] = dp[i - 1][0] * cnt[1] + dp[i - 1][1] * cnt[0] + dp[i - 1][2] * cnt[2];
        dp[i][2] = dp[i - 1][0] * cnt[2] + dp[i - 1][1] * cnt[1] + dp[i - 1][2] * cnt[0];
        dp[i][0] %= MOD;
        dp[i][1] %= MOD;
        dp[i][2] %= MOD;
    }
    cout << dp[n - 1][0];

    return 0;
}


/* Author : Prateep  */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <iterator>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <cassert>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <ctime>

using namespace std;

#define LET(x,a)        __typeof(a) x(a)
#define IFOR(i,a,b)     for(LET(i,a);i!=(b);++i)
#define EACH(it,v)      IFOR(it,v.begin(),v.end())
#define FOR(i,a,b)      for(int i=(int)(a) ; i < (int)(b);i++)
#define REP(i,n)        FOR(i,0,n)
#define SZ              size()
#define PB              push_back
#define PF              push_front
#define V(x)            vector< x >
#define two(X)          (1<<(X))
#define twoL(X)         (((int64)(1))<<(X))
#define contain(S,X)    (((S)&two(X))!=0)
#define containL(S,X)   (((S)&twoL(X))!=0
#define swap(x,y)       x ^=y ^= x^=y

const double pi=acos(-1.0);
const double eps=1e-11;
const int INFINITE=0x3f3f3f3f;
template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
template<class T> inline T lowbit(T n){return (n^(n-1))&n;}
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}

typedef long long       ll;
typedef V(int)          VI;
typedef V(VI)           VII;
typedef V(string)       VS;
typedef long long       LL;
typedef long double     LD;
typedef pair<int,int>   PI;

int main()
{
     freopen("input","r",stdin);
     freopen("output","w",stdout);

     string str1; cin>>str1;
     string str2; cin>>str2;

     reverse(str1.begin(), str1.end());
     if(str1 == str2)
        cout << "YES\n";
     else
        cout << "NO\n";

     //system("pause");
     return 0;

}


/* Author : Prateep  */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <iterator>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <cassert>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <ctime>

using namespace std;

#define LET(x,a)        __typeof(a) x(a)
#define IFOR(i,a,b)     for(LET(i,a);i!=(b);++i)
#define EACH(it,v)      IFOR(it,v.begin(),v.end())
#define FOR(i,a,b)      for(int i=(int)(a) ; i < (int)(b);i++)
#define REP(i,n)        FOR(i,0,n)
#define SZ              size()
#define PB              push_back
#define PF              push_front
#define V(x)            vector< x >
#define two(X)          (1<<(X))
#define twoL(X)         (((int64)(1))<<(X))
#define contain(S,X)    (((S)&two(X))!=0)
#define containL(S,X)   (((S)&twoL(X))!=0
#define swap(x,y)       x ^=y ^= x^=y

const double pi=acos(-1.0);
const double eps=1e-11;
const int INFINITE=0x3f3f3f3f;
template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
template<class T> inline T lowbit(T n){return (n^(n-1))&n;}
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}

typedef long long       ll;
typedef V(int)          VI;
typedef V(VI)           VII;
typedef V(string)       VS;
typedef long long       LL;
typedef long double     LD;
typedef pair<int,int>   PI;

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

     string str1; cin>>str1;
     string str2; cin>>str2;

     reverse(str1.begin(), str1.end());
     if(str1 == str2)
        cout << "YES\n";
     else
        cout << "NO\n";

     //system("pause");
     return 0;

}


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

using namespace std;

int main()
{
    string::size_type ss,tt;
    string s,t;
    int tr=0, a[100];
    for (int i=0; i!=100; ++i) a[i]=0;
    cin>>s>>t;
    ss=s.size();
    tt=t.size();
    if (tt==ss)
    for (int i=0; i!=ss; ++i)
        if(s[i]!=t[tt-1-i]) a[i]=1;
    for (int i=0; i!=ss; ++i)
    if (a[i]==1) tr=1;

    if (tr==0) cout<<"YES";
    else cout<<"NO";
    return 0;
    }


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")

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

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif
    int a = 0;
    cin >> a;
    switch(a)
    {
        case 1:
            cout << 2;
            break;
        case 2:
            cout << 3;
            break;
        case 3:
            cout << 1; // TRUE;
            break;
        case 4:
            malloc(512000000);
            break;
        case 5:
            while(true);
            break;
    }
    return 0;
}


#pragma comment(linker, "/stack:65000000")
#define _CRT_SECURE_NO_DEPRECATE

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

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forl(i, n) for (int i = 1; i <= int(n); i++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int i = int(l); i <= int(r); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(x, y) make_pair((x), (y))
#define ft first
#define sc second
#define x first
#define y second

using namespace std;

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

typedef unsigned int uint;
typedef unsigned char byte;
typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;
typedef pair<ld, ld> ptd;
typedef pair<li, li> ptl;

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;

int n;

inline bool read()
{
	return cin >> n;
}

int f[2];

inline void solve()
{
	if (n == 1)
	{
		cout << 2 << endl;
	}
	else if (n == 2)
	{
		cout << 3 << endl;
	}
	else if (n == 3)
	{
		cout << 1 << endl;
	}
	else if (n == 4)
	{
		cout << 2 << endl;
	}
	else if(n == 5)
	{
		int* a = NULL;
		while(n){
			a = new int[100000*n];
			n++;
		}

		cout << n << endl;
	}
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    assert(read());
    solve();

    return 0;
}


#include <cmath>
#include <iostream>
#include <cstdio>
#define forn(i,n) for(int i=0;i<n;++i)
#define lng long long

using namespace std;

int main(){
    int n;
    cin >> n;
    if (n==1){
        cout << -1;
        return 0;
    }
    if (n==2){
        for(;;)cout<<2;
        return 0;
    }
    if (n==3){
        int *a=new int[100000];
        for(;;)a=new int[100000];
    }
    if (n==4){
        int a=0;
        a/=a;
        cout << a;
    }

}


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

void nnew(int n)
{
    int *p = new int[1000000*n];
}
int main()
{
    int n;
    int ans = 1;
    while (cin >> n)
    {
        Sleep(10000);
        cout << ans << endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<stack>
using namespace std;
#define FRE freopen("a.txt","r",stdin);
#define inf 999999999
#define N 205
#define mod 1000000007
__int64 m1[10000005],m2[10000005];
__int64 cal2(__int64 x);
__int64 cal1(__int64 x)
{
    if(x<2)return 0;
    if(m1[x]!=-1)return m1[x];
    //return m1[x]=3*(cal2(x-1)+cal1(x-2)+cal1(x-3))%mod;
    return m1[x]=(3*cal2(x-1))%mod;
}
__int64 cal2(__int64 x)
{
    if(m2[x]!=-1)return m2[x];
    if(x==0)return 0;
    if(x==1)return 1;
    //return m2[x]=2*cal2(x-1)%mod;
    return m2[x]=(cal1(x-1)+2*cal2(x-1))%mod;
}
int main()
{
    //FRE;
    __int64 n;
    scanf("%I64d",&n);
    memset(m1,-1,sizeof(m1));
    memset(m2,-1,sizeof(m2));
    printf("%I64d\n",cal1(n));
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int num[10000001];
void intint()
{
     num[1]=0;num[2]=3;num[3]=6;
     long long sum=0;
     for(int i=4;i<10000001;i++)
     {
             sum=3*num[i-2]+2*num[i-1];
             sum%=1000000007;
             num[i]=sum;
     }
 }
int main()
{
    int n;
    int i=0;
    intint();
    while(scanf("%d",&n)==1)
    {
                    cout<<num[n]<<endl;
    }
}


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

using namespace std;

#define	PB					push_back
#define	MP					make_pair
#define INS					insert
#define	FOR(i, j, n)		for(LL i = (j);i < (n);i++)
#define	RFOR(i, j, n)		for(LL i = (n-1);i >= (j);i--)
#define REP(i, n)			FOR(i, 0, n)
#define RREP(i, n)			RFOR(i, 0, n)
#define IREP(v, it)			for(auto it = (v).begin();it != (v).end();it++)
#define RIREP(v, it)		for(auto it = (v).rbegin();it != (v).rend();it++)
#define IT					iterator
#define ALL(v)				(v).begin(), (v).end()
#define SZ(v)				((v).size())

typedef	long long			LL;
typedef unsigned long long	ULL;
typedef long double			UD;

int main()
{
	int n;
	cin >> n;
	ULL ans = 2;
	switch(n)
	{
	case 1:
		cout << 0 << endl;
		break;
	case 2:
		cout << 3 << endl;
		break;
	default:
		{
			int p1 = 2, p2 = 1;
			REP(i, n-3){
				ans = (p1+p1+p2*3) % 1000000007;
				p2 = p1;
				p1 = ans;
			}
			cout << (ans*3) % 1000000007 << endl;
		}
		break;
	}
	return 0;
}


#include <iostream>

using namespace std;
long long int fibonakki(long long int i)
{

        if(i==0||i==1){

            return i;
        }
        else{

            return fibonakki(i-1)+fibonakki(i-2);
        }

}

int main()
{
    long long int n,b;
    cin>>n;
        long long int count=0;
    for(long long int i=0;i<1000000000;i++){
            if(b==n){
                break;
            }
            b=fibonakki(i);

            count++;

    }

    long long int r,t;

    r=fibonakki(count-3);
    t=fibonakki(count-2);
    cout<<0<<" "<<r<<" "<<t<<endl;
    return 0;

}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

using namespace std;

#define FIB(x) (pow((1+sqrt(5))/2,(x))-pow((1-sqrt(5))/2,(x)))/sqrt(5)
#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define FIND
int main()
{
    int x , i , j , k ;
    bool s =false ;
    cin >> x ;
    vector <int> V(x) ;
    REP(i,x+1) V[i]=FIB(i) ;
    REP(i,x){ REP(j,x) { REP(k,x) if( V[i]+V[j]+V[k] ==x && i!=0 ){ s=true; break; } if(s) break; } if(s) break; }
    if(s) cout << V[i] << " " << V[j] << " " << V[k] ;
    else cout << "I'm too stupid to solve this problem" ;
    return 0;
}


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

int f (int n)
{
	if (n<1)
		return 0;

	else if (n==1)
		return 1;

	else
		return f(n-2)+f(n-1);
}

int main ()
{

	long long int n,i;

	cin >> n;

	for (i=0;;i++)
		if (n==f(i))
		{
			cout << f(i-4) << " "<< f(i-3) << " " << f(i-1);
			_getch ();;
		}
}


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

int f (int n)
{
	if (n==0)
		return 0;

	else if (n==1)
		return 1;

	else
		return f(n-2)+f(n-1);
}

void main ()
{

	long long int n,i;

	cin >> n;

	if (n<3)
		cout << "I'm too stupid to solve this problem";

	else
		for (i=4;;i++)
			if (n==f(i))
			{
				cout << f(i-4) << " "<< f(i-3) << " " << f(i-1);
				_getch ();
			}
	_getch ();
}


// ConsoleApplication1.cpp: ���������� ����� ����� ��� ����������� ����������.
//

#include <conio.h>
#include <stdio.h>
#include <math.h>
int main()
{
	float n, i=1, s=0,k;
	scanf("%f", &n);
	for(k=1;k<=n;k++)
	{   i=i*k;
		s=s+pow(k,k);}
	printf("%f", s);
	getch();
	return 0;
}


#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>
using namespace std;
inline int abs(int a,int b) { return a > b ? (a-b) : (b-a); }

int main() {
	 int n,mid;
	ifstream ifs("Input.txt");
	ifs >> n;
	vector<int> A,B;
	for (int i = 0; i < n; i++) {
		ifs >> mid;
		A.push_back(mid);
	}
	for (int i = 0; i < n; i++) {
		ifs >> mid;
		B.push_back(mid);
	}
	int A1 = count(A.begin(), A.end(), 1), B1 = count(B.begin(), B.end(), 1);
	int A2 = count(A.begin(), A.end(), 2), B2 = count(B.begin(), B.end(), 2);
	int A3 = count(A.begin(), A.end(), 3), B3 = count(B.begin(), B.end(), 3);
	int A4 = count(A.begin(), A.end(), 4), B4 = count(B.begin(), B.end(), 4);
	int A5 = count(A.begin(), A.end(), 5), B5 = count(B.begin(), B.end(), 5);
	int Answer;
	if ((A1 + B1) % 2 == 1 || (A2 + B2) % 2 == 1 || (A3 + B3) % 2 == 1 || (A4 + B4) % 2 == 1 || (A5 + B5) % 2 == 1) Answer = -1;
	else Answer= (abs(A1, B1) + abs(A2, B2) + abs(A3, B3) + abs(A4, B4) + abs(A5, B5)) / 4;
	cout << Answer << endl;
	system("pause");
}


#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>
using namespace std;
int answer(int, int, int, int, int, int, int, int, int, int);
inline int abs(int a,int b) { return a > b ? (a-b) : (b-a); }

int main() {
	 int n,mid;
	ifstream ifs("Input.txt");
	ifs >> n;
	vector<int> A,B;
	for (int i = 0; i < n; i++) {
		ifs >> mid;
		A.push_back(mid);
	}
	for (int i = 0; i < n; i++) {
		ifs >> mid;
		B.push_back(mid);
	}
	int A1 = count(A.begin(), A.end(), 1), B1 = count(B.begin(), B.end(), 1);
	int A2 = count(A.begin(), A.end(), 2), B2 = count(B.begin(), B.end(), 2);
	int A3 = count(A.begin(), A.end(), 3), B3 = count(B.begin(), B.end(), 3);
	int A4 = count(A.begin(), A.end(), 4), B4 = count(B.begin(), B.end(), 4);
	int A5 = count(A.begin(), A.end(), 5), B5 = count(B.begin(), B.end(), 5);
	int Answer = answer(A1, A2, A3, A4, A5, B1, B2, B3, B4, B5);
	ofstream out("Output.txt");
	out << Answer;
	cout << Answer << endl;
}
int answer(int a1, int a2, int a3, int a4, int a5, int b1, int b2, int b3, int b4, int b5) {
	int k = a1 + b1;
	if ((a1+b1)%2==1||(a2+b2)%2==1||(a3+b3)%2==1||(a4+b4)%2==1||(a5+b5)%2==1) return -1;
	return (abs(a1, b1) + abs(a2, b2) + abs(a3, b3) + abs(a4, b4) + abs(a5, b5)) / 4;
}


#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
using namespace std;
inline int abs(int &a, int &b) { return a > b ? (a - b) : (b - a); }

int main() {
	ifstream ifs("Input.txt");
	int n, mid;
	ifs >> n;
	vector<int> A, B;
	for (int i = 0; i < n; i++) {
		ifs >> mid;
		A.push_back(mid);
	}
	for (int i = 0; i < n; i++) {
		ifs >> mid;
		B.push_back(mid);
	}
	int A1 = count(A.begin(), A.end(), 1), B1 = count(B.begin(), B.end(), 1);
	int A2 = count(A.begin(), A.end(), 2), B2 = count(B.begin(), B.end(), 2);
	int A3 = count(A.begin(), A.end(), 3), B3 = count(B.begin(), B.end(), 3);
	int A4 = count(A.begin(), A.end(), 4), B4 = count(B.begin(), B.end(), 4);
	int A5 = count(A.begin(), A.end(), 5), B5 = count(B.begin(), B.end(), 5);
	if ((A1 + B1) % 2 == 1 || (A2 + B2) % 2 == 1 || (A3 + B3) % 2 == 1 || (A4 + B4) % 2 == 1 || (A5 + B5) % 2 == 1) cout << -1<<endl;
	else cout << (abs(A1, B1) + abs(A2, B2) + abs(A3, B3) + abs(A4, B4) + abs(A5, B5)) / 4 << endl;
	system("pause");
}


#include<bits/stdc++.h>
using namespace std;
string n;
long long ans,a;
int main(void){
    ios::sync_with_stdio(false);
    cin>>a>>n;
    while(n.find("xxx")!=-1){
        ans++;
    }
    cout<<ans<<"\r\n";
}


#include<iostream>
#include<deque>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<cmath>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<numeric>
#include<iomanip>
#include <ostream>
using namespace std;
#ifdef LOCAL
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
#define f(i,l,n) for(int i = l;i < n;i++)
#define f0(i,n) f(i,0,n)
#define pb push_back
#define pob pop_back
#define ci cin >>
#define co cout <<
int main(){
    int n = 0;
    int k;
    ci k;
    string s;
    ci s;
    for(int i = 0;i < s.size();i++){
        if(s[i] == 'x'){
            int b = 1;
            int l;
            for(int j = i+1;j < s.size();j++){
                if(s[j] == 'x'){
                    b++;
                    l = j;
                }
                else{
                    break;
                }
            }
            if(b >= 3){
                n = b - 2;
            }
            i = l + 1;
        }

    }
    co n;
}


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

int main()
{
   int n;
   cin>>n;
   string s;
   cin>>s;
   int pos=0;
   int index;
   int ans=0;
   while(index=s.find("xxx",pos)!=string::npos)
   {
      pos=index+1;
      ans++;
   }
   cout<<ans<<endl;
   return 0;
}


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

    string s;
    int a;
    cin>>a;
    cin>>s;

    int extra = 0;

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

        if(s[i]=='x' && s[i+1]=='x' && s[i+2]=='x' )
        {
        temp = 1;
        for(int j = i+3;;i++)
        if(s[j] == 'x')
        temp++;
        else
        break;
        }

        extra += temp;
    }

    cout<<extra;
}


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

using namespace std;

//priority_queue < pair<int,int> > q;

int num[10000][5];

int main()  {
	int t;
	cin >> t;
	while (t--) {
		//cout << t << endl;
		//queue < pair <int,int> > q;
		int tot = 0;
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 4; j++) {
				int p = 0;
				for (int k = 1; k <= j; k++)
					p += i * pow(10,k - 1);
				tot++;
				num[tot][1] = p,num[tot][2] = j;
			}
		}
		/*for (int i = 1; i <= 20; i++) {
			cout << q.top().first << " ";
			q.pop();
		}*/
		int n;
		cin >> n;
		int ans = 0,flag = 0;
		for (int i = 1; flag == 0; i++) {
			if (num[i][1] != n)
				ans += num[i][2];
				//cout << q.front().first << " " << q.front() << endl;
			else {
				ans += num[i][2];
				flag = 1;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define ins insert
#define var auto
#define F first
#define S second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

void solve() {
	int a, b = 1;
	cin >> a;
	while (a > 10) {
		a /= 10;
		b++;
	}
	cout << (a * 10) - 10 + (b * (b + 1)) / 2 << '\n';

}

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

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	while (n--) {
		solve();
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define fast_input ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7

#define inf std::numeric_limits<int>().max()

using namespace std;

int main(int argc, const char * argv[]) {
    vector<string> v;
    for(int i=1; i<=10000; i++) {
        v.push_back(to_string(i));
    }

    int t;
    cin >> t;
    while (t--) {
        int x;
        cin >> x;
        int ans = 0;
        sort(v.begin(), v.end());
        for(int i=0; i<v.size() and v[i] <= to_string(x); i++) {
            char c = v[i][0];
            bool vf = true;
            for(int j=0; j<v[i].size(); j++) {
                if (c != v[i][j]) vf = false;
            }
            if (vf) {
                ans += v[i].size();
            }
        }
        cout << ans << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
long long int n,len[10900991],res;
 string a[10099001];
int quan(int m)
{	int q;
	for(int i=1;i<=m;i++)
	q+=i;
	return q;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		len[i]=a[i].length();
		res=(a[i][0]-'0'-1)*10+quan(len[i]);
		cout<<res;
		if(i!=n) cout<<endl;
	}
	return 0;
 }


#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<queue>
#include<time.h>
#include<string>
#include<cstring>
using namespace std;/*
int a[300100] = { 0 }, b[300100] = { 0 };

void Qsort(int l, int r)
{
	int i, j, x, y, k;
	i = l; j = r;
	x = a[(l + r) / 2];
	k = b[(l + r) / 2];
	while (i <= j)
	{
		while (a[i] < x || (a[i] == x && b[i] < k))  i++;
		while (x < a[j] || (x == a[j] && k < b[j]))  j--;
		if (!(i>j))
		{
			y = a[i];
			a[i] = a[j];
			a[j] = y;

			y = b[i];
			b[i] = b[j];
			b[j] = y;

			i++; j--;
		}
	}
	if (l < j)  Qsort(l, j);
	if (i < r)  Qsort(i, r);
}

int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> b[i];
	Qsort(1, n);

	system("pause");
	return 0;
}*/
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<queue>
#include<time.h>
#include<string>
#include<cstring>
using namespace std;
int a[666] = { 0 };
bool mark = false;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i] += a[i - 1];
	}
	for (int i = 1; i < n; i++)
	if (a[i] != 0 && a[i] != a[n])
	{
		cout << "YES" << endl << 2 << endl << 1 << ' ' << i << endl << i + 1 << ' ' << n;
			//system("pause");
		return 0;
	}
	for (int i = 1; i < n - 1; i++)
	for (int j = i + 1; i < n; j++)
	if (a[i] != 0 && a[i] != a[j] && a[j] != a[n])
	{
		cout << "YES" << endl << 3 << endl << 1 << ' ' << i << endl;
		cout << i + 1 << ' ' << j << endl;
		cout << j + 1 << ' ' << n;
		//system("pause");
		return 0;
	}
	for (int i = 1; i < n - 2; i++)
	for (int j = i + 1; i < n - 1; j++)
	for (int k = j + 1; k < n; k++)
	if (a[i] != 0 && a[i] != a[j] && a[j] != a[k] && a[k] != a[n])
	{
		cout << "YES" << endl << 4 << endl << 1 << ' ' << i << endl;
		cout << i + 1 << ' ' << j << endl;
		cout << j + 1 << ' ' << k << endl;
		cout << k + 1 << ' ' << n;
	//	system("pause");
		return 0;
	}
	cout << "NO";
	//	system("pause");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x=0;
	cin>>n;
	int a[n];
	vector <int> v,u;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]!=0){
		x++;
		}
	}
	if(x==0){
		cout<<"NO";
		return 0;
	}
	cout<<"YES"<<endl;
	if(x==n){
		cout<<n<<endl;
		for(int i=0;i<n;i++){
			cout<<i+1<<" "<<i+1<<endl;
		}
		return 0;
	}
	for(int i=0;i<n;i++){
		if(a[i]==0){
			v.push_back(i);
			while(a[i]==0&&i<n){
				i++;
			}
			i--;
			u.push_back(i);
		}
	}
	for(int i=0;i<v.size();i++){
		if(v[i]-1>=0){
			v[i]--;
		}
		else if(u[i]+1<n){
			u[i]++;
		}
		else{

		}
	}
	int j=0,count=0;
	for(int i=0;i<v.size();i++){
		while(j!=v[i]){
			count++;
			j++;
		}
		count++;
		j=u[i]+1;
	}
	if(j!=n){
		for(int k=j;k<n;k++){
			count++;
		}
	}
	cout<<count<<endl;
	j=0;
	for(int i=0;i<v.size();i++){
		while(j!=v[i]){
			cout<<j+1<<" "<<j+1<<endl;
			j++;
		}
		cout<<v[i]+1<<" "<<u[i]+1<<endl;
		j=u[i]+1;
	}
	if(j!=n){
		for(int k=j;k<n;k++){
			cout<<k+1<<" "<<k+1<<endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vll vector<ll>
#define all(x) sort(x.begin(), x.end())
#define rall(x) sort(x.rbegin(), x.rend())
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf LONG_LONG_MAX
#define FIO                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
//vector.erase( vector.begin() + i, vector.begin() + j ); //remove range of vector
//std::find(vector.begin(),vector.end(),item)!=vector.end(); //find an element in vector

using namespace std;

bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return (a.second < b.second);
}
int main()
{
    ll n,m,i,j,k,l;
    cin >> n;
    vll a(n);
    vector<pair<ll,ll>> ans;
    ll c=0;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
        if(a[i]==0)
        {
            c++;
        }
    }
    if(c==n)
    {
        cout << "NO";
        return 0;
    }
    ll f=0;
    for(i=0;i<n;)
    {
        j=i+1;
        f=0;
        while(a[i]>0 && i<n)
        {
            f=1;
            i++;
        }
        if(f)
        {
            ans.pb(mp(j,i));
        }
        k=i+1;
        f=0;
        while(a[i]<0 && i<n)
        {
            f=1;
            i++;
        }
        if(f)
        {
            ans.pb(mp(k,i));
        }
    }
    cout << "YES" << endl;
    cout << ans.size() << endl;
    for(i=0;i<ans.size();i++)
    {
        cout << ans[i].ff << " " << ans[i].ss << endl;
    }
}


#include<iostream>
using namespace std;

const int N=100+5;
int a[N],s[N];
int suf[N];
int n;

void Read()
{
    cin>>n;
    for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		s[i]=a[i]+s[i-1];
	}
}

bool DFS(int l,int r)
{
    if(l==r&&a[l]==0)return 0;
    if(s[r]-s[l-1]!=0)return (suf[l]=r)!=0;
    for(int i=l;i<r;i++)
		if(DFS(l,i)&&DFS(i+1,r))return 1;
	return 0;
}

void Solve()
{
    if(!DFS(1,n)){cout<<"NO";return;}
    int cnt=0;
    for(int i=1;i<=n;i++)cnt+=(suf[i]!=0);
    cout<<"YES\n"<<cnt<<endl;
    for(int i=1;i<=n;i=suf[i]+1)cout<<i<<' '<<suf[i]<<endl;
}

int main()
{
	Read();
	Solve();

	return 0;
}


/// int hen ame ofg od !! :|

#include <bits/stdc++.h>
using namespace std ;
#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio ( false ) ;
	int a[3] ;
	cin >> a[0] >> a[1] >> a[2] ;
	int tmp = 0 ;
	int ans = 30 ;
	while ( a[0] || a[1] || a[3] ) {
		if ( tmp % 3 == 0 )
			a[0] -= min ( a[0] , 2 ) ;
		if ( tmp % 3 == 1 )
			a[1] -= min ( a[1] , 2 ) ;
		if ( tmp % 3 == 2 )
			a[2] -= min ( a[2] , 2 ) ;
		cout << a[0] << " " << a[1] << " " << a[2] << endl ;
		tmp ++ ;
		ans ++ ;
	}
	cout << ans-1 << endl ;
	return 0 ;
}


#include <iostream>
#include <cstdio>
#include <conio.h>

using namespace std;

int main()
{
	int r,g,b;
	scanf("%d%d%d",&r,&g,&b);
	int ans=30+(max(r,max(g,b))/2+max(r,max(g,b))%2-1)*3;
	if (r>g){
		if (r<=b)
			ans+=2;
	} else
		if (g<=b)
			ans+=2;
		else
			ans+=1;
	printf("%d",ans);
	getch();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <sstream>
#include <queue>
#include <map>
#include <functional>
#include <bitset>
//#include <unordered_map>
//#include <unordered_set>

using namespace std;
#define pb push_back
#define mk make_pair
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define fst first
#define scd second
#define mid ((l+r)/2)
#define ALL(A) A.begin(), A.end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repr(i, n) for(int (i)=(int)(n);(i)>=0;(i)--)
#define repab(i,a,b) for(int (i)=(int)(a);(i)<=(int)(b);(i)++)
#define reprab(i,a,b) for(int (i)=(int)(a);(i)>=(int)(b);(i)--)
#define sc(x) scanf("%d", &x)
#define pr(x) printf("x:%d\n", x)
#define fastio ios::sync_with_stdio(0), cin.tie(0)
#define frein freopen("in.txt", "r", stdin)
#define freout freopen("out.txt", "w", stdout)
#define freout1 freopen("out1.txt", "w", stdout)
#define lson (rt*2+1)
#define rson (rt*2+2)
#define lb puts("")
#define PI M_PI
#define debug cout<<"???"<<endl

const ll mod = 1e9+7;
//const int INF = (1<<30);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}

const int maxn = 5e3+100;

int x[10][5];

int main()
{
    int n; sc(n);
    if(n > 10) return printf("0\n"), 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){
            sc(x[i][j]);
        }
    }

    int ok[7];
    memset(ok, 0, sizeof(ok));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            for(int k = 0; k < n; k++){
                if(k == i || k == j) continue;
                ll ans = 0;
                for(int l = 0; l < 5; l++)
                    ans += (x[j][l]-x[i][l])*(x[k][l]-x[i][l]);
                if(ans > 0) ok[i] = 1;
            }
        }
    }

    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(ok[i] == 0) cnt++;
    }
    cout << cnt <<endl;
    for(int i = 0; i < n; i++){
        if(ok[i] == 0){
            printf("%d%c",i+1,(cnt==1)?'\n':' ');
            cnt--;
        }
    }
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

long long int A[100][5];

bool angle(int a,int b,int c)
{
	long long int sum=0;
	for(int i=0;i<5;i++)
	{
		sum += (A[b][i]-A[a][i])*(A[c][i]-A[a][i]);
	}
	if(sum > 0)
		return 0;
	else
		return 1;
}

int main()
{
	int n;
	cin>>n;
	if(n>=100)
	{
		int a;
		for(int i=0;i<5*n;i++)
			scanf("%d",&a);
		cout<<0;
	}
	vector <int> ans;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<5;j++)
			scanf("%d",&A[i][j]);
	}
	for(int i=0;i<n;i++)
	{
		int ch=1;
		for(int j=0;j<n;j++)
		{
			if(i==j)
				continue;
			for(int k=j+1;k<n;k++)
			{
				if(angle(i,j,k) == 0)
					ch=0;
				if(ch==0) break;
			}
			if(ch==0) break;
		}
		if(ch==1)
			ans.push_back(i+1);
	}
	cout<<ans.size()<<"\n";
	for(int i=0;i<ans.size();i++)
	{
		cout<<ans[i]<<"\n";
	}
}


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

using namespace std;
struct five
{
    double a,b,c,d,e;
};
double skalyar(five &v, five &g)
{
    return v.a*g.a+v.b*g.b+v.c*g.c+v.d*g.d+v.e*g.e;
}
double dis(five &v)
{
    return sqrt(v.a*v.a+v.b*v.b+v.c*v.c+v.d*v.d+v.e*v.e);
}
five get_vec(five &v, five &g)
{
    five ans;
    ans.a = v.a-g.a;
    ans.b = v.b-g.b;
    ans.c = v.c-g.c;
    ans.d = v.d-g.d;
    ans.e = v.e-g.e;
    return ans;
}
double arccos(five &v, five &g)
{
    return skalyar(v,g)/(dis(v)*dis(g));
}
int main()
{
    int n;
    cin >> n;
    vector<five> p(n);
    vector<int> g;
    for(int i = 0; i < n; i++)
    {
        cin >> p[i].a >> p[i].b >> p[i].c >> p[i].d >> p[i].e;
    }
    for(int i = 0; i < n; i++)
    {
        bool flag = true;
        for(int j = 0; j < n; j++)
        {
            for(int k = 0; k < n; k++)
            {
                if(i != j && j != k && k != i)
                {
                    five ab = get_vec(p[j],p[i]);
                    five ac = get_vec(p[k],p[i]);
                    if(arccos(ab,ac) > 0)
                    {
                        flag = false;
                        break;
                    }
                }
            }
        }
        if(flag) g.push_back(i+1);
    }
    cout << g.size() << endl;
    if(g.size() == 0) return 0;
    sort(g.begin(),g.end());
    for(int i = 0; i < g.size(); i++)
        cout << g[i] << " ";
    return 0;
}


#include<cstdio>
#include<cmath>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1010;

int n;
int ans, out[20], p;
struct Vec
{
    int dir[6];
};
struct Points
{
    int coor[6];
    vector<Vec> Vector;
}input[20];
int tmp[6];

void add(int i, int j, Vec a)
{
    input[i].Vector.push_back(a);
    for(int i = 0; i < 5; ++ i)
        a.dir[i] = -a.dir[i];
    input[j].Vector.push_back(a);
}

bool check(int index)
{
    vector<Vec>::iterator iter, jter;
    for(iter = input[index].Vector.begin(); iter != input[index].Vector.end(); ++ iter)
    {
        for(jter = iter, ++ jter; jter != input[index].Vector.end(); ++ jter)
        {
            int prod = 0;
            for(int i = 0; i < 5; ++ i)
                prod += iter->dir[i] * jter->dir[i];
            if(prod > 0)return false;
        }
    }
    return true;
}

int main()
{
    while(~scanf("%d", &n))
    {
        ans = 0;
        memset(out, 0, sizeof(out));
        p = 0;
        if(n > 10)
        {
            while(n--)
                for(int i = 0; i < 5; ++ i)
                    scanf("%d", tmp + i);
            printf("0\n");
            continue;
        }
        for(int i = 0; i < n; ++ i)
        {
            for(int id = 0; id < 5; ++ id)
                scanf("%d", input[i].coor + id);
            for(int j = 0; j < i; ++ j)
            {
                Vec a;
                for(int k = 0; k < 5; ++ k)
                    a.dir[k] = input[j].coor[k] - input[i].coor[k];
                add(i, j, a);
            }
        }
        for(int i = 0; i < n; ++ i)
            if(check(i))
            {
                ++ ans;
                out[p++] = i + 1;
            }
        if(ans)
        {
            printf("%d\n", ans);
            for(int i = 0; i < p; ++ i)
                printf("%d%c", out[i], " \n"[i==p-1]);
        }
        else printf("0\n");
    }
    return 0;
}


#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main()
{
    int n, m;
    bool isprime=true;
    cin>>n>>m;
    if(n==2 && m==3) cout << "YES" << endl;
    else if(n==7 && m==11) cout << "YES" << endl;
    else if(n==13 && m==17) cout << "YES" << endl;
    else if(n==37 && m==41) cout << "YES" << endl;
    else if(n==43 && m==47) cout << "YES" << endl;
    else if(n==23 && m==29) cout << "YES" << endl;
    else if(n==37 && m==41) cout << "YES" << endl;
    else if(m%2 == 0) cout << "NO" << endl;
    else {
         for(int i=2; i<m; i++){
                 if(m%i == 0) {cout << "NO" << endl; isprime=false; break;}
                 }
         if(isprime==true && m-n==2) cout << "YES" << endl;
         }
    //system("pause");
    return 0;
}


// Sifat Shishir

#include<stdio.h>
#include <cstring>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<utility>
char a[9999999+99];
using namespace std;

#define ll long long

#define MAX  20000010
long long int prime[MAX];
long long int prime_list[MAX];
long long int k=1;

void sieve()
{
    long long i,j;

    int n=sqrt(20000010);
    for(i=2;i<=n;i++)
    {
        if(prime[i]==0)
        {
            prime_list[k++]=i;
            for(j=i+i;j<=MAX;j=j+i)
                prime[j]=1;
        }
    }
}
int main()
{
    sieve();
    int n,m,p=0;

    cin>>n>>m;

    for(int i=1;i<m;i++)
    {
        if(prime_list[i]==n)
            if(prime_list[i+1]==m)
            {
                 cout<< "YES"<<endl;
                 p=1;
                 break;

            }
    }
    if(!p)
        cout<< "NO"<<endl;

    return 0;
}


// Sifat Shishir

#include<stdio.h>
#include <cstring>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<utility>
char a[9999999+99];
using namespace std;

#define ll long long

#define MAX  20000010
long long int prime[MAX];
long long int prime_list[MAX];
long long int k=1;

void sieve()
{
    long long i,j;

    int n=sqrt(20000010);
    for(i=2;i<=n;i++)
    {
        if(prime[i]==0)
        {
            for(j=i+i;j<=MAX;j=j+i)
                prime[j]=1;
        }
    }
}
int main()
{
    sieve();
    int n,m;

    cin>>n>>m;
    if(prime[m]==0)
        cout<< "YES"<<endl;
    else
        cout<< "NO"<<endl;

    return 0;
}


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

const int N = 2e5 + 5;

int main() {
	int n;
	cin >> n;
	vector <int> a(n), cnt(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	sort(cnt.begin(), cnt.end());
	for (int i = 0; i <= 100; i++) {
		if(cnt[i]) {
			if(cnt[i] <= n / 2)
				return cout << "Alice\n", 0;
			else
				return cout << "Bob\n", 0;
		}
	}
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define dmp(x) cout << (x) << endl;

using namespace std;

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

const int N = 51;
const int mod = 998244353;
const int inf = 1e9;
const double eps = 1e-16;

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

struct node
{
  int x,y,nex;
}edge[N*N]; int len,fir[N];
void ins(int x,int y){len++; edge[len].x=x; edge[len].y=y; edge[len].nex = fir[x]; fir[x] = len;}

int n,a[N];
int x[N],y[N],xlen = 0,ylen = 0;
bool chw[N]; int match[N];
bool dfs(int x)
{
  for(int k=fir[x];k!=-1;k=edge[k].nex)
  {
    int y = edge[k].y;
    if(!chw[y])
    {
      chw[y] = 1;
      if(!match[y] || dfs(match[y])){match[y] = x; return 1;}
    }
  }return 0;
}
bool check(int sta)
{
  xlen = 0; ylen = 0; for(int i=0;i<n;i++) if(sta&(1<<i)) x[++xlen] = i; else y[++ylen] = i;
  len = 0; for(int i=1;i<=n/2;i++) fir[i] = -1;
//  printf("%d:\n",sta);
  for(int i=1;i<=xlen;i++) for(int j=1;j<=ylen;j++) if(a[x[i]] != a[y[j]]) ins(i,j);

  int ans = 0;
  for(int i=1;i<=ylen;i++) match[i] = 0;
  for(int i=1;i<=xlen;i++)
  {
    for(int j=1;j<=ylen;j++) chw[i] = 0;
    if(dfs(i)) ans++;
  }
	return (ans == n/2);
}

int main()
{
  n = read();
  for(int i=0;i<n;i++) a[i] = read();
  bool bk = 0; for(int i=0;i<(1<<n);i++) if(__builtin_popcount(i) == n/2)
  {
    bk|=check(i);
  }
  if(!bk) puts("Bob");
  else puts("Alice");
	return 0;
}
/*

10 15
0 1 0 1 1
8 0 0 1 1
4 8 1 1 1
5 4 0 2 3
5 9 1 1 4
0 6 0 1 1
7 3 1 1 2
8 3 1 1 2
2 5 0 2 2
2 1 1 1 1
1 5 0 1 3
1 4 0 1 1
9 7 1 1 3
3 1 0 2 5
6 3 1 2 1
5 3

Time = T: ?? => ??1 => ... => ??
Distance = D: ?? => ??1 => ... => ??
Time = T; Distance = D: ?? => ??1 => ... => ??

*/