stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-

// ALDS1_1-D: Maximum Profit



#include <algorithm>

#include <iostream>



static int max_profit(int const rs[], const unsigned int n)

{

  auto r0 = rs[0], r1 = rs[1];



  auto cur_p = r1 - r0;

  auto max_p = cur_p;

  auto min_r = std::min(r0, r1);



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

    const auto r = rs[i];

    cur_p = r - min_r;

    max_p = std::max(max_p, cur_p);

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

  }



  return max_p;

}



int main()

{

  unsigned int n;

  std::cin >> n;

  int rs[n];

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

    std::cin >> rs[i];

  }



  const int max_p = max_profit(rs, n);

  std::cout << max_p << std::endl;

}



// eof

// Optimized solution to the same problem (faster):
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-

// ALDS1_1-D: Maximum Profit



#include <algorithm>

#include <cstdio>



static int max_profit(int const rs[], const unsigned int n)

{

  auto r0 = rs[0], r1 = rs[1];



  auto cur_p = r1 - r0;

  auto max_p = cur_p;

  auto min_r = std::min(r0, r1);



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

    const auto r = rs[i];

    cur_p = r - min_r;

    max_p = std::max(max_p, cur_p);

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

  }



  return max_p;

}



int main()

{

  unsigned int n;

  std::scanf("%d", &n);

  int rs[n];

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

    std::scanf("%d", &rs[i]);

  }



  const int max_p = max_profit(rs, n);

  std::printf("%d\n", max_p);

}



// eof

// Fastest known solution for this problem:
// Original C++ solution (slower):


#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++) {

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

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

	}

	cout << maxv << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include "stdio.h"

#include <math.h>

int main()

{

	int n,R,Min;

	int diff = (int)pow(10, 9)*-1-1;



	scanf("%d %d",&n,&Min);

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

		scanf("%d", &R);

		if (diff < R - Min) {

			diff = R - Min;

		}

		if (Min > R) {

			Min = R;

		}

	}

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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++) {

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

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

	}

	cout << maxv << endl;

	return 0;

}




// Optimized solution to the same problem (faster):
#include "stdio.h"

#include <math.h>

int main()

{

	int n,R,Min;

	int diff = (int)pow(10, 9)*-1-1;



	scanf("%d %d",&n,&Min);

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

		scanf("%d", &R);

		if (diff < R - Min) {

			diff = R - Min;

		}

		if (Min > R) {

			Min = R;

		}

	}

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

using namespace std;



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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

using namespace std;



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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
//============================================================================

// 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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

    }

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem: