#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
char mday[12]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int y, m, d;
int startwday;
int i, ct;
y= atoi(argv[1]);
m= atoi(argv[2]);
d= mday[m-1];
if(m==2 && ((y % 4 == 0 && y % 100 != 0 )|| y % 400 == 0)) d++;
struct tm t, *ltime;
time_t time;
t.tm_year= y-1900;
t.tm_mon= m-1;
t.tm_mday= 1;
time= mktime(&t);
ltime= localtime(&time);
startwday =ltime->tm_wday;
printf(" Sun Mon Tue Wed Thu Fri Sat\n");
for(i=0,ct=0; i<startwday; i++,ct++) printf(" ");
for(i=1; i<=d; i++,ct++){
if((ct%7 == 0)&&(ct!=0)) printf("\n");
printf(" %3d", i);
}
printf("\n");
return 0;
}