#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pll pair<ll,ll>

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

inline pll operator-(pll a,pll b){
    return pll(a.f-b.f,a.s-b.s);
}

inline ll cross(pll a,pll b){
    return a.f*b.s-a.s*b.f;
}

inline ll dot(pll a,pll b){
    return a.f*b.f+a.s*b.s;
}

inline int ori(pll a,pll b,pll c){
    ll ans=cross(b-a,c-a);
    return (ans==0?0:(ans<0?-1:1));
}

inline bool btw(pll a,pll b,pll c){
    return (ori(a,b,c)==0 and dot(a-b,c-b)<=0);
}

inline bool intersect(pll a,pll b,pll c,pll d){
    if(btw(a,c,b)||btw(a,d,b)||btw(c,a,d)||btw(c,b,d)) return true;
    return (ori(a,b,c)*ori(a,b,d)<0 and ori(c,d,a)*ori(c,d,b)<0);
}

inline bool comp(pair<pll,int> a,pair<pll,int> b){
    #define is_neg(x) (x.s<0 or (x.s==0 and x.f<0))
    int A=is_neg(a.f);
    int B=is_neg(b.f);
    if(A!=B){
        return A>B;
    }
    int res=ori(pll(0,0),a.f,b.f);
    if(res>0) return true;
    else if(res<0) return false;
    else return a.s<b.s;
}

struct BIT{
    vector<int> bit;
    int n;
    BIT(int _n){
        n=_n;
        bit.resize(n+1);
    }
    void update(int pos,int val){
        pos++;
        for(;pos<=n;pos+=(pos&-pos)){
            bit[pos]+=val;
        }
    }
    int query(int pos){
        pos++;
        int ans=0;
        for(;pos>0;pos-=(pos&-pos)){
            ans+=bit[pos];
        }
        return ans;
    }
};

int main() {_
    int n,m;
    cin>>n>>m;
    vector<pll> a(n),b(m);
    for(int i=0;i<n;i++){
        cin>>a[i].f>>a[i].s;
    }
    for(int i=0;i<m;i++){
        cin>>b[i].f>>b[i].s;
    }
    sort(all(b));
    ll ans=0;
    vector<int> ord(m);
    for(int i=0;i<m;i++){
        vector<pair<pll,int>> pt;
        for(int j=i+1;j<m;j++){
            pt.push_back({b[j]-b[i],j});
        }
        sort(all(pt),comp);
        int sz=(int)pt.size();
        BIT bit(sz);
        for(int i=0;i<sz;i++){
            ord[pt[i].s]=i;
        }
        int r=i+1;
        for(int j=0;j<n-1;j++){
            if(a[j].f<b[i].f) continue;;
            while(r<m and b[r].f<=a[j+1].f){
                bit.update(ord[r],1);
                cout << r << ' ' ;
                r++;
            }
            cout << '\n';
            int l=lower_bound(all(b),pll(a[j].f,-1))-b.begin();
            l=max(l,i+1);
            for(int k=l;k<r;k++){
                if(intersect(b[i],b[k],a[j],a[j+1])) ans++;
            }
            pll L=a[j]-b[i];
            pll R=a[j+1]-b[i];
            if(comp(make_pair(R,-1),make_pair(L,-1))) swap(L,R);
            int tl=lower_bound(all(pt),make_pair(L,-1),comp)-pt.begin();
            int tr=upper_bound(all(pt),make_pair(R,m),comp)-pt.begin()-1;
            cout<<r << ' ' << ans << ' ' << tl <<' '<< tr <<'\n';
            if(tl<=tr) ans+=(tr-tl+1)-(bit.query(tr)-bit.query(tl-1));
        }
        //cout<<ans<<'\n';
    }
    for(int i=0;i<m;i++){
        int pos=-1;
        for(int j=0;j<n-1;j++){
            if(a[j].f<b[i].f and a[j+1].f>=b[i].f){
                pos=j;
            }
        }
        if(pos==-1) continue;
        for(int j=i+1;j<m;j++){
            if(intersect(b[i],b[j],a[pos],a[pos+1])) ans++;
        }
    }
    cout<<ans<<'\n';
    return 0;
}
//maybe its multiset not set
//yeeorz
//diaoborz