{"problem":{"name":"Colorful Balls","description":{"content":"Snuke arranged $N$ colorful balls in a row. The $i$\\-th ball from the left has color $c_i$ and weight $w_i$. He can rearrange the balls by performing the following two operations any number of times, ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"agc012_d"},"statements":[{"statement_type":"Markdown","content":"Snuke arranged $N$ colorful balls in a row. The $i$\\-th ball from the left has color $c_i$ and weight $w_i$.\nHe can rearrange the balls by performing the following two operations any number of times, in any order:\n\n*   Operation $1$: Select two balls with the same color. If the total weight of these balls is at most $X$, swap the positions of these balls.\n*   Operation $2$: Select two balls with different colors. If the total weight of these balls is at most $Y$, swap the positions of these balls.\n\nHow many different sequences of colors of balls can be obtained? Find the count modulo $10^9 + 7$.\n\n## Constraints\n\n*   $1 ≤ N ≤ 2 × 10^5$\n*   $1 ≤ X, Y ≤ 10^9$\n*   $1 ≤ c_i ≤ N$\n*   $1 ≤ w_i ≤ 10^9$\n*   $X, Y, c_i, w_i$ are all integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $X$ $Y$\n$c_1$ $w_1$\n$:$\n$c_N$ $w_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"agc012_d","tags":[],"sample_group":[["4 7 3\n3 2\n4 3\n2 1\n4 4","2\n\n*   The sequence of colors $(2,4,3,4)$ can be obtained by swapping the positions of the first and third balls by operation $2$.\n*   It is also possible to swap the positions of the second and fourth balls by operation $1$, but it does not affect the sequence of colors."],["1 1 1\n1 1","1"],["21 77 68\n16 73\n16 99\n19 66\n2 87\n2 16\n7 17\n10 36\n10 68\n2 38\n10 74\n13 55\n21 21\n3 7\n12 41\n13 88\n18 6\n2 12\n13 87\n1 9\n2 27\n13 15","129729600"]],"created_at":"2026-03-03 11:01:14"}}