#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 i64 = int64_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; unordered_map cnt; for(auto [s, t] : vector>{{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}){ cnt.clear(); for(int i = 0; i < N; i++){ auto [a, b] = A[i]; for(auto [c, d] : B) cnt[uint64_t(c - s * a) << 32 ^ (d - t * b)] += P[i]; } for(auto [key, val] : cnt) chmax(ans, val); } cout << ans << endl; }