akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//priority_queue <int, vector <int>, greater <int> > pq; ..for min heap
using namespace std;
#define MOD 1000000007
#define PI 3.14159265358979323846264
#define pii pair <int, int>
#define pipii pair <int, pair <int, int> > 
#define piipi pair <pair <int, int>, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
#define FOR(i, x, y) for (int i=x; i<=y; i++)
#define FORD(i, y, x) for (int i=y; i>=x; i--)
#define debug printf("OK\n")
int n, m;
char s[1005][1005];
ll dp[1005][1005];
int main() {
    scanf("%d %d", &n, &m);
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            scanf(" %c", &s[i][j]);
        }
    }
    dp[1][1] = 1;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            if (i == 1 && j == 1) continue;
            if (s[i][j] == '.') dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
        }
    }
    printf("%lld\n", dp[n][m]);
    return 0;
}

Measured memory_bytes: 9088
/*input
5 5
..#..
.....
#...#
.....
..#..
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits>

using namespace std; 

int GCD(int x,int y){return y?GCD(y,x%y):x;}
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define rept(v) for(auto it=v.begin();it<v.end();it++)
#define all(v) v.begin(),v.end()
const int INF = 1<<30;
typedef long long ll;
typedef pair<int,int> pii;

int const MOD = 1e9+7;
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int h, w;
	cin >> h >> w;
	char a[h+1][w+1];
	rep(i, h) rep(j, w) cin >> a[i+1][j+1];
	int dp[h+1][w+1];
	memset(dp, 0, sizeof(dp));
	dp[0][1]=1;
	repl(i, 1, h+1) repl(j, 1, w+1) {
		if(a[i][j]=='.') dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
	}
	cout << dp[h][w] << endl;
	return 0;
}

Measured memory_bytes: 8536
#include <iostream>
#include <string>
#define int long long
#define MOD 1000000007
using namespace std;

signed main(){
	string t,b;
	int dp[1001][1001] = {};
	for(int i = 0;i <= 1000;i++) dp[i][0] = 1;
	cin >> t >> b;
	for(int i = 1;i <= t.length();i++){
		for(int j = 1;j <= b.length();j++){
			dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
			if(t[i - 1] == b[j - 1]) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
		}
	}
	cout << dp[t.length()][b.length()] << endl;
	return 0;
}

Measured memory_bytes: 10988
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

long long a[2000];
long long min_interval[2001][2001];

int N;
long long x;

long long min(long long a, long long b) {
	if (a < b) {
		return a;
	}
	else {
		return b;
	}
}

long long min_int(int i, int j) {
	
	int middle;
	/*[i,j)のminimum*/
	if (min_interval[i][j] != 1000000001) {
		return min_interval[i][j];
	}
	else if (j <= i) {
		return min_interval[i][j];
	}
	else if (j - i == 1) {
		min_interval[i][j] = a[i];
		return min_interval[i][j];
	}
	else {
		middle = (i + j) / 2;
		min_interval[i][j] = min(min_int(i, middle), min_int(middle, j));
		return min_interval[i][j];
	}
}

long long min_int_circ(int i, int k) {
	/*a[i], a[i-1], ..., a[i-k]の最小値*/
	if (i - k >= 0) {
		return min_int(i - k, i + 1);
	}
	else {
		return min(min_int(0, i + 1), min_int(i - k + N, N));
	}
}

int main() {
	cin >> N >> x;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N+1; i++) {
		for (int j = 0; j < N + 1; j++) {
			min_interval[i][j] = 1000000001;
		}
	}

	long long ans = 1000000000;
	ans *= 100000000;
	for (int i = 0; i < N; i++) {
		long long t = (long long)i * x;
		for (int j = 0; j < N; j++) {
			t += min_int_circ(j, i);
		}
		if (ans > t) { ans = t; }
	}

	cout << ans;
}

Measured memory_bytes: 31488
#include <stdio.h>
#include <math.h>

int judg(int x) {
  int i;
  if( x==2) return 1;
  if(x<2 || x%2==0) return 0;
  for(i=3;i<=sqrt(x);i+=2) {
    if(x%i==0) return 0;
  }
  return 1;
}
    

int main(){
  int i,in,lonely,nakama=0;

  scanf("%d",&in);

  for(i=0;i<in;i++) {
    scanf("%d",&lonely);
    if(judg(lonely)==1) nakama++;
  }

  printf("%d\n",nakama);

  return 0;
}
  



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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    priority_queue<int> pq;
    rep(i,n){
        int x;
        cin >> x;
        a.at(i) = x;
        pq.push(x);
    }
    int fs = pq.top();
    pq.pop();
    int sc = pq.top();
    rep(i,n){
        int val = (a.at(i) == fs) ? sc : fs;
        cout << val << endl;
    }
    return 0;
}

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a*b/gcd(a,b);
}


long long getDigit(long long n){
	if(n==1)return 1;
	else return log10(n)+1;
}

class Point{
public:
	long long x;
	long long y;
};
long long N,M;
vector<long long>X(100006,0);
bool isOK(long long time){
	long right=0;
	for(int i=0;i<M;i++){
		if(right>=X[i]-1){
			//go right
			right=X[i]+time;
		}else{
			if(right < X[i]-time-2)return false;
			right=max(X[i],X[i]+(time-(2*(X[i]-right)-1)));
		}
		//cout<<right<<endl;
	}
	if(right<N-1)return false;
	return true;
	
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long H,W;
	cin>>H>>W;
	char map[H][W];
	vector<bool>h(H,true);
	vector<bool>w(W,true);
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>map[i][j];
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(map[i][j]=='#')h[i]=false;
		}
	}
	for(int j=0;j<W;j++){
		for(int i=0;i<H;i++){
			if(map[i][j]=='#')w[j]=false;
		}
	}
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(h[i]==false && w[j]==false)cout<<map[i][j];
		}
		if(!h[i])cout<<endl;
	}
}


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

s = list(map(int,input().split()))
A=s[0]
B=s[1]

if A > 12:
    print(B)
elif 5 < A <= 12:
    print(int(B/2))
elif A <= 5:
    print(0)


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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=1e5+5;
int n,a[MAXN];
//int dp[5005][5005];
//int dfs(int i,int j){
//	if(dp[i][j]!=-1)return dp[i][j];
//	if(i+1>n||j>a[i+1])return dp[i][j]=(!dfs(i,j+1));
//	return dp[i][j]=(!(dfs(i+1,j)&dfs(i,j+1)));
//}
int main() {
//	srand((unsigned)time(NULL));
//	n=30;
//	for(int i=1;i<=n;++i)a[i]=rand()%20+1;
	n=read();
	for(int i=1;i<=n;++i)a[i]=read();
	sort(a+1,a+n+1);reverse(a+1,a+n+1);
	for(int i=1;i<=n+1;++i){
		if(a[i]==i){
			int j;
			for(j=i;j<=n;++j)if(a[j]!=a[i])break;
			--j;
			if((j-i+1)&1)puts("Second");
			else puts("First");
			return 0;
		}
		if(a[i]<i){
			assert(i>1);
			if(a[i]==i-1){
				int j;
				for(j=i;j<=n;++j)if(a[j]!=a[i])break;
				--j;
				bool x=((j-i+1)&1)?0:1;
				bool y=((a[i-1]-i+1)&1)?0:1;
				if(!(x&y))puts("First");
				else puts("Second");
			}else{
				if((a[i-1]-i+1)&1)puts("First");
				else puts("Second");
			}
			return 0;
		}
	}
//	for(int i=1;i<=n;++i)cout<<a[i]<<" ";cout<<endl;

//	memset(dp,-1,sizeof(dp));
//	for(int i=1;i<=n;++i){
//		int j;
//		for(j=i;j<=n;++j)if(a[j]!=a[i])break;
//		--j;
//		if((j-i+1)&1)dp[i][a[i]]=0;
//		else dp[i][a[i]]=1;
//	}
//	if(dfs(1,1))cout<<"First"<<endl;
//	else cout<<"Second"<<endl;
//	for(int i=a[1];i>=1;--i){
//		for(int j=1;j<=n;++j)if(a[j]<i)break;else cout<<dfs(j,i)<<" ";
//		cout<<endl;
//	}
	return 0;
}

Measured memory_bytes: 768
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 62
ll dp[N][3];

int main(){
	ll x;
	cin>>x;
	int s = 0;
	while((1LL<<s) <= x) s++;
	dp[s][2] = 1;
	for(int i = s-1; i >= 0; i--){
		ll t = 1&(x>>i);
		if(t==0){
			dp[i][2] += dp[i+1][2];
			dp[i][2] += dp[i+1][1];
			dp[i][1] += dp[i+1][1];
			dp[i][0] += dp[i+1][1];
			dp[i][0] += dp[i+1][0]*3;
		} else {
			dp[i][2] += dp[i+1][2];
			dp[i][1] += dp[i+1][2];
			dp[i][1] += dp[i+1][1];
			dp[i][0] += dp[i+1][1]*2;
			dp[i][0] += dp[i+1][0]*3;
		}
		rep(j, 3) dp[i][j] %= mod;
	}
	ll res = 0;
	rep(i, 3) res += dp[0][i];
	cout<<res%mod<<endl;
	return 0;
}

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

int main()
{
  string S;
  cin >> S;
  stack<char> stk, ans;
  for (int i = 0; i < (int)(S.size()); i++)
  {
    if (S.at(i) == '0')
    {
      stk.push('0');
    }
    else if (S.at(i) == '1')
    {
      stk.push('1');
    }
    else
    {
      if (!stk.empty())
      {
        stk.pop();
      }
    }
  }
  while (stk.size())
  {
    ans.push(stk.top());
    stk.pop();
  }
  while (ans.size())
  {
    cout << ans.top();
    ans.pop();
  }
  cout << endl;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V 100005

ll table[10][10];

void warshall_floyd(){
  REP(i, 10) REP(j, 10) REP(k, 10) table[j][k] = min(table[j][k], table[j][i] + table[i][k]);
}


int main() {
    int h, w;
    cin >> h >> w;

    REP(i, 10) REP(j, 10) {
        int k;
        cin >> k;
        table[i][j] = k;
    }

    warshall_floyd();
    ll ans = 0;

    REP(i, h) REP(j, w) {
        int k;
        cin >> k;
        if(k != -1) {
            ans += table[k][1];
        }
    }


    cout << ans << endl;


}
 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
template <class T>
vector<ll> countVector(vector<T>v,T guard=0){
    ll size=v.size();
    v.push_back(guard);
    vector<ll>ret;
    ll count=1;
    for(int i=0;i<size;i++){
        if(v[i]==v[i+1]){
            count++;
        }else{
            ret.push_back(count);
            count=1;
        }
    }
    return ret;
}
ll gcd(ll a,ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
	init();
	string s;cin>>s;
	ll a=(s[0]-'0')*10+(s[1]-'0');
	ll b=(s[2]-'0')*10+(s[3]-'0');
	if(0<a&&a<=12&&0<b&&b<=12)cout<<"AMBIGUOUS"<<endl;
	else if(0<a&&a<=12&&!(0<b&&b<=12))cout<<"MMYY"<<endl;
	else if(!(0<a&&a<=12)&&0<b&&b<=12)cout<<"YYMM"<<endl;
	else cout<<"NA"<<endl;
}


Measured memory_bytes: 256
hit = 'HIT'
homerun = 'HOMERUN'
out = 'OUT'


class Runer:
    def __init__(self):
        self.ini()

    def ini(self):
        self.runner = []
        self.score = 0

    def mhit(self):
        if len(self.runner) < 3:
            self.runner.append(1)
#            print self.runner, len(self.runner)

        else:
            self.score += 1
#            print self.score

    def mhomerun(self):

        self.score += len(self.runner)+1
        self.runner = []

    def getScore(self):
        return self.score




if __name__ == '__main__':

    runner = Runer()

    ining = int(raw_input())
    for i in xrange(ining):

#        print i
        outcount = 0

        while True:

            data = raw_input()

            if data == hit:
                runner.mhit()

            elif data == homerun:
                runner.mhomerun()

            elif data == out:
                outcount += 1

            if outcount >= 3:
                break


        print runner.getScore()
        runner.ini()

Measured memory_bytes: 4240
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n,x,t;cin>>n>>x>>t;
	int p = n/x;
	if(p*x<n){
		p++;
	}
	int ans = t*p;
	cout<<ans<<endl;
}

Measured memory_bytes: 3608
H,W,D=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
Q=int(input())
L,R=[],[]
for i in range(Q):
  L.append(list(map(int,input().split())))
  R.append(L[i][1])
  L[i]=L[i][0]
B=dict()
for i in range(H):
  for j in range(W):
    B[A[i][j]]=(i,j)
C=[[0,0] for i in range(D)]
for i in range(1,D):
  for j in range(i+D,H*W+1,D):
    C[i].append(C[i][-1]+abs(B[j][0]-B[j-D][0])+abs(B[j][1]-B[j-D][1]))
for j in range(D+D,H*W+1,D):
  C[0].append(C[0][-1]+abs(B[j][0]-B[j-D][0])+abs(B[j][1]-B[j-D][1]))
for i in range(Q):
  print(C[R[i]%D][(R[i]+D-1)//D]-C[L[i]%D][(L[i]+D-1)//D])

Measured memory_bytes: 108492
import collections


def solve(n, k, digits):
    digitsNotAvailable = set(digits)

    ans = n

    while True:
        temp = ans
        possible = True

        while temp:
            digit = temp % 10

            if digit in digitsNotAvailable:
                possible = False
                break

            temp //= 10

        if possible:
            return ans

        ans += 1

    return None


[n, k] = list(map(int, input().strip().split()))
digits = list(map(int, input().strip().split()))

print(solve(n, k, digits))


Measured memory_bytes: 3316
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	String s = sc.next();
      	boolean isGood = true;
      	if(s.charAt(0) == s.charAt(1)) isGood = false;
      	if(s.charAt(1) == s.charAt(2)) isGood = false;
      	if(s.charAt(2) == s.charAt(3)) isGood = false;
      	
      	if(isGood) System.out.println("Good");
      	else System.out.println("Bad");
    }
}

Measured memory_bytes: 35588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[1050][1050];
ll arr[2000][2000];
const ll mod = (long long)1e9 + 7;
int main(){
	int n,m;
	cin>>n>>m;
	for(int i = 1;i<=n;i++){
		for(int j = 1;j<=m;j++){
			char t;
			cin>>t;
			if(t == '.')arr[i][j] = 1; else arr[i][j] = 0;
		}
	}
	dp[0][1] = 1;
	dp[1][0] = 1;	
	for(int i = 1;i<=n;i++)dp[i][1] = arr[i][1] * dp[i - 1][1];
	for(int j = 1;j<=m;j++)dp[1][j] = arr[1][j] * dp[1][j - 1];
	for(int i = 2;i <= n;i++){
		for(int j = 2;j <= m;j++){
			if(arr[i][j] == 1)dp[i][j] = (dp[i - 1][j] * arr[i - 1][j] + dp[i][j - 1] * arr[i][j - 1]) % mod;
		}
		
	}

	cout<<dp[n][m];
	return 0;
}

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


int main() {
	int a,b,c,x,y;
	cin >> a >> b >> c >> x >> y;
	int sum = 0;
	int de = (x > y) ? x - y : y - x;
	if (a + b <= 2 * c) {
		cout << a * x + b * y << endl;
		return 0;
	}
	else {
		if (x > y) {
			if(a*de <= 2*c*de)
				sum += 2 * c * y + a * de;
			else
				sum += 2 * c * (y +de);

		}
		else {
			if (b*de <= 2 * c*de)
				sum += 2 * c * x + b * de;
			else
				sum += 2 * c*(x + de);
		}
	}
	cout << sum << endl;


	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 14 20:59:48 2020

@author: Kanaru Sato
"""

nums = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(nums[K-1])

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
using namespace std;
int A[100001];
int B[50001];
bool BSearch(int A[],int n,int key){
    int left = 0;
    int right = n;
    while(left<=right){
        int mid = (left+right)/2;
        if(A[mid]==key){
            return true;
        }else if(A[mid]>key){
            right = mid-1;
        }else{
            left = mid+1;
        }
    }
    return false;
}
int main()
{
    int n1,n2,q,num=0;
    cin>>n1;
    for(int i=0;i<n1;i++){
        scanf("%d",&A[i]);
    }
    cin>>n2;
    for(int i=0;i<n2;i++){
        scanf("%d",&q);
        if(BSearch(A,n1,q)) num++;
    }
    cout<<num<<endl;
    return 0;
}



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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N; ll T; cin >> N >> T;

  ll d;
  cin >> d;
  assert(d == 0);

  pair<ll, ll> p {0, T};
  ll ans = 0;  
  rep(i, N - 1) {
    ll t; cin >> t;
    if (p.second < t) {
      // Split
      ans += p.second - p.first;
      p = std::make_pair(t, t + T);
    } else {
      // Merge
      p = std::make_pair(p.first, t + T);
    }
  }

  ans += p.second - p.first;

  std::cout << ans << "\n";
  
  return 0;
}

Measured memory_bytes: 256
def solve():
  n=int(input())
  a=list(map(int,input().split()))
  s=input()
  base=[]
  for i in range(n-1,-1,-1):
    v=a[i]
    for x in base:
      v=min(v,v^x)
    if v:
      if s[i]=='0':
        base.append(v)
      else:
        return 1
  return 0

def main():
  t=int(input())
  for _ in range(t):
    print(solve())

if __name__ == '__main__':
  main()

Measured memory_bytes: 73916
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009
using namespace std;
typedef long long lli;
#define int long long
const int NMAX = 100005;
int parent[NMAX];
int size[NMAX];

int get_parent(int a){
	if(parent[a] == a) return a;
	return parent[a] = get_parent(parent[a]);
}

signed main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for(int i=0; i<n; i++){
		parent[i] = i;
		size[i] = 1;
	}
	vector <pii> edges(m);
	for(int i=0; i<m; i++){
		int x, y;
		cin >> x >> y;
		edges[i] = {x, y};
	}

	reverse(ALL(edges));
	int ans = n*(n-1) / 2;
	vector <int> res;
	for(int i=0; i<m; i++){
		res.pb(ans);
		int para = get_parent(edges[i].fi);
		int parb = get_parent(edges[i].sc);
		if(para != parb){
			ans -= size[para] * size[parb];
			parent[para] = parb;
			size[parb] += size[para];
		}
	}

	reverse(ALL(res));
	for(int i: res) cout << i << endl;

	return 0;
}

Measured memory_bytes: 5364
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int k,a;
  int r[n][m];
  for(int i=0;i<n;++i){
    for(int j=0;j<m;++j){
      r[i][j]=0;
    }
  }
  for(int i=0;i<n;++i){
    cin>>k;
    for(int j=0;j<k;++j){
      cin>>a;
      r[i][a-1]=1;
    }
  }
  int ans=0;
  bool flag;
  for(int j=0;j<m;++j){
    flag = true;
    for(int i=0;i<n;++i){
      if(r[i][j]==0){
        flag = false;
      }
    }
    if(flag){ ans++; }
  }
  cout<<ans;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TwoIntegers solver = new TwoIntegers();
        solver.solve(1, in, out);
        out.close();
    }

    static class TwoIntegers {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt(), y = in.nextInt();
            if (x % y == 0) out.println(-1);
            else out.println(x);
        }

    }

    static class InputReader {
        private StringTokenizer tokenizer;
        private BufferedReader reader;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main(){
    long long n, m;
    cin >> n >> m;

    vector<bool> red(n, false);
    vector<long long> s(n, 1);

    red[0] = true;
    for(long long i = 0; i < m; i++){
        long long x, y;
        cin >> x >> y;
        x--;
        y--;

        if(red[x] == false){
            s[x]--;
            s[y]++;
        }
        else{
            red[y] = true;
            s[x]--;
            s[y]++;
            if(s[x] == 0) red[x] = false;
        }
    }

    long long cnt = 0;

    for(long long i = 0; i < n; i++){
        if(red[i] == true) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3944
import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  static int N;
  static ArrayList<Integer> original;

  public static void main(String[] args) {
    N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();

    original = new ArrayList(N);

    for (int i=0; i<N; i++) {
      original.add(sc.nextInt());
    }

    int minMP = Integer.MAX_VALUE;

    minMP = Math.min(minMP, g(new ArrayList(original), A, B, C));
    minMP = Math.min(minMP, g(new ArrayList(original), A, C, B));
    minMP = Math.min(minMP, g(new ArrayList(original), B, A, C));
    minMP = Math.min(minMP, g(new ArrayList(original), B, C, A));
    minMP = Math.min(minMP, g(new ArrayList(original), C, A, B));
    minMP = Math.min(minMP, g(new ArrayList(original), C, B, A));

    System.out.println(minMP);

  }

  static int h(ArrayList<Integer> ls, int len) {
    int index = -1;
    int minDif = Integer.MAX_VALUE;

    for (int i = 0; i < ls.size(); i++) {
      int dif = Math.abs(ls.get(i) - len);
      if (dif < minDif) {
        index = i;
        minDif = dif;
      }
    }

    ls.remove(index);

    return minDif;

  }

  static int g(ArrayList<Integer> ls, int a, int b, int c) {

    int min = Integer.MAX_VALUE;

    if (ls.size() > 3) {
      for (int i = 0; i < ls.size(); i++) {
        for (int j = i + 1; j < ls.size(); j++) {
          ArrayList<Integer> copyList = new ArrayList(ls);
          copyList.set(i, copyList.get(i) + copyList.get(j));
          copyList.remove(j);
          min = Math.min(min, 10 + g(copyList, a, b, c));
        }
      }
    }

    return Math.min(min, h(ls, a) + h(ls, b) + h(ls, c));
  }

}

Measured memory_bytes: 98772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAX=105;
int H,W,N,a[MAX*MAX],field[MAX][MAX];
int main(){
    scanf("%d%d",&H,&W);
    scanf("%d",&N);
    for(int i=1;i<=N;i++) scanf("%d",&a[i]);
    int pt=1;
    for(int i=0;i<H;i++){
        for(int j=(i&1)*(W-1);j>=0&&j<W;j+=1-2*(i&1)){
            if(a[pt]==0) pt++;
            field[i][j]=pt; a[pt]--;
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++) printf("%d ",field[i][j]);
        printf("\n");
    }
    printf("\n");

}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;


int main(void){
    int n;
    cin>>n;
    vector<ll>a(3*n);
    for(int i=0;i<3*n;i++)cin>>a[i];
    sort(a.begin(),a.end(),greater<ll>());
    ll ans = 0;
    for(int i=1;i<2*n;i+=2){
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

using namespace std;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main(){
    int n, m; cin >> n >> m;
    set<int> ac;
    unordered_map<int, int> wa;
    vector<int> p(m);
    vector<string> s(m);
    rep(i, m) {
        cin >> p[i] >> s[i];
        if(s[i] == "AC"){
            ac.insert(p[i]);
        }
        else {
            if(ac.find(p[i]) != ac.end())
                continue;
            if(wa.find(p[i]) != wa.end()) {
                wa[p[i]]++;
            } else {
                wa[p[i]] = 1;
            }
        }
    }
    // for(auto it = ac.begin(); it!=ac.end(); it++) {
    //     cout << *it << endl;
    // }
    ll acs = 0;
    ll was = 0;
    for(int i = 1; i < n+1; i++) {
        if(ac.find(i) != ac.end()) {
            acs++;
        if(wa.find(i) != wa.end()) {
            was += wa[i];
        }
        }
    }
    cout << acs << " " << was << endl;
}


Measured memory_bytes: 10752
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"3 70
7 60
1 80
4 50"# => "4",
}

// 23, 0, 10, 10, 10

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize, t: usize,
        mut ct: [(usize, usize); n],
    }
    let mut ans = "TLE".to_string();
    ct.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap());
    for i in 0..n {
        if ct[i].1 <= t {
            ans = ct[i].0.to_string();
            break;
        }
    }
    ans
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int k;
  cin >> k;
  vl a(k);
  vl ma(k + 1), mi(k + 1);
  REP(i, k) { cin >> a[i]; }
  if (a[k - 1] != 2) {
    cout << -1 << endl;
    return 0;
  }

  ma[k] = 2;
  mi[k] = 2;
  for (int i = k - 1; i >= 0; i--) {
    ma[i] = (ma[i + 1] / a[i]) * a[i];
    mi[i] = ((mi[i + 1] + a[i] - 1) / a[i]) * a[i];
    if (ma[i] < mi[i + 1] || mi[i] > ma[i + 1]) {
      cout << -1 << endl;
      return 0;
    }
    ma[i] += a[i] - 1LL;
  }

  cout << mi[0] << " " << ma[0] << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  long int ans = 0;
  cin >> N;
  vector<int> a(N);
  for(int i = 0;i < N;i++){
    cin >> a[i];
  }
  for(int j = 0;j < N-1;j++){
    if(a[j] > a[j+1]){
      ans += a[j] - a[j+1];
      a[j+1] = a[j];
    } 
  }
  cout << ans;
  
  
  return 0;
}

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

using namespace std;

const int MAXN = 200100;

int cnt[MAXN];
int arr[MAXN];

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

    int n;

    memset(cnt, 0, sizeof(cnt));

    cin >> n;

    long long sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        sum += cnt[arr[i]];
        cnt[arr[i]]++;
    }
    
    for (int i = 0; i < n; i++) {
        cout << sum - cnt[arr[i]] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 4224
function main()
    K = pread(Int)
    for i in 1:K
        print("ACL")
    end
    println()
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()


Measured memory_bytes: 180720
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

visit = [0] * (n + 1)


def dfs(now, depth):
    if visit[now]:
        return 0
    if depth == n:
        return 1

    count = 0
    visit[now] = 1
    if graph[now]:
        for i in graph[now]:
            count += dfs(i, depth + 1)
    visit[now] = 0

    return count


ans = dfs(1, 1)
print(ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
	static int a[5][65536]={1};
	for(int i=1;i<=256;i++)
		for(int j=i*i;j<65536;j++)
			for(int k=0;k<4;k++)
				a[k+1][j]+=a[k][j-i*i];
	for(int n;cin>>n,n;)
		cout<<a[1][n]+a[2][n]+a[3][n]+a[4][n]<<endl;
	
	return 0;
}

Measured memory_bytes: 2440
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=LONG_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int n,m,cnt[nmax],i,x,y;
int main()
{
	//freopen("sol.in","r",stdin);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>m;
	while(m--)
	{
		cin>>x>>y;
		cnt[x]++,cnt[y]++;
	}
	for(i=1;i<=n;i++)if(cnt[i]&1)rc("NO");
	rc("YES");
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>

using namespace std;

int N;
vector<int> edge[1001];
bool used[1001];
int X[1001];

pii DFS(int v){
    used[v]=true;
    if(edge[v].size()==1&&v!=1)return {0,X[v]};

    vector<pii> wb;
    int sum=0;
    for(int u : edge[v])if(!used[u])wb.push_back(DFS(u));
    bool dp[wb.size()+1][X[v]+1];
    fill(dp[0],dp[wb.size()+1],false);
    dp[0][0]=true;
    REP(i,wb.size()){
        sum+=wb[i].first+wb[i].second;
        REP(j,X[v]+1){
            if(dp[i][j]){
                if(j+wb[i].first<= X[v])dp[i+1][j+wb[i].first] =true;
                if(j+wb[i].second<=X[v])dp[i+1][j+wb[i].second]=true;
            }
        }
    }

    for(int i=X[v];i>=0;i--){
        if(dp[wb.size()][i]){
            return {X[v],sum-i};
        }
    }
    return {10000,10000};
}


int main(){

    cin>>N;
    REP(i,N-1){
        int p;cin>>p;
        edge[i+2].push_back(p);
        edge[p].push_back(i+2);
    }
    fill_n(used,N+1,false);
    REP(i,N)cin>>X[i+1];
    if(DFS(1)==make_pair(10000,10000))cout<<"IMPOSSIBLE"<<endl;
    else cout<<"POSSIBLE"<<endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<queue>
#define CMAX -1
using namespace std;

int cost[101][101];
int maxc[101];

class datum {
public:
	int cost;
	int wheres;
	datum(int c, int w) {cost = c; wheres = w;};
};

bool operator<(const datum &a, const datum &b) {
	return a.cost > b.cost;
}
bool operator>(const datum &a, const datum &b) {
	return a.cost < b.cost;
}


int main () {
	for (;;) {
		int n,k;
		int cmd;
		int x,y;
		int tcost;
		int start, end;
		cin >> n >> k;

		if ( n == 0 )
			break;

		for ( int i=0; i<=n; i++ ) {
			for ( int j=0; j<=n; j++ ) {
				cost[i][j] = 0;
			}
		}

		for ( int i=0; i<k; i++ ) {
			cin >> cmd;
			if ( cmd == 1 ) {
				cin >> x >> y >> tcost;
				if ( cost[x][y] == 0 || cost[x][y] > tcost ) {
				cost[x][y] = tcost;
				cost[y][x] = tcost;
				}
			}
			else {
				cin >> start >> end;

				priority_queue<datum> q;
				q.push(datum(0,start));

				for ( int j=1; j<=n; j++ ) {
					maxc[j] = CMAX;
				}

				bool found = false;
				int finalcost = 0;

				while(!q.empty()) {
					datum now = q.top();
					q.pop();
					if ( now.wheres == end ) {
						found = true;
						finalcost = now.cost;
						break;
					}

					for ( int j=1; j<=n; j++ ) {
						if ( cost[now.wheres][j] != 0 ) {
							if ( maxc[j] == CMAX || maxc[j] > (now.cost + cost[now.wheres][j])) {
								maxc[j] = now.cost+cost[now.wheres][j];
								q.push(datum(now.cost+cost[now.wheres][j],j));
							}
						}
					}
				}
				if ( found )
					cout << finalcost << endl;
				else
					cout << -1 << endl;
			}
		}
	}
}

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

int main()
{
    int n;
    scanf("%d",&n);
    long long temp[n + 1];
    int cnt = 0;
    for(int i = 1;i <= n;i++){
        scanf("%lld",&temp[i]);
        if(temp[i] % 2 == 1){
            cnt++;
        }
    }
    //printf("%d",cnt);
    if(cnt % 2 == 0)
    printf("YES");
    else printf("NO");
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
    int a[3],i,j,t;
    for(i=0;i<3;i++)scanf("%d",&a[i]);
    for(i=0;i<2;i++){
        for(j=2;j>i;j--){
            if(a[j]<a[j-1]){
                t=a[j];
                a[j]=a[j-1];
                a[j-1]=t;
            }
        }
    }
    printf("%d",a[2]-a[1]+(a[1]-a[0]));
    return 0;
}

Measured memory_bytes: 128
import heapq
n,k=list(map(int,input().split()))
h=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(h)
if k>len(h):k=len(h)
for i in range(k):
  heapq.heappop(h)
print(-sum(h))

Measured memory_bytes: 25896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define SWAP(a, b) (a += b,b = a - b,a -= b)
#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define urng(i, a, b) for(int i = int(b) - 1; i >= int(a); i--)
#define urep(i, b) urng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
 
main() {
  int n, a, b;
  ll ans = 2, h;
  //string s;
  cin >> h;
  //vector<int> v(n), c(n);
  rep(i, 40){
    if(h < ans) break;
    ans *= 2;
  }
  cout << ans - 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) if (debug) cout << #x << " = " << (x) << endl;

const int debug = 0;

int sz = 0;
long long sum_d = 0;
vector<int> cnt;
long long kinds = 0;

void modify(int t, int d, int sig) {
  if (debug) cout << "modiy " << t << " " << d << " " << sig << endl;
  sz += 1 * sig;
  sum_d += d * sig;
  cnt[t] += 1 * sig;
  if (sig == 1 and cnt[t] == 1) {
    kinds++;
  }

  D(sz); D(sum_d); D(cnt[t]); D(kinds);
}

int main() { IO;
  int n, k;
  cin >> n >> k;

  vector<pair<int, int>> v(n);
  for (auto &p : v) cin >> p.second >> p.first;
  sort(v.begin(), v.end(), greater<pair<int, int>>());

  if (debug) {
    cout << "new order:" << endl;
    for (auto &p : v) cout << p.second << " " << p.first << endl;
    cout << "--" << endl;
  }

  cnt.resize(v.size() + 1);
  for (int i = 0; i < k; ++i) {
    int t = v[i].second;
    int d = v[i].first;

    modify(t, d, 1);
  }

  int i = k - 1;
  int j = k;
  long long ans = sum_d + kinds * kinds;
  D(ans);

  while (sz == k) {
    while (i >= 0 and sz == k) {
      int t = v[i].second;
      int d = v[i].first;
      if (cnt[t] > 1) {
        modify(t, d, -1);
      }

      i--;
    }

    if (sz == k) {
      break;
    }

    while (j < n and sz < k) {
      int t = v[j].second;
      int d = v[j].first;
      if (cnt[t] == 0) {
        modify(t, d, 1);
      }

      j++;
    }

    if (sz < k) {
      break;
    }

    ans = max(ans, sum_d + kinds * kinds);
    D(sum_d + kinds * kinds);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;


#define PB push_back
#define MP make_pair
#define F first
#define S second

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll n;
	cin >> n;
	if(n%10==3){
		cout << "bon";
	}else if(n%10 == 0 || n%10 == 1 || n%10 == 6  || n%10 == 8){
		cout << "pon";
	}else{
		cout << "hon";
	}
	cout << endl;
	return 0;
 }

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<ll,pair<ll,ll> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000+7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e18+5LL
# define LN 20  
typedef pair<ll,pair<ll,ll> > pii;
# define INF1 (int)1e9+2
# define maxn 300006
# define offset 1005

/*************************************************
struct Coupon {
    ll l;
    ll r;
    ll id;

    Coupon(ll l, ll r, ll id): l(l), r(r), id(id) {} // Initialization

    bool operator<(const Coupon& c) { // Sorting
        return l < c.l;    
    }
};

**************************************************/
ll dp[55];
vi v;
string s[2];

int main()
{
  IOS;
  int n;
  cin >> n;
  cin >> s[0];
  cin >> s[1];

  for(int i=0;i<n;i++)
  {
    //trace1(i);
    if(s[0][i]==s[1][i])
    {
      v.pb(1);
    }
    else
    {
      v.pb(2);
      i++;
    }
  }

  dp[0]=3;
  if(v[0]==2)
    dp[0]=6;

  for(int i=1;i<v.size();i++)
  {
    if(v[i]==1 && v[i-1]==1)
       dp[i]=(dp[i-1]*2)%mod;
    if(v[i]==1 && v[i-1]==2)
       dp[i]=(dp[i-1]);
    if(v[i]==2 && v[i-1]==1)
       dp[i]=(dp[i-1]*2)%mod;
    if(v[i]==2 && v[i-1]==2)
       dp[i]=(dp[i-1]*3)%mod;
  }
  cout << dp[v.size()-1];
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll cnt[50][20][20];

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

  ll n;
  cin>>n;
  vector<ll> a(n),b(n,0);
  rep(i,n){
    string s;
    cin>>s;
    bool update=false;
    rep(j,s.size()){
      if(s[j]=='.'){
        update=true;
        for(ll k=s.size()-1;k>=j;k--){
          if(s[k]!='0'){
            b[i]=k-j;
            break;
          }
        }
        if(b[i]==0){
          a[i]=stoll(s.substr(0,j));
        }else{
          a[i]=stoll(s.substr(0,j))*pow(10LL,b[i])+stoll(s.substr(j+1,b[i]));
        }
      }
    }
    if(!update){
      a[i]=stoll(s.substr(0,s.size()));
    }
  }

  vector<ll> x(n,0),y(n,0),z(n,0);
  ll res=0,B=9;
  rep(i,n){
    z[i]=-b[i];
    while(a[i]%10==0){
      a[i]/=10;
      z[i]++;
    }
    while(a[i]%2==0){
      a[i]/=2;
      x[i]++;
    }
    while(a[i]%5==0){
      a[i]/=5;
      y[i]++;
    }
    cnt[x[i]][y[i]][z[i]+B]++;
    if(min(2*x[i],2*y[i])+2*z[i]>=0){
      res--;
    }
  }

  rep(xx,50){
    rep(yy,20){
      repl(zz,-9,10){
        if(cnt[xx][yy][zz+B]==0)continue;
        rep(nx,50){
          rep(ny,20){
            repl(nz,-9,10){
              if(min(xx+nx,yy+ny)+zz+nz>=0){
                res+=cnt[xx][yy][zz+B]*cnt[nx][ny][nz+B];
              }
            }
          }
        }
      }
    }
  }

  cout<<res/2<<endl;

  return 0;
}


Measured memory_bytes: 11420
// mod custom_lib;

use std::io::*;
use std::str::FromStr;

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

fn main() {
  let a = read::<u32>();
  let b = read::<u32>();

  if a >= 13 {
    println!("{}", b)
  } else if a >= 6 {
    println!("{}", b / 2)
  } else {
    println!("{}", 0)
  }
}


Measured memory_bytes: 4352