prithivMLmods/Coder-Stat huggingface dataset:
Problem p03796 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
p = 1
for i in range(n):
    p *= i + 1
print(p % (10**9 + 7))


Fixed submission:
n = int(input())
p = 1
for i in range(n):
    p = p * (i + 1) % (10**9 + 7)
print(p)
Problem p03796 (Python)

Buggy submission (status: Time Limit Exceeded):
h1 = int(input())
m = 1
for i in range(h1):
    m = m * (i + 1)
print(m % (10**9 + 7))


Fixed submission:
h1 = int(input())
m = 1
for i in range(h1):
    m = (m * (i + 1)) % (10**9 + 7)
print(m)
Problem p03796 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
n = 1000000007
p = 1
for i in range(1, N + 1):
    p *= i
print(p % n)


Fixed submission:
N = int(input())
n = 1000000007
p = 1
for i in range(1, N + 1):
    p *= i
    p %= n
print(p)
Problem p03796 (Python)

Buggy submission (status: Runtime Error):
import math

n = int(input())
print(math.factorical(n) % (10**9 + 7))


Fixed submission:
import math

n = int(input())
print(math.factorial(n) % (10**9 + 7))
Problem p03796 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
training = 1
for i in range(1, n + 1):
    training *= i
print(training % (10**9 + 7))


Fixed submission:
n = int(input())
training = 1
for i in range(1, n + 1):
    training = i * training % (10**9 + 7)
print(training)
Problem p03796 (Python)

Buggy submission (status: Time Limit Exceeded):
def main():
    N = int(input())
    result = 1
    for i in range(1, N + 1):
        result = result * i
    print(result % (10**9 + 7))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = int(input())
    result = 1
    for i in range(1, N + 1):
        result = (result * i) % (10**9 + 7)
    print(result)


if __name__ == "__main__":
    main()
Problem p03796 (Python)

Buggy submission (status: Time Limit Exceeded):
p = 1
for i in range(int(input())):
    p *= i + 1
print(p % (10**9 + 7))


Fixed submission:
p = 1
for i in range(int(input())):
    p = ((i + 1) * p) % (10**9 + 7)
print(p)
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;
  while (n < m / 2) {
    n++;
    m -= 2;
  }
  cout << m / 2;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;
  if (n < m / 2) {
    long long k = (m - 2 * n + 3) / 4;
    m -= (2 * k);
  }
  cout << m / 2;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll n, m;
  cin >> n >> m;

  ll ans = 0;

  if (n > 0) {
    while (true) {
      if (m >= 2) {
        ans++;
        n--;
        m = m - 2;
      } else {
        break;
      }
      if (n == 0) {
        break;
      }
    }
  }

  if (m >= 4) {
    ans += m / 4;
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll n, m;
  cin >> n >> m;

  ll ans = 0;

  if (n > 0) {
    if (m >= 2) {
      ll tmp = min(n, m / 2);
      ans += tmp;
      m = m - 2 * tmp;
    }
  }

  if (m >= 4) {
    ans += m / 4;
  }

  cout << ans << endl;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <ctype.h>
#include <math.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for (int i = 0; i < n; i++)

int main() {
  long long n, m;
  cin >> n >> m;

  long long cnt = 0;
  while (1) {
    if (n > 0 and m > 1) {
      n -= 1;
      m -= 2;
      cnt++;
    } else
      break;
  }
  cnt = cnt + m / 4;

  cout << cnt << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <ctype.h>
#include <math.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for (int i = 0; i < n; i++)

int main() {
  long long n, m;
  cin >> n >> m;

  long long ans;
  if (2 * n <= m) {
    ans = n;
    m -= n * 2;
    ans += m / 4;
  } else
    ans = m / 2;
  cout << ans << endl;

  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

long long n, m;
long long ans = 0;
int main() {
  cin >> n;
  cin >> m;

  ans = min(n, m / 2);
  n -= ans;
  m -= ans * 2;
  while (n >= 0 and m >= 4) {
    m -= 4;
    ans += 1;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

long long n, m;
long long ans = 0;
int main() {
  cin >> n;
  cin >> m;

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

  cout << ans << endl;

  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long N;
  long M;
  long a = 0;

  cin >> M >> N;

  if (N / 2 < M) {
    a = N / 2;
  } else {
    while (N - M * 2 > 3) {
      N = N - 2;
      M++;
    }
    a = M;
  }
  cout << a << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long N;
  long M;
  long a = 0;

  cin >> M >> N;

  if (N / 2 < M) {
    a = N / 2;
  } else {
    if (N - M * 2 > 3) {
      M = M + (N - M * 2) / 4;
    }
    a = M;
  }
  cout << a << endl;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, m;
  cin >> n >> m;

  ll ans = 0;
  while (n-- && m >= 2) {
    ans++;
    m -= 2;
  }
  ans += m / 4;

  cout << ans << '\n';
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, m;
  cin >> n >> m;

  ll ans = 0;
  if (n * 2 <= m) {
    ans += n;
    m -= 2 * n;
  } else {
    ans += m / 2;
    m = 0;
  }
  ans += m / 4;

  cout << ans << '\n';
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  ll i = 0;
  for (i = n; 2 * i > m; i--)
    ;
  m -= 2 * i;
  cout << m / 4 + i;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  if (2 * n <= m) {
    m -= 2 * n;
  } else {
    n = m / 2;
    m = 0;
  }
  cout << m / 4 + n;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  long long n, m;
  cin >> n >> m;
  int ans = 0;
  while (true) {
    if (n >= 1 && m >= 2) {
      n--;
      m -= 2;
      ans++;
    } else {
      if (m >= 2) {
        m -= 2;
        n++;
      } else {
        break;
      }
    }
  }
  cout << ans;
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  long long s, c;
  cin >> s >> c;

  long scc = min(s, c / 2);
  long cccc = (c - 2 * scc) / 4;
  cout << scc + cccc << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int mx4[] = {0, 1, 0, -1};
int my4[] = {1, 0, -1, 0};

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0, k;
  for (int i = 0; i <= m; i += 2) {
    k = min(n + (i / 2), (m - i) / 2);
    ans = max(ans, k);
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int mx4[] = {0, 1, 0, -1};
int my4[] = {1, 0, -1, 0};

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main() {
  ll n, m;
  cin >> n >> m;
  if (m - n * 2 >= 0)
    cout << n + (m - n * 2) / 4 << endl;
  else
    cout << m / 2 << endl;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long n, m;
  cin >> n >> m;
  while (true) {

    if (n * 2 >= m) {
      cout << m / 2 << endl;
      return 0;
    }
    m -= 2;
    n++;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long n, m;
  cin >> n >> m;
  long t = max((m - 2 * n) / 4, (long)0);
  m -= 2 * t;
  n += t;
  while (true) {

    if (n * 2 >= m) {
      cout << m / 2 << endl;
      return 0;
    }
    m -= 2;
    n++;
  }
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;

int main() {
  ll n, m, t, tmp = 0;
  cin >> n >> m;
  while (n < m / 2) {
    n++;
    m -= 2;
  }
  cout << min(n, m / 2);
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;

int main() {
  ll n, m, t, tmp = 0;
  cin >> n >> m;
  if (n * 2 < m)
    tmp = (m - 2 * n) / 4;
  cout << min(n, m / 2) + tmp;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main(void) {
  long long s, c;
  long long result = 0;
  cin >> s >> c;

  while (s && c >= 2) {
    c -= 2;
    s--;
    result++;
  }

  while (c >= 4) {
    c -= 4;
    result++;
  }

  cout << result << endl;
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  long long s, c;
  long long result = 0;
  cin >> s >> c;

  if (s * 2 >= c) {
    result = c / 2;
  } else {
    result = s + (c - s * 2) / 4;
  }

  cout << result << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  long long int N, M;
  long long int result;
  long long int tmp_result;
  cin >> N >> M;
  result = (N < M / 2) ? N : M / 2;
  for (long long int i = 1; i <= M / 4; i++) {
    tmp_result = (N + i < (M - 2 * i) / 2) ? N + i : (M - 2 * i) / 2;
    result = (result > tmp_result) ? result : tmp_result;
  }
  cout << result << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long int N, M;
  long long int result;
  long long int tmp_result;
  cin >> N >> M;
  result = (N < M / 2) ? N : M / 2;
  M = M - 2 * result;
  if (M > 0)
    result = result + M / 4;
  cout << result << endl;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long s, c, n = 0;
  scanf("%lld %lld", &s, &c);
  for (;;)
    if (s < 0) {
      s++, c++, c++, n--;
      break;
    } else if (c < 0) {
      c++, c++, n--;
      cout << n << endl;
      return 0;
    } else
      s--, c--, c--, n++;
  cout << s + c / 4 + n << endl;
  return 0;
}

Fixed submission:
#include <cstdio>
long long n, m;
signed main() {
  return scanf("%lld%lld", &n, &m),
         printf("%lld\n", n > ((n << 1) + m) / 4 ? m >> 1 : ((n << 1) + m) / 4),
         0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m, i;
  cin >> n >> m;
  long long ans = 0;
  while (n >= 1 && m >= 2) {
    n--;
    m -= 2;
    ans++;
  }
  ans += m / 4;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m, i;
  cin >> n >> m;
  long long ans = 0;
  if (m > 2 * n) {
    ans += n;
    m -= 2 * n;
  } else {
    ans += m / 2;
    m = 0;
  }
  ans += m / 4;
  cout << ans << endl;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;
  long long ans = 0;
  while (n > 0 && m > 1) {
    ans++;
    n--;
    m -= 2;
  }
  while (m >= 4) {
    ans++;
    m -= 4;
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;
  long long ans = 0;
  if (2 * n > m) {
    ans = m / 2;
  } else {
    m = m - 2 * n;
    ans = n + m / 4;
  }
  cout << ans;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long c, s;
  cin >> s >> c;
  while (c / 2 > s) {
    c -= 2;
    s += 1;
  }
  if (c / 2 == s - 1 && c > s)
    cout << s - 1 << endl;
  else if (c < s)
    cout << c / 2 << endl;
  else if (c == s)
    cout << c / 2 << endl;
  else if (c / 2 < s)
    cout << c / 2 << endl;
  else
    cout << s << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long c, s;
  cin >> s >> c;
  if (c / 2 > s)
    s += (c / 2 - s) / 2;
  if (c / 2 == s - 1 && c > s)
    cout << s - 1 << endl;
  else if (c < s)
    cout << c / 2 << endl;
  else if (c == s)
    cout << c / 2 << endl;
  else if (c / 2 < s)
    cout << c / 2 << endl;
  else
    cout << s << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vll = vector<ll>;
using vi = vector<int>;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// pow(llpow,modpow)
template <class T> ll llpow(T x, T n) {
  ll ans = 1;
  if (x == 0)
    ans = 0;
  while (n) {
    if (n & 1)
      ans *= x;
    x *= x;
    n >>= 1;
  }
  return ans;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
// 最大公約数
template <class T> inline T gcd(T x, T y) {
  if (y == 0)
    return x;
  else {
    return gcd(y, x % y);
  }
}
// 最小公倍数
template <class T> inline T lcm(T x, T y) { return x / gcd(x, y) * y; }
// 逆元
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL << 60;
int main() {
  ll n, m;
  cin >> n >> m;
  ;
  ll cnt = 0;
  while (n > 0 && m - 2 >= 0) {
    n--;
    m -= 2;
    cnt++;
  }
  while (m - 4 >= 0) {
    m -= 4;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vll = vector<ll>;
using vi = vector<int>;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// pow(llpow,modpow)
template <class T> ll llpow(T x, T n) {
  ll ans = 1;
  if (x == 0)
    ans = 0;
  while (n) {
    if (n & 1)
      ans *= x;
    x *= x;
    n >>= 1;
  }
  return ans;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
// 最大公約数
template <class T> inline T gcd(T x, T y) {
  if (y == 0)
    return x;
  else {
    return gcd(y, x % y);
  }
}
// 最小公倍数
template <class T> inline T lcm(T x, T y) { return x / gcd(x, y) * y; }
// 逆元
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL << 60;
int main() {
  ll n, m;
  cin >> n >> m;
  ;
  ll cnt = 0;
  if (n >= m / 2) {
    cnt = m / 2;
  } else {
    cnt += n;
    m -= 2 * n;
    cnt += m / 4;
  }
  cout << cnt << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, M;
  cin >> N >> M;
  long long S = 0;
  while (M > 1) {
    if (N > 0) {
      N--;
      M -= 2;
      S++;
    } else {
      M -= 2;
      if (M >= 2) {
        M -= 2;
        S++;
      } else
        break;
    }
  }
  cout << S << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, M;
  cin >> N >> M;
  long long S = 0;
  if (N * 2 <= M) {
    long long L = M - N * 2;
    S += N + L / 4;
  } else {
    S += M / 2;
  }
  cout << S << endl;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
// インクルード
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

// 型宣言
typedef long long ll;
typedef unsigned long long ull;
typedef std::string string;
typedef ull answerType;

// 変数宣言
ll N;
ll M;
std::vector<string> Ai;
std::vector<string> Bi;
answerType answer;

// 関数のプロトタイプ宣言
// 入力の取得
void getInput();
// 答えを求める
answerType calcAnswer();

// メイン関数
int main() {
  // 入力の取得
  getInput();

  // 答え
  answerType answer = calcAnswer();

  // 答えの出力
  std::cout << answer << std::endl;

  // 正常終了
  return EXIT_SUCCESS;
}

// 入力の取得
void getInput() { std::cin >> N >> M; }

// 答えを求める
answerType calcAnswer() {
  ull temp = 0;
  ull N2 = N << 1;
  if (N2 <= M) {
    temp = N;
    M -= N2;
  } else {
    for (; N >= 1 && M >= 2; --N, -- --M, ++temp) {
    }
  }
  temp += M >> 2;
  return temp;
}


Fixed submission:
// インクルード
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

// 型宣言
typedef long long ll;
typedef unsigned long long ull;
typedef std::string string;
typedef ull answerType;

// 変数宣言
ll N;
ll M;
std::vector<string> Ai;
std::vector<string> Bi;
answerType answer;

// 関数のプロトタイプ宣言
// 入力の取得
void getInput();
// 答えを求める
answerType calcAnswer();

// メイン関数
int main() {
  // 入力の取得
  getInput();

  // 答え
  answerType answer = calcAnswer();

  // 答えの出力
  std::cout << answer << std::endl;

  // 正常終了
  return EXIT_SUCCESS;
}

// 入力の取得
void getInput() { std::cin >> N >> M; }

// 答えを求める
answerType calcAnswer() {
  ull temp = 0;
  ull N2 = N << 1;
  if (N2 <= M) {
    temp = N;
    M -= N2;
  } else {
    return M >> 1;
    //		for(; N>=1 && M>=2; --N,----M,++temp) {
    //		}
  }
  temp += M >> 2;
  return temp;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// max=({});
// 条件式が真ならwhileの中身を回し続ける
// printf("%d\n", ans);

// pairの入力
// vector<pair<ll, ll>>work(n);
// rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
// for(auto p:mp)(mapの探索)
// printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll x, ll y) {
  if (x == 0 || y == 0)
    return 0;
  return (x / gcd(x, y) * y);
}

// 素因数分解
vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
  ll n, m;
  cin >> n >> m;
  ll s = n;
  ll c = m;
  ll ans = 0;
  while (c >= 2 && s > 0) {
    s--;
    c -= 2;
    ans++;
  }
  ans += c / 4;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// max=({});
// 条件式が真ならwhileの中身を回し続ける
// printf("%d\n", ans);

// pairの入力
// vector<pair<ll, ll>>work(n);
// rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
// for(auto p:mp)(mapの探索)
// printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll x, ll y) {
  if (x == 0 || y == 0)
    return 0;
  return (x / gcd(x, y) * y);
}

// 素因数分解
vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
  ll n, m;
  cin >> n >> m;
  ll s = n;
  ll c = m;
  ll ans = min(s, c / 2);
  c -= ans * 2;
  ans += c / 4;
  cout << ans << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  while (n >= 1 && m >= 2) {
    n--;
    m -= 2;
    ans++;
  }
  ans += m / 4;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  if (n * 2 >= m) {
    ll temp = m / 2;
    n -= temp;
    m -= temp * 2;
    ans += temp;
  } else {
    ans += n;
    m -= n * 2;
  }
  ans += m / 4;
  cout << ans << endl;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;

  long long ans = 0;
  while (n >= 1 && m >= 2) {
    n--;
    m -= 2;
    ans++;
  }
  while (m >= 4) {
    m -= 4;
    ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;

  long long ans = min(n, m / 2);
  m -= ans * 2;
  ans += m / 4;
  cout << ans << endl;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  int ans = 0;
  while (1) {
    if (n >= 1 && m >= 2) {
      ans++;
      n--;
      m -= 2;
    } else if (n < 1 && m >= 4) {
      ans++;
      m -= 4;
    } else
      break;
  }
  cout << ans << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long ans = 0;
  if (2 * n <= m)
    ans = n + (m - 2 * n) / 4;
  else
    ans = m / 2;
  cout << ans << endl;
}
Problem p03797 (Python)

Buggy submission (status: Time Limit Exceeded):
n, m = map(int, input().split())
c = 0
while n > 0 and m > 2:
    n -= 1
    m -= 2
    c += 1

while m >= 4:
    m -= 4
    c += 1
print(c)


Fixed submission:
n, m = map(int, input().split())
if n <= m // 2:
    m -= n * 2
    print(n + m // 4)
else:
    print(m // 2)
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ll s, c;
  cin >> s >> c;
  ll res = 0;
  bool update = false;
  while (!update) {
    update = true;
    if (s > 0 && c > 1) {
      s--;
      c -= 2;
      res++;
      update = false;
    } else if (c > 3) {
      c -= 4;
      res++;
      update = false;
    }
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ll s, c;
  cin >> s >> c;
  ll res = 0;
  c /= 2;
  res = min(c, s + (c - s) / 2);
  cout << res << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define RFOR(i, a, b) for (long long i = (b - 1); i >= a; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<P> Graph;

int main() {
  ll N, M;
  cin >> N >> M;
  ll ans = 0;
  REP(i, N) {
    if (M < 2)
      break;
    ans++;
    M -= 2;
  }
  for (;;) {
    M -= 4;
    if (M >= 0)
      ans++;
    else
      break;
  }
  cout << fixed << ans << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define RFOR(i, a, b) for (long long i = (b - 1); i >= a; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<P> Graph;

int main() {
  ll N, M;
  cin >> N >> M;
  ll ans = 0;

  ans += min(M / 2, N);
  M -= 2 * N;
  ans += max((ll)0, M / 4);
  cout << fixed << ans << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
using namespace std;

int main() {
  ll n, m;
  ll ans = 0;
  cin >> n >> m;
  for (;;) {
    if (2 * n > m) {
      while (2 * n > m) {
        n--;
      }
      ans += n;
      break;
    } else {
      ans += n;
      m -= n * 2;
      ans += m / 4;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
using namespace std;

int main() {
  ll n, m;
  ll ans = 0;
  cin >> n >> m;
  if (2 * n > m) {
    ans += m / 2;
  } else {
    ans += n;
    m -= n * 2;
    ans += m / 4;
  }
  cout << ans << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  long int N, M, count = 0;
  cin >> N >> M;
  for (int i = 0; N >= 1 && M >= 2; ++i) {
    N -= 1;
    M -= 2;
    ++count;
  }
  if (N == 0 && M >= 4) {
    count += (M / 4);
  }
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long int N, M, count = 0;
  cin >> N >> M;
  if (N >= 1 && M >= 2) {
    if (N >= (M / 2)) {
      count += (M / 2);
      N -= (M / 2);
      M -= 2 * (M / 2);
    } else {
      count += N;
      M -= (2 * N);
      N = 0;
    }
  }
  if (N == 0 && M >= 4) {
    count += (M / 4);
  }
  cout << count << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  long long int ans = 0, s, c;
  cin >> s >> c;
  while (s > 0 && c > 1) {
    ans++;
    s--;
    c -= 2;
  }
  while (c > 3) {
    ans++;
    c -= 4;
  }
  cout << ans << "\n";
  cin >> s;
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  long long int ans = 0, s, c;
  cin >> s >> c;
  if (s <= c / 2) {
    ans += s;
    c -= 2 * s;
    ans += c / 4;
  } else {
    ans += c / 2;
  }
  cout << ans << "\n";
  cin >> s;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
ll n, m, ans;
int main() {
  scanf("%lld %lld", &n, &m);
  ans = 0;
  for (int i = 0; i <= m / 2; i++)
    ans = max(ans, min(n + i, (m - i * 2) / 2));
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
ll n, m, ans;
int main() {
  scanf("%lld %lld", &n, &m);
  if (m / 2 >= n)
    ans = n + (m - n * 2) / 4;
  else
    ans = m / 2;
  printf("%lld\n", ans);
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
unsigned long long n, m, i;
int main() {
  scanf("%llu %llu", &n, &m);
  while (n > 0 && m > 1) {
    n--;
    m -= 2;
    i++;
  }
  i += m / 4;
  printf("%llu", i);
}


Fixed submission:
#include <cstdio>
unsigned long long n, m, i;
int main() {
  scanf("%llu %llu", &n, &m);
  if (n <= m / 2) {
    m -= n * 2;
    i += n;
  } else {
    i += m / 2;
    m = 0;
  }
  i += m / 4;
  printf("%llu", i);
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#define ll long long
int main() {
  ll n, m, cnt = 0;
  scanf("%lld%lld", &n, &m);
  while (n) {
    n--;
    if (m >= 2)
      m -= 2;
    else
      break;
    cnt++;
  }
  cnt += m / 4;
  printf("%lld", cnt);
  return 0;
}


Fixed submission:
#include <cstdio>
#define ll long long
int main() {
  ll n, m, cnt = 0;
  scanf("%lld%lld", &n, &m);
  int t = m / 2;
  if (t > n) {
    cnt += n;
    m -= 2 * n;
    cnt += m / 4;
  } else if (t == n)
    cnt += n;
  else
    cnt += m / 2;
  printf("%lld", cnt);
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i, a, b) for (int i = a, almo5t = b; i < almo5t; ++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN                                                                    \
  std::ios_base::sync_with_stdio(false);                                       \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

ll solve(ll n, ll m) {
  if (n * 2 >= m) {
    return m / 2;
  } else {
    return n + (m - n * 2) / 4;
  }
}

int main() {
  FIN;
#ifndef ONLINE_JUDGE
  freopen("../in.txt", "r", stdin);
  freopen("../out.txt", "w", stdout);
#endif
  ll n, m;
  cin >> n >> m;
  ll out = solve(n, m);
  cout << out;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i, a, b) for (int i = a, almo5t = b; i < almo5t; ++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN                                                                    \
  std::ios_base::sync_with_stdio(false);                                       \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

ll solve(ll n, ll m) {
  if (n * 2 >= m) {
    return m / 2;
  } else {
    return n + (m - n * 2) / 4;
  }
}

int main() {
  ll n, m;
  cin >> n >> m;
  ll out = solve(n, m);
  cout << out;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
const ll LINF = 0x1fffffffffffffff;
const int INF = 0x3fffffff;
const int MOD = 1000000007;
#define VAR(type, ...)                                                         \
  type __VA_ARGS__;                                                            \
  in(__VA_ARGS__)
#define VEC(type, name, size)                                                  \
  vector<type> name(size);                                                     \
  each(x, name) in(x)
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, a, b) for (int i = (a - 1); i >= (b); --i)
#define each(x, v) for (auto &x : (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl
void in() {}
template <class T, class... U> void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}
void solve();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  solve();
}

void solve() {
  VAR(ll, N, M);
  ll cnt = min(M / 2, N);
  M -= cnt * 2;
  N -= cnt;
  ll ans = cnt;
  while (N > -1 && M > 1) {
    if (N == 0) {
      M -= 2;
      N += 1;
      continue;
    }
    M -= 2;
    N -= 1;
    ans++;
  }
  print(ans);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
const ll LINF = 0x1fffffffffffffff;
const int INF = 0x3fffffff;
const int MOD = 1000000007;
#define VAR(type, ...)                                                         \
  type __VA_ARGS__;                                                            \
  in(__VA_ARGS__)
#define VEC(type, name, size)                                                  \
  vector<type> name(size);                                                     \
  each(x, name) in(x)
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, a, b) for (int i = (a - 1); i >= (b); --i)
#define each(x, v) for (auto &x : (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl
void in() {}
template <class T, class... U> void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}
void solve();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  solve();
}

void solve() {
  VAR(ll, N, M);
  ll cnt = min(M / 2, N);
  M -= cnt * 2;
  print(cnt + M / 4);
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int n, m;
  scanf("%lld %lld", &n, &m);
  long long int ans;
  while (m > 2 * n) {
    m -= 2;
    ++n;
  }
  if (m >= 2 * n)
    ans = n;
  else
    ans = floor(m / 2);
  printf("%lld\n", ans);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int n, m;
  scanf("%lld %lld", &n, &m);
  long long int ans;
  long long int i = 0;
  if (m > 2 * n)
    i = floor((m - 2 * n) / 4.0);
  n += i;
  m -= 2 * i;
  if (m >= 2 * n)
    ans = n;
  else
    ans = floor(m / 2);
  printf("%lld\n", ans);

  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
#define ff(i, n, m) for (int i = n; i < m; i++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
  i64 n, m;
  cin >> n >> m;
  i64 ans = 0;
  while (n >= 1 && m >= 2) {
    n--;
    m--;
    m--;
    ans++;
  }
  while (m >= 4) {
    m -= 4;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
#define ff(i, n, m) for (int i = n; i < m; i++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
  i64 n, m;
  cin >> n >> m;
  i64 ans = 0;
  if (2 * n >= m) {
    ans = m / 2;
  } else {
    ans = n;
    m -= 2 * ans;
    ans += m / 4;
  }
  cout << ans << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define ll long long
using namespace std;

int main() {
  ll s, c;
  cin >> s >> c;

  int ans = 0;
  while (c >= 2) {
    if (s > 0) {
      c -= 2;
      s -= 1;
      ans++;
    } else {
      if (c >= 4) {
        c -= 4;
        ans++;
      } else {
        break;
      }
    }
  }

  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define ll long long
using namespace std;

int main() {
  ll s, c;
  cin >> s >> c;

  ll ans = 0;
  ll t = c / 2;

  if (s > t) {
    cout << t;
    return 0;
  } else {
    ans += s;
    c -= (s * 2);
    ans += (c / 4);
  }

  cout << ans;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
int main(void) {
  long long int N, M;
  std::cin >> N >> M;
  long long int ans = 0;
  while (N > 0 && M > 0) {
    if (M == 1)
      break;
    N -= 1;
    M -= 2;
    ans++;
  }
  if (M >= 0) {
    ans += M / 4;
  }
  printf("%lld", ans);
}

Fixed submission:
#include <iostream>
#include <stdio.h>
int main(void) {
  long long int N, M;
  std::cin >> N >> M;
  long long int ans = 0;
  if (M <= N) {
    ans += M / 2;
    printf("%lld", ans);
    return 0;
  }
  if (M - 2 * N >= 0) {
    ans += N;
    M -= 2 * N;
  } else {
    ans += 2 * N - M;
    M -= 2 * (2 * N - M);
  }
  if (M >= 0) {
    ans += M / 4;
  }
  printf("%lld", ans);
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
int main() {
  ll n, m;
  cin >> n >> m;

  ll ans = 0;
  while (n >= 1 && m >= 2) {
    ans++;
    n--;
    m -= 2;
  }
  while (m >= 4) {
    ans++;
    m -= 4;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
int main() {
  ll n, m;
  cin >> n >> m;

  ll ans = 0;
  ans += min(n, m / 2);
  if ((m - 2 * n) / 4 >= 0)
    ans += (m - 2 * n) / 4;
  cout << ans << endl;
}
Problem p03797 (Python)

Buggy submission (status: Time Limit Exceeded):
N, M = map(int, input().split())

ans = 0

while True:
    if N >= 1 and M >= 2:
        N -= 1
        M -= 2
        ans += 1
    elif M >= 4:
        M -= 4
        ans += 1
    else:
        break
print(ans)


Fixed submission:
N, M = map(int, input().split())

ans = 0

ans += min(N, M // 2)

N -= ans
M -= ans * 2

ans += M // 4

print(ans)
Problem p03797 (Python)

Buggy submission (status: Time Limit Exceeded):
n, m = map(int, input().split())
comb = 0

while m >= 2 and n >= 1:
    comb += 1
    m -= 2
    n -= 1

comb += m // 4

print(comb)


Fixed submission:
n, m = map(int, input().split())
comb = 0

if 2 * n >= m:
    comb += m // 2
    m -= comb * 2
else:
    comb += n
    m -= 2 * n

comb += m // 4

print(comb)
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  if (2 * n > m) {
    cout << m / 2;
    system("pause");
    return 0;
  }
  while (2 * n < m) {
    n += 1;
    m -= 2;
    if (2 * n > m) {
      cout << n - 1;
      system("pause");
      return 0;
    }
  }
  cout << n;
  system("pause");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  if (2 * n > m) {
    cout << m / 2;
    system("pause");
    return 0;
  }
  cout << n + (m - 2 * n) / 4;
  system("pause");
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int, int>;
using pq = priority_queue<int>;
typedef long long ll;
typedef long double ld;
#define pi 3.14159265358979

int main() {
  long n, m;
  cin >> n >> m;
  long sum = 0;
  while (n > 0 && m > 1) {
    if (n > 0 && m > 1) {
      n--;
      m -= 2;
      sum++;
    }
  }
  while (m > 3) {
    if (m > 3) {
      m -= 4;
      sum++;
    }
  }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int, int>;
using pq = priority_queue<int>;
typedef long long ll;
typedef long double ld;
#define pi 3.14159265358979

int main() {
  long n, m;
  cin >> n >> m;
  long sum = 0;
  if (n * 2 <= m) {
    m -= (n * 2);
    sum += n;
    sum += m / 4;
  } else {
    if (n >= (m / 2)) {
      sum += (m / 2);
    } else {
      sum += n;
      m -= (2 * n);
      sum += m / 4;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define INF 9999999999

int main() {
  ll n, m, ans = 0;
  cin >> n >> m;
  if (n >= (m / 2)) {
    ans = n / (m / 2);
  } else {
    ans = n;
    m -= 2 * n;
    ans += m / 4;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define INF 9999999999

int main() {
  ll n, m, ans = 0;
  cin >> n >> m;
  if (n >= (m / 2)) {
    ans = m / 2;
  } else {
    ans = n;
    m -= 2 * n;
    ans += m / 4;
  }
  cout << ans << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  ll cnt = 0;
  while (1) {
    if (n >= 1 && m >= 2) {
      n--, m -= 2, cnt++;
    } else if (n == 0 && m >= 2) {
      n++, m -= 2;
      continue;
    } else
      break;
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  if (n * 2 < m)
    cout << n + (m - 2 * n) / 4 << endl;
  else
    cout << m / 2 << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

typedef long long int lli;

int main(int argc, char const *argv[]) {
  lli n, m, ans = 0;
  cin >> n >> m;
  while (m > 1) {
    if (n != 0) {
      n--;
      m -= 2;
      ans++;
    } else {
      if (m >= 4) {
        m -= 4;
        ans++;
      } else
        break;
    }
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

typedef long long int lli;

int main(int argc, char const *argv[]) {
  lli n, m, ans = 0;
  cin >> n >> m;

  if (m >= 2 * n) {
    ans += n;
    m -= 2 * n;
    n = 0;
  } else {
    ans += m / 2;
    n -= m / 2;
    m -= ((m + 1) / 2) * 2;
  }
  if (n == 0 and m >= 4) {
    ans += m / 4;
    m = 0;
  }

  cout << ans << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m, c = 0;
  cin >> n >> m;
  while (m >= 2 && n >= 1) {
    c++;
    m -= 2;
    n -= 1;
  }
  while (m >= 4) {
    c++;
    m -= 4;
  }
  cout << c;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m, c = 0;
  cin >> n >> m;
  if (m >= n * 2) {
    c += n;
    m -= n * 2;
    c += m / 4;
  } else {
    c += m / 2;
  }
  cout << c;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;

int main() {
  ll S, c, ans = 0;
  cin >> S >> c;
  while (1) {
    if (S >= 1 && c >= 2) {
      S -= 1;
      c -= 2;
      ans += 1;
    } else if (c >= 4) {
      c -= 4;
      ans += 1;
    } else {
      cout << ans << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;

int main() {
  ll S, c, ans = 0;
  cin >> S >> c;
  if (S * 2 <= c) {
    ans += S;
    c -= 2 * S;
    ans += c / 4;
    cout << ans << endl;
  } else
    cout << c / 2 << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  if (m / 2 >= n) {
    while (m / 2 > n) {
      m -= 2;
      n++;
    }
  }
  ans = m / 2;
  cout << ans << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  ll ans = min(n, m / 2);
  if (m - 2 * ans >= 4)
    ans += (m - 2 * ans) / 4;
  cout << ans << '\n';
  return 0;
}