A triangle field is numbered with successive integers in the way shown on the picture below.

The traveller needs to go from the cell with number M to the cell with number N. The traveller is able to enter the cell through cell edges only, he can not travel from cell to cell through vertices. The number of edges the traveller passes makes the length of the traveller's route.
Write the program to determine the length of the shortest route connecting cells with numbers N and M.
#include <stdio.h>
#include<math.h>
int main()


{
int temp,n,m,s,flag=3,cn,cm,zb,yb,cc,k,sj;
while(scanf("%d%d",&m,&n)==2 )

{
flag=3; s=0; k=0;
if(m>n)

{
temp=m; m=n; n=temp;
}
cn=(int)ceil(sqrt(n)); //鍒ゆ柇n鍜宮鎵鍦ㄥ眰鏁?/span>
cm=(int)ceil(sqrt(m));
cc=abs(cn-cm); //鍒ゆ柇涓ょ偣灞傚樊
zb=m+(cn-1)*(cn-1)-(cm-1)*(cm-1); //鍒ゆ柇m杈愬皠鍒皀灞傛墍鍙婅寖鍥寸殑宸﹁竟鐣屽拰鍙寵竟鐣?/span>
yb=zb+2*cc;
if(n>=zb && n <=yb) //鍒ゆ柇n鍦╩鑼冨洿鎵欏繪鏁?/span>

{
s=2*(cc);
k=1;
}
else

{
if(n<zb) //鍒ゆ柇n鍒癿杈圭晫鍙妋鐐規墍欏繪鏁板拰
s=2*(cc)+abs(n-zb);
else
s=2*(cc)+abs(n-yb);
}
sj=m-(cm-1)*(cm-1); //鍒ゆ柇涓夎綾誨瀷0姝?1鍊?/span>
if(abs(n-m)% 2 !=(cc) % 2)

{
if(sj % 2 ==1 )
flag=1;
else
flag=0;
}
if(flag==1 && k==1)
s=s-1; //鍋囧n鐐瑰湪m鐐硅緪灝勮寖鍥村唴,姝d笁瑙?1,鍊掍笁瑙?1,涓嶅湪涓嶅垽鏂?
if(flag==0 && k==1)
s=s+1;
printf("%d\n",s);
}
return 0;
}
cn-1)*(cn-1)鏄?鍒皀-1琛屾湯灝劇殑鏁幫紝涔熷氨鏄?-n鐨勯噷闈㈠皬涓夎褰㈢殑涓暟~錛?br>(cm-1)*(cm-1);涔熸槸涓鏍風殑鍢泘
涓や釜鐩稿噺灝辨槸m琛岀殑涓暟浜嗭紒~ m鍔犱釜鏁頒笉灝辨槸宸﹁竟鐣屼簡鍢泘
zb+涓ゅ嶇殑琛屽樊灝辨槸鍙寵竟鐣屼簡錛亊
鑰屼笖姝d笁瑙掓墍鍒扮殑杈圭晫鏄涓夎鍨嬶紝鍙嶄笁瑙掓墍鍒扮殑杈圭晫鏄弽涓夎鍨嬶紝榪欑偣瑕佹敞鎰忥紒
