akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

#define INF (1<<30)

struct node{
	int ID,cost;
	struct node *next;
};
typedef struct node* nP;

nP List[10000],NIL;
int n,size;
struct node minHeap[500050],empty;

//{{{ Functions
void MinHeapify(int pos){
	int L=pos*2, R=pos*2 +1,min=pos;
	struct node tmp;

	if(L<=size && minHeap[L].cost<minHeap[pos].cost){
		min=L;
	}
	if(R<=size && minHeap[min].cost>minHeap[R].cost){
		min=R;
	}

	if(min!=pos){
		//swap
		tmp=minHeap[pos];
		minHeap[pos]=minHeap[min];
		minHeap[min]=tmp;

		MinHeapify(min);
	}

	return;
}

void Push(int id, int c){
	int pos;
	struct node data,tmp;
	data.ID=id;	data.cost=c;

	minHeap[++size]=data;
	pos=size;

	while(pos/2>0 && minHeap[pos].cost<minHeap[pos/2].cost){
		// swap
		tmp=minHeap[pos];
		minHeap[pos]=minHeap[pos/2];
		minHeap[pos/2]=tmp;

		pos/=2;
	}

	return;
}

struct node Pop(void){
	if(size==0)return *NIL;
	struct node ret=minHeap[1];
	minHeap[1]=minHeap[size];	--size;
	MinHeapify(1);

	return ret;
}
//{{{
void Insert(nP head, int v, int c){
	nP data=(nP)malloc(sizeof(struct node));
	data->ID=v;	data->cost=c;

	data->next=head->next;
	head->next=data;

	return;
}
//}}}

void Dijkstra(void){
	int i,minCost;
	struct node u;
	nP v;
	int c[10000],visited[10000];

	for(i=0;i<n;i++){
		c[i]=INF;	visited[i]=0;
	}
	c[0]=0;
	Push(0,0);

	while(1){
		u=Pop();	if(u.ID==-1)break;
		if(c[u.ID]<u.cost)continue;
		visited[u.ID]=1;

		//printf("%d: ",u.ID);
		for(v=List[u.ID]->next; v!=NIL; v=v->next){
			//printf("%d->",v->ID);
			if(visited[v->ID]==1)continue;

			if(c[v->ID]>c[u.ID]+v->cost){
				c[v->ID]=c[u.ID]+v->cost;
				Push(v->ID, c[v->ID]);
			}
		}
		//printf("\n");
	}

	for(i=0;i<n;i++)printf("%d %d\n",i,c[i]);
}

//}}}
int main(){
	int i,j,u,k,v,c;
	scanf("%d",&n);

	NIL=(nP)malloc(sizeof(struct node));
	NIL->ID=-1;
	for(i=0;i<n;i++){
		List[i]=(nP)malloc(sizeof(struct node));
		List[i]->next=NIL;
	}

	for(i=0;i<n;i++){
		scanf("%d%d",&u,&k);
		for(j=0;j<k;j++){
			scanf("%d%d",&v,&c);
			Insert(List[u],v,c);
		}
	}

	Dijkstra();

	return 0;
}



Measured memory_bytes: 17452
def count(num):    
    l1=[]
    for a in range (10):
        for b in range(10):
            for c in range (10):
                for d in range (10):
                    l1.append([a,b,c,d])
    l1=list(filter(lambda x: sum(x)==num,l1))
    return(len(l1))

while True:
    try:
        print(count(int(input())))
    except:
        break
    

Measured memory_bytes: 8916
#include<bits/stdc++.h>
#include<bitset>
using namespace std;
using ll =long long;

struct DSU{
    DSU(int n):parent(vector<int>(n+1)),rank(vector<int>(n+1)), size(vector<int>(n+1)){
        for(int i = 0;i<=n;++i){
            parent[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
        size[0] = 0;
        num_groups = n;
        max_group_size = 1;
    }
    int max_gs (){return max_group_size;}
    int num_gs (){return num_groups;}
    void union_set(int u, int v){
        auto r1 = find_root(u);
        auto r2 = find_root(v);
        // cout<<"u , v, r1, r2: "<<u<<' '<<v<<' '<<r1<<' '<<r2<<endl;
        if(r1!=r2)
            link_roots(r1, r2);
    }
    int find_root(int i){
       return parent[i] == i?i:(parent[i] = find_root(parent[i])); 
    }
    void link_roots(int r1, int r2){
        max_group_size = max(max_group_size, size[r1] + size[r2]);
        if(rank[r1] < rank[r2]){
            parent[r1] = r2;
            size[r2] += size[r1];
        }
        else if(rank[r1] > rank[r2]){
            parent[r2] = r1;
            size[r1] += size[r2];
        }
        else{
            parent[r1] = r2;
            rank[r2] ++;
            size[r2] += size[r1];
        }
        num_groups--;
    }
    void print_parent(){
        for(int i = 1;i<=parent.size();++i)
            cout<<i <<" --> "<<parent[i]<<endl;
    }
    void print_size(){
        for(int i = 1;i<=parent.size();++i)
            cout<<i <<" <--> "<<size[i]<<endl;
    }
    void print_rank(){
        for(int i = 1;i<=parent.size();++i)
            cout<<i <<" <--> "<<rank[i]<<endl;
    }
private: 
    vector<int>  parent, rank, size;
    int max_group_size;
    int num_groups;
};

int main(){
    int N,M;
    cin>>N>>M;
    DSU ds(N);
    while(M--){
        int a,b;
        cin>>a>>b;
        ds.union_set(a,b);
    }
    cout<<ds.max_gs()<<endl;
    /*ds.print_rank();
    ds.print_size();
    ds.print_parent();*/
}

Measured memory_bytes: 5612
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int a, b, k;

int main(){
    INIT;
    cin >> a >> b >> k;
    for(int i = min(a, b);i >= 1;i--){
        if(a % i == 0 && b % i == 0){
            k--;
        }
        if(k == 0){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, x, a, b);
    if (abs(x - a) < abs(x - b)) {
        print("A");
    } else
        print("B");

    return 0;
}


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

#define EPS 0.0002

struct Point{double x,y,z;};
double getDistance(Point p1,Point p2)
{
  return sqrt(pow(p1.x-p2.x,2.0)+pow(p1.y-p2.y,2.0)+pow(p1.z-p2.z,2.0));
}

int main()
{
  int n,m,P,Q,R;
  double original[3],x,y,z;
  int i,j,k,t;
  cin>>n;
  while(n-->0){
    for(i=0;i<3;i++)cin>>original[i];

    cin>>m;
    vector<Point>v(m);
    for(i=0;i<m;i++){
      cin>>x>>y>>z;
      Point p={x,y,z};
      v[i]=p;
    }

    P=0;
    for(i=0;i<m;i++){
      for(j=0;j<m;j++){
	if(i==j)continue;
	for(k=0;k<m;k++){
	  if(i==k||j==k)continue;
	  double d[3]={getDistance(v[j],v[k]),getDistance(v[k],v[i]),getDistance(v[i],v[j])};
	  bool ok=true;
	  for(t=0;t<3;t++){
	    if(original[t]/original[(t+1)%3]-d[t]/d[(t+1)%3]>EPS)ok=false;
	  }
	  if(ok){
	    P=i+1;
	    Q=j+1;
	    R=k+1;
	  }
	  if(P)break;
	}
	if(P)break;
      }
      if(P)break;
    }

    cout<<P<<" "<<Q<<" "<<R<<endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>  
#include<cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include<map>
#include<algorithm>
#include<functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include<deque>
#include<climits>
#include<typeinfo>
#include<utility>
#define LEN 100005
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpc[10000][10000];

//void nCr(ll n, ll r) {
//	ll ans = 1;
//	for (int i = n; i > n - r; --i) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; ++i) {
//		ans = ans / i;
//	}
//	printf("%d",ans);
//}

ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else { return dpc[n][r] = combination(n - 1, r - 1) + combination(n - 1, r); }
}

//cout << fixed << setprecision(10);


int main() {

	int S, W;
	cin >> S >> W;
	if (W >= S)cout << "unsafe" << endl;
	else cout << "safe" << endl;

	return 0;
}

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

ll a[200000];
ll s[200010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

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

	map<ll, ll> m;
	for(int i = 0; i < N; i++){
		m[s[i + 1]]++;
	}

	ll ans = 0;
	for(int i = 0; i < N; i++){
		ans += m[s[i]];
		m[s[i + 1]]--;
	}
	cout << ans << endl;
}


Measured memory_bytes: 15872
#include <stdio.h>
#include <stdlib.h>

// useage : swap(&int1,&int2);
// 値入れ替え
int swap(int *c1,int *c2){
  int tmp;
  tmp=*c1;
  *c1=*c2;
  *c2=tmp;
  return 0;
}

int main(void) {
 
  int n;
  scanf("%d",&n);
  int k;
  scanf("%d",&k);
  int tmp,cnt=0;
  for(int i=0;i<n;i++){
    scanf("%d",&tmp);
    if(tmp>=k)cnt+=1;
  }
  
  printf("%d\n",cnt);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const ll mod = 1000000007;
using namespace std;
 
int N,K;
int cnt[maxn];
ll f[111][maxn],pre[maxn];
 
ll solve(){
    for(int i = 0;i<=K;i++) f[1][i] = (i<=cnt[1])? 1:0;
    for(int i = 2;i<=N;i++){ // child
        memset(pre,0,sizeof pre);
        pre[0] = f[i-1][0];
        for(int j = 1;j<=K;j++) pre[j] = (f[i-1][j] + pre[j-1]);
        for(int j = K;j>=0;j--){ //want to use
            if(j-cnt[i]>= 0) f[i][j] = pre[j] - pre[j-cnt[i]-1];
            else f[i][j]  =  pre[j];
            f[i][j] %= mod;
        }
    }
    return f[N][K];
}
 
int main(){
    // debug;
    ios;
 
    cin>>N>>K;
    for(int i = 1;i<=N;i++) cin>>cnt[i];
    cout<<solve()<<'\n';
 
 
    return 0;
}

Measured memory_bytes: 295168
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
#define ll long long
#define ull unsigned ll
const int N=100005;
int n, m, col[N];
vector<int> g[N];
int cnt[2];
void dfs(int u, int c) {
	col[u]=c;
	cnt[c]++;
	for(int i=0; i<g[u].size(); i++) {
		int v=g[u][i];
		if(col[v]<0) dfs(v, !c);
		if(col[v]>=0&&col[v]!=!c) {
			printf("%lld\n", 1ll*n*(n-1)/2-m);
			exit(0);
		}
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i=0; i<m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	cnt[0]=0, cnt[1]=0;
	memset(col, -1, sizeof(col));
	dfs(0, 0);
	printf("%lld\n", 1ll*cnt[0]*cnt[1]-m);
	return 0;
}

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

const int MOD = (int)1e9+7;

int main(){
  int N;
  long long K;
  cin >> N >> K;
  vector<long long> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);
 
  vector<int> k(50);
  int cnt=0;
  while(K>0){
    if(K%2==1)  k.at(cnt)++;
    K/=2;
    cnt++;
  }
  cnt--;
  
  vector<int> bitA(50);
  for(int i=0;i<N;i++){
    long long x=A.at(i);
    int count=0;
    while(x>0){
      if(x%2==1)  bitA.at(count)++;
      x/=2;
      count++;
    }
  }
 
  long long ans=0;
  for(int j=cnt;j>=-1;j--){
    vector<int> y(50);
    if(j>=0 && k.at(j)==0)  continue;
    for(int s=0;s<50;s++){
      if(j==s) y.at(s)=0;
      else if(j<s)  y.at(s)=k.at(s);
      else if(j>s)  y.at(s)=-1;
    }
 
    long long ansx=0;
    long long count2=1;
    for(int i=0;i<50;i++){
      long long mx;
      if(y.at(i)==0) mx=bitA.at(i);
      else if(y.at(i)==1) mx=N-bitA.at(i);
      else if(y.at(i)==-1)  mx=max(bitA.at(i),N-bitA.at(i));
      ansx+=count2*mx;
      count2*=2;
    }
    ans=max(ans,ansx);
  }
 
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1276
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

namespace Contest
{
    class Program
    {
        public void Solve()
        {
            var sc = new Scanner();

            int[] arr = new int[5];
            for (int i = 0; i < 5; i++)
            {
                arr[i] = sc.NextInt();
            }
            Array.Sort(arr, f);

            int ans = 0;

            for (int i = 0; i < 4; i++)
            {
                ans += T(arr[i]);
            }

            ans += arr[4];
            Console.WriteLine(ans);
        }

        private int f(int a, int b)
        {
            if (a % 10 == b % 10) return 0;
            if (a % 10 == 0) return -1;
            if (b % 10 == 0) return 1;
            return -(a % 10).CompareTo(b % 10);

        }

        private int T(int i)
        {
            if (i % 10 == 0) return i;
            else return i + 10 - i % 10;
        }


        static void Main(string[] args) => new Program().Solve();
    }

    class Scanner
    {
        private char _separator = ' ';
        private StreamReader _stream = new StreamReader(Console.OpenStandardInput());
        private int _pos = 0;
        private string[] _line = new string[0];
        public string Next()
        {
            if (_pos >= _line.Length)
            {
                _line = _stream.ReadLine().Split(_separator);
                _pos = 0;
            }
            return _line[_pos++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public string[] Array()
        {
            if (_pos >= _line.Length)
                _line = _stream.ReadLine().Split(_separator);
            _pos = _line.Length;
            return _line;
        }
        public int[] IntArray()
        {
            var arr = Array();
            var res = new int[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = int.Parse(arr[i]);
            }
            return res;
        }
        public long[] LongArray()
        {
            var arr = Array();
            var res = new long[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = long.Parse(arr[i]);
            }
            return res;
        }
        public double[] DoubleArray()
        {
            var arr = Array();
            var res = new double[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = double.Parse(arr[i]);
            }
            return res;
        }
    }
}


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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*alias*/
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -fsanitize=signed-integer-overflow -fno-sanitize-recover=all -o template template.cpp


signed main()
{
	int a,b,c;cin >> a >> b >> c;
	int ab = a-b;if(ab < 0)ab = -ab;
	int ac = a-c;if(ac < 0)ac = -ac;

	if(a <= b && b < c){
		if(ab < ac){
			cout << "No" << endl;
		}
	}
	else if(c < b && b <= a){
		if(ab < ac){
			cout << "No" << endl;
		}
	}
	else if(c < a && a <= b){
		cout << "No" << endl;
	}
	else if(b <= a && a < c){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
	

	return 0;
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define FF first
#define SS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

int n, T, L;
int a[MAXN];
LL dp[MAXN];
PLI q[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d%d%d", &n, &L, &T );
	lpi ( i, 1, n ) scanf ( "%d", &a[i] );
}

void work ()
{
	// main work
	
	dp[0] = 0;
	int l = 1, r = 0;
	int nl = 0;
	LL vl = LINF;
	q[++r] = MP ( dp[0], 0 );
	lpi ( i, 1, n ){
		while ( ( ( a[i] - a[nl+1] ) << 1 ) > T ){
			vl = min ( vl, dp[nl] - ( a[nl+1] << 1 ) );
			++nl;
		}
		while ( l <= r && ( ( a[i] - a[q[l].SS+1] ) << 1 ) > T ) ++l;
		dp[i] = min ( vl + ( a[i] << 1 ), ( l <= r ) ? ( q[l].FF + T ) : LINF );
		while ( l <= r && ( q[r].FF >= dp[i] ) ) --r;
		q[++r] = MP ( dp[i], i );
	}
	
//	lpi ( i, 1, n ) cerr << dp[i] << " "; cerr << endl;
	
	cout << dp[n] + L << endl;
}

Measured memory_bytes: 2944
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n ;
    cin >> n ;
    vector<int> ans(n + 1, 2) ;
    ans[1] = 1 ;
    for(int i = 2; i <= n; i++){
        for(int j = i + i; j <= n; j += i){
            ans[j]++ ;
        }
    }
    int answer = 0 ;
    for(int i = 1; i < n + 1; i++){
        answer += i * ans[i] ;
    }
    cout << answer << endl;
    return 0; 
}

Measured memory_bytes: 81340
fn string_cut(mut num: usize, s:String) -> String{
    let mut add = 0;
    if s.len() <= num {
        num = s.len();
    }else {
        add = 1;
    }
    
    let mut output = String::new();
    let str_list = &s.chars().collect::<Vec<char>>();
    
    for i in 0..num{
        output += &str_list[i].to_string();
    }
    if add == 1{
        output += &"...".to_string();
        output
    }else {
        output
    }
}

fn read<T:std::str::FromStr>() -> T{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main(){
    let num:usize = read();
    let input:String = read();
    let s = string_cut(num, input);
    println!("{}", s);
}

Measured memory_bytes: 2116
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  int k[N];
  int s[M][N+1];
  for(int i=0;i<M;i++){
    cin >> k[i];
    for(int j=0;j<k[i];j++){
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  int p[M];
  for(int i=0;i<M;i++) cin >> p[i];

  int ans = 0;
  //bit全探索
  //cout << "start" << endl;
  for(int i=0; i<(1 << N); i++){
    //cout << (1 << N) << endl;
    bool use[N];
    int tmp = i;
    for(int j=0;j<N;j++){
      if(tmp % 2 == 0) use[j] = false;
      else use[j] = true;
      tmp /= 2;
    }
    //for(int j=0;j<N;j++) cout << use[j] << " ";
    //cout << endl;

    bool allok = true;
    for(int j=0;j<M;j++){
      int cnt = 0;
      for(int m=0;m<k[j];m++){
        if(use[s[j][m]]) cnt++;
      }
      if((cnt % 2) != p[j]){
        allok = false;
        break;
      }
    }

    if(allok) ans++;
  }

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


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

int m,t,p,r,a[50][10];
pair<pair<int,int>,int> b[50];

int main(){
	while(cin>>m>>t>>p>>r,m||t||p||r){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		rep(i,r){
			int M,T,P,R;cin>>M>>T>>P>>R;T--;P--;
			if(R) a[T][P]++;
			else b[T].first.first--,b[T].first.second+=a[T][P]*20+M;
		}
		rep(i,t)b[i].second-=i+1;
		sort(b,b+t);
		rep(i,t){
			if(i) cout<<(b[i].first==b[i-1].first?'=':',');
			cout<<-b[i].second;
		}
		cout<<endl;
	}
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/04  Problem: ABC 042 B / Link: http://abc042.contest.atcoder.jp/tasks/abc042_b  ----- */


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

	LL N, L; cin >> N >> L;
	vector<string> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	sort(ALL(a), [](const string&L,const string &R) {
		return L + R < R + L;
	});
	for (auto it : a) {
		cout << it;
	}cout << endl;

	return 0;
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(string, "s", long, "p");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto d = aryread.sort.array();
    auto m = lread();
    auto t = aryread.sort.array();
    long d_iter, t_iter;
    while(t_iter < m)
    {
        if(d_iter >= n)
        {
            writeln("NO");
            return;
        }
        
        if(t[t_iter] == d[d_iter])
        {
            t_iter++, d_iter++;
        }
        else if(t[t_iter] < d[d_iter])
        {
            writeln("NO");
            return;
        }
        else
        {
            d_iter++;
        }
    }
    writeln("YES");
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

int main() {
    int n;
    string ss;
    cin >> n >> ss;
    int ans = 1;
    char s_before = ss[0];
    for (int i=0; i<n; i++) {
        char s = ss[i];
        if (s != s_before) {
            ans++;
            s_before = s;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
/*
 * atcoder/abc147/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
#define MOD 1000000007
template <class T> void madd(T &a, T b){ if((a+=b)>=MOD) a-=MOD; }
template <class T> void msub(T &a, T b){ if((a+=MOD-b)>=MOD) a-=MOD; }
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}

bool nth(ll x, int n) {
  return (x>>n)&1;
}
int N;
vector<ll> A;
void solve() {
  cin >> N;
  A.resize(N);
  loop(n,0,N) cin >> A[n];
  mint total = 0;
  for (int d=0; d<60; d++) {
    mint D = 1LL<<d;
    mint num1 = 0;
    mint num0 = 0;
    for (auto&&a: A)
      if (nth(a, d)) num1 += 1;
      else num0 += 1;
    total += D * num1 * num0;
  }
  cout << total << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 2560
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>
 
#define INF 100000000
#define EPS 1e-9
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
  
#define MAX_H 10
int H;
int maze[MAX_H][5];

vector<int> ans_list;

int main(){

  while(true){
    cin >> H;
    if(H == 0)
      break;

    for(int i = 0; i < H; i++){
      for(int j = 0; j < 5; j++){
	cin >> maze[i][j];
      }
    }

    int ans = 0;

    while(true){

      bool flag = false;
      for(int i = 0; i < H; i++){
	for(int j = 0; j < 3; j++){
	  int num = maze[i][j];
	  if(num == -1)
	    continue;
	  int n;
	  for(n = 0; n + j < 5; n++){
	    if(maze[i][j+n] != num)
	      break;
	  }
	  if(n < 3)
	    continue;
	  ans += num*n;
	  flag = true;
	  for(int k = 0; k < n; k++){
	    maze[i][j+k] = -1;
	  }
	}
      }

      if(!flag)
	break;

      /*
      cout << "消去前" << endl;
      for(int i = 0; i < H; i++){
	for(int j = 0; j < 5; j++){
	  cout << maze[i][j] << " ";
	}
	cout << endl;
      }
      */

      for(int x = 0; x < 5; x++){
	for(int y = H-1; y >= 0; y--){
	  if(maze[y][x] != -1)
	    continue;
	  int n, num = -1;
	  for(n = 1; y-n >= 0; n++){
	    if(maze[y-n][x] != -1){
	      num = maze[y-n][x];
	      maze[y-n][x] = -1;
	      maze[y][x] = num;
	      break;
	    }
	  }
	}
      }

      /*
      cout << "消去後" << endl;
      for(int i = 0; i < H; i++){
	for(int j = 0; j < 5; j++){
	  cout << maze[i][j] << " ";
	}
	cout << endl;
      }
      */

    }

    ans_list.push_back(ans);

  }

  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }
  
}

Measured memory_bytes: 1224
use proconio::input;
use proconio::marker::Usize1;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        m: usize,
    }

    let mut vaild: HashMap<usize, Vec<usize>> = HashMap::new();
    for i in 0..m {
        input! {
            k:usize,
            switches:[Usize1; k],
        }
        vaild.insert(i, switches.into_iter().collect::<Vec<usize>>());
    }
    input! {
        amari:[usize; m],
    }

    let mut res = 0;
    for bit in 0..1 << n {
        let mut on = vec![0; n];
        for i in 0..n {
            on[i] = bit & (1 << i);
        }
        let mut f = true;
        for i in 0..m {
            let mut sum = 0;
            for j in vaild.get(&i).unwrap() {
                sum += if on[*j] > 0 { 1 } else { 0 };
            }
            if (sum % 2) != amari[i] {
                f = false;
                break;
            }
        }

        if f {
            res += 1;
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 2180
#include<stdio.h>
int main(void) {
	int n, x, y, b, p, f, z=0, i, j;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d %d %d %d", &x, &y, &b, &p);
		f = x*b + y*p;
		if (b >= 5 && p >= 2)f*=0.8;
		else {
			if (b < 5)b = 5;
			if (p < 2)p = 2;
			z = 0.8*(x*b + y*p);
			if (z < f)f = z;
		}
		printf("%d\n", f);
	}
	return 0;
}

Measured memory_bytes: 600
#coding UTF-8
N=int(input())
L=[]
for i in range(N):
    a,b=map(str,input().split())
    L.append([a,int(b)])
#print(L)

X=input()

for i in range(N):
    if L[i][0]==X:
        flg=i
ans=0
for i in range(flg+1,N):
    ans+=L[i][1]
print(ans)

Measured memory_bytes: 38516
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=998244353;
int f1[maxn];
int f2[maxn];

int find1(int x)
{
    if(f1[x]==x)
        return x;
    return f1[x]=find1(f1[x]);
}
int find2(int x)
{
    if(f2[x]==x)
        return x;
    return f2[x]=find2(f2[x]);
}

void add1(int x,int y)
{
    int t1=find1(x),t2=find1(y);
    f1[t1]=t2;
}
void add2(int x,int y)
{
    int t1=find2(x),t2=find2(y);
    f2[t1]=t2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k,l;
    cin>>n>>k>>l;
    for(int i=1;i<maxn;i++)
        f1[i]=f2[i]=i;
    while(k--)
    {
        int p,q;
        cin>>p>>q;
        add1(p,q);
    }
    while(l--)
    {
        int r,s;
        cin>>r>>s;
        add2(r,s);
    }
    map<pair<int,int>,int>mp;
    for(int i=1;i<=n;i++)
    {
        mp[{find1(i),find2(i)}]++;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<mp[{f1[i],f2[i]}]<<" ";
    }


}


Measured memory_bytes: 16500
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+18
#define MOD 1000000007
using namespace std;



int main(){
    int a,b;
    cin>>a>>b;
    if(b%a==0){
        cout<<a+b<<endl;
    }else{
        cout<<b-a<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
lst = list(range(1,N+1))
st =set()
for i in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    st |= set(A)

num=0

for s in lst:
    if not s in st:
        num+=1

print(num)

Measured memory_bytes: 9192
#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 a, b;
    cin >> a >> b;

    if(a>b) {
        cout << "a > b" << endl;
    } else if(a<b) {
        cout << "a < b" << endl;
    } else if(a==b) {
        cout << "a == b" << endl;
    }
    
    
}

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


Measured memory_bytes: 3132
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

a = a.sort.reverse
sum = 0
a.each do |b|
  sum += b   
end

if a.find_all{|b| b * 4 * m >= sum }.size >= m
  puts 'Yes'
else
  puts 'No'
end

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


int main(){
	int a, b, c, i;
	cin >> a >> b >> c;
	for(i = 0; i < 10; i++){
		c = a * c - b;
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 384
i = $<.read

order, *works = i.split("\n").map do |e|
  a, b = e.split
  [a, b.to_i]
end

c = 0

until works.empty?
  k, v = works.shift
  c += v < order[1] ? v : order[1]
  v -= order[1]
  v <= 0 ? (puts "#{k} #{c}") : works << [k, v]
end

Measured memory_bytes: 21536
#include <cstdio>
#include <iostream>

using namespace std;

typedef unsigned long long ullong;

ullong power(ullong m, ullong n, ullong M) {
	if (n == 0)
		return 1;
	ullong res = power(m, n / 2, M);
	if (n % 2 == 0) {
		res = res * res % M;
	} else {
		res = (res * res % M) * m % M;
	}
	return res;
}

int main() {

	int m, n;
	scanf("%d %d", &m, &n);
	cout << power(m, n, 1000000007) << endl;

	return 0;
}

Measured memory_bytes: 3212
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
int a[200010];
int M;
pair<int,int>getlim(int l,int r)
{
	int mx=0,mn=M*2;
	for(int i=0;l+i<=r-i;i++)
		mx=max(a[l+i]+a[r-i],mx),
		mn=min(a[l+i]+a[r-i],mn);
	return make_pair(mn,mx);
}
bool check(int x)
{
	int pos=0;
	while(pos<n&&a[(pos+1)*2]<=x)pos++;
	int Llim,Rlim;
	int l=-1,r=pos+1;
	while(l+1<r)
	{
		int mid=(l+r)>>1;
		if(getlim(mid*2+1,2*n).first<M)l=mid;
		else r=mid;
	}
	Llim=r;
	l=-1,r=pos+1;
	while(l+1<r)
	{
		int mid=(l+r)>>1;
		if(getlim(mid*2+1,2*n).second>M+x)r=mid;
		else l=mid;
	}
	Rlim=l;
	if(Llim>Rlim)return false;
	l=0,r=pos+1;
	while(l+1<r)
	{
		int mid=(l+r)>>1;
		if(getlim(1,mid*2).second>x)r=mid;
		else l=mid;
	}
	if(l<Llim)return false;
	return true;
}
int main()
{
	scanf("%d %d",&n,&M);
	for(int i=1;i<=n*2;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n*2+1);
	int l=-1,r=M-1;
	while(l+1<r)
	{
		int mid=(l+r)>>1;
		if(check(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}
    sort(a.begin(), a.end());

    int ans = 0;
    rep(i, k) ans+=a[i];
    cout << ans << endl;
}



Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	 public static void main(String[] args) { 

        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
            String s = kb.readLine();
            String p = kb.readLine();

            int slen = s.length();
            int plen = p.length();
            int j = 0;
            for( int i = 0; i<slen; i++ ) {
                if( p.charAt( 0 ) == s.charAt( i ) ) {
                    int ij = i;
                    for( j = 0; j<plen; j++ ) {
                        ij = ( i+j ) % slen;
                        if( p.charAt( j ) != s.charAt( ij ) ) {
                            break;
                        }
                    }
                }
                if( plen == j ) { break; }
            }

            if( plen == j ) {
                System.out.println( "Yes" );            
            } else {
                System.out.println( "No" );
            }
        } catch( IOException e ) {
            System.err.println( e );
        }
	 }
}
	



Measured memory_bytes: 24472
n, m = map(int, input().split())
a = list(map(int, input().split()))

sum_ = sum(a)
for i in range(n):
    a[i] *= (4 * m)
cnt = 0
for i in range(n):
    if a[i] >= sum_:
        cnt += 1
if cnt >= m:
    print("Yes")
else:
    print("No")

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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    int t = min(a, k);
    ans += t; k -= t;
    t = min(b, k); k -= t;
    t = min(c, k);
    ans -= t; k -= t;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int a[100000];

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	int sum=0;
	for(int i=n;i>=n-m+1;i--)
	sum+=a[i];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

# b = qa + r
b = C
a = D
r = C%D
while r != 0:
    b = a
    a = r
    r = b%a
gcd = a
CDlcm = C*D//gcd

total = B-(A-1)
Cmuls = B//C - (A-1)//C
Dmuls = B//D - (A-1)//D
CDmuls = B//CDlcm - (A-1)//CDlcm
ans = total - Cmuls - Dmuls + CDmuls
print(ans)


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long double ld;
typedef long long ll;
const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


int main() {
    ll a, b, n; cin >> a >> b >> n;
    if(n < b){
        cout << (a * n) / b << endl;
    }else{
        cout << (a * (b - 1)) / b << endl;
    }

    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define int ll
#define endl "\n"
#define all( x ) x.begin(), x.end()
#define rev_all( x ) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(0);cin.tie(0);

typedef unsigned long long ull;

const int mod = 1e9 + 7;
const int inf = 1e12 + 5;
const long double PI = 3.141592653589793;

void solve(){
  int l, r, d;
  cin >> l >> r >> d;
  int ans = 0;
  for(int i = l; i <=r; i++){
    if(i % d == 0){
      ans++;
    }
  }
  cout << ans << endl;
  return;
}
signed main(){
  fast;
  int t;
  t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 3580
def calc(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x + 1
    else:
        return 0


def solve():
    A, B = map(int, input().split())
    ans = calc(B)
    if 0 < A:
        ans ^= calc(A-1)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
    int n,sum;
    sum=0;
    cin>>n;
    for(int i=0;i<3;++i){
        if(n%2 != 0)sum++;
        n=n/10;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
atoms = []
loop {
    atom, weight = gets.split
    break if atom =~ /^END/
    atoms << [atom, ?+ + weight]
}
atoms.sort_by!{|atom, _| -atom.size}

loop {
    s = gets.chomp
    break if s == ?0
    s.gsub!(/(\D)(\d)/){|x| $1 + "*" + $2}
    s.gsub!("(", "+(")
    atoms.each{|atom, weight|
        [atom, weight]
        s.gsub!(atom, weight)
    }
    if s =~ /[a-zA-Z]/
        puts 'UNKNOWN'
        next
    end

    p eval s
}

Measured memory_bytes: 8800
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	pair<int, char> p[m];
	for (int i = 0; i < m; i++){
		cin >> p[i].first >> p[i].second;
	}
	for (int i = 0; i < pow(10, n); i++){
		string s = to_string(i);
		bool flag = 1;
		for (int j = 0; j < m; j++){
			if (s[p[j].first-1] != p[j].second) flag = 0;
		}
		if (s.size() == n and flag){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

}


Measured memory_bytes: 256
import bisect
import copy
from decimal import Decimal
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
L = copy.copy(H)
H.sort()
s = Decimal((T-A)/0.006)
B1 = bisect.bisect_left(H,s)
B2 = B1-1
if B1 == 0:
    print(L.index(H[B1])+1)
elif B1 == N:
    print(L.index(H[B2])+1)
elif H[B1]-s < s-H[B2]:
    print(L.index(H[B1])+1)
else:
    print(L.index(H[B2])+1)

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

using namespace std;

typedef long long ll;



int main()
{
    ios_base::sync_with_stdio(0);
    
    ll n,m;
    cin>>n>>m;
    ll ans=0;
    ans = min(n,m/2);
    n-=ans;
    m-=2*ans;
    ans+=(m/4);
    cout<<ans;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        solve();
    }

    private static void solve() {
        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int x = input.nextInt();

        int cnt = 1;
        int lsum = 0;

        for (int i = 0; i < n; i++) {
        	int l = input.nextInt();
        	lsum += l;
        	if (lsum <= x) {
        		cnt++;
        	}
        }

        System.out.println(cnt);

    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    string s;
    ll k;
    while(cin>>s>>k)
    {
        ll last=-1;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]!='1')
            {
                last=i+1;
                break;
            }
        }

        if(last==-1 || k<last)pf("1\n");
        else pf("%c\n",s[last-1]);
    }   
    return 0;
}
 









 




























Measured memory_bytes: 256