#include <bits/stdc++.h>
using namespace std;
int  get(int n,int k,int d1,int d2){
        int x,y,z,a,maxi;
        a = (k - (d1+d1+d2))/3;
        x = a; y = a+d1; z = a+d1+d2;
        // cout<<x<<" "<<y<<" "<<z<<"\n";
        if(x>=0 && y>=0 && z>=0 && x+y+z==k){
            maxi = max(x, max(y, z) );
            maxi = (3*maxi) - (x + y + z);
            k = n - k - maxi;
            if(k>=0 && k%3==0){
                cout<<"yes"<<endl;
                // continue;
                return 1;
            }
        }
        return 0;
}
int main() {
    int t,n,k,d11,d22,d1,d2,x,y,z,a,maxi;
    cin>>t;
    while(t--){
        cin>>n>>k>>d1>>d2;
        if(get(n,k,d1,d2) || get(n,k,-d1,d2) || get(n,k,d1,-d2) || get(n,k,-d1,-d2)){
            continue;
        }
        cout<<"no"<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll  get(ll n,ll k,ll d1,ll d2){
        ll x,y,z,a,maxi;
        a = (k - (d1+d1+d2))/3;
        x = a; y = a+d1; z = a+d1+d2;
        // cout<<x<<" "<<y<<" "<<z<<"\n";
        if(x>=0 && y>=0 && z>=0 && x+y+z==k){
            maxi = max(x, max(y, z) );
            maxi = (3*maxi) - (x + y + z);
            k = n - k - maxi;
            if(k>=0 && k%3==0){
                cout<<"yes"<<endl;
                // continue;
                return 1;
            }
        }
        return 0;
}
int main() {
    ll t,n,k,d11,d22,d1,d2,x,y,z,a,maxi;
    cin>>t;
    while(t--){
        cin>>n>>k>>d1>>d2;
        if(get(n,k,d1,d2) || get(n,k,-d1,d2) || get(n,k,d1,-d2) || get(n,k,-d1,-d2)){
            continue;
        }
        cout<<"no"<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

long long t, n, d1, d2, k, n1, x1, x2, x3;

bool od()
{
	if((k-d1+d2) % 3 != 0)
		return false;

	if((k-d1+d2) < 0)
		return false;

	x2 = (k-d1+d2)/3;
	x1 = x2 + d1;
	x3 = x2 - d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;
	if(n - (x1 - x3) - (x1 - x2) == 0)
		return true;

	if(n - (x1 - x3) - (x1 - x2) > 0)
	{
		n1 = n - (x1 - x3) - (x1 - x2);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;

}

bool dv()
{
	if((k-d1-d2) % 3 != 0)
		return false;

	if((k-d1-d2) < 0)
		return false;

	x2 = (k-d1-d2)/3;
	x1 = x2 + d1;
	x3 = x2 + d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;

	int maxi = max(x1, x3), mini = min(x1,x3);
	if(n - (maxi - mini) - (maxi - x2) == 0)
		return true;

	if(n - (maxi - mini) - (maxi - x2) > 0)
	{
		n1 = n - (maxi - mini) - (maxi - x2);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;
}

bool tr()
{
	if((k+d1+d2) % 3 != 0)
		return false;

	x2 = (k+d1+d2)/3;
	x1 = x2 - d1;
	x3 = x2 - d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;

	if(n - (x2 - x1) - (x2 - x3) == 0)
		return true;

	if(n - (x2 - x1) - (x2 - x3) > 0)
	{
		n1 = n - (x2 - x1) - (x2 - x3);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;
}

bool chet()
{
	if((k+d1-d2) % 3 != 0)
		return false;

	if((k+d1-d2) < 0)
		return false;

	x2 = (k+d1-d2)/3;
	x1 = x2 - d1;
	x3 = x2 + d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;

	if(n - (x3 - x2) - (x3 - x1) == 0)
		return true;

	if(n - (x3 - x2) - (x3 - x1) > 0)
	{
		n1 = n - (x3 - x2) - (x3 - x1);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;
}

int main()
{
//freopen("INPUT.TXT", "r", stdin);
//freopen("OUTPUT.TXT", "w", stdout);

	cin >> t;

	for(long long i(0); i < t; i++)
	{
		cin >> n >> k >> d1 >> d2;

		n-=k;

		if(od())
			cout << "yes" << endl;
		else if(dv())
			cout << "yes" << endl;
		else if(tr())
			cout << "yes" << endl;
		else if(chet())
			cout << "yes" << endl;
		else cout << "no" << endl;

	}

}


#include <bits/stdc++.h>

using namespace std;

int t, n, d1, d2, k, n1, x1, x2, x3;

bool od()
{
	if((k-d1+d2) % 3 != 0)
		return false;

	if((k-d1+d2) < 0)
		return false;

	x2 = (k-d1+d2)/3;
	x1 = x2 + d1;
	x3 = x2 - d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;
	if(n - (x1 - x3) - (x1 - x2) == 0)
		return true;

	if(n - (x1 - x3) - (x1 - x2) > 0)
	{
		n1 = n - (x1 - x3) - (x1 - x2);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;

}

bool dv()
{
	if((k-d1-d2) % 3 != 0)
		return false;

	if((k-d1-d2) < 0)
		return false;

	x2 = (k-d1-d2)/3;
	x1 = x2 + d1;
	x3 = x2 + d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;

	int maxi = max(x1, x2), mini = min(x1,x2);

	if(n - (maxi - mini) - (maxi - x2) == 0)
		return true;

	if(n - (maxi - mini) - (maxi - x2) > 0)
	{
		n1 = n - (maxi - mini) - (maxi - x2);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;
}

bool tr()
{
	if((k+d1+d2) % 3 != 0)
		return false;

	x2 = (k+d1+d2)/3;
	x1 = x2 - d1;
	x3 = x2 - d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;

	if(n - (x2 - x1) - (x2 - x3) == 0)
		return true;

	if(n - (x2 - x1) - (x2 - x3) > 0)
	{
		n1 = n - (x2 - x1) - (x2 - x3);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;
}

bool chet()
{
	if((k+d1-d2) % 3 != 0)
		return false;

	if((k+d1-d2) < 0)
		return false;

	x2 = (k+d1-d2)/3;
	x1 = x2 - d1;
	x3 = x2 + d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;

	if(n - (x3 - x2) - (x3 - x1) == 0)
		return true;

	if(n - (x3 - x2) - (x3 - x1) > 0)
	{
		n1 = n - (x3 - x2) - (x3 - x1);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;
}

int main()
{
//freopen("INPUT.TXT", "r", stdin);
//freopen("OUTPUT.TXT", "w", stdout);

	cin >> t;

	for(int i(0); i < t; i++)
	{
		cin >> n >> k >> d1 >> d2;

		n-=k;

		if(od())
			cout << "yes" << endl;
		else if(dv())
			cout << "yes" << endl;
		else if(tr())
			cout << "yes" << endl;
		else if(chet())
			cout << "yes" << endl;
		else cout << "no" << endl;

	}

}


#include <bits/stdc++.h>

using namespace std;

int t, n, d1, d2, k, n1, x1, x2, x3;

bool od()
{
	if((k-d1+d2) % 3 != 0)
		return false;

	if((k-d1+d2) < 0)
		return false;

	x2 = (k-d1+d2)/3;
	x1 = x2 + d1;
	x3 = x2 - d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;
	if(n - (x1 - x3) - (x1 - x2) == 0)
		return true;

	if(n - (x1 - x3) - (x1 - x2) > 0)
	{
		n1 = n - (x1 - x3) - (x1 - x2);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;

}

bool dv()
{
	if((k-d1-d2) % 3 != 0)
		return false;

	if((k-d1-d2) < 0)
		return false;

	x2 = (k-d1-d2)/3;
	x1 = x2 + d1;
	x3 = x2 + d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;

	int maxi = max(x1, x3), mini = min(x1,x3);
	if(n - (maxi - mini) - (maxi - x2) == 0)
		return true;

	if(n - (maxi - mini) - (maxi - x2) > 0)
	{
		n1 = n - (maxi - mini) - (maxi - x2);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;
}

bool tr()
{
	if((k+d1+d2) % 3 != 0)
		return false;

	x2 = (k+d1+d2)/3;
	x1 = x2 - d1;
	x3 = x2 - d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;

	if(n - (x2 - x1) - (x2 - x3) == 0)
		return true;

	if(n - (x2 - x1) - (x2 - x3) > 0)
	{
		n1 = n - (x2 - x1) - (x2 - x3);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;
}

bool chet()
{
	if((k+d1-d2) % 3 != 0)
		return false;

	if((k+d1-d2) < 0)
		return false;

	x2 = (k+d1-d2)/3;
	x1 = x2 - d1;
	x3 = x2 + d2;

	if(x1 < 0 || x2 < 0 || x3 < 0)
		return false;

	if(n - (x3 - x2) - (x3 - x1) == 0)
		return true;

	if(n - (x3 - x2) - (x3 - x1) > 0)
	{
		n1 = n - (x3 - x2) - (x3 - x1);

		if(n1 % 3 == 0)
			return true;

		return false;
	}

	return false;
}

int main()
{
//freopen("INPUT.TXT", "r", stdin);
//freopen("OUTPUT.TXT", "w", stdout);

	cin >> t;

	for(int i(0); i < t; i++)
	{
		cin >> n >> k >> d1 >> d2;

		n-=k;

		if(od())
			cout << "yes" << endl;
		else if(dv())
			cout << "yes" << endl;
		else if(tr())
			cout << "yes" << endl;
		else if(chet())
			cout << "yes" << endl;
		else cout << "no" << endl;

	}

}


#include <bits/stdc++.h>

using namespace std;

#define mk make_pair
#define pb push_back

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

int main(void) {
        int t;
        cin >> t;
        while( t-- )
        {
                ll n, k, d1, d2;
                cin >> n >> k >> d1 >> d2;

                n = n-k;

                n -= d2;
                d1 -= d2;
                if( d1<0 ) d1 *= -1;
                n -= 2*d1;

                if( n < 0 ) {
                        cout << "no\n";
                        continue;
                }

                if( n % 3 == 0 )
                {
                        cout << "yes\n";
                }
                else cout << "no\n";

        }

        return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mk make_pair
#define pb push_back

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

// 1 < 2 < 3
bool op1( ll k, ll n, ll d1, ll d2 ) {
        if( k - (2*d1+d2) < 0 ) return false;
        if( (k-(2*d1+d2))%3 != 0 ) return false;
        n -= d1;
        n -= d2*2;
        if( n < 0 ) return false;
        return n%3==0;
}

//1>2 2<3
bool op2(ll k, ll n, ll d1, ll d2 ) {
        if( k - (d1+d2) < 0 ) return false;
        if( (k-(d1+d2))%3!=0) return false;

        ll dd1 = min(d1,d2);
        ll dd2 = max(d1,d2 );

        n -= dd1;
        dd2 -= dd1;
        n -= 2*dd2;
        if( n < 0 ) return false;
        return n%3!=0;
}

//1<2 ,2 > 3
bool op3( ll k, ll n, ll d1, ll d2 ) {
        if( (k-(2*d1-d2)) < 0 ) return false;
        if( (k-(2*d1-d2))%3 != 0 ) return false;
        n -= d2;
        n -= d1;
        if( n < 0 ) return false;
        return n%3 == 0;
}
// 1>2>3
bool op4( ll k, ll n, ll d1, ll d2 ) {
        if( k - 2*d2 - d1 < 0 ) return false;
        if( (k-2*d2-d1)%3!=0 ) return false;
        n -= d2;
        n -= 2*d1;
        if ( n < 0 ) return false;
        return n%3==0;
}

bool chk( ll n, ll d1, ll d2 ) {
        if( n - d1 -d2 < 0 ) return false;
        if( (n-d1-d2)%3!=0 ) return false;
        return true;
}

int main(void) {
        int t;
        cin >> t;
        while( t-- )
        {
                ll n, k, d1, d2;
                cin >> n >> k >> d1 >> d2;

                if( op4(k,n-k,d1,d2) || op3(k,n-k,d1,d2) || op1(k,n-k,d1,d2) || op2(k,n-k,d1,d2) )
                        cout << "yes\n";
                else cout << "no\n";

        }

        return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mk make_pair
#define pb push_back

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

// 1 < 2 < 3
bool op1( ll k, ll n, ll d1, ll d2 ) {
        if( k - (2*d1+d2) < 0 ) return false;
        if( (k-(2*d1+d2))%3 != 0 ) return false;
        n -= d1;
        n -= d2*2;
        if( n < 0 ) return false;
        return n%3==0;
}

//1>2 2<3
bool op2(ll k, ll n, ll d1, ll d2 ) {
        if( k - (d1+d2) < 0 ) return false;
        if( (k-(d1+d2))%3!=0) return false;

        ll dd1 = min(d1,d2);
        ll dd2 = max(d1,d2 );

        n -= dd1;
        dd2 -= dd1;
        n -= 2*dd2;
        if( n < 0 ) return false;
        return n%3==0;
}

//1<2 ,2 > 3
bool op3( ll k, ll n, ll d1, ll d2 ) {
        if( (k-(2*d1-d2)) < 0 ) return false;
        if( (k-(2*d1-d2))%3 != 0 ) return false;
        n -= d2;
        n -= d1;
        if( n < 0 ) return false;
        return n%3 == 0;
}
// 1>2>3
bool op4( ll k, ll n, ll d1, ll d2 ) {
        if( k - 2*d2 - d1 < 0 ) return false;
        if( (k-2*d2-d1)%3!=0 ) return false;
        n -= d2;
        n -= 2*d1;
        if ( n < 0 ) return false;
        return n%3==0;
}

bool chk( ll n, ll d1, ll d2 ) {
        if( n - d1 -d2 < 0 ) return false;
        if( (n-d1-d2)%3!=0 ) return false;
        return true;
}

int main(void) {
        int t;
        cin >> t;
        while( t-- )
        {
                ll n, k, d1, d2;
                cin >> n >> k >> d1 >> d2;

                if( op4(k,n-k,d1,d2) || op3(k,n-k,d1,d2) || op1(k,n-k,d1,d2) || op2(k,n-k,d1,d2) )
                        cout << "yes\n";
                else cout << "no\n";

        }

        return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mk make_pair
#define pb push_back

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

bool op1( ll n, ll d1, ll d2 ) {
        n -= d2;
        n -= d1*2;
        if( n < 0 ) return false;
        return n%3==0;
}
bool op2( ll n, ll d1, ll d2 ) {
        n -= d2;
        d1 -= d2;
        if( d1 < 0 ) d1 *= -1;
        n -= 2*d1;
        if( n < 0 ) return false;
        return n%3==0;
}
bool chk( ll n, ll d1, ll d2 ) {
        if( n - d1 -d2 < 0 ) return false;
        if( (n-d1-d2)%3!=0 ) return false;
        return true;
}

int main(void) {
        int t;
        cin >> t;
        while( t-- )
        {
                ll n, k, d1, d2;
                cin >> n >> k >> d1 >> d2;

                if( !chk( k, d1, d2 ) )
                        cout << "no\n";
                else
                if( op1(n-k,d1,d2) || op2(n-k,d1,d2) )
                        cout << "yes\n";
                else cout << "no\n";

        }

        return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mk make_pair
#define pb push_back

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

// 1 < 2 < 3
bool op1( ll k, ll n, ll d1, ll d2 ) {
        if( k - (2*d1+d2) < 0 ) return false;
        if( (k-(2*d1+d2))%3 != 0 ) return false;
        n -= d1;
        n -= d2*2;
        if( n < 0 ) return false;
        return n%3==0;
}

//1>2 2<3
bool op2(ll k, ll n, ll d1, ll d2 ) {
        if( k - (-2*d1+d2) < 0 ) return false;
        if( (k-(-2*d1+d2))%3!=0) return false;

        ll dd1 = min(d1,d2);
        ll dd2 = max(d1,d2 );

        n -= dd1;
        dd2 -= dd1;
        n -= 2*dd2;
        if( n < 0 ) return false;
        return n%3==0;
}

//1<2 ,2 > 3
bool op3( ll k, ll n, ll d1, ll d2 ) {
        if( (k-(2*d1-d2)) < 0 ) return false;
        if( (k-(2*d1-d2))%3 != 0 ) return false;
        n -= d2;
        n -= d1;
        if( n < 0 ) return false;
        return n%3 == 0;
}
// 1>2>3
bool op4( ll k, ll n, ll d1, ll d2 ) {
        if( k - (-2*d1 - d2) < 0 ) return false;
        if( (k-(-2*d1-d2))%3!=0 ) return false;
        n -= d2;
        n -= 2*d1;
        if ( n < 0 ) return false;
        return n%3==0;
}

int main(void) {
        int t;
        cin >> t;
        while( t-- )
        {
                ll n, k, d1, d2;
                cin >> n >> k >> d1 >> d2;

                if( op4(k,n-k,d1,d2) || op3(k,n-k,d1,d2) || op1(k,n-k,d1,d2) || op2(k,n-k,d1,d2) )
                        cout << "yes\n";
                else cout << "no\n";

        }

        return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mk make_pair
#define pb push_back

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

bool op1( ll n, ll d1, ll d2 ) {
        n -= d2;
        n -= d1*2;
        if( n < 0 ) return false;
        return n%3==0;
}
bool op2( ll n, ll d1, ll d2 ) {
        n -= d2;
        d1 -= d2;
        if( d1 < 0 ) d1 *= -1;
        n -= 2*d1;
        if( n < 0 ) return false;
        return n%3==0;
}

int main(void) {
        int t;
        cin >> t;
        while( t-- )
        {
                ll n, k, d1, d2;
                cin >> n >> k >> d1 >> d2;

                if( op1(n-k,d1,d2) || op2(n-k,d1,d2) )
                        cout << "yes\n";
                else cout << "no\n";

        }

        return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mk make_pair
#define pb push_back

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

bool op1( ll k, ll n, ll d1, ll d2 ) {
        if( k - (2*d2+d1) < 0 ) return false;
        if( (k-(2*d2+d1))%3 != 0 ) return false;

        n -= d2;
        n -= d1*2;
        if( n < 0 ) return false;
        return n%3==0;
}

bool op2(ll k, ll n, ll d1, ll d2 ) {
        if( k - (d1+d2) < 0 ) return false;
        if( (k-(d1+d2))%3!=0) return false;

        n -= d2;
        d1 -= d2;
        if( d1 < 0 ) d1 *= -1;
        n -= 2*d1;
        if( n < 0 ) return false;
        return n%3==0;
}

bool op3( ll k, ll n, ll d1, ll d2 ) {
        if( k - (2*d1 - d2 ) < 0 ) return false;
        if( ( k-(2*d1-d2))%3 != 0 ) return false;

        n -= d2;
        n -= d1;
        if( n < 0 ) return false;
        return n%3 == 0;
}
bool op4( ll k, ll n, ll d1, ll d2 ) {
        if( k - 2*d1 - d2 < 0 ) return false;
        if( (k-2*d1-d2)%3!=0 ) return false;
        n -= d2;
        d1 += d2;
        n -= d1;
        if ( n < 0 ) return false;
        return n%3==0;
}

bool chk( ll n, ll d1, ll d2 ) {
        if( n - d1 -d2 < 0 ) return false;
        if( (n-d1-d2)%3!=0 ) return false;
        return true;
}

int main(void) {
        int t;
        cin >> t;
        while( t-- )
        {
                ll n, k, d1, d2;
                cin >> n >> k >> d1 >> d2;

                if( op4(k,n-k,d1,d2) || op3(k,n-k,d1,d2) || op1(k,n-k,d1,d2) || op2(k,n-k,d1,d2) )
                        cout << "yes\n";
                else cout << "no\n";

        }

        return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mk make_pair
#define pb push_back

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

// 1 < 2 < 3
bool op1( ll k, ll n, ll d1, ll d2 ) {
        if( k - (2*d1+d2) < 0 ) return false;
        if( (k-(2*d1+d2))%3 != 0 ) return false;
        n -= d1;
        n -= d2*2;
        if( n < 0 ) return false;
        return n%3==0;
}

//1>2 2<3
bool op2(ll k, ll n, ll d1, ll d2 ) {
        if( k - (-2*d1+d2) < 0 ) return false;
        if( (k-(-2*d1+d2))%3!=0) return false;

        //ll dd1 = min(d1,d2);
        //ll dd2 = max(d1,d2 );

        n -= d1;
        d2 -= d1;
        if( d2 < 0 ) d2 *= -1;
        n -= 2*d2;
        if( n < 0 ) return false;
        return n%3==0;
}

//1<2 ,2 > 3
bool op3( ll k, ll n, ll d1, ll d2 ) {
        if( (k-(2*d1-d2)) < 0 ) return false;
        if( (k-(2*d1-d2))%3 != 0 ) return false;
        n -= d2;
        n -= d1;
        if( n < 0 ) return false;
        return n%3 == 0;
}
// 1>2>3
bool op4( ll k, ll n, ll d1, ll d2 ) {
        if( k - 2*d2 - d1 < 0 ) return false;
        if( (k-2*d2-d1)%3!=0 ) return false;
        n -= d2;
        n -= 2*d1;
        if ( n < 0 ) return false;
        return n%3==0;
}

int main(void) {
        int t;
        cin >> t;
        while( t-- )
        {
                ll n, k, d1, d2;
                cin >> n >> k >> d1 >> d2;

                if( op4(k,n-k,d1,d2) || op3(k,n-k,d1,d2) || op1(k,n-k,d1,d2) || op2(k,n-k,d1,d2) )
                        cout << "yes\n";
                else cout << "no\n";

        }

        return 0;
}


#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<algorithm>
#include<string>
#include<string.h>
#include<map>
using namespace std;
int n, ans;
int xa, ya, xb, yb;
int kv(int a){
    return a*a;
}
struct P{
    int x, y, r;
    void in(){
        cin>>x>>y>>r;
    }
}a[1005];
void solve(int x, int y){
    for(int i = 0; i < n; i ++){
        int d = kv(x - a[i].x) + kv(y - a[i].y);
        if(d <= kv(a[i].r)){
            return;
        }
    }
    ans ++;
   // cout<<x<<" "<<y<<endl;
}
int main(){
	cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
	cin>>xa>>ya>>xb>>yb;
	cin>>n;
	for(int i = 0; i < n; i ++){
        a[i].in();
	}
	if(yb > ya) swap(yb,ya);
	if(xa > xb) swap(xa,xb);
	for(int i = yb; i <= ya; i ++){
        solve(xa,i);
        solve(xb,i);
	}
	for(int i = xa; i <= xb; i ++){
        solve(i,yb);
        solve(i,ya);
	}
	int res = ans;
	ans = 0;
	solve(xa,yb);
	solve(xa,ya);
	solve(xb,ya);
	solve(xb,yb);
	cout<< res - ans;
	return 0;
}


#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
int n, ans;
int xa, ya, xb, yb;
int us[1005][1005];
int kv(int a){
    return a*a;
}
struct P{
    int x, y, r;
    void in(){
        cin>>x>>y>>r;
    }
}a[1005];
void solve(int x, int y){
    for(int i = 0; i < n; i ++){
        int d = kv(x - a[i].x) + kv(y - a[i].y);
        if(d <= kv(a[i].r)){
            return;
        }
    }
    if(us[x][y]) return;
    us[x][y] = 1;
    ans ++;
   // cout<<x<<" "<<y<<endl;
}
int main(){
	cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
	cin>>xa>>ya>>xb>>yb;
	cin>>n;
	for(int i = 0; i < n; i ++){
        a[i].in();
	}
	if(yb > ya) swap(yb,ya);
	if(xa > xb) swap(xa,xb);
	for(int i = yb; i <= ya; i ++){
        solve(xa,i);
        solve(xb,i);
	}
	for(int i = xa; i <= xb; i ++){
        solve(i,yb);
        solve(i,ya);
	}
	cout<< ans;
	return 0;
}


/*

 Deathly Hallows

 */

#include<iostream>
#include<bits/stdc++.h>

using namespace std;
int gdistance(int i, int j) {
	return i * i + j * j;
}
int x[1500], y[1500], r[1500];
int main()
{
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> r[i];
	}
	int ans = 0;
	for (int i = min(x1, x2); i <= max(x1, x2); i++) {
		bool flag1 = false, flag2 = false;
		for (int j = 0; j < n; j++) {
		if(gdistance(i-x[j] , y1-y[j]) <= r[j]*r[j]) flag1 = true;
		if(gdistance(i-x[j] , y2-y[j]) <= r[j]*r[j]) flag2 = true;
		}
		if(!flag1) ans++;
		if(!flag2) ans++;
	}

	for (int i = min(y1, y2)+1; i < max(y1, y2); i++) {
			bool flag1 = false, flag2 = false;
			for (int j = 0; j < n; j++) {
			if(gdistance(x1-x[j] , i-y[j]) <= r[j]*r[j]) flag1 = true;
			if(gdistance(x2-x[j] , i-y[j]) <= r[j]*r[j]) flag2 = true;
			}
			if(!flag1) ans++;
			if(!flag2) ans++;
		}
 cout<<ans<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,c,man,mix,l,r,d[200000],e[200000],h[200000],ans,ans1;
vector<long long> v[100000],v1;
// set<long long> st;
// map<long long,long long> mp,mp1;
// string s,s1,s2;
// pair<int,int> p[100000];
// deque <long long> dq[200000];
bool o;
int main(){
    cin>>a>>b>>c>>r>>l;
    man=INT_MAX;
    for(int i = 1; i  <= l; i++){
        cin>>d[i]>>e[i]>>h[i];
    }
    int i = 0,j = 0,k = 0;
    for(i = min(a,c); i <= max(a,c); i++)
        for(j = min(b,r); j <=max(b,r); j++)
            if(i==a || i==c || j==b || j==r){
                for(k = l;k--;)
                    if((i-d[k])*(i-d[k])+(j-e[k])*(j-e[k])<=h[k]*h[k])
                        break;
                       ans+=k<0;
            }

    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,c,man,mix,l,r,d[200000],e[200000],h[200000],ans,ans1;
vector<long long> v[100000],v1;
// set<long long> st;
// map<long long,long long> mp,mp1;
// string s,s1,s2;
// pair<int,int> p[100000];
// deque <long long> dq[200000];
bool o;
int main(){
    cin>>a>>b>>c>>r>>l;
    man=INT_MAX;
    for(int i = 0; i  < l; i++){
        cin>>d[i]>>e[i]>>h[i];
    }
    int i = 0,j = 0,k = 0;
    for(i = min(a,c); i <= max(a,c); i++)
        for(j = min(b,r); j <=max(b,r); j++)
            if(i==a || i==c || j==b || j==r){
                for(k = l;k--;)
                    if((i-d[k])*(i-d[k])+(j-e[k])*(j-e[k])<=h[k]*h[k])
                        break;
                       ans+=k<0;
            }

    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,c,man,mix,l,r,d[200000],e[200000],h[200000],ans,ans1;
vector<long long> v[100000],v1;
set<long long> st;
map<long long,long long> mp,mp1;
string s,s1,s2;
pair<int,int> p[100000];
deque <long long> dq[200000];
bool o;
int main(){
    cin>>a>>b>>c>>r>>l;
    man=INT_MAX;
    for(int i = 1; i  <= l; i++){
        cin>>d[i]>>e[i]>>h[i];
    }
    int i = 0,j = 0;
    for(i = min(a,c); i <= max(a,c); i++){
        for(j = min(b,r); j <=max(b,r); j++){
            if(i==a || i==c || j==b || j==r){
                for(int k = l;k--;){
                    if((i-d[k])*(i-d[k])+(j-e[k])*(j-e[k])<=h[k]*h[k]){
                        break;
                        ans+=k<0;
                    }
                }
            }
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,c,man,mix,l,r,d[200000],e[200000],h[200000],ans,ans1;
vector<long long> v[100000],v1;
set<long long> st;
map<long long,long long> mp,mp1;
string s,s1,s2;
pair<int,int> p[100000];
deque <long long> dq[200000];
bool o;
int main(){
    cin>>a>>b>>c>>r>>l;
    man=INT_MAX;
    for(int i = 1; i  <= l; i++){
        cin>>d[i]>>e[i]>>h[i];
    }
    int i = 0,j = 0;
    for(i = min(a,c); i <= max(a,c); i++){
        for(j = min(b,r); j <=max(b,r); j++){
            if(i==a || i==c || j==b || j==r){
                for(int k = l;k--;){
                    if((i-d[k])*(i-d[k])+(j-e[k])*(j-e[k])<=h[k]*h[k]){
                        break;
                    }
                    ans+=k<0;
                }
            }
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,c,man,mix,l,r,d[200000],e[200000],h[200000],ans,ans1;
vector<long long> v[100000],v1;
// set<long long> st;
// map<long long,long long> mp,mp1;
// string s,s1,s2;
// pair<int,int> p[100000];
// deque <long long> dq[200000];
bool o;
int main(){
    cin>>a>>b>>c>>r>>l;
    man=INT_MAX;
    for(int i = 1; i  <= l; i++){
        cin>>d[i]>>e[i]>>h[i];
    }
    int i = 0,j = 0;
    for(i = min(a,c); i <= max(a,c); i++)
        for(j = min(b,r); j <=max(b,r); j++)
            if(i==a || i==c || j==b || j==r){
                for(int k = l;k--;)
                    if((i-d[k])*(i-d[k])+(j-e[k])*(j-e[k])<=h[k]*h[k])
                        break;
                       ans+=k<0;
            }

    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,c,man,mix,l,r,d[200000],e[200000],h[200000],ans,ans1;
vector<long long> v[100000],v1;
set<long long> st;
map<long long,long long> mp,mp1;
string s,s1,s2;
pair<int,int> p[100000];
deque <long long> dq[200000];
bool o;
int main(){
    cin>>a>>b>>c>>r>>l;
    man=INT_MAX;
    for(int i = 1; i  <= l; i++){
        cin>>d[i]>>e[i]>>h[i];
    }
    int i = 0,j = 0;
    for(i = min(a,c); i <= max(a,c); i++){
        for(j = min(b,r); j <=max(b,r); j++){
            if(i==a || i==c || j==b || j==r){
                for(int k = l;k--;){
                    if((i-d[k])*(i-d[k])+(j-e[k])*(j-e[k])<=h[k]*h[k]){
                        break;
                    }
                    ans+=k>0;
                }
            }
        }
    }
    cout<<ans;
}


// Created by Manuver
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << " : " << x << endl;

int points[2055][2055];

void set(int i, int j, int v) {
    points[i+1000][j+1000] = v;
}

int set(int i, int j) {
    return points[i+1000][j+1000];
}

int euclidean(int x0, int y0, int x1, int y1) {
    int x = x1 - x0;
    int y = y1 - y0;
    return ceil(sqrt((x*x) + (y*y)));
}

int main() {
    int x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    int xs = min(x1, x0), xe = max(x1, x0), ys = min(y1, y0), ye = max(y1, y0);
    int n; cin >> n;
    int a, b, c;
    for (int i=0; i<n; i++) {
        cin >> a >> b >> c;
        for (int i=xs; i<=xe; i++) {
            int dist = euclidean(i, ys, a, b);
            // printf("table cord : %d %d  heater cord : %d %d radius : %d distance : %d\n", i, ys, a, b, c, dist);
            if (dist <= c) {
                points[i+1000][ys+1000] = 1;
            }
            dist = euclidean(i, ye, a, b);
            // printf("table cord : %d %d  heater cord : %d %d radius : %d distance : %d\n", i, ye, a, b, c, dist);
            if (dist <= c) {
                points[i+1000][ye+1000] = 1;
            }
        }
        for (int i=ys; i<=ye; i++) {
            int dist = euclidean(xs, i, a, b);
            // printf("table cord : %d %d  heater cord : %d %d radius : %d distance : %d\n", xs, i, a, b, c, dist);
            if (dist <= c) {
                points[xs+1000][i+1000] = 1;
            }
            dist = euclidean(xe, i, a, b);
            // printf("table cord : %d %d  heater cord : %d %d radius : %d distance : %d\n", xe, i, a, b, c, dist);
            if (dist <= c) {
                points[xe+1000][i+1000] = 1;
            }
        }
    }
    int ans = 0;
    for (int i=xs; i<=xe; i++) {

        if (points[i+1000][ys+1000] == 0) {
            ans++;
        }
        if (points[i+1000][ye+1000] == 0) {
            ans++;
        }
    }
    for (int i=ys+1; i<ye; i++) {
        if (points[xs+1000][i+1000] == 0) {
            ans++;
        }
        if (points[xe+1000][i+1000] == 0) {
            ans++;
        }
    }
    cout << ans << endl;
}


// Created by Manuver
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << " : " << x << endl;

int points[2055][2055];

void set(int i, int j, int v) {
    points[i+1000][j+1000] = v;
}

int set(int i, int j) {
    return points[i+1000][j+1000];
}

int euclidean(int x0, int y0, int x1, int y1) {
    int x = x1 - x0;
    int y = y1 - y0;
    return ceil(sqrt((x*x) + (y*y)));
}

int main() {
    int x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    int xs = min(x1, x0), xe = max(x1, x0), ys = min(y1, y0), ye = max(y1, y0);
    int n; cin >> n;
    int a, b, c;
    for (int i=0; i<n; i++) {
        cin >> a >> b >> c;
        for (int i=xs; i<=xe; i++) {
            int dist = euclidean(i, ys, a, b);
            // printf("table cord : %d %d  heater cord : %d %d radius : %d distance : %d\n", i, ys, a, b, c, dist);
            if (dist <= c) {
                points[i][ys] = 1;
            }
            dist = euclidean(i, ye, a, b);
            // printf("table cord : %d %d  heater cord : %d %d radius : %d distance : %d\n", i, ye, a, b, c, dist);
            if (dist <= c) {
                points[i][ye] = 1;
            }
        }
        for (int i=ys; i<=ye; i++) {
            int dist = euclidean(xs, i, a, b);
            // printf("table cord : %d %d  heater cord : %d %d radius : %d distance : %d\n", xs, i, a, b, c, dist);
            if (dist <= c) {
                points[xs][i] = 1;
            }
            dist = euclidean(xe, i, a, b);
            // printf("table cord : %d %d  heater cord : %d %d radius : %d distance : %d\n", xe, i, a, b, c, dist);
            if (dist <= c) {
                points[xe][i] = 1;
            }
        }
    }
    int ans = 0;
    for (int i=xs; i<=xe; i++) {

        if (points[i][ys] == 0) {
            ans++;
        }
        if (points[i][ye] == 0) {
            ans++;
        }
    }
    for (int i=ys+1; i<ye; i++) {
        if (points[xs][i] == 0) {
            ans++;
        }
        if (points[xe][i] == 0) {
            ans++;
        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;

bool iscovered (int a, int b, int x, int y, int r)
{
    int r1, r2;
    r1=round(pow(x-a,2));
    r2=round(pow(y-b,2));
    float dist;
    dist=sqrt(r1+r2);
    if(dist<=r)
            return 1;
    else
            return 0;
}

int main(){
 int a, b, c, d, flag, i, j, n, x, y, count=0, isc, k;
 cin>>a>>b>>c>>d;
 cin>>n;
 int h[n][3];
 for(i=0;i<n;i++)
    cin>>h[i][0]>>h[i][1]>>h[i][2];
 if(a<c&&b<d){
    i=a;j=b;
    for(i=a;i<=c;i++){
        flag=0;
        for(k=0;k<n;k++){
            isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
            if(isc==1){
                flag=1;
                break;
            }
        }
        if(flag==0)
            count++;
    }
    j=d;
    for(i=a;i<=c;i++){
        flag=0;
        for(k=0;k<n;k++){
            isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
            if(isc==1){
                flag=1;
                break;
            }
        }
        if(flag==0)
            count++;
    }
    i=a;
    for(j=b-1;j<d;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    i=c;
    for(j=b-1;j<d;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

 }
 else if(a<c&&b>d){
    i=a;j=b;
    for(i=a;i<=c;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    j=d;
    for(i=a;i<=c;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

    i=a;
    for(j=d+1;j<b;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    i=c;
    for(j=d+1;j<b;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

 }
 else if(a>c&&b<d){
    i=c;j=b;
    for(i=c;i<=a;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    j=d;
    for(i=c;i<=a;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

    i=a;
    for(j=b+1;j<d;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    i=c;
    for(j=b+1;j<d;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

 }
 else{
    i=c;j=b;
    for(i=c;i<=a;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    j=d;
    for(i=c;i<=a;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

    i=a;
    for(j=d+1;j<b;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    i=c;
    for(j=d+1;j<b;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

  }
 cout<<count<<endl;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;

bool iscovered (int a, int b, int x, int y, int r)
{
    int r1, r2;
    r1=(x-a)*(x-a);
    r2=(y-b)*(y-b);
    int dist=r1+r2;
    if(dist<=(r*r))
            return 1;
    else
            return 0;
}

int main(){

 int a, b, c, d, flag, i, j, n, x, y, count=0, isc, k;
 cin>>a>>b>>c>>d;
 cin>>n;
 int h[n][3];
 for(i=0;i<n;i++)
    cin>>h[i][0]>>h[i][1]>>h[i][2];
 if(a<c&&b<d){
    i=a;j=b;
    for(i=a;i<=c;i++){

        flag=0;
        for(k=0;k<n;k++){
            isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
            if(isc==1){
                flag=1;
                break;
            }
        }

        if(flag==0)
            count++;
    }
    j=d;

    for(i=a;i<=c;i++){

        flag=0;
        for(k=0;k<n;k++){
            isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
            if(isc==1){
                flag=1;
                break;
            }
        }

        if(flag==0)
            count++;
    }
    i=a;

    for(j=b+1;j<d;j++){

        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }

        if(flag==0)
            count++;
    }
    i=c;

    for(j=b+1;j<d;j++){
        flag=0;

        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }

        if(flag==0)
            count++;
    }

 }
 else if(a<c&&b>d){
    i=a;j=b;
    for(i=a;i<=c;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    j=d;
    for(i=a;i<=c;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

    i=a;
    for(j=d+1;j<b;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    i=c;
    for(j=d+1;j<b;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

 }
 else if(a>c&&b<d){
    i=c;j=b;
    for(i=c;i<=a;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    j=d;
    for(i=c;i<=a;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

    i=a;
    for(j=b+1;j<d;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    i=c;
    for(j=b+1;j<d;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

 }
 else{
    i=c;j=b;
    for(i=c;i<=a;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    j=d;
    for(i=c;i<=a;i++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

    i=a;
    for(j=d+1;j<b;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }
    i=c;
    for(j=d+1;j<b;j++){
        flag=0;
        for(k=0;k<n;k++){
                isc=iscovered(i,j,h[k][0],h[k][1],h[k][2]);
                if(isc==1){
                    flag=1;
                    break;
                }
        }
        if(flag==0)
            count++;
    }

  }
 cout<<count<<endl;
 return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,t[5005],pos,pre;
long long cnt[5005];
bool f[5005];

int main()
{

    scanf("%d",&n);

    for(int i = 0; i < n; i++){
        scanf("%d",&t[i]);
        cnt[t[i]]++;
    }

    pre = t[0];
    pos = 0;

    for(int i = 1; i < n; i++){
        int y = t[i];
        cnt[y]++;
        if(cnt[y] >= cnt[pre]){
            if(y > pre){

            }
        }
    }

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,a,b,c,d,x[1005],y[1005],r[1005],aa,bb,cc,dd;

int dis(int p,int q,int r,int s)
{
    int u = (p-r)*(p-r) + (q-s)*(q-s);

    return u;
}

bool check(int a,int b)
{
    bool f =false;
    for(int i = 0; i < n; i++){
        int cc = x[i],dd = y[i];
        int y = dis(a,b,cc,dd);
        if(y <= r[i] * r[i]){
            f = true;
            break;
        }
    }

    if(f) return true;
    else return false;

}

int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&d);

    scanf("%d",&n);

    for(int i = 0; i < n; i++){
        scanf("%d%d%d",&x[i],&y[i],&r[i]);
    }

    int cnt = 0;

    aa = min(a,c);
    bb = max(a,c);
    cc = min(b,d);
    dd = max(b,d);
    //cout << aa << " "<< bb <<" " <<cc <<  " "<< dd  << endl;

    for(int i = aa; i <= bb; i++){
       // cout << i << " " << cc << endl;
        //cout << i << " " << dd  << endl;
        if(check(i,cc)) cnt++;
        if(check(i,dd)) cnt++;
    }

    for(int i = cc + 1; i < dd; i++){
       // cout << aa << " " << i << endl;
       // cout << bb << " " << i  << endl;
        if(check(aa,i)) cnt++;
        if(check(bb,i)) cnt++;
    }
    //cout << cnt << endl;
    int y = 2 * (bb - aa + 1) + 2 * (dd - cc - 1);
    //cout << y << endl;
    printf("%d\n",y - cnt);

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int lx1,lx2,ly1,coun=0,ly2,x,y,xa,ya,xb,yb,n;cin>>xa>>ya>>xb>>yb;
    vector <pair<int,int> > v;
    n=((max(ya,yb)-min(ya,yb))*2+(max(xa,xb)-min(xa,xb))*2);
    x=min(xa,xb);
    y=max(ya,yb);
    lx1=x;
    lx2=max(xa,xb);
    ly1=min(ya,yb);
    ly2=y;
    xb=n;
while(n--)
{
    if(x<lx2&&y==ly2)
    {
v.push_back(make_pair(x,y));
x++;
    }
    else if(x==lx2&&y>ly1)
    {
v.push_back(make_pair(x,y));
y--;
    }
    else if(x>lx1&&y==ly1)
    {
      v.push_back(make_pair(x,y));
      x--;
    }
    else if(x==lx1&&y<ly2)
    {
v.push_back(make_pair(x,y));
y++;
    }
}cin>>lx1;
for(int i=0;i<lx1;i++)
{
  cin>>xa>>ya>>lx2;
  for(int j=0;j<v.size();j++)
{
    if((lx2*lx2)>=(v[j].first-xa)*(v[j].first-xa)+(v[j].second-ya)*(v[j].second-ya)&&v[j].first!=-1&&v[j].second!=-1)

        {
            v[j].first=-1;
            v[j].second=-1;
            coun++;
        }
}
}
cout<<xb-coun;
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int lx1,lx2,ly1,coun=0,ly2,x,y,xa,ya,xb,yb,n;cin>>xa>>ya>>xb>>yb;
    vector <pair<int,int> > v;
    n=((max(ya,yb)-min(ya,yb))*2+(max(xa,xb)-min(xa,xb))*2);
    x=min(xa,xb);
    y=max(ya,yb);
    lx1=x;
    lx2=max(xa,xb);
    ly1=min(ya,yb);
    ly2=y;
    xb=n;
while(n--)
{
    if(x<lx2&&y==ly2)
    {
v.push_back(make_pair(x,y));
x++;
    }
    else if(x==lx2&&y>ly1)
    {
v.push_back(make_pair(x,y));
y--;
    }
    else if(x>lx1&&y==ly1)
    {
      v.push_back(make_pair(x,y));
      x--;
    }
    else if(x==lx1&&y<ly2)
    {
v.push_back(make_pair(x,y));
y++;
    }
}cin>>lx1;
for(int i=0;i<lx1;i++)
{
  cin>>xa>>ya>>lx2;
  for(int j=0;j<v.size();j++)
{
    if((lx2*lx2)>=(v[j].first-xa)*(v[j].first-xa)+(v[j].second-ya)*(v[j].second-ya)&&v[j].first!=-2*1069999999&&v[j].second!=-2*1069999999)

        {
            v[j].first=-2*1069999999;
            v[j].second=-2*1069999999;
            coun++;
        }
}
}
cout<<xb-coun;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long double LD;
typedef long long ll;
#define int ll
#define ff(i,a,b) for (int i = a; i < b; i++)
#define bf(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define one cout<<"-1"<<endl
#define pi 3.141592653589793238
#define mod 1000000007
#define intmx INT_MAX
#define intmi INT_MIN

void solve(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int xa=min(x1,x2),xb=max(x1,x2),ya=min(y1,y2),yb=max(y1,y2);
    std::vector<pair<int,int> > v;
    ff(i,xa,xb+1){
        v.pb(mp(i,ya));
        v.pb(mp(i,yb));
    }
    ff(i,ya+1,yb){
        v.pb(mp(xa,i));
        v.pb(mp(xb,i));
    }
    int m;
    cin>>m;
    set<int> st;
    while(m--){
        int x,y,r;
        cin>>x>>y>>r;
        ff(i,0,v.size()){
            if((x-v[i].F)*(x-v[i].F)+(y-v[i].S)*(y-v[i].S)<=r*r)
            st.insert(i);
        }
    }
    cout<<v.size()-st.size();
}
signed main() {
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main (int argc, char const *argv[]) {

       int x[2], y[2];
       cin >> x[0] >> y[0] >> x[1] >> y[1];

       sort(x, x + 2);
       sort(y, y + 2);

       double nGenerals = (x[1] - x[0] + 1) * 2 + (y[1] - y[0] - 1) * 2;

       double n, xi, yi, r;
       cin >> n;

       set<pair<int, int>> s;
       for (int i = 0; i < n; i++) {

              cin >> xi >> yi >> r;

              for (int j = x[0]; j <= x[1]; j++) {

                     if (j == x[0] || j == x[1]) {

                            for (int k = y[0]; k <= y[1]; k++)
                                   if (sqrtl(powl(xi - j, 2) + powl(yi - k, 2)) <= r)
                                          s.insert({j, k});
                     }
                     else {
                            if (sqrtl(powl(xi - j, 2) + powl(yi - y[0], 2)) <= r)
                                   s.insert({j, y[0]});

                            if (sqrtl(powl(xi - j, 2) + powl(yi - y[1], 2)) <= r)
                                   s.insert({j, y[i]});
                     }
              }

       }

       cout << nGenerals - (double) s.size();
       return 0;
}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main (int argc, char const *argv[]) {

       int x[2], y[2];
       cin >> x[0] >> y[0] >> x[1] >> y[1];

       sort(x, x + 2);
       sort(y, y + 2);

       double nGenerals = (x[1] - x[0] + 1) * 2 + (y[1] - y[0] - 1) * 2;

       double n, xi, yi, r;
       cin >> n;

       set<pair<int, int>> s;
       for (int i = 0; i < n; i++) {

              cin >> xi >> yi >> r;

              for (int j = x[0]; j <= x[1]; j++) {

                     if (j == x[0] || j == x[1]) {

                            for (int k = y[0]; k <= y[1]; k++)
                                   if (sqrtl(powl(xi - j, 2) + powl(yi - k, 2)) <= r)
                                          s.insert({j, k});
                     }
                     else {
                            if (sqrtl(powl(xi - j, 2) + powl(yi - y[0], 2)) <= r)
                                   s.insert({j, y[0]});

                            if (sqrtl(powl(xi - j, 2) + powl(yi - y[1], 2)) <= r)
                                   s.insert({j, y[1]});
                     }
              }

       }

       cout << nGenerals - (double) s.size();
       return 0;
}


#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main(void){
    int x1,y1,x2,y2;
    vector<pair<int,int> > pts;
    vector<int> check;
    cin>>x1>>y1>>x2>>y2;
    if(x1>x2){
        int temp=x1;
        x1=x2;
        x2=temp;
    }
    if(y1>y2) {
        int temp=y1;
        y1=y2;
        y2=temp;
    }
    for(int i=x1; i<=x2; ++i){
        pts.push_back(make_pair(i,y1));
        pts.push_back(make_pair(i,y2));
        check.push_back(0);
        check.push_back(0);
    }
    for(int i=y1+1; i<y2; ++i){
        pts.push_back(make_pair(x1,i));
        pts.push_back(make_pair(x2,i));
        check.push_back(0);
        check.push_back(0);
    }
    int n,x,y,r;
    cin>>n;
    for(int i=0; i<n; ++i){
        cin>>x>>y>>r;
        for(int j=0; j<pts.size(); ++j)
            if((x-pts[j].first)*(x-pts[j].first)+(y-pts[j].second)*(y-pts[j].second) <= r*r) check[j] =1;
    }
    int ctr=0;
    for(int i=0; i<check.size(); ++i)
        if(check[i]== 0) ++ctr;
    cout<<ctr;
}


#include <bits\stdc++.h>
#define int long long
using namespace std;
int x[2005];
int y[2005];
int r[2005];
int check(int xx,int yy,int size){
	for(int i = 0; i < size; i++){
		if(pow(xx-x[i],2) + pow(yy-y[i],2) <= r[i]*r[i]){
			return 0;
		}
	}
	return 1;
}
signed main()
{
	int n = 0,ans = 0;
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2 >> n;
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i] >>r[i];
	}
	for(int  i = min(x1,x2);i<max(x1,x2); i++){
		ans = ans + check(i,y1,n) + check(i,y2,n);
	}

	for(int  i = min(y1,y2);i<=max(y1,y2); i++){
		ans = ans + check(x1,i,n) + check(x2,i,n);
	}

	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int x[2006];
long long int y[2006];
long long int r[2006];
long long int n;
int check(long long int xx,long long int yy)
{
	for(long long int i=0;i<n;i++)
	{
		if(pow(xx-x[i],2)+pow(yy-y[i],2)<=r[i]*r[i])
		return 0;
	}
	return 1;
}
int main()
{
	long long int x1,y1,x2,y2,i,ans = 0;
	cin>>x1>>y1>>x2>>y2;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>x[i]>>y[i]>>r[i];
	}
	for(i=min(x1,x2);i<=max(x1,x2);i++)
	{
		ans+=check(i,y1)+check(i,y2);
	}
	for(i=min(y1,y2)+1;i<max(y1,y2);i++)
	{
		ans+=check(x1,i)+check(x2,i);
	}
	cout<<ans<<endl;
}


#include <bits\stdc++.h>
#define int long long
using namespace std;
int x[2005];
int y[2005];
int r[2005];
int check(int xx,int yy,int size){
	for(int i = 0; i < size; i++){
		if(pow(xx-x[i],2) + pow(yy-y[i],2) <= r[i]*r[i]){
			return 0;
		}
	}
	return 1;
}
signed main()
{
	int n = 0,ans = 0;
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2 >> n;
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i] >>r[i];
	}
	for(int  i = min(x1,x2);i<=max(x1,x2); i++){
		ans = ans + check(i,y1,n) + check(i,y2,n);
	}

	for(int  i = min(y1,y2);i<max(y1,y2); i++){
		ans = ans + check(x1,i,n) + check(x2,i,n);
	}

	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e2 + 5;

int a[MAXN];

int calc_dis(int x1, int y1, int x2, int y2) {
    return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
}

pair <pair<int, int>, int> p[MAXN];

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int x1, y1, x2, y2, n;
    cin >> x1 >> y1 >> x2 >> y2 >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i].first.first >> p[i].first.second >> p[i].second;
    }
    int ans = 0, all = 0;
    for (int i = min(x1, x2); i <= max(x1, x2); i++) {
        for (int j = min(y1, y2); j <= max(y1, y2); j++) {
            if (i > min(x1, x2) && i < max(x1, x2) && j > min(y1, y2) && j < max(y1, y2))
                continue;
            else {
                for (int k = 0; k < n; k++) {
                    if (calc_dis(p[k].first.first, p[k].first.second, i, j) <= p[k].second * p[k].second) {
                        ans++;
                        break;
                    }
                }
                all++;
            }
        }
    }
    cout << all - ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e3 + 5;

int a[MAXN];

int calc_dis(int x1, int y1, int x2, int y2) {
    return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
}

pair <pair<int, int>, int> p[MAXN];

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int x1, y1, x2, y2, n;
    cin >> x1 >> y1 >> x2 >> y2 >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i].first.first >> p[i].first.second >> p[i].second;
    }
    int ans = 0, all = 0;
    for (int i = min(x1, x2); i <= max(x1, x2); i++) {
        for (int j = min(y1, y2); j <= max(y1, y2); j++) {
            if (i > min(x1, x2) && i < max(x1, x2) && j > min(y1, y2) && j < max(y1, y2))
                continue;
            else {
                for (int k = 0; k < n; k++) {
                    if (calc_dis(p[k].first.first, p[k].first.second, i, j) <= p[k].second * p[k].second) {
                        ans++;
                        break;
                    }
                }
                all++;
            }
        }
    }
    cout << all - ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <math.h>
using namespace std;

double distance_rad(int xi,int yi , int xg , int yg)
{
    double first_pair = abs(xi-xg);
    first_pair=pow(first_pair,2);
    double second_pair = abs(yi-yg);
    second_pair = pow(second_pair,2);
    double distance_return = first_pair + second_pair;
    distance_return = sqrt(distance_return);

    return  distance_return;
}

int main()
{

    int xa,ya,xb,yb;
    cin>>xa>>ya>>xb>>yb;

    pair<int,int> point1;
    pair<int,int> point2;
    point1=make_pair(xa,ya);
    point2=make_pair(xb,yb);

    int n;
    cin>>n;
    vector<pair<pair<int,int>,int>> radiators; //radiator coordinate and their radius
    radiators.resize(n);
    for(int i =0 ; i<n; i++)
    {
        int xi,yi,ri;
        cin>>xi>>yi>>ri;
        radiators[i] = make_pair(make_pair(xi,yi),ri);
    }

    int where_point = 0 ;
    if(point1.first>point2.first)
    {
        if(point1.second>point2.second)
        {
            where_point=1;
        }
        else
        {
            where_point=2;
        }

    }
    else
    {
        if(point1.second>point2.second)
        {
            where_point=4;
        }
        else
        {
            where_point=3;
        }
    }
  pair<int,int> point3;
  pair<int,int>point4;
  point3=make_pair(point1.first,point2.second); point4=make_pair(point2.first,point1.second);  //other points in rectangle
  vector<pair<int,int>> up;         //segment of rectangle
  vector<pair<int,int>> down;
  vector<pair<int,int>> right;
  vector<pair<int,int>> left;

  if(where_point==1){

    int up_down_diff = abs(point1.first-point2.first);
    int left_right_diff = abs(point1.second-point2.second);

    for(int i = point4.first+1 ; i<point1.first ; i++)        //make the upper part of the rectangle containing generals
    {
        up.push_back(make_pair(i,point1.second));
    }
    for(int i = point2.second+1 ; i<point1.second ; i++)        //make the left part of the rectangle containing generals
    {
        left.push_back(make_pair(point2.first,i));
    }

    for(int i = point2.second+1 ; i<point1.second ; i++)        //make the right part of the rectangle containing generals
    {
        right.push_back(make_pair(point1.first, i));
    }

    for(int i = point2.first+1 ; i<point1.first ; i++)        //make the down part of the rectangle containing generals
    {
        down.push_back(make_pair(i, point2.second));
    }

    }
  else if(where_point==2){

    for(int i = point2.first+1 ; i<point1.first ; i++)        //make the upper part of the rectangle containing generals
    {
        up.push_back(make_pair(i,point2.second));
    }
    for(int i = point4.second+1 ; i<point2.second ; i++)        //make the left part of the rectangle containing generals
    {
        left.push_back(make_pair(point2.first,i));
    }

    for(int i = point1.second+1 ; i<point2.second ; i++)        //make the right part of the rectangle containing generals
    {
        right.push_back(make_pair(point1.first, i));
    }

    for(int i = point2.first+1 ; i<point1.first ; i++)        //make the down part of the rectangle containing generals
    {
        down.push_back(make_pair(i, point1.second));
    }

    }
  else if(where_point==3){

    for(int i = point1.first+1 ; i<point2.first ; i++)        //make the upper part of the rectangle containing generals
    {
        up.push_back(make_pair(i,point2.second));
    }
    for(int i = point1.second+1 ; i<point2.second ; i++)        //make the left part of the rectangle containing generals
    {
        left.push_back(make_pair(point1.first,i));
    }

    for(int i = point1.second+1 ; i<point2.second ; i++)        //make the right part of the rectangle containing generals
    {
        right.push_back(make_pair(point2.first, i));
    }

    for(int i = point1.first+1 ; i<point2.first ; i++)        //make the down part of the rectangle containing generals
    {
        down.push_back(make_pair(i, point1.second));
    }

    }
  else if(where_point==4){

     for(int i = point1.first+1 ; i<point2.first ; i++)        //make the upper part of the rectangle containing generals
    {
        up.push_back(make_pair(i,point1.second));
    }
    for(int i = point2.second+1 ; i<point1.second ; i++)        //make the left part of the rectangle containing generals
    {
        left.push_back(make_pair(point1.first,i));
    }

    for(int i = point2.second+1 ; i<point1.second ; i++)        //make the right part of the rectangle containing generals
    {
        right.push_back(make_pair(point2.first, i));
    }

    for(int i = point1.first+1 ; i<point2.first ; i++)        //make the down part of the rectangle containing generals
    {
        down.push_back(make_pair(i, point2.second));
    }
    }
    up.push_back(point2);
    down.push_back(point1);
    left.push_back(point3);
    right.push_back(point4);
    int num_blacket = 0 ;

    for(auto up_point : up)
    {
        int x_g = up_point.first;
        int y_g = up_point.second;
        int within_distance = false;
        for(auto radiator : radiators)
        {
            int xi = radiator.first.first;
            int yi = radiator.first.second;
            int ri = radiator.second;
            if(distance_rad(xi,yi,x_g,y_g)<=ri)within_distance=true;

        }
        if(!within_distance)num_blacket++;
    }

    for(auto right_point : right)
    {

        int x_g = right_point.first;
        int y_g = right_point.second;
        int within_distance = false;
        for(auto radiator : radiators)
        {
            int xi = radiator.first.first;
            int yi = radiator.first.second;
            int ri = radiator.second;
            if(distance_rad(xi,yi,x_g,y_g)<=ri)within_distance=true;

        }
        if(!within_distance)num_blacket++;
    }

    for(auto left_point : left)
    {
        int x_g = left_point.first;
        int y_g = left_point.second;
        int within_distance = false;
        for(auto radiator : radiators)
        {
            int xi = radiator.first.first;
            int yi = radiator.first.second;
            int ri = radiator.second;
            if(distance_rad(xi,yi,x_g,y_g)<=ri)within_distance=true;
        }
        if(!within_distance)num_blacket++;
    }

    for(auto down_point : down)
    {
        int x_g = down_point.first;
        int y_g = down_point.second;
        int within_distance = false;
        for(auto radiator : radiators)
        {
            int xi = radiator.first.first;
            int yi = radiator.first.second;
            int ri = radiator.second;
            if(distance_rad(xi,yi,x_g,y_g)<=ri)within_distance=true;

        }
        if(!within_distance)num_blacket++;
    }

    cout<<num_blacket<<endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <math.h>
using namespace std;

double distance_rad(int xi,int yi , int xg , int yg)
{
    double first_pair = (xi-xg)*(xi-xg);
    double second_pair = (yi-yg)*(yi-yg);
    double distance_return = first_pair + second_pair;
    return  distance_return;
}

int main()
{
    int xa,ya,xb,yb;
    cin>>xa>>ya>>xb>>yb;
    int n; cin>>n;

    int x_up;
    int x_down;
    int y_right;
    int y_left;

    if(xa>xb) {x_down=xa; x_up=xb;}
    else if(xb>xa){x_down=xb; x_up = xa;}

    if(ya>yb){y_right = ya; y_left = yb;}
    else if(yb>ya){y_right=yb; y_left = ya;}

    vector<pair<int,int>> general_right;

    general_right.push_back(make_pair(x_up,y_right));
    for(int i = 1 ; i<x_down-x_up;i++)
    {
        general_right.push_back(make_pair(x_up+i,y_right));
    }
    general_right.push_back(make_pair(x_down,y_right));

    vector<pair<int,int>> general_up;

    for(int i = 1 ; i<y_right-y_left ;i++)
    {
        general_up.push_back(make_pair(x_up,y_left+i));
    }

    vector<pair<int,int>> general_down;
    for(int i = 1 ; i<y_right-y_left;i++)
    {
        general_down.push_back(make_pair(x_down,y_left+i));
    }
    vector<pair<int,int>> general_left;
    general_left.push_back(make_pair(x_up,y_left));

    for(int i = 1 ; i<x_down-x_up ;i++)
    {
        general_left.push_back(make_pair(x_up+i,y_left));
    }
    general_left.push_back(make_pair(x_down,y_left));

    //coordinates of the generals

    vector<pair<pair<int,int>,int>> radiators; //radiator coordinate and their radius
    radiators.resize(n);

    for(int i =0 ; i<n; i++)
    {
        int xi,yi,ri;
        cin>>xi>>yi>>ri;
        radiators[i] = make_pair(make_pair(xi,yi),ri);
    }

    int num_blancket = 0 ;

        //check all generals
        for(auto general: general_up)
        {
            int xg = general.first;
            int yg = general.second;
            bool use_blancket = false;
            for(auto radiator: radiators)
            {
                int xi = radiator.first.first;
                int yi=radiator.first.second;
                int radius = radiator.second;
                if(distance_rad(xi,yi , xg,yg)<=radius) use_blancket=true;

            }

            if(!use_blancket)num_blancket++;
        }

        for(auto general : general_down)
        {
            int xg = general.first;
            int yg = general.second;
            bool use_blancket = false;
            for(auto radiator: radiators)
            {
                int xi = radiator.first.first;
                int yi=radiator.first.second;
                int radius = radiator.second;
                if(distance_rad(xi,yi , xg,yg)<=radius) use_blancket=true;

            }

            if(!use_blancket)num_blancket++;

        }

        for(auto general : general_left)
        {
            int xg = general.first;
            int yg = general.second;
            bool use_blancket = false;
            for(auto radiator: radiators)
            {
                int xi = radiator.first.first;
                int yi=radiator.first.second;
                int radius = radiator.second;
                if(distance_rad(xi,yi , xg,yg)<=radius) use_blancket=true;

            }

            if(!use_blancket)num_blancket++;

        }

        for(auto general : general_right)
        {
            int xg = general.first;
            int yg = general.second;
            bool use_blancket = false;
            for(auto radiator: radiators)
            {
                int xi = radiator.first.first;
                int yi=radiator.first.second;
                int radius = radiator.second;
                if(distance_rad(xi,yi , xg,yg)<=radius) use_blancket=true;

            }

            if(!use_blancket)num_blancket++;

        }

            cout<<num_blancket<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long 			LL;
typedef unsigned long long	ULL;
typedef vector<int>			vi;
typedef vector<vi>			vvi;
typedef pair<int,int> 		pii;
#define scf					scanf
#define prf					printf
#define all(c)				c.begin(),c.end()
#define sz(c)				((int)((c).size()))
#define pb					push_back
#define eb					emplace_back
#define popb				pop_back
#define mp					make_pair
#define xf					first
#define ys					second
#define lp(i,s,e)			for(__typeof(e) i=s ; i<e ;  ++i)
#define lpr(i,e,s)			for(__typeof(e) i=e ; i>s ;  --i)
#define lpo(var , c)		for(const auto &var : c)
#define mems(c,val)			memset(c,val,sizeof(c))
#define mod					1000000007
#define OOi					(~(1<<31))
#define OOl					(~((LL)1<<63))
#define PI					(3.141592654)
#define EPS					(1e-7)
//___________________________________________________________.
#define dis(c_x,c_y,p) 		(sqrt( (c_x-p.xf)*(c_x-p.xf)+(c_y-p.ys)*(c_y-p.ys) ))

vector<pii> p;
vector<char> O;

void f(pii a,pii b){
	lp(i,a.xf,b.xf)
		p.pb({i,a.ys});

	lpr(j,a.ys,b.ys)
		p.pb({b.xf,j});

	lpr(i,b.xf,a.xf)
		p.pb({i,b.ys});

	lp(j,b.ys,a.ys)
		p.pb({a.xf,j});
}

int main(){
	p.reserve(8000);
	pii a,b;
	scf("%d %d %d %d",&a.xf,&a.ys,&b.xf,&b.ys);

	if(b.ys>a.ys)swap(a,b);

	if(a.xf>b.xf)f(mp(b.xf,a.ys),mp(a.xf,b.ys));
	else f(a,b);

	O.resize(sz(p),0);
	int n;
	scf("%d",&n);

	lp(i,0,n){
		int x,y,r;
		scf("%d %d %d",&x,&y,&r);

		lp(i,0,sz(p))
			if(dis(x,y,p[i])<=r)
				O[i]=1;
	}

	prf("%d\n",count(all(O),0));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long 			LL;
typedef unsigned long long	ULL;
typedef vector<int>			vi;
typedef vector<vi>			vvi;
typedef pair<int,int> 		pii;
#define scf					scanf
#define prf					printf
#define all(c)				c.begin(),c.end()
#define sz(c)				((int)((c).size()))
#define pb					push_back
#define eb					emplace_back
#define popb				pop_back
#define mp					make_pair
#define xf					first
#define ys					second
#define lp(i,s,e)			for(__typeof(e) i=s ; i<e ;  ++i)
#define lpr(i,e,s)			for(__typeof(e) i=e ; i>s ;  --i)
#define lpo(var , c)		for(const auto &var : c)
#define mems(c,val)			memset(c,val,sizeof(c))
#define mod					1000000007
#define OOi					(~(1<<31))
#define OOl					(~((LL)1<<63))
#define PI					(3.141592654)
#define EPS					(1e-7)
//___________________________________________________________.
#define dis(c_x,c_y,p) 		(sqrt( (c_x-p.xf)*(c_x-p.xf)+(c_y-p.ys)*(c_y-p.ys) ))

vector<pii> p;
vector<char> O;

void f(pii a,pii b){
	lp(i,a.xf,b.xf)
		p.eb(i,a.ys);

	lpr(j,a.ys,b.ys)
		p.eb(b.xf,j);

	lpr(i,b.xf,a.xf)
		p.eb(i,b.ys);

	lp(j,b.ys,a.ys)
		p.eb(a.xf,j);
}

int main(){
	p.reserve(8000);
	pii a,b;
	scf("%d %d %d %d",&a.xf,&a.ys,&b.xf,&b.ys);

	if(b.ys>a.ys)swap(a,b);

	if(a.xf>b.xf)f(mp(b.xf,a.ys),mp(a.xf,b.ys));
	else f(a,b);

	O.resize(sz(p),0);
	int n;
	scf("%d",&n);

	lp(i,0,n){
		int x,y,r;
		scf("%d %d %d",&x,&y,&r);

		lp(i,0,sz(p))
			if(dis(x,y,p[i])<=r)
				O[i]=1;
	}

	prf("%d\n",count(all(O),0));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long 			LL;
typedef unsigned long long	ULL;
typedef vector<int>			vi;
typedef vector<vi>			vvi;
typedef pair<int,int> 		pii;
#define scf					scanf
#define prf					printf
#define all(c)				c.begin(),c.end()
#define sz(c)				((int)((c).size()))
#define pb					push_back
#define eb					emplace_back
#define popb				pop_back
#define mp					make_pair
#define xf					first
#define ys					second
#define lp(i,s,e)			for(__typeof(e) i=s ; i<e ;  ++i)
#define lpr(i,e,s)			for(__typeof(e) i=e ; i>s ;  --i)
#define lpo(var , c)		for(const auto &var : c)
#define mems(c,val)			memset(c,val,sizeof(c))
#define mod					1000000007
#define OOi					(~(1<<31))
#define OOl					(~((LL)1<<63))
#define PI					(3.141592654)
#define EPS					(1e-7)
//___________________________________________________________.
vector<pii> p;
vector<pair<pii,int> >c;
set<int> G;

void f1(pii a,pii b){
	lp(i,a.xf,b.xf)
			p.eb(i,a.ys);

	lpr(j,a.ys,b.ys)
		p.eb(b.xf,j);

	lpr(i,b.xf,a.xf)
		p.eb(i,b.ys);

	lp(j,b.ys,a.ys)
		p.eb(a.xf,j);
}
void f2(pii a, pii b){
	lpr(j,a.ys,b.ys)
		p.eb(a.xf,j);

	lpr(i,a.xf,b.xf)
		p.eb(i,b.ys);

	lp(j,b.ys,a.ys)
		p.eb(b.xf,j);

	lp(i,b.xf,a.xf)
		p.eb(i,a.ys);
}

bool dis(const pair<pii,int>&p1 , const pii &p2){
	return sqrt( ((p1.xf.xf-p2.xf-0.0)*1.0*(p1.xf.xf-p2.xf) + (p1.xf.ys-p2.ys-0.0)*1.0*(p1.xf.ys-p2.ys-0.0) ))<=p1.ys;
}
int main(){
	p.reserve(8000);
	c.reserve(1000);
	pii a,b;
	scf("%d %d %d %d",&a.xf,&a.ys,&b.xf,&b.ys);

	if(b.ys>a.ys)swap(a,b);
	if(a.xf<b.xf)f1(a,b);
	else f2(a,b);

	int n;
	scf("%d",&n);
	lp(i,0,n){
		int x,y,r;
		scf("%d %d %d",&x,&y,&r);
		c.eb(mp(x,y),r);
	}

	lp(k,0,n){
		lp(i,0,sz(p)){
			if(dis(c[k],p[i]))G.emplace(i);
		}
	}
	prf("%d",sz(p)-sz(G));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long 			LL;
typedef unsigned long long	ULL;
typedef vector<int>			vi;
typedef vector<vi>			vvi;
typedef pair<int,int> 		pii;
#define scf					scanf
#define prf					printf
#define all(c)				c.begin(),c.end()
#define sz(c)				((int)((c).size()))
#define pb					push_back
#define eb					emplace_back
#define popb				pop_back
#define mp					make_pair
#define xf					first
#define ys					second
#define lp(i,s,e)			for(__typeof(e) i=s ; i<e ;  ++i)
#define lpr(i,e,s)			for(__typeof(e) i=e ; i>s ;  --i)
#define lpo(var , c)		for(const auto &var : c)
#define mems(c,val)			memset(c,val,sizeof(c))
#define mod					1000000007
#define OOi					(~(1<<31))
#define OOl					(~((LL)1<<63))
#define PI					(3.141592654)
#define EPS					(1e-7)
//___________________________________________________________.
#define dis(c_x,c_y,p) 		(sqrt( (c_x-p.xf)*(c_x-p.xf)+(c_y-p.ys)*(c_y-p.ys) ))

vector<pii> p;
set<int> G;

void f(pii a,pii b){
	lp(i,a.xf,b.xf)
		p.eb(i,a.ys);

	lpr(j,a.ys,b.ys)
		p.eb(b.xf,j);

	lpr(i,b.xf,a.xf)
		p.eb(i,b.ys);

	lp(j,b.ys,a.ys)
		p.eb(a.xf,j);
}

int main(){
	p.reserve(8000);

	pii a,b;
	scf("%d %d %d %d",&a.xf,&a.ys,&b.xf,&b.ys);

	if(b.ys>a.ys)swap(a,b);

	if(a.xf>b.xf)f(mp(b.xf,a.ys),mp(a.xf,b.ys));
	else f(a,b);

	int n;
	scf("%d",&n);

	lp(i,0,n){
		int x,y,r;
		scf("%d %d %d",&x,&y,&r);

		lp(i,0,sz(p))
			if(dis(x,y,p[i])<=r)
				G.emplace(i);
	}

	prf("%d\n",sz(p)-sz(G));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef unsigned long long llu;

#define author ayushtomar
#define rf freopen("in.txt", "r", stdin)
#define wf freopen("out.txt", "w", stdout)
#define debug(x) cerr<<#x<<" "<<x<<endl;
#define f first
#define s second
#define mp make_pair
#define pb push_back
int A[1<<21];
vector < pair < pll, long long  > > v;
int main()
{
    ll xa,ya,xb,yb;
    cin>>xa>>ya>>xb>>yb;
    int n;
    if(xa>xb)
        {
            swap(xa,xb);
            swap(ya,yb);
        }    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        {
            ll x,y,r;
            cin>>x>>y>>r;
         v.pb(mp(mp(x,y),r));
        }
    ll x=xa,y=ya,addx=1,addy=0;
    int counts=0,ready=0;
    while(1)
    {
        if(x==xa&&y==ya)
        {
            if(ready==1)
                break;
        }
        ready=1;

        int i;
        for(i=0;i<n;i++)
        {
            ll p=v[i].f.f;
            ll q=v[i].f.s;
            ll r=v[i].s;
            ll dis=(p-x)*(p-x)+(q-y)*(q-y);
            if( (dis-r*r) <=0)
                break;
        }
        if(i==n)
            {//printf("%lld %lld\n",x,y);

                counts++;
            }
        if(x==xb&&y==ya)
        {
            addx=0;
            if(yb>ya)
                addy=1;
            else
                addy=-1;
        }
        else if(x==xb&&y==yb)
        {
            addx=-1;
            addy=0;
        }
        else if(x==xa&&y==yb)
        {
            addx=0;
            if(yb>ya)
                addy=-1;
            else
                addy=1;
        }
        x=x+addx;
        y=y+addy;
    }
    cout<<counts;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef unsigned long long llu;

#define author ayushtomar
#define rf freopen("in.txt", "r", stdin)
#define wf freopen("out.txt", "w", stdout)
#define debug(x) cerr<<#x<<" "<<x<<endl;
#define f first
#define s second
#define mp make_pair
#define pb push_back
int A[1<<21];
vector < pair < pii, int > > v;
int main()
{
    ll xa,ya,xb,yb;
    cin>>xa>>ya>>xb>>yb;
    int n;
    if(xa>xb)
        {
            swap(xa,xb);
            swap(ya,yb);
        }    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        {
            ll x,y,r;
            cin>>x>>y>>r;
         v.pb(mp(mp(x,y),r));
        }
    ll x=xa,y=ya,addx=1,addy=0;
    int counts=0,ready=0;
    while(1)
    {
        if(x==xa&&y==ya)
        {
            if(ready==1)
                break;
        }
        ready=1;

        int i;
        for(i=0;i<n;i++)
        {
            ll p=v[i].f.f;
            ll q=v[i].f.s;
            ll r=v[i].s;
            ll dis=(p-x)*(p-x)+(q-y)*(q-y);
            if( (dis-r*r) <=0)
                break;
        }
        if(i==n)
            {printf("%lld %lld\n",x,y);

                counts++;
            }
        if(x==xb&&y==ya)
        {
            addx=0;
            if(yb>ya)
                addy=1;
            else
                addy=-1;
        }
        else if(x==xb&&y==yb)
        {
            addx=-1;
            addy=0;
        }
        else if(x==xa&&y==yb)
        {
            addx=0;
            if(yb>ya)
                addy=-1;
            else
                addy=1;
        }
        x=x+addx;
        y=y+addy;
    }
    cout<<counts;
 return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <math.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
typedef long long ll;
struct pairs {
	ll first;
	ll second;
};
struct save {
	int xe;
	int ye;
	int re;
};
bool check(int xr, int yr, int r, int x, int y)
{
	if ((xr - x)*(xr - x) + (yr - y)*(yr - y) <= r * r)
		return true;
	return false;
}
int main()
{
	int xa, ya, xb, yb;
	cin >> xa >> ya >> xb >> yb;
	int n;
	cin >> n;
	int count = 0;
	int xi, yi, ri;
	save *tui;
	tui = new save[n];
	REP(i, 0, n)
	{
		cin >> tui[i].xe >>tui[i]. ye >> tui[i].re;
	}
	bool check1;
	for (int j = min(xa,xb); j <= max(xa,xb); j++)
	{
		check1 = false;
		REP(i, 0, n)
		{
			if (check(tui[i].xe, tui[i].ye, tui[i].re, j, max(ya,yb) )== true)
			{
				check1 = true;
				break;
			}
		}
		if (check1 == false)
			count += 1;
	}
	for (int j = max(ya,yb)-1; j >=min(ya, yb); j--)
	{
		check1 = false;
		REP(i, 0, n)
		{
			if (check(tui[i].xe, tui[i].ye, tui[i].re, min(xa,xb), j) == true)
			{
				check1 = true;
				break;
			}
		}
		if (check1 == false)
			count += 1;
	}
	for (int j = min(xa,xb)+1; j <= max(xa,xb); j++)
	{
		check1 = false;
		REP(i, 0, n)
		{
			if (check(tui[i].xe, tui[i].ye, tui[i].re, j, min(ya,yb)) == true)
			{
				check1 = true;
				break;
			}
		}
		if (check1 == false)
			count += 1;
	}
	for (int j = min(yb,ya)+1; j< max(ya,yb); j++)
	{
		check1 = false;
		REP(i, 0, n)
		{
			if (check(tui[i].xe, tui[i].ye, tui[i].re, max(xa,xb), j) == true)
			{
				check1 = true;
				break;
			}
		}
		if (check1 == false)
			count += 1;
	}
	cout << count;
	//system("pause");
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <math.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
typedef long long ll;
struct pairs {
	ll first;
	ll second;
};
void generate(int numslot, int need, float &countans, int current)
{
	if (need == current && numslot == 0)
	{
		countans += 1;
		return;
	}
	if (numslot == 0)
	{
		return;
	}
	generate(numslot - 1, need, countans, current + 1);
	generate(numslot - 1, need, countans, current - 1);
}
int factorial(int n)
{
	if (n == 1)
		return 1;
	return n * factorial(n - 1);
}
bool checkout(int x1, int y1, int x2, int y2)
{
	if (y1 < x2)
		return true;
	if (y2 < x1)
		return true;
	return false;
}
struct ranked {
	double height;
	int order;
};
void generate(int *a, int n, int index, bool &find, int total)
{
	if (index == n)
	{
		if (total % 360 == 0)
		{
			find = true;
		}
		return;
	}
	generate(a, n, index + 1, find, total + a[index]);
	if (find == true)
		return;
	generate(a, n, index + 1, find, total - a[index]);
}
struct pair1 {
	int f;
	int s;
	int d;
};
bool checkver(int col, int **&a)
{
	if (a[0][col] == 1 && a[1][col] == 1 && a[2][col] == 1 && a[3][col] == 1)
	{
		a[0][col] = 0;
		a[1][col] = 0;
		a[2][col] = 0;
		a[3][col] = 0;
		return true;
	}
	return false;
}
bool checkhor(int row, int **&a)
{
	if (a[row][0] == 1 && a[row][1] == 1 && a[row][2] == 1 && a[row][3] == 1)
	{
		a[row][0] = 0;
		a[row][1] = 0;
		a[row][2] = 0;
		a[row][3] = 0;
		return true;
	}
	return false;
}
struct me {
	bool choose;
	int dif;
	int startindex;
};
struct operation {
	int start;
	int end;
	ll  num;
};
struct dishes
{
	ll remain;
	ll cost;
	ll index;
};
struct save {
	int x;
	int y;
	int r;
};
bool sorting(dishes x, dishes y) { return x.cost < y.cost; }
bool check(int xr, int yr, int r, int x, int y)
{
	if ((xr - x)*(xr - x) + (yr - y)*(yr - y) <= r * r)
		return true;
	return false;
}
int main()
{
	int xa, ya, xb, yb;
	cin >> xa >> ya >> xb >> yb;
	int n;
	cin >> n;
	int count = 0;
	int xi, yi, ri;
	save *tui;
	tui = new save[n];
	REP(i, 0, n)
	{
		cin >> tui[i].x >>tui[i]. y >> tui[i].r;
	}
	bool check1;
	for (int j = xa; j <= xb; j++)
	{
		check1 = false;
		REP(i, 0, n)
		{
			if (check(tui[i].x, tui[i].y, tui[i].r, j, ya) == true)
			{
				check1 = true;
				break;
			}
		}
		if (check1 == false)
			count += 1;
	}
	for (int j = ya-1; j >= yb; j--)
	{
		check1 = false;
		REP(i, 0, n)
		{
			if (check(tui[i].x, tui[i].y, tui[i].r, xa, j) == true)
			{
				check1 = true;
				break;
			}
		}
		if (check1 == false)
			count += 1;
	}
	for (int j = xa+1; j <= xb; j++)
	{
		check1 = false;
		REP(i, 0, n)
		{
			if (check(tui[i].x, tui[i].y, tui[i].r, j, yb) == true)
			{
				check1 = true;
				break;
			}
		}
		if (check1 == false)
			count += 1;
	}
	for (int j = yb+1; j< ya; j++)
	{
		check1 = false;
		REP(i, 0, n)
		{
			if (check(tui[i].x, tui[i].y, tui[i].r, xb, j) == true)
			{
				check1 = true;
				break;
			}
		}
		if (check1 == false)
			count += 1;
	}
	cout << count;
	//system("pause");
}


#include <iostream>
#include <vector>
using namespace std;
struct header{
	pair<int,int> x;
	int r;
};
bool test(pair<int,int> p1,pair<int,int> p2,int r){
	return (p1.first-p2.first)*(p1.first-p2.first)+(p1.second-p2.second)*(p1.second-p2.second)<=r*r;
}
int main() {
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	int n;
	cin>>n;
	vector<header>v;
	for(int i=0;i<n;i++){
		header h;
		cin>>h.x.first>>h.x.second>>h.r;
		v.push_back(h);
	}
	int ans=0;
	for(int i=y2;i<=y1;i++){
		pair<int,int>p1=make_pair(x1,i);
		pair<int,int>p2=make_pair(x2,i);
		//cout<<p1.first<<" "<<p1.second<<" "<<p2.first<<" "<<p2.second<<endl;
		bool enter1=false,enter2=false;
		for(int k=0;k<v.size();k++){
			if(test(p1,v[k].x,v[k].r)){
				enter1=true;
			}
			if(test(p2,v[k].x,v[k].r)){
				enter2=true;
			}
			if(enter1&&enter2)
				break;

		}
		if(!enter1){
			ans++;
			//cout<<p1.first<<" "<<p1.second<<endl;
		}
		if(!enter2){
			ans++;
			//cout<<p2.first<<" "<<p2.second<<endl;
		}

	}
	for(int i=x1+1;i<x2;i++){
		pair<int,int>p1=make_pair(i,y1);
		pair<int,int>p2=make_pair(i,y2);
		//cout<<p1.first<<" "<<p1.second<<" "<<p2.first<<" "<<p2.second<<endl;
		bool enter1=false,enter2=false;
		for(int k=0;k<v.size();k++){
			if(test(p1,v[k].x,v[k].r)){
				enter1=true;
			}
			if(test(p2,v[k].x,v[k].r)){
				enter2=true;
			}
			if(enter1&&enter2)
				break;

		}
		if(!enter1){
			ans++;
			//cout<<p1.first<<" "<<p1.second<<endl;
		}
		if(!enter2){
			ans++;
			//cout<<p2.first<<" "<<p2.second<<endl;
			}
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
struct header{
	pair<int,int> x;
	int r;
};
bool test(pair<int,int> p1,pair<int,int> p2,r){
	return (p1.first-p2.first)*(p1.first-p2.first)+(p1.second-p2.second)*(p1.second-p2.second)<=r*r;
}
int main() {
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	int n;
	cin>>n;
	vector<header>v;
	for(int i=0;i<n;i++){
		header h;
		cin>>h.x.first>>h.x.second>>h.r;
		v.push_back(h);
	}
	for(int i=y2;i<=y1;i++){
		pair<int,int>p1={x1,i};
		pair<int,int>p2={x2,i};
		bool enter1=false,enter2=false;
		for(int k=0;k<v.size();k++){
			if(test(p1,))

		}

	}
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
struct header{
	pair<int,int> x;
	int r;
};
bool test(pair<int,int> p1,pair<int,int> p2,int r){
	return (p1.first-p2.first)*(p1.first-p2.first)+(p1.second-p2.second)*(p1.second-p2.second)<=r*r;
}
int main() {
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	int n;
	cin>>n;
	vector<header>v;
	for(int i=0;i<n;i++){
		header h;
		cin>>h.x.first>>h.x.second>>h.r;
		v.push_back(h);
	}
	int ans=0;
	for(int i=y2;i<=y1;i++){
		pair<int,int>p1={x1,i};
		pair<int,int>p2={x2,i};
		bool enter1=false,enter2=false;
		for(int k=0;k<v.size();k++){
			if(test(p1,v[i].x,v[i].r)){
				enter1=true;
			}
			if(test(p2,v[i].x,v[i].r)){
				enter2=true;
			}
			if(enter1&&enter2)
				break;

		}
		if(!enter1)
			ans++;
		if(!enter2)
			ans++;

	}
	for(int i=x1;i<=x2;i++){
		pair<int,int>p1={i,y1};
		pair<int,int>p2={i,y2};
		bool enter1=false,enter2=false;
		for(int k=0;k<v.size();k++){
			if(test(p1,v[i].x,v[i].r)){
				enter1=true;
			}
			if(test(p2,v[i].x,v[i].r)){
				enter2=true;
			}
			if(enter1&&enter2)
				break;

		}
		if(!enter1)
			ans++;
		if(!enter2)
			ans++;

	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
struct header{
	pair<int,int> x;
	int r;
};
bool test(pair<int,int> p1,pair<int,int> p2,int r){
	return (p1.first-p2.first)*(p1.first-p2.first)+(p1.second-p2.second)*(p1.second-p2.second)<=r*r;
}
int main() {
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	int n;
	cin>>n;
	vector<header>v;
	for(int i=0;i<n;i++){
		header h;
		cin>>h.x.first>>h.x.second>>h.r;
		v.push_back(h);
	}
	int ans=0;
	for(int i=y2;i<=y1;i++){
		pair<int,int>p1={x1,i};
		pair<int,int>p2={x2,i};
		bool enter1=false,enter2=false;
		for(int k=0;k<v.size();k++){
			if(test(p1,v[i].x,v[i].r)){
				enter1=true;
			}
			if(test(p2,v[i].x,v[i].r)){
				enter2=true;
			}
			if(enter1&&enter2)
				break;

		}
		if(!enter1)
			ans++;
		if(!enter2)
			ans++;

	}
	for(int i=x1;i<=x2;i++){
		pair<int,int>p1={i,y1};
		pair<int,int>p2={i,y2};
		bool enter1=false,enter2=false;
		for(int k=0;k<v.size();k++){
			if(test(p1,v[i].x,v[i].r)){
				enter1=true;
			}
			if(test(p2,v[i].x,v[i].r)){
				enter2=true;
			}
			if(enter1&&enter2)
				break;

		}
		if(!enter1)
			ans++;
		if(!enter2)
			ans++;

	}
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
struct header{
	pair<int,int> x;
	int r;
};
bool test(pair<int,int> p1,pair<int,int> p2,int r){
	return (p1.first-p2.first)*(p1.first-p2.first)+(p1.second-p2.second)*(p1.second-p2.second)<=r*r;
}
int main() {
	int x1,y1,x2,y2,xa,xb,ya,yb;
	cin>>xa>>ya>>xb>>yb;
	x1=min(xa,xb);
	x2=max(xa,xb);
	y1=min(ya,yb);
	y2=max(ya,yb);
	//cout<<x1<<" "<<y1<<" "<<x2<<" "<<x2<<endl;
	int n;
	cin>>n;
	vector<header>v;
	for(int i=0;i<n;i++){
		header h;
		cin>>h.x.first>>h.x.second>>h.r;
		v.push_back(h);
	}
	int ans=0;
	for(int i=y1;i<=y2;i++){
		pair<int,int>p1=make_pair(x1,i);
		pair<int,int>p2=make_pair(x2,i);
		//cout<<p1.first<<" "<<p1.second<<" "<<p2.first<<" "<<p2.second<<endl;
		bool enter1=false,enter2=false;
		for(int k=0;k<v.size();k++){
			if(test(p1,v[k].x,v[k].r)){
				enter1=true;
			}
			if(test(p2,v[k].x,v[k].r)){
				enter2=true;
			}
			if(enter1&&enter2)
				break;

		}
		if(!enter1){
			ans++;
			//cout<<p1.first<<" "<<p1.second<<endl;
		}
		if(!enter2){
			ans++;
			//cout<<p2.first<<" "<<p2.second<<endl;
		}

	}
	for(int i=x1+1;i<x2;i++){
		pair<int,int>p1=make_pair(i,y1);
		pair<int,int>p2=make_pair(i,y2);
		//cout<<p1.first<<" "<<p1.second<<" "<<p2.first<<" "<<p2.second<<endl;
		bool enter1=false,enter2=false;
		for(int k=0;k<v.size();k++){
			if(test(p1,v[k].x,v[k].r)){
				enter1=true;
			}
			if(test(p2,v[k].x,v[k].r)){
				enter2=true;
			}
			if(enter1&&enter2)
				break;

		}
		if(!enter1){
			ans++;
			//cout<<p1.first<<" "<<p1.second<<endl;
		}
		if(!enter2){
			ans++;
			//cout<<p2.first<<" "<<p2.second<<endl;
			}
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <string.h>
#include <cmath>
#include <set>
using namespace std;

int xa, ya, xb, yb;
int n;
int x[1000];
int y[1000];
int r[1000];
bool warm[1000];
double EPS = 1e-6;
int ans = 0;

int sqr(int x) {
    return x * x;
}

double dist(int x1, int y1, int x2, int y2) {
       return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}

int main() {
    scanf("%d %d %d %d", &xa, &ya, &xb, &yb);
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
            scanf("%d %d %d", x + i, y + i, r + i);
    }

    for(int i = min(xa, xb); i <= max(xa, xb); i++) {
            int currX = i;
            int currY = ya;
            bool warm = 0;
            for(int j = 0; j < n; j++) {
                    double currD = dist(currX, currY, x[j], y[j]);
                    if (currD < r[j] || fabs(currD - r[j]) < EPS) {
                              warm = 1;
                    }
            }
            if (!warm) ans++;
            warm = 0;
            currY = yb;
            for(int j = 0; j < n; j++) {
                    double currD = dist(currX, currY, x[j], y[j]);
                    if (currD < r[j] || fabs(currD - r[j]) < EPS) {
                              warm = 1;
                    }
            }
            if (!warm) ans++;

    }

    for(int i = min(ya, yb) + 1; i < max(ya, yb); i++) {
            int currY = i;
            int currX = xa;
            bool warm = 0;
            for(int j = 0; j < n; j++) {
                    double currD = dist(currX, currY, x[j], y[j]);
                    if (currD < r[j] || fabs(currD - r[j]) < EPS) {
                              warm = 1;
                    }
            }
            if (!warm) ans++;
            warm = 0;
            currX = xb;
            for(int j = 0; j < n; j++) {
                    double currD = dist(currX, currY, x[j], y[j]);
                    if (currD < r[j] || fabs(currD - r[j]) < EPS) {
                              warm = 1;
                    }
            }
            if (!warm) ans++;
    }

    printf("%d", ans);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <string.h>
#include <cmath>
#include <set>
using namespace std;

int xa, ya, xb, yb;
int n;
int x[1000];
int y[1000];
int r[1000];
bool warm[1000];
double EPS = 1e-7;
int ans = 0;

int sqr(int x) {
    return x * x;
}

double dist(int x1, int y1, int x2, int y2) {
       return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}

int main() {
    scanf("%d %d %d %d", &xa, &ya, &xb, &yb);
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
            scanf("%d %d %d", x + i, y + i, r + i);
    }

    for(int i = min(xa, xb); i <= max(xa, xb); i++) {
            int currX = i;
            int currY = ya;
            bool warm = 0;
            for(int j = 0; j < n; j++) {
                    double currD = dist(currX, currY, x[j], y[j]);
                    if (currD < r[j] || fabs(currD - r[j]) < EPS) {
                              warm = 1;
                    }
            }
            if (!warm) ans++;
            currY = yb;
            for(int j = 0; j < n; j++) {
                    double currD = dist(currX, currY, x[j], y[j]);
                    if (currD < r[j] || fabs(currD - r[j]) < EPS) {
                              warm = 1;
                    }
            }
            if (!warm) ans++;

    }

    for(int i = min(ya, yb) + 1; i < max(ya, yb); i++) {
            int currY = i;
            int currX = xa;
            bool warm = 0;
            for(int j = 0; j < n; j++) {
                    double currD = dist(currX, currY, x[j], y[j]);
                    if (currD < r[j] || fabs(currD - r[j]) < EPS) {
                              warm = 1;
                    }
            }
            if (!warm) ans++;
            currX = xb;
            for(int j = 0; j < n; j++) {
                    double currD = dist(currX, currY, x[j], y[j]);
                    if (currD < r[j] || fabs(currD - r[j]) < EPS) {
                              warm = 1;
                    }
            }
            if (!warm) ans++;
    }

    printf("%d", ans);

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int minx, miny, maxx, maxy;
int at(int x,int y) {
	if (y==miny) {
		return x-minx;
	}
	else if(y==maxy) {
		return (maxx-minx+1)+(x-minx);
	}
	if (x==minx) {
		return 2*(maxx-minx+1) + y-miny-1;
	}
	else if(x==maxx) {
		return 2*(maxx-minx+1) + (maxy-miny-1) + y-miny-1;
	}
}
void test() {
	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	minx = x1>x2?x2:x1;
	maxx = x1<x2?x2:x1;
	miny = y1>y2?y2:y1;
	maxy = y1<y2?y2:y1;

	vector<int> occupied (2*(maxx-minx+maxy-miny), 0);

	int n, x, y, r;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>x>>y>>r;
		double yup = y+floor(sqrt(r*r-(minx-x)*(minx-x)));
		double ydown = y-ceil(sqrt(r*r-(minx-x)*(minx-x)));
		for (int j=ydown;j<=yup;j++) {
			if (miny<=j && j<=maxy)
				occupied[at(minx,j)] = 1;
		}
		yup =  y+floor(sqrt(r*r-(maxx-x)*(maxx-x)));
		ydown = y-ceil(sqrt(r*r-(maxx-x)*(maxx-x)));
		for (int j=ydown;j<=yup;j++) {
			if (miny<=j && j<=maxy)
				occupied[at(maxx,j)] = 1;
		}
		double xup = x+floor(sqrt(r*r-(miny-y)*(miny-y)));
		double xdown = x-ceil(sqrt(r*r-(miny-y)*(miny-y)));
		for (int j=xdown;j<=xup;j++) {
			if (minx<=j && j<=maxx)
				occupied[at(j,miny)] = 1;
		}
		xup =  x+floor(sqrt(r*r-(maxy-y)*(maxy-y)));
		xdown = x-ceil(sqrt(r*r-(maxy-y)*(maxy-y)));
		for (int j=xdown;j<=xup;j++) {
			if (minx<=j && j<=maxx)
				occupied[at(j,maxy)] = 1;
		}
	}
	int val =0;
	for (int i=0;i<occupied.size();i++) {
		if (!occupied[i])
			val++;
	}
	cout<<val;
}
int main() {
	//code
	int t=1;
	while (t--) {
	    test();
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int minx, miny, maxx, maxy;
int at(int x,int y) {
	if (y==miny) {
		return x-minx;
	}
	else if(y==maxy) {
		return (maxx-minx+1)+(x-minx);
	}
	if (x==minx) {
		return 2*(maxx-minx+1) + y-miny-1;
	}
	else if(x==maxx) {
		return 2*(maxx-minx+1) + (maxy-miny-1) + y-miny-1;
	}
}
void test() {
	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	minx = x1>x2?x2:x1;
	maxx = x1<x2?x2:x1;
	miny = y1>y2?y2:y1;
	maxy = y1<y2?y2:y1;

	vector<int> occupied (2*(maxx-minx+maxy-miny), 0);

	int n, x, y, r;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>x>>y>>r;
		for (int j = minx;j<=maxx;j++) {
			if ( ( (x-j)*(x-j) + (y-miny)*(y-miny) ) <= r*r ) {
				occupied[at(j,miny)]=1;
			}
		}
		for (int j = minx;j<=maxx;j++) {
			if ( ( (x-j)*(x-j) + (y-maxy)*(y-maxy) ) <= r*r ) {
				occupied[at(j,maxy)]=1;
			}
		}
		for (int j = minx;j<=maxx;j++) {
			if ( ( (y-j)*(y-j) + (x-minx)*(x-minx) ) <= r*r ) {
				occupied[at(minx,j)]=1;
			}
		}
		for (int j = minx;j<=maxx;j++) {
			if ( ( (y-j)*(y-j) + (x-maxx)*(x-maxx) ) <= r*r ) {
				occupied[at(maxx,j)]=1;
			}
		}
	}
	int val =0;
	for (int i=0;i<occupied.size();i++) {
		if (!occupied[i])
			val++;
	}
	cout<<val;
}
int main() {
	//code
	int t=1;
	while (t--) {
	    test();
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int minx, miny, maxx, maxy;
int at(int x,int y) {
	if (y==miny) {
		return x-minx;
	}
	if(y==maxy) {
		return (maxx-minx+1)+(x-minx);
	}
	if (x==minx) {
		return 2*(maxx-minx+1) + y-miny-1;
	}
	if(x==maxx) {
		return 2*(maxx-minx+1) + (maxy-miny-1) + y-miny-1;
	}
}
void test() {
	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	minx = x1>x2?x2:x1;
	maxx = x1<x2?x2:x1;
	miny = y1>y2?y2:y1;
	maxy = y1<y2?y2:y1;

	// cout<<at(4,3);
	// cout<<minx<<" "<<miny<<" "<<maxx<<" "<<maxy<<" ";

	vector<int> occupied (2*(maxx-minx+maxy-miny), 0);

	int n, x, y, r;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>x>>y>>r;
		for (int j = minx;j<=maxx;j++) {
			if ( ( (x-j)*(x-j) + (y-miny)*(y-miny) ) <= r*r ) {
				occupied[at(j,miny)]=1;
			}
			// cout<<(at(j, miny))<<" ";
			if ( ( (x-j)*(x-j) + (y-maxy)*(y-maxy) ) <= r*r ) {
				occupied[at(j,maxy)]=1;
			}
				// cout<<(at(j, maxy))<<" ";
		}
		for (int j = miny;j<=maxy;j++) {
			if ( ( (y-j)*(y-j) + (x-minx)*(x-minx) ) <= r*r ) {
				occupied[at(minx,j)]=1;
			}
			// cout<<(at(minx, j))<<" ";
			if ( ( (y-j)*(y-j) + (x-maxx)*(x-maxx) ) <= r*r ) {
				occupied[at(maxx,j)]=1;
			}
			// cout<<(at(maxx, j))<<" ";
		}
	}
	int val =0;
	for (int i=0;i<occupied.size();i++) {
		if (!occupied[i])
			val++;
	}
	cout<<val;
}
int main() {
	//code
	int t=1;
	while (t--) {
	    test();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e5+1;
int main () {
    int xa,ya,xb,yb;
    scanf("%d %d %d %d",&xa,&ya,&xb,&yb);
    int xc = min(xa, xb);
    int yc = min(ya, yb);
    int xd = max(xa, xb);
    int yd = max(ya, yb);
    vector <pair<int,int> > v;
    for (int y = yc;y <= yd; y++)
    for (int  x=xc;x<=xd;x++){
            v.push_back({x,y});
    }
    int n;
    map < pair <int,int> , bool > vis;
    vis[{xa,ya}]= 1;
    vis[{xb,yb}]=1;
    scanf("%d",&n);
    int x, y, r;
    for (int i=0;i<n;i++){
        scanf("%d %d %d",&x,&y,&r);
        for (auto p:v){
            if (vis[p])continue;
            int X = p.first, Y = p.second;
            int DIS = (X - x)*(X - x) + (Y - y) * (Y - y);
            if (DIS <= r*r){
                vis[{X,Y}] = 1;
            }
        }
    }
    int ans = 0;
    for (auto p:v)if (!vis[p])ans++;
    printf("%d",ans);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e5+1;
int main () {
    int xa,ya,xb,yb;
    scanf("%d %d %d %d",&xa,&ya,&xb,&yb);
    int xc = min(xa, xb);
    int yc = min(ya, yb);
    int xd = max(xa, xb);
    int yd = max(ya, yb);
    set <pair<int,int> > v;
    for (int y:{yc,yd})
        for (int x=xc;x<=xd;x++)
            v.insert({x,y});
    for (int y=yc;y<=yd;y++)
        for (int x:{xc,xd})
            v.insert({x,y});
    int n;
    map < pair <int,int> , bool > vis;
    scanf("%d",&n);
    int x, y, r;
    for (int i=0;i<n;i++){
        scanf("%d %d %d",&x,&y,&r);
        for (auto p:v){
            if (vis[p])continue;
            int X = p.first, Y = p.second;
            int DIS = (X - x)*(X - x) + (Y - y) * (Y - y);
            if (DIS <= r*r){
                vis[{X,Y}] = 1;
            }
        }
    }
    int ans = 0;
    for (auto p:v)if (!vis[p])ans++;
    printf("%d",ans);
}


#include <bits/stdc++.h>
using namespace std;
long long a[1005][3];
int n;
long long chec(long long x,long long y)
{
		int ye=0;
	for(int i=0;i<n;i++)
	{
	{
		long long re=(x-a[i][0])*(x-a[i][0])+(y-a[i][1])*(y-a[i][1])-(a[i][2]*a[i][2]);
		//cout<<re<<"\n";
		if(re<=0)
		return 0;
	}}

	return 1;

}

int main()
{
	long long xa,xb,ya,yb;
	cin>>xa>>ya>>xb>>yb;
	if(xb<xa)
	swap(xa,xb);
	if(yb<ya)
	swap(ya,yb);
	cin>>n;

	for(int i=0;i<n;i++)
	{for(int j=0;j<3;j++)
	cin>>a[i][j];}

	long long count=0;

		for(long long j=ya;j<=yb;j++)
		{
			count+=chec(xa,j);
			count+=chec(xb,j);
		}

			for(long long j=xa+1;j<xb;j++)
		{
			count+=chec(j,ya);
			count+=chec(j,yb);
	}
	cout<<count;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long a[1005][3];
int n;
long long chec(long long x,long long y)
{
		int ye=0;
	for(int i=0;i<n;i++)
	{
	{
		long long re=pow((x-a[i][0]),2)+pow((y-a[i][1]),2)-pow(a[i][2],2);
		//cout<<re<<"\n";
		if(re<=0)
		ye=1;
	}}
	if(ye==0)
	return 1;
	else
	return 0;

}

int main()
{
	long long xa,xb,ya,yb;
	cin>>xa>>ya>>xb>>yb;
	if(xb<xa)
	swap(xa,xb);
	if(yb<ya)
	swap(ya,yb);
	cin>>n;

	for(int i=0;i<n;i++)
	{for(int j=0;j<3;j++)
	cin>>a[i][j];}

	long long count=0;

		for(long long j=ya;j<=yb;j++)
		{
			count+=chec(xa,j);
			count+=chec(xb,j);
		}

			for(long long j=xa+1;j<xb;j++)
		{
			count+=chec(j,ya);
			count+=chec(j,yb);
	}
	cout<<count;
	return 0;
}


#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
const double PI = acos(-1.0);
const double  EPS = 1e-11;
typedef long long ll;
//freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
int xpos[1009], ypos[1009], r[1009],n;
int dist(int x1, int y1, int x2, int y2)
{
	return (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
}
bool check(int x, int y)
{
	for (int i = 0; i < n; i++)
		if (dist(x, y, xpos[i], ypos[i]) <= r[i] * r[i])
			return 0;
	return 1;
}
int main()
{
	int x1, y1, x2, y2, ans = 0;
	cin >> x1 >> y1 >> x2 >> y2 >> n;
	for (int i = 0; i < n; i++)
		cin >> xpos[i] >> ypos[i] >> r[i];

	for (int i = min(x1, x2); i <= max(x1, x2); i++)
		ans += check(i, y1) + check(i,y2);

	for (int i = min(y1, y2)+1; i < max(y1, y2); i++)
		ans += check(x1,i) + check(x2,i);

	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
double distanceCalculate(double x1, double y1, double x2, double y2)
{
	double x = x1 - x2; //calculating number to square in next step
	double y = y1 - y2;
	double dist;

	dist = pow(x, 2) + pow(y, 2);       //calculating Euclidean distance
	dist = sqrt(dist);

	return dist;
}
int main()
{
    long long int a,b,c,d,x1,x2,x3,x4,y1,y2,y3,y4,i,j,ct=0,f,n,s[1005][4];
    double dist;
	cin>>a>>b>>c>>d;
    x1=a;
    y1=b;
    x2=c;
    y2=b;
    x3=c;
    y3=d;
    x4=a;
    y4=d;

    cin>>n;

    for(i=0;i<n;i++)
        cin>>s[i][1]>>s[i][2]>>s[i][3];

    for(i=min(x1,x2);i<=max(x1,x2);i++)
    {
        f=0;
        for(j=0;j<n;j++)
            {
                 dist = distanceCalculate(i,y1,s[j][1],s[j][2]);
                if(dist<=s[j][3])
                {
                    f=1;
                    break;
                }
        }
        if(f==0)
            ct++;
    }

    for(i=min(y2,y3);i<max(y2,y3);i++)
    {
        f=0;
        for(j=0;j<n;j++)
            {
                dist = distanceCalculate(x2,i,s[j][1],s[j][2]);
                 if(dist<=s[j][3])
                {
                    f=1;
                    break;
                }
        }
        if(f==0)
        {
            ct++;
        }
    }

    for(i=min(x3,x4);i<=max(x3,x4);i++)
    {
        f=0;
        for(j=0;j<n;j++)
            {
                 dist = distanceCalculate(i,y3,s[j][1],s[j][2]);
                if(dist<=s[j][3])
                {
                    f=1;
                    break;
                }
        }
        if(f==0)
            ct++;
    }

    for(i=min(y1,y4);i<max(y1,y4);i++)
    {
        for(j=0;j<n;j++)
            {
                 dist = distanceCalculate(x1,i,s[j][1],s[j][2]);
                if(dist<=s[j][3])
                {
                    f=1;
                    break;
                }
        }
        if(f==0)
            ct++;
    }
    cout<<ct;
	return 0;
}