akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
 // 	freopen("input.txt","r",stdin);
 // 	freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n ,k;
		cin >> n >> k;
		fn{
			cin >> ar[i];
		}
		sort(ar,ar+n);
		int ans=0;
		for(int i =0 ;i < n-k;i++)ans+=ar[i];
			cout << ans<<endl;
	
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 4352
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int sum(vector<vector<long long>> &data, vector<int> &comp,long long G, int n){
    if (n == 0){
        int ans = 0;
        for (long long sub = 0; sub < comp.size(); sub++){
            long long sum = 0;
            int ansi = 0;
            if (comp.at(sub) == 1){
                continue;
            }
            for (long long i = 0; i < comp.size(); i++){
                if (comp.at(i) == 1) {
                    sum += (i + 1) * 100 * data.at(i).at(0) + data.at(i).at(1);
                    ansi += data.at(i).at(0);
                }
            }
            bool less = false;
            for (long long i = 0; i < data.at(sub).at(0); i++){
                if (sum < G && i == data.at(sub).at(0) - 1) {
                    less = true;
                }
                if (sum < G) {
                    sum += (sub + 1) * 100;
                    ansi++;
                }
                else {
                    break;
                }
            }
            if (less) {
                sum += data.at(sub).at(1);
            }
            if (sum < G) {
                ansi = 0;
            }
            if (ans ==  0 || ansi < ans) {
                ans = ansi;
            }
        }
        return ans;
    }
    else {
        comp.at(comp.size() - n) = 0;
        int ans0 = sum(data, comp, G, n - 1);
        comp.at(comp.size() - n) = 1;
        int ans1 = sum(data, comp, G, n - 1);
        if (ans0 == 0){
            return ans1;
        }
        else if (ans1 == 0){
            return ans0;
        }
        return min(ans0, ans1);
    }
}

int main() {
    long long D, G;
    cin >> D >> G;
    vector<vector<long long>> data(D, vector<long long>(2));
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> data.at(i).at(j);
        }
    }
    vector<int> comp(D, 0);
    int ans = sum(data, comp, G, D);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>

int main(){
  std::string x,y;
  int a[1001][1001];
  int cnt=0;

  std::cin>>x;
  std::cin>>y;
  for(int j=0;j<1001;j++){
    for(int k=0;k<1001;k++){
      a[j][k]=0;
      if(j==0) a[j][k]=k;
      if(k==0) a[j][k]=j;
    }
  }

  int b00,b01,b10,b11;
  for(int j=1;j<=x.size();j++){
    for(int k=1;k<=y.size();k++){
      b00=a[j-1][k-1];
      b01=a[j][k-1]+1;
      b10=a[j-1][k]+1;
      if(x[j-1]==y[k-1]){
	if(b00<=b01 && b00<=b10) a[j][k]=b00;
	else if(b01<=b00 && b01<=b10) a[j][k]=b01;
	else a[j][k]=b10;
      }else{
	if(b00+1<=b01 && b00+1<=b10) a[j][k]=b00+1;
	else if(b01<=b00 && b01<=b10) a[j][k]=b01;
	else a[j][k]=b10;
      }
    }

  }

  std::cout<<a[x.size()][y.size()]<<"\n";

  return 0;
}


Measured memory_bytes: 7136
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define ll long long
#define W(x) cerr << "\033[31m"<< #x << " = " << x << "\033[0m" << endl;
 
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef set<int> si;
typedef vector<vi> vii;
typedef vector<ii> vpi;
typedef vector<ll> vll;
int oo = (1e9) + 7;
ll oo2 = 1ll*oo*oo;  


int main() {
   int n;
   cin >> n;
   vi v(n);
   int mdc = 0;
   for(int i = 0; i < n; i++)
   {
       scanf("%d", &v[i]);
       mdc = __gcd(mdc, v[i]);
   }
   cout << mdc << endl;



   return 0;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){
  long long n,a;
  
  cin >> n;
  a = n;
  int sum = 0;
  while(n != 0){
    sum += n%10;
    n /= 10;
  }
  //cout << sum << endl;
  if(a%sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << ' ' << max(0,a + b - n) << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  
  int a;
  a=N%10;
  
  if(a==0 || a==1 || a==6 || a==8 ){
    cout <<"pon" <<endl;
  }
  else if(a==2 || a==4 || a==5 || a==7 || a==9){
    cout << "hon" <<endl;
  }
  else if(a==3){
    cout <<"bon" << endl;
  }
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<pair<int, int>> w(n);
    int l, r;
    int isomax = -1;
    int lmx = -1;
    int rmn = INF;
    REP(i, n) {
        cin >> l >> r;
        l--; r--;
		chmax(lmx, l);
		chmin(rmn, r);
        v[i] = make_pair(l, r);
        w[i] = make_pair(r, l);
        chmax(isomax, r - l + 1);
    }
    sort(ALL(v));
    vector<int> lmin(n);
    vector<int> rmin(n);
    int mn = INF;
    REP(i, n) {
        chmin(mn, v[i].second);
        lmin[i] = mn;
    }
    mn = INF;
    REPR(i, n) {
        chmin(mn, v[i].second);
        rmin[i] = mn;
    }
    int ans = 0;
    REP(i, n - 1) {
        int x = lmin[i] - v[i].first + 1;
        if (x <= 0) x = 0;
        int y = rmin[i + 1] - v[n - 1].first + 1;
        if (y <= 0) y = 0;
        chmax(ans, x + y);
    }

    // ?????
    sort(ALL(w), greater<pair<int, int>>());
    vector<int> lmax(n);
    vector<int> rmax(n);
    int mx = -1;
    REP(i, n) {
        chmax(mx, w[i].second);
        lmax[i] = mx;
    }
    mx = -1;
    REPR(i, n) {
        chmax(mx, w[i].second);
        rmax[i] = mx;
    }
    REP(i, n - 1) {
        int x = w[i].first - lmax[i] + 1;
        if (x <= 0) x = 0;
        int y = w[n - 1].first - rmax[i + 1] + 1;
        if (y <= 0) y = 0;
        chmax(ans, x + y);
    }

    cout << max(ans, isomax + max(0, rmn - lmx + 1)) << EOL;
}



Measured memory_bytes: 3456
#include <stdio.h>

typedef long long ll;

ll min(ll a, ll b){return(a<b)?a:b;}
ll max(ll a, ll b){return(a>b)?a:b;}
ll abs(ll a){return(a<0)?-a:a;}

int N,K;
ll x[100001];
int main(){
        scanf("%d %d",&N,&K);

        for(int i = 1; i <= N; i++){
                scanf("%lld",x+i);
        }

        ll mindist = 10000000000;
        for(int l = 1; l <= N-K+1; l++){
                int r = l+K-1;
                ll distL = abs(x[l]-0) + x[r]-x[l];
                ll distR = abs(x[r]-0) + x[r]-x[l];
                ll dist = min(distL,distR);
                //printf("l=%d,r=%d,dist=%lld\n",l,r,dist);
                if(mindist > dist) mindist = dist;
        }

        printf("%lld\n",mindist);
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
#define y1 xoxo
const int N=1e6+20;
int n,m,k,l,x1,y1,x2,y2;
string a[N];
vector <int> dp[N];
queue <pair <int,int>> q;
set <int> r[N],c[N];

bool invalid(int x,int y)
{
	return min(x,y)<0 or x>=n or y>=m or a[x][y]=='@';
}

void add(int x,int y,int d)
{
	q.push({x,y});
	dp[x][y]=d;
	r[x].erase(y);
	c[y].erase(x);
}

void right(int x,int y)
{
	int sx=x,sy=y,d=dp[x][y];
	while(1729)
	{
		auto it=r[x].upper_bound(y);
		if(it==r[x].end() or *it-sy>k) break;
		y=*it;
		if(invalid(x,y)) break;
		add(x,y,d+1);
	}
}

void down(int x,int y)
{
	int sx=x,sy=y,d=dp[x][y];
	while(1729)
	{
		auto it=c[y].upper_bound(x);
		if(it==c[y].end() or *it-sx>k) break;
		x=*it;
		if(invalid(x,y)) break;
		add(x,y,d+1);
	}
}

void left(int x,int y)
{
	int sx=x,sy=y,d=dp[x][y];
	while(1729)
	{
		auto it=r[x].upper_bound(y);
		if(it==r[x].begin()) break;
		it--;
		if(sy-*it>k) break;
		y=*it;
		if(invalid(x,y)) break;
		add(x,y,d+1);
	}
}

void up(int x,int y)
{
	int sx=x,sy=y,d=dp[x][y];
	while(1729)
	{
		auto it=c[y].upper_bound(x);
		if(it==c[y].begin()) break;
		it--;
		if(sx-*it>k) break;
		x=*it;
		if(invalid(x,y)) break;
		add(x,y,d+1);
	}
}

int main()
{
	cin>>n>>m>>k;
	cin>>x1>>y1>>x2>>y2;
	for(int i=0;i<n;i++) cin>>a[i];
	x1--,y1--,x2--,y2--;

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			dp[i].push_back(INT_MAX);
			r[i].insert(j);
			c[j].insert(i);
		}
	}

	add(x1,y1,0);
	while(not q.empty())
	{
		auto p=q.front();
		int x=p.first,y=p.second;
		q.pop();

		right(x,y);
		left(x,y);
		up(x,y);
		down(x,y);
	}

	if(dp[x2][y2]==INT_MAX) dp[x2][y2]=-1;
	printf("%d",dp[x2][y2]);
}

Measured memory_bytes: 251616
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long MOD = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

void dfs(vector<llong> &A, vector<llong> &ans){
    llong n=0;
    if(A.size()<=10){
        llong exp=A.size()-1;
        for(int i=0; i<A.size(); i++){
            n = n + A[i]*pow(10, exp);
            exp--;
        }
        ans.push_back(n);
    }else{
        return;
    }

    for(llong i=0; i<10; i++){
        if(abs(i-A[A.size()-1])>1){
            continue;
        }
        A.push_back(i);
        dfs(A, ans);
        A.pop_back();
    }
    return;
}

int main(){
    vector<llong> ans;
    vector<llong> A;
    llong K;
    cin >> K;
    for(int i=1; i<10; i++){
        A.push_back(i);
        dfs(A, ans);
        A.pop_back();
    }
    sort(ans.begin(), ans.end());
    cout << ans[K-1] << endl;
    return 0;
}


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

int main(void){
    long long n, x;
    cin >> n >> x;
    
    vector<long long> a(n), d(n);
    rep(i, n){
        cin >> a.at(i);
    }
    
    long long count = 0;
    rep(i, n-1){
        d.at(i) = a.at(i)+a.at(i+1);
    }
    rep(i, n-1){
        if(d.at(i) > x){
            if(a.at(i+1) >= d.at(i)-x){
                d.at(i+1) -= d.at(i)-x;
            } else {
                d.at(i+1) -= a.at(i+1);
            }
            count += d.at(i)-x;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1792
N = gets.to_i
neighbors = Array.new(N + 1){Array.new}
(N - 1).times do |i|
    a, b, c = gets.split.map(&:to_i)
    neighbors[a].push([b, c])
    neighbors[b].push([a, c])
end

Q, K = gets.split.map(&:to_i)
xs, ys = [], []
Q.times do |i|
    xs[i], ys[i] = gets.split.map(&:to_i)
end

INF = 2**16
distK = Array.new(N + 1, INF)
distK[K] = 0
updated = [K]
while updated.length > 0 do
    nup = []
    updated.each do |u|
        neighbors[u].each do |b, c|
            if distK[b] == INF
                distK[b] = distK[u] + c
                nup.push(b)
            end
        end
    end
    updated = nup
end

Q.times do |i|
    puts distK[xs[i]] + distK[ys[i]]
end

Measured memory_bytes: 30840
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    ll base = m * 1900ll + (n-m) * 100ll;
    
    ll fact = 1;
    rep(i,m) fact *= 2;

    cout << base * fact << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

   int a,b,c,A;

   scanf("%d %d %d",&a,&b,&c);

   if( a > b ){
       A = b;
       b = a;
       a = A;
}

   if( b > c ){
       A = c;
       c = b;
       b = A;
}


   if( a > b ){
       A = b;
       b = a;
       a = A;
}


   printf("%d %d %d\n",a,b,c);

return 0;
}




Measured memory_bytes: 2100
/*
假设修改的是d[x]。D = min(|D - d[x]|, D)，因为d[x]可以任意修改，所以|D - d[x]|可以取0 ~ INF任意一个值，故这时候等价于把D改成不大于它的任意非负整数
考虑求出F[x][D]表示从x开始、初始值为D最终的结果。那么如果修改的是d[x]，D是走到x时的值，存在一个p <= D满足F[x + 1][p] > 0就代表有解
只要对于每个x求出最小的满足条件的p就可以直接判定了。设G[x]表示最小的满足条件的p是什么
求G[x]只要贪心考虑G[x + 1]，即找到最小的G[x]满足min(|G[x] - d[x]|, G[x]) = G[x + 1]
*/

#include <cstdio>
#include <algorithm>

using namespace std;
const int Max_N(500050);
typedef long long int LL;

constexpr LL Abs(LL x)
{
	return x >= 0LL ? x : -x;
}

int N;
LL D[Max_N], d[Max_N], G[Max_N];

int main()
{
	scanf("%d%lld", &N, D);
	for (int i = 1;i <= N;++i)
		scanf("%lld", d + i), D[i] = min(Abs(D[i - 1] - d[i]), D[i - 1]);
	G[N + 1] = 1LL;
	for (int i = N;i >= 1;--i)
		if (min(Abs(G[i + 1] - d[i]), G[i + 1]) == G[i + 1])
			G[i] = G[i + 1];
		else
			G[i] = G[i + 1] + d[i];
	int Q;
	scanf("%d", &Q);
	for (int q;Q--;)
	{
		scanf("%d", &q);
		if (G[q + 1] <= D[q - 1])
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  int a[200001];
  int b[200001];
  int an, bn;
  cin >> n >> m;
  vector<vector<int>> graph(n+1);


  for(int i = 0; i < m; i++){
     cin >> an >> bn;
     graph[an].push_back(bn);
     graph[bn].push_back(an);
  }


  vector<int> dist(n+1, -1);
  queue<int> que;
  dist[1] = 0;
  que.push(1);

  while(!que.empty()){
    int v = que.front();
    que.pop();


    for(int i = 0; i < graph[v].size(); i++){
      if(dist[graph[v][i]] != -1)continue;

      dist[graph[v][i]] = v;
      que.push(graph[v][i]);

    }
  }
  bool flag = true;

  for(int i = 2; i <= n; i++){
     if(dist[i] == -1){
       flag = false;
       break;
      }
  }

  if(flag){
    cout << "Yes" << endl;
  for(int i = 2; i <= n; i++){
      cout << dist[i] << endl;
  }
  }else{
    cout << "No" << endl;
    }



}


Measured memory_bytes: 10104
package main

import (
    "fmt"
    "sort"
)

type As [][]int

func (a As) Len() int {
    return len(a)
}

func (a As) Swap(i, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a As) Less(i, j int) bool {
    return a[i][0] > a[j][0]
}

func main() {
    var n, m int
    fmt.Scan(&n, &m)
    as := make(As, n+m)
    for i := 0; i < n; i++ {
        var a int
        fmt.Scan(&a)
        as[i] = []int{a, 1}
    }
    for i := 0; i < m; i++ {
        var b, c int
        fmt.Scan(&b, &c)
        as[n+i] = []int{c, b}
    }
    sort.Sort(as)
    var sum, cnt int
    for i := 0; i < len(as); i++ {
        wgt, num := as[i][0], as[i][1]
        if num >= n-cnt {
            sum += (n - cnt) * wgt
            break
        } else {
            sum += wgt * num
            cnt += num
        }
    }
    fmt.Println(sum)
}


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

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007ll
void printbit(int u) { if (u == 0)cout << 0; else { int s = 0, k = 0; for (; 0<u; u >>= 1, k++)s = (s << 1) | (u & 1); for (; 0<k--; s >>= 1)cout << (s & 1); } }

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

namespace {
    std::chrono::system_clock::time_point t;
    void tic() { t = TIME; }
    void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - t)); }
}

template<typename T1, typename T2>
ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; }

int width, height;
ll m, n;

int main() {
    int i, j, k;
    int x, y, a, b;

    cin >> n >> m;

    ll result = 0;

    result = min(n, m / 2);

    m -= result * 2;
    if (m < 2) {
        cout << result << endl;
    }
    else {
        cout << (result + m / 4) << endl;
    }


    return 0;
}

Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    print(math.ceil(N/2))
        


if __name__ == '__main__':
    main()

Measured memory_bytes: 63980
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <cstring>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
const int MAX_N=300000;
int par[MAX_N];
int rnk[MAX_N];

void init(int n){
    FOR(i,0,n){
        par[i]=i;
        rnk[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(rnk[x]<rnk[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(rnk[x]==rnk[y]) rnk[x]++;
    }
}

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

const int MAX_E=300000;
struct edge{int u,v,cost;};
bool comp(const edge& e1,const edge& e2){
    return e1.cost<e2.cost;
}
edge es[MAX_E];
int V,E;
int kruskal(){
    sort(es,es+E,comp);
    init(V);
    int res=0;
    FOR(i,0,E){
        edge e=es[i];
        if(!same(e.u,e.v)){
            unite(e.u,e.v);
            res+=e.cost;
        }
    }
    return res;
}

int main(){
    vector<PA> xv,yv;
    int n; cin>>n;
    FOR(i,0,n){
        int x,y; cin>>x>>y;
        xv.PB(PA(x,i));
        yv.PB(PA(y,i));
    }
    sort(xv.begin(),xv.end());
    sort(yv.begin(),yv.end());
    int k=0;
    FOR(i,0,n-1){
        es[k]={xv[i].SE,xv[i+1].SE,abs(xv[i].FI-xv[i+1].FI)};
        k++;
        es[k]={yv[i].SE,yv[i+1].SE,abs(yv[i].FI-yv[i+1].FI)};
        k++;
    }
    V=n; E=k;
    co(kruskal());
}


Measured memory_bytes: 6508
n=int(input())
if n==0:
	print('0')
else:
	L=[]
	while n!=0:
		if n>0:
			r=n%2
			n=-(n//2)
		else:
			r=(-n)%2
			n=(-n)//2
			if r==1:
				n+=1
		L.append(r)
	print(''.join(map(str,L[::-1])))

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    long long int n,i,sum=0;

    scanf("%lld",&n);

    for(i=1;i<=n;i++)
    {
        if(i%3==0 || i%5==0)
            continue;
        else
            sum+=i;
    }

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

    return 0;
}


Measured memory_bytes: 1704
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[]l = new int[n];
    
    for(int i=0; i<n; i++) {
    	l[i] = sc.nextInt();
    }
    Arrays.sort(l);
    int all = 0;
    int hiku = 0;
    for(int i=0; i<n; i++) {
    	all += l[i]; 
    }
    for(int i=0; i<n-k; i++) {
    	hiku += l[i];
    }
    System.out.print(all-hiku);
    }
}


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

vector<long long> solve(int N, const vector<int> &A){
    vector<pair<int, int>> vis;
    vis.reserve(N);
    for (int i = 0; i != N; ++i) vis.emplace_back(make_pair(A[i], i));
    sort(vis.begin(), vis.end());
    vector<int> val;
    vector<int> freq;
    vector<int> min_idx;
    val.push_back(vis[N - 1].first);
    min_idx.push_back(vis[N - 1].second);
    freq.push_back(1);
    for (int i = N - 2; i >= 0; --i){
        auto vi = vis[i];
        if (vi.first == val.back()){
            min_idx.back() = vi.second;
            ++freq.back();
        }else{
            val.push_back(vi.first);
            min_idx.push_back(vi.second);
            freq.push_back(1);
        }
    }
    vector<long long> ret(N, 0);
    long long cum = freq[0];
    int idx = min_idx[0];
    for (int i = 1; i != val.size(); ++i){
        ret[idx] += (val[i - 1] - val[i]) * cum;
        idx = min(idx, min_idx[i]);
        cum += freq[i];
    }
    ret[idx] += val.back() * cum;
    return ret;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto & a : A) cin >> a;
    auto freq = solve(N, A);
    for (auto f : freq) cout << f << '\n';
    return 0;
}

Measured memory_bytes: 3692
N = int(input())
a = [i for i in range(1,10)]
b = [i for i in range(100,1000)]
c = [i for i in range(10000,100000)]
U1 = a+b+c
U2 =[i for i in range(1,N+1)]
print(len(set(U1) & set(U2)))


Measured memory_bytes: 26252
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb; 

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


int main() {
    ll N,K,Q;
    cin >> N >> K >> Q;
    vector<ll> score(N,0);
    rep(i,Q){
        ll A;
        cin >> A;
        score[A-1]++;
    }

    vector<ll> sannkasya(N,K);
    rep(i,N){
        sannkasya[i] = sannkasya[i]+score[i]-Q;
        if(sannkasya[i] <= 0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
}


Measured memory_bytes: 4780
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
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()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int calc(vector<int> v) {
    int ret = 0;
    rep(i, v.size() - 1) { ret += abs(v[i + 1] - v[i]); }
    return ret;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(All(A));
    ll res = 0, tmp = 0;
    if(N % 2) {
        for(int i = 0; i < N; i++) {
            if(i < N / 2 + 1) {
                if(i == N / 2 || i == N / 2 - 1) {
                    tmp -= A[i];
                } else
                    tmp -= 2 * A[i];
            } else {
                tmp += 2 * A[i];
            }
        }
    } else {
        for(int i = 0; i < N; i++) {
            if(i < N / 2 + 1) {
                if(i == N / 2)
                    tmp -= A[i];
                else
                    tmp -= 2 * A[i];
            } else {
                if(i == N / 2 + 1)
                    tmp += A[i];
                else
                    tmp += 2 * A[i];
            }
        }
    }

    res = max(tmp, res);

    tmp = 0;
    if(N % 2) {
        for(int i = 0; i < N; i++) {
            if(i >= N / 2) {
                if(i == N / 2 || i == N / 2 + 1) {
                    tmp += A[i];
                } else
                    tmp += 2 * A[i];
            } else {
                tmp -= 2 * A[i];
            }
        }
    } else {
        for(int i = 0; i < N; i++) {
            if(i >= N / 2) {
                if(i == N / 2)
                    tmp += A[i];
                else
                    tmp += 2 * A[i];
            } else {
                if(i == N / 2 - 1)
                    tmp -= A[i];
                else
                    tmp -= 2 * A[i];
            }
        }
    }
    res = max(res, tmp);

    cout << res << endl;
    return 0;
}

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

using namespace std;

#define int long long

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

#ifdef DBG
#define log(item) cout << #item << " " << item << endl
#define loga(array, val) cout << #array << "[" << val << "] " << array [ val ] << endl
#else
#define log(item)
#define loga(array, val)
#endif

typedef vector<int> VI;
typedef pair<int, int> PII;

//-------------------

int S;

signed main(){
    cin >> S;

    int b = -1;
    rep(i, 4){
        int y = S % 10;
        
        if(y == b){
            cout << "Bad" << endl;
            return 0;
        }

        b = y;

        S /= 10;
    }

    cout << "Good" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int prime[1000000];

int judge(int n){
  if(n%2==0)
    return 0;
  int i=1;
  int tmp=2*i+1;
  int nn= sqrt(n);
  while(tmp <= nn){
    if(prime[tmp]==1 &&  n%tmp==0){
      return 0;
    } 
    i++;
    tmp = 2*i+1;
  }
  return 1;
}
int calc_prime(){
  prime[2]=1;
  prime[3]=1;
  int i=2;
  int tmp = 2*i+1;
  while(tmp <= 1000000){
    if(judge(tmp)){
      prime[tmp]=1;
    }
    i++;
    tmp=2*i+1;
  }
  
}
int count(int n){
  int i=0;
  int count=0;
  if(n>=2)
    count++;
  int tmp = 2*i+1;
  while(tmp<=n){
    if(prime[tmp]==1)
      count++;
    i++;
    tmp=2*i+1;
  }
  return count;
}

int main(){
  calc_prime();
  int i=0;
  char tmp[32];
  while(fgets(tmp, 32, stdin)!=NULL){
    printf("%d\n", count(atoi(tmp)));
  }
  return 0;
}

Measured memory_bytes: 4432
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstring>
#define SF scanf
#define PF printf
#define MAXN 60
using namespace std;
typedef long long ll;
bool used[MAXN],vis[MAXN];
ll ans;
int A[MAXN],B[MAXN],n;
bool w[MAXN][MAXN];
void build(){
    for(int i=1;i<=50;i++)
        if(used[i]==1){
            for(int j=0;j<=50;j++)
                w[j][j%i]=1;
        }
}
void dfs(int x){
    vis[x]=1;
    for(int i=0;i<=50;i++)
        if(w[x][i]==1&&vis[i]==0)
            dfs(i);
}
bool check(){
    for(int i=0;i<n;i++){
        memset(vis,0,sizeof vis);
        dfs(A[i]);
        if(vis[B[i]]==0)
            return 0;
    }
    return 1;
}
int main(){
    SF("%d",&n);
    for(int i=0;i<n;i++)
        SF("%d",&A[i]);
    for(int i=0;i<n;i++)
        SF("%d",&B[i]);
    for(int i=1;i<=50;i++)
        used[i]=1;
    build();
    if(check()==0){
        PF("-1\n");
        return 0;
    }
    for(int i=50;i>=0;i--){
        memset(w,0,sizeof w);
        used[i]=0;
        build();
        if(check()==0){
            used[i]=1;
            ans+=(1ll<<i);
        }
    }
    PF("%lld",ans);
}


Measured memory_bytes: 128
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
  string s, t;
  cin >> s >> t;
  
  int ss = (int)s.size(), ts = (int)t.size();
  sort(all(s)); sort(all(t));

  for (int i = 0; i < min(ss, ts); ++i) {
    if (s[i] < t[ts-i-1]) {
      cout << "Yes" << endl;
      return 0;
    }
    if (s[i] > t[ts-i-1]) {
      cout << "No" << endl;
      return 0;
    }
    if (i == ts-1) {
      cout << "No" << endl;
      return 0;
    }
    if (i == ss-1) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int ans=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		if(i%2 && x%2)
			ans++;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n;
	cin>>n;
	rep(i,10){
		rep(j,10){
			if(i*j==n){
				cout<<"Yes";
				re 0;
			}
		}
	}
	cout<<"No";
	re 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;


int main(){

while(1){
 int m,min,max;
 cin>>m>>min>>max;

 if(m==0&&max==0&&min==0){break;}

 int p[200];
 for(int i=0;i<m;i++){
	cin>>p[i];
 }

 int gap=-1;
 int n=-1;

 
 for(int i=min;i<max+1;i++){
	int g=p[i-1]-p[i];

	if(gap<=g){
		gap=g;
		n=i;
	}
 }
 cout<<n<<endl;
}
return 0;
}
 


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll h,n,s=0;
  cin >> h >> n;

  for(ll i=0;i<n;i++){
    ll a;
    cin >> a;
    s+=a;
  }

  if(s>=h)cout << "Yes" << endl;
  else cout << "No" << endl;

}

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

ll a,b,k;
int main(){
   cin>>a>>b>>k;
   if(a>=k)
     cout<<(a-k)<<" "<<b;
   else
     cout<<0<<" "<<max(0LL,a+b-k);
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define endl "\n"
const ll maxn = 2e5+10;
 
int main()
{
    fastio;
    ll i, j, k, t=1, n, m, d, c=0;
    string s;

    cin>>n>>s;
    
    ll curw=-1;

    i=0;j=n-1;

    while (i<=j)
    {
        if(s[i]=='W')
        {
            if(s[j]=='R'){
                c++;
                swap(s[i],s[j]);
                i++;
                j--;
            }
            else
                j--;
        }
        else
            i++;
    }

    cout<<c<<endl;    
    

    

    return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){

    string s,t;
    cin >> s >> t;
    int n = s.length(),m = t.length();
    
    vvi dp(n+1,vi(m+1,0));
    ve<ve<pii>> from(n+1,ve<pii>(m+1,{-1,-1}));
    
    rep(i,n){
        rep(j,m){
            if(chmax(dp[i+1][j+1],dp[i+1][j])) from[i+1][j+1] = {i+1,j};
            if(chmax(dp[i+1][j+1],dp[i][j+1])) from[i+1][j+1] = {i,j+1};
            if(s[i] == t[j]) if(chmax(dp[i+1][j+1],dp[i][j]+1)) from[i+1][j+1] = {i,j};
        }
    }
    
    string ans = "";
    
    int x = n, y = m;
    while (x > 0 && y > 0) {
        pii a = from[x][y];
        if(a.se < y && a.fi < x && dp[x][y] > 0) ans += t[y-1];
        x = a.fi;
        y = a.se;
    }
    
    
    reverse(all(ans));
    cout << ans << endl;
    
    //outmat(dp);
    
    

    return 0;
}


Measured memory_bytes: 105984
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
typedef pair<int, int> P;

int n;
int a[200005];
P A[200005];
vector<int> G[200005];
vector<int> topo;
bool used[200005];
int dp[200005];
int Prev[200005];

void tpsort(int v)
{
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(!used[G[v][i]]) tpsort(G[v][i]);
	}
	topo.push_back(v);
}

int main(void)
{
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++){
		A[i] = make_pair(a[i], i);
	}
	sort(A, A+n);
	
	for(int i = 0; i < n; i++){
		P *p = upper_bound(A, A+n, make_pair(A[i].first+1, A[i].second));
		if(p >= A+n) continue;
		if(p->first != A[i].first+1) continue;
		G[A[i].second].push_back(p->second);
	}
	
	for(int i = 0; i < n; i++){
		if(!used[i]) tpsort(i);
	}
	reverse(topo.begin(), topo.end());
	for(int i = 0; i < n; i++) Prev[i] = -1;
	
	for(int i = 0; i < topo.size(); i++){
		int v = topo[i];
		for(int j = 0; j < G[v].size(); j++){
			if(dp[G[v][j]] < dp[v] + 1){
				dp[G[v][j]] = dp[v] + 1;
				Prev[G[v][j]] = v;
			}
		}
	}
	
	int max_val = -1, max_i;
	for(int i = 0; i < n; i++){
		if(dp[i] > max_val){
			max_val = dp[i];
			max_i = i;
		}
	}
	
	int cur = max_i;
	vector<int> ans;
	ans.push_back(cur);
	
	while(Prev[cur] != -1){
		cur = Prev[cur];
		ans.push_back(cur);
	}
	reverse(ans.begin(), ans.end());
	
	cout << n - ans.size() << endl;
	return 0;
}

Measured memory_bytes: 23800
#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, k;
int x[100000];

int cost(int s, int e) {
    if (s <= 0 && 0 <= e) return -s + e + min(-s, e);
    return max(abs(s), abs(e));
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int ans = 1e9;
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
        cin >> x[i];
        if (k - 1 <= i) ans = min(ans, cost(x[i - k + 1], x[i]));
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
main = do
  [a,b,k] <- map read . words <$> getLine :: IO [Int]
  let (i,j) = solve a b k
  putStrLn $ show i ++ " " ++ show j
  
solve :: Int -> Int -> Int -> (Int,Int)
solve a b k
  | a < k = (0, max 0 (b-(k-a)))
  | a > k = (a-k, b)
  | otherwise = (0,b)

Measured memory_bytes: 508
use proconio::marker::Bytes;
fn main() {
    proconio::input! {
        s: Bytes,
        t: Bytes,
    }
    let mut a = vec![26; 26];
    let mut b = vec![26; 26];
    for (s, t) in s.into_iter().zip(t.into_iter()) {
        let s = s - b'a';
        let t = t - b'a';
        let a = &mut a[s as usize];
        let b = &mut b[t as usize];
        if *a != 26 && *a != t || *b != 26 && *b != s {
            println!("No");
            return;
        }
        *a = t;
        *b = s;
    }
    println!("Yes");
}


Measured memory_bytes: 2872
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int a, b;
  	cin >> a >> b;
  	cout << a*b << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

ll N;
//int ans;

int main() {
	cin >> N;
	cout << (N - 1) * N / 2 << endl;

}

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

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vl a(n);
  REP(i, n)cin >> a[i];
  ll x = 0;
  REP(i, n)x ^= a[i];
  ll ans = 0;
  bitset<60> bx(x);
  REP(i, n) {
    REP(j, 60) {
      if (bx[j] && ((1ll << j) & a[i])) {
        a[i] ^= 1ll << j;
     }
    }
  }
  vl basis(60);

  vi used(n);
  RREP(j, 60) {
    REP(i, n) {
      if (used[i])continue;
      if (a[i] & (1ll << j)) {
        basis[j] = a[i];
        ll tmp = a[i];
        REP(k, n) {
          if (a[k] & (1ll << j))a[k] ^= tmp;
        }
        used[i] = 1;
        break;
      }
    }
  }
  RREP(j, 60) {
    if (((ans&(1ll<<j))==0)&&bx[j]==0) {
      ans ^= basis[j];
    }
  }
  cout << 2 * ans + x << endl;
}


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

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
const ll MOD = 1e9+7;

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

  int a[4] = {};
  for (int i = 0; i < 3; i++) {
    int x, y;
    cin >> x >> y;
    a[--x]++;
    a[--y]++;
  }
  int k = 0;
  for (int i = 0; i < 4; i++) {
    k += a[i] % 2;
  }
  if (k == 1 || k > 2) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int D;
vector<int> c(26);
vector<vector<int>> s;

int64_t calc_score(const vector<int>& t) {
  int64_t result = 0;
  vector<int> last(26, -1);
  rep(i, D) {
    const int j = t[i];
    result += s[i][j];
    last[j] = i;
    rep(k, 26) { result -= c[k] * (i - last[k]); }
  }
  return result;
}

int main() {
  cin >> D;

  rep(i, 26) { cin >> c[i]; }

  s.resize(D, vector<int>(26));
  rep(i, D) rep(j, 26) { cin >> s[i][j]; }

  vector<int> t(D);
  rep(i, D) {
    cin >> t[i];
    t[i]--;
  }

  int M;
  cin >> M;
  rep(i, M) {
    int d, q;
    cin >> d >> q;
    d--;
    q--;
    t[d] = q;
    int64_t z = calc_score(t);
    cout << z << "\n";
  }

  return 0;
}

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

const int N = 2e5 + 10;

char s[N];

int main(){
	int n, a, b, c, d;
	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
	scanf("%s", s + 1);
	for (int i = a + 1; i <= max(c, d); i++){
		if (s[i] == '#' && s[i - 1] == '#'){
			printf("No\n");
			return 0;
		}
	}
	if (c < d){
		printf("Yes\n");
		return 0;
	}
	for (int i = b; i <= d; i++){
		if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.'){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 384
//
//  main.cpp
//  absolute minima
//
//  Created by Dong Truong on 5/28/19.
//  Copyright © 2019 Dong Truong. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <queue>

using namespace std;
#define maxn 1000001

int q;int64_t kq;
priority_queue<int,vector<int>,greater<int> > r;
priority_queue<int,vector<int>,less<int> > l;

void xuly(int a)
{
    l.push(a);r.push(a);
    int x=l.top(),y=r.top();
    if(x>y)
    {
        l.pop();r.pop();
        kq=kq+x-y;
        l.push(y);r.push(x);
    }
}
void sol()
{
    cin>>q;
    int64_t i=1;
    while (i<=q)
    {
        int o;cin>>o;
        if (o==1)
        {
            int a,b;cin>>a>>b;
            kq+=b;
            xuly(a);
        }
        else
        {
            //if ( (l.size()+r.size()) % 2 == 1)
            cout<<l.top()<<" "<<kq<<"\n";
        }
        ++i;
    }
}
int main(int argc, const char * argv[]) {
    // insert code here...
    //std::cout << "Hello, World!\n";
    //freopen("a.inp","r",stdin);
    sol();
    return 0;
}


Measured memory_bytes: 3828
#include <stdio.h>

int main(void)
{
        long int a,b,x,s,c;
        scanf("%ld%ld%ld",&a,&b,&x);
        if(a==0)s=0;
        else s=(a-1)/x+1;
        c=b/x+1;
        printf("%ld\n",c-s);
        return 0;
}


Measured memory_bytes: 1708
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', function (line) {
  var i,j,result;
  var a = line.split(' ');
  var b = parseInt(a[0],10);
  var c = parseInt(a[1],10);
  if(!b && !c)
    process.exit();
  for(i=0;i<b;i++){
    result="";
    for(j=0;j<c;j++){
      if(i%2==0 && j%2==0 || i%2==1 && j%2==1)
        result += "#";
      else
        result += ".";
    }
    console.log(result);
  }
  console.log("");
});
process.stdin.on('end', function () {
});

Measured memory_bytes: 18500
#include<stdio.h>

int main(void){
  int N,L,a[100001],sum[100001];
  int i,j,k,knum;
  scanf("%d%d",&N,&L);
  for(i=1;i<=N;i++) scanf("%d",&a[i]);
  for(i=k=1;i<N;i++){
    sum[i]=a[i]+a[i+1];
    if(k<sum[i]){
      k=sum[i];
      knum=i;
    }
  }

  if(k<L){
    puts("Impossible");
    return 0;
  }

  puts("Possible");
  for(i=1;i<knum;i++) printf("%d\n",i);
  for(i=N-1;i>knum;i--) printf("%d\n",i);
  printf("%d\n",knum);
  return 0;
}


  
  


Measured memory_bytes: 1152
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

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

	while (1)
	{
		int num = 0; cin >> num;
		if (num == 0) { break; }
		vector<int> scr(num, 0);
		rep(i, num){ cin >> scr[i]; }
		int ans = 0;
		ans = accumulate(all(scr), 0) - *max_element(all(scr)) - *min_element(all(scr));
		printf("%d\n", ans / (num - 2));
	}

	return 0;
}

Measured memory_bytes: 1196