program pinigai_pastu;
  { 72 u‘davinys }
{----------------------------------------------------------}
  const N = 10;   { maksimalus laižke ražom— adres— skai‡ius }
  type pinigai = array [1..N] of integer;
  function iskrito (a, p : integer; pin : pinigai) : integer;
    var zaidzia,   { ‘aid‚j— skai‡ius nagrin‚jamame etape }
        rezultatas, i : integer;
  begin
    rezultatas := 0;   { kol kas neižkrito nei vienas ‘aid‚jas }
    zaidzia := p;
    for i := a downto 1 do
      begin
        rezultatas := rezultatas + (zaidzia - pin[i]);
        zaidzia := pin [i] * p
      end;
    iskrito := rezultatas
  end;
{----------------------------------------------------------}
  var a, p, i : integer;
      pin : pinigai;
      f : text;
      v : string;
begin
  writeln ('­veskite pradini— duomen— bylos vard…: ');
  readln (v);
  assign (f, v);
  reset (f);
  readln (f, a, p);
  for i := 1 to a do
    read (f, pin[i]);
  writeln (iskrito (a, p, pin));
end.


