#include <bits/stdc++.h>
class Task {
  int64_t *dp;

 public:
  Task();
  int64_t solve(int32_t x);
  int64_t *count;
  static const int32_t MAX;
};
Task::Task() {
  dp = new int64_t[Task::MAX];
  count = new int64_t[Task::MAX];
  std::fill(dp, dp + Task::MAX, 0);
  std::fill(count, count + Task::MAX, 0);
  dp[0] = 0;
}
int64_t Task::solve(int32_t x) {
  dp[1] = count[1];
  for (int32_t i = 2; i <= x; i++) {
    dp[i] = std::max(dp[i - 1], dp[i - 2] + i * count[i]);
  }
  return dp[x];
}
const int Task::MAX = 1e5 + 1;
int main() {
  int32_t n, temp;
  std::cin >> n;
  Task t;
  for (int32_t i = 1; i <= n; i++) {
    std::cin >> temp;
    t.count[temp]++;
  }
  std::cout << t.solve(Task::MAX) << std::endl;
  return 0;
}
