n, x = map(int, input().split())
if (n%2 ==1):
    print((n-1)*3)
elif (n==2):
    print(3)
else:
    k=n/2
    if (x<k):
        print((n-x)*k)
    elif(x==k):
        print(k*3)
    else:
        print(x*k)
