akhauriyash/Code-Regression huggingface dataset:
//                        Bismillahir Rahmanir Rahim
//ALGO:
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define FILL(a, x) memset(a, x, sizeof(a))
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define INF INT_MAX
#define mx 1000010
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update>
*/
const double Pi=acos(-1);
using namespace std;
int debug=01;
long double p[3010], dp[3010][3010];
int n;
long double solve(int i, int c){
    if(i==n){
        if(c>(n/2)) return 1.0;
        return 0.0;
    }
    if(dp[i][c]!=-1) return dp[i][c];
    return dp[i][c]=solve(i+1, c+1)*p[i]+solve(i+1, c)*(1.0-p[i]);
}
int main() {
    cin>>n;
    for(int i=0; i<n; i++) cin>>p[i];
    FILL(dp, -1);
    cout<<fixed<<setprecision(10)<<solve(0, 0);
}



Measured memory_bytes: 142080
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef pair<ll, pair<int, int>> P;
typedef pair<ll,pair<ll,ll>> T;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;


int main(){
    ll D,N;
    cin >> D >> N;
    if(N == 100){
        N++;
    }
    ll ans = pow(100, D) * N;
    cout << fixed << setprecision(10) << ans << endl;
    
    
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
typedef long long int ll;
void llswap(ll *x,ll *y){ll tmp;tmp=*x;*x=*y;*y=tmp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}

int main(){
    int n,h[200000];

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
    }

    int dp[200000]={};
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    
    for(int i=2;i<n;i++){
        dp[i]=rmin(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        //2コ前の足場からきたときと、1コ前の足場からきたときで比較する。
        //それぞれの足場まで行くために必要なコストの最小値を記録しておく。
    }
    printf("%d\n",dp[n-1]);
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
 
int main(){
  string s;
  cin>>s;
  int a,b,c,d;
  a=s[0]-'0';
  b=s[1]-'0';
  c=s[2]-'0';
  d=s[3]-'0';
 
  if(a+b+c+d==7){
    cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
    return 0;
  }
  if(a-b+c+d==7){
    cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
    return 0;
  }
  if(a+b-c+d==7){
    cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
    return 0;
  }
  if(a+b+c-d==7){
    cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
    return 0;
  }
  if(a+b-c-d==7){
    cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
    return 0;
  }
  if(a-b-c+d==7){
    cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
    return 0;
  }
  if(a-b+c-d==7){
    cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
    return 0;
  }
  if(a-b-c-d==7){
    cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
    return 0;
  }
 
 
 
  return 0;
}

Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    S = SI()
    if S[-1] == 's':
        S += 'es'
    else:
        S += 's'
    print(S)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68820
#include <bits/stdc++.h>
#define fo(i,n) for(i=0;i<n;++i)
#define forr(i,n) for(i=n-1;i>0;--i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

ll gcd(ll a,ll b){while(a&&b)a>b?a%=b:b%=a;return a+b;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    char c;
    cin>>c;
    if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
        cout<<"vowel"<<endl;
    else
        cout<<"consonant"<<endl;
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
const int maxn=55;
int n,m,ans=0;
int a[maxn],b[maxn];
int graph[maxn][maxn];
bool vis[maxn];
void dfs(int x)
{
	vis[x]=true;
	for(int i=0;i<n;i++)
	{
		if(!graph[x][i]||vis[i])
			continue;
		dfs(i);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<maxn;i++)
		for(int j=0;j<maxn;j++)
			graph[i][j]=false;
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",a+i,b+i);
		--a[i],--b[i];
		graph[a[i]][b[i]]=true;
		graph[b[i]][a[i]]=true;
	}
	for(int i=0;i<m;i++)
	{
		graph[a[i]][b[i]]=false;
		graph[b[i]][a[i]]=false; 
		memset(vis,false,sizeof(vis));
		dfs(0);
		int bridge=false;
		for(int j=0;j<n;j++)
			if(!vis[j])
			{
				bridge=true;
				break;
			}
		ans+=bridge;
		graph[a[i]][b[i]]=true;
		graph[b[i]][a[i]]=true;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  LL A, B, K; cin >> A >> B >> K;
  if (A >= K) {
    cout << A-K << " " << B << endl;
    return 0;
  }
  K -= A;
  cout << 0 << " " << max(0LL, B - K) << endl;
}


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

#define int long long

#define MAX 100

signed main(){

  int N;
  int a[MAX], used[MAX] = {}, num = 1;
  
  vector<int> ans;

  cin>>N;

  for(int i = 0; i < N; i++){
    cin>>a[i];
  }

  for(int i = 0; i < N; i++){
    if(a[i] == 2 || a[i] == -2) used[i] = true;
    if(a[i] == -2) num *= -1;
  }
  
  if(num == -1){
    bool flag = false;
    for(int i = 0; i < N; i++){
      if(a[i] == -1){
	flag = true;
	used[i] = true;
	break;
      }
    }
    
    if(flag == false){
      for(int i = N-1; i >= 0; i--){
	if(a[i] == -2){
	  used[i] = false;
	  break;
	}
      }
    }
  }
  
  for(int i = 0; i < N; i++){
    if(used[i] == true) ans.push_back(i);
  }

  cout<<ans.size()<<endl;
  
  for(int i = 0; i < ans.size(); i++){
    cout<<ans[i]+1<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3148
from collections import deque
H, W = map(int, input().split())
C = []
Q = deque()
dist = [[-1]*W for i in range(H)]

for i in range(H):
  s = list(input())
  yxidx = [(i,x) for x,v in enumerate(s) if v == "#"]
  for (y, x) in yxidx:
    Q.append((y,x))
    dist[y][x] = 0
  C.append(s)
X = [1,0,-1,0]
Y = [0,-1,0,1]


while Q:
  y,x = Q.popleft()
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dist[ny][nx] == -1):
      dist[ny][nx] = dist[y][x] + 1
      Q.append((ny,nx))

ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)


Measured memory_bytes: 125276
#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 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 sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#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))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

int tot;
void out(int ans) {
  int a = (tot+ans)/2;
  int b = tot-a;
  cout<<a<<" "<<b<<endl;
}

bool f(vi& s, vi& t, int x) {
  int n = sz(s);
  int l = s[0];
  rep(i,n) {
    if (t[i] >= l+x) {
      if (i == n-1) return true;
      // mins(l,s[i]);
      mins(l,s[i+1]);
    }
  }
  return false;
}

int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  cin>>a;
  tot = suma(a);
  a.insert(a.begin(),0);
  rep(i,n) if (i&1) a[i+1] *= -1;
  rep(i,n) a[i+1] += a[i];
  if (n%2 == 0) {
    int ans = abs(a.back());
    out(ans);
    return 0;
  }
  vi s, t;
  rep(i,n+1) {
    if (i&1) {
      t.pb(a[i]);
    } else {
      s.pb(a[i]);
    }
  }
  int l = -INF, r = INF;
  while (l+1<r) {
    int c = (l+r)>>1;
    if (f(s,t,c)) l = c; else r = c;
  }
  // cerr<<l<<endl;
  int ans = -a.back() + l*2;
  out(ans);
  return 0;
}






















Measured memory_bytes: 5100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			//渡される定数
			String[] number = (input.readLine()).split("\\s");//入力数値をスペース前後で分割
			int n = Integer.parseInt(number[0]);//1からn番目(前)
			int x = Integer.parseInt(number[1]);//合計値x(後)

			if (n == 0 && x == 0) {//両方0の時抜ける
				break;
			}

			int count = 0;//組み合わせのが何種類かあるかの初期化
			int s = x / 3;//合計の1/3未満の数(超えると計算できないため)
			for (int i = 1; i < s; i++) {//要素数1 一番小さい数

				int m = (x - i) / 2;//合計から最小を引いた半分の数(超えると計算できないため)
				for (int j = i + 1; j <= m; j++) {//要素数2 jは確定でiより大きい

					int k = x - i - j;//最大値k　sとmは上限なので実数値はiとj

					if (j < k && k <= n) {//kはjより大きくなければならない

						count++;//上記が達成時に種類が増えるので追加

						//for (int k = 0; k <= n; k++) {//要素数3　一番大きい数
					}
				}
			}
			System.out.println(count);

		}
	}
}



Measured memory_bytes: 24464
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


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

    int N;
    cin >> N;
    vector<ll> a(N), b(N);
    rep(i, N) cin >> a[i] >> b[i];

    ll cnt = 0;
    for(int i = N - 1; i >= 0; i--){
        a[i] += cnt;
        if(a[i] % b[i] != 0){
            cnt += b[i] - (a[i] % b[i]);
        }
    }
    cout << cnt << endl;
    return 0;
}


// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


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

long long n, a[90]={2,1};
int main() {
    cin >> n;
    rep(i, 2, n + 1) {
        a[i] = a[i - 1] + a[i - 2];
    }
    cout << a[n] << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=12e4,M=2*N;

int fa[N],ne[M],la[N],lb[M],size[N],zd[N];
ll len[M],ans=0;
int oo,n;
ll ok=0;

inline void llb(int a,int b,ll z)
{ne[++oo]=la[a]; la[a]=oo; lb[oo]=b; len[oo]=z;};

inline int min(int a,int b)
{return a<b?a:b;}

inline int max(int a,int b)
{return a>b?a:b;}

inline ll min(ll a,ll b)
{return a<b?a:b;}

inline ll readll()
{
	ll o=0; char ch=' ';
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar())o=o*10+ch-48;
	return o;
}

inline int read()
{
	int o=0; char ch=' ';
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar())o=o*10+ch-48;
	return o;
}

void dg(int o)
{
	size[o]=1;
	for(int y=la[o];y;y=ne[y])
	if(!fa[lb[y]]){
		fa[lb[y]]=o;
		dg(lb[y]);
		size[o]+=size[lb[y]];
		if(size[lb[y]]*2==n)ok=len[y];
		ans=ans+len[y]*min(size[lb[y]],n-size[lb[y]]);
	}
	zd[o]=n-size[o];
	for(int y=la[o];y;y=ne[y])
	if(fa[lb[y]]==o)zd[o]=max(zd[o],size[lb[y]]);
}

int main()
{
	cin>>n;
	fo(i,1,n-1){
		int a=read(),b=read();
		ll Z=readll();
		llb(a,b,Z); llb(b,a,Z);
	}
	fa[1]=-1; dg(1);
	if(ok==0){
		int o=0; zd[0]=n+1;
		fo(i,1,n)if(zd[i]<zd[o])o=i;
		ok=(ll)12e17;
		for(int y=la[o];y;y=ne[y])
		ok=min(ok,len[y]);
	}
	ans=(ans<<1)-ok;
	cout<<ans;
}

Measured memory_bytes: 7936
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#define P 10000

#define N 1001
#define M 7777

int LCS(char *, char *);

int main()
{
  int d, i, r[M];
  
  char A[N], B[N];

  scanf("%d", &d);

  for(i = 0; i < d; i++){
    
    scanf("%s", A);
    
    scanf("%s", B);

    r[i] = LCS(A, B);
  }

  for(i = 0; i < d; i++){
    
    printf("%d\n", r[i]);
  }
  
  return 0;
}

int LCS(char *A, char *B)
{

  int a,b, i, j,c[N][N];

  a = (int)strlen(A);
  b = (int)strlen(B);

  for(i = 1; i <= a; i++) {
    
    c[i][0] = 0;
  }
  for(j = 0; j <=b; j++){ c[0][j] = 0;
  }

  for(i = 1; i <= a; i++){
    
    for(j = 1; j <= b;j++){
      
      if(A[i-1] == B[j-1]){
	
	c[i][j] = c[i-1][j-1] + 1;
	
      }
      else if(c[i-1][j] >= c[i][j-1]){ c[i][j] = c[i-1][j]; }
      
      else {c[i][j] = c[i][j-1];
      }
    }
  }

  return c[a][b];
}



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

int main(){
  int h, w;
  cin >> h >> w;
  
  vector<string> a(h);
  
  for(int i = 0; i < h; i++) {
  	cin >> a.at(i);
  }
  
  for(int i = 0; i < w+2; i++) {
  	cout << '#';
  }
  cout << endl;
  
  for(int i = 0; i < h; i++) {
    cout << '#' << a.at(i) << '#' << endl;
  }
   for(int i = 0; i < w+2; i++) {
    cout << '#';
   }
  cout << endl;
  
}

Measured memory_bytes: 256
n,k,l=map(int,input().split())
pq=[list(map(int,input().split())) for _ in [0]*k]
rs=[list(map(int,input().split())) for _ in [0]*l]

gpq=[[] for _ in [0]*n]
[gpq[b-1].append(a-1) for a,b in pq]
[gpq[a-1].append(b-1) for a,b in pq]

grs=[[] for _ in [0]*n]
[grs[b-1].append(a-1) for a,b in rs]
[grs[a-1].append(b-1) for a,b in rs]

memo_set=set()
list_pq=[]
for i in range(n):
    if i not in memo_set:
        q=[i]
        temp_set={i}
        while q:
            qq=q.pop()
            for g in gpq[qq]:
                if g not in temp_set:
                    q.append(g)
                    temp_set.add(g)
                    memo_set.add(g)
        list_pq.append(temp_set)
        
memo_set=set()
list_rs=[]
for i in range(n):
    if i not in memo_set:
        q=[i]
        temp_set={i}
        while q:
            qq=q.pop()
            for g in grs[qq]:
                if g not in temp_set:
                    q.append(g)
                    temp_set.add(g)
                    memo_set.add(g)
        list_rs.append(temp_set)

dict_rs=dict()

for i,d in enumerate(list_rs):
    for j in d:
        dict_rs[j]=i

dict_pq=dict()

ans=[None]*n
for i,d in enumerate(list_pq):
    for j in d:
        no=dict_rs[j]
        if (i,no) in dict_pq.keys():
            ans[j]=dict_pq[(i,no)]
        else:
            a=len(d&list_rs[no])
            dict_pq[(i,no)]=a
            ans[j]=a

print(*ans)

Measured memory_bytes: 249168
const fs = require('fs');

function main(input) {
  var arr = input.split('\n')
  var N = parseInt(arr[0], 10);
  var a = arr[1].split(' ')
  a = a.map(n => parseInt(n, 10));
  a.sort((a, b) => (b - a));

  var sa = 0;
  var sb = 0;
  a.forEach((v, i) => {
    (i & 1) ? sb += v : sa += v;
  });
  var ans = sa - sb;
  console.log(ans);
}

var input = fs.readFileSync('/dev/stdin', 'utf8');
main(input);

Measured memory_bytes: 7500
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <iostream> 
#include <iomanip>  
#include <string>
#include <sstream>  
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <cstring>
#include <cmath>
#include <cassert>


#define INF              (int)1000000007
#define EPS              1e-9
#define pb               push_back
#define mp               make_pair
#define all(c)           c.begin(), c.end()
#define forall(i,a,b)    for(int i=a;i<(b);++i)
#define trav(a,x)        for(auto & a: x)
#define in(a,b)          ((b).find(a) != (b).end())
#define sz(c)            (int)(c).size()
#define input(a)         for(auto & x : a) cin >> x;

using namespace std;

typedef vector<int>      vi;
typedef pair<int,int>    ii;
typedef vector<vi>       vvi;
typedef vector<ii>       vii;
typedef long long        ll;

#ifdef DEBUG
#define trace(...)       __f(#__VA_ARGS__, __VA_ARGS__)
#define debug(args...)   {dbg,args; clog<<endl;}
#define print_( a )      for( auto & x : a ) clog << x << ' '; clog << '\n';
#define printPair_( a )  for( auto & x : a ) clog << '(' << x.first << ',' << x.second << ')' << ' '; clog << '\n';
#else
#define trace(...)       
#define debug(args...)            
#define print_( a )               
#define printPair_( a )           
#endif

struct debugger {
  template<typename T> debugger& operator , (const T& x) {    
    clog << x << " ";    return *this;    
  }
}dbg;

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

auto ____ =[]() { std::ios::sync_with_stdio(0); cin.tie(0); return nullptr; }();

int encode( const vi & v ){
  int ans = 0;
  for(auto x : v ) ans |= (1<<(x-1));
  return ans;
}
int main( int argc, char * argv[] ){
  int n, m, w; cin >> n >> m; 
  vi cost(m), code(m);
  forall(t,0,m){
    cin >> cost[t] >> w;
    debug("t=",t, cost[t], w);
    vi v(w);
    debug("vsz", v.size());
    input(v);
    code[t] = encode(v);
  }
  trace(code[1]);
  trace(code[0], code[2]);

  vi p(1<<n, INF), q(1<<n, INF);
  p[0]=q[0]=0;
  forall(i,0,m){// for each code
    int cur_code = code[i];
    int cur_cost = cost[i];
    q = p;
    forall(j,0,1<<n){ // for each state
      if( p[j] == INF ) continue;
      q[j|cur_code] = min(q[j|cur_code], p[j] + cur_cost);
    }
    swap(p,q);
  }

  int ans =  p[(1<<n)-1];
  cout << ( ans == INF ? -1 : ans ) << endl;
  return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<string> W(N);
    set<string> s;
    string ans = "Yes\n";
    rep(i, N) {
        cin >> W[i];
        s.insert(W[i]);
    }
    rep(i, N - 1) {
        if (W[i][W[i].size() - 1] != W[i + 1][0]) ans = "No\n";
    }
    if (s.size() < N) ans = "No\n";
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

int  main()
{
	int a; cin >> a;
	if (a <= 999)
		cout << "ABC\n";
	else
		cout << "ABD\n";
	return (0);
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef priority_queue<int> pqb;
typedef priority_queue<int, vi, greater<int> > pqs;

#define iamtheflash         ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod                 1000000007
#define debug1(x)           cout<<"#x: "<<x<<"\n"
#define debug2(x,y)         cout<<"#x: "<<x<<" #y: "<<y<<"\n"
#define debug3(x,y,z)       cout<<"#x: "<<x<<" #y: "<<y<<" #z: "<<z<<"\n"
#define debug4(x,y,z,w)     cout<<"#x: "<<x<<" #y: "<<y<<" #z: "<<z<<" #w: "<<w<<"\n"
#define rep(i,n)            for(int i=0;i<(n);i++)
#define repl(i,n)           for(ll i=0;i<(n);i++)
#define fori(i,a,b)         for(int i=(a);i<=(b);i++)
#define forl(i,a,b)         for(ll i=(a);i<=(b);i++)
#define ford(i,a,b)         for(int i=(a);i>=(b);i--)
#define fordl(i,a,b)        for(ll i=(a);i>=(b);i--)
#define pb                  push_back
#define mp                  make_pair
#define ff                  first
#define ss                  second
#define mid(s,e)            (s+(e-s)/2)
#define setbits(x)          __builtin_popcountll(x)
#define zrobits(x)          __builtin_ctzll(x)
#define ps(x,y)             fixed<<setprecision(y)<<x
#define w(x)                int x; cin>>x; while(x--)
#define in(x)               int x; cin>>x;
#define ins(x)              string x; cin>>x;
#define endl                '\n'
#define infi                INT_MAX
#define infll               LLONG_MAX
#define infim               INT_MIN
#define infllm              LLONG_MIN
#define mk(arr,n,type)      type *arr = new type[n];
#define umap(x,type1,type2) unordered_map<type1, type2 > x;

int solve(int *a, int n, int k) {
	int dp[n + 1];
	dp[1] = 0;

	fori(i, 2, n) {
		dp[i] = infi;
		for (int j = i - 1; j >= 1 && (i - j) <= k; j--) {
			dp[i] = min(dp[i], abs(a[i] - a[j]) + dp[j]);
		}
	}
	return dp[n];
}

int32_t main() {
	iamtheflash

	in(n);
	in(k);
	mk(a, n + 1, int);

	fori(i, 1, n) cin >> a[i];

	cout << solve(a, n, k);

	return 0;
}


Measured memory_bytes: 1024
import math
import re
#import sympy

#n,x,t=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

tempmax=0
retnum=0

tempmax=a[0]

for i in range(len(a)):
    if tempmax>a[i]:
        retnum+=tempmax-a[i]
    else:
        tempmax=a[i]
print(retnum)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

ll mod = 1000000007;

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

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}

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

  int n;
  cin >> n;
  vi a(n),b(n);

  rep(i,n)cin >> a[i];
  rep(i,n)cin >> b[i];
  
  vi ret(n);
  queue<int> pos;
  int con = -1;
  rep(i,n) {
    ret[i] = b[n-i-1];
    if(a[i] == ret[i]){
      pos.push(i);
      con = a[i];
    }
  }

  rep(i,n){
    if(pos.empty())break;
    if(a[i] != con && ret[i] != con) {
      int p = pos.front();
      pos.pop();
      swap(ret[i], ret[p]);
    }
  }

  if(pos.empty()) {
    cout << "Yes" << endl;
    rep(i,n) cout << ret[i] << " ";
    cout << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 6308
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 3e3 + 10;
const int MOD = 1e9 + 7;
 
typedef long long ll;
int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> f(k + 1, 1);
    while (n--) {
        int use;
        cin >> use;
        for(int i = k; i >= 0; i--) {
            f[i] -= (i - use - 1 >= 0 ? f[i - use - 1] : 0);
        }
        for(int i = 1; i <= k; i++)
            f[i] = (f[i] + f[i - 1] + 2LL * MOD) % MOD;
    }
    ll ans = f[k];
    if (k > 0) ans = (ans - f[k - 1] + MOD) % MOD;
    cout << ans;
}


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

using namespace std;
char ma[1000][1000];

int main(){
    int n,m; cin>> n >> m;
    vector<pair<int,int> > v;
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin>> ma[i][j];
        }
    }
    for(int i=0;i<n;++i){
        int cont=0;
        for(int j=0;j<m;++j){
            if(ma[i][j]=='.'){
                if(j-1>=0 && ma[i][j-1]=='#')cont++;
                if(i-1>=0 && ma[i-1][j]=='#')cont++;
                if(i+1<n && ma[i+1][j]=='#')cont++;
                if(j+1<m && ma[i][j+1]=='#')cont++;
                if(i+1<n && j+1<m && ma[i+1][j+1]=='#')cont++;
                if(i+1<n && j-1>=0 && ma[i+1][j-1]=='#')cont++;
                if(i-1>=0 && j-1>=0 && ma[i-1][j-1]=='#')cont++;
                if(i-1>=0 && j+1<m && ma[i-1][j+1]=='#')cont++;
                 cout<<cont;
            }else if(ma[i][j]=='#')cout<<ma[i][j];
            cont=0;
        }
        cout<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
import heapq
N,M,S = [int(i) for i in input().split()]
S = min(S,2500)
Train = [[] for p in range(N)]
for j in range(M):
    U,V,A,B = [int(hoge) for hoge in input().split()]
    Train[U-1].append((V-1,(A,B)))#(次、(運賃,時間))
    Train[V-1].append((U-1,(A,B)))

CD = [[int(hoge) for hoge in input().split()] for k in range(N)]

num = N*2501          # グラフのノード数
dist = [float('inf') for i in range(num)] # 始点から各頂点までの最短距離を格納する
prev = [float('inf') for i in range(num)] # 最短経路における，その頂点の前の頂点のIDを格納する
    
start = 0 * 2501 + S
dist[start] = 0 #ID = Point * 2501 + Money(P=ID//2501 M = ID%2501)
q = []                  # プライオリティキュー．各要素は，(startからある頂点vまでの仮の距離, 頂点vのID)からなるタプル
heapq.heappush(q, (0, start)) # 始点をpush
while len(q) != 0:
    prov_cost, src = heapq.heappop(q) # pop(仮の距離,ID)
    
    # プライオリティキューに格納されている最短距離が，現在計算できている最短距離より大きければ，distの更新をする必要はない
    if dist[src] < prov_cost:
        continue

    # 他の頂点の探索
    src_Point = src//2501
    src_Money = src%2501
    src_RyogaeM = CD[src_Point][0]
    src_RyogaeTime = CD[src_Point][1]

    RyogaeAfter = min(2500,src_Money + src_RyogaeM)
    RyogaeID = src - src_Money + RyogaeAfter
    cost = src_RyogaeTime

    if dist[RyogaeID] > dist[src] + cost:
        dist[RyogaeID] = dist[src] + cost#distの更新
        heapq.heappush(q,(dist[RyogaeID],RyogaeID))

    for togo,trainfo in Train[src//2501]:#つながってる線路について
        cost = trainfo[1]#src→dest間の距離
        fee = trainfo[0]
        dest = togo * 2501 + src_Money - fee
        if src_Money >= fee and dist[dest] > dist[src] + cost:
            dist[dest] = dist[src] + cost # distの更新
            heapq.heappush(q, (dist[dest], dest)) # キューに新たな仮の距離の情報をpush
            prev[dest] = src                      # 前の頂点を記録

curpoint = 0
TheEnd = 2500
curmin = float("inf")
for point,d in enumerate(dist):
    if d < curmin:
        curmin = d
    if point == TheEnd:
        TheEnd += 2501
        if point > 2500:
            print(curmin)
        curmin = float("inf")



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

int main(){
    int x,y;
    cin >> x >>y;
    int a,b;
    if (x>y){
        a = x;
        b = y;
    }
    else {
        a = y;
        b = x;
    }
    int d;
    while(1){
        d = b;
        b = a%b;
        a = d;
        
        if (x%d==0 && y%d==0){
            cout << d <<endl;
            break;
        }
    }
    return 0;
    
}


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

int main() {
	int N;
	cin >> N;
	for (int i = N; i > 0; i--) {
		int n = i;
		while (n % 2 == 0) {
			n /= 2;
		}
		if (n == 1) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let r: usize = read();
    println!("{}", 3*r*r);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
#define int long long
   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; }
    const int MAX =1002;
const int MOD =1000000007;
vector<int> hen[100000];
bool used[100000];
int ok,ng,mid;
int dfs(int a,bool a0){
  used[a]=true;
  vector<int> v;
  for(auto&& i:hen[a])if(!used[i]){
    int b=dfs(i,false);
    if(b==-1)return -1;
    v.push_back(b+1);
  }
  sort(v.begin(),v.end());
  if(v.size()%2==0){
    bool t=true;
      for(int i=0;i*2<v.size();i++){
        if(v[i]+v[v.size()-1-i]>mid){
          t=false;
          break;
        }
      }
    if(t)return 0;
    if(v[v.size()-1]>mid||a0)return -1;
    v.pop_back();
  }
  
    int ok2=v.size(),ng2=-1,mid2;
    while(abs(ok2-ng2)>1){
      mid2=(ok2+ng2)/2;
      bool t=true;
      for(int i=0;i*2<v.size()-1;i++){
        if(v[i+(i>=mid2)]+v[v.size()-2-i+(v.size()-2-i>=mid2)]>mid){
          t=false;
          break;
        }
      }
      if(t)ok2=mid2;
      else ng2=mid2;
    }
    if(ok2==v.size())return -1;
    return v[ok2];
    
  
}
signed main(){
 int n,a,b,ansa=1;
 cin>>n;
 for(int i=0;i<n-1;i++){
   cin>>a>>b;
   a--;b--;
   hen[a].push_back(b);
   hen[b].push_back(a);
 }
 for(int i=0;i<n;i++)ansa+=(hen[i].size()-1)/2;
  ng=0;ok=n;
  while(abs(ok-ng)>1){
    mid=(ok+ng)/2;
    fill(used,used+n,false);
    int y=dfs(0,true);
    if(y==-1||y>mid)ng=mid;
    else ok=mid;
  }
  cout<<ansa<<' '<<ok<<endl;
 
}

Measured memory_bytes: 19796
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >>N;
    vector<int>vec(N,0);
    for(int i=0;i<N;i++){
        cin>>vec.at(i);
    }
    //今の光がどれかを保存する関数を用意
    int light=1,count=0;
    for(int i=0;i<N;i++){
    light = vec.at(light - 1);
     count++;
     if(light == 2){
     cout << count << endl;
     return 0;
     }
    }
    cout <<-1 <<endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
int a[N];
ll f[N][3];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++) {
        for(int j=0;j<3;j++) {
            f[i][j]=-1e18;
        }
    }
    for(int i=1;i<=3;i++) {
        f[i][i-1]=a[i];
    }
    f[3][0]=a[1]+a[3];
    for(int i=4;i<=n;i++) {
        f[i][0]=f[i-2][0]+a[i];
        f[i][1]=max(f[i-2][1],f[i-3][0])+a[i];
        f[i][2]=max(f[i-2][2],f[i-3][1])+a[i];
        if(i>4) f[i][2]=max(f[i][2],f[i-4][0]+a[i]);
    }
    ll ans;
    if(n&1) ans=max(f[n][2],max(f[n-1][1],f[n-2][0]));
    else ans=max(f[n][1],f[n-1][0]);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 9276
N = int(input())
S = input()
B = 127
MOD = 10 ** 11 + 7

H = [0] * (len(S) + 1)
P = [1] * (len(S) + 1)
b = pow(B, N-1)
for i in range(len(S)):
    H[i+1] = (H[i] + ord(S[i]) * b) % MOD
    P[i+1] = (P[i] * B) % MOD
    b //= B

l = 0
r = N
ans = 0
while r - l > 1:
    mid = (l + r) // 2
    tmp = {}
    for i in range(N - mid + 1):
        h = ((H[mid+i] - H[i]) * P[mid+i-1]) % MOD
        if h in tmp and i - tmp[h] >= mid:
            l = mid
            ans = mid
            break
        else:
            if not h in tmp:
                tmp[h] = i
    else:
        r = mid
        
print(ans)

Measured memory_bytes: 4112
import numpy as np

N = int(input())
H = [int(s) for s in str(input()).split()]
dp = np.full(10**5 + 10, np.inf)

def rec(i):
    if dp[i] < np.inf:
        return dp[i]
    
    if i==0:
        return 0
    
    res = np.inf
    res = rec(i-1) + abs(H[i]-H[i-1])
    if i > 1:
	    res = min(res, rec(i-2) + abs(H[i]-H[i-2]))
    
    dp[i] = res
    return dp[i]

def main3():
    print(int(rec(N-1)))

def main1():
    dp = np.full(10**5 + 10, np.inf)
    dp[0] = 0
    
    for i in range(1, N):
        dp[i] = min(dp[i], dp[i-1] + abs(H[i] - H[i-1]))
        if i > 1:
            dp[i] = min(dp[i], dp[i-2] + abs(H[i] - H[i-2]))
            
    print(int(dp[N-1]))
    
if __name__ == '__main__':
    main1()

Measured memory_bytes: 38680
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&!(1<<i);}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mul(int a, int b) {return ((a%MOD)*(b%MOD))%MOD;}
int add(int a, int b) {return (a+b)%MOD;}
int sub(int a, int b) {return (((a-b)%MOD)+MOD)%MOD;}
int __div(int a, int b) {return mul(a, powmod(b, MOD-2, MOD));} //if MOD is prime;
const int inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
int n, m;
vi vis(100010, 0);
int dp[100010];
int dfs(int v, vector<vi>& adjlist) {
	vis[v]=1;
	// if(!adjlist[v].size())
	// 	return 0;
	int mx=0;
	for(int i = 0; i < adjlist[v].size(); i++) {
		int u = adjlist[v][i];
		// cout<<u<<" fefe "<<v<<" "<<vis[u]<<" "<<vis[v]<<endl;
		if(vis[u]) {
			// cout<<"fe "<<dp[u]<<endl;
			mx=max(mx, dp[u]+1);
		}
		else
			mx=max(mx, dfs(u, adjlist)+1);
	}
	dp[v]=mx;
	// cout<<mx<<" "<<v<<endl;
	return dp[v];
}
int32_t main(void)
{
	IOS;
	cin>>n>>m;
	vector<vi> adjlist(n);
	for(int i = 0; i < m; i++) {
		int u,v; cin>>u>>v;
		adjlist[u-1].pb(v-1);
	}
	for(int i = 0; i < n; i++)
		dp[i]=-1;
	for(int i = 0; i < n; i++) {
		if(!adjlist[i].size()) {
			dp[i]=0;
			vis[i]=1;
		}
	}
	// cout<<dp[3]<<endl;
	for(int i = 0; i < n; i++) {
		if(!vis[i]) {
			dp[i] = dfs(i, adjlist);
		}
	}
	cout<<*max_element(dp, dp+n)<<endl;
	time();	
	return 0;
}

Measured memory_bytes: 9344
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main(){
    int n,ans = 0;
    cin >> n;
    vector<string> s(n);
    for(int i = 0;i < n;i++){
        cin >> s.at(i);
    }
    /**/
    sort(s.begin(),s.end());
    for(int i = 1;i < n;i++){
        if(s.at(i) != s.at(i - 1)){
            ans++;
        }
    }

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

Measured memory_bytes: 7644
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll w,h,x,y;
	cin>>w>>h>>x>>y;
	double area=1.0*w*h/2;
	cout<<area<<" ";
	if((1.0*w)/2==1.0*x && (1.0*h)/2==1.0*y){
		cout<<1;
	}else
		cout<<0;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var ab = Console.ReadLine().Split().Select(long.Parse).ToArray();
        Console.WriteLine(ab[0] * ab[1] / GCD(ab[0], ab[1]));
    }

    static long GCD(long a, long b)
    {
        while (true)
        {
            if (b == 0) return a;
            a %= b;
            if (a == 0) return b;
            b %= a;
        }
    }
}

Measured memory_bytes: 13396
#include<iostream>
using namespace std;
int main(){
  int c[3][3],b[3],a2,a3;
  bool f=false,tf[4];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> c[i][j];
    }
  }
  for(int a1=0;a1<=100;a1++){
    b[0] = c[0][0]-a1;
    b[1] = c[0][1]-a1;
    b[2] = c[0][2]-a1;
    a2 = c[1][0]-b[0];
    a3 = c[2][0]-b[0];
    tf[0]=c[1][1]==(b[1]+a2);
    tf[1]=c[1][2]==(b[2]+a2);
    tf[2]=c[2][1]==(b[1]+a3);
    tf[3]=c[2][2]==(b[2]+a3);
    if(tf[0]&&tf[1]&&tf[2]&&tf[3]){
      f=true;
      break;
    }
  }
  if(f) cout << "Yes\n";
  else cout <<"No\n";
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }


        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadLong;
            var m = cin.ReadLong;
            var M = 1000000007;
            if (m < n)
            {
                (n, m) = (m, n);
            }

            long[] factorial = new long[100001];
            for (int i = 0; i <= 100000; i++)
            {
                if (i <= 1) factorial[i] = 1;
                else factorial[i] = (factorial[i - 1] * i) % M;
            }
            long ans = 0;
            if (m - n <= 1)
            {
                ans = (factorial[n] * factorial[m]) % M;
                if (n == m)
                {
                    ans = (ans * 2) % M;
                }
            }
            Console.WriteLine($"{ans}");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 28660
K = int(input())


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        x = gcd(a, b)
        for c in range(1, K + 1):
            ans += gcd(x, c)

print(ans)

Measured memory_bytes: 70620
from collections import Counter
from collections import deque
from functools import reduce
from operator import mul
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


a = II()
b = II()
c = II()
d = II()
print(min(a, b) + min(c, d))



Measured memory_bytes: 66796
def solve(n, hn, depth)
  return 0 if n == 0

  min = hn.min
  return min if n == 1

  (0..n-1).each { |i| hn[i] -= min}

  start = hn[0] == 0 ? 1 : 0
  i = start
  ans = min
  while i < n do
    if hn[i] == 0
      tmp = solve(i - start, hn[start..(i-1)], depth + 1)
      ans += tmp
      start = i + 1
    end

    i += 1
  end
  if hn[i-1] != 0
    ans += solve(i - start, hn[start..(i-1)], depth + 1)
  end

  ans
end

n = gets.to_i
hn = gets.split.map(&:to_i)

puts solve(n, hn, 0)


Measured memory_bytes: 1788
N = int(input())
p = list(map(int, input().split()))

counts = []

for i in range(len(p)):
    if p[i] == i + 1:
        counts.append(i)

if len(counts) == N - 2:
    print('YES')
elif len(counts) == N:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  string s; cin >>s;
  if (s.size() > 9){ cout <<"NO" <<endl; return 0;}
  if (s[s.size()-1] == 'A') s.pop_back();
  string t = "AKIHABAR";
  int si = 0, ti = 0;
  while (si < s.size() && ti < t.size()){
    if (s[si] == t[ti]){
      si++; ti++; continue;
    }else if (t[ti] == 'A'){
      ti++; continue;
    }else{
      cout <<"NO" <<endl; return 0;
    }
  }
  if (si == s.size() && ti == t.size()){
    cout <<"YES" <<endl;
  }else{
    cout <<"NO" <<endl;
  }
}

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

ans = []
for i in range(n-k+1):
    if xxx[i]*xxx[i+k-1] < 0:
        if abs(xxx[i]) > abs(xxx[i+k-1]):
            ans.append(xxx[i+k-1]*2-xxx[i])
        else:
            ans.append(xxx[i+k-1]-xxx[i]*2)
    else:
        ans.append(max(abs(xxx[i]),abs(xxx[i+k-1])))

print(min(ans))


Measured memory_bytes: 14568
#include<iostream>
#include<string>
#include<queue>
#include<vector>
using namespace std;
const long long INF=4000000000000000000LL;
typedef pair<long long,int> P;
int main(){
	string S,T,ans;
	int BX[55],BY[55],nx,ny;
	bool a,b=false;
	cin>>S>>T;
	for(int i=S.size()-T.size();i>=0;--i){
		a=false;
		ans=S;
		for(int j=i;j<i+T.size();++j){
			if(S[j]=='?'||T[j-i]==S[j]){
				ans[j]=T[j-i];
			}else{
				a=true;
				break;
			}
		}
		if(!a){
			b=true;
			break;
		}
	}
	for(int i=0;i<S.size();++i){
		if(ans[i]=='?')ans[i]='a';
	}
	if(b)cout<<ans<<endl;
	else cout<<"UNRESTORABLE"<<endl;
	return 0;
}


Measured memory_bytes: 256
N=int(input())
dic={"AC":0,"WA":0,"TLE":0,"RE":0}
for i in range(N):
  s=input()
  dic[s]+=1
print("AC x "+str(dic["AC"]))
print("WA x "+str(dic["WA"]))
print("TLE x "+str(dic["TLE"]))
print("RE x "+str(dic["RE"]))

Measured memory_bytes: 69868
H, W = map(int, input().split())
Ass = ['.#' + '.' * W] + ['.' + input() + '.' for _ in range(H)] + ['.' * W + '#.']

def solve():
    for x in range(1, H + 1):
        for y in range(1, W + 1):
            if Ass[x][y] == '.': continue
            isOK_pX = Ass[x - 1][y] == '#'
            isOK_pY = Ass[x][y - 1] == '#'
            isOK_nX = Ass[x + 1][y] == '#'
            isOK_nY = Ass[x][y + 1] == '#'
            if isOK_pX == isOK_pY or isOK_nX == isOK_nY:
                print('Impossible')
                return
    print('Possible')

solve()


Measured memory_bytes: 3064
#coding:utf-8

def ch2int(a):
    s=["S","H","C","D"]
    for i,b in enumerate(s):
        if a==b:
            return i

def int2ch(i):
    s=["S","H","C","D"]
    return s[i]

n=int(input())
card=[[0 for i in range(0,13)]for j in range(0,4)]

for i in range(n):
    c,x=list(map(str,input().split()))

    card[ch2int(c)][int(x)-1]=1

for i,x in enumerate(card):
    for j,y in enumerate(x):
        if y==0:
            print(int2ch(i)+" "+str(j+1))
    

Measured memory_bytes: 7712
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  
  int l, r;
  
  int number;
  number = 0;
  int sum;
  sum = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sum = number + r - l + 1;
    number = sum;
    
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	zentai := 0
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		zentai ^= a[i]
	}
	ans := make([]string, n)
	for i := 0; i < n; i++ {
		ans[i] = strconv.Itoa(zentai ^ a[i])
	}
	fmt.Println(strings.Join(ans, " "))
}


Measured memory_bytes: 16268