Language: C++

#include<iostream>
using namespace std;
int L = 998244353;

unsigned int pairPattern(unsigned int m, unsigned int n,unsigned int K) {
	if (m == 0 && n == 0) {
		return 1;
	}
	else if (m == 0 && n > 0) {
		return pairPattern(0, n - 1, K - 1);
	}
	else if (n == 0 && m > 0) {
		return pairPattern(m - 1, 0, K - 1);
	}
	else {
		return pairPattern(m - 1, n, K - 1) + pair(m, n - 1, K - 1);
	}
}

long long pattern(int i, int j, int N) {
	int l, m, n, min;
	if (i > j) {
		min = i;
	}
	else {
		min = j;
	}
	long long ans = 0;
	for (m = 0; m <= min; m++) {
		l = i - m;
		n = j - m;
		if (l + m + n <= N) {
			ans += pairPattern(l, N - l, N) + pairPattern(m, N - l - m, N - l) + pairPattern(n, N - l - m - n, N - l - m);
		}
	}
	return ans;
}

int main()
{
	long long N,A,B,K;
	cin >> N >> A >> B >> K;
	if (K == 0) {
		cout << 1 << endl;
		return 0;
	}
	int i = 0;
	long long ans = 0;
	while (K - A*i > 0) {
		if ((K - A*i) % B == 0) {
			ans += pattern(i, (K - A*i) / B, N);
		}
		if (ans > L) {
			ans %= L;
		}
		i++;
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'unsigned int pairPattern(unsigned int, unsigned int, unsigned int)':
a.cc:16:75: error: class template argument deduction failed:
   16 |                 return pairPattern(m - 1, n, K - 1) + pair(m, n - 1, K - 1);
      |                                                                           ^
a.cc:16:75: error: no matching function for call to 'pair(unsigned int&, unsigned int, unsigned int)'
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:913:28: note: candidate: 'template<class _T1, class _T2, class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > pair(std::pair<_U1, _U2>&&)-> std::pair<_T1, _T2>'
  913 |         explicit constexpr pair(pair<_U1, _U2>&& __p)
      |                            ^~~~
/usr/include/c++/14/bits/stl_pair.h:913:28: note:   candidate expects 1 argument, 3 provided
/usr/include/c++/14/bits/stl_pair.h:902:19: note: candidate: 'template<class _T1, class _T2, class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > pair(std::pair<_U1, _U2>&&)-> std::pair<_T1, _T2>'
  902 |         constexpr pair(pair<_U1, _U2>&& __p)
      |                   ^~~~
/usr/include/c++/14/bits/stl_pair.h:902:19: note:   candidate expects 1 argument, 3 provided
/usr/include/c++/14/bits/stl_pair.h:891:28: note: candidate: 'template<class _T1, class _T2, class _U1, class _U2, typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > pair(_U1&&, _U2&&)-> std::pair<_T1, _T2>'
  891 |         explicit constexpr pair(_U1&& __x, _U2&& __y)
      |                            ^~~~
/usr/include/c++/14/bits/stl_pair.h:891:28: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/14/bits/stl_pair.h:881:19: note: candidate: 'template<class _T1, class _T2, class _U1, class _U2, typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > pair(_U1&&, _U2&&)-> std::pair<_T1, _T2>'
  881 |         constexpr pair(_U1&& __x, _U2&& __y)
      |                   ^~~~
/usr/include/c++/14/bits/stl_pair.h:881:19: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/14/bits/stl_pair.h:869:9: note: candidate: 'template<class _T1, class _T2, class _U2, typename std::enable_if<std::__and_<std::is_pointer<_Tp>, std::__not_<std::is_reference<_U2> >, std::is_constructible<_T2, _U2>, std::__not_<std::is_constructible<_T2, const _U2&> >, std::__not_<std::is_convertible<_U2, _T2> > >::value, bool>::type <anonymous> > pair(typename std::pair<_T1, _T2>::__zero_as_null_pointer_constant, _U2&&, ...)-> std::pair<_T1, _T2>'
  869 |         pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:869:9: note:   template argument deduction/substitution failed:
a.cc:16:75: note:   couldn't deduce template parameter '_T1'
   16 |                 return pairPattern(m - 1, n, K - 1) + pair(m, n - 1, K - 1);
      |                                                                           ^
/usr/include/c++/14/bits/stl_pair.h:856:9: note: candidate: 'template<class _T1, class _T2, class _U2, typename std::enable_if<std::__and_<std::is_pointer<_Tp>, std::__not_<std::is_reference<_U2> >, std::is_constructible<_T2, _U2>, std::__not_<std::is_constructible<_T2, const _U2&> >, std::is_convertible<_U2, _T2> >::value, bool>::type <anonymous> > pair(typename std::pair<_T1, _T2>::__zero_as_null_pointer_constant, _U2&&, ...)-> std::pair<_T1, _T2>'
  856 |         pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:856:9: note:   template argument deduction/substitution failed:
a.cc:16:75: note:   couldn't deduce template parameter '_T1'
   16 |                 return pairPattern(m - 1, n, K - 1) + pair(m, n - 1, K - 1);
      |                                                                           ^
/usr/include/c++/14/bits/stl_pair.h:843:9: note: candidate: 'template<class _T1, class _T2, class _U1, typename std::enable_if<std::__and_<std::__not_<std::is_reference<_U2> >, std::is_pointer<_T2>, std::is_constructible<_T1, _U1>, std::__not_<std::is_constructible<_T1, const _U1&> >, std::__not_<std::is_convertible<_U1, _T1> > >::value, bool>::type <anonymous> > pair(_U1&&, typename std::pair<_T1, _T2>::__zero_as_null_pointer_constant, ...)-> std::pair<_T1, _T2>'
  843 |         pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:843:9: note:   template argument deduction/substitution failed:
a.cc:16:75: note:   couldn't deduce template parameter '_T1'
   16 |                 return pairPattern(m - 1, n, K - 1) + pair(m, n - 1, K - 1);
      |                                                                           ^
/usr/include/c++/14/bits/stl_pair.h:830:9: note: candidate: 'template<class _T1, class _T2, class _U1, typename std::enable_if<std::__and_<std::__not_<std::is_reference<_U2> >, std::is_pointer<_T2>, std::is_constructible<_T1, _U1>, std::__not_<std::is_constructible<_T1, const _U1&> >, std::is_convertible<_U1, _T1> >::value, bool>::type <anonymous> > pair(_U1&&, typename std::pair<_T1, _T2>::__zero_as_null_pointer_constant, ...)-> std::pair<_T1, _T2>'
  830 |         pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:830:9: note:   template argument deduction/substitution failed:
a.cc:16:75: note:   couldn't deduce template parameter '_T1'
   16 |                 return pairPattern(m - 1, n, K - 1) + pair(m, n - 1, K - 1);
      |                                                                           ^
/usr/include/c++/14/bits/stl_pair.h:789:28: note: candidate: 'template<class _T1, class _T2, class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > pair(const std::pair<_U1, _U2>&)-> std::pair<_T1, _T2>'
  789 |         explicit constexpr pair(const pair<_U1, _U2>& __p)
      |                            ^~~~
/usr/include/c++/14/bits/stl_pair.h:789:28: note:   candidate expects 1 argument, 3 provided
/usr/include/c++/14/bits/stl_pair.h:779:19: note: candidate: 'template<class _T1, class _T2, class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > pair(const std::pair<_U1, _U2>&)-> std::pair<_T1, _T2>'
  779 |         constexpr pair(const pair<_U1, _U2>& __p)
      |                   ^~~~
/usr/include/c++/14/bits/stl_pair.h:779:19: note:   candidate expects 1 argument, 3 provided
/usr/include/c++/14/bits/stl_pair.h:762:26: note: candidate: 'template<class _T1, class _T2, class _U1, class _U2, typename std::enable_if<(std::_PCC<true, _T1, _T2>::_ConstructiblePair<_U1, _U2>() && (! std::_PCC<true, _T1, _T2>::_ImplicitlyConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > pair(const _T1&, const _T2&)-> std::pair<_T1, _T2>'
  762 |       explicit constexpr pair(const _T1& __a, const _T2& __b)
      |                          ^~~~
/usr/include/c++/14/bits/stl_pair.h:762:26: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/14/bits/stl_pair.h:752:17: note: candidate: 'template<class _T1, class _T2, class _U1, class _U2, typename std::enable_if<(std::_PCC<true, _T1, _T2>::_ConstructiblePair<_U1, _U2>() && std::_PCC<true, _T1, _T2>::_ImplicitlyConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > pair(const _T1&, const _T2&)-> std::pair<_T1, _T2>'
  752 |       constexpr pair(const _T1& __a, const _T2& __b)
      |                 ^~~~
/usr/include/c++/14/bits/stl_pair.h:752:17: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/14/bits/stl_pair.h:737:26: note: candidate: 'template<class _T1, class _T2, class _U1, class _U2, typename std::enable_if<std::__and_<std::is_default_constructible<_U1>, std::is_default_constructible<_U2>, std::__not_<std::__and_<std::__is_implicitly_default_constructible<_U1>, std::__is_implicitly_default_constructible<_U2> > > >::value, bool>::type <anonymous> > pair()-> std::pair<_T1, _T2>'
  737 |       explicit constexpr pair()
      |                          ^~~~
/usr/include/c++/14/bits/stl_pair.h:737:26: note:   candidate expects 0 arguments, 3 provided
/usr/include/c++/14/bits/stl_pair.h:725:17: note: candidate: 'template<class _T1, class _T2, class _U1, class _U2, typename std::enable_if<std::__and_<std::__is_implicitly_default_constructible<_U1>, std::__is_implicitly_default_constructible<_U2> >::value, bool>::type <anonymous> > pair()-> std::pair<_T1, _T2>'
  725 |       constexpr pair()
      |                 ^~~~
/usr/include/c++/14/bit