akhauriyash/Code-Regression huggingface dataset:
/**
 * File:  insertion.c
 * Author: ymiyamoto
 *
 * Created on Fri Apr 21 15:42:44 2017
 */

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#define BUF_SIZE 100

#define SWAP(a, b)                                                                                                                         \
  {                                                                                                                                        \
    typeof(a) _x = a;                                                                                                                      \
    a = b;                                                                                                                                 \
    b = _x;                                                                                                                                \
  }

void print_arr(int32_t buf[], size_t size)
{
  int32_t i;
  for (i = 0; (size_t)i < size; i++) {
    if (i != 0) {
      printf(" ");
    }
    printf("%d", buf[i]);
  }
  printf("\n");

  return;
}

void insertion_sort(int32_t buf[], size_t size)
{
  uint8_t i;
  for (i = 0; i < size; i++) {
    uint8_t j;
    for (j = i; 0 < j; j--) {
      if (buf[j - 1] > buf[j]) {
        SWAP(buf[j - 1], buf[j]);
      }
    }
    print_arr(buf, size);
  }

  return;
}

#if !defined(TEST)
int32_t main(void)
{
  int32_t num;
  scanf("%d", &num);

  int32_t buf[BUF_SIZE];

  uint8_t i;
  for (i = 0; i < num; i++) {
    scanf("%d", &buf[i]);
  }

  insertion_sort(buf, (size_t)num);

  return 0;
}
#endif

Measured memory_bytes: 604
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int x,ans;
			x=cin.nextInt();
			if(x==0){
				break;
			}
				x=1000-x;
				ans=x/500;
				x=x%500;
				ans=ans+x/100;
				x=x%100;
				ans=ans+x/50;
				x=x%50;
				ans=ans+x/10;
				x=x%10;
				ans=ans+x/5;
				x=x%5;
				ans=ans+x;
				System.out.println(ans);
		}
		
			

	}

}

Measured memory_bytes: 17156
#include <bits/stdc++.h> 
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef double ld;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
const ll MOD = 1e9 + 7 ;
const ll INF=1e17;																									
ll mpow(ll a,ll b){a=a%MOD;ll res=1;while(b>0){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b=b>>1;}return res%MOD;}             

int main()
{ 
ios_base::sync_with_stdio(false);
cin.tie(NULL);
///freopen("input.txt", "r", stdin);
ll n;
cin>>n;
ll maxi=-1e13;
ll mini=1e13;
forn(i,n)
{
  ll x;
  cin>>x;
   maxi=max(maxi,x);
   mini=min(mini,x);
}
cout<<maxi-mini;
return 0;    
} 

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

using namespace std;
// (]  >=
int main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (auto & y: a) {
        cin >> y;
    }
    int64_t ans = 0;
    for (int i = 1; i < n; ++i) {
        if (a[i - 1] + a[i] > x) {
            int val = a[i - 1] - x + a[i];
            a[i] = max(0, a[i] - val);
            ans += val;
        }
    }
    cout << ans;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define INF 1 << 30

using namespace std;

int main()
{
  int n, m; cin >> n >> m;
  vector<int> c(m);
  vector<int> T(n+1,INF);
  T[0] = 0;
  REP(i,m) cin >> c[i];
  REP(i,m) FOR(j,c[i],n)
    T[j] = min(T[j],T[j-c[i]]+1);
  cout << T[n] << endl;
}

Measured memory_bytes: 3116
import java.util.ArrayDeque;
import java.util.Deque;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] hwn = br.readLine().split(" ");
        int h = Integer.parseInt(hwn[0]);
        int w = Integer.parseInt(hwn[1]);
        int n = Integer.parseInt(hwn[2]);
        char[][] grid = new char[h][w];
        int sx=-1, sy=-1;
        
        for (int i = 0; i < h; i++) {
            String raw = br.readLine();
            for (int j = 0; j < w; j++) {
                grid[i][j] = raw.charAt(j);
                if (grid[i][j] == 'S') {
                    sy = i;
                    sx = j;
                }
            }
        }
        
        int next = 1;
        int[][] dfyxs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
        boolean[][] visited = new boolean[h][w];
        visited[sy][sx] = true;
        int[][] distance = new int[h][w];
        distance[sy][sx] = 0;
        Deque<Integer> xq = new ArrayDeque<Integer>();
        Deque<Integer> yq = new ArrayDeque<Integer>();
        int d = 0;
        int ans = 0;
        outer: while (true) {
            inner: for (int[] dfyx: dfyxs) {
                if (sy-dfyx[0] < 0 || sx-dfyx[1] < 0 || sy-dfyx[0] >= h || sx-dfyx[1] >= w) continue;
                if (visited[sy-dfyx[0]][sx-dfyx[1]] == true) continue;
                if (grid[sy-dfyx[0]][sx-dfyx[1]] == 'X') {
                    continue;
                }
                distance[sy-dfyx[0]][sx-dfyx[1]] = distance[sy][sx] + 1;
                //System.out.println((sy-dfyx[0]) + " " + (sx-dfyx[1]));
                if ((int)grid[sy-dfyx[0]][sx-dfyx[1]]-48 == next) {
                    //System.out.println("aaa");
                    //System.out.println(distance[sy-dfyx[0]][sx-dfyx[1]]);
                    yq.clear();
                    xq.clear();
                    ans += distance[sy-dfyx[0]][sx-dfyx[1]];
                    if (next == n) break outer;
                    next++;
                    distance = new int[h][w];
                    distance[sy-dfyx[0]][sx-dfyx[1]] = 0;
                    visited = new boolean[h][w];
                    sy = sy-dfyx[0];
                    sx = sx-dfyx[1];
                    continue outer;
                }
                visited[sy-dfyx[0]][sx-dfyx[1]] = true;
                xq.addLast(sx-dfyx[1]);
                yq.addLast(sy-dfyx[0]);
            }
            sy = yq.removeFirst();
            sx = xq.removeFirst();
        }
        //System.out.println(distance[3][1]);
        System.out.println(ans);
    }
}



Measured memory_bytes: 86540
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra


class Graph(object):

    def __init__(self, K):
        self.K = K
        self.weights = {}

    def add(self, node1, node2, weight):
        if (node1, node2) in self.weights:
            self.weights[(node1, node2)] = min(self.weights[(node1, node2)], weight)
        else:
            self.weights[(node1, node2)] = weight

    def to_csr(self):
        n1, n2, w = [], [], []
        for (node1, node2), weight in self.weights.items():
            n1.append(node1)
            n2.append(node2)
            w.append(weight)
        return csr_matrix((w, (n1, n2)), shape=(self.K, self.K))


K = int(input())
g = Graph(K)

for i in range(K):
    if i == K - 1:
        g.add(i, 0, 1)
    else:
        g.add(i, i + 1, 1)
    g.add(i, (i * 10) % K, 10**(-8))

d = dijkstra(g.to_csr(), directed=True, indices=1)
print(int(d[0]) + 1)

Measured memory_bytes: 64512
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 5100
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
const double PI = acos(-1);

int main(){
    int N;
    ll a[1100],K;
    cin>>N>>K;
    for(int i=0;i<N;i++) cin>>a[i];

    vector<ll> V,ans[50];
    for(int i=0;i<N;i++){
        ll temp=0;
        for(int j=0;i+j<N;j++){
            temp+=a[i+j];
            V.push_back(temp);
            ans[0].push_back(temp);
        }
    }
    int t=45;
    ll x=1;
    while(t--){
        x*=2;
    }
    bool hantei[1100000];
    ll ret=0;
    for(int i=0;x!=0;i++,x/=2){
        int count=0;
        for(int j=0;j<(int)ans[i].size();j++){
            if(ans[i][j]>=x){
                ans[i][j]-=x;
                count++;
                hantei[j]=true;
            }else hantei[j]=false;
        }
        if(count>=K){
            ret+=x;
            for(int j=0;j<(int)ans[i].size();j++){
                if(hantei[j]) ans[i+1].push_back(ans[i][j]);
            }
        }else{
            for(int j=0;j<(int)ans[i].size();j++){
                ans[i+1].push_back(ans[i][j]);
            }
        }


    }
    cout<<ret<<endl;
}



Measured memory_bytes: 48860
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

int main(){
    int h,w;
    cin>>h>>w;
    int startx,starty,endx,endy;
    cin>>startx>>starty>>endx>>endy;
    startx--,starty--,endx--,endy--;

    char s[h][w];
    rep(i,h) rep(j,w) cin>>s[i][j];

    int cnts[h][w];
    rep(i,h) rep(j,w) cnts[i][j]=INF;
    queue<pair<int,int>> q,visited;
    q.push({startx,starty});
    cnts[startx][starty]=0;

    while(!q.empty() || !visited.empty()){
        int nowx,nowy;
        if(!q.empty()){
            nowx=q.front().first,nowy=q.front().second;
            visited.push({nowx,nowy});
            q.pop();
            rep(i,4){
                int nx=nowx+dx[i],ny=nowy+dy[i];
                if(0<=nx && nx<h && 0<=ny && ny<w && s[nx][ny]!='#' && cnts[nowx][nowy]<cnts[nx][ny]){
                    cnts[nx][ny]=cnts[nowx][nowy];
                    q.push({nx,ny});
                }
            }
        }
        else{
            nowx=visited.front().first,nowy=visited.front().second;
            visited.pop();
            for(int i=-2;i<=2;i++){
                for(int j=-2;j<=2;j++){
                    int nx=nowx+i,ny=nowy+j;
                    if(0<=nx && nx<h && 0<=ny && ny<w && s[nx][ny]!='#' && cnts[nowx][nowy]+1<cnts[nx][ny]){
                        cnts[nx][ny]=cnts[nowx][nowy]+1;
                        q.push({nx,ny});
                    }
                }
            }
        }
    }

    if(cnts[endx][endy]==INF) cout<<-1<<endl;
    else cout<<cnts[endx][endy]<<endl;
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,ans=0;
	cin>>n>>k;
	while(n>=k)
	{
		ans+=1;
		n/=k;
	} 
	ans+=1;
	cout<<ans<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int x;
  cin >> x;
  
  for(int i = -140; i <= 140; ++i){
    for(int j = -140; j <= 140; ++j){
      if(pow(i, 5.0) - pow(j, 5.0) == x){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
#define SIZE 16
vector<pll> arr[SIZE];

bool check(ll mask,ll n){
	// cout<<mask<<" ";
	set<ll> s[n];
	for(ll i=0;i<n;++i){
		s[i].insert((mask>>i)&1);
	}
	for(ll i=0;i<n;++i){
		// cout<<(mask>>i&1)<<" ";
		for(auto p:arr[i]){
			if((mask>>i)&1){
				s[p.first-1].insert(p.second);
			}
		}
	}
	for(ll i=0;i<n;++i){
		// cout<<i<<","<<s[i].size()<<" ";
		if(s[i].size()>1){
			// cout<<endl;
			return false;
		}
	}
	return true;
}


int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n;
	cin>>n;
	for(ll i=0;i<n;++i){
		ll a;
		cin>>a;
		for(ll j=0;j<a;++j){
			ll p,q;
			cin>>p>>q;
			arr[i].pb(mp(p,q));
		}
	}
	ll MAX=1<<n;
	ll ans=0;
	for(ll i=1;i<MAX;++i){
		if(check(i,n)){
			// cout<<ans<<endl;
			ans=max(ans,(ll)__builtin_popcountll(i));
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <numeric>
#include <iomanip>
#include <climits>
#include <cstring>
#include <cmath>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define rrep(i, n) for (int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for (int i=(int)(n);i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=(int)(r)-1;i>=l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using vpii=vector<pii>;
using ll=long long;

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}
template<typename T>bool chmin(T&a,T b){return a>b?(a=b,1):0;}
template<typename T>bool chmax(int&a,int b){return a<b?(a=b,1):0;}
int read(){int a;scanf("%lld",&a);return a;}

const double pi = acos(-1);
constexpr int inf = 3*TEN(18) + 10;

signed main()
{
	int N,A,B; cin >> N >> A >> B;
	vi X(N);
	rep(i, N) cin >> X[i];

	int ans = 0, cur = X[0];
	rep(i, N - 1) {
		ans += min((X[i + 1] - cur) * A, B);
		cur = X[i + 1];
	}

	cout << ans << endl;
}




Measured memory_bytes: 1024
#include <stdio.h>
#define mod 1000000007
#define LL long long
LL n,a,b;
LL quick_pow(LL a,LL b){
	LL ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
LL C(LL a,LL b){
	LL i,ans=1,c=1;
	for(i=a;i>=a-b+1;i--)ans=ans*i%mod;
	for(i=b;i>=1;i--)c=c*i%mod;
	return ans*quick_pow(c,mod-2)%mod;
}
int main(){
	LL ans=0;
	scanf("%lld%lld%lld",&n,&a,&b);
	ans+=quick_pow(2,n)-1;//全集
	ans-=C(n,a);
	ans-=C(n,b);
	ans=(ans%mod+mod)%mod;//ans=(ans+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;//溢出会变成负值 
typedef long double ldb;
typedef unsigned long long ull;//自动取模2^64
const double pi=acos(-1.0);
const int mod = 1e9+7; // 998244353;
const int inf = 0x7fffffff;//2^31-1
const ll INF = 0x7fffffffffffffff;
const int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
//ll begin_time=clock();    ll end_time=clock();  cout<<"time = "<<end_time-begin_time<<" ms!"<<endl;
//bool operator < (const mmp &a) const{return x<a.x||x==a.x&&y<a.y;}       //map<int,map<int,int> >z;
//map<int,int>::iterator it;for(it=z.begin();it!=z.end();it++)printf("%d %d\n",it->first,it->second);
//ll poww(ll a,ll b){ll s=1;while(b){if(b&1)s=(s*a)%mod;a=(a*a)%mod;b>>=1;}return s%mod;}  //快速幂取模 
//lower_bound(begin,end,num); 第一个>=num的数字  upper_bound(begin,end,num); 第一个>num的数字 返回地址 
//freopen("input.in","r",stdin);     freopen("output.out","w",stdout);      //文件读写提交 
//reverse(s.begin(),s.end());   //反转字符串        floor(); 向下取整  ceil(); 向上取证 
//数轴上n个点移动到同一位置，移动到该组数字的中位数的总距离最短 
bool isPrime(int n){if(n==2||n==3)return 1;if(n%6!=1&&n%6!=5)return 0;
int t=sqrt(n);for(int i=5;i<=t;i+=6)if(n%i==0||n%(i+2)==0)return 0;return 1;}//判断素数 

int z[100005];
int x[100005];
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	ll a,b,c,d,e,f,g,T;  
//	cin>>T;
	//while(T--)
	{
		cin>>a;
		memset(z,0,sizeof(z));
		b=0;
		for(int i=0;i<a;i++)
		{
			cin>>x[i];
			b+=x[i];
			z[x[i]]++;
		}
		cin>>T;
		while(T--)
		{
			cin>>c>>d;
			b-=z[c]*c;
			b+=z[c]*d;
			z[d]+=z[c];
			z[c]=0;
			cout<<b<<endl;
		}
		
	}
	
}



Measured memory_bytes: 4440
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<30;
const int MOD = 1000000007;

void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

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


// グラフ
using Edge = pair<int,long long>; // {辺の行き先, 重み}
using Graph = vector<vector<Edge> >; // グラフ

// 使われうる辺集合
set<pair<int,int> > use;

// s を始点とする Dijkstra
vector<long long> Dijkstra(const Graph &G, int s) {
    vector<long long> dist((int)G.size(), INF);
    vector<vector<int> > prev((int)G.size()); // prev[v] := v から復元できる辺たち
    dist[s] = 0;
    priority_queue<pair<long long,int>, vector<pair<long long,int> >, greater<pair<long long,int> > > que;
    que.push({0, s});
    while (!que.empty()) {
        auto cur = que.top(); que.pop();
        long long cur_dist = cur.first;
        int v = cur.second;
        if (cur_dist > dist[v]) continue; // 効く枝刈り
        for (auto e : G[v]) {
            if (dist[e.first] > dist[v] + e.second) {
                dist[e.first] = dist[v] + e.second;
                que.push({dist[e.first], e.first});

                // 復元のための
                prev[e.first].clear();
                prev[e.first].push_back(v);
            }
            else if (dist[e.first] == dist[v] + e.second) {
                prev[e.first].push_back(v);
            }
        }
    }

    // 使われうる辺集合
    for (int v = 0; v < (int)G.size(); ++v) {
        for (auto u : prev[v]) {
            use.insert(make_pair(min(u, v), max(u, v)));
        }
    }
    return dist;
}

int main() {
    int N, M; cin >> N >> M;
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b; long long c;
        cin >> a >> b >> c;
        --a, --b;
        G[a].push_back(Edge(b, c));
        G[b].push_back(Edge(a, c));
    }
    for (int v = 0; v < N; ++v) Dijkstra(G, v);
    cout << M - (int)use.size() << endl;
}

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

int main() {
  int N;
  cin >> N;
  //cout << M << endl;*/

  vector<unsigned long long int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  unsigned long long int tmp_sum = 0;
  /*for(int i = 0; i < vec.size(); i++){
    tmp_sum = tmp_sum+vec.at(i);
  }*/

  unsigned long long int sum = 0;

  for(int i = 1; i < vec.size(); i++){
    tmp_sum = (tmp_sum + vec.at(i-1))% 1000000007;
    sum = (sum + vec.at(i) * tmp_sum) % 1000000007;
  }

  cout << sum % 1000000007 << endl;
  /*for (int i = 0; i < vec.size(); i ++){
    cout << vec.at(i) << endl;
  }

  for (int i = 0; i < vec.size()-1; i ++){
    cout << vec.at(i) << " ";
  }
  cout << vec.at(vec.size() - 1) << endl;*/
}


Measured memory_bytes: 4780
n=int(input())
s=input()
sum=0
r=int(s.count('R'))
g=int(s.count('G'))
b=int(s.count('B'))
for k in range(n):
    for j in range(k):
        i=2*j-k
        if i+1>0:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                sum=sum+1
print(r*g*b-sum)

Measured memory_bytes: 9204
n, m, v, p = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

ok, ng = p-1, n
while ng-ok > 1:
	mi = (ng+ok)//2
	possible = True
	x = a[mi]
	i = mi-1
	cnt = 0
	while i >= p-1:
		if a[i]-x > m:
			possible = False
			break
		cnt += a[i]-x
		i -= 1
	if cnt > m * (n - v):
		possible = False

	if possible:
		ok = mi
	else:
		ng = mi

print(ok+1)

Measured memory_bytes: 14484
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
typedef long long ll;
typedef pair<int, int> P;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> c(n);
  vector<vector<int>> a(m,vector<int> (n));
  int i,j;
  rep(i,n){
    cin>>c[i];
    rep(j,m)cin>>a[j][i];
  }
  ll ans = INF;
  ll cost;
  vector<int> performance(m,0);
  
    for (int tmp = 0; tmp < (1 << n); tmp++) {
      bitset<12> s(tmp);
      cost=0;
      rep(j,m)performance[j]=0;
      for (int i = 0; i < n; i++) {
        if (s.test(i)) {
          cost+=c[i];
          rep(j,m)performance[j]+=a[j][i];
        }
      }
      int judge=0;
      rep(i,m)if(performance[i]<x)judge=1;
      if(judge==0)ans=min(ans,cost);
    }
  
  if(ans<INF)cout<<ans;
  else cout<<-1;
  
  return 0;
}

Measured memory_bytes: 3636
import sys


def main():
    input_str = sys.stdin.readline()
    W, H, x, y, r = [int(i) for i in input_str.split(' ')]
    upper = H >= y + r
    lower = y - r >= 0
    left = x - r >= 0
    right = x + r <= W
    if upper & lower & left & right:
        print('Yes')
    else:
        print('No')
    return


if __name__ == '__main__':
    main()



Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t a,b,c,k;
  cin >> a >> b >> c >> k;
  int64_t sum=0;
  
  if(k>=a){
    sum += a;
    k -= a;
  }else{
    sum += k;
    k = 0;
  }
  
  if(k>=b)k -= b;
  else k=0;
  
  if(k>0){
    sum -= k;
  }
  
  cout << sum <<endl;
}

Measured memory_bytes: 3636
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B, C);

// ===

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let c: i32 = read();
    let d: i32 = read();
    println!("{}", min(a, b) + min(c, d));
}


Measured memory_bytes: 4352
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
template <typename T>
using priority_queue_lo = priority_queue<T, vector<T>, greater<T>>;
#endif


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

    int N;  cin >> N;
    vl A(N*3);
    REP(i, N*3) cin >> A[i];

    priority_queue_lo<ll> pql;
    ll sum1 = 0;
    REP(i, N) {
        pql.push(A[i]);
        sum1 += A[i];
    }

    priority_queue<ll> pq;
    ll sum2 = 0;
    FOR(i, N*2, N*3) {
        pq.push(A[i]);
        sum2 += A[i];
    }

    vl sumL(N+1,0);
    sumL[0] = sum1;
    FOR(k,N,2*N) {
        pql.push(A[k]);
        sum1 += A[k];
        sum1 -= pql.top();
        sumL[k-N+1] = sum1;
        pql.pop();
    }

    vl sumR(N+1,0);
    sumR[N] = sum2;
    for (int k = 2 * N - 1; k >= N; k--) {
        pq.push(A[k]);
        sum2 += A[k];
        sum2 -= pq.top();
        sumR[k-N] = sum2;
        pq.pop();
    }

    ll ans = -LINF;
    REP(i,N+1) {
        ans = max(ans, sumL[i] - sumR[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5876
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    
    int count = 0;
    for(int i=1; i<=n; i++){

        int c = 0;
        int now = i;
        while (now>=10){
            now /= 10;
            c++;
        }
        if(c %2 == 0){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        const long MOD = 1000000007;
        var sc = new Scanner();
        int n = sc.nextInt();
        var a = new long[n];
        long a_max = 0;
        for (int i = 0; i < n; i++)
        {
            a[i] = sc.nextLong();
            a_max = Math.Max(a_max, a[i]);
        }

        var count = new long[Convert.ToString(a_max, 2).Length];

        for (int i = 0; i < n; i++)
        {
            string a_2 = Convert.ToString(a[i], 2);
            a_2 = a_2.PadLeft(Convert.ToString(a_max, 2).Length, '0');
            for (int j = 0; j < a_2.Length; j++)
            {
                if (a_2[j] == '1') count[j]++;
            }
            Debug.WriteLine("a_2=" + a_2);
        }

        long ans = 0;
        for (int i = 0; i < count.Length; i++)
        {
            long p = 1;
            for (int j = 0; j < count.Length - i - 1; j++)
            {
                p *= 2 % MOD;
            }
            p %= MOD;
            // Debug.WriteLine("i:" + i + "(p)" + p + "*(count)" + count[i] + "*(n-count)" + (n - count[i]));
            long tmp = p * count[i] % MOD;
            ans = ans + tmp * (n - count[i]) % MOD;
            ans %= MOD;
        }
        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 53064
#include <stdio.h>

int main(void)
{
	int a[100],n,i,j,m,t,s=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	for(i=0;i<n;i++){
		m=i;
		for(j=i;j<n;j++)if(a[m]>a[j])m=j;
		if(a[i]!=a[m])s++;
		t=a[i];
		a[i]=a[m];
		a[m]=t;
	}
	for(i=0;i<n-1;i++)printf("%d ",a[i]);
	printf("%d\n%d\n",a[n-1],s);
	return 0;
}


Measured memory_bytes: 2048
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))

v1, v2 = defaultdict(int), defaultdict(int)
for i, vv in enumerate(v):
    if i%2 == 0:
        v1[vv] += 1
    else:
        v2[vv] += 1
v1 = sorted([(c, vv) for vv, c in v1.items()], reverse = True)
v2 = sorted([(c, vv) for vv, c in v2.items()], reverse = True)

if v1[0][1] == v2[0][1]:
    if len(v1) == 1 and len(v2) == 1:
        ans = n//2
    elif v1[1][0] > v2[1][0]:
        ans = n - v1[1][0] - v2[0][0]
    else:
        ans = n - v1[0][0] - v2[1][0]
else:
    ans = n - v1[0][0] - v2[0][0]
print(ans)


Measured memory_bytes: 18072
#include <cstdio>
#include <math.h>

using namespace std;

bool similar[100010];
bool prime[100010];
int ruiseki[100010] = {};

bool is_prime(int s) {
  if (s == 2) {
    return true;
  }
  if (s == 1 || s % 2 == 0) {
    return false;
  }
  double s_rt = sqrt(s);
  for (int i = 3; i <= s_rt; i += 2) {
    if (s % i == 0) {
      return false;
    }
  }
  return true;
}     

int main() {
  int i, j;
  for (i = 1; i < 100000; i++) {
    prime[i] = is_prime(i);
    //printf("i:%d, sqrt:%d, %d\n", i, (int)sqrt(i), (int)is_prime(i));
  }
  for (i = 1; i < 100000; i++) {
    if (prime[i] == true && prime[(i+1)/2] == true) {
      similar[i] = true;
    }
    //printf("i:%d, sqrt:%d, %d\n", i, (int)sqrt(i), (int)similar[i]);
  }
  for (i = 1; i < 100000; i++) {
    ruiseki[i] = ruiseki[i-1] + similar[i];
  }
  int Q;
  int l[100010], r[100010];
  scanf("%d", &Q);
  for (i = 0; i < Q; i++) {
    scanf("%d %d", &l[i], &r[i]);
    printf("%d\n", ruiseki[r[i]]-ruiseki[l[i]-1]);
  } 
  return 0;
}
    


Measured memory_bytes: 1920
#include <stdio.h>
#include <stdlib.h>
#define M 100000

int n, k;
double A[M];

int check(double p){
  int i = 0, j;
  double s;
  for( j = 0 ; j < k ; j++){
    s = 0.0;
    while( s + A[i] <= p){
      s += A[i];
      i++;
      if( i == n ) return n;
    }
  }
  return i;
}

int solve(){
  double left = 0.0;
  double right = M*10000;
  double mid;
  int v;

  while( right - left > 1){
    mid = ( left + right ) / 2;
    v = check(mid);
    if( v >= n ) right = mid;
    else left = mid;
  }
  return right;
}

int main(){
  int i;
  double ans;
  scanf("%d%d", &n, &k);
  for( i = 0 ; i < n ; i++) scanf("%lf", &A[i]);
  ans = solve();
  printf("%d\n", (int)ans);

  return 0;
}



Measured memory_bytes: 2532
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e3 + 7;
int ls1[Max], ls2[Max];
int n;


int main()
{
	int a, b;
	string str;
	cin >> a >> b;
	cin >> str;
	int f = 0;
	for (int i = 0; i <= str.size() - 1; i++)
	{
		if (i == a)
		{
			if (str[i] != '-')
			{
				f = 1;
				break;
			}
		}
		else
		{
			if (!(str[i] <= '9' && str[i] >= '0'))
			{
				f = 1;
				break;
			}
		}
	}
	if (f)cout << "No";
	else cout << "Yes";
}

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

typedef long long ll;
string S;

int main() {
    cin >> S;

    if (S.size() == 1) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    for (int i = 0; i <= S.size() - 2; i++) {
        if (S[i] != S[i + 1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M, C = mapint()
Bs = list(mapint())
ans = 0
for _ in range(N):
    p = [a*b for a, b in zip(mapint(), Bs)]
    if sum(p)+C>0:
        ans += 1
print(ans)

Measured memory_bytes: 62168
#include<vector>
#include<algorithm>

std::vector<int> primeNumbers = {2, 3};
std::vector<bool> isPrime;

void eratosthenes(int n){
    int i, j;
    int s = 4;

    isPrime.assign(std::max(n + 1, 2), true);
    isPrime[0] = false;
    isPrime[1] = false;

    for(i = 4 ; i <= n ; i += 2){
        isPrime[i] = false;
    }
    for(i = 9 ; i <= n ; i += 6){
        isPrime[i] = false;
    }

    for(i = 5 ; i * i <= n ; i += s){
        if(isPrime[i]){
            primeNumbers.emplace_back(i);
            for(j = i * i ; j <= n ; j += i){
                isPrime[j] = false;
            }
        }
        s ^= 6;
    }
    for( ; i <= n ; i += s){
        if(isPrime[i]){
            primeNumbers.emplace_back(i);
        }
        s ^= 6;
    }

    return;
}

#include<iostream>

int main(){
    eratosthenes(999999);

    int n;
    while(std::cin >> n){
        std::cout << std::upper_bound(primeNumbers.begin(), primeNumbers.end(), n) - primeNumbers.begin() << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3480
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
const int mod=1e9+7;
const int N=1e5+3;
int f[N],inv[N];
int modp(int a,int b)
{
	if(b==0)return 1;
	int u=modp(a,b/2);
	u=(u*u)%mod;
	if(b&1)return (a*u)%mod;
	return u;
}
int C(int n,int r)
{
	if(n<r)return 0;
	int res=(f[n]*inv[r])%mod;
	res*=inv[n-r];res%=mod;
	return res;
}
int32_t main()
{
	f[0]=1;
	int n=in();int k=in();
	for(int i=1;i<=n;i++)
	f[i]=(i*f[i-1])%mod;
	
	inv[n]=modp(f[n],mod-2);
	for(int i=n-1;i>=0;i--)
	inv[i]=((i+1)*inv[i+1])%mod;
	
	vector<int> a(n);for(auto &i:a)i=in();
	sort(all(a));
	int ans=0;int greater, smaller,mx,mn;
	for(int i=0;i<n;i++)
	{
		greater=n-i-1;
		smaller=i;
		
		//maxcontribution
		mx=a[i]*C(smaller,k-1);
		mx%=mod;
		mn=-(a[i]*C(greater,k-1));
		mn%=mod;mn+=mod;mn%=mod;
		ans+=mx;ans%=mod;ans+=mn;ans%=mod;
		
	}
	cout<<ans;
	
	
}

Measured memory_bytes: 5524
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace A
{
    partial class Program
    {
        long a;
        long b;
        long c;
        long d;
        public IEnumerable<string> Solve()
        {
            a = Num;
            b = Num;
            c = Num;
            d = Num;

            var res = Slv(b) - Slv(a - 1);

            yield return res.ToString();
        }

        long Slv(long n)
        {
            var cc = n / c;
            var dd = n / d;
            var lcm = c * d / Gcm(c, d);
            var cd = n / lcm;



            return n - cc - dd + cd;
        }

        long Gcm(long x, long y)
        {
            if (x < y)
                return Gcm(y, x);
            if (x % y == 0)
                return y;

            return Gcm(y, x % y);
        }
    }

    class StartingPoint
    {
        static void Main(string[] args)
        {
            if (args?.Any() == true)
            {
                var assembly = Assembly.GetExecutingAssembly();
                var resourceName = "AtCoder.Resources.In.txt";
                var stream = assembly.GetManifestResourceStream(resourceName);
                var streamReader = new StreamReader(stream, Encoding.UTF8);
                var str = streamReader.ReadToEnd();
                var textReader = new StringReader(str);
                Console.SetIn(textReader);
            }

            try
            {
                foreach (var s in new Program().Solve())
                {
                    Console.WriteLine(s);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                if (args?.Any() != true)
                    throw e;
            }

            if (args?.Any() == true)
                Console.ReadLine();
        }
    }

    partial class Program
    {
        long[] Nums(long count) => Enumerable.Range(0, (int)count).Select(_ => Num).ToArray();
        long Num => long.Parse(Str);
        double NumD => (double)Num;

        StringBuilder sb = new StringBuilder();

        string Str => GetStr();
        string GetStr()
        {
            sb.Clear();

            int r = 0;
            bool? b = null;
            do
            {
                r = Console.Read();
                b = IsBreak(r);
            } while (b == true);

            if (b == null)
                throw new Exception("input error: unexpected end of stream");

            do
            {
                sb.Append((char)r);
                r = Console.Read();
                b = IsBreak(r);
            } while (b == false);

            return sb.ToString();
        }

        bool? IsBreak(int c)
        {
            switch (c)
            {
                case -1:
                    return null;
                case (int)' ':
                case (int)'\n':
                case (int)'\r':
                    return true;
                default:
                    return false;
            }
        }
    }
}

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

typedef pair<int,int> P;

P t[1002];

int main() {
  int n, m;

  while (cin >> n >> m) {
    for (int i = 0; i < m; i++) {
      cin >> t[i].first >> t[i].second;
    }
    sort(t, t + m);

    vector<P> v;

    for (int i = 0; i < m; i++) {
      int lft = t[i].first;
      int rht = t[i].second;
      int j = i + 1;

      while (j < m && lft <= t[j].first && t[j].first <= rht) {
        rht = max(rht, t[j].second);
        j++;
      }

      v.push_back(P(lft, rht));
      i = j - 1;
    }

    int ans = 0;
    int now = 0;

    for (int i = 0; i < v.size(); i++) {
      ans += abs(now - v[i].second);
      ans += v[i].second - v[i].first;
      now = v[i].first;
    }

    ans += (n + 1) - now;

    cout << ans << endl;
  }
}

Measured memory_bytes: 1212
#include <iostream>
#include <cctype>
#include <string>
using namespace std;

int main(void){
    
    int counter[256];
    string ch;
    char c;
    
    for(c = 'a'; c <= 'z'; c++){
        counter[c] = 0;
    }
    
    while(cin >> ch){
        for(int i=0; i < (int)ch.size(); i++){
            if(isupper(ch[i])) ch[i] = tolower(ch[i]);
            counter[ch[i]]++;
        }
    }
    
    for(c='a'; c<= 'z'; c++){
        cout << c << " : " << counter[c] << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3132
using System;

public class UnionFind
{
    private int[] data;
    public UnionFind(int size)
    {
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(int x, int y)
    {
        x = Root(x);
        y = Root(y);
        if (x != y)
        {
            if (data[y] < data[x])
            {
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    public bool IsSameGroup(int x, int y) => Root(x) == Root(y);
    public int Root(int x) => data[x] < 0 ? x : data[x] = Root(data[x]);
    public int getMem(int x) => -data[Root(x)];
}


public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var a = new int[m];
        var b = new int[m];
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            a[i] = int.Parse(line[0]) - 1;
            b[i] = int.Parse(line[1]) - 1;
        }
        Array.Reverse(a);
        Array.Reverse(b);
        putAns(a, b, n, m);
    }
    static void putAns(int[] a, int[] b, int n, int m)
    {
        var ans = new long[m + 1];
        var uf = new UnionFind(n + 10);
        ans[0] =(long) n * (n - 1) / 2L;
        for (int i = 0; i < m; i++)
        {
            if (uf.IsSameGroup(a[i], b[i])) ans[i + 1] = ans[i];
            else
            {
                long wa = uf.getMem(a[i]);
                long wb = uf.getMem(b[i]);
                ans[i + 1] = ans[i] - wa * wb;
                uf.Unite(a[i], b[i]);
            }
        }
        Array.Reverse(ans);
        for (int i = 1; i <= m; i++) Console.WriteLine(ans[i]);
    }
}

Measured memory_bytes: 18316
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn gcd(a: usize, b: usize) -> usize {
    if b != 0 {
        gcd(b, a % b)
    } else {
        a
    }
}

fn lcm(a: usize, b: usize) -> usize {
    a / gcd(a, b) * b
}

fn f(a: usize, b: usize, c: usize) -> usize {
    a - (a / b + a / c - a / lcm(b, c))
}

fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize,
        d: usize,
    }

    println!("{}", f(b, c, d) - f(a - 1, c, d));
}


Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		int h[] = new int[N];

		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}

		Arrays.sort(h); //昇順に並べ替え
		int min = Integer.MAX_VALUE;

		for(int i = 0; i < N-K+1; i++) {
			int diff = h[i+K-1] - h[i];
			if (diff < min) {
				min = diff;
			}
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 50804
/*
        |___________________________Arshit Mangukiya_____________________________|
        |_______________________________DA-IICT__________________________________|
        |_____________________________201801173__________________________________|
*/
        /*______________________WRITE  YOUR  CODE  HERE_________________________*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;            
typedef long double ld;
#define ff first
#define ss second
#define mr_ad_0501 ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define all(a)      a.begin(),a.end()
//#define F(i,n) for(ll i=0;i<n;i++)
#define MOD 1000000007
#define MAX 200005
#define sz size()
#define p(x) 		cout<< x << " ";
#define pe(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
		const ll N=1e5;
		ll i,j,k;
    		bool fun(pair<int,int>a , pair<int,int>b)
			{
				if(a.ff == b.ff)	return a.ss < b.ss;
				else			return a.ff > b.ff;
			}
bool fun(string s,string t)
	{
		ll c=0;
		for(ll i=0;i<s.sz;i++)
		{
			if(c<t.sz && s[i]==t[c])c++;
			
		}
		return c==t.sz;
	}
//ll dp[64];
//ll ans=1;
// vector<ll> v[N+1];
 //vector<ll> l(N+1,0);
 //vector<ll>vis(N+1);
 ll cnt=0,cnt1=0;
 /*void bfs(ll x)
 {
 	queue<ll> q;
	q.push(x);
    while(!q.empty())
    {
        ll k=q.front();
        q.pop();
        for(auto X:v[k])
        {
            if(!vis[X])
            {
            	l[X]=l[k]+1;
                vis[X]=1;
                q.push(X);
            }
        }
    }
 }*/
void solve()
{
	ll n,m,sum=0;
	cin>>n>>m;
	ll a[m+1];
	for(ll i=0;i<m;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(n>=sum)cout<<n-sum;
	else cout<<-1;
}

int32_t main(){
	mr_ad_0501;
	ll t=1;
	//cin >> t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

int main(int argc, char **argv) {
    int n,x;
    cin >> n >> x;

    std::vector<int> v(n, 0);

    for (int i=0; i<n; ++i) {
        cin >> v[i];
    }
    int ans{0}, d{0};
    ++ans;
    for (int i=0; i<n; ++i) {
        d += v[i];
        if (d > x) {
            break;
        }
        ++ans;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int x, y, z, k;
  cin >> x >> y >> z >> k;

  vector<ll> a(x), b(y), c(z);
  rep(i, 0, x) cin >> a[i];
  rep(i, 0, y) cin >> b[i];
  rep(i, 0, z) cin >> c[i];

  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(c.rbegin(), c.rend());

  vector<ll> ans;

  rep(i, 0, x) {
    rep(j, 0, y) {
      rep(m, 0, z) {
        if ((i + 1) * (j + 1) * (m + 1) <= k)
          ans.push_back(a[i] + b[j] + c[m]);
        else
          break;
      }
    }
  }

  sort(ans.rbegin(), ans.rend());

  rep(i, 0, k) cout << ans[i] << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N;
    cin >> N;
    ll A[100000], Asorted[100000];
    ll cnt[2]={0,0};
    for(int i=0;i<N;i++){
        cin >> A[i];
        Asorted[i]=A[i];
    }
    sort(Asorted,Asorted+N);
    map<ll,ll> idx;
    for(int i=0;i<N;i++) idx[Asorted[i]]=i;

    for(int i=0;i<N;i++){
        if(i%2!=idx[A[i]]%2) cnt[i%2]++;
    }
    
    cout << max(cnt[0],cnt[1]) << endl;
    
    return 0;
}

Measured memory_bytes: 8192
N = int(input())
mons = list(map(int, input().split()))
yush = list(map(int, input().split()))

temp = sum(mons)

for i, yu in enumerate(yush):
    mo = mons[i]
    if (yu >= mo):
        mons[i] = 0
        yush[i] = yu - mo
        
        if (mons[i + 1] > yush[i]):
            mons[i + 1] -= yush[i]
        else:
            mons[i + 1] = 0
        
    else:
        mons[i] = mo - yu
ans = temp - sum(mons)
print(ans)

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

bool is_integer( double x ){
  return floor(x)==x;
}

int main() {
    int N, D;
    cin >> N >> D;

    int X[12][12] = {0};
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < D; ++j) {
            cin >> X[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < N - 1; ++i) {
        for (int j = i + 1; j < N; ++j) {

            double dist = 0;
            for (int k = 0; k < D; ++k) {
                dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }

            if (is_integer(sqrt(dist))) ++ans;
        }
    }

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

Measured memory_bytes: 256