#include using namespace std; struct Cell { int d, i, j; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vector cells; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { char c; cin >> c; int d = c - '0'; if (d > 0) { cells.push_back({d, i, j}); } } } mt19937 rng(random_device{}()); // タイブレーク用に全体をシャッフル shuffle(cells.begin(), cells.end(), rng); // 乾燥度の降順(同じ乾燥度ならシャッフル順を維持) stable_sort(cells.begin(), cells.end(), [](const Cell& a, const Cell& b) { return a.d > b.d; }); int M = min(K, (int)cells.size()); cout << M << '\n'; for (int k = 0; k < M; k++) { cout << cells[k].i << ' ' << cells[k].j << '\n'; } return 0; }