Polycarpus analyzes a string called abracadabra. This string is constructed using the following algorithm:   On the first step the string consists of a single character "a".  On the k-th step Polycarpus concatenates two copies of the string obtained on the (k - 1)-th step, while inserting the k-th character of the alphabet between them. Polycarpus uses the alphabet that consists of lowercase Latin letters and digits (a total of 36 characters). The alphabet characters are numbered like this: the 1-st character is "a", the 2-nd — "b", ..., the 26-th — "z", the 27-th — "0", the 28-th — "1", ..., the 36-th — "9". Let's have a closer look at the algorithm. On the second step Polycarpus will concatenate two strings "a" and insert the character "b" between them, resulting in "aba" string. The third step will transform it into "abacaba", and the fourth one - into "abacabadabacaba". Thus, the string constructed on the k-th step will consist of 2k - 1 characters. Polycarpus wrote down the string he got after 30 steps of the given algorithm and chose two non-empty substrings of it. Your task is to find the length of the longest common substring of the two substrings selected by Polycarpus.A substring s[i... j] (1 ≤ i ≤ j ≤ |s|) of string s = s1s2... s|s| is a string sisi + 1... sj. For example, substring s[2...4] of string s = "abacaba" equals "bac". The string is its own substring.The longest common substring of two strings s and t is the longest string that is a substring of both s and t. For example, the longest common substring of "contest" and "systemtesting" is string "test". There can be several common substrings of maximum length.

The input consists of a single line containing four integers l1, r1, l2, r2 (1 ≤ li ≤ ri ≤ 109, i = 1, 2). The numbers are separated by single spaces. li and ri give the indices of the first and the last characters of the i-th chosen substring, correspondingly (i = 1, 2). The characters of string abracadabra are numbered starting from 1.

Print a single number — the length of the longest common substring of the given strings. If there are no common substrings, print 0.

NoteIn the first sample the first substring is "acab", the second one is "abac". These two substrings have two longest common substrings "ac" and "ab", but we are only interested in their length — 2.In the second sample the first substring is "a", the second one is "c". These two substrings don't have any common characters, so the length of their longest common substring is 0.

Uses math;
Var rez,l1,r1,l2,r2:longint;
procedure probeg(n,l1,r1,l2,r2:longint);
Var z:longint;
begin
  if l2>r2
  then exit;
  if l1>r1
  then exit;
  if n=0
  then exit;
  if (l2>=l1)and(r2<=r1)
  then begin rez:=max(rez,r2-l2+1); exit; end;
  if (l1>=l2)and(r1<=r2)
  then begin rez:=max(rez,r1-l1+1); exit; end;
  if (r1>=l2)and(r2>=r1)
  then rez:=max(rez,r1-l2+1);
  if (r2>=l1)and(r1>=r2)
  then rez:=max(rez,r2-l1+1);
  z:=1 shl n;
  if (r2<z div 2)and(r1<z div 2)
  then probeg(n-1,l1,r1,l2,r2)
  else if (l1>z div 2)and(l2>z div 2)
       then probeg(n-1,l1-z div 2,r1-z div 2,l2-z div 2,r2-z div 2)
       else if (l1>z div 2)and(r2<z div 2)
            then probeg(n-1,l1-z div 2,r1-z div 2,l2,r2)
            else if (l2>z div 2)and(r1<z div 2)
                 then probeg(n-1,l1,r1,l2-z div 2,r2-z div 2)
                 else
            if (l1<=z div 2)and(l2<=z div 2)and(r1>=z div 2)and(r2
            >=z div 2)
            then begin
                  probeg(n-1,l1,z div 2-1,l2,z div 2-1);
                  probeg(n-1,1,r1-z div 2,1,r2-z div 2);
                  probeg(n-1,l1,z div 2-1,1,r2-z div 2);
                  probeg(n-1,1,r1-z div 2,l2,z div 2-1);
                 end
            else if (l1<=z div 2)and(r1>=z div 2)
                 then begin
                        if r2<z div 2
                        then begin
                              probeg(n-1,l1,z div 2-1,l2,r2);
                              probeg(n-1,1,r1-z div 2,l2,r2);
                             end
                        else begin
                              probeg(n-1,l1,z div 2-1,l2-z div 2,r2-z div 2);
                              probeg(n-1,1,r1-z div 2,l2-z div 2,r2-z div 2);
                             end;
                      end
                 else begin
                        if r1<z div 2
                        then begin
                              probeg(n-1,l1,r1,l2,z div 2-1);
                              probeg(n-1,l1,r1,1,r2-z div 2);
                             end
                        else begin
                              probeg(n-1,l1-z div 2,r1-z div 2,l2,z div 2-1);
                              probeg(n-1,l1-z div 2,r1-z div 2,1,r2-z div 2);
                             end;
                      end;
end;
begin
//  Assign(input,'input.txt'); reset(input);
//  Assign(output,'output.txt'); rewrite(output);
  read(l1,r1,l2,r2);
  rez:=0;
  probeg(30,l1,r1,l2,r2);
  writeln(rez);
end.

{$R-,S-,Q-,I-,O+}
var
  l1,r1,l2,r2: longint;

function go(l1,r1,l2,r2:longint):longint;
var
  ans,cur,lg,rg,m1,m2,i: longint;
begin
  if (l1 > r1) or (l2 > r2) then
  begin
    go:=0;
    exit;
  end;
  for i:=29 downto 0 do
    if (l1 > 1 shl i) and (r1 < 1 shl (i+1)) then
    begin
      dec(l1,1 shl i);
      dec(r1,1 shl i);
    end;
  for i:=29 downto 0 do
    if (l2 > 1 shl i) and (r2 < 1 shl (i+1)) then
    begin
      dec(l2,1 shl i);
      dec(r2,1 shl i);
    end;
  if (l1 <= l2) and (r2 <= r1) then
  begin
    go:=r2-l2+1;
    exit;
  end;
  if (l2 <= l1) and (r1 <= r2) then
  begin
    go:=r1-l1+1;
    exit;
  end;
  m1:=1;
  while m1 shl 1 <= r1 do m1:=m1 shl 1;
  m2:=1;
  while m2 shl 1 <= r2 do m2:=m2 shl 1;
  if m1 = m2 then
  begin
    lg:=l1; rg:=r1;
    if l2 > lg then lg:=l2;
    if r2 < rg then rg:=r2;
    ans:=rg-lg+1;
    if (l1 < l2) and (r1 < r2) then
    begin
      cur:=go(l1,m1-1,m1+1,r2);
      if cur > ans then ans:=cur;
    end else
    if (l2 < l1) and (r2 < r1) then
    begin
      cur:=go(l2,m1-1,m1+1,r1);
      if cur > ans then ans:=cur;
    end;
    go:=ans;
  end else
  if m1 > m2 then
  begin
    ans:=go(l1,m1-1,l2,r2);
    cur:=go(m1+1,r1,l2,r2);
    if cur > ans then ans:=cur;
    go:=ans;
  end else
  begin
    ans:=go(l1,r1,l2,m2-1);
    cur:=go(l1,r1,m2+1,r2);
    if cur > ans then ans:=cur;
    go:=ans;
  end;
end;

begin
  read(l1,r1,l2,r2);
  writeln(go(l1,r1,l2,r2));
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:int64;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg,k:int64;
 var i,cntrl:longint;
 t,tmp:boolean;
 label 1;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
function maxim(a:int64;b:int64):int64;
begin
    If a>b then maxim:=a else maxim:=b;
end;
function krygovaya(summ:int64;n:int64;j:int64):int64;
var max,maxsumm1,summtmp,maxsumm2,kryg,s:int64;
var cntrl:integer;
begin
 summtmp:=summ;
 kryg:=0;
 summ:=summ-round(exp((n+1)*ln(2)));
 cntrl:=0;
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp((n+1)*ln(2)));
  If summ<l2 then summ:=summ+((round(l2)-summ) div round(exp((i+1)*ln(2))))*round(exp((i+1)*ln(2)));
//  If summ=round(exp(n*ln(2)))*j then j:=j*2 else begin
  If (summ>=l2) and (summ<=r2) then begin cntrl:=cntrl+1;max:=n;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end else If summ>r2 then summ:=maxim(round(r2),round(r1))+1;
   If cntrl=2 then summ:=maxim(round(r2),round(r1))+1;
                end;
 krygovaya:=kryg;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;

 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 maxkryg:=0;
 If min(x,y)=0 then k:=0 else k:=min(x,y)-1;
 for i:=k to 30 do begin
 summ:=round(exp(i*ln(2)))-round(exp((i+1)*ln(2)));
 j:=2;
 cntrl:=0;
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp((i+1)*ln(2)));
   If summ<l1 then summ:=summ+((round(l1)-summ) div round(exp((i+1)*ln(2))))*round(exp((i+1)*ln(2)));
 // If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin cntrl:=cntrl+1; If krygovaya(summ,i,j)>maxkryg then maxkryg:=krygovaya(summ,i,j) end else If summ>r1 then summ:=maxim(round(r2),round(r1))+1;
               If cntrl=2 then summ:=maxim(round(r2),round(r1))+1;
               end;
     //           end;

 end;

  If maxkryg>0 then writeln(maxkryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

uses math;
type pair = record
l:longint;
r:longint;
end;
var f1,f2:text;
a,b,l,r:longint;

function mp(u,v:longint):pair;begin mp.l:=u;mp.r:=v;end;

Function process(a,b,l,r:longint;k:longint):longint;
var i,j:longint;
vt:longint;
res:longint;
t1,t2:array[1..2] of pair;
begin
        if k=0 then exit(0);
        if (a>b) or (l>r) then exit(0);
        res:=0;
        if max(a,l)<=min(b,r) then res:=min(r,b)-max(a,l)+1;
        if ((a<=l) and (r<=b)) or ((l<=a) and (b<=r)) then exit(min(r,b)-max(a,l)+1);
        vt:=1 shl (k-1);
        if vt=a then inc(a);if vt=b then dec(b);if vt=l then inc(l);if vt=r then dec(r);
        t1[1]:=mp(a,min(b,vt-1));
        t1[2]:=mp(max(a,vt+1)-vt,b-vt);
        t2[1]:=mp(l,min(r,vt-1));
        t2[2]:=mp(max(l,vt+1)-vt,r-vt);
        for i:=1 to 2 do
        for j:=1 to 2 do
        res:=max(res,process(t1[i].l,t1[i].r,t2[j].l,t2[j].r,k-1));
        process:=res;
end;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(f2);
        readln(F1,a,b,l,r);
        writeln(f2,Process(a,b,l,r,30));
        close(f1);
        close(f2);
end.

uses math;
type pair = record
l:longint;
r:longint;
end;
var f1,f2:text;
a,b,l,r:longint;

function mp(u,v:longint):pair;
begin
        mp.l:=u;mp.r:=v;
end;

Function process(a,b,l,r:longint;k:longint):longint;
var i,j:longint;
vt:longint;
res:longint;
t1,t2:array[1..2] of pair;
begin
        if k=0 then exit(0);
        if (a>b) or (l>r) then exit(0);
        res:=0;
        if max(a,l)<=min(b,r) then res:=min(r,b)-max(a,l)+1;
        if ((a<=l) and (r<=b)) or ((l<=a) and (b<=r)) then exit(res);
        vt:=1 shl (k-1);
        if vt=a then inc(a);
        if vt=b then dec(b);
        if vt=l then inc(l);
        if vt=r then dec(r);
        t1[1]:=mp(a,min(b,vt-1));
        t1[2]:=mp(max(a,vt+1)-vt,b-vt);
        t2[1]:=mp(l,min(r,vt-1));
        t2[2]:=mp(max(l,vt+1)-vt,r-vt);
        for i:=1 to 2 do
        for j:=1 to 2 do
        res:=max(res,process(t1[i].l,t1[i].r,t2[j].l,t2[j].r,k-1));
        process:=res;
end;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(f2);
        readln(F1,a,b,l,r);
        writeln(f2,Process(a,b,l,r,30));
        close(f1);
        close(f2);
end.

var
ans:longint;

function min(x,y:longint):longint; begin if x<y then exit(x) else exit(y); end;
function max(x,y:longint):longint; begin if x>y then exit(x) else exit(y); end;
procedure update(var x:longint; const y:longint); begin if y>x then x:=y; end;

procedure dfs(l,r,l1,r1,l2,r2:longint);
var mid,midlen:longint; flag:boolean;
begin if l1=l2 then
	begin update(ans,min(r1,r2)-l1+1);
		exit;
	end;
	if r1=r2 then
	begin update(ans,r1-max(l1,l2)+1);
		exit;
	end;

	mid:=(l+r)>>1; midlen:=(r-l)>>1+1; flag:=false;
	if (l1<=mid)and(mid<=r1)and(l2<=mid)and(mid<=r2) then begin update(ans,min(r1,r2)-max(l1,l2)+1); flag:=true; end;
	if l1<mid then
	begin if (l2<mid) then dfs(l,mid-1,l1,min(mid-1,r1),l2,min(mid-1,r2));
		if r2>mid then dfs(l,mid-1,l1,min(mid-1,r1),max(mid+1,l2)-midlen,r2-midlen);
	end;
	if r1>mid then
	begin if l2<mid then dfs(mid+1,r,max(mid+1,l1),r1,l2+midlen,min(mid-1,r2)+midlen);
		if (r2>mid) then dfs(mid+1,r,max(mid+1,l1),r1,max(mid+1,l2),r2);
	end;
end;

procedure lemon;
var l1,r1,l2,r2:longint;
begin readln(l1,r1,l2,r2);
	ans:=0;
	dfs(1,1<<30-1,l1,r1,l2,r2);
	writeln(ans);
end;

begin
lemon;
end.

var
ans:longint;

function min(x,y:longint):longint; begin if x<y then exit(x) else exit(y); end;
function max(x,y:longint):longint; begin if x>y then exit(x) else exit(y); end;
procedure update(var x:longint; const y:longint); begin if y>x then x:=y; end;

procedure dfs(l,r,l1,r1,l2,r2:longint);
var mid,midlen:longint; flag:boolean;
begin if l1=l2 then
	begin update(ans,min(r1,r2)-l1+1);
		exit;
	end;
	if r1=r2 then
	begin update(ans,r1-max(l1,l2)+1);
		exit;
	end;

	mid:=(l+r)>>1; midlen:=(r-l)>>1+1; flag:=false;
	if (l1<=mid)and(mid<=r1)and(l2<=mid)and(mid<=r2) then begin update(ans,min(r1,r2)-max(l1,l2)+1); flag:=true; end;
	if l1<mid then
	begin if (l2<mid)and(not flag) then dfs(l,mid-1,l1,min(mid-1,r1),l2,min(mid-1,r2));
		if r2>mid then dfs(l,mid-1,l1,min(mid-1,r1),max(mid+1,l2)-midlen,r2-midlen);
	end;
	if r1>mid then
	begin if l2<mid then dfs(mid+1,r,max(mid+1,l1),r1,l2+midlen,min(mid-1,r2)+midlen);
		if (r2>mid)and(not flag) then dfs(mid+1,r,max(mid+1,l1),r1,max(mid+1,l2),r2);
	end;
end;

procedure lemon;
var l1,r1,l2,r2:longint;
begin readln(l1,r1,l2,r2);
	ans:=0;
	dfs(1,1<<30-1,l1,r1,l2,r2);
	writeln(ans);
end;

begin
lemon;
end.

type z=longint;
var x,y,l,r:z;
function o(a,b:z):z;
begin if a>b then o:=a else o:=b end;
function d(x,y,l,r,k:z):z;
var m:z;
begin
  m:=1 shl k;
  if (l>r)or(x>y) then exit(0);
  if (l<x)or(l=x)and(r>y) then exit(d(l,r,x,y,k));
  if y>=r then exit(r-l+1);
  if l>m then exit(d(x,y,l-m,r-m,k));
  if r<m then exit(d(x,y,l,r,k-1));
  exit(o(o(d(x,y,l,m-1,k),d(1,r-m,x,y,k)),y-l+1));
end;
begin
  read(x,y,l,r);
  write(d(x,y,l,r,30));
end.

Program vkr1pc;
Var l1,r1,l2,r2:longint;
    ans:longint;
procedure upd(x:longint);
begin
  if x>ans then ans:=x;
end;
function min(a,b:longint):longint;
begin
  if a<b then exit(a) else exit(b);
end;
function max(a,b:longint):longint;
begin
  if a>b then exit(a) else exit(b);
end;
procedure solve(s,l1,r1,l2,r2:longint);
var f1,f2:boolean;
    tmp,g1,g2:longint;
begin
  if (l1>r1) or (l2>r2) then exit;
  upd(min(r1,r2)-max(l1,l2)+1);
  if (l1<=l2) and (r2<=r1) or (l2<=l1) and (r1<=r2) then exit;
  tmp:=1 shl s;
  f1:=(l1<=tmp) and (tmp<=r1);
  f2:=(l2<=tmp) and (tmp<=r2);
  if (not f1) and (not f2) then
    solve(s-1,l1 mod tmp,r1 mod tmp,l2 mod tmp,r2 mod tmp);
  if f1 and (not f2) then
    begin
    solve(s-1,l1,tmp-1,l2 mod tmp,r2 mod tmp);
    solve(s-1,1,r1-tmp,l2 mod tmp,r2 mod tmp);
    end;
  if (not f1) and f2 then
    begin
    solve(s-1,l1 mod tmp,r1 mod tmp,l2,tmp-1);
    solve(s-1,l1 mod tmp,r1 mod tmp,1,r2-tmp);
    end;
  if f1 and f2 then
    begin
    solve(s-1,l1,tmp-1,1,r2-tmp);
    solve(s-1,1,r1-tmp,l2,tmp-1);
    end;
end;
begin
  readln(l1,r1,l2,r2);
  solve(29,l1,r1,l2,r2);
  writeln(ans);
end.
    end;

program cf161c;
var
  x,y,l,r:longint;
function max(a,b:longint):longint;
begin if a>b then max:=a else max:=b end;
function deal(x,y,l,r,k:longint):longint;
var m:longint;
begin
  m:=1 shl k;
  if (l>r)or(x>y) then exit(0);
  if (l<x)or(l=x)and(r>y) then exit(deal(l,r,x,y,k));
  if y>=r then exit(r-l+1);
  if l>m then exit(deal(x,y,l-m,r-m,k));
  if r<m then exit(deal(x,y,l,r,k-1));
  exit(max(max(deal(x,y,l,m-1,k),deal(1,r-m,x,y,k)),y-l+1));
end;

begin
  readln(x,y,l,r);
  writeln(deal(x,y,l,r,30));
end.

var
  x,y,l,r:longint;
function max(a,b:longint):longint;
begin if a>b then max:=a else max:=b end;
function deal(x,y,l,r,k:longint):longint;
var m:longint;
begin
  m:=1 shl k;
  if (l>r)or(x>y) then exit(0);
  if (l<x)or(l=x)and(r>y) then exit(deal(l,r,x,y,k));
  if y>=r then exit(r-l+1);
  if l>m then exit(deal(x,y,l-m,r-m,k));
  if r<m then exit(deal(x,y,l,r,k-1));
  exit(max(max(deal(x,y,l,m-1,k),deal(1,r-m,x,y,k)),y-l+1));
end;
begin
  read(x,y,l,r);
  write(deal(x,y,l,r,30));
end.

var l1,r1,l2,r2,ans:longint;

procedure swap(var a,b:longint);
  var r:longint;
  begin
    r:=a;
    a:=b;
    b:=r;
  end;

function max(a,b:longint):longint;
  begin
    if a>b then exit(a) else exit(b);
  end;

function min(a,b:longint):longint;
  begin
    if a<b then exit(a) else exit(b);
  end;

procedure doit(l1,r1,l2,r2,len:longint);
  var e,mid:longint;
  begin
    if (r1-l1+1<=ans) or (r2-l2+1<=ans) then exit;
    if (l1>l2) or ((l1=l2) and (r1>r2)) then
      begin
        swap(l1,l2);
        swap(r1,r2);
      end;
    //writeln(l1,' ',r1,' ',l2,' ',r2,' ',ans);
    e:=min(r1,r2)-max(l1,l2)+1;
    if e>ans then ans:=e;
    mid:=(len+1)>>1;
    if (l2<=mid) and (mid<=r1) then
      doit(1,r2-mid,l1,mid-1,len div 2)
    else
      if r2<mid then
        doit(l1,r1,l2,r2,len div 2)
      else
        if l1>mid then
          doit(l1-mid,r1-mid,l2-mid,r2-mid,len div 2)
        else
          if l2<=mid then
            begin
              doit(l1,r1,l2,mid-1,len div 2);
              doit(l1,r1,1,r2-mid,len div 2);
            end
          else
            if r1>=mid then
              begin
                doit(l1,mid-1,l2-mid,r2-mid,len div 2);
                doit(1,r1-mid,l2-mid,r2-mid,len div 2);
              end
            else
              doit(l1,r1,l2-mid,r2-mid,len div 2);
  end;

begin
  readln(l1,r1,l2,r2);
  if (l1>l2) or ((l1=l2) and (r1>r2)) then
    begin
      swap(l1,l2);
      swap(r1,r2);
    end;
  ans:=0;
  doit(l1,r1,l2,r2,1<<30-1);
  writeln(ans);
end.

uses
  math;
var
  l1,r1,l2,r2,ans:longint;

  procedure solve(x,l1,r1,l2,r2:longint);
    var
      cr,t:longint;
    begin
      if (l1>=l2)and(r1<=r2)then begin
        cr:=r1-l1+1;
        if (cr>ans)then ans:=cr;
        exit;
      end;
      if (l2>=l1)and(r2<=r1)then begin
        cr:=r2-l2+1;
        if (cr>ans)then ans:=cr;
        exit;
      end;
      if (x=0)then exit;
      t:=1 shl (x-1);
      if (l1<=t)and(l2<=t)and(r1>=t)and(r2>=t)then begin
        cr:=min(r1,r2)-max(l1,l2)+1;
        if (cr>ans)then ans:=cr;
      end;
      if (l1<t)and(l2<t)then solve(x-1,l1,min(t-1,r1),l2,min(r2,t-1));
      if (r1>t)and(r2>t)then solve(x-1,max(l1,t+1)-t,r1-t,max(l2,t+1)-t,r2-t);
      if (l1<t)and(r2>t)then solve(x-1,l1,min(t-1,r1),max(t+1,l2)-t,r2-t);
      if (r1>t)and(l2<t)then solve(x-1,max(l1,t+1)-t,r1-t,l2,min(r2,t-1));
    end;

begin
  read(l1,r1,l2,r2);
  ans:=0;
  solve(30,l1,r1,l2,r2);
  writeln(ans);
end.

uses math;
type pair = record
l:longint;
r:longint;
end;
var f1,f2:text;
a,b,l,r:longint;

function mp(u,v:longint):pair;begin mp.l:=u;mp.r:=v;end;

Function process(a,b,l,r:longint;k:longint):longint;
var i,j:longint;
vt:longint;
res:longint;
t1,t2:array[1..2] of pair;
begin
        if k=0 then exit(0);
        if (a>b) or (l>r) then exit(0);
        res:=0;
        if max(a,l)<=min(b,r) then res:=min(r,b)-max(a,l)+1;
        if ((a<=l) and (r<=b)) or ((l<=a) and (b<=r)) then exit(res);
        vt:=1 shl (k-1);
        if vt=a then inc(a);if vt=b then dec(b);if vt=l then inc(l);if vt=r then dec(r);
        t1[1]:=mp(a,min(b,vt-1));
        t1[2]:=mp(max(a,vt+1)-vt,b-vt);
        t2[1]:=mp(l,min(r,vt-1));
        t2[2]:=mp(max(l,vt+1)-vt,r-vt);
        for i:=1 to 2 do
        for j:=1 to 2 do
        res:=max(res,process(t1[i].l,t1[i].r,t2[j].l,t2[j].r,k-1));
        process:=res;
end;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(f2);
        readln(F1,a,b,l,r);
        writeln(f2,Process(a,b,l,r,30));
        close(f1);
        close(f2);
end.

Uses math;
Var rez,l1,r1,l2,r2:longint;
procedure probeg(n,l1,r1,l2,r2:longint);
Var z:longint;
begin
  if l2>r2
  then exit;
  if l1>r1
  then exit;
  if n=0
  then exit;
  if (l2>=l1)and(r2<=r1)
  then begin rez:=max(rez,r2-l2+1); exit; end;
  if (l1>=l2)and(r1<=r2)
  then begin rez:=max(rez,r1-l1+1); exit; end;
  if (r1>=l2)and(r2>=r1)
  then rez:=max(rez,r1-l2+1);
  if (r2>=l1)and(r1>=r2)
  then rez:=max(rez,r2-l1+1);
  z:=1 shl n;
  if (r2<z div 2)and(r1<z div 2)
  then probeg(n-1,l1,r1,l2,r2)
  else if (l1>z div 2)and(l2>z div 2)
       then probeg(n-1,l1-z div 2,r1-z div 2,l2-z div 2,r2-z div 2)
       else if (l1<=z div 2)and(l2<=z div 2)and(r1>=z div 2)and(r1>=z div 2)
            then begin
                  probeg(n-1,l1,z div 2-1,l2,z div 2-1);
                  probeg(n-1,1,r1-z div 2,1,r2-z div 2);
                  probeg(n-1,l1,z div 2-1,1,r2-z div 2);
                  probeg(n-1,1,r1-z div 2,l2,z div 2-1);
                 end
            else if (l1<=z div 2)and(r1>=z div 2)
                 then begin
                        if r2<z div 2
                        then begin
                              probeg(n-1,l1,z div 2-1,l2,r2);
                              probeg(n-1,1,r1-z div 2,l2,r2);
                             end
                        else begin
                              probeg(n-1,l1,z div 2-1,l2-z div 2,r2-z div 2);
                              probeg(n-1,1,r1-z div 2,l2-z div 2,r2-z div 2);
                             end;
                      end
                 else begin
                        if r1<z div 2
                        then begin
                              probeg(n-1,l1,r1,l2,z div 2-1);
                              probeg(n-1,l1,r1,1,r2-z div 2);
                             end
                        else begin
                              probeg(n-1,l1-z div 2,r1-z div 2,l2,z div 2-1);
                              probeg(n-1,l1-z div 2,r1-z div 2,1,r2-z div 2);
                             end;
                      end;
end;
begin
//  Assign(input,'input.txt'); reset(input);
//  Assign(output,'output.txt'); rewrite(output);
  read(l1,r1,l2,r2);
  rez:=0;
  probeg(30,l1,r1,l2,r2);
  writeln(rez);
end.

Uses math;
Var rez,l1,r1,l2,r2:longint;
procedure probeg(n,l1,r1,l2,r2:longint);
Var z:longint;
begin
  if l2>r2
  then exit;
  if l1>r1
  then exit;
  if n=0
  then exit;
  if (l2>=l1)and(r2<=r1)
  then begin rez:=max(rez,r2-l2+1); exit; end;
  if (l1>=l2)and(r1<=r2)
  then begin rez:=max(rez,r1-l1+1); exit; end;
  if (r1>=l2)and(r2>=r1)
  then rez:=max(rez,r1-l2+1);
  if (r2>=l1)and(r1>=r2)
  then rez:=max(rez,r2-l1+1);
  z:=1 shl n;
  if (r2<z div 2)and(r1<z div 2)
  then probeg(n-1,l1,r1,l2,r2)
  else if (l1>z div 2)and(l2>z div 2)
       then probeg(n-1,l1-z div 2,r1-z div 2,l2-z div 2,r2-z div 2)
       else if (l1<=z div 2)and(l2<=z div 2)and(r1>=z div 2)and(r1>=z div 2)
            then begin
                  probeg(n-1,l1,z div 2-1,l2,z div 2-1);
                  probeg(n-1,1,r1-z div 2,1,r2-z div 2);
                 end
            else if (l1<=z div 2)and(r1>=z div 2)
                 then begin
                        if r2<z div 2
                        then begin
                              probeg(n-1,l1,z div 2-1,l2,r2);
                              probeg(n-1,1,r1-z div 2,l2,r2);
                             end
                        else begin
                              probeg(n-1,l1,z div 2-1,l2-z div 2,r2-z div 2);
                              probeg(n-1,1,r1-z div 2,l2-z div 2,r2-z div 2);
                             end;
                      end
                 else begin
                        if r1<z div 2
                        then begin
                              probeg(n-1,l1,r1,l2,z div 2-1);
                              probeg(n-1,l1,r1,1,r2-z div 2);
                             end
                        else begin
                              probeg(n-1,l1-z div 2,r1-z div 2,l2,z div 2-1);
                              probeg(n-1,l1-z div 2,r1-z div 2,1,r2-z div 2);
                             end;
                      end;
end;
begin
//  Assign(input,'input.txt'); reset(input);
//  Assign(output,'output.txt'); rewrite(output);
  read(l1,r1,l2,r2);
  rez:=0;
  probeg(30,l1,r1,l2,r2);
  writeln(rez);
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2:real;
 var a,b,c,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);
 a:=trunc(ln(l1)/ln(2));
 b:=trunc(ln(r1)/ln(2));
 //c:=trunc(ln(l2)/ln(2));
 //d:=trunc(ln(r2)/ln(2));
 //If a>b then x:=a else If a=b then x:=trunc(ln(r1-l1)/ln(2)) else x:=b;
 //If c>d then y:=c else If c=d then y:=trunc(ln(r2-l2)/ln(2)) else y:=d;
 i:=0;
 j:=0;
 x:=0;y:=0;
 If l1<>r1 then x:=trunc(ln(r1-l1+1)/ln(2));
 If l2<>r2 then y:=trunc(ln(r2-l2+1)/ln(2));
 for i:=min(x,y) to 30 do begin
 summ:=0;
 t:=false;
 j:=2;
 while (summ<=r2)  do begin
  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (not t) and (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
   s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 for i:=min(x,y) to min(x,y)+1 do begin
 summ:=0;
 t:=false;
 j:=2;
 kryg:=0;
 while (summ<=r2)  do begin

  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ; end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
  // s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2:real;
 var a,b,c,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);
 a:=trunc(ln(l1)/ln(2));
 b:=trunc(ln(r1)/ln(2));
 //c:=trunc(ln(l2)/ln(2));
 //d:=trunc(ln(r2)/ln(2));
 //If a>b then x:=a else If a=b then x:=trunc(ln(r1-l1)/ln(2)) else x:=b;
 //If c>d then y:=c else If c=d then y:=trunc(ln(r2-l2)/ln(2)) else y:=d;
 i:=0;
 j:=0;
 If l1<>r1 then x:=trunc(ln(r1-l1)/ln(2));
 If l2<>r2 then y:=trunc(ln(r2-l2)/ln(2));
 for i:=min(round(x),round(y)) to 30 do begin
 summ:=0;
 t:=false;
 j:=2;
 while (summ<=r2)  do begin
  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (not t) and (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
   s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm2),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2:real;
 var a,b,c,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);
 a:=trunc(ln(l1)/ln(2));
 b:=trunc(ln(r1)/ln(2));
 //c:=trunc(ln(l2)/ln(2));
 //d:=trunc(ln(r2)/ln(2));
 //If a>b then x:=a else If a=b then x:=trunc(ln(r1-l1)/ln(2)) else x:=b;
 //If c>d then y:=c else If c=d then y:=trunc(ln(r2-l2)/ln(2)) else y:=d;
 i:=0;
 j:=0;
 If l1<>r1 then x:=trunc(ln(r1-l1)/ln(2));
 If l2<>r2 then y:=trunc(ln(r2-l2)/ln(2));
 for i:=min(round(x),round(y)) to 30 do begin
 summ:=0;
 t:=false;
 j:=2;
 while (summ<=r2)  do begin
  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (not t) and (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
   s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2:real;
 var a,b,c,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);
 a:=trunc(ln(l1)/ln(2));
 b:=trunc(ln(r1)/ln(2));
 //c:=trunc(ln(l2)/ln(2));
 //d:=trunc(ln(r2)/ln(2));
 //If a>b then x:=a else If a=b then x:=trunc(ln(r1-l1)/ln(2)) else x:=b;
 //If c>d then y:=c else If c=d then y:=trunc(ln(r2-l2)/ln(2)) else y:=d;
 i:=0;
 j:=0;
 x:=0;y:=0;
 If l1<>r1 then x:=trunc(ln(r1-l1)/ln(2));
 If l2<>r2 then y:=trunc(ln(r2-l2)/ln(2));
 for i:=min(x,y) to 30 do begin
 summ:=0;
 t:=false;
 j:=2;
 while (summ<=r2)  do begin
  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (not t) and (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
   s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 for i:=min(x,y) to min(x,y)+1 do begin
 summ:=0;
 t:=false;
 j:=2;
 while (summ<=r2)  do begin

  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (not t) and (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;summ:=round(r2)+2; end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
   s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:int64;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg,k:int64;
 var i:longint;
 t,tmp:boolean;
 label 1;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
function maxim(a:int64;b:int64):int64;
begin
    If a>b then maxim:=a else maxim:=b;
end;
function krygovaya(summ:int64;n:int64;j:int64):int64;
var max,maxsumm1,summtmp,maxsumm2,kryg,s:int64;
begin
 summtmp:=summ;
 kryg:=0;
 summ:=summ-round(exp((n+1)*ln(2)));

 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp((n+1)*ln(2)));

//  If summ=round(exp(n*ln(2)))*j then j:=j*2 else begin
  If (summ>=l2) and (summ<=r2) then begin max:=n;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end else If summ>r2 then summ:=maxim(round(r2),round(r1))+1;
   //            end;
                end;
 krygovaya:=kryg;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 maxkryg:=0;
 If min(x,y)=0 then k:=0 else k:=min(x,y)-1;
 for i:=k to 30 do begin
 summ:=round(exp(i*ln(2)))-round(exp((i+1)*ln(2)));
 j:=2;
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp((i+1)*ln(2)));
   If summ<l1 then summ:=summ+(round(l1)-summ div round(exp((i+1)*ln(2))))*round(exp((i+1)*ln(2)));
 // If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin If krygovaya(summ,i,j)>maxkryg then maxkryg:=krygovaya(summ,i,j) end else If summ>r1 then summ:=maxim(round(r2),round(r1))+1;
               end;
     //           end;

 end;

  If maxkryg>0 then writeln(maxkryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg:int64;
 var i:longint;
 t,tmp:boolean;
 label 1;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
function maxim(a:int64;b:int64):int64;
begin
    If a>b then maxim:=a else maxim:=b;
end;
function krygovaya(summ:int64;n:int64;j:int64):int64;
var max,maxsumm1,summtmp,maxsumm2,kryg,s:int64;
begin
 summtmp:=summ;
 kryg:=0;
 summ:=summ-round(exp(n*ln(2)));
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp(n*ln(2)));
  If summ=round(exp(n*ln(2)))*j then j:=j*2 else begin
 // If (summ>=l1) and (summ<=r1) then krygovaya(summ,i);// begin t:=true;summtmp:=summ; end;
  If (summ>=l2) and (summ<=r2) then begin max:=n;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
 krygovaya:=kryg;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 maxkryg:=0;
 for i:=min(x,y) to min(x,y)+1 do begin
 summ:=0;
 t:=false;
 j:=2;

 while (summ<=maxim(round(r2),round(r1)))  do begin

  summ:=summ+round(exp(i*ln(2)));
 1:
  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin If krygovaya(summ,i,j)>maxkryg then maxkryg:=krygovaya(summ,i,j) end else If summ>r1 then summ:=maxim(round(r2),round(r1))+1// begin t:=true;summtmp:=summ; end;
  //If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
        // If tmp then begin summ:=summtmp;goto 1 end;
 end; //writeln(max,maxsumm1,maxsumm2);
  // s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If maxkryg>0 then writeln(maxkryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2:real;
 var a,b,c,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);

 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 for i:=0 to min(x,y) do begin
 summ:=0;
 t:=false;
 j:=2;
 while (summ<=r2)  do begin
  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (not t) and (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
   s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2:real;
 var a,b,c,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);
 a:=trunc(ln(l1)/ln(2));
 b:=trunc(ln(r1)/ln(2));
 //c:=trunc(ln(l2)/ln(2));
 //d:=trunc(ln(r2)/ln(2));
 //If a>b then x:=a else If a=b then x:=trunc(ln(r1-l1)/ln(2)) else x:=b;
 //If c>d then y:=c else If c=d then y:=trunc(ln(r2-l2)/ln(2)) else y:=d;
 i:=0;
 j:=0;
 If l1<>r1 then x:=trunc(ln(r1-l1)/ln(2));
 for i:=x to 30 do begin
 summ:=0;
 t:=false;
 j:=2;
 while (summ<=r2)  do begin
  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (not t) and (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp end;
               end;   end;

 end;
   s:=min(min(round(exp(max*ln(2))),maxsumm1-round(l1)),min(round(exp(max*ln(2))),round(r1)-maxsumm1))+min(min(round(exp(max*ln(2))),maxsumm2-round(l2)),min(round(exp(max*ln(2))),round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:int64;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg,k:int64;
 var i,cntrl:longint;
 t,tmp:boolean;
 label 1;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
function maxim(a:int64;b:int64):int64;
begin
    If a>b then maxim:=a else maxim:=b;
end;
function krygovaya(summ:int64;n:int64;j:int64):int64;
var max,maxsumm1,summtmp,maxsumm2,kryg,s:int64;
var cntrl:integer;
begin
 summtmp:=summ;
 kryg:=0;
 summ:=summ-round(exp((n+1)*ln(2)));
 cntrl:=0;
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp((n+1)*ln(2)));
  If summ<l2 then summ:=summ+((round(l2)-summ) div round(exp((i+1)*ln(2))))*round(exp((i+1)*ln(2)));
//  If summ=round(exp(n*ln(2)))*j then j:=j*2 else begin
  If (summ>=l2) and (summ<=r2) then begin cntrl:=cntrl+1;max:=n;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end else If summ>r2 then summ:=maxim(round(r2),round(r1))+1;
   If cntrl=2 then summ:=maxim(round(r2),round(r1))+1;
                end;
 krygovaya:=kryg;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 cntrl:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 maxkryg:=0;
 If min(x,y)=0 then k:=0 else k:=min(x,y)-1;
 for i:=k to 30 do begin
 summ:=round(exp(i*ln(2)))-round(exp((i+1)*ln(2)));
 j:=2;
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp((i+1)*ln(2)));
   If summ<l1 then summ:=summ+((round(l1)-summ) div round(exp((i+1)*ln(2))))*round(exp((i+1)*ln(2)));
 // If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin cntrl:=cntrl+1; If krygovaya(summ,i,j)>maxkryg then maxkryg:=krygovaya(summ,i,j) end else If summ>r1 then summ:=maxim(round(r2),round(r1))+1;
               If cntrl=2 then summ:=maxim(round(r2),round(r1))+1;
               end;
     //           end;

 end;

  If maxkryg>0 then writeln(maxkryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg:int64;
 var i:longint;
 t,tmp:boolean;
 label 1;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
function maxim(a:int64;b:int64):int64;
begin
    If a>b then maxim:=a else maxim:=b;
end;
function krygovaya(summ:int64;n:int64;j:int64):int64;
var max,maxsumm1,summtmp,maxsumm2,kryg,s:int64;
begin
 summtmp:=summ;
 kryg:=0;
 summ:=summ-round(exp(n*ln(2)));
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp(n*ln(2)));
  If summ=round(exp(n*ln(2)))*j then j:=j*2 else begin
 // If (summ>=l1) and (summ<=r1) then krygovaya(summ,i);// begin t:=true;summtmp:=summ; end;
  If (summ>=l2) and (summ<=r2) then begin max:=n;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
 krygovaya:=kryg;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 maxkryg:=0;
 for i:=min(x,y) to 30 do begin
 summ:=0;
 t:=false;
 j:=2;

 while (summ<=maxim(round(r2),round(r1)))  do begin

  summ:=summ+round(exp(i*ln(2)));
 1:
  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin If krygovaya(summ,i,j)>maxkryg then maxkryg:=krygovaya(summ,i,j) end else If summ>r1 then summ:=maxim(round(r2),round(r1))+1// begin t:=true;summtmp:=summ; end;
  //If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
        // If tmp then begin summ:=summtmp;goto 1 end;
 end; //writeln(max,maxsumm1,maxsumm2);
  // s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If maxkryg>0 then writeln(maxkryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg:int64;
 var i:longint;
 t,tmp:boolean;
 label 1;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
function maxim(a:int64;b:int64):int64;
begin
    If a>b then maxim:=a else maxim:=b;
end;
function krygovaya(summ:int64;n:int64;j:int64):int64;
var max,maxsumm1,summtmp,maxsumm2,kryg,s:int64;
begin
 summtmp:=summ;
 kryg:=0;
 summ:=summ-round(exp(n*ln(2)));
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp(n*ln(2)));
  If summ=round(exp(n*ln(2)))*j then j:=j*2 else begin
 // If (summ>=l1) and (summ<=r1) then krygovaya(summ,i);// begin t:=true;summtmp:=summ; end;
  If (summ>=l2) and (summ<=r2) then begin max:=n;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
 krygovaya:=kryg;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 maxkryg:=0;
 for i:=min(x,y) to maxim(x,y) do begin
 summ:=0;
 t:=false;
 j:=2;

 while (summ<=maxim(round(r2),round(r1)))  do begin

  summ:=summ+round(exp(i*ln(2)));
 1:
  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin If krygovaya(summ,i,j)>maxkryg then maxkryg:=krygovaya(summ,i,j) end else If summ>r1 then summ:=maxim(round(r2),round(r1))+1// begin t:=true;summtmp:=summ; end;
  //If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
        // If tmp then begin summ:=summtmp;goto 1 end;
 end; //writeln(max,maxsumm1,maxsumm2);
  // s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If maxkryg>0 then writeln(maxkryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:int64;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg,k:int64;
 var i:longint;
 t,tmp:boolean;
 label 1;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
function maxim(a:int64;b:int64):int64;
begin
    If a>b then maxim:=a else maxim:=b;
end;
function krygovaya(summ:int64;n:int64;j:int64):int64;
var max,maxsumm1,summtmp,maxsumm2,kryg,s:int64;
begin
 summtmp:=summ;
 kryg:=0;
 summ:=summ-round(exp((n+1)*ln(2)));

 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp((n+1)*ln(2)));

//  If summ=round(exp(n*ln(2)))*j then j:=j*2 else begin
  If (summ>=l2) and (summ<=r2) then begin max:=n;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end else If summ>r2 then summ:=maxim(round(r2),round(r1))+1;
   //            end;
                end;
 krygovaya:=kryg;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 maxkryg:=0;
 If min(x,y)=0 then k:=0 else k:=min(x,y)-1;
 for i:=k to 30 do begin
 summ:=round(exp(i*ln(2)))-round(exp((i+1)*ln(2)));
 j:=2;
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp((i+1)*ln(2)));
   If summ<l1 then summ:=(round(l1)-summ div round(exp((i+1)*ln(2))))*round(exp((i+1)*ln(2)));
 // If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin If krygovaya(summ,i,j)>maxkryg then maxkryg:=krygovaya(summ,i,j) end else If summ>r1 then summ:=maxim(round(r2),round(r1))+1;
               end;
     //           end;

 end;

  If maxkryg>0 then writeln(maxkryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 for i:=min(x,y) to min(x,y)+1 do begin
 summ:=0;
 t:=false;
 j:=2;

 while (summ<=r2)  do begin

  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ; end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
  // s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If kryg>0 then writeln(kryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2:real;
 var a,b,c,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);

 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 for i:=min(x,y) to min(x,y)+1 do begin
 summ:=0;
 t:=false;
 j:=2;
 while (summ<=r2)  do begin

  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (not t) and (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;summ:=round(r2)+2; end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
   s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2:real;
 var a,b,c,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);
 a:=trunc(ln(l1)/ln(2));
 b:=trunc(ln(r1)/ln(2));
 //c:=trunc(ln(l2)/ln(2));
 //d:=trunc(ln(r2)/ln(2));
 //If a>b then x:=a else If a=b then x:=trunc(ln(r1-l1)/ln(2)) else x:=b;
 //If c>d then y:=c else If c=d then y:=trunc(ln(r2-l2)/ln(2)) else y:=d;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 for i:=min(x,y) to 30 do begin
 summ:=0;
 t:=false;
 j:=2;
 while (summ<=r2)  do begin
  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (not t) and (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
   s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg:int64;
 var i:longint;
 t,tmp:boolean;
 label 1;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
function maxim(a:int64;b:int64):int64;
begin
    If a>b then maxim:=a else maxim:=b;
end;
function krygovaya(summ:int64;n:int64;j:int64):int64;
var max,maxsumm1,summtmp,maxsumm2,kryg,s:int64;
begin
 summtmp:=summ;
 kryg:=0;
 summ:=summ-round(exp(n*ln(2)));
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp(n*ln(2)));
  If summ=round(exp(n*ln(2)))*j then j:=j*2 else begin
 // If (summ>=l1) and (summ<=r1) then krygovaya(summ,i);// begin t:=true;summtmp:=summ; end;
  If (summ>=l2) and (summ<=r2) then begin max:=n;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
 krygovaya:=kryg;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 maxkryg:=0;
 for i:=min(x,y) to maxim(x,y)+1 do begin
 summ:=0;
 t:=false;
 j:=2;

 while (summ<=maxim(round(r2),round(r1)))  do begin

  summ:=summ+round(exp(i*ln(2)));
 1:
  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin If krygovaya(summ,i,j)>maxkryg then maxkryg:=krygovaya(summ,i,j) end else If summ>r1 then summ:=maxim(round(r2),round(r1))+1// begin t:=true;summtmp:=summ; end;
  //If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
        // If tmp then begin summ:=summtmp;goto 1 end;
 end; //writeln(max,maxsumm1,maxsumm2);
  // s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If maxkryg>0 then writeln(maxkryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg:int64;
 var i:longint;
 t,tmp:boolean;
 label 1;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
function maxim(a:int64;b:int64):int64;
begin
    If a>b then maxim:=a else maxim:=b;
end;
function krygovaya(summ:int64;n:int64;j:int64):int64;
var max,maxsumm1,summtmp,maxsumm2,kryg,s:int64;
begin
 summtmp:=summ;
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp(n*ln(2)));
  If summ=round(exp(n*ln(2)))*j then j:=j*2 else begin
 // If (summ>=l1) and (summ<=r1) then krygovaya(summ,i);// begin t:=true;summtmp:=summ; end;
  If (summ>=l2) and (summ<=r2) then begin max:=n;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
 krygovaya:=kryg;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 maxkryg:=0;
 for i:=min(x,y) to min(x,y)+1 do begin
 summ:=0;
 t:=false;
 j:=2;

 while (summ<=maxim(round(r2),round(r1)))  do begin

  summ:=summ+round(exp(i*ln(2)));
 1:
  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin If krygovaya(summ,i,j)>maxkryg then maxkryg:=krygovaya(summ,i,j) end else If summ>r1 then summ:=maxim(round(r2),round(r1))+1// begin t:=true;summtmp:=summ; end;
  //If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
        // If tmp then begin summ:=summtmp;goto 1 end;
 end; //writeln(max,maxsumm1,maxsumm2);
  // s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If maxkryg>0 then writeln(maxkryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg:int64;
 var i:longint;
 t,tmp:boolean;
 label 1;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
function maxim(a:int64;b:int64):int64;
begin
    If a>b then maxim:=a else maxim:=b;
end;
function krygovaya(summ:int64;n:int64;j:int64):int64;
var max,maxsumm1,summtmp,maxsumm2,kryg,s:int64;
begin
 summtmp:=summ;
 kryg:=0;
 summ:=summ-round(exp(n*ln(2)));
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp(n*ln(2)));
  If summ=round(exp(n*ln(2)))*j then j:=j*2 else begin
 // If (summ>=l1) and (summ<=r1) then krygovaya(summ,i);// begin t:=true;summtmp:=summ; end;
  If (summ>=l2) and (summ<=r2) then begin max:=n;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
 krygovaya:=kryg;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 maxkryg:=0;
 for i:=min(x,y) to maxim(x,y)+1 do begin
 summ:=0;
 t:=false;
 j:=2;

 while (summ<=maxim(round(r2),round(r1)))  do begin

  summ:=summ+round(exp(i*ln(2)));
 1:
  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin If krygovaya(summ,i,j)>maxkryg then maxkryg:=krygovaya(summ,i,j) end else If summ>r1 then summ:=maxim(round(r2),round(r1))+1// begin t:=true;summtmp:=summ; end;
  //If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
        // If tmp then begin summ:=summtmp;goto 1 end;
 end; //writeln(max,maxsumm1,maxsumm2);
  // s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;
  IF (l1=r1) and (l2=r2) and (l2=l1) then writeln('1') else
  If maxkryg>0 then writeln(maxkryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 for i:=min(x,y) to min(x,y)+1 do begin
 summ:=0;
 t:=false;
 j:=2;
 kryg:=0;
 while (summ<=r2)  do begin

  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ; end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
   s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2,c:real;
 var a,b,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp,kryg,maxkryg,k:int64;
 var i:longint;
 t,tmp:boolean;
 label 1;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
function maxim(a:int64;b:int64):int64;
begin
    If a>b then maxim:=a else maxim:=b;
end;
function krygovaya(summ:int64;n:int64;j:int64):int64;
var max,maxsumm1,summtmp,maxsumm2,kryg,s:int64;
begin
 summtmp:=summ;
 kryg:=0;
 summ:=summ-round(exp(n*ln(2)));
 while (summ<=maxim(round(r2),round(r1)))  do begin
  summ:=summ+round(exp(n*ln(2)));
  If summ=round(exp(n*ln(2)))*j then j:=j*2 else begin
 // If (summ>=l1) and (summ<=r1) then krygovaya(summ,i);// begin t:=true;summtmp:=summ; end;
  If (summ>=l2) and (summ<=r2) then begin max:=n;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
 krygovaya:=kryg;
end;
begin
 readln(l1,r1,l2,r2);
 If l1>l2 then begin c:=l1;l1:=l2;l2:=c;c:=r1;r1:=r2;r2:=c end;
 i:=0;
 j:=0;
 x:=trunc(ln(r1-l1+1)/ln(2));
 y:=trunc(ln(r2-l2+1)/ln(2));
 kryg:=0;
 maxkryg:=0;
 If min(x,y)=0 then k:=0 else k:=min(x,y)-1;
 for i:=k to 30 do begin
 summ:=0;
 t:=false;
 j:=2;

 while (summ<=maxim(round(r2),round(r1)))  do begin

  summ:=summ+round(exp(i*ln(2)));
 1:
  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (summ>=l1) and (summ<=r1) then begin If krygovaya(summ,i,j)>maxkryg then maxkryg:=krygovaya(summ,i,j) end else If summ>r1 then summ:=maxim(round(r2),round(r1))+1// begin t:=true;summtmp:=summ; end;
  //If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp;s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;If s>kryg then kryg:=s; end;
               end;
                end;
        // If tmp then begin summ:=summtmp;goto 1 end;
 end; //writeln(max,maxsumm1,maxsumm2);
  // s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If maxkryg>0 then writeln(maxkryg) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var l1,r1,l2,r2:real;
 var a,b,c,d,x,y:integer;
 var j,s,summ,max,maxsumm1,maxsumm2,summtmp:int64;
 var i:longint;
 t:boolean;
function min(a:int64;b:int64):int64;
begin
    If a<b then min:=a else min:=b;
end;
begin
 readln(l1,r1,l2,r2);
 a:=trunc(ln(l1)/ln(2));
 b:=trunc(ln(r1)/ln(2));
 //c:=trunc(ln(l2)/ln(2));
 //d:=trunc(ln(r2)/ln(2));
 //If a>b then x:=a else If a=b then x:=trunc(ln(r1-l1)/ln(2)) else x:=b;
 //If c>d then y:=c else If c=d then y:=trunc(ln(r2-l2)/ln(2)) else y:=d;
 i:=0;
 j:=0;
 If l1<>r1 then x:=trunc(ln(r1-l1)/ln(2));
 If l2<>r2 then y:=trunc(ln(r2-l2)/ln(2));
 for i:=min(x,y) to 30 do begin
 summ:=0;
 t:=false;
 j:=2;
 while (summ<=r2)  do begin
  summ:=summ+round(exp(i*ln(2)));

  If summ=round(exp(i*ln(2)))*j then j:=j*2 else begin
  If (not t) and (summ>=l1) and (summ<=r1) then begin t:=true;summtmp:=summ end;
  If (t) and (summ>=l2) and (summ<=r2) then begin max:=i;maxsumm2:=summ;maxsumm1:=summtmp end;
               end;   end;

 end; //writeln(max,maxsumm1,maxsumm2);
   s:=min(min(round(exp(max*ln(2)))-1,maxsumm1-round(l1)),min(round(exp(max*ln(2)))-1,maxsumm2-round(l2)))+min(min(round(exp(max*ln(2)))-1,round(r1)-maxsumm1),min(round(exp(max*ln(2)))-1,round(r2)-maxsumm2))+1;

  If s>0 then writeln(s) else writeln('0');
 readln;
  { TODO -oUser -cConsole Main : Insert code here }
end.

uses math;
type pair = record
l:longint;
r:longint;
end;
var f1,f2:text;
a,b,l,r:longint;

function mp(u,v:longint):pair;begin mp.l:=u;mp.r:=v;end;

Function process(a,b,l,r:longint;k:longint):longint;
var i,j:longint;
vt:longint;
res:longint;
t1,t2:array[1..2] of pair;
begin
        if k=0 then exit(0);
        if (a>b) or (l>r) then exit(0);
        res:=0;
//        if max(a,l)<=min(b,r) then res:=min(r,b)-max(a,l)+1;
        if ((a<=l) and (r<=b)) or ((l<=a) and (b<=r)) then exit(min(r,b)-max(a,l)+1);
        vt:=1 shl (k-1);
        if vt=a then inc(a);if vt=b then dec(b);if vt=l then inc(l);if vt=r then dec(r);
        t1[1]:=mp(a,min(b,vt-1));
        t1[2]:=mp(max(a,vt+1)-vt,b-vt);
        t2[1]:=mp(l,min(r,vt-1));
        t2[2]:=mp(max(l,vt+1)-vt,r-vt);
        for i:=1 to 2 do
        for j:=1 to 2 do
        res:=max(res,process(t1[i].l,t1[i].r,t2[j].l,t2[j].r,k-1));
        process:=res;
end;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(f2);
        readln(F1,a,b,l,r);
        writeln(f2,Process(a,b,l,r,30));
        close(f1);
        close(f2);
end.

var l1,r1,l2,r2,ans:longint;

procedure swap(var a,b:longint);
  var r:longint;
  begin
    r:=a;
    a:=b;
    b:=r;
  end;

procedure doit(l1,r1,l2,r2,len:longint);
  var mid:longint;
  begin
    if (r1-l1+1<=ans) or (r2-l2+1<=ans) then exit;
    if (l1>l2) or ((l1=l2) and (r1>r2)) then
      begin
        swap(l1,l2);
        swap(r1,r2);
      end;
    writeln(l1,' ',r1,' ',l2,' ',r2,' ',ans);
    if l2<=r1 then
      if r1-l2+1>=ans then ans:=r1-l2+1;
    mid:=(len+1)>>1;
    if (l2<=mid) and (mid<=r1) then
      doit(1,r2-mid,l1,mid-1,len div 2)
    else
      if r2<mid then
        doit(l1,r1,l2,r2,len div 2)
      else
        if l1>mid then
          doit(l1-mid,r1-mid,l2-mid,r2-mid,len div 2)
        else
          if l2<=mid then
            begin
              doit(l1,r1,l2,mid-1,len div 2);
              doit(l1,r1,1,r2-mid,len div 2);
            end
          else
            if r1>=mid then
              begin
                doit(l1,mid-1,l2-mid,r2-mid,len div 2);
                doit(1,r1-mid,l2-mid,r2-mid,len div 2);
              end
            else
              doit(l1,r1,l2-mid,r2-mid,len div 2);
  end;

begin
  readln(l1,r1,l2,r2);
  if (l1>l2) or ((l1=l2) and (r1>r2)) then
    begin
      swap(l1,l2);
      swap(r1,r2);
    end;
  ans:=0;
  doit(l1,r1,l2,r2,1<<30-1);
  writeln(ans);
end.

var l1,r1,l2,r2,ans:longint;

procedure swap(var a,b:longint);
  var r:longint;
  begin
    r:=a;
    a:=b;
    b:=r;
  end;

procedure doit(l1,r1,l2,r2,len:longint);
  var mid,x1,y1,x2,y2:longint;
  begin
    if (r1-l1+1<=ans) or (r2-l2+1<=ans) then exit;
    if (l1>l2) or ((l1=l2) and (r1>r2)) then
      begin
        swap(l1,l2);
        swap(r1,r2);
      end;
    if l2<=r1 then
      if r1-l2+1>=ans then ans:=r1-l2+1;
    mid:=(len+1)>>1;
    if (l2<=mid) and (mid<=r1) then
      doit(1,r2-mid,l1,mid-1,len div 2)
    else
      if r2<mid then
        doit(l1,r1,l2,r2,len div 2)
      else
        if l1>mid then
          doit(l1-mid,r1-mid,l2-mid,r2-mid,len div 2)
        else
          if l2<=mid then
            begin
              doit(l1,r1,l2,mid-1,len div 2);
              doit(l1,r1,1,r2-mid,len div 2);
            end
          else
            begin
              doit(l1,mid-1,l2-mid,r2-mid,len div 2);
              doit(1,r1-mid,l2-mid,r2-mid,len div 2);
            end;
  end;

begin
  readln(l1,r1,l2,r2);
  if (l1>l2) or ((l1=l2) and (r1>r2)) then
    begin
      swap(l1,l2);
      swap(r1,r2);
    end;
  ans:=0;
  doit(l1,r1,l2,r2,1<<30-1);
  writeln(ans);
end.

var l1,r1,l2,r2,ans:longint;

procedure swap(var a,b:longint);
  var r:longint;
  begin
    r:=a;
    a:=b;
    b:=r;
  end;

procedure doit(l1,r1,l2,r2,len:longint);
  var mid:longint;
  begin
    if (r1-l1+1<=ans) or (r2-l2+1<=ans) then exit;
    if (l1>l2) or ((l1=l2) and (r1>r2)) then
      begin
        swap(l1,l2);
        swap(r1,r2);
      end;
    //writeln(l1,' ',r1,' ',l2,' ',r2,' ',ans);
    if l2<=r1 then
      if r1-l2+1>=ans then ans:=r1-l2+1;
    mid:=(len+1)>>1;
    if (l2<=mid) and (mid<=r1) then
      doit(1,r2-mid,l1,mid-1,len div 2)
    else
      if r2<mid then
        doit(l1,r1,l2,r2,len div 2)
      else
        if l1>mid then
          doit(l1-mid,r1-mid,l2-mid,r2-mid,len div 2)
        else
          if l2<=mid then
            begin
              doit(l1,r1,l2,mid-1,len div 2);
              doit(l1,r1,1,r2-mid,len div 2);
            end
          else
            if r1>=mid then
              begin
                doit(l1,mid-1,l2-mid,r2-mid,len div 2);
                doit(1,r1-mid,l2-mid,r2-mid,len div 2);
              end
            else
              doit(l1,r1,l2-mid,r2-mid,len div 2);
  end;

begin
  readln(l1,r1,l2,r2);
  if (l1>l2) or ((l1=l2) and (r1>r2)) then
    begin
      swap(l1,l2);
      swap(r1,r2);
    end;
  ans:=0;
  doit(l1,r1,l2,r2,1<<30-1);
  writeln(ans);
end.


Manao is working for a construction company. Recently, an order came to build wall bars in a children's park. Manao was commissioned to develop a plan of construction, which will enable the company to save the most money.After reviewing the formal specifications for the wall bars, Manao discovered a number of controversial requirements and decided to treat them to the company's advantage. His resulting design can be described as follows:  Let's introduce some unit of length. The construction center is a pole of height n.  At heights 1, 2, ..., n exactly one horizontal bar sticks out from the pole. Each bar sticks in one of four pre-fixed directions.  A child can move from one bar to another if the distance between them does not exceed h and they stick in the same direction. If a child is on the ground, he can climb onto any of the bars at height between 1 and h. In Manao's construction a child should be able to reach at least one of the bars at heights n - h + 1, n - h + 2, ..., n if he begins at the ground.   The figure to the left shows what a common set of wall bars looks like. The figure to the right shows Manao's construction Manao is wondering how many distinct construction designs that satisfy his requirements exist. As this number can be rather large, print the remainder after dividing it by 1000000009 (109 + 9). Two designs are considered distinct if there is such height i, that the bars on the height i in these designs don't stick out in the same direction.

A single line contains two space-separated integers, n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ min(n, 30)).

In a single line print the remainder after dividing the number of designs by 1000000009 (109 + 9).

NoteConsider several designs for h = 2. A design with the first bar sticked out in direction d1, the second — in direction d2 and so on (1 ≤ di ≤ 4) is denoted as string d1d2...dn.Design "1231" (the first three bars are sticked out in different directions, the last one — in the same as first). A child can reach neither the bar at height 3 nor the bar at height 4.Design "414141". A child can reach the bar at height 5. To do this, he should first climb at the first bar, then at the third and then at the fifth one. He can also reach bar at height 6 by the route second  →  fourth  →  sixth bars.Design "123333". The child can't reach the upper two bars.Design "323323". The bar at height 6 can be reached by the following route: first  →  third  →  fourth  →  sixth bars.

{$r-,q-,s-,i-,o+}
const
  base=1000000009;

var
  ni,ii,cr,i1,i2,i3,i4,res,kq,n,h,i,qqq,nkq,nq1,nq2,nq3,nq4:longint;
  used:array[0..33,0..33,0..33,0..33]of longint;
  qq1,qq2,qq3,qq4,q1,q2,q3,q4:array[0..500050]of longint;
  f,ff:array[0..33,0..33,0..33,0..33]of longint;

  procedure upd(i1,i2,i3,i4,cr:longint);inline;
    var
      t:array[1..5]of longint;
      j,i,tmp:longint;

    begin
      t[1]:=i1;t[2]:=i2;t[3]:=i3;t[4]:=i4;
      for i:=1 to 3 do
        for j:=1 to 3 do
          if (t[j]>t[j+1])then begin
            tmp:=t[j];t[j]:=t[j+1];t[j+1]:=tmp;
          end;
      i1:=t[1];i2:=t[2];i3:=t[3];i4:=t[4];
      if (used[i1][i2][i3][i4]<>qqq)then begin
        inc(nkq);
        qq1[nkq]:=i1;
        qq2[nkq]:=i2;
        qq3[nkq]:=i3;
        qq4[nkq]:=i4;
        used[i1][i2][i3][i4]:=qqq;
        ff[i1][i2][i3][i4]:=0;
      end;
      inc(ff[i1][i2][i3][i4],cr);
      if (ff[i1][i2][i3][i4]>=base)then dec(ff[i1][i2][i3][i4],base);
    end;

begin
  //assign(input,'input.txt');reset(input);
  //assign(output,'output.txt');rewrite(output);
  read(n,h);
  kq:=1;
  q1[1]:=0;
  q2[1]:=0;
  q3[1]:=0;
  q4[1]:=0;
  f[0][0][0][0]:=1;
  fillchar(used,sizeof(used),$0);
  qqq:=0;res:=0;
  for ii:=1 to n do begin
    inc(qqq);
    nkq:=0;
    for i:=1 to kq do begin
      i1:=q1[i];i2:=q2[i];
      i3:=q3[i];i4:=q4[i];
      nq1:=i1+1;if (nq1>h)then nq1:=h+1;
      nq2:=i2+1;if (nq2>h)then nq2:=h+1;
      nq3:=i3+1;if (nq3>h)then nq3:=h+1;
      nq4:=i4+1;if (nq4>h)then nq4:=h+1;
      cr:=f[i1][i2][i3][i4];
      if (cr=0)then continue;

      if (nq1<>h+1)then ni:=0 else ni:=h+1;
      upd(ni,nq2,nq3,nq4,cr);
      if (nq2<>h+1)then ni:=0 else ni:=h+1;
      upd(nq1,ni,nq3,nq4,cr);
      if (nq3<>h+1)then ni:=0 else ni:=h+1;
      upd(nq1,nq2,ni,nq4,cr);
      if (nq4<>h+1)then ni:=0 else ni:=h+1;
      upd(nq1,nq2,nq3,ni,cr);
    end;
    kq:=nkq;
    for i:=1 to kq do begin
      q1[i]:=qq1[i];q2[i]:=qq2[i];
      q3[i]:=qq3[i];q4[i]:=qq4[i];
    end;
    for i:=1 to kq do f[q1[i]][q2[i]][q3[i]][q4[i]]:=ff[q1[i]][q2[i]][q3[i]][q4[i]];
  end;
  for i:=1 to kq do begin
    i1:=q1[i];i2:=q2[i];i3:=q3[i];i4:=q4[i];
    if (i1>=h)and(i2>=h)and(i3>=h)and(i4>=h)then continue;
    inc(res,f[i1][i2][i3][i4]);
    if (res>=base)then dec(res,base);
  end;
  writeln(res);
end.

const md:longint=1000000009;

var i,j,h,n,lj,lx,ly,lz,x,y,z,ans:longint;
    v:array[0..1001,0..1,0..31,0..31,0..31] of longint;

function tt(x:longint):longint;
 begin
  if (x=0) or
     (x=h) then tt:=0
           else tt:=x+1;
 end;

 begin
  read(n,h);

  v[1,1,0,0,0]:=4;
  for i:=2 to n do
   begin
    for j:=0 to 1 do
     begin
      for x:=0 to h do
       for y:=0 to h do
        for z:=0 to h do
         begin
          lx:=tt(x);
          ly:=tt(y);
          lz:=tt(z);
          lj:=tt(j);
          v[i,j,lx,ly,lz]:=(v[i,j,lx,ly,lz]+v[i-1,j,x,y,z]) mod md;

          v[i,ord((x>0) or (i<=h)),lj,ly,lz]:=(v[i,ord((x>0) or (i<=h)),lj,ly,lz]+v[i-1,j,x,y,z]) mod md;
          v[i,ord((y>0) or (i<=h)),lx,lj,lz]:=(v[i,ord((y>0) or (i<=h)),lx,lj,lz]+v[i-1,j,x,y,z]) mod md;
          v[i,ord((z>0) or (i<=h)),lx,ly,lj]:=(v[i,ord((z>0) or (i<=h)),lx,ly,lj]+v[i-1,j,x,y,z]) mod md;
         end;

     end;

   end;

  ans:=0;
  for i:=0 to 1 do
   for x:=0 to h do
    for y:=0 to h do
     for z:=0 to h do
      if (i=0) then begin
                     if (x>0) or
                        (y>0) or
                        (z>0) then ans:=(ans+v[n,i,x,y,z]) mod md;
                    end
               else ans:=(ans+v[n,i,x,y,z]) mod md;

  writeln(ans);
 end.

const md:longint=1000000009;

var
  i,j,h,n,lj,lx,ly,lz,x,y,z,ans:longint;
  v:array[0..1001,0..1,0..31,0..31,0..31] of longint;

function tt(x: longint): longint;
  begin
    if (x = 0) or (x = h) then
      tt := 0
    else
      tt := x + 1;
  end;

begin
  read(n,h);
  v[1,1,0,0,0]:=4;
  for i:=2 to n do
   begin
    for j:=0 to 1 do
     begin
      for x:=0 to h do
       for y:=0 to h do
        for z:=0 to h do
         begin
          lx:=tt(x);
          ly:=tt(y);
          lz:=tt(z);
          lj:=tt(j);
          v[i,j,lx,ly,lz]:=(v[i,j,lx,ly,lz]+v[i-1,j,x,y,z]) mod md;
          v[i,ord((x>0) or (i<=h)),lj,ly,lz]:=(v[i,ord((x>0) or (i<=h)),lj,ly,lz]+v[i-1,j,x,y,z]) mod md;
          v[i,ord((y>0) or (i<=h)),lx,lj,lz]:=(v[i,ord((y>0) or (i<=h)),lx,lj,lz]+v[i-1,j,x,y,z]) mod md;
          v[i,ord((z>0) or (i<=h)),lx,ly,lj]:=(v[i,ord((z>0) or (i<=h)),lx,ly,lj]+v[i-1,j,x,y,z]) mod md;
         end;
     end;

   end;

  ans:=0;
  for i:=0 to 1 do
   for x:=0 to h do
    for y:=0 to h do
     for z:=0 to h do
      if (i=0) then begin
                     if (x>0) or
                        (y>0) or
                        (z>0) then ans:=(ans+v[n,i,x,y,z]) mod md;
                    end
               else ans:=(ans+v[n,i,x,y,z]) mod md;

  writeln(ans);
 end.

const
  md: longint = 1000000009;

var
  i,j,h,n,lj,lx,ly,lz,x,y,z,ans:longint;
  v:array[0..1001,0..1,0..31,0..31,0..31] of longint;

function tt(x: longint): longint;
  begin
    if (x = 0) or (x = h) then
      tt := 0
    else
      tt := x + 1;
  end;

begin
  read(n,h);
  v[1,1,0,0,0]:=4;
  for i:=2 to n do
   begin
    for j:=0 to 1 do
     begin
      for x:=0 to h do
       for y:=0 to h do
        for z:=0 to h do
         begin
          lx:=tt(x);
          ly:=tt(y);
          lz:=tt(z);
          lj:=tt(j);
          v[i,j,lx,ly,lz]:=(v[i,j,lx,ly,lz]+v[i-1,j,x,y,z]) mod md;
          v[i,ord((x>0) or (i<=h)),lj,ly,lz]:=(v[i,ord((x>0) or (i<=h)),lj,ly,lz]+v[i-1,j,x,y,z]) mod md;
          v[i,ord((y>0) or (i<=h)),lx,lj,lz]:=(v[i,ord((y>0) or (i<=h)),lx,lj,lz]+v[i-1,j,x,y,z]) mod md;
          v[i,ord((z>0) or (i<=h)),lx,ly,lj]:=(v[i,ord((z>0) or (i<=h)),lx,ly,lj]+v[i-1,j,x,y,z]) mod md;
         end;
     end;

   end;

  ans:=0;
  for i:=0 to 1 do
   for x:=0 to h do
    for y:=0 to h do
     for z:=0 to h do
      if (i=0) then begin
                     if (x>0) or
                        (y>0) or
                        (z>0) then ans:=(ans+v[n,i,x,y,z]) mod md;
                    end
               else ans:=(ans+v[n,i,x,y,z]) mod md;

  writeln(ans);
 end.

program Adina;
const
  m = 1000000009;
var
  d : array [1..1001, 0..1, 0..31, 0..31, 0..31] of longint;
  n, i, j, al, l1, l2, l3, x, y, z, h, ans : longint;

procedure check(var l : longint);
begin
  if l = h - 1 then
    l := 0
  else
  if l > 0 then
    inc(l);
end;

procedure calc1;
begin
  for y := 0 to h do
     for z := 0 to h do
       for x := 0 to h do begin
         l1 := x; l2 := y; l3 := z;
         check(l2); check(l3);
         if (x > 0) or (i < h) then
           d[i + 1, 1, al, l2, l3] := (d[i + 1, 1, al, l2, l3] + d[i, al, x, y, z]) mod m
         else
           d[i + 1, 0, al, l2, l3] := (d[i + 1, 0, al, l2, l3] + d[i, al, x, y, z]) mod m;
       end;
end;

procedure calc2;
begin
  for z := 0 to h do
     for x := 0 to h do
       for y := 0 to h do begin
          l1 := x; l2 := y; l3 := z;
          check(l1); check(l3);
          if (y > 0) or (i < h) then
            d[i + 1, 1, l1, al, l3] := (d[i + 1, 1, l1, al, l3] + d[i, al, x, y, z]) mod m
          else
            d[i + 1, 0, l1, al, l3] := (d[i + 1, 0, l1, al, l3] + d[i, al, x, y, z]) mod m;
        end;
end;

procedure calc3;
begin
  for y := 0 to h do
     for x := 0 to h do
       for z := 0 to h do begin
         l1 := x; l2 := y; l3 := z;
         check(l1); check(l2);
         if (z > 0) or (i < h) then
           d[i + 1, 1, l1, l2, al] := (d[i + 1, 1, l1, l2, al] + d[i, al, x, y, z]) mod m
         else
           d[i + 1, 0, l1, l2, al] := (d[i + 1, 0, l1, l2, al] + d[i, al, x, y, z]) mod m
       end;
end;

procedure calc4;
begin
  for x := 0 to h do
     for y := 0 to h do
       for z := 0 to h do begin
         l1 := x; l2 := y; l3 := z;
         check(l1); check(l2); check(l3);
         d[i + 1, al, l1, l2, l3] := (d[i + 1, al, l1, l2, l3] + (d[i, al, x, y, z])) mod m;
       end;
end;

begin
  {assign(input, 'input.in');
  assign(output, 'output.out');
  reset(input);
  rewrite(output);    }
  read(n, h);
  if h = 1 then begin
    writeln(4);
    halt;
  end;
  d[1, 1, 0, 0, 0] := 4;
  for i := 1 to n - 1 do
    for al := 0 to 1 do begin
      calc1;
      calc2;
      calc3;
      calc4;
    end;
  for l2 := 0 to h do
     for l3 := 0 to h do
       for l1 := 0 to h do
         if (l1 > 0) or (l2 > 0) or (l3 > 0) then begin
           ans := (ans + d[n, 0, l1, l2, l3]) mod m;
           writeln(0,' ',l1,' ',l2,' ',l3,' ',d[n, 0, l1, l2, l3]);
         end;

    for l1 := 0 to h do
     for l2 := 0 to h do
       for l3 := 0 to h do begin
         ans := (ans + d[n, 1, l1, l2, l3]) mod m;
         writeln(1,' ',l1,' ',l2,' ',l3,' ',d[n, 1, l1, l2, l3]);
       end;

  writeln(ans);
  //writeln(d[2, 1, 0, 0, 0]);
  {close(input);
  close(output);  }
end.

program Adina;
const
  m = 1000000009;
var
  d : array [1..1001, 0..1, 0..31, 0..31, 0..31] of longint;
  n, i, j, al, l1, l2, l3, x, y, z, h, ans : longint;

procedure check(var l : longint);
begin
  if l = h - 1 then
    l := 0
  else
  if l > 0 then
    inc(l);
end;

procedure calc1;
begin
  for y := 0 to h do
     for z := 0 to h do
       for x := 0 to h do begin
         l1 := x; l2 := y; l3 := z;
         check(l2); check(l3);
         if (x > 0) or (i < h) then
           d[i + 1, 1, al, l2, l3] := (d[i + 1, 1, al, l2, l3] + d[i, al, x, y, z]) mod m
         else
           d[i + 1, 0, al, l2, l3] := (d[i + 1, 0, al, l2, l3] + d[i, al, x, y, z]) mod m;
       end;
end;

procedure calc2;
begin
  for z := 0 to h do
     for x := 0 to h do
       for y := 0 to h do begin
          l1 := x; l2 := y; l3 := z;
          check(l1); check(l3);
          if (y > 0) or (i < h) then
            d[i + 1, 1, l1, al, l3] := (d[i + 1, 1, l1, al, l3] + d[i, al, x, y, z]) mod m
          else
            d[i + 1, 0, l1, al, l3] := (d[i + 1, 0, l1, al, l3] + d[i, al, x, y, z]) mod m;
        end;
end;

procedure calc3;
begin
  for y := 0 to h do
     for x := 0 to h do
       for z := 0 to h do begin
         l1 := x; l2 := y; l3 := z;
         check(l1); check(l2);
         if (z > 0) or (i < h) then
           d[i + 1, 1, l1, l2, al] := (d[i + 1, 1, l1, l2, al] + d[i, al, x, y, z]) mod m
         else
           d[i + 1, 0, l1, l2, al] := (d[i + 1, 0, l1, l2, al] + d[i, al, x, y, z]) mod m
       end;
end;

procedure calc4;
begin
  for x := 0 to h do
     for y := 0 to h do
       for z := 0 to h do begin
         l1 := x; l2 := y; l3 := z;
         check(l1); check(l2); check(l3);
         d[i + 1, al, l1, l2, l3] := (d[i + 1, al, l1, l2, l3] + (d[i, al, x, y, z])) mod m;
       end;
end;

begin
  {assign(input, 'input.in');
  assign(output, 'output.out');
  reset(input);
  rewrite(output); }
  read(n, h);
  d[1, 1, 0, 0, 0] := 4;
  for i := 1 to n - 1 do
    for al := 0 to 1 do begin
      calc1;
      calc2;
      calc3;
      calc4;
    end;
  for l2 := 0 to h do
     for l3 := 0 to h do
       for l1 := 0 to h do
         if (l1 > 0) or (l2 > 0) or (l3 > 0) then begin
           ans := (ans + d[n, 0, l1, l2, l3]) mod m;
           //writeln(0,' ',l1,' ',l2,' ',l3,' ',d[n, 0, l1, l2, l3]);
         end;

    for l1 := 0 to h do
     for l2 := 0 to h do
       for l3 := 0 to h do begin
         ans := (ans + d[n, 1, l1, l2, l3]) mod m;
         //writeln(1,' ',l1,' ',l2,' ',l3,' ',d[n, 1, l1, l2, l3]);
       end;

  writeln(ans);
  //writeln(d[2, 1, 0, 0, 0]);
  {close(input);
  close(output);    }
end.