You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of  is maximized. Chosen sequence can be empty.Print the maximum possible value of .

The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 109). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

NoteIn the first example you can choose a sequence b = {1, 2}, so the sum  is equal to 7 (and that's 3 after taking it modulo 4).In the second example you can choose a sequence b = {3}.

program Maximum_Subsequence;

const
   maxn = 35;
   half = 18;

var
   n, m: longint;
   a: array [1 .. maxn] of longint;

   left, right: longint;
   b, c: array [0 .. (1 shl half) - 1] of longint;

   i, j, ans: longint;

procedure process(sz, offs: longint; var x: array of longint);
var
   i, j, sum: longint;
begin
   for i := 0 to (1 shl sz) - 1 do begin
      sum := 0;
      for j := 0 to sz - 1 do
         if (i and (1 shl j)) > 0 then
            sum := (sum + a[offs + j]) mod m;
      x[i] := sum;
   end;
end;

procedure sort(var arr: array of longint; l, r: longint);
var
   m, t, i, j: longint;
begin
   m := arr[l + random(r - l + 1)];
   i := l;
   j := r;
   repeat
      while arr[i] < m do inc(i);
      while arr[j] > m do dec(j);
      if i <= j then begin
         t := arr[i]; arr[i] := arr[j]; arr[j] := t;
         inc(i); dec(j);
      end;
   until i > j;
   if j > l then sort(arr, l, j);
   if i < r then sort(arr, i, r);
end;

begin
   readln(n, m);
   for i := 1 to n do read(a[i]);

   left := n div 2;
   right := n - left;
   process(left, 1, b);
   process(right, left + 1, c);
   randomize;
   sort(b, 0, (1 shl left) - 1);
   sort(c, 0, (1 shl right) - 1);

   if c[0] = c[(1 shl right) - 1] then begin
      writeln(b[(1 shl left) - 1]);
      halt;
   end;

   j := 1;
   ans := 0;
   for i := 0 to (1 shl left) - 1 do begin
      while (b[i] + c[j]) mod m <= (b[i] + c[(j + 1) mod (1 shl right)]) mod m do
         j := (j - 1 + (1 shl right)) mod (1 shl right);
      if ans < (b[i] + c[j]) mod m then
         ans := (b[i] + c[j]) mod m;
   end;

   writeln(ans);
end.

                   const eps=1e-10;
                    besk=4000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1000000+1] of int64;
var mask,step,i,j,k:longint;
num1,num2,num,sum,tt,xx,pos,x0,y0,x1,y1,q2,q1,sum1,sum2,izb1,izb2,t1,t2,m,n,l,dl,i1,j1,imin,pp,p1,p2,kol,ost,nn,modul,p,ot,pmin,tmax,minf,kk,gr1,gr2,ii,tt1,nnn,d,raz1,raz2,v,s,st,q,t,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
g,b1,a1:array[-1000..3000000] of int64;
yy,zz,bbbb,cccc:array[-10..1000000] of int64;
 ss,ss1:string;
sumx,sumy,ott,da,dc,dn,d1,d2,aa,bb,cc,t3:extended;
r,z1,z2,z,x,y,dd:array[-1000..1000000] of int64;
ll,rr,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin srav:=a[i]<=a[j];  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function zapmin(ll,rr:longint):longint;
var t1,t2,ot:longint;
begin
  if ll=rr then zapmin:=z[ll] else
    begin
       if not odd(rr) then zapmin:=min(z[rr],zapmin(ll,rr-1));
       if  odd(ll) then zapmin:=min(z[ll],zapmin(ll+1,rr));
       if odd(rr) and not odd(ll) then zapmin:=zapmin(ll shr 1,rr shr 1);

    end;

end;

begin

 { assign(input,'input.txt');reset(input);
  assign(output,'output.txt');rewrite(output);
  }

  read(nn,modul);
  for i:=1 to nn do read(z[i]);

      t:=nn div 2;
      tt:=nn-t;
      p:=1; for i:=1 to t do p:=p*2;
      pp:=1; for i:=1 to tt do pp:=pp*2;

     for mask:=0 to p-1 do
       begin
          q:=mask;
          sum:=0;
          for i:=1 to t do begin  x[i]:=q and 1; q:=q shr 1;  end;
          for i:=1 to t do sum:=sum+x[i]*z[i];
          inc(num); y[num]:=sum mod modul;

       end;

      { for i:=1 to num do write(y[i],' ');
      } for i:=1 to num do a[i]:=y[i];
       n:=1; repeat n:=n*2 until(n>=num);
       for i:=1+num to n do a[i]:=besk;
       sort(a);
       for i:=1 to num do yy[i]:=a[i]; num1:=num;

      { writeln(num1); for i:=num1-10 to num1 do write(yy[i],' '); writeln;
       }

            num:=0;
        for mask:=0 to pp-1 do
       begin
          q:=mask;
          sum:=0;
          for i:=1 to tt do begin  x[i]:=q and 1; q:=q shr 1;  end;
          for i:=1 to tt do sum:=sum+x[i]*z[nn-i+1];
          inc(num); y[num]:=sum mod modul;

       end;

      { for i:=1 to num do write(y[i],' ');
      } for i:=1 to num do a[i]:=y[i];
       n:=1; repeat n:=n*2 until(n>=num);
       for i:=1+num to n do a[i]:=besk;
       sort(a);
       for i:=1 to num do zz[i]:=a[i]; num2:=num;

       { writeln(num2); for i:=num2-10 to num2 do write(zz[i],' ');writeln;
        }
       pos:=num2;
       for i:=1 to num1 do
         begin
            if yy[i]+zz[pos]>=modul then
            repeat ot:=max(ot,(yy[i]+zz[pos]) mod modul); dec(pos);
               {     writeln('dvigaem i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul);
                }   ot:=max(ot,(yy[i]+zz[pos]) mod modul);
             until (pos<=0)or(yy[i]+zz[pos]<modul ) else
              begin
                ot:=max(ot,(yy[i]+zz[pos]) mod modul);
              {  writeln('stoim i= ',i,' pos= ',pos,'  sum= ',yy[i],' + ',zz[pos],' ot= ',ot);
             } end;

         end;

        pos:=num1;
       for i:=1 to num2 do
         begin
            if yy[i]+zz[pos]>=modul then
            repeat ot:=max(ot,(zz[i]+yy[pos]) mod modul); dec(pos);
                  {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul); }
             until (pos<=0)or(zz[i]+yy[pos]<modul ) else
              begin
                ot:=max(ot,(zz[i]+yy[pos]) mod modul);
              {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul);
             } end;

         end;

   writeln(ot);

 1: close (output);
end.

const
    maxn=40;
var
    n,k,n1,m:longint;
    a,x:array[0..maxn] of longint;
    s1:array[0..1000005] of int64;
    kq:int64;

procedure enter;
var i:longint;
    begin
    readln(n,m);
    for i:=1 to n do
        read(a[i]);
    k:=(n+1) div 2;
    if n=1 then
        begin
        write(a[1] mod m);
        halt;
        end;
    end;

procedure swap(var a,b:int64);
var c:int64;
    begin
    c:=a;
    a:=b;
    b:=c;
    end;

procedure sort(l,r:longint);
var i,j:longint;
    mid:int64;
    begin
    i:=l; j:=r;
    mid:=s1[l+random(r-l+1)];
    repeat
        while s1[i]<mid do inc(i);
        while s1[j]>mid do dec(j);
        if i<=j then
            begin
            swap(s1[i],s1[j]);
            inc(i);
            dec(j);
            end;
    until i>j;
    if i<r then sort(i,r);
    if l<j then sort(l,j);
    end;

procedure ghinghiem;
var i:longint;
    s:int64;
    begin
    s:=0;
    for i:=1 to k do
        if x[i]=1 then
            inc(s,a[i]);
    inc(n1);
    s1[n1]:=s mod m;
    end;

procedure try1(i:longint);
var j:longint;
    begin
    for j:=0 to 1 do
        begin
        x[i]:=j;
        if i=k then ghinghiem
            else try1(i+1);
        end;
    end;

function find(i,j:longint; val:int64):longint;
var l,r,mid:longint;
    begin
    l:=i; r:=j;
    while l<=r do
        begin
        mid:=l+random(r-l+1);
        if s1[mid]<=val then
            if (mid=n1) or (s1[mid+1]>val) then exit(mid);
        if s1[mid]<=val then
            l:=mid+1 else
                r:=mid-1;
        end;
    exit(-1);
    end;

function max(a,b:int64):int64;
    begin
    if a>b then exit(a);
    exit(b);
    end;

procedure timnghiem;
var i,v:longint;
    s:int64;
    begin
    s:=0;
    for i:=k+1 to n do
        if x[i]=1 then
            inc(s,a[i]);
    s:=s mod m;
    v:=find(1,n1,m-1-s);
    if v=-1 then exit;
    kq:=max(kq,s+s1[v]);
    end;

procedure try2(i:longint);
var j:longint;
    begin
    for j:=0 to 1 do
        begin
        x[i]:=j;
        if i=n then timnghiem
            else try2(i+1);
        end;
    end;

procedure process;
    begin
    try1(1);
    sort(1,n1);
    try2(k+1);
    write(kq);
    end;

begin
    enter;
    process;
end.

var n,nn,mm:longint;
cnt:longint;
m:int64;
a,x:array[0..40] of int64;
f:array[0..1000005] of int64;
res:int64;
procedure       mo;
begin
        assign(input,'test.inp');reset(input);
        assign(output,'test.out');rewrite(output);
end;
procedure       dong;
begin
        close(input);close(output);
end;
procedure       nhap;
var i:longint;
begin
        readln(n,m);
        for i:=1 to n do
                begin
                read(a[i]);
                end;
        if n=1 then
                begin
                writeln(a[i] mod m);
                halt;
                end;
        nn:=(n+1) div 2;
           mm:=nn+1;
end;
procedure       luunghiem;
var i:longint;
begin
        inc(cnt);
        for i:=1 to nn do
                begin
                if x[i]=1 then f[cnt]:=(f[cnt]+a[i]);
                end;
        f[cnt]:=f[cnt] mod m;
end;
procedure       vet1(i:longint);
var j:longint;
begin
        for j:=0 to 1 do
                begin
                x[i]:=j;
                if i=nn then luunghiem else vet1(i+1);
                end;
end;
procedure       swap(var x,y:int64);
var t:int64;
begin
        t:=x;
        x:=y;
        y:=t;
end;
procedure       qs(l,r:longint);
var i:longint;                 j,mid:longint;
begin
        i:=l;
        j:=r;
        mid:=f[l+random(r-l+1)];
        repeat
                while f[i]<mid do inc(i);
                while f[j]>mid do dec(J);
                if not(I>j) then
                        begin
                        swap(f[i],f[j]);
                        inc(i);
                        dec(j);
                        end;
        until I>j;
        if i<r then qs(i,r);
        if l<j then qs(l,j);
end;
function        find(l,r:longint;x:int64):int64;
var mid:longint;
begin
        repeat
                mid:=(l+r) div 2;
                if (f[mid]<=x) and (f[mid+1]>x) then exit(f[mid]);
                if (f[mid]>x) then r:=mid-1;
                if (f[mid]<=x) and (f[mid+1]<=x) then l:=mid+1;
        until l>r;
        exit(0);
end;
procedure       xulinghiem;
var i:longint;s:int64;   tam:int64;
begin
        s:=0;
        for i:=mm to n do
                begin
                if x[i]=1 then s:=s+a[i];
                end;
        s:=s mod m;
        tam:=find(1,cnt,m-s-1);
        if s+tam>res then res:=s+tam;
end;
procedure       vet2(i:longint);
var j:longint;
begin
        for j:=0 to 1 do
                begin
                x[i]:=j;
                if i=n then xulinghiem else vet2(i+1);
                end;
end;
procedure       xuli;
var i:longint;
begin
        vet1(1);
        qs(1,cnt);
        f[cnt+1]:=maxlongint;
        vet2(mm);
        writeln(res);
end;
begin
      //  mo;
        nhap;
        xuli;
    //    dong;
end.

uses math;
const fi='888E.inp';
        fo='888E.out';
var a,f:array[0..1000000] of longint;
        n,du,nn,dem,kq:longint;
        s:int64;
procedure ran;
        var i:longint;
        begin
                readln(n,du);
                for i:=1 to n do read(a[i]);
                if n=1 then
                        begin
                        writeln(a[i] mod du);
                        halt;
                        end;
                nn:=n div 2;
        end;
procedure haibara;
        begin
                inc(dem);
                f[dem]:=s mod du;
        end;
procedure conan(i:longint);
        var j:longint;
        begin
                for j:=0 to 1 do
                        begin
                        if j=1 then s:=s+a[i];
                        if i=nn then haibara else conan(i+1);
                        if j=1 then s:=s-a[i];
                        end;
        end;
function tnp(l,r,x:longint):longint;
        var g,k:longint;
        begin
                while l<=r do
                        begin
                        g:=(l+r) div 2;
                        if f[g] > x then r:=g-1 else
                                begin
                                k:=f[g];
                                l:=g+1;
                                end;
                        end;
                exit(k);
        end;

procedure ai;
        var j,t:longint;
        begin
                t:=s mod du;
                kq:=max(kq,t+tnp(1,dem,du-1-t));
        end;
procedure tm(i:longint);
        var j:longint;
        begin
                for j:=0 to 1 do
                        begin
                        if j=1 then s:=s+a[i];
                        if i=n then ai else tm(i+1);
                        if j=1 then s:=s-a[i];
                        end;
        end;
 procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=f[(l+r) div 2];
         repeat
           while f[i]<x do
            inc(i);
           while x<f[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=f[i];
                f[i]:=f[j];
                f[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;

begin

        ran;
        dem:=0;
        s:=0;
        conan(1);
        sort(1,dem);
        s:=0;
        kq:=0;
        tm(nn+1);
        writeln(kq);
end.

type mang=array [0..300000] of int64;
var n,i,d1,d2:longint;
x,v1,v2,l,r,max,mid,t,m:int64;
s1,s2,a:mang;
procedure alibotto(i:longint);
    var J:longint;
    begin
    for j:=0 to 1 do
        begin
        x:=x+j*a[i];
        if i= n div 2 then
            begin
            inc(d1);
            s1[d1]:=x mod m;
            end
        else alibotto(i+1);
        x:=x-j*a[i];
        end;
    end;
 procedure sort(l,r: longint);
      var
         i,j:longint;
         x,y: int64;
      begin
         i:=l;
         j:=r;
         x:=s1[(l+r) div 2];
         repeat
           while s1[i]<x do
            inc(i);
           while x<s1[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=s1[i];
                s1[i]:=s1[j];
                s1[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;
  procedure sort1(l,r: longint);
      var
         i,j:longint;
         x,y: int64;
      begin
         i:=l;
         j:=r;
         x:=s2[(l+r) div 2];
         repeat
           while s2[i]<x do
            inc(i);
           while x<s2[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=s2[i];
                s2[i]:=s2[j];
                s2[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort1(l,j);
         if i<r then
           sort1(i,r);
      end;
procedure alibotto1(i:longint);
    var J:longint;
    begin
    for j:=0 to 1 do
        begin
        x:=x+j*a[i];
        if i= n then
            begin
            inc(d2);
            s2[d2]:=x mod m;
            end
        else alibotto1(i+1);
        x:=x-j*a[i];
        end;
    end;
function cnp:longint;
    begin
    l:=1;r:=d2;
        while l<=r do
            begin
            mid:=(l+r) div 2;
            if (s1[i]+s2[mid]<m) and(s1[i]+s2[mid+1]>=m)  then exit(mid)
            else if s1[i]+s2[mid]>=m then r:=mid-1
            else l:=mid+1;
            end;
        exit(-1);
    end;
{function cnp1:longint;
    begin
    l:=1;r:=d2;
        while l<=r do
            begin
            mid:=(l+r) div2;
            if (s1[i]
            end;
    end; }
begin
   // assign(input,'test.inp');reset(input);
   // assign(output,'test.out');rewrite(output);
    readln(n,m);
    for I:=1 to n do
        read(a[i]);
        if n=1 then
            begin
            write(a[1] mod m);
            halt;
            end;
    alibotto(1);
    alibotto1(n div 2 +1);
    v1:=m div 2;
    if  m mod 2 =0 then
        v2:=m div 2
        else v2:=m div 2+1;
        s1[d1+1]:=high(int64)-100000000000000;
        s2[d2+1]:=high(int64)-100000000000000;
        sort(1,d1);
    sort1(1,d2);

    for i:=1 to d1 do
        begin
        t:=cnp;
        if t<>-1 then
            if s2[t]+s1[i]>max then max:=s2[t]+s1[i];
        end;
        s2[0]:=-maxlongint;
      for i:=1 to d1 do
        s1[i]:=s1[i]-v1;
    for i:=1 to d2 do
        s2[i]:=s2[i]-v2;
    for i:=1 to d1 do
        begin
        if s1[i]+s2[d2]>=0 then
            if s1[i]+s2[d2]>max then max:=s1[i]+s2[d2];
        end;
    write(max);
end.

var stk:array[0..500009,0..1] of longint;
    a,top:array[0..200009] of longint;
    res,l,r,mid,n,m,i,du,kq:longint;
    ans:int64;

function max(a,b:longint):longint;
    begin
        if a>b then exit(a) else exit(b);
    end;

procedure vet(i,n,k:longint);
    var j:longint;
        begin
            if i=n+1 then
                begin
                    inc(top[k]);
                    stk[top[k],k]:=ans mod du;
                    exit;
                end;
            for j:=0 to 1 do
                begin
                    ans:=ans+a[i]*j;
                    vet(i+1,n,k);
                    ans:=ans-a[i]*j;
                end;
        end;

procedure sort(l,r,k:longint);
    var i,j,m,t,tam:longint;
        begin
            i:=l;
            j:=r;
            m:=random(r-l)+l+1;
            t:=stk[m,k];
            repeat
                while t>stk[i,k] do inc(i);
                while t<stk[j,k] do dec(j);
                if not (i>j) then
                    begin
                        tam:=stk[i,k];
                        stk[i,k]:=stk[j,k];
                        stk[j,k]:=tam;
                        inc(i);
                        dec(j);
                    end;
            until i>j;
                if l<j then sort(l,j,k);
                if i<r then sort(i,r,k);
        end;
begin
readln(n,du);
for i:=1 to n do
    read(a[i]);
vet(1,n div 2,0);
vet(n div 2+1,n,1);
sort(1,top[0],0);
sort(1,top[1],1);
for i:=1 to top[0] do
    begin
        ans:=du-stk[i,0]-1;
        l:=1;
        r:=top[1];
        res:=-1;
        while l<=r do
            begin
                mid:=(l+r) div 2;
                if stk[mid,1]>ans then r:=mid-1 else
                    begin
                        res:=stk[mid,1];
                        l:=mid+1;
                    end;
            end;
        if res=-1 then continue;
        kq:=max(kq,res+stk[i,0]);
    end;
writeln(kq);
end.

Program _888_E;
uses    math;
const   finput='888_E.inp';
        foutput='888_E.out';
        MaxN=10000000;
var     a,f,p:array[0..MaXN] of int64;
        n,q,res:longint;

Procedure Nhap;
var i:longint;
begin
   // assign(input,finput);reset(input);
   // assign(output,foutput);rewrite(output);
    read(n,q);
    for i:=1 to n do
        read(a[i]);
end;

Function getbit(x,i:longint):longint;
begin
    exit(1 and (x shr (i-1)));
end;

Procedure Cre_state;
var s,j:longint;
begin
    for s:=0 to 1 shl (n div 2)-1 do
        begin
        for j:=1 to n div 2 do
            if getbit(s,j)=1 then
                f[s]:=f[s]+a[j];
        f[s]:=f[s] mod q;
        end;
    for s:=0 to 1 shl (n-(n div 2))-1 do
        begin
        for j:=1 to n-(n div 2) do
            if getbit(s,j)=1 then
                p[s]:=p[s]+a[j+n div 2];
        p[s]:=p[s] mod q;
        end;
end;

Procedure Sort(l,r:longint);
var i,j,mid,tmp:longint;
begin
    i:=l;
    j:=r;
    mid:=p[l+random(r-l+1)];
    repeat
        while p[i]<mid do inc(i);
        while p[j]>mid do dec(j);
        if i<=j then
            begin
            tmp:=p[i];
            p[i]:=p[j];
            p[j]:=tmp;
            inc(i);
            dec(j);
            end;
    until i>j;
    if i<r then Sort(i,r);
    if j>l then Sort(l,j);
end;

function find(x:longint):longint;
var l,r,mid,temp:longint;
begin
    l:=0;
    r:=1 shl(n-n div 2)-1;
    temp:=-1;
    repeat
        mid:=(l+r) div 2;
        if p[mid]<x then
            begin
            temp:=mid;
            l:=mid+1;
            end
        else
            r:=mid-1;
    until l>r;
    exit(temp);
end;

Procedure Xuli;
var s,k:longint;
begin
    Cre_State;
    sort(1,1 shl (n-n div 2)-1);
    for s:=0 to 1 shl (n div 2)-1 do
        begin
        {if f[s]=q then k:=find(q-1)
        else    }
            k:=find(q-f[s]);
        if k<>-1 then
            res:=max(res,f[s]+p[k]);
        end;
end;
begin
    Nhap;
    Xuli;
    write(res);
end.

Uses    math;

Var     n,m,kq: Longint;
        a,f1,f2,c: Array[0..10000005] Of Longint;

Procedure       Nhap;
Var     i: Longint;
Begin
Readln(n,m);
For i:=1 to n do
        Read(a[i]);
End;

Procedure       KhoiTao;
Var     s,i,mid,t: Longint;
Begin
mid:= n div 2;
For s:=1 to 1 shl mid -1 do
        Begin
        For i:=1 to mid do
                Begin
                t:=1 and (s shr (i-1));
                f1[s]:=f1[s]+t*a[i];
                f1[s]:=f1[s] mod m;
                End;
        c[s]:=s;
        End;
For s:=1 to 1 shl(n-mid)-1 do
        Begin
        For i:=1 to (n-mid) do
                Begin
                t:=1 and (s shr (i-1));
                f2[s]:=f2[s]+t*a[mid+i];
                f2[s]:=f2[s] mod m;
                End;
        End;
End;

Procedure       QuickSort(l,r:Longint);
Var     i,j,m,x,t: Longint;
Begin
i:=l; j:=r;
m:=l+random(r-l+1);
x:=f1[m];
Repeat
        While f1[i]<x Do Inc(i);
        While x<f1[j] Do Dec (j);
        If i<=j Then
                Begin
                t:=f1[i];
                f1[i]:=f1[j];
                f1[j]:=t;

                t:=c[i];
                c[i]:=c[j];
                c[j]:=t;

                Inc(i); Dec (j);
                End;
Until i>j;
If i<r Then QuickSort(i,r);
If j>l Then QuickSort(l,j);
End;

Function        Chat(x:Int64): Int64;
Var     l,r,mid,t: Longint;
Begin
l:=1;
r:=1 shl (n div 2);
t:=-1;
Repeat
        mid:=(l+r) div 2;
        If f1[mid]<x Then
                Begin
                t:=mid;
                l:=mid+1;
                End
        Else    r:=mid-1;
Until l>r;
Exit(t);
End;

Procedure       Xuly;
Var     mid,s,i: Longint;
Begin
If n=1 Then
        Begin
        kq:=a[n] mod m;
        Exit;
        End;
KhoiTao;
QuickSort(1,1 shl (n div 2));
mid:=n div 2;
kq:=0;
For s:=0 to 1 shl(n-mid)-1 do
        Begin
        i:=Chat(m-f2[s]);
        If i<>-1 Then kq:=max(kq,f1[i]+f2[s]);
        End;
End;

Procedure       Xuat;
Begin
Writeln(kq);
End;

Begin
Nhap;
XuLy;
Xuat;
End.

program Maximum_Subsequence;

const
   maxn = 35;
   half = 18;

var
   n, m: longint;
   a: array [1 .. maxn] of longint;

   left, right: longint;
   b, c: array [0 .. (1 shl half) - 1] of longint;

   i, j, ans: longint;

procedure process(sz, offs: longint; var x: array of longint);
var
   i, j, sum: longint;
begin
   for i := 0 to (1 shl sz) - 1 do begin
      sum := 0;
      for j := 0 to sz - 1 do
         if (i and (1 shl j)) > 0 then
            sum := (sum + a[offs + j]) mod m;
      x[i] := sum;
   end;
end;

procedure sort(var arr: array of longint; l, r: longint);
var
   m, t, i, j: longint;
begin
   m := arr[l + random(r - l + 1)];
   i := l;
   j := r;
   repeat
      while arr[i] < m do inc(i);
      while arr[j] > m do dec(j);
      if i <= j then begin
         t := arr[i]; arr[i] := arr[j]; arr[j] := t;
         inc(i); dec(j);
      end;
   until i > j;
   if j > l then sort(arr, l, j);
   if i < r then sort(arr, i, r);
end;

begin
   readln(n, m);
   for i := 1 to n do read(a[i]);

   left := n div 2;
   right := n - left;
   process(left, 1, b);
   process(right, left + 1, c);
   randomize;
   sort(b, 0, (1 shl left) - 1);
   sort(c, 0, (1 shl right) - 1);

   if c[0] = c[(1 shl right) - 1] then begin
      writeln(b[(1 shl left) - 1]);
      halt;
   end;

   j := 1;
   ans := 0;
   for i := 0 to (1 shl left) - 1 do begin
      while (b[i] + c[j]) mod m <= (b[i] + c[(j - 1 + (1 shl right)) mod (1 shl right)]) mod m do
         j := (j - 1 + (1 shl right)) mod (1 shl right);
      if ans < (b[i] + c[j]) mod m then
         ans := (b[i] + c[j]) mod m;
   end;

   writeln(ans);
end.

                   const eps=1e-10;
                    besk=4000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1000000+1] of int64;
var mask,step,i,j,k:longint;
num1,num2,num,sum,tt,xx,pos,x0,y0,x1,y1,q2,q1,sum1,sum2,izb1,izb2,t1,t2,m,n,l,dl,i1,j1,imin,pp,p1,p2,kol,ost,nn,modul,p,ot,pmin,tmax,minf,kk,gr1,gr2,ii,tt1,nnn,d,raz1,raz2,v,s,st,q,t,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
g,b1,a1:array[-1000..3000000] of int64;
yy,zz,bbbb,cccc:array[-10..100000] of int64;
 ss,ss1:string;
sumx,sumy,ott,da,dc,dn,d1,d2,aa,bb,cc,t3:extended;
r,z1,z2,z,x,y,dd:array[-1000..1000000] of int64;
ll,rr,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin srav:=a[i]<=a[j];  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function zapmin(ll,rr:longint):longint;
var t1,t2,ot:longint;
begin
  if ll=rr then zapmin:=z[ll] else
    begin
       if not odd(rr) then zapmin:=min(z[rr],zapmin(ll,rr-1));
       if  odd(ll) then zapmin:=min(z[ll],zapmin(ll+1,rr));
       if odd(rr) and not odd(ll) then zapmin:=zapmin(ll shr 1,rr shr 1);

    end;

end;

begin

 { assign(input,'input.txt');reset(input);
  assign(output,'output.txt');rewrite(output);
  }

  read(nn,modul);
  for i:=1 to nn do read(z[i]);

      t:=nn div 2;
      tt:=nn-t;
      p:=1; for i:=1 to t do p:=p*2;
      pp:=1; for i:=1 to tt do pp:=pp*2;

     for mask:=0 to p-1 do
       begin
          q:=mask;
          sum:=0;
          for i:=1 to t do begin  x[i]:=q and 1; q:=q shr 1;  end;
          for i:=1 to t do sum:=sum+x[i]*z[i];
          inc(num); y[num]:=sum mod modul;

       end;

      { for i:=1 to num do write(y[i],' ');
      } for i:=1 to num do a[i]:=y[i];
       n:=1; repeat n:=n*2 until(n>=num);
       for i:=1+num to n do a[i]:=besk;
       sort(a);
       for i:=1 to num do yy[i]:=a[i]; num1:=num;

      { writeln(num1); for i:=1 to num1 do write(yy[i],' '); writeln;
       }

            num:=0;
        for mask:=0 to pp-1 do
       begin
          q:=mask;
          sum:=0;
          for i:=1 to t do begin  x[i]:=q and 1; q:=q shr 1;  end;
          for i:=1 to t do sum:=sum+x[i]*z[nn-i+1];
          inc(num); y[num]:=sum mod modul;

       end;

      { for i:=1 to num do write(y[i],' ');
      } for i:=1 to num do a[i]:=y[i];
       n:=1; repeat n:=n*2 until(n>=num);
       for i:=1+num to n do a[i]:=besk;
       sort(a);
       for i:=1 to num do zz[i]:=a[i]; num2:=num;

     {   writeln(num2); for i:=1 to num2 do write(zz[i],' ');writeln;
      }
       pos:=num2;
       for i:=1 to num1 do
         begin
            if yy[i]+zz[pos]>=modul then
            repeat ot:=max(ot,(yy[i]+zz[pos]) mod modul); dec(pos);
                  {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul); }
             until (pos<=0)or(yy[i]+zz[pos]<modul ) else
              begin
                ot:=max(ot,(yy[i]+zz[pos]) mod modul);
              {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul);
             } end;

         end;

   writeln(ot);

 1: close (output);
end.

                   const eps=1e-10;
                    besk=4000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1000000+1] of int64;
var mask,step,i,j,k:longint;
num1,num2,num,sum,tt,xx,pos,x0,y0,x1,y1,q2,q1,sum1,sum2,izb1,izb2,t1,t2,m,n,l,dl,i1,j1,imin,pp,p1,p2,kol,ost,nn,modul,p,ot,pmin,tmax,minf,kk,gr1,gr2,ii,tt1,nnn,d,raz1,raz2,v,s,st,q,t,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
g,b1,a1:array[-1000..3000000] of int64;
yy,zz,bbbb,cccc:array[-10..100000] of int64;
 ss,ss1:string;
sumx,sumy,ott,da,dc,dn,d1,d2,aa,bb,cc,t3:extended;
r,z1,z2,z,x,y,dd:array[-1000..1000000] of int64;
ll,rr,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin srav:=a[i]<=a[j];  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function zapmin(ll,rr:longint):longint;
var t1,t2,ot:longint;
begin
  if ll=rr then zapmin:=z[ll] else
    begin
       if not odd(rr) then zapmin:=min(z[rr],zapmin(ll,rr-1));
       if  odd(ll) then zapmin:=min(z[ll],zapmin(ll+1,rr));
       if odd(rr) and not odd(ll) then zapmin:=zapmin(ll shr 1,rr shr 1);

    end;

end;

begin

 { assign(input,'input.txt');reset(input);
  assign(output,'output.txt');rewrite(output);
  }

  read(nn,modul);
  for i:=1 to nn do read(z[i]);

      t:=nn div 2;
      tt:=nn-t;
      p:=1; for i:=1 to t do p:=p*2;
      pp:=1; for i:=1 to tt do pp:=pp*2;

     for mask:=0 to p-1 do
       begin
          q:=mask;
          sum:=0;
          for i:=1 to t do begin  x[i]:=q and 1; q:=q shr 1;  end;
          for i:=1 to t do sum:=sum+x[i]*z[i];
          inc(num); y[num]:=sum mod modul;

       end;

      { for i:=1 to num do write(y[i],' ');
      } for i:=1 to num do a[i]:=y[i];
       n:=1; repeat n:=n*2 until(n>=num);
       for i:=1+num to n do a[i]:=besk;
       sort(a);
       for i:=1 to num do yy[i]:=a[i]; num1:=num;

      { writeln(num1); for i:=1 to num1 do write(yy[i],' '); writeln;
       }

            num:=0;
        for mask:=0 to pp-1 do
       begin
          q:=mask;
          sum:=0;
          for i:=1 to t do begin  x[i]:=q and 1; q:=q shr 1;  end;
          for i:=1 to t do sum:=sum+x[i]*z[nn-i+1];
          inc(num); y[num]:=sum mod modul;

       end;

      { for i:=1 to num do write(y[i],' ');
      } for i:=1 to num do a[i]:=y[i];
       n:=1; repeat n:=n*2 until(n>=num);
       for i:=1+num to n do a[i]:=besk;
       sort(a);
       for i:=1 to num do zz[i]:=a[i]; num2:=num;

     {   writeln(num2); for i:=1 to num2 do write(zz[i],' ');writeln;
      }
       pos:=num2;
       for i:=1 to num1 do
         begin
            if yy[i]+zz[pos]>=modul then
            repeat ot:=max(ot,(yy[i]+zz[pos]) mod modul); dec(pos);
                  {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul); }
             until (pos<=0)or(yy[i]+zz[pos]<modul ) else
              begin
                ot:=max(ot,(yy[i]+zz[pos]) mod modul);
              {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul);
             } end;

         end;

        pos:=num1;
       for i:=1 to num2 do
         begin
            if yy[i]+zz[pos]>=modul then
            repeat ot:=max(ot,(zz[i]+yy[pos]) mod modul); dec(pos);
                  {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul); }
             until (pos<=0)or(zz[i]+yy[pos]<modul ) else
              begin
                ot:=max(ot,(zz[i]+yy[pos]) mod modul);
              {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul);
             } end;

         end;

   writeln(ot);

 1: close (output);
end.

                   const eps=1e-10;
                    besk=4000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1000000+1] of int64;
var mask,step,i,j,k:longint;
num1,num2,num,sum,tt,xx,pos,x0,y0,x1,y1,q2,q1,sum1,sum2,izb1,izb2,t1,t2,m,n,l,dl,i1,j1,imin,pp,p1,p2,kol,ost,nn,modul,p,ot,pmin,tmax,minf,kk,gr1,gr2,ii,tt1,nnn,d,raz1,raz2,v,s,st,q,t,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
g,b1,a1:array[-1000..3000000] of int64;
yy,zz,bbbb,cccc:array[-10..100000] of int64;
 ss,ss1:string;
sumx,sumy,ott,da,dc,dn,d1,d2,aa,bb,cc,t3:extended;
r,z1,z2,z,x,y,dd:array[-1000..1000000] of int64;
ll,rr,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin srav:=a[i]<=a[j];  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function zapmin(ll,rr:longint):longint;
var t1,t2,ot:longint;
begin
  if ll=rr then zapmin:=z[ll] else
    begin
       if not odd(rr) then zapmin:=min(z[rr],zapmin(ll,rr-1));
       if  odd(ll) then zapmin:=min(z[ll],zapmin(ll+1,rr));
       if odd(rr) and not odd(ll) then zapmin:=zapmin(ll shr 1,rr shr 1);

    end;

end;

begin

 { assign(input,'input.txt');reset(input);
  assign(output,'output.txt');rewrite(output);
  }

  read(nn,modul);
  for i:=1 to nn do read(z[i]);

      t:=nn div 2;
      tt:=nn-t;
      p:=1; for i:=1 to t do p:=p*2;
      pp:=1; for i:=1 to tt do pp:=pp*2;

     for mask:=0 to p-1 do
       begin
          q:=mask;
          sum:=0;
          for i:=1 to t do begin  x[i]:=q and 1; q:=q shr 1;  end;
          for i:=1 to t do sum:=sum+x[i]*z[i];
          inc(num); y[num]:=sum mod modul;

       end;

      { for i:=1 to num do write(y[i],' ');
      } for i:=1 to num do a[i]:=y[i];
       n:=1; repeat n:=n*2 until(n>=num);
       for i:=1+num to n do a[i]:=besk;
       sort(a);
       for i:=1 to num do yy[i]:=a[i]; num1:=num;

      { writeln(num1); for i:=1 to num1 do write(yy[i],' '); writeln;
       }

            num:=0;
        for mask:=0 to pp-1 do
       begin
          q:=mask;
          sum:=0;
          for i:=1 to tt do begin  x[i]:=q and 1; q:=q shr 1;  end;
          for i:=1 to tt do sum:=sum+x[i]*z[nn-i+1];
          inc(num); y[num]:=sum mod modul;

       end;

      { for i:=1 to num do write(y[i],' ');
      } for i:=1 to num do a[i]:=y[i];
       n:=1; repeat n:=n*2 until(n>=num);
       for i:=1+num to n do a[i]:=besk;
       sort(a);
       for i:=1 to num do zz[i]:=a[i]; num2:=num;

       { writeln(num2); for i:=1 to num2 do write(zz[i],' ');writeln;
        }
       pos:=num2;
       for i:=1 to num1 do
         begin
            if yy[i]+zz[pos]>=modul then
            repeat ot:=max(ot,(yy[i]+zz[pos]) mod modul); dec(pos);
                  {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul);
                  } ot:=max(ot,(yy[i]+zz[pos]) mod modul);
             until (pos<=0)or(yy[i]+zz[pos]<modul ) else
              begin
                ot:=max(ot,(yy[i]+zz[pos]) mod modul);
              {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul);
             } end;

         end;

        pos:=num1;
       for i:=1 to num2 do
         begin
            if yy[i]+zz[pos]>=modul then
            repeat ot:=max(ot,(zz[i]+yy[pos]) mod modul); dec(pos);
                  {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul); }
             until (pos<=0)or(zz[i]+yy[pos]<modul ) else
              begin
                ot:=max(ot,(zz[i]+yy[pos]) mod modul);
              {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul);
             } end;

         end;

   writeln(ot);

 1: close (output);
end.

                   const eps=1e-10;
                    besk=4000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1000000+1] of int64;
var mask,step,i,j,k:longint;
num1,num2,num,sum,tt,xx,pos,x0,y0,x1,y1,q2,q1,sum1,sum2,izb1,izb2,t1,t2,m,n,l,dl,i1,j1,imin,pp,p1,p2,kol,ost,nn,modul,p,ot,pmin,tmax,minf,kk,gr1,gr2,ii,tt1,nnn,d,raz1,raz2,v,s,st,q,t,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
g,b1,a1:array[-1000..3000000] of int64;
yy,zz,bbbb,cccc:array[-10..100000] of int64;
 ss,ss1:string;
sumx,sumy,ott,da,dc,dn,d1,d2,aa,bb,cc,t3:extended;
r,z1,z2,z,x,y,dd:array[-1000..1000000] of int64;
ll,rr,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin srav:=a[i]<=a[j];  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function zapmin(ll,rr:longint):longint;
var t1,t2,ot:longint;
begin
  if ll=rr then zapmin:=z[ll] else
    begin
       if not odd(rr) then zapmin:=min(z[rr],zapmin(ll,rr-1));
       if  odd(ll) then zapmin:=min(z[ll],zapmin(ll+1,rr));
       if odd(rr) and not odd(ll) then zapmin:=zapmin(ll shr 1,rr shr 1);

    end;

end;

begin

 { assign(input,'input.txt');reset(input);
  assign(output,'output.txt');rewrite(output);
  }

  read(nn,modul);
  for i:=1 to nn do read(z[i]);

      t:=nn div 2;
      tt:=nn-t;
      p:=1; for i:=1 to t do p:=p*2;
      pp:=1; for i:=1 to tt do pp:=pp*2;

     for mask:=0 to p-1 do
       begin
          q:=mask;
          sum:=0;
          for i:=1 to t do begin  x[i]:=q and 1; q:=q shr 1;  end;
          for i:=1 to t do sum:=sum+x[i]*z[i];
          inc(num); y[num]:=sum mod modul;

       end;

      { for i:=1 to num do write(y[i],' ');
      } for i:=1 to num do a[i]:=y[i];
       n:=1; repeat n:=n*2 until(n>=num);
       for i:=1+num to n do a[i]:=besk;
       sort(a);
       for i:=1 to num do yy[i]:=a[i]; num1:=num;

      { writeln(num1); for i:=1 to num1 do write(yy[i],' '); writeln;
       }

            num:=0;
        for mask:=0 to pp-1 do
       begin
          q:=mask;
          sum:=0;
          for i:=1 to tt do begin  x[i]:=q and 1; q:=q shr 1;  end;
          for i:=1 to tt do sum:=sum+x[i]*z[nn-i+1];
          inc(num); y[num]:=sum mod modul;

       end;

      { for i:=1 to num do write(y[i],' ');
      } for i:=1 to num do a[i]:=y[i];
       n:=1; repeat n:=n*2 until(n>=num);
       for i:=1+num to n do a[i]:=besk;
       sort(a);
       for i:=1 to num do zz[i]:=a[i]; num2:=num;

       { writeln(num2); for i:=1 to num2 do write(zz[i],' ');writeln;
        }
       pos:=num2;
       for i:=1 to num1 do
         begin
            if yy[i]+zz[pos]>=modul then
            repeat ot:=max(ot,(yy[i]+zz[pos]) mod modul); dec(pos);
                  {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul); }
             until (pos<=0)or(yy[i]+zz[pos]<modul ) else
              begin
                ot:=max(ot,(yy[i]+zz[pos]) mod modul);
              {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul);
             } end;

         end;

        pos:=num1;
       for i:=1 to num2 do
         begin
            if yy[i]+zz[pos]>=modul then
            repeat ot:=max(ot,(zz[i]+yy[pos]) mod modul); dec(pos);
                  {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul); }
             until (pos<=0)or(zz[i]+yy[pos]<modul ) else
              begin
                ot:=max(ot,(zz[i]+yy[pos]) mod modul);
              {  writeln('i= ',i,' pos= ',pos,'  sum= ',(yy[i]+zz[pos]) mod modul);
             } end;

         end;

   writeln(ot);

 1: close (output);
end.

const
    maxn=40;
var
    n,k,n1,m:longint;
    a,x:array[0..maxn] of longint;
    s1:array[0..1000005] of int64;
    kq:int64;

procedure enter;
var i:longint;
    begin
    readln(n,m);
    for i:=1 to n do
        read(a[i]);
    k:=(n+1) div 2;
    if n=1 then
        begin
        write(a[1] mod m);
        halt;
        end;
    end;

procedure swap(var a,b:int64);
var c:int64;
    begin
    c:=a;
    a:=b;
    b:=c;
    end;

procedure sort(l,r:longint);
var i,j:longint;
    mid:int64;
    begin
    i:=l; j:=r;
    mid:=s1[l+random(r-l+1)];
    repeat
        while s1[i]<mid do inc(i);
        while s1[j]>mid do dec(j);
        if i<=j then
            begin
            swap(s1[i],s1[j]);
            inc(i);
            dec(j);
            end;
    until i>j;
    end;

procedure ghinghiem;
var i:longint;
    s:int64;
    begin
    s:=0;
    for i:=1 to k do
        if x[i]=1 then
            inc(s,a[i]);
    inc(n1);
    s1[n1]:=s mod m;
    end;

procedure try1(i:longint);
var j:longint;
    begin
    for j:=0 to 1 do
        begin
        x[i]:=j;
        if i=k then ghinghiem
            else try1(i+1);
        end;
    end;

function find(i,j:longint; val:int64):longint;
var l,r,mid:longint;
    begin
    l:=i; r:=j;
    while l<=r do
        begin
        mid:=l+random(r-l+1);
        if s1[mid]<=val then
            if (mid=n1) or (s1[mid+1]>val) then exit(mid);
        if s1[mid]<=val then
            l:=mid+1 else
                r:=mid-1;
        end;
    exit(-1);
    end;

function max(a,b:int64):int64;
    begin
    if a>b then exit(a);
    exit(b);
    end;

procedure timnghiem;
var i,v:longint;
    s:int64;
    begin
    s:=0;
    for i:=k+1 to n do
        if x[i]=1 then
            inc(s,a[i]);
    s:=s mod m;
    v:=find(1,n1,m-1-s);
    if v=-1 then exit;
    kq:=max(kq,s+s1[v]);
    end;

procedure try2(i:longint);
var j:longint;
    begin
    for j:=0 to 1 do
        begin
        x[i]:=j;
        if i=n then timnghiem
            else try2(i+1);
        end;
    end;

procedure process;
    begin
    try1(1);
    sort(1,n1);
    try2(k+1);
    write(kq);
    end;

begin
    enter;
    process;
end.

var n,nn,mm:longint;
cnt:longint;
m:int64;
a,x:array[0..40] of int64;
f:array[0..1000005] of int64;
res:int64;
procedure       mo;
begin
        assign(input,'test.inp');reset(input);
        assign(output,'test.out');rewrite(output);
end;
procedure       dong;
begin
        close(input);close(output);
end;
procedure       nhap;
var i:longint;
begin
        readln(n,m);
        for i:=1 to n do
                begin
                read(a[i]);
                a[i]:=a[i] mod m;
                end;
        nn:=(n+1) div 2;
        mm:=nn+1;
end;
procedure       luunghiem;
var i:longint;
begin
        inc(cnt);
        for i:=1 to nn do
                begin
                if x[i]=1 then f[cnt]:=(f[cnt]+a[i]) mod m;
                end;
end;
procedure       vet1(i:longint);
var j:longint;
begin
        for j:=0 to 1 do
                begin
                x[i]:=j;
                if i=nn then luunghiem else vet1(i+1);
                end;
end;
procedure       swap(var x,y:int64);
var t:int64;
begin
        t:=x;
        x:=y;
        y:=t;
end;
procedure       qs(l,r:longint);
var i:longint;                 j,mid:longint;
begin
        i:=l;
        j:=r;
        mid:=f[l+random(r-l+1)];
        repeat
                while f[i]<mid do inc(i);
                while f[j]>mid do dec(J);
                if not(I>j) then
                        begin
                        swap(f[i],f[j]);
                        inc(i);
                        dec(j);
                        end;
        until I>j;
        if i<r then qs(i,r);
        if l<j then qs(l,j);
end;
function        find(l,r:longint;x:int64):int64;
var mid:longint;
begin
        repeat
                mid:=(l+r) div 2;
                if (f[mid]<x) and (f[mid+1]>=x) then exit(f[mid]);
                if (f[mid]>=x) then r:=mid-1;
                if (f[mid]<x) and (f[mid+1]<x) then l:=mid+1;
        until l>r;
        exit(0);
end;
procedure       xulinghiem;
var i:longint;s:int64;   tam:int64;
begin
        s:=0;
        for i:=mm to n do
                begin
                if x[i]=1 then s:=(s+a[i]) mod m;
                end;
        tam:=find(1,cnt,m-s);
        if s+tam>res then res:=s+tam;
end;
procedure       vet2(i:longint);
var j:longint;
begin
        for j:=0 to 1 do
                begin
                x[i]:=j;
                if i=n then xulinghiem else vet2(i+1);
                end;
end;
procedure       xuli;
var i:longint;
begin
        vet1(1);
        qs(1,cnt);
        vet2(mm);
        writeln(res);
end;
begin
      //  mo;
        nhap;
        xuli;
    //    dong;
end.

var n,nn,mm:longint;
cnt:longint;
m:int64;
a,x:array[0..40] of int64;
f:array[0..1000005] of int64;
res:int64;
procedure       mo;
begin
        assign(input,'test.inp');reset(input);
        assign(output,'test.out');rewrite(output);
end;
procedure       dong;
begin
        close(input);close(output);
end;
procedure       nhap;
var i:longint;
begin
        readln(n,m);
        for i:=1 to n do
                begin
                read(a[i]);
                a[i]:=a[i] mod m;
                end;
        nn:=(n+1) div 2;
        mm:=nn+1;
end;
procedure       luunghiem;
var i:longint;
begin
        inc(cnt);
        for i:=1 to nn do
                begin
                if x[i]=1 then f[cnt]:=(f[cnt]+a[i]) mod m;
                end;
end;
procedure       vet1(i:longint);
var j:longint;
begin
        for j:=0 to 1 do
                begin
                x[i]:=j;
                if i=nn then luunghiem else vet1(i+1);
                end;
end;
procedure       swap(var x,y:int64);
var t:int64;
begin
        t:=x;
        x:=y;
        y:=t;
end;
procedure       qs(l,r:longint);
var i:longint;                 j,mid:longint;
begin
        i:=l;
        j:=r;
        mid:=f[l+random(r-l+1)];
        repeat
                while f[i]<mid do inc(i);
                while f[j]>mid do dec(J);
                if not(I>j) then
                        begin
                        swap(f[i],f[j]);
                        inc(i);
                        dec(j);
                        end;
        until I>j;
        if i<r then qs(i,r);
        if l<j then qs(l,j);
end;
function        find(l,r:longint;x:int64):int64;
var mid:longint;
begin
        repeat
                mid:=(l+r) div 2;
                if (f[mid]<=x) and (f[mid+1]>x) then exit(f[mid]);
                if (f[mid]>x) then r:=mid-1;
                if (f[mid]<=x) and (f[mid+1]<=x) then l:=mid+1;
        until l>r;
        exit(0);
end;
procedure       xulinghiem;
var i:longint;s:int64;   tam:int64;
begin
        s:=0;
        for i:=mm to n do
                begin
                if x[i]=1 then s:=(s+a[i]) mod m;
                end;
        tam:=find(1,cnt,m-s-1);
        if s+tam>res then res:=s+tam;
end;
procedure       vet2(i:longint);
var j:longint;
begin
        for j:=0 to 1 do
                begin
                x[i]:=j;
                if i=n then xulinghiem else vet2(i+1);
                end;
end;
procedure       xuli;
var i:longint;
begin
        vet1(1);
        qs(1,cnt);
        vet2(mm);
        writeln(res);
end;
begin
       // mo;
        nhap;
        xuli;
        //dong;
end.

uses math;
const fi='888E.inp';
        fo='888E.out';
var a,f:array[0..1000000] of longint;
        n,du,nn,dem,kq:longint;
        s:int64;
procedure ran;
        var i:longint;
        begin
                readln(n,du);
                for i:=1 to n do read(a[i]);
                nn:=n div 2;
        end;
procedure haibara;
        begin
                inc(dem);
                f[dem]:=s mod du;
        end;
procedure conan(i:longint);
        var j:longint;
        begin
                for j:=0 to 1 do
                        begin
                        if j=1 then s:=s+a[j];
                        if i=nn then haibara else conan(i+1);
                        if j=1 then s:=s-a[j];
                        end;
        end;
function tnp(l,r,x:longint):longint;
        var g,k:longint;
        begin
                while l<=r do
                        begin
                        g:=(l+r) div 2;
                        if f[g] > x then r:=g-1 else
                                begin
                                k:=f[g];
                                l:=g+1;
                                end;
                        end;
                exit(k);
        end;

procedure ai;
        var j,t:longint;
        begin
                t:=s mod du;
                kq:=max(kq,t+tnp(1,dem,du-1-t));
        end;
procedure tm(i:longint);
        var j:longint;
        begin
                for j:=0 to 1 do
                        begin
                        if j=1 then s:=s+a[j];
                        if i=n then ai else tm(i+1);
                        if j=1 then s:=s-a[j];
                        end;
        end;
 procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=f[(l+r) div 2];
         repeat
           while f[i]<x do
            inc(i);
           while x<f[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=f[i];
                f[i]:=f[j];
                f[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;

begin

        ran;
        dem:=0;
        s:=0;
        conan(1);
        sort(1,dem);
        s:=0;
        kq:=0;
        tm(nn+1);
        writeln(kq);
end.

var stk:array[0..200009,0..1] of longint;
    a,top:array[0..200009] of longint;
    ans,res,l,r,mid,n,m,i,du,kq:longint;

function max(a,b:longint):longint;
    begin
        if a>b then exit(a) else exit(b);
    end;

procedure vet(i,n,k:longint);
    var j:longint;
        begin
            if i=n+1 then
                begin
                    inc(top[k]);
                    stk[top[k],k]:=ans mod du;
                    exit;
                end;
            for j:=0 to 1 do
                begin
                    ans:=ans+a[i]*j;
                    vet(i+1,n,k);
                    ans:=ans-a[i]*j;
                end;
        end;

procedure sort(l,r,k:longint);
    var i,j,m,t,tam:longint;
        begin
            i:=l;
            j:=r;
            m:=random(r-l)+l+1;
            t:=stk[m,k];
            repeat
                while t>stk[i,k] do inc(i);
                while t<stk[j,k] do dec(j);
                if not (i>j) then
                    begin
                        tam:=stk[i,k];
                        stk[i,k]:=stk[j,k];
                        stk[j,k]:=tam;
                        inc(i);
                        dec(j);
                    end;
            until i>j;
                if l<j then sort(l,j,k);
                if i<r then sort(i,r,k);
        end;
begin
readln(n,du);
for i:=1 to n do
    read(a[i]);
vet(1,n div 2,0);
vet(n div 2+1,n,1);
sort(1,top[0],0);
sort(1,top[1],1);
for i:=1 to top[0] do
    begin
        ans:=du-stk[i,0]-1;
        l:=1;
        r:=top[1];
        res:=-1;
        while l<=r do
            begin
                mid:=(l+r) div 2;
                if stk[mid,1]>ans then r:=mid-1 else
                    begin
                        res:=stk[mid,1];
                        l:=mid+1;
                    end;
            end;
        if res=-1 then continue;
        kq:=max(kq,res+stk[i,0]);
    end;
writeln(kq);
end.

var stk:array[0..200009,0..1] of longint;
    a,top:array[0..200009] of longint;
    res,l,r,mid,n,m,i,du,kq:longint;
    ans:int64;

function max(a,b:longint):longint;
    begin
        if a>b then exit(a) else exit(b);
    end;

procedure vet(i,n,k:longint);
    var j:longint;
        begin
            if i=n+1 then
                begin
                    inc(top[k]);
                    stk[top[k],k]:=ans mod du;
                    exit;
                end;
            for j:=0 to 1 do
                begin
                    ans:=ans+a[i]*j;
                    vet(i+1,n,k);
                    ans:=ans-a[i]*j;
                end;
        end;

procedure sort(l,r,k:longint);
    var i,j,m,t,tam:longint;
        begin
            i:=l;
            j:=r;
            m:=random(r-l)+l+1;
            t:=stk[m,k];
            repeat
                while t>stk[i,k] do inc(i);
                while t<stk[j,k] do dec(j);
                if not (i>j) then
                    begin
                        tam:=stk[i,k];
                        stk[i,k]:=stk[j,k];
                        stk[j,k]:=tam;
                        inc(i);
                        dec(j);
                    end;
            until i>j;
                if l<j then sort(l,j,k);
                if i<r then sort(i,r,k);
        end;
begin
readln(n,du);
for i:=1 to n do
    read(a[i]);
vet(1,n div 2,0);
vet(n div 2+1,n,1);
sort(1,top[0],0);
sort(1,top[1],1);
for i:=1 to top[0] do
    begin
        ans:=du-stk[i,0]-1;
        l:=1;
        r:=top[1];
        res:=-1;
        while l<=r do
            begin
                mid:=(l+r) div 2;
                if stk[mid,1]>ans then r:=mid-1 else
                    begin
                        res:=stk[mid,1];
                        l:=mid+1;
                    end;
            end;
        if res=-1 then continue;
        kq:=max(kq,res+stk[i,0]);
    end;
writeln(kq);
end.

Program _888_E;
uses    math;
const   finput='888_E.inp';
        foutput='888_E.out';
        MaxN=10000000;
var     a,f,p:array[0..MaXN] of longint;
        n,q,res:longint;

Procedure Nhap;
var i:longint;
begin
  //  assign(input,finput);reset(input);
 //   assign(output,foutput);rewrite(output);
    read(n,q);
    for i:=1 to n do
        read(a[i]);
end;

Function getbit(x,i:longint):longint;
begin
    exit(1 and (x shr (i-1)));
end;

Procedure Cre_state;
var s,j:longint;
begin
    for s:=0 to 1 shl (n div 2)-1 do
        begin
        for j:=1 to n div 2 do
            if getbit(s,j)=1 then
                f[s]:=f[s]+a[j];
        f[s]:=f[s] mod q;
        end;
    for s:=0 to 1 shl (n-(n div 2))-1 do
        begin
        for j:=1 to n-(n div 2) do
            if getbit(s,j)=1 then
                p[s]:=p[s]+a[j+n div 2];
        p[s]:=p[s] mod q;
        end;
end;

Procedure Sort(l,r:longint);
var i,j,mid,tmp:longint;
begin
    i:=l;
    j:=r;
    mid:=p[l+random(r-l+1)];
    repeat
        while p[i]<mid do inc(i);
        while p[j]>mid do dec(j);
        if i<=j then
            begin
            tmp:=p[i];
            p[i]:=p[j];
            p[j]:=tmp;
            inc(i);
            dec(j);
            end;
    until i>j;
    if i<r then Sort(i,r);
    if j>l then Sort(l,j);
end;

function find(x:longint):longint;
var l,r,mid,temp:longint;
begin
    l:=0;
    r:=1 shl(n-n div 2)-1;
    temp:=-1;
    repeat
        mid:=(l+r) div 2;
        if p[mid]<x then
            begin
            temp:=mid;
            l:=mid+1;
            end
        else
            r:=mid-1;
    until l>r;
    exit(temp);
end;

Procedure Xuli;
var s,k:longint;
begin
    Cre_State;
    sort(1,1 shl (n-n div 2)-1);
    for s:=0 to 1 shl (n div 2)-1 do
        begin
        {if f[s]=q then k:=find(q-1)
        else    }
            k:=find(q-f[s]);
        if k<>-1 then
            res:=max(res,f[s]+p[k]);
        end;
end;
begin
    Nhap;
    Xuli;
    write(res);
end.


This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations.After the qualifying round completes, you know K of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round.

The first line of input contains K (1 ≤ K ≤ 25), the number of onsite finalists you know. The second line of input contains r1, r2, ..., rK (1 ≤ ri ≤ 106), the qualifying ranks of the finalists you know. All these ranks are distinct.

Print the minimum possible number of contestants that declined the invitation to compete onsite.

NoteIn the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3.

var
	n, h, m, r, x, sum, y: integer;
	a: array of integer;

begin

	readln(n);
	SetLength(a, n);

	for var i := 0 to n - 1 do
	begin
		read(a[i]);
	end;

	Sort(a);
	if (a[a.length-1] <= 25) then
		writeln(0)
	else
		writeln(a[a.length-1] - 25);

end.

Var
    K, max, num: UInt64;

Begin
    Read(K);
    For Var i := 1 to K do Begin
        Read(num);
        If num > max then
            max := num
    End;
    If max <= 25 then
        Write(0)
    Else
        Write(max - 25)
End.

program final;
var i,j,k,a,o,s:Integer;
    r:array[1..25] of Integer;
begin
  readln(k);
  for i:=1 to k do
    read(r[i]);
  o:=1;
  for j:=1 to k-1 do
    for i:=1 to k-1 do
      while r[i]>r[i+1] do
        begin
          a:=r[i];
          r[i]:=r[i+1];
          r[i+1]:=a;
        end;
  for i:=1 to k do
    if r[k]>25 then
     a:=i
    else
     a:=0;
  if a>0 then writeln(r[k]-25);
  if a<=0 then writeln(0);
end.

   const eps=0.0000000001;    nn=200000;
   label 1,2;
    type   { real=double;}  {string=ansistring;}
    mas=array [0..nn] of longint;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..nn] of longint;mass1=^mass;
    var t,tt,p,time,pp,jj,gr,qq,z,pmax,imax,p1,p2,p3,p4,l,ot,nm,n,s1,s2,m,s,smin,cen,dl,t2,i1:int64;
    step, k,i,j:longint;
     aa,bb,cc:int64;
     aold,b,a,x,y:array[-10..2000000] of int64;
     dda:array[-10..1200,-10..1200] of int64;
   zanx,zany:array[-10..200000] of boolean;
    sss, ss1,ss2:string;
     fl:array[0..200] of boolean;
    ss:string;ch:char;
    pole :array [-10..2000,-10..2000] of char;
    maxpr:array[0..nn] of string;
    st2:array[0..nn] of string;
     v0,v1,s0,t0:real;
     zv:point;
     newx,newy,xx,yy:array[-1..200000] of int64;

     yot:double;
       flag,flag1:boolean;
    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p/pi*180;
 end;
  function min(x,y:int64):int64;begin min:=x;if y<x then min:=y; end;
  function max(x,y:int64):int64;begin max:=x;if y>x then max:=y; end;

  function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

{function degg(a,k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=degg(a,k-1)*a mod modul else
   begin  p:=degg(a,k div 2); degg:=p*p mod modul;   end;

end;
 }

begin
   { assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
    }
   read(n);  for i:=1 to n do read(a[i]);
   ot:=0;
   for i:=1 to n do ot:=max(ot,a[i]);
   p:=ot-25;
   writeln(max(p,0));

   1:          close(output);
end.

var n,i,max,s:longint;
begin
  read(n);
  for i:=1 to n do
  begin
    read(s);
    if s>max then max:=s;
  end;
  if max>25 then writeln(max-25) else writeln('0');
end.

var
k,max,nol,i:integer;
r:array[1..1000000]of integer;
begin
readln(k);
max:=0;
nol:=0;
for i:=1 to k do
begin
read(r[i]);
if max<r[i] then max:=r[i];
end;
if max<26 then writeln(nol)
else
writeln(max-25);
end.

var
 max,a,n,i:longint;
begin
 readln(n);
 for i:=1 to n do
  begin
   read(a);
   if a>max then max:=a;
  end;
 if max-25>=0 then write(max-25)
  else write(0);
end.

var
  k,i,r,max:longint;
begin
  readln(k);
  for i:=1 to k do
  begin
  read(r);
  if r>max then max:=r;
  end;
  if max<25 then max:=25;
  writeln(max-25);
  end.

  //Fredericksburg

var
  i,n,max,x:longint;
begin
  readln(n);
  for i:=1 to n do
    begin
      read(x);
      if x>max then max:=x;
    end;
  if max<25 then write(0) else write(max-25);
end.

uses math;

var i, k, r, ans: longint;

begin
  readln(k);
  ans := 25;
  for i := 1 to k do
  begin
    read(r);
    ans := max(ans, r);
  end;
  writeln(ans - 25);
end.

var
k,t,i,r:longint;
begin
readln(k); i:=0;
for t:=1 to k do
begin read(r);
if r>i then
i:=r; end;
if i<=25 then write('0')
else write(i-25); end.

var
 i,n,max:longint;
 a:array[1..1000000] of longint;
begin
 readln(n);
 for i:=1 to n do read(a[i]);
 max:=a[1];
 for i:=2 to n do if a[i]>max then
  max:=a[i];
 if max<25 then write(0)
  else write(max-25);
end.

var
 n,i,x,max:longint;
begin
 readln(n);
 for i:=1 to n do
  begin
   read(x);
   if x>max then max:=x;
  end;
 if max>25 then writeln(max-25)
           else writeln(0);
end.

var
    n,i,a,max:longint;
begin
    read(n);
    max:=0;
    for i:=1 to n do
    begin
        read(a);
        if max<a then max:=a;
    end;
    if max>25 then writeln(max-25)
    else writeln(0);
end.

var n,i,q,max:longint;
begin
readln(n);
for i:=1 to n do
  begin
  read(q);
  if q>max then max:=q;
  end;
if max<25 then max:=25;
writeln(max-25);
end.

var k,x,m:longint;
begin
  readln(k);
  for k:=1 to k do
  begin
    read(x);
    if x>m then m:=x;
  end;
  if m<25 then
    writeln(0)
  else
    writeln(m-25);
end.

// luogu-judger-enable-o2
var n,x,m,i:longint;

function max(a,b:longint):longint;
begin
  if a>b then exit(a) else exit(b);
end;

begin
  readln(n);
  for i:=1 to n do
  begin
    read(x);
    m:=max(x,m);
  end;
  writeln(max(0,m-25));
end.

var
 n,max,i,x:longint;
begin
 readln(n);
 max:=-maxlongint;
 for i:=1 to n do begin read(x);if x>max then max:=x; end;
 if max<25 then begin writeln(0);halt; end;
 writeln(max-25);
end.

var
  k,i,r,max: longint;
begin
  readln(k);
  for i:=1 to k do
  begin
  read(r);
  if r>max then max:=r;
  end;
  if max<25 then max:=25;
  writeln(max-25);
  end.

var
  k,i,r,max:longint;
begin
  readln(k);
  for i:=1 to k do
  begin
  read(r);
  if r>max then max:=r;
  end;
  if max<25 then write(0)
            else write(max-25);
end.

var n,o,i,max:longint;
begin
readln(n);
for i:=1 to n do
begin
read(o);
if o>max then max:=o;
end;
if max>25 then writeln(max-25)
else writeln(0);
end.

uses math;
	var n,i,l,m,x,j,kq,o: longint; a: array[1..1010] of longint;
	procedure sort(i,j: longint);
		var l,m,y: longint;
		begin
		l:=i;
		j:=m;
		x:=a[(l+j) div 2];
		repeat
		while a[i]<x do inc(i);
		while a[i]>x do dec(j);
		if i<j then
			begin
			y:=a[i]; a[i]:=a[j]; a[j]:=y;
			inc(i);
			dec(j);
			end;
		until i>j;
		                begin
		                if i<j then sort(i,j);
		                if m>l then sort(l,m);
		                end;
                  end;
	begin
		read(n);
		for i:=1 to n do begin
		read(o);
		kq:=max(kq, o-25);
		end;
		writeln(kq);

	end.

uses math; var  n,i,kq,o: integer; begin read(n); for i:=1 to n do begin read(o); kq:=max(kq,o-25); end;
write(kq);
end.

var n,i,m,c:longint;
Begin
    readln(n);
    for i:=1 to n do
    Begin
        read(c);if(c>m) then m:=c;
    end;
    if(m<25) then writeln(0) else writeln(m-25);
end.

var k,i,max:longint;
    a:array[1..25] of longint;

begin
//assign(input,'a.inp');reset(input);
//assign(output,'a.out');rewrite(output);
readln(k);
max:=0;
for i:=1 to k do read(a[i]);
for i:=1 to k do
   IF a[i]>max then max:=a[i];
IF max-25<0 then write(0) else write(max-25);
readln;
end.

var
i:longint;
max,x,kol,ans,n,d:int64;
a:array[-100..1000000]of int64;
begin
readln(n);

for i:=1 to n do begin
    read(x);
    a[x]:=1;
    if x>max then max:=x;
end;
kol:=25-n;
for i:=1 to max  do begin
if a[i]=0 then begin
    if kol>0 then dec(kol)
    else
    inc(ans);
end;
end;
writeln(ans);
end.

var n,k,i,max: longint;
begin
 readln(n);
 max:=0;
 for i:= 1 to n do begin
  read(k);
  if k>max then max:=k;
 end;
 if max<=25 then write(0) else write(max-25);
end.

 var n,i,m:longint;
    a:array[1..25] of longint;

begin
readln(n);
m:=0;
for i:=1 to n do
    begin
    read(a[i]);
    IF a[i]>m then m:=a[i];
    end;
m:=m-25;
IF m<0 then write(0) else write(m);
readln;
end.

// luogu-judger-enable-o2
var
  k,i,r,max:longint;
begin
  readln(k);
  for i:=1 to k do
   begin
    read(r);
    if r>max then max:=r;
   end;
  readln;
  if max<25 then max:=25;
  writeln(max-25);
 end.
{
I AK IOI!!!
}

//abcdefghijklmnopqrstuvwxyz
var
a,c,i,n:longint;
begin
readln(n);
for i:=1 to n do
  begin
  read(a);
  if a>C then c:=a;
  end;
if c>25
  then writeln(c-25)
  else writeln(0);
end.

var
        i,k:byte;

        a:array [1..25] of longint;

procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;

Begin
        Readln(k);
        For i:= 1 to k do
                read(a[i]);
        Sort(1,k);
        if a[k] > 25 then writeln(a[k] -25)
                else Writeln(0);
end.

var n,a,max:int64;
    i:cardinal;
begin
        readln(n);
        max:=0;
        for i:=1 to n do
        begin
                read(a);
                if a>max then max:=a;
        end;
        if max-25>0 then write(max-25)
        else write(0);
end.

var a:array[1..1000000] of longint;
i,n,x,b,s,k,max:longint;
begin
read(n);
max:=0;
for i:=1 to n do begin
read(x);
a[x]:=1;
if x>max then max:=x;
if x>25 then k:=1;
end;
if k=0 then begin writeln('0'); halt; end else
for i:=1 to max do
if a[i]=0 then inc(s);
writeln(s-25+n);
end.

var
a:array[1..1000000]of integer;
i,j,n,t:integer;
begin
read(n);
for i:=1 to n do read(a[i]);
for j:=1 to n-1 do
for i:=1 to n-j do
if a[i] > a[i+1] then
begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
end;

if a[n]>25 then
write(a[n]-25)
else write(0);
end.

{$mode objfpc}
uses math;

var
  n,o,i,kq:integer;

begin
  read(n);
  for i:=1 to n do
    begin
      read(o);
      kq:=max(kq,o-25);
    end;
  write(kq);
end.

var
 max,a,n,i:longint;
begin
 readln(n);
 for i:=1 to n do
  begin
   read(a);
   if a>max then max:=a;
  end;
 if max>25 then write(max-25)
  else write(0);
end.

var
n,i,x,max:longint;
begin
readln(n);
max:=-maxlongint;
for i:=1 to n do
  begin
    read(x);
    if x>max then max:=x;
  end;
if max>25 then writeln(max-25)
          else writeln(0);
end.

var
 n,i,x,y:longint;
begin
 readln(n);
 for i:=1 to n do
  begin
   read(x);
   if x>y then y:=x;
  end;
 if y-25<0 then writeln(0)
  else writeln(y-25);
end.

var
n,a,max,i:longint;
begin
readln(n);
for i:=1 to n do
begin
read(a);
if a>max then max:=a;
end;
 if max-25>0 then write(max-25)
             else write(0);
             end.

var
  n,max,i,x:longint;
begin
  readln(n);
  max:=-maxlongint;
  for i:=1 to n do begin read(x);if x>max then max:=x;end;
  if max<25 then begin writeln(0);halt;end;
  writeln(max-25);
end.

Program CHUNGKET;
Const fin ='';
      fout='';
Var i,n,a,d:Longint;
    f:Text;
Begin
  Assign(f,fin);
  Reset(f);
  Readln(f,n);
  d:=0;
  For i:=1 to n do
    Begin
      Read(f,a);
      If d<a then d:=a;
    End;
  Close(f);
  Assign(f,fout);
  ReWrite(f);
  If d>=25 then d:=d-25
  Else d:=0;
  Write(f,d);
  Close(f);
End.

Var i , max , n , tmp : Longint;
Begin
Readln(n);
For i := 1 to n do
    Begin
    Read(tmp);
    If tmp > max then max := tmp;
    End;
If max <= 25 then Writeln('0') else Writeln(max - 25);
End.

Program z1;
var k,i,j:integer;
    r:array[1..25]of longint;
begin
readln(k);
for i:=1 to k do read(r[i]);
j:=r[1];
for i:=2 to k do
if r[i]>j then j:=r[i];
if j>25 then j:=j-25
        else j:=0;
write(j);
end.

var
a:array[1..25]of integer;
k,i,max,v:integer;

begin
read(k);
for i:=1 to k do
read(a[i]);
for i:=1 to k do
if max<a[i] then
max:=a[i];
if max-25>=0 then
v:=max-25
else
v:=0;
write(v);
end.

var
  n,i,x,max:longint;
begin
  readln(n);
  for i:=1 to n do
  begin
    read(x);
    if x>max then max:=x;
  end;
  if max<25 then writeln(0)else
                 writeln(max-25);
end.

uses math;
type
 qtr=-2147483648..2147483647;
var
 i,n,rui,shg:qtr;
begin
 readln(n);
 for i:=1 to n do
  begin
   read(rui);
   shg:=max(rui,shg);
  end;
  writeln(max(shg-25,0));
end.

var n,o,i,max:longint;
begin
readln(n);
for i:=1 to n do
begin
readln(o);
if o>max then max:=o;
end;
if max>25 then writeln(max-25)
else writeln(0);
end.

uses math;
	var n,i,l,m,x,j,kq,o: longint; a: array[1..1010] of longint;
	procedure sort(i,j: longint);
		var l,m,y: longint;
		begin
		l:=i;
		j:=m;
		x:=a[(l+j) div 2];
		repeat
		while a[i]<x do inc(i);
		while a[i]>x do dec(j);
		if i<j then
			begin
			y:=a[i]; a[i]:=a[j]; a[j]:=y;
			inc(i);
			dec(j);
			end;
		until i>j;
		                begin
		                if i<j then sort(i,j);
		                if m>l then sort(l,m);
		                end;
                  end;
	begin
		read(n);
		for i:=1 to n do
		read(o);
		kq:=max(kq, o-25);
		writeln(kq);

	end.

	uses math;
	var n,i,l,m,x,j,kq,o: longint; a: array[1..1010] of longint;
	procedure sort(i,j: integer);
		var l,m,y: integer;
		begin
		l:=i;
		j:=m;
		x:=a[(l+j) div 2];
		repeat
		while a[i]<x do inc(i);
		while a[i]>x do dec(j);
		if i<j then
			begin
			y:=a[i]; a[i]:=a[j]; a[j]:=y;
			inc(i);
			dec(j);
			end;
		until i>j;
		                begin
		                if i<j then sort(i,j);
		                if m>l then sort(l,m);
		                end;
                  end;
	begin
		read(n);
		for i:=1 to n do
		read(o);
		kq:=max(kq, o-25);

	end.

uses math;
var
n,i,kq,o: integer;
begin
read(n);
for i:=1 to n do
    begin
    read(o);
    kq:=max(o,o-25);
    end;
    write(kq);
end.

	uses math;
	var n,i,l,m,x,j,kq,o: longint; a: array[1..1010] of longint;
	procedure sort(i,j: integer);
		var l,m,y: integer;
		begin
		l:=i;
		j:=m;
		x:=a[(l+j) div 2];
		repeat
		while a[i]<x do inc(i);
		while a[i]>x do dec(j);
		if i<j then
			begin
			y:=a[i]; a[i]:=a[j]; a[j]:=y;
			inc(i);
			dec(j);
			end;
		until i>j;
		                begin
		                if i<j then sort(i,j);
		                if m>l then sort(l,m);
		                end;
                  end;
	begin
		read(n);
		for i:=1 to n do
		read(o);
		kq:=max(kq, o-25);
		writeln(kq);

	end.

var k,i,max:longint;
    a:array[1..25] of longint;

begin
//assign(input,'a.inp');reset(input);
//assign(output,'a.out');rewrite(output);
readln(k);
max:=0;
for i:=1 to k do read(a[i]);
for i:=1 to k do
   IF a[i]>max then max:=a[i];
write(max-25);
readln;
end.

var n,a,max:int64;
    i:cardinal;
begin
        readln(n);
        for i:=1 to n do
        begin
                read(a);
                if a>max then max:=a;
        end;
        if max-25>0 then write(a-25)
        else write(0);
end.

var i,n,a,max:integer;
begin
        readln(n);
        for i:=1 to n do
        begin
                read(a);
                if a>max then max:=a;
        end;
        if max-25>0 then write(a-25)
        else write(0);
end.

var n,i,q,max:longint;
begin
readln(n);
for i:=1 to n do
  begin
  readln(q);
  if q>max then max:=q;
  end;
if max<25 then max:=25;
writeln(max-25);
end.

var n,i,max,s:longint;
begin
  read(n);
  for i:=1 to n do
  begin
    read(s);
    if s>max then max:=s;
  end;
  writeln(max-25);
end.

var
    n,i,a,max:longint;
begin
    read(n);
    max:=0;
    for i:=1 to n do
    begin
        read(a);
        if max<a then max:=a;
    end;
    if max>25 then writeln(max-25)
    else writeln(max);
end.

var
  k,i,r,max:longint;
begin
  readln(k);
  for i:=1 to k do
  begin
  read(r);
  if r>max then max:=r;
  end;
  if max<25 then write(0)
            else write('-25');
end.

var
n,a,max,i:longint;
begin
read(n);
for i:=1 to n do
 if a>max then max:=a;
 if max-25>0 then write(max-25)
             else write(0);
             end.

var
  n,i,x,max:longint;
begin
  readln(n);
  for i:=1 to n do
  begin
    read(x);
    if x>max then max:=x;
  end;
  if max<25 then writeln(25)else
                 writeln(max-25);
end.


Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?Please help Haruhi solve this problem.

The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters.

Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.

NoteIn the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.

var
     S:String;
     L,answer:Longint;
begin
     Readln(S);
     L:=Length(S);
     L:=L+1;
     answer:=L*26;
     answer:=answer-L+1;
     Writeln(answer);
 end.

var
  st:string;
begin
  readln(st);
  write(25*length(st)+26)
end.

var s:string;
    a:array[1..1000] of longint;
    i,j,k,l,m,n:longint;
begin
readln(s);
writeln(length(s)*25+26);
end.

var
	n, c: int64;
	s: string;
	a: array[97..122] of integer;

begin

	readln(s);
	writeln((s.length+1)*26 - s.length);

end.

program ex;
var s:string;
begin
read(s);
writeln(length(s)*25+26);
end.

var su,k:int64;i:longint;s:string;
m:array [0..100] of longint;
begin
 readln(s);
 k:=1;
 for I:=1 to length(s) do
 if i=length(s) then
                begin
                if m[i]<1 then m[i]:=25
                                else dec(m[i]);
                m[i+1]:=26;
                end
 else
                if m[i]<1 then m[i]:=25
                else dec(m[i]);
 for i:=1 to length(s)+1 do
 su:=su+m[i];
 writeln(su);
end.

Var
    n: String;

Begin
    Readln(n);
    Write(26 + 25*Length(n))
End.

var
  s : string;

begin
  readln(s);
  writeln((length(s)+1)*26-length(s));
end.

var a:string;
k:integer;
begin
read(a);
k:=(length(a)+1)*26-length(a);
write(k);
end.

var s:string;
    i:integer;
    c:char;
    reS:int64;
begin
     readln(s);
     reS:=1;
     for c:='a' to 'z' do
     begin
       inc(res);
       for i:=1 to length(s) do
          if(c<>s[i])then inc(res);
     end;
   reS:=res-1;
   writeln(res);
end.

var
  s:string;
begin
  readln(s);
  write(26*(length(s)+1)-length(s));
end.

Var s : String;
    tmp : Longint;

Begin
Readln(S);
tmp := Length(S);
Writeln(25 * (tmp + 1) + 1);
End.

program jk;
var s:string;
    l,ans:longint;
begin
  readln(s);
  l:=length(s);
  ans:=(l+1)*26-l;
  writeln(ans);
end.

var s:string;
begin
  readln(s);
  write((length(s)+1)*25+1);
end.

{$mode objfpc}
var
  s: ansistring;
begin
  readln(s);
  writeln((length(s) + 1) * 26 - length(s));
end.

var a,b:longint;
 s:string;
begin
readln(s);
a:=length(s);
b:=a*25+26;
writeln(b);
end.

var
 n: longint;
 s: string;
begin
 readln(s);
 n:=length(s);
 writeln( ((n+1)*26)-n );
end.

program codeforces_round309_a;

var
  s : array[0..100000] of string;
  l, i, j, k, f, p, a : longint;

begin
  read(s[0]);
  l:=length(s[0]);
  for i:=1 to l + 1 do
    begin
      for k:=1 to 26 do
        begin
          insert(chr(96 + k), s[0], i);
          f:=0;
          for j:=1 to p do
            if s[0] = s[j]
               then begin
                      f:=1;
                      break;
                    end;
          if f = 0
             then a:=a + 1;
          p:=p + 1;
          s[p]:=s[0];
          delete(s[0], i, 1);
        end;
    end;
  write(a);
end.

var s:string;
    n:longint;
begin
    read(s);
    n:=length(s);
    write((n+1)*26-n);
end.

Var s:string;
t, x, ans:longint;
Begin
Read(s);
WriteLn(25*(Length(s)+1)+1);
End.

var k,i,la:integer;
a:string;
begin
     read(a); la:=length(a);
     k:=0;
     for i:=1 to 26 do
     begin
     k:=k+la+1;
     end;
     writeln(k-la);
end.

var
  s:string;
  t,i:longint;
  z:char;
begin
  readln(s);
  t:=26;
  z:=s[1];
  for i:=1 to length(s) do
    begin
      if s[i]=z then t:=t+25
                else t:=t+26;
      if i<=length(s) then z:=s[i+1];
    end;
  writeln(t);
end.

var i,j,kol:integer;
s,str:string;
begin
readln(s);
kol:=0;
str:='';
for i:=1 to length(s)+1 do
   for j:=97 to 122 do
   begin
     Insert(chr(j),s,i);
     if pos(s,str)=0 then
       begin
        str:=str+s+' ';
        inc(kol);

       end;
       Delete(s,i,1);
    end;
writeln(kol);

end.

var
    s : string;
    n,n1,i : longint;
    res,tmp : int64;
    count : array[97..122] of longint;
procedure nhap;
begin
    readln(s);
end;
procedure solve;
begin
    fillchar(count,sizeof(count),0);
    n := length(s);
    tmp := 0;
    for i := 1 to n do
        inc(count[ord(s[i])]);

    for i := 97 to 122 do
        if count[i] > 0 then
            tmp := tmp + (count[i] - 0);

    n1 := n + 1;

    res := n1 * 26 - tmp;
    writeln(res);
end;

begin
    //assign(input,'554A.INP'); reset(input);
    //assign(output,'554A.OUT'); rewrite(output);
    nhap;
    solve;
end.

var
    s : string;
    n : longint;
    res : int64;
procedure nhap;
begin
    readln(s);
end;
procedure solve;
begin
    n := length(s);
    res := (n + 1) * 26 - n;
    writeln(res);
end;

begin
    //assign(input,'554A.INP'); reset(input);
    //assign(output,'554A.OUT'); rewrite(output);
    nhap;
    solve;
end.

program yan;
  var ar:array['a'..'z']of longint;
      i,x,ans:longint; s:string;  c,j:char;
begin
  read(s);
  for i:=1 to length(s) do inc(ar[s[i]]);
  for c:='a' to 'z' do
    begin
      for j:='a' to 'z' do
        if c<>j then ans:=ans+ar[j];
      inc(ans);
    end;
  write(ans);
end.

var n:longint;
    S:string;
    begin
    readln(S);
    n:=length(S);
    write(26*(n+1)-n);
    end.

var s: string;
begin
    readln(s);
    write((26*(length(s)+1))-length(s));
end.

var
        s: string;
begin
        readln(S);
        writeln((length(s)+1)*26-length(s))
end.

const   fi='';
        fo='';
        maxn=20;
var     res:longint;
        s:string;
        le:integer;
begin
    assign(input,fi);reset(input);
    assign(output,fo);rewrite(output);

    readln(s);
    le:=length(s);

    writeln((le+1)*26-le);
    close(input);close(output);
end.

{$MODE OBJFPC}
const max=26*21+1067;
var    s,t:ansistring; dem,i,k,cnt:integer;   j:char;st:boolean;
       x:array[1..max] of ansistring;
begin
       readln(s);  dem:=0;  cnt:=0;
       for i:=1 to length(s)+1 do
           begin
                for j:='a' to 'z' do
                    begin
                         st:=true;
                         t:=s;
                         insert(j,t,i);
                         for k:=1 to dem do
                             begin
                                  if t=x[k] then begin st:=false ; break end
                             end;
                         if st then
                            begin
                                inc(dem);
                                x[dem]:=t;
                            end
                    end;
           end;
       writeln(dem)
end.

var s : string;
    Begin
        readln(s);
        writeln(26 * (length(s) + 1) - length(s));
    end.

var
  s:string;
  j,n,res,dem,i:longint;
  k:char;
  a:array[0..10000] of string;
procedure qs(l,r:longint);
  var i,j:longint; x,t:string;
  begin
    i:=l; j:=r; x:=a[(l+r)>>1];
    repeat
      while a[i]<x do inc(i);
      while a[j]>x do dec(j);
      if i<=j then
        begin
          t:=a[i]; a[i]:=a[j]; a[j]:=t;
          inc(i); dec(j);
        end;
    until i>j;
    if i<r then qs(i,r);
    if l<j then qs(l,j);
  end;
begin
  readln(s);
  n:=length(s);
  for i:=1 to n+1 do
    for k:='a' to 'z' do
      begin
        inc(dem);
        for j:=1 to i-1 do a[dem]:=a[dem]+s[j];
        a[dem]:=a[dem]+k;
        for j:=i to n do a[dem]:=a[dem]+s[j];
      end;
  qs(1,dem);
  res:=1;
  for i:=2 to dem do
    if a[i]<>a[i-1] then inc(res);
  writeln(Res);
  readln;
end.

var
  s:string;
  len,ans:longint;
begin
        readln(s);
        len:=length(s);
        ans:=(len+1)*26-len;
        writeln(ans);
end.

var
 s:string;
 i,j,y,x1,x2,y1,y2,n,ans,k,t,c,a,b,r:longint;
begin
 readln(s);
 n:=length(s);
 ans:=(n+1)*26-n;
 writeln(ans);

 end.

var
  s, ns: string;
  w: array [1 .. 1000] of string;
  wc, i, j: longint;
  c: char;

begin
  readln(s); wc := 0;
  for i := 1 to 1000 do w[i] := '.';
  for i := 1 to length(s) + 1 do
    for c := 'a' to 'z' do
    begin
      ns := s; Insert(c, ns, i);
      for j := 1 to wc + 1 do
        if w[j] = ns then break;
      if j = wc + 1
         then begin
                inc(wc);
                w[wc] := ns;
              end;
    end;
  writeln(wc);
end.

var s:string;
begin
  readln(s);
  writeln(26*(length(s)+1)-length(s));
end.

var s:ansistring;
begin
readln(s);
writeln((length(s)+1)*26-length(s));
end.

var
 n: longint;
 s: string;
begin
 readln(s);
 n:=length(s);
 writeln( ((n+1)*26)-n );
end.

Var     s:string;
        res:longint;
Procedure print;
Begin
        Write(res);
End;

Procedure sol;
Begin
        res:=26+25*length(s);
ENd;

Procedure init;
Begin
        Read(s);
ENd;

BEGIN
        init;
        sol;
        print;
END.

var a,b:longint;
 s:string;
begin
readln(s);
a:=length(s);
b:=a*25+26;
writeln(b);
end.

Var
    n: String;

Begin
    Readln(n);
    Write(26 + 25*Length(n))
End.

var
  n:string;
begin
  readln(n);
  writeln(length(n)*25+26);
end.

var a:string;
begin
 readln(a);
 writeln(26+(length(a)*25));
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var s:string;
begin
 read(s);
 write(26+length(s)*25);
end.

program a;
var     s:ansistring;
begin
        readln(s);
        writeln((length(s)+1)*26-length(s));
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var s:string;
    i,l,c:integer;
begin
  read(s);
  c:=0;
  l:=length(s);
  for i:=2 to l do
    if s[i]=s[i-1] then c := c+1;
  write(26*(l+1)-l);
  readln;readln;
end.

var s : string;
    Begin
        readln(s);
        writeln(26 * (length(s) + 1) - length(s));
    end.

var
    s:string;
    l:longint;
begin
    read(s);
    l:=length(s);
    writeln(l*l+(l+1)*(26-l))
end.

Var s:string;
t, x, ans:longint;
Begin
Read(s);
WriteLn(25*(Length(s)+1)+1);
End.

var
  s : string;

begin
  readln(s);
  writeln((length(s)+1)*26-length(s));
end.

program A_554;

var
  s:string;
  n:longint;

begin
  read(s);
  n:=length(s);
  write(25*n+26);
end.

var
 i:char;
 s:string;
 j,n,m,l,k:longint;
begin
 readln(s);
 for i:='a' to 'z' do
 begin
  for j:=1 to length(s)+1 do
  begin
       if s[j]<>i then inc(l);
      { if (s[j]=s[j+1])and(s[j]=i) then else inc(l);
  }end;
 end;
 writeln(l-k);
end.

const fi = '';
      fo = '';
var s, t: string;
    i, j, n, cnt: longint;
    p: array [1..100000] of string;
    c: char;
    ok: boolean;

begin
 assign(input, fi); reset(input);
 assign(output, fo); rewrite(output);

 readln(s);
 n:=length(s);

 cnt:=0;
 for i:=1 to n+1 do
  for c:='a' to 'z' do
   begin
    t:=s; insert(c, t, i);
    ok:=true;
    for j:=1 to cnt do
     if p[j] = t then
      begin
       ok:=false;
       break;
      end;
    if ok then
     begin
      inc(cnt);
      p[cnt]:=t;
     end;
   end;

 writeln(cnt);

 close(input); close(output);
end.

var
  st:string;
begin
  readln(st);
  write(25*length(st)+26)
end.

var
 s : string ;
 n,x : longint ;

begin
 readln (s) ;
 x := length(s) ;
 n := ((x+1) * 25) + 1 ;
 writeln (n) ;
end.

var st: string;
begin
  readln(st);
  write((length(st)+1)*25+1);
end.

program milenka;
var
 s:ansistring;
begin
 readln(s);
 writeln(25*length(s)+26);
end.

var s:string;

begin
readln(s);
writeln( (length(s)+1)*25+1);
end.

var s:string;
begin
read(s);
write((length(s)+1)*26-length(s));
end.

var s:string;
    i,ans,l:longint;
begin
readln(s);
l:=length(s);
ans:=(l+1)*26-l;
writeln(ans);
end.

var s:string;
begin
        read(s);
        write(26*(length(s)+1)-length(s));
end.

var n:longint;
    S:string;
    begin
    readln(S);
    n:=length(S);
    write(26*(n+1)-n);
    end.

Var
  s:string;
begin
  read(s);
  write((length(s)+1)*25+1)
end.

var
a:string;
begin
readln(a);
writeln((length(a)+1)*26-length(a));
end.

var s:string;
begin
    readln(s);
    write((length(s)+1)*25+1);
end.

var
    s:ansistring;
    ans,i:longint;
begin
    readln(s);
    for i:=1 to length(s) do
        ans:=ans+25;
    writeln(ans+26);
end.

var
  s:string;
begin
  readln(s);
  write(26*(length(s)+1)-length(s));
end.

{$MODE OBJFPC}
var
    s: string;
    res: qword;

begin
    readln(s);
    res := qword(26) * (length(s) + 1) - length(s);
    write(res);
end.

{$MODE OBJFPC}
uses math;
var
    s: array[1..100] of string;
    ok: array[1..100] of boolean;
    n, res: integer;
    a: array[1..100] of integer;
    i, j: integer;

begin
    fillchar(a,sizeof(a),0);
    fillchar(ok,sizeof(ok),true);
    readln(n);
    for i := 1 to n do readln(s[i]);
    for i := 1 to n - 1 do begin
        for j := i + 1 to n do
            if (ok[i]) and (ok[j]) and (s[i] = s[j]) then begin
                inc(a[i]);
                ok[j] := false;
            end;
        ok[i] := false;
    end;
//    for i := 1 to n do writeln(a[i]);
    res := 0;
    for i := 1 to n do res := max(res,a[i] + 1);
    write(res);
end.

Program _554A;
var
  s : string;
  i : longint;
  kol : int64;
begin
  read(s);
  kol := 26;
  for i := 1 to Length(s) do
    kol := kol + 25;
  write(kol);
end.
{
26 25 25 25 25
  a  a  b  c
}

var s:string;
begin
  readln(s);
  writeln(26*(length(s)+1)-length(s));
end.

VAR s:string;
a,w:integer;
begin
read(s);
a:=length(s);
w:=(a+1)*26-a;
write(w);
end.

uses math;
var
  s : string;
begin
  readln(s);
  writeln(26 + length(s) * 25);
end.

Program KyoyaandPhotobook;
Var
    S: string;

Begin
    readln(S);
    writeln((length(S)+1)*26-length(S));
End.

{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q-,R+,S+,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE CONSOLE}

const filename='qc';
      oo=maxlongint div 2;
      eps=1e-6;
      eee=1e-21;

var qq,cc,a,aa:array[0..1000000]of longint;
    qc,he:array[0..2014,0..2014]of longint;
    s,ss,sss,s0,s1,s2,s3:string;
    x,y,z,xx,yy,zz,x0,y0,z0,x1,x2,x3,y1,y2,y3,z1,z2,z3:extended;
    res64,n64,nn64:int64;
    w,nt,ii,jj,n,m,q,c,q0,c0,q1,c1,q2,c2,q3,c3:longint;
    nn,mm,kk,u,v,res,cur,max,min:longint;
    test,ll,t,tt:longint;
    b,bb,bbb,b0,b1,b2,b3:boolean;
    ccc:char;

function mx(q,c:longint):longint;
  begin
  if q>c then mx:=q else mx:=c;
  end;

function mn(q,c:longint):longint;
  begin
  if q<c then mn:=q else mn:=c;
  end;

procedure init;
  begin
  assign(input,filename+'.in');
  assign(output,filename+'.out');
  reset(input);
  rewrite(output);
  end;

procedure fin;
  begin
  close(input);
  close(output);
  end;

procedure clear;
var i,j,k:longint;
  begin
  fillchar(qc,sizeof(qc),0);
  end;

procedure load;
var i,j,k:longint;
  begin
  end;

procedure save;
var i,j,k:longint;
  begin
  end;

procedure swap(var q,c:longint);
var i:longint;
    begin
    i:=q; q:=c; c:=i;
    end;

procedure qcsort(q,c:longint; var qc:array of longint);
var h,e,x:longint;
    ass:boolean;
    begin
    if q>=c then exit;
    x:=q+random(c-q+1);
    swap(qc[x],qc[q]);
    ass:=true;
    for h:=q to c do if qc[h]<>qc[q] then ass:=false;
    if ass then exit;
    h:=q; e:=c;
    while h<e do
      begin
      if qc[h]<qc[h+1] then begin swap(qc[h+1],qc[e]); dec(e); end
      else begin swap(qc[h],qc[h+1]); inc(h); end
      end;
    qcsort(q,h-1,qc);
    qcsort(e+1,c,qc);
    end;

procedure run;
var i,j,k:longint;
  begin
  //init;
  readln(s);
  n:=length(s);
  writeln(25*n+26);

  //fin;
  end;

begin
nt:=1;
//readln(nt);
for test:=1 to nt do
  begin
  clear;
  load;
  run;
  save;
  end;
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var s:string;
    i,l,c:integer;
begin
  read(s);
  c:=1;
  l:=length(s);
  for i:=2 to l do
    if s[i]<>s[i-1] then c := c+1;
  write(26*(l+1)-c);
  readln;readln;
end.

{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q-,R+,S+,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE CONSOLE}

const filename='qc';
      oo=maxlongint div 2;
      eps=1e-6;
      eee=1e-21;

var qq,cc,a,aa:array[0..1000000]of longint;
    qc,he:array[0..2014,0..2014]of longint;
    s,ss,sss,s0,s1,s2,s3:string;
    x,y,z,xx,yy,zz,x0,y0,z0,x1,x2,x3,y1,y2,y3,z1,z2,z3:extended;
    res64,n64,nn64:int64;
    w,nt,ii,jj,n,m,q,c,q0,c0,q1,c1,q2,c2,q3,c3:longint;
    nn,mm,kk,u,v,res,cur,max,min:longint;
    test,ll,t,tt:longint;
    b,bb,bbb,b0,b1,b2,b3:boolean;
    ccc:char;

function mx(q,c:longint):longint;
  begin
  if q>c then mx:=q else mx:=c;
  end;

function mn(q,c:longint):longint;
  begin
  if q<c then mn:=q else mn:=c;
  end;

procedure init;
  begin
  assign(input,filename+'.in');
  assign(output,filename+'.out');
  reset(input);
  rewrite(output);
  end;

procedure fin;
  begin
  close(input);
  close(output);
  end;

procedure clear;
var i,j,k:longint;
  begin
  fillchar(qc,sizeof(qc),0);
  end;

procedure load;
var i,j,k:longint;
  begin
  end;

procedure save;
var i,j,k:longint;
  begin
  end;

procedure swap(var q,c:longint);
var i:longint;
    begin
    i:=q; q:=c; c:=i;
    end;

procedure qcsort(q,c:longint; var qc:array of longint);
var h,e,x:longint;
    ass:boolean;
    begin
    if q>=c then exit;
    x:=q+random(c-q+1);
    swap(qc[x],qc[q]);
    ass:=true;
    for h:=q to c do if qc[h]<>qc[q] then ass:=false;
    if ass then exit;
    h:=q; e:=c;
    while h<e do
      begin
      if qc[h]<qc[h+1] then begin swap(qc[h+1],qc[e]); dec(e); end
      else begin swap(qc[h],qc[h+1]); inc(h); end
      end;
    qcsort(q,h-1,qc);
    qcsort(e+1,c,qc);
    end;

procedure run;
var i,j,k:longint;
  begin
  //init;
  readln(s);
  n:=length(s);
  writeln(25*n+1);

  //fin;
  end;

begin
nt:=1;
//readln(nt);
for test:=1 to nt do
  begin
  clear;
  load;
  run;
  save;
  end;
end.

var s:string;
    kq:longint;
begin
    readln(s);
    kq:=length(s)*26-length(s)+1;
    writeln(kq);
end.

var s:string;
    kq:longint;
begin
    readln(s);
    kq:=(length(s)+1)*26-length(s)+1;
    writeln(kq);
end.

var st: string;
begin
  readln(st);
  write(length(st)*25+1);
end.

var
  n:string;
begin
  read(n);
  writeln((length(n) + 1) * (26 - length(n)))
end.

var
  n:string;
begin
  read(n);
  writeln(length(n) * length(n) + (length(n) - 1) * (26 - length(n)))
end.

var n,m,i,j,k,ans,l,r:longint;
    s:ansistring;
  begin
    readln(s);
    ans:=(length(s)+1)*26-length(s);
    for i:=2 to length(s) do
     if s[i]=s[i-1] then dec(ans);
    writeln(ans);
  end.

program A_554;

var
  s:string;
  n:longint;

begin
  read(s);
  n:=length(s);
  write(25*n-26);
end.

{$MODE OBJFPC}
var    s:ansistring; dem,i:integer;
begin
       readln(s);  dem:=0;
       for i:=2 to length(s) do
           begin
                if s[i]=s[i-1] then inc(dem)
           end;
       writeln(26*(length(s)+1)-length(s)-dem)
end.

var s:string;
begin
    readln(s);
    write(length(s)*25+1);
end.

program codeforces_round309_a;

var
  s : string;
  p : array[1..26] of longint;
  i, j, f : longint;

begin
  read(s);
  for i:=1 to length(s) do
    p[ord(s[i]) - 96]:=1;
  for i:=1 to 26 do
    if p[i] = 1
       then j:=j + 1;
  write((26 * j) + 26 - j);
end.

Var s : String;
    tmp : Longint;

Begin
Readln(S);
tmp := Length(S);
Writeln(25 * (tmp + 1) + tmp);
End.

var album:array[1..26] of string;
k,i,l,la:integer;
a:string;
begin
     for i:=1 to 26 do
     readln(album[i]);
     writeln('������� �');
     read(a); la:=length(a);
     if la=1 then k:=0
     else k:=-1;
     for i:=1 to 26 do
     begin
     k:=k+la+1;
     end;
     writeln(k-1);
end.

var album:array[1..26] of string;
k,i,j,l:integer;
a:string;
begin
     for i:=1 to 26 do
     readln(album[i]);
     writeln('������� �');
     read(a); k:=-1;
     for i:=1 to 26 do
     begin
     l:=length(album[i]);
     k:=k+l+1
     end;
     writeln(k);

end.

var k,i,la:integer;
a:string;
begin
     read(a); la:=length(a);
     if la=1 then k:=0
     else k:=-1;
     for i:=1 to 26 do
     begin
     k:=k+la+1;
     end;
     writeln(k-1);
end.

var s:ansistring;
    st:array[-1..1000]of char;
    v,i,k,n,l:longint;
begin
 readln(s);
 readln(k);l:=0;
 n:=length(s);v:=0;st[0]:=' ';st[-1]:=' ';
 for i:=1 to n do begin
 if s[i]=st[v-1] then begin v:=v-2; l:=l+2;end;
 if s[i]=st[v] then begin v:=v-1; l:=l+1; end
 else begin v:=v+1;l:=l+1; st[v]:=s[i]; end;
 if (v=0)and(i mod l=0) then k:=k-1;
 end;
 if k=0 then writeln('YES')
 else writeln('NO');
end.