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

Python: n = int(input())
aw = [[0,0] for i in range(n)]
for i, a in enumerate(map(int, input().split())): aw[i][0] = a
for i, w in enumerate(map(int, input().split())): aw[i][1] = w
migimin = 1001
hidarimin = 1001
for a,w in aw:
    if a: hidarimin = min(hidarimin, w)
    else: migimin = min(migimin, w)
if hidarimin>1000 or migimin>1000: print(0)
else: print(hidarimin+migimin)

Python: n = int(input())
a = [int(_) for _ in input().split()]
w = [int(_) for _ in input().split()]

if sum(a) == n or sum(a) == 0:
    print(0)
    quit()

lia = []
lib = []
for i in range(n):
    if a[i] == 0:
        lia.append(w[i])
    else:
        lib.append(w[i])

print(min(lia)+min(lib))

Python: n = int(input())
a = list(map(int,input().split()))
w = list(map(int,input().split()))

INF = 10**9
x = [INF]*2
for i in range(n):
    x[a[i]] = min(x[a[i]], w[i])

ans = sum(x)
if ans >= INF:
    ans = 0
print(ans)

Python: N = input()
a = [int(x) for x in input().split()]
w = [int(x) for x in input().split()]

R = [w for a, w in zip(a, w) if a == 0]
L = [w for a, w in zip(a, w) if a == 1]

if R and L:
    print(min(R) + min(L))
else:
    print(0)

Python: n = int(input())
alst = list(map(int, input().split()))
wlst = list(map(int, input().split()))
right = [w for a, w in zip(alst, wlst) if a == 0]
left = [w for a, w in zip(alst, wlst) if a == 1]
if right and left:
  print(min(right) + min(left))
else:
  print(0)

Python: 
N = int(input())
a = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]

rightMin = 1001
leftMin = 1001

for i in range(N):
    if a[i] == 0:
        rightMin = min(rightMin, w[i])
    else:
        leftMin = min(leftMin, w[i])

if rightMin == 1001 or leftMin == 1001:
    print(0)
else:
    print(rightMin + leftMin)

Python: N = int(input())
*A, = map(int, input().split())
*W, = map(int, input().split())
INF = 10**9
l = r = INF
for a, w in zip(A, W):
    if a:
        r = min(w, r)
    else:
        l = min(w, l)
if l == INF or r == INF:
    print(0)
else:
    print(l+r)

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

#define ALL(a) (a).begin(), (a).end()
#define int long long

using namespace std;

signed main(){
	
	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];
	}

	vector<int> p(n);
	for(int i = 0; i < n; i++) p[i] = i;
	int ans = 1000000000000000007;
	
	do{
		int tmp = 0;
		for(int i = 0; i < n; i++){
			int val = a[p[i]];
			if(val == 0){
				// みぎきき
				// int idx = 
				int idx = (i + 1) % n;
				int val2 = a[p[idx]];
				if(val2 == 1) tmp += w[p[i]];
			}else{

				int idx = (i + n - 1) % n;
				int val2 = a[p[idx]];
				if(val2 == 0) tmp += w[p[i]];
			}
		}

		ans = min(ans, tmp);
	}while(next_permutation(p.begin(), p.end()));
	
	cout << ans << endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n; cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	int x = 10000; int y = 10000;
	for (int i = 0; i < n; i++) {
		if (a[i] == 0) x = min(x, b[i]);
		else y = min(y, b[i]);
	}
	if (x == 10000 || y == 10000) cout << 0 << endl;
	else cout << x + y << endl;
	return 0;
}

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

int main(){
	int n,ans=1e9;
	cin>>n;
	int a[n],w[n],A[n];
	r(i,n)cin>>a[i];
	r(i,n)cin>>w[i];
	r(i,n)A[i]=i;
	do{
		int sum=0;
		for(int i=0;i<n;i++){
			int X=a[A[i]];
			int Y=a[A[(i+1)%n]];
			if(X&&!Y){
				sum+=w[A[(i+1)%n]]+w[A[i]];
			}
		}
		ans=min(sum,ans);
	}while(next_permutation(A,A+n));

	cout<<ans<<endl;
}

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

int main(){
    int N;cin>>N;
    vector<int> vec;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec.push_back(b);
    }
    vector<int> b1,b2;
    for(int a= 0;a < N;a++){
        int b;cin >> b;
        if(vec.at(a) == 0)b1.push_back(b);
        if(vec.at(a) == 1)b2.push_back(b);
    }
    if(b1.empty() || b2.empty()){
        cout<<0<<endl;
    }else{
        cout<<*min_element(b1.begin(),b1.end())+*min_element(b2.begin(),b2.end())<<endl;
    }
}
//2t+2

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), w(n);
  vector<int> r, l;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> w[i];
    if (a[i]) {
      l.push_back(w[i]);
    } else {
      r.push_back(w[i]);
    }
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  if (l.size() == 0 || r.size() == 0) {
    cout << 0 << endl;
  } else {
    cout << r[0] + l[0] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
  ll n,vl=1e9,vr=1e9,a[11];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++){
      ll w; cin>>w;
      if(a[i]==0)vl=min(vl,w);
      if(a[i]==1)vr=min(vr,w);
  }
  if(vl==1e9||vr==1e9)cout<<0<<endl;
  else cout<<vl+vr<<endl;
  return 0;
}

C++: #include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int a[10],w[10],i,m[2],cnt,n,x;
	scanf("%d",&n);
	m[0]=9999;	m[1]=9999;
	cnt=0;
	for(i=0;i<n;i++)	{
		scanf("%d",&a[i]);
		cnt+=a[i];
	}
	for(i=0;i<n;i++)	{
		scanf("%d",&w[i]);
		m[a[i]]=min(m[a[i]],w[i]);
	}
	if(cnt==n || cnt==0)	x=0;
	else x=m[0]+m[1];
	printf("%d\n",x);
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int IINF = INT_MAX;

int main() {
    int n, a[10], l=IINF, r=IINF;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        int w;
        cin >> w;
        if(a[i]) l = min(l, w);
        else r = min(r, w);
    }
    if(l==IINF || r==IINF){
        cout << 0 << endl;
    }
    else{
        cout << l+r << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
  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=1001,lmin=1001,rnum=0,lnum=0;
  for(int i=0;i<n;++i){
    if(a[i]==0){
      if(rmin>w[i]) rmin = w[i];
      rnum++;
    }else{
      if(lmin>w[i]) lmin = w[i];
      lnum++;
    }
  }

  if(rnum==n||lnum==n){
    rmin=0;
    lmin=0;
  }

    cout << rmin + lmin << endl;
  
  return 0;
}