Program Kalendar;
uses crt;
var Rok, i, j, k, l: integer;
    Dny:array[1..12] of integer;
    Zac_den:array[1..12] of integer;
    P: longint;
    Mesice:array[1..12, 1..42] of integer;
    f: text;

Function PrestupnyRok(R:integer):boolean;  {zjisti, zda je dany rok prestupny}
begin
   if ((R mod 4 = 0) and (R mod 100<>0)) or (R mod 400 = 0) then
       PrestupnyRok:=true
   else PrestupnyRok:=false;
end;

Procedure ZacatekRoku(R:integer); {zjisti, na ktery den pripadne 1.1.}
var R1, R2, I:integer;
begin
    R1:=1583; {1.1.1583 je sobota}
    for I:=R1 to (R-1) do begin
        if PrestupnyRok(I) then
          P:=P+366
        else P:=P+365;
    end;

    P:= P mod 7;
    if P=0 then P:=6;      {vrati poradove cislo dne}
    if P=1 then P:=7;
    if P=2 then P:=1;
    if P=3 then P:=2;
    if P=4 then P:=3;
    if P=5 then P:=4;
    if P=6 then P:=5;

end;

Procedure vrat_dny(den:integer); {vrati pocatecni den v mesici}
var i:integer;
    buffer : integer;
begin
   Zac_den[1]:=den;
   buffer := Zac_den[1];
   for i:=2 to 12 do begin
       Zac_den[i]:=(buffer + Dny[i-1]) mod 7;
       buffer := buffer + Dny[i-1];
   if (Zac_den[i]=0) then Zac_den[i]:=7; end;
end;

Begin
   assign (f,'.\rok.txt');
   rewrite(f);
   Dny[1]:=31; Dny[3]:=31; Dny[4]:=30;
   Dny[5]:=31; Dny[6]:=30; Dny[7]:=31; Dny[8]:=31;
   Dny[9]:=30; Dny[10]:=31; Dny[11]:=30; Dny[12]:=31;
   readln(Rok);
   if PrestupnyRok(Rok) then
     Dny[2]:=29
   else
     Dny[2]:=28;
   ZacatekRoku(Rok);
   Vrat_dny(P);
   for i:=1 to 12 do
   begin
       k:=1;
       for j:=1 to 42 do
       begin
           if (j >= zac_den[i]) and (j < dny[i] + zac_den[i]) then
              begin
                Mesice[i,j]:=k;
                k:=k+1;
              end
           else
              Mesice[i,j]:= 0;
       end;
   end;

  for i := 0 to 3 do
   begin
    for j := 1 to 7 do
     begin  write(f,' *  ');
      for k := 1 to 3 do
       begin  if j=1 then write(f,'Po ');
              if j=2 then write(f,'Ut ');
              if j=3 then write(f,'St ');
              if j=4 then write(f,'Ct ');
              if j=5 then write(f,'Pa ');
              if j=6 then write(f,'So ');
              if j=7 then write(f,'Ne ');

         for l := 0 to 5 do
         begin
           if mesice[k+i*3, j+l*7] = 0 then
             write(f,'   ')
           else
               if mesice[k+i*3, j+l*7] < 10 then
                  write(f,' ', mesice[k+i*3, j+l*7],' ')
                else
                    write(f,mesice[k+i*3, j+l*7],' ');
         end;
         write(f,' *  ');
        end;
       writeln(f);
     end;
     writeln(f);
   end;
  close(f);
End.


