#include #include #include #include #include #include #include #include #define se second #define fi first using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(long long i = 0; i < (int)n; i++) #define FOR(i, m, n) for(long long i = (m);i < (n); ++i) #define ALL(obj) (obj).begin(),(obj).end() #define SPEED cin.tie(0);ios::sync_with_stdio(false); template using V = vector; template using P = pair; template using PQ = priority_queue; template using PQR = priority_queue,greater>; void print(V ar) { for(auto x: ar)cout << x << " " ; cout << endl; } ll gcd(ll a, ll b) { if (a0) { if (n%2) { r*=x; r%=p; } x *= x; x %= p; n/=2; } return r; } const ll mod = 998244353; V> facts(ll n) { V> res; if (n==1)return res; for(int x = 2; x*x<=n; x++) { if (n%x==0) { int p = 0; while (n%x==0) { p+=1; n/=x; } res.emplace_back(P(x, p)); } } if (n!=1) { res.emplace_back(P(n, 1)); } return res; } int main() { int n,m;cin >> n >> m; V p(n);rep(i, n)cin >> p[i]; V a(n),b(n),c(m),d(m); rep(i, n)cin >> a[i] >> b[i]; rep(i, m)cin >> c[i] >> d[i]; ll ans = 0; map, ll> mp; rep(i, n)rep(j, m) { mp[P(a[i]-c[j], b[i]-d[j])] += p[i]; } for(auto x = mp.begin(); x!=mp.end() ; x++) { ans = max(ans, x->second); } rep(i, n) { a[i] = -a[i]; } mp = map,ll>(); rep(i, n)rep(j, m) { mp[P(a[i]-c[j], b[i]-d[j])] += p[i]; } for(auto x = mp.begin(); x!=mp.end() ; x++) { ans = max(ans, x->second); } rep(i, n) { b[i] = -b[i]; } mp = map,ll>(); rep(i, n)rep(j, m) { mp[P(a[i]-c[j], b[i]-d[j])] += p[i]; } for(auto x = mp.begin(); x!=mp.end() ; x++) { ans = max(ans, x->second); } rep(i, n) { a[i] = -a[i]; } mp = map,ll>(); rep(i, n)rep(j, m) { mp[P(a[i]-c[j], b[i]-d[j])] += p[i]; } for(auto x = mp.begin(); x!=mp.end() ; x++) { ans = max(ans, x->second); } cout << ans << endl; }