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++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <iostream>
#include <string>

using namespace std;

string ss;
bool translate(int n, string s, string in);

int main()
{
	int n;
	string s;
	cin >> n >> s;
	if(translate(n, s, "SS"))
		cout << ss << endl;
	else if(translate(n, s, "SW"))
		cout << ss << endl;
	else if(translate(n, s, "WW"))
		cout << ss << endl;
	else if(translate(n, s, "WS"))
		cout << ss << endl;
	else
		cout << "-1" << endl;
	return 0;
}



bool translate(int n, string s, string in)
{
	ss = in;
	s = s + s[0];
	for(int i=1; i<n+1; i++) {
		if(ss[i] == 'S') {
			if(s[i] == 'o')
				ss = ss + ss[i-1];
			else {
				char ch = 'W' ^ 'S' ^ ss[i-1];
				ss = ss + ch;
			}
		}
		else {
			if(s[i] == 'o') {
				char ch = 'W' ^ 'S' ^ ss[i-1];
				ss = ss + ch;
			}
			else
				ss = ss + ss[i-1];
		}
	}

	if(ss[0] == ss[n] && ss[1] == ss[n+1])
		ss[n] = '\0';
	else
		return false;
	return true;
}