prithivMLmods/Coder-Stat huggingface dataset:
Problem p03557 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vbo = vector<bool>;
using vvbo = vector<vector<bool>>;
using vpii = vector<pair<int, int>>;
using pqsin = priority_queue<int, vector<int>, greater<int>>;
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define decp(n) cout << fixed << setprecision((int)n)
const int inf = 1e9 + 7;
const ll INF = 1e18;

int main() {
  int n;
  cin >> n;
  vin a(n), b(n + 1), c(n + 1);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];
  b[n] = inf;
  c[n] = inf;
  sort(all(b));
  sort(all(c));
  map<int, int> numb;
  numb[b[0]] = n;
  map<int, int> numc;
  numc[c[0]] = n;
  rep2(i, 1, n) if (b[i] != b[i - 1]) numb[b[i]] = n - i;
  rep2(i, 1, n) if (c[i] != c[i - 1]) numc[c[i]] = n - i;
  map<int, ll> btoc;
  ll tmp = 0;
  for (int i = n - 1; i >= 0; i--) {
    btoc[b[i]] = tmp + (ll)numc[*upper_bound(all(c), b[i])];
    tmp = btoc[b[i]];
  }
  ll sum = 0;
  rep(i, n) sum += btoc[*upper_bound(all(b), a[i])];
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vbo = vector<bool>;
using vvbo = vector<vector<bool>>;
using vpii = vector<pair<int, int>>;
using pqsin = priority_queue<int, vector<int>, greater<int>>;
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define decp(n) cout << fixed << setprecision((int)n)
const int inf = 1e9 + 7;
const ll INF = 1e18;

int main() {
  int n;
  cin >> n;
  vin a(n), b(n + 1), c(n + 1);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];
  b[n] = inf;
  c[n] = inf;
  sort(all(b));
  sort(all(c));
  map<int, int> numb;
  numb[b[0]] = n;
  map<int, int> numc;
  numc[c[0]] = n;
  rep2(i, 1, n) if (b[i] != b[i - 1]) numb[b[i]] = n - i;
  rep2(i, 1, n) if (c[i] != c[i - 1]) numc[c[i]] = n - i;
  map<int, ll> btoc;
  ll tmp = 0;
  for (int i = n - 1; i >= 0; i--) {
    btoc[b[i]] = tmp + (ll)numc[*upper_bound(all(c), b[i])];
    tmp = btoc[b[i]];
  }
  ll sum = 0;
  rep(i, n) sum += btoc[*upper_bound(all(b), a[i])];
  cout << sum << endl;
}
Problem p03557 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 1 << 30; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, 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;
}
// ミョ(-ω- ?)
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n, 0);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  vector<ll> b(n, 0);
  rep(i, n) cin >> b[i];
  sort(b.begin(), b.end());
  vector<ll> c(n, 0);
  rep(i, n) cin >> c[i];
  sort(c.begin(), c.end());
  ll res = 0;
  rep(i, n) {
    ll lo = distance(b.begin(), upper_bound(b.begin(), b.end(), a[i]));
    for (ll j = lo; j < n; j++) {
      res += distance(upper_bound(c.begin(), c.end(), b[j]), c.end());
    }
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 1 << 30; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, 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;
}
// ミョ(-ω- ?)
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n, 0);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  vector<ll> b(n, 0);
  rep(i, n) cin >> b[i];
  sort(b.begin(), b.end());
  vector<ll> c(n, 0);
  rep(i, n) cin >> c[i];
  sort(c.begin(), c.end());
  ll res = 0;
  rep(j, n) {
    res += (lower_bound(a.begin(), a.end(), b[j]) - a.begin()) *
           (c.end() - upper_bound(c.begin(), c.end(), b[j]));
  }
  cout << res << endl;
  return 0;
}
Problem p03557 (C++)

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

// AtCoder ABC 77

using namespace std;

#define int long long
#define all(m) m.begin(), m.end()
#define all_mas(m)                                                             \
  for (auto &i : m)                                                            \
    cout << i << " ";                                                          \
  cout << endl;
#define fast ios::sync_with_stdio(0), cin.tie(), cout.tie()

signed main() {
  int n;
  cin >> n;
  vector<int> a(n), b = a, c = a;
  for (auto &i : a)
    cin >> i;
  for (auto &i : b)
    cin >> i;
  for (auto &i : c)
    cin >> i;
  sort(all(a));
  sort(all(b));
  sort(all(c));
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int pos2 = upper_bound(all(b), a[i]) - b.begin();
    for (int j = pos2; j < n; ++j) {
      int pos3 = upper_bound(all(c), b[j]) - c.begin();
      // cout << ans << ' ' << pos2 << ' ' << pos3 << endl;
      ans += (n - pos3);
    }
  }
  cout << ans;
  return 0;
}


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

// AtCoder ABC 77

using namespace std;

#define int long long
#define all(m) m.begin(), m.end()
#define all_mas(m)                                                             \
  for (auto &i : m)                                                            \
    cout << i << " ";                                                          \
  cout << endl;
#define fast ios::sync_with_stdio(0), cin.tie(), cout.tie()

signed main() {
  int n;
  cin >> n;
  vector<int> a(n), b = a, c = a;
  for (auto &i : a)
    cin >> i;
  for (auto &i : b)
    cin >> i;
  for (auto &i : c)
    cin >> i;
  sort(all(a));
  sort(all(b));
  sort(all(c));
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int pos1 = lower_bound(all(a), b[i]) - a.begin();
    int pos3 = upper_bound(all(c), b[i]) - c.begin();
    // cout << pos1 << ' ' << pos3 << endl;
    ans += (n - pos3) * (pos1);
  }
  cout << ans;
  return 0;
}
Problem p03557 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  int N;
  int A[100000], B[100000], C[100000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }
  sort(A, A + N);
  sort(B, B + N);
  sort(C, C + N);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    int *mid = upper_bound(B, B + N, A[i]);
    int idx = distance(B, mid);
    for (int j = idx; j < N; j++) {
      int *mid_ = upper_bound(C, C + N, B[j]);
      int idx_ = distance(C, mid_);
      ans += (N - idx_);
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  int N;
  int A[100000], B[100000], C[100000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }
  sort(A, A + N);
  sort(B, B + N);
  sort(C, C + N);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    int *mid = lower_bound(A, A + N, B[i]);
    ll idx = distance(A, mid);
    int *mid_ = upper_bound(C, C + N, B[i]);
    ll idx_ = distance(C, mid_);
    ans += idx * (N - idx_);
  }
  cout << ans << endl;
}
Problem p03557 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N), D(N), E(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
  }
  for (int i = 0; i < N; i++) {
    int d = B.at(i);
    for (int j = 0; j < N; j++) {
      if (d > A.at(j))
        D.at(i)++;
      if (d < C.at(j))
        E.at(i)++;
    }
  }
  long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += D.at(i) * E.at(i);
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n), b(n), c(n);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  for (int i = 0; i < n; i++)
    cin >> b.at(i);
  for (int i = 0; i < n; i++)
    cin >> c.at(i);
  sort(a.begin(), a.end());
  sort(c.begin(), c.end());
  long long ans = 0, p, q;
  for (int i = 0; i < n; i++) {
    long long x = b.at(i);
    p = lower_bound(a.begin(), a.end(), x) - a.begin();
    q = c.begin() + n - upper_bound(c.begin(), c.end(), x);
    ans += p * q;
  }
  cout << ans << endl;
}
Problem p03557 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < N; i++)
    cin >> B[i];
  for (int i = 0; i < N; i++)
    cin >> C[i];

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    auto biter = upper_bound(B.begin(), B.end(), A[i]);
    for (auto iter = biter; iter != B.end(); iter++) {
      ans += (C.end() - upper_bound(C.begin(), C.end(), *iter));
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < N; i++)
    cin >> B[i];
  for (int i = 0; i < N; i++)
    cin >> C[i];

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += (lower_bound(A.begin(), A.end(), B[i]) - A.begin()) *
           (C.end() - upper_bound(C.begin(), C.end(), B[i]));
  }
  cout << ans << endl;
}
Problem p03557 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ac = 0, bc = 0, cc = 0;
  cin >> n;
  long long cnt = 0;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int i = 0; i < n; i++)
    cin >> c[i];
  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());
  sort(c.begin(), c.end(), greater<int>());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i] >= b[j])
        break;
      for (int k = 0; k < n; k++) {
        if (b[j] >= c[k])
          break;
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ac = 0, bc = 0, cc = 0;
  cin >> n;
  long long cnt = 0;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int i = 0; i < n; i++)
    cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  for (int i = 0; i < n; i++)
    cnt += (lower_bound(a.begin(), a.end(), b[i]) - a.begin()) *
           (c.size() - (upper_bound(c.begin(), c.end(), b[i]) - c.begin()));
  cout << cnt << endl;
  return 0;
}
Problem p03557 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<vector<int64_t>> a(3, vector<int64_t>(N));
  rep(k, 3) rep(i, N) cin >> a[k][i];
  rep(k, 3) sort(a[k].begin(), a[k].end());
  a[0].push_back(1LL << 55);
  a[1].push_back(1LL << 55);

  vector<int> bsum(a[1].size() - 1);
  rep(i, a[1].size()) {
    auto iter = lower_bound(a[0].begin(), a[0].end(), a[1][i]);
    bsum[i] = iter - a[0].begin();
    if (i) {
      bsum[i] += bsum[i - 1];
    }
  }

  int64_t ans = 0;
  rep(i, a[2].size()) {
    auto iter = lower_bound(a[1].begin(), a[1].end(), a[2][i]);
    auto size = iter - a[1].begin();
    if (size) {
      ans += bsum[size - 1];
    }
  }

  cout << ans << endl;
}


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

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<vector<int64_t>> a(3, vector<int64_t>(N));
  rep(k, 3) rep(i, N) cin >> a[k][i];
  rep(k, 3) sort(a[k].begin(), a[k].end());
  a[0].push_back(1LL << 55);
  a[1].push_back(1LL << 55);

  vector<int64_t> bsum(a[1].size() - 1);
  rep(i, a[1].size() - 1) {
    auto iter = lower_bound(a[0].begin(), a[0].end(), a[1][i]);
    bsum[i] = iter - a[0].begin();
    if (i) {
      bsum[i] += bsum[i - 1];
    }
  }

  int64_t ans = 0;
  rep(i, a[2].size()) {
    auto iter = lower_bound(a[1].begin(), a[1].end(), a[2][i]);
    auto size = iter - a[1].begin();
    if (size) {
      ans += bsum[size - 1];
    }
  }

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

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

int main() {
  int n;
  ll ans = 0;
  cin >> n;
  vector<vector<ll>> a(3, vector<ll>(n));
  rep(i, 3) {
    rep(j, n) { cin >> a[i][j]; }
  }
  sort(a[0].begin(), a[0].end());
  sort(a[1].begin(), a[1].end());
  sort(a[2].begin(), a[2].end());
  for (int i = 0; i < n; ++i) {
    auto cent = upper_bound(a[1].begin(), a[1].end(), a[0][i]);
    for (auto j = cent; j < a[1].end(); ++j) {
      if (*j < a[0][i])
        break;
      auto und = upper_bound(a[2].begin(), a[2].end(), *j);
      for (auto k = und; k < a[2].end(); ++k) {
        if (a[0][i] < *j && *j < *k) {
          ans++;
        } else
          break;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  ll ans = 0;
  cin >> n;
  vector<vector<ll>> a(3, vector<ll>(n));
  rep(i, 3) {
    rep(j, n) { cin >> a[i][j]; }
  }
  sort(a[0].begin(), a[0].end());
  sort(a[1].begin(), a[1].end());
  sort(a[2].begin(), a[2].end());
  rep(i, n) {
    auto und = lower_bound(a[0].begin(), a[0].end(), a[1][i]) - 1;
    auto hed = upper_bound(a[2].begin(), a[2].end(), a[1][i]);
    ans += (und - a[0].begin() + 1) * (a[2].end() - hed);
  }
  cout << ans << endl;
}
Problem p03557 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  rep(i, N) cin >> A.at(i);
  rep(i, N) cin >> B.at(i);
  rep(i, N) cin >> C.at(i);
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  int res = 0;
  rep(i, C.size()) {
    rep(j, B.size()) {
      if (C.at(i) <= B.at(j))
        break;
      rep(k, A.size()) {
        if (B.at(j) <= A.at(k))
          break;
        else
          res++;
      }
    }
  }
  cout << res << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  rep(i, N) cin >> A.at(i);
  rep(i, N) cin >> B.at(i);
  rep(i, N) cin >> C.at(i);
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  /*
  rep(i, N) cout << A[i] << " "; cout << endl;
  rep(i, N) cout << B[i] << " "; cout << endl;
  rep(i, N) cout << C[i] << " "; cout << endl;
  */
  ll res = 0;
  for (int j = 0; j < N; j++) {
    if (B.at(j) <= A[0])
      continue;
    auto x = lower_bound(A.begin(), A.end(), B.at(j));
    x--;
    ll n = x - A.begin() + 1;
    auto y = upper_bound(C.begin(), C.end(), B.at(j));
    if (y == C.end())
      continue;
    ll m = N - (y - C.begin());
    res += n * m;
    // cout << n << endl;
    // cout << m << endl;
  }
  cout << res << endl;
}
Problem p03557 (C++)

Buggy submission (status: Time Limit Exceeded):
// https://atcoder.jp/contests/abc077/tasks/arc084_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  REP(i, N) cin >> C[i];
  sort(ALL(A));
  sort(ALL(B));
  sort(ALL(C));

  int ans = 0;
  REP(i, N) {
    auto it1 = upper_bound(ALL(B), A[i]);
    int idx1 = distance(B.begin(), it1);
    FOR(j, idx1, N) {
      auto it2 = upper_bound(ALL(C), B[j]);
      int idx2 = distance(C.begin(), it2);
      ans += (N - idx2);
    }
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
// https://atcoder.jp/contests/abc077/tasks/arc084_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  REP(i, N) cin >> C[i];
  sort(ALL(A));
  sort(ALL(B));
  sort(ALL(C));

  int ans = 0;
  for (auto &x : B) {
    // 配列Aからxより小さい値を探す
    auto ia = lower_bound(ALL(A), x);
    int a = ia - A.begin();
    // 配列Cからxより大きい値を探す
    auto ic = lower_bound(ALL(C), x + 1);
    int c = C.end() - ic;
    ans += a * c;
  }
  cout << ans << endl;

  return 0;
}
Problem p03557 (C++)

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

typedef long long ll;

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

int main() {
  int N;
  cin >> N;

  vector<int> A(N), B(N), C(N);
  rep(i, N) cin >> A.at(i);
  rep(i, N) cin >> B.at(i);
  rep(i, N) cin >> C.at(i);

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  int num = 0;
  for (auto itr = A.begin(); itr != A.end(); itr++) {
    int b_num = 0;
    int c_num = 0;
    auto itr_b = upper_bound(B.begin(), B.end(), *itr);
    if (itr_b != B.end()) {
      b_num = B.end() - itr_b;
      for (auto itr2 = itr_b; itr2 != B.end(); itr2++) {
        auto itr_c = upper_bound(C.begin(), C.end(), *itr2);
        if (itr_c != C.end()) {
          c_num = C.end() - itr_c;
          num += c_num;
        }
      }
    }
  }
  cout << num << endl;
  return 0;
}


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

typedef long long ll;

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

int main() {
  int N;
  cin >> N;

  vector<int> A(N), B(N), C(N);
  rep(i, N) cin >> A.at(i);
  rep(i, N) cin >> B.at(i);
  rep(i, N) cin >> C.at(i);

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  ll num = 0;
  for (auto itr = B.begin(); itr != B.end(); itr++) {
    ll a_num = 0;
    ll c_num = 0;
    auto itr_a = lower_bound(A.begin(), A.end(), *itr);
    auto itr_c = upper_bound(C.begin(), C.end(), *itr);
    a_num = itr_a - A.begin();
    if (itr_c != C.end())
      c_num = C.end() - itr_c;
    num += a_num * c_num;
  }
  cout << num << endl;
  return 0;
}
Problem p03557 (C++)

Buggy submission (status: Time Limit Exceeded):
typedef long long llong;

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

int main(void) {
  int n;
  cin >> n;
  vector<llong> A(n), B(n), C(n);
  for (int i = 0; i < n; i++)
    scanf("%lld", &A[i]);
  for (int i = 0; i < n; i++)
    scanf("%lld", &B[i]);
  for (int i = 0; i < n; i++)
    scanf("%lld", &C[i]);

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  llong res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (A[i] < B[j] && B[j] < C[k])
          res++;
      }
    }
  }

  cout << res << endl;

  return 0;
}

Fixed submission:
typedef long long llong;

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

int main(void) {
  int n;
  cin >> n;
  vector<llong> A(n), B(n), C(n);
  for (int i = 0; i < n; i++)
    scanf("%lld", &A[i]);
  for (int i = 0; i < n; i++)
    scanf("%lld", &B[i]);
  for (int i = 0; i < n; i++)
    scanf("%lld", &C[i]);

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  llong res = 0;
  for (int j = 0; j < n; j++) {
    llong key = B[j];
    llong low_pos = (lower_bound(A.begin(), A.end(), key) == A.end()
                         ? A.size()
                         : lower_bound(A.begin(), A.end(), key) - A.begin());
    llong up_pos = (upper_bound(C.begin(), C.end(), key) == C.end()
                        ? C.size()
                        : upper_bound(C.begin(), C.end(), key) - C.begin());
    res += low_pos * (n - up_pos);
  }

  cout << res << endl;

  return 0;
}
Problem p03557 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B(N), C(N);
  for (ll i = 0; i < N; ++i)
    cin >> A[i];
  for (ll i = 0; i < N; ++i)
    cin >> B[i];
  for (ll i = 0; i < N; ++i)
    cin >> C[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    auto itrB = lower_bound(B.begin(), B.end(), A[i] + 1);
    for (auto j = itrB; j != B.end(); ++j) {
      auto itrC = lower_bound(C.begin(), C.end(), *j + 1);
      ans += distance(itrC, C.end());
    }
  }
  cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B(N), C(N);
  for (ll i = 0; i < N; ++i)
    cin >> A[i];
  for (ll i = 0; i < N; ++i)
    cin >> B[i];
  for (ll i = 0; i < N; ++i)
    cin >> C[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    auto itrA = lower_bound(A.begin(), A.end(), B[i]);
    auto itrC = lower_bound(C.begin(), C.end(), B[i] + 1);
    ans += (N - distance(itrA, A.end())) * distance(itrC, C.end());
  }
  cout << ans << endl;
}
Problem p03557 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < N; i++)
    cin >> B[i];
  for (int i = 0; i < N; i++)
    cin >> C[i];

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  ll ans = 0;

  for (int i = 0; i < N; i++) {
    int t = upper_bound(B.begin(), B.end(), A[i]) - B.begin();
    for (int j = t; j < N; j++) {
      ans += C.end() - upper_bound(C.begin(), C.end(), B[j]);
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < N; i++)
    cin >> B[i];
  for (int i = 0; i < N; i++)
    cin >> C[i];

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  ll ans = 0;

  for (int i = 0; i < N; i++) {
    ll a = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
    ll c = C.end() - upper_bound(C.begin(), C.end(), B[i]);
    ans += a * c;
  }
  cout << ans << endl;
}
Problem p03557 (C++)

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

int lt(int ok, int ng, int key, vector<int> a) {
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (a[mid] < key)
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int i = 0; i < n; i++)
    cin >> c[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long cnta = lt(-1, n, b[i], a) + 1;
    long long cntc = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    ans += cnta * cntc;
  }
  cout << ans << endl;
}

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

int lt(int ok, int ng, int key, vector<int> a) {
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (a[mid] < key)
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int i = 0; i < n; i++)
    cin >> c[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    // long long cnta = lt(-1,n,b[i],a) + 1;
    long long cnta = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    long long cntc = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    ans += cnta * cntc;
  }
  cout << ans << endl;
}
Problem p03557 (C++)

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

using namespace std;
typedef long long ll;

int lb(vector<int> a, int key) {
  int l = -1, r = (int)a.size();
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (a[mid] >= key)
      r = mid;
    else
      l = mid;
  }
  return r;
}
int ub(vector<int> a, int key) {
  int l = -1, r = (int)a.size();
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (a[mid] > key)
      r = mid;
    else
      l = mid;
  }
  return r;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int i = 0; i < n; i++)
    cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int na = lb(a, b[i]);
    int nc = n - ub(c, b[i]);
    ans += nc * na;
  }
  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

int lb(vector<int> a, int key) {
  int l = -1, r = (int)a.size();
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (a[mid] >= key)
      r = mid;
    else
      l = mid;
  }
  return r;
}
int ub(vector<int> a, int key) {
  int l = -1, r = (int)a.size();
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (a[mid] > key)
      r = mid;
    else
      l = mid;
  }
  return r;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int i = 0; i < n; i++)
    cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll na = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    ll nc = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
    ans += nc * na;
  }
  cout << ans << endl;
}
Problem p03557 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
  ll N;
  cin >> N;
  vl A(N), B(N), C(N);
  rep(i, N) { cin >> A[i]; }
  sort(all(A));
  rep(i, N) { cin >> B[i]; }
  sort(all(B));
  rep(i, N) { cin >> C[i]; }
  sort(all(C));

  ll ans = 0;
  // 中段を決めると全て決まる
  rep(i, N) {
    ll a = lower_bound(all(A), B[i]) - A.begin();
    ll c = N - (upper_bound(all(C), B[i]) - C.begin());
    ans += a * c;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
  ll N;
  cin >> N;
  vl A(N), B(N), C(N);
  rep(i, N) { cin >> A[i]; }
  sort(all(A));
  rep(i, N) { cin >> B[i]; }
  sort(all(B));
  rep(i, N) { cin >> C[i]; }
  sort(all(C));

  ll ans = 0;
  // 中段を決めると全て決まる
  rep(i, N) {
    ll a = lower_bound(all(A), B[i]) - A.begin();
    ll c = N - (upper_bound(all(C), B[i]) - C.begin());
    ans += a * c;
  }
  cout << ans << endl;
}
Problem p03557 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    auto iter_1 = upper_bound(b.begin(), b.end(), a[i]);
    int index_1 = iter_1 - b.begin();
    for (int j = index_1; j < n; j++) {
      auto iter_2 = upper_bound(c.begin(), c.end(), b[j]);
      int index_2 = iter_2 - c.begin();
      ans += n - index_2;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    auto iter_1 = lower_bound(a.begin(), a.end(), b[i]);
    ll index_1 = iter_1 - a.begin();
    auto iter_2 = upper_bound(c.begin(), c.end(), b[i]);
    ll index_2 = c.end() - iter_2;
    ans += index_1 * index_2;
  }
  cout << ans << endl;
}
Problem p03557 (C++)

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

Int lcm(Int x, Int y) { return x * y / gcd(x, y); }

int n, a[100001], b[100001], c[100001];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(b, b + n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(c, c + n);

  Int ans = 0;

  for (int i = 0; i < n; i++) {
    for (int j = upper_bound(b, b + n, a[i]) - (b); j < n; j++) {
      ans += (c + n) - upper_bound(c, c + n, b[j]);
    }
  }
  cout << ans << endl;

  return 0;
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

Int lcm(Int x, Int y) { return x * y / gcd(x, y); }

int n, a[100001], b[100001], c[100001];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(b, b + n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(c, c + n);

  Int ans = 0;

  for (int i = 0; i < n; i++) {
    ans += (lower_bound(a, a + n, b[i]) - (a)) *
           ((c + n) - upper_bound(c, c + n, b[i]));
  }
  cout << ans << endl;

  return 0;
}
Problem p03557 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <random>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

struct edge {
  int to, cost;
};
vector<int> G[100005];

int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

std::vector<P> tree[100010];
ll i, j;

ll n;
ll a[8] = {1, 3, 5, 7, 8, 9, 10, 13}, b[100005], c[100005];
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(a, a + n);
  sort(c, c + n);
  ll aa = 0, cc = 0;
  ll ans = 0;
  for (i = 0; i < n; i++) {
    aa = lower_bound(a, a + n, b[i]) - lower_bound(a, a + n, 0);
    cc = upper_bound(c, c + n, b[i]) - upper_bound(c, c + n, 0);
    ans += aa * (n - cc);
    aa = cc = 0;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <random>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

struct edge {
  int to, cost;
};
vector<int> G[100005];

int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

std::vector<P> tree[100010];
ll i, j;

ll n;
ll a[100005] = {1, 3, 5, 7, 8, 9, 10, 13}, b[100005], c[100005];
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(a, a + n);
  sort(c, c + n);
  ll aa = 0, cc = 0;
  ll ans = 0;
  for (i = 0; i < n; i++) {
    aa = lower_bound(a, a + n, b[i]) - lower_bound(a, a + n, 0);
    cc = upper_bound(c, c + n, b[i]) - upper_bound(c, c + n, 0);
    ans += aa * (n - cc);
    aa = cc = 0;
  }
  cout << ans << endl;
}
Problem p03557 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long LL;
#define ms(a, b) memset(a, b, sizeof(a))
#define eps 1e-8

int A[10005];
int B[10005];
int C[10005];
LL D[10005];
int main() {
  int N;
  cin >> N;
  A[0] = B[0] = C[0] = D[N + 1] = 0;
  for (int i = 1; i <= N; i++)
    cin >> A[i];
  for (int i = 1; i <= N; i++)
    cin >> B[i];
  B[N + 1] = B[N] + 1;
  for (int i = 1; i <= N; i++)
    cin >> C[i];
  C[N + 1] = C[N] + 1;
  sort(A + 1, A + N + 1);
  sort(B + 1, B + N + 1);
  sort(C + 1, C + N + 1);
  LL ans = 0;
  for (int i = N; i >= 1; i--) {
    D[i] = N + 1 - (upper_bound(C, C + N + 1, B[i]) - C);
    if (i < N)
      D[i] += D[i + 1];
  }

  /*for(int i=1;i<=N;i++) cout<<D[i]<<" ";
  cout<<endl;
  for(int i=1;i<=N;i++) cout<<D[i]<<" ";
  cout<<endl;
*/
  for (int i = 1; i <= N; i++) {
    int j = (upper_bound(B, B + N + 1, A[i]) - B);
    ans += D[j];
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long LL;
#define ms(a, b) memset(a, b, sizeof(a))
#define eps 1e-8

int A[100005];
int B[100005];
int C[100005];
LL D[100005];
int main() {
  int N;
  cin >> N;
  A[0] = B[0] = C[0] = D[N + 1] = 0;
  for (int i = 1; i <= N; i++)
    cin >> A[i];
  for (int i = 1; i <= N; i++)
    cin >> B[i];
  B[N + 1] = B[N] + 1;
  for (int i = 1; i <= N; i++)
    cin >> C[i];
  C[N + 1] = C[N] + 1;
  sort(A + 1, A + N + 1);
  sort(B + 1, B + N + 1);
  sort(C + 1, C + N + 1);
  LL ans = 0;
  for (int i = N; i >= 1; i--) {
    D[i] = N + 1 - (upper_bound(C, C + N + 1, B[i]) - C);
    if (i < N)
      D[i] += D[i + 1];
  }

  /*for(int i=1;i<=N;i++) cout<<D[i]<<" ";
  cout<<endl;
  for(int i=1;i<=N;i++) cout<<D[i]<<" ";
  cout<<endl;
*/
  for (int i = 1; i <= N; i++) {
    int j = (upper_bound(B, B + N + 1, A[i]) - B);
    ans += D[j];
  }
  cout << ans << endl;
  return 0;
}
Problem p03557 (C++)

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

using namespace std;

const long long int MAX_N = 100000;

int main(int argc, char const *argv[]) {
  long long int n;
  vector<long long int> a(MAX_N, 0), b(MAX_N, 0), c(MAX_N, 0);
  cin >> n;
  a.resize(n);
  b.resize(n);
  c.resize(n);
  for (size_t i = 0; i < n; i++)
    cin >> a[i];
  for (size_t i = 0; i < n; i++)
    cin >> b[i];
  for (size_t i = 0; i < n; i++)
    cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  long long int ans = 0;
  for (size_t i = 0; i < n; i++) {
    for (size_t j = 0; j < n; j++) {
      for (size_t k = 0; k < n; k++) {
        if (a[i] < b[j] and b[j] < c[k])
          ans++;
      }
    }
  }

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


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const long long int MAX_N = 100000;

int main(int argc, char const *argv[]) {
  long long int n;
  vector<long long int> a(MAX_N, 0), b(MAX_N, 0), c(MAX_N, 0);
  cin >> n;
  a.resize(n);
  b.resize(n);
  c.resize(n);
  for (size_t i = 0; i < n; i++)
    cin >> a[i];
  for (size_t i = 0; i < n; i++)
    cin >> b[i];
  for (size_t i = 0; i < n; i++)
    cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  long long int ans = 0;
  for (size_t i = 0; i < n; i++) {
    vector<long long int>::iterator lba = lower_bound(a.begin(), a.end(), b[i]),
                                    lbc = upper_bound(c.begin(), c.end(), b[i]);
    ans += (lba - a.begin()) * (n - (lbc - c.begin()));
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (signed i = 0; i < n; ++i)
#define repi(n) rep(i, n)
#define repvin(n)                                                              \
  vint a(n);                                                                   \
  r(i, n) cin >> a[i];
#define int long long
#define str string
#define vint vector<signed>
#define pint pair<signed, signed>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define call(a)                                                                \
  for (auto t : a)                                                             \
    cout << t << " ";                                                          \
  cout << endl
#define ENDL printf("\n");
#define debg(a) cout << #a << ":" << a << endl;
#define SORT(a) sort(all(a));
signed main() {
  int n;
  cin >> n;
  vint a(n), b(n), c(n);
  repi(n) cin >> a[i];
  repi(n) cin >> b[i];
  repi(n) cin >> c[i];
  SORT(a);
  SORT(b);
  SORT(c);
  int res = 0;
  for (signed i = 0; i < n; ++i) {
    int bitr = upper_bound(all(b), a[i]) - b.begin();
    for (signed j = bitr; j < n; ++j) {
      int citr = upper_bound(all(c), b[j]) - c.begin();
      res += n - citr;
    }
  }
  cout << res << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (signed i = 0; i < n; ++i)
#define repi(n) rep(i, n)
#define repvin(n)                                                              \
  vint a(n);                                                                   \
  r(i, n) cin >> a[i];
#define int long long
#define str string
#define vint vector<signed>
#define pint pair<signed, signed>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define call(a)                                                                \
  for (auto t : a)                                                             \
    cout << t << " ";                                                          \
  cout << endl
#define ENDL printf("\n");
#define debg(a) cout << #a << ":" << a << endl;
#define SORT(a) sort(all(a));
signed main() {
  int n;
  cin >> n;
  vint a(n), b(n), c(n);
  repi(n) cin >> a[i];
  repi(n) cin >> b[i];
  repi(n) cin >> c[i];
  SORT(a);
  SORT(b);
  SORT(c);
  int res = 0;
  for (signed j = 0; j < n; ++j) {
    int aitr = lower_bound(all(a), b[j]) - a.begin();
    int citr = upper_bound(all(c), b[j]) - c.begin();
    res += (aitr) * (n - citr);
  }
  cout << res << endl;

  return 0;
}
Problem p03557 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define F first
#define S second

typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e12;
const ll mlnf = -1e12;

void debug_vector(vector<int> &v) {
  int n = v.size();
  for (int i = 0; i < n; i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}

void solve();

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

void solve() {
  int N;
  std::cin >> N;
  std::vector<ll> A(N);
  std::vector<ll> B(N);
  std::vector<ll> C(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  rep(i, N) cin >> C[i];
  sort(all(A));
  sort(all(B));
  sort(all(C));
  ll ans = 0;
  for (auto a : A) {
    int b_ind = upper_bound(all(B), a) - B.begin();
    for (int b = b_ind; b < N; b++) {
      auto c_it = upper_bound(all(C), B[b]);
      ans += C.end() - c_it;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define F first
#define S second

typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e12;
const ll mlnf = -1e12;

void debug_vector(vector<int> &v) {
  int n = v.size();
  for (int i = 0; i < n; i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}

void solve();

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

void solve() {
  int N;
  std::cin >> N;
  std::vector<ll> A(N);
  std::vector<ll> B(N);
  std::vector<ll> C(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  rep(i, N) cin >> C[i];
  sort(all(A));
  sort(all(B));
  sort(all(C));
  ll ans = 0;
  for (auto b : B) {
    auto c_iter = upper_bound(all(C), b);
    ll c_cnt = C.end() - c_iter;

    auto a_iter = lower_bound(all(A), b);
    ll a_cnt = a_iter - A.begin();

    ans += a_cnt * c_cnt;
  }
  cout << ans << endl;
}
Problem p03557 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
const int maxn = 10005;
int n;
int a[maxn], b[maxn], c[maxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int i = 0; i < n; i++)
    cin >> c[i];
  sort(a, a + n);
  sort(b, b + n);
  sort(c, c + n);
  long long sum = 0;
  long long temp1 = 0, temp2 = 0;
  for (int i = 0; i < n; i++) {
    while (a[temp1] < b[i] && temp1 < n)
      temp1++;
    while (c[temp2] <= b[i] && temp2 < n)
      temp2++;
    sum += temp1 * (n - temp2);
  }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
const int maxn = 1000005;
int n;
int a[maxn], b[maxn], c[maxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int i = 0; i < n; i++)
    cin >> c[i];
  sort(a, a + n);
  sort(b, b + n);
  sort(c, c + n);
  long long sum = 0;
  long long temp1 = 0, temp2 = 0;
  for (int i = 0; i < n; i++) {
    while (a[temp1] < b[i] && temp1 < n)
      temp1++;
    while (c[temp2] <= b[i] && temp2 < n)
      temp2++;
    sum += temp1 * (n - temp2);
  }
  cout << sum << endl;
  return 0;
}
Problem p03557 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int i = 0; i < n; i++)
    cin >> c[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    auto it_b = upper_bound(b.begin(), b.end(), a[i]);
    for (; it_b != b.end(); it_b++) {
      auto it_c = upper_bound(c.begin(), c.end(), *it_b);
      ans += c.end() - it_c;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int i = 0; i < n; i++)
    cin >> c[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    auto it_a = lower_bound(a.begin(), a.end(), b[i]);
    auto it_c = upper_bound(c.begin(), c.end(), b[i]);
    ans += (it_a - a.begin()) * (c.end() - it_c);
  }
  cout << ans << endl;
  return 0;
}