Problem: G: Code Art Online

Code Art Online (CAO) is an online RPG that advances adventures by solving various problems by programming. Since CAO was the world's first game that realized a virtual reality space, it was sold out while it was very popular, and users who purchased the game should enjoy this world. However, players who dive into the game are told a terrifying decree by the gamemaster.

"Unless some of you players solve the last problem of the last dungeon, you can't get out of this virtual space. And in this world, WA and TLE / RE mean death in the real world. I want you to start the problem with your heart. "

You are one of the CAO players, and you are doing your best to capture the game in order to clear this game and return to the real world. One day, you face the following problems.

This time, a party was formed with n members to capture the new dungeon. You are one of the parties. In order to enter the dungeon that you are about to capture, you must pass through a hole that can be seen from the cliff. If you can pass through the hole safely, you can enter the dungeon, but if you can not enter the hole and touch other parts, death is waiting. Furthermore, if someone passes through one hole, that hole will close, so each person must enter a separate hole.

Holes and people are considered on a two-dimensional plane. The shape of the hole is a circle of various sizes, as shown in Fig. G-1. In the input, the length of the radius is given.

<image>
---
Figure G-1: Hole shape

As shown in Fig. G-2, the human shape is given as a polygonal cross section of the human (not necessarily convex). In the input, the vertices are given counterclockwise to represent the shape of the polygon. It can be assumed that any three points of a polygon do not line up on a straight line. Furthermore, it is assumed that polygonal line segments do not intersect each other except for the purpose of forming vertices. It may rotate freely to pass through the hole (however, rotation in the z-axis direction is prohibited). It is assumed that the vertices of a polygon representing a person can pass through the hole even if it is on the circumference of the hole.

<image>
---
Figure G-2: Human shape

You, who have the highest algorithm skills in the party, decided to solve the decision problem of whether everyone can pass through the hole safely. If you can pass it safely, indicate who should pass which hole.

* You will not die in this contest, but if you make a mistake, please solve it with the intention of dying.

Input

On the first line, the integer n (1 <= n <= 100), which represents the number of holes, and the integer m (1 <= m <= n), which represents the number of parties, are entered separated by spaces.

In the next line, n integers ri (1 <= ri <= 1000) representing the radius of the hole are entered, separated by spaces. These holes are counted as the 1st hole, the 2nd hole, ..., and the nth hole in the order of input.

Then, information on the shape of m people is input. For the information of one person, the number of vertices p (3 <= p <= 100) of the polygon is first input to the first line. In the following line p, the coordinates of the vertices of the polygon are given counterclockwise. Integers xi, yi (-1000 <= xi, yi <= 1000) representing one vertex are entered in each line, separated by spaces. People are counted as the 1st person, the 2nd person, ..., and the mth person in the order of input.

Output

Output the number of hole that the person with i (1 <= i <= m) should enter. On the i-line, output the number of the hole that the person i should pass through.

If there are multiple paths, output the smallest path in lexicographical order. When there are two sequences A = {a1, a2, ..., am} and B = {b1, b2, ..., bm}, if A is smaller than B in lexicographical order, ai is bi. For the first i that is different, we say when ai is smaller than bi.

If no way is found, output one line as "NG". Don't forget to print a newline at the end.

Sample Input 1


3 3
25 100 10
8
-10 0
-twenty two
0 10
twenty two
10 0
twenty two
0 -10
-twenty two
Four
30 0
50 0
50 40
30 40
3
30 -10
45 -70
60 -10


Sample Output 1


3
1
2


Sample Input 2


4 3
25 15 15 30
Five
0 0
10 0
20 10
0 20
-20 10
3
20 0
40 0
30 10
3
-50 0
-30 0
-40 10


Sample Output 2


1
2
3


Sample Input 3


twenty two
1 30
Four
0 0
10 0
10 10
0 10
3
5 5
20 20
5 20


Sample Output 3


NG






Example

Input

3 3
25 100 10
8
-10 0
-2 2
0 10
2 2
10 0
2 -2
0 -10
-2 -2
4
30 0
50 0
50 40
30 40
3
30 -10
45 -70
60 -10


Output

3
1
2

Solution (in CPP):

Solution:
#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

class Point{
public:
  double x,y;

  Point(double x = 0,double y = 0): x(x),y(y){}

  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  Point operator * (Point a){ return Point(x * a.x - y * a.y, x * a.y + y * a.x); }

  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:y<p.y; }

  bool operator == (const Point& p)const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; }

};

struct Segment{
  Point p1,p2;
  Segment(Point p1 = Point(),Point p2 = Point()):p1(p1),p2(p2){}
  bool operator == (const Segment& p)const { return p.p1 == p1 && p.p2 == p2; }
};

typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;

ostream& operator << (ostream& os,const Point& a){ os << "(" << a.x << "," << a.y << ")"; }

ostream& operator << (ostream& os,const Segment& a){ os << "( " << a.p1 << " , " << a.p2 << " )"; }

double dot(Point a,Point b){ return a.x*b.x + a.y*b.y; }

double cross(Point a,Point b){ return a.x*b.y - a.y*b.x; }

double norm(Point a){ return a.x*a.x+a.y*a.y; }

double abs(Point a){ return sqrt(norm(a)); }

//rad は角度をラジアンで持たせること
Point rotate(Point a,double rad){ return Point(cos(rad)*a.x - sin(rad)*a.y,sin(rad)*a.x + cos(rad)*a.y); }

// 度をラジアンに変換
double toRad(double agl){ return agl*M_PI/180.0; }

// a => prev, b => cur, c=> next
// prev から cur へ行って next へ行く際の角度を求める
double getArg(Point a,Point b,Point c){
  double arg1 = atan2(b.y-a.y,b.x-a.x);
  double arg2 = atan2(c.y-b.y,c.x-b.x);
  double arg = fabs( arg1 - arg2 );
  while( arg > M_PI ) arg -= 2.0 * M_PI;
  return fabs(arg);
}

int ccw(Point p0,Point p1,Point p2){
  Point a = p1-p0;
  Point b = p2-p0;
  if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS)return CLOCKWISE;
  if(dot(a,b) < -EPS)return ONLINE_BACK;
  if(norm(a) < norm(b))return ONLINE_FRONT;
  return ON_SEGMENT;
}

Polygon andrewScan(Polygon s)
{
  Polygon u,l;
  if(s.size() < 3)return s;

  sort(s.begin(),s.end());

  u.push_back(s[0]);
  u.push_back(s[1]);
  l.push_back(s[s.size()-1]);
  l.push_back(s[s.size()-2]);

  for(int i=2;i<s.size();i++)
    {
      for(int n=u.size();n >= 2 && ccw(u[n-2],u[n-1],s[i]) != CLOCKWISE; n--)
	u.pop_back();
      u.push_back(s[i]);
    }

  for(int i=s.size()-3; i>=0 ; i--)
    {
      for(int n=l.size(); n >= 2 && ccw(l[n-2],l[n-1],s[i]) != CLOCKWISE; n--)
	l.pop_back();
      l.push_back(s[i]);
    }

  reverse(l.begin(),l.end());

  for(int i = u.size()-2; i >= 1; i--) l.push_back(u[i]);

  return l;
}

vector<int> G[310];
int match[310];
bool used[310];
int V;
void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v){
  used[v] = true;
  for(int i=0;i<G[v].size();i++){
    int u = G[v][i], w = match[u];
    if( w < 0 || !used[w] && dfs(w) ) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching(){
  int res = 0;
  memset(match,-1,sizeof(match));
  rep(v,V){
    if( match[v] < 0 ) {
      memset(used,0,sizeof(used));
      if( dfs(v) ) res++;
    }
  }
  return res;
}


int n,m;
double r[110],poly_r[110];
Polygon vec[110];
Point ps[110];
vector<int> cand[110];

inline double dist(Point a) { return sqrt(a.x*a.x+a.y*a.y); }
bool LT(double a,double b)  { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return  equals(a,b) || a < b; }

Point calc_ps(Polygon poly) {
  poly = andrewScan(poly);
  Point mp = poly[0];
  double rate = 1;
  int max_pos;
  double eps = 1e-10;
  while( rate > eps ) {
    rep(_,60){
      max_pos = 0;
      REP(j,1,poly.size()) {
        double dist1 = dist(mp-poly[max_pos]);
        double dist2 = dist(mp-poly[j]);
        if( !fabs(dist1-dist2) < eps && dist1 < dist2 ) max_pos = j;
      }
      mp.x += ( poly[max_pos].x - mp.x ) * rate;
      mp.y += ( poly[max_pos].y - mp.y ) * rate;
    }
    rate *= 0.5;
  }
  return mp;
}

int main(){
  cin >> n >> m;
  V = n + m;
  rep(i,n) cin >> r[i];
  rep(i,m) {
    int p;
    cin >> p;
    vec[i].resize(p);
    rep(j,p) cin >> vec[i][j].x >> vec[i][j].y;
  }

  rep(i,m) ps[i] = calc_ps(vec[i]);

  rep(i,m) {
    double maxi = dist(ps[i]-vec[i][0]);
    REP(j,1,vec[i].size()) maxi = max(maxi,dist(ps[i]-vec[i][j]));
    poly_r[i] = maxi;
  }

  set<int> S[n];
  rep(i,n) {
    rep(j,m){
      if( LTE(poly_r[j],r[i]) ) { cand[i].push_back(j); S[i].insert(j); }
    }
  }
  int ans[m];
  bool completed[n];
  rep(i,m) ans[i] = -1;
  rep(i,n) completed[i] = false;
  rep(i,m) {
    rep(j,n) if( !completed[j] && !cand[j].empty() ){
      if( !S[j].count(i) ) continue;
      rep(k,V) G[k].clear();
      rep(k,n) if( k != j && !completed[k] )rep(l,cand[k].size()) {
        if( cand[k][l] == i || ans[cand[k][l]] != -1 ) continue;
        add_edge(cand[k][l],k+m);
      }
      int res = bipartite_matching();
      if( res == m - i - 1 ) {
        ans[i] = j + 1;
        completed[j] = true;
        goto Skip;
      }
    }
  Skip:;
    if( ans[i] == -1 ) {
      puts("NG");
      return 0;
    }
  }

  rep(i,m) cout << ans[i] << endl;
  return 0;
}