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

Solution in C (GCC 5.4.1) (judge verdict: Accepted)

#include <stdio.h>
#include <inttypes.h>

int ok(uint64_t s_num, uint64_t c_num, uint64_t target_num) {
	uint64_t s_tarinai;
	uint64_t c_as_c, c_as_s;
	if (s_num < target_num) {
		s_tarinai = target_num - s_num;
	} else {
		s_tarinai = 0;
	}
	c_as_c = target_num * 2;
	c_as_s = s_tarinai * 2;
	return c_as_c + c_as_s <= c_num;
}

int main(void) {
	uint64_t N, M;
	uint64_t left, right, mid;
	uint64_t answer = 0;
	if (scanf("%"SCNu64"%"SCNu64, &N, &M) != 2) return 1;
	left = 0;
	right = N + M;
	while (left <= right) {
		mid = (left + right) / 2;
		if (ok(N, M, mid)) {
			if (mid > answer) answer = mid;
			left = mid + 1;
		} else {
			right = mid - 1;
		}
	}
	printf("%"PRIu64"\n", answer);
	return 0;
}