On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.

The first line of the input contains a positive integer n (1 ≤ n ≤ 1 000 000) — the number of days in a year on Mars.

Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.

NoteIn the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.

var n,v:integer;
begin
    read(n);
    v:=n div 7*2;
    n:=n mod 7;
    if n<3 then write(v,' ',v+n)
    else
    if n<6 then write(v,' ',v+2)
    else write(v+1,' ',v+2)
end.

uses Math;
var b,a,c:longint;
Begin
   readln(a);
   b:=(a div 7)*2;
   b:=b+max(0,(a mod 7)-5);
   c:=(a div 7)*2;
   c:=c+min(a mod 7,2);
   writeln(b,' ',c);
end.

program holidays;
var n,x:longint;
begin
     readln(n);
     if (n mod 7=0) then writeln(2*(n div 7),' ',2*(n div 7))
     else begin
               x:=n-(n div 7)*7;
               if x=1 then writeln(2*(n div 7),' ',2*(n div 7)+1);
               if (x>=2) and (x<=5) then writeln(2*(n div 7),' ',2*(n div 7)+2);
               if (x>5) then writeln(2*(n div 7)+1,' ',2*(n div 7)+2);
     end;
end.

var n:longint;
begin
  read(n);
  if n mod 7 = 0 then
    write(n div 7 * 2,' ', n div 7 * 2);
  if n mod 7 =1 then
    write(n div 7*2,' ', n div 7*2 +1);
  if n mod 7 = 2 then
    write(n div 7*2,' ', n div 7*2 +2);
  if n mod 7 = 6 then
    write(n div 7*2 + 1,' ', n div 7 * 2 + 2);
  if (n mod 7 > 2) and (n mod 7 <6) then
    write(n div 7*2,' ', n div 7 *2+2);
end.

var n,k,mi:integer;
begin
read(n);
k:=(n div 7)*2;
mi:=k;
if n mod 7>=2 then k:=k+2
else if n mod 7=1 then k:=k+1;
if n mod 7=6 then mi:=mi+1;
write(mi,' ',k);
end.

var n,a:longint;
begin
 readln(n);
 a:=n div 7;
 if n mod 7<2 then
  begin
   writeln(2*a,' ',2*a+n mod 7);
   halt;
  end;
 if (n mod 7>=2) and (n mod 7<>6) then
  begin
   writeln(2*a,' ',2*a+2);
   halt;
  end;
 if (n mod 7=6) then
  begin
   writeln(2*a+1,' ',2*a+2);
   halt;
  end;
end.

uses math;
var   n:int64;
begin
       readln(n);
       writeln(n div 7*2 + (n mod 7+1) div 7,' ',n div 7*2 +min(n mod 7,2))
end.

var n,x,y,min,max:longint;
begin
readln(n);
x:=n div 7;
y:= n - 7*x;
if y >=2 then max:= x*2 + 2
else max:=x*2 + y;
if y<=5 then min:= x*2
else min:= x*2 + y - 5;

writeln(min,' ',max)
end.

program holidays;
var n,max,min:longint;
begin
    readln(n);
    min:=(n div 7)*2;
    if n mod 7 = 6 then inc(min);
    repeat
        if n>1 then
        begin
            inc(max,2);
            dec(n,7);
        end;
        if n=1 then
        begin
            inc(max);
            n:=0;
        end;
    until n<=0;
    write(min,' ',max);
    readln;
end.

var n,min,max,a,b:integer;
begin
read(n);
a:=n div 7;
b:=n mod 7;
min:=a*2;
max:=a*2;
if b>5 then min:=a*2+1;
if (b>0) and (b<6) then min:=a*2;
if b=1 then max:=a*2+1;
if b>1 then max:=a*2+2;
write(min,' ',max);
end.

var n,min,max,a,b:integer;
begin
read(n);
a:=n div 7;
b:=n mod 7;
min:=a*2;
max:=a*2;
if b>5 then min:=a*2+1;
if (b>0) and (b<6) then
min:=a*2;
if b=1 then
max:=a*2+1;
if b>1 then
max:=a*2+2;
write(min,' ',max);
end.

var
  a,s,d:integer;
begin
  read(a);
  d:=(a div 7)*2;
  if ((a mod 7) > 5) then
     inc (d,a mod 7 - 5);
  s:=a div 7 * 2;
  if a mod 7 = 1 then
     inc(s, 1)
  else if a mod 7 >= 2 then
     inc(s,2);
  writeln(d, '  ', s);
end.

var
x,y,z:integer;
begin
	readln(x);
	y:=(x div 7)*2;
	if (x mod 7 = 6)then y:=y+1;
	if x=1 then z:=1 else begin
		z:=2;
		x:=x-2;
		z:=z+(x div 7)*2;
		if (x mod 7 = 6)then z:=z+1;
	end;
	writeln(y,' ',z);
end.

Const Finp='';
      Fout='';
Var n,min,max:longint;

Procedure Nhap;
Var f:Text;
Begin
    assign(f,finp); reset(f);
    read(f,n);
    close(f);
End;
Procedure Tinh;
Begin
    min:=(n div 7)*2; max:=(n div 7)*2;
    if n mod 7>=2 then inc(max,2);
    if n mod 7=1 then inc(max);
    if n mod 7=6 then inc(min);
End;
Procedure Xuat;
Var f:Text;
Begin
    assign(f,fout); rewrite(f);
    write(f,min,' ',max);
    close(f);
End;

Begin
    nhap;
    tinh;
    xuat;
End.

var n, m, k,i, o, p, l, j, ans, min, max:LongInt;

 Begin
   Read(n);

   if (n mod 7=0) then BEgin k:=n div 7;WriteLn(k*2,' ', k*2);Halt;End;
   if (n mod 7=1) then Begin k:=n div 7;WriteLn(k*2,' ',K*2+1);HAlt;End;

   if (n mod 7<6) then Begin k:=n div 7;WriteLn(k*2,' ',K*2+2);HAlt;End;
   if (n mod 7=6) then BEgin k:=n div 7; WriteLn(k*2+1,' ',k*2+2);HAlt;End;
   WriteLn(min,' ', max);
 End.

var i,k,n,m,l,min,max,d:longint;
 begin
  readln(n);
  max:=0;
  min:=maxlongint;
  d:=0;
  l:=0;
  k:=0;
  inc(k);
  while l<=n-1 do
   begin
    inc(l);
    if l=n then break;
    inc(d);
    d:=d mod 7;
    if (d=6) or (d=0) then inc(k);
   end;
   if k>max then max:=k;
   if k<min then min:=k;
  d:=1;
  l:=0;
  k:=0;
  while l<=n-1 do
   begin
    inc(l);
    if l=n then break;
    inc(d);
    d:=d mod 7;
    if (d=6) or (d=0) then inc(k);
   end;
   if k>max then max:=k;
   if k<min then min:=k;
  d:=2;
  l:=0;
  k:=0;
  while l<=n-1 do
   begin
    inc(l);
    if l=n then break;
    inc(d);
    d:=d mod 7;
    if (d=6) or (d=0) then inc(k);
   end;
   if k>max then max:=k;
   if k<min then min:=k;
  d:=3;
  l:=0;
  k:=0;
  while l<=n-1 do
   begin
    inc(l);
    if l=n then break;
    inc(d);
    d:=d mod 7;
    if (d=6) or (d=0) then inc(k);
   end;
   if k>max then max:=k;
   if k<min then min:=k;
  d:=4;
  l:=0;
  k:=0;
  while l<=n-1 do
   begin
    inc(l);
    if l=n then break;
    inc(d);
    d:=d mod 7;
    if (d=6) or (d=0) then inc(k);
   end;
   if k>max then max:=k;
   if k<min then min:=k;
  d:=5;
  l:=0;
  k:=0;
  while l<=n-1 do
   begin
    inc(l);
    if l=n then break;
    inc(d);
    d:=d mod 7;
    if (d=6) or (d=0) then inc(k);
   end;
   if k>max then max:=k;
   if k<min then min:=k;
  d:=6;
  l:=0;
  k:=0;
  inc(k);
  while l<=n-1 do
   begin
    inc(l);
    if l=n then break;
    inc(d);
    d:=d mod 7;
    if (d=6) or (d=0) then inc(k);
   end;
   if k>max then max:=k;
   if k<min then min:=k;
  WriteLn(min,' ',max);
 end.

var
        n,kq1,kq2:longint;
begin
        read(n);
        kq1:=0;
        kq2:=0;
        if n>5 then
                begin
                        kq1:=(n div 7)*2;
                        if n mod 7 =6 then
                                inc(kq1);
                end;
        if (n=1) or (n=2) then
                kq2:=n
        else
                begin
                        n:=n-2;
                        kq2:=(n div 7)*2+2;
                        if n mod 7 = 6 then
                                inc(kq2);
                end;

        write(kq1,' ',kq2);
end.

var n,min,max,n1,a:longint;
i:integer;
f:boolean;
begin
read(n);
for i:= 0 to 5 do
 begin
 n1:=n-i;
 a:=2*(n1 div 7);
 if (n1 mod 7 =1) then inc(a)
 else if (n1 mod 7>=2) then inc(a,2);
 if a>max then max:=a;
 if (a<min) or not(f) then begin min:=a;f:=true end;
 end;

 n1:=n-6;
 a:=2*(n1 div 7)+1;
 if (n1 mod 7 =1) then inc(a)
 else if (n1 mod 7>=2) then inc(a,2);
 if a>max then max:=a;
 if (a<min) or not(f) then begin min:=a;f:=true end;
 write(min,' ', max);
 end.

uses math;
var mi,ma,m,n,k:longint;

begin
readln(n);
m:=n div 7;k:=n mod 7;
ma:=min(2,k);
if k>5 then mi:=k-5;
writeln(mi+m*2,' ',ma+m*2);
end.

var
l,d,k,n:longint;
 begin
readln(n);
l:=(n div 7 )*2;
if( n mod 7 )= 6 then l:=l+1;
write(l,' ');
  if n=2 then begin write('2'); exit; end;
if n=1 then  begin write('1'); exit; end;
d:=n-2;
k:=2;
while  d>0 do
begin
d:=d-7;
k:=k+2;
end;
if d<-1 then k:=k-2;
if d=-1 then k:=k-1;
write(k);
 end.

program abc;
var
max,min,n:longint;
begin
readln(n);
max:=n div 7*2;
if n mod 7-2>=0 then max:=max+2 else
if n mod 7-1>=0 then max:=max+1;
min:=n div 7*2;
if n mod 7=6 then min:=min+1;
writeln(min,' ',max);
end.

var
 a,b:array[0..100]of longint;
 c,i,j,k,m,n:longint;
begin
 read(n);
 c:=(n div 7)*2;
 k:=n mod 7;
 if (k=6) then write(c+1,' ') else write(c,' ');

 if k>0 then
 begin
  if k>2 then write(c+2) else write(c+k);
  halt;
 end;
 write(c);

end.

var
 n,a,b,nghi:longint;
begin
  readln(n);
  a:=n div 7;   a:=a*2;
  b:=n mod 7;
  if (b=6) then inc(a);
  if (b>=2) then b:=(n div 7)*2+2
  else b:=(n div 7)*2+b;
  writeln(a,' ',b);
end.

var n,b,s,i,k:integer; a:array of integer;
begin
read(n);
setlength(a,n);
k:=1;
b:=0;
s:=0;
for i:=0 to n-1 do begin
a[i]:=k;
k:=k+1;
if k=8 then k:=1;
end;
for i:=0 to n-1 do begin
if (a[i]=1) or (a[i]=2) then b:=b+1;
if (a[i]=6) or (a[i]=7) then s:=s+1;
end;
write(s,' ',b);
end.

var
  n:longint;
begin
 readln(n);
 if n mod 7 = 0
   then begin writeln(2*(n div 7),' ',2*(n div 7)); exit; end
    else
      if (n mod 7 = 6)
        then
          write(2*(n div 7)+1,' ')
        else
          write (2*(n div 7),' ');
 if n mod 7 > 1
   then writeln(2*(n div 7)+2)
   else writeln(2*(n div 7)+1)

//(2*(n div 7))+(n mod 7)
end.

var n,ans,ans2:longint;

begin
	readln(n);
	ans:=n div 7*2;ans2:=ans;
	n:=n mod 7;
	if n>=6 then inc(ans);
	write(ans,' ');
	if n>=2 then inc(ans2,2) else inc(ans2,n);
	writeln(ans2);
end .

var i,n,max,min:longint;
begin
 readln(n);
  for i:=1 to n do
   begin
    if ( (i mod 7) = 1 ) then inc(max);
    if ( (i mod 7) = 2 ) then inc(max);
   end;
  for i:=1 to n do
    begin
     if ( (i mod 7) = 6 ) then inc(min);
     if ( (i mod 7) = 0 ) then inc(min);
    end;
  writeln(min,' ',max);
end.

uses math;
var c,n,k,i,j,l,f,flag,max1,min1:longint;
    ans:int64;
    a:array[1..100000] of longint;
    q,p:real;
    s:string;
begin
read(n); l:=2;
max1:=(n div 7)*2;
min1:=max1;
if n mod 7=6 then inc(min1);
inc(max1,min(l,n mod 7));
write(min1,' ',max1);
end.

var n,v:integer;
begin
    read(n);
    v:=n div 7*2;
    n:=n mod 7;
    if n<3 then write(v,' ',v+n)
    else
    if n<6 then write(v,' ',v+2)
    else write(v+1,' ',v+2)
end.

type arr=array [1..100000] of ansistring;
var i,j,k,l,l1,l2,l3,t: longint;
n,t1,t2: longint;
flag:integer;
procedure Sort(var A: arr; L, R: integer);
  var i, j: integer;
      x, t: string;
  begin
  while L < R do begin
    x:= A[L];
    i:= L; j:= R;
    repeat
      while A[i] < x do inc(i);
      while x < A[j] do dec(j);
      if i <= j then  begin
        t:= A[i]; A[i]:= A[j]; A[j]:= t;
        inc(i); dec(j);
        end;
    until i > j;
    if (j - L) > (R - i) then
      begin
      Sort(A, i, R);
      R:= j;
      end
    else
      begin
      Sort(A, L, j);
      L:= i;
      end;
    end;
  end;

Begin
  readln(n);
  t1:=0;
  t2:=0;
  t1:=2*(n div 7);
  t2:=t1;
  if (n mod 7)=6 then t1:=t1+1;
  if (n mod 7)>=3 then t2:=t2+2
  else t2:=t2+(n mod 7);
  //t2:=t1+(n mod 7);
  writeln(t1,' ',t2);
end.

var a,b,n,min,max:longint;
begin
readln(n);
a:=n div 7;
b:=n mod 7;
if b<=2 then begin
             min:=a*2;
             max:=a*2+b;
             end
        else if b=6 then begin
                          min:=a*2+1;
                          max:=a*2+2;
                          end
                     else begin
                          min:=a*2;
                          max:=a*2+2;
                          end;
write(min,' ',max);
end.

var
  a,s,d:integer;
begin
  read(a);
  d:=(a div 7)*2;
  if ((a mod 7) > 5) then
     inc (d,a mod 7 - 5);
  s:=a div 7 * 2;
  if a mod 7 = 1 then
     inc(s, 1)
  else if a mod 7 >= 2 then
     inc(s,2);
  writeln(d, '  ', s);
end.

const fi='';
        fo='';

procedure doc;
var i,d,n,d1:longint;
begin
        assign(input,fi);reset(input);
        readln(n); close(input);
        d:=0; i:=0; d1:=2;
        while i<=n do begin
                i:=i+7;
                if i<=n then d:=d+2
                else if i=n+1 then d:=d+1;
                if i<=n-2 then d1:=d1+2
                else if i=n-1 then d1:=d1+1;
        end;
        if n=1 then d1:=1;
        assign(output,fo);rewrite(output);
        writeln(d,' ',d1);close(output);
end;

begin
        doc;
end.

var n:longint;
begin
readln(n);
if n mod 7=0 then begin write(2*(n div 7),' ',2*(n div 7)); exit; end;
if n mod 7=1 then write((n div 7)*2,' ',2*(n div 7)+1);
if (n mod 7>1)and(n mod 7<6) then write((n div 7)*2,' ',2*(n div 7)+2);
if n mod 7=6 then write((n div 7)*2+1,' ',2*(n div 7)+2);
end.

var k,k1,k2,n:integer;
begin
readln(n);
if n<=7 then begin
if n=1 then writeln(0,' ',1);
if (n>=2)and(n<=5) then writeln(0,' ',2);
if n=6 then writeln(1,' ',2);
if n=7 then writeln(2,' ',2);
end
else begin
if n mod 7=0 then begin k:=n div 7; writeln(k*2,' ',k*2); end
else begin
k:=n-(n div 7)*7;
k2:=(n div 7)*2; k1:=(n div 7)*2;
if k=1 then k2:=k2+1;
if k>=2 then k2:=k2+2;
if k=6 then k1:=k1+1;
writeln(k1,' ',k2);
end;
end;
end.

program z1;
var a,b,c,d,i,j,k,l,m,n,ansmin,ansmax,cur:longint;
begin
//assign(input,'d:\input.txt'); reset(input);
//assign(output,'d:\output.txt'); rewrite(output);
readln(n);

for i:=0 to n-1 do
 begin
 if (i mod 7=5) or (i mod 7=6) then inc(ansmin);
 if i>=1 then if ((i-2) mod 7=5) or ((i-2) mod 7=6) then inc(ansmax);
 end;

if n=1 then ansmax:=ansmax+1 else ansmax:=ansmax+2;

writeln(ansmin,' ',ansmax);
end.

var
x,y,z:integer;
begin
	readln(x);
	y:=(x div 7)*2;
	if (x mod 7 = 6)then y:=y+1;
	if x=1 then z:=1 else begin
		z:=2;
		x:=x-2;
		z:=z+(x div 7)*2;
		if (x mod 7 = 6)then z:=z+1;
	end;
	writeln(y,' ',z);
end.

var n,mi,ma,a,b,c:integer;
begin
readln(n);
a:=n div 7; b:=a*2;
mi:=b; ma:=b;
c:=n mod 7;
if (c>0) then if c=1 then ma:=ma+1 else if (c<=5) then ma:=ma+2 else if c=6 then begin mi:=mi+1; ma:=ma+2; end;
write(mi,' ',ma);
end.

var n,k,d:longint;
begin
readln(n);
k:=(n div 7)*2;
if n mod 7 = 6 then write(k+1,' ')
else write(k,' ');
if n mod 7 = 1 then write(k+1)
else if n mod 7 >=2 then write(k+2)
else write(k);
end.

Var n,k,y:longint;
    Begin
     read(n);
     if n mod 7=6 then y:=1;
     if n mod 7=1 then k:=1;
     if n mod 7>1 then k:=2;
     writeln(y+((n div 7)*2),' ',k+((n div 7)*2));
    End.

program sum_delit;
var
  n,koln,ost,min,max:longint;
begin
  {Assign(input,'input.txt');
  Reset(input);
  Assign(output,'output.txt');
  Rewrite(output);}

  readln(n);

  if n mod 7=0 then writeln((n div 7)*2,' ',(n div 7)*2)
  else begin
   koln:=(n div 7)*2; ost:=n mod 7;

   if ost=6 then min:=koln+1 else min:=koln;
   if ost=1 then max:=koln+1 else max:=koln+2;

   writeln(min,' ',max);

  end;

//Close(input); Close(output);
end.

var n,min,max:longint;
 begin
  readln(n);
  min:=2*(n div 7);
  max:=2*(n div 7);
  if n mod 7 = 6 then inc(min);
  if n mod 7 > 2 then inc(max,2)
                 else max:=max+ n mod 7;
 writeln(min,' ',max);
 end.

var n,min,max,a,b:integer;
begin
read(n);
a:=n div 7;
b:=n mod 7;
min:=a*2;
max:=a*2;
if b>5 then min:=a*2+1;
if (b>0) and (b<6) then
min:=a*2;
if b=1 then
max:=a*2+1;
if b>1 then
max:=a*2+2;
write(min,' ',max);
end.

var n,min,max,k,i,j,x:longint;
begin
    readln(n);
    min:=9545454;
    max:=0;
    for i:=1 to 7 do
     begin
     k:=0;
     for j:=1 to n do
      begin
        x:=(i+j-1)mod 7;
        if (x=0) or(x=6)then k:=k+1;
       end;
      if k<min then min:=k;
      if k>max then max:=k;
    end;
    writeln(min,' ',max);
end.

Program A350;
USES math;
CONST FINP = '1.INP';	FOUT = '1.OUT';
VAR fi, fo: text;
n, resmin, resmax: longint;
a: array[0..3000000] of longint;

Procedure Process;
Var i, j, k, tmp: longint;
BEGIN
readln(fi, n);
i := 0;
resmin := maxlongint;
while (i <= n + 10) do
	begin
	for j := i + 1 to i + 5 do a[j] := 0;
	for j := i + 6 to i + 7 do a[j] := 1;
	i := i + 7;
	end;
for i := 1 to 7 do
	begin
	tmp := 0;
	for j := i to i + n - 1 do if a[j] = 1 then inc(tmp);
	resmin := min(resmin, tmp);
	resmax := max(resmax, tmp);
	end;
writeln(fo, resmin, ' ', resmax);
END;

BEGIN
{$IFDEF ONLINE_JUDGE}
assign(fi, '');		assign(fo, '');
{$ELSE}
assign(fi, FINP);	assign(fo, FOUT);
{$ENDIF}
reset(fi);			rewrite(fo);
Process;
close(fi);
close(fo);
END.

uses math;
var c,n,k,i,j,l,f,flag,max1,min1:longint;
    ans:int64;
    a:array[1..100000] of longint;
    q,p:real;
    s:string;
begin
read(n); l:=2;
max1:=(n div 7)*2;
min1:=max1;
if n mod 7=6 then inc(min1);
inc(max1,min(l,n mod 7));
write(min1,' ',max1);
end.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
   d,n,kmin,i,kmax:integer;
begin
   readln(n);
   kmin:=0;
   kmax:=0;
   d:=1;
   for i:=1 to n do begin
      if((d=6)or(d=7))then inc(kmin);
      inc(d);
      if(d=8)then d:=1;
   end;
   d:=6;
   for i:=1 to n do begin
      if((d=6)or(d=7))then inc(kmax);
      inc(d);
      if(d=8)then d:=1;
   end;
   writeln(kmin,' ',kmax);
end.

var
        n,kq1,kq2:longint;
begin
        read(n);
        kq1:=0;
        kq2:=0;
        if n>5 then
                begin
                        kq1:=(n div 7)*2;
                        if n mod 7 =6 then
                                inc(kq1);
                end;
        if (n=1) or (n=2) then
                kq2:=n
        else
                begin
                        n:=n-2;
                        kq2:=(n div 7)*2+2;
                        if n mod 7 = 6 then
                                inc(kq2);
                end;

        write(kq1,' ',kq2);
end.

var
 n,x,y: longint;
begin
 readln(n);
 x:=n div 7*2;
 y:=x;
 if n mod 7 = 1 then y:=y+1 else
 if n mod 7 > 1 then y:=y+2;
 if n mod 7 = 6 then x:=x+1;
 writeln(x,' ',y);
end.

var
    n, min, max: LongInt;

begin
    Read (n);

    if n = 1 then
        WriteLn (0, ' ', 1)
    else
    begin
        max:= 2 * (n div 7);
        min:= max;

        if n mod 7 >= 2 then
            Inc (max, 2)
        else if n mod 7 = 1 then
            Inc (max);

        if n mod 7 = 6 then
            Inc (min);

        WriteLn (min, ' ', max)
    end
end.

var n:longint;
t1,t2:integer;
begin
        read(n);
        t1:=(n mod 7) div 5;
        if t1<=0 then t1:=0 else t1:=(n mod 7)-(t1*5);
        t2:=0;
        if n mod 7=1 then t2:=1 else
                if n mod 7>=2 then t2:=2;
        write((n div 7)*2+t1,' ',(n div 7)*2+t2);
end.

var
  a,b,i,n,k,j:int64;
begin
  read(n);
  if n mod 7=0 then begin writeln((n div 7)*2,' ' ,(n div 7)*2);halt;end;
  if n=1 then begin writeln(0,' ',1);halt;end;
  if n<=5 then begin writeln(0,' ',2);halt;end;
  if n=6 then begin writeln(1,' ',2);halt;end;
  if n mod 7=6 then begin writeln((n div 7)*2+1,' ',(n div 7)*2+2);halt;end;
  if (n mod 7>=2) and (n mod 7<6)  then begin writeln((n div 7)*2,' ',(n div 7)*2+2);halt;end;
  if (n mod 7<2) then begin writeln((n div 7)*2,' ',(n div 7)*2+1);halt;end;
end.

var n,max,m,min:Longint;
begin
    read(n);m := n-5;
    min := 0;max := 0;
    while (n>0) do
    begin
        if (n>=2) then max := max + 2
        else max := max + n;
        n := n - 7;
    end;
    while (m > 0) do
    begin
        if (m>=2) then min := min + 2
        else min := min + m;
        m:=m-7;
    end;
    write(min,#32,max);
end.

var n,a,b,s1,s2:int64;
begin
  readln(n);
  a:=n div 7;
  b:=n mod 7;
  s2:=a*2;
  if b>5 then write(s2+(b mod 5),' ')
         else write(s2,' ');

  if b>=2 then writeln(s2+2)
          else writeln(s2+b);
end.

var
        a:integer;
Begin
        Readln(a);
        if a mod 7=6 then
                write(1+((a div 7)*2),' ')
        else write((a div 7)*2,' ');
        if a mod 7=0 then
                Write((a div 7)*2);
        if a mod 7=1 then
                Write(((a div 7)*2)+1);
        if a mod 7>=2 then
                Write(((a div 7)*2)+2);
        Readln;
End.

var
  n, s0, cmin, cmax, m: integer;

begin

  read(n);

  s0 := n div 7;
  m := n mod 7;
  if m = 0 then begin
    cmin := s0 * 2;
    cmax := cmin;
  end;
  if m = 1 then begin
    cmax := s0 * 2 + 1;
    cmin := s0 * 2;
  end;
  if (m >= 2) and (m <= 5) then begin
    cmax := s0 * 2 + 2;
    cmin := s0 * 2;
  end;
  if m = 6 then begin
    cmax := s0 * 2 + 2;
    cmin := s0 * 2 + 1;
  end;
  write(cmin, ' ', cmax);

end.

uses math;
var n,w,o:longint;
begin
    readln(n);
    w:=n div 7;
    o:=n mod 7;
    write(2*w+ord(o=6),' ',2*w+min(2,o));
    readln;
end.

var i,n,s:longint;
begin
{ assign(input,'input.txt');
 assign(output,'output.txt');
 reset(input);
 rewrite(output);
                   }
 readln(n);
 s:=n div 7;
 if (n mod 7>1) and (n mod 7 <>6) then
  writeln(s*2,' ',s*2+2);
 if n mod 7=1 then writeln(s*2,' ',s*2+1);
 if n mod 7=6 then writeln(s*2+1,' ',s*2+2);
if n mod 7=0 then writeln(s*2,' ',s*2);
{ close(input);
 close(output);
                 }
 end.

 var n,s,d:longint;
begin
 readln(n);
  s:=n div 7;
  d:=n mod 7;
  if d=1 then write(s*2,' ',s*2+1);
  if (d>=2) and (d<6) then write(s*2,' ',s*2+2);
  if d=6 then write(s*2+1,' ',s*2+2);
  if d=0 then write(s*2,' ',s*2);
end.

var
   n,x,y:integer;
begin
     readln(n);
     x:=n div 7;
     y:=n mod 7;
     if y=6 then
        write(x*2+1,' ')
     else
         write(x*2,' ');
     if y=1 then
        write(x*2+1)
     else if y<>0 then
         write(x*2+2)
     else
         write(x*2);
end.

var n,k,mi:integer;
begin
read(n);
k:=(n div 7)*2;
mi:=k;
if n mod 7>=2 then k:=k+2
else if n mod 7=1 then k:=k+1;
if n mod 7=6 then mi:=mi+1;
write(mi,' ',k);
end.

const
   fin='670A.inp';fon='670A.out';
var n,k:longint;
procedure mo;
begin
assign(input,fin);reset(input);
assign(output,fon);rewrite(output);
end;

procedure solve;
begin
readln(n);
k:=n mod 7;
case k of
   6: writeln(n div 7 * 2 + 1,' ',n div 7 * 2 + 2);
   0: writeln(n div 7 * 2,' ',n div 7 * 2);
   5,4,3,2: writeln(n div 7 * 2,' ',n div 7 * 2 + 2);
   1: writeln(n div 7 * 2,' ',n div 7 * 2 + 1);
   end;
end;

begin
//mo;
solve;
end.

var
  a,s,d:integer;
begin
  read(a);
  d:=(a div 7)*2;
  if ((a mod 7) > 5) then
     inc (d,a mod 7 - 5);
  s:=a div 7 * 2;
  if a mod 7 = 1 then
     inc(s, 1)
  else if a mod 7 >= 2 then
     inc(s,2);
  writeln(d, '  ', s);
end.

var n,min,max,k,i,j,x:longint;
begin
    readln(n);
    min:=9545454;
    max:=0;
    for i:=1 to 7 do
     begin
     k:=0;
     for j:=1 to n do
      begin
        x:=(i+j-1)mod 7;
        if (x=0) or(x=6)then k:=k+1;
       end;
      if k<min then min:=k;
      if k>max then max:=k;
    end;
    writeln(min,' ',max);
end.

uses
   math;
var
   a,b,n:longint;
   arr:array[0..100000] of longint;

begin
   readln(n);
   a:=2*(n div 7);
   if (n mod 7)>=2 then
      a:=a+2
   else
      a:=a + (n mod 7);

   b:=2*(n div 7);
   if n>=7 then
   begin
   if n mod 7=6 then
      b:=b+1
   end
   else
   if n=6 then
      b:=1;
   writeln(b,' ',a);
end.

program z2;
var n:longint;i,b,c,d:integer;
begin
read(n);
c:=n;
d:=0;
if n<=5 then
if n>2 then begin d:=d+2;write(0,' ',d);exit;end
else begin d:=d+n;write(0,' ',d);exit;end;
if n=6 then begin write(1,' ',2);exit;end;
while c>=7 do begin
c:=c-7;b:=b+2;end;
if c=6 then inc(b);
while n>=7 do begin
n:=n-7;d:=d+2;end;
if n>0 then
if n>2 then d:=d+2
else d:=d+n;
write(b,' ',d);
end.

var n: longint;
    i,j,omin,omax: longint;

begin
  readln(n);
  omin:= (n div 7)*2;
  omax:=omin;
  i:= n mod 7;
  if (i>2) then omax:=omax+2;
  if i<=2 then omax:=omax+i;
  if i=6 then omin:=omin+1;
  writeln(omin,' ',omax);
end.

uses math;
var c,n,k,i,j,l,f,flag,max1,min1:longint;
    ans:int64;
    a:array[1..100000] of longint;
    q,p:real;
    s:string;
begin
read(n); l:=2;
max1:=(n div 7)*2;
min1:=max1;
if n mod 7=6 then inc(min1);
inc(max1,min(l,n mod 7));
write(min1,' ',max1);
end.

var n,m,dem,max,min:longint;
begin
 readln(n); m:=n; dem:=0;
 while n <> 0 do
  begin
   inc(dem); dec(n);
   if (dem = 6) or (dem = 7) then
    begin
     inc(min);
     if dem = 7 then dem:=0;
    end;
  end;
 n:=m; dem:=0;
 if n = 1 then begin inc(max); dec(n); end;
 if n > 1 then begin inc(max,2); dec(n,2); end;
 while n <> 0 do
  begin
   inc(dem); dec(n);
   if (dem = 6) or (dem = 7) then
    begin
     inc(max);
     if dem = 7 then dem:=0;
    end;
  end;
 write(min,' ',max);
end.

uses math;
var mi,ma,m,n,k:longint;

begin
readln(n);
m:=n div 7;k:=n mod 7;
ma:=min(2,k);
if k>5 then mi:=k-5;
writeln(mi+m*2,' ',ma+m*2);
end.

var n,v:integer;
begin
    read(n);
    v:=n div 7*2;
    n:=n mod 7;
    if n<3 then write(v,' ',v+n)
    else
    if n<6 then write(v,' ',v+2)
    else write(v+1,' ',v+2)
end.

Program qq;
Var mn,mx,b,n:LongInt;
Function Min(x,y:LongInt):LongInt;
begin
  If x<y
   then min:=x
   else min:=y;
end;
begin
Read(N);
b:=N div 7;
Inc(mx,b*2);
Inc(mx,min(n mod 7,2));
Inc(mn,b*2);
If n mod 7>5
 then Inc(mn,7-n mod 7);
Write(mn,' ',mx);
end.

var a, i, b, j, min, max, c : longint;
begin
   readln(a);
   min := a;
   max := 0;
   for j := 1 to 7 do
   begin
      b := j;
      c := 0;
      for i := 1 to a do
      begin
         if (b = 6) or (b = 7) then
            inc(c);
         inc(b);
         if b = 8 then
            b := 1;
      end;
      if max < c then
         max := c;
      if min > c then
         min := c;
   end;
   writeln(min, ' ', max);
end.

var n,min,max:longint;
 begin
  readln(n);
  min:=2*(n div 7);
  max:=2*(n div 7);
  if n mod 7 = 6 then inc(min);
  if n mod 7 > 2 then inc(max,2)
                 else max:=max+ n mod 7;
 writeln(min,' ',max);
 end.

program ex670a;
var n,max,min,a,b:integer;
begin
readln (n);
a:=n div 7;
b:=n mod 7;
max:=a*2;
if (b=1) then max:=max+1;
if (b>1) then max:=max+2;
min:=a*2;
if (b=6) then min:=min+1;
writeln (min,' ',max);
end.

var
n,max,min,NUM:integer;
Begin
read(n);
max:=(n div 7)*2;
if n mod 7=1 then max:=max+1;
NUM:=n mod 7;
min:=(n div 7)*2;
if n mod 7=6 then min:=min+1;
case NUM of
0:writeln(min,' ',max);
1:writeln(min,' ',max);
2..6:writeln(min,' ',max+2);
end;
end.

var nn,ln,n:integer;
begin
 read(n);
 if n=6 then nn:=1
 else if n>=7 then nn:=(((n div 7)*7) div 7)*2;
 if n=1 then ln:=1
 else if (n>=2) and (n<7) then ln:=2
 else if n>=7 then ln:=n-(n div 7)*5;
 write(nn,' ',ln);
end.

 var n,k:longint;
begin
  readln(n);
  k:=n div 7;
  k:=k*2;
  if n mod 7 = 6 then
    k:=k+1;
  if n>=7 then
  writeln(k,' ',k);
  if n<7 then
    if n=6 then
     writeln(1,' ',2)
     else
       if n>=3 then
       writeln(0,' ',2)
       else
         writeln(0,' ',n);
 readln
end.

var nn,ln,n:integer;
begin
 read(n);
 nn:=(n div 7)*2;
 ln:=n-((n div 5)*5);
 write(nn,' ',ln);
end.

var nn,ln,n:integer;
begin
 read(n);
 if n=6 then nn:=1
 else if n>=7 then nn:=(((n div 7)*7) div 7)*2;
 if n=1 then ln:=1
 else if (n>=2) and (n<7) then ln:=2
 else ln:=n-(n div 5)*5;
 write(nn,' ',ln);
end.

var
x,y,z:integer;
begin
	readln(x);
	y:=(x div 7)*2;
	if (x mod 7 = 6)then y:=y+1;
	if x=1 then z:=1 else begin
		z:=2;
		x:=x-2;
		z:=z+(x div 7)*2;
		if (x mod 7 = 6)then z:=z+1;
		writeln(x);
	end;
	writeln(y,' ',z);
end.

var n,min,max:longint;
 begin
  readln(n);
  min:=2*(n div 7);
  max:=2*(n div 7);
  if n = 6 then inc(min);
  if n mod 7 > 2 then inc(max,2)
                 else max:=max+ n mod 7;
 writeln(min,' ',max);
 end.

var nn,ln,n:integer;
begin
 read(n);
 if n=1 then nn:=1
 else if n=2 then nn:=2
 else if n>7 then nn:=n-(n div 5)*5;
 if n=1 then ln:=1
 else if (n>=2) and (n<7) then ln:=2
 else ln:=(n div 7)+2;
 write(nn,' ',ln);
end.

var n, mi, ma : Integer;
begin
  readln(n);
  ma := (n div 7) * 2;
  mi := ma;
  If n < 6 then mi := 0;
  If (n + 1) mod 2 = 0 then mi := mi + 1;
  If n mod 7 > 1 then ma := ma + 2;
  If n mod 7 = 1 then ma := ma + 1;
  writeln(mi,' ',ma);
end.

const fi='';
        fo='';

procedure doc;
var i,d,n,d1:longint;
begin
        assign(input,fi);reset(input);
        readln(n); close(input);
        d:=0; i:=0; d1:=2;
        while i<=n do begin
                i:=i+7;
                if i<=n then d:=d+2
                else if i=n+1 then d:=d+1;
                if i<=n-2 then d1:=d1+2
                else if i=n-1 then d1:=d1+1;
        end;
        {i:=2; d1:=2;
        while i<=n do begin
                i:=i+7;
                if i<=n then d1:=d1+2
                else if i=n+1 then d1:=d1+1;
        end;}
        assign(output,fo);rewrite(output);
        writeln(d,' ',d1);close(output);
end;

begin
        doc;
end.

var n,a,b,s1,s2:int64;
begin
  readln(n);
  a:=n div 7;
  b:=n mod 7;
  s1:=a*5;
  s2:=a*2;
  if b>5 then writeln(s1+5,' ',s2+b mod 5)
         else writeln(s2,' ',s2+b);
end.

var
l,d,k,n:longint;

begin
readln(n);
l:=(n div 7 )*2;
write(l,' ');

d:=n-2;
k:=(d div 7)*2+2;
if (d mod 5)>1 then k:=k+2 ;
if (d mod 5 )=1 then k:=k+1 ;
write(k);

end.

program holidays;
var n,x:longint;
begin
     readln(n);
     if (n mod 7=0) then writeln(2*(n div 7),' ',2*(n div 7))
     else begin
               x:=n-(n div 7)*7;
               if x=1 then writeln(2*(n div 7),' ',2*(n div 7)+1);
               if x>=2 then writeln(2*(n div 7),' ',2*(n div 7)+2);
     end;
end.

var n:longint;
begin
        read(n);
        if n-5>=0 then write((n-5) mod 5,' ',n mod 5) else write(0,' ',n mod 5);
end.

var n:longint;
t1,t2:integer;
begin
        read(n);
        t1:=(n mod 7) div 5;
        if t1<=0 then t1:=0 else t1:=(n mod 7)-(t1*5);
        t2:=(n mod 7) div 2;
        if t2<=0 then t2:=0 else t2:=1;
        write((n div 7)*2+t1,' ',(n div 7)*2+t2*2);
end.

 var n,k:longint;
begin
  readln(n);
  k:=n div 7;
  k:=k*2;
  if n mod 7 = 6 then
    k:=k+1;
  if (n>=7) and (n mod 7 >= 2) then
  writeln(k,' ',k+2)
  else
    if n>=7 then
    writeln(k,' ',k+(n mod 7));
    if n=6 then
     writeln(1,' ',2)
     else
       if (n>=3) and (n<7) then
       writeln(0,' ',2)
       else
         if n<3 then
         writeln(0,' ',n);
 readln
end.

var
  n,min,max:longint;
begin
  read(n);
  min:=(n div 7)*2;max:=min;
  if n mod 7=1 then max:=max+1;
   if n mod 7=2 then max:=max+2;
  n:=n - (min div 2)*7-5;
  if n>0 then min:=min+n;
  write(min, ' ',max);
end.

var
 n,a,b,nghi:longint;
begin
  readln(n);
  a:=n div 7;
  b:=n mod 7;
  if (b>=2) then b:=a+2
  else b:=a+b;
  writeln(a,' ',b);
end.

uses math;
var n,i,maxi,mini,t1,t2,t3,t4,t5,t6,t7,id1,id2,id3,id4,id5,id6,id7:longint;
begin
readln(n);
inc(id6);inc(id7);
for i:=2 to n do
begin
inc(t1);inc(t2);inc(t3);inc(t4);inc(t5);inc(t6);inc(t7);
if t1>7 then t1:=1;
if t2>7 then t2:=1;if t3>7 then t3:=1;
if t4>7 then t4:=1;if t5>7 then t5:=1;
if t6>7 then t6:=1;if t7>7 then t7:=1;
if (t1=6)or(t1=7)then inc(id1);
if (t2=6)or(t2=7)then inc(id2);
if (t3=6)or(t3=7)then inc(id3);
if (t4=6)or(t4=7)then inc(id4);
if (t5=6)or(t5=7)then inc(id5);
if (t6=6)or(t6=7)then inc(id6);
if (t7=6)or(t7=7)then inc(id7);
end;
maxi:=max(id1,max(id2,max(id3,max(id4,max(id5,max(id6,id7))))));
mini:=min(id1,min(id2,min(id3,min(id4,min(id5,min(id6,id7))))));
writeln(mini,' ',maxi);
end.

var
 n,a,b,nghi:longint;
begin
  readln(n);
  a:=n div 7;   a:=a*2;
  b:=n mod 7;
  if (b>=2) then b:=a+2
  else b:=a+b;
  if (b=6) then inc(a);
  writeln(a,' ',b);
end.

var n,i,max,min,t1,t2,id1,id2:longint;
begin
readln(n);
inc(max);
t1:=1;t2:=6;
for i:=1 to n do
begin
inc(t1);inc(t2);
if t1>7 then t1:=1;
if t2>7 then t2:=1;
if (t1=6)or(t1=7)then inc(min);
if (t2=6)or(t2=7)then inc(min);
end;
writeln(min,' ',max);
end.

var nn,ln,n:integer;
begin
 read(n);
 if n=6 then nn:=1
 else if n>=7 then nn:=(((n div 7)*7) div 7)*2;
 if n=1 then ln:=1
 else if n=2 then ln:=2
 else if n>=7 then ln:=n-(n div 7)*5;
 write(nn,' ',ln);
end.

var
x,y,z:integer;
begin
	readln(x);
	y:=(x div 7)*2;
	if (x mod 7 = 6)then y:=y+1;
	if x=1 then z:=1 else begin
		z:=2;
		x:=x-2;
		z:=z+(x div 7)*2;
		if (x mod 7 = 6)then x:=z+1;
	end;
	writeln(y,' ',z);
end.

var
 n,min,max,x : longint ;

begin
 readln (n) ;
 x := n div 7 ;
 if n mod 7 = 0 then
  begin
   min := x * 2 ;
   max := min ;
  end
 else if (n mod 2 = 0) or (n-1 mod 2 = 0) then
  begin
   min := x * 2 ;
   max := min + 2 ;
  end
 else
  begin
   min := x * 2 ;
   max := min + 1 ;
  end;
 writeln (min,' ',max) ;
end.

Const Finp='';
      Fout='';
Var n,min,max:longint;

Procedure Nhap;
Var f:Text;
Begin
    assign(f,finp); reset(f);
    read(f,n);
    close(f);
End;
Procedure Tinh;
Begin
    min:=(n div 7)*2; max:=(n div 7)*2;
    if n mod 7>=2 then inc(max,2);
    if n mod 7=1 then inc(max);
End;
Procedure Xuat;
Var f:Text;
Begin
    assign(f,fout); rewrite(f);
    write(f,min,' ',max);
    close(f);
End;

Begin
    nhap;
    tinh;
    xuat;
End.

var
 n,min,max,x : longint ;

begin
 readln (n) ;
 x := n div 7 ;
 if n mod 7 = 0 then
  begin
   min := x * 2 ;
   max := min ;
  end
 else if n mod 2 = 0 then
  begin
   min := x * 2 ;
   max := min + 2 ;
  end;
 writeln (min,' ',max) ;
end.

var a,b,n,min,max:longint;
begin
readln(n);
a:=n div 7;
b:=n mod 7;
if b<=2 then begin
             min:=a*2;
             max:=a*2+b;
             end
        else if b>=5 then begin
                          min:=a*2+(7-b);
                          max:=a*2+2;
                          end
                     else begin
                          min:=a*2;
                          max:=a*2+2;
                          end;
write(min,' ',max);
end.

var
 n,min,max,x : longint ;

begin
 readln (n) ;
 x := n div 7 ;
 if n mod 7 = 0 then
  begin
   min := x * 2 ;
   max := min ;
  end
 else if n mod 2 = 0 then
  begin
   min := x * 2 ;
   max := min + 2 ;
  end
 else
  begin
   min := x * 2 ;
   max := min + 1 ;
  end;
 writeln (min,' ',max) ;
end.

var n,a,b,min,max:integer;
Begin
readln(n);
if n mod 7 =0 then begin
  min:= (n div 7) *2;
  max:=min;
  end
else begin
  min:=(n div 7) *2;
  if n div 7 = 1 then
  max:=min + 1
  else max:=min+2;
  end;
writeln(min,' ',max);
End.

var nn,ln,n:integer;
begin
 read(n);
 if n=6 then nn:=1
 else if n>=7 then nn:=(((n div 7)*7) div 7)*2;
 if n=1 then ln:=1
 else if (n>=2) and (n<7) then ln:=2
 else ln:=n-(n div 5)*5;
 write(nn,' ',ln);
end.

var n, mi, ma : Integer;
begin
  readln(n);
  mi := (n div 7) * 2;
  If n = 6 then mi := 1;
  ma := mi;
  If n mod 7 > 1 then ma := ma + 2;
  If n mod 7 = 1 then ma := ma + 1;
  writeln(mi,' ',ma);
end.

var n,min,max:longint;
 begin
  readln(n);
  min:=2*(n div 7);
  max:=2*(n div 7);
  if n = 6 then inc(max);
  if n mod 7 > 2 then inc(max,2)
                 else max:=max+ n mod 7;
 writeln(min,' ',max);
 end.

var n, m, k,i, o, p, l, j, ans, min, max:LongInt;

 Begin
   Read(n);
   if n mod 7=0 then BEgin min:= (n div 7)*2; max:= (n div 7)*2;End;
   if (n mod 7=1)  then BEGin min:=(n div 7)*2; max:=(n div 7)*2+n mod 7;End
   else BEgin min:=(n div 7)*2; max:=(n div 7)*2 +2;End;

   WriteLn(min,' ', max);

 End.

var
  n:longint;
begin
 readln(n);
 if n mod 7 = 0
   then writeln(2*(n div 7),' ',2*(n div 7))
    else
      if (n mod 7 = 6)
        then
          write(2*(n div 7)+1,' ')
        else
          write (2*(n div 7),' ');
 if n mod 7 > 1
   then writeln(2*(n div 7)+2)
   else writeln(2*(n div 7)+1)

//(2*(n div 7))+(n mod 7)
end.

var n,min,max:longint;
 begin
  readln(n);
  min:=2*(n div 7);
  max:=2*(n div 7);
  if n = 6 then inc(min);
  if n mod 7 > 2 then inc(max,2)
                 else max:=max+ n mod 7;
 writeln(min,' ',max);
 end.

var
 n:longint;
begin
  readln(n);
  if n mod 5 <> 2
    then
      write((n div 5)*1,' ')
    else
      write((n div 5)*2,' ');
  if n mod 7 = 0
    then writeln((n div 7)*2)
    else if n mod 7 > 1
      then writeln((n div 7)*2+2)
      else writeln((n div 7)*2+1)
end.

var
 n,min,max : longint;

begin
 readln(n);
 min := (n div 7) * 2;
 max := min;
 if n mod 7 = 1 then
  max := min + 1
 else if n mod 7 > 1 then
  max := min + 2;
 writeln(min,' ',max);
end.

var n,min,max:longint;
begin
 read(n);
 min:=(n div 7)*2;
 max:=min;
 if n mod 7=1
  then max:=max+1;
 if n mod 7>1
  then max:=max+2;
 write(min,' ',max);
end.

var
l,k,n:longint;

begin
readln(n);
l:=(n div 7 )*2;
write(l,' ');

k:=n-2;
k:=(k div 7)*2+2;
write(k);

end.

program z4;
var a:array[1..100]of integer;i:byte;
begin
for i:=1 to 100 do
if i mod 2=0 then a[i]:=0
else a[i]:=1;
for i:=1 to 100 do
write(a[i],' ');
end.

var n, mi, ma : Integer;
begin
  readln(n);
  ma := (n div 7) * 2;
  mi := ma;
  If n = 6 then mi := 1;
  If n mod 7 > 1 then ma := ma + 2;
  If n mod 7 = 1 then ma := ma + 1;
  writeln(mi,' ',ma);
end.

var n,max,min:longword;
begin
Readln(N);
if N mod 7 = 0 then begin Writeln((N div 7)*2,' ',(N div 7)*2); exit; end;
max:=(N div 7)*2+ ((N mod 7) mod 3);
min:=(N div 7)*2 + (N mod 7) div 6;
Writeln(min,' ',max);
end.

var
i,otv,otv1,n,q:longint;
begin
readln(N);
for i:=1 to n do begin
    if i mod 6 = 0 then inc(otv);
    if i mod 7=0 then inc(otv);
end;
if n>=2 then begin
    otv1:=2;
    n:=n-2;
end;
if n=1 then begin
    otv1:=1;
    dec(n);
end;
for i:=1 to n do begin
if i mod 7 = 0  then inc(otv1);
if  i mod 8 = 0 then inc(otv1);
end;
writeln(otv,' ' ,otv1);
end.

var n,h,cnt,cnta:longint;
begin
 readln(n);
 for h:=1 to n do
  begin
   if ((h mod 7)= 6) or ((h mod 7)= 5) then inc(cnt);
  end;
 for h:=1 to n do
  begin
   if ((h mod 7)= 0) or ((h mod 7) = 1) then inc(cnta);
  end;
 writeln(cnt,cnta);
end.

var
n:longint;
begin
readln(n);
if n=1  then writeln('0 1')
else

if (n<=5)and(n<>1) then writeln('0 2')
else
if n=6 then writeln('1 2')
else
if n=7 then writeln('2 2')
else
begin
    if n mod 7=0 then
    writeln(2*(n div 7),' ', 2*(n div 7))
    else
    writeln(2*(n div 7),' ',2*(n div 7)+1);

end;
end.

var
 n,a,b,nghi:longint;
begin
  readln(n);
  a:=n div 7;
  b:=n mod 7;
  if (b>=2) then b:=a+2
  else b:=a+b;
  writeln(a,' ',b);
end.

var
    n, min, max: LongInt;

begin
    Read (n);

    if n = 1 then
        WriteLn (0, ' ', 1)
    else
    begin
        max:= 2 * n div 7;
        min:= max;

        if n mod 7 >= 2 then
            Inc (max, 2)
        else if n mod 7 = 1 then
            Inc (max);

        if n mod 7 = 6 then
            Inc (min);

        WriteLn (min, ' ', max)
    end
end.

var
otv1,q,n,nn,otv:longint;
begin
readln(n);
nn:=n;
q:=n div 7;
nn:=nn mod 7;
if nn=6 then inc(otv);
otv:=otv+2*q;
writeln(otv);
if n>=2 then begin
    otv1:=2;
    n:=n-2;
end;
if n=1 then begin
    otv1:=1;
    dec(n);
end;
q:=n div 7;
if n mod 7 = 6 then inc(otv1);
otv1:=otv1+2*q;
writeln(otv,' ',otv1);
end.

var
 n,min,max,x : longint ;

begin
 readln (n) ;
 x := n div 7 ;
 if n mod 7 = 0 then
  begin
   min := x * 2 ;
   max := min ;
  end
 else if ((n mod 2 = 0) or (n-1 mod 2 = 0)) and (n <> 1) then
  begin
   min := x * 2 ;
   max := min + 2 ;
  end
 else
  begin
   min := x * 2 ;
   max := min + 1 ;
  end;
 writeln (min,' ',max) ;
end.

var
 n,a,b,nghi:longint;
begin
  readln(n);
  a:=n div 7;   a:=a*2;
  b:=n mod 7;
  if (b>=2) then b:=a+2
  else b:=a+b;
  if (b=6) then inc(a);
  writeln(a,' ',b);
end.

const fi='';
        fo='';

procedure doc;
var i,d,n,d1:longint;
begin
        assign(input,fi);reset(input);
        readln(n); close(input);
        d:=0; i:=0;
        while i<=n do begin
                i:=i+7;
                if i<=n then d:=d+2
                else if i=n+1 then d:=d+1;
        end;
        i:=2; d1:=2;
        while i<=n do begin
                i:=i+7;
                if i<=n then d1:=d1+2
                else if i=n+1 then d1:=d1+1;
        end;
        assign(output,fo);rewrite(output);
        writeln(d,' ',d1);close(output);
end;

begin
        doc;
end.

USES Math;
CONST
    tfi = '';
    tfo = '';
VAR
    fi,fo               : text;
    n,res               : int64;

BEGIN
    assign(fi,tfi); reset(fi);
    assign(fo,tfo); rewrite(fo);
        Read(fi,n);
        res:=n div 7;
        write(fo,res*2,' ',res*2+min(n-res*7,2));
    close(fi); close(fo);
END.

var n:int64;
begin
read(n);
writeln((n div 7)*2,' ',((n-2) div 7)*2+2);
end.

program z1;
var
  n, min, max : integer;
begin
  read(n);
  min := n div 7 * 2;
  if (n > 2) then max := (n - 2) div 7 * 2 + 2;
  if (n = 1) then max := (n - 1) div 7 * 2 + 1;
  if (n = 0) then max := 0;
  write(min,' ',max);
end.

var nn,ln,n:integer;
begin
 read(n);
 nn:=(n div 7)*2;
 ln:=n-((n div 5)*5);
 write(nn,' ',ln);
end.

program abc;
var
max,min,n:longint;
begin
readln(n);
max:=(n-2)div 7*2+2;
if n<2 then max:=n;
min:=n div 7*2;
writeln(min,' ',max);
end.

var
 n,x,y: longint;
begin
 readln(n);
 x:=n div 7*2;
 y:=x;
 if n mod 7 <> 0 then
 begin
  if n mod 7 = 6 then y:=y+3 else
  if n mod 7 < 6 then y:=y+2;
 end;
 writeln(x,' ',y);
end.

var n:longint;
begin
readln(n);
if n mod 7=0 then begin write(2*(n div 7),' ',2*(n div 7)); exit; end;
if n mod 7=1 then write((n div 7)*2,' ',2*(n div 7)+1);
if (n mod 7>1)and(n mod 7<6) then write((n div 7)*2,' ',2*(n div 7)+2);
if n mod 7=6 then write((n div 7)*2+1,' ',2*(n div 7));
end.

var
        a:integer;
Begin
        Readln(a);
        write(((a div 7)*2),' ');
        if a mod 7=0 then
                Write((a div 7)*2);
        if a mod 7=1 then
                Write(((a div 7)*2)+1);
        if a mod 7>=2 then
                Write(((a div 7)*2)+2);
        Readln;
End.

const fi = '';
      fo = '';
var i, j, n: longint;
begin
  assign(input,fi);      reset(input);
  assign(output,fo);      rewrite(output);

  readln(n);
  if n = 1 then j:=1 else j:=2+((n-2) div 7)*2;
  i:=(n div 7)*2;  if n mod 7 = 6 then inc(i);
  writeln(i,' ',j);

  close(input);         close(output);
end.

var
n,max,min,NUM:integer;
Begin
read(n);
max:=(n div 7)*2;
if n mod 7=1 then max:=max+1;
NUM:=n mod 7;
min:=(n div 7)*2;
case NUM of
0:writeln(min,' ',max);
1:writeln(min,' ',max);
2..6:writeln(min,' ',max+2);
end;
end.

var nn,ln,n:integer;
begin
 read(n);
 if n=6 then nn:=1
 else if n>=7 then nn:=(((n div 7)*7) div 7)*2;
 if n=1 then ln:=1
 else if n=2 then ln:=2
 else if n>=7 then ln:=n-(n div 7)*5;
 write(nn,' ',ln);
end.

var nn,ln,n:integer;
begin
 read(n);
 nn:=(n div 7)*2;
 ln:=((n-2)-(((n-2) div 5)*5))+2;
 write(nn,' ',ln);
end.

program holidays;
var
	d	: integer;
	max	: integer;
	min	: integer;
begin
	readln(d);
	if ((d mod 7)=0) then
	begin
		min := 2*(d div 7);
		max := min;
	end else if ((d mod 7)=6) then
	begin
		min := (2*(d div 7))+1;
		max := (2*(d div 7))+2;
	end else
	begin
		min := (2*(d div 7));
		max := (2*(d div 7))+2;
	end;
	writeln(min,' ',max);
end.

type    int     =       longint;
var     n,t,m,a,b     :       int;
begin
     readln(n);
     t := n div 7;
     m := n mod 7;
     if m=0 then
       begin
           a := t*2; b := a;
       end else
     if m=1 then
       begin
           a := t*2; b := a+1;
       end else
       begin
           a := t*2; b := a+2;
       end;
     writeln(a,' ',b);

end.

var nn,ln,n:integer;
begin
 read(n);
 if n=1 then nn:=1
 else if n=2 then nn:=2
 else if n>7 then nn:=n-(n div 5)*5;
 if n=1 then ln:=1
 else if (n>=2) and (n<7) then ln:=2
 else ln:=(n div 7)+2;
 write(nn,' ',ln);
end.

program z1;
var
  n, min, max : integer;
begin
  read(n);
  min := n div 7 * 2;
  if (n > 2) then max := (n - 2) div 7 * 2 + 2;
  if (n = 1) then max := (n - 1) div 7 * 2 + 1;
  if (n = 0) then max := 0;
  max := n div 7 * 2 + 2;
  write(min,' ',max);
end.

var
    n, min, max: LongInt;

begin
    Read (n);

    if n = 1 then
        WriteLn (0, 1)
    else
    begin
        max:= 2 * n div 7;
        min:= max;

        if n mod 7 >= 2 then
            Inc (max, 2)
        else if n mod 7 = 1 then
            Inc (max);

        if n mod 7 = 6 then
            Inc (min);

        WriteLn (min, ' ', max)
    end
end.

const fi = '';
      fo = '';
var i, j, n: longint;
begin
  assign(input,fi);      reset(input);
  assign(output,fo);      rewrite(output);

  readln(n);
  if n = 1 then j:=1 else j:=2+((n-2) div 7)*2;  if n-2 mod 7 = 6 then inc(j);
  i:=(n div 7)*2;  if n mod 7 = 6 then inc(i);
  writeln(i,' ',j);

  close(input);         close(output);
end.

program z1;
var
  n, min, max : integer;
begin
  read(n);
  min := n div 7 * 2;
  if (n mod 7 = 6) then inc(min);
  if (n >= 2) then max := (n - 2) div 7 * 2 + 2;
  if (n = 1) then max := (n - 1) div 7 * 2 + 1;
  if (n = 0) then max := 0;
  if (n mod 7 = 1) then inc(max);
  write(min,' ',max);
end.

var
        a:integer;
Begin
        Readln(a);
        if a mod 7=6 then
                write(1,' ')
        else write((a div 7)*2,' ');
        if a mod 7=0 then
                Write((a div 7)*2);
        if a mod 7=1 then
                Write(((a div 7)*2)+1);
        if a mod 7>=2 then
                Write(((a div 7)*2)+2);
        Readln;
End.

program z2;
var n:longint;i,b,c,d:integer;
begin
read(n);
c:=n;
d:=0;
if n<=5 then
if n>2 then begin d:=d+2;write(0,' ',d);exit;end
else begin d:=d+n;write(0,' ',d);exit;end;
if n=6 then begin write(1,' ',2);exit;end;
while c>=7 do begin
c:=c-7;b:=b+2;end;
while n>=7 do begin
n:=n-7;d:=d+2;end;
if n>0 then
if n>2 then d:=d+2
else d:=d+n;
write(b,' ',d);
end.

var n:longint;
begin
readln(n);
if n mod 7=0 then begin write(2*(n div 7),' ',2*(n div 7)); exit; end;
if n mod 7=1 then write((n div 7)*2,' ',2*(n div 7)+1) else write((n div 7)*2,' ',2*(n div 7)+2);
end.

var
n,q:longint;
begin
readln(N);
write(2*(n div 7));
write(' ');

if n mod 7>=2 then q:=2;
if n mod 7=1 then q:=1;
writeln(2*(n div 7)+q);
end.

var n,min,max:longint;
 begin
  readln(n);
  min:=2*(n div 7);
  max:=2*(n div 7);
  if n = 6 then inc(min);
  if n mod 7 > 2 then inc(max,2)
                 else max:=max+ n mod 7;
 writeln(min,' ',max);
 end.

var
 n,x,y: longint;
begin
 readln(n);
 x:=n div 7*2;
 y:=x+n mod 7;
 writeln(x,' ',y);
end.

var n,mi,ma,a,b,c:integer;
begin
readln(n);
a:=n div 7; b:=a*2;
mi:=b; ma:=b;
c:=n mod 7;
if (c>0) then if c=1 then ma:=ma+1 else if (c<=5) then ma:=ma+2 else if c=6 then begin mi:=mi+1; ma:=ma+1; end;
write(mi,' ',ma);
end.

var n,h,cnt,cnta:longint;
begin
 readln(n);
 for h:=1 to n do
  begin
   if ((h mod 7)= 6) or ((h mod 7)= 5) then inc(cnt);
  end;
 for h:=1 to n do
  begin
   if ((h mod 7)= 2) or ((h mod 7) = 1) then inc(cnta);
  end;
 writeln(cnt,cnta);
end.

var n, m, k,i, o, p, l, j, ans, min, max:LongInt;

 Begin
   Read(n);
   if n mod 7=0 then BEgin min:= (n div 7)*2; max:= (n div 7)*2;WriteLn(min,' ', max);HAlt;End;
   if (n mod 7=1)  then BEGin min:=(n div 7)*2; max:=(n div 7)*2+n mod 7;End
   else BEgin min:=(n div 7)*2; max:=(n div 7)*2 +2;End;

   WriteLn(min,' ', max);

 End.

var nn,ln,n:integer;
begin
 read(n);
 if n=6 then nn:=1
 else if n>=7 then nn:=(((n div 7)*7) div 7)*2;
 if n=1 then ln:=1
 else if (n>=2) and (n<7) then ln:=2
 else ln:=n-(n div 5)*5;
 write(nn,' ',ln);
end.

var
  a,s,d:integer;
begin
  read(a);
  d:=(a div 7)*2;
  if ((a mod 7) > 5) then
     inc (d,a mod 7 - 5);
  s:=a div 7 * 2;
  if a mod 7 < 3 then
     inc(s, a mod 7);
  writeln(d, '  ', s);
end.

{$MODE OBJFPC}
program dream_hyojoo;
uses math;
var   n:int64;
begin
       readln(n);
       writeln(n div 7*2,' ',n div 7*2 +min(n mod 7,2))
end.


This problem was deleted from the contest, because it was used previously at another competition.

{$MODE OBJFPC}
{$R-,Q-,S-,I-}
{$OPTIMIZATION LEVEL2}
program LineCount;
const
  InputFile  = '';
  OutputFile = '';
  maxXY = Round(1E5);
  maxP = 6;
var
  m, n, l, h: Integer;
  divisor: array[1..maxXY] of Integer;
  res: Int64;
  fi, fo: TextFile;
  hash: Integer;

procedure Init;
var
  i, j: Integer;
begin
  for i := 1 to maxXY do divisor[i] := i;
  for i := 2 to Trunc(Sqrt(maxXY)) do
    for j := i to maxXY div i do
      if i < divisor[i * j] then divisor[i * j] := i;
end;

//So luong va tong cac boi so cua k trong pham vi tu 1 toi n
procedure CSMultiples(k, n: Integer; var count, sum: Int64);
begin
  count := n div k;
  sum := count * (count + 1) div 2 * k;
end;

//CS(k, n): So luong va tong cac so tu 1 toi n nguyen to cung nhau voi k
procedure CS(k, n: Integer; var count, sum: Int64);
var
  p: array[1..maxP] of Integer;
  np, d: Integer;

  procedure Attempt(i: Integer; OddSet: Integer; setvalue: Int64);
  var
    tempc, temps: Int64;
  begin
    if setvalue > n then Exit;
    if i = np + 1 then
      begin
        CSMultiples(setvalue, n, tempc, temps);
        count := count - OddSet * tempc;
        sum := sum - OddSet * temps;
        Exit;
      end;
    Attempt(i + 1, OddSet, setvalue);
    Attempt(i + 1, -OddSet, setvalue * p[i]);
  end;

begin
  if k = 1 then
    begin
      count := n;
      sum := Int64(n) * (n + 1) div 2;
      Exit;
    end;
  if k = 0 then
    if n = 0 then
      begin
        count := 0; sum := 0;
        Exit;
      end
    else
      begin
        count := 1; sum := 1;
        Exit;
      end;
  np := 0;
  repeat
    d := divisor[k];
    Inc(np); p[np] := d;
    while k mod d = 0 do k := k div d;
  until k = 1;
  count := 0;
  sum := 0;
  Attempt(1, -1, 1);
end;

function CountLinesByHeight(height, maxwidth: Integer): Int64;
var
  i: Integer;
  c, s: Int64;
begin
  if height = 0 then Exit(m);
  if maxwidth = 0 then Exit(m + 1);
  CS(height, maxwidth, c, s);
  Result := 2 * ((m + 1) * c - s);
end;

function CountLines(lower, upper: Int64): Int64;
var
  height: Integer;
  minwidth, maxwidth: Int64;
  temp: Int64;
begin
  if upper= 0 then Exit(0);
  if lower <= 1 then
    Result := Int64(m) * (n + 1) + Int64(n) * (m + 1)
  else
    Result := 0;
  maxwidth := m; minwidth := m;
  for height := 1 to n do
    begin
      while (maxwidth > 0) and
            (Sqr(Int64(height)) + Sqr(maxwidth) > Sqr(upper)) do
        Dec(maxwidth);
      while (minwidth > 0) and
            (Sqr(Int64(height)) + Sqr(minwidth) >= Sqr(lower)) do
        Dec(minwidth);
      if maxwidth <= 0 then Break;

      temp := CountLinesByHeight(height, maxwidth);
      if minwidth > 0 then
        temp := temp - CountLinesByHeight(height, minwidth);
      temp := temp mod hash;
      Result := (Result + temp * (n + 1 - height)) mod hash;
    end;
  Result := (Result + hash) mod hash;
end;

begin
  AssignFile(fi, InputFile); Reset(fi);
  AssignFile(fo, OutputFile); Rewrite(fo);
  try
    ReadLn(fi, m, n);
    ReadLn(fi, l, h, hash);
    Init;
    res := CountLines(l, h);
    Write(fo, res);
  finally
    CloseFile(fi); CloseFile(fo);
  end;
end.

program e;
const maxp=10000;
      maxn=100010;
      eps=1e-8;
var p:array[0..maxp]of longint;
    v:array[0..maxn]of boolean;
    pr,st:array[0..maxn]of longint;
    modd:longint;
    ans,num,sum,l,r,ll,rr,n,m:int64;

function calc(w,l,r:int64):int64;
begin
  l:=l div w;
  r:=r div w;
  exit(r-l);
end;

function calc2(w,l,r:int64):int64;
var ll,rr,sum:int64;
begin
  ll:=(l div w+1)*w;
  rr:=(r div w)*w;
  sum:=(rr+ll)*((rr-ll)div w+1)shr 1;
  exit(sum);
end;

procedure prepare;
var i,j:longint;
begin
  fillchar(v,sizeof(v),true);
  fillchar(pr,sizeof(pr),0);
  fillchar(p,sizeof(p),0);
  for i:=2 to n do
   begin
     if v[i] then
      begin
        inc(p[0]);
        p[p[0]]:=i;
        pr[i]:=i;
      end;
     for j:=1 to p[0] do
      begin
        if i*p[j]<=n then begin v[i*p[j]]:=false;pr[i*p[j]]:=p[j];end;
        if (i*p[j]>n)or(i mod p[j]=0) then break;
      end;
   end;
end;

procedure init;
var j,k,u,v,w:longint;
    i:int64;
    fl:double;
    flag:boolean;
begin
  read(n,m,l,r,modd);
  prepare;
  ans:=0;
  if l=1 then ans:=(ans+(n+1)*m+(m+1)*n)mod modd;
  ans:=ans mod modd;
  i:=1;
  ll:=l;
  while i<=n do
   begin
     if (i*i>=r*r)then break;
     if (l*l<=i*i) then ll:=1
     else ll:=trunc(sqrt(l*l-i*i));
     if ll*ll<l*l-i*i then inc(ll);
     rr:=trunc(sqrt(r*r-i*i));
     if rr>m then rr:=m;
     if ll>rr then begin inc(i);continue;end;
     fillchar(st,sizeof(st),0);
     u:=i;
     while u<>1 do
      begin
        flag:=true;
        for j:=1 to st[0] do
         if st[j]=pr[u] then flag:=false;
        if flag then
         begin
           inc(st[0]);
           st[st[0]]:=pr[u];
         end;
        u:=u div pr[u];
      end;
     num:=0;sum:=0;
     for w:=0 to 1<<st[0]-1 do
      begin
        u:=w;j:=1;k:=0;v:=1;
        while u<>0 do
         begin
           if u and 1=1 then begin j:=j*st[v];inc(k);end;
           inc(v);
           u:=u shr 1;
         end;
        if k and 1=1 then begin
                           num:=num-calc(j,ll-1,rr);
                           sum:=sum-calc2(j,ll-1,rr);
                          end
                     else begin
                           num:=num+calc(j,ll-1,rr);
                           sum:=sum+calc2(j,ll-1,rr);
                          end;
      end;
     ans:=(ans+2*(n-i+1)*((num*(m+1)-sum)mod modd))mod modd;
     inc(i);
   end;
  write(ans);
end;

begin
  init;
end.

program e;
const maxp=10000;
      maxn=100010;
      eps=1e-8;
var p:array[0..maxp]of longint;
    v:array[0..maxn]of boolean;
    pr,st:array[0..maxn]of longint;
    modd:longint;
    ans,num,sum,l,r,ll,rr,n,m:int64;

function calc(w,l,r:int64):int64;
begin
  l:=l div w;
  r:=r div w;
  exit(r-l);
end;

function calc2(w,l,r:int64):int64;
var ll,rr,sum:int64;
begin
  ll:=(l div w+1)*w;
  rr:=(r div w)*w;
  sum:=(rr+ll)*((rr-ll)div w+1)shr 1;
  exit(sum);
end;

procedure prepare;
var i,j:longint;
begin
  fillchar(v,sizeof(v),true);
  fillchar(pr,sizeof(pr),0);
  fillchar(p,sizeof(p),0);
  for i:=2 to n do
   begin
     if v[i] then
      begin
        inc(p[0]);
        p[p[0]]:=i;
        pr[i]:=i;
      end;
     for j:=1 to p[0] do
      begin
        if i*p[j]<=n then begin v[i*p[j]]:=false;pr[i*p[j]]:=p[j];end;
        if (i*p[j]>n)or(i mod p[j]=0) then break;
      end;
   end;
end;

procedure init;
var j,k,u,v,w:longint;
    i:int64;
    fl:double;
    flag:boolean;
begin
  read(n,m,l,r,modd);
  prepare;
  ans:=0;
  if l=1 then ans:=(ans+(n+1)*m+(m+1)*n)mod modd;
  ans:=ans mod modd;
  i:=1;
  ll:=l;
  while i<=n do
   begin
     if (i*i>=r*r)then break;
     while (l*l-i*i<(ll-1)*(ll-1))and(ll>1) do dec(ll);
     rr:=trunc(sqrt(r*r-i*i));
     if rr>m then rr:=m;
     if ll>rr then begin inc(i);continue;end;
     fillchar(st,sizeof(st),0);
     u:=i;
     while u<>1 do
      begin
        flag:=true;
        for j:=1 to st[0] do
         if st[j]=pr[u] then flag:=false;
        if flag then
         begin
           inc(st[0]);
           st[st[0]]:=pr[u];
         end;
        u:=u div pr[u];
      end;
     num:=0;sum:=0;
     for w:=0 to 1<<st[0]-1 do
      begin
        u:=w;j:=1;k:=0;v:=1;
        while u<>0 do
         begin
           if u and 1=1 then begin j:=j*st[v];inc(k);end;
           inc(v);
           u:=u shr 1;
         end;
        if k and 1=1 then begin
                           num:=num-calc(j,ll-1,rr);
                           sum:=sum-calc2(j,ll-1,rr);
                          end
                     else begin
                           num:=num+calc(j,ll-1,rr);
                           sum:=sum+calc2(j,ll-1,rr);
                          end;
      end;
     ans:=(ans+2*(n-i+1)*((num*(m+1)-sum)mod modd))mod modd;
     inc(i);
   end;
  write(ans);
end;

begin
  init;
end.

program e;
const maxp=10000;
      maxn=100010;
      eps=1e-8;
var p:array[0..maxp]of longint;
    v:array[0..maxn]of boolean;
    pr,st:array[0..maxn]of longint;
    modd:longint;
    ans,num,sum,l,r,ll,rr,n,m:int64;

function calc(w,l,r:int64):int64;
begin
  l:=l div w;
  r:=r div w;
  exit(r-l);
end;

function calc2(w,l,r:int64):int64;
var ll,rr,sum:int64;
begin
  ll:=(l div w+1)*w;
  rr:=(r div w)*w;
  sum:=(rr+ll)*((rr-ll)div w+1)shr 1;
  exit(sum);
end;

procedure prepare;
var i,j:longint;
begin
  fillchar(v,sizeof(v),true);
  fillchar(pr,sizeof(pr),0);
  fillchar(p,sizeof(p),0);
  for i:=2 to n do
   begin
     if v[i] then
      begin
        inc(p[0]);
        p[p[0]]:=i;
        pr[i]:=i;
      end;
     for j:=1 to p[0] do
      begin
        if i*p[j]<=n then begin v[i*p[j]]:=false;pr[i*p[j]]:=p[j];end;
        if (i*p[j]>n)or(i mod p[j]=0) then break;
      end;
   end;
end;

procedure init;
var j,k,u,v,w:longint;
    i:int64;
    fl:double;
    flag:boolean;
begin
  read(n,m,l,r,modd);
  prepare;
  ans:=0;
  if l=1 then ans:=(ans+(n+1)*m+(m+1)*n)mod modd;
  ans:=ans mod modd;
  i:=1;
  while i<=n do
   begin
     if (i*i>=r*r)then break;
     if l*l-i*i<=0 then ll:=1
     else ll:=trunc(sqrt(l*l-i*i));
     if ll*ll<l*l-i*i then inc(ll);
     if ll>m then ll:=m;
     rr:=trunc(sqrt(r*r-i*i));
     if rr>m then rr:=m;
     if ll>rr then continue;
     fillchar(st,sizeof(st),0);
     u:=i;
     while u<>1 do
      begin
        flag:=true;
        for j:=1 to st[0] do
         if st[j]=pr[u] then flag:=false;
        if flag then
         begin
           inc(st[0]);
           st[st[0]]:=pr[u];
         end;
        u:=u div pr[u];
      end;
     num:=0;sum:=0;
     for w:=0 to 1<<st[0]-1 do
      begin
        u:=w;j:=1;k:=0;v:=1;
        while u<>0 do
         begin
           if u and 1=1 then begin j:=j*st[v];inc(k);end;
           inc(v);
           u:=u shr 1;
         end;
        if k and 1=1 then begin
                           num:=num-calc(j,ll-1,rr);
                           sum:=sum-calc2(j,ll-1,rr);
                          end
                     else begin
                           num:=num+calc(j,ll-1,rr);
                           sum:=sum+calc2(j,ll-1,rr);
                          end;
      end;
     ans:=(ans+2*(n-i+1)*((num*(m+1)-sum)mod modd))mod modd;
     inc(i);
   end;
  write(ans);
end;

begin
  init;
end.

program e;
const maxp=2000;
      maxn=100010;
      eps=1e-8;
var p:array[0..maxp]of longint;
    v:array[0..maxn]of boolean;
    pr,st:array[0..maxn]of longint;
    n,m,modd:longint;
    ans,num,sum,l,r,ll,rr:int64;

function calc(w,l,r:int64):int64;
begin
  l:=l div w;
  r:=r div w;
  exit(r-l);
end;

function calc2(w,l,r:int64):int64;
var ll,rr,sum:int64;
begin
  ll:=(l div w+1)*w;
  rr:=(r div w)*w;
  sum:=(rr+ll)*((rr-ll)div w+1)shr 1;
  exit(sum);
end;

procedure prepare;
var i,j:longint;
begin
  fillchar(v,sizeof(v),true);
  fillchar(pr,sizeof(pr),0);
  fillchar(p,sizeof(p),0);
  for i:=2 to n do
   begin
     if v[i] then
      begin
        inc(p[0]);
        p[p[0]]:=i;
        pr[i]:=i;
      end;
     for j:=1 to p[0] do
      begin
        if i*p[j]<=n then begin v[i*p[j]]:=false;pr[i*p[j]]:=p[j];end;
        if (i*p[j]>n)or(i mod p[j]=0) then break;
      end;
   end;
end;

procedure init;
var i,j,k,u,v,w:longint;
    fl:double;
    flag:boolean;
begin
  read(n,m,l,r,modd);
  prepare;
  ans:=0;
  if l=1 then ans:=(ans+n*(m+1)+m*(n+1))mod modd;
  for i:=1 to n do
   begin
     if (i*i>=r*r)then break;
     if l*l-i*i<=0 then ll:=1
     else ll:=trunc(sqrt(l*l-i*i));
     if ll*ll<l*l-i*i then inc(ll);
     rr:=trunc(sqrt(r*r-i*i));
     if rr*rr>r*r-i*i then dec(rr);
     if rr>m then rr:=m;
     if ll>rr then continue;
     fillchar(st,sizeof(st),0);
     u:=i;
     while u<>1 do
      begin
        flag:=true;
        for j:=1 to st[0] do
         if st[j]=pr[u] then flag:=false;
        if flag then
         begin
           inc(st[0]);
           st[st[0]]:=pr[u];
         end;
        u:=u div pr[u];
      end;
     num:=0;sum:=0;
     for w:=0 to 1<<st[0]-1 do
      begin
        u:=w;j:=1;k:=0;v:=1;
        while u<>0 do
         begin
           if u and 1=1 then begin j:=j*st[v];inc(k);end;
           inc(v);
           u:=u shr 1;
         end;
        if k and 1=1 then begin
                           num:=num-calc(j,ll-1,rr);
                           sum:=sum-calc2(j,ll-1,rr);
                          end
                     else begin
                           num:=num+calc(j,ll-1,rr);
                           sum:=sum+calc2(j,ll-1,rr);
                          end;
      end;
     ans:=(ans+2*(n-i+1)*(num*(m+1)-sum))mod modd;
   end;
  write(ans);
end;

begin
  init;
end.

program e;
const maxp=2000;
      maxn=100010;
      eps=1e-8;
var p:array[0..maxp]of longint;
    v:array[0..maxn]of boolean;
    pr,st:array[0..maxn]of longint;
    n,m,modd:longint;
    ans,num,sum,l,r,ll,rr:int64;

function calc(w,l,r:int64):int64;
begin
  l:=(l-1)div w;
  r:=r div w;
  exit(r-l);
end;

function calc2(w,l,r:int64):int64;
var ll,rr,sum:int64;
begin
  ll:=(l div w)*w;
  rr:=(r div w)*w;
  sum:=(rr+ll)*((rr-ll)div w+1)shr 1;
  exit(sum);
end;

procedure prepare;
var i,j:longint;
begin
  fillchar(v,sizeof(v),true);
  fillchar(pr,sizeof(pr),0);
  fillchar(p,sizeof(p),0);
  for i:=2 to n do
   begin
     if v[i] then
      begin
        inc(p[0]);
        p[p[0]]:=i;
        pr[i]:=i;
      end;
     for j:=1 to p[0] do
      begin
        if i*p[j]<=n then begin v[i*p[j]]:=false;pr[i*p[j]]:=p[j];end;
        if (i*p[j]>n)or(i mod p[j]=0) then break;
      end;
   end;
end;

procedure init;
var i,j,k,u,v,w:longint;
    fl:double;
    flag:boolean;
begin
  read(n,m,l,r,modd);
  prepare;
  ans:=0;
  if l=1 then ans:=(ans+n*(m+1)+m*(n+1))mod modd;
  for i:=1 to n do
   begin
     if (i*i>=r*r)then break;
     if i*i>=l*l then ll:=1
       else begin
              fl:=sqrt(l*l-i*i);
              if trunc(fl)+eps>=fl then ll:=trunc(sqrt(l*l-i*i))
                                   else ll:=trunc(sqrt(l*l-i*i))+1;
            end;
     rr:=trunc(sqrt(r*r-i*i));
     fillchar(st,sizeof(st),0);
     u:=i;
     while u<>1 do
      begin
        flag:=true;
        for j:=1 to st[0] do
         if st[j]=pr[u] then flag:=false;
        if flag then
         begin
           inc(st[0]);
           st[st[0]]:=pr[u];
         end;
        u:=u div pr[u];
      end;
     num:=rr-ll+1;
     sum:=(ll+rr)*(rr-ll+1)shr 1;
     for w:=1 to 1<<st[0]-1 do
      begin
        u:=w;j:=1;k:=0;v:=1;
        while u<>0 do
         begin
           if u and 1=1 then begin j:=j*st[v];inc(k);end;
           inc(v);
           u:=u shr 1;
         end;
        if k and 1=1 then begin
                           num:=num-calc(j,ll-1,rr);
                           sum:=sum-calc2(j,ll-1,rr);
                          end
                     else begin
                           num:=num+calc(j,ll-1,rr);
                           sum:=sum-calc2(j,ll-1,rr);
                          end;
      end;
     ans:=(ans+2*(n-i+1)*(num*(m+1)-sum))mod modd;
   end;
  write(ans);
end;

begin
  init;
end.


Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.Arithmetic progression is a sequence a1, a1 + d, a1 + 2d, ..., a1 + (n - 1)d, where a1 and d are any numbers.Geometric progression is a sequence b1, b2 = b1q, ..., bn = bn - 1q, where b1 ≠ 0, q ≠ 0, q ≠ 1. Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer.

The first line contains exactly four integer numbers between 1 and 1000, inclusively.

Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element. Print 42 if the given sequence is not an arithmetic or geometric progression.

NoteThis problem contains very weak pretests!

Program z328A;

var
  a, b, c, d, s1, s2, s3: longint;
  p1, p2, p3:real;

begin
  readln(a, b, c, d);
  if (a = b)and(b = c)and(c = d) then writeln(a)
  else
  //if ((aa > b)and(b > c)and(c > d)) or ((a < b)and(b < c)and(c < d))//Знакочередование может быть в случае с геом прогр
  //  then
     begin
           s1 := b - a;
           s2 := c - b;
           s3 := d - c;
           p1:=0;p2:=0;p3:=0;
           if a<>0 then p1 := b / a;// На ноль делить нельзя
           if b<>0 then p2 := c / b;
           if c<>0 then p3 := d / c;
           //writeln(p1,' ',p2,' ',p3);
           if (s1 = s2)and(s2 = s3)
             then writeln(d + s1)
             else if (p1 = p2)and(p2 = p3)and(p1<>0)and(frac(d * b/a)=0)// Целое число!!!!
                    then writeln(trunc(d * b/a))//Целое число должно быть не real:)!!!
                                       //1/3
                    else writeln(42)
         end
    //else writeln(42)
  //readln !!!!!
end.

var a,b,c,d:word; e:integer;
function ucln(x,y:word):word;
var z:word;
begin
        x:=abs(x); y:=abs(y);
        while y>0 do
        begin
                x:=x mod y; z:=x; x:=y; y:=z
        end;
        ucln:=x
end;
begin
        read(a,b,c,d);
        e:=b-a;
        if (c=a+e shl 1) and (d=a+e*3) then write(a+e shl 2)
        else begin
                e:=ucln(a,b); a:=a div e; e:=b div e;
                if (b*e mod a=0) and (b*e div a=c) and (c*e mod a=0) and (c*e div a=d) and (d*e mod a=0) then write(d*e div a)
                else write(42)
        end
end.

var
  a,b,c,d:longint;

begin

  readln(a,b,c,d);
  if (b-a=c-b) and (c-b=d-c) then writeln(d+b-a) else
  if (b/a=c/b) and (c/b=d/c) and (frac(d*b/a)=0) then writeln(trunc(d*b/a)) else
  writeln(42);

end.

program qq;

const
  eps = 1e-9;

var
  n, d, x, i: integer;
  q, l: real;
  a: array[1..10000] of integer;

begin
  d := 0;
  q := 0;
  x := 0;
  for i := 1 to 4 do
    read(a[i]);
  //if (a[1]=a[2]) and (a[1]=a[3]) and (a[1]=a[4]) then begin
  //write(a[1]);
  {halt;}
  //end;
  if (a[2] - a[1] = a[3] - a[2]) and (a[2] - a[1] = a[4] - a[3]) then
  begin
    d := a[2] - a[1];
    write(a[4] + d);
    x := 1;
  end
  else
  if (abs(a[2] / a[1] - a[3] / a[2]) < eps) and (abs(a[2] / a[1] - a[4] / a[3]) < eps) then
  begin
    q := a[2] / a[1];
    l := a[4] * q;
    if (abs(l - round(l)) < eps) then
    begin
      write(l: 5: 0);
      x := 1;
    end;
  end;
  if x = 0 then
    write(42);
end.

Const
   fin='';
   fon='';
Var
   n: Longint;
   kt: Boolean;
   A: array[1..5] of Longint;
Procedure Start;
   Begin
      assign(input,fin);
      reset(input);
      assign(output,fon);
      rewrite(output);
   End;
Procedure Programe;
   Var i: Longint;
   Begin
      for i:=1 to 4 do read(A[i]);
      kt:=False;
      for i:=1 to 3 do
         if A[i]+A[2]-A[1] <> A[i+1] then kt:=True;
      if kt = False then
      begin
         writeln(A[4]+A[2]-A[1]);
         Exit;
      end;
      kt:=False;
      for i:=1 to 3 do
         if A[i]*A[2]/A[1] <> A[i+1] then kt:=True;
      if frac(A[4]*A[2]/A[1]) <> 0 then kt:=True;
      if kt = False then
      begin
         writeln(A[4]*A[2]/A[1]:0:0);
         Exit;
      end;
      writeln(42);
   End;
Procedure Finish;
   Begin
      close(input);
      close(output);
   End;
Begin
   Start;
   Programe;
   Finish;
End.

var a,b,c,d: LongInt;
begin
  Readln(a,b,c,d);

  if ((b-a)=(c-b)) and ((c-b)=(d-c)) then Writeln(2*d-c) else

  if (a=0) or (b / a = 0) or (b / a = 1) or (c / b = 0) or (c / b = 1) or (d / c = 0) or (d / c = 1) then Writeln(42) else

  if ((b / a)=(c / b)) and ((c / b)=(d / c)) and (sqr(d) mod c = 0) then Writeln(sqr(d) div c) else Writeln(42);
end.

var a:array[1..4]of integer;
    d:array[2..4]of integer;
    q:array[2..4]of real;
    i:byte;

begin
    for i:=1 to 4 do begin
        read(a[i]);
        if i>1 then begin
            d[i]:=a[i]-a[i-1];
            q[i]:=a[i]/a[i-1];
        end;
    end;
    readln;
    if (d[2]=d[3])and(d[3]=d[4]) then
        writeln(a[4]+d[4])
    else
        if (q[2]=q[3])and(q[3]=q[4]) then
            if (a[4]*a[4]) mod a[3]=0 then
                writeln(a[4]*q[4]:0:0)
            else
                writeln(42)
        else
            writeln(42);
    readln;
end.

var a,b,c,d:longint;

begin
readln(a,b,c,d);
if(a-b=b-c)and(b-c=c-d) then writeln(d-a+b)
else if (a=0)and(b=0)and(c=0)and(d=0) then writeln(0)
else if (a*c=b*b)and(b*d=c*c) then
  begin
  if (d*d mod c=0)then writeln(d*d div c)
  else writeln(42);
  end
else writeln(42);
end.

Program A;

Var
a,b,c,d,g,f: integer;
e: real;
Begin
Read(a, b, c, d);
G:=42; f:=1;
If (a+c=b+b) and (b+d=c+c) then begin
e:=d+d-c;
F:=0;
End;
If (a*c=b*b) and (b*d=c*c) then begin
F:=(d*d) mod c;
e:=(d*d)/c;
End;

If f=0 then write(e:0:0) else write(g);
End.

{$r-, s-, q-, i-, o+}
var
  a, b, c, d, res : extended;
begin
  readln(a, b, c, d);
  res := maxlongint;
  if (b / a = c / b) and (c / b = d / c) then res := d * (b / a);
  if (res = trunc(res)) and (res < maxlongint) then begin writeln(trunc(res)); halt(0); end;
  if (b - a = c - b) and (c - b = d - c) then writeln(trunc(d + b - a)) else writeln(42);
end.

  var a,b,c,d:integer;
      e:real;
begin
  readln(a,b,c,d);
  if (a-b=b-c)and(b-c=c-d)
    then e:=d-(a-b)
    else if (a/b=b/c)and(b/c=c/d)
           then e:=d/(a/b)
           else e:=42;
  if frac(e)<>0 then e:=42;
  writeln(e:0:0);
end.

{$MODE OBJFPC}
program proA328;
uses
  math;
const
  fi = 'PROA.INP';
var
  u1, u2, u3, u4 : Integer;

begin
  readln(u1, u2, u3, u4);
  if ((u2 - u1 = u3 - u2) and (u3 - u2 = u4 - u3)) then
    begin
      writeln(u4 + (u2 - u1));
      halt;
    end else
    if ((u2 / u1) = (u3 / u2)) and ((u3 / u2) = (u4 / u3)) then
    begin
      if (frac(u4 * (u2 / u1)) <> 0) then
        begin
          writeln(42);
          halt;
        end;
      writeln(u4 * (u2 / u1) : 0 : 0);
      halt;
    end;
  writeln(42);

end.

program work;
var a:array[1..10] of longint;
 i,j,n,m,t:longint;ans:double;
begin
 for i:=1 to 4 do
  read(a[i]);
 n:=a[1]-a[2];
 m:=a[2]-a[3];
 t:=a[3]-a[4];
 if (n=m)and(n=t)and(t=m) then
  begin
   writeln(a[4]-t);
   halt;
  end;
 n:=a[1]*a[4];
 m:=a[2]*a[3];
 if n<>m then begin  writeln('42');halt;end;
 n:=a[1]*a[3];
 m:=a[2]*a[2];
 if n<>m then begin writeln('42');halt;end;
 n:=a[2]*a[4];
 m:=a[3]*a[3];
 if n<>m then begin writeln('42');halt;end;
 if (a[1]-a[3]<0)and(a[2]-a[4]>0) then begin writeln('42');halt;end;
 if (a[1]-a[3]>0)and(a[2]-a[4]<0) then begin writeln('42');halt;end;
 n:=a[4]*a[4];
 m:=a[3];t:=0;
 for i:=1 to 20000 do
  if i*m=n then t:=i;
 if t=0 then writeln('42') else writeln(t);
end.

var a, b, c, d: Longint;

function eq(a, b: Extended): Boolean;
Begin
     if abs(a - b) < 0.0000000001 then
        eq := true
     else
        eq := false;
End;

Begin
     read(a, b, c, d);
     if (a - b = b - c) and (b - c = c - d) then begin
        write(d - (b - c));
        halt;
     end;
     if (b = 0) and (c = 0) and (d = 0) then begin
        write(0);
        halt;
     end;
     if (eq(a / b, b / c)) and (eq(b / c, c / d)) then begin
        if d * b mod a = 0 then begin
           write(d * b div a);
           halt;
        end;
     end;
     write(42);
End.

var
 a,b,c,d:longint;
begin
 readln(a,b,c,d);
 if (b+b=a+c)and(c+c=b+d) then writeln(d+c-b) else
 if (c*c=b*d)and(b*b=a*c)and(frac(d*b/a)=0) then writeln(trunc(d*c/b)) else
 writeln(42);
end.

var
  i,e: longint;
  t: integer;
  n,m,o,p,q,r,s: real;
  b: array[1..10]of real;
begin
  e:=42;
  for i:=1 to 4 do
    read(b[i]);
  n:=(b[2]-b[1]);
  m:=(b[3]-b[2]);
  o:=(b[4]-b[3]);
  p:=(b[2]/b[1]);
  q:=(b[3]/b[2]);
  r:=(b[4]/b[3]);
  s:=(b[4]*b[4]/b[3]);
  t:=round(s);
  if(n=m)and(m=o)then
    writeln((b[4]+b[4]-b[3]):0:0)
  else if(p=q)and(q=r)then
  begin
    if s<1 then
      writeln(e)
    else if s<>t then
      writeln(e)
    else if s=t then
      writeln((b[4]*b[4]/b[3]):0:0);
  end
  else
    writeln(e);
end.

var a,b,c,d:longint;
begin
  readln(a,b,c,d);
  if (abs(a-b)=abs(b-c))and(abs(b-c)=abs(c-d)) then
    writeln(d-a+b)
  else
  if (a*c=b*b)and(b*d=c*c) then
    if d*d mod c=0 then
      writeln(d*d div c)
    else
      writeln(42)
  else
    writeln(42);
end.

var a:array[1..4] of integer;

function ktcsc:boolean;
var i:byte;
	l:integer;
begin
	l:=a[2]-a[1];
	for i:=2 to 3 do
	begin
		if a[i+1]-a[i]<>l then exit(FALSE);
	end;
	exit(TRUE);
end;

function ktcsn:boolean;
var i:byte;
        v:longint;
	l,k,j,u:real;
begin
	l:=a[2]/a[1];
        k:=a[3]/a[2];
        j:=a[4]/a[3];
        if j<>l then exit(FALSE);
        if j<>k then exit(FALSE);
        if l<>k then exit(FALSE);
        v:=trunc(a[4]*a[2]/a[1]);
        u:=v/a[4];
        if u<>l then exit(FALSE) else exit(TRUE);
end;

procedure proonf;
var i:byte;
begin
	for i:=1 to 4 do read(a[i]);
	if ktcsc=TRUE then writeln(a[4]+a[2]-a[1])
	else
	if ktcsn=TRUE then writeln(trunc(a[4]*(a[2]/a[1])))
	else writeln(42);
end;

//main
begin
	proonf;
end.
var x:array[1..5] of longint;

procedure proonf;
var t,s:string;
	found:boolean;
	m,i,k,min,temp:longint;
        f:text;
begin
        assign(f,'');
        reset(f);
	readln(f,k);
	str(k,t);
        readln(f,s);
	fillchar(x,sizeof(x),0);
        found:=true;
	while found=true do
	begin
		for i:=1 to length(t) do
		begin
			m:=pos(t[i],s);
			if (t[i]='2')and(m=0) then m:=pos('5',s);
			if (t[i]='5')and(m=0) then m:=pos('2',s);
			if (t[i]='9')and(m=0) then m:=pos('6',s);
			if (t[i]='6')and(m=0) then m:=pos('9',s);
			if m<> 0 then inc(x[i]);
			delete(s,m,1);
		end;
                if m<>0 then
                begin
		m:=x[1];
		for i:=2 to length(t) do
		begin
			if (x[i]<>m) then begin found:=false; break; end;
		end;
		end
                else found:=FALSE;
	end;
	min:=x[1];
	for i:=2 to length(t) do
	begin
		if min>x[i] then
		begin
			temp:=min;
			min:=x[i];
			x[i]:=temp;
		end;
	end;
	writeln(min);
end;

//main
begin
	proonf;
end.

var n,i,j:longint;
    a:array[0..4]of longint;
procedure swap(var q,w:longint);
var z:longint;
 begin
  z:=q;
  q:=w;
  w:=z;
 end;
procedure arifmetr;
var x,i,p,cons:longint;
 begin
  p:=0;
  cons:=a[2]-a[1];
  for i:=2 to n do
   begin
    x:=a[i]-a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(p=0)then
   begin
    writeln(a[4]+x);
    halt(0);
   end;
 end;
procedure geometr;
var i,p:longint;
    x,cons:extended;
 begin
  p:=0;
  cons:=a[2]/a[1];
  for i:=2 to n do
   begin
    x:=a[i]/a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(p=0)and(frac(a[4]*x)=0)then
   begin
    writeln(a[4]*x:0:0);
    halt(0);
   end;
 end;
 begin
  n:=4;
  for i:=1 to n do
   read(a[i]);
  arifmetr;
  geometr;
  writeln(42);
 end.

{$n+}
var
 a:array[1..5]of longint;
 p1,p2,x,n,i:longint;
 y:extended;
begin
 {assign(input,'a.in');
 reset(input);
 assign(output,'a.out');
 rewrite(output);}
 n:=4;
 for i:=1 to n do read(a[i]);
 x:=a[2]-a[1];
 for i:=1 to n-1 do if a[i]+x<>a[i+1] then p1:=1;
 if p1=0 then
 begin
  writeln(a[4]+x);
  halt;
 end;
 y:=a[2]/a[1];
 for i:=1 to n-1 do if a[i]*y<>a[i+1]then p2:=1;
 if frac(a[4]*y)<>0 then p2:=1;
 if p2=0 then
 begin
  writeln(a[4]*y:0:0);
  halt;
 end;
 writeln(42);
end.

var
a,b,c,d,y:longint;
x,e:real;

begin
  read(a,b,c,d);
  if (d-c=c-b) and (c-b=b-a) then
   begin
    y:=d-c;
    writeln(d+y);
    halt;
  end;
  if (d/c=c/b) and (c/b=b/a) then
   begin
    x:=d/c;
    e:=d*x;
    if trunc(e)=e then writeln(e:0:0) else writeln(42);
    halt;
  end;
  writeln(42);
end.

                  {$APPTYPE CONSOLE}
const  besk=100000000000000;
   nnn=2000000;  eps=1e-13;
 label 1,2,3,4;
var nn,n,i10,i100,n1,dl,kol,ii,jj,i3,i2,i1,j1,k1,kt,ppp,mask,i0,j0,step,i,j,start,finish:longint;
t,k,p,m1,pl,sum,p1,p2,m,k2,r,cc,ot,aa,bb,x1,y1,x0,y0,ll,rr,d1,d2,kolvyk,xx2,q,t1,t2,modul,pp,tt,ot1,ot2,s,kold,kkr:int64;
mon1,mon2,day1,day2,god1,god2,plus,kk,mnog,koef:int64;
fl0,fl10,fl100,flag2,flag1,flag:boolean;
ott,pp1,pp2,dl1,dl2,dl3,hh,po,pt,doltek,dolpred:extended;
dx,dy,b,a,c:array[-1000..200000] of int64;

xx,yy,z1,z,x,y: array[-10..500000] of int64;
gr1,gr: array[-50..700,-50..700] of boolean;
ee,deg,marked:array[-100000..250000] of int64;
{ss:array[0..2000000] of char; }
sss:string;
ab:array[-100..200,-100..201,-100..201] of char;
ch11,ch12,ch1,ch:char;
sl,sr,str :array[-10 ..200000] of int64;
ssot:array[-1000..1100000] of char;
fact:array[0..100] of extended;
name:array[0..2000] of string;
function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;

    function nod(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
nod:=p;
end;

function degg(a,k:int64):int64; var p:int64;
begin
 if k=0 then degg:=1 else if odd(k) then degg:=degg(a,k-1)*a mod modul else
   begin  p:=degg(a,k div 2); degg:=p*p mod modul;   end;

end;

begin
{assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
 }
                              modul:=1000000007 ;
    n:=4;
  for i:=1 to n do read(a[i]);
flag1:=true;
for i:=2 to n-1 do if a[i]*a[i]<>a[i-1]*a[i+1] then flag1:=false;

flag2:=true;
for i:=2 to n-1 do if a[i]+a[i]<>a[i-1]+a[i+1] then flag2:=false;

if flag2 then begin  write(2*a[4]-a[3]); goto 1;   end;
if flag1 and((a[4]*a[4]/a[3])=round(a[4]*a[4]/a[3])) then begin
write(a[4]*a[4]/a[3]:0:0); goto 1;   end;
write(42);

   1:          close(output);

end.

Var z,i:longint;
ch1,zn1,ch,zn:longint;
f:boolean;
m:array [1..100] of longint;
function nod(a,b:longint):longint;
begin
  if b>a
  then nod:=nod(b,a)
  else if b=0
       then nod:=a
       else nod:=nod(b,a mod b);
end;
begin
  //Assign(input,'input.txt'); reset(input);
  //Assign(output,'output.txt'); rewrite(output);
  for i:=1 to 4 do
  read(m[i]);
  z:=m[2]-m[1];
  f:=true;
  for i:=3 to 4 do
  if m[i]-m[i-1]<>z
  then f:=false;
  if f
  then begin
        writeln(m[4]+z);
        halt(0);
       end;
  ch:=m[2];
  zn:=m[1];
  z:=nod(m[2],m[1]);
  ch:=ch div z;
  zn:=zn div z;
  f:=true;
  for i:=3 to 4 do
  begin
    ch1:=m[i];
    zn1:=m[i-1];
    z:=nod(m[i],m[i-1]);
    ch1:=ch1 div z;
    zn1:=zn1 div z;
    if (ch1<>ch)or(zn1<>zn)
    then f:=false;
  end;
  if (m[4]*ch) mod zn<>0
  then f:=false;
  if f=false
  then writeln(42)
  else writeln((m[4]*ch) div zn);
end.

program Project2;

{$APPTYPE CONSOLE}

uses   SysUtils;
var m: array [1..10] of Integer;
    x,y,z,t: Integer;
    arif, geom: Boolean;
    next: Real;
begin
  { TODO -oUser -cConsole Main : Insert code here }
  Readln(x,y,z,t);
  if  (y-x = z-y) and (t-z = z-y ) then Writeln(2*t-z)
  else
    if  (y/x=z/y) and (t/z=z/y) and ( Frac(t*t/z) = 0)  then Writeln(t*t/z :0:0)
       else writeln(42);

end.

program Project2;

{$APPTYPE CONSOLE}

uses   SysUtils;
var m: array [1..10] of Integer;
    i,j,k,d,q: Integer;
    arif, geom: Boolean;
    next: Real;
begin
  { TODO -oUser -cConsole Main : Insert code here }
  for i:=1 to 4 do Read(m[i]);
  arif:=True;
  geom:=True;
  d:=m[2]-m[1];
  q:=m[2] div m[1];
  for i:=2 to 4 do
    if m[i]-m[i-1] <> d   then arif :=False;
  for i:=2 to 3 do
    if  m[i-1]*m[i+1] <> m[i]*m[i] then geom:=False;

  next:=m[4]*m[4]/m[3];
  k:=round(m[4]*m[4]/m[3]);

  if  Abs(next-k)>0.00001 then geom:=False;

  if arif then Writeln(m[4]+d)
    else  if  geom then Writeln(m[4]*m[4]/m[3]:0:0)
     else Writeln(42);

end.

Uses Math,SysUtils;
Var I,J,L,H,R,G,X,Y,DX,DY,K,H1,ma:Integer;P1,T,N,M:Int64;R1,A,B,C,D:Extended;F:array[1..100] of Boolean;S:String;m1:array[1..100] of Char;p:array[1..1000,1..1000] of char;
Begin
   ///reset(input,'Input.txt');
   ///assign(output,'Output.txt');
   readln(A,B,C,D);
   If ((A-B)=(B-C)) and ((B-C)=(C-D))
   then write((D+(D-C)):0:0)
   else If ((A/B)=(B/C)) and ((B/C)=(C/D)) and (A/B<>1)
        then If (D/(C/D))=Round(D/(C/D))
             then write((D/(C/D)):0:0)
             else write('42')
        else write('42');
end.

Program z328A;

var
  a, b, c, d, s1, s2, s3: longint;
  p1, p2, p3:real;

begin
  readln(a, b, c, d);
  if (a = b)and(b = c)and(c = d) then writeln(a)
  else
  //if ((aa > b)and(b > c)and(c > d)) or ((a < b)and(b < c)and(c < d))//Знакочередование может быть в случае с геом прогр
  //  then
     begin
           s1 := b - a;
           s2 := c - b;
           s3 := d - c;
           p1:=0;p2:=0;p3:=0;
           if a<>0 then p1 := b / a;// На ноль делить нельзя
           if b<>0 then p2 := c / b;
           if c<>0 then p3 := d / c;
           //writeln(p1,' ',p2,' ',p3);
           if (s1 = s2)and(s2 = s3)
             then writeln(d + s1)
             else if (p1 = p2)and(p2 = p3)and(p1<>0)//!!!
                    then writeln(trunc(d * p1))//Целое число должно бытьб не real:)!!!
                    else writeln(42)
         end
    //else writeln(42)
  //readln !!!!!
end.

Program z328A;

var
  a, b, c, d, s1, s2, s3: longint;
  p1, p2, p3:real;

begin
  readln(a, b, c, d);
  if (a = b)and(b = c)and(c = d) then writeln(a)
  else
  //if ((aa > b)and(b > c)and(c > d)) or ((a < b)and(b < c)and(c < d))//Знакочередование может быть в случае с геом прогр
  //  then
     begin
           s1 := b - a;
           s2 := c - b;
           s3 := d - c;
           p1:=0;p2:=0;p3:=0;
           if a<>0 then p1 := b / a;// На ноль делить нельзя
           if b<>0 then p2 := c / b;
           if c<>0 then p3 := d / c;
           //writeln(p1,' ',p2,' ',p3);
           if (s1 = s2)and(s2 = s3)
             then writeln(d + s1)
             else if (p1 = p2)and(p2 = p3)and(p1<>0)and(trunc(d * b/a)<>0)// Целое число!!!!
                    then writeln(trunc(d * b/a))//Целое число должно быть не real:)!!!
                                       //1/3
                    else writeln(42)
         end
    //else writeln(42)
  //readln !!!!!
end.

Program z328A;

var
  a, b, c, d, s1, s2, s3: longint;
  p1, p2, p3: real;

begin
  readln(a, b, c, d);
  if ((a > b)and(b > c)and(c > d)) or ((a < b)and(b < c)and(c < d))
    then begin
           s1 := b - a;
           s2 := c - b;
           s3 := d - c;
           p1 := b / a;
           p2 := c / b;
           p3 := d / c;
           if (s1 = s2)and(s2 = s3)
             then writeln(d + s1)
             else if (p1 = p2)and(p2 = p3)
                    then writeln(d * p1)
                    else writeln(42)
         end
    else writeln(42)
end.

Program z328A;

var
  a, b, c, d, s1, s2, s3: longint;
  p1, p2, p3: real;

begin
  readln(a, b, c, d);
  if (a = b)and(b = c)and(c = d) then writeln(a)
  else
  if ((a > b)and(b > c)and(c > d)) or ((a < b)and(b < c)and(c < d))
    then begin
           s1 := b - a;
           s2 := c - b;
           s3 := d - c;
           p1 := b / a;
           p2 := c / b;
           p3 := d / c;
           if (s1 = s2)and(s2 = s3)
             then writeln(d + s1)
             else if (p1 = p2)and(p2 = p3)
                    then writeln(d * p1)
                    else writeln(42)
         end
    else writeln(42)
end.

var a,b,c,d:word; e:integer;
begin
        read(a,b,c,d);
        e:=b-a;
        if (c=a+e shl 1) and (d=a+e*3) then write(a+e shl 2)
        else if b mod a=0 then
        begin
                e:=b div a;
                if (c=b*e) and (d=c*e) then write(d*e)
                else write(42)
        end
        else write(42)
end.

program qq;
const eps = 1e-9;

var n,d,x,i:integer;
    q,l:real;
    a:array[1..10000] of integer;

begin
d:=0;
q:=0;
x:=0;
for i:=1 to 4 do read(a[i]);
//if (a[1]=a[2]) and (a[1]=a[3]) and (a[1]=a[4]) then begin
//write(a[1]);
{halt;}
//end;
if (a[2]-a[1]=a[3]-a[2]) and (a[2]-a[1]=a[4]-a[3]) then begin
d:=a[2]-a[1];
write(a[4]+d);
x:=1;
end
else
if (abs(a[2]/a[1]-a[3]/a[2])<eps) and (abs(a[2]/a[1]-a[4]/a[3])<eps) then begin
q:=a[2]/a[1];
l:=a[4]*q;
//if l<1 then begin
//write(42);
{halt;}
write(l:5:0);
x:=1;
end;
if x=0 then write(42);
end.

var a,b,c,d: LongInt;
begin
  Readln(a,b,c,d);

  if ((b-a)=(c-b)) and ((c-b)=(d-c)) then Writeln(2*d-c) else

  if (a=0) or (b / a = 0) or (b / a = 1) or (c / b = 0) or (c / b = 1) or (d / c = 0) or (d / c = 1) then Writeln(42) else

  if ((b / a)=(c / b)) and ((c / b)=(d / c)) then Writeln(trunc(sqr(d)/c)) else

  Writeln(42);
end.

var a,b,c,d: LongInt;
begin
  Readln(a,b,c,d);

  if ((b-a)=(c-b)) and ((c-b)=(d-c)) then Writeln(2*d-c) else

  if (a=0) or (b / a = 0) or (b / a = 1) or (c / b = 0) or (c / b = 1) or (d / c = 0) or (d / c = 1) then Writeln(42) else

  if ((b / a)=(c / b)) and ((c / b)=(d / c)) then Writeln(trunc((2*d)/c)) else

  Writeln(42);
end.

Program A;

Var
a,b,c,d,g,f: integer;
e: real;
Begin
Read(a, b, c, d);
G:=42; f:=1;
If (a+c=b+b) and (b+d=c+c) then
e:=d+d-c;
F:=0;
If (a*c=b*b) and (b*d=c*c) then begin
F:=(d*d) mod c;
e:=(d*d)/c;
End;

If f=0 then write(e:0:0) else write (g);
End.

{$MODE OBJFPC}
program proA328;
uses
  math;
const
  fi = 'PROA.INP';
var
  u1, u2, u3, u4 : Integer;

begin
  readln(u1, u2, u3, u4);
  if ((u2 - u1 = u3 - u2) and (u3 - u2 = u4 - u3)) then
    begin
      writeln(u4 + (u2 - u1));
      halt;
    end else
    if ((u2 / u1) = (u3 / u2)) and ((u3 / u2) = (u4 / u3)) then
    begin
      writeln(u4 * (u2 / u1) : 0 : 0);
      halt;
    end;
  writeln(42);

end.

var a:array[1..4] of longint;
    p:longint;
    q:real;
begin
  readln(a[1],a[2],a[3],a[4]);
  p:=a[2]-a[1];
  q:=a[2]/a[1];
  if (a[2]+p=a[3]) and (a[3]+p=a[4]) then writeln(a[4]+p) else
  if (trunc(a[2]*q)=a[3]) and (trunc(a[3]*q)=a[4]) then writeln(a[4]*q:0:0) else
  writeln(42);
end.

var a:array[1..4] of longint;
    p:longint;
    q:real;
begin
  readln(a[1],a[2],a[3],a[4]);
  p:=a[2]-a[1];
  q:=a[2]/a[1];
  if (a[2]+p=a[3]) and (a[3]+p=a[4]) then writeln(a[4]+p) else
  if (a[2]*q=a[3]) and (a[3]*q=a[4]) then writeln(a[4]*q:0:0) else
  writeln(42);
end.

var a:array[1..4] of longint;
    p:longint;
    q:real;
begin
  readln(a[1],a[2],a[3],a[4]);
  p:=a[2]-a[1];
  q:=a[2]/a[1];
  if (a[2]+p=a[3]) and (a[3]+p=a[4]) then writeln(a[4]+p) else
  if (trunc(a[2]*q)=a[3]) and (trunc(a[3]*q)=a[4]) then writeln(trunc(a[4]*q)) else
  writeln(42);
end.

var
 a,b,c,d:longint;
begin
 readln(a,b,c,d);
 if (b+b=a+c)and(c+c=b+d) then writeln(d+c-b) else
 if (c*c=b*d)and(b*b=a*c)and(d<>1) then writeln(trunc(d*c/b)) else
 writeln(42);
end.

var
 a,b,c,d:longint;
begin
 readln(a,b,c,d);
 if b+b=a+c then writeln(d+c-b) else
 if c*c=b*d then writeln(trunc(d*c/b)) else
 writeln(42);
end.

program cf(input,output);
var
a,b,c,d,s:longint;
begin
read(a,b,c,d);
if b-a=c-b then
s:=d+b-a else
s:=trunc(d*b/a);
writeln(s);
end.

var
 a,b,c,d:longint;
begin
 readln(a,b,c,d);
 if b+b=a+c then writeln(d+c-b)
 else writeln(trunc(d*c/b));
end.

program cf(input,output);
var
a,b,c,d,s:longint;
begin
read(a,b,c,d);
if b-a=c-b then
s:=d+b-a else
s:=d*trunc(b/a);
writeln(s);
end.

var
 a,b,c,d:longint;
begin
 readln(a,b,c,d);
 if (b+b=a+c)and(c+c=b+d) then writeln(d+c-b) else
 if (c*c=b*d)and(b*b=a*c) then writeln(trunc(d*c/b)) else
 writeln(42);
end.

var
  i,e: longint;
  t: integer;
  n,m,o,p,q,r,s: real;
  b: array[1..10]of real;
begin
  e:=42;
  for i:=1 to 4 do
    read(b[i]);
  n:=(b[2]-b[1]);
  m:=(b[3]-b[2]);
  o:=(b[4]-b[3]);
  p:=(b[2]/b[1]);
  q:=(b[3]/b[2]);
  r:=(b[4]/b[3]);
  s:=(b[4]*b[4]/b[3]);
  t:=round(s);
  if(n=m)and(m=o)then
    writeln((b[4]+b[4]-b[3]):0:0)
  else if(p=q)and(q=r)then
  begin
    if s<1 then
      writeln(e)
    else if s<>t then
      writeln(e)
    else if s=t then
      writeln((b[4]*b[4]/b[3]):0:2);
  end
  else
    writeln(e);
end.

var
  i,e: longint;
  n,m,o,p: real;
  b: array[1..10]of real;
begin
  e:=42;
  for i:=1 to 4 do
    read(b[i]);
  n:=(b[1]-b[2]);
  m:=(b[2]-b[3]);
  o:=(b[2]/b[1]);
  p:=(b[3]/b[2]);
  if n=m then
    writeln((b[4]-n):0:0)
  else if o=p then
    writeln((b[4]*o):0:0)
  else
    writeln(e);
end.

var
  i,e: longint;
  n,m,o,p,q,r: integer;
  b: array[1..10]of integer;
begin
  e:=42;
  for i:=1 to 4 do
    read(b[i]);
  n:=(b[1]-b[2]);
  m:=(b[2]-b[3]);
  o:=(b[3]-b[4]);
  p:=(b[2]div b[1]);
  q:=(b[3]div b[2]);
  r:=(b[4]div b[3]);
  if(n=m)and(m=o)then
    writeln((b[4]-n))
  else if(p=q)and(q=r)then
    writeln((b[4]*b[4]/b[3]):0:0)
  else
    writeln(e);
end.

var n,i,j:longint;
    a:array[0..4]of longint;
procedure swap(var q,w:longint);
var z:longint;
 begin
  z:=q;
  q:=w;
  w:=z;
 end;
procedure arifmetr;
var x,i,p,cons:longint;
 begin
  p:=0;
  cons:=a[2]-a[1];
  for i:=2 to n do
   begin
    x:=a[i]-a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(p=0)then
   begin
    writeln(a[4]+x);
    halt(0);
   end;
 end;
procedure geometr;
var i,p:longint;
    x,cons:extended;
 begin
  p:=0;
  cons:=a[2]/a[1];
  for i:=2 to n do
   begin
    x:=a[i]/a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(p=0)and(frac(a[4]*x)<>0)then
   begin
    writeln(a[4]*x:0:0);
    halt(0);
   end;
 end;
 begin
  n:=4;
  for i:=1 to n do
   read(a[i]);
  arifmetr;
  geometr;
  writeln(42);
 end.

var n,i,j:longint;
    a:array[0..4]of longint;
procedure swap(var q,w:longint);
var z:longint;
 begin
  z:=q;
  q:=w;
  w:=z;
 end;
procedure arifmetr;
var x,i,p,cons:longint;
 begin
  p:=0;
  cons:=a[2]-a[1];
  for i:=2 to n do
   begin
    x:=a[i]-a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(p=0)then
   begin
    writeln(a[4]+x);
    halt(0);
   end;
 end;
procedure geometr;
var i,p:longint;
    x,cons:extended;
 begin
  p:=0;
  cons:=a[2]/a[1];
  for i:=2 to n do
   begin
    x:=a[i]/a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(frac(x)<>0)then exit;
  if(p=0)and(a[4]*x>0)then
   begin
    writeln(a[4]*x:0:0);
    halt(0);
   end;
 end;
 begin
  n:=4;
  for i:=1 to n do
   read(a[i]);
  arifmetr;
  geometr;
  writeln(42);
 end.

var n,i,j:longint;
    a:array[0..4]of longint;
procedure swap(var q,w:longint);
var z:longint;
 begin
  z:=q;
  q:=w;
  w:=z;
 end;
procedure arifmetr;
var x,i,p,cons:longint;
 begin
  p:=0;
  cons:=a[2]-a[1];
  for i:=2 to n do
   begin
    x:=a[i]-a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(p=0)then
   begin
    writeln(a[4]+x);
    halt(0);
   end;
 end;
procedure geometr;
var i,p:longint;
    x,cons:extended;
 begin
  p:=0;
  cons:=a[2]/a[1];
  for i:=2 to n do
   begin
    x:=a[i]/a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(p=0)then
   begin
    writeln(a[4]*x:0:0);
    halt(0);
   end;
 end;
 begin
  n:=4;
  for i:=1 to n do
   read(a[i]);
  arifmetr;
  geometr;
  writeln(42);
 end.

var n,i,j:longint;
    a:array[0..4]of longint;
procedure swap(var q,w:longint);
var z:longint;
 begin
  z:=q;
  q:=w;
  w:=z;
 end;
procedure arifmetr;
var x,i,p,cons:longint;
 begin
  p:=0;
  cons:=a[2]-a[1];
  for i:=2 to n do
   begin
    x:=a[i]-a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(p=0)then
   begin
    writeln(a[4]+x);
    halt(0);
   end;
 end;
procedure geometr;
var i,p:longint;
    x,cons:extended;
 begin
  p:=0;
  cons:=a[2]/a[1];
  for i:=2 to n do
   begin
    x:=a[i]/a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(p=0)and(a[4]*x>0)then
   begin
    writeln(a[4]*x:0:0);
    halt(0);
   end;
 end;
 begin
  n:=4;
  for i:=1 to n do
   read(a[i]);
  arifmetr;
  geometr;
  writeln(42);
 end.

var n,i,j:longint;
    a:array[0..4]of longint;
procedure swap(var q,w:longint);
var z:longint;
 begin
  z:=q;
  q:=w;
  w:=z;
 end;
procedure arifmetr;
var x,i,p,cons:longint;
 begin
  p:=0;
  cons:=a[2]-a[1];
  for i:=2 to n do
   begin
    x:=a[i]-a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(p=0)then
   begin
    writeln(a[4]+x);
    halt(0);
   end;
 end;
procedure geometr;
var i,p:longint;
    x,cons:extended;
 begin
  cons:=a[2]/a[1];
  for i:=2 to n do
   begin
    x:=a[i]/a[i-1];
    if(x<>cons)then
     begin
      p:=1;
      break;
     end;
   end;
  if(p=0)then
   begin
    writeln(a[4]*x);
    halt(0);
   end;
 end;
 begin
  n:=4;
  for i:=1 to n do
   read(a[i]);
  arifmetr;
  geometr;
  writeln(42);
 end.

Program z328A;

var
  a, b, c, d, s1, s2, s3: longint;
  p1, p2, p3:real;

begin
  readln(a, b, c, d);
  if (a = b)and(b = c)and(c = d) then writeln(a)
  else
  //if ((aa > b)and(b > c)and(c > d)) or ((a < b)and(b < c)and(c < d))//Знакочередование может быть в случае с геом прогр
  //  then
     begin
           s1 := b - a;
           s2 := c - b;
           s3 := d - c;
           p1:=0;p2:=0;p3:=0;
           if a<>0 then p1 := b / a;// На ноль делить нельзя
           if b<>0 then p2 := c / b;
           if c<>0 then p3 := d / c;
           //writeln(p1,' ',p2,' ',p3);
           if (s1 = s2)and(s2 = s3)
             then writeln(d + s1)
             else if (p1 = p2)and(p2 = p3)and(p1<>0)//!!!
                    then writeln(trunc(d * b/a))//Целое число должно бытьб не real:)!!!
                                       //1/3
                    else writeln(42)
         end
    //else writeln(42)
  //readln !!!!!
end.

Program z328A;

var
  a, b, c, d, s1, s2, s3, p1, p2, p3: longint;

begin
  readln(a, b, c, d);
  if (a = b)and(b = c)and(c = d) then writeln(a)
  else
  if ((a > b)and(b > c)and(c > d)) or ((a < b)and(b < c)and(c < d))
    then begin
           s1 := b - a;
           s2 := c - b;
           s3 := d - c;
           p1 := b div a;
           p2 := c div b;
           p3 := d div c;
           //writeln(p1,' ',p2,' ',p3);
           if (s1 = s2)and(s2 = s3)
             then writeln(d + s1)
             else if (p1 = p2)and(p2 = p3)
                    then writeln(d * p1)
                    else writeln(42)
         end
    else writeln(42);
  readln
end.

Program z328A;

var
  a, b, c, d, s1, s2, s3: longint;
  p1, p2, p3:real;

begin
  readln(a, b, c, d);
  if (a = b)and(b = c)and(c = d) then writeln(a)
  else
  //if ((aa > b)and(b > c)and(c > d)) or ((a < b)and(b < c)and(c < d))//Знакочередование может быть в случае с геом прогр
  //  then
     begin
           s1 := b - a;
           s2 := c - b;
           s3 := d - c;
           p1:=0;p2:=0;p3:=0;
           if a<>0 then p1 := b div a;// На ноль делить нельзя
           if b<>0 then p2 := c div b;
           if c<>0 then p3 := d div c;
           //writeln(p1,' ',p2,' ',p3);
           if (s1 = s2)and(s2 = s3)
             then writeln(d + s1)
             else if (p1 = p2)and(p2 = p3)and(p1<>0)//!!!
                    then writeln(trunc(d * p1))//Целое число должно бытьб не real:)!!!
                    else writeln(42)
         end
    //else writeln(42)
  //readln !!!!!
end.

Program z328A;

var
  a, b, c, d, s1, s2, s3: longint;
  p1, p2, p3:real;

begin
  readln(a, b, c, d);
  if (a = b)and(b = c)and(c = d) then writeln(a)
  else
  //if ((aa > b)and(b > c)and(c > d)) or ((a < b)and(b < c)and(c < d))//Знакочередование может быть в случае с геом прогр
  //  then
     begin
           s1 := b - a;
           s2 := c - b;
           s3 := d - c;
           p1:=0;p2:=0;p3:=0;
           if a<>0 then p1 := b div a;// На ноль делить нельзя
           if b<>0 then p2 := c div b;
           if c<>0 then p3 := d div c;
           //writeln(p1,' ',p2,' ',p3);
           if (s1 = s2)and(s2 = s3)
             then writeln(d + s1)
             else if (p1 = p2)and(p2 = p3)
                    then writeln(trunc(d * p1))//Целое число должно бытьб не real:)!!!
                    else writeln(42)
         end
    //else writeln(42)
  //readln
end.

Var z,i:longint;
ch1,zn1,ch,zn:longint;
f:boolean;
m:array [1..100] of longint;
function nod(a,b:longint):longint;
begin
  if b>a
  then nod:=nod(b,a)
  else if b=0
       then nod:=a
       else nod:=nod(b,a mod b);
end;
begin
 // Assign(input,'input.txt'); reset(input);
 // Assign(output,'output.txt'); rewrite(output);
  for i:=1 to 4 do
  read(m[i]);
  z:=m[2]-m[1];
  f:=true;
  for i:=3 to 4 do
  if m[i]-m[i-1]<>z
  then f:=false;
  if f
  then begin
        writeln(m[4]+z);
        halt(0);
       end;
  ch:=m[2];
  zn:=m[1];
  z:=nod(m[2],m[1]);
  ch:=ch div z;
  zn:=zn div z;
  f:=true;
  for i:=3 to 4 do
  begin
    ch1:=m[i];
    zn1:=m[i-1];
    z:=nod(m[i],m[i-1]);
    ch1:=ch1 div z;
    zn1:=zn1 div z;
    if (ch1<>ch)or(zn1<>zn)
    then f:=false;
  end;
  if (m[4]*ch) mod zn<>0
  then f:=false;
  if f
  then writeln(42)
  else writeln((m[4]*ch) div zn);
end.

program Project2;

{$APPTYPE CONSOLE}

uses   SysUtils;
var m: array [1..10] of Integer;
    x,y,z,t: Integer;
    arif, geom: Boolean;
    next: Real;
begin
  { TODO -oUser -cConsole Main : Insert code here }
  Readln(x,y,z,t);
  if  (y-x = z-y) and (t-z = z-y ) then Writeln(2*t-z)
  else
    if  (y/x=z/y) and (t/z=z/y) then
      if  Frac(t*t/z) = 0  then Writeln(t*t/z :0:0)
       else writeln(42);

end.

program Project2;

{$APPTYPE CONSOLE}

uses   SysUtils;
var m: array [1..10] of Integer;
    i,j,k,d,q: Integer;
    arif, geom: Boolean;
begin
  { TODO -oUser -cConsole Main : Insert code here }
  for i:=1 to 4 do Read(m[i]);
  arif:=True;
  geom:=True;
  d:=m[2]-m[1];

  for i:=2 to 4 do
    if m[i]-m[i-1] <> d   then arif :=False;
  for i:=2 to 3 do
    if  m[i-1]*m[i+1] <> m[i]*m[i] then geom:=False;
  if arif then Writeln(m[4]+d)
    else  if  geom then Writeln(m[4]*m[4]/m[3]:0:2)
     else Writeln(42);

end.

program Project2;

{$APPTYPE CONSOLE}

uses   SysUtils;
var m: array [1..10] of Integer;
    i,j,k,d,q: Integer;
    arif, geom: Boolean;
begin
  { TODO -oUser -cConsole Main : Insert code here }
  for i:=1 to 4 do Read(m[i]);
  arif:=True;
  geom:=True;
  d:=m[2]-m[1];

  for i:=2 to 4 do
    if m[i]-m[i-1] <> d   then arif :=False;
  for i:=2 to 3 do
    if  m[i-1]*m[i+1] <> m[i]*m[i] then geom:=False;
  if arif then Writeln(m[4]+d)
    else  if  geom then Writeln(m[4]*m[4]/m[3]:0:0)
     else Writeln(42);

end.