importstd.stdio;importstd.math:realabs=abs;importstd.complex;importstd.conv:to;autogenerateSpiral(numType)(numTypex){autoz=Complex!numType(0);autoi=Complex!numType(0,1);autodirection=Complex!numType(1);numTypestepsTillTurn=1,stepsTaken=0;boolmaxedOnce=false;autoresult=[z];for(numTypesteps=1;steps<x;steps++){z+=direction;stepsTaken++;result~=z;if(stepsTaken==stepsTillTurn){// Time to turndirection*=i;stepsTaken=0;if(maxedOnce){stepsTillTurn++;maxedOnce=false;}else{maxedOnce=true;}}}returnresult;}autotallySpiral(numType)(Complex!numType[]spiral){autotally=[numType(1)];for(autoi=1;i<spiral.length;i++){numTypesum=0;autoz=spiral[i];for(autoj=0;j<i;j++){autow=spiral[j];if(abs(w-z)<2){sum+=tally[j];}}tally~=sum;}returntally;}voidmain(string[]args){autotarget=to!double(args[1]);autospiral=generateSpiral(target);autoend=spiral[$-1];writeln(realabs(end.re)+realabs(end.im));autotally=tallySpiral(spiral);writeln(tally);}