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 rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=100000000000000000;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a.at(i);
    }
    vector<int> b(0),c(0);
    int o;
    rep(i,n){
        cin >> o;
        if (a.at(i)==0) b.push_back(o);
        else c.push_back(o);
    }
    if (b.size()==0 || c.size()==0) {cout << 0 << endl;return 0;} 
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    cout << b.at(0)+c.at(0) << endl;

}

C++: #include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>
#include<utility>
#define LL long long
using namespace std;



int main() {
	int N, a[20], w[20], rmin=10000, lmin=10000;
	cin >> N;
	for (int i = 0; i < N; i++)cin >> a[i];
	for (int i = 0; i < N; i++) {
		cin >> w[i];
		if (a[i])rmin = min(rmin, w[i]);
		else lmin = min(lmin, w[i]);
	}
	if (rmin == 10000 || lmin == 10000)cout << 0 << endl;
	else cout << rmin + lmin << endl;

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
bool fin;
int main(){
  int n,ans;
  cin>>n;
  vector<pair<int,int> >v(n);
  for(int i=0;i<n;++i){cin>>v[i].first;}
  for(int i=0;i<n;++i){cin>>v[i].second;}
  
  sort(v.begin(),v.end());
  if(v[0].first==1){
    cout<<0<<endl;
    return 0;
  }
  ans=v[0].second;
  for(int i=0;i<n;++i){
    if(v[i].first==1){
      ans+=v[i].second;
      fin=1;
      break;
    }
  }
  if(fin){cout<<ans<<endl;}
  else{cout<<0<<endl;}
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <numeric>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	/*
	int n;
	cin >> n;
	vector<vector<int>> f(n, vector<int>(6));
	for(int j = 0; j < n; j++)
		for (int i = 0; i < 6; i++) cin >> f[j][i];

	// 相手のカードもわかる 6 + 6 + 1 = 13のため
	bool win = true;


	// 自分が出し終わるあとの数字が相手に残っている
	*/

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

	int rmin = 10000;
	int lmin = 10000;

	bool all = true;
	int r = a[0];
	for (int i = 0; i < n; i++) {
		if (r != a[i]) {
			all = false;
		}
		if (a[i] == 0) rmin = min(rmin, w[i]);
		else lmin = min(lmin, w[i]);
	}

	if (all) cout << 0 << endl;
	else cout << rmin + lmin << endl;

}

C++: #include<iostream>
using namespace std;
#define min(a,b) (a>b?b:a)
#define MAX 1010
#define INF 12345678

int N, a[MAX], w[MAX], used[11]={1,};

int huga(int t, int y){
	int dis = 0;
	if(!a[t]&&a[y]) dis += w[t];
	if(a[y]&&!a[t]) dis += w[y];
	return dis;
}

int solve(int z){//cout<<z<<endl;
	int ans = INF, count = 0;
	
	for(int i = 0; i < N; i++){
		if(used[i]) continue;
		used[i] = true;
		ans = min(ans,solve(i)+huga(z,i));
		used[i] = false;
		count++;
	}//cout<<z<<" "<<ans<<" "<<count<<endl;
	if(count == 0) return huga(z,0);
	return ans;
}

int main(){
	cin>>N;
	for(int i = 0; i < N; i++)cin>>a[i];
	for(int i = 0; i < N; i++)cin>>w[i];
	
	cout<<solve(0)<<endl;
	return 0;
}

/*
5
1 0 0 1 0
2 3 5 1 2

3
0 0 0
1 2 3
*/

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> left, right;
    vector<int> lr(N);
    for (int i = 0; i < N; i++) cin >> lr[i];
    for (int t : lr) {
        int a;
        cin >> a;
        if (t == 0)
            right.push_back(a);
        else
            left.push_back(a);
    }
    if (min(right.size(), left.size()) == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(right.begin(), right.end());
    sort(left.begin(), left.end());
    cout << right[0] + left[0] << endl;
    return 0;
}

C++: #include<bits/stdc++.h>
#define INF INT_MAX
using namespace std;
int main(void){
	int n;
	cin >> n;
	int a[n], b[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	int rmn = INF, lmn = INF;
	for(int i = 0; i < n; i++){
		if(a[i]) lmn = min(lmn, b[i]);
		else rmn = min(rmn, b[i]);
	}
	if(rmn == INF || lmn == INF) cout << 0 << endl;
	else cout << rmn + lmn << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin >> n;
    
    vector<int> te(n);
    vector<int> fu(n);
    
    for( int i = 0; i < n; i++ ){
        cin >> te[i];
    }
    
    for( int i = 0; i < n; i++ ){
        cin >> fu[i];
    }
    
    int left = 1001, right = 1001, lc = 0, rc = 0;
    for( int i = 0; i < n; i++ ){
        if( te[i] == 0 ){
            if( right > fu[i] ){
                right = fu[i];
                rc++;
            }
        }
        
        if( te[i] == 1 ){
            if( left > fu[i] ){
                left = fu[i];
                lc++;
            }
        }
    }
    
    if( lc == 0 || rc == 0 ){
        cout << 0 << endl;
    }else{
        cout << right + left << endl;
    }
}

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

const int inf = (1 << 30) - 1;

int main()
{
	int N;
	int A[15], W[15];
	int minv[2];

	cin >> N;

	for ( int i = 0; i < N; i++ ) cin >> A[i];
	for ( int i = 0; i < N; i++ ) cin >> W[i];
	
	minv[0] = minv[1] = inf;

	for ( int i = 0; i < N; i++ ) {
		minv[A[i]] = min(minv[A[i]], W[i]);
	}

	if ( minv[0] == inf || minv[1] == inf ) {
		cout << 0 << endl;
	} else {
		cout << minv[0] + minv[1] << endl;
	}

	return ( 0 );
}

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

int main(){
    int N;
    cin >> N;
    vector<int> hand(N), w(N), yancle;
    for(int i = 0; i < N; i++) cin >> hand[i];
    for(int i = 0; i < N; i++) cin >> w[i];
    for(int i = 1; i < N; i++) yancle.emplace_back(i);

    int ans = 1e9;
    do{ 
        int res = 0;
        int left = yancle[N-3];
        int mid = yancle[N-2];
        int right = 0;
        for(int n = 0; n < N; n++){
            if(hand[mid] == 0 && hand[right] == 1) res += w[mid];
            if(hand[mid] == 1 && hand[left] == 0) res += w[mid];
            left = mid;
            mid = right;
            if(n < N-1) right = yancle[n];
        }
        ans = min(ans, res);
    }while(next_permutation(yancle.begin(), yancle.end()));

    cout << ans << endl;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n; cin >> n;
	VI a(n), w(n);
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> w[i];

	VI l, r;
	rep(i, n) {
		if (a[i])l.pb(w[i]);
		else r.pb(w[i]);
	}

	int ans;
	if (l.empty() || r.empty()) {
		ans = 0;
	}
	else {
		ans = *min_element(all(l)) + *min_element(all(r));
	}
	Cout(ans);
}