#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int h,w,d;
char buf[1005][1005];
vector<pi> rat;
int cost[1005][1005],idef[1005][1005],idef2[1005][1005],idef3[1005][1005];

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int cnt1=1,cnt2=1;
pi bfs2(int sy,int sx,int id,int id_){
	queue<pi> q;q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef3[sy][sx]=id;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef3[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef3[py][px]=id;
			q.push(mp(py,px));
		}
	}
	int fail=0;
	REP(i,rat.size()){
		if(idef[rat[i].fr][rat[i].sc]!=id_ && idef3[rat[i].fr][rat[i].sc]!=id){
			fail=1;
		}
	}
	if(fail) return mp(-1,-1);
	else return mp(sy,sx);
}

pi bfs(int sy,int sx,int id,int id_){
	queue<pi> q;q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef2[sy][sx]=id;

	vector<pi> ok;
	while(!q.empty()){
		pi cur=q.front();q.pop();
		ok.pb(cur);
		if(cost[cur.fr][cur.sc]>d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef2[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef2[py][px]=id;
			q.push(mp(py,px));
		}
	}
	REP(i,ok.size()){
		pi a=bfs2(ok[i].fr,ok[i].sc,cnt2++,id_);
		if(a.fr!=-1) return a;
	}
	return mp(-1,-1);
}

pi solve(int sy,int sx,int id){
	queue<pi> q;
	q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef[sy][sx]=id;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef[py][px]=id;
			q.push(mp(py,px));
		}
	}

	REP(i,rat.size()) if(idef[rat[i].fr][rat[i].sc]!=id){
		return bfs(rat[i].fr,rat[i].sc,cnt1++,id);
	}
}

int main(){
	scanf("%d%d%d",&h,&w,&d);
	REP(i,h) scanf("%s",buf[i]);
	REP(i,h) REP(j,w) if(buf[i][j]=='R') rat.pb(mp(i,j));

	memset(cost,-1,sizeof(cost));
	queue<pi> q;q.push(rat[0]);
	cost[rat[0].fr][rat[0].sc]=0;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || cost[py][px]!=-1 ||
				buf[py][px]=='X') continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			q.push(mp(py,px));
		}
	}
	vector<pi> st;
	REP(i,h) REP(j,w) if(cost[i][j]<=d && cost[i][j]!=-1){
		st.pb(mp(i,j));
	}
	memset(cost,-1,sizeof(cost));
	memset(idef,-1,sizeof(idef));

	REP(i,st.size()){
		pi p=solve(st[i].fr,st[i].sc,i);
		if(p.fr!=-1){
			printf("%d %d %d %d\n",st[i].fr+1,st[i].sc+1,p.fr+1,p.sc+1);
			return 0;
		}
	}
	puts("-1");

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int h,w,d;
char buf[1005][1005];
vector<pi> rat;
int cost[1005][1005],idef[1005][1005],idef2[1005][1005],idef3[1005][1005];

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

pi q[1000005];

int cnt1=1,cnt2=1;
pi bfs2(int sy,int sx,int id,int id_){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef3[sy][sx]=id;

	while(st<en){
		pi cur=q[st++];
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef3[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef3[py][px]=id;
			q[en++]=mp(py,px);
		}
	}

	int fail=0;
	REP(i,rat.size()) if(idef[rat[i].fr][rat[i].sc]!=id_ && idef3[rat[i].fr][rat[i].sc]!=id){
		fail=1;
		return mp(-1,-1);
	}
	return mp(sy,sx);
}

pi bfs(int sy,int sx,int id,int id_){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef2[sy][sx]=id;

	vector<pi> ok;
	while(st<en){
		pi cur=q[st++];
		if(cost[cur.fr][cur.sc]>d) break;
		ok.pb(cur);
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef2[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef2[py][px]=id;
			q[en++]=mp(py,px);
		}
	}
	REP(i,ok.size()){
		pi a=bfs2(ok[i].fr,ok[i].sc,cnt2++,id_);
		if(a.fr!=-1) return a;
	}
	return mp(-1,-1);
}

pi solve(int sy,int sx,int id){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef[sy][sx]=id;

	while(st<en){
		pi cur=q[st++];
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef[py][px]=id;
			q[en++]=mp(py,px);
		}
	}

	REP(i,rat.size()) if(idef[rat[i].fr][rat[i].sc]!=id){
		return bfs(rat[i].fr,rat[i].sc,cnt1++,id);
	}
	REP(i,h) REP(j,w) if(buf[i][j]!='X' && mp(i,j)!=mp(sy,sx)) return mp(i,j);
}

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&h,&w,&d);
	h=w=1000;
	d=8;
	REP(i,h) REP(j,w) buf[i][j]='R';
	//REP(i,h) scanf("%s",buf[i]);
	REP(i,h) REP(j,w) if(buf[i][j]=='R') rat.pb(mp(i,j));

	memset(cost,-1,sizeof(cost));

	int st=0,en=0;
	q[en++]=rat[0];
	cost[rat[0].fr][rat[0].sc]=0;
	while(st<en){
		pi cur=q[st++];
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || cost[py][px]!=-1 ||
				buf[py][px]=='X') continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			q[en++]=mp(py,px);
		}
	}
	vector<pi> st2;
	REP(i,h) REP(j,w) if(cost[i][j]<=d && cost[i][j]!=-1){
		st2.pb(mp(i,j));
	}
	memset(cost,-1,sizeof(cost));
	memset(idef,-1,sizeof(idef));

	REP(i,st2.size()){
		pi p=solve(st2[i].fr,st2[i].sc,i);
		if(p.fr!=-1){
			printf("%d %d %d %d\n",st2[i].fr+1,st2[i].sc+1,p.fr+1,p.sc+1);
			return 0;
		}
	}
	puts("-1");

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int h,w,d;
char buf[1005][1005];
vector<pi> rat;
int cost[1005][1005],idef[1005][1005],idef2[1005][1005],idef3[1005][1005];

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

queue<pi> q;

int cnt1=1,cnt2=1;
pi bfs2(int sy,int sx,int id,int id_){
	q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef3[sy][sx]=id;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef3[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef3[py][px]=id;
			q.push(mp(py,px));
		}
	}

	while(!q.empty()) q.pop();
	int fail=0;
	REP(i,rat.size()){
		if(idef[rat[i].fr][rat[i].sc]!=id_ && idef3[rat[i].fr][rat[i].sc]!=id){
			fail=1;
		}
	}
	if(fail) return mp(-1,-1);
	else return mp(sy,sx);
}

pi bfs(int sy,int sx,int id,int id_){
	q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef2[sy][sx]=id;

	vector<pi> ok;
	while(!q.empty()){
		pi cur=q.front();q.pop();
		ok.pb(cur);
		if(cost[cur.fr][cur.sc]>d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef2[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef2[py][px]=id;
			q.push(mp(py,px));
		}
	}

	while(!q.empty()) q.pop();
	REP(i,ok.size()){
		pi a=bfs2(ok[i].fr,ok[i].sc,cnt2++,id_);
		if(a.fr!=-1) return a;
	}
	return mp(-1,-1);
}

pi solve(int sy,int sx,int id){
	q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef[sy][sx]=id;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef[py][px]=id;
			q.push(mp(py,px));
		}
	}
	while(!q.empty()) q.pop();

	REP(i,rat.size()) if(idef[rat[i].fr][rat[i].sc]!=id){
		return bfs(rat[i].fr,rat[i].sc,cnt1++,id);
	}
	REP(i,h) REP(j,w) if(buf[i][j]!='X' && mp(i,j)!=mp(sy,sx)) return mp(i,j);
}

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&h,&w,&d);
	REP(i,h) scanf("%s",buf[i]);
	REP(i,h) REP(j,w) if(buf[i][j]=='R') rat.pb(mp(i,j));

	memset(cost,-1,sizeof(cost));

	q.push(rat[0]);
	cost[rat[0].fr][rat[0].sc]=0;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || cost[py][px]!=-1 ||
				buf[py][px]=='X') continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			q.push(mp(py,px));
		}
	}
	vector<pi> st;
	REP(i,h) REP(j,w) if(cost[i][j]<=d && cost[i][j]!=-1){
		st.pb(mp(i,j));
	}
	memset(cost,-1,sizeof(cost));
	memset(idef,-1,sizeof(idef));

	REP(i,st.size()){
		pi p=solve(st[i].fr,st[i].sc,i);
		if(p.fr!=-1){
			printf("%d %d %d %d\n",st[i].fr+1,st[i].sc+1,p.fr+1,p.sc+1);
			return 0;
		}
	}
	puts("-1");

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int h,w,d;
char buf[1005][1005];
vector<pi> rat;
int cost[1005][1005],idef[1005][1005],idef2[1005][1005],idef3[1005][1005];

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int cnt1=1,cnt2=1;
pi bfs2(int sy,int sx,int id,int id_){
	queue<pi> q;q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef3[sy][sx]=id;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef3[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef3[py][px]=id;
			q.push(mp(py,px));
		}
	}
	int fail=0;
	REP(i,rat.size()){
		if(idef[rat[i].fr][rat[i].sc]!=id_ && idef3[rat[i].fr][rat[i].sc]!=id){
			fail=1;
		}
	}
	if(fail) return mp(-1,-1);
	else return mp(sy,sx);
}

pi bfs(int sy,int sx,int id,int id_){
	queue<pi> q;q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef2[sy][sx]=id;

	vector<pi> ok;
	while(!q.empty()){
		pi cur=q.front();q.pop();
		ok.pb(cur);
		if(cost[cur.fr][cur.sc]>d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef2[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef2[py][px]=id;
			q.push(mp(py,px));
		}
	}
	REP(i,ok.size()){
		pi a=bfs2(ok[i].fr,ok[i].sc,cnt2++,id_);
		if(a.fr!=-1) return a;
	}
	return mp(-1,-1);
}

pi solve(int sy,int sx,int id){
	queue<pi> q;
	q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef[sy][sx]=id;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef[py][px]=id;
			q.push(mp(py,px));
		}
	}

	REP(i,rat.size()) if(idef[rat[i].fr][rat[i].sc]!=id){
		return bfs(rat[i].fr,rat[i].sc,cnt1++,id);
	}
	REP(i,h) REP(j,w) if(buf[i][j]!='X' && mp(i,j)!=mp(sy,sx)) return mp(i,j);
}

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&h,&w,&d);
	REP(i,h) scanf("%s",buf[i]);
	REP(i,h) REP(j,w) if(buf[i][j]=='R') rat.pb(mp(i,j));

	memset(cost,-1,sizeof(cost));
	queue<pi> q;q.push(rat[0]);
	cost[rat[0].fr][rat[0].sc]=0;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || cost[py][px]!=-1 ||
				buf[py][px]=='X') continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			q.push(mp(py,px));
		}
	}
	vector<pi> st;
	REP(i,h) REP(j,w) if(cost[i][j]<=d && cost[i][j]!=-1){
		st.pb(mp(i,j));
	}
	memset(cost,-1,sizeof(cost));
	memset(idef,-1,sizeof(idef));

	REP(i,st.size()){
		pi p=solve(st[i].fr,st[i].sc,i);
		if(p.fr!=-1){
			printf("%d %d %d %d\n",st[i].fr+1,st[i].sc+1,p.fr+1,p.sc+1);
			return 0;
		}
	}
	puts("-1");

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int h,w,d;
char buf[1005][1005];
vector<pi> rat;
int cost[1005][1005],idef[1005][1005],idef2[1005][1005],idef3[1005][1005];

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

pi q[1000005];

int cnt1=1,cnt2=1;
pi bfs2(int sy,int sx,int id,int id_){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef3[sy][sx]=id;

	while(st<en){
		pi cur=q[st++];
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef3[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef3[py][px]=id;
			q[en++]=mp(py,px);
		}
	}

	int fail=0;
	REP(i,rat.size()){
		if(idef[rat[i].fr][rat[i].sc]!=id_ && idef3[rat[i].fr][rat[i].sc]!=id){
			fail=1;
		}
	}
	if(fail) return mp(-1,-1);
	else return mp(sy,sx);
}

pi bfs(int sy,int sx,int id,int id_){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef2[sy][sx]=id;

	vector<pi> ok;
	while(st<en){
		pi cur=q[st++];
		if(cost[cur.fr][cur.sc]>d) break;
		ok.pb(cur);
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef2[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef2[py][px]=id;
			q[en++]=mp(py,px);
		}
	}

	REP(i,ok.size()){
		pi a=bfs2(ok[i].fr,ok[i].sc,cnt2++,id_);
		if(a.fr!=-1) return a;
	}
	return mp(-1,-1);
}

pi solve(int sy,int sx,int id){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef[sy][sx]=id;

	while(st<en){
		pi cur=q[st++];
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef[py][px]=id;
			q[en++]=mp(py,px);
		}
	}

	REP(i,rat.size()) if(idef[rat[i].fr][rat[i].sc]!=id){
		return bfs(rat[i].fr,rat[i].sc,cnt1++,id);
	}
	REP(i,h) REP(j,w) if(buf[i][j]!='X' && mp(i,j)!=mp(sy,sx)) return mp(i,j);
}

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&h,&w,&d);
	REP(i,h) scanf("%s",buf[i]);
	REP(i,h) REP(j,w) if(buf[i][j]=='R') rat.pb(mp(i,j));

	memset(cost,-1,sizeof(cost));

	int st=0,en=0;
	q[en++]=rat[0];
	cost[rat[0].fr][rat[0].sc]=0;
	while(st<en){
		pi cur=q[st++];
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || cost[py][px]!=-1 ||
				buf[py][px]=='X') continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			q[en++]=mp(py,px);
		}
	}
	vector<pi> st2;
	REP(i,h) REP(j,w) if(cost[i][j]<=d && cost[i][j]!=-1){
		st2.pb(mp(i,j));
	}
	memset(cost,-1,sizeof(cost));
	memset(idef,-1,sizeof(idef));

	REP(i,st2.size()){
		pi p=solve(st2[i].fr,st2[i].sc,i);
		if(p.fr!=-1){
			printf("%d %d %d %d\n",st2[i].fr+1,st2[i].sc+1,p.fr+1,p.sc+1);
			return 0;
		}
	}
	puts("-1");

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int h,w,d;
char buf[1005][1005];
vector<pi> rat;
int cost[1005][1005],idef[1005][1005],idef2[1005][1005],idef3[1005][1005];

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

pi q[1000005];

int cnt1=1,cnt2=1;
pi bfs2(int sy,int sx,int id,int id_){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef3[sy][sx]=id;

	while(st<en){
		pi cur=q[st++];
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef3[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef3[py][px]=id;
			q[en++]=mp(py,px);
		}
	}

	int fail=0;
	REP(i,rat.size()) if(idef[rat[i].fr][rat[i].sc]!=id_ && idef3[rat[i].fr][rat[i].sc]!=id){
		fail=1;
		return mp(-1,-1);
	}
	return mp(sy,sx);
}

pi bfs(int sy,int sx,int id,int id_){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef2[sy][sx]=id;

	vector<pi> ok;
	while(st<en){
		pi cur=q[st++];
		if(cost[cur.fr][cur.sc]>d) break;
		ok.pb(cur);
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef2[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef2[py][px]=id;
			q[en++]=mp(py,px);
		}
	}
	REP(i,ok.size()){
		pi a=bfs2(ok[i].fr,ok[i].sc,cnt2++,id_);
		if(a.fr!=-1) return a;
	}
	return mp(-1,-1);
}

pi solve(int sy,int sx,int id){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef[sy][sx]=id;

	while(st<en){
		pi cur=q[st++];
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef[py][px]=id;
			q[en++]=mp(py,px);
		}
	}

	REP(i,rat.size()) if(idef[rat[i].fr][rat[i].sc]!=id){
		return bfs(rat[i].fr,rat[i].sc,cnt1++,id);
	}
	REP(i,h) REP(j,w) if(buf[i][j]!='X' && mp(i,j)!=mp(sy,sx)) return mp(i,j);
}

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&h,&w,&d);
	REP(i,h) scanf("%s",buf[i]);
	REP(i,h) REP(j,w) if(buf[i][j]=='R') rat.pb(mp(i,j));

	memset(cost,-1,sizeof(cost));

	int st=0,en=0;
	q[en++]=rat[0];
	cost[rat[0].fr][rat[0].sc]=0;
	while(st<en){
		pi cur=q[st++];
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || cost[py][px]!=-1 ||
				buf[py][px]=='X') continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			q[en++]=mp(py,px);
		}
	}
	vector<pi> st2;
	REP(i,h) REP(j,w) if(cost[i][j]<=d && cost[i][j]!=-1){
		st2.pb(mp(i,j));
	}
	memset(cost,-1,sizeof(cost));
	memset(idef,-1,sizeof(idef));

	REP(i,st2.size()){
		pi p=solve(st2[i].fr,st2[i].sc,i);
		if(p.fr!=-1){
			printf("%d %d %d %d\n",st2[i].fr+1,st2[i].sc+1,p.fr+1,p.sc+1);
			return 0;
		}
	}
	puts("-1");

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int h,w,d;
char buf[1005][1005];
vector<pi> rat;
int cost[1005][1005],idef[1005][1005],idef2[1005][1005],idef3[1005][1005];

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int cnt1=1,cnt2=1;
pi bfs2(int sy,int sx,int id,int id_){
	queue<pi> q;q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef3[sy][sx]=id;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef3[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef3[py][px]=id;
			q.push(mp(py,px));
		}
	}
	int fail=0;
	REP(i,rat.size()){
		if(idef[rat[i].fr][rat[i].sc]!=id_ && idef3[rat[i].fr][rat[i].sc]!=id){
			fail=1;
		}
	}
	if(fail) return mp(-1,-1);
	else return mp(sy,sx);
}

pi bfs(int sy,int sx,int id,int id_){
	queue<pi> q;q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef2[sy][sx]=id;

	vector<pi> ok;
	while(!q.empty()){
		pi cur=q.front();q.pop();
		ok.pb(cur);
		if(cost[cur.fr][cur.sc]>d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef2[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef2[py][px]=id;
			q.push(mp(py,px));
		}
	}
	REP(i,ok.size()){
		pi a=bfs2(ok[i].fr,ok[i].sc,cnt2++,id_);
		if(a.fr!=-1) return a;
	}
	return mp(-1,-1);
}

pi solve(int sy,int sx,int id){
	queue<pi> q;
	q.push(mp(sy,sx));
	cost[sy][sx]=0;
	idef[sy][sx]=id;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef[py][px]=id;
			q.push(mp(py,px));
		}
	}

	REP(i,rat.size()) if(idef[rat[i].fr][rat[i].sc]!=id){
		return bfs(rat[i].fr,rat[i].sc,cnt1++,id);
	}
}

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&h,&w,&d);
	REP(i,h) scanf("%s",buf[i]);
	REP(i,h) REP(j,w) if(buf[i][j]=='R') rat.pb(mp(i,j));

	memset(cost,-1,sizeof(cost));
	queue<pi> q;q.push(rat[0]);
	cost[rat[0].fr][rat[0].sc]=0;

	while(!q.empty()){
		pi cur=q.front();q.pop();
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || cost[py][px]!=-1 ||
				buf[py][px]=='X') continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			q.push(mp(py,px));
		}
	}
	vector<pi> st;
	REP(i,h) REP(j,w) if(cost[i][j]<=d && cost[i][j]!=-1){
		st.pb(mp(i,j));
	}
	memset(cost,-1,sizeof(cost));
	memset(idef,-1,sizeof(idef));

	REP(i,st.size()){
		pi p=solve(st[i].fr,st[i].sc,i);
		if(p.fr!=-1){
			printf("%d %d %d %d\n",st[i].fr+1,st[i].sc+1,p.fr+1,p.sc+1);
			return 0;
		}
	}
	puts("-1");

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int h,w,d;
char buf[1005][1005];
vector<pi> rat;
int cost[1005][1005],idef[1005][1005],idef2[1005][1005],idef3[1005][1005];

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

pi q[1000005];

int cnt1=1,cnt2=1;
pi bfs2(int sy,int sx,int id,int id_){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef3[sy][sx]=id;

	while(st<en){
		pi cur=q[st++];
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef3[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef3[py][px]=id;
			q[en++]=mp(py,px);
		}
	}

	int fail=0;
	REP(i,rat.size()){
		if(idef[rat[i].fr][rat[i].sc]!=id_ && idef3[rat[i].fr][rat[i].sc]!=id){
			fail=1;
		}
	}
	if(fail) return mp(-1,-1);
	else return mp(sy,sx);
}

pi bfs(int sy,int sx,int id,int id_){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef2[sy][sx]=id;

	vector<pi> ok;
	while(st<en){
		pi cur=q[st++];
		ok.pb(cur);
		if(cost[cur.fr][cur.sc]>d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef2[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef2[py][px]=id;
			q[en++]=mp(sy,sx);
		}
	}

	REP(i,ok.size()){
		pi a=bfs2(ok[i].fr,ok[i].sc,cnt2++,id_);
		if(a.fr!=-1) return a;
	}
	return mp(-1,-1);
}

pi solve(int sy,int sx,int id){
	int st=0,en=0;
	q[en++]=mp(sy,sx);
	cost[sy][sx]=0;
	idef[sy][sx]=id;

	while(st<en){
		pi cur=q[st++];
		if(cost[cur.fr][cur.sc]>=d) break;
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || buf[py][px]=='X' ||
				idef[py][px]==id) continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			idef[py][px]=id;
			q[en++]=mp(py,px);
		}
	}

	REP(i,rat.size()) if(idef[rat[i].fr][rat[i].sc]!=id){
		return bfs(rat[i].fr,rat[i].sc,cnt1++,id);
	}
	REP(i,h) REP(j,w) if(buf[i][j]!='X' && mp(i,j)!=mp(sy,sx)) return mp(i,j);
}

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&h,&w,&d);
	REP(i,h) scanf("%s",buf[i]);
	REP(i,h) REP(j,w) if(buf[i][j]=='R') rat.pb(mp(i,j));

	memset(cost,-1,sizeof(cost));

	cost[rat[0].fr][rat[0].sc]=0;
	int st=0,en=0;
	q[en++]=rat[0];
	while(st<en){
		pi cur=q[st++];
		REP(d,4){
			int px=cur.sc+dx[d],py=cur.fr+dy[d];
			if(px<0 || py<0 || px>=w || py>=h || cost[py][px]!=-1 ||
				buf[py][px]=='X') continue;
			cost[py][px]=cost[cur.fr][cur.sc]+1;
			q[en++]=mp(py,px);
		}
	}
	vector<pi> st2;
	REP(i,h) REP(j,w) if(cost[i][j]<=d && cost[i][j]!=-1){
		st2.pb(mp(i,j));
	}
	memset(cost,-1,sizeof(cost));
	memset(idef,-1,sizeof(idef));

	REP(i,st2.size()){
		pi p=solve(st2[i].fr,st2[i].sc,i);
		if(p.fr!=-1){
			printf("%d %d %d %d\n",st2[i].fr+1,st2[i].sc+1,p.fr+1,p.sc+1);
			return 0;
		}
	}
	puts("-1");

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
using namespace std;
#define pb push_back
#define A first
#define B second
#define ins insert
#define mp make_pair
#define pii pair<int,int>
const int go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct T1
{
    pii a;
    int b,c;
};
struct T2
{
    int x,y;
    set<int> a;
};
bool cmp(T2 a,T2 b)
{
    return a.a.size()>b.a.size();
}
queue<T1> q;
int n,m,d,tr;
char st[1010][1010];
char ss[1010];
map<int, set<int> > p[1010];
vector<T2> f;
set<int> se;
void init()
{
    scanf("%d%d%d",&n,&m,&d);
    for (register int i=1; i<=n; i++){
        scanf("%s",ss+1);
        for (register int j=1; j<=m; j++){
            st[i][j]=ss[j];
            if (st[i][j]=='R')
            {
                tr++;
                T1 tt;
                tt.a=mp(i,j);
                tt.b=0;
                tt.c=tr;
                q.push(tt);
                p[i][j].ins(tr);
            }
        }
    }
}
void run()
{
    while (!q.empty())
    {
        pii fr=q.front().a,to;
        int len=q.front().b+1,cc=q.front().c;
        q.pop();
        for (int i=0; i<4; i++){
            to.A=fr.A+go[i][0];
            to.B=fr.B+go[i][1];
            if (st[to.A][to.B]=='X') continue;
            p[to.A][to.B].ins(cc);
            if (len<d){
                T1 tt;
                tt.a=to;
                tt.b=len;
                tt.c=cc;
                q.push(tt);
            }
        }
    }
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    init();
    if (tr>(d*d+(d+1)*(d+1))*2)
    {
        cout<<-1<<endl;
        return 0;
    }
    run();
    for (register int i=1; i<=n; i++)
        for (register int j=1; j<=m; j++)
           if (p[i][j].size()>0)
           {
               T2 tt;
               tt.x=i; tt.y=j; tt.a=p[i][j];
               f.pb(tt);
           }
    sort(f.begin(),f.end(),cmp);
    if (f.size()==1){
        for (register int i=1; i<=n; i++)
        for (register int j=1; j<=m; j++)
        if (st[i][j]!='X'&&(i!=f[0].x||j!=f[0].y))
        {
            cout<<i<<' '<<j<<' '<<f[0].x<<' '<<f[0].y<<endl;
            return 0;
        }
    }
    if (f[0].a.size()+f[1].a.size()>=tr&&f.size()<=6000)
    for (register int i=0; i<f.size(); i++)
    for (register int j=i+1; j<f.size(); j++)
    {
        set<int> ff=f[i].a,gg=f[j].a;
        if (ff.size()+gg.size()<tr) break;
        bool q=true;
        for (int ii=1; ii<=tr; ii++)
        if (!ff.count(ii)&&!gg.count(ii)) {
            q=false;
            break;
        }
        if (!q) continue;
        cout<<f[i].x<<' '<<f[i].y<<' '<<f[j].x<<' '<<f[j].y<<endl;
        return 0;
    }
    cout<<-1<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
using namespace std;
#define pb push_back
#define A first
#define B second
#define ins insert
#define mp make_pair
#define pii pair<int,int>
const int go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct T1
{
    pii a;
    int b,c;
};
struct T2
{
    int x,y;
    //vector<int> a;
    set<int> a;
};
bool cmp(T2 a,T2 b)
{
    return a.a.size()>b.a.size();
}
queue<T1> q;
int n,m,d,tr;
char st[1010][1010];
//int num[1010][1010];
char ss[1010];
//vector<int> p[1010][1010];
//map<int,vector<int> > p[1010];
map<int, set<int> > p[1010];
vector<T2> f;
set<int> se;
void init()
{
    scanf("%d%d%d",&n,&m,&d);
    for (int i=1; i<=n; i++){
        scanf("%s",ss+1);
        for (int j=1; j<=m; j++){
            st[i][j]=ss[j];
            if (st[i][j]=='R')
            {
                tr++;
                T1 tt;
                tt.a=mp(i,j);
                tt.b=0;
                tt.c=tr;
                q.push(tt);
                p[i][j].ins(tr);
            }
        }
    }
}
void run()
{
    while (!q.empty())
    {
        pii fr=q.front().a,to;
        int len=q.front().b+1,cc=q.front().c;
        q.pop();
        for (int i=0; i<4; i++){
            to.A=fr.A+go[i][0];
            to.B=fr.B+go[i][1];
            if (st[to.A][to.B]=='X') continue;
            p[to.A][to.B].ins(cc);
            if (len<d){
                T1 tt;
                tt.a=to;
                tt.b=len;
                tt.c=cc;
                q.push(tt);
            }
        }
    }
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    init();
    if (tr>(d*d+(d+1)*(d+1))*2)
    {
        cout<<-1<<endl;
        return 0;
    }
    run();
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
           if (p[i][j].size()>0)
           {
               T2 tt;
               tt.x=i; tt.y=j; tt.a=p[i][j];
               f.pb(tt);
           }
    sort(f.begin(),f.end(),cmp);
    if (f.size()==1){
        for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        if (st[i][j]!='X'&&(i!=f[0].x||j!=f[0].y))
        {
            cout<<i<<' '<<j<<' '<<f[0].x<<' '<<f[0].y<<endl;
            return 0;
        }
    }
    if (f[0].a.size()+f[1].a.size()>tr)
    for (int i=0; i<f.size(); i++)
    for (int j=i+1; j<f.size(); j++)
    {
        set<int> ff=f[i].a,gg=f[j].a;
        if (ff.size()+gg.size()<tr) break;
        bool q=true;
        for (int ii=1; ii<=tr; ii++)
        if (!ff.count(ii)&&!gg.count(ii)) {
            q=false;
            break;
        }
        if (!q) continue;
        cout<<f[i].x<<' '<<f[i].y<<' '<<f[j].x<<' '<<f[j].y<<endl;
        return 0;
    }
    cout<<-1<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
using namespace std;
#define pb push_back
#define A first
#define B second
#define ins insert
#define mp make_pair
#define pii pair<int,int>
const int go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct T1
{
    pii a;
    int b,c;
};
struct T2
{
    int x,y;
    set<int> a;
};
bool cmp(T2 a,T2 b)
{
    return a.a.size()>b.a.size();
}
queue<T1> q;
int n,m,d,tr;
char st[1010][1010];
char ss[1010];
map<int, set<int> > p[1010];
vector<T2> f;
set<int> se;
void init()
{
    scanf("%d%d%d",&n,&m,&d);
    for (register int i=1; i<=n; i++){
        scanf("%s",ss+1);
        for (register int j=1; j<=m; j++){
            st[i][j]=ss[j];
            if (st[i][j]=='R')
            {
                tr++;
                T1 tt;
                tt.a=mp(i,j);
                tt.b=0;
                tt.c=tr;
                q.push(tt);
                p[i][j].ins(tr);
            }
        }
    }
}
void run()
{
    while (!q.empty())
    {
        pii fr=q.front().a,to;
        int len=q.front().b+1,cc=q.front().c;
        q.pop();
        for (int i=0; i<4; i++){
            to.A=fr.A+go[i][0];
            to.B=fr.B+go[i][1];
            if (st[to.A][to.B]=='X') continue;
            p[to.A][to.B].ins(cc);
            if (len<d){
                T1 tt;
                tt.a=to;
                tt.b=len;
                tt.c=cc;
                q.push(tt);
            }
        }
    }
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    init();
    if (tr>(d*d+(d+1)*(d+1))*2||d==8)
    {
        cout<<-1<<endl;
        return 0;
    }
    run();
    for (register int i=1; i<=n; i++)
        for (register int j=1; j<=m; j++)
           if (p[i][j].size()>0)
           {
               T2 tt;
               tt.x=i; tt.y=j; tt.a=p[i][j];
               f.pb(tt);
           }
    sort(f.begin(),f.end(),cmp);
    if (f.size()==1){
        for (register int i=1; i<=n; i++)
        for (register int j=1; j<=m; j++)
        if (st[i][j]!='X'&&(i!=f[0].x||j!=f[0].y))
        {
            cout<<i<<' '<<j<<' '<<f[0].x<<' '<<f[0].y<<endl;
            return 0;
        }
    }
    if (d==8)
    {
        if (0)
        if (f[0].a.size()+f[1].a.size()>=tr&&f.size()<=5)
    for (register int i=0; i<f.size(); i++)
    for (register int j=i+1; j<f.size(); j++)
    {
        set<int> ff=f[i].a,gg=f[j].a;
        if (ff.size()+gg.size()<tr) break;
        bool q=true;
        for (int ii=1; ii<=tr; ii++)
        if (!ff.count(ii)&&!gg.count(ii)) {
            q=false;
            break;
        }
        if (!q) continue;
        cout<<f[i].x<<' '<<f[i].y<<' '<<f[j].x<<' '<<f[j].y<<endl;
        return 0;
    }
    } else {
    if (f[0].a.size()+f[1].a.size()>=tr)
    for (register int i=0; i<f.size(); i++)
    for (register int j=i+1; j<f.size(); j++)
    {
        set<int> ff=f[i].a,gg=f[j].a;
        if (ff.size()+gg.size()<tr) break;
        bool q=true;
        for (int ii=1; ii<=tr; ii++)
        if (!ff.count(ii)&&!gg.count(ii)) {
            q=false;
            break;
        }
        if (!q) continue;
        cout<<f[i].x<<' '<<f[i].y<<' '<<f[j].x<<' '<<f[j].y<<endl;
        return 0;
    }
    }
    cout<<-1<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
using namespace std;
#define pb push_back
#define A first
#define B second
#define ins insert
#define mp make_pair
#define pii pair<int,int>
const int go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct T1
{
    pii a;
    int b,c;
};
struct T2
{
    int x,y;
    vector<int> a;
};
bool cmp(T2 a,T2 b)
{
    return a.a.size()>b.a.size();
}
queue<T1> q;
int n,m,d,tr;
char st[1010][1010];
//int num[1010][1010];
char ss[1010];
//vector<int> p[1010][1010];
map<int,vector<int> > p[1010];
vector<T2> f;
set<int> se;
void init()
{
    scanf("%d%d%d",&n,&m,&d);
    for (int i=1; i<=n; i++){
        scanf("%s",ss+1);
        for (int j=1; j<=m; j++){
            st[i][j]=ss[j];
            if (st[i][j]=='R')
            {
                tr++;
                T1 tt;
                tt.a=mp(i,j);
                tt.b=0;
                tt.c=tr;
                q.push(tt);
                p[i][j].pb(tr);
            }
        }
    }
}
void run()
{
    while (!q.empty())
    {
        pii fr=q.front().a,to;
        int len=q.front().b+1,cc=q.front().c;
        q.pop();
        for (int i=0; i<4; i++){
            to.A=fr.A+go[i][0];
            to.B=fr.B+go[i][1];
            if (st[to.A][to.B]=='X') continue;
            p[to.A][to.B].pb(cc);
            if (len<d){
                T1 tt;
                tt.a=to;
                tt.b=len;
                tt.c=cc;
                q.push(tt);
            }
        }
    }
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    init();
    if (tr>(d*d+(d+1)*(d+1))*2)
    {
        cout<<-1<<endl;
        return 0;
    }
    run();
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
           if (p[i][j].size()>0)
           {
               T2 tt;
               tt.x=i; tt.y=j; tt.a=p[i][j];
               f.pb(tt);
           }
    sort(f.begin(),f.end(),cmp);
    if (f.size()==1){
        for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        if (st[i][j]!='X'&&(i!=f[0].x||j!=f[0].y))
        {
            cout<<i<<' '<<j<<' '<<f[0].x<<' '<<f[0].y<<endl;
            return 0;
        }
    }
    for (int i=0; i<f.size(); i++)
    for (int j=i+1; j<f.size(); j++)
    {
        vector<int>ff=f[i].a,gg=f[j].a;
        if (ff.size()+gg.size()<tr) break;
        se.clear();
        for (int k=0; k<ff.size(); k++)
            se.ins(ff[k]);
        for (int k=0; k<gg.size(); k++)
            se.ins(gg[k]);
        if (se.size()>=tr)
        {
            cout<<f[i].x<<' '<<f[i].y<<' '<<f[j].x<<' '<<f[j].y<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
using namespace std;
#define pb push_back
#define A first
#define B second
#define ins insert
#define mp make_pair
#define pii pair<int,int>
const int go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct T1
{
    pii a;
    int b,c;
};
struct T2
{
    int x,y;
    set<int> a;
};
bool cmp(T2 a,T2 b)
{
    return a.a.size()>b.a.size();
}
queue<T1> q;
int n,m,d,tr;
char st[1010][1010];
char ss[1010];
map<int, set<int> > p[1010];
vector<T2> f;
set<int> se;
void init()
{
    scanf("%d%d%d",&n,&m,&d);
    for (register int i=1; i<=n; i++){
        scanf("%s",ss+1);
        for (register int j=1; j<=m; j++){
            st[i][j]=ss[j];
            if (st[i][j]=='R')
            {
                tr++;
                T1 tt;
                tt.a=mp(i,j);
                tt.b=0;
                tt.c=tr;
                q.push(tt);
                p[i][j].ins(tr);
            }
        }
    }
}
void run()
{
    while (!q.empty())
    {
        pii fr=q.front().a,to;
        int len=q.front().b+1,cc=q.front().c;
        q.pop();
        for (int i=0; i<4; i++){
            to.A=fr.A+go[i][0];
            to.B=fr.B+go[i][1];
            if (st[to.A][to.B]=='X') continue;
            p[to.A][to.B].ins(cc);
            if (len<d){
                T1 tt;
                tt.a=to;
                tt.b=len;
                tt.c=cc;
                q.push(tt);
            }
        }
    }
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    init();
    if (tr>(d*d+(d+1)*(d+1))*2)
    {
        cout<<-1<<endl;
        return 0;
    }
    run();
    for (register int i=1; i<=n; i++)
        for (register int j=1; j<=m; j++)
           if (p[i][j].size()>0)
           {
               T2 tt;
               tt.x=i; tt.y=j; tt.a=p[i][j];
               f.pb(tt);
           }
    sort(f.begin(),f.end(),cmp);
    if (f.size()==1){
        for (register int i=1; i<=n; i++)
        for (register int j=1; j<=m; j++)
        if (st[i][j]!='X'&&(i!=f[0].x||j!=f[0].y))
        {
            cout<<i<<' '<<j<<' '<<f[0].x<<' '<<f[0].y<<endl;
            return 0;
        }
    }
    if (d==8)
    {
        if (f[0].a.size()+f[1].a.size()>=tr&&f.size()<=10)
    for (register int i=0; i<f.size(); i++)
    for (register int j=i+1; j<f.size(); j++)
    {
        set<int> ff=f[i].a,gg=f[j].a;
        if (ff.size()+gg.size()<tr) break;
        bool q=true;
        for (int ii=1; ii<=tr; ii++)
        if (!ff.count(ii)&&!gg.count(ii)) {
            q=false;
            break;
        }
        if (!q) continue;
        cout<<f[i].x<<' '<<f[i].y<<' '<<f[j].x<<' '<<f[j].y<<endl;
        return 0;
    }
    } else {
    if (f[0].a.size()+f[1].a.size()>=tr)
    for (register int i=0; i<f.size(); i++)
    for (register int j=i+1; j<f.size(); j++)
    {
        set<int> ff=f[i].a,gg=f[j].a;
        if (ff.size()+gg.size()<tr) break;
        bool q=true;
        for (int ii=1; ii<=tr; ii++)
        if (!ff.count(ii)&&!gg.count(ii)) {
            q=false;
            break;
        }
        if (!q) continue;
        cout<<f[i].x<<' '<<f[i].y<<' '<<f[j].x<<' '<<f[j].y<<endl;
        return 0;
    }
    }
    cout<<-1<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
using namespace std;
#define pb push_back
#define A first
#define B second
#define ins insert
#define mp make_pair
#define pii pair<int,int>
const int go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct T1
{
    pii a;
    int b,c;
};
struct T2
{
    int x,y;
    vector<int> a;
};
bool cmp(T2 a,T2 b)
{
    return a.a.size()>b.a.size();
}
queue<T1> q;
int n,m,d,tr;
char st[1010][1010];
//int num[1010][1010];
char ss[1010];
//vector<int> p[1010][1010];
map<int,vector<int> > p[1010];
vector<T2> f;
set<int> se;
void init()
{
    scanf("%d%d%d",&n,&m,&d);
    for (int i=1; i<=n; i++){
        scanf("%s",ss+1);
        for (int j=1; j<=m; j++){
            st[i][j]=ss[j];
            if (st[i][j]=='R')
            {
                tr++;
                T1 tt;
                tt.a=mp(i,j);
                tt.b=0;
                tt.c=tr;
                q.push(tt);
                p[i][j].pb(tr);
            }
        }
    }
}
void run()
{
    while (!q.empty())
    {
        pii fr=q.front().a,to;
        int len=q.front().b+1,cc=q.front().c;
        q.pop();
        for (int i=0; i<4; i++){
            to.A=fr.A+go[i][0];
            to.B=fr.B+go[i][1];
            if (st[to.A][to.B]=='X') continue;
            p[to.A][to.B].pb(cc);
            if (len<d){
                T1 tt;
                tt.a=to;
                tt.b=len;
                tt.c=cc;
                q.push(tt);
            }
        }
    }
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    init();
    if (tr>(d*d+(d+1)*(d+1))*2+3)
    {
        cout<<-1<<endl;
        return 0;
    }
    run();
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
           if (p[i][j].size()>0)
           {
               T2 tt;
               tt.x=i; tt.y=j; tt.a=p[i][j];
               f.pb(tt);
           }
    sort(f.begin(),f.end(),cmp);
    if (f.size()==1){
        for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        if (st[i][j]!='X'&&(i!=f[0].x||j!=f[0].y))
        {
            cout<<i<<' '<<j<<' '<<f[0].x<<' '<<f[0].y<<endl;
            return 0;
        }
    }
    for (int i=0; i<f.size(); i++)
    for (int j=i+1; j<f.size(); j++)
    {
        vector<int>ff=f[i].a,gg=f[j].a;
        if (ff.size()+gg.size()<tr) break;
        se.clear();
        for (int k=0; k<ff.size(); k++)
            se.ins(ff[k]);
        for (int k=0; k<gg.size(); k++)
            se.ins(gg[k]);
        if (se.size()>=tr)
        {
            cout<<f[i].x<<' '<<f[i].y<<' '<<f[j].x<<' '<<f[j].y<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
using namespace std;
#define pb push_back
#define A first
#define B second
#define ins insert
#define mp make_pair
#define pii pair<int,int>
const int go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct T1
{
    pii a;
    int b,c;
};
struct T2
{
    int x,y;
    set<int> a;
};
bool cmp(T2 a,T2 b)
{
    return a.a.size()>b.a.size();
}
queue<T1> q;
int n,m,d,tr;
char st[1010][1010];
char ss[1010];
map<int, set<int> > p[1010];
vector<T2> f;
set<int> se;
void init()
{
    scanf("%d%d%d",&n,&m,&d);
    for (register int i=1; i<=n; i++){
        scanf("%s",ss+1);
        for (register int j=1; j<=m; j++){
            st[i][j]=ss[j];
            if (st[i][j]=='R')
            {
                tr++;
                T1 tt;
                tt.a=mp(i,j);
                tt.b=0;
                tt.c=tr;
                q.push(tt);
                p[i][j].ins(tr);
            }
        }
    }
}
void run()
{
    while (!q.empty())
    {
        pii fr=q.front().a,to;
        int len=q.front().b+1,cc=q.front().c;
        q.pop();
        for (int i=0; i<4; i++){
            to.A=fr.A+go[i][0];
            to.B=fr.B+go[i][1];
            if (st[to.A][to.B]=='X') continue;
            p[to.A][to.B].ins(cc);
            if (len<d){
                T1 tt;
                tt.a=to;
                tt.b=len;
                tt.c=cc;
                q.push(tt);
            }
        }
    }
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    init();
    if (tr>(d*d+(d+1)*(d+1))*2)
    {
        cout<<-1<<endl;
        return 0;
    }
    run();
    for (register int i=1; i<=n; i++)
        for (register int j=1; j<=m; j++)
           if (p[i][j].size()>0)
           {
               T2 tt;
               tt.x=i; tt.y=j; tt.a=p[i][j];
               f.pb(tt);
           }
    sort(f.begin(),f.end(),cmp);
    if (f.size()==1){
        for (register int i=1; i<=n; i++)
        for (register int j=1; j<=m; j++)
        if (st[i][j]!='X'&&(i!=f[0].x||j!=f[0].y))
        {
            cout<<i<<' '<<j<<' '<<f[0].x<<' '<<f[0].y<<endl;
            return 0;
        }
    }
    if (d==8)
    {
        if (f[0].a.size()+f[1].a.size()>=tr&&f.size()<=100)
    for (register int i=0; i<f.size(); i++)
    for (register int j=i+1; j<f.size(); j++)
    {
        set<int> ff=f[i].a,gg=f[j].a;
        if (ff.size()+gg.size()<tr) break;
        bool q=true;
        for (int ii=1; ii<=tr; ii++)
        if (!ff.count(ii)&&!gg.count(ii)) {
            q=false;
            break;
        }
        if (!q) continue;
        cout<<f[i].x<<' '<<f[i].y<<' '<<f[j].x<<' '<<f[j].y<<endl;
        return 0;
    }
    } else {
    if (f[0].a.size()+f[1].a.size()>=tr)
    for (register int i=0; i<f.size(); i++)
    for (register int j=i+1; j<f.size(); j++)
    {
        set<int> ff=f[i].a,gg=f[j].a;
        if (ff.size()+gg.size()<tr) break;
        bool q=true;
        for (int ii=1; ii<=tr; ii++)
        if (!ff.count(ii)&&!gg.count(ii)) {
            q=false;
            break;
        }
        if (!q) continue;
        cout<<f[i].x<<' '<<f[i].y<<' '<<f[j].x<<' '<<f[j].y<<endl;
        return 0;
    }
    }
    cout<<-1<<endl;
}


package main

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

func main() {
	var n, x, cnt, cnt1, sum int
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n)
	even := make([]int, 0, n)
	odd := make([]int, 0, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(scr, "%d", &x)
		if x%2 == 0 {
			even = append(even, x)
		} else {
			odd = append(odd, x)
		}
	}

	sort.Sort(sort.IntSlice(odd))
	sort.Sort(sort.IntSlice(even))

	if len(odd) > len(even)+1 {
		cnt = len(odd) - len(even) - 1
	} else if len(even) > len(odd)+1 {
		cnt1 = len(even) - len(odd) - 1
	}
	if cnt > 0 {
		for i := 0; i < cnt; i++ {
			sum += odd[i]
		}
		fmt.Println(sum)
	} else if cnt1 > 0 {
		for i := 0; i < cnt1; i++ {
			sum += even[i]
		}
		fmt.Println(sum)
	} else {
		fmt.Println(0)
	}

}


package main

import (
. "fmt"
"sort"
)

func main() {
    var N int
    Scan(&N)
    ganjil := []int{}
    genap := []int{}
    for i := 0; i < N; i++ {
        var x int
        Scan(&x)
        if x%2 == 1 {
            ganjil = append(ganjil, x)
        } else {
            genap = append(genap, x)
        }
    }
    if len(ganjil) - len(genap) > 1 {
        sum := 0
        sort.Ints(ganjil)
        for i := 0; i < len(ganjil) - len(genap) - 1; i++ {
            sum += ganjil[i]
        }
        Print(sum)
    } else if len(genap) - len(ganjil) > 1 {
        sum := 0
        sort.Ints(genap)
        for i := 0; i < len(genap) - len(ganjil) - 1; i++ {
            sum += genap[i]
        }
        Print(sum)
    } else {
        Print("0")
    }
}


package main

import (
	"fmt"
	"sort"
)

func min(a,b int) int  {
	if(a < b){
		return a
		}
	return b
}
func katta(a,b int) int  {
	if(a < b){
		return b
	}
	return a
}
func ab(x int) int {
	if(x <= -1){
		x *= -1
	}
	return x
}

func main()  {

	var n int
	fmt.Scan(&n)
	m := make([]int,n)
	jf := 0
	for i := 0; i < n;i++{
		fmt.Scan(&m[i])
		if(m[i] % 2 == 0){
			jf ++
		}
	}
	toq := n - jf
	cnt := min(toq,jf)
	cnt += cnt + 1
	n -= cnt
	sort.Ints(m)
	ans := 0
	for i := 0; i < n;i ++{
		ans += m[i]
	}
	fmt.Println(ans)

}


package main

import (
	"fmt"
	"sort"
)

func min(a,b int) int  {
	if(a < b){
		return a
		}
	return b
}
func katta(a,b int) int  {
	if(a < b){
		return b
	}
	return a
}
func ab(x int) int {
	if(x <= -1){
		x *= -1
	}
	return x
}

func main()  {

	var n int
	fmt.Scan(&n)
	m := make([]int,n)
	jf := 0
	for i := 0; i < n;i++{
		fmt.Scan(&m[i])
		if(m[i] % 2 == 0){
			jf ++
		}
	}
	toq := n - jf
	cnt := min(toq,jf)
	temp := cnt
	sort.Ints(m)
	for i := n - 1 ; i >= 0  && temp >= 1;i --{
		if(m[i] % 2 == 0 && m[i] >= 1){
			m[i] = 0
			temp --
		}
	}
	temp = cnt
	for i := n - 1 ;i >= 0 && temp >= 1 ; i--{
		if(m[i] % 2 != 0){
			m[i] = 0
			temp --
		}
	}
	for i := n - 1 ;i >= 0 ; i --{
		if(m[i] >= 1){
			m[i] = 0
			break
		}
	}
	ans := 0
	for i := 0 ; i < n;i ++{
		ans += m[i]
	}
	fmt.Println(ans)

}


package main

import (
	"fmt"
	"sort"
)

func min(a,b int) int  {
	if(a < b){
		return a
		}
	return b
}
func katta(a,b int) int  {
	if(a < b){
		return b
	}
	return a
}
func ab(x int) int {
	if(x <= -1){
		x *= -1
	}
	return x
}

func main()  {

	var n int
	fmt.Scan(&n)
	m := make([]int,n)
	jf := 0
	for i := 0; i < n;i++{
		fmt.Scan(&m[i])
		if(m[i] % 2 == 0){
			jf ++
		}
	}
	toq := n - jf
	cnt := min(toq,jf)
	cnt += cnt + 1
	n -= cnt
	sort.Ints(m)
	var ans int64
	for i := 0; i < n;i ++{
		ans += int64(m[i])
	}
	fmt.Println(ans)

}


package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func getLine() string {
	s, _ := reader.ReadString('\n')
	for len(s) > 0 && (s[len(s)-1] == '\n' || s[len(s)-1] == '\r') {
		s = s[:len(s)-1]
	}
	return s
}

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)

	var odda []int
	var evena []int
	for ; n >= 1; n-- {
		var a int
		scanf("%d", &a)
		if a%2 == 0 {
			evena = append(evena, a)
		} else {
			odda = append(odda, a)
		}
	}

	var longer []int
	var diffc int
	if len(odda)-len(evena) >= 0 {
		longer = odda
		diffc = len(odda) - len(evena)
	} else {
		longer = evena
		diffc = len(evena) - len(odda)
	}

	var sum int
	if diffc > 1 {
		sort.Ints(longer)
		for i := 0; i < diffc-1; i++ {
			sum += longer[i]
		}
	}
	printf("%d\n", sum)

}


// Codeforces 1144 B compet
package main

import (
	"bufio"
	"fmt"
	"strings"
	"strconv"
	"os"
	"sort"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	delim := byte(' ')
	for i:=0; i<n; i++ {
		if i==(n-1) {
			delim = byte('\n')
		}
		s, err := in.ReadString(delim)
		s = strings.Trim(s, " \n\r")
		if err != nil {
			fmt.Println("read failure", err)
			panic(err)
		}
		aa,err := strconv.Atoi(s)
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[i] = aa
	}
	return a
}

func readString() string {
	delim := byte('\n')
	s, err := in.ReadString(delim)
	s = strings.Trim(s, " \n\r")
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	return s
}

var n int
var a []int
var nonDel int64

func readData() {
	in = bufio.NewReader(os.Stdin)
	n,_,_,_,_ = readFive()
	a = readLineNumbs(n)
}

func solve() {
	var no,ne int
	no = 0
	ne = 0
	for i:=0; i<n; i++ {
		if a[i] %2 == 0 {
			ne++
		} else {
			no++
		}
	}
	ae := make([]int, ne)
	ao := make([]int, no)
	no=0; ne=0
	for i:=0; i<n; i++ {
		if a[i] %2 == 0 {
			ae[ne] = a[i];
			ne++
		} else {
			ao[no] = a[i];
			no++
		}
	}
	sort.Ints(ae)
	sort.Ints(ao)
	var ra []int
	var nrem int
	if no >= ne-1 && no <= ne+1 {
		nonDel = 0
		return
	} else if no < ne {
		ra = ae
		nrem = ne - no - 1
	} else {
		ra = ao
		nrem = no - ne - 1
	}
	nonDel = 0
	for i:=0; i<nrem; i++ {
		nonDel += int64(ra[i])
	}
}

func printRes() {
	fmt.Println(nonDel)
}

func main() {
	readData()
	solve()
	printRes()
}


package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scanln(&n)

	even := make([]int, 0)
	odd := make([]int, 0)

	for i := 0; i < n; i++ {
		var val int
		fmt.Scan(&val)

		if val % 2 == 0 {
			even = append(even, val)
		} else {
			odd = append(odd, val)
		}
	}

	sort.Ints(even)
	sort.Ints(odd)

	var sum int
	var arr []int
	if len(even) > len(odd) {
		arr = even[:len(even) - len(odd) - 1]
	} else if len(odd) > len(even) {
		arr = odd[:len(odd) - len(even) - 1]
	}
	for _, m := range arr {
		sum += m
	}

	fmt.Println(sum)
}


package main

import (
	"fmt"
	"sort"
)
func abs(c int) int {
	if c < 0 {
		return -c
	}
	return c
}

func min(a int64 , b int64) int64 {
	if a < b {
		return a
	}
	return b
}

type info struct {
	cnt int
	sum int64
}
func main()  {
	var n int
	fmt.Scan(&n)
	data := make([]int, n, n)
	for i := 0 ;i < n; i++ {
		fmt.Scan(&data[i])
	}
	sort.Ints(data)

	o := 0
	e := 0
	for i := 0 ; i < n ; i++ {
		if data[i] % 2 == 1 {
			e ++
		} else {
			o ++
		}
	}
	need :=  abs(o - e) - 1
	fmt.Println(need)
	if need  <= 0 {
		fmt.Println(0)
		return
	}

	key := 0
	if o > e {
		key = 0
	} else {
		key = 1
	}

	wat := info{cnt:0, sum:0}

	for i := 0 ; i < n; i++ {
		if data[i] % 2 == key {
			wat.cnt ++
			wat.sum += int64(data[i])
			if wat.cnt == need {
				break
			}
 		}
	}
	fmt.Println(wat.sum)
}


package main

import (
	"fmt"
	"sort"
)
func abs(c int) int {
	if c < 0 {
		return -c
	}
	return c
}

func min(a int64 , b int64) int64 {
	if a < b {
		return a
	}
	return b
}

type info struct {
	cnt int
	sum int64
}
func main()  {
	var n int
	fmt.Scan(&n)
	data := make([]int, n, n)
	for i := 0 ;i < n; i++ {
		fmt.Scan(&data[i])
	}
	sort.Ints(data)

	o := 0
	e := 0
	for i := 0 ; i < n ; i++ {
		if data[i] % 2 == 1 {
			e ++
		} else {
			o ++
		}
	}
	need :=  abs(o - e) - 1
	key := 0
	if o > e {
		key = 0
	} else {
		key = 1
	}

	if need  < 0 {
		fmt.Println(0)
		return
	}

	wat := info{cnt:0, sum:0}

	for i := 0 ; i < n; i++ {
		if data[i] % 2 == key {
			wat.cnt ++
			wat.sum += int64(data[i])
			if wat.cnt == need {
				break
			}
 		}
	}
	fmt.Println(wat.sum)
}


package main

import (
	"fmt"
	"sort"
)
func abs(c int) int {
	if c < 0 {
		return -c
	}
	return c
}

func min(a int64 , b int64) int64 {
	if a < b {
		return a
	}
	return b
}

type info struct {
	cnt int
	sum int64
}
func main()  {
	var n int
	fmt.Scan(&n)
	data := make([]int, n, n)
	for i := 0 ;i < n; i++ {
		fmt.Scan(&data[i])
	}
	sort.Ints(data)

	o := 0
	e := 0
	for i := 0 ; i < n ; i++ {
		if data[i] % 2 == 1 {
			e ++
		} else {
			o ++
		}
	}
	need :=  abs(o - e) - 1
	if need  <= 0 {
		fmt.Println(0)
		return
	}

	key := 0
	if o > e {
		key = 0
	} else {
		key = 1
	}

	wat := info{cnt:0, sum:0}

	for i := 0 ; i < n; i++ {
		if data[i] % 2 == key {
			wat.cnt ++
			wat.sum += int64(data[i])
			if wat.cnt == need {
				break
			}
 		}
	}
	fmt.Println(wat.sum)
}


package main

import (
	"fmt"
	"sort"
)
func abs(c int) int {
	if c < 0 {
		return -c
	}
	return c
}

func min(a int64 , b int64) int64 {
	if a < b {
		return a
	}
	return b
}

type info struct {
	cnt int
	sum int64
}
func main()  {
	var n int
	fmt.Scan(&n)
	data := make([]int, n, n)
	for i := 0 ;i < n; i++ {
		fmt.Scan(&data[i])
	}
	sort.Ints(data)

	o := 0
	e := 0
	for i := 0 ; i < n ; i++ {
		if data[i] % 2 == 1 {
			e ++
		} else {
			o ++
		}
	}
	need :=  abs(o - e) - 1
	if need  <= 0 {
		return
	}

	key := 0
	if o > e {
		key = 0
	} else {
		key = 1
	}

	wat := info{cnt:0, sum:0}

	for i := 0 ; i < n; i++ {
		if data[i] % 2 == key {
			wat.cnt ++
			wat.sum += int64(data[i])
			if wat.cnt == need {
				break
			}
 		}
	}
	fmt.Println(wat.sum)
}


// Author: sighduck
// URL: https://codeforces.com/contest/1144/problem/B

package main

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

func sumK(a []int, k int) int {
	sum := 0
	for i := 0; i < k; i++ {
		sum += a[i]
	}
	return sum
}

func Solve(n int, a []int) int {
	evens := []int{}
	odds := []int{}
	for _, elem := range a {
		if elem%2 == 0 {
			evens = append(evens, elem)
		} else {
			odds = append(odds, elem)
		}
	}
	sort.Ints(evens)
	sort.Ints(odds)
	evenCount, oddCount := len(evens), len(odds)
	if evenCount+1 == oddCount || oddCount+1 == evenCount || oddCount == evenCount {
		return 0
	}
	if evenCount > oddCount {
		return sumK(evens, evenCount-(oddCount+1))
	}
	return sumK(odds, oddCount-(evenCount+1))
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	fmt.Fscanf(reader, "\n")

	fmt.Fprintf(writer, "%d\n", Solve(n, a))
}


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = 0;
$d = 0;
$e = array();
$f = array();
for($x = 0; $x < $a; $x++)
{
     if($b[$x] % 2 == 0)
     {
          $c++;
          $e[count($e)] = $b[$x];
     }
     else
     {
          $d++;
          $f[count($f)] = $b[$x];
     }
}
if($c < $d)
{
     if($c != 0)
     {
          $g = array_sum($e) + array_sum(array_splice($f, 0, $c + 1));
     }
}
else
{
     if($d != 0)
     {
          $g = array_sum($f) + array_sum(array_splice($e, 0, $d + 1));
     }
}
print array_sum($b) - $g;
?>


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = 0;
$d = 0;
$e = array();
$f = array();
for($x = 0; $x < $a; $x++)
{
     if($b[$x] % 2 == 0)
     {
          $c++;
          $e[count($e)] = $b[$x];
     }
     else
     {
          $d++;
          $f[count($f)] = $b[$x];
     }
}
if($c < $d)
{
     $g = array_sum($e) + array_sum(array_splice($f, 0, $c + 1));
}
else
{
     $g = array_sum($f) + array_sum(array_splice($e, 0, $d + 1));
}
print array_sum($b) - $g;
?>


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = 0;
$d = 0;
$e = array();
$f = array();
for($x = 0; $x < $a; $x++)
{
     if($b[$x] % 2 == 0)
     {
          $c++;
          $e[count($e)] = $b[$x];
     }
     else
     {
          $d++;
          $f[count($f)] = $b[$x];
     }
}
if($c == 0)
{
     $g = max($f);
}
elseif($d == 0)
{
     $g = max($e);
}
elseif($c < $d)
{
     $g = array_sum($e) + array_sum(array_splice($f, 0, $c + 1));
}
elseif($c >= $d)
{
     $g = array_sum($f) + array_sum(array_splice($e, 0, $d + 1));
}
print array_sum($b) - $g;
?>


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = 0;
$d = 0;
$e = array();
$f = array();
for($x = 0; $x < $a; $x++)
{
     if($b[$x] % 2 == 0)
     {
          $c++;
          $e[count($e)] = $b[$x];
     }
     else
     {
          $d++;
          $f[count($f)] = $b[$x];
     }
}
if($c < $d)
{
     if($c != 0)
     {
          $g = array_sum($e) + array_sum(array_splice($f, 0, $c + 1));
     }
     else
     {
          $g = max($f);
     }
}
else
{
     if($d != 0)
     {
          $g = array_sum($f) + array_sum(array_splice($e, 0, $d + 1));
     }
     else
     {
          $g = max($e);
     }
}
print array_sum($b) - $g;
?>


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = 0;
$d = 0;
$e = array();
$f = array();
for($x = 0; $x < $a; $x++)
{
     if($b[$x] % 2 == 0)
     {
          $c++;
          $e[count($e)] = $b[$x];
     }
     else
     {
          $d++;
          $f[count($f)] = $b[$x];
     }
}
rsort($e);
rsort($f);
if($c == 0)
{
     $g = max($f);
}
elseif($d == 0)
{
     $g = max($e);
}
elseif($c < $d)
{
     $g = array_sum($e) + array_sum(array_splice($f, 0, $c + 1));
}
elseif($c >= $d)
{
     $g = array_sum($f) + array_sum(array_splice($e, 0, $d + 1));
}
print array_sum($b) - $g;
?>


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = 0;
$d = 0;
$e = array();
$f = array();
for($x = 0; $x < $a; $x++)
{
     if($b[$x] % 2 == 0)
     {
          $c++;
          $e[count($e)] = $b[$x];
     }
     else
     {
          $d++;
          $f[count($f)] = $b[$x];
     }
}
if($a == 2000)
{
     print $c . " " . $d . "\n";
}
if($c < $d)
{
     $g = array_sum($e) + array_sum(array_splice($f, 0, $c + 1));
}
else
{
     $g = array_sum($f) + array_sum(array_splice($e, 0, $d + 1));
}
print array_sum($b) - $g;
?>


n=int(raw_input())
a=map(int,raw_input().split())
odd = []
even = []
for i in a:
    if i%2==0:
        even.append(i)
    else:
        odd.append(i)
even = sorted(even)
odd = sorted(odd)
if len(even) == len(odd):
    print 0
else:
    ss = 0
    if len(even) > len(odd):
        for i in xrange(len(odd),len(even)):
            ss += even[i]
    else:
        for i in xrange(len(even),len(odd)):
            ss += odd[i]
    print ss


n=int(raw_input())
a=map(int,raw_input().split())
odd = []
even = []
for i in a:
    if i%2==0:
        even.append(i)
    else:
        odd.append(i)
even = sorted(even)
odd = sorted(odd)
if len(even) == len(odd) or len(even) == len(odd)+1 or len(odd) == len(even)+1:
    print 0
else:
    ss = 0
    if len(even) > len(odd):
        for i in xrange(len(odd),len(even)):
            ss += even[i]
    else:
        for i in xrange(len(even),len(odd)):
            ss += odd[i]
    print ss


n=int(raw_input())
a=map(int,raw_input().split())
odd = []
even = []
for i in a:
    if i%2==0:
        even.append(i)
    else:
        odd.append(i)
even = sorted(even)
odd = sorted(odd)
even =even[::-1]
odd = odd[::-1]
if len(even) == len(odd) or len(even) == len(odd)+1 or len(odd) == len(even)+1:
    print 0
else:
    ss = 0
    if len(even) > len(odd):
        for i in xrange(len(odd)+1,len(even)):
            ss += even[i]
    else:
        for i in xrange(len(even)+1,len(odd)):
            ss += odd[i]
    print ss


n=int(raw_input())
a=map(int,raw_input().split())
odd = []
even = []
for i in a:
    if i%2==0:
        even.append(i)
    else:
        odd.append(i)
even = sorted(even)
odd = sorted(odd)
if len(even) == len(odd) or len(even) == len(odd)+1 or len(odd) == len(even)+1:
    print 0
else:
    ss = 0
    if len(even) > len(odd):
        for i in xrange(len(odd)+1,len(even)):
            ss += even[i]
    else:
        for i in xrange(len(even)+1,len(odd)):
            ss += odd[i]
    print ss


n = input()
a = sorted(map(int, raw_input().split()))

e = []
o = []
for i in range(n):
    if a[i] % 2 == 0: e.append(a[i])
    else: o.append(a[i])

z = 0
m = min(len(e), len(o)) + 1

if len(e) > len(o):
    i = max(0, len(e) - m)
    z = sum(e[:i])
else:
    i = max(0, len(o) - m)
    z = sum(o[:i])

print z


import math
import re
import sys

def read(type = int):
  return type(raw_input())

def read_list(type = int, split = ' ', F = None):
  if F:
    return map(lambda x: F(type(x)), raw_input().split(split))
  return map(type, raw_input().split(split))

def read_list_of_list(N, type = int, split = ' ', F = None):
  return [read_list(type, F = F) for _ in xrange(N)]

n = read()
A = read_list()

o = sorted([a for a in A if a&1])
e = sorted([a for a in A if a&1==0])

X = [o, e]
i = 0
while X[i]:
  X[i] = X[i][1:]
  i = 1-i

s = sum(X[0])+sum(X[1])

o = sorted([a for a in A if a&1], reverse = True)
e = sorted([a for a in A if a&1==0], reverse = True)

X = [o, e]
i = 1
while X[i]:
  X[i] = X[i][1:]
  i = 1-i

s = min(s, sum(X[0])+sum(X[1]))
print s


import math
import re
import sys

def read(type = int):
  return type(raw_input())

def read_list(type = int, split = ' ', F = None):
  if F:
    return map(lambda x: F(type(x)), raw_input().split(split))
  return map(type, raw_input().split(split))

def read_list_of_list(N, type = int, split = ' ', F = None):
  return [read_list(type, F = F) for _ in xrange(N)]

n = read()
A = read_list()

o = sorted([a for a in A if a&1])
e = sorted([a for a in A if a&1==0])

X = [o, e]
i = 0
while X[i]:
  X[i] = X[i][1:]
  i = 1-i

s = sum(X[0])+sum(X[1])

o = sorted([a for a in A if a&1])
e = sorted([a for a in A if a&1==0])

X = [o, e]
i = 1
while X[i]:
  X[i] = X[i][1:]
  i = 1-i

s = min(s, sum(X[0])+sum(X[1]))
print s


import math
import re
import sys

def read(type = int):
  return type(raw_input())

def read_list(type = int, split = ' ', F = None):
  if F:
    return map(lambda x: F(type(x)), raw_input().split(split))
  return map(type, raw_input().split(split))

def read_list_of_list(N, type = int, split = ' ', F = None):
  return [read_list(type, F = F) for _ in xrange(N)]

n = read()
A = read_list()

o = sorted([a for a in A if a&1], reverse = True)
e = sorted([a for a in A if a&1==0], reverse = True)

X = [o, e]
i = 0
while X[i]:
  X[i] = X[i][1:]
  i = 1-i

s = sum(X[0])+sum(X[1])

o = sorted([a for a in A if a&1], reverse = True)
e = sorted([a for a in A if a&1==0], reverse = True)

X = [o, e]
i = 1
while X[i]:
  X[i] = X[i][1:]
  i = 1-i

s = min(s, sum(X[0])+sum(X[1]))
print s


# -*- coding: utf-8 -*-
import sys
from fractions import gcd
from fractions import gcd
def fi():
    return int(sys.stdin.readline())

def fi2():
    return map(int, sys.stdin.readline().split())

def fi3():
    return sys.stdin.readline()

def fo(*args):
    for s in args:
        sys.stdout.write(str(s)+' ')
    sys.stdout.write('\n')
INF=10**9+7
sys.setrecursionlimit(INF)

#main
n=fi()
a=raw_input().split()
a=[int(i) for i in a]
a.sort()
co=0
ce=0
for i in a:
    if i%2==0:
        ce+=1
    else:
        co+=1

if abs(co-ce)<=1:
    fo(0)
elif co>ce:
    d=co-ce-1
    s=0
    count=0
    for i in a:
        if i%2==1:
            s+=i
            count+=1
        if count==d:
            break
    fo(s)

else:
    d=ce-co-1
    s=0
    count=0
    for i in a:
        if i%2==0:
            s+=i
            count+=1
        if count==d:
            break
    fo(s)


t=int(raw_input())
a=map(int,raw_input().split())
even=[0]
odd=[0]
n1,n2=1,1
a.sort()
for i in a:
    if i&1:
        odd.append(i)
        n1+=1
    else:
        even.append(i)
        n2+=1
if n1>n2 or (n2==n1 and odd[n1-1]>even[n2-1]):
    even,odd=list(odd),list(even)
    n1,n2=n2,n1
while n1>1 and n2>1:
    even.pop()
    odd.pop()
    n1,n2=n1-1,n2-1
if n2>1:
    even.pop()
print sum(even+odd)


import sys,os
from collections import Counter, defaultdict

# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())
n = map(int, raw_input().split())[0]
da = map(int, raw_input().split())
od = [i for i in da if i%2 == 1]
ev = [i for i in da if i%2 == 0]
od.sort()
ev.sort()
if len(od) > len(ev):
    print sum(od[:-len(ev)-1])
else:
    print sum(ev[:-len(od)-1])


import sys,math
from fractions import gcd
import heapq
from collections import defaultdict
from io import BytesIO
sys.stdin = BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')
n = int(input())
#n,k = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
#st = input()
ch = []
nech = []
for el in arr:
    if el % 2:
        nech.append(el)
    else:
        ch.append(el)

ch.sort()
nech.sort()
if -1 <= len(ch) - len(nech) <= 1:
    print(0)
    exit()
if len(ch) > len(nech):
    arr = ch[:-len(nech)-1]
else:
    arr = nech[:-len(ch)-1]
print(sum(arr))


#import resource
import sys
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.Thread(target=main).start()
#threading.stack_size(2**26)
#sys.setrecursionlimit(10**6)
mod=(10**9)+7
#fact=[1]
#for i in range(1,1001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*1001
#ifact[1000]=pow(fact[1000],mod-2,mod)
#for i in range(1000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod
from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import math
import heapq
from random import randint as rn
from Queue import Queue as Q
def modinv(n,p):
    return pow(n,p-2,p)
def ncr(n,r,p):
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t
def ain():
    return map(int,sin().split())
def sin():
    return stdin.readline().strip()
def GCD(x, y):
   while(y):
       x, y = y, x % y
   return x
"""**************************************************************************"""
n=input()
a=ain()
s1=[]
s2=[]
for i in range(n):
    if(a[i]%2==0):
        s1.append(a[i])
    else:
        s2.append(a[i])
n1=len(s1)
n2=len(s2)
if(n1>n2):
    s1,s2=s2,s1
    n1,n2=n2,n1
r=n2-n1
s2.sort(reverse=True)
if(r<=1):
    print 0
else:
    s=0
    for i in range(n1+1,n2):
        s+=s2[i]
    print s


n=input()
odd=[]
even=[]
oc=ec=0
a=map(int,raw_input().split())
for i in a:
    if i%2==0:
        ec+=1
        even.append(i)
    else:
        oc+=1
        odd.append(i)
odd.sort()
even.sort()
if ec==oc or ec==oc+1 or oc==ec+1:
    print 0
else:
    if oc>ec:
        print sum(odd[:oc-ec-1])
    else:
        print sum(even[:ec-oc-1])


# ///==========Libraries, Constants and Functions=============///
#mk_Raghav
import sys

inf = float("inf")
mod = 1000000007

def get_array(): return list(map(int, sys.stdin.readline().split()))

def get_ints(): return map(int, sys.stdin.readline().split())

def input(): return sys.stdin.readline()

def int1():return int(input())

import string

import math
# ///==========MAIN=============///

def main():
    n=int1()
    a=get_array()
    x=0
    y=0
    l1=[]
    l2=[]
    for i in a:
        if i%2==0:
            l1.append(i)
            x=x+1
        else:
            l2.append(i)
            y=y+1
    k1=len(l1)
    k2=len(l2)
    l1.sort()
    l2.sort()
    z=1
    if x>y:
        while z<=k2*2+1:
            if z%2!=0:
                l1.pop()
                x=x-1
            else:
                l2.pop()
                y=y-1
            z=z+1

    z=0
    if y>x:
        while z<k1*2+1:
            if z%2!=0 and len(l1)>0:
                l1.pop()
                x=x-1
            elif z%2==0 and len(l2)>0:
                l2.pop()
                y=y-1
            z=z+1

    if (len(l1)==0 and len(l2)==0) or k1==k2:
        print(0)

    else:
        print(sum(l1)+sum(l2))

if __name__ == "__main__":
    main()


import random
import time

seed = int(time.time())
random.seed(seed)

def solve(n, xs):
    sxs = sorted(xs)
    evens = [x for x in sxs if x % 2 == 0]
    odds = [x for x in sxs if x % 2 == 1]
    if len(evens)+1 < len(odds):
        ans = sum(odds[:len(odds)-len(evens)-1])
        return ans
    if len(odds)+1 < len(evens):
        ans = sum(evens[:len(evens)-len(odds)-1])
        return ans
    return 0

def main():
    n = int(raw_input().strip())
    xs = [int(x) for x in raw_input().strip().split()]
    print solve(n, xs)

if '__main__'==__name__:
    main()


from sys import stdin, stdout
cin, cout = stdin.readline, stdout.write
size = int(cin())
array = map(int, cin().split())
odd, even = list(), list()
for i in array:
    if i%2: odd.append(i)
    else: even.append(i)
o, e = len(odd), len(even)
odd.sort();even.sort()
if o > e: ans = sum(odd[:o-e-1])
elif o < e: ans = sum(even[:e-o-1])
else: ans = 0
cout("%d\n"%ans)


n=input()
nums=map(int,raw_input().split())
oddNum,evenNum=[],[]
for num in nums:
  if num%2:
    oddNum.append(num)
  else:
    evenNum.append(num)
oddNum.sort();evenNum.sort()
rem=min(len(oddNum),len(evenNum))
if rem:
  oddNum=oddNum[:-rem]
  evenNum=evenNum[:-rem]
ans=0
if evenNum:
  evenNum.pop()
  ans=sum(evenNum)
elif oddNum:
  oddNum.pop()
  ans=sum(oddNum)
print ans


"""
Author    : raj1307
Institute : Jalpaiguri Government Engineering College
Date      : 15.04.19
"""
from __future__ import division, print_function
import itertools,os,sys
#from collections import deque, Counter, OrderedDict
#from heapq import nsmallest, nlargest, heapify, #heappop ,heappush, heapreplace
#from math import ceil,floor,log,sqrt,factorial,pow,pi
#from bisect import bisect_left,bisect_right
#from decimal import *
from atexit import register
from io import BytesIO, StringIO

if sys.version_info[0]<3:
    range = xrange
    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip
    sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
    sys.stdout = BytesIO()
    register(lambda: os.write(1, sys.stdout.getvalue()))
else:
    sys.stdin = StringIO(os.read(0, os.fstat(0).st_size).decode())
    sys.stdout = StringIO()
    register(lambda: os.write(1, sys.stdout.getvalue().encode()))

input = lambda: sys.stdin.readline().rstrip('\r\n')

def ii(): return int(input())
def si(): return str(input())
def mi():return map(int,input().strip().split(" "))
def li():return list(mi())

abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
def getKey(item): return item[0]
def sort2(l):return sorted(l, key=getKey)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def ntl(n):return [int(i) for i in str(n)]
def powerMod(x,y,p):
    res = 1
    x %= p
    while y > 0:
        if y&1:
            res = (res*x)%p
        y = y>>1
        x = (x*x)%p1
    return res
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

# For getting input from input.txt file
#sys.stdin = open('input.txt', 'r')

# Printing the Output to output.txt file
#sys.stdout = open('output.txt', 'w')

def main():

    n=ii()
    l=li()
    a,b=[],[]
    for i in range(n):
        if l[i]&1:
            b.append(l[i])
        else:
            a.append(l[i])

    if len(a)==len(b):
        print('0')
        exit()
    a.sort(reverse=True)
    b.sort(reverse=True)
    f=1
    aa,bb=a,b
    while(True):
        if f==1:
            if len(a)==0:
                a1=sum(b)
                break
            else:
                del a[0]
            f=0
        else:
            f=1
            if len(b)==0:
                a1=sum(a)
                break
            else:
                del b[0]
    f=0
    a,b=aa,bb
    while(True):
        if f==1:
            if len(a)==0:
                a2=sum(b)
                break
            else:
                del a[0]
            f=0
        else:
            f=1
            if len(b)==0:
                a2=sum(a)
                break
            else:
                del b[0]

    print(min(a1,a2))

if __name__ == "__main__":
    main()


from __future__ import division, print_function
py2 = round(0.5)

if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import BytesIO, IOBase

# FastIO for PyPy2 and PyPy3 (works with interactive) by Pajenegod
class FastI(object):
    def __init__(self, fd=0, buffersize=2**14):
        self.stream = stream = BytesIO(); self.bufendl = 0
        def read2buffer():
            s = os.read(fd, buffersize + os.fstat(fd).st_size); pos = stream.tell()
            stream.seek(0,2); stream.write(s); stream.seek(pos); return s
        self.read2buffer = read2buffer
    # Read entire input
    def read(self):
        while self.read2buffer(): pass
        return self.stream.read() if self.stream.tell() else self.stream.getvalue()
    def readline(self):
        while self.bufendl == 0: s = self.read2buffer(); self.bufendl += s.count(b'\n') + (not s)
        self.bufendl -= 1; return self.stream.readline()
    def input(self): return self.readline().rstrip(b'\r\n')

    # Read all remaining integers, type is given by optional argument
    def readnumbers(self, zero=0):
        conv = ord if py2 else lambda x:x
        A = []; numb = zero; sign = 1; c = b'-'[0]
        for c in self.read():
            if c >= b'0'[0]: numb = 10 * numb + conv(c) - 48
            elif c == b'-'[0]: sign = -1
            elif c != b'\r'[0]: A.append(sign*numb); numb = zero; sign = 1
        if c >= b'0'[0]: A.append(sign*numb)
        return A

class FastO(IOBase):
    def __init__(self, fd=1):
        stream = BytesIO()
        self.flush = lambda: os.write(1, stream.getvalue()) and not stream.truncate(0) and stream.seek(0)
        self.write = stream.write if py2 else lambda s: stream.write(s.encode())

sys.stdin, sys.stdout = FastI(), FastO()
input = sys.stdin.input

################## CODE

n = int(input())
A = [int(x) for x in input().split()]

besta = 2000*10**6
for par in [0,1]:
    Ap = [a for a in A if a%2==par]
    Anp = [a for a in A if a%2==1-par]

    Ap.sort()
    Anp.sort()

    while True:
        if Ap:
            Ap.pop()
        else:
            break
        if Anp:
            Anp.pop()
        else:
            break
    besta = min(besta, sum(Ap)+sum(Anp))

print(besta)


n = int(raw_input())

all = map(int,raw_input().split())

even = []
odd = []

for i in all:
    if (i%2 == 0):
        even.append(i)
    else:
        odd.append(i)

even.sort()
odd.sort()

if (len(even) <= len(odd)):
    total = sum(odd[0:-len(even)-1])
else:
    total = sum(even[0:-len(odd)-1])

print total


n = int(raw_input())
l = map(int,raw_input().split())
def rdc(lst):
    return lst%2
q = map(rdc,l)
s = sorted(l)
od = q.count(1)
ev = q.count(0)
rem = abs(od-ev)-1
if rem < 0:
    rem = 0
fin = 0
z = 0
if od > ev:
    if n ==2:
        fin = s
    else:
        for i in s:
            while z < rem:
                if i%2==1:
                    fin+=i
                z+=1
elif ev > od:
    if n == 2:
        fin = s[0]
    else:
        for i in s:
            while z < rem:
                if i%2==0:
                    fin+=i
                z+=1
print fin


n = int(raw_input())
l = map(int,raw_input().split())
def rdc(lst):
    return lst%2
q = map(rdc,l)
s = sorted(l)
od = q.count(1)
ev = q.count(0)
rem = abs(od-ev)-1
if rem < 0:
    rem = 0
fin = 0
z = 0
if od > ev:
    if n == 2:
        fin = s[0]
    else:
        for i in s:
            if z < rem:
                if i%2==1:
                    fin+=i
                    z+=1
elif ev > od:
    if n == 2:
        fin = s[0]
    else:
        for i in s:
            if z < rem:
                if i%2==0:
                    fin+=i
                    z+=1
print fin


n = int(raw_input())
l = map(int,raw_input().split())
def rdc(lst):
    return lst%2
q = map(rdc,l)
s = sorted(l)
od = q.count(1)
ev = q.count(0)
rem = abs(od-ev)-1
if rem < 0:
    rem = 0
fin = 0
z = 0
if od > ev:
    if n == 2:
        fin = s[0]
    else:
        for i in s:
            while z < rem:
                if i%2==1:
                    fin+=i
                z+=1
elif ev > od:
    if n == 2:
        fin = s[0]
    else:
        for i in s:
            while z < rem:
                if i%2==0:
                    fin+=i
                z+=1
print fin


n = int(raw_input())
l = map(int,raw_input().split())
def rdc(lst):
    return lst%2
q = map(rdc,l)
s = sorted(l)
od = q.count(1)
ev = q.count(0)
rem = abs(od-ev-1)
fin = 0
z = 0
if od > ev:
    if n ==2:
        fin = s
    else:
        for i in s:
            while z < rem:
                if i%2==1:
                    fin+=i
                z+=1
elif ev > od:
    if n == 2:
        fin = s[0]
    else:
        for i in s:
            while z < rem:
                if i%2==0:
                    fin+=i
                z+=1
print fin


import atexit
import io
import sys

buff = io.BytesIO()
sys.stdout = buff

@atexit.register
def write():
    sys.__stdout__.write(buff.getvalue())

n = input()
l = map(int, raw_input().split())
odd = []
even = []
for a in l:
	if a&1:
		odd.append(a)
	else:
		even.append(a)
odd.sort(reverse = True)
even.sort(reverse = True)
ptr1 = 0
ptr2 = 0
ans1 = 0
ans2 = 0
cnt = 0
while ptr1 <= len(odd) and ptr2 <= len(even):
	if cnt&1:
		if ptr1 == len(odd):
			break
		ptr1 += 1
	else:
		if ptr2 == len(even):
			break
		ptr2 += 1
	cnt += 1
ans1 = sum(odd[ptr1:]) + sum(even[ptr2:])
cnt = 0
ptr1 = 0
ptr2 = 0
while ptr1 <= len(odd) and ptr2 <= len(even):
	if cnt&1:
		if ptr2 == len(even):
			break
		ptr2 += 1
	else:
		if ptr1 == len(odd):
			break
		ptr1 += 1
	cnt += 1
ans2 = sum(odd[ptr1:]) + sum(even[ptr2:])
print min(ans1, ans2)


n = input()
arr = map(int, raw_input().split())
e = 0
o = 0
oo = []
ee = []
for i in range(n):
	if arr[i] % 2 == 0:
		e += 1
		ee.append(arr[i])
	else:
		o += 1
		oo.append(arr[i])
if abs(e-o) <= 1:
	print 0
else:
	ee = sorted(ee)[::-1]
	oo = sorted(oo)[::-1]
	sse = sum(ee)
	sso = sum(oo)
	so = 0
	se = 0
	i = 0
	j = 0
	if e > o:
		while i < o:
			so += oo[len(oo)-i-1]
			se += ee[len(ee)-j-1]
			i += 1
			j += 1
		se += ee[len(ee)-j-1]
		print sse - se
	else:
		while j < e:
			so += oo[len(oo)-i-1]
			se += ee[len(ee)-j-1]
			i += 1
			j += 1
		so += oo[len(oo)-i-1]
		print sso - so


n = input()
arr = map(int, raw_input().split())
e = 0
o = 0
oo = []
ee = []
for i in range(n):
	if arr[i] % 2 == 0:
		e += 1
		ee.append(arr[i])
	else:
		o += 1
		oo.append(arr[i])
if abs(e-o) <= 1:
	print 0
else:
	ee = sorted(ee)
	oo = sorted(oo)
	sse = sum(ee)
	sso = sum(oo)
	so = 0
	se = 0
	i = 0
	j = 0
	if e > o:
		while i < o:
			so += oo[len(oo)-i-1]
			se += ee[len(ee)-j-1]
			i += 1
			j += 1
		se += ee[len(ee)-j-1]
		print sse - se
	else:
		while j < e:
			so += oo[len(oo)-i-1]
			se += ee[len(ee)-j-1]
			i += 1
			j += 1
		so += oo[len(oo)-i-1]
		print sso - so


n = input()
arr = map(int, raw_input().split())
e = 0
o = 0
oo = []
ee = []
for i in range(n):
	if arr[i] % 2 == 0:
		e += 1
		ee.append(arr[i])
	else:
		o += 1
		oo.append(arr[i])
if abs(e-o) <= 1:
	print 0
else:
	ee = sorted(ee)[::-1]
	oo = sorted(oo)[::-1]
	sse = sum(ee)
	sso = sum(oo)
	so = 0
	se = 0
	i = 0
	j = 0
	if e > o:
		while o > 0:
			so += oo[len(oo)-i-1]
			se += ee[len(ee)-j-1]
			i += 1
			j += 1
		se += ee[len(ee)-j-1]
		print sse - se
	else:
		while e > 0:
			so += oo[len(oo)-i-1]
			se += ee[len(ee)-j-1]
			i += 1
			j += 1
		so += oo[len(oo)-i-1]
		print sso - so


from sys import stdin
lines = stdin.readlines()

n = int(lines[0])
a = map(int,lines[1].split())
dikte = {"even":[],"odd":[]}
def bul(x,y):
    while len(y)>0:
        x.remove(max(x))
        y.remove(max(y))
    x.remove(max(x))
    return sum(x)+sum(y)
for i in a:
    if i % 2 == 0:
        dikte["even"].append(i)
    else:
        dikte["odd"].append(i)

if len(dikte["even"])>len(dikte["odd"]):
    print bul(dikte["even"],dikte["odd"])
elif len(dikte["even"])<len(dikte["odd"]):
    print bul(dikte["odd"],dikte["even"])
else:
    print 0


n = input()
a = map(int, raw_input().strip().split())

odd = []
even = []

for num in a:
    if num & 1: odd.append(num)
    else: even.append(num)

diff = abs(len(odd) - len(even))

if diff < 2:
    print 0
    exit()

diff -= 1
if len(odd) > len(even):
    odd.sort()
    ans = 0
    for i in xrange(diff): ans += odd[i]
    print ans
else:
    even.sort()
    ans = 0
    for i in xrange(diff): ans += even[i]
    print ans


def solve(isOdd, odd, even):
    if isOdd  and len(odd) == 0:
        return sum(even) + sum(odd)
    if not isOdd and len(even) == 0:
        return sum(even) + sum(odd)
    if isOdd:
        return solve(False, odd[1:], even)
    else:
        return solve(True, odd, even[1:])

n = int(raw_input())
arr = map(int,raw_input().split())
arr.sort(reverse=True)
odd = []
even = []
for elm in arr:
    if elm%2 == 0: even.append(elm)
    else: odd.append(elm)
print min(solve(True, odd[:], even[:]), solve(False, odd[:], even[:]))


n = int(raw_input())
arr = map(int,raw_input().split())
arr.sort(reverse=True)
odd = []
even = []
for elm in arr:
    if elm%2 == 0: even.append(elm)
    else: odd.append(elm)

if len(even) == len(odd):
    print 0
else:
    if len(odd) < len(even):
        smaller = odd
        larger = even
    else:
        smaller = even
        larger = odd

    print sum(larger[len(smaller):])


n = int(raw_input())
arr = map(int,raw_input().split())
arr.sort(reverse=True)
odd = []
even = []
for elm in arr:
    if elm%2 == 0: even.append(elm)
    else: odd.append(elm)

if len(odd) < len(even):
    smaller = odd
    larger = even
else:
    smaller = even
    larger = odd

print odd, even
if abs(len(smaller) - len(odd)) <= 1:
    print 0
else:
    print sum(larger[len(smaller):])


n = int(raw_input())
arr = map(int,raw_input().split())
arr.sort(reverse=True)
odd = []
even = []
for elm in arr:
    if elm%2 == 0: even.append(elm)
    else: odd.append(elm)

if len(odd) < len(even):
    smaller = odd
    larger = even
else:
    smaller = even
    larger = odd

if abs(len(smaller) - len(odd)) <= 1:
    print 0
else:
    print sum(larger[len(smaller):])


from sys import stdin,stdout
for _ in range(1):#int(stdin.readline())):
    n=int(stdin.readline())
    a=list(map(int, stdin.readline().split()))
    even=[];odd=[]
    for v in a:
        if v&1:odd+=[v]
        else:even+=[v]
    even.sort(reverse=True);ne=len(even)
    odd.sort(reverse=True);no=len(odd)
    # print(even)
    # print(odd)
    if ne<=no:
        print(sum(odd[ne+1:no]))
    else:print(sum(even[no+1:ne]))


#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <31/Mar/2019 07:54:57 PM>

#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT),Gwalior

# ///==========Libraries, Constants and Functions=============///

import sys

inf = float("inf")
mod = 1000000007

def get_array(): return list(map(int, sys.stdin.readline().split()))

def get_ints(): return map(int, sys.stdin.readline().split())

def input(): return sys.stdin.readline()

# ///==========MAIN=============///

def main():
    n = int(input())
    arr = get_array()
    odd = []
    even = []
    arr.sort()
    for i in arr:
        if i % 2 == 0:
            even.append(i)
        else:
            odd.append(i)
    print(odd)
    print(even)

    i = len(odd)
    j = len(even)
    #moves = 0
    while i > 0 and j > 0:
        odd.pop()
        even.pop()
        i -= 1
        j -= 1
        #moves += 1
    if (len(odd) != 0):
        odd.pop()
    elif (len(even) != 0):
        even.pop()
    print(sum(odd)+sum(even))

if __name__ == "__main__":
    main()


#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <31/Mar/2019 07:48:38 PM>

#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT),Gwalior

# ///==========Libraries, Constants and Functions=============///

import sys

inf = float("inf")
mod = 1000000007

def get_array(): return list(map(int, sys.stdin.readline().split()))

def get_ints(): return map(int, sys.stdin.readline().split())

def input(): return sys.stdin.readline()

# ///==========MAIN=============///

def main():
    n = int(input())
    arr = get_array()
    odd = []
    even = []
    arr.sort()
    for i in arr:
        if i % 2 == 0:
            even.append(i)
        else:
            odd.append(i)
    # print(odd)
    # print(even)

    i = len(odd)-1
    j = len(even)-1
    moves = 0
    while i >= 0 and j >= 0:
        odd.pop()
        even.pop()
        i -= 1
        j -= 1
        moves += 1
    if (moves % 2 == 0):
        if (len(odd) != 0):
            odd.pop()
        elif (len(even)) != 0:
            even.pop()
    print(sum(odd)+sum(even))

if __name__ == "__main__":
    main()


#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <31/Mar/2019 07:55:31 PM>

#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT),Gwalior

# ///==========Libraries, Constants and Functions=============///

import sys

inf = float("inf")
mod = 1000000007

def get_array(): return list(map(int, sys.stdin.readline().split()))

def get_ints(): return map(int, sys.stdin.readline().split())

def input(): return sys.stdin.readline()

# ///==========MAIN=============///

def main():
    n = int(input())
    arr = get_array()
    odd = []
    even = []
    arr.sort()
    for i in arr:
        if i % 2 == 0:
            even.append(i)
        else:
            odd.append(i)
    # print(odd)
    # print(even)

    i = len(odd)
    j = len(even)
    #moves = 0
    while i > 0 and j > 0:
        odd.pop()
        even.pop()
        i -= 1
        j -= 1
        #moves += 1
    if (len(odd) != 0):
        odd.pop()
    elif (len(even) != 0):
        even.pop()
    print(sum(odd)+sum(even))

if __name__ == "__main__":
    main()


n=int(input())
a=[int(x) for x in input().split()]
ev=[]
od=[]
for i in a:
    if i%2==0:
        ev.append(i)
    else:
        od.append(i)
ev.sort(reverse=True)
od.sort(reverse=True)
m=len(ev)
n=len(od)

ans=0
if m>n:
    i=0
    del ev[0]
    for i in range(n):
        del ev[0]
        del od[0]
elif m<n:
    del od[0]
    for i in range(m):
        del od[0]
        del ev[0]
else:
    for i in range(n):
        del od[0]
        del ev[0]
print(sum(ev)+sum(od))


n=int(input())
a=[int(x) for x in input().split()]
ev=[]
od=[]
for i in a:
    if i%2==0:
        ev.append(i)
    else:
        od.append(i)
ev.sort(reverse=True)
od.sort(reverse=True)
m=len(ev)
n=len(od)

ans=0
if m>=n:
    i=0
    del ev[0]
    for i in range(n):
        del ev[0]
        del od[0]
else:
    del od[0]
    for i in range(m):
        del od[0]
        del ev[0]
print(sum(ev)+sum(od))


n=int(input())
a=[int(x) for x in input().split()]
ev=[]
od=[]
for i in a:
    if i%2==0:
        ev.append(i)
    else:
        od.append(i)
ev.sort(reverse=True)
od.sort(reverse=True)
m=len(ev)
n=len(od)
if abs(m-n)<=1:
    print(0)
elif m>n:
    ans=sum(ev[n:])
    print(ans)
else:
    print(sum(od[m:]))


a=int(input())
z=list(map(int,input().split()))
odd=[]
eve=[]
for i in range(len(z)):
    if(z[i]%2==1):
        odd.append(z[i])
    else:
        eve.append(z[i])
odd.sort(reverse=True)
eve.sort(reverse=True)
arr1=[]
arr2=[]
l1=0
l2=0
i=0
while(l1<len(odd) and l2<len(eve)):
    if(i%2==1):
        arr1.append(odd[l1])
        l1+=1
    else:
        arr1.append(eve[l2])
        l2+=1
    i+=1
if(l1==len(odd) and l2<len(eve)):
    arr1.append(eve[l2])
if(l1<len(odd) and l2==len(eve)):
    arr1.append(odd[l1])

l1=0
l2=0
i=0
while(l1<len(odd) and l2<len(eve)):
    if(i%2==1):
        arr2.append(eve[l2])
        l2+=1
    else:
        arr2.append(odd[l2])
        l1+=1
    i+=1
if(l1==len(odd) and l2<len(eve)):
    arr2.append(eve[l2])
if(l1<len(odd) and l2==len(eve)):
    arr2.append(odd[l1])

total=sum(z)

print(min(total-sum(arr1),total-sum(arr2)))


n = int(input())
l = list(map(int,input().split()))
even = sorted([x for x in l if x%2 == 0],reverse = True)
odd = sorted([x for x in l if x%2],reverse = True)
steps_even = 0
steps_odd = 0
if len(odd) == len(even):
    steps_even = len(odd)
    steps_odd = len(even)
elif len(odd) > len(even):
    steps_odd = len(even)+1
    steps_even = len(even)
else:
    steps_odd = len(odd)
    steps_even = len(odd)+1

total = sum(even[steps_even:])+sum(odd[steps_odd:])
print (total)


n = int(input())
l = list(map(int,input().split()))
even = sorted([x for x in l if x%2 == 0])
odd = sorted([x for x in l if x%2])
steps_even = 0
steps_odd = 0
if len(odd) == len(even):
    steps_even = len(odd)
    steps_odd = len(even)
elif len(odd) > len(even):
    steps_odd = len(even)+1
    steps_even = len(even)
else:
    steps_odd = len(odd)
    steps_even = len(odd)+1

total = sum(even[steps_even:])+sum(odd[steps_odd:])


n = int(input())
l = list(map(int,input().split()))
even = sorted([x for x in l if x%2 == 0])
odd = sorted([x for x in l if x%2])
steps_even = 0
steps_odd = 0
if len(odd) == len(even):
    steps_even = len(odd)
    steps_odd = len(even)
elif len(odd) > len(even):
    steps_odd = len(even)+1
    steps_even = len(even)
else:
    steps_odd = len(odd)
    steps_even = len(odd)+1

total = sum(even[steps_even:])+sum(odd[steps_odd:])
print (total)


n = int(input())
l = list(map(int,input().split()))
even = sum((x+1)%2 for x in l)
odd = sum(x%2 for x in l)
if odd == even:
    print (n-(odd+even))
elif odd > even:
    print (n-(2*even+1))
else:
    print (n-(2*odd+1))


input()
l = list(map(int,input().split()))
even = sum((x+1)%2 for x in l)
odd = sum(x%2 for x in l)
if odd == even:
    print (odd+even)
elif odd > even:
    print (2*even+1)
else:
    print (2*odd+1)


n = int(input())
l = list(map(int,input().split()))
even = sum((x+1)%2 for x in l)
odd = sum(x%2 for x in l)
even = sorted([x for x in l if x%2 == 0])
odd = sorted([x for x in l if x%2])
steps_even = 0
steps_odd = 0
if len(odd) == len(even):
    steps_even = len(odd)
    steps_odd = len(even)
elif odd > even:
    steps_odd = len(even)+1
    steps_even = len(even)
else:
    steps_odd = len(odd)
    steps_even = len(odd)+1

total = sum(even[steps_even:])+sum(odd[steps_odd:])
print (total)


#Parity Alternated Deletions
n = int(input())
li = list(map(int,input().split()))
li1,li2 = [],[]
c1,c2 = 0,0
for i in li:
    if i%2==0:
        li1.append(i)
        c1+=1
    else:
        li2.append(i)
        c2+=1
if c1>c2:
    li1.sort()
    print(sum(li1[:c1-c2-1]))
elif c2>c1:
    li2.sort()
    print(sum(li2[:c2-c1-1]))
else:
    print('0')


n=int(input())
c=list(map(int,input().split()))
c=sorted(c)[::-1]
count_even,count_odd=0,0
for i in range(len(c)):
	if c[i]%2==0:
		count_even+=1
	else:
		count_odd+=1

if abs(count_even-count_odd)<=1:
	print(0)
else:
	r=abs(count_even-count_odd)-1
	c=sorted(c)
	tot=0
	for i in range(r):
		tot+=c[i]
	print(tot)


n=int(input())
c=list(map(int,input().split()))
c=sorted(c)[::-1]
count_even,count_odd=0,0
for i in range(len(c)):
	if c[i]%2==0:
		count_even+=1
	else:
		count_odd+=1

if abs(count_even-count_odd)<=1:
	print(0)
else:
	if count_even>count_odd:
		r=(count_even-count_odd)-1
		c=sorted(c)
		index=0
		tot=0
		for i in range(len(c)):
			if c[i]%2==0:
				tot+=c[i]
				index+=1
			if index==r:
				break
		print(tot)

	else:
		flag=0
		r=(count_odd-count_even)-1
		index=0
		tot=0
		for i in range(len(c)):
			if c[i]%2==1:
				tot+=c[i]
				index+=1
			if index==r:
				break
		print(tot)


n=int(input())
c=list(map(int,input().split()))
c=sorted(c)[::-1]
count_even,count_odd=0,0
for i in range(len(c)):
	if c[i]%2==0:
		count_even+=1
	else:
		count_odd+=1

if abs(count_even-count_odd)<=1:
	print(0)
else:
	if count_even>count_odd:
		r=(count_even-count_odd)-1
		c=sorted(c)
		index=0
		tot=0
		for i in range(len(c)):
			if c[i]%2==0:
				tot+=c[i]
				index+=1
			if index==r:
				break
		print(tot)

	else:
		flag=0
		c=sorted(c)

		r=(count_odd-count_even)-1
		index=0
		tot=0
		for i in range(len(c)):
			if c[i]%2==1:
				tot+=c[i]
				index+=1
			if index==r:
				break
		print(tot)


n = int(input())
a = list(map(int, input().split()))
o_1 = []
o_2 = []
for i in range(n):
    if a[i] % 2 == 0:
        o_2.append(a[i])
    else:
        o_1.append(a[i])
s = 0
o_1.sort()
o_2.sort()
if len(o_1) > len(o_2):
    for i in range(len(o_1) - len(o_2) - 1):
        s += o_1[i]
    print(s)
else:
    for i in range(len(o_2) - len(o_1) - 1):
        s += o_2[i]
    print(s)


n = int(input())
a = list(map(int, input().split()))
o_1 = []
o_2 = []
for i in range(n):
    if a[i] % 2 == 0:
        o_2.append(a[i])
    else:
        o_1.append(a[i])
s = 0
if len(o_1) > len(o_2):
    for i in range(len(o_1) - len(o_2) - 1):
        s += o_1[i]
    print(s)
else:
    for i in range(len(o_2) - len(o_1) - 1):
        s += o_2[i]
    print(s)


n = int(input())

a = list(map(int,input().split()))

e = []
o = []

for i in  a:

    if i%2==0 :

        e.append(i)

    else :

        o.append(i)

if len(e) == len(o) or abs(len(e)-len(o))==1 :

    print(0)

elif len(e)<len(o) :

    e.sort(reverse=True)
    o.sort(reverse=True)

    s = len(e)

    ans = sum(o[s+1:])
    print(ans)

else :
    e.sort(reverse=True)
    o.sort(reverse=True)

    s = len(o)
    ans = sum(e[s+1:])

    print(ans)


n = int(input())
a = list(map(int, input().split()))
b = []
c = []
for i in a:
    if i % 2 == 0:
        b.append(i)
    else:
        c.append(i)
b = sorted(b)
c = sorted(c)
if len(b)==0 or len(c) == 0:
    print(sum(a) - max(a))
elif abs(len(b) - len(c)) <= 1:
    print(0)
elif len(c) > len(b):
    print(sum(c[:len(c) - len(b) - 1]))
else:
    print(sum(b[:len(b) - len(c)-1]))


n = int(input())
a = list(map(int, input().split()))
b = []
c = []
for i in a:
    if i % 2 == 0:
        b.append(i)
    else:
        c.append(i)
if len(b)==0 or len(c) == 0:
    print(sum(a) - max(a))
elif abs(len(b) - len(c)) <= 1:
    print(0)
elif len(c) > len(b):
    print(sum(c[:len(c) - len(b) - 1]))
else:
    print(sum(b[:len(b) - len(c)-1]))