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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        ans+=min(2*abs(a-k),2*a);
    }
    cout<<ans<<"\n";
    
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};


signed main(){

    string s; cin >> s;


    int n = (int)s.size();
    for(int l = 0; l < n; l++){
        for(int r = l; r <= n; r++){
            string t = "";

            for(int k = 0; k < n; k++){
                if(l <= k && k < r) continue;

                t = t + s[k];
            }

            if(t == "keyence"){
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



int main() {
	int N;
	cin >> N;
	vector<int>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		while (v[i] % 2 == 0) {
			v[i] /= 2;
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define scan int n;cin>>n;for(int i=0;i<n;i++)
#define ll long long
#define vl vector<long long>
using namespace std;
#define mod 1000000007
int main(){
    ios_base::sync_with_stdio(false);
    unsigned long long x,y;
    cin >> x >> y;
    if((x+y) % 3 != 0 || min(x,y) *2 < max(x,y)){
        cout << 0 << endl;
    }else if(min(x,y) * 2 == max(x,y)){
        cout << 1 << endl;
    }else{
       unsigned long long level = (x+y) / 3;
        int index = 2*level - x;
       unsigned long long factLevel = 1;
        for(int i=2;i<=level;i++) factLevel = (factLevel*i)%mod;
       unsigned long long factX = 1; 
        for(int i=2;i<=index;i++) factX = (factX * i) % mod;
      unsigned  long long facti = 1; 
        for(int i=2;i<=level-index;i++) facti = (facti * i)% mod;

        unsigned long long begin = ((facti % mod) *  (factX % mod))% mod;
        //cout << begin << endl;
        long long p = mod-2;
        unsigned long long answer = 1;
        //cout << answer << " " << p << endl;
        while(p != 0){
            //cout << answer << " " << p <<" " << begin << endl;
            if(p % 2 == 0){
                begin = (begin * begin) % mod;
                p = p/2;
            }else{ 
                p--;
                answer = ((answer % mod) * (begin % mod))%mod;
            }
        }
        cout << (answer * factLevel % mod) << endl;
    }
}



Measured memory_bytes: 256
N = gets.to_i
A = (0...N).map{ gets.split.map(&:to_i) }
b = (0...N).map{ |i| (0...N).map{ |j| A[i][j] } }

N.times{ |i|
  i.times{ |j|
    a = A[i][j]
    N.times.each{ |k|
      v = A[i][k] + A[k][j]
      next if a < v
      if v < a
        puts -1; exit
      end

      next if i == k || j == k
      b[i][j] = 0; break
    }
  }
}

puts (0...N).reduce(0){ |a,i| a + (0...i).reduce(0){ |a,j| a+b[i][j] } }

Measured memory_bytes: 4348
#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() {
	char c;
	cin >> c;

	string alphabet = "abcdefghijklmnopqrstuvwxyz";
	for (int i = 0; i < alphabet.size(); i++) {
		if (c == alphabet[i]) {
			cout << alphabet[i + 1] << endl;
		}
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  if(S.at(0) == 'a' || S.at(0) == 'i' || S.at(0) == 'u' || S.at(0) == 'e' || S.at(0) == 'o'){ 
    cout << "vowel" << endl;
  } else {
  	cout << "consonant" << endl;
  }
}


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

int main(){
  int a,b,x; cin >>a >>b >>x;
  if(a*a*b>=2*x) cout <<fixed<<setprecision(10)<<atan(a*b*b/2.0/x)*180/acos(-1);
  else cout <<fixed<<setprecision(10)<<atan((2.0*b-2.0*x/a/a)/a)*180/acos(-1);
return 0;}

Measured memory_bytes: 512
#pragma region Macros

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> const &v) {
    for (auto &&a : v) out << a << " ";
    out << endl;
    return out;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;

    cout << Z << " " << X << " " << Y;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3648
#include<stdio.h>

int main()
{
//変数定義
int A;
int B;

//入力
scanf("%d", &A);
scanf("%d", &B);

//A,Bの判定
if(A>=10){
printf("-1\n");
}else if(B>=10){
printf("-1\n");
}else{
printf("%d\n",A*B);
}
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int main()
{
    int n, x;
    cin >> n >> x;
    int a[n];
    rep(i, 0, n) cin >> a[i];

    sort(a, a + n);
    int ans = 0;
    rep(i, 0, n) {
        if (a[i] <= x) {
            ans ++;
            x -= a[i];
        } else {
            break;
        }
    }
    if (ans == n && x) ans --;
    cout << ans << endl;
}


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

int findnum(int num)
{
    int m = 0;
    while (num > 0)
    {
        m += num % 10;
        num /= 10;
    }
    return m;
}
int main()
{
    int a, b, n;
    cin >> n >> a >> b;
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        int sum = findnum(i);

        if (a <= sum && sum <= b)
        {
            cnt += i;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



Measured memory_bytes: 1136
#include "bits/stdc++.h"
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    vector<int> rest(n+1,0);
    vector<int> ans(n+1,0);
    vector<int> res;
    for(int i = n; i > 0; i--){
        ans[i] = (abs(rest[i] - a[i]))%2;
        if(ans[i] == 1){
            res.push_back(i);
            for(int j = 1; j * j <= i; j++){
                if(i % j == 0){
                    if(j * j == i) rest[j]++;
                    else{
                        rest[j]++;
                        rest[i/j]++;
                    }
                }
            }
        }
    }
    int m = res.size();
    cout << m << endl;
    for(int i = 0; i < m; i++){
        cout << res[i];
        if(i == m-1) cout  << endl;
        else cout << " ";
    }
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
 
struct city{
  int pref;
  int year;
  int id_head;
  int id_tail;
  int num;
};
 
int main(){
  int n,m,pref,year,buf;
  array<city,100000> c; 
  
  cin >> n >> m ;
  for(int i=0; i<m; i++){
    cin >> c[i].pref >> c[i].year ;
    c[i].num = i;
  }
  
  sort(c.begin(),c.begin()+m,
      [](const city &x, const city &y) { return x.pref == y.pref ? x.year < y.year : x.pref < y.pref;});
  
  for(int i=0,pref=0,year=1; i<m; i++){
    c[i].id_head = c[i].pref;
    if(pref == c[i].pref) year++;
    else                { pref=c[i].pref; year=1;}
    c[i].id_tail = year; 
  }
  
  sort(c.begin(),c.begin()+m,
      [](const city& x, const city& y) { return x.num < y.num;});
  
  for(int i=0; i<m; i++){
    printf("%06d%06d\n",c[i].id_head,c[i].id_tail);
  }
  
  return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  ll n,m;
  while(cin>>n>>m,n+m){
    ll ans=0;
    vector<pair<int,int> >pii(n);
    for(int i=0;i<n;i++){
      cin>>pii[i].S>>pii[i].F;
      ans+=pii[i].S*pii[i].F;
    }
    int po=n-1;
    sort(pii.begin(),pii.end());
    while(po>=0){
      if(m-pii[po].S>=0){
	ans-=pii[po].F*pii[po].S;
	m-=pii[po].S;
      }else{
	ans-=pii[po].F*m;
	break;
      }
      po--;
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ll long long 
#define MM(arr,x) memset(arr,x,sizeof(arr))
#define INF 0x3f3f3f3f
#define Maxn 1e5+10;
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	string s;
	int n,cnt=0,ans=0;
	cin>>n;
	cin>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R') cnt++;
	}
	for(int i=0;i<cnt;i++)
	{
		if(s[i]=='W') ans++;
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 3788
import java.util.Scanner;

public class Main{    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
                
        while(true){
            int H=sc.nextInt();
            int W=sc.nextInt();
            if(H==0&&W==0){
                break;
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(i==0 || j==0 || i==H-1 || j==W-1){
                        System.out.printf("#");
                    }else{
                        System.out.printf(".");
                    }                  
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


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

typedef struct myvector{
  double x;
  double y;
}Vector;

Vector sub_vector(Vector& a, Vector& b)
{
  Vector ret;
  ret.x = b.x - a.x;
  ret.y = b.y - a.y;
  return ret;
}

double cross_product(Vector& a, Vector& b)
{
  return a.x * b.y - b.x * a.y;
}

int main()
{
  Vector A, B, C, P;
  while(cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> P.x >> P.y){
    Vector AC = sub_vector(A, C);
    Vector CB = sub_vector(C, B);
    Vector BA = sub_vector(B, A);
    Vector AP = sub_vector(A, P);
    Vector CP = sub_vector(C, P);
    Vector BP = sub_vector(B, P);
    if((cross_product(AP, AC) > 0 && cross_product(CP, CB) > 0 && cross_product(BP, BA) > 0) || ((cross_product(AP, AC) < 0 && cross_product(CP, CB) < 0 && cross_product(BP, BA) < 0)))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;    
  }
}

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double

void dump(const vector<int>& a) {
  if (a.size() == 0) {
    return;
  }
  cout << a[0];
  rep2(i,1,a.size()) {
    cout << " " << a[i];
  }
  cout << endl;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n, 0);
  rep(i, n) {
    cin >> a[i];
  }
  rep2(i,1,n) {
    dump(a);
    const int v = a[i];
    int j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j+1] = a[j];
      --j;
    }
    a[j+1] = v;
  }
  dump(a);
  return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <functional>
using namespace std;

long long N, X, dp[100], dp2[100], sum = 0;

int main() {
	cin >> N >> X;
	dp[0] = 1; for (int i = 1; i <= N; i++) dp[i] = dp[i - 1] * 2 + 3;
	dp2[0] = 1; for (int i = 1; i <= N; i++) dp2[i] = dp2[i - 1] * 2 + 1;

	for (int i = N; i >= 1; i--) {
		if (X <= 1) {
			sum += 0; X = 0;
		}
		else if (X <= 1 + dp[i - 1]) {
			X -= 1;
		}
		else if (X <= 2LL + dp[i - 1]) {
			sum += dp2[i - 1] + 1; X = 0;
		}
		else if (X <= 2LL + 2LL * dp[i - 1]) {
			X -= (2LL + dp[i - 1]);
			sum += dp2[i - 1] + 1;
		}
		else {
			X = 0; sum += dp2[i];
		}
	}
	if (X >= 1) sum += 1;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int p=a*c;
    long long   int q=a*d;
    long long int r=b*c;
    long long  int s=b*d;
    cout<<max(p,max(q,max(r,s)))<<endl;
    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <sstream>

using namespace std;

int main()
{
	vector<string> sv;
	for (int i = 1; i <= 9; i++){
		for (int j = 1; j <= 9; j++){
			stringstream ss;
			ss << i << 'x' << j << '=' << i*j << '\n';
			string temp = ss.str();
			sv.push_back(temp);
		}
	}

	//sv.back().erase(sv.back().find('\n'));

	for_each(sv.begin(), sv.end() ,
		[](string tmp){
		cout << tmp;
		}
	);

	getchar();
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
long long int runrun(long long int k){
  
} 

int main (){
  long long int i,k;
  cin>>k;
  queue<long long int> q1;
  for(i=1;i<=9;i++){
    q1.push(i);
  }
  long long int x;
  for(i=0;i<k;i++){
    x = q1.front();
    q1.pop();
    if(x%10!=0){
      q1.push(x*10+x%10-1);
    }
    q1.push(10*x+x%10);
    if(x%10!=9){
      q1.push(x*10+x%10+1);
    }
  }
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

class UnionFind{
    vector<int> par;
    vector<long long> wei;
    int groupCount;

public:
    UnionFind(int n = 0){
        init(n);
    }

    void init(int n = 0){
        par.resize(n);
        fill(par.begin(), par.end(), -1);

        wei.resize(n);
        fill(wei.begin(), wei.end(), 0LL);

        groupCount = n;

        return;
    }

    int root(int x){
        if(par[x] < 0){
            return x;
        }
        int r = root(par[x]);
        wei[x] += wei[par[x]];
        return par[x] = r;
    }

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

    int size(int x){
        return -par[root(x)];
    }

    long long weight(int x){
        root(x);
        return wei[x];
    }

    long long diff(int x, int y){
        return weight(y) - weight(x);
    }

    bool unite(int x, int y, long long w = 0){
        w += weight(x) - weight(y);

        x = root(x);
        y = root(y);

        if(x == y){
            return false;
        }

        if(par[y] < par[x]){
            swap(x, y);
            w = -w;
        }

        par[x] += par[y];
        par[y] = x;
        wei[y] = w;
        --groupCount;

        return true;
    }

    int size(void){
        return groupCount;
    }
};

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

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

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

    int n, q;
    cin >> n >> q;

    UnionFind uf(n);
    while(q--){
        int com, x, y;
        cin >> com >> x >> y;

        if(com == 0){
            uf.unite(x, y);
        }else if(com == 1){
            cout << uf.same(x, y) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3340
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Fri Dec 28 23:24:07 2018
//
package main

import "fmt"

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var N int
	fmt.Scan(&N)

	arr := make([]int, N)
	for i := range arr {
		fmt.Scan(&arr[i])
	}

	total := 0
	for i, a := range arr {
		if i == 0 {
			total += abs(a - 0)
		} else {
			total += abs(a - arr[i-1])
		}
	}
	total += abs(0 - arr[len(arr)-1])

	for i, a := range arr {
		before := 0
		if i > 0 {
			before = arr[i-1]
		}
		next := 0
		if i+1 < len(arr) {
			next = arr[i+1]
		}
		high := abs(a-before) + abs(next-a)
		low := abs(next - before)
		fmt.Println(total - high + low)
	}
}


Measured memory_bytes: 6528
s = list(str(input()))

count = 0
ACGT = ["A","C","G","T"]
tmp_max = [0]

if all(s) in ACGT:
	print(len(s))
else:
	for letter in s:
		if letter in ACGT:
			count += 1
		else:
			tmp_max.append(count)
			count = 0
	tmp_max.append(count)
	print(max(tmp_max))

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

int main(){
  int h, w, m; cin >> h >> w >> m;
  int mxr = -1, mxc = -1;
  vector<vector<int>> row(h), colum(w);
  vector<int> mxh, mxw;
  rep(i, m){
    int hi, wi; cin >> hi >> wi;
    hi--;
    wi--;
    row[hi].push_back(wi);
    colum[wi].push_back(hi);
    mxr = max(mxr, (int)row[hi].size());
    mxc = max(mxc, (int)colum[wi].size());
  }

  rep(i, h){
    if(mxr == row[i].size()) mxh.push_back(i);
  }

  vector<int> cnt(h, 0);
  rep(j, w){
    if(mxc == colum[j].size()){
      mxw.push_back(j);
      rep(k, colum[j].size()) cnt[colum[j][k]]++;
    }
  }

  int ans = 0;
  rep(i, mxh.size()){
    if(cnt[mxh[i]] != mxw.size()){
      ans++;
      break;
    }
  }

  ans += mxr + (mxc - 1);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 41508
/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 2e3+23;
const int maxn = 2e5+35;
const int mod =1e9+7;
int n,k,a[maxn],per1[maxn],per0[maxn];
vector<int> ve[2];
int main(){
    scanf("%d %d",&n,&k);
    for(int i = 1;i <= n; ++i){
        scanf("%d",a+i);
        if(a[i] < 0) ve[0].push_back(a[i]);
        else ve[1].push_back(a[i]);
    }
    sort(all(ve[1]));
    int x1 = max(sz(ve[1])-k,0);
    sort(all(ve[0]));
    int x0 = 0;
    if(sz(ve[1]) < k) x0 = k-sz(ve[1]);
    if((x0&1)&&x0<sz(ve[0])&&x1+1<=sz(ve[1])){
        x0 += 1; x1 += 1;
    }
    if(x0&1){
        sort(all(ve[0]),greater<int>());
    }
    while(x0+2<=sz(ve[0])&&x1+2<=sz(ve[1])&&1ll*ve[0][x0]*ve[0][x0+1]>1ll*ve[1][x1]*ve[1][x1+1]){
        x0 += 2; x1 += 2;
    }
    int ans = 1;
    for(int i = 0;i < x0; ++i) ans = 1ll*ans*ve[0][i]%mod;
    for(int i = x1;i < sz(ve[1]); ++i) ans = 1ll*ans*ve[1][i]%mod;
    cout << (ans+mod)%mod << '\n';
    return 0;
}

Measured memory_bytes: 5036
#include <bits/stdc++.h>   
using namespace std;
#define N 3005   
#define REP(i, n) for(int i=0; i<n; i++)
int n,a,b;
int x[N];
int total;
int sumdigits(int i){
    int sum=0;
    while(i>0){
        sum+=i%10;
        i=i/10;
    }
    return sum;
}
int main(){
 scanf("%d%d%d",&n,&a,&b);
 for(int i=1;i<=n;i++){
    int y = sumdigits(i);
    if(a<=y&&y<=b){
        total+=i;
    }
 }
    
 cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

struct edge{
  int to,cost;
};

vector<vector<edge>> g;

vector<int> ans;

void dfs(int v,int p = -1,int ccost = 0){
  ans[v] = ccost;
  for(auto e: g[v]){
    if(e.to == p) continue;
    dfs(e.to,v,ccost + e.cost);
  }
}

signed main(){
  int n;
  cin >> n;
  g.resize(n);
  ans.resize(n);
  rep(i,n-1){
    int a,b,cost;
    cin >> a >> b >> cost;
    a--,b--;
    g[a].push_back((edge){b,cost});
    g[b].push_back((edge){a,cost});
  }
  int num,k;
  cin >> num >> k;
  k--;
  dfs(k);
  rep(i,num){
    int a,b;
    cin >> a >> b;
    a--;b--;
    cout << ans[a] + ans[b] << endl;
  }
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

int a,b,c;

int main(){
  cin >> a >> b >> c;
  swap(a,b);
  swap(a,c);
  cout << a << " " << b << " " << c;
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

ll lpow(ll x, ll y){
    if(y==0) return 1LL;
    if(y==1) return x;
    if(y%2==0) return lpow(x*x, y/2);
    return lpow(x*x, y/2)*x;
}

int main(){
    ll N, P;
    cin >> N >> P;
    if(N==1){
        cout << P << endl;
        return 0;
    }
    ll ans = 1;
    for(ll i=2;i<=sqrt(P)+1;i++){
        int cnt=0;
        while(P%i==0){
            cnt++;
            P/=i;
        }
        ans = ans * lpow(i, (cnt/N));
    }

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

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

int main(){
    int N;
    int count=0;
    int x=1;
    cin>>N;
    int32_t	 a[N];

    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    while(x==1){
        for(int i=0;i<N;i++){
            if(a[i]%2==1){
                x=0;
                break;
            }

            if(a[i]<2){
                x=0;
                break;
            }

            if(a[i]%2==0){
                a[i]=a[i]/2;
            }

            if(i==N-1){
                count++;
            }
        }
        if(x==0){
            break;
        }
    }
    cout <<count<< endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    ll a[n];
    map<ll, ll> mp;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    sort(a, a + n);
    reverse(a, a + n);
    ll sum = 0;
    for(int i = 0; i < n; i++){
        if(mp[a[i]] == 0) continue;
        ll po = 1;
        while(po <= a[i]) po *= 2;
        mp[a[i]]--;
        ll r = po - a[i];
        if(mp[r] != 0){
            sum++;
            mp[r]--;
        }
    }
    cout << sum << endl;
    return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e18;

ll A[100005];

int main()
{
    int N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }

    ll min = INF;
    {
        //! 奇数番目をマイナス
        ll sum = 0;
        ll m = 0;
        REP(i, N)
        {
            sum += A[i];
            if (i % 2 == 0)
            {
                if (sum >= 0)
                {
                    m += sum + 1;
                    sum = -1;
                }
            }
            else
            {
                if (sum <= 0)
                {
                    m += abs(sum) + 1;
                    sum = 1;
                }
            }
        }
        min = std::min(m, min);
    }
    {
        //! 奇数番目をpurasu
        ll sum = 0;
        ll m = 0;
        REP(i, N)
        {
            sum += A[i];
            if (i % 2 == 0)
            {
                if (sum <= 0)
                {
                    m += abs(sum) + 1;
                    sum = 1;
                }
            }
            else
            {
                if (sum >= 0)
                {
                    m += abs(sum) + 1;
                    sum = -1;
                }
            }
        }
        min = std::min(m, min);
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 1024
while true
    n = gets.to_i
    break if n == 0
    arr = [[gets.to_i, 1]]
    (n - 1).times{|i|
        x = gets.to_i
        if i.even? && arr[-1][0] != x
            a, b = arr.pop
            if arr.empty?
                arr << [x, b + 1]
            else
                arr[-1][1] += b + 1
            end
        else
            if arr[-1][0] == x
                arr[-1][1] += 1
            else
                arr << [x, 1]
            end
        end
    }
    count = 0
    (arr[0][0] == 0 ? 0 : 1).step(arr.length - 1, 2){|i| count += arr[i][1]}
    puts count
end



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

int main()
{
    int H, W; cin>>H>>W;
    vector<string> s(H);
    for(auto& v: s) cin>>v;

    int res=-1;
    queue<tuple<int, int, int>> q;
    q.emplace(0, 0, 1);
    while (q.size()) {
        int r, c, k;
        tie(r, c, k)=q.front();
        q.pop();
        if (r==H-1 && c==W-1) {
            res=-k;
            break;
        }
        array<int, 4> dr={-1, 0, 1, 0};
        array<int, 4> dc={0, -1, 0, 1};
        for(int i=0; i<4; ++i) {
            int nr=r+dr[i], nc=c+dc[i];
            if (nr<0 or nr>=H or nc<0 or nc>=W) continue;
            if (s[nr][nc]!='.') continue;
            q.emplace(nr, nc, k+1);
            s[nr][nc]=' ';
        }
    }

    if (s[H-1][W-1]!='.')
        for(auto& v: s) for(auto& e: v) res+=e!='#';
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;


int main() {
	speed;
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i < n + 1; i += 2) {
		int count = 0;
		for (int j = 1; j < i + 1; j++) {
			if (i%j == 0)count++;
		}
		if (count == 8)ans++;
	}
	cout << ans;
	ed;
	return 0; 
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		long x = scan.nextLong();
		long a = scan.nextLong();
		long b = scan.nextLong();

		//safeライン：b-a<x
		//おいしいライン:b-a<=0
		if(b-a<=x && b-a>0) {
			System.out.println("safe");
		}else if(b-a<=0) {
			System.out.println("delicious");
		}else {
			System.out.println("dangerous");
		}
	}

}


Measured memory_bytes: 20692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
unsigned gcd( unsigned a, unsigned b){
  
  if( !b ) return 0;
  if( a%b == 0 ) return b;
  else gcd( b, a%b );
  
}


int main(){
  
  int K;
  cin >> K;
  ll sum = 0;
  for( int i=1; i<= K; i++){
      for( int j=i; j<= K; j++){
        for( int l=j; l<= K; l++){
            
          if( i==j && j==l )sum += gcd(gcd( i,j ),l);
          else if( i==j || j==l )sum += 3*gcd(gcd( i,j ),l);
          else sum += 6*gcd(gcd( i,j ),l);

          }
      }
  }
  
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 3764
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <utility>
#include <vector>
const int MAXN = 2e5 + 10;
using std::make_pair;

char s[MAXN];
int n;
namespace solver1 {
  std::set <int> letters[26];
  //int letter[26];
  std::set <int> seq;
  namespace bit {
    int a[MAXN];
    void add(int x, int y) {
      for (; x <= n; x += x & (-x)) a[x] += y;
    }
    int query(int x) {
      int ans = 0;
      for (; x > 0; x -= x & (-x)) ans += a[x];
      return ans;
    }
  }
  void main() {
    for (int i = 1; i <= n; i++) {
      letters[s[i] - 'a'].insert(i);
      seq.insert(i);
      bit::add(i, 1);
    }            
    int cnt_odd = 0;
    for (int i = 0; i < 26; i++) {
      if (letters[i].size() & 1) cnt_odd++;
    }
    if (cnt_odd > 1) {puts("-1"); return;}
    long long ans = 0;
    for (int i = 1; i <= n / 2; i++) {
      std::set<int>::iterator front = seq.begin(), rear = seq.end(); --rear;
      int f = *front, e = *rear;
      char fc = s[f], ec = s[e];
      if (fc == ec) {
        bit::add(f, -1); bit::add(e, -1);
        seq.erase(f); seq.erase(e);
        letters[fc - 'a'].erase(f); letters[ec - 'a'].erase(e);
        continue;
      }
      std::set<int>::iterator lf = letters[fc - 'a'].end(),
        le = letters[ec - 'a'].begin();
      --lf;
      int nxt_fc = *lf, 
        nxt_ec = *le;
      int dis_f = bit::query(n) - bit::query(nxt_fc),
        dis_e = bit::query(nxt_ec) - 1;
      if ((dis_f < dis_e && letters[fc - 'a'].size() != 1) || letters[ec - 'a'].size() == 1) {
        ans += dis_f;
        bit::add(nxt_fc, -1); bit::add(f, -1);
        seq.erase(f); seq.erase(nxt_fc);
        letters[fc - 'a'].erase(f); letters[fc - 'a'].erase(nxt_fc);
      } else {
        ans += dis_e;
        bit::add(nxt_ec, -1); bit::add(e, -1);
        seq.erase(nxt_ec); seq.erase(e); 
        letters[ec - 'a'].erase(e); letters[ec - 'a'].erase(nxt_ec);
        
      }
    }
    printf("%lld\n", ans);

  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  solver1::main();
}


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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll h, w; cin>>h>>w;
  vector<string> s(h);
  rep(i, h) cin>>s[i];

  int dx[] = {1, -1, 0, 0};
  int dy[] = {0, 0, 1, -1};
  rep(i, h) rep(j, w) {
    if (s[i][j] == '.') continue;
    bool isok = false;
    rep(k, 4) {
      int ni = i - dx[k];
      int nj = j - dy[k];
      if (ni<0||h<=ni||nj<0||w<=nj) continue;
      if (s[ni][nj] == '#') isok = true;
    }
    if (!isok) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


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

int ticket[4] = {6000, 4000, 3000, 2000};

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

	for(int i = 0; i < 4; ++i){
		int t, n;
		cin >> t >> n;
		--t;
		cout << ticket[t] * n << endl;
	}

	return 0;
}

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

int main() {
  string S;
  cin >> S;
  vector<int> xs(256);
  for (int i = 0; i < S.size(); ++i) xs[S[i]] = 1;
  for (int i = 1; i < xs.size(); ++i) xs[i] += xs[i - 1];
  cout << (xs[xs.size() - 1] == S.size() ? "yes" : "no") << endl;
}


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


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> vec;
    vec.push_back(a);
    vec.push_back(b);
    vec.push_back(c);
    sort(vec.begin(), vec.end());
    cout << abs(vec.at(0) - vec.at(1)) + abs(vec.at(1) - vec.at(2)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define R register
#define int long long
using namespace std;
const int N =2e6+200;
template <class Ruby_Rose> inline void read(Ruby_Rose &x)
{
 	x=0;
	char ch=getchar(), w=0;
	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
	x=w?-x:x;
}
int n, k, val[N], tot;
signed main()
{
	read(k), read(n);
	for(R int i=1; i<=n; i++)
	{
		read(val[i]);
		tot+=val[i];
	}
	int ans=1e18;
	for(R int i=1; i<n; i++)
	{
		ans=min(ans, k-(val[i+1]-val[i]));
	}
	ans=min(ans, k-(val[1]+k-val[n]));
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n;
	cin >> n;
	vector<string> s(n);
	rep(i, n)cin>>s[i];
	vector<int> ans(4,0);
	rep(i,n){
		if(s[i] == "AC") ans[0]++;
		else if(s[i] == "WA") ans[1]++;
		else if(s[i] == "TLE") ans[2] ++;
		else ans[3]++;
	}
	cout << "AC x " << ans[0] << endl;
	cout << "WA x " << ans[1] << endl;
	cout << "TLE x " << ans[2] << endl;
	cout << "RE x " << ans[3] << endl;
}


Measured memory_bytes: 6424
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=a; i<b; i++)
#define repi(i, a, b) for(int i=a; i>b; i--)
#define db(x) (cerr << #x << ": " << x << '\n')
#define iceil(n, x) ((n + x - 1) / x)
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define fi first
#define se second
#define umap unordered_map
#define umapi umap<int, int>
#define mapi map<int, int>
#define uset unordered_set
#define useti uset<int>
#define seti set<int>
#define pqueue priority_queue
#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld", &a)
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007
#define MOD 1000000007
#define N 200000
using namespace std;

template<typename T>
using maxpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using minpq = priority_queue<T>;
#define inv Fermat
#define div Div

inline int add(int a, int b){ ll c = a + b; if(c >= mod) c -= mod; return c;}

inline int sub(int a, int b){ int c = a - b; if(c < 0) c += mod; return c;}

inline int mul(int a, int b){ return (a * 1ll * b) % mod;}

int power(int a,int b,int m = mod)
{
	int res = 1;
	while(b > 0){
		if(b & 1) res = mul(res, a);
		a= mul(a, a);
		b >>= 1;
	}
	return res;
}

//Computes a^(-1) mod p
// p must be a prime no.
// Fermat's little theorem: a^(p-1) = 1(mod p)
//So, we have a^(p-2) = a^(-1) (mod p)
inline int Fermat(int a,int p = mod){ return power(a, p-2, p);}

inline int div(int a, int b) {
	return mul(a, Fermat(b));
}

int fac[N + 5];
void pre() {
	fac[0] = 1;
	rep(i, 0, N) {
		fac[i + 1] = mul(i + 1, fac[i]);
	}
}

int nCr(int n, int r, int p = mod) {
	if(n < r)
		return 0;
	int res = 1;
	res = mul(res, fac[n]);
	res = div(res, fac[r]);
	res = div(res, fac[n - r]);
	return res;

}

int a, b, w, h;

main()
{	
	#ifndef ONLINE_JUDGE
		//freopen("C:\\Users\\HP\\Desktop\\input.txt", "r", stdin);
//		freopen("C:\\Users\\HP\\Desktop\\output.txt", "w", stdout);
	#endif
	clock_t clk = clock();
	cerr << "I will return...\n";
	
	pre();
	cin >> h >> w >> a >> b;
	
	int ans, x, y;
	
	ans = 0;
	
	rep(i, b, w) {
		x = nCr(h - a - 1 + i, i);
		y = nCr(w + a - 2 - i, a - 1);
//		db(x), db(y);
//		db(mul(x, y));
		ans = add(ans, mul(x, y));
//		x = mul(x, h - a + i), x = div(x, i + 1);
//		y = mul(w - i - 1, y), y = div(y, w - 2 - i);
	}
	
	cout << ans << '\n';
	
	cerr << "...don't you ever hang your head.\n";
	cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << '\n';
}








Measured memory_bytes: 1024
a,b,c = map(int, input().split())
if a <= b <= c :
    print(str(a) + " " + str(b) + " " + str(c))
elif a <= c <= b :
    print(str(a) + " " + str(c) + " " + str(b))
elif b <= a <= c :
    print(str(b) + " " + str(a) + " " + str(c))
elif b <= c <= a :
    print(str(b) + " " + str(c) + " " + str(a))
elif c <= a <= b :
    print(str(c) + " " + str(a) + " " + str(b))
else :
    print(str(c) + " " + str(b) + " " + str(a))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;

int main(){
  int n;cin >> n;
  int M=0;
  int ans=0;
  rep(i,n){
    int t;cin >> t;
    if(t>=M){
      ans++;
      M=t;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, j) for (int i = 0; i < (int)(j); ++i)
#define rep1(i, j) for (int i = 1; i < (int)(j); ++i)
#define all(v) (v).begin(), (v).end()
#define int long long

using namespace std;
using ll = long long;
using ld = long double;

signed main()
{
  int N; cin >> N;
  vector<int> A(N);

  int total = 0;
  rep(i, N) cin >> A[i], total += A[i];

  int sum = 0, ans = LONG_LONG_MAX;
  rep(i, N-1) {
    sum += A[i];
    total -= A[i];
    ans = min(ans, abs(total-sum));
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
import std.stdio;
import std.array;
import std.string;
import std.algorithm;
import std.conv;

void bubbleSort(ref string[] arr) {
  for (auto i = 0; i < arr.length; i++)
    for (auto j = arr.length-1; j >= i+1; j--)
      if (arr[j][1] < arr[j-1][1]) swap(arr[j], arr[j-1]);
}

void selectionSort(ref string[] arr) {
  for (auto i = 0; i < arr.length; i++) {
    int min = i;
    for (auto j = i; j < arr.length; j++)
      if (arr[j][1] < arr[min][1]) min = j;
    swap(arr[i], arr[min]);
  }
}

void main(string[] args)
{
  int n = to!int(strip(readln()));
  string[] arr = split(readln());
  string[] b, s;
  b ~= arr;
  s ~= arr;
  sort!((string a, string b)=>a[1] < b[1], SwapStrategy.stable)(arr);
  bubbleSort(b);
  selectionSort(s);
  writeln(join(b.map!(text), " "));
  writeln(arr == b? "Stable": "Not stable");
  writeln(join(s.map!(text), " "));
  writeln(arr == s? "Stable": "Not stable");
}

Measured memory_bytes: 2524
#include<bits/stdc++.h>
using namespace std;
#define N 200000
#define maxn (N + 10)
#define maxm (maxn * 2)
#define pb push_back
#define lc (id * 2)
#define rc (id * 2 + 1)
#define Mod(x) (((x) % mod + mod) % mod)
typedef long long ll;
const ll INF = (1e8);
const ll mod = (998244353);
ll a[maxn];
int main(){
    int n;scanf("%d",&n);
    for(int i = 1;i <= n;i++)scanf("%lld",&a[i]);
    sort(a + 1,a + 1 + n);
    ll ans = a[n],t = n - 2;
    for(int i = n - 1;i >= 1;i--){
        if(!t)break;
        if(t >= 2){
            ans += a[i] * 2;t -= 2;
        }
        else if(t >= 1){
            ans += a[i];t -= 1;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

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

using namespace std;

using ll = long long;

#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(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)

typedef pair<int, int> P;

const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

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

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

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int r;
	cin >> r;
	
	if (r < 1200) cout << "ABC" << endl;
	else if (r < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> a[100005];
void dfs(int st,int la,int step,int dist[])
{
	dist[st]=step;
	vector<int>::iterator it;
	for(it=a[st].begin();it!=a[st].end();it++)
	{
		if(*it!=la)
		dfs(*it,st,step+1,dist);
	}
}
int main()
{
	int n,i,dist1[100005],dist2[100005],u,v,sum;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=1;i<=n;i++)
		a[i].clear();
		for(i=1;i<=n-1;i++)
		{
			scanf("%d%d",&u,&v);
			a[u].push_back(v);
			a[v].push_back(u);
			//cout<<i<<endl;
		}
		dfs(1,-1,0,dist1);
		dfs(n,-1,0,dist2);
		sum=0;
		for(i=1;i<=n;i++)
		{
			if(dist1[i]<=dist2[i])
			sum++;
			else
			sum--;
		}
		if(sum>0)
		printf("Fennec\n");
		else
		printf("Snuke\n");
	}
	return 0;
}

Measured memory_bytes: 12800
W, H, N = gets.chomp.split.map(&:to_i)
Ws = [0, W]
Hs = [0, H]  # どっちも右上

N.times do |i|
  xi, yi, ai = gets.chomp.split.map(&:to_i)
  # 題意から
  if ai == 1
    Ws[0] = [Ws[0], xi].max
  elsif ai == 2
    Ws[1] = [Ws[1], xi].min
  elsif ai == 3
    Hs[0] = [Hs[0], yi].max
  else
    Hs[1] = [Hs[1], yi].min
  end
end

puts [Ws[1] - Ws[0], 0].max * [Hs[1] - Hs[0], 0].max

Measured memory_bytes: 1788
#include <stdio.h>
int main(){
    int a[100], max=0, b=0, c=0;
    scanf("%d",&max);
    for(b = 0; b<max; b++){
        scanf("%d",&a[b]);
     
    }
    for(c = max-1; c>0;c--){
        printf("%d ",a[c]);
    }
    printf("%d",a[0]);
    printf("\n");
     
 
 
    return 0;
}

Measured memory_bytes: 600