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 sys
import math

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

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

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

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

Solution (Python):

"""
Created on Wed Sep 30 00:56:12 2020

@author: liang
"""

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

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

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

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

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

if m >= 2 and n > 0:
  ans += min(n, m // 2)
  m -= 2*ans

if m > 0:
  ans += m // 4
print(ans)

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

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

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

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    N,M = i_map()
    if M <= 2*N:
        print(M//2)
        exit()

    print(N + (M-2*N)//4)

if __name__=="__main__":
    main()

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

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

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

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

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

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

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

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

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

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 2*n>=m:
    print(m//2)
else:
    x=(m-2*n)//4
    ans=min(n+x,(m-2*x)//2)
    x+=1
    anser=min(n+x,(m-2*x)//2)
    print(max(ans,anser))

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

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

n = N
m = M // 2

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

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

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

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

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array





sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()

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


if __name__ == '__main__':
    main()

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

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

        if (m - 2 * n) % 4 == 0:
            tmp = (m - 2 * n) // 4
        else:
            tmp = (m - 2 * n) // 4 + 1

        ans += (m - 2 * tmp) // 2

    else:
        ans = m // 2

    print(ans)


if __name__ == '__main__':
    main()

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

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

cnt += c//4
print(cnt)

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

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

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

pieces = min(n, m//2)
if pieces == n:
    pieces += (m-2*n)//4
print(pieces)

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


if __name__ == '__main__':
    main()

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

l = 0
r = 10**12+1

while r-l>1:
    s = (r+l)//2
    c = 2*s
    t = s

    S,C = N,M
    s-=S
    if s > 0:
        C-=2*s
    if C < c:
        r = t
    else:
        l = t
    
print(l)

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

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

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):
n, m = [int(i) for i in input().split()]

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

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

a1 = min(N,M//2)
a2 = 0
if M//2 > N:
  a2 = (M - N*2)//4
  
a3 = a1+a2
print(a3)

Solution (Python):




import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1 6"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """12345 678901"""
        output = """175897"""
        self.assertIO(input, output)


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

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


if __name__ == "__main__":
    
    resolve()

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

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

print(ans)

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

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

Solution (Python):

def main():
    n, m = map(int, input().split())


    if m-n*2 >= 0:
        print(n+((m-n*2)//4))
    else:
        print(m//2)
  
        
if __name__ == '__main__':
    main()

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

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

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

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

if s == c:
    print(s)
elif s > c:
    print(c)
elif s < c:
    t = c - s
    print(s + t//2)

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

Solution (Python):

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




if __name__ == "__main__":
    main()

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

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

Solution (Python):


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

cc = m//2
ans = min(n, cc) 
res = cc-min(n, cc) 
if res > 0:
    ans += res//2
print(ans)

Solution (Python):


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

ans = 0 
cc = m//2
if n >= cc: 
    ans = cc
else:
    ans = (n+cc)//2
print(ans)

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

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

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

Solution (Python):
a,b=map(int, input().split())

if a*2 <= b:
    c = (b-a*2)//4
    print(a+c)
if a*2 > b:
    print(b//2)

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, M = map(int, input().split())
    if M <= 2 * N:
        print(M // 2)
    else:
        k = (M - 2 * N) // 4
        ans= 0
        for i in range(max(0, k - 4), min(M // 2, k + 4)):
            if (M - 2 * i) <= 2 * (N + i):
                ans = max(ans, (M - 2 * i) // 2)
            else:
                ans = max(ans, N + i)
        print(ans)
    
    

if __name__ == "__main__":
    main()

Solution (Python):
n, m = map(int, raw_input().split())
def f(n,m): 
	if n == 0: return m /4
	x = min(n, m/2)
	return x + (f(n - x,m - 2*x) if x else 0)

print f(n,m)

Solution (Python):
n, m = map(int, raw_input().split())
def f(n,m): 
	if n == 0:
		return m /4


	x = min(n, m/2)
	if x:
		return x + f(n - x,m - 2*x)
	else:
		return 0
print f(n,m)

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

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

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

Solution (Python):
import math
N,M = (int(T) for T in input().split())
if M-2*N>0:
    Convert = int(math.floor((M-2*N)/4))
    N += Convert
    M -= 2*Convert
    print(N)
else:
    print(M//2)

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

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

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

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

Solution (Python):
n,m=map(int,input().split())
if m<2:
    print(0)
    exit()
if n>m//2:
    print(m//2)
    exit()
c=n%(m//2)
d=m-2*c
c+=d//4
print(c)

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

if 2 * S >= C:
  print(min([S, int(C/2)]))
else:
  print(S + int((C - 2 * S) / 4))

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

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

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

Solution (Python):
n, m = map(int, input().split())
m = (m//2) * 2
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:
	remaining = m- n*2
	ans = remaining//4 + n
	print(ans)

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

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

if (2 * s == c):
    ans = s

elif (2 * s > c):
    ans = c // 2

else:
    ans = s
    tar = c - 2 * s

    ans += tar // 4


print(int(ans))

Solution (Python):
def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

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

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

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

if N >= 2*M:
  print(M//2)
  exit()
  
def f(x):
  return max(min(N+x, (M-2*x)//2),0)
  
delta = [-3,-2,-1,0,1,2,3]
x = (M-2*N)//4

ans = 0
for i in range(7):
  x_ = max(0,x+delta[i])
  ans = max(ans,f(x_))

print(ans)

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

Solution (Python):
import sys
N,M = map(int,input().split())
if not ( 1 <= N <= 10**12 and 1 <= M <= 10**12 ): sys.exit()

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

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

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

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

ans = min(S, C // 2)
S -= ans
C -= ans * 2
if C >= 4:
    ans += C // 4
print(ans)

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

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())

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

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

Solution (Python):
n, m = list(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:
    print(M // 2)

else:
    m = M - N * 2
    s = m // 4
    print(N + s)

Solution (Python):
import sys
n,m = map(int,input().split())
if m < 2:
  print(0)
  sys.exit()
if(1 < m < n) or 2*n > m >= n:
  print(m//2)
  sys.exit()
m -= 2*n
print(n+(m//4))

Solution (Python):
import sys
n,m = map(int,input().split())
if m < 2:
  print(0)
  sys.exit()
if 1 < m < n:
  print(m//2)
  sys.exit()
if 2*n > m >= n:
  print(m//2)
  sys.exit()
m -= 2*n
print(n+(m//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):
import sys, math
from collections import defaultdict
from itertools import product
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

class Graph:
    

    
    no_labeling_num = -1

    class Vertex:
        

        def __init__(self, g, no, label):
            """

            :param g: グラフを表す。またVertexを所有するオブジェクトでもある
            :param no: 頂点にグラフのなかで一意に割り振られた識別用の番号
            :param label: 探索された順番を表す番号。ラベル。
            """
            self.no = no
            self.g = g
            self.label = label

        def __str__(self):
            """
            　
            """
            return "no:{0},label:{1}".format(self.no,self.label)

        def adjacentVs(self):
            """ selfと隣接している頂点のリストを返す

            :return:
            """
            result = []
            for c in range(self.g.order):
                if self.g.aDJM[self.no][c] == 1:
                    result.append((self.g.vs[c]))
            return result

        def back_to_previous(self):
            """ 前に探索した頂点を返す（厳密な表現ではない）
            詳細
            ・この頂点に隣接する頂点において、ラベル付けされていない（未探索）なものがないときに、
            次に探索する頂点を返す関数
            ・自身のラベル番号より小さい頂点の中で一番近いものを返す
            ・存在しないときは「None」を返す

            :return:
            """
            result = None
            vs = list(filter(lambda x: self.label > x.label, self.adjacentVs()))
            if vs != []:
                result = vs[0]
                key0 = self.label - result.label
                for v in vs:
                    key1 = self.label - v.label
                    if (key1 < key0):
                        key0 = key1
                        result = v

            return result

    def __init__(self, aDJM):
        """
        
        :param aDJM:隣接行列
        """
        self.aDJM = aDJM
        self.order = len(aDJM)
        self.vs = [Graph.Vertex(self, i, self.no_labeling_num) for i in range(self.order)]

    def no_labelingVs(self, vs):
        """ 渡された頂点リストにおいてlabelingされていない頂点のリストを返す

        :return:
        """
        result = []
        for v in vs:
            if v.label == self.no_labeling_num:
                result.append(v)
        return result

    def isconnected(self):
        """ このグラフが連結グラフであるかどうかを判定する
        
        :return:
        """
        label = 0
        v = self.vs[0]
        v.label = label
        
        if v.adjacentVs()==[]:
            v=None
        else:
            v = v.adjacentVs()[0]
            label += 1
            v.label = label
        while (v != None):  
            vs = self.no_labelingVs(v.adjacentVs())
            if vs == []:
                v = v.back_to_previous()
            else:
                v = vs[0]
                label += 1
                v.label = label

        return not(self.no_labeling_num in list(map(lambda x:x.label,self.vs)))


def main():
    N, M = mi()
    k = max((M//2-N)//2, 0)
    print(min(N+k, (M-2*k)//2))

if __name__ == '__main__':
    main()

Solution (Python):
import sys

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


def main():
    N, M = map(int, readline().split())

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

    print(ans)
    return


if __name__ == '__main__':
    main()

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 main():
    n, m = map(int, input().split())
    ans = 0
    if m >= 2*n:
        ans += n
        m -= 2*n
        n = 0
    else:
        ans += m // 2
        m -= ans * 2
    ans += m // 4
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys

N, M=map(int,input().split())
Mh=M//2

if N>Mh:
  print(Mh)
  sys.exit()
else:
  rem=M-2*N
  print(rem//4+N)

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

print(m)

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

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

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

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

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





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

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

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

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

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

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

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

print(ans)

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

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

ans = 0
if(M//2 >= N):
    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:
  print(m // 2)
  exit()
res = n
m -= (2 * n)
res += (m // 4)
print(res)

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

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

Solution (Python):
s, c = map(int, input().split())
ans = 0
ans += min(s,c//2)
res = c-min(s,c//2)*2
ans += res//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())
M//=2
print(min(M,(N+M)//2))

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

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

M-=2*N
ans+=M//4
print(ans)

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


if S*2 <= C:
    C = C - S*2
    ans += S
    ans += C // 4
else:
    ans += C // 2

print(int(ans))

Solution (Python):
import sys;input = lambda : sys.stdin.readline()
n,m = map(int,input().split())
if m-2*n>=0:
    print(n+(m-2*n)//4)
else:
    print(m//2)

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):
N,M = map(int,input().rstrip().split(" "))
k = N * 2 + M
print(min(k // 4,M//2))

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

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

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = map(int, readline().split())
    if 2 * n > m:
        ans = min(n, m // 2)
    else:
        c = m - 2 * n
        ans = n + c // 4

    print(ans)


if __name__ == '__main__':
    main()

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

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

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())

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

if m >= 4:
  ans += m // 4
  
print(ans)

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

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

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

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


else:
    count = m//2
print(count)

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

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

real = M - 2*N

if real < 0:
    ans = M // 2
elif real == 0:
    ans = real
else:
    a = real // 4
    ans = a + N

print(ans)

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

Solution (Python):


LI = lambda: list(map(int, input().split()))


N, M = LI()


def main():
    s = N
    c = M
    x = min(s, c // 2)
    c -= 2 * x
    y = c // 4
    ans = x + y
    print(ans)
    


if __name__ == "__main__":
    main()

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

x = min(N, M//2)

ans = x + (M - 2 * x) // 4
print(ans)

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


def calculate(n, m):

    if (m // 2) < n:
        print(m // 2)
        return

    res = ((m - n * 2) // 4) + n
    print(res)

calculate(N, M)

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

m //= 2

ans = 0

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

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

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


print(count)

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

x = M - 2 * N
if x > 0:
  N += x // 4

print(min(N, M // 2))

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

counter=0

raw_scc=min(N//1,M//2)
N-=raw_scc
M-=raw_scc*2
counter+=raw_scc


counter+=M//4
print(counter)

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

count = 0
if N >= M:
    count += M//2
elif N*2 <= M:
    count += N
    M = M - N*2
    count += M//4

print(count)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n,m=map(int,readline().split())

    ans=0
    t=min(n,m//2)
    ans+=t
    n-=t
    m-=2*t
    ans+=m//4
    print(ans)
    
if __name__=="__main__":
    main()

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

Solution (Python):
n,m=[int(x) for x in input().rstrip().split()]
ans=0
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())
print(min(M//2,(N*2+M)//4))

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:
    print(M//2)
else:
    tmp = M - N*2
    print(tmp//4+N)

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

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

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

print(res)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

 
N, M = MAP()

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

 
N, M = MAP()

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