https://www.luogu.org/problemnew/show/P1009

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
typedef __int128 lll;
const int N=100010;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int he[N],num[N],s[N];
inline void add()
{
    memset(he,0,sizeof(he));
    he[0]=max(s[0],num[0]);
    for(RI i=1;i<=he[0];++i)
    {
        he[i]+=s[i]+num[i];
        he[i+1]=he[i]/10;
        he[i]%=10;
    }
    while(he[ he[0]+1 ]>0)
    {
        he[ he[0]+2 ]=he[ he[0]+1 ]/10;
        he[ he[0]+1 ]%=10;
        he[0]++;
    }
    s[0]=he[0];
    for(RI i=1;i<=he[0];++i)
        s[i]=he[i];
}
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    scanf("%d",&n);
    num[0]=1,num[1]=1;
    s[0]=1,s[0]=0;
    for(RI k=1;k<=n;++k)
    {
        memset(he,0,sizeof(he));
        he[0]=num[0];
        for(RI i=1;i<=num[0];++i)
        {
            he[i]+=num[i]*k;
            he[i+1]=he[i]/10;
            he[i]%=10;
        }
        while(he[ he[0]+1 ]>0)
        {
            he[ he[0]+2 ]=he[ he[0]+1 ]/10;
            he[ he[0]+1 ]%=10;
            he[0]++;
        }
        for(RI i=1;i<=he[0];++i)
            num[i]=he[i];
        num[0]=he[0];
        add();
    }
    for(RI i=s[0];i>=1;--i)
        printf("%d",s[i]);
    puts("");
    //cout << "Hello world!" << endl;
    return 0;
}