Program Chem_rov_jadro;
 type Mcislo = record
                c,m:integer;
               End;

 var s : string;

Procedure Nacitaj;
Begin
 s:='KMnO4+FeSO4+H2SO4>Fe2(SO4)3+MnSO4+K2SO4+H2O';
End;

Procedure Vymen(var a,b : integer);
 var c : integer;
Begin
 c := a;
 a := b;
 b := c;
End;

Function NSD(a,b : integer) : integer;
 { najde najmensieho spolocneho delitela cisel a,b }
Begin
 a := abs(a);
 b := abs(b);

 if a < b
  then
   Vymen(a,b);
 while (a mod b <> 0) do
  Begin
   a := a mod b;
   if a < b
    then
     Vymen(a,b)
  End;
End;

Procedure Vydel(cim,co : Mcislo; var v : Mcislo);
 var a : integer;
Begin
 co.c := co.c * cim.m;
 co.m := co.m * cim.c;
 if (co.c=0)or(co.m=0)
  then a := 1
  else a := NSD(co.c,co.m);
 if a <> 1
  then
   Begin
    co.c := co.c div a;
    co.m := co.m div a
   End;
End;

Procedure Scitaj(coc,com,scimc,scimm : integer; var vc,vm:integer);
 var a : integer;
Begin
 vc := coc*scimm + com*scimc;
 vm := com*scimm;
 if (vc=0)or(vm=0)
  then a := 1
  else a := NSD(vc,vm);
 if a <> 1
  then
   Begin
    vc := vc div a;
    vm := vm div a
   End;
End;

Procedure Uprav;
 var c : string[2];
     n : char;
     i,j,k,l : integer;
     h,z : byte;
     chyba : integer;
     A : array[1..20,1..20] of Mcislo;
     p : array[1..20] of string[2];
     st,r : integer;
     bolo,ns : boolean;
     pom : Mcislo;

Begin
 {inicializacia}
 for i:=1 to 20 do
  Begin
   p[i]:='';
   for j:=1 to 20 do
    Begin
     A[i,j].c:=0;
     A[i,j].m:=1;
    End;
  End;
 st := 1;
 r := 0;
 i := length(s);
 z := 1;
 ns := false;


 repeat
  h := 1;
  if s[i] in ['+','>']
   then
    Begin
     if s[i] = '>'
      then
       ns := true;
     inc(st);
     dec(i);
    End;
  {najdi kolkokrat}
  while s[i] in ['0'..'9','(',')'] do
   Begin
    if s[i] = ')'
     then
      z := h
     else
      if s[i] = '('
       then
        z := 1;

    if s[i] in ['0'..'9']
     then
      val(s[i],h,chyba);
    dec(i);
   End;
  {najdi prvok}
  if s[i] in ['a'..'z']
   then
    Begin
     dec(i);
     c := s[i] + s[i+1];
    End
   else
    c := s[i];

  bolo := false;
  for j:=1 to r do
   Begin
    if p[j]=c
     then
      Begin
       bolo := true;
       break;
      End;
   End;
  if bolo
   then
    Begin
     if ns
      then
       A[j,st].c := -h * z
      else
       A[j,st].c := h * z;
    End
   else
    Begin
     inc(r);
     p[r] := c;
     if ns
      then
       A[r,st].c := -h * z
      else
       A[r,st].c :=h * z;
    End;
  dec(i);
 until i=0;

 inc(st);
 for i:=1 to r do
  A[i,st].c := 0;
 inc(r);
 for i:=1 to st-2 do
  A[r,i].c := 0;
 A[r,st-1].c := 1;
 A[r,st].c := 1;

 { teraz to ma urobit Gaussovu eliminaciu...}
 writeln('Tuto maticu bude este treba dopocitat...');
 writeln;

 for i:=1 to r do
  Begin
   for j:=1 to st do
    Begin
     write(A[i,j].c:4)
    End;
   writeln;
  End;
 writeln('----------------------------------------------')

End;

Procedure Vypis;
 var i,j : integer;
Begin
End;

Begin
 Nacitaj;
 Uprav;
 Vypis;
End.