program pil_7_32_a(input,output);
type date=1..31;
       month=(jan,feb,mar,apr,may,jun,jul,aug,sep,okt,nov,dec);
       weekday=(mon,tue,wed,thu,fri,sat,sun);
var 
	d : date; 
	m,m1 : month; 
	wd1,wd : weekday; 
	k : 1..12; 
	s : 0..365; 
	t : 1..7;
	day : 0..7;
Begin
  Writeln('Input date and month : ');
  Read(d,k);
  Writeln('Input wd1 : ');
  Read(t);
  m := jan;
  While ord(m)+1<k do m := succ(m);
  wd1 := mon;
  While ord(wd1)+1<t do wd1 := succ(wd1);
  s := 0;
  If m>jan then
   Begin
    For m1 := pred(m) downto jan do
     Begin
      Case m1 of
       jan,mar,may,jul,aug,okt,dec:s := s+31;
       feb:s := s+28;
       apr,jun,sep,nov:s := s+30;
      End
     End
    End;
  s := s+d;
  day := s mod 7;
  if day=0 then day := 7;
  wd := mon;
  day := (day+ord(wd1)-1)mod 7;
  While day>ord(wd) do wd := succ(wd);
  Writeln('Result : ',ord(wd)+1)
 End.
