#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; 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){ int key = c - s * a; key ^= key << 13; key ^= key >> 17; key ^= key << 5; 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){ int key = c - s * a; key ^= key << 13; key ^= key >> 17; key ^= key << 5; key ^= d - t * b; cnt[key & 0xfffffff] -= P[i]; } } } cout << ans << endl; }