CodeEff/ECCO huggingface dataset:
# Original solution
import sys
sys.setrecursionlimit(10 ** 6)
n = int(eval(input()))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors



ansl = list(set(make_divisors(n-1)))
ansl.remove(1)

import sys
sys.setrecursionlimit(10 ** 6)

def check(i, k):
    if i == 1:
        return True
    if i < 1:
        return False
    if i % k == 0:
        return check(i // k, k)
    else:
        return check(i - k, k)

ansl2 = []
for i in make_divisors(n):
    if i == 1:
        continue
    elif i == 2:
        ansl.append(2)
    elif check(n, i):
        ansl2.append(i)

print((len(set(ansl + ansl2))))

# Optimized solution
n = int(eval(input()))


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors



ansl = make_divisors(n-1)
ansl.remove(1)
for i in make_divisors(n):
    if i == 1:
        continue
    k = n
    while k:
        if k % i == 0:
            k //= i
        else:
            if k % i == 1:
                ansl.append(i)
            break

print((len(set(ansl))))
# Original solution
import sys,math,copy,queue,itertools,bisect
NI = lambda : int(sys.stdin.readline())
INF = 10**18

N = NI()
if N == 2:
    print((1))
    exit (0)
ans = 0
max_b = int(math.log(N,2))
for x in range(2,int(math.sqrt(N-1))+1):
    if (N-1) % x == 0:
        if (N-1) == x**2:
            ans += 1
        else:
            ans += 2
for x in range(1, int(math.sqrt(N)) + 1):
    if N % x == 0:
        for b in range(1,max_b+1):
            k = round(x**(1/b))
            if k**b == x and k > 1:
                if (N//x-1) % k == 0:
                    ans += 1
            if x**2 != N:
                x = N // x
                k = round(x ** (1 / b))
                if k ** b == x and k > 1:
                    if (N // x - 1) % k == 0:
                        ans += 1

print((ans+1))



# Optimized solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    max_i = int(math.log2(N))
    div = []
    for i in range(1,int(math.sqrt(N))+1):
        if N % i == 0:
            div.append((i,N//i)); div.append((N//i,i))

    ans = 0
    for a,b in div:
        if a == 1:
            for i in range(1,int(math.sqrt(b-1))+1):
                if (b-1) % i == 0:
                    p = 2 - (i*i == b-1) - (i == 1)
                    ans += p
        else:
            for i in range(1,max_i+1):
                c = round(math.pow(a,1/i))
                if c ** i == a:
                    if b % c == 1: ans += 1
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
sqrt_N = int(N ** 0.5) + 1

dividers_for_N = [N]
ans_list = [N - 1]

for i in range(2, sqrt_N + 1):
    if (N - 1) % i == 0:
        ans_list.append(i)
        ans_list.append((N - 1) // i)

    if N % i == 0:
        dividers_for_N.append(i)
        dividers_for_N.append(N // i)

for i in dividers_for_N:
    num = N
    while num % i == 0:
        num //= i
    if num % i == 1:
        ans_list.append(i)

ans = len(set(ans_list))

print(ans)

# Optimized solution
N = int(eval(input()))
sqrt_N = int(N ** 0.5)

dividers_for_N = set()
ans_set = set()

for i in range(1, sqrt_N + 1):
    if (N - 1) % i == 0:
        ans_set.add(i)
        ans_set.add((N - 1) // i)

    if N % i == 0:
        dividers_for_N.add(i)
        dividers_for_N.add(N // i)

dividers_for_N -= {1}
ans_set -= {1}

for i in dividers_for_N:
    num = N
    while num % i == 0:
        num //= i
    if num % i == 1:
        ans_set.add(i)

ans = len(ans_set)

print(ans)
# Original solution
N = int(eval(input()))
sqrt_N = int(N ** 0.5)

dividers_for_N = set()
ans_set = set()

for i in range(1, sqrt_N + 1):
    if (N - 1) % i == 0:
        ans_set.add(i)
        ans_set.add((N - 1) // i)

    if N % i == 0:
        dividers_for_N.add(i)
        dividers_for_N.add(N // i)

dividers_for_N -= {1}
ans_set -= {1}

for i in dividers_for_N:
    num = N
    while num % i == 0:
        num //= i
    if num % i == 1:
        ans_set.add(i)

ans = len(ans_set)

print(ans)

# Optimized solution
N = int(eval(input()))
sqrt_N = int(N ** 0.5)

dividers_for_N = []
ans_list = []

for i in range(1, sqrt_N + 1):
    if (N - 1) % i == 0:
        ans_list.append(i)
        if i != (N - 1) // i:
            ans_list.append((N - 1) // i)

    if N % i == 0:
        dividers_for_N.append(i)
        if i != N // i:
            dividers_for_N.append(N // i)

dividers_for_N.remove(1)
ans_list.remove(1)
        
for i in dividers_for_N:
    num = N
    while num % i == 0:
        num //= i
    if num % i == 1:
        ans_list.append(i)

ans = len(ans_list)

print(ans)
# Original solution
from copy import deepcopy

# 約数を全列挙する関数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors

N0 = int(eval(input()))
ans = 0

# N = K^a (bK + 1) と表現できるので K は N or N-1 の約数であることが必要
K_cand = set(make_divisors(N0) + make_divisors(N0-1))

for K in K_cand:
    N = deepcopy(N0)
    if K == 1:  # K = 1 を除外
        continue
    else:
        while N%K == 0:
            N = N // K  # 割れるだけ割る
        N = N%K  # 引けるだけ引く
        if N == 1:
            ans += 1

print(ans)


# Optimized solution
# 約数を全列挙する関数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors

N0 = int(eval(input()))
ans = 0

# N = K^a (bK + 1) と表現できるので K は N or N-1 の約数であることが必要
K_cand = set(make_divisors(N0) + make_divisors(N0-1))

for K in K_cand:
    N = N0
    if K == 1:  # K = 1 を除外
        continue
    else:
        while N%K == 0:
            N = N // K  # 割れるだけ割る
        N = N%K  # 引けるだけ引く
        if N == 1:
            ans += 1

print(ans)
# Original solution
N=int(eval(input()))
if N==2:
  print((1))
  exit()
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)

    # divisors.sort()
  return divisors
#N-1の約数(1は除く)　Nそのもの
#2
d=make_divisors(N-1)
if not 2 in d:
  d.append(2)
#print(d)
d2=make_divisors(N)
#print(len(d))
for i in d2:
  if i!=N and i!=1 and i not in d:
    now=N
    while now%i==0:
      now/=i
    if now%i==1:
      d.append(i)
print((len(d)))

# Optimized solution
N=int(eval(input()))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


#print(make_divisors(3141))
#N, N-1, 2
#%*==1
ans=[2]
if N not in ans:
    ans.append(N)
if (N%(N-1)!=0) and (N-1 not in ans):
    ans.append(N-1)
D=make_divisors(N)
for d in D:
    now=N
    if d==1:
        continue
    while now%d==0:
        now=now//d
    if now%d==1:
        if d not in ans:
            ans.append(d)
#print(ans)

ans2=[]
for a in ans:
    i=1
    while a**i<=N:
        x=a**i
        now=N
        while now%x==0:
            now=now//x
        if now%x==1:
            if x not in ans2:
                ans2.append(x)

        i+=1
#print(ans2)
d2=make_divisors(N-1)
for d in d2:
    if d!=1 and (d not in ans2):
        ans2.append(d)
#print(ans2)
print((len(ans2)))
# Original solution
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(eval(input()))

div = []
ans = 0

for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        div.append(i)
        if i != N // i:
            div.append(N//i)

for d in div:
    if d == 1: continue
    tmp = N
    while tmp % d == 0:
        tmp //= d
    if tmp % d == 1:
        ans += 1    

div2 = []        
for i in range(1, int((N-1)**0.5)+1):
    if (N-1) % i == 0:
        div2.append(i)
        if i != (N-1) // i:
            div2.append((N-1)//i)

print((ans + len(div2)-1))

# Optimized solution
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(eval(input()))

ans = 0

def divisor(x):
    res = []
    for i in range(1, int(x**0.5) + 1):
        if x % i == 0:
            if i != x//i:
                res.append(i)
                res.append(x//i)
            else:
                res.append(i)   
    return res[1:]


ans += len(divisor(N-1))

div_N = divisor(N)

for num in div_N:
    tmp = N
    while tmp % num == 0:
        tmp //= num
    if tmp == 1:
        ans += 1
        continue    
    if (tmp-1) % num == 0:
        ans += 1
print(ans)
# Original solution
from math import sqrt


def f(x):
    ret = []
    for i in range(1, int(sqrt(x)) + 1):
        if x % i == 0:
            ret.append(i)
            ret.append(x // i)

    return ret


n = int(eval(input()))

ans = 1
for k in range(2, int(sqrt(n)) + 1):
    r = n
    while r % k == 0:
        r //= k

    if r % k == 1:
        ans += 1

li = f(n - 1)
for e in li:
    if e > int(sqrt(n)):
        ans += 1

print(ans)


# Optimized solution
from math import sqrt


def divisors(x):
    for i in range(1, int(sqrt(x)) + 1):
        if x % i == 0:
            yield i
            if x // i != i:
                yield x // i


n = int(eval(input()))

ans = 0
for e in divisors(n):
    if e == 1:
        continue

    r = n
    while r % e == 0:
        r //= e

    if r % e == 1:
        ans += 1

ans += len(list(divisors(n - 1))) - 1

print(ans)
# Original solution
n = int(eval(input()))

def divisior(n):
    a = []
    i = 1
    while (i*i <= n):
        if n%i == 0:
            a.append(i)
            if (i*i != n): a.append(n//i)
        i += 1
    return a

ans = 0
a = divisior(n)

for x in a[1:]:
    tmp = n
    while (tmp%x == 0): tmp = tmp//x
    if (tmp%x == 1) : ans += 1

b = divisior(n-1)

ans = ans + len(b) -1

print(ans)




# Optimized solution
n = int(eval(input()))

def divisior(n):
    a = []
    i = 1
    while (i*i <= n):
        if n%i == 0:
            a.append(i)
            if (i*i != n): a.append(n//i)
        i += 1
    return a

ans = 0
a = divisior(n)

for x in a:
    if x == 1: continue
    tmp = n
    while (tmp%x == 0): tmp = tmp//x
    if (tmp%x == 1) : ans += 1

b = divisior(n-1)

ans = ans + len(b) -1

print(ans)
# Original solution
N = int(eval(input()))

def check(p):
  _N = N
  while _N%p == 0:
    _N //= p
  return ((_N-1)%p == 0) or (_N == 1)

n = int(N**0.5) + 1
P0 = set([N])
P1 = set([N-1])
for i in range(2, n+1):
  if (N-1)%i == 0:
    P1.add(i)
    P1.add((N-1)//i)
  if N%i == 0:
    P0.add(i)
    P0.add(N//i)

ans = len(P1)
for p in P0:
  ans += check(p)

print(ans)

# Optimized solution
N = int(eval(input()))

def check(p):
  _N = N
  while _N%p == 0:
    _N //= p
  return (_N-1)%p == 0

n = int(N**0.5) + 1
P0 = set([N])
P1 = set([N-1])
for i in range(2, n+1):
  if (N-1)%i == 0:
    P1.add(i)
    P1.add((N-1)//i)
  if N%i == 0:
    P0.add(i)
    P0.add(N//i)

P0.discard(1)
P1.discard(1)
ans = len(P1)
for p in P0:
  ans += check(p)

print(ans)
# Original solution
N = int(eval(input()))

def check(p):
  _N = N
  while _N%p == 0:
    _N //= p
  return (_N-1)%p == 0

n = int(N**0.5) + 1
P0 = set([N])
P1 = set([N-1])
for i in range(2, n+1):
  if (N-1)%i == 0:
    P1.add(i)
    P1.add((N-1)//i)
  if N%i == 0:
    P0.add(i)
    P0.add(N//i)

P0.discard(1)
P1.discard(1)
ans = len(P1)
for p in P0:
  ans += check(p)

print(ans)

# Optimized solution
def check(p):
  _N = N
  while _N%p == 0:
    _N //= p
  return (_N-1)%p == 0

def calc_divisors(n):
    m = int(n**0.5)
    left = []
    right = []
    for i in range(1, m+1):
        if n%i == 0:
            left.append(i)
            right.append(n//i)
    if left[-1] == right[-1]:
        right.pop()
    return left + right[::-1]

N = int(eval(input()))
P0 = calc_divisors(N)[1:] # [:1]で1を除外
P1 = calc_divisors(N-1)[1:] # 同上
ans = len(P1)
for p in P0:
  ans += check(p)

print(ans)
# Original solution
# 1は除外
# ・N-1の約数は全て対象
# ・Nの約数で、sqrt(N)以下であればOK　ただしN自身は対象
# これを足し合わせる

N = int(eval(input()))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
  
# N-1の約数の個数
ans = len(make_divisors(N-1)) - 1

def check(n,x):
  # xで割った余りがxの倍数でなくなるまでxで割る
  # xの倍数でなくなったときにxで割って1余ればOK
  while n % x == 0:
    n //= x
  return (n % x == 1)

# Nの約数で2以上sqrt(N)以下の数
for i in range(2,int(N ** 0.5) + 1):
  if N % i == 0:
    if check(N,i):
      ans += 1

# N自身も対象
ans += 1

print(ans)


# Optimized solution
# 1は除外
# ・N-1の約数は全て対象
# ・Nの約数でsqrt(N)以下の数について、Nで割れなくなるまで割って、最後にあまりが1になればOK
# ・N自身は必ず対象
# これを足し合わせる

N = int(eval(input()))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
  
# N-1の約数の個数
ans = len(make_divisors(N-1)) - 1

def check(n,x):
  # xで割った余りがxの倍数でなくなるまでxで割る
  # xの倍数でなくなったときにxで割って1余ればOK
  while n % x == 0:
    n //= x
  return (n % x == 1)

# Nの約数で2以上sqrt(N)以下の数
for i in range(2,int(N ** 0.5) + 1):
  if N % i == 0:
    if check(N,i):
      ans += 1

# N自身も対象
ans += 1

print(ans)
# Original solution
def make_divisors(n):
    divisors = [n]
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors


def main():
    N = int(eval(input()))
    if N == 2:
        print((1))
        exit()
    n = make_divisors(N)
    m = make_divisors(N - 1)
    answer = m[:]
    cnt = len(answer)
    for i in n:
        tmp = N
        while tmp % i == 0:
            tmp //= i
        if tmp % i == 1:
            cnt += 1
            answer.append(i)
    answer.sort()
    print(cnt)


if __name__ == '__main__':
    main()


# Optimized solution
def make_divisors(n):
    divisors = [n]
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors


def main():
    N = int(eval(input()))
    if N == 2:
        print((1))
        exit()
    n = make_divisors(N)
    m = make_divisors(N - 1)
    cnt = len(m)
    for i in n:
        tmp = N
        while tmp % i == 0:
            tmp //= i
        if tmp % i == 1:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()
# Original solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def divisors(n):
    lower = []
    upper = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)

    lower.extend(reversed(upper))
    return lower


def main():
    N = int(readline())

    D = divisors(N)
    D1 = divisors(N - 1)
    ans = len(D1) - 1

    for d in D[1:]:
        n = N
        while n % d == 0:
            n //= d
            if (n - 1) % d == 0:
                ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def divisors(n):
    lower = []
    upper = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)

    lower.extend(reversed(upper))
    return lower


def main():
    N = int(readline())

    D = divisors(N)
    D1 = divisors(N - 1)
    ans = len(D1) - 1

    for d in D[1:]:
        n = N
        while n % d == 0:
            n //= d
        if n % d == 1:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()
# Original solution
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def all_pattern(l):
    global n
    ans=0
    for ds in make_divisors(l)[1:]:
        k=n
        while k%ds==0:
            k//=ds
        ans+=(k%ds==1 or k-k%ds==1)
    return ans

n=int(eval(input()))
print((all_pattern(n)+all_pattern(n-1)))

# Optimized solution
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def all_pattern(l):
    global n
    ans=0
    for ds in make_divisors(l)[1:]:
        k=n
        while k%ds==0:
            k//=ds
        ans+=(k%ds==1)
    return ans

n=int(eval(input()))
print((all_pattern(n)+all_pattern(n-1)))
# Original solution
N = int(eval(input()))


def divisor(M):
    div = set()
    for i in range(1, int(N ** 0.5 + 0.5) + 1):
        if M % i == 0:
            div.add(i)
            div.add(M // i)
    return div


def simu(M, X):
    cnt = 0
    while M >= X:
        if M % X == 0:
            M //= X
        elif M % X == 1:
            return True
        else:
            M -= X
        cnt += 1
        if cnt > 1000:
            return False
    return M == 1


A = divisor(N)
B = divisor(N - 1)

# N%K==1となるやつ
ans = len(B) - 1

for a in (A - B):
    if simu(N, a):
        ans += 1

print(ans)


# Optimized solution
N = int(eval(input()))


def divisor(M):
    div = set()
    for i in range(1, int(N ** 0.5 + 0.5) + 1):
        if M % i == 0:
            div.add(i)
            div.add(M // i)
    return div


def simu(M, X):
    while M % X == 0:
        M //= X
    return M % X == 1


B = divisor(N - 1)
ans = len(B) - 1

A = divisor(N)
A -= {1}
for a in A:
    if simu(N, a):
        ans += 1

print(ans)
# Original solution
n=int(eval(input()))
if n%2==0:
        print(n)
else:
        print((2*n))


# Optimized solution
N = int(eval(input()))
if N%2 == 0:
    print(N)
else:
    print((N*2))
# Original solution
n = int(input())
if n % 2 == 0:
  print(n)
else:
  print(n * 2)


# Optimized solution
n = int(input())
if n % 2 == 1:
  print(n * 2)
else:
  print(n)
# Original solution
# -*-coding=utf-8-*-
n = int(eval(input()))
if n%2:
    n *= 2
print(n)

# Optimized solution
n=int(eval(input()))
if n%2==0:
    print(n)
else:
    print((n*2))
# Original solution
n = int(eval(input()))
if n % 2:
    print((2 * n))
else:
    print(n)

# Optimized solution
n = int(eval(input()))
if n % 2 == 0:
    ans = n
else:
    ans = 2*n
print(ans)
# Original solution
N = int(eval(input()))

if N%2 == 0:
    print(N)
else:
    print((2*N))


# Optimized solution
N = int(eval(input()))
print((2*N if N%2==1 else N))
# Original solution
import math
n = int(eval(input()))
print((2 // math.gcd(2, n) * n))


# Optimized solution
n = int(eval(input()))
if n % 2 == 0:
    print(n)
else:
    print((2 * n))
# Original solution
N=int(eval(input()))
#A1,A2,A3=map(int,input().split())
if N%2==0:
    print(N)
else:
    print((N*2))

# Optimized solution
N=int(eval(input()))
if N%2==0:
    print(N)
else:
    print((N*2))
# Original solution
n=int(eval(input()))
print((2*n if n%2 else n))

# Optimized solution
n=int(eval(input()))
print((n+n%2*n))
# Original solution
import math
n = int(eval(input()))
gcd = math.gcd(2, n)
lcm = 2 * n // gcd
print(lcm)


# Optimized solution
n = int(eval(input()))
if n % 2 == 0:
    print(n)
else:
    print((2 * n))
# Original solution
a=eval(input());print(a+a%2*a)

# Optimized solution
n=int(eval(input()))
print((n+n%2*n))
# Original solution
n = int(eval(input()))

print((n if n%2==0 else n*2))

# Optimized solution
n = int(eval(input()))
if n%2 ==0 :
  print(n)
else:
  print((n*2))
# Original solution
N = int(eval(input()))
if N%2 == 1:
  print((N*2))
else:
  print(N)
  

# Optimized solution
N = int(eval(input()))
print((N if N%2==0 else 2*N))
# Original solution
N = int(eval(input()))

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

def lcm(m, n):
  return int((m * n) / gcd(m, n))

print((lcm(N,2)))

# Optimized solution
N = int(eval(input()))

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

def lcm(m, n):
  print((m * n // gcd(m, n)))

lcm(N,2)
# Original solution
a = int(eval(input()))
if a%2 == 0:
    print(a)
else:
    print((a*2))

# Optimized solution
a = int(eval(input()))
if a%2 == 0:
    print(a)
else:
    print((2*a))
# Original solution
import fractions

def main():
    n = int(eval(input()))
    if n%2 == 0:
        print(n)
    else:
        print((2*n))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    n = int(eval(input()))
    if n%2 == 0:
        print(n)
    else:
        print((2*n))


if __name__ == '__main__':
    main()
# Original solution
def solve(h, w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    if w < h:
        h, w = w, h
    if h == 1:
        return 1
    min_diff = h * w
    vals = [0, 0, 0]
    for i in range(1, w // 2 + 1):
        vals[0] = i * h
        if h % 2 == 0:
            vals[1] = (w - i) * (h // 2)
            vals[2] = vals[1]
        else:
            vals[1] = (w - i) * (h // 2 + 1)
            vals[2] = (w - i) * (h // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
        if (w - i) % 2 == 0:
            vals[1] = h * ((w - i) // 2)
            vals[2] = vals[1]
        else:
            vals[1] = h * ((w - i) // 2 + 1)
            vals[2] = h * ((w - i) // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
    h, w = w, h
    for i in range(1, w // 2 + 1):
        vals[0] = i * h
        if h % 2 == 0:
            vals[1] = (w - i) * (h // 2)
            vals[2] = vals[1]
        else:
            vals[1] = (w - i) * (h // 2 + 1)
            vals[2] = (w - i) * (h // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
        if (w - i) % 2 == 0:
            vals[1] = h * ((w - i) // 2)
            vals[2] = vals[1]
        else:
            vals[1] = h * ((w - i) // 2 + 1)
            vals[2] = h * ((w - i) // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
    return min_diff

_h, _w = list(map(int, input().split()))
print((solve(_h, _w)))


# Optimized solution
def solve(h, w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    if h == 1 or w == 1:
        return 1
    def f(a, b):
        vals = [0, 0, 0]
        min_diff = h * w
        for i in range(1, a // 2 + 1):
            vals[0] = i * b
            vals[1] = (a - i) * (b // 2 + b % 2)
            vals[2] = (a - i) * (b // 2)
            diff = max(vals) - min(vals)
            if diff < min_diff:
                min_diff = diff
            vals[1] = b * ((a - i) // 2 + (a - i) % 2)
            vals[2] = b * ((a - i) // 2)
            diff = max(vals) - min(vals)
            if diff < min_diff:
                min_diff = diff
        return min_diff
    return min(f(h, w), f(w, h))

_h, _w = list(map(int, input().split()))
print((solve(_h, _w)))