Language: C++

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

const int maxn(2e5 + 5);
const int mod(1e9 + 7);

int n, mn[maxn], inv[maxn], size[maxn], mn1 = mod, mn2 = mod, x, y, id[maxn], ans = 1, cnt;
vector <int> ball[maxn];

inline bool Cmp(int i, int j) {
	return mn[i] < mn[j];
}

int main() {
	register int i, j, w, c, nmn;
	scanf("%d%d%d", &n, &x, &y), inv[1] = inv[0] = 1;
	for (i = 2; i <= n; ++i) inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
	for (i = 1; i <= n; ++i) inv[i] = 1LL * inv[i] * inv[i - 1] % mod;
	for (i = 1; i <= n; ++i) scanf("%d%d", &c, &w), ball[c].push_back(w), ++size[c], id[i] = i;
	for (i = 1; i <= n; ++i)
		if (size[i]) {
			sort(ball[i].begin(), ball[i].end());
			mn[i] = ball[i][0], mn2 = min(mn[i], mn2);
			if (mn2 < mn1) swap(mn2, mn1);
		}
		else mn[i] = mod;
	for (i = 1; i <= n; ++i)
		if (size[i]) {
			nmn = mn[i] == mn1 ? mn2 : mn1;
			if (mn[i] > x) {
				size[i] = 0, mn[i] = inf;
				continue;
			}
			for (j = 1; j < size[i]; ++j)
				if (mn[i] + ball[i][j] > x && nmn + ball[i][j] > y) break;
		   size[i] = j;
		}
	sort(id + 1, id + n + 1, Cmp), nmn = mn[id[1]];
	cnt = mn[id[1]] != mod ? size[id[1]] : 0;
	for (i = 2; i <= n; ++i)
		if (mn[id[i]] + nmn <= y) ans = 1LL * ans * inv[size[id[i]]] % mod, cnt += size[id[i]];
	for (i = 1; i <= cnt; ++i) ans = 1LL * ans * i % mod;
	printf("%d\n", ans);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   16 |         register int i, j, w, c, nmn;
      |                      ^
a.cc:16:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   16 |         register int i, j, w, c, nmn;
      |                         ^
a.cc:16:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   16 |         register int i, j, w, c, nmn;
      |                            ^
a.cc:16:31: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   16 |         register int i, j, w, c, nmn;
      |                               ^
a.cc:16:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   16 |         register int i, j, w, c, nmn;
      |                                  ^~~
a.cc:20:81: error: reference to 'size' is ambiguous
   20 |         for (i = 1; i <= n; ++i) scanf("%d%d", &c, &w), ball[c].push_back(w), ++size[c], id[i] = i;
      |                                                                                 ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:29: note:                 'int size [200005]'
    8 | int n, mn[maxn], inv[maxn], size[maxn], mn1 = mod, mn2 = mod, x, y, id[maxn], ans = 1, cnt;
      |                             ^~~~
a.cc:22:21: error: reference to 'size' is ambiguous
   22 |                 if (size[i]) {
      |                     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:29: note:                 'int size [200005]'
    8 | int n, mn[maxn], inv[maxn], size[maxn], mn1 = mod, mn2 = mod, x, y, id[maxn], ans = 1, cnt;
      |                             ^~~~
a.cc:29:21: error: reference to 'size' is ambiguous
   29 |                 if (size[i]) {
      |                     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:29: note:                 'int size [200005]'
    8 | int n, mn[maxn], inv[maxn], size[maxn], mn1 = mod, mn2 = mod, x, y, id[maxn], ans = 1, cnt;
      |                             ^~~~
a.cc:32:33: error: reference to 'size' is ambiguous
   32 |                                 size[i] = 0, mn[i] = inf;
      |                                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:29: note:                 'int size [200005]'
    8 | int n, mn[maxn], inv[maxn], size[maxn], mn1 = mod, mn2 = mod, x, y, id[maxn], ans = 1, cnt;
      |                             ^~~~
a.cc:32:54: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   32 |                                 size[i] = 0, mn[i] = inf;
      |                                                      ^~~
      |                                                      ynf
a.cc:35:41: error: reference to 'size' is ambiguous
   35 |                         for (j = 1; j < size[i]; ++j)
      |                                         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:29: note:                 'int size [200005]'
    8 | int n, mn[maxn], inv[maxn], size[maxn], mn1 = mod, mn2 = mod, x, y, id[maxn], ans = 1, cnt;
      |                             ^~~~
a.cc:37:20: error: reference to 'size' is ambiguous
   37 |                    size[i] = j;
      |                    ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:29: note:                 'int size [200005]'
    8 | int n, mn[maxn], inv[maxn], size[maxn], mn1 = mod, mn2 = mod, x, y, id[maxn], ans = 1, cnt;
      |                             ^~~~
a.cc:40:34: error: reference to 'size' is ambiguous
   40 |         cnt = mn[id[1]] != mod ? size[id[1]] : 0;
      |                                  ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:29: note:                 'int size [200005]'
    8 | int n, mn[maxn], inv[maxn], size[maxn], mn1 = mod, mn2 = mod, x, y, id[maxn], ans = 1, cnt;
      |                             ^~~~
a.cc:42:65: error: reference to 'size' is ambiguous
   42 |                 if (mn[id[i]] + nmn <= y) ans = 1LL * ans * inv[size[id[i]]] % mod, cnt += size[id[i]];
      |                                                                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:29: note:                 'int size [200005]'
    8 | int n, mn[maxn], inv[maxn], size[maxn], mn1 = mod, mn2 = mod, x, y, id[maxn], ans = 1, cnt;
      |                             ^~~~
a.cc:42:92: error: reference to 'size' is ambiguous
   42 |                 if (mn[id[i]] + nmn <= y) ans = 1LL * ans * inv[size[id[i]]] % mod, cnt += size[id[i]];
      |                                                                                            ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:29: note:                 'int size [200005]'
    8 | int n, mn[maxn], inv[maxn], size[maxn], mn1 = mod, mn2 = mod, x, y, id[maxn], ans = 1, cnt;
      |                             ^~~~