akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** MOD CALCULATION ***/

const int MOD = 1e9+7;
const int MAX = 500'005;

ll addM(ll a, ll b){
	return (a + b) % MOD;
}

ll mulM(ll a, ll b){
	ll temp = ((a % MOD) * (b % MOD)) % MOD;
  	return temp;
}

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a % MOD;
  	else if(b%2==0) return mulM(powM(a, b/2), powM(a, b/2));
  	else return mulM(a, mulM(powM(a, (b-1)/2), powM(a, (b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a, powM(b, MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

/*** MOD CALCULATION ここまで ***/


void Main(){
    ll n, m; cin >> n >> m;
    
    COMBinit();

    // 包除原理
    ll ans = 0;
    
    rep(i, n+1){
        ll tmp = COMB(n, i);
        tmp = mulM(tmp, fac[m-i]);
        tmp = mulM(tmp, finv[m-n]);
        if(i&1) tmp = mulM(tmp, MOD-1);
        ans = addM(ans, tmp);
        // cout << i << " " << tmp << " " << ans << endl;
    }
    
    ans = mulM(ans, fac[m]);
    ans = mulM(ans, finv[m-n]);
    cout << ans << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 15340
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}


ll dp[1111][22222];
template<class Type>
Type solve(Type res = Type()){
    ll H,N; cin >> H >> N;
    vector<ll> A(N),B(N);
    for(int i = 0; i < N;i++) cin >> A[i] >> B[i];
    
    fill(*dp,*dp+1111*22222,LINF);
    dp[0][0] = 0;
    for(int i = 0; i < N;i++){
        for(int j = 0; j < 22222;j++){
            if(dp[i][j] == LINF) continue;
            
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
            if(j+A[i] >= 22222) continue;
            dp[i][j+A[i]] = min(dp[i][j+A[i]],dp[i][j]+B[i]);
        }
    }
    
    res = *min_element(dp[N]+H, dp[N]+22222);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

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

    bool f = ((S.substr(0, 2) >= "01") && (S.substr(0, 2) <= "12"));
    bool r = ((S.substr(2, 2) >= "01") && (S.substr(2, 2) <= "12"));
    if (f && r) cout << "AMBIGUOUS" << endl;
    else if (f && !r) cout << "MMYY" << endl;
    else if (!f && r) cout << "YYMM" << endl;
    else cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N= 2e5 + 5;
const ll MOD=1e9 + 7;

int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    string str;
    cin>>str;

   // , , , , , , or
    if(str=="SUN")cout<<"7";
    if(str=="MON")cout<<"6";
    if(str=="TUE")cout<<"5";
    if(str=="WED")cout<<"4";
    if(str=="THU")cout<<"3";
    if(str=="FRI")cout<<"2";
    if(str=="SAT")cout<<"1";
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;


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

  int n, a, b;
  string s;

  cin >> n >> a >> b;

  ll ans = 0;

  forn(i, 1, n+1){
	  s = to_string(i);
		int sum = 0;
	  for(auto c: s){
			sum += c-'0';
	  }
		if(sum >= a && sum <= b)ans += i;
  }

	cout << ans << endl;




}




Measured memory_bytes: 3700
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>

#define reps(i,j,k) for(int i = j; i < k ;i++)
#define rep(i,j) reps(i,0,j)

using namespace std;
int dp[4012][4012];
int main(){
    string str1,str2;
    while(cin >> str1 >> str2){
        memset(dp,0,sizeof(dp));
        int h = str1.size();
        int w = str2.size();
        int ma = -100000;
        rep(i,h){
            rep(j,w){
                if(i==0 && str1[i] == str2[j])dp[i][j] = 1;
                else if(j == 0 && str1[i] == str2[j])dp[i][j] = 1;
                else if(str1[i] == str2[j])dp[i][j] += dp[i-1][j-1]+1;
                ma = max(ma,dp[i][j]);
            }
        }
        printf("%d\n",ma);
    }
    return 0;
}

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

using namespace std;



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

	vector<int> cnt(n + 1);

	for(int i = 1; i < n; ++i) {
		int x; cin >> x;
		cnt[x]++;
	}

	for(int i = 1; i <= n; ++i)
		cout << cnt[i] << '\n';


	return 0;	
}

Measured memory_bytes: 3992
// C - Linear Approximation
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	int N; cin>>N;
	vector<ll> B(N);
	for(int i=0; i<N; ++i){ cin>>B[i]; B[i] -= (i+1); }
	sort(B.begin(), B.end());
	ll r = B[N/2];
	ll ans = 0;
	for(ll bi:B) ans += abs(bi - r);
	cout<< ans <<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int,int>P;
int Start,End;
const int INF=100000000;
struct edge{
    int to,cost;
    edge(int a,int b){
        to=a;cost=b;
    }
    edge(){}
};
int dijkstra(vector<vector<edge> >V){
    priority_queue<P,vector<P>,greater<P> >Q;
    int d[100];
    fill(d,d+100,INF);
    d[Start]=0;
    Q.push(P(0,Start));

    while(Q.size()){
        P p=Q.top();Q.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<V[v].size();i++){
            int to=V[v][i].to;
            int cost=V[v][i].cost;
            if(d[to]>d[v]+cost){
                d[to]=d[v]+cost;
                Q.push(P(d[to],to));
            }
        }
    }
    return d[End];
}
int main(){
    int n,m;
    while(cin>>n>>m,n||m){
        vector<vector<edge> >V[2];
        V[0].resize(m);V[1].resize(m);
        while(n--){
            int a,b,cost,time;
            cin>>a>>b>>cost>>time;a--;b--;
            V[0][a].push_back(edge(b,cost));
            V[0][b].push_back(edge(a,cost));

            V[1][a].push_back(edge(b,time));
            V[1][b].push_back(edge(a,time));
        }
        int k;
        cin>>k;
        while(k--){
            int r;
            cin>>Start>>End>>r;Start--;End--;
            cout<<dijkstra(V[r])<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1364
#include <bits/stdc++.h>
  #define endl "\n"
  #define ll long long int
  #define vi vector<int>
  #define vll vector<ll>
  #define vvi vector < vi >
  #define pii pair<int,int>
  #define pll pair<long long, long long>
  #define mod 1000000007
  #define inf 1000000000000000001;
  #define all(c) c.begin(),c.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define pb push_back
  #define f first
  #define se second
  
  using namespace std;
  int main()
  {
    std::ios::sync_with_stdio(false);
    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;

    cin>>n>>k;
    ll arr[n+1],dp[n+1];
    fill(dp,dp+n+1,INT_MAX);
    arr[0]=inf; dp[0]=0; 
   
    for (ll i = 1; i <= n; ++i){
      cin>>arr[i];
    }
    dp[1]=0;

    for (ll i = 2; i <= n; ++i)
    {
      for (ll j = 1; j <=k; ++j)
      {
        if(i-j>=1)
         dp[i]=min(abs(arr[i]-arr[i-j])+dp[i-j],dp[i]);
      }
    }

    cout<<dp[n]<<endl;

    return 0;
  }



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


int main() {

  long long x , y;
  
  cin >> x >> y;
  
  
  if ( x % y == 0 ) {
    cout << -1 << endl;
  }
  else {
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 764
# happendはsetで保持しておき，roopはlistで保持しておく
N, X, M = map(int, input().split())  # modMは10**5以下が与えられる
happend = set()
A = [X]
MOD = M
# 第1~N項まで計N項の和をもとめる
start = 0
for _ in range(N-1):
    if A[-1]**2 % MOD not in happend:
        happend.add(A[-1]**2 % MOD)
        A.append(A[-1]**2 % MOD)
    else:
        start = A.index(A[-1]**2 % MOD)
        break

roop_count = (N-start)//len(A[start:])

ans = sum(A[:start]) + sum(A[start:])*roop_count + sum(A[start:start+(N-start) % len(A[start:])])
# print(A[:start], A[start:], A[start:start+(N-start) % len(A[start:])])
print(ans)


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

int comp(const void* a, const void* b)
{ return *(int*)a > *(int*)b ; }

int findNumberOfTriangles(int arr[], int n)
{

    qsort(arr, n, sizeof( arr[0] ), comp);


    int count = 0;


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

        int k = i + 2;
        for (int j = i + 1; j < n; ++j)
        {
          
            while (k < n && arr[i] + arr[j] > arr[k])
            ++k;

            if(k > j)
            count += k - j - 1;
        }
    }

    return count;
}

int main()
{     int n;
     cin>>n;
     int arr[n];
     for(int i=0;i<n;i++)
        cin>>arr[i];

    int size = sizeof( arr ) / sizeof( arr[0] );

    cout<<findNumberOfTriangles( arr, size );

    return 0;
}


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

int main(void) {
  int H, W;
  int count[H][W] = {0};
  cin >> H >> W;
  string str[H], Tri[H];
  for (int i = 0; i < H; i++) {
    cin >> str[i];
    Tri[i] = str[i];
  }
  for (int i = 0; i < H; i++) {
    for (int k = 0; k < W; k++) {
      if (str[i][k] != '#') {
        Tri[i][k] = '0';
        for (int j = -1; j <= 1; j++) {
          for (int l = -1; l <= 1; l++) {
            int ny = i + j, nx = k + l;
            if (ny < 0 || nx < 0 || ny >= H || nx >= W)
              continue;
            if (str[ny][nx] == '#')
              ++Tri[i][k];
          }
        }
      }
    }
    cout << Tri[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    string s[5];
    for(int i = 0; i < 2; i++) cin >> s[i];
    map<string, int> mp;
    for(int i = 0; i < 2; i++){
        int x;
        cin >> x;
        mp[s[i]] = x;
    }
    string x;
    cin >> x;
    mp[x]--;
    for(int i = 0; i < 2; i++) cout << mp[s[i]] << ' ';


    return 0;
}




Measured memory_bytes: 3656
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

type xyz struct {
	x int
	y int
	z int
}

func main() {
    sc.Split(bufio.ScanWords)

	N := nextInt()
	Y := nextInt()
	//N := 20
	//Y := 196000
	slice := []xyz{}

	for i := 0; i < N+1; i++ {
		x := N - i
		for j := 0; j < x+1; j++ {
			y := x - j
			for k := 0; k < y+1; k++ {
				z := y - k
				if z  == 0 && 10000*i+5000*j+1000*k == Y {
					slice = append(slice, xyz{
						x: i,
						y: j,
						z: k,
					})
					break
				} 
			}
		}
	}
	
	if len(slice) == 0 {
		fmt.Printf("-1 -1 -1")
	} else {
		x := slice[0].x
		y := slice[0].y
		z := slice[0].z

		fmt.Printf("%d %d %d", x, y, z)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200) cout << s << endl;
  else cout << "red" << endl;
}	


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

#define NM_MAX 1002

using namespace std;

const int MOD = 1e9+7;

int n, m;

char ma[NM_MAX][NM_MAX];

int dp[NM_MAX][NM_MAX];

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> ma[i][j];
    dp[0][1] = 1;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            if(ma[i][j] == '.')
            {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                if(dp[i][j] >= MOD)
                    dp[i][j] -= MOD;
            }
    cout << dp[n][m] << "\n";
    return 0;
}


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

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

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

  if(a+b+c >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  
  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s[6]<='4'&&s[5]!='1'){
        cout<<"Heisei"<<endl;
    }
    else cout<<"TBD"<<endl;
}
//＼(^q^)／ｵﾜﾀ


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

using namespace std;

vector<int> v;

int main()
{
  ios_base::sync_with_stdio(false);
  //cin.tie(1);
  int q;
  cin >> q;
  while(q--) {
    int a, aa, aaa;
    cin >> a;
    if (a == 0) {
      cin >> aa;
      v.push_back(aa);
    }
    else if (a == 2) {
      v.pop_back();
    }
    else if (a == 1) {
      cin >> aaa;
      cout << v[aaa] << endl;

    }
  }
  return 0;
}



Measured memory_bytes: 3868
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 1


int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		int x=0,y=0;
		int dx,dy;
		int d = 0;
		int mx=0,my=0;
		while(scanf("%d %d",&dx,&dy),dx|dy){
			x += dx;
			y += dy;
			if( x*x+y*y>d ){
				d = x*x+y*y;
				mx = x;
				my = y;
			}else if( x*x+y*y==d && mx<x ){
				mx = x;
				my = y;
			}
		}
		printf("%d %d\n",mx,my);
	}
	return 0;
}

Measured memory_bytes: 0
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------


//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int a,b;cin>>a>>b;
    if(a+b<10)
        cout<<a+b<<endl;
    else
        cout<<"error"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

class UnionFind{
public:
	vector<ll> par;
	vector<ll> num;

	UnionFind(ll N):par(N),num(N){
		for(ll i=0;i<N;i++){
			par[i]=i;
			num[i]=1;
		}
	}

	ll root(ll x){
		if(par[x]==x){
			return x;
		}
		return par[x]=root(par[x]);
	}

	void unite(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		par[rx] = ry;
		num[ry] += num[rx];
	}

	bool same(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		return rx == ry;
	}

	ll getsize(ll x){
		return num[root(x)];
	}
};

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

	ll N=in<ll>(),M=in<ll>();
	vector<pair<ll,ll>> P(M);
	vector<ll> result(M);
	REP(i,M){
		P[i].first=in<ll>();
		P[i].second=in<ll>();
	}
	UnionFind tree(N);
	ll uc = N*(N-1)/2;
	REP(i,M){
		result[M-1-i] = uc;
		ll a = P[M-1-i].first-1,b = P[M-1-i].second-1;
		if(!tree.same(a,b)){
			uc -= tree.getsize(a)*tree.getsize(b);
			tree.unite(a,b);
		}
	}
	
	for(auto& x:result){
		cout << x << endl;
	}
	return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using graph = vector<vector<int>>;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    ll a,b;
    cin >> a >> b;
    if(a > 0) cout << "Positive" << endl;
    else if(b >= 0) cout << "Zero" << endl;
    else (b-a)%2 == 0 ? cout << "Negative" << endl : cout << "Positive" << endl;
}

Measured memory_bytes: 256
"use strict"
function main(arg) {
    let data = arg.trim().split("\n")[1].split(" ")
    .map(e => BigInt(e))
    let boundary = 10 ** 18
    let sum = 1n
    for (let i = 0; i < data.length; i++) {
        if (data[i] === 0n) {
            console.log(0)
            return
        }
    }
    for (let i = 0; i < data.length; i++) {
        sum = sum * BigInt(data[i])
        if (boundary < sum) {
            console.log(-1)
            return
        }
        
    }
    console.log(sum + "")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 44196
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 19 13:18:23 2020

@author: morihiranaoki
"""

D, G = map(int,input().split())
pc = [list(map(int, input().split())) for i in range(D)]
score = [100*i for i in range(D)]

def reverse(depth, limit, stack, all_stack):
    if depth == limit + 1:
        return stack, all_stack

    for i in range(2):
        stack.append(i)
        reverse(depth+1, limit, stack, all_stack)[0]
        if len(stack) == limit:
            all_stack.append(list(stack))
            #print(stack)
        del stack[-1]
    return stack, all_stack

Each_Full = [[pc[i][0], pc[i][0]*100*(i+1) + pc[i][1]] for i in range(D)]
_, AllStack = reverse(1, D, [], [])

chosen_Scores = [sum([Each_Full[i][1] for i in range(D) if AllStack[j][i] == 1]) for j in range(len(AllStack))]
chosen_Costs = [sum([Each_Full[i][0] for i in range(D) if AllStack[j][i] == 1]) for j in range(len(AllStack))]

for j in range(len(AllStack)):
    if chosen_Scores[j] >= G:
        continue
    else:
        kari = 0
        for i,factor in enumerate(AllStack[j]):
            if factor == 0:
                kari = i
        for i in range(pc[kari][0]):
            chosen_Scores[j] += (kari+1)*100
            chosen_Costs[j] += 1
            if chosen_Scores[j] >= G:
                break
        else:
            chosen_Costs[j] = 99999

print(min(chosen_Costs))

Measured memory_bytes: 43632
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

int main()
{
    int a;

    cin >> a;

    if(a%2==0) cout << (a/2)*(a/2) << endl;
    else cout << (a+1)/2*(a-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	var k int

	fmt.Scan(&k)

	sum := 0
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				sum += gcd(gcd(a, b), c)
			}
		}
	}
	fmt.Printf("%v", sum)
}


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

using namespace std;

int gcd(int a, int b) {
	for (; b; swap(a, b))
		a %= b;
	return a;
}
int main() {
	int n, g = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		g = gcd(g, a);
	}
	cout << g << endl;
	return 0;
}


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

int main()
{
	vector<int>v;
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)v.push_back(2);
	for(int i=0;i<m;i++)v.push_back(1);
	int cnt=0;
	for(int i=0;i<v.size();i++)
		for(int j=i+1;j<v.size();j++)
		{
			if((v[i]+v[j])%2==0)cnt++;
		}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s;

int main() {
  cin >> s;
  i64 n = s.size();

  i64 ans = 0;
  for (i64 b = 0; b < (1 << (n - 1)); ++b) {
    i64 y = 0, x = s[0] - '0';
    for (i64 i = 0; i < n - 1; ++i) {
      if (b & (1 << i)) {
        y += x;
        x = s[i + 1] - '0';
      } else {
        x *= 10;
        x += s[i + 1] - '0';
      }
    }
    y += x;
    ans += y;
  }
  cout << ans << '\n';
  return 0;
}


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

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

    cin >> a >> b >> c >> d;

    for (int turn = 0; ; turn = (turn + 1)%2) {
        if (turn == 0) {
            c -= b;
            if (c <= 0) {
                cout << "Yes\n";
                return 0;
            }
        } else {
            a -= d;
            if (a <= 0) {
                cout << "No\n";
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3596
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

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

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

int main() {
    int a, b;
    cin >> a >> b;
    OUT(lcm(a, b));
}

Measured memory_bytes: 256
def ctoi(x):
    return ord(x)-ord("a")
n = int(input())
s = list(input())
q = int(input())
bit = [[0]*(n+1) for _ in range(26)]

def update(pos,a,x):
    while pos<=n:
        bit[a][pos] += x
        pos += pos&(-pos)

def query(pos):
    ret=[0]*26
    for i in range(26):
        tmp=0
        p=pos
        while p>0:
            tmp+=bit[i][p]
            p-=p&(-p)
        ret[i]=tmp
    return ret

for i in range(n):
    update(i+1,ctoi(s[i]),1)

for _ in range(q):
    flag,a,b = input().split()
    flag=int(flag)
    a=int(a)
    if flag==1:
        if s[a-1]==b:
            continue
        else:
            update(a,ctoi(s[a-1]),-1)
            update(a,ctoi(b),1)
            s[a-1]=b
    else:
        b=int(b)
        c1 = query(b)
        c2 = query(a-1)
        ans = 0
        for i in range(26):
            if c1[i]-c2[i]>0:
                ans += 1
        print(ans)

Measured memory_bytes: 165020
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

double dp[301][301][301];

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

  int n; cin >> n;
  vector<int> a(n);
  int cnt1 = 0;
  int cnt2 = 0;
  int cnt3 = 0;
  rep(i, n) {
    int a; cin >> a;
    if (a == 1) {
      cnt1++;
    } else if (a == 2) {
      cnt2++;
    } else {
      cnt3++;
    }
  }

  //debug(cnt1);debug(cnt2);debugln(cnt3);

  for(int k=0; k<=cnt3; k++) {
    for(int j=0; j<=300-k; j++) {
      for(int i=0; i<=300-j-k; i++) {
        if (i==0 && j==0 && k==0) {
          dp[i][j][k] = 0;
          continue;
        }
        dp[i][j][k] = n;
        if (i>0) {
          dp[i][j][k] += i*dp[i-1][j][k];
        }
        if (j>0) {
          dp[i][j][k] += j*dp[i+1][j-1][k];
        }
        if (k>0) {
          dp[i][j][k] += k*dp[i][j+1][k-1];
        }
        dp[i][j][k] /= i+j+k;
      }
    }
  }
  cout << setprecision(16) << dp[cnt1][cnt2][cnt3] << endl;
}

Measured memory_bytes: 213376
H,W=map(int,input().split(' '))
S=[list(input()) for i in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w]=='#':
            flg = False
            for x,y in [[-1,0],[1,0],[0,-1],[0,1]]:
                if 0<=h+x<H and 0<=w+y<W and S[h+x][w+y]=='#':
                    flg=True
                    break

            if not flg:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
N, X, M = map(int, input().split())
d = dict()
L = []
for i in range(M+1):
    if X not in d:
        d[X] = i
        L.append(X)
    else:
        j = d[X]
        k = i
        break
    X = X*X%M
s=k-j
kk, zz = divmod((N-j), s)
print(sum(L[:j])+sum(L[j:])*kk+sum(L[j:j+zz]))



Measured memory_bytes: 77508
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[1<<17];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		int flag=1;
		while(i<n-1&&a[i]==a[i+1])
		{
			i++;
			flag=!flag;
		}
		cnt+=flag;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long n, m, f[101010], ans;

int main(){
cin >> n >> m;
if(abs(n-m)>1)return 0*printf("%d", 0);
f[1]=1;
for(int i =2; i<=100001; i++){
    f[i]=(f[i-1]*i)%mod;
}
ans = (f[m]*f[n])%mod;
if(n==m)ans= (2*ans)%mod;
cout << ans << endl;

return 0;}


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

string S;
int N, K;

int main(){
  cin >> N >> S;
  int dir[N][2] = {0};
  
  /*累積和でOKかな*/
  for(int i = 0; i < N; i++){
    if(i == 0){
      if(S[i] == 'E') dir[i][0] = 1;
      else if(S[i] == 'W') dir[i][1] = 1;
    }else{
      if(S[i] == 'E'){ dir[i][0] = dir[i-1][0] + 1; dir[i][1] = dir[i-1][1]; }
      else if(S[i] == 'W'){ dir[i][1] = dir[i-1][1] + 1; dir[i][0] = dir[i-1][0]; }
    }
  }
  
  int mi = min(dir[N-1][0]-dir[0][0], dir[N-2][1]);   //端処理は面倒　比較順序は自由なので先取
  for(int i = 1; i < N-1; i++) mi = min(mi, (dir[N-1][0]-dir[i][0]+dir[i-1][1]));
    
  cout << mi << endl;
  return 0;
  
}

  

Measured memory_bytes: 3076
N, K = gets.chomp.split(" ").map{|s| s.to_i}
R, S, P = gets.chomp.split(" ").map{|s| s.to_i}
T = gets.chomp
t_arr = [""] +  T.split("")

f, s, t = "r", "s", "p"
if R >= S && S >= P
  f, s, t = "s", "p", "r"
elsif R >= P && P >= S
  f, s, t = "s", "r", "p"
elsif S >= R && R >= P
  f, s, t = "p", "s", "r"
elsif S >= P && P >= R
  f, s, t = "p", "r", "s"
elsif P >= R && R >= S
  f, s, t = "r", "s", "p"
elsif P >= S && S >= R
  f, s, t = "r", "p", "s"
end

score = {"r"=> P, "p"=> S, "s"=> R}
hand = {f=> {f=> t, s=>t, t=>s}, s=> {f=> t, s=>t, t=>f}, t=> {f=> s, s=>f, t=>s}}

point = 0
T.split("").each_with_index do |c, i|
  bind = [0, i + 1 - K].max
  bhand = t_arr[bind]
  if c != bhand
    point += score[c]
  else
    nind = i+1+K
    t_arr[i+1] = hand[bhand][ t_arr[nind] || f ]
  end
end

puts point



Measured memory_bytes: 16892
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-9;
const ll mod=1e9+7;
ll dp[100010][3];
ll a;char c;int n;
int main()
{
    cin>>n>>a;
    memset(dp,-0x3f3f3f3f3f3f3f3f,sizeof(dp));
    dp[0][0]=a;
    for(int i=1;i<n;i++)
    {
        scanf(" %c%d",&c,&a);
        if(c=='+')
        {
            dp[i][2]=dp[i-1][2]+a;
            dp[i][1]=max(dp[i-1][1]-a,dp[i-1][2]+a);
            dp[i][0]=max(dp[i-1][0]+a,max(dp[i-1][1]-a,dp[i-1][2]+a));
        }
        else
        {
            dp[i][2]=dp[i-1][1]+a;
            dp[i][0]=dp[i][1]=max(dp[i-1][1]+a,max(dp[i-1][2]-a,dp[i-1][0]-a));
        }
    }
    printf("%lld\n",max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])));
    return 0;
}

Measured memory_bytes: 2560
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

int A[N], B[N], C[N];
int dp[N][3];

int main() {

	boost;
	int n; cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>A[i]>>B[i]>>C[i];
	}
	for(int i=1; i<=n; i++) {
		dp[i][0] = max(B[i] + dp[i-1][1], C[i] + dp[i-1][2]);
		dp[i][1] = max(A[i] + dp[i-1][0], C[i] + dp[i-1][2]);
		dp[i][2] = max(B[i] + dp[i-1][1], A[i] + dp[i-1][0]);
	}
	cout<<max(dp[n][0], max(dp[n][1], dp[n][2]))<<"\n";
	return 0;
}

Measured memory_bytes: 7552
// 2014/07/18 Tazoe

#include <iostream>
using namespace std;

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

	int H[4][3][10];
	for(int i=0; i<4; i++){
		for(int j=0; j<3; j++){
			for(int k=0; k<10; k++){
				H[i][j][k] = 0;
			}
		}
	}

	for(int i=0; i<n; i++){
		int b, f, r, v;
		cin >> b >> f >> r >> v;

		H[b-1][f-1][r-1] += v;
	}

	for(int i=0; i<4; i++){
		if(i!=0){
			cout << "####################" << endl;
		}
		for(int j=0; j<3; j++){
			for(int k=0; k<10; k++){
				cout << ' ' << H[i][j][k];
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1164
def B():
    N, L = map(int, input().split())
    apples = [L + i for i in range(N)]
    taste_sum = sum(apples)
    if 0 in apples:
        print(taste_sum)
    elif taste_sum>0:
        print(taste_sum-min(apples))
    else:
        print(taste_sum-max(apples))

B()

Measured memory_bytes: 38384
#include<stdio.h>
int main(void)
{
	int e,y;
	scanf("%d %d",&e,&y);
	if(e==0){
		if(y<=1911)	printf("M%d\n",y-1867);
		if(y>=1912&&y<=1925)	printf("T%d\n",y-1911);
		if(y>=1926&&y<=1988)	printf("S%d\n",y-1925);
		if(y>=1989)	printf("H%d\n",y-1988);
	}
	else{
		if(e==1)	printf("%d\n",1867+y);
		if(e==2)	printf("%d\n",1911+y);
		if(e==3)	printf("%d\n",1925+y);
		if(e==4)	printf("%d\n",1988+y);
	}
	return 0;
}



Measured memory_bytes: 2756
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll fb[4]={2,1,1,0};

double next(double p1,double p2,ll ind){
  if(ind==0) return p1*p2;
  else if(ind==1) return (1.0-p1)*p2;
  else if(ind==2) return p1*(1.0-p2);
  //else if(ind==3) return (1.0-p1)*(1.0-p2);
  else return (1.0-p1)*(1.0-p2);

  
}

int main(void){

  ll n;
  cin>>n;
  vector<double> p(n+1);
  vector< vector<double> > q( 3000, vector<double>(3000,0.0) );
  rep1(i,n){
    cin>>p[i];
  }

  q[1][0]=p[1]; // round, num o' front
  q[0][1]=1.0-p[1];
  
  for(ll i=1;i<=n-2;i+=2){

    rep(j,i+1){
      //cout << i-j << "," << j << ":" << endl;
      rep(k,4){
        //cout << i-j + fb[k] << "," << j + fb[3-k] << endl;
        //cout << "q:" << q[i-j][j] << "next:" << next(p[i+1],p[i+2],k) << endl;
        q[i-j + fb[k] ][j + fb[3-k]] += q[i-j][j] * next(p[i+1],p[i+2],k);

      }

    }

  }
  double ans=0.0;
  for(ll i=n; i>n-i ;i--){
    //cout << i << "," << n-i << endl;
    ans+=q[i][n-i];
  }
  
  cout << setprecision(20) << ans << endl;

  return 0;

}


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

using namespace std;
using ll = long long;

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

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

  vector<int> a(n + 1);
  for (int i = 1; i < n; ++i) {
    a[i + 1] = a[i];
    if (s[i] == 'C' && s[i - 1] == 'A') ++a[i + 1];
  }

  rep(i, q) {
    int l, r;
    cin >> l >> r;
    int ans = a[r] - a[l];
    // if (l >= 2 && s[l - 1] == 'C' && s[l - 2] == 'A') --ans;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3772
import qualified Data.Map.Strict as M
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Debug.Trace

qTrace :: (Show a) => String -> a -> a
-- qTrace lab a = trace (lab ++ ": " ++ show a) a
qTrace _ a = a

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

type CMap = M.Map (Int, Int) Int

setMat :: [[Int]] -> CMap
setMat css =
  M.fromList $ concat (zipWith g [0..9] (map f css))
  where f cs = zip [0..9] cs
        g j zz = map (\(i, v) -> ((j, i), v)) zz

countAs :: [[Int]] -> M.Map Int Int
countAs ass = foldr f aInit [j | j <- concat ass, j >= 0]
  where f i mmap = M.alter g i mmap
        g Nothing = Just 1
        g (Just k) = Just (k + 1)
        aInit = M.fromList $ zip [0..9] (repeat 0)

modCmap :: CMap -> CMap
modCmap cmap = mcSub [(i,j) | i <- [0..9], j <- [0..9], i /= j] cmap

mcSub :: [(Int, Int)] -> CMap -> CMap
mcSub [] cmap = cmap
mcSub (p : tbc) cmap = mcSub ([q | q <- added, notElem q tbc] ++ tbc) newCmap
  where (added, newCmap) = mcSub2 p cmap

mcSub2 :: (Int, Int) -> CMap -> ([(Int, Int)], CMap)
mcSub2 (i,j) cmap = (map fst ps, foldr h cmap ps)
  where
    f k | i == k = []
        | j == k = []
        | otherwise = g i j k ++ g k i j
    g a b c | dist_abc < dist_ac = [((a,c), dist_abc)]
            | otherwise          = []
      where dist_abc = (cmap M.! (a,b)) + (cmap M.! (b,c))
            dist_ac  =  cmap M.! (a,c)
    ps = concatMap f [0..9]
    h ((a,b), dist) = M.adjust (const dist) (a,b)

solve :: CMap -> M.Map Int Int -> Int
solve cmap amap =
  let cmapMod = modCmap (qTrace "cmap" cmap)
  in sum $ map (\i -> (amap M.! i) * (cmapMod M.! (i, 1))) [0..9]

main :: IO ()
main = do
  conts <- B.getContents
  let [valH, valW] : iss = map bsReadInts (B.lines conts)
      (css, ass) = splitAt 10 iss
      cmat = setMat css
      xA = countAs ass
      answer = solve cmat xA
  putStrLn (show answer)



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

using namespace std;
typedef long long ll;

int main() {
    ll n;
    cin >> n;
    __int128 a = 1;
    ll thres = 1;
    for (ll i = 0; i < 18; i++) {
        thres *= 10;
    }
    for (ll i = 0; i < n; i++) {
        ll ta;
        cin >> ta;
        if (a == -1 && ta > 0) {
            continue;
        }
        a *= ta;
        if (a < 0) {
            a = -1;
        }
        if (a > thres) {
            a = -1;
        }
    }
    ll ans = a;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;

public static class Program
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        List<int> L = new List<int> 
        (
            new List<string>
            (
                Console.ReadLine().Split(' ')
                ).Select(_ => {return int.Parse(_);}));
        L.Sort();
        double result = 0;
        for(int i = 0; i < N; i++)
        {
            if(i == 0){
                result += L[i] * Math.Pow(0.5, N - 1);
            }
            else
            {
                result += L[i] * Math.Pow(0.5, N - i);
            }
        }
        Console.WriteLine(result);
    }

}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
	char c;

	cin >> c;
	cout << (char)(c + 1) << endl;

	return 0;
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define input() ios::sync_with_stdio(false);cin.tie(0);
void solve(){
	
}
int power(int x,int y){
	int res=1;
	while(y){
		if(y&1)
		res=res*x;
		x=x*x;
		y=y/2;
	}
	return res;
}
int main(){
    input()
    ll n,k;
    cin>>n>>k;
    ll ans=1e18;
    if(n>=k){
    	ll p=n%k;
    	ans=min(ans,p);
    	ans=min(ans,k-p);
    }
    else{
      ans=min(ans,n);
      ans=min(ans,k-n);  
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
k, a, b = map(int, input().split())

def uru(t, bis): # すぐ売れるとき
    c = min(t, int(bis/a)*2) # 売り買いの回数
    return int(c/2)*2, bis + (b - a)*int(c/2)

def sousa(t, bis): # 残りターン数、所持ビスケット数、所持金はゼロまで全部買った後
    req = max(a - bis, 0) + 2 # 売買に必要なターン数
    # print(t, bis, req)
    if t< req: # 残りターン不足
        print(bis + t)
        return 
    elif req >= b - a + (req - 2): # 売買の成果が叩く成果以下なら売買する意味なし
        print(bis + t)
        return
    elif bis > a: # すぐ売れるとき
        sousa(t - uru(t, bis)[0], uru(t, bis)[1])
    else: # 売買する
        sousa(t - req, bis + ((req - 2) - a + b)) # 売買の結果

import sys
sys.setrecursionlimit(5000000)
sousa(k, 1)

Measured memory_bytes: 7620
#include<iostream>
#include<vector>

using namespace std;
const int MX = 100005;

int main(){
    int N;
    long long A;
    long long Q;
    int B,C;
    long long sum;
    long long num;

    cin >> N;
    vector<long long> x(MX);

    for(int i = 1 ; i <= N ; i++){
        cin >> A;
        x[A]++;
        sum += A;
    }

    cin >> Q;

    long long calc;

    while(Q--){
        cin >> B >> C;
        sum-=B*x[B];
        sum+=C*x[B];
        x[C]+=x[B];
        x[B]=0;
        cout << sum << endl;
        /**
        num = C - B;
        calc = num * x[B] + sum;
        sum = calc;
        x[C] = x[C] + x[B];
        x[B] = 0;
        cout << calc << endl;
        **/

    }

    return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
	int h, n;
	cin >> h >> n;
	vector<int> a(n), b(n);
	for(int i = 0; i < n; i++)cin >> a[i] >> b[i];
	vector<ll> dp(100000, 100000000000000000);
	dp[0] = 0;

	for(int i = 0; i <= h; i++) {
		for(int j = 0; j < n; j++) {
			dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j]);
		} 
	}
	cout << *min_element(dp.begin() + h, dp.end()) << endl;
}

Measured memory_bytes: 1024
from collections import defaultdict

def prime_factors(n):
    d = defaultdict(int)
    while n%2 == 0:
        d[2] += 1
        n //= 2
    i = 3
    while i*i <= n:
        while n%i == 0:
            d[i] += 1
            n //= i
        i += 2
    if n > 2:
        d[n] += 1
    return d

# Combination
MOD = 10**9+7
MAX = 2*10**5
fac = [1,1] + [0]*MAX
finv = [1,1] + [0]*MAX
inv = [0,1] + [0]*MAX
for i in range(2,MAX+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

N, M = map(int, input().split())
ans = 1
pf = prime_factors(M)
for k,v in pf.items():
    ans *= comb(v+N-1, N-1)
    ans %= MOD
print(ans)


Measured memory_bytes: 28624
from collections import deque, defaultdict


def main():
    n, q = [int(e) for e in input().split()]
    AB = [[int(e) for e in input().split()] for i in range(n - 1)]
    PX = [[int(e) for e in input().split()] for i in range(q)]

    G = defaultdict(set)
    for a, b in AB:
        G[a].add(b)
        G[b].add(a)

    Ans = [0] * (n + 1)
    for p, x in PX:
        Ans[p] += x

    Q = deque([1])
    Visited = [False] * (n + 1)
    Visited[1] = True
    while len(Q) > 0:
        v = Q.popleft()
        for vc in G[v]:
            if Visited[vc]:
                continue

            Ans[vc] += Ans[v]
            Q.append(vc)
            Visited[vc] = True

    print(*Ans[1:])


if __name__ == '__main__':
    main()


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

using namespace std;


int main()
{
    long H,W;
    cin >> H >> W;
    long count = 0;

    if(W == 1){
        cout << 1 << endl;
        return 0;
    }

    if(H == 1)
    {
        cout << 1 << endl;
        return 0;
    }

    if(H % 2 ==0){
        cout << (H*W)/2 << endl;
    }else{
        if(W%2 ==0)
        {
            cout <<  ((H-1)*W) /2  + W /2 << endl;
        }else{
            cout <<  ((H-1)*W) /2  + ((W+1) /2)  << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 256
# include <iostream>
using namespace std;
string a;
int n,s;
void work (void)
{
	int i,p,q,t;
	p=0;
	q=0;
	for (i=0;i<n;i++)
	if (a[i]=='E')
	q++;
	for (i=0;i<n;i++)
	{
		if (a[i]=='E')
		t=p+q-1;
   else t=p+q;
		if (t<s)
		s=t;
		if (a[i]=='W')
		p++;
   else q--;
	}
	cout<<s;
}
int main (void)
{
	s=1000000000;
	cin>>n;
	cin>>a;
	work ();
	return 0;
}


Measured memory_bytes: 900
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String S = br.readLine();
		int N = Integer.parseInt(S);
		S = br.readLine();

		List<Integer> westList = new ArrayList<Integer>();
		List<Integer> eastList = new ArrayList<Integer>();

		int west = 0;
		int east = 0;

		for(int i = 0;i<S.length();i++){
			if(S.charAt(i) == 'W')west++;
			else east++;

			westList.add(west);
			eastList.add(east);
		}

		int change = eastList.get(eastList.size()-1) - eastList.get(0);
		change = Math.min(change, westList.get(westList.size()-1) );

		for(int i = 1;i<S.length()-1;i++){
			int nowE = westList.get(i) ;
			int nowW = eastList.get(eastList.size()-1) - eastList.get(i);

			change = Math.min(change, nowE+nowW);
		}

		System.out.println(change);


	}
}


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

int main() {
    string S;
    cin >> S;
  	int j=0;
    for (int i=0 ; i<3 ; i++){
    if (S.at(i)==S.at(i+1))
    j++;
    }
    if (j==3){
    cout << "No" << endl;
   	return 0;
    }
    if (S.at(0)==S.at(1)&&S.at(3)==S.at(2)){
    cout << "Yes" << endl;
    return 0;
    }
    if (S.at(0)==S.at(2)&&S.at(1)==S.at(3)){
    cout << "Yes" << endl;
    return 0;
    }
    if (S.at(0)==S.at(3)&&S.at(1)==S.at(2)){
    cout << "Yes" << endl;
    return 0;
    }
    cout <<"No" << endl;
}


Measured memory_bytes: 256