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



Sample input:
1 6


Sample output:
2

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

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()))
# rstrip().decode()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n >= m//2:
  # cの数が律速
  print(m//2)
else:
  print(n+(m-n*2)//4)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
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)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)
 
 
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()

Submission status: Accepted

Solution code:

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

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

M -= (N * 2)

print(N + M // 4)

Submission status: Accepted

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

# c*2 = s -> scc

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans+m//4)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
cnt = 0
#cが余る（Sが使い切れる）とき
if 2*N <= M:
  cnt += N
  M -= 2*N
  cnt += M//4
  print(cnt)
#cが足りない（Sが余る）とき
else:
  print(M//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
if 2 * n > m:
    print(m // 2)
else:
    print(n + (m - 2 * n) // 4)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
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


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


# n*(n-1)*...*(l+1)*l
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

# Union Find
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


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
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

abc

"""

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[22]:


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


# In[23]:


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


# In[ ]:

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
#ARC069-C
n,m = map(int,input().split())
if n*2 <= m:#cのほうが多いとき
    print((n*2 + m)//4)
else:
    print(m//2)

Submission status: Accepted

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

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

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

print(res)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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

#print(ans,n,m)
if m:
    ans += m//4

print(ans)

Submission status: Accepted

Solution code:
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:
    # Sを全部使う
    ans += n
    m -= 2 * n
    n -= n
    # c のあまりで作る
    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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# NはSの個数、MはCの個数
N, M = map(int, input().split())

# 既存のSを消費しきれない場合
if M < 2 * N:
    # Cの個数のみでSccの数が決まる
    print(M // 2)

# 既存のSを消費し切れる場合
else:
    ans_1 = N
    M = M - 2 * N
    ans_2 = M // 4
    print(ans_1 + ans_2)

Submission status: Accepted

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

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

ans = N
M -= N*2

ans += M//4

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
if s*2 <= c:
    ans += s
    c -= s*2 # sと組んだ後の残り
    ans += c // 4
else: # sが余るパターン
    ans += c // 2


print(ans)

Submission status: Accepted

Solution code:
[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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

if (2 * N > M):
    print(M // 2)
    exit()
elif (2 * N == M):
    print(M // 2)
    exit()
else:
    # 2 * N< M のときはMに余裕があるときはcを2つ使ってSを作成する
    # Mこのうちk個使ってSを作成
    # Mが奇数or偶数で分ける
    if (M % 2 == 0):
        k = M // 2 - N
    else:
        k = (M // 2) - N - 1
    print(min(((M - k) // 2), (N + (k // 2))))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
s,c = list(map(int, input().split()))
# 今あるSで出来る限りSCCを作る
# 余ったC（4個消費）でできる限りSCCを作る

ans = 0
if c >= 2*s:
    # Cの在庫に余力がある
    ans += s
    c -= 2*s
else:
    ans += c//2
    c = 0

ans += c//4

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
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 # if のとき
print(cnt)

Submission status: Accepted

Solution code:

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

def main(N, M):

    if N <= M // 2: # Sが足りない
        print(int(N + (M - (N*2))//4))
    else:# cが足りない
        print(int(M//2))

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    a = min(N, M // 2)
    M -= 2 * a
    b = M // 4
    ans = a + b
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans=0

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

Submission status: Accepted

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

cnt=0
p=min(s,c//2)
s-=p
c-=2*p
cnt+=p
q=0
if c<2:
    print(cnt)

else:
    q=c//4
    cnt+=q
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def solve(N,M):
  # 今あるもの
  if M < N * 2:
    return M // 2
  
  M -= N * 2
  
  ans = N + (M // 4)
  return ans

print(solve(N,M))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


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

Submission status: Accepted

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

ans = 0

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

ans += N
M -= N*2

ans += M//4

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
x = max(0, (M-2*N) // 4)
r = min(10, M//2)
for i in range(max(0, x-r), x+r):
    tmp = min(N+i, (M-2*i)//2)
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())

    ans = 0

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

    if N == 0:
        ans += M // 4

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve():
  n, m = map(int, input().split())
  if m//2 <= n:
    print(m//2)
  else:
    ans = 0
    ans += n
    m = m-n*2
    ans += m//4
    print(ans)
  return 0
 
if __name__ == "__main__":
  solve()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if n > (m+n)/3:
    print(m//2)
    exit()

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

Submission status: Accepted

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

if n > (m+n)/3:
    print(m//2)
    exit()
if m > 10000000000:
    print(m//4)
    exit()

while n <= (n+m)/3:
    n += 1
    m -= 2

print(n-1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
cnt_s=n
cnt_c=m
ans=0
if cnt_s>cnt_c:
  ans=cnt_c//2
  print(ans)
elif cnt_s<=cnt_c:
  ans+=min(n,cnt_c//2)
  cnt_c-=2*min(n,cnt_c//2)
  ans+=cnt_c//4
  print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()

if 2*n>=m:
    print(m//2)
    exit()
print(n+math.ceil((m-2*n)//4))

Submission status: Accepted

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

if m < 2:
    print(0)
    exit()

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

ans += m // 4

print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

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