akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
MI=lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))

N,K=MI()
A=LI()
A.sort(reverse=True)
F=LI()
F.sort()

def check(x):
    # x分以内に食べきれるための修行回数はK回以下か
    k=0
    for i in range(N):
        k+=max(int(0--(A[i]-x//F[i])//1),0)
    return k<=K

    
ok=10**13
ng=-1
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if check(mid):
        ok=mid
    else:
        ng=mid
print(ok)

Measured memory_bytes: 105292
#include <iostream>
using namespace std;
int main(void){
    
    int A,B;
    string s;
    cin>>A>>B>>s;
    int count=0;
    for(int i=0;i<s.size();i++){
        if(s[i]!='-')count++;
        if(s[i]=='-'){
            if(count==A)count=0;
            else break;
        }
        if(i==s.size()-1 && count==B){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <tuple>
typedef long long int ll;
using namespace std;
int main() {
    int n, W;
    cin >> n >> W;
    ll w[n + 1];
    ll v[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    int num_of_w0 = 0; // w1 + 0
    int num_of_w1 = 0; // w1 + 1
    int num_of_w2 = 0;
    int num_of_w3 = 0;
    vector<ll> vecW0;
    vector<ll> vecW1;
    vector<ll> vecW2;
    vector<ll> vecW3;
    for (int i = 1; i <= n; i++) {
        if (w[i] == w[1]) {
            num_of_w0++;
            vecW0.push_back(v[i]);
        }
        else if (w[i] == w[1] + 1) {
            num_of_w1++;
            vecW1.push_back(v[i]);
        }
        else if (w[i] == w[1] + 2) {
            num_of_w2++;
            vecW2.push_back(v[i]);
        }
        else {
            num_of_w3++;
            vecW3.push_back(v[i]);
        }
    }
    sort(vecW0.begin(), vecW0.end(), greater<ll>());
    sort(vecW1.begin(), vecW1.end(), greater<ll>());
    sort(vecW2.begin(), vecW2.end(), greater<ll>());
    sort(vecW3.begin(), vecW3.end(), greater<ll>());
    //cout << vecW0[0] << endl;
    //cout << num_of_w0 << endl;
    ll dp[num_of_w0 + 2][num_of_w1 + 2][num_of_w2 + 2][num_of_w3 + 2];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= num_of_w0; i++) {
        for (int j = 0; j <= num_of_w1; j++) {
            for (int k = 0; k <= num_of_w2; k++) {
                for (int l = 0; l <= num_of_w3; l++) {
                    if (i != num_of_w0) dp[i + 1][j][k][l] = dp[i][j][k][l] + vecW0[i];
                    if (j != num_of_w1) dp[i][j + 1][k][l] = dp[i][j][k][l] + vecW1[j];
                    if (k != num_of_w2) dp[i][j][k + 1][l] = dp[i][j][k][l] + vecW2[k];
                    if (l != num_of_w3) dp[i][j][k][l + 1] = dp[i][j][k][l] + vecW3[l];
                }
            }
        }
    }
    //cout << dp[1][0][0][0] << endl;
    ll max = 0;
    for (int i = 0; i <= num_of_w0; i++) {
        for (int j = 0; j <= num_of_w1; j++) {
            for (int k = 0; k <= num_of_w2; k++) {
                for (int l = 0; l <= num_of_w3; l++) {
                    if (W >= i * w[1] + j * (w[1] + 1) + k * (w[1] + 2) + l * (w[1] + 3)) {
                        if (max < dp[i][j][k][l]) {
                            max = dp[i][j][k][l];
                        }
                    }
                }
            }
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 7784
#include <iostream>
/*
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <iomanip>
#include <numeric>
*/

using namespace std;

typedef long long LL;

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int X,Y;

	cin >> X >> Y;

	cout << X * Y << " " << 2 * X + 2 * Y << endl;

	return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    ll n;
    char s[100020];
    cin >> n;
    cin >> s;
    
    int k[26];
    for (int i = 0; i < 26; i ++) k[i] = 0;
    for (int i = 0; i < n; i++) {
        k[s[i] - 'a']++;
    }
    
    ll ans = 1;
    for (int i = 0; i < 26; i++) {
        ans *= (k[i] + 1);
        ans %= 1000000007;
    }
    
    
    cout << ans - 1 << endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
	int n,t,x,y,F=0;
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>t>>x>>y;
		if (x+y<=t && (t-x-y)%2==0) continue;
		else F=1;
		
	}
	if (F==0) cout<<"Yes";
	else	  cout<<"No";
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)

using ll = long long;

int main(){
  int n;
  cin >> n;
  vector<ll> x(n);
  vector<ll> m(n);
  rep(i,n){
    cin >> x.at(i);
    m.at(i) = x.at(i);
  }
  sort(m.begin(),m.end());

  ll a = m.at(n/2-1),b = m.at(n/2);
  rep(i,n){
    ll ans = 0;
    if(x.at(i)<=a)ans = b;
    else if(x.at(i)>=b)ans = a;
    cout<<ans<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 5376
#include<stdio.h>
int main(){
    int x;
    char b[4];
    scanf("%s",b);
    if(b[0]='S'&&b[1]=='U'&&b[2]=='N')x=7;
    else if(b[0]='M'&&b[1]=='O'&&b[2]=='N')x=6;
    else if(b[0]='T'&&b[1]=='U'&&b[2]=='E')x=5;
    else if(b[0]='W'&&b[1]=='E'&&b[2]=='D')x=4;
    else if(b[0]='T'&&b[1]=='H'&&b[2]=='U')x=3;
    else if(b[0]='F'&&b[1]=='R'&&b[2]=='I')x=2;
    else x=1;
    printf("%d\n",x);
    return 0;
    
}

Measured memory_bytes: 128
#include <stdio.h>
int dp[10][10];
int main(){
	int N;scanf("%d",&N);
	for(int i=1;i<=N;i++){
		int L=i%10,R=i%10;
		int x = i;
		while(x>0){
			L=x%10;
			x/=10;
		}
		dp[L][R]++;
	}
	long long cnt = 0;
	for(int i=1;i<=N;i++){
		int L=i%10,R=i%10;
		int x = i;
		while(x>0){
			L=x%10;
			x/=10;
		}
		cnt +=dp[R][L];
	}
	printf("%lld",cnt);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
const ll INF = 1e18;

int dp[N];
int has[N];
vector<int> tmp;
vector<int> tar[N];


int main() {
	int n, m;
	while(~scanf("%d %d", &n, &m)) {

		dp[0] = 0;
		for(int i = 0; i < m; ++i) {
			int a, b;
			scanf("%d %d", &a, &b);
			tar[a].push_back(b);
			dp[2*a] ++;
			dp[2*b - 1] --;
		}
	//	for(int i = 1; i <= 2*n; ++i) printf("%d ", dp[i]); printf("\n");
		int ans = 0;
		int flag = 0;
		for(int i = 1; i <= 2*n; ++i) {
			if(dp[i] > 0) {
				for(int j = 0; j < tar[(i+1)/2].size(); ++j) 
					tmp.push_back(tar[(i+1)/2][j]);
				flag = 1;
			} else if(dp[i] < 0 && flag) {
				flag = 0;
				ans ++;
				for(int j = 0; j < tmp.size(); ++j) {
					dp[2*tmp[j] - 1] ++;
				}
				tmp.clear();
			}
		}

		printf("%d\n", ans);
		
	}
	return 0;
}

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

int main() {
  int a,b,c;
 
  cin >> a >>b >>c ;
  
  
   vector <int> vec ={a,b,c};
  sort (vec.begin(),vec.end());
  
  cout << vec[0]+vec[1] <<endl;
}
  




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

using i64 = int64_t;

i64 calc_fib(i64 n){
    static vector<i64> memo(n+1);
    if(memo[n] > 0)return memo[n];
    if(n <= 1)return memo[n] = 1;
    return memo[n] = calc_fib(n-1) + calc_fib(n-2);
}

int main(){
    i64 n;
    cin >> n;
    cout << calc_fib(n) << endl;

    return 0;
}



Measured memory_bytes: 3088
// #include <iostream>
// #include <fstream>
// #include <cstdio>
// #include <set>
// #include <vector>
// #include <algorithm>
// #include <cmath>
// #include <cstdlib>
// #include <queue>
// #include <string>
// #include <map>
// #include <unordered_map>
// #include <cstring>
// #include <numeric>
// #include <stack>
// #include <iomanip>
// #include <chrono>

#include<bits/stdc++.h>
using namespace std;

#define sd(mark) scanf("%d",&mark)
#define ss(mark) scanf("%s",mark)
#define clr(mark) memset(mark,0,sizeof(mark))
#define setinf(mark) memset(mark,0x3f,sizeof(mark))
#define setneg(mark) memset(mark,-1,sizeof(mark))



#ifndef strange
#define trace(...)
// #define endl '\n'
#define start_routine() 
#define end_routine()
#endif
typedef long long ll;   
//__gcd


const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
#define PI 3.141592653589793238
#define mod 1000000007


#define F first 
#define S second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define trav(a,x) for(auto &a:x)
#define pii pair<int,int>

#define pb push_back
#define int long long

#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)

#define sz(x) (int)(x).size()
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<vi> vii;
#define vp vector <pii>
int x;

int power(int x,  int y) 
{ 
    int res = 1;   
  
    x = x % mod;  
   
    if (x == 0) return 0; 

    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % mod;  
  
          
        y = y>>1; 
        x = (x*x) % mod;  
    }  
    return res;  
}
int dp[2005];
void solve(){
    int n;
    cin>>n;
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=1;i<=n;i++){
        for(int j=i-3;j>=0;j--){
            dp[i]+=dp[j];
            dp[i]%=mod;
        }
    }
    cout<<dp[n]<<"\n";

}


signed main(){
    int t=1;
    start_routine();
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(NULL);
    cout<<fixed<<setprecision(10);
    
    
    // cin>>t;
    
    fr(i,1,t) {
		// cout<<"Case #"<<i<<": ";
		solve();
	}

    end_routine();
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++) //n回繰り返すときだけ使う普通はforで楽しないのがいいかな

using namespace std;
typedef long long int ll;
int main()
{        
    int n;
    string s;
    cin >>n >>s;
    int ans=0;

    for(char i='0';i <= '9';i++)
    {
        for(char k='0';k<='9';k++)
        {
            for(char j='0';j<='9';j++)
            {
                queue<char> q;
                q.push(i);
                q.push(j);
                q.push(k);

                for(int l=0;l<s.size();l++)
                {
                    if(q.front()==s[l])
                    {
                        q.pop();
                    }

                    if(q.size()==0)
                    {
                        ans++;
                        break;
                    }
                }
            }
        }
        
    }
     cout << ans << endl;



}


Measured memory_bytes: 3712
#include<iostream>
using namespace std;
int a,n,i,j,k;
bool b[2001]={1};
main(){
  for(cin>>n;i++<n;){
    cin>>a;
    for(k=2001;k+1;--k)b[k]?b[k+a]=1:0;
  }
  for(cin>>n;j++<n;cout<<(b[i]?"yes\n":"no\n"))cin>>i;
}

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

using namespace std;

int n, m, a[100];
bool check;

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; ++i)
    {
        int s, c;
        cin >> s >> c;
        if (s == 1) check = true;
        if ((a[s] && a[s] != c) || (s == 1 && c == 0 && n > 1)) { cout << -1; return 0; }
        a[s] = c;
    }
    if (!check && n != 1) a[1] = 1;
    for (int i = 1; i <= n; ++i) cout << a[i];
    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,L;
#define Maxn 200010
ll Ans=0;
struct data{
    int val,pos;
    bool operator <(const data &z)const{return val==z.val?pos<z.pos:val<z.val;}
}seq[Maxn];
struct Data{
    int l,r;
	int x,y;
	bool operator <(const Data &z)const{return l<z.l;}
};
vector<Data> A,B,vec2;
vector<pair<int,int> > vec1;
int num[Maxn];

inline ll calc(vector< pair<int,int> > &a){
	ll res=0,sum=0;
	for(int i=L-1,j=0;i<a.size();i++,j++){
		sum+=a[j].first;
		res+=a[i].second*sum;
	}
	return res;
}

inline void rd(int &x){
	x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	} 
}

int main(){
	rd(n);rd(L);
	for(register int i=1;i<=n;++i){
		rd(num[i]);
		seq[i]=(data){num[i],i};
	}
	sort(seq+1,seq+n+1);
	ll Ans=n;
	int at=1,tmp;
	while(true){
		if(A.empty()){
			if(at>n)break;
			else tmp=seq[at].val;
		}else tmp++;
		while(tmp==seq[at].val)A.push_back((Data){seq[at].pos,seq[at].pos,1,1}),at++;
		B.clear();sort(A.begin(),A.end());
		for(int i=0,j;i<A.size();i=j+1){
			j=i;
			while(j+1<A.size()&&A[j+1].l==A[j].r+1)j++;
			int len=j-i+1,cnt=len/L;
			if(cnt){
				vec1.clear();
				vec2.clear();
				for(register int k=i;k<=j;++k)vec1.push_back(make_pair(A[k].x,A[k].y));
				Ans+=calc(vec1);
				for(register int k=1;k<=cnt;++k)
					vec2.push_back((Data){A[i].l+k-1,(k==cnt)?A[j].r:A[i].l+k-1,0,0});
				for(register int k=i;k<=j;++k){
					int tl=k-i+1,tr=j-k+1;
					if(tl>=L)vec2[tl/L-1].y+=A[k].y;
					if(tr>=L)vec2[cnt-tr/L].x+=A[k].x;
				}
				vec1.clear();
			    for(register int k=0;k<cnt;++k)vec1.push_back(make_pair(vec2[k].x,vec2[k].y));
				Ans-=calc(vec1);
				for(register int k=0;k<cnt;++k)B.push_back(vec2[k]);
			}
		}
		A.clear();
		for(int i=0;i<B.size();++i)A.push_back(B[i]);
	}
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 11372
import java.util.*;

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

		int[] tastes = new int[N];
		int minAbs = 1000;
		int minIdx = -1;

		// 味を求める
		for (int i = 0; i < N; i++) {
			tastes[i] = L + (i + 1) - 1;

			int abs = Math.abs(tastes[i]);
			if (abs < minAbs) {
				minAbs = abs;
				minIdx = i;
			}
		}

		// アップルパイ
		int ans = 0;
		for (int i = 0; i < N; i++) {
			if (i != minIdx) {
				ans += tastes[i];
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35684
N, M, X = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(N)]
answer = 10**7

for num in range(2**N):
  algos = [0 for i in range(M+1)]
  money = 0
  for i in range(N):
    if num>>i&1:
      for j in range(1, M+1):
        algos[j] += books[i][j]
      money += books[i][0]
  master = True
  for k in range(1, M+1):
    if algos[k] < X:
        master = False
        break
  if master:
    answer = min(answer, money)
if answer == 10**7:
  print(-1)
else:
  print(answer)

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

 const long long int mod=1e9+7;


 long long int dfs(int K,const vector<vector<int>>&graph, int now,int from) {

 int can_use_color_num;
 if (from==-1) {
 can_use_color_num=K-1;
 }
 else {
 can_use_color_num=K-2;
 }
 if (K<graph[now].size()) {
 return 0;
 }
 else {
 long long int case_num=1;
 for (auto e : graph[now]) {
 if(e==from)continue;

 case_num*=can_use_color_num;
 can_use_color_num--;
 case_num%=mod;
 }
 for (auto e : graph[now]) {
 if(e==from)continue;

 case_num *=dfs(K,graph,e,now);
 case_num %= mod;
 }
 return case_num;
 }
 }



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

 vector<vector<int>>graph(N);
 for (int i = 0; i < N - 1; ++i) {
 int a,b;cin>>a>>b;a--;b--;

 graph[a].push_back(b);
 graph[b].push_back(a);
 }

 long long int answer=K*dfs(K,graph,0,-1);
 answer%=mod;
 cout<<answer<<endl;
 return 0;
}

Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int x,y;
  cin>>x>>y;
  if(x%y==0) cout<<-1<<endl;
  else cout<<x<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
queue<ll> q;
ll k;
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> k;
	for(int i = 1;i <= 9;i++) q.push(i);
	ll ans = 0;
	for(int i = 1;i <= k;i++){
		ans = q.front(); q.pop();
		ll cur = ans;
		cur %= 10;
		if(cur > 0) q.push(ans * 10 + cur - 1);
		q.push(ans * 10 + cur);
		if(cur < 9) q.push(ans * 10 + cur + 1); 
	}
	cout << ans << endl;
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int x; cin>>x;
	
	if(x == 1)
		cout << "0";
	else if(x == 0)
		cout << "1";
	return 0;
}

Measured memory_bytes: 3656
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type point struct {
	x int
	y int
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	points := make([]point, n)
	for i := 0; i < n; i++ {
		points[i].x = nextInt()
		points[i].y = nextInt()
	}

	total := 0.0
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i != j {
				dx := math.Pow(float64(points[i].x-points[j].x), 2)
				dy := math.Pow(float64(points[i].y-points[j].y), 2)

				total += math.Sqrt(dx + dy)
			}
		}
	}
	fmt.Printf("%.10f", total/float64(n))
}


Measured memory_bytes: 640
N = int(input())
As, Bs = [], []
for i in range(N):
    A, B = map(int, input().split())
    As.append((A, i))
    Bs.append((B, i))

ansA = sum([A for A, i in As])
ansB = sum([B for B, i in Bs])

Cs = sorted(As + Bs)

useds = [False] * N
sumC = 0
for C, i in Cs[:N]:
    useds[i] = True
    sumC += C

if not all(useds):
    ansC = sumC
elif Cs[N-1][1] != Cs[N][1]:
    ansC = sumC - Cs[N-1][0] + Cs[N][0]
else:
    ansC = min(sumC - Cs[N-2][0] + Cs[N][0], sumC - Cs[N-1][0] + Cs[N+1][0])

print(min(ansA, ansB, ansC))


Measured memory_bytes: 30716
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();

int main() {
    clue();
    return 0;
}
int clue() {

    int n;
    cin>>n;
    int a=0,w=0,r=0,t=0;
    while(n-->0) {
        string s;
        cin>>s;
        if(s=="AC")++a;
        elif(s=="TLE")++t;
        elif(s=="RE")++r;
        else ++w;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int s;cin>>s;
    if(s == 3||s == 5||s == 7) cout<<"YES";
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[100010];
    a[0] = 0;
    rep(i, n) cin >> a[i + 1];
    a[n + 1] = 0;
    int sum = 0;
    rep(i, n + 1) {
        sum += abs(a[i] - a[i + 1]);
    }
    //cout << sum << endl;
    rep(i, n) {
        cout << sum - abs(a[i] - a[i + 1]) - abs(a[i + 1] - a[i + 2]) + abs(a[i] - a[i + 2]) << endl;
    }

    return 0;
}


Measured memory_bytes: 1664
import java.util.*;

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

		for(int i = 1 ; i <= n ; i++){
			if((dig(i)&1) == 1){
				ans++;
			}
		}

		System.out.println(ans);
	}

	public static int dig(int target){
		int result = 0;
		while(target>0){
			result++;
			target /= 10;
		}
		return(result);
	}
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int main() {
    int p, q;
    cin >> p >> q;
    int g = __gcd(p, q);
    int b = q / g;
    int ans = 1;
    rep(i, 1000006) if (i > 1) {
        if (b % i == 0) {
            ans *= i;
            while (b % i == 0) b /= i;
        }
    }
    cout << ans * b << endl;
    return 0;
}

Measured memory_bytes: 3120
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		int a,b;
		Map<Integer, List<Integer>> map = new HashMap<>();
		for(int i=0; i<n-1; i++) {
		    a = Integer.parseInt(sc.next());
		    b = Integer.parseInt(sc.next());
		    if(map.containsKey(a)) { map.get(a).add(b);}
		    else {
		        map.put(a, new ArrayList<Integer>()); 
		        map.get(a).add(b);
		    }
		    if(map.containsKey(b)) { map.get(b).add(a);}
		    else {
		        map.put(b, new ArrayList<Integer>()); 
		        map.get(b).add(a);
		    }
		}
		
 
		int[] count = new int[n+1];
		int p,x;
		for(int i=0; i<q; i++) {
		    p = Integer.parseInt(sc.next());
		    x = Integer.parseInt(sc.next());
		    count[p] += x;
		}
		
		boolean[] visited = new boolean[n];
		Deque<Integer> que = new ArrayDeque<>();
		que.add(1);
		visited[0] = true;
		while(que.size() != 0) {
		    int z = que.poll();
		    if(map.get(z) != null) {
    		    for(int m : map.get(z)) {
    		        if(visited[m-1] == false) {
        		        que.add(m);
        		        count[m] += count[z];
        		        visited[m-1] = true;
    		        }
    		    }
		    }
		}
		for(int i=1; i<=n; i++) {
		    System.out.print(count[i]+" ");
		}
	}
}

Measured memory_bytes: 195236
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,p,count=0,max,min=1000001;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>p;
        if (i==0) {
            count++;
            max=p;
            if (min>p) {
                min=p;
            }
        } else {
            if (max>p&&min>p) {
                count++;
            }
            if (max<p) {
                max=p;
            }
            if (min>p) {
                min=p;
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  if (a.at(2) == a.at(3) && a.at(4) == a.at(5)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main(){
  ll n,i,m[2],a;
  cin >> n;
  ll p[n];
  m[0]=0;
  m[1]=n+2;
  m[2]=0;
  for(i=1;i<=n;i++){
    cin >> p[i];
    if(p[i]<m[1]){
      m[1]=p[i];
      m[0]=i;
      m[2]+=1;
    }
  }
  cout << m[2];
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#define For(i,a,b) for(int i=a;i<=b;++i)
#define Forr(i,a,b) for(int i=a;i<b;++i)
#define Ford(i,a,b) for(int i=a;i>=b;--i)
#define Rep(i,a) for(int i=1;i<=a;++i)
#define Repp(i,a) for(int i=0;i<a;++i)
#define Repd(i,a) for(int i=a;i;--i)
#define F first
#define S second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1e5+5;
const int mod = 1e9+7;
string t = "BW";
string s;
int n, l, cur = 1;
void End(){
	cout << 0;
	exit(0);
}
int Pow(int a, int b){
	int c = 1;
	for(; b; b>>=1, a=(1ll*a*a)%mod){
		if(b&1) c = (1ll*c*a)%mod;
	}
	return c;
}
int main(){
	ios_base::sync_with_stdio(NULL);
	cin. tie(NULL); cout. tie(NULL);
//	freopen(".inp" , "r", stdin);
//	freopen(".out", "w", stdout);
    cin >> n >> s;
    Repp(i,n+n){
		int temp = t.find(s[i]);
		if((l&1)==temp){
			++l;
		}else{
			cur = (1ll*cur*l)%mod;
			--l;
			if(l<0) End();
		}
    }
    if(l) End();
    Rep(i,n)cur = (1ll*cur*i)%mod;
    cout << cur;
    return 0;
}

Measured memory_bytes: 720
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) begin(x),end(x)
#define msi map<string,int>
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define sh short int
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const int inf = 1e9+9;
const int mod = 1e9+7;
const int shift = 2e6;
int a[9];
int main(){
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0] == a[1] && a[0] != a[2]){
        cout<<"Yes"<<endl;
    }
  	else if(a[1] == a[2] && a[1] != a[0]){
      cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
#define MAX 1001000
    int n; //来場者数
    int a[MAX]; //来場者の年齢

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

        for(int i = 0; i < n; i++)
            cin >> a[i];
        
        int c0 = 0, c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0;
        //10代未満の人数、10代の人数、20代の人数、30代の人数、40代の人数、50代の人数、60歳以上の人数
        for(int i = 0; i < n; i++){
            if(a[i] < 10) 
                c0++;
            else if(10 <= a[i] && a[i] < 20)
                c1++;
            else if(20 <= a[i] && a[i] < 30)
                c2++;
            else if(30 <= a[i] && a[i] < 40)
                c3++;
            else if(40 <= a[i] && a[i] < 50)
                c4++;
            else if(50 <= a[i] && a[i] < 60)
                c5++;
            else
                c6++;
        }
        cout << c0 << endl;
        cout << c1 << endl;
        cout << c2 << endl;
        cout << c3 << endl;
        cout << c4 << endl;
        cout << c5 << endl;
        cout << c6 << endl;
    }
}


Measured memory_bytes: 6988
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 10200,mo=1e9+7;
int n,head[N],to[N],nxt[N],edgenum;
void ADD(int u, int v){
	to[++edgenum]=v;nxt[edgenum]=head[u];head[u]=edgenum;
}
void add(int &x, int y){x=x+y<mo?x+y:x+y-mo;}
int sz[N],s[N],len,f[2][5050],fac[N],ifac[N];
void dfs(int u, int fa, Pii &r){
	sz[u]=1;int mx=0;
	L(i,u)if(to[i]!=fa)dfs(to[i],u,r),sz[u]+=sz[to[i]],mx=max(mx,sz[to[i]]);
	mx=max(mx,n-sz[u]);r=min(r,Pii(mx,u));
}
int power(int a, int n){
	int res=1;
	while(n){
		if(n&1)res=1LL*res*a%mo;
		a=1LL*a*a%mo;n>>=1;
	}
	return res;
}
int C(int n, int m){return 1LL*fac[n]*ifac[m]%mo*ifac[n-m]%mo;}
int main() {
	read(n);rep(i,1,n-1){int u,v;read(u);read(v);ADD(u,v);ADD(v,u);}
	Pii r(1e9,0);dfs(1,0,r);int rt=r.se;dfs(rt,0,r);
	L(i,rt)s[++len]=sz[to[i]];
	fac[0]=1;rep(i,1,n)fac[i]=1LL*fac[i-1]*i%mo;
	ifac[n]=power(fac[n],mo-2);per(i,n-1,0)ifac[i]=1LL*ifac[i+1]*(i+1)%mo;
	f[0][0]=1;//printf("[%d %d %d %d]\n",len,s[1],s[2],s[3]);
	rep(t,1,len){
		int p=t&1,q=p^1;rep(i,0,n)f[p][i]=0;
		rep(i,0,n)if(f[q][i]){
			rep(j,0,s[t])add(f[p][i+j],1LL*f[q][i]*C(s[t],j)%mo*C(s[t],j)%mo*fac[j]%mo);
		}
	}
//	rep(i,0,n)printf("%d:%d\n",i,f[len&1][i]);
	ll res=0;rep(i,0,n)res+=1LL*f[len&1][i]*(i&1?-1:1)*fac[n-i]%mo;cout<<(res%mo+mo)%mo;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#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()
typedef long long ll;

int main(){
    int N,M;cin >> N >> M;
    vector<int> imos(N+10);
    rep(i,M){
        int L,R;
        cin >> L >> R;
        L--;
        imos[L]+=1;
        imos[R]-=1;
    }
    rep(i,N+1){
        imos[i+1]+=imos[i];
    }
    int cnt =0;
    rep(i,N+1){
        if(imos[i]==M)cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep (i, n) {
        cin >> a[i];
    }
    sort(all(a), greater<ll>());
    ll ans = 0;
    rep (i, n-1) {
        int idx = (i + 1) / 2;
        ans += a[idx];
    }
    cout << ans << endl;
}




Measured memory_bytes: 4836
#include<cstdio>
using namespace std;

int main() {
  int n,ans;
  while(1) {
    scanf("%d",&n);
    if(!n) break;
    ans = 0;
    for(int i=3; i<47; i+=2)
      if(n%i==0 && n/i > i/2) {
	ans++;
      }

    for(int i=2; i<47; i+=2) {
      if(n%i!=0 && (n*2)%i==0 && n/i >= i/2) {
	ans++;
      }
    }

    printf("%d\n",ans);
  }
}

Measured memory_bytes: 0
n=int(input())
Alist=[int(i) for i in input().split(" ")]
Blist=[int(i) for i in input().split(" ")]
sumA=sum(Alist)
sumB=sum(Blist)
Dlist=[]
muinus=0
muinus_num=0
count=0
if sumA<sumB:
    print(-1)
else:
    for i in range(n):
        AB=Alist[i]-Blist[i]
        Dlist.append(AB)
        if AB<0:
            muinus+=AB
            muinus_num+=1
    Dlist.sort(reverse=True)
    while muinus<0:
        muinus+=Dlist[count]
        count+=1
    print(muinus_num+count)

Measured memory_bytes: 19284
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

int main(){
	long x;
	cin>>x;
	double y = sqrt(2*x);
	long n = floor(y);
	if((n*(n+1))/2 >= x)
		cout<<n<<endl;
	else cout<<n+1<<endl;
	return 0;
}

Measured memory_bytes: 256
//
// Created by 佐竹俊哉 on 2019/11/11.
//

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"("<<p.first<<","<<p.second<<")";
    return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os<<"{";
    rep(i, v.size()) {
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

int main() {
    int X; cin >> X;
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            if (X == i * j) {
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
exception Error of string
let err s = raise (Error s)

let rec solve () =
    let x, y = Scanf.scanf "%d %d " (fun x y -> x, y) in
    if x != 0 || y != 0 then (
        if x < y then
            Printf.printf "%d %d\n" x y
        else
            Printf.printf "%d %d\n" y x;
        solve ()
    )

let _ = solve ()


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, bool> pi;
typedef pair<int, pi> pii;
#define f first
#define s second
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int n;
ll arr[200005];
map<pii, ll> memo;

ll dp(ll idx, ll taken, bool pre) {
	if (idx == n+1) {
		if (taken == n/2) return 0;
		else return (ll) -1e16;
	}
	if (taken + (n - idx + 2)/2 < n/2) return -1e16;
	pii cur = pii(idx, pi(taken, pre));
	if (memo.find(cur) != memo.end()) return memo[cur];
	
	ll ans = dp(idx+1, taken, 0);
	if (!pre) ans = max(ans, dp(idx+1, taken+1, 1) + arr[idx]);
	return memo[cur] = ans;
}

int main() {
	fastio; cin >> n;
	FOR(i, 1, n) cin >> arr[i];
	cout << dp(1, 0, 0);
}

Measured memory_bytes: 67652
#define _CRT_SECURE_NO_WARNINGS
#define NOMINMAX
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INF = (int) 1e9;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.00001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	set<tuple<int, int, int>> st;
	int a, b, c, cnt = 0;
	cin >> a >> b >> c;
	while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0 && st.find(make_tuple(a, b, c)) == st.end()) {
		st.insert(make_tuple(a, b, c));
		int na = b / 2 + c / 2;
		int nb = c / 2 + a / 2;
		int nc = a / 2 + b / 2;
		a = na;
		b = nb;
		c = nc;
		cnt++;
	}
	if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) cout << cnt << endl;
	else cout << -1 << endl;
	return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            decimal oddCount = 0;
            decimal evenCount = 0;

            foreach (var item in Enumerable.Range(1, N))
            {
                if (item % 2 == 0)
                    evenCount++;
                else
                    oddCount++;
            }

            Console.WriteLine(oddCount / N);
        }
    }

}


Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N, M, S;
ll U[200], V[200], A[200], B[200];
ll C[100], D[100];
ll d[100][5000];

struct edge {
    ll to, fare, time;
};

vector<edge> G[100];

typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

void dijkstra()
{
    priority_queue<PP, vector<PP>, greater<PP>> que;
    rep(i, 0, 100)
    {
        rep(j, 0, 5000)
        {
            d[i][j] = INF;
        }
    }

    d[1][S] = 0;

    que.push(PP(0, P(1, S)));

    while (!que.empty()) {
        auto p = que.top();
        que.pop();

        auto state = p.second;
        auto city_num = state.first;
        auto coin = state.second;

        auto cur_d = d[city_num][coin];
        if (cur_d < p.first)
            continue;

        if (coin + C[city_num] <= 2500) {
            ll ncoin = coin + C[city_num];
            ll ntime = cur_d + D[city_num];
            if (d[city_num][ncoin] > ntime) {
                d[city_num][ncoin] = ntime;
                que.push(PP(d[city_num][ncoin], P(city_num, ncoin)));
            }
        }

        auto city = G[city_num];

        for (ll i = 0; i < city.size(); i++) {
            auto e = city[i];
            ll c = C[city_num];
            ll dd = D[city_num];
            auto nextCoin = min(coin - e.fare, 2500LL);
            if (nextCoin < 0)
                continue;

            if (d[e.to][nextCoin] > cur_d + e.time) {
                d[e.to][nextCoin] = cur_d + e.time;
                que.push(PP(d[e.to][nextCoin], P(e.to, nextCoin)));
            }
        }
    }
}

int main()
{
    cin >> N >> M >> S;
    chmin(S, 2500LL);

    repe(i, 1, M)
    {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        G[u].push_back(edge { v, a, b });
        G[v].push_back(edge { u, a, b });
    }

    repe(i, 1, N)
    {
        cin >> C[i] >> D[i];
    }

    dijkstra();

    repe(i, 2, N)
    {
        ll ans = INF;
        repe(j, 0, 2500)
        {
            if (d[i][j] != INF) {
                ans = min(ans, d[i][j]);
            }
        }
        cout << ans << endl;
    }
}


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


int main()
{
    long long int  m, n, cnt=0, rem;
    cin >> n;
    long long int a[n+1], b[n];
    for(int i=0; i<n+1; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];
    for(int i=0; i<n; i++)
    {
        if(a[i]<b[i])
        {
            cnt+=a[i];
            rem = b[i]-a[i];
            if(rem>a[i+1])
            {
                cnt+=a[i+1];
                a[i+1] = 0;
            }
            else
            {
                a[i+1]-=rem;
                cnt += rem;
            }
        }
        else
        {
            cnt+=b[i];
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1792
#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;
typedef pair<int, int> P;

const ll INF = 1LL << 60;

int main() {
    ll N; cin >> N;
    vector<ll> P(N), Q(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    vector<ll> v;
    rep(i, N) v.push_back(i + 1);

    ll a = 0, b = 0, cnt = 0; 

    string a_str = "", b_str = "";
    rep(i, N) a_str += to_string(P[i]);
    rep(i, N) b_str += to_string(Q[i]);
    fprintf(stderr, "%s %s\n", a_str.c_str(), b_str.c_str());

    do {
        cnt++;
        string target_str = "";
        for (int i = 0; i < v.size(); i++) {
            // cout << v[i] << " ";
            target_str += to_string(v[i]);
        }
        fprintf(stderr, "target_str: %s\n", target_str.c_str());
        if (target_str == a_str) {
            a = cnt;
        }
        if (target_str == b_str) {
            b = cnt;
        }
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(a - b) << endl;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

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

    if(x<=3){
        cout<<x<<endl;
        return 0;
    }

    if(x%2==0){
        x++;
    }

    for(int i=x;i<=100010;i+=2){
        bool jdg=true;
        for(int j=3;j<=sqrt(i);j++){
            if(i%j==0){
                jdg=false;
                break;
            }
        }
        if(jdg){
            cout<<i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n;
int v[200001];

struct _edge {
    int x, c;
    _edge(int x, int c) : x(x), c(c) {}
};

vector<_edge> edge[200001];

struct _es {
    int a, b;
    llong c;
    bool operator<(const _es &e) const {
        return c < e.c;
    }
    _es(int a, int b, llong c) : a(a), b(b), c(c) {}
};
vector<_es> es;

int del[200001];
int sz[200001];
llong dist[200001];

void dfs(int x, int p) {
    sz[x] = 1;
    for (_edge i : edge[x]) {
        if (i.x == p) continue;
        if (del[i.x]) continue;
        dfs(i.x, x);
        sz[x] += sz[i.x];
    }
}

pll dfs2(int x, int p) {
    pll ret(dist[x] + v[x], x);
    for (_edge i : edge[x]) {
        if (i.x == p) continue;
        if (del[i.x]) continue;
        dist[i.x] = dist[x] + i.c;
        ret = min(ret, dfs2(i.x, x));
    }
    return ret;
}

void dfs3(int x, int p, llong d, int t) {
    es.emplace_back(x, t, d + dist[x] + v[x]);
    for (_edge i : edge[x]) {
        if (i.x == p) continue;
        if (del[i.x]) continue;
        dfs3(i.x, x, d, t);
    }
}

void centroid(int x) {
    dfs(x, 0);
    int s = sz[x], p = 0, loop = 1;
    while (loop) {
        loop = 0;
        for (_edge i : edge[x]) {
            if (i.x == p) continue;
            if (del[i.x]) continue;
            if (s < (sz[i.x] << 1)) {
                loop = 1;
                p = x;
                x = i.x;
                break;
            }
        }
    }
    
    dist[x] = 0;
    pll ret = dfs2(x, 0);
    dfs3(x, 0, ret.first, ret.second);
    del[x] = 1;
    
    for (_edge i : edge[x]) {
        if (del[i.x]) continue;
        centroid(i.x);
    }
}

int par[200001];
int find(int x) {
    if (par[x]) return par[x] = find(par[x]);
    return x;
}

int merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return 0;
    par[x] = y;
    return 1;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> v[i];
	for (int i = 1; i < n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        edge[a].emplace_back(b, c);
        edge[b].emplace_back(a, c);
	}
	
	centroid(1);
	sort(es.begin(), es.end());
	llong ans = 0;
	for (_es i : es) {
        if (merge(i.a, i.b)) ans += i.c;
	}
    printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 95076
#include<bits/stdc++.h>
#include<stdio.h>
#include<vector>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define vll vector<long long int>
#define endl "\n"
#define FOR(x) for(int i=0; i<x; i++)
#define sortV(x) sort(x.begin(), x.end())
#define sortA(x) sort(x, x+(sizeof(x)/sizeof(x[0])))
#define arrsige(x) (sizeof(x)/sizeof(x[0]))
#define vsige(x) x.size()
#define pb push_back
#define ll long long int
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define yess cout << "Yes" << endl
#define noo cout << "No" << endl


using namespace std;


void prnt(vector<long long int> v)
{
    cout << endl << endl << "vector size: " << v.size() << "  \nthe vector: " ;

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


    cout << endl << endl;
}


void solve()
{
    vll v;
    long long int n, k;
    cin >> n >> k;
    for(int i=0; i<n; i++)
    {
        long long int x;
        cin >> x;
        v.push_back(x);
    }

    long long int s=0;

    sortV(v);

    for(int i=0; i<k ;i++)
    {
        s+= v[i];
    }

    cout << s;
}




int main()
{
    IOS;
    int tc=1;
    //cin >> tc;
    while(tc--)
    {
        solve();
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3624
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int N,d,x,ans;
 	cin >> N>>d>>x;
 	int a[N];
 	for (int i = 0; i < N; i++) {
 		cin >> a[i];
 	}for (int i = 0; i < N; i++) {
 		if(d%a[i]==0){
 			ans=ans+d/a[i];
 		}else{
 			ans=ans+1+d/a[i];
 		}
 	}
 	cout << ans+x << endl;
 }

Measured memory_bytes: 256