Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensional circle. No, wait, it's even worse — as a square of side n. Thus, the task has been reduced to finding the shortest path between two dots on a square (the path should go through the square sides). To simplify the task let us consider the vertices of the square to lie at points whose coordinates are: (0, 0), (n, 0), (0, n) and (n, n).

The single line contains 5 space-separated integers: n, x1, y1, x2, y2 (1 ≤ n ≤ 1000, 0 ≤ x1, y1, x2, y2 ≤ n) which correspondingly represent a side of the square, the coordinates of the first point and the coordinates of the second point. It is guaranteed that the points lie on the sides of the square.

You must print on a single line the shortest distance between the points.

#include<stdio.h>
#include <stdlib.h>
int min(int num1, int num2);

int main()
{

    int n = 0;
    int x1 = 0;
    int y1 = 0;
    int x2 = 0;
    int y2 = 0;

    scanf("%d %d %d %d %d", &n, &x1, &y1 ,&x2 , &y2);
    if(abs(x2-x1)!=n && abs(y2-y1)!=n){
    int distance = abs(x2-x1)+abs(y2-y1);
    printf("%d",distance);}
    else if( abs(x2-x1)==n) {
      int distance =min(y1+y2,n-y1+n-y2)+n;
      printf("%d",distance);
    }
    else if( abs(y2-y1)==n) {
        int distance = min(x1+x2,n-x1+n-x2)+n;
      printf("%d",distance);
    }

    return 0;
}

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

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

int cal(int x, int y, int n);

int main(void)
{
    int n, x1, y1, x2, y2;

    scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

    int d;
    d = abs(cal(x1, y1, n) - cal(x2, y2, n));

    printf("%d", d > 4 * n - d ? 4 * n - d : d);

    return 0;
}

int cal(int x, int y, int n)
{
    if(x == 0)
        return y;
    else if(y == n)
        return n + x;
    else if(x == n)
        return n + n + n - y;
    else
        return n + n + n + n - x;
}

#include<stdio.h>
#include<string.h>
#include<math.h>
int abs1(int x){if(x>0)return x;else return -x;}
int main()
{
int n,x1,i,j,y1,x2,y2,sum=0;

    scanf("%d %d %d %d %d",&n,&x1,&y1,&x2,&y2);
    if((x1>y1)==(x2>y2)){i=abs1(x1-x2);j=abs1(y1-y2);sum=i+j;}
    else{
    sum=x1+x2+y1+y2;
    if(sum>4*n-sum)sum=4*n-sum;
    }
        printf("%d",sum);
return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main(void){
  int x1,x2,y1,y2,dist,half,n;
  int zerodis1,zerodis2;
  scanf("%d %d %d %d %d",&n,&x1,&y1,&x2,&y2);
  half=n*2;
  zerodis1=(x1>=y1)?(x1+y1):((half*2)-x1-y1);
  zerodis2=(x2>=y2)?(x2+y2):((half*2)-x2-y2);
  dist=abs(zerodis1-zerodis2);
  if(dist>half) dist=half*2-dist;
  printf("%d\n",dist);
  return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main(void){
  int n,x1,x2,y1,y2,dist,half;
  int zerodis1,zerodis2;
  scanf("%d %d %d %d %d",&n,&x1,&y1,&x2,&y2);
  half=n*2;
  zerodis1=(x1>=y1)?(x1+y1):((half*2)-x1-y1);
  zerodis2=(x2>=y2)?(x2+y2):((half*2)-x2-y2);
  dist=abs(zerodis1-zerodis2);
  if(dist>half) dist=half*2-dist;
  printf("%d\n",dist);
  return 0;
}

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

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

int minimum(int a, int b)
{
     if (a < b) {
	  return a;
     } else {
	  return b;
     }
}

int main()
{
     int n, x1, y1, x2, y2, a, b, c;

     scanf("%d %d %d %d %d", &n, &x1, &y1, &x2, &y2);

     if (y1 == 0) {
	  a = x1;
     } else if (x1 == n) {
	  a = n + y1;
     } else if (y1 == n) {
	  a = 3 * n - x1;
     } else {
	  a = 4 * n - y1;
     }

     if (y2 == 0) {
	  b = x2;
     } else if (x2 == n) {
	  b = n + y2;
     } else if (y2 == n) {
	  b = 3 * n - x2;
     } else {
	  b = 4 * n - y2;
     }

     c = minimum(a, b) + 4 * n;

     printf("%d\n", minimum(abs(a - b), c - maximum(a, b)));

     return 0;
}

#include <stdio.h>

int distance(int x, int y, int n)
{
    int d;
    if (x==0) d = y;
    else if(x!=n)
    {
        if (y==0) d = 4*n-x;
        else d = n + x;
    }
    else d = 3*n-y;

    return d;
}

int main()
{
    int n,x1,y1,x2,y2;
    int d1, d2,d;
    scanf("%d %d %d %d %d",&n,&x1,&y1,&x2,&y2);
    d1 = distance(x1,y1,n);
    d2 = distance(x2,y2,n);
    if(d1>d2) d = d1-d2;
    else d = d2-d1;
    if(d>2*n)
        d = 4*n-d;
    printf("%d", d);

    return 0;
}

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

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

int main(){
	int n , x1 , y1 , x2 , y2 ;

	scanf("%d%d%d%d%d", &n , &x1 , &y1 ,&x2 , &y2 );

	if ( abs(x1 - x2) == n || abs(y1-y2) == n)
		printf("%d\n" , min ( x1 + y1 + x2 + y2 , 4*n - (x1 + y1 + x2 + y2 ) ) );
	else
		printf("%d\n" , abs(x1-x2) + abs(y1-y2) );

	return 0;
}

#include<stdio.h>
int min(int a, int b)
{
 	return a<b?a:b;
}
int abs(int x)
{
	return x>0?x:-x;
}

int main()
{
	int n,x1,y1,x2,y2;
	scanf("%d%d%d%d%d",&n,&x1,&y1,&x2,&y2);
	if(x1 == x2 && (x1==n || x1==0))
	{
		printf("%d\n",abs(y1-y2));
		return 0;
	}

	else if(y1 == y2 && (y1==n || y1==0))
	{
		printf("%d\n",abs(x1-x2));
		return 0;
	}

	//if opposite side
	int onver1 = 0, onver2 = 0;
	if(x1==n || x1==0)
	onver1 = 1;

	if(x2==n || x2==0)
	onver2 = 1;

	if(onver1==1 &&  onver2==1)
	{
		//opposite vertical
		int tmp = min(y1+y2,n-y1+n-y2);
		//printf("BDEUG %d\n",tmp);
		printf("%d\n",n+tmp);
		return 0;
	}
	else if(onver1==0 && onver2==0)
	{
		//opposite hori
		int tmp = min(x1+x2,n-x1+n-x2);
		printf("%d\n",n+tmp);
		return 0;
	}

	//adjacent sides
	int tmp = 0;
	if(x1==0)
	{
		if(y2==0)
		tmp = y1+x2;
		else if(y2==n)
		tmp = n-y1+x2;
	}
	else if(x1==n)
	{
		if(y2==n)
		tmp = 2*n - x2 - y1;
		else if(y2 == 0)
		tmp = n-x2+y1;
	}
	else if(x2==0)
	{
		if(y1 == 0)
		tmp = x1+y2;
		else if(y1==n)
		tmp = n-y2+x1;
	}
	else
	{
		if(y1==0)
		tmp = n-x1+y2;
		else if(y1==n)
		tmp = 2*n - x1 -y2;
	}
	printf("%d\n",tmp);
	return 0;
}

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

int xx1,yy1,xx2,yy2,n,ans;
scanf("%d%d%d%d%d", &n, &xx1, &yy1, &xx2, &yy2);
if ((xx1==0&&xx2==n)||(xx1==n&&xx2==0))
ans=min(n+yy1+yy2,n+n-yy2+n-yy1);
else {if
((yy1==0&&yy2==n)||(yy1==n&&yy2==0))
ans=min(n+xx1+xx2,n+n-xx2+n-xx1);
else ans=abs(xx1-xx2)+abs(yy1-yy2);}
printf ("%d", ans);
return 0;
}
int min(int num1, int num2)
{

   int result;

   if (num1 < num2)
      result = num1;
   else
      result = num2;

   return result;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int min(int a,int b);
int main()
{
	int n,x1,y1,x2,y2,d1,d2;
	scanf("%d%d%d%d%d",&n,&x1,&y1,&x2,&y2);
	d1=x1+y1+x2+y2;
	d2=(4*n)-d1;
	if(abs(x1-x2)==n || abs(y1-y2)==n)
	printf("%d",min(d1,d2));
	else
		printf("%d",abs(x1-x2)+abs(y1-y2));
	return 0;
}
int min(int a,int b)
{
	if(a>b) return b;
	else return a;
}

#include<stdio.h>

int min(int, int);
int absolute(int);
int main()
{
int n, x1,y1,x2,y2;
scanf("%d",&n);
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
int sd=0;
if(x1==0 )//case 1
{
    if(x2==0)
    sd=absolute(y2-y1);
    else if(x2<n && y2==0)
    sd=y1+x2;
    else if(x2<n && y2==n)
    sd=n-y1+x2;
    else if(x2==n)
    sd=min(y1+n+y2,n-y1+n+n-y2);

}
else if(y1==0)//case 2
{
    if(y2==0)
    sd=absolute(x2-x1);
    else if(x2==0)
    sd=x1+y2;
    else if(x2==n)
    sd=n-x1+y2;
    else if(x2<n)
    sd=min(x1+n+x2,n-x1+n+n-x2);
}
else if(x1==n)
{
    if(x2==n)
    sd=absolute(y2-y1);
    else if(x2==0)
    sd=min(y1+n+y2,n-y1+n+n-y2);
    else if(y2==0)
    sd=y1+n-x2;
    else if(y2==n)
    sd=n-x2+n-y1;
}
else if(y1==n)
{
    if(y2==n)
    sd=absolute(x2-x1);
    else if(y2==0)
    sd=min(x1+n+x2,n-x1+n+n-x2);
    else if(x2==0)
    sd=x1+n-y2;
    else if(x2==n)
    sd=n-x1+n-y2;
}
printf("%d",sd);

return 0;
}
int min(int a, int b)
{
    if(a<b)
    return(a);
    else
    return(b);
}
int absolute(int m)
{
    if(m<0)
    m=m*(-1);
    return(m);
}

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

int mn(int a, int b)
{
	return (a < b ? a : b);
}

int main(int argc, char *argv[])
{
	int n, x1, y1, x2, y2;

	scanf("%d %d %d %d %d", &n, &x1, &y1, &x2, &y2);

	if(abs(x1 - x2) == n)
		printf("%d\n", n + mn(y1 + y2, 2 * n - (y1 + y2)));
	else if(abs(y1 - y2) == n)
		printf("%d\n", n + mn(x1 + x2, 2 * n - (x1 + x2)));
	else
		printf("%d\n", abs(x1 - x2) + abs(y1 - y2));

	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)

int get_d(int x,int y,int n){
  if(x==0) return y;
  if(y==n) return x+n;
  if(x==n) return (n-y)+n+n;
  return (n-x)+n+n+n;
}

int main(){
  int i,j,k,l,m,n;
  int x1,x2,y1,y2,d1,d2,res;

  while(scanf("%d%d%d%d%d",&n,&x1,&y1,&x2,&y2)==5){
    d1 = get_d(x1,y1,n);
    d2 = get_d(x2,y2,n);
    res = d1-d2;
    if(res<0) res = -res;
    if(res > 4*n-res) res = 4*n-res;
    printf("%d\n",res);
    break;
  }

  return 0;
}

#include <stdio.h>

int main(void)
{
  int n, x, y, xx, yy;
  int vzd_x, vzd_y;
  int c;
  int cc;

  scanf("%d %d %d %d %d", &n, &x, &y, &xx, &yy);

  vzd_x = x + y;
  vzd_y = xx + yy;

  if ((((x == 0) || (y == n)) && ((xx == n) || (yy == 0))) ||
      (((xx == 0) || (yy == n)) && ((x == n) || (y == 0)))){
    c = vzd_x + vzd_y;
  } else {
    c = abs(vzd_x - vzd_y);
  }
  if (c < (2*n)) printf("%d\n", c);
  else printf("%d\n", 4*n - c);

  return 0;
}

#include <stdio.h>

int abs (int x)
{
	return ( x < 0 ? -x : x );
}

int min (int x, int y)
{
	return (x < y ? x : y);
}

int main()
{
	int n, x1, y1, x2, y2;
	int s, sq;

	scanf ("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

	sq = n * n;
	s = x1 + x2 + y1 + y2;

	if ( abs (x1 - x2) == n || abs (y1 - y2) == n ) {
		printf ("%d\n", min (s, 4 * n - s));
	} else {
		printf ("%d\n", abs(x1 - x2) + abs(y1 - y2));
	}

	return 0;
}

#include <stdio.h>

int abs( int d )
{

    return d < 0 ? -d : d;
}

int cut( int x, int y, int n )
{
    if ( x == 0 ) {
        return y;
    }
    if ( y == n ) {
        return n + x;
    }
    if ( x == n ) {
        return 3 * n - y;
    }

    if ( y == 0 ) {
        return 4 * n - x ;
    }

    return -1;
}

int main( void )
{
    int n, x1, y1, x2, y2;
    int d1, d2, diff;

    scanf( "%d %d %d %d %d", &n, &x1, &y1, &x2, &y2 );
    d1 = cut( x1, y1, n );
    d2 = cut( x2, y2, n );
    diff = abs( d1 - d2 );
    diff = 4 * n - diff < diff ? 4 * n - diff : diff;
    printf( "%d\n", diff );
    fflush( stdout );

    return 0;

}

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

int main()
{

    int n = 0;
    int x1 = 0;
    int y1 = 0;
    int x2 = 0;
    int y2 = 0;

    scanf("%d %d %d %d %d", &n, &x1, &y1 ,&x2 , &y2);

    int distance = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
    printf("%d",distance);

    return 0;
}

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

int main()
{

    int n = 0;
    int x1 = 0;
    int y1 = 0;
    int x2 = 0;
    int y2 = 0;

    scanf("%d %d %d %d %d", &n, &x1, &y1 ,&x2 , &y2);

    int distance = abs(x2-x1)+abs(y2-y1);
    printf("%d",distance);

    return 0;
}

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

int main(void)
{
    int n, x1, y1, x2, y2;

    scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

    int a, b, c, d;
    a = n - y1 + n - y2 + abs(x2 - x1);
    b = n - x1 + n - x2 + abs(y2 - y1);
    c = y1 + y2 + abs(x2 - x1);
    d = x1 + x2 + abs(y2 - y1);
    if(x2 - x1 == 0 || y1 == 0 || y2 == 0 || y1 == n || y2 == n)
    {
        a = b < d ? b : d;
    }
    else if(y2 - y1 == 0 || x1 == 0 || x2 == 0 || x1 == n || x2 == n)
    {
        a = a < c ? a : c;
    }
    else
    {
        a = a < b ? a : b;
        a = a < c ? a : c;
        a = a < d ? a : d;
    }

    printf("%d", a);

    return 0;
}

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

int cal(int x, int y, int n);

int main(void)
{
    int n, x1, y1, x2, y2;

    scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

    int d;
    d = abs(cal(x1, y1, n) - cal(x2, y2, n));

    printf("%d", d > 4 * n - d) ? 4 * n - d : d;

    return 0;
}

int cal(int x, int y, int n)
{
    if(x == 0)
        return y;
    else if(y == n)
        return n + x;
    else if(x == n)
        return n + n + n - y;
    else
        return n + n + n + n - x;
}

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

int main(void)
{
    int n, x1, y1, x2, y2;

    scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

    int a, b, c, d;
    a = n - y1 + n - y2 + x2 - x1;
    b = n - x1 + n - x2 + y2 - y1;
    c = y1 + y2 + x2 - x1;
    d = x1 + x2 + y2 - y1;
    a = a < b ? a : b;
    a = a < c ? a : c;
    a = a < d ? a : d;
    printf("%d", a);

    return 0;
}

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

int main(void)
{
    int n, x1, y1, x2, y2;

    scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

    int a, b, c, d;
    a = n - y1 + n - y2 + abs(x2 - x1);
    b = n - x1 + n - x2 + abs(y2 - y1);
    c = y1 + y2 + abs(x2 - x1);
    d = x1 + x2 + abs(y2 - y1);
    printf("%d, %d, %d, %d\n", a, b, c, d);
    if(x2 - x1 == 0 || y1 == 0 || y2 == 0 || y1 == n || y2 == n)
    {
        a = b < d ? b : d;
    }
    else if(y2 - y1 == 0 || x1 == 0 || x2 == 0 || x1 == n || x2 == n)
    {
        a = a < c ? a : c;
    }
    else
    {
        a = a < b ? a : b;
        a = a < c ? a : c;
        a = a < d ? a : d;
    }

    printf("%d", a);

    return 0;
}

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

int main(void)
{
    int n, x1, y1, x2, y2;

    scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

    printf("%d", y1 + y2 + x2 - x1);

    return 0;
}

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

int main(void)
{
    int n, x1, y1, x2, y2;

    scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

    int a, b, c, d;
    a = n - y1 + n - y2 + x2 - x1;
    b = n - x1 + n - x2 + y2 - y1;
    c = y1 + y2 + x2 - x1;
    d = x1 + x2 + y2 - y1;
    if(x2 - x1 == 0)
    {
        a = b < d ? b : d;
    }
    else if(y2 - y1 == 0)
    {
        a = a < c ? a : c;
    }
    else
    {
        a = a < b ? a : b;
        a = a < c ? a : c;
        a = a < d ? a : d;
    }

    printf("%d", a);

    return 0;
}

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

int main(void)
{
    int n, x1, y1, x2, y2;

    scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

    int a, b, c, d;
    a = n - y1 + n - y2 + abs(x2 - x1);
    b = n - x1 + n - x2 + abs(y2 - y1);
    c = y1 + y2 + abs(x2 - x1);
    d = x1 + x2 + abs(y2 - y1);
    if(x2 - x1 == 0)
    {
        a = b < d ? b : d;
    }
    else if(y2 - y1 == 0)
    {
        a = a < c ? a : c;
    }
    else
    {
        a = a < b ? a : b;
        a = a < c ? a : c;
        a = a < d ? a : d;
    }

    printf("%d", a);

    return 0;
}

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

int main(void)
{
    int n, x1, y1, x2, y2;

    scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

    int a, b, c, d;
    a = n - y1 + n - y2 + abs(x2 - x1);
    b = n - x1 + n - x2 + abs(y2 - y1);
    c = y1 + y2 + abs(x2 - x1);
    d = x1 + x2 + abs(y2 - y1);
    printf("%d, %d, %d, %d\n", a, b, c, d);
    if(x2 - x1 == 0)
    {
        a = b < d ? b : d;
    }
    else if(y2 - y1 == 0)
    {
        a = a < c ? a : c;
    }
    else
    {
        a = a < b ? a : b;
        a = a < c ? a : c;
        a = a < d ? a : d;
    }

    printf("%d", a);

    return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main(void){
  int n,x1,x2,y1,y2,dist,half;
  int zerodis1,zerodis2;
  scanf("%d %d %d %d %d",&n,&x1,&y1,&x2,&y2);
  half=n<<1;
  zerodis1=(x1>=y1)?(x1+y1):((half<<1)-x1-y1);
  zerodis2=(x2>=y2)?(x2+y2):((half<<1)-x2-y2);
  dist=abs(zerodis1-zerodis2);
  if(dist>half) dist=half<<1-dist;
  printf("%d\n",dist);
  return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main(void){
  int n,x1,x2,y1,y2,dist,half;
  int zerodis1,zerodis2;
  scanf("%d %d %d %d %d",&n,&x1,&y1,&x2,&y2);
  half=n<<1;
  zerodis1=(x1>=y1)?(x1+y1):(half<<1-x1-y1);
  zerodis2=(x2>=y2)?(x2+y2):(half<<1-x2-y2);
  dist=abs(zerodis1-zerodis2);
  if(dist>half) dist=half<<1-dist;
  printf("%d\n",dist);
  return 0;
}

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

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

int minimum(int a, int b)
{
     if (a < b) {
	  return a;
     } else {
	  return b;
     }
}

int main()
{
     int n, x1, y1, x2, y2, a, b, c;

     scanf("%d %d %d %d %d", &n, &x1, &y1, &x2, &y2);

     if (y1 == 0) {
	  a = x1;
     } else if (x1 == n) {
	  a = n + y1;
     } else if (y1 == n) {
	  a = 3 * n - x1;
     } else {
	  a = 4 * n - y1;
     }

     if (y2 == 0) {
	  b = x2;
     } else if (x2 == n) {
	  b = n + y2;
     } else if (y2 == n) {
	  b = 3 * n - x2;
     } else {
	  b = 4 * n - y2;
     }

     c = minimum(a, b) + 400;

     printf("%d\n", minimum(abs(a - b), c - maximum(a, b)));

     return 0;
}

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

int main()
{
     int n, x1, y1, x2, y2, a, b;

     scanf("%d %d %d %d %d", &n, &x1, &y1, &x2, &y2);

     if (y1 == 0) {
      a = x1;
     } else if (x1 == n) {
      a = n + y1;
     } else if (y1 == n) {
      a = 3 * n - x1;
     } else {
      a = 4 * n - y1;
     }

     if (y2 == 0) {
      b = x2;
     } else if (x2 == n) {
      b = n + y2;
     } else if (y2 == n) {
      b = 3 * n - x2;
     } else {
      b = 4 * n - y2;
     }

     printf("%d\n", abs(a - b));

     return 0;
}

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

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

int main(){
	int n , x1 , y1 , x2 , y2 ;

	scanf("%d%d%d%d%d", &n , &x1 , &y1 ,&x2 , &y2 );

	if ( abs(x1 - x2) == n || abs(y1-y2) == n)
		printf("%d\n" , min ( x1 + y1 + x2 + y2 , 4*n - x1 + y1 + x2 + y2 ) );
	else
		printf("%d\n" , abs(x1-x2) + abs(y1-y2) );

	return 0;
}

#include<stdio.h>
int min(int a,int b);
int main()
{
	int n,x1,y1,x2,y2,d1,d2;
	scanf("%d%d%d%d%d",&n,&x1,&y1,&x2,&y2);
	d1=x1+y1+x2+y2;
	d2=(4*n)-d1;
	printf("%d",min(d1,d2));
	return 0;
}
int min(int a,int b)
{
	if(a>b) return b;
	else return a;
}

#include <stdio.h>

int abs (int x)
{
	return ( x < 0 ? -x : x );
}

int min (int x, int y)
{
	return (x < y ? x : y);
}

int main()
{
	int n, x1, y1, x2, y2;
	int s, sq;

	scanf ("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

	sq = n * n;
	s = x1 + x2 + y1 + y2;

	if ( abs (x1 - x2) == n || abs (y1 - y2) == n ) {
		printf ("%d\n", min (s, 4 * s - s));
	} else {
		printf ("%d\n", abs(x1 - x2) + abs(y1 - y2));
	}

	return 0;
}

#include <stdio.h>

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

int main()
{
	int n, x1, y1, x2, y2;
	int s, sq;

	scanf ("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

	s = x1 + x2 + y1 + y2;
	sq = n * n;

	if ( s != 0 && sq - s != 0 ) {
		printf ("%d\n", min (s, sq - s));
	} else {
		printf ("%d\n", s);
	}

	return 0;
}

#include <stdio.h>

int abs (int x)
{
	return ( x < 0 ? -x : x );
}

int main()
{
	int n, x1, y1, x2, y2;
	int s, sq;

	scanf ("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

	if ( abs (x1 - x2) == n || abs (y1 - y2) == n ) {
		printf ("%d\n", x1 + x2 + y1 + y2);
	} else {
		printf ("%d\n", abs(x1 - x2) + abs(y1 - y2));
	}

	return 0;
}

#include <stdio.h>

int main()
{
	int n, x1, y1, x2, y2;
	int s;

	scanf ("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

	s = x1 + x2 + y1 + y2;

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

	return 0;
}

#include <stdio.h>

int abs (int x)
{
	return ( x < 0 ? -x : x );
}

int min (int x, int y)
{
	return (x < y ? x : y);
}

int main()
{
	int n, x1, y1, x2, y2;
	int s, sq;

	scanf ("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);

	sq = n * n;
	s = x1 + x2 + y1 + y2;

	if ( abs (x1 - x2) == n || abs (y1 - y2) == n ) {
		printf ("%d\n", min (s, sq - s));
	} else {
		printf ("%d\n", abs(x1 - x2) + abs(y1 - y2));
	}

	return 0;
}

#include <stdio.h>

int abs( int d )
{

    return d < 0 ? -d : d;
}

int cut( int x, int y, int n )
{
    if ( x == 0 ) {
        return y;
    }
    if ( y == n ) {
        return n + x;
    }
    if ( x == n ) {
        return 2 * n + y ;
    }

    if ( y == 0 ) {
        return 3 * n + x ;
    }

    return -1;
}

int main( void )
{
    int n, x1, y1, x2, y2;
    int d1, d2, diff;

    scanf( "%d %d %d %d %d", &n, &x1, &y1, &x2, &y2 );
    d1 = cut( x1, y1, n );
    d2 = cut( x2, y2, n );
    diff = abs( d1 - d2 );
    diff = 4 * n - diff < diff ? 4 * n - diff : diff;
    printf( "%d\n", diff );
    fflush( stdout );

    return 0;

}

#include <stdio.h>

int abs( int d )
{

    return d < 0 ? -d : d;
}

int cut( int x, int y, int n )
{
    if ( x == 0 ) {
        return y;
    }
    if ( y == n ) {
        return n + x;
    }
    if ( x == n ) {
        if ( y ) {
            return 2 * n + y ;
        } else {
            return 3 * n;
        }
    }

    if ( y == 0 ) {
        return 3 * n + x ;
    }

    return -1;
}

int main( void )
{
    int n, x1, y1, x2, y2;
    int d1, d2, diff;

    scanf( "%d %d %d %d %d", &n, &x1, &y1, &x2, &y2 );
    d1 = cut( x1, y1, n );
    d2 = cut( x2, y2, n );
    diff = abs( d1 - d2 );
    diff = 4 * n - diff < diff ? 4 * n - diff : diff;
    printf( "%d\n", diff );
    fflush( stdout );

    return 0;

}


Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display).  Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.For example if a = 1 and b = 3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.

The only line contains two integers a, b (1 ≤ a ≤ b ≤ 106) — the first and the last number typed by Max.

Print the only integer a — the total number of printed segments.

#include<stdio.h>
int cal(int x)
{
    if(x==0)
        return 6;
    else if(x==1)
        return 2;
    else if(x==2)
        return 5;
    else if(x==3)
        return 5;
    else if(x==4)
        return 4;
    else if(x==5)
        return 5;
    else if(x==6)
        return 6;
    else if(x==7)
        return 3;
    else if(x==8)
        return 7;
    else
        return 6;
}
int main()
{
    int a,b,i,ans=0,p;
    scanf("%d %d",&a,&b);
    for(i=a;i<=b;i++)
    {
        int t=i;
        while(t!=0)
        {
        p=t%10;
        ans=ans+cal(p);
        t=t/10;
        }
    }
    printf("%d",ans);
    return 0;
}

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

//			  0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
int CoS[] = { 6, 2, 5, 5, 4 ,5, 6, 3, 7, 6 };

int GetCountOfSegment(int a)
{
	int iSum = 0;
	int i = 0;
	int iLen ;

	char strA[20];
	sprintf(strA,"%d",a);

	iLen = strlen( strA );

	for( i = 0 ; i < iLen ; i++ )
	{
		iSum += CoS[ strA[i]-'0' ];
	}

	return iSum;
}

int main()
{

	int a,b;
	int iSum = 0;
	int i;

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

	for( i = a ; i <= b ; i++ )
	{
		iSum += GetCountOfSegment( i );
	}

	printf("%d",iSum);

	return 0;
}

#include<stdio.h>
int main()
{
    int i,a,b,z,sum=0,o,u,j;
    scanf("%d%d",&a,&b);
    for(i=a;i<=b;i++)
    {
     z=i;
     for(j=0;z!=0;j++)
     {
    o=z%10;
          if(o==0)
     {
         sum=sum+6;
     }
     else if(o==1)
     {
         sum=sum+2;
     }
          else if(o==2)
     {
         sum=sum+5;
     }
          else if(o==3)
     {
         sum=sum+5;
     }
          else if(o==4)
     {
         sum=sum+4;
     }
          else if(o==5)
     {
         sum=sum+5;
     }
          else if(o==6)
     {
         sum=sum+6;
     }
          else if(o==7)
     {
         sum=sum+3;
     }
          else if(o==8)
     {
         sum=sum+7;
     }
          else if(o==9)
     {
         sum=sum+6;
     }
     z=z/10;
     }

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

//
//  main.cpp
//  B
//
//  Created by KJBS2 on 2016. 1. 22..
//  Copyright (c) 2016년 KJBS2. All rights reserved.
//

#include <stdio.h>

int Plus[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main() {
    int a, b;
    scanf("%d%d", &a, &b);

    int result = 0;
    for(int i=a; i<=b; i++) {
        int now = i;
        while(now) {
            result += Plus[now%10];
            now /= 10;
        }
    }

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

    return 0;
}

#include<stdio.h>
int F(int n){
	switch(n){
		case 0:
			return 6;
		case 1:
			return 2;
		case 2:
			return 5;
		case 3:
			return 5;
		case 4:
			return 4;
		case 5:
			return 5;
		case 6:
			return 6;
		case 7:
			return 3;
		case 8:
			return 7;
		case 9:
			return 6;
	}
}
int main(){
	int a,b,n,m,sum = 0;
	scanf("%d %d",&a,&b);
	for(int i = a; i <= b; i++){
		n = i;
			while(n>0){
				sum += F((n%10));
				n/=10;
			}

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

#include <stdio.h>

int main()
{
    int a = 0, b = 0, tmp;
    int c;
    int sum = 0;
    scanf("%d", &a);
    scanf("%d", &b);
    for (int i = a; i <= b; i++)
    {
        tmp = i;
        while (tmp > 0)
        {
            c = tmp % 10;
            tmp = tmp / 10;
            if (c == 1)
                sum += 2;
            else if (c == 2 || c == 3 || c == 5)
                sum += 5;
            else if (c == 4)
                sum += 4;
            else if (c == 6 || c == 9 || c == 0)
                sum += 6;
            else if (c == 7)
                sum += 3;
            else if (c == 8)
                sum += 7;
        }
    }
    printf("\n %d", sum);
    return 0;
}

#include<stdio.h>
int call(int);
int main()
{
int a,b;
scanf("%d%d",&a,&b);
int i,j,k,count=0;
for(i=a;i<=b;i++){ j=i;
            for(;j>0;){
            k=j%10;
            count=call(k)+count;
            j=j/10;
            }
}
printf("%d",count);
return 0;
}
int call(int c){
switch(c){
 case 0: return 6;
 case 1: return 2;
 case 2: return 5;
 case 3: return 5;
 case 4: return 4;
 case 5: return 5;
 case 6: return 6;
 case 7: return 3;
 case 8: return 7;
 case 9: return 6;
}
}

#include <stdio.h>

int main()
{
    int a,b,i,k,m;
    long long sum=0;
    int ara[]={6,2,5,5,4,5,6,3,7,6};
    scanf("%d %d",&a,&b);

    for(i=a;i<=b;i++){
        k=i;
        while (k>0)
        {
            m=k%10;
            k = k/10;
            sum = sum+ara[m];
        }
    }

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

    return 0;
}

#include<stdlib.h>
#include<stdio.h>
int a[10]={6,2,5,5,4,5,6,3,7,6},x,y,i,sum,tmp,digit;
int main(){
    scanf("%d %d",&x,&y);
    for (i=x; i<=y; i++) {
        tmp=i;
        while(tmp){
            digit=tmp%10;
            sum+=a[digit];
            tmp/=10;
        }
    }
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
int a[] = {6,2,5,5,4,5,6,3,7,6};
int s(int n)
{
int r = 0;
while(n){r+= a[n%10];n/=10;}
return r;
}
int main()
{
int ans = 0;
int n,m;
scanf("%d%d",&n,&m);
int x;
for(x=n;x<=m;x++)
ans+= s(x);
printf("%d\n",ans);
return 0;
}

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

#define debug(name, arg) printf("debug(%s%d) \n", name, arg)

int solution(int arg, int arg1) {
	int ret = 0;
	int i;
	int rem;
	int number;

	for(i = arg; i <= arg1; ++i) {
		number = i;
		while(number) {
			rem = number % 10;

			switch(rem) {
				case 0 : ret += 6; break;
				case 1 : ret += 2; break;
				case 2 : ret += 5; break;
				case 3 : ret += 5; break;
				case 4 : ret += 4; break;
				case 5 : ret += 5; break;
				case 6 : ret += 6; break;
				case 7 : ret += 3; break;
				case 8 : ret += 7; break;
				case 9 : ret += 6; break;
			}

			number = number / 10;
		}
	}

	return ret;
}

int main()
{
	int a, b;
	int sol;

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

	//debug("a = ",a);
	//debug("b = ",b);

	sol = solution(a, b);
	printf("%d \n", sol);
	//debug("sol = ", sol);

	return 0;
}

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

    int x,y,n,i,j,d;
    long int z=0;

    scanf("%d %d",&x,&y);
    int hey[10]={6,2,5,5,4,5,6,3,7,6};
    for(i=x;i<=y;i++){
        n=count(i);
        for(j=1;j<=n;j++){
        d=digit(i,j);
        z=z+hey[d];

        }
    }
        printf("%ld\n",z);

}
int count(int n)
{
    int c=0;
    while(n != 0)
    {
    n /= 10;
    c++;
    }

  return c;
}

int digit(int num,int n)
{
    int i;
    long int z1=1;
    for(i=1;i<=n;i++){
        z1=z1*10;

    }
    int y1=num%z1;
    long int z2=1;
    for(i=1;i<=n-1;i++){
    z2=z2*10;
    }
    int y2=y1/z2;
    return y2;

}

#include <stdio.h>
int segCalc(int number){
	if(number==4){
		return 4;
	}else if (number==1){
		return 2;
	}else if (number==2||number==5||number==3){
		return 5;
	}else if (number==6||number==0||number==9){
		return 6;
	}else if (number==7){
		return 3;
	}else if (number==8){
		return 7;
	}

}
long findSeg(long i){
	long seg;
	int temp;
	if((i)/10==0){
		seg= segCalc(i%10);
		return seg;
	}
	else{
		temp=i%10;
		seg=segCalc(temp);

		return seg+findSeg(i/10);
	}

}
int main() {
	// your code goes here
	long a,b,sum=0,i;

	scanf("%ld %ld",&a,&b);
	for(i=a;i<=b;i++){

	sum+=	findSeg(i);

	}

	printf("%ld",sum);
	return 0;
}

#include<stdio.h>

int yes(int *t,int n)
{
	if(n>=10)
	return t[n%10]+yes(t,n/10);
	else return t[n];
}

int main(){
	int sig[]={6,2,5,5,4,5,6,3,7,6};
	int a,b,i,s=0;
	scanf("%d%d",&a,&b);
	for(i=a;i<=b;i++)
		s=s+yes(sig,i);
		printf("%d",s);
	return 0;
}

#include<stdio.h>
int main()
{
    int a, b, sum=0, s;
    scanf("%d%d",&a,&b);
    for (int i=a; i<=b; i++)
        for (int j=i; j!=0; j/=10){
            s=j%10;
            switch (s){
                case 0 :
                case 6 :
                case 9 : sum+=6; break;
                case 1 : sum+=2; break;
                case 2 :
                case 3 :
                case 5 : sum+=5; break;
                case 4 : sum+=4; break;
                case 7 : sum+=3; break;
                case 8 : sum+=7; break;
            }
        }
    printf("%d",sum);
    return 0;
}

#include<stdio.h>

int show[10]={6,2,5,5,4,5,6,3,7,6};
int count(int a){
	int counter=0;
	while(a>0){
		counter+=show[a%10];
		a=a/10;
	}
	return counter;
}

int main() {
	int a,b;
	scanf("%d%d",&a,&b);
	int i;
	long long total=0;
	for(i=a;i<=b;i++){
		total+=count(i);
	}
	printf("%lld\n",total);

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
  int arra[]={6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int a, b;
  int o=0 ;
  int i,c;
  scanf("%d%d", &a, &b) ;
  for ( i=a ; i<=b ;  i++)
  {
        c=i ;
        while (c)
        {
                o +=arra[c%10] ;
                c  /=10 ;
        }
  }
  printf("%d\n", o) ;
  return 0 ;
}

#include <stdio.h>

int cnt(int d) {
	switch (d) {
		case 0:
			return 6;
		case 1:
			return 2;
		case 2:
			return 5;
		case 3:
			return 5;
		case 4:
			return 4;
		case 5:
			return 5;
		case 6:
			return 6;
		case 7:
			return 3;
		case 8:
			return 7;
		case 9:
			return 6;
	}
	return 0;
}

int segments(int n) {
	return n < 10 ? cnt(n) : segments(n / 10) + cnt(n % 10);
}

int main() {
	int n, a, b, sum;

	scanf("%d%d", &a, &b);
	sum = 0;
	for (n = a; n <= b; n++)
		sum += segments(n);
	printf("%d\n", sum);
	return 0;
}

#include<stdio.h>

#define ll long long int

int main()
{
	ll arr[10]={6,2,5,5,4,5,6,3,7,6};
	ll a,b,i,j,count=0,t;

	scanf("%lld%lld",&a,&b);
	for(i=a;i<=b;i++)
	{
		if(i>9)
		{
			for(j=i;;)
			{
				t=j%10;
				count+=arr[t];
				j=j/10;
				if(j==0) break;
			}
		}
		else
		{
			count+=arr[i];
		}
	}
	printf("%lld\n",count);
}

#include<stdio.h>
int main()
{
int p[]={6,2,5,5,4,5,6,3,7,6};
int num,sum,a,b,i;
scanf("%d%d",&a,&b);
sum=0;
for(i=a;i<=b;i++)
{
a=i;
while(a!=0)
{
num=a%10;
a=a/10;
sum=sum+p[num];
}
}
printf("%d\n",sum);
return 0;
}

#include <stdio.h>

const int seg[10] = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

int a, b;

int main(void)
{
    int i, num, count;

    /* Reads the input */
    scanf("%d%d", &a, &b);

    /* Count */
    count = 0;

    for (i = a; i <= b; ++i)
    {
        num = i;

        /* Count each digits */
        while (num > 0)
        {
            count += seg[num % 10];
            num /= 10;
        }
    }

    /* Writes the answer */
    printf("%d\n", count);

    return 0;
}

#include<stdio.h>
int main()
{
	int a,b,i,sum=0,c,d;
	scanf("%d%d",&a,&b);
	for(i=a;i<=b;i++)
	{
		d=i;
		while(d!=0)
		{
			c=d%10;
			if(c==0)
			sum=sum+6;
			if(c==1)
			sum=sum+2;
			if(c==2)
			sum=sum+5;
			if(c==3)
			sum=sum+5;
			if(c==4)
			sum=sum+4;
			if(c==5)
			sum=sum+5;
			if(c==6)
			sum=sum+6;
			if(c==7)
			sum=sum+3;
			if(c==8)
			sum=sum+7;
			if(c==9)
			sum=sum+6;
			d=d/10;
		}
	}
	printf("%d",sum);
return 0;
}

#include <stdio.h>
#include <stdlib.h>
int Num(long a , long b);
int Analysize(int i);
int GetSeg(int a);

int main()
{
    long a,b;
    scanf("%ld %ld",&a,&b);
    long result=Num(a,b);
    printf("%ld",result);
    return 0;
}

int Num(long a , long b)
{
    long result=0;

    while(a<=b)
    {
        result+=GetSeg(a);
        a++;
    }
    return result;
}

int Analysize(int i)
{
    int d;
    switch (i)
    {
    case 1:
        d=2;
        break;
    case 7:
        d=3;
        break;
    case 2:
    case 3:
    case 5:
        d=5;
        break;
    case 4:
        d=4;
        break;
    case 0:
    case 6:
    case 9:
        d=6;
        break;
    case 8:
        d=7;
        break;
    }
    return d;
}

int GetSeg(int a){
    int result=0;
while(a!=0){
    result+=Analysize(a%10);
    a/=10;
}
return result;
}

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

int y,i,a,b,x,s;

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

s=0;
for (i=a;i<=b;i++){
y=i;
while(y!=0){
	x=(y%10);
	y=(y/10);

	switch (x){
		case 0 : s=s+6;
		        break;
		case 1 : s=s+2;
		        break;
		case 2 : s=s+5;
		        break;
		case 3 : s=s+5;
		        break;
		case 4 : s=s+4;
		        break;
		case 5 : s=s+5;
		        break;
		case 6 : s=s+6;
		        break;
		case 7 : s=s+3;
		        break;
		case 8 : s=s+7;
		        break;
		case 9 : s=s+6;
		        break;
	}
	if (y==0){
		break;
		}
}
}

printf("%d",s);

return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#define SIZE 1000002

long min(long a, long b)
{
    return (a < b) ? a : b;
}

long max(long a, long b)
{
    return (a < b) ? b : a;
}

long sum(int seg[], long x)
{
    long k = 0;
    while (x > 0)
    {
        k += seg[x % 10];
        x /= 10;
    }
    return k;
}
/*****************************************************************************/
int main(void)
{
    long m, n, k, i;
    int seg[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    scanf("%ld %ld", &m, &n);
    k = 0;
    for (i = m; i <= n; ++i)
    {
        k += sum(seg, i);
    }
    printf("%ld\n", k);
    return 0;
}

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

int main(){
    int a,b,i,j;
    long long unsigned int count=0;
    char str[8];
    scanf("%d %d",&a,&b);

    for(i=a;i<=b;i++){
        j=0;
        itoa(i,str,10);
        while(str[j]!=0){
            switch(str[j]){
                case '0':   count+=6;
                            break;
                case '1':   count+=2;
                            break;
                case '2':   count+=5;
                            break;
                case '3':   count+=5;
                            break;
                case '4':   count+=4;
                            break;
                case '5':   count+=5;
                            break;
                case '6':   count+=6;
                            break;
                case '7':   count+=3;
                            break;
                case '8':   count+=7;
                            break;
                case '9':   count+=6;
                            break;

                }
                j++;
        }

    }
    printf("%I64d\n",count);

    return 0;

}

#include<stdio.h>
int main()
{
    int i,a,b,segment=0,digit;
    scanf("%d%d",&a,&b);
    for(i=a;i<=b;i++)
    {  a=i;
       while(a!=0)
       {
          digit=a%10;
          if(digit==0) segment+=6;
          if(digit==1) segment+=2;
          if(digit==2) segment+=5;
          if(digit==3) segment+=5;
          if(digit==4) segment+=4;
          if(digit==5) segment+=5;
          if(digit==6) segment+=6;
          if(digit==7) segment+=3;
          if(digit==8) segment+=7;
          if(digit==9) segment+=6;
          a=a/10;
        }
    }
    printf("%d",segment);
}

#include<stdio.h>

int main(){
    int a,b,total=0;
    int segments[]={6,2,5,5,4,5,6,3,7,6};
    int j;
    scanf("%d%d",&a,&b);

    for (int i=a; i<=b; i++) {
        a=i;
        while (a>=10) {
            j=a%10;
            a=a/10;
            total+=segments[j];
        }
        total+=segments[a];
    }
    printf("%d",total);

}

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

int main()
{
    int seg[10]= {6,2,5,5,4,5,6,3,7,6};
    long a , b ,loopIndex , i;
    long sum = 0 ;
    scanf("%d %d", &a , &b);
    for(loopIndex=a;loopIndex<=b;loopIndex++)
    {
        i = loopIndex ;
        while(i>0)
        {
            sum+=seg[i%10];
            i/=10 ;
        }
    }
    printf("%d", sum);
}

#include <stdio.h>

int main()
{
    long long int test,n,i,j,sum1,k,m,a,flag=0,count=0,b,c[10]={6,2,5,5,4,5,6,3,7,6},a1,b2;
  scanf("%lld%lld",&a,&b);
  count=0;
  for(i=a;i<=b;i++){
      k=i;
      while(k>0){
          count+=c[k%10];
          k/=10;
      }
  }
   printf("%lld",count);
    return 0;
}

#include<stdio.h>
#include<math.h>
#include<string.h>
int number(int a)
{
	int i,num=0;
	int b[10]={6,2,5,5,4,5,6,3,7,6};
	while(1)
	{
		i=a%10;
		num+=b[i];
		if(a/10==0) break;
		a/=10;
	}
	return num;

}
int main()
{
	int a,b,i,num=0;
	scanf("%d%d",&a,&b);
	for(i=a;i<=b;++i)
	{
		num+=number(i);
	}
	printf("%d",num);
	return 0;
}

#include<stdio.h>
int main()
{
    unsigned long long int sum=0;
    int x,z,y,dif,i,temp;
    scanf("%d %d",&x,&y);
        dif=y-x;
        for(i=0;i<=dif;i++)
        {
            z=x;
            while(z!=0)
            {
            temp=z%10;
    if(0==temp)
        sum=sum+6;
    if(1==temp)
        sum=sum+2;
    if(2==temp)
        sum=sum+5;
    if(3==temp)
        sum=sum+5;
    if(4==temp)
        sum=sum+4;
    if(5==temp)
        sum=sum+5;
    if(6==temp)
        sum=sum+6;
    if(7==temp)
        sum=sum+3;
    if(8==temp)
        sum=sum+7;
    if(9==temp)
        sum=sum+6;
         z=z/10;
        }
        x++;
        }
    printf("%llu",sum);
    return 0;
}

#include<stdio.h>

int main()
{
    int a, b;
    long long cnt=0;
    scanf("%d%d",&a,&b);
    for(int i=a;i<=b;i++)
    {
    int num=i;
    while(num)
    {
    int rem=num%10;
    if(rem==1)
    cnt+=2;
    else if(rem==2||rem==3||rem==5)
    cnt+=5;
    else if(rem==6||rem==9||rem==0)
    cnt+=6;
    else if(rem==8)
    cnt+=7;
    else if(rem==7)
    cnt+=3;
    else if(rem==4)
    cnt+=4;
    num/=10;
    }
    }
    printf("%lld",cnt);
    return 0;
}

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

int main()
{int a, b, i, intermediate;
long int segments = 0 ;

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

for ( i = a; i <= b; i++)
{

    intermediate = i;
    do {
            switch(intermediate % 10)
            {
                case 0: segments += 6; break;
                case 1: segments += 2; break;
                case 2: segments += 5; break;
                case 3: segments += 5; break;
                case 4: segments += 4; break;
                case 5: segments += 5; break;
                case 6: segments += 6; break;
                case 7: segments += 3; break;
                case 8: segments += 7; break;
                case 9: segments += 6; break;

            }

            intermediate = intermediate / 10;

    } while (intermediate != 0);

}

printf("%ld",segments);

    return 0;
}

//shauwaaa
//shauwaaa
//shauwaaa
//shauwaaa
//shauwaaa
//shauwaaa
//shauwaaa
//shauwaaa
//shauwaaa
//shauwaaa
//shauwaaa
//shauwaaa

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

    int y,i,a,b,x,s=0;

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

    for (i=a; i<=b; i++)
    {
        y=i;
        while(y!=0)
        {
            x=(y%10);
            y=(y/10);

            switch (x)
            {
            case 0 :
                s=s+6;
                break;
            case 1 :
                s=s+2;
                break;
            case 2 :
                s=s+5;
                break;
            case 3 :
                s=s+5;
                break;
            case 4 :
                s=s+4;
                break;
            case 5 :
                s=s+5;
                break;
            case 6 :
                s=s+6;
                break;
            case 7 :
                s=s+3;
                break;
            case 8 :
                s=s+7;
                break;
            case 9 :
                s=s+6;
                break;
            }
            if (y==0)
            {
                break;
            }
        }
    }

    printf("%d",s);

}

#include<stdio.h>

int main() {
        int m;
        int n;
        unsigned long long sum=0;
        int i,j,k;
        int arr[10]={6,2,5,5,4,5,6,3,7,6};

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

        if(m==0)
                sum+=6;
        for(i=m;i<=n;i++) {
                j = i;
                while(j!=0) {
                        k = j%10;
                        j/=10;
                        sum+=arr[k];
                }
        }
        printf("%llu",sum);
        return 0;
}

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

//1〜nに含まれるcountの個数を求める
unsigned long long solve(unsigned long long n,int count,int base){
	unsigned long long r=0; //結果
	unsigned long long lower=0; //処理している桁より下の桁の合計
	unsigned long long digits=0,expbase=1;
	for(;n;digits++,expbase*=base,n/=base){
		unsigned long long d=digits*expbase/base; //0,1,20,300,4000,...
		unsigned long long current_digit=n%base;
		r+=current_digit*d;
		if(current_digit==count)r+=lower+1;
		if(current_digit>=count+1)r+=expbase;
		lower+=current_digit*expbase;
		if(count==0)r-=expbase;
	}
	return r;
}

int d[]={6,2,5,5,4,5,6,3,7,6};
int main(){
	int base=10;

	unsigned long long n,m,r=0;
	scanf("%I64d%I64d",&n,&m);
	int i=0;
	for(;i<10;i++)r+=d[i]*(solve(m,i,base)-solve(n-1,i,base));
	printf("%I64d\n",r);
}

#include <stdio.h>

int main() {
    int num[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    int ans, t;
    int a, b;

    scanf("%d %d", &a, &b);
    ans = 0;
    for (int i = a;i <= b;i ++) {
        t = i;
        while (t) {
            ans += num[t % 10];
            t /= 10;
        }
    }
    printf("%d\n", ans);

    return 0;
}

#include<stdio.h>
int main()
{
	unsigned long long a,b,num,number;
	int sum = 0,total = 0;
	int last_dig;

	scanf("%llu %llu",&a,&b);
	for(number = a; number<= b; number++)
	{
		num = number;
		while(1)
	   {
		 last_dig = num % 10;

 		 if(last_dig == 0){
 			total += 6;
		 }

		 else if(last_dig == 1){
			total += 2;
		 }

		 else if(last_dig == 2){
			total += 5;
		 }

		 else if(last_dig == 3){
			total += 5;
		 }

		 else if(last_dig == 4){
			total += 4;
		 }

		 else if(last_dig == 5){
			total += 5;
		 }

		 else if(last_dig == 6){
			total += 6;
		 }

		 else if(last_dig == 7){
			total += 3;
		 }

		 else if(last_dig == 8){
			total += 7;
		 }

		 else if(last_dig == 9){
			total += 6;
		 }

		 num = num/10;
		 if(num==0)
			break;
    	}
	}
	printf("%d",total);
	return 0;
}

#include<stdio.h>
int a[20]={6,2,5,5,4,5,6,3,7,6};
int ha(int n)
{
    int m,sum=0;
    while(n)
    {
        m=n%10;
        n=n/10;
        sum+=a[m];
    }
    return(sum);
}
int main()
{int m,n,sum,i;
scanf("%d%d",&n,&m);
sum=0;
for(i=n;i<=m;i++)
    sum+=ha(i);
    printf("%d\n",sum);
    return 0;
}

#include<stdio.h>

int yes(int *t,int n)
{
	if(n>=10)
	return t[n%10]+yes(t,n/10);
	else return t[n];
}

int main(){
	int sig[]={6,2,5,5,4,5,6,3,7,6};
	int a,b,i,s=0;
	scanf("%d%d",&a,&b);
	for(i=a;i<=b;i++)
		s=s+yes(sig,i);
		printf("%d",s);
	return 0;
}

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

int main()
{
    int m,n,i,j,x,c=0;
    scanf("%d %d",&m,&n);
    for(i=m;i<=n;i++){
            j=i;
        while(j>0){
            x=j%10;
            j=j/10;
            switch(x){
            case 0:
            case 6:
            case 9:
                c=c+6;
                break;
            case 1:
                c=c+2;
                break;
            case 2:
            case 3:
            case 5:
                c=c+5;
                break;
            case 4:
                c=c+4;
                break;
            case 7:
                c=c+3;
                break;
            case 8:
                c=c+7;
                break;

            }

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

}

#include<stdio.h>
int arr[10]={6,2,5,5,4,5,6,3,7,6},t;
int hesapla(int x){
	if(x>=10){
		t+=arr[x%10];
		x/=10;
		return hesapla(x);}
	else
		return arr[x]+t;}
main(){
	int i,z=0,a,b;
	scanf("%d%d",&a,&b);
	for(i=a;i<=b;i++){
		z+=hesapla(i);
		t=0;
	}
	printf("%d",z);

}

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

#define PI 3.141592653589793
#define max(a,b) (a < b) ? (b) : (a)
#define min(a,b) (a > b) ? (b) : (a)
#define FOR(i,a,b) for(i = a ; i <= b ; i++)
#define ROF(i,a,b) for(i = a ; i >= b ; i--)
#define RAD(x) ((x)*PI)/180
#define y1 y_1
#define ll long long
#define endl printf("\n")
#define MAX 100005

int a, b, i, x, ans, t[10] = {6, 2, 5, 5 ,4, 5 ,6, 3, 7, 6};

int main () {
	scanf("%d %d",&a ,&b);
	FOR(i, a, b){
		x = i;
		while(x){
			ans += t[x%10];
			x/=10;
		}
	}
	printf("%d\n",ans);
	return 0;
}

#include<stdio.h>

int main(){
    int a,b,total=0;
    int segments[]={6,2,5,5,4,5,6,3,7,6};
    int j;
    scanf("%d%d",&a,&b);

    for (int i=a; i<=b; i++) {
        a=i;
        while (a>=10) {
            j=a%10;
            a=a/10;
            total+=segments[j];
        }
        total+=segments[a];
    }
    printf("%d",total);

}

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

int main ()
{
	int a,b,n=0;
	scanf("%d %d",&a,&b);
	for ( ;a<=b;a++)
	{
		int i=a;
		int t=1;
		while (i)
		{
			t = i % 10;
			switch (t)
			{
			case 0:
				n+=6;
				break;
			case 1:
				n+=2;
				break;
			case 2:
				n+=5;
				break;
			case 3:
				n+=5;
				break;
			case 4:
				n+=4;
				break;
			case 5:
				n+=5;
				break;
			case 6:
				n+=6;
				break;
			case 7:
				n+=3;
				break;
			case 8:
				n+=7;
				break;
			case 9:
				n+=6;
				break;
			}
			//printf ("%d\n",t);
			i /=10;
		}
	}
	printf ("%d",n);
	return 0;
}

#include <stdio.h>

int main(void)
{
	int a, b, k, m, num = 0;

	scanf("%d %d", &a, &b);
	for(; a <= b; a++)
	{
		m = a;
		for(; m != 0;)
		{
			k = m % 10;
			switch(k)
			{
				case 0 : num += 6; break;
				case 1 : num += 2; break;
				case 2 : num += 5; break;
				case 3 : num += 5; break;
				case 4 : num += 4; break;
				case 5 : num += 5; break;
				case 6 : num += 6; break;
				case 7 : num += 3; break;
				case 8 : num += 7; break;
				case 9 : num += 6; break;
			}
			m /= 10;
		}
	}
	printf("%d", num);

	return 0;
}

#include <stdio.h>

int main()
{
    long long int test,n,i,j,sum1,k,m,a,flag=0,count=0,b,c[10]={6,2,5,5,4,5,6,3,7,6},a1,b2;
  scanf("%lld%lld",&a,&b);
  count=0;
  for(i=a;i<=b;i++){
      k=i;
      while(k>0){
          count+=c[k%10];
          k/=10;
      }
  }
   printf("%lld",count);
    return 0;
}

#include<stdio.h>
#include<process.h>
#include<string.h>
#include<math.h>
int main()
{
	int a, b,k,j,sum=0;
	scanf("%d%d", &a, &b);
	for (int i = a; i < b + 1; i++){
		j = i;
		while (j != 0){
			k=j % 10;
			j=j / 10;
			switch (k){
			case 1:sum += 2; break;
			case 2:sum += 5; break;
			case 3:sum += 5; break;
			case 4:sum += 4; break;
			case 5:sum += 5; break;
			case 6:sum += 6; break;
			case 7:sum += 3; break;
			case 8:sum += 7; break;
			case 9:sum += 6; break;
			case 0:sum += 6; break;
			}
		}

	}
	printf("%d", sum);

	return 0;
}

#include <stdio.h>
long long int sum=0;
void func(long int c)
{
   if(c==0)
	   sum+=6;
   else if(c==1)
	   sum+=2;
   else if(c==2)
	   sum+=5;
   else if(c==3)
	   sum+=5;
   else if(c==4)
	  sum+=4;
   else if(c==5)
	   sum+=5;
   else if(c==6)
	   sum+6;
   else if(c==7)
	   sum+=3;
   else if(c==8)
	   sum+=7;
   else
	   sum+=6;
}
int main()
{
	long int a,b,i,j;
	scanf("%ld %ld",&a,&b);
	for(i=a;i<=b;i++)
	{
		j=i;
		while(j>0)
		{
			func(j%10);
			j=j/10;
		}
	}
	printf("%lld\n",sum);
	return 0;
}

#include <stdio.h>
long long int sum=0;
void func(long int c)
{
   if(c==0)
	   sum+=6;
   else if(c==1)
	   sum+=2;
   else if(c==2)
	   sum+=5;
   else if(c==3)
	   sum+=5;
   else if(c==4)
	  sum+=4;
   else if(c==5)
	   sum+=5;
   else if(c==6)
	   sum+6;
   else if(c==7)
	   sum+=3;
   else if(c==8)
	   sum+=7;
   else
	   sum+=6;
}
int main()
{
	long int a,b,i,j;
	sum=0;
	scanf("%ld %ld",&a,&b);
	for(i=a;i<=b;i++)
	{
		j=i;
		while(j!=0)
		{
			func(j%10);
			j=j/10;
//			printf("%lld\n",sum);
		}
	}
	printf("%lld\n",sum);
	return 0;
}

#include <stdio.h>
long long int sum=0;
void func(long int c)
{
   if(c==0)
	   sum+=6;
   else if(c==1)
	   sum+=2;
   else if(c==2)
	   sum+=5;
   else if(c==3)
	   sum+=5;
   else if(c==4)
	  sum+=4;
   else if(c==5)
	   sum+=5;
   else if(c==6)
	   sum+6;
   else if(c==7)
	   sum+=3;
   else if(c==8)
	   sum+=7;
   else
	   sum+=6;
}
int main()
{
	long int a,b,i,j;
	scanf("%ld %ld",&a,&b);
	for(i=a;i<=b;i++)
	{
		j=i;
		while(j!=0)
		{
			func(j%10);
			j=j/10;
//			printf("%lld\n",sum);
		}
	}
	printf("%lld\n",sum);
	return 0;
}

#include<stdio.h>
int main()
{
    unsigned long long int sum=0;
    int x,z,y,dif,i,temp;
    scanf("%d %d",&x,&y);
    if(x>=9)
    {
        dif=y-x;
        for(i=0;i<=dif;i++)
        {
            z=x;
            while(z!=0)
            {
            temp=z%10;
    if(0==temp)
        sum=sum+6;
    if(1==temp)
        sum=sum+2;
    if(2==temp)
        sum=sum+5;
    if(3==temp)
        sum=sum+5;
    if(4==temp)
        sum=sum+4;
    if(5==temp)
        sum=sum+5;
    if(6==temp)
        sum=sum+6;
    if(7==temp)
        sum=sum+3;
    if(8==temp)
        sum=sum+7;
    if(9==temp)
        sum=sum+6;
         z=z/10;
        }
        x++;
        }
    }
    else
    {
    if(0>=x&&0<=y)
        sum=sum+6;
    if(1>=x&&1<=y)
        sum=sum+2;
    if(2>=x&&2<=y)
        sum=sum+5;
    if(3>=x&&3<=y)
        sum=sum+5;
    if(4>=x&&4<=y)
        sum=sum+4;
    if(5>=x&&5<=y)
        sum=sum+5;
    if(6>=x&&6<=y)
        sum=sum+6;
    if(7>=x&&7<=y)
        sum=sum+3;
    if(8>=x&&8<=y)
        sum=sum+7;
    if(9>=x&&9<=y)
        sum=sum+6;
    }
    printf("%llu",sum);
    return 0;
}

#include<stdio.h>
int a[] = {6,2,5,5,4,5,6,3,7,6};
int s(int n)
{
int r = 0;
while(n){r+= a[n%10];n/=10;}
return r;
}
int main()
{
int ans = 0;
int n,m;
scanf("%d%d",&n,&m);
int x;
for(x=n;x<=n;x++)
ans+= s(x);
printf("%d\n",ans);
return 0;
}

#include<stdio.h>
int a[] = {6,2,5,5,4,5,6,3,7,6};
int s(int n)
{
int r = 0;
while(n)r+= a[n/10],n/=10;
return r;
}
int main()
{
int ans = 0;
int n,m;
scanf("%d%d",&n,&m);
int x;
for(x=n;x<=n;x++)
ans+= s(x);
printf("%d\n",ans);
return 0;
}

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

#define PI 3.141592653589793
#define max(a,b) (a < b) ? (b) : (a)
#define min(a,b) (a > b) ? (b) : (a)
#define FOR(i,a,b) for(i = a ; i <= b ; i++)
#define ROF(i,a,b) for(i = a ; i >= b ; i--)
#define RAD(x) ((x)*PI)/180
#define y1 y_1
#define ll long long
#define endl printf("\n")
#define MAX 100005

int a, b, i, x, ans, t[10] = {6, 2, 5, 5 ,4, 5 ,6, 3, 8, 6};

int main () {
	scanf("%d %d",&a ,&b);
	FOR(i, a, b){
		x = i;
		while(x){
			ans += t[x%10];
			x/=10;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

//			  0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
int CoS[] = { 6, 2, 5, 5, 4 ,5, 6, 3, 7, 6 };

int GetCountOfSegment(int a)
{
	int iSum = 0;
	int i = 0;
	int iLen ;

	char strA[20];
	sprintf(strA,"%d",a);

	iLen = strlen( strA );

	for( i = 0 ; i < iLen ; i++ )
	{
		iSum += CoS[ strA[i]-'0' ];
	}

	printf("%d(%s) : %d\n", a, strA , iSum);

	return iSum;
}

int main()
{

	int a,b;
	int iSum = 0;
	int i;

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

	for( i = a ; i <= b ; i++ )
	{
		iSum += GetCountOfSegment( i );

		printf("%d : %d \n\n", i, iSum);

	}

	printf("%d",iSum);

	return 0;
}

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

//			  0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
int CoS[] = { 6, 2, 5, 5, 4 ,5, 6, 4, 7, 6 };

int GetCountOfSegment(int a)
{
	int iSum = 0;
	int i = 0;
	int iLen ;

	char strA[20];
	sprintf(strA,"%d",a);

	iLen = strlen( strA );

	for( i = 0 ; i < iLen ; i++ )
	{
		iSum += CoS[ strA[i]-'0' ];
	}

	return iSum;
}

int main()
{

	int a,b;
	int iSum = 0;
	int i;

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

	for( i = a ; i <= b ; i++ )
	{
		iSum += GetCountOfSegment( i );
	}

	printf("%d",iSum);

	return 0;
}

#include<stdio.h>
#include<math.h>
#include<string.h>
int number(int a)
{
	int i,num=0;
	do
	{
		i=a%10;
		switch(i)
		{
	 		case 0:num+=6;break;
	 	    case 1:num+=2;break;
	 	    case 2:num+=5;break;
	   	    case 3:num+=5;break;
	     	case 4:num+=4;break;
      		case 5:num+=5;break;
	     	case 6:num+=6;break;
     		case 7:num+=3;break;
       		case 8:num+=7;break;
     		case 9:num+=6;break;
		}
		a/=10;
	}
	while(a/10!=0);
	return num;
}
int main()
{
	int a,b,i,num=0;
	scanf("%d%d",&a,&b);
	for(i=a;i<=b;++i)
	{
		num+=number(i);
	}
	printf("%d",num);
	return 0;
}

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

#define debug(name, arg) printf("debug(%s%d) \n", name, arg)

int solution(int arg, int arg1) {
	int ret = 0;
	int i;
	int rem;
	int number;

	for(i = arg; i <= arg1; ++i) {
		number = i;
		while(number) {
			rem = number % 10;

			switch(rem) {
				case 0 : ret += 6; break;
				case 1 : ret += 2; break;
				case 2 : ret += 5; break;
				case 3 : ret += 5; break;
				case 4 : ret += 4; break;
				case 5 : ret += 5; break;
				case 6 : ret += 6; break;
				case 7 : ret += 3; break;
				case 8 : ret += 7; break;
				case 9 : ret += 9; break;
			}

			number = number / 10;
		}
	}

	return ret;
}

int main()
{
	int a, b;
	int sol;

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

	//debug("a = ",a);
	//debug("b = ",b);

	sol = solution(a, b);
	printf("%d \n", sol);
	//debug("sol = ", sol);

	return 0;
}

#include<stdio.h>
int F(int n){
	switch(n){
		case 0:
			return 6;
		case 1:
			return 2;
		case 2:
			return 5;
		case 3:
			return 5;
		case 4:
			return 4;
		case 5:
			return 5;
		case 6:
			return 6;
		case 7:
			return 3;
		case 8:
			return 7;
		case 9:
			return 6;
	}
}
int main(){
	int a,b,n,m,sum = 0;
	scanf("%d %d",&a,&b);
	for(int i = a; i <= b; i++){
		if(i<10){
			sum += F(i);
		}
		else{
			sum += F(i/10);
			sum += F(i%10);
		}
	}
	printf("%d\n",sum);
	return 0;
}

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

int x[1000];

int main()
{
	memset(x,0,sizeof(x));
	int a,b,n=0;
	scanf("%d %d",&a,&b);
	for ( int i=a;i<=b;i++)
	{
		for ( int j=0;j<=6;j++ )
		{
			x[j] = (i % (int)pow(10,j+1))/ (int)pow(10,j);
		}
		for ( int j=0;j<=6;j++ )
		{
			if ( x[j] == 0 && (x[j+1] !=0 || x[j+2] !=0 || x[j+3] !=0 || x[j+4] !=0 || x[j+5] !=0 || x[j+6] !=0))
			n+=6;
			else
			{
		switch (x[j])
		{
			case 1:
				n+=2;
				break;
			case 2:
				n+=5;
				break;
			case 3:
				n+=5;
				break;
			case 4:
				n+=4;
				break;
			case 5:
				n+=5;
				break;
			case 6:
				n+=6;
				break;
			case 7:
				n+=3;
				break;
			case 8:
				n+=7;
				break;
			case 9:
				n+=6;
				break;
			}
		}
		//printf("%d %d\n",x[j],n);
	}

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

#include<stdio.h>
main(){
	int a,b,c,ans=0;
	scanf("%d %d",&a,&b);
	for(;a<=b;a++){
		c=a;
		for(;c!=0;c=c/10){
			switch(c%10){
				case 0:ans=ans+6;break;
				case 1:ans=ans+2;break;
				case 2:ans=ans+5;break;
				case 3:ans=ans+5;break;
				case 4:ans=ans+4;break;
				case 5:ans=ans+5;break;
				case 6:ans=ans+6;break;
				case 7:ans=ans+3;break;
				case 8:ans=ans+8;break;
				case 9:ans=ans+6;break;
			}
		}
	}
	printf("%d",ans);
}

#include<stdio.h>
main(){
	int a,b,c;
	long long int ans=0;
	scanf("%d %d",&a,&b);
	for(;a<=b;a++){
		c=a;
		for(;c!=0;c=c/10){
			switch(c%10){
				case 0:ans=ans+6;break;
				case 1:ans=ans+2;break;
				case 2:ans=ans+5;break;
				case 3:ans=ans+5;break;
				case 4:ans=ans+4;break;
				case 5:ans=ans+5;break;
				case 6:ans=ans+6;break;
				case 7:ans=ans+3;break;
				case 8:ans=ans+8;break;
				case 9:ans=ans+6;break;
			}
		}
	}
	printf("%d",ans);
}

#include <stdio.h>
#include <math.h>
int count(int n)
{
    int c=0;
    while(n != 0)
    {
    n /= 10;
    ++c;
    }

  return c;
}

int digit(int num,int n)
{   int p, t1, t2;

    t1 = pow(10, n+1);
    p = num % t1;

    if (n > 0)
    {
        t2 = pow(10, n);
        p = p / t2;
    }

    return p;

}
int main()
{

    int x,y,n,i,j,d,z=0;

    scanf("%d %d",&x,&y);
    int hey[10]={6,2,5,5,4,5,6,3,7,6};
    for(i=x;i<=y;i++){
        n=count(i);
        for(j=0;j<n;j++){
        d=digit(i,j);
        z=z+hey[d];

        }
    }
        printf("%d\n",z);

}

#include<stdio.h>

int main()
{
	int arr[10]={6,2,5,5,4,5,6,3,7,6};
	int a,b,sum=0,i,rem,temp;
	scanf("%d%d",&a,&b);
	for(i=a;i<=b;i++)
	{
		temp=i;
		while(temp!=0)
		{
			rem=temp%10;
			sum+=arr[rem];
			printf("%d ",sum);
			temp=temp/10;
		}
	}
	printf("%d",sum);
}

#include <stdio.h>

int main()
{
	int svSeg[10]={6,2,5,5,4,5,6,3,7,6};

	int firNum=0,lastNum=0;

	int sum=0;
	scanf("%d%d",&firNum,&lastNum);
	for(int i=firNum ; i <= lastNum ; i++){

		int iCal=i;

		if( iCal/1000000 != 0)
		sum = sum + svSeg[iCal/1000000];
		iCal = iCal % 1000000;

		if( iCal/100000 != 0)
		sum = sum + svSeg[iCal/100000];
		iCal = iCal % 100000;

		if( iCal/10000 != 0)
		sum = sum + svSeg[iCal/10000];
		iCal = iCal % 10000;

		if( iCal/1000 != 0)
		sum = sum + svSeg[iCal/1000];
		iCal = iCal % 1000;

		if( iCal/100 != 0)
		sum = sum + svSeg[iCal/100];
		iCal = iCal % 100;

		if( iCal/10 != 0)
		sum = sum + svSeg[iCal/10];
		iCal = iCal % 10;

		sum = sum + svSeg[iCal];
	}

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

#include<stdio.h>

int yes(int *t,int n)
{
	if(n>=10)
	return t[n%10]+yes(t,n/10);
	else return t[n];
}

int main(){
	int sig[]={4,2,5,5,4,5,6,3,7,6};
	int a,b,i,s=0;
	scanf("%d%d",&a,&b);
	for(i=a;i<=b;i++)
		s=s+yes(sig,i);
		printf("%d",s);
	return 0;
}

#include <stdio.h>

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);

    unsigned long long counts[10];
    for (int i = a; i <= b; i++) {
        int x = i;
        while (x != 0) {
            counts[x % 10]++;
            x /= 10;
        }
    }

    int digits[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    unsigned long long ans = 0;
    for (int i = 0; i < 10; i++) {
        ans += (unsigned long long)(counts[i] * digits[i]);
    }
    printf("%lld\n", ans);
    return 0;
}

#include<stdio.h>
int main()
{
    long long int sum=0;
    int x,z,y,dif,i,temp;
    scanf("%d %d",&x,&y);
    if(x>=9)
    {
        dif=y-x;
        for(i=0;i<=dif;i++)
        {
            z=x;
            while(z!=0)
            {
            temp=z%10;
    if(0==temp)
        sum=sum+6;
    if(1==temp)
        sum=sum+2;
    if(2==temp)
        sum=sum+5;
    if(3==temp)
        sum=sum+5;
    if(4==temp)
        sum=sum+4;
    if(5==temp)
        sum=sum+5;
    if(6==temp)
        sum=sum+6;
    if(7==temp)
        sum=sum+3;
    if(8==temp)
        sum=sum+7;
    if(9==temp)
        sum=sum+6;
         z=z/10;
        }
        x++;
        }
    }
    else
    {
    if(0>=x&&0<=y)
        sum=sum+6;
    if(1>=x&&1<=y)
        sum=sum+2;
    if(2>=x&&2<=y)
        sum=sum+5;
    if(3>=x&&3<=y)
        sum=sum+5;
    if(4>=x&&4<=y)
        sum=sum+4;
    if(5>=x&&5<=y)
        sum=sum+5;
    if(6>=x&&6<=y)
        sum=sum+6;
    if(7>=x&&7<=y)
        sum=sum+3;
    if(8>=x&&8<=y)
        sum=sum+7;
    if(9>=x&&9<=y)
        sum=sum+6;
    }
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
int main()
{
    long long int sum=0;
    int x,z,y,dif,i,temp;
    scanf("%d %d",&x,&y);
    if(x>=9)
    {
        dif=y-x;
        for(i=0;i<=dif;i++)
        {
            z=x;
            while(z!=0)
            {
            temp=z%10;
    if(0==temp)
        sum=sum+6;
    if(1==temp)
        sum=sum+2;
    if(2==temp)
        sum=sum+5;
    if(3==temp)
        sum=sum+5;
    if(4==temp)
        sum=sum+4;
    if(5==temp)
        sum=sum+5;
    if(6==temp)
        sum=sum+6;
    if(7==temp)
        sum=sum+3;
    if(8==temp)
        sum=sum+7;
    if(9==temp)
        sum=sum+6;
         z=z/10;
        }
        x++;
        }
    }
    else
    {
    if(0>=x&&0<=y)
        sum=sum+6;
    if(1>=x&&1<=y)
        sum=sum+2;
    if(2>=x&&2<=y)
        sum=sum+5;
    if(3>=x&&3<=y)
        sum=sum+5;
    if(4>=x&&4<=y)
        sum=sum+4;
    if(5>=x&&5<=y)
        sum=sum+5;
    if(6>=x&&6<=y)
        sum=sum+6;
    if(7>=x&&7<=y)
        sum=sum+3;
    if(8>=x&&8<=y)
        sum=sum+7;
    if(9>=x&&9<=y)
        sum=sum+6;
    }
    printf("%llu",sum);
    return 0;
}

#include<stdio.h>
int main()
{
    int x,z,y,sum=0,dif,i,temp;
    scanf("%d %d",&x,&y);
    if(x>=9)
    {
        dif=y-x;
        for(i=0;i<=dif;i++)
        {
            z=x;
            while(z!=0)
            {
            temp=z%10;
    if(0==temp)
        sum=sum+6;
    if(1==temp)
        sum=sum+2;
    if(2==temp)
        sum=sum+5;
    if(3==temp)
        sum=sum+5;
    if(4==temp)
        sum=sum+4;
    if(5==temp)
        sum=sum+5;
    if(6==temp)
        sum=sum+6;
    if(7==temp)
        sum=sum+3;
    if(8==temp)
        sum=sum+7;
    if(9==temp)
        sum=sum+6;
         z=z/10;
        }
        x++;
        }
    }
    else
    {
    if(0>=x&&0<=y)
        sum=sum+6;
    if(1>=x&&1<=y)
        sum=sum+2;
    if(2>=x&&2<=y)
        sum=sum+5;
    if(3>=x&&3<=y)
        sum=sum+5;
    if(4>=x&&4<=y)
        sum=sum+4;
    if(5>=x&&5<=y)
        sum=sum+5;
    if(6>=x&&6<=y)
        sum=sum+6;
    if(7>=x&&7<=y)
        sum=sum+3;
    if(8>=x&&8<=y)
        sum=sum+7;
    if(9>=x&&9<=y)
        sum=sum+6;
    }
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
int main()
{
    int x,z,y,sum=0,dif,i,temp;
    scanf("%d %d",&x,&y);
    if(x>9)
    {
        dif=y-x;
        for(i=0;i<=dif;i++)
        {
            z=x;
            while(z!=0)
            {
            temp=z%10;
    if(0==temp)
        sum=sum+6;
    if(1==temp)
        sum=sum+2;
    if(2==temp)
        sum=sum+5;
    if(3==temp)
        sum=sum+5;
    if(4==temp)
        sum=sum+4;
    if(5==temp)
        sum=sum+5;
    if(6==temp)
        sum=sum+6;
    if(7==temp)
        sum=sum+3;
    if(8==temp)
        sum=sum+7;
    if(9==temp)
        sum=sum+6;
         z=z/10;
        }
        x++;
        }
    }
    else
    {
    if(0>=x&&0<=y)
        sum=sum+6;
    if(1>=x&&1<=y)
        sum=sum+2;
    if(2>=x&&2<=y)
        sum=sum+5;
    if(3>=x&&3<=y)
        sum=sum+5;
    if(4>=x&&4<=y)
        sum=sum+4;
    if(5>=x&&5<=y)
        sum=sum+5;
    if(6>=x&&6<=y)
        sum=sum+6;
    if(7>=x&&7<=y)
        sum=sum+3;
    if(8>=x&&8<=y)
        sum=sum+7;
    if(9>=x&&9<=y)
        sum=sum+6;
    }
    printf("%d",sum);
    return 0;
}

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

//1〜nに含まれるcountの個数を求める
unsigned long long solve(unsigned long long n,int count,int base){
	unsigned long long r=0; //結果
	unsigned long long lower=0; //処理している桁より下の桁の合計
	unsigned long long digits=0,expbase=1;
	for(;n;digits++,expbase*=base,n/=base){
		unsigned long long d=digits*expbase/base; //0,1,20,300,4000,...
		unsigned long long current_digit=n%base;
		r+=current_digit*d;
		if(current_digit==count)r+=lower+1;
		if(current_digit>=count+1)r+=expbase;
		lower+=current_digit*expbase;
		if(count==0)r-=expbase;
	}
	return r;
}

int d[]={6,2,5,5,4,5,6,3,7,6};
int main(int argc,char **argv){
	int base=10;

	unsigned long long n,m,r=0;
	//%d is used due to lovely msvcrt.
	scanf("%d%d",&n,&m);
	int i=0;
	for(;i<10;i++)r+=d[i]*(solve(m,i,base)-solve(n-1,i,base));
	printf("%d\n",r);
}

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

int main()
{ int a,b,c=0,i,d,e;
printf("a= ");scanf("%d",&a);
printf("b= ");scanf("%d",&b);
for(i=a;i<=b;i++)
    {d=i;
    while (d!=0)
        {e=d%10; d=d/10;
    switch(e)
    { case 0: {c+=6; break;}
      case 1: {c+=2; break;}
      case 2: {c+=5; break;}
      case 3: {c+=5; break;}
      case 4: {c+=4; break;}
      case 5: {c+=5; break;}
      case 6: {c+=6; break;}
      case 7: {c+=3; break;}
      case 8: {c+=7; break;}
      case 9: {c+=6; break;}
    }}}

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

#include<stdio.h>
int a[]={6,2,5,5,4,5,6,3,7,6};
int cnt(int n)
{
    if(n==0)
        return;
    return a[n%10]+(n/10);
}
int main()
{
    int a,b;
    long long s=0;
    scanf("%d%d",&a,&b);
    for(int i=a;i<=b;i++)
    {
        int t=i;
        s+=cnt(t);
    }
    printf("%lld\n",s);
    return 0;
}

#include <stdio.h>
long long min(long long a, long long b){
    return a>b?b:a;
}
long long max(long long a, long long b){
    return a<b?b:a;
}
int cnt[]={6,2,5,5,4,5,6,3,0,6};
long long slv(long long n){
    long long s=0;
    while(n){
        s+=cnt[n%10];
        n/=10;
    }
    return s;
}
int main(){
    int a,b,i; long long ans=0;
    scanf("%d%d",&a,&b);
    for(i=a;i<=b;++i){
        ans+=slv(i);
    }
    printf("%lld\n",ans);
    return 0 ;
}

#include <stdio.h>
int ara[12];
long long visited[1000010];
int main()
{
    long long a,b,c,d,k,r,i;
     ara[0]=6;
     ara[1]=2;
     ara[2]=5;
     ara[3]=5;
     ara[4]=4;
    ara[5]=5;
    ara[6]=6;
    ara[7]=7;
    ara[8]=7;
    ara[9]=6;
    visited[0]=6;
    long long sum=6;
    for(i=1;i<=1000000;i++){
        a=i;
        while(a!=0){
            sum=sum+ara[a%10];
            a=a/10;
        }
      visited[i]=sum;
    }
  scanf("%I64d%I64d",&a,&b);
    printf("%I64d\n",visited[b]-visited[a-1]);
}

#include <stdio.h>

int segCalc(int number){
	if(number==4){
		return 4;
	}else if (number==1){
		return 2;
	}else if (number==2||number==5||number==3){
		return 5;
	}else if (number==6||number==0){
		return 6;
	}else if (number==7){
		return 3;
	}else if (number==8){
		return 8;
	}else if (number==9){
		return 7;
	}

}
long findSeg(long i){
	long seg;
	int temp;
	if(i/10==0){
		seg= segCalc(i);
		return seg;
	}
	else{
		temp=i%10;
		seg=segCalc(temp);

		return seg+findSeg(i/10);
	}

}
int main() {
	// your code goes here
	long a,b,sum=0,i;

	scanf("%ld %ld",&a,&b);
	for(i=a;i<=b;i++){

	sum+=	findSeg(i);

	}
	printf("%ld",sum);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int clock[10]={6,2,5,5,4,5,6,3,7,6};
    int sta,fin,ans;
    scanf("%d%d",&sta,&fin);
    for(int i=sta;i<=fin;i++)
    {
        int a=i;
        while(a/10>0)
        {
            ans+=clock[a%10];
            a/=10;
        }
        ans+=clock[a];
    }
    printf("%d\n",ans);
    return 0;
}

#include<stdio.h>
int a[]={6,2,5,5,4,5,6,3,7,6};
int cnt(int n)
{
    if(n==0)
        return;
    return (a[n%10]+cnt(n/10));
}
int main()
{
    int a,b;
    long long s=0;
    scanf("%d%d",&a,&b);
    for(int i=a;i<=b;i++)
    {
        int t=i;
        s+=cnt(t);
    }
    printf("%lld\n",s);
    return 0;
}

#include<stdio.h>
int a[]={6,2,5,5,4,5,6,3,7,6};
int cnt(int n)
{
    if(n==0)
        return;
    return a[n%10]+cnt(n/10);
}
int main()
{
    int a,b;
    long long s=0;
    scanf("%d%d",&a,&b);
    for(int i=a;i<=b;i++)
    {
        int t=i;
        s+=cnt(t);
    }
    printf("%lld\n",s);
    return 0;
}

#include<stdio.h>
int a[]={6,2,5,5,4,5,6,3,7,6};
int cnt(int n)
{
    int s=0;
    if(n==0)
        return;
    s=a[n%10]+cnt(n/10);
    return s;
}
int main()
{
    int a,b;
    long long s=0;
    scanf("%d%d",&a,&b);
    for(int i=a;i<=b;i++)
    {
        int t=i;
        s+=cnt(t);
    }
    printf("%lld\n",s);
    return 0;
}