var
a,b,d,e,f,g:longint;
c:array[1..17]of longint;
z:array[1..9]of longint;
begin
assign(input,'palsquare.in');
assign(output,'palsquare.out');
reset(input);
rewrite(output);
read(b);
d:=0;
for a:=1 to 300 do
begin
d:=d+2*a-1;
c[1]:=d;
for e:=1 to 16 do
begin
c[e+1]:=c[e] div b;
c[e]:=c[e] mod b;
end;
e:=17;
while c[e]=0 do dec(e);
f:=0;
for g:=1 to e div 2 do
if c[g]<>c[e-g+1] then
begin
f:=1;
break;
end;
if f=0 then
begin
z[1]:=a;
for g:=1 to 8 do
begin
z[g+1]:=z[g] div b;
z[g]:=z[g] mod b;
end;
while z[g]=0 do dec(g);
for g:=g downto 1 do
if z[g]<10 then write(z[g])
else write(chr(z[g]+55));
write(' ');
for e:=1 to e do
if c[e]<10 then write(c[e])
else write(chr(c[e]+55));
writeln;
end;
end;
close(input);close(output);
end.