akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#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)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define SORT(x) sort(x.begin(),x.end())
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vi a(n);
  vi b(n);
  rep(i,n){
    cin >> a[i];
    b[i] = a[i];
  }
  SORT(a);
  sort(b.begin(),b.end(),greater<int>());
  
  int ai=1,bi=0;
  ll l = a[0], r = a[0];
  ll ans = 0;
  while(ai+bi < n){
    // show(ai);
    // show(bi);
    ll diff1 = max(abs(l-a[ai]),abs(r-a[ai]));
    ll diff2 = max(abs(l-b[bi]),abs(r-b[bi]));
    if(diff1 > diff2){
      ans+= diff1;
      if(abs(l-a[ai])> abs(r-a[ai])) l = a[ai];
      else r = a[ai];
      ai++;
    }else{
      ans+=diff2;
      if(abs(l-b[bi])> abs(r-b[bi])) l = b[bi];
      else r = b[bi];
      bi++;      
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3

s = input()

for i in range(1<<3):
    sum = int(s[0])
    ans = s[0]
    for k in range(3):
        # print(k)
        if i>>k&1:
            sum += int(s[k+1])
            ans += '+' + s[k+1]
        else:
            sum -= int(s[k+1])
            ans += '-' + s[k+1]
    if sum == 7:
        print(ans + '=7')
        break


Measured memory_bytes: 3060
N,K = map(int,input().split())
A = list(map(int,input().split()))
tmp = [0]*N
tmp_2 = [0]*N
Cnt=0
result = 0
for i in range(N):
  tmp[A[i]-1]+= 1
  tmp_2[A[i]-1] = 1

m = sum(tmp_2)-K
if m>0:
	tmp = sorted(tmp)
	for i in range(N):
		if tmp[i]!=0:
			result += tmp[i]
			Cnt +=1
		if Cnt == m:
			break
    
print(result) 	 	

Measured memory_bytes: 25376
N, Q = map(int, input().split())
S = ' ' + input() + ' '

ps = [0, N+1]
dirs = { 'L': 1, 'R': -1 }
QS = [input().split() for _ in range(Q)][::-1]
p = 0
for t, d in QS:
  di = dirs[d]
  np = p + di
  if 0 <= np <= N+1 and di == 1 and S[np] == t:
    p += 1
  if 0 <= np <= N+1 and di == -1 and S[p] == t:
    p -= 1
p1 = p

p = N+1
for t, d in QS:
  di = dirs[d]
  np = p + di
  if 0 <= np <= N+1 and di == -1 and S[np] == t:
    p -= 1
  if 0 <= np <= N+1 and di == 1 and S[p] == t:
    p += 1
p2 = p
print(max(0, p2 - p1 - 1))

Measured memory_bytes: 40892
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n,x;
		int count = 0;
		while(true){
			n = sc.nextInt();
			x = sc.nextInt();
			if(n==0&&x==0)break;
			for(int i=1;i<=n-2;i++){
				for(int j=i+1;j<=n-1;j++){
					for(int k=j+1;k<=n;k++){
						if(i+j+k==x){
							count++;
							break;
						}
					}
				}
			}
			System.out.println(count);
			count=0;
		}
	}
}



Measured memory_bytes: 26556
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n,m; cin >> n >> m;
  vector<vector<int>> g(n);
  for(int i = 0; i < m; i++){
    int a,b; cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> dist(n,999999);
  dist[0] = 0;
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int now = q.front(); q.pop();
    for(int v: g[now]){
      if(dist[v] != 999999) continue;
      dist[v] = now+1;
      q.push(v);
    }
  }
  bool flg = true;
  for(int i = 1; i < n; i++){
    if(dist[i] == 999999) flg = false;
  }
  if(!flg){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  for(int i = 1; i < n; i++){
    cout << dist[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 10232
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
queue<pint> q;
int dp[1010][1010];
void aedge(int x,int y,int z){
	if(dp[x][y]>-1) return;
	//cout<<x<<y<<z<<endl;
	dp[x][y]=z;q.push(mp(x,y));
}
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
string a[1010];
int main()
{
	int h,w,out=0;cin>>h>>w;
	rep(i,h) cin>>a[i];
	memset(dp,-1,sizeof(dp));
	rep(i,h) rep(j,w){
		if(a[i][j]=='#') aedge(i,j,0);
	}
	while(!q.empty()){
		pint p=q.front();q.pop();
		out=max(out,dp[p.fi][p.se]);
		rep(i,4){
			int x=p.fi+dx[i],y=p.se+dy[i];
			if(x<0 || y<0 || x>=h || y>=w) continue;
			aedge(x,y,dp[p.fi][p.se]+1);
		}
	}
	cout<<out<<endl;
}


Measured memory_bytes: 13456
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int n,m,t;
struct node
{
	int l,r,no;
	bool operator<(const node s)const
	{
		return r<s.r;
	}
}a[500005];
int d[500005],c[500005],p[2000005],ans[500005];
int lowbit(int x)
{
	return x&(-x);
}
int sum(int x)
{
	int res=0;
	while(x>0)
	{
		res+=d[x];
		x-=lowbit(x);
	}
	return res;
}
void add(int x,int lazy)
{
	while(x<=n)
	{
		d[x]+=lazy;
		x+=lowbit(x);
	}
	return;
}
int main()
{
	scanf("%d%d",&n,&t);
	for(int i=1;i<=n;i++)
		scanf("%d",&c[i]);
	for(int i=1;i<=t;i++)
	{
		a[i].no=i;
	    scanf("%d%d",&a[i].l,&a[i].r);
	}
	sort(a+1,a+t+1);
	int beg=1;
	for(int i=1;i<=t;i++)
	{
		for(int j=beg;j<=a[i].r;j++)
		{
			if(!p[c[j]])
			    add(j,1);
			else
			{
				add(p[c[j]],-1);
				add(j,1);
			}
			p[c[j]]=j;
		}
		beg=a[i].r+1;
		ans[a[i].no]=sum(a[i].r)-sum(a[i].l-1);
	}
	for(int i=1;i<=t;i++)
	    printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 17456
/*
Author: Arham_doshi
@quote "Code like there's no tommorow!"
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
#include <bits/stdc++.h>

#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>

#define mi          map<int,int>
#define mii         map<pii,int>
#define piii           pair<int,pair<int,int> >


#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define ef else if
#define N           200005


using namespace std;

int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }  
bool mod(double a,double b) {return a/b - floor(a/b);}

int occurs(vi v,int n){
auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}

int logb(int base, int x) {
    return (log(x) / log(base));
}


 int power(int n,int Pow){
            int result=1;
            while(Pow>0){
                if(Pow%2==1){
                    result=(result*n)%MOD;
                }
                n=(n*n)%MOD;
               Pow/=2LL;
            }
            return result;
        }
        
int inverse(int a){
    return power(a,1000000005);
}        

int fun(int a,int b,int p){
  if(a<0)return 0;  
  int APB=1,A=1,B=1,i;
    
    fo(i,2,a+b+1){
        APB=(APB*i)%p;
    }
    
        fo(i,2,b+1){
        B=(B*i)%p;
    }
    
        fo(i,2,a+1){
        A=(A*i)%p;
    }
    
    return (APB%p*inverse(A)%p*inverse(B)%p)%p;
}

signed main()
{
    int i,j,x,y,a,b;
      cin>>x>>y;
    int c=2*y-x;
    
    if(c>=0&&c%3LL==0){
        
        b=c/3LL;
        a=(x-b)/2LL;
        //cout<<a<<" "<<b;
        int fact[a+b+1]={0};
        fact[0]=1;
        fact[1]=1;
        
        
        
       
            
            
        cout<<fun(a,b,1000000007);
        
        
        
        
    }
    else{
        cout<<0;
    }

    return 0;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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;
}

ll gcd(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

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

	return (ll)result;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) { //にぶたんgreater
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

vector<ll> Divisor(ll x) { // 約数列挙
	vector<ll> result;
	ll i=1LL;
	for( ; i*i<x; i++) {
		if(x%i) continue;
		result.push_back(i);
		result.push_back(x/i);
	}
	if(i*i==x&&x%i==0)
		result.push_back(i);
	
	sort(result.begin(),result.end());
	return result;
}

vector<llpair> PrimeFact(ll x) { // 素因数分解 {素因数,指数}
	vector<llpair> result;
	ll ex=0LL;
	if(x%2==0) {
		while(x%2==0) {
			x/=2;
			ex++;
		}
		result.push_back({2,ex});
	}

	for(ll i=3LL; i*i<=x; i+=2) {
		if(x%i) continue;

		ex=0LL;
		while(x%i==0) {
			x/=i;
			ex++;
		}
		result.push_back({i,ex});
	}

	if(x!=1) result.push_back({x,1});

	return result;
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}

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

	int num=0;
	for(int i=0; i<S.length(); i++) {
		if(S[i]=='(') {
			num++;
		}
		else {
			if(num==0) {
				S.insert(0,"(");
				i++;
			}
			else {
				num--;
			}
		}
	}
	for(int i=0; i<num; i++) {
		S+=")";
	}

	cout<<S<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	string s;
	cin >> s;
	
	bool yes = true;
	int n = s.size();
	
	for(int i = 0; i < (n - 1) / 2; ++i) {
		if( s[i] != s[(n - 1) / 2 - 1 - i] ) { 
			cout << "No" << endl;
			return 0;
		}
	}
	
	for(int i = (n - 1) / 2 + 1; i < n; ++i) {
		if( s[i] != s[n - 1 - i] ) { 
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl; 
	
	return 0;
}


Measured memory_bytes: 256
import heapq
n,m=map(int,input().split())
a=list(map(lambda x:-int(x),input().split()))
heapq.heapify(a)
for i in range(m):
    x=-heapq.heappop(a)
    heapq.heappush(a,-(x//2))
print(-sum(a))

Measured memory_bytes: 20292
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue
 
#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)
 
#define MN 200005
int n, m;
int a[MN];
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    cin >> n >> m;
  	n *= 2;
    F0R(i, n){
        cin >> a[i];
    }
 
    sort(a, a+n);
 
    int l = -1, r = n;
    while(l+1 < r){
        int mid = (l+r)/2;
        bool ok = true;
        FOR(i, mid, n-1){
            if(a[i]+a[n-1+mid-i] < m){
                ok = false;
                break;
            }
        }
 
        if(ok){
            r = mid;
        } else{
            l = mid;
        }
    }
    if(r%2==1)r++;
 
    int ans = 0;
    F0R(i, r-1){
        ans = max(ans, a[i]+a[r-1-i]);
    }
    FOR(i, r, n-1){
        ans = max(ans, a[i]+a[n-1+r-i]-m);
    }
 
    cout << ans << "\n";
 
    return 0;
}


Measured memory_bytes: 1024
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var s = o.a(1), t = o.a(1);
  return t+s;
}

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 1000005
#define PI 3.14159265358979323846264338327950
#define ll signed long long int
using namespace std;
ll t , n, ans, k, a[MAXX], b[MAXX], x, y, z;
double f = 0.5;
 
int main()
{
	cin >> n >> y >> z;
	vector<ll> v(n+5, y-z);
	for(ll i = 1; i <= z; i++){
		cin   >> a[i];
		b[a[i]] ++;
	}
	for(ll i = 0; i < n; i++){
		v[i] += b[i];
	}
	for(ll i = 1; i <= n; i++){
		if(v[i] > 0){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	return 0;
    
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e6+5,M=4100,p=1e9+7,ad=2002;
int fac[N],inv[N],finv[N];
int comb(int n,int m)
{
    if(n<m)return 0;
    return fac[n]*1ll*finv[m]%p*finv[n-m]%p;
}
int a[N],b[N],f[M][M];
int main()
{
    int n=8000;
    fac[0]=finv[0]=fac[1]=finv[1]=inv[1]=1;
    for(int i=2;i<=n;i++)
    {
        fac[i]=fac[i-1]*1ll*i%p;
        inv[i]=(p-p/i)*1ll*inv[p%i]%p;
        finv[i]=finv[i-1]*1ll*inv[i]%p;
    }
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        f[ad-a[i]][ad-b[i]]++;
    }
    for(int i=-2000;i<=2000;i++)
        for(int j=-2000;j<=2000;j++)
            f[ad+i][ad+j]=(1ll*f[ad+i][ad+j]+f[ad+i-1][ad+j]+f[ad+i][ad+j-1])%p;
    int ans=0;
    for(int i=1;i<=n;i++)
        ans=(1ll*ans+f[ad+a[i]][ad+b[i]]-comb(2*a[i]+2*b[i],2*a[i])+p)%p;
    ans=ans*500000004ll%p;
    printf("%d\n",ans);
}


Measured memory_bytes: 78080
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    rep(i,m){
        int k; cin >> k;
        rep(j,k){
            int s; cin >> s;
            s--;
            a[s] |= 1<<i;
        }
    }
    int p = 0;
    rep(i,m){
        int x; cin >> x;
        p |= x<<i;
    }
    int ans = 0;

    for(int i = 0; i<(1<<n); i++){
        int t = 0;
        rep(j,n){
            if(i>>j & 1){
                t ^= a[j];
            }
        }if(t==p) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools
n, k = map(int, input().split())
p = list(map(int, input().split()))

EV_acc = [0] + list(itertools.accumulate([(i+1)/2 for i in p]))

ans = max(EV_acc[i]-EV_acc[i-k] for i in range(k, n+1))
print(ans)

Measured memory_bytes: 33048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC124
{
    class Program
    {
        static void Main(string[] args)
        {
            Buttons();
        }

        static void Buttons()
        {
            int[] xs = ReadIntArray();

            int ans = 0;

            for(int i = 0; i < 2; i++)
            {
                if (xs[0] > xs[1])
                {
                    ans += xs[0]--;
                }
                else
                {
                    ans += xs[1]--;
                }
            }

            Console.WriteLine(ans);
        }

        public static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
    }
}


Measured memory_bytes: 13396
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    int alice=0, bob=0;
    REP(i, n){
        if(i%2==0){
            alice += a[i];
        }
        else{
            bob += a[i];
        }
    }

    cout << alice - bob << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;


int main(){
    int r;
    cin >> r ;
    cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();

        int t[] = new int[n];

        for (int x = 0; x != n; x++) {
            t[x] = scan.nextInt();
        }

        for (int i = n - 1; i >= 0; i--) {
            if (i != 0) {

                System.out.print(t[i] + " ");
            } else {
                System.out.println(t[i]);

            }
        }
    }
}



Measured memory_bytes: 26292
class struct:
  def __init__(self,a,b):
    self.a=a
    self.b=b
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append(struct(a,b))
l=sorted(l,key=lambda x:x.a)
su=0
for x in l:
  if x.b<m:
    m-=x.b
    su+=(x.a)*(x.b)
  else:
    su+=(x.a)*m
    break
print(su)

Measured memory_bytes: 29052
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int[] num = new int[2];
		while (true) {
			num[0] = scn.nextInt();
			num[1] = scn.nextInt();
			if (num[0] == 0 && num[1] == 0) {
				break;
			}
			Arrays.sort(num);
			System.out.println(num[0] +" "+ num[1]);
		}
	}
}



Measured memory_bytes: 37096
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int MAX_N = 100;
vector<int> G[MAX_N];
int d[MAX_N], f[MAX_N];
bool used[MAX_N];

int stamp;

void dfs(const int v) {
    d[v] = stamp++;
    used[v] = true;
    for(int i = 0; i < (int)G[v].size(); i++) {
        int u = G[v][i];
        if(used[u] == false) dfs(u);
    }
    f[v] = stamp++;
}

int main() {
    int N; cin >> N;
    for(int i = 0; i < N; i++) {
        int u, k; cin >> u >> k; u--;
        while(k--) {
            int v; cin >> v; v--;
            G[u].push_back(v);
        }
        sort(G[u].begin(), G[u].end());
    }

    fill(used, used + N, false);
    stamp = 1;
    for(int i = 0; i < N; i++) {
        if(used[i] == false) dfs(i);
    }

    for(int i = 0; i < N; i++) {
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int n, m, x;
    int back, front;
    cin >> n >> m >> x;
    vector<int> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a.at(i);
    }
    for (int i = 0; i < m; i++) {
        if (a.at(i) > x) {
            back = i;
            front = m - i;
            goto next;
        }
    }
    next:
    cout << min(back, front) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main(void){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
	double x[2],y[2],r[2],h;
		for(int j=0;j<2;j++){
			cin>>x[j]>>y[j]>>r[j];
		}
		h=hypot(abs(x[0]-x[1]),abs(y[0]-y[1]));
		if(r[1]+h<r[0])puts("2");
		else if(r[0]+h<r[1])puts("-2");
		else if(h<=r[0]+r[1])puts("1");
		else puts("0");
	}
}


Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main() {
    string A, B, S;
    cin >> A >> B >> S;
    string regex_str = "[0-9]{" + A + "}-[0-9]{" + B + "}";
    cout << (regex_match(S, regex(regex_str.c_str())) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ENDL '\n'
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FOR_EACH(i, v) for (auto&& i : v);

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

	int N;
	cin >> N;
	vector<int> up(N);
	vector<int> down(N);
	up.clear();
	down.clear();

	FOR(i, N) {
		int t;
		cin >> t;
		up.push_back(t);
	}
	FOR(i, N) {
		int t;
		cin >> t;
		down.push_back(t);
	}

	int ans = 0;
	FOR(i, N) {
		int tMax = 0;
		FOR(j, N) {
			if (j < i) {
				tMax += up[j];
			}
			else if (i < j) {
				tMax += down[j];
			}
			else {
				tMax += up[j] + down[j];
			}
		}
		ans = max(ans, tMax);
	}

	cout << ans << ENDL;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n, d;
    cin >> n >> d;
    vvi x(n, vector<int64_t>(d));
    for(int i=0; i<n; i++){
        for(int j=0; j<d; j++){
            cin >> x.at(i).at(j);
        }
    }
    int64_t dist = 0;
    int res = 0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            dist = 0;
            for(int k=0; k<d; k++){
                dist += (x.at(i).at(k) - x.at(j).at(k)) * (x.at(i).at(k) - x.at(j).at(k));
            }
            if(floor(sqrt(dist))==sqrt(dist)){
                res++;
            }
        }
    }
    cout << res << endl;
}


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

int main(){
	int i=0,check=0;
	string S,T;
	cin>>S>>T;
	if(S.length() > T.length()) check=1;
	if(check != 1){
		while(S[i] != '\0' && T[i] != '\0'){
			if(S[i] != T[i]) {
				check=1;
			}
			i++;
		}
		if(T[i] == '\0') check=1;
		else if(T[i+1] != '\0') check=1;

	}
	if(check) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200005;
int n,d,fail[N];
ll l,r,s[N][30];
char a[N];
void KMP(){
	int k=0;
	for (int i=2;i<=n;i++){
		for (;k&&a[k+1]!=a[i];) k=fail[k];
		fail[i]=(k+=(a[k+1]==a[i]));
	}
	d=n-fail[n];
}
ll fib(ll p,int c){
	if (p<=n) return s[p][c];
	if (p<=n*2) return s[n][c]+s[p-n][c];
	ll ans1=s[n][c]+s[d][c],ans2=s[n][c];
	ll a=n+d,b=n;
	for (;p>a+b;){
		ll c=ans1; ans1+=ans2; ans2=c;
		c=a; a+=b; b=c;
	}
	return ans1+fib(p-a,c);
}
ll calc(ll p,int c){
	if (p<=n) return s[p][c];
	if(n%d==0){
		ll ans=(p-n)/d*s[d][c]+s[n][c];
		return ans+s[(p-n)%d][c];
	}
	return fib(p,c);
}
int main(){
	scanf("%s",a+1);
	n=strlen(a+1)/2;
	for (int i=1;i<=n;i++){
		for (int j=0;j<26;j++)
			s[i][j]=s[i-1][j];
		s[i][a[i]-'a']++;
	}
	KMP();
	scanf("%lld%lld",&l,&r);
	for (int i=0;i<26;i++)
		printf("%lld ",calc(r,i)-calc(l-1,i));
}

Measured memory_bytes: 27264
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e3+100;
int n,a[maxn];
int main() {
    long long ans=1,ret=1;
    cin >> n;
    for(int i=1;i<=n;++i) {
        cin >> a[i];
        if(!(a[i]&1)) ret<<=1;
        ans*=3;
    }
    cout << ans-ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

bool isPrime(int num)
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
vector<int> primes;
void solve(long long N)
{
    for (int i = 2; i <= 55555; i++)
    {
        if (isPrime(i))
        {
            if (i % 5 == 4)
            {
                primes.push_back(i);
            }
        }
    }

    for (int i = 0; i < N; i++)
    {
        cout << primes[i] << endl;
    }
    
}

int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 10005
using namespace std;
int n, m;
int in[N];
int used[N];
vector<int> G[N];
void bfs(int s){
    queue<int> q;
    q.push(s);
    while(!q.empty()){
        int t = q.front(); q.pop();
        used[t] = 1;
        printf("%d\n", t);

        for(int i = 0; i < G[t].size(); i++){
            int v = G[t][i];
            in[v]--;
            if(in[v] == 0 && !used[v]) q.push(v);
        }
    }
}
int main(){
    scanf("%d %d", &n, &m);
    for(int i = 0; i < n; i++) {in[i] = 0; used[i] = 0;}
    for(int i = 0; i < m; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        in[b]++;
        G[a].push_back(b);
    }
    for(int i = 0; i < n; i++){
        if(!used[i] && in[i] == 0) bfs(i);
    }
    return 0;
}


Measured memory_bytes: 3856
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int p1 = a * x + b * y;
  int p2 = max(x, y) * c * 2;
  int p3 = min(x, y) * c * 2;
  if (x >= y)
    p3 += (x - y) * a;
  else
    p3 += (y - x) * b;
  cout << min({p1, p2, p3}) << endl;
}


Measured memory_bytes: 256
# python 3.8.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
from math import gcd
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def lcm(a,b):return (a*b) // gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,K = imn()

c = [0 for _ in range(N+1)]
c[0] = N
tmp = N
for i in range(1, N+1):
    c[i] = c[i-1] + tmp-i

ans = 0
for i in range(K, N+2):
    if i == 1:
        min_v = 0
        max_v = N
    else:
        min_v = i*(i-1)//2
        max_v = c[i-1]
    ans += max_v-min_v+1
print(ans%MOD)


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

#define MAX_NUM (998244353)

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

i64 My_Comb(u64 n, u64 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  k = (n / 2 < k) ? n - k : k;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}

u64 My_Pow(u64 a, u64 n, i64 m) {
  u64 tmp = n, calc = 1;
  while (tmp > 0) {
    if (tmp % 2) {
      tmp--;
      calc *= a;
      calc %= m;
    } else {
      a *= a;
      a %= m;
      tmp /= 2;
    }
  }
  return calc;
}
string S[10] = {"pon", "pon", "hon", "bon", "hon",
                "hon", "pon", "hon", "pon", "hon"};

int main() {
  cout << setprecision(18);

  i64 N;
  cin >> N;
  cout << S[N % 10] << endl;

  return 0;
}


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

int main(){
  set<int> s;
  int a,b,c;
  cin >> a >> b >> c;
  s.insert(a);
  s.insert(b);
  s.insert(c);
  if(s.size()==2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
   
struct Node{ int p, l, r;};
struct Node T[MAX];
int n, H, D[MAX];
int getDepth(int);
void print(int);
 
 
   
int main(){
  int i, j, d, v, c,l,r;
     
  scanf("%d",&n);
     
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
     
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
      T[c].p = v;
         
      if(j == 0) T[v].l = c;
         
      else if (j >= 1)
    T[r].r = c;
      r = c;
    }
  }
     
   
  for ( i = 0; i < n; i++ ){
    D[i] = getDepth(i);
  }
   
  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}
 
 
int getDepth(int u){
  int d = 0;
   
  while(T[u].p >= 0){
    u = T[u].p; 
    d++;
  }
   
  return d;
}
   
void print(int u){
  if(T[u].p == NIL)
    printf("node %d: parent = %d, depth = %d, root, ",u,T[u].p,D[u]);
     
  else if(T[u].l == NIL)
    printf("node %d: parent = %d, depth = %d, leaf, ",u,T[u].p,D[u]);
     
     
  else printf("node %d: parent = %d, depth = %d, internal node, ",u,T[u].p,D[u]);
     
     
  printf("[");
  int t; 
  t = u;
  if(T[t].l  != NIL){
    printf("%d",T[t].l);
    if(T[T[t].l].r == NIL)
      printf("]\n");
    else printf(",");
    t =T[t].l;
    while(T[t].r != NIL){
      printf(" %d",T[t].r);
   
      if(T[T[t].r].r == NIL)
    printf("]\n");
      else printf(",");
      t =T[t].r;
    }
  }
  else  printf("]\n");
}



Measured memory_bytes: 3292
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

#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)

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
template<typename T>
T lcm( T m, T n )
{
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long N,M;
    long long ans=0;
    cin >> N >>M;
    long long N_permutation=1;
    long long M_permutation=1;

    long long temp=N;
    while(temp>0){
        N_permutation*=temp%MOD;
        N_permutation%=MOD;
        temp--;
    }

    temp=M;
    while(temp>0){
        M_permutation*=temp%MOD;
        M_permutation%=MOD;
        temp--;
    }

    if(N==M){
        ans=N_permutation*M_permutation*2%MOD;
    }else if(N-1==M || M-1==N){
        ans=N_permutation*M_permutation%MOD;
    }else{
        ans=0;
    }

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



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int x, y; cin >> x >> y;
    ll ans = 0;
    if ((x > 0 && y > 0) || (x < 0 && y < 0)) {
        if (x < y) ans = y - x;
        else ans = abs(y - x) + 2;
    } else if ((x == 0 && y < 0) || (x > 0 && y == 0)) {
        ans = abs(y - x) + 1;
    } else {
        ans = min(abs(y - x), abs(x + y) + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int x, y,w;
    while(1){
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0){
            break;
        }
        if(x > y){
            w = x;
            x = y;
            y = w;
        }
        printf("%d %d\n", x, y);
    }
    return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int h,n;
  cin>>h>>n;
  PII m[n];
  rep(i,n){
    cin>>m[i].F>>m[i].S;
  }
  int dp[h+10];
  rep(i,h+10){
    dp[i]=INF;
  }
  dp[0]=0;
  rep(j,h+1){
    rep(i,n){
      if(j+m[i].F<=h){
	dp[j+m[i].F]=min(dp[j]+m[i].S,dp[j+m[i].F]);
      }else{
	dp[h]=min(dp[j]+m[i].S,dp[h]);
      }
    }
  }
  
  cout<<dp[h]<<endl;
  return 0;
}


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

int main()
{
	bool flag = false;

	while (true) {
		int n;
		cin >> n;

		if (n == 0) {
			break;
		}

		if (flag == true) {
			cout << endl;
		}
		else {
			flag = true;
		}

		int a, b, c, d;
		cin >> a >> b >> c >> d;

		int ans = 10000;
		int a_ans = 0;//10
		int b_ans = 0;//50
		int c_ans = 0;//100
		int d_ans = 0;//500

		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				for (int k = 0; k <= c; k++) {
					for (int l = 0; l <= d; l++) {
						if (i * 10 + j * 50 + k * 100 + l * 500 >= n) {
							int temp = i * 10 + j * 50 + k * 100 + l * 500 - n;
							int d_change = temp / 500;
							temp %= 500;
							int c_change = temp / 100;
							temp %= 100;
							int b_change = temp / 50;
							temp %= 50;
							int a_change = temp / 10;

							if (a_change != 0 && i != 0) {
								break;
							}
							else if (b_change != 0 && j != 0) {
								break;
							}
							else if (c_change != 0 && k != 0) {
								break;
							}
							else if (d_change != 0 && l != 0) {
								break;
							}
							else {
								if (a + b + c + d - i - j - k - l + a_change + b_change + c_change + d_change < ans) {
									ans = a + b + c + d - i - j - k - l + a_change + b_change + c_change + d_change;
									a_ans = i;
									b_ans = j;
									c_ans = k;
									d_ans = l;
								}
							}
						}
					}
				}
			}
		}

		if (a_ans != 0) {
			cout << 10 << " " << a_ans << endl;
		}
		if (b_ans != 0) {
			cout << 50 << " " << b_ans << endl;
		}
		if (c_ans != 0) {
			cout << 100 << " " << c_ans << endl;
		}
		if (d_ans != 0) {
			cout << 500 << " " << d_ans << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3088
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();
    std::io::stdin()
        .read_line(&mut line)
        .map_err(|err| format!("{:?}", err))?;

    let xs = line.trim().split_whitespace();
    let mut result = Vec::new();

    for x in xs {
        let ans = x.parse::<T>().map_err(|_| format!("{}", "parse error"))?;
        result.push(ans);
    }
    Ok(result)
}

fn main() {
    // let (a, b) = read_parameters::<isize>().map(|xs| (xs[0], xs[1])).unwrap();
    let mut a = read_parameters::<isize>().unwrap();
    a.sort();

    println!("{} {} {}", a[0], a[1], a[2]);
}



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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        ll a, b; cin >> a >> b;
        a = __gcd(a, b);
        int ans = 1;
        for (ll div = 2; div * div <= a; div++) {
                if (a % div) continue;
                ans++;
                while (a % div == 0) {
                        a /= div;
                }
        }

        if (a > 1) ans++;

        cout << ans << '\n';
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

#ifndef _WIN32
    #define getchar getchar_unlocked
#endif

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

typedef long long int LLI;
typedef unsigned long long int LLU;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<int> vi;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',') cerr<<*sdbg++;
  cerr<<"="<<h<<",";
  _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int h = 100, w = 100;
char t[h][w];

int32_t main()
{
	for(int i = 0; i < h/2; ++i)
		for(int j = 0; j < w; ++j)
			t[i][j] = '.';
	for(int i = h/2; i < h; ++i)
		for(int j = 0; j < w; ++j)
			t[i][j] = '#';
	int A, B; scanf("%d%d", &A, &B);

	int tmp = B - 1;
	for(int i = 1; i < h / 2 && tmp > 0; i += 2){
		for(int j = 1; j < w && tmp > 0; j += 2){
			t[i][j] = '#';
			--tmp;
		}
	}
	tmp = A - 1;
	for(int i = h / 2 + 1; i < h && tmp > 0; i += 2){
		for(int j = 1; j < w && tmp > 0; j += 2){
			t[i][j] = '.';
			--tmp;
		}
	}
	printf("%d %d\n", h, w);
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j)
			printf("%c", t[i][j]);
		puts("");
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <iostream>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;

int main(){
    int a;
    string s;
    cin  >> a>> s;
    if(a >= 3200){
        cout << s << endl;
    }else{
        cout << "red"<<endl;
    }


    return 0;
}


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

int main() {
	// your code goes here
	ll n;
	cin>>n;
	ll a[n],s=0;
	for(ll i=0;i<n;i++){
	   cin>>a[i];
	   s=s+a[i];
	}
	map<ll,ll> m;
	for(ll i=0;i<n;i++)
	    m[a[i]]++;
	ll q;
	cin>>q;
	for(ll i=1;i<=q;i++)
	{
	    ll b,c;
	    cin>>b>>c;
	    s=s-(b*m[b]);
	    s=s+(c*m[b]);
	    m[c]=m[c]+m[b];
	    m[b]=0;
	    cout<<s<<endl;
	}
}


Measured memory_bytes: 10140