Language: C++

#include <bits/stdc++.h>
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 1e9+7;
using mint = Fp<MOD>
using namespace std;
 
int main() {
  mint N,M;
  mint A=1;
  mint B=0;
  cin>>N>>M;
  if(N==M){
    for(mint X=1;X<=N;X++){
      A*=X;
    }
    cout<<A*A*2<<endl;
  }
  else if(abs(N-M)>1){
    cout<<0<<endl;
  }
  else{
    for(mint X=1;X<=max(N,M);X++){
      A*=X;
      if(X=min(N,M)){
        B+=A;
      }
    }
    cout<<A*B<<endl;
  }
}

Compiler output:
a.cc:46:22: error: 'ostream' does not name a type
   46 |     friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
      |                      ^~~~~~~
a.cc: In member function 'constexpr Fp<MOD>& Fp<MOD>::operator/=(const Fp<MOD>&)':
a.cc:33:25: error: there are no arguments to 'swap' that depend on a template parameter, so a declaration of 'swap' must be available [-fpermissive]
   33 |             a -= t * b; swap(a, b);
      |                         ^~~~
a.cc:33:25: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:34:25: error: there are no arguments to 'swap' that depend on a template parameter, so a declaration of 'swap' must be available [-fpermissive]
   34 |             u -= t * v; swap(u, v);
      |                         ^~~~
a.cc: At global scope:
a.cc:58:21: error: expected ';' before 'using'
   58 | using mint = Fp<MOD>
      |                     ^
      |                     ;
   59 | using namespace std;
      | ~~~~~                
a.cc: In function 'int main()':
a.cc:62:3: error: 'mint' was not declared in this scope; did you mean 'uint'?
   62 |   mint N,M;
      |   ^~~~
      |   uint
a.cc:63:7: error: expected ';' before 'A'
   63 |   mint A=1;
      |       ^~
      |       ;
a.cc:64:7: error: expected ';' before 'B'
   64 |   mint B=0;
      |       ^~
      |       ;
a.cc:65:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   65 |   cin>>N>>M;
      |   ^~~
      |   std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146,
                 from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:65:8: error: 'N' was not declared in this scope
   65 |   cin>>N>>M;
      |        ^
a.cc:65:11: error: 'M' was not declared in this scope
   65 |   cin>>N>>M;
      |           ^
a.cc:67:13: error: expected ';' before 'X'
   67 |     for(mint X=1;X<=N;X++){
      |             ^~
      |             ;
a.cc:67:18: error: 'X' was not declared in this scope
   67 |     for(mint X=1;X<=N;X++){
      |                  ^
a.cc:68:7: error: 'A' was not declared in this scope
   68 |       A*=X;
      |       ^
a.cc:70:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   70 |     cout<<A*A*2<<endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:70:11: error: 'A' was not declared in this scope
   70 |     cout<<A*A*2<<endl;
      |           ^
a.cc:70:18: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   70 |     cout<<A*A*2<<endl;
      |                  ^~~~
      |                  std::endl
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc:73:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   73 |     cout<<0<<endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:73:14: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   73 |     cout<<0<<endl;
      |              ^~~~
      |              std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc:76:13: error: expected ';' before 'X'
   76 |     for(mint X=1;X<=max(N,M);X++){
      |             ^~
      |             ;
a.cc:76:18: error: 'X' was not declared in this scope
   76 |     for(mint X=1;X<=max(N,M);X++){
      |                  ^
a.cc:76:21: error: 'max' was not declared in this scope; did you mean 'std::max'?
   76 |     for(mint X=1;X<=max(N,M);X++){
      |                     ^~~
      |                     std::max
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: 'std::max' declared here
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc:77:7: error: 'A' was not declared in this scope
   77 |       A*=X;
      |       ^
a.cc:78:12: error: 'min' was not declared in this scope; did you mean 'std::min'?
   78 |       if(X=min(N,M)){
      |            ^~~
      |            std::min
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: 'std::min' declared here
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc:79:9: error: 'B' was not declared in this scope
   79 |         B+=A;
      |         ^
a.cc:82:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   82 |     cout<<A*B<<endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:82:11: error: 'A' was not declared in this scope
   82 |     cout<<A*B<<endl;
      |           ^
a.cc:82:13: error: 'B' was not declared in this scope
   82 |     cout<<A*B<<endl;
      |             ^
a.cc:82:16: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   82 |     cout<<A*B<<endl;
      |                ^~~~
      |                std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~