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

int main(){

	long int i,j,N,cnt=0;
	char s[110];
	long int A,B,C,X,Y,ans1=0,ans2=0,ans3=0,zan;
	
	scanf("%ld%ld%ld%ld%ld",&A,&B,&C,&X,&Y);
	
//	if(A>C){
		ans1 += 2*C*X;
		zan = Y-X;
		if(zan>0){
			if(B>2*C){
				ans1 += 2*C*zan;
			}
			else{
				ans1 += zan*B;
			}
		}
//	}
//	else if(B>C) {
		
		ans2 += 2*C*Y;
		zan = X-Y;
		if(zan>0){
			if(A>2*C){
				ans2 += 2*C*zan;
			}
			else ans2 += zan*A;
		}
		
//	}
//	else{
		ans3 += A*X+B*Y;
		
//	}
	
	long int ans=0;
	if(ans1<ans2)ans = ans1;
	else ans = ans2;
	
	if(ans<ans3);
	else ans = ans3;
	printf("%ld\n",ans);
	

 return 0;
 }

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <cctype>
using namespace std;

int main(void){
  string a;
  int sum;
  while(1){
    getline(cin,a);
    if(a=="0") break;
    for (int i=0;i<a.size();i++) {
      sum += ((int)a[i] -'0');
    }
    cout << sum <<endl;
    sum = 0;
  }
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
    ll n,c=1;
    cin>>n;
    vector<pair<ll,ll>> a(n);
    rep(i,n){
        cin>>a[i].first;
        a[i].second=0;
    }
    ll b=1;
    while(a[b-1].first!=2){
        a[b-1].second++;
        b=a[b-1].first;
        if(a[b-1].second==2){
            cout<<"-1"<<endl;
            return 0;
        }
       c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 1792
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  string S;
  cin >> S;
  ll bc = 0, res = 0;
  for (const auto &c : S) {
    if (c == 'B') {
      bc++;
    } else {
      res += bc;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll a,b,c;
	cin>>a>>b>>c;
	if(c>a+b && 4*a*b<(c-a-b)*(c-a-b))
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



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

const int INF=0x3f3f3f3f;
const int M=2e5+5;
int n,k,c;
char s[M];

int l[M],r[M];

int ml[M],mr[M];

inline void cmin(int &x,int y)
{
	if(x>y) x=y;
}
inline void cmax(int &x,int y)
{
	if(x<y) x=y;
}

int main()
{
	//freopen("E.in","r",stdin);
	scanf("%d%d%d",&n,&k,&c);
	scanf("%s",s+1);
	memset(ml,INF,sizeof(ml));
	for(int i=1;i<=n;i++)
	{
		l[i]=l[i-1];
		if(s[i]!='x')
			l[i]=max(l[i],i-c-1>=1?l[i-c-1]+1:1);
		cmin(ml[l[i]],i);
	}
	memset(r,INF,sizeof(r));
	r[n+1]=k;
	for(int i=n;i>=1;i--)
	{
		r[i]=r[i+1];
		if(s[i]!='x')
			r[i]=min(r[i],i+c+1<=n?r[i+c+1]-1:k);
		//assert(r[i]<=n);
		if(r[i]>0)
			cmax(mr[r[i]],i);
	}
	// for(int i=1;i<=k;i++)
	// 	cout<<ml[i]<<" "<<mr[i]<<endl;
	for(int i=1;i<=n;i++)
	{
		//assert(0<=l[i]&&l[i]<M);
		if(i==ml[l[i]]&&ml[l[i]]==mr[l[i]])
			printf("%d\n",i);
	}
	return 0;
}


Measured memory_bytes: 4864
// Example program
#include <iostream>
#include <string>
using namespace std;
#include<math.h>
#define mx 10002 
void solve()
{
   int n;
   cin>>n;
   
  int ans[100000]={0};
  int a= sqrt(mx);
   for(long long  i=1;i<=a;i++) 
    {
      for(long long  j=1;j<=a;j++) 
      {
        for(long long  k=1;k<=a;k++)
          {
           long long c= i*i + j*j + k*k + i*j + i*k + k*j ;
              
              ans[c]++ ;
          }
      }
    }
  
   // cout<<ans[0];
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<endl;
}

int main()
{    solve();
}


Measured memory_bytes: 3980
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		doIt();

	}
	
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++){
			String[] str = new String[2];
			str[0] = sc.next();
			str[1] = sc.next();
			if(str[0].length() > 80 || str[1].length() > 80){
				System.out.println("overflow");
				continue;
			}
			int[][] num = new int[2][80];
			for(int j = 0; j < 2; j++){
				//initialize
				for(int k = 0; k < 80; k++){
					num[j][k] = 0;
				}
				int len = str[j].length();
				//System.out.println(len);
				for(int k = 0; k < len; k++){
					char c = str[j].charAt((len - 1) - k);
					num[j][k] = Character.getNumericValue(c);
				}
			}
			//print(num[0]);
			//print(num[1]);
			boolean bUp = false;
			int[] ans = new int[80];
			for(int j = 0; j < 80; j++){
				int tmp = num[0][j] + num[1][j];
				if(bUp){
					tmp++;
					bUp = false;
				}
				if(tmp >= 10){
					tmp = tmp%10;
					bUp = true;
				}
				ans[j] = tmp;
			}
			if(bUp){
				System.out.println("overflow");
				continue;
			}

			//print(ans);
			int start = 79;
			//0は飛ばす
			while(start >= 0 && ans[start] == 0){
				start--;
			}
			if(start == -1){
				System.out.println(0);
			}
			else{
				for(int j = start; j >= 0; j--){
					System.out.print(ans[j]);
				}
				System.out.println("");
			}
			//String2Int[]
		}
	}
	
	public static void print(int[] array){
		int len = array.length;
		for(int i = 0; i < len; i++){
			System.out.print(array[i]);
		}
		System.out.println("");
	}
 
}

Measured memory_bytes: 12000
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,pos;
ll k,T=1;
vector<vector<int>> table;
vector<int> as,used,route={};
vector<P> to;


void solve(){
    cin >> n >> k;
    table.resize(1000000,{});
    used.resize(1000000,0);
    to.resize(n+1,P(0,0));
    rep(i,n){
        int a;
        cin >> a;
        
        as.push_back(a-1);
        table[a-1].push_back(i);
    }
    rep(i,n){
        //cout << as[i] << " " << used[as[i]] << endl;
        to[i].first=table[as[i]][(used[as[i]]+1)%table[as[i]].size()]+1;
        if (used[as[i]]+1>=table[as[i]].size()) {
            to[i].second=1;
        }
        used[as[i]]+=1;
    }
    pos=0;
    while (pos!=n){
        route.push_back(pos);
        T+=to[pos].second;
        pos=to[pos].first;
    }
    route.push_back(n);
    
    // cout << " " << endl;
    // rep(i,n) cout << to[i].first << " " << to[i].second << endl;
    // rep(i,route.size()) cout << route[i] << " ";
    // cout << " " << endl;
    // cout << T << endl;
    int a=0,pos=0;

    while (a<(k-1)%T){
        P p=to[pos];
        pos=p.first;
        a+=p.second;
        //cout << pos << " " << a << endl; 
     }

    Rep(i,pos,n){
        if (to[i].second) cout << as[i]+1 << " ";
        else i=to[i].first-1;
    }
}

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

Measured memory_bytes: 38388
#include<cstdio>
#include<iostream>
using namespace std;
const int INF=0x3f3f3f3f;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
int n,m,K,sx,sy,head,tail;
char s[805][805];
int dist[805][805];
int q[1000005][2];
inline void Ins(int x,int y,int d){
	if(s[x][y]!='.'||dist[x][y]!=INF)return;
	dist[x][y]=d;
	q[tail][0]=x;q[tail][1]=y;tail++;
}
void bfs(){
	Ins(sx,sy,0);
	while(head<tail){
		int x=q[head][0],y=q[head][1];head++;
		int d=dist[x][y];
		for(int i=0;i<4;i++){
			int nx=x+dx[i];
			int ny=y+dy[i];
			Ins(nx,ny,d+1);
		}
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++){
			if(s[i][j]=='S'){
				s[i][j]='.';
				sx=i;sy=j;
			}
		}
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)dist[i][j]=INF;
	bfs();
	int res=INF;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(dist[i][j]<=K){
				int tmp=1+(min(min(i-1,n-i),min(j-1,m-j))+K-1)/K;
				if(res>tmp){
					res=tmp;
				}
			}
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define vl vector
using namespace std;

int main()
{
    ll t,i,n;
    ll a,b,c;
    string s;
    map<ll,ll> mp;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a;
        if(mp.find(a)!=mp.end())
        {
            cout<<"NO";
            return 0;
        }
        mp[a]++;
    }
    cout<<"YES";
    return 0;
}

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

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

int main(void)
{
    ll a,b,c,d;
    ll saidai=-9223372036854775808;
    cin >> a >> b >> c >> d;

    if((a<0 && b>0) || (c<0 && d>0))
    {
        saidai=0;
    }
    saidai=max(saidai,b*d);
    saidai=max(saidai,a*c);
    saidai=max(saidai,a*d);
    saidai=max(saidai,c*b);
    cout << saidai << endl;     
    return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int N, M;
  int a[100];
  cin >> N >> M;
  rep(i, N) {
    cin >> a[i];
  }

  int sum = 0;
  rep(i, N) {
    sum += a[i];
  }
  int key = sum / (4 * M);
  if(sum % (4 * M) == 0) key--;
  int ans = 0;
  rep(i, N) {
    if(a[i] > key) ans++;
  }

  if(ans >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/

#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))

//ABC 144 B

int main(void)
{
  int N;
  int flag = 0;
  scanf("%d", &N);
  for (size_t i = 1; i < 10; i++) {
    if (N / i < 10 && N % i == 0) {
      flag = 1;
      break;
    }
  }
  if (flag == 1) {
    printf("Yes\n" );
  }
  else printf("No\n" );
  return 0;
}


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

long long int findTrailingZeros(long long int n) 
{ 
    // Initialize result 
   long long int count = 0; 
  
    // Keep dividing n by powers of  
    // 5 and update count 
    for (long long int i = 5; n / i >= 1; i *= 5) 
        count += n / i; 
  
    return count; 
} 
   
int main(void){
    // Your code here!
long long int N;
cin >> N;
if(N%2)
 cout << 0;
 else  { 
     long long int M=N/2;
   
    cout <<findTrailingZeros(M);
    
 }
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:
const ll inf=1LL<<50;

// Description: ??°??????????????????(?????????????°??????¨???)
// Verifyed: Many Diffrent Problem 

//Appropriately Changed
using edge=struct{int to,cost,cap,rev;};
using G=vector<vector<edge>>;

//Appropriately Changed
void add_edge(G &graph,int from,int to,int cap,int cost){ 
	graph[from].push_back({to,cost,cap,int(graph[to].size())});
	graph[to].push_back({from,-cost,0,int(graph[from].size())-1});
}

// Description: ??°??????????????????????°??????¨??? 
// TimeComplexity: $ \mathcal{O}(FVE) $ 
// Verifyed: AOJ GRL_6_B

template <typename W> W primal_dual(G &graph,int s,int t,int f,W inf){
	W res=0;
	while(f){
		int n=graph.size(),update;
		vector<W> dist(n,inf);
		vector<int> pv(n,0),pe(n,0);
		dist[s]=0;

		rep(loop,n){
			update=false;
			rep(v,n)rep(i,graph[v].size()){
				edge &e=graph[v][i];
				if(e.cap>0 && chmin(dist[e.to],dist[v]+e.cost)){
					pv[e.to]=v,pe[e.to]=i;
					update=true;
				}
			}
			if(!update) break;
		}

		if(dist[t]==inf) return -1;

		int d=f;
		for(int v=t;v!=s;v=pv[v]) chmin(d,graph[pv[v]][pe[v]].cap);
		f-=d,res+=d*dist[t];

		for(int v=t;v!=s;v=pv[v]){
			edge &e=graph[pv[v]][pe[v]];
			e.cap-=d;
			graph[v][e.rev].cap+=d;
		}
	}
	return res;
}

int main(void){
	int v,e,f;
	cin >> v >> e >> f;
	G graph(v);
	rep(i,e){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		add_edge(graph,a,b,c,d);
	}

	cout << primal_dual<ll>(graph,0,v-1,f,inf) << endl;
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX_N=100005;
const int Mod=1e9+7;
vector <int> g[MAX_N]; 
int n;
LL dp[MAX_N][2];
void dfs(int v,int fa)
{
	dp[v][0]=dp[v][1]=1;
	for(int i=0;i<g[v].size();i++)
	{
		int u=g[v][i];
		if(u==fa)continue;
		dfs(u,v);
		dp[v][0]*=(dp[u][0]+dp[u][1]);
		dp[v][1]*=dp[u][0];
		dp[v][0]%=Mod;
		dp[v][1]%=Mod;
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1,0);
	cout<<(dp[1][0]+dp[1][1])%Mod<<endl;
	return 0;
}


Measured memory_bytes: 14208
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
int W,H,N;
const int MAXN=1015;
int X1[MAXN],X2[MAXN],Y1[MAXN],Y2[MAXN];
/// ??????????????¨?????£??¨??????(i, j)??????????????????????????????
bool fld[MAXN*6][MAXN*6];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
///???X1???X2?????????????????£???,??¶???????????£??????????????????
int compress(int *x1,int *x2,int w)
{
    vector<int>xs;
    for(int i=0; i<N; i++)
    {
        for(int d=-1; d<=1; d++)
        {
            int tx1=x1[i]+d,tx2=x2[i]+d;
            if(0<=tx1&&tx1<w)xs.push_back(tx1);
            if(0<=tx2&&tx2<w)xs.push_back(tx2);
        }
    }
    sort(xs.begin(),xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());///unique ??????
    for(int i=0; i<N; i++) ///?????°????????°??????
    {
        x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
        x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
    }
    return xs.size();
}
void solve()
{
    ///???????????£???
    W=compress(X1,X2,W);
    H=compress(Y1,Y2,H);
    ///???????????´????????¨???
    memset(fld,0,sizeof(fld));

    for(int i=0; i<N; i++)
    {
        for(int y=Y1[i]; y<=Y2[i]; y++)
        {
            for(int x=X1[i];x<=X2[i]; x++)
            {
                fld[y][x]=true;
            }
        }
    }
    ///?±???????????????°
    int ans=0;
    for(int y=0; y<H; y++)
    {
        for(int x=0; x<W; x++)
        {
            if(fld[y][x])continue;
            ans++;
            ///????´¢
            queue<pair<int,int> >que;
            que.push(make_pair(x,y));
            while(!que.empty())
            {
                int sx=que.front().first,sy=que.front().second;
                que.pop();
                for(int i=0; i<4; i++)
                {
                    int tx=sx+dx[i],ty=sy+dy[i];
                    if(tx<0||W<=tx||ty<0||H<=ty)continue;
                    if(fld[ty][tx])continue;
                    que.push(make_pair(tx,ty));
                    fld[ty][tx]=true;
                }
            }
        }
    }
    printf("%d\n",ans);
}
int main()
{
    while(scanf("%d%d",&W,&H)&&W)
    {
        scanf("%d",&N);
        for(int i=0;i<N;i++)
        {
            scanf("%d%d%d%d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
            --X2[i];
            --Y2[i];
        }
        solve();
    }
    return 0;
}
/*

*/

Measured memory_bytes: 37464
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n);
  for (auto &v : vec)
    cin >> v;

  sort(vec.begin(), vec.end(), greater<int>());

  int vsum = accumulate(vec.begin(), vec.end(), 0);

  bool flag = true;
  for (int i = 0; i < m; ++i)
    if (vec[i] < vsum / 4. / m)
      flag = false;

  cout << (flag ? "Yes" : "No") << endl;
}

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

int main(){
  int k,s;
  cin >> k >> s;
  
  int p = 0;
  for ( int i = 0; i <= k ; i++){
    for (int j = 0; j <= k ; j++){
      if ( s < i + j ) continue;
      else if ( s - i - j <= k ) p++;
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <complex>
#include <utility>
#include <cmath>
#include <cassert>

using namespace std;

typedef complex<double> Vector;
typedef pair<Vector,Vector> Line;

const double EPS = 1e-8;

double cross(const Vector &v1, const Vector &v2) {
    return v1.real()*v2.imag() - v1.imag()*v2.real();
}

double dot(const Vector &v1, const Vector &v2) {
    return v1.real()*v2.real() + v1.imag()*v2.imag();
}

int ccw(const Vector &p1, const Vector &p2, const Vector &p3) {
    Vector v1 = p2-p1;
    Vector v2 = p3-p1;
    double op = cross(v1, v2);
    if(op > 0) return 1;
    if(op < 0) return -1;
    if(dot(v1, v2)) return 2;
    if(norm(v1) < norm(v2)) return -2;
    return 0;
}

Vector crosspoint(const Line &l1, const Line &l2) {
    double a = cross(l1.second-l1.first, l2.second-l2.first);
    double b = cross(l1.second-l1.first, l1.second-l2.first);
    if(fabs(a) < EPS && fabs(b) < EPS) return l2.first;
    assert(fabs(a) >= EPS);
    return l2.first + b / a * (l2.second-l2.first);
}

vector<Vector> convex_cut(const vector<Vector> &v, const Line &l) {
    vector<Vector> res;
    for(int i = 0; i < v.size(); ++i) {
        Vector cur = v[i], next = v[(i+1)%v.size()];
        if(ccw(l.first, l.second, cur) != -1) res.push_back(cur);
        if(ccw(l.first, l.second, cur)*ccw(l.first, l.second, next) < 0) {
            res.push_back(crosspoint(Line(cur, next), l));
        }
    }

    return res;
}

int main() {
    while(true) {
        int N;
        cin >> N;
        if(N == 0) break;

        vector<Vector> v;
        for(int i = 0; i < N; ++i) {
            double x, y;
            cin >> x >> y;
            v.push_back(Vector(x, y));
        }

        vector<Vector> poly;
        poly.push_back(Vector(-20000, -20000));
        poly.push_back(Vector(20000, -20000));
        poly.push_back(Vector(20000, 20000));
        poly.push_back(Vector(-20000, 20000));
        for(int i = 0; i < N; ++i) {
            const Vector &p1 = v[i];
            const Vector &p2 = v[(i+1)%N];
            const Vector v = p2-p1;
            poly = convex_cut(poly, Line(p1-v*50000., p1+v*50000.));
            //for(int j = 0; j < poly.size(); ++j) cout << poly[j] << ' ';
            //cout << endl;
        }

        cout << ((poly.size() > 0) ? 1 : 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 0
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
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); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

void sputs(){}
template <class Head, class... Tail>
void sputs(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(Tail) == 0) { cout << endl; }
  else { cout << " "; }
  sputs(std::move(tail)...);
}

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n;cin>>n;
  vector<int> a(n);
  map<int, int> cnt;
  map<int, int> mostleft;
  int s = 0;
  rep(i, n) { cin>>a[i]; s+=a[i];}
  rrep(i, n){
    cnt[a[i]]++;
    mostleft[a[i]] = i;
  }
  dump(cnt);
  dump(mostleft);
  vi sa = a;
  sort(all(sa));
  uni(sa);

  vi ans(n);
  int carry = 0;
  dump(sa);

  rrep(i, 0, sz(sa)){
    int v = sa[i];
    if (mostleft[v]==0){
      ans[0] = s - accumulate(all(ans), 0LL);
      break;
    }

    int nv = sa[i-1];
    int ni = i-1;
    dump(v);
    while(mostleft[nv]>mostleft[v]){
      nv = sa[--ni];
    }
    int idx = mostleft[v];

    dump(i, v, nv, idx);
    dump(i, idx, carry, cnt[v]);
    ans[idx] += (v-nv)*(carry + cnt[v]);
    carry += cnt[v];

    rep(j, ni+1, i){
      carry+=cnt[sa[j]];
      ans[idx] += (sa[j]-nv)*cnt[sa[j]];
    }
    
    i = ni+1;
    cerr << endl;
  }

  assert(s = accumulate(all(ans), 0LL));
  rep(i, n){
    cout << ans[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int x=0,y=0,z=0,a,sub=-1000000000;
  for(int i=0;i<n;i++){
    cin>>a;
    if(i==0) x=a;
    if(i!=0 && sub<a-x) sub=a-x;
    if(x>a){
      x=a;
    }
    if(x-a>z)
      z=x-a;
  }
  if(z==0) cout<<sub<<endl;
  else 
  cout<<z<<endl;
  return 0;
  
}



Measured memory_bytes: 3104
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
double a;
int s[1000];
double n;
double m;
double sum;
int main()
{
  while(cin >>n,n){
    sum = 0;
    a = 0;
    for(int i = 0;i <n;i++){
      cin >>s[i];
      sum +=s[i];
    }
    m =sum/n;
    for(int i = 0;i <n;i++){
      a +=(s[i]-m)*(s[i]-m);
    }
    a =a/n;
    a =sqrt(a);
    cout <<fixed<<setprecision(10)<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1292
//状态:
//题号:
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <iomanip>
#include <cassert>
#include <complex>
#include <functional>
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
int n;
ll ret,sum;
map<ll,int> mp;
int main(){
	scanf("%d",&n);
	mp[0ll]=1;
	for(int i=0;i<n;i++){
		ll a;
		scanf("%lld",&a);
		sum+=a;
		ret+=mp[sum];
		mp[sum]++;
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 12800
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>

using namespace std;
int gcd(int a, int b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
#define MOD 1000000007
#define INF 99999999999 
#define pb push_back
#define mt make_tuple
#define ll long long
ll ncr(ll n, ll r)
{
	ll i, ans = 1, k = 0;
	if (r == 0)
		return 1;
	else if (n < r)
		return 0;
	for (i = n; i >= n - r + 1; i--)
	{
		ans *= i;
		ans /= n - i + 1;
	}


	return ans;

}
bool visited[6] = { false };
int n = 6;
vector<int> adj[6];


void max_heapify(int a[100], int i)
{
	int l, r, largest = i;
	l = 2 * i + 1;
	r = 2 * i + 2;
	if (l<n && a[l]>a[i])
		largest = l;
	if (r<n && a[r]>a[l])
		largest = r;
	if (largest != i)
	{
		int k;
		k = a[i];
		a[i] = a[largest];
		a[largest] = k;
		max_heapify(a, largest);
	}

}
int power(ll x, ll y, ll p)
{
	int res = 1;
	x = x % p;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;


		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

bool square(ll n)
{
	double x;
	x = sqrt(n);
	if (x == floor(x))
		return true;
	else return false;
}


bool prime(ll n)
{
	ll i;
	for (i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}
void dfs(ll a, ll b, vector<pair<ll, ll>>adj[][1001], bool visited[][1001])
{
	visited[a][b] = true;
	for (auto u : adj[a][b])
	{
		if (!visited[get<0>(u)][get<1>(u)])
		{
			visited[get<0>(u)][get<1>(u)] = true;
			dfs(get<0>(u), get<1>(u), adj, visited);
		}
	}
}
ll modi(ll a, ll m)
{
	return power(a, m - 2, m);

}
ll dp[101][100001];
int main() {
	ll N, W,w[101],v[101],i,j;
	cin >> N >> W;
	for ( i = 0; i < N; ++i) cin >> w[i] >> v[i];

	for (i = 0; i <= W; ++i) dp[0][i] = 0;
	for (i = 0; i < N; ++i) {
		for (j = 0; j < w[i]; j++) dp[i + 1][j] = dp[i][j];
		for (j = w[i]; j <= W; ++j) {
			dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
		}
	}
	cout << dp[N][W] <<endl;
	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define INF 1e9

int main(){
    int n; cin >> n;
    ll k; cin >> k;
    map<ll ,ll> mp;
    rep(i,n){
        int a,b; cin >> a >> b;
        mp[a] += b;
    }
    ll cnt = 0;
    
    for(auto i : mp){
        cnt += i.second;
        if(cnt >= k){
            cout << i.first << endl;
            return 0;
        }
    }
    
    
}


Measured memory_bytes: 4224
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
const int M = 1e5 + 2 ;
int n;
int a[M];
int dp[M];
int main()
{
    scanf ("%d" , &n );
    for (int i =0 ; i < n ;i++)scanf ("%d" , a+i );
    dp[1] = abs( a[0] - a[1] );
    for (int i = 2; i < n ;i++)
    {
        dp[i] = min (abs (a[i-1] - a[i]) + dp[i-1] , dp[i-2] + abs (a[i-2] - a[i]));
    }
    cout << dp[n-1] <<"\n";
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(),v.end()

int main() {
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    int ans = 0;
    while (1) {
        if (a[0]==a[1] && a[1]==a[2]) break;

        sort(all(a));
        if (a[0] < a[1]) {
            a[0] += 2;
        } else {
            a[0]++;
            a[1]++;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
string s;
stack<int> st;

int main(){
	cin >> s;
	
	REP(i,0,s.size()){
		if(s[i] == '0') st.push(0);
		else if(s[i] == '1') st.push(1);
		else if(s[i] == 'B' and !st.empty()) st.pop();
	}
	
	stack<int> stt;
	while(!st.empty()) stt.push(st.top()),st.pop();
	while(!stt.empty()) cout << stt.top(),stt.pop();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lv = rli()
    lv.sort()
    ans = lv[0]
    for i in range(1, n):
        ans = (ans+lv[i])/2
    print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> iii;
typedef vector<iii> viii;

#define umap unordered_map
#define uset unordered_set
#define pb push_back
#define LSOne(x) (x & (-x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

const int iinf = 1e9+7;
const ll inf = 1e18+7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,k; cin >> n >> k;
    vi v(n);
    for (auto& i : v) cin >> i;
    vi dp(n,iinf);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j <= i+k; ++j) {
            if (j < n) dp[j] = min(dp[i]+abs(v[i]-v[j]),dp[j]);
        }
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0) {
				break;
			}
			if (H % 2 == 0) {
				for (int i = 1; i <= H / 2; i++) {
					if (W % 2 == 0) {
						for (int j = 1; j <= W / 2; j++) {
							System.out.print("#.");
						}
						System.out.print("\n");
						for (int k = 1; k <= W / 2; k++) {
							System.out.print(".#");
						}
						System.out.print("\n");
					} else if (W != 1) {
						for (int j = 1; j <= W / 2; j++) {
							System.out.print("#.");
						}
						System.out.print("#\n");
						for (int k = 1; k <= W / 2; k++) {
							System.out.print(".#");
						}
						System.out.printf(".\n");
					} else {
						System.out.print("#\n");
						System.out.print(".\n");
					}
				}
			} else if (H != 1) {
				for (int i = 1; i <= H / 2; i++) {
					if (W % 2 == 0) {
						for (int j = 1; j <= W / 2; j++) {
							System.out.print("#.");
						}
						System.out.print("\n");
						for (int k = 1; k <= W / 2; k++) {
							System.out.print(".#");
						}
						System.out.print("\n");
					} else if (W != 1) {
						for (int j = 1; j <= W / 2; j++) {
							System.out.print("#.");
						}
						System.out.print("#\n");
						for (int k = 1; k <= W / 2; k++) {
							System.out.print(".#");
						}
						System.out.printf(".\n");
					} else {
						System.out.print("#\n");
						System.out.print(".\n");
					}
				}
				if (W % 2 == 0) {
					for (int j = 1; j <= W / 2; j++) {
						System.out.print("#.");
					}
					System.out.print("\n");
				} else if (W != 1) {
					for (int j = 1; j <= W / 2; j++) {
						System.out.print("#.");
					}
					System.out.print("#\n");
				} else {
					System.out.print("#\n");
				}
			} else {
				if (W % 2 == 0) {
					for (int j = 1; j <= W / 2; j++) {
						System.out.print("#.");
					}
					System.out.print("\n");
				} else if (W != 1) {
					for (int j = 1; j <= W / 2; j++) {
						System.out.print("#.");
					}
					System.out.print("#\n");
				} else {
					System.out.print("#\n");
				}
			}
			System.out.print("\n");
		}
	}
}

Measured memory_bytes: 36976
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1LL << (x))
using ll = long long;
using namespace std;

constexpr int mod = 1e9 + 7;

int main(){
  int n; cin >> n;
  vector<vector<int>> a(n, vector<int>(n, 0));
  REP(i, n)REP(j, n) cin >> a[i][j];

  /*
  vector<vector<ll>> dp(n+1, vector<ll>(bit(n+1), 0));
  function<ll(int, int)> rec = [&](int i, int b){
    if(i == n) return 1LL;
    if(dp[i][b]) return dp[i][b];

    ll res = 0;
    REP(j, n){
      if(b & bit(j) || !a[i][j]) continue;
      (res += rec(i+1, b | bit(j))) %= mod;
    }

    return dp[i][b] = res;
  };
  */

  vector<vector<ll>> dp(n+1, vector<ll>(bit(n), 0LL));
  dp[n][bit(n)-1] = 1;

  RFOR(b, bit(n)-2, -1)REP(i, n){
    if(__builtin_popcount(b) != i) continue;
    REP(j, n){
      if(b & bit(j) || !a[i][j]) continue;
  
      (dp[i][b] += dp[i+1][b | bit(j)]) %= mod;
    }
  }

  cout << dp[0][0] << endl;

  return 0;
}


Measured memory_bytes: 377216
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

assist = 0
kill = 0

for i in range(n):
    if assist+b[i] < a[i]:
        kill += assist+b[i]
        assist = 0
    else:
        if assist <= a[i]:
            kill += a[i]
            assist += b[i] - a[i]
        else:
            kill += a[i]
            assist = b[i]

if assist == 0:
    print(kill)
elif assist < a[-1]:
    print(kill + assist)
else:
    print(kill + a[-1])

Measured memory_bytes: 18476
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

double PI = 6.28318530717958623200 / 2.0;

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main()
{
    int n, m;
    cin >> n >> m;
    ll sum = 0;
    rep(i, m)
    {
        ll t;
        cin >> t;
        sum += t;
    }
    if (n < sum)
        cout << -1 << endl;
    else
        cout << n - sum << endl;
    return 0;
}


Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll H,W,N,sr,sc;
string S,T;
struct Vector{
	ll x,y;
	Vector(ll x=0,ll y=0):x(x),y(y){}
};
Vector operator+(Vector a,Vector b){
	return Vector(a.x+b.x,a.y+b.y);
}
void operator+=(Vector &a,Vector b){
	a=a+b;
}
bool isout(Vector v){
	return v.x<0||v.x>=W||v.y<0||v.y>=H;
}
ll yoi(ll dir,char c,Vector v){
	switch(dir){
		case 0:{
			if(c=='R'){
				return 1;
			}else if(c=='L' && v.x>0){
				return -1;
			}
			break;
		}
		case 1:{
			if(c=='D'){
				return 1;
			}else if(c=='U' && v.y>0){
				return -1;
			}
			break;
		}
		case 2:{
			if(c=='L'){
				return 1;
			}else if(c=='R' && v.x<W-1){
				return -1;
			}
			break;
		}
		case 3:{
			if(c=='U'){
				return 1;
			}else if(c=='D' && v.y<H-1){
				return -1;
			}
			break;
		}
	}
	return 0;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	map<char,Vector> mp;
	mp['L']=Vector(-1,0);
	mp['R']=Vector(1,0);
	mp['U']=Vector(0,-1);
	mp['D']=Vector(0,1);
	cin>>H>>W>>N>>sr>>sc>>S>>T;
	bool ans=false;
	REP(i,4){
		Vector v(sc-1,sr-1);
		REP(j,N){
			if(yoi(i,S[j],v)==1){
				v+=mp[S[j]];
			}
			if(isout(v)){
				ans=true;
			}
			if(yoi(i,T[j],v)==-1){
				v+=mp[T[j]];
			}
		}
	}
	cout<<(ans?"NO":"YES")<<endl;
}

Measured memory_bytes: 920
n, k = readline.split(' ').map(&:to_i)
h = readline.split(' ').map(&:to_i)
rh = h.sort { |x,y| y <=> x }
total = 0

if rh[k] != nil
  rh[k..-1].each do |h|
    total += h
  end
end


puts total

Measured memory_bytes: 19312
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
    cin >> s;
    int slen = s.length();
    for(int i = 0; i < slen; ++i) {
        if(s.at(i) == ',') {
            s.at(i) = ' ';
        }
    }

    cout << s << endl;
}

Measured memory_bytes: 256
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))

first_cnt = 0
second_cnt = 0
third_cnt = 0

for i in range(N):
    if P[i] <= A:
        first_cnt += 1
    elif P[i] <= B:
        second_cnt += 1
    else:
        third_cnt += 1

print(min(first_cnt, second_cnt, third_cnt))

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

int main() {
    int n, k; cin >> n >> k;
    vector <int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    sort(a.begin(), a.end());
    
    int sum = 0;
    for(int i = 0; i < k; i++) sum += a[i];

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3628
grad :: [Integer] -> String
grad (m:f:r:_) | m < 0 || f < 0 = "F"
               | m+f >= 80 = "A"
               | m+f >=65  = "B"
               | m+f >= 50 = "C"
               | r >= 50   = "C"
               | m+f >= 30 = "D"
               | otherwise = "F"
main = getContents >>= mapM_ (putStrLn . grad) . takeWhile (/=[-1,-1,-1]) . map (map read . words) . lines

Measured memory_bytes: 4064
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int DY[4] = {-1, 0, 1, 0};
const int DX[4] = {0, 1, 0, -1};

struct Node {
  int y;
  int x;
  int cost;

  Node(int y = -1, int x = -1, int cost = -1) {
    this->y = y;
    this->x = x;
    this->cost = cost;
  }
};

int main() {
  int H, W;
  cin >> H >> W;

  int CH, CW;
  cin >> CH >> CW;

  int DH, DW;
  cin >> DH >> DW;

  vector<string> grid;
  string row;

  for (int i = 0; i < H; ++i) {
    cin >> row;
    grid.push_back(row);
  }

  deque<Node> dque;
  bool visited[H][W];
  memset(visited, false, sizeof(visited));

  dque.push_back(Node(CH - 1, CW - 1, 0));

  while (!dque.empty()) {
    Node node = dque.front();
    dque.pop_front();

    if (grid[node.y][node.x] == '#') continue;
    if (visited[node.y][node.x]) continue;
    visited[node.y][node.x] = true;

    if (node.y == DH - 1 && node.x == DW - 1) {
      cout << node.cost << endl;
      return 0;
    }

    for (int i = 0; i < 4; ++i) {
      int ny = node.y + DY[i];
      int nx = node.x + DX[i];

      if (ny < 0 || nx < 0 || H <= ny || W <= nx) continue;

      dque.push_front(Node(ny, nx, node.cost));
    }

    for (int dy = -2; dy <= 2; ++dy) {
      for (int dx = -2; dx <= 2; ++dx) {
        int ny = node.y + dy;
        int nx = node.x + dx;

        if (ny < 0 || nx < 0 || H <= ny || W <= nx) continue;

        dque.push_back(Node(ny, nx, node.cost + 1));
      }
    }
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 8676
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  ll a = 0, b = 0, c = 0, d = 0;
  for(int i=0;i<n;i++){
    string s;std::cin >> s;
    if(s=="AC") a++;
    if(s=="WA") b++;
    if(s=="TLE") c++;
    if(s=="RE") d++;
  }
  std::cout << "AC x " << a << '\n';
  std::cout << "WA x " << b << '\n';
  std::cout << "TLE x " << c << '\n';
  std::cout << "RE x " << d << '\n';
  return 0;
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>x(m), l(m - 1);
	rep(i, m) {
		cin >> x[i];
	}
	sort(x.begin(), x.end());
	rep(i, m - 1) {
		l[i] = x[i + 1] - x[i];
	}
	sort(l.begin(), l.end());
	int nmax = max(m - n, 0);
	int ans = 0;
	if (nmax) {
		for (int i = 0;i < nmax;++i) {
			ans += l[i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long H, W, M;
    cin >> H >> W >> M;
    vector<long> yoko(H);
    vector<long> tate(W);
    long h,w;
    vector<long> target[H];
    vector<long> target_[W];
    for(size_t i=0;i<M; i++)
    {
        cin >> h >> w;
        h--;w--;
        target[h].push_back(w);
        target_[w].push_back(h);
        yoko[h]++;
        tate[w]++;
    }
    vector<long> yoko_ = yoko;
    vector<long> tate_ = tate;

    vector<long>::iterator y_iter = max_element(yoko.begin(), yoko.end());
    size_t y_index = distance(yoko.begin(), y_iter);
    for(auto w : target[y_index]) tate[w]--;
    vector<long>::iterator t_iter = max_element(tate.begin(), tate.end());
    size_t t_index = distance(tate.begin(), t_iter);

    vector<long>::iterator t_iter_ = max_element(tate_.begin(), tate_.end());
    size_t t_index_ = distance(tate_.begin(), t_iter_);
    for(auto h : target_[t_index_]) yoko_[h]--;
    vector<long>::iterator y_iter_ = max_element(yoko_.begin(), yoko_.end());
    size_t y_index_ = distance(yoko_.begin(), y_iter_);
    cout << max(*y_iter + *t_iter, *y_iter_ + *t_iter_) << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

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

const long long INF = 1LL << 60;

//入力
int sx,sy,tx,ty;


int main(){
    cin >> sy >> sx >> ty >> tx;
    for (int i = 0; i < (tx - sx); i++){
        cout << 'U';
    }
    for (int i = 0; i < (ty - sy); i++){
        cout << 'R';
    }
    for (int i = 0; i < (tx - sx); i++){
        cout << 'D';
    }
    for (int i = 0; i < (ty - sy); i++){
        cout << 'L';
    }
    cout << 'L';
    for (int i = 0; i < (tx - sx + 1); i++){
        cout << 'U';
    }
    for (int i = 0; i < (ty - sy + 1); i++){
        cout << 'R';
    }
    cout << 'D';
    cout << 'R';
    for (int i = 0; i < (tx - sx + 1); i++){
        cout << 'D';
    }
    for (int i = 0; i < (ty - sy + 1); i++){
        cout << 'L';
    }
    cout << 'U' << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    string s;
    int d[10000]={0};
    cin>>s;
    rep(i,s.size()){
        d[s[i]]++;
        if(d[s[i]]>=2){
            cout<<"no"<<endl;
            return 0;
        }
    }
    cout<<"yes"<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
int main(){
int i,n;
double ave,a=0,s[1010],sum=0;
while(1){
scanf("%d\n",&n);
if(n==0){
break;
}
for(i=0;i<n;i++){
scanf("%lf\n",&s[i]);
}
for(i=0;i<n;i++){
sum=sum+s[i];
}
ave=sum/n;
for(i=0;i<n;i++){
a=a+(s[i]-ave)*(s[i]-ave);
}
a=a/n;
printf("%lf\n",sqrt(a));
sum=0,a=0;
}
return 0;
}


Measured memory_bytes: 2024
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define vi vector<int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	// int t;
	// cin>>t;
	// while(t--){
		
	// }
	int h, n;
	cin>>h>>n;
	int sum = 0;
	for(int i = 0; i < n; i++){
		int temp;
		cin>>temp;
		sum += temp;
	}
	if(sum >= h){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 256