#include <bits/stdc++.h>
using namespace std;
const bool testing = false;
const int m = 500007;
long long DP[m];
long long C[m];
void program() {
  int n;
  cin >> n;
  int t;
  for (size_t i = 0; i < m; i++) {
    C[i] = DP[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> t;
    C[t]++;
  }
  DP[1] = C[1];
  DP[2] = C[2] * 2;
  for (long long i = 3; i < m; i++) {
    DP[i] = std::max(DP[i - 2] + C[i] * i, DP[i - 3] + C[i] * i);
  }
  cout << DP[m - 1] << std::endl;
}
int main() {
  if (!testing) {
    program();
    return 0;
  }
  FILE* fin = NULL;
  fin = fopen("in.txt", "w+");
  fprintf(fin, "2\n1 2\n");
  fclose(fin);
  freopen("in.txt", "r", stdin);
  printf("test case(1) => expected : \n");
  printf("2\n");
  printf("test case(1) => founded  : \n");
  program();
  fin = fopen("in.txt", "w+");
  fprintf(fin, "3\n1 2 3\n");
  fclose(fin);
  freopen("in.txt", "r", stdin);
  printf("test case(2) => expected : \n");
  printf("4\n");
  printf("test case(2) => founded  : \n");
  program();
  fin = fopen("in.txt", "w+");
  fprintf(fin, "9\n1 2 1 3 2 2 2 2 3\n");
  fclose(fin);
  freopen("in.txt", "r", stdin);
  printf("test case(3) => expected : \n");
  printf("10\n");
  printf("test case(3) => founded  : \n");
  program();
  return 0;
}
