var n,x,k,pols:int64;
    f,myl:boolean;
begin
  read(n);
  myl:=false;
  repeat
  x:=1;
  while round(sqrt(n*x))<>sqrt(n*x) do inc(x);
  pols:=n;
  n:=round(sqrt(n*x));
  f:=false;
  if n=pols then f:=true
  else
  begin
    if (x>1)and not myl then
    begin
    myl:=true;
    k:=k+2
    end
    else k:=k+1;
  end;
  until f;
  write(n,' ',k);
end.

program b1062;
var
n,colpred,min,col,del,st:integer;
bool,bool2:boolean;
function f(i:integer):integer;
begin
while i>1 do
begin
if i mod 2 =1 then begin i+=1;bool:=true; end;
i:= i div 2;
result+=1;
end;
end;
begin
st:=0;
min:=1;
read(n);
for del:= 2 to (n) do
begin
col:=0;
while n mod del= 0 do
begin
n:=n div del;
col+=1;
end;
if col>0 then begin min*=del;if (col<>colpred)and(colpred>0)and(col>0) then bool2:=true;if st<f(col) then st:=f(col); end;
if col<>0 then colpred:=col;
if n<del then break;
end;
if (bool)or(bool2) then st+=1;

write(min,' ',st);
end.

var
 p:boolean;
 n,i,ans,s,t,max,f:longint;
 a:array[0..1000005] of longint;
begin
 read(n);
 t:=n;
 p:=false;
 ans:=1;
 if n=1 then begin writeln('1 0');halt;end;
 for i:=2 to t do
  if n mod i=0 then
   begin
    ans:=ans*i;
    while (n<>1) and (n mod i=0) do begin inc(a[i]);n:=n div i;end;
   end;
   for i:=1 to t do
    if (a[i]<>0) then begin if a[i]>max then max:=a[i];end;
   for i:=1 to t do
    if (a[i]<>0) and (a[i]<>max) then begin p:=true;inc(s);break;end;
  f:=1;
  while f<max do begin f:=f*2;inc(s);end;
  if not p and (max<f) then inc(s);
  writeln(ans,' ',s);
end.

var
n:integer;
min:integer;
op:integer;
col:integer;
del:integer;
st:integer;
bool:boolean;
bool2:boolean;
colpred:integer;

function f(i:integer):integer;
begin
while i>1 do
begin
if i mod 2 =1 then begin i+=1;bool:=true; end;
i:= i div 2;
result+=1;
end;
end;
begin
st:=0;
op:=0;
min:=1;
read(n);
for del:= 2 to (n) do
begin
col:=0;
while n mod del= 0 do
begin
n:=n div del;
col+=1;
end;
if col>0 then begin min*=del;if (col<>colpred)and(colpred>0)and(col>0) then bool2:=true;if st<f(col) then st:=f(col); end;
if col<>0 then colpred:=col;
if n<del then break;
end;
if (bool)or(bool2) then st+=1;

write(min,' ',st);
end.

var     s:array[1..1000000] of integer;
        q:array[1..1000] of longint;
        n,m,l,i,res,res1:longint;

function max(a,b:longint):longint;
begin
        if a>b then exit(a)
                else
                        exit(b);
end;
function cal1:byte;
var   ok:boolean; i,k,u:longint;
        begin
                ok:=true;
                for i:=2 to l do
                        if s[q[i]]<>s[q[i-1]] then
                                begin
                               ok:=false;
                               break;
                                end;

                if ok then
                        begin
                                u:=s[q[1]];
                                if u=1 then exit(0);
                                k:=1;
                                while k<=u do
                                        begin
                                                  k:=k shl 1;
                                                if k=u then exit(0);

                                        end;
                        end;
                exit(1);
        end;

function cal2:longint;
var  tmp,i,k:longint;
        begin
                tmp:=0;
                m:=0;
                res1:=1;
                for i:=1 to l do
                        begin
                        m:=max(m,s[q[i]]);
                        res1:=res1*q[i];
                        end;
                k:=1;
                        while k<m do
                                begin
                                        inc(tmp);
                                        k:=k shl 1;
                                end;
                exit(tmp);
        end;

begin
                m:=0;
                l:=0;
                readln(n);
                        if n=1 then
                                begin
                                        write(1,' ',0);
                                        halt;
                                end;
                i:=2;
                while (i*i<=n) do
                       begin
                                while (n mod i=0) do
                                        begin
                                                m:=max(m,i);
                                                if s[i]=0 then
                                                       begin
                                                                inc(l);
                                                                q[l]:=i;

                                                       end;
                                                inc(s[i]);
                                                        n:=n div i;
                                        end;
                       inc(i);
                       end;
                if (n<>1) then
                        begin
                                m:=max(m,n);
                                if s[n]=0 then
                                        begin
                                                inc(l);
                                                q[l]:=n;
                                        end;
                                inc(s[n]);
                        end;

                    res:=cal1+cal2;
                write(res1,' ',res);
end.

Program ILoveYou;
VAR n,k,max,k2,min,p,i,n2:int64;
Begin

Readln(n);
min:=10000;
max:=0;
p:=1;
i:=2;
while (i <= n) do
Begin

k:=0;
while ((n mod i) = 0) do
Begin
k:=k + 1;
n:=n div i;
end;

if (k <> 0) and (k < min) then min:=k;
if (k > max) then max:=k;
if (k > 0) then p:=p*i;

i:=i + 1;

end;

Write(p,' ');
if (max > 1) then
Begin

p:=1;
k2:=0;
while (p < max) do
Begin
p:=p*2;
k2:=k2 + 1;
end;

if (p <> max) or (min <> max) then k:=1 else k:=0;

Writeln(k + k2);

end else Writeln(0);

Readln;
END.

var f : text;
i,n,kq,k,max,dem,kq1,l : longint;
a,b : array[1..100000] of longint;
function kt(i: longint) : boolean;
var j : longint;
begin
        kt := true;
        if i <= 1 then kt := false else
                begin
                        for j := 2 to trunc(sqrt(i)) do
                                if i mod j = 0 then
                                        begin
                                                kt := false;
                                                break;
                                        end;
                end;
end;

begin
        readln(n);
        kq := n;
        kq1 := 1;
        for i := 2 to n do
                if (n mod i = 0) and (kt(i)) then
                        begin
                                inc(dem);
                                a[dem] := i;
                                kq1 := kq1 * i;
                        end;
        i := 0;
        repeat
                inc(i);
                k := 0;
                if i > dem then break;
                repeat
                        if n mod a[i]=0 then
                        n := n div a[i] else break;
                        inc(k);
                until (n mod a[i] <> 0)  or (n<=1);
                b[i] := k;
                if k > max then max := k;
        until  i = dem;
        n := kq;
        kq := 1;
        for i := 1 to 29 do
                if (kq*2) < max then kq := kq*2 else break;
        if max > 1 then max := kq * 2 else max := 0;
        kq := 0;
        i:= 0;
        repeat
                inc(i);
                if i>dem then break;
                if b[i] < max then
                        begin
                                b[i] := max;
                                inc(kq);
                        end;
        until i = dem;
        if kq > 0 then kq := 1;
        l := 0;
        repeat
                if b[i]<=1 then break;
                b[i] := b[i] div 2;
                inc(l);
                if b[i]=1 then break;
        until b[i] <= 1;
        writeln(kq1,' ',kq+l);
end.

                           const eps=0.0000000001;  besk1=200000008;  nnn=4600000;
              modul={1000000007}998244353 ;
   besk=4000000000000000000;
   label 22,1,2,3,4;
    type    real=extended;   double=extended;
    mas=array [-300000..nnn] of int64;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[-10000..nnn] of longint;mass1=^mass;
    var posleft,posright,n,xxx,yyy,dx,dy,m,w,h,zz,jjj,l,r,aa,bb,cc,sum,mnog,nn,t3,t4,t5,t6,posmax,tmax,kold,kk,j2,ttt,ppp,kol,sq,pmin,pmax,limit,posi,posj,diam,oldt,ot1,time,pos,ll,rr,posx,posy,gr,dloch,newdl,oldn,oldm,ost,ot,p1,p2,p3,p4,znamzz,kolperiod,znam,tperiod,start,finish,kol1,kol2,lavel,x0,p0,t2,t1,jj,ii,ogr,q,p,pp,tt,oldtt,qq,qq1,qq2,q1,q2,imax,t,nm,smin,cen:int64;
   k,i2,i3,step2,k1,k2,pp0,mask,i1,j1,step1, step, i,j:longint;
   d,xx,yy,b,a,zsum,y,x,z:array[-200000..4350012] of int64;
    prob1,prob2,prob3,pr1new,pr2new,pr3new,pr1,pr2,pr3:zap;
    iii,oldpos,finot,vv,znak:int64;
    aold:mas;
    v,ans,ccc,dist,alpha,phi:extended;
    koef,polex,poley,dd:array[-1..2400,-1..2103] of int64;
    ppos,mma,ma:array[-1000..2000005,-1..15] of int64;
    xleft,xright,xplus,xminus,px,py,xc,yc,xxc,yyc:extended;
    del:array[-1..100001,-1..150] of longint;
    z0,num,y1,z1,z2,kolnul,fact,next,prev,str,s,name,dnew, voltay,c,day:mas;
    zzz:array[0..125000000] of byte;
    aaa,bbb,x1,x2:extended;
    pole:array[-10..2002,-10..2005] of char;
    ddd,ppole,ddl,ddr,dd3,dd4:array[-10..200,-10..220] of int64;
    ddnew:array[-1..12,-1..12,0..200,0..3] of int64;
   newzan,marked,zanx,zany:array[-1000000..2000000] of boolean;
    ssold,sss1,sss2:string;
    def,stepen,koled,dl,och,newoch,place,newnabor,stoim,nabor:array[-10..200005] of int64;
     zanleft,zanright,zan,fl:array[-100000..10000000] of boolean;
    ss1,ss2,ss:string;ch,ch1,ch2:char;
    pr,hesh,numright,dr: array [-10..206000,-1..16] of int64;
    s3,s2,s1:array[-100..500000] of string;

    grr :array [-10..2010,-10..2010] of boolean;
    maxpr:array[0..nnn] of string;
    sss:array[-10..nnn] of string;
     tx,ty,vel,ott,v0,v1,s0,t0:int64;
     zv:point;
     left,right,ugol,rot,temp,sumtemp,vol,newx,newy:array[-1000..400000] of int64;
     mash,sqx,sqy,ottt:extended;
     xxxx,yyyy,yot:double;
       flag2,flag,flag1:boolean;

  function max(a,b:int64):int64;
begin max:=a; if b>a then max:=b;   end;

  function min(a,b:int64):int64;
begin min:=a; if b<a then min:=b;   end;

procedure udal(p:longint);
begin  next[prev[p]]:=next[p]; prev[next[p]]:=prev[p]; end;

      function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

     function summ(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p2+xx.p2*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=t1 div tt mod modul;
    t2:=t2 div tt mod modul;
    ott.p1:=t1; ott.p2:=t2;

   summ:=@ott;
 end;

     function prod(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=(t1 div tt) mod modul;
    t2:=(t2 div tt) mod modul;
    ott.p1:=t1; ott.p2:=t2;

   prod:=@ott;
 end;

    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p{/pi*180};
 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 shr 1); degg:=p*p mod modul;   end;

end;

function prost(tt:int64):boolean;
var aa:extended; i,p,t:longint;  fl:boolean;
 begin
   fl:=true;
   aa:=tt;
   aa:=sqrt(aa);
   t:=round(aa);
   for i:=2 to t do if tt mod i=0 then fl:=false;

   prost:=fl;
 end;

function arcsin(pp:extended):extended;
var tt:extended;
begin
   if (abs(pp)<=1+eps)and (abs(pp)>=1-eps)
   then if pp>0 then arcsin:=pi/2 else arcsin:=-pi/2;
   tt:=1-pp*pp;
   if abs(tt)>=0 then
     begin
        arcsin:=arctan(pp/sqrt(tt));

     end;

end;

function gl(ch:char):boolean;
begin
 if (ch='o')or (ch='a')or(ch='e')or(ch='u')or(ch='i') then gl:=true else gl:=false;

end;

function zaprmax(left,right:longint):int64;
begin
   if left>=right then zaprmax:=y[left] else
     begin
        if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
         begin
          if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
          if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);

         end;

     end;

end;

 function ff(gr:int64):boolean;

var ot,aa,bb,cc:int64; fl:boolean;
begin
  aa:=1; bb:=m;  cc:=aa; fl:=false;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if y[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,m+1);
   repeat dec(cc) until y[cc]<=gr;
   if y[cc]=gr then fl:=true else fl:=false;
  ff:=fl;
end;

function minprdel(t:int64):int64; label 2;
var i,j:longint; ot,p,pp:int64; v:extended; fl:boolean;
begin
  v:=t;
  v:=sqrt(v)+eps;
  fl:=false;
  for i:=2 to trunc(v) do if t mod i=0 then begin pp:=i; fl:=true; goto 2; end;
2: if fl then minprdel:=pp else minprdel:=t;

end;

begin
   { assign (input,'D:\Projects\input.txt');reset(input);
      assign (output,'D:\Projects\output.txt'); rewrite(output);
    }

      read(n);
      if n=1 then begin writeln(1,' ',0); goto 1;  end;
     while n>1 do
       begin
          for i:=2 to n do if n mod i=0 then
            begin  inc(q); x[q]:=i; while n mod i=0 do begin inc(y[q]); n:=n div i;  end;   end;

       end;

    {   for i:=1 to q do writeln(x[i],' ',y[i]);
    }   ot:=1;
       for i:=1 to q do ot:=ot*x[i];
       pp:=0;
       for i:=1 to q do pp:=max(pp,y[i]);

       for i:=0 to 20 do if 1 shl i>=pp then begin ii:=i; goto 2;  end;
  2:     for i:=1 to q do if y[i]<>y[1] then flag1:=true;
       for i:=0 to 10 do if y[1]=1 shl i then flag2:=true;

       if flag1 or not flag2 then inc(ii);
       writeln(ot,' ',ii);

1:             close(output);
end.

var
b,a:Array[-10..10000000]of longint;
i:longint;
max,kol,ans,n,x,p:int64;
begin
readln(n);
x:=n;
p:=trunc(sqrt(n));
i:=2;
ans:=1;
while (i<=p) do begin
      while (x mod i =0) do begin
       x:=x div i;
       inc(a[i]);
       if a[i]=1 then ans:=ans*i;
      end;
      inc(i);
end;
if x>1 then begin
      inc(a[x]);
      ans:=ans*x;
end;
write(Ans,' ');
for i:=1 to 2000  do if a[i]>0 then begin
if a[i]>max then max:=a[i];
end;

x:=1;
ans:=0;
while true do begin
    x:=x*2;
    inc(ans);
    if x>=max then break;
end;
for i:=1 to 2000 do if (A[i]>0)and(a[i]<>x) then begin
    inc(ans);
    break;
end;
if (max=1)or(max=0) then write(0)
else
writeln(Ans);

end.

uses math;
var x,c,n,i,j:longint;a,b:array[1..100000]of longint;
function nd(n:longint):longint;//assign(f,'i.txt');reset(f);assign(g,'o.txt');rewrite(g);
var i:longint;
begin
for i:=2 to round(sqrt(n)) do if (n mod i)=0 then begin nd:=i;exit end;nd:=0
end;
function dd(var n:longint;c:longint):longint;
var i:longint;
begin
i:=0;while true do if (n mod c)=0 then begin inc(i);n:=n div c end else break;dd:=i
end;
begin
//assign(f,'i.txt');reset(f);assign(g,'o.txt');rewrite(g);
read(n);if n=1 then begin writeln(1,' ',0);exit end;
while true do begin i:=nd(n);if i=0 then break;j:=dd(n,i);inc(c);a[c]:=i;b[c]:=j end;
if n<>1 then begin inc(c);a[c]:=n;b[c]:=1 end;
//for c:=1 to c do writeln(a[c],' ',b[c]);
j:=0;for i:=1 to c do if b[i]>b[j] then j:=i;//writeln(j);
//writeln(j);
i:=1;while i<b[j] do i:=i shl 1;
for c:=1 to c do if b[c]<>i then x:=1;
j:=1;for c:=1 to c do j:=j*a[c];
writeln(j,' ',round(log2(i))+x);
//writeln(x,' ',i);
end.

var n,i,tmp,count:longint;
    tmp2:int64;
begin
    readln(n);
    if n mod 2=0 then
       tmp2:=2
    else tmp2:=1;
    tmp:=n;
    while tmp mod 2=0 do
       tmp:=tmp div 2;
    i:=3;
    while i<=trunc(sqrt(tmp)) do
        begin
           if tmp mod i=0 then
              begin
                 tmp2:=tmp2*i;
                 while tmp mod i=0 do
                    tmp:=tmp div i;
              end;
           inc(i,2);
        end;
    //write(tmp2,' ');
    if tmp<>1 then tmp2:=tmp2*tmp;
    write(tmp2,' ');
    count:=0;
    while (tmp2 mod n<>0) do
       begin
          tmp2:=sqr(tmp2);
          inc(count);
       end;
    if tmp2>n then inc(count);
    write(count);
end.

uses math;
var
        n:longint;
        kt: array[1..1000002] of boolean;
procedure sang(x:longint);
var
        i,j:longint;
begin
        fillchar(kt,sizeof(kt),true);
        kt[1]:=false;
        for i:=2 to trunc(sqrt(x)) do
                if(kt[i]=true) then
                begin
                        j:=i*i;
                        while (j<=x) do
                        begin
                                kt[j]:=false;
                                j:=j+i;
                        end;
                end;
end;
procedure nguyenban();
var
        mu2: array[1..30] of longint;
        m,vt,i,mu,res:longint;
        kt2:boolean;
begin
        sang(n);
        mu2[1]:=2;m:=0;vt:=2;res:=1;kt2:=true;
        for i:=2 to 20 do mu2[i]:=mu2[i-1]*2;
        while(n>1) do
        begin
                mu:=0;
                if (kt[vt]=true) then
                begin
                        if (n mod vt =0) then res:=res*vt;
                        while  (n mod vt = 0) do
                        begin
                                mu:=mu+1;n:=n div vt;
                        end;
                end;
                if (((m<>0)and(mu<>0)) and (m <> mu)) then kt2:=false;
                m:=max(m,mu);
                vt:=vt+1;
        end;
        vt:=1;
        while (m>mu2[vt]) do vt:=vt+1;
        write(res,' ');
        if(m=1) then write(0)
        else
                if ((kt2=true) and (m=mu2[vt])) then write(vt)
                else
                        write(vt+1);
end;
begin
        read(n);
        if (n=1) then write('1 0')
        else
        nguyenban();
end.

var     s:array[1..1000000] of integer;
        q:array[1..1000] of longint;
        n,m,l,i,res,res1:longint;

function max(a,b:longint):longint;
begin
        if a>b then exit(a)
                else
                        exit(b);
end;
function cal1:byte;
var   ok:boolean; i,k,u:longint;
        begin
                ok:=true;
                for i:=2 to l do
                        if s[q[i]]<>s[q[i-1]] then
                                begin
                               ok:=false;
                               break;
                                end;

                if ok then
                        begin
                                u:=s[q[1]];
                                if u=1 then exit(0);
                                k:=1;
                                while k<=u do
                                        begin
                                                  k:=k shl 1;
                                                if k=u then exit(0);

                                        end;
                        end;
                exit(1);
        end;

function cal2:longint;
var  tmp,i,k:longint;
        begin
                tmp:=0;
                m:=0;
                res1:=1;
                for i:=1 to l do
                        begin
                        m:=max(m,s[q[i]]);
                        res1:=res1*q[i];
                        end;
                k:=1;
                        while k<m do
                                begin
                                        inc(tmp);
                                        k:=k shl 1;
                                end;
                exit(tmp);
        end;

begin
                m:=0;
                l:=0;
                readln(n);
                i:=2;
                while (i*i<=n) do
                       begin
                                while (n mod i=0) do
                                        begin
                                                m:=max(m,i);
                                                if s[i]=0 then
                                                       begin
                                                                inc(l);
                                                                q[l]:=i;

                                                       end;
                                                inc(s[i]);
                                                        n:=n div i;
                                        end;
                       inc(i);
                       end;
                if (n<>1) then
                        begin
                                m:=max(m,n);
                                if s[n]=0 then
                                        begin
                                                inc(l);
                                                q[l]:=n;
                                        end;
                                inc(s[n]);
                        end;

                    res:=cal1+cal2;
                write(res1,' ',res);
end.

var f : text;
i,j,n,dem,kq,k,l,max : longint;
kt : array[1..1000000] of boolean;
a,b : array[1..1000] of longint;
procedure sang;
begin
        i := 1;
        repeat
                inc(i);
                if kt[i] then
                        begin
                                inc(dem);
                                a[dem] := i;
                                for j := 1 to n div i do kt[i*j] := not(true);
                        end;
        until i = round(sqrt(n))+1;
end;

begin
      {  assign(f,'MATH.INP');
        reset(f);}
        readln(n);
      {  close(f);}
      {  assign(f,'MATH.OUT');
        rewrite(f); }
        fillchar(kt,sizeof(kt),true);
        sang;
        kq := n;
        for i := 1 to dem do
                if n mod a[i] = 0 then
                        begin
                                inc(k);
                                dem := 0;
                                repeat
                                        n := n div a[i];
                                        inc(dem);
                                until (n mod a[i] <> 0)or(n<=1);
                                a[k] := a[i];
                                b[k] := dem;
                        end;
        n := kq;
        dem := 0;
        l := 1;
        repeat
                j := 0;
                l := 1;
                kq := 1;
                max := 0;
                for i := 1 to k do if b[i]<=1 then inc(j);
                if j=k then break;
                for i := 1 to k do
                        if b[i] mod 2 = 0 then inc(max);
                if max <> k then
                begin
                for i := 1 to k do if b[i] > max then max := b[i];
                if max mod 2 = 1 then inc(max);
                end else max := 0;
                for i := 1 to k do
                        begin
                                if b[i] > 0 then
                                        begin
                                                if b[i] < max then
                                                        begin
                                                                repeat
                                                                inc(b[i]);
                                                                kq := kq * a[i];
                                                                until b[i]>=max;
                                                                l := 0;
                                                        end;
                                                b[i] := b[i] div 2;
                                        end;
                        end;
                if l=0 then inc(dem);
                n := round(sqrt(n*kq));
                inc(dem);
        until false;
        writeln(n,' ',dem);
      {  close(f); }
end.

var f : text;
i,j,n,dem,kq,k,l,max : longint;
kt : array[1..10000000] of boolean;
a,b : array[1..1000000] of longint;
procedure sang;
begin
        i := 1;
        repeat
                inc(i);
                if kt[i] then
                        begin
                                inc(dem);
                                a[dem] := i;
                                for j := 1 to n div i do kt[i*j] := not(true);
                        end;
        until i = trunc(sqrt(n))+1;
end;

begin
        readln(n);
        fillchar(kt,sizeof(kt),true);
        if n>=2 then sang;
        kq := n;
        if n>=2 then
        begin
        for i := 1 to dem do
                if n mod a[i] = 0 then
                        begin
                                inc(k);
                                dem := 0;
                                repeat
                                        n := n div a[i];
                                        inc(dem);
                                until (n mod a[i] <> 0)or(n<=1);
                                a[k] := a[i];
                                b[k] := dem;
                        end;
        n := kq;
        dem := 0;
        l := 1;
        repeat
                j := 0;
                l := 1;
                kq := 1;
                max := 0;
                for i := 1 to k do if b[i]<=1 then inc(j);
                if j=k then break;
                for i := 1 to k do
                        if b[i] mod 2 = 0 then inc(max);
                if max <> k then
                begin
                for i := 1 to k do if b[i] > max then max := b[i];
                if max mod 2 = 1 then inc(max);
                end else max := 0;
                for i := 1 to k do
                        begin
                                if b[i] > 0 then
                                        begin
                                                if b[i] < max then
                                                        begin
                                                                repeat
                                                                inc(b[i]);
                                                                kq := kq * a[i];
                                                                until b[i]>=max;
                                                                l := 0;
                                                        end;
                                                b[i] := b[i] div 2;
                                        end;
                        end;
                if l=0 then inc(dem);
                n := round(sqrt(n*kq));
                inc(dem);
        until false;
        writeln(n,' ',dem);
        end else
                begin
                        if n = 1 then writeln(1,' ',0);
                        if n = 0 then writeln(0,' ',0);
                end;
end.

var
b,a:Array[-10..100000]of longint;
i:longint;
max,kol,ans,n,x,p:int64;
begin
readln(n);
x:=n;
p:=trunc(sqrt(n));
i:=2;
ans:=1;
while (i<=p) do begin
      while (x mod i =0) do begin
       x:=x div i;
       inc(a[i]);
       if a[i]=1 then ans:=ans*i;
      end;
      inc(i);
end;
if x>1 then begin
      inc(a[x]);
      ans:=ans*x;
end;
write(Ans,' ');
for i:=1 to 2000  do if a[i]>0 then begin
if a[i]>max then max:=a[i];
end;

x:=1;
ans:=0;
while true do begin
    x:=x*2;
    inc(ans);
    if x>=max then break;
end;
for i:=1 to 2000 do if (A[i]>0)and(a[i]<>max) then begin
    inc(ans);
    break;
end;
if max=1 then write(0)
else
writeln(Ans);

end.

var
b,a:Array[-10..10000000]of longint;
i:longint;
max,kol,ans,n,x,p:int64;
begin
readln(n);
x:=n;
p:=trunc(sqrt(n));
i:=2;
ans:=1;
while (i<=p) do begin
      while (x mod i =0) do begin
       x:=x div i;
       inc(a[i]);
       if a[i]=1 then ans:=ans*i;
      end;
      inc(i);
end;
if x>1 then begin
      inc(a[x]);
      ans:=ans*x;
end;
write(Ans,' ');
for i:=1 to 2000  do if a[i]>0 then begin
if a[i]>max then max:=a[i];
end;

x:=1;
ans:=0;
while true do begin
    x:=x*2;
    inc(ans);
    if x>=max then break;
end;
for i:=1 to 2000 do if (A[i]>0)and(a[i]<>x) then begin
    inc(ans);
    break;
end;
if max=1 then write(0)
else
writeln(Ans);

end.

var
b,a:Array[-10..100000]of int64;
i:longint;
max,kol,ans,n,x,p:int64;
begin
readln(n);
x:=n;
p:=trunc(sqrt(n));
i:=2;
ans:=1;
while (i<=p) do begin
      while (x mod i =0) do begin
       x:=x div i;
       inc(a[i]);
       if a[i]=1 then ans:=ans*i;
      end;
      inc(i);
end;
if x>1 then begin
      inc(a[x]);
      ans:=ans*x;
end;
write(Ans,' ');
for i:=1 to 2000  do if a[i]>0 then begin
if a[i]>max then max:=a[i];
end;

x:=1;
ans:=0;
while true do begin
    x:=x*2;
    inc(ans);
    if x>=max then break;
end;
for i:=1 to 2000 do if (A[i]>0)and(a[i]<>max) then begin
    inc(ans);
    break;
end;
writeln(Ans);

end.

uses math;
var x,c,n,i,j:longint;a,b:array[1..100000]of longint;
function nd(n:longint):longint;//assign(f,'i.txt');reset(f);assign(g,'o.txt');rewrite(g);
var i:longint;
begin
for i:=2 to round(sqrt(n)) do if (n mod i)=0 then begin nd:=i;exit end;nd:=0
end;
function dd(var n:longint;c:longint):longint;
var i:longint;
begin
i:=0;while true do if (n mod c)=0 then begin inc(i);n:=n div c end else break;dd:=i
end;
begin
//assign(f,'i.txt');reset(f);assign(g,'o.txt');rewrite(g);
read(n);while true do begin i:=nd(n);if i=0 then break;j:=dd(n,i);inc(c);a[c]:=i;b[c]:=j end;
if n<>1 then begin inc(c);a[c]:=n;b[c]:=1 end;
//for c:=1 to c do writeln(a[c],' ',b[c]);
j:=0;for i:=1 to c do if b[i]>b[j] then j:=i;//writeln(j);
//writeln(j);
i:=1;while i<b[j] do i:=i shl 1;
for c:=1 to c do if b[c]<>i then x:=1;
if odd(b[j]) then begin inc(x);inc(b[j]) end;
j:=1;for c:=1 to c do j:=j*a[c];
writeln(j,' ',round(log2(i))+x);
end.

var n,i,tmp,count:longint;
    tmp2:int64;
begin
    readln(n);
    if n mod 2=0 then
       tmp2:=2
    else tmp2:=1;
    tmp:=n;
    while tmp mod 2=0 do
       tmp:=tmp div 2;
    i:=3;
    while i<=trunc(sqrt(tmp)) do
        begin
           if tmp mod i=0 then
              begin
                 tmp2:=tmp2*i;
                 while tmp mod i=0 do
                    tmp:=tmp div i;
              end;
           inc(i,2);
        end;
    //write(tmp2,' ');
    if tmp<>1 then tmp2:=tmp2*tmp;
    write(tmp2,' ');
    count:=0;
    while tmp2<n do
       begin
          tmp2:=sqr(tmp2);
          inc(count);
       end;
    if tmp2>n then inc(count);
    write(count);
end.

var n,i,tmp,count:longint;
    tmp2:int64;
begin
    readln(n);
    if n mod 2=0 then
       tmp2:=2
    else tmp2:=1;
    tmp:=n;
    while tmp mod 2=0 do
       tmp:=tmp div 2;
    i:=3;
    while i<=trunc(sqrt(tmp)) do
        begin
           if tmp mod i=0 then
              begin
                 tmp2:=tmp2*i;
                 while tmp mod i=0 do
                    tmp:=tmp div i;
              end;
           inc(i,2);
        end;
    write(tmp2,' ');
    if tmp<>1 then tmp2:=tmp2*tmp;
    count:=0;
    while tmp2<n do
       begin
          tmp2:=sqr(tmp2);
          inc(count);
       end;
    if tmp2>n then inc(count);
    write(count);
end.

uses math;
var
        n:longint;
        kt: array[1..1000002] of boolean;
procedure sang(x:longint);
var
        i,j:longint;
begin
        fillchar(kt,sizeof(kt),true);
        kt[1]:=false;
        for i:=2 to trunc(sqrt(x)) do
                if(kt[i]=true) then
                begin
                        j:=i*i;
                        while (j<=x) do
                        begin
                                kt[j]:=false;
                                j:=j*i;
                        end;
                end;
end;
procedure nguyenban();
var
        mu2: array[1..30] of longint;
        m,vt,i,mu,res:longint;
begin
        sang(n);
        mu2[1]:=2;m:=0;vt:=2;res:=1;
        for i:=2 to 20 do mu2[i]:=mu2[i-1]*2;
        while(n>1) do
        begin
                mu:=0;
                if (kt[vt]=true) then
                begin
                        if (n mod vt =0) then res:=res*vt;
                        while  (n mod vt = 0) do
                        begin
                                mu:=mu+1;n:=n div vt;
                        end;
                end;
                m:=max(m,mu);
                vt:=vt+1;
        end;
        vt:=1;
        while (m>mu2[vt]) do vt:=vt+1;
        write(res,' ');
        if(m=1) then write(0)
        else  write(vt+1);
end;
begin
        read(n);
        nguyenban();
end.

uses math;
var
        n:longint;
        kt: array[1..1000002] of boolean;
procedure sang(x:longint);
var
        i,j:longint;
begin
        fillchar(kt,sizeof(kt),true);
        kt[1]:=false;
        for i:=2 to trunc(sqrt(x)) do
                if(kt[i]=true) then
                begin
                        j:=i*i;
                        while (j<=x) do
                        begin
                                kt[j]:=false;
                                j:=j*i;
                        end;
                end;
end;
procedure nguyenban();
var
        mu2: array[1..30] of longint;
        m,vt,i,mu,res:longint;
begin
        sang(n);
        mu2[1]:=2;m:=0;vt:=2;res:=1;
        for i:=2 to 20 do mu2[i]:=mu2[i-1]*2;
        while(n>1) do
        begin
                mu:=1;
                if (kt[vt]=true) then
                begin
                        if (n mod vt =0) then res:=res*vt;
                        while  (n mod vt = 0) do
                        begin
                                mu:=mu+1;n:=n div vt;
                        end;
                end;
                m:=max(m,mu);
                vt:=vt+1;
        end;
        vt:=1;
        while (m>mu2[vt]) do vt:=vt+1;
        write(res,' ');
        if(vt=1) then write(0)
        else  write(vt+1);
end;
begin
        read(n);
        nguyenban();
end.

uses math;
var
        n:longint;
        kt: array[1..1000002] of boolean;
procedure sang(x:longint);
var
        i,j:longint;
begin
        fillchar(kt,sizeof(kt),true);
        kt[1]:=false;
        for i:=2 to trunc(sqrt(x)) do
                if(kt[i]=true) then
                begin
                        j:=i*i;
                        while (j<=x) do
                        begin
                                kt[j]:=false;
                                j:=j*i;
                        end;
                end;
end;
procedure nguyenban();
var
        mu2: array[1..30] of longint;
        m,vt,i,mu,res:longint;
        kt2:boolean;
begin
        sang(n);
        mu2[1]:=2;m:=0;vt:=2;res:=1;kt2:=true;
        for i:=2 to 20 do mu2[i]:=mu2[i-1]*2;
        while(n>1) do
        begin
                mu:=0;
                if (kt[vt]=true) then
                begin
                        if (n mod vt =0) then res:=res*vt;
                        while  (n mod vt = 0) do
                        begin
                                mu:=mu+1;n:=n div vt;
                        end;
                end;
                if (((m<>0)and(mu<>0)) and (m <> mu)) then kt2:=false;
                m:=max(m,mu);
                vt:=vt+1;
        end;
        vt:=1;
        while (m>mu2[vt]) do vt:=vt+1;
        write(res,' ');
        if(m=1) then write(0)
        else
                if ((kt2=true) and (m=mu2[vt])) then write(vt)
                else
                        write(vt+1);
end;
begin
        read(n);
        nguyenban();
end.

var n,x,k,pols:longint;
    f:boolean;
begin
  read(n);
  if n=1 then
  begin
    write(1,' ',0);
    halt;
  end;
  repeat
  x:=1;
  while round(sqrt(n*x))<>sqrt(n*x) do inc(x);
  pols:=n;
  n:=round(sqrt(n*x));
  f:=false;
  if n=pols then f:=true
  else
  begin
    if x>1 then
    k:=k+2;

  end;
  until f;
  write(n,' ',k);
end.

var
 p:boolean;
 n,i,ans,s,t,max,f:longint;
 a:array[0..1000005] of longint;
begin
 read(n);
 t:=n;
 p:=false;
 if n=1 then begin writeln('1 0');halt;end;
 for i:=2 to n do
  if n mod i=0 then
   begin
    ans:=ans*i;
    while (n<>1) and (n mod i=0) do begin inc(a[i]);n:=n div i;end;
   end;
   for i:=1 to t do
    if (a[i]<>0) then begin if a[i]>max then max:=a[i];end;
   for i:=1 to t do
    if (a[i]<>0) and (a[i]<>max) then begin p:=true;inc(s);break;end;
  f:=1;
  while f<max do begin f:=f*2;inc(s);end;
  if not p and (max<f) then inc(s);
  writeln(ans,' ',s);
end.

var
n:integer;
min:integer;
op:integer;
col:integer;
del:integer;

function f(i:integer):integer;
begin
while i>1 do
begin
if i mod 2 =1 then result+=1;
i:= i div 2;
result+=1;
end;
end;
begin
op:=0;
min:=1;
read(n);
for del:= 2 to round(sqr(n)) do
begin
col:=0;
while n mod del= 0 do
begin
n:=n div del;
col+=1;
end;
if col>0 then begin min*=del;if op<f(col) then op:=f(col); end;
end;
write(min,' ',op+1);
end.

var
n:integer;
min:integer;
op:integer;
col:integer;
del:integer;
st:integer;
bool:boolean;
bool2:boolean;
colpred:integer;

function f(i:integer):integer;
begin
while i>1 do
begin
if i mod 2 =1 then begin i+=1;bool:=true; end;
i:= i div 2;
result+=1;
end;
end;
begin
st:=0;
op:=0;
min:=1;
read(n);
for del:= 2 to round(sqr(n)) do
begin
col:=0;
while n mod del= 0 do
begin
n:=n div del;
col+=1;
end;
if col>0 then begin min*=del;if (col<>colpred)and(colpred>0)and(col>0) then bool2:=true;if st<f(col) then st:=f(col); end;
if col<>0 then colpred:=col;
if n<del then break;
end;
if (bool)or(bool2) then st+=1;

write(min,' ',st);
end.

var
n:integer;
min:integer;
op:integer;
col:integer;
del:integer;
st:integer;
bool:boolean;
bool2:boolean;
colpred:integer;

function f(i:integer):integer;
begin
while i>1 do
begin
if i mod 2 =1 then begin i+=1;bool:=true; end;
i:= i div 2;
result+=1;
end;
end;
begin
st:=0;
op:=0;
min:=1;
read(n);
for del:= 2 to round(sqrt(n)) do
begin
col:=0;
while n mod del= 0 do
begin
n:=n div del;
col+=1;
end;
if col>0 then begin min*=del;if (col<>colpred)and(colpred>0)and(col>0) then bool2:=true;if st<f(col) then st:=f(col); end;
if col<>0 then colpred:=col;
if n<del then break;
end;
if (bool)or(bool2) then st+=1;

write(min,' ',st);
end.

var
n:integer;
min:integer;
op:integer;
col:integer;
del:integer;
st:integer;
bool:boolean;
bool2:boolean;

function f(i:integer):integer;
begin
while i>1 do
begin
if i mod 2 =1 then begin i+=1;bool:=true; end;
i:= i div 2;
result+=1;
end;
end;
begin
st:=0;
op:=0;
min:=1;
read(n);
for del:= 2 to round(sqr(n)) do
begin
col:=0;
while n mod del= 0 do
begin
n:=n div del;
col+=1;
end;
if col>0 then begin min*=del;if col=1 then bool2:=true;if st<f(col) then st:=f(col); end;
if n<del then break;
end;
if (bool)or(bool2 and(st>0)) then st+=1;

write(min,' ',st);
end.

Program ILoveYou;
VAR n,k,max,k2,min,p,i:int64;
Begin

Readln(n);
min:=0;
max:=0;
p:=1;
i:=2;
while (i <= n) do
Begin

k:=0;
while ((n mod i) = 0) do
Begin
k:=k + 1;
n:=n div i;
end;

if (k <> 0) or (k < min) then min:=k;
if (k > max) then max:=k;
if (k > 0) then p:=p*i;
i:=i + 1;

end;

Write(p,' ');
if (max > 1) then
Begin

p:=1;
k2:=0;
while (p < max) do
Begin
p:=p*2;
k2:=k2 + 1;
end;

if (p = max) then k:=0 else k:=1;

if (p = max) or (max <> min) then k:=1;

//Writeln(k,' ',max,' ',p);

Writeln(k + k2);

end else Writeln(0);

Readln;
END.

Program ILoveYou;
VAR n,k,max,k2,min,p,i:int64;
Begin

Readln(n);
min:=0;
max:=0;
p:=1;
i:=2;
while (i <= n) do
Begin

k:=0;
while ((n mod i) = 0) do
Begin
k:=k + 1;
n:=n div i;
end;

if (k <> 0) or (k < min) then min:=k;
if (k > max) then max:=k;
if (k > 0) then p:=p*i;
i:=i + 1;

end;

Write(p,' ');
if (max > 1) then
Begin

p:=1;
k2:=0;
while (p < max) do
Begin
p:=p*2;
k2:=k2 + 1;
end;

if (p = max) then k:=0 else k:=1;

if (p <> max) or (max <> min) then k:=1;

//Writeln(k,' ',max,' ',p);

Writeln(k + k2);

end else Writeln(0);

Readln;
END.

Program ILoveYou;
VAR n,k,max,k2,min,p,i:int64;
Begin

Readln(n);
min:=0;
max:=0;
p:=1;
i:=2;
while (i <= n) do
Begin

k:=0;
while ((n mod i) = 0) do
Begin
k:=k + 1;
n:=n div i;
end;

if (k <> 0) or (k < min) then min:=k;
if (k > max) then max:=k;
if (k > 0) then p:=p*i;
i:=i + 1;

end;

Write(p,' ');
if (max > 1) then
Begin

p:=1;
k2:=0;
while (p < max) do
Begin
p:=p*2;
k2:=k2 + 1;
end;

if (p = max) then k:=0 else k:=1;

if (p = max) and (max <> min) then k:=1;

//Writeln(k,' ',max,' ',p);

Writeln(k + k2);

end else Writeln(0);

Readln;
END.

Program ILoveYou;
VAR n,k,max,k2,min,p,i:int64;
Begin

Readln(n);
min:=0;
max:=0;
p:=1;
i:=2;
while (i <= n) do
Begin

k:=0;
while ((n mod i) = 0) do
Begin
k:=k + 1;
n:=n div i;
end;

if (k <> 0) or (k < min) then min:=k;
if (k > max) then max:=k;
if (k > 0) then p:=p*i;
i:=i + 1;

end;

if (max = 1) then Writeln(p,' ',0) else
Begin

Write(p,' ');

if (min = max) then
Begin

Writeln((min div 2) + (min mod 2));

end else
Begin

k:=1;
if ((max mod 2) <> 0) then max:=max + 1;

Writeln((max div 2) + 1);

end;

end;

Readln;
END.

                           const eps=0.0000000001;  besk1=200000008;  nnn=4600000;
              modul={1000000007}998244353 ;
   besk=4000000000000000000;
   label 22,1,2,3,4;
    type    real=extended;   double=extended;
    mas=array [-300000..nnn] of int64;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[-10000..nnn] of longint;mass1=^mass;
    var posleft,posright,n,xxx,yyy,dx,dy,m,w,h,zz,jjj,l,r,aa,bb,cc,sum,mnog,nn,t3,t4,t5,t6,posmax,tmax,kold,kk,j2,ttt,ppp,kol,sq,pmin,pmax,limit,posi,posj,diam,oldt,ot1,time,pos,ll,rr,posx,posy,gr,dloch,newdl,oldn,oldm,ost,ot,p1,p2,p3,p4,znamzz,kolperiod,znam,tperiod,start,finish,kol1,kol2,lavel,x0,p0,t2,t1,jj,ii,ogr,q,p,pp,tt,oldtt,qq,qq1,qq2,q1,q2,imax,t,nm,smin,cen:int64;
   k,i2,i3,step2,k1,k2,pp0,mask,i1,j1,step1, step, i,j:longint;
   d,xx,yy,b,a,zsum,y,x,z:array[-200000..4350012] of int64;
    prob1,prob2,prob3,pr1new,pr2new,pr3new,pr1,pr2,pr3:zap;
    iii,oldpos,finot,vv,znak:int64;
    aold:mas;
    v,ans,ccc,dist,alpha,phi:extended;
    koef,polex,poley,dd:array[-1..2400,-1..2103] of int64;
    ppos,mma,ma:array[-1000..2000005,-1..15] of int64;
    xleft,xright,xplus,xminus,px,py,xc,yc,xxc,yyc:extended;
    del:array[-1..100001,-1..150] of longint;
    z0,num,y1,z1,z2,kolnul,fact,next,prev,str,s,name,dnew, voltay,c,day:mas;
    zzz:array[0..125000000] of byte;
    aaa,bbb,x1,x2:extended;
    pole:array[-10..2002,-10..2005] of char;
    ddd,ppole,ddl,ddr,dd3,dd4:array[-10..200,-10..220] of int64;
    ddnew:array[-1..12,-1..12,0..200,0..3] of int64;
   newzan,marked,zanx,zany:array[-1000000..2000000] of boolean;
    ssold,sss1,sss2:string;
    def,stepen,koled,dl,och,newoch,place,newnabor,stoim,nabor:array[-10..200005] of int64;
     zanleft,zanright,zan,fl:array[-100000..10000000] of boolean;
    ss1,ss2,ss:string;ch,ch1,ch2:char;
    pr,hesh,numright,dr: array [-10..206000,-1..16] of int64;
    s3,s2,s1:array[-100..500000] of string;

    grr :array [-10..2010,-10..2010] of boolean;
    maxpr:array[0..nnn] of string;
    sss:array[-10..nnn] of string;
     tx,ty,vel,ott,v0,v1,s0,t0:int64;
     zv:point;
     left,right,ugol,rot,temp,sumtemp,vol,newx,newy:array[-1000..400000] of int64;
     mash,sqx,sqy,ottt:extended;
     xxxx,yyyy,yot:double;
       flag2,flag,flag1:boolean;

  function max(a,b:int64):int64;
begin max:=a; if b>a then max:=b;   end;

  function min(a,b:int64):int64;
begin min:=a; if b<a then min:=b;   end;

procedure udal(p:longint);
begin  next[prev[p]]:=next[p]; prev[next[p]]:=prev[p]; end;

      function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

     function summ(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p2+xx.p2*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=t1 div tt mod modul;
    t2:=t2 div tt mod modul;
    ott.p1:=t1; ott.p2:=t2;

   summ:=@ott;
 end;

     function prod(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=(t1 div tt) mod modul;
    t2:=(t2 div tt) mod modul;
    ott.p1:=t1; ott.p2:=t2;

   prod:=@ott;
 end;

    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p{/pi*180};
 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 shr 1); degg:=p*p mod modul;   end;

end;

function prost(tt:int64):boolean;
var aa:extended; i,p,t:longint;  fl:boolean;
 begin
   fl:=true;
   aa:=tt;
   aa:=sqrt(aa);
   t:=round(aa);
   for i:=2 to t do if tt mod i=0 then fl:=false;

   prost:=fl;
 end;

function arcsin(pp:extended):extended;
var tt:extended;
begin
   if (abs(pp)<=1+eps)and (abs(pp)>=1-eps)
   then if pp>0 then arcsin:=pi/2 else arcsin:=-pi/2;
   tt:=1-pp*pp;
   if abs(tt)>=0 then
     begin
        arcsin:=arctan(pp/sqrt(tt));

     end;

end;

function gl(ch:char):boolean;
begin
 if (ch='o')or (ch='a')or(ch='e')or(ch='u')or(ch='i') then gl:=true else gl:=false;

end;

function zaprmax(left,right:longint):int64;
begin
   if left>=right then zaprmax:=y[left] else
     begin
        if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
         begin
          if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
          if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);

         end;

     end;

end;

 function ff(gr:int64):boolean;

var ot,aa,bb,cc:int64; fl:boolean;
begin
  aa:=1; bb:=m;  cc:=aa; fl:=false;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if y[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,m+1);
   repeat dec(cc) until y[cc]<=gr;
   if y[cc]=gr then fl:=true else fl:=false;
  ff:=fl;
end;

function minprdel(t:int64):int64; label 2;
var i,j:longint; ot,p,pp:int64; v:extended; fl:boolean;
begin
  v:=t;
  v:=sqrt(v)+eps;
  fl:=false;
  for i:=2 to trunc(v) do if t mod i=0 then begin pp:=i; fl:=true; goto 2; end;
2: if fl then minprdel:=pp else minprdel:=t;

end;

begin
  {  assign (input,'D:\Projects\input.txt');reset(input);
      assign (output,'D:\Projects\output.txt'); rewrite(output);

   }
      read(n);
     while n>1 do
       begin
          for i:=2 to n do if n mod i=0 then
            begin  inc(q); x[q]:=i; while n mod i=0 do begin inc(y[q]); n:=n div i;  end;   end;

       end;

    {   for i:=1 to q do writeln(x[i],' ',y[i]);
    }   ot:=1;
       for i:=1 to q do ot:=ot*x[i];
       pp:=0;
       for i:=1 to q do pp:=max(pp,y[i]);

       for i:=0 to 20 do if 1 shl i>=pp then begin ii:=i; goto 2;  end;
  2:     for i:=1 to q do if y[i]<>y[1] then flag1:=true;
       for i:=0 to 10 do if y[1]=1 shl i then flag2:=true;

       if flag1 or not flag2 then inc(ii);
       writeln(ot,' ',ii);

1:             close(output);
end.


uses math;
var i,n,h,m,l,r,x,j,sum:longint;
f:array[1..100]of longint;
begin
readln(n,h,m);
for i:=1 to n do f[i]:=h;
for i:=1 to m do
  begin
  readln(l,r,x);
  for j:=l to r do f[j]:=min(f[j],x);
  end;
for i:=1 to n do inc(sum,f[i]*f[i]);
writeln(sum);
end.

Program Restrictions;
uses math;
Type arr=array[0..57] of longint;
var f:arr; n,h,m,l,r,x:byte; i,j:longint; ans:int64;
Procedure Profit;
begin   for i:=1 to n do f[i]:=h;
        ans:=0;
        while m>0 do
        begin   readln(l,r,x);
                for j:=l to r do f[j]:=min(f[j],x);
                dec(m);
        end;
        for i:=1 to n do ans:=ans+sqr(f[i]);
        writeln(ans);
end;
begin   //assign(input,'1162A.inp'); reset(input);
        //assign(output,'1162A.out'); rewrite(output);
        readln(n,h,m);
        Profit;
        //close(input); close(output);
end.

var n,h,m,i,a,b,c,j,sum:longint;
ma:array[1..50] of integer;
begin
   readln(n,h,m);
   for i:=1 to n do
    ma[i]:=h;
   for i:=1 to m do
    begin
       readln(a,b,c);
       for j:=a to b do
        begin
           if c<ma[j]
           then ma[j]:=c;
        end;
    end;
   for i:=1 to n do
    sum:=sum+ma[i]*ma[i];
   writeln(sum);
end.

var a:array[0..100]of longint;j,h,x,n,s,i,m,l,r:longint;
begin
 read(n,h,m);
 for i:=1 to n do a[i]:=h;
 for i:=1 to m do
 begin
  read(l,r,x);
  for j:=l to r do
  if a[j]>x then a[j]:=x;
 end;
 s:=0;
 for i:=1 to n do
  s:=s+a[i]*a[i];
 write(s);

end.

var
 n,m,h,x,y,z,i,j,s:longint;
 a:array[0..55] of longint;
begin
 readln(n,h,m);
 for i:=1 to 55 do a[i]:=h;
 for i:=1 to m do
  begin
   readln(x,y,z);
   for j:=x to y do
    if z<a[j] then a[j]:=z;
  end;
 for i:=1 to n do s:=s+a[i]*a[i];
 write(s);
end.

uses math;
var g:array[1..50] of longint;
  n,m,a,b,c,d,e:longint;
begin
  readln(n,a,m);
  for b:=1 to n do g[b]:=a;
  for a:=1 to m do
   begin
    readln(b,c,d);
    for e:=b to c do g[e]:=min(g[e],d);
   end;
  b:=0;
  for a:=1 to n do b:=b+g[a]*g[a];
  writeln(b);
end.

type tabel=array[1..50] of longint;
var t:tabel;
    a,b,n,m,p,r,k,i,j:longint;
    s:int64;
begin
read(n,r,m);
for i:=1 to n do t[i]:=r;
for i:=1 to m do begin
read(a,b,k);
for j:=a to b do
if t[j]>k then t[j]:=k end;
for i:=1 to n do s:=s+sqr(t[i]);
write(s)
end.

program p1;
var j,i,n,h,m,max:integer;
l:array[1..10000] of integer;
x:array[1..10000] of integer;
r:array[1..10000] of integer;
a:array[1..10000] of integer;
begin
  max:=0;
  readln(n,h,m);

  for i:=1 to m do
  readln(l[i],r[i],x[i]);

  for i:=1 to n do
  a[i]:=h;

  for i:=1 to m do
  for j:=1 to n do
  if (l[i]<=j) and (r[i]>=j) then
  if a[j]>x[i] then
  a[j]:=x[i];

  for i:=1 to n do
  max:=max+a[i]*a[i];

  writeln(max);
  readln;

end.

uses math;
var
    n, h, m, ans, i, j, bound : longint;
    l, r, x : array[1..55] of longint;

begin
    readln(n, h, m);
    for i := 1 to m do readln(l[i], r[i], x[i]);
    ans := 0;
    for i := 1 to n do
    begin
        bound := 300;
        for j := 1 to m do
        if (i >= l[j]) and (i <= r[j]) then bound := min(bound, x[j]);
        if (bound = 300) then ans := ans + h * h
        else ans := ans + bound * bound;
    end;
    writeln(ans);
end.

uses math;
var
 n,h,m,l,r,x,s,i,j:longint;
 a:array[1..50]of longint;
begin
 readln(n,h,m);
 for i:=1 to n do
  a[i]:=h;
 for i:=1 to m do
  begin
   readln(l,r,x);
   for j:=l to r do
    a[j]:=min(a[j],x);
  end;
 for i:=1 to n do
  s:=s+a[i]**2;
 writeln(s);
end.

var min,n,h,m,sum,x,y,z,i,j:longint;
    a:array[1..1000] of longint;

begin
        readln(n,h,m);
        for i:=1 to n do a[i]:=h;
        min:=99999999;
        for i:=1 to m do
        begin
                readln(x,y,z);
                for j:=x to y do
                begin
                    if z<a[j] then a[j]:=z;
                end;
        end;
        for i:=1 to n do
        begin
                sum:=sum+(a[i]*a[i]);
        end;
        write(sum);
end.

const maxn=100;
var l,r,x,hous:array[1..maxn]of longint;
    n,h,m,i,j,ans:longint;

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

begin
  readln(n,h,m);
  for i:=1 to m do
    read(l[i],r[i],x[i]);
  for i:=1 to n do
    hous[i]:=h;
  for i:=1 to m do
    for j:=l[i] to r[i] do
      hous[j]:=min(hous[j],x[i]);
  for i:=1 to n do
    ans:=ans+sqr(hous[i]);
  writeln(ans);
end.

uses math;
var n,h,m,l,r,x,i,j,s:longint;
    a:array[1..50]of longint;
begin
  readln(n,h,m);
  for i:=1 to 50 do
    a[i]:=h;
  for i:=1 to m do
  begin
    readln(l,r,x);
    for j:=l to r do
      a[j]:=min(a[j],x);
  end;
  for i:=1 to n do
    s:=s+sqr(a[i]);
  writeln(s);
end.

uses math;
var
g:array[0..55] of longint;
n,m,a,b,c,d,e:longint;
begin
readln(n,a,m);
for b:=1 to n do g[b]:=a;
for a:=1 to m do
  begin
    readln(b,c,d);
    for e:=b to c do g[e]:=min(g[e],d);
  end;
b:=0;
for a:=1 to n do b:=b+g[a]*g[a];
writeln(b);
end.

uses math;//用math库是应为懒
var i,n,h,m,l,r,x,j,sum:longint;
f:array[1..100]of longint;//f数组代表每个房子的高度
begin
readln(n,h,m);//输入
for i:=1 to n do f[i]:=h;//将房子的高度初始化为h（最大可建筑高度）
for i:=1 to m do
  begin
  readln(l,r,x);//这里根本不需要数组
  for j:=l to r do f[j]:=min(f[j],x);//求最小（min函数是math库中请求两数最小的一个函数）
  end;
for i:=1 to n do inc(sum,f[i]*f[i]);//sum加上利润
writeln(sum);//美丽输出
end.

Var n , h , m , i , j , l , r , x : Byte;
    kq : Longint;
    A : Array [1..50] of Byte;
begin
Readln(n , h , m);
For i := 1 to n do
A[i] := h;
For i := 1 to m do
    Begin
    Readln(l , r , x);
    For j := l to r do
    If A[j] > x then A[j] := x;
    End;
For i := 1 to n do
Inc(kq , Sqr(A[i]));
Writeln(kq);
End.

var
	n, h, m, l, r, x, sum, y: integer;
	a: array[1..50] of integer;

begin

	readln(n, h, m);

	for var i := 1 to n do
	begin
		a[i] := h;
	end;

	for var i := 1 to m do
	begin
		read(l, r, x);
		for var j := l to r do
		begin
			if (a[j] > x) then
				a[j] := x;
		end;
	end;

	for var i := 1 to n do
	begin
		sum += sqr(a[i]);
	end;

	writeln(sum);

end.

var
  n,h,m:word;
  l,r,x:integer;
  sum:integer = 0;
  otvet:array [1..50] of integer;
BEGIN
  readln (n,h,m);
  for var i:=1 to n do
    otvet[i]:=h;
  for var j:=1 to m do
  begin
    readln(l,r,x);
    for var k:=l to r do
      if otvet[k]>x then
        otvet[k]:=x;
  end;
  for var i:=1 to n do
    sum:=sum+sqr(otvet[i]);
  writeln(sum);
END.

Var
    n, h, m, l, r, x, Ans: Int64;
    a: Array [1..50] of Int64;

Begin
    Read(n, h, m);
    For Var i := 1 to n do
        a[i] := h;
    For Var i := 1 to m do Begin
        Read(l, r, x);
        For Var j := l to r do
            If a[j] > x then
                a[j] := x
    End;
    For Var i := 1 to n do
        Ans += a[i]*a[i];
    Write(Ans)
End.

Program ILoveYou;
VAR n,h,m,i,s,j,x,y,max:int64; a:array[1..50] of int64;
Begin

Readln(n,h,m);
for i:=1 to n do
Begin
a[i]:=h;
end;

for i:=1 to m do
Begin
Readln(x,y,max);
for j:=x to y do
Begin
if (a[j] > max) then a[j]:=max;
end;
end;

s:=0;
for i:=1 to n do
Begin
//Writeln(a[i]);
s:=s + a[i]*a[i];
end;

Writeln(s);

Readln;
END.

var
  n,h,m:1..50;
  i,j,p:integer;
  l,r,x:1..50;
  dom:array[1..50] of integer;
begin
  read(n,h,m);
  for i:=1 to n do
    dom[i]:=h;
  for i:=1 to m do
    begin
      read(l,r,x);
      for j:=l to r do
        begin
          if dom[j]>x then
            dom[j]:=x;
        end;
    end;
  for i:=1 to n do
    p:=p+(dom[i]*dom[i]);
  write(p);
end.

uses
  Math;

var
  n, h, m, i, l, r, x, ans, j: longint;
  a: array[1..50] of longint;
begin
  read(n, h, m);
  for i := 1 to n do
    a[i] := h;
  for i := 1 to m do begin
    read(l, r, x);
    for j := l to r do
      a[j] := min(a[j], x);
  end;
  for i := 1 to n do
    ans := ans + a[i] * a[i];
  write(ans);
end.

                                 const eps=0.0000000001;  besk1=200000008;
                                 nnn=4600000;
            besk=80000000000000000;
              modul=1000000007{998244353};

   label 22,1,2,3,4,33;
    type    real=extended;   double=extended;
    mas=array [-300000..nnn] of int64;   point=record x,y,z:real;end;
    zap=record p1,p2,p3,p4 :int64;end; zap1=^zap;
    mass=array[-10000..nnn] of longint;mass1=^mass;
    matr=array[-10..200,-10..200] of int64;
    matr1=^matr;
    var sum,p01,hh,oldq,ll,rr,maskk,otmin,otmax,izb,kol,oldpp,t,pos1,pos2,r,razm,kollad,leftx,rightx,lefty,righty,num,dirx,diry,oldii,obr,koludal,maxdl,mindl,tmin,aaa,bbb,ccc,kolst,kollek,aa,bb,t1,t2,kolx,koly,ans,ans2,dl,posleft,posright,n,xxx,yyy,dx,dy,m,w,h,jjj,l,cc,mnog,nn,t3,t4,t5,t6,posmax,tmax,kold,kk,j2,ttt,ppp,pmin,pmax,limit,posi,posj,diam,oldt,ot1,time,pos,posx,posy,dloch,newdl,oldn,oldm,ost,ot,p1,p2,p3,p4,znamzz,kolperiod,znam,tperiod,start,finish,kol1,kol2,lavel,p0,jj,ii,ogr,q,p,pp,tt,oldtt,qq,qq1,qq2,q1,q2,imax,nm,smin,cen:int64;
   istart,jstart,ifinish,jfinish,k,i2,i3,step2,k1,k2,pp0,mask,i1,j1,step1, step, i,j:longint;
   maxprefix,maxsuffix,prefix,suffix,minprefix,minsuffix,zagr,xx,yy,kolizm,test,zz,predok,hesh,yold,x1,x0,d,b,a,zsum,y,x,z:array[-200000..1535002] of int64;
    otmat,amat,bmat,cmat:matr;
    zan1,zan2:array[-1000..200000,-2..26] of boolean;
    marked1,marked2:array[-2000..2000000] of boolean;
   gr1,gr2,gr:array[-1..2000,-1..2000] of boolean;
    dd,ddr:array[-1..1502,-1..1502] of int64;
    prob1,prob2,prob3,pr1new,pr2new,pr3new,pr1,pr2,pr3:zap;
    iii,oldpos,finot,vv,znak:int64;
    aold:mas;  anss:zap;
    sss,ss,ss1,ss2:string;
    newstr,str:array[-1000..200000] of string;
    lll,rrr,v,dist,alpha,phi:extended;
    masmatr:array[-1..101,-1..101,-1..101] of int64;
    zzz,ddnew,koef,polex,ddsum,ddl:array[-1..4,-1..1300000] of int64;
    str1,str2,dpos,ppos,mma,ma:array[-1000..200005,-1..30] of int64;
    xleft,xright,xplus,xminus,px,py,xc,yc,xxc,yyc:extended;
    del:array[-1..100001,-1..20] of longint;
    z0,y1,z1,z2,kolnul,fact,next,prev,s,name,dnew, voltay,c,day:mas;
    zzzz:array[0..125000000] of byte;
    aaaa,bbbb,x2:extended;
    delit:array[0..100000,0..20] of longint;
    pole:array[-10..2002,-10..2005] of char;
    ddd,matrr,ppole,dd3,dd4:array[-10..2000,-10..2200] of int64;
    ddnnew:array[-1..12,-1..12,0..200,0..3] of int64;
   newzan,marked,zanx,zany:array[-1000000..2000000] of boolean;
    ssold,sss1,sss2:string;
    def,stepen,koled,och,newoch,place,newnabor,stoim,nabor:array[-10..500005] of int64;
     zanleft,zanright,zan,fl:array[-100000..10000000] of boolean;
     dost:array[-1..210,-1..210,0..3,0..3] of int64;
    sss12:string;ch,ch1,ch2:char;
    pr,heshh,numright,dr: array [-10..2060,-1..1600] of int64;
    s3,s2,s1:array[-100..500000] of string;

    grr :array [-10..2010,-10..2010] of extended;
    maxpr:array[0..nnn] of string;
     tx,ty,vel,ott,v0,v1,s0,t0:int64;
     zv:point;
     left,right,ugol,rot,temp,sumtemp,vol,newx,newy:array[-1000..400000] of int64;
     mash,sqx,sqy,ottt:extended;
     xxxx,yyyy,yot:double;
       flag2,flag,flag1:boolean;

  function max(a,b:int64):int64;
begin max:=a; if b>a then max:=b;   end;

  function min(a,b:int64):int64;
begin min:=a; if b<a then min:=b;   end;

procedure udal(p:longint);
begin  next[prev[p]]:=next[p]; prev[next[p]]:=prev[p]; end;

      function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

     function summ(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p2+xx.p2*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=t1 div tt mod modul;
    t2:=t2 div tt mod modul;
    ott.p1:=t1; ott.p2:=t2;

   summ:=@ott;
 end;

     function prod(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=(t1 div tt) mod modul;
    t2:=(t2 div tt) mod modul;
    ott.p1:=t1; ott.p2:=t2;

   prod:=@ott;
 end;

    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p{/pi*180};
 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 shr 1); degg:=p*p mod modul;   end;

end;

function prost(tt:int64):boolean;
var aa:extended; i,p,t:longint;  fl:boolean;
 begin
   fl:=true;
   aa:=tt;
   aa:=sqrt(aa);
   t:=round(aa);
   for i:=2 to t do if tt mod i=0 then begin fl:=false; break; end;

   prost:=fl;
 end;

function arcsin(pp:extended):extended;
var tt:extended;
begin
   if (abs(pp)<=1+eps)and (abs(pp)>=1-eps)
   then if pp>0 then arcsin:=pi/2 else arcsin:=-pi/2;
   tt:=1-pp*pp;
   if abs(tt)>=0 then
     begin
        arcsin:=arctan(pp/sqrt(tt));

     end;

end;

function gl(ch:char):boolean;
begin
 if (ch='o')or (ch='a')or(ch='e')or(ch='u')or(ch='i') then gl:=true else gl:=false;

end;

function zaprmin(left,right:longint):int64;
begin
   if left>=right then zaprmin:=y[left] else
     begin
        if not odd(left) and odd(right) then zaprmin:=zaprmin(left shr 1,right shr 1) else
         begin
          if odd(left) then zaprmin:=min(zaprmin(left+1,right),y[left]);
          if not odd(right) then zaprmin:=min(zaprmin(left,right-1),y[right]);

         end;

     end;

end;

 function ff(gr:int64):boolean;

var ot,aa,bb,cc:int64; fl:boolean;
begin
  aa:=1; bb:=m;  cc:=aa; fl:=false;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if y[cc]<gr then aa:=cc else bb:=cc;

    end;
   writeln(' cc= ',cc);
   cc:=min(cc+3,m+1);
   repeat dec(cc) until y[cc]<=gr;
   if y[cc]=gr then fl:=true else fl:=false;
  ff:=fl;
end;

function dis(i,j:longint):longint;
begin
  dis:=min(abs(i-j),26-abs(i-j));

end;

function fg(kol,start:int64):int64;
var tt,t3,p:int64;
begin
  fg:=((2*start+kol-1)*kol) shr 1;

end;

begin
   { assign (input,'D:\Projects\input.txt');reset(input);
      assign (output,'D:\Projects\output.txt'); rewrite(output);
    }

  read(n,p,m);
   for i:=1 to m do read(a[i],b[i],c[i]);
   for i:=1 to n do x[i]:=p;
   for i:=1 to m do for j:=a[i] to b[i] do x[j]:=min(x[j],c[i]);
   for i:=1 to n do ot:=ot+x[i]*x[i];

   writeln(ot);

1:             close(output);
end.

program Project2;
{$APPTYPE CONSOLE}
uses
  SysUtils;
type tm=array [1..50] of integer;
var n,j,h,m,i,d,osh:Byte;
sum,mine:Integer;
left,right,visot:tm;
begin
Readln (n,h,m);
mine:=high(integer);
for i:=1 to m do
Readln(left[i],right[i],visot[i]);
for i:=1 to n do
begin
for j:=1 to m do
if (i<left[j]) or (i>right[j]) then Inc(d) else begin  Inc(osh); if visot[j]<mine then mine :=visot[j]; end;
if osh >0 then Inc(sum,mine*mine);
if d=m then Inc(sum,h*h);
osh:=0;
mine:=High(Integer);
d:=0;
end;
Writeln(sum);
readln;
end.

program ZP1;

{$APPTYPE CONSOLE}

    var x,y,z,s:array[1..50] of longint;
        i,j,n,h,m,k,kilk:longint;
begin
    readln(n,h,m);
    for i:=1 to m do
       readln(x[i],y[i],z[i]);
    for i:=1 to n do
       s[i]:=h;
    for i:=1 to m do
       begin
          for j:=x[i] to y[i] do
             if s[j]>z[i] then s[j]:=z[i]
       end;
    kilk:=0;
    for i:=1 to n do
       kilk:=kilk+s[i]*s[i];
    writeln(kilk)
end.

type tabel=array[1..50] of longint;
var t:tabel;
    a,b,n,m,p,r,k,i,j:longint;
    s:int64;
begin
read(n,r,m);
for i:=1 to n do t[i]:=r;
for i:=1 to m do begin
read(a,b,k);
for j:=a to b do
if t[j]>k then t[j]:=k else
if t[j]<k then t[j]:=k end;
for i:=1 to n do s:=s+sqr(t[i]);
write(s)
end.

var n,h,m,sum,x,y,z,i:integer;
    a:array[1..1000] of integer;

begin
        readln(n,h,m);
        for i:=1 to n do a[i]:=h;
        for i:=1 to m do
        begin
                readln(x,y,z);
                a[x]:=z;
                a[y]:=z;
        end;
        for i:=1 to n do
        begin
                sum:=sum+(a[i]*a[i]);
        end;
        write(sum);
end.

var n,h,m,sum,x,y,z,i,j:longint;
    a:array[1..1000] of longint;

begin
        readln(n,h,m);
        for i:=1 to n do a[i]:=h;
        for i:=1 to m do
        begin
                readln(x,y,z);
                for j:=x to y do a[j]:=z;
        end;
        for i:=1 to n do
        begin
                sum:=sum+(a[i]*a[i]);
        end;
        write(sum);
end.

var n,h,m,sum,x,y,z,i:longint;
    a:array[1..1000] of longint;

begin
        readln(n,h,m);
        for i:=1 to n do a[i]:=h;
        for i:=1 to m do
        begin
                readln(x,y,z);
                a[x]:=z;
                a[y]:=z;
        end;
        for i:=1 to n do
        begin
                sum:=sum+(a[i]*a[i]);
        end;
        write(sum);
end.

uses math;
var
  n,h,m,i,j,r,l,x,s:longint;
  a:array[1..10000] of longint;
begin
  readln(n,h,m);
  for i:=1 to 51 do a[i]:=h;
  for i:=1 to m do
   begin
    readln(l,r,x);
    for j:=1 to r do a[j]:=min(a[j],x);
   end;
  for i:=1 to n do s:=s+a[i]*a[i];
  write(s);
end.

var
  n,h,m:1..50;
  i,j,p:integer;
  l,r,x:1..50;
  dom:array[1..50] of integer;
begin
  read(n,h,m);
  for i:=1 to m do
    dom[i]:=h;
  for i:=1 to m do
    begin
      read(l,r,x);
      for j:=l to r do
        begin
          if dom[j]>x then
            dom[j]:=x;
        end;
    end;
  for i:=1 to n do
    p:=p+(dom[i]*dom[i]);
  write(p);
end.

var
  n,h,m:1..50;
  i,j,p:integer;
  l,r,x:1..50;
  dom:array[1..50] of integer;
begin
  read(n,h,m);
  for i:=1 to m do
    dom[i]:=h;
  for i:=1 to m do
    begin
      read(l,r,x);
      for j:=l to r do
        dom[j]:=x;
    end;
  for i:=1 to n do
    p:=p+(dom[i]*dom[i]);
  write(p);
end.

var
  n,h,m,i,j,p,l,r,x:integer;
  dom:array[1..50] of integer;
begin
  read(n,h,m);
  for i:=1 to m do
    dom[i]:=h;
  for i:=1 to m do
    begin
      read(l,r,x);
      for j:=l to r do
        dom[j]:=x;
    end;
  for i:=1 to n do
    p:=p+(dom[i]*dom[i]);
  write(p);
end.

uses
  Math;

var
  n, h, m, i, l, r, x, ans, j: longint;
  a: array[1..50] of longint;
begin
  read(n, h, m);
  for i := 1 to m do
    a[i] := h;
  for i := 1 to m do begin
    read(l, r, x);
    for j := l to r do
      a[j] := min(a[j], x);
  end;
  for i := 1 to m do
    ans := ans + a[i] * a[i];
  write(ans);
end.

program ZP1;

{$APPTYPE CONSOLE}

    var x,y,z,s:array[1..50] of longint;
        i,j,n,h,m,k,kilk,max:longint;
begin
    readln(n,h,m);
    for i:=1 to m do
       readln(x[i],y[i],z[i]);
    for i:=1 to n do
       s[i]:=h;
    for i:=1 to m do
       begin
          for j:=x[i] to y[i] do
             s[j]:=z[i]
       end;
    kilk:=0;
    for i:=1 to n do
       kilk:=kilk+sqr(s[i]);
    writeln(kilk)
end.