akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define SPACE " "

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1LL << 25;
double EPS = 1e-9;

// BEGIN //////////////////////////////////////////////////////////////

int main() {
	int as[4];
	int bs[4];
	while (scanf("%d%d%d%d", as, as+1, as+2, as+3) != EOF) {
		scanf("%d%d%d%d", bs, bs+1, bs+2, bs+3);
		int h = 0, b = 0;
		REP(i, 4) {
			if (as[i] == bs[i]) {
					h++;
			}	else {
				REP(j, 4) {
					if (i == j) continue;
					if (bs[i] == as[j]) {
						b++;
					}
				}
			}
		}
		cout << h << SPACE << b << endl;

	}
}

// END   //////////////////////////////////////////////////////////////

Measured memory_bytes: 1204
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int H, W;
    cin >> H >> W;
    lint ret = H * 1LL * W;
    FOR(_it, 0, 2) {
        FOR(i, 1, H) {
            lint area1 = i * 1LL * W;
            lint area2 = (H - i) / 2 * 1LL * W, area3 = (H - i + 1) / 2 * 1LL * W;
            VEC(lint) A {area1, area2, area3};
            sort(ALL(A));
            ret = min(A[2] - A[0], ret);

            area2 = (H - i) * 1LL * ((W + 1) / 2);
            area3 = (H - i) * 1LL * ((W) / 2);
            A = VEC(lint) {area1, area2, area3};
            sort(ALL(A));
            ret = min(A[2] - A[0], ret);
        }
        swap(H, W);
    }

    cout << ret << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int H, W;
	int i, j;

	while (1) {
		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0) {
			break;
		}

		for (i = 1; i <= H; i++) {
			for (j = 1; j <= W; j++) {
				if ((i + j) % 2 == 0) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>
using namespace std;

using T = tuple<int, int, int>; // (rの合計, id, range)

struct Object {
    int x, y;
    bool isGoal;
};

const int INF = (1 << 28);

int cost[200][1010];

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

    vector<Object> objects;
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        objects.push_back((Object){x, y, false});
    }
    objects.push_back((Object){1, 1, true});
    objects.push_back((Object){W, H, true});

    for (int i = 0; i < 200; i++) {
        for (int j = 0; j < 1010; j++) {
            cost[i][j] = INF;
        }
    }

    priority_queue<T, vector<T>, greater<T>> Q;
    Q.push(make_tuple(0, N, 0));

    int ans = INF;
    while (!Q.empty()) {
        int rsum, id, range;
        tie(rsum, id, range) = Q.top();
        Q.pop();

        if (id == N + 1) {  // goal
            ans = rsum;
            break;
        }

        for (int i = 0; i < objects.size(); i++) {
            Object& o = objects[i];

            int d = abs(o.x - objects[id].x) + abs(o.y - objects[id].y);

            if (id == N) {  // 自分がスタート
                if (not o.isGoal) {
                    if (cost[i][d] > rsum + d) {
                        cost[i][d] = rsum + d;
                        Q.push(make_tuple(cost[i][d], i, d));
                    }
                } // else
            } else {
                if (not o.isGoal) {
                    int r = max(0, d - 1 - range);
                    if (cost[i][r] > rsum + r) {
                        cost[i][r] = rsum + r;
                        Q.push(make_tuple(cost[i][r], i, r));
                    }
                } else {    // 相手がゴールかつ範囲内
                    int r = max(0, d - range);
                    if (cost[i][r] > rsum + r) {
                        cost[i][r] = rsum + r;
                        Q.push(make_tuple(cost[i][r], i, r));
                    }
                }
            }
        }
    }

    if (ans >= INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4672
fun main(argv: Array<String>) {
    val line = readLine()
    val splited = readLine()!!.split(' ')
    val intArr = splited.map { Integer.parseInt(it) }

    val average = Math.round(intArr.average()).toInt()
    var cost = 0

    for (number in intArr) {
        cost += Math.pow((number - average).toDouble() ,2.0).toInt()
    }
    print(cost)
}

Measured memory_bytes: 38304
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int K, S;
	cin >> K >> S;
	int cnt = 0;
	for (int X = 0; X <= K; X++) {
		for (int Y = 0; Y <= K; Y++) {
			if (0 <= S - X - Y && S - X - Y <= K) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
/* 
    AABRA KA DABRA.. !! 
*/
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
#define int long long
#define RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i <n; i++)
#define repv(i,k,n) for(int i=k; i<=n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define endl '\n'
#define deb(x) cout<<#x<<" = "<<x<<endl
#define gcd __gcd
#define inf LLONG_MAX
#define minf LLONG_MIN 
const int mod = (int)(1e9+7);

int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
bool is_power_2(int n)  { return log2(n)==floor(log2(n));}
bool is_prime(int n){   for(int i=2; i*i<=n; i++)   if(n%i==0)  return 0;   return 1;}

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

/*                                                                 
    ╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦ 
*/  




void solve()
{   
    int n,i,j,k,m;
    cin>>n>>k;
    int ar[n];
    rep(i,n)
        cin>>ar[i];
    sort(ar,ar+n);
    m=0;
    rep(i,k)
        m += ar[i];
    cout<<m;
}   
signed main()
{
    RAGE;
    int t=1;
    //  cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3648
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A
// Graph I - Connected Components

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <cstring>
#include <climits>
#include <memory>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const int NIL = -1;
const ui64 MAX_N = 100000;

vector<int> adj[MAX_N];
int assigned_group_ids[MAX_N];
int n, m, q;
int group_id;

void dfs(int u, int id) {
    assigned_group_ids[u] = id;
    // search adj nodes
    for (const auto& v : adj[u]) {
        if (assigned_group_ids[v] == NIL) dfs(v, id);
    }
}

void assign_group() {
    memset(assigned_group_ids, NIL, sizeof(assigned_group_ids));
    group_id = 0;

    for (int u = 0; u < n; ++u) {
        if (assigned_group_ids[u] == NIL) {
            dfs(u, group_id);
            group_id++;
        }
    }
}

int main() {
    memset(adj, 0, sizeof(adj));
    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    assign_group();

    cin >> q;

    for (int i = 0; i < q; ++i) {
        int s, t;
        cin >> s >> t;
        if (assigned_group_ids[s] == assigned_group_ids[t]) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}


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

typedef long long LL;

vector<LL> levels(55);
vector<LL> patties(55);

LL calc_layers(int N)
{
    levels[0] = 1;
    for (int i = 1;i < N + 1; i++)
    {
        levels[i] = 2*levels[i - 1] + 2 + 1;
    }
    return levels[N];
}

void calc_patties(int N)
{
    patties[0] = 1;
    for (int i = 1;i < N + 1; i++)
    {
        patties[i] = 2*patties[i - 1] + 1;
    }
}

int main() {
    int N;
    LL X;
    cin >> N >> X;
    LL number_layers = calc_layers(N);
    calc_patties(N);
        int L = N;
        LL p = 0;
        while (L > 1) {
            if (X < (number_layers + 1) / 2) // first half of the burguer
            {

                X--;
            } else if (X > (number_layers + 1) / 2) {
                p += patties[L - 1] + 1;
                X -= (number_layers + 1) / 2;
            } else {
                p += patties[L - 1] + 1;
                X = 0;
                break;
            }
            L--;
            number_layers = levels[L];
        }
        if (X > 1 and X < 5)
            p += X - 1;
        else if (X >= 5)
            p += 3;

        cout << p;
    return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
		int N;
	cin >> N;
	ll ans = 0;
	int pre = -1;
	fx(N) {
		int a;
		cin >> a;
		if (pre>=0) {
			if (a<pre) {
				ans += pre - a;
			}
			pre = max(pre, a);
		}
		else {
			pre = a;
		}
	}
	ce(ans)
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, m;
  cin >> n >> m;
  vector<vi32> g(n);
  rep(i, m) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vi32 dp(n, -1);
  using T = tuple<int, int>;
  queue<T> q;
  q.emplace(0, 0);
  while (sz(q)) {
    int u, prev;
    tie(u, prev) = q.front();
    q.pop();
    if (dp[u] != -1) continue;
    dp[u] = prev;
    for (auto v : g[u]) {
      q.emplace(v, u);
    }
  }
  cout << "Yes" << endl;
  reps(i, n - 1) {
    cout << dp[i] + 1 << endl;
  }
}


Measured memory_bytes: 12212
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  map<string , int> mp = {
    {"SUN", 7},
    {"MON", 6},
    {"TUE", 5},
    {"WED", 4},
    {"THU", 3},
    {"FRI", 2},
    {"SAT", 1}};
  string s; cin >> s;
  cout << mp[s] << endl;
  return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    pair<int ,int >s[5] ;
    int temp ,ama ;
    for(int i = 0; i < 5 ; i++){
        cin >> temp ;
        ama = temp % 10 ;
        if(ama ==0){
            ama = 10;
        }
        s[i] =  make_pair(ama ,temp);
        
    }
    int ans  = 0;
    sort(s,s+5);
    for(int j = 5 ; j > 1; j--){
           ans += s[j-1].second + (10 - s[j-1].first);
    }
    
        ans += s[0].second ;
    
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
 #include <iostream>
using namespace std;
int main() {
  int A, B, C;
  scanf("%d %d %d", &A, &B, &C);
 
  if (C == 0) {
    printf("YES\n");
    return 0;
  }
 
  for (int i=1; i<1000; ++i)
    if (i*A % B == C) {
      printf("YES\n");
      return 0;
    }
 
  printf("NO\n");
  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 int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n, a;
  cin >> n >> a;
  if(n % 500 == 0){
    cout << "Yes" << endl;
  }
  else{
    if(n % 500 <= a){
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  system("pause");
}


Measured memory_bytes: 504
<?php

class Transformer
{
    private $target;
    private $order;
    private $params;

    public function __construct($target)
    {
        $this->target = $target;
    }

    public function order($order)
    {
        $this->order = $order;
        return $this;
    }

    public function parameters($params)
    {
        $this->params = $params;
        return $this;
    }

    public function transform()
    {
        call_user_func([$this, '_'.$this->order], $this->params);
    }

    private function _replace($params)
    {
        list($start, $end, $replaceText) = $params;
        $this->target = substr_replace($this->target, $replaceText, $start, $end - $start + 1);
    }

    private function _print($params)
    {
        list($start, $end) = $params;
        echo substr($this->target, $start, $end - $start + 1), PHP_EOL;
    }

    private function _reverse($params)
    {
        list($start, $end) = $params;

        $this->target = substr_replace(
            $this->target,
            strrev(substr($this->target, $start, $end - $start + 1)),
            $start, $end - $start + 1
        );
    }
}


$str = getStdin();
$q   = getStdin();

for ($i = 0; $i < $q; $i++) {
    $input[] = explode(' ', getStdin());
}

$transformer = new Transformer($str);

foreach ($input as $orders) {
    $transformer->order(first($orders))
        ->parameters(drop($orders, 1))
        ->transform();
}


function first($array)
{
    foreach ($array as $value) {
        return $value;
    }
}

function drop($array, $n)
{
    return array_slice($array, $n);
}

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

Measured memory_bytes: 15560
#include<iostream>

using namespace std;

int main(){
  int H,N;
  int s=0;
  cin >> H >> N;
  int A[N];
  for(int i=0;i<N;i++)
  cin >> A[i];
  for(int i=0;i<N;i++)
  s+=A[i];
  if(s>=H)
  cout << "Yes";
  else
  cout << "No";

  return 0;
}

Measured memory_bytes: 640
x=int(input())
ulist=[]

for i in range(1,int(x**0.5)+1):
    if x%i==0:
        ulist.append(i)

def root(n):
    hanbun=int(n**0.5)
    if hanbun**2==n:
        return True
    return False
        

def niji(a,b,c):
    hanbetu=b**2-4*a*c
    if hanbetu>=0:
        if root(hanbetu):
            one=-b+int(hanbetu**0.5)
            two=-b-int(hanbetu**0.5)
            ans=[]
            if one%(2*a)==0:
                ans.append(one//(2*a))
            if two%(2*a)==0:
                ans.append(two//(2*a))
            if ans!=[]:
                return ans
    return False
# print(ulist)        
for u in ulist:
#     print(u)
#     print(5*u,5*(u**3),u**5-x)
    if niji(5*u,5*(u**3),u**5-x):
        plist=niji(5*u,5*(u**3),u**5-x)
#         print(plist)
        for p in plist:
            if niji(1,-u,-p):
                alist=niji(1,-u,-p)
                print(alist[0],alist[0]-u)
                break
    

Measured memory_bytes: 9504
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
 
N, K = rrm()
a = rrm()
a = sorted(a)
print(sum(a[:K]))

Measured memory_bytes: 66928
#include <iostream>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 7;
int a,b,c,k,cnt;
int main(){
    cin>>a>>b>>c>>k;
    while(a>=b){
        b*=2;
        cnt++;
    }
    while(b>=c){
         c*=2;
         cnt++;
    }
    if(cnt>k) printf ("No\n");
    else printf ("Yes\n");

   

}

Measured memory_bytes: 3040
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;


int main() {
	double n;
	cin >> n;
	//cout << (ll)(n / 1.08) << endl;
	//cout << (ll)((n + 1) / (1.08)) << endl;
	//cout << (double)((n+1) / 1.08) << endl;
	//cout << (ll)((n + 1) / (1.08)) << endl;
	if (((double)(n+1) / (1.08) -(ll)((n+1) /( 1.08))>0) &&((ll)(n / 1.08) != (ll)((n + 1) / (1.08)))) {
		cout << (ll)((n + 1) / 1.08) << endl;
	}
	else if((double)(n/1.08)==(ll)(n / 1.08)) {
		cout << n / 1.08 << endl;
	}
	else {
		cout << ":(" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 200;
const int N = 10;

vector<pii> G[N];
int d[N][N];

void dijkstra(int s, int d[]){
	priority_queue<pii, vector<pii>, greater<pii>> Q;
	Q.push(pii(0,s));
	d[s]=0;
	while(!Q.empty()){
		pii p=Q.top();Q.pop();
		for(auto q:G[p.second]){
			if(d[q.second]>d[p.second]+q.first){
				d[q.second]=d[p.second]+q.first;
				Q.push(q);
			}
		}
	}
}

int main() {
	int h,w;cin>>h>>w;
	rep(i,N) { rep(j,N) {
		int c;cin>>c;
		d[i][j]=INF;
		if(i==j) continue;
		G[i].push_back(pii(c,j));
	}}
	rep(i,N) dijkstra(i,d[i]);
	int ans=0;
	rep(i,h) { rep(j,w) {
		int a;cin>>a;
		if(a==-1||a==1) continue;
		ans+=d[a][1];
	}}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
	unsigned short *A, *B;
	
	int C[VMAX+ 1];
	int n,i,j;
	scanf("%d", &n);
	
	A = malloc(sizeof(short)*n+1);
	B = malloc(sizeof(short)*n+1);
	
	for(i = 0;i <= VMAX;i++) C[i] = 0;
	
	for(i = 0;i < n;i++){
		scanf("%hu",&A[i+1]);
		C[A[i+1]]++;
	}
	
	for(i = 1;i <= VMAX;i++) C[i] = C[i] + C[i-1];
	
	for(j = 1;j <= n;j++){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
	
	for(i = 1;i <= n;i++){
		if(i > 1) printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 9716
#include<bits/stdc++.h>
using namespace std;
#define  ll long long int
ll less_check(ll a,vector<ll>v){
  ll count =0,i=0;
  for(i=0;i<v.size();i++){
    if(v[i]==a) break;
    else if(v[i]<a) count++;
  }
  return a-1-count ;
}
ll fac(ll n){
  ll a=1;
  if(n==0) return 1;
  else {
  for(ll i=1;i<=n;i++){
    a = a*i ;
  }
  return a;
}
}
int main(){
  ll n,ra=0,rb=0;
  cin >> n;
  vector <ll> a(n),b(n),c(n+1) ;
  for(ll i=0;i<n;i++){
    cin >> a[i] ;
  }
  for(ll i=0;i<n;i++){
    cin >> b[i] ;
  }
  for(ll i=0;i<n;i++){
      ra = ra + (less_check(a[i],a))*fac(n-1-i) ;
  }
  for(ll i=0;i<n;i++){
      rb = rb + (less_check(b[i],b))*fac(n-1-i) ;
  }
  cout << abs(ra-rb) << endl;
}


Measured memory_bytes: 256
import collections
import sys


def count_connected_components(max_v, adj_list):
    result = 0
    visited = collections.defaultdict(bool)

    def depth_first_search(start_v):
        visited[start_v] = True
        for v in adj_list[start_v]:
            if not visited[v]:
                depth_first_search(v)
    for u in range(max_v):
        if not visited[u]:
            depth_first_search(u)
            result += 1
    return result


def main():
    sys.setrecursionlimit(50000)
    n, m = map(int, input().split())
    adj_list = collections.defaultdict(set)
    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())
        adj_list[a].add(b)
        adj_list[b].add(a)
    print(count_connected_components(n, adj_list) - 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 74364
#include <stdio.h>
int main(){
  int n, m, sum=0, cnt=0, a[101]={0};
  scanf("%d%d",&n,&m);
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
    sum += a[i];
  }
  for(int i=0; i<n; i++){
    if( a[i]*4*m >= sum ){ cnt++; }
  }
  if( cnt >= m ){ printf("Yes\n"); }
  else			{ printf("No\n");  }
  return 0;
}

Measured memory_bytes: 1628
use std::io;
use std::collections::VecDeque;


fn main() {
    let n = read_one::<usize>();
    let mut edge = vec![Vec::new(); n];

    for _ in 0..n - 1 {
        let (u, v, w) = {
            let i = read::<usize>();
            (i[0] - 1, i[1] - 1, i[2])
        };
        edge[u].push((v, w));
        edge[v].push((u, w));
    }

    let mut color = vec![2; n];
    let mut cost = vec![0; n];
    let mut q = VecDeque::new();
    q.push_back(0);
    color[0] = 0;
    while let Some(u) = q.pop_front() {
        for &(v, w) in edge[u].iter() {
            if color[v] != 2 { continue; }
            cost[v] = cost[u] + w;
            if (cost[v] - cost[u]) % 2 == 0 { color[v] = color[u]; }
            else { color[v] = 1 - color[u]; }
            q.push_front(v);
        }
    }

    for i in 0..n { println!("{}", color[i]); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 16764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define OUT(x) cout << (x) << endl;
#define ALL(v) v.begin(), v.end()
#define REP(i, n) for (int i=0; i<(int)(n); ++i)
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

const int MAX_X=50, 
          MAX_Y=50;
const ll INF = 10e9;

int main() {
    ll A, B; cin >> A >> B;
    ll tmp;
    if(A > B){
        tmp = A;
        A=B;
        B=tmp;
    }
    ll x = A*B;
    ll r = A % B;
    while(r != 0){
        A = B;
        B = r;
        r = A % B; 
    }
    cout << x/B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#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 setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
bool even(string s){
	int flag=0,n=s.length();
	REP(i,0,(n/2)-1){
		if(s[i]!=s[i+(n/2)]){
			flag=1;
			break;
		}
	}
	if(flag==1)
		return false;
	else
		return true;
}


//--main function
int main(){
	string s;cin>>s;s.pop_back();
	int sol=1;
	while(s.length()%2!=0 || !even(s)){
		s.pop_back();	
	}
	cout<<s.length();
	return 0;

//   TimeTaken();
}



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

string a;
int ans;
int z;
int main()
{
	int i;
//	freopen ("input.txt", "r", stdin);
	cin >> a;
	z = 0;
	for (i = 0; i < a.size(); i++) {
		if (a[i] == 'g' && z == 1) ans++;
		else if (a[i] == 'p' && z == 0) ans--;
		z = 1 - z;
	}
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <string.h>
#include <stdio.h>
#define SIZE 1028
char str[SIZE];
void apple(int len);
int main() {

	int len;
	fgets(str,sizeof(str),stdin);
	len = strlen(str)-1;
	apple(len);
	printf("%s",str);
	return 0;
}

void apple(int len){
	int i;
	for(i=0;i<len;i++){
		if(strncmp(&str[i],"apple",5)==0)
			strncpy(&str[i],"peach",5);
		else if(strncmp(&str[i],"peach",5)==0)
			strncpy(&str[i],"apple",5);
	}
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  char prev = s[0];
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (prev != s[i]) {
      ans++;
      prev = s[i];
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var a = IO.RInt;
            WriteLine(a + a * a + a * a * a);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 17640
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int main()
{
  int N;
  cin >> N;
  bool succeeded = false;
  for (int i = 0; i <= 25; ++i) {
    if (succeeded) break;
    for (int j = 0; j <= 15; ++j) {
      if (i * 4 + j * 7 == N) {
	cout << "Yes" << endl;
	succeeded = true;
	break;
      }
    }
  }
  if (not succeeded) cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
long long f[100005],n,m,sum,ans[100005],s[100005];
pair<long,long> p[100005];
long long find(long long x)
{
	if(f[x]!=x)
		f[x]=find(f[x]);
	return f[x];
 } 
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
		cin>>p[i].f>>p[i].s;
	for(int i=1;i<=n;i++)
	{
		s[i]=1;
		f[i]=i;
	}
	sum=n*(n-1)>>1;
	for(int i=m;i>0;i--)
	{
		ans[i]=sum;
		long long x=find(p[i].f),y=find(p[i].s);
		if(x!=y)
		{
			f[x]=y;
			sum-=s[x]*s[y];
			s[y]+=s[x];
		}
	}
	for(int i=1;i<=m;i++)
		cout<<ans[i]<<endl;
	return  0;
} 

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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    if (r <= x && x <= W-r && r <= y && y <= H-r) cout << "Yes" << endl;
    else    cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3088
N = int(input())
X = list(map(int, input().split()))
X.sort()
p = X[0]
Cost = 0
MinCost = 0
for k in X:
    MinCost += (k-p)**2
while p <= X[N-1]:
    Cost = 0
    for i in X:
        Cost += (i-p)**2
    if Cost < MinCost:
        MinCost = Cost
    p += 1
    
print(MinCost)

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



ll n, h, d;
ll dp[maxn];
ll acc[maxn];

ll fac[maxn];
ll facSum;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>h>>d;
    fac[0]=1;
    for (int i=1; i<=n; i++) {
	fac[i]=1ll*i*fac[i-1]%mod;
	facSum += fac[i];
	facSum %= mod;
    }



    // facSum = 1! + 2! ... N!


    // dp[i]: (# of ways to have at least 1 square reach height i) x (all orders of blocks that get stacked to this height)


    dp[0] = fac[n];
    acc[0] = dp[0];
    for (ll i=1; i<=h; i++) {
	dp[i] += acc[i-1];
	if (i-1-d>=0) {
	    dp[i] += (mod-acc[i-1-d]);
	}
	dp[i] %= mod;

	// at height H, we don't care about order of arrival
	if (i<h) {
	    dp[i] *= facSum;
	    dp[i] %= mod;
	}
	acc[i]=(acc[i-1]+dp[i])%mod;
    }


    cout<<dp[h]<<endl;    
    return 0;
}


Measured memory_bytes: 27056
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int N;
    long long int ans=0;
    cin >> N;
    vector<long long int> A(N),B(N);
    for(int i=0;i<N;i++){
        cin >> A[i] >> B[i];
    }

    for(int i=N-1;0<=i;i--){
        A[i] += ans;

        if(A[i] != 0 && B[i]!=1 && (A[i]%B[i])!=0){
            ans += B[i]-(A[i]%B[i]);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.reverse()
    
    temp = 0
    a_sum = []

    for i in range(len(a)):
        temp += a[i]
        a_sum.append(temp)

    total = 0
    a_sum.reverse()
    a.reverse()

    for i in range(1, len(a_sum)):
        total += a[i-1]*a_sum[i]
    
    print(total % (10**9+7))

if __name__ == '__main__':
    main()

Measured memory_bytes: 106988
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    long long capacity[5];
    long long N;
    cin >> N;
    long long minimum_cap;
    for (int i = 0; i < 5; i++) {
        cin >> capacity[i];
        minimum_cap = i == 0 ? capacity[0] : min(capacity[i], minimum_cap);
    }
    cout << 5 + (N % minimum_cap == 0 ? N / minimum_cap - 1 : N / minimum_cap) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
vector<string> ans;
void solve(int x, string s, char c){
	if(x==0){
		ans.push_back(s);
		return;
	}
	int k=0;
	for(int i=0; i<n; i++){
		if(x&(1<<i)){
			k=i; break;
		}
	}
	for(int i=x; i>0; i=(i-1)&x){
		if(!(i&(1<<k))) continue;
		string t=s;
		for(int j=0; j<n; j++){
			if(i&(1<<j)) t[j]=c;
		}
		solve(x^i, t, c+1);
	}
}
int main()
{
	cin>>n;
	string s0;
	for(int i=0; i<n; i++) s0+='.';
	solve((1<<n)-1, s0, 'a');
	sort(ans.begin(), ans.end());
	for(auto s:ans){
		cout<<s<<"\n";
	}
	return 0;
}


Measured memory_bytes: 7796
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<int,int> P;
typedef pair<P,int> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;

//input
ll n;
string s1,s2;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
    cin >> n;
    cin >> s1;
    cin >> s2;
    mint ans = 1;

    //start
    int j;
    if(s1[0]==s2[0]){
        j=1;
        ans*=3;
    }
    else{
        j=2;
        ans*=6;
    }

    //solve
    while(j<n){
        if(s1[j]==s2[j]){
            if(s1[j-1]==s2[j-1]){
                ans*=2;
            }
            else{
                ans*=1;
            }
            j++;
        }
        else{
            if(s1[j-1]==s2[j-1]){
                ans*=2;
            }
            else{
                ans*=3;
            }
            j+=2;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
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; }


string strmax(string a, string b){
  if(a.size() > b.size()) return a;
  if(a.size() < b.size()) return b;
  if(a > b) return a;
  else return b;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  int C[9] = {2,5,5,4,5,6,3,7,6};
  rep(i, 0, M) cin >> A[i];
  vector<string> dp(10101, "0");
  dp[0] = "";
  rep(i, 0, N) rep(j, 0, M) {
    if(dp[i] != "0") dp[i + C[A[j] - 1]] = strmax(dp[i+ C[A[j] - 1]], to_string(A[j]) + dp[i] );
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 32512
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;
typedef long long ll;

char a[100000+5];

int main()
{
	scanf("%s",a);
	int len=strlen(a);
	int ans=0x7fffffff;
	for(int i=0;i<len-1;i++){
		if(a[i]!=a[i+1]){
			ans=min(ans,max(i+1,len-i-1));
		}
	}
	if(ans==0x7fffffff){
		cout<<len<<endl;
	}
	else {
		cout<<ans<<endl;
	}
	return 0;
}	 


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

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

    int a,b;
    cin >> a >> b;
    string s;
    if(a>=b){
    	rep(i,0,a){
    		cout << b ;
    	}
    }
    else{
    	rep(i,0,b){
    		cout << a ;
    	}
    }
    cout << "\n";

}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
e = []
o = []
e_append = e.append
o_append = o.append

for a in A:
    if a % 2 == 0:
        e_append(a)
    else:
        o_append(a)

if len(o) %2 != 0:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 14112
import java.util.*;
import java.util.Map.Entry;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		Hashtable<String,Integer> vals = new Hashtable<String, Integer>();
		while (sc.hasNext()) {
			String m = sc.next();
			if(vals.containsKey(m)){
				vals.put(m,vals.get(m)+1);
			}else{
				vals.put(m,0);
			}
		}
		
		ArrayList<Entry<String,Integer>> valList=new ArrayList<Entry<String,Integer>>(vals.entrySet());
			
		Collections.sort(valList,new Comparator<Entry<String,Integer>>() {
@Override
		public int compare(Entry<String, Integer> o1,
				Entry<String, Integer> o2) {
			return o2.getValue()-o1.getValue();
		}
		});
		String mode=valList.get(0).getKey();
	
		Collections.sort(valList,new Comparator<Entry<String,Integer>>() {
			@Override
					public int compare(Entry<String, Integer> o1,
							Entry<String, Integer> o2) {
						return o2.getKey().length()-o1.getKey().length();
					}
		});
		String lng=valList.get(0).getKey();
		
		ln(mode+" "+lng);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <set>
#include <algorithm>

using namespace std;
typedef long long ll;
#define all(x) begin(x), end(x)

int main() {
    int n, m;
    cin >> n >> m;

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

    set<int> s;

    int a, b;
    for(int i=0; i<m; i++){
        cin >> a >> b;
        if(h[a-1] > h[b-1]) s.insert(b);
        else if(h[a-1] < h[b-1]) s.insert(a);
        else {
            s.insert(a);
            s.insert(b);
        }
    }

    cout << n - s.size() << endl;

    return 0;
}

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

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

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct robot {ll x; ll l;};

int main() {
  int N; cin >> N;
  robot r[N]; rep(i,N) { ll x, l; cin >> x >> l; r[i] = {x, l}; }
  sort(r,r+N,[](const robot x, const robot y){return x.x+x.l<y.x+y.l;});
  int result = 0, pos = 0;
  while (pos!=N) {
    result++;
    ll d = r[pos].x + r[pos].l;
    while(d>r[pos].x-r[pos].l&&pos!=N) pos++;
  }
  cout << result << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	ll K;
	cin >> K;
	vector<ll>A(K);
	rep(i, K) {
		cin >> A[i];
	}
	ll minn = 2, maxn = 3;
	if (A[K - 1] != 2) {
		cout << -1 << endl;
		return 0;
	}
	reps(i,1, K) {
		ll x = maxn / A[K - 1 - i];
		ll y = minn / A[K - 1 - i] + (minn%A[K - 1 - i] == 0 ? 0 : 1);
		if (x==0) {
			cout << -1 << endl;
			return 0;
		}
		minn = y * A[K - 1 - i];
		maxn = (x + 1)*A[K - 1 - i] - 1;
		if (minn > maxn) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << minn << " " << maxn << endl;
	return 0;
}


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

using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  if(s == "SUN")
    cout << "7" << endl;
  if(s == "MON")
    cout << "6" << endl;
  if(s == "TUE")
    cout << "5" << endl;
  if(s == "WED")
    cout << "4" << endl;
  if(s == "THU")
    cout << "3" << endl;
  if(s == "FRI")
    cout << "2" << endl;
  if(s == "SAT")
    cout << "1" << endl;
  
  return 0;
}


Measured memory_bytes: 256