Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
	"time"
)

var sc = bufio.NewScanner(os.Stdin)

//Sliceconvtoi ...
func Sliceconvtoi() []int {
	strs := strings.Split(sc.Text(), " ")

	var ints []int
	var x int

	for _, s := range strs {
		x, _ = strconv.Atoi(s)
		ints = append(ints, x)
	}

	return ints
}

func main() {
	for sc.Scan() {
		i := Sliceconvtoi()

		if i[0] == 0 && i[1] == 0 {
			break
		}

		m := time.Month(i[0])
		d := i[1]
		t := time.Date(2004, m, d, 0, 0, 0, 0, time.Local)
		fmt.Println(t.Weekday())
	}

}

C++: #include <iostream>
using namespace std;
int main(void){
    int a,b;
    while (cin >>a>>b) {
        if(a==0 && b==0) break;
        
        else if(a==1){
            if((b+7)%7==1) cout<<"Thursday"<<endl; else if((b+7)%7==2) cout<<"Friday"<<endl;
            else if((b+7)%7==3) cout<<"Saturday"<<endl; else if((b+7)%7==4) cout<<"Sunday"<<endl;
            else if((b+7)%7==5) cout<<"Monday"<<endl; else if((b+7)%7==6) cout<<"Tuesday"<<endl;
            else cout<<"Wednesday"<<endl;
        }
        
        else if(a==2){
            if((b+7)%7==1) cout<<"Sunday"<<endl; else if((b+7)%7==2) cout<<"Monday"<<endl;
            else if((b+7)%7==3) cout<<"Tuesday"<<endl; else if((b+7)%7==4) cout<<"Wednesday"<<endl;
            else if((b+7)%7==5) cout<<"Thursday"<<endl; else if((b+7)%7==6) cout<<"Friday"<<endl;
            else cout<<"Saturday"<<endl;
        }
        else if(a==3){
            if((b+7)%7==1) cout<<"Monday"<<endl; else if((b+7)%7==2) cout<<"Tuesday"<<endl;
            else if((b+7)%7==3) cout<<"Wednesday"<<endl; else if((b+7)%7==4) cout<<"Thursday"<<endl;
            else if((b+7)%7==5) cout<<"Friday"<<endl; else if((b+7)%7==6) cout<<"Saturday"<<endl;
            else cout<<"Sunday"<<endl;
        }
        
        else if(a==4){
            if((b+7)%7==1) cout<<"Thursday"<<endl; else if((b+7)%7==2) cout<<"Friday"<<endl;
            else if((b+7)%7==3) cout<<"Saturday"<<endl; else if((b+7)%7==4) cout<<"Sunday"<<endl;
            else if((b+7)%7==5) cout<<"Monday"<<endl; else if((b+7)%7==6) cout<<"Tuesday"<<endl;
            else cout<<"Wednesday"<<endl;
        }
        
        else if(a==5){
            if((b+7)%7==1) cout<<"Saturday"<<endl; else if((b+7)%7==2) cout<<"Sunday"<<endl;
            else if((b+7)%7==3) cout<<"Monday"<<endl; else if((b+7)%7==4) cout<<"Tuesday"<<endl;
            else if((b+7)%7==5) cout<<"Wednesday"<<endl; else if((b+7)%7==6) cout<<"Thursday"<<endl;
            else cout<<"Saturday"<<endl;
        }
        
        else if(a==6){
            if((b+7)%7==1) cout<<"Tuesday"<<endl; else if((b+7)%7==2) cout<<"Wednesday"<<endl;
            else if((b+7)%7==3) cout<<"Thursday"<<endl; else if((b+7)%7==4) cout<<"Friday"<<endl;
            else if((b+7)%7==5) cout<<"Saturday"<<endl; else if((b+7)%7==6) cout<<"Sunday"<<endl;
            else cout<<"Monday"<<endl;
        }
        
        
        else if(a==7){
            if((b+7)%7==1) cout<<"Thursday"<<endl; else if((b+7)%7==2) cout<<"Friday"<<endl;
            else if((b+7)%7==3) cout<<"Saturday"<<endl; else if((b+7)%7==4) cout<<"Sunday"<<endl;
            else if((b+7)%7==5) cout<<"Monday"<<endl; else if((b+7)%7==6) cout<<"Tuesday"<<endl;
            else cout<<"Wednesday"<<endl;
        }
        
        else if(a==8){
            if((b+7)%7==1) cout<<"Sunday"<<endl; else if((b+7)%7==2) cout<<"Monday"<<endl;
            else if((b+7)%7==3) cout<<"Tuesday"<<endl; else if((b+7)%7==4) cout<<"Wednesday"<<endl;
            else if((b+7)%7==5) cout<<"Thursday"<<endl; else if((b+7)%7==6) cout<<"Friday"<<endl;
            else cout<<"Saturday"<<endl;
            
        }
        
        else if(a==9){
            if((b+7)%7==1) cout<<"Wednesday"<<endl; else if((b+7)%7==2) cout<<"Thursday"<<endl;
            else if((b+7)%7==3) cout<<"Friday"<<endl; else if((b+7)%7==4) cout<<"Saturday"<<endl;
            else if((b+7)%7==5) cout<<"Sunday"<<endl; else if((b+7)%7==6) cout<<"Monday"<<endl;
            else cout<<"Tuesday"<<endl;
        }
        
        else if(a==10){
            if((b+7)%7==1) cout<<"Friday"<<endl; else if((b+7)%7==2) cout<<"Saturday"<<endl;
            else if((b+7)%7==3) cout<<"Sunday"<<endl; else if((b+7)%7==4) cout<<"Monday"<<endl;
            else if((b+7)%7==5) cout<<"Tuesday"<<endl; else if((b+7)%7==6) cout<<"Wednesday"<<endl;
            else cout<<"Thursday"<<endl;
            
        }
        
        else if(a==11){
            if((b+7)%7==1) cout<<"Monday"<<endl; else if((b+7)%7==2) cout<<"Tuesday"<<endl;
            else if((b+7)%7==3) cout<<"Wednesday"<<endl; else if((b+7)%7==4) cout<<"Thursday"<<endl;
            else if((b+7)%7==5) cout<<"Friday"<<endl; else if((b+7)%7==6) cout<<"Saturday"<<endl;
            else cout<<"Sunday"<<endl;
        }
        else if(a==12){
            if((b+7)%7==1) cout<<"Wednesday"<<endl; else if((b+7)%7==2) cout<<"Thursday"<<endl;
            else if((b+7)%7==3) cout<<"Friday"<<endl; else if((b+7)%7==4) cout<<"Saturday"<<endl;
            else if((b+7)%7==5) cout<<"Sunday"<<endl; else if((b+7)%7==6) cout<<"Monday"<<endl;
            else cout<<"Tuesday"<<endl;
        }
        
        
        
    }
}

C++: #include <iostream>
#include <string>
using namespace std;


int main() {
  const int n_day[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  const string week_name[] = {
    "Wednesday",
    "Thursday",
    "Firday",
    "Saturday",
    "Sunday",
    "Monday",
    "Tuesday"
  };


  int m, d, sum=0;
  cin >> m >> d;
  while(m != 0 && d != 0) {
    m--;
    for(int i=0; i<m; i++) {
      sum += n_day[i];
    }
    sum += d;
    cout << week_name[sum%7] << endl;
    sum = 0;
    cin >> m >> d;
  }
  return 0;
}

C++: 
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

C++: #include <iostream>
#include <cstdio>
using namespace std;
string name[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int dayOfWeek(int y, int m, int d) {
    if(m == 1 || m == 2) {
        y--;
        m += 12;
    }
    return(y + y / 4 - y / 100 + y / 400 + (13*m + 8) / 5 + d) % 7;
}

int main(void) {
    int y = 2004, m, d;
    while(scanf("%d %d", &m, &d), m + d != 0) {
        cout << name[dayOfWeek(y, m, d)] << endl;
    }
    return(0);
}