stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;



int main() {

  int n, Rt;

  int maxv = -2e9;

  int minv = 2e9;



  cin >> n;



  for ( int i = 0; i < n; i++ ) {

    cin >> Rt;

    maxv = max(maxv, Rt - minv);

    minv = min(minv, Rt);

  }



  cout << maxv << endl;



  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.232788568400972x):
#include<cstdio>



int main() {

  int n, Rt;

  int maxv = -2e9;

  int minv = 2e9;



  scanf("%d", &n);



  for ( int i = 0; i < n; i++ ) {

    scanf("%d", &Rt);

    maxv = maxv > Rt-minv ? maxv : Rt-minv;

    minv = minv < Rt ? minv : Rt;

  }



  printf("%d\n", maxv);



  return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;

static const int MAX = 200000;



int main() {

  int R[MAX], n;



  cin >> n;

  for ( int i = 0; i < n; i++ ) cin >> R[i];



  int maxv = -2000000000;  // 十分小さい値を初期値に設定

  int minv = R[0];



  for ( int i = 1; i < n; i++ ) {  // ここで毎回 R[i] を読み込めば、配列は不要

    maxv = max(maxv, R[i] - minv);  // 最大値を更新

    minv = min(minv, R[i]);  // ここまでの最小値を保持しておく

  }



  cout << maxv << endl;



  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.31314179961239x):
#include<stdio.h>



int main() {

  int n, Rt;

  int maxv = -2e9;

  int minv = 2e9;



  scanf("%d", &n);



  for ( int i = 0; i < n; i++ ) {

    scanf("%d", &Rt);

    maxv = maxv > Rt-minv ? maxv : Rt-minv;

    minv = minv < Rt ? minv : Rt;

  }



  printf("%d\n", maxv);



  return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;



int main() {

  int n, Rt;

  int maxv = -2e9;

  int minv = 2e9;



  cin >> n;



  for ( int i = 0; i < n; i++ ) {

    cin >> Rt;

    maxv = max(maxv, Rt - minv);

    minv = min(minv, Rt);

  }



  cout << maxv << endl;



  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.232788568400972x):
#include<stdio.h>



int main() {

  int n, Rt;

  int maxv = -2e9;

  int minv = 2e9;



  scanf("%d", &n);



  for ( int i = 0; i < n; i++ ) {

    scanf("%d", &Rt);

    maxv = maxv > Rt-minv ? maxv : Rt-minv;

    minv = minv < Rt ? minv : Rt;

  }



  printf("%d\n", maxv);



  return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;

static const int MAX = 200000;



int main() {

	int R[MAX], n;



	cin >> n;

	for (int i = 0; i < n; i++)cin >> R[i];



	int maxv = -1000000000;

	int minv = R[0];



	for (int i = 1; i < n; i++) {

		maxv = max(maxv, R[i] - minv);

		minv = min(minv, R[i]);

	}



	cout << maxv << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.748702502347826x):
#include<stdio.h>

#include<stdlib.h>



#define BUFSIZE 200000

#define INTMIN -2000000000



int main(){

    int n, buf[BUFSIZE];

    scanf("%d", &n);

    for(int i = 0; i < n; i++){

        scanf("%d", buf + i);

    }

    int min = buf[0];

    int max = INTMIN;

    for(int i = 1; i < n; i++){

        if(max < buf[i] - min)max = buf[i] - min;

        if(min > buf[i])min = buf[i];

    }

    printf("%d\n", max);

}
// Slower C++ solution:
//============================================================================

// Name        : ALDS1_1_D.cpp

// Author      :

// Version     :

// Copyright   : Your copyright notice

// Description : Hello World in C++, Ansi-style

//============================================================================



#include <iostream>

using namespace std;



int main() {

	int n;

	int temp, min=1000000000, p_max=-1000000000;

	cin >> n;

	cin >> min;

	for(int i=1; i<n; ++i) {

		cin >> temp;

		if(temp-min>p_max) p_max=temp-min;

		if(min>temp) min=temp;

	}

	cout << p_max << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.228592228176549x):
#include <cstdio>

using namespace std;



int main() {

	int n;

	int temp, min=1000000000, p_max=-1000000000;

	scanf("%d",&n);

	scanf("%d",&min);

	for(int i=1; i<n; ++i) {

		scanf("%d",&temp);

		if(temp-min>p_max) p_max=temp-min;

		if(min>temp) min=temp;

	}

	printf("%d\n",p_max);

	return 0;

}
// Slower C++ solution:
#include <cstdint>

#include <iostream>



using namespace std;



inline int64_t max(int64_t a, int64_t b) {

  return a >= b ? a : b;

}



inline int64_t min(int64_t a, int64_t b) {

  return a <= b ? a : b;

}



int main() {

  int n;

  cin >> n;



  int64_t r;

  int64_t r_min;

  int64_t d_max = -1000000000;

  cin >> r_min;

  for (int i = 1; i < n; ++i) {

    cin >> r;

    d_max = max(d_max, r - r_min);

    r_min = min(r_min, r);

  }

  cout << d_max << endl;



  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.217714006433662x):
#include <cstdint>

#include <cstdio>



using namespace std;



inline int64_t max(int64_t a, int64_t b) {

  return a >= b ? a : b;

}



inline int64_t min(int64_t a, int64_t b) {

  return a <= b ? a : b;

}



int main() {

  int n;

  scanf("%d", &n);



  int64_t r;

  int64_t r_min;

  int64_t d_max = -1000000000;

  scanf("%lld", &r_min);

  for (int i = 1; i < n; ++i) {

    scanf("%lld", &r);

    d_max = max(d_max, r - r_min);

    r_min = min(r_min, r);

  }

  printf("%lld\n", d_max);                                                                                                                                                



  return 0;

}
// Slower C++ solution:
#include<iostream>

int main()

{

	int maxv = -1000000000;

	int minv;

	int n;

	int r,r0;



	std::cin >> n;

	std::cin >> r0;

	minv = r0;



	for(int i=1;i<n;i++){

		std::cin >> r;

		maxv = std::max(maxv,r-minv);

		minv = std::min(minv,r);

	}



	std::cout << maxv << "\n";



	return (0);

}

// Faster C++ solution for the same problem (measured speedup: 5.241779809990273x):
#include<cstdio>

#include<algorithm>

using namespace std;



int main(void){

	int N, R;

	scanf("%d", &N);

	int maxv = -1000000001;

	scanf("%d", &R);

	int minv = R;

	for(int i = 2; i <= N; i++){

		scanf("%d", &R);

		maxv = max(maxv, R - minv);

		minv = min(minv, R);

	}

	printf("%d\n", maxv);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<climits>

using namespace std;

int main(){

        int n;

        int R[200000];

        cin >> n;

        for(int i=0;i<n;i++)

                cin >> R[i];

        int minv=R[0],maxv=INT_MIN;

        for(int i=1;i<n;i++){

                maxv=max(maxv,R[i]-minv);

                minv=min(minv,R[i]);

        }

        cout<<maxv<<endl;

        return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.423008059640872x):
#include<stdio.h>

#include<limits.h>

#include<algorithm>



using namespace std;



int main(void){

  int n;

  long long int R[200001];

  scanf("%d", &n);

  for(int i = 0; i < n; i++){

    scanf("%lld", &R[i]);

  }

  long long int maxv = LLONG_MIN;

  long long int minv = R[0];

  for(int i = 1; i < n; i++){

    maxv = max(R[i] - minv, maxv);

    minv = min(R[i], minv);

  }



  printf("%lld\n", maxv);



  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){

  int n;

  cin >> n;

  int R[200000];

  for(int i=0;i<n;i++)

    cin >> R[i];

  int minv=R[0],maxv=INT_MIN;

  for(int i=1;i<n;i++){

    maxv=max(maxv,R[i]-minv);

    minv=min(minv,R[i]);

  }

  cout << maxv << endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.423008059640872x):
#include<stdio.h>

#include<limits.h>

#include<algorithm>



using namespace std;



int main(void){

  int n;

  long long int R[200001];

  scanf("%d", &n);

  for(int i = 0; i < n; i++){

    scanf("%lld", &R[i]);

  }

  long long int maxv = LLONG_MIN;

  long long int minv = R[0];

  for(int i = 1; i < n; i++){

    maxv = max(R[i] - minv, maxv);

    minv = min(R[i], minv);

  }



  printf("%lld\n", maxv);



  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <cassert>

#include <cctype>

#include <cstdio>



using namespace std;



int main(void) {



    int N;

    cin >> N;



    int diff = -1e9, begin;

    cin >> begin;

    for (int i = 0, r; i < N - 1; ++i) {

        cin >> r;

        if (r - begin > diff)

            diff = r - begin;

        if (r < begin)

            begin = r;

    }



    printf("%d\n", diff);



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.172754868717503x):
#include <cstdio>



using namespace std;



int main(void) {



    int N;

    scanf("%d", &N);



    int d = -1e9, b;

    scanf("%d", &b);

    for (int i = 0, r; i < N - 1; ++i) {

        scanf("%d", &r);

        if (r - b > d)

            d = r - b;

        if (r < b)

            b = r;

    }



    printf("%d\n", d);



    return 0;

}
// Slower C++ solution:
#include <cstdio>

using namespace std;

int main(void){

    int n;

    long long r[200000], maxv, minv;

    scanf("%d", &n);

    for (int i = 0; i < n; i++){

        scanf("%ld", &r[i]);

    }

    maxv = r[1] - r[0];

    minv = r[0];

    for (int i = 1; i < n; i++){

        if (minv > r[i-1]) minv = r[i-1];

        if (maxv < r[i] - minv) maxv = r[i] - minv;

    }

    printf("%d\n", maxv);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.200099369578732x):
#include <cstdio>

using namespace std;

int main(void){

    int n;

    long maxv, minv, buy, sell;

    scanf("%d", &n);

    scanf("%ld", &buy);

    scanf("%ld", &sell);

    maxv = sell - buy;

    if (buy > sell) buy = sell;

    for (int i = 2; i < n; i++){

        scanf("%ld", &sell);

        if (maxv < sell - buy) maxv = sell - buy;

        if (buy > sell) buy = sell;

    }

    printf("%d\n", maxv);

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>



using namespace std;



int n;

static const int MAX_N = 200000;

int R[MAX_N];



int main(){

  cin >> n;

  for(int i = 0; i < n; i++)

    cin >> R[i];

  int maxv = -2000000000;

  int minv = R[0];

  for(int i = 1; i < n; i++){

    maxv = max(maxv, R[i] - minv);

    minv = min(minv, R[i]);

  }

  cout << maxv << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.22698040898629x):
#include <cstdio>

using namespace std;



#define MAX(a, b) ((a) > (b) ? (a) : (b))

#define MIN(a, b) ((a) > (b) ? (b) : (a))



int d[200000 + 2];



int main(){

	int n;

	scanf("%d", &n);

	for (int i = 0; i < n; i++) scanf("%d", &d[i]);



	int max = d[1] - d[0];

	int min = d[0];

	for(int i = 1; i < n; i++){

		max = MAX(d[i]-min, max);

		min = MIN(min, d[i]);

	}

	printf("%d\n", max);



	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main()

{

	int n, mini, res, R;

	cin >> n >> mini >> R;

	res = R - mini;

	mini = min(mini, R);

	for (int i = 2; i < n; i++) {

		cin >> R;

		res = max(res, R - mini);

		mini = min(mini, R);

	}

	cout << res << endl;

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.240238562084469x):
#include <stdio.h> 

int main()

{

	int n, mini, res, r, i;

    scanf("%d%d%d", &n, &mini, &r);

	res = r - mini;

    if(r < mini) mini = r;

	for (i = 2; i < n; i++) {

        scanf("%d", &r);

        if(r - mini > res) res = r - mini;

        if(r < mini) mini = r;

	}

    printf("%d\n", res);

	return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;



int main()

{

    int i, n, d, min, max, R_t[200000];

    cin >> n >> R_t[0] >> R_t[1];

    min = R_t[0];

    max = R_t[1] - R_t[0];

    if(R_t[0] > R_t[1]) min = R_t[1];



    for(i = 2; i < n; i++){

        cin >> R_t[i];

        d = R_t[i] - min;

        if(max < d) max = d;

        if(min > R_t[i]) min = R_t[i];

    }



    cout << max << endl;



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.924018427724365x):
#include<stdio.h>



int main()

{

    int i, n, d, min, max, R_t[200000];

    scanf("%d %d %d", &n, &R_t[0], &R_t[1]);



    min = R_t[0];

    max = R_t[1] - R_t[0];

    if(R_t[0] > R_t[1]) min = R_t[1];



    for(i = 2; i < n; i++){

        scanf("%d", &R_t[i]);

        d = R_t[i] - min;

        if(max < d) max = d;

        if(min > R_t[i]) min = R_t[i];

    }



    printf("%d\n", max);



    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



int main()

{   long long  n,m;

   while(~scanf("%lld%lld",&n,&m))

   {

		    long long ans=0;

			if(m/2>=n)

			{ ans+=n;

			  m-=n*2;

			  ans+=m/4.0;

			}

			else {

				ans+=m/2.0;

			}

    	 printf("%lld\n",ans);

   }

	

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.191659413300713x):
#include<stdio.h>

int main()

{

	long long N,M,num,x,p;

	while(~scanf("%lld%lld",&N,&M))

	{

		x=M/2;

		if(N>=x) num=x;

		else

		{

			num=N;

			M-=2*N;

			p=M/4;

			num+=p;

		}

		printf("%lld\n",num);

	}

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



int main()

{   long long  n,m;

   while(~scanf("%lld%lld",&n,&m))

   {

		    long long ans=0;

			if(m/2>=n)

			{ ans+=n;

			  m-=n*2;

			  ans+=m/4.0;

			}

			else {

				ans+=m/2.0;

			}

    	 printf("%lld\n",ans);

   }

	

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2012874050833355x):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int a[1000001];

main()

{



    long long n,m,sum,p;

    scanf("%lld %lld",&n,&m);

    if (n*2==m)

    {

        sum=n;

    }

    else if (n*2<m)

    {

        p=m-n*2;

        sum=n+p/4;

    }

    else

    {

        sum=m/2;

    }

    printf("%lld\n",sum);

}
// Slower C++ solution:
#include <map>

#include <math.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

#include <algorithm>

using namespace std;

#define INF 0x3f3f3f3f







int main()

{

	long long n, m, sum;

	std::ios::sync_with_stdio(false);

	while (cin >> n >> m)

	{

		sum = 0;

		if (2 * n <= m)

		{

			sum += n;

			m -= 2 * n;

			sum += m / 4;

		}

		else if (2 * n > m)

			sum = m / 2;

		cout << sum << endl;

	}



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.324822318949454x):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int a[1000001];

main()

{



    long long n,m,sum,p;

    scanf("%lld %lld",&n,&m);

    if (n*2==m)

    {

        sum=n;

    }

    else if (n*2<m)

    {

        p=m-n*2;

        sum=n+p/4;

    }

    else

    {

        sum=m/2;

    }

    printf("%lld\n",sum);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



int main()

{   long long  n,m;

   while(~scanf("%lld%lld",&n,&m))

   {

		    long long ans=0;

			if(m/2>=n)

			{ ans+=n;

			  m-=n*2;

			  ans+=m/4.0;

			}

			else {

				ans+=m/2.0;

			}

    	 printf("%lld\n",ans);

   }

	

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.19995464311643x):
#include <stdio.h>

#include <algorithm>

using namespace std;

int main(int argc, char *argv[])

{

	long long n,m,s;

	scanf("%lld %lld",&n,&m);

	if(2*n<=m)

	{

		s=n;

		m=m-2*n;

		s+=m/4;

		printf("%lld\n",s);

	}

	else 

	{

		printf("%lld\n",m/2);

	}

	return 0;

}
// Slower C++ solution:
#include <map>

#include <math.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

#include <algorithm>

using namespace std;

#define INF 0x3f3f3f3f







int main()

{

	long long n, m, sum;

	std::ios::sync_with_stdio(false);

	while (cin >> n >> m)

	{

		sum = 0;

		if (2 * n <= m)

		{

			sum += n;

			m -= 2 * n;

			sum += m / 4;

		}

		else if (2 * n > m)

			sum = m / 2;

		cout << sum << endl;

	}



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.3234579027742805x):
#include <stdio.h>

#include <algorithm>

using namespace std;

int main(int argc, char *argv[])

{

	long long n,m,s;

	scanf("%lld %lld",&n,&m);

	if(2*n<=m)

	{

		s=n;

		m=m-2*n;

		s+=m/4;

		printf("%lld\n",s);

	}

	else 

	{

		printf("%lld\n",m/2);

	}

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

LL fun(LL n, LL m){

    if((m / 2) < n) return  m / 2;

    LL ans = n;m=m-n*2;

    ans = ans + m / 4;

    return ans;

}

int main(){

    LL n, m;

    scanf("%lld%lld", &n, &m);

    LL ans = fun(n, m);

    printf("%lld\n", ans); return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.19823147526304x):
#include<stdio.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<stdlib.h>

using namespace std;

typedef long long ll;

const int mod=1e9+7;

int main()

{

	ll n,m;

	scanf("%lld%lld",&n,&m);

	ll a,b;

	ll sum=0;

	if(n*2<=m)

	{

		sum+=n;

		a=m-n*2;

		sum+=a/4;

	}

	else

	{

		sum=m/2;

		

	}

	printf("%lld\n",sum);

	return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;

long long int a,b;

int main()

{

	cin>>a>>b;

	if(a>=b/2)

	{

		cout<<b/2<<endl;

	}

	else

	{

		cout<<a+(b-a*2)/4<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2609825857457615x):
#include<stdio.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<stdlib.h>

using namespace std;

typedef long long ll;

const int mod=1e9+7;

int main()

{

	ll n,m;

	scanf("%lld%lld",&n,&m);

	ll a,b;

	ll sum=0;

	if(n*2<=m)

	{

		sum+=n;

		a=m-n*2;

		sum+=a/4;

	}

	else

	{

		sum=m/2;

		

	}

	printf("%lld\n",sum);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;



LL fun(LL n, LL m)//写个自定义函数配配对

{

    if((m / 2) < n) return  m / 2;

    LL ans = n;

    m = m - n * 2;

    ans = ans + m / 4;

    return ans;

}



int main()

{

    LL n, m;

    scanf("%lld%lld", &n, &m);

    LL ans = fun(n, m);

    printf("%lld\n", ans);//输出与换行

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.19823147526304x):
#include<stdio.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<stdlib.h>

using namespace std;

typedef long long ll;

const int mod=1e9+7;

int main()

{

	ll n,m;

	scanf("%lld%lld",&n,&m);

	ll a,b;

	ll sum=0;

	if(n*2<=m)

	{

		sum+=n;

		a=m-n*2;

		sum+=a/4;

	}

	else

	{

		sum=m/2;

		

	}

	printf("%lld\n",sum);

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

using namespace std;

int main(){

	long long n,m;

	cin>>n>>m;

	if(m/2<n){

		cout<<m/2;

	}else{

		cout<<n+(m-n*2)/4;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2491384185783465x):
#include<stdio.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<stdlib.h>

using namespace std;

typedef long long ll;

const int mod=1e9+7;

int main()

{

	ll n,m;

	scanf("%lld%lld",&n,&m);

	ll a,b;

	ll sum=0;

	if(n*2<=m)

	{

		sum+=n;

		a=m-n*2;

		sum+=a/4;

	}

	else

	{

		sum=m/2;

		

	}

	printf("%lld\n",sum);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

inline int minn(int a,int b)

{

    if(a>b)return b;

    else return a;

}

int main()

{

    long long int n,m,ans;

    cin>>n>>m;

    if(n>=m/2)ans=m/2;

    else ans=(n*2+m)/4;

    cout<<ans<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2606379531771x):
#include<stdio.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<stdlib.h>

using namespace std;

typedef long long ll;

const int mod=1e9+7;

int main()

{

	ll n,m;

	scanf("%lld%lld",&n,&m);

	ll a,b;

	ll sum=0;

	if(n*2<=m)

	{

		sum+=n;

		a=m-n*2;

		sum+=a/4;

	}

	else

	{

		sum=m/2;

		

	}

	printf("%lld\n",sum);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){

    long long n,m;

    scanf ("%lld%lld",&n,&m);

    if (n<=(n*2+m)/4) printf ("%lld",(n*2+m)/4);

    else printf ("%lld",m/2);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.196462655968329x):
#include<stdio.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<stdlib.h>

using namespace std;

typedef long long ll;

const int mod=1e9+7;

int main()

{

	ll n,m;

	scanf("%lld%lld",&n,&m);

	ll a,b;

	ll sum=0;

	if(n*2<=m)

	{

		sum+=n;

		a=m-n*2;

		sum+=a/4;

	}

	else

	{

		sum=m/2;

		

	}

	printf("%lld\n",sum);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#define int long long

using namespace std;

int s,c;

signed main()

{

	scanf("%lld%lld",&s,&c);

	if(c<=s*2)

		printf("%lld\n",min(c/2,s));

	else

		printf("%lld\n",s+(c-s*2)/4);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.203827859769898x):
#include <cstdio>

#define ll long long

#define min(a,b) (a<b?a:b)

#define max(a,b) (a>b?a:b)



ll n,m;



int main(){

    scanf("%lld%lld",&n,&m);

    printf("%lld\n",min(n,m/2)+max(m-n*2,0)/4);

    return 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;

long long n,m;



int main(void){

    cin>>n>>m;

    if(2*n>=m)cout<<m/2<<endl;

    else cout<<n+(m-2*n)/4<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.262682419370049x):
#include <cstdio>

#define ll long long

#define min(a,b) (a<b?a:b)

#define max(a,b) (a>b?a:b)



ll n,m;



int main(){

    scanf("%lld%lld",&n,&m);

    printf("%lld\n",min(n,m/2)+max(m-n*2,0)/4);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

unsigned long long n,m,nd;

int main()

{

    cin>>n>>m;

    nd=2*n;

    if(nd>m)

    {

        cout<<(m>>1)<<endl;

        return 0;

    }

    else if(nd==m)

    {

        cout<<n<<endl;

        return 0;

    }

    else

    {

        m-=nd;

        m/=4;

        cout<<n+m<<endl;

        return 0;

    }

}

// Faster C++ solution for the same problem (measured speedup: 5.262256577706526x):
#include <cstdio>

#define ll long long

#define min(a,b) (a<b?a:b)

#define max(a,b) (a>b?a:b)



ll n,m;



int main(){

    scanf("%lld%lld",&n,&m);

    printf("%lld\n",min(n,m/2)+max(m-n*2,0)/4);

    return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <cstdio>

using namespace std;

#define debug(x) cerr << #x << "=" << x << endl;

typedef long long ll;

ll n, m, ans;

int main() {

    cin >> n >> m;

    if(m - 2*n >= 0) {

        ans += n;

        ans += (m-2*n)/4;

    } else {

        ans = m/2;

    }

    cout << ans;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.209704882489144x):
#include<cstdio>

int main()

{

	long long n,m;

	scanf("%lld%lld",&n,&m);

	long long ans=m-n*2;

	if(ans<0)

	{

		printf("%lld\n",m/2);

		return 0;

	} 

	printf("%lld\n",n+ans/4);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

using namespace std;

ll fun(ll n, ll m)

{

    if((m/2)<n)return m/2;

    ll ans=n;

    m=m-n*2;

    ans=ans+m/4;

    return ans;

}  

int main()

{

    ll n,m;

    scanf("%lld%lld",&n,&m);

    ll ans=fun(n,m);

    printf("%lld\n",ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.201249650009578x):
#include <cstdio> 

#include <cmath> 

#include <cstdlib> 

#define For(i,j,k) for(int i=j;i<=k;i++)

#define Dow(i,j,k) for(int i=j;i>=k;i--)

#define LL long long

using namespace std ;

inline int read() {

	int x = 0 , f = 1 ;

	char ch = getchar() ;

	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }

	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }

	return x * f ;

}



const int inf = 1e9; 

LL s,c;



int main() {

	scanf("%lld%lld",&s,&c);

	if( s*2>=c ) {

		printf("%lld\n",c/2);

		return 0;

	}

	c-=s*2;

	printf("%lld\n",s+c/4);

}