Problem:
Problem A: K Cards

ある日、先生は次のようなゲームを思いついた。

ゲームは 1 から 10 までの数がひとつ書かれたカードを n 枚使用し、以下のように進む。

先生が n 枚のカードを数が見えるようにして横一列に黒板に貼り付け、ある整数 k (k ≥ 1) を生徒に宣言する。横一列に並べられた n 枚のカードについて、連続した k 枚のカードの積の最大値を Ck とする。また、先生が並べた時点での Ck を Ck' とおく。

生徒は 1. で貼られたカードの列を見て Ck を大きくすることを考える。ある 2 枚を入れ替えることで Ck をより大きくすることができた場合、生徒の成績は Ck - Ck' 点上がる。誰かが成績点を得たらゲームを終了する。

あなたの仕事は先生が並べたカードの列を入力し、生徒が得られる最大の成績点を出力するプログラムを書くことである。ただし、そこからどの 2 枚を選んで交換してもCkを下げることしかできない (Ck - Ck' < 0) 場合、文字列 "NO GAME" (引用符を含まない)を出力せよ。

先生が並べたカードが7, 2, 3, 5の場合。このとき 7 と 3 を交換することで生徒は最大で 35 - 15 = 20 成績点を得る。

Input

入力は複数のテストケースからなる。ひとつのテストケースは以下の形式に従う。

n k
c1
c2
c3
…
cn

n は先生が並べるカードの枚数、k は宣言する整数である。
また ci (1 ≤ i ≤ n) はカードに書かれた数を示す。また、この順で先生が横に黒板に貼り付けるとする。入力の終わりは、ふたつの0が一文字の空白で区切られる一行で示される。

Constraints

入力はすべて整数

2 ≤n ≤ 100

1 ≤k ≤ 5

k ≤ n

1 ≤ ci ≤ 10 (1 ≤ i ≤ n)

テストケースの数は 100 を超えない。

Output

生徒が得られる成績点の最大値あるいは文字列 "NO GAME" (引用符を含まない)を各テストケースに付き 1 行で出力せよ。

Sample Input

4 2
2
3
7
5
0 0

Sample Output

0

Hint

サンプルにおいて C2' = 35 であり、ここからどの 2 枚を並び替えても C2 の最大値は 35 より大きくならない。したがって生徒が得られる成績点は最大 0 点である。

Solution in JavaScript (judge verdict: Time Limit Exceeded)

// This program was compiled from OCaml by js_of_ocaml 1.3
function caml_raise_with_arg (tag, arg) { throw [0, tag, arg]; }
function caml_raise_with_string (tag, msg) {
  caml_raise_with_arg (tag, new MlWrappedString (msg));
}
function caml_invalid_argument (msg) {
  caml_raise_with_string(caml_global_data[4], msg);
}
function caml_array_bound_error () {
  caml_invalid_argument("index out of bounds");
}
function caml_str_repeat(n, s) {
  if (!n) { return ""; }
  if (n & 1) { return caml_str_repeat(n - 1, s) + s; }
  var r = caml_str_repeat(n >> 1, s);
  return r + r;
}
function MlString(param) {
  if (param != null) {
    this.bytes = this.fullBytes = param;
    this.last = this.len = param.length;
  }
}
MlString.prototype = {
  string:null,
  bytes:null,
  fullBytes:null,
  array:null,
  len:null,
  last:0,
  toJsString:function() {
    return this.string = decodeURIComponent (escape(this.getFullBytes()));
  },
  toBytes:function() {
    if (this.string != null)
      var b = unescape (encodeURIComponent (this.string));
    else {
      var b = "", a = this.array, l = a.length;
      for (var i = 0; i < l; i ++) b += String.fromCharCode (a[i]);
    }
    this.bytes = this.fullBytes = b;
    this.last = this.len = b.length;
    return b;
  },
  getBytes:function() {
    var b = this.bytes;
    if (b == null) b = this.toBytes();
    return b;
  },
  getFullBytes:function() {
    var b = this.fullBytes;
    if (b !== null) return b;
    b = this.bytes;
    if (b == null) b = this.toBytes ();
    if (this.last < this.len) {
      this.bytes = (b += caml_str_repeat(this.len - this.last, '\0'));
      this.last = this.len;
    }
    this.fullBytes = b;
    return b;
  },
  toArray:function() {
    var b = this.bytes;
    if (b == null) b = this.toBytes ();
    var a = [], l = this.last;
    for (var i = 0; i < l; i++) a[i] = b.charCodeAt(i);
    for (l = this.len; i < l; i++) a[i] = 0;
    this.string = this.bytes = this.fullBytes = null;
    this.last = this.len;
    this.array = a;
    return a;
  },
  getArray:function() {
    var a = this.array;
    if (!a) a = this.toArray();
    return a;
  },
  getLen:function() {
    var len = this.len;
    if (len !== null) return len;
    this.toBytes();
    return this.len;
  },
  toString:function() { var s = this.string; return s?s:this.toJsString(); },
  valueOf:function() { var s = this.string; return s?s:this.toJsString(); },
  blitToArray:function(i1, a2, i2, l) {
    var a1 = this.array;
    if (a1) {
      if (i2 <= i1) {
        for (var i = 0; i < l; i++) a2[i2 + i] = a1[i1 + i];
      } else {
        for (var i = l - 1; i >= 0; i--) a2[i2 + i] = a1[i1 + i];
      }
    } else {
      var b = this.bytes;
      if (b == null) b = this.toBytes();
      var l1 = this.last - i1;
      if (l <= l1)
        for (var i = 0; i < l; i++) a2 [i2 + i] = b.charCodeAt(i1 + i);
      else {
        for (var i = 0; i < l1; i++) a2 [i2 + i] = b.charCodeAt(i1 + i);
        for (; i < l; i++) a2 [i2 + i] = 0;
      }
    }
  },
  get:function (i) {
    var a = this.array;
    if (a) return a[i];
    var b = this.bytes;
    if (b == null) b = this.toBytes();
    return (i<this.last)?b.charCodeAt(i):0;
  },
  safeGet:function (i) {
    if (!this.len) this.toBytes();
    if ((i < 0) || (i >= this.len)) caml_array_bound_error ();
    return this.get(i);
  },
  set:function (i, c) {
    var a = this.array;
    if (!a) {
      if (this.last == i) {
        this.bytes += String.fromCharCode (c & 0xff);
        this.last ++;
        return 0;
      }
      a = this.toArray();
    } else if (this.bytes != null) {
      this.bytes = this.fullBytes = this.string = null;
    }
    a[i] = c & 0xff;
    return 0;
  },
  safeSet:function (i, c) {
    if (this.len == null) this.toBytes ();
    if ((i < 0) || (i >= this.len)) caml_array_bound_error ();
    this.set(i, c);
  },
  fill:function (ofs, len, c) {
    if (ofs >= this.last && this.last && c == 0) return;
    var a = this.array;
    if (!a) a = this.toArray();
    else if (this.bytes != null) {
      this.bytes = this.fullBytes = this.string = null;
    }
    var l = ofs + len;
    for (var i = ofs; i < l; i++) a[i] = c;
  },
  compare:function (s2) {
    if (this.string != null && s2.string != null) {
      if (this.string < s2.string) return -1;
      if (this.string > s2.string) return 1;
      return 0;
    }
    var b1 = this.getFullBytes ();
    var b2 = s2.getFullBytes ();
    if (b1 < b2) return -1;
    if (b1 > b2) return 1;
    return 0;
  },
  equal:function (s2) {
    if (this.string != null && s2.string != null)
      return this.string == s2.string;
    return this.getFullBytes () == s2.getFullBytes ();
  },
  lessThan:function (s2) {
    if (this.string != null && s2.string != null)
      return this.string < s2.string;
    return this.getFullBytes () < s2.getFullBytes ();
  },
  lessEqual:function (s2) {
    if (this.string != null && s2.string != null)
      return this.string <= s2.string;
    return this.getFullBytes () <= s2.getFullBytes ();
  }
}
function MlWrappedString (s) { this.string = s; }
MlWrappedString.prototype = new MlString();
function MlMakeString (l) { this.bytes = ""; this.len = l; }
MlMakeString.prototype = new MlString ();
function caml_array_get (array, index) {
  if ((index < 0) || (index >= array.length - 1)) caml_array_bound_error();
  return array[index+1];
}
function caml_array_set (array, index, newval) {
  if ((index < 0) || (index >= array.length - 1)) caml_array_bound_error();
  array[index+1]=newval; return 0;
}
function caml_call_gen(f, args) {
  if(f.fun)
    return caml_call_gen(f.fun, args);
  var n = f.length;
  var d = n - args.length;
  if (d == 0)
    return f.apply(null, args);
  else if (d < 0)
    return caml_call_gen(f.apply(null, args.slice(0,n)), args.slice(n));
  else
    return function (x){ return caml_call_gen(f, args.concat([x])); };
}
function caml_parse_format (fmt) {
  fmt = fmt.toString ();
  var len = fmt.length;
  if (len > 31) caml_invalid_argument("format_int: format too long");
  var f =
    { justify:'+', signstyle:'-', filler:' ', alternate:false,
      base:0, signedconv:false, width:0, uppercase:false,
      sign:1, prec:-1, conv:'f' };
  for (var i = 0; i < len; i++) {
    var c = fmt.charAt(i);
    switch (c) {
    case '-':
      f.justify = '-'; break;
    case '+': case ' ':
      f.signstyle = c; break;
    case '0':
      f.filler = '0'; break;
    case '#':
      f.alternate = true; break;
    case '1': case '2': case '3': case '4': case '5':
    case '6': case '7': case '8': case '9':
      f.width = 0;
      while (c=fmt.charCodeAt(i) - 48, c >= 0 && c <= 9) {
        f.width = f.width * 10 + c; i++
      }
      i--;
     break;
    case '.':
      f.prec = 0;
      i++;
      while (c=fmt.charCodeAt(i) - 48, c >= 0 && c <= 9) {
        f.prec = f.prec * 10 + c; i++
      }
      i--;
    case 'd': case 'i':
      f.signedconv = true; /* fallthrough */
    case 'u':
      f.base = 10; break;
    case 'x':
      f.base = 16; break;
    case 'X':
      f.base = 16; f.uppercase = true; break;
    case 'o':
      f.base = 8; break;
    case 'e': case 'f': case 'g':
      f.signedconv = true; f.conv = c; break;
    case 'E': case 'F': case 'G':
      f.signedconv = true; f.uppercase = true;
      f.conv = c.toLowerCase (); break;
    }
  }
  return f;
}
function caml_finish_formatting(f, rawbuffer) {
  if (f.uppercase) rawbuffer = rawbuffer.toUpperCase();
  var len = rawbuffer.length;
  if (f.signedconv && (f.sign < 0 || f.signstyle != '-')) len++;
  if (f.alternate) {
    if (f.base == 8) len += 1;
    if (f.base == 16) len += 2;
  }
  var buffer = "";
  if (f.justify == '+' && f.filler == ' ')
    for (var i = len; i < f.width; i++) buffer += ' ';
  if (f.signedconv) {
    if (f.sign < 0) buffer += '-';
    else if (f.signstyle != '-') buffer += f.signstyle;
  }
  if (f.alternate && f.base == 8) buffer += '0';
  if (f.alternate && f.base == 16) buffer += "0x";
  if (f.justify == '+' && f.filler == '0')
    for (var i = len; i < f.width; i++) buffer += '0';
  buffer += rawbuffer;
  if (f.justify == '-')
    for (var i = len; i < f.width; i++) buffer += ' ';
  return new MlWrappedString (buffer);
}
function caml_format_int(fmt, i) {
  if (fmt.toString() == "%d") return new MlWrappedString(""+i);
  var f = caml_parse_format(fmt);
  if (i < 0) { if (f.signedconv) { f.sign = -1; i = -i; } else i >>>= 0; }
  var s = i.toString(f.base);
  if (f.prec >= 0) {
    f.filler = ' ';
    var n = f.prec - s.length;
    if (n > 0) s = caml_str_repeat (n, '0') + s;
  }
  return caml_finish_formatting(f, s);
}
function caml_int64_compare(x,y) {
  var x3 = x[3] << 16;
  var y3 = y[3] << 16;
  if (x3 > y3) return 1;
  if (x3 < y3) return -1;
  if (x[2] > y[2]) return 1;
  if (x[2] < y[2]) return -1;
  if (x[1] > y[1]) return 1;
  if (x[1] < y[1]) return -1;
  return 0;
}
function caml_int_compare (a, b) {
  if (a < b) return (-1); if (a == b) return 0; return 1;
}
function caml_compare_val (a, b, total) {
  var stack = [];
  for(;;) {
    if (!(total && a === b)) {
      if (a instanceof MlString) {
        if (b instanceof MlString) {
            if (a != b) {
		var x = a.compare(b);
		if (x != 0) return x;
	    }
        } else
          return 1;
      } else if (a instanceof Array && a[0] === (a[0]|0)) {
        var ta = a[0];
        if (ta === 250) {
          a = a[1];
          continue;
        } else if (b instanceof Array && b[0] === (b[0]|0)) {
          var tb = b[0];
          if (tb === 250) {
            b = b[1];
            continue;
          } else if (ta != tb) {
            return (ta < tb)?-1:1;
          } else {
            switch (ta) {
            case 248: {
		var x = caml_int_compare(a[2], b[2]);
		if (x != 0) return x;
		break;
	    }
            case 255: {
		var x = caml_int64_compare(a, b);
		if (x != 0) return x;
		break;
	    }
            default:
              if (a.length != b.length) return (a.length < b.length)?-1:1;
              if (a.length > 1) stack.push(a, b, 1);
            }
          }
        } else
          return 1;
      } else if (b instanceof MlString ||
                 (b instanceof Array && b[0] === (b[0]|0))) {
        return -1;
      } else {
        if (a < b) return -1;
        if (a > b) return 1;
        if (total && a != b) {
          if (a == a) return 1;
          if (b == b) return -1;
        }
      }
    }
    if (stack.length == 0) return 0;
    var i = stack.pop();
    b = stack.pop();
    a = stack.pop();
    if (i + 1 < a.length) stack.push(a, b, i + 1);
    a = a[i];
    b = b[i];
  }
}
function caml_compare (a, b) { return caml_compare_val (a, b, true); }
function caml_greaterequal (x, y) { return +(caml_compare(x,y,false) >= 0); }
function caml_parse_sign_and_base (s) {
  var i = 0, base = 10, sign = s.get(0) == 45?(i++,-1):1;
  if (s.get(i) == 48)
    switch (s.get(i + 1)) {
    case 120: case 88: base = 16; i += 2; break;
    case 111: case 79: base =  8; i += 2; break;
    case  98: case 66: base =  2; i += 2; break;
    }
  return [i, sign, base];
}
function caml_parse_digit(c) {
  if (c >= 48 && c <= 57)  return c - 48;
  if (c >= 65 && c <= 90)  return c - 55;
  if (c >= 97 && c <= 122) return c - 87;
  return -1;
}
var caml_global_data = [0];
function caml_failwith (msg) {
  caml_raise_with_string(caml_global_data[3], msg);
}
function caml_int_of_string (s) {
  var r = caml_parse_sign_and_base (s);
  var i = r[0], sign = r[1], base = r[2];
  var threshold = -1 >>> 0;
  var c = s.get(i);
  var d = caml_parse_digit(c);
  if (d < 0 || d >= base) caml_failwith("int_of_string");
  var res = d;
  for (;;) {
    i++;
    c = s.get(i);
    if (c == 95) continue;
    d = caml_parse_digit(c);
    if (d < 0 || d >= base) break;
    res = base * res + d;
    if (res > threshold) caml_failwith("int_of_string");
  }
  if (i != s.getLen()) caml_failwith("int_of_string");
  res = sign * res;
  if ((res | 0) != res) caml_failwith("int_of_string");
  return res;
}
function caml_js_get_console () {
  var c = this.console?this.console:{};
  var m = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
           "trace", "group", "groupCollapsed", "groupEnd", "time", "timeEnd"];
  function f () {}
  for (var i = 0; i < m.length; i++) if (!c[m[i]]) c[m[i]]=f;
  return c;
}
function caml_js_to_array(a) { return [0].concat(a); }
function caml_make_vect (len, init) {
  var b = [0]; for (var i = 1; i <= len; i++) b[i] = init; return b;
}
function caml_ml_out_channels_list () { return 0; }
function caml_mul(x,y) {
  return ((((x >> 16) * y) << 16) + (x & 0xffff) * y)|0;
}
function caml_register_global (n, v) { caml_global_data[n + 1] = v; }
var caml_named_values = {};
function caml_register_named_value(nm,v) {
  caml_named_values[nm] = v; return 0;
}
(function(){function F(bg,bh){return bg.length==1?bg(bh):caml_call_gen(bg,[bh]);}var a=[0,new MlString("Failure")],b=[0,new MlString("Invalid_argument")];caml_register_global(6,[0,new MlString("Not_found")]);caml_register_global(5,[0,new MlString("Division_by_zero")]);caml_register_global(3,b);caml_register_global(2,a);var l=new MlString("%d"),k=new MlString("Pervasives.do_at_exit"),j=[0,0,0],i=new MlString("split_n"),h=new MlString("NO GAME"),g=new MlString("get_input"),f=new MlString("\\s");function e(d,c){return caml_greaterequal(d,c)?d:c;}function n(m,o){if(m){var p=m[1];return [0,p,n(m[2],o)];}return o;}function u(t){var q=caml_ml_out_channels_list(0);for(;;){if(q){var r=q[2];try {}catch(s){}var q=r;continue;}return 0;}}caml_register_named_value(k,u);function J(v){var w=v.length-1-1|0,x=0;for(;;){if(0<=w){var z=[0,v[w+1],x],y=w-1|0,w=y,x=z;continue;}return x;}}function B(A){if(A){var C=A[1];return n(C,B(A[2]));}return 0;}function H(E,D){if(D){var G=D[2],I=F(E,D[1]);return [0,I,H(E,G)];}return 0;}var K=[0,0],O=RegExp,N=Array;function P(L){return L;}function Q(M){return M instanceof N?0:[0,new MlWrappedString(M.toString())];}K[1]=[0,Q,K[1]];var W=caml_js_get_console(0);function av(R,S){return F(S,R);}function U(T){return T.toString();}function aw(V){return W.log(U(V));}function _(X,Y){var Z=X<Y?1:0,$=Z?[0,X,_(X+1|0,Y)]:Z;return $;}function ax(ab,aa,ac){var ad=caml_array_get(ab,aa);caml_array_set(ab,aa,caml_array_get(ab,ac));return caml_array_set(ab,ac,ad);}function ag(af,ae){if(ae){if(0<af){var ah=ag(af-1|0,ae[2]);return [0,[0,ae[1],ah[1]],ah[2]];}return [0,0,ae];}if(0===af)return j;throw [0,b,i];}function ay(ai){return caml_int_of_string(ai);}function az(al,aj){function au(ak){if(aj.length-1<=((ak+al|0)-1|0))return -1;var am=1,an=0,ao=al-1|0;if(ao<an)var ap=am;else{var aq=an,ar=am;for(;;){var as=caml_mul(ar,caml_array_get(aj,ak+aq|0)),at=aq+1|0;if(ao!==aq){var aq=at,ar=as;continue;}var ap=as;break;}}return e(ap,au(ak+1|0));}return au(0);}var aB=require("fs").readFileSync("/dev/stdin", "utf8"),aD=F(H,function(aA){return new MlWrappedString(aA);});function aE(aC){return caml_js_to_array(aC);}var aF=av(av(av(av(aB.split(new O(U(f))),P),aE),J),aD);a:for(;;){if(aF){var aG=aF[2];if(aG){var aH=ay(aF[1]),aI=ay(aG[1]);if(0===aH&&0===aI){var aJ=0,aK=1;}else var aK=0;if(!aK){var aL=ag(aH,aG[2]),aM=aL[2],aJ=[0,[0,aH,aI,H(ay,aL[1]),aM]];}if(aJ){var aN=aJ[1],aO=aN[2],aP=aN[1],aQ=aN[3];if(aQ){var aR=0,aS=aQ,aY=aQ[2],aV=aQ[1];for(;;){if(aS){var aU=aS[2],aT=aR+1|0,aR=aT,aS=aU;continue;}var aW=caml_make_vect(aR,aV),aX=1,aZ=aY;for(;;){if(aZ){var a0=aZ[2];aW[aX+1]=aZ[1];var a1=aX+1|0,aX=a1,aZ=a0;continue;}var a2=aW;break;}break;}}else var a2=[0];var a3=az(aO,a2),a4=_(0,aP),a7=_(0,aP),ba=B(H(function(a4){return function(a6){return H(function(a5){return [0,a6,a5];},a4);};}(a4),a7)),bb=-1,bc=H(function(aO,a2){return function(a8){var a9=a8[2],a_=a8[1];ax(a2,a_,a9);var a$=az(aO,a2);ax(a2,a_,a9);return a$;};}(aO,a2),ba);for(;;){if(bc){var bd=bc[2],be=e(bb,bc[1]),bb=be,bc=bd;continue;}if(bb<a3)aw(h);else aw(caml_format_int(l,bb-a3|0));var bf=aN[4],aF=bf;continue a;}}u(0);return;}}throw [0,a,g];}}());