akhauriyash/Code-Regression huggingface dataset:
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;

fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let a: Vec<i64> = (0..n).map(|_| sc.ne()).collect();
    let f = |s: i64| -> i64 {
        let mut sum = s;
        let mut ans = 0;
        for i in 1..n {
            if sum > 0 {
                if sum + a[i] >= 0 {
                    ans += sum + a[i] + 1;
                    sum = -1;
                } else {
                    sum = a[i] + sum;
                }
            } else {
                if sum + a[i] <= 0 {
                    ans += -(sum + a[i]) + 1;
                    sum = 1;
                } else {
                    sum = sum + a[i];
                }
            }
        }
        ans
    };
    let r = a[0];
    let mut ans = std::cmp::min(f(r), f(if r > 0 { -1 } else { 1 }) + r.abs() + 1);
    if a[0] == 0 {
        ans = std::cmp::min(f(1) + 1, f(-1) + 1);
    }
    println!("{}", ans);
}

fn main() {
    const STACK: usize = 16 * 1024 * 1024;
    let _ = std::thread::Builder::new()
        .stack_size(STACK)
        .spawn(|| { exec(); })
        .unwrap()
        .join()
        .unwrap();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!("parse error, {:?}",
                       String::from_utf8(self.buf[l..r].to_owned()))
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


Measured memory_bytes: 12668
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n;
	cin >> n;
	int a[n], v[100010] = {};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		v[a[i]]++;
	}
	int Ans = -1;
	for (int i = 1; i < 100000; i++) {
		int Cmp = v[i - 1] + v[i] + v[i + 1];
		Ans = max(Ans, Cmp);
	}
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N;
ll A[100000];
vector<int> E[100000];
bool used[100000];
bool dfs(int x){
    used[x]=1;
    if(sz(E[x])==1){
        return true;
    }
    bool t=true;
    ll sum=0;
    ll m=0;
    rep(i,0,sz(E[x])){
        if(used[E[x][i]]==0){
            t&=dfs(E[x][i]);
            sum+=A[E[x][i]];
            m=max(m,A[E[x][i]]);
        }
    }
    if(min(sum-m,sum/2)<sum-A[x]||A[x]>sum||sum>2*A[x]) return false;
    A[x]=2*A[x]-sum;
    return t;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N) cin>>A[i];
    rep(i,0,N-1){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        E[a].pb(b);
        E[b].pb(a);
    }
    rep(i,0,N){
        if(sz(E[i])>1){
            if(dfs(i)&&A[i]==0){
                cout <<"YES"<<"\n";
            }
            else cout <<"NO"<<"\n";
            return 0;
        }
    }
    if(A[0]==A[1]) cout <<"YES"<<"\n";
    else cout <<"NO"<<"\n";
}

Measured memory_bytes: 13312
import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List

getInts :: IO (Int, Int)
getInts = do
  a <- map read . words <$> getLine
  return (a!!0, a!!1)

main :: IO()
main = do
  [n, m] <- map read . words <$> getLine
  tmpab <- replicateM m $ getInts
  let ab = sortOn fst tmpab
  let leftslv = slv (tail ab) (snd (head ab)) 0
  let revab = tmpList n ab []
  putStrLn $ show $ min leftslv $ slv (tail revab) (snd (head revab)) 0

slv :: [(Int, Int)] -> Int -> Int -> Int
slv [] _ ret = ret + 1
slv (a:as) bound ret | fst a >= bound = slv as (snd a) (ret + 1)
                     | otherwise = slv as (min bound (snd a)) ret 

tmpList :: Int -> [(Int, Int)] -> [(Int, Int)] -> [(Int, Int)]
tmpList _ [] ret = sortOn fst ret
tmpList n (a:as) ret = tmpList n as ((n - (snd a - 1), n - (fst a - 1)):ret)

Measured memory_bytes: 147836
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A>B){
        int temp = A-B;
        REP(i,temp){
            B++;
            if(B==C){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    if(B>A){
        int temp = B-A;
        REP(i,temp){
            A++;
            if(A==C){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main() {
	int N;
	int Y;
	int ans[3];
	ans[0]=-1;
	ans[1]=-1;
	ans[2]=-1;
	scanf("%d%d",&N,&Y);
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N-i;j++){
			if(i*10000+j*5000+(N-i-j)*1000==Y){
				ans[0] = i;
				ans[1] = j;
				ans[2] = N-i-j;
			}
		}
	}
	
	for(int i=0;i<3;i++){
		printf("%d ",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline())

m = 10 ** 18 + 7


t_votes, a_votes = (int(x) for x in stdin.readline().split())

p_t, p_a = t_votes, a_votes

for _ in range(n-1):
    t, a = (int(x) for x in stdin.readline().split())
    if (t, a) == (p_t, p_a):
        continue
    for i in range(max(t_votes // t, a_votes // a) - 1, m):
        t_v, a_v = t * i, a * i
        if t_v >= t_votes and a_v >= a_votes:
            break
    t_votes, a_votes = t_v, a_v
    p_t, p_a = t, a

print(t_votes + a_votes)


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

#define MAX 100010

using namespace std;
typedef long long int lli;

int n, m;
int n1;

multiset<int> s;

int main()
{
	scanf("%d %d",&n,&m);

	for(int i = 1 ; i <= n ; i++)
	{
		scanf("%d",&n1);

		s.insert( -n1 );
	}

	for(int i = 1 ; i <= m ; i++)
	{
		int cur = *s.begin();
		s.erase( s.begin() );

		cur = (-cur)/2;

		s.insert( -cur );
	}

	lli ans = 0;

	for(auto it = s.begin() ; it != s.end() ; it++)
		ans -= *it;

	printf("%lld\n",ans);
}

Measured memory_bytes: 4992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		try {
			String buffer[] = br.readLine().split("\\s+");

			int N = Integer.parseInt(buffer[0]);
			int M = Integer.parseInt(buffer[1]);
			int L = Integer.parseInt(buffer[2]);

			int A[][] = new int[N][M];
			int B[][] = new int[M][L];

			String buf_A[] = new String[M];
			String buf_B[] = new String[L];

			for(int row = 0; row < N; row++){
				buf_A = br.readLine().split("\\s+");
				for(int col = 0; col < M; col++){
					A[row][col] = Integer.parseInt(buf_A[col]);
				}
			}

			for(int row = 0; row < M; row++){
				buf_B = br.readLine().split("\\s+");
				for(int col = 0; col < L; col++){
					B[row][col] = Integer.parseInt(buf_B[col]);
				}
			}

			Long ans;

			for(int A_row = 0; A_row < N; A_row++){
				for(int B_col = 0; B_col < L; B_col++){
					ans = 0L;
					for(int B_row = 0; B_row < M; B_row++){
						ans += A[A_row][B_row]*B[B_row][B_col];
					}
					if(B_col == 0){
						System.out.printf("%d", ans);
					}else{
						System.out.printf(" %d", ans);
					}
				}
				System.out.printf("\n");
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}




Measured memory_bytes: 80240
import java.io.*;
import java.math.*;
import java.util.*;
public class Main{ 
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		long N = input.nextLong();
		long K = input.nextLong();
		long ans = K;
		K--;
		N--;
		for (long ball = 1; ball <= N; ball++) {
			ans*=K;
		} 
		System.out.println(ans);
	}
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define F first
#define S second
#define um map <ll,ll>
#define rep(i,z,n)  for(int i=z;i<n;i++)
#define repi(i,z,n) for(int i=z;i<=n;i++)
#define repn(i,z,n) for(int i=n-1;i>=z;i--)
#define vec vector<ll>
#define vecp vector<pair<ll,ll>>
#define pi (double)3.14159265358979323846
#define ld long double
#define all(z) z.begin(),z.end()

ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; if (a == 0) return 0; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }
ll modInverse(ll a, ll m) {return power(a, m - 2, m);}
ll binpow(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll binlog2(ll n) {ll logValue = -1; while (n) {logValue++; n >>= 1;} return logValue;}
void print(vec a) {rep(i, 0, a.size())cout << a[i] << " "; cout << endl;}
const ll mod = 1e9 + 7;
const ll N = 1e5 + 5;
const ll inf = 2e18;




void solve() {
    ll n, w ;
    cin >> n >> w;
    ll tot = 0;
    vecp vp(n);
    rep(i, 0, n) {
        cin >> vp[i].F >> vp[i].S;
        tot += vp[i].S;
    }

    ll dp[n + 1][tot + 1];
    dp[0][0] = 0;
    repi(i, 1, tot)
    dp[0][i] = inf;
    ll ans = 0;
    repi(i, 1, n) {
        repi(j, 0, tot) {
            if (j >= vp[i - 1].S) {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - vp[i - 1].S] + vp[i - 1].F);
            }
            else {
                dp[i][j] = dp[i - 1][j];
            }
            if (dp[i][j] <= w)
                ans = max(ans, (ll) j);
        }
    }

    cout << ans << endl;

}





int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    speed;
    int test = 1;
    // cin >> test;
    while (test--) {
        // cout << "Case #" << t1 << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 82396
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
  static long ans = 0;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long X = sc.nextLong();
    long[] size = new long[N+1];
    long[] meat = new long[N+1];
    size[0] = 1;
    meat[0] = 1;
    for (int i = 0; i < N ; i++) {
      size[i + 1] = 2 * size[i] + 3;
      meat[i + 1] = 2 * meat[i] + 1;
    }
    calc(N, meat, size, X);
    System.out.println(ans);
  }

  static void calc(int n, long[] meat, long[] size, long x) {
    if (1 == x) {
      return;
    } else if (size[n - 1] + 1 > x) {
      calc(n - 1, meat, size, x - 1);
    } else if (size[n - 1] + 1 == x) {
      ans = ans + meat[n - 1];
    } else if (size[n - 1] + 2 == x) {
      ans = meat[n - 1] + 1 + ans;
    } else if (2 * size[n - 1] + 2 > x) {
      ans = ans + meat[n - 1]+1;
      calc(n - 1, meat, size, x - (size[n - 1] + 2));
    } else {
      ans = ans + meat[n];
    }
  }
}


Measured memory_bytes: 25300
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<ll, ll, ll>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

vector<vector<ll>> dijkstra(int s, int sil, vector<vector<T>> &G, vector<int> &c, vector<int> &d){
    int n = G.size();
    sil = min(sil, 2500);
    vector<vector<ll>> dist(55, vector<ll>(2510, INF));
    priority_queue<T, vector<T>, greater<T>> que;
    dist[s][sil] = 0;
    que.emplace(0, s, sil);

    set<int> visited;

    while(que.size()){
        ll ctime, cv, csil;
        tie(ctime, cv, csil) = que.top(); que.pop();

        visited.emplace(cv);

        if(visited.size() == n) break;

        if(dist[cv][csil] < ctime) continue;

        for(auto nxt : G[cv]){
            int nv, ncost, ntime;
            tie(nv, ncost, ntime) = nxt;
            
            // i 回両替する
            for(ll i=0; ; i++){

                if(ncost <= csil + i * c[cv] && dist[cv][csil] + i * d[cv] + ntime < dist[nv][min(2500LL, csil + i * c[cv]) - ncost]){
                    dist[nv][min(2500LL, csil + i * c[cv]) - ncost] = dist[cv][csil] + i * d[cv] + ntime;
                    que.emplace(dist[nv][min(2500LL, csil + i * c[cv]) - ncost], nv, min(2500LL, csil + i * c[cv]) - ncost);
                }
            
                if(2500 < csil + i * c[cv]) break;
            }
        }
    }

    return dist;
}

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

    int n, m, s; cin>>n>>m>>s;
    vector<vector<T>> G(n);
    for(int i=0; i<m; i++){
        int u, v, a, b; cin>>u>>v>>a>>b;
        u--, v--;
        G[u].emplace_back(v, a, b);
        G[v].emplace_back(u, a, b);
    }

    vector<int> c(n), d(n);
    for(int i=0; i<n; i++) cin>>c[i]>>d[i];

    vector<vector<ll>> dist = dijkstra(0, s, G, c, d);

    for(int i=1; i<n; i++){
        ll ans = INF;
        for(int j=0; j<2510; j++) chmin(ans, dist[i][j]);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 53516
// https://atcoder.jp/contests/abc151/tasks/abc151_a
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    char c;
    cin >> c;
    ++c;
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  



void solve(){
	int n ; 
	cin >> n ;
	int x =0  ; 
	vi a(n);
	assert(n>1) ;
	rep(i,0,n){
		cin >> a[i];
		x ^= a[i];
	}
	vi ans(n) ;
	rep(i,0,n){
		ans[i] = a[i] ^ x ;
	}
	trav(i,ans) cout << i << ' ' ;
	cout << endl;
}  

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

class UnionFind{
  public:
    //親の番号を格納．親の場合は-(その集合のサイズ)
    vector<int> Parent;
    //親との距離
    vector<int> Distance;
    //作るときはParentの値をすべて-1にする
    UnionFind(int N){
      Parent = vector<int>(N,-1);
      Distance = vector<int>(N,0);
    }

    //親を求める
    int find(int x){
      if(Parent[x] < 0) return x;
      //親の紐づけを変更
      int p = Parent[x];
      int fp = find(Parent[x]);
      int d = Distance[p];
      if(p != fp) Distance[x] += d; 
      return Parent[x] = find(Parent[x]);
    }

    //xの属する集合のサイズを取ってくる
    int size(int x){
      return -Parent[find(x)];
    }

    //2点間の距離を計算
    //xからみてy
    int getDistance(int x,int y){
      find(x);
      find(y);
      return  Distance[y] - Distance[x];
    }

    //xとyの属する集合を併合
    //併合できたらtrue，すでに併合していたらfalse 
    bool unite(int x, int y, int d){
      //xとyを直接つけない，親同士をつける
      int x_ = find(x);
      int y_ = find(y);
      d += Distance[x] - Distance[y];
      x = x_;
      y = y_;
      if(x==y) return false;

      //大きいほうに小さいほうをくっつける
      if(size(x) < size(y)){
        swap(x,y);
        d *= -1;
      }

      //xのサイズを更新
      Parent[x] += Parent[y];
      Parent[y] = x;
      Distance[y] = d;
      return true;
    }

    //xとyが同じ集合に属するか
    bool same(int x, int y){
      return find(x) == find(y);
    }
};
int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,M;cin >> N >> M;
  UnionFind uni =  UnionFind(N);
  bool isExist = true;
  rep(i,M){
    int L,R,D;cin >> L >> R >> D;
    L--;R--;
    if(uni.same(L,R)){ 
      if(uni.getDistance(L,R) != D){
        isExist = false;
        break;
      }
    } else uni.unite(L,R,D);
  }
  YesNo(isExist);
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <numeric>
using namespace std;
#define MAX_N 200000

template<class T> inline bool chmax(T& a, T b) { if(a < b) {a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if(a > b) {a = b; return true; } return false; }
const long long INF = 1LL << 60;

// Input
long long N, K;
long long A[MAX_N];
int A_hst[MAX_N];

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A_hst[i] = 0;
    // cout << i << "," << A[i] << endl;
  }
  
  int loc = 0;
  int ct = 1;

  int next = A[loc]-1;
  while (ct <= K && A_hst[next] == 0) {
    A_hst[next] = ct;
    // cout << loc << "->" << next << " (" << A_hst[next] << ")" << endl;
    loc = next; //move
    next = A[loc]-1;

    ct++;
  }
//   cout << "Final: " << loc << "->" << next << " (" << A_hst[next] << ")" << endl;
  int T;
  T = ct - A_hst[next];
//   cout << loc << "," << T << " (" << A_hst[next] << ")" << endl;

  int ans_hosei = A_hst[next];
  int amari = (K - ans_hosei) % T;
  int ans;
  if (K < ans_hosei + T) {
    ans = K;
  } else {
    ans = amari + ans_hosei;
  }

//   printf("ct: %d, amari: %d, ans_hosei: %d, ans: %d\n", ct, amari, ans_hosei, ans);
  int ans_loc = -1;
  for (int i = 0; i < N; i++) {
    // cout << i << "->" << A[i]-1 << " (" << A_hst[A[i]-1] << ")" << endl;
    // cout << i << " (" << A_hst[i] << ")" << endl;
    if (A_hst[i] == ans) {
      ans_loc = i;
    }
    
  }
  
//   cout << ans_loc << "," << A[ans_loc] << "," << A_hst[ans_loc] << endl;
  cout << ans_loc + 1 << endl;
}


Measured memory_bytes: 5976
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int judge(int);
int main(){

  int n,i,cnt=0,*a;

  scanf("%d",&n);
  a=(int *)malloc(sizeof(int)*n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(judge(a[i])==1) cnt++;
  }
  free(a);
  printf("%d\n",cnt);
  return 0;
}

int judge(int a){
  int i;

  if(a==2) return 1;
  for(i=3;i<=(int)sqrt(a);i+=2){
    if(a%i==0) return 0;
  }
  if(a%2==0) return 0;
  return 1;
}
    

Measured memory_bytes: 2696
#include <iostream>
using namespace std;
string s[5];
int p, x[5];
int main() {
	cin>>s[0]>>s[1]>>s[2];
	while(s[p][x[p]]) p = s[p][x[p]++] -'a';
	cout<<char(p+'A');
	return 0;
}


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

const long double pi=3.14159265359;

int main()
{
 int t=1;
 //cin>>t;
 while(t--)
 {int n;
  cin>>n;
  vector<vector<int>> v(n+1);
  int x;
  for(int i=2;i<=n;i++){
      cin>>x;
      v[x].push_back(i);
  }
  for(int i=1;i<=n;i++)
  cout<<v[i].size()<<endl;
 }
 return 0;
}


Measured memory_bytes: 14028
n, a, b = gets.chomp.split.map(&:to_i)

def sum_of_digit(n)
  ans = 0
  while n > 0
    ans += n % 10
    n /= 10
  end
  ans
end

ans = 0
(1..n).to_a.each do |i|
  sod = sum_of_digit(i)
  ans += i if a <= sod && sod <= b
end

puts ans


Measured memory_bytes: 1916
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

void run() {
  i64 n, x, m;
  cin >> n >> x >> m;
  vector<i64> i_pre(m, -1);
  vector<i64> ret_pre(m, 0);
  i64 i{0};
  i64 ret{0};
  x %= m;
  while(0 < n){
    --n;
    i_pre[x] = i++;
    ret_pre[x] = ret;
    ret += x;
    x = (x*x)%m;
    if(0 <= i_pre[x]){
      i64 w{i - i_pre[x]};
      ret += (ret - ret_pre[x])*(n/w);
      n %= w;
    }
  }
  cout << ret << endl;
}

int main() {
  cin.tie(nullptr);
  run();
  return 0;
}


Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    int n, m, x;
    cin>>n>>m>>x;
    int c[22];
    int a[22][22];
    for (int i = 0; i < n; i++) {
        cin>>c[i];
        for (int j = 0; j < m; j++) {
            cin>>a[i][j];
        }
    }
    int mn = INF;
    for (int i = 0; i < pow(2, n); i++) {
        int v[22] = {};
        int money = 0;
        for (int j = 0; j < n; j++) {
            if (i >> j & 1) {
                money += c[j];
                for (int k = 0; k < m; k++) {
                    v[k] += a[j][k];
                }
            }
            bool flag = true;
            for (int k = 0; k < m; k++) {
                if (v[k] < x) flag = false;
            }
            if (flag) mn = min(mn, money);
        }
    }
    if (mn == INF) cout<<-1<<endl;
    else cout<<mn<<endl;
}

Measured memory_bytes: 4104
#include<stdio.h>

int main(void){
  int n, a[1000], i;
  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%d", &a[i]);    
  }

  for(i=n-1;i>-1;i--){
    if(i<n-1) printf(" ");
    printf("%d" ,a[i]);
  }

  printf("\n");
  
  return 0;  
  
}


Measured memory_bytes: 2668
#include<bits/stdc++.h>
using namespace std;
int main ( void ) {
	string s;
	cin>>s;
	bool flag=0;
	for(int i=0;i<=s.length();i++){
		if(flag){
			puts("No");
			return 0;
		}
		else if ( ( i + 1 ) % 2 == 1 ) {
			if ( s[i] == 'R' || s[i] == 'U' || s[i] == 'D' ) 
				continue;
			else 
				flag = 1;
		}
		else {
			if ( s[i] == 'L' || s[i] == 'U' || s[i] == 'D' ) 
				continue;
			else 
				flag = 1;
		} 
	}	
	puts ( "Yes" );
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
int main(){
    double x[3][2],a,b,c;
    rep(i,3)rep(j,2) cin>>x[i][j];
    a=sqrt((x[0][0]-x[1][0])*(x[0][0]-x[1][0])+(x[0][1]-x[1][1])*(x[0][1]-x[1][1]));
    b=sqrt((x[1][0]-x[2][0])*(x[1][0]-x[2][0])+(x[1][1]-x[2][1])*(x[1][1]-x[2][1]));
    c=sqrt((x[2][0]-x[0][0])*(x[2][0]-x[0][0])+(x[2][1]-x[0][1])*(x[2][1]-x[0][1]));
    double d=max({a,b,c}),e=min({a,b,c}),f=a+b+c-d-e;
    a=d,b=e,c=f;
    double cosB=(a*a+c*c-b*b)/(2*a*c),cosC=(a*a+b*b-c*c)/(2*a*b);
    double tanB2=sqrt((1-cosB)/(1+cosB)),tanC2=sqrt((1-cosC)/(1+cosC));
    double ans=a/(2+1/tanB2+1/tanC2);
    cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Long N = sc.nextLong();
    Long K = sc.nextLong();
    Long ans = N % K;
    if(ans > (K-ans)){
      System.out.println(K-ans);
      return;
    }
    
    System.out.println(ans);
    return;
  }
}


Measured memory_bytes: 23124
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w = map(int, input().split())
rows,cols = h,w

OK = "."
NG = "#"

from collections import defaultdict

ns = defaultdict(set)
ss = [None] * rows
for i in range(rows):
    s = input()
    ss[i] = s
    for j,c in enumerate(s):
        u = i*cols+j
        if i>0:
            if c==OK and ss[i-1][j]==OK:
                v = u - cols
                ns[u].add(v)
                ns[v].add(u)
        if j>0:
            if c==OK and s[j-1]==OK:
                v = u - 1
                ns[u].add(v)
                ns[v].add(u)
                    
n = rows * cols

def bfs(start):
    from queue import deque
    q = deque([start])
    seen = [None] * n
    seen[start] = 0
    while q:
        u = q.pop()
        d = seen[u]
        for v in ns[u]:
            if seen[v] is None:
                seen[v] = d + 1
                q.appendleft(v)
    return seen
ans = -1
for i in range(rows):
    for j in range(cols):
        if ss[i][j] == "#":
            continue
        u = i*cols+j
        dist = bfs(u)
        ans = max(ans, max(num for num in dist if num is not None))
print(ans)

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

string s[1000];
bool f[1000];
//ind行目の階層を求める
int level(int ind)
{
	int ret=0;
	for(int i=0;i<s[ind].size();i++)
	{
		if(!(s[ind][i]=='.' || s[ind][i]=='|' || s[ind][i]=='+'))
			break;
		ret++;
	}
	return ret;
}


int main()
{
	int n;
	while(1)
	{
		cin>>n;
		if(n==0)
			break;
		for(int i=0;i<1000;i++)
			s[i].clear();
		for(int i=0;i<n;i++)
			cin>>s[i];
		fill(f,f+1000,false);
		//ペアを探す
		for(int i=1;i<n;i++)
		{
			if(f[i])
				continue;
			int kai=level(i);
			int next=i;
			for(int j=i;j<n;j++)
			{
				if(level(j)<kai)
					break;
				else if(level(j)==kai){
					f[j]=true;
					s[j][kai-1]='+';
					next=j;
				}
			}
			//|をつける
			for(int j=i;j<next+1;j++)
			{
				if(s[j][kai-1]!='+')
					s[j][kai-1]='|';
			}
		}
		//'.'を除く
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<s[i].size();j++)
			{
				if(s[i][j]=='.')
					s[i][j]=' ';
			}
		}
		//output
		for(int i=0;i<n;i++)
			cout<<s[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3804
// Problem : B - Comparing Strings
// Contest : AtCoder Beginner Contest 152
// URL : https://atcoder.jp/contests/abc152/tasks/abc152_b
// Memory Limit : 1024,000000 MB 
// Time Limit : 2000,000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <cmath>
#include <cstdio>

#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <map>
#include <set>
#include <vector>

using namespace std;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int a;
int b;

void input() {
  cin >> a >> b;
}

void solve1() {
  if (a > b)
    swap(a, b);
    
  cout << string(b, a + '0');
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve1();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	IOS;
	int n, q;
	cin >> n >> q;
	vector<int> a(n),b(n,0);
	vector<ll> se((n + 1) / 2 + 1, 0), so(n / 2 + 1, 0), s(n + 1, 0), res(q, 0);
	REP(i, n) {
		cin >> a[i];
		b[i] = a[i];
		if (i % 2 == 0) {
			se[i / 2 + 1] = se[i / 2] + a[i];
		} else {
			so[i / 2 + 1] = so[i / 2] + a[i];
		}
		s[i + 1] = s[i] + a[i];
	}
	reverse(all(b));
	REP(i, n) {
		b.push_back(0);
	}
	REP(i, q) {
		int x;
		cin >> x;
		int lb = -1, ub = n-1;
		while (ub - lb > 1) {
			int mid = (lb + ub) / 2;
			if (b[mid] + b[mid * 2] < 2 * x) {
				ub = mid;
			} else {
				lb = mid;
			}
		}
		int l = ub;
		ll temp = 0;
		if (l * 2 >= n) {
			temp += s[n / 2];
		} else {
			temp += s[n - l] - s[n - l * 2];
			if (n % 2 == 0) {
				temp += se[(n - l * 2) / 2];
			} else {
				temp += so[(n - l * 2) / 2];
			}
		}
		res[i] = s[n] - temp;
	}
	REP(i, q) {
		put(res[i]);
	}
	return 0;
}


Measured memory_bytes: 5240
#include<bits/stdc++.h>
using namespace std;
int main()
{

	int n,k,i,j;
	cin>>n>>k;
	int a[n+1],dp[n+1];
	for(i=1;i<=n;i++)
		 cin>>a[i];
	dp[1]=0;
	dp[2]=abs(a[2]-a[1]);
	for(i=3;i<=n;i++)
		 dp[i]=	INT_MAX;
	for(i=3;i<=n;i++)
	  {
	  	for(j=1;j<=k;j++)
	  		 {
	  		 	if(i-j>=1)
	  		 	dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
	  		   else
	  		   	 break;
	  		 }
	  }	
	  cout<<dp[n]<<endl;

}


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

void no() { printf("0\n"); exit(0); }
void win(ll x) { printf("%lld\n", x); exit(0); }

int main(){
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	if (a > b)no();
	if (n == 1){
		if (a == b)win(1);
		no();
	}
	win((ll)(n - 2) * b - (ll)(n - 2) * a + 1);
}

Measured memory_bytes: 256
import numpy as np

def main():
    with open(0) as f:
        N, C = map(int, f.readline().split())
        Rec = [tuple(map(int, f.readline().split())) for _ in range(N)]
    
    time_line_by_channel = np.array([[0] * (10**5+1) for _ in range(C+1)])
    #チャンネルごとにタイムラインを作成
    for s, t, c in Rec:
        time_line_by_channel[c, s-1:t] = 1
    #タイムライン結合
    joined_timeline = np.sum(time_line_by_channel, axis=0)
    ans = max(joined_timeline)
    print(ans)

main()


Measured memory_bytes: 88868
#include <cstdio>
#include <algorithm>

const int MAXN = 3005;

int a[MAXN];
long long f[MAXN][MAXN];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

    for (int i = 1; i <= n; i++) f[i][i] = a[i];
    for (int len = 2; len <= n; len++) for (int l = 1; l + len - 1 <= n; l++) {
        int r = l + len - 1;
        f[l][r] = std::max(a[l] - f[l + 1][r], a[r] - f[l][r - 1]);
    }

    printf("%lld\n", f[1][n]);
    
    return 0;
}

Measured memory_bytes: 69888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

ll gcd(ll i, ll j) { return i % j ? gcd(j, i % j) : j; }

int main() {

	int n;
	cin >> n;
	int g;
	rep(i, n) {
		int a;
		cin >> a;
		if (!i)g = a;
		else g = gcd(g, a);
	}
	cout << g << endl;
}

Measured memory_bytes: 3604
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        x: usize,
        y: usize,
    }

    for i in 0..=x {
        if i * 2 + (x-i) * 4 == y {
            println!("Yes");
            return;
        }
    }
    println!("No");
}

Measured memory_bytes: 2200
n = int(input())

def f(lst):
  res = 0
  ex = 0
  for a in lst:
    ex += a
    res += ex//2
    ex %= 2
  return res

A = []
ans = 0
for _ in range(n):
  a = int(input())
  if a%2:
    ans += a//2
    a = 1
  else:
    if a>2:
      ans += a//2-1
      a = 2

  if a!= 0:
    A.append(a)
  elif A:
    ans += max(f(A), f(A[::-1]))
    A = []
  else:
    continue
else:
  ans += max(f(A), f(A[::-1]))
print(ans)



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

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

  string s; cin >>s;
  bool a = false;
  bool b = false;

  if(s[0] == 'A') a = true;
  if(s[0] == 'B') b = true;
  if(s[1] == 'A') a = true;
  if(s[1] == 'B') b = true;
  if(s[2] == 'A') a = true;
  if(s[2] == 'B') b = true;

  if(a && b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    6月で水色になるぞ〜!!!
*/

// from std...
use std::cmp::{
    max, min,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, Integer};
use num_rational::Rational;
use num_traits::{clamp, one, pow, zero, One, Pow, Zero};
use permutohedron::Heap;
use petgraph::unionfind::UnionFind;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

pub const MOD: usize = 1000000007;
pub const MAX: usize = 1usize << 63usize;
pub const MIN: i64 = i64::MIN;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 'A' as u8;

/// ランレングス圧縮
pub fn run_length_encoding<T: PartialEq + Copy>(v: &Vec<T>) -> Vec<(T, usize)> {
    let mut res = Vec::new();
    let mut c = 1usize;
    let mut h = v[0];
    for e in v.iter().skip(1) {
        if h != *e {
            res.push((h, c));
            c = 1;
            h = *e;
        } else {
            c += 1;
        }
    }
    res.push((h, c));

    res
}

// code...
// #[fastout]
fn main() {
    input! {
        n: usize, m: usize,
        a: [usize; n]
    }

    let mut h = a.into_iter().collect::<BinaryHeap<_>>();

    for _ in 0..m {
        let mut e = h.peek_mut().unwrap();
        *e /= 2;
    }

    let ans = h.into_iter().sum::<usize>();
    println!("{}", ans);
}


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

int main(){
	int N,M,P;

	while(1){
		cin >> N >> M >> P;
		if ((N == 0)&&(M == 0)&&(P == 0)){
			break;
		}

		double A[N];
		double sum = 0;
		double num = 0;
		double money;
		for (int i = 1; i <= N; i++){
			cin >> A[i];
			sum += A[i]*100;
			if (i == M){
				num = A[i];
			}
		}
		
		money = (sum*(100 - P)/100)/num;
		//cout << M << " " << num << " " << sum << " " << money << " " << P << endl;

		if (num == 0){
			cout << 0 << endl;
		} 
	else if (num != 0){
		cout << (int)money << endl;
	 }
	}
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
 
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
const int MOD = 1e9+7;
// const int MOD  = 998244353;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
// struct custom_hash {
//     static uint64_t splitmix64(uint64_t x) {
//         // http://xorshift.di.unimi.it/splitmix64.c
//         x += 0x9e3779b97f4a7c15;
//         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//         return x ^ (x >> 31);
//     }
 
//     size_t operator()(uint64_t x) const {
//         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
//         return splitmix64(x + FIXED_RANDOM);
//     }
// };
// ll gcd(ll a, ll b) { 
//     if (a == 0) return b; 
//     return gcd(b % a, a); 
// }
// ll mod(ll x) {
//  x%=MOD;
//  if(x<0)x+=MOD;
//  return x;
// }
// ll power(int base, int power) {
//  ll prod = 1;
//  ll b = base;
//  while(power) {
//      if (power & 1) {
//          prod = mod(prod*b);
//      }
//      b = mod(b*b);
//      power/=2;
//  }
//  return prod;
// }
// struct line {
//     int m, c;
//     ll eval(int x) { return 1LL * m * x + c; }
//     double intersectX(line l) { return (double) (c - l.c) / (l.m - m); }
// double degToRad(double x) {
//  return x * PI / 180;
// }
// double area(int a, int b, int c, int d, int e, int f) {
//  return abs(0.5*(a*(d-f)+c*(f-b)+e*(b-d)));
// }
int n,dist[250000];
bool removed[250000];
void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            dist[i*n+j] = min(min(i,j),min(n-1-i,n-1-j));
        }
    }
    int cnt = 0;
    queue<int> q;
    for (int i = 0,p; i < n * n; i++) {
        cin >> p;
        --p;
        cnt += dist[p];
        removed[p] = true;
        q.push(p);
        while(!q.empty()) {
            int cur = q.front();
            q.pop();
            int tmp = dist[cur]+!removed[cur];
            if (cur/n>0&&dist[cur-n]>tmp) {
                dist[cur-n] = tmp;
                q.push(cur-n);
            }
            if (cur/n<n-1&&dist[cur+n]>tmp) {
                dist[cur+n] = tmp;
                q.push(cur+n);
            }
            if (cur%n>0&&dist[cur-1]>tmp) {
                dist[cur-1] = tmp;
                q.push(cur-1);
            }
            if (cur%n<n-1&&dist[cur+1]>tmp) {
                dist[cur+1] = tmp;
                q.push(cur+1);
            }
        }
    }
    cout << cnt << endl;
}
int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1;
    // cin >> t;
    for (int i = 1; i <= t; i++) { 
        // cout << "Case #" << i << " :";
        solve();
    }
}

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


int main() {
    string s;
    cin >> s;
    s += "$";
    int pos = 0;
    ll ans = 0;
    while(s[pos] != '$'){
        int a = 0;
        while(s[pos] == '<'){
            ++pos;
            ++a;
        }
        int b = 0;
        while(s[pos] == '>'){
            ++pos;
            ++b;
        }
        ll c = min(a,b), d = max(a,b);
        ans += c*(c-1)/2;
        ans += d*(d+1)/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 900
def main():
    n, m, c = map(int, input().split())
    b = list(map(int, input().split()))
    a = []

    cnt = 0
    for i in range(n):
        a.append(list(map(int, input().split())))

    for i in range(n):
        ans = 0
        for k in range(m):
            ans += a[i][k] * b[k]
        if ans + c > 0:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9092
#include<algorithm> 
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
ll v4=0,v2=0,v14=0,v24=0,v74=0;
bool is_prime(int x){
	if(x==1) return false;
	for(int i=2;i*i<=x;i++){
		if(x%i==0){
			return false;
		}
	}
	return true;
}
ll C(int m,int n){
	if(m<n) return 0;
	ll sum=1;
	for(int i=0;i<n;i++){
		sum*=m-i;
	}
	for(int i=2;i<=n;i++){
		sum/=i;
	}
	return sum;
}
int main(){
/*
c=p1^a1*p2^a2*……*pn^an(pi为各个质因数，ai为他们的次数) 
一个数的因数个数=(a1+1)(a2+1)……(an+1) 
所以因数有75个的数的情况：
1.
75=3*25 (2,24)
2.
75=3*5*5(2,4,4)
3.
75=5*15 (4,14)
4.
75=75   (74)

案例:n=10
 32400=2^8*3^4*5^2*7
*/
	ll n;
	int count[101];//count表示n!里面各个质因数出现的次数 
	cin>>n;
	memset(count,0,sizeof(count));
	for(int i=2;i<=n;i++){
		int t=i;
		for(int j=2;j<=t;j++){
			if(is_prime(j) && t%j==0 && t>1){
				count[j]++;
				t/=j;
				j--;
			}
		}
	}
	for(int i=2;i<=n;i++){
		if(is_prime(i)){
			if(count[i]>=2){
				v2++;
			}
			if(count[i]>=4){
				v4++;
			}
			if(count[i]>=14){
				v14++;
			}
			if(count[i]>=24){
				v24++;
			}
			if(count[i]>=74){
				v74++;
			}
		}
	}
	ll ans=0;
	ans=v74+(v4-v14)*v14+(v14-1)*v14+v24*(v2-v24)+(v24-1)*v24+C(v4,2)*(v2-v4)+C(v4-1,2)*v4;
	cout<<ans<<"\n";
	return 0;
}


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

using  namespace std;

#define FOR(x,z,y) for(int x = z; x < y; x++)
typedef long long ll;
typedef pair<int,int> iPair;




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

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int ARRAYSIZE = 100001;
int main() {
    
    int n;
    cin >> n;
    
    int cnt[2][ARRAYSIZE] = {};
    for (int i = 0; i < n; i++) {
        int v;
        cin >> v;
        cnt[i % 2][v]++;
    }
    
    int maxn[2] = {0, 0};
    int maxv[2] = {-1, -1};
    int secn[2] = {0, 0};
    int secv[2] = {-1, -1};
    for (int v = ARRAYSIZE; v--;) {
        for (int i = 2; i--;) {
            if (maxn[i] < cnt[i][v]) {
                maxn[i] = cnt[i][v];
                maxv[i] = v;
            }
        }
    }
    for (int v = ARRAYSIZE; v--;) {
        for (int i = 2; i--;) {
            if (secn[i] < cnt[i][v] && maxv[i] != v) {
                secn[i] = cnt[i][v];
                secv[i] = v;
            }
        }
    }
    
    if (maxv[0] != maxv[1])
        cout << n - maxn[0] - maxn[1] << endl;
    else
        cout << n - max(maxn[0] + secn[1], maxn[1] + secn[0]) << endl;
    
}

Measured memory_bytes: 1024
n, m, l = map(int, input().split())
A = [[0]*m for i in range(n)]
B = [[0]*l for i in range(m)]
C = [[0]*l for i in range(n)]

for i in range(n):
    A[i] = list(map(int, input().split()))
    
for i in range(m):
    B[i] = list(map(int, input().split()))
    
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for i in range(n):
    print("%d" %C[i][0], end="")
    for j in range(1, l):
        print(" %d" %C[i][j], end="")
    print()


Measured memory_bytes: 7068
right = 'yuiophjklnm'
while True:
    S = input()
    if S == '#': break
    ans = 0
    for c1,c2 in zip(S,S[1:]):
        h1 = c1 in right
        h2 = c2 in right
        if h1 != h2: ans += 1
    print(ans)

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

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int cnt = 0;
      for(int i = 1; i <= n; i++) {
        int digit = numDigit(i);
        if(digit % 2 == 1)
          cnt++;
      }
      System.out.println(cnt);
  }

  private static int numDigit(int n) {
    int cnt = 0;

    while(n > 0) {
      cnt++;
      n /= 10;
    }
    return cnt;
  }
}

Measured memory_bytes: 21972