public void solve() throws IOException {
    List<Integer> odd = new ArrayList<Integer>();
    List<Integer> even = new ArrayList<Integer>();
    
    String[] data = nextLine().split(" ");
    for (int x = 0; x < data.length; x += 2) {
      int value = Integer.parseInt(data[x + 1]);
      if (value % 2 == 0) {
        even.add(value);
      } else {
        odd.add(value);
      }
    }
    
    Collections.sort(odd);
    Collections.sort(even);
    int len = Math.min(4, Math.min(odd.size(), even.size()));
    int total = 0;
    for (int x = 1; x <= len; x++) {
      total += odd.get(odd.size() - x);
      total += even.get(even.size() - x);
    }
    if (odd.size() > len && len < 4) {
      total += odd.get(odd.size() - len - 1);
    }
    System.out.println(total);
  }