Problem:
What day is today? Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29. Input The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset consists of two integers m and d separated by a single space in a line. These integers respectively represent the month and the day. The number of datasets is less than or equal to 50. Output For each dataset, print the day (please see the following words) in a line. Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday Sample Input 1 1
2 29
0 0 Output for the Sample Input Thursday
Sunday

Solution (Python):
M=[ 31, 29, 31, 30, 31,30,31,31,30,31,30,31]
DAY=["Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"]


m=2
d=29

	

while True:
	m,d=map( int , raw_input().split() )
	if m==d==0:
		quit()
	else:
		x=0
		for i in range(m-1):
			x+=M[i]
		x+=d
		print DAY[x%7]

Solution (Python):
from datetime import date
dic={3:"Thursday",4:"Friday",5:"Saturday",6:"Sunday",0:"Monday",1:"Tuesday",2:"Wednesday"}
while True:
    m,d=map(int,input().split())
    if m==0 and d==0:
        break
    print(dic[date(2004,m,d).weekday()])

Solution (Python):
import sys
from datetime import *

for line in sys.stdin:
    a, b = map(int,line.split())
    try:
        print(date(2004, a, b).strftime("%A"))
    except ValueError:
        break

Solution (Python):


import datetime

days = [
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday',
    'Sunday'
        ]

while True:
    m, d = map(int, input().split(' '))
    if m == 0: break
    print(days[datetime.date(2004, m, d).weekday()])

Solution (Python):
import datetime

weekdays = [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
]

while True:
  m, d = map(int, raw_input().strip().split(" "))
  if m == 0:
    break
  print weekdays[datetime.date(2004, m, d).weekday()]

Solution (Python):
from datetime import date

week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

while True:
  line = map(int, raw_input().split())
  if line[0] == 0: break
  print week[date(2004,line[0],line[1]).weekday()]

Solution (Python):
days=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
dom=[31,29,31,30,31,30,31,31,30,31,30,31]
while True:
    try:
        try:
            (m,d)=map(int,raw_input().split())
        except: break
        if m==0 and d==0: break
        day=4-1
        for i in xrange(m-1):
            day+=dom[i]
        day+=d
        print days[day%7]
    except EOFError: break

Solution (Python):
days=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
import calendar
while True:
    try:
        try:
            (m,d)=map(int,raw_input().split())
        except: break
        if m==0 and d==0: break
        print days[calendar.weekday(2004,m,d)]
    except EOFError: break

Solution (Python):



import sys
from datetime import date

def print_week(n):
  n_to_week = {0:"Monday",1:"Tuesday",2:"Wednesday",3:"Thursday",4:"Friday",5:"Saturday",6:"Sunday"}
  print n_to_week[n]

for s in sys.stdin:
  d = map(int,s.split())
  if d == [0,0]:
    exit()
  print_week(date(2004,d[0],d[1]).weekday())

Solution (Python):
import datetime
import sys

week = {0:'Monday', 1:'Tuesday', 2:'Wednesday', 3:'Thursday', 4:'Friday', 5:'Saturday', 6:'Sunday'}

f = sys.stdin
while True:
    month, date = map(int, f.readline().split())
    if month == 0:
        break
    day = datetime.date(2004, month, date)
    print(week[day.weekday()])

Solution (Python):
from datetime import date
while True:
    m,d = map(int,raw_input().split(" "))
    
    if m ==0:
        break
        
    w = date(2004,m,d).isoweekday()

    if w==1:
        print 'Monday'
    elif w==2:
        print 'Tuesday'
    elif w==3:
        print 'Wednesday'
    elif w==4:
        print 'Thursday'
    elif w==5:
        print 'Friday'
    elif w==6:
        print 'Saturday'
    elif w==7:
        print 'Sunday'

Solution (Python):
import datetime

week=["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
while True:
    a,b=map(int, input().split())
    if a == b == 0:
        break
    print(week[datetime.date(2004, a, b).weekday()])

Solution (Python):
days_sum={1:31,2:29,3:31,4:30,5:31,6:30,7:31,8:31,9:30,
          10:31,11:30,12:31}
days2month={1:'Thursday',2:'Friday',3:'Saturday',4:'Sunday',
            5:'Monday',6:'Tuesday',0:'Wednesday'}

while True:
    month,day=map(int,raw_input().split(" "))
    if month==0 and day==0:
        break
    keika=0
    for i in range(1,month):
        keika += days_sum[i]
    keika+=day
    print days2month[keika%7]

Solution (Python):
import datetime

try:
	while 1:
		s = raw_input().split()
		s[0] = int(s[0])
		s[1] = int(s[1])
		
		if s[0] + s[1] == 0:
			exit()
		
		n = datetime.date(2004, s[0], s[1]).weekday()
		
		if n == 0:
			print("Monday")
		elif n == 1:
			print("Tuesday")
		elif n == 2:
			print("Wednesday")
		elif n == 3:
			print("Thursday")
		elif n == 4:
			print("Friday")
		elif n == 5:
			print("Saturday")
		elif n == 6:
			print("Sunday")
except:
	pass

Solution (Python):
from datetime import date
while 1:
	m,d=map(int,raw_input().split())
	if m==0:break
	print date(2004,m,d).strftime("%A")

Solution (Python):
from datetime import date
while 1:
	m,d=map(int,raw_input().split())
	if m==0:break
	print date(2004,m,d).strftime("%A")

Solution (Python):
def create(month, days):
    day = 1
    while week:
        calendar[(month, day)] = week[0]
        week.append(week[0])
        del week[0]
        if day == days: break
        day += 1
        
week = ['Thursday','Friday','Saturday','Sunday','Monday','Tuesday','Wednesday']
calendar = {}
for i in range(12):
    month = i+1
    if month in (1,3,5,7,8,10,12):
        create(month, 31)
    elif month == 2:
        create(month, 29)
    else:
        create(month, 30)
    
while True:
        month, day = map(int, raw_input().split())
        if month == 0 and day == 0: break
        print calendar[(month, day)]

Solution (Python):

import sys
import math

dayy = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def days(a, day):
    if a == 0:
        return day
    else:
        return days(a-1, day + dayy[a])


while 1:
    inp = raw_input().split()
    ii = int(inp[0])
    jj = int(inp[1])
    if ii == 0 and jj== 0:
        break
    ans = days(ii-1, 0) + jj
    ans = ans % 7
    if ans == 1:
        print "Thursday"
        continue
    if ans == 2:
        print "Friday"
        continue
    if ans == 3:
        print "Saturday"
        continue
    if ans == 4:
        print "Sunday"
        continue
    if ans == 5:
        print "Monday"
        continue
    if ans == 6:
        print "Tuesday"
        continue
    if ans == 0:
        print "Wednesday"
        continue

Solution (Python):
def create(month, days):
    day = 1
    while day <= days:
        calendar[(month, day)] = week[0]
        week.append(week[0])
        del week[0]
        day += 1
        
week = ['Thursday','Friday','Saturday','Sunday','Monday','Tuesday','Wednesday']
calendar = {}
for i in range(12):
    month = i+1
    if month in (1,3,5,7,8,10,12):
        create(month, 31)
    elif month == 2:
        create(month, 29)
    else:
        create(month, 30)
    
while True:
        month, day = map(int, raw_input().split())
        if month == 0 and day == 0: break
        print calendar[(month, day)]

Solution (Python):
def create(month, days):
    day = 1
    while day <= days:
        calendar[(month, day)] = week[0]
        week.append(week[0])
        del week[0]
        day += 1
        
week = ['Thursday','Friday','Saturday','Sunday','Monday','Tuesday','Wednesday']
calendar = {}
for i in range(12):
    month = i+1
    if month == 2:
        create(month, 29)
    elif month in (4,6,9,11):
        create(month, 30)
    else:
        create(month, 31)
    
while True:
        month, day = map(int, raw_input().split())
        if month == 0 and day == 0: break
        print calendar[(month, day)]

Solution (Python):
def create(month, days):
    for i in range(days):
        day = i+1
        calendar[(month, day)] = week[0]
        week.append(week[0])
        del week[0]
        
week = ['Thursday','Friday','Saturday','Sunday','Monday','Tuesday','Wednesday']
calendar = {}
for i in range(12):
    month = i+1
    if month == 2:
        create(month, 29)
    elif month in (4,6,9,11):
        create(month, 30)
    else:
        create(month, 31)
    
while True:
        month, day = map(int, raw_input().split())
        if month == 0 and day == 0: break
        print calendar[(month, day)]

Solution (Python):
import sys

day = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
num = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

for s in sys.stdin:
    M, D = map(int, s.strip().split())
    if M == 0:
        break
    totalDay = D
    M -= 1

    while M > 0:
        totalDay += num[M-1]
        M -= 1

    print(day[(totalDay+2)%7])

Solution (Python):
ans=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
c=[31,29,31,30,31,30,31,31,30,31,30,31]
while 1:
    a,b=map(int,raw_input().split())
    if a==0:
        break
    t=3
    for i in range(a-1):
        t+=c[i]
    t+=b
    print ans[(t-1)%7]

Solution (Python):


def main():
    LIST=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]

    while True:
        try:
            count=3
            M,D=map(int,input().split())
            if M==0:
                break

            if M in [1,4,7]:
                pass
            elif M in [10]:
                count+=1
            elif M in [5]:
                count+=2
            elif M in [2,8]:
                count+=3
            elif M in [3,11]:
                count+=4
            elif M in [6]:
                count+=5
            elif M in [9,12]:
                count+=6

            count+=D%7

            print(LIST[count%7])

        except:
            break

if __name__ == '__main__':
    main()

Solution (Python):
from math import *
PI = 3.1415926535898
res = [0,31,29,31,30,31,30,31,31,30,31,30,31]
wk = ["Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"]
pas = [0]
for i in range(1, len(res)):
	pas.append(pas[i-1] + res[i])
while True:
	try:
		m, d = map(int, raw_input().strip().split(' '))
		if m == 0 and d == 0:
			break
		print wk[(pas[m-1]+d)%7]
	except EOFError:
		break

Solution (Python):
from datetime import date
import sys
for line in sys.stdin.readlines():
   m , d = map(int,line.split())
   if m != 0 and d != 0 :
       val = date(2004,m,d)
       day = val.isoweekday()
       if day == 7:
           print("Sunday")
       elif day == 1:
           print("Monday")
       elif day == 2:
           print("Tuesday")
       elif day == 3:
           print("Wednesday")
       elif day == 4:
           print("Thursday")
       elif day == 5:
           print("Friday")
       else:
           print("Saturday")
   else:
       break

Solution (Python):
def day(x,y):
	start=0
	if x==2 or x==8 :
		start=0
	elif x==3 or x==11:
		start=1
	elif x==6:
		start=2
	elif x==9 or x==12:
		start=3
	elif x==1 or x==4 or x==7:
		start=4
	elif x==10:
		start=5
	elif x==5:
		start=6 



	day=(start+y)%7
	if day==1:
		return "Sunday"
	elif day==2:
		return "Monday"
	elif day==3:
		return "Tuesday"
	elif day==4:
		return "Wednesday"
	elif day==5:
		return "Thursday"
	elif day==6:
		return "Friday"
	else:
		return "Saturday"


while True:	
	x,y=map(int,input().split())
	if x==y==0:
		break
	print(day(x,y))

Solution (Python):
month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30]
day = ['Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday']
while True:
    m, d = map(int, input().split())
    if m == 0:
        break
    print(day[(sum(month[:m - 1]) + d) % 7])

Solution (Python):

import datetime

def tako():
	while True:
		month, day = map(int, raw_input().split())
		if month == day == 0:
			break

		date1 = datetime.date(2004,month,day)
		tag = date1.weekday()
		print syori(tag + 1)

def syori(m):
	if m == 1:
		return "Monday"
	elif m == 2:
		return "Tuesday"
	elif m == 3:
		return "Wednesday"
	elif m == 4:
		return "Thursday"
	elif m == 5:
		return "Friday"
	elif m == 6:
		return "Saturday"
	elif m == 7:
		return "Sunday"

if __name__ == "__main__":
	tako()

Solution (Python):
DAY_OF_WEEK = ['Sunday', 'Monday', 'Tuesday',
               'Wednesday', 'Thursday', 'Friday', 'Saturday']
def day_of_week(y, m, d):
    
    
    
    if m == 1 or m == 2:
        m += 12
        y -= 1
    h = (y + y // 4 - y // 100 + y // 400 + (13 * m + 8) // 5 + d) % 7
    return h

while True:
    m,d = map(int, input().split())
    if m==0:
        exit()
    print(DAY_OF_WEEK[day_of_week(2004,m,d)])

Solution (Python):
from datetime import date
while 1:
	input_data = map(int,raw_input().split())
	day = 0
	if input_data[0] == 0:
		break
	day = date(2004,int(input_data[0]),int(input_data[1])).weekday()
	if day == 6:
		print("Sunday")
	elif day == 0:
		print("Monday")
	elif day == 1:
		print("Tuesday")
	elif day == 2:
		print("Wednesday")
	elif day == 3:
		print("Thursday")
	elif day == 4:
		print("Friday")
	elif day == 5:
		print("Saturday")

Solution (Python):


import sys

days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
while True:
    ans = 3
    m, d = map(int, raw_input().split())
    if m == 0:
        break
    for i in range(1, m):
        if i == 2:
            ans = (ans+1)%7
        elif i == 4 or i == 6 or i == 9 or i == 11:
            ans = (ans+2)%7
        else:
            ans = (ans+3)%7
    ans = (ans+d)%7
    print days[ans]

Solution (Python):
while True:
    m, d = map(int, input().split())
    if m == d == 0:
        break
    dim = {1: 0, 2: 31, 3: 60, 4: 91, 5: 121, 6: 152, 7: 182, 8: 213, 9: 244, 10: 274, 11: 305, 12: 335}
    ds = dim[m] + d -1
    print({0:'Thursday', 1:'Friday', 2:'Saturday', 3:'Sunday', 4:'Monday', 5:'Tuesday', 6:'Wednesday'}[ds % 7])

Solution (Python):
daymonth = [0, 2, 5, 6, 2, 4, 0, 2, 5, 1, 3, 6, 1]
str = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]




m = 1
d = 1

while m!=0:
	md = input().split(" ")
	m = int(md[0])
	d = int(md[1])
	if m != 0:
		print(str[(daymonth[m] + d) % 7])

Solution (Python):
from datetime import date
while 1:
    m, d = map(int, raw_input().split())
    if m == d == 0: break
    ans = date(2004,m,d).weekday()
    ansday = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
    for i in range(7):
        if ans == i: print ansday[i]

Solution (Python):
from datetime import date
while True:
    m,d = map(int, input().split())
    if m == 0 or d == 0:
        break
    wDay = date(2004, m, d).weekday()
    if wDay == 0:
        print("Monday")
    elif wDay == 1:
        print("Tuesday")
    elif wDay == 2:
        print("Wednesday")
    elif wDay == 3:
        print("Thursday")
    elif wDay == 4:
        print("Friday")
    elif wDay == 5:
        print("Saturday")
    elif wDay == 6:
        print("Sunday")

Solution (Python):
from datetime import date

day = (
       'Monday',
       'Tuesday',
       'Wednesday',
       'Thursday',
       'Friday',
       'Saturday',
       'Sunday',
       'Sunday',)
while 1:
    m, d = list(map(int, input().split()))
    if m == 0:
        break
    print(day[date(2004, m, d).weekday()])

Solution (Python):

day = (
       'Sunday',
       'Monday',
       'Tuesday',
       'Wednesday',
       'Thursday',
       'Friday',
       'Saturday',
)
mm = {1:4,
      2:0,
      3:1,
      4:4,
      5:6,
      6:2,
      7:4,
      8:0,
      9:3,
      10:5,
      11:1,
      12:3,
      }
while 1:
    m, d = list(map(int, input().split()))
    if m == 0:
        break
    print(day[(mm[m] + d - 1)%7])

Solution (Python):

import datetime


def main(a, b):
    dt = datetime.datetime(2004, a, b)
    week_num = dt.weekday()

    if week_num == 0:
        print('Monday')
    elif week_num == 1:
        print('Tuesday')
    elif week_num == 2:
        print('Wednesday')
    elif week_num == 3:
        print('Thursday')
    elif week_num == 4:
        print('Friday')
    elif week_num == 5:
        print('Saturday')
    elif week_num == 6:
        print('Sunday')


while True:
    a, b = [int(e) for e in input().split()]
    if a == 0 and b == 0:
        break

    main(a, b)

Solution (Python):
mday = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
youbi = ["Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"]

while True:
	month, day = map(int, input().split())
	if month == day == 0: break

	days = 0
	for m in range(12):
		if month-1 <= m: break
		days += mday[m]
	days += day

	print(youbi[days % 7])

Solution (Python):
from datetime import date

weeks = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

while True:

  s = map(int, raw_input().split())

  if s[0] == 0:
    break

  print weeks[date(2004, s[0], s[1]).weekday()]

Solution (Python):
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
nums = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
while True:
    try:
        m, d = map(int, input().split())
        if not m:
            break
    except:
        break
    print(days[(sum(nums[:m - 1]) + d + 2) % 7])

Solution (Python):
c = []
m = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
w = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
s = 3
for d in m:
    c.append([(s + i) % 7 for i in xrange(d)])
    s = c[-1][-1] + 1
while 1:
    mon, day = map(int, raw_input().split())
    if mon == 0: break
    print w[c[mon - 1][day - 1]]

Solution (Python):
import sys
import datetime

w = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
while True:
    m, d = map(int, raw_input().split())
    if m == 0 and d == 0:
        break
    print w[datetime.date(2004,m,d).weekday()]

Solution (Python):
import datetime

daylist = ["Monday", "Tuesday", "Wednesday",
           "Thursday", "Friday", "Saturday", "Sunday"]

while True:
    m, d = map(int, input().split())
    if m == 0:
        break
    day = datetime.date(2004, m, d).weekday()
    print(daylist[day])

Solution (Python):
import math
def Wit(y,m,d):
    if m == 1 or m == 2:
        y -= 1
        m += 12
    e = math.floor((26 * (m + 1)) / 10)
    Y = y % 100
    C = math.floor(y / 100)
    f = math.floor(C / 4)
    g = math.floor(Y / 4)
    h = d + e + Y + f + g + 5 * C
    h = int(h % 7)
    return h
while True:

    y = 2004
    m,d = map(int,input().split())
    if m == 0 and d == 0:
        break
    You = Wit(y,m,d)
    if You == 1:
        print("Sunday")
    elif You == 3:
        print("Tuesday")
    elif You == 2:
        print("Monday")
    elif You == 4:
        print("Wednesday")
    elif You == 5:
        print("Thursday")
    elif You == 6:
        print("Friday")
    elif You == 0:
        print("Saturday")

Solution (Python):
from datetime import date

if __name__ == '__main__':
    while True:
        
        month, day = [int(x) for x in input().split(' ')]
        if month == 0:
            break

        
        dt = date(2004, month, day)
        print(dt.strftime('%A'))

Solution (Python):
from datetime import date

while True:
    m, d = map(int, input().split())
    if (m, d) == (0, 0):
        break
    weeks = {1:'Monday',2:'Tuesday',3:'Wednesday',4:'Thursday',5:'Friday',6:'Saturday',7:'Sunday'}
    w = date.isoweekday(date(2004, m, d))
    print(weeks[w])

Solution (Python):
from datetime import date
week=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
while True:
    a,b=map(int,input().split())
    if a==0:
        break
    print(week[date(2004,a,b).weekday()])

Solution (Python):
from datetime import date
LIST=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]

while True:
    m, d = map(int,input().split())
    if m == 0:
        break
    print(LIST[date(2004,m,d).weekday()])

Solution (Python):
while 1:
    m,d=map(int,input().split())
    if m==0:break
    print(['Wednes', 'Thurs', 'Fri', 'Satur', 'Sun', 'Mon', 'Tues'][([0,31,60,91,121,152,182,213,244,274,305,335][m-1]+d)%7]+'day')

Solution (Python):
while 1:
    m,d=map(int,input().split())
    if m==0:break
    print(['Wednes','Thurs','Fri','Satur','Sun','Mon','Tues'][([0,31,60,91,121,152,182,213,244,274,305,335][m-1]+d)%7]+'day')

Solution (Python):
import datetime
while 1:
    m,d=map(int,input().split())
    if m==0:break
    print(['Mon','Tues','Wednes','Thurs','Fri','Satur','Sun'][datetime.date(2004,m,d).weekday()]+'day')

Solution (Python):
import datetime

l = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ]

while True:
  m, d = raw_input().rstrip().split(" ")
  if int(m) == 0 and int(d) == 0: break
  print(l[datetime.date(2004, int(m), int(d)).weekday()])

Solution (Python):
from datetime import date
import calendar

while True:
    m, d = map(int, input().split())
    if not m:
        break
    print(calendar.day_name[date(2004, m, d).weekday()])

Solution (Python):
month = [0,31,29,31,30,31,30,31,31,30,31,30,31]
week = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']

while True:
    m,d = list(map(int,input().split()))
    if m == 0 and d == 0:
        break
    day = 3
    x = 1
    y = 1
    while x != m or y != d:
        if y == month [x]:
            x += 1
            y = 1
        else:
            y += 1
        day += 1
        day %= 7
    print(week [day])

Solution (Python):
days = [31,29,31,30,31,30,31,31,30,31,30,31]
ans = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]

while True:
    idx = 3
    m,d = map(int, input().split())
    if m==0: break
    print(ans[(idx+sum(days[:m-1])+d-1)%7])

Solution (Python):


import sys
import os
import datetime

DAY_OF_WEEK = ['Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday']
MONTH = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

for s in sys.stdin:
    month, day = map(int, s.split())
    if month == day == 0:
        break

    past_day = sum(MONTH[:month]) + day - 1

    a = past_day % 7
    print(DAY_OF_WEEK[a])

Solution (Python):
from datetime import date
DOTW = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
while True :
    try :
        month,day = [int(_) for _ in input().split()]
        print(DOTW[date(2004,month,day).weekday()])
    except : break

Solution (Python):
monthday = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
days = ['Wednesday', 'Thursday', 'Friday', 'Saturday',
		'Sunday', 'Monday', 'Tuesday']

def nthday(m, d):
	cnt = d
	for i in range(0, m):
		cnt += monthday[i]
	return cnt

while True:
	inpt = map(int, raw_input().split())
	if inpt[0] == 0:
		break
	else:
		print days[nthday(inpt[0], inpt[1]) % 7]

Solution (Python):
import sys
from datetime import *
for line in sys.stdin:
    m, d = map(int,line.split())
    try:
        print(date(2004, m, d).strftime("%A"))
    except ValueError:
        break

Solution (Python):
import datetime
 
days = [
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday',
    'Sunday'
        ]
 
while True:
    m, d = map(int, input().split(' '))
    if m == 0: break
    print(days[datetime.date(2004, m, d).weekday()])

Solution (Python):
from datetime import date
while True:
    m, d = map(int, input().split())
    if m == 0:
        break
    result = date(2004, m, d).isoweekday()
    print("Monday"*(result==1)+"Tuesday"*(result==2)+"Wednesday"*(result==3)+"Thursday"*(result==4)+"Friday"*(result==5)+"Saturday"*(result==6)+"Sunday"*(result==7))

Solution (Python):
from datetime import date
while True:
    m, d = map(int, input().split())
    if m == 0:
        break
    result = date(2004, m, d).isoweekday()
    print("Mon"*(result==1)+"Tues"*(result==2)+"Wednes"*(result==3)+"Thurs"*(result==4)+"Fri"*(result==5)+"Satur"*(result==6)+"Sun"*(result==7)+"day")

Solution (Python):
while True:
    m, d = map(int, input().split())
    if m == d == 0:
        break
    dim = {1: 0, 2: 31, 3: 60, 4: 91, 5: 121, 6: 152, 7: 182, 8: 213, 9: 244, 10: 274, 11: 305, 12: 335}
    ds = dim[m] + d -1
    print({0:'Thursday', 1:'Friday', 2:'Saturday', 3:'Sunday', 4:'Monday', 5:'Tuesday', 6:'Wednesday'}[ds % 7])

Solution (Python):
week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
while 1:
    key = 2
    data = list(map(int, input().split()))
    if data[0] == 0 and data[1] == 0:
        break
    month = data[0]
    day = data[1]
    for i in range(month-1):
        key += days[i]
    key += day
    print(week[key % 7])

Solution (Python):


import sys, math, os, datetime


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


DAY = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
while True:
    m, d = [int(_) for _ in input().split()]
    if m == d == 0:
        break
    print(DAY[datetime.date(2004, m, d).weekday()])

Solution (Python):


import sys, math, os, datetime


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


DAY = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
while True:
    m, d = [int(_) for _ in input().split()]
    if m == d == 0:
        break
    print(DAY[datetime.date(2004, m, d).weekday()])

Solution (Python):
import sys
from datetime import *
from time import *


day = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ]

while True:
    try:
        user_input_date = '2004/'+'/'.join(input().split())
        if user_input_date == '2004/0/0':
            break
        else:
            a = datetime.strptime(user_input_date,'%Y/%m/%d')
            print(day[a.weekday()])
    except ValueError:
        pass
else:
    sys.exit(1)

Solution (Python):
import sys
from datetime import *
from time import *

day = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ]

while True:
    try:
        user_input_date = '2004/'+'/'.join(input().split())
        if user_input_date == '2004/0/0':
            break
        else:
            a = datetime.strptime(user_input_date,'%Y/%m/%d')
            print(day[a.weekday()])
    except ValueError:
        pass
else:
    sys.exit(1)

Solution (Python):
import sys
from datetime import *
from time import *

day = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ]

while True:
    try:
        user_input_date = '2004/'+'/'.join(raw_input().split())
        if user_input_date == '2004/0/0':
            break
        else:
            a = datetime.strptime(user_input_date,'%Y/%m/%d')
            print day[a.weekday()]
    except ValueError:
        pass
else:
    sys.exit(1)

Solution (Python):
day = ['Wednesday','Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday']
month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]


m, d = [int(i) for i in input().split()]
while m != 0:
    sum = 0
    for i in range(0, m - 1):
        sum += month[i]
    sum += d
    print(day[sum % 7])
    m, d = [int(i) for i in input().split()]

Solution (Python):

import datetime
day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
while True :
    month, date = map(int, input().split())
    if month == date == 0: break
    print(day[datetime.date(2004, month, date).weekday()])

Solution (Python):
days_in_month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

while True:
    m, d = map(int, input().split())
    if m == 0 or d == 0:
        break
    days = 0
    for month in range(0, m-1):
        days += days_in_month[month]
    days += d + 2
    days %= 7
    print(day[days])

Solution (Python):
month, day = map(int, raw_input().split())
days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
youbi = ["Sunday", "Monday", "Tuesday",
         "Wednesday", "Thursday", "Friday", "Saturday"]
while month != 0:
    Days = 0
    for i in range(month - 1):
        Days += days[i]
    Days += day
    print youbi[(Days + 3) % 7]
    month, day = map(int, raw_input().split())

Solution (Python):
lis=[0 for i in range(7)]
lis[0]="Wednesday"
lis[1]="Thursday"
lis[2]="Friday"
lis[3]="Saturday"
lis[4]="Sunday"
lis[5]="Monday"
lis[6]="Tuesday"
while 1:
    date=0
    x,y=map(int,input().split())
    if x!=0 and y!=0:
        for i in range(1,x):
            if i==4 or i==6 or i==9 or i==11:
                date=date+30
            elif i==2:
                date =date+29
            else:
                date=date+31
        k=(date+y)%7
        print(lis[k])
    else:
        break

Solution (Python):
f = lambda x:x%7
p = print

def judge(x):
    if  f(x)== 1:
        p("Thursday")
    elif f(x) == 2:
        p("Friday")
    elif f(x) == 3:
        p("Saturday")
    elif f(x) == 4:
        p("Sunday")
    elif f(x) == 5:
        p("Monday")
    elif f(x) == 6:
        p("Tuesday")
    else:
        p("Wednesday")

days = [31,29,31,30,31,30,31,31,30,31,30,31]
while True:
    month,day = [int(i) for i in input().split()]
    if month == 0:
        break
    elif month == 1:   
        x = day
    else:
        x = sum(days[:month-1]) + day
    judge(x)

Solution (Python):
import sys

DoD = ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"]


def getPNoD(n):
  if n == 1:
    return 0
  elif n == 3:
    return 29 + getPNoD(n-1)
  elif (n % 2 == 0 and n <= 8) or (n % 2 != 0 and n > 8):
    return 31 + getPNoD(n-1)
  else:
    return 30 + getPNoD(n-1)


for line in sys.stdin:
  m, d = [int(i) for i in line.split()]
  if m == 0:
    break
  n = getPNoD(m) + d - 1
  print(DoD[n % 7])

Solution (Python):
import datetime

weekdays = [
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday',
    'Sunday'
]

while True:
    m,d = [int(i) for i in input().split()]
    if not(m or d):
        break
    print(weekdays[datetime.date(2004, m, d).weekday()])

Solution (Python):
import datetime

date_list = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

while True:
    m, d = map(int, input().split())
    if m == 0 and d == 0:
        break
    print(date_list[datetime.date(2004, m, d).weekday()])

Solution (Python):
import datetime

date_list = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

while True:
    m, d = map(int, input().split())
    if m == 0 and d == 0:
        break
    print(date_list[datetime.date(2004, m, d).weekday()])

Solution (Python):
accum = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]
youbi = ["Wednesday", "Thursday", "Friday", "Saturday",
         "Sunday", "Monday", "Tuesday", ]


def getYoubi(month, day):
    total = accum[month - 1] + day
    return youbi[total % 7]


month = 13
day = 32

while True:
    month, day = map(int, input().split())
    if month == 0:
        break
    print(getYoubi(month, day))