Language: C++

#include "bits/stdc++.h"

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;

// Modulo.h start----------------------------------------

#pragma once

#include <vector>

unsigned int mod;
struct Modint;
std::vector<Modint> fact_mod;
std::vector<Modint> rev_fact_mod;

using namespace std;

template<typename Tint>
Tint gcd(Tint a, Tint b) {
	// O(log max(a,b))
	a = abs(a);
	b = abs(b);
	return b != 0 ? gcd(b, a % b) : a;
}

template<typename Tint>
Tint lcm(Tint a, Tint b) {
	return a / gcd(a, b) * b;
}

// a x + b y = gcd(a, b)
int extgcd(const unsigned int a, const unsigned int b, int &x, int &y) {
	// O(log max(a,b))
	int g = a; x = 1; y = 0;
	if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
	return g;
}

void set_mod(const unsigned int m) {
	mod = m;
}
void set_mod(const int m) {
	if (m > 0)
		set_mod((unsigned int)m);
	else
		cout << "Error in set_mod" << endl;
}

unsigned int inv_mod(const unsigned int a) {
	int x, y;
	if (extgcd(a, mod, x, y) == 1)
		return (unsigned int)(((long long)x + mod) % mod);
	else // unsolvable
		return 0;
}

struct Modint {
	unsigned int value;
	Modint() { }
	Modint(unsigned int value) : value(value % mod) { }
	Modint(int value) : Modint((unsigned int)(value % mod + mod)) {	}
	Modint(unsigned long long value) : Modint((unsigned int)(value % mod)) { }
	Modint(long long value) : Modint((unsigned int)(value % mod +mod)) { }
	Modint(const Modint& rhs) : Modint(rhs.value) { }
	bool operator==(const Modint& rhs) const;
	inline bool operator!=(const Modint& rhs) const
	{
		return !(*this == rhs);
	}
	Modint& operator+=(const Modint& rhs);
	Modint& operator+=(const unsigned int rhs);
	Modint& operator+=(const int rhs);
	Modint& operator+=(const unsigned long long rhs);
	Modint& operator+=(const long long rhs);
	Modint& operator-=(const Modint& rhs);
	Modint& operator-=(const unsigned int rhs);
	Modint& operator-=(const int rhs);
	Modint& operator-=(const unsigned long long rhs);
	Modint& operator-=(const long long rhs);
	Modint& operator*=(const Modint& rhs);
	Modint& operator*=(const unsigned int rhs);
	Modint& operator*=(const int rhs);
	Modint& operator*=(const unsigned long long rhs);
	Modint& operator*=(const long long rhs);
	Modint& operator/=(const Modint& rhs);
	Modint& operator/=(const unsigned int rhs);
	Modint& operator/=(const int rhs);
	Modint& operator/=(const unsigned long long rhs);
	Modint& operator/=(const long long rhs);
};
bool Modint::operator==(const Modint& rhs) const
{
	return value == rhs.value;
}
Modint& Modint::operator+=(const unsigned int rhs)
{
	unsigned long long tmp = this->value;
	tmp += rhs;
	tmp %= mod;
	this->value = (unsigned int)tmp;
	return *this;
}
Modint& Modint::operator+=(const Modint& rhs)
{
	(*this) += rhs.value;
	return *this;
}
Modint& Modint::operator+=(const int rhs)
{
	(*this) += (unsigned int)(rhs % mod + mod);
	return *this;
}
Modint& Modint::operator+=(const unsigned long long rhs)
{
	(*this) += (unsigned int)(rhs % mod);
	return *this;
}
Modint& Modint::operator+=(const long long rhs)
{
	(*this) += (unsigned int)(rhs % mod + mod);
	return *this;
}
Modint& Modint::operator-=(const Modint& rhs)
{
	(*this) -= rhs.value;
	return *this;
}
Modint& Modint::operator-=(const unsigned int rhs)
{
	*this += mod - rhs % mod;
	return *this;
}
Modint& Modint::operator-=(const int rhs)
{
	*this -= (unsigned int)(rhs % mod + mod);
	return *this;
}
Modint& Modint::operator-=(const unsigned long long rhs)
{
	(*this) -= (unsigned int)(rhs % mod);
	return *this;
}
Modint& Modint::operator-=(const long long rhs)
{
	(*this) -= (unsigned int)(rhs % mod + mod);
	return *this;
}
Modint& Modint::operator*=(const Modint& rhs)
{
	(*this) *= rhs.value;
	return *this;
}
Modint& Modint::operator*=(const unsigned int rhs)
{
	unsigned long long tmp = this->value;
	tmp *= rhs;
	tmp %= mod;
	this->value = (unsigned int)tmp;
	return *this;
}
Modint& Modint::operator*=(const int rhs)
{
	(*this) *= (unsigned int)(rhs % mod + mod);
	return *this;
}
Modint& Modint::operator*=(const unsigned long long rhs)
{
	(*this) *= (unsigned int)(rhs % mod);
	return *this;
}
Modint& Modint::operator*=(const long long rhs)
{
	(*this) *= (unsigned int)(rhs % mod + mod);
	return *this;
}
Modint& Modint::operator/=(const Modint& rhs)
{
	(*this) /= rhs.value;
	return *this;
}
Modint& Modint::operator/=(const unsigned int rhs)
{
	*this *= inv_mod(rhs);
	return *this;
}
Modint& Modint::operator/=(const int rhs)
{
	*this /= (unsigned int)(rhs % mod + mod);
	return *this;
}
Modint& Modint::operator/=(const unsigned long long rhs)
{
	*this /= (unsigned int)(rhs % mod);
	return *this;
}
Modint& Modint::operator/=(const long long rhs)
{
	*this /= (unsigned int)(rhs % mod + mod);
	return *this;
}
const Modint operator + (const Modint& lhs, const Modint& rhs) {
	return Modint(lhs) += rhs;
}
const Modint operator + (const Modint& lhs, unsigned int rhs) {
	return Modint(lhs) += rhs;
}
const Modint operator + (unsigned int lhs, const Modint& rhs) {
	return Modint(lhs) += rhs;
}
const Modint operator - (const Modint& lhs, const Modint& rhs) {
	return Modint(lhs) -= rhs;
}
const Modint operator - (const Modint& lhs, unsigned int rhs) {
	return Modint(lhs) -= rhs;
}
const Modint operator - (unsigned int lhs, const Modint& rhs) {
	return Modint(lhs) -= rhs;
}
const Modint operator * (const Modint& lhs, const Modint& rhs) {
	return Modint(lhs) *= rhs;
}
const Modint operator * (const Modint& lhs, unsigned int rhs) {
	return Modint(lhs) *= rhs;
}
const Modint operator * (unsigned int lhs, const Modint& rhs) {
	return Modint(lhs) *= rhs;
}
const Modint operator / (const Modint& lhs, const Modint& rhs) {
	return Modint(lhs) /= rhs;
}
const Modint operator / (const Modint& lhs, unsigned int rhs) {
	return Modint(lhs) /= rhs;
}
const Modint operator / (unsigned int lhs, const Modint& rhs) {
	return Modint(lhs) /= rhs;
}
ostream& operator<<(std::ostream& lhs, const Modint& rhs)
{
	lhs << rhs.value;
	return lhs;
}

Modint pow_mod(const Modint& x, const unsigned int k) { //x^k (mod)
	if (k == 0)     return Modint(1);
	if (k % 2 == 0) return pow_mod(x*x, k / 2);
	else            return x * pow_mod(x, k - 1);
}
Modint pow_mod(const unsigned int x, const unsigned int k) {
	return pow_mod(Modint(x), k);
}

std::vector<Modint> set_fact_mod(unsigned int n) {
	fact_mod = vector<Modint>(n + 1);
	fact_mod[0] = 1;
	for (unsigned int i = 1; i <= n; i++)
	{
		fact_mod[i] = fact_mod[i - 1] * i;
	}
	return fact_mod;
}

std::vector<Modint> set_rev_fact_mod(unsigned int n) {
	rev_fact_mod = vector<Modint>(n + 1);
	rev_fact_mod[n] = 1 / fact_mod[n];
	for (int i = n - 1; i >= 0; i--)
	{
		rev_fact_mod[i] = rev_fact_mod[i + 1] * (unsigned int)(i + 1);
	}
	return rev_fact_mod;
}

Modint combination_mod_precalculation(unsigned int n, unsigned int r) {
	//set mod, fact_mod, rev_fact_mod
	return fact_mod[n] * rev_fact_mod[r] * rev_fact_mod[n - r];
}

Modint combination_mod_straightforward(unsigned long long n, unsigned long long r) { //mod is prime
	if (r * 2 > n) r = n - r;
	Modint numerator = 1;
	Modint denominator = 1;
	for (unsigned long long i = 1; i <= r; ++i) {
		numerator *= n - i + 1;
		denominator *= i;
	}
	return numerator / denominator;
}

// Modulo.h end----------------------------------------------
#define MOD 1000000007

int main() {
	int N, A, B, C;
	set_mod(MOD);
	Modint a = 1 / A, b = 1 / B, c = 1 / C;
	vector<vector<Modint>> g(N + 1, vector<int>(N + 1));
	g[0][0] = 0;
	std::vector<Modint> fact_mod = set_fact_mod(N);
	std::vector<Modint> rev_fact_mod = set_rev_fact_mod(N);

	for (int i = 0; i <= N - 1; i++)
	{
		g[N][i] = (a / (1 - c) / (1 - c) * N + b / (1 - c) / (1 - c) * i) * combination_mod_precalculation(N, i);
	}
	for (int j = 0; j <= N - 1; j++)
	{
		g[j][N] = (b / (1 - c) / (1 - c) * N + a / (1 - c) / (1 - c) * j) * combination_mod_precalculation(N, j);
	}
	Modint ans = 0;
	for (int i = 0; i < N-1; i++)
	{
		ans += g[N][i] + g[i][N];
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc:10:9: warning: #pragma once in main file
   10 | #pragma once
      |         ^~~~
a.cc: In function 'int main()':
a.cc:298:59: error: no matching function for call to 'std::vector<std::vector<Modint> >::vector(int, std::vector<int>)'
  298 |         vector<vector<Modint>> g(N + 1, vector<int>(N + 1));
      |                                                           ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:707:9: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >]'
  707 |         vector(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:707:9: note:   template argument deduction/substitution failed:
a.cc:298:59: note:   deduced conflicting types for parameter '_InputIterator' ('int' and 'std::vector<int>')
  298 |         vector<vector<Modint>> g(N + 1, vector<int>(N + 1));
      |                                                           ^
/usr/include/c++/14/bits/stl_vector.h:678:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >; allocator_type = std::allocator<std::vector<Modint> >]'
  678 |       vector(initializer_list<value_type> __l,
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:678:43: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<std::vector<Modint> >'
  678 |       vector(initializer_list<value_type> __l,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:659:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >; std::__type_identity_t<_Alloc> = std::allocator<std::vector<Modint> >]'
  659 |       vector(vector&& __rv, const __type_identity_t<allocator_type>& __m)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:659:23: note:   no known conversion for argument 1 from 'int' to 'std::vector<std::vector<Modint> >&&'
  659 |       vector(vector&& __rv, const __type_identity_t<allocator_type>& __m)
      |              ~~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_vector.h:640:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::false_type) [with _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >; allocator_type = std::allocator<std::vector<Modint> >; std::false_type = std::false_type]'
  640 |       vector(vector&& __rv, const allocator_type& __m, false_type)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:640:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_vector.h:635:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::true_type) [with _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >; allocator_type = std::allocator<std::vector<Modint> >; std::true_type = std::true_type]'
  635 |       vector(vector&& __rv, const allocator_type& __m, true_type) noexcept
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:635:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_vector.h:624:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >; std::__type_identity_t<_Alloc> = std::allocator<std::vector<Modint> >]'
  624 |       vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:624:28: note:   no known conversion for argument 1 from 'int' to 'const std::vector<std::vector<Modint> >&'
  624 |       vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
      |              ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:620:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >]'
  620 |       vector(vector&&) noexcept = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:620:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:601:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >]'
  601 |       vector(const vector& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:601:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:569:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >; size_type = long unsigned int; value_type = std::vector<Modint>; allocator_type = std::allocator<std::vector<Modint> >]'
  569 |       vector(size_type __n, const value_type& __value,
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:569:47: note:   no known conversion for argument 2 from 'std::vector<int>' to 'const std::vector<std::vector<Modint> >::value_type&' {aka 'const std::vector<Modint>&'}
  569 |       vector(size_type __n, const value_type& __value,
      |                             ~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_vector.h:556:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >; size_type = long unsigned int; allocator_type = std::allocator<std::vector<Modint> >]'
  556 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:556:51: note:   no known conversion for argument 2 from 'std::vector<int>' to 'const std::vector<std::vector<Modint> >::allocator_type&' {aka 'const std::allocator<std::vector<Modint> >&'}
  556 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |                             ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:542:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >; allocator_type = std::allocator<std::vector<Modint> >]'
  542 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:542:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:531:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = std::vector<Modint>; _Alloc = std::allocator<std::vector<Modint> >]'
  531 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:531:7: note:   candidate expects 0 arguments, 2 provided