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: Time Limit Exceeded)

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

int main(){
	long long int n, m;
	scanf("%lld%lld", &n, &m);
	long  long int count = 0;
	if((n>100000000000) && (m>200000000000)){
		while((n>100000000000) && (m>200000000000)){
			n = n-100000000000;
			m = m-200000000000;
			count += 100000000000;
		}
	}//11
	if((n>10000000000) && (m>20000000000)){
		while((n>10000000000) && (m>20000000000)){
			n = n-10000000000;
			m = m-20000000000;
			count += 10000000000;
		}
	}//10
	if((n>1000000000) && (m>2000000000)){
		while((n>1000000000) && (m>2000000000)){
			n = n-1000000000;
			m = m-2000000000;
			count += 1000000000;
		}
	}//9
	if((n>100000000) && (m>200000000)){
		while((n>100000000) && (m>200000000)){
			n = n-100000000;
			m = m-200000000;
			count += 100000000;
		}
	}//8
	if((n>10000000) && (m>20000000)){
		while((n>10000000) && (m>20000000)){
			n = n-10000000;
			m = m-20000000;
			count += 10000000;
		}
	}//7
	if((n>1000000) && (m>2000000)){
		while((n>1000000) && (m>2000000)){
			n = n-1000000;
			m = m-2000000;
			count += 1000000;
		}
	}//6
	while((n>=1) && (m>=2)){
		n--;
		m = m-2;
		count++;
	}
	if(m>=4){
		while(m>=4){
			count++;
			m = m-4;
		}
	}
	printf("%lld\n", count);

	return 0;
}