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: Wrong Answer)

                #include <bits/stdc++.h>
                using namespace std;
                typedef long long ll;
                #define INPUT()              freopen("input.txt", "r", stdin)
                #define OUTPUT()             freopen("output.txt", "w", stdout)
                #define F                    first
                #define S                    second
            //Templatefunctions
                template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y);}
                template <class T> T euclideanDistance(T x1 , T x2 , T y1 , T y2){return sqrt(( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ));}
                template <class T> T digitSum(T n){T sum = 0;while(n > 0)sum += n % 10,n /= 10;return sum;}
            //datatypes
                typedef long long int ll;
                typedef unsigned long long int ull;
                typedef long double ld;
            //constants
                const double INF = 1e+9;
                const double INFLL = 1e+18;
                const double EPS = 1e-9;
                const double PI = acos(-1);
                const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
                       //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
                       //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
                const int dx[] = {0 , 1 , 0 , -1};
                const int dy[] = {1 , 0 , -1 , 0};
            //helpers
                //#define MOD         1000000007LL
                #define MAX         1000005
                const ll MOD = 1000000000 + 7;
                int arr[MAX];
                char str[MAX+10];
            //Global Variables
                int price[MAX] = {0 , 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 , 24 , 30};
                int dp[MAX],n;

                int main()
                {
                   ll s,c;
                   scanf("%lld%lld",&s,&c);
                   ll ans = 0;
                   if(c < s * 2 || c < s)
                   {
                        ans = c / 2;
                   }else
                   {
                        ans += s;
                        c -= s * 2;
                        for(int i = 1 ; ; i++)
                        {
                            if(i * 4 > c)
                            {
                                ans += (i-1);
                                break;
                            }
                        }
                   }
                   printf("%lld\n",ans);
                }