#include #include #include #include #include using namespace std; using mint = atcoder::modint998244353; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, M; cin >> N >> M; constexpr int D = 101; auto f = [&](int a, int b, int c) { return (a * D + b) * D + c; }; vector dp(D * D * D); for (int i = 0; i < N; ++i) { int a, b, c; cin >> a >> b >> c; dp.at(f(a, b, c)) += 1; } auto dprev = dp; reverse(dprev.begin(), dprev.end()); auto conv = atcoder::convolution(dprev, dp); int hi = N; for (int i = 0; i < M; ++i) { int x, y, z; cin >> x >> y >> z; hi = min(hi, conv.at(D * D * D - 1 + f(x, y, z)).val()); } cout << N * 2 - hi << '\n'; }