#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 1010;

struct Portal
{
	int x, y, p, q;
	Portal(int _x, int _y, int _p, int _q): x(_x), y(_y), p(_p), q(_q) {}
};
vector<Portal> ans;
int n, a[N], b[N], c[N], d[N], ra[N], rb[N], rc[N], rd[N];

int main()
{
	int i;

	scanf("%d", &n);

	for (i = 1; i <= n; ++i)
	{
		scanf("%d", b + i);
		rb[b[i]] = i;
	}
	for (i = 1; i <= n; ++i)
	{
		scanf("%d", a + i);
		ra[a[i]] = i;
	}
	for (i = 1; i <= n; ++i) c[i] = d[i] = rc[i] = rd[i] = i;

	for (i = 1; i < n; ++i)
	{
		if (c[i] == ra[i] && d[i] == rb[i]) continue;
		ans.push_back(Portal(i, rc[ra[i]], rd[rb[i]], i));
		int t1 = c[i];
		int t2 = d[i];
		swap(c[i], c[rc[ra[i]]]);
		swap(d[i], d[rd[rb[i]]]);
		swap(rc[ra[i]], rc[t1]);
		swap(rd[rb[i]], rd[t2]);
	}

	printf("%d\n", ans.size());
	for (auto k : ans) printf("%d %d %d %d\n", k.x, k.y, k.p, k.q);
	// sorry
	return 0;
}


#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define N 1005
using namespace std;
int r[N],r1[N],c[N],c1[N],n,ans[N][4];
int main()
{
	cin>>n;
	fo(i,1,n) scanf("%d",&r[i]),r1[r[i]]=i;
	fo(i,1,n) scanf("%d",&c[i]),c1[c[i]]=i;
	int cnt=0;
	fo(i,1,n)
	{
		int p=r1[i],q=c1[i];
		if(p==i&&q==i) continue;
		cnt++;
		ans[cnt][0]=p,ans[cnt][1]=i,ans[cnt][2]=i,ans[cnt][3]=q;
		swap(r1[r[i]],r1[r[p]]);
		swap(c1[c[i]],c1[c[q]]);
		swap(r[i],r[p]);
		swap(c[i],c[q]);
	}
	printf("%d\n",cnt);
	fo(i,1,cnt) printf("%d %d %d %d\n",ans[i][0],ans[i][1],ans[i][2],ans[i][3]);
}


#include <bits/stdc++.h>

inline int read()
{
	int res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	return bo ? ~res + 1 : res;
}

const int N = 1005;

int n, m, ir[N], ic[N], a[N], ia[N], b[N], ib[N],
ans1x[N], ans1y[N], ans2x[N], ans2y[N];

int main()
{
	n = read();
	for (int i = 1; i <= n; i++) ir[read()] = a[i] = ia[i] = i;
	for (int i = 1; i <= n; i++) ic[read()] = b[i] = ib[i] = i;
	for (int i = 1; i <= n; i++)
	{
		if (ir[i] == a[i] && ic[i] == b[i]) continue;
		int x = ia[ir[i]], y = ib[ic[i]];
		ans1x[++m] = x; ans1y[m] = ans2x[m] = i;
		ans2y[m] = y;
		a[x] = a[i]; b[y] = b[i];
		ia[a[i]] = x; ib[b[i]] = y;
	}
	std::cout << m << std::endl;
	for (int i = 1; i <= m; i++)
		printf("%d %d %d %d\n", ans1x[i], ans1y[i], ans2x[i], ans2y[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define M 1010
struct Node{
	int x, y, p, q;
};
int a[M], b[M], c[M], d[M];
int ra[M], rb[M], rc[M], rd[M];
vector<Node> ans;
int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++ i) {
		scanf("%d", &b[i]);
		rb[b[i]] = i;
	}
	for(int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
		ra[a[i]] = i;
		c[i] = d[i] = i;
		rc[i] = rd[i] = i;
	}
	for(int i = 1; i <= n; ++ i) {
		if(c[i] == ra[i] && d[i] == rb[i]) continue;
		ans.push_back((Node){i, rc[ra[i]], rd[rb[i]], i});
		int t1 = c[i], t2 = d[i];
		swap(c[i], c[rc[ra[i]]]);
		swap(d[i], d[rd[rb[i]]]);
		swap(rc[ra[i]], rc[t1]);
		swap(rd[rb[i]], rd[t2]);
	}
	printf("%d\n", ans.size());
	for(int i = 0; i < ans.size(); ++ i) {
		printf("%d %d %d %d\n", ans[i].x, ans[i].y, ans[i].p, ans[i].q);
	}
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 1010;

struct Portal
{
	int x, y, p, q;
	Portal(int _x, int _y, int _p, int _q): x(_x), y(_y), p(_p), q(_q) {}
};
vector<Portal> ans;
int n, a[N], b[N], c[N], d[N], ra[N], rb[N], rc[N], rd[N];

int main()
{
	int i;

	scanf("%d", &n);

	for (i = 1; i <= n; ++i)
	{
		scanf("%d", b + i);
		rb[b[i]] = i;
	}
	for (i = 1; i <= n; ++i)
	{
		scanf("%d", a + i);
		ra[a[i]] = i;
	}
	for (i = 1; i <= n; ++i) c[i] = d[i] = rc[i] = rd[i] = i;

	for (i = 1; i < n; ++i)
	{
		if (c[i] == ra[i] && d[i] == rb[i]) continue;
		ans.push_back(Portal(i, rc[ra[i]], rd[rb[i]], i));
		int t1 = c[i];
		int t2 = d[i];
		swap(c[i], c[rc[ra[i]]]);
		swap(d[i], d[rd[rb[i]]]);
		swap(rc[ra[i]], rc[t1]);
		swap(rd[rb[i]], rd[t2]);
	}

	printf("%d\n", ans.size());
	for (auto k : ans) printf("%d %d %d %d\n", k.x, k.y, k.p, k.q);

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 1010;

struct Portal
{
	int x, y, p, q;
	Portal(int _x, int _y, int _p, int _q): x(_x), y(_y), p(_p), q(_q) {}
};
vector<Portal> ans;
int n, a[N], b[N], c[N], d[N], ra[N], rb[N], rc[N], rd[N];

int main()
{
	int i;

	scanf("%d", &n);

	for (i = 1; i <= n; ++i)
	{
		scanf("%d", a + i);
		ra[a[i]] = i;
	}
	for (i = 1; i <= n; ++i)
	{
		scanf("%d", b + i);
		rb[b[i]] = i;
	}
	for (i = 1; i <= n; ++i) c[i] = d[i] = rc[i] = rd[i] = i;

	for (i = 1; i < n; ++i)
	{
		if (c[i] == ra[i] && d[i] == rb[i]) continue;
		ans.push_back(Portal(i, rc[ra[i]], rd[rb[i]], i));
		int t1 = c[i];
		int t2 = d[i];
		swap(c[i], c[rc[ra[i]]]);
		swap(d[i], d[rd[rb[i]]]);
		swap(rc[ra[i]], rc[t1]);
		swap(rd[rb[i]], rd[t2]);
	}

	printf("%d\n", ans.size());
	for (auto k : ans) printf("%d %d %d %d\n", k.x, k.y, k.p, k.q);

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#define N 1010
using namespace std;
int x[N],y[N],ix[N],iy[N];
struct node{
	int x1,y1,x2,y2;
}ans[N];
int tot;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]),ix[x[i]]=i;
	for(int i=1;i<=n;i++) scanf("%d",&y[i]),iy[y[i]]=i;
	for(int i=1;i<n;i++)
	if(x[i]!=i || y[i]!=i)
	{
		if(ix[i]==n && iy[i]==n)
		{
			ans[++tot]=(node){i,n,n,i};
			x[n]=x[i];
			y[n]=y[i];
			ix[x[n]]=n,iy[y[n]]=n;
		}
		else if(iy[i]==n)
		{
			ans[++tot]=(node){ix[i],i,n,i};
			y[n]=y[i];iy[y[n]]=n;
			x[ix[i]]=x[i];ix[x[ix[i]]]=ix[i];
		}
		else if(ix[i]==n)
		{
			ans[++tot]=(node){i,iy[i],n,i};
			x[n]=x[i];ix[x[n]]=n;
			y[iy[i]]=y[i];iy[y[iy[i]]]=iy[i];
		}
		else
		{
			ans[++tot]=(node){ix[i],i,i,n};
			ans[++tot]=(node){i,iy[i],i,n};
			int x0=ix[i],y0=iy[i];
			x[x0]=x[n],x[n]=x[i];
			y[y0]=y[n],y[n]=y[i];
			ix[x[x0]]=x0,iy[y[y0]]=y0;
			ix[x[n]]=n,iy[y[n]]=n;
		}
	}
	printf("%d\n",tot);
	for(int i=1;i<=tot;i++) printf("%d %d %d %d\n",ans[i].x1,ans[i].y1,ans[i].x2,ans[i].y2);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#define N 1010
using namespace std;
int x[N],y[N],ix[N],iy[N];
struct node{
	int x1,y1,x2,y2;
}ans[N];
int tot;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]),ix[x[i]]=i;
	for(int i=1;i<=n;i++) scanf("%d",&y[i]),iy[y[i]]=i;
	for(int i=1;i<n;i++)
	if(x[i]!=i || y[i]!=i)
	{
		if(ix[i]==n && iy[i]==n)
		{
			ans[++tot]=(node){i,n,n,i};
			x[n]=x[i];
			y[n]=y[i];
			ix[x[n]]=n,iy[y[n]]=n;
		}
		else if(iy[i]==n)
		{
			ans[++tot]=(node){ix[i],i,i,n};
			y[n]=y[i];iy[y[n]]=n;
			x[ix[i]]=x[i];ix[x[ix[i]]]=ix[i];
		}
		else if(ix[i]==n)
		{
			ans[++tot]=(node){i,iy[i],n,i};
			x[n]=x[i];ix[x[n]]=n;
			y[iy[i]]=y[i];iy[y[iy[i]]]=iy[i];
		}
		else
		{
			ans[++tot]=(node){ix[i],i,i,n};
			ans[++tot]=(node){i,iy[i],n,i};
			int x0=ix[i],y0=iy[i];
			x[x0]=x[n],x[n]=x[i];
			y[y0]=y[n],y[n]=y[i];
			ix[x[x0]]=x0,iy[y[y0]]=y0;
			ix[x[n]]=n,iy[y[n]]=n;
		}
	}
	printf("%d\n",tot);
	for(int i=1;i<=tot;i++) printf("%d %d %d %d\n",ans[i].x1,ans[i].y1,ans[i].x2,ans[i].y2);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#define N 2010
using namespace std;
int x[N],y[N],ix[N],iy[N];
struct node{
	int x1,y1,x2,y2;
}ans[N];
int tot;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]),ix[x[i]]=i;
	for(int i=1;i<=n;i++) scanf("%d",&y[i]),iy[y[i]]=i;
	for(int i=1;i<n;i++)
	if(x[i]!=i || y[i]!=i)
	{
		if(ix[i]==n && iy[i]==n)
		{
			ans[++tot]=(node){i,n,n,i};
			x[n]=x[i];
			y[n]=y[i];
			ix[x[n]]=n,iy[y[n]]=n;
		}
		else if(iy[i]==n)
		{
			ans[++tot]=(node){ix[i],i,i,n};
			y[n]=y[i];iy[y[n]]=n;
			x[ix[i]]=x[i];ix[x[ix[i]]]=ix[i];
		}
		else if(ix[i]==n)
		{
			ans[++tot]=(node){i,iy[i],n,i};
			x[n]=x[i];ix[x[n]]=n;
			y[iy[i]]=y[i];iy[y[iy[i]]]=iy[i];
		}
		else
		{
			ans[++tot]=(node){ix[i],i,i,n};
			ans[++tot]=(node){i,iy[i],n,i};
			int x0=ix[i],y0=iy[i];
			x[x0]=x[n],x[n]=x[i];
			y[y0]=y[n],y[n]=y[i];
			ix[x[x0]]=x0,iy[y[y0]]=y0;
			ix[x[n]]=n,iy[y[n]]=n;
		}
	}
	printf("%d\n",tot);
	for(int i=1;i<=tot;i++) printf("%d %d %d %d\n",ans[i].x1,ans[i].y1,ans[i].x2,ans[i].y2);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
int n;
int pos[1005], num[1005];
int row[1005], col[1005];
void solve (int t[1005]) {
  FOR(i, 1, n - 1) {
    if (num[i] != i) {
      int p = i, q = pos[i];
      t[p] = q;
      swap(num[p], num[q]);
      swap(pos[num[p]], pos[num[q]]);
    } else {
      t[i] = i;
    }
  }
}
int main () {
  scanf("%d", &n);
  FOR(i, 1, n) {
    scanf("%d", &num[i]);
    pos[num[i]] = i;
  }
  solve(row);
  FOR(i, 1, n) {
    scanf("%d", &num[i]);
    pos[num[i]] = i;
  }
  solve(col);
  int cnt = 0;
  FOR(i, 1, n - 1) cnt += !(row[i] == i && i == col[i]);
  printf("%d\n", cnt);
  FOR(i, 1, n - 1) {
    if (row[i] == i && i == col[i]) continue;
    printf("%d %d %d %d\n", row[i], i, i, col[i]);
  }
  return 0;
}


//2019.6.10 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 1e-10
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
//inline void add(res &x,const res &y,const res &kcz){
//    x+=y,x>=kcz?x-=kcz:(x<0?x+=kcz:1);
//}
//inline int Add(const res &x,const res &y,const res &kcz){
//    return x+y>=kcz?x+y-kcz:(x+y<0?x+y+kcz:x+y);
//}
//inline int mul(const res &x,const res &y,const res &kcz){
//    return int(1LL*x*y%kcz);
//}
//inline int qpow(res x,res y,const res &kcz){
//    res ret=1;
//    while(y){
//        if(y&1)ret=mul(ret,x,kcz);
//        y>>=1,x=mul(x,x,kcz);
//    }
//    return ret;
//}
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void swap(res &x,res &y) {
//    x^=y^=x^=y;
//}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=1e3+10;
namespace MAIN {
    typedef pair<Pair,Pair> Pai;
    int vecx;
    Pai vec[N];
    int n,pa[N],pb[N],ida[N],idb[N],a[N],b[N];
    inline void MAIN(){
        n=read();
        for(res i=1;i<=n;i++)pb[read()]=b[i]=idb[i]=i;
        for(res i=1;i<=n;i++)pa[read()]=a[i]=ida[i]=i;
        for(res i=1;i<n;i++){
            if(a[i]==pa[i]&&b[i]==pb[i])continue;
            res A=a[i],B=b[i],&C=ida[pa[i]],&D=idb[pb[i]];
            vec[++vecx]=Pai(mp(i,C),mp(D,i)),swap(a[i],a[C]),swap(b[i],b[D]),swap(C,ida[A]),swap(D,idb[B]);
        }
        printf("%d\n",vecx);
        for(res i=1;i<=vecx;i++)printf("%d %d %d %d\n",vec[i].fi.fi,vec[i].fi.se,vec[i].se.fi,vec[i].se.se);
    }
}
int main() {
//    srand((unsigned)time(NULL));
    // freopen("zao.in","r",stdin);
    // freopen("std.out","w",stdout);
    MAIN::MAIN();
    return 0;
}


//2019.6.10 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 1e-10
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
//inline void add(res &x,const res &y,const res &kcz){
//    x+=y,x>=kcz?x-=kcz:(x<0?x+=kcz:1);
//}
//inline int Add(const res &x,const res &y,const res &kcz){
//    return x+y>=kcz?x+y-kcz:(x+y<0?x+y+kcz:x+y);
//}
//inline int mul(const res &x,const res &y,const res &kcz){
//    return int(1LL*x*y%kcz);
//}
//inline int qpow(res x,res y,const res &kcz){
//    res ret=1;
//    while(y){
//        if(y&1)ret=mul(ret,x,kcz);
//        y>>=1,x=mul(x,x,kcz);
//    }
//    return ret;
//}
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void swap(res &x,res &y) {
//    x^=y^=x^=y;
//}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=1e3+10;
namespace MAIN {
    typedef pair<Pair,Pair> Pai;
    int vecx;
    Pai vec[N*N];
    int n,pa[N],pb[N],ida[N],idb[N],a[N],b[N];
    inline void MAIN(){
        n=read();
        for(res i=1;i<=n;i++)pa[read()]=a[i]=ida[i]=i;
        for(res i=1;i<=n;i++)pb[read()]=b[i]=idb[i]=i;
        for(res i=1;i<n;i++){
            if(a[i]==pa[i]&&b[i]==pb[i])continue;
            res A=a[i],B=b[i],&C=ida[pa[i]],&D=idb[pb[i]];
            vec[++vecx]=Pai(mp(i,C),mp(D,i)),swap(a[i],a[C]),swap(b[i],b[D]),swap(C,pa[A]),swap(D,pb[B]);
        }
        printf("%d\n",vecx);
        for(res i=1;i<=vecx;i++)printf("%d %d %d %d\n",vec[i].fi.fi,vec[i].fi.se,vec[i].se.fi,vec[i].se.se);
    }
}
int main() {
//    srand((unsigned)time(NULL));
    // freopen("zao.in","r",stdin);
    // freopen("std.out","w",stdout);
    MAIN::MAIN();
    return 0;
}


//2019.6.7 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 1e-10
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
//inline void add(res &x,const res &y,const res &kcz){
//    x+=y,x>=kcz?x-=kcz:(x<0?x+=kcz:1);
//}
//inline int Add(const res &x,const res &y,const res &kcz){
//    return x+y>=kcz?x+y-kcz:(x+y<0?x+y+kcz:x+y);
//}
//inline int mul(const res &x,const res &y,const res &kcz){
//    return int(1LL*x*y%kcz);
//}
//inline int qpow(res x,res y,const res &kcz){
//    res ret=1;
//    while(y){
//        if(y&1)ret=mul(ret,x,kcz);
//        y>>=1,x=mul(x,x,kcz);
//    }
//    return ret;
//}
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void swap(res &x,res &y) {
//    x^=y^=x^=y;
//}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int kcz=998244353;
const int N=2e5+10;
namespace MAIN {
    int n,m;
    int fac[N],inv[N],a[N],w[N],sum[2],Sum;
    inline void add(res &x,const res &y,const res &kcz){
        x+=y,x>=kcz?x-=kcz:(x<0?x+=kcz:1);
    }
    inline int Add(const res &x,const res &y,const res &kcz){
        return x+y>=kcz?x+y-kcz:(x+y<0?x+y+kcz:x+y);
    }
    inline int mul(const res &x,const res &y,const res &kcz){
        return int(1LL*x*y%kcz);
    }
    inline int qpow(res x,res y,const res &kcz){
        res ret=1;
        while(y){
            if(y&1)ret=mul(ret,x,kcz);
            y>>=1,x=mul(x,x,kcz);
        }
        return ret;
    }
    int gl[2][N],cur;
    int INV[2][N];
    map<int,int> M[2];
    inline int DP(const res &fl,const res &val,const res &lim){
        if(M[fl].count(val))return M[fl][val];
        res ret=0,sum=0;
        for(res i=0;i<m;i++)add(sum,mul(fl==0?Add(val,-sum,kcz):Add(val,sum,kcz),INV[fl][i],kcz),kcz),add(ret,mul(sum,fl==0?gl[cur][m-i-1]:gl[cur][i+1],kcz),kcz);
        return M[fl][val]=ret;
    }
    inline void MAIN(){
        n=read(),m=read();
        res qaq=m+5;
        for(res i=1;i<=n;i++)a[i]=read();
        for(res i=1;i<=n;i++)w[i]=read(),sum[a[i]]+=w[i],Sum+=w[i];
        for(res i=0;i<=2*qaq;i++)inv[i]=qpow(Sum+i-qaq,kcz-2,kcz);
        gl[0][0]=1,INV[0][0]=qpow(sum[0],kcz-2,kcz),INV[1][0]=qpow(sum[1],kcz-2,kcz);
        for(res i=1;i<=m;i++){
            INV[0][i]=qpow(sum[0]-i,kcz-2,kcz),INV[1][i]=qpow(sum[1]+i,kcz-2,kcz);
            for(res j=0;j<=i;j++)gl[cur^1][j]=0;
            for(res j=0;j<i;j++){
                res p=mul(sum[1]+j,inv[2*j-i+1+qaq],kcz);
                add(gl[cur^1][j],mul(gl[cur][j],1-p,kcz),kcz),add(gl[cur^1][j+1],mul(gl[cur][j],p,kcz),kcz);
            }
            cur^=1;
        }
        for(res i=1;i<=n;i++)printf("%d\n",Add(w[i],a[i]==0?-DP(a[i],w[i],m):DP(a[i],w[i],m),kcz));
    }
}
int main() {
//    srand((unsigned)time(NULL));
    // freopen("zao.in","r",stdin);
    // freopen("std.out","w",stdout);
    MAIN::MAIN();
    return 0;
}


//2019.6.10 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 1e-10
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
//inline void add(res &x,const res &y,const res &kcz){
//    x+=y,x>=kcz?x-=kcz:(x<0?x+=kcz:1);
//}
//inline int Add(const res &x,const res &y,const res &kcz){
//    return x+y>=kcz?x+y-kcz:(x+y<0?x+y+kcz:x+y);
//}
//inline int mul(const res &x,const res &y,const res &kcz){
//    return int(1LL*x*y%kcz);
//}
//inline int qpow(res x,res y,const res &kcz){
//    res ret=1;
//    while(y){
//        if(y&1)ret=mul(ret,x,kcz);
//        y>>=1,x=mul(x,x,kcz);
//    }
//    return ret;
//}
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void swap(res &x,res &y) {
//    x^=y^=x^=y;
//}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=1e3+10;
namespace MAIN {
    typedef pair<Pair,Pair> Pai;
    int vecx;
    Pai vec[N*N];
    int n,pa[N],pb[N],ida[N],idb[N],a[N],b[N];
    inline void MAIN(){
        n=read();
        for(res i=1;i<=n;i++)pa[read()]=a[i]=ida[i]=i;
        for(res i=1;i<=n;i++)pb[read()]=b[i]=idb[i]=i;
        for(res i=1;i<n;i++){
            if(a[i]==pa[i]&&b[i]==pb[i])continue;
            res A=a[i],B=b[i],&C=ida[pa[i]],&D=idb[pb[i]];
            vec[++vecx]=Pai(mp(i,C),mp(D,i)),swap(a[i],a[C]),swap(b[i],b[D]),swap(C,ida[A]),swap(D,idb[B]);
        }
        printf("%d\n",vecx);
        for(res i=1;i<=vecx;i++)printf("%d %d %d %d\n",vec[i].fi.fi,vec[i].fi.se,vec[i].se.fi,vec[i].se.se);
    }
}
int main() {
//    srand((unsigned)time(NULL));
    // freopen("zao.in","r",stdin);
    // freopen("std.out","w",stdout);
    MAIN::MAIN();
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,a[1005],b[1005],pa[1005],pb[1005],fromx[1005],fromy[1005],tox[1005],toy[1005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		pb[b[i]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		pa[a[i]]=i;
	}
	for(int i=n;i>1;i--)
	{
		if(a[i]==i&&b[i]==i)continue;
		fromx[++m]=i;
		fromy[m]=a[i];
		a[pa[i]]=a[i];
		pa[a[i]]=pa[i];
		tox[m]=b[i];
		toy[m]=i;
		b[pb[i]]=b[i];
		pb[b[i]]=pb[i];
	}
	printf("%d\n",m);
	for(int i=1;i<=m;i++)printf("%d %d %d %d\n",fromx[i],fromy[i],tox[i],toy[i]);
	return 0;
}


#include <cstdio>
#include <vector>
#include <array>

int as[1005];
int bs[1005];

int inva[1005];
int invb[1005];

void exchange_a(int i,int j){
  std::swap(as[i],as[j]);
  std::swap(inva[as[i]],inva[as[j]]);
}

void exchange_b(int i,int j){
  std::swap(bs[i],bs[j]);
  std::swap(invb[bs[i]],invb[bs[j]]);
}

int main(){
  int N;
  scanf("%d",&N);
  for(int i=1;i<=N;i++){
    scanf("%d",&as[i]);
    inva[as[i]]=i;
  }
  for(int i=1;i<=N;i++){
    scanf("%d",&bs[i]);
    invb[bs[i]]=i;
  }
  std::vector<std::array<int,4> > portals;
  for(int i=1;i<=N;i++){
    if(inva[i]!=i||invb[i]!=i){
      portals.push_back({inva[i],i,i,invb[i]});
      exchange_a(i,inva[i]);
      exchange_b(i,invb[i]);
    }
  }
  printf("%d\n",(int)portals.size());
  for(auto it:portals){
    printf("%d %d %d %d\n",it[0],it[1],it[2],it[3]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> r(n);
  for (int i = 0; i < n; ++i) {
    cin >> r[i];
    --r[i];
  }
  vector<int> rr(n);
  for (int i = 0; i < n; ++i) {
    rr[r[i]] = i;
  }
  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    --c[i];
  }
  vector<int> cc(n);
  for (int i = 0; i < n; ++i) {
    cc[c[i]] = i;
  }
  vector<vector<int>> ans;
  for (int i = 0; i < n; ++i) {
    int j = rr[i];
    int k = cc[i];
    if (j != i || k != i) {
      ans.push_back({j, i, i, k});
      swap(r[i], r[j]);
      swap(rr[r[i]], rr[r[j]]);
      swap(c[i], c[k]);
      swap(cc[c[i]], cc[c[k]]);
    }
  }
  cout << ans.size() << "\n";
  for (auto v : ans) {
    cout << v[0] + 1 << " " << v[1] + 1 << " " << v[2] + 1 << " " << v[3] + 1 << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>

const int MAXN = 1010;
int R[MAXN], C[MAXN], n;
int ar[MAXN], ac[MAXN];
std::vector<std::vector<int> > ansl;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> R[i], ar[R[i]] = i;
	for (int i = 1; i <= n; ++i) std::cin >> C[i], ac[C[i]] = i;
	for (int i = 1; i <= n; ++i) {
		if (R[i] == i && C[i] == i) continue;
		ansl.push_back({ar[i], i, i, ac[i]});
		ar[R[ar[i]] = R[i]] = ar[i];
		ac[C[ac[i]] = C[i]] = ac[i];
	}
	std::cout << ansl.size() << std::endl;
	for (auto t : ansl) {
		for (auto i : t)
			std::cout << i << ' ';
		std::cout << '\n';
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;
const int MAXN = 1005;
inline int readint()
{
	int res = 0, f = 1;
	char c = 0;
	while(!isdigit(c))
	{
		c = getchar();
		if(c=='-')
			f = -1;
	}
	while(isdigit(c))
		res = res*10+c-'0', c = getchar();
	return res*f;
}
int n,a[MAXN],b[MAXN],ia[MAXN],ib[MAXN];
int ansx[MAXN][2],ansy[MAXN][2],tot;

int main()
{
	n = readint();
	for(int i = 1; i<=n; i++)
	    a[i] = readint(), ia[a[i]] = i;
	for(int i = 1; i<=n; i++)
	    b[i] = readint(), ib[b[i]] = i;
	for(int i = 1; i<=n; i++)
	{
        if(ia[i]==i&&ib[i]==i)
            continue;
        tot++;
        ansx[tot][0] = i, ansy[tot][0] = ib[i];
        ansx[tot][1] = ia[i], ansy[tot][1] = i;
        ia[a[i]] = ia[i], a[ia[i]] = a[i];
		ib[b[i]] = ib[i], b[ib[i]] = b[i];
	}
	cout << tot << endl;
	for(int i = 1; i<=tot; i++)
	    cout << ansx[i][0] << " " << ansy[i][0] << " " << ansx[i][1] << " " << ansy[i][1] << endl;
	return 0;
}


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

const int N = 1e3 + 5;

typedef class Pair4 {
	public:
		int x1, y1, x2, y2;

		Pair4(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {	}

		void print() {
			printf("%d %d %d %d\n", x1, y1, x2, y2);
		}
} Pair4;

int n;
int r[N], c[N];
int a[N], b[N];
int p[N], q[N];
int _r[N], _c[N];
vector<Pair4> ans;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		r[i] = c[i] = i;
		_r[i] = _c[i] = i;
	}
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		p[a[i]] = i;
	}
	for (int i = 1; i <= n; i++) {
		scanf("%d", b + i);
		q[b[i]] = i;
	}
	for (int i = 1; i <= n; i++) {
		if (r[i] != p[i] || c[i] != q[i]) {
			// person p[i] -> i
			int x = _r[p[i]], y = _c[q[i]];
			ans.emplace_back(x, i, i, y);
			swap(r[i], r[x]);
			swap(_r[r[i]], _r[r[x]]);
			swap(c[i], c[y]);
			swap(_c[c[i]], _c[c[y]]);
		}
	}
	printf("%d\n", ans.size());
	for (auto p : ans) {
		p.print();
	}
	return 0;
}


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

const int N=1005;

int a[N],b[N],c[N],d[N],pa[N],pb[N],pc[N],pd[N];
vector <pair <int, int>> ans;

int main(){
	int n; scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",b+i);
		pb[b[i]]=i;
	}
	for (int i=1;i<=n;i++){
		scanf("%d",a+i);
		pa[a[i]]=i;
	}
	for (int i=1;i<=n;i++)
		c[i]=pc[i]=d[i]=pd[i]=i;
	for (int i=1;i<n;i++){
		if (c[i]==pa[i]&&d[i]==pb[i])
			continue;
		ans.push_back(make_pair(i,pc[pa[i]]));
		ans.push_back(make_pair(pd[pb[i]],i));
		int tc=c[i],td=d[i];
		swap(c[i],c[pc[pa[i]]]);
		swap(d[i],d[pd[pb[i]]]);
		swap(pc[pa[i]],pc[tc]);
		swap(pd[pb[i]],pd[td]);
	}
	printf("%d\n",ans.size()>>1);
	for (int i=0;i<ans.size()>>1;i++){
		printf("%d %d ",ans[i<<1].first,ans[i<<1].second);
		printf("%d %d\n",ans[i<<1|1].first,ans[i<<1|1].second);
	}
	return 0;
}


#include <cstdio>
#include <tuple>
int a[1005], b[1005], cnt;
std::tuple<int, int, int, int> ans[1005];
void work(int i)
{
	if (i < 0)
		return;
	if (a[i] == i && b[i] == i)
	{
		work(i - 1);
		return;
	}
	for (int j = 0; j < i; j++)
	{
		a[j] = a[j] == i ? a[i] : a[j];
		b[j] = b[j] == i ? b[i] : b[j];
	}
	work(i - 1);
	ans[cnt++] = std::make_tuple(a[i], i, i, b[i]);
}
int main()
{
	// freopen("1172D.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", a + i);
		a[i]--;
	}
	for (int i = 0; i < n; i++)
	{
		scanf("%d", b + i);
		b[i]--;
	}
	work(n - 1);
	printf("%d\n", cnt);
	for (int i = 0; i < cnt; i++)
	{
		int x1, y1, x2, y2;
		std::tie(x1, y1, x2, y2) = ans[i];
		printf("%d %d %d %d\n", x1 + 1, y1 + 1, x2 + 1, y2 + 1);
	}
	return 0;
}


#include <cstdio>
#include <tuple>
int a[1005], b[1005], cnt;
std::tuple<int, int, int, int> ans[1005];
void work(int i)
{
	if (i < 0)
		return;
	if (a[i] == i && b[i] == i)
	{
		work(i - 1);
		return;
	}
	for (int j = 0; j < i; j++)
	{
		a[j] = a[j] == i ? a[i] : a[j];
		b[j] = b[j] == i ? b[i] : b[j];
	}
	work(i - 1);
	ans[cnt++] = {a[i], i, i, b[i]};
}
int main()
{
	// freopen("1172D.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", a + i);
		a[i]--;
	}
	for (int i = 0; i < n; i++)
	{
		scanf("%d", b + i);
		b[i]--;
	}
	work(n - 1);
	printf("%d\n", cnt);
	for (int i = 0; i < cnt; i++)
	{
		int x1, y1, x2, y2;
		std::tie(x1, y1, x2, y2) = ans[i];
		printf("%d %d %d %d\n", x1 + 1, y1 + 1, x2 + 1, y2 + 1);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>

int n;
int A[1005],B[1005];
int P[1005],Q[1005];
int posP[1005],posQ[1005];
std::vector<std::pair<std::pair<int,int>,std::pair<int,int> > > V;

int main(){
	scanf("%d",&n);
	for (int i=1,x;i<=n;i++) scanf("%d",&x),A[x]=i,P[i]=posP[i]=i;
	for (int i=1,x;i<=n;i++) scanf("%d",&x),B[x]=i,Q[i]=posQ[i]=i;
	for (int i=1;i<=n;i++){
		if (P[i]==A[i]&&Q[i]==B[i]) continue;
		V.push_back(std::make_pair(std::make_pair(posP[A[i]],i),std::make_pair(i,posQ[B[i]])));
		posP[P[i]]=posP[A[i]],P[posP[A[i]]]=P[i];
		posQ[Q[i]]=posQ[B[i]],Q[posQ[B[i]]]=Q[i];
	}
	printf("%lu\n",V.size());
	for (std::vector<std::pair<std::pair<int,int>,std::pair<int,int> > >::iterator it=V.begin();it!=V.end();++it) printf("%d %d %d %d\n",it->first.first,it->first.second,it->second.first,it->second.second);
}


#include<iostream>
#include<cstdio>
#include<vector>

int n;
int A[1005],B[1005];
int P[1005],Q[1005];
int posP[1005],posQ[1005];
std::vector<std::pair<std::pair<int,int>,std::pair<int,int> > > V;

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]),P[i]=posP[i]=i;
	for (int i=1;i<=n;i++) scanf("%d",&B[i]),Q[i]=posQ[i]=i;
	for (int i=1;i<=n;i++){
		if (P[i]==A[i]&&Q[i]==B[i]) continue;
		V.push_back(std::make_pair(std::make_pair(posP[A[i]],i),std::make_pair(i,posQ[B[i]])));
		posP[P[i]]=posP[A[i]],P[posP[A[i]]]=P[i];
		posQ[Q[i]]=posQ[B[i]],Q[posQ[B[i]]]=Q[i];
	}
	printf("%lu\n",V.size());
	for (std::vector<std::pair<std::pair<int,int>,std::pair<int,int> > >::iterator it=V.begin();it!=V.end();++it) printf("%d %d %d %d\n",it->first.first,it->first.second,it->second.first,it->second.second);
}


#include<iostream>
#include<cstdio>
#include<vector>

int n;
int A[1005],B[1005];
int P[1005],Q[1005];
int posP[1005],posQ[1005];
std::vector<std::pair<int,int> > V;

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]),P[i]=posP[i]=i;
	for (int i=1;i<=n;i++) scanf("%d",&B[i]),Q[i]=posQ[i]=i;
	for (int i=1;i<=n;i++){
		if (P[i]==A[i]&&Q[i]==B[i]) continue;
		V.push_back(std::make_pair(posP[A[i]],i));
		V.push_back(std::make_pair(i,posQ[B[i]]));
		posP[P[i]]=posP[A[i]],P[posP[A[i]]]=P[i];
		posQ[Q[i]]=posQ[B[i]],Q[posQ[B[i]]]=Q[i];
	}
	printf("%lu\n",V.size());
	for (std::vector<std::pair<int,int> >::iterator it=V.begin();it!=V.end();++it) printf("%d %d\n",it->first,it->second);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
#define fir first
#define sec second
#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)
#define rrp(i,a,b) for (int i = (a) ; i >= (b) ; -- i)
#define gc() getchar()
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc() ; !isdigit(tmp) ; tmp = gc())
    key = (tmp == '-');
  for ( ; isdigit(tmp) ; tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 1010;
typedef pair<pii,pii> piiii;
vector<piiii> ans;
int n, p1[N], p2[N], o1[N], o2[N];
int main() {
  read(n);
  rep (i, 1, n) read(p1[i]);
  rep (i, 1, n) read(p2[i]);
  rrp (i, n, 1) {
    int p = i;
    rep (j, 1, i-1) if (p1[j] == i) p = j;
    o1[i] = p;
    if (p != i) swap(p1[i], p1[p]);
  }
  rrp (i, n, 1) {
    int p = i;
    rep (j, 1, i-1) if (p2[j] == i) p = j;
    o2[i] = p;
    if (p != i) swap(p2[i], p2[p]);
  }
  rep (i, 2, n) {
    if (o1[i] == i && o2[i] == i) continue;
    ans.push_back(piiii(pii(p1[o1[i]], i), pii(i, p2[o2[i]])));
    swap(p1[i], p1[o1[i]]);
    swap(p2[i], p2[o2[i]]);
  }
  printf("%d\n", (int)ans.size());
  rep (i, 0, (int)ans.size()-1)
    printf("%d %d %d %d\n", ans[i].fir.fir, ans[i].fir.sec, ans[i].sec.fir, ans[i].sec.sec);
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define N 1005

using namespace std;
inline int Get() {int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}while('0'<=ch&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}

int n;
int a[N],b[N];
int ra[N],rb[N];
struct node {
	int x1,y1,x2,y2;
	node() {}
	node(int _x1,int _y1,int _x2,int _y2) {x1=_x1,y1=_y1,x2=_x2,y2=_y2;}
};
vector<node>ans;
int c[N],rc[N],d[N],rd[N];
int main() {
	n=Get();
	for(int i=1;i<=n;i++) b[i]=Get();
	for(int i=1;i<=n;i++) a[i]=Get();
	for(int i=1;i<=n;i++) ra[a[i]]=i,rb[b[i]]=i;
	for(int i=1;i<=n;i++) c[i]=d[i]=rc[i]=rd[i]=i;
	for(int i=1;i<n;i++) {
		if(ra[i]==c[i]&&rb[i]==d[i]) continue ;
		ans.push_back(node(i,rc[ra[i]],rd[rb[i]],i));
		int x1=c[i],x2=d[i];
		swap(c[i],c[rc[ra[i]]]);
		swap(d[i],d[rd[rb[i]]]);
		swap(rc[ra[i]],rc[x1]);
		swap(rd[rb[i]],rd[x2]);
	}
	cout<<ans.size()<<"\n";
	for(int i=0;i<ans.size();i++) {
		cout<<ans[i].x1<<" "<<ans[i].y1<<" "<<ans[i].x2<<" "<<ans[i].y2<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 10;
int a[N],b[N],c[N],d[N];
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i], b[a[i]] = i;
    for(int i=1;i<=n;i++) cin>>c[i], d[c[i]] = i;
    vector<pair<pair<int,int>,pair<int,int> > > ans;
    for(int i=1;i<=n;i++){
        if(i==b[i]&&i==d[i]) continue;
        ans.push_back({{b[i],i},{i,d[i]}});
        b[a[i]] = b[i], a[b[i]] = a[i];
        d[c[i]] = d[i], c[d[i]] = c[i];
    }
    cout<<ans.size()<<endl;
    for(auto i: ans){
        cout<<i.first.first<<' '<<i.first.second<<' '<<i.second.first<<' '<<i.second.second<<endl;
    }
}


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

const int MAXN = 1234;
int N;
int R[MAXN], C[MAXN];
vector<array<int, 4>> ans;

void go(int n) {
	if (n == 0) return;
	if (C[n] == n && R[n] == n) {
		// do nothing
	} else {
		for (int i = n-1; i >= 1; i--) {
			if (R[i] == n) R[i] = R[n];
		}
		for (int i = n-1; i >= 1; i--) {
			if (C[i] == n) C[i] = C[n];
		}
		ans.push_back({C[n], n, n, R[n]});
	}
	go(n-1);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> C[i];
	for (int i = 1; i <= N; i++) cin >> R[i];
	go(N);

	cout << ans.size() << '\n';
	for (auto p : ans) {
		cout << p[0] << ' ' << p[1] << ' ' << p[2] << ' ' << p[3] << '\n';
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 1010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,m,a[N],b[N],row_from[N],line_from[N],infromleft[N],outtoright[N],infromup[N],outtodown[N];
struct data{int x1,y1,x2,y2;
}q[N];
signed main()
{
#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) a[i]=read(),row_from[i]=i;
	for (int i=1;i<=n;i++) b[i]=read(),line_from[i]=i;
	for (int i=1;i<=n;i++) infromleft[i]=i,outtoright[a[i]]=i;
	for (int i=1;i<=n;i++) infromup[i]=i,outtodown[b[i]]=i;
	for (int i=1;i<=n;i++)
	{
		if (infromleft[i]==outtoright[i]&&infromup[i]==outtodown[i]) continue;
		m++;q[m].x1=row_from[outtoright[i]],q[m].y1=i,q[m].x2=i,q[m].y2=line_from[outtodown[i]];
		row_from[infromleft[i]]=row_from[outtoright[i]],line_from[infromup[i]]=line_from[outtodown[i]];
		infromleft[row_from[infromleft[i]]]=infromleft[i],infromup[line_from[infromup[i]]]=infromup[i];
	}
	cout<<m<<endl;
	for (int i=1;i<=m;i++) cout<<q[i].x1<<' '<<q[i].y1<<' '<<q[i].x2<<' '<<q[i].y2<<endl;
	return 0;
	//NOTICE LONG LONG!!!!!
}
//��һЩ������ʹ����(i,1)�����ܵ�(ai,n)��(1,i)�����ܵ�(n,bi)
//���ǵ�ǰ�ǵ�i���˴�(1,1)��������j���˴�(1,n)��ȥ����x���˴�(1,1)��������y���˴�(n,1)��ȥ
//�ڵ�j���˽����ĵط��Ŵ����� ���͵���y���˽����ĵط�
//֮���i���˱�Ϊ��ԭ����j���˽����ĵط����� ��x���˱�Ϊ��ԭ����y���˽����ĵط�����


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 1010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,m,a[N],b[N],infromleft[N],outtoright[N],infromup[N],outtodown[N];
struct data{int x1,y1,x2,y2;
}q[N];
signed main()
{
#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++) b[i]=read();
	for (int i=1;i<=n;i++) infromleft[i]=i,outtoright[a[i]]=i;
	for (int i=1;i<=n;i++) infromup[i]=i,outtodown[b[i]]=i;
	for (int i=1;i<=n;i++)
	{
		if (infromleft[i]==outtoright[i]&&infromup[i]==outtodown[i]) continue;
		m++;q[m].x1=outtoright[i],q[m].y1=i,q[m].x2=i,q[m].y2=outtodown[i];
		a[infromleft[i]]=outtoright[i],b[infromup[i]]=outtodown[i];
		outtoright[a[infromleft[i]]]=infromleft[i],outtodown[b[infromup[i]]]=infromup[i];
	}
	cout<<m<<endl;
	for (int i=1;i<=m;i++) cout<<q[i].x1<<' '<<q[i].y1<<' '<<q[i].x2<<' '<<q[i].y2<<endl;
	return 0;
	//NOTICE LONG LONG!!!!!
}
//��һЩ������ʹ����(i,1)�����ܵ�(ai,n)��(1,i)�����ܵ�(n,bi)
//���ǵ�ǰ�ǵ�i���˴�(1,1)��������j���˴�(1,n)��ȥ����x���˴�(1,1)��������y���˴�(n,1)��ȥ
//�ڵ�j���˽����ĵط��Ŵ����� ���͵���y���˽����ĵط�
//֮���i���˱�Ϊ��ԭ����j���˽����ĵط����� ��x���˱�Ϊ��ԭ����y���˽����ĵط�����


#include <cstdio>
#include <vector>
#include <algorithm>

const int N = 1e3 + 5;
int n, a[N], b[N], p[N], q[N];
struct Portal {
    int x, y, z, w;
};
std::vector <Portal> ans;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), p[a[i]] = i;
    for (int i = 1; i <= n; ++i) scanf("%d", &b[i]), q[b[i]] = i;
    for (int i = 1; i <= n; ++i) {
        if (a[i] == i && b[i] == i) continue;
        ans.push_back((Portal) {p[i], i, i, q[i]});
        int tmp1 = a[i], tmp2 = b[i];
        std::swap(a[i], a[p[i]]), std::swap(p[i], p[tmp1]);
        std::swap(b[i], b[q[i]]), std::swap(q[i], q[tmp2]);
    }
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); ++i) printf("%d %d %d %d\n", ans[i].x, ans[i].y, ans[i].z, ans[i].w);
    return 0;
}


// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=1000+10;

int n;
int r[N],pr[N];
int c[N],pc[N];
struct data { int a,b,c,d; };
vector<data> ans;

int main() {
    n=read();
    for (re int i=1;i<=n;++i) r[i]=read(),pr[r[i]]=i;
    for (re int i=1;i<=n;++i) c[i]=read(),pc[c[i]]=i;
    for (re int i=1;i<n;++i) {
        if (pr[i]==i&&pc[i]==i) continue;
        ans.push_back((data){i,pc[i],pr[i],i});
        swap(r[i],r[pr[i]]),swap(c[i],c[pc[i]]);
    }
    printf("%d\n",ans.size());
    for (re auto i:ans) printf("%d %d %d %d\n",i.a,i.b,i.c,i.d);
    return 0;
}


// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=1000+10;

int n;
int r[N],pr[N];
int c[N],pc[N];
struct data { int a,b,c,d; };
vector<data> ans;

int main() {
    n=read();
    for (re int i=1;i<=n;++i) r[i]=read();
    for (re int i=1;i<=n;++i) c[i]=read();
    for (re int i=1;i<n;++i) {
        int pr,pc;
        for (re int j=1;j<=n;++j) {
            if (r[j]==i) pr=j;
            if (c[j]==i) pc=j;
        }
        if (pr==i&&pc==i) continue;
        ans.push_back((data){i,pc,pr,i});
        swap(r[i],r[pr]),swap(c[i],c[pc]);
    }
    printf("%d\n",ans.size());
    for (re auto i:ans) printf("%d %d %d %d\n",i.a,i.b,i.c,i.d);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int N=1005;
int n,a[N],b[N],pa[N],pb[N],cnt;
pii px[N],py[N];
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]),pa[a[i]]=i;
	For(i,1,n) scanf("%d",&b[i]),pb[b[i]]=i;
	For(i,1,n) if (pa[i]!=i||pb[i]!=i){
		px[++cnt]=pii(i,pb[i]);
		py[cnt]=pii(pa[i],i);
		int x=i,y=pa[i];
		if (x!=y){
			swap(a[x],a[y]);
			swap(pa[a[x]],pa[a[y]]);
		}
		x=i,y=pb[i];
		if (x!=y){
			swap(b[x],b[y]);
			swap(pb[b[x]],pb[b[y]]);
		}
	}
	printf("%d\n",cnt);
	For(i,1,cnt)
		printf("%d %d %d %d\n",px[i].fi,px[i].se,py[i].fi,py[i].se);
}


// luogu-judger-enable-o2
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <string>
#include <string.h>
#include <cmath>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <fstream>
#include <sstream>
#include <assert.h>
#define SIZE 2010
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
void io() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}
ll n, t, m, k;
struct Point {
	int x, y, xx, yy;
	Point() {}
	Point(int ax, int ay, int axx, int ayy): x(ax), y(ay), xx(axx), yy(ayy) {}
}tp;
vector<Point> v;
int a[SIZE], b[SIZE], ra[SIZE], rb[SIZE], c[SIZE], d[SIZE], rc[SIZE], rd[SIZE];
bool visa[SIZE], visb[SIZE];
int main() {
	io(); cin >> n;
	rep(i, 1, n) {
		cin >> b[i];
		rb[b[i]] = i;
	}
	rep(i, 1, n) {
		cin >> a[i];
		ra[a[i]] = i;
	}
	rep(i, 1, n) c[i] = d[i] = rc[i] = rd[i] = i;
	rep(i, 1, n) {
		if (c[i] == ra[i] && d[i] == rb[i]) continue;
		v.emplace_back(Point(i, rc[ra[i]], rd[rb[i]], i));
		int tp1 = c[i], tp2 = d[i];
		swap(c[i], c[rc[ra[i]]]);
		swap(d[i], d[rd[rb[i]]]);
		swap(rc[ra[i]], rc[tp1]);
		swap(rd[rb[i]], rd[tp2]);
	}
	cout << v.size() << endl;
	int tmp = v.size() - 1;
	rep(i, 0, tmp) {
		cout << v[i].x << ' ' << v[i].y << ' ' << v[i].xx << ' ' << v[i].yy << endl;
	}
}


// luogu-judger-enable-o2
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <string>
#include <string.h>
#include <cmath>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <fstream>
#include <sstream>
#include <assert.h>
#define SIZE 2010
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
void io() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}
ll n, t, m, k;
struct Point {
	int x, y, xx, yy;
	Point() {}
	Point(int ax, int ay, int axx, int ayy): x(ax), y(ay), xx(axx), yy(ayy) {}
}tp;
vector<Point> v;
int a[SIZE], b[SIZE], ra[SIZE], rb[SIZE], c[SIZE], d[SIZE], rc[SIZE], rd[SIZE];
bool visa[SIZE], visb[SIZE];
int main() {
	io(); cin >> n;
	rep(i, 1, n) {
		cin >> b[i];
		rb[b[i]] = i;
	}
	rep(i, 1, n) {
		cin >> a[i];
		ra[a[i]] = i;
	}
	rep(i, 1, n) c[i] = d[i] = rc[i] = rd[i] = i;
	rep(i, 1, n) {
		if (c[i] == ra[i] && d[i] == rb[i]) continue;
		v.emplace_back(Point(i, rc[ra[i]], rd[rb[i]], i));
		int tp1 = c[i], tp2 = d[i];
		swap(c[i], c[rc[ra[i]]]);
		swap(d[i], d[rd[rb[i]]]);
		swap(rc[ra[i]], rc[tp1]);
		swap(rd[rb[i]], rd[tp2]);
	}
	cout << v.size() << endl;
	rep(i, 0, v.size() - 1) {
		cout << v[i].x << ' ' << v[i].y << ' ' << v[i].xx << ' ' << v[i].yy << endl;
	}
}


#include<bits/stdc++.h>
#define db long double
#define il inline
#define re register

using namespace std;
const int N=1000+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
int n,m,a[N],pa[N],b[N],pb[N],c[N],pc[N],d[N],pd[N];
int an[N][4],ta;

int main()
{
	n=rd();
	for(int i=1;i<=n;++i) a[i]=rd(),pa[a[i]]=i;
	for(int i=1;i<=n;++i) b[i]=rd(),pb[b[i]]=i;
	for(int i=1;i<=n;++i) c[i]=pc[i]=d[i]=pd[i]=i;
	for(int i=1;i<n;++i)
	{
		if(pa[i]==pc[i]&&pb[i]==pd[i]) continue;
		an[++ta][0]=i,an[ta][1]=d[pb[i]],an[ta][2]=c[pa[i]],an[ta][3]=i;
		swap(c[pc[i]],c[pa[i]]),swap(d[pd[i]],d[pb[i]]);
		int cc=pc[i],dd=pd[i];
		pc[c[pc[i]]]=cc,pc[c[pa[i]]]=pa[i];
		pd[d[pd[i]]]=dd,pd[d[pb[i]]]=pb[i];
	}
	printf("%d\n",ta);
	for(int i=1;i<=ta;++i) printf("%d %d %d %d\n",an[i][0],an[i][1],an[i][2],an[i][3]);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <utility>
#define N 1020
using namespace std;

int a[N], b[N];
vector<pair<pair<int, int>, pair<int, int> > > o;

int main(void)
{
    int n;
    int i;

    cin >> n;
    for(i = 0; i < n; i ++)
        cin >> a[i];
    for(i = 0; i < n; i ++)
        cin >> b[i];

    for(i = 0; i < n; i ++)
        if(a[i] != b[i])
            o.push_back(make_pair(make_pair(i, b[i]), make_pair(a[i], i)));
    cout << o.size() << endl;
    for(i = 0; i < (signed)o.size(); i ++)
        cout << o.at(i).first.first + 1 << ' ' << o.at(i).first.second << ' ' << o.at(i).second.first << ' ' << o.at(i).second.second + 1 << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <utility>
#define N 1020
using namespace std;

int a[N], b[N];
vector<pair<pair<int, int>, pair<int, int> > > o;

int main(void)
{
    int n;
    int i, j;

    cin >> n;
    for(i = 0; i < n; i ++)
    {
        cin >> a[i];
        a[i] --;
    }
    for(i = 0; i < n; i ++)
    {
        cin >> b[i];
        b[i] --;
    }

    for(i = n - 1; i > -1; i --)
        if(i != a[i] || i != b[i])
        {
            o.push_back(make_pair(make_pair(i, b[i]), make_pair(a[i], i)));
            for(j = 0; j <= i; j ++)
            {
                if(a[j] == i)
                    a[j] = a[i];
                if(b[j] == i)
                    b[j] = b[i];
            }
        }
    cout << o.size() << endl;
    for(i = 0; i < (signed)o.size(); i ++)
        cout << o.at(i).first.first + 1 << ' ' << o.at(i).first.second + 1 << ' ' << o.at(i).second.first + 1 << ' ' << o.at(i).second.second + 1 << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <utility>
#define N 1020
using namespace std;

int a[N], b[N], c[N], d[N];
vector<pair<pair<int, int>, pair<int, int> > > o;

int main(void)
{
    int n;
    int i, j, x, y;

    cin >> n;
    for(i = 0; i < n; i ++)
        cin >> a[i];
    for(i = 0; i < n; i ++)
        cin >> b[i];
    for(i = 0; i < n; i ++)
        c[i] = d[i] = i;

    for(i = 0; i < n; i ++)
    {
        for(j = 0; j < n; j ++)
        {
            if(c[j] == i)
                x = j;
            if(d[j] == i)
                y = j;
        }
        if(a[i] - 1 != x || b[i] - 1 != y)
        {
            o.push_back(make_pair(make_pair(x, b[i]), make_pair(a[i], y)));
            swap(c[a[i] - 1], c[x]);
            swap(d[b[i] - 1], d[y]);
        }
    }
    cout << o.size() << endl;
    for(i = 0; i < (signed)o.size(); i ++)
        cout << o.at(i).first.first + 1 << ' ' << o.at(i).first.second << ' ' << o.at(i).second.first << ' ' << o.at(i).second.second + 1 << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <utility>
#define N 1020
using namespace std;

int a[N], b[N], c[N], d[N];
vector<pair<pair<int, int>, pair<int, int> > > o;

int main(void)
{
    int n;
    int i, j, x, y, p, q;

    cin >> n;
    for(i = 0; i < n; i ++)
        cin >> a[i];
    for(i = 0; i < n; i ++)
        cin >> b[i];
    for(i = 0; i < n; i ++)
        c[i] = d[i] = i;

    for(i = 0; i < n; i ++)
    {
        for(j = 0; j < n; j ++)
        {
            if(c[j] == i)
                x = j;
            if(d[j] == i)
                y = j;
        }
        if(i != a[x] - 1 || i != b[y] - 1)
        {
            o.push_back(make_pair(make_pair(i, b[y]), make_pair(a[x], i)));
            for(j = 0; j < n; j ++)
            {
                if(c[j] == a[x] - 1)
                    p = j;
                if(d[j] == b[y] - 1)
                    q = j;
            }
            swap(c[p], c[i]);
            swap(d[q], d[i]);
        }
    }
    cout << o.size() << endl;
    for(i = 0; i < (signed)o.size(); i ++)
        cout << o.at(i).first.first + 1 << ' ' << o.at(i).first.second << ' ' << o.at(i).second.first << ' ' << o.at(i).second.second + 1 << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <utility>
#define N 1020
using namespace std;

int a[N], b[N], c[N], d[N];
vector<pair<pair<int, int>, pair<int, int> > > o;

int main(void)
{
    int n;
    int i, j, x, y;

    cin >> n;
    for(i = 0; i < n; i ++)
        cin >> a[i];
    for(i = 0; i < n; i ++)
        cin >> b[i];
    for(i = 0; i < n; i ++)
        c[i] = d[i] = i;

    for(i = 0; i < n; i ++)
    {
        for(j = 0; j < n; j ++)
        {
            if(c[j] == i)
                x = j;
            if(d[j] == i)
                y = j;
        }
        if(i != a[x] - 1 || i != b[y] - 1)
        {
            o.push_back(make_pair(make_pair(i, b[y]), make_pair(a[x], i)));
            swap(c[a[x] - 1], c[i]);
            swap(d[b[y] - 1], d[i]);
        }
    }
    cout << o.size() << endl;
    for(i = 0; i < (signed)o.size(); i ++)
        cout << o.at(i).first.first + 1 << ' ' << o.at(i).first.second << ' ' << o.at(i).second.first << ' ' << o.at(i).second.second + 1 << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <utility>
#define N 1020
using namespace std;

int a[N], b[N];
vector<pair<pair<int, int>, pair<int, int> > > o;

int main(void)
{
    int n;
    int i, j;

    cin >> n;
    for(i = 0; i < n; i ++)
    {
        cin >> a[i];
        a[i] --;
    }
    for(i = 0; i < n; i ++)
    {
        cin >> b[i];
        b[i] --;
    }

    for(i = 0; i < n; i ++)
        if(i != a[i] || i != b[i])
        {
            o.push_back(make_pair(make_pair(i, b[i]), make_pair(a[i], i)));
            for(j = i + 1; j < n; j ++)
            {
                if(a[j] == i)
                    a[j] = a[i];
                if(b[j] == i)
                    b[j] = b[i];
            }
        }
    cout << o.size() << endl;
    for(i = 0; i < (signed)o.size(); i ++)
        cout << o.at(i).first.first + 1 << ' ' << o.at(i).first.second + 1 << ' ' << o.at(i).second.first + 1 << ' ' << o.at(i).second.second + 1 << endl;

    return 0;
}


use std::{cmp, collections::HashMap, io, str};

fn main() {
    let mut input = IO::new();
    let n = input.read();
    let mut a = Vec::new();
    let mut b = Vec::new();
    for _ in 0..n {
        let (x, y): (i32, i32) = (input::read(), input::read());
        a.push(x);
        b.push(y);
    }
    a.sort();
    a.dedup();
    b.sort();
    b.dedup();
    println!("{}", cmp::min(a.len(), b.len()));
}

struct IO {
    tokens: Vec<String>,
}

impl IO {
    fn new() -> IO {
        IO { tokens: Vec::new() }
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.read_token().parse::<T>().ok().unwrap()
    }

    fn read_token(&mut self) -> String {
        if self.tokens.is_empty() {
            self.tokens = self
                .read_line()
                .split_whitespace()
                .map(|x| x.to_string())
                .collect();
            self.tokens.reverse();
        }
        self.tokens.pop().unwrap()
    }

    fn read_line(&mut self) -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        s.trim_right().to_string()
    }
}


use std::{cmp, collections::HashMap};

fn main() {
    let mut input = IO::new();
    let n = input.read();
    let mut a = Vec::new();
    let mut b = Vec::new();
    for _ in 0..n {
        let (x, y): (i32, i32) = (input.read(), input.read());
        a.push(x);
        b.push(y);
    }
    a.sort();
    a.dedup();
    b.sort();
    b.dedup();
    println!("{}", cmp::min(a.len(), b.len()));
}

struct IO {
    tokens: Vec<String>,
}

impl IO {
    fn new() -> IO {
        IO { tokens: Vec::new() }
    }

    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.read_token().parse::<T>().ok().unwrap()
    }

    fn read_token(&mut self) -> String {
        if self.tokens.is_empty() {
            self.tokens = self
                .read_line()
                .split_whitespace()
                .map(|x| x.to_string())
                .collect();
            self.tokens.reverse();
        }
        self.tokens.pop().unwrap()
    }

    fn read_line(&mut self) -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        s.trim_right().to_string()
    }
}


use std::{cmp, collections::HashMap, io, str};

fn main() {
    let n = read_int();
    let mut a = Vec::new();
    let mut b = Vec::new();
    for i in 0..n {
        let line: Vec<i32> = read_line()
            .split(' ')
            .map(|v| v.parse::<i32>().ok().unwrap())
            .collect();
        a.push(line[0]);
        b.push(line[1]);
    }
    a.sort();
    a.dedup();
    b.sort();
    b.dedup();
    println!("{}", cmp::min(a.len(), b.len()));
}

fn read_int<T: str::FromStr>() -> T {
    read_line().parse::<T>().ok().unwrap()
}

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s);
    s.trim_right().to_string()
}


package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var vertical, horizontal [101]bool
	var v, h int
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		var x, y int
		fmt.Fscanf(reader, "%d %d\n", &x, &y)
		horizontal[x] = true
		vertical[y] = true
	}
	for i := 0; i < 101; i++ {
		if vertical[i] {
			v++
		}
		if horizontal[i] {
			h++
		}
	}
	if v < h {
		fmt.Printf("%d", v)
	} else {
		fmt.Printf("%d", h)
	}

}


package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"io"
	// "time"
	// "strings"
)

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner(r io.Reader) *Scanner {
	scanner := bufio.NewScanner(r)
	scanner.Split(bufio.ScanWords)

	return &Scanner{
		scanner: scanner,
	}
}

func (s *Scanner) next() string {
	ok := s.scanner.Scan()
	if !ok {
		panic("Scan error")
	}
	return s.scanner.Text()
}

func (s *Scanner) nextInt() int {
	n, err := strconv.Atoi(s.next())
	if err!=nil {
		panic(err)
	}
	return n
}

func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	// Method 1 slowest
	// reader := bufio.NewReader(os.Stdin)
	// var n int
	// fmt.Fscan(reader, &n)

	// Method 2 slowest
	// reader := bufio.NewReader(os.Stdin)
	// var n int
	// line, _ := reader.ReadString('\n')
	// fmt.Sscan(line, &n)

	// Method 3 fast
	// reader := bufio.NewReader(os.Stdin)
	// line, _ := reader.ReadString('\n')
	// n, _ := strconv.Atoi(line[:len(line)-1])
	// var token []string

	// Method 4 fastest
	// scanner := bufio.NewScanner(os.Stdin)
	// scanner.Split(bufio.ScanWords)
	// scanner.Scan()
	// n, _ := strconv.Atoi(scanner.Text())

	// Method 5 fastest
	scanner := NewScanner(os.Stdin)
	n := scanner.nextInt()

	X := make([]bool, 101)
	Y := make([]bool, 101)

	var a, b int
	var countX, countY int

	for i:=0; i<n; i++ {
		// Method 1
		// fmt.Fscan(reader, &a, &b)

		// Method 2
		// line, _ = reader.ReadString('\n')
		// fmt.Sscan(line, &a, &b)

		// Method 3
		// line, _ = reader.ReadString('\n')
		// token = strings.Fields(line)
		// a, _ = strconv.Atoi(token[0])
		// b, _ = strconv.Atoi(token[1])

		// Method 4
		// scanner.Scan()
		// a, _ = strconv.Atoi(scanner.Text())
		// scanner.Scan()
		// b, _ = strconv.Atoi(scanner.Text())

		// Method 5
		a, b = scanner.nextInt(), scanner.nextInt()

		if !X[a] {
			countX++
			X[a] = true
		}
		if !Y[b] {
			countY++
			Y[b] = true
		}
	}

	if countX < countY {
		fmt.Println(countX)
	} else {
		fmt.Println(countY)
	}
}


package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"io"
	// "time"
	"strings"
)

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner(r io.Reader) *Scanner {
	scanner := bufio.NewScanner(r)
	scanner.Split(bufio.ScanWords)

	return &Scanner{
		scanner: scanner,
	}
}

func (s *Scanner) next() string {
	ok := s.scanner.Scan()
	if !ok {
		panic("Scan error")
	}
	return s.scanner.Text()
}

func (s *Scanner) nextInt() int {
	n, err := strconv.Atoi(s.next())
	if err!=nil {
		panic(err)
	}
	return n
}

func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	// Method 1 slowest
	// reader := bufio.NewReader(os.Stdin)
	// var n int
	// fmt.Fscan(reader, &n)

	// Method 2 slowest
	// reader := bufio.NewReader(os.Stdin)
	// var n int
	// line, _ := reader.ReadString('\n')
	// fmt.Sscan(line, &n)

	// Method 3 fast
	// reader := bufio.NewReader(os.Stdin)
	// line, _ := reader.ReadString('\n')
	// n, _ := strconv.Atoi(line[:len(line)-1])
	// var token []string

	// Method 4 fastest
	// scanner := bufio.NewScanner(os.Stdin)
	// scanner.Split(bufio.ScanWords)
	// scanner.Scan()
	// n, _ := strconv.Atoi(scanner.Text())

	// Method 5 fastest
	scanner := NewScanner(os.Stdin)
	n := scanner.nextInt()

	X := make([]bool, 101)
	Y := make([]bool, 101)

	var a, b int
	var countX, countY int

	for i:=0; i<n; i++ {
		// Method 1
		// fmt.Fscan(reader, &a, &b)

		// Method 2
		// line, _ = reader.ReadString('\n')
		// fmt.Sscan(line, &a, &b)

		// Method 3
		// line, _ = reader.ReadString('\n')
		// token = strings.Fields(line)
		// a, _ = strconv.Atoi(token[0])
		// b, _ = strconv.Atoi(token[1])

		// Method 4
		// scanner.Scan()
		// a, _ = strconv.Atoi(scanner.Text())
		// scanner.Scan()
		// b, _ = strconv.Atoi(scanner.Text())

		// Method 5
		a, b = scanner.nextInt(), scanner.nextInt()

		if !X[a] {
			countX++
			X[a] = true
		}
		if !Y[b] {
			countY++
			Y[b] = true
		}
	}

	if countX < countY {
		fmt.Println(countX)
	} else {
		fmt.Println(countY)
	}
}


package main

import (
	"fmt"
	"bufio"
	"os"
)

func main() {
	var (
		n, x, y        int
		roomHorizontal [101] bool
		roomVertical [101] bool
	)

    scanner := bufio.NewScanner(os.Stdin)

    scanner.Scan()
    fmt.Sscanf(scanner.Text(), "%d", &n)

	cntHor := 0
	cntVer := 0

	for i := 0; i < n; i++ {
        scanner.Scan()
        fmt.Sscanf(scanner.Text(), "%d %d", &x, &y)

		ok := roomHorizontal[x]
		if !ok {
			roomHorizontal[x] = true
			cntHor++
		}

		ok = roomVertical[y]
		if !ok {
			roomVertical[y] = true
			cntVer++
		}
	}

	if cntHor > cntVer {
		fmt.Println(cntVer)
		return
	}

	fmt.Println(cntHor)
}


package main

import (
    "fmt"
    "bufio"
    "os"
)

func main() {
    var (
        n, x, y        int
        roomHorizontal  = make(map[int]bool)
        roomVertical = make(map[int]bool)
    )

    scanner := bufio.NewScanner(os.Stdin)

    scanner.Scan()
    fmt.Sscanf(scanner.Text(), "%d", &n)

    cntHor := 0
    cntVer := 0

    for i := 0; i < n; i++ {
        scanner.Scan()
        fmt.Sscanf(scanner.Text(), "%d %d", &x, &y)

        _, ok := roomHorizontal[x]
        if !ok {
            roomHorizontal[x] = true
            cntHor++
        }

        _, ok = roomVertical[y]
        if !ok {
            roomVertical[y] = true
            cntVer++
        }
    }

    if cntHor > cntVer {
        fmt.Println(cntVer)
        return
    }

    fmt.Println(cntHor)
}


package main

import (
	"fmt"
)

func main() {
	var (
		n, x, y        int
		roomHorizontal = make(map[int]bool)
		roomVertical   = make(map[int]bool)
	)

	_, _ = fmt.Scan(&n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scan(&x)
		_, _ = fmt.Scan(&y)

		roomHorizontal[x] = true
		roomVertical[y] = true
	}
	answer := len(roomHorizontal)
	if len(roomVertical) < answer {
	    answer = len(roomVertical)
	}
	fmt.Println(answer)
}


package main

import (
	"fmt"
)

func main() {
	var (
		n, x, y        int
		roomHorizontal [101] bool
		roomVertical [101] bool
	)

	_, _ = fmt.Scan(&n)

	cntHor := 0
	cntVer := 0

	for i := 0; i < n; i++ {
		_, _ = fmt.Scan(&x)
		_, _ = fmt.Scan(&y)

		ok := roomHorizontal[x]
		if !ok {
			roomHorizontal[x] = true
			cntHor++
		}

		ok = roomVertical[y]
		if !ok {
			roomVertical[y] = true
			cntVer++
		}
	}

	if cntHor > cntVer {
		fmt.Println(cntVer)
		return
	}

	fmt.Println(cntHor)
}


package main

import (
	"fmt"
	"bufio"
	"os"
)

func main() {
	var (
		n, x, y        int
		roomHorizontal [101] bool
		roomVertical [101] bool
	)

    scanner := bufio.NewScanner(os.Stdin)

    scanner.Scan()
    fmt.Sscanf(scanner.Text(), "%d", &n)

	cntHor := 0
	cntVer := 0

	for i := 0; i < n; i++ {
	    scanner.Scan()
	    fmt.Sscanf(scanner.Text(), "%d %d", &x, &y)

		ok := roomHorizontal[x]
		if !ok {
			roomHorizontal[x] = true
			cntHor++
		}

		ok = roomVertical[y]
		if !ok {
			roomVertical[y] = true
			cntVer++
		}
	}

	if cntHor > cntVer {
		fmt.Println(cntVer)
		return
	}

	fmt.Println(cntHor)
}


package main

import (
	"fmt"
	"bufio"
	"os"
)

func main() {
	var (
		n, x, y        int
		roomHorizontal [101] bool
		roomVertical [101] bool
	)

    scanner := bufio.NewScanner(os.Stdin)

    scanner.Scan()
    fmt.Sscanf(scanner.Text(), "%d", &n)

    cntHor := 0
	cntVer := 0

	for i := 0; i < n; i++ {
        scanner.Scan()
        fmt.Sscanf(scanner.Text(), "%d %d", &x, &y)

		ok := roomHorizontal[x]
		if !ok {
			roomHorizontal[x] = true
			cntHor++
		}

		ok = roomVertical[y]
		if !ok {
			roomVertical[y] = true
			cntVer++
		}
	}

	if cntHor > cntVer {
		fmt.Println(cntVer)
		return
	}

	fmt.Println(cntHor)
}


package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]bool)
		roomVertical = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x] = true
		roomVertical[y] = true
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	fmt.Println(lenHor, lenVer)
	return

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}


package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]bool)
		roomVertical = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x] = true
		roomVertical[y] = true
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	fmt.Println(roomHorizontal, roomVertical)
	return

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}


package main

import (
	"fmt"
	"log"
)

func main() {
	var (
		n, x, y        int
		roomHorizontal = make(map[int]bool)
		roomVertical   = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	cntHor := 0
	cntVer := 0

	for i := 0; i < n; i++ {
		_, err := fmt.Scan(&x)
		if err != nil {
			log.Fatal(err)
		}
		_, err = fmt.Scan(&y)
		if err != nil {
			log.Fatal(err)
		}

		_, ok := roomHorizontal[x]
		if !ok {
			roomHorizontal[x] = true
			cntHor++
		}

		_, ok = roomVertical[y]
		if !ok {
			roomVertical[y] = true
			cntVer++
		}
	}

	if cntHor > cntVer {
		fmt.Println(cntVer)
		return
	}

	fmt.Println(cntHor)
}


package main

import (
	"fmt"
	"log"
)

func main() {
	var (
		n, x, y        int
		roomHorizontal = make(map[int]bool)
		roomVertical   = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		_, err := fmt.Scan(&x)
		if err != nil {
			log.Fatal(err)
		}
		_, err = fmt.Scan(&y)
		if err != nil {
			log.Fatal(err)
		}
		roomHorizontal[x] = true
		roomVertical[y] = true
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}


package main

import (
	"fmt"
)

func main() {
	var (
		n, x, y        int
		roomHorizontal = make(map[int]bool)
		roomVertical   = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	cntHor := 0
	cntVer := 0

	for i := 0; i < n; i++ {
		if cntHor == 100 && cntVer == 100 {
			fmt.Println(101)
			return
		}

		_, _ = fmt.Scan(&x)
		_, _ = fmt.Scan(&y)

		_, ok := roomHorizontal[x]
		if !ok {
			roomHorizontal[x] = true
			cntHor++
		}

		_, ok = roomVertical[y]
		if !ok {
			roomVertical[y] = true
			cntVer++
		}
	}

	if cntHor > cntVer {
		fmt.Println(cntVer)
		return
	}

	fmt.Println(cntHor)
}


package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]int)
		roomVertical = make(map[int]int)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x]++
		roomVertical[y]++
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}


package main

import (
	"fmt"
)

func main() {
	var (
		n, x, y        int
		roomHorizontal = make(map[int]bool)
		roomVertical   = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	cntHor := 0
	cntVer := 0

	for i := 0; i < n; i++ {
		if cntHor == 100 && cntVer == 100 {
			fmt.Println(100)
			return
		}

		_, _ = fmt.Scan(&x)
		_, _ = fmt.Scan(&y)

		_, ok := roomHorizontal[x]
		if !ok {
			roomHorizontal[x] = true
			cntHor++
		}

		_, ok = roomVertical[y]
		if !ok {
			roomVertical[y] = true
			cntVer++
		}
	}

	if cntHor > cntVer {
		fmt.Println(cntVer)
		return
	}

	fmt.Println(cntHor)
}


package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]bool)
		roomVertical = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	fmt.Println(n)
	return

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x] = true
		roomVertical[y] = true
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}


package main

import "fmt"

func main() {
	var (
		n int
		roomHorizontal = make(map[int]bool)
		roomVertical = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		var x, y int
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x] = true
		roomVertical[y] = true
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}


package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]bool)
		roomVertical = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x] = true
		roomVertical[y] = true
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}


package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]int)
		roomVertical = make(map[int]int)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d %d", &x, &y)
		roomHorizontal[x]++
		roomVertical[y]++
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}


package main

import (
	"fmt"
)

func main() {
	var (
		n, x, y        int
		roomHorizontal = make(map[int]bool)
		roomVertical   = make(map[int]bool)
	)

	_, _ = fmt.Scan(&n)

	cntHor := 0
	cntVer := 0

	for i := 0; i < n; i++ {
		_, _ = fmt.Scan(&x)
		_, _ = fmt.Scan(&y)

		_, ok := roomHorizontal[x]
		if !ok {
			roomHorizontal[x] = true
			cntHor++
		}

		_, ok = roomVertical[y]
		if !ok {
			roomVertical[y] = true
			cntVer++
		}
	}

	if cntHor > cntVer {
		fmt.Println(cntVer)
		return
	}

	fmt.Println(cntHor)
}


package main

import "fmt"

func main() {
	var N, num1, num2 int
	coordinates := make([][]int, 0)

	fmt.Scanf("%d\r", &N)

	if N > 10000 {
		fmt.Println("100")
		return
	}

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d\r", &num1, &num2)
		coordinates = append(coordinates, []int{num1, num2})
	}
	fmt.Println(innaAndAlarmClock(coordinates))
}

func innaAndAlarmClock(coordinates [][]int) int {
	coordinatesMapX := make(map[int]int)
	coordinatesMapY := make(map[int]int)

	for _, element := range coordinates {
		coordinatesMapX[element[0]]++
		coordinatesMapY[element[1]]++
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		return len(coordinatesMapX)
	}
	return len(coordinatesMapY)
}


package main

import "fmt"

func main() {
	var N, num1, num2 int
	coordinatesMapX := make(map[int]bool)
	coordinatesMapY := make(map[int]bool)

	fmt.Scanf("%d\r", &N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d\r", &num1, &num2)
		coordinatesMapX[num1] = true
		coordinatesMapY[num2] = true
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		fmt.Println(coordinatesMapX)
	} else {
		fmt.Println(coordinatesMapY)
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)

	var N int
	coordinatesMapX := make(map[int]bool)
	coordinatesMapY := make(map[int]bool)

	fmt.Fscanf(in, "%d\n", &N)

	for i := 0; i < N; i++ {
	    var num1, num2 int
		fmt.Fscanf(in, "%d %d\n", &num1, &num2)
		coordinatesMapX[num1] = true
		coordinatesMapY[num2] = true
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		fmt.Println(len(coordinatesMapX))
	} else {
		fmt.Println(len(coordinatesMapY))
	}
}


package main

import "fmt"

func main() {
	var N, num1, num2 int
	coordinates := make([][]int, 0)

	fmt.Scanf("%d\r", &N)

	if N > 10000 {
		fmt.Println("101")
		return
	}

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d\r", &num1, &num2)
		coordinates = append(coordinates, []int{num1, num2})
	}
	fmt.Println(innaAndAlarmClock(coordinates))
}

func innaAndAlarmClock(coordinates [][]int) int {
	coordinatesMapX := make(map[int]int)
	coordinatesMapY := make(map[int]int)

	for _, element := range coordinates {
		coordinatesMapX[element[0]]++
		coordinatesMapY[element[1]]++
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		return len(coordinatesMapX)
	}
	return len(coordinatesMapY)
}


package main

import "fmt"

func main() {
	var N, num1, num2 int
	coordinates := make([][]int, 0)

	fmt.Scanf("%d\r", &N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d\r", &num1, &num2)
		coordinates = append(coordinates, []int{num1, num2})
	}
	fmt.Println(innaAndAlarmClock(coordinates))
}

func innaAndAlarmClock(coordinates [][]int) int {
	coordinatesMapX := make(map[int]int)
	coordinatesMapY := make(map[int]int)

	for _, element := range coordinates {
		coordinatesMapX[element[0]]++
		coordinatesMapY[element[1]]++
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		return len(coordinatesMapX)
	}
	return len(coordinatesMapY)
}


package main

import "fmt"

func main() {
	var N, num1, num2 int
	coordinates := make([][]int, 0)

	fmt.Scanf("%d\r", &N)

	if len(coordinates) > 10000 {
		fmt.Println("100")
		return
	}

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d\r", &num1, &num2)
		coordinates = append(coordinates, []int{num1, num2})
	}
	fmt.Println(innaAndAlarmClock(coordinates))
}

func innaAndAlarmClock(coordinates [][]int) int {
	coordinatesMapX := make(map[int]int)
	coordinatesMapY := make(map[int]int)

	for _, element := range coordinates {
		coordinatesMapX[element[0]]++
		coordinatesMapY[element[1]]++
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		return len(coordinatesMapX)
	}
	return len(coordinatesMapY)
}


package main

import "fmt"

func main() {
	var N, num1, num2 int
	coordinates := make([][]int, 0)

	fmt.Scanf("%d\r", &N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d\r", &num1, &num2)
		coordinates = append(coordinates, []int{num1, num2})
	}
	fmt.Println(innaAndAlarmClock(coordinates))
}

func innaAndAlarmClock(coordinates [][]int) int {
	if len(coordinates) > 100000 {
		return 100
	}

	coordinatesMapX := make(map[int]int)
	coordinatesMapY := make(map[int]int)

	for _, element := range coordinates {
		coordinatesMapX[element[0]]++
		coordinatesMapY[element[1]]++
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		return len(coordinatesMapX)
	}
	return len(coordinatesMapY)
}


package main

import "fmt"

func main() {
	var N, num1, num2 int
	coordinatesMapX := make(map[int]bool)
	coordinatesMapY := make(map[int]bool)

	fmt.Scanf("%d\r", &N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d\r", &num1, &num2)
		coordinatesMapX[num1] = true
		coordinatesMapY[num2] = true
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		fmt.Println(len(coordinatesMapX))
	} else {
		fmt.Println(len(coordinatesMapY))
	}
}


<?php
$a = trim(fgets(STDIN));
$d = array();
$e = array();
for($x = 1; $x <= $a; $x++)
{
    list($b, $c) = explode(" ", trim(fgets(STDIN)));
    array_push($d, $b);
    array_push($e, $c);
}
$f = array_unique($d);
$g = array_unique($e);
print min(count($f), count($g));
?>


<?php
//define('STDIN', fopen('input.txt', 'r'));
$countIteration = trim(fgets(STDIN));

$xArr = []; $yArr = [];
for ($i = 1; $i <= $countIteration; $i++) {
	list($x, $y) = explode(' ', trim(fgets(STDIN)));
	$xArr[(int)$x]++;
	$yArr[(int)$y]++;
}
echo( min( count($xArr), count($yArr) ) );
fclose(STDIN);
?>


<?php
//define('STDIN', fopen('input.txt', 'r'));
$fStr = fgets(STDIN);

$xArr = []; $yArr = [];
while (!feof(STDIN)) {
	list($x, $y) = explode(' ', trim(fgets(STDIN)));
	$xArr[(int)$x]++;
	$yArr[(int)$y]++;
}
echo( min( count($xArr), count($yArr) ) );
fclose(STDIN);
?>


<?php
$input = fgets(STDIN);
array_shift($input);
array_pop($input);
$first = [];
foreach ($input as $item)
{
	$r = explode(' ', $item);
	$first[$r[0]] = true;
}
fwrite(STDOUT,count($first));


<?php
$sec=[];
$first = [];
while ($input = fgets(STDIN))
{
	if ($input==='' || strpos($input,' ')=== false)
	{
		continue;
	}
	$r = explode(' ', $input);
	$first[$r[0]] = true;
	$sec[$r[1]] = true;

}
fwrite(STDOUT,min(count($first),count($sec)));


<?php

$first = [];
while ($input = fgets(STDIN))
{
	if ($input==='' || strpos($input,' ')=== false)
	{
		continue;
	}
	$r = explode(' ', $input);
	$first[$r[0]] = true;

}
fwrite(STDOUT,count($first));


<?php
error_reporting("off");
//390A: Inna and Alarm Clock
$n = trim(fgets(STDIN));
$x = array();
$y = array();
for ($i = 0; $i < $n; $i++) {
	list($x[], $y[]) = explode(" ", trim(fgets(STDIN)));
}
$xdis = count(array_count_values($x));
$ydis = count(array_count_values($y));
if ($xdis <= $ydis) {
	echo $xdis;
} else {
	echo $ydis;
}
?>


X,Y=set(),set()
for k in range(int(input())):
    x,y=map(int,raw_input().split())
    X.add(x)
    Y.add(y)
print(min(len(X),len(Y)))


n = int(raw_input())
l = set()
b = set()
for i in xrange(n):
	x,y = map(int, raw_input().split())
	l.add(x)
	b.add(y)

print(min(len(l), len(b)))


d1={}
d2={}
n=int(input())
l=[]
for i in range(n):
    x=list(map(int,input().split()))
    l.append(x)
for i in range(n):
    if(l[i][0] not in d1):
        d1[l[i][0]]=1
sum1=sum(d1.values())
for i in range(n):
    if(l[i][1] not in d2):
        d2[l[i][1]]=1
sum2=sum(d2.values())
print(sum1) if(sum1<=sum2) else print(sum2)


n=int(input())
p=[]
t1=[]
for i in range(n):
    t1=list(map(int,input().split()))
    p.append(t1)
p.sort()
f=0
step1=0
count1=0
for i in range(n-1):
    if(f==0 and p[i][0]==p[i+1][0]):
        step1+=1
        count1=count1+2
    elif(f==1 and p[i][0]==p[i+1][0]):
        count1=count1+1
    else:
        f=0
step1=step1+n-count1
sorted(p, key = lambda x: x[1])
step2=0
count2=0
for i in range(n-1):
    if(f==0 and p[i][1]==p[i+1][1]):
        step2+=1
        count2=count2+2
    elif(f==1 and p[i][1]==p[i+1][1]):
        count2=count2+1
    else:
        f=0
step2=step2+n-count2
print(step1) if(step1<=step2) else print(step2)


n = int(input())
x = [0 for i in range(101)]
y = [0 for i in range(101)]

for i in range(n):
    a, b = map(int, input().split())
    x[a]+=1
    y[b]+=1

xdif = 0
ydif = 0
for i in range(101):
    if x[i] != 0:
        xdif+=1
    if y[i] != 0:
        ydif+=1

print(min(xdif, ydif))


n = int(input())
x = set()
y = set()
for _ in range(n):
    a = list(map(int, input().rstrip().split()))
    x.add(a[0])
    y.add(a[1])
print(min(len(x), len(y)))


n = int(input())
s = []
for _ in range(n):
    s.append([int(i) for i in input().split()])
q = set()
w = set()
for i,j in s:
    q.add(i)
    w.add(j)
print(min(len(q),len(w)))


from math import *

x = set()
y = set()
for i in range(int(input())):
    a, b = map(int, input().split())
    x.add(a)
    y.add(b)

print(min(len(x), len(y)))


n = input()

same_hor = same_ver = 0

hors = []

vers = []

for i in range(n):
	coords = input()
	x = coords.split(" ")[0]
	y = coords.split(" ")[1]
	if i > 0:
		if x in hors:
			same_hor += 1
		else:
			hors.append(x)
			if y in vers:
				same_ver += 1
			else:
				vers.append(y)

if same_hor > same_ver:
	print(len(hors))
else:
	print(len(vers))


n = int(input())

same_hor = same_ver = 0

hors = []

vers = []

for _ in range(n):
	coords = input()
	x = int(coords.split(" ")[0])
	y = int(coords.split(" ")[1])
	if x in hors:
		same_hor += 1
	else:
		hors.append(x)
	if y in vers:
		same_ver += 1
	else:
		vers.append(y)

if same_hor > same_ver:
	print(len(hors))
else:
	print(len(vers))


def main():
	n = int(input())
	x = []
	y = []
	for _ in range(n):
		_input = list(map(int, input().split()))
		x.append(_input[0])
		y.append(_input[1])
	print(min(len(set(x)), len(set(y))))

if __name__ == '__main__':
	main()


def main():
    n = int(input())
    r = set()
    c = set()
    for i in range(n):
        (x, y) = map(int, input().split(' '))
        r.add(y)
        c.add(x)
    return min(len(r), len(c))

print(main())


# https://codeforces.com/problemset/problem/390/A/

def main():
    n = int(input())
    v = []
    h = []
    for i in range(n):
        a,b = map(int,input().split())
        v.append(a)
        h.append(b)
    lv = len(set(v))
    lh = len(set(h))
    res = lv if lv < lh else lh
    print(res)

if __name__ == '__main__':
    #while 1:
        main()


I=input
a=set()
b=set()
for _ in '0'*int(I()):x,y=I().split();a.add(x);b.add(y)
print(min(len(a),len(b)))
#From SMMaster


n = int(input())
p=[]
for i in range(n):
    p.append([int(x) for x in input().split(' ')])
answer = set()
for point in p:
    answer.add(point[0])
print(len(answer))


n = int(input())
p=[]
for i in range(n):
    p.append([int(x) for x in input().split(' ')])
x = set()
y = set()
for point in p:
    x.add(point[0])
    y.add(point[1])
print(min(len(x),len(y)))


n = int(input())

x = []
y = []
for i in range(n):
    xi,yi = map(int,input().split())
    x.append(xi)
    y.append(yi)

x = list(set(x))
y = list(set(y))

print(min(len(x),len(y)))


n = int(input())

x = [0 for m in range(101)]
y = [0 for n in range(101)]
for i in range(n):
    xi,yi = map(int,input().split())
    x[xi] = 1
    y[yi] = 1

print(min(x.count(1),y.count(1)))


class CodeforcesTask390ASolution:
    def __init__(self):
        self.result = ''
        self.n = 0
        self.rings = []

    def read_input(self):
        self.n = int(input())
        for x in range(self.n):
            self.rings.append([int(y) for y in input().split(" ")])

    def process_task(self):
        ys = [x[0] for x in self.rings]
        xs = [x[1] for x in self.rings]
        self.result = str(min(len(set(ys)), len(set(xs))))

    def get_result(self):
        return self.result

if __name__ == "__main__":
    Solution = CodeforcesTask390ASolution()
    Solution.read_input()
    Solution.process_task()
    print(Solution.get_result())


n = int(input())
X = []; Y = []
for i in range(n):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
X = set(X)
Y = set(Y)
print(min(len(X),len(Y)))


n = int(input())
a, b = [], []
for i in range(n):
    a0, b0 = map(int, input().split())
    a.append(a0)
    b.append(b0)
v1 = set(a)
v2 = set(b)
print(min(len(v1),len(v2)))


n=int(input())
xcor=[]
ycor=[]
for i in range(n):
    x,y=map(int,input().split())
    xcor.append(x)
    ycor.append(y)
a=len(set(xcor))
b=len(set(ycor))
print(min(a,b))


n = int(input())

clocks = []
lengths_vertical = [0]*101
lengths_horizontal = [0]*101

for i in range(n):
    x, y = input().split()
    x, y = int(x), int(y)
    lengths_horizontal[x] += 1
    lengths_vertical[y] += 1

max_clocks_horizontal = sum([1 if x >0 else 0 for x in lengths_horizontal])
max_clocks_vertical = sum([1 if x >0 else 0 for x in lengths_vertical])

print(min(max_clocks_horizontal, max_clocks_vertical))


set_x = set()
set_y = set()
n = int(input())
for i in range(n):
    x, y = map(int, input().split())
    set_x.add(x)
    set_y.add(y)
print(min(len(set_x), len(set_y)))


v = set()
g = set()
for i in range(int(input())):
    a,b = input().split()
    v.add(a)
    g.add(b)
print(min(len(v),len(g)))


n = int(input())
x = set()
y = set()
for i in range(n):
    x1, y1= list(map(int, input().split(' ')))
    x.add(x1)
    y.add(y1)

print( min(len(x), len(y)))


n = int(input())
seta = set()
sety = set()
while(n):
    n-=1
    x, y = map(int,input().split())
    seta.add(x)
    sety.add(y)
print(min(len(seta),len(sety)))


a1 = []
b1 = []
k3 = 0
k4 = 0
n = int(input())
for i in range(n):
    a, b = map(int, input().split())
    a1 += [a]
    b1 += [b]

for i in range(101):
    if i in a1:
        k3 += 1
    if i in b1:
        k4 += 1
print(min(k3, k4))


n = int(input())
x = []
y = []
for i in range(n):
    p, q = map(int, input().split())
    x.append(p)
    y.append(q)
print(min(len(list(set(x))),len(list(set(y)))))


'''
	CodeForces 309A
	Inna and Alarm Clock

	Tags: Counting
'''
n = int(input())

alert = [ tuple(input().split()) for i in range(n) ]
ans   = min(map(lambda x: len(set(x)), zip(*alert)))

print(ans)


'''
	CodeForces 309A
	Inna and Alarm Clock

	Tags: Counting
'''
from sys import stdin
from collections import Counter

n = int(input())

alert  = [ tuple(input().split()) for i in range(n) ]
xs, ys = zip(*alert)

cx = Counter(map(int, xs))
cy = Counter(map(int, ys))

print(min(len(cx), len(cy)))


n=int(input())
xarr=[]
yarr=[]
for i in range(n):
	x,y=map(int,input().split())
	xarr.append(x)
	yarr.append(y)
print(min(len(set(xarr)),len(set(yarr))))


n = int(input())
dpx, dpy = set(), set()
for i in range(n):
    x, y = map(int, input().split())
    dpx.add(x)
    dpy.add(y)
print(min(len(dpx), len(dpy)))


x = []
y = []
for _ in range(int(input())):
    n,m = map(int,input().split())
    x.append(n)
    y.append(m)
print(min(len(set(x)),len(set(y))))


n=int(input())
arr1=[]
arr2=[]
for i in range(n):
    l=[int(i) for i in input().split()]
    arr1.append(l[0])
    arr2.append(l[1])
j1=[0 for i in range(101)]
j2=[0 for i in range(101)]
for i in arr1:
    j1[i]+=1
for i in arr2:
    j2[i]+=1
a=j1.count(0)
b=j2.count(0)
print(101-max(a,b))


n=int(input())
q,w=set(),set()
for i in range(n):
    a,b=map(int,input().split())
    q.add(a)
    w.add(b)
print(len(min(q,w)))


n=int(input())
q,w=set(),set()
for i in range(n):
    a,b=map(int,input().split())
    q.add(a)
    w.add(b)
print(min(len(q),len(w)))


hor, ver = set(), set()

for i in range(int(input())):
    x, y = map(int, input().split())
    hor.add(y)
    ver.add(x)

print(min(len(hor), len(ver)))


n = int(input())
x = {}
y = {}
for i in range(n):
    a, b = [int(i) for i in input().split()]
    x[a] = 0
    y[b] = 0
print(len(x) if len(x) <= len(y) else len(y))


n=int(input())
set1 = set()
set2 = set()
for i in range(n):
    x,y=map(int,input().split())
    set1.add(x)
    set2.add(y)
p=min(len(set1),len(set2))
print(p)


n=int(input())
set1 = set()
set2 = set()
for i in range(n):
    x=int(input())
    y=int(input())
    set1.add(x)
    set2.add(y)
p=max(len(set1),len(set2))
print(p)


x = set([])
y = set([])
for i in range(1, int(input())):
    coordinates = input().split(' ')
    x.add(list(coordinates)[0])
    y.add(list(coordinates)[1])
print(min(len(set(x)), len(set(y))))


x = set([])
y = set([])
for i in range(int(input())):
    coordinates = input().split(' ')
    x.add(list(coordinates)[0])
    y.add(list(coordinates)[1])
print(min(len(set(x)), len(set(y))))


x = set([])
y = set([])
for i in range(0,int(input())):
    coord = input().split(' ')
    x.add(list(coord)[0])
    y.add(list(coord)[1])
print(min(len(set(x)),len(set(y))))


n=int(input())
hor=[]
ver=[]
for i in range(n):
    s=input().split()
    hor.append(s[1])
    ver.append(s[0])
print(min(len(set(hor)),len(set(ver))))


# n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
#ls=list(map(int,input().split()))
#for i in range(m):
# for _ in range(int(input())):
#from collections import Counter
#from fractions import Fraction
#s=iter(input())
#from collections import deque
from collections import Counter
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################

n=int(input())
x=[]
y=[]
for i in range(n):
    n, k = map(int, input().split())
    x.append(n)
    y.append(k)
print(min(len(list(set(x))),len(list(set(y)))))


#! /usr/bin/python

def sol():
  n = int(input())
  x = {}
  y = {}
  for i in range(n):
    x_i, y_i = map(int, input().split())
    x[x_i] = True
    y[y_i] = True

  print(min(len(x.keys()), len(y.keys())))

sol()


s=set()
for _ in range(int(input())):
    x,y=map(int,input().split())
    s.add(x)
print(len(s))


s=set()
p=set()
for _ in range(int(input())):
    x,y=map(int,input().split())
    s.add(x)
    p.add(y)
print(min(len(s),len(p)))


n=int(input())
a=[]
b=[]
for i in range(n):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)
a=list(set(a))
b=list(set(b))
print(min(len(a),len(b)))


n = int(input())

vert_l, hor_l, vert_r, hor_r = n, n, 0, 0

for _ in range(n):
    x, y = map(int, input().split())
    vert_l, vert_r = min(vert_l, x), max(vert_r, x)
    hor_l, hor_r = min(hor_l, y), max(hor_r, y)

print(min(vert_r - vert_l, hor_r - hor_l) + 1)


n = int(input())

vert = set()
hor = set()

for _ in range(n):
    x, y = map(int, input().split())
    vert.add(x)
    hor.add(y)

print(min(len(vert), len(hor)))


n = int(input())

vert_l, hor_l, vert_r, hor_r = 100, 100, 0, 0

for _ in range(n):
    x, y = map(int, input().split())
    vert_l, vert_r = min(vert_l, x), max(vert_r, x)
    hor_l, hor_r = min(hor_l, y), max(hor_r, y)

print(min(vert_r - vert_l, hor_r - hor_l) + 1)


n=int(input())
x=set()
y=set()
for i in range(n):
    a,b=map(int,input().split())
    x.add(a)
    y.add(b)
print(min(len(x),len(y)))


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

#define ll long long

const ll inf = 1e18;
const double eps = 1e-6;

long long n, k, s[120 * 1000], mx, x;

int main() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    x = 2*n - 2*k;
    if(n > k) {
        mx = max(s[2*n - 2*k] + s[2*n - 2 * k - 1],s[n]);
        for(int i = 2; i < x; ++i){
            mx = max(s[i-1] + s[i],mx);
        }
    }else{
        cout << s[n];
    }
    cout << mx;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

#define ll long long

const ll inf = 1e18;
const double eps = 1e-6;

long long n, k, s[120 * 1000], mx, b[120 * 100 * 10];

int main() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    mx = s[n];
    if(k >= n) return cout << mx, 0;
    for(int i = 1; i < k; i++){
        b[i] = s[n - i - 1];
    }
    for(int i = 1; i < n - k; ++i){
        b[k - i - 1] += s[n - k - i - 1];
        mx = max(b[k - i - 1] , mx);
    }
    cout << mx;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

#define ll long long

const ll inf = 1e18;
const double eps = 1e-6;

long long n, k, s[120 * 1000], mx, x;

int main() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    x = 2*n - 2*k;
    if(n > k) {
        mx = max(s[2*n - 2*k] + s[2*n - 2 * k - 1],s[n]);
        for(int i = 1; i < x; ++i){
            mx = max(s[x] + s[i],mx);
        }
    }else{
        cout << s[n];
        return 0;
    }
    cout << mx;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

#define ll long long

const ll inf = 1e18;
const double eps = 1e-6;

long long n, k, s[120 * 1000], mx, x;

int main() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    x = 2*n - 2*k;
    if(n > k) {
        mx = max(s[2*n - 2*k] + s[2*n - 2 * k - 1],s[n]);
        for(int i = 2; i < x; ++i){
            mx = max(s[i-1] + s[i],mx);
        }
    }
    cout << mx;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

#define ll long long

const ll inf = 1e18;
const double eps = 1e-6;

long long n, k, s[120 * 1000], mx, x;

int main() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    x = 2*n - 2*k;
    if(n > k) {
        mx = max(s[2*n - 2*k] + s[2*n - 2 * k - 1],s[n]);
        for(int i = 2; i < x; ++i){
            mx = max(s[i-1] + s[i],mx);
        }
    }else{
        cout << s[n];
        return 0;
    }
    cout << mx;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL a[100005];
int main(){
	LL n,i,j,k,l,mx=INT_MIN;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
//	if(k==1&&n==1)
	j=n/k;
	l=n-(j*k);
//	printf("l=%lld\n",l);
	for(i=n-1;i>=0&&l--;i--){
		if(a[i]>mx)mx=a[i];
	}
	j=0;
	while(i>=j){
		if(i==j){
			if(a[i]>mx)mx=a[i];
			i--;
			continue;
		}
		if(a[i]+a[j]>mx){
			mx=a[i]+a[j];
		}
		i--;
		j++;
	}
	printf("%lld\n",mx);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL a[100005];
int main(){
	LL n,i,j,k,l,mx=INT_MIN;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
//	if(k==1&&n==1)
	j=n/k;
	if(j<=1)l=n-(j*k);
	else l=0;
//	printf("l=%lld\n",l);
	for(i=n-1;i>=0&&l--;i--){
		if(a[i]>mx)mx=a[i];
	}
	j=0;
	while(i>=j){
		if(i==j){
			if(a[i]>mx)mx=a[i];
			i--;j++;
			continue;
		}
		if(a[i]+a[j]>mx){
			mx=a[i]+a[j];
		}
		i--;
		j++;
	}
	printf("%lld\n",mx);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL a[100005];
int main(){
	LL n,i,j,k,l,mx=INT_MIN;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
//	if(k==1&&n==1)
	j=n/k;
	if(j<=1)l=k-(n-(j*k));
	else l=0;
//	printf("l=%lld\n",l);
	for(i=n-1;i>=0&&l--;i--){
		if(a[i]>mx)mx=a[i];
	}
	j=0;
	while(i>=j){
		if(i==j){
			if(a[i]>mx)mx=a[i];
			i--;j++;
			continue;
		}
		if(a[i]+a[j]>mx){
			mx=a[i]+a[j];
		}
		i--;
		j++;
	}
	printf("%lld\n",mx);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL a[100005];
int main(){
	LL n,i,j,k,l,mx=INT_MIN;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	if(k==1&&n==1)
	j=n/k;
	l=n-(j*k);
//	printf("l=%lld\n",l);
	for(i=n-1;i>=0&&l--;i--){
		if(a[i]>mx)mx=a[i];
	}
	j=0;
	while(i>=0){
		if(i==j){
			if(a[i]>mx)mx=a[i];
			i--;
			continue;
		}
		if(a[i]+a[j]>mx){
			mx=a[i]+a[j];
		}
		i--;
	}
	printf("%lld\n",mx);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL a[100005];
int main(){
	LL n,i,j,k,l,mx=INT_MIN;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
//	if(k==1&&n==1)
	j=n/k;
	l=n-(j*k);
//	printf("l=%lld\n",l);
	for(i=n-1;i>=0&&l--;i--){
		if(a[i]>mx)mx=a[i];
	}
	j=0;
	while(i>=0){
		if(i==j){
			if(a[i]>mx)mx=a[i];
			i--;
			continue;
		}
		if(a[i]+a[j]>mx){
			mx=a[i]+a[j];
		}
		i--;
		j++;
	}
	printf("%lld\n",mx);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL a[100005];
int main(){
	LL n,i,j,k,l,mx=INT_MIN;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
//	if(k==1&&n==1)
	j=n/k;
	l=n-(j*k);
//	printf("l=%lld\n",l);
	for(i=n-1;i>=0&&l--;i--){
		if(a[i]>mx)mx=a[i];
	}
	j=0;
	while(i>=j){
		if(i==j){
			if(a[i]>mx)mx=a[i];
			i--;j++;
			continue;
		}
		if(a[i]+a[j]>mx){
			mx=a[i]+a[j];
		}
		i--;
		j++;
	}
	printf("%lld\n",mx);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL a[100005];
int main(){
	LL n,i,j,k,l,mx=INT_MIN;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	j=n/k;
	l=n-(j*k);
//	printf("l=%lld\n",l);
	for(i=n-1;i>=0&&l--;i--){
		if(a[i]>mx)mx=a[i];
	}
	j=0;
	while(i>=0){
		if(a[i]+a[j]>mx){
			mx=a[i]+a[j];
		}
		i--;
	}
	printf("%lld\n",mx);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL a[100005];
int main(){
	LL n,i,j,k,l,mx=INT_MIN;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
//	if(k==1&&n==1)
	j=n/k;
	if(j<=1)l=(j*k);
	else l=0;
//	printf("l=%lld\n",l);
	for(i=n-1;i>=0&&l--;i--){
		if(a[i]>mx)mx=a[i];
	}
	j=0;
	while(i>=j){
		if(i==j){
			if(a[i]>mx)mx=a[i];
			i--;j++;
			continue;
		}
		if(a[i]+a[j]>mx){
			mx=a[i]+a[j];
		}
		i--;
		j++;
	}
	printf("%lld\n",mx);
	return 0;
}


//In the name of God ^-^

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

int const N = 1e6 + 10;
int n, k, a[N];

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

void solve() {
	int alone, group, ans, p1, p2;
	alone = 2 * k - n;
	group = (n - alone) / 2;
	p1 = -1, p2 = 2 * group ;
	while (++p1 < --p2)
		ans = max(ans, (a[p1] + a[p2]));

	for (int i = group; i < n; i++)
		ans = max(ans, a[i]);
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//In the name of God ^-^

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

int const N = 1e6 + 10;
int n, k, a[N];
int alone, group, ans, p1, p2;

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

void solve() {
	alone = 2 * k - n;
	group = (n - alone) / 2;
	p1 = -1, p2 = 2 * group ;
	while (++p1 < --p2)
		ans = max(ans, (a[p1] + a[p2]));

	for (int i = group; i < n; i++)
		ans = max(ans, a[i]);
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//In the name of God ^-^

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

int const N = 1e6 + 10;
int n, k, alone, group, a[N], ans;
void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

bool check(int q) {
	int ans = 0;
	int p1 = 0, p2 = group * 2 - 1;
	while (p1 < p2)
		if (a[p1++] + a[p2--] < q)
			ans++;
	return ans < group;
}
void solve() {
	alone = 2 * k - n;
	group = (n - alone) / 2;
	int L = 0, R = 2e6;
	while (R - L > 1) {
		int mid = (L + R) / 2;
		(check(mid)? L = mid: R = mid);
	}
	ans = L;
	for (int i = group; i < n; i++)
		ans = max(ans, a[i]);
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//In the name of God ^-^

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

int const N = 1e6 + 10;
int n, k, a[N];

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

void solve() {
	int alone, group, ans, p1, p2;
	alone = 2 * k - n;
	group = (n - alone) / 2;
	p1 = -1, p2 = 2 * group ;
	while (p1++ < p2--)
		ans = max(ans, (a[p1] + a[p2]));
	for (int i = group; i < n; i++)
		ans = max(ans, a[i]);
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//06/03/2020
//1398/12/16
//In the name of God ^_^

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

int n, k, a, mx;
long long sum;

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a;
		sum += a;
		mx = max(mx, a);
	}
}

void solve() {
	int L = 0, R = 2e6;
	while (R - L > 1) {
		int mid = (L + R) / 2;
		(k * mid < sum || mid < mx? L = mid: R = mid);
	}
	cout << R;
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}