akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define one_peace ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int main()
{
    one_peace;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(d==1){cout<<1;}
    else{cout<<0;}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//priority_queue <int, vector <int>, greater <int> > pq; ..for min heap
using namespace std;
#define MOD 1000000007
#define PI 3.14159265358979323846264
#define pii pair <int, int>
#define pipii pair <int, pair <int, int> > 
#define piipi pair <pair <int, int>, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
#define FOR(i, x, y) for (int i=x; i<=y; i++)
#define FORD(i, y, x) for (int i=y; i>=x; i--)
#define debug printf("OK\n")
char s[100005], t[100005];
set <int> st[30];
int n, m;
bool check (ll x) {
    ll sum = 0;
    int last = -1;
    for (int i=0; i<m; i++) {
        auto k = st[t[i]-'a'].lower_bound(last + 1);
        if (k == st[t[i]-'a'].end()) {
            if (st[t[i]-'a'].empty()) {
                return false;
            }
            auto z = st[t[i]-'a'].begin();
            sum += n - 1 - last + *z + 1;
            last = *z;
        } else {
            if (last == -1) sum += *k + 1;
            else sum += *k - last;
            last = *k;
        }
    }
    return sum <= x;
}
int main() {
    scanf("%s %s", s, t);
    n = strlen(s);
    m = strlen(t);
    for (int i=0; i<n; i++) {
        st[s[i]-'a'].insert(i);
    }
    ll lo = 1, hi = 1e12, ans = -1;
    while (lo <= hi) {
        ll mid = (lo + hi) / 2;
        if (check(mid)) hi = mid - 1, ans = mid;
        else lo = mid + 1;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 7168
// #pragma GCC optimize("03")
#include <bits/stdc++.h>
#define ll long long 
#define fi first
#define se second
#define mod 1000000007

using namespace std;

int n, m;
char c[1010][1010];
int dp[1010][1010];

int main() {    
    // ifstream cin("tst.in");
    // ofstream cout("tst.out");
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> c[i][j];

    dp[1][1] = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            if (i + j == 2)
                continue;

            if (c[i][j] == '#')
                continue;

            if (i > 1)
                dp[i][j] += dp[i - 1][j];

            if (j > 1)
                dp[i][j] += dp[i][j - 1];

            if (dp[i][j] >= mod)
                dp[i][j] -= mod;
        }

    cout << dp[n][m];   

    return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;

int main(){
    int N;
    int64_t K;
    cin >> N >> K;
    /*
    vector<int> v;
    for(int i=0; i<N; i++){
        int a,b;
        cin >> a >> b;
        for(int j=0; j<b; j++){
            v.push_back(a);
        }
    }
    sort(v.begin(), v.end());
    cout << v.at(K-1) << endl;
    */
   vector<int64_t> v(100001, 0);
   for(int i=0; i<N; i++){
       int a,b;
       cin >> a >> b;
       v.at(a) += b;
   }
   for(int i=0; i< 100001; i++){
       if(K<=v.at(i)){
           cout << i << endl;
           break;
       }
       K -= v.at(i);
   }
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  if (N <= K) {
    cout << N * X << endl;
  }
  else {
    cout << K * X + (N - K) * Y << endl;
  }
}

Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 
int N;


int main(){

    int A,B;
    cin >> A;
    cin >> B;

    int cnt = 1;

    if(B==1) cout << 0 << endl;
    else{
        cout << (B-2) / (A-1) + 1 << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <list>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<pair<ll, ll> > xd(n);
  for (auto &x: xd) cin >> x.first >> x.second;

  sort(xd.begin(), xd.end());
  list<pair<ll, ll> > group;
  group.push_front(pair<ll, ll>(2, xd[n-1].first));
  for (int i = n-2; i >= 0; i--) {
    if (xd[i].first + xd[i].second - 1 < group.begin()->second) {
      group.push_front(pair<ll, ll>(2, xd[i].first));
    }
    else {
      while(true) {
        auto it1 = group.begin();
        auto it2 = group.begin();
        it2++;
        if (it2 == group.end()) break;
        if (xd[i].first + xd[i].second - 1 >= it2->second) {
          it2->first = (it1->first * it2->first) % mod;
          group.erase(it1);
        }
        else break;
      }
      group.begin()->first = (group.begin()->first + 1) % mod;
      group.begin()->second = xd[i].first;
    }
  }

  ll ans = 1;
  for (auto &x: group) {
    ans = (ans * x.first) % mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int x, y;
  cin >> x >> y;
  if ((y - 2 * x) % 2 == 0 && y >= 2 * x && (y - 2 * x) / 2 <= x) {
    cout << "Yes\n";
  } else {
    cout << "No\n"; 
  }
  return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
 
typedef long long LL;
typedef pair<int, int> PII;

const int MAX = 100;

int solve(vector<int> a)
{
	while(SZ(a) > 1)
	{
		vector<int> b(SZ(a) - 1);
		FOR(i, 0, SZ(a) - 1)
			b[i] = abs(a[i] - a[i + 1]);
		a = b;
	}
	return a[0];
}

int a[MAX];
int N;
int cnt = 0;

int f(int n)
{
	int res = 0;
	while(n)
	{
		res += n / 2;
		n /= 2;
	}
	return res;
}

void rec(int pos)
{
	if(pos == N)
	{
		vector<int> v(a, a + N);
		int res = solve(v);
		int only13 = true;
		FOR(i, 0, N)
			only13 &= a[i] != 2;
		if(res == 2)
		{
			
			FOR(i, 0, N)
				cout << a[i];
			cout << endl;
		}
		return;
	}
	FOR(x, 1, 4)
	{
		a[pos] = x;
		rec(pos + 1);
	}
}

int main()
{
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	string s;
	cin >> n >> s;
	int sum = 0;
	bool only13 = true;
	int xr = 0;
	FOR(i, 0, n)
	{
		if(f(n - 1) == f(i) + f(n - 1 - i))
		{
			sum += s[i] - '0';
			xr ^= s[i] - '0';
		}
		only13 &= s[i] != '2';
		
	}
	if(sum & 1)
	{
		cout << "1\n";
		return 0;
	}
	if(!only13)
	{
		cout << "0\n";
		return 0;
	}
	cout << (xr ? 2 : 0) << "\n";
	return 0;
}


Measured memory_bytes: 1412
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;


int main() {
	vector<int>odds,evens;
	int N;cin>>N;
	for (int i = 0; i < N; ++i) {
		int a;cin>>a;
		if(a%2)odds.push_back(a);
		else evens.push_back(a);
	}
	sort(odds.begin(),odds.end(),greater<int>());
	int answer=0;
	answer=accumulate(evens.begin(),evens.end(),0);
	bool flag=odds.size()%2;
	answer=accumulate(odds.begin(),(flag?odds.end()-1:odds.end()),answer);
	cout<<answer/2<<endl;
	return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<vector<int>> ten(20, vector<int>(20, 0));
  int64_t res = 0;
  for (int i = 0; i < N; i++) {
    double x;
    cin >> x;
    int64_t y = x * 1000000000 + 0.1;
    int two = 0, five = 0;
    while (y % 2 == 0) {
      y /= 2;
      two++;
    }
    while (y % 5 == 0) {
      y /= 5;
      five++;
    }
    two = min(two, 18);
    five = min(five, 18);
    for (int j = 18 - two; j <= 18; j++) {
      for (int k = 18 - five; k <= 18; k++) {
        res += ten[j][k];
      }
    }
    ten[two][five]++;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 3716
#include <iostream>

using namespace std;

int main(){
  int card[4][13] = {};
  int n;
  char a;
  int b;
  
  cin >> n;
  for( int i = 0; i < n; ++i){
    cin >> a >> b;
    if( a == 'S' ) card[0][b-1] = 1;
    if( a == 'H' ) card[1][b-1] = 1;
    if( a == 'C' ) card[2][b-1] = 1;
    if( a == 'D' ) card[3][b-1] = 1;
  }

  for( int i = 0; i < 13; ++i){
    if( !card[0][i] ) cout << "S " << i+1 << endl;
  }
  for( int i = 0; i < 13; ++i){
    if( !card[1][i] ) cout << "H " << i+1 << endl;
  }
  for( int i = 0; i < 13; ++i){
    if( !card[2][i] ) cout << "C " << i+1 << endl;
  }
  for( int i = 0; i < 13; ++i){
    if( !card[3][i] ) cout << "D " << i+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <cmath>
#include <math.h>

int main() {
    double a, b, C;
    std::cin >> a >> b >> C;

    double radian = C / 180 * M_PI;
    double h = b * std::sin(radian);
    double S = a * h / 2;
    double shahen = std::sqrt(h * h + std::pow(b * std::cos(radian) - a, 2));
    double L = a + b + shahen;

    std::cout << std::fixed << S << " " << L << " " << h << std::endl;
}



Measured memory_bytes: 3512
import sys
from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
A = Counter([int(_) for _ in stdin.readline().rstrip().split()]).most_common()
B = [t for t in A if t[1] >= 2]
B.sort(reverse=True)
if len(B) < 2:
    print(0)
    sys.exit()
if B[0][1] >= 4:
    print(B[0][0]**2)
else:
    print(B[0][0]*B[1][0])

Measured memory_bytes: 21412
#-*-coding:utf-8-*-

def main():
    #入力
    N = int(input())
    a = list(map(int, input().split()))

    #変数
    count = 0

    for i in a:
        while i % 2 == 0:
            i /= 2
            count += 1 
            
    print(count)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 4212
#include <bits/stdc++.h>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int adj[105][105] = {0};
int res[105][2] = {0};
int t = 1;
int n;

int dfs(int start){
    if(res[start][0] == 0)
        res[start][0] = t;
    t++;
    REP(i, n)
        if(adj[start][i] != 0 && res[i][0] == 0)
            dfs(i);
    res[start][1] = t;
    t++;
    return 0;
}

int main() {
    cin >> n;
    REP(i, n){
        int u, k;
        cin >> u >> k;
        REP(j, k) {
            int tmp;
            cin >> tmp;
            adj[u-1][tmp-1] = 1;
        }
    }
    REP(i, n)
        if(res[i][0] == 0)
            dfs(i);
    REP(i, n)
        cout << i+1 << " " << res[i][0] << " " << res[i][1] << endl;
    return 0;
}

Measured memory_bytes: 1200
#include<iostream>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,k,l;
    cin>>n;
    k=n/100;
    l=n%100;
    if((l>0 && l<13) && (k>0 && k<13))
        cout<<"AMBIGUOUS"<<endl;
    else if((l>0 && l<13))
        cout<<"YYMM"<<endl;
    else if((k>0 && k<13))
        cout<<"MMYY"<<endl;
    else
        cout<<"NA"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
using namespace std;

int main(){
	int n,m,c;
	cin >> n >> m >> c;
	int b[m];
	for(int i = 0; i < m; i++)cin >> b[i];
	int a[n][m];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++)cin >> a[i][j];
	}
	int res = 0;
	for(int i = 0; i < n; i++){
		int num = 0;
		for(int j = 0; j < m; j++)num += a[i][j] * b[j];
		if(num + c > 0)res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
using namespace std;
int main(void){
  int n,k,x=1;
  cin >> n >> k;
  while(n!=0){
    if(x<k)
      x=x*2;
    else
      x+=k;
    n--;
  }
  cout << x << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    ll r = 0, g = 0, b = 0;

    rep(i, N) {
        if (S[i] == 'R') r++;
        if (S[i] == 'G') g++;
        if (S[i] == 'B') b++;
    }
    ll result = r * g * b;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1 ; j < N; j++) {
            if(S[i] == S[j]) continue;
            int k = (j - i) + j;
            if (k >= N || S[k] == S[i] || S[k] == S[j]) continue;
            result--;
        }
    }
    
    cout << result << endl;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int A;
		for (int i = 0; i < N; i++) {
			A = scanner.nextInt();
			if (A % 2 == 0) {
				if (A % 3 != 0 && A % 5 != 0) {
					System.out.println("DENIED");
					return;
				}
			}
		}
		System.out.println("APPROVED");
	}

}


Measured memory_bytes: 22612
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int mi = 1, ma = n;
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        mi = max(mi, l);
        ma = min(ma, r);
    }
    cout << max(0, ma - mi + 1) << '\n';
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    double ans=0;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        double a;
        std::cin >> a;
        ans+=(1/a);
    }
    std::cout << 1/ans << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;

int main()
{
  int a,b,c,n;

  while(1){
    cin>>n;
    vector<pair<pair<int,int>,int> > vpp;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      vpp.push_back(mp(mp(a,b),c));
    }
    sort(vpp.begin(),vpp.end());

    int dp[400][400]={};
    for(int i=0;i<400;i++)for(int j=0;j<400;j++)dp[i][j]=-1;

    dp[0][0]=0;
    for(int i=0;i<n;i++){
      for(int j=365;j>=0;j--){
	for(int k=0;k<vpp[i].f.f;k++){
	  if(dp[j][k]!=-1)
	    dp[j][vpp[i].f.s]=max(dp[j][vpp[i].f.s],dp[j][k]+vpp[i].s);
	  if(dp[k][j]!=-1)
	    dp[vpp[i].f.s][j]=max(dp[vpp[i].f.s][j],dp[k][j]+vpp[i].s);
	}
      }
    }
    int ans=0;
    for(int i=0;i<=365;i++)
      for(int j=0;j<=365;j++)ans=max(ans,dp[i][j]);

    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1856
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int a[100005],s[100005],n,m; 
int check(int mid){
	int sum=0;
	FOR(i,1,n){
		sum=sum+n-(lower_bound(a+1,a+n+1,mid-a[i])-a)+1;
	}
	return sum;
}
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	cin>>n>>m;
	FOR(i,1,n)cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=n;i>=1;i--)s[i]=s[i+1]+a[i];
	int l=0,r=1000000000,mid,ans=-1;
	while(r>=l){
		mid=(l+r)>>1;
		if(check(mid)>=m){
			ans=mid;l=mid+1;
		}else r=mid-1;
	} 
	int sum=0;
	FOR(i,1,n){
		int t=lower_bound(a+1,a+n+1,ans-a[i])-a;
		sum=sum+a[i]*(n-t+1)+s[t];
	}
	cout<<sum-(check(ans)-m)*ans;
	return 0;
}




Measured memory_bytes: 1792
#include<cstdio>
int main()
{
	int n;scanf("%d",&n);
	if(n==111) return printf("3\n"),0;
	if(n==11||n==101||n==110) return printf("2\n"),0;
	if(n==1||n==10||n==100) return printf("1\n"),0;
	printf("0\n");return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
const int maxn=1e6+10;
int  xx[100005],a[maxn],b[maxn];
int main()
{
    int n,h;
    cin>>h>>n;
    for(int i=0;i<n;i++)
    {
        sint2(a[i],b[i]);
    }
    for(int i=1;i<=h;i++)
    {
        int x=1e9+10;
        for(int j=0;j<n;j++)
        {
            if(i-a[j]<=0)
            {
                x=min(x,b[j]);
            }
            else
            {
                int k;
                if(i%a[j])
                    k=i/a[j]+1;
                else
                    k=i/a[j];
                x=min(x,min(xx[i-a[j]]+b[j],k*b[j]));
            }
        }
        xx[i]=x;
    }
    printf("%d\n",xx[h]);
    return 0;
}


Measured memory_bytes: 4352
/**
 *  author: MOOONI
 *  hackers are welcome!
**/
#include <bits/stdc++.h>

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

const int N = (int) 1e5 + 10;

vector<int> g[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<int> que;
  que.push_back(0);
  vector<int> par(n, -1);
  for (int b = 0; b < (int) que.size(); b++) {
    int v = que[b];
    for (int u : g[v]) {
      if (par[u] == -1) {
        par[u] = v;
        que.push_back(u);
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (par[i] == -1) {
      cout << "No" << '\n';
      return 0;
    }
  }
  cout << "Yes" << '\n';
  for (int i = 1; i < n; i++) {
    cout << par[i] + 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 10700
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	pair<int,int> a[2*n];
	char c;
	int b;
	for (int i = 0; i < 2*n; ++i)
	{
		cin>>c>>b;--b;
		a[i].first=(c=='B');
		a[i].second=b;
	}
	int wh[n+5][n+5]={},bk[n+5][n+5]={},wn[n+5]={},bn[n+5]={};
	for (int i = 0; i < 2*n; ++i)
	{
		int ws[n+5]={},bs[n+5]={};
		for (int j = n-1; j >= 0; --j)
		{
			ws[j]=ws[j+1]+wn[j];
			bs[j]=bs[j+1]+bn[j];
		}
		for (int j = n; j >= 0; --j)
		{
			if (a[i].first==0)
			{
				wh[a[i].second][j]=ws[a[i].second+1]+bs[j];
			}
			else
			{
				bk[a[i].second][j]=bs[a[i].second+1]+ws[j];
			}
		}
		if (a[i].first==0)
		{
			++wn[a[i].second];
		}
		else
		{
			++bn[a[i].second];
		}
	}
	int dp[n+5][n+5];
	for (int i = 0; i < n+5; ++i)
	{
		for (int j = 0; j < n+5; ++j)
		{
			dp[i][j]=1000000000;
		}
	}
	dp[0][0]=0;
	for (int i = 0; i <= n; ++i)
	{
		for (int j = 0; j <= n; ++j)
		{
			if (i<n)
			{
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]+bk[i][j]);
			}
			if (j<n)
			{
				dp[i][j+1]=min(dp[i][j+1],dp[i][j]+wh[j][i]);
			}
		}
	}
	cout<<dp[n][n]<<endl;
	return 0;
}


Measured memory_bytes: 47360
#include<stdio.h>
int main(void)
{
	int Alice, Bob;
	scanf("%d %d", &Alice, &Bob);
	if (Alice > Bob && 1 < Bob) {
		printf("Alice");
	}
	else if (Alice < Bob && Alice == 1) {
		printf("Alice");
	}
	else if (Alice == Bob) {
		printf("Draw");
	}
	else {
		printf("Bob");
	}
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
	int n, i, j;
	cin >> n;
	vl a(n), b(n);
	ll suma = 0, sumb = 0;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		suma += a[i];
	}
	for (i = 0; i < n; i++) {
		cin >> b[i];
		sumb += b[i];
	}
	ll m = sumb - suma;
	if (m < 0) {
		cout << "No" << endl;
		return 0;
	}
	ll ma = m, mb = m;
	for (i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			continue;
		}
		else if (a[i] > b[i]) {
			mb -= (a[i] - b[i]);
			b[i] = a[i];
		}
		else {
			if ((b[i] - a[i]) % 2 != 0) {
				mb--;
				b[i]++;
			}
			ma -= (b[i] - a[i]) / 2;
			a[i] = b[i];
		}
		if (ma < 0 || mb < 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	if (mb == 2 * ma && a == b) {
		cout << "Yes" << endl;
		return 0;
	}
	else {
		cout << "No" << endl;
		return 0;
	}


}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;

int main(){
  long long N;
  cin>>N;
  int k=log10(N)+1;
  //cout<<k<<endl;
  long long h=pow(10,k-1);
  long long x = N/h;
  h = x*h;
  if(N%10!=9) h--;
  else h=N;
  long ans =0;
  while(h>10){
    ans += h%10;
    h /=10;
  }
  ans +=h;
  if(N<10) ans =N;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
module Main where

import Control.Applicative
import Numeric
import Data.List

main :: IO ()
main = do
  { [n] <- getInts
  ; cards <- loop n
  ; putCards (allcards \\ cards)
  }

putCards :: [(Suit, Int)] -> IO ()
putCards = putStr . unlines . map showCard

loop :: Int -> IO [(Suit, Int)]
loop 0 = return []
loop n = do
  { c  <- getCard
  ; cs <- loop (n-1)
  ; return (c:cs)
  }

showCard :: (Suit, Int) -> String
showCard (s, n) = show s ++ " " ++ show n

--

data Suit = S | H | C | D deriving (Eq, Ord, Show, Read)

allcards :: [(Suit, Int)]
allcards = [ (s,r) | s <- [S, H, C, D], r <- [1..13] ]

getCard :: IO (Suit, Int)
getCard = do
  { [s, r] <- words <$> getLine
  ; return (read s, read r)
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



Measured memory_bytes: 4232
#include<iostream>
#include<string>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

int main(){
  int a[3],ans;
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  cout << abs(ans=(a[0]-a[1])+(a[1]-a[2]));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll h, w, n;
  cin >> h >> w >> n;
  ll k = max(h, w);
  cout << (n + k - 1) / k << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#define print(n) std::cout << n << std::endl
using namespace std;


int main() {
   int n;
   cin >> n;

   int count = 0;

    for (int i = 0; i < n; i++){
        if(to_string(i + 1).size() % 2 == 1) count++;
    }
    print(count);

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;

const int INF = 100000000;

int main(int argc, char const *argv[]){
    int n, m, k;
    int cost[100][100];
    int time[100][100];

    while (cin>>n>>m, n||m){
        for (int i = 0; i < 100; i++){
            for (int j = 0; j < 100; j++){
                if (i == j) {
                    cost[i][j] = 0;
                    time[i][j] = 0;
                }
                else{
                    cost[i][j] = INF;
                    time[i][j] = INF;
                }
            }
        }

        for (int i = 0; i < n; i++){
            int a, b, c, t;
            cin>>a>>b>>c>>t;
            a--; b--;

            cost[a][b] = c;
            cost[b][a] = c;
            time[a][b] = t;
            time[b][a] = t;
        }

        for (int s = 0; s < m; s++){
            for (int i = 0; i < m; i++){
                for (int j = 0; j < m; j++){
                    cost[i][j] = min(cost[i][j], cost[i][s] + cost[s][j]);
                    time[i][j] = min(time[i][j], time[i][s] + time[s][j]);
                }
            }
        }

        cin>>k;
        for (int i = 0; i < k; i++)
        {
            int p, q, r;
            cin>>p>>q>>r;
            p--; q--;

            if (r){
                cout<<time[p][q]<<endl;
            }
            else{
                cout<<cost[p][q]<<endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3024
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	static class P implements Comparable<P>{
		int time;
		int value;
		P(int a , int b){
			time = a;
			value = b;
		}
		@Override
		public int compareTo(P o) {
			return time - o.time;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A[] = new int[N];
		int B[] = new int[N];
		List<P> lst = new ArrayList<P>();
		for(int i = 0 ; i < N ; ++i){
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
			lst.add(new P(A[i] , B[i]));
		}
		Collections.sort(lst);
		int ans = 0;
		int dp[] = new int[T + 1];
		Arrays.fill(dp, -1);
		dp[0] = 0;
		for(P p : lst){			
			int next[] = dp.clone();
			int a = p.time;
			int b = p.value;
			for(int j = 0 ; j < T ; ++j){
				if(dp[j] < 0){
					continue;
				}
				if(j + a >= T){
					ans = Math.max(ans, dp[j] + b);
				}else{
					next[j + a] = Math.max(next[j + a], dp[j] + b);
				}
			}
			dp = next;
		}
		for(int d : dp){
			ans = Math.max(ans, d);
		}
//		System.out.println(Arrays.toString(dp));
		System.out.println(ans);
	}	
}


Measured memory_bytes: 44968
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,c,k = map(int,ipt().split())
    t = [int(ipt()) for i in range(n)]

    t.sort()
    t0 = t[0]
    n = 1
    ans = 0
    for i in t[1::]:
        if n == c or i > k+t0:
            ans += 1
            n = 1
            t0 = i
        else:
            n += 1
    ans += 1
    print(ans)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 79796
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;cin >> S;
  long long L=S.size(),k=0;
  for (int i=L-1;i>=1;i--) {
    if (i%2==0 && k==0) {
	  long long r=1;
	  for (int j=0;j<i/2;j++) {
	    if (S[j]!=S[i/2+j]) r=0;
	  }
	  if (r) {k=1;cout << i << endl;}
	}
  }
}


Measured memory_bytes: 256
#include <cstdio>
int main() {
    int k, x;
    scanf("%d%d",&k,&x);
    int temp;
    temp = x - k + 1;
    int s, e;
    if (temp < -1000000)
        s = -1000000;
    else
        s = temp;
    temp = x + k - 1;
    if (temp > 1000000)
        e = 1000000;
    else
        e = temp;
    printf("%d",s);
    for (int i = s + 1; i <= e; i++) {
        printf(" %d",i);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

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

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    vector<ll> a(n),s(n+1,0);
    Rep(i,n){
        cin >> a[i];
        s[i+1] = s[i]+a[i];
    }
    vector<ll> b;
    Rep(i,n){
        for(ll j = i+1; j<n+1; j++){
            b.emplace_back(s[j]-s[i]);
        }
    }
    ll x = *max_element(all(b));
    ll t = b.size();
    ll ans = 0;
    RRep(i,40){
        ll c = 0;
        ans += (1ll<<i);
        Rep(i,t){
            if((ans&b[i])==ans) c++;
        }
        if(c<k) ans -= (1ll<<i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3, y3, x4, y4;
  x3=y1-y2+x2;
  y3=y2-(x1-x2);
  x4=y1-y2+x1;
  y4=y1-(x1-x2);
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();

		int dx = x2 - x1;//4
		int dy = y2 - y1;//3

		StringBuilder sb = new StringBuilder();
		sb.append(x2 - dy);
		sb.append(" ");
		sb.append(y2 + dx);
		sb.append(" ");
		sb.append(x1 - dy);
		sb.append(" ");
		sb.append(y1 + dx);
		System.out.println(sb.toString());
	}
}




Measured memory_bytes: 23252
#include<iostream>

using namespace std;

int main(){
    int n;
    int student[31]={0};
    for(int i=1;i<=30;i++){
        cin>>n;
        student[n]=1;
    }
    for(int i=1;i<=30;i++)
        if(!student[i])
           cout<<i<<endl;
    return 0;
}

Measured memory_bytes: 1160
import  numpy as np
pos1 = [False for i in range(10)]

pos2 = [False for i in range(10*10)]

pos3 = [False for i in range(10*10*10)]


n = int(input())
s = input()


for i in range(n):
    k = int(s[i])

    for j in range(100):
        if pos2[j]:
            pos3[j*10+k] = True

    for j in range(10):
        if pos1[j]:
            pos2[j*10+k] = True

    for j in range(10):
        pos1[k] = True



print(np.sum(pos3))

Measured memory_bytes: 21676
import numpy as np

N,M,C=map(int,input().split())
B=input().split()
A=[]
Ans=[]
count=0
for i in range(M):
    B[i]=int(B[i])
for i in range(N):
    A.append(input().split())
for i in range(N):
    for j in range(M):
        A[i][j]=int(A[i][j])
B=np.array(B)
A=np.array(A)
#print(A,B)
Ans=np.dot(A,B)+C
Ans=Ans.tolist()
for i in range(len(Ans)):
    if Ans[i]>0:
        count=count+1
print(count)

Measured memory_bytes: 12392
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

int main() {
	int n,T;
	cin >> n>>T;
	VI c(n), t(n);
	rep(i, n) cin >> c[i]>>t[i];

	int minv = INF;
	rep(i, n) {
		if (t[i] <= T) {
			chmin(minv, c[i]);
		}
		//cout << minv << endl;
	}

	if (minv == INF) {
		cout << "TLE" << endl;
	} else {
		cout << minv << endl;
	}

}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    if(k-a<=0)
    {
        cout << k << endl;
    }else{
        if(k-a-b<=0){
            cout << a << endl;
        }else{
            cout << (a - (k - a - b)) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main()
{
	int num;
	scanf("%d", &num);
	int t = 1, s = 1;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		if (z % 2 == 0)t *= 2;
		s *= 3;
	}
	printf("%d\n", s - t);
}

Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll n, t, m, p, x;
	ll sum = 0;
	ll ans = 0;
	vector<ll> v;

	cin >> n;

	REP(i, n) {
		cin >> t;
		v.push_back(t);
		sum += t;
	}

	cin >> m;

	REP(i, m) {
		cin >> p >> x;

		ans = sum - (v[p - 1] - x);

		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

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

int N, K;
int x[102];

int s;

int main() {
  
  cin>>N>>K;
  rep(i, N)cin>>x[i];
  
  rep(i, N)s += (x[i]<(K-x[i]) ? x[i] : (K-x[i]));
  
  cout<<2*s<<endl;
  
  return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0

    for i in range(N-1):
        if A[i] > A[i+1]:
            tmp = A[i] - A[i+1]
            A[i+1] += tmp
            ans += tmp
    
    print(ans)
   # print(A)        

if __name__ == "__main__":
    solve()


Measured memory_bytes: 32244
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

typedef struct {
	int64_t A;
	int64_t B;
} pair;

int compare_f(const void *a, const void *b) {
	const int64_t aDiff = ((pair *)a)->A - ((pair *)a)->B;
	const int64_t bDiff = ((pair *)b)->A - ((pair *)b)->B;

	return aDiff > bDiff ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

static pair p[100000];

int main(void) {
	size_t N;
	int64_t sumA = 0;
	int64_t sumB = 0;
	int64_t shortageSum = 0;
	size_t shortageCount = 0;

	scanf("%zu\n", &N);
	for (size_t i = 0; i < N; i++) {
		scanf("%"PRId64, &(p[i].A));
		if (i < N - 1) {
			scanf(" ");
		}

		sumA += p[i].A;
	}
	scanf("\n");
	for (size_t i = 0; i < N; i++) {
		scanf("%"PRId64, &(p[i].B));
		if (i < N - 1) {
			scanf(" ");
		}

		sumB += p[i].B;
		if (p[i].A < p[i].B) {
			shortageSum += p[i].B - p[i].A;
			shortageCount++;
		}
	}

	size_t repCount = 0;

	if (sumA < sumB){
		printf("%d\n", -1);
	}
	else {
		qsort(p, N, sizeof(pair), compare_f);

		int64_t sum = 0;
		for (size_t i = 0; i < N; i++) {
			if (shortageSum <= sum) {
				repCount = i;
				break;
			}

			sum += p[i].A - p[i].B;
		}

		printf("%zu\n", shortageCount + repCount);
	}

	return 0;
}

Measured memory_bytes: 3324
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)2e5 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

int n, m;
ll cur1 = 1, cur2 = 1;
int main (){
  scanf ("%d %d", &n, &m);
  forn (i, 1, n){
    (cur1 *= 1ll * i) %= INF;
  }
  forn (i, 1, m){
    (cur2 *= 1ll * i) %= INF;
  }
  ll ans = 0;
  if (n == m){
    (ans = (2 * cur1 * cur2)) %= INF;
  } else if (n + 1 == m || m + 1 == n){
    (ans = (cur1 * cur2)) %= INF;
  }
  printf ("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  int l,r;
  int a = 0;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> l >> r;
    a += (r - l + 1);
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

int main() {
    int h,w;cin>>h>>w;
    char s[h][w];rep(i,h)rep(j,w)cin>>s[i][j];
    rep(i,h) {
        rep(j, w) {
            if (s[i][j]=='.') {
                int n = 0;
                if(0<=i-1 && i-1<h && 0<=j-1 && j-1<w && s[i-1][j-1]=='#') n++;
                if(0<=i-1 && i-1<h && 0<=j   && j  <w && s[i-1][j] == '#') n++;
                if(0<=i-1 && i-1<h && 0<=j+1 && j+1<w && s[i-1][j+1]=='#') n++;
                if(0<=i   && i  <h && 0<=j-1 && j-1<w && s[i][j-1] == '#') n++;
                if(0<=i   && i  <h && 0<=j+1 && j+1<w && s[i][j+1] == '#') n++;
                if(0<=i+1 && i+1<h && 0<=j-1 && j-1<w && s[i+1][j-1]=='#') n++;
                if(0<=i+1 && i+1<h && 0<=j   && j  <w && s[i+1][j] == '#') n++;
                if(0<=i+1 && i+1<h && 0<=j+1 && j+1<w && s[i+1][j+1]=='#') n++;
                cout<<n;
            }
            else cout<<'#';
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < SIZE; ++i) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

LL Bin(LL n, LL k) {
    if(k < 0 || n < k) {
        return 0;

    }
    LL ret = 1;
    for(LL i = 1; i <= k; ++i) {
        ret *= n--;
        ret /= i;

    }
    return ret;
}

LL H(LL x, LL y) {
    return comb(x + y - 1, x - 1);

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    LL n, k;
    cin >> n >> k;
    combInit();

    LL res = 0;
    for(int i = 0; i <= min(k, n - 1); ++i) {
        res = (res + (comb(n, i) * H(n - i, i)) % MOD) % MOD;

    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  //fact 階乗　iface 階乗の逆数
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} c(1000005);

vector<pair<ll,int>> prime_factor(ll n) {
  vector<pair<ll,int>>res;
  for(ll i = 2; i * i <= n; i++) {
    if(n % i == 0) {
      int t = 1;
      n /= i;
      while(n%i==0){
        t++;
        n/=i;
      }
      res.push_back(pair<ll,int>(i,t));
    }
  }
  if(n != 1) res.push_back(pair<ll,int>(n,1));
  return res;
}

int main(){
  int n,m;
  cin >> n >> m;
  auto vp = prime_factor(m);
  mint ans = 1;
  for(auto p:vp){
    ans *= c(n-1+p.second,n-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    string s;
    cin>>s;
    int n=s.length();

    rep(i,(n-1)/2){
        if(s[i]!=s[n-1-i]){
            cout<<"No\n";
            return 0;
        }
    }

    rep(i,(n+1)/4){
        if(s[i]!=s[(n-1)/2-1-i] || s[(n+1)/2+i]!=s[n-1-i]){
            cout<<"No\n";
            return 0;
        }
    }

    cout<<"Yes\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>

using namespace std;


struct I{I(){ios::sync_with_stdio(false);cin.tie(0);}}init;

typedef long long LL;

typedef vector<int> V;
typedef vector<V> VV;
typedef VV Graph;

const LL MOD=1e9+7;
int main(){
    int N;cin>>N;
    V a(N);for(auto &it:a)cin>>it;
    LL res=1e16;
    for(LL i=-100;i<=100;i++){
        LL ans=0;
        for(auto &it:a)ans+=(i-it)*(i-it);
        res=min(res,ans);
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 2507
using namespace std;
int n,m,p,dis[M],num[M];
bool flag[M],mark[M],f;
struct mo {
	int to,co;
};
vector<mo>q[M];
queue<int>Q;
vector<int>d[M];
void spfa() {
	Q.push(1);
	flag[1]=1;
	for(int i=1;i<=n;i++)dis[i]=-1e9;
	dis[1]=0;
	while(!Q.empty()) {
		int x=Q.front();
		Q.pop(),flag[x]=0;
		for(int i=0; i<(int)q[x].size(); i++) {
			mo Mo=q[x][i];
			if(!mark[Mo.to])continue;
			if(dis[Mo.to]<dis[x]+Mo.co-p) {
				dis[Mo.to]=dis[x]+Mo.co-p,num[Mo.to]=num[x]+1;
				if(num[Mo.to]>n){
					f=1;
					return;
				}
				if(!flag[Mo.to])Q.push(Mo.to),flag[Mo.to]=1;
			}
		}
	}
}
void dfs(int x) {
	if(mark[x])return;
	mark[x]=1;
	for(int i=0; i<(int)d[x].size(); i++)
		dfs(d[x][i]);
}
int main() {
	scanf("%d%d%d",&n,&m,&p);
	for(int i=1,a,b,c; i<=m; i++) {
		scanf("%d%d%d",&a,&b,&c);
		q[a].push_back((mo)<%b,c%>);
		d[b].push_back(a);
	}
	dfs(n),spfa();
	if(f)puts("-1");
	else printf("%d",max(0,dis[n]));
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MAXN 114
#define MAXW 10010

unsigned short N;
unsigned long W;
unsigned long long v[MAXN], w[MAXN];
unsigned long long dp[MAXN][MAXW];

int main() {
	ios::sync_with_stdio(false);
	memset(dp, 0, sizeof(dp));
	cin >> N >> W;
	for(unsigned long i=0; i<N; i++) {
		cin >> w[i] >> v[i];
	}
	for(unsigned long j=W; j>=w[0]; j--) {
		dp[0][j] = v[0];
	}
	for(unsigned long i=1; i<N; i++) {
		for(unsigned long j=W; j<=W; j--) {
			if(j>=w[i]) {
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
			} else {
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	unsigned long long ans = 0;
	for(unsigned long j=0; j<=W; j++) {
		ans = max(ans, dp[N-1][j]);
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 9216