stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <functional>

#define fs first

#define se second



using namespace std;

typedef long long llong;

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<llong, llong> pll;

typedef pair<ld, ld> pdd;



bool dp[101][10001];

int main() {

    ios_base::sync_with_stdio(0); cin.tie(0);

    dp[0][0] = 1;

    int n, x;

    cin >> n;

    for (int i = 1; i <= n; ++i) {

        cin >> x;

        for (int j = 0; j <= 10000; ++j) {

            if (dp[i - 1][j]) {

                dp[i][j] = 1;

                if (j + x <= 10000) dp[i][j + x] = 1;

            }

        }

    }

    int ans = 0;

    for (int i = 0; i <= 10000; ++i) {

        if (i % 10 && dp[n][i]) {

            ans = i;

        }

    }

    printf("%d\n", ans);

    return 0;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<string>

#include<cstring>

#include<cmath>

#include<ctime>

#include<algorithm>

#include<utility>

#include<stack>

#include<queue>

#include<vector>

#define INF 0x3f3f3f3f

#define LL long long

const int MOD = 1E9+7;

const int N = 1000000+5;

const int dx[] = {-1,1,0,0,-1,-1,1,1};

const int dy[] = {0,0,-1,1,-1,1,-1,1};

using namespace std;

 

int main() {

    int n;

    scanf("%d",&n);

    int sum=0;

    int minn=INF;

    bool flag=false;

    for(int i=1; i<=n; i++){

        int x;

        scanf("%d",&x);

        sum+=x;

        if(x%10!=0){

            flag=true;

            minn=min(minn,x);

        }

    }

 

    if(!flag)

        printf("0\n");

    else{

        if(sum%10!=0)

            printf("%d\n",sum);

        else

            printf("%d\n",sum-minn);

    }

 

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;

inline void read(long long &x) {

    char ch;

    bool flag = false;

    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;

    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());

    x = flag ? -x : x;

}

inline void write(long long x) {

    static const long long maxlen = 100;

    static char s[maxlen];

    if (x < 0) {   putchar('-'); x = -x;}

    if (!x) { putchar('0'); return; }

    long long len = 0; for (; x; x /= 10) s[len++] = x % 10 + '0';

    for (long long i = len - 1; i >= 0; --i) putchar(s[i]);

}



inline void read(int &x){

    char ch;

    bool flag = false;

    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;

    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());

    x = flag ? -x : x;

}



const int MAXN =101000;



int n;

int a[ MAXN ];

bool f[ MAXN ];



int main(){

    read(n);

    for (int i=1;i<=n;i++)

        read(a[i]);

    f[0]=1;

    for (int i=1;i<=n;i++)

        for (int j=MAXN-1;j>=a[i];j--)

            f[j]=f[j]||f[j-a[i]];

    for (int i=MAXN-1;i>=0;i--)

        if ( (f[i]) && ( i%10!=0) )

            {

                printf("%d\n",i);

                return 0;

            }

    puts("0");

    return 0;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#define LL long long

#define MEM(x,y) memset(x,y,sizeof(x))

#define MOD(x) ((x)%mod)

#define mod 1000000007

#define pb push_back

#define STREAM_FAST ios::sync_with_stdio(false)



using namespace std;

int a[107];

int main()

{

    int n;scanf("%d",&n);

    int sum=0;

    for (int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];

    sort(a+1,a+1+n);

    a[0]=0;

    for (int i=0;i<=n;i++)

    {

        if ((sum-a[i])%10!=0)

        {

            sum-=a[i];

            break;

        }

    }

    if (sum%10==0) sum=0;

    printf("%d\n",sum);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int n;

int a[205];

bool dp[105][10005];



int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++)

        scanf("%d",&a[i]);

    dp[0][0]=1;

    for(int i=1;i<=n;i++)

    {

        dp[i][0]=1;

        for(int j=1;j<=10005;j++)

        {

            dp[i][j]|=dp[i-1][j];

            if(j-a[i]>=0)

                dp[i][j]|=dp[i-1][j-a[i]];

        }

    }



    for(int j=10000;j>=0;j--)

    {

        if(j==0)

        {

            printf("0\n");

            return 0;

        }

        if(j%10==0)continue;

        if(dp[n][j])

        {

            printf("%d\n",j);

            return 0;

        }

    }



    return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>

using namespace std;



const int N = 110;



int q[N];



int main()

{

    int n;

    cin >> n;



    for (int i = 0; i < n ; i ++ )

        cin >> q[i];



    int sum = 0;



    sort(q,q+n);



    for (int i = 0; i < n; i ++ )

        sum += q[i];



        if(sum % 10 == 0)

        {

            for (int j = 0; j < n; j ++ )

            {

                if(q[j] % 10 != 0)

                    {

                        sum -= q[j];

                        cout << sum << endl;

                        return 0;

                    }

            }

        }

        else  cout << sum << endl;

        if(sum % 10 == 0) cout << "0" << endl;

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cstring>

#include <vector>

#include <map>

#include <set>

#include <list>

#include <algorithm>



#define REP(i, n) for(int i=0;i<n;i++)

#define ll long long

#define INF 999999999

#define pb(a) push_back(a)



using namespace std;



bool dp[100001];

int n;

vector<int> v;



int main(){



  scanf("%d", &n);

  REP(i, n){

    int t;

    scanf("%d", &t);

    v.pb(t);

  }



  REP(i, 100001) dp[i] = false;



  dp[0] = true;

  REP(i, n){

    for(int j = 100000; j >= 0; --j){

      if(dp[j]){

        dp[j + v[i]] = true;

      }

    }

  }



  int res = 0;

  REP(i, 100001){

    if(dp[i] && i % 10 != 0 && res < i){

      res = i;

    }

  }



  printf("%d\n", res);



  return 0;

}




// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cstring>

#include <climits>

#include <vector>

#include <map>

#include <set>

#include <list>

#include <stack>

#include <queue>

#include <algorithm>

#include <iostream>

#include <string>



#define REP(i,n) for(auto i=0;i<n;++i)

#define REPR(i,n) for(auto i=n;i>=0;--i)

#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)

#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)

#define FOR(i,a,b) for(auto i=a;i<b;++i)

#define SORT(v,n) sort(v, v+n)

#define SORTV(v) sort(v.begin(), v.end())

#define ALL(v) v.begin(),v.end()

#define llong long long

#define ll long long

#define INF 999999999

#define MOD 1000000007

#define pb push_back

#define pf push_front

#define MP make_pair

#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}



int dx[] = {0, 0, -1, 1};

int dy[] = {1, -1, 0, 0};



using namespace std;



typedef pair<int,int> pii;



bool dp[110][10010];



int main(){



  int n;

  cin >> n;

  vector<int> s(n);

  REP(i,n){

    cin >> s[i];

  }



  dp[0][0] = true;

  for(int i = 0; i < n; ++i){

    for(int j = 0; j <= n * 100; ++j){

      if(j - s[i] >= 0){

        dp[i+1][j] = max(dp[i][j-s[i]], dp[i][j]);

      }else{

        dp[i+1][j] = dp[i][j];

      }

    }

  }



  int ans = 0;

  REP(i,n*100+1){

    if(dp[n][i] && i % 10 != 0)

    ans = max(ans, i);

  }



  cout << ans << endl;



  return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

typedef long long ll;



const int maxn = 123;

int n , a[maxn] , dp[maxn][10009];





int calc(int x , int have)

{

	if(x == n)

	{

		if(have % 10 == 0) return 0;

		else return have;

	}

	if(dp[x][have] != -1) return dp[x][have];

	int ret = 0;

	ret = max(calc(x + 1 , have) , calc(x + 1 , have + a[x]));

	return dp[x][have] = ret;

}



int main()

{

	ios_base::sync_with_stdio(0); cin.tie(NULL);

	memset(dp,-1,sizeof(dp));

	cin >> n;

	for(int i=0;i<n;i++) cin >> a[i];		

	cout << calc(0 , 0) << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

typedef long long ll;



const int maxn = 123;

int n , a[maxn];

bool dp[maxn][10009];



int main()

{

	ios_base::sync_with_stdio(0); cin.tie(NULL);

	cin >> n;

	for(int i=0;i<n;i++) cin >> a[i];

	for(int i=0;i<=n;i++) dp[i][0] = 1;

	for(int i=1;i<=n;i++)

	{

		for(int have=1;have<=10000;have++)

		{

			if(have - a[i-1] >= 0) dp[i][have] = dp[i-1][have] | dp[i-1][have - a[i-1]];

			else dp[i][have] = dp[i-1][have];

		}

	}

	

	for(int i=10000;i>0;i--)

	{

		if(dp[n][i] && i % 10 != 0)

		{

			cout << i << endl;

			return 0;

		}

	}

	cout << 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>



using namespace std;



int dp[101][10001];

int main() {

    int N;

    cin >> N;

    vector<int> S;

    for(int i = 0; i < N; i++) {

        int s;

        cin >> s;

        S.push_back(s);

    }

    

    dp[0][0] = 1;

    

    for(int i = 0; i < N; i++) {

        for(int j = 0; j < 10001; j++) {

            if (dp[i][j] != 0) {

                dp[i + 1][j + S[i]] |= dp[i][j];

            }

            dp[i + 1][j] |= dp[i][j];

        }

    }

    

    for(int j = 10000; j >= 0; j--) {

        if (dp[N][j] != 0 && (j % 10 != 0)) {

            cout << j << endl;

            break;

        }

        if (j == 0) {

            cout << 0 << endl;

        }

    }

    

    

    return 0;

}

// Optimized solution to the same problem (faster):
#include <map>

#include <set>

#include <list>

#include <cmath>

#include <queue>

#include <stack>

#include <cstdio>

#include <string>

#include <vector>

#include <complex>

#include <cstdlib>

#include <cstring>

#include <numeric>

#include <sstream>

#include <iostream>

#include <algorithm>

#include <functional>

  

#define mp       make_pair

#define pb       push_back

#define all(x)   (x).begin(),(x).end()

#define rep(i,n) for(int i=0;i<(n);i++)

  

using namespace std;

  

typedef    long long          ll;

typedef    unsigned long long ull;

typedef    vector<bool>       vb;

typedef    vector<int>        vi;

typedef    vector<vb>         vvb;

typedef    vector<vi>         vvi;

typedef    pair<int,int>      pii;

  

const int INF=1<<29;

const double EPS=1e-9;

  

const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};





int main() {

  int N;

  cin >> N;

  vector<ll> S(N);

  ll sum = 0;

  for (int i = 0; i < N; i++) {

    cin >> S[i];

    sum += S[i];

  }



  if (sum % 10 != 0) {

    cout << sum << endl;

  } else {

    ll mi = 1LL << 61;

    for(int i = 0; i < N; i++) {

      if (S[i] % 10 == 0) continue;

      mi = min(mi, S[i]);

    }

    if (mi == 1LL << 61) {

      cout << 0 << endl;

    } else {

      cout << sum - mi << endl;

    }

  }



  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int dp(int now,int sum);

int n;

int a[109];

int memo[109][10009];



int main(){

  memset(memo,-1,sizeof(memo));

  cin>>n;

  for(int i=0;i<n;i++){

    cin>>a[i];

  }

  cout<<dp(0,0)<<endl;

}



int dp(int now,int sum){

  int rec=0;

  if(memo[now][sum]!=-1)return memo[now][sum];

  if(now==n){

    if(sum%10==0)return 0;

    else return sum;

  }

  rec=max(rec,dp(now+1,sum));

  rec=max(rec,dp(now+1,sum+a[now]));

  return memo[now][sum]=rec;

}

  


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

int dp[109][10009];



int main(){

  int n,s=10000;

  int a[109];

  cin>>n;

  for(int i=0;i<n;i++){

    cin>>a[i];

  }

  dp[0][0]=true;

  for(int i=0;i<n;i++){

    for(int j=0;j<=s;j++){

      if(j-a[i]<0){

	dp[i+1][j]=dp[i][j];

      }

      else{

	dp[i+1][j]=dp[i][j]|dp[i][j-a[i]];

      }

    }

  }

  int ans=0;

  for(int i=0;i<=s;i++){

    if(dp[n][i]&&i%10!=0){

      ans=i;

    }

  }

  cout<<ans<<endl;

  return(0);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i, a, n) for(int i = a; i < n; i++)

#define repb(i, a, b) for(int i = a; i >= b; i--)

#define all(a) a.begin(), a.end()

#define o(a) cout << a << endl

#define int long long

#define fi first

#define se second

using namespace std;

typedef pair<int, int> P;



int dp[10010];



signed main(){

    int n;

    cin >> n;

    int d[110] = {};

    rep(i, 0, n) cin >> d[i];

    rep(i, 0, 10010) dp[i] = -1; 

    dp[0] = 0;

    rep(i, 0, n){

        repb(j, 10000, 0){

            if(j - d[i] >= 0 && dp[j - d[i]] != -1){

                dp[j] = 1;

            }

        }

    }

    int ans = 0;

    rep(i, 0, 10010) if(dp[i] == 1 && i % 10 != 0) ans = i;

    cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i, a, n) for(int i = a; i < n; i++)

#define REP(i, n) rep(i, 0, n)

#define repb(i, a, b) for(int i = a; i >= b; i--)

#define all(a) a.begin(), a.end()

#define int long long

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

using namespace std;

typedef pair<int, int> P;

const int mod = 1000000007;

const int INF = 1e12;



signed main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    int n;

    cin >> n;

    vector<int> s(n);

    int sum = 0;

    rep(i, 0, n){

        cin >> s[i];

        sum += s[i];

    }

    sort(all(s));

    bool f = false;

    if(sum % 10 == 0) f = true;

    rep(i, 0, n){

        if(f && s[i] % 10 != 0){

            sum -= s[i];

            f = false;

        }

    }

    if(f == false) cout << sum << endl;

    else cout << 0 << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main() {

    int x, a, b;

    cin >> x >> a >> b;

    int diff_a = abs(x - a), diff_b = abs(x - b);

    if(diff_a < diff_b) cout << "A" << endl;

    else cout << "B" << endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

  int z, A, B;

  scanf("%d %d %d", &z, &A, &B);

  int distA = (z > A) ? z - A : A - z;

  int distB = (z > B) ? z - B : B - z;

  (distA < distB) ? puts("A") : puts("B");

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()

{

    int x,a,b;

    scanf("%d %d %d",&x,&a,&b);

    if(abs(x-a)<abs(x-b))

        printf("A\n");

    else

        printf("B\n");







    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

  int z, A, B;

  scanf("%d %d %d", &z, &A, &B);

  int distA = (z > A) ? z - A : A - z;

  int distB = (z > B) ? z - B : B - z;

  (distA < distB) ? puts("A") : puts("B");

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cmath>



using namespace std;



int main(){

    int x,a,b;

    cin >> x >> a >> b;

    a=abs(a-x);

    b=abs(b-x);

    if (a>b){

        cout << "B" << " ";

    }

    else if (b>a){

        cout << "A" << " ";

    }

    else {

        cout << "A" ;

    }

    return 0;

}









/*#include <iostream>



using namespace std;



int main() {

        int a,b;

        cin >> a >> b;

        b*=2;

        b-=a;

        cout << b ;

    return 0;

}*/


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

  int z, A, B;

  scanf("%d %d %d", &z, &A, &B);

  int distA = (z > A) ? z - A : A - z;

  int distB = (z > B) ? z - B : B - z;

  (distA < distB) ? puts("A") : puts("B");

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

typedef long long int ll;

using namespace std;

ll a,b,i,j,x,y,n,m;

ll arr[1000];

int main()

{

    cin >> a >> n >> m;

    x = a-n;

    y = a-m;

    if (x<0)

        x*=-1;

    if (y<0)

        y*=-1;



    if (x>y)

        cout << "B\n";

    else

        cout << "A\n";







    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

  int z, A, B;

  scanf("%d %d %d", &z, &A, &B);

  int distA = (z > A) ? z - A : A - z;

  int distB = (z > B) ? z - B : B - z;

  (distA < distB) ? puts("A") : puts("B");

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

    int main()

    {

        int x,a,b;

        cin>>x>>a>>b;



        if(abs(x - a) < abs(x - b))

           cout<<"A";

           else

            cout<<"B";

    }


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

  int z, A, B;

  scanf("%d %d %d", &z, &A, &B);

  int distA = (z > A) ? z - A : A - z;

  int distB = (z > B) ? z - B : B - z;

  (distA < distB) ? puts("A") : puts("B");

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cmath>



using namespace std;



int main()

{

    int a, b, c;

    cin>>a>>b>>c;

    if(abs(a - b) > abs(a - c)) cout<<"B"<<endl;

    else cout<<"A"<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

  int z, A, B;

  scanf("%d %d %d", &z, &A, &B);

  int distA = (z > A) ? z - A : A - z;

  int distB = (z > B) ? z - B : B - z;

  (distA < distB) ? puts("A") : puts("B");

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cmath>

using namespace std;

int main()

{

	int x=0,A=0,B=0;

	cin >> x >> A>>B;

	if(abs(x-A)>abs(x-B)) 

	{

		cout<<"B";

	}else 

	{

		cout<<"A";

	}

	

	return 0;

 } 

// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

	

	int x, a, b;

	scanf("%d %d %d", &x, &a, &b);

	

	int aa;

	if(a>=x){

		aa=a-x;

	}

	else{

		aa=x-a;

	}



	int bb;

	if(b>=x){

		bb=b-x;

	}

	else{

		bb=x-b;

	}

	

	if(aa<bb){

		printf("A\n");

	}

	else{

		printf("B\n");

	}



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdlib>



using namespace std;



int main()

{

  int x, a, b;

  cin >> x >> a >> b;

  cout << (abs(x - a) < abs(x - b) ? 'A' : 'B') << endl;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstdlib>



int main()

{

        int x, a, b;

        scanf("%d%d%d", &x, &a, &b);



        int dstA = abs(x - a), dstB = abs(x - b);

        char ans = dstA < dstB ? 'A' : 'B';

        printf("%c\n", ans);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

    int x, a, b;

    cin >> x >> a >> b;



    if (abs(x - a) > abs(x - b))

        cout << "B" << endl;

    else cout << "A" << endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

	int pos,a,b;

	scanf("%d %d %d", &pos, &a, &b);

	int disa, disb;

	if(pos > a){

		disa = pos - a;

	}else{

		disa = a - pos;

	}

	if(pos > b){

		disb = pos - b;

	}else{

		disb = b - pos;

	}

	if(disa > disb){

		puts("B");

	}else{

		puts("A");

	}

	

	

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<stdio.h>

#include<iostream>

#include<math.h>

#include<stdlib.h>

using namespace std;





int main(){

    int a,b,x;

    cin>>x>>a>>b;

    a=abs(x-a);

    b=abs(x-b);

    if(a<b){

        cout<<"A";

    }

    else{

        cout<<"B";

    }



    return 0;



}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

	int pos,a,b;

	scanf("%d %d %d", &pos, &a, &b);

	int disa, disb;

	if(pos > a){

		disa = pos - a;

	}else{

		disa = a - pos;

	}

	if(pos > b){

		disb = pos - b;

	}else{

		disb = b - pos;

	}

	if(disa > disb){

		puts("B");

	}else{

		puts("A");

	}

	

	

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cmath>

using namespace  std;



int main()

{

    int x,y,z;

    while(cin>>x>>y>>z)

    {

        if(abs(y-x)>=abs(z-x))

        {

            cout<<"B"<<endl;

        }

        else cout<<"A"<<endl;

    }

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

  int line, store1, store2;

  scanf("%d %d %d", &line, &store1, &store2);

  int distA = (line > store1) ? line - store1 : store1 - line;

  int distB = (line > store2) ? line - store2 : store2 - line;

  (distA < distB) ? puts("A") : puts("B");

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main ()

{

    int x,a,b;

    cin>>x>>a>>b;

    a=x-a;

    a=abs(a);

    b=x-b;

    b=abs(b);

    if(a>b)

        cout<<"B";

    else

        cout<<"A";

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

  int line, store1, store2;

  scanf("%d %d %d", &line, &store1, &store2);

  int distA = (line > store1) ? line - store1 : store1 - line;

  int distB = (line > store2) ? line - store2 : store2 - line;

  (distA < distB) ? puts("A") : puts("B");

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

void meal(int x,int a,int b){

       if(abs(x-a)<abs(x-b)){

        cout<<"A"<<endl;

       }

       if(abs(x-b)<abs(x-a)){

        cout<<"B"<<endl;

       }

}

int main(){

   int x,a,b;

   cin>>x>>a>>b;

   meal(x,a,b);

   return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

  int W, A, B;

  scanf("%d %d %d", &W, &A, &B);

  int distA = (W > A) ? W - A : A - W;

  int distB = (W > B) ? W - B : B - W;

  (distA < distB) ? puts("A") : puts("B");

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;



typedef long long ll;



const int N = 1e5 + 5, Mod = 1e9 + 7;

int n, m;

ll fact[N];



int main() {

  ios::sync_with_stdio(false);

  cin >> n >> m;

  int offset = abs(n - m);

  fact[0] = 1;

  for (int i = 1; i < N; ++i)

    fact[i] = fact[i - 1] * i % Mod;

  if (offset > 1)

    cout << 0 << endl;

  else if (offset == 1) {

    cout << fact[m] * fact[n] % Mod << endl;

  } else

    cout << fact[m] * fact[n] * 2LL % Mod << endl;

  return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstdlib>

using namespace std;

typedef long long ll;

const int mod=1e9+7;

int n,m;

ll ans;

inline int abs(int x){return (x>0)?x:-x;}

inline void init(){

	scanf("%d%d",&n,&m);

	if (abs(n-m)>1) {

		puts("0");

		exit(0);

	} 

}

inline void solve(){

	ans=1;

	for (int i=1;i<=n;i++){

		(ans*=i)%=mod;

	}

	for (int i=1;i<=m;i++){

		(ans*=i)%=mod;

	}

	if (n==m) ans=ans*2%mod;

	printf("%lld\n",ans);

}

int main(){

	init();

	solve();

	return 0;

} 

// Fastest known solution for this problem: