#include <bits/stdc++.h>
using namespace std;
long long glob_cnt = 0;
int minKey(int key[], bool mstSet[]) {
  int min = INT_MAX, min_index;
  for (int v = 0; v < 10; v++)
    if (mstSet[v] == false && key[v] < min) min = key[v], min_index = v;
  return min_index;
}
int printMST(int parent[], int n, int graph[10][10]) {
  printf("Edge   Weight\n");
  for (int i = 1; i < 10; i++) {
    printf("%d - %d    %d \n", parent[i], i, graph[i][parent[i]]);
    glob_cnt += graph[i][parent[i]];
  }
}
void primMST(int graph[10][10]) {
  int parent[10];
  int key[10];
  bool mstSet[10];
  for (int i = 0; i < 10; i++) key[i] = INT_MAX, mstSet[i] = false;
  key[0] = 0;
  parent[0] = -1;
  for (int count = 0; count < 10 - 1; count++) {
    int u = minKey(key, mstSet);
    mstSet[u] = true;
    for (int v = 0; v < 10; v++)
      if (graph[u][v] && mstSet[v] == false && graph[u][v] < key[v])
        parent[v] = u, key[v] = graph[u][v];
  }
  printMST(parent, 10, graph);
}
int main() {
  long long cnt = 0;
  long long n;
  cin >> n;
  cnt += n / 2;
  for (long long i = 2; i < n; i *= 2) {
    cnt += i;
    long long razl = min(i * 2, n) - i - 1;
    razl /= 2;
    long long mnoz = 2;
    while (razl > 0) {
      if (razl % 2 == 0)
        cnt += (razl / 2) * mnoz;
      else
        cnt += (razl / 2 + 1) * mnoz;
      razl /= 2;
      mnoz *= 2;
    }
  }
  cout << cnt << endl;
  return 0;
}
