//Author: Rok Lekse

//School: St.Stanislav's Institution

//Country: Slovenia

//Division: Intermediate 3

PROGRAM MANCALA;

uses crt, sysutils;

var a:array[1..14] of integer;

r:array[1..5] of integer;

v:array[1..3] of string;

i, x, y, j, n, st, vsi, stej, z:integer;

s:string;

 

begin

CLRSCR;

WRITELN('* * * Mancala * * *   // Avtor: Rok Lekse //');

writeln('Vnesi podatke:');

 

//Avtor: Rok Lekse

 

for i:=1 to 14 do

begin

 if (i<>7) and (i<>14) then

 a[i]:=4;

end;

 

FOR Z:=1 TO 5 DO

BEGIN

readln(s);

n:=1;

 

for i:=1 to 3 do

 begin

  v[i]:='';

 end;

 

for i:=1 to length(s) do

 begin

  if (s[i]<>',') and (s[i]<>' ') then

   v[n]:=v[n]+s[i];

 

  if s[i]=' ' then

   n:=n+1;

 end;

 

x:=strtoint(v[2]);

 

if z mod 2 = 1 then

 begin

 vsi:=a[x];

 stej:=a[x];

 a[x]:=0;

 st:=x;

  if v[1]='R' then

   begin

    for i:=x+1 to x+stej do

     begin

      st:=st+1;

      if st=14 then

       st:=1;

      vsi:=vsi-1;

      if vsi>=0 then

      a[st]:=a[st]+1;

     end;

   end;

 

  if v[1]='L' then

   begin

    for i:=x-1 to x-1+stej do

     begin

      st:=st-1;

      if st=0 then

       st:=13;

      vsi:=vsi-1;

      if vsi>=0 then

      a[st]:=a[st]+1;

     end;

   end;

end;

 

if z mod 2 = 0 then

 begin

 vsi:=a[x+1];

 stej:=a[x+1];

 a[x+1]:=0;

 st:=x+1;

  if v[1]='R' then

   begin

    for i:=x+1 to x+stej do

     begin

      st:=st+1;

      if st=15 then

       st:=1;

      if st=7 then

      st:=8;

      vsi:=vsi-1;

 

      if vsi>=0 then

      a[st]:=a[st]+1;

     end;

   end;

 

  if v[1]='L' then

   begin

   for i:=x-1 to x-1+stej do

   begin

    st:=st-1;

    if st=7 then

     st:=6;

    if st=0 then

     st:=14;

    vsi:=vsi-1;

 

    if vsi >=0 then

     a[st]:=a[st]+1;

   end;

   end;

 end;

 

if v[3]='A' then

r[z]:=a[7];

if v[3]='B' then

r[z]:=a[14];

if (v[3]<>'A') and (v[3]<>'B') then

begin

if strtoint(v[3])<=6 then

r[z]:=a[strtoint(v[3])]

else

r[z]:=a[strtoint(v[3])+1];

end;

 

{

for i:=1 to 14 do

 begin

 if i=7 then

 writeln('A = ',a[7])

 else if i=14 then

 writeln('B = ',a[14])

 else

 writeln(i, '  ', a[i]);

 end;

 writeln;}

END;

writeln;

WRITELN('Reçitve:');

for i:=1 to 5 do

begin

writeln(i, '.  ', r[i]);

end;

 

readln;

end.