akhauriyash/Code-Regression huggingface dataset:
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function Main(input){
	input = input.split(' ');
	var ball = toInt(input[0]);
	var color = toInt(input[1]);
	console.log(color * Math.pow(color - 1, ball-1));
}



Measured memory_bytes: 7372
#include <iostream>

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

  if (a < b)
  {
    std::swap(a, b);
  }

  return gcd(b, a%b);
}

int main()
{
  long a, b;
  std::cin >> a >> b;
  std::cout << gcd(a, b) << std::endl;
  return 0;
}

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

int main(){
  int n, k;
  string s;
  cin >> n >> k >> s;

  int tmp, l = 0, cnt = 0, ans = 0, sum = 0;
  vector<int> v;

  tmp = 1;
  for ( int i = 1; i < n; i++){
    if ( s[i-1] == '1' && s[i] == '0' ){
      v.push_back(tmp);
      tmp = 1;
    } else if ( s[i-1] == '0' && s[i] == '1' ){
      v.push_back((-1) * tmp);
      tmp = 1;
    } else {
      tmp++;
    }
  }

  if ( s[n-1] == '0'){
    v.push_back((-1) * tmp);
  } else {
    v.push_back(tmp);
  }

  for ( int i = 0; i < v.size(); i++){
    if ( v[i] < 0){
      cnt++;
    }
    sum += abs(v[i]);
    while(cnt > k){
      sum -= abs(v[l]);
      if ( v[l] < 0){
        cnt--;
      }
      l++;
    }
    ans = max(ans, sum);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <queue>

using namespace std;

int main(){
    int n, k; cin >> n >> k;
    vector<int> as(n);
    int sum=0;
    for(int i=0; i<n; ++i){
        cin >> as[i];
        sum+=as[i];
    }

    int ans=1;
    for(int i=1; i*i<=sum; ++i){
        if(sum%i) continue;
        vector<int> diff1(n), diff2(n);
        for(int j=0; j<n; ++j){
            diff1[j]=as[j]%(sum/i);
            diff2[j]=as[j]%i;
        }

        sort(diff1.begin(), diff1.end());
        long long k1=0;
        for(int j=0, last=n-1; j<last; ++j){
            k1+=diff1[j];
            while(diff1[j]){
                if(diff1[j]>=sum/i-diff1[last]){
                    diff1[j]-=sum/i-diff1[last];
                    diff1[last]=0;
                    --last;
                } else{
                    diff1[last]+=diff1[j];
                    diff1[j]=0;
                }
            }
        }
        if(k1<=k){
            ans=max(ans, sum/i);
            break;
        }

        sort(diff2.begin(), diff2.end());
        long long k2=0;
        for(int j=0, last=n-1; j<last; ++j){
            k2+=diff2[j];
            while(diff2[j]){
                if(diff2[j]>=i-diff2[last]){
                    diff2[j]-=i-diff2[last];
                    diff2[last]=0;
                    --last;
                } else{
                    diff2[last]+=diff2[j];
                    diff2[j]=0;
                }
            }
        }
        if(k2<=k) ans=max(ans, i);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
def main():
    input()
    times = 0
    sequence = list(map(int, input().split()))
    for i in range(len(sequence)):
        for j in range(len(sequence)-1, i, -1):
            if sequence[j-1] > sequence[j]:
                tmp = sequence[j]
                sequence[j] = sequence[j-1]
                sequence[j-1] = tmp
                times += 1
    print(' '.join(map(str, sequence)))
    print(times)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
long long m=1e9+7;
long long fact[1000001],inv[1000001];

long long modRecursive(long long a,long long b,long long c)
{
	if(b == 0) return 1;
	if(b%2 ==0) return modRecursive((a*a)%c,b/2,c);
	else return ((a%c)*(modRecursive((a*a)%c,b/2,c)))%c;
}

int main()
{
    fact[0]=1; inv[0]=1;
    for(int i=1; i<=1000000; i++)
    {
        fact[i]=(i*fact[i-1])%m;
        inv[i]=modRecursive(fact[i],m-2,m);
    }
    long long h,w,a,b,ans=0;
    cin>>h>>w>>a>>b;
    for(long long i=b; i<w; i++)
    {
        long long p=i,q=h-a-1;
        long long r=w-i-1,s=a-1;
        long long x=(((fact[p+q]*inv[p])%m)*inv[q])%m;
        x*=(((fact[r+s]*inv[r])%m)*inv[s])%m;
        ans=(ans+x)%m;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define int long long
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
int n, k;
signed main() {
	#ifdef aome
	in("aome.inp");	
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	/*
	If a, b, c < k, then a + b = b + c = c + a = k.
	So a = b = c = k / 2. 2 cases arise:
	- k's odd. Then a b c are forced to be its multiplies
	- k's even. Then a b c can either divide k having a remainder of 0 or k / 2.
	The rest of the task is pretty simple
	*/
	if (k & 1) {
		int tmp = n / k;
		cout << tmp * tmp * tmp << "\n";
	} else {
		int tmp1 = n / k, tmp2 = (n - k / 2) / k + 1;
		if (n - k / 2 < 0) tmp2 = 0;
		cout << tmp1 * tmp1 * tmp1 + tmp2 * tmp2 * tmp2 << "\n";
	}
	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++)
    
int main(void){
    int n; cin >> n;
    
    int ans = 0;
    for(int i = 0; i <= 10; i++){
        if(i * 1000 >= n){
            ans = i * 1000 - n;
            cout << ans << endl;
            return 0;
        }
    }
}


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

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

    long long N, A, B;
    cin >> N >> A >> B;

    if (N < A+B-1 || A*B < N) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> v;
    
    for (int i=N-A+1; i<=N; ++i) {
        v.push_back(i);
    }
    N -= A;

    int m;
    for (int i=B-1; i>0; --i) {
        m = min(A, N-i+1);
        for (int j=N-m+1; j<=N; ++j) {
            v.push_back(j);
        }
        N -= m;
    }

    for (int i=0; i<(int)v.size(); ++i) {
        cout << (i == 0 ? "" : " ") << v[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3568
#include<iostream>
using namespace std;
int main()
{
char arr[3];
cin>>arr[0]>>arr[1]>>arr[2];
for(int i=0;i<3;i++)
{
    if(arr[i]=='1')
        arr[i]='9';
    else if(arr[i]=='9')
        arr[i]='1';
}
cout<<arr[0]<<arr[1]<<arr[2];
 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;
using namespace __gnu_pbds;

tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderset;

const int N=2e5+5;
int n,m,d[N],pre[N];
vector<int>adj[N];

void bfs(int x)
{
    queue<int>pq;
    pq.push(x);
    d[x]=1;
    while(!pq.empty())
    {
        int u=pq.front();
        pq.pop();
        for(auto&v:adj[u])
        {
            if(!d[v])
            {
                d[v]=d[u]+1;
                pre[v]=u;
                pq.push(v);
            }
        }
    }
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m;
    while(m--)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    bfs(1);
    for(int i=1;i<=n;i++) if(d[i]==-1) return cout<<"No",0;
    cout<<"Yes"<<'\n';
    for(int i=2;i<=n;i++) cout<<pre[i]<<'\n';
}


Measured memory_bytes: 16136
#include <bits/stdc++.h>
using namespace std;
class fastio {
public:
    fastio() {
        ios_base::sync_with_stdio(false);
        cout.tie(nullptr);
        cin.tie(nullptr);
    }
} __fastio;
int main() {
  __fastio;
  int x, a; cin >> x >> a;
  if(x < a) cout << "0" << endl;
  else cout << "10" << endl;
  return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	long long a, b;
	cin >> a >> b;
	long long wynik = a*b / __gcd(a,b);
	cout << wynik << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int a,b,c,d;
  scanf("%d %d %d",&a,&b,&c);
  if(a > b){
    d = a;
    a = b;
    b = d;
  }
  if (b > c) {
    d = b;
    b = c;
    c = d;
  }
  if(a > b){
    d = a;
    a = b;
    b = d;
  }
  printf("%d %d %d\n",a ,b ,c);
  return 0;
}

Measured memory_bytes: 1796
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int min = 0;
    for (int i = 0; i < n; i++) {
      int a = scan.nextInt();
      int count = findMin(a, 0);
      if (i == 0 || count < min) {
        min = count;
      }
    }
    System.out.println(min);
  }
  
  private static int findMin(int n, int count) {
    if (n % 2 != 0) {
      return count;
    }
    return findMin(n / 2, ++count);
  }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(10);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

ll f(ll n){
    if(n%2)return 3*n+1;
    return n/2;
}

signed main(){
    ll s;
    map<ll,bool> m;
    cin >> s;
    vl v(1001000);
    v[1] = s;
    m[s] = 1;
    FOR(i,2,1001000){
        v[i] = f(v[i-1]);
        if(m[v[i]]){
            cout << i << endl;
            return 0;
        }
        m[v[i]] = 1;
    }
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cassert>
using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> a;
    for(int i=0; i<H; i++){
        string s;
        cin >> s;
        if(s != string(W, '.'))
            a.push_back(s);
    }
    vector<bool> v(W, false);
    for(int i=0; i<a.size(); i++)
        for(int j=0; j<W; j++)
            if(a[i][j] == '#')
                v[j] = true;

    vector<string> ans;
    for(int i=0; i<a.size(); i++){
        string s;
        for(int j=0; j<W; j++){
            if(v[j])
                s.push_back(a[i][j]);
        }
        ans.push_back(s);
    }
    for(auto x : ans)
        cout << x << endl;

    return 0;
}


Measured memory_bytes: 256
function Main(inputs) {
　　const inputlines = inputs.split("\n");
　　const limit = inputlines[0].split(" ").map(x => parseInt(x,10));
　　const inputvalues = inputlines[1].split(" ").map(x => parseInt(x,10));
	
　　var sum  = function(arr) {
　　　var sum = 0;
　　　arr.forEach(function(elm) {
　　　　　sum += elm;
　　　});
　　　return sum;
　　};
  
　　let total = limit[0] - sum(inputvalues);
  
　　console.log(total>=0?total:-1);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30596
#include <iostream>
#include <vector>
#include <functional>
#include <cassert>
#include <algorithm>
using namespace std;

template <class T> class RAQ_and_RmQ {
	int n;
	T init;
	vector<T> node, lazy;
	static int ceil2(int n) {
		int m = 1;
		while (m < n) m *= 2;
		return m;
	}
	void eval(int k, int l, int r) {
		if (lazy[k] != 0) {
			node[k] += lazy[k];
			if (r - l > 1) {
				lazy[2 * k + 0] += lazy[k];
				lazy[2 * k + 1] += lazy[k];
			}
			lazy[k] = 0;
		}
	}
	void add_impl(int a, int b, const T& x, int k, int l, int r) {
		eval(k, l, r);
		if (b <= l || r <= a) {
			return;
		} else if (a <= l && r <= b) {
			lazy[k] += x;
			eval(k, l, r);
		} else {
			add_impl(a, b, x, 2 * k + 0, l, (l + r) / 2);
			add_impl(a, b, x, 2 * k + 1, (l + r) / 2, r);
			node[k] = min(node[2 * k + 0], node[2 * k + 1]);
		}
	}
	T query_impl(int a, int b, int k, int l, int r) {
		if (b <= l || r <= a) {
			return init;
		}
		eval(k, l, r);
		if (a <= l && r <= b) {
			return node[k];
		} else {
			auto vl = query_impl(a, b, 2 * k + 0, l, (l + r) / 2);
			auto vr = query_impl(a, b, 2 * k + 1, (l + r) / 2, r);
			return min(vl, vr);
		}
	}

public:
	RAQ_and_RmQ(const vector<T>& vec, const T& _init) : init(_init) {
		build(vec);
	}
	void build(const vector<T>& v) {
		n = ceil2(v.size());
		node.assign(n * 2, init);
		lazy.assign(n * 2, 0);
		for (int i = 0; i < v.size(); ++i) {
			node[i + n] = v[i];
		}
		for (int i = n - 1; i > 0; --i) {
			node[i] = min(node[i * 2 + 0], node[i * 2 + 1]);
		}
	}
	void add(int l, int r, const T& x) {
		add_impl(l, r, x, 1, 0, n);
	}
	T operator[](int i) {
		assert(0 <= i && i < n);
		return operator()(i, i + 1);
	}
	T operator()(int l, int r) {
		assert(0 <= l && l < r && r <= n);
		return query_impl(l, r, 1, 0, n);
	}
	vector<T> to_a() {
		vector<T> res(n);
		for (int i = 0; i < n; ++i) {
			res[i] = operator[](i);
		}
		return res;
	}
};

using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, q;
	cin >> n >> q;
	RAQ_and_RmQ<ll> seg(vector<ll>(n, 0), 1e9);
	for (int i = 0; i < q; ++i) {
		int com;
		cin >> com;
		if (com == 0) {
			int s, t;
			ll x;
			cin >> s >> t >> x;
			seg.add(s, t + 1, x);
		} else if (com == 1) {
			int s, t;
			cin >> s >> t;
			cout << seg(s, t + 1) << '\n';
		}
	}
}


Measured memory_bytes: 7852
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   int N;
   cin >> N;
   string S;
   cin >> S;
   int ans = N;
   int kuro[N + 1];
   int siro[N + 1];
   memset(kuro, 0, sizeof(kuro));
   memset(siro, 0, sizeof(siro));
   for (int i = 0; i < N; i++) {
      if (S[i] == '#') kuro[i + 1] = kuro[i] + 1;
      else kuro[i + 1] = kuro[i];
      if (S[i] == '.') siro[i + 1] = siro[i] + 1;
      else siro[i + 1] = siro[i];
   }
   for (int i = 0; i <= N; i++) {
      ans = min(ans, kuro[i] + siro[N] - siro[i]);
   }
   cout << ans << endl;
   return 0;
}


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

struct edge {
  int to;
  ll cost;
};

vector<edge> g[100010];
ll ans[100010];

void dfs(int v, int p, ll d) {
  ans[v] = d;
  rep(i, (int)g[v].size()) {
    if (g[v][i].to == p) continue;
    dfs(g[v][i].to, v, d + g[v][i].cost);
  }
}

int main() {
  int n; cin >> n;
  rep(i, n-1) {
    int a, b, c; cin >> a >> b >> c; a--; b--;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  int q, k; cin >> q >> k; k--;
  dfs(k, -1, 0);
  rep(i, q) {
    int x, y; cin >> x >> y; x--; y--;
    cout << ans[x] + ans[y] << endl;
  }
  return 0;
}

Measured memory_bytes: 17408
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
typedef pair<int,int> pi;
pi zlt;
map<pi,int> cnt,bz;
set<int> s[maxn];
set<int>::iterator it;
queue<pi> dl;
int fa[maxn];
int i,j,k,l,t,n,m,x,y,z,ca;
bool czy;
int getfa(int x){
	return fa[x]?fa[x]=getfa(fa[x]):x;
}
int main(){
	scanf("%d",&n);
	fo(i,1,2*(n-1)){
		scanf("%d%d",&j,&k);
		if (j>k) swap(j,k);
		zlt=make_pair(j,k);
		cnt[zlt]++;
		if (cnt[zlt]==1){
			s[j].insert(k);
			s[k].insert(j);
		}
		if (cnt[zlt]>1&&!bz[zlt]){
			dl.push(zlt);
			bz[zlt]=1;
		}
	}
	czy=1;
	ca=n-1;
	while (ca--){
		x=y=-1;
		while (!dl.empty()){
			j=getfa(dl.front().first);
			k=getfa(dl.front().second);
			dl.pop();
			if (j!=k){
				x=j;y=k;
				break;
			}
		}
		if (x==y&&x==-1){
			czy=0;
			break;
		}
		if (s[x].size()<s[y].size()) swap(x,y);
		fa[y]=x;
		it=s[y].begin();
		while (it!=s[y].end()){
			z=*it;
			it++;
			s[z].erase(s[z].find(y));
			if (z==x) continue;
			//if (s[x].find(z)==s[x].end()) s[x].insert(z),s[z].insert(x);
			if (x<z) zlt=make_pair(x,z);else zlt=make_pair(z,x);
			cnt[zlt]++;
			if (cnt[zlt]==1){
				s[x].insert(z);
				s[z].insert(x);
			}
			if (cnt[zlt]>1&&!bz[zlt]){
				dl.push(zlt);
				bz[zlt]=1;
			}
		}
		s[y].clear();
	}
	if (czy) printf("YES\n");else printf("NO\n");
}

Measured memory_bytes: 41472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
int main(){
	int n,l;
	cin>>n>>l;
	string a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++)
		 cout<<a[i];
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(const ll& x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	template <typename U>
	explicit operator U() const { return (U)val; }
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
};
Mint dp[5005][5005];
const int MAXN = 10000005;
Mint fac[MAXN], invfac[MAXN];
Mint binom(ll a, ll b) {
	if (b < 0) return 0;
	if (b > a) return 0;
	return fac[a] * invfac[b] * invfac[a - b];
}
int main() {
	fac[0] = 1;
	for (int i = 1; i < MAXN; ++i)
		fac[i] = fac[i - 1] * i;
	invfac[MAXN - 1] = 1 / fac[MAXN - 1];
	for (int i = MAXN - 2; i >= 0; --i)
		invfac[i] = invfac[i + 1] * (i + 1);
	int n, A;
	scanf("%d%d", &n, &A);
	int B = n - A;
	Mint ans = 0;
	dp[0][0] = 1;
	for (int ones = 0; ones <= A; ++ones) {
		Mint sum = 0;
		for (int i = 1; i <= A; ++i) {
			if (i >= 2) sum += dp[i - 2][ones] * fac[A - i + 1];
			dp[i][ones] = sum * invfac[A - i];
			if (ones) dp[i][ones] += dp[i - 1][ones - 1];
			if (i >= 2) {
				ans += dp[i - 1][ones] * binom(i - 2 + B - ones, i - 2) * fac[A - i] * fac[B];
			}
		}
		ans += dp[A][ones] * binom(A - 1 + B - ones, A - 1) * fac[B];
	}
	printf("%d\n", ans.val);
}


Measured memory_bytes: 179764
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define pb emplace_back
#define F first
#define S second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
const int N = 1e5 + 10;
const ll INF = 1LL << 60;


void solve()
{
	ll n, m;
	cin>>n>>m;
	ll ans = ((n-1)*n) /2 + ((m-1)*m) / 2;
	cout<<ans<<endl;
}


int main()
{
    FAST
    ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
        solve();
    }
    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++)
int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> k(n,vector<int>(1,-1));
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    k[a].push_back(b);
    k[b].push_back(a);
  }
  int dist[n];
  dist[0]=0;
  int c[n];
  rep(i,n)c[i]=-1;
  c[0]=0;
  queue<int> q;
  q.push(0);
  while(q.size()!=0){
    int u=q.front();
    q.pop();
    for(int w: k[u]){
      if(w==-1)continue;
      if(c[w]!=-1)continue;
      c[w]=u;
      dist[w]=dist[u]+1;
      q.push(w);
    }
  }
  cout << "Yes" << endl;
  rep(i,n-1)cout << c[i+1]+1 << endl;
}


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

int main(){
  int X;
  cin >> X;
  int D = X%10;
  X /= 10;
  int C = X%10;
  X /= 10;
  int B = X%10;
  X /= 10;
  int A = X;
  if(A+B+C+D==7){
    cout <<A<<"+"<<B<<"+"<<C<<"+"<<D<<"=7";
  }else if(A+B+C-D==7){
    cout <<A<<"+"<<B<<"+"<<C<<"-"<<D<<"=7";
  }else if(A+B-C+D==7){
    cout <<A<<"+"<<B<<"-"<<C<<"+"<<D<<"=7";
  }else if(A+B-C-D==7){
    cout <<A<<"+"<<B<<"-"<<C<<"-"<<D<<"=7";
  }else if(A-B+C+D==7){
    cout <<A<<"-"<<B<<"+"<<C<<"+"<<D<<"=7";
  }else if(A-B+C-D==7){
    cout <<A<<"-"<<B<<"+"<<C<<"-"<<D<<"=7";
  }else if(A-B-C+D==7){
    cout <<A<<"-"<<B<<"-"<<C<<"+"<<D<<"=7";
  }else if(A-B-C-D==7){
    cout <<A<<"-"<<B<<"-"<<C<<"-"<<D<<"=7";
  }
  return 0;
}

Measured memory_bytes: 3608
from collections import deque
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
A = sorted(A)
B = deque()
C = deque()
mod = (10**9)+7
for h in range(N):
    B.append(A[h])
    C.append(A[h])


def cmb(n, r):  # 【Python】組み合わせ(nCr) 計算の高速化より引用
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return fac[n] * finv[r] * finv[n-r] % mod


N_cmb = 10**5  # 入力の制約によって変えるところ、nCrの計算で欲しいnの最大値
fac = [1, 1]  # 階乗テーブル
finv = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for ZZZ in range(2, N_cmb + 1):
    fac.append((fac[-1] * ZZZ) % mod)
    inverse.append(mod-inverse[mod % ZZZ]*(mod//ZZZ) % mod)
    finv.append((finv[-1] * inverse[-1]) % mod)


ans = 0
for i in range(N):
    if N - i >= K:
        kari = cmb(N - i - 1, K-1) % mod
        # print(kari)
        ans += (kari * B.pop()) % mod
        ans -= (kari * C.popleft()) % mod
        ans = ans % mod
print(ans)


Measured memory_bytes: 22596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n, x, sum = 0;
    cin >> n >> x;
    vector<ll> m(n);
    rep(i, n) {
        cin >> m[i];
        sum += m[i];
    }
    x -= sum;
    sort(m.begin(), m.end());

    cout << n + x / m[0] << "\n";

    return 0;
}

Measured memory_bytes: 3584
#include<iostream> 
using namespace std;
int main(){
	int n;
	int b[200000];
	cin>>n;
	int a;
	for (a=0;a<n;a++)
	cin>>b[a];
	int max=-2100000000,min=b[0];
	int d;
	for (d=1;d<n;d++){
		if (max<(b[d]-min))
		max=b[d]-min;
		if (min>b[d])
		min=b[d];
	}
	cout<<max<<endl;
	return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	ll a, b;
	cin >> a >> b;
	ll n = b - a;
	cout << (n * (n + 1) / 2 - b) << endl;
	return 0;
}
 

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

template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<1000000007>;

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

    int n;
    cin >> n;
    int r = 0, g = 0, b = 0;
    mint ans = 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a == r && a == g && a == b) {
            r++;
            ans *= 3;
        } else if (a == r && a == g) {
            r++;
            ans *= 2;
        } else if (a == g && a == b) {
            g++;
            ans *= 2;
        } else if (a == r && a == b) {
            r++;
            ans *= 2;
        } else if (a == r) {
            r++;
        } else if (a == g) {
            g++;
        } else if (a == b) {
            b++;
        } else {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

std::vector<int> par;
std::vector<int> rak; // number of the vertices

void init(int n) {
  par.resize(n+1);
  rak.resize(n+1, 1);
  for(int i=1; i<=n; i++) {
    par[i] = i;
  }
}

int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x==y) return;
  if (rak[x] < rak[y]) {
    rak[y] += rak[x];
    par[x] = y;
  } else {
    rak[x] += rak[y];
    par[y] = x;
  }
}

bool same(int x, int y) {
  return find(x) == find(y);
}

vector<int> xpos[100005];
vector<int> ypos[100005];
set<int> xset[100005];
set<int> yset[100005];

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  init(n);
  vector<P> vec(n);

  rep(i, n) {
    int x, y; cin >> x >> y;
    xpos[x].push_back(i);
    ypos[y].push_back(i);
    vec[i] = P(x, y);
  }

  for(int i=1; i<=1e+5; i++) {
    int s = xpos[i].size();
    rep(j, s-1) {
      unite(xpos[i][j], xpos[i][j+1]);
    }
    s = ypos[i].size();
    rep(j, s-1) {
      unite(ypos[i][j], ypos[i][j+1]);
    }
  }

  rep(i, n) {
    int p = find(i);
    int x = vec[i].first;
    int y = vec[i].second;
    xset[p].insert(x);
    yset[p].insert(y);
  }

  ll ans = 0;
  rep(i, n) {
    if (i != find(i)) continue;
    int si = rak[i];
    ll all = xset[i].size() * yset[i].size();
    ans += all-si;
  }
  cout << ans << endl;
}

Measured memory_bytes: 24576
N = int(input())
o = []
mon = 0
for i in range(N):
  x = input().split(' ')
#  print(x[0],x[1])
  if x[1] == 'BTC':
    mon +=float(x[0])*380000
  else:
    mon +=int(x[0])
 

print(mon)

Measured memory_bytes: 2940
//
// Created by moono on 2018/10/27.
//

#include <iostream>
#include <string>
using namespace std;


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

    int n, max_n = 0, min_n = 1 << 30;
    for (int i = 0; i < N; ++i) {
        cin >> n;

        if(max_n < n) max_n = n;
        if(min_n > n) min_n = n;
    }

//    cout << min_n << " " << max_n << endl;
    cout << max_n - min_n  << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N; ll A,B;
  cin >> N >> A >> B;
  ll h[N];
  ll mx_h = -1;
  for (int i = 0; i < N; i++) {
    cin >> h[i];
    mx_h = max(mx_h , h[i]);
  }
  ll left = 0;
  ll right = (mx_h / B) + 10;
  ll leftres = -1;
  ll rightres = -1;
  while (right - left > 1) {
    ll mid = (left + right) / 2;
    ll s[N];
    for (int i = 0; i < N; i++) {
      s[i] = max(0LL , h[i] - (B * mid));
    }
    ll cnt = 0;
    for (int i = 0; i < N; i++) {
      cnt += (s[i] + (A - B) - 1) / (A - B);
    }
    if (cnt <= mid) {
      right = mid;
      rightres = max(mid , cnt);
    } else {
      left = mid;
      leftres = max(mid , cnt);
    }
  }
  cout << rightres << endl;
  return 0;
}

Measured memory_bytes: 5152
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
int32_t main(){
    sync;
    ll n,x;
    cin >> n >> x;
    vector <int> a;
    for (int i=0;i<n;i++){
        ll z;
        cin >> z;
        a.pb(z);
    }
    sort(a.begin(),a.end());
    ll ans=0;
    for (int i=0;i<n;i++){
        if (x>=a[i]){
            ans++;
            x-=a[i];
        }
        else x=0;
    }
    if (x) kill(max((ll)0,ans-1))
    else
        cout << ans << endl;
}


Measured memory_bytes: 3640
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] s = sc.next().toCharArray();
		char[] cf = "CODEFESTIVAL2016".toCharArray();

		int ret = 0;
		for (int i = 0; i < s.length; i++) {
			if (s[i] != cf[i]) {
				ret++;
			}
		}

		pr.println(ret);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 10188
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int n;
string s[100100];
int main()
{
    go;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
    }
    ll ans=0;
    sort(s,s+n);
    for(ll i=0;i<n;)
    {
        ll j=i;
        while(j<n&&s[i]==s[j])
            j++;
        ans+=(j-i)*(j-i-1)/2;
        i=j;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5760
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a)+min(b)  # 通常価格の最小値


for r in range(M):
    x, y, c = map(int, input().split())
    if ans > a[x-1]+b[y-1]-c:
        ans = a[x-1]+b[y-1]-c

print(ans)


Measured memory_bytes: 70892
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
//static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
struct edge {int /*from,*/to,cost;};

signed main(){
    int a,b,c,n;
    string s,t;

    cin >> n >> a;
    n -= 500*(n/500);
    if(n>a) puts("No");
    else puts("Yes");
    return 0;
}



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

int main() {
  int K, X;
  cin >> K >> X;
  int min,max;
  min=X-K+1;
  max=X+K-1;
  for(int i=min;i<max+1;i++){
    if(i==max){
      cout<< i << endl;
    } else{
      cout<< i << ' ';
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

int N, M, Q;
int a[505][505];
int S[505][505];


int main() {
  
  scanf("%d %d %d", &N, &M, &Q);
  rep(i, 0, M) {
      int L, R;
      scanf("%d %d", &L, &R);
      a[L][R]++;
  }
  
  rep(i, 1, N+1) {
    rep(j, 1, N+1) {
      S[i][j] = S[i-1][j] + S[i][j-1] - S[i-1][j-1] + a[i][j];
    }
  }

  rep(i, 0, Q) {
      int p, q;
      scanf("%d %d", &p, &q);
      printf("%d\n", S[q][q] - S[q][p-1] - S[p-1][q] + S[p-1][p-1]);
  }
  
  return 0;
}
 


Measured memory_bytes: 2944
N = int(input())
dp = [[0] * 3 for _ in range(N)]
action = list(map(int, input().split()))
dp[0][0] = action[0]
dp[0][1] = action[1]
dp[0][2] = action[2]
for i in range(N-1):
    action = list(map(int, input().split()))
    dp[i+1][0] = max(dp[i][1]+action[0],dp[i][2]+action[0])
    dp[i+1][1] = max(dp[i][0]+action[1],dp[i][2]+action[1])
    dp[i+1][2] = max(dp[i][0]+action[2],dp[i][1]+action[2])
print(max(dp[N-1]))

Measured memory_bytes: 60396
#include<stdio.h>
#define Max 500000
#define term 1000000000

int Left[(Max/2)+2], Right[(Max/2)+2];
int c=0;


void merge(int e[], int n, int left, int mid, int right){
  int i,j,k;

  int x = (mid-left);
  int y = (right-mid);

  for ( i=0; i<x; i++ )
   Left[i] = e[left+i];
  for ( i=0; i<y; i++ )
   Right[i] = e[mid+i];

  Left[x]= Right[y] = term;
  i = j = 0;
  for ( k=left; k<right; k++){
    c++;
    if ( Left[i]<=Right[j] ){
      e[k] = Left[i++];
    } else {
      e[k] = Right[j++];
    }
  }
}

void mergeSort(int e[], int n, int left, int right ){
  int mid;
  if ( left+1<right ){
    mid=(left + right)/2;
    mergeSort(e, n, left, mid);
    mergeSort(e, n, mid, right);
    merge(e, n, left, mid, right);
  }
}

int main(){
  int e[Max], n, i;
  scanf("%d", &n);
  for ( i=0; i<n; i++) {
    scanf("%d", &e[i]);
    if (e[i]>=term ){
      return 1;
    }
  }
  mergeSort(e,n,0,n);

  for ( i=0; i<n; i++) {
    if ( i !=0 ) 
    printf(" ");

    printf("%d", e[i]);
    }
  printf("\n");

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


  return 0;
}




Measured memory_bytes: 5644
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll=long long;
int main()
{
    ll x,k,d,out,kaisu,amari;
    cin>>x>>k>>d;
    if(x<0) 
        x *= -1;
    kaisu=x/d;
    amari=x%d;
    if(k<=kaisu) 
	{
        out=x-k*d;
        cout<<out<<endl;
        return 0;
    }
    else 
	{
        if((k-kaisu)%2==0) 
		{
            out=amari;
            cout<<out<<endl;
            return 0;
        }
        else 
		{
            out=abs(amari-d);
            cout<<out<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv){
    string a, b;
    cin >> a >> b;
    vector<vector<int>> dp(a.length() + 1, vector<int>(b.length() + 1));
    string res = "";

    vector<vector<pair<int,int>>> path(a.length() + 1, vector<pair<int,int>>(b.length() + 1));

    for(int i = 0; i < a.length(); ++i){
        for(int j  = 0; j < b.length(); ++j){
            if(a[i] == b[j]){
                dp[i+1][j+1] = 1 + dp[i][j];
                path[i+1][j+1] = make_pair(i,j);
            }else{
                int v1 = dp[i+1][j];
                int v2 = dp[i][j+1];
                if(v1 > v2){
                    dp[i+1][j+1] = v1;
                    path[i+1][j+1] = make_pair(i+1, j);
                }else{
                    dp[i+1][j+1] = v2;
                    path[i+1][j+1] = make_pair(i, j+1);
                }
            }
        }
    }
    int index = dp[a.length()][b.length()];
    char lcs[index+1];
   lcs[index] = '\0'; // Set the terminating character

   // Start from the right-most-bottom-most corner and
   // one by one store characters in lcs[]
   int i = a.length(), j = b.length();
   while (i > 0 && j > 0)
   {
      // If current character in X[] and Y are same, then
      // current character is part of LCS
      if (a[i-1] == b[j-1])
      {
          lcs[index-1] = a[i-1]; // Put current character in result
          i--; j--; index--;     // reduce values of i, j and index
      }

      // If not same, then find the larger of two and
      // go in the direction of larger value
      else if (dp[i-1][j] > dp[i][j-1])
         i--;
      else
         j--;
   }

    cout << lcs << "\n";
    return 0;
   // Print the lcs
   cout << "LCS of  is " << lcs;
    /*
    for(const auto& v : dp){
        for (const auto& i : v){
            cout << i << " ";
        }
        cout << "\n";
    }
    */
    int x = a.length(), y = b.length();

    while(x != 0 && y != 0){
        if(a[x-1] == b[y-1]){
            res.push_back(a[x-1]);
        }
    //    cout << x << " " << y << "\n";
        x = path[x][y].first;
        y = path[x][y].second;
    }
    reverse(res.begin(), res.end());
    cout << res << "\n";
    return 0;
}


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

int main() {
  int n, i;
  string s;
  cin >> n >> s;
  
  vector<int> a(n), b(n), c(n);
  if(s.at(0) == 'W') a.at(0) = 1;
  if(s.at(n - 1) == 'E') b.at(n - 1) = 1;
  
  for(i = 1; i < n; i++){
    a.at(i) = a.at(i - 1) + (s.at(i) == 'W');
  }
  
  for(i = n - 2; i >= 0; i--){
    b.at(i) = b.at(i + 1) + (s.at(i) == 'E');
  }
  
  c.at(0) = b.at(1);
  c.at(n - 1) = a.at(n - 2);
  for(i = 1; i < n - 1; i++){
    c.at(i) = a.at(i - 1) + b.at(i + 1);
  }
  
  sort(c.begin(), c.end());
  
  cout << c.at(0) << endl;
}

Measured memory_bytes: 4228
//#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;
#define AC 0
vector<long long> t;
void insert(int x, long long v) {
	for (; x < t.size(); x += x & -x) t[x] = max(t[x], v);
}
long long find(int x) {
	long long ans = 0;
	for (; x; x -= x & -x) ans = max(ans, t[x]);
	return ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	long long mx = 0;
	cin >> n;
	t.resize(4 * n + 1);
	vector<int> a(n + 1);
	vector< pair<int, int> > h(n + 1);
	vector<long long> dp(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> h[i].first;
		h[i].second = i;
	}
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(h.begin(), h.end());
	for (int i = 1; i <= n; i++) {
		dp[i] = find(h[i].second - 1) + a[h[i].second];
		insert(h[i].second, dp[i]);
		mx = max(mx, dp[i]);
	}
	cout << mx << '\n';
	return AC;
}

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

int main(void)
{
	int n;
	const int max_n = 2000;
	cin >> n;
	cout << pow(n, 3) << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Linq;
class B{
  static void Main(){
    ReadLine();
    var ts = Array.ConvertAll(ReadLine().Split(), int.Parse);
    var sum = ts.Sum();
    var n = int.Parse(ReadLine());
    for(int i = 0;i < n; i++){
      var px = Array.ConvertAll(ReadLine().Split(), int.Parse);
      WriteLine(sum-ts[px[0]-1]+px[1]);
    }
  }
}

Measured memory_bytes: 13268
//一般化

#include<iostream>
#include<string>

int main() {
	const int use = 13; //今回使用するトランプの枚数は 13    ここの値は問題によって変更　　正の整数なら数字でもいけそう(？)　　　　　 (しっかりと確認はしてないですが頭の中だと反例は見つかりませんでした)
	const int min = 2;  //今回2が一番小さい　                ここの値は問題によって変更　  use以下であればどんな数字でも行けそう(？)　(しっかりと確認はしてないですが頭の中だと反例は見つかりませんでした)
	const int difference = use - min; //13-2=11


	int alice, bob;
	std::string result;
	std::cin >> alice >> bob;

	(alice + difference) % use > (bob + difference) % use ? result = "Alice" : (alice + difference) % use < (bob + difference) % use ? result = "Bob" : result = "Draw";

	std::cout << result << std::endl;

	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()

  val mod = 1000000007
  def times(a: Long, b: Long): Long = (a * b) % mod

  def factorize(n: Int): IndexedSeq[Int] = {
    var res = IndexedSeq[Long]()
    var i = 2L
    var m = n.toLong
    while (i * i <= m) {
      while (m % i == 0) {
        res :+= i
        m /= i
      }
      i += 1
    }

    if (m != 1) {
      res :+= m
    }

    res.map(_.toInt)
  }

  val factor = Array.fill(n)(0L)
  for (i <- 2 to n) {
    for (f <- factorize(i)) {
      factor(f-1) += 1
    }
  }

  println(factor.map(_ + 1).reduceLeft(times))
}


Measured memory_bytes: 55780
#include <iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
typedef pair<int,pint> ppi;
const int inf   = 510101010;
const int mod=1e9+7;
const ll longinf=1LL<<60;

map<ll,ll> memo;

ll rec(ll n){
  if(memo.count(n))return memo[n];
  ll ret=0;
  if(n%2){
    ret=(2*rec(n/2)+rec(n/2-1))%mod;
    return memo[n]=ret;
    }
  else{
    ret=(rec(n/2)+2*rec(n/2-1))%mod;
    return memo[n]=ret;
    return ret;
    }
  }

int main(){
  ll n;cin>>n;
  memo[0]=1;memo[1]=2;
  cout<<rec(n)<<endl;
  return 0;
  }

Measured memory_bytes: 256