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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define ll long long
#define ld long double
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 2e5 + 10;
const int inf = 1e9 + 7;

int x;
ll c;

main()
{
    cin >> x;
    for(int i = 1 ; i <= 1000000 ; i ++)
    {
        c += i;
        if(c >= x)
        {
            cout << i << endl;
            return 0;
        }
    }

}


Measured memory_bytes: 256
isPrime=[1 for i in range(10**6+1)]
isPrime[0]=0;isPrime[1]=0
for i in range(2,10**6+1):
    if isPrime[i]==0:
        continue
    for j in range(2*i,10**6+1,i):
        isPrime[j]=0
X=int(input())
for i in range(X,10**6+1):
    if isPrime[i]==1:
        print(i)
        exit()


Measured memory_bytes: 16904
N,M,C = list(map(int,input().split()))
B = list(map(int,input().split()))
A = []
for i in range(N):
    A_p = list(map(int,input().split()))
    A.append(A_p)
cnt = 0
for A_q in A:
    siki = C
    for i in range(M):
        siki += A_q[i]*B[i] 
    if siki > 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
def cc136
    n = gets.chomp.to_i
    h = gets.chomp.split(/\s/).map{|x| x.to_i}

    if n == 1
        puts 'Yes'
        exit
    end

    if n == 2
        puts h[0]-1 <= h[1] ? 'Yes' : 'No'
        exit
    end

    for i in 1..(n-1)
        j = n - i
        if h[j-1]-1 == h[j]
            h[j-1] -= 1
        end
        if h[j-1] > h[j]
            puts 'No'
            exit
        end
    end

    puts 'Yes'
end

cc136

Measured memory_bytes: 9612
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let mut a: Vec<usize> = parse_line().unwrap();
    let mut ans = 0;

    a.sort();
    for i in 0..n {
        ans += a[3 * n - 1 - 2 * i - 1];
    }
    println!("{}", ans);
}


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

using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int n,k;
    cin >> n >> k;
    int a[n];
    vector <int> dp(n,2e9);

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

    dp[0]=0;
    for (int i=0;i<n;i++)
        for (int j=i+1;j<=i+k;j++)
        if (j<n)
        dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));

    cout << dp[n-1];
}


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

int a[10]={0};
int b[10]={0};
int c[10]={0};
int main()
{
    cin.tie(NULL);
    int res=0,res2=0,num=0,aa=-1,bb=-1;
    int x;
    cin>>x;
    for(int i=1;i<=x;i++)
    {
        a[i]=i;
        cin>>b[i];
    }
    for(int i=1;i<=x;i++)
    {
        cin>>c[i];
    }
    do{
        if(aa!=-1&&bb!=-1)
        break;
        num++;
        if(res==0)
        {
            int flag=1;
            for(int i=1;i<=x;i++)
            {
                if(a[i]!=b[i])
                {
                    flag=0;
                    break;
                }
            }
            if(flag==1)
            {
                aa=num;
                res=1;
            }
        }
        if(res2==0)
        {
            int flag=1;
            for(int i=1;i<=x;i++)
            {
                if(a[i]!=c[i])
                {
                    flag=0;
                    break;
                }
            }
            if(flag==1)
            {
                bb=num;
                res2=1;
            }
        }
    }while(next_permutation(a+1,a+x+1));
    cout<<abs(aa-bb);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int a[3];

int gcd(int x, int y){
		if(y == 0)return x;
		else return gcd(y, x % y);
}

void calc(int x){
		for(int i = 1; i <= x; i++){
				if(x % i == 0)cout << i << endl;
		}
}

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)cin >> a[i];
	int gc = gcd(a[0], a[1]);
	if(n == 3)gc = gcd(gc, a[2]);
	calc(gc);
	return 0;
}



Measured memory_bytes: 3104
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<i64>();
    let b = read::<i64>();
    println!("{}", std::cmp::max(0, a - 2 * b));
}


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

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

	for (int x = 1; x <= 50000; x++) {
		if (static_cast<int>(static_cast<double>(x) * 1.08) == N) {
			cout << x << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n, k, c; cin >> n >> k >> c;
    string s; cin >> s;
    
    vi l(n, 0);
    int now = 1;
    rep(i, n){
        if(now > k) break;
        if(s[i] == 'o'){
            l[i] = now;
            now++;
            i += c;
        }    
    }
    
    vi r(n, 0);
    now = k;
    rep3rev(i, n-1, 0){
        if(now < 0) break;
        if(s[i] == 'o'){
            r[i] = now;
            now--;
            i -= c;
        }
    }
    
    /*
    cout << s << endl;;
    rep(i, n) cout << l[i];
    cout << endl;
    rep(i, n) cout << r[i];
    */
    
    vi ans;
    
    rep(i, n){
        if(l[i] == r[i] && l[i] != 0) ans.pb(i+1);
    }
    
    for(auto x : ans){
        cout << x << endl;
    }
    
    return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 5996
import Control.Applicative
import Control.Monad
import Data.Array

main = do
	n <- readLn
	ls <- map (map read.words) <$> replicateM n getLine
	putStrLn.show $ maximum (dp ls)

dp (l:ls) = foldl happy l ls
happy [a,b,c] [va,vb,vc] = [va+max b c,vb+max a c,vc+max b a]

Measured memory_bytes: 157052
N = int(input())

S, T = [], []
for i in range(N):
    s, t = input().split()
    S.append(s)
    T.append(int(t))
X = str(input())

for i in range(N):
    if S[i] == X:
        sleep = i
time = 0

for i in range(sleep+1,N):
    time += T[i]

print(time)

Measured memory_bytes: 38384
def search_end(arr, start)
  now = start

  arr.each do |row|
    if row[1] == now
      now = row[2]
    elsif row[2] == now
      now = row[1]
    end
  end

  now
end

loop do
  n, m, a = gets.chomp.split(" ").map(&:to_i)
  break if n + m + a == 0
  amida = []

  m.times do
    amida << gets.chomp.split(" ").map(&:to_i)
  end

  puts search_end(amida.sort { |a, b| b[0] <=> a[0] }, a)
end

Measured memory_bytes: 8776
#include<stdio.h>
 int main(void)
 {
     int N,s,t;

     scanf("%d",&N);

       s=N%100;
       t=s%10;

     if(t==2) printf("hon\n");
     if(t==4) printf("hon\n");
     if(t==5) printf("hon\n");
     if(t==7) printf("hon\n");
     if(t==9) printf("hon\n");

     if(t==0) printf("pon\n");
     if(t==1) printf("pon\n");
     if(t==6) printf("pon\n");
     if(t==8) printf("pon\n");

     if(t==3) printf("bon\n");

     return 0;
 }


Measured memory_bytes: 1644
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef unsigned long long ll;
typedef long double ld;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
ll n, m, x, y, q, d, z, w, sum = 0, ans = 0;
const int MOD = 1000000007;
vector<int> a, b;
priority_queue<pair<ll, int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
int main(void) {
	cin >> n;
	req(k, 360) {
		if (n * k % 360 == 0) {
			cout << k << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  if (A + B < C + D) {
    cout << "Right" << endl;
  }
}

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int x, y;
  int ans;

  scanf("%d %d",&x, &y);

  if ((x < 0 && y < 0 && y < x) || (0 < x && 0 < y && y < x)) ans = abs(x - y) + 2;
  else if ((0 < x && 0 < y && x < y) || (x < 0 && y < 0 && x < y)) ans = y - x;
  else if (x == 0 && 0 < y) ans = y;
  else if (x < 0 && y == 0) ans = abs(x);
  else ans = abs(abs(x) - abs(y)) + 1;

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


Measured memory_bytes: 256
import numpy as np

n, k = map(int, input().split())
xyc = [list(input().split()) for _ in range(n)]

b = np.zeros((3 * k - 1, 2 * k - 1), np.int64)

for x, y, c in xyc:
    x = int(x)
    y = int(y)

    q, r = divmod(x, k)
    if q % 2:
        y += k
    x = r

    if c == "W":
        y += k

    y %= 2 * k

    b[y][x] += 1

b[:k, k:] = b[k:2*k, :k-1]
b[k:2*k, k:] = b[:k, :k-1]
b[2*k:, :] = b[:k-1, :]

b = np.pad(b, (1, 0), "constant")

b = np.cumsum(b, axis=0)
b = np.cumsum(b, axis=1)

cnt = b[k:, k:] - b[k:, :-k] - b[:-k, k:] + b[:-k, :-k]
ans = cnt.max()
print(ans)


Measured memory_bytes: 225388
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
typedef long long ll;
using namespace std;

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 long long INF = 1LL << 60;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
ll ma = 1000000000 + 7;


ll n;ll h[100010];ll dp[100010];

int main() {
	cin >> n;
	for (ll i = 0;i < n;i++) {
		cin >> h[i];
	}
	for (int i = 0;i < n;i++) {
		dp[i] = INF;
	}
	dp[0] = 0;
	for (int i = 1;i < n;i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1) {
			chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
		}
	}
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll MOD = 1000000007;
const int MAX = 100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }


int main(){
    int a,b; cin >> a >> b;
    if(a>b){
        for(int i=0;i<a;i++){
            cout << b;
        }
        cout << "\n";
    }else{
        for(int i=0;i<b;i++){
            cout << a;
        }
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)
#define mod 1000000007
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

vector<P> count_runlength(int* a, int* b){
	vector<P> v;
	for (int* p = a; p < b;){
		int* q = p;
		while (q < b && *p == *q) q++;
		v.push_back(P(*p, q - p));
		p = q;
	}

	return v;
}

signed main(){

	int N, a[100000];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	sort(a, a + N, greater<int>());

	int area = 1, c = 0;
	for (int i = 0; i < N; i++){
		if (i + 1 < N && a[i] == a[i + 1]){
			area *= a[i]; c++;
			if (c == 2) break;
			i++;
		}
	}

	if (c == 2) cout << area << endl;
	else cout << 0 << endl;

	return 0;
}


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
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...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n+1,-1);
  rep(i,1,n+1)cin>>a[i];
  rep(i,0,n){
    if(a[i]+1<a[i+1])judge=false;
    if(a[i]+1==a[i+1])res++;
    else{
      res+=a[i+1];
    }
  }
  if(judge){
    cout<<res-1<<endl;
  }
  else cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 1792
N = int(input().strip())

list = [input().strip().split() for i in range(N)]

from operator import itemgetter

sort1 = sorted(list, key=lambda x: int(x[1]), reverse=True)
sort2 = sorted(sort1, key=itemgetter(0))

for i in range(N):
    print(list.index(sort2[i]) + 1)


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

int main() {
    int n;
	cin>>n;
	vector<int >a(n + 1),b(n + 1);
    
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    
    for(int i = n; i >= 1; i--) {
        int sum = 0;
        for(int j = i+i; j <= n; j += i) {
            sum ^= b[j];
        }
        
        b[i] = sum ^ a[i];
    }
    
    
    vector<int> ans;
    for(int i = 1; i <= n; i++) {
        if(b[i]) ans.push_back(i);
    }
    
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); ++i) {
        printf("%d%c", ans[i], i+1==ans.size()?'\n':' ');
    } 
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(name, stop) for (ll(name) = 0; (name) < (stop); (name)++)
using ll = long long;
using vi = vector<ll>;

ll func(const vi& x, ll p) {
    return accumulate(begin(x), end(x), 0LL, [p](ll l, ll r) -> ll { return l + pow(r - p, 2); });
}

int main(void) {
    ll n;
    cin >> n;
    vi x(n);
    REP(i, n) {
        cin >> x[i];
    }
    ll ave = floor(accumulate(begin(x), end(x), 0LL) / n);
    ll ans = min(func(x, ave), func(x, ave + 1));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

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

	int len = s.length();

	int ns = 0;
	int cnt = 0;
	int bef = 0;//前のiで消去がおこなわれたか
	REP(i, len) {

		if (s[i] == 'S') {
			if(bef==0) ns++;//Sを蓄える
			else {
				ns++;
				bef = 0;
			}
		}

		if (s[i] == 'T') {
			if (ns > 0) {//消去を行う
				ns--;
				cnt++;
				bef = 1;
			}
			else {//Sのたくわえを消す
				//ns = 0;
				bef = 0;
			}
		}

	}

	cout << len - 2 * cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef vector<int>V;
int main(void){
	int n,m;
	int box[10]={512,256,128,64,32,16,8,4,2,1};
	int sum;
	V v;
	int i;
	while(1){
		cin>>n;
		if(cin.eof())	break;
		m=0;
		v.clear();
		while(1){
			if(n==0||m==10)	break;
			if(n-box[m]>=0){
				//cout<<box[m]<<endl;
				n-=box[m];
				v.push_back(box[m]);
			}
			//cout<<"N="<<n<<"M="<<m<<endl;
			m++;
		}
		reverse(v.begin(),v.end());
		for(i=0;i<(int)v.size();i++){
			if(i)	cout<<" ";
			cout<<v[i];
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
ll u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
ll d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int f(ll a){
  for(int i=2;i<=sqrt(a);i++)if(a%i<1)return 0;
  return 1;
}
int main(void){
  int n;
  scanf("%d",&n);
  int a[n];
  FOR(n)scanf("%d",&a[i]);
  qsort(a,n,sizeof(int),u);
  PRN((a[n-1]-a[0]+(a[n-1]-a[0])%2)/2);
  return 0;
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
//typedef long long int;
const ll M = 1000000007;
ll A, B, C, D, G, H, N, L, K, P, Q, R, W, X, Y, Z;
string S, T;

signed main(){
	std::cin >> S;
	std::cout << S.substr(0,3)<< std::endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;

int n, a[100005], flag[100005];
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	int x = a[1];
	int sum = 0;
	while(1) {
		sum++;
		if(flag[x] == 1)  {
			sum = 0;
			break;
		}
		if(x == 2) break;
		flag[x] = 1;
		x = a[x];
	}
	if(sum == 0) printf("-1\n");
	else printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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 MAX_N = 100000;
const int INF = 1000000000;

int main() {
    vector<int> amount = {1};
    int a = 6;
    while (a <= MAX_N) {
        amount.push_back(a);
        a *= 6;
    }
    a = 9;
    while (a <= MAX_N) {
        amount.push_back(a);
        a *= 9;
    }

    // input
    int N; cin >> N;

    // initialize DP table
    int dp[2 * MAX_N + 1];
    for (int i = 0; i <= 2 * MAX_N; i++) dp[i] = INF;

    // initial condition
    dp[0] = 0;

    for (int i = 0; i <= MAX_N; i++) {
        for (int j = 0; j < amount.size(); j++) {
            chmin(dp[i + amount[j]], dp[i] + 1);
        }
    }

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

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;

int main(){
string s,t,ans;
    int n=0;
    cin>>s>>t;
    ans="UNRESTORABLE";
    for(int i=s.size()-t.size();i>=0;i--){
        for(int j=0;j<=t.size();j++){
            if(j<t.size()&&t[j]!=s[i+j]&&s[i+j]!='?'){
                break;
            }
            else if(j==t.size()){
                n=i;
                ans=s;
            }
        }
        if(ans!="UNRESTORABLE"){
            break;
        }
    }    
    for(int i=n;i<n+t.size();i++){
       if(ans[i]=='?'){
           ans[i]=t[i-n];
       }
    }
    for(int i=0;i<s.size();i++){
       if(ans[i]=='?'){
           ans[i]='a';
       }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>


using namespace std;


int main()
{
	long double x1, y1, x2, y2;

	cin >> x1 >> y1 >> x2 >> y2;

	cout << fixed;
	cout << sqrt(pow(fabs(x1 - x2), 2) + pow(fabs(y1 - y2), 2)) << endl;

	return 0;
}


Measured memory_bytes: 3288
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
  
#define PI 3.1415926535
  
typedef struct{
  double x;
  double y;
}Point;
  
void KochCurve(Point,Point,int);
  
int main(void){
  int n;
  Point p1={0,0};
  Point p2={100,0};
  
  scanf("%d", &n);
  
  printf("%.8f %.8f\n", p1.x, p1.y);
  KochCurve(p1,p2,n);
  printf("%.8f %.8f\n", p2.x, p2.y);
  
  return 0;
}
  
void KochCurve(Point p1, Point p2, int n){
  Point p3,p4,p5;
  
  if(n==0) return;
  
  p3.x=(2*p1.x+p2.x)/3.0;
  p3.y=(2*p1.y+p2.y)/3.0;
  p4.x=(p1.x+2*p2.x)/3.0;
  p4.y=(p1.y+2*p2.y)/3.0;
  p5.x=(p4.x-p3.x)*cos(PI/3)-(p4.y-p3.y)*sin(PI/3)+p3.x;
  p5.y=(p4.x-p3.x)*sin(PI/3)+(p4.y-p3.y)*cos(PI/3)+p3.y;
  
  KochCurve(p1,p3,n-1);
  printf("%.8f %.8f\n", p3.x, p3.y);
  KochCurve(p3,p5,n-1);
  printf("%.8f %.8f\n", p5.x, p5.y);
  KochCurve(p5,p4,n-1);
  printf("%.8f %.8f\n", p4.x, p4.y);
  KochCurve(p4,p2,n-1);
  
  return;
}


Measured memory_bytes: 2044
#include <stdio.h>

int main(void) {
	int n,i,j,k;
	int b,f,r,v;
	int house[4][3][10]={};

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d %d %d %d%*c",&b,&f,&r,&v);

		house[b-1][f-1][r-1]+=v;
	}
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				printf(" %d",house[i][j][k]);
			}
			printf("\n");
		}
		if(i!=3){
			printf("####################\n");
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 10;
int num[maxn];
int main(void) {
    std::ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, k, x;
    while(cin >> n >> k) {
        memset(num, 0, sizeof(num));
        int kind = 0;
        for(int i = 0; i < n; ++i) {
            cin >> x;
            if(!num[x]) ++kind;
            num[x]++;
        }
        if(kind <= k) {
            cout << 0 << endl;
            continue;
        }
        sort(num, num + n + 1, greater<int>());
        int cnt = 0;
        for(int i = k; i < kind; ++i) cnt += num[i];
        cout << cnt << endl;
    }
}


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

int main() {
  int S, s1, s2, s3;
  cin >> S;
  s1 = S / 100;
  s2 = (S - s1 * 100) / 10;
  s3 = S - 100 * s1 - 10 * s2;
  cout << s1 + s2 + s3 << endl;
}

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

ll dist[100005]={};
vector<ll> edgelist[100005];
ll indegree[100005]={};
ll visited[100005]={};

void dfs(ll node)
{
    if(visited[node]==1) return;
    for(ll i=0;i<edgelist[node].size();i++)
    {
        dist[edgelist[node][i]]=max(dist[edgelist[node][i]], 1 +dist[node]);
        indegree[edgelist[node][i]]--;
        if(indegree[edgelist[node][i]]==0) dfs(edgelist[node][i]);
    }
    visited[node]=1;
}

int main()
{
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        edgelist[x].push_back(y);
        indegree[y]++;
    }
    for(ll i=1;i<=n;i++)
    {
        if(indegree[i]==0) dfs(i);
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ans = max(ans, dist[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 12800
// AOJ 1275

#include <iostream>

using namespace std;

int main(void)
{
	int n, k, m;
	while (cin >> n >> k >> m){
		if (n == 0 && k == 0 && m == 0) break;
		int dp[10050] = {0};
		for (int i = 2; i <= n; i++){
			if (i == n){
				dp[i] = (dp[i-1] + m) % i;
			}
			else {
				dp[i] = (dp[i-1] + k) % i;
			}
		}
		cout << dp[n] + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main(void){
    int H,W,h,w;
    cin >> H >> W;
    cin >> h >> w;
    cout << H*W-h*W-w*(H-h) << endl;
    return 0;
}


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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e&1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) { return 0; }
    if (n == r || r == 0) { return 1; }
    r = min(r, n-r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * (n-i+1))/(i); 
    }
    return ans;
}

ll nCr(tuple<ll,ll> t) {
    auto n = get<0>(t);
    auto k = get<1>(t);
    return nCr(n+k-1, k);
}

template<typename T>
void print(const T &v) {
    cout << v << " ";
}

template<typename T>
void print(const vector<T> &v) {
    for (auto &i : v) {
        print(i);
    }
    cout << endl;
}

void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for (auto &i : h) {
        cin >> i;
    }
    vector<ll> dp(n, LLONG_MAX);
    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        for (int j = 1; j <= k && i-j >= 0; ++j) {
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n-1] << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef D_LOCAL
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

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

int main() {

    int N;
    cin >> N; 
	vector<ll> A(N);
	ll total = 0;
	for(int i=0;i<N;i++){
		cin >> A.at(i);
		total += A.at(i);
	}
	ll middle_front = 0;
	ll middle_end = 0;
	ll diff_min = 0;
	for(int i=0;i<N;i++){
		middle_front += A.at(i);
		if(middle_front * 2 >= total){
			ll a = abs((total - middle_front) - middle_front);
			middle_front -= A.at(i);
			ll b = abs((total - middle_front) - middle_front);
			diff_min = min(a, b);
			cout << diff_min;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 1792
s = input()
import re
ans=[]
ans.append(re.match(".*keyence$",s))
ans.append(re.match("^k.*eyence$",s))
ans.append(re.match("^ke.*yence$",s))
ans.append(re.match("^key.*ence$",s))
ans.append(re.match("^keye.*nce$",s))
ans.append(re.match("^keyen.*ce$",s))
ans.append(re.match("^keyenc.*e$",s))
ans.append(re.match("^keyence.*",s))
c = sum(x!=None for x in ans)
if c > 0:
  print("YES")
else:
  print("NO")

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

int main()
{
    int n,k;
    int i,pow;
    //scanf("%d %d",&n,&k);
    cin>>n>>k;
    vector<int>vr;
    for(i=0;i<n;++i){
        //scanf("%d",&pow); 
        cin>>pow;
        vr.push_back(pow);
    }
    sort(vr.begin(),vr.end());
    reverse(vr.begin(),vr.end());
    if(k>=n) printf("0");
    else{
        long long int need=0;
        for(i=k;i<n;++i) need+=vr[i];
        //printf("%I64d",need);
        cout<<need;
    }
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
 
using namespace std;
 
#define ALL(x) x.begin(), x.end()
 
typedef long long int lld;
typedef pair<int, int> pii;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(15);
	cout << fixed;
 
	int n = 0;
	cin >> n;

	multiset<int> mt;

	for (int i = 0; i < n; i++) {
		int x = 0;
		cin >> x;
		
		auto it = mt.lower_bound(x);
		
		if (it != mt.begin()) {
			it--;
			mt.erase(it);
		}

		mt.insert(x);
	}

	cout << mt.size() << '\n';
 
	
 
 
	return 0;
}

Measured memory_bytes: 4992
n, k = [int(i) for i in input().split()]
mod = 10**9+7
m, M, L = 0, 0, 0
for i in range(k,n+2):
    m = i *(i-1)//2
    M = (2*n-i+1)*i//2
    L = L+(M - m+1)
print(L%mod)



Measured memory_bytes: 9116
#include <functional>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> adj[n];
    for (int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int col[n];
    function<void(int, int, int)> dfs = [&](int i, int p, int c) {
        col[i] = c;
        for (int j : adj[i]) if (j != p) dfs(j, i, -c);
    };
    dfs(0, -1, 1);
    int p = 0, q = 0;
    for (int i = 0; i < n; i++) if (col[i] == 1) p++; else q++;
    int ans[n] = {};
    vector<int> v[3];
    for (int i = 1; i <= n; i++) v[i%3].push_back(i);
    if (p <= n/3 || q <= n/3) {
        int c0 = p <= n/3 ? 1 : -1;
        bool used[n+1] = {};
        int x = 3;
        for (int i = 0; i < n; i++)
            if (col[i] == c0) { ans[i] = x; used[x] = true; x += 3; }
        x = 1;
        for (int i = 0; i < n; i++)
            if (ans[i] == 0) {
                ans[i] = x;
                if (used[++x]) ++x;
            }
    } else {
        for (int i = 0; i < n; i++) {
            if (col[i] == 1) {
                int j = v[1].empty() ? 0 : 1;
                ans[i] = v[j].back();
                v[j].pop_back();
            } else {
                int j = v[2].empty() ? 0 : 2;
                ans[i] = v[j].back();
                v[j].pop_back();
            }
        }
    }
    for (int i = 0; i < n; i++) cout << ans[i] << (i == n-1 ? '\n' : ' ');
}


Measured memory_bytes: 22904
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())
flag = 0
if N == 1:
    flag = -1
M = len(factorization(N))
num = [1,3,6,10,15,21,28,36]
ans = 0
for i in range(M):
    for j in range(len(num)):
        if num[j] <= factorization(N)[i][1]:
            ans += 1
        else:
            break

if flag == -1:
    print(0) 
else:
    print(ans)

Measured memory_bytes: 9508
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  int b=0,w=0;
  for(int i=0;i<n;i++){
    if(s[i]=='.')w++;
  }
  int ans=b+w;
  for(int i=0;i<n;i++){
    if(s[i]=='#'){
      b++;
    }
    else{
      w--;
    }
    ans=min(ans,b+w);
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define LEN 201
#define END "-"
void shuffle(char[],int);
int main(void)
{
  int i;
  int h;
  int m;
  char str[LEN];
  for(;;)
    {
      scanf("%s",str);
      if(strcmp(END,str)==0) break;
      scanf("%d",&m);
      for(i=0;i<m;i++)
        {
          scanf("%d",&h);
          shuffle(str,h);
        }
      printf("%s\n",str);
    }
  return 0;
}
void shuffle(char str[],int h)
{
  char temp[LEN*2+1];
  strcpy(temp,str+h);
  strcpy(temp+strlen(str)-h,str);
  temp[strlen(str)]='\0';
  strcpy(str,temp);
}


Measured memory_bytes: 2032
s = input()
t = input()

l0 = len(s)
l = len(t)


def chk(n):
    x = s[n:n+l]
    flg = True
    for j in range(l):
        if x[j] != t[j] and x[j] != "?":
            flg = False
    return flg


res = []
for i in range(l0 - l + 1):
    if chk(i):
        res.append(i)

ans = []
if not res:
    print("UNRESTORABLE")
else:
    p = res[-1]
    y = s[:p] + t + s[p+l:]
    z = y.replace("?", "a")
    print(z)


Measured memory_bytes: 3064
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let ans = n * n * n;

    return ans.to_string();
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int vec[200004],vv[200004];
int main() {
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  int N;
  cin >> N;
  for (int X=0; X<N-1; X++){
    cin >> vec[X];
    vv[vec[X]-1]++;
  }
  for (int X=0; X<N; X++){
    cout << vv[X] << endl;
  }
}


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

int main() {
  long ans;
  string s;
  cin >> s;
  ans=s.size()*(s.size()+1)/2+1;
  vector<long> c(26);
  for(long i=0;i<s.size();i++) c[s[i]-'a']++;
  for(long i=0;i<26;i++) ans-=c[i]*(c[i]+1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 3664
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	final boolean DEBUG = false;
	int[] rank, tmp;
	int n, k;

	void run() {
		Scanner scan = new Scanner(System.in);
		String t = scan.next();
		int q = scan.nextInt();
		Integer[] sa = new Integer[t.length() + 1];
		rank = new int[t.length() + 1];
		tmp = new int[t.length() + 1];
		constructSA(t.toCharArray(), sa);
		if (DEBUG)
			System.out.println(Arrays.toString(sa));
		for (int i = 0; i < q; i++) {
			String p = scan.next();
			System.out.println(contain(t, sa, p) ? 1 : 0);
		}
	}

	boolean contain(String s, Integer[] sa, String t) {
		int a = 0, b = s.length(), subIndex = 0;
		while (b - a > 1) {
			int c = (a + b) / 2;
			subIndex = sa[c] + t.length() > s.length() ? s.length() : sa[c] + t.length();
			if (DEBUG) {
				System.out.print(sa[c] + " " + (sa[c] + t.length()));
				System.out.print(", cmp: " + (s.substring(sa[c], subIndex).compareTo(t) < 0));
				System.out.println(", str: " + s.substring(sa[c], subIndex));
			}
			if (s.substring(sa[c], subIndex).compareTo(t) < 0) a = c;
			else b = c;
		}
		subIndex = sa[b] + t.length() > s.length() ? s.length() : sa[b] + t.length();
		return s.substring(sa[b], subIndex).compareTo(t) == 0;
	}

	boolean compareSA(int i, int j) {
		if (rank[i] != rank[j]) return rank[i] < rank[j];
		else {
			int ri = i + k <= n ? rank[i + k] : -1;
			int rj = j + k <= n ? rank[j + k] : -1;
			return ri < rj;
		}
	}

	void constructSA(char[] s, Integer[] sa) {
		n = s.length;
		
		for (int i = 0; i <= n; i++) {
			sa[i] = i;
			rank[i] = i < n ? s[i] : -1;
		}

		Comparator<Integer> compare_sa = new Comparator<Integer>() {
			@Override
			public int compare(Integer i, Integer j) {
				if (rank[i] != rank[j]) return rank[i] == rank[j] ? 0 : (rank[i] < rank[j] ? -1 : 1);
				else {
					int ri = i + k <= n ? rank[i + k] : -1;
					int rj = j + k <= n ? rank[j + k] : -1;
					return ri == rj ? 0 : (ri < rj ? -1 : 1);
				}
			}
		};
		for (k = 1; k <= n; k *= 2) {
			Arrays.sort(sa, 0, n + 1, compare_sa);
			tmp[sa[0]] = 0;
			for (int i = 1; i <= n; i++) {
				tmp[sa[i]] = tmp[sa[i - 1]] + (compareSA(sa[i - 1], sa[i]) ? 1 : 0);
			}
			for (int i = 0; i <= n; i++) {
				rank[i] = tmp[i];
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 209044
function Main(input) {
    // 入力値
    const lines = input.split(' ');
    let takahashi_hp = lines[0];
    const takahashi_at = lines[1];
    let aoki_hp = lines[2];
    const aoki_at = lines[3];

    // 攻撃のループ
    for (let i = 0; i < 100; i++) {
        // 高橋の体力が0になったらbreak
        aoki_hp -= takahashi_at;
        if (aoki_hp <= 0) {
            console.log('Yes');
            break;
        }
        // 青木の体力が０になったらbreak
        takahashi_hp -= aoki_at;
        if (takahashi_hp <= 0) {
            console.log('No');
            break;
        }
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
 int n,k;
 cin>>n>>k;
 vector<int>v(n);
 for(int i=0;i<n;i++)cin>>v[i];
 sort(v.begin(),v.end());
 int ans=0;
 for(int i=0;i<k;i++)ans+=v[i];
 cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#define N 1000000007
typedef long long ll;
using namespace std;
ll quick_mod(ll a,ll b){
    ll ans=1;  
    a%=N;  
    while(b){  
        if (b&1){ 
            ans=ans*a%N;  
    		b--;
		}
        b>>=1;
        a=a*a%N;
    }
	return ans;  
}

ll C(ll n,ll m){
	if (m>n) return 0;  
	ll ans=1;  
	for (int i=1;i<=m;i++){ 
		ll a=(n+i-m)%N;
		ll b=i%N;
		ans=ans*(a*quick_mod(b,N-2)%N)%N;
	}
	return ans;
}
ll Lucas(ll n,ll m){
	if (!m) return 1;
	return C(n%N,m%N)*Lucas(n/N,m/N)%N;
}

int main(){
	ll n,a,b,x,y;
	cin>>x>>y;
	n=(x+y)/3;
	if (3*n!=(x+y)){
		cout<<"0";
		return 0;
	}
	a=(2*x-y)/3;
	b=(2*y-x)/3;
	if (a<0||b<0){
		cout<<"0";
		return 0;	
	}
	cout<<Lucas(n,a);
	return 0;
}

Measured memory_bytes: 384
fun main(args: Array<String>) = IO().println {
    val n = int()
    val h = long()
    val w = long()
    var cnt = 0
    for (i in n) {
        val a = long()
        val b = long()
        if (h <= a && w <= b) cnt++
    }
    cnt
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }

    inline fun println(block: IO.() -> Any) {
        println(block())
        out.flush()
    }
}
// endregion

Measured memory_bytes: 31264
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	cin >> n;
	string ans = "No";

	for (int a = 1; a < 10;a++) {
		for (int b = 1; b < 10;b++) {
			if (a*b==n) {
				ans = "Yes";
				break;
			}
		}
	}
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    ll ans=0,count=0;
    for(int i=n-1;i>=1;i--){
        if(arr[i-1]>=arr[i]) count++;
        else{
            ans=max(ans,count);
            count=0;
        }
    }
    ans=max(ans,count);
    cout<<ans;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n, m;
int K[20];
vector<int> s[20];
int p[20];

int ans;

int main(void){
	cin>>n>>m;
	for (int i = 0; i < m; i++) {
		cin>>K[i];
		for (int j = 0; j < K[i]; j++) {
			int x; cin>>x; x--; //x--はスイッチの番号を0 ~ m - 1としているから
			s[i].push_back(x);
		}
	}
	for (int i = 0; i < m; i++) cin>>p[i];

	for (int i = 0; i < (1 << n); i++) { //あるスイッチの状態を表すbit列を生成
		bool can = true;
		for (int j = 0; j < m; j++) {
			int cnt = 0; //bit列上で、j番目の電球に接続されているスイッチがonになっているものの個数

			for (int k = 0; k < K[j]; k++) {
				if (i & (1 << s[j][k])) cnt++;
			}

			if (cnt % 2 != p[j]) can = false; //cnt % 2 != p[j]ならj番目の電球は点灯不可、
											  //この時点ですべての電球を点灯させることはできない。
		}

		if (can) ans++;
	}

	printf("%d\n", ans);
	
	return 0;
}

/*
方針ー
あるスイッチの状態を表すbit列が与えられる。 あるj番目の電球(0 <= j <= m - 1)について
K[i]コのスイッチに接続されているので全部調べる。つまり、s[j][k]番目のスイッチが与えられたbit
列でonになっているのならcnt++; (j番目のスイッチでonになっているスイッチの個数 % 2 == p[i])なら
j番目の電球は点灯することができないので、can = false; あるbit列が与えられて、can = trueと
なれば、それは電球をすべて点灯させることができるということなのでans++; あとはこれを考えられるbit列
2^nコすべてについて調べればok.
O(2^n * m * n)
 */

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int S,x,h,m,s;
    scanf("%d",&S);
    h=S/3600;
    x=S%3600;
    m=x/60;
    s=x%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}

Measured memory_bytes: 592
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, ans, now, cnt;
int main() {
	cin >> n;
	for(int i = 1; i <= n; i ++ ) {
		int x;
		cin >> x;
		if(now == x) cnt++;
		else {
			if(cnt > 1) ans += cnt/2;
			now = x, cnt = 1;
		}
	}
	ans += cnt/2;
	cout << ans << endl;
}

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

string S;
int mem[501][501];

bool isCat(int l, int r) {
  int &res = mem[l][r];
  if(res != -1) return res;
  if(r - l == 0) return res = true;
  if(S[l] != 'm' || S[r-1] != 'w') return res = false;
  for(int i = l + 1; i < r - 1; ++i) {
    if(S[i] == 'e' && isCat(l + 1, i) && isCat(i + 1, r - 1) ){
      return res = true;
    }
  }
  return res = false;
}

int main() {
  cin >> S;
  memset(mem, -1, sizeof(mem));
  cout << (isCat(0, S.size()) ? "Cat" : "Rabbit") << endl;
  return 0;
}

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

int main(){
  int x,y;
  cin >> x >> y;
  if(x==2||y==2)
    cout << "No" << endl;
  else if(x==4||x==6||x==9||x==12){
    if(y==4||y==6||y==9||y==12)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  else{
    if(y==4||y==6||y==9||y==12)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
}

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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

const int N = 5e4L + 11;
int p[N];

int main() {
	iota(p, p + N, 0);
	for(int i = 2; i < N; i ++) if(p[i] == i)
		for(int j = i; j < N; j += i) p[j] = i;

	cout << fixed << setprecision(9);
	ios :: sync_with_stdio(0);

	for(int n; cin >> n && n; ) {
		int ans = 0;
		for(int i = 2; i * 2 <= n; i ++)
			if(p[i] == i && p[n - i] == n - i)
				ans ++;
		cout << ans << '\n';
	}

	return 0;
}

Measured memory_bytes: 3212