#coding=utf-8
from __future__ import print_function

#利用泰勒公式计算星期几
#w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1 
def getweek(year,month,day):
    #w        #星期
    #c        #世纪-1 YYYY的头两位
    #y        #年份   YYYY的后两位
    #m        #月份 >=3 1月 2月看成上年的13月 14月
    #d=day    #日
    if month>=3: 
        c=year / 100
        y=year % 100
        m=month
    else:
        m=month+12
        y=(year-1) % 100
        c=(year-1) / 100
    w=y+y/4+c/4-2*c+(26*(m+1))/10+day-1
    w=(w+700) %7
    return w


def get_days(year,mmonth):
  rui=[31,29,31,30,31,30,31,31,30,31,30,31]
  ping=[31,28,31,30,31,30,31,31,30,31,30,31]
  ruiflag=0
  if year%4==0 and year%100!=0 or year%400==0:
    ruiflag=1
  if ruiflag==1:
    return rui[mmonth-1]
  return ping[mmonth-1]



#print("come in main:")
month=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"]
title=["SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"]
year=raw_input("please input year:")     
for i in range(1,13):
  print("%6s"%month[i-1])
  for j in range(1,8): 
    print("%10s"%title[j-1],end=' ')
  print(" ")
  flag=0
  days=get_days(int(year),i)
  for k in range(1,days+1):
    if(k==1): 
      week=5*getweek(int(year),i,k)+1
      for j in range(1,week):
        print(' ',end=' ')
      flag=getweek(int(year),i,k)
    print("%9d"%k,end=' ')
    if k<7:
      if flag+k==7: 
        print(" ")
    else :
      if (k+flag)%7==0:
        print(" ")
  print("\n   ==========================================================================\n")