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: Wrong Answer

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

res=-1
left=0
right=M
ans=0

while left < right:
	mid1 = (2*left + right)//3
	mid2 = (left + 2*right)//3
	m1=mid1//2
	m2=mid2//2
	curr1 = min(m1+N, M//2-m1)
	curr2 = min(m2+N, M//2-m2)
	ans=max(curr1,curr2)
	if curr1 < curr2:
		left=mid1
	elif curr1 > curr2:
		right=mid2
	else:
		res=curr1
		break

res=(ans if res == -1 else res)
print(res)

Submission status: Wrong Answer

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

res=-1
left=0
right=M

while left < right:
	mid1 = (2*left + right)//3
	mid2 = (left + 2*right)//3
	m1=mid1//2
	m2=mid2//2
	curr1 = min(m1+N, M//2-m1)
	curr2 = min(m2+N, M//2-m2)
	if curr1 < curr2:
		left=mid1
	elif curr1 > curr2:
		right=mid2
	else:
		res=mid1
		break

res=(left if res == -1 else res)
print(res)

Submission status: Wrong Answer

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

res=-1
left=0
right=M

while left < right:
	mid1 = (2*left + right)//3
	mid2 = (left + 2*right)//3
	m1=mid1//2
	m2=mid2//2
	curr1 = min(m1+N, M//2-m1)
	curr2 = min(m2+N, M//2-m2)
	if curr1 < curr2:
		left=mid1
	elif curr1 > curr2:
		right=mid2
	else:
		res=curr1
		break

res=(left if res == -1 else res)
print(res)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, raw_input().split())
print max((n + m / 2) / 2, min(n, m / 2))

Submission status: Wrong Answer

Solution code:
n, m = map(int, raw_input().split())
print (n + m / 2) / 2

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
two_input = input().split()

s = int(two_input[0])
c = int(two_input[1])

while (s + 1) * 2 <= c - 2:
    s += 1
    c -= 2

print(s)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n,m = map(int, raw_input().split())

l = (n*2+m)/4

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

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n,m = map(int, raw_input().split())

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

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n,m=map(int, input().split())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    s, c = map(int, input.row().split())
    count = 0
    for i in range(s):
        if(c >= 2):
            count += 1
            c -= 2
        else:
            break
    for i in range(c):
        if(c >= 4):
            count += 1
            c -= 4
        else:
            break
    print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3                                                                                 
                                                                                                       
input_list = input().split(" ")                                                                        
N = int(input_list[0])                                                                                 
M = int(input_list[1])                                                                                 
if 2 * M <=  N:                                                                                        
    print(N)                                                                                           
else:                                                                                                  
    print(N + (M - 2*N) // 4)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

input_list = input().split(" ")
N = int(input_list[0])
M = int(input_list[1])
if 2 * M <=  N:
    print(N // 2)
else:
    print(N + (M - 2*N) // 4)

Submission status: Wrong Answer

Solution code:
#============

#============
def myfun():
    myInput = input()
    myInput = [int(x) for x in myInput.split(' ')]
    extraC = myInput[1]-myInput[0]*2
    if extraC>=0:
        print(myInput[0]+int(extraC/4))
    else:
        print(int(myInput[1]/2)+int(extraC*-1/4))
#============
if __name__=='__main__':
    myfun()

Submission status: Wrong Answer

Solution code:
#============

#============

#============
if __name__=='__main__':
    myInput = input()
    myInput = [int(x) for x in myInput.split(' ')]
    extraC = myInput[1]-myInput[0]*2
    if extraC>=0:
        print(myInput[0]+int(extraC/4))
    else:
        print(int((myInput[0]-int(myInput[1]/2))/2)+int(myInput[1]/2))

Submission status: Wrong Answer

Solution code:
#============

#============

#============
if __name__=='__main__':
    myInput = input()
    myInput = [int(x) for x in myInput.split(' ')]
    extraC = myInput[1]-myInput[0]*2
    if extraC>=0:
        print(myInput[0]+int(extraC/4))
    else:
        print(myInput[0]+int(extraC/2))

Submission status: Wrong Answer

Solution code:
#============

#============

#============
if __name__=='__main__':
    myInput = input()
    myInput = [int(x) for x in myInput.split(' ')]
    needC = myInput[0]*2
    diff = needC - myInput[1]
    if diff<=0:
        diff = diff*-1
        extra = int(diff/4)
        print(myInput[0]+extra)
    else:
        if myInput[1]%2==1:
            print(int((myInput[1]-1)/2))
        else:
            print(myInput[1]/2)

Submission status: Wrong Answer

Solution code:
#ARC069A

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
#N=12345
#M=67890100
scc = 0

di = 10000
if(M>2*di and N>di):
    nr,nyo = divmod(N,di)
    mr,myo = divmod(M,2*di)
    
    if nr>mr:
        scc += mr*di
        N = di*(nr-mr)+nyo
        M = myo
    elif mr>nr:
        scc += nr*di
        M = 2*di*(mr-nr)+myo
        N = nyo
    elif nr==mr:
        scc += nr
        N,M = nyo,myo

while(N>0):
    N -= 1
    M -= 2
    if M<0:
        break
    if N==0 and M>=4:
        M-=2
        N+=1
    scc += 1
print(scc)

Submission status: Wrong Answer

Solution code:
# coding=utf-8
s,c = map(int, input().split());

c = c + (s * 2);

print(int(c // 4));

Submission status: Wrong Answer

Solution code:
# coding=utf-8
s,c = map(int, input().split());

c = c + (s * 2);

print(int(c / 4));

Submission status: Wrong Answer

Solution code:
N=12345
M=678901
scc = 0

while(N>0):
    N -= 1
    M -= 2
    if M<0:
        break
    if N==0 and M>=4:
        M-=2
        N+=1
    scc += 1
print(scc)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#print(inp)
s = inp[0]
c = inp[1]

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


print (ans)

Submission status: Wrong Answer

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

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

print(a)

Submission status: Wrong Answer

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

#print(inp)
s = inp[0]
c = inp[1]

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


print (ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
x,y =map(int,stdin.readline().split())
z = x*2 + y
print z/4

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# Copyright (C) 2017 Sayutin Dmitry.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 3
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.

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

    t0 = (c - 2 * s) // 4
    ans = 0

    for t in range(t0 - 2, t0 + 3):
        ans = max(ans, min((c - 2 * t) // 2, s + t))
    print(ans)

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = S
if S < C / 2:
    a += (C - 2*S) // 4

print(a)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N, M = map(int,input().split())

ans = min(M // 2, N)

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
ans=0
while True:
    if M>=2 and N>=1:
        ans+=1
        N-=1
        M-=2
    elif M>=4:
        ans+=1
        M-=4
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

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

while True:
  if N >= 1:
    N -= 1
  elif M >= 2:
    M -= 2
  else:
    break

  if M >= 2:
    cnt += 1
    M -= 2
  else:
    break

print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
while True:
  if N >= 1:
    N -= 1
  elif M >= 2:
    M -= 2
  else:
    break

  if M >= 2:
    cnt += 1
    M -= 2
  else:
    break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#45 C - Scc Puzzle
N,M = map(int,input().split())
if M//N < 2:
    print(M//2)
else:
    for i in range(M//2+1):
        if M//N < 2:
            break   
        M -= 2
        N += 1
    print(N-1)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,M = [int(x) for x in input().split()]
    Scc_cnt = 0
    while N >= 0 and M >= 2:
        if N >= 1 and M >= 2:
            N -= 1
            M -= 2
            Scc_cnt += 1
        if N == 0 and M >= 4:
            M -= 4
            Scc_cnt += 1
        if N == 0 and M <= 3:
            break
    print(Scc_cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

cnt=0
while s>0 and c>1:
    s-=1
    c-=2
    cnt+=1

if c<2:
    print(cnt)
    
else:
    while c>3:
        c-=4
        cnt+=1
    print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
for _ in range(n):
    if m >= 2:
        m -= 2
        cnt += 1
for _ in range(m // 4):
    if m >= 4:
        m -= 4
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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

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

print(n-1)

Submission status: Time Limit Exceeded

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()
s_default = N
s_plus = M // 2

# now_make = min(s_default, M//2)
# print(now_make)

ans = 0
for n in range(M//2 + 1):
    A, B = N + n, M - 2 * n
    mi = min(A, B//2)
    ans = max(mi, ans)
print(ans)

Submission status: Time Limit Exceeded

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

if m <= 2*n:
    print(m//2)
elif 2*n < m:
    while 2*n <= m:
        m -= 2
        n += 1
    # print("m: "+ str(m))
    print(n-1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

M = M - 1 if M%2==1 else M
mx = 0
for i in range(M//2):
    mx = max(min(N+i, (M-2*i)//2), mx)

print(mx)

Submission status: Time Limit Exceeded

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

while True:
  if 2*n<m:
    n += 1
    m -= 2
  else:
    if n*2 == m:
      print(n)
      break
    elif n*2>m:
      print(m//2)
      break

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
cnt = 0
for i in range(n):
  if m < 2: break
  cnt += 1
  n -= 1
  m -= 2
print(cnt+m//4)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
if n==m//2:
  print(m//2)
  exit()
if n>m//2:
  print(m//2)
  exit()
while n<m//2:
  n+=1
  m-=2
print(m//2)

Submission status: Time Limit Exceeded

Solution code:
S,C=map(int,input().split())
#start=time.time()
scc=0
count=0

while (S>0 or C>=4): #and count<max(S,C*44301):
    if S>0 and C>=2:
        S-=1
        C-=2
        scc+=1
        
        count+=1
        #print(count)
        
    elif S<=0 and C>=4:
        C-=4
        scc+=1
        
        count+=1
        #print(count)
    else:
        count+=1
        #print(count)
    
print(scc)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
ans=0
for i in range(n):
    if m>=2:
        m-=2
        ans+=1
    else:
        break

while m>=4:
    ans+=1
    m-=4
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while M != 0:
    if N != 0 and M >= 2:
        N -= 1
        M -= 2
        ans += 1
    elif N == 0 and M >= 3:
        N += 1
        M -= 2
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ans = 0
for i in range(n):
    if m > 2:
        m -= 2
        ans += 1
    else:
        break
ans += (m//4)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections
import math
from collections import Counter
from collections import deque


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

scc = 0
n = N
m = M

while (n >= 1 and m >= 2):
    n -= 1
    m -= 2
    scc += 1
if m >= 4:
    scc += (m // 4)

print(scc)

sys.exit(0)

Submission status: Time Limit Exceeded

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

scc = 0

while(N>0):
    N -= 1
    M -= 2
    if M<0:
        break
    if N==0 and M>=4:
        M-=2
        N+=1
    scc += 1
print(scc)

Submission status: Time Limit Exceeded

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

#print(inp)
s = inp[0]
c = inp[1]

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


print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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 - n*2
    ans += m//4
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m =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())

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)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans += math.floor(m / 4)



print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if not s:
    ans += c//4

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,m=map(int,input().split())
if n>=m//2:
    print(m//2)
else:
    ans=n+(m-2*n)//4
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
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))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
if M//N < 2:
    print(M//2)
else:
    # 交換できる回数の最大値は M - 2x = 2*(N + x) より求めた
    x = (M-2*N)//4
    print(N+x)

Submission status: Accepted

Solution code:
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():
	#a = int(input())
	S_num, c_num = tin()
	#s = input()
	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
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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