1. 
/**
* Angewandte Mathematik, SS11
* Problem: 602 - What Day Is It?
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=8&page=show_problem&problem=543
*
* @author Unverzart Michael
* @author Wurth Manuel
* @version 1.0, 06/05/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.284
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String inputLine;
int[] mt = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int[] mz = { 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 };
String[] d = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
String[] m = { "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
while ((inputLine = reader.readLine()) != null) {
StringTokenizer st = new StringTokenizer(inputLine);
int month = new Integer(st.nextToken());
int day = new Integer(st.nextToken());
int year = new Integer(st.nextToken());
if(day==0&&month==0&&year==0) break;
try {
if(mt[month-1]>=day){
//gregorianischer oder julianischer Kalender
boolean gregorianisch = (year>1752);
boolean julianisch = (year<1752);
if(year==1752) {
if (month>9 || month==9 && day>=14) gregorianisch = true;
if (month<9 || month==9 && day<=2) julianisch = true;
if (!gregorianisch && !julianisch) throw new Exception();
}
//Schaltjahr
int yearmod100 = year % 100;
boolean schaltjahr = (year % 4 == 0 && (yearmod100 != 0 || year % 400 == 0));
if(julianisch && !schaltjahr) schaltjahr = yearmod100 == 0;
if(!schaltjahr && month == 2 && day>28) throw new Exception();
//Wochentagsberechnung
int ziffer = day;
ziffer += mz[month - 1];
ziffer += (yearmod100 + (yearmod100 / 4));
if (gregorianisch) ziffer += (3 - ((year / 100) % 4)) * 2;
if (julianisch) ziffer += 6 - (((year / 100) - 5) % 7);
if ((month == 1 || month == 2) && schaltjahr) ziffer += 6;
System.out.println(m[month - 1] + " " + day + ", " + year + " is a " + d[ziffer % 7]);
} else {
throw new Exception();
}
} catch (Exception e) {
System.out.println(month+"/"+day+"/"+year+" is an invalid date.");
}
}
}
}