stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,m,q,ans=0,x,y;

vector <int> a[10005];

int main()

{

	cin>>n>>m>>q;

	for (int i=1;i<=m;i++)

	{

		cin>>x>>y;

		a[x].push_back(y);

	}

	for (int i=1;i<=n;i++)

	sort(a[i].begin(),a[i].end());

	for (int i=1;i<=q;i++)

	{

		ans=0;

		cin>>x>>y;

		for (int i=x;i<=y;i++)

		{

			ans+=upper_bound(a[i].begin(),a[i].end(),y)-a[i].begin();

		}

		cout<<ans<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2553739584227226x):
#include <iostream>

using namespace std;

int info[505][505], raw[200005][2], quest[200005][2], ans[200005];

int main()

{

    int n, m, q;

    cin >> n >> m >> q;

    for ( int i = 0; i <= m-1; i++ )

    {

        cin >> raw[i][0] >> raw[i][1];

        info[raw[i][0]][raw[i][1]]++;

    }

    for ( int i = 1; i <= n; i++ )

    {

        for ( int j = 1; j <= n; j++ )

        {

            info[i][j] = info[i][j] + info[i][j-1];

        }

    }

    for ( int i = 0; i <= q-1; i++ )

    {

        cin >> quest[i][0] >> quest[i][1];

        for ( int j = quest[i][0]; j <= quest[i][1]; j++ )

        {

            ans[i] = ans[i] + info[j][quest[i][1]] - info[j][quest[i][0]-1];

        }

        cout << ans[i] << endl;

    }

}
// Slower C++ solution:


#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int N = 550;



int a[N][N], b[N][N], n, m, Q;



int main() {

	scanf("%d%d%d", &n, &m, &Q);

	for (int i = 1; i <= m; ++ i) {

		int x, y; scanf("%d%d", &x, &y); ++ a[x][y];

	}

	for (int i = n; i >= 1; -- i) {

		for (int j = 1; j <= n; ++ j) {

			b[i][j] = a[i][j] + b[i + 1][j] + b[i][j - 1] - b[i + 1][j - 1];

		}

	}

	

	while (Q --) {

		int x, y; scanf("%d%d", &x, &y);

		cout << b[x][y] << endl;

	}

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.16635180588448x):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

int n,m,q,a,b;

int dp[510][510];

int main() {

    scanf("%d%d%d",&n,&m,&q);

    for(int i=1;i<=m;i++){

        scanf("%d%d",&a,&b);

        dp[a][b]++;

    }

    for(int j=1;j<n;j++) {

        for(int i=1;i+j<=n;i++) {

            int k=i+j;

            dp[i][k]+=dp[i+1][k]+dp[i][k-1];

            if(j!=1)dp[i][k]-=dp[i+1][k-1];

        }

    }

    while(q--){

        scanf("%d%d",&a,&b);

        printf("%d\n",dp[a][b]);

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.108580724250497x):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define maxn 200008

int n,m,q;

int arr[maxn];

int sum[maxn];

int cha[maxn];

vector<int> v1[maxn];

int main(){

	scanf("%d%d%d",&n,&m,&q);

	for(int i=1;i<=m;i++){

		int a,b;

		scanf("%d%d",&a,&b);

		v1[a].push_back(b);

	}

	for(int i=1;i<=n;i++){

		sort(v1[i].begin(),v1[i].end());

	}

	int ans=0;

	for(int i=1;i<=q;i++){

		int a,b;

		ans=0;

		scanf("%d%d",&a,&b);

		for(int j=a;j<=b;j++){

			ans+=upper_bound(v1[j].begin(),v1[j].end(),b)-v1[j].begin();

		}

		cout<<ans<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 33.35668426616671x):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<vector>

using namespace std;

int n,m,q,x,y,ans,xx;

vector <int> v[505];

int main(){

        scanf("%d%d%d",&n,&m,&q);

        for(int i=1;i<=m;i++){

                scanf("%d%d",&x,&y);

                v[y].push_back(x);

        }

        for(int i=1;i<=n;i++) sort(v[i].begin(),v[i].end());

        for(int i=1;i<=q;i++){

                scanf("%d%d",&x,&y);

                for(int i=x;i<=y;i++){

                        xx=lower_bound(v[i].begin(),v[i].end(),x)-v[i].begin();

                                ans+=v[i].size()-xx;

                    }

                printf("%d\n",ans);

                ans=0;

        }

}

// Faster C++ solution for the same problem (measured speedup: 5.195098355715311x):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,m,q,ans=0,x,y;

vector <int> a[10005];

int main()

{

	cin>>n>>m>>q;

	for (int i=1;i<=m;i++)

	{

		cin>>x>>y;

		a[x].push_back(y);

	}

	for (int i=1;i<=n;i++)

	sort(a[i].begin(),a[i].end());

	for (int i=1;i<=q;i++)

	{

		ans=0;

		cin>>x>>y;

		for (int i=x;i<=y;i++)

		{

			ans+=upper_bound(a[i].begin(),a[i].end(),y)-a[i].begin();

		}

		cout<<ans<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.492615120699897x):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

#include <vector>

using namespace std;

typedef long long LL;

inline LL in()

{

    LL x = 0, flag = 1; char ch = getchar();

    while (ch < '0' || ch > '9') {if (ch == '-') flag = -1; ch = getchar();}

    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();

    return x * flag;

}

vector <int> vec[600];

int n, m, q;

int main()

{

    n = in(), m = in(), q = in();

    for (int i = 1; i <= m; i ++)

    {

        int l = in(), r = in();

        vec[l].push_back(r);

    }

    for (int i = 1; i <= 500; i ++) sort(vec[i].begin(), vec[i].end());

    for (int i = 1; i <= q; i ++)

    {

        int l = in(), r = in(), ans = 0;

        for (int j = l; j <= r; j ++)

        {

            int pos = upper_bound(vec[j].begin(), vec[j].end(), r) - vec[j].begin();

            ans += pos;

            // cout << pos << endl;

        }

        cout << ans << endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.235400940631348x):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

int n,m,q;

int dp[502][502];

int main() {

    int a,b;

    scanf("%d%d%d",&n,&m,&q);

    for(int i = 0;i < m;i ++) {

        scanf("%d%d",&a,&b);

        dp[a][b] ++;

    }

    for(int j = 1;j < n;j ++) {

        for(int i = 1;i + j <= n;i ++) {

            int k = i + j;

            dp[i][k] += dp[i + 1][k] + dp[i][k - 1];

            if(j > 1)dp[i][k] -= dp[i + 1][k - 1];

        }

    }

    for(int i = 0;i < q;i ++) {

        scanf("%d%d",&a,&b);

        printf("%d\n",dp[a][b]);

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.106746065826458x):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}
// Slower C++ solution:
#include <iostream>

using namespace std;

int info[505][505], raw[200005][2], quest[200005][2], ans[200005];

int main()

{

    int n, m, q;

    cin >> n >> m >> q;

    for ( int i = 0; i <= m-1; i++ )

    {

        cin >> raw[i][0] >> raw[i][1];

        info[raw[i][0]][raw[i][1]]++;

    }

    for ( int i = 1; i <= n; i++ )

    {

        for ( int j = 1; j <= n; j++ )

        {

            info[i][j] = info[i][j] + info[i][j-1];

        }

    }

    for ( int i = 0; i <= q-1; i++ )

    {

        cin >> quest[i][0] >> quest[i][1];

        for ( int j = quest[i][0]; j <= quest[i][1]; j++ )

        {

            ans[i] = ans[i] + info[j][quest[i][1]] - info[j][quest[i][0]-1];

        }

        cout << ans[i] << endl;

    }

}

// Faster C++ solution for the same problem (measured speedup: 5.171857419168827x):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define maxn 200008

int n,m,q;

int arr[maxn];

int sum[maxn];

int cha[maxn];

vector<int> v1[maxn];

int main(){

	scanf("%d%d%d",&n,&m,&q);

	for(int i=1;i<=m;i++){

		int a,b;

		scanf("%d%d",&a,&b);

		v1[a].push_back(b);

	}

	for(int i=1;i<=n;i++){

		sort(v1[i].begin(),v1[i].end());

	}

	int ans=0;

	for(int i=1;i<=q;i++){

		int a,b;

		ans=0;

		scanf("%d%d",&a,&b);

		for(int j=a;j<=b;j++){

			ans+=upper_bound(v1[j].begin(),v1[j].end(),b)-v1[j].begin();

		}

		cout<<ans<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.444663491479692x):
#include<bits/stdc++.h>

using namespace std;

const int N=505;

int dp[N][N],n,m,q;

int main()

{

	cin>>n>>m>>q;

	for(int i=0;i<m;i++)

	{

		int x,y;

		cin>>x>>y;

		dp[x][y]++;

	}

	for(int i=1;i<=n;i++)

		for(int j=1;j<=n;j++)

			dp[i][j]+=dp[i][j-1];

	for(int i=1;i<=n;i++)

		for(int j=1;j<=n;j++)

			dp[i][j]+=dp[i-1][j];

	for(int i=1;i<=q;i++)

	{

		int x,y;

		cin>>x>>y;

		x--;

		cout<<dp[y][y]+dp[x][x]-dp[x][y]-dp[y][x]<<endl;

	}

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,m,q,ans=0,x,y;

vector <int> a[10005];

int main()

{

	cin>>n>>m>>q;

	for (int i=1;i<=m;i++)

	{

		cin>>x>>y;

		a[x].push_back(y);

	}

	for (int i=1;i<=n;i++)

	sort(a[i].begin(),a[i].end());

	for (int i=1;i<=q;i++)

	{

		ans=0;

		cin>>x>>y;

		for (int i=x;i<=y;i++)

		{

			ans+=upper_bound(a[i].begin(),a[i].end(),y)-a[i].begin();

		}

		cout<<ans<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.254402844680945x):
#include<bits/stdc++.h>

using namespace std;

const int N=505;

int dp[N][N],n,m,q;

int main()

{

	cin>>n>>m>>q;

	for(int i=0;i<m;i++)

	{

		int x,y;

		cin>>x>>y;

		dp[x][y]++;

	}

	for(int i=1;i<=n;i++)

		for(int j=1;j<=n;j++)

			dp[i][j]+=dp[i][j-1];

	for(int i=1;i<=n;i++)

		for(int j=1;j<=n;j++)

			dp[i][j]+=dp[i-1][j];

	for(int i=1;i<=q;i++)

	{

		int x,y;

		cin>>x>>y;

		x--;

		cout<<dp[y][y]+dp[x][x]-dp[x][y]-dp[y][x]<<endl;

	}

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define maxn 200008

int n,m,q;

int arr[maxn];

int sum[maxn];

int cha[maxn];

vector<int> v1[maxn];

int main(){

	scanf("%d%d%d",&n,&m,&q);

	for(int i=1;i<=m;i++){

		int a,b;

		scanf("%d%d",&a,&b);

		v1[a].push_back(b);

	}

	for(int i=1;i<=n;i++){

		sort(v1[i].begin(),v1[i].end());

	}

	int ans=0;

	for(int i=1;i<=q;i++){

		int a,b;

		ans=0;

		scanf("%d%d",&a,&b);

		for(int j=a;j<=b;j++){

			ans+=upper_bound(v1[j].begin(),v1[j].end(),b)-v1[j].begin();

		}

		cout<<ans<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.169695736847922x):
//#pragma GCC optimize("Ofast,no-stack-protector")

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

//#pragma GCC target("avx,tune=native")

#include<bits/stdc++.h>

//#include<ext/pb_ds/assoc_container.hpp>

using namespace std;

//using namespace __gnu_pbds;

const int inf=0x3f3f3f3f;

const double eps=1e-6;

const int mod=1000000007;

typedef long long ll;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}

int bit[505];

void add(int x){

	while(x<=500){

		bit[x]++;

		x+=(x&-x);

	}

}

int sum(int x){

	int ret=0;

	while(x){

		ret+=bit[x];

		x&=x-1;

	}

	return ret;

}

int calc(int l,int r){

	return sum(r)-sum(l-1);

}

vector<pair<int,int> >qry[505];//l-><r,id>

int n,m,q;

vector<int>train[505];//l->r

int ans[200005];

int main(){

	ios::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	cin>>n>>m>>q;

	for(int i=1;i<=m;i++){

		int l,r;

		cin>>l>>r;

		train[l].push_back(r);

	}

	for(int i=1;i<=q;i++){

		int l,r;

		cin>>l>>r;

		qry[l].push_back(make_pair(r,i));

	}

	for(int i=n;i>=1;i--){

		for(auto x:train[i])add(x);

		for(auto p:qry[i]){

			int l=i,r=p.first,id=p.second;

			ans[id]=calc(l,r);

		}

	}

	for(int i=1;i<=q;i++)cout<<ans[i]<<endl;

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,m,q,ans=0,x,y;

vector <int> a[10005];

int main()

{

	cin>>n>>m>>q;

	for (int i=1;i<=m;i++)

	{

		cin>>x>>y;

		a[x].push_back(y);

	}

	for (int i=1;i<=n;i++)

	sort(a[i].begin(),a[i].end());

	for (int i=1;i<=q;i++)

	{

		ans=0;

		cin>>x>>y;

		for (int i=x;i<=y;i++)

		{

			ans+=upper_bound(a[i].begin(),a[i].end(),y)-a[i].begin();

		}

		cout<<ans<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2008825431071493x):
//#pragma GCC optimize("Ofast,no-stack-protector")

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

//#pragma GCC target("avx,tune=native")

#include<bits/stdc++.h>

//#include<ext/pb_ds/assoc_container.hpp>

using namespace std;

//using namespace __gnu_pbds;

const int inf=0x3f3f3f3f;

const double eps=1e-6;

const int mod=1000000007;

typedef long long ll;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}

int bit[505];

void add(int x){

	while(x<=500){

		bit[x]++;

		x+=(x&-x);

	}

}

int sum(int x){

	int ret=0;

	while(x){

		ret+=bit[x];

		x&=x-1;

	}

	return ret;

}

int calc(int l,int r){

	return sum(r)-sum(l-1);

}

vector<pair<int,int> >qry[505];//l-><r,id>

int n,m,q;

vector<int>train[505];//l->r

int ans[200005];

int main(){

	ios::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	cin>>n>>m>>q;

	for(int i=1;i<=m;i++){

		int l,r;

		cin>>l>>r;

		train[l].push_back(r);

	}

	for(int i=1;i<=q;i++){

		int l,r;

		cin>>l>>r;

		qry[l].push_back(make_pair(r,i));

	}

	for(int i=n;i>=1;i--){

		for(auto x:train[i])add(x);

		for(auto p:qry[i]){

			int l=i,r=p.first,id=p.second;

			ans[id]=calc(l,r);

		}

	}

	for(int i=1;i<=q;i++)cout<<ans[i]<<endl;

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N=2e5+10;

struct E{

	int x,y,nxt,flag;

}mm[N<<2];

int h[N],len,p[N],n,ans[N],cur[N];

bool v[N];

inline int rd(){

	int x=0;int f=1;char s=getchar();

	while(!isdigit(s)) f=(s=='-'?-1:f),s=getchar();

	while(isdigit(s)) x=(x<<1)+(x<<3)+s-'0',s=getchar();

	return x*f;

}



inline void add(int x,int y){

	++len;

	mm[len].x=x;mm[len].y=y;mm[len].nxt=h[x];h[x]=len;

	++len;

	mm[len].x=y;mm[len].y=x;mm[len].nxt=h[y];h[y]=len;

	p[x]++;p[y]++;

	return ;

}

void dfs(int u,int f){

	for(int& k=h[u];k;k=mm[k].nxt){

		int y=mm[k].y;

		if(mm[k].flag||f==y) continue; 

		mm[k].flag=mm[k%2==0?k-1:k+1].flag=1;

		if(v[u] && u<=n && y>n) ans[u]=ans[y]=1; 

		if(v[u] && u>n && y<=n) ans[u]=ans[y]=-1;

		dfs(y,u);

	}

}

int main(){

//	freopen("t.in","r",stdin);

	n=rd();memset(h,0,sizeof h);

	for(int i=1;i<=n;i++){

		int u=rd();u=max(0,u);

		add(u,i);

	}

	for(int i=1;i<=n;i++){

		int u=rd();u=u==-1?0:(u+n);

		add(u,i+n);

	}

	for(int i=1;i<=2*n;i++){

		if(p[i]%2) v[i]=1;

		else v[i]=0;

	}

	bool flag=true;

	for(int i=1;i<=n;i++)

		if(v[i]!=v[i+n]) flag=0;

	if(flag) printf("POSSIBLE\n");

	else {

		printf("IMPOSSIBLE\n");

		return 0;

	}

	for(int i=1;i<=n;i++)

		if(v[i]) add(i,i+n);//,printf("#%d %d\n",i,i+n);

	dfs(1,0);

	for(int i=1;i<=n;i++) printf("%d ",ans[i]);printf("\n");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8077950915114172x):
#include<bits/stdc++.h>

using namespace std;

const int N=1e5+10;

int n,fa,rt1,rt2,cnt,cnt1,cnt2;

int val1[N],val2[N],to1[N],to2[N],tag[N],to[N<<2],nxt1[N],nxt2[N],nxt[N<<2],head[N],head1[N],head2[N];

inline void add1(int u,int v){

	to1[++cnt1]=v,nxt1[cnt1]=head1[u],head1[u]=cnt1;

}

inline void add2(int u,int v){

	to2[++cnt2]=v,nxt2[cnt2]=head2[u],head2[u]=cnt2;

}

inline void add(int u,int v){

	to[++cnt]=v,nxt[cnt]=head[u],head[u]=cnt;

}

int dfs1(int u){

	int lst=0;

	for(int i=head1[u];i;i=nxt1[i]){

		int v=to1[i],rt=dfs1(v); 

		if(!lst) lst=rt;

		else add(lst,rt),add(rt,lst),lst=0;

	}

	return (lst==0)?u:lst;

}

int dfs2(int u){

	int lst=0;

	for(int i=head2[u];i;i=nxt2[i]){

		int v=to2[i],rt=dfs2(v);

		if(!lst) lst=rt;

		else add(lst,rt),add(rt,lst),lst=0;

	}

	return (lst==0)?u:lst; 

}

void dfs(int u,int vv){

	tag[u]=vv;

	for(int i=head[u];i;i=nxt[i]) if(!tag[to[i]]) dfs(to[i],vv*-1); 

}

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++) val1[i]=val2[i]=1;

	for(int i=1;i<=n;i++){

		scanf("%d",&fa);

		if(fa==-1) rt1=i;

		else add1(fa,i),val1[fa]^=1;

	}

	for(int i=1;i<=n;i++){

		scanf("%d",&fa);

		if(fa==-1) rt2=i;

		else add2(fa,i),val2[fa]^=1;

	}

	for(int i=1;i<=n;i++) if(val1[i]!=val2[i]) { puts("IMPOSSIBLE"); return 0; }

	puts("POSSIBLE");

	

	dfs1(rt1),dfs2(rt2);

	for(int i=1;i<=n;i++) if(tag[i]==0 && head[i]>0) dfs(i,1);

	for(int i=1;i<=n;i++) printf("%d ",(tag[i]!=0)?tag[i]:val1[i]);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N=2e5+10;

struct E{

	int x,y,nxt,flag;

}mm[N<<2];

int h[N],len,p[N],n,ans[N],cur[N];

bool v[N];

inline int rd(){

	int x=0;int f=1;char s=getchar();

	while(!isdigit(s)) f=(s=='-'?-1:f),s=getchar();

	while(isdigit(s)) x=(x<<1)+(x<<3)+s-'0',s=getchar();

	return x*f;

}



inline void add(int x,int y){

	++len;

	mm[len].x=x;mm[len].y=y;mm[len].nxt=h[x];h[x]=len;

	++len;

	mm[len].x=y;mm[len].y=x;mm[len].nxt=h[y];h[y]=len;

	p[x]++;p[y]++;

	return ;

}

void dfs(int u,int f){

	for(int& k=h[u];k;k=mm[k].nxt){

		int y=mm[k].y;

		if(mm[k].flag||f==y) continue; 

		mm[k].flag=mm[k%2==0?k-1:k+1].flag=1;

		if(v[u] && u<=n && y>n) ans[u]=ans[y]=1; 

		if(v[u] && u>n && y<=n) ans[u]=ans[y]=-1;

		dfs(y,u);

	}

}

int main(){

//	freopen("t.in","r",stdin);

	n=rd();memset(h,0,sizeof h);

	for(int i=1;i<=n;i++){

		int u=rd();u=max(0,u);

		add(u,i);

	}

	for(int i=1;i<=n;i++){

		int u=rd();u=u==-1?0:(u+n);

		add(u,i+n);

	}

	for(int i=1;i<=2*n;i++){

		if(p[i]%2) v[i]=1;

		else v[i]=0;

	}

	bool flag=true;

	for(int i=1;i<=n;i++)

		if(v[i]!=v[i+n]) flag=0;

	if(flag) printf("POSSIBLE\n");

	else {

		printf("IMPOSSIBLE\n");

		return 0;

	}

	for(int i=1;i<=n;i++)

		if(v[i]) add(i,i+n);//,printf("#%d %d\n",i,i+n);

	dfs(1,0);

	for(int i=1;i<=n;i++) printf("%d ",ans[i]);printf("\n");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8157931139724375x):
#include <iostream>

#include <cstdio>

#define il inline

#define ri register

#define Size 600050

using namespace std;

namespace{

	template<class free>

		il void read(free&x){

		x^=x;ri char c;while(c=getchar(),c==' '||c=='\n'||c=='\r');

		ri bool check(false);if(c=='-')check=true,c=getchar();

		while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();

		if(check)x=~x+1;

	}

	template<class f1,class...f2>

		il void read(f1&x,f2&...y){

		read(x),read(y...);

	}

}

struct point{

	int next,to;

}ar[Size];

bool is[Size];

int head[Size],art(1);

int son[2][Size],rt[2],a[Size];

il void link(int,int),dfs(int);

int main(){

	int n;read(n);

	for(int i(1),j;i<=n;++i)

		read(j),~j?link(j,i),

			++son[0][j]:rt[0]=i;

	for(int i(1),j;i<=n;++i)

		read(j),~j?link(j+n,i+n),

			++son[1][j]:rt[1]=i+n;

	link(rt[0],rt[1]);

	for(int i(1);i<=n;++i){

		if(son[0][i]+son[1][i]&1)

			return puts("IMPOSSIBLE"),0;

		if(~son[0][i]&1)link(i,i+n),a[i]=art;

	}dfs(1),puts("POSSIBLE");

	for(int i(1);i<=n;++i)

		if(son[0][i]&1)puts("0");

		else puts(is[a[i]]?"-1":"1");

	return 0;

}

il void dfs(int x){

	for(int i(head[x]);i;i=head[x])

		if(head[x]=ar[head[x]].next,!is[i])

			is[i^1]=1,dfs(ar[i].to);

}

il void link(int u,int v){

	ar[++art]={head[u],v},head[u]=art;

	ar[++art]={head[v],u},head[v]=art;

}