akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int n,seat[100001];
int ans,l,r;
void calc(int s,int e)
{
	for(int kk=s;kk<=e;kk++)
	{
		if(seat[kk]==0)
		{
			seat[kk]=1;
			ans++;
		}
	}
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>l>>r;
		calc(l,r);
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M; cin >> N >> M;
    vl cnt(N+1, 0);
    REP(i, M){
        ll l,r; cin >> l >> r;
        l--;r--;
        cnt[l]++; cnt[r+1]--;
    }
    vl sum(N, 0); ll s = 0;
    REP(i, N){
        s += cnt[i];
        sum[i] = s;
    }
    ll ans = 0;
    REP(i, N) if(sum[i] == M) ans++;
    cout << ans << endl;
    return 0;
}


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

int tag[531441];

void solve(int n,const string& T,vector<int> &perm,vector<int> &pos){
	if(n==0){
		perm={0};
		pos=vector<int>(T.size(),0);
		return;
	}
	vector<int> pe,po;
	solve(n-1,T,pe,po);
	pos.resize(T.size());
	perm.resize(pe.size()*3);
	vector<int> msb;
	for(int i=0;i<3;i++)
		for(int j=0;j<pe.size();j++)
			msb.emplace_back(i);
	memset(tag,0,sizeof tag);
	int t=0;
	for(int i=0;i<T.size();i++){
		for(int j=po[i];j<msb.size();j+=pe.size()){
			if(tag[j]%2!=t%2)	if(msb[j])	msb[j]=3-msb[j];
			tag[j]=t;
			if(msb[j]==2)	pos[i]=j;
		}
		if(T[i]=='S')	t++;
		else{
			for(int j=po[i];j<msb.size();j+=pe.size())
				msb[j]=(msb[j]+1)%3;
		}
	}
	for(int i=0;i<perm.size();i++){
		if(tag[i]%2!=t%2)	if(msb[i])	msb[i]=3-msb[i];
		perm[i]=msb[i]*pe.size()+pe[i%pe.size()];
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string T;
	cin>>n>>T;
	vector<int> perm,pos;
	solve(n,T,perm,pos);
	for(int it:perm)	cout<<it<<' ';
	cout<<endl;
}


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int n;
    cin>>n;
    vector<ll> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ll tmp=abs(v[i]-v[j]);
            ans=max(ans,tmp);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define ll long long int
ll mod=1e9+7;

// vector<ll> g[200005];
// ll vis[200005];
// queue<ll> q;
// ll level[200005];

// void dfs(ll i)
// {
//     vis[i] = 1;
//     for(ll j=0;j<g[i].size();j++)
//     {
//         ll child = g[i][j];
//         if(vis[child] == 0)
//         {
//             dfs(child);
//         }
//     }
// }

// void bfs(ll i)
// {
//     vis[i] = 1;
//     while(!q.empty())
//     {
//         ll top = q.front();
//         ll len_adj = g[top].size();
//         ll j;
//         for(j=0;j<len_adj;j++)
//         {
//             ll v = g[top][j];
//             if(vis[v]==0)
//             {
//                 vis[v]=1;
//                 q.push(v);
//                 level[v] = level[top] + 1;
//             }
//         }   
//         q.pop();
//     }
// }

vector<ll> DecToBinary(ll num,ll trailing_zero, ll nbits)
{
    vector<ll> bits;
    while(num > 0)
    {
        bits.push_back(num%2);
        num /= 2;
    }

    if(trailing_zero == 1)
    {
        while(bits.size() < nbits)
        {
            bits.push_back(0);
        }
    }

    return bits;
}

long long int BinaryToDec(vector<ll> bits)
{
    ll number = 0;
    ll i;
    for(i=bits.size()-1;i>=0;i--)
    {
        number += (bits[i] * (long long)pow((ll)2 , i));
    }
    return number;
}

ll modular_exponentiation(ll base, ll power)
{
    ll ans = 1;
    base = base % mod;
    while (power > 0)
    {
        if (power & 1)
        {
            ans = (ans * base) % mod;
        }

        power /= 2;
        base = (base * base) % mod;
    }
    return ans;
}

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ll t = 1;
    // cin >> t;
    while(t--)
    {        
        ll n,i,j;
        cin >> n;
        ll arr[n];
        
        ll xo;
        for(i=0;i<n;i++)
        {
            cin >> arr[i];
            if(i == 0)
            {
                xo = arr[i];
            }
            else
            {
                xo = arr[i]^xo;
            }
        }

        for(i=0;i<n;i++)
        {
            ll ans = xo^arr[i];
            cout << ans << " ";
        }
        cout << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 5140
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

bool guru[110][110];

int main() {
	int d=in();
	int n;
	bool first=true;
	while(d--){
		if(!first)cout<<endl;
		first=false;
		cin>>n;
		int i,j;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				guru[i][j]=false;
			}
		}
		int len=n;
		for(i=0;i<n;i++){
			guru[i][0]=true;
		}
		while(1){
			for(i=0;i<len;i++){
				guru[(n-len)/2][i+(n-len)/2]=true;
			}
			if(len<3)break;
			for(i=0;i<len;i++){
				guru[i+(n-len)/2][n-1-(n-len)/2]=true;
			}
			len-=2;
			for(i=0;i<len;i++){
				guru[n-1-(n-len-2)/2][n-(n-len)/2-i]=true;
			}
			if(len<3)break;
			for(i=0;i<len;i++){
				guru[n-(n-len)/2-i][(n-len-2)/2+2]=true;
			}
			len-=2;
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(guru[i][j])cout<<"#";
				else cout<<" ";
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
struct edge{long long to,cost;};
typedef pair<int,int>P;
#define inf 1000000007
string alph("abcdefghijklmnopqrstuvwxyz");
signed main(){
    int n,m;cin>>n>>m;
    if(n%m==0)cout<<-1<<endl;
    else cout<<n<<endl;
    return 0;
}



Measured memory_bytes: 256
def main():
    s = input().strip()
    if len(s) < 26:
        for i in range(ord('a'), ord('z') + 1):
            c = chr(i)
            if c not in s:
                print(s + c)
                return
    for i in range(24, -1, -1):
        c = s[i]
        ss = s[:i]
        for j in range(ord(c) + 1, ord('z') + 1):
            cc = chr(j)
            if cc not in ss:
                print(ss + cc)
                return
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1046527;
const int NIL=-1;
char H[mod][15];
int n,h;
char str[105],com[15];
int getC(char x)
{
    if(x=='A')
        return 1;
    if(x=='C')
        return 2;
    if(x=='G')
        return 3;
    if(x=='T')
        return 4;
    return 0;
}
ll getK(char str[])
{
    ll ant=0,p=1;
    for(int i=0;i<strlen(str);i++)
    {
        ant+=p*(getC(str[i]));
        p*=5;
    }
    return ant;
}
int h1(int key)
{
    return key%mod;
}
int h2(int key)
{
    return 1+(key%(mod-1));
}
int findd(char str[])
{
    ll key,h;
    key=getK(str);
    for(ll i=0;;i++)
    {
        h=(h1(key)+i*h2(key))%mod;
        if(strcmp(H[h],str)==0)
            return 1;
        else if(strlen(H[h])==0)
            return 0;
    }
    return 0;
}
int ins(char str[])
{
    ll key,h;
    key=getK(str);
    for(ll i=0;;i++)
    {
        h=(h1(key)+i*h2(key))%mod;
        if(strcmp(H[h],str)==0)
            return 1;
        else if(strlen(H[h])==0)
            {
                strcpy(H[h],str);
                return 0;
            }
    }
    return 0;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<mod;i++)
    {
        H[i][0]='\0';
    }
    for(int i=0;i<n;i++)
    {
        scanf("%s %s",com,str);
        if(com[0]=='i')
            ins(str);
        else
        {
            if(findd(str))
                printf("yes\n");
            else
                printf("no\n");
        }
    }
    return 0;
}



Measured memory_bytes: 18496
#include <bits/stdc++.h>
#define double long double
#define int long long
#define inf 1000000007 
#define sort(vec) sort(vec.begin(),vec.end());
#define rever(vec) reverse(vec.begin(),vec.end());
#define unsort(vec) sort(vec); rever(vec);
#define rep(i,n) for(int i=0;i<n;i++)
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
	int h,w;
	cin>>h>>w;
	char tab[h][w];
	rep(i,h) {
		string s;
		cin>>s;
		rep(j,w) {
			tab[i][j]=s[j];
		}
	}
	int a[8]={1,1,1,0,-1,-1,-1,0},b[8]={-1,0,1,1,1,0,-1,-1};
	rep(i,h) {
		rep(j,w) {
			int cnt=0;
			rep(k,8) {
				int nx=i+a[k],ny=j+b[k];
				if(0<=nx&&nx<h&&0<=ny&&ny<w) {
					if(tab[nx][ny]=='#') cnt++;
				}
			}
			if(tab[i][j]=='.') {
				tab[i][j]=to_string(cnt)[0];
			}
			cnt=0;
		}
	}
	rep(i,h) {
		rep(j,w) {
			cout<<tab[i][j];
		}
		cend;
	}					
}
	


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

ll dp[2001][2001] = {};

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  int n;cin>>n;
  vector<pair<ll, int>> A(n);
  rep(i,n){
    ll a;cin>>a;
    A[i] = {a, i};
  }
  sort(all(A));
  reverse(all(A));
  ll ans = 0;
  
  rep(i,n){
    ll a = A[i].first;
    int idx = A[i].second;
    rep(j,i+1){
      chmax(dp[i+1][j+1], dp[i][j] + abs(j - idx) * a);
      chmax(dp[i+1][j], dp[i][j] + abs(n - 1 - i + j - idx) * a);
    }
  }
    rep(j,n+1){
      chmax(ans, dp[n][j]);
    }
    cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 26272
# solution

import io
import math
import scipy.sparse
import numpy

nim, mike = map(int, input().split())
array = [list(map(int, input().split())) for i in range(nim)]

answer = 10**100
sortx = sorted(array, key = lambda x: x[0])
for a, pt1 in enumerate(sortx[:nim-mike+1]):
    for b, pt2 in enumerate(sortx[a+mike-1:]):
        #print(a,b)
        sorty = sorted(sortx[a:a+mike+b], key = lambda x: x[1])
        sorty_len = len(sorty)
        for c, pt3 in enumerate(sorty[:sorty_len-mike+1]):
            #print(len(sorty), c, k)
            pt4 = sorty[c+mike-1]
            #print(pt1, pt2, pt3, pt4)
            if pt3[1] <= pt1[1] and pt3[1] <= pt2[1] and pt4[1] >= pt1[1] and pt4[1] >= pt2[1]:
                answer = min(answer, (pt2[0] - pt1[0]) * (pt4[1] - pt3[1]))
print(answer)

Measured memory_bytes: 13632
<?php

(new Main)->execute();

class Main
{
    public function execute()
    {
        $house = new House();
        $n = getInput();
        for ($i = 0; $i < $n; $i++) {
            fscanf(STDIN, '%d %d %d %d', $b, $f, $r, $v);
            $house->put($b, $f, $r, $v);
        }
        $tenant = $house->merge();
        echo $house->merge2($tenant);
    }
}

class House
{
    private $rooms;
    private $floors;
    private $buildings;
    
    public function __construct()
    {
        $this->rooms     = array_fill_keys(range(1, 10), 0);
        $this->floors    = array_fill_keys(range(1, 3), $this->rooms);
        $this->buildings = array_fill_keys(range(1, 4), $this->floors);
    }
    
    public function put($b, $f, $r, $v)
    {
        $this->buildings[$b][$f][$r] += $v;
    }
    
    public function merge()
    {
        foreach ($this->buildings as $floors) {
            $floor = array();
                foreach ($floors as $rooms) {
                    $floor[] = sprintf(' %s%s', implode(' ', $rooms), PHP_EOL);
            }
        $tenant[] = implode('', $floor);
        
        }
        return $tenant;
    }
    
    public function merge2($tenant)
    {
        return implode(str_repeat('#', 20) . "\n", $tenant);
    }
}

function getInput()
{
    return trim(fgets(STDIN));
}

Measured memory_bytes: 15592
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
    

    
    ll m, d;
    cin >> m >> d;
    
    ll ret = 0;
    for (int i = 1; i <= m; ++i)
    {
        for (int j = 1; j <= d; ++j)
        {
            ll d1 = j % 10;
            ll d10 = j / 10;
            if (d1 * d10 == i && d1 >= 2 && d10 >= 2)
            {
                ret++;
            }
        }
    }
    
    cout << ret << endl;
    

    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
using namespace std;

int n;

                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>n;
  ll ans=0;
  for(int i=0;i<n;i++){
    ll a,b;cin>>a>>b;
    ans+=b-a+1;
  }
  cout<<ans<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_set>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
	string s;
	cin >> s;
	if (s == "AAA" or s == "BBB")cout << "No" << endl;
	else cout << "Yes" << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main { 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) {
			values[i] = i + 1; 
			} 
		for (int i = 0; i < n; i++) {
			int x=0;
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			x=values[a];
			values[a]=values[b];
			values[b]=x;
			} 
		for(int i = 0; i<w;i++){
			System.out.println(values[i]);
		}
		}
	}

Measured memory_bytes: 26272
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
	double p;
	int n;
	std::cin>>n;

	std::vector<double> v(n);
	for (double& x : v) {
		std::cin >> x;
	}

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

	p = (v[0]+v[1])/2.0;

	for (int i = 2; i < n; i++) {
		p = (p + v[i]) / 2;
	}

	std::cout<<p<<std::endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	list := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&list[i])
	}

	total := 0
	for i := 0; i < n; i++ {
		if list[i] > k-list[i] {
			total += 2 * (k - list[i])
		} else {
			total += 2 * (list[i])
		}

	}
	fmt.Println(total)
}


Measured memory_bytes: 512
import java.util.*;
import java.lang.Math;
public class Main{
        public static void main(String[]args){
                Scanner scan = new Scanner(System.in);
                long n = scan.nextLong();
                long t = (long)Math.sqrt((double)n);
                Long x = 0L;
                for(long i = 1; i <= t; i++){
                        if(n % i == 0){
                                x = i;
                                }
                        }
                System.out.println(n / x + x - 2);
                }
        }


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl; 
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a,LL b){LL s=1;while(b>0){if(b&1)s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
LL gcd(LL a,LL b) {return b?gcd(b,a%b):a;}
int dr[2][4] = {1,-1,0,0,0,0,-1,1};
typedef pair<int,int> P;
const int maxn = 1e5+10;
double a[maxn];
int main(void)
{
    int n;cin>>n;
    for(int i = 0;i < n; ++i){
        cin>>a[i];
    }    
    sort(a,a+n);
    double ans = a[0];
    for(int i = 1;i < n; ++i){
        ans = (ans+a[i])/2;
    }
    cout<<ans<<endl;

   return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

struct UnionFind {
private:
    vector<int> par,depth;
public:
    UnionFind (int n) {
        par.resize(n);
        depth = vector<int>(n,0);
        for (int i = 0;i < n;++i) par[i] = i;
    }

    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 (depth[x] < depth[y]) par[x] = y;
        else {
            par[y] = x;
            if (depth[x] == depth[y]) depth[x]++;
        }
    }

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

int main() {
    int n,q;
    cin >> n >> q;
    UnionFind uf(n);
    while (q--) {
        int t,u,v;
        cin >> t >> u >> v;
        if (t == 0) uf.unite(u,v);
        else cout << uf.same(u,v) << newl;
    }
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll a[N],dp[N],sum[N];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1,x;i<=n;i++){
		scanf("%lld",&a[i]);
		sum[i]=(i>2?sum[i-2]:0)+a[i];
	}
	for(int i=2;i<=n;i++)
	{
		if(i&1) dp[i]=max(dp[i-1],dp[i-2]+a[i]);//i为奇数的情况 选和不选该数. 
		else dp[i]=max(sum[i-1],dp[i-2]+a[i]);//i为偶数的情况 选和不选该数. 
	}
	printf("%lld\n",dp[n]);
	return 0;
}


Measured memory_bytes: 8444
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
int a[N];
int n;
int dp[N][2];
int dfs(int x, int o = 0)
{
	if (dp[x][o] != -1) return dp[x][o];
	int &ret = dp[x][o] = abs(a[n] - a[x - 1]);
	for (int i = x; i < n; i++)
	{
		if (o == 0)
			ret = max(ret, dfs(i + 1, o ^ 1));
		else
			ret = min(ret, dfs(i + 1, o ^ 1));
	}
	return ret;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	MEM(dp, -1);
	int x, y;
	cin >> n >> x >> y;
	for (int i = 1; i <= n; i++) cin >> a[i];
	a[0] = y;
	cout << dfs(1) << endl;
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
typedef long long ll;
const int MAXN = 100005;

pair < int, pair <int, int> >  a[MAXN];

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int N;
    cin >> N;

    a[0].ff = 0;
    a[0].ss.ff = 0;
    a[0].ss.ss = 0;
    for (int i = 1; i <= N; i++)
    {
        cin >> a[i].ff >> a[i].ss.ff >> a[i].ss.ss;
    }

    sort(a + 1, a + N + 1);
    for (int i = 1; i <= N; i++)
    {
        int dt = a[i].ff - a[i-1].ff;
        int dd = abs(a[i].ss.ff - a[i-1].ss.ff) + abs(a[i].ss.ss - a[i-1].ss.ss);
        if (dt < dd || dt % 2 != dd % 2)
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
	return 0;
}



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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    int lim = 2010;
    int n; cin >> n;
    vi A(n);
    rep(i,n) cin >> A[i];
    vvi dp(n+1, vi(lim+1, 0));

    dp[0][0] = 1;
    rep(i,n){
        rep(j,lim+1) dp[i+1][j] = dp[i][j];
        rep(j,lim+1){
            if(lim < j+A[i]) break;
            if(dp[i][j]) dp[i+1][j+A[i]] = 1;
        }
    }
    int q; cin >> q;
    rep(i,q){
        int m; cin >> m;
        if(dp[n][m]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}


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

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(),x.end()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<int,ull> piu;
typedef vector<vector<int>> matrix;

const ll INF=1e18+123;
const ld EPS=1e-9;
const int inf=1e9+123;
const int MOD=1e9+7;
const int N=1e3+123;
const int M=1e6+123;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

int d[N][N];

bool used[N][N];

int n,m;

char c[N][N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    queue<pii>q;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>c[i][j];
            d[i][j]=inf;
            if(c[i][j]=='#'){
                q.push({i,j});
                d[i][j]=0;
            }
        }
    }

    while(!q.empty()){
        int x=q.front().x;
        int y=q.front().y;
        q.pop();
        for(int i=0;i<4;i++){
            int nx=x+dx[i];
            int ny=y+dy[i];
            if(d[nx][ny]>d[x][y]+1){
                q.push({nx,ny});
                d[nx][ny]=d[x][y]+1;
            }
        }
    }
    int mx=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            mx=max(d[i][j],mx);
        //    cout<<d[i][j]<<" ";
        }
        //cout<<ndl;
    }
    cout<<mx;
    return 0;
}


Measured memory_bytes: 14352
#include <iostream>
using namespace std;
int main(){
	int n;
	int b[100000];
	int a;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a;
		b[a - 1] = i + 1; 
	}
	for(int i = 0;i < n;i++){
		if(i) cout << " ";
		cout << b[i];
	}
	cout << endl;
}


Measured memory_bytes: 1152
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
const int N=1e6+5,inf=0x3f3f3f3f;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
inline int min(R int x,R int y){return x<y?x:y;}
struct node;typedef node* ptr;
struct node{
	ptr lc,rc;int mn;
	inline void upd(){mn=min(lc->mn,rc->mn);}
}E[N<<2],*nd=E,*rt;
priority_queue<int,vector<int>,greater<int> >q;int deg[N],pos[N],id[N],n,k;
void build(ptr &p,int l,int r){
	p=++nd;if(l==r)return p->mn=inf,void();
	int mid=(l+r)>>1;
	build(p->lc,l,mid),build(p->rc,mid+1,r);
	p->upd();
}
void update(ptr p,int l,int r,int x,int v){
	if(l==r)return p->mn=v,void();
	int mid=(l+r)>>1;
	x<=mid?update(p->lc,l,mid,x,v):update(p->rc,mid+1,r,x,v);
	p->upd();
}
int res;
void query(ptr p,int l,int r,int ql,int qr){
	if(ql<=l&&qr>=r)return cmin(res,p->mn),void();
	int mid=(l+r)>>1;
	if(ql<=mid)query(p->lc,l,mid,ql,qr);
	if(qr>mid)query(p->rc,mid+1,r,ql,qr);
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d",&n,&k);
	for(R int i=1,x;i<=n;++i)scanf("%d",&x),pos[x]=i;
	build(rt,1,n);
	for(R int i=n,l,r;i;--i){
		l=max(pos[i]-k+1,1),r=pos[i]-1,res=inf;
		if(l<=r)query(rt,1,n,l,r);if(res!=inf)add(pos[i],pos[res]),++deg[pos[res]];
		l=pos[i]+1,r=min(pos[i]+k-1,n),res=inf;
		if(l<=r)query(rt,1,n,l,r);if(res!=inf)add(pos[i],pos[res]),++deg[pos[res]];
		update(rt,1,n,pos[i],i);
	}
//	fp(u,1,n)go(u)printf("%d %d\n",u,v);
	fp(i,1,n)if(!deg[i])q.push(i);
	for(R int u,i=1;i<=n;++i){
		u=q.top(),q.pop(),id[u]=i;
		go(u)if(!--deg[v])q.push(v);
	}
	fp(i,1,n)printf("%d\n",id[i]);
	return 0;
}

Measured memory_bytes: 54784
S = list(map(int, input().split()))
S.sort(reverse  = True)
A, B, C = S[0], S[1], S[2]

if (B-C)%2 == 0:
    print(A-B + (B-C)//2)
else:
    print(A-B + (B-C-1)//2 + 2)
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N, ans;
  cin >> N;
  
  if(N == "Sunny"){
    ans = "Cloudy";
  }
  
  if(N == "Cloudy"){
    ans = "Rainy";
  }
  
  if(N == "Rainy"){
    ans = "Sunny";
  }
 
  cout << ans << endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readString = map BS.unpack . BS.words
getString = readString <$> BS.getLine

isqrt :: Int -> Int
isqrt = floor . sqrt . fromIntegral

main = do
  [a, b] <- getString
  let x = read (a ++ b) :: Int
  let x_sqrt = isqrt x
  if x_sqrt ^ 2 == x then
    putStrLn "Yes"
  else
    putStrLn "No"

Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, H);
    CIN(int, W);

    vector<vector<int>> cell(H, vector<int>(W, -1));
    vector<vector<int>> h(H, vector<int>(W, 0));
    vector<vector<int>> v(H, vector<int>(W, 0));

    for (int i = 0; i < H; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < W; j++) {
            if (s[j] == '.') cell[i][j] = 1;
        }
    }

    int c = 0;

    for (int i = 0; i < H; i++) {
        c = 0;
        for (int j = 0; j < W; j++) {
            if (cell[i][j] == 1) {
                c++;
            } else {
                c = 0;
            }
            v[i][j] += c;
        }
        c = 0;
        for (int j = W - 1; j >= 0; j--) {
            if (cell[i][j] == 1) {
                c++;
            } else {
                c = 0;
            }
            v[i][j] += c;
        }
    }

    for (int j = 0; j < W; j++) {
        c = 0;
        for (int i = 0; i < H; i++) {
            if (cell[i][j] == 1) {
                c++;
            } else {
                c = 0;
            }
            h[i][j] += c;
        }
        c = 0;
        for (int i = H - 1; i >= 0; i--) {
            if (cell[i][j] == 1) {
                c++;
            } else {
                c = 0;
            }
            h[i][j] += c;
        }
    }

    int ans = 0;

    for (int i = 0; i < H; i++) {
        int temp = 0;
        for (int j = 0; j < W; j++) {
            temp = v[i][j] + h[i][j] - 3;
            ans = max(ans, temp);
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 47360
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template<class T>bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin>>s;
    cout<<(find(ALL(s),'9')!=end(s)?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define LINE_BUFSIZ 1024

int main(int argc, char **argv)
{
  char buf[LINE_BUFSIZ];
  if (!fgets(buf, LINE_BUFSIZ, stdin)) {
    perror("fgets");
    exit(1);
  }

  int N = atoi(buf);

  if (0 < N && N < 1000)
    printf("ABC\n");
  else if (1000 <= N && N < 2000)
    printf("ABD\n");
  else
    printf("UNKNOWN\n");

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int A,B;
  cin>>A>>B;
  if(A==1) A+=13;
  if(B==1) B+=13;
  string S="Draw";
  if(A>B) S="Alice";
  if(A<B) S="Bob";
  cout<<S;
return 0;}

Measured memory_bytes: 3556
#include <stdio.h>
static int a, b, c, d, arr[101], i, sum;
int main(void) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    for (i = a; i < b; ++i) ++arr[i];
    for (i = c; i < d; ++i) ++arr[i];
    for (i = 0; i <= 100; ++i)
        if (arr[i] == 2) ++sum;
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  int num = 0;
  rep(i, N.size())
  {
    num += N[i] - '0';
  }

  int n = std::stoi(N);

  if (n % num == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n,maxn,minn,temp;
int main()
{
	minn=2e9;
	maxn=0;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&temp);
		if(temp>maxn) maxn=temp;
		if(temp<minn) minn=temp;
	}
	printf("%d",maxn-minn);
}

Measured memory_bytes: 256
N=list(map(str,input()))
ketasu=len(N)
def dfs(siki,sitei):
    if sitei == ketasu-1 :    
        if eval(siki)==7:
            print(siki+"=7")
            exit()
            return
    else:
        dfs(siki+"+"+N[sitei+1],sitei+1)
        dfs(siki+"-"+N[sitei+1],sitei+1)

dfs(N[0],0)

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

int main() {

    int N;
    cin >> N;

    string ans = "APPROVED";

    rep(i, N) {
        int a;
        cin >> a;

        if (a % 2 == 0 and (a % 3 != 0 and a % 5 != 0)) ans = "DENIED";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
from collections import deque

h, w = map(int, input().split())
grid = []
for i in range(h):
    grid.append([j for j in input()])

parent = [[-1 for j in range(w)] for i in range(h)]


def bfs(s):
    q = deque()
    check = [[0 for j in range(w)] for i in range(h)]

    q.append(s)
    check[s[0]][s[1]] = 1
    while len(q) != 0:
        u = q.popleft()
        x, y = u[0], u[1]
        if x > 0 and grid[x-1][y] == "." and check[x-1][y] == 0:
            check[x-1][y], parent[x-1][y] = 1, u
            q.append((x-1, y))
        if y > 0 and grid[x][y-1] == "." and check[x][y-1] == 0:
            check[x][y-1], parent[x][y-1] = 1, u
            q.append((x, y-1))
        if x < h-1 and grid[x+1][y] == "." and check[x+1][y] == 0:
            check[x+1][y], parent[x+1][y] = 1, u
            q.append((x+1, y))
        if y < w-1 and grid[x][y+1] == "." and check[x][y+1] == 0:
            check[x][y+1], parent[x][y+1] = 1, u
            q.append((x, y+1))

        check[x][y] = 2


def main():
    bfs((0, 0))

    if parent[h-1][w-1] != -1:
        x, y = h-1, w-1
        while x != 0 or y != 0:
            grid[x][y] = "#"
            x, y = parent[x][y]
        grid[0][0] = "#"

        pt = 0
        for i in range(h):
            for j in range(w):
                if grid[i][j] == ".":
                    pt += 1

    else:
        pt = -1

    print(pt)


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

#define int ll

void read() {
	int a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	int la = a - v * t, ra = a + v * t, lb = b - w * t, rb = b + w * t;
	if (la <= lb && ra >= rb) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int n1 = mid -left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i=0, j=0;
  for(int k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

	cin >> n;
  for(i=0;i<n;i++) cin >> A[i];

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i)cout << " ";
  	cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 6976
#![allow(non_snake_case, unused)]
use std::collections::*;

////////// missing functions in 1.15.1 //////////
macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}
/////////////////////////////////////////////////
pub trait SetMinMax {
	fn setmin(&mut self, v: Self) -> bool;
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMinMax for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

fn run() {
	let N = read!(usize);
	let mut crt = vec![0; 3];
	for cs in read!([i32]; N) {
		let mut next = vec![0; 3];
		for i in 0..3 {
			let i1 = (i + 1) % 3;
			let i2 = (i + 2) % 3;
			next[i] = std::cmp::max(crt[i1] + cs[i1], crt[i2] + cs[i2]);
		}
		crt = next;
	}
	println!("{}", crt.into_iter().max().unwrap());
}


Measured memory_bytes: 13816
from collections import deque
N = int(input())
H = []
Q = deque()
for i in range(N):
  A = int(input())
  H.append(A)
H.sort()
#H = deque(H)

if N%2 == 0:
  groupA = H[:N//2]
  groupB = H[N//2:]
  ans = 2*sum(groupB)-2*sum(groupA)-groupB[0]+groupA[-1]
else:
  groupA1 = H[:N//2]
  groupB1 = H[N//2:]
  groupA2 = H[:N//2+1]
  groupB2 = H[N//2+1:]
  ans1 = 2*sum(groupB1)-2*sum(groupA1)-groupB1[0]-groupB1[1]
  ans2 = 2*sum(groupB2)-2*sum(groupA2)+groupA2[-1]+groupA2[-2]
  ans = max(ans1,ans2)
print(ans)

Measured memory_bytes: 8880
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

pll dp[100000];
// vi visited[100000];

pll dfs(int curr, int par, vvi const &edges) {
    // if (visited[curr] == 1)
    //     return dp[curr];
    ll black = 1;
    ll white = 1;
    for (auto &node : edges[curr]) {
        if (node == par)
            continue;
        auto p = dfs(node, curr, edges);
        black = (black * p.first) % MOD;
        white = (white * (p.first + p.second)) % MOD;
    }
    return dp[curr] = {white, black};
}

int main() {
    int n;
    cin >> n;
    vvi edges(n);
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
    auto ret = dfs(0, -1, edges);
    cout << (ret.first + ret.second) % MOD << "\n";
    return 0;
}

Measured memory_bytes: 15616