Go: package main

import "fmt"

const MAX = 1001

func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	w := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&w[i])
	}
	l := MAX
	r := MAX
	for i := 0; i < n; i++ {
		if a[i] == 0 {
			if w[i] < r {
				r = w[i]
			}
		} else {
			if w[i] < l {
				l = w[i]
			}
		}
	}
	ans := 0
	if l < MAX && r < MAX {
		ans = l + r
	}
	fmt.Println(ans)
}

C++: #include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
const int INF = 1e18, MOD = 1e9 + 7;
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
signed main() {
    INCANT;
    int n;
    int a[11], b[11], c[11];
    bool flag1 = true, flag2 = true;
    cin>>n;
    rep(i, n){
        cin>>a[i];
        if(a[i]) flag1 = false;
        else flag2 = false;
    }
    if(flag1 || flag2){
        cout<<0<<endl;
        return 0;
    }
    rep(i, 11){
        b[i] = c[i] = INF;
    }
    rep(i, n){
        if(a[i]) cin>>c[i];
        else cin>>b[i];
    }
    sort(b, b + n);
    sort(c, c + n);
    cout<<b[0] + c[0]<<endl;
}

C++: #include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, X[10];
	vector<long long> V[2];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> X[i];
	for (int i = 0; i < N; i++) {
		long long Y;
		cin >> Y;
		V[X[i]].push_back(Y);
	}
	if (V[0].empty() || V[1].empty()) {
		cout << 0 << endl;
		return 0;
	}
	sort(V[0].begin(), V[0].end());
	sort(V[1].begin(), V[1].end());
	cout << V[0][0] + V[1][0] << endl;
}

C++: #include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <numeric>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<size_t> idx(N);
  std::iota(idx.begin(), idx.end(), 0);

  std::vector<int> a(N), w(N);
  for (auto& ai: a) scanf("%d", &ai);
  for (auto& wi: w) scanf("%d", &wi);

  int res = 1e9;
  do {
    int cur = 0;
    for (size_t i = 0; i < N; ++i) {
      size_t ii = idx[i];
      size_t jj = idx[(i+1)%N];
      if (a[ii] == 0 && a[jj] == 1) {
        cur += w[ii];
      } else if (a[ii] == 1 && a[jj] == 0) {
        cur += w[ii];
      }
    }
    res = std::min(res, cur);
  } while (std::next_permutation(idx.begin(), idx.end()));
  printf("%d\n", res);
}

C++: #include <iostream>
#include <algorithm>

using namespace std;



int main(){
int n;

int a=100000;
int b=100000;
int h[1005][2]={0};
cin>>n;
for (int i=1;i<=n;i++){
cin>>h[i][0];
}
for (int i=1;i<=n;i++){
cin>>h[i][1];
}
for (int i=1;i<=n;i++){
if(h[i][0]==0&&h[i][1]<a)a=h[i][1];
if(h[i][0]==1&&h[i][1]<b)b=h[i][1];
}
if(a==100000||b==100000)cout<<0<<endl;
else cout<<a+b<<endl;
}

C++: #include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N;
	cin >> N;
	VI A(N),W(N);
	bool F = false, FF = false;
	REP(i, N) {
		cin >> A[i];
		if (A[i])F = true;
		if (!A[i])FF = true;
	}
	REP(i, N)cin >> W[i];
	
	VI L, R;
	REP(i, N) {
		if (A[i])L.push_back(W[i]);
		else R.push_back(W[i]);
	}
	SORT(R);
	SORT(L);

	if (F ^ FF) {
		cout << 0 << endl;
	}
	else {
		cout << R[0] + L[0] << endl;
	}


	return 0;
}

C++: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	
	int N;
	cin >> N;
	
	int a[15], w[15];
	int S1 = 100000, S2 = 100000;
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < N; i++){
		cin >> w[i];
		if(a[i]){
			S1 = min(S1, w[i]);
		}else{
			S2 = min(S2, w[i]);
		}
	}
	
	if(S1 == 100000 || S2 == 100000){
		cout << 0 << endl;
	}else{
		cout << S1 + S2 << endl;
	}
	
	return 0;
}

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

int main(void) {
	int n, right = 0,left=0,minR=100000,minL=100000;
	scanf("%d", &n);
	vector<int> a(n),w(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> w[i];
	for (int i = 0; i < n; i++) {
		if(a[i]){
			left++;
			if (minL > w[i]) minL = w[i];
		}else{
			right++;
			if (minR > w[i]) minR = w[i];
		}
	}
	if(right == 0 || right == n)
		printf("0\n");
	else
		printf("%d\n", minL + minR);
	return 0;
}

C++: #include <iostream>
using namespace std;

int main()
{
	int n, rm = 1001, lm = 1001;
	int a[10], w;

	cin >> n;

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

		if (a[i] == 0 && rm > w)
			rm = w;
		else if (a[i] == 1 && lm > w)
			lm = w;
	}

	if (rm == 1001 || lm == 1001)
		cout << 0 << endl;
	else
		cout << rm + lm << endl;
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(2));
    for (int i = 0; i < n; i++) cin >> v[i][0];
    for (int i = 0; i < n; i++) cin >> v[i][1];

    vector<int> l;
    vector<int> r;
    for (int i = 0; i < n; i++) (v[i][0] > 0 ? l : r).push_back(v[i][1]);

    if (l.size() == 0 || r.size() == 0)cout << 0 << endl;
    else {
        sort(l.begin(), l.end());
        sort(r.begin(), r.end());
        cout << l[0] + r[0] << endl;
    }
    return 0;
}