akhauriyash/Code-Regression huggingface dataset:
#include "cmath"
#include "cstdio"
#include "algorithm"
using namespace std;

const int maxn=10100;
struct edge {int u,v;double w;};
edge edges[maxn*maxn];
int f[maxn],n,m,p;
double tot,res;
int wx[maxn],wy[maxn];

double dis(int i,int j){return sqrt( 1.0*(wx[i]-wx[j])*(wx[i]-wx[j]) + (wy[i]-wy[j])*(wy[i]-wy[j]) );}

int find(int x){return f[x]==x?f[x]:f[x]=find(f[x]);}
int cmp(edge a,edge b){return a.w>b.w;}


void add(int u,int v,double w)
{
	edges[++p].u=u;
	edges[p].v=v;
	edges[p].w=w;
}

int main()
{
	//freopen("v.txt","r",stdin);
	//tot=res=.0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&wx[i],&wy[i]);
		f[i]=i;
	}
	
	for(int i=0;i<m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v,dis(u,v));
		tot=tot+dis(u,v);
	}
	
	sort(edges+1,edges+p+1,cmp);
	for(int i=1;i<=p;i++)
	{
		edge &e=edges[i];
		if(find(e.u)!=find(e.v))
		{
			res=res+e.w;
			f[find(e.u)]=find(e.v);
		}
	}
	
	printf("%.3f\n",tot-res);
	return 0;
}


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

public static partial class Program
{
    public static void Main()
    {
        var ap = CRL().ArrayInts();
        var cnt = ap[0] * 3 + ap[1];
        if (cnt == 0)
        {
            CWL(0);
        }
        else
        {
            CWL(cnt / 2);
        }
    }
}

public static partial class Program
{
    //テンプレここから
    public static int Sigma(int n, int next = 1, int val = 0) => next > n ? val : Sigma(n, next + 1, val + next);
    public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
    public static int GCD(int a, int b) => b == 0 ? a : GCD(b, a % b);
    public static long LCM(long a, long b) => a * b / GCD(a, b);
    public static int LCM(int a, int b) => a * b / GCD(a, b);
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static int ToInt(this double d) => (int) d;
    public static long ToLong(this double d) => (long) d;
    public static int ToInt(this string str) => int.Parse(str);
    public static long ToLong(this string str) => long.Parse(str);
    public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static int[] ArrayInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static readonly int[] Dx = new[] {0, -1, 0, 1};
    public static readonly int[] Dy = new[] {-1, 0, 1, 0};
    public const int Mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array) => array.OrderBy(x => x).ToArray();
    public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray();
    public static long[] DSort(this long[] array) => array.OrderByDescending(x => x).ToArray();
    public static int[] DSort(this int[] array) => array.OrderByDescending(x => x).ToArray();
    public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
    public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);

    public static string JoinToStr(this IEnumerable<int> array, string sep = "")
        => array.Select(x => x.ToString()).Join(sep);

    //テンプレここまで
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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;

int main(){
    Init();
    ll n, a, b; cin >> n >> a >> b;
    cout << max(0LL ,(b*(n-1)+a) - (a*(n-1)+b) + 1) << endl;
}

Measured memory_bytes: 3564
S = list(input())
count_g = [0,0]
count_k = [0,0]
for index, x in enumerate(S):
    if index % 2 == 0:
        if x == '0':
            count_g[0] += 1
        else:
            count_g[1] += 1
        
    else:
        if x == '0':
            count_k[0] += 1
        else:
            count_k[1] += 1
a = [count_k[0]+count_g[1], count_k[1]+count_g[0]]
print(min(a))


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

//コピペここから

namespace MMNMM {

// extended Euclidean Algorithm
// ax + by = gcd(a, b)
// return : gcd(a, b)
    template<typename Integer = int_fast64_t>
    constexpr Integer extgcd(Integer a, Integer b, Integer &x, Integer &y) {
        Integer u = 0, v = 1, q = 0, tmp = 0;
        x = v = 1;
        y = u = 0;

        while (b) {
            q = a / b;
            x ^= u ^= x ^= u;
            u = u - q * x;
            y ^= v ^= y ^= v;
            v = v - q * y;
            a ^= b ^= a ^= b;
            b = b - q * a;
        }

        return a;
    }

// mod inverse(設計が変わるかもしれません)
// return : val^(-1) mod MOD
    template<uint_fast64_t MOD, typename Integer = int_fast64_t>
    constexpr Integer modinv(Integer val) {
        int_fast64_t ret = 0, tmp = 0;

        extgcd<int_fast64_t>(static_cast<int_fast64_t>(val), static_cast<int_fast64_t>(MOD), ret, tmp);

        return static_cast<Integer>(ret > 0 ? ret % MOD : (MOD - (-ret % MOD)));
    }

// const expression factorial mod MOD
    template<std::size_t N, std::uint_fast64_t MOD>
    struct Fact {
        std::uint_fast64_t val[N + 1];

        constexpr Fact() : val() {
            val[0] = 1;
            for (std::size_t i = 1; i <= N; ++i) val[i] = val[i - 1] * i % MOD;
        }
    };

// const expression factorial inverse mod MOD
    template<std::size_t N, std::uint_fast64_t MOD, std::uint_fast64_t F>
    struct IFact {
        std::uint_fast64_t val[N + 1];

        constexpr IFact() : val() {
            val[N] = F;
            for (std::size_t i = N; i; --i) val[i - 1] = val[i] * i % MOD;
        }
    };
}

constexpr std::uint_fast64_t MOD = 998244353, maxN = 2250000;

constexpr auto fact = MMNMM::Fact<maxN, MOD>();
constexpr auto ifact = MMNMM::IFact<maxN, MOD, MMNMM::modinv<MOD>(fact.val[maxN])>();

// const expression binomial mod MOD
inline constexpr std::uint_fast64_t binommod(std::uint_fast64_t n, std::uint_fast64_t r){
    if(r < 0 || r > n)return 0;
    return fact.val[n] * (ifact.val[r] * ifact.val[n - r] % MOD) % MOD;
}

inline constexpr std::uint_fast64_t C(std::uint_fast64_t n, std::uint_fast64_t r){
    return binommod(n, r);
}

//コピペここまで(ある部分を使うためにはそれより上を全てコピーしてください)

//verified : AtCoder Grand Contest 025 B - RGB Coloring

long long int N, M, A, B, K, ans;

int main(){
    using namespace std;
    scanf("%lld%lld%lld%lld", &N, &A, &B, &K);
    M = min(N, K / A);
    for(int i = 0; i <= M; ++i){
        if((K - i * A) % B == 0){
            ans += C(N, i) * C(N, (K - i * A) / B);
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.trim().split("\n");
Arr.shift();
Arr.forEach(function(v){
   var ans=[];
   var arr=v.split("");
   var t=-1;
   for(var i=0;i<arr.length;i++){
      if(arr[i]=="c"){ans.push(0);t=1;}
      else if(arr[i]=="." && t==-1){ans.push(t);}
      else if(arr[i]=="." && t!=-1){ans.push(t);t++;}
   }
   console.log(ans.join(" "));
});

Measured memory_bytes: 9488
////   template  ///////////////////////////////////////////////////////
#include <stdlib.h>
#include <sys/time.h>
#include <stdio.h>
#include <sys/resource.h>
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

class timer{
	enum KIND{ REAL, CPU }; // real_time or cpu_time
	double t0; // start
	double t1; // end
	KIND kind_of_time; // default is real_time
	double get_realtime(){struct timeval tv; gettimeofday(&tv, NULL);
		return tv.tv_sec + (double)tv.tv_usec*1e-6;}
	double get_cputime(){struct rusage RU; getrusage(RUSAGE_SELF, &RU); 
		return RU.ru_utime.tv_sec + (double)RU.ru_utime.tv_usec*1e-6;}
public:
	timer(){kind_of_time = REAL;}
	void set(KIND k){kind_of_time = k;}
	void start(){t0 = get_realtime();}
	void stop(){t1 = get_realtime();}
	void print(){printf("TotalTime : %.3fsec\n", t1-t0);}
};
////////////////////////////////////////////////////////////////////////

int main()
{
	int a[4], b[4];
	while(cin>>a[0]>>a[1]>>a[2]>>a[3], cin>>b[0]>>b[1]>>b[2]>>b[3]){
		int hit=0, blow=0;
		bitset<10> fa, fb;
		for(int i=0; i<4; i++){
			if(a[i]==b[i]) hit++;
			fa.set(a[i]), fb.set(b[i]);
		}
		for(int i=0; i<10; i++)
			if(fa[i]&fb[i]) blow++;
		blow -= hit;
		cout << hit << " " << blow << endl;
	}

    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>

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

void bubble_sort(int *x, int n)
{
    int i, j, temp;

    for (i = 0; i < n - 1; i++) {
        for (j = n - 1; j > i; j--) {
            if (x[j - 1] < x[j]) {
                temp = x[j];
                x[j] = x[j - 1];
                x[j - 1]= temp;
            }
        }
    }
}


int main(void)
{
	int n;
	int a, b;
	int kcal, tcal[100];
	int sum;
	int ans;
	int i, j;
	
	scanf("%d", &n);
	scanf("%d%d", &a, &b);
	scanf("%d", &kcal);
	
	for (i = 0; i < n; i++){
		scanf("%d", &tcal[i]);
	}
	
	bubble_sort(tcal, n);
	
	ans = 0;
	for (i = 0; i < n; i++){
		sum = kcal;
		for (j = 0; j < i; j++){
			sum += tcal[j];
		}
		ans = max_(ans, sum / (a + b * i));
	}
	
	printf("%d\n", ans);
	
	return (0);
}

Measured memory_bytes: 0
// Aizu Vol-5 0568: Pasta
// 2017.8.31 bal4u@uu

#include <stdio.h>

int p[4][4][2];
int s[102];

int main()
{
	int n, k, a, b;
	int i, j, m, i1, i2, j1, j2, k1, k2, ans;

	scanf("%d%d", &n, &k);
	while (k--) scanf("%d%d", &a, &b), s[a] = b;
	if (s[1] > 0) i1 = i2 = s[1]; else i1 = 1, i2 = 3;
	if (s[2] > 0) j1 = j2 = s[2]; else j1 = 1, j2 = 3;
	for (i = i1; i <= i2; i++) for (j = j1; j <= j2; j++) p[i][j][0] = 1;

	for (k1 = 0, k2 = 1, k = 3; k <= n; k++, k1 = k2, k2 = !k2) {
		for (i = 1; i <= 3; i++) for (j = 1; j <= 3; j++) p[i][j][k2] = 0;
		for (i = 1; i <= 3; i++) for (j = 1; j <= 3; j++) for (m = 1; m <= 3; m++) {
			if (i == j) { if (m != j) p[j][m][k2] += p[i][j][k1]; }
			else                      p[j][m][k2] += p[i][j][k1];
		}
		if (s[k] > 0) {
			for (i = 1; i <= 3; i++) for (j = 1; j <= 3; j++) if (j != s[k]) p[i][j][k2] = 0;
		}
		for (i = 1; i <= 3; i++) for (j = 1; j <= 3; j++) p[i][j][k2] %= 10000;
	}
	for (ans = 0, i = 1; i <= 3; i++) for (j = 1; j <= 3; j++) ans += p[i][j][k1];
	printf("%d\n", ans % 10000);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	string s;
	cin>>s;
	if(s=="SUN"){
		cout<<7;
	}
	else if(s=="MON"){
		cout<<6;
	}
	else if(s=="TUE"){
		cout<<5;
	}
	else if(s=="WED"){
		cout<<4;
	}
	else if(s=="THU"){
		cout<<3;
	}
	else if(s=="FRI"){
		cout<<2;
	}
	else if(s=="SAT"){
		cout<<1;
	}
	re 0;
}

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

int main() {
  int d[7][7]={{0,300,500,600,700,1350,1650},{6,0,350,450,600,1150,1500},
               {13,7,0,250,400,1000,1350},{18,12,5,0,250,850,1300},
               {23,17,10,5,0,600,1150},{43,37,30,25,20,0,500},
               {58,52,45,40,35,15}};
      
  int a,b;
  while(cin >> a && a) {
    int x[2],y[2];
    cin >> x[0] >> x[1] >> b >> y[0] >> y[1];
    a--,b--;
    if(a>b) swap(a,b);
    int m1=x[0]*60+x[1],m2=y[0]*60+y[1];
    int c=d[a][b];
    if((m1>=17*60+30&&m1<=19*60+30||m2>=17*60+30&&m2<=19*60+30)&&d[b][a]<=40) {
      c/=2;
      if(c%50) c+=50-c%50;
    }
    cout << c << endl;
  }
  return 0;
}


Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>

int main(void){
  char S[1000];
  char *np, *sp, *ep, *wp; 
  int x = 0;
  int y = 0;
  
  scanf("%s", S);
  np = strchr(S, 'N');
  sp = strchr(S, 'S');
  ep = strchr(S, 'E');
  wp = strchr(S, 'W');
  
  if (np != NULL){
    y++;
  }
  if (sp != NULL){
    y--;
  }
  if (ep != NULL){
    x++;
  }
  if (wp != NULL){
    x--;
  }
  
  if(x == 0 && y == 0){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define y second
#define x first
#define lsb(x) (x&-x)
#define pb push_back
#define y second
const int NMAX=100666; //LOL
const int MOD=1000000007; //LOL
const int SQRT=350;
using namespace std;
const int INF=1000000007;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;

LL a,b,c;

int main()
{
	//freopen("input.in", "rt", stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>a>>b>>c;
	if(a%2==0 || b%2==0 || c%2==0)
	{
		cout<<0;
		return 0;
	}
	cout<<min({a*b, b*c, a*c});
	
	return 0;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
#define spn setprecision
#define fr(x,a,b,c) for(int x = a; x <= b; x+=c)
using namespace std;
ll multiply(ll num1, ll num2, ll mod) { // with mod > 1e9
	ll ans = 0;
	num1 %= mod;
	num2 %= mod;
	while (num2) {
		if (num2&1) {
			ans += num1;
			ans %= mod;
		}
		num1 *= 2;
		num1 %= mod;
		num2 /= 2;
	}
	return ans;
}
ll powmod2(ll base,ll exponent,ll mod){ // with mod > 1e9
	ll ans = 1;
	while (exponent) {
		if (exponent&1) {
			ans = multiply(ans, base, mod);
		}
		base = multiply(base, base, mod);
		exponent /= 2;
	}
	return ans;
}
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 2e6;
const int mod = 1e9+7;
int main() {
	int a,b,c;
	sd(a);sd(b);sd(c);
	pd(max(10*a+b+c,max(10*b+a+c,10*c+a+b)));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <tuple>

//....................................................................................................................//

using std::cin;
using std::cout;
using std::vector;
using std::list;
using std::unordered_set;
using std::set;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::swap;
using std::stack;
using std::deque;
using std::queue;
using std::ios_base;
using std::ifstream;
using std::ofstream;
using std::string;
using std::tuple;
using std::make_tuple;
using std::get;
using std::upper_bound;
using std::lower_bound;
using std::max_element;
using std::min_element;
using std::multiset;

//....................................................................................................................//

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long ul;

[[maybe_unused]] const string endl = "\n";
[[maybe_unused]] const string sep = " ";
[[maybe_unused]] const string yes = "YES\n";
[[maybe_unused]] const string no = "NO\n";
[[maybe_unused]] const string ng = "NG\n";
[[maybe_unused]] const string ok = "OK\n";
[[maybe_unused]] const double pi = acos(-1);

//....................................................................................................................//



int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout.precision(10);
    int n;
    cin >> n;
    vector<int> H(n);
    for (int i = 0; i < n; ++i) {
        cin >> H[i];
    }
    map<int, int> M;
    for (int i = 0; i < n; ++i) {
        ++M[i - H[i]];
    }
    ll result = 0;
    for (int i = 0; i < n; ++i) {
        result += M[i + H[i]];
    }
    cout << result;
}


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

using namespace std;

int n, l[105], x;

int main() {
	scanf("%d%d", &n, &x);
	
	for (int i = 1; i <= n; i++) scanf("%d", &l[i]);
	
	int res = 1;
	int cur = 0;
	
	for (int i = 1; i <= n; i++) {
		cur += l[i];
		if (cur <= x) res++;
	}
	
	printf("%d\n", res);
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);

    const PS = arg.slice(1, M + 1);
    
    const map = {};
    const penaMap = {};
    
    let score = 0;
    let pena  = 0;
    
    for(let i=0; i<M; i++) {
        const P = parseInt(PS[i].split(" ")[0]);
        const S = PS[i].split(" ")[1];
        
        if(!map[P] && S === "WA") {
            if(penaMap[P]) {
                penaMap[P]++;
            } else {
                penaMap[P] = 1;
            }
        } else if(!map[P] && S ==="AC") {
            map[P] = "done";
            score++;
            pena += penaMap[P] ? penaMap[P] : 0;
        }
        
        // console.log(P)
        // console.log(JSON.stringify(map));
        // console.log(!map[P])
    }
    
    console.log(score + " " + pena);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 31004
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;

void solve(int a[], int b[], int ret[]){
	// ret[0] = ヒット数, ret[1] = ブロー数
	for (int i = 0; i < 4; i++){
		if (a[i] == b[i])	ret[0]++;
		else{
			for (int j = 0; j < 4; j++){
				if (b[i] == a[j])
					ret[1]++;
			}
		}
	}
}

int main(){
	int a[4], b[4];
	int ret[2] = {};

	while (cin >> a[0] >> a[1] >> a[2] >> a[3], !cin.eof()){
		for (int i = 0; i < 4; i++)	cin >> b[i];
		ret[0] = 0; ret[1] = 0;
		solve(a, b, ret);
		cout << ret[0] << " " << ret[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<string>S(N);
    set<string>X;
    for(int i=0;i<N;i++){
        cin >> S[i];
        X.insert(S[i]);
    }
    cout << X.size() << endl;
}


Measured memory_bytes: 24992
#include <iostream>
using namespace std;
#define F(i,n) for( int i = 0; i < n; i++ )

char graph[6][2] = {
  // fで失敗
  { 'x', 'y' }, // a
  { 'f', 'z' }, // x
  { 'x', 'f' }, // y
  { 'w', 'b' }, // z
  { 'b', 'y' }, // w
  { 'y', 'x' }  // b    
};

bool simulate( string s ){
  char now = 'a';
  F( i, s.size() ){
    int next = s[i] == '0' ? 0 : 1;
    int nowIndex;
    if( now == 'a' ){ nowIndex = 0; }
    else if( now == 'x' ){ nowIndex = 1; }
    else if( now == 'y' ){ nowIndex = 2; }
    else if( now == 'z' ){ nowIndex = 3; }
    else if( now == 'w' ){ nowIndex = 4; }
    else if( now == 'b' ){ nowIndex = 5; }
    now = graph[ nowIndex ][ next ];
    if( now == 'f'){ return false; }
  }
  if( now == 'b' ){ return true; }
  else return false;
}

main(){
  string s;
  while( cin >> s && s != "#" ){
    if( simulate( s ) ){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<pair<int,int>> pii[m+10];
    vector<int> val(n,0); //n冊の本の値段
    vector<int> v(m,0);// 理解度の総和
    vector<int> u[n];//
    rep(i,n){
        int c;
        cin>>c;
        val[i]=c;
        rep(j,m){
            int a;
            cin>>a;
            v[j]+=a;
            pii[j].push_back({c,a});
            u[i].push_back(a);
        }
    }
    rep(i,m){
        if(v[i]<x){
            cout<<-1<<endl;
            return 0;
        }
    }
    int ans = inf;
    rep(i,1<<n){
        //vector<bool> buy(n,0);
        vector<int> und(m,0);
        int now = 0;
        bool ok = 1;
        rep(j,n){
            if((i>>j)&1){
                now += val[j];
                rep(k,m){
                    und[k]+=u[j][k];
                }
            }
        }
        for(auto u : und){
            if(u<x) ok = 0;
        }
        if(ok) ans = min(now,ans);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main () {
  int N, M, X;
  cin >> N >> M >> X;
  
  vector<vector<int>> skill(N, vector<int> (M+1));
  
  for (int i=0; i<N; i++) {
    for (int j=0; j<M+1; j++)
      cin >> skill.at(i).at(j);
  }
  
  //ansは制約上の上限（10^5 * N）より大きな数値を初期値で設定
  int ans = 100000 * N + 1;
  
  //全ビット探索
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    vector<int> sumskill(M+1);
    
    //ビット要素が1のときだけsumskillとして加算
    for (int i=0; i < N; i++) {
      if (s.test(i)) {
        for (int j=0; j <M+1; j++)
          sumskill.at(j) += skill.at(i).at(j);
      }
    }

    //各要素がX以上かどうか調べる
    int flag = 0;
    for (int i=1; i <M+1; i++) {
      if (sumskill.at(i) < X)
        flag++;
    }
    //すべてX以上だったらansを更新するか判定
    if (flag == 0)
      ans = min(ans, sumskill.at(0));
  }
  
  //ans更新していればansを。そうでなければ-1を出力
  if (ans == 100000 * N + 1)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Measured memory_bytes: 3592
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll H, W;
  cin >> H >> W;
  if (H == 1 || W == 1) {
    cout << 1 << endl;
    return 0;
  }

  ll answer = 0;
  for (ll y = 0; y < H; y++) {
    ll add = W / 2;
    if (W % 2 == 1 && y % 2 == 0) {
      add += 1;
    }
    answer += add;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public Main(){
		Scanner sc = new Scanner(System.in);
		
		System.out.println(((sc.nextLine()).replaceAll("peach", "sasami").replaceAll("apple", "samy").replaceAll("samy", "peach").replaceAll("sasami", "apple")));
	}
	
	public static void main(String[] args){
		Main test = new Main();
	}
}

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

int main() {
    int a,b;
    cin>>a>>b;
    int add,des,mul;
    add=a+b;
    des=a-b;
    mul=a*b;
    int ans;
    ans=max(add,des);
    ans=max(ans,mul);
    cout<<ans<<endl;
}


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

// 入力
int N, C[400], S[400][26];

// 出力
int Last[409];
int Answer[409];

int solve(int pos) {
	pair<int, int> maxn = make_pair(-(1 << 30), -1);
	for (int i = 1; i <= 26; i++) {
		int score = S[pos][i];
		for (int j = 1; j <= 26; j++) {
			if (i != j) score -= C[j] * (pos - Last[j]);
		}
		maxn = max(maxn, make_pair(score, i));
	}
	return maxn.second;
}

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> C[i];
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= 26; j++) cin >> S[i][j];
	}
	for (int i = 1; i <= N; i++) {
		Answer[i] = solve(i);
		Last[Answer[i]] = i;
	}
	for (int i = 1; i <= N; i++) cout << Answer[i] << endl;
	return 0;
}

Measured memory_bytes: 3684
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(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 debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    LL n; cin >> n;
    cout << (n * (n + 1)) / 2 - n << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair

void solve(int W, int H) {
    vector<pair<ll,ll>> a;
    rep(i,W) {
        int p; scanf("%d",&p);
        a.pb(mp(p,0));
    }
    rep(i,H) {
        int p; scanf("%d",&p);
        a.pb(mp(p,1));
    }
    sort(ALL(a));

    ll ans = 0;
    for(auto& i : a) {
        if(i.second == 0) {
            ans += i.first * (H + 1);
            --W;
        } else {
            ans += i.first * (W + 1);
            --H;
        }
    }

    cout << ans << "\n";
}

int main() {
    int W, H;
    cin>>W>>H;
    solve(W,H);
    return 0;
}

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

int main(){
	int n, t;
	cin >> n >> t;
	int ans = 0, start = 0, stop = 0;
	while(n--){
		int a;
		cin >> a;
		if(stop < a){
			ans += stop - start;
			start = a;
		}
		stop = a + t;
	}
	cout << ans + stop - start << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using Int = long long;
#define rep(i, n) for (Int i = 0; i < n; i++)

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end(), greater<Int>());
    Int ans=1e15;
    rep(i, n-k+1) {
        ans = min(ans, h[i]-h[i+k-1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
def partition(a, p, r):
    x = a[r][1]
    i = p-1

    for j in range(p, r):
        if a[j][1] <= x:
            i += 1
            a[i], a[j] = a[j], a[i]

    a[i+1], a[r] = a[r], a[i+1]
    return i+1


def quicksort(a, p, r):
    if p < r:
        q = partition(a, p, r)
        quicksort(a, p, q-1)
        quicksort(a, q+1, r)


def isstable(a):
    for i in range(n-1):
        if a[i][1] == a[i+1][1]:
            if a[i][2] > a[i+1][2]:
                return False
    return True


n = int(input())
deck = [None]*n
for num in range(n):
    card = input().split()
    deck[num] = [card[0], int(card[1]), num]

quicksort(deck, 0, n-1)
if isstable(deck):
    print("Stable")
else:
    print("Not stable")
[print(deck[i][0], deck[i][1]) for i in range(n)]

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

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	if (abs(a - c) <= d) {
		cout << "Yes" << endl;
	}
	else if (abs(a - b) <= d && abs(c - b) <= d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

int count_prime( unsigned int const& n )
{
    if ( n <= 0 || 1000000 <= n ) return -1;
    std::vector<bool> memo_prime( n+1, true );
    memo_prime.at(0) = memo_prime.at(1) = false;
    for ( unsigned int i = 2; i < n; ++i )
    {
        for ( unsigned int j = 2; i*j <= n; ++j )
        {
            memo_prime.at(i*j) = false;
        }
    }
    return std::count( memo_prime.begin(), memo_prime.end(), true );
}

int main()
{
    int n;
    while( std::cin >> n )
    {
        std::cout << count_prime(n) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int n; cin>>n;
    int a, b; cin>>a>>b;
    vector<int> p(n);
    for(int i=0; i<n; i++) cin>>p[i];
    sort(p.begin(), p.end());

    int num1=0, num2=0, num3=0;
    for(int i=0; i<n; i++){
        if(p[i]<=a) num1++;
        if(a<p[i]&&p[i]<=b) num2++;
        if(b<p[i]) num3++;
    }

    cout << min({num1, num2, num3}) << endl;
}

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

int main(){
    int n, t, T, c, menor_custo = 100002;
    cin >> n >> T;

    while(n--){
        cin >> c >> t;

        if(t <= T){
            if(c < menor_custo){
                menor_custo = c;
            }
        }
    }

    if(menor_custo == 100002) cout << "TLE\n";
    else cout << menor_custo << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void printa(int A[], int len) {
	cout << A[0];
	for (int i = 1; i < len; i++)
		cout << " " << A[i];
	cout << endl;
}

int bsort(int A[], int len) {
	int t = 0;
	for (int i = 0; i < len; i++) {
		for (int j = len - 1; j >= i + 1; j--) {
			if (A[j] < A[j-1]) {
				swap(A[j], A[j-1]);
				t++;
			}
		}
	}
	return t;
}

int main() {
	int n, *a, t;
	cin >> n;
	a = new int[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	t = bsort(a, n);
	printa(a, n);
	cout << t << endl;
	return 0;
}

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

int n,m;
int f[111][111];

int rec(int p, vector<int> &used){
    int res = 0;
    for(int u : used){
        int min_f = 1e9;
        for(int v : used){
            if(u == v) continue;
            min_f = min(min_f, f[u][v]);
            assert(f[u][v] > 0);
        }
        if(min_f == 1e9) min_f = 0;
        res += min_f;
    }
    for(int i = p; i < n; ++i){
        int min_f = 1e9;
        for(int v : used){
            min_f = min(min_f, f[i][v]);
        }
        if(min_f == 0) continue;
        used.push_back(i);
        res = max(res, rec(i+1, used));
        used.pop_back();
    }
    return res;
}

int main(){
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int u,v,f_;
        cin >> u >> v >> f_;
        --u; --v;
        f[u][v] = f[v][u] = f_;
    }
    vector<int> used;
    cout << rec(0,used) << endl;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string n ;
	cin>>n;
	if(n.size() == 1)
	{
		cout<<n;
		return 0;
	}
	for(int i =0 ; i < n.size() - 1; i ++)
	{
		if(n[i] == 'S' && n[i + 1] == 'T')
		{
			n.erase(i ,2);
		    if(i == 0)
		    {
		    	i = -1;
			}else
			{
				i-=2;
			}
		}
		if(n.size() == 0)
		{
			cout<<0;
			return 0;
		}
	}
	cout<<n.size();
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,m; cin >> n >> m;
	int a[n],t=0;
	for(int i=0; i<n; i++){
		cin >> a[i];
		t += a[i];
	}
	ld cutoff = ld(t)/(4*m);
	int cnt = 0;
	for(int i=0; i<n; i++){
		if(a[i]>=cutoff)cnt++;
	}
	cout << (cnt>=m?"Yes":"No") << endl;
}	
/*  Benq's (modified)
	stuff you should look for
	* ll, int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,x;cin >> n >> m >> x;
    ll a[n][m];ll c[n];
    for (int i = 0; i < n; ++i)
    {
        cin >> c[i];
        for (int j = 0; j < m; ++j)
        {
            cin >> a[i][j];
        }
    }
    int ans=1e18;
    for(int i=1;i<(1LL<<n);i++)
    {
        ll b[m];memset(b,0,sizeof(b));ll dans=0;
        for (int j = 0; j < n; ++j)
        {
            if(i&(1LL<<j))
            {
                dans+=c[j];
                for (int k = 0; k < m; ++k)
                {
                    b[k]+=a[j][k];
                }
            }
        }bool bl=1;
        for (int k = 0; k < m; ++k)
        {
            if(b[k]<x){bl=0;break;}
        }
        if(bl)ans=min(ans,dans);
    }
    if(ans==1e18)cout << -1;else cout << ans;
    }

Measured memory_bytes: 3656
def mrinfinit(a, b):
    bf = list(set(a))
    rr = a[:b]
    sf = list(set(rr))

    if len(bf) == 1 and bf[0] == '1':
        return a[0]
    elif len(sf) == 1 and sf[0] == '1':
        return a[0]
    elif len(a) > 1:
        if '1' in a:
            a = a.replace('1', '')
            return a[0]
        else:
            return a[0]
    else:
        return a[0]


if __name__ == '__main__':
    la = input()
    lb = int(input())
    print(mrinfinit(la, lb))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N;
  vector<string> blue(110);
  vector<string> red(110);
 
  for(int i=0;i<N;i++) {
    cin >> blue.at(i);
  }
  cin >> M;
  for(int i=0;i<M;i++) {
    cin >> red.at(i);
  }
  string cp;
  int sum,max=0;
  for(int b=0;b<N;b++) {
    cp=blue.at(b);
    sum=0;
    for(int bb=0;bb<N;bb++){
      if(cp==blue.at(bb)) sum++;
    }
    for(int rr=0;rr<M;rr++){
	if(cp==red.at(rr)) sum--;
    }
    if(sum>max) max=sum;
  }
 
  for(int b=0;b<M;b++) {
    cp=red.at(b);
    sum=0;
    for(int bb=0;bb<N;bb++){
      if(cp==blue.at(bb)) sum++;
    }
    for(int rr=0;rr<M;rr++){
	if(cp==red.at(rr)) sum--;
    }
    if(sum>max) max=sum;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> w(n);
    rep(i, n) cin >> w[i];
    ll tot = accumulate(all(w), 0LL);
    ll sum = 0;
    ll ans = LONG_LONG_MAX;
    rep(i, n) {
        sum += w[i];
        tot -= w[i];
        ans = min(ans, abs(sum - tot));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
          
        int n = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        
        int max, min;
        
        int cnt;
        
        if( a == 0 || b == 0 ){
          max = 0;
          min = 0;
        }
        
        else if( a + b <= n ){
          if(a>b){
            max = b;
          }
          else{
            max = a;
          }
          min = 0;
        }
        else{
          if(a>b){
            max = b;
          }
          else{
            max = a;
          }
          min = (a+b)-n;
        }
            
        System.out.println(max + " " + min);
	  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#define LL long long

LL gcd(LL a, LL b) {
	if (a < b)std::swap(a, b);
	if (a%b != 0)gcd(b, a%b);
	else return b;
}

int main() {
	LL A, B;
	while (std::cin >> A >> B) {
		LL g = gcd(A, B);
		std::cout << g << " " << (A*B) / g << std::endl;
	}
	return 0;
}


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

char shift_char(int shift_count, char char_in)
{
	char str[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int i, j;
	
	for (i = 0; i < 26; i++){
		if (char_in == str[i]) break;
	}
	
	j = (i + shift_count) % 26;
	
	if (j < 0) {
		j += 26;
	}
	return str[j];
}

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

  int len = s.size();
  
  vector<char> ans(len);
  
  for (int i = 0; i<len; i++){
    
    ans[i] = shift_char(n, s[i]);
    cout << ans[i];
  }
  
  cout << endl;
	
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc120/tasks/abc120_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

struct UnionFind {
    vector<int> data;

    UnionFind(int sz) { data.assign(sz, -1); }

    // 集合xとyを併合する. 併合済のときfalse, 未併合のときtrueが返される
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)
            return (false);
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    // 要素kが属する集合を求める
    int find(int k) {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    // 要素kが属する集合の要素の数を求める
    int size(int k) { return (-data[find(k)]); }
};

void solve() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> v(M);
    for (auto &x : v) {
        cin >> x.first >> x.second;
        x.first--, x.second--;
    }
    UnionFind uf(N);
    vector<int> ans;
    int cur = N * (N - 1) / 2;
    // UnionFindは連結のみ可能なので、逆順で連結する
    for (int i = M - 1; i >= 0; i--) {
        ans.emplace_back(cur);
        int sz1 = uf.size(v[i].first);
        int sz2 = uf.size(v[i].second);
        // 新たに併合した場合
        if (uf.unite(v[i].first, v[i].second)) {
            // 連結数が(sz1 * sz2)減る
            cur -= sz1 * sz2;
        }
    }
    reverse(ALL(ans));
    for (auto &x : ans) {
        cout << x << "\n";
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 6616
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

constexpr long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll n;
vvll edges;
vll fac, invfac;
vll subsz, subans, ans;

ll powmod(ll m, ll p) {
    if (p == 0) return 1;
    ll tmp = powmod(m, p / 2);
    if (p & 1) return (tmp * tmp % MOD) * m % MOD;
    else return tmp * tmp % MOD;
}

void initin() {
    fac.resize(n + 1), invfac.resize(n + 1);
    fac[0] = fac[1] = 1;
    for (ll i = 2; i <= n; i++) fac[i] = fac[i - 1] * i % MOD;
    invfac[0] = invfac[1] = 1;
    for (ll i = 2; i <= n; i++) invfac[i] = invfac[i - 1] * powmod(i, MOD - 2) % MOD;
}

ll dfs1(int i, int p) {
    subsz[i] = 1;
    for (int e: edges[i]) {
        if (e == p) continue;
        subsz[i] += dfs1(e, i);
    }
    subans[i] = fac[subsz[i] - 1];
    for (int e: edges[i]) {
        if (e == p) continue;
        (subans[i] *= invfac[subsz[e]]) %= MOD;
        (subans[i] *= subans[e]) %= MOD;
    }
    return subsz[i];
}

void dfs2(int i, int p) {
    ans[i] = fac[n - 1];
    for (int e: edges[i]) {
        (ans[i] *= invfac[subsz[e]]) %= MOD;
        (ans[i] *= subans[e]) %= MOD;
    }

    for (int e: edges[i]) {
        if (e == p) continue;
        subans[i] = (((ans[i] * invfac[n - 1] % MOD) * fac[n - 1 - subsz[e]] % MOD)
             * fac[subsz[e]] % MOD) * powmod(subans[e], MOD - 2) % MOD;
        subsz[i] = n - subsz[e];
        dfs2(e, i);

    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    edges.resize(n);
    for (ll i = 0; i < n - 1; i++) {
        ll a, b; cin >> a >> b;
        a--, b--;
        edges[a].emplace_back(b);
        edges[b].emplace_back(a);
    }
    initin();
    subsz.resize(n, 0), subans.resize(n, 0), ans.resize(n, 0);
    dfs1(0, -1); dfs2(0, -1);
    for (ll i = 0; i < n; i++) cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 22512
#include <iostream>

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

using namespace std;
int main(){
    const long long INF = 1LL << 60;
    long long dp[100010];
    int n, k;
    cin >> n >> k;
    int *h = (int *)calloc(n, sizeof(int));
    for(int i=0;i<n;++i){
        cin >> h[i];
    }

    for(int i=0;i<100010;++i) dp[i] = INF;
    dp[0] = 0;

    for(int i=0;i<n;++i){
        for(int j=i+1;j<=i+k;++j){
            if(j>n-1)break;
            chmin(dp[j], dp[i]+abs(h[i]-h[j]));
        }
    }
    cout << dp[n-1] << "\n";
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n, r;
	cin >> n >> r;
	if(n >= 10) cout << r << endl;
	else {
		cout << r + 100*(10-n) << endl;
	}
	return 0;
}



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

int main(){
  int n,W;
  cin >> n >> W;
  long long kizyun;
  int a[4][100];
  int w,v;
  cin >> w >> v;
  kizyun = w;
  int m[4] = {};
  a[w-kizyun][m[w-kizyun]] = v;
  m[w-kizyun]++;


  for(int i = 1;i < n;i++){
    cin >> w >> v;
    a[w-kizyun][m[w-kizyun]] = v;
    m[w-kizyun]++;
  }

  for(int i = 0;i < 4;i++){
    sort(a[i],a[i]+m[i],greater<int>());
  }

  int ans=0;

  int data[4] = {};
  for(int i = 0;i <= m[3];i++){
    if(i != 0) data[3] += a[3][i-1];
    for(int j = 0;j <= m[2];j++){
      if(j != 0) data[2] += a[2][j-1];
      for(int k = 0;k <= m[1];k++){
        if(k != 0) data[1] += a[1][k-1];
        for(int l = 0;l <= m[0];l++){
          if(l != 0) data[0] += a[0][l-1];
          if((3+kizyun)*i + (2+kizyun)*j + (1+kizyun)*k + kizyun*l <= W){
            ans = max(ans,data[0]+data[1]+data[2]+data[3]);
          }else{
            break;
          }
        }
        data[0] = 0;
      }
      data[1] = 0;
    }
    data[2] = 0;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100005];
int main()
{
  int n,k,i,j;
  cin>>n>>k;
  int h[n];
  for(i=0;i<n;i++) cin>>h[i];
  dp[0]=0;
  for(i=1;i<n;i++)
  {
    int t=2;
    dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
    while(t<=k && i-t>=0)
    {dp[i]=min(dp[i],dp[i-t]+abs(h[i]-h[i-t]));t++;}
  }
 cout<<dp[n-1];
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>

using namespace std;

const long long mod = 998244353;
int n;
int d[120000];
int ex[120000] , mx;
long long ans;
long long ksm ( long long f , long long x ) {
	long long s = 1;
	while ( x ) {
		if ( x % 2 ) s = s * f % mod;
		f = f * f % mod; x = x / 2;
	}
	return s % mod;
}
void work () {
	int i;
	scanf ( "%d" , &n );
	for ( i = 1 ; i <= n ; i++ ) {
		scanf ( "%d" , &d[i] );
		ex[d[i]]++;
		mx = max ( mx , d[i] );
	}
	ans = 1;
	if ( d[1] != 0 ) ans = 0;
	if ( ex[0] != 1 ) ans = 0;
	for ( i = 1 ; i <= mx ; i++ ) {
		ans = ans * ksm ( ex[i-1] , ex[i] ) % mod;
	}
	printf ( "%lld\n" , ans );
}
int main () {
	work ();
	return 0;
}


Measured memory_bytes: 896
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int total=0;
		for(int i=1;i<=N;i++) {
			total=total+i;
		}
		System.out.println(total);
	}

}


Measured memory_bytes: 21332
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>

const long long int Z = 1000000007;
const long long int INF = 1 << 30;
int flag = 0;
using ll = long long;

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

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

 int main() {
	 std::string s;
	 std::cin >> s;
	 for (int i = 0;i < s.size();i++) {
		 if (islower(s[i])) {
			 s[i] = toupper(s[i]);
		 }
		 else {
			 s[i] = tolower(s[i]);
		 }
	 }
	 std::cout << s;
	 while (std::cin >> s) {
		 std::cout << ' ';
		 for (int i = 0;i < s.size();i++) {
			 if (islower(s[i])) {
				 s[i] = toupper(s[i]);
			 }
			 else {
				 s[i] = tolower(s[i]);
			 }
		 }
		 std::cout << s ;
	 }
	 std::cout << std::endl;
	return 0;
}


Measured memory_bytes: 3152