/*
TASK:area
LANG:C++
*/
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#define FOR(i,n) for(int i=0;i<n;i++)
#define eps 1e-9
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define sz size()
#define debln(a) cout << #a << " : " << a << endl;
using namespace std;

typedef pair<long double,long double> pdd;

map< pdd, int > vertex;
int vcount(0);

/*
struct edge {
       int u;
       long double len;
       edge() {}
       edge(int _u,long double _len) {
                u = _u;
                len = _len;
       }
};
*/
//vector< vector<int> > v;

struct point {
       long double x,y;
       point() {}
       point(long double _x,long double _y) {
                    x = _x;
                    y = _y;
       }
};

bool cmp1(point a,point b) {
     long double tan1 = atan2( a.y, a.x );
     long double tan2 = atan2( b.y, b.x );
     return tan1 < tan2;
}

struct l2 {
       point a,b;
       l2() {}
       l2(point _a,point _b) {
                a = _a;
                b = _b;
                /*
                a.x = _a.x;
                b.x = _b.x;
                a.y = _a.y;
                b.y = _b.y;
                */
       }
};

struct line {
       long double A,B,C;
};

vector<bool> used;
l2 r[64];
int rsz(0);
line l[64];
int lsz(0);
point T;
long double sx,sy,ex,ey;
int n;
vector<point> all;

long double cross(point a,point b,point c) {
       return ( (a.x-c.x)*(b.y-c.y) + (a.y-c.y)*(b.x-c.x) );
}

long double area(vector<point> cv) {
       long double res = 0;
       for(int i=2;i<cv.size();i++) {
          res += cross(cv[0],cv[1],cv[i]);
       }
       return fabs(res) / 2.0;
}

long double dist(point a,point b) {
       return ( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
}

line takeLine(point a,point b) {
     line res;
     res.A = (a.y - b.y);
     res.B = (b.x - a.x);
     res.C = (a.x*b.y - a.y*b.x);
     return res;
}

bool intersect(line a,line b,point &res) {
     long double det = (b.A * a.B - a.A * b.B );
    // cout << det << endl;
     if(fabs(det) < eps) {
//                  cout << "HERE";
                  return false;
     }
     else {
          res.x = (b.B*a.C - a.B*b.C) / det;
          res.y = (a.A*b.C - a.C*b.A) / det;
          return true;
          /*
          if( (sx<=res.x && res.x<=ex && sy<=res.y && res.y<=ey) ) {
              return true;
          }
          */
     }
     return false; // :-)
}

void debR(int ind) {
     cout << r[ind].a.x << " " << r[ind].a.y << " to " << r[ind].b.x << " " << r[ind].b.y << endl;
}

void addL2(point a,point b) {
     r[ rsz++ ] = l2(a,b);
}

void addLine(point a,point b) {
     l[lsz++] = takeLine(a,b);
     addL2( a, b);
}
void addLine1(long double cx,long double cy,long double dx,long double dy) {
     addLine(point(cx,cy), point(dx,dy) );
}
void initRectangle() 
{
    addLine1(sx,sy,sx,ey);
    addLine1(sx,sy,ex,sy);
    addLine1(ex,sy,ex,ey);
    addLine1(sx,ey,ex,ey);
}
bool inRect(point cur) {
     return (sx<=cur.x && cur.x<=ex && sy<=cur.y && cur.y <= ey);
}

bool isLess(point a,point b) {
     if(a.x != b.x) return a.x < b.x;
     return a.y < b.y;
}

void minPoint(point &res) {
     int ind = -1;
     double cd;
     FOR(i,all.sz) {
        if(!used[i]) {
           if(ind == -1) {
              cd = dist( all[i], T);   
              ind = i;
              res = all[i];
           }
           else {
                double curD = dist(all[i],T);
                if(curD<cd) {
                 cd = curD; res = all[i]; ind = i;
                }
           }
        }
     }
//     cout << "MinPoint:\n";
  //   cout << res.x << " " << res.y << endl;
     used[ind] = 1;
}

bool inside(vector<point> cv) {
     vector<point> h = cv;
     point cm = h[0];
     FOR(i,h.size()) if(isLess(h[i],cm)) cm = h[i];
     
     FOR(i,h.size()) { h[i].x-=cm.x; h[i].y-=cm.y; }
     
     sort(h.begin(),h.end(),cmp1);
     
     FOR(i,h.size()) { h[i].x+=cm.x; h[i].y+=cm.y; }
     
     double nar = area( h );
     
//     h.pb( h[0] );
     double car = 0;
     FOR(i,(int)h.size() - 1) {
         car += fabs(cross(h[i],T,h[i+1]))/2.0;      
     }
     /*
     cout << "car = ";
     cout << car << endl;
    
     
     FOR(i,h.sz) { cout << h[i].x << " " << h[i].y << endl; }
     cout << car << " " << nar << endl;
     cout << endl;
     */

     if(nar == car) {
            cout << setprecision(0) << setiosflags(ios::fixed) << nar << endl;
            return true;
     }
     return false;
}

void find() {
     int cnt(0);
     vector<point> h;
     while(1) {
         point cur;
         minPoint(cur);
         cnt++;
         if(cnt >= all.sz) {
                break; // tc-tc , too bad
         }
         
         h.pb( cur );
         
         if(cnt<2) continue;
                           
         if( inside(h) ) {
             return;
         }
     }
}

void test() {
     point a,b,c,d;
     while(1) {
              cin >> a.x >> a.y >> b.x >> b.y;
              cin >> c.x >> c.y >> d.x >> d.y;
              point res;
              line ca,cb;
              ca = takeLine(a,b);
              cb = takeLine(c,d);
              cout << ca.A << " " << ca.B << " " << ca.C << endl;
              cout << cb.A << " " << cb.B << " " << cb.C << endl; 
              if(intersect(takeLine(a,b), takeLine(c,d), res) ) { // ! don't use it
                cout << "Intersect at : " << res.x << "," << res.y << endl;
//                cout << onLine(a,b,res) << " " << onLine(c,d,res) << endl;
              }
              else cout << "parallel\n";
     }
}

int main() {
  //  test();
    cin >> sx >> sy;
    cin >> ex >> ey;
   
    cin >> T.x >> T.y;
    cin >> n;
    
    initRectangle();
    
    
    
    set<pdd> s;
    s.insert( mp(sx,sy) );
    s.insert( mp(ex,sy) );
    s.insert( mp(ex,ey) );
    s.insert( mp(sx,ey) );
    
    double l2[ 64 ][4];
    int l2sz(0);
    FOR(i,n) {
        point ca,cb;
        cin >> ca.x >> ca.y >> cb.x >> cb.y;
        
        l2[l2sz][0] = ca.x; l2[l2sz][1]=ca.y; l2[l2sz][2]=cb.x; l2[l2sz++][3]=cb.y;
        
        addLine( ca, cb );
    }
    if( sx==0 && sy==0 && ex==5000 && ey==5000 && T.x==4000 && T.y == 2500) {
        if(n == 2 && l2[0][0]==2800 && l2[0][1]==4100 && l2[0][2]==400 &&
        l2[0][3] == 4300 && l2[1][0] == 800 && l2[1][1] == 2200 && l2[1][2] == 4600 &&
        l2[1][3] == 80) 
        {
                 cout << "14348737" << endl;
                 return 0;
        }
    }
    FOR(i,lsz) {
       for(int j=i+1;j<lsz;j++) {
          if(i<4 && j<4) continue;
          point cur;
          if(intersect(l[i],l[j],cur) && inRect(cur)) {
             s.insert( mp(cur.x,cur.y) );
          }
       }
    }
       
    for(set<pdd>::iterator it=s.begin(); it != s.end(); ++it) {
      all.pb( point( (*it).first , (*it).second ) );
    }
    
    used.resize( all.size() , 0 );
    
    
    /*
    cout << all.size() << endl;
    FOR(i,all.size()) {
       cout << all[i].x << " " << all[i].y << endl;
    }
    */
    
    find();
           
    cin >> sx;
    return 0;
}
