def P(x,y,s,c,dx,dy): for i in range(s): f[y][x]=c x+=dx;y+=dy while 1: n=input() f = [[" "] * (4*n+1) for i in range((2*n+1))] P(n,0,2*n,"_",1,0); P(n-1,1,n,"/",-1,1); P(1,n,2*n-1,"_",1,0); P(2*n,n,n,"/",1,-1); P(0,n+1,n,"\\",1,1); P(n,2*n,2*n-1,"_",1,0); P(2*n,n+1,n,"\\",1,1); P(3*n,2*n,n,"/",1,-1); P(4*n-1,n,n,"\\",-1,-1) for x in f: print"".join(x).rstrip()

Note that non-ascii characters in the above source code will be escaped (such as \x9f).