#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; constexpr int inf = 1e9 + 7; constexpr ll longinf = 1LL << 60; constexpr ll mod = 1e9 + 7; struct Xor128 { unsigned x, y, z, w; Xor128(unsigned w_ = 88675123) : x(123456789), y(362436069), z(521288629), w(w_){}; inline unsigned xor128() { unsigned t; t = x ^ (x << 11); x = y; y = z; z = w; return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); } int nextInt(int x, int y) { if(x > y) swap(x, y); return xor128() % (y - x) + x; } double nextDouble(double a, double b) { return (double)(xor128() & 0xffff) / 0xffff * (b - a) + a; } }; int dist[200][200]; int N = 3000, T = 400, M = 196; int cost[3030]; int s[3030], t[3030]; int NC = 100000, NH = 22301; void input() { int _; cin >> _ >> _; rep(i, N) { int a, b, c, d; cin >> a >> b >> c >> d; --a; --b; --c; --d; s[i] = a * 14 + b; t[i] = c * 14 + d; } } pair etov(int e) { int x, y; if(e < 13 * 14) { x = (e / 13) * 14 + e % 13; y = x + 1; } else { e -= 13 * 14; x = e; y = e + 14; } return {x, y}; } struct State { int score; int dist[196][196]; vector result; vector up; State() : result(0), score(0), up(0) { rep(i, 196) rep(j, 196) { dist[i][j] = NC * 50; } rep(i, 14) rep(j, 14) { int x = i * 14 + j; if(j > 0) { dist[x][x - 1] = NC; } if(j < 13) { dist[x][x + 1] = NC; } if(i > 0) { dist[x][x - 14] = NC; } if(i < 13) { dist[x][x + 14] = NC; } dist[x][x] = 0; } rep(i, M) rep(j, M) rep(k, M) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } static State getNewState(State &s, int e, int score) { s.result.push_back(e); s.up.push_back(score - s.score); auto [v1, v2] = etov(e); s.dist[v1][v2] = NH; s.dist[v2][v1] = NH; rep(i, M) rep(j, M) { s.dist[i][j] = min(s.dist[i][j], min(s.dist[i][v1] + s.dist[v2][j] + NH, s.dist[i][v2] + s.dist[v1][j] + NH)); } s.score = score; return s; } int getNextScore(int e) { int res = 0; auto [v1, v2] = etov(e); rep(i, N) { int nc = min(dist[s[i]][t[i]], min(dist[s[i]][v1] + dist[v2][t[i]] + NH, dist[s[i]][v2] + dist[v1][t[i]] + NH)); res += nc % 100; } return res + score; } }; auto rng = Xor128(); State search() { State s; vector bests; bests.emplace_back(s); rep(i, 90) { int t = i == 0 ? 400 : 40; priority_queue>> pq; rep(c, bests.size()) { rep(_, t) { int e = rng.nextInt(0, 2 * 14 * 13); int ns = bests[c].getNextScore(e); pq.push({ns, {-c, e}}); } } vector nb; rep(_, 27) { auto p = pq.top(); pq.pop(); int s = p.first, id = -p.second.first, e = p.second.second; State state = bests[id]; auto ns = State::getNewState(state, e, s); nb.emplace_back(ns); } nb.swap(bests); } return bests[0]; } int num = 0; void output(int e) { auto [x, y] = etov(e); cout << 1 << " "; cout << x / 14 + 1 << " " << x % 14 + 1 << " "; cout << y / 14 + 1 << " " << y % 14 + 1 << endl; } int cur = 0; int U = 1000000, V = 1; pair read() { // cerr << cur << " " << U << " " << V << endl; // return {U, V}; int u, v; cin >> u >> v; return {u, v}; } void turn(int t, State &state) { auto p = read(); int u = p.first, v = p.second; int ma = num < 90 ? state.up[num] : cur; int ben = 60 * (ma - cur) * (T - t); int pay = (int)(10000000 / sqrt(v)); cerr << ben << " " << pay << endl; if((ben > pay || num < 75) && u > pay) { output(state.result[num]); ++num; U = u - pay; cur = ma; } else { int npay = (int)(10000000 / sqrt(v + 1)); int dpay = max(0, min(90 - num, T - t - 1)) * (pay - npay); if(dpay > 50000) { cout << 2 << endl; V = v + 1; } else { cout << 3 << endl; U = u + 50000; } } U += cur * 60; } int main() { input(); State state = search(); rep(i, T) { turn(i, state); } cerr << U << " " << V << endl; cerr << num << endl; return 0; }