#include <iostream>
using namespace std;
int main()
{
int a = 0, b = 0, n, k, s = 0;
cin >> n >> k;
a = n / 3;
n -= a * 3;
b = a / 3;
a -= b * 3;
for (int i = 0; i < b; i += 0)
{
if (k != 0)
{
k--;
s += 16 * b;
b--;
}
else
{
break;
}
}
for (int i = 0; i < a; i += 0)
{
if (k != 0)
{
k--;
s += 4 * a;
a--;
}
else
{
break;
}
}
for (int i = 0; i < n; i += 0)
{
if (k != 0)
{
k--;
s++;
n--;
}
else
{
break;
}
}
cout << s;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkKewogICAgaW50IGEgPSAwLCBiID0gMCwgbiwgaywgcyA9IDA7CiAgICBjaW4gPj4gbiA+PiBrOwogICAgYSA9IG4gLyAzOwogICAgbiAtPSBhICogMzsKICAgIGIgPSBhIC8gMzsKICAgIGEgLT0gYiAqIDM7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IGI7IGkgKz0gMCkKICAgIHsKICAgICAgICBpZiAoayAhPSAwKQogICAgICAgIHsKICAgICAgICAgICAgay0tOwogICAgICAgICAgICBzICs9IDE2ICogYjsKICAgICAgICAgICAgYi0tOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICB9CiAgICBmb3IgKGludCBpID0gMDsgaSA8IGE7IGkgKz0gMCkKICAgIHsKICAgICAgICBpZiAoayAhPSAwKQogICAgICAgIHsKICAgICAgICAgICAgay0tOwogICAgICAgICAgICBzICs9IDQgKiBhOwogICAgICAgICAgICBhLS07CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgIH0KICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSArPSAwKQogICAgewogICAgICAgIGlmIChrICE9IDApCiAgICAgICAgewogICAgICAgICAgICBrLS07CiAgICAgICAgICAgIHMrKzsKICAgICAgICAgICAgbi0tOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IHM7Cn0K