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: Runtime Error

Solution code:
n = int(input())
ans = 1
dummy1,dummy2 = divmod(n,2)
for i in range(1,dummy1+1):
  ans *= i
  ans *= n+1-i
  ans = ans % (10**9+7)
if dummy2 == 1:
  ans = ((dummy1+1)*ans % (10**9+7))
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
count=0
if N>=1 and M>=2:
    a=M//2
    if N>=a:
        M=M-2*a
        answer=a
    else:
        M=M-2*N
        answer=N
if M>=4:
    kotae=M//4
print(answer+kotae)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

    if s>=c/2:
        print(str(math.floor(c/2)))
    else:
        zanc = c - (s * 2)
        print(str(s + math.floor(zanc/4)))
        
resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

while(True):
    if(c > 2):
        if(s > 0):
            s = s - 1
            c = c - 2
        else:
            c = c - 3
        cnt = cnt + 1
    else:
        break

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s,c = map(int,input().split(" "))
     
counter = 0
if s >= 1 and c >= 2:
    temp = min(s,c//2)
    s -= temp
    c -= temp * 2
    counter += temp
    #print("s:",s)
    #print("c:",c)
    #print("counter:",counter)
    
if s<=0 and c >= 4:
    temp = c // 4
    counter += temp
    c -= temp
    #print("s:",s)
    #print("c:",c)
    #print("counter:",counter)
      
print(temp)

Submission status: Runtime Error

Solution code:
s,c = map(int,input().split(" "))
     
counter = 0
if s >= 1 and c >= 2:
    temp = min(s,c//2)
    s -= temp
    c -= temp * 2
    counter += temp
    print("s:",s)
    print("c:",c)
    print("counter:",counter)
    
if s<=0 and c >= 4:
    temp = c // 4
    counter += temp
    c -= temp
    print("s:",s)
    print("c:",c)
    print("counter:",counter)
      
print(temp)

Submission status: Runtime Error

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

counter = 0
if s >= 1 and c >= 2:
  temp = min(s,c//2)
  s -= temp
  c -= temp
  counter += temp

if s<=0 and c >= 4:
  temp = c // 4
  counter += temp
  c -= temp
  
print(temp)

Submission status: Runtime Error

Solution code:
n = int(input())
power = [1]

if n == 1:
    print(1)
    exit()

for i in range(2, n+1):
    power.append((i * power[-1]) % (10 ** 9 + 7))

print(power[-1])

Submission status: Runtime Error

Solution code:
List=[int(j) for j in input().split()]
a=List[1]
b=List[2]

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

Submission status: Runtime Error

Solution code:
List=input().split()
a=int(List[1])
b=int(List[2])

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

Submission status: Runtime Error

Solution code:
a,b=input().split()

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())


    c=b-2*a
    d=c//4
    print(a+d)

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())

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

Submission status: Runtime Error

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

for scc in range(M//2, -1, -1):
    excess_c = M - scc*2
    if excess_c//2 + N >= scc:
        print(scc)
        sys.exit(0)

print(0)

Submission status: Runtime Error

Solution code:
import sys

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

    if N >= M // 2:
        ans = M // 2
        S -= M // 2

        ans += S // 2

        return ans

    else:
        ans = N
        M -= 2 * N

        ans += M // 4

        return ans


if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
if 2 * N <= M:
    ans1 = N
    M -= ans1 * 2
# print(ans1)
# print(M)

ans2 = M // 4
# print(ans2)

print(ans1 + ans2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
ans = 0 
#S型をN個を使い切る
if 2*N <= M:
	M -= 2*N
ans +=  N

#C型で作る
ans += //4

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m = [int(x) for x in input().split()]
c = n if m - n >= 0 else pass

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if s<c/2:
    c_s = (c-2*s)//4
    sc = s
    print(c_s+sc)
else:
    sc = (min(s,c//2)
    print(sc)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
if s >= c//2:
    print(c//2)
else:
    print((2*s+c)//4)

Submission status: Runtime Error

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

counter = counter + m //4 
    
    
print(count)

Submission status: Runtime Error

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

def cul(s,c):
  if s >= c // 2:
    x = s
    c = c - s * 2, 0
    x += c//4
  else:
    x = c//2
  return x
print(cul(s,c))

Submission status: Runtime Error

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

tmp = m - (2 * n)
ans = 0
if tmp < 0:
        tmp = m - 2 * (n - tmp)
        if tmp >= 0:
                n -= n - tmp
                break

m = tmp

ans += n
ans += tmp / 4

print ans

Submission status: Runtime Error

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

tmp = m - (2 * n)
ans = 0
if tmp < 0:
        for i in range(n):
                tmp = m - 2 * (n - i)
                if tmp >= 0:
                        n -= i
                        break

m = tmp

ans += n
ans += tmp / 4

print ans

Submission status: Runtime Error

Solution code:
S,C=map(int,input().split())
if C<2*S:
  print(int(C/2))
else:
  if (C-2*S)%4==0:
    k=(C-2*S)/4
  else:
    k=int(1+(C-2*S)/4)
print(int((C-2*k)/2))

Submission status: Runtime Error

Solution code:
n,m = gets.chomp.split.map(&:to_i)
if n > m / 2
  p m / 2
else
  p (m+2*n) / 4
end

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
N,M = map(int,input().split())
count = 0
if N*2>M:
    count = math.floor(M/2)
else:
    temp=M-2*N
    ans = N+math.floor(temp/4)

print(ans)

Submission status: Runtime Error

Solution code:
import math
N,M = map(int,input().split())
count = 0
if N*2>M:
    count = math.floor(M/2)
else:
    temp=M-2*N
    ans = N+math.floor(temp/4)

print(ans)

Submission status: Runtime Error

Solution code:
s, c = [int(e) for e in input().split()]


def main(s, c):
    ret = 0
    for i in range(s):
        ret += 1
        c   -= 2
    ret += c // 4
    return ret


ans = main(n)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def sunuke_f3(n, m) :
    if n >= m :
        return(m//2)
    else :
        if 2*n < m :
            return(n + (m-2*n)//4)
        else :
            return(m//2)
sunuke_f3(N, M)

Submission status: Runtime Error

Solution code:


# if a > b return true
def compare(a, b): # a also b are both string
	l = max(len(a), len(b))
	a_ = a.rjust(l, '0')
	b_ = b.rjust(l, '0')
	return a_ > b_


def divide(num, den): # den is integer
	quo = ''; resi = 0
	digit = len(num) if int(num[0]) >= den else len(num)-1
	for i in range(len(num)):
		temp = (int(num[i])+resi*10)//den
#		print('temp', temp)
		resi = (int(num[i])+resi*10)%den
#		print('resi', resi)
		quo += str(temp) if temp != 0 else ''
	return quo.ljust(digit, '0')

def multi(a, n):
	s = ''; resi = 0
	for i in range(len(a))[::-1]:
		temp = (int(a[i])*n + resi)%10
#		print('temp', temp)
		resi = (int(a[i])*n + resi)//10
#		print('resi', resi)
		s = str(temp) + s
	return s


def plus(a, b):
	l = max(len(a), len(b))
	a_ = a.rjust(l, '0')
	b_ = b.rjust(l, '0')

	s = ''; resi = 0
	for i in range(l)[::-1]:
		temp = (int(a_[i]) + int(b_[i]) + resi)%10
#		print('temp', temp)
		resi = (int(a_[i]) + int(b_[i]) + resi)//10
#		print('resi', resi)
		s = str(temp) + s
	return s

# a is higher than b
def minus(a, b):
	l = max(len(a), len(b))
	a_ = a.rjust(l, '0')
	b_ = b.rjust(l, '0')

	s = ''; bollow = 0
	for i in range(l)[::-1]:
		temp = int(a_[i]) - int(b_[i]) - bollow
#		print('temp', temp)
		bollow = 0
		if temp >= 0:
			s = str(temp) + s
		else:
			bollow = 1
			s = str(temp + 10) + s
	return s

if compare(s, divide(c, 2)) or s == c:
	print(divide(c, 2))
else:
	print(plus(s, divide(minus(c, multi(s, 2)), 4)))

Submission status: Runtime Error

Solution code:
#include <stdio.h>
int main(void){
    long long int N, M;
    scanf("%lld %lld", &N, &M);
    long long int ans = (N+M/2)/2;
    printf("%lld\n", ans);
    return 0;
}

Submission status: Runtime Error

Solution code:
import math
Sc = input().split()
Scc = int(Sc[1])/4
math.floor(Scc)
for i in range(int(Sc[0])):
    if int(Sc[1])%4 == 2*int(Sc[0]):
        Scc+=1
math.floor(Scc)
print(Scc

Submission status: Runtime Error

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