Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n).Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a house number x. Then he goes to the house whose number is written on the plaque of house x (that is, to house px), then he goes to the house whose number is written on the plaque of house px (that is, to house ppx), and so on.We know that:  When the penguin starts walking from any house indexed from 1 to k, inclusive, he can walk to house number 1.  When the penguin starts walking from any house indexed from k + 1 to n, inclusive, he definitely cannot walk to house number 1.  When the penguin starts walking from house number 1, he can get back to house number 1 after some non-zero number of walks from a house to a house. You need to find the number of ways you may write the numbers on the houses' plaques so as to fulfill the three above described conditions. Print the remainder after dividing this number by 1000000007 (109 + 7).

The single line contains two space-separated integers n and k (1 ≤ n ≤ 1000, 1 ≤ k ≤ min(8, n)) — the number of the houses and the number k from the statement.

In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

{$APPTYPE CONSOLE}
const md=1000000007;
var a,b,c,i,k,n,z:integer;ans,p:int64;
begin
 //  assign(input,'input.txt');
 //  assign(output,'output.txt');
   readln(n,k);
   ans:=1;
   for i:=1 to k-1 do
      ans:=(ans*k) mod md;
   p:=1;
   for i:=1 to n-k do
      p:=(p*(n-k)) mod md;
   writeln((ans*p) mod md);
end.

program progaD;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  p = 1000000007;

var
  i: integer;
  ans, ans1, n, k: int64;
  good: array[1..8] of boolean;

procedure f(s: string);
var
  i, j: integer;
  b: boolean;
begin
  if length(s) = k then begin
    for i := 1 to k do
      if s[i] = '1' then
        good[i] := true
      else
        good[i] := false;
    for i := 1 to k do
      for j := 1 to k do
        if good[strtoint(s[j])] then
          good[j] := true;
    b := true;
    for i := 1 to k do
      if not good[i] then
        b := false;
    if b then
      inc(ans1);
    ans1 := ans1 mod p;
  end
  else
    for i := 1 to k do
      if i = 1 then
        f(s + inttostr(i))
      else if (i <> length(s) + 1) and (i <> 1) then
        f(s + inttostr(i));
end;

begin
//  reset(input, 'input.txt');
//  rewrite(output, 'output.txt');
  readln(n, k);
  ans := 1;
  ans1 := 0;
  for i := k + 1 to n do
    ans := (ans * (n - k)) mod p;
  if k = 8 then
    ans1 := 2097152
  else if k = 7 then
    ans1 := 117649
  else if k = 6 then
    ans1 := 7776
  else if k = 5 then
    ans1 := 625
  else
    f('');
  ans := (ans * ans1) mod p;
  writeln(ans);
end.

program ProjectCF;

{$APPTYPE CONSOLE}
{$R+,O-}

uses
  SysUtils,
  Math;

const
  base = 1000000007;

var
  n, k, res, t: int64;
  i: integer;

begin
  {$IFNDEF ONLINE_JUDGE}
  Reset(input, 'input.txt');
  Rewrite(output, 'output.txt');
  {$ENDIF}

  readln(n, k);
  res := 1;
  t := int64(n - k);
  for i := 1 to n - k do
    res:=(res*t) mod base;
  for i := 1 to k - 1 do
    res := (res * k) mod base;
  writeln(res);

end.

                     {$APPTYPE CONSOLE}
const nn=1000001; besk=1000000000;
   nnn=2000000;  eps=1e-13;
 label 1,2,3,4;
var chis,znam,dl,len,ii,jj,i3,i2,i1,j1,k1,p1,p2,kt,ppp,god,day,mon,mask,i0,j0,k,step,i,j,start,finish,kol,m:longint;
n,yy1,xx1,xx2,q,xx,yy,t1,t2,p,t,aa,modul,pp,tt,ot1,ot2,s,kold,ot,kkr:int64;
ostminus,kk,centr,koef:int64;
flag2,flag1,flag:boolean;
minotkl,dl1,dl2,dl3,hh,po,pt,doltek,dolpred:extended;
a,f,h,kop:array[0..2000000] of int64;
pred,c,x,y,b: array[-10..2000000] of int64;
bb,marked:array[-10..250000] of boolean;
ss:array[0..2000000] of char;
ssgood:string;
ch11,ch12,ch1,ch:char;
dd: array[-10..5001] of boolean;
ll,rr,sl,sr,stoim,str :array[-10 ..200000] of int64;
sss:array[-1000..110000] of char;
name:array[0..2000] of string;
function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;

    function nod(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;
nod:=p;
end;

  procedure dfs(i0:longint); var i,j,k:longint;
begin
  marked[i0]:=true;
 for i:=sl[i0-1]+1 to sl[i0] do
   begin
       k:=str[i]; if not marked[k] then
       begin stoim[k]:=min(stoim[k],stoim[i0]+1);
       x[k]:=stoim[k]; pred[k]:=i0;
       dfs(k);    end;
   end;

end;

begin
 {   assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
  }                                modul:=1000000007 ;
   read(n,k);
    p:=1;
     for i:=1 to k-1 do begin t:=k; p:=(p*t) mod modul;         end;

     for i:=1 to n-k do begin t:=n-k; p:=(p*t) mod modul;         end;

       writeln(p);

   1:          close(output);
end.

program Project2;

{$APPTYPE CONSOLE}
{$O-}

uses
  SysUtils;

var
  a: array[1..1000000] of Integer;
  i, n, k, x, y, max, m , j, d: integer;
  res, cnt: Int64;
  ch: Char;
  s: string;

begin
  readln(n, k);

  res := 1;
  cnt := 1;

  for i := 1 to k - 1 do
    res := (res * k) mod 1000000007;

  for i := 1 to (n - k) do
    cnt := (cnt*(n - k)) mod 1000000007;

  write((res*cnt) mod 1000000007);

end.

Var n,i:longint;
k,e,rez:int64;
m:array [1..8] of longint;
Used:array [1..8] of boolean;
procedure dfs(v:longint);
begin
  if (used[v])
  then exit;
  used[v]:=true;
  if v=1
  then exit;
  dfs(m[v]);
end;
procedure rec(v:longint);
Var i:longint;
begin
  if v>k
  then begin
        for i:=2 to k do
        begin
          fillchar(used,SizeOf(used),false);
          dfs(i);
          if not used[1]
          then Exit;
        end;
        inc(rez);
        exit;
       end;
  for i:=1 to k do
  begin
    if (v>1)and(v=i)
    then Continue;
    m[v]:=i;
    rec(v+1);
  end;
end;
begin
//  Assign(input,'input.txt'); reset(input);
//  Assign(output,'output.txt'); rewrite(output);
  readln(n,k);
  rez:=0;
  if n=1
  then begin writeln(1); halt(0); end;
  rec(2);
  e:=n-k;
  for i:=k+1 to n do
  rez:=(rez*e) mod 1000000007;
  rez:=(rez*k) mod 1000000007;
  writeln(rez);
End.

var
n,k,i:integer;
ret:int64;
begin
readln(n,k);
ret:=1;
for i:=1 to n-k do ret:=ret*(n-k) mod   1000000007;
for i:=1 to k-1 do ret:=ret*k mod  1000000007;
writeln(ret);
end.

{$R+,Q+,I+}
{$apptype console}
{$maxstacksize 100000000}
Uses SysUtils,math;
Var
   p,f,t:Array[0..5000] of Int64;
   n,k,md,w,r,it:Int64;
   i:Integer;
Function Solve(i:Integer):Integer;
Begin
   If t[i]=it Then Begin
      Solve:=f[i];
      Exit;
   End;
   If i=1 Then Begin
      Solve:=1;
      Exit;
   End;
   f[i]:=-it;
   t[i]:=it;
   If f[p[i]]=-it Then Begin
      f[i]:=0;
      Solve:=0;
      Exit;
   End;
   f[i]:=Solve(p[i]);
   Solve:=f[i];
End;
Procedure Search(i:Integer);
Var j,f1:Integer;
Begin
   If i>k Then Begin
      it:=it+1;
      f[1]:=1;
      For j:=1 To k Do Solve(j);
      f1:=1;
      For j:=1 To k Do
         If f[j]=0 Then f1:=0;
      If f1=1 Then r:=r+1;
      Exit;
   End;
   For j:=1 To k Do
      If (i<>j) or (j=1) Then Begin
         p[i]:=j;
         Search(i+1);
      End;
End;
Begin
   Read(n,k);
   md:=1000000007;
   r:=0;
   it:=10;
   Search(1);
   If k=1 Then r:=1;
   w:=1;
   For i:=1 To n-k Do w:=w*(n-k) mod md;
   Write(r*w mod md);
End.

program p2;

Uses Sysutils, Math;

Var n, k, ans: int64; i: integer;

begin
 {reset(input, 'input.txt');
 rewrite(output, 'output.txt');}
 readln(n, k);
 ans := 1;
 for i := 1 to k - 1 do
  ans := (ans * k) mod 1000000007;
 for i := k + 1 to n do
  ans := (ans * (n - k)) mod 1000000007;
 writeln(ans);
end.

const
 co=trunc(1e+9)+7;
var
 i,j,n,k,x,t:longint;
 ans,p:int64;
 a:array[1..8]of longint;
 f:array[1..8]of boolean;

function found(q:longint):boolean;
var
 w:longint;
begin
 w:=0;
 while true do
 begin
  inc(w);
  if w>k then exit(false);
  if q=1 then exit(true)else q:=a[q];
 end;
 exit(false);
end;

function check:boolean;
begin
 for j:=1 to k do if not found(j) then exit(false);
 exit(true);
end;

procedure rec(i,x:longint);
var
 j:longint;
begin
 a[x]:=i;
 if x=k then
 begin
  if check then ans:=(ans+p)mod co;
  exit;
 end;
 for j:=1 to k do rec(j,x+1);
end;

begin
 readln(n,k);
 p:=n-k;
 for i:=2 to n-k do p:=(p*(n-k))mod co;
 if p=0 then p:=1;
 for i:=1 to k do rec(i,1);
 writeln(ans);
end.

const c=1000000007;
var q,ans: qword;
    n,k,i,j: longint;
   begin
    readln(n,k);
    ans:=1;
    q:=k;
    for i:=1 to k-1 do ans:=(ans*q) mod c;
    if k=1 then ans:=1;
    q:=n-k;
    for i:=k+1 to n do ans:=(ans*q) mod c;
    writeln(ans);
   end.

{$MODE OBJFPC}
const
    maxn=1000000007;
var
    n,i,j:integer;
    res,k:int64;

begin
    readln(n,k);
    res:=1;
    for i:=1 to n-k do
        begin
            res:=(res*(n-k)) mod maxn;
        end;
    for i:=1 to k-1 do
        begin
            res:=(res*k) mod maxn;
        end;
    writeln(res);
end.

const modulo = 1000000007;
const mas:array[1..8] of int64 = (1, 2, 9, 64, 625, 7776, 117649, 2097152);

var n,m,i,j,k,answer:int64;
    cur:array[0..10] of longint;

function step(a,b:int64):int64;
var ans:int64;
begin
 if b = 0 then
  begin
   step:=1;
   exit;
  end;
ans:=step(a,b div 2);
ans:=(ans*ans) mod modulo;
if b mod 2 = 1 then ans:=ans*a;
ans:=ans mod modulo;
step:=ans;
end;

function f(n:int64):int64;
begin
 f:=mas[n];
end;

begin
 readln(n,m);

 answer:=0;
 answer:=f(m);
 answer:=int64(answer)*int64(step(n-m,n-m));
 answer:=answer mod modulo;
 writeln(answer);
end.

const  maxn=10000;
       base=1000000007;
var n,k,ans:int64;

function binpow(a,b:int64):int64;
var res:int64;
begin
if b=0 then exit(1);
res:=binpow(a,b shr 1);
res:=(res*res) mod base;
if b and 1=1 then res:=(res*a) mod base;
exit(res);
end;

BEGIN
readln(n,k);
ans:=binpow(k,k-1);
ans:=(ans*binpow(n-k,n-k)) mod base;
write(ans);
END.

var n,m,i,t:longint;x,y:int64;
f:array[0..1000]of boolean;
a:array[0..10000]of longint;
function pd:boolean;
var i:longint;
begin
for i:=1 to m do
  begin
  t:=a[i];
  fillchar(f,sizeof(f),true);
  while t<>1 do
    begin
    f[t]:=false;
    t:=a[t];
    if f[t]=false then break;
    end;
  if t<>1 then exit(false);
  end;
exit(true);
end;
procedure s(t:longint);
var i:longint;
begin
if t=m+1 then
  begin
  if pd then y:=(y+1)mod 1000000007;
  exit;
  end;
for i:=1 to m do
  begin
  a[t]:=i;
  s(t+1);
  a[t]:=0;
  end;
end;
begin
//assign(input,'fz.in');reset(input);
//assign(output,'fz.out');rewrite(output);
readln(n,m);x:=1;y:=1;
if m=8 then y:=2097152;
for i:=1 to n-m do x:=x*(n-m)mod 1000000007;
if y=1 then
  begin
  y:=0;
  s(1);
  end;
writeln(x*y mod 1000000007);
close(input);close(output);
end.

const modulo=trunc(1e9+7);
var n,k,i:longint;
    ans:int64;
begin
    read(n,k);
    if (n=1) then begin
        writeln(1);
        exit;
    end;
    ans:=1;
    for i:=k+1 to n do
        ans:=ans*(n-k) mod modulo;
    for i:=1 to k-1 do
    ans:=ans*(k) mod modulo;
    writeln(ans);
end.

const
        tfi     =       '';
        tfo     =       '';
        Nmax    =       1001;
        t:array[1..8] of longint =
(1,
2,
9,
64,
625,
7776,
117649,
2097152);
        p=1000000007 ;
type
        arr1    =       array[0..Nmax] of longint ;
var
        fi,fo   :       text;
        n,m,nho,res     :       longint;
       // a,dd,p      :       arr1 ;
{procedure DFS(i:longint);
begin
        if dd[i] = nho then exit;
        dd[i] := nho ;
        DFS(p[i]) ;
end;
procedure check;
var
        i,j,k:longint;
begin
        for i := 1 to n do
         begin
                inc(nho) ;
                DFS(i) ;
                if dd[1] < nho then exit;
         end;
        inc(res) ;
end;
procedure Try(i:longint) ;
var
j:longint;
begin
        if i = n + 1 then check else
         for j := 1 to n do
           begin
                p[i] := j ;
                Try(i+1) ;
           end;
end;   }
procedure process;
var
        i,j,k:longint;
begin
      {  for n := 1 to 8 do
        begin
                res := 0;
                try(1) ;
                writeln(fo,res) ;
        end;}
        read(fi,n,m);
        res := t[m];
        k := n - m ;
        For i := m + 1 to n do res := int64(res)*k mod p;
        write(fo,res) ;
end;
begin
        assign(fi,tfi);reset(fi);
        assign(fo,tfo);rewrite(fo);
                process;
        close(fi);
        close(fo) ;
end.

program poloandhouses;
var
  a,b,n,m,sum,i,j:longint;
  ans,re:int64;
begin
  readln(n,m);
  a:=n-m;
  ans:=1;
  for i:=1 to a do
  ans:=(ans*a) mod (1000000007);
  for i:=n downto a+2  do
  ans:=(ans*m) mod 1000000007;
  writeln(ans);
end.

Const
        kq:array [1..8] of longint=(1,2,9,64,625,7776,117649,2097152);
        oo=1000000007;
Type
        mat=array [0..1000,0..1000] of int64;
Var     a,p:mat;
        n,k:longint;
        res:int64;
        s:string;
        fi,fo:text;

Procedure Doc;
        Begin
                Read(fi,n,k);

        end;

{Function Check:boolean;
        Var i,tg,j,ok:longint;
        Begin
                For i:=1 to k do
                 Begin
                  tg:=0;
                  j:=i;
                  ok:=0;
                  Repeat
                        j:=p[j];
                        If j=1 then
                          Begin
                                ok:=1;
                                break;
                          end;
                        inc(tg);
                  Until tg=10;
                  If ok=0 then exit(false);
                 end;
                exit(true);
        end;

Procedure Try(i:longint);
        Var j:longint;
        Begin
                If i=k+1 then
                 Begin
                        If Check then inc(res);
                 end
                else
                 For j:=1 to k do
                  Begin
                        p[i]:=j;
                        Try(i+1);
                  end;
        end; }

Procedure Lam;
        Var i,j:longint;
        Begin
                For i:=0 to 1000 do a[i,0]:=1;
                For i:=0 to 1000 do
                 For j:=1 to 1000 do a[i,j]:=(a[i,j-1]*i) mod oo;
                res:=(kq[k]*a[n-k,n-k]) mod oo;
                Write(fo,res);
        end;

Procedure Inkq;
        Begin
        end;

        Begin
                Assign(fi,'');Reset(fi);
                Assign(fo,'');Rewrite(fo);
                        Doc;
                        Lam;
                        Inkq;
                Close(fo);Close(fi);
        end.

{$r-,q-,s-,i-,o+}
const
  base=1000000007;

var
  qqq,res,n,k,i:longint;
  p,used:array[0..500500]of longint;
  u:array[0..500500]of boolean;

  function can(x:longint):boolean;
    begin
      if (x=1)or(used[x]=qqq)then begin
        can:=u[x] or (x=1);
        exit;
      end;
      used[x]:=qqq;
      u[x]:=false;
      u[x]:=can(p[x]);
      can:=u[x];
    end;

  procedure rec(x:longint);
    var
      i:longint;
    begin
      if (x>k)then begin
        inc(qqq);
        for i:=2 to k do if (not can(i))then exit;
        res:=res+1;
        exit;
      end;
      for i:=1 to k do begin
        p[x]:=i;
        rec(x+1);
        p[x]:=0;
      end;
    end;

begin
  read(n,k);
  res:=0;
  rec(2);
  for i:=k+1 to n do res:=int64(res)*(n-k)mod base;
  res:=int64(res)*k mod base;
  writeln(res);
end.

var
ans:int64;
a:array[0..100]of longint;
i,n,k:longint;
md:longint;
f:array[0..10]of boolean;
used:array[0..10]of boolean;

function ch:boolean;
var
ok:boolean;
x,i:longint;
begin
   for i:=1 to k do
    begin
       x:=i;
       fillchar(f,sizeof(f),false);
       ok:=false;
       while true do
        begin
         x:=a[x];
         if x=1 then
          begin
            ok:=true;
            break;
          end;
         if f[x] then break;
         f[x]:=true;
        end;
       if (i>k)and(ok) then exit(false);
       if (i<=k)and(not ok) then exit(false);
    end;

   ch:=true;
end;
procedure rec(x:longint);
var i:longint;
begin
 if x=k+1 then
  begin
     if ch then inc(ans);
     exit;
  end;
 for i:=1 to k do
   begin
     a[x]:=i;

     rec(x+1);
     a[x]:=0;
   end;
end;
 begin
  readln(n,k);
  rec(1);
  md:=1000000007;
  for i:=1 to n-k do
   ans:=ans*int64(n-k) mod md;
  writeln(ans);
 end.

const base=1000000000+7;
      mang:array[1..8]of longint=(1,2,9,64,625,7776,117649,2097152);
var f,s:array[1..1000]of longint;
    sum:int64;
    n,k:longint;

procedure update;
var i,t:longint;
    check:boolean;
begin
  fillchar(f,sizeof(f),0);
  for i:=1 to k do if f[i]=0 then begin
    t:=i;  check:=false;
    while true do begin
      t:=s[t];  if t=1 then begin check:=true;  break; end;
      if f[t]=1 then check:=true
      else if f[t]=-1 then check:=false;
      if f[t]<>0 then break;
      f[t]:=2;
    end;
    t:=i;
    while true do begin
      if check then f[t]:=1 else f[t]:=-1;
      t:=s[t];
      if (f[t]=1)or(f[t]=-1) then break;
    end;
  end;
  for i:=1 to k do if f[i]<>1 then exit;
  inc(sum);
end;

procedure pick(p:longint);
var i:Longint;
begin
  for i:=1 to k do begin
    s[p]:=i;
    if p=k then update else pick(p+1);
  end;
end;

procedure solve;
var ans,t:int64;
   i:longint;
begin
  t:=n-k;  ans:=1;
  for i:=1 to t do ans:=(ans*t)mod base;  sum:=mang[k];
  ans:=(ans*sum)mod base;
  writeln(ans);
end;

begin
  assign(input,'');  reset(input);
  assign(output,'');  rewrite(output);
  readln(n,k);
  solve;
end.

const q = 1000000007;

var mark: array [1..100000] of Boolean;
    p: array [1..1000000] of Longint;
    i, n, k: Longint;
    sum, rez: Int64;

function prov: Boolean;
var i, j: Longint;
Begin

     {if p[1] = 1 then begin
        prov := false;
        exit;
     end;}

     for i := 1 to k do begin
         for j := 1 to k do
             mark[j] := false;
         j := i;

         if i = 1 then begin
            j := p[j];
         end;

         while (mark[j] = false) and (j <> 1) do begin
               mark[j] := true;
               j := p[j];
         end;
         if j <> 1 then begin
            prov := false;
            exit;
         end;
     end;
     prov := true;
end;

procedure src(x: Longint);
var i: Longint;
Begin
     if x = k + 1 then begin
        if prov then
           inc(rez);
        rez := rez mod q;
        exit;
     end;
     for i := 1 to k do begin
         p[x] := i;
         src(x + 1);
     end;
End;

Begin
     read(n, k);
     sum := 1;
     for i := k + 1 to n do
         sum := (sum * (n - (k + 1) + 1)) mod q;
     src(1);
     sum := (sum * rez) mod q;
     write(sum);
End.

const md=1000000007;
Var ans:int64;
   o,n,m,i,j,k,cnt:longint;
   a:array[0..123,0..123]of boolean;
   used:array[0..123]of longint;
procedure dfs(v:longint);
  var j:longint;
    begin
      used[v]:=o;
      inc(cnt);
      for j:=1 to k do
        if a[v,j] and (used[j]<>o) then dfs(j);
    end;
procedure rec(x:longint);
  var j:longint;
    begin
      if x=k+1 then
        begin
          cnt:=0;
          inc(o);
          dfs(1);
          if cnt=k then inc(ans);
          exit;
        end;
      for j:=1 to k do
        begin
          a[j,x]:=true;
          rec(x+1);
          a[j,x]:=false;
        end;
    end;
  begin
    read(n,k);
    if k=8 then ans:=2097152 else
    rec(1);
    for i:=k+1 to n do
      ans:=(ans*(n-k))mod md;
    Writeln(ans);
  end.

Const md=1000000007;
var i,j:longint;
    q,x,n,k,ans,f:int64;
    c:array[0..100]of boolean;
    b:array[0..100]of longint;
function dfs:boolean;
var x,i:longint;
 begin
  for i:=2 to k do
   begin
    fillchar(c,sizeof(c),false);
    x:=b[i];
    while not(c[x]) do
     begin
      c[x]:=true;
      x:=b[x];
     end;
    if not(c[1])then exit(false);
   end;
  exit(true);
 end;
procedure rec(x:longint);
var i:longint;
 begin
  if(x=k+1) then
    begin
     if dfs then inc(f);
     exit;
    end;
  for i:=1 to k do
   begin
    b[x]:=i;
    rec(x+1);
   end;
 end;
 begin
  read(n,k);
  q:=n-k;
  x:=1;
  f:=0;
  for i:=1 to q do
   x:=(x*q)mod md;
  rec(2);
  ans:=(x*k)mod md;
  ans:=(ans*f)mod md;
  writeln(ans);
 end.

uses math;
const
        nmax    =       1001;
        modul   =       1000000007;
var
        n,k,sol:longint;
        res:int64;
        F,free:Array[0..nmax] of boolean;
        p:Array[0..nmax] of longint;
procedure visit(u:longint);
var v:longint;
begin
        free[u]:=false;
        F[u]:=false;
        v:=p[u];
        if (v>1)and(free[v]) then visit(v);
        if (v=1)or F[v] then f[u]:=true;
end;
function check:boolean;
var i:longint;
begin
        for i:=2 to k do free[i]:=true;
        for i:=2 to k do
          begin
            if free[i] then visit(i);
            if F[i]=false then exit(false);
          end;
        exit(true);
end;
procedure DFS(i:longint);
var j:longint;
begin
        if i>k then
          begin
            if check then inc(Sol);
            exit;
          end;
        for j:=1 to k do
          begin
            p[i]:=j;
            DFS(i+1);
          end;
end;
procedure process;
var i,j,u,v:longint;
begin
        read(n,k);
        res:=k;
        for i:=k+1 to n do res:=(res*(n-k))mod modul;
        Sol:=0;
        DFS(2);
        res:=(res*sol)mod modul;
        writeln(res);
end;
begin
        assign(input,'');reset(input);
          process;
end.

program baib;
const finp='';
	  somod=trunc(1e9)+7;
type mangcha=array[1..8] of longint;
var n,k,kq:longint;
	f:text;
    fa:mangcha;
    dem:longint;

procedure nhap;
begin
    assign(f,finp);
    reset(f);
    readln(f,n,k);
    close(f);
end;

procedure vet(vt:longint;fa:mangcha);
var i,j,x:longint;
begin
    if vt=k+1 then
    begin
        inc(dem);
        exit;
    end;
    for i:=1 to k do
    begin
    	if i=vt then continue;
		fa[vt]:=i;
        x:=vt;
        j:=0;
        while (fa[x]<>x) do
		begin
        	x:=fa[x];
            inc(j);
            if j=9 then break;
        end;
        if j<>9 then vet(vt+1,fa);
    end;
end;

function tinh2(x:longint):longint;
var tam:qword;
begin
	if x=0 then exit(1);
	if x=1 then exit(n-k);
    tam:=tinh2(x div 2);
    tam:=tam*tam mod somod;
    if x and 1 = 1 then tam:=tam*(n-k) mod somod;
    exit(tam);
end;

procedure xuli;
var i,tam:longint;
begin
	tam:=tinh2(n-k);
    for i:=1 to 8 do fa[i]:=i;
    vet(2,fa);
    kq:=qword(tam)*dem*k mod somod;
end;

BEGIN
    nhap;
    xuli;
    writeln(kq);
END.

var i:longint;
    ans,md,n,k:int64;
 begin
  md:=1000000007;
  read(n,k);
  ans:=1;

  for i:=2 to k do
   ans:=ans*k;
  for i:=k+1 to n do
   ans:=ans*(n-k) mod md;
  writeln(ans);
 end.

const fi = '';
      fo = '';
      e = round(1e9)+7;
var i, n, k: longint;
    cnt, cnt2: int64;
    p: array [1..8] of longint;

procedure EndProg;
begin
 close(input); close(output);
 halt;
end;

function Check(x: longint): boolean;
var v: longint;
    visited: array [1..8] of boolean;
begin
 //if (x = 1) and (p[x] = 1) then exit(true);
 fillchar(visited, sizeof(visited), false);
 visited[x]:=true;
 while true do
  begin
   x:=p[x];
   if x = 1 then exit(true)
   else if not visited[x] then visited[x]:=true
   else exit(false);
  end;
end;

procedure Generate(i: longint);
var j: longint;
begin
 if i > k then
  begin
   for j:=1 to k do
    if not Check(j) then exit;
   inc(cnt);
   exit;
  end;
 for j:=1 to k do
  begin
   p[i]:=j;
   Generate(i+1);
  end
end;

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

 readln(n, k);

 Generate(1);

 cnt2:=1;
 for i:=k+1 to n do cnt2:=(cnt2*(n-k)) mod e;

 writeln((cnt*cnt2) mod e);

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

var
  used: array[1..10] of boolean;
  a: array[1..10] of integer;
  n, k: longint;
  q, ans: int64;

function dfs(x: longint): boolean;
begin
  if used[x] then
  begin
    if x = 1 then dfs := true else dfs := false;
    exit;
  end;
  used[x] := true;
  dfs := dfs(a[x]);
  used[x] := false;
end;

procedure check();
var
  i: longint;
  h: boolean;
begin
  h := true;
  for i := 1 to k do
    if not dfs(i) then h := false;
  if  h then inc(ans);
  ans := ans mod 1000000007;
  for i := 1 to k do used[i] := false;
end;

function pow(x, y: int64): int64;
var
  r: int64;
  i: longint;
begin
  r := 1;
  for i := 1 to y do r := r * x mod  1000000007;
  pow := r;
end;

begin

  read(n, k);

  a[1] := 1;
  a[2] := 2;
  a[3] := 9;
  a[4] := 64;
  a[5] := 625;
  a[6] := 7776;
  a[7] := 117649;
  a[8]:=  2097152;
  q := pow(n - k, n - k);
  writeln(a[k] * q mod 1000000007);
end.

const module=1000000007;
var
    f:array[1..8] of longint; used:array[1..8] of boolean; ans,n,k:int64; i:longint;

function can(nom:longint):boolean;
begin
  fillchar(used,sizeof(used),false);
  while true do
    begin
      if nom=1 then exit(true);
      if used[nom]=true then exit(false);
      used[nom]:=true; nom:=f[nom];
    end;
end;

procedure rec(nom:longint);
var i:longint;
begin
  if nom>k then
    begin
      for i:=2 to k do if can(i)=false then exit;
      inc(ans);
    end
      else
    begin
      for i:=1 to k do
        begin
        f[nom]:=i; rec(nom+1);
        end;
    end;
end;

begin

  readln(n,k); ans:=0; rec(2); ans:=ans*k;
  for i:=k+1 to n do ans:=(ans*(n-k)) mod module;
  writeln(ans);

end.

program problem2;

const md =	1000000007;

function pow( a, p: longInt ): qWord;
var	res: qWord;
begin
	res := 1;
	while ( p > 0 ) do
	begin
		if ( odd(p) ) then
			res := ( res * a ) mod md;

		a := ( qWord(a) * a ) mod md;
		p := p div 2;
	end;

	exit( res );
end;

var	n, k, ans: longInt;

begin
	readln( n, k );

	ans := ( pow( k, k - 1 ) * pow( n - k, n - k ) ) mod md;

	writeln( ans );
end.

var n,k,ans:int64;
i,j:integer;
a:array [1..8,1..8] of int64;
begin
readln(n,k);
for i:=1 to 8 do
  for j:=1 to 8 do a[i,j]:=0;
a[1,1]:=k;
for i:=2 to k do
  begin
  for j:=1 to i-1 do
    begin
    a[i,i]+=a[i-1,j]*j;
    a[i,j]+=a[i-1,j]*(k-i);
    end;
  end;
ans:=a[k,k];
for i:=k+1 to n do
  ans:=(ans*(n-k)) mod 1000000007;
writeln(ans);
end.

const MAXK = 8;
      modulo = 1000000007;

var  p , d : array [1..MAXK] of int64;
    good : array [1..MAXK] of boolean;
    ans : int64;

procedure supercheck( curr , time , k : longint );
begin

  if time > k + 1 then exit;
  if ( good[ curr ] ) or ( curr = 1 ) then begin
    good[ curr ]:=true;
    exit;
  end;

  supercheck( p[curr] , time+1 , k );
  good[curr]:=good[ p[curr] ];

end;

function check( k : longint  ) : boolean;
var i : longint ;
begin

  for i:=1 to k do good[i]:=false;

  for i:=2 to k do begin

    supercheck( i , 0 , k );
    if not good[i] then exit( false );

  end;

  exit( true );

end;

procedure  solve( k , curr : longint );
var i : longint ;
begin

  if curr <= k then begin

    for i:=1 to k do begin
      p[curr]:=i;
      solve( k , curr + 1 );
    end;

  end
  else begin

    if check( k ) then inc( ans );
    //writeln( p[1] ,' ',p[2],' ',p[3],' ',ans);
  end;

end;

function power( a , b : longint ) : int64;
var res , y : int64;
begin

  if b = 0 then exit( 1 );

  if b mod 2 = 1 then res:=a else res:=1;
  y := sqr( power( a , b div 2 ) )  mod modulo;
  res:=res * y;
  res:=res mod modulo;

  exit( res );

end;

var k , n  : longint ;
    x : int64;
begin

  d[1]:=1; d[2]:=2; d[3]:=9; d[4]:=64; d[5]:=625; d[6]:=7776; d[7]:=117649;
  d[8]:=2097152;

  readln( n , k );

  x:=Power( n - k , n - k );

  writeln( ( x * d[k] ) mod modulo );

end.

var n,m,k,i:longint;
    ans:int64;
begin
//  assign(input,'input.txt');reset(input);
//    assign(output,'output.txt');rewrite(output);
  readln(n,k);
  ans:=1;
  for i:=1 to k-1 do
    ans:=(ans*k) mod 1000000007;
  for i:=1 to n-k do
    ans:=(ans*(n-k)) mod 1000000007;
  writeln(ans);
end.

const m = 1000000007;
var
  i: longint;
  k, n, ans: int64;

begin
  read(n, k);

  ans := 1;

  for i := 1 to k - 1 do
    ans := ans * k mod m;

  for i := k + 1 to n do
    ans := ans * (n - k) mod m;

   write(ans);
end.

//(n-m)^(n-m)*m^(m-1)

const modul=1000000007;

var n,m,ans: int64;

function pow(x,y: int64): int64;
begin
  if y=0 then pow:=1
  else
  begin
    if y mod 2=1 then pow:=(pow(x,y-1)*x) mod MODUL
    else pow:=sqr(pow(x,y shr 1)) mod MODUL;
  end;
end;

begin
  readln(n,m);

  ans:=(pow(n-m,n-m)*pow(m,m-1)) mod MODUL;

  writeln(ans);
end.

const M = 1000000007;
var n, k, i : longint;
    ans : int64;
begin
     readln(n,k);
     ans := 1;
     For i := 1 to n-k do
         ans := (ans*(n-k)) mod M;
     For i := 1 to k-1 do
         ans := (ans*k) mod M;
     writeln(ans);
end.

const
    finp='';
    fout='';
    modp=1000000007;
var a,dau:array [1..10] of longint;
    n,k,dem,t,i:longint;
    KQ:int64;
    f,g:text;
function kt:boolean;
var i,x,j:longint;
begin
    for i:=1 to k do
        begin
            x:=i;
            for j:=1 to k do dau[j]:=0;
            while (x<>1) and (dau[x]<>1) do
                begin dau[x]:=1; x:=a[x]; end;
            if x<>1 then exit(false);
        end;
    exit(true);
end;
procedure duyet(d,vt:longint);
var i:longint;
begin
    if d=k then
        begin
            if kt then inc(dem);
            exit;
        end;
    for i:=1 to k do
        begin
            if (vt<>1) and (vt=i) then continue;
            a[vt]:=i; duyet(d+1,vt+1);
            a[vt]:=0;
        end;
end;
begin
    assign(f,finp); reset(f);
    assign(g,fout); rewrite(g);
    readln(f,n,k); duyet(0,1);
    KQ:=dem mod ModP; t:=n-k;
    for i:=k+1 to n do
        KQ:=(KQ*t) mod modp;
    write(g,KQ); close(f); close(g);
end.

Var n,k,q,ans:Int64;
    i:LongInt;
    a:Array[0..1000] of Int64;
Procedure rec(n:Int64);
Var num,t,numb:Int64;
    i:LongInt;
    b:Array[0..1000] of Boolean;
    y,y1:Boolean;
 begin
   if n=k+1 then
    begin
      y:=true;
      For i:=2 to k do
       begin
         fillchar(b,sizeof(b),false);
         t:=a[i];
         While not(b[t]) do
           begin
             b[t]:=true;
             t:=a[t];
           end;
         if not b[1] then y:=false;
       end;
      if y then inc(ans);
      exit;
    end;
   For i:=1 to k do
    begin
      a[n]:=i;
      rec(n+1);
    end;
 end;
  begin
    Read(n,k);
    q:=1;
    For i:=1 to n-k do
     begin
       q:=(q*(n-k)) mod 1000000007;
     end;
     ans:=0;
    rec(2);
    q:=(q*ans*k) mod 1000000007;
    WriteLn(q);
  end.

program Project1;

{$MODE DELPHI}
{$APPTYPE CONSOLE}
{$O+}

uses
  SysUtils;

const
  M = 1000000007;

var
  n, k, res : int64;
  top, i : integer;
  a : array[1..100] of integer;

procedure check;
var
  i, j, p : integer;
  bool : boolean;
begin
  for i := 1 to k do begin
    p := i;
    bool := false;
    for j := 1 to k do begin
      p := a[p];
      if (p = 1) then begin
        bool := true;
        break;
      end;
    end;
    if not bool then
      exit;
  end;
  inc(res);
end;

procedure gen;
var
  i : integer;
begin
  if (top = k) then begin
    check;
    exit;
  end;
  for i := 1 to k do begin
      inc(top);
      a[top] := i;
      gen;
      dec(top);
  end;
end;

begin
//  reset(input, 'input.txt');
//  rewrite(output, 'output.txt');

  read(n, k);

  gen;
  for i := k + 1 to n do
    res := (res * (n - k)) mod M;

  writeln(res);

end.

const c=1000000007;
var q,ans: qword;
    n,k,i,j: longint;
   begin
    readln(n,k);
    ans:=1;
    q:=k;
    for i:=1 to k-1 do ans:=(ans*q) mod c;
    if k=1 then ans:=1;
    q:=n-k;
    for i:=k+1 to n do ans:=(ans*q) mod c;
    writeln(ans);
   end.

const MO=1000000007;
Var
n,k,i,j:longint;
ans:int64;

Begin
read(n,k);
ans:=1;
for i:=1 to k-1 do
ans:=(ans*k) mod MO;

 for i:=1 to (n-k)  do
 ans:=(ans*(n-k)) mod MO;
writeln(ans);
End.

const inf=1000000007;
var n,m,s:int64;
function binPOW(n,m:int64):int64;
begin
  if m=0 then binPOW:=1
         else begin
                if m mod 2=1 then binPOW:=(binPOW(n,m-1)*n) mod inf
                             else binPOW:=sqr(binPOW(n,m shr 1)) mod inf;
              end;
end;
begin
  readln(n,m);
  s:=(binPOW(n-m,n-m)*binPOW(m,m-1)) mod inf;
  writeln(s);
end.

const md=1000000007;
var n,k,br,m,i,br1:longint;
    r:int64;
    nb,nb1,niz:array[0..100] of longint;
procedure rek(x:longint);
var i,j:longint;
begin
  if x>k then
   begin
     inc(br);
     for j:=1 to k do
      begin
        i:=j;
        inc(br1);
        while (i<>1) and (nb[i]<>br) do
         begin
           nb1[i]:=br1;
           i:=niz[i];
           if nb1[i]=br1 then exit;
         end;
        nb[j]:=br;
      end;
     inc(r);
     exit;
   end;
  for i:=1 to k do
   begin
     niz[x]:=i;
     rek(x+1);
   end;
end;
begin
  readln(n,k);
  rek(1);
  m:=n-k;
  if m>0 then
   for i:=1 to m do
    r:=(r*m) mod md;
  writeln(r);
end.

var
 m,i,n,k:longint;
 s:int64;
begin
 readln(n,k);
 s:=1;
 m:=1000000000+7;
 for i:=1 to k-1 do
   s:=s*k mod m;
 for i:=1 to n-k do
  s:=s*(n-k) mod m;
 write(s);
end.

const md=1000000007;
var f:array[1..8] of boolean;
a:array[2..8] of longint;
n,k,sum:int64;
function ksm(x,n:int64):int64;
var s:int64;
begin
s:=1;
while n<>0 do
  begin
  if n mod 2=1 then s:=(s*x) mod md;
  x:=(x*x) mod md;n:=n div 2;
  end;
exit(s);
end;
procedure sc(t:longint);
var i,x:longint;
begin
if t>k then
  begin
  for i:=2 to k do
    begin
    fillchar(f,sizeof(f),false);
    f[i]:=true;x:=a[i];
    while x<>1 do
      begin
      if f[x] then break;
      f[x]:=true;x:=a[x];
      end;
    if x<>1 then exit;
    end;
  sum:=sum+1;if sum=md then sum:=0;exit;
  end;
for i:=1 to k do
  begin
  a[t]:=i;sc(t+1);
  end;
end;
begin
//assign(input,'qedfw.in');reset(input);
//assign(output,'qedfw.out');rewrite(output);
readln(n,k);sc(2);
writeln((ksm(n-k,n-k)*((sum*k) mod md)) mod md);
close(input);close(output);
end.

const md=1000000007;
var i:longint;n,k,s,ans:int64;
e:array[0..9] of boolean;
a:array[0..9] of longint;
procedure sc(t:integer);
var i,j:integer;f:boolean;
begin
if t>k then
  begin
  f:=true;
  for i:=2 to k do
    begin
    fillchar(e,sizeof(e),false);
    j:=i;
    while (j<>1) and (not e[j]) do
      begin e[j]:=true;j:=a[j];end;
    if j<>1 then f:=false;
    if not f then break;
    end;
  ans:=ans+ord(f);
  exit;
  end;
for i:=1 to k do
  begin a[t]:=i;sc(t+1);end;
end;
begin
//assign(input,'qehfw.in');reset(input);
//assign(output,'qehfw.out');rewrite(output);
readln(n,k);s:=1;
for i:=1 to n-k do
  s:=s*(n-k) mod md;
s:=s*k mod md;sc(2);
writeln(s*ans mod md);
close(input);close(output);
end.

const md=round(1e9)+7;
var
  n,k,j,i : longint;
  data : array [0..8] of qword;
  function bpow(a,n : qword) : qword;
  var k : qword;
  begin
    if (n=1) then exit(a);
    if (n=0) then exit(1);
    if ((n mod 2)=0) then
    begin
      k:=bpow(a,n div 2);
      exit(k*k);
    end else exit(bpow(a,n-1)*a);
  end;
begin
  readln(n,k);
  for i:=1 to 8 do data[i]:=bpow(i,i-1);
  for i:=1 to 8 do
    for j:=1 to (n-k) do
      data[i]:=(data[i]*(n-k)) mod md;
  writeln(data[k]);
end.

{-Lost-}

{$mode objfpc}

const
        fi = '';
        fo = '';
        base = 1000000007;

var
        n,k: integer;
        res,t: int64;

procedure enter;
var i: integer;
begin
        readln(n,k);
        res:=1;
        t:=int64(n-k);
        for i:=1 to n-k do res:=(res*t) mod base;
        for i:=1 to k-1 do res:=(res*k) mod base;
        writeln(res);
end;

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

        enter;
end.

const
maxn=1000000007;
var
i : longint;
n,k,t,y : int64;
begin
  readln(n,k);
  t:=1;
  for i:=1 to n-k do
  t:=t*(n-k) mod maxn;
  y:=1;
  for i:=1 to k-1 do
   y:=y*k mod maxn;
  writeln(t*y mod maxn);
end.

Program d178;
Var
  n,k,modd,i:Longint;
  sum:Int64;
  ans:Array[1..8] Of Longint=(1,2,9,64,625,7776,117649,2097152);
Begin
  Readln(n,k);
  sum:=ans[k];
  modd:=1000000007;
  For i:=1 To n-k Do sum:=sum*(n-k) Mod modd;
  Writeln(sum);
End.

{$mode objfpc}

const           base                    =       trunc( 1E9 ) + 7;

var             n , k , i , j           :       integer;
                res                     :       int64;

begin
                readln( n , k );
                res := 1;
                for i := 1 to n - k do res := ( res * int64( n - k ) ) mod base;
                for i := 1 to k - 1 do res := ( res * int64( k ) ) mod base;
                writeln( res );
end.

{$mode delphi}
const bigp=1000000007;
var n,k,i:integer;
    c,ans:int64;
    a:array[1..10]of integer;
procedure check;
var used:array[1..10]of boolean;
    i,j:integer;
begin
  for i:=1 to k do begin
    fillchar(used,sizeof(used),0);
    j:=i;
    while (not used[j]) and (1<>j) do begin
      used[j]:=true;
      j:=a[j];
    end;
    if j<>1 then exit;
  end;
  ans:=ans+1;
end;

procedure worker(v:integer);
var i:integer;
begin
  if v=k+1 then check
    else begin
      for i:=1 to k do begin
        if (v=1) or (i<>v) then begin
          a[v]:=i;
          worker(v+1);
          a[v]:=0;
        end;
      end;
    end;
end;
begin
  read (n,k);
  ans:=0;
  worker(1);
  //writeln (ans);
  c:=n-k;
  for i:=1 to c do begin
    ans:= (ans*c) mod bigp;
  end;
  writeln (ans);
end.

uses math;
const fi='';//mau.inp';
      fo='';//mau.out';
      maxn=1000000007;
      mh:array[1..8] of longint=(1,2,9,64,625,7776,117649,2097152);
var   n,k:longint;
procedure   docfile;
   begin
      assign(input,fi);
      reset(input);
      readln(n,k);
      assign(output,fo);
      rewrite(output);
   end;
procedure   dongfile;
   begin
      close(input);  close(output);
   end;
procedure   xuli;
   var i,res:longint;
   begin
      res:=mh[k];
      for i:=1 to (n-k) do
         res:=int64(res)*(n-k) mod maxn;
      writeln(res);
   end;
BEGIN
   docfile;
   xuli;
   dongfile;
END.

uses
    Math;

const
    md = round(1e+9) + 7;

var
    n, k, ans:    int64;
    i:    integer;

begin
    readln(n, k);
    ans := 1;
    for i := 1 to k - 1 do begin
        ans := ans * k;
        ans := ans mod md;
    end;
    for i := 1 to (n - k) do begin
        ans := ans * (n - k);
        ans := ans mod md;
    end;
    write(ans);
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  i, n, m: integer;
  res: int64;
  a, b: array[1..10000] of integer;

function f(x: integer): integer;
begin
  b[x] := -2;
  if (b[a[x]] = -1) then begin
    result := f(a[x]);
  end else begin
    if (b[a[x]] = -2) then begin
      result := -2;
    end else begin
      result := 1;
    end;
  end;
  b[x] := result;
end;

function good: boolean;
var
  i: integer;
begin
  for i := 2 to m do
    b[i] := -1;

  for i := 2 to m do begin
    b[i] := f(i);
    if (b[i] = -2) then begin
      result := false;
      exit;
    end;
  end;
  result := true;
end;

function get(x: integer): int64;
var
  i: integer;
begin
  if (x = m + 1) then begin
    if (good) then
      result := 1
    else
      result := 0;
    exit;
  end;

  result := 0;

  for i := 1 to m do begin
    if (i <> x) then begin
      a[x] := i;
      result := result + get(x + 1);
    end;
  end;

end;

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

  readln(n, m);

  res := 0;

  b[1] := 1;
  for i := 1 to m do begin
    a[1]:= i;
    res := res + get(2);
  end;

  for i := 1 to n - m do begin
    res := (res * (n - m)) mod 1000000007;
  end;

  writeln(res mod 1000000007);

end.

{$R-,S-,Q-,I-,O-}
{$M 32000000}

{$APPTYPE CONSOLE}

uses Math;
const
inf = round(1e9);
maxn = round(1e5) + 200;
md = round(1e9) + 7;
var
n,k,ans,add,id : int64;
st,used : array [1..10] of longint;
ok : array [1..10] of boolean;

function pow (x,p : int64) : int64;
var
res : int64;
begin
 res:=1;
 while p<>0 do
 begin
  if odd (p) then res:=(res*x) mod md;
  x:=(x*x) mod md;
  p:=p shr 1;
 end;
 pow:=res mod md;
end;

function check() : boolean;
var
i,v : longint;
begin
 fillchar(ok,sizeof(ok),false);
 for i:=1 to k do
 begin
  inc(id);
  v:=i;
  while v <> 1 do
  begin
   if ok[v] then
   begin
    v:=1;
    break;
   end;
   used[v]:=id;
   v:=st[v];
   if used[v] = id then break;
  end;
  if v <> 1 then
  begin
   check:=false;
   exit;
  end;
  ok[i]:=true;
 end;
 check:=true;
end;

procedure rec(len : longint);
var
i : longint;
begin
 if len = k + 1 then
 begin
  if check() then inc(add);
  exit;
 end;
 for i:=1 to k do
 //if i <> len then
 begin
  st[len]:=i;
  rec(len + 1);
 end;
end;

begin
 //reset(input,'input.txt');
 //rewrite(output,'output.txt');
 randomize;
 readln(n,k);
 ans:=pow(n - k,n - k);
 add:=0;
 id:=0;
 rec(1);
 ans:=(ans * add) mod md;
 writeln(ans);
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='b.in';
      file2='b.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,cur:longint;
    i1,i2,i3,i4,i5,i6,i7,i8:longint;
    r1,r2,res:int64;
    s,s0,s1,s2:string;
    sss:ansistring;
    x,y,z,x0,x1,x2,y0,y1,y2,z0,z1,z2:extended;
    ch:char;
    b,b0,b1,b2:boolean;

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

procedure load;
var i,j,k:longint;
    begin
    readln(q,c);
    end;

procedure save;
var i,j,k:longint;
    begin
    writeln(res);
    end;

procedure run;
var i,j,k:longint;
    begin
    m:=1000000007;
    r1:=1;
    for i:=1 to c-1 do r1:=r1*c;
    r2:=1;
    for i:=1 to q-c do r2:=(r2*(q-c))mod m;
    res:=(r1*r2) mod m;
    end;

begin
{assign(input,file1);
assign(output,file2);
reset(input);
rewrite(output);{}
for test:=1 to 1 do
  begin
  clear;
  load;
  run;
  save;
  end;
close(input);
close(output);    {}
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 $01100000}

program Shablon;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  base = 1000000007;

var
  qwe, n, i: integer;
  a : array[1..8] of integer;
  was : array[1..8] of boolean;
  ans, res : int64;

function prov:boolean;
var
  i, t : integer;
begin
  for i := 1 to qwe do begin
    fillchar(was, sizeof(was), false);
    was[i] := true;
    t := a[i];
    while t <> 1 do begin
      if was[t] then begin
        result := false;
        exit;
      end else begin
        was[t] := true;
        t := a[t];
      end;
    end;
  end;
  result := true;
end;

procedure rec(tec : integer);
var
  i : integer;
begin
  if tec > qwe then begin
    if prov then
      inc(ans);
    exit;
  end;
  for i := 1 to qwe do begin
    a[tec] := i;
    rec(tec + 1);
  end;
end;

begin
  {$IFNDEF ONLINE_JUDGE}
  reset(input, 'input.txt');
  rewrite(output, 'output.txt');
  {$ENDIF}
  read(n, qwe);
  ans := 0;
  if qwe = 8 then
    ans := 2097152 else
    rec(1);
  res := 1;
  //writeln(ans);
  for i := 1 to n - qwe do begin
    res := res * (n - qwe) mod base;
  end;
  ans := ans * res mod base;
  write(ans);

end.

var n,k,ans:int64;
i,j:integer;
a:array [1..8,1..8] of int64;
begin
readln(n,k);
for i:=1 to 8 do
  for j:=1 to 8 do a[i,j]:=0;
a[1,1]:=k;
for i:=2 to k do
  begin
  for j:=1 to i-1 do
    begin
    a[i,i]+=a[i-1,j]*j;
    a[i,j]+=a[i-1,j]*(k-i);
    end;
  end;
ans:=a[k,k];
for i:=k+1 to n do
  ans:=(ans*(n-k)) mod 1000000007;
writeln(ans);
end.

program progaD;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  p = 1000000007;

var
  n, k, i: integer;
  ans, ans1: int64;
  good: array[1..8] of boolean;

procedure f(s: string);
var
  i, j: integer;
  b: boolean;
begin
  if length(s) = k then begin
    for i := 1 to k do
      if s[i] = '1' then
        good[i] := true
      else
        good[i] := false;
    for i := 1 to k do
      for j := 1 to k do
        if good[strtoint(s[j])] then
          good[j] := true;
    b := true;
    for i := 1 to k do
      if not good[i] then
        b := false;
    if b then
      inc(ans1);
    ans1 := ans1 mod p;
  end
  else
    for i := 1 to k do
      if i = 1 then
        f(s + inttostr(i))
      else if (i <> length(s) + 1) and (i <> 1) then
        f(s + inttostr(i));
end;

begin
//  reset(input, 'input.txt');
//  rewrite(output, 'output.txt');
  readln(n, k);
  ans := 1;
  ans1 := 0;
  for i := k + 1 to n do
    ans := (ans * (n - k )) mod p;
  if k = 8 then
    ans1 := 2097152
  else if k = 7 then
    ans1 := 117649
  else if k = 6 then
    ans1 := 7776
  else if k = 5 then
    ans1 := 625;
  f('');
  ans := (ans * ans1) mod p;
  writeln(ans);
end.

program progaD;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  p = 1000000007;

var
  n, k, i: integer;
  ans, ans1: int64;
  good: array[1..8] of boolean;

procedure f(s: string);
var
  i, j: integer;
  b: boolean;
begin
  if length(s) = k then begin
    for i := 1 to k do
      if s[i] = '1' then
        good[i] := true
      else
        good[i] := false;
    for i := 1 to k do
      for j := 1 to k do
        if good[strtoint(s[j])] then
          good[j] := true;
    b := true;
    for i := 1 to k do
      if not good[i] then
        b := false;
    if b then
      inc(ans1);
    ans1 := ans1 mod p;
  end
  else
    for i := 1 to k do
      if i = 1 then
        f(s + inttostr(i))
      else if (i <> length(s) + 1) and (i <> 1) then
        f(s + inttostr(i));
end;

begin
//  reset(input, 'input.txt');
//  rewrite(output, 'output.txt');
  readln(n, k);
  ans := 1;
  ans1 := 0;
  for i := k + 1 to n do
    ans := (ans * (n - k )) mod p;
  if n = 8 then
    ans1 := 2097152
  else if n = 7 then
    ans1 := 117649
  else if n = 6 then
    ans1 := 7776
  else if n = 5 then
    ans1 := 625;
  f('');
  ans := (ans * ans1) mod p;
  writeln(ans);
end.

program progaD;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  p = 1000000007;

var
  n, k, i, x: integer;
  ans, ans1: int64;
  good: array[1..8] of boolean;

procedure f;
var
  i, j, kol: integer;
  s: string;
begin
  s := inttostr(x);
  if length(s) = k then begin
    kol := 0;
    for i := 1 to k do
      if s[i] = '1' then begin
        good[i] := true;
        inc(kol);
      end
      else
        good[i] := false;
    for i := 1 to k do begin
      for j := 1 to k do
        if  not good[j] and good[strtoint(s[j])] then begin
          good[j] := true;
          inc(kol);
        end;
      if kol = k then
        break;
    end;
    if kol = k then
      inc(ans1);
    ans1 := ans1 mod p;
  end
  else
    for i := 1 to k do
      if x = 0 then begin
        x := x * 10 + i;
        f;
        x := x div 10;
      end
      else if (i <> length(s) + 1) then begin
        x := x * 10 + i;
        f;
        x := x div 10;
      end;
end;

begin
//  reset(input, 'input.txt');
//  rewrite(output, 'output.txt');
  readln(n, k);
  ans := 1;
  for i := k + 1 to n do
    ans := (ans * (n - k )) mod p;
  x := 0;
  if k = 8 then
    ans1 := 2097152
  else if k = 7 then
    ans1 := 117649
  else begin
    ans1 := 0;
    f();
  end;
  ans := (ans * ans1) mod p;
  writeln(ans);
end.

program progaD;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  p = 1000000007;

var
  i: integer;
  ans, ans1, n, k: int64;
  good: array[1..8] of boolean;

procedure f(s: string);
var
  i, j: integer;
  b: boolean;
begin
  if length(s) = k then begin
    for i := 1 to k do
      if s[i] = '1' then
        good[i] := true
      else
        good[i] := false;
    for i := 1 to k do
      for j := 1 to k do
        if good[strtoint(s[j])] then
          good[j] := true;
    b := true;
    for i := 1 to k do
      if not good[i] then
        b := false;
    if b then
      inc(ans1);
    ans1 := ans1 mod p;
  end
  else
    for i := 1 to k do
      if i = 1 then
        f(s + inttostr(i))
      else if (i <> length(s) + 1) and (i <> 1) then
        f(s + inttostr(i));
end;

begin
//  reset(input, 'input.txt');
//  rewrite(output, 'output.txt');
  readln(n, k);
  ans := 1;
  ans1 := 0;
  for i := k + 1 to n do
    ans := (ans * (n - k)) mod p;
  if k = 8 then
    ans1 := 2097152
  else if k = 7 then
    ans1 := 117649
  else if k = 6 then
    ans1 := 7776
  else if k = 5 then
    ans1 := 625;
  f('');
  ans := (ans * ans1) mod p;
  writeln(ans);
end.

{$R+,Q+,I+}
{$apptype console}
{$maxstacksize 100000000}
Uses SysUtils,math;
Var
   p,f,t:Array[0..5000] of Int64;
   n,k,md,w,r,it:Int64;
   i:Integer;
Function Solve(i:Integer):Integer;
Begin
   If t[i]=it Then Begin
      Solve:=f[i];
      Exit;
   End;
   If i=1 Then Begin
      Solve:=1;
      Exit;
   End;
   f[i]:=-it;
   t[i]:=it;
   If f[p[i]]=-it Then Begin
      f[i]:=0;
      Solve:=0;
      Exit;
   End;
   f[i]:=Solve(p[i]);
   Solve:=f[i];
End;
Procedure Search(i:Integer);
Var j,f1:Integer;
Begin
   If i>k Then Begin
      it:=it+1;
      f[1]:=1;
      For j:=1 To k Do Solve(j);
      f1:=1;
      For j:=1 To k Do
         If f[j]=0 Then f1:=0;
      If f1=1 Then r:=r+1;
      Exit;
   End;
   For j:=1 To k Do
      If (i<>j) or (j=1) Then Begin
         p[i]:=j;
         Search(i+1);
      End;
End;
Begin
   Read(n,k);
   If k=1 Then Begin
      Write(0);
      Halt;
   End;
   md:=1000000007;
   r:=0;
   it:=10;
   Search(1);
   w:=1;
   For i:=1 To n-k Do w:=w*(n-k) mod md;
   Write(r*w mod md);
End.

const
 co=trunc(1e+9)+7;
var
 ans,n,k,p,i,j,x,t:longint;
 a:array[1..8]of longint;
 f:array[1..8]of boolean;

function found(q:longint):boolean;
var
 w:longint;
begin
 w:=0;
 while true do
 begin
  inc(w);
  if w>k then exit(false);
  if q=1 then exit(true)else q:=a[q];
 end;
 exit(false);
end;

function check:boolean;
begin
 for j:=1 to k do if not found(j) then exit(false);
 exit(true);
end;

procedure rec(i,x:longint);
var
 j:longint;
begin
 a[x]:=i;
 if x=k then
 begin
  if check then ans:=(ans+p)mod co;
  exit;
 end;
 for j:=1 to k do rec(j,x+1);
end;

begin
 readln(n,k);
 p:=n-k;
 for i:=2 to n-k do p:=(p*(n-k))mod co;
 for i:=1 to k do rec(i,1);
 writeln(ans);
end.

const
 co=trunc(1e+9)+7;
var
 i,j,n,k,x,t:longint;
 ans,p:int64;
 a:array[1..8]of longint;
 f:array[1..8]of boolean;

function found(q:longint):boolean;
var
 w:longint;
begin
 w:=0;
 while true do
 begin
  inc(w);
  if w>k then exit(false);
  if q=1 then exit(true)else q:=a[q];
 end;
 exit(false);
end;

function check:boolean;
begin
 for j:=1 to k do if not found(j) then exit(false);
 exit(true);
end;

procedure rec(i,x:longint);
var
 j:longint;
begin
 a[x]:=i;
 if x=k then
 begin
  if check then ans:=(ans+p)mod co;
  exit;
 end;
 for j:=1 to k do rec(j,x+1);
end;

begin
 readln(n,k);
 p:=n-k;
 for i:=2 to n-k do p:=(p*(n-k))mod co;
 for i:=1 to k do rec(i,1);
 writeln(ans);
end.

var n,m,i:longint;     ans:int64;  k:int64;
f:boolean;

procedure sc(t:longint);
var i:longint;
begin
if t>m then
  begin
  if f=true then
    ans:=(ans+k) mod 1000000007;
  f:=false;
  exit;

  end;
for i:=1 to m do

  begin
  if (t<>1) and (i=1) then f:=true;
    sc(t+1);
  end;
end;

begin
//assign(input,'fz.in');reset(input);
//assign(output,'fz.out');rewrite(output);
readln(n,m);
k:=1;
for i:=1 to (n-m) do
  k:=(k*(n-m)) mod 1000000007;
sc(1);
write(ans);
close(input);
close(output);
end.

var
  t,a:array[0..1005000]of longint;
  used:array[0..1000500]of boolean;
  s,sum:int64;
  n,i,j:longint;

begin
  read(n);
  s:=int64(n)*(N+1);
  writeln(s);
  for i:=0 to 20 do t[i]:=(1 shl i)-1;
  for i:=n downto 0 do begin
    j:=20;
    while (t[j]xor i>n)or(t[j]>s)or(used[t[j] xor i])do dec(j);
    used[t[j] xor i]:=true;
    s:=s-t[j];
    a[i]:=t[j] xor i;
  end;
  for i:=0 to n do write(a[i],' ');
  writeln;
end.

Const
        kq:array [1..8] of longint=(1,2,9,64,625,7776,117649,2097152);
        oo=1000000007;
Type
        mat=array [0..1000,0..1000] of int64;
Var     a,p:mat;
        n,k:longint;
        res:int64;
        s:string;
        fi,fo:text;

Procedure Doc;
        Begin
                Read(fi,n,k);

        end;

{Function Check:boolean;
        Var i,tg,j,ok:longint;
        Begin
                For i:=1 to k do
                 Begin
                  tg:=0;
                  j:=i;
                  ok:=0;
                  Repeat
                        j:=p[j];
                        If j=1 then
                          Begin
                                ok:=1;
                                break;
                          end;
                        inc(tg);
                  Until tg=10;
                  If ok=0 then exit(false);
                 end;
                exit(true);
        end;

Procedure Try(i:longint);
        Var j:longint;
        Begin
                If i=k+1 then
                 Begin
                        If Check then inc(res);
                 end
                else
                 For j:=1 to k do
                  Begin
                        p[i]:=j;
                        Try(i+1);
                  end;
        end; }

Procedure Lam;
        Var i,j:longint;
        Begin
                For i:=1 to 1000 do a[i,0]:=1;
                For i:=1 to 1000 do
                 For j:=1 to 1000 do a[i,j]:=(a[i,j-1]*i) mod oo;
                res:=(kq[k]*a[n-k,n-k]) mod oo;
                Write(fo,res);
        end;

Procedure Inkq;
        Begin
        end;

        Begin
                Assign(fi,'');Reset(fi);
                Assign(fo,'');Rewrite(fo);
                        Doc;
                        Lam;
                        Inkq;
                Close(fo);Close(fi);
        end.

const q = 1000000007;

var mark: array [1..100000] of Boolean;
    p: array [1..1000000] of Longint;
    i, n, k: Longint;
    sum, rez: Int64;

function prov: Boolean;
var i, j: Longint;
Begin

     {if p[1] = 1 then begin
        prov := false;
        exit;
     end;}

     for i := 1 to k do begin
         for j := 1 to k do
             mark[j] := false;
         j := i;

         if i = 1 then begin
            j := p[j];
         end;

         while (mark[j] = false) and (j <> 1) do begin
               mark[j] := true;
               j := p[j];
         end;
         if j <> 1 then begin
            prov := false;
            exit;
         end;
     end;
     prov := true;
end;

procedure src(x: Longint);
var i: Longint;
Begin
     if x = k + 1 then begin
        if prov then
           inc(rez);
        rez := rez mod q;
        exit;
     end;
     for i := 1 to k do begin
         p[x] := i;
         src(x + 1);
     end;
End;

Begin
     read(n, k);
     sum := 1;
     for i := k + 1 to n do
         sum := (sum * (n - (k + 1) + 1)) mod q;
     src(1);
     sum := sum * rez;
     write(sum);
End.

const MAXK = 8;
      modulo = 1000000007;

var  p , d : array [1..MAXK] of int64;
    good : array [1..MAXK] of boolean;
    ans : int64;

procedure supercheck( curr , time , k : longint );
begin

  if time > k + 1 then exit;
  if ( good[ curr ] ) or ( curr = 1 ) then begin
    good[ curr ]:=true;
    exit;
  end;

  supercheck( p[curr] , time+1 , k );
  good[curr]:=good[ p[curr] ];

end;

function check( k : longint  ) : boolean;
var i : longint ;
begin

  for i:=1 to k do good[i]:=false;

  for i:=2 to k do begin

    supercheck( i , 0 , k );
    if not good[i] then exit( false );

  end;

  exit( true );

end;

procedure  solve( k , curr : longint );
var i : longint ;
begin

  if curr <= k then begin

    for i:=1 to k do begin
      p[curr]:=i;
      solve( k , curr + 1 );
    end;

  end
  else begin

    if check( k ) then inc( ans );
    //writeln( p[1] ,' ',p[2],' ',p[3],' ',ans);
  end;

end;

function power( a , b : longint ) : int64;
var res : int64;
begin

  if b = 0 then exit( 1 );

  if b mod 2 = 1 then res:=a else res:=1;

  res:=res * sqr( power( a , b div 2 ) ) ;
  res:=res mod modulo;

  exit( res );

end;

var k , n  : longint ;
    x : int64;
begin

  d[1]:=1; d[2]:=2; d[3]:=9; d[4]:=64; d[5]:=625; d[6]:=7776; d[7]:=117649;
  d[8]:=2097152;

  readln( n , k );

  x:=Power( n - k , n - k );

  writeln( ( x * d[k] ) mod modulo );

end.

//(n-m)^(n-m)*m^(m-1)

const modul=1000000007;

var n,m,ans: int64;

function pow(x,y: int64): int64;
begin
  if y=0 then pow:=1
  else
  begin
    if y mod 2=1 then pow:=(pow(x,y-1)*x) mod MODUL
    else pow:=sqr(pow(x,y shr 1)) mod MODUL;
  end;
end;

begin
  readln(n,m);

  ans:=(pow(n-m,n-m)*pow(m,m-1)) mod MODUL;

  if n=m then ans:=0;

  writeln(ans);
end.

const c=1000000007;
var q,ans: qword;
    n,k,i,j: longint;
   begin
    readln(n,k);
    ans:=1;
    q:=k;
    for i:=1 to k div 2 do ans:=(ans*q) mod c;
    q:=q div 2;
    for i:=k div 2+1 to k do ans:=(ans*q) mod c;
    if k=1 then ans:=1;
    q:=n-k;
    for i:=k+1 to n do ans:=(ans*q) mod c;
    writeln(ans);
   end.

const c=1000000007;
var q,ans: qword;
    n,k,i,j: longint;
   begin
    readln(n,k);
    ans:=1;
    q:=k;
    for i:=1 to k div 2 do ans:=(ans*q) mod c;
    q:=q div 2;
    for i:=k div 2+1 to k do ans:=(ans*q) mod c;
    q:=n-k;
    for i:=k+1 to n do ans:=(ans*q) mod c;
    writeln(ans);
   end.

const MO=1000000007;
Var
n,k,i,j:longint;
ans:int64;

Begin
read(n,k);
ans:=1;
for i:=1 to k-1 do
ans:=(ans*k) mod MO;

 for i:=1 to (n-k)  do
 ans:=(ans*(n-k)) mod MO;
if k=1 then writeln(0) else writeln(ans);
End.

const inf=1000000007;
var n,m,s:int64;
function binPOW(n,m:int64):int64;
begin
  if m=0 then binPOW:=1
         else begin
                if m mod 2=1 then binPOW:=(binPOW(n,m-1)*n) mod inf
                             else binPOW:=sqr(binPOW(n,m shr 1)) mod inf;
              end;
end;
begin
  readln(n,m);
  if (n=m) or (n=0) or (m=0) then begin
                                    writeln(0);
                                    halt;
                                  end;
  s:=(binPOW(n-m,n-m)*binPOW(m,m-1)) mod inf;
  writeln(s);
end.

const inf=1000000007;
var n,m,s:int64;
function binPOW(n,m:int64):int64;
begin
  if m=0 then binPOW:=1
         else begin
                if m mod 2=1 then binPOW:=(binPOW(n,m-1)*n) mod inf
                             else binPOW:=sqr(binPOW(n,m shr 1)) mod inf;
              end;
end;
begin
  readln(n,m);
  if n=m then begin
                writeln(0);
                halt;
              end;
  s:=(binPOW(n-m,n-m)*binPOW(m,m-1)) mod inf;
  writeln(s);
end.

const md=1000000007;
var n,k,br,m,i,r,br1:longint;
    nb,nb1,niz:array[0..100] of longint;
procedure rek(x:longint);
var i,j:longint;
begin
  if x>k then
   begin
     inc(br);
     for j:=1 to k do
      begin
        i:=j;
        inc(br1);
        while (i<>1) and (nb[i]<>br) do
         begin
           nb1[i]:=br1;
           i:=niz[i];
           if nb1[i]=br1 then exit;
         end;
        nb[j]:=br;
      end;
     inc(r);
     exit;
   end;
  for i:=1 to k do
   begin
     niz[x]:=i;
     rek(x+1);
   end;
end;
begin
  readln(n,k);
  rek(1);
  writeln(r);
  m:=n-k;
  for i:=1 to m do
   r:=(r*m) mod md;
  writeln(r);
end.

const md=1000000007;
var n,k,br,m,i,r,br1:longint;
    nb,nb1,niz:array[0..100] of longint;
procedure rek(x:longint);
var i,j:longint;
begin
  if x>k then
   begin
     inc(br);
     for j:=1 to k do
      begin
        i:=j;
        inc(br1);
        while (i<>1) and (nb[i]<>br) do
         begin
           nb1[i]:=br1;
           i:=niz[i];
           if nb1[i]=br1 then exit;
         end;
        nb[j]:=br;
      end;
     inc(r);
     exit;
   end;
  for i:=1 to k do
   begin
     niz[x]:=i;
     rek(x+1);
   end;
end;
begin
  readln(n,k);
  rek(1);
  m:=n-k;
  if m>0 then
   for i:=1 to m do
    r:=(r*m) mod md;
  writeln(r);
end.

const md=1000000007;
var n,k,br,m,i,r,br1:longint;
    nb,nb1,niz:array[0..100] of longint;
procedure rek(x:longint);
var i,j:longint;
begin
  if x>k then
   begin
     inc(br);
     for j:=1 to k do
      begin
        i:=j;
        inc(br1);
        while (i<>1) and (nb[i]<>br) do
         begin
           nb1[i]:=br1;
           i:=niz[i];
           if nb1[i]=br1 then exit;
         end;
        nb[j]:=br;
      end;
     inc(r);
     exit;
   end;
  for i:=1 to k do
   begin
     niz[x]:=i;
     rek(x+1);
   end;
end;
begin
  readln(n,k);
  rek(1);
  m:=n-k;
  for i:=1 to m do
   r:=(r*m) mod md;
  writeln(r);
end.

const md=1000000007;
var n,k,br,m,i,br1:longint;
r:longint;
    nb,nb1,niz:array[0..100] of longint;
procedure rek(x:longint);
var i,j:longint;
begin
  if x>k then
   begin
     inc(br);
     for j:=1 to k do
      begin
        i:=j;
        inc(br1);
        while (i<>1) and (nb[i]<>br) do
         begin
           nb1[i]:=br1;
           i:=niz[i];
           if nb1[i]=br1 then exit;
         end;
        nb[j]:=br;
      end;
     inc(r);
     exit;
   end;
  for i:=1 to k do
   begin
     niz[x]:=i;
     rek(x+1);
   end;
end;
begin
  readln(n,k);
  rek(1);
  m:=n-k;
  if m>0 then
   for i:=1 to m do
    r:=(r*m) mod md;
  writeln(r);
end.

const
maxn=1000000007;
var
i : longint;
n,k,t,y : int64;
begin
  readln(n,k);
  t:=1;
  for i:=1 to n-k do
  t:=t*(n-k) mod maxn;
  y:=1;
  for i:=1 to k-1 do
   y:=y*k mod maxn;
  writeln(t*y);
end.

program p2;

Uses Sysutils, Math;

Var n, k, ans: int64; i: integer;

begin
 readln(n, k);
 ans := 1;
 for i := 1 to k - 1 do
  ans := (ans * k) mod 1000000007;
 for i := n - k + 1 to n do
  ans := (ans * (n - k)) mod 1000000007;
 writeln(ans);
end.