akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long N, std::vector<long long> a){
    sort(ALL(a));
    reverse(ALL(a));
    ll ans = 0;
    REP(i, N){
        ans += a[2*i+1];
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(3*N);
    for(int i = 0 ; i < 3*N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	if(n < 1000){
		cout << "ABC" << endl;
	}else{
		cout << "ABD" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
function Main(input) {
	var num = input.split("\n");
	
	// 入力値のクレンジング
	var numList=new Array();
	for(var n=0; n<num.length; n++){
		var temp=num[n].split(" ");
		numList[n]=new Array();
		for(var n2=0; n2<temp.length; n2++){ numList[n].push(parseInt(temp[n2], 10)); }
	}
	
	// チェックリストの用意
	var checkList=new Array();
	for(var n=0; n<numList[0][1]; n++){ checkList[n]=0; }
	
	// チェック開始
	for(var n=1; n<numList.length; n++){
		for(var n2=1; n2<numList[n].length; n2++){
			checkList[numList[n][n2] - 1]++;
		}
	}
	
	// 結果
	var output=0;
	for(var n=0; n<checkList.length; n++){
		if(checkList[n]==numList[0][0]){ output++; }
	}
	
	//出力
	console.log(output);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        double a = scn.nextDouble();
        double b = scn.nextDouble();
        double C = scn.nextDouble();
        double S, c, L, h;
        h = b*Math.sin(Math.toRadians(C));
        S = a*h/2;
        c = Math.sqrt(Math.pow(a,2)+Math.pow(b,2)-2*a*b*Math.cos(Math.toRadians(C)));
        L = a+b+c;
        System.out.printf("%.8f%n",S);
        System.out.printf("%.8f%n",L);
        System.out.printf("%.8f%n",h);

        scn.close();

    }

}


Measured memory_bytes: 28272
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void scanArray(Scanner sc, int[] array, int num) {
        for (int i = 0; i < num; i++) {
            array[i] = sc.nextInt();
        }
    }

    //最小公倍数
    static long lcm(long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return (long) (c / b);
    }
    //最大公約数
    static long gcd (long a, long b) {
        long temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (long)b;
    }

    public static void main(String[] args) {

        int N;
        int K;
        HashSet<Integer> dSet = new HashSet<>();
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            K = sc.nextInt();

            for (int i = 0; i < K; i++) {
                int n = sc.nextInt();
                dSet.add(n);
            }
        }

        int result = N;
        while(true){
            if(checkNumaber(result,dSet)){
                break;
            }
            result++;
        }
        System.out.println(result);


    }

    static boolean checkNumaber(int target,HashSet<Integer> set){
        int n = target;
        boolean result = true;
        while(true){
            int i = n%10;
            if(set.contains(i)){
                result = false;
                break;
            }
            if(n<10){
                break;
            }
            n = n/10;
        }
        return result;
    }



}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5+100;
int t[MN];
int main() {
    int n;
    cin>>n;
    vector<int> v;
    for(int i = 0; i < n; ++i) {
        cin>>t[i];
        v.push_back(t[i]);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    map<int, int> mp;
    for(int i = 0; i < v.size(); ++i) {
        mp[v[i]] = i;
    }
    int q = 0;
    for(int i = 0; i < n; ++i) {
        t[i] = mp[t[i]];
        if(t[i]%2 != i%2) {
            ++q;
        }
    }
    cout<<q/2<<endl;
}


Measured memory_bytes: 5752
use std::io::prelude::*;

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

fn main() {
    let n: usize = input();
    let h: i64 = input();
    let (a, b): (Vec<i64>, Vec<i64>) = (0..n)
        .map(|_| {
            let a = input();
            let b = input();
            (a, b)
        })
        .unzip::<i64, i64, _, _>();

    let a_max = a.iter().max().unwrap();
    let mut b_use: Vec<i64> = b.iter().filter(|&b| b > a_max).cloned().collect();
    b_use.sort();
    b_use.reverse();

    let mut h = h;
    let mut ans = 0;
    for bi in b_use {
        ans += 1;
        h -= bi;
        if h <= 0 {
            break;
        }
    }

    if h > 0 {
        ans += (h + a_max - 1) / a_max;
    }

    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <iostream>
using namespace std;
int N;
char s[100008*3];
bool line[100008]={false}; // 0=s 1=w
bool d[4][2] = {
		{false,false},
		{false,true},
		{true,false},
		{true,true},
};
int main() {
	scanf("%d%s",&N,s);
	bool found = false;
	for(int i=0;i<4;i++){
		line[0] = d[i][0];line[1] = d[i][1];
		for(int j=1;j<N-1;j++){
			if(s[j]=='o' != line[j]){
				line[j+1]=line[j-1];
			}else{
				line[j+1]=!line[j-1];
			}
		}
		found=
				  (( line[1]==line[N-1] ) == ( (line[0]) != ( s[0]=='o' ) ) )
				&&(( line[0]==line[N-2] ) == ( (line[N-1]) != ( s[N-1]=='o' ) ) );
		if(found)break;
	}
	if(found){
		for(int i=0;i<N;i++)printf(line[i] ? "W":"S");
		printf("\n");
	}else printf("-1\n");
	return 0;
}


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

using namespace std;
const long mod = 1000000007;
typedef long long lint;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(N) for(int i = 0; i < (int)(N); i++)
#define all(x) (x).begin(),(x).end()
#define length(x) ((int)(x).size())
#define prln(s) cout<<s<<endl;

#define str(s) string s;cin>>s;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;

int main() {
  int2(n, m);
  int sum = 0;
  vector<int> a(n);
  repi(n){
    int1(ai);
    sum += ai;
    a[i] = ai;
  }
  int cc = 0;
  repi(n){
    if((double)a[i] >= (double)sum/(double)(4*m)){
      cc++;
    }
  }
  if(cc>=m){
    prln("Yes");
  }else{
    prln("No");
  }
}

Measured memory_bytes: 256
use std::io;
use std::cmp;


// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {

    let n = read_t_in_line::<i32>()[0];
    
    let mut ans = 1;
    for i in 0..n {
        if ans * 2 <= n {
            ans *= 2;
        }
        else{
            println!("{}", ans);
            break;
        }
    }

}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in<ll>(),M=in<ll>();
	ll sum = 0;
	if(2LL*N<=M){
		sum = N;
		M-=2LL*N;
		N=0;
		sum += M/4LL;
	}
	else{
		M -= (M%2);
		sum += M/2LL;
	}
	out(sum);
	return 0;
}


Measured memory_bytes: 256
let judge: int array -> string =
    Array.mapi (fun i x -> (x, i + 1))
    >> Array.sortBy (fun x -> x |> fst)
    >> Array.map (snd >> string)
    >> String.concat " "
//let input = [| 3, [|2;3;1|]; 5, [|1;2;3;4;5|]; 8, [|8;2;7;3;4;5;6;1|] |]
//for _, a in input do (judge a |> printfn "%s")
// expected 3 1 2; 1 2 3 4 5; 8 2 4 5 6 7 3 1
[<EntryPoint>]
let main argv =
    stdin.ReadLine() |> ignore
    stdin.ReadLine().Split()
    |> Array.map int
    |> judge
    |> printfn "%s"
    0


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

int main(){
    cin.sync_with_stdio(false);
    int n, w; cin >> n >> w;

    long long sumvals = 0;
    vector<vector<long long>>a(n, vector<long long>(2));
    for(int i = 0; i < n; i++){
        cin >> a[i][0] >> a[i][1];
        sumvals += a[i][1];
    }
    
    vector<vector<long long>>dp(n,vector<long long>(sumvals+1, LLONG_MAX));
    
    for(int i = 0; i < n; i++)dp[i][0] = 0;
    dp[n-1][a[n-1][1]] = a[n-1][0];

    for(int i = n-2; i >= 0; i--){
        for(long long j = 0; j <= sumvals; j++){
            if(a[i][1] <= j){
                dp[i][j] = min((a[i][0]+dp[i+1][j-a[i][1]])<0?LLONG_MAX:(a[i][0]+dp[i+1][j-a[i][1]]), dp[i+1][j]);
            }else{
                dp[i][j] = dp[i+1][j];
            }
        }
    }

    long long profit = sumvals;
    while(dp[0][profit] > w){
        assert(profit>=0);
        profit--;
    }
    cout<<profit<<endl;
}


Measured memory_bytes: 82296
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, a;
  string s;
  a=0;
  cin >> n;
  for(i=0;i<n;i++) {
    cin >> s;
      if(s == "Y") {
        a++;
        break;
      }
  }
  if(a == 0) {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
  return 0;
}
        


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class BIT {
    int n;
    vector<ll> node;

public:
    BIT(int N) : n(N), node(N + 1) {}
    void add(int i, ll x) {
        for (++i; i <= n; i += i & -i) { node[i] += x; }
    }
    ll sum(int i) {
        ll s = 0;
        for (; i > 0; i -= i & -i) { s += node[i]; }
        return s;
    }
};
class RSQ {
    int n;
    BIT a, b;

public:
    RSQ(int N) : n(N), a(N), b(N) {}
    void add(int l, int r, ll x) {
        int t = r - l;
        a.add(l, -l * x);
        a.add(r, r * x);
        b.add(l, x);
        b.add(r, -x);
    }
    ll sum(int i) { return a.sum(i) + i * b.sum(i); }
};

class Main {
    int N, K;
    vector<int> A;
    void input() {
        cin >> N >> K;
        A.resize(N);
        REP(i, N) { cin >> A[i]; }
    }
    void output() {
        REP(_, K) {
            vector<ll> imos(N + 2);
            REP(i, N) {
                imos[max(0, i - A[i]) + 1] += 1;
                imos[min(N, i + A[i] + 1) + 1] -= 1;
            }
            REP(i, N) {
                imos[i + 1] += imos[i];
                A[i] = imos[i + 1];
            }
            if (*min_element(A.begin(), A.end()) == N) break;
        }
        REP(i, N) { cout << A[i] << " "; }
        cout << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 5560
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N;
int main(){
	cin>>N;
	if(N<1200)cout<<"ABC"<<endl;
	else cout<<"ARC"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = n; i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	int n;
	cin >> n;
	if (n % 1000 == 0) cout << 0 << endl;
	else cout << 1000 - (n % 1000) << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

int main() {
  uint32_t N;
  cin >> N;
  vector<uint32_t> p(N);
  for (uint32_t i = 0; i < N; ++i) cin >> p[i];
  uint32_t cnt = 0;
  for (uint32_t i = 1; i < N + 1; ++i) {
    if (p[i - 1] != i) {
      ++cnt;
    }
  }
  if (cnt <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B == C + D) {
    cout << "Balanced" << endl;
  }else if (A + B > C + D){
    cout << "Left" << endl;
  }else{
    cout << "Right" << endl; 
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    ll n;string x;cin>>n>>x;
    int k = x.length();
    ll a=1;
    ll tmp=0;
    repn(i,k-1,0){
        if(x[i]!='.'){
            tmp +=  (x[i]-'0')*a;
            a*=10;
        }
    }
    ll ans;
    ans= n*tmp;
    ans/=100;
    cout<<ans;
 
return 0;
}

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;


public class Main {
	private	static	BufferedReader			br   = null;
	private	static	HashMap<String,Integer>	freq = null;
	static {
		br   = new BufferedReader(new InputStreamReader(System.in));
		freq = new HashMap<String,Integer>();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	strIn  = null;
		Integer	v      = null;
		String	strLng = "";
		String	strMax = null;
		Integer	nMax   = 0;

		while((strIn = parseStdin()) != null) {
			String[]	line = strIn.split(" ");
			for (int n = 0; n < line.length; n++) {
				if ((v = freq.get(line[n])) == null) {
					v = new Integer(1);
				}
				else {
					v++;
				}

				if (line[n].length() > strLng.length()) {
					strLng = line[n];
				}

				if (v > nMax) {
					nMax   = v;
					strMax = line[n];
				}

				freq.put(line[n], v);
			}
		}

		System.out.printf("%s %s\n", strMax, strLng);
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 15076
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>> n;
int m[n+1];
for(int i=1;i<=n;i++){
        m[i]=0;
    for(int j=1;j<=i;j++){
        if(i%j==0){
            m[i]=m[i]+1;
        }
    }
}
int sum=0;
for(int i=1;i<=n;i++){
    if(m[i]==8&&i%2!=0){
        sum++;
    }
}
cout<< sum;
    return 0;
}


Measured memory_bytes: 384
let five_antennas a b c d e k = if e - a > k then ":(" else "Yay!"

let a = read_int()
let b = read_int()
let c = read_int()
let d = read_int()
let e = read_int()
let k = read_int()

let () = Printf.printf "%s\n" (five_antennas a b c d e k)

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

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

	ll n;
	cin >> n;

	vector<ll> u(n), v(n);
	rep(i, n - 1) {
		cin >> u[i] >> v[i];
		if(u[i] > v[i]) swap(u[i], v[i]);
	}

	ll vcnt = (n+2) * (n+1) * n / 3 / 2 / 1;

	ll ecnt = 0;
	rep(i, n){
		ecnt += u[i] * (n - v[i] + 1);
	}

	cout << vcnt - ecnt << endl;
}


Measured memory_bytes: 6348
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9

bool a[1000001];
int s;

int f(int n) {
	if (n % 2 == 0) return n / 2;
	else return 3 * n + 1;
}

int ans = 1;

void solve(int n) { // 初めて2回でた数字を返す
	int num = f(n);
	ans++;
	if (num <= 1000000) {
		if (a[num] != true) {
			a[num] = true; // まだ出現してなかったらチェックを付ける
			solve(num);
		}
	}
	else solve(num);
}

int pos(int n) {


}

int main() {
	cin >> s;
	a[s] = true;
	solve(s);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	int h, w = -1;
	cin >> h >> w;
	while (h != 0 && w != 0) {
		for (int i = h; i > 0; --i) {
			for (int j = w; j > 0; j--) {
				if (j == w || j == 1 || (i == h || i == 1)) { printf("#"); }
				else { printf("."); }
			}
			printf("\n");
		}
		printf("\n");
		cin >> h >> w;
	}
}


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

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

    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];


    long long sum = 0;
    for (int i = 1; i <= N-1; i++) {
        if (A[i-1] <= A[i]) continue;
        sum += A[i-1] - A[i];
        A[i] += A[i-1] - A[i];
    }
    cout << sum << endl;
}



Measured memory_bytes: 4668
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1001001001;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll memo[100000];
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/

int main(){//keyence
    string K = "keyence";
    string S;
    cin >> S;
    ll s = S.size();
    ll left = 0;
    rep(i,7){
        if(S.substr(0,i + 1) == K.substr(0,i + 1))left = i + 1;
    }
    ll right = 0;
    rep(i,7){
        if(S.substr(s - 1 - i,i + 1) == K.substr(6 - i,i + 1))right = i + 1;
    }
    if(left + right >= 7)cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
 
int Pow(int n, int m);
int Max(int N[], int n);
int Min(int N[], int n);
int Sum(int N[], int n);
 
 
 
 
int main()
{
	int A = 0, B = 0, C = 0;
 
	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);
 
	int X[3] = { A,B,C };
 
	int ans = 9 * Max(X, 3) + Sum(X, 3);
 
  	printf("%d", ans);
  
	return 0;
}
 
int Pow(int n, int m) {
	int ret = 1;
 
	for (int i = 0; i < m; i++) {
		ret *= n;
	}
 
	return ret;
}
 
int Max(int N[], int n) {
	int max = N[0];
 
	for (int i = 0; i < n; i++) {
		max = max < N[i] ? N[i]: max;
	}
 
	return max;
}
 
int Min(int N[], int n) {
	int min = N[0];
 
	for (int i = 0; i < n; i++) {
		min = min > N[i] ? N[i] : min;
	}
 
	return min;
}
 
int Sum(int N[], int n) {
	int sum = 0;
 
	for (int i = 0; i < n; i++) {
		sum += N[i];
	}
 
	return sum;
}

Measured memory_bytes: 128
numDishes = int(input())
order = input()
sat1 = input()
sat2 = input()
satisfaction = 0
prev = -20

orderList = []
orderList = order.split(" ")
sat1List = []
sat1List = sat1.split(" ")
sat2List = []
sat2List = sat2.split(" ")

if (len(orderList) == numDishes) and (len(sat1List) == numDishes) and (len(sat2List) == numDishes-1):
    for i in orderList:
        num = int(i)
        if prev + 1 == num:
            satisfaction = satisfaction + int(sat1List[num - 1])
            satisfaction = satisfaction + int(sat2List[prev - 1])
        else:
            satisfaction = satisfaction + int(sat1List[num - 1]) 
        prev = num

print(satisfaction)


Measured memory_bytes: 3064
# 再帰関数の呼び出し回数が多くなる時はこれが必要！！無いとruntime errorになる。
import sys
sys.setrecursionlimit(100000+10)

# 木の深さ優先探索
def add_edge(u, v):
	G[u].append(v)
	G[v].append(u)

def dfs(vertex, x_set, y_set):

	global visited

	if visited[vertex]:
		#探索済み
		return 0
	visited[vertex] = True

	x_set.add(coords[vertex][1])
	y_set.add(coords[vertex][2])
	for v in G[vertex]:
		if visited[v]:
			#探索済み
			pass
		else:
			dfs(v, x_set, y_set)

	return len(x_set)*len(y_set)

n = int(input())

G = [[] for _ in range(n)] #グラフの隣接リスト表現

visited = [False] * n
now_index = n-1

coords = [ [i] + list(map(int, input().split())) for i in range(n)]

from operator import itemgetter

# xでソート
coords_xs = sorted(coords, key = itemgetter(1))
for i in range(n-1):
	if coords_xs[i][1] == coords_xs[i+1][1]: 
		# 隣接 coords_xs[i][0] coords_xs[i+1][0]
		add_edge(coords_xs[i][0], coords_xs[i+1][0])

# yでソート
coords_ys = sorted (coords, key = itemgetter(2))
for i in range(n-1):
	if coords_ys[i][2] == coords_ys[i+1][2]: 
		# 隣接 coords_ys[i][0] coords_ys[i+1][0]
		add_edge(coords_ys[i][0], coords_ys[i+1][0])

# 深さ優先探索
final = 0
for i in range(n):
	x_set = {coords[i][1]} #set
	y_set = {coords[i][2]}
	final += dfs(i, x_set, y_set)

print(final - n)
# print(coords)


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

typedef long long ll;

ll N;
vector<ll> A;

ll l[100100], r[100100];

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

int main() {
	cin >> N;
	A.resize(N);
	for(int i = 0; i < N; i++) {
		cin >> A[i];
	}

	for(int i = 0; i < N; i++) {
		if(i)
			l[i] = gcd(A[i], l[i-1]);
		else
			l[i] = A[i];
	}

	for(int i = N-1; i >= 0; i--) {
		if(i == N-1)
			r[i] = A[i];
		else
			r[i] = gcd(A[i], r[i+1]);
	}

	ll res = 1;
	for(int i = 0; i < N; i++) {
		if(i-1 < 0)
			res = max(res, r[i+1]);
		else if(i+1 >= N)
			res = max(res, l[i-1]);
		else
			res = max(res, gcd(l[i-1], r[i+1]));
	}
	cout << res << endl;
}




Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	if(t.substr(0, s.size()) == s)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3600
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}

const int MAXN=1000002;
char str[MAXN];

int main()
{
    scanf("%s",str);
    printf("%s",str[1]=='R'?"ABC":"ARC");

    return 0;
}

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

namespace CSharpSample01
{

    

    class Program
    {
        
        
        static void Main(string[] args)
        {
            
            while(true)
            {
                int n = int.Parse(Console.ReadLine());

                if(n == 0)
                {
                    break;
                }

                List<int> grade_list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();

                grade_list.Sort();
                
                int min_defe = (int)Math.Pow(10, 6);

                for(int i = 0; i < grade_list.Count() - 1; i++)
                {

                    if(Math.Abs(grade_list[i] - grade_list[i + 1]) < min_defe)
                    {
                        min_defe = Math.Abs(grade_list[i] - grade_list[i + 1]);                        
                    }
                    
                }

                Console.WriteLine(min_defe);

            }
            
        }
    }
}


Measured memory_bytes: 16312
#include <iostream>
#include <bits/stdc++.h>
#include <cstdlib>
#include <string>
using namespace std;

typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()

int main()
{
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = 0;

    if(a > k) {
        cout << k << endl;
    } else {
        ans += a;
        k -= a;

        for(int i = 0; i < b && k > 0; i++) {
            if(k == 0) break;
            --k;
        }

        for(int i = 0; i < c && k > 0; i++) {
            if(k == 0) break;
            --ans;
            --k;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
import Control.Monad
import Data.Set

f :: [String] -> Bool
f [] = True
f [w] = True
f (w0:w1:ws)
  | last w0 == head w1 = f (w1:ws)
  | otherwise = False

main = do
  n <- readLn
  w <- replicateM n getLine
  putStrLn $ if f w && size (fromList w) == n then "Yes" else "No"

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL maxn = 100+100;
int vis[maxn];
char a[maxn][maxn];
int len[maxn];
int ans[maxn];
int ans1[maxn];
int ans2[maxn];
int main()
{
    int n;
    cin>>n;
    string sum="";
    for(int i=1;i<=n;i++)
    {
        scanf("%s",a[i]);
        len[i]=strlen(a[i]);
    }
    for(int i=49;i<=74;i++)
    {
        ans2[i]=10000;//´æ´¢¸öÊý
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<len[i];j++)
        {
            ans1[a[i][j]-'0']++;
        }
        for(int j=49;j<=74;j++)
        {
            ans2[j]=min(ans2[j],ans1[j]);
        }
        memset(ans1,0,sizeof(ans1));
    }
    int flag=0;
    for(int i=49;i<=74;i++)
    {
        for(int j=0;j<ans2[i];j++)
        {
            printf("%c",i+'0');
            flag=1;
        }
    }
    if(flag)
    cout<<""<<endl;


}


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

typedef long long ll;
ll n, x;

ll calc(ll a, ll b) {
	if(a % b) return (a/b)*2*b+calc(b, a%b);
	return ((a/b)*2-1)*b;
}

int main() {
	scanf("%lld%lld", &n, &x);
	printf("%lld\n", n+calc(n-x, x));
	return 0;
}


Measured memory_bytes: 256
from collections import deque
dirc = ((1, 0), (0, 1), (-1, 0), (0, -1))
H, W = map(int, input().split())
maze = [list(str(input())) for _ in range(H)]
white = 0
for h in range(H):
    for w in range(W):
        if maze[h][w]=='.':
            white += 1
queue = deque()
queue.appendleft((0, (0, 0)))
checked = [[0]*W for _ in range(H)]
ans = 0
while queue:
    c, (y, x) = queue.pop()
    c += 1
    if checked[y][x]:
        continue
    checked[y][x] = 1
    if (y, x)==(H-1, W-1):
        ans = c
        break
    for i, (dy, dx) in enumerate(dirc):
        ny, nx = y+dy, x+dx
        if nx<0 or nx>=W or ny<0 or ny>=H:
            continue
        if maze[ny][nx]=='#':
            continue
        if not checked[ny][nx]:
            queue.appendleft((c, (ny, nx)))
if ans==0:
    print(-1)
else:
    print(white-ans)

Measured memory_bytes: 41712
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define P push
#define B begin()
#define E end()
#define SI size()
#define RE return
#define C continue
#define W while
#define SF(x) scanf("%d",&x);
#define MEM(vis,i) memset(vis,i,sizeof(vis))
#define rep(i,x,n) for(int i=x;i<n;i++)
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> pll;
const long long MOD = 1e9+7;
const long long MAX = 1e14+8;
const long long MAXN = 1e5+8;
const long long eps = 1e-4;
int main()
{
    string str;
    cin>>str;
    ll s=0;
    ll r=0;
    for(int i=0;i<str.SI;i++){
        if(str[i]=='S'){
            s++;
        }
        else{
            if(!s)C;
            s--;
            r++;
        }
    }
    cout<<str.SI-(r*2);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  sort(a,a+n);
  cout<<a[n-1]-a[0]<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3608
_, cards = input(), input().split()

def bubble_sort(array):
    A = array[:]
    for i in range(len(A)):
        for j in range(1, len(A) - i):
            if int(A[j - 1][1]) > int(A[j][1]):
                A[j], A[j - 1] = A[j - 1], A[j]
    return A

def selection_sort(array):
    A = array[:]
    for i in range(len(A)):
        minn = i
        for j in range(i, len(A)):
            if int(A[j][1]) < int(A[minn][1]): minn = j
        A[i], A[minn] = A[minn], A[i]
    return A
def is_stable(org, sorted):

    def get_same_numbers(array):
        result = {}
        for i in range(1, 10):
            result[i] = []
            for j in range(len(array)):
                if int(array[j][1]) == i:
                    result[i].append(array[j])
        return [cards for _, cards in result.items() if len(cards) >= 2]

    return "Stable" if get_same_numbers(org) == get_same_numbers(sorted) else "Not stable"

a = bubble_sort(cards)
print(" ".join(a))
print(is_stable(cards, a))
b = selection_sort(cards)
print(" ".join(b))
print(is_stable(cards, b))


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

void No(){
    cout << "No" << endl;
}

void Yes(){
    cout << "Yes" << endl;
}


int main(){

    int h, w; cin >> h >> w;
    vector<int> a(26, 0);
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char in; cin >> in;
            a[(int)(in - 'a')]++;
        }
    }

    if(h == 1 && w == 1){
        Yes();
        return 0;
    }

    if(h % 2 == 0 && w % 2 == 0){
        bool flag = true;
        for(int i = 0; i < 26; i++){
            if(a[i] % 4 != 0){
                flag = false;
                break;
            }
        }

        if(flag) Yes();
        else No();
        return 0;
    }

    if(h == 1 || w == 1){

        bool flag = false;
        int cnt = 0;
        for(int i = 0; i < 26; i++){
            cnt += (a[i] % 2);
        }

        if(cnt == 0) flag = true;
        else if(cnt == 1){
            if(h == 1 && w % 2 == 1) flag = true;

            if(h % 2 == 1 && w == 1) flag = true;
        }

        if(flag) Yes();
        else No();
        return 0;
    }

    if(w % 2 == 0){
        int cnt = 0;
        for(int i = 0; i < 26; i++){
            cnt += a[i] / 4;
            a[i] %= 4;
        }

        int k = (h - 1) * w / 4;

        if(cnt != k){
            No();
            return 0;
        }

        for(int i = 0; i < 26; i++){
            if(a[i]%2 != 0){
                No();
                return 0;
            }
        }

        Yes();
        return 0;
    }

    if(h % 2 == 0){
        int cnt = 0;
        for(int i = 0; i < 26; i++){
            cnt += a[i] / 4;
            a[i] %= 4;
        }

        int k = (w - 1) * h / 4;

        if(cnt != k){
            No();
            return 0;
        }

        for(int i = 0; i < 26; i++){
            if(a[i]%2 != 0){
                No();
                return 0;
            }
        }

        Yes();
        return 0;
    }

    if(h % 2 == 1 && w % 2 == 1){
        int cnt = 0;
        for(int i = 0; i < 26; i++){
            cnt += a[i] / 4;
            a[i] %= 4;
        }

        int k = (h - 1)*(w - 1)/4;
        //cout << k << cnt << endl;
        if(k != cnt){
            No();
            return 0;
        }

        cnt = 0;
        for(int i = 0; i < 26; i++){
            cnt += a[i] / 2;
            a[i] %= 2;
        }

        k = ((h - 1) + (w - 1))/2;
        //cout << k << cnt << endl;        
        if(k != cnt){
            No();
            return 0;
        }

        cnt = 0;
        for(int i = 0; i < 26; i++){
            cnt += a[i];
        }
        //cout << cnt << endl;
        if(cnt == 1){
            Yes();
        }else{
            No();
        }

        return 0;
    }

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($($args),*), ($($args),*));
    };
}

// (s, w + s)
fn maxi(a: (usize, usize), b: (usize, usize)) -> bool {
    a.0 * b.1 > b.0 * a.1
}

fn main() {
    let mut sc = Scanner::new();
    let a: usize = sc.cin();
    let b: usize = sc.cin();
    let c: usize = sc.cin();
    let d: usize = sc.cin();
    let e: usize = sc.cin();
    let f: usize = sc.cin();

    let mut ws = vec![];
    {
        const M: usize = 40;
        let mut memo = vec![false; M];
        memo[0] = true;
        for i in 0..M {
            if memo[i] {
                if i + a < M { memo[i + a] = true; }
            }
        }
        for i in 0..M {
            if memo[i] {
                if i + b < M { memo[i + b] = true; }
            }
        }
        for i in 0..M {
            if memo[i] && i * 100 <= f {
                ws.push(i * 100);
            }
        }
    }

    let mut ss = vec![];
    {
        const M: usize = 3003;
        let mut memo = vec![false; M];
        memo[0] = true;
        for i in 0..M {
            if memo[i] {
                if i + c < M { memo[i + c] = true; }
            }
        }
        for i in 0..M {
            if memo[i] {
                if i + d < M { memo[i + d] = true; }
            }
        }
        for i in 0..M {
            if memo[i] && i <= f {
                ss.push(i);
            }
        }
    }

    let mut ans = (0, 100 * a);
    // trace!(ws); trace!(ss);

    for &w in ws.iter() {
        for &s in ss.iter() {
            if w + s > f { continue }
            if 100 * s > e * w { continue }
            let noudo = (s, w + s);
            if maxi(noudo, ans) {
                ans = noudo;
            }
        }
    }

    println!("{} {}", ans.1, ans.0);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
int B[205000];
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) B[i] = A[i];
    sort(A.begin(), A.end(), greater<int>());
    for(int i = 0; i < N; i++) {
        if(A[0] == B[i]) cout << A[1] << endl;
        else cout << A[0] << endl;
    }
    return 0;
}


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



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

  int n; cin >> n;
  string s; cin >> s;
  int r = 0,b = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'R'){
      r++;
    }
    else b++;
  }
  if(r > b){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#120_D
#Union-Find
n,m=map(int,input().split())
edges=[]
for _ in range(m):
    a,b=map(int,input().split())
    edges.append((a-1,b-1))
edges=edges[::-1]

par=[i for i in range(n)]
size=[1 for _ in range(n)]
rank=[0 for _ in range(n)]

def find(x):#木の根を求める
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
    
def merge(x,y):#併合
    x=find(x)
    y=find(y)
    if x==y:
        return
    if rank[x]>rank[y]:
        par[y]=x
        size[x]+=size[y]
    else:
        par[x]=y
        size[y]+=size[x]
        if rank[x]==rank[y]:
            rank[y]+=1
            
def same(x,y):
    return find(x)==find(y)
    

ans=[n*(n-1)//2 for i in range(m)]
for i in range(0,m-1):
    a,b=edges[i]
    ans[i+1]=ans[i]
    if not same(a,b):
        ans[i+1]-=size[find(a)]*size[find(b)]
        merge(a,b)
        

ans=ans[::-1]
for i in range(m):
    print(ans[i])

Measured memory_bytes: 28080
# ABC086C - Traveling (ARC089C)
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
    for t, x, y in A:
        if x + y > t or (t + x + y) % 2 != 0:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

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


#define MAX 32
#define pb push_back
#define mp make_pair

using namespace std;

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

int h,w,n;

bool check(char f[MAX][MAX])
{
	int i1,i2,i3,i4;
	bool tf[MAX][MAX];
	char temp[MAX][MAX];
	int x,y;
	int cnt;
	char c;
	bool b;

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			if(f[i1][i2]!='.') {
				i1=99;
				break;
			}
		}
	}
	if(i1!=100) return true;

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			temp[i1][i2]=f[i1][i2];
			tf[i1][i2]=false;
		}
	}

	for(i1=1;i1<=w;i1++){
		cnt=0;
		for(i2=h;i2>1;i2--){
			if(temp[i2][i1]=='.') {
				cnt++;
			}
			if(cnt>0 && temp[i2][i1]!='.') {
				temp[i2+cnt][i1]=temp[i2][i1];
				temp[i2][i1]='.';
			}
		}
	}

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			if(temp[i1][i2]!='.'){
				c=temp[i1][i2];

				for(i3=0;i3<2;i3++){
					cnt=0;
					y=i1;
					x=i2;
					while(c==temp[y][x]){
						cnt++;
						y+=dy[i3];
						x+=dx[i3];
					}
					if(cnt>=n) {
						y=i1;
						x=i2;
						for(i4=0;i4<cnt;i4++){
							tf[y][x]=true;
							y+=dy[i3];
							x+=dx[i3];
						}
					}
				}
			}
		}
	}

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			if(tf[i1][i2]) temp[i1][i2]='.';
		}
	}

	for(i1=1;i1<=w;i1++){
		cnt=0;
		for(i2=h;i2>0;i2--){
			if(temp[i2][i1]=='.') {
				cnt++;
			}
			if(cnt>0 && temp[i2][i1]!='.') {
				temp[i2+cnt][i1]=temp[i2][i1];
				temp[i2][i1]='.';
			}
		}
	}

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			if(f[i1][i2]!=temp[i1][i2]) {
				i1=99;
				break;
			}
		}
	}
	if(i1!=100) {
		return false;
	}


	return check(temp);
}

int main(void)
{

	int i1,i2;
	char f[MAX][MAX];

	for(i1=0;i1<MAX;i1++){
		for(i2=0;i2<MAX;i2++){
			f[i1][i2]='.';
		}
	}

	cin>>h>>w>>n;
	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			cin>>f[i1][i2];
		}
	}

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<w;i2++){
			if(f[i1][i2]!='.' || f[i1][i2+1]!='.'){
				swap(f[i1][i2],f[i1][i2+1]);
				if(check(f)) {
					cout<<"YES"<<endl;
					return 0;
				}
				swap(f[i1][i2],f[i1][i2+1]);

			}
		}
	}



	cout<<"NO"<<endl;

	return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	int n;	cin >> n;
	vector<int> d(n);	VECCIN(d);

	ll ans = 0;
	for(int i = 0 ; i < n ; i++){
	 for(int j = i + 1 ; j < n ; j++){
		ans += d[i]*d[j];
	 }
	}

	SCOUT(ans) << endl;

	return 0;
}

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

bool binary_search(long key, long nums[], int size) {
  int left = 0;
  int right = size;

  while (left < right) {
    int mid = (left + right) / 2;

    if (nums[mid] == key) {
      return true;
    }

    if (key < nums[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }

  return false;
}

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

  long S[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  int q;
  cin >> q;

  int count = 0;
  for (int j = 0; j < q; j++) {
    long t;
    cin >> t;

    bool found = binary_search(t, S, n);
    if (found) {
      count++;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 3856
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define inf 1000000000000000000
#define N 1000000007
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

//try thinking from a different angle after spending some time
//edge cases when n=1,m=1.wrong variable in loop.if<->while;merge resize;LLONG_MAX
signed main()
{
    speed
    //global var
    int x;cin>>x;
    int cnt=8;
    for(int i=600;i<=2000;i+=200){
        //cout<<i<<"\n";
        if(x<i){cout<<cnt;return 0;}
        --cnt;
    }
}

Measured memory_bytes: 3640