akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
constexpr int mod = 1e9+7;

vector<pii> pf(int n){
  vector<pii> res;
  int i = -1;
  FOR(j,2,sqrt(n)+1){
    if(n == 1) break;
    if(n%j == 0){
      res.push_back(pii(j,0));
      i++;
    }
    while(n%j == 0){
      res[i].second++;
      n /= j;
    }
  }
  if(n != 1) res.push_back(pii(n,1));
  return res;
}

class ModuloCombination{
public:
  vector<ll> fact, fact_inv;

  static ll mod_pow(ll a, ll n){
    if(n == 0) return 1;
    if(n % 2 == 0) return mod_pow((a * a) % mod, n/2);
    return (a * mod_pow(a, n-1) % mod);
  }

  ModuloCombination(ll N):fact(N+1), fact_inv(N+1){ // N log Nで初期化
    fact[0] = 1;
    FOR(i, 1, N+1) fact[i] = (i * fact[i-1]) % mod;
    FOR(i, 0, N+1) fact_inv[i] = mod_pow(fact[i], mod-2);
  }

  ll op(ll n, ll r){ // nCr
    if(r < 0 or n < r) return 0;
    return fact[n] * fact_inv[r] % mod * fact_inv[n-r] % mod;
  }
};

main(){
  int n,m; cin >> n >> m;
  auto fact = pf(m);

  ModuloCombination C(n+30);
  int res = 1;
  for(auto x : fact){
    int tmp = C.op(n+x.second-1,x.second);
    tmp %= mod;
    res *= tmp;
    res %= mod;
  }
  cout << res << endl;
}

Measured memory_bytes: 1792
import numpy as np
def receive_round_setting():
    round_settings = input()
    N, K, Q = round_settings.split(' ')
    N, K, Q = int(N), int(K), int(Q)
    participants = np.full(N, K, dtype='i')
    round_settings = {'N':N, 'K':K, 'Q':Q,
                    'participants':participants}
    return round_settings

def answer_question(round_settings):
    round_settings['participants'] -= 1*round_settings['Q']
    answerers = np.zeros(shape=round_settings['N'], dtype='i')
    for _ in range(round_settings['Q']):
        answerer = int(input()) - 1
        answerers[answerer] += 1
    round_settings['participants'] += answerers
    return round_settings
        
def announce_resutl(round_setting):

    [print('Yes') if participant > 0 else print('No')
    for participant in round_settings['participants']]

if __name__ == '__main__':
    round_settings = receive_round_setting()
    if round_settings['Q'] < round_settings['K']:
        announce_resutl(round_settings)
    else:
        round_settings = answer_question(round_settings)
        announce_resutl(round_settings)
    # round_settings = receive_round_setting()
    # round_settings = answer_question(round_settings)
    # announce_resutl(round_settings)


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    lint r, d, x;
    cin >> r >> d >> x;

    rep(i, 10){
        x = r * x - d;
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e18 + 1e18;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long 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 {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= 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 {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll N;
	cin >> N;
	vll A(N + 1);
	repn(i,N)cin >> A[i];
	
	ll mon = 1000;
	for (ll i = 2; i <= N; i++) {
		ll x = mon / A[i-1];
		ll now = mon % A[i - 1] + x * A[i];
		mon = max(now, mon);
	}
	cout << mon << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define N 3050
int memo[N][N];
string a,b;

int dp(int curr1 , int curr2) {
    if (curr1 >= a.length() || curr2 >= b.length()) return 0;
    int &sol = memo[curr1][curr2];
    if (sol != -1) return sol;
    sol = max(dp(curr1 + 1 , curr2) , dp(curr1 , curr2 + 1));
    if (a[curr1] == b[curr2]) {
        sol = max(
            dp(curr1 + 1 , curr2 + 1) + 1 ,
            sol
        );
    }
    return sol;
}

void dp2(int curr1 , int curr2) {
    if (curr1 >= a.length() || curr2 >= b.length()) return;
    int inc1 = dp(curr1 + 1 , curr2), inc2 = dp(curr1 , curr2 + 1),take;
    if (a[curr1] == b[curr2]) take = dp(curr1 + 1 , curr2 + 1) + 1;
    else take = INT_MIN;
    if (inc1 >= take && inc1 >= inc2) {
        dp2(curr1 + 1 , curr2);
    } else if (inc2 >= take && inc2 >= inc1) {
        dp2(curr1 , curr2 + 1);
    } else if (take >= inc1 && take >= inc2) {
        printf("%c" , a[curr1]);
        dp2(curr1 + 1 , curr2 + 1);
    }
}

int main() {
    char x[N],y[N]; scanf("%s %s" , x , y);
    a = x, b = y;
    memset (memo , -1 , sizeof memo);
    dp(0 , 0);
    dp2(0 , 0);
    printf("\n");
}


Measured memory_bytes: 37120
from heapq import *
r=reversed
N=int(input())
A=list(map(int,input().split()))
def w(L):
	q=L[:N]
	heapify(q)
	s=sum(q)
	yield s
	for e in L[N:2*N]:
		s+=e-heappushpop(q,e)
		yield s
print(max(map(sum,zip(w(A),r(list(w([-a for a in r(A)])))))))

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

int main(){
    int N,D;
    cin >> N >> D;
    int i = (D+1)+D;
    int ans = 0;
if(N%i == 0){
    ans = (N/i);
}else{
    ans = (N/i)+1;
}
    
    cout << ans << endl;
}

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


n,k,l = list(map(int, input().split()))
from collections import defaultdict
ns0 = defaultdict(list)
ns1 = defaultdict(list)
for i in range(k):
    p,q = map(int, input().split())
    p-=1;q-=1
    ns0[p].append(q)
    ns0[q].append(p)
for i in range(l):
    p,q = map(int, input().split())
    p-=1;q-=1
    ns1[p].append(q)
    ns1[q].append(p)
def sub(ns):
    seen = [None]*n
    num = 1
    for i in range(n):
        if seen[i] is not None:
            continue
        q = [i]
        seen[i] = num
        while q:
            u = q.pop()
            for v in ns[u]:
                if seen[v] is not None:
                    continue
                seen[v] = num
                q.append(v)
        num += 1
    return seen

s1 = sub(ns0)
s2 = sub(ns1)

import gc
del ns0, ns1
gc.collect()

from collections import Counter
c = Counter([(s1[i], s2[i]) for i in range(n)])
ans = [(c[s1[i],s2[i]]) for i in range(n)]
write(" ".join(map(str, ans)))

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  cin >> n;

  int ans = 100000;
  for (int i = 0; i < n; i++) {
    ans += ans / 20;
    if (ans % 1000) {
      ans = ans / 1000 * 1000;
      ans += 1000;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3100
/****************
 *		*
 * ALDS_1_5_A:  *
 * Search	*
 *		*
 * 2019/08/19	*
 *		*
 ***************/

#include<iostream>

#define MAX_ARRAY 2000

using namespace std;

int A[MAX_ARRAY] = {0};

bool check(int num_array,int value){

  bool ans;
  if(value == 0) return true;
  if(num_array < 0) return false;

  ans = check((num_array-1),value) | check((num_array-1),(value-A[num_array]));
  
  return ans;
}

int main(void){
  int n=0;
  int q=0;
  int m=0;

  /*n、及びn個の要素Aを入力*/
  cin >> n;
  for(int i=0;i<n;i++) cin >> A[i];

  cin >> q;
  for(int i=0;i<q;i++){
    cin >> m;
    if(check(n-1,m)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}



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

#define pb push_back
#define all(a) begin(a), end(a)
#define deb(x) cout << #x << " = " << x << endl
template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

void yes() {cout << "YES" << "\n";}
void no() {cout << "NO" << "\n";}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;

    int ans = -1;
    int n = 0;
    int rem = 0;
    bool is = false;
    while(n < 1e6) {
        rem = rem*10 + 7;
        n++;
        rem = rem%k;
        if(rem == 0) {is = true; break;}
    }

    if(is) ans = n;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
use proconio::*;

#[fastout]
fn main() {
    input!(s: String);
    let ss: String = s;

    let mut min = 1_000;
    for i in 0..ss.len() - 2 {
        min = std::cmp::min(min, (753 - &ss[i..3 + i].parse::<i32>().unwrap()).abs());
    }

    println!("{}", min);
}


Measured memory_bytes: 2140
N = int(input())
inputs = [int(i) for i in input().split()]

start = inputs[0]
flag = 0
ans = 1

for i in range(1, N):
    if flag == 0:
        if start < inputs[i]:
            flag = 1
        elif start > inputs[i]:
            flag = -1
        start = inputs[i]
    elif flag == 1:
        if start > inputs[i]:
            flag = 0
            ans += 1
        start = inputs[i]
    else:
        if start < inputs[i]:
            flag = 0
            ans += 1
        start = inputs[i]

print(ans)


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int ab = a + b;
    int bc = b + c;
    int ac = a + c;
    int ans = 100000;

    ans = min(ans, ab);
    ans = min(ans, bc);
    ans = min(ans, ac);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int c[3030][3030];
char b[3030][3030];
void LCS_LENGTH(string X, string Y){
	int m=X.length();
	int n=Y.length();
	for(int i=1;i<=m;i++)
		c[i][0]=0;
	for(int j=0;j<=n;j++)
		c[0][j]=0;
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++){
			if(X[i-1]==Y[j-1]){
				c[i][j]=c[i-1][j-1]+1;
				b[i][j]='a';
			}
			else if(c[i-1][j]>=c[i][j-1]){
				c[i][j]=c[i-1][j];
				b[i][j]='b';
			}
			else{
				c[i][j]=c[i][j-1];
				b[i][j]='c';
			}
		}
}
void PRINT_LCS(string X,int m,int n){
	if(m==0||n==0)
		return;
	if(b[m][n]=='a'){
		PRINT_LCS(X,m-1,n-1);
		cout<<X[m-1];
	}
	else if(b[m][n]=='b')
		PRINT_LCS(X,m-1,n);
	else
		PRINT_LCS(X,m,n-1);
}
int main(){
	string X,Y;
	cin>>X>>Y;
	LCS_LENGTH(X,Y);
	PRINT_LCS(X,X.length(),Y.length());
	return 0;
}

Measured memory_bytes: 62700
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        A: usize,
        B: usize,
    }
    if B == 1 {
        println!("0");
    } else if A >= B {
        println!("1");
    } else {
        let mut x = 0;
        let mut b = 1;
        while b < B {
            b -= 1;
            b += A;
            x += 1;
        }
        println!("{}", x);
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl

using namespace std;

using ll = int64_t;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

template <class T>
ostream &operator<<(ostream &os, vector<T> const &vec) {
    if (vec.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr) {
    if (arr.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

namespace math {
ll gcd(ll u, ll v) {
    while (v != 0) {
        ll r = u % v;
        u = v;
        v = r;
    }
    return u;
}
ll lcm(ll m, ll n) {
    if ((0 == m) || (0 == n)) return 0;

    return ((m / math::gcd(m, n)) * n);
}
}  // namespace math

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) {}
    bool unionSet(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) { return root(x) == root(y); }
    ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    ll size(ll x) { return -data[root(x)]; }
};

template <class T, class U>
pair<T, U> operator+(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first + b.first, a.second + b.second);
}

template <class T, class U>
pair<T, U> operator-(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first - b.first, a.second - b.second);
}

ll bound(function<bool(ll)> f, ll ng, ll ok) {
    while (abs(ng - ok) > 1) {
        ll mid = (ng + ok) / 2;
        if (f(mid))
            ok = mid;
        else
            ng = mid;
    }

    return ok;
}


int main(void) {
    ll R, G, B, N;
    cin >> R >> G >> B >> N;

    ll ans = 0;
    for(ll r = 0; r <= 3000; r++) for(ll g = 0; g <= 3000; g++){
        if((N - r * R - g * G) % B != 0)
            continue;
        ll c = (N - r * R - g * G) / B;
        if(c >= 0)
            ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
int main()
{
    int n; cin >> n;
    VI a(n); rep(i, n) cin >> a[i];
    sort(ALL(a), greater<ll>());
    
    ll ans = a[0];
    int m = (n+1)/2;
    FOR(i, 1, m){
        ans += a[i]*2;
    }
    if (n%2 == 1) ans -= a[m-1];
    cout << ans << endl;
    return 0;
}

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

int N,arr[200010];

int main(){
	cin>>N;
	int total=0;
	for(int i=0; i<N; i++){
		cin>>arr[i];
		total=total^arr[i];
	}
	if(total==0){
		sort(arr,arr+N);
		if(N%3==0){
			bool pos=true;
			for(int i=0; i<N; i++){
				if(i<N/3){
					if(arr[i]!=arr[0])pos=false;
				}else if(i<2*N/3){
					if(arr[i]!=arr[N/3])pos=false;
				}else{
					if(arr[i]!=arr[2*N/3])pos=false;
				}
			}
			if(((arr[0]^arr[N/3])^arr[2*N/3])!=0)pos=false;
			if(pos){
				cout<<"Yes"<<'\n';
			}else{
				cout<<"No"<<'\n';
			}
		}else{
			if(arr[N-1]==0){
				cout<<"Yes"<<'\n';
			}else{
				cout<<"No"<<'\n';
			}
		}
	}else{
		cout<<"No"<<'\n';
	}
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=220;
ll a[N];
int Main(){
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    string s;
    cin >> s;
    vector <int> ad;
    for (int i=n;i;i--){
        ll x=a[i];
        for (auto u : ad){
            ll z= (u & (-u));
            if (x & z){
                x ^= u;
            }
        }
        /*
        if (a[2]==2){
                ll z=2;
        z &= -2;
            cout << " " << z << endl;
        }
        */
        if (x!=0){
            ad.pb(x);
            if (s[i-1]=='1'){
                kill(1);
            }
        }
    }
    kill(0);
}
int32_t main(){
    ll t;
    cin >> t;
    while(t--) Main();
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+2;
int ar[N],num[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,r,s,ans=0,lst=-1;
	cin>>n>>s;
	for(i=1;i<=n;i++){
		cin>>ar[i]>>num[i];
	}
	l=1;
	r=n;
	while(true){
		if(ar[r]<s){
			ans+=s-ar[l];
			break;
		}
		if(ar[l]>s){
			ans+=ar[r]-s;
			break;
		}
		if(num[l]>=num[r]){
			num[l]+=num[r];
			if(lst!=l){
				ans+=ar[r]-ar[l];
			}
			r--;
			lst=l;
		}
		else{
			num[r]+=num[l];
			if(lst!=r){
				ans+=ar[r]-ar[l];
			}
			l++;
			lst=r;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1792
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
  
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 1000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;

char A[N][N];

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    vector<string> a(10);
    a[3] = "a..a...aa";
    a[4] = "abccabddeeghffgh";
    a[5] = "ahhggai..fbi..fb.jjeccdde";
    a[6] = "abbc..a.ac..bba.ddc..abbc..a.a.ddbba";
    a[7] = "add...ea.c...ebbc...f...addf...a.cg...bbcgeeffgg.";
    /*rep(c, 3, 7 + 1) {
        string sss, s;
        rep(i, 0, c) {
            cin >> s;
            sss += s;
        }
        cout << "a[" << c << "] = " << '"' << sss << '"' << ";" << endl;
    }*/
    int n;
    cin >> n;
    if (n == 2) {
        cout << -1 << "\n";
        return 0;
    }
    rep(i, 0, n) {
        rep(j, 0, n) {
            A[i][j] = '.';
        }
    }
    if (n % 3 == 0) {
        rep(i, 0, n / 3) {
            rep(j, 0, 3) {
                rep(k, 0, 3) {
                    A[i * 3 + j][i * 3 + k] = a[3][j * 3 + k];
                }
            }
        }
    } else {
        int cur = n;
        while (cur >= 8) {
            rep(i, 0, 4) {
                rep(j, 0, 4) {
                    A[cur - 4 + i][cur - 4 + j] = a[4][i * 4 + j];
                }
            }
            cur -= 4;
        }
        rep(i, 0, cur) {
            rep(j, 0, cur) {
                A[i][j] = a[cur][i * cur + j];
            }
        }
    }
    rep(i, 0, n) {
        string s;
        rep(j, 0, n) {
            s += A[i][j];
        }
        cout << s << "\n";
    }
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    double x = sqrt(N);
    cout << (int)x * (int)x << endl;
}

Measured memory_bytes: 256
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string x;
            int i=0;
            string[] str = new string[10000];
            while (true)
            {
                x = Console.ReadLine();
                if (x == "0"||i > 10000){
                    for (int c = 0; c < i;c++){
                        Console.WriteLine("Case {0}: {1}",c+1,str[c]);
                    }
                        break;
                    }
                else{
                    str[i] = x;
                    i = i + 1;
                }
            }
        }
    }
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  for (int i = n; i < 1000; i++)
    if (i % 111 == 0)
    {
      cout << i << endl;
      return 0;
    }

  return 0;
}


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

#define pb push_back
#define FIO                      \
    {                            \
        ios::sync_with_stdio(0); \
        cin.tie(nullptr);        \
        cout.tie(nullptr);       \
    }
#define testCases      \
    int testCases = 0; \
    cin >> testCases;  \
    while (testCases--)
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
int main()
{
    FIO
        // testCases{

        // }
    int A, B, M;
    cin >> A >> B >> M;
    int a[A], b[B];
    for (int i = 0; i < A; ++i)
        cin >> a[i];
    for (int i = 0; i < B; ++i)
        cin >> b[i];
    int mA = a[0], mB = b[0];
    for (int i = 0; i < A; ++i)
    {
        if (a[i] < mA)
            mA = a[i];
    }
    for(int i=0; i<B; ++i){

        if (b[i] < mB)
            mB = b[i];
    }
    int alt = mA + mB;
    int cost[M];
    for (int i = 0; i < M; ++i)
    {
        int x, y, c;
        cin >> x >> y >> c;
        cost[i] = a[x - 1] + b[y - 1] - c;
    }
    int answer;
    if (M != 0)
        answer = cost[0];
    else
        answer = alt;
    for (int i = 0; i < M; ++i)
    {
        if (cost[i] < answer)
            answer = cost[i];
    }
    if (answer < alt)
        cout << answer << endl;
    else
        cout << alt << endl;
}

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

int main(){
  double a,b,c,d,e,f;
  while(cin >> a >> b >> c >> d >> e >> f){
    double x = (e*c - b*f)/(e*a - b*d) + 1e-10;
    double y = (d*c - a*f)/(d*b - a*e) + 1e-10;
    cout << fixed << setprecision(3) << x << " " << y << endl;
  }
} 

Measured memory_bytes: 1284
N = int(input())
W = [input() for i in range(N)]

memo = [W[0]]
OK = True
pre = W[0]
for word in W[1:]:
    if word in memo or pre[-1] != word[0]:
        OK = False
        print("No")
        break
    memo.append(word)
    pre = word
if OK:
    print("Yes")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
int main()
{
  string s,t;
  cin >> s >> t;
  
  int cnt = 0;
  REP(i,s.size()){
    if(s[i] != t[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3916
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;


int main(){
	int n = 0;
	while(cin >> n && n != 0){
		int count = 0;
		for(int i = 1; i <= n; i++){
			int sum = 0;
			int seq = 0;
			for(int j = i; j <= n; j++){
				sum += j;
				seq++;
				if(sum == n && seq >= 2) count++;
				if(sum > n) break;
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;


int main() {
	int N; cin >> N;
	vector<ll> a(N), b(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	ll ans = 0;
	if (N % 2) ans = b[N / 2] - a[N / 2];
	//else ans = 2 * ((b[N / 2] + b[N / 2 - 1]) / 2 - (a[N / 2] + a[N / 2 - 1]) / 2);
	else ans = b[N / 2] + b[N / 2 - 1] - (a[N / 2] + a[N / 2 - 1]);
	cout << ans+1 << endl;
	
}

Measured memory_bytes: 6436
let range a b =
  let rec range' n acc =
    if a > n then
      acc
    else
      range' (n-1) (n::acc) in
   range' b []

exception InvalidInput

let () =
  let line = read_line () in
  let (a, b, c) = line |>
                  Str.split (Str.regexp " ") |>
                  List.map int_of_string |>
                  (function | [a; b; c] -> (a, b, c)
                            | _ -> raise InvalidInput) in
  let result = range a b |>
               List.filter (fun i -> c mod i = 0) |>
               List.length in
  print_endline (string_of_int result)

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

int main() {
  int A,B;
  cin >>A>>B;
  int sum =max(A,B);
  if(A == B)
    sum += max(A,B);
  if(A > B)
    sum += max(A-1,B);
  if(A <B)
    sum += max(A,B-1);
    
  cout << sum << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC150B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            var cnt = 0;
            var index = 0;
            while (true)
            {
                if ((index = s.IndexOf("ABC", index) + 1) != 0)
                {
                    cnt++;
                }
                else
                {
                    break;
                }
            }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13404
from collections import deque
h,w=map(int,input().split())
ans=0
field=[["*" for i in range(w+2)]]+[["*"]+list(input())+["*"] for i in range(h)]+[["*" for i in range(w+2)]]
queue=deque([])
for H in range(h+2):
    for W in range(w+2):
        if field[H][W]=="#":
            queue.append((H,W))
            field[H][W]=0
        elif field[H][W]==".":
          field[H][W]=-1
move=[(0,1),(0,-1),(1,0),(-1,0)]
ans=0
while queue:
    pos=queue.popleft()
    for i in move:
      if field[pos[0]+i[0]][pos[1]+i[1]]!=-1:continue
      if field[pos[0]+i[0]][pos[1]+i[1]]=="*":continue
      field[pos[0]+i[0]][pos[1]+i[1]]=field[pos[0]][pos[1]]+1
      queue.append((pos[0]+i[0],pos[1]+i[1]))
      if ans < field[pos[0]+i[0]][pos[1]+i[1]]:ans=field[pos[0]+i[0]][pos[1]+i[1]]
print(ans)


Measured memory_bytes: 135644
#import<cstdio>
#define k 1024
#define r(a) for(int i=0;i<a;i++)
#define s(a) scanf("%d",a);
#define c(a,b) a=a<b?a:b
int w,n,m,d[k],p[k];main(){s(&n)s(&m)r(n)s(d+i)r(n)p[i]=1e9;r(m){s(&w)r(n)c(p[i],p[i+1]+w*d[n-i-1]);}printf("%d\n",p[0]);}

Measured memory_bytes: 1032
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val Array(w, a, b) = sc.nextLine.split(" ").map(_.toInt)
    val Array(aOne, aTwo, bOne, bTwo) = Array(a, a + w, b, b + w)
    if ((aOne <= bOne & bOne <= aTwo) | (aOne <= bTwo & bTwo <= aTwo)) println(0)
    else println(Array(math.abs(bOne - aOne), math.abs(bOne - aTwo), math.abs(bTwo - aOne), math.abs(bTwo - aTwo)).min)
  }
}


Measured memory_bytes: 27456
X, N = map(int,input().split())
P = list(map(int,input().split()))

if N == 0:
    print(X)
    exit()

for i in range(N+1):
    if X - i not in P:
        print(X-i)
        exit()
    elif X + i not in P:
        print(X+i)
        exit()
print(-1)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
const int INF = 1e9;
const llint llINF = 1e18;

int main () {
    llint h; cin >> h;
    llint ans = 1;
    while (h > 0) {
        h = floor(h / 2);
        ans *= 2;
    }

    cout << ans - 1<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int N,M; cin >> N >> M;
  vector<ll> mem(N+10,0);
  rep(i, M) {
    int A; cin >> A;
    mem[A] = -1;
  }
  mem[0] = 1;
  rep(i, N+1) {
    if(mem[i] >=0 ) {
      if(mem[i+1] >= 0) mem[i+1] = (mem[i]+mem[i+1])%MOD;
      if(mem[i+2] >= 0) mem[i+2] = (mem[i]+mem[i+2])%MOD;
    }
  }
  cout << mem[N] << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a, &b, &c);
	if ((a >= b) && (a >= c)) {
		if (b > c) {
			printf("%d %d %d\n", c, b, a);
		} else {
			printf("%d %d %d\n", b, c, a);
		}
	} else if ((b >= a) && (b >= c)) {
		if (a > c) {
			printf("%d %d %d\n", c, a, b);
		} else {
			printf("%d %d %d\n", a, c, b);
		}
	} else {
		if (a > b) {
			printf("%d %d %d\n", b, a, c);
		} else {
			printf("%d %d %d\n", a, b, c);
		}
	}
	
	return 0;
}

Measured memory_bytes: 596
///
// File:  a.go
// Author: ymiyamoto
//
// Created on Wed Jan  9 16:14:59 2019
//
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var N int
	fmt.Scan(&N)

	n := strconv.Itoa(N)
	for i := range n {
		if n[i] != n[len(n)-1-i] {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void abc_160a();

void abc_161a();

void abc_162a();

void abc_163a();

int main()
{
  //abc_160a();
  //abc_161a();
  //abc_162a();
  abc_163a();

}

void abc_160a()
{
  string S;
  cin >> S;

  if (S[2] == S[3] && S[4] == S[5]) cout << "Yes\n";
  else cout << "No\n";
}

void swap(int& a, int& b)
{
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

void abc_161a()
{
  int x, y, z;
  cin >> x >> y >> z;

  swap(x, y);
  swap(x, z);

  cout << x << " " << y << " " << z << "\n";
}

void abc_162a()
{
  string s;
  cin >> s;
  for (char c : s)
  {
    if (c == '7')
    {
      cout << "Yes\n";
      return;
    }
  }

  cout << "No\n";
}

void abc_163a()
{
  int R;
  cin >> R;

  cout << (double)(2 * R * M_PI);
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define pb push_back
typedef long long ll;
const ll INF = 1e18;
const int MOD = 1e9+7;
const int N = 1e6+9;

#define fast()    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int ar[100005],br[100005];

int main()
{
    fast();
    ll t, num, x, y, z, c0=0, c1=0, sum=0, ans=0, res=0, m0;
    sf("%lld",&num);
    while(num!=0)
    {
        num=num>>1;
        c0++;
    }
    cout << (1LL<<c0)-1 <<endl;
    //main();
}


Measured memory_bytes: 256
#define  _USE_MATH_DEFINES
#define  _USE_MATH_DEFINES

#define  rep(i, n) for(int i = 0; i < n; i++)
#define  repx(i, a, n) for(int i = a; i < n; i++)
#define  loop while(1)
#define  lli long long int
#define  aryout(ary) rep(i, ary.size()) cout << ary[i] << (i < ary.size() - 1 ? " " : "\n");
#define  TO_STRING(VariableName) # VariableName
#define  vout(value) cout << TO_STRING(value) << ": " << value << endl;
 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;

int main() {

  string mnt; cin >> mnt;
  stack<int> stall;

  int sz  = mnt.size();
  int ans = 0;
  stack<pair<int, int>> stsub;

  rep (i, sz) {
    char c = mnt[i];

    if (c == '\\') {
      stall.push(i);

    } else if (c == '/' && !stall.empty()) {
      int left = stall.top();

      ans += i - left;
      stall.pop();
  
      pair<int, int> tmp; //{left index of the leftest ike, total amount of ike}
      tmp.first = left;
      tmp.second = i - left;

      while (!stsub.empty() && left < stsub.top().first) {

        pair<int, int> ike = stsub.top();

        tmp.second += ike.second;
        stsub.pop();
      }
      stsub.push(tmp);
    }
  }

  cout << ans << endl;

  vector<int> ans2;
  while (!stsub.empty()) {
    ans2.push_back(stsub.top().second);
    stsub.pop();
  }
  if (ans2.size() > 0) {
    cout << ans2.size() << " ";
    reverse(ans2.begin(), ans2.end());
    aryout(ans2);
  } else
    cout << 0 << endl;

  return 0;
}



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

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

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; }

typedef long long ll;

using namespace std;
ll mod=1e9+7;
ll modn(ll a,ll mod)
{
  a%=mod;
  if(a<0)a+=mod;
  return a;
}
vector<ll> mem(10,0);
long long modinv(long long a,long long mod)
{
  if(a<=9 && mem[a]>0)return mem[a];
  long long cnt=a,res=1;
  long long m=mod-2;
  while(m>0)
  {
    if(m%2)res*=cnt;
    cnt=cnt*cnt;
    cnt%=mod;
    res%=mod;

    m>>=1;
  }
  //cout<<a<<"modinv"<<res<<endl;
  if(a<=9)mem[a]=res;
  return res;
}
ll c(ll num,ll d)
{
  if(num==1 || num==d || d==0)return 1;
  return modn(modn(c(num-1,d-1)*num,mod)*modinv(d,mod),mod);
}

int  main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  ll n,m;
  cin>>n>>m;
  map<ll,ll> pd;
  ll sqrtm=sqrt(m)+1;
  ll tm=m;
  repi(i,2,sqrtm+1000)
  {
    while(tm%i==0){pd[i]++;tm/=i;}
    if(tm==1)break;
  }
  if(tm>1)pd[m]++;
  ll res=1;
  for ( auto p : pd)
  {
    //cout<<p.first<<" "<<p.second<<endl;
    res=modn((ll)res*c(p.second+n-1,p.second),mod);
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main(){
    ll N,r=0,g=0,b=0,count=0;
    string S;
    cin >> N >> S;
    rep(i,N){
        if(S.at(i)=='R'){
            r++;
        }
        else if(S.at(i)=='G'){
            g++;
        }
        else{
            b++;
        }
    }
    for(ll i=0; i<N;i++){
        for(ll j=i+1; j<N; j++){
            if(S.at(i)==S.at(j)){
                continue;
            }
            ll wakabayashi=j+j-i;
            if(!(wakabayashi<=N-1)){
                continue;
            }
            if(S.at(i)!=S.at(j) && S.at(j)!=S.at(j+j-i) && S.at(i)!=S.at(j+j-i)){
                    count++;
            }

            
        }
    }

    cout << r*g*b - count << endl;
    }



Measured memory_bytes: 3620
n,m = map(int,input().split(" "))
ar = [[] for i in range(n)]
br = [0 for i in range(n)]
for i in range(m):
    x,y = map(int,input().split(" "))
    ar[x-1].append(y-1)
    ar[y-1].append(x-1)
cr = [0]
dr = []
for r in cr:
    for i in ar[r]:
        if br[i] == 0:
            br[i] = r + 1
            cr.append(i)
print("Yes")
for i in range(1,n):
    print(br[i])

Measured memory_bytes: 37504
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n, k;
	cin >> n >> k;
	vector<int> le(n);
	REP(i, n) cin >> le[i];
	sort(le.begin(), le.end());
	REP(i, k) ans += le[n-1-i];
	cout << ans << endl;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<pair<string, pair<int, int>>> v(n);
  rep (i, n) {
    string s;
    int p;
    cin >> s >> p;
    v[i] = mp(s, mp(-p, i + 1));
  }

  sort(all(v));

  rep (i, n) cout << v[i].S.S << endl;
}


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

int main(){
  int N,K;
  cin>>N>>K;
  int A[N];
  for (int i=0;i<N;++i){
    cin>>A[i];
  }  
  int ans=0;
  for (int i=0;i<N;++i){
    if (A[i]>=K) ++ans;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main() {
	long long n,m,ans=0;
	cin >> n >> m;
	if (n * 2 > m) {
		ans = m / 2;
	}
	else {
		ans += n;
		m -= n * 2;
		ans += m / 4;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
int main(){
  int w,h,x,y,r;
  std::cin >> w >> h >> x >> y >> r;
  bool flag = (w >= x + r && h >= y + r && 0 <= x - r && 0 <= y - r);
  std::cout << (flag ? "Yes" : "No") << std::endl;
  return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s;
	cin >> s;
	int n = s.size();
	int c = 0;
	for(int i = 0; i < n/2; i++) {
		if (s[i] != s[n - i - 1]){
			c++;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    char com[20];
    int i;
    priority_queue<int> PQ;
    while(1){
        scanf("%s",com);
        if(com[0]=='i'){
            scanf("%d",&i);
            PQ.push(i);
        }
        else if(com[1]=='x'){
            cout << PQ.top() << endl;
            PQ.pop();
        }
        else if(com[0]=='e'){
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 7092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=100005;
int fa[N],a[N],to[N];
PI q[N];
inline int gf(int x){
	return fa[x]==x?x:fa[x]=gf(fa[x]);
}
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	int n=read(),m=read();
	For(i,0,n-1)a[fa[i]=i]=read();
	For(i,1,m){
		int x=read(),y=read();
		fa[gf(x)]=gf(y);
	}
	For(i,0,n-1)q[i]=mp(a[i],gf(i));
	sort(q,q+n);
	int t=n-m-1,dq=2*t;
	if(!t){
		puts("0"); return 0;
	}
	ll ans=0;
	For(i,0,n-1)if(!to[q[i].se]){
		to[q[i].se]=1; ans+=q[i].fi; q[i].se=n; dq--;
	}
	to[n]=1e9;
	for(int i=0;i<n&&dq;i++)if(to[q[i].se]<t){
		to[q[i].se]++;
		dq--;
		ans+=q[i].fi;
	}
	if(dq)puts("Impossible"); else cout<<ans<<endl;
}

Measured memory_bytes: 6404
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <map>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> a(n);
    REP(i, 0, n) {
        cin >> a[i];
        sort(a[i].begin(), a[i].end());
    }
    map<string, ll> m;
    ll ans = 0;
    REP(i, 0, n) {
        ans += m[a[i]];
        m[a[i]]++;
    }
    cout << ans << endl;
    return 0;
}


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

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) 
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) 
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) 
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) 
#define forrc(i,l,r) for (int i= (int)(r); i>= (int)(l); --i)

#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define all(x) (x).begin(), (x).end() 
#define rall(x) (x).rbegin, (x).rend() 


#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)


#define present(c,x) ((c).find(x) != (c).end())


#define cpresent(c,x) (find(all(c),x) != (c).end())

#define sz(a) int((a).size())

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
typedef long long ll;
typedef unsigned long long int ull;

const int MOD=1000000007;

void add_self(int &a, int b){
  a+=b;
  if(a>=MOD){
    a-=MOD;
  }
}

void sub_self(int &a, int b){
  a-=b;
  if(a<0){
    a+=MOD;
  }
}

int main(){
  fastio; 
  
  int n;
  cin >> n;
  vi a(n);
  for0(i,n) cin >> a[i];
  ll dp[n][n];
  ll prev[n][n];
  int l,r;
  for0(i,n){
    l=0;r=i;
    while(r<n){
      if(l==r){
        dp[l][r]=a[l];
      }else if(l+1==r){
        dp[l][r]=a[l]+a[r];
        prev[l][r]=a[l]+a[r];
      }else{
          dp[l][r]=dp[l][l]+dp[l+1][r];
          prev[l][r]=prev[l+1][r];
        forc(j,l,r-1){
          if(dp[l][r]+prev[l][r]>dp[l][j]+dp[j+1][r]+(l==j?0:prev[l][j])+(j+1==r?0:prev[j+1][r])){
            dp[l][r]=dp[l][j]+dp[j+1][r];
            prev[l][r]=(l==j?0:prev[l][j])+(j+1==r?0:prev[j+1][r]);
          }
        }
        prev[l][r]+=dp[l][r];
      }
      l++;
      r++;
    }
  }
  cout << prev[0][n-1];
}

Measured memory_bytes: 2816