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;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

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

    VI a(n), w(n);
    cin >> a; cin >> w;
    VI l, r;
    FOR(i, 0, n) {
        if (a[i] == 0)r.push_back(w[i]);
        else l.push_back(w[i]);
    }
    bool ng = false;
    if (l.empty())ng = true;
    else SORT(l);
    if (r.empty())ng = true;
    else SORT(r);
    cout << (ng ? 0 : l[0] + r[0]) << "\n";
}

C++: // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1 << 28;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    int mi0 = INF, mi1 = INF;
    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];
        if(a[i] == 0) mi0 = min(mi0, w[i]);
        if(a[i] == 1) mi1 = min(mi1, w[i]);
    }

    if(mi0 == INF or mi1 == INF) cout << 0 << endl;
    else cout << mi0 + mi1 << endl;
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<P> v1, v2;
    int A[n + 1], W[n + 1];
    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] == 1) v1.push_back(P(A[i], -W[i]));
        else v1.push_back(P(A[i], W[i]));
        if(A[i] == 0) v2.push_back(P(A[i], -W[i]));
        else v2.push_back(P(A[i], W[i]));
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end(), greater<P>());
    int ans = v1[0].second - v1.back().second; 
    int idx = -1;
    for(int i = 0; i < v2.size() - 1; i++)
    {
        if(v2[i].first != v2[i + 1].first)
        {
            idx = i;
            break;
        }
    }
    if(idx == -1) cout << 0 << endl;
    else
    {
        ans = min(ans, v2[idx].second - v2[idx + 1].second);
        cout << ans << endl;
    }
    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {

    int N; cin >> N;
    vector<int> a(N), w(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> w[i];

    vector<int> v(N, 0);
    iota(v.begin(), v.end(), 0);
    int ans = 1e8;
    do {

        int tmp = 0;
        rep(i, N) {
            // 右効き

            if (a[v[i]] == 0) {
                if (i+1 == N) {
                    if (a[v[0]] == 1) tmp += w[v[i]];
                }
                else {
                    if (a[v[i+1]] == 1) tmp += w[v[i]];
                }
            }
            else {
                if (i == 0) {
                    if (a[v[N-1]] == 0) tmp += w[v[i]];
                }
                else {
                    if (a[v[i-1]] == 0) tmp += w[v[i]];
                }
            }
        }

        ans = min(ans, tmp);

    } while (next_permutation(v.begin(), v.end()));

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

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

using namespace std;

int N;
vector<int> PersonId;
vector<int> PersonInfo;
vector<int> Claim;

void solve() {
	int p1, p2, sum, minTotal;

	minTotal = 10000000;
	do {
		sum = 0;
		for (int i = 0; i < N; ++i) {
			p1 = PersonInfo[PersonId[i]];
			p2 = PersonInfo[PersonId[(i + 1) % N]];
			if (!p1 && p2) {
				sum += Claim[PersonId[i]] + Claim[PersonId[(i + 1) % N]];
			}
		}
		minTotal = min(minTotal, sum);
	} while (next_permutation(PersonId.begin(), PersonId.end()));

	cout << minTotal << endl;
}

int main() {
	int num;

	cin >> N;
	for (int i = 0; i < N; ++i) {
		PersonId.push_back(i);
		cin >> num;
		PersonInfo.push_back(num);
	}
	for (int i = 0; i < N; ++i) {
		cin >> num;
		Claim.push_back(num);
	}
	solve();

	return 0;
}

C++: #include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

int N;
bool rl[100];
bool check[2] = {};
int b = INF, x = INF;
int a, w;

int main() {
	cin >> N;
	REP(i, N) {
		cin >> rl[i];
		check[rl[i]] = true;
	}
	REP(i, N) {
		if (rl[i] == 0)
		{
			cin >> a;
			b = min(b, a);
		}
		else {
			cin >> w;
			x = min(x, w);
		}
	}
	if (!check[0] || !check[1]) {
		cout << 0 << endl;
		return 0;
	}
	
	cout << b + x << endl;
}

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;
}