akhauriyash/Code-Regression huggingface dataset:
#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 MX              200005
#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 pw(b,p)         pow(b,p) + 0.1
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;

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int32_t main()
{
    //c_p_c();
    string s,t; cin>>s>>t;

    int ans=0;

    map<char,vi> idval;

    int n = s.length();

    for(int i=0;i<s.length();++i)
    {
        idval[s[i]].pb(i+1);
    }

    for(auto ch : t)
    {
        if(idval[ch].empty())
        {
            cout<<-1<<'\n';
            return 0;
        }
        int id = ans%n;

        auto it = upper_bound(idval[ch].begin(), idval[ch].end(),id);

        if(it==idval[ch].end())
            ans += idval[ch][0] + n - id;

        else
            ans += (*it) - id;

    }

    cout << ans << '\n';
    return 0;
}

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

long long cut_times(long long *logs, long long cut_len, int log_num);

int main() {
    int N,K;
    cin >> N >> K;
    long long logs[N];
    long long max_long = 0;

    for(int i = 0;i<N;i++){
        cin >> logs[i];
        if(logs[i] > max_long) {
            max_long = logs[i];
        }
    }
    if(K==0){
        cout << max_long;
        return 0;
    }

    long long start = 1;
    long long end = max_long;
    long long mid;

    while(start<end){
        mid = (start + end)/2;
//        cout << "mid: " << mid << endl;
//        cout << cut_times(logs, mid, N) << endl;
        if(cut_times(logs, mid, N)<=K){
            end = mid;
        }else if(cut_times(logs, mid, N)>K){ //cut times equals to k, still need to try a smaller one to find min(max)
            start = mid+1;
        }

    }

    cout << start;

}

// Given max cut length, get needed cut times
long long cut_times(long long *logs, long long cut_len, int log_num){
    long long  need_times = 0;
    for(int i = 0;i<log_num;i++){
        if(*logs%cut_len==0){
            need_times += *logs/cut_len-1;
        }else{
            need_times += *logs/cut_len;
        }
        logs++;
    }
    return need_times;
}


Measured memory_bytes: 4584
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class ATakoyaki {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int t = Integer.parseInt(in.next());
            int ans = ((a + b - 1) / b) * t;

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 35644
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep(i,n)    for(ll i=1; i<=n; i++)
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
using namespace std;

int main()
{
    godspeed
    ll i,j,n,x;
    cin>>n;
    vector<ll>a(n),b(n);
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    b=a;
    sort(a.begin(),a.end());
    ll medo=a[n/2-1],mede=a[n/2];
    for(i=0; i<n; i++)
    {
        if(b[i]<=medo)
        {
            cout<<mede<<endl;
            continue;
        }
        if(b[i]>=mede)
            cout<<medo<<endl;

    }

    return 0;
}





Measured memory_bytes: 6352
#include<bits/stdc++.h>
using namespace std;
typedef vector<int>V;
int main(void){
	int n;
	int box[101];
	int i,j;
	int flg[101];
	int flag;
	int x,y;
	V v;
	while(1){
		cin>>n;
		if(n==0)	break;
		for(i=0;i<n+1;i++){
			cin>>box[i];
			flg[i]=0;
		}
		for(i=0;i<n+1;i++){
			flg[i]=1;
			v.clear();
			for(j=0;j<n+1;j++){
				if(flg[j]==0){
					v.push_back(box[j]);
				}
			}
			//for(j=0;j<(int)v.size();j++)	cout<<v[j]<<" ";	cout<<endl;
			flag=0;
			x=v[1]-v[0];
			for(j=1;j<(int)v.size()-1;j++){
				y=v[j+1]-v[j];
				if(x!=y){
					flag=1;
					break;
				}
				y=x;
			}
			if(flag==0){
				break;
			}
			flg[i]=0;
		}
		cout<<box[i]<<endl;
	}
	return 0;
}
			
				
	


Measured memory_bytes: 3156
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,k;
int arr[5005];
bitset<5005> memo1[5005],memo2[5005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>k;
	rep(x,0,n) cin>>arr[x];
	
	memo1[0][0]=1;
	rep(x,0,n){
		rep(y,0,k){
			memo1[x+1][y]=memo1[x][y];
			if (y>=arr[x] && memo1[x][y-arr[x]]) memo1[x+1][y]=1;
		}
	}
	
	memo2[n][0]=1;
	rep(x,n,0){
		rep(y,0,k){
			memo2[x][y]=memo2[x+1][y];
			if (y>=arr[x] && memo2[x+1][y-arr[x]]) memo2[x][y]=1;
		}
	}
	
	int ans=n;
	vector<int> stk;
	rep(x,0,n){
		stk.clear();
		
		rep(y,0,k) if (memo1[x][y]) stk.push_back(y);
		
		//need to be between [k-arr[x],k)
		rep(y,0,k) if (memo2[x+1][y]){
			while (!stk.empty() && stk.back()+y>=k) stk.pop_back();
			
			if (!stk.empty() && stk.back()+y>=k-arr[x]){
				ans--;
				break;
			}
		}
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 9892
#include<iostream>
#include<vector>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define var(i) long long(i)
vector<long long> t;
var(ans) = 1;
long long gcd(var(a), var(b)) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}
void kbs(int n) {
	rep(i, n) {
		ans = ans / gcd(ans, t[i]) * t[i];
	}
}
int main() {
	int n;
	cin >> n;
	t.resize(n);
	rep(i, n) {
		cin >> t[i];
	}
	kbs(n);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll a[200004],pre[200004],bac[200004];
int main(){
    scanf("%d",&n);
    pre[0]=0;
    bac[n+1]=0;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)pre[i]=max(a[i],pre[i-1]);
    for(int i=n;i;i--)bac[i]=max(a[i],bac[i+1]);
    for(int i=1;i<=n;i++){
        printf("%d\n",max(pre[i-1],bac[i+1]));
    }

    return 0;
}



Measured memory_bytes: 6272
#include<bits/stdc++.h>
#define N 100100
using namespace std;
inline void read(long long &x)
{
	x=0;
	static long long p;p=1;
	static char c;c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-48);c=getchar();}
	x*=p;
}
long long n;
long long dis[N];
long long sum;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	for(long long i=1;i<=n;i++)
		read(dis[i]);
	for(long long i=1;i<=n+1;i++)
		sum+=abs(dis[i]-dis[i-1]);
	for(long long i=1;i<=n;i++)
	{
		if(i==1)printf("%lld\n",sum-abs(dis[1])-abs(dis[i+1]-dis[i])+abs(dis[2]));
		else 
		if(i>1&&i<n)printf("%lld\n",sum-abs(dis[i]-dis[i-1])-abs(dis[i+1]-dis[i])+abs(dis[i-1]-dis[i+1]));
		else printf("%lld\n",sum-abs(dis[i]-dis[i-1])-abs(dis[i])+abs(dis[i-1]));
	}
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace tr1;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;
typedef long long ll;
typedef pair<int,int> pii;

int w, h;
inline bool get(ll S, int y, int x) {
  return S>>(y*w+x)&1;
}
inline ll bit(int y, int x) {
  return 1LL<<(y*w+x);
}
inline bool ok(ll S, int y, int x) {
  if (y<0||y>=h||x<0||x>=w) return 0;
  if (get(S,y,x)) return 0;
  return 1;
}
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

bool visited[7][7];
int sy,sx;
unordered_map<ll, int> mp[7][7];
bool dfs(ll S, int y, int x, int num) {
//  if (num < 30) {
  // if (y) { 
    if (mp[y][x].count(S)) return 0;
    mp[y][x][S] = 1;
  // }
//  }
  // cout << y << "," << x << "," << num << endl;
  // REP(i,h) {
  //   REP(j,w) cout << get(S,i,j);
  //   cout << endl;
  // }
  if (num == 0) {
    return abs(y-sy)+abs(x-sx) == 1;
  }
  // BFSして領域が2つあったらだめ
  {
    REP(i,h)REP(j,w)visited[i][j]=0;
    REP(i,h)REP(j,w) {
      if (get(S,i,j)) continue;
      queue<pii>Q;
      Q.push(pii(i,j));
      visited[i][j] = 1;
      int cnt = 0;
      while(!Q.empty()) {
        pii p = Q.front(); Q.pop();
        ++cnt;
        REP(k,4) {
          int ii=p.first+dy[k];
          int jj=p.second+dx[k];
          if (!ok(S,ii,jj)) continue;
          if (visited[ii][jj]) continue;
          visited[ii][jj] = 1;
          Q.push(pii(ii,jj));
        }
      }
      if (cnt != num) return 0;
      goto next;
    }
  next:;
  }
  {
    // 今の場所と最初の場所以外で凸の部分があったらだめ
    int cnt = 0;
    REP(i,h)REP(j,w) {
      if (get(S,i,j)) continue;
      int c = 0;
      REP(k,4) {
        int ii=i+dy[k];
        int jj=j+dx[k];
        if (!ok(S,ii,jj)) {
          if (ii!=y||jj!=x) {
            if (ii!=sy||jj!=sx) {
              ++c;
            }
          }
        }
      }
      if (c >= 3) {
        ++cnt;
      }
    }
    if (cnt >= 1) return 0;
  }
  REP(k,4) {
    int yy=y+dy[k];
    int xx=x+dx[k];
    if (!ok(S,yy,xx)) continue;
    if (dfs(S|bit(yy,xx),yy,xx,num-1)) return 1;
  }
  return 0;
}

int main() {
  while(cin>>w>>h,w||h) {
    ll S = 0;
    int num = 0;
    REP(i,h) REP(j,w) {
      int a; cin >> a;
      if (a) S |= bit(i,j);
      else {
        sy=i,sx=j;
        ++num;
      }
    }
    if (num <= 3) {               // 空きマスが3以下
      puts("No");
      continue;
    }
    S |= bit(sy,sx); --num;
    REP(i,h)REP(j,w) mp[i][j].clear();
    cout << (dfs(S,sy,sx,num)?"Yes":"No") << endl;
  }
}

Measured memory_bytes: 25240
r, c = map(int, input().split())

matrix = [list(map(int, input().split())) for _ in range(r)]

for i in range(r):
    matrix[i].append(sum(matrix[i]))

matrix.append(list(map(sum, zip(*matrix))))
# matrix.append([sum(i) for i in zip(*matrix)])

for row in matrix:
    print(' '.join(str(e) for e in row))


Measured memory_bytes: 5700
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];

    vector<int> can;
    can.push_back(0);
    int KK = 0;
    rrep(h, 0, 63) {
        int c = 0;
        rep(i, 0, N) {
            if (A[i] >> h & 1) { c++; }
        }
        // 7 -> 3
        if (c <= N / 2) { KK |= (1LL << h); }
        if (KK > K) { KK ^= (1LL << h); }
        can.push_back(KK);
    }

    dump(can);
    int maxx = 0;
    for (auto k : can) {
        int x = 0;
        rep(i, 0, N) { x += k ^ A[i]; }
        dump(x);
        chmax(maxx, x);
    }
    cout << maxx << endl;
    return 0;
}

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

int main(){

  int N,num,ans=0;
  cin >> N;
  string S;
  cin >> S;
  bool A[26], B[26];

  for(int i=1; i<S.size()-1; i++){

    num = 0;

    for(int j=0; j<26; j++){
      A[j] = false;
      B[j] = false;
    }

    for(int j=0; j<i; j++){
      A[S[j]-'a'] = true;
    }
    for(int j=i; j<S.size(); j++){
      B[S[j]-'a'] = true;
    }

    for(int j=0; j<26; j++){
      if(A[j] && B[j]) num++;
    }

    ans = max(ans, num);

  }

  cout << ans << endl;

  return 0;
}


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

int main() {
    long long int n, a, b, d, a_left, a_right, b_left, b_right, ans[4] = {0};
    cin >> n >> a >> b;
    d = abs(a-b);
    if(d%2 == 0) {
        ans[0] = d/2;
    } else {
        a_left = a - 1;
        a_right = n - a;
        b_left = b - 1;
        b_right = n - b;
        ans[0] = a_right;
        ans[1] = b_left;
        ans[2] = (d-1)/2 + 1 + a_left;
        ans[3] = (d-1)/2 + 1 + b_right;
        sort(ans, ans + 4);
    }
    cout << ans[0] << '\n';
}


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

double W, H, x, y;

void solve()
{
	cout << setprecision(10) << (double)W*H/2.0 << " ";
	if(x==W/2.0 && y==H/2.0){
		cout << 1 << endl;		
	}else{
		cout << 0 << endl;
	}
}

int main()
{
	cin >> W >> H >> x >> y;
	solve();
	return 0;
}


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

int main(){
  string N;
  int K;
  cin >> N >> K;
  vector<bool> flag(10,true);
  int D;
  for(int i=0;i<K;i++){
    cin >> D;
    flag.at(D)=false;
  }
  bool carry=false;
  deque<int> ans;
  int x,j,mi;
  for(int i=0;i<=9;i++){
    if(flag.at(i)){
      mi=i;
      break;
    }
  }
  for(int i=N.size()-1;i>=0;i--){
    x=N.at(i)-'0';
    if(carry){
      x++;
      if(x==10){
        x=0;
      }else{
        carry=false;
      }
    }
    if(flag.at(x)){
      ans.push_front(x);
    }else{
      for(j=x+1;j<=9;j++){
        if(flag.at(j)){
          ans.assign(ans.size(),mi);
          ans.push_front(j);
          break;
        }
      }
      if(j==10){
        carry=true;
        for(j=0;j<x;j++){
          if(flag.at(j)){
            ans.assign(ans.size(),mi);
            ans.push_front(j);
            break;
          }
        }
      }
    }
  }
  if(carry){
    if(flag.at(1)){
      ans.push_front(1);
    }else{
      for(int i=2;i<=9;i++){
        if(flag.at(i)){
          ans.assign(ans.size(),mi);
          ans.push_front(i);
          break;
        }
      }
    }
  }
  for(int i=0;i<ans.size();i++){
    cout << ans.at(i);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3596
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cin4(x, y, z, _) cin >> x >> y >> z >> _
#define cin5(x, y, z, p, q) cin >> x >> y >> z >> p >> q
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define Test ll _t cin1(_t); rep(i, 0, _t)

struct point{    int x, y, ind;   char ch;  };
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//ll rnd(ll x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
bool cmp(point A, point B){   if(A.x != B.x) ret(A.x < B.x);  ret(A.y < B.y);   }
// head collected

ll n, m, _, __, u, v;
string str;
char ara_a[55][55];
char ara_b[55][55];

bool check(ll u, ll v){
    rep(i, 1, m+1)
        rep(j, 1, m+1)
            if( ara_b[ i ][ j ] != ara_a[ i + u - 1 ][ j + v - 1 ] )
                ret(false);

    ret(true);
}

bool solve()
{
    rep(i, 0, n-m+1)
        rep(j, 0, n-m+1)
            if ( ara_a[ i ][ j ] == ara_b[ i ][ j ] )
                if( check(i, j) )
                    ret(true);

    ret(false);
}

start;

    cin1(str);

    if( str[ 0 ] == str[ 1 ] && str[ 1 ] == str[ 2 ])
        coul("No");
    else
        coul("Yes");


finish


Measured memory_bytes: 256
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[][] r = new int[M][2];
        for (int i = 0; i < M; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            r[i][0] = a;
            r[i][1] = b;
        }
        Arrays.sort(r, (a,b)->a[0]-b[0] != 0 ? a[0]-b[0] : a[1]-b[1]);
        int ans = 1;
        int nowA = r[0][0];
        int nowB = r[0][1];
        for (int i = 1; i < M; i++) {
            if (nowA < r[i][1] && r[i][0] < nowB) {
                nowA = Math.max(nowA,r[i][0]);
                nowB = Math.min(nowB,r[i][1]);
            } else {
                ans++;
                nowA = r[i][0];
                nowB = r[i][1];
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 95300
#import numpy as np
#import functools
#import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm
#import collections as C #most_common

#N = int(input())
N,K= map(int,input().split())
P = list(map(int,input().split()))
#S= str(input())

P.sort()


a=sum(P[0:K])
print(a)


Measured memory_bytes: 9168
#include<bits/stdc++.h>
#define abs abs_

using namespace std;

const int N=500005;

template<class I>void gi(I&x){
	static char c;
	for(c=getchar();c<'0'||c>'9';c=getchar());
	for(x=0;c<='9'&&c>='0';c=getchar())x=x*10+(c&15);
}
inline int abs(int x){return x<0?-x:x;}

int n,D,d[N],v[N],g[N],Q,m;

int main(){
	gi(n),gi(D),v[0]=D;
	for(int i=1;i<=n;i++)
		gi(d[i]),v[i]=min(v[i-1],abs(v[i-1]-d[i]));
	g[n+1]=1;
	for(int i=n;i>=1;i--)
		if(d[i]<2*g[i+1])
			g[i]=g[i+1]+d[i];
		else
			g[i]=g[i+1];
	gi(Q);
	while(Q--){
		gi(m);
		if(g[m+1]<=v[m-1])
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

LL a, b, c;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z)                                                        \
  cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z  \
       << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair< int, int >
#define ld long double
using namespace std;
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;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, K;
  cin >> N >> K;
  int ans = 0;
  REP(i, N) {
    int p;
    cin >> p;
    if (p >= K)
      ans++;
  }
  print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int> a(n, 0);
	rep (i, n){
		cin >> a[i];
	} // end rep

	deque<int> d;
	rep (i, n){
		if (i % 2 == 0){
			d.push_front(a[i]);
		}else{ // if (i % 2 != 0)
			d.push_back(a[i]);
		} // end if
	} // end rep

	if (n % 2 == 0){
		for (int i = n - 1; i >= 0; --i){
			cout << d[i] << (i != 0 ? ' ' : '\n');
		} // end for
	}else{
		rep (i, n){
			cout << d[i] << (i != n - 1 ? ' ' : '\n');
		} // end rep
	} // end if

	return 0;
}

Measured memory_bytes: 3840
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 998244353

long long int comb[4010][4010] = {};
long long int modpow2[4010] = {};

long long int getdupcomb(int n, int r)
{
	if(n + r - 1 < 0) return 1;
	if(r < 0) return 0;
	return comb[n + r - 1][r];
}

int main()
{
	comb[0][0] = 1;
	comb[1][0] = comb[1][1] = 1;
	modpow2[0] = 1;
	modpow2[1] = 2;
	for(int i = 2; i <= 4000; i++){
		comb[i][0] = 1;
		for(int j = 1; j <= i; j++){
			comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % mod;
		}
		modpow2[i] = (2 * modpow2[i - 1]) % mod;
	}

	int k, n;
	cin >> k >> n;

	for(int i = 2; i <= 2 * k; i++){
		// cout << i << endl;
		// 同時に出てはいけないペアの数は p = (min(i - 1, k) - max(1, i - k) + 1) / 2
		// またiが偶数の時は値i / 2は0回か1回しか出てはいけない
		// なおiが偶数の時、同時に出てはいけないペアの中に i / 2 は含まれていない
		int cnt = min(i - 1, k) - max(1, i - k) + 1;
		int p = cnt / 2;
		// cout << cnt << " " << p << endl;

		long long int ans = 0;
		for(int j = 0; j <= p; j++){
			// 制約のある値のペアp個のうち、j種類がでるとする
			// このとき出る値j種類の選び方は pCj * 2^j (tmp1とする)
			// (k - cnt + j個の値からj種類をそれぞれ1つ以上選んでn個選ぶ方法)
			//  = k - cnt + j 個から n - j個選ぶ方法 (tmp2とする)
			long long int tmp1 = (comb[p][j] * modpow2[j]) % mod;
			long long int tmp2 = getdupcomb(k - cnt + j, n - j);
			// iが偶数のときはn個の中でi / 2が出た場合も考えないとダメ
			if(i % 2 == 0) tmp2 = (tmp2 + getdupcomb(k - cnt + j, n - j - 1)) % mod;
			ans = (ans + (tmp1 * tmp2) % mod) % mod;
			// cout << j << " " << tmp1 << " " << tmp2 << endl;
		}
		cout <<  ans << endl;
	}
}

Measured memory_bytes: 123904
import math

N = int(input())
names = []
for i in range(N):
  names.append(input()[0])
  
conbi = []  
count = 0
ans = 0

while count< 2** 5:
  twodig = bin(count)
  list_td = list(twodig)
  list_tdc = list_td[2:]
  while len(list_tdc) < 5:
    list_tdc.insert(0, "0")
  conbi.append(list_tdc)
  count+= 1
  
conbi2 = list(filter(lambda x: x.count("1") == 3, conbi))

m = names.count("M")
a = names.count("A")
r = names.count("R")
c = names.count("C")
h = names.count("H")

MARCH = [m, a, r, c, h]

for x in conbi2:
  p = x.index("1")
  x[p] = "0"
  q = x.index("1")
  x[q] = "0"
  r = x.index("1")
  x[r] = "0"
  
  ans+= MARCH[p]* MARCH[q]* MARCH[r]

print(int(ans))

Measured memory_bytes: 4016
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int two = 0, one = 0, zero = 0;

    int m1;
    for (int i = 0; i < n; i++) {
        cin >> m1;
        if (m1 % 4 == 0)
            two++;
        else if (m1 % 2 == 0)
            one++;
        else
            zero++;
    }

    bool flag;
    if (n % 2 == 0) {
        if (zero <= two)
            flag = true;
        else
            flag = false;
    } else {
        if (zero <= two + 1)
            flag = true;
        else
            flag = false;
    }

    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<fstream>
#include<string>
#define rep(i,a,b) for(int (i)=(a);(i)<(b);(i)++)

using namespace std;




int main(void){
	//string fname;
	//cin >> fname;
	//ifstream fin(fname);
	//fname = fname + ".answer";
	//ofstream fout(fname);
	int x, y, s;
	while (true){
		int max_int = 0;
		//fin >> x >> y >> s;
		cin >> x >> y >> s;
		if (x == 0)break;
		rep(i,1,s+1)
			rep(j, 1, s+1){
				int r = i*(100 + x),l=j*(100+x);
				if (r / 100 + l / 100 != s)continue;
				r = i*(100 + y), l = j*(100 + y);
				max_int = max(max_int, r / 100 + l / 100);
			}
	//	fout << max_int << endl;
		cout << max_int << endl;
	}

	//fin.close();
	//fout.close();
	return 0;
}

Measured memory_bytes: 1160
def solve():
    INF = float('inf')

    def max2(x, y): return x if x >= y else y

    N = int(input())
    As = [(A, i) for i, A in enumerate(map(int, input().split()))]

    As.sort(reverse=True)

    dp = [[-INF]*(N+1) for _ in range(N+1)]
    dp[0][0] = 0
    for no, (A, pos) in enumerate(As):
        for i in range(no+1):
            j = no-i
            dp[i+1][j] = max2(dp[i+1][j], dp[i][j] + A*abs(pos-i))
            dp[i][j+1] = max2(dp[i][j+1], dp[i][j] + A*abs(pos-(N-1-j)))

    ans = 0
    for i in range(N+1):
        j = N-i
        ans = max2(ans, dp[i][j])

    print(ans)


solve()


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

int main()
{
    string str;

    cin >> str;

    for( int i = str.size() - 1; i >= 0; i-- )  //格納順と逆に出力
        cout << str[i];
    
    cout << endl;

    return 0;
}



Measured memory_bytes: 3144
n, k = map(int, input().split())

res = 0
for i in range(1, n + 1):
    a = i % k
    b = (-a) % k
    c = (-a) % k
    if (b + c) % k == 0:
        res += ((n + b) // k) * ((n + c) // k)
        
print(res)

Measured memory_bytes: 9116
from collections import deque

N, M = map(int, input().split())
paths = {}
for i in range(1, N+1):
  paths[i]=set()
for i in range(M):
  a, b = map(int, input().split())
  paths[a].add(b)
  paths[b].add(a)

count = 0

def dfs(v, visited):
  global count
  if len(visited) == N:
    count += 1
    return
  for i in paths[v]:
    if i not in visited:
      visited.add(i)
      dfs(i, visited)
      visited.remove(i)
  return

pq = deque()
for i in paths[1]:
  pq.append(i)
  dfs(i, {1, i})
print(count)

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

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str[] = br.readLine().split(" ");
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		int c = Integer.parseInt(str[2]);

		int d = a - b - c;
		if (d < 0) {
			System.out.println(Math.abs(d));
		} else {
			System.out.println(0);
		}
	}
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define IN freopen("alchemy_input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)

#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define i64 long long int
#define ui64 unsigned long long int
#define xx first
#define yy second
#define ln 17
#define off 2

#define sq(x) ((x)*(x))

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace __gnu_pbds;
using namespace std ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int,int> pii;

//#define log 20
#define mod 1000000007LL
#define INF 2000000000
#define maxn 200005

const long double eps = 1e-9 ;

i64 a[maxn] ;

int two[25][75] , five[25][75] ;
int cnt[25] ;

int main()
{
    int n ;

    scanf("%d",&n) ;

    for(int i=1 ; i<=n ; i++)
    {
        char s[55] ;
        scanf("%s",s) ;
        i64 num = 0 , cnt = 0 , fl = 0 ;
        for(int j=0 ; s[j]!='\0' ; j++)
        {
            if(s[j]=='.')
            {
                fl = 1 ;
                continue ;
            }
            cnt += fl ;
            num = num*10 + s[j]-'0' ;
        }
        for(int j=1 ; j<=9-cnt ; j++) num *= 10LL ;
        a[i] = num ;
//        printf("%lld\n",a[i]) ;
    }

    i64 ans = 0 ;

    for(int i=1;  i<=n ; i++)
    {
        int p10 = 0 ;
        while( a[i]%10 == 0 )
        {
            p10++ ;
            a[i] /= 10 ;
        }
        int p2 = 0 , p5 = 0 ;
        while( a[i]%2 == 0 )
        {
            a[i] /= 2 ;
            p2++ ;
        }
        while( a[i]%5 == 0 )
        {
            a[i] /= 5 ;
            p5++ ;
        }
        for(int j=0 ; j<=15 ; j++)
        {
            if( p10+j >= 18 ) ans += cnt[j] ;
            else{

                if( p2 >= 18-(p10+j) ) ans += five[j][ 18-(p10+j) ] ;
                if( p5 >= 18-(p10+j) ) ans += two[j][ 18-(p10+j) ] ;
            }
        }
        cnt[p10]++ ;
        if( p2 > 0 )
        {
            for(int j=p2 ; j>=0 ; j--) two[p10][j]++ ;
        }
        if(p5>0)
        {
            for(int j=p5 ; j>=0 ; j--) five[p10][j]++ ;
        }
     //   printf("%d : %lld %d %d %d\n",i,ans,p10,p2,p5) ;
    }

    printf("%lld\n",ans) ;

    return 0 ;
}


Measured memory_bytes: 5296
#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>;
 
const int INF = 1001001001;
 
int main() {
  int h, n;
  cin >> h >> n;
  vector<int> dp(h+1, INF);
  dp[0] = 0;
  rep(i,n) {
    int a, b;
    cin >> a >> b;

    // 1
    rep(j,h) {
      int nj = min(j+a,h); // 1+8, 9
      dp[nj] = min(dp[nj], dp[j]+b); // dp[9] = min dp[0],dp[1]+b
    }
  }
  cout << dp[h] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int mod = 1000000007;
  cin >> N;
  int A[N] = {0};
  long long sum = 0;
  long long ans = 0;
  for (int i=0; i < N; i++){
    cin >> A[i];
    sum += A[i];
    sum %= mod;
  }
  for (int i=0; i < N; i++){
    sum -= A[i];
    if (sum < 0) sum += mod;
    ans += A[i] * sum;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4364
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string n;
    cin>>n;
    long long int gou=0;
    for(int i=0; i<n.size(); i++){
        gou+=n.at(i)-'0';
    }
    if(gou%9==0 || gou==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3692
#include<stdio.h>
int main()
{

          int X,h,m,s,x,y,z;
          scanf("%d",&X);
          h=X/3600;
          X=X%3600;
          m=X/60;
          X=X%60;
          s=X;
          printf("%d:%d:%d\n",h,m,s);
          return 0;


}



Measured memory_bytes: 2680
N = int(input())
s_min = 100
score = 0
all_10 = True

for _ in range(N):
    tmp = int(input())
    score += tmp
    if tmp % 10 != 0:
        s_min = min(s_min, tmp)
        all_10 = False

if all_10:
    print(0)
else:
    print(score - s_min if score % 10 == 0 else score)

Measured memory_bytes: 38384
import math
import copy
from queue import Queue

n = int(input())
#n, k = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#num = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
# s = [input() for i in range(n)]
#s = input()
# list = list(s)
# dp = [[0 for _ in range(2)] for _ in range(13)]
#s = [input() for i in range(n)]

#a = [[0 for _ in range(n+1)] for _ in range(n+1)]
#b = [[0 for _ in range(n+1)] for _ in range(n+1)]

queue = Queue()
temp = 0

if (n < 10):
    print(n)
else:
    for i in range(1,10):
        queue.put(i)
    for i in range(1,n):
        temp = queue.get()
        if (temp % 10 != 0) :
            queue.put(10 * temp + (temp % 10) - 1)
        queue.put(10 * temp + (temp % 10))
        if (temp % 10 != 9) :
            queue.put(10 * temp + (temp % 10) + 1)
    print(queue.get())



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

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

	for (int i = (x - k + 1); i < (x + k); i++ ) {
		if (i == (x + k - 1)) {
			cout << i << endl;
		} else {
			cout << i << " ";
		}
	}
}


Measured memory_bytes: 256
import sys
N = int(input())
A = [int(v) for v in sys.stdin.readline().split()]

Ax = list(zip(range(1, N + 1), A))
#print(Ax)
Ax.sort(key = lambda x: x[1])
#print(Ax)
result = [r[0] for r in Ax]
for r in result:
    print(str(r) + ' ', end="")
print()


Measured memory_bytes: 20044
d=int(input())
C=list(map(int,input().split()))
S=[]
for i in range(d):
    S.append(list(map(int,input().split())))
T=[]
for i in range(d):
    t=int(input())-1
    T.append(t)


Last=[0]*26

ans=0
for i in range(d):
    t=T[i]
    temp=S[i][t]
    for j in range(26):
        if j==t:
            Last[j]=i+1
        else:
            temp-=C[j]*(i+1-Last[j])
    ans+=temp
    print(ans)
    


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;
    
    i64 N,M;
    cin >> N >> M;
    
    vector<pair<i64,i64>> AB(N);
    rep(i,0,N){
        cin >> AB[i].first >> AB[i].second;
    }
    
    sort(begin(AB),end(AB));
    
    i64 ans=0,cnt=0;
    rep(i,0,N){
        if(cnt>=M){
            break;
        }
        
        i64 num=min(AB[i].second,M-cnt);
        ans+=AB[i].first*num;
        
        cnt+=num;
    }
    
    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

bool isPrime(ll x) {
  if (x == 1) {
    return false; // by definition of prime
  }

  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    vector<ll> nums(100000+1, 0);
    ll c = 0;
    for(ll t = 1; t <= 100000; t+=2){
        if( isPrime(t) && isPrime((t+1)/2)){
            c++;
        }
        nums[t] = c;
        // DEBUG("nums[%lld(%lld)]=%lld", t, (t+1)/2, c );
    }


    ll Q;
    cin >> Q;

    REP(i, Q){
        ll l, r;
        cin >> l >> r;
        //DEBUG("l=%lld, r=%lld", l, r );
        //DEBUG("nums[r]=%lld, nums[l-2]=%lld", nums[r], nums[l-2]);
        if( l >= 2){
            cout << (nums[r] - nums[l-2]) << endl;
        }else{
            cout << (nums[r]) << endl;
        }
    }

    return 0;
}


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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

class UnionFindTree{
    private:
        vector<int> par, rank;
    
    public:
        UnionFindTree(int n) {
            par = rank = vector<int>(n);

            for (int i = 0; i < n; ++i) {
                par[i] = i;
                rank[i] = 0;
            }
        }

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

        void unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return;

            if (rank[x] < rank[y]) {
                par[x] = y;
            } else {
                par[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }

        bool same(int x, int y) {
            return find(x) == find(y);
        }
};

struct Edge
{
    int from, to, cost;

    Edge(int f, int t, int c) {
        from = f;
        to = t;
        cost = c;
    }

    bool operator <(const Edge& e) const {
        return cost < e.cost;
    }

    bool operator >(const Edge& e) const {
        return cost > e.cost;
    }
};

struct Town
{
    int id, x, y;

    Town() {}

    Town(int a, int b, int c) {
        id = a, x = b, y = c;
    }
};


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

    vector<Town> T(N);
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        T[i] = Town(i, x, y);
    }

    priority_queue<Edge, vector<Edge>, greater<Edge>> q;

    sort(T.begin(), T.end(), [](Town a, Town b){ return (a.x < b.x) || (a.x == b.x && a.y < b.y); });

    rep(i, N - 1) {
        Town a = T[i], b = T[i + 1];
        Edge e = Edge(a.id, b.id, b.x - a.x);
        q.push(e);
    }

    sort(T.begin(), T.end(), [](Town a, Town b){ return (a.y < b.y) || (a.y == b.y && a.x < b.x); });

    rep(i, N - 1) {
        Town a = T[i], b = T[i + 1];
        q.push(Edge(a.id, b.id, b.y - a.y));
    }

    UnionFindTree uf = UnionFindTree(N);
    int ans = 0;
    while (!q.empty()) {
        Edge e = q.top(); q.pop();
        int a = e.from, b = e.to;
        if (!uf.same(a, b)) {
            ans += e.cost;
            uf.unite(a, b);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 6132
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli h,w;
    string s;
    vector<string> vec;
    vector<lli> atu;
    lli i,j=0;
    cin>>h>>w;
    rep(i,0,h){
        cin>>s;
        if(s.find('#')!=string::npos){
            vec.push_back(s);
        }
    }
    rep(i,0,w){
        lli find=0;
        rep(j,0,vec.size()){
            if(vec[j][i]=='#'){
                find++;
            }
        }
        if(find!=0){
            atu.push_back(i);
        }
    }
    rep(i,0,vec.size()){
        rep(j,0,atu.size()){
            cout<<vec[i][atu[j]];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; ++i)
        cin >> a[i];

    ll ans = LLONG_MAX;
    for (int i = 0; i < (1 << N); ++i) {
        ll cost = 0;
        int cnt = 0;
        int maxh = 0;
        for (int j = 0; j < N; ++j) {
            if (i & (1 << j)) {
                cnt++;
                cost += max(maxh + 1 - a[j], 0);
                maxh = max(maxh + 1, a[j]);
            } else
                maxh = max(maxh, a[j]);
        }
        if (cnt >= K)
            ans = min(ans, cost);
    }

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


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
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; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
int main(){
    iosetup;
    int N, K; IN(N, K);
    vector<int> a(N);
    rep(i, 0, N) IN(a[i]);

    sort(ALL(a));
    int ans = N, t = 0;
    rrep(i, 0, N){
        if(t + a[i] < K) t += a[i];
        else chmin(ans, i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

#define INX(x) (cin >> x)
#define OUTX(x) (cout << x << endl)

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>


int main()
{
    ll X;
    INX(X);

    ll result = 10 - (X / 200);
    OUTX(result);


    return 0;
}


Measured memory_bytes: 3636
#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 a,b;
    cin >> a >> b;
    if(a<=8&&b<=8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;
#define LL long long

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



Measured memory_bytes: 1664