Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have an adjacent number to the left or right, Artem doesn't get any points. After the element is removed, the two parts of the array glue together resulting in the new array that Artem continues playing with. Borya wondered what maximum total number of points Artem can get as he plays this game.

The first line contains a single integer n (1 ≤ n ≤ 5·105) — the number of elements in the array. The next line contains n integers ai (1 ≤ ai ≤ 106) — the values of the array elements.

In a single line print a single integer — the maximum number of points Artem can get.

uses math;
var
 i,j,t,n,m,k,x:longint;
 ans:int64;
 a:array[0..111111]of int64;

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

begin
 readln(n);
 for i:=1 to n do
 begin
  read(x);
  while(k>1)and(a[k-1]>=a[k])and(x>=a[k])do
  begin
   inc(ans,min(a[k-1],x));
   dec(k);
  end;
  inc(k);a[k]:=x;
 end;
 qs(1,k);
 for i:=1 to k-2 do inc(ans,a[i]);
 writeln(ans);
end.

var a:array[0..500010] of longint;
    n,t,i,x:longint;
    ans:int64;

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

procedure sort(l,r: longint);
    var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) shr 1];
         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(n);
  t:=0;
  for i:=1 to n do
  begin
    read(x);
    while (t>0) and (a[t]<=a[t-1]) and (a[t]<x) do
    begin
      ans:=ans+min(a[t-1],x);
      dec(t);
    end;
    inc(t);
    a[t]:=x;
  end;

  sort(1,t);
  for i:=1 to t-2 do
    ans:=ans+a[i];
  writeln(ans);
end.

uses math;
var
  stack:array[0..1000000] of longint;
  n,i,top:longint;
  ans:int64;
  procedure sort(l,r:longint);
  var
    i,j,x,t:longint;
  begin
    i:=l;j:=r;x:=stack[(l+r) div 2];
    repeat
      while stack[i]<x do inc(i);
      while stack[j]>x do dec(j);
      if not(i>j) then
        begin
          t:=stack[i];stack[i]:=stack[j];stack[j]:=t;
          inc(i);dec(j);
        end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
  end;
begin
  read(n);
  if n<=2 then
    begin
      writeln(0);
      halt;
    end;
  read(stack[1],stack[2]);top:=2;ans:=0;
  for i:=3 to n do
    begin
      inc(top);
      read(stack[top]);
      while (top>=3)and(stack[top-1]<=stack[top])and(stack[top-1]<=stack[top-2]) do
        begin
          inc(ans,min(stack[top-2],stack[top]));
          stack[top-1]:=stack[top];
          dec(top);
        end;
    end;
  sort(1,top);
  for i:=1 to top-2 do
    inc(ans,stack[i]);
  writeln(ans);
end.

uses math;
var
  f : array[0..550000] of longint;
  ans : int64;
  a,i,j,n,m,k : longint;

begin
  readln(n);
  for i:=1 to n do begin
    read(a);
    inc(m); f[m]:=a;
    while (m >= 3) and (f[m-1] <= min(f[m-2],f[m])) do begin
      ans:=ans+int64(min(f[m-2],f[m]));
      f[m-1]:=f[m];
      dec(m);
    end;
  end;
  for i:=2 to m-1 do ans:=ans+int64(min(f[i-1],f[i+1]));
  writeln(ans);
end.

var a:array[0..600000] of longint;
i,t,n,x:longint;sum:int64;
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
//assign(input,'zl.in');reset(input);
//assign(output,'zl.out');rewrite(output);
readln(n);
for i:=1 to n do
  begin
  read(x);
  while (t>=2) and (a[t-1]>=a[t]) and (a[t]<=x) do
    begin
    if a[t-1]>x then sum:=sum+x
    else sum:=sum+a[t-1];
    t:=t-1;
    end;
  t:=t+1;a[t]:=x;
  end;
sort(1,t);
for i:=1 to t-2 do
  sum:=sum+a[i];
writeln(sum);
close(input);close(output);
end.

const
   fi='';
   fo='';
   mn=500010;
   var
   f:text;
   n,i,j,l,r:longint;
   kq:int64;
   pre,next,b,id, a:array[0..mn] of longint;
    Procedure Input;
     Begin
      assign(f,fi);
      reset(f);
      readln(f,n);
      for i:=1 to n do
       read(f,a[i]);
       close(f);
       b:=a;
    end;
    function min(x,y:longint):int64;
    Begin
      if x>y then exit(y) else
      exit(x);
   end;
   procedure swap( var x,y:longint);
    var tg:longint;
     Begin
        tg:=x;
        x:=y;
        y:=tg;
      end;
  Procedure qs(l,h:longint);
   var i,j,x:longint;
    Begin
     i:=l;
     j:=h;
     x:=a[random(h-l+1)+l];
     repeat
       while a[i]< x do inc(I);
       while a[j]>x do dec(j);
       if i<=j then
         Begin

           swap(a[i],a[j]);
           swap(id[i],id[j]);
           inc(i);
           dec(j);
         end;
       until i>j;
     if i<h then qs(i,h);
     if l<j then qs(l,j);
  end;
    Procedure Process;
    var x,y:longint;
     Begin
     for i:=1 to n do
      Begin
       id[i]:=i;
       pre[i]:=i-1;
       next[i]:=i+1;
     end;
     l:=1;
     r:=n;
        qs(1,n);
        for i:=1 to  n-2 do
         if id[i]=l then
             Begin
              kq:= kq+int64(a[i]);
              l:= next[id[i]];
            end else
            if id[i]=r then
             Begin
               kq:=kq+int64(a[i]);
               r:=pre[id[i]];
             end else
               Begin
                  y:=next[id[i]];
                  x:=pre[id[i]];
                  next[x]:=y;
                  pre[y]:=x;
                  kq:=kq+min(b[x],b[y]);
              end;
              write(kq);
    end;

Begin
 Input;
 Process;
end.

type
     node=record
       data,num:longint;
     end;
var
    n,i,l,r,x,y:longint;
    a:array[0..500010] of node;
    b,next,pre:array[0..500010] of longint;
    ans:int64;

function min(x,y:longint):longint;
begin
  if x<y then exit(x) else exit(y);
end;

procedure qsort(l,r:longint);
var
    i,j:longint;
    mid,temp:node;
begin
  i:=l;j:=r;
  mid:=a[l+random(r-l+1)];
  repeat
    while a[i].data<mid.data do inc(i);
    while a[j].data>mid.data do dec(j);
    if i<=j then
      begin
        temp:=a[i];a[i]:=a[j];a[j]:=temp;
        inc(i);dec(j);
      end;
  until i>j;
  if l<j then qsort(l,j);
  if i<r then qsort(i,r);
end;

begin {main}
  randomize;
  readln(n);
  for i:=1 to n do
    begin
      read(a[i].data);b[i]:=a[i].data;a[i].num:=i;
    end;
  qsort(1,n);
  for i:=1 to n do begin pre[i]:=i-1;next[i]:=i+1;end;
  l:=1;r:=n;
  ans:=0;
  for i:=1 to n-2 do
    if a[i].num=l then
      begin
        ans:=ans+int64(a[i].data);l:=next[a[i].num];
      end
    else
      if a[i].num=r then
        begin
          ans:=ans+int64(a[i].data);r:=pre[a[i].num];
        end
      else
        begin
          x:=pre[a[i].num];y:=next[a[i].num];ans:=ans+int64(min(b[x],b[y]));pre[y]:=x;next[x]:=y;
        end;
  writeln(ans);
end.

var
  a:Array[1..800000]of int64;
  n,i,x,top:longint;
  ans:int64;
function min(x,y:int64):int64;
begin
  if x<y then exit(x) else exit(y);
end;
procedure qsort(left,right:longint);
var
  mid,t:int64;
  i,j:longint;
begin
  if left>=right then exit;
  i:=left;
  j:=right;
  mid:=a[(i+j)div 2];
  repeat
    while a[i]<mid do inc(i);
    while a[j]>mid 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;
  qsort(left,j);
  qsort(i,right);
end;
begin

  read(n);
  top:=0;
  ans:=0;
  for i:=1 to n do
  begin
    inc(top);
    read(a[top]);
    while (top>=3)and(a[top-2]>=a[top-1])and(a[top-1]<=a[top])do
    begin
      ans:=ans+min(a[top-2],a[top]);
      a[top-1]:=a[top];
      dec(top);
    end;
  end;
  qsort(1,top);
  for i:=1 to top-2 do ans:=ans+a[i];
  writeln(ans);

end.

program problem3;
uses math;

var	a, next, prev, nextReady, added: array[ 0..1000001 ] of longInt;
	firstReady: longInt;
	sum: int64;

procedure addReady( x: longInt );
begin
	if ( a[x] > a[ prev[x] ] ) or ( a[x] > a[ next[x] ] ) or ( added[x] = 1 ) then
		exit();

	added[x] := 1;

	nextReady[x] := firstReady;
	firstReady := x;
end;

procedure remove( x: longInt );
begin
	inc( sum, min( a[ prev[x] ], a[ next[x] ] ) );

	next[ prev[x] ] := next[x];
	prev[ next[x] ] := prev[x];

	addReady( prev[x] );
	addReady( next[x] );
end;

var	n, i, x, l, r, c: longInt;
	s: int64;
	incr, decr: boolean;

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

		next[i] := i + 1;
		prev[i] := i - 1;
	end;

	a[0] := 0;
	a[n + 1] := 0;

	if ( n < 3 ) then
	begin
		writeln( 0 );
		halt;
	end;

	firstReady := 0;
	for i := 2 to n - 1 do
		if ( a[i] <= a[i - 1] ) and ( a[i] <= a[i + 1] ) then
			addReady( i );

	while ( firstReady > 0 ) do
	begin
		x := firstReady;

		firstReady := nextReady[firstReady];

		remove( x );
	end;

	s := a[1];
	x := 1;
	i := next[1];
	while ( i <= n ) do
	begin
		inc( x );
		a[x] := a[i];

		inc( s, a[x] );

		i := next[i];
	end;

	a[0] := 0;
	a[x + 1] := 0;

	if ( x < 3 ) then
	begin
		writeln( sum );
		halt;
	end;

	incr := false;
	decr := false;
	for i := 2 to x do
		if ( a[i] > a[i - 1] ) then
			incr := true
		else if ( a[i] < a[i - 1] ) then
			decr := true;

	if ( incr and decr ) then
	begin
		l := 1;
		while ( a[l + 1] >= a[l] ) do
			inc( l );

		r := l;
		while ( a[l - 1] = a[r] ) do
			dec( l );

		if ( r - l + 1 > 2 ) then
			inc( sum, int64(r - l - 1) * a[l] );

		c := l;
		l := l - 1;
		if ( r = c ) then
			inc( r );

		while ( a[l] > 0 ) or ( a[r] > 0 ) do
		begin
			if ( a[l] > 0 ) and ( a[l - 1] > a[r] ) then
			begin
				inc( sum, a[l - 1] );
				dec( l );
			end
			else if ( a[r] > 0 ) and ( a[r + 1] > a[l] ) then
			begin
				inc( sum, a[r + 1] );
				inc( r );
			end
			else
			begin
				inc( sum, min( a[l], a[r] ) );

				if ( a[l] > a[r] ) then
				begin
					c := l;
					dec( l );
				end
				else
				begin
					c := r;
					inc( r );
				end;
			end;
		end;
	end
	else if ( incr ) then
		inc( sum, s - a[x] - a[x - 1] )
	else
		inc( sum, s - a[1] - a[2] );

	writeln( sum );
end.

const
   fi='';
   fo='';
   mn=500010;

var
   n,i,j,l,r:longint;
   kq:int64;
   pre,next,b,id, a:array[0..mn] of longint;

    Procedure Input;
    Var     f:text;
     Begin
      assign(f,fi);
      reset(f);
      readln(f,n);
      for i:=1 to n do
       read(f,a[i]);
       close(f);
       b:=a;
    end;

    function min(x,y:longint):int64;
    Begin
      if x>y then exit(y) else
      exit(x);
   end;

   procedure swap( var x,y:longint);
    var tg:longint;
     Begin
        tg:=x;
        x:=y;
        y:=tg;
      end;

  Procedure qs(l,h:longint);
   var i,j,x:longint;
    Begin
     i:=l;
     j:=h;
     x:=a[random(h-l+1)+l];
     repeat
       while a[i]< x do inc(I);
       while a[j]>x do dec(j);
       if i<=j then
         Begin

           swap(a[i],a[j]);
           swap(id[i],id[j]);
           inc(i);
           dec(j);
         end;
       until i>j;
     if i<h then qs(i,h);
     if l<j then qs(l,j);
  end;

  Procedure Process;
    var x,y:longint;
  Begin
     for i:=1 to n do
      Begin
       id[i]:=i;
       pre[i]:=i-1;
       next[i]:=i+1;
     end;
     l:=1;
     r:=n;
     qs(1,n);
     for i:=1 to  n-2 do
         if id[i]=l then
             Begin
              kq:= kq+int64(a[i]);
              l:= next[id[i]];
            end else
            if id[i]=r then
             Begin
               kq:=kq+int64(a[i]);
               r:=pre[id[i]];
             end else
               Begin
                  y:=next[id[i]];
                  x:=pre[id[i]];
                  next[x]:=y;
                  pre[y]:=x;
                  kq:=kq+min(b[x],b[y]);
              end;
     write(kq);
    end;

Begin
 Input;
 Process;
end.

uses math;
var
  stack:array[0..1000000] of longint;
  n,i,top,ans:longint;
  procedure sort(l,r:longint);
  var
    i,j,x,t:longint;
  begin
    i:=l;j:=r;x:=stack[(l+r) div 2];
    repeat
      while stack[i]<x do inc(i);
      while stack[j]>x do dec(j);
      if not(i>j) then
        begin
          t:=stack[i];stack[i]:=stack[j];stack[j]:=t;
          inc(i);dec(j);
        end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
  end;
begin
  read(n);
  if n<=2 then
    begin
      writeln(0);
      halt;
    end;
  read(stack[1],stack[2]);top:=2;ans:=0;
  for i:=3 to n do
    begin
      inc(top);
      read(stack[top]);
      if (top>=3)and(stack[top-1]<stack[top])and(stack[top-1]<stack[top-2]) then
        begin
          inc(ans,min(stack[top-2],stack[top]));
          stack[top-1]:=stack[top];
          dec(top);
        end;
    end;
  sort(1,top);
  for i:=1 to top-2 do
    inc(ans,stack[i]);
  writeln(ans);
end.

uses math;
var
  stack:array[0..1000000] of longint;
  n,i,top,ans:longint;
  procedure sort(l,r:longint);
  var
    i,j,x,t:longint;
  begin
    i:=l;j:=r;x:=stack[(l+r) div 2];
    repeat
      while stack[i]<x do inc(i);
      while stack[j]>x do dec(j);
      if not(i>j) then
        begin
          t:=stack[i];stack[i]:=stack[j];stack[j]:=t;
          inc(i);dec(j);
        end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
  end;
begin
  read(n);
  if n<=2 then
    begin
      writeln(0);
      halt;
    end;
  read(stack[1],stack[2]);top:=2;ans:=0;
  for i:=3 to n do
    begin
      inc(top);
      read(stack[top]);
      while (top>=3)and(stack[top-1]<stack[top])and(stack[top-1]<stack[top-2]) do
        begin
          inc(ans,min(stack[top-2],stack[top]));
          stack[top-1]:=stack[top];
          dec(top);
        end;
    end;
  sort(1,top);
  for i:=1 to top-2 do
    inc(ans,stack[i]);
  writeln(ans);
end.

uses math;
var
  stack:array[0..1000000] of longint;
  n,i,top,ans:longint;
  procedure sort(l,r:longint);
  var
    i,j,x,t:longint;
  begin
    i:=l;j:=r;x:=stack[(l+r) div 2];
    repeat
      while stack[i]<x do inc(i);
      while stack[j]>x do dec(j);
      if not(i>j) then
        begin
          t:=stack[i];stack[i]:=stack[j];stack[j]:=t;
          inc(i);dec(j);
        end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
  end;
begin
  read(n);
  if n<=2 then
    begin
      writeln(0);
      halt;
    end;
  read(stack[1],stack[2]);top:=2;ans:=0;
  for i:=3 to n do
    begin
      inc(top);
      read(stack[top]);
      while (top>=3)and(stack[top-1]<=stack[top])and(stack[top-1]<=stack[top-2]) do
        begin
          inc(ans,min(stack[top-2],stack[top]));
          stack[top-1]:=stack[top];
          dec(top);
        end;
    end;
  sort(1,top);
  for i:=1 to top-2 do
    inc(ans,stack[i]);
  writeln(ans);
end.

var a:array[0..600000] of longint;
i,t,n,x:longint;sum:int64;
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
//assign(input,'zl.in');reset(input);
//assign(output,'zl.out');rewrite(output);
readln(n);
for i:=1 to n do
  begin
  read(x);
  while (t>=2) and (a[t-1]>=a[t]) and (a[t]<=x) do
    begin
    if a[t-1]>x then sum:=sum+x
    else sum:=sum+a[t-1];
    t:=t-1;
    end;
  t:=t+1;a[t]:=x;
  end;
sort(1,n);
for i:=1 to n-2 do
  sum:=sum+a[i];
writeln(sum);
close(input);close(output);
end.

program problem3;
uses math;

var	a, next, prev, nextReady, added: array[ 0..1000001 ] of longInt;
	firstReady: longInt;
	sum: int64;

procedure addReady( x: longInt );
begin
	if ( a[x] > a[ prev[x] ] ) or ( a[x] > a[ next[x] ] ) or ( added[x] = 1 ) then
		exit();

	added[x] := 1;

	nextReady[x] := firstReady;
	firstReady := x;
end;

procedure remove( x: longInt );
begin
	inc( sum, min( a[ prev[x] ], a[ next[x] ] ) );

	next[ prev[x] ] := next[x];
	prev[ next[x] ] := prev[x];

	addReady( prev[x] );
	addReady( next[x] );
end;

var	n, i, x, l, r: longInt;
	s: int64;
	incr, decr: boolean;

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

		next[i] := i + 1;
		prev[i] := i - 1;
	end;

	a[0] := 0;
	a[n + 1] := 0;

	if ( n < 3 ) then
	begin
		writeln( 0 );
		halt;
	end;

	firstReady := 0;
	for i := 2 to n - 1 do
		if ( a[i] <= a[i - 1] ) and ( a[i] <= a[i + 1] ) then
			addReady( i );

	while ( firstReady > 0 ) do
	begin
		x := firstReady;

		firstReady := nextReady[firstReady];

		remove( x );
	end;

	s := a[1];
	x := 1;
	i := next[1];
	while ( i <= n ) do
	begin
		inc( x );
		a[x] := a[i];

		inc( s, a[x] );

		i := next[i];
	end;

	a[0] := 0;
	a[x + 1] := 0;

	if ( x < 3 ) then
	begin
		writeln( sum );
		halt;
	end;

	incr := false;
	decr := false;
	for i := 2 to x do
		if ( a[i] > a[i - 1] ) then
			incr := true
		else if ( a[i] < a[i - 1] ) then
			decr := true;

	if ( incr and decr ) then
	begin
		l := 1;
		while ( a[l + 1] >= a[l] ) do
			inc( l );

		r := l;
		while ( a[l - 1] = a[r] ) do
			dec( l );

		if ( r - l + 1 > 2 ) then
			inc( sum, int64(r - l - 1) * a[l] );

		if ( l = r ) then
		begin
			inc( r );
			dec( l );

			inc( sum, min( a[l], a[r] ) );
		end;

		while ( a[l] > 0 ) or ( a[r] > 0 ) do
		begin
			if ( a[l] > a[r] ) then
			begin
				inc( sum, min( a[l - 1], a[r] ) );
				dec( l );
			end
			else
			begin
				inc( sum, min( a[l], a[r + 1] ) );
				inc( r );
			end;
		end;
	end
	else if ( incr ) then
		inc( sum, s - a[x] - a[x - 1] )
	else
		inc( sum, s - a[1] - a[2] );

	writeln( sum );
end.


Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue.We'll describe the rules of the game in more detail.The players move in turns. The first player begins.With every move the first player chooses one of his unglued chips, and shifts it one square to the left, to the right, up or down. It is not allowed to move a chip beyond the board edge. At the beginning of a turn some squares of the board may be covered with a glue. The first player can move the chip to such square, in this case the chip gets tightly glued and cannot move any longer.At each move the second player selects one of the free squares (which do not contain a chip or a glue) and covers it with superglue. The glue dries long and squares covered with it remain sticky up to the end of the game.If, after some move of the first player both chips are in the same square, then the first player wins. If the first player cannot make a move (both of his chips are glued), then the second player wins. Note that the situation where the second player cannot make a move is impossible — he can always spread the glue on the square from which the first player has just moved the chip.We will further clarify the case where both chips are glued and are in the same square. In this case the first player wins as the game ends as soon as both chips are in the same square, and the condition of the loss (the inability to move) does not arise.You know the board sizes and the positions of the two chips on it. At the beginning of the game all board squares are glue-free. Find out who wins if the players play optimally.

The first line contains six integers n, m, x1, y1, x2, y2 — the board sizes and the coordinates of the first and second chips, correspondingly (1 ≤ n, m ≤ 100; 2 ≤ n × m; 1 ≤ x1, x2 ≤ n; 1 ≤ y1, y2 ≤ m). The numbers in the line are separated by single spaces. It is guaranteed that the chips are located in different squares.

If the first player wins, print "First" without the quotes. Otherwise, print "Second" without the quotes.

program cf176c;
var
  n,x,t,y,m,x1,y1,x2,y2,i,j:longint;
begin
  readln(n,m,x1,y1,x2,y2);
  x:=abs(x1-x2);
  y:=abs(y1-y2);
  if y<x then begin
    t:=x; x:=y; y:=t;
  end;

  if (x=3)and(y=4)or(x=4)and(y=4)or(y>=5) then writeln('Second')
  else writeln('First');
end.

var
        n,m,x1,y1,x2,y2:longint;
        x,y:longint;
begin
        readln(n,m,x1,y1,x2,y2);
        x:=abs(x1-x2)+1;
        y:=abs(y1-y2)+1;
        if (x>3) and (y>3) then begin
        if (x>=5) or (y>=5) then writeln('Second')
        else begin
        writeln('First');
        end;
        end
        else if ((x>=6) or (y>=6)) then writeln('Second')
        else writeln('First');
end.

var
 met:array [1..1000,1..1000] of longint;
 i,j,n,m,k,x1,y1,x2,y2,xx,yy:longint;

begin
 readln(n,m,x1,y1,x2,y2);
  xx:=abs(x1-x2);
 yy:=abs(y1-y2);
 if (xx<=4)and(yy<=4)and(xx+yy<=6 )then writeln('First')
  else writeln('Second');
end.

Uses math;

Var n,m,x1,y1,x2,y2:longint;
    d:array[0..100,0..100,0..1] of longint;
    i,j:longint;
    a,b:longint;

Begin

Readln(n,m,x1,y1,x2,y2); a:=abs(x1-x2); b:=abs(y1-y2);

if a>b then begin a:=a+b; b:=a-b; a:=a-b; end;

if a=0 then begin if b<5 then Writeln('First') else Writeln('Second'); halt; end;
if a=1 then begin if b<5 then Writeln('First') else Writeln('Second'); halt; end;
if a=2 then begin if b<5 then Writeln('First') else Writeln('Second'); halt; end;
if a=3 then begin if b<4 then WRiteln('First') else WRiteln('Second'); halt; end;
if a=4 then begin if b<4 then Writeln('First') else Writeln('Second'); halt; end;

Writeln('Second');

End.

var
n,m,x1,y1,x2,y2:longint;
 begin
  readln(n,m,x1,y1,x2,y2);
  if (abs(x1-x2)>=5)or(abs(y1-y2)>=5) then writeln('Second') else
    begin
     if ((abs(x1-x2)<=2)and(abs(y1-y2)=4))or((abs(y1-y2)<=2)and(abs(x1-x2)=4)) then writeln('First') else
     if (abs(y1-y2)=4)or(abs(x1-x2)=4) then writeln('Second') else
       writeln('First');
    end;
 end.

var n,m,x1,y1,x2,y2,t:longint;
//======================================================
begin
  readln(n,m,x1,y1,x2,y2);
  t:=abs(x1-x2)+abs(y1-y2);
  if t<=4 then
    begin
      writeln('First');exit;
    end;
  if t>=7 then
    begin
      writeln('Second');exit;
    end;
  if t=6 then
    begin
      if (abs(x1-x2)>1)and(abs(y1-y2)>1) then
        writeln('First')
      else writeln('Second');
      exit;
    end;
  if (x1=x2)or(y1=y2) then writeln('Second')
                      else writeln('First');
end.

var                                                n,m,x1,y1,x2,y2,x,y:longint;
 begin
  readLn(n,m,x1,y1,x2,y2);
  x:=abs(x1-x2);
  y:=abs(y1-y2);

  if (x>4)or(y>4)or((x>=3)and(y>=4))or((x>=4)and(y>=3)) then writeln('Second')
   else writeln('First');
 end.

const c=6;
var a,b,x1,y1,x2,y2:longint;

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

 procedure second;
  begin
   writeln('Second');
   halt;
  end;

 procedure first;
  begin
   writeln('First');
   halt;
  end;

 begin
  readln(a,b,x1,y1,x2,y2);
  if a=1 then
   begin
    swap(a,b);
    swap(x1,y1);
    swap(x2,y2);
   end;
 a:=abs(x1-x2);
 b:=abs(y1-y2);
 if (a>=5) or (b>=5) or (a+b>=7) then second else first;
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 file1='c.in';
      file2='c.out';
      oo=maxlongint div 2;
      empty='';
      eps=1e-6;
      dohrena=1e21;

var qc,he:array[0..2009,0..2009]of longint;
    ss:array[0..2009]of string;
    qq,cc:array[0..500000]of longint;
    bb:array[0..500000]of boolean;
    xx,yy,zz:array[0..500000]of extended;
    ii,jj,kk,t,test,u,v,w,n,m,r,p,q,c,h,e,r0,r1,r2,res:longint;
    a:int64;
    s,s0,s1,s2:string;
    sss:ansistring;
    x,y,z,x0,x1,x2,y0,y1,y2,z0,z1,z2:longint;
    ch:char;
    b,b0,b1,b2:boolean;

procedure clear;
var i,j,k:longint;
    begin
    res:=0;
    end;

procedure load;
var i,j,k:longint;
    begin
    readln(x,y,x1,y1,x2,y2);
    end;

procedure save;
var i,j,k:longint;
    begin
    if res=1 then writeln('First');
    if res=2 then writeln('Second');
    end;

procedure run;
var i,j,k:longint;
    begin
    q:=abs(x1-x2);
    c:=abs(y1-y2);
    if q<c then begin r:=q; q:=c; c:=r; end;
    if q>4 then res:=2;
    if q<4 then res:=1;
    if q=4 then
      begin
      if c>2 then res:=2 else res:=1;
      end;
    end;

begin
{assign(input,file1);
assign(output,file2);
reset(input);
rewrite(output);}
for t:=1 to 1 do
  begin
  clear;
  load;
  run;
  save;
  end;
{close(input);
close(output);}
end.

var n,m,x1,y1,x2,y2,d1,d2:longint;
begin
readln(n,m,x1,y1,x2,y2);
d1:=abs(x1-x2);
d2:=abs(y1-y2);
if (d1<=4) and (d2<=4) and (d1+d2<=6 )then writeln('First') else writeln('Second');
end.

program pr;
 var x1,y1,x2,y2,X,Y:longint;

begin
 read(x1,y1);
 read(x1,y1);
 read(x2,y2);

 X:=abs(x1 - x2);
 Y:=abs(y1 - y2);

 if (X >= 5) or (Y >= 5) or (X + Y >= 7) then
  writeln('Second')
 else
  writeln('First');
end.

const nn=3004;
var a,b:array[0..nn] of integer;  {  c:array[-2001..2001,-2001..2001]of integer;
}    m,n,i,j,y,z,t,k,x:integer;s:string; q:char;
begin
 read(n,m,a[1],b[1],a[2],b[2]);
 if (abs(a[1]-a[2])>4)or(abs(b[1]-b[2])>4) or (abs(a[1]-a[2])+abs(b[1]-b[2])>6)then write('Second') else
 write('First');
end.

var
        n,m,x1,y1,x2,y2:longint;
        x,y:longint;
begin
        readln(n,m,x1,y1,x2,y2);
        x:=abs(x1-x2)+1;
        y:=abs(y1-y2)+1;
        if (x>=5) or (y>=5) then writeln('Second')
        else begin
        writeln('First');
        end;
end.

Uses math;

Var n,m,x1,y1,x2,y2:longint;
    d:array[0..100,0..100,0..1] of longint;
    i,j:longint;
    a,b:longint;

Begin

Readln(n,m,x1,y1,x2,y2); a:=abs(x1-x2); b:=abs(y1-y2);

if a>b then begin a:=a+b; b:=a-b; a:=a-b; end;

if b<=5 then begin Writeln('First'); halt; end else begin Writeln('Second'); halt; end;

End.

Uses math;

Var n,m,x1,y1,x2,y2:longint;
    d:array[0..100,0..100,0..1] of longint;
    i,j:longint;
    a,b:longint;

Begin

Readln(n,m,x1,y1,x2,y2); a:=abs(x1-x2); b:=abs(y1-y2);

if a>b then begin a:=a+b; b:=a-b; a:=a-b; end;

if a=0 then begin if b<5 then Writeln('First') else Writeln('Second'); halt; end;
if a=1 then begin if b<5 then Writeln('First') else Writeln('Second'); halt; end;
if a=2 then begin if b<5 then Writeln('First') else Writeln('Second'); halt; end;
if a=3 then begin if b<5 then WRiteln('First') else WRiteln('Second'); halt; end;
if a=4 then begin if b<5 then Writeln('Forst') else Writeln('Second'); halt; end;
Writeln('Second');

End.

Uses math;

Var n,m,x1,y1,x2,y2:longint;
    d:array[0..100,0..100,0..1] of longint;
    i,j:longint;
    a,b:longint;

Begin

Readln(n,m,x1,y1,x2,y2); a:=abs(x1-x2); b:=abs(y1-y2);

if a>b then begin a:=a+b; b:=a-b; a:=a-b; end;

if b<=4 then begin Writeln('First'); halt; end else begin Writeln('Second'); halt; end;

End.

var
n,m,x1,y1,x2,y2:longint;
 begin
  readln(n,m,x1,y1,x2,y2);
  if (abs(x1-x2)>=4)and(abs(y1-y2)>=4) then writeln('Second') else writeln('First');
 end.

const c=6;
var a,b,x1,y1,x2,y2:longint;

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

 procedure second;
  begin
   writeln('Second');
   halt;
  end;

 procedure first;
  begin
   writeln('First');
   halt;
  end;

 begin
  readln(a,b,x1,y1,x2,y2);
  if a=1 then
   begin
    swap(a,b);
    swap(x1,y1);
    swap(x2,y2);
   end;
 if b=1 then
  begin
   if abs(x1-x2)>4 then second else first;
  end;
 if (abs(x1-x2)+abs(y1-y2)>=c)and((abs(x1-x2)>=5)or(abs(y1-y2)>=5)) then second else first;
end.

const c=6;
var a,b,x1,y1,x2,y2:longint;

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

 procedure second;
  begin
   writeln('Second');
   halt;
  end;

 procedure first;
  begin
   writeln('First');
   halt;
  end;

 begin
  readln(a,b,x1,y1,x2,y2);
  if a=1 then
   begin
    swap(a,b);
    swap(x1,y1);
    swap(x2,y2);
   end;
 if b=1 then
  begin
   if abs(x1-x2)>4 then second else first;
  end;
 if (abs(x1-x2)+abs(y1-y2)>=c)or(abs(x1-x2)>=5)or(abs(y1-y2)>=5) then second else first;
end.

var
 met:array [1..1000,1..1000] of longint;
 i,j,n,m,k,x1,y1,x2,y2,xx,yy:longint;

begin
 readln(n,m,x1,y1,x2,y2);
  xx:=abs(x1-x2);
 yy:=abs(y1-y2);
 if (xx<=4)and(yy<=4)and(xx+yy-1>=6 )then writeln('Second')
  else writeln('First');
end.

var
 i,j,n,m,k,x1,y1,x2,y2,xx,yy:longint;
begin
 readln(n,m,x1,y1,x2,y2);
 xx:=abs(x1-x2);
 yy:=abs(y1-y2);
 if xx+yy-1>=4 then writeln('Second')
  else writeln('First');
end.

var
 met:array [1..1000,1..1000] of longint;
 i,j,n,m,k,x1,y1,x2,y2,xx,yy:longint;

begin
 readln(n,m,x1,y1,x2,y2);
  xx:=abs(x1-x2);
 yy:=abs(y1-y2);
 if xx+yy-1>=6 then writeln('Second')
  else writeln('First');
end.

var
 i,j,n,m,k,x1,y1,x2,y2,xx,yy:longint;
begin
 readln(n,m,x1,y1,x2,y2);
 xx:=abs(x1-x2);
 yy:=abs(y1-y2);
 if xx+yy-1>=5 then writeln('Second')
  else writeln('First');
end.

var n,m,x1,y1,x2,y2,d1,d2:longint;
begin
readln(n,m,x1,y1,x2,y2);
d1:=abs(x1-x2);
d2:=abs(y1-y2);
if (d1<=4) or (d2<=4) then writeln('First')
else writeln('Second');
end.

var n,m,x1,y1,x2,y2,d1,d2:longint;
begin
readln(n,m,x1,y1,x2,y2);
d1:=abs(x1-x2);
d2:=abs(y1-y2);
if (d1<=4) and (d2<=4) then writeln('First')
else writeln('Second');
end.

program pr;
 var x1,y1,x2,y2,X,Y:longint;

begin
 read(x1,y1);
 read(x1,y1);
 read(x2,y2);

 X:=abs(x1 - x2);
 Y:=abs(y1 - y2);

 if (X >= 5) or (Y >= 5) then
  writeln('Second')
 else
  writeln('First');
end.

program pr;
 var x1,y1,x2,y2,X,Y,min,max:longint;

begin
 read(x1,y1);
 read(x1,y1);
 read(x2,y2);

 X:=abs(x1 - x2);
 Y:=abs(y1 - y2);

 if (X >= Y) then
 begin
  max:=X;
  min:=Y;
 end else
 begin
  max:=Y;
  min:=X;
 end;

 if (max >= 4) and (min >= 2) then
  writeln('Second')
 else
  writeln('First');
end.

program pr;
 var x1,y1,x2,y2,X,Y,min,max:longint;

begin
 read(x1,y1);
 read(x1,y1);
 read(x2,y2);

 X:=abs(x1 - x2);
 Y:=abs(y1 - y2);

 if (X >= Y) then
 begin
  max:=X;
  min:=Y;
 end else
 begin
  max:=Y;
  min:=X;
 end;

 if ((max >= 4) and (min >= 2)) or (max >= 5) then
  writeln('Second')
 else
  writeln('First');
end.

const nn=3004;
var a,b:array[0..nn] of integer;  {  c:array[-2001..2001,-2001..2001]of integer;
}    m,n,i,j,y,z,t,k,x:integer;s:string; q:char;
begin
 read(n,m,a[1],b[1],a[2],b[2]);
 if (abs(a[1]-a[2])>4)or(abs(b[1]-b[2])>4) then write('Second') else
 write('First');
end.


Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x > 0 exist such that:  Decimal representation of x (without leading zeroes) consists of exactly n digits;  There exists some integer y > 0 such that:   ;  decimal representation of y is a suffix of decimal representation of x.  As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.Can you help Amr escape this embarrassing situation?

Input consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 109).

NoteA suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S.

var
 i,j,x:longint;
 ans,n,m,t,k:int64;
 a,b:array[0..1111]of int64;
 f:array[0..1111,0..1111]of int64;
begin
 readln(n,k,m);
 a[1]:=1;
 for i:=2 to n do a[i]:=(a[i-1]*10)mod k;
 b[0]:=1;b[1]:=9;
 for i:=2 to n do b[i]:=(b[i-1]*10)mod m;
 f[0,0]:=1;
 for i:=1 to n do for j:=0 to k-1 do for x:=0 to 9 do
 if(x>0)and((j+x*a[i])mod k=0)then ans:=(ans+f[i-1,j]*b[n-i])mod m else
 f[i,(j+x*a[i])mod k]:=(f[i,(j+x*a[i])mod k]+f[i-1,j])mod m;
 writeln(ans);
end.

const
     finp='';
     fout='';
     maxn=1010;
     maxc=1000000000;
var
     fi,fo:text;
     n,k,m:longint;
     f:array[0..maxn,0..9,0..110,0..1] of int64;
     mu:array[0..maxn] of int64;

procedure openfile;
begin
     assign(fi,finp);
     assign(fo,fout);
     reset(fi);
     rewrite(fo);
end;

procedure closefile;
begin
     close(fi);
     close(fo);
end;

function calc(vt,so,nho,kt:longint):int64;
var
     i:longint;
     res:int64;
begin
     if vt=n then exit( ord( (nho=0) and (so<>0) ) );
     if f[vt,so,nho,kt]<>-1 then exit(f[vt,so,nho,kt]);
     if (nho=0) and (vt<>0) and (kt<>0) then
          begin
               res:=9 mod m;
               for i:=vt+1 to n-1 do res:=(res*10) mod m;
               f[vt,so,nho,kt]:=res;
               //writeln(fo,vt,' ',so,' ',nho,' ',res);
               exit(res);
          end;
     res:=0;
     for i:=0 to 9 do
          res:=(res+calc(vt+1,i,(nho+i*mu[vt+1]) mod k,kt or ord(i<>0))) mod m;
     f[vt,so,nho,kt]:=res;
     //writeln(fo,vt,' ',so,' ',nho,' ',res);
     exit(res);
end;

procedure nhap;
var
     i:longint;
begin
     read(fi,n,k,m);
     mu[1]:=1;
     for i:=2 to n do
          mu[i]:=(mu[i-1]*10) mod k;
     fillchar(f,sizeof(f),255);
     writeln(fo,calc(0,0,0,0));
end;

BEGIN
     openfile;
     nhap;
     closefile;
END.

var
  f : array[0..1010,0..110,0..1] of longint;
  n,m,k,i,j,c,nn,q,cr,ans : longint;

  function add(a,b : longint) : longint; begin exit((a+b) mod m); end;

begin
  readln(n,k,m);
  f[0,0,0]:=1;
  cr:=1;
  for i:=0 to n-1 do begin for j:=0 to k-1 do for q:=0 to 1 do for c:=0 to 9 do begin
    if (i = n-1) and (c = 0) then continue;
    nn:=(j+cr*c) mod k;
    if (nn = 0) and (c > 0) then f[i+1,nn,1]:=add(f[i+1,nn,1],f[i,j,q]) else f[i+1,nn,q]:=add(f[i+1,nn,q],f[i,j,q]);
  end;
  cr:=(cr*10) mod k;
  end;
  ans:=0;
  for i:=0 to k-1 do ans:=(ans+f[n,i,1]) mod m;
  writeln(ans);
end.

const fi='';//287D.inp';
        fo='';
        maxn=1005;
        maxk=105;

var n,m,k:longint;
        f:array[1..maxn,0..maxk,0..1,0..1] of longint;
        mu:array[1..maxn] of longint;

procedure docdl;
begin
        readln(n,k,m);
end;

function tinh(i,t,ok,truez:longint):longint;
var j,minj,sl,tmp:longint;
begin
        if (i>n) then
        begin
                if (ok=1) and (truez=1) then exit(1);
                exit(0);
        end;
        if (f[i,t,ok,truez]<>-1) then exit(f[i,t,ok,truez]);
        sl:=0;
        if (i=n) then minj:=1 else minj:=0;
        if (ok=1) then
        begin
                for j:=minj to 9 do
                begin
                        tmp:=(t+j*mu[i]) mod k;
                        sl:=(sl+tinh(i+1,tmp,1,truez or ord(j>0))) mod m;
                end;
        end
        else
        begin
                for j:=minj to 9 do
                        if (j<>0) then
                        begin
                                tmp:=(t+j*mu[i]) mod k;
                                sl:=(sl+tinh(i+1,tmp,ord(tmp mod k=0),1)) mod m;
                        end
                        else sl:=(sl+tinh(i+1,t,0,truez)) mod m;
        end;
        f[i,t,ok,truez]:=sl;
        exit(sl);
end;

procedure xuli;
var i:longint;
begin
        mu[1]:=1;
        for i:=2 to n do
                mu[i]:=(mu[i-1]*10) mod k;
        fillchar(f,sizeof(f),255);
        writeln(tinh(1,0,0,0));
end;

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

        docdl;
        xuli;

        close(input);
        close(output);
END.

var n,k,m,i,j,z,o,ans:longint;
t:array[0..10000] of longint;
dp:array[0..1000,0..100,1..2] of longint;

begin
//(input,'sxjz.in');reset(input);
//assign(output,'sxjz.out');rewrite(output);
readln(n,k,m);
t[0]:=1;
for i:=1 to 1000 do t[i]:=(t[i-1]*10) mod k;
dp[0,0,1]:=1;
for i:=0 to n-1 do
  begin
  for j:=0 to k-1 do
    begin
    for z:=0 to 9 do
      begin
      if (i=n-1) and (z=0) then continue;
      o:=(z*t[i]+j) mod k;
      if (o=0) and (z>0) then
        dp[i+1,o,2]:=(dp[i+1,o,2]+dp[i,j,1]) mod m
      else
        dp[i+1,o,1]:=(dp[i+1,o,1]+dp[i,j,1]) mod m;
      dp[i+1,o,2]:=(dp[i+1,o,2]+dp[i,j,2]) mod m;
      end;
    end;
  end;
ans:=0;
for i:=0 to k-1 do
  ans:=(ans+dp[n,i,2]) mod m;
write(ans);
close(input);close(output);
end.

{$mode objfpc}
{$coperators on}
{$macro on}
uses math;
const
     fin   ='';//p507d.inp';
     fou   ='';
     maxn = 1010;
     maxk = 100;
     base = trunc(1e9)+7;
type
     pair = record
          fi,se     :longint;
     end;
var
     n,k,m               :longint;
     f                   :array[0..maxn,0..maxk,false..true] of longint;
     v                   :array[0..9,0..maxn] of longint;
procedure enter;
begin
     readln(n,k,m);
end;

function cal(i,r    :longint;ok    :boolean):longint;
var
     c    :longint;
begin
     if i=0 then exit(ord(ok));
     if f[i,r,ok]<>-1 then exit(f[i,r,ok]);
     f[i,r,ok]:=0;
     for c:=0 to 9 do
          if (i<>1) or (c<>0) then
          begin
               f[i,r,ok]:=(f[i,r,ok]+cal(i-1,(r+v[c,i]) mod k,ok or ((c>0) and ((r+v[c,i]) mod k=0)))) mod m;
          end;
//     writeln(i,' ',r,' ',ok,' ',f[i,r,ok]);
     exit(f[i,r,ok]);
end;
procedure solve;
var
     i,j       :longint;
begin
     fillchar(f,sizeof(f),255);
     for i:=1 to 9 do
     begin
          v[i,n]:=i mod k;
          for j:=n-1 downto 1 do
               v[i,j]:=v[i,j+1]*10 mod k;
     end;
     writeln(cal(n,0,false));
end;

BEGIN
     assign(input,fin);   reset(input);
     assign(output,fou);  rewrite(output);

     enter;
     solve;

     close(input);
     close(output);
END.

var
     dp:array [0..1010,0..111] of Int64;
     i,j,u:Longint;
     a,b:array [0..1010] of Int64;
     N,K,M,answer,y:Int64;
begin
     Readln(N,K,M);
     dp[0][0]:=1;
     a[1]:=1 mod k;
     b[1]:=9 mod m;
     b[0]:=1;
     dp[1][0]:=0;
     for i:=2 to N do
begin
     a[i]:=(a[i-1]*10) mod k;
     b[i]:=(b[i-1]*10) mod m;
     dp[i][0]:=0;
 end;
     answer:=0;
     for i:=0 to n-1 do
     for j:=0 to k-1 do
     for u:=0 to 9 do
begin
     y:=(j+u*a[i+1]) mod k;
     if (u>0) and (y=0) then answer:=(answer+(dp[i][j]*b[n-i-1])) mod m
                        else dp[i+1][y]:=(dp[i+1][y]+dp[i][j]) mod m;
 end;
     Writeln(answer);
 end.

const
     fi='';
     fo='';
     maxn=1000;

var
     n,k,m:longint;
     mu:array[1..maxn] of longint;
     F:array[1..maxn,0..110,0..1,0..1] of longint;

procedure Docdl;
var
     i,j:longint;
begin
     readln(n,k,m);
end;

function Tinh(i,modul,check,zero:longint):longint;
var
     j,minj:longint;
     check1,zero1:longint;
     sl:longint;
     tmp:string;
begin
     if (i>n) then
          begin
               if (modul=0) and (check=0) and (zero=1) then
                    begin
                         exit(1);
                    end;
               exit(check);
          end;
     if F[i,modul,check,zero]<>-1 then exit(F[i,modul,check,zero]);
     sl:=0;
     if i=n then minj:=1 else minj:=0;
     if check=1 then
          begin
               for j:=minj to 9 do
                    begin
                         if j<>0 then zero1:=1 else zero1:=0;
                         sl:=(sl+Tinh(i+1,(modul + j*mu[i]) mod k,1,zero1)) mod m;
                    end;
          end
     else
          begin
               for j:=minj to 9 do
                    begin
                         if j<>0 then
                              begin
                                   if (modul + j*mu[i]) mod k =0 then check1:=1 else check1:=0;
                                   sl:=(sl + Tinh(i+1,(modul + j*mu[i]) mod k,check1,1)) mod m;
                              end
                         else sl:=(sl + Tinh(i+1,modul,0,zero)) mod m;
                    end;
          end;
     F[i,modul,check,zero]:=sl;
     exit(sl);
end;

procedure Xuli;
var
     i,j:longint;
begin
     mu[1]:=1;
     for i:=2 to n do
          begin
               mu[i]:=(mu[i-1]*10) mod k;
          end;
     fillchar(F,sizeof(F),255);
     writeln(Tinh(1,0,0,0));
end;

BEGIN
 assign(input,fi); reset(input);
 assign(output,fo); rewrite(output);
  docdl;
  xuli;
 close(input); close(output);
END.

program D507;
const
    finp = '';
    fout = '';
    maxn = 1000+1;
    maxmod = 100+1;
var
    f : array [0..maxn,0..maxmod,0..1,0..1] of longint;
    pow : array [0..maxn] of longint;
    fi,fo : text;
    n,k,m : longint;
procedure mofile;
begin
    assign(fi,finp);
    reset(fi);
    assign(Fo,fout);
    rewrite(fo);
end;
procedure input;
begin
    readln(Fi,n,k,m);
end;
procedure dp;
var
    i,res,pos,d,td,valid,tvalid,zero,tzero,cs : longint;
begin
    f[0,0,0,0] := 1;
    pow[0] := 1;
    for i := 1 to n do
        pow[i] := (pow[i-1]*10) mod k;

    for pos := 0 to n-1 do
        for d := 0 to k-1 do
            for valid := 0 to 1 do
                for zero := 0 to 1 do
                    if f[pos,d,valid,zero] <> 0 then
                    begin
                        for cs := ord(pos = (n-1)) to 9 do
                        begin
                            td := (d+cs*pow[pos]) mod k;
                            tzero := zero or ord(cs <> 0);
                            tvalid := valid or ( ord(td = 0) and tzero );
                            f[pos+1,td,tvalid,tzero] := f[pos+1,td,tvalid,tzero] + f[pos,d,valid,zero];
                            f[pos+1,td,tvalid,tzero] := f[pos+1,td,tvalid,tzero] mod m;
                        end;
                    end;

    res := 0;
    for d := 0 to k-1 do
        res := (res + f[n,d,1,1]) mod m;

    writeln(Fo,res);
end;
procedure dongfile;
begin
    close(fi);
    close(Fo);
end;
begin
    mofile;
    input;
    dp;
    dongfile;
end.

const
    finp = '';
    maxN = 1010;
    maxK = 110;

var
    fi : text;
    n,k,m,res : longint;
    f,g : array[0..maxN,0..maxK] of int64;
    x10 : array[0..maxN] of longint;
    count : array[0..maxK] of longint;

procedure init;
var
    i : longint;
begin
    assign(fi,finp); reset(fi);
    read(fi,n,k,m);
    close(fi);
end;

procedure process;
var
    i,j,p : longint;
    t,d : int64;
begin
    x10[0]:=1;
    for i:=1 to n do x10[i]:=(x10[i-1]*10) mod k;

    f[0,0]:=1;

    for i:=1 to n do
    begin
        for j:=0 to k-1 do
        for p:=0 to 9 do
        begin
            d:=j-p*x10[i-1] mod k;
            if d<0 then d:=d+k;
            f[i,j]:=(f[i,j]+f[i-1,d]) mod m;
        end;
    end;

    for i:=1 to n do
    for j:=0 to k-1 do
    begin
        g[i,j]:=0;
        for p:=0 to k-1 do
        if (j*p) mod k = 0 then g[i,j]:=(g[i,j]+f[i,p]) mod m;
    end;

    for i:=1 to n do
    begin
        f[i,0]:=(f[i,0]-1+m) mod m;

        for j:=1 to i-1 do f[i,0]:=(f[i,0]-f[j,0]*g[i-j,x10[j]]) mod m;

        if f[i,0]<0 then f[i,0]:=f[i,0]+m;
    end;

    t:=1;
    res:=f[n,0];
    for i:=n-1 downto 1 do
    begin
        d:=(f[i,0]*9*t) mod m;
        res:=(res+d) mod m;
        t:=(t*10) mod m;
    end;

    writeln(res);
end;

begin
    init;
    process;
end.

const
        finp='';
        fout='';
        maxn=1010;
var
        fi,fo:text;
        f:array[1..maxn,0..110,false..true] of longint;
        mu:array[0..maxn] of longint;
        n,k,m:longint;
{---------------------}
procedure mo;
begin
        assign(fi,finp);
        reset(fi);
        assign(fo,fout);
        rewrite(fo);
end;
{---------------------}
procedure doc;
begin
        readln(fi,n,k,m);
end;
{---------------------}
function find(x,r:longint;subfix:boolean):longint;
var
        i,tg,newr:longint;
        check:boolean;
begin
        if x>n then exit(ord(subfix));
        if (f[x,r,subfix]<>-1) then exit(f[x,r,subfix]);
        tg:=0;
        for i:=0 to 9 do
        if ((x=n) and (i<>0)) or (x<>n) then
        begin
                newr:=(r+i*mu[x-1]) mod k;
                check:=subfix or ((i<>0) and (newr=0));
                tg:=(tg+find(x+1,newr,check)) mod m;
        end;
        f[x,r,subfix]:=tg;
        exit(tg);
end;
{---------------------}
procedure xuli;
var
        i:longint;
begin
        fillchar(f,sizeof(f),255);
        mu[0]:=1 mod k;
        for i:=1 to n do
        begin
                mu[i]:=(mu[i-1]*10) mod k;
        end;
        writeln(fo,find(1,0,false));
end;
{---------------------}
procedure ghi;
begin
end;
{---------------------}
procedure dong;
begin
        close(fi);
        close(fo);
end;
{---------------------}
begin
        mo;
        doc;
        xuli;
        ghi;
        dong;
end.

program math_lecture;

const
  tfi = '';//'507d.inp';
  tfo = '';//'507d.out';

var
  n,k,base : longint;
  f : array [0..1000,0..99,0..1] of longint;
  dd : array [0..1000,0..99,0..1] of boolean;
  fi,fo : text;

procedure input;
  begin
    assign(fi,tfi);
    reset(fi);
    read(fi,n,k,base);
    close(fi);
  end;

function power(i,modul : longint) : longint;
  var tmp : longint;
  begin
    if i = 0 then exit(1);
    tmp := power(i div 2,modul);
    tmp := int64(tmp)*tmp mod modul;
    if i mod 2 = 1 then tmp := int64(tmp)*10 mod modul;
    exit(tmp);
  end;

function cal(i,t,xh : longint) : longint;
  var d,j,xh1 : longint;
  begin
    if not dd[i,t,xh] then
      begin
        dd[i,t,xh] := true;
        if i = n then
          begin
            if (t = 0) and (xh = 1) then f[i,t,xh] := 1;
          end
        else
        if (i > 0) and (t = 0) and (xh = 1) then f[i,t,xh] := int64(power(n-i-1,base))*9 mod base
        else
          begin
            if i = n-1 then d := 1 else d := 0;
            for j := d to 9 do
              begin
                if (xh = 0) and (j = 0) then xh1 := 0 else xh1 := 1;
                f[i,t,xh] := (f[i,t,xh] + cal(i+1,(t + j*power(i,k)) mod k,xh1)) mod base;
              end;
          end;
      end;
    exit(f[i,t,xh]);
  end;

procedure output;
  begin
    assign(fo,tfo);
    rewrite(fo);
    write(fo,cal(0,0,0));
    close(fo);
  end;

begin
  input;
  output;
end.

const
        fi='';
        fo='';
        maxn=1100;
        maxc=1000000000;
var
        f:array[0..maxn,0..110,{0..1,}0..1] of int64;
        n,k,base:longint;
        mu:array[0..maxn] of int64;
        res:int64;
{-------------------------}
procedure openfiles;
begin
        assign(input,fi);
        reset(input);
        assign(output,fo);
        rewrite(output);
end;
{------------------------}
procedure closefiles;
begin
        close(input);
        close(output);
end;
{-------------------------}
procedure nhap;
begin
        readln(n,k,base);
end;
{-------------------------}
procedure xuly;
var
        i,j,l,r,o:longint;
        tmp:longint;
        sum:int64;
begin
        f[0,0,0]:=1;

        mu[0]:=1;
        for i:=1 to n do mu[i]:=(mu[i-1]*10) mod k;
        for i:=1 to n do
        begin
                for o:=0 to k-1 do
                for j:=0+ord(i=n) to 9 do
                begin
                        tmp:=(o+j*mu[i-1]) mod k;
                        for r:=0 to 1 do
                        begin
                                f[i,tmp,r or (ord(tmp=0) and ord(j>0))]:=(f[i,tmp,r or (ord(tmp=0) and ord(j>0))]+f[i-1,o,r]) mod base;
                        end;
                end;
        end;

        for i:=0 to k-1 do
        begin
                res:=(res+f[n,i,1]) mod base;
        end;
        writeln(res);
end;
{-------------------------}
BEGIN
        openfiles;
        nhap;
        xuly;
        closefiles;
END.

var
	ans:Int64;
	nines,tens:array[0..1001]of Int64;
	dp:array[0..1001,0..1001]of Int64;
	n,k,m,i,j,c:longint;
begin
	read(n,k,m);
	tens[1]:=1;
	for i:=2 to n do tens[i]:=(tens[i-1]*10)mod k;

	nines[0]:=1;
	nines[1]:=9;
	for i:=2 to n do nines[i]:=(nines[i-1]*10)mod m;

	dp[0,0]:=1;

	for i:=1 to n do
	for j:=0 to k-1 do
	for c:=0 to 9 do
		if((c>0)and(((j+c*tens[i])mod k)=0)) then ans:=(ans+dp[i-1,j]*nines[n-i])mod m
		else dp[i,(j+c*tens[i])mod k]:=(dp[i,(j+c*tens[i])mod k]+dp[i-1,j])mod m;
	writeln(ans);
end.

var
 ans,i,j,n,m,t,x,k:longint;
 a,b:array[0..1111]of longint;
 f:array[0..1111,0..1111]of longint;
begin
 readln(n,k,m);
 a[1]:=1;
 for i:=2 to n do a[i]:=(a[i-1]*10)mod k;
 b[0]:=1;b[1]:=9;
 for i:=2 to n do b[i]:=(b[i-1]*10)mod m;
 f[0,0]:=1;
 for i:=1 to n do for j:=0 to k-1 do for x:=0 to 9 do
 if(x>0)and((j+x*a[i])mod k=0)then ans:=(ans+f[i-1,j]*b[n-i])mod m else
 f[i,(j+x*a[i])mod k]:=(f[i,(j+x*a[i])mod k]+f[i-1,j])mod m;
 writeln(ans);
end.

const
     finp='';
     fout='';
     maxn=1010;
     maxc=1000000000;
var
     fi,fo:text;
     n,k,m:longint;
     f:array[0..maxn,0..9,0..110] of int64;
     mu:array[0..maxn] of int64;

procedure openfile;
begin
     assign(fi,finp);
     assign(fo,fout);
     reset(fi);
     rewrite(fo);
end;

procedure closefile;
begin
     close(fi);
     close(fo);
end;

function calc(vt,so,nho:longint):int64;
var
     i:longint;
     res:int64;
begin
     if vt=n then exit( ord( (nho=0) and (so<>0) ) );
     if f[vt,so,nho]<>-1 then exit(f[vt,so,nho]);
     if (nho=0) and (vt<>0) then
          begin
               res:=9 mod m;
               for i:=vt+1 to n-1 do res:=(res*10) mod m;
               f[vt,so,nho]:=res;
               //writeln(fo,vt,' ',so,' ',nho,' ',res);
               exit(res);
          end;
     res:=0;
     for i:=0 to 9 do
          res:=(res+calc(vt+1,i,(nho+i*mu[vt+1]) mod k)) mod m;
     f[vt,so,nho]:=res;
     //writeln(fo,vt,' ',so,' ',nho,' ',res);
     exit(res);
end;

procedure nhap;
var
     i:longint;
begin
     read(fi,n,k,m);
     mu[1]:=1;
     for i:=2 to n do
          mu[i]:=(mu[i-1]*10) mod k;
     fillchar(f,sizeof(f),255);
     writeln(fo,calc(0,0,0));
end;

BEGIN
     openfile;
     nhap;
     closefile;
END.

const
     fi='';
     fo='';
     maxn=1000;

var
     n,k,m:longint;
     mu:array[1..maxn] of longint;
     F:array[1..maxn,0..110,0..1,0..1] of longint;

procedure Docdl;
var
     i,j:longint;
begin
     readln(n,k,m);
end;

function Tinh(s:string; i,modul,check,zero:longint):longint;
var
     j,minj:longint;
     check1,zero1:longint;
     sl:longint;
     tmp:string;
begin
     if (i>n) then
          begin
               if (modul=0) and (check=0) and (zero=1) then
                    begin
                        // writeln(s);
                         exit(1);
                    end;
              // if check=1 then writeln(s);
               exit(check);
          end;
     if F[i,modul,check,zero]<>-1 then exit(F[i,modul,check,zero]);
     sl:=0;
     if i=n then minj:=1 else minj:=0;
     if check=1 then
          begin
               for j:=minj to 9 do
                    begin
                         if j<>0 then zero1:=1 else zero1:=0;
                         tmp:=s+chr(j+48);
                         sl:=(sl+Tinh(tmp,i+1,(modul + j*mu[i]) mod k,1,zero1)) mod m;
                    end;
          end
     else
          begin
               for j:=minj to 9 do
                    begin
                         tmp:=s+chr(j+48);
                         if j<>0 then
                              begin
                                   if (modul + j*mu[i]) mod k =0 then check1:=1 else check1:=0;
                                   sl:=(sl + Tinh(tmp,i+1,(modul + j*mu[i]) mod k,check1,1)) mod m;
                              end
                         else sl:=(sl + Tinh(tmp,i+1,modul,0,zero)) mod m;
                    end;
          end;
     F[i,modul,check,zero]:=sl;
     exit(sl);
end;

procedure Xuli;
var
     i,j:longint;
begin
     mu[1]:=1;
     for i:=2 to n do
          begin
               mu[i]:=(mu[i-1]*10) mod m;
          end;
     fillchar(F,sizeof(F),255);
     writeln(Tinh('',1,0,0,0));
end;

BEGIN
 assign(input,fi); reset(input);
 assign(output,fo); rewrite(output);
  docdl;
  xuli;
 close(input); close(output);
END.

const
    finp = '';
    maxN = 1010;
    maxK = 110;

var
    fi : text;
    n,k,m,res : longint;
    f,g : array[0..maxN,0..maxK] of longint;

procedure init;
var
    i : longint;
begin
    assign(fi,finp); reset(fi);
    read(fi,n,k,m);
    close(fi);
end;

procedure process;
var
    i,j,p,t,d : longint;
begin
    f[0,0]:=1;

    t:=1;
    for i:=1 to n do
    begin
        for j:=0 to k-1 do
        for p:=0 to 9 do
        begin
            d:=j-(p*t) mod k;
            if d<0 then d:=d+k;

            f[i,j]:=(f[i,j]+f[i-1,d]) mod m;
        end;

        t:=(t*10) mod k;
    end;

    g:=f;

    for i:=1 to n do
    begin
        f[i,0]:=(f[i,0]-1+m) mod m;
        t:=10;
        for j:=1 to i-1 do
        begin
            for p:=0 to k-1 do
            if (p*t) mod k = 0 then f[i,0]:=(f[i,0]-(int64(f[j,0])*g[i-j,p]) mod m + m) mod m;

            t:=(t*10) mod k;
        end;
    end;

    t:=1;
    res:=f[n,0] mod m;
    for i:=n-1 downto 1 do
    begin
        d:=(int64(f[i,0])*9*t) mod m;
        res:=(res+d) mod m;
        t:=(t*10) mod m;
    end;

    writeln(res);
end;

begin
    init;
    process;
end.

const
        fi='';
        fo='';
        maxn=1100;
        maxc=1000000000;
var
        f:array[0..maxn,0..110,0..1,0..1] of int64;
        n,k,base:longint;
        mu:array[0..maxn] of int64;
        res:int64;
{-------------------------}
procedure openfiles;
begin
        assign(input,fi);
        reset(input);
        assign(output,fo);
        rewrite(output);
end;
{------------------------}
procedure closefiles;
begin
        close(input);
        close(output);
end;
{-------------------------}
procedure nhap;
begin
        readln(n,k,base);
end;
{-------------------------}
procedure xuly;
var
        i,j,l,r,o:longint;
        tmp:longint;
        sum:int64;
begin
        f[0,0,0,0]:=1;

        mu[0]:=1;
        for i:=1 to n do mu[i]:=(mu[i-1]*10) mod base;
        for i:=1 to n do
        begin
                for o:=0 to k-1 do
                for j:=0+ord(i=n) to 9 do
                begin
                        tmp:=(o+j*mu[i-1]) mod k;
                        for l:=0 to 1 do
                        for r:=0 to 1 do
                        begin
                                f[i,tmp,l or ord(j>0),(r and l) or ord(tmp=0)]:=(f[i,tmp,l or ord(j>0),(r and l) or ord(tmp=0)]+f[i-1,o,l,r]) mod base;
                        end;
                end;
        end;

        for i:=0 to k-1 do
        begin
                res:=(res+f[n,i,1,1]) mod base;
        end;
        writeln(res);
end;
{-------------------------}
BEGIN
        openfiles;
        nhap;
        xuly;
        closefiles;
END.