#include <bits/stdc++.h>
#include <algorithm>
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF ((1LL<<62)-(1LL<<31)) 
#define MOD 1000000007
using ll = long long;
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    int a, b, x, y;
    cin >> a >> b >> x >> y;

    int diff;
    if (a <= b) diff = abs(a - b);
    else diff = abs(a - b) - 1;
    int up = min(x * 2, y);

    int res = diff * up + x;

    cout << res;

}
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template <class T>
void read(T &);
template <class T>
void write(const T &);

typedef long long ll;
typedef unsigned long long ull;
typedef const long long &cll;
typedef const int &ci;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;
using std::abs;
using std::max;
using std::min;

int main() {
  int n, k;
  read(n), read(k);
  ll ans = 0;
  for (int i = max(2, k + 2); i <= 2 * n; ++i) {
    if (i - 2 * n > k) {
      break;
    }
    int na, nb;
    if (i <= n) {
      na = i - 1;
    } else {
      na = 2 * n - i + 1;
    }
    if (i - k <= n) {
      nb = i - k - 1;
    } else {
      nb = 2 * n - (i - k) + 1;
    }
    ans += na * 1ll * nb;
  }
  write(ans), EL;
  return 0;
}

template <class T>
inline void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!isNum(ch)) {
    if (ch == '-') {
      flag = -1;
    }
    ch = getchar();
  }
  while (isNum(ch)) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template <class T>
inline void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}
