#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> m;
  m["00"] = 0;
  m["01"] = 1;
  m["10"] = 2;
  m["11"] = 3;
  int n;
  cin >> n;
  string s;
  vector<int> a[4];
  for (int i = 0; i < n; i++) {
    cin >> s;
    int aux1 = m[s];
    int aux2;
    cin >> aux2;
    a[aux1].push_back(-aux2);
  }
  for (int i = 0; i < 4; i++) sort(a[i].begin(), a[i].end());
  int sol = 0;
  for (int j = 0; j < (int)a[3].size(); j++) sol -= a[3][j];
  int menor = min(a[1].size(), a[2].size());
  for (int j = 0; j < menor; j++) {
    sol -= a[1][j];
    sol -= a[2][j];
  }
  for (int i = menor; i < (int)a[1].size(); i++) a[0].push_back(a[1][i]);
  for (int i = menor; i < (int)a[2].size(); i++) a[0].push_back(a[2][i]);
  sort(a[0].begin(), a[0].end());
  for (int i = 0; i < (int)a[3].size() and i < (int)a[0].size(); i++) {
    sol -= a[0][i];
  }
  cout << sol << endl;
}
