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 <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int N;
int a[10], w[10];
int ans = INT_MAX;

void solve(int already, vector<int> now){
    bool tmp[10] = {};
    for(int i=0; i<already; i++) tmp[now[i]] = true;
    if(already == N){
        int W = 0;
        for(int i=0; i<N-1; i++){
            if(a[now[i]] == 0 && a[now[i+1]] == 1) W += w[now[i]] + w[now[i+1]];
        }
        if(a[now[N-1]] == 0 && a[now[0]] == 1) W += w[now[N-1]] + w[now[0]];
        ans = min(ans, W);
        return;
    }
    for(int i=0; i<N; i++){
        if(tmp[i] == false){
            now[already] = i;
            solve(already+1, now);
            now[already] = -1;
        }
    }
}

int main(){
    iostream::sync_with_stdio(false);
    
    cin >> N;
    for(int i=0; i<N; i++) cin >> a[i];
    for(int i=0; i<N; i++) cin >> w[i];
    vector<int> tmp;
    tmp.push_back(0);
    for(int i=1; i<N; i++) tmp.push_back(-1);
    solve(1, tmp);
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin >> 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];
	int r = -1, l = -1;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == 0)
			r = (r == -1 ? w[i] : min(r, w[i]));
		else
			l = (l == -1 ? w[i] : min(l, w[i]));
	}
	cout << (r == -1 || l == -1 ? 0 : l + r) << endl;

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
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());
  ans=v[0].second;
  for(int i=0;i<n;++i){
    if(v[i].first==1){
      ans+=v[i].second;
      break;
    }
  }
  
  cout<<ans<<endl;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,s,e) for(int i=s;i<e;i++)

using namespace std;

int main(void) {
	int N, MINR = 1001, MINL = 1001;
	cin >> N;
	vector<int> a(N);
	vector<int> w(N);
	REP(i, N)cin >> a[i];
	REP(i, N)cin >> w[i];
	REP(i, N) {
		if (a[i] == 0 && w[i] < MINR)MINR = w[i];
		else if (a[i] == 1 && w[i] < MINL)MINL = w[i];
	}
	if (MINL == 1001 || MINR == 1001)cout << 0 << endl;
	else cout << MINL + MINR << 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(fi){cout<<ans<<endl;}
  else{cout<<0<<endl;}
}

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

#define int long long

main() {
    int n; cin >> n;
    int lr[] = {-1, 1};
    vector<int> ord;
    vector<int> a(n), w(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i) ord.push_back(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> w[i];
    }
    int ans = 1000000007;
    do {
        int tmp = 0;
        vector<int> cnd{0};
        for (int i = 0; i < n - 1; i++) cnd.push_back(ord[i]);
        for (int i = 0; i < n; i++) {
            if (a[cnd[(i + n + lr[a[cnd[i]]]) % n]] != a[cnd[i]]) {
                tmp += w[cnd[i]];
            }
        }
        ans = min(ans, tmp);
    } while (next_permutation(ord.begin(), ord.end()));
    cout << ans << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
#define PI acos(-1.0)
#define EPS 1e-10
const ll INT = 1e16;
const ll MOD = 1e9 + 7;
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define rep(i,N) FOR(i, 0, N)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).reeal(), (b).real) && EQ((a).imag(), (b).imag()))
#define NIL -1

int main(){
    int n;
    cin>>n;
    vector<int> a(n),w(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>w[i];
    int rmin=100000,lmin=100000;
    rep(i,n){
        if(a[i])lmin=min(lmin,w[i]);
        else rmin=min(rmin,w[i]);
    }
    if(rmin==100000 || lmin==100000)cout<< 0 <<endl;
    else cout<< rmin + lmin <<endl;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n, a[12], w[12], p[12];

  scanf("%d", &n);

  for(int i=0;i<n;i++)
    scanf("%d", a+i);

  for(int i=0;i<n;i++)
    scanf("%d", w+i);

  int ans = INF;
  iota(p, p+n, 0);

  do{
    int sum = 0;
    
    for(int i=0;i<n;i++){
      if(a[p[i]] == 0)
        sum += w[p[i]] * (a[p[i]] != a[p[(i+1)%n]]);
      if(a[p[i]] == 1)
        sum += w[p[i]] * (a[p[i]] != a[p[(i+n-1)%n]]);
    }

    ans = min(ans, sum);

  }while(next_permutation(p, p+n));

  cout << ans << endl;
  
  return 0;
}