def L(a,b,c,m):\x0d for i in range(m):x=" _"[b]*n;print((" |"[a]+x+"|"+x+" |"[c]).rstrip())\x0d while 1:\x0d n=int(input())\x0d for i in range(8):L(1<i<4,i%2 and i<7,3<i<6,[n-1,1][i%2])\x0d
Note that non-ascii characters in the above source code will be escaped (such as \x9f).