#include #include #include #include int main() { int w, h, k, p; std::cin >> w >> h >> k >> p; w++; h++; std::vector xs(k), ys(k); std::vector ns(k); for (int i = 0; i < k; i++) { std::cin >> xs[i] >> ys[i] >> ns[i]; } std::pair max; for (int s = 0; s < 1 << k; s++) { std::vector> ban(h, std::vector(w)); std::vector> dp(h, std::vector(w)); int cnt = 0; for (int i = 0; i < k; i++) { if (s >> i & 1) { cnt++; } else { ban[ys[i]][xs[i]] = true; } } if (cnt != p) continue; dp[0][0] = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (ban[i][j]) { dp[i][j] = 0; } if (i + 1 < h) { dp[i + 1][j] += dp[i][j]; } if (j + 1 < w) { dp[i][j + 1] += dp[i][j]; } } } if (max.first < dp[h - 1][w - 1]) { max.first = dp[h - 1][w - 1]; max.second = s; } } std::cout << max.first % 1000000007 << std::endl; for (int i = 0; i < k; i++) { if (max.second >> i & 1) { std::cout << ns[i] << std::endl; } } }