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):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
num = []
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n,m = I()

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

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

Solution (Python):
s,c = list(map(int, input().split()))
ret=0
if 2*s < c:
    c-=2*s
    ret+=s
else:
    ret += c//2
    c = c%2

ret += c // 4
print(ret)

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

ans=0
if 2*N<=M:
    ans=N+(M-2*N)//4
else:
    b=M//2
    ans=b
print(ans)

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

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

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

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

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

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

if M > 0:
  cnt += M // 4

print(cnt)

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

ans=min(N,M//2)
M-=ans*2
M=max(M,0)
ans+=M//4
print(ans)

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

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

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

cnt=0

if m-2*n>=0:
  m=m-2*n
  cnt+=n
  num=m//4
  cnt+=num
else:
  num=m//2
  n=n-num
  if n>=0:
    cnt+=num

print(cnt)

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

if c//2 - s > 0:
    ans = s + (c - 2*s)//4
else:
    ans = c//2
print(ans)

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

ans = int(min(2*N,M)/2)
if M-2*ans>0:
    ans += int((M-2*ans)/4)
print(ans)

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

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

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

Solution (Python):
import sys

N, M = map(int, sys.stdin.readline().split())

ans = 0
first = min(2 * N, M - M % 2)
M -= first
ans += first // 2
ans += M // 4
print(ans)

Solution (Python):
import math
n, m = map(int, input().split())
ans = 0

ans += min(n, m // 2)
m -= 2 * min(n, m // 2)

ans += math.floor(m / 4)

print(ans)

Solution (Python):
import math
n, m = map(int, input().split())
ans = 0

ans += min(n, m // 2)
m -= 2 * min(n, m // 2)









ans += math.floor(m / 4)



print(ans)

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

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

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

Solution (Python):
def LI():
    return list(map(int, input().split()))


S, c = LI()
if 2*S >= c:
    ans = c//2
else:
    ans = S
    c -= 2*S
    ans += c//4
print(ans)

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

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

Solution (Python):
N,M = map(int,input().split())
if M//2 <= N:
  ans = M//2
  print(ans);exit()
A = N*2+M
ans = A//4
print(ans)

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

if s*2 >= c:
    print(c//2)
else:
    ans = s
    rem = c-s*2
    ans += rem//4
    print(ans)

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

if m == 1:
  ans = 0
elif m > n:
  ans = (m - n*2) // 4 +n
elif n >= m:
  ans = m//2
  
print(ans)

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

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

if not s:
    ans += c//4

print(ans)

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

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

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

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

if s * 2 <= c:
    print((s*2+c)//4)
else:
    print(c // 2)

Solution (Python):
import sys
import heapq
from decimal import Decimal

input = sys.stdin.readline

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

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

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

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

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd


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

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

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

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

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

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

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

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

Solution (Python):
N,M=map(int,input().split())
if N>M//2:
    ans=M//2
    N-=ans
    if M%2==0:
        M=0
    else:
        M=1
else:
    ans=N
    M-=N*2
    N=0
    if M>3:
        X=M//4
        M-=X*4
        ans+=X
while True:
    if M<2:
        break
    if N==0:
        if M<4:
            break
    if N>0:
        N-=1
        M-=2
        ans+=1
    elif M>3:
        M-=2
        ans+=1
print(ans)

Solution (Python):
def INT():
    return int(input())

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

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

N, M = MI()

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

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

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	
	S_num, c_num = tin()
	
	if c_num <= S_num * 2:
		return c_num // 2
	
	c_num -= S_num*2
	return S_num + (c_num // 4)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
'''
Created on 2020/08/28

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,M=map(int,pin().split())
  if 2*N>M:
    print(M//2)
  else:
    print(N+((M-2*N)//4))
  return 

main()

Solution (Python):
from sys import stdin

n, m = [int(x) for x in stdin.readline().split()]
yoj = m - 2*n
if yoj < 0: print(m//2)
else: print(n + (yoj // 4))

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

ans = 0

if M - (N*2) < 0:
    cpair = M // 2
    S_count = min(N,cpair)
    ans = ans + S_count
    print(ans)
    sys.exit()
    


restM = M - (N*2)

ans = ans + N


ans = ans + restM//4

print(ans)

Solution (Python):
S, c = map(int, input().split())
if 2 * S > c:
    print(c // 2)
    exit()
ans = S
rest_c = c - 2 * S
ans += rest_c // 4
print(ans)

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n,m = LI()

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

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(2*N,M)+M)//4)

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

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

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

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

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

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

Solution (Python):

S, C = map(int, input().split())
ret = 0
if 2 * S <= C:
    ret += S
    C -= 2 * S
    S = 0
else:
    ret += C // 2
    S -= C // 2
    C %= 2

ret += C // 4
print(ret)

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

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

ans=0

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

Solution (Python):
N,M=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())
ans = 0

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

print(ans)

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

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

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

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

Solution (Python):
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, m = inintm()

ans = 0

if m - n*2 >= 0:
    ans += n
    m -= n*2
    ans += m//4
    print(ans)
    exit()
else:
    if m % 2 == 0:
        print(m//2)
        exit()
    else:
        print((m-1)//2)
        exit()

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

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

Solution (Python):
import sys
input = sys.stdin.buffer.readline




def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))


import bisect

def main():
	s,c=MI()

	ans=min(s,c//2)

	c-=s*2

	if c>0:
		ans+=c//4

	print(ans)





if __name__ == "__main__":
	main()

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

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

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

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

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

Solution (Python):
def solve():
  N, M = map(int, input().split())
  if M<=2*N:
    ans = M//2
  else:
    ans = N+(M-2*N)//4
  return ans
print(solve())

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

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

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re












import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
s,c = readInts()
need = s*2
if need > c:
    ans = c//2
    c = 0
else:
    ans = s
    c -= ans*2
ans += c//4
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

 
 
def main():
    n, m = [int(i) for i in input().strip().split()]
    s1 = min(n, m // 2)
    s2 = (m - s1 * 2) // 4
    print(s1 + s2)
 
 
if __name__ == "__main__":
    main()

Solution (Python):

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

if N*2 > M:
    print(M // 2)
    exit()

M -= (N * 2)

print(N + M // 4)

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



scc = 0
if s*2 <= c:
    scc += s
    c -= s*2
    s = 0
    scc += c//4
else:
    print(c//2)
    exit()
print(scc)

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

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n, m = inl()
    if n * 2 >= m:
        return m // 2

    def check(x):
        y = x - n
        mm = m - y * 2
        return mm >= x * 2

    ok = n
    ng = n + m
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok


print(solve())

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

p = min(S,C//2)
C -= p*2
ans = p + C//4
print(ans)

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

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

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

ans = min(N,M//2)
if N < M//2:
    M -= 2*N
    ans += M//4

print(ans)

Solution (Python):
S, C = [int(i) for i in input().split()]
if S*2 <= C:
    setn = S
    C -= S*2
    setn += C//4
else:
    setn = C//2
print(setn)

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

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

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

Solution (Python):
n,m = map(int,input().split())
ans = 0
x = min(n,m//2)
n -= x
m -= x*2
ans += x

print(ans+m//4)

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

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

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

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

else:
  print(M//2)

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

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

Solution (Python):
N,M = map(int,input().split())
if N > M//2:
    print(M//2)
    exit()
ans = (M//2 + N)//2
print(ans)

Solution (Python):
S, C = [ int(v) for v in input().split(" ") ]

total = 0
C_2 = C - (2 * S)

if C_2 < 0:
  print(int(C/2))
else:
  print(S + int(C_2 / 4))

Solution (Python):
import sys
input = sys.stdin.readline



def main():
    n, m = [int(i) for i in input().strip().split()]
    s1 = min(n, m // 2)
    s2 = (m - s1 * 2) // 4
    print(s1 + s2)


if __name__ == "__main__":
    main()

Solution (Python):
n,M=map(int,input().split())
l,r,ans=0,10**18,-1
while(l<=r):
    m=(l+r)//2
    ns=max(0,m-n)
    uc=(2*ns+2*m)
    if(uc<=M):
        ans=m
        l=m+1
    else:
        r=m-1
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 2 * n > m:
    print(m // 2)
else:
    print(n + (m - 2 * n) // 4)

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

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

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,m = lr()

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

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

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

K=0
X="+"
while X :
    X=min(N,M//2)
    K+=X
    N-=X
    M-=2*X

    Y=M//4
    N+=Y
    M-=2*Y

print(K)

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

Solution (Python):
n, m = map(int, input().split())
if n*2 < m:
    while n*2 <= m:
        if m - 2*n > 100000:
            m -= 60000
            n += 30000
        elif m - 2*n > 10000:
            m -= 6000
            n += 3000
        else:
            m -= 2
            n += 1
    print(n - 1)
else:
    print(m//2)

Solution (Python):
n, m = map(int, input().split())
if n*2 < m:
    while n*2 <= m:
        if m-n - n > 10000:
            m -= 6000
            n += 3000
        else:
            m -= 2
            n += 1
    print(n - 1)
else:
    print(m//2)

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

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

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

print(res)

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

if c//2 <= s:
    print(c//2)
else:
    ans = s
    ans += (c-2*s)//4
    print(ans)

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd





def solve():
    s, c = [int(x) for x in input().split()]
    if s > c // 2:
        print(c // 2)
    else:
        c -= 2 * s
        print(s + c // 4)
        


t = 1

for case in range(1,t+1):
    ans = solve()


"""

abc

"""

Solution (Python):
import sys
input = sys.stdin.readline

N,M=list(map(int,input().split()))

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

Solution (Python):
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,m = readInts()

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

print(ans)

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

Solution (Python):






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





s1 = min(N, M//2)
s2 = (M-s1*2)//4
print(s1+s2)

Solution (Python):
import sys
input = sys.stdin.readline


def read():
    N, M = map(int, input().strip().split())
    return N, M


def solve(N, M):
    nScc = min(N, M//2)
    N -= nScc
    M -= nScc * 2
    if M >= 4:
        nScc += M // 4
    return nScc


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):
def resolve():
    '''
    code here
    '''
    num_S, num_c  = [int(item) for item in input().split()]

    delta = num_c - num_S *2
    scc = 0
    if num_S != 0:
        if num_c // 2 <= num_S :
            scc = num_c//2
        else:
            scc = num_S
            scc += delta//4
    else:
        scc = num_c//4

    print(scc)

if __name__ == "__main__":
    resolve()

Solution (Python):

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

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

res = 0
res += min(N, M//2)
M -= N*2

res += max(M//4, 0)

print(res)

Solution (Python):
s,c = map(int,input().split())
res = 0
if s*2 <= c:
    res = s
    c -= s*2
    s = 0
else:
    res += c//2
    c = 0

if c:
    res += c//4
print(res)

Solution (Python):
n, m = map(int, open(0).read().split())

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

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline

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

if m >= n*2:
    ans = n
    m -= n*2
    n = 0
else:
    ans = m//2
    m = 0


if m:
    ans += m//4

print(ans)

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, m = LI()
ans = 0
if 2 * n <= m:
    
    ans += n
    m -= 2 * n
    n -= n
    
    if m >= 4:
        ans += m // 4
        m -= 4 * (m // 4)
    print(ans)

else:
    ans += m // 2
    n -= m // 2
    m -= 2 * (m // 2)
    print(ans)

Solution (Python):
import bisect,copy,heapq,itertools,math,string
from collections import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
print(min((2*n+m)//4,m//2))

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

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

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

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

Solution (Python):

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


if M < 2 * N:
    
    print(M // 2)


else:
    ans_1 = N
    M = M - 2 * N
    ans_2 = M // 4
    print(ans_1 + ans_2)

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

if M <= N * 2:
    print(M // 2)
    exit()

ans = N
M -= N*2

ans += M//4

print(ans)

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

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

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

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

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

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


print(ans)

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

Solution (Python):
[N,M]=[int(i) for i in input().split()]
if M//2<N:print(M//2)
else:print((M-(N*2))//4+N)

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

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

print(ans)

Solution (Python):
N, M = map(int, input().split())
if M < 2 * N:
  ans = M // 2
else:
  ans = (N + M // 2) // 2
print(ans)

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

if (2 * N > M):
    print(M // 2)
    exit()
elif (2 * N == M):
    print(M // 2)
    exit()
else:
    
    
    
    if (M % 2 == 0):
        k = M // 2 - N
    else:
        k = (M // 2) - N - 1
    print(min(((M - k) // 2), (N + (k // 2))))

Solution (Python):
def main():
    N,M = [int(x) for x in input().split()]
    Scc_cnt = 0
    if N >= 0 and M >= 2:
        if M >= N*2:
            Scc_cnt += N + (M-N*2)//4
        else:
            Scc_cnt += M//2
    print(Scc_cnt)

if __name__ == '__main__':
    main()

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

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

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

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

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

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



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

ans += c//4

print(ans)

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

Solution (Python):






from collections import deque,defaultdict











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
cnt = 0
if m //2 >= n:
    cnt += n
    m -= n * 2
else:
    cnt += m//2
    n -= m//2
    m -= m
cnt += m//4 
print(cnt)

Solution (Python):

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

def main(N, M):

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

if __name__ == '__main__':
    main(N, M)

Solution (Python):
def main():
    N, M = map(int, input().split())
    M2 = M//2
    if M2 <= N:
        print(M2)
        return
    m = M - N*2
    ans = N + m//4
    print(ans)

if __name__ == "__main__":
    main()

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

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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = map(int, input().split())
def sub(x):
    if n>=x:
        return m>=2*x
    else:
        return max(0, (m-2*x)//2) + n >= x
l = 0
r = n+m+1
while l<r-1:
    mm = (l+r)//2
    if sub(mm):
        l = mm
    else:
        r = mm
print(l)

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

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

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

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

print(res)