akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int dp1[5009][5009], dp2[5009][5009], n, k, a[5009], p1[5009], p2[5009];

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	dp1[0][0] = 1;
	for (int i = 0; i <= n - 1; i++) {
		for (int j = 0; j <= k; j++) {
			if (dp1[i][j] == 0) continue;
			dp1[i + 1][j] = 1;
			if (j + a[i + 1] <= k) dp1[i + 1][j + a[i + 1]] = 1;
		}
	}
	dp2[n + 1][0] = 1;
	for (int i = n + 1; i >= 2; i--) {
		for (int j = 0; j <= k; j++) {
			if (dp2[i][j] == 0) continue;
			dp2[i - 1][j] = 1;
			if (j + a[i - 1] <= k) dp2[i - 1][j + a[i - 1]] = 1;
		}
	}

	int ret = 0;

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= k; j++) { p1[j] = 0; p2[j] = 0; }
		for (int j = 0; j <= k; j++) p1[j] = dp1[i - 1][j];
		for (int j = 0; j <= k; j++) p2[j] = dp2[i + 1][j];
		for (int j = 1; j <= k; j++) p2[j] += p2[j - 1];
		
		int L = k - a[i], R = k, sum = 0; if (L < 0) L = 0;

		for (int j = 0; j <= k; j++) {
			if (p1[j] == 0) continue;

			int S1 = L - j, S2 = R - j; if (S1 < 0) S1 = 0;
			int F1 = 0; if (S2 >= 1) F1 += p2[S2 - 1];
			if (S1 >= 1) F1 -= p2[S1 - 1];

			sum += F1;
		}
		if (sum == 0) ret++;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 196224
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    vector<int> a(n + 2);
    a[0] = a[n + 1] = 0;
    copy_n(istream_iterator<int>(cin), n, next(a.begin()));
    int cost = 0;
    rep(i, n + 1){
        cost += abs(a[i] - a[i + 1]);
    }
    rep(i, n){
        if((a[i] <= a[i + 1] && a[i + 1] <= a[i + 2]) && (a[i] >= a[i + 1] && a[i + 1] >= a[i + 2])){
            cout << cost << endl;
            continue;
        }
        cout << cost + abs(a[i] - a[i + 2]) - abs(a[i] - a[i + 1]) - abs(a[i + 1] - a[i + 2]) << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
// AOJ 1534 Sum of Last Digits
// 下一桁のべき乗について、その周期性に注目
// 2019.3.31 bal4u

#include <stdio.h>
#include <stdlib.h>

int t[10][4] = {{0},{1},{6,2,4,8},{1,3,9,7},{6,4,6,4},{5},{6},{1,7,9,3},{6,8,4,2},{1,9,1,9}};
int f[4];

int main()
{
	int i, n, m, k, a, nm;
	long long _n, ans;

	scanf("%lld%d%d", &_n, &m, &k);
	n = (int)(_n % 10);
	if (n == 0 || n == 1 || n == 5 || n == 6) ans = n * (long long)k;  // いくらべき乗しても下一桁が変わらないもの
	else {
		nm = t[n][m % 4];                      // n^m　の下一桁

		f[0] = f[1] = f[2] = f[3] = --k / 4;   // n^m, n^(2m), n^(3m), n^(4m) それぞれの個数
		for (i = 0; i < k % 4; i++) f[i]++;

		ans = t[n][1];                         // 最初の項  n%10
		a = 1;  for (i = 0; i < 4; i++) {      // n^m ~ n^(4m)各項の累積和
			a *= nm;                           // aは n^m, n^(2m), n^(3m), n^(4m) の下一桁になる
			ans += (long long)f[i] * ((a*n) % 10);          // されに n をかける
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;
    vector<int> S(100005, 0);
    for(int i = 0; i < n; ++i){
        int l, r;
        cin >> l >> r;
        ++S[l], --S[r + 1];
    }
    for(int i = 1; i <= 100000; ++i)    S[i + 1] += S[i];
    int ans = 0;
    for(int i = 1; i <= 100000; ++i){
        if(S[i])    ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
n,m=map(int,input().split())

l=[list(map(int,input().split())) for i in range(m)]
from operator import itemgetter as it
l.sort(key=it(1))
head=0
ans=0
for a,b in l:
    if not(a<head<=b):ans+=1;head=b
print(ans)

Measured memory_bytes: 89696
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"; exit $?
exit 0
'''
import sys

def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

a = _ia()
if sum(a)>=22: ans="bust"
else: ans="win"
print(ans)


Measured memory_bytes: 38256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int a, b, n; cin >> a >> b >> n;
    int ans = (a * n) / b - a * (n / b);
    if(b <= 1000000) {
        for(int i = 1; i <= min(b + 3, n); ++ i) {
            int res = (a * i) / b - a * (i / b);
            chmax(ans, res);
        }
    } else {
        for(int i = b - 1; i <= n; i += b) {
            int res = (a * i) / b - a * (i / b);
            chmax(ans, res);
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3604
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    unordered_map<int, int> allpen, isac;
    int n, m;
    cin >> n >> m;
    int cnt = 0, pen = 0;
    forn(i, m) {
        int x;
        string s;
        cin >> x >> s;
        if (s == "AC") {
            if (!isac[x]) isac[x] = 1, cnt++, pen += allpen[x];
        } else {
            if (!isac[x]) allpen[x]++;
        }
    }
    cout << cnt << " " << pen << "\n";
    return 0;
}

Measured memory_bytes: 8520
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pb push_back
const ll k=1e9+7;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h,w;
	cin>>h>>w;
	ll dp[h+1][w+1];
	memset(dp,0,sizeof(dp));
	char a[h][w];
	for(int i=0;i<h;i++){
	    for(int j=0;j<w;j++){
	        cin>>a[i][j];
	    }
	}
	bool f=0;
	for(int j=w-1;j>=0;j--){
	    if(a[h-1][j]=='#'){
	        f=1;
	    }
	    else{
	       if(!f) dp[h-1][j]=1;
	       else dp[h-1][j]=0;
	    }
	}
	for(int i=h-2;i>=0;i--){
	    for(int j=w-1;j>=0;j--){
	        if(a[i][j]=='#') dp[i][j]=0;
	        else
	        dp[i][j]=(dp[i+1][j]%k+dp[i][j+1]%k)%k;
	    }
	}
	
	cout<<dp[0][0]%k<<"\n";
	
	
	return 0;
}


Measured memory_bytes: 9088
import math

def countPrimeNum(n):
  count = 0
  max = math.ceil(math.sqrt(n)) + 1
  for i in range(1, max):
    if n % i == 0:
      if n / i == i:
        count = count + 1
      else:
        count = count + 2
  return count

n = int(input())
count = 0
for i in range(1, n + 1):
  if i % 2 == 1:
    if countPrimeNum(i) == 8:
      count = count + 1

print(count)


Measured memory_bytes: 3060
<?php
$second = trim(fgets(STDIN));
$h = (int)($second / 3600);
$m = (int)(($second / 60) - ($h * 60));
$s = $second - ($h * 3600) - ($m * 60);
$result = sprintf('%d:%d:%d',$h,$m,$s);
echo $result."\n";
?>


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;
int main() {

    ll n, m;
    cin >> n >> m;

    ll ans = 0;
    if(n*2 <= m){
        ans += n;
        m -= 2*n;
        ans += m / 4; 
    }
    else{
        ans += m / 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define all(v) (v).begin(),(v).end()
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using int32 = int32_t; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
#define FASTCIN() cin.tie(0);ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
#define DEBUG_IMPORT(file) vs args(argv, argv+argc);str sample = make_sample(args, file);ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#else
#define DEBUG_IMPORT(file)
#endif
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


int32 main(int32 argc, char* argv[]) {
    FASTCIN();
    DEBUG_IMPORT("sample-1");


    int N,M; cin>>N>>M;
    vi W(N), V(N); REP(i,N) cin>>W[i]>>V[i];

    var dp = vvi(N+1, vi(M+4, 0));
    // dp[i][j] := [0,i] の品から、重さ j 以下で得られる価値の最大値

    REP(i, N)
        dp[i][0] = 0;

    REP(j, M+1) {
        if (j >= W[0])
            dp[0][j] = V[0];
        else
            dp[0][j] = 0;
    }

    FOR(i, 1, N) {
        FOR(j, 1, M+1) {
            if (j >= W[i]) {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-W[i]] + V[i]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    int ans = dp[N-1][M];
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 80256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
using namespace std;
int main()
{
	int a,b,c,x;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> x;
	
	int cnt=0;

	if(x%100==50){
		if(!c){
			cout << "0" << endl;
			return 0;
		}else{
			c--;
			x-=50;
		}
	}
	//xは100の倍数
	int tmp=0;
	for(int i=0; i<=a; i++){
		for(int j=0; j<=b; j++){
			for(int k=0; k<=c; k++){
				tmp = 500*i + 100*j + 50*k;
//				cout << tmp << endl;
				if(tmp==x){
					cnt++;
				}
				if(tmp>x){
					break;	
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x = c-a;
    int y = d-b;
    cout<<c-y<<" "<<d+x<<" "<<a-y<<" "<<b+x<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b && b < c)
    {
        cout << "Yes" << endl;
    }
    else 
    {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3100
N = input()
N = int(N)
dlist = [0] * N
for i in range(N):
    dlist[i] = input()
    dlist[i] = int(dlist[i])

nlist = [0] * 101
for i in range(N):
    if(nlist[dlist[i]]==0):
        nlist[dlist[i]] = 1

print(sum(nlist))

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

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

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll n; cin >> n;

    ll i = 0;
    while(i*(i+1) < n*2) i++;

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
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 int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main()
{
   int N,K;
   cin >> N >> K;
   vector<bool> appear(N + 1,true);
   vector<int> numCount (N + 1,0);
   vector<int> A(N);
   int kinds = 0;
   for(int i = 0; i < N; i++)
   {
       cin >> A[i];
       if(appear[A[i]])
       {
           kinds++;
           appear[A[i]] = false;
           numCount[A[i]]++;
       }
       else
       {
           numCount[A[i]]++;
       }
   }
//    cout << kinds << endl;
    // cout  << kinds - K << endl;
   if(kinds <= K)
   {
       cout << 0 << endl;
       return 0;
   }
   else
   {
       sort(numCount.begin(),numCount.end());
       int diff = 0;
       int diffKind = 0;
       for(int i = 0; i < N + 1; i++)
       {
           if(diffKind != kinds - K && numCount[i] != 0)
           {
                diffKind++;
                diff += numCount[i];
           }
           else if(diffKind == kinds - K)
           {
               cout << diff << endl;
               return (0);
           }
       }
   }
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    string S;
    cin>>S;
    int cnt=0;
    int ans=0;

    for (int i = 0; i < S.size() ; ++i) {
        if(S[i]=='A'||S[i]=='G'||S[i]=='C'||S[i]=='T'){
            cnt++;
        } else {
            cnt=0;
        }
        ans = max(ans, cnt);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

n,k= gets.split.map(&:to_i)
pi = gets.split.map(&:to_i)

pi.sort!

sum = 0
k.times do |i|
  sum += pi[i]
end
puts sum 



Measured memory_bytes: 14324
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner input=new Scanner(System.in);
		String str=input.next();
		char[] reverse=str.toCharArray();
		for(int i=reverse.length-1;i>=0;i--){
			System.out.print(reverse[i]);
		}
		System.out.println();
		
	}

}

Measured memory_bytes: 25852
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S, T = input().split()
A, B = MAP()
U = input()

D = {}
D[S] = A
D[T] = B
D[U] -= 1
print(D[S], D[T])


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

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

  int ans;
  if (b * 2 >= a) { 
    cout << 0 << endl;
  } else {
    cout << a - b * 2 << endl;
  }
  
  return 0;
}

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

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

   char c = s.at(0);

   switch(c)
   {
        case 'S':
            cout << "Cloudy" << endl;
            break;
        case 'C':
            cout << "Rainy" << endl;
            break;
        case 'R':
            cout << "Sunny" << endl;
            break;
   }
   
    
    
    
    return 0;
}

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

using namespace std;

unsigned long long f(unsigned long long n, unsigned long long d){
    unsigned long long pow = 1;
    while(pow < n){
        pow *= d;
    }
    unsigned long long num = 0;
    while(pow > 1){
        num += n/pow;
        pow /= d;
    }
    return num;
}

int main(){
    unsigned long long n;
    scanf("%llu", &n);
    // printf("%lld\n", f(n, 2));
    unsigned long long res = 0;
    if(n % 2 == 0){
        unsigned long long num5 = f(n/2, 5);
        unsigned long long num2 = f(n/2, 2) + n/2;
        res = min(num5, num2);
    }else{
        res = 0;
    }
    printf("%llu\n", res);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, n)    for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define _in(a) \
    ll a;      \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
#define in(a, b, c, d, e) \
    _in(a);               \
    _in(b);               \
    _in(c);               \
    _in(d);               \
    _in(e)
#define in(a, b, c, d) \
    _in(a);            \
    _in(b);            \
    _in(c);            \
    _in(d)
#define in(a, b, c) \
    _in(a);         \
    _in(b);         \
    _in(c)
#define in(a, b) \
    _in(a);      \
    _in(b)
#define in(a) _in(a)
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)  (x).begin(), (x).end()    //昇順
#define rall(x) (x).rbegin(), (x).rend()  //降順
#define yes     out("Yes");
#define no      out("No");

int main() {
    ins(n);
    ll ans = 0;
    rep(i, n.size()) {
        ans += n[i] - '0';
    }
    if (ans % 9 == 0) {
        yes;
    } else {
        no;
    }
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a[7],b[7],c=0;
  for(int i=1;i<=6;i++){
    cin>>a[i];
  }
  for(int i=1;i<=6;i++){
    cin>>b[i];
  }
  if(a[1]==b[1]&&a[2]==b[2]&&a[3]==b[3]&&a[4]==b[4]&&a[5]==b[5]&&a[6]==b[6]){
    c++;
  }else if(a[1]==b[1]&&a[2]==b[3]&&a[3]==b[5]&&a[5]==b[4]&&a[4]==b[2]&&a[6]==b[6]){
    c++;
  }else if(a[1]==b[1]&&a[2]==b[5]&&a[5]==b[2]&&a[4]==b[3]&&a[3]==b[4]&&a[6]==b[6]){
    c++;
  }else if(a[1]==b[1]&&a[2]==b[4]&&a[4]==b[5]&&a[5]==b[3]&&a[3]==b[2]&&a[6]==b[6]){
    c++;
  }
  if(a[1]==b[2]&&a[2]==b[6]&&a[3]==b[3]&&a[5]==b[1]&&a[4]==b[4]&&a[6]==b[5]){
    c++;
  }else if(a[1]==b[2]&&a[2]==b[3]&&a[3]==b[1]&&a[5]==b[4]&&a[4]==b[6]&&a[6]==b[5]){
    c++;
  }else if(a[1]==b[2]&&a[2]==b[1]&&a[5]==b[6]&&a[3]==b[4]&&a[4]==b[3]&&a[6]==b[5]){
    c++;
  }else if(a[1]==b[2]&&a[2]==b[4]&&a[4]==b[1]&&a[5]==b[3]&&a[3]==b[6]&&a[6]==b[5]){
    c++;
  }
  if(a[1]==b[3]&&a[2]==b[2]&&a[3]==b[6]&&a[5]==b[5]&&a[4]==b[1]&&a[6]==b[4]){
    c++;
  }else if(a[1]==b[3]&&a[2]==b[6]&&a[3]==b[5]&&a[5]==b[1]&&a[4]==b[2]&&a[6]==b[4]){
    c++;
  }else if(a[1]==b[3]&&a[2]==b[5]&&a[3]==b[1]&&a[5]==b[2]&&a[4]==b[6]&&a[6]==b[4]){
    c++;
  }else if(a[1]==b[3]&&a[2]==b[1]&&a[3]==b[2]&&a[5]==b[6]&&a[4]==b[5]&&a[6]==b[4]){
    c++;
  }
  if(a[1]==b[4]&&a[2]==b[2]&&a[3]==b[1]&&a[5]==b[5]&&a[4]==b[6]&&a[6]==b[3]){
    c++;
  }else if(a[1]==b[4]&&a[2]==b[1]&&a[3]==b[5]&&a[5]==b[6]&&a[4]==b[2]&&a[6]==b[3]){
    c++;
  }else if(a[1]==b[4]&&a[2]==b[5]&&a[3]==b[6]&&a[5]==b[2]&&a[4]==b[1]&&a[6]==b[3]){
    c++;
  }else if(a[1]==b[4]&&a[2]==b[6]&&a[3]==b[2]&&a[5]==b[1]&&a[4]==b[5]&&a[6]==b[3]){
    c++;
  }
  if(a[1]==b[5]&&a[2]==b[1]&&a[3]==b[3]&&a[5]==b[6]&&a[4]==b[4]&&a[6]==b[2]){
    c++;
  }else if(a[1]==b[5]&&a[2]==b[3]&&a[3]==b[6]&&a[5]==b[4]&&a[4]==b[1]&&a[6]==b[2]){
    c++;
  }else if(a[1]==b[5]&&a[2]==b[6]&&a[3]==b[4]&&a[5]==b[1]&&a[4]==b[3]&&a[6]==b[2]){
    c++;
  }else if(a[1]==b[5]&&a[2]==b[4]&&a[3]==b[1]&&a[5]==b[3]&&a[4]==b[6]&&a[6]==b[2]){
    c++;
  }
  if(a[1]==b[6]&&a[2]==b[2]&&a[3]==b[4]&&a[5]==b[5]&&a[4]==b[3]&&a[6]==b[1]){
    c++;
  }else if(a[1]==b[6]&&a[2]==b[4]&&a[3]==b[5]&&a[5]==b[3]&&a[4]==b[2]&&a[6]==b[1]){
    c++;
  }else if(a[1]==b[6]&&a[2]==b[5]&&a[3]==b[3]&&a[5]==b[2]&&a[4]==b[4]&&a[6]==b[1]){
    c++;
  }else if(a[1]==b[6]&&a[2]==b[3]&&a[3]==b[2]&&a[5]==b[4]&&a[4]==b[5]&&a[6]==b[1]){
    c++;
  }
  if(c>0){
    cout<<"Yes"<<endl;
    }else {
        cout <<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S; cin >> S;
    int cnt = 0;
    if (S.find('R') != string::npos) cnt++;
    if (S[0] == 'R' && S[0] == S[1]) cnt++;
    if (S[1] == 'R' && S[1] == S[2]) if (cnt == 0) cnt = 2; else cnt++;
    cout << cnt << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <climits>
#include <cstdint>
using namespace std;

inline namespace atcoder {
    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;

    constexpr inline int64_t mpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
        if (b == 0) return 1; if (b == 1) return a;
        return (((max(a * (b & 1), (int64_t)1) * mpow(a, b / 2)) % mod) * mpow(a, b / 2)) % mod;
    }
}

int main() {
    constexpr int64_t mod = 1000000000 + 7;

    int64_t n; cin >> n;
    if (n < 2) {
        cout << 0 << endl;
        return 0;
    }

    int64_t a = mpow(10, n), b = mpow(9, n), c = mpow(8, n);

    int64_t ans = (a - 2 * b) % mod;
    while (ans < 0) ans += mod;
    ans = (ans + c) % mod;

    cout << ans << endl;
}



Measured memory_bytes: 3584
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

char qmap[10][10];

int main(){
  int n, q;
  cin >> n;
  vector<int> S(n);
  rep(i,n) cin >> S[i];
  cin >> q;
  vector<int> T(q);  
  rep(i,q) cin >> T[i];

  int ans = 0;
  rep(i,q){
    int now = T[i], l = 0, r = S.size();
    while(r-l > 1){
      int mid = (l + r) / 2;
      if(S[mid] >= now)  r = mid;
      else l = mid;
    }
    if(S[r] == now) ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD ((ll)1e9+7)
#define MAX 103
#define SZ 5

int n;
char alph[] = {'-', 'A', 'T', 'G', 'C'};
ll dp[MAX][SZ][SZ][SZ];

bool is_valid_c(int l1, int l2, int l3) {
    if (alph[l1] == 'A' && alph[l3] == 'G') return false;
    if (alph[l1] == 'A' && alph[l2] == 'G') return false;
    if (alph[l2] == 'A' && alph[l3] == 'G') return false;
    if (alph[l2] == 'G' && alph[l3] == 'A') return false;
    return true;
}

bool is_valid_g(int l1, int l2, int l3) {
    if (alph[l2] == 'A' && alph[l3] == 'C') return false;
    return true;
}

ll get_dp(int i, int l1, int l2, int l3) {
    if (i == n) {
        return 1;
    } else if (dp[i][l1][l2][l3] != -1) {
        return dp[i][l1][l2][l3];
    } else {
        ll ans = 0;
        ans = (ans+get_dp(i+1, l2, l3, 1))%MOD;
        ans = (ans+get_dp(i+1, l2, l3, 2))%MOD;
        ans = is_valid_g(l1, l2, l3) ? (ans+get_dp(i+1, l2, l3, 3))%MOD : ans;
        ans = is_valid_c(l1, l2, l3) ? (ans+get_dp(i+1, l2, l3, 4))%MOD : ans;
        return dp[i][l1][l2][l3] = ans;
    }
}

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

    cin >> n;
    memset(dp, 255, sizeof(dp));
    cout << get_dp(0, 0, 0, 0) << "\n";
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N, M;
vector<int> G[1010];
int came[1010];
int finish[1010];
vector<int> dat;
bool cycle = false;
bool con[1010];
int st;

void dfs(int v){
    if(cycle) return;

    came[v] = true;
    dat.push_back(v);

    for(auto& u : G[v]){
        if(!came[u]) dfs(u);

        if(cycle) return;

        if(came[u] && !finish[u]){
            st = u;
            cycle = true;
            return;
        }
    }
    finish[v] = true;
    if(cycle) return;
    dat.pop_back();

    return;
}

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
    }
    for(int i = 1; i <= N; i++){
        if(!came[i]) dfs(i);
    }

    if(dat.size() == 0){
        cout << -1 << endl;
        return 0;
    }
    for(auto it = dat.begin(); it < dat.end(); it++){
        if(*it == st){
            dat.erase(dat.begin(), it);
            break;
        }
    }
    for(auto& u : dat) con[u] = true;

    while(true){
        dat.push_back(dat[0]);
        
        int s = 0, t = 0;
        bool flag = false;
        for(int i = 0; i < dat.size() - 2; i++){
            for(auto u : G[dat[i]]){
                if(dat[i + 1] == u) continue;
                if(con[u]) s = dat[i], t = u;
            }
        }
        if(s == 0 && t == 0) break;
        vector<int> dat2 = {t};
        while(true){
            for(auto u : G[t]){
                if(con[u]){
                    dat2.push_back(u);
                    t = u;
                    break;
                }
            }
            if(t == s) break;
        }
        dat = dat2;
        for(int i = 1; i <= N; i++) con[i] = false;
        for(auto& u : dat) con[u] = true;
    }
    cout << dat.size() - 1 << endl;
    for(int i = 0; i < dat.size() - 1; i++) cout << dat[i] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int H, W;
int c[10][10];

void _main() {
    cin >> H >> W;
    REP (i, 10) REP (j, 10) cin >> c[i][j];
    REP (k, 10) REP (i, 10) REP (j, 10) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    }
    int ans = 0;
    REP (i, H) REP (j, W) {
        int A;
        cin >> A;
        if (A == -1) continue;
        ans += c[A][1];
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
#define nl endl
#define in cin
#define out cout
#define ll long long
ll x[1000000];
int main()
{ ll a,b,c,d,e,f,i,j,n,k=0,v=0;
  char s[10000];
   in>>n;
   if(n>=30)out<<"Yes"<<nl;
   else out<<"No"<<nl;
}

Measured memory_bytes: 3648
n = int(input())
a_list = [0] + list(map(int, input().split()))
b_list = [0] + list(map(int, input().split()))
c_list = [0] + list(map(int, input().split()))

sum = 0

for i in range(1, n+1):
    sum += b_list[a_list[i]]
    if i >= 2:
        if a_list[i] == a_list[i-1] + 1:
            sum += c_list[a_list[i-1]]
    #print(sum)


print(sum)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  ll n;
  cin>>n;
  vector<string> s(n+5);
  ll a=0,b=0,c=0,d=0;
  rep(i,n){
    cin>>s[i];
    if(s[i]=="AC"){
      a++;
    }
    else if(s[i]=="WA"){
      b++;
    }
    else if(s[i]=="TLE"){
      c++;
    }
    else if(s[i]=="RE"){
      d++;
    }
  }
  cout<<"AC"<<' '<<'x'<<' '<<a<<endl;
  cout<<"WA"<<' '<<'x'<<' '<<b<<endl;
  cout<<"TLE"<<' '<<'x'<<' '<<c<<endl;
  cout<<"RE"<<' '<<'x'<<' '<<d<<endl;
}

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

using namespace std;

int main() {
    std :: ios :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ///cout << "debug" << endl;
    int n;
    cin >> n;
    cout << n + n*n + n*n*n << endl;
    return 0;
}


Measured memory_bytes: 3604
import sys
input=sys.stdin.readline

def main():
    _ = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    ans = 0
    tmp = -1
    for a in A:
        ans += B[a-1]
        if tmp + 1 == a:
            ans += C[a-2]
        tmp = a

    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import sys
import math
import bisect

def solve(n):
    for i in range(200):
        for j in range(200):
            if i * 4 + j * 7 == n:
                return True
    return False

def main():
    n = int(input())
    if solve(n):
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
using namespace std;

int main(){
  int n, m, x; cin >> n >> m >> x;
  int acnt=0, bcnt=0;
  int a[m]; for(int i=0; i<m; i++) {
    cin >> a[i];
    if(a[i] < x){
      acnt++;
    }
    else if(a[i] > x){
      bcnt++;
    }
  }

  cout << min(acnt, bcnt) << endl;

  return 0;
}


Measured memory_bytes: 256
s = list(input())

alpha = [chr(ord('a')+i) for i in range(26)]
def check(s, c, k):
    if len(set(s)) <= 1:
        return k

    for i in range(len(s)-1):
        if s[i] == c or s[i+1] == c:
            s[i] = c
    s = s[:-1]
    return check(s, c, k+1)

import copy
def solve(s):
    ans = 1000
    for a in alpha:
        ans = min(ans, check(copy.copy(s), a, 0))
    return ans
print(solve(s))


Measured memory_bytes: 3572
#include<stdio.h>
int main(){
  int H[300],W[300],n,i,j,k,l;
  
  for(i=0;i<300;i++){
    scanf("%d%d",&H[i],&W[i]);
    if(H[i]==0&&W[i]==0) break;
  }
  n = i;

  for(i=0;i<n;i++){
    for(l=0;l<W[i];l++) printf("#");
    printf("\n");
    for(j=0;j<H[i]-2;j++){
      printf("#");
      for(k=1;k<W[i]-1;k++){
	printf(".");
      }
      printf("#\n");
    }
    for(l=0;l<W[i];l++) printf("#");
    printf("\n\n");
  }
  
  return 0;
}

Measured memory_bytes: 588
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        if(k == 1) {
            System.out.println(0);
            return;
        }
        n -= k;
        System.out.println(n);
        
    } 
}

Measured memory_bytes: 21716
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }

int main()
{
	uint32_t n;
	cin >> n;

	vector<uint32_t> v(n-1);

	uint32_t last_v = (uint32_t)1e5;
	uint32_t result = 0;

	for (uint32_t i = 0; i < n - 1; i++) {
		cin >> v[i];

		result += (last_v <= v[i] ? last_v : v[i]);
		last_v = v[i];
	}

	result += last_v;
	printf("%d\n", result);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define int long long int
    #define loop(i,a,b) for(int i=a;i<b;i++)
    #define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i]
    #define vi vector<int>
    #define si set<int>
    #define pii pair <int, int>
    #define sii set<pii>
    #define vii vector<pii>
    #define mii map <int, int>
    #define pb push_back
    #define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
    //Constants
    const int MOD = 1000000007; /* 1e9 + 7*/
    const int MAXN = 1000005; /*1e6 +5 */
     
    int spf[1000009]; // stores the smallest prime factor of a number
     
    void sieve()
    {
    spf[1] = 1;
        for (int i=2; i<MAXN; i++)
            spf[i] = i;
        for (int i=4; i<MAXN; i+=2)
            spf[i] = 2;
     
        for (int i=3; i*i<MAXN; i++)
            if (spf[i] == i)
            {
                for (int j=i*i; j<MAXN; j+=i)
                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    
     
    /* Iterative Function to calculate (x^y)%p in O(log y) */
    int power(int x,  int y, int p)
    {
        int res = 1;     // Initialize result
        x = x % p; // Update x if it is more than or
                    // equal to p 
        if (x == 0) return 0; // In case x is divisible by p;     
        while (y > 0)
        {
            // If y is odd, multiply x with result
            if (y & 1)
                res = (res*x) % p;     
            // y must be even now
            y = y>>1; // y = y/2
            x = (x*x) % p;
        }
        return res;
    }
    
     
    void solve(int caseNumber)
    {
		// cout<<"Case "<<caseNumber<<": "endl;
		int n;cin>>n;
		int arr[n];
		scan(arr,n);int cnt=0;
		sort(arr,arr+n);
		loop(i,0,n)
		{
			loop(j,i+1,n)
			{
				loop(k,j+1,n)
				{
					vi v;
					v.pb(arr[i]);v.pb(arr[j]);v.pb(arr[k]);
					sort(v.begin(),v.end());
					if(v[0]+v[1]>v[2] && v[0]!=v[1] && v[1]!=v[2] && v[0]!=v[2])
					cnt++;
					v.clear();
				}
			}
		}
		cout<<cnt<<endl;
			
    }

     
    int32_t main()
    {
        faster;
        /*sieve();*/
       // compute();
      // int t;cin>>t;
     int t=1;
        for(int ii=1;ii<=t;ii++)
        {
            solve(ii);
        }
     
     
        return 0;
    }


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define Ifor(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dfor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n, k, x;
	map<int, int> freq;
	cin >> n >> k;
	Ifor(i, 0, n) { cin >> x; freq[x]++; } 
	vii p;
	Trav(q, freq) p.pb(mp(q.second, q.first));
	sort(all(p));
	reverse(all(p));
	int ans = 0;
	while (sz(p) > k) { ans += p.back().first; p.pop_back(); }
	cout << ans << '\n'; 
}



Measured memory_bytes: 11764
"use strict";
    
const permutation = (n, r) => {
    let res = 1;
    
    for(let i=0; i<r; i++) {
        res *= n - i;
    }
    
    return res;
}

const combination = (n, r) => {
    return permutation(n, r) / permutation(r, r);
}

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n)).sort((a,b)=>b-a);
    
    let middle = A[0] / 2;
    let min = Infinity;
    let r;

    for(let i=1; i<N; i++) {
        const abs = Math.abs(middle - A[i]);
        
        if(abs < min) {
            r = A[i];
            min = abs;
        }
    }
    
    console.log(A[0] + " " + r);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 28604
#include<stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	int p[n];
	for(int i=0; i<n; i++){
		scanf("%d",&p[i]);
	}
	int count=0;
	for(int i=1; i<n-1; i++){
		if((p[i-1] <= p[i]) && (p[i] <= p[i+1])) count++;
		else if((p[i-1] >= p[i]) && (p[i] >= p[i+1])) count++;
	}
	printf("%d",count);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
using namespace std;

int main() {
	string temp;
	int n[26] = {0};
	char a[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	vector<string> vStr;
	while (getline(cin, temp) && !temp.empty()) {
		vStr.push_back(temp);
	}

	for (string s : vStr) {
		for (char& c : s) {
			c = tolower(c);
			switch (c) {
				case 'a':
					n[0]++; break;
				case 'b':
					n[1]++; break;
				case 'c':
					n[2]++; break;
				case 'd':
					n[3]++; break;
				case 'e':
					n[4]++; break;
				case 'f':
					n[5]++; break;
				case 'g':
					n[6]++; break;
				case 'h':
					n[7]++; break;
				case 'i':
					n[8]++; break;
				case 'j':
					n[9]++; break;
				case 'k':
					n[10]++; break;
				case 'l':
					n[11]++; break;
				case 'm':
					n[12]++; break;
				case 'n':
					n[13]++; break;
				case 'o':
					n[14]++; break;
				case 'p':
					n[15]++; break;
				case 'q':
					n[16]++; break;
				case 'r':
					n[17]++; break;
				case 's':
					n[18]++; break;
				case 't':
					n[19]++; break;
				case 'u':
					n[20]++; break;
				case 'v':
					n[21]++; break;
				case 'w':
					n[22]++; break;
				case 'x':
					n[23]++; break;
				case 'y':
					n[24]++; break;
				case 'z':
					n[25]++; break;
				default:
					break;
			}
		}
	}
	for (int i = 0; i < 26; i++) {
		cout << a[i] << " : " << n[i] << endl;
	}
	return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m;
	cin>>n>>m;
	int cnt = 0;
	for (int i = 0; i < m; ++i){
		int x;
		cin>>x;
		cnt += x;
	}
	cout<<(n-cnt < 0 ? -1 : n-cnt)<<endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define  LL long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
char s[200004];
int main()
{
    scanf("%s",s);
    int n=strlen(s);
    int l=0,r=n-1;
    LL ans=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='W')
        {
            ans+=1LL*(i-l);
            l++;
        }
    }

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


Measured memory_bytes: 384
def mx(ls,m):
	global n
	sum = 0
	for i in range(m):
		sum += (n-i)*ls[-i-1]
	return sum

def mn(ls,m):
	global n
	sum = 0
	for i in range(m):
		sum += (n-i)*ls[i]
	return sum
	
def f(ls,m,s):
	global n
	count = 0
	if m > 0:
		vmx,vmn = mx(ls,m),mn(ls,m)
		if vmx < s or vmn > s: return 0
		elif vmx == s or vmn == s: return 1
		for i in range(len(ls)):
			lls = ls[:]
			a = (n-m+1)*lls.pop(i)
			if s-a < 0:	break
			else: count += f(lls,m-1,s-a)
		return count
	else:
		return 1 if s == 0 else 0
			
ls = [i for i in range(10)]
while True:
	try:
		n,s = map(int, raw_input().split())
		print f(ls,n,s)
	except:
		break

Measured memory_bytes: 4268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int sum = 0;
		int max = 0;
		for (int i = 0; i < n; i++) {
			int price = Integer.parseInt(sc.next());
			sum += price;
			max = Math.max(max, price);
		}
		System.out.println(sum - max / 2);
		sc.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
  #endif

  string s;
  string t;
  cin >> s;
  cin >> t;

  string x = t.substr(0, s.length());
  if (x == s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3656