#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include using namespace std; using u64 = uint64_t; void chmax(int& a, int b){ if(a < b) a = b; } int main(){ int N, M; cin >> N >> M; vector P(N); for(int& p : P) cin >> p; int ans = 0; vector> A(N), B(M); for(auto& [a, b] : A) cin >> a >> b; for(auto& [c, d] : B) cin >> c >> d; static int cnt[1 << 28] = {}; for(auto [s, t] : vector>{{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}){ for(int i = 0; i < N; i++){ auto [a, b] = A[i]; for(auto [c, d] : B){ u64 key = c - s * a; key ^= key << 13; key ^= key >> 7; key ^= key << 17; key ^= d - t * b; chmax(ans, cnt[key & 0xfffffff] += P[i]); } } for(int i = 0; i < N; i++){ auto [a, b] = A[i]; for(auto [c, d] : B){ u64 key = c - s * a; key ^= key << 13; key ^= key >> 7; key ^= key << 17; key ^= d - t * b; cnt[key & 0xfffffff] -= P[i]; } } } cout << ans << endl; }