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())
a = list(map(int, input().split()))
b = []
for i in range(N):
    b.append([a[i], i+1])
b.sort(reverse = True)
ans = [0]*(N+1)
mini = N+1

for i in range(N-1):
    mini = min(mini, b[i][1])
    if b[i+1][0] - b[i][0] < 0:
        ans[mini] += (b[i][0] - b[i+1][0])*(i+1)

ans[1] += N*min(b[-1][0])
for i in range(N):
    print(ans[i+1])

Submission status: Runtime Error

Solution code:
from sys import exit, stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
r = M-2*N
if r <= 0:
    print(N//2)
else:
    pritnt(N+r//4)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from functools import cmp_to_key
     
n = int(input())
a = list(map(int, input().split()))
     
def group(a):
	d = {}
    for i, x in enumerate(a):
      d.setdefault(x, []).append(i)
      s = sorted(d.items(), key=cmp_to_key(lambda x, y: x[0] - y[0]),
               reverse=True)
      return list(map(lambda x: [x[0], x[1][0], len(x[1])], s))
     
ans = [0] * n
g = group(a)
g.append([0, 0, 0])
for c, n in zip(g[:-1], g[1:]):
  ans[c[1]] += (c[0] - n[0]) * c[2]
  n[1] = min(c[1], n[1])
  n[2] += c[2]

  [print(a) for a in ans]

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
from operator import itemgetter
n = int(raw_input())
a = [[int(k),i+1] for i,k in enumerate(raw_input().split())]
a.sort(key=itemgetter(0),reverse=True)
s = []
b = []
a.append([0,0])
for i,p in enumerate(a[:-1]):
    if not p[0] == a[i+1][0]:
        q = a[i][0] - a[i+1][0]
        y = [z[1] for z in a[:i+1]]
        s.extend([min(y)]*(i+1)*q)

for i in xrange(1,int(n)+1):
    print(s.count(i))

Submission status: Runtime Error

Solution code:
def main():
    s, c = map(int, raw_input().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
    return count

print main()

Submission status: Runtime Error

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
    return count

print main()

Submission status: Runtime Error

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

answer = 0
if (n * 2) >= m:
  answer = m / 2
else:
  answer = n + (  m - (n *2) )  / 3)
print answer
print calc_scc(12345,678901), 175897

Submission status: Runtime Error

Solution code:
#ARC069A

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

Submission status: Runtime Error

Solution code:
#ARC069A

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, raw_input().split())
if M == 2*N:
    print("%d"%M)
elif M < 2*M:
    print("%d"%M + (N - 2*M - (N - 2*M)%4) / 4)
else:
    print("%d"%N + (M - 2*N - (M - 2*N) %4) / 4)

Submission status: Runtime Error

Solution code:

N, M = map(int, raw_input().split())
if M == 2*N:
    print("%d"%M)
elif M < 2*M:
    print("%d"%M + (N - 2*M - (N - 2*M)%4) / 4)
else:
    print("%d"%N + (M - 2*N - (M - 2*N) %4) / 4)

Submission status: Runtime Error

Solution code:
def solve(M, N):
    if M == 2*N:
        return M
    elif M < 2*M:
        return M + (N - 2*M - (N - 2*M)%4) / 4
    else:
        return N + (M - 2*N - (M - 2*N) %4) / 4
M, N = map(int, raw_input().split())
print("%d"%solve(M, N))

Submission status: Runtime Error

Solution code:
def solve(M, N):
    if M == 2*N:
        return M
    elif M < 2*M:
        return M + int((N - 2*M) / 4)
    else:
        return N + int((M - 2*N) / 4)
M, N = map(int, raw_input().split())
print(solve(M, N))

Submission status: Runtime Error

Solution code:
M, N = raw_input().split(" ")
def solve(M, N):
    if M == 2*N:
        return M
    elif M < 2*M:
        return M + int((N - 2*M) / 4)
    else:
        return N + int((M - 2*N) / 4)
solve(M, N)

Submission status: Runtime Error

Solution code:
import math
def solve(M, N):
    if M == 2*N:
        return M
    elif M < 2*M:
        return M + math.floor((N - 2*M) / 4)
    else:
        return N + math.floor((M - 2*N) / 4)
M, N = raw_input().split(" ")
solve(M, N)

Submission status: Runtime Error

Solution code:
n=int(input());s=input();a=['SS','WS','SW','WW']
for i in range(n):
    for j in range(4):a[j]+='SW'[::-1 if s[i]=='o' else 1][a[j][i]==a[j][i+1]]
for i in range(4):
    if a[i][1]==a[i][n+1] and a[i][0] == a[i][n]:print(a[i][1:n+1]);exit()
print(-1)

Submission status: Runtime Error

Solution code:
def findNextAnimal(oxList, swList, index):
    nextAns = oxList[index]
    before = swList[index-1]
    animal = swList[index]
    nextAnimal = ""
    if(nextAns == "o" and before == "S" and animal == "S"):
        nextAnimal = "S"
    elif(nextAns == "o" and before == "S" and animal == "W"):
        nextAnimal = "W"
    elif(nextAns == "o" and before == "W" and animal == "S"):
        nextAnimal = "W"
    elif(nextAns == "o" and before == "W" and animal == "W"):
        nextAnimal = "S"
    elif(nextAns == "x" and before == "S" and animal == "S"):
        nextAnimal = "W"
    elif(nextAns == "x" and before == "S" and animal == "W"):
        nextAnimal = "S"
    elif(nextAns == "x" and before == "W" and animal == "S"):
        nextAnimal = "S"
    elif(nextAns == "x" and before == "W" and animal == "W"):
        nextAnimal = "W"
    return nextAnimal

def checkList(oxList, swList):
    ans = 0
    if(swList[-1] == "S"):
        if(oxList[-1] == "x" and swList[-2] != swList[0]):
            ans = 1
        elif(oxList[-1] == "o" and swList[-2] == swList[0]):
            ans = 1
    elif(swList[-1] == "W"):
        if(oxList[-1] == "x" and swList[-2] == swList[0]):
            ans = 1
        elif(oxList[-1] == "o" and swList[-2] != swList[0]):
            ans = 1
            
    ans2 = 0    
    if(swList[0] == "S"):
        if(oxList[0] == "x" and swList[1] != swList[-1]):
            ans2 = 1
        elif(oxList[0] == "o" and swList[1] == swList[-1]):
            ans2 = 1
    elif(swList[0] == "W"):
        if(oxList[0] == "x" and swList[1] == swList[-1]):
            ans2 = 1
        elif(oxList[0] == "o" and swList[1] != swList[-1]):
            ans2 = 1
    
    return ans*ans2

n = raw_input().strip().upper()
oxList = raw_input().strip().lower()

ans = -1
for s0 in ["S", "W"]:
    for s1 in ["S","W"]:
        swList = [0]*int(n)
        swList[0] = s0
        swList[1] = s1
        for i in range(2, int(n)):
            nextAnimal = findNextAnimal(oxList, swList, i-1)
            swList[i] = nextAnimal
        flag = checkList(oxList, swList)
        if(flag == 1):
            ans = ""
            for s in swList:
                ans += s
print ans

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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