#include #define rep(i,n) for(int i=0; i=0; i--) #define pers(i,n,s) for(int i=n-1; i>=s; i--) #define all(v) v.begin(),v.end() #define fi first #define se second #define pb push_back #define si(v) int(v.size()) #define lb(v,n) lower_bound(all(v),n) #define lbi(v,n) int(lower_bound(all(v),n) - v.begin()) #define ub(v,n) upper_bound(all(v),n) #define ubi(v,n) int(upper_bound(all(v),n) - v.begin()) #define mod 1000000007 #define infi 1010000000 #define infl 1100000000000000000 #define outve(v) {for(auto i : v) cout << i << " ";cout << endl;} #define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;} #define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];} #define IN(n,m,v) rep(i,n) rep(j,m){cin >> v[i][j];} #define cyes cout << "Yes" << endl #define cno cout << "No" << endl #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define csp << " " << #define outset(n) cout << fixed << setprecision(n); using namespace std; using ll = long long; using ull = unsigned long long; using uint = unsigned int; using ld = long double; using vi = vector; using vvi = vector>; using vd = vector; using vvd = vector>; using vl = vector; using vvl = vector>; using vs = vector; using pii = pair; using pll = pair; template using ve = vector; template using vv = vector>; template using pq2 = priority_queue; template using pq1 = priority_queue,greater>; template bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;} template bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;} int popcnt(uint n) {return __builtin_popcount(n);} int popcntl(ull n) {return __builtin_popcountll(n);} int bsr(uint n) {return 31 - __builtin_clz(n);} int bsrl(ull n) {return 63 - __builtin_clzll(n);} int bsf(uint n) {return __builtin_ctz(n);} int bsfl(ull n) {return __builtin_ctzll(n);} unsigned int xorshift() { static unsigned int tx = 123456789, ty=362436069, tz=521288629, tw=88675123; unsigned int tt = (tx^(tx<<11)); tx = ty; ty = tz; tz = tw; return ( tw=(tw^(tw>>19))^(tt^(tt>>8)) ); } double TIME_LIMIT = 1.78; int LOCAL = 0; int TEATER = 0; constexpr int dh[4] = {-1,0,1,0}; constexpr int dw[4] = {0,-1,0,1}; constexpr int N = 14; constexpr int M = 3000; constexpr int T = 400; int home[M]; int company[M]; ll money,people; vvi road; void solve(){ int ti = clock(); double time = 1.0 * (clock() - ti) / CLOCKS_PER_SEC; int m,t; cin >> m >> t; int road[N][N]; rep(i,N) rep(j,N) road[i][j] = 0; int road_num = 0; rep(i,m) { int a,b,c,d; cin >> a >> b >> c >> d; a--,b--,c--,d--; home[i] = a*N+b; company[i] = c*N+d; } int build_road = 1; ll road_incom = 0; ll next_road_incom = -1; int next_hwk = -1; { ll score_max = -infl; int hwk = -1; rep(a,N) rep(b,N) rep(k,4) if(k == 2 || k == 3){ road[a][b] |= 1< pq; pq.push(0*10000+i*100+j); while (!pq.empty()) { ll chw = pq.top(); pq.pop(); ll c = chw/10000; int h = (chw%10000)/100, w = chw%100; if(D[s][h*N+w] < c) continue; rep(k,4) { int nh = h + dh[k], nw = w + dw[k]; if(nh < 0 || nh >= N || nw < 0 || nw >= N) continue; if(chmin(D[s][nh*N+nw], c+(road[h][w]&1<> money >> people; if(build_road==1 && people > 0 && money > ll(10000000.0/sqrt((double)people))){ if(road_num < 30 && next_hwk >= 0){ int x = next_hwk/1000, y = (next_hwk%1000)/10, k = next_hwk%10; int z = x + dh[k], w = y+dw[k]; cout << 1 csp x+1 csp y+1 csp z+1 csp w+1 << endl; if(LOCAL) money -= ll(10000000.0/sqrt((double)people)); road[x][y] |= 1<= N || nw < 0 || nw >= N) continue; if(road[nh][nw] & 1 << kk) ff++; } if(ff == 0) continue; time = 1.0 * (clock() - ti) / CLOCKS_PER_SEC; if(time > TIME_LIMIT) { score_max = -infl; build_road = 0; next_hwk = -1; break; } road[a][b] |= 1< pq; pq.push(0*10000+i*100+j); while (!pq.empty()) { ll chw = pq.top(); pq.pop(); ll c = chw/10000; int h = (chw%10000)/100, w = chw%100; if(D[s][h*N+w] < c) continue; rep(k,4) { int nh = h + dh[k], nw = w + dw[k]; if(nh < 0 || nh >= N || nw < 0 || nw >= N) continue; if(chmin(D[s][nh*N+nw], c+(road[h][w]&1< pq; pq.push(0*10000+i*100+j); while (!pq.empty()) { ll chw = pq.top(); pq.pop(); ll c = chw/10000; int h = (chw%10000)/100, w = chw%100; if(D[s][h*N+w] < c) continue; rep(k,4) { int nh = h + dh[k], nw = w + dw[k]; if(nh < 0 || nh >= N || nw < 0 || nw >= N) continue; if(chmin(D[s][nh*N+nw], c+(road[h][w]&1<