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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
   
using namespace std;
   

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define rforeach(it, c) for (__typeof__((c).rbegin()) it=(c).rbegin(); it != (c).rend(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))
#define COPY(dest, src) memcpy(dest, src, sizeof(dest))
#define ten(n) ((long long)(1e##n))
#define bin(n) (1LL << (n))

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

template <class T> void sort(vector<T>& c) { sort(c.begin(), c.end()); }
template <class T> void uniq(vector<T>& c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); }

template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }
  
template <class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { os << "( " << p.first << ", " << p.second << " )"; return os; }
  
template <class T> void print(T a, int n, const string& deli = " ", int br = 1) { for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } while (br--) cout << endl; }
template <class T> void print(const T& c, const string& deli = " ", int br = 1) { foreach (it, c) { cout << *it; if (++it != c.end()) cout << deli;--it; } while (br--) cout << endl; }
template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) {    if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }
   
template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
#define trace(x) (cout << #x << ": " << (x) << endl)

bool valid(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }


typedef long long ll;
typedef pair<int, int> pint;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
  
const double PI = acos(-1.0);
const int mod = 1000000007;



#include <valarray>

typedef double number;
typedef valarray<number> point;
const int dim = 2;

number dot(const point& a, const point& b) {
  return (a * b).sum();
}
point cross(const point& a, const point& b) {
  return a.cshift(+1)*b.cshift(-1)
       - a.cshift(-1)*b.cshift(+1);
}
number dist2(const point& a, const point& b) {
  return dot(a-b, a-b);
}
struct min_ball {
  point center;
  number radius2;
  void add(const point& p) {
    ps.push_back(p);
  }
  void compile() {
    m = 0;
    center.resize(dim, 0);
    radius2 = -1;
    make_ball(ps.end());
  }
  template <class OUT>
  void support(OUT out) {
    copy(ps.begin(), supp_end, out);
  }
  min_ball() {
    for (int i = 0; i <= dim; ++i) {
      c[i].resize(dim, 0);
      v[i].resize(dim, 0);
    }
  }
private:
  list<point> ps;
  list<point>::iterator supp_end;
  int m;
  point v[dim+1], c[dim+1];
  number z[dim+1], r[dim+1];
  void pop() { --m; }
  void push(const point& p) {
    if (m == 0) {
      c[0] = p; r[0] = 0;
    } else {
      number e = dist2(p, c[m-1]) - r[m-1];
      point delta = p - c[0];
      v[m] = p - c[0];
      for (int i = 1; i < m; ++i)
        v[m] -= v[i] * dot(v[i], delta) / z[i];
      z[m] = dot(v[m], v[m]);
      c[m] = c[m-1] + e*v[m]/z[m]/2;
      r[m] = r[m-1] + e*e/z[m]/4;
    }
    center  = c[m];
    radius2 = r[m]; ++m;
  }
  void make_ball(list<point>::iterator i) {
    supp_end = ps.begin();
    if (m == dim + 1) return;
    for (list<point>::iterator k = ps.begin(); k != i; ) {
      list<point>::iterator j = k++;
      if (dist2(*j, center) > radius2) {
        push(*j); make_ball(j); pop();
        move_to_front(j);
      }
    }
  }
  void move_to_front(list<point>::iterator j) {
    if (supp_end == j) ++supp_end;
    ps.splice (ps.begin(), ps, j);
  }
};
double min_radius_sq()
{
    int p;
    cin >> p;
    min_ball s;
    while (p--)
    {
        point pt(2);
        cin >> pt[0] >> pt[1];
        s.add(pt);
    }
    s.compile();
    return s.radius2;
}


class BipatiteGraph
{
	vector<bool> used;

	bool _dfs(int v)
	{
        if (used[v])
            return false;

		used[v] = true;
		for (int i = 0; i < edges[v].size(); ++i)
		{
			int u = edges[v][i];
			int k = match[u];
            if (used[u])
                continue;
			if (k < 0 || !used[k] && _dfs(k))
			{
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}

public:
	int n, m;
	int vertices;
	vector<vector<int> > edges;
	vector<int> match;
    int matching;

	BipatiteGraph(int n, int m)
		: used(n + m), n(n), m(m), vertices(n + m), edges(n + m), match(n + m), matching(0)
	{
        clear();

        fix_used = vector<bool>(n + m);
	}

	void add_edge(int a, int b)
	{
		edges[a].push_back(b + n);
		edges[b + n].push_back(a);
	}

    void clear()
    {
		fill(match.begin(), match.end(), -1);
        matching = 0;
    }

	bool dfs(int v)
	{
		// fill(used.begin(), used.end(), false);
        used = fix_used;
		return _dfs(v);
	}

    int update_matching()
    {
        for (int i = 0; i < n; ++i)
            if (match[i] < 0 && dfs(i))
                ++matching;
        return matching;
    }

	int max_matching()
	{
		fill(match.begin(), match.end(), -1);
		int res = 0;
		for (int i = 0; i < n; ++i)
		{
			if (match[i] < 0)
			{
				if (dfs(i))
					++res;
			}
		}
		return res;
	}

    vector<pair<int, int> > matching_edges()
    {
        vector<pair<int, int> > edges;
        for (int i = 0; i < n; ++i)
            if (match[i] >= 0)
               edges.push_back(make_pair(i, match[i] - n));
        return edges;
    }

    vector<bool> fix_used;
    void fix_left(int i, bool f) { fix_used[i] = f; }
    void fix_right(int i, bool f) { fix_used[n + i] = f; }
};
int main()
{
    int n, m, r[128];
    cin >> n >> m;
    rep(i, n)
    {
        cin >> r[i];
        r[i] = r[i] * r[i];
    }

    bool ok[128][128];
    rep(i, m)
    {
        double d = min_radius_sq();
        rep(j, n)
            ok[i][j] = d <= r[j] + 1e-9;
    }

    BipatiteGraph g(m, n);
    rep(i, m) rep(j, n)
        if (ok[i][j])
            g.add_edge(i, j);
    if (g.max_matching() < m)
    {
        cout << "NG" << endl;
        return 0;
    }

    bool used[128] = {};
    int match[128];
    rep(i, m)
    {
        g.fix_left(i, true);
        rep(j, n)
        {
            if (!used[j] && ok[i][j])
            {
                g.fix_right(j, true);
                if (g.max_matching() == m - (i + 1))
                {
                    match[i] = j + 1;
                    used[j] = true;
                    break;
                }
                g.fix_right(j, false);
            }
        }
    }

    rep(i, m)
        cout << match[i] << endl;
}