akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
using namespace std;

constexpr int kN = int(1E5 + 10);

int a[kN];
long long int s[kN];

int main() {
	long long int n, m, v, p, pos;
	long long int now = 0;
	scanf("%lld%lld%lld%lld", &n, &m, &v, &p);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	s[0] = 0;
	for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
	for (int i = n - p; i >= 1; i--) {
		if (a[i] == a[i + 1]) continue;
		if (p + i - 1 < v) {
			if (a[i] + m < a[n - p + 1]) {
				printf("%lld\n", n - i);
				return 0;
			}
			now = s[n - p + 1] - s[i] + (v - p + 1 - i) * m;
			if ((now - 1) / (n - p - i + 1) >= a[i] + m) {
				printf("%lld\n", n - i);
				return 0;
			}
		}
		else {
			if (a[i] + m >= a[n - p + 1]) continue;
			else {
				printf("%lld\n", n - i);
				return 0;
			}
		}
	}
	printf("%lld\n", n);
}


Measured memory_bytes: 1280
a,b,c = sorted(map(int, raw_input().split()))
count = 0
 
if (c-a)%2==(c-b)%2==0:
    count = (c-a+c-b)/2
elif (c-a)%2 and (c-b)%2:
    c-=1
    count = (c-a+c-b)/2 + 1
else:
    count = (c-a + c-b + 1)/2 + 1
 
print count


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

int main()
{

string str="";
cin>>str;
for(int i=0;i<str.length();i++)
{
if(str[i]=='B' && i!=0)
{
    int count=0;
    int j=i;
    while(str[j]=='B')
        {str[j]='.';count++;j++;}
    
    for(int k=i-1;k>=0;k--)
    {
        if(count>0)
        {
            str[k]='.';
            count--;
        }
    }
    
    
    i=j-1;
}
if(str[i]=='B' && i==0)
{

    str[i]='.';
    
    
}
}

for(auto i:str)
if(i!='.')cout<<i;




return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int n,m,fa[100005],dis[100005];
bool ok=1;
int find(int x){
    if(fa[x]!=x){
        int nf=fa[x];
        fa[x]=find(fa[x]);
        dis[x]+=dis[nf];
    }
    return fa[x];
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=m;i++){
        int l,r,d;
        scanf("%d%d%d",&l,&r,&d);
        int rl=find(l),rr=find(r);
        if(rl==rr&&dis[l]-dis[r]!=d)
            ok=0;
        if(rl!=rr){
            fa[rl]=rr;
            dis[rl]=d+dis[r]-dis[l];
        }
    }
    if(ok)printf("Yes");
    else printf("No");
    return 0;
} 

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

const int MAXN = 200100;
int a[MAXN];
map<int,int> mp;
struct Ball
{
    int color,number;
};
Ball balls[MAXN];

bool cmp(const Ball& a, const Ball& b)
{
    return a.number < b.number;
}

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i = 0; i < n; ++i)
    {
        scanf("%d",&a[i]);
        mp[a[i]]++;
    }
    if(mp.size() <= k)
    {
        puts("0");
        return 0;
    }
    int len = 0;
    for(map<int,int>::iterator it = mp.begin(); it != mp.end(); ++it)
    {
        balls[len].color = it->first;
        balls[len++].number = it->second;
    }
    //按照数量从小到达排序
    sort(balls,balls+len,cmp);
    int endi = len - k;
    int res = 0;
    for(int i = 0; i < endi; ++i)
        res += balls[i].number;
    printf("%d\n",res);
    return 0;
}


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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    string table = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int n;
    while (cin >> n, n) {
        vi key(n);
        string s;
        REP(i, n) cin >> key[i];
        cin >> s;
        REP(i, SZ(s)) cout << table[(table.find(s[i]) - key[i%n] + 52) % 52];
        cout << endl;
    }
}

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

#define double long double
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

int norm(int a) {
  return ((a % MOD) + MOD) % MOD;
}

int mul(int a, int b) {
  return int(a * 1LL * b % MOD);
}

int binPow(int a, int k) {
  int ans = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
  }
  return ans;
}

// If I need to find (x / a) % MOD, I need to use this function:
//    (x / a) % MOD = (x * inv(a)) % MOD
int inv(int a) {
  int b = binPow(a, MOD - 2);
  assert(mul(a, b) == 1);
  return b;
}

// Init variables here
const int N = 1e5 + 7;

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);

}

void solve() {
  int n, m;
  scanf("%d %d", &n, &m);
  vec<int> v[m];
  int a, b;
  FOR(i, 0, n) {
    scanf("%d %d", &a, &b);
    if (a <= m) {
      v[m - a].push_back(b);
    }
  }
  int ans = 0;
  priority_queue<int> pq;
  FORD(i, m - 1, 0) {
    for (int c : v[i]) {
      pq.push(c);
    }
    if (pq.size()) {
      ans += pq.top();
      pq.pop();
    }
  }
  printf("%d\n", ans);
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  //ios_base::sync_with_stdio(false); cin.tie();
  //auto beginProgram = chrono::steady_clock::now();
  //int t; scanf("%d", &t); while (t--) 
  {
    input();
    solve();
  }
  //auto endProgram = chrono::steady_clock::now();

  return 0;
}




Measured memory_bytes: 5504
#include<stdio.h>
int main(){
int a,b;
char op;

while(1){
 scanf("%d %c %d", &a, &op, &b);

 if(op == '+')
   printf("%d\n", a+b);

else if(op == '-')
   printf("%d\n", a-b);

else if(op == '*')
   printf("%d\n", a*b);

else if(op == '/')
   printf("%d\n", a/b);

else
  break;

}

return 0;

}

 

Measured memory_bytes: 600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    int n, a; cin >> n >> a;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        x[i] -= a;
    }
    sort(x.rbegin(), x.rend());
    vector<vector<ll>> dp(n + 1, vector<ll>(2505, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2505; j++) {
            dp[i + 1][j] += dp[i][j];
            if (j + x[i] >= 0 && j + x[i] < 2505) {
                dp[i + 1][j + x[i]] += dp[i][j];
            }
        }
    }
    cout << dp[n][0] - 1 << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ln '\n';
int lim=1e6;
int inf=1e9+7;
ll dp[3001][3001];
pair<int,int> nextdp[3001][3001];
ll solve(int i,int j,int n1,int n2,string &s1,string &s2){
	if(i==n1 or j==n2){
		return 0;
	}
	if(dp[i][j]!=-1){
		return dp[i][j];
	}
	else{
		ll a1=-1;
		if(s1[i]==s2[j]){
			a1=1+solve(i+1,j+1,n1,n2,s1,s2);
			nextdp[i][j]=make_pair(i+1,j+1);
			//final.push_back(s1[i]);
			dp[i][j]=a1;
			return a1;	
		}
		ll a2=solve(i+1,j,n1,n2,s1,s2);
		ll a3=solve(i,j+1,n1,n2,s1,s2);
		if(a2>a3){
			dp[i][j]=a2;
			nextdp[i][j]=make_pair(i+1,j);
		}else{
			dp[i][j]=a3;
			nextdp[i][j]=make_pair(i,j+1);
		}
		return dp[i][j];
	}
}
int main()
{	
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s,t;
	cin>>s>>t;
	int n1=s.size(),n2=t.size();
	for(int i=0;i<3001;i++){
		for(int j=0;j<3001;j++){
			dp[i][j]=-1;
			nextdp[i][j]=make_pair(-1,-1);	
		}
	}
	ll ans=solve(0,0,n1,n2,s,t);
	int i=0,j=0;
	string final="";
	while(true){
		if(i==n1 or j==n2){
			break;
		}
		if(s[i]==t[j]){
			final+=string(1,s[i]);
		}
		pair<int,int> p=nextdp[i][j];
		i=p.first;j=p.second;
	}
	cout<<final;
	cout<<ln;
}

Measured memory_bytes: 141568
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int A, B, Q;

int main() {
    while (cin >> A >> B >> Q) {
        vector<long long> s(A), t(B);
        for (int i = 0; i < A; ++i) cin >> s[i];
        for (int i = 0; i < B; ++i) cin >> t[i];
        sort(s.begin(), s.end());
        sort(t.begin(), t.end());

        for (int _ = 0; _ < Q; ++_) {
            long long x; cin >> x;

            long long res = 1LL<<60;

            // 先に s
            int it = lower_bound(s.begin(), s.end(), x) - s.begin();
            for (int i = max(0, it-2); i < min(A, it+2); ++i) {
                long long y = s[i]; 
                int it2 = lower_bound(t.begin(), t.end(), y) - t.begin();
                for (int j = max(0, it2-2); j < min(B, it2+2); ++j) {
                    chmin(res, abs(x - y) + abs(y - t[j]));
                }         
            }

            // 先に t
            it = lower_bound(t.begin(), t.end(), x) - t.begin();
            for (int i = max(0, it-2); i < min(B, it+2); ++i) {
                long long y = t[i]; 
                int it2 = lower_bound(s.begin(), s.end(), y) - s.begin();
                for (int j = max(0, it2-2); j < min(A, it2+2); ++j) {
                    chmin(res, abs(x - y) + abs(y - s[j]));
                }         
            }
            cout << res << endl;
        }
    }
}















Measured memory_bytes: 2944
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    X = I()

    ans = X ** 3
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10048
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
		int n;
		int count = 0;

		cin >> n;

		vector<int> d(n);

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

		sort(d.begin(), d.end());

		if ((n / 2) - 2 == (n / 2) - 1 || n / 2 == (n / 2) - 1)
		{
			cout << 0 << endl;
		}
		else
		{
			count = d[n / 2] - d[(n / 2) - 1];

			cout << count << endl;
		}

	return 0;
}

Measured memory_bytes: 640
d = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(d[int(input())-1])

Measured memory_bytes: 2940
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=2e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	ll h,ans=0;
	scanf("%lld",&h);
	ll i,a[60]={1};
	for(i=1;i<=59;i++)a[i]=a[i-1]*2;
	ll k=lower_bound(a+1,a+60,h)-a;
	if(a[k]!=h)k--;
	printf("%lld\n",a[k]*2-1);
}

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

int main() {
  int d,g,ans = 1e9+7;
  cin >> d >> g;
  vector<int>p(d),c(d);
  rep(i,0,d) cin >> p[i] >> c[i];
  for (int bit = 0; bit < (1<<d); ++bit){
    int sum = 0,cnt = 0;
    rep(i,0,d){
      if (bit&(1<<i)){
        sum += p[i]*(i+1)*100+c[i];
        cnt += p[i];
      }
    }
    if(sum < g){
      for(int i = d-1;i >= 0;i--){
        if(!(bit&(1<<i))){
          int t = (g-sum)/((i+1)*100);
          if((g-sum)%((i+1)*100) != 0) t++;
          if(t < p[i]){
            cnt += t;
            ans = min(ans,cnt);
          }
          break;
        }
      }
    }
    else ans = min(ans,cnt);
    //cout << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
n = gets.to_i
a = []
n.times{ a << gets.chomp.to_i}
colors = [a[0]]
 
a[1..-1].each do |x|
  i = colors.bsearch_index{|y| y >= x}
  if i.nil?
    colors[-1] = x
  elsif i == 0
    colors.unshift(x)
  else
    colors[i-1] = x
  end
end
 
puts colors.length

Measured memory_bytes: 3784
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    // ????????????????????¨??????????????????????????????????????????
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}

Measured memory_bytes: 4008
#include<stdio.h>

int main(int argc, char *argv[])
{
  int ret;
  int val;
  int yes = 0;
  ret = scanf("%d", &val);
  //printf("%d\n", val);
  if((val % 10) == 7){
    yes = 1;
  }
  val /= 10;
  if((val % 10) == 7){
    yes = 1;
  }
  val /= 10;
  if((val % 10) == 7){
    yes = 1;
  }
  if(yes){
	printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

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

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;


int main(void) {
    ll K,X;
    cin>>K>>X;
    if (X<=K*500) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;





   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> g(N);
    for (int i = 0; i < M; i++)
    {
        int A, B;
        cin >> A >> B;
        --A;
        --B;
        g[A].push_back(B);
        g[B].push_back(A);
    }
    vector<int> dist(N, -1);
    dist[0] = 0;
    queue<int> q;
    q.push(0);
    vector<int> ans(N, -1);
    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        for (int u : g[v])
        {
            if (dist[u] != -1)
            {
                continue;
            }
            dist[u] = dist[v] + 1;
            ans[u] = v;
            q.push(u);
        }
    }
    for (int i = 1; i < N; i++)
    {
        if (ans[i] == -1)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++)
    {
        cout << ans[i] + 1 << endl;
    }
}

Measured memory_bytes: 10744
def composite(d,n,s):
    for a in (2,3,5,7):
        p = False
        if pow(a,d,n) == 1:
            continue
        for i in range(s):
            if pow(a, 2**i * d, n) == n-1:
                p = True
                break
        if not p:
            return True
    return False
 
def is_prime(n):
    if n in (2,3,5,7):
        return True
    elif 0 in (n%2,n%3,n%5,n%7):
        return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return not composite(d,n,s)
r = []
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n):
    r.append(n)
 
print(len(r))

Measured memory_bytes: 7688
#include <bits/stdc++.h>
int main(){
    using namespace std;
    long long n,m;
    std::cin>>n>>m;

    long long ans =0LL;
    if(m/2<=n) ans = m/2;
    else {
        ans = n + (m-2*n)/4;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  ll A;
  double B;
  cin >> A >> B;
  ll ans = A * int(B * 100 + 0.1) / 100;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3744
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;


int sumDig(int num) {
	int sum = 0;
	while (num > 0) {
		sum += num % 10;
		num /= 10;
	}

	return sum;
}

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

	int ans = n;
	for (int a = 1;a < n;a++) {
		int b = n - a;

		ans = min(sumDig(a) + sumDig(b), ans);
	}

	cout << ans << endl;
}



Measured memory_bytes: 256
# coding: utf-8
# Your code here!

n = int(input())

ans = []

while n > 0:
    if n % 26 != 0:
        ans.append(chr(ord('a') + n % 26 - 1))
    else:
        ans.append('z')
        n -= 1
    n //= 26

print("".join(ans[::-1]))

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

int main() {
    string a, b, c;
    const char change = 'A'-'a';
    cin >> a >> b >> c;
    char d = ' ';

    if(a[0]>='a' && a[0]<='z') a[0] += change;
    if(b[0]>='a' && b[0]<='z') b[0] += change;
    if(c[0]>='a' && c[0]<='z') c[0] += change;

    cout << a[0] << b[0] << c[0] << endl;
    
    return 0;
}

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
bool Q;
struct Line {
    mutable ll k, m, p;
    bool operator<(const Line& o) const {
        return Q ? p < o.p : k < o.k;
    }
};
struct LineContainer : multiset<Line> {
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b){
        return a / b - ((a ^ b) < 0 && a % b);
    }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        Q = 1; auto l = *lower_bound({0,0,x}); Q = 0;
        return l.k * x + l.m;
    }
};
void solve(){
    ll n,c,x;
    cin>>n>>c;
    LineContainer lc;
    cin>>x;
    lc.add(2*x,-x*x);
    ll dp[n+1]={0};
    rep(i,2,n){
        cin>>x;
        dp[i]=-lc.query(x)+c+x*x;
        lc.add(2*x,-x*x-dp[i]);
    }
    cout<<dp[n];
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

int main(){
    int N;
    string S;
    cin >> N >> S;
    char c;
    vector <char> slimes;
    int ans;

    for(int i=0; i<N; i++){
        if(i==0){
            c=S[i];
            slimes.push_back(c);
        }else{
            if( c==S[i] ){
                continue;
            }else{
                c=S[i];
                slimes.push_back(c);
            }
        }
    }

    ans = (int) slimes.size();

    cout << ans << endl;

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll n, m, fac[100005];

int main()
{
	scanf("%lld%lld",&n,&m);
	if(n < m) swap(n, m);
	if(n - m > 1) {puts("0"); return 0;}
	fac[0] = 1;
	for(ll i=1;i<=n;i++) fac[i] = fac[i-1]*i%mod;
	if(n - m == 1) printf("%lld\n",fac[n]*fac[m]%mod);
	else printf("%lld\n",2*fac[n]*fac[m]%mod);
}


Measured memory_bytes: 1024
def main():
    N, A, B = [int(i) for i in input().split()]
    diff = B - A
    if diff % 2 == 0:
        ans = diff // 2
    else:
        ans = min(B - 1, N - A, (A - 1) + 1 + (diff - 1) // 2, (N - B) + 1 + (diff - 1) // 2)
    print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 5e5+10;

int main(){
fast;
int h1,h2,m1,m2;
ll k;
cin>>h1>>m1>>h2>>m2>>k;
int uptime = 60*h1 + m1;
int downtime = 60*h2 + m2;

cout<<max(0LL, downtime-uptime-k)<<endl;
return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define all(v)    ((v.begin()),(v.end()))
#define sz(v)     ((int)(v.size()))
#define forv(i, v) for(int i = 0; i < sz(v); ++i)
#define forn(i,n)   for(int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector< vi >    vii;
typedef vector< vd >    vdd;
typedef vector<string>  vs;


int main()
{
	fast;
	string a;
	cin >> a;
	if (a == "AAA" || a == "BBB") cout << "No\n";
	else cout << "Yes\n";

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, ans = 10e7, tmp = 0;
  scanf("%lld", &n);
  char s[n + 10];
  ll a[n + 1];
  for(i = 0; i < n; ++i) a[i] = 0;
  scanf("%s", s);
  for(i = 0; i < n; ++i) {
    if(s[i] == 'W') a[i + 1]++;
    else a[0]++, a[i]--;
  }
  for(i = 0; i < n; ++i) {
    tmp += a[i];
    if(ans > tmp) ans = tmp;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int prime[MAX];
bool isprime[MAX];

int sieve(int n){
    int p = 0;
    for(int i=0; i<=n; i++) isprime[i] = true;
    isprime[0] = isprime[1] = false;
    for(int i=2; i<=n; i++){
        if(isprime[i]){
            prime[p++] = i;
            for(int j=2*i; j<=n; j+=i) isprime[j] = false;
        }
    }
    return p;
}

int main(){
    sieve(303030);
    while(1){
        ll n,p; cin >> n >> p;
        if(n==-1 && p==-1) break;
        vl v;
        ll cnt = p;
        for(ll i=n+1;; i++){
            if(isprime[i]){
                v.push_back(i);
                cnt--;
            }
            if(!cnt) break;
        }
        vl sum;
        rep(i,v.size()){
            REP(j,i,v.size()){
                sum.push_back(v[i]+v[j]);
            }
        }
        sort(all(sum));
        cout << sum[p-1] << endl;
    }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long
#define rep(i,N) for(int i = 0; i < N; i++)
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 ll INF = 1LL << 60;
int main() {
  int N;
  cin >> N;
  ll h[100010];
  rep(i,N) cin >> h[i];
  ll dp[100010];
  rep(i,100010) dp[i] = INF;
  dp[0] = 0;
  for (int i = 1; i < N; i++) {
    chmin (dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if (i > 1) chmin (dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define boost() ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cout << fixed; cout << setprecision(15); srand(time(NULL))
#define all(x) x.begin(), x.end()
using namespace std;

vector <string> s;
int n;

signed main () {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string cur;
    cin >> cur;
    sort(all(cur));
    s.push_back(cur);
  }
  sort(all(s));
  int res = 0;
  int i = 0, j = 0;
  while (i < n && j < n) {
    while (j < n && s[i] == s[j]) j++;
    int x = j - i;
    res += (x * (x - 1)) / 2;
    i = j;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 100005;

ll two[33], a[MAX_N];
bool ok[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll res = 0;
    rep(i,n){
        cin >> a[i];
        res ^= a[i];
    }
    int id = 0;
    two[id] = 1;
    while(res){
        two[id+1] = two[id] * 2;
        res /= 2;
        id++;
    }
    int sm = 0;
    rep(i,id){
        ll cri = 0;
        rep(j,n){
            cri ^= a[j];
        }
        if(cri>>(id-i-1)&1LL){
            bool flag = false;
            rep(j,n){
                if(!ok[j] && a[j] % two[id-1-i] == 0 && (a[j]>>(id-i-1)&1LL)){
                    flag = true;
                    ok[j] = true;
                    a[j]--;
                    sm++;
                    break;
                }
            }
            if(!flag){
                cout << "-1\n";
                return 0;
            }
        }
    }
    cout << sm << "\n";
    return 0;
}


Measured memory_bytes: 1024
def g(A,l,m,r):
 global c
 L,R=A[l:m]+[1e9],A[m:r]+[1e9]
 i=j=0
 for k in range(l,r):
  if L[i]<R[j]:A[k]=L[i];i+=1
  else:A[k]=R[j];j+=1
  c+=1
def s(A,l,r):
 if l+1<r:
  m=(l+r)//2
  s(A,l,m);s(A,m,r)
  g(A,l,m,r)
c=0
n=int(input())
A=list(map(int,input().split()))
s(A,0,n)
print(*A)
print(c)


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

int main(){
  int N;
  int count=0;
  cin>>N;
  vector<int>taco(N);
  for(int i=0;i<N;i++){
    cin>>taco[i];
  }
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      count=taco[i]*taco[j]+count;
    }
  }
  cout<<count;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

vector<long long> num;
long long Q[int(1e7)];
int l=1,r=0;
inline void prepare() {
	for(register int i=1;i<10;i++)
		Q[++r]=i;
	while(r>l) {
		long long cur=Q[l++];
		if(cur>1e11) return;
		num.push_back(cur);
		int back=cur%10;
		
		Q[++r]=cur*10ll+back;
		if(back!=0) Q[++r]=cur*10ll+back-1;
		if(back!=9) Q[++r]=cur*10ll+back+1;
	}
}

signed main() {
	prepare();
	int k;
	cin>>k;
	sort(num.begin(),num.end()) ;
	cout<<num[k-1]<<endl;
}

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

long long solve1(long long i,long long j,long long dp[][3001],long long a[])
{
    if(i>j)
    return 0;
    if(dp[i][j]!=-1)
    return dp[i][j];
    long long op1=a[i]+min(solve1(i+2,j,dp,a),solve1(i+1,j-1,dp,a));
    long long op2=a[j]+min(solve1(i+1,j-1,dp,a),solve1(i,j-2,dp,a));
    return dp[i][j]=max(op1,op2);
}

int main() {
    long long n;
    cin>>n;
    long long a[n];
    long long sum=0;
    for(long long i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    long long dp[3001][3001];
    memset(dp,-1,sizeof(dp));
    long long X=solve1(0,n-1,dp,a);
     long long Y=sum-X;
    cout<<X-Y;
    return 0;
}


Measured memory_bytes: 74096
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;


int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  
  rep(i,n){
    cin >> l[i];
  }
  
  sort(l.begin(),l.end());
  
  int other = 0;
  rep(i,n-1) other += l[i];
  
  if (l[n-1] < other) cout << "Yes";
  else cout << "No";
  
  return 0;
}

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


typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;


void initialize(){
    head = tail = 0;
}

int isEmpty() {
    return head==tail;
}

int isFull() {
    return head == (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}


int main(void){
    // Your code here!
    int n, q;
    scanf("%d %d", &n, &q);
    for(int i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    
    initialize();
    head = 1;
    tail = n + 1;
    
    int t;
    int now = 0;
    while(head != tail){
        P x = dequeue();
        t = x.t;
        if(t <= q) {
            now += t;
            printf("%s %d\n", x.name, now);
        } else {
            now += q;
            x.t -= q;
            enqueue(x);
        }
    }
}



Measured memory_bytes: 21020
import java.math.BigInteger;
import java.util.Scanner;
import java.util.Vector;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();

		int[] ans = new int[N];

		int A = 0;

		for(int index = 0; index < N; index++) {
			ans[scanner.nextInt() - 1] = index + 1;
		}

		for(int index = 0; index < N; index++) {
			log(ans[index]);
		}

//		long A = scanner.nextLong();
//
//		long B = scanner.nextLong();
//
//		Vector<Integer> kouyakusuu = new Vector<>();
//		Vector<Integer> kouyakusuuB = new Vector<>();
//
//		int ans = 0;
//
//		for(int index = 1; index < A / 2; index++) {
//			if(A % index == 0) {
//				// 公約数
//				kouyakusuu.add(index);
//			}
//		}
//
//		for (int index = 0; index < kouyakusuu.size(); index++) {
//			if(B % kouyakusuu.get(index) == 0) {
//				kouyakusuuB.add(kouyakusuu.get(index));
//			}
//		}
//
//		for (int index = 0; index < kouyakusuuB.size(); index++) {
//			if(isPrimeNumber( kouyakusuuB.get(index))) {
//				ans++;
//			}
//		}
//
//		log(ans);

	}

	private static boolean isPrimeNumber( long num ){
		// 1以下は素数ではない
		if ( 1 >= num ) return true;

		// 2の場合は素数
		if ( 2 == num ) return true;

		// 素数判定
		long n = (long)Math.sqrt( num );
		for ( long i = 2; i <= n; ++ i ) {
			// 余り0で割り切れるかを判定
			if ( 0 == ( num % i ) ) return false;
		}

		// numが2～nで割り切れなかったので素数
		return true;
	}

	private static void dfs(int[] treeArray,int parrent, int children) {
		Vector<Vector> aa = new Vector<>();
		Vector<Integer> bb = new Vector<>();
		bb.add(1);
		aa.add(bb);
	}


	/**
	 * バブルソートの交換数を算出
	 * ※転倒数
	 * @param array
	 * @return
	 */
	private static long countSwapBabbleSort(int[] array, int N) {
		long ans = 0;
		int[] binary = new int[N + 1];

		for (int index = 0; index < array.length; index++) {
			ans = ans + (index - sum(binary, array[index]));
			add(binary, array[index], 1);
		}
		return ans;
	}

    //add value at idx on bit O(logN)
	private static void add(int[] bit,int idx,int value) {
        for(int i=idx;i<bit.length;i=i+(i&-i)) {
        	bit[i] += value;
        }
    }

    //return sum [1,idx] O(logN)
	private static long sum(int[] bit,int idx) {
        long ret = 0;
        for(int i=idx;i>0;i-=(i&-i)) {
        	ret += bit[i];
        }
        return ret;
    }

	private static void log(String str) {
		System.out.println(str);
	}

	private static void log(int str) {
		System.out.println(str);
	}

	private static void log(long str) {
		System.out.println(str);
	}

	private static void log(double str) {
		System.out.println(str);
	}

	private static void log(BigInteger str) {
		System.out.println(str);
	}

}



Measured memory_bytes: 56836
n,k,q=map(int,input().split())
a=[int(input()) for i in range(q)]
ans = []
def calc(n):
    return n-q
for i in range(n):
  ans.append(k)
ans = list(map(calc, ans))
for i in range(q):
  ans[a[i]-1]+= 1
for i in range(n):
  if ans[i] <= 0:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 17656
using System;
using System.Linq;

namespace abc090_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = 0;
            for (int i = x[0]; i <= x[1]; i++)
            {
                string s = i.ToString();
                if (s[0] == s[4] && s[1] == s[3]) ret++;
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 15444
// 575に並び替えられるかどうか
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val nums = inputs.head.split(" ").map(_.toInt)

  println(solve(nums))

  def solve(nums: Array[Int]): String = {
    val fiveCount = nums.filter(_ == 5).size
    val sevenCount = nums.filter(_ == 7).size

    if(fiveCount == 2 && sevenCount == 1) {
      "YES"
    } else {
      "NO"
    }
  }

}

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

const int N = 1e3 + 10;

int n, k;
int ar[N];

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

    cin >> n >> k;
    for (int i=1;i<=n;i++){
        cin >> ar[i];
    }
    sort(ar + 1, ar + n + 1);
    int tot = 0;
    for (int i=1;i<=k;i++) tot += ar[i];
    cout << tot << el;

    return 0;
}

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

int main() {
  long n;
  cin >> n;
  
  long ans;
  
  long m = sqrt(n)/1;
  
  for(long i=m; i>0; i--){
    if(n%i==0){
      long j = n/i;
      ans = i + j - 2;
      cout << ans << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3652
mod = pow(10, 9) + 7

def main():
    N, K = map(int, input().split())
    ans = 0
    for k in range(K, N+2):
        #ans += sum(range(N+1-k, N+1)) - sum(range(0, k)) + 1
        ans += (N*(N+1))//2 - ((N-k)*(N-k+1))//2 - ((k-1)*k)//2 + 1
        ans %= mod
    print(ans%mod)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9188
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
        int S = 0,h = 0,m = 0,s = 0;
    cin >> S;
    h = S/3600;
    m = (S-h*3600)/60;
    s = S-h*3600-m*60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


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

const int maxn=1e6+7;
#define ll long long
ll a[maxn];
ll k;

ll vis[maxn];

map<ll,ll>mp;

int main (){
	ll n;cin>>n>>k;k++;
	for(ll i=1;i<=n;i++) cin>>a[i];
	ll cnt=1;
	vis[1]=1;
	mp[1]=1;
	for(ll i=1;;){
        if(vis[a[i]]) {
            if(k<=vis[a[i]]-1) cout<<mp[k]<<endl;
            else {
				ll ret=vis[a[i]]-1;
				k-=ret;
				ll len=cnt-vis[a[i]]+1;
				k%=len;
				if(k==0) k+=len;
				k+=ret;
				cout<<mp[k]<<endl;
            }
            break;
        }
		else vis[a[i]]=++cnt,mp[cnt]=a[i],i=a[i];
	}
	return 0;
}


Measured memory_bytes: 18896
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<numeric>

int main(){
	int N, X;
	int cnt=1;
	int pos=0;

	std::cin >> N >> X;

	for(int i=0;i<N;i++){
		int _L;
		std::cin >> _L;

		pos+=_L;
		if(pos<=X){
			cnt++;
		}
	}

	std::cout << cnt << std::endl;

	return 0;
}


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

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

    int p;
    vector<pair<int, int>> ans(102);
    for (int i = 0; i < 102; i++)
    {
        ans[i].first = i;
        ans[i].second = 0;
    }

    for (int i = 0; i < n; i++)
    {
        cin >> p;
        ans[p].second = 1;
    }

    int res = INT_MAX;
    int tmp;
    for (int i = 0; i < 102; i++)
    {
        if (ans[i].second == 1)
            continue;

        if (res > abs(x - ans[i].first))
        {
            res = abs(x - ans[i].first);
            tmp = ans[i].first;
        }
    }

    cout << tmp << endl;
}

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

typedef long long ll;

#define F first 
#define S second 
#define PB push_back
#define MP make_pair 
#define rep(i,a,b) for (ll i=a;i<b;i++)

typedef vector<int> vi;
typedef pair<int,int> pi;

bool isPrime(ll n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}

int main()
{
    ll a;
    cin>>a;

    ll i=a; 
    while(i<LONG_MAX) {
        if(isPrime(i)) {
            cout<<i<<endl;
            return 0;
        }
        i++;
    }

    return 0; 
}



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

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

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let n: usize = read();
    let p: Vec<i64> = read_n(n);
    let mut ans = 0;

    let mut prev_min = std::i64::MAX;
    for (i, v) in p.iter().enumerate() {
        if *v < prev_min {
            prev_min = *v;
            ans += 1;
        }
    }

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


Measured memory_bytes: 59516
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{

        

        // for dfs
        static int n;
        static int ansi;
        static int[] w;
        static int[] ww;
        static boolean[] isvisited;
        //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
            
        String s = sc.next();
        int cnt = 0;
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'A' || 
            s.charAt(i) == 'T' ||
            s.charAt(i) == 'G' ||
            s.charAt(i) == 'C' ) {
                cnt++;
            } else {
                ans = Math.max(ans, cnt);
                cnt = 0;
            }
        }

        ans = Math.max(ans, cnt);
        System.out.println(ans);

        sc.close();
    }


        public static int gcd_int(int a, int b) {
        
            if (a < b) {
                int tmpp = a;
                a = b;
                b = tmpp;
            }
            if (b == 0) {
                return a;
            }else{
                return gcd_int(b, a%b);
            }
        } 

        public static long gcd_long(long a, long b) {
        
            if (a < b) {
                long tmpp = a;
                a = b;
                b = tmpp;
            }
            if (b == 0) {
                return a;
            }else{
                return gcd_long(b, a%b);
            }
        }

        public static int lcm_int(int a, int b) {
            int gcd = gcd_int(a,b);
            return a/gcd*b;
        }

        public static long lcm_long(long a, long b) {
            long gcd = gcd_long(a,b);
            return a/gcd*b;
        }

        public static void dfs(int placenow) {
            // if went all -> success! 
            // if not went all -> fail...
            
            /*
            dfs    
            Go All Place that there is way to and not having been yet. 

             if island 1 is start point, dfs(1);
            if there is way to island 2 and island 3,
            - island 2 changes non-visited -> visited, and dfs(2).
            - island 3 changes non-visited -> visited, and dfs(3).
    
            */

            isvisited[placenow] = true;
            boolean success = true;
            for (int i = 0; i < n; i++) {
                if (isvisited[i] == false) { // not go all place
                    success = false;
                    break;
                }
            }
            if (success) {
                ansi++;
                isvisited[placenow] = false;
                return;
            }

            for (int i = 0; i < n; i++) {
                if (w[i] == placenow && isvisited[ww[i]] == false ) {
                    dfs(ww[i]);
                }else if(ww[i] == placenow && isvisited[w[i]] == false){
                    dfs(w[i]);
                }else{
                    continue;
                }
            }
            isvisited[placenow] = false;
            return;
        }

}



Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(false); std::cin.tie(NULL);
using namespace std;
 
int main(){
  IO_OP;
  int x[6];
  for(int i=1;i<6;i++){
    cin>>x[i];
  }
  for(int i=1;i<6;i++){
    if(x[i]==0){
      cout<<i<<"\n";
      return 0;
    }
  }
}

Measured memory_bytes: 3652
N = int(input())
P = [int(input())-1 for i in range(N)]

idx = [-1 for _ in range(N)]
successive = [False for _ in range(N)]

for i in range(N):
    idx[P[i]] = i

for p in P:
    if p < N-1 and idx[p+1] > idx[p]:
        successive[p] = True

cnt = 1
max_cnt = 0
for p in range(N):
    if successive[p]:
        cnt += 1
    else:
        max_cnt = max(cnt, max_cnt)
        cnt = 1

print(N-max_cnt)

Measured memory_bytes: 20524
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod) - 1 
mod_inv = [0, 1] + [0] * (b+3)
for i in range(2, b+5):
    mod_inv[i] = - mod_inv[mod % i] * (mod // i) % mod
def comod(n, r, mod):
    ans = 1
    for i in range(r):
        ans *= (n-i) % mod
        ans *= mod_inv[i+1]
        ans %= mod
    return ans
ans -= comod(n,a,mod) + comod(n,b,mod)
print(ans % mod)


Measured memory_bytes: 12888