akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

void solve(){
  ll N;
  cin >> N;
  string S;
  cin >> S;

  ll cnt = 0;
  rep(i, N-2){
    if(S.substr(i, 3) == "ABC") cnt++;
  }
  cout << cnt << endl;
}


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


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;

    if (A <= 8 && B <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;

    return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	int n; cin >> n;
	vector<int> ans;
	if(n == 0) cout << 0;
	int i = 0;
	while(n != 0){
		if(n % 2 != 0){
			ans.push_back(1);
			if(i % 2 == 0) n--;
			else n++;
		}
		else{
			ans.push_back(0);
		}
		i++;
		n /= 2;
	}
	reverse(ans.begin(), ans.end());
	for(int j = 0; j < ans.size(); j++) cout << ans[j];
	cout << endl;
	return 0;	
}


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

bool compare_inverse(pair<int, int> a, pair<int, int> b) {
        return a.first > b.first;
}

int main(){
  int n,h;
  cin >> n >> h;
  int a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  vector<pair<int,int>>attack(2*n);
  for(int i=0;i<n;i++){
    attack[i] = make_pair(a[i],0);
  }
  for(int i=0;i<n;i++){
    attack[i+n] = make_pair(b[i],1);
  }
  sort(attack.begin(),attack.end(),compare_inverse);
  int technique_num=0;
  int ans = 0;
  while(h>0){
    if(attack[technique_num].second==1){
      h -= attack[technique_num].first;
      technique_num+=1;
      ans += 1;
    }else{
      ans += h/attack[technique_num].first + 1;
      if(h%attack[technique_num].first==0)ans -= 1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ull i=start;i<end;i++)
#define N 100001
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
int main() 
{
    fastio();

  int n;
  cin>>n;
  for(int i=n;i<=999;i++)
  {
    int m=i;
    if(m%10 == (m/10)%10 && m%10 == (m/100)%100)
    {
      cout<<i<<endl;return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) (vec).begin(),(vec).end()
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n;
long long s,a,ans,mod=1000000007;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		ans=(ans+a*s)%mod;
		s+=a;
		s%=mod;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
main(void)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a <= b && b <= c)printf("%d %d %d\n",a,b,c);
else if( a <= c && c<= b)printf("%d %d %d\n",a,c,b);
else if( b <= a && a<= c)printf("%d %d %d\n",b,a,c);
else if( b <= c && c<= a)printf("%d %d %d\n",b,c,a);
else if( c <= a && a<= b)printf("%d %d %d\n",c,a,b);
else if( c <= b && b<= a)printf("%d %d %d\n",c,b,a);
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#include <regex>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

int main()
{
	int x, n;
	int pn[100 + 1] = { 0 };

	cin >> x >> n;
	rep(i, n) {
		int p;
		cin >> p;
		pn[p] = 1;
	}
	int big = 101;
	for (int i = x; i <= 100; i++) {
		if ( pn[i] == 0 ) {
			big = i;
			break;
		}
	}
	int small = -1;
	for (int i = x; i >= 0; i--) {
		if ( pn[i] == 0 ) {
			small = i;
			break;
		}
	}
	
	int big_diff = abs(x - big);
	int small_diff = abs(x - small);

	if ( big_diff > small_diff )
	{
		cout << small << endl;
	}
	else if ( big_diff < small_diff )
	{
		cout << big << endl;
	}
	else
	{
		cout << MIN(big, small) << endl;
	}

	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main()
{
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(q);
    REP(i, q)
    cin >> a[i];

    vector<int> score(n, k);
    vector<int> answer(n);
    // for (int i = 0; i < a.size(); i++)
    // {
    //     for (int q = 0; q < score.size(); q++)
    //     {
    //         if (q != a[i] - 1)
    //             score[q] = score[q] - 1;
    //     }
    // }

    for (int i = 0; i < a.size(); i++)
    {
        answer[a[i] - 1]++;
    }

    for (int i = 0; i < score.size(); i++)
    {
        score[i] = score[i] - (q - answer[i]);
    }

    for (int i = 0; i < n; i++)
    {
        if (score[i] >= 1)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}

int main()
{
    std::cout << std::fixed << std::setprecision(15);
    Main();
}

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

void main_()
{
    int H, W;
    cin >> H >> W;
    vector<string> ss(H);
    for (auto&& s : ss) {
        cin >> s;
    }

    vector<ll> dp_p;
    vector<ll> dp(W, 1e9);
    dp[0] = ss[0][0] == '#' ? 1 : 0;

    // 右下に向けてDP
    for (ll i = 0; i < H; ++i) {
        for (ll j = 0; j < W; ++j) {
            if (j > 0) {
                // 左から来る場合
                auto cost = ss[i][j] == '#' && ss[i][j - 1] != '#' ? 1 : 0;
                dp[j] = min(dp[j], dp[j - 1] + cost);
            }
            if (i > 0) {
                // 上から来る場合
                auto cost = ss[i][j] == '#' && ss[i - 1][j] != '#' ? 1 : 0;
                dp[j] = min(dp[j], dp_p[j] + cost);
            }
        }
        dp_p = move(dp);
        dp.assign(W, 1e9);
    }

    cout << dp_p[W - 1] << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

using namespace std;

vector<int> a[111];
int f(int s, int *p, int &u) {
	int m = -1;
	u = s;
	for (auto i : a[s]) {
		if (i == p[s]) continue;
		p[i] = s;
		int v;
		int j = f(i, p, v);
		if (m < j) m = j, u = v;
	}
	return m + 1;
}
void g(int s, int *p, int *r, int ra) {
	r[s] = ra;
	for (auto i : a[s]) {
		if (i == p[s]) continue;
		p[i] = s;
		g(i, p, r, ra + 1);
	}
}
long h(int c1, int c2, int n) {
	int p[111] = {}, q[111] = {}, r[111], s[111];
	fill(s, s + 111, 1);
	p[c1] = c2;
	g(c1, p, r, 0);
	q[c2] = c1;
	g(c2, q, r, 0);
	for (int i = 1; i <= n; i++)
		s[r[i]] = max(s[r[i]], (int)a[i].size() - 1);
	s[0] = c1 == c2 ? s[0] + 1 : s[0] * 2;
	long l = 1;
	for (int i = 0; i < 111; i++)
		l *= s[i];
	return l;
}
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	int p[111] = {}, u;
	f(1, p, u);
	fill(p, p + 111, 0);
	int d = f(u, p, u);
	cout << d / 2 + 1 << ' ';
	int c1 = u;
	for (int i = 0; i < d / 2; i++)
		c1 = p[c1];
	int c2 = d % 2 ? p[c1] : c1;
	long m = h(c1, c2, n);
	if (c1 == c2) {
		for (auto c : a[c1])
			m = min(m, h(c1, c, n));
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
# import math
import numpy as np
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]
N, K = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip().split()[0]

B = [0]
count = 0
oz = 1
for s in S:
  if int(s) == oz:
    count+=1
  else:
    B.append(count)
    count=1
    oz=int(s)
B.append(count)
if oz==0:
  B.append(0)
# print(B)
L = len(B)-1
if 2*K+1>L:
  K = int(L/2)
# print("K",K)
B = np.cumsum(B)
# print(B)
C = []
for i in range(L):
  start = 2*i
  last = 2*i+2*K+1
  if last>L:
    # print("break",last)
    break
  C.append(B[last]-B[start])
# print(C)
ans = max(C)
print(ans)


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

int main() {
  int N,n=0;
  cin >> N;
  int t=N;
  while(t>0) {
    n += t%10;
    t/=10;
  }
    if(N%n==0) {cout << "Yes" << endl;}
    else {cout << "No" << endl;}
}

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  
  int counter = 0;
  for(int i =1 ; i <= n; i++){
    int sum = i /10000 + (i % 10000) / 1000 + (i % 1000) /100 + (i % 100) / 10 + i % 10;
    if(sum >= a && sum <= b){
      counter += i;   
    }
  }
  
  cout  << counter << endl;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define MAX_P 3000

ll N;
vector<ll> primes;
map<ll,ll> prime2;


void getPrime(ll n){
    vector<bool> p(n+10,true);
    for(ll i=2;i<=n;i++){
        if(!p[i]) continue;
        if(p[i]) primes.push_back(i);
        for(ll j=2;i*j<=n;j++) p[i*j] = false;
    }
}

int main(){
    bool f=false;
    getPrime(MAX_P+10);
    for(ll p : primes) prime2[p*p]=p;

    cin>>N;
    vector<ll> S(N);
    for(int i=0;i<N;i++) cin>>S[i];


    // NN[t] : Norm(t) の個数
    // Pair[t] : Pair(t)
    map<ll,ll> Norm,NN,Pair;
    for(int i=0;i<N;i++){
//        cout << i << " " << S[i] << endl;
        ll s = S[i];
        ll n = 1;       // norm(s)
        ll r = 1;       // pair(s)
        ll cnt=0;
        for(ll p : primes){
            cnt++;
            if(p>s) break;
            ll cnt=0;
            while(s%p==0){
                cnt++;
                s/=p;
            }
            cnt%=3;

            if(cnt==1){
                n *= p;
                r *= p*p;
            }else if(cnt==2){
                n *= p*p;
                r *= p;
            }
        }
//        cout << S[i] << " " << cnt << endl;

        n *= s;
        if(n==1){
            f=true;
            continue;
        }

        ll ss = sqrt(s);
        if(ss*ss==s){
            r *= ss;
        }else{
            r *= s*s;
        }

//        cout << n << " " << r << endl;

        NN[n]++;
        Pair[n]=r;
    }


    ll ans=0;
    if(f) ans=1;

    for(auto m:NN){
        ll n=m.first;
        ll p=Pair[n];
        if(!NN.count(p)){
            ans += NN[n];
        }else if(n <= p){
            ans += max(NN[n],NN[p]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

int main(){
  kyopro;
  ll A, B, T;
  cin >> A >> B >> T;
  cout << T / A * B << rt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  rep(i,m) {
    ll x;
    R x;
    n-=x;
  }
  if(n<0) pr(-1);
  else pr(n);
}

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


Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<algorithm>
#define R register
#define MIN(_A,_B) (_A<_B?_A:_B)
using namespace std;
long long n,m,t,s[3000010],kl=-1;
long long f[3000010],g=192608170817;
long long read()
{
	R long long x=0;R char ch=getchar();
	for(;ch>'9'||ch<'0';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';return x;
}
int main()
{
	n=read(),m=read(),t=read();
	for(R int i=1;i<=n;i++) s[i]=read();
	sort(s+1,s+n+1);
	for(R int i=1;i<=n;i++){
		while(kl<i&&2*(s[i]-s[kl+2])>=t){
			kl++;
			g=MIN(g,f[kl]-s[kl]-2*s[kl+1]);
		}
		f[i]=MIN(g+3*s[i],f[kl+1]+s[i]-s[kl+1]+t);
	}
	printf("%lld\n",f[n]+m-s[n]);
	return 0;
}


Measured memory_bytes: 2944
<?php
// Your code here!
list($n,$m,$k) = explode(" ",trim(fgets(STDIN)));
$a = explode(" ",trim(fgets(STDIN)));
$b = explode(" ",trim(fgets(STDIN)));
// array_unshift($a,"0");//最初はAを0冊にしたいから0を追加
$t=0;
// var_dump($b);

//N冊全部読んだことにする
for($i=0; $i<$m; $i++){
    $t += $b[$i];//Bの本の全ての合計時間
}

$j = $m;//mだけかどっちかわからない
$ans = 0;//答えのmax
//1回目のループではAを一冊も選ばない
//$hがaから$h冊選ぶということになっている
//最初は$hが0なので一冊も読まない
for($h=0; $h<$n+1; $h++){
    while($j>0 && $t>$k){//$jが0より大きい　かつ　合計時間が$kより大きい時
        --$j;
        $t -= $b[$j];
    }
    if($t > $k){//もし諦めれる本がないなら       
    break;
    }
    $ans = max($ans, $h+$j);
    if($h == $n){
        break;
    }
    $t += $a[$h];
    // return 0;
}

// echo $t;
echo $ans;

?>


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

using namespace std;

int main() {
  size_t H;
  cin >> H;

  if (H == 0) {
    cout << 0 << endl;
    return 0;
  } else if (H == 1) {
    cout << 1 << endl;
    return 0;
  }

  size_t h = H / 2;
  size_t n = 1;
  while (true) {
    if ((size_t) pow(2, n) > h) {
      cout << (size_t) (pow(2, (n + 1)) - 1) << endl;
      break;
    }
    n++;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<vector>
#include<cmath>

using namespace std;

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

    if(a>0)cout << "Positive" << endl;

    else if(b>=0)cout << "Zero" << endl;

    else if((b-a)%2==0)cout << "Negative" << endl;

    else cout << "Positive" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double 
#define foi(a,n) for(int i = a; i < n; i++)
#define ee 1000000007
#define pb push_back
 
using namespace std;

void solve() {
    ll n;
	cin >> n;
	if(n){
		cout << 0;
		return;
	}
	else cout << 1;
}

int main() {
    int t = 1;
    //~ cin >> t;
    while(t--){
		solve();
		cout << '\n';
	}
}


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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main() {
  int n;
  ll ans=0;
  cin >> n;
  vector<string> str(n);
  unordered_map<string,int> strs;
  rep(i,n) {
    cin >> str[i];
    sort(str[i].begin(),str[i].end());
  }
  rep(i,n){
    if (strs.count(str[i])){
      ans+=strs[str[i]];
      strs[str[i]]++;
      
    }
    else{
      strs[str[i]]=1;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 17700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,d,x;
    int count =0;
    cin >> n >> d >> x;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        count++;
        for(int j=1;j<=d;j++){
            if((x*j)+1<=d){
                count++;
            }else{
                break;
            }
    }
    }
    cout << x+count << endl;
}

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

void redbrack(char **a, int x, int y,int m, int h,int *c)
{
  (*c)++;
  a[x][y]='#';
  if(x-1 >= 0){
	if(a[x-1][y] == '.')
		{
			redbrack(a,x-1,y,m,h,c);
		}}
	if(y-1 >= 0){
	if(a[x][y-1] == '.')
		{ 
			redbrack(a,x,y-1,m,h,c);
		}}
	if(x+1 < h){
	if(a[x+1][y] == '.')
		{ 
			redbrack(a,x+1,y,m,h,c);
		}}
	if(y+1 < m){
	if(a[x][y+1] == '.')
		{ 
			redbrack(a,x,y+1,m,h,c);
		}}
}

int main(void)
{

	int i,j,*c;
	char **a;
	int m,h;
	int x,y;
	
	while(1)
		{
			c = (int *)malloc(sizeof(int));
		  *c=0;
			scanf("%d %d ",&m,&h);
			if(m==0 && h==0)break;

			a = (char **)malloc(sizeof(char *)*h);
			for(i=0;i<h;i++){
				a[i]=(char *)malloc(sizeof(char)*m);
			}

			for(i=0;i<h;i++)
				{
					scanf("%s ",a[i]);
					for(j=0;j<m;j++){
					  if(a[i][j]=='@')
								{
									x = i;
									y = j;
								}
						}
				}
		redbrack(a,x,y,m,h,c);
		printf("%d\n",*c);
		}
		
		return 0;
}
		

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <sstream>
#include <bitset>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;  
ll ans;  
int num[100010];  
int main(){  
    int n;  
    cin>>n;  
    for(int i=1;i<=n;i++){
        cin>>num[i];  
        if (num[i]==i) ans++;
    }  
    if(!ans){  
        cout<<0<<endl;  
        return 0;  
    }  
    ans=0;  
    for(int i=1;i<=n;i++){  
        if(num[i]==i){  
            ans++;  
            swap(num[i],num[i+1]);  
        }  
    }  
    cout<<ans<<endl;  
    return 0;
}  

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

using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	int arr[m];
	for(int i=0;i<m;i++)cin>>arr[i];
	sort(arr,arr+m);
	int ans=arr[m-1]-arr[0];
	int diff[m-1];
	for(int i=0;i<m-1;i++){
		diff[i]=-arr[i+1]+arr[i];
	}
	sort(diff,diff+(m-1));
	for(int i=0;i<n-1 && i<m-1;i++){
		//cout<<diff[i]<<endl;
		ans+=diff[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <chrono>
#include<math.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std::chrono;
using namespace std;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// declaration: ordered_set os;  methods->  1. *os.find_by_order(x)   2. os.order_of_key(k) ->return int

#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
#define ld long double
const ll mod=998244353;

void solve(){
    int a[6];
    fr(i,1,6)
    cin>>a[i];
    fr(i,1,6){
        if(a[i]==0){
            cout<<i;
            return;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--)
    solve();

}


Measured memory_bytes: 3616
#include <iostream>

using namespace std;

int main() {
	int N{};
	cin >> N;
	if (N == 1) {
		cout << "Hello World" << endl;
	}
	else if (N==2) {
		int A{};
		int B{};
		cin >> A;
		cin >> B;
		cout << A + B << endl;
	}
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)

ll sq(ll x){
	return x*x;
}

bool isvowel(char c){
	int i;
	string v="aeiou";
	for(i = (v.size()-1); i>=0; --i){
		if(c == v[i]){
			return true;
		}
	}
	return false;
}

int main(void){
	int a,b;
	char op;
	cin >> a >> op >> b;
	cout << ((op=='+')?(a+b):(a-b)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)




int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(0<a&&0<c){
        c-=b;
        if(c<=0){
         cout<<"Yes"<<endl;
         return 0;}
        a-=d;
        if(a<=0){
         cout<<"No"<<endl;
         return 0;}
    }
   
}



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

int main() {
  int N;
  cin >> N;
  string color;
  string P = "Three";
  
  for(int i = 0; i < N; i++){
    cin >> color;
    if(color == "Y"){
      P = "Four";     
      cout << P << endl;
      break;
    }
  }
  if(P == "Three"){
    cout << P << endl;
  }
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void){

	string str[1010];
	int num[1010]={0};
	char inp[41];
	int max=0,max2=0;
	while(scanf("%s",&inp)!=EOF){
		for(int i=0;;i++){
			if(str[i].empty()==1){
				str[i]=inp;
				num[i]++;
				break;
			}
			if(str[i]==inp){
				num[i]++;
				break;
			}
		}
	}

		for(int i=1;!str[i].empty();i++){
			if(str[max].size()<str[i].size()) max=i;
			if(num[max2]<num[i]) max2=i;
		}
	cout<<str[max2]<<" "<<str[max]<<endl;

	return 0;
}

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

int main(){
	int n,r;
	while(cin>>n>>r,n,r){
		vector<int>v;
		for(int i=0;i<n;i++){
			v.push_back(i+1);
			}
			
			for(int i=0;i<r;i++){
				int p,c;
				cin>>p>>c;
				
				for(int i=0;i<c;i++){
					v.push_back(v[n-c-p+1]);
					v.erase(v.begin()+n-c-p+1);
					}
				}
		cout<<v[n-1]<<endl;			
		}
		return 0;
	}

Measured memory_bytes: 3004
#include <iostream>
using namespace std;
     
int main()
{
	int n, k;
	cin >> n >> k;
    	
	if ((n - k) >= (k - 1))
    	{
    		cout << "YES" << endl;
    	}
	else
    	{
    		cout << "NO" << endl;
    	}
	return 0;

}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const *argv[]) {
  int n=0,x=0;
  while(1){
    int count=0;
    std::cin >> n >> x;
    if(n == 0 && x == 0)break;
    int sum=0;
    for(int i=1;i<=n-2;i++){
      for(int j=i+1;j<=n-1;j++){
        for(int k=j+1;k<=n;k++){
          sum = i+j+k;
          if(sum == x)count++;
          else if ((i + j + k) > x) break;
        }
      }
    }
    std::cout << count << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3076
N,M = map(int,input().split())

ypi = []

for i in range(M):
    p, y = map(int,input().split())
    ypi.append([y, p, i])

ypi.sort()

rank = [0] * N

ans = [''] * M
for count in range(M):
    y, p, i = ypi[count]
    rank[p-1] += 1
    ans[i] = '{:06}'.format(p)+'{:06}'.format(rank[p-1])

for s in ans:
    print(s)

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

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

    string s;
    cin >> s;
    s = s + 'R';

    vector<int> pos;
    int r = 0;
    int l = 0;
    char prev = 'R';
    rep(i, s.size()){
        
        if(s[i] == 'R'){
            if(prev == 'R') ++r;
            else{
                pos.push_back(r-1);
                pos.push_back(-1);
                pos.push_back(l-1);
                prev = 'R';
                r = 1;
                l = 0;
            }
        }
        else ++l;

        prev = s[i];

    }

    int le = 0;
    int ri = 0;
    bool flg = false;
    for(int p: pos){
        if(p != -1){
            if(flg) {
                ri = p;
                rep(i, le) cout << 0 << " ";
                cout << 1 + le/2 + (ri+1)/2 << " ";
                cout << 1 + (le+1)/2 + ri/2 << " ";
                rep(i, ri) cout << 0 << " ";

                le = 0;
                ri = 0;
                flg = false;
            }
            else le = p;
        }
        else flg = true;
        
    }
    cout << endl;
}

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

using namespace std;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int a, b, c;
  std::cin >> a >> b >> c;
  std::cout << ((c >= a && c <= b) ? "Yes" : "No") << std::endl;
  return 0;
}


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

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin >> n;
   for (int i = 1; i <= n; i++) {
      if (floor(i * 1.08) == n) {
         cout << i << '\n';
         return 0;
      }
   }
   cout << ":(" << '\n';
   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int n, a, b,kotae;
int main() 
{
	int kurai, hnbt = 0, kaeri = 0;
	scanf("%d", &n);
	scanf("%d", &a);
	scanf("%d", &b);
	for (int i = 1; i < n + 1; i++) {
		kurai = i;
		while (1) {
			hnbt += (kurai % 10);
			kurai = (kurai / 10);
			if (kurai == 0) break;
		}
		if ((a <= hnbt) && (hnbt <= b)) {
			kaeri += i;
		}
		hnbt = 0;
	}
	kotae = kaeri;
	printf("%d", kotae);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
  int sub1[4], sub2[2], i, min = 100, high, total = 0;

  for(i = 0; i < 4; i++){
    scanf("%d", &sub1[i]);
    total += sub1[i];
  if(min > sub1[i])
    min = sub1[i];
  }

  for(i = 0; i < 2; i++)
    scanf("%d", &sub2[i]);

  if(sub2[0] > sub2[1])
    high = sub2[0];
  else
    high = sub2[1];

  printf("%d\n", total - min + high);

  return 0;
}

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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)

#define ll long long

#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));

int main(){
	int N;
cin >> N;
  if(N == 0)cout << 1 << endl;
  else cout << 0 << endl;
  
return 0;
}

Measured memory_bytes: 3632
n = int(input())
listA = list(map(int, input().split()))
q = int(input())

totalSum = 0
numMap = {}
for a in listA:
    totalSum+=a
    if a in numMap:
        numMap[a]+=1
    else:
        numMap[a]=1

for i in range(q):
    b, c = map(int, input().split())
    if b in numMap:
        count = numMap[b]
        del numMap[b]
        if c in numMap:
            numMap[c]+=count
        else:
            numMap[c]=count
        totalSum+=c*count-b*count
    print(totalSum)


Measured memory_bytes: 20948
#include<stdio.h>
#define N 100
int main(){
  int i,j,v,n;
  int A[1000];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){  
    scanf("%d",&A[i]);
  }
  
  for(i=1;i<n;i++){
    for(j=0;j<n;j++){
      if(j==n-1){
	printf("%d\n",A[j]);
	break;
      }
      printf("%d ",A[j]);
    } 
    v = A[i];   
    j = i -1;
    while((j >= 0 )&&( A[j] > v)){
      A[j+1] =A[j];
      j--;
    }
  
    A[j+1]= v;
  }
  for(i=0;i<n;i++){
      if(i==n-1){
	printf("%d\n",A[i]);
	break;
      }
 printf("%d ",A[i]);      
    }
  return 0;
}



Measured memory_bytes: 2084
import sys
def input():
    return sys.stdin.readline()
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
a = [0] * (N+1)
b = [0] * (M+1)
for i in range(N):
    a[i+1] = a[i] + A[i]
for i in range(M):
    b[i+1] = b[i] + B[i]
ans = 0
j = M
for i in range(N+1):
    tmp = K - a[i]
    if tmp < 0:
        break
    while b[j] > tmp:
        j -= 1
    ans = max(ans, i + j)
print(ans)

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

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

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

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


int main()
{
    string s,t;
    cin >> s >> t;
    int n = s.size() + t.size();
    for(int i = 0; i < n; i++){
        if(i % 2 == 0) cout << s[i/2];
        else cout << t[i/2];
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define bg begin()
#define end end()
#define sz size()
#define vi vector<int>
#define vl vector<long long int>
int main(){
	fast;
	ll n,ans=0;
	cin>>n;
	ll arr[n];
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		if((i+1)%2!=0&&arr[i]%2!=0)
			ans++;
	}
	cout<<ans;
	return 0;
}



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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll K;
	cin>>K;
    if(K<=9){
        cout<<K<<"\n";
        return 0;
    }
    
    ll n = 0;
    deque<ll> q;
    rep(i,9){
        q.push_back(i+1);
    }
    n+=9;
    ll a;
    ll b;
    while(n<K){
        a = q.front();q.pop_front();
        b = a%10;
        if(b-1>=0){
            ++n;
            q.push_back(a*10+b-1);
        }
        ++n;
        q.push_back(a*10+b);
        if(b+1<=9){
            ++n;
            q.push_back(a*10+b+1);
        }
    }
    ll ans;
    if(n==K){
        ans = q.back();
    }else if(n==K+1){
        q.pop_back();
        ans = q.back(); 
    }else if(n==K+2){
        q.pop_back();
        q.pop_back();
        ans = q.back();
    }
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    int n,m;
    cin >> n >> m;
    cout << (n == m ? "Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io;
fn main() {
    let mut x = String::new();
    io::stdin().read_line(&mut x).unwrap();
    let x: u32 = x.trim().parse().unwrap();
    let h = x / 3600;
    let m = x % 3600 / 60;
    let s = x % 60;
    println!("{}:{}:{}", h, m, s);
}


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

using namespace std;

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

	string ans;
	int stat = 0;
	int min_stat = 0;
	for (auto c : s) {
		if (c == '(') {
			stat++;
		} else {
			stat--;
			min_stat = min(min_stat, stat);
		}
	}

	if (min_stat < 0) {
		ans += string(-min_stat, '(');
	}
	ans += s;
	stat += -min_stat;
	if (stat > 0) {
		ans += string(stat, ')');
	}

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


Measured memory_bytes: 256
V = int(input())
E = V - 1
G = {}
for i in range(V):
    G[i] = {}

for _ in range(E):
    s, t, c = [int(_) for _ in input().split()]
    s -= 1  # 0-indexed
    t -= 1  # 0-indexed
    G[s][t] = c
    G[t][s] = c
Q, K = [int(_) for _ in input().split()]
K -= 1  # 0-indexed
XY = [[int(_) for _ in input().split()] for _ in range(Q)]

INF = float('inf')
D = [INF] * V
D[K] = 0
cand = []
for j in G[K].keys():
    cand += [(K, j)]
while True:
    if cand:
        x, y = cand.pop()
        if D[y] == INF:
            D[y] = D[x] + G[x][y]
            for z in G[y].keys():
                cand += [(y, z)]
    else:
        break
for x, y in XY:
    x -= 1
    y -= 1
    print(D[x] + D[y])


Measured memory_bytes: 82192
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;
const int maxn=123456;
char ch[maxn];
int n;
int ai[maxn];
int bi[maxn];
void init()
{
    n=strlen(ch+1);

}
int ans;
void play()
{

    ans=1;
    for(int i=1; i<=n/2; i++)
    {
        if(ch[i]!=ch[n-i])
        {
            ans=-1;
            return;
        }
    }
    if(ch[n]=='1')
    {
        ans=-1;
        return;
    }
    if(ch[1]=='0')
    {
        ans=-1;
        return;
    }
    int fa=2;
    int chi=1;
    int st=1;
    for(int i=1; i<=n-1; i++)
    {
        if(ch[i]=='1')
        {
            ai[st]=fa;
            bi[st]=chi;
            chi=fa;
            fa++;
        }
        else
        {
            ai[st]=chi;
            bi[st]=fa;
            fa++;
        }

        st++;
    }

}

void Pri()
{
    if(ans==-1)
    {
        printf("-1\n");
    }
    else
    {
        for(int i=1; i<n; i++)
        {
            printf("%d %d\n",ai[i],bi[i]);
        }
    }

}



int main()
{



    while(scanf("%s",ch+1)!=EOF)
    {
        init();
        play();
        Pri();



    }




    return 0;

}


Measured memory_bytes: 2304
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n; cin>>n;
    vector<int> p(n,0),a(n,0),b(n,0);
    rep(i,n){
        cin>>p[i]; p[i]--;
    }
    rep(i,n) a[i]=i*20000+1;
    for(int i=n-1;i>=0;i--) b[i]=(n-i)*20000+a.back();
    rep(i,n) b[p[i]]+=i;
    rep(i,n){
        cout<<a[i];
        if(i<n-1) cout<<" ";
    }
    cout<<endl;
    rep(i,n){
        cout<<b[i];
        if(i<n-1) cout<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 3876
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	string s2 = s.substr(1, n-2);
	string o[4] = {"SSS", "WSW", "SWW", "WWS"};
	string x[4] = {"SSW", "WSS", "SWS", "WWW"};
	queue<string> q;
	if (s2[0] == 'o') {
		for (int i = 0; i < 4; i++) {
			q.push(o[i]);
		}
	} else {
		for (int i = 0; i < 4; i++) {
			q.push(x[i]);
		}
	}
	for (int i = 1; i < n-2; i++) {
		queue<string> q2;
		while (!q.empty()) {
			string ss = q.front();
			q.pop();
			int sz = ss.size();
			string ss2 = ss.substr(sz-2, 2);
			if (s2[i] == 'o') {
				for (int j = 0; j < 4; j++) {
					if (ss2 == o[j].substr(0, 2)) {
						q2.push(ss+o[j].substr(2));
					}
				}
			} else {
				for (int j = 0; j < 4; j++) {
					if (ss2 == x[j].substr(0, 2)) {
						q2.push(ss+x[j].substr(2));
					}
				}
			}
		}
		q = q2;
	}
	string ans = "-1";
	while (!q.empty()) {
		string ks = q.front(); 
		q.pop();
		string sf = ks.substr(n-1)+ks.substr(0, 2);
		string sff = ks.substr(n-2)+ks.substr(0, 1);
		bool h = false;
		if (s[0] == 'o') {
			for (int i = 0; i < 4; i++) {
				if (sf == o[i]) {
					h = true;
				}
			}
		} else {
			for (int i = 0; i < 4; i++) {
				if (sf == x[i]) {
					h = true;
				}
			}
		}
		bool h2 = false;
		if (s[n-1] == 'o') {
			for (int i = 0; i < 4; i++) {
				if (sff == o[i]) {
					h2 = true;
				}
			}
		} else {
			for (int i = 0; i < 4; i++) {
				if (sff == x[i]) {
					h2 = true;
				}
			}
		}
		if (h && h2) {
			ans = ks;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1172
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
from numba import njit
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N,K = LI()
p = LI()
p.sort()
p1 = np.array(p)
print(p1[:K].sum())


Measured memory_bytes: 91800
//cwystc <--> 陈威宇是天才  --by cwy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const double PI=acos(-1);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define per(i,a,b) for (int i=(a);i>=(b);i--)
#define Rep(i,a,b) for (int i=(a);i<(b);i++)
#define Per(i,a,b) for (int i=(a);i>(b);i--)
#define travel_set(it,a) for (set<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_map(it,a) for (map<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_vec(it,a) for (vector<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define p(x) cout << x << endl;
#define def cout << "find" << endl;
#define what_is(x) cout << #x << " is " << x << endl;
template <class T>T sqr(T x){return x*x;}
template <class T>T alex(T x){return (x>0)?x:-x;}
template <class T>void read(T&x){
	x=0;T f=1;char ch=getchar();
	while ((ch<48||ch>57)&&ch!=45)ch=getchar();
	if (ch==45)f=-1,ch=getchar();
	while (ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();
	x*=f;
}

//-------------------------------------------------head-------------------------------------------------

#define maxn 200005
ll n,a[maxn];
ll p[maxn],q[maxn];
ll sum(int x,int y){return a[y]-a[x-1];}
ll max(ll a,ll b,ll c,ll d){
	ll res=a;
	if (b>res)res=b;
	if (c>res)res=c;
	if (d>res)res=d;
	return res;
}
ll min(ll a,ll b,ll c,ll d){
	ll res=a;
	if (b<res)res=b;
	if (c<res)res=c;
	if (d<res)res=d;
	return res;
}
ll calc(ll a,ll b,ll c,ll d){
	return max(a,b,c,d)-min(a,b,c,d);
}
int main(){
	read(n);rep(i,1,n)read(a[i]),a[i]+=a[i-1];
	int pos=1;
	rep(i,2,n-2){
		while (pos+1<i&&max(sum(1,pos+1),sum(pos+2,i))<=max(sum(1,pos),sum(pos+1,i)))pos++;
		p[i]=sum(1,pos),q[i]=sum(pos+1,i);
	}
	pos=n-1;ll ans=1e18;
	per(i,n-2,2){
		while (pos-1>i&&max(sum(pos,n),sum(i+1,pos-1))<=max(sum(pos+1,n),sum(i+1,pos)))pos--;
		ll _p=sum(pos+1,n),_q=sum(i+1,pos);
		ans=min(ans,calc(_p,_q,p[i],q[i]));
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define FOR(n) for(int i=0;i<n;i++)
#define till(n) for(int i=1;i<=n;i++)
#define mod 1000000007
using namespace std;

ll h[100005], k;

ll dp[100005];

ll getAns(int n){
    if(n==0) return 0;
    if(n==1) return 0;

    if(dp[n]!=-1)return dp[n];

    ll ans = INT_MAX;
    for(int i = 1; i <= k; i++)
        if(n>i)
            ans = min( ans, getAns(n-i) + abs(h[n]-h[n-i]) );
    //cout << ans << endl;
    return dp[n] = ans;
}

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

    int n;cin>>n>>k;

    for(int i=1;i<=n;i++)cin >>h[i], dp[i]=-1;

    cout << getAns(n) << endl;

	return 0;
}


Measured memory_bytes: 8064
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
yosage = 100000000
ans = 0
for i in range(n):
	hi = abs(a-(t-h[i]*0.006))
	if hi < yosage:
		yosage = hi
		ans = i+1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;

int main(void) {
    cpp_int X, K, D;
    cin >> X >> K >> D;
    if(X < 0) X *= -1;
    if(X - K*D >= 0) {
        cout << X - K*D << endl;
    } else if((X/D)%2 == K%2) {
        cout << X%D << endl;
    } else {
        cout << (abs((X - K*D)%D) == 0 ? D : abs((X - K*D)%D)) << endl;
    }
    return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <utility>

using namespace std;

int main(void)
{
  int N;
  string S[200000];

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

  map<string, int> mp;

  for (int i = 0; i < N; i++) {
    mp[S[i]] += 1;
  }

  std::multimap<int, std::string, std::greater<int>> sorted_map;
  for (auto i = mp.begin(); i != mp.end(); ++i) {
    sorted_map.insert(std::make_pair(i->second, i->first));
  }

  auto itr = sorted_map.begin();
  // cout << "begin(): " << itr->first << endl;
  int max = itr->first;
  map<string, int> mp_ans;
  for (auto i = sorted_map.begin(); i != sorted_map.end(); ++i) {
    if (i->first != max) {
      break;
    }
    // cout << i->second << " (has " << i->first << " legs)" << '\n';
    mp_ans[i->second] = i->first;
  }

  for (auto i = mp_ans.begin(); i != mp_ans.end(); ++i) {
    cout << i->first << "\n";
  }

  return 0;
}


Measured memory_bytes: 51712
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<cstring>
#include<climits>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
inline int read() {
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c==EOF)exit(0);if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 2000
#define INF 0x3f3f3f3f
#define Mod 924844033
bool cut[2*MAXN+5];
LL f[2*MAXN+5][2*MAXN+5][2],fac[MAXN+5];
int main(){
	fac[0]=1;
	for(int i=1;i<=MAXN;i++)
		fac[i]=fac[i-1]*i%Mod;
	int n=read(),k=read(),cnt=0;
	for(int i=1;i<=k;i++)
		for(int t=0;t<=1;t++)
			for(int j=i;j<=n;j+=k){
				++cnt;
				if(j==i)
					cut[cnt]=1;
			}
	f[1][0][0]=1;
	for(int i=2;i<=2*n;i++)
		for(int j=0;j<=n;j++){
			f[i][j][0]=(f[i-1][j][1]+f[i-1][j][0])%Mod;
			if((!cut[i])&&j)
				f[i][j][1]=f[i-1][j-1][0];
		}
	LL ans=0;
	for(int j=0;j<=n;j++)
		ans=(ans+(j&1?-1:1)*(f[2*n][j][0]+f[2*n][j][1])*fac[n-j]%Mod)%Mod;
	ans=(ans+Mod)%Mod;
	printf("%lld\n",ans);
	return 0;
}
//

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

int n, m;
vector<int> p0(100100); //提出番号→問題番号
vector<string> p1(100100);//提出番号→提出結果
vector<bool> q(100100); //問題ごとにacしたかを記録
vector<int> q1(100100); //いつ正解したか
int ac = 0, wa = 0;

void input(){
  cin >> n >> m;
  rep(i, m){
    cin >> p0.at(i) >> p1.at(i);
    //cout<< p0.at(i) << " "<< p1.at(i) << " ";
  }
  rep(i, 100100){
    q.at(i) = false;
  }
}
/*
void update(int i){ //提出番号→問題番号、結果→更新
  int num = p0.at(i);//問題番号
  //cout <<  num <<" "<<q.at(num) << " ";
  if(q.at(num)){
    return;
  }
  if(p1.at(i) == "AC"){
    ac++;
    q.at(num) = true;
  }else if(p1.at(i) == "WA"){
    wa++;
  }
}*/
void func1(int i){
  int num = p0.at(i);
  if(!q.at(num) && p1.at(i) == "AC"){
    ac++;
    q.at(num) = true;
    q1.at(num) = i;
  }
}
void func2(int i){
  int num = p0.at(i);
  if(q.at(num) && p1.at(i) == "WA" && q1.at(num) > i){
    wa++;
  }
} 

void solve(){
  input();
  rep( i , m ){
    func1(i);
  }
  rep( i, m ){
    func2(i);
  }
  cout << ac << " " << wa << endl;
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 6528
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) (v).begin(), (v).end()

int main() {
  int N;
  vector<int> A, B;
  // a+bとindexのpair
  vector<pair<int, int>> P;
  ll result = 0;
  cin >> N;
  rep(i, N) {
    // cout << i << endl;
    int a, b, c;
    cin >> a >> b;
    A.push_back(a);
    B.push_back(b);
    result -= b;
    P.push_back(make_pair(a, b));
  }
  sort(all(P),
       [](auto x, auto y) { return x.first + x.second > y.first + y.second; });

  rep(i, N) {
    if (i % 2 == 0) {
      // turn for A
      result += P[i].first + P[i].second;
    } else {
      // turn for B
      // result -= B[P[i].second];
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 2028
s = list(input())
ans_list = []
for i in range(len(s)-2):
    ans = 100 * int(s[i]) + 10 * int(s[i+1]) + int(s[i+2])
    ans_list.append(abs(ans - 753))
ans_list = sorted(ans_list)
print(ans_list[0])

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		try {
			String[] input = br.readLine().split(" ");
			int a = Integer.parseInt(input[0]);
			int b = Integer.parseInt(input[1]);
			int c = Integer.parseInt(input[2]);
			
			double S = a * b * Math.sin(Math.toRadians(c)) / 2;
			double L = a + b + Math.sqrt(a*a + b*b -2*a*b*Math.cos(Math.toRadians(c)));
			double h = 2 * S / a;
			
			System.out.println(S);
			System.out.println(L);
			System.out.println(h);
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
		
	}
}


Measured memory_bytes: 24584
e, y = map(int, input().split())

if e == 0:
    if 1868 <= y <= 1911:
        ans = "M" + str(y-1868+1)
    elif 1912 <= y <= 1925:
        ans = "T" + str(y-1912+1)
    elif 1926 <= y <= 1988:
        ans = "S" + str(y-1926+1)
    else:
        ans = "H" + str(y-1989+1)

elif e == 1:
    ans = 1868 + y - 1
elif e == 2:
    ans = 1912 + y - 1
elif e == 3:
    ans = 1926 + y - 1
else:
    ans = 1989 + y - 1

print(ans)


Measured memory_bytes: 5596