#include using namespace std; int main() { int N, K, M; cin >> N >> K >> M; int ans = 0; for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; if (a == N - 1 - K && b == N - 1 - K && c == K) { ans++; } } cout << ans << endl; return 0; }