#include<stdio.h>
#include<stdlib.h>
#include<math.h>
long long int funk(long long int x,long long int b){
long long int m=1;

long long int a;

for(a=1;a<=b;a++){
m=m*x;
}
return m;

}
main(){

    long long int a,b,c;
  long long  int increase;
   long long int unos,unos1;
    scanf("%lld%lld",&unos,&unos1);
  long long  int x;
   long long int counter=0;

    for(a=64;a>=3;a--){
            x=funk(2,a)-1;
            increase=1;
            for(b=1;b<=a;b++)
            {
                increase=increase*2;
               //printf("%lld\n",x-increase);
                    if( ((x-increase)>=unos) && ((x-increase) <=unos1) ){
                           counter++;
                    }

            }

    }

    printf("%lld",counter);

}


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

int main() {
	long long a, b, c, d, e, f;

	scanf("%lld%lld", &a, &b);
	e = 0;
	for (c = b; c >= 0; --c) {
		d = floor((b - c) * a);
		f = (c + 1) / 2 * (2 * (d * (d + 1) / 2) + c * (d + 1));
		if (f > e)
			e = f;
	}
	printf("%lld\n", e);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){

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

	char C[4][4]={{0}};

	int D[4][4]={{0}};

	while(scanf("%d",&k)){

		for(i=0;i<4;i++)
				scanf("%s",C[i]);

		for(i=0;i<4;i++)
			for(j=0;j<4;j++)
				D[i][j]=C[i][j]-48;

		for(l=1;l<10;l++){
			for(i=0;i<4;i++)
				for(j=0;j<4;j++)
					if(l==D[i][j])
						count++;
			if(count > k*2){
				count=!printf("NO\n");
				break;
			}
			count=0;
		}

		if(l==10)
			count=!printf("YES\n");

	}

	return 0;

}


#include<stdio.h>
int main()
{
int a,b,c;
int s=0;
scanf("%d%d%d",&a,&b,&c);
while(a<=100){
    if(a+b>c){
        printf("%d",s);
    }
    else{
        a=a+1;
        c=c+1;
        s=s+1;
    }
}
return 0;
}


#include<stdio.h>
int main()
{
	int a,b,c,t=0,min,f=0;
	scanf("%d%d%d",&a,&b,&c);
	if(a<=c && a<=b)
	{
		min=a;
		f=1;
	}
	else if(c<=b && c<=a)
	{
	  min=b;
	  f=2;
	}
	else if(b<=c && b<=a)
	{
		min=c;
		f=3;
	}
	while(((a+b)<=c) || ((b+c)<=a) || ((c+a)<=b))
	{
		min++;
		t++;
		if(f==1)
		a=min;
		else if(f==2)
		b=min;
		else if(f==3)
		c=min;
	}
	printf("%d",t);
	return 0;
}


#include<stdio.h>
int main()
{
    int l,a,p,c,i,j,k;
    scanf("%d%d%d",&l,&a,&p);

    /*for(i=1; i<=l; i++)
    {
        j=i*2;
        k=i*4;
        if(j>a||k>p)
        {
            i--;
            break;
        }
        if(i==l)
            break;
    }

    c=i*7;
    printf("%d",c);*/


#include < stdio.h >

int min(int num1, int num2);
int main(){
    int comp[3];
    for(int i = 0; i < 3; i++){
        scanf("%d",&comp[i]);
    }
    a = comp[1] / 2;
    b = comp[2] / 4;
    z = min(comp[0], min(a,b));
    printf("%d",((1 * z) + (2 * z) + (4 * z)));
    return 0;
}

int min(int num1, int num2){
    return num1 > num2 ? num2 : num1;
}


#include<stdio.h>
int main(){
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
int i,j,k;
i=a;
j=b/2;
k=c/4;
if(i/j==0 && i/k==0)
printf("%d",7*i);
else if(j/i==0 && j/k==0)
printf("%d",7*j);
else
printf("%d",7*k);
return 0;}


#include<stdio.h>

int main()

{
    int l,d,v,g,r;

    scanf("%d%d%d%d%d",&l,&d,&v,&g,&r);

    if((double)d/v)<=g)
    {
        printf("%f",((double)l/v));
    }

    else
    {
        printf("%f",(g + r + ((double)(l-d)/v)));
    }
return 0;
}


#include<stdio.h>
int main()
{
	float l,d,v,t,g,r,flag;
	int i;
	scanf("%f%f%f%f%f",&l,&d,&v,&g,&r);
	t=d/v;
	for(i=0;i<=(d/v)+1;i++)
	{if(i*(g+r)<=t< i*(g+r)+g)
	 {flag=1;
	  break;}
	 if(i*(g+r)+g<=t<(i+1)*(g+r))
	 {flag=0;
	  break;}
	}
	if(flag==1)
	{t=l/v;
	printf("%f",t);
	}
	if(flag==0)
	printf("%f",(i+1)*(g+r)+(l-d)/v);
	return 0;
}


#include<stdio.h>
long long main()
{
  long long n;
  scanf("%lld",&n);
  if(n==0)
  {
  printf("%lld",n)
  }
  else
  {
  if((n+1)%2==0)
  {
   printf("%lld",(n+1)/2);
  }
  else
  {
  printf("%lld",n+1);
  }
  };
  return 0;
  }


#include <stdio.h>

int main()
{
    int n, x;
    scanf("%d", n);
    if (n%2 == 1)
    {
        x=(n+1)/2;
        printf("%d", x);
    }
    else
    {
        x=n/2;
        printf("%d", x);
    }
    return 0;
}


#include <stdio.h>

int mmax( int a, int b) {
	if ( a > b ) return b;
	else return a;
}

int main()
{
	int i, j, k;
	int a, b, c;
	int max;

	scanf("%d%d%d", &a, &b, &c);
	max = mmax(a,mmax(b,c));
	for ( i = 0; i <= max; i++)
		for ( j = 0; j <= max; j++)
			for ( k = 0; k <= max; k++)
				if ( i + k == a && i + j == b && j + k == c ) {
					printf("%d %d %d", i, j, k);
					return 0;
				}

	printf("Impossible");
	return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
    char s[50];
    scanf("%s",s);
    char ans[]="hello";
    int j=0;
    for (int i=0;i<strlen(s);i++){
        if(ans[j]==s[i]){
        j++;}}
    if(j>4){
    printf("YES\n");}
    else {
    printf("NO\n");}

}


#include<stdio.h>
int main ()
{
    int a,b,n,i,j,k;
    int flag=0;
    scanf("%d %d",&a,&b);
    for(i=0;i<a && i<b ;i++)
    {

    }

   if(a==b)
   {
       flag=0;
   }
    else if(a>b)
       {
           n=a-b;
           while(n>=2){

           if(n%2==0)
           {
               flag++;
               n=n/2;
           }
           }
       }
    else if(b>a)
    {
        n=b-a;
       while(n>=2)
       {
           if(n%2==0)
           {
               flag++;
               n=n/2;

           }
       }

    }
    printf("%d %d",i,flag);

}


#include <stdio.h>

int n,t,c;

void dfs(int y1,int y2,int x,int l) {
	// printf("%d %d %d %d\n",y1,y2,x,l);
	if (l>t) return;
	if (x==n) {
		if (y1<y2&&t==l) c++;
		return;
	}
	int y;
	for (y=1;y<5;y++)
		if (y!=y1)
			dfs(y,y1,x+1,l+(y1>y2&&y1>y));
}

int main() {
	scanf("%d %d\n",&n,&t);
	dfs(0,-1,0,0);
	printf("%d\n",c);
	return 0;
}


#include <stdio.h>

int n,t,c;

void dfs(int y1,int y2,int x,int l) {
	// printf("%d %d %d %d\n",y1,y2,x,l);
	if (x==2&&y1<y2) return;
	if (l>t) return;
	if (x==n) {
		if (y1<y2&&t==l) c++;
		return;
	}
	int y;
	for (y=1;y<5;y++)
		if (y!=y1)
			dfs(y,y1,x+1,l+(y1>y2&&y1>y));
}

int main() {
	scanf("%d %d\n",&n,&t);
	dfs(0,-1,0,0);
	printf("%d\n",c);
	return 0;
}


#include<stdio.h>
int main()
{
    int a,b,c,x,y,ans;
    scanf("%d %d %d", &a, &b, &c);
    x=b/2;
    y=c/4;
    if(a<x && a<y)
    {
        ans=a+(2*a)+(4*a);
    }
    else if(x<y && x<a)
    {N
        ans=x+(2*x)+(4*x);
    }
    else
    {
        ans=y+(2*y)+(4*y);
    }
    printf("%d\n",ans);
    return 0;
}


#include<stdio.h>
int main()
{
	int a,b,c,;
	int i;
	    scanf("%d%d%d",&a,&b,&c);
	    for(i=a;i>=1;i--)
		    if(b>=2*i && c>=4*i)
		    	{break;}
	    printf("%d",7*i);
}


#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main() {
    int x,y,n,i,j,k,count=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    	for(j=i+1;j<=n;j++)
    	{
    		for(k=j+1;k<i+j && k<=n ;k++)
    		{
    			if((i+k>j) && (j+k>i))
    			{
    				if((i^j)==k)
    				{
    					count++;
    					//printf("%d %d %d\n",i,j,k);
    				}
    			}
    		}
    	}
    }
    printf("%d",count);

    return 0;
}


#include<stdio.h>

int main()
{
   int t,i,j,k,cnt=0;

    scanf("%d",&t);

    for(i=1;i<=t-2;i++){
        for(j=i;j<=t;j++){
            for(k=j;k<=t;k++){
                if((i^j^k)==0 && i+j>k && j+k>i && k+i>j) cnt++;
            }
        }
    }
    printf("%d\n",cnt);

   return 0;
}


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

using namespace std;

typedef long long ll;

int n,ans;

int main()
{
    scanf("%d",&n);
    for (int i = 1;  i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            int temp = i ^ j;
            if (temp > j || temp > i)
                continue;
            if (temp + j <= i)
                continue;
            ans++;
        }
    }
    printf("%d\n",ans);

    return 0;
}


#include<stdio.h>
int main()
{
  int n,a,b,c,i,max,count=0,j,k;
  scanf("%d",&n);
  for (int i = 1; i < n; ++i)
  {
    for (int j = i+1; j < n; ++j)
    {
      /* code */
      if(i>j)
        max=i;
      else
        max=j;
      for (int k = max+1; k < i+j; ++k)
      {
        /* code */
        if((i^j^k)=0)
          count++;
      }
    }
  }
  printf("%d\n",count );
}


#include<stdio.h>
int main()
{
  int n,a,b,c,i,max,count=0,j,k;
  scanf("%d",&n);
  for (int i = 1; i < n; ++i)
  {
    for (int j = i+1; i < n; ++j)
    {
      /* code */
      if(i>j)
        max=i;
      else
        max=j;
      for (int k = max+1; i < i+j; ++k)
      {
        /* code */
        if((i^j)==k)
          count++;
      }
    }
  }
  printf("%d\n",count );
}


#include <stdio.h>
#include <stdlib.h>

int isTriangle(int a,int b,int c)
{
    if(a+b>c)
    {
        if(b+c>a)
        {
            if(a+c>b)
            {
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    //printf("%d",3^5^6);
    int i,j,k,n,count=0;
    scanf("%d",&n);
    for(k=1;k<=n;k++)
    {
        for(j=1;j<=k;j++)
        {
            for(i=1;i<=j;i++)
            {
                if((i^j^k)==0)
                {
                    if(isTriangle(i,j,k)==1)
                        count++;
                    //printf("%d and %d and %d\n",i,j,k);
                }
            }
        }
    }
    printf("%d",count);
    return 0;
}


#include <stdio.h>
#include <string.h>

#define LL "%I64d"

long long d[2][256][7][8][9][2][2];
int digits[20], dgCount;

long long solve(long long n) {
    int i, mask, j, high, r7, r8, r9, last, next;
    memset(d, 0, sizeof(d));

    dgCount = 0;
    while(n) {
        digits[dgCount++] = n % 10;
        n /= 10;
    }

    d[0][0][0][0][0][0][0] = 1;
    for(i = 0; i < dgCount; i++) {
      memset(d[(i & 1) ^ 1], 0, sizeof(d[(i & 1) ^ 1]));
      for(mask = 0; mask < (1 << 8); mask++) {
        for(r7 = 0; r7 < 7; r7++) {
          for(r8 = 0; r8 < 8; r8++) {
            for(r9 = 0; r9 < 9; r9++) {
              for(high = 0; high < 2; high++) {
                for(last = 0; last < 2; last++) {
                    if(d[i & 1][mask][r7][r8][r9][high][last] == 0)
                        continue;
                    int limit = 9;
                    if(high == 0)
                        limit = digits[dgCount - i - 1];
                    for(next = 0; next <= limit; next++) {
                        int nr7 = (10 * r7 + next) % 7;
                        int nr8 = (10 * r8 + next) % 8;
                        int nr9 = (10 * r9 + next) % 9;
                        int nmask = (next < 2 ? mask : mask | (1 << (next - 2)));
                        int nhigh = (high ? 1 : (next == limit ? 0 : 1));
                        int nlast = (next == 0 || next == 5 ? 1 : 0);
                        d[(i & 1) ^ 1][nmask][nr7][nr8][nr9][nhigh][nlast] +=
                            d[i & 1][mask][r7][r8][r9][high][last];
                    }
                }
              }
            }
          }
        }
      }
    }

    long long ans = 0;
    for(mask = 0; mask < (1 << 8); mask++) {
        for(r7 = 0; r7 < 7; r7++) {
            if((mask & (1 << 5)) && r7 > 0)
                break;
            for(r8 = 0; r8 < 8; r8++) {
                if((mask & (1 << 0)) && (r8 % 2 > 0))
                    continue;
                if((mask & (1 << 2)) && (r8 % 4 > 0))
                    continue;
                if((mask & (1 << 6)) && (r8 > 0))
                    break;
                for(r9 = 0; r9 < 9; r9++) {
                    if((mask & (1 << 1)) && (r9 % 3 > 0))
                        continue;
                    if((mask & (1 << 7)) && (r9 > 0))
                        continue;
                    for(high = 0; high < 2; high++)
                        for(last = 0; last < 2; last++) {
                            if((mask & (1 << 3)) && last == 0)
                                continue;
                            ans += d[dgCount & 1][mask][r7][r8][r9][high][last];
                        }
                }
            }
        }
    }

    return ans;
}

int main() {
    int t, i;
    scanf("%d", &t);
    for(i = 0; i < t; i++) {
        long long from, to;
        scanf(LL" "LL, &from, &to);
        printf(LL"\n", solve(to) - solve(from - 1));
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

#define LL "%I64d"

long long d[2][256][7][8][9][2][2];
int digits[20], dgCount;

int nx7[10][10], nx8[10][10], nx9[10][10];

long long solve(long long n) {
    int i, mask, j, high, r7, r8, r9, last, next;
    memset(d, 0, sizeof(d));

    dgCount = 0;
    while(n) {
        digits[dgCount++] = n % 10;
        n /= 10;
    }

    d[0][0][0][0][0][0][0] = 1;
    for(i = 0; i < dgCount; i++) {
      memset(d[(i & 1) ^ 1], 0, sizeof(d[(i & 1) ^ 1]));
      for(mask = 0; mask < (1 << 8); mask++) {
        for(r7 = 0; r7 < 7; r7++) {
          for(r8 = 0; r8 < 8; r8++) {
            for(r9 = 0; r9 < 9; r9++) {
              for(high = 0; high < 2; high++) {
                for(last = 0; last < 2; last++) {
                    if(d[i & 1][mask][r7][r8][r9][high][last] == 0)
                        continue;
                    int limit = 9;
                    if(high == 0)
                        limit = digits[dgCount - i - 1];
                    for(next = 0; next <= limit; next++) {
                        int nr7 = nx7[r7][next];
                        int nr8 = nx8[r8][next];
                        int nr9 = nx9[r9][next];
                        int nmask = (next < 2 ? mask : mask | (1 << (next - 2)));
                        int nhigh = (high ? 1 : (next == limit ? 0 : 1));
                        int nlast = (next == 0 || next == 5 ? 1 : 0);
                        d[(i & 1) ^ 1][nmask][nr7][nr8][nr9][nhigh][nlast] +=
                            d[i & 1][mask][r7][r8][r9][high][last];
                    }
                }
              }
            }
          }
        }
      }
    }

    long long ans = 0;
    for(mask = 0; mask < (1 << 8); mask++) {
        for(r7 = 0; r7 < 7; r7++) {
            if((mask & (1 << 5)) && r7 > 0)
                break;
            for(r8 = 0; r8 < 8; r8++) {
                if(((mask & (1 << 4)) || (mask & (1 << 0))) && (r8 % 2 > 0))
                    continue;
                if((mask & (1 << 2)) && (r8 % 4 > 0))
                    continue;
                if((mask & (1 << 6)) && (r8 > 0))
                    break;
                for(r9 = 0; r9 < 9; r9++) {
                    if(((mask & (1 << 4)) || (mask & (1 << 1))) && (r9 % 3 > 0))
                        continue;
                    if((mask & (1 << 7)) && (r9 > 0))
                        continue;
                    for(high = 0; high < 2; high++)
                        for(last = 0; last < 2; last++) {
                            if((mask & (1 << 3)) && last == 0)
                                continue;
                            ans += d[dgCount & 1][mask][r7][r8][r9][high][last];
                            /*if(d[dgCount & 1][mask][r7][r8][r9][high][last] > 0)
                                printf("mask=%d r7=%d r8=%d r9=%d high=%d last=%d val="LL"\n"
                                        , mask, r7, r8, r9, high, last,
                                        d[dgCount & 1][mask][r7][r8][r9][high][last]);
                            */
                        }
                }
            }
        }
    }

    return ans;
}

int stupid(int n) {
    int i, j, tmp;
    int ans = 0;
    for(i = 0; i <= n; i++) {
        int isValid = 1;
        tmp = i;
        while(tmp) {
            int cur = tmp % 10;
            tmp /= 10;
            if(cur >= 2 && i % cur)
                isValid = 0;
        }
        ans += isValid;
    }
    return ans;
}

void test() {
    int n;
    for(n = 0; n <= 200; n++) {
        int answer = stupid(n);
        int cand = solve(n);
        if(answer != cand) {
            puts("WA");
            printf("n = %d, answer is %d, you think it's %d\n", n, answer, cand);
            break;
        }
    }
}

void init() {
    int i, j;
    for(i = 0; i < 10; i++)
        for(j = 0; j < 10; j++) {
            nx7[i][j] = (10 * i + j) % 7;
            nx8[i][j] = (10 * i + j) % 8;
            nx9[i][j] = (10 * i + j) % 9;
        }
}

int main() {
    int t, i;
    init();
    scanf("%d", &t);
    for(i = 0; i < t; i++) {
        long long from, to;
        scanf(LL" "LL, &from, &to);
        printf(LL"\n", solve(to) - solve(from - 1));
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define ll long long
#define M 2520

int GCD(int a,int b){int r; while(a){r=b; b=a; a=r%a;} return b;}
int LCM(int a,int b){ return a/GCD(a,b)*b; }

ll *dp1, *dp2, *nx1, *nx2, *swap;
ll dp1__[M], dp2__[M];
ll nx1__[M], nx2__[M];

ll dp[323][M];
int bc[323];

int nex[M][10];

ll solve(ll mx){
  int i,j,k,mask,use[10],us,now,nn;
  int go[20],gos,g;
  ll res;

  dp1=dp1__; dp2=dp2__; nx1=nx1__; nx2=nx2__;

  gos=0;
  while(mx) go[gos++]=mx%10, mx/=10;

  rep(mask,1<<8){
    if( (mask&1<<2) && !(mask&1<<0) ) continue;
    if( (mask&1<<4) && (!(mask&1<<0)||!(mask&1<<1)) ) continue;
    if( (mask&1<<6) && (!(mask&1<<0)||!(mask&1<<2)) ) continue;
    if( (mask&1<<7) && (mask&1<<1) ) continue;
    us=2; use[0]=0; use[1]=1;
    rep(i,8) if(mask&1<<i) use[us++]=i+2;

    rep(i,M) dp1[i]=dp2[i]=0;
    dp1[0]=1;

    rep(i,M) rep(j,us) nex[i][j] = (i*10+use[j])%M;

    for(now=gos-1;now>=0;now--){
      rep(i,M) nx1[i]=nx2[i]=0;

      rep(i,M) if(dp2[i]) rep(k,us) nx2[nex[i][k]] += dp2[i];

      rep(i,M) if(dp1[i]) rep(k,us){
        if(go[now]==use[k]) nx1[nex[i][k]] += dp1[i];
        if(go[now]> use[k]) nx2[nex[i][k]] += dp1[i];
      }

      swap=dp1, dp1=nx1, nx1=swap;
      swap=dp2, dp2=nx2, nx2=swap;
    }

    rep(i,M) dp[mask][i] = dp1[i] + dp2[i];
  }

  res = 0;
  rep(mask,1<<8){
    g=1;
    rep(i,8) if(mask&1<<i) g=LCM(g,i+2);

    rep(i,mask+1) if( (i&mask)==i ){
      for(j=0;j<M;j+=g){
        if( (bc[mask] - bc[i])%2 ) res -= dp[i][j];
        else                       res += dp[i][j];
      }
    }
  }

  return res;
}

int main(){
  int i,j,k,l,n;
  ll a, b, res;
  int size;

  bc[0]=0;
  REP(i,1,1<<8) bc[i] = bc[i&(i-1)]+1;

  scanf("%d",&size);
  while(size--){
    scanf("%I64d%I64d",&a,&b);
    res = solve(b) - solve(a-1);
    printf("%I64d\n",res);
  }

  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define ll long long
#define M 2520

int GCD(int a,int b){int r; while(a){r=b; b=a; a=r%a;} return b;}
int LCM(int a,int b){ return a/GCD(a,b)*b; }

ll *dp1, *dp2, *nx1, *nx2, *swap;
ll dp1__[M], dp2__[M];
ll nx1__[M], nx2__[M];

ll dp[323][M];
int bc[323];

int nex[M][10];

ll solve(ll mx){
  int i,j,k,mask,use[10],us,now,nn;
  int go[20],gos,g;
  ll res;

  dp1=dp1__; dp2=dp2__; nx1=nx1__; nx2=nx2__;

  gos=0;
  while(mx) go[gos++]=mx%10, mx/=10;

  rep(mask,1<<8){
    us=2; use[0]=0; use[1]=1;
    rep(i,8) if(mask&1<<i) use[us++]=i+2;

    rep(i,M) dp1[i]=dp2[i]=0;
    dp1[0]=1;

    rep(i,M) rep(j,us) nex[i][j] = (i*10+use[j])%M;

    for(now=gos-1;now>=0;now--){
      rep(i,M) nx1[i]=nx2[i]=0;

      rep(i,M) if(dp2[i]) rep(k,us) nx2[nex[i][k]] += dp2[i];

      rep(i,M) if(dp1[i]) rep(k,us){
        if(go[now]==use[k]) nx1[nex[i][k]] += dp1[i];
        if(go[now]> use[k]) nx2[nex[i][k]] += dp1[i];
      }

      swap=dp1, dp1=nx1, nx1=swap;
      swap=dp2, dp2=nx2, nx2=swap;
    }

    rep(i,M) dp[mask][i] = dp1[i] + dp2[i];
  }

  res = 0;
  rep(mask,1<<8){
    g=1;
    rep(i,8) if(mask&1<<i) g=LCM(g,i+2);

    rep(i,mask+1) if( (i&mask)==i ){
      for(j=0;j<M;j+=g){
        if( (bc[mask] - bc[i])%2 ) res -= dp[i][j];
        else                       res += dp[i][j];
      }
    }
  }

  return res;
}

int main(){
  int i,j,k,l,n;
  ll a, b, res;
  int size;

  bc[0]=0;
  REP(i,1,1<<8) bc[i] = bc[i&(i-1)]+1;

  scanf("%d",&size);
  while(size--){
    scanf("%I64d%I64d",&a,&b);
    res = solve(b) - solve(a-1);
    printf("%I64d\n",res);
  }

  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007

int cmpfunc(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int min(int a,int b){
	return (a>b)?b:a;
}

int
main(int argc, char *argv[]) {
	long long a,b;
    scanf("%lld %lld",&a,&b);
    int sa[100],sb[100];
    int i=0;
    while(a>0){
        sa[i]=a%2;
        a/=2;
        i++;
    }
    int j=0;
    while(b>0){
        sb[j]=b%2;
        b/=2;
        j++;
    }
    int k;
    int len_a=i,len_b=j;
    long long ans=0;
    if(len_a==len_b) {
        for(i=len_a-1;i>=0;i--){
            if(sa[i]==sb[i] && sa[i]==1) ;
            else break;
        }
        if(i<0) {ans=0;}
        else{
            if(sa[i]==sb[i] && sa[i]==0){
                for(j=i-1;j>=0;j--){
                    if(sb[j]==0) {ans=0;break;}
                }
                if(j<0) {ans++;}
            } else{
                for(j=i-1;j>=0;j--){
                    if(sb[j]==0) break;
                }
                if(j>=0){
                    ans=i-j;
                    for(k=j-1;k>=0;k--){
                        if(sb[k]==0) break;
                    }
                    if(k<0) {ans++;}
                } else {ans=i+1;}
            }
        }
    } else {
        for(i=len_a-1;i>=0;i--){
            if(sa[i]==0) break;
        }
        if(i>=0){
            ans=i+1;
        }
        for(i=len_a+1;i<len_b;i++)
            {ans+=i-1;}
        //consider len_b only
        for(i=len_b-1;i>=0;i--){
            if(sb[i]==0) break;
        }
        if(i<0) {ans+=len_b;}
        else{
            ans+=len_b-2-i;
            for(k=i-1;k>=0;k--){
                if(sb[k]==0) break;
            }
            if(k<0) {ans++;}
        }
    }
    printf("%lld\n",ans);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

typedef unsigned long long int llu;

int numberOfZeros(llu num, size_t const size){
	int i, result, temp;
	for(i = 0, result = 0, temp = 0; i < size*8; i++){
		// printf("%llu\n", num);
		if(num%2 == 0){
			temp++;
		} else {
			result += temp;
			temp = 0;
		}
		num = num >> 1;
		// printBits(sizeof(num), &num);
	}

	return result;
}

void printBits(size_t const size, void const * const ptr)
{
    unsigned char *b = (unsigned char*) ptr;
    unsigned char byte;
    int i, j;

    for (i=size-1;i>=0;i--)
    {
        for (j=7;j>=0;j--)
        {
            byte = b[i] & (1<<j);
            byte >>= j;
            printf("%u", byte);
        }
    }
    puts("");
}

int findMax(llu* b){
	int i;
	llu max = 1, mask = 3;
	max = ~(max << (sizeof(max)*8 - 2));

	for(i = 0; i < sizeof(max)*8; i++){
		if(max <= *b){
			break;
		}
		max = max >> 1;
	}

	mask = mask << (61 - i);
	for(; (max ^ mask) <= *b && i < 62; max = max ^ mask, mask = mask >> 1, i++);

	*b = max;

	return 62 - i;
}

int findMin(llu *a, llu b){
	int i;
	llu min;

	for(min = *a; min < b; min++){
		if(numberOfZeros(min, sizeof(min)) == 1){
			break;
		}
	}

	*a = min;

	for(i = 0; i < 8*sizeof(min); i++){
		if(min%2 == 0){
			break;
		}
		min = min >> 1;
	}

	return i;
}

int len(llu a){
	int temp, i, result;

	for(i = 0, temp = 0, result = 0; i < 8*sizeof(a); i++, temp++, a = a >> 1){
		if(a%2 != 0){
			result += temp;
			temp = 0;
		}
	}

	return ++result;
}

int main(){
	llu i, a, b, ta, tb, result = 0;
	int pa, pb;

	scanf("%llu %llu", &a, &b);
	ta = a;
	tb = b;

	pb = findMax(&tb);
	pa = findMin(&ta, tb);

	if(ta >= a && tb <= b && ta <= tb){
		for(i = len(ta); i <= len(tb); i++){
			result += i - 1;
		}

		result -= pb;
		result -= len(ta) - 2 - pa;
	}

	printf("%llu", result);
	return 0;
}
// 1453787442792


#include<stdio.h>
int main(){
	long long int i,sayi,a,b,n = 0,sonuc,ensonuc = 0;
	scanf("%lld %lld",&a,&b);
	for(i = a ; i <= b ; i++){
		sayi = i;
		sonuc = 0;
		while(sayi>=1){
			if(sayi%2==0)
				sonuc++;
			sayi=sayi/2;
			n++;
		}
		if(sonuc==1)
			ensonuc++;
	}
	printf("%lld",ensonuc);
	return 0;
}


#include<stdio.h>

int main()
{
	unsigned long long int s, e, cnt=0, curcnt, cn, temp, temp2;
	scanf("%llu %llu",&s, &e);
	for(temp=s;temp<=e;temp++){
		//printf("%llu\n",temp);
		for(cn=temp,curcnt=0;cn>0;cn=cn>>1){
			temp2=cn&1;
			if(temp2==0)curcnt++;
			if(curcnt==2) break;
		}
		if(curcnt==1) cnt++;
	}
	printf("%llu\n",cnt);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
long long int power(long long int x,long long int y)
{
	if(y==0)
		return 1;
	else if(y%2==0)
		return power(x,y/2)*power(x,y/2);
	else
		return x*power(x,y/2)*power(x,y/2);
}
int cmpfunc (const void * a, const void * b)
{
	return ( *(int*)a - *(int*)b );
}
int main()
{
	long long int n,i,j,a[2484],l=0,count=0,b,c;
	scanf("%lld %lld",&b,&c);
	for(i=2;i<=70;i++)
	{
		for(j=i-2;j>=0;j--)
		{
			a[l]=power(2,i)-1-power(2,j);
			l++;
		}
	}
	qsort(a, 2484, sizeof(long long int), cmpfunc);
	for(i=0;i<2484;i++)
	{
		if(b<=a[i] && a[i]<=c && a[i]!=a[i+1])
		{
			count++;
		}
	}
	printf("%lld\n",count);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<ctype.h>
#include<limits.h>
#define eps 1e-9
#define ll long long int
#define N 500500
char arr[N];
ll first_try(ll numb){
   ll gen = numb+3;
   if(gen%4==0){
      ll before=(gen/4)-1;
      ll get_res=((gen/4+before)-1)*6;
      return get_res + (numb-1);
   }
   ll gen1=numb+2;
   if(gen1%4==0){
      ll before=(gen1/4);
      ll get_res=((gen1/4+before)-1)*6;
      return get_res + (numb-1);
   }
   return -1;
}

ll second_try(ll numb){
   ll gen = numb+1;
   if(gen%4==0){
      ll before=(gen/4)-1;
      ll get_res=((gen/4+before)-1)*6;
      return get_res + (numb-3);
   }
   ll gen1=numb;
   if(gen1%4==0){
      ll before=(gen1/4);
      ll get_res=((gen1/4+before)-1)*6;
      return get_res + (numb-3);
   }
   return -1;
}
int main(){
   gets(arr);
   char c;
   ll numb=0;
   char *q=arr;
   while(isdigit(*q)){
      numb=numb*10+(*q-'0');
      q++;
   }
   c=*q;

   if(first_try(numb)!=-1){
      ll cmpt=first_try(numb);
      cmpt++;
      if(c=='f'){
         printf("%lld",cmpt);
      }
      else if(c=='e'){
          printf("%lld",cmpt+1);
      }
      else if(c=='d'){
          printf("%lld",cmpt+2);
      }
      else if(c=='c'){
          printf("%lld",cmpt+3);
      }
      else if(c=='b'){
          printf("%lld",cmpt+4);
      }
      else if(c=='a'){
          printf("%lld",cmpt+5);
      }
      return 0;
   }
   else{
      ll cmpt=second_try(numb);
      cmpt--;
      if(c=='f'){
         printf("%lld",cmpt);
      }
      else if(c=='e'){
          printf("%lld",cmpt+1);
      }
      else if(c=='d'){
          printf("%lld",cmpt+2);
      }
      else if(c=='c'){
          printf("%lld",cmpt+3);
      }
      else if(c=='b'){
          printf("%lld",cmpt+4);
      }
      else if(c=='a'){
          printf("%lld",cmpt+5);
      }
      return 0;
   }
}


#include<stdio.h>
int main() {
    long long row=0;
    char col='\0';
    while(1){
        char get=getchar();
        if(get=='\n' || get==EOF){
            break;
        }else{
            if(get>='0' && get<='9'){
                row=10*row+(long long)(get-'0');
            }else{
                col=get;
                break;
            }
        }
    }
    //printf("row=%lld,col=%c\n",row,col);
    long long time=1;
    //int step=0;
    long long row1=1;
    char col1='f';
    long long row2=3;
    char col2='f';

    while(1){
        /*
        if(step==5)break;
        step++;
        */
        if(row1==row && col1==col){
            printf("%lld\n",time);
            break;
        }else if(row2==row && col2==col){
            printf("%lld\n",time);
            break;
        }
        //printf("%lld %c  ",row1,col1);
        //printf("%lld %c  ",row2,col2);
        //printf("%lld\n",time);
        if(col1=='f'){
            //printf("?##%lld####\n",time);
            col1 ='e';
            col2 ='e';
            time+=1;
        }else if(col1=='e'){
            col1='d';
            col2='d';
            time+=1;
        }else if(col1=='d'){
            col1='a';
            col2='a';
            time+=1;
        }else if(col1=='a'){
            col1='b';
            col2='b';
            time+=1;
        }else if(col1=='b'){
            col1='c';
            col2='c';
            time+=1;
        }else if(col1=='c'){
            time+=1;//先走到下一排，再走到下一个座位
            col1='f';
            col2='f';
            if(row1%2==1){
                row1=row1+1;
                row2=row2+1;
                time+=1;
            }else{
                row1=row1+3;
                row2=row2+3;
                time+=3;
            }
        }
    }
    return 0;
}


#include<stdio.h>
int main() {
    long long row=0;
    char col='\0';
    while(1){
        char get=getchar();
        if(get=='\n' || get==EOF){
            break;
        }else{
            if(get>='0' && get<='9'){
                row=10*row+(long long)(get-'0');
            }else{
                col=get;
                break;
            }
        }
    }
    //printf("%lld %c\n",row,col);
    long long base_time=0;
    if(row%4==1){
        base_time=row*4-3;
    }else if(row%4==2){
        if(row<4){
            base_time=(1)*4-3+7;
        }else{
            base_time=(row-4+1)*4-3+7;
        }
    }else if(row%4==3){
        base_time=row*4-3;
    }else if(row%4==0){
        base_time=(row-4+1)*4-3+7;
    }
    long long real_time=0;
    //printf("base time = %lld\n",base_time);
    if(col=='f'){
        real_time=base_time+0;
    }else if(col=='e'){
        real_time=base_time+1;
    }else if(col=='d'){
        real_time=base_time+2;
    }else if(col=='a'){
        real_time=base_time+3;
    }else if(col=='b'){
        real_time=base_time+4;
    }else if(col=='c'){
        real_time=base_time+5;
    }
    printf("%lld\n",real_time);
    return 0;
}


#include<stdio.h>

int main()
{
    int w;
    scanf("%d",w);
    if((w>0)&&(w<100)&&(!(w%2)))
        printf("YES");
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>

#define SORT while(t--){for(i=0;i<x-1;i++)if(arr[i]>arr[i+1]){o=arr[i];arr[i]=arr[i+1];arr[i+1]=o;}}
#define R return 0;
#define and &&
#define or ||
#define buyuk(a,b) (a<b)? b:a
#define kucuk(a,b) (a<b)? a:b
main(){
	int arr[105],x,i,t,o,h[105]={0};
	scanf("%d",&x);
	for(i=0;i<x;i++){
		scanf("%d",&arr[i]);
		h[arr[i]]++;
	}
	for(i=0;i<105;i++){
		if(h[i] and h[i+1] and h[i+2]){
			printf("YES");
			return 0;
		}
	}
		printf("NO");
}


#include <stdio.h>
#include <stdlib.h>

struct nodoLista{
    int dato;
    struct nodoLista * ptrSiguiente;
};

typedef struct nodoLista NodoLista;
typedef NodoLista *ptrNodoLista;

void insertar(ptrNodoLista *ptrS, int valor);
int main(){
    int n;
    scanf("%d", &n);
    int array[n];
    int i;
    for( i = 0; i < n; i++ )
    scanf("%d", &array[i]);

    ptrNodoLista ptrInicial = NULL;

    for( i = 0; i < n; i++)
        insertar(&ptrInicial, array[i]);

    int resp = 0;

    ptrNodoLista ptrAnterior, ptrCentro, ptrPosterior, temp;
    temp = ptrInicial;
    do{
        ptrAnterior = temp;
        ptrCentro = temp->ptrSiguiente;
        ptrPosterior = ptrCentro->ptrSiguiente;
        if( (ptrAnterior->dato + 1) == ptrCentro->dato )
            if( (ptrCentro->dato + 1) == ptrPosterior->dato ){
                resp = 1;
                break;
            }
            temp = ptrCentro;
        }while( ptrPosterior->ptrSiguiente != NULL );

    resp?printf("YES"):printf("NO");

    return 0;

}/* fin de main */

void insertar(ptrNodoLista *ptrS, int valor)
{
    ptrNodoLista ptrNuevo;
    ptrNodoLista ptrAnterior;
    ptrNodoLista ptrActual;

    ptrNuevo = malloc(sizeof(NodoLista));

    if(ptrNuevo != NULL){
        ptrNuevo->dato = valor;
        ptrNuevo->ptrSiguiente = NULL;

        ptrAnterior = NULL;
        ptrActual = *ptrS;

        while( ptrActual != NULL && valor >= ptrActual->dato){
            ptrAnterior = ptrActual;
            ptrActual = ptrActual->ptrSiguiente;
        }/* fin de while */

        if(ptrAnterior == NULL){
            if(*ptrS == NULL || (*ptrS)->dato != valor){
                ptrNuevo->ptrSiguiente = *ptrS;
                *ptrS = ptrNuevo;
            }
        }
        else{
            if( ptrAnterior->dato != ptrNuevo->dato ){
                ptrAnterior->ptrSiguiente = ptrNuevo;
                ptrNuevo->ptrSiguiente = ptrActual;
            }
        }/* en de else */

    }/* fin de if */
    else{
        printf("No se inserto %c. No hay memoria disponible.\n", valor);
    }/* fin de else */

}/* fin de la función insertar */


#include<stdio.h>
#include<stdlib.h>
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}
int main()
{
	int a[50],t;
	int n;scanf("%d",&n);
	int i,j,count=0;
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	qsort(a,n,sizeof(int),cmpfunc);
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<i+3;j++)
		{
			if(a[j]-a[i]<=2 &&a[j]-a[i]!=0)
				count++;
			if(count==2){printf("YES\n");goto y;}
		}
	}
	y:if(count!=2)printf("NO\n");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

/*---------  Estructura del arbol  -------*/
typedef struct nodo{
     int nro;
     struct nodo *izq, *der;
}*ABB;

int numNodos = 0; // nummero de nodos del arbol ABB
int numK = 0, k;     //  nodos menores que un numero k ingresado

ABB crearNodo(int x)
{
     ABB nuevoNodo = new(struct nodo);
     nuevoNodo->nro = x;
     nuevoNodo->izq = NULL;
     nuevoNodo->der = NULL;

     return nuevoNodo;
}
void insertar(ABB *arbol, int x)
{
     if(arbol==NULL)
     {
           arbol = crearNodo(x);
     }
     else if(x < arbol->nro)
          insertar(arbol->izq, x);
     else if(x > arbol->nro)
          insertar(arbol->der, x);
}

void preOrden(ABB arbol)
{
     if(arbol!=NULL)
     {
          printf("%d ", arbol->nro);
          preOrden(arbol->izq);
          preOrden(arbol->der);
     }
}

void enOrden(ABB arbol)
{
     if(arbol!=NULL)
     {
          enOrden(arbol->izq);
		  printf("%d ", arbol->nro);
          enOrden(arbol->der);
     }
}

void postOrden(ABB arbol)
{
     if(arbol!=NULL)
     {
          enOrden(arbol->izq);
          enOrden(arbol->der);
		  printf("%d ", arbol->nro);
     }
}

ABB arbolEspejo(ABB arbol)
{
    ABB temp;

    if(arbol!=NULL)
    {
          temp = arbol->izq;
          arbol->izq = arbolEspejo(arbol->der);
          arbol->der = arbolEspejo(temp);
    }
    return arbol;
}

int main()
{
    ABB arbol = NULL;
    int el;
    int cant,i;
	scanf("%d",&cant);
	for(i=0; i<cant; ++i)
    {
        scanf("%d",&el);
        insertar( arbol, el);
    }
    printf("\n");
    preOrden(arbol);

    ABB espejo = NULL;
    printf("\n");
    espejo = arbolEspejo(arbol);
    enOrden(espejo);
    printf("\n");
    preOrden(espejo);
    printf("\n");
    postOrden(espejo);
    printf("\n");

}


#include<stdio.h>
#include<stdlib.h>

struct llst_int
{
	int a;
	struct llst_int *next;
};
typedef struct llst_int __llst_int;

__llst_int* receive_sort(__llst_int *head, int *p);
int check(__llst_int *head);

int main()
{
	__llst_int *head;
	__llst_int *temp;
	int n;
	char flag;

	scanf("%d",&n);
	head = (__llst_int *)malloc(sizeof(__llst_int));
	head = receive_sort(head, &n);
	flag=check(head);
	if(flag)
		puts("YES");
	else
		puts("NO");

	return 0;
}

__llst_int* receive_sort(__llst_int *head, int *p)
{
	__llst_int *k;
	__llst_int *temp;
	__llst_int *t;
	int i;
	int j;

	scanf("%d",&head->a);
	head->next = NULL;

	i=1;
	while(i<*p)
	{
		temp = (__llst_int *)malloc(sizeof(__llst_int));
		temp->next=NULL;
		scanf("%d",&temp->a);
		t=head;
		j=0;
		if(temp->a > t->a)
			j++;
		while(j<i && t->next && temp->a > t->next->a)
		{
			t = t->next;
			j++;
		}
		if(j==i)
		{
			if(i>1)
				t->next=temp;
			else
				head->next=temp;
			i++;
		}
		else
		{
			if(j)
			{
				if(temp->a == t->next->a)
				{
					free(temp);
					(*p)--;
				}
				else
				{
					k=t->next;
					t->next=temp;
					temp->next=k;
					i++;
				}
			}
			else
			{
				if(temp->a == t->a)
				{
					free(temp);
					(*p)--;
				}
				else
				{
					k=head;
					head=temp;
					head->next=k;
					i++;
				}
			}
		}
	}
	return head;
}

int check(__llst_int *head)
{
	__llst_int *temp;

	temp=head;
	while(temp->next->next)
	{
		if(temp->a+1==temp->next->a && temp->a+2==temp->next->next->a)
			return 1;
		temp=temp->next;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
int arr[52];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
sort(arr,arr+n);

//
int count =0;
int flag =0;
for(int i =1;i<n;i++)
{

if(arr[i]==arr[i-1])
{

    cout<<"NO";
    flag =1;
    break;
}
if(arr[i]!=arr[i-1] && (arr[i] == (arr[i-1]+1)))
count++;
else
count=0;
if(count ==2)
{
cout<<"YES";
flag =1;
break;
}
}
if(flag==0)
cout<<"NO";
return 0;

}


#include<stdio.h>

int main () {

	int n;								// cantidad de bolas a ingresar
	int i;								// indice para recorrer
	int j;								// indice para recorrer
	int cont=0;							// cuenta la cantidad de numeros distintos ingresados
	int ban;							// bandera

	do{								// validacion
		scanf ( "%d", &n );					// se ingresan la cantidad de bolas
	} while ( !(3 ≤ n && n ≤ 50) );

	int v[n];							// vector de bolas y sus respectivos pesos, pueden haber bolas repetidas

	for (i=0; i<n; i++) {						// recorre para contar la cantidad de numeros sin repeticion

		do{							// validacion
			scanf ( "%d", &v[i] );				// se ingresan las respectivas bolas
		} while ( !(1 ≤ v[i] && v[i] ≤ 1000) );

		cont++;
		for ( j=0; j<i; j++ ) {
			if ( v[i]==v[j] ) {
				cont--;
				j=i;
			}
		}
	}

	int b[cont];							// bolas y sus respectivos pesos, sin haber bolas repetidas
	for ( i=0; i<cont; i++ ) {					// se inicializa a cero dicho vector
		b[i]=0;
	}

	for ( i=0; i<n; i++ ) {						// recorre el vector v para cargar los no repetidos en b
		ban=1;
		for ( j=0; (j<cont && ban!=0 && b[j]!=0); j++ ) {	// recorre el vector b para cargar en el los no repetidos de v
			if ( v[i]==b[j] ) {
				ban=0;
			}
		}
		if ( ban ) {
			b[j]=v[i];
		}
	}

	for ( i=1; i<cont; i++ ) {					// recorre b para ordenarlo por burbuja
		for ( j=0; j<cont-i; j++ ) {
			if ( b[j]>b[j+1] ) {				// si se cumple dicha condicion se intercambian las bolas
				b[j]=b[j]+b[j+1];
				b[j+1]=b[j]-b[j+1];
				b[j]=b[j]-b[j+1];
			}
		}
	}

	for ( i=0; i<cont-2; i++ ) {					// compara los numeros con sus dos siguientes para determinar si cumple
		if ( b[i+1]-b[i] <= 2 && b[i+2]-b[i] <= 2 && b[i+2]-b[i+1] <= 2 ) {
			ban=1;
			i=cont-2;
		}
	}

	if ( ban ) {							// si hay uno que cumple ban=1 y se imprime SI caso contrario NO
		printf( "SÍ" );
	}else{
		printf( "NO" );
	}

	return 0;

}


#include<stdio.h>
void main()
{
    int a,b;
    scanf("%d,&a");
    b=a/2;
    if(b%2==0)
    {
        printf("YES");
    }
    else{
        printf("NO");
    }

}


#include<stdio.h>
#include<math.h>
int ara[10000];
int factors(int n)
{
    int i,j,k,m=0;
    for(i=1;i<n;i++){
        if(n%i==0){
            ara[m++]=i;
        }
    }
    return m;
}

int main()
{
    int i,j,k,min=99999999,row,col,result,n;
    scanf("%d",&result);
    k=factors(result);
    for(i=0;i<k;i++){
        for(j=0;j<k;j++){
            if(ara[i]*ara[j]==result){
                if(abs(ara[i]-ara[j])<min){
                    row=ara[i];
                    col=ara[j];
                    min=abs(ara[i]-ara[j]);
                }
            }
        }
    }
    printf("%d %d\n",row,col);
    return 0;
}


#include<stdio.h>
int chekk(int a,int b, int c)
{
	if(((a+b)>c)&&((b+c)>a)&&((c+a)>b))
		return -1;
	else
	{
	if((a>=b)&&(a<=c))
		return a;
	if((b>=c)&&(b<=a))
		return b;
	if((c>=a)&&(c<=b))
		return c;
	}
	return 0;
}
int fu(int a, int b, int c)
{
	int add=0,d;
	int fl=chekk(a,b,c);
	if(fl==-1)
		return add;
	while(fl!=-1)
	{
		if(fl==a)
		{
			if(c>b)
				{
					d=c-b+1;
					add=d-a;
					return add;
				}
			else
			{
				d=b-c+1;
				add=d-a;
				return add;
			}
		}
		if(fl==b)
		{
			if(a>c)
				{
					d=a-c+1;
					add=d-b;
					return add;
				}
			else
			{
				d=c-a+1;
				add=d-b;
				return add;
			}
		}
		if(fl==c)
		{
			if(a>b)
				{
					d=a-b+1;
					add=d-c;
					return add;
				}
			else
			{
				d=b-a+1;
				add=d-c;
				return add;
			}
		}
	}
	return 123;
}
int main()
{
	int a,b,c,to;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	to=fu(a,b,c);
	printf("%d\n",to);
	return 0;
}


#include<cstdio>

int main(void){
    long long a,b,c;
    scanf("%lld%lld%lld",&a,&b,&c);
    long long d = a;

    if(b/2 < d)
        d = b/2;
    if(c/4 < d)
        d = c/4;

    printf("%I64d\n",7*d);

    return 0;
}


#include<stdio.h>
int main ()
{
    int a,b,c,i,count=0,count1=0,count2=0;
    scanf("%d %d %d",&a,&b,&c);
    if(c<b || b<a)
        printf("0");
    else{
   while(a--)
   {
       if(b/a>=2 && c/a>=4)
        break;
       else
        continue;

   }

    printf("%d",(a+a*2+a*4));

    }
}


#include<stdio.h>
#include <math.h>
int func(int a, int b)
{
if(b>=2*a)
{
b=2*a;

}
else{

if(b%2==0)
{
a=b/2;
}

else{a=b/2;
b-=1;}
}

}

}

int main()
{

 int a, b, c;

scanf("%d %d %d", &a, &b, &c);

func(a, b);
func(b, c);
func(a, b);
func(b, c);
printf ("%d", a+b+c);

}


#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
    int lem;
    int app;
    int peace;

    cin >> lem;
    cin >> app;
    cin >> peace;

    int k_p;
    int k_a;
    int k_l;
    int k;
    int sum;

    k_p = peace/4;
    k_a = app/2;
    k_l = lem/1;

    if(k_p>0 && k_a>0 && k_l>0)
    {
        if(k_p >= k_a)
        {
            if(k_a >= k_l)
            {
                k = k_l;

            }
            else
                {
                    k = k_a;
                }
        }
        else if(k_p < k_a)
        {
            if(k_p >= k_l)
            {
                k = k_l;
            }
            else
            {
                k = k_p;
            }
        }
        else if(k_a < k_l)
        {
            if(k_a >= k_p)
            {
                k = k_p;

            }
            else
                {
                    k = k_a;
                }
        }
        else if(k_l >= k_a)
        {
            if(k_a > k_l)
            {
                k = k_l;

            }
            else
                {
                    k = k_a;
                }
        }
        else if(k_p >= k_l)
        {
            if(k_a > k_l)
            {
                k = k_l;

            }
            else
                {
                    k = k_a;
                }
        }
        else if(k_l < k_p)
        {
            if(k_a >= k_l)
            {
                k = k_l;

            }
            else
                {
                    k = k_a;
                }
        }

        sum = k * 7;
    }
    else
    {
        sum = 0;
    }

    cout << sum;

    system("pause");
    return 0;
}


#include <stdio.h>
int main()
{
    int l, a, p, i, total;
    scanf("%d", &l);
    scanf("%d", &a);
    scanf("%d", &p);.

    if(p<4 || a<2) total = 0;
    else {
        for(i=l; i>=1; i--) {
            if(i*2<=a && i*4<=p) {
                total = i + (i*2) + (i*4);
                break;
            }
        }
    }

    printf("%d", total);
    return 0;

}


#include<stdio.h>
int main()
{
    int a,b,c;
    while(~scanf("%d%d%d",&a,&b,&c) )
    {
        int i;
        for( i=a;i＞0; i－-)
        {
            if(2*i＜=b&&4*i＜=c)
            printf("%d\n",7*i);
            break;
        }
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
int main ()
{

    int l,a,p,mk,min,tmp;
    int lm,ap,per;
    while(scanf("%d %d %d",&l,&a,&p))
    {

        lm=l;
        ap=a/2;
        per=p/4;
        if(lm<ap)
        {
            min=lm;

        }
        else
            min=ap;
        if(min>per)
            mk=per;
        else
            mk=min;

        printf("%d\n",7*mk);
    }
    return 0;
}


#include<stdio.h>
int main()
{
      int a,b,c,i;
      scanf("%d %d %d",&a,&b,&c);
      for(i=a;i>=0;i--)
      {
            if(i*2<=b&&i*4<=c)
            System.out.println(i+i*2+i*4);
      }
}


#include<stdio.h>
int main()
{
    long long int res=0,mres=0;
    int m,b,x,y,i,j;
    scanf("%d%d",&m,&b);
    for(y=0;y<=b;y++){
        x=m*(b-y);
        for(i=0;i<=y;i++){
            for(j=0;j<=x;j++)
                res+=i+j;
        }
        if(res>mres){
            mres=res;
            res=0;
        }
        else
            res=0;
    }
    printf("%I64d",mres);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(){
	unsigned long long ans=0,temp=0;
	int i,j,m,b;
	scanf("%d%d",&m,&b);

	for(i=0;i<=b*m;i=i+m){
		j= (m*b - i)/m;
		temp = ((i*(i+1))/2)*(j+1) +  ((j*(j+1))/2)*(i+1);
		if(temp>ans)
			ans=temp;
	}
	printf("%llu\n",ans);
}


#include <stdio.h>

typedef long long int INT64;

int main(void) {
    INT64 m = 0, b = 0, x = 0, y = 0, max = 0, tree = 0;

	scanf("%lld %lld", &m, &b);

    x = b * m;

    while (x >= 0) {
        y = b - x / m;
        if (x % m != 0) {
            y--;
        }

        tree = ((y + 1) * x * (x + 1)) / 2 + ((x + 1) * y * (y + 1)) / 2;
        printf("%lld %lld %lld\n", x, y, tree);

        if (tree > max) {
            max = tree;
        }

        x--;
    }

	printf("%lld\n", max);

	return 0;
}


#include<stdio.h>

long long f(long long x)
{
    return x*(x+1)/2;
}

int main()
{
    long long ans,sum;
    int m,b,x,y,yy;

    scanf("%d%d",&m,&b);
    ans = sum = f(b);
    yy = b;
    for(x=1;x<=m*b;x++)
    {
        y = (b*m-x)/m;
        if(yy>y)sum -=f(x-1)+yy*x;
        sum += f(y) + (long long)x*(y+1);
        yy = y;
        if(sum>ans)ans = sum;
    }
    printf("%I64d\n",ans);

    return 0;
}


#include<stdio.h>

int main()
{
    int n,m,rmdr,x,sum=0;

    scanf("%d%d",&n,&m);
    x=n;
    while(x>0)
    {
        rmdr=x%m;
        x=x/m;
        sum=sum+x;
        x=x+rmdr;
        if(x<m)
            break;

    }
    if(n<m)
        printf("%d\n",n);
    else
    printf("%d\n",sum+n);

    return 0;

}


#include<stdio.h>
int main()
{
    int n,i,initial,day,copy_initial,amount,remainder;
    int socks=0,total_socks,day_without_socks;
    scanf("%d %d",&initial,&day);
    copy_initial=initial;
    while(initial>0)             //if i didn't give the second condition loop would never stop cause always 1 remainder will be left.
    {
        amount=initial/day;
        remainder=initial%day;
        initial=remainder+amount;
        socks=socks+amount;
        if(initial<day)
        {
            break;
        }

    }
    total_socks=copy_initial+socks;
    printf("%d\n",total_socks);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
    int a,b,res=0;
    scanf("%i%i", &a, &b);
    while(a&&b){
        a--;
        b--;
        res++;
    }
    printf("%i ", res);
    res=0;
    while(a>1){
        a-=2;
        res++;
    }
    while(b>1){
        a-=2;
        res++;
    }
    printf("%i", res);
    return 0;
};


#include<stdio.h>
#include<string.h>
int main()
{
	int n, c, p;
	int b[26] = {0,0 };
	char a[101];
	scanf("%d%d", &n, &c);
	getchar();
	gets(a);
	for (int i = 0; i < strlen(a); i++)
	{
		p = a[i] - 97;

		b[p]++;
	}

	for (int i = 0; i < 26; i++)
	{
		if (b[i] >=k+1)
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main(n,k)
{scanf("%d%d",&n,&k);
char s[n+1];
int i,j,c;
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
{
c=0;
for(j=0;s[j]!='\0';j++)
{
if(s[i]==s[j])
c++;
if(c>k)
{
printf("NO");
exit(1);
}
}
}
printf("YES");
}


#include <stdio.h>
#include <string.h>

int main(void){
	int i, n ,contX = 0, total = 0;
	int cont = 0;
	int primera;
	const char eq = 'x';
	char *ptr;

	scanf ( "%d", &n );
	const char cadena [n];
	scanf ( "%s", cadena );

	ptr = strchr ( cadena, eq );

	if ( ptr[0] == 'x' && ptr[1] == 'x' && ptr[2] == 'x' ){
		for ( i = 0; i < n; i++ ){
			if ( 'x' == cadena[i] ){
				contX++;
				if ( contX == 3 ){
					contX--;
					total++;
				}
			} else {
				contX = 0;
			}
		}
	}

	printf ( "%d", total );
	return 0;
}


#include <stdio.h>
int main()
{
    int n;
    scanf ("%d\n", &n);
    char a[n];
    int b[24];
    for (int i = 0; i < n; i++)
    {
        scanf("%c", &a[i]);
    }
    int counter = 0, j = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == 'x')
        {
            counter++;
        }
        else if(a[i] != 'x'&& a[i-1] == 'x' && i != 0)
        {
            b[j] = counter;
            j++;
            counter = 0;
        }
        if (i == n-1)
        {
            if (a[i] == 'x')
            {
                b[j] = counter;
                j++;
                counter = 0;
            }
        }
    }
    for (int i = 0; i < j; i++)
    {
        counter = b[i] - 2;
    }
    printf ("%d", counter);

}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node{
        int v;
        struct node *next;
} NODE;

void dfs(int n, NODE *e[], char v[]){
     NODE *tmp = e[n];
     v[n] = 1;
     while (tmp){
           if (!v[tmp->v])
              dfs(tmp->v, e, v);
           tmp = tmp->next;
     }
     return;
}

int main(){
    int n, m, i, j, x, y;
    char f[100000], f1 = 0, f2 = 0, v1[100000] = {}, v2[100000] = {};
    NODE *e[100000] = {}, *b[100000] = {}, *tmp;
    scanf("%d%d", &n, &m);
    for (i = 0 ; i < n ; ++i){
        scanf("%d", f + i);
        if (f[i] == 1)f1 = 1;
        else if (f[i] == 2)f2 = 1;
    }
    if (!f1 || !f2){
       while (n--)puts("0");
       return 0;
    }

    for (i = 0 ; i < m ; ++i){
        scanf("%d%d", &x, &y);
        --x, --y;
        tmp = calloc(1, sizeof(NODE));
        tmp->v = y, tmp->next = e[x], e[x] = tmp;
        tmp = calloc(1, sizeof(NODE));
        tmp->v = x, tmp->next = b[y], b[y] = tmp;
    }
    for (i = 0 ; i < n ; ++i)
        if (f[i] == 1)
           dfs(i, e, v1);
    for (i = 0 ; i < n ; ++i)
        if (f[i] == 2)
           dfs(i, b, v2);
    for (i = 0 ; i < n ; ++i)
        printf("%d\n", v1[i] && v2[i]);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node{
        int v;
        struct node *pre, *next;
} NODE;

int e[100000][2], v[100001] = {};
char s[100001] = {}, f[100001];
NODE pre[100000] = {}, *prep[100001];

int cmp(const void *a, const void *b){
    int *x = (int*)a, *y = (int*)b;
    if (x[0] < y[0])return -1;
    if (x[0] > y[0])return 1;
    if (x[1] < y[1])return -1;
    if (x[1] > y[1])return 1;
    return 0;
}

void fill(int now, NODE *prep[]){
     do {
        if (!prep[now]->v)return;
        if (s[prep[now]->v])continue;
        s[prep[now]->v] = 1;
        fill(prep[now]->v, prep);
     }while (prep[now]->pre && (prep[now] = prep[now]->pre));
     return;
}

int main(){
    int n, m, i, j;
    char f1 = 0, f2 = 0;

    scanf("%d%d", &n, &m);
    for (i = 1 ; i <= n ; ++i){
        scanf("%d", f + i);
        if (f[i] == 1)f1 = 1;
        else if (f[i] == 2)f2 = 1;
    }
    if (!f1 || !f2){
       while (n--)puts("0");
       return 0;
    }

    for (i = 0 ; i < m ; ++i)
        scanf("%d%d", &e[i][0], &e[i][1]);
    qsort(e, m, sizeof(int) * 2, cmp);
    for (i = 0, j = 1 ; i < m ; ++i)
        while (e[i][0] > j)v[j++] = i;
    while (j <= n)v[j++] = m;

    for (i = 1 ; i <= n ; ++i){
        if (f[i] != 1)continue;
        int l, r, q[100000];
        char c[100001] = {};
        memset(pre, 0, sizeof(pre));
        q[0] = i, c[i] = 1;
        prep[i] = &pre[0];
        for (l = 0, r = 1 ; l < r ; ++l){
            for (j = v[q[l] - 1] ; j < v[q[l]] ; ++j){
                if (f[e[j][1]] == 1)continue;
                if (c[e[j][1]]){
                   NODE *tmp = prep[e[j][1]];
                   do {
                      if (tmp->v == q[l])break;
                   }while (tmp->pre && (tmp = tmp->pre));
                   if (tmp->v == q[l])continue;
                   prep[e[j][1]]->next = calloc(1, sizeof(NODE));
                   prep[e[j][1]]->next->pre = prep[e[j][1]];
                   prep[e[j][1]] = prep[e[j][1]]->next;
                   prep[e[j][1]]->v = q[l];
                }
                else {
                     c[e[j][1]] = 1;
                     pre[r].v = q[l];
                     prep[e[j][1]] = &pre[r];
                     q[r++] = e[j][1];
                }
                if (s[e[j][1]] || f[e[j][1]] == 2){
                   s[e[j][1]] = 1;
                   fill(e[j][1], prep);
                }
            }
        }
    }
    for (i = 1 ; i <= n ; ++i)
        printf("%d\n", s[i]);
    return 0;
}


#include <stdio.h>
#include <string.h>

int main(void)
{
    int n;
    scanf("%d", &n);
    char str[n];
    scanf("%s", str);
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (i+2 <= n - 1)
        {
            if (str[i] == 'x' && str[i+1] == 'x' && str[i+1] == 'x')
            {
                count++;

            }

        }

    }

    printf("%d", count);
    return 1;
}


/* By the name of ALLAH */

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

int main()
{
   int t,n,k,m,j,i,l,max,sum1=0,sum2=0,cnt1=0,cnt2=0;
   scanf("%d",&n);
   char s1[105];
   scanf("%s",s1);
   i=0;
   while(s1[i] != '\0')
   {
      j=i;
      while(s1[j] == 'x')
      {
         cnt1++;
         k = j;
         j++;
      }

      if(cnt1 > 2)
      {
         sum1 += (cnt1 - 2);
      }
      cnt1 = 0;
      i += k;
   }

   printf("%d\n",sum1);
   return 0;
}


#include <stdio.h>

int main(){
	int i,n,cont,error,POS;
	n=cont=error=0;
	scanf("%d",&n);
	char letras[n];
	scanf("%s",letras);
	for(POS=0;POS<n;POS++){
		if(letras[POS]==letras[POS+1] && (letras[POS]=='X' || letras[POS]=='x')){
			cont++;
		}else{
			cont=0;
		}
		if(cont>=2){
			error++;
		}
	}
	printf("%d",error);
	return 1;
}


#include<stdio.h>
#define u_int unsigned int

u_int uintpow(u_int a,u_int b);
u_int wint(u_int a,u_int b);

int main(void){
  u_int n;
  scanf("%u",&n);
  printf("%u\n",uintpow(3,n-1));
  return 0;
}

u_int uintpow(u_int a,u_int b){
    const u_int mod=1000003;
    u_int i;
    u_int prod=1;
    for(i=0;(b>>i)!=0;i++){
      if((b>>i)&1==1){
	prod*=wint(a,i);
	prod%=mod;
      }
    }
    prod%=mod;
    return prod;
}

u_int wint(u_int a,u_int b){
  const u_int mod=1000003;
  for(;b>0;b--){
    a*=a;
    a%=mod;
  }
  return a;
}


#include <stdio.h>

int n , i , j , k ;
int main()
{

    scanf("%d", &n) ;

    if ( n == 0 ) printf("1" ) ;
    else
    {
        k = 1 ;
        while( n > 1 )
        {
            k =( k * 3 ) % 1000003 ;
            n-- ;
        }
    }
    printf("%d", k ) ;
 return 0 ;
 }


#include <stdio.h>

int main(int argc, char *argv[])
{
    int n, p = 1;

    scanf("%d", &n);
    while(-- n)
        p = (p * 3) % 1000003;

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

    return 0;
}


#include <stdio.h>

#define MOD     1000003

int main()
{
        int N,Sum=1;
        scanf("%d",&N);
        for(i=1;i<N;++i)
        {
                Sum*=3;
                Sum%=MOD;
        }
        printf("%d\n",Sum);
        return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
int main()
{
   long int n;
    scanf("%ld",&n);
    if (n==1)
    {
        printf("4\n");
        return 0;
    }
    n= (4*n) -3;
    n=n/3;
    n=n+3;
    printf("%ld\n",n);

    return 0;
}


#include<stdio.h>
long long int n;
int good(long long int m){
	long long int sum=0;
	for(int i=1;i*(i+2)<=m;i++){
		sum+=1+(m-(i+2)*i)/(i*2);
	}
	if(sum>=n){
		return 1;
	}
	else{
		return 0;
	}
}
int main(){
	long long int low, high, mid;
	scanf("%lld",&n);
	low=2; 						//good(low)=0
	high=100000000;				//good(high)=1
	while(high>low+1){
		mid=(high+low)/2;
		if(good(mid)){
			high=mid;
		}
		else{
			low=mid;
		}
	}
	printf("%lld\n",high);
	return 0;
}


#include <stdio.h>

int main() {
    long long int n;
    scanf("%lld", &n);
    printf("%lld", n + n + 1);
    return 0;
}


#include <stdio.h>
int main()
{
	long long int n, ans;
	scanf("%lld",&n);
	ans = n - 1;
	ans =  4 + 4 * ans / 3 + (ans % 3 == 2);
	printf("%lld\n",ans);
}


#include <stdio.h>
#include <assert.h>

int n;

double p(double a, double e) {
    return a / e;
}
double q(double a, double b, double c, double d, double e, double f) {
    return (a / d) * (b / e) * (c / f);
}

double solve(int k) {
    const double q3 = q(k, k-1, k-2, n, n-1, n-2);
    const double q0 = q(n-k, n-k-1, n-k-2, n, n-1, n-2);
    const double q1 = 2 * q(k, n-k, n-k-1, n, n-1, n-2);
    const double q2 = q(k, k-1, n-k, n, n-1, n-2);
    const double res = q3 + q1 + q2;
    //printf("solve(%d) = %lf\n", k, res);
    //assert(q3 + q0 + 3 / 2. * q1 + 3 * q2 == 1.);
    assert(res >= 0.);
    assert(res <= 1.);
    return res;
}

int main(void) {
    double p;
    scanf("%d%lf", &n, &p);
    int l = 0, r = n - 1;
    if (p == 0) {
        puts("0");
        return 0;
    }
    while (l + 1 < r) {
        const int m = (l + r) >> 1;
        if (solve(m) >= p) {
            r = m;
        } else {
            l = m;
        }
    }
    assert(r > 0);
    assert(r < n);
    printf("%d\n", r);
}


#include <stdio.h>
#include <assert.h>

int n;

double p(double a, double e) {
    return a / e;
}
double q(double a, double b, double c, double d, double e, double f) {
    return (a / d) * (b / e) * (c / f);
}

double solve(int k) {
    const double q3 = q(k, k-1, k-2, n, n-1, n-2);
    const double q0 = q(n-k, n-k-1, n-k-2, n, n-1, n-2);
    const double q1 = 2 * q(k, n-k, n-k-1, n, n-1, n-2);
    const double q2 = q(k, k-1, n-k, n, n-1, n-2);
    assert(q3 + q0 + 3 / 2. * q1 + 3 * q2 == 1.);
    const double res = q3 + q1 + q2;
    //printf("solve(%d) = %lf\n", k, res);
    assert(res >= 0.);
    assert(res <= 1.);
    return res;
}

int main(void) {
    double p;
    scanf("%d%lf", &n, &p);
    int l = 0, r = n - 1;
    if (p == 0) {
        puts("0");
        return 0;
    }
    while (l + 1 < r) {
        const int m = (l + r) >> 1;
        if (solve(m) >= p) {
            r = m;
        } else {
            l = m;
        }
    }
    assert(r > 0);
    assert(r < n);
    printf("%d\n", r);
}