Problem:
 Score : 300 points    Problem Statement Snuke loves puzzles.  Today, he is working on a puzzle using S - and c -shaped pieces.
In this puzzle, you can combine two c -shaped pieces into one S -shaped piece, as shown in the figure below:     Snuke decided to create as many Scc groups as possible by putting together one S -shaped piece and two c -shaped pieces.  Find the maximum number of Scc groups that can be created when Snuke has N  S -shaped pieces and M  c -shaped pieces.      Constraints  1 ≤ N,M ≤ 10^{12}         Input The input is given from Standard Input in the following format:  N  M       Output Print the answer.        Sample Input 1 1 6      Sample Output 1 2  Two Scc groups can be created as follows:   Combine two c -shaped pieces into one S -shaped piece  Create two Scc groups, each from one S -shaped piece and two c -shaped pieces        Sample Input 2 12345 678901      Sample Output 2 175897

Solution (Python):
N, M = [int(_) for _ in input().split()]

result = 0

x = min(N, M // 2)

result += x
M -= x * 2

y = M // 4

result += y
M -= y * 2

print(result)

Solution (Python):

line = input().split()
n = int(line[0])
m = int(line[1])

if n >= m//2:
    print(m//2)
else:
    print(n + (m-2*n)//4)

Solution (Python):
def count(s, c):
    if s >= c / 2:
        return int(c / 2)

    return s + int((c - 2 * s) / 4)


n, m = (int(i) for i in input().split())
print(count(n, m))

Solution (Python):
n, m = list(map(int, input().split()))
if 2*n<=m:
  ans = n+(m-2*n)//4
else:
  ans = m//2
print(ans)

Solution (Python):
s,c=map(int,input().split())
if 2*s>=c:
    print(c//2)
else:
    print(s+(c-2*s)//4)

Solution (Python):
s,c = (int(i) for i in input().split())
S = s
C = int(c/2)

total = max(S,C) - abs(S-C)
total += int((C-total)/2)

print(total)

Solution (Python):
N, M = list(map(int, input().split()))
ans = 0
if N >= M//2:
    ans += M//2
    N -= M//2
    M %= 2
else:
    ans += N
    M -= 2*N
    N = 0
ans += M//4
print(ans)

Solution (Python):
n,m = map(int,input().split())
if n > m//2:
	print(m//2)
else:
	print(n+(m-2*n)//4)

Solution (Python):
N,M = map(int,input().split())

if M//2 < N:
    print(M//2)
else:
    print((N+(M//2))//2)

Solution (Python):
n,m=map(int,input().split())
if m<=2*n:
    print(m//2)
else:
    v=m-2*n
    print(n+v//4)

Solution (Python):
n,m=map(int,input().split())
if n*2>m:
    print(m//2)
elif n*2==m:
    print(n)
else:
    print(n+(m-n*2)//4)

Solution (Python):

s, c = map(int, input().split())
scc = min(s, c // 2)
cccc = (c - 2 * scc) // 4
print(scc + cccc)

Solution (Python):
N, M = map(int, input().split())
ans = min(N, M // 2)
N, M = N - ans, M - ans * 2
ans += M // 4
print(ans)

Solution (Python):
N,M=map(int,input().split())
res=0

if N >= M // 2:
	res = M // 2
else: 
	res = N
	M -= N * 2
	res += M // 4

print(res)

Solution (Python):
n, m = map(int,input().split())
 
if n >= m // 2:
    ans = m // 2
 
else:
    ans = n
    m -= n * 2
    ans += m // 4
 
print(ans)

Solution (Python):
S, C = map(int, raw_input().split(' '))

X = min(S, C / 2)

res = X

C -= 2 * X

res += C / 4

print res

Solution (Python):
n, m = map(int,input().split())

if n >= m // 2:
    ans = m // 2

else:
    ans = n
    m -= n * 2
    ans += m // 4

print(ans)

Solution (Python):
def scc_puzzle():
	n,m = map(int, raw_input().split(" "))
	max_ans = m/2
	if n>=max_ans:
		print max_ans
		return
	else:
		min_ans = n
		
		while min_ans+1<max_ans:
			current_ans = (max_ans+min_ans)/2
			if _check(current_ans, n ,m):
				max_ans = current_ans
			else:
				min_ans = current_ans
		
		
		print min_ans
		return


def _check(ans, n, m):
	total_c = ans*2+(ans-n)*2
	if total_c>m:
		
		return True
	else:
		return False


if __name__ == "__main__":
	scc_puzzle()

Solution (Python):
N, M = map(int, input().split())

ans = min(N, M // 2)
N -= ans
M -= (ans * 2)

ans += M // 4

print(ans)

Solution (Python):
n, m = map(int, input().split())
ret = min(n, m//2)
n -= ret; m -= ret * 2
print(ret + m // 4)

Solution (Python):
kr=list(map(int,input().split()))
n,m=kr[0],kr[1]
if n*2<=m:
    amr=m-n*2
    n+=int(amr/4)
else:
    n=int(m/2)
print(n)

Solution (Python):
n, m = map(int, input().split())
if n * 2 >= m:
    print(m // 2)
else:
    print(n + (m - n * 2) // 4)

Solution (Python):
x = map(int, raw_input().split(" "))
N = x[0]
M = x[1]

ans = 0

if N*2 < M:
    ans += N
    M -= 2*N
    ans += M / 4
else:
    ans += M / 2


print ans

Solution (Python):
N, M = map(int, raw_input().split())
ans = min(N, M/2)
M -= 2*ans
ans += M/4
print ans

Solution (Python):
n, m = map(int, raw_input().split())

m /= 2






x = max((m - n) / 2, 0)
n += x
m -= x

print min(m, n)

Solution (Python):
n,m = map(int,input().split())
count = 0
 
if m > n*2:
    count = n + int((m-2*n)/4)
    print(count)
else:
    count = int(m/2)
    print(count)

Solution (Python):
n, m = map(int, raw_input().split())
if n >= m / 2:
	print m / 2
else:
	print n + (m / 2 - n) / 2

Solution (Python):
n, k = (int(s) for s in input().strip().split(' '))
print((n * 2 + k) // 4 if k/2 > n else k//2)

Solution (Python):
n, k = (int(s) for s in input().strip().split(' '))
print(int((n * 2 + k) / 4) if k/2 > n else int(k/2))

Solution (Python):


n_s, n_c = map(int, input().split())
ans = 0

if n_c >= n_s * 2:
    ans += n_s
    rest_c = n_c - n_s * 2
    ans += rest_c // 4
else:
    ans += n_c // 2

print(ans)

Solution (Python):
nm = raw_input().split()
nm[1] = str(int(nm[1]) / 2)
scc1 = min(int(nm[0]),int(nm[1]))
nm[0] = str(int(nm[0]) - scc1)
nm[1] = str(int(nm[1]) - scc1)
scc2 = int(nm[1]) / 2
print scc1+scc2

Solution (Python):
S, c = map(int, raw_input().split())
if 2*S<c:
    print S + (c - 2*S)/4
else:
    print c/2

Solution (Python):
i = input().split()
s, c = int(i[0]), int(i[1])
ans = int()
if(s * 2 < c):
    ans = int(s + (c - s * 2) / 4)
else:
    ans = int(c / 2)
print(str(ans))

Solution (Python):
m, n = map(int, input().split(" "))

if 2*m>n:
    print(n//2)
else:
    l = n - 2*m
    print(m+l//4)

Solution (Python):











N, M = map(int, raw_input().split())

res = min(N, M/2)

if res == N:
    res += (M - 2*N) / 4

print res

Solution (Python):

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

l = (n*2+m)/4

answer = l if l>= n else min(n,m/2)
print(answer)

Solution (Python):
def main():
    s, c = map(int, raw_input().split())
    count = 0
    if s > c/2:
        return c/2
    elif s == c/2:
        return s
    elif s < c/2:
        return s + ((c-2*s)/4)
print main()

Solution (Python):

def main():
    arg = raw_input().split(" ")
    N = int(arg[0])
    M = int(arg[1])
    c_pattern = (M/2)

    if N < 1 or N > 10**12:
        return 0
    if M < 1 or M > 10**12:
        return 0

    if N == c_pattern:
        return N
    elif N < c_pattern:
        tmp = M - (N * 2)
        return N + (tmp / 4)
    elif N > c_pattern:
        return int(c_pattern)


print main()

Solution (Python):

def main():
    arg = raw_input().split(" ")
    N = int(arg[0])
    M = int(arg[1])
    c_pattern = (M/2)

    if N < 1 or N > 10**12:
        return 0
    if M < 1 or M > 10**12:
        return 0

    if N == c_pattern:
        return N
    elif N < c_pattern:
        tmp = M - (N * 2)
        return N + (tmp / 4)
    elif N > c_pattern:
        return int(c_pattern)


print main()

Solution (Python):
s, c = map(int, raw_input().rstrip("\n").split(" "))

def calc_scc(s, c):
  answer = 0
  if (s * 2) >= c:
    answer = c / 2
  else:
    answer = s + ((  c - (s * 2) )  / 4 )
  return answer

print calc_scc(s, c)

Solution (Python):
N, M = map(int, input().split())
ans = 0
x = min(N, M // 2)
ans += x
N -= x
M -= 2 * x
if M != 0:
    ans += M // 4
print(ans)

Solution (Python):
l = input().split()
N = int(l[0])
M = int(l[1])
if N*2>M:
	Max = M//2
elif N*2 == M:
	Max = N
else:
	N2 = N*2
	Max = (N2 +M)//4
print(Max)

Solution (Python):
import sys

cin = sys.stdin


N, M = map(int, cin.readline().split())

if N*2 < M:
    print(N + (M-N*2)//4)
else:
    print(M//2)

Solution (Python):


n,m=map(int,raw_input().split())
if n>m/2:
 res=m/2
else:
 res=n+(m-2*n)/4
print res

Solution (Python):
n, m = map(int, raw_input().split())
if n > m / 2:
	print m / 2
else:
	print (n * 2 + m) / 4

Solution (Python):



def readln():
    _res = list(map(int,str(input()).split(' ')))
    return _res

a = readln()
m,n = a[0],a[1]
k = m
if k * 2 > n: k = n // 2
n = n - k * 2
m = m - k
k = k + (n // 4)
print(k)

Solution (Python):
S, C = map(int, input().split())
if S > C // 2:
    print(C//2)
else:
    print(S + (C-S*2) // 4)

Solution (Python):
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, M = map(int, input().split())

    ans = min(M//2, (2*N + M)//4)

    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
N,M=map(int,input().split())
a=(M-2*N)//4
if a<0:
    print(min(N,M//2))
else:
    print(N+a)

Solution (Python):
n,m=map(int,input().split());print((min(2*n,m)+m)//4)

Solution (Python):
n,m=map(int,input().split())
print(min(m+2*n,2*m)//4)

Solution (Python):

n_s, n_c = map(int, input().split())
scc_from_s = 0
scc_from_c = 0

if n_s >= 1 and n_c >=2:
	if n_s <= (n_c // 2):
		scc_from_s = n_s
		n_c -= (n_s * 2)
		scc_from_c = n_c // 4
	else:
		scc_from_s = (n_c // 2)
		scc_from_c = 0

scc_sum = scc_from_s + scc_from_c

print(scc_sum)

Solution (Python):
def solve(s, c):
    """rv = min(Sr, Cr//2), where
       Sr = S + a
       Cr = C - 2a  
       thus
       rv = max(min(S + a, C//2 - a) for a in range(0, C//2))
       if a >=0, optimum is Sr == Cr//2, thus
                            S + a == Cr//2 - a
                            a = (C//2 - S) / 2
    """
    a = (c / 2 - s) / 2
    if a < 0:
        a = 0
    al = int(a)
    ar = int(a) + 1
    return max(min(s + a, c//2 - a) for a in (al, ar))


if __name__ == "__main__":
    import sys
    S, C = map(int, sys.stdin.readline().split())
    print(solve(S, C))


def test_solve():
    assert solve(1, 2) == 1
    assert solve(0, 4) == 1
    assert solve(0, 1) == 0


def test_atcode():
    assert solve(1, 6) == 2
    assert solve(12345, 678901) == 175897

Solution (Python):


s,c = map(int, input().split())

ns = max(0, (c - 2*s) // 4)
s += ns
c -= 2*ns

print(min(s,c//2))

Solution (Python):
def countScc(s, c):
    res = 0
    if(2*s <= c):
        res = s
        c = c - 2*s
        res = res + c / 4
    else:
        res = c / 2
    return res

try:
    while True:  
        s, c = raw_input().strip().upper().split()
        print countScc(int(s), int(c))
except EOFError:
    pass

Solution (Python):















def main():
    s, c = map(int, input().split())

    lo, hi = 0, int(1e18)
    
    while hi - lo > 1:
        mi = lo + (hi - lo) // 2

        free = c - 2 * mi
        if free < 0 or s + free // 2 < mi:
            hi = mi
        else:
            lo = mi
    print(lo)

main()

Solution (Python):
inp = list(map(int, input().split()))


s = inp[0]
c = inp[1]

ans = 0
if s*2 <= c:
    ans += s
    c -= 2*s
    s = 0
    if c>=4:
        ans += c//4
elif c//2<=s:
        ans += c//2
        s -= c//2
        c -= 0
else:
    if c>=4:
        ans += c//4



print (ans)

Solution (Python):
n, m = map(int, input().split())
extra_c = m - 2 * n
if extra_c <= 0:
    print(m // 2)
else:
    print(n + extra_c // 4)

Solution (Python):
n, m = (int(_) for _ in input().split())
ans = min(n, m // 2)
m -= ans * 2
ans += m // 4
print(ans)

Solution (Python):
N, M = map(int, input().split())

if 2*N >= M:
  print(M//2)
else:
  result = N
  M -= 2*N
  result += M//4
  print(result)

Solution (Python):
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, M = map(int, input().split())

    if 2*N >= M:
        ans = M // 2
    else:
        top = M // 2
        btm = 0

        while top - btm > 1:
            mid = (top + btm)//2
            if check(N + mid, M - 2*mid):
                btm = mid
            else:
                top = mid

        ans = N + btm

    print(ans)

def check(a, b):
    return 2*a <= b

if __name__ == '__main__':
    solve()

Solution (Python):
u, v = map(int, input().split())
if 2*u > v:
  print(v//2)  
else:
  print((2*u+v)//4)

Solution (Python):



def solve(N, M):
    ans = min(M // 2, N)
    
    x = (M - 2*N) // 4
    for i in range(x - 5, x + 6):
        if i >= 0 and M >= 2 * i:
            M2 = M - 2 * i
            N2 = N + i
            ans = max(ans, min(M2 // 2, N2))

    return ans


N, M = map(int,input().split())
ret = solve(N,M)
print(ret)

Solution (Python):
N, M = map(int, input().split())
if (N*2 >= M):
    print(M//2)
elif (M < 2):
    print(0)
else:
    M -= N*2
    M = M // 4
    print(N + M)

Solution (Python):
S, C = map(int, input().split())

if 2 * S < C:
    a = S + (C - 2 * S) // 4
else:
    a = max(C//2, 0)

print(a)

Solution (Python):
n, m = map(int, raw_input().split())
x0 = min(max(int(m / 4. - n / 2.), 0), m / 2)
print max(min(n + x, (m - 2 * x) / 2) for x in xrange(x0 - 5, x0 + 5) if 0 <= x <= m / 2)

Solution (Python):
if __name__=="__main__":
    [S, C] = map(int,input().split())
    if(C - 2*S > 0):
        ans = S
        ans += (C - 2*S) // 4
    else:
        ans = C//2
    print(ans)

Solution (Python):
n,m=[int(i) for i in input().split()]
ans=0
if m>=n*2:
    ans=n
    m-=n*2
    ans+=m//4
else:
    ans=m//2
print(ans)

Solution (Python):
n, m = map(int, input().split())
a, b = 0, 10 ** 12
while b - a > 1:
    k = (a + b) // 2
    if 2 * k <= m and k <= n + (m - 2 * k) // 2:
        a = k
    else:
        b = k
print(a)

Solution (Python):
n, m = input().split()
num_s = int(n)
num_c = int(m)

if num_c <= num_s * 2:
  
  print(num_c // 2)
else:
  scc = num_s
  num_s = 0
  num_c -= 2 * scc
  scc += num_c // 4
  print(scc)

Solution (Python):
N, M = map(int, input().split())

lb, ub = 0, 10**18
K = 2 * N + M

while ub - lb > 1:
    md = (ub + lb) >> 1
    n, m = N, M
    n -= md
    if n < 0:
        m -= -n * 2
    if md * 2 <= m:
        lb = md
    else:
        ub = md

print(lb)

Solution (Python):



[N, M] = map(int, input().split())

ans = 0

if N * 2 <= M:
    
    print(N + (M-2*N) // 4)

else:
    
    print(M // 2)

Solution (Python):
n, m = list(map(int, input().split()))

x = min(n,  m//2)
r = m - 2 * x
print(x + r // 4)

Solution (Python):
from sys import stdin
x,y =map(int,stdin.readline().split())
z = x*2 + y
mi = min(x,y/2)
x-=mi
y-=mi*2

print mi + y/4

Solution (Python):
S, C = map(int,input().split())
ans = 0
x1 = min(S, C//2)
ans += x1
S -= x1
C -= x1 * 2
ans += C // 4
print(ans)

Solution (Python):
n,m = map(int, raw_input().split())

if 2*n < m:
    print n + (m-2*n)/4
elif 2*n == m:
    print n
else:
    print m/2

Solution (Python):
N, M = map(int, input().split())
print(min(N + int((M - 2*N)/4), int(M/2)))

Solution (Python):
n,m=map(int,raw_input().split())
if n>=2*m:
    print m/2
else:
    if m-2*n>=0:
        m-=2*n
        print n+m/4
    else:
        print m/2

Solution (Python):
n, m = map(int, raw_input().split())

if m < 2 * n:
    print m/2
else:
    print n + (m - 2 * n)/4

Solution (Python):



def solve(n, m):
    x = min(m // 2, n)
    y = (m - 2 * x) // 4
    return x + y


def main():
    n, m = (int(x) for x in input().split())
    print(solve(n, m))


if __name__ == '__main__':
    main()

Solution (Python):



def rl(s): return xrange(len(s))

INF = 2147483647


import sys
stdin = sys.stdin

s, c = map(int, stdin.readline().strip().split())

base = min(s, c // 2)
s -= base
c -= 2*base
rr = base

four = c // 4
c -= 4*c
rr += four

print rr

Solution (Python):
def solve():
    n, m = map(int, input().split())
    ans = 0
    ans += min(n, m // 2)
    m -= n * 2
    if m > 0:
        ans += m // 4
    print(ans)

if __name__=="__main__":
    solve()

Solution (Python):
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

(N, M) = reads()

result = 0

k = min(N, M // 2)
(N, M) = (N - k, M - 2 * k)
result += k

k = M // 4
result += k

print(result)

Solution (Python):


s, c = [int(x) for x in input().split()]
ans = min(s, c // 2)
ans += (c - ans * 2) // 4
print(ans)

Solution (Python):
s,c = map(int, input().split())
total = min(s, c//2)
c -= total * 2
total += c//4
print(total)

Solution (Python):
s, c = map(int, raw_input().split())

first = min(s, c/2)
ans = first
s -= first
c -= first*2

ans += c/4

print ans

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n,m = LI()
    if n >= m//2:
        return m//2
    r = n
    m -= 2*n
    r += m//4

    return r

print(main())