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<vector>
#include<algorithm>
using namespace std;

int solve(vector<int> R, vector<int> L){
  if ( R.size() == 0 || L.size() == 0 ) return 0;
  sort(R.begin(), R.end());
  sort(L.begin(), L.end());
  return R[0] + L[0];
}

int main() {
  int A[10], W[10];
  int N, a, w;
  vector<int> R, L;
  cin >> 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] == 0 ) R.push_back(W[i]);
    if ( A[i] == 1 ) L.push_back(W[i]);
  }

  cout << solve(R, L) << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed 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];
  vector<int> x,y;
  for(int i=0;i<n;i++)
    (a[i]?x:y).emplace_back(w[i]);
  if(x.empty()||y.empty()){
    cout<<0<<endl;
    return 0;
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  cout<<x[0]+y[0]<<endl;
  return 0;
}

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

#define int long long

using namespace std;

signed main() {
	int n;
	cin >> n;

	vector<int> left;
	vector<int> right;

	vector<int> lrs;

	for (int i = 0; i < n; i++) {
		int v;
		cin >> v;
		lrs.emplace_back(v);
	}

	for (int i = 0; i < n; i++) {
		int val;
		cin >> val;
		if (lrs[i] == 1)left.emplace_back(val);
		else right.emplace_back(val);
	}

	sort(left.begin(), left.end());
	sort(right.begin(), right.end());

	if (left.size() == n || right.size() == n) {
		cout << 0 << endl;
	}
	else {
		cout << left[0] + right[0] << endl;
	}
}

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

using namespace std;

using i64 = long long int;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()

int main(){
    i64 n;
    cin >> n;
    vector<i64> a(n), w(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> w[i];
    vector<i64> pat(n);
    rep(i, n) pat[i] = i;
    i64 ans = numeric_limits<i64>::max();
    do{
        i64 cost = 0;
        rep(i, n){
            if(i == 0){
                if(a[pat[i]] == 1 && a[pat[i + 1]] == 0) cost += w[pat[i]];
                if(a[pat[i]] == 0 && a[pat[n - 1]] == 1) cost += w[pat[i]];
            }else if(i == n - 1){
                if(a[pat[i]] == 1 && a[pat[0]] == 0) cost += w[pat[i]];
                if(a[pat[i]] == 0 && a[pat[i - 1]] == 1) cost += w[pat[i]];
            }else{
                if(a[pat[i]] == 1 && a[pat[i + 1]] == 0) cost += w[pat[i]];
                if(a[pat[i]] == 0 && a[pat[i - 1]] == 1) cost += w[pat[i]];
            }
        }
        ans = min(ans, cost);
    }while(next_permutation(all(pat)));
    cout << ans << endl;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    cin >> n;
    vi a(n),b(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    vi v(2,INF);
    rep(i,n){
        v[a[i]] = min(v[a[i]],b[i]);
    }
    if(v[0] == INF || v[1] == INF){
        cout << 0 << endl;
    }else{
        cout << v[0] + v[1] << endl;
    }
}

C++: #include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;


int main() {
	int N;cin>>N;
	vector<int>ls(N),nums(N);
	for(int i=0;i<N;++i)cin>>ls[i];
	for(int i=0;i<N;++i)cin>>nums[i];

	int min_l=1e9+1,min_r=1e9+1;
	for (int i = 0; i < N; ++i) {
		if (ls[i]) {
			min_r=min(min_r,nums[i]);
		}
		else {
			min_l=min(min_l,nums[i]);
		}
	}
	if(min_l+min_r>=1e9)cout<<0<<endl;
	else {
		cout<<min_l+min_r<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(a,n) rep(i,0,n){ cout<<(i ? " ":"")<<a[i]; }cout<<endl;
#define pprint(a,m,n) rep(j,0,m){ print(a[j],n); }
const int mod = 1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	int N;cin>>N;
	int A[N],W[N];priority_queue<int> left,right;
	rep(i,0,N) cin>>A[i];
	rep(i,0,N){
		cin>>W[i];
		if(A[i]) left.push(-W[i]);
		else right.push(-W[i]); 
	}
	if(left.empty()||right.empty()) cout<<0<<endl;
	else cout<<-left.top()-right.top()<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[20],b[20];
int main(){
	int n;cin>>n;
	rep(i,n)scanf("%d",&a[i]);
	rep(i,n)scanf("%d",&b[i]);
	vector<int>v;
	rep(i,n)v.push_back(i);
	int Min=INT_MAX;
	do{
		int cnt=0;
		rep(i,n){
			int j=v[i],k;
			if(a[v[i]]==0){
				k=v[(i+1)%n];
			}
			else{
				k=v[(i+n-1)%n];
			}
			if(a[j]!=a[k])cnt+=b[j];
		}
		Min=min(Min,cnt);
	}while(next_permutation(v.begin(),v.end()));
	cout<<Min<<endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
//typedef long long int ll;
//typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	int n;
	cin>>n;
	vector<int> a(n),bb(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>bb[i];
	}
	bool r=false;
	bool l=false;
	int rr=inf,ll=inf;

	for(int i=0;i<n;i++){
		//int b,c;
		//cin>>b>>c;
		int b = a[i],c = bb[i];
		if(b==0){
			r = true;
			rr = min(rr,c);
		}else{
			l = true;
			ll = min(ll,c);
		}
	}
	if(l&&r){
		cout<<rr+ll<<endl;
	}else{
		cout<<0<<endl;
	}


	return 0;
}

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

int N, A[1 << 18], W[1 << 18], minx = (1 << 30);
int p[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> W[i];

	do {
		int sum = 0;
		for (int i = 0; i < N; i++) {
			if (A[p[i]] == 0) {
				if (A[p[(i + 1) % N]] == 1) sum += W[p[i]];
			}
			else {
				if (A[p[(i + N - 1) % N]] == 0) sum += W[p[i]];
			}
		}
		minx = min(minx, sum);
	} while (next_permutation(p, p + N));

	cout << minx << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll N; cin >> N;
    ll a[100005];
    ll f1,f0;
    f1 = f0 = false;
    for (int i = 0;i < N;i++){
        cin >> a[i];
        if(a[i] == 0) f0 = true;
        if(a[i] == 1) f1 = true;
    }
    ll w[100005];
    for (int i = 0;i < N;i++){
        cin >> w[i];
    }

    if(!f0 || !f1) cout << 0 << endl;
    else{
        ll s,t;
        s = t = INT_MAX;
        for (int i = 0;i < N;i++){
            if(a[i] == 0) s = min(s,w[i]);
            else t = min(t,w[i]);
        }
        cout << s+t << endl;
    }

    return 0;

}