#/*        */include<stdio.h>
                    /*    */int/**/main(int/**/o,char**O){int      y[4],
                  r[4]   ,z[4],C,h,i,n,a,t,s,u[2][3][4]={{{6,9,0,3}     ,
                {     1,10,4,7},{5,11,2,8}},{{3,0,6,9},{10,1,4,7},{     8,2,5
          ,11}}},    M,I,R,A,K,U[2],RU[2],N[2],_=2;FILE*x[03]      ;  unsigned/*,
       */char/**/ p[2][3<<16],d[12],b[256][256];float/**/f,q        [12];if((o<4)){
      return!puts("<a.ppm>\40<b.ppm>\40<output.ppm>\40[odd]")    ;}else{for(h=0;h<2;
    h++){M=SEEK_SET;if(!(x[h]=fopen(O[h+1],"rb")))goto/**/e;if( (int)fread(*b,1,256,x[h
    ])<1||sscanf((char*)*b,*O="P6\n%d\40%d\n%d\n",&U[h],&N[h],&i)-3||i-255)goto/**/e;for(
   i=C=RU[h]=0;i<256&&!RU[h];i++)if(b[0][i]=='\n')if(++C==3)fseek(x[h],RU[h]=i+1,M);if(!RU
  [h]||U[h]<1||U[h]>(1<<16))goto/**/e;}if(*U-U[1]||*N-N[1])goto/**/s;for(h=0;h<256;h++)for(
  i=0;i<256;b[h][i++]=0) ;for(i=0;i<*N;i++){for(h=0;h<2;h++)if(fread(p[h],3**U,01,x[h])!=1)
 goto/**/e;for(h=0;h<3**  U;h++)b[p[0][h]][p[1][h]]=1; }*y=*r=y[2]=r[2]=64;y[1]=r[1]=y[3]=r[
 3]=192;A=(y[1]-*y)*(y[   3]-y[2]);for(M=64;M>0; M/=2) {for(t=-1;t<=0;t++)if((*z=*r+t*M)>-1)
 for(I=-1;I<1;I++)if((z    [ 2]=r[2]+I*M)> (-1))  for   (s=1;s>-1;s--)if((z[1]=r[1]+s*M)<257
 )for(R=1;R>-1;R--)if(     +  257>(z[3]=r  [3]+R*  M)   )if((K=(z[1]-z[0])*(z[3]-z[2]))>A){
for(h=C=0;h<256&&C> -1           &&C<256;   h  ++)for      (n=h*(z[1]-z[i=0])/256+*z;C>-1&&
i<256&&C<256;i++){a =  i*(z[3]-z              [2    ])/256+ z[2];if(b[h][i])C=(3*n-a)/2;}if
 (C>-1&&C<256)for(C  =0     ,   A=           K  ;C   <4;++   C)y[C]=z[C];}for(C=0;C<4;C++)r
 [C]=y[C];}if(!(x[2     ]   =/*                 */   fopen   (O[03],"wb+")))goto/**/e;else{
 fprintf(x[2],*O,2*    *U,2**N,+               255);for(h=   0;h<(2);h++)fseek(x[h],RU[h],
 SEEK_SET);C=(o<5)?    1/***/:00               ;/***/R=1+(  1<<16);for(i=0;i<*N;i++){for(h
 =0;h<2;h++)if(fread   (/****/p[               h/****/],+3  **U,1,x[h])!=1)goto/**/e;for(
  M=0;M<7;M+=6)for(h    =/**/0;*                U/**/>h;h  ++){for(n=0;n<3;n++){for(a=0;
   a<2;a++)q[u[C][n]     [a]]=p                  [a][h    *3+n]*(r[a*2+1]-r[a*2])/256.f
   +r[a*2];q[u[C][n]                                     [2]]=q[u[C][n][3]]=(3*q[*u[C][
    n]]-q[u[C][n][1]]                                    )/2;}for(n=0;n<12;d[n++]=t<0?
    0:(t>255?255:t)){               t       =          q[n];f=q[n]-t;_=(_*75)%R;if(_<f
     *R)++ t;}fwrite(d               +M,6,1,            x[2]);}}}}for(h=0;h<3;h =h + 1
     )  t=   fclose(x [h                               ]);     return  (t*1);s  :
         *O    ="si"    /*                           */       "ze ";   printf  (
           *     /*'      P*/                     O);        ;e  :    return
                  !          /*w*/            puts                      /*;
                                  */("error");                            }