#include <bits/stdc++.h>
using namespace std;
/*
Coded by 秦惜梦
The most attractive girl in the world
.........   `;!!!!!!!!!;;;;;;;;::::::'''''''``''''''''````````````````````....`:;;;;;:'.....`:|$$$$$$$|;;;:`.    ..........`''``...`''``.   ........   ...  ...   ....  ...   ...  '
........     '!!!!!!!!!;;;;;;;:::::::::''''':::''''`````````````````````......`:;;;;;!%$$%!'.....`:|$%!;;;'....   .....`....`'''`...```..    ........  ..   ...    ..   ...  ...   '
........     .:!!!!!!!!;;;;;;;:::::::::::::::'''''''`````````..```````........`:;!%$$$$$$$$$$$%!'.....`:|!'````..   .........`''``.......    ........  ...  ...   ...   ..   ..   .'
.......       `;!!!!!!;;;;;;;;::::::::::::::::'''''```````````.``````...       .`';|%$$$$$&&$$$$$$%%;'..`'':'''``..  ...``.....```.   ....    .......  ...  ...   ...  ...  ...   .'
.......      . '!!!!!!;;;;;;;:::'''''''''::::::'''```````````````````.........':'`.......`:!%%|||%$$$$$&%;'::::''``.   .```..   ....   ....   .......   ..  ...   ..   ...  ...  ..'
......      '::'''':::::::::::::'''''''''''::::''''``````````````````.........'!$$$$$$%!:`.......`:!%&&&|'``':::'''``.....```.   ....   ...    ......   .......   ..   ..  ...   ..'
``...       .`.``'::::::::;;;;:::::'''''''`'''''`````````````..```````........'!$$$$$$$$$$$$$$%!;'`.....`'`..`'::''''`.....```..  ....   ...   ......   ........ .... .......  ....'
````.      .````.`;!!!;;;;;;;;::'''''''``'''''`````````````````````````.. ....`:!|%$$$&&&&&&&$%%$&&&&@&$|::'`.`''''''''`....````.  ....   ...   ......   .  .....```..``.....  ... '
````      .````.  `;!!;;;;;;;:::::'''''':::'''''````````````........`````.... ........````........``'::::::::'``.``'''''``...````.. ....   ...  ......   .  ......``.```....   ..  '
```.      .```.  .`';!!;;;;;;;:::::::::::::'''''``````````..........````````...`;$$$$&&&&&&$%%||||!|!;;::::::::'`...`'''''`....````.  .... ...   .....   .   .. .``..```....  ..   '
``.       .``.  .`'`';!;;;;;;;;:::::::::::'''''`````````...........`````````....'!|%%%%%%%%%%%%%%%%%%$&&&|:'''''''`...`'''''`....```.  .... ...   .....  .   ..  ..  ......   .   .'
`.        .`.  `''''`';!;;;;;;;::::::::::'''''''```````..........````````````....:|%%%%%%%%%%%%%%%%%%%%%%|:`''''''''`...`''''`....```.. ...   ..  .....  ..  .   ..  .. ...  ..  ..'
`         .  .`'''''``';!;;;;;;;:::::::''''''''''```.``........```````````````````!%%%%%%%%%%||!;:''`.........`'''''''`...`''''`...````.....  ..   ....  ..  .   .   .  ..  ..  ...'
            .''''''````';!;;;;;;;:::::'''''''''''```````````````````````````.........``````...  ...```':;!!:....`'''''''``..`'''`....```.  ... ..  ....      ..  .   .  ..  ..  ...'
         .`''''''''``````;!;;;;;;:::::'''''''''''``````````'''''''''``....```````````````````````````':!||%|;``....`''''''``..`''``....`..  ...     ...   .  .   .  .. ..  .   ... '
        .'''''''''````````:;;;;:::'''''':::::::::::::''''''''''''``..``````....```````````````````````````:!!'`'`.....`'''''``...```.  .........    ....     .  ..  .  .  ..  ...  '
        `'''''''''````';;;:::::::::::::::::::::::''''```````````..........```````````````````````````````````'`.``'``....`''''``.. .`.. ..... ...    ...        .  .. ..  .   ..   '
       .'''''''''```````';;:::::''''''''''''''''''`''```````.`````.....````````````````````````````````''``````....``''`...``''```......  ........   ...     .     .  .  .   ..    '
       `''''''''````'''`````.`::::::::'''''''''''''''''``.``.```........````````````''''`````````````````''''''''`....``'``...``````...... ........   ..     .  .  . .   .  ..     '
      .`'''''''```'''''````````':::::::''''''''''''''``.``.`............`````````'''''''''''''''``````````'''''''''`.....````....```...  ..  ......    .                .   .     .'
      `'''''''`''''''''````````.`::::::'''''''''''''`.```..............``````````'''''''''''''''''````````''''''''''``.......```.........  .  ....     .     ........              '
     .`''''''`''''''''``````````.`:::::::'''''''''``.`..............```````'''''''''''''''''''''''''``````'''''''''''''.........``... .....  .  ...     ..`:::::::::::::'`.        '
      .'''''`''''''''``````````````':::::''''''''``..````````````````````''''''''''''''''''':''''''```''````''''::''''''`.```..........  .....   ....    `'::::::::::::::::`.      '
     ....`''''''''''```````````````.`':::::'''''`...``````````''''''''''''''''''''''''''''''';:'''``''`::````';:''''''''''.....``......... .....   ...   `::::::::::::::::::'`.....'
    ......`''''''''``````````````````.':::::::'`...``'''````''''''''''''''''''''''''''''''';!:;:'''':!;::'```````''''''''''`   ........ ..... ...    ..  ....`':::':::::::::::'... '
    .......`'''''`````````````````````.`':::'```.`''''''````''''''''':'''::'''::''':;::!!!;:;!;;:```````::`````````'''''''''`.     ............  ..   ..          .':::::::::''`   '
   ........`''`````````````````````````..`':''`:;:'':''':''''''''''''::'':;:'''''''''::'''''':;;;:``````:;'```''``````'``'''''`.... ...........    ..                 `::::::'`.   '
  ..........`````````````````````````'::::''':;!!!!;:'::':!;;;:::'''';;'''::::''''':'''::'''''''::'`````':''``''````::`':'''''''''.         ......                      .''`....   '
.`'`.......```````````````````````````````'':!;:::::::::':;::::::::''::''`''::::'`''''':::'':''`:;'`````':'```''`````::`````'''''':;'..................                 .......  . '
`'''''```````````````````````````````````.`;!:::::::::::'''::::::::''::''``'::::'``'''''::''''''':'````````````'`````''````````````:!!;'................              ..........   '
'''''`````````````````````````````````````;!;;;:':::''::''''::::;;:'':::'```'::'````''''''''''''':'```````````''````````````````````';!!!;'....  ......               .......      '
''''````````````````````````````````````';!;;;:'::::':''`''':::;;;:'''':'``'':'````.```''''''''`':'````````````'`````````..``....`...`:!!!!:`.`.....                    .          '
'''````````````````````````````````````':;!;;:`'::':'''``''':::;;;:''``'```'':'``....''`'''''''`''`.`````````````.````````.............';;'.`:;;;'`.                 .....   ...   '
''````````````````````````````````````'':!;::'`::':::''`''''':;;;;:```````'''''```...''`'''''''`''`.``.````````````````````............... `;;;;;;;;;:`.                ....   ....'
''''''''````````````````````````````''`:!;;:''':''::''`'':''':;;;;'```'```''''''`.`'``:'''::''''''```````````````````````````.............`:;;;;;;;;;;;'.      .         ....    ..'
:::::::''''````````````````````````''`'!!;:''''''':''`''''''':;;;:```::``'''':'''`';:';:'::::':`''`''`````````````````'``````````..........`:;;;;;;;;;:.     `'..          .....   '
|%$$%%!;;:'''````````````````````''``';!;:'''':'``'''`'':''':::;:'``:!:``':::::::`:!;';;':::::''`''::````'''''````````''`````````...........`:;;;;;;;'.    .':` `;;;;:. ..   ..... '
@@@@@@@@$|;:''`````````````````''```';!;:::::::'``````'':''::::::'`'!|:`':::;:::'';|!:;;'''''''::::;:``'::''`'````````''````````````.........`:;;;;;`     .:;'..';;;;;;;;;:` ......'
@@@@@@@@@@$|;:''`````````````:'`````;;;:';;;;::'`'````'':''::::::'`;!!;':::::::'`.';!;;;:::::';!!::;'`':::'``'`.``````''````````.......... ..``';;:`     .';;` `:;;;;;;;;;:` `;;;;;;
@@@@@@@@@@@&|;:'``````````''```````;;::':;;;;:'`''```'':'::::;;;:':;|!!;:'''''::::!||!!!!;!!!!||;:!'`:::::'````..``````''`````.......... .  ..`':;`     .';;:` ';;;;;;;;;;:. ';;;;;;
@@@@@@@@@@#@$!:''`````````````````::```';;;;::``'''``'::':::;;;::;;!|||!::;;!!!;;;:'``````'':!!!!|:``':::'`````:;:`.``````.............   . ..`';'     .';;;'..:;;;;;;;;;;'..';;;;;;
@@@@@@@@@@@@$|;:'````````````````::````:;;;::'.`''```''''':::;:::;||%|||%%%%%|!:''''`...`'':!;:;|;```:::'``''`';!;'..`````..............  . ..`''.    .';;;:` `;;;;;;;;;;;' .:;;;;;;
@@@@@@@@@@@&%!;:'```````````````''````':;;;::'..''```````:::::';||%%%%%%$$&&&%!;!|$&%:..';!%%!!|!'`;::::'``''';!;;'...````..............  ....``..   .';;;;'..';;;;;;;;;;;` `:;;;;;;
@@@@@@@@@#@%!!;:'````````````````````.'''::::`..````'''::!||||%%%%&&&&&&&&&&&&&$&&&%||||!|%%%%|!:';;;;!;``''`:;;;:`....`...................`....```. .`':::` `:;;;;;;;;;;:` `;;;;;;;
@@@@@@##@$|!!;:''```````````````````````':'```..`````':!;:''''':!%$&&&&&&&&&&&&$$$|!;;!|%%%%%%|;':;''::'`'''`:!;:`........................```..````........  .':;;;;;;;;;'. ';;;;;;;
!%$$$$%%|!!!;:''``````````````````````````````````````';!:'::'``':|$&&&&&&&&&&&&$$$$$$$$%%%%%|!:```''::'''''```...........................``..`'''`........   ......'::;;'..';;;;;;;
;!!!!!!!!!!;:''``````````````````````````````..````````'!%!;!;;!!%$%$&&&&&&&&&&&&$$$$$$$$$$%%||;``'''':''''``..`....    ... .................`'''````.....   .....`.......  `::;;;;;
::;!!!!!;;:''````````````````````````````````...````````'!%|!|%$$$$%$&&&&&&&&&&&&&&$$$$$$$$%|||:``''''''''```..`....      ..    ...     ....`'''`''```....   .'|%%;......    .... .'
``'::::'''````````````````````````````````````..`...```'`'|&$$$$$$$%$&&&&&&&&&&&&&&$$$$$$$$%%%|:`'''''''''```..`....                    ....`''```''```... .:%%%%|:......   .......'
 .````````````````````````````````````````````.``..```````:|&$$$$$$|%$&&&&&&&&&&&&&&&&&$$$$%%%|:'`'''''''````..`....                      .``'`````''````. :%%%%%;`....... ........'
  .``````````````````````````````````````````..`..`````````:%&&&&&&$%|%$&&&&&&&&&&&&&&&&$$$%$%|:'`'''''''````.``.....                    .``'`````'`'':|:.'!%%%%|'.`````.   .......'
  .```````````````````````````````````````````'`..`````````.:$&&&&&&&&&&&&&&&&&&&&&&&&&&&$$$$%|;'```''''```````.......                  .``'```'``':|%%|'.'|%%%%;```````...........'
  .`````````````````````````````````````````:'`..''````````..!&&&&&&&&&&&&&&&&&&&&&&&&&&&$$&$%%;''```''````````....   .                .'''`.`'``'`;%%%;``;%%$%!'..................'
  .``````````````````````````````````````;|:.``.`''''`````...`|&&&&&&&&&&&&&&&&&&&&&&&&&&$$&&$%!:'```````````.``..                    .`''```;;'''';%%%:.:%&&$|:...................:
  .```````````````````````````````````'!!```'`.`:!:''`````. ..`|&&&&&&&&&&&$%%$$$%|%$$&&&$$&&&$%;'`.``..`......`.                   ..`''''!;''''':|%$|'`!&&$|:...................`:
   .````````````````````````````````;|:````'::`'!;::''''`.  ...`!&&&&&&&&&&&&&&$&&&&&&&&&&$&&&&$|:'```.``.........        .`.    ....`'''```''''';$&&&;`:!;`......................`:
   .`````````````````````````````:|;`````'';:'`';:'''```.. ......'|&&&&&&&&&&&%%%$&&&&&&&$$&&&&&%;'`'`..```........         ``  `;:`''''``'```'!$&&&%!'.....................```````:
   .``````````````````````````:|;``````'':;:'``':'''`````. ........`:%&&&&&&&&&&&&&&&&&&&$&&&&|!!!;'''`....``......`.        .;%%;`''''';|||!;:''::;;' ..``......``````````````````:
   .```````````````````````!%:````````'':;:'```'':''````.. ............'|&@&&&&&&&&&&&&&&&$$|;!!!!!;:'``'`....``...````..      `:;;:'''!%;::::::::;;`. .````````'''````````````````:
   .```````````````````:%!'``````````'::::'````'''''````.  .............```;$&@&&&&&&&&&&$|;;!!!!!!!!;```::`  ...``.';;'```.    `:::'';$$|;:::::!;'`....``````''''''''````''''`````:
   .```````````````:%|'`````````````'::::'`````'''''''``.  .....  ....`````````;$&&&&@&|::!!;!!!!!!!!|!'```';'..  ....'!%%|!::``'':'':|$&&$|!!;:;:'`. .```````':::::''''''''''''''':
   .``````````;||:```````````````''::'::'````.`'''''''`.. .......  ..`````````````';:`````';!!!!!!!||||!;'```';!:`... ..`:|%%!'''''`:!%$&&&$$$!:;;;:'``'```''::::::::''''':::::'''';
   ..``';;:'```````````````````'''::'':'```````'''::''`..  .......   ..``````````````````. '||!!!|||||||!!;'````'!|;'``````````'''`';:'`'%&&&&&&|;!;:;!!!;;::;;::::::''''::::::::::;
``...``````````````````````''''''::''''`````````':::''``. .........  ....```````````...   .:!||||||%%%|||!!!!;'````'!||;'```.`'''`.`.`''`.;$&&&$:  .``'::::;!|%$$%|;:''':::::::::::;
    .````````````````````'''''''::```'````````.`:::'''```. .......... .............    `!%|!!||||%%||||!!!!!|%%%!:````````..`'''..``''`.....':. .   ..`':;;;;;;;::::;!%&%!;;;;:::::;
    .`````````````````''''''''''''''::'''````..`::''''`````. ........``............ .;%%%|!!!||%%%%%%%|!!!|%%%%%%||%%%%%%!'`'''`````....``.....       ..  .`':;;;;;;:::::;!%%!;;;;;;
    .`````````````'''''''''''```''''::'''''``..`''''''```````........````````.....:%%%$%||!|||%%%%%%%||!|%%%%%%%%%%%%|||!'`'''';%%|;`````......'`.      ..      `':::::::;;;;;|%!;;;
    .``````````''''''''''```````'```''''````..`.`'''''````````....  ..```....  `|%%%%$%|||!|%%%%%%%%%|!|%%%%%%%%%%%%%%%|:`'''`;%%%%!:.:!|%$$$$|;:'`...   .``..  .`.  '::::;;;;;;!%!;
%!'..```````''''''''''``````````'```'````````.``.`'''''```````.......       .;%%%%%%%|!!!||%%%%%|!!!!!|%%%%%%%%%%%%%%%%:`''''!%%%!!!:`:!|%$$$$$$$$$%|'`.  .```'`.``.  ..     .':::|%
%%%%%%;```''''''''```````````````'``''``````.````.`''''`..'````.......`'''';|%%%%%%%%||%%%%%%%%%%%|!!%%%%%%%%%%%%%%%%%:`'''';%%||||:`:!|%$$$$$$$$$$$$$%;``. .``''`.                '
$$$%%%%%$$|:''````````````````````''''``````.`````.`'''''`...      .`':|%$$%%%%%%%%%|!|%%%%%%%%%%|||%%$$%%%%%%%%%%%%%:`'''';%||%%%;.:||%$$$$$$$$$$$$$$&&&%:...````''`              '
$$$$$$$$$$%%%%%;`.``````````````````':'``````.`````.`'''''`......`''':!%%%%%%%%%%%%|!!%%%%|||%%|!|%%%%%%%%%%%%%%%%%%:`'''';||%%%|:`;||%$$$$$$$$$$$$&&&&&&&$|'...```'''`            '
|%%$$%%$$$$$%%%%%%%;`..`.`````````````':'````.``.```..`''````''''':|!:|%%%%%%%%%%%%|!!|%|||%||!!%%%%%%%%%%%%%%%%%%%:`'''':|%%%%;``;|%%$$$$$$$$$$&&&&&&&&&&&$$;...`````''`          '
@$|||||%%%%%%%%%%%%%%%%|:`....```````.`''``'''`````````.````''':;|%|;:|%%%%%%%%%%||!!|||||||!!|%%%%%%%%%%%%%%%%%%%:`'''';|%%%%:.'!|%$$$$$$$$$$$$$&&&&&&&&&&&&$!`..``````''`        '
||||&@&%|!|||%%%%%%%%%%%%%%|:.....```````'````.........`!%%%%%%%%|||;:|%%%%%%%%%%||!!|%|%|!!||%%%%%%%%%%%%%%%%%%%:`'''';|%%%!'`;||%$$$$$$$&&$$$$$&&&&&&@&&&&&$$!`..``````````.     '
|||||!|!|$@&%|!|||%%%%%%%%%%%%%:. ...`````''``........:|%%%%%%%%%||%;:|%%%%%%%$%%%%!;|||!!||||%%%%%%%%%%%%%%%%%%:`'''';||%|:`:||%%$$$&&&&&$$%%$$&&&&@######&&$$$!`..``..```````.   '
||||||||!|!!!!|%$%|||||%$%%%%%%%%%!`.....````'`......'|%%%%%%%%%%|%$|;%&&&&&&&&$$$$|!|!!%$$$$&&&&&&&&&$$$$$$$$%;`''':;|||;``;||%$$&&&&&&&$$%%$$&&&&&@######&$$$$%:.....``````````. '
||%%||||||!!|!!|||!|%$%|||%%%%%%%%%%%|:.....`.`'`...'|%%%%%%%%%$$$$&|:|&&&&&&&&$$$$|;!|$$$$&&&&&&&&&&&&&&&&@&$;`''':;||;``!||%$&$$$&&&&$%%%%%$&#####@@###@&$$&$$$!`.......`````````:
   .:!|%%|||||||||||||||!|||||%%%%$%%%%%;`.......``:%&&&&&&&&&&&&$$$%;;$&&&&&&&&&&$||$$$&&@@@@@@@@@@@@@@@@@@&!'''':;!:`'!||%$&$$$$$&&&$%%|%%$@######@&&&&&$$$$$$$%;..`...`...`````':
    .....`;|%%%%%|||!|||!|||!!!||%%%%%%%%%%;`.....:%&&&&&&&&&&&&$$$&$|'!$&&&&&&&$$%$$$&&@@@@@@@@@@@@@@@@@@@@!'::':'`.'|||%$$&&$$$$$&&$%%||%$@#########@@&&$$$$&$%$!`..`...```..````:
    ..........'!|%|%|||||!||||||||||%%%%%%%%%:...'|&&&&&&&&&&&&&$$&&&$;'|&&&&&$%%$$$&&@@@@@@@@@@@@@@@@@##@@!'::::'`:|%%%$$$&&&$$$$$$$%%|%&@@##########@@@@&&&$$$$$%;..``....````.``:
    .....```......`;|%|%%||||||||||||||%%%%%%|!:`!&&&&&&&&&&&&&&$$$&&$%::%&$$%%$$&&&@@@@@@@@@@@@@@@@@@@#@&|::::::;|%%$$$$&&&&&$$$$$$%%%%&@@@###########@@@@&&&&&$$$!`..`.....`````.'
    ..................`;|%%%|%%|||!|||||||%%%|||$&&&&&&&&&&&@&&&$$$&&&$%;;%%%$$&&@@@@@@@@@@@@@@@@@##@#@&$;':::::!%%$$$$&&&&&&&$$$%%%%%|$@@@@##@#########@@@@@&&&&$$|:...`.....`````:
    ............``..```...`;|%|||%||!!|||||||||%&&&&&&&&&&@@@@&&$$$&&&&$%;;%$$&@@@@@@@@@@@@@@@@@@#@@&$!`.`:::::!%$$$&&&&&&&&$$$$$$%%%||&@@@@##@@@@########@@@@&&&&$$!`...`.....````:
    ...................```...`:|%||||||||!||||%&&&&&&&&&&&@@@@@&$%&&$$$%%%;:!$&@@@@@@@@@@@@@@#@@&&%;``;|;:::::!$$$&&&&&&&&&&$$$$$%%%%||&@@@@@@@@@@##@#####@@@@@&&&&&$:..```.....```:
    .....................``.`...`;|%|||||||||%&&&&&&&&&&&&@@@@@@$$&$$%%$$$%!::|&@@@@@####@@@&$%;'':|%|!::::::!$$&&&&&@&&&&&&$$$$$$%%|||$@@@@@@@@@@@@@@@####@@@@@&&&&&%'.```..`...``:
    ...........................``..'!%|||||!%$&&&&&&&&&&&&@@@@@&$$$%%$$@@@&$%!::|&&&&&&&&$|;::;||||%%|::::::!$$&&&&@@@&&&&&&$$$$$$%%|||$@@@@&&&&&&&@@@@@@@@@@@@@@&&&$$|'.```.......:
    ...........................```...`;||||%$&&&&&&&&&&&&@@@@@&$%%$$&@@@@&&&&$|!!;;!||;:;!|%%||%$&&$|;:::::!$$&&&@@@@@@@&&&&$$$$$$%%%%|%&@@@&&&&&&&&&&&&&&&&&@@@&&&&$$$!`.``.......:
*/

const int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
const int maxn=3005;
const int Inf=0x3f3f3f3f;
int n,m;
int a[maxn],b[maxn],c[maxn],d[maxn],e[maxn],f[maxn];
vector<int> X,Y;
int cx[maxn][maxn],cy[maxn][maxn];
bool can[maxn][maxn][4];
bool lgl[maxn][maxn];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",a+i,b+i,c+i);
		X.push_back(a[i]);
		X.push_back(b[i]);
		Y.push_back(c[i]);
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",d+i,e+i,f+i);
		X.push_back(d[i]);
		Y.push_back(e[i]);
		Y.push_back(f[i]);
	}
	X.push_back(0);
	X.push_back(Inf);
	Y.push_back(0);
	Y.push_back(Inf);
	sort(X.begin(),X.end());
	X.resize(unique(X.begin(),X.end())-X.begin());
	sort(Y.begin(),Y.end());
	Y.resize(unique(Y.begin(),Y.end())-Y.begin());
	int H=X.size(),W=Y.size();
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(X.begin(),X.end(),a[i])-X.begin();
		b[i]=lower_bound(X.begin(),X.end(),b[i])-X.begin();
		c[i]=lower_bound(Y.begin(),Y.end(),c[i])-Y.begin();
	}
	for(int i=1;i<=m;i++){
		d[i]=lower_bound(X.begin(),X.end(),d[i])-X.begin();
		e[i]=lower_bound(Y.begin(),Y.end(),e[i])-Y.begin();
		f[i]=lower_bound(Y.begin(),Y.end(),f[i])-Y.begin();
	}
	int sx=lower_bound(X.begin(),X.end(),0)-X.begin();
	int sy=lower_bound(Y.begin(),Y.end(),0)-Y.begin();
	for(int i=1;i<=n;i++){
		cx[a[i]][c[i]]++;
		cx[b[i]][c[i]]--;
	}
	for(int i=1;i<=m;i++){
		cy[d[i]][e[i]]++;
		cy[d[i]][f[i]]--;
	}
	for(int i=1;i<H;i++){
		for(int j=0;j<W;j++){
			cx[i][j]+=cx[i-1][j];
		}
	}
	for(int i=0;i<H;i++){
		for(int j=1;j<W;j++){
			cy[i][j]+=cy[i][j-1];
		}
	}
	for(int i=0;i<H-1;i++){
		for(int j=0;j<W-1;j++){
			if(!cy[i][j]){
				can[i][j][0]=1;
			}
			if(!cy[i+1][j]){
				can[i][j][1]=1;
			}
			if(!cx[i][j]){
				can[i][j][2]=1;
			}
			if(!cx[i][j+1]){
				can[i][j][3]=1;
			}
		}
	}
	queue<pair<int,int>> q;
	lgl[sx][sy]=1;
	q.emplace(sx,sy);
	long long ans=0;
	while(q.size()){
		int x=q.front().first,y=q.front().second;
		q.pop();
		ans+=1ll*(X[x+1]-X[x])*(Y[y+1]-Y[y]);
		for(int d=0;d<4;d++){
			if(!can[x][y][d]){
				continue;
			}
			int nx=x+dx[d],ny=y+dy[d];
			if(nx<0||ny<0||nx>=H-1||ny>=W-1){
				puts("INF");
				return 0;
			}
			if(!lgl[nx][ny]){
				lgl[nx][ny]=1;
				q.emplace(nx,ny);
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 118384