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=int(input())

print(800*N-int(N/15)*200)
"""
"""
N=int(input())
S=input()

max_n=0
temp=0
for strng in S:
	if strng=="I":
		temp+=1
		if max_n<temp:
			max_n=temp
	else:
		temp-=1
print(max_n)
"""
"""
N=int(input())

Q=1000000007
p=1
for i in range(1,N+1):
	p*=i
	p=p%Q
print(p%Q)
"""

"""
n=int(input())
S=[input() for i in range(n)]
alphabet_dict={chr(97+i):100 for i in range(26)}
for s in S:
	temp={chr(97+i):0 for i in range(26)}
	for i in s:
		temp[i]+=1

	for key in alphabet_dict.keys():
		if alphabet_dict[key]>temp[key]:
			alphabet_dict[key]=temp[key]
result=""
for item in alphabet_dict.items():
	for i in range(item[1]):
		result+=item[0]
if result=="":
	print("\n")
else:
	print(result)
"""

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

if N>int(M/2):
	print(int(M/2))
else:
	hoge=int(M/2)-N
	print(N+int(hoge/2))

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def check(x):
  if M < 2*x:
    return False
  s = max(0, x-N)
  if M < 2*s + 2*x:
    return False
  return True

ok = 0
ng = 2**60
while ng - ok > 1:
  m = (ok + ng) // 2
  if check(m):
    ok = m
  else:
    ng = m
print(ok)

Submission status: Accepted

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

s = N
c = M

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

Submission status: Accepted

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

scc = min(n, m // 2)

n = n - scc
m = m - 2 * scc

if m >= 4:
    scc += (m // 4)

print(scc)
sys.exit(0)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = min(n, m // 2)
if n < m // 2:
    m = m - n * 2
    ans += m // 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:
f = lambda: list(map(int,input().split()))

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

Submission status: Accepted

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

x = min(N, M // 2)
y = (M - x * 2) // 4

result = x + y

print(result)

Submission status: Accepted

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

result = 0

x = min(N, M // 2)

result += x
M -= x * 2

y = M // 4

result += y
M -= y * 2

print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
line = input().split()
n = int(line[0])
m = int(line[1])

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

Submission status: Accepted

Solution code:
def count(s, c):
    if s >= c / 2:
        return int(c / 2)

    return s + int((c - 2 * s) / 4)


n, m = (int(i) for i in input().split())
print(count(n, m))

Submission status: Accepted

Solution code:
n, m = list(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())
if 2*s>=c:
    print(c//2)
else:
    print(s+(c-2*s)//4)

Submission status: Accepted

Solution code:
s,c = (int(i) for i in input().split())
S = s
C = int(c/2)

total = max(S,C) - abs(S-C)
total += int((C-total)/2)

print(total)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
ans = 0
if N >= M//2:
    ans += M//2
    N -= M//2
    M %= 2
else:
    ans += N
    M -= 2*N
    N = 0
ans += M//4
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:
N,M = map(int,input().split())

if M//2 < N:
    print(M//2)
else:
    print((N+(M//2))//2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s, c = map(int, input().split())
scc = min(s, c // 2)
cccc = (c - 2 * scc) // 4
print(scc + cccc)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

X = min(S, C / 2)

res = X

C -= 2 * X

res += C / 4

print res

Submission status: Accepted

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

if n >= m // 2:
    ans = m // 2

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

print(ans)

Submission status: Accepted

Solution code:
def scc_puzzle():
	n,m = map(int, raw_input().split(" "))
	max_ans = m/2
	if n>=max_ans:
		print max_ans
		return
	else:
		min_ans = n
		# binary search
		while min_ans+1<max_ans:
			current_ans = (max_ans+min_ans)/2
			if _check(current_ans, n ,m):
				max_ans = current_ans
			else:
				min_ans = current_ans
		# there is no opportunity for max_ans to be an ans
		# however, the min_ans could be, based on our _check() fun
		print min_ans
		return


def _check(ans, n, m):
	total_c = ans*2+(ans-n)*2
	if total_c>m:
		# current ans is too large
		return True
	else:
		return False


if __name__ == "__main__":
	scc_puzzle()

Submission status: Accepted

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

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

ans += M // 4

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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)
else:
    n=int(m/2)
print(n)

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:
x = map(int, raw_input().split(" "))
N = x[0]
M = x[1]

ans = 0

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


print ans

Submission status: Accepted

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

Submission status: Accepted

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

m /= 2

# convert x pairs of c to S
# new c = c - 2x
# new S = S + x
# amount = min(c/2 - x, S + x)

x = max((m - n) / 2, 0)
n += x
m -= x

print min(m, n)

Submission status: Accepted

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 = int(m/2)
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

n_s, n_c = map(int, input().split())
ans = 0

if n_c >= n_s * 2:
    ans += n_s
    rest_c = n_c - n_s * 2
    ans += rest_c // 4
else:
    ans += n_c // 2

print(ans)

Submission status: Accepted

Solution code:
nm = raw_input().split()
nm[1] = str(int(nm[1]) / 2)
scc1 = min(int(nm[0]),int(nm[1]))
nm[0] = str(int(nm[0]) - scc1)
nm[1] = str(int(nm[1]) - scc1)
scc2 = int(nm[1]) / 2
print scc1+scc2

Submission status: Accepted

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

Submission status: Accepted

Solution code:
i = input().split()
s, c = int(i[0]), int(i[1])
ans = int()
if(s * 2 < c):
    ans = int(s + (c - s * 2) / 4)
else:
    ans = int(c / 2)
print(str(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

# a = int(raw_input())
# # スペース区切りの整数の入力
# b, c = map(int, raw_input().split())
# # 文字列の入力
# s = raw_input()
# # 出力
# print str(a+b+c) + " " + s

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

res = min(N, M/2)

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

print res

Submission status: Accepted

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

l = (n*2+m)/4

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    arg = raw_input().split(" ")
    N = int(arg[0])
    M = int(arg[1])
    c_pattern = (M/2)

    if N < 1 or N > 10**12:
        return 0
    if M < 1 or M > 10**12:
        return 0

    if N == c_pattern:
        return N
    elif N < c_pattern:
        tmp = M - (N * 2)
        return N + (tmp / 4)
    elif N > c_pattern:
        return int(c_pattern)


print main()

Submission status: Accepted

Solution code:
s, c = map(int, raw_input().rstrip("\n").split(" "))

def calc_scc(s, c):
  answer = 0
  if (s * 2) >= c:
    answer = c / 2
  else:
    answer = s + ((  c - (s * 2) )  / 4 )
  return answer

print calc_scc(s, c)
#print calc_scc(12345, 678901), 175897

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = input().split()
N = int(l[0])
M = int(l[1])
if N*2>M:
	Max = M//2
elif N*2 == M:
	Max = N
else:
	N2 = N*2
	Max = (N2 +M)//4
print(Max)

Submission status: Accepted

Solution code:
import sys

cin = sys.stdin
# cin = open("in.txt", "r")

N, M = map(int, cin.readline().split())

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def readln():
    _res = list(map(int,str(input()).split(' ')))
    return _res
# n-c m-s
a = readln()
m,n = a[0],a[1]
k = m
if k * 2 > n: k = n // 2
n = n - k * 2
m = m - k
k = k + (n // 4)
print(k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

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

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

    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# cpding: utf-8
n_s, n_c = map(int, input().split())
scc_from_s = 0
scc_from_c = 0

if n_s >= 1 and n_c >=2:
	if n_s <= (n_c // 2):
		scc_from_s = n_s
		n_c -= (n_s * 2)
		scc_from_c = n_c // 4
	else:
		scc_from_s = (n_c // 2)
		scc_from_c = 0

scc_sum = scc_from_s + scc_from_c

print(scc_sum)

Submission status: Accepted

Solution code:
def solve(s, c):
    """rv = min(Sr, Cr//2), where
       Sr = S + a
       Cr = C - 2a  # a>=0, a is number of (2c->S) conversions
       thus
       rv = max(min(S + a, C//2 - a) for a in range(0, C//2))
       if a >=0, optimum is Sr == Cr//2, thus
                            S + a == Cr//2 - a
                            a = (C//2 - S) / 2
    """
    a = (c / 2 - s) / 2
    if a < 0:
        a = 0
    al = int(a)
    ar = int(a) + 1
    return max(min(s + a, c//2 - a) for a in (al, ar))


if __name__ == "__main__":
    import sys
    S, C = map(int, sys.stdin.readline().split())
    print(solve(S, C))


def test_solve():
    assert solve(1, 2) == 1
    assert solve(0, 4) == 1
    assert solve(0, 1) == 0


def test_atcode():
    assert solve(1, 6) == 2
    assert solve(12345, 678901) == 175897

Submission status: Accepted

Solution code:


s,c = map(int, input().split())

ns = max(0, (c - 2*s) // 4)
s += ns
c -= 2*ns

print(min(s,c//2))

Submission status: Accepted

Solution code:
def countScc(s, c):
    res = 0
    if(2*s <= c):
        res = s
        c = c - 2*s
        res = res + c / 4
    else:
        res = c / 2
    return res

try:
    while True:  
        s, c = raw_input().strip().upper().split()
        print countScc(int(s), int(c))
except EOFError:
    pass

Submission status: Accepted

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

    lo, hi = 0, int(1e18)
    
    while hi - lo > 1:
        mi = lo + (hi - lo) // 2

        free = c - 2 * mi
        if free < 0 or s + free // 2 < mi:
            hi = mi
        else:
            lo = mi
    print(lo)

main()

Submission status: Accepted

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
elif c//2<=s:
        ans += c//2
        s -= c//2
        c -= 0
else:
    if c>=4:
        ans += c//4



print (ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = (int(_) for _ in 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 2*N >= M:
  print(M//2)
else:
  result = N
  M -= 2*N
  result += M//4
  print(result)

Submission status: Accepted

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

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

    if 2*N >= M:
        ans = M // 2
    else:
        top = M // 2
        btm = 0

        while top - btm > 1:
            mid = (top + btm)//2
            if check(N + mid, M - 2*mid):
                btm = mid
            else:
                top = mid

        ans = N + btm

    print(ans)

def check(a, b):
    return 2*a <= b

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

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

    return ans


N, M = map(int,input().split())
ret = solve(N,M)
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(a)

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
x0 = min(max(int(m / 4. - n / 2.), 0), m / 2)
print max(min(n + x, (m - 2 * x) / 2) for x in xrange(x0 - 5, x0 + 5) if 0 <= x <= m / 2)

Submission status: Accepted

Solution code:
if __name__=="__main__":
    [S, C] = map(int,input().split())
    if(C - 2*S > 0):
        ans = S
        ans += (C - 2*S) // 4
    else:
        ans = C//2
    print(ans)

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]
ans=0
if m>=n*2:
    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())
a, b = 0, 10 ** 12
while b - a > 1:
    k = (a + b) // 2
    if 2 * k <= m and k <= n + (m - 2 * k) // 2:
        a = k
    else:
        b = k
print(a)

Submission status: Accepted

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

if num_c <= num_s * 2:
  # Sが多いとき
  print(num_c // 2)
else:
  scc = num_s
  num_s = 0
  num_c -= 2 * scc
  scc += num_c // 4
  print(scc)

Submission status: Accepted

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

lb, ub = 0, 10**18
K = 2 * N + M

while ub - lb > 1:
    md = (ub + lb) >> 1
    n, m = N, M
    n -= md
    if n < 0:
        m -= -n * 2
    if md * 2 <= m:
        lb = md
    else:
        ub = md

print(lb)

Submission status: Accepted

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

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

ans = 0
# Cが余る場合
if N * 2 <= M:
    # Sを全部使ってからCを使う
    print(N + (M-2*N) // 4)
# Sが余るとき
else:
    # ccの個数だけ作れる
    print(M // 2)

Submission status: Accepted

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

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

Submission status: Accepted

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

print mi + y/4

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


def solve(n, m):
    x = min(m // 2, n)
    y = (m - 2 * x) // 4
    return x + y


def main():
    n, m = (int(x) for x in input().split())
    print(solve(n, m))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))

INF = 2147483647


import sys
stdin = sys.stdin

s, c = map(int, stdin.readline().strip().split())

base = min(s, c // 2)
s -= base
c -= 2*base
rr = base

four = c // 4
c -= 4*c
rr += four

print rr

Submission status: Accepted

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

if __name__=="__main__":
    solve()

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

(N, M) = reads()

result = 0

k = min(N, M // 2)
(N, M) = (N - k, M - 2 * k)
result += k

k = M // 4
result += k

print(result)

Submission status: Accepted

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

s, c = [int(x) for x in input().split()]
ans = min(s, c // 2)
ans += (c - ans * 2) // 4
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans += c/4

print ans

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

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


def main():
    n,m = LI()
    if n >= m//2:
        return m//2
    r = n
    m -= 2*n
    r += m//4

    return r

print(main())

Submission status: Runtime Error

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

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

#print(res,s,c)

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

Submission status: Runtime Error

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

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

#print(res,s,c)

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if N==0:
  ans=n1+M//4
else:
  ans=n1+N//2
  raise ValueError()
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
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(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)
mod = 10**9+7

N = i()
S = s()
a = 'S'
b = 'W'
kouho = [[a,a],[a,b],[b,a],[b,b]]
for a,b in kouho:
    S1 = [a,b]
    for i in range(1,N):
        if S[i] == 'o':
            if S1[i] == 'S':
                if S1[i-1] == 'S':
                    S1.append('S')
                else:
                    S1.append('W')
            else:
                if S1[i-1] == 'S':
                    S1.append('W')
                else:
                    S1.append('S')
        else:
            if S1[i] == 'S':
                if S1[i-1] == 'S':
                    S1.append('W')
                else:
                    S1.append('S')
            else:
                if S1[i-1] == 'S':
                    S1.append('S')
                else:
                    S1.append('W')
    if S1[-1] != a:
        continue
    S1 = S1[:N]
    if a == 'S' and b == 'S':
        if S[0] == 'o':
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
    elif a == 'S' and b == 'W':
        if S[0] == 'o':
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
    elif a == 'W' and b == 'S':
        if S[0] == 'o':
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
    else:
        if S[0] == 'o':
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
print(-1)

Submission status: Runtime Error

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

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

print(solve(N,M))

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=input()
    for ans in ("SS","SW","WS","WW"):
        for c in s[1:]:
            if ans[-1]=="S":
                ans+="W" if (ans[-2]=="W")^(c=="x") else "S"
            else:
                ans+="S" if (ans[-2]=="W")^(c=="x") else "W"
        if ans[0]==ans[-1] and (((ans[0]=="W")^(s[0]=="x"))^(ans[-2]==ans[1])):
            print(ans[:-1])
            sys.exit()
    print(-1)


if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
N, M = map(int, input().split())
S = [0] * M
C = [0] * M
for i in range(M):
    S[i], C[i] = map(int, input().split())

for i in range(1000):
    string = str(i)
    if len(string) != N:
        continue
    flag = True
    for j in range(M):
        if string[S[j] - 1] == str(C[j]):
            None
        else:
            flag = False
            break
    if flag:
        print(i)
        sys.exit(0)
print("-1")

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
if 2 * N > M:
  print(M // 2)
else:
  C = M // 2
  n = (C - N) // 2
  print(max(min(S+n-1, C-n+1), min(S+n, C-n), min(S+n+1, C-n-1)))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions

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

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

top_list = [0]


for i in range(1, N):

	if a[i] > a[top_list[-1]]:
		top_list.append(i)

num_list = [0]*N
com = []
for i in range(len(top_list)):
	bisect.insort(com, a[top_list[i]])


for i in range(N - 1, top_list[-1], -1):
	bisect.insort(com, a[i])

stock = 0
#print(com, top_list, num_list)
for top in range(len(top_list) - 2, -1, -1):
	for i in range(top_list[top + 1] - 1, top_list[top], -1):
		#bisect.insort(com, a[i])
		com.append(a[i])
	com.sort()
	judge = 0
	total = stock*(a[top_list[top + 1]] - a[top_list[top]])
	#print(total, (a[top_list[top + 1]] - a[top_list[top]])*stock,  top)
	while judge == 0:
		x = com.pop()
		if x > a[top_list[top]]:
			total += x - a[top_list[top]]
			stock += 1
		else:
			bisect.insort(com, x)
			judge = 1
	num_list[top_list[top + 1]] = total
	#print(com, top_list, num_list, stock)


num_list[top_list[0]] = sum(a) - sum(num_list)
for i in range(N):
	print(num_list[i])

Submission status: Runtime Error

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