Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.

The first line of the input contains two positive integers a1 and a2 (1 ≤ a1, a2 ≤ 100), the initial charge level of first and second joystick respectively.

Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.

NoteIn the first sample game lasts for 6 minute by using the following algorithm:  at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%;  continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%;  at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%;  continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%;  at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%;  at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.

import math
a, b = map(int,input().split())
c = 0
while 1:
    if a == 0 or b == 0:
        break
    elif a == 1 and b == 1:
        break
    else:
        if a == min(a,b):
            a += 1
            b -= 2
        else:
            b += 1
            a -= 2
        c += 1
print(c)

percent = [int(x) for x in input().split()]
p1 = percent[0]
p2 = percent[1]
n = 0
while p1 > 0 and p2 > 0:
    """
    a = abs(p1-p2)
    """
    if 1==p1==p2:
        break
    """
    if a == 0:
        n += 2*min((p1,p2))-3
        break
    elif a == 1:
        n += 2*min((p1,p2))+1
        break
    elif a == 2:
        n += 2*min((p1,p2))
        break
    else:
    """
    n+=1
    if p1 < p2:
        p1+=1
        p2-=2
    else:
        p1-=2
        p2+=1
print(n)

i, j = [int(x) for x in input().split()]

# original shitty greedy solution is now working
T=0
while i>0 and j>0:
    # because of this
    # and i was wondering during whole contest
    # 'why the hell it doesn't work?'
    # wasted an hour for task A
    # and haven't even looked at others tasks
    if i == 1 and j == 1:
        break; # again, never attend codeforces if you're drunk
    i, j = min(i, j), max(i, j)
    t = j//2
    if not t>0:
        T += i
        break
    if 2*t == j and t>1: t -= 1
    i += t
    j -= 2*t
    T += t
print(T)

a1, a2 = map(int, raw_input().split())
minute = 0
while a1 > 0 and a2 > 0 and (a1 + a2) > 2:
    minute += 1
    if a1 >= a2 :
        a2 += 1
        a1 -= 2
    else:
        a1 += 1
        a2 -= 2
print minute

a1,a2=map(int,input().split())
count=0
while(a1>0 and a2>0):
    if a1>=a2:
        a1-=2
        if a1<0:
            break
        a2+=1
        count+=1
    else:
        a1+=1
        a2-=2
        if a2<0:
            break
        count+=1
print(count)

import sys

data = list(map(int, sys.stdin.read().split(" ")))
a, b = data[0], data[1]
ans = 0
while a > 0 and b > 0:
	if a < b:
		a += 1
		b -= 2
	else:
		a -= 2
		b += 1
	if a >= 0 and b >= 0:
		ans += 1
print(ans)

import sys
discharge = 2
charge = 1
controller  = input().split()
controller[0] = int(controller[0])
controller[1] = int(controller[1])
controller.sort()

if(controller[0] == 1 and controller[1] == 1):
    print(0)
    sys.exit()
timePlayed = 0
while(True):
    controller.sort()
    timePlayed += 1

    controller[0] += 1
    controller[1] -= 2
    if(controller[0] <= 0 or controller[1] <= 0):
        print(timePlayed)
        break

(p1, p2) = map(int, raw_input().split())

t = 0
while p1 > 0 and p2 > 0 and (p1 > 1 or p2 > 1):
    if p1 < p2:
        p1 += 1
        p2 -= 2
    else:
        p1 -= 2
        p2 += 1
    t += 1
print t

import io
import sys
import math
import itertools as itt

def rlist(t):
    return map(t, raw_input().split())

def read_int_list():
    return rlist(int)

def write_list(lst, divider=" "):
    print divider.join(map(str, lst))

def main():
    a, b = read_int_list()
    if a == b == 1:
        print 0
        return 0
    if (a-b) % 3 == 0:
        print a + b - 3
    else:
        print a + b - 2
main()

a,b=map(int,input().split())
c=0
if a==b and a==1:
    print(0)
else:
    while a>0 and b>0:
        if a>b:
            t=a
            a=b
            b=t
        a+=1
        b-=2
        c+=1
    print(c)

a , b = map(int, input().split())
time = 0
while(a>0 and b>0):
    if(a<b):
        temp = a
        a = b
        b = temp
    a -= 2
    b += 1
    if(a>=0 and b>=0):
        time += 1
print(time)

a, b = map(int, input().split())
ans = 0

if (a == b == 100):
    print(197)
else:

    while (a > 1 or b > 1) and a != 0 and b != 0:
        ma = max(a ,b)
        mb = min(a, b)
        if ma == mb == 100:
            a = ma - 2
            b = mb - 2
            ans += 1
            continue
        if ma == 100 and mb != 100:
            a = ma - 2
            b = mb + 1
            ans += 1
            continue
        ma -= 2
        mb += 1
        ans += 1
        a = ma
        b = mb
        #print(a, b)
    print(ans)

from  bisect import bisect_right as br
import sys
from collections import *
from math import *
import re
def sieve(n):
    prime=[True for i in range(n+1)]
    p=2
    while p*p<=n:
        if prime[p]==True:
            for i in range(p*p,n+1,p):
                prime[i]=False
        p+=1
    c=0
    for i in range(2,n):
        if prime[i]:
            #print(i)
            c+=1
    return c

def iseven(n):return[False,True][0 if n%2 else 1]
def inp_arr():return list(map(int,input().split()))
def inp():return map(int,input().split())
def lcm(a,b):return (a*b)/gcd(a,b)
max_int = sys.maxsize
mod = 10**9+7

a1,a2=inp()
res=0
while a1>0 and a2>0:
    if a1<=a2:
        a1+=1;a2-=2;
        if a2>=0:res+=1
    else:
        a2+=1;a1-=2;
        if a1>=0:res+=1;
    #print(a1,a2,res)
print(res)

a, b = map(int, raw_input().split())
elapsed = 0
while a > 1 or b > 1:
  if a < b:
    a += 1
    b -= 2
  else:
    b += 1
    a -= 2
  elapsed += 1
  if a == 0 or b == 0:
    break
print(elapsed)

z,zz=input,lambda:list(map(int,z().split()))
zzz=lambda:[int(i) for i in stdin.readline().split()]
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
    p=ceil(x**.5)+1
    for i in range(2,p):
        if (x%i==0 and x!=2) or x==0:return 0

    return 1
def dfs(u,visit,graph):
    visit[u]=True
    for i in graph[u]:
        if not visit[i]:
            dfs(i,visit,graph)

###########################---Test-Case---#################################
"""

"""
###########################---START-CODING---##############################

n,m=zz()
ans=0
while True:
    n,m=sorted([n,m])
    if n>=1 and m>=2:
        n+=1
        m-=2
        ans+=1

    else:
        break

print(ans)

a,b = list(map(int,input().split(' ')))
minutes = 0

if a == b == 1:
    print(minutes)

else:
    while a != 0 and  b != 0:
        if a <= b :
            a += 1
            b -= 2
        else:
            b += 1
            a -= 2
        minutes += 1

    print(minutes)

a1, a2 = map(int, raw_input().split())
t = 0
while a1 > 0 and a2 > 0:
    if a1 < a2:
        if a2 < 2:
            break
        a1 += 1
        a2 -= 2
    else:
        if a1 < 2:
            break
        a1 -= 2
        a2 += 1
    t += 1
print t

a,b=map(int,raw_input().split())
m=min(a,b)
n=max(a,b)
a=m
b=n
count=0
if a==1 and b==1:
    print 0
else:
    while True:
        a+=1
        b-=2
        count+=1
        if a>b:
            a,b=b,a
        if a<=0 or b<=0:
            break

    print count

n = list(map(int, input().split()))
first_d = n[0]
second_d = n[1]
k = 0
if first_d == 1 and second_d == 1:
    k = 0
else:
    while first_d > 0 and second_d > 0:
            if first_d > second_d:
                first_d -= 2
                second_d += 1
            else:
                first_d += 1
                second_d -= 2
            k += 1
print(k)

# your code goes here

a,b = map(int, raw_input().split())
c = 0
while a>=1 and b>=1:
	if min(a,b)==a:
		a+=1
		b-=2
	else:
		a-=2
		b+=1
	if a>=0 and b>=0:
		c+=1
	else:
		break
print c

a,b = map(int, raw_input().split())
count = 0
if a > b: b,a = a,b
while b>2:
    temp = b/2 if b&1 else (b-1)/2
    count += temp
    b -= 2*temp
    a += temp
    a, b = b, a
print count + [1,0][b&1]

from collections import Counter
import operator

'''
1) Convrt a List to Dict of counts:
	Counter(Lis)

2) Sort a dict based on key or value:

	sorted_key = sorted(x.items(), key = operator.itemgetter(0))

	sorted_value = sorted(x.items(), key = operator.itemgetter(1))

'''

def main():

	#X = raw_input()
	N = map(int, (raw_input().split()))

	a = N[0]
	b = N[1]

	retans = 0

	while((a > 0 and b > 0) and (a > 1 or b > 1)):
		retans += 1

		if(a > b):
			a-=2
			b+=1
		else:
			a+=1
			b-=2
	print retans
if __name__ == '__main__':
	main()

if __name__ == '__main__':
    a, b = map(int, input().split())

    cnt = 0

    while a > 0 and b > 0 and a + b > 2:
        a, b = min(a, b) + 1, max(a, b) - 2
        cnt += 1

    print(cnt)

n1,n2=map(int,raw_input().split())
c=0
if (n1==1 and n2==1):
    print 0
else:
    while n1 > 0 and n2 > 0:
        c = c + 1
        if (n1 < n2) or n1 == n2:
            n1 = n1 + 1
            n2 = n2 - 2
        else:
            n1 = n1 - 2
            n2 = n2 + 1
    print c

a,b=map(int,input().split())
ans=0
c=a
d=b
while a>0 and b>0:
    if a<b:
        a+=1
        b-=2
    else:
        b+=1
        a-=2
    if a>=0 and b>=0:
        ans+=1
print(ans)

def main():
    a, b = [int(v) for v in input().split()]
    c= 0
    while a>0 and b>0:
        c+=1
        if a>b:
            b+=1
            a-=2
        else:
            b-=2
            a+=1
        if a<0 or b<0:
            c-=1
            break
    print(c)

if __name__ == "__main__":
    main()

try:
    a,b=map(int,input().split())
    c=0
    if a==1 and b==1:
        a=0
        b=0

    while a>0 and b>0:
        if b>a:
            a=a+1
            b=b-2
            c+=1
        elif a>b:
            a=a-2
            b+=1
            c+=1
        elif a==b:
            a=a-2
            b=b+1
            c+=1
    print(c)
except:
    pass

a,b = map(int,input().split())
c = 0
while (a >= 2 or b >= 2) and a>0 and b>0:
    a,b = min(a,b),max(a,b)
    a+=1
    b-=2
    c+=1
print(c)

x = [int(x) for x in input().split()]

x.sort()

a = x[0]
b = x[1]
count = 0
if a == 1 and b == 1:
    print(0)
    exit()
while 1:
    a = a + 1
    b = b - 2
    #print(a , b)
    count = count + 1
    if a <= 0 or b <= 0:
        break
    c = min(a , b)
    d = max(a , b)
    a = c
    b = d

print(count)

#! /usr/bin/python

[a1, a2] = [int(x) for x in raw_input().split(" ")]
last_time = 0

while min(a1, a2)>0 and (a1>=2 or a2>=2):
    #print([a1, a2])
    last_time += 1
    if a1 < a2:
        a1 += 1
        a2 -= 2
    else:
        a2 += 1
        a1 -= 2
print(last_time)

ss = raw_input().split(" ")
a = int(ss[0])
b = int(ss[1])
cnt = 0
while a >= 2 and b > 0 or b >= 2 and a > 0:
    if a < b:
        a += 1
        b -= 2
    else:
        a -= 2
        b += 1
    cnt += 1

print(cnt)

import sys

a, b = sys.stdin.readline().split()
a, b = int(a), int(b)

n = 102
dp = [[0 for i in range(n)] for j in range(n)]

for i_plus_j in range(2 * n):
    for i in range(n):
        j = i_plus_j - i
        if j < 0 or j >= n:
            continue
        if i == 0 or j == 0:
            dp[i][j] = 0
            continue
        dp[i][j] = max(
            1 + dp[i - 2][j + 1] if i >= 2 and j + 1 < n else 0,
            1 + dp[i + 1][j - 2] if j >= 2 and i + 1 < n else 0,
        )

print dp[a][b]

a , b = map(int, input().split())
time = 0
while(a>0 and b>0):
    if(a<b):
        temp = a
        a = b
        b = temp
    a -= 2
    b += 1
    if(a>=0 and b>=0):
        time += 1
print(time)

a1, a2 = map(int, input().split())
ans = 0
while a1 > 0 and a2 > 0:
    if a2 <= 2 and a1 >= 2:
        a1, a2 = a2, a1
    a1 += 1
    a2 -= 2
    ans += 1
if a2 >= 0:
    print(ans)
else:
    print(0)

a1,a2 = map(int,raw_input().split())

count = 0
while a1>0 and a2>0 and max(a1,a2)>1:
	if a1<=a2:
		a1+=1
		a2-=2
	else:
		a2+=1
		a1-=2
	count +=1

print count

#!/usr/bin/python

import sys
line = sys.stdin.readline()

cont1 = int(line.split()[0])
cont2 = int(line.split()[1])

x = 0
while (cont1 > 0 and cont2 > 0):
        x+=1
        cont1 -= 2
        cont2 -= 2
        if (cont1 < cont2):
                cont1+=3
        else:
                cont2+=3
if (cont1 < 0 or cont2 < 0):
	x-=1
print x

# import sys
# sys.stdin=open(r'/home/vipenl26/Documents/Sublime text files/input.txt')
# sys.stdout=open(r'/home/vipenl26/Documents/Sublime text files/output.txt','w')
# ##############################################################################

a,b=list(map(int,input().split()))

c=0

while a>0 and b>0:
	a,b=min(a,b)+1,max(a,b)-2
	if -1 in [a,b]:
		break
	c+=1

print(c)

"""
[int(i) for i in raw_input().split(" ")]
raw_input()
raw_input().split(" ")

"""

def main():
	a,b = [int(i) for i in raw_input().split(" ")]

	if a == 1 and b == 1:
		print 0
		return

	for turn in range(300):

		if a < b:
			a += 1
			b -= 2
		elif b <= a:
			b += 1
			a -= 2
		a = min(100,a)
		b = min(100,b)

		if a == 1 and b == 1:
			return

		if min(a,b) <= 0:
			break

	print turn+1

main()

a1, a2 = map(int,input().split(' '))
cnt = 0

while(a1 >=1) and (a2 >=1 ):
    if (a1 ==1 and a2 == 1):
        break
    if a1 > a2:
        a1 -= 2
        a2 += 1
        cnt +=1
    else:
        a2 -= 2
        a1 += 1
        cnt +=1

print(cnt)

n,m = input().split()
n = int(n)
m = int(m)
count = 0
large = max(m,n)
small = min(m,n)
while(1):
    if large == 1 and small == 1:
        break
    if (large == 2 or large == 1) and (small == 2 or small == 1):
        count += 1
        break
    if large == 2 or large == 1:
        temp = large
        large = small
        small = temp
    else:
        large -= 2
        small += 1
        count += 1
print(count)

n1,n2=map(int,raw_input().split())
c=0
if (n1==1 and n2==1):
    print 0
else:
    while n1 > 0 and n2 > 0:
        c = c + 1
        if (n1 < n2) or n1 == n2:
            n1 = n1 + 1
            n2 = n2 - 2
        else:
            n1 = n1 - 2
            n2 = n2 + 1
    print c

def play(a, b):
    time = 0

    while a > 0 and b > 0:
        if a > b:
            b += 1
            a -= 2
        else:
            b -= 2
            a += 1
        a = min(a, 100)
        b = min(b, 100)
        time += 1

    # Not enough charge to finish the minute.
    if a < 0 or b < 0:
        return time - 1
    else:
        return time

def test_one(a, b, right_ans):
    ans = play(a, b)
    if ans == right_ans:
        print("[OK]")
    else:
        print("[Fail] Expected {right_ans} but got {ans} on '{a} {b}'".format(**locals()))

def test():
    test_one(3, 5, 6)
    test_one(4, 4, 5)
    test_one(1, 1, 0)
    test_one(2, 2, 1)
    test_one(3, 3, 3)
    test_one(98, 1, 97)
    test_one(100, 100, 197)

if __name__ == "__main__":
    ab = list(map(int, input().split()))
    a = ab[0]
    b = ab[1]
    print(play(a, b))
#   test()

a,b = map( int, raw_input().split())
contador = 0
while a > 0 and b > 0:
	if(a < b):
		a += 1
		b -= 2
	else:
		b += 1
		a -= 2
	if(a < 0 or b < 0):
		break

	contador += 1
print contador

def fun(a, b):
    if a <= 1 and b <= 1:
        return 0
    a, b = min(a, b), max(a, b)
    cnt = 0
    while abs(a - b) > 1:
        a += 1
        b -= 2
        cnt += 1
    return cnt + 2 * ((a + b - 1) // 2) - 1

a, b = map(int, input().split())
print(fun(a, b))

a,b = map(int,raw_input().split())
time = 0
while 1 :
    if a == 0 or b == 0 :
        break
    elif a <= 1 and b <= 1 :
        break
    if a > b :
        b += 1
        a -= 2
    else :
        b -= 2
        a += 1
    time += 1
print time

a1,a2=map(int,input().split())
if a1==1 and a2==1:
	print(0)
elif (a1-a2)%3==0:
	print(a1+a2-3)
else:
	print(a1+a2-2)

x, y = map(int, raw_input().split(' '))
ans = 0
while True:
  if x < y:
    x, y = y, x
  if x <= 1 or y == 0:
    break
  ans += 1
  x -= 2
  y += 1
print ans

#start the code from here
a,b=map(int,input().split())
ans=0
if a==1 and b==1:
	print(0)
	exit()
while a>0 and b>0:
	if a>=b:
		b=b+1
		a=a-2
	else:
		b=b-2
		a=a+1
	ans+=1
print(ans)

a, b = map(int, raw_input().split())
ans = 0
if a == 1 and b == 1:
	print "0"
else:
	while True:
		if a<=0 or b<=0:
			break
		if a>=b:
			b+=1
			a-=2
			ans+=1
		else:
			a+=1
			b-=2
			ans+=1
	print ans

f,s = map(int, input().split())
mem = [[0 for i in range(500)]for i in range(500)]
if(f==1 and s==1):
    print(0)
else:
    def check(a,b):
        if(mem[a][b]):
            return mem[a][b]
        if(a <=0 or b<= 0):
            return 0
        else:
            mem[a][b] = 1 + max(check(a-2, b+1), check(a+1, b-2))
            return mem[a][b]
    print(check(f, s))

a, b = map(int, raw_input().split())
cont = 0
while True:
	if a <= 0 or b <= 0: break
	if a == 1 and b == 1: break

	if a <= b:
		a += 1
		b -= 2
	else:
		a -= 2
		b += 1

	cont += 1

print cont

a,b= map(int,input().split())
mi=0
if a==1 and b==1:
    print(mi)
else:
    while a>=1 and b>=1:
        mi+=1
        if a<=b and b>1:
            a+=1
            b-=2
        elif b<a and a>1:
            b+=1
            a-=2
        else:
            break
    print(mi)

a1,a2 = map(int , input().split())

count = 0
while a1>0 and a2>0:
    if a1==1 and a2==1:
        break
    if a1>a2:
        a1-=2
        a2+=1
    else:
        a1+=1
        a2-=2
    count+=1
print(count)

j1, j2 = map(int, raw_input().split())

minutos = 0
while j1 > 0 and j2 > 0:
	if j1 == 1 and j2 == 1:
		break
	elif j1 == 1 and j2 > 1:
		j1 += 1
		j2 -= 2
	elif j1 > 1 and j2 == 1:
		j2 += 1
		j1 -= 2
	else:
		if j1 > j2:
			j1 -= 2
			j2 += 1
		else:
			j1 += 1
			j2 -= 2
	minutos += 1
print minutos

a = input().split()
a[0] = int(a[0])
a[1] = int(a[1])
if a[0] < a[1]: #menentukan mana yang akan dicharge terlebih dahulu
    p = 0
else:
    p = 1
n = int(0)
if a[0] == 1 and a[1] == 1: #jika sama-sama 1 maka tidak perlu dijalankan
    n = 0
else:
##    while a[0] > 0 and a[1] > 0: #perulangan berhenti ketika salah satu baterai mencapai 0
##        if p: #jika p = 1, a[1] yang ditambah a[0] berkurang, begitu juga sebaliknya
##            a[1] += 1
##            a[0] -= 2
##        else:
##            a[0] += 1
##            a[1] -= 2
##        if a[0] < a[1]:
##            p = 0
##        else:
##            p = 1
##    ##    if a[0] == 1:
##    ##        p = 0
##    ##    elif a[1] == 1:
##    ##        p = 1
##        n += 1 #setiap akhir perulangan menandakan menit bertambah 1
    n = a[0] + a[1] - 2
    if abs(a[0] - a[1]) % 3 == 0:
        n -= 1

print(n)

x,y = map(int, input().split())
ans = 0
if max(x,y) <= 1:
    print(0)
    exit()
while max(x,y) > 2:
    a = max(x,y)
    b = min(x,y)
    ans += (a-1)//2
    b += (a-1)//2
    a -= 2*((a-1)//2)
    x = a
    y = b

print(ans+1)

a1, a2 = map(int, raw_input().split(" "))
time = 0
while a1 > 0 and a2 > 0:
    if a1 == a2 == 1:
        break
    time+=1
    if a1 > a2:
        a1 -= 2
        a2 += 1
    else:
        a2 -= 2
        a1 += 1
print time

n,m=map(int,input().split())
c=0
if(n==0 and m==0 or n==1 and m==1):
    print(0)
    exit(0)
for i in range(1000):
    if(n<=0 or m<=0):
        break
    if(m>n):
        m-=2
        n+=1
        c+=1
    else:
        m+=1
        n-=2
        c+=1
print(c)

if __name__ == '__main__':
    a, b = map(int, input().split())

    cnt = 0

    while a > 0 and b > 0 and a + b > 2:
        a, b = min(a, b) + 1, max(a, b) - 2
        cnt += 1

    print(cnt)

a,b=map(int,input().split())
c=max(a,b)
d=min(a,b)
if c<2:
    print(0)
elif c>=2:
   if (c-d)%3==0:
      print(max(c+d-3,1))
   elif (c-d)%3!=0:
      print(max(c+d-2,1))

a,b=map(int,input().split())
ans=0
c=a
d=b
while a>0 and b>0:
    if a<b:
        a+=1
        b-=2
    else:
        b+=1
        a-=2
    ans+=1
if c==1 and d==1:
    print(0)
else:
    print(ans)

# -*- codeing:utf-8 -*-

class A(object):
	def __init__(self):
		self.AC()

	def GetData(self):
		self.m_A1, self.m_A2 = map(int, input().split())

	def AC(self):
		self.GetData()
		self.m_Ans = self.Slove(self.m_A1, self.m_A2)
		print(self.m_Ans)

	def Slove(self, a1, a2):
		ans = 0
		while (a1 > 1 or a2 > 1 ) and (a1 != 0 and a2 != 0):
			if a1 > a2:
				a1 -= 2
				a2 += 1
			else:
				a1 += 1
				a2 -= 2
			ans += 1
		return ans

A()

a,b = map( int, raw_input().split())
contador = 0
while a > 0 and b > 0:
	if(a < b):
		a += 1
		b -= 2
	else:
		b += 1
		a -= 2
	if(a < 0 or b < 0):
		break

	contador += 1
print contador

import math as mt
import sys,string,bisect
input=sys.stdin.readline
import random
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
d=defaultdict(int)
def dp(x,y):
    if(d[(x,y)]!=0):
        return d[(x,y)]
    if(x<=0 or y<=0):
        return 0
    if(x>=2 and y>=2):
        d[(x,y)]=max(1+dp(x+1,y-2),1+dp(x-2,y+1))
        return max(1+dp(x+1,y-2),1+dp(x-2,y+1))
    if(x>=2):
        d[(x,y)]=1+dp(x-2,y+1)
        return 1+dp(x-2,y+1)
    if(y>=2):
        d[(x,y)]=1+dp(x+1,y-2)
        return 1+dp(x+1,y-2)
    return 0
a,b=M()
print(dp(a,b))

x,y=raw_input().split(' ')
x=int(x)
y=int(y)

for i in range(0,10000):
    if x<=0 or y<=0:
        print i
        break
    elif x==1 and y==1:
        print i
        break
    elif x>=y:
        x=x-2
        y=y+1
        continue
    elif x<=y:
        y=y-2
        x=x+1
        continue

a, b = map(int, input(). split())
z = 0
while a>0 and b>0:
    if a<b :
        a,b=b,a
    if a<2:
        break
    a -= 2
    b += 1
    z += 1
print(z)

number = map(int, raw_input().split())
count = 0
while number[0] > 0 and number[1] > 0:
  if number[0] == number[1] == 1:
    break
  if number[0] > number[1]:
    number[0] -= 2
    number[1] += 1
    count += 1
  else:
    number[1] -= 2
    number[0] += 1
    count += 1
print count

a,b=map(int,input().split())
c=0
if max(a,b)==1:
    print(c)
else:
    if a<b:
        d=a
        e=b
    else:
        d=b
        e=a
    while d>0 and e>0:
        if d==1 or d==2:
            d,e=e,d

        d-=2
        e+=1
        c+=1
    print(c)

num = input()
a = []

def get_the_data(count, num, arr):
    for i in range(0, len(num)):
        if num[i] == ' ':
            arr.append(int(num[count:i]))
            count = i+1
        elif i == len(num)-1:
            arr.append(int(num[count:len(num)]))
    return arr

arr = get_the_data(0, num,  a)
arr.sort()
if arr[0] < 2 and  arr[1] < 2:
    print(0)
else:
    time = 0
    first = True
    while arr[0] > 0 and arr[1] > 0:
        if arr[0] == 1 or arr[0] == 2:
            first = True
        elif arr[1] == 1 or arr[1] == 2:
            first = False

        if first == True:
            arr[0] += 1
            arr[1] -= 2
        else:
            arr[1] += 1
            arr[0] -= 2
        time += 1

    print(time)

a,b = [int(i) for i in input().split()]

x = min(a,b)
y = max(a,b)
time = 0
while x > 0 and y > 0:

    if y > 2:
        if y & 1:
            a = y // 2
            y = 1
        else:
            a = (y-2) // 2
            y = 2

        time += a
        x += a

    if x > 2:
        if x & 1:
            a = x // 2
            x = 1
        else:
            a = (x-2) // 2
            x = 2
        y += a
        time += a

    if x <= 2 and y <= 2:
        time += max(y,x)//2
        x=0
        y=0

print(time)

n,m = list(map(int,input().split()))
cnt = 0
if n == 1 and m == 1:
    print(0)
else:
    while n > 0 and m > 0:

        if n == 1 and m == 1:
            break
        if n > m:
            n,m = m, n

        n = min(100, n+1)
        m-=2
        cnt += 1
    print(cnt)

# import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("out.out",'w')
a,b=map(int,input().split())
t=0
while a>0 and b>0:
	if a==1 and b==1:
		print(0)
		exit()
	x=min(a,b)
	if x==a:
		a+=1
		b-=2
	else:
		a-=2
		b+=1
	t+=1
print(t)

def game(a,b,count):
    if(a==0 or b==0):
        return count
    else:
        mi=min(a,b)
        ma=max(a,b)
        return game(mi+1,ma-2,count+1)

a,b=map(int,input().split())
if(a<2 and b<2):
    print(0)
else:
    res=game(a,b,0)
    print(res)

''' ===============================
    -- @uthor : Kaleab Asfaw
    -- Handle : kaleabasfaw2010
    -- Bio    : High-School Student
    ==============================='''

# Fast IO
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file): self._fd = file.fileno(); self.buffer = BytesIO(); self.writable = "x" in file.mode or "r" not in file.mode; self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b: break
            ptr = self.buffer.tell(); self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0; return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)); self.newlines = b.count(b"\n") + (not b); ptr = self.buffer.tell(); self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1; return self.buffer.readline()
    def flush(self):
        if self.writable: os.write(self._fd, self.buffer.getvalue()); self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file): self.buffer = FastIO(file); self.flush = self.buffer.flush; self.writable = self.buffer.writable; self.write = lambda s: self.buffer.write(s.encode("ascii")); self.read = lambda: self.buffer.read().decode("ascii"); self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout); input = lambda: sys.stdin.readline().rstrip("\r\n")
# Others
# from math import floor, ceil, gcd
# from decimal import Decimal as d
mod = 10**9+7
def lcm(x, y): return (x * y) / (gcd(x, y))
def fact(x, mod=mod):
	ans = 1
	for i in range(1, x+1): ans = (ans * i) % mod
	return ans
def arr2D(n, m, default=0):
	lst = []
	for i in range(n): temp = [default] * m; lst.append(temp)
	return lst
def sortDictV(x): return {k: v for k, v in sorted(x.items(), key = lambda item : item[1])}

def solve(a, b):
	if a == 1 and b == 1: return 0
	time = 0
	while a > 0 and b > 0:
		if a < b:
			a += 1
			b -= 2
		else:
			a -= 2
			b += 1
		time += 1
	return time

a, b = list(map(int, input().split()))
print(solve(a, b))

a, b = [int(x) for x in input().split()]
count = 0
if a == 1 and b == 1:
    print(0)
else:
    while a > 0 and b > 0:
        if a == 1 or a == 2:
            a += 1
            b -= 2
        elif b == 1 or b == 2:
            b += 1
            a -= 2
        elif a > b:
            a -= 2
            b += 1
        else:
            a += 1
            b -= 2
        count += 1
    print(count)

import sys
import math
import bisect

def solve(A):
    ans = 0
    while min(A) > 0:
        A.sort()
        if A[1] == 1:
            break
        A[0] += 1
        A[1] -= 2
        ans += 1
    return ans

def main():
    a, b = map(int, input().split())
    ans = solve([a, b])
    print(ans)

if __name__ == "__main__":
    main()

a, b = map(int, input().split())
min_ = 0
while(max(a,b) > 1 and min(a,b) > 0):
    min_ += 1
    if(a < b):
        a += 1
        b -= 2
    else:
        b += 1
        a -= 2

print(min_)

a,b=map(int,input().split())
ans=0
c=a
d=b
while a>0 and b>0:
    if a<b:
        a+=1
        b-=2
    else:
        b+=1
        a-=2
    if a>=0 and b>=0:
        ans+=1
print(ans)

a,b=input().split()
a=int(a)
b=int(b)
cnt=0
flg=True
while flg:
    if (a<=0 or b<=0) or (b==a and a<=1):
        flg=False
    else:
        if a<b:
            a=a+1
            b=b-2
        else:
            b=b+1
            a=a-2
        cnt=cnt+1
print(cnt)

def solve(a, b):
	if(a == 100 and b == 100):
		return solve(100, 98) + 1

	if(a < b):
		return solve(b, a)

	ans = 0
	while(True):
		# print(a, b)
		while(a > 2 and b < 100):
			a -= 2
			b += 1
			ans += 1

		if(a < b):
			a, b = b, a
		if(a <= 1):
			return ans
		if(a == 2):
			if(b == 0):
				return ans
			else:
				return ans + 1

	return ans

if(__name__ == "__main__"):
	a, b = [int(t) for t in raw_input().split(' ')]
	print(solve(a, b))

a,b=map(int,input().split())
c=1
k=0
if(a==0  or b==0 ):
    print(0)
elif(a==1 and b==1):
    print(0)
else:
    while(c!=0):
        if(a>=b):
            if(a>2):
                b=b+1
                a=a-2
                k=k+1
            else:
                c=0
        elif(a<b):
            if(b>2):
                a=a+1
                b=b-2
                k=k+1
            else:
                c=0
    print(k+1)

a1,a2=map(int,input().split())
count=0
sp=0
if a1==1 and a2==1:
    sp+=1
    print(0)
while a1>0 and a2>0:
    if a1>1 and a2>1:
        if a1<a2:
            a1+=1
            a2-=2
            count+=1
        else:
            a2+=1
            a1-=2
            count+=1
    else:
        t=a1
        a1=a2
        a2=t
        if a1<a2:
            a1+=1
            a2-=2
            count+=1
        else:
            a2+=1
            a1-=2
            count+=1
if sp==0:
    print(count)

a1, a2 = map(int, raw_input().split())
mins = 0

while(a1 > 0 and a2 > 0):
    if(a1 == 1 and a2 == 1):
        break

    minimum = min(a1, a2)
    maximum = max(a1, a2)

    minimum += 1
    maximum -= 2

    a1 = minimum
    a2 = maximum
    mins += 1

print mins

a,b = map(int, input().split(' '))
if a>=b and (a>1 or b>1):
	time = 0
	b_bool = True
	while a>0 and b>0:
		time+=1
		if b_bool:
			b+=1
			a-=2
			if a<=2:
				b_bool = False
		else:
			b-=2
			a+=1
			if b<=2:
				b_bool = True
	print(time)

elif b>=a and (a>1 or b>1):
	time = 0
	a_bool = True
	while a>0 and b>0:
		time+=1
		if a_bool:
			a+=1
			b-=2
			if b<=2:
				a_bool = False
		else:
			a-=2
			b+=1
			if a<=2:
				a_bool = True
	print(time)
else:
	print(0)

#651A
a,b=map(int,input().split())
n=0
while (a>1 or b>1) and a*b>0:
    if a>b:
        a-=2
        b+=1
        n+=1
    else:
        a+=1
        b-=2
        n+=1

print(n)

n,b = tuple(map(int,input().split()))
if n > b:
    n,b = b, n

if n < 2 and b < 2:
    print(0)

else:
    p = b-n
    l = [-3,-1,0]
    print(2*(n+(p//3))+l[p%3]+(p//3))

t=list(map(int,input().split()))
t.sort()

if max(t)<2 and min(t)<2:
    print(0)
else:
    for j in range(1,1000):
        if t[1]>2:
            t[0]+=1
            t[1]-=2
        else:
            t[0],t[1]=t[1]+1,t[0]-2
        if min(t)<=0:
            print(j)
            break

a, b = map(int, input().split())
print(max(a + b - 2 - ((b - a) % 3 is 0), 0))

import sys

c1, c2=map(int, sys.stdin.readline().strip().split(" "))
c2Connected=False
c1Connected=False
c1Connected, c2Connected=c1<=c2, c1>c2
minutes=0
while c1>0 and c2>0:
	minutes+=1
	if c1Connected:
		c2-=2
		c1+=1
		c2Connected=((c2-2)<1)
		c1Connected= not c2Connected
	elif c2Connected:
		c1-=2
		c2+=1
		c1Connected=((c1-2)<1)
		c2Connected= not c1Connected
print minutes

# @Date    : 2016-06-25 17:45:27
# @Author  : Samandar Ravshanov (ravshanoff@protonmail.com)
# @Problem : http://codeforces.com/problemset/problem/651/A

import unittest

from random import randint
from sys import maxsize

import pprint

class StressTest(unittest.TestCase):
	known_values = (
		# a,   b,        expected
		( 3,   5,  		6),
		( 4,   4,  		5),
		( 1, 100,       0),
		( 100, 1,       0),
	)

	def test_known_cases(self):
		for a, b, expected in self.known_values:
			#self.assertEqual(expected, NaiveSolution().joysticks(a, b))
			self.assertEqual(expected, GreedySolution().joysticks(a, b))
			#self.assertEqual(expected, DPSolution().joysticks(a, b))

	def ptest_all_cases(self):
		while True:
			a = randint(1, 50)
			b = randint(1, 50)
			memo_res = NaiveSolution().joysticks(a, b)
			greedy_res = GreedySolution().joysticks(a, b)
			print(a, b)
			self.assertEqual(memo_res, greedy_res)

class NaiveSolution:   # C(a, b) = max(1 + C(a+1,  b-2),  1 + C(a-2, b+1))
	def joysticks(self, a, b):
		# base case
		if a < 1 or b < 1:
			return 0

		if not hasattr(self, 'memo'):
			self.memo = {}

		if self.memo.get((a, b)):
			return self.memo.get((a, b))

		# recursive cases
		self.memo[(a, b)] = 1 + max(
				self.joysticks(a+1, b-2),
				self.joysticks(a-2, b+1)
			)

		#print(self.memo)

		return self.memo[(a, b)]

class DPSolution:
	def joysticks(self, a, b):
		m = max(a, b) + 3
		dp = [[0 for x in range(m)] for x in range(m)] # dp[a][b]

		for row in range(2, a+2):
			for col in range(2, b+2):

				dp[row][col] = dp[col][row] = 1 + max(
						dp[row-2][col+1],
						dp[row+1][col-2]
					)

		pprint.pprint(dp)
		a += 1
		b += 1

		return dp[a][b]

class GreedySolution:
	def joysticks(self, a, b):
		if a < 2 or b < 2:
			return 0
		minutes = 0
		while a > 0 < b:
			if a <= b:
				a += 1
				b -= 2
			else:
				b += 1
				a -= 2

			minutes += 1

		return minutes

if __name__ == '__main__':
	#unittest.main()

	a, b = tuple(input().strip().split())
	ans = GreedySolution().joysticks(int(a), int(b))
	print(ans)

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 13 10:05:12 2019

@author: pratik1104
"""

a,b=map(int,raw_input().split())
ans=0
while(True):
    ans+=1
    if(a<b):
        a+=1
        b-=2
    else:
        b+=1
        a-=2
    if(min(a,b)<=0):
        break
print ans

# coding=utf-8

if __name__ == '__main__':
	a, b = str(input()).split()
	a = int(a)
	b = int(b)
	if a % 2 == 1 and b % 2 == 1:
		print(a + b - 2)
	else:
		print(a + b - 3)

def d1100_joysticks(a, b):
    if max(a, b) <= 2:
        return 0
    if abs(a - b) % 3 == 0:
        return a + b -3
    else:
         return a + b -2

if __name__ == "__main__":
    [a, b] = map(int, input().split())
    result = d1100_joysticks(a, b)
    print(result)

s1,s2 = input().split()
s1 = int(s1)
s2 = int(s2)
count = 0
while(s1>1 and s2>1):
    if s1<s2:
        s1+=1
        s2-=2
    else:
        s1-=2
        s2+=1

    count+=1
print(count)

#!/usr/bin/python

import sys
line = sys.stdin.readline()

cont1 = int(line.split()[0])
cont2 = int(line.split()[1])

x = 0
while (cont1 > 0 and cont2 > 0 and (cont1 != 1 and cont2 != 1)):
        x+=1
        cont1 -= 2
        cont2 -= 2
        if (cont1 < cont2):
                cont1+=3
        else:
                cont2+=3
print x

a, b = map(int, input().split())
if a - b % 3 == 0:
    print(max(a - 2 + b - 2 + 1, 0))
else:
    print(a + b - 2)

a, b = map(int, input(). split())
z = 0
while a>0 and b>0:
    if a<b :
        a,b=b,a
    a -= 2
    b += 1
    z += 1
    print(a,b)
print(z)

import math
import itertools
import collections

def getdict(n):
    d = {}
    if type(n) is list:
        for i in n:
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
    else:
        for i in range(n):
            t = ii()
            if t in d:
                d[t] += 1
            else:
                d[t] = 1
    return d
def cdiv(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a*b) // math.gcd(a, b)

a = li()
suma = sum(a)
if suma % 3 == 0:
    print(suma - 3)
else:
    print(suma - 2)

def game(a,b,count):
    if(a==0 or b==0):
        return count
    else:
        if(count%2==0):
            return game(a+1,b-2,count+1)
        else:
            return game(a-2,b+1,count+1)
a,b=map(int,input().split())
res=game(a,b,0)
print(res)

a, b = map(int, input().split())
res = 0
while(a > 0 and b > 0):
    res += 1
    if(a <= b):
        a += 1
        b -= 2
    else:
        b += 1
        a -= 2

print (res)

import sys

inp=[]
i=0
for line in sys.stdin.readline().splitlines():
	for num in line.split():
		#print int(num)
		inp += [int(num)]
		#i+=1

#inp = [100,100]
#inp = [1,1]
ans = 0
print ans
while(1):
    if(inp[0]<=0 or inp[1]<=0):
        break
    if(inp[0]<=inp[1]):
        inp[0]+=1
        inp[1]-=2
    else:
        inp[1]+=1
        inp[0]-=2
    ans+=1
print ans

a,b = map(int, input().split())
res = 0
if (a > 1) and (b > 1):
    while a > 0 and b > 0:
        a, b = min(a, b), max(a, b)
        a += 1
        b -= 2
        res += 1
    print(res)
else:
    print(0)

read = lambda: map(int, input().split())
a1, a2 = read()
if a1 <= 1 and a2 <= 1:
    ans = 0
else:
    ans = 0
    cur = 0
    while a1 > 0 and a2 > 0:
        cur = 1 if a1 < a2 else 2
        if (a1, a2) == (100, 100): cur = 0
        if cur == 0:
            a1 -= 2
            a2 -= 2
        elif cur == 1:
            a1 += 1
            a2 -= 2
        elif cur == 2:
            a1 -= 2
            a2 += 1
        ans += 1

print(ans)

'__author__'=='deepak Singh Mehta(learning brute force)) '

if __name__=='__main__':
  n,m = map(int,input().split())
  cnt = 0
  if n<3 and m<3:
    print(0)
  else:
    while n!=0 and m!=0:
      if n>m:
        n-=2
        m+=1
      else:
        m-=2
        n+=1
      cnt += 1
    print(cnt)

a,b=map(int,input().split())
flag=1
sum=3
while(a>0 and b>0):
    if(flag==1):
        a+=1
        b-=2
    else:
        b+=1
        a-=2
    sum+=1
print(sum)

read = lambda: map(int, input().split())
a1, a2 = read()
cur = 1
time = 0
while a1 > 0 and a2 > 0:
    if (cur == 1 or cur == 0) and a2 <= 2 or a1 >= 100: cur = 2
    if (cur == 2 or cur == 0) and a1 <= 2 or a2 >= 100: cur = 1
    if a1 == 100 and a2 == 100: cur = 0
    a1 -= 2
    a2 -= 2
    if cur == 1: a1 += 3
    elif cur == 2: a2 += 3
    time += 1
    #print(a1, a2)
print(time)

a,b=map(int,raw_input().split())
ans=0
a-=1
while a>0 and b>0:
    if a==1 and b==1:break
    if a<b:
        a+=1
        b-=2
    else:
        a-=2
        b+=1
    ans+=1

print ans

a, b = map(int, input().split())
num = 0
while a > 0 and b > 0:
    if a < b:
        a += 1
        b -= 2
    else:
        a -= 2
        b += 1
    num += 1

print(num)

m, n = input().split()
m=int(m)
n=int(n)

mins = 0
if m<2 or n<2:
	print(0)
else:
	while m>0 and n>0:

		if m<n:
			m+=1
			n-=2
		else:

			m-=2
			n+=1

		mins+=1

	print(mins)

from sys import stdin, stdout
import math

a1, a2 = [int(x) for x in stdin.readline().rstrip().split()]
total = 0

def increaseDecrease(a1, a2):
    add = a1 >> 1
    if add == 0:
        return 0, a2, 0
    a1 -= (add << 1)
    if a1 == 0 and a2 > 1:
        a1 += 2
        add -= 1
    a2 += add

    return a1, a2, add

while a1 > 0 and a2 > 0:
    if a1 > a2:
        a1, a2, add = increaseDecrease(a1, a2)
        total += add
    else:
        a2, a1, add = increaseDecrease(a2, a1)
        total += add

print total

a, b = map(int, raw_input().split())
if a > b:
	a, b = b, a
result = 0
while True:
	while b > 2 and a >= 1:
		b -= 2
		a += 1
		result += 1
	while a > 2 and b >= 1:
		a -= 2
		b += 1
		result += 1
	if (a == 2 and b == 2) or (a == 1 and b == 2) or (a == 2 and b == 1) or (a == 1 and b == 1):
		result += 1
		break

print result

a, b = map(int, input().split())
print(a - 1 + b - 1 - (a == b) if not a == b == 1 else 0)

from  bisect import bisect_right as br
import sys
from collections import *
from math import *
import re
def sieve(n):
    prime=[True for i in range(n+1)]
    p=2
    while p*p<=n:
        if prime[p]==True:
            for i in range(p*p,n+1,p):
                prime[i]=False
        p+=1
    c=0
    for i in range(2,n):
        if prime[i]:
            #print(i)
            c+=1
    return c

def iseven(n):return[False,True][0 if n%2 else 1]
def inp_arr():return list(map(int,input().split()))
def inp():return map(int,input().split())
def lcm(a,b):return (a*b)/gcd(a,b)
max_int = sys.maxsize
mod = 10**9+7

a1,a2=inp()
res=0
while a1!=0 and a2!=0:
    if a1<=a2:a1+=1;a2-=2;
    else:a2+=1;a1-=2;
    res+=1
print(res)

a, b = map(int, input().split())
aux = 0
while(True):
    if a == 0 or b == 0:
        break
    elif a == b:
        a -= 2
        b += 1
    elif a == 1:
        a += 1
        b -= 2
    elif b == 1:
        a -= 2
        b += 1
    elif a < b:
        a += 1
        b -= 2
    elif a > b:
        a -= 2
        b += 1
    aux += 1
print(aux)

import sys

a1, a2 = map( int, sys.stdin.readline().split() )
answer = 1
while a1 > 2 or a2 > 2 :
    if a1 > a2:
        if a1 % 2 == 0:
            answer += a1/2-1
            a2 += a1/2-1
            a1 -= (a1/2-1)*2
        else:
            answer += a1/2
            a2 += a1/2
            a1 = 1
    else:
        if a2 % 2 == 0:
            answer += a2/2-1
            a1 += a2/2-1
            a2 -= (a2/2-1)*2
        else:
            answer += a2/2
            a1 += a2/2
            a2 = 1
print answer

cnt = lambda s, i: s.count(i)
ii = lambda: int(input())
si = lambda : input()
f = lambda : map(int,input().split())
il = lambda : list(map(int,input().split()))
n,m=f()
if m>n:
    (n,m)=(m,n)
t=0
while n>0 and m>0:
    m+=1
    n-=2
    if m>n:
        (n,m)=(m,n)
    t+=1
print(t)

a, b = input().split()
a, b = int(a), int(b)

tid = 0
while a != 0 and b != 0:
	if a % 2 == 1 and b>2:
		a+=1
		b-=2
		tid+=1
	elif b % 2 == 1 and a>2:
		b+=1
		a-=2
		tid+=1
	elif a<=2 and b>a:
		a+=1
		b-=2
		tid+=1
	elif b<=2 and b<a:
		b+=1
		a-=2
		tid+=1
	else:
		a+=1
		b-=2
		tid+=1
print(tid)

a,b=map(int,input().split())
ans=0

while a>0 and b>0:
    if a<b:
        a+=1
        b-=2
    else:
        b+=1
        a-=2
    if a>0 and b>0:
        ans+=1
if a==1 and b==1:
    print(0)
else:
    print(ans)

a, b = raw_input().split(' ')
a = int(a)
b = int(b)
ans = 0
flag = 0
while True:
    if a <= 0 or b <= 0:
        break
    if not flag:
        a += 1
        b -= 2
    else:
        a -= 2
        b += 1
    flag ^= 1
    ans += 1
print ans

a,b=map(int,input().split(' '))
c=0
while(1):

    if(a<=0 or b<=0):
        break;
    if(a==1 and b==1):
        break;
    if(a<b):
        a,b=b,a
    a+=1
    b-=2
    c+=1

print(c)

a1, a2 = map(int, input().split())
b, c, ans = min(a1, a2), max(a1, a2), 0 # b < c
while c-b > 1:
    c -= 2
    b += 1
    ans += 1
b, c = min(b, c), max(b, c)
print(1 if b < 2 and c < 2 else ans + (c-2)*2 + 1)

a1,a2=map(int,input().split())
if a2==a2==1: print(0); exit()
ans=0
while a1 and a2:
    if a1>2:
        while a1>2:
            ans+=1
            a1-=2
            a2+=1
    else:
        while a2>2:
            ans+=1
            a2-=2
            a1+=1
    if (a1==2 and a2==1) or (a2==2 and a1==1) or (a1==a2==2):
        ans+=1; break
print(ans)

n,m=map(int,input().split())
ka=1
while(n>0 and m>0):
    if(n>m):
        n=n-2
        m=m+1
    else:
        m=m-2
        n=n+1
    if(n<1 or m<1):
        break
    ka+=1
print(ka)

# n = int(input())
#
# widths, heights = [0]*n, [0]*n
# total_width = 0
# for i in range(n):
#     widths[i], heights[i] = list(map(int, input().split()))
#     total_width += widths[i]
#
# for i in range(n):
#     print((total_width-widths[i])*())

a1, a2 = list(map(int, input().split()))
minutes = 0
while a1 > 0 and a2 > 0:
    if a1 <= 0 or a2 <= 0:
        break
    if a1 - 2 > 0:
        a1 -= 2
        a2 += 1
    else:
        a2 -= 2
        a1 += 1
    if a1 > 0 and a2 > 0:
        minutes += 1
print(minutes)

# python2
import sys
import os.path
from collections import deque

def main():
    if os.path.exists('input.txt'):
        input = open('input.txt', 'r').read()
    else:
        input = sys.stdin.read()
    #--------------------------------INPUT---------------------------------
    data = list(map(int, input.split()))
    a1,a2,counter = data[0],data[1],0
    while a1>0 and a2>0:
        if a1<=a2:
            a1+=1
            a2-=2
        else:
            a2+=1
            a1-=2
        counter+=1
    output = counter
    #-------------------------------OUTPUT----------------------------------
    if os.path.exists('output.txt'):
        open('output.txt', 'w').writelines(str(output))
    else:
        sys.stdout.write(str(output))

if __name__ == "__main__":
    main()

percent = [int(x) for x in input().split()]
p1 = percent[0]
p2 = percent[1]
n = 0
while p1 > 0 and p2 > 0:
    a = abs(p1-p2)
    if 1==p1==p2:
        n+=1
        break
    if a == 0:
        n += 2*min((p1,p2))-2
        break
    elif a == 1:
        n += 2*min((p1,p2))+1
        break
    elif a == 2:
        n += 2*min((p1,p2))
        break
    else:
        n+=1
        if p1 < p2:
            p1+=1
            p2-=2
        else:
            p1-=2
            p2+=1
print(n)

s=input().split();a=int(s[0]);b=int(s[1]);ans=0
while 1:
    if min(a,b)==a:
        a+=1
        b-=2
        ans+=1
        if b<=0:
            break
    else:
        b+=1
        a-=2
        ans+=1
        if a<=0:
            break
if a==1 or b==1:
    print(0)
else:
    print(ans)

a1, a2 = map(int, input().split())
ans = 0
while a1 > 0 and a2 > 0:
    if a2 <= 2:
        a1, a2 = a2, a1
    a1 += 1
    a2 -= 2
    ans += 1
print(ans)

n,m = list(map(int,input().split()))
cnt = 0
while n and m:

    if n > m:
        n,m = m, n

    n = min(100, n+1)
    m-=2
    cnt += 1
print(cnt)

a,b = map(int,raw_input().split());
print a + b - min(a,b) + 1;

num = input()
a = []

def get_the_data(count, num, arr):
    for i in range(0, len(num)):
        if num[i] == ' ':
            arr.append(int(num[count:i]))
            count = i+1
        elif i == len(num)-1:
            arr.append(int(num[count:len(num)]))
    return arr

arr = get_the_data(0, num,  a)
arr.sort()
if arr[0] <= 2 or arr[1] <= 2:
    print(0)
else:
    time = 0
    first = True
    while arr[0] > 0 and arr[1] > 0:
        if arr[0] == 1 or arr[0] == 2:
            first = True
        elif arr[1] == 1 or arr[1] == 2:
            first = False

        if first == True:
            arr[0] += 1
            arr[1] -= 2
        else:
            arr[1] += 1
            arr[0] -= 2
        time += 1

    print(time)

x, y = map(int, input().split())
print(max(x + y - 3 + (x % 2 and y % 2), 0))

n,m=map(int,input().split())
count=1

while(True):
    if(n==1 and m==1):break
    elif(n==1 and m==2):break
    elif(n==2 and m==1):break
    elif(n==2 and m==2):break
    else:
        if(n<m):
            n+=1
            m-=2
        else:
            n-=2
            m+=1

        count+=1
print(count)

a1,a2=map(int,input().split())
t=0
stop=False
while not stop:
    if(a1==1 and a2==1):
        print(0)
        stop=True

    if(a1<=0 or a2<=0):
        stop=True
    a=min(a1,a2)
    b=max(a1,a2)
    a+=1
    b-=2
    a1=a
    a2=b
    t+=1
print(t)

import math
a,b = map(int,input().split())
m = max(a,b)
mi = min(a,b)
charge = 1
game = -2
ans = 0
while (m>0 or mi>0 and (m<100 or mi<100)):
    if (m==1 or m-2==0):
        mi,m = m,mi
    mi += charge
    m += game
    #print(m,mi)
    if (m <= 0 or mi <= 0):
        ans += 1
        break
    else:
        ans += 1
print(ans)

a1,a2=map(int,input().split())
t=0
stop=False
while not stop:
    if(a1==1 and a2==1):
        print(0)
        stop=True

    if(a1<=0 or a2<=0):
        stop=True
    a=min(a1,a2)
    b=max(a1,a2)
    a+=1
    b-=2
    a1=a
    a2=b
    t+=1
    print(a1,a2)
print(t)

x,y = map(int, input().split())
ans = 0
while max(x,y) > 2:
    a = max(x,y)
    b = min(x,y)
    ans += (a-1)//2
    b += (a-1)//2
    a -= 2*((a-1)//2)
    x = a
    y = b

print(ans+1)

read = lambda: map(int, input().split())
a1, a2 = read()
cur = 1
time = 0
while a1 > 0 and a2 > 0:
    if a2 <= 2: cur = 2
    if a1 <= 2: cur = 1
    if a1 == 100: cur = 2
    if a2 == 100: cur = 1
    if a1 == 100 and a2 == 100: cur = 0
    if cur == 0:
        a1 -= 2
        a2 -= 2
    elif cur == 1:
        a1 += 1
        a2 -= 2
    elif cur == 2:
        a1 -= 2
        a2 += 1
    time += 1
    #print(a1, a2)
print(time)

a1,a2 = map(int,raw_input().split())

if a1 <= 0 or a2 <= 0:
    print 0
elif a1 <= 2 and a2 <= 2:
    print 1
elif (a1-a2)% 3 == 0:
    print (a1+a2)-3
else:
    print (a1+a2)-2

n,m=map(int,input().split())
count=0
while n!=0 and m!=0:
	if n>m:
		n-=2
		m+=1
	else:
		if n==100 and m==100:
			n-=2
			m-=2
		else:
			m-=2
			n+=1
	count+=1
print(count)

a1, a2 = map(int, raw_input().split())
minutesplay = 0

while True:

	if a1 < a2:

		charge = "a1"
	else:

		charge = "a2"
	"""

	if a1 == 1 or a2 == 1:

		if a1 == 1:

			charge = "a1"

		else:

			charge = "a2"

	"""
	if charge == "a1":

		a1 += 1
		a2 -= 2

	else:

		a1 -= 2
		a2 += 1

	if a1 <= 0 or a2 <= 0:
		break

	minutesplay += 1

print minutesplay

a,b=map(int,input().split())
cnt=0
while True:
    if a>b:
        a-=2
        b+=1
    elif a<=b:
        a+=1
        b-=2
    cnt+=1
    if a<=0 or b<=0:
        break
print(cnt)

a , b = map(int , input().split())
ans = 0
while a > 0 and b > 0:
    ### gonna only charge the smallest percent
    if a > b :
        a-=2
        b+=1
    else :
        b-=2
        a+=1
    ans +=1
print(ans )

a,b=map(int,raw_input().split())
ans=0
a-=1
while a>0 and b>0:
    if a==1 and b==1:break
    if a<b:
        a+=1
        b-=2
    else:
        a-=2
        b+=1
    ans+=1

print ans

a, b = map(int, raw_input().split())
if a > b:
	a, b = b, a
result = 0
for i in xrange(200):
	for j in xrange(200):
		term1 = a - 2*i + j
		term2 = b - 2*j + i
		if min(term1, term2) == 0 and max(term1, term2) > 0:
			result = max(result, i+j)
			break

print result

a, b = sorted(map(int, input().split()))
res = 0
while a > 2 or b > 2:
    x, y = divmod(b, 2)
    if y == 0:
        x -= 1
        y = 2
    a += x
    res += x
    b = y
    a, b = sorted([a, b])
if a == 2 and b == 2:
    res += 1
print(res)

n , m = map(int,input().split())
c=0
while n>0 and m>0:
    if n>m:
        n-=2
        m+=1
    else:
        m-=2
        n+=1
    c+=1
print(c)

m,n=map(int,input().split())
p=0
if m==1 and n==1:
    print("0")
elif m>n:
    while n>0 and m>0:
        k=m%2
        if k==0:
            if m//2>1:
                m=(m//2)-1
                p=p+m
                m=n+m
                n=k+2
            else:
                m=m//2
                p=p+m
                m=n+m
                n=k
        else:
            m=m//2
            p=p+m
            m=n+m
            n=k
else:
    while n>0 and m>0:
        k=n%2
        if k==0:
            if n//2>1:
                n=(n//2)-1
                p=p+n
                n=m+n
                m=k+2
            else:
                n=n//2
                p=p+n
                n=m+n
                m=k
        else:
            n=n//2
            p=p+n
            n=m+n
            m=k
print(p)

x,y = map(int,input().split())
ans =0
while (x!=0 and y!=0):
    temp1 =x
    temp2 =y
    x= min(temp1,temp2)

    y = max(temp1,temp2)
#    print('-'*10)
#    print("x is  ",x)
#    print("y is  ",y)
#    print('-'*10)
    x = x+1
    y = y-2
#    print('*'*10)
#    print("x is  ",x)
#    print("y is  ",y)
#    print('*'*10)

    ans+=1

print(ans)

a = raw_input().split(" ")
x = int(a[0])
y = int(a[1])
i = 0
while (x!=0 and y!=0):
    if x>y:
        x-=2
        y+=1
    else:
        y-=2
        x+=1
    if (x>-1 and y > -1):
        i+=1
print i

n, m = map(int, input().split())
c = 0

while n > 0 and m > 0:
    if n > m:
        m += 1
        n -= 2
    else:
        n += 1
        m -= 2
    c += 1

print(c)

a,b = map(int,raw_input().split())
ans = 0
while 1:
	if a<=0 or b<=0:
		break
	if a>=b:
		b+=1
		a-=2
		ans+=1
	else:
		a+=1
		b-=2
		ans+=1
print ans

import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

# For getting input from input.txt file
#sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')
def inp():
    return(int(input()))

def inlist():
    return(list(map(int, input().split())))

def instr():
    s = input()
    return(list(s[:len(s)]))

def invr():
    return(map(int, input().split()))

def def_value():
    return 0

def solve(a, b, res):
    if b <= 2:
        return res+1
    sec = (b-1) // 2
    b = ((b-1) % 2) + 1
    a = a + sec
    return solve(b, a, res+sec)

a, b = invr()
if a == 1 and b == 1:
    print(0)
else:

    res = solve(a, b, 0)
    print(res)

# @Date    : 2016-06-25 17:45:27
# @Author  : Samandar Ravshanov (ravshanoff@protonmail.com)
# @Problem : http://codeforces.com/problemset/problem/651/A

import unittest

from random import randint
from sys import maxsize

import pprint

class StressTest(unittest.TestCase):
	known_values = (
		# a,   b,        expected
		( 3,   5,  		6),
		( 4,   4,  		5),
	)

	def test_known_cases(self):
		for a, b, expected in self.known_values:
			self.assertEqual(expected, NaiveSolution().joysticks(a, b))
			self.assertEqual(expected, GreedySolution().joysticks(a, b))
			#self.assertEqual(expected, DPSolution().joysticks(a, b))

	def ptest_all_cases(self):
		while True:
			a = randint(1, 50)
			b = randint(1, 50)
			memo_res = NaiveSolution().joysticks(a, b)
			greedy_res = GreedySolution().joysticks(a, b)
			print(a, b)
			self.assertEqual(memo_res, greedy_res)

class NaiveSolution:   # C(a, b) = max(1 + C(a+1,  b-2),  1 + C(a-2, b+1))
	def joysticks(self, a, b):
		# base case
		if a < 1 or b < 1:
			return 0

		if not hasattr(self, 'memo'):
			self.memo = {}

		if self.memo.get((a, b)):
			return self.memo.get((a, b))

		# recursive cases
		self.memo[(a, b)] = 1 + max(
				self.joysticks(a+1, b-2),
				self.joysticks(a-2, b+1)
			)

		#print(self.memo)

		return self.memo[(a, b)]

class DPSolution:
	def joysticks(self, a, b):
		m = max(a, b) + 3
		dp = [[0 for x in range(m)] for x in range(m)] # dp[a][b]

		for row in range(2, a+2):
			for col in range(2, b+2):

				dp[row][col] = dp[col][row] = 1 + max(
						dp[row-2][col+1],
						dp[row+1][col-2]
					)

		pprint.pprint(dp)
		a += 1
		b += 1

		return dp[a][b]

class GreedySolution:
	def joysticks(self, a, b):
		if a < 2 or b < 2:
			return 0
		minutes = 0
		while a > 0 < b:
			if a <= b:
				a += 1
				b -= 2
			else:
				b += 1
				a -= 2

			minutes += 1

		return minutes

if __name__ == '__main__':
	#unittest.main()

	a, b = tuple(input().strip().split())
	ans = GreedySolution().joysticks(int(a), int(b))
	print(ans)

s=input().split();a=int(s[0]);b=int(s[1]);ans=0
while 1:
    if min(a,b)==a:
        a+=1
        b-=2
        ans+=1
        if b<=0:
            break
    else:
        b+=1
        a-=2
        ans+=1
        if a<=0:
            break
if a==1 and b==1:
    print(0)
else:
    print(ans)

x,y=raw_input().split(' ')
x=int(x)
y=int(y)

for i in range(0,1000000):
    if x<=0 or y<=0:
        print i
        break
    elif x>=y:
        x=x-2
        y=y+1
        continue
    elif x<=y:
        y=y-2
        x=x+1
        continue

proz_1, proz_2 = input().split()
proz_1, proz_2  = int(proz_1), int(proz_2)
count=0
while proz_1>=0 or proz_2>=0:
    print(proz_1,proz_2)
    if proz_1 < proz_2:
        proz_1 += 1
        proz_2 -= 2
        count+=1
    else:
        proz_1 -=2
        proz_2 +=1
        count+=1
    if proz_1 ==1 or proz_2 ==1:
        break
print(count)

a, b = sorted(map(int, input().split()))
print(a + b - 3 + bool((b - a) % 3))

joystick = map(int,raw_input().split())

result = 0
while True:
    joystick = sorted(joystick)

    joystick[0] += 1
    joystick[1] -= 2

    result += 1

    if joystick[0] <= 0:
        break

print result

a1,a2 = map(int,raw_input().split())

if a1 == 1 and a2 == 1:
    print 1
elif (a1-a2)% 3 == 0:
    print (a1+a2)-3
else:
    print (a1+a2)-2

import sys
def f():
    a = int(sys.argv[1])
    b = int(sys.argv[2])
    count = 0
    while a > 0 and b > 0:
        if a > b:
            b += 1
            a -= 2
        else:
            a += 1
            b -= 2
        count += 1
    return count

s=input().split();a=int(s[0]);b=int(s[1]);ans=0
while 1:
    if min(a,b)==a:
        a+=1
        b-=2
        ans+=1
        if b<=0:
            break
    else:
        b+=1
        a-=2
        ans+=1
        if a<=0:
            break
    if a==1 or b==1:
        break
print(ans)

from sys import stdin

def algo(a):
	minutes = 0

	if(a[0] < a[1]):
		connected = 0
	else:
		connected = 1

	while(a[0] > 0 and a[1] > 0):
		a[connected] += 1
		a[1-connected] -= 2

		if(a[1-connected] <= 2):
			connected = 1-connected

		minutes += 1

	return minutes

def main():
	a = [int(x) for x in stdin.readline().strip().split(' ')]
	minutes = algo(a)
	print(minutes)

if __name__ == '__main__':
	main()

a,b=map(int,raw_input().split())
l=min(a,b)
g=max(a,b)
count=0
while l>0 and g>0:
    l+=1
    g-=2
    p=min(l,g)
    q=max(l,g)
    l=p
    g=q
    count+=1
print count

a,b=map(int,input().split())
cnt=0
while a>0 and b>0:
    cnt+=1
    a,b=max(a,b),min(a,b)
    a-=2
    b+=1
print(cnt)

a1,a2=map(int,input().split())
min=0
while (a1>1) and (a2>1):
    if a1<=a2:
        a1+=1
        a2-=2
        min+=1
    else:
        a2+=1
        a1-=2
        min+=1
print(min)

a, b = map(int, input().split())
r = abs(a - b)
if a == b:
    if a == 1:
        print(1)
    else:
        print(a + b - 3)
else:
    if min(a,b) == 1 and max(a, b) == 2:
        print(1)
    else:
        print((a + b) // 2 * 2 - 2)

a, b = [int(x) for x in input().split()]
count = 0
while a > 0 and b > 0:
    if a == 1:
        a += 1
        b -= 2
    elif b == 1:
        b += 1
        a -= 2
    elif a % 2 == 0:
        a += 1
        b -= 2
    else:
        b += 1
        a -= 2
    count += 1
print(count)

a,b = map(int,raw_input().split())
c = 0
menor = min(a,b)
maior = max(a,b)
while True:
    if maior == 0 or menor ==0:break
    maior -= 2
    menor += 1
    if maior<3:maior,menor = menor,maior
    c +=1
print c

n,m=map(int,input().split())
count=1

while(True):
    if(n==1 and m==1):break
    elif(n==1 and m==2):break
    elif(n==2 and m==1):break
    elif(n==2 and m==2):break
    else:
        if(n<m):
            n+=1
            m-=2
        else:
            n-=2
            m+=1

        count+=1
print(count)

a,b=map(int,input().split())
c=max(a,b)
d=min(a,b)
if c<2:
    print(0)
elif (c-d)%3==0:
    print(max(c+d-3,1))
elif (c-d)%3!=2:
    print(max(c+d-2,1))

a,b=[int(x) for x in input().split()]
c=0
while(a>0 and b>0):
    if a<b:
        a+=1
        b-=2
    else:
        b+=1
        a-=2
    c+=1
print(c)

def game(a,b,count):
    if(a==0 or b==0):
        return count
    else:
        if(count%2==0):
            return game(a+1,b-2,count+1)
        else:
            return game(a-2,b+1,count+1)
a,b=map(int,input().split())
res=game(a,b,0)
print(res)

a1, a2 = map(int, raw_input().split())

timeList = {}

def totalTime(a1, a2):
    print totalTimeAUX(a1, a2, 0, 0)

def totalTimeAUX(a1, a2, charger, time):
    global timeList
    if a1 <= 0 or a2 <= 0 or (a1 == 1 and charger != 1) or (a2 == 1 and charger != 2):
        return time
    else:
        if (a1, a2, charger) in timeList:
            return timeList[a1, a2, charger]
        else:
            if charger == 0:
                timeList[a1, a2, 1] = totalTimeAUX(a1, a2, 1, time)
                timeList[a1, a2, 2] = totalTimeAUX(a1, a2, 2, time)
                return max(timeList[a1, a2, 1], timeList[a1, a2, 2])
            elif charger == 1:
                timeList[a1 + 1, a2 - 2, 1] = totalTimeAUX(a1 + 1, a2 - 2, 1, time + 1)
                timeList[a1 + 1, a2 - 2, 2] = totalTimeAUX(a1 + 1, a2 - 2, 2, time + 1)
                return max(timeList[a1 + 1, a2 - 2, 1], timeList[a1 + 1, a2 - 2, 2])
            else:
                timeList[a1 - 2, a2 + 1, 1] = totalTimeAUX(a1 - 2, a2 + 1, 1, time + 1)
                timeList[a1 - 2, a2 + 1, 2] = totalTimeAUX(a1 - 2, a2 + 1, 2, time + 1)
                return max(timeList[a1 - 2, a2 + 1, 1], timeList[a1 - 2, a2 + 1, 2])

totalTime(a1, a2)

a,b=map(int,raw_input().split())
a=min(a,b)
b=max(a,b)
count=0
while True:
    a+=1
    b-=2
    count+=1
    if a>b:
        a,b=b,a
    if a<=0 or b<=0:
        break

print count

print(max(map(int, input().split())) + 1)

a, b = map(int, input().split())
max_num = max(a, b)
min_num = min(a, b)
ans = 0
while min(max_num, min_num) > 0:
    min_num += 1
    max_num -= 2
    max_num, min_num = max(max_num, min_num), min(max_num, min_num)
    if min_num < 1:
        break
    ans += 1
print(ans)


After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon.Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another.It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell.

n = input()
if n == 0:
    print(1)
else:
    num = (6+6*n)/2
    print(1+n*num)

n = int(input())
print(3 * n * (n + 1) + 1)

n= input()

if n == 0:
    print 1
else:
    n = n +1

    print 3*n*n - 3 * n + 1

n = int(raw_input())

print 1 + 3*n*(n+1)

n = int(input())
if n==0:
    print(1)
elif n==1:
    print(7)
else:
    k = n*(n+1)//2-1
    print(k*6+7)

n = int(input())
n = n + 1
rez = 3*(n-1)*n + 1
print(rez)

# cook your dish here
n=int(input())
print(1+3*n*(n+1))

i = int(input())

print( 1 +  3 * i * (i+1))

k = input()
if k == 0:
    print 1
    exit()
mid = 2 * k + 1
def gauss(m,n):
	return n*(n+1)/2 - m*(m-1)/2
print 2 * gauss(k+1,2*k) + mid

dist = int(input())

nTiles = 1 + ( ((dist * (dist+1))) * 3)

print(nTiles)

from sys import stdin, stdout
from gc import disable

def main() -> int:
  disable()
  n = int(stdin.readline())
  ans = 6 * (2+(n-1))*n//2 + 1
  stdout.write("%i"%ans)
  return 0;
if (__name__ == "__main__"):
  main()

from math import factorial

def nCr(n, r):
    f, m = factorial, 1
    for i in range(n, n - r, -1):
        m *= i
    return int(m // f(r))

print(nCr(int(input()) + 1, 2) * 6 + 1)

__author__ = 'Rasulbek'
n=input()
print(((n*(n+1))*3)+1)

import collections
import math

#n, m = map(int, input().split())
n = int(input())
print(3 * n * n + 3 * n + 1)

n = int(raw_input())
print 3 * n * (n + 1) + 1

n = int(raw_input())
ans = 1 + 6*(n*(n + 1) / 2)
print ans

x=long(raw_input())

y=3*x*x + 3*x + 1

print(y)

from decimal import *
n = Decimal(input())
print( int((0 + n * 6) * (n+1) / 2 + 1+1-1))

import math
n=int(input())
ans=int((n*(12+(n-1)*6))/2)
ans=int(ans+1)
print (ans)

print((lambda x: 6*(x*(x+1)//2)+1)(int(input()))) #python is a meme

n = int(input())
print(1 + 3 * n * (n + 1))

#########			##	##     ##    	  ####  #####  ##     #  ##     #		##
	#			   # #	# #   # #		 #	  #	#	#  # #    #  # #    #	   # #
	#			  #  #	#  ###  #	    #		#	#  #  #   #  #  #   #	  #  #
	#			 #####	#	#	#	   #    ###	#	#  #   #  #  #   #  #    #####
	#			#    #	#		#	   #    # #	#	#  #	# #  #	  # #   #    #
######### 	   #     # 	#		#		##### #	#####  #	 ##  #	   ##  #     #

"""

PPPPPPP       RRRRRRR		    OOOO	  VV        VV    EEEEEEEEEE
PPPPPPPP      RRRRRRRR         OOOOOO     VV       VV	  EE
PPPPPPPPP     RRRRRRRRR       OOOOOOOO    VV      VV	  EE
PPPPPPPP      RRRRRRRR        OOOOOOOO    VV     VV    	  EEEEEE
PPPPPPP       RRRRRRR         OOOOOOOO    VV    VV        EEEEEEE
PP  		  RRRR			  OOOOOOOO    VV   VV         EEEEEE
PP			  RR  RR          OOOOOOOO    VV  VV          EE
PP			  RR    RR         OOOOOO     VV VV           EE
PP			  RR      RR        OOOO      VVVV            EEEEEEEEEE

"""

"""
 Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1
    return x

def factorial(x, m):
	val = 1
	while x>0:
		val = (val * x) % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## nCr function efficient using Binomial Cofficient
def nCr(n, k):
	if k > n:
		return 0
	if(k > n - k):
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0, hi = None):
    if hi == None:
        hi = len(a);
    while lo < hi:
        mid = (lo+hi)//2;
        if a[mid] < x:
            lo = mid+1;
        else:
            hi = mid;
    return lo;

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];

    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;

# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
    prime = [True for i in range(n+1)]
    prime[0], prime[1] = False, False
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    res = []
    for i in range(2, int(x ** 0.5) + 1):
    	while x % i == 0:
    		res.append(i)
    		x //= i
    if x != 1:
   		res.append(x)
    return res
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

from itertools import permutations
import math

from bisect import bisect_left

def solve():
	n = int(input())
	print(1 + 6 * (n * (n + 1) // 2))

if __name__ == '__main__':
	for _ in range(1):
		solve()
	# fin_time = datetime.now()
# 	print("Execution time (for loop): ", (fin_time-init_time))

#!/usr/bin/env python3
import collections, itertools, functools, math

# 1 + 6 + 12 + 18 = 37
# 1, 6, 12, 18

def solve():
    n = int(input())
    return 1 + ((6*n)*(n+1))//2

if __name__ == '__main__':
    print(solve())

n = int(input())
print(n * (3 + 3 * n) + 1)

# You lost the game.
n = int(input())
print(1+3*n*(n+1))

n = int(raw_input())
result = 1
result += 3*n*(n+1)
print result

n = int(input())

print 3 * (n) * (n + 1) + 1

s = raw_input()
n = long(s)
print (n + 1) * n / 2 * 6 + 1

# from debug import debug
import sys
mod = int(1e9)+7
inf = int(1e10)
n = int(input())
print(3*(n)*(n+1)+1)

n = int(input())
print(3 * n * (n + 1) + 1)

from decimal import *
n = Decimal(input())
print( int((0 + n * 6) * (n+1) / 2 + 1))

N = int(input())

ans = 1

add = 6

ans += 6 * ((N + 1) * N // 2)

print(ans)

#!/usr/bin/env python
# coding=utf-8

n = input()
print (n + 1) ** 3 - n ** 3

n = int(raw_input())
print 1 + ((n+1)*6*n)/2

n = int(raw_input())

print 1 + 3*n*(n+1)

n=int(raw_input())
if n == 0:
    print 1
elif n == 1:
    print 7
else:
    print 3*n*n + 3*n + 1

#map(int,raw_input().split())
n = int(raw_input())

print 6*(((n+1)*n)/2) + 1

#!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange as range
from math import ceil, factorial, log
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
from fractions import Fraction
from functools import reduce
import string
import sys
import os
import re
inf = float('inf')
mod = int(1e9) + 7
mod_ = 998244353

def solve():
    n = int(input())
    print(6 * n*(n + 1)//2 + 1)

def main():
    solve()

BUFSIZE = 8192
class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(
                b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()
class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()
def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
    def bootstrap(cont):
        call, arg = cont.switch()
        while True:
            call, arg = cont.switch(to=continulet(
                lambda _, f, args: f(*args), call, arg))
    cont = continulet(bootstrap)
    cont.switch()
    main()

n = int(input())
print(n * (n + 1) * 3 + 1)

n = int(input())
print(1 + 3 * n * (n + 1))

def main():
	n = int(raw_input())
	print 1+(n*(n+1))*3

main()

n = int(input())

result = 1

result += int(6 * (n * n - (n * (n - 1)) / 2))

print(result)

distance = int(input())
result = float()
#result = (2 * 6 + (distance - 1) * 6)*distance / 2

test = (6+distance*6) / 2 * distance + 1
print(int(test))

from sys import stdin

n = int(stdin.readline())
# 1 + 6  + 12 + 18  + 24
res = int(1 + (6 + 6 * n) * n / 2)
print(res)

#hexagons
n=int(input())
if(n==1):
    print(7)
elif(n==0):
    print(1)
else:
    print( int( ((6+(6*n))/2)*n +1) )

if __name__=='__main__':
    n = int(input())
    cell = 0
    if n<54794158:
        cell = 6*(n*(n+1)/2)+1
    else:
        cell = 6*(n*(n+1)/2)
    print (int(cell))
'''
D. Hexagons!
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon.

Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another.

It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell.
Input

The only line of the input contains one integer n (0 ≤ n ≤ 109).
Output

Output one integer — the number of hexagons situated not farther than n cells away from a given cell.
Examples
Input

2

Output

19

'''

x=long(raw_input())

y=0

if x==0:
    y=1

if x>0:
        y=1+x*2
if x>1:
        for i in range(0,x):
                y=y+x*4-2*i

print(y)

n = int(input())
s = 1
for i in range(0, n):
    s += n * 6
print(s)

def iter_pow(x, n):

    res = 1

    while n:
        if n & 1:
            res = res * x
        x = x * x
        n = n >> 1
    return res

n = int(input())
print((iter_pow(6, n) - 1)//5)

n=int(input())
res = (6*(n+1))+1
print(res)

ans=1
n=int(input())
for i in range(1,n-1):
    ans+=i*6
print(ans)

a=input()
x=0

x+=1
for i in range (0,a) :
    x+=(2**i)*6
print x

n = int(input())
counter = 1
counter += 6 * n * (n + 1) / 2
print(counter)

n = int(input())
if n==0:
    print(1)
elif n==1:
    print(7)
s = 7
for i in range(2,n+1):
    s+=6*i
print(s)

import io
import sys
n = int(sys.stdin.readline().strip())
print (1 + 6 * ((n + 1)/2 * n))

if __name__=='__main__':
    n = int(input())
    cell = 6*(n*(n+1)/2)+1

    print (int(cell))
'''
D. Hexagons!
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon.

Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another.

It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell.
Input

The only line of the input contains one integer n (0 ≤ n ≤ 109).
Output

Output one integer — the number of hexagons situated not farther than n cells away from a given cell.
Examples
Input

2

Output

19

'''

def iter_pow(x, n):

    res = 1

    while n:
        if n & 1:
            res = res * x
        x = x * x
        n = n >> 1
    return res

n = int(input())
print(1 + 6 * (iter_pow(2, n) - 1))

n = int(input())
if(n == 0):
    print(1)
else:
    print((n + 1) * n / 2 * 6 + 1)

n = int(input())

if n == 0:
    print(1)
else:
    print((n+1)*6+1)

n=input()
n=n+1
result=1+(3*(n)*(n+1))/2

print result

print sum(2 * (k + 1) + 2 * (2 * k - 1) for k in range(input())) + 1

n = input()
ans = 6*((2**n) -1)
print ans+1

n = input()

if n == 0:
    p = 1
elif n == 1:
    p = 7
else:
    p = (n+1)*6 + 1

print p

n=int(input())
t=0
for i in range (1,n+1):
    t=t+i*6
print(t)

n = int(input())
if n == 0:
    print("1")
else:
    if n == 1:
        print("7")
    else:
        m = 6 * 6 * (n - 1)/2 + 1
        print(m)

n = int(raw_input())

res = 6
_sum = 6

for x in range(n-1):
    res += 6
    _sum += res

print _sum + 1

def sum_ab(a,b):
    return int((a + b) / 2 * (b - a + 1))
n = int(input())
ile_6 = sum_ab(1, n)
print(ile_6 * 6 + 1)

n=int(input())
if n==0:
    print("0")
else:
    print(1+(2*3**n))

n = int(raw_input())
print 6 * (n + 1) + 1

import sys

n = int(input())

print(- 6 *(1 - 2 ** n) + 1)

x = int(raw_input())
r = 1
p = 6
if x==0:
    print 0
    exit()
while x > 0:
    r += p
    p += 6
    x -= 1
print r

n=input()
result=1+(3*(n)*(n+1))/2

print result

n = int(raw_input())
print (n * (2 + (n) * 6)) / 2

n=input()
sum=1+6*(pow(2,n) -1)
print sum

def num_hexes(n):
  answer = 1
  for i in xrange(1, n + 1):
    answer += 6 * i
  return answer

print num_hexes(2)

n = int(input())

print(int(6*n*(n+1)/2))

a=input()
x=0
if a>=1 :
    x+=1
for i in range (0,a) :
    x+=(2**i)*6
print x

from math import factorial

def nCr(n, r):
    f, m = factorial, 1
    for i in range(n, n - r, -1):
        m *= i
    return int(m // f(r))

n = int(input())
print(nCr(n + 1, 2) * 6 + 1 if n else 0)

import math
n=int(input())
ans=int(6*(math.pow(2,n)-1))
ans=int(ans+1)
print (ans)

n = int(input())

if n == 0:
    print(1)
else:
    print((n+1)*6+1)