akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N; cin >> N;
    vector <ll> A(N);
    loop(i,0,N) cin >> A[i];
    int curpos=0;
    int start=-1;
    ll curamount=1000;
    while (curpos<N-1)
    {
        for (int i=curpos; i<N-1; ++i)
        {
            if (A[i]<A[i+1]) {
                start=i;
                int end=i+1;
                for (int j=i+2; j<N; ++j) {
                    if (A[j]>A[j-1]) end=j;
                    else break;
                }
                curpos=max(curpos,end+1);
                ll numstocks = curamount/A[start];
                curamount %= A[start];
                curamount += numstocks*A[end];
                break;
            }
            curpos=max(curpos, i+1);
        }
    }
    cout << curamount << "\n";
    return 0;
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[][][] state = new int[4][3][10];
		for(int i = 0; i < n; i++) {
			int b = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			int v = scan.nextInt();
			state[b - 1][f - 1][r - 1] += v;
		}
		scan.close();

		for(int i = 0; i < 4; i++) {
			for(int j = 0; j < 3; j++) {
				for(int k = 0; k < 10; k++) {
					if(k == 9) {
						System.out.println(" " + state[i][j][k]);
					}else {
						System.out.print(" " + state[i][j][k]);
					}
				}
			}
			if(i != 3) {
				System.out.println("####################");
			}
		}
	}
}


Measured memory_bytes: 29492
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//const int mod = 1e9+7;
ll n;
unordered_map<ll, ll> divs;
inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

void divide(ll x)
{
    for (ll i = 2; i <= x / i; i ++ )
        if (x % i == 0)
        {
            ll s = 0;
            while (x % i == 0) x /= i, s ++ ;
            divs[i] = s;
        }
    if (x > 1) divs[x] = 1;
}

ll get(ll x) {
    ll l = 0;
    ll r = x;
    ll res = -1;
    while(l <= r) {
        ll mid = (l + r) / 2;
        if((mid + 1)*mid/2 <= x) {
            res = mid;
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }
    return res;
}

int main()
{
    quickread();
    cin >> n;
    divide(n);
    ll res = 0;
    for(auto x:divs) {
        res += get(x.second);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int col(int x, int y) {
  int i = 0;
  while ((x & (1 << i)) == (y & (1 << i))) i++;
  return (i+1);
}

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;

  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      if (j > i+1) cout << " ";
      cout << col(i, j) ;
    }
    cout << "\n";
  }

  return 0;
}



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

int main(void) {
  int N, X;
  cin >> N >> X;
  int sum = 0;
  int a = 1000;

  for (int i = 0; i < N; ++i) {
    int m;
    cin >> m;
    sum += m;
    a = min(a, m);
  }

  cout << N + (X - sum) / a << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
struct Matrix
{
    vector< vector<ll> > mat;
    ll n_rows, n_cols;

    Matrix(vector< vector<ll> > values): mat(values), n_rows(values.size()),
        n_cols(values[0].size()) {}

    static Matrix identity_matrix(ll n)
    {
        // Return I_n - the identity matrix of size n.
        // This function is static, because it creates a new Matrix instance
        vector< vector<ll> > values(n, vector<ll>(n, 0));
        for(int i = 0; i < n; i++)
            values[i][i] = 1;
        return values;
    }

    Matrix operator*(const Matrix &other) const
    {
        ll n = n_rows, m = other.n_cols;
        vector< vector<ll> > result(n_rows, vector<ll>(m, 0));
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++) {
                for(int k = 0; k < n_cols; k++) {
                    result[i][j] = (result[i][j] + mat[i][k] * 1ll * other.mat[k][j]) % MOD;
                }
            }
        // Multiply matrices as usual, then return the result as the new Matrix
        return Matrix(result);
    }

    bool is_square() const
    {
        return n_rows == n_cols;
    }
};

Matrix fast_exponentiation(Matrix m, ll power)
{
    assert(m.is_square());
    Matrix result = Matrix::identity_matrix(m.n_rows);

    while(power) {
        if(power & 1)
            result = result * m;
        m = m * m;
        power >>= 1;
    }

    return result;
}
int main()
{
    ll n,k;
    cin>>n>>k;
    vector<vector<ll> > vec(n,vector<ll>(n));
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        cin>>vec[i][j];
    Matrix m(vec);
    m=fast_exponentiation(m,k);
    vec=m.mat;
    ll ans=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        ans=(ans + vec[i][j])%MOD;
    cout<<ans;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456;
int f[maxn];
int main(){
  iota(f, f + maxn, 0);
  for(int p : {6, 9}){
  	long long now = p;
   	while(now < maxn){
		for(int i = 0; i < maxn - now; i++) f[i + now] = min(f[i + now], f[i] + 1);
      now *= p;
    }
  }
  int n; cin >> n;
  cout << f[n] << endl;
  return 0;
}

Measured memory_bytes: 768
n = int(input())
memo = [{} for i in range(n+1)]
mod = 10**9+7
#想定解法の写経
def ok(last4):
    #隣接する二つを入れ替えてAGC二ならないかどうかをチェック
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i], t[i-1] = t[i-1], t[i]
        if "".join(t).count('AGC') >= 1:
            return False
    return True
def dfs(now, last3):
    if last3 in memo[now]:
        return memo[now][last3]
    if now == n:
        return 1
    ret = 0
    for i in 'AGCT':
        #もし、次の一文字を足した4文字がずらしてAGCに引っかからなければ
        if ok(last3 + i):
            #今回をiにした場合のこの後の文字列の数を全て計算
            ret = (ret + dfs(now+1, last3[1:] + i)) % mod
    memo[now][last3] = ret
    return ret
print(dfs(0,'TTT'))


Measured memory_bytes: 47836
/*
Created at: 2018 December 22 16:55:07
Created by: metamorphosis00
*/
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e5;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
int a[N + 1], sum;
main() {
    int n = readInt();
    for (int i = 1; i <= n; i++) {
        a[i] = readInt();
        if (a[i] & 1) {
            puts("first");
            return 0;
        }
    }
    puts("second");
}



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

int main(void) {
  ll N;
  cin >> N;
  vector<ll> X(N);
  REP(i, 0, N) cin >> X[i];

  ll ans = -1;
  REP(i, 0, N) REP(j, i + 1, N) {
    ll p = X[i] * X[j];
    string s = to_string(p);
    bool ok = true;
    REP(k, 0, s.size() - 1) ok = ok && s[k] + 1 == s[k + 1];
    if(ok) ans = max(ans, p);
  }
  cout << ans << endl;
}


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

int dp[8001][16001];
int a[8001];

int main(){
	ios::sync_with_stdio(false);
	string s;
	int x,y;
	cin>>s>>x>>y;
	int k=0,w=0;
	for(int i=0;i<s.size();++i){
		if(s[i]=='T'){
			++k;
			a[k]=w;
			w=0;
		}else
			++w;
	}++k;
	a[k]=w;
	//for(int i=1;i<=k;i++)cout<<a[i]<<endl;
	dp[1][a[1]+8000]=1;
	for(int i=3;i<=k;i+=2){
		for(int j=0;j<=16000;++j){
			if(j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
				dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	dp[0][8000]=1;
	for(int i=2;i<=k;i+=2){
		for(int j=0;j<=16000;++j){
			if(j+a[i]<=16000)
			dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
			dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	int ans;
	if(k%2==0){ 
		ans=dp[k][y+8000]&&dp[k-1][x+8000];
	}
	else{
		ans=dp[k][x+8000]&&dp[k-1][y+8000];
	}
	cout<<(ans==0?"No\n":"Yes\n");
	return 0;
}

Measured memory_bytes: 497792
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        a: usize,
        b: usize,
    }
    if a >= 13 {
        println!("{}", b);
    } else if a <= 5 {
        println!("{}", 0);
    } else {
        println!("{}", b/2);
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define eps 1e-6
#define ll  long long
#define endl '\n'
bool isPrime(ll a)
{
  ll count=0,i;
  rep(i,2,a/2+1)
    if(a%i==0) count++;
    if(count) return false;
    else return true;
}
void solve()
{
  ll n, a,m=0,b=1, k=0, i, j,l=2e9+7;
  string s, r, y;
  cin>>n>>a;
  ll ar[n+1]={0},br[n+1]={0};
 while(a--)
 {
   cin>>n>>s;
   if(ar[n]==0 && s=="WA")
   br[n]++;
   else if(ar[n]==0 && s=="AC")
   {
     ar[n]=1;k++;m+=br[n];
   }
 }
 cout<<k<<" "<<m;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
  // cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 5216
#include<iostream> 
#include<vector> 
#include<algorithm> 
#include<iomanip> 
#include<stack> 
#include<unordered_map>
#include<climits>
#include<set> 
#include<string> 
//#include<bits/stdc++.h> 
using namespace std; 
#define lld long long int 
#define eb emplace_back
//to insert pair use eb
#define mp make_pair
#define fi first
#define se second
#define pb push_back

#define X 1000000007
#define Y 998244353
#define E4 1000
#define E5 10000 
#define E6 1000000
#define inf 1001001001
#define longinf 2001001001001001001
#define pi 3.1415926535

# define rec2(i,a,b) for(lld i=a;i<b;i++) 
#define rec(i,n) for(lld i=0;i<n;i++)
#define rev(i,a,b) for(lld i=b-1;i>=a;i--)
#define all(v) (v).begin(), (v).end()
#define large(v)  *max_element(all(v))
#define small(v)  *min_element(all(v)) 
#define v vector
const double EPS = 1e-6;
/*  //prime sieve if needed 
//prime factors of number
int prime[E6+1]; 
void sieve(lld n) 
{ rec(i,n+1) 
    prime[i]=1; 
   for(lld i=2;i*i<=n;i++) 
     { if(prime[i]!=1) 
          continue; 
         for(lld j=i*i;j<=n;j=j+i) 
          if(prime[i]==1)
           prime[j]=i; 
      }
}
*/
lld gcd(lld a,lld b)
{
    if(a==0)
     return b; 
    return gcd(b%a,a); 
}
//fermat a^(m-2)%mod
lld binarymul(lld a,lld n,lld m)
{  lld res=1; 
 while(n) 
  { if(n%2) 
      { res=(res*a)%m; 
         n--; 
      } 
     a=(a*a)%m; 
     n/=2; 
  }
  return res; 
}
int main()
{
   ios_base::sync_with_stdio(false); 
   cin.tie(0);
     #ifdef PUNEET_GOEL
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif
   //sieve(E6); 
    lld n; 
    cin>>n; 
    n=n%1000; 
    if(n!=0) 
     n=1000-n; 
    cout<<n<<endl; 
	return 0;
}

Measured memory_bytes: 3648
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

fn main() {
    let (r, w, e) = (stdin(), stdout(), stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    // =============================================== //
    let (n, m): (usize, usize) = (io.read(), io.read());
    let mut g: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..m {
        let (a, b): (usize, usize) = (io.read(), io.read());
        g[a - 1].push(b - 1);
        g[b - 1].push(a - 1);
    }

    let mut q: VecDeque<(usize, usize)> = VecDeque::new();
    let mut ans: Vec<isize> = vec![-1; n];
    q.push_back((0, 0));
    ans[0] = 0;
    let mut visited = vec![false; n];
    visited[0] = true;
    // bfs
    while let Some(got) = q.pop_front() {
        //
        let now = got.0;
        let depth = got.1;

        visited[now] = true;
        for &nxt in g[now].iter() {
            if visited[nxt] {
                continue;
            }
            ans[nxt] = now as isize;
            visited[nxt] = true;
            q.push_back((nxt, depth + 1));
        }
    }

    println!("Yes");
    for i in 1..n {
        println!("{}", ans[i] + 1);
    }
}

// IO
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug ) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
}


Measured memory_bytes: 12692
#include<bits/stdc++.h>
using namespace std;
// Function to add an edge

void addEdge(vector<int> adj[], int u, int v) 
{ 
    adj[u].push_back(v); 
} 

int DFS(vector<int> adj[],int start,bool vis[],int dp[]){
  vis[start]=true;
  int temp;
  for(int i=0;i<adj[start].size();i++){
    if(vis[adj[start][i]]==false){
      //cout << adj[start][i];
      temp = 1+DFS(adj,adj[start][i], vis,dp);
      
    }
    else temp  = 1+ dp[adj[start][i]];
    dp[start] = max(temp,dp[start]);
  }
  if(adj[start].size()==0) dp[start]=0;
  return dp[start];
}

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> adj[N+1];
  int start,end;
  int dp[N + 1];
  memset(dp, 0, sizeof dp); 
  for(int i=0;i<M;i++){
    cin >> start >> end;
    addEdge(adj,start,end);
  }
  bool vis[N + 1]; 
  memset(vis, false, sizeof vis);
  for(int i=1;i<=N;i++){
    if(vis[i]==false){
        //cout << i;
       DFS(adj,i,vis,dp);  
    }
    
  }
  int max1=dp[0];
  for(int i=1;i<=N;i++){
  	  max1=max(max1,dp[i]);
  }
  
  cout << max1;
  return 0;
}

Measured memory_bytes: 13008
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int x;
    cin>>x;
    vector<bool> isP(1001000,true);
    isP[0] = isP[1] = false;
    for (int i = 2; i < 1001000; i++)
    {
        if (isP[i])
        {
            for(int j = i * 2; j < 1001000; j += i)
            {
                isP[j] = false;
            }
        }
    }
    while(true){
        if(isP[x]){
            cout<<x<<endl;
            break;
        }
        x++;
    }
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

std::vector<std::string> v;

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

    std::string S;
    std::cin >> S;

    int K;
    std::cin >> K;
    
    int l = S.size();

    for(int i=1;i<=10;++i){
        for(int j=0;j+i<=l;++j){
            v.emplace_back(S.substr(j, i));
        }
    }

    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::cout << v[K-1] << std::endl;
}


Measured memory_bytes: 3064
#include<stdio.h>
main () {
	int data[10];
	int temp;
	int i = 0;
	int j = 0;
	for (i = 0; i < 10; i++) {
		scanf("%d", &data[i]);
	}
	for (i = 0; i < (10 - 1); i++) {
		for (j = i + 1; j < 10; j++) {
			if (data[j] > data[i]) {
				temp = data[j];
				data[j] = data[i];
				data[i] = temp;
				
			}
		}
	}
	for (i = 0; i < 3; i++) {
		printf("%d\n", data[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

LL dp[101][100001];

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

    vector<int> w(N+1);
    vector<int> v(N+1);

    for (int i = 1; i <= N; ++i) {
        cin >> w[i] >> v[i];
    }

    for (int i = 1; i <= N; ++i) { //! checking up to i-th item (where i is in 1..N range)
        for (int j = 0; j <= W; ++j) {  //! the weight is less than or equal to j   
            if (j < w[i]) {
                dp[i][j] = dp[i-1][j];
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            }
        }
        // cout << "dp[" << i << "] = ";
        // for (int k = 0; k <=W; ++k) {
        //     cout << dp[i][k] << ' ';
        // }
        // cout << endl;
    }

    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 78336
n,w=map(int,input().split())
l=[]
for _ in range(n):
    a,b=map(int,input().split())
    l.append((a,b))
dp=[[0 for i in range(w+1)]for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,w+1):
        if l[i-1][0]<=j:
            
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-l[i-1][0]]+l[i-1][1])
        else:
            dp[i][j]=dp[i-1][j]
# print(dp)
print(dp[-1][-1])

Measured memory_bytes: 171784
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return 0;
}

int main() {
    fastio;
    ll ans=0;
    ll N,K;
    cin >> N >> K;
    vector<int> s(N);
    rep(i,N) cin >> s[i];
    segtree<int, op, e> dp(300005);
    for (int i=0; i<N; ++i) {
        int l = s[i] - K, r = s[i] + K + 1;
        updmax(l, 0);
        updmin(r, 300005);
        dp.set(s[i], dp.prod(l, r) + 1);
    }
    ans = dp.all_prod();
    cout << ans << endl;
}


Measured memory_bytes: 9832
#include<map>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
typedef long long int ll;
using namespace std;
#define MAX   150002
#define X first
#define Y second
#define MOD 1000000007
#define fr(a,b,c) for(ll a=b;a<c;++a)
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll t,n,i,j;
int main()
{
    fastio;
    cin>>n;
    vector <double > v(n);
    fr(i,0,n){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    double x=v[0];
    for(i=1;i<n;i++){
        x=(x+v[i])/(2.0);
    }
    cout<<setprecision(15)<<x<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((int)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	LL H, W;
	cin >> H >> W;
	LL ans = INF;
	REP(i, H/2+1){
		LL a = i * W;
		LL b = (H-i)/2 * W;
		LL c = (H-i+1)/2 * W;
		ans = min(ans, max({a, b, c}) - min({a, b, c}));
		b = (H-i) * (W / 2);
		c = (H-i) * ((W+1) / 2);
		ans = min(ans, max({a, b, c}) - min({a, b, c}));
	}
	REP(i, W/2+1){
		LL a = H * i;
		LL b = H * ((W-i)/2);
		LL c = H * ((W-i+1)/2);
		ans = min(ans, max({a, b, c}) - min({a, b, c}));
		b = (H/2) * (W-i);
		c = ((H+1)/2) * (W-i);
		ans = min(ans, max({a, b, c}) - min({a, b, c}));
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
    int S, h, m;
    int Hour = 60 * 60;
    int Minute = 60;
    std::cin >> S;

    h = S / Hour;
    S -= h * Hour;
    m = S / Minute;
    S -= m * Minute;
    printf("%d:%d:%d\n", h, m, S);
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
bool pjudge(int p){
    bool judge = true;
    for(int i = 2;i < p;i++){
        if(p % i == 0){
            judge = false;
            break;
        }
    }
    return judge;
}
int main(){
    int n;cin >> n;
    vector<int> p;
    for(int i = 2;i < 55555;i += 5){
        if(pjudge(i) == true)p.push_back(i);
    }
    for(int i = 0;i < n;i++)cout << p[i] << " ";
    //cin >> n;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int T = sc.nextInt();
    int cost = 2000;
    for(int i = 0; i < n; i++) {
      int c = sc.nextInt();
      int t = sc.nextInt();
      if(t <= T) cost = Math.min(cost, c); 
    }
    if(cost == 2000) {
      System.out.println("TLE");
    } else {
      System.out.println(cost);
    }
  }
}

Measured memory_bytes: 23764
//けんちょん見ました
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

vector<int> places[210000];
ll dp[210000];

int main(){
  ll n;
  cin >> n;
  vector<int>c(n);
  for(int i=0; i<n; i++) cin >> c[i];
  for(int i=0; i<n; i++) places[c[i]].push_back(i);
  
  dp[0]=1;
  for(int i=1; i<=n; i++){
    dp[i]=dp[i-1];
    
    ll color = c[i-1];
    ll it = lower_bound(places[color].begin(),places[color].end(),i-1)-places[color].begin();
    if(it>0){
      ll j = places[color][it-1];
      if((i-1)-j>1){
        dp[i]+=dp[j+1];
        dp[i]%=mod;
      }
    }
  }
  cout << dp[n] << endl;
}
  
  
  


Measured memory_bytes: 13824
from heapq import heappush, heappop


N, K = map(int, input().split())

V = list(map(int, input().split()))

ans = 0
for back in range(K + 1):
    getV = min(N, K - back)
    for left in range(getV + 1):
        r = getV - left
        S = 0
        hq = []
        for i in range(left):
            heappush(hq, V[i])
            S += V[i]
        for j in range(r):
            heappush(hq, V[N - 1 - j])
            S += V[N - 1 - j]
        for k in range(back):
            if len(hq) > 0 and hq[0] < 0:
                S -= heappop(hq)

        ans = max(ans, S)

print(ans)


Measured memory_bytes: 3064
import numpy
N,D = map(int,input().split())
count = 0
temp =[]
for i in range(N):
    temp.append(list(map(int,input().split())))
for i in range(len(temp)):
    ss = numpy.sqrt(temp[i][0] * temp[i][0] + temp[i][1] * temp[i][1])
    if ss <= D:
        count += 1

print(count)

Measured memory_bytes: 63292
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>
#include <functional>

using namespace std;
using ll = long long;

#define all(x) (x).begin(),(x).end()
#define PRI(n) cout << n << " "<<endl;
#define PRI2(n, m) cout << n << " " << m << " "<<endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define FOR(i, t, n)  for(int i = t; i <= (int)n; ++i)

const char alphabet[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'};
const ll MOD = 1e9 + 7;

struct edge;
struct UnionFind;

bool isPrime(ll x);

ll GCD(ll a, ll b);

ll LCM(ll a, ll b);

ll nCr(int n, int r);


struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int N) {
        for (int i = 0; i < N; ++i) {
            par.push_back(i);
            rank.push_back(0);
        }
    }

    int find(int x) {
        if (par[x] == x)return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }

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

int M, N;
int F[100][10];
int P[100][10];
int A[2][100];

int main() {
    cin >> N;
    REP(i, N)cin >> A[0][i];
    REP(i, N)cin >> A[1][i];
    int ans = 0;
    REP(i, N) {
        int sum = 0;
        int c = i;
        REP(j, N) {
            if (j <= c)sum += A[0][j];
            if(j >= c)sum += A[1][j];
        }
        ans = max(ans,sum);
    }
    PRI(ans)
    return 0;
}

struct edge {
    int to, cost;
    bool flag = false;
};

bool isPrime(ll x) {
    if (x == 0)return 0;
    if (x == 1)return 0;
    if (x == 2)return 1;
    if (x % 2 == 0)return 0;
    FOR(i, 3, x - 1) {
        if (x % i == 0)return 0;
    }
    return 1;
}

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

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}


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

int main(){
  	int N, ans=0;
  	cin >> N;
  	vector<int> d(N);
  	
  	for(int i=0; i<N; i++){
    	cin >> d[i];
    }
  	
  	for(int i=0; i<N; i++){
    	for(int j=i+1; j<N; j++){
        	ans += d[i]*d[j];
        }
    }
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999
#define eps 1e-9


bool solve(string s){
    if(s.find("this")!=string::npos)return true;
    if(s.find("that")!=string::npos)return true;
    return false;
}

int main(){
    int n;
    cin>>n;
    cin.ignore();
    rep(i,n){
        string s;
        getline(cin,s);
        rep(j,1000){
            rep(k,27){
                string m=s;
                rep(l,m.size()){
                    if(isalpha(m[l])){
                        m[l] = 'a'+((j*(m[l]-'a')+k)%26);
                    }
                }
//                cout<<m<<endl;
                if(solve(m)){
                    cout<<m<<endl;
                    goto end;
                }
            }
        }
    end:;
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(ALLOF(v));

  cout << v[v.size()-1] - v[0] << endl;
  
  return 0;
}


Measured memory_bytes: 256
/*
--> WHEN IT'S OBVIOUS THAT THE GOAL CANNOT BE REACHED,
	DON'T ADJUST THE GOALS,
	ADJUST THE ACTION STEPS.

--> THE WAY YOU CONQUER SELF-DOUBT IS BY DOING THINGS THAT MAKE YOU UNCOMFORTABLE.

--> IT IS DURING OUR DARKEST MOMENTS WE MUST FOCUS TO SEE LIGHT.
*/

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <climits>
using namespace std;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(all(x))
#define sz(x) (int)x.size()
#define clr(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef pair< int, int >	pii;
typedef pair< ll, ll >		pl;
typedef vector< int >		vi;
typedef vector< ll >		vl;
typedef vector< pii >		vpii;
typedef vector< pl >		vpl;
typedef vector< vi >		vvi;
typedef vector< vl >		vvl;

const int MOD = 1e9 + 7;

ll power(ll a, ll b)
{
	ll ans = 1;

	while (b > 0)
	{
		if (b & 1)
			ans *= a;
		a = a * a;
		b >>= 1;
	}
	return ans;
}

ll powm(ll a, ll b)
{
	a %= MOD;
	ll ans = 1;

	while (b > 0)
	{
		if (b & 1)
			ans = (ans * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return ans;
}

//================================

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

	if (sz(s) >= 6 && s[2] == s[3] && s[4] == s[5])
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}

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

typedef pair<int, int> P;
struct edge { int to, cost; };

const int INF = 10000000;

int main()
{
    int n,m;
    while(cin >> n && n) {
        cin >> m;
        vector<edge> G[n+1];
        for(int i = 0; i < m; i++) {
            int a, b, c, d;
            scanf("%d,%d,%d,%d\n", &a, &b, &c, &d);
            G[a].push_back((edge){b, c});
            G[b].push_back((edge){a, d});
        }
        
        int x1, x2, y1, y2;
        scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
        
        priority_queue<P, vector<P>, greater<P> > que;
        int dist1[n+1];
        fill(dist1, dist1 + n + 1, INF);
        dist1[x1] = 0;
        que.push(P(0, x1));
        while(!que.empty()) {
            P p = que.top(); que.pop();
            int v = p.second;
            if(dist1[v] < p.first) continue;
            for(int i = 0; i < G[v].size(); i++) {
                edge e = G[v][i];
                if(dist1[e.to] > dist1[v] + e.cost) {
                    dist1[e.to] = dist1[v] + e.cost;
                    que.push(P(dist1[e.to], e.to));
                }
            }
        }

        priority_queue<P, vector<P>, greater<P> > que2;
        int dist2[n+1];
        fill(dist2, dist2 + n + 1, INF);
        dist2[x2] = 0;
        que2.push(P(0, x2));
        while(!que2.empty()) {
            P p = que2.top(); que2.pop();
            int v = p.second;
            if(dist2[v] < p.first) continue;
            for(int i = 0; i < G[v].size(); i++) {
                edge e = G[v][i];
                if(dist2[e.to] > dist2[v] + e.cost) {
                    dist2[e.to] = dist2[v] + e.cost;
                    que2.push(P(dist2[e.to], e.to));
                }
            }
        }

        cout << y1 - y2 - dist1[x2] - dist2[x1] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
data class Item(val to: Int, val cost: Int)
fun main(args: Array<String>) {
    val N = nextInt()
    var G = Array(N) {
        mutableListOf<Item>()
    }
    for (n in 0 until N - 1) {
        var (u, v, w) = listOfInt()
        u -= 1; v -= 1; w %= 2
        G[u].add(Item(v, w))
        G[v].add(Item(u, w))
    }
    val ans = Array(N) { -1 }
    ans[0] = 0
    val Q = Queue<Int>()
    Q.enqueue(0)
    while (!Q.isEmpty()) {
        val v = Q.dequeue()!!
        G[v].forEach {
            val u = it.to
            val cost = it.cost
            if (ans[u] == -1) {
                ans[u] = ans[v] xor cost
                Q.enqueue(u)
            }
        }
    }
    println(ans.joinToString("\n"))
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
class Queue<T> {
    val elements = mutableListOf<T>()
    fun isEmpty() = elements.isEmpty()
    fun count() = elements.size
    fun enqueue(item: T) = elements.add(item)
    fun dequeue() = if (!isEmpty()) elements.removeAt(0) else null
    fun peek() = if (!isEmpty()) elements[0] else null
}

Measured memory_bytes: 85488
from sys import stdin
h,w = map(int,stdin.readline().rstrip().split())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(h)]
point = 0
lin = []
#まず行ごとにまとめて右に1つづつスライド
for i in range(h):
    for j in range(w-1):
        if li[i][j] %2 == 1:
            li[i][j] -= 1
            li[i][j+1] += 1
            lin.append([i+1,j+1,i+1,j+2])
            point += 1
#右端のを１つづつ下にスライド
for i in range(h-1):
    if li[i][w-1] %2 == 1:
        li[i][w-1] -= 1
        li[i+1][w-1] += 1
        lin.append([i+1,w,i+2,w])
        point += 1
print(point)
for i in lin:
    print(*i)

Measured memory_bytes: 30260
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+20;
int n,a[N];
int f[N],h[N];
//f[i] increase
int main()
{
	while(cin>>n)
	{
		
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		f[n]=h[n]=1;
		for(int i=n-1;i>=1;i--)
		{
			if(a[i]==a[i+1])
			{
				f[i]=f[i+1]+1;
				h[i]=h[i+1]+1;
			}
			else if(a[i]>a[i+1])
			{
				f[i]=1;
				h[i]=h[i+1]+1;
			}
			else
			{
				h[i]=1;
				f[i]=f[i+1]+1;
			}
		}
		int ans=0;
		int i=1;
		while(i<=n)
		{
		//	cout<<i<<' ';
			if(f[i]>h[i])
			i+=f[i];
			else
			i+=h[i];
			
			
			
			ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

constexpr int64_t inf = 1ll << 60;

int64_t nearest(const vector<int64_t> &v, int64_t x) {
  int index = lower_bound(v.begin(), v.end(), x) - v.begin();
  if (index == 0) return v.at(0) - x;
  if (index == v.size()) return x - v.back();
  return min(x - v.at(index - 1), v.at(index) - x);
}

int main() {
  int64_t a, b, q;
  cin >> a >> b >> q;
  vector<int64_t> s(a + 2), t(b + 2), x(q);
  s.at(0) = -inf;
  for (int i = 0; i < a; i++) {
    cin >> s.at(i + 1);
  }
  s.at(a + 1) = inf;
  t.at(0) = -inf;
  for (int i = 0; i < b; i++) {
    cin >> t.at(i + 1);
  }
  t.at(b + 1) = inf;
  for (int i = 0; i < q; i++) {
    cin >> x.at(i);
  }
  for (int i = 0; i < q; i++) {
    int s0 = lower_bound(s.begin(), s.end(), x.at(i)) - s.begin(),
        t0 = lower_bound(t.begin(), t.end(), x.at(i)) - t.begin();
    int s1 = s0 - 1, t1 = t0 - 1;
    int64_t d = inf;
    d = min(d, abs(s.at(s0) - x.at(i)) + nearest(t, s.at(s0)));
    d = min(d, abs(s.at(s1) - x.at(i)) + nearest(t, s.at(s1)));
    d = min(d, abs(t.at(t0) - x.at(i)) + nearest(s, t.at(t0)));
    d = min(d, abs(t.at(t1) - x.at(i)) + nearest(s, t.at(t1)));
    cout << d << endl;
  }
}


Measured memory_bytes: 3840
#include<iostream>

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

using namespace std;

#define NMAX 50
#define NMIN 2
#define DMAX 100
#define DMIN 0


int main(void){
	int N;
	cin >> N;
	
	int d[NMAX];
	rep(i, N){
		cin >> d[i];
	}
	
	int total = 0;
	for(int i=0; i<N; i++){
		for(int j=i+1; j<N; j++){
			total += d[i] * d[j];
		}
	}
	
	cout << total << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define mt make_tuple

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int par[100001];
int ran[100001];

int findset(int i){
    if(par[i]==i)
        return i;
    else
        return par[i]=findset(par[i]);
}

void merge(int i,int j){
    int b=findset(i);
    int s=findset(j);
    if(ran[b]<ran[s])swap(b,s);
    else ran[b]++;
    par[s]=b;
}

int main() {
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        par[i]=i;
        ran[i]=1;
    }
    vector<tuple<int,int,int>> kruskal;
    vector<pair<int,int> > x;
    vector<pair<int,int> > y;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        x.pb({a,i});
        y.pb({b,i});
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    for(int i=0;i<n-1;i++){
        int p=x[i].fi,q=x[i].se;
        int r=x[i+1].fi,s=x[i+1].se;
        kruskal.push_back(mt(r-p,q,s));
        p=y[i].fi,q=y[i].se;
        r=y[i+1].fi,s=y[i+1].se;
        kruskal.push_back(mt(r-p,q,s));
    }
    sort(kruskal.begin(),kruskal.end());

    long long ans=0;
    for(long i=0;i<kruskal.size();i++){
        int u,v,c;
        c=get<0>(kruskal[i]);
        u=get<1>(kruskal[i]);
        v=get<2>(kruskal[i]);
        if(findset(u)!=findset(v)){
            merge(u,v);
            ans+=c;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7912
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	int n;
	bool flag = false;

	while( cin >> n , n ){
		vector<int> vc;
		map<int,vector<string> > f;
		if( flag ){
			cout << endl;
		}else{
			flag = true;
		}

		for(int i=0 ; i < n ; i++ ){
			string name;
			int a,b,c;

			cin >> name >> a >> b >> c;
			int p = -(a*3 + c);
			if( count(vc.begin(),vc.end(),p) == 0 ){
				vc.push_back( p );
			}
			f[p].push_back( name );
		}
		sort( vc.begin() , vc.end() );
		for(int i=0 ; i < vc.size() ; i++ ){
			for(int j=0 ; j < f[vc[i]].size() ; j++ ){
				cout << f[vc[i]][j] << "," << -vc[i] << endl;
			}
		}
	}
}

Measured memory_bytes: 0
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
#define MAX 1000005
#define forci(p,q) for(int i=p;i<q;i++)
bool prime[MAX];
/*ull sieve()
{
	memset(prime,true,sizeof(prime));
	for(ull p=2;p*p<MAX;p++)
	{
		if(prime[p]==true){
			for(ull i=2*p;i<MAX;i+=p)
			{
				prime[i]=false;
			}
		}
	}
	prime[0]=0;
	prime[1]=0;
}*/
using namespace std;
signed main()
{
	fastio;
	int n,m;
	cin>>n>>m;
	int a[m];
	int sum=0;
	forci(0,m)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(sum<=n)
		cout<<n-sum<<endl;
	else
		cout<<"-1"<<endl;
	
	
	
	
	
	
	
	
	
}


Measured memory_bytes: 3668
#include<cstdio>
#include<cmath>
const int N=1233;
int n,X[N],Y[N],R[N];
double dis[N];
bool vis[N];
inline double Dist(int x,int y){return sqrt(1.*x*x+1.*y*y);}
int main(){
	scanf("%d%d%d%d%d",X+1,Y+1,X+2,Y+2,&n),n+=2;
	for(int i=3;i<=n;++i)scanf("%d%d%d",X+i,Y+i,R+i);
	for(int i=2;i<=n;++i)dis[i]=1e18;
	for(int T=1;T<n;++T){
		int u=0;
		for(int i=1;i<=n;++i)
		if((!u||dis[i]<dis[u])&&!vis[i])u=i;
		vis[u]=1;
		for(int i=1;i<=n;++i)
		if(u!=i&&!vis[i]){
			double nd=Dist(X[u]-X[i],Y[u]-Y[i])-R[u]-R[i];
			if(nd<0)nd=0;
			if(dis[i]>dis[u]+nd)dis[i]=dis[u]+nd;
		}
	}
	printf("%.15f\n",dis[2]+1e-15);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define vs vector<string>
#define vc vector<char>
#define vvc vector< vector<char> >

#define all(a) (a).begin(),(a).end()
using namespace std;

int main(){
	ll a, b, k; cin >> a >> b >> k;
	vl ngo;
	for (ll i = a; i < min(b,a + k); ++i) ngo.push_back(i);
	for (ll i = max(a,b - k+1); i <= b; ++i) ngo.push_back(i);
	sort(all(ngo));
	ngo.erase(unique(all(ngo)),ngo.end());
	for (ll i = 0; i < ngo.size(); ++i){
		cout << ngo[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
using namespace std;

int main() {
	int N, M;
	string s[110], t[110];
	cin >> N;
	for (int i = 1; i <= N; ++i) cin >> s[i];
	cin >> M;
	for (int i = 1; i <= M; ++i) cin >> t[i]; // 入力終わり
	
	int c[110] = {};
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			if (s[i] == s[j]) ++c[i];
		}	
		for (int j = 1; j <= M; ++j) {
			if (s[i] == t[j]) --c[i];
		}
	}
	sort (c, c + N, greater<int>());
	cout << c[0] <<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var s = Integer.parseInt(br.readLine());

      final var modulo = (long)Math.pow(10, 9) + 7;
      final var cache = new long[Math.max(s + 1, 6)];

      cache[3] = 1;
      cache[4] = 1;
      cache[5] = 1;

      for (int i = 6; i <= s; i++) {
        cache[i] = (cache[i - 1] + cache[i - 3]) % modulo;
      }

      System.out.println(cache[s]);
    }
  }
}


Measured memory_bytes: 32716
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#pragma warning(disable : 4996)

#define MAX_N 100
#define MAX_W 100000
#define INF 1000000000

template <typename T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <typename T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
int Abs(int a) {
	if (a < 0) return a *= -1;
	return a;
}

int min(int a, int b) {
	if (a < b) return a;
	return b;
}
long long max(long long a, long long b) {
	if (a > b) return a;
	return b;
}

int N, W;
long long DP[MAX_N+1][MAX_W + 1];

int main(void) {
	scanf("%d %d", &N, &W);
	for (int i = 1; i <= N; ++i) {
		int w;
		int v;
		scanf("%d %d", &w, &v);
		for (int j = 0; j <= W; ++j) {
			if (j - w >= 0) {
				DP[i][j] = max(DP[i - 1][j - w] + v, DP[i - 1][j]);
			}
			else {
				DP[i][j] = DP[i - 1][j];
			}
		}
	}
	printf("%lld", DP[N][W]);
	return 0;
}


Measured memory_bytes: 78336