settings.outformat = "pdf";
settings.prc = false;

//usepackage("amsmath,amssymb"); usepackage("inputenc","utf8"); // code
//figure import graph; //unitsize(1cm,1cm);
import graph;
//settings.render=16;
size(6cm,6cm);


path c=arc((0,0),r=1,angle1=0,angle2=180);
path d=shift((1,0))*c;
path[] pth;
path vertline=(-1/2,0)--(-1/2,2);
for (int i=-1;i<2;++i)
{
	draw(shift((i,0))*vertline);

}

pth.push(arc((-2,0),r=1,angle1=0,angle2=90));
for (int i=-1;i<1;++i)
{
	pth.push(shift((i,0))*c);

}
pth.push(arc((1,0),r=1,angle1=90,angle2=180));
for (int j=0;j<pth.length;++j)
{
	draw(pth[j]);

}


for (int i=-2;i<2;++i)
{

if (i<1) 
{

path[] rcirc;
rcirc.push(arc((i+1/3,0),r=1/3,angle1=0,angle2=180));
for (int k=1;k<5;++k)
{
	
	rcirc.push(arc((i+(1/3)*(2/3)^k,0),r=(1/3)*(2/3)^k,angle1=0,angle2=180));
}
for (int j=0;j<rcirc.length;++j)
{
	draw(rcirc[j]);

}

}

if (i>-2) 
{

path[] lcirc;
lcirc.push(arc((i-1/3,0),r=1/3,angle1=0,angle2=180));
for (int k=1;k<5;++k)
{
	lcirc.push(arc((i-(1/3)*(2/3)^k,0),r=(1/3)*(2/3)^k,angle1=0,angle2=180));
}
for (int j=0;j<lcirc.length;++j)
{
	draw(lcirc[j]);

}

}
}
//draw(arc((1/3,0),r=1/3,angle1=0,angle2=180));

pair[] pt;
pt.push((-2,1));

for (int i=-2;i<1;++i)
{
pt.append(intersectionpoints(shift((i+1,0))*c,shift((i,0))*c));

pt.append(intersectionpoints(arc((i+1/3,0),r=1/3,angle1=0,angle2=180),arc((i+1-1/3,0),r=1/3,angle1=0,angle2=180)));
pt.append(intersectionpoints(arc((i+1/3,0),r=1/3,angle1=0,angle2=180),arc((i+1-(1/3)*(2/3),0),r=(1/3)*(2/3),angle1=0,angle2=180)));

pt.append(intersectionpoints(arc((i+(1/3)*(2/3),0),r=2/9,angle1=0,angle2=180),arc((i+1-1/3,0),r=1/3,angle1=0,angle2=180)));

}



pt.push((1,1));
for (int i=1;i<pt.length-1;++i)
{
dot(pt[i],blue);
}


draw(arc((-2,0),pt[0],pt[1],direction=CW),red);

draw(pt[1]--pt[2],red);
draw(pt[2]--(pt[1]+pt[2])/2,green+linewidth(1),arrow=Arrow(TeXHead));

draw(arc((-1-1/3,0),pt[2],pt[4],direction=CCW),red);
draw(subpath(arc((-1-1/3,0),pt[4],pt[2],direction=CW),0,1/2),green+linewidth(1),arrow=Arrow(TeXHead));

draw(arc((-2+1/3,0),pt[2],pt[3],direction=CW),red);
draw(subpath(arc((-2+1/3,0),pt[3],pt[2],direction=CCW),0,1/2),green+linewidth(1),arrow=Arrow(TeXHead));

draw(arc((-1,0),pt[1],pt[5],direction=CW),red);
draw(subpath(arc((-1,0),pt[1],pt[5],direction=CW),0,1),green+linewidth(1),arrow=Arrow(TeXHead));

draw(pt[5]--pt[6],red);
draw(subpath(pt[6]--pt[5],0,1/2),green+linewidth(1),arrow=Arrow(TeXHead));

draw(arc((-1/3,0),pt[6],pt[8],direction=CCW),red);
draw(subpath(arc((-1/3,0),pt[8],pt[6],direction=CW),0,1/2),green+linewidth(1),arrow=Arrow(TeXHead));

draw(arc((-1+1/3,0),pt[6],pt[7],direction=CW),red);
draw(subpath(arc((-1+1/3,0),pt[7],pt[6],direction=CCW),0,1/2),green+linewidth(1),arrow=Arrow(TeXHead));

draw(arc((0,0),pt[5],pt[9],direction=CW),red);
draw(subpath(arc((0,0),pt[9],pt[5],direction=CCW),0,1),green+linewidth(1),arrow=Arrow(TeXHead));

draw(pt[9]--pt[10],red);
draw(subpath(pt[10]--pt[9],0,1/2),green+linewidth(1),arrow=Arrow(TeXHead));


draw(arc((1-1/3,0),pt[10],pt[12],direction=CCW),red);
draw(subpath(arc((1-1/3,0),pt[12],pt[10],direction=CW),0,1/2),green+linewidth(1),arrow=Arrow(TeXHead));

draw(arc((1/3,0),pt[10],pt[11],direction=CW),red);
draw(subpath(arc((1/3,0),pt[11],pt[10],direction=CCW),0,1/2),green+linewidth(1),arrow=Arrow(TeXHead));



draw(arc((1,0),pt[9],(1,1),direction=CW),red);
