#include #define fi first #define se second #define rep(i,s,n) for (int i = (s); i < (n); ++i) #define rrep(i,g,n) for (int i = (n)-1; i >= (g); --i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define len(x) (int)(x).size() #define dup(x,y) (((x)+(y)-1)/(y)) #define pb push_back #define eb emplace_back #define Field(T) vector> using namespace std; using ll = long long; using ull = unsigned long long; template using pq = priority_queue,greater>; using P = pair; templatebool chmax(T&a,T b){if(abool chmin(T&a,T b){if(b> n; if (n > 5) { cout << "Wow!" << endl; } vector> a(n, vector(n-1)); vector> b(n-1, vector(n)); uniform_int_distribution r(1, 300000); rep(i,0,n) rep(j,0,n-1) { a[i][j] = r(mt); } rep(i,0,n-1) rep(j,0,n) { b[i][j] = r(mt); } function f = [&]() { vector> G(n*n); rep(i,0,n) rep(j,0,n-1) { G[i*n+j].eb(i*n+j+1, a[i][j]); G[i*n+j+1].eb(i*n+j, a[i][j]); } rep(i,0,n-1) rep(j,0,n) { G[i*n+j].eb((i+1)*n+j, b[i][j]); G[(i+1)*n+j].eb(i*n+j, b[i][j]); } pq

que; vector> dist(n*n, vector(n*n, 1000000000)); rep(s,0,n*n) { que.emplace(0, s); dist[s][s] = 0; while(!que.empty()) { auto [c, v] = que.top(); que.pop(); if (dist[s][v] < c) continue; for (auto [nv, cost] : G[v]) { if (dist[s][nv] > dist[s][v]+cost) { dist[s][nv] = dist[s][v]+cost; que.emplace(dist[s][nv], nv); } } } } set st; rep(i,0,n*n) rep(j,i+1,n*n) st.emplace(dist[i][j]); rep(i,0,n*n) { rep(j,0,n*n) cout << dist[i][j] << " "; cout << endl; } cout << len(st) << " " << (n*n)*(n*n-1)/2 << endl; }; rep(i,0,n) { rep(j,0,n-1) { cout << a[i][j] << " "; } cout << endl; } rep(i,0,n-1) { rep(j,0,n) { cout << b[i][j] << " "; } cout << endl; } // f(); return 0; }