#include using namespace std; long long ap(long long a, long long d, long long n){ return (2 * a + (n - 1) * d) * n / 2; } int get(int B, int M, int E, int t){ int cnt = (B - M) / E + 1; long long T = ap(B * 2, -E * 2, cnt); if (t <= T){ int tv = 0, fv = (B - M) / E + 1; while (fv - tv > 1){ int mid = (tv + fv) / 2; if (ap(B * 2, -E * 2, mid) <= t){ tv = mid; } else { fv = mid; } } long long t2 = ap(B * 2, -E * 2, tv); t -= t2; if (tv % 2 == 0){ int a = B - E * tv; if (t <= a){ return t; } else { return a * 2 - t; } } else { int a = B - E * tv; if (t <= a){ return -t; } else { return -(a * 2 - t); } } } else { t -= T; t %= M * 4; int ans; if (t < M){ ans = t; } else if (t < M * 3){ ans = M * 2 - t; } else { ans = t - M * 4; } if (cnt % 2 == 1){ ans *= -1; } return ans; } } long long get_score_1(int N, int K, vector &T, vector &B, vector &M, vector &E){ long long S = 0; for (int i = 0; i < K; i++){ vector X(N); for (int j = 0; j < N; j++){ X[j] = get(B[j], M[j], E[j], T[i]); } double ans = 0; for (int j = 0; j < N; j++){ for (int k = j + 1; k < N; k++){ ans += (double) abs(X[j] - X[k]) / (B[j] + B[k]); } } ans *= 20000000; ans /= N; ans /= N - 1; S += ans; } return S; } long long get_score_2(int N, int K, vector &U, vector &B, vector &M, vector &E){ long long S = 0; for (int i = 0; i < K; i++){ vector X(N); for (int j = 0; j < N; j++){ X[j] = get(B[j], M[j], E[j], U[i]); } int mx = 0; for (int j = 0; j < N; j++){ for (int k = j + 1; k < N; k++){ mx = max(mx, abs(X[k] - X[j])); } } double ans = (double) mx / 20 + 1; ans = 10000000 / sqrt(ans); S += ans; } return S; } long long get_score(int N, int K, vector &T, vector &U, vector &B, vector &M, vector &E){ long long S1 = get_score_1(N, K, T, B, M, E) / K; long long S2 = get_score_2(N, K, U, B, M, E) / K; return S1 * S2; } void generate(int K, vector &T, vector &U){ int D = 200; vector G(K * 2 + 1); mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); uniform_real_distribution<> dist(0.0, 1.0); while (true){ vector F(K * 2, 0); for (int i = 0; i < K * 2; i++){ while (F[i] == 0){ F[i] = dist(mt); } } G[0] = 0; bool ok = true; for (int i = 0; i < K * 2; i++){ int c = D / F[i]; if (G[i] + c > 1000000000){ ok = false; break; } G[i + 1] = G[i] + c; } if (ok){ break; } } T.resize(K); U.resize(K); for (int i = 0; i < K; i++){ T[i] = G[i * 2 + 1]; U[i] = G[i * 2 + 2]; } if (mt() % 2 == 0){ swap(T, U); } } void solve(int N, int K, vector &T, vector &U, vector &B, vector &M, vector &E){ mt19937 mt(0); B.resize(N); M.resize(N); E.resize(N); for (int i = 0; i < N; i++){ B[i] = mt() % 10 + 1; M[i] = mt() % B[i] + 1; E[i] = mt() % 3 + 1; } long long mx = get_score(N, K, T, U, B, M, E); for (int i = 0; i < 1000; i++){ int p = mt() % N; vector B2 = B, M2 = M, E2 = E; B2[p] = mt() % 10 + 1; M2[p] = mt() % B2[p] + 1; E2[p] = mt() % 3 + 1; long long x = get_score(N, K, T, U, B2, M2, E2); if (x > mx){ mx = x; B = B2; M = M2; E = E2; } } } long long test(int N, int K){ long long ans = 0; for (int i = 0; i < 50; i++){ vector T, U; generate(K, T, U); vector B, M, E; solve(N, K, T, U, B, M, E); ans += get_score(N, K, T, U, B, M, E); } return ans; } int main(){ //cout << test(50, 50) << endl; int N, K; cin >> N >> K; vector T(N); for (int i = 0; i < N; i++){ cin >> T[i]; } vector U(N); for (int i = 0; i < N; i++){ cin >> U[i]; } vector B, M, E; solve(N, K, T, U, B, M, E); for (int i = 0; i < N; i++){ cout << B[i] << ' ' << M[i] << ' ' << E[i] << endl; } }