public static final void nbest_sign(final float[] in,
                                      final int offset,
                                      final float[] codebook,
                                      final int len,
                                      final int entries,
                                      final float[] E,
                                      final int N,
                                      final int[] nbest,
                                      final float[] best_dist)
  {
    int i, j, k, l=0, sign, used=0;
    for (i=0;i<entries;i++) {
      float dist=0;
      for (j=0;j<len;j++)
        dist -= in[offset+j]*codebook[l++];
      if (dist>0) {
        sign=1;
        dist=-dist;
      }
      else {
        sign=0;
      }
      dist += .5*E[i];
      if (i<N || dist<best_dist[N-1]) {
        for (k=N-1; (k >= 1) && (k > used || dist < best_dist[k-1]); k--)
        {
          best_dist[k]=best_dist[k-1];
          nbest[k] = nbest[k-1];
        }
        best_dist[k]=dist;
        nbest[k]=i;
        used++;
        if (sign != 0)
          nbest[k]+=entries;
      }
    }
  }