#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define int   long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
void phongbeo();
const int inf = 1e16;
const ll mod2 = 1e9+9999;
const int  mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
    if(x+y>=mod2) x-=mod2;
    if(x+y<0)x+=mod2;
    return x+y;
}
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    ll a;
    int  b, c;
};
struct id
{
    int a, b, c, d;
};
struct ie
{
    int a, b, c, d, e;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int  i, s10, s12,k1,k2,k3,s11,lim,w ;
int kk;
int el = 19;
main()
{
    if(fopen(task".inp","r"))
    {
        fin(task);
        fou(task);
    }
    NHP
    ///  cin>>s1;
    // modwwe
    phongbeo();
//   checktime
}
ib dsu[100001];
vector<int> v;
vector<ib> ask[100001],ask2[100001];
id a[200001];
void reset()
{
    for(int i=1; i<=n; i++)
        dsu[i]= {1,i};
}
int get(int x)
{
    if(x==dsu[x].b) return x;
    return dsu[x].b=get(dsu[x].b);
}
void noi(int x,int y)
{
    x=get(x);
    y=get(y);
    if(x==y)
    {
        mx++;
        return;
    }
    if(dsu[x].a<dsu[y].a) swap(x,y);
    dsu[x].a+=dsu[y].a;
    dsu[y].b=x;
}
void build(int x,int y,int c,int b)
{
    k++;
    v.pb(x);
    v.pb(y);
    v.pb(c);
    v.pb(b);
    a[k]= {x,y,c,b};
}
bool check(int x,int y)
{
    bool de=0,de2=0;
    if(a[x].a==a[x].c) de=1;
    if(a[y].a==a[y].c) de2=1;
    if(de==de2) return 0;
    if(de2) swap(x,y);
    if(a[x].b<=a[y].b&&a[y].b<=a[x].d&&a[x].a>=a[y].a&&a[x].a<=a[y].c)
        return 1;
    return 0;
}
bool cmp(ib a,ib b)
{
    return a.a<b.a;
}
void phongbeo()
{
    cin>>n>>m>>k;
    for(int i=1; i<=k; i++)
        cin>>a[i].a>>a[i].b>>a[i].c>>a[i].d,
            v.pb(a[i].a),v.pb(a[i].b),v.pb(a[i].c),v.pb(a[i].d);
    build(0,0,0,m);
    build(0,0,n,0);
    build(n,0,n,m);
    build(0,m,n,m);
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    for(int i=1; i<=k; i++)
    {
        a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1;
        a[i].b=lower_bound(v.begin(),v.end(),a[i].b)-v.begin()+1;
        a[i].c=lower_bound(v.begin(),v.end(),a[i].c)-v.begin()+1;
        a[i].d=lower_bound(v.begin(),v.end(),a[i].d)-v.begin()+1;
        if(a[i].a==a[i].c&&a[i].b==a[i].d) continue;
        if(a[i].a==a[i].c)
            ask[a[i].a].pb({a[i].b,a[i].d});
        else ask2[a[i].b].pb({a[i].a,a[i].c});
    }
    n=k;
    reset();
    for(int i=1; i<=n; i++)
        for(int j=i+1; j<=n; j++)
            if(check(i,j))
                noi(i,j);
    cout<<mx;
}
Compilation message (stderr)
2014_ho_t5.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main()
      | ^~~~
2014_ho_t5.cpp: In function 'int main()':
2014_ho_t5.cpp:12:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
2014_ho_t5.cpp:62:9: note: in expansion of macro 'fin'
   62 |         fin(task);
      |         ^~~
2014_ho_t5.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define fou(x) freopen(x".out","w",stdout)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~
2014_ho_t5.cpp:63:9: note: in expansion of macro 'fou'
   63 |         fou(task);
      |         ^~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |