akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int T = sc.nextInt();
        if (T==5 || T==3 || T==7) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22356
#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) 1e15;

ll A[1005];
ll B[1005];

int main() {
    ll N, M;
    cin >> N >> M;
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, M) {
        cin >> B[i];
    }
    ll ans = 1;
    sort(A, A + N, [](ll a, ll b) { return a > b; });
    sort(B, B + M, [](ll a, ll b) { return a > b; });
    REP(i, N - 1) {
        if (A[i] == A[i + 1]) {
            ans = 0;
        }
    }
    REP(i, M - 1) {
        if (B[i] == B[i + 1]) {
            ans = 0;
        }
    }

    ll a = 0, b = 0;
    for (ll n = N * M; n > 0; --n) {
        if (a < N - 1 && A[a + 1] == n)
            a++;
        if (b < M - 1 && B[b + 1] == n)
            b++;

        if (A[a] < n || B[b] < n) {
            ans = 0;
            break;
        }

        ll x = A[a] == n ? 1LL : a + 1;
        ll y = B[b] == n ? 1LL : b + 1;
        if (A[a] == n || B[b] == n) {
            ans = (ans * x * y) % MOD;
        }
        else {
            ll s = x * y - (N * M - n);
            if (s <= 0) {
                ans = 0;
                break;
            }
            ans = (ans * s) % MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int x = Integer.parseInt(in.next());
            int y = Integer.parseInt(in.next());
            int z = Integer.parseInt(in.next());
            int ans = 0;

            int tmp = x / (y + z);
            if (x % (y + z) == 0) {
                out.println(tmp - 1);
            } else {
                if (x - tmp * (y + z) >= z) {
                    out.println(x / (y + z));
                } else {
                    out.println(tmp - 1);
                }
            }

        }

    }
}



Measured memory_bytes: 21716
/*
     _              ,_,                 
    / \   _ __, ___,| |__   __ _,_ __  
   / ^ \ | '_ \/ _ \| '_ \ / _` | /_/  
  /-/-\-\|-| |--| |-|-|_)-|-(_|-|-|    
 /_/   \_\_| |__| |_|_.__/ \__,_|_|    
 
*/
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(a)       (a).begin(),(a).end()
#define rep(i,a,n)   for(int i=a ; i<n ; i++)
 
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<ll,ll> mii;
typedef map<char,ll> mci;
 
ll gcd(ll a, ll b){
	if(b==0)return a;
	else return gcd(b, a%b);
}

signed main(){
    ll test=1;
    // cin>>test;
    while(test--){
        ll n; cin>>n;
        vi h(n+1, 0);
        rep(i, 1, n+1)cin>>h[i];
        vi dp(n+1, 0);
        for(int i=2; i<=n; i++){
        	int x=dp[i-1]+abs(h[i]-h[i-1]);
        	int y=dp[i-2];
        	if(i-2>0)y+=+abs(h[i]-h[i-2]);
        	else {
        		dp[i]=x;
        		continue;
        	}
        	dp[i]=min(x, y);
        }
        cout<<dp[n]<<endl;
    }
        
}


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

int main() {
	int N;
	cin >> N;
	int A[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);
	cout << A[N/2] - A[N/2-1] << endl;
}


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


int main(){
    vector<vector<int>> card(3,vector<int>(3));//card
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> card[i][j];
        }
    }
    int n;
    cin >> n; //回数
    vector<int> a(n);
    rep(i,n) cin >> a[i]; //出た番号
    
    int cnt = 0;
    while(cnt<n){
        rep(i,3){
            rep(j,3){
                if(a[cnt] == card[i][j]){
                    card[i][j] = 0;
                }
            }
        }
        cnt++;
}

if(card[0][0] == 0 &&card[1][1]==0 &&card[2][2]==0){
    cout << "Yes" << endl;
    return 0;
}else if(card[0][2]==0&&card[1][1]==0&&card[2][0]==0){
        cout << "Yes" << endl;
    return 0;
}

rep(i,3){
    if(card[i][0]==0&&card[i][1]==0 &&card[i][2]==0){
        cout << "Yes" << endl;
        return 0;
    }else if(card[0][i] ==0&&card[1][i] ==0&& card[2][i]==0){
        cout << "Yes" << endl;
        return 0;
    }
}
cout << "No" << endl;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
vector<string> ans[200005];
int main(){
  ll n;
  cin>>n;
  vector<string> vec;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    vec.push_back(s);
  }
  sort(vec.begin(),vec.end());
  ll cnt=1;
  for(int i=0;i<n-1;i++){
    if(vec[i]==vec[i+1]) cnt++;
    else {
      ans[cnt].push_back(vec[i]);
      cnt=1;
    }
  }
  ans[cnt].push_back(vec[n-1]);
  for(int i=200004;i>0;i--){
    if(ans[i].size()>0){
      sort(ans[i].begin(),ans[i].end());
      for(int j=0;j<ans[i].size();j++) cout<<ans[i][j]<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 20592
# -*- coding: utf-8 -*-

def do_binary_search(target_value, target_list, target_list_length=None):
    left = 0
    right = target_list_length

    while right - left > 0:
        mid = (right + left) / 2
        key = target_list[mid]
        if key == target_value:
            return True
        elif target_value < key:
            right = mid
        else:
            left = mid + 1
    return False



def main():
    s_length = int(raw_input())
    s = [int(x) for x in raw_input().strip().split(' ')]
    t_length = raw_input()
    t = [int(x) for x in raw_input().strip().split(' ')]

    counter = 0
    for value in t:
        counter += int(do_binary_search(value, s, s_length))

    print counter 

if __name__ == '__main__':
    main()

Measured memory_bytes: 15184
// :(

#ifndef LOCAL
#define NDEBUG 1
#endif
#include<bits/stdc++.h>

#define MODULAR_LESS_EFFICIENT_BUT_EASIER_TO_CODE 1
int const MOD=1000000007;
struct modular {
	int val;
	explicit constexpr operator int() const { return val; }
	constexpr modular():val(){}
#if MODULAR_LESS_EFFICIENT_BUT_EASIER_TO_CODE
	constexpr modular(auto v):val(int(v%MOD)){ if(val<0)val+=MOD; }
#else
	constexpr modular(int v):val(v){
		assert(0<=v and v<MOD);
	}
#endif

#define COMPAREOP(OP) bool constexpr operator OP(modular b) const { return val OP b.val; }
	COMPAREOP(==) COMPAREOP(!=) COMPAREOP(<) COMPAREOP(>) COMPAREOP(<=) COMPAREOP(>=)
#undef COMPAREOP

	friend modular constexpr operator-(modular x) { x.val=x.val?MOD-x.val:0; return x; }
	modular constexpr& operator+=(modular m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	modular constexpr& operator-=(modular m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	modular constexpr& operator*=(modular m) {
		if(__builtin_constant_p(m.val)){
			switch(m.val){
				case 1: return *this;
				case 2: return *this+=*this;
				case 3: return *this+=*this+*this;
				case 0: return *this=0;
				case -1: return *this=-*this;
			}
		}else if(__builtin_constant_p(val)){
			*this=m**this;
		}
		val = int((int64_t)val*m.val%MOD);
		return *this;
	}
	modular constexpr pow(int p) const {
		modular a=*this;
		modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans;
	}
	modular constexpr inv() const {
		int a=val,b=MOD, ax=1,bx=0;
		while(b){
			int q=a/b, t=a%b;
			a=b; b=t;
			t=ax-bx*q; ax=bx; bx=t;
		}
		assert(a==1);
		if(ax<0)ax+=MOD;
		return ax;
	}
	modular constexpr& operator/=(modular m) { return (*this) *= m.inv(); }

#define ARITHBINARYOP(OP) friend modular constexpr operator OP(modular a, modular b) { return a OP##= b; }
	ARITHBINARYOP(+) ARITHBINARYOP(-) ARITHBINARYOP(*) ARITHBINARYOP(/)
#undef ARITHBINARYOP
};

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int n, k; std::cin>>n>>k;
	std::vector<modular> temp(n==k ? 2 : n-k+1);
	temp[1]=1;
	while((int)temp.size()<n){
		temp.push_back(0);
		std::partial_sum(begin(temp), end(temp), begin(temp));
	}
	std::cout<<int(
			std::accumulate(begin(temp),end(temp), modular(0))*modular(2).pow(std::max(0, n-k-1))
			)<<'\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string s;
vector<int> l,r;
long long ans = 1,mod = 1000000007;
int main(){
	int i,n;
	cin >> n >> s;
	for(i=0;i<2*n;i++){
		int x = l.size() - r.size();
		if(x<0){
			cout << 0 << endl;
			return 0;
		}
		if(x&1){
			if(s[i]=='W') l.push_back(i);
			else r.push_back(i);
		}else{
			if(s[i]=='W') r.push_back(i);
			else l.push_back(i);
		}
	}
	if(l.size()!=n || r.size()!=n){
		cout << 0 << endl;
		return 0;
	}
	int z = n;
	long long cnt = 0;
	for(i=n - 1;i>=0;i--){
		while(z>0 && r[z - 1]>l[i]){
			cnt++; z--;
		}
		(ans *= cnt) %= mod;
		cnt--;
	}
	for(i=1;i<=n;i++){
		(ans *= i) %= mod;
	}
	cout << ans << endl;
}

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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)

//MIN-MAX
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }



int main()
{
    ll n,m;
     cin>>n>>m;
     vector<ll>vect(n);
     ll sum=0;

     f(i,0,n)
     {
          cin>>vect[i];
          sum+=vect[i];
     }
     ll pop=0;
     ll  temp=4*m;
     ll min_votes= (sum+temp-1)/temp;

     f(i,0,n)
     {
         if(vect[i]>=min_votes)
            pop++;
     }
     if(pop>=m)
        cout<<"Yes\n";
     else
        cout<<"No\n";



	return 0;
}













Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] number = new int[n];
		for(int i = 0; i < n; i++){
			int a = scan.nextInt();
			number[i] = a;
		}

		for(int i = n - 1; i >= 0; i--){
			System.out.print(number[i]);
			if(i != 0){
				System.out.print(" ");
			} else{
				System.out.println("");
			}
		}
	}
}

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

int main() {
	int d;
	cin>>d;
	
	if(d==25)
	{
		cout<<"Christmas"<<endl;
	}
	else if(d==24)
	{
		cout<<"Christmas Eve"<<endl;
	}
	else if(d==23)
	{
		cout<<"Christmas Eve Eve"<<endl;
	}
	else if(d==22)
	{
		cout<<"Christmas Eve Eve Eve"<<endl;
	}
	
	
	
	return 0;
}

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int st, et, r;
  int d[60] = {};
  for(st = r = 0, et = a;; d[st] = et, st = et + b, et = st + a){
    if(st >= 60){
      st -= 60;
      et -= 60;
      r++;
    }
    if(c >= st && c <= et){
      cout << r*60+c << endl;
      break;
    }
    if(d[st] == et){
      cout << "-1" << endl;
      break;
    }
  }
}

Measured memory_bytes: 1164
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long r = ReadLong();
            var ret = r / 11;
            if (r <=6)
            {
                Console.WriteLine(1);
                return;
            }else if (r <= 11)
            {
                Console.WriteLine(2);
                return;
            }

            if (r % 11 == 0)
            {
                Console.WriteLine(ret * 2);
                return;
            }

            if (r % 11 <= 6)
            {
                Console.WriteLine(ret * 2 + 1);
            }
            else
            {
                Console.WriteLine(ret * 2 + 2);
            }
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13140
import scala.io.StdIn._
import scala.collection.mutable

object Main extends App {
  
  var cnt = 0
  def merge(A: Array[Int], left: Int, mid: Int, right: Int) {
    val n1 = mid - left
    val n2 = right - mid
    val L = A.slice(left, left + n1) :+ Int.MaxValue
    val R = A.slice(mid, mid + n2) :+ Int.MaxValue
    var i = 0
    var j = 0
    for (k <- (left to right - 1)) {
      if (L(i) <= R(j)) {
        A(k) = L(i)
        i += 1
      } else {
        A(k) = R(j)
        j += 1
      }
      cnt += 1
    }
  }
  def mergeSort(A: Array[Int], left: Int, right: Int) {
    if (left + 1 < right) {
      val mid = (left + right) / 2
      mergeSort(A, left, mid)
      mergeSort(A, mid, right)
      merge(A, left, mid, right)
    }
  }

  val N = readLine.toInt
  val A = readLine.split(" ").map(_.toInt)
  mergeSort(A, 0, A.size)
  println(A.mkString(" "))
  println(cnt)
}


Measured memory_bytes: 456124
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

const long long INF = 1e18 + 1;

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

	int N;
	long long K;
	cin >> N >> K;

	vector<long long> nlist(N, 0);

	for (int i = 0; i < N; i++)
	{
		cin >> nlist[i];
	}

	sort(nlist.begin(), nlist.end());

	long long lo = -INF;
	long long hi = INF;
	while (hi - lo >= 2)
	{
		long long val = (lo + hi) / 2;
		bool check = [&]()->bool
		{
			long long count = 0;
			for (int i = 0; i < N; i++)
			{
				if (nlist[i] < 0)
				{
					int lo = -1;
					int hi = N;
					while (hi - lo >= 2)
					{
						int mid = (lo + hi) / 2;
						if (nlist[i] * nlist[mid] < val)
							hi = mid;
						else
							lo = mid;
					}
					count += N - hi;
				}
				else
				{
					int lo = -1;
					int hi = N;
					while (hi - lo >= 2)
					{
						int mid = (lo + hi) / 2;
						if (nlist[i] * nlist[mid] < val)
							lo = mid;
						else
							hi = mid;
					}
					count += hi;
				}

				if (nlist[i] * nlist[i] < val) count--;
			}
			
			count /= 2;

			if (count < K) return true;
			return false;
		}();

		if (check)
			lo = val;
		else
			hi = val;
	}

	cout << lo;
	
	return 0;
}

Measured memory_bytes: 1792
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    rep(i, m) cin >> s.at(i) >> c.at(i);

    int ans = -1;
    rep(i, 1000) {
        string l = to_string(i);
        if (l.size() != n) continue;
        bool isOk = true;
        rep(j, m) {
            if(l.at(s.at(j) - 1) - '0' != c.at(j)) {
                isOk = false ;
            }
        }
        if (!isOk) continue;
        ans = i;
        break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3696
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはメントされる
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--) //ループ変数は1ずつデクリ
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--) //ループ変数は1ずつデクリ
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) ll(x.size())      // sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000

int main() {

    ll N;
    cin >> N;
    vector<vector<ll>> p(N + 1, vector<ll>(3, 0));
    ll t, x, y;
    REP(i, N) {
        cin >> t >> x >> y;
        p[i + 1][0] = t;
        p[i + 1][1] = x;
        p[i + 1][2] = y;
    }

    sort(ALL(p), [](const vector<ll> &alpha, const vector<ll> &beta) {
        return alpha[0] < beta[0];
    });
    bool can = true;
    FOR(i, 1, N + 1) {
        ll diff = p[i][0] - p[i - 1][0];
        ll diff_met=abs(p[i][1] - p[i - 1][1]) + abs(p[i][2] - p[i - 1][2]);
        if (diff % 2 == 0) {
            if (diff_met % 2 == 0 && diff >= diff_met) {
                continue;
            } else {
                can = false;
                break;
            }
        } else {
            if (diff_met % 2 == 1 && diff >= diff_met) {
                continue;
            } else {
                can = false;
                break;
            }
        }
    }
    can ? cout << "Yes" << endl : cout << "No" << endl;
}


Measured memory_bytes: 11940
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    INT(n,x,y);
    vector<int> distance(n,0);
    x--;
    y--;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            distance[min(j-i,abs(x-i)+abs(y-j)+1)]++;
        }
    }
    for(int i=1;i<n;i++)out(distance[i]);
}


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

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c==17&&((a==5&&b==5)||(a==5&&c==5)||(b==5&&c==5)))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 256
import itertools

def f(x):
    if x[1] == 0:
        return x[1]
    else:
        return 10 -x[1] 

a = []
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))


b = []

for i in a:
    c = i - (int(i / 10) * 10) 
    b.append((i, c))

b.sort(key=f)

x = 0

for i in b:
    x += i[0]
    if i[1] != 0:
        x += 10 - i[1]
        l = 10 - i[1]
    else:
        l = 0
x -= l

print(x)
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0,(i##_len)=(n);(i)<(i##_len);(i)++)
#define rep2(i,a,b) for(ll (i)=(a),(i##_len)=(b);(i)<=(i##_len);(i++))
#define rrep(i,n) ll(i)=(n);ll now=-1;while((i)--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)<<"\n"
#define vll vector<ll>
#define pb push_back

using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
template<class T> T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> T sum(vector<T>v){return accumulate(all(v),0LL);}

// Template ends here

int main() {
    vector<int> T(5); int mod = 10, base = 0;
    rep(i, 5) {
        cin >> T.at(i);
        base += ceil(T.at(i) / 10.0) * 10;
    }
    rep(i, 5) if (T.at(i) % 10) chmin(mod, T.at(i) % 10);
    cout << base - 10 + mod << "\n";
    return 0;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll>   pairl;
typedef vector<ll>     vl;
typedef vector<ll>     vll;
typedef vector<vector<ll> > vvl;
const   int            infi = numeric_limits<int>::max();
const   ll             infl = numeric_limits<ll>::max();
const   double         eps = 0;
const   int            ms  = 0;


int N;
vi L;

int upperbound(int i, int j) {
    int low = j;/////
    int high = N;//////array.size /// not N-1
    
    while (abs(high - low) > 1){
        int mid = (high + low)/ 2;
        if(L[mid] < L[i] + L[j]){///////////
            low = mid;
        }
        else{
            high = mid;
        }
    }
    
    return low;
    
}

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    cin >> N;
    L = vi(N);
    rep(i, N)cin >> L[i];
    sort(all(L));
    //rep(i, N)debug(L[i])
    int a = 0;
    for(int i = 0; i < N-2; i++){
       
        for(int j = i+1; j < N-1; j++){
            int k = upperbound(i, j);
            //debug(k-j)
            a+=k-j;
        }
    }

    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

astr = input()
bstr = input()
n = getN()
queries = []
for i in range(n):
    queries.append(getlist())
s1 = 1 if astr[0] == "A" else 2
t1 = 1 if bstr[0] == "A" else 2
s_acc = [0]
t_acc = [0]
tmp = 0
for s in astr:
    if s == "A":
        s_acc.append(s_acc[-1] + 1)
    else:
        s_acc.append(s_acc[-1] + 2)

for s in bstr:
    if s == "A":
        t_acc.append(t_acc[-1] + 1)
    else:
        t_acc.append(t_acc[-1] + 2)


for q in queries:
    x,y,z,w = q

    if (s_acc[y] - s_acc[x-1]) % 3 == (t_acc[w] - t_acc[z-1])%3:
        print("YES")
    else:
        print("NO")




Measured memory_bytes: 36440
a,b,c,d,e,f=map(int,input().split())
dpw=[False]*31
dps=[False]*1501
dpw[0]=True
dps[0]=True
for i in range(1,31):
    if i>=a:
        dpw[i]=dpw[i] or dpw[i-a]
    if i>=b:
        dpw[i]=dpw[i] or dpw[i-b]
for i in range(1,1501):
    if i>=c:
        dps[i]=dps[i] or dps[i-c]
    if i>=d:
        dps[i]=dps[i] or dps[i-d]
Va=100*a
Vs=0
for i in range(1,31):
    for j in range(1501):
        if dpw[i] and dps[j]:
            Sum=100*i+j
            if Sum<=f and j<=i*e:
                if j/Sum>Vs/Va:
                    Va=Sum
                    Vs=j
print(Va,Vs)



Measured memory_bytes: 39792
def main():
    N, Q = map(int, input().split())
    S = input()

    t = [0] * (N + 1)
    for i in range(N):
        t[i + 1] = t[i] + (1 if S[i:i + 2] == "AC" else 0)
    for i in range(Q):
        l, r = map(int, input().split())
        print(t[r - 1] - t[l - 1])


if __name__ == '__main__':
    main()


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

int main(){
  int N;
  cin>>N;
  int k=N;
  int a=0;
  while(k>0){
    a+=k%10;
    k/=10;
  }
  if(N%a)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long A,B,C,K,k;
int main(){
    cin>>A>>B>>C>>K;
    while(A>=B){B<<=1LL;k++;}
     while(B>=C){C<<=1LL;k++;}
    cout<<(k<=K?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 3568
from collections import deque

S = input()
Q = int(input())

# T = ""
# for i in range(Q) :
#     Query = list(input().split())
#     if Query[0] == "1" :
#         S, T = T, S
#     elif Query[0] == "2" :
#         if Query[1] == "1" :
#             T = T + Query[2]
#         elif Query[1] == "2" :
#             S = S + Query[2]

# T = T[::-1]
# T = T + S
# print(T)

d = deque(S)

rev = False
for i in range(Q) :
    Query = list(input().split())
    if Query[0] == "1" :
        rev = not rev
    else :
        Query[1] = int(Query[1])
        if rev :
            Query[1] = 3 - Query[1]
        if Query[1] == 1 :
            d.appendleft(Query[2])
        else :
            d.append(Query[2])

if rev :
    d.reverse()
ans = ""
for s in d :
    ans += s
print(ans)

Measured memory_bytes: 7156
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int main(){
int a,b,c,d;
cin>>a;
if(a<=9)cout<<a;
else if(a<=99&&a>=9)cout<<"9";
     else if(a>99&a<1000)cout<<a-90;
          else if(a>999&&a<10000)cout<<"909";
               else if(a>=10000&&a<100000)cout<<a-9090;
                    else cout<<"90909";
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  long A[N];
  bool flag = false;
  int count = 0;
  for(int i=0;i<N;i++){
      cin >> A[i];
      if(A[i]==0){
        flag = true;
      }
      if(A[i]<0){
        count++;
      }
  }

  long ans = 0;
  for(int i=0;i<N;i++){
    ans += abs(A[i]);
  }

  if(flag || count%2==0){
    cout << ans <<endl;
  }else{
    vector<long> absolute; 
    for(int i=0;i<N;i++){
      long l = abs(A[i]);
      absolute.push_back(l);
    }
    sort(absolute.begin(), absolute.end());
    ans -= 2*absolute[0];
    cout << ans <<endl;
  }
  
  return 0;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    string s;
    cin>>n;
    std::deque<int> deq(4,0);
    for (int i=0;i<n;i++) {
        cin>>s;
        if (s=="AC") {
            deq[0]++;
        } else if (s=="WA") {
            deq[1]++;
        } else if (s=="TLE") {
            deq[2]++;
        } else {
            deq[3]++;
        }
    }
    for (int i=0;i<4;i++) {
        if (i==0) {
            cout<<"AC x "<<deq[i]<<endl;
        } else if (i==1) {
            cout<<"WA x "<<deq[i]<<endl;
        } else if (i==2) {
            cout<<"TLE x "<<deq[i]<<endl;
        } else {
            cout<<"RE x "<<deq[i]<<endl;
        }
    }
}

Measured memory_bytes: 3636
/*
   Deque
   http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_1_B&lang=jp
 */

import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.Deque;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int q = scan.nextInt();
		int i = 0;
		int d = 0;
		int limit = 400000;
		MyDeque A = new MyDeque(limit);
		while (i < q) {
			i++;

			int Cmd = scan.nextInt();
			switch (Cmd) {
			case 0:
				d = scan.nextInt();
				int x = scan.nextInt();
				push(A, d, x);
				break;
			case 1:
				int p = scan.nextInt();
				randomAccess(A, p);
				break;
			case 2:
				d = scan.nextInt();
				pop(A, d);
				break;
			default:
				break;
			}
		}
	}

	private static void push(MyDeque A, int d, int x) {
		if (d == 0) {
			A.addFirst(x);
		} else if (d == 1) {
			A.addLast(x);
		}
	}
	private static void randomAccess(MyDeque A, int p) {
		System.out.println(A.get(p));
	}
	private static void pop(MyDeque A, int d) {
		if (d == 0) {
			A.removeFirst();
		} else if (d == 1) {
			A.removeLast();
		}
	}
}

class MyDeque {
	private int size;
	private int first;
	private int last;
	private int data[];
	MyDeque(int limit) {
		data = new int [limit * 2 + 1];
		first = limit;
		last = limit - 1;
		size = 0;
	}
	void addFirst(int x) {
		data[--first] = x;
	}
	void addLast(int x) {
		data[++last] = x;
	}
	int get(int p) {
		return data[first + p];
	}
	void removeFirst() {
		first++;
	}
	void removeLast() {
		last--;
	}
}



Measured memory_bytes: 297404
/*
USER: caoash3
LANG: JAVA
TASK: 
*/

import java.io.*;
import java.util.*;

public class Main {

	static final boolean stdin = true;
	static final String filename = "";
	static FastScanner br;
	static PrintWriter pw;

	public static void main(String[] args) throws IOException {

		if (stdin) {
			br = new FastScanner();
			pw = new PrintWriter(new OutputStreamWriter(System.out));
		}

		else {
			br = new FastScanner(filename + ".in");
			pw = new PrintWriter(new FileWriter(filename + ".out"));
		}

		X solver = new X();
		solver.solve(br, pw);
	}

	static class X {
		public void solve(FastScanner br, PrintWriter pw) throws IOException {
			
			String s = br.nextToken();
			String t = br.nextToken();
			
			int N = s.length();
			int M = t.length();
			
			int[][] dp = new int[N+1][M+1];
			
			dp[0][0] = 0;
			
			for(int i = 1; i <= N; i++) {
				dp[i][0] = 0;
			}
			
			for(int i = 1; i <= M; i++) {
				dp[0][i] = 0;	
			}
			
			for(int i = 1; i <= N; i++) {
				for(int j = 1; j <= M; j++) {
					
					
					boolean c = s.charAt(i-1) == t.charAt(j-1);
										
					if(!c) {
						if(dp[i-1][j] > dp[i][j-1]) {
							dp[i][j] = dp[i-1][j];
						}
						else {
							dp[i][j] = dp[i][j-1];
						}
					}
					else {
						dp[i][j] = dp[i-1][j-1] + 1;
					}
					

					
				}

			}
			
			int i = N;
			int j = M;
			
			String ans = "";
			
			while(!(i==0 && j == 0)) {
				String a = "";
				String b = "";
				if(i > 0) {
				 a = Character.toString(s.charAt(i-1));
				}
				else {
				a = "";
				}
				if(j > 0) {
				 b = Character.toString(t.charAt(j-1));
				}
				else {
				b = "";	
				}
				
				
				if(a.equals(b)) {
					ans += a;
					i--;
					j--;
				}
				else {
					if(i == 0) {
						j--;
					}
					else if(j == 0) {
						i--;
					}
					else if(dp[i-1][j] > dp[i][j-1]) {
						i--;
					}
					else {
						j--;
					}
				}
			}
			
			String rev = "";
			
			for(int c = ans.length()-1; c >= 0 ; c--) {
				rev += ans.charAt(c);
			}
			
			pw.println(rev);
			
			pw.close();
		}

	}

	//fastscanner class
	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

}
 



Measured memory_bytes: 107492
#include<iostream>
#define ll long long
using namespace std;
ll n,m,ans;
inline void dfs(ll x,ll y)
{
    if(x%y == 0)
	{
        ans+=x*2-y;
        return ;
    }
    else
	{
        ans+=(x-x%y)*2;
        dfs(y,x%y);
    }
}
main()
{
	cin>>n>>m;
	ans = n,n -= m;
	dfs(max(n,m),min(n,m));
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int n;
vector < string > v;


void Rec(int i , char Max , string s){

    if(i == n) {
            v.push_back(s);
            return;
    }
    for(char j = 'a';j<=Max;j++)  Rec(i + 1 , max(Max , char(j + 1)) , s + j);

}

int main()
{
    cin >> n;
    Rec(0 , 'a' , "");
    for(auto j : v)  cout << j << '\n';
    return 0;
}


Measured memory_bytes: 7796
n = int(input())
t=[0]*(n+1)
x=[0]*(n+1)
y=[0]*(n+1)
for i in range(1,n+1):
    t[i],x[i],y[i]=map(int, input().split())
    
for i in range(1,n+1):
    time=t[i]-t[i-1]
    trip=abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
    if time<trip:
        print("No")
        exit()
    else:
        extra=time-trip
        if extra%2!=0:
            print("No")
            exit()

print("Yes")

Measured memory_bytes: 17224
#include <iostream>
#include <utility>
#include <vector>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint n, m, a;
vector<P> vec[1005];

int main(void)
{
	while(1){
		cin >> n >> m >> a;
		if(n == 0 && m == 0 && a == 0) break;
		
		for(int i = 1; i <= 1000; i++) vec[i].clear();
		llint h, u, v;
		for(int i = 1; i <= m; i++){
			cin >> h >> u >> v;
			vec[h].push_back(P(u, v));
		}
		
		for(int i = 1000; i >= 1; i--){
			for(int j = 0; j < vec[i].size(); j++){
				P p = vec[i][j];
				if(a == p.first) a = p.second;
				else if(a == p.second) a = p.first;
			}
		}
		cout << a << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3148
#include <iostream>

using namespace std;

int main() {
    
    int x, y, z;
    
    cin>> x >> y >> z;
    
    if(x < y && y < z){
        
        cout << "Yes" << endl;
    
    }
    
    else{
        
        cout << "No" << endl;
        
    }
    
    return 0;
    
}


Measured memory_bytes: 3100
from sys import stdin

h,w = [int(x) for x in stdin.readline().rstrip().split()]
li = [stdin.readline().rstrip() for _ in range(h)]

now = 0

for i in range(h):
    if "#" in li[i][:now]:
        print("Impossible")
        exit()
    for j in range(now,w-1):
        if li[i][j] == "#" and li[i][j+1] == ".":
            now = j
        if li[i][w-2] == "#" and li[i][w-1] == "#":
            now = w-1 
    if "#" in li[i][now+1:]:
        print("Impossible")
        exit()
print("Possible")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
       int n,m,ans,a[100],i,j,b,c,k,t;


              for(i=0;i<3;i++)
              {
                     cin>>a[i];
              }
              cin>>k;
              sort(a,a+3,greater<int>());
              int x=a[0];
              ans=2;
              for(i=1;i<=k;i++)
              {
                     x=2*x;
              }
              cout<<x+a[1]+a[2]<<endl;

       return 0;
}


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

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
using ll = long long;
using P = pair<int,int>;

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

class UnionFind{
public:
    // 親の番号を格納する
    // Parent -> -(the size)
    vector<int> Parent;
    
    // initialization
    // all nodes are roots
    UnionFind(int N){
        Parent =  vector<int>(N, -1);
    }
    
    int root(int A){
        if (Parent[A] < 0) return A; // A is in its own group.
        return Parent[A] = root(Parent[A]); // exchange parents
    }
    
    long long size(int A){
        return -Parent[root(A)];
    } 
    
    void connect(int A, int B){
        A = root(A);
        B = root(B);
        
        if (A == B) return; //already connected
        if (size(A) < size(B)) swap(A, B);
        
        Parent[A] += Parent[B]; //小さい方を大きい方にくっつける
        Parent[B] = A; //小さい方を大きい方にくっつける
    }
};
 
 
int main(){
    int N;
    cin >> N;
    
    vector<int> x(N),y(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
    
    using pint = pair<int, int>; //edgeを表現する
    using Edge = pair<long long, pint>; 
    vector<Edge> edges;
    
     // x 軸方向にソートして隣接している部分のみ
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0); //???????
    sort(ids.begin(), ids.end(), [&](int i, int j) {return x[i] < x[j];});
    
    for (int i = 0; i+1 < ids.size(); i++){
        int u = ids[i];
        int v = ids[i+1];
        edges.push_back( Edge(x[v] - x[u], pint(u, v) ) );
    }
    
     // y軸方向にソートして隣接している部分のみ考える
    sort(ids.begin(), ids.end(), [&](int i, int j) {return y[i] < y[j]; } );
    for (int i = 0; i+1 < ids.size(); i++){
        int u = ids[i];
        int v = ids[i+1];
        edges.push_back( Edge(y[v] - y[u], pint(u, v)) );
    }
    
    sort(edges.begin(), edges.end()); //edge.costが小さい順にソートする
    UnionFind Uni(N);
    long long res = 0;
    
    for (auto e : edges){
        
        int u = e.second.first;
        int v = e.second.second;
        long long cost = e.first;
        
        if(Uni.root(u) == Uni.root(v)) continue;
        Uni.connect(u, v);
        res += cost;
    }
    
    cout << res << endl;
}

Measured memory_bytes: 7536
#include <stdio.h>

int main(){
  int N,i,j,v;
  int A[100];

  scanf("%d",&N);
  for(i = 0; i < N; i++) scanf("%d",&A[i]);
  
  for(i = 1; i <= N-1; i++){
    for(j = 0; j < N; j++){
      printf("%d",A[j]);
      if(j == N-1) break;
      printf(" ");
    }
    printf("\n");
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
  }

  for(j = 0; j < N; j++){
    printf("%d",A[j]);
    if(j == N-1) break;
    printf(" ");
  }
  printf("\n");

  return 0;
}



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

int check(std::vector<int>& A){
    int tmp=0, first = A.at(0);
    A.erase(A.begin());
    for (int i: A){
        if (i < first) ++tmp;
    }
    return tmp;
}

int main(void){
    int N, a=0, b=0, ans=0;
    std::cin >> N;
    std::vector<int> P(N);
    std::vector<int> Q(N);
    const std::vector<int> con = {
        1, 1, 2, 6, 24, 120, 720, 5040, 40320
    };
    for (int i=0; i<N; ++i){
        std::cin >> P.at(i);
    }
    for (int i=0; i<N; ++i){
        std::cin >> Q.at(i);
    }

    for (int i=N; i>0; --i){
        a += con.at(i - 1) * check(P);
        b += con.at(i - 1) * check(Q);
    }


    std::cout << abs(a - b) << std::endl;

    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main(){
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;

	return 0;
}

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

using namespace std;

const long long INF = (1ll << 60);

void dfs(int node, vector<bool>& from, vector<bool>& to, vector<vector<int>>& graph){
  if(from[node]) return;
  from[node] = true;
  for(int next : graph[node]){
    dfs(next, from, to, graph);
    if(to[next]){
      to[node] = true;
    }
  }
}

int main(){
  int N, M;
  long long P;
  scanf("%d%d%lld", &N, &M, &P);
  
  vector<long long> coin(N, -INF);
  coin[0] = 0;
  
  vector<vector<int>> graph(N);
  vector<int> A(M), B(M);
  vector<long long> C(M);
  for(int j = 0; j < M; j++){
    scanf("%d%d%lld", &A[j], &B[j], &C[j]);
    A[j]--;
    B[j]--;
    C[j] -= P;
    graph[A[j]].push_back(B[j]);
  }
  
  vector<bool> from(N, false), to(N, false);
  to[N - 1] = true;
  dfs(0, from, to, graph);
  for(int i = 0; i < N; i++) from[i] = false;
  dfs(0, from, to, graph);
  for(int i = 0; i < N; i++) from[i] = false;
  dfs(0, from, to, graph);
  for(int i = 0; i < N; i++) from[i] = false;
  dfs(0, from, to, graph);
  for(int i = 0; i < N; i++) from[i] = false;
  dfs(0, from, to, graph);
  
  int num = 0;
  for(int i = 0; i < N; i++){
    if(from[i] && to[i]) num++;
  }
  
  bool fever = false;
  for(int i = 0; i < num; i++){
    for(int j = 0; j < M; j++){
      if(!(from[A[j]] && to[B[j]])) continue;
      if(coin[B[j]] < coin[A[j]] + C[j]){
        coin[B[j]] = coin[A[j]] + C[j];
        if(i == num - 1){
          fever = true;
          break;
        }
      }
    }
  }
  
  if(fever){
    puts("-1");
  }else{
    printf("%lld\n", max(coin[N - 1], 0ll));
  }
  
  return 0;
}

Measured memory_bytes: 640
#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()
using namespace std;

int main() {
    string s, ans="None";
    cin >> s;
    char abc[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    rep(i, 26){
        if(s.find(abc[i]) == string::npos){
            ans = abc[i];
            break;
        }
    }
    cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 inf = std::numeric_limits<i64>::max() / 2;
    i64 n, k;
    std::cin >> n >> k;
    std::vector<i64> h(n + 2);
    for (int i = 1; i <= n; i++) std::cin >> h[i];

    std::vector<std::vector<i64>> dp(n + 2, std::vector<i64>(k + 1, inf));
    dp[0][0] = 0;
    for (int i = 1; i <= n + 1; i++) for (int j = 0; j < i; j++) {
        int c = i - j - 1;
        i64 d = std::max(h[i] - h[j], 0ll);
        for (int l = 0; l + c <= k; l++) {
            dp[i][l + c] = std::min(dp[i][l + c], dp[j][l] + d);
        }
    }

    std::cout << *std::min_element(dp.back().begin(), dp.back().end()) << std::endl;

    return 0;
}


Measured memory_bytes: 1024