Problem p02957 (C++)

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

using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(), (x).end()

template <typename T> void print_vec(vector<T> a) {
  int n = a.size();
  REP(i, n) {
    cout >> a[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << endl;
  }
}
ll power(ll base, ll exponent) {
  if (exponent % 2) {
    return power(base, exponent - 1) * base % mod;
  } else if (exponent) {
    ll root_ans = power(base, exponent / 2);
    return root_ans * root_ans % mod;
  } else {
    return 1;
  }
}
ll inverse(ll x) { return power(x, mod - 2); }
ll gcd(ll a, ll b) {
  if (a < b)
    gcd(b, a);
  ll r;
  while (r = a % b) {
    a = b;
    b = r;
  }
  return b;
}
template <typename T> ll sum(T begin, T end) {
  return accumulate(begin, end, 0ll);
}
struct combination {
  vector<ll> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1) {
    fact[0] = 1;
    for (int i = 1; i <= sz; i++) {
      fact[i] = fact[i - 1] * i % mod;
    }
    inv[sz] = power(fact[sz], mod - 2);
    for (int i = sz - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % mod;
    }
  }
  ll C(int p, int q) const {
    if (q < 0 || p < q)
      return 0;
    return (fact[p] * inv[q] % mod * inv[p - q] % mod);
  }
};

int bsearch(const vector<ll> &a, ll x) {
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if (a[mid] < x) {
      lft = mid;
    } else {
      rgt = mid;
    }
  }
  return lft;
}

signed main() {
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  ll c = 1e9 + 1;
  REP_FROM(k, -c, c) {
    if (abs(a - k) == abs(b - k)) {
      cout << k << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(), (x).end()

template <typename T> void print_vec(vector<T> a) {
  int n = a.size();
  REP(i, n) {
    cout >> a[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << endl;
  }
}
ll power(ll base, ll exponent) {
  if (exponent % 2) {
    return power(base, exponent - 1) * base % mod;
  } else if (exponent) {
    ll root_ans = power(base, exponent / 2);
    return root_ans * root_ans % mod;
  } else {
    return 1;
  }
}
ll inverse(ll x) { return power(x, mod - 2); }
ll gcd(ll a, ll b) {
  if (a < b)
    gcd(b, a);
  ll r;
  while (r = a % b) {
    a = b;
    b = r;
  }
  return b;
}
template <typename T> ll sum(T begin, T end) {
  return accumulate(begin, end, 0ll);
}
struct combination {
  vector<ll> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1) {
    fact[0] = 1;
    for (int i = 1; i <= sz; i++) {
      fact[i] = fact[i - 1] * i % mod;
    }
    inv[sz] = power(fact[sz], mod - 2);
    for (int i = sz - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % mod;
    }
  }
  ll C(int p, int q) const {
    if (q < 0 || p < q)
      return 0;
    return (fact[p] * inv[q] % mod * inv[p - q] % mod);
  }
};

int bsearch(const vector<ll> &a, ll x) {
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if (a[mid] < x) {
      lft = mid;
    } else {
      rgt = mid;
    }
  }
  return lft;
}

signed main() {
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  ll c = 1e9 + 1;
  REP(k, c) {
    if (abs(a - k) == abs(b - k)) {
      cout << k << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}