from time import * m=mktime while 1: d=strptime(raw_input(),'%m %Y');print strftime('%B %Y',d).center(20)+'\nSu Mo Tu We Th Fr Sa' for i in range(6):print' '.join((-~d[6]%7*[' ']+['%2i'%j for j in range(1,32-(d[1]==2)-(d[1]in(2,9,4,6,11)))])[i*7:][:7])
Note that non-ascii characters in the above source code will be escaped (such as \x9f).