akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

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

int extgcd(int a, int b, int &x, int &y){
    if(a == 0) return b;
    if(b == 0) return a;
    int d = a;
    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
    return d;
}

int gcd_multi(vec a){
    if(a.size() == 1) return llabs(a[0]);
    int x, y, g;
    g = llabs(a[0]);
    FOR(i, 1, a.size()) g = extgcd(g, llabs(a[i]), x, y);
    return g;
}

signed main(){

    int N; cin >> N;
    vec a(N + 1); readv(a); Reverse(a);

    set<int> ans;
    int g = gcd_multi(a);
    FOR(i, 2, 100001){
        while(g % i == 0){
            g /= i;
            ans.insert(i);
        }
    }
    if(g > 1) ans.insert(g);

    vec b(N + 1);
    FOR(p, 2, N + 2) if(is_prime(p) && a[0] % p == 0){
        fill(all(b), 0);
        REP(i, N + 1){
            b[i % (p - 1)] += a[i];
        }
        bool ok = true;
        REP(i, N + 1) if(b[i] % p != 0) ok = false;
        if(ok) ans.insert(p);
    }
    for(int i: ans) cout << i << endl;

    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cassert>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

struct Edge {
    int from, to, cost;
    Edge(){}
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost){}
    bool operator < (const Edge &rhs) const {
        return (cost < rhs.cost);
    }
    bool operator > (const Edge &rhs) const {
        return (rhs < *this);
    }
};

int directed_MST(vector<Edge> &G, int N, int r)
{
    vector<Edge> mini(N, Edge(-1, -1, 1000000));

    for (int i = 0; i < G.size(); i++){
        mini[G[i].to] = min(mini[G[i].to], G[i]);
    }

    mini[r] = Edge(-1, -1, -1);

    vector<int> gr(N, 0);
    vector<bool> isCycle(N, false);
    vector<bool> visited(N, false);
    int ct = 0;

    for (int i = 0; i < N; i++){
        if (visited[i]) continue;

        vector<int> chain;
        int v = i;
        while (v != -1 && !visited[v]){
            visited[v] = true;
            chain.push_back(v);
            v = mini[v].from;
        }

        if (v != -1){
            bool inCycle = false;
            for (int j = 0; j < chain.size(); j++){
                gr[chain[j]] = ct;
                if (chain[j] == v){
                    isCycle[ct] = true;
                    inCycle = true;
                }
                if (!inCycle) ct++;
            }
            ct += inCycle;
        }
        else {
            for (int j = 0; j < chain.size(); j++){
                gr[chain[j]] = ct++;
            }
        }
    }

    if (ct == N){
        int ans = 0;
        for (int i = 0; i < N; i++){
            if (i != r) ans += mini[i].cost;
        }
        return (ans);
    }

    int ans = 0;

    for (int i = 0; i < N; i++){
        if (i != r && isCycle[gr[i]]) ans += mini[i].cost;
    }

    vector<Edge> nG;
    for (int i = 0; i < G.size(); i++){
        int f2 = gr[G[i].from], t2 = gr[G[i].to];
        if (f2 == t2) continue;
        else if (isCycle[t2]){
            nG.push_back(Edge(f2, t2, G[i].cost - mini[G[i].to].cost));
        }
        else {
            nG.push_back(Edge(f2, t2, G[i].cost));
        }
    }

    return (ans + directed_MST(nG, ct, gr[r]));
}

int main()
{
    int n, m, s;
    set< pair<int, int> > dup;
    vector<Edge> G;

    scanf("%d %d %d", &n, &m, &s);

    for (int i = 0; i < m; i++){
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        G.push_back(Edge(x, y, z));
    }

    printf("%d\n", directed_MST(G, n, s));

    return (0);
}



Measured memory_bytes: 2948
#include<stdio.h>
#include<stdlib.h>
int fib(int);
typedef struct Chain{
  int o;
  int w, l;
}T_chain;
T_chain **C;
int main(){
  int n;
  scanf("%d", &n);
  C = (T_chain **)malloc(sizeof(T_chain *) * (n));
  int i;
  for(i = 0; i < n; i++){
    C[i] = (T_chain *)malloc(sizeof(T_chain) * (n));
    C[i][i].o = 0;
    scanf("%d %d", &C[i][i].w, &C[i][i].l);
  }
  int min, m, j, k;
  for(j = 1; j < n; j++){
    for(i = n - 1 - j; i >= 0; i--){
      min = 2147483647;
      for(k = i; k < i + j; k++){
	//	printf(" %d %d %d %d %d %d", C[i][k].o, C[k + 1][i + j].o, C[i][k].w, C[i][k].l, C[k + 1][i + j].w, C[k + 1][i + j].l);
	m = C[i][k].o + C[k + 1][i + j].o + C[i][k].w * C[i][k].l * C[k + 1][i + j].l;
	//	printf(" i:%d j:%d i:%d j:%d %d\n", i, k, k + 1, i + j, m);
	if(m < min){
	  min = m;
	  C[i][i + j].o = min;
	  C[i][i + j].w = C[i][k].w;
	  C[i][i + j].l = C[k + 1][i + j].l;
	}
      }
    }
  }
  printf("%d\n", C[0][n - 1]);
  return 0;
}

Measured memory_bytes: 712
#include <cstdio>
#include <queue>
#include <utility>
using namespace std;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int>> adj[100];
int *d;

void dijkstra() {
    priority_queue<pair<int, int>> PQ;
    int d[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0, 0));

    while (!PQ.empty()) {
        pair<int, int> f = PQ.top();
        PQ.pop();

        int u = f.second;
        color[u] = BLACK;

        if (d[u] < f.first * (-1)) { continue; }

        for (int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) { continue; }
            if (d[u] + adj[u][j].second < d[v]) {
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int u, k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; j++) {
            int v, c;
            scanf("%d %d", &v, &c);
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}


Measured memory_bytes: 2752
#include<stdio.h>
int main()
{
	long long t,i,a,z,min;
	scanf("%lld",&t);
	for(i=1;i<=t;i++)
	{
		scanf("%lld",&a);
		z=0;
		while(a)
		{
			if(a%2==0)z++;
			else break;
			a=a/2;
		}
		if(i==1)min=z;
		else if(min>z)min=z;
	}
	printf("%lld\n",min);
}

Measured memory_bytes: 128
from math import sqrt, cos, pi


def main():
    a, b, h, m = map(int, input().split())
    theta = abs(6 * m - 0.5 * (60 * h + m))
    theta = min(theta, 360 - theta)
    if theta == 0:
        print(abs(b - a))
    elif theta == 180:
        print(a + b)
    else:
        print(sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(theta * pi / 180)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 9512
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
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(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n;cin>>n;
    vector<char> s1(n),s2(n);
    REP(i,n)cin>>s1[i];
    REP(i,n)cin>>s2[i];
    ll prd=1,type;
    
    REP(i,n){
        if(s1[i]==s2[i]){
            if(i==0){
                prd*=3;
            }else{
                type==0?prd*=2:prd*=1;
            }
            type=0;
        }else{
            if(i==0){
                prd*=6;
            }else{
                type==0?prd*=2:prd*=3;
            }
            type=1;
            i++;
        }
        prd=prd%1000000007;
    }
    cout<<prd<<endl;
    return 0;
}


Measured memory_bytes: 3632
import sys
 
 
alph="abcdefghijklmnopqrstuvwxyz"
allis=list(alph)
S=input()
if(S=="zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    sys.exit()
 
for i in alph:
    if(i not in S):
        print(S+i)
        sys.exit()
        
l=-1
for i in range(len(S)-1)[::-1]:
    if(ord(S[i])<ord(S[i+1])):
        l=i
        break
        
x=sorted(S[i+1:])
for i in x:
    if(i>S[l]):
        print(S[:l]+i)
        sys.exit()

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

int main(void) {
  long long n, i, m, mt, mt2;
  scanf("%lld%lld", &m, &n);
  mt = m, mt2 = m;
  m = 1;
  long long a = log2(n), b = n - (int)pow(2, a);
  while( a ) {
    for(i = 0; i < a; ++i) {
      mt *= mt;
      mt %= 1000000007;
    }
    a = log2(!b ? 1 : b);
    m *= mt;
    m %= 1000000007;
    if(a) b = b - (int)pow(2, a);
    else if(b){
      m *= mt2;
      m %= 1000000007;
    }
    mt = mt2;
  }
  printf("%lld\n", m);
  return 0;
}


Measured memory_bytes: 2976
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int calcnum1(ll int x, int n){
  if(n == 0){
    // int kurikaesi = x / 2;

    return ((((x+1)/2)%2)==1);
  } 
  ll int waru = 1;
  REP(i, n) waru *= 2;
  if(waru > x) return 0;
  ll int shou = x / waru;
  ll int amari = x % waru;
  if(shou%2 == 0) return 0;
  else if(amari%2 == 1) return 0;
  else return 1;
}

int sub_calcnum1(ll int x, int n){
  int res = calcnum1(x, n);
  // cout << "x: " << x << " n: " << n << "res : " << res << endl;
  return res;
}
int main(){
  ll int a, b;
  cin >> a >> b;
  if(a == b){
    cout << a << endl;
    return 0;
  }
  ll int ans = 0;
  ll int keta = 1;
  REP(i, 40){
    int tmpres = sub_calcnum1(b, i)^sub_calcnum1(a-1, i);
    ans += tmpres * keta;
    keta*=2;
  }
  cout << ans << endl;

}
/*
0 0 0
1 1 0
2 0 1
3 1 1
4 0 2

*/	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int i = 0, j = n - 1;
	int ans = 0;
	while (i<=j) {
		while (i <= j&&s[i] == 'R')i++;
		while (i <= j&&s[j] == 'W')j--;
		if (i <= j) {
			ans++;
			i++;
			j--;
		}
	}
	cout << ans << endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}



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

int main() {
    int A, B, N, j, count = 0;
    cin >> A >> B;
    vector<int> a(5);
    for (int i = A; i <= B; i++) {
        N = i;
        j = 0;
        while (N > 0) {
            a.at(j) = N % 10;
            N /= 10;
            j++;
        }
        if (a.at(0) == a.at(4) && a.at(1) == a.at(3)) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  char tmp[10];
  char buf;
  while(cin >> buf){
    tmp[0] = buf - '0';
    for(int i=1;i<10;i++){
      cin >> buf;
      tmp[i] = buf -'0';
    }
    for(int i=8;i>=0;i--){
      for(int j=0;j<=i;j++){
	tmp[j] = (tmp[j] + tmp[j+1]) % 10;
      }
    }
    cout << (int)tmp[0] << endl;
  }
}

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

using namespace std;
#define rep(i, l, r) for (int i = l; i<r;i++)
#define dec(i, l, r) for (int i = l; i>=r;i--)
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define pb(c) push_back(c)
#define vii vector<pair<int,int>>
#define ii pair<int,int>
#define mp(i, j) make_pair(i,j)
#define ull unsigned long long int
#define ll  long long int
#define pie 3.141592653589793238
#define inf ((ll)1e18)
#define eps 1e-7
#define mod ((ll)1e9+7)
#define maxlg 18
const int maxn = ((int) 100)  ;
#define left(i) ((i)<<1)
#define right(i) (((i)<<1)+1
char arr[maxn][maxn];

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

#ifndef ONLINE_JUDGE
 //  freopen("input", "r", stdin);
    //freopen("/home/arasmus/output", "w", stdout);
#endif
    fill(&arr[0][0], &arr[0][0] + maxn * maxn, '.');
    int a, b;
    cin >> a >> b;
    a--, b--;
    int col = 0;
    for (int i = 0; i < maxn; i += 2) {
        for (int j = 0; j < maxn; j += 2) {
            if (b>=1)
                arr[i][j] = '#',b--;
            if (b==0)
                break;
        }
        col = i+2;
        if (b==0) {
            break;
        }
    }
    for (int i = col;i<maxn;i++) {
        for (int j =  0;j<maxn;j++) {
            arr[i][j] = '#';
        }
    }
    for (int i = col+1; i < maxn; i += 2) {
        for (int j = 0; j < maxn; j += 2) {
            if (a>=1)
                arr[i][j] = '.',a--;
            if (a==0)
                break;
        }
        col = i+2;
        if (a==0) {
            break;
        }
    }
    cout<<100<<" "<<100<<endl;
    rep (i,0,maxn) {
        rep (j, 0, maxn)cout << arr[i][j];
        cout<<endl;
    }
    return 0;
}  //cout<<"Case #"<<++T<<": ";

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll h,w ;
	cin >> h >> w ;
	map<char,ll> m ;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char c ; cin >> c ;
			m[c]++ ;
		}
	}
	map<ll,ll> cnt ;
	for(auto p:m){
		cnt[0] += p.second/4 ;
		cnt[p.second%4]++ ;
	}
	if(h%2==0&&w%2==0){
		yorn(cnt[1]+cnt[2]+cnt[3]==0) ;
	}else if(h*w&1){
		yorn(cnt[1]+cnt[3]==1&&cnt[2]<=(h/2+w/2-cnt[3])) ;
	}else{
		yorn(cnt[1]+cnt[3]==0&&cnt[2]<=(h&1?w:h)/2) ;
	}
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

//[0,l)+[r,a.size())
bool same(string &a,string &b,ll l,ll r){
    if((int)a.size()-(r-l)!=b.size()){return false;}
    for(int i=0;i<l;i++){
        if(a[i]!=b[i]){return false;}
    }
    for(ll i=r;i<a.size();i++){
        if(a[i]!=b[i-(r-l)]){return false;}
    }
    return true;
}


int main(){
    string s;
    cin>>s;
    string ans="keyence";
    if(s==ans){cout<<"YES"<<endl; return 0;}
    if(s.size()<=ans.size()){cout<<"NO"<<endl; return 0;}
    for(ll i=0;i<s.size();i++){
        for(ll t=0;t<s.size();t++){
            if(same(s,ans,i,t)){cout<<"YES"<<endl; return 0;}
        }
    }
    cout<<"NO"<<endl;
    
    
    return 0;
}


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

int main(){
	string s;
	string num = "";
	while(getline(cin,s)){
		num += s;
	}
	int count[26] ={};
	for(int i = 0; i < num.size(); i++){
		if(num[i] >= 'a' && num[i] <= 'z')count[num[i] - 'a']++;
		if(num[i] >= 'A' && num[i] <= 'Z')count[num[i] - 'A']++;
	}
	for(int i = 0; i < 26; i++){
		cout << (char)(i + 'a') << " : " << count[i] << endl;
	}

	return 0;
}


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

fn main() {
	let n: u32 = read();
	let l: u32 = (1..n+1).map(|x| x % 2).fold(0, |x, y| x + y);
	println!("{}", l as f32 / n as f32);
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main() {
  char s[5];
  int c[26],i;
  for(i=0;i<26;i++)c[i]=0;
  cin >> s;
  for(i=0;i<4;i++) {
    c[s[i]-'A']++;
  }
  for(i=0;i<26;i++) {
    if(!(c[i] == 0 || c[i] == 2)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
from functools import cmp_to_key


N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(N)]
# print(N, M, AB)

def compare(item1, item2):
    if item1[0] == item2[0]: return 0
    return -1 if item1[0] < item2[0] else 1
sorted_AB = sorted(AB, key=cmp_to_key(compare))
# print(sorted_AB)

remaining = M
total_amount = 0
for ABi in sorted_AB:
    price = ABi[0]
    number_of_stocks = ABi[1]
    number_of_purchases = min(number_of_stocks, remaining)
    sub_total = price * number_of_purchases

    total_amount += sub_total
    remaining -= number_of_purchases

    if remaining <= 0: break

print(total_amount)


Measured memory_bytes: 33432
from collections import deque

def updiv(a,b):
    if a % b == 0:
        return a // b
    else:
        return a // b + 1

N,D,A = map(int,input().split())

XH = []

for i in range(N):

    x,h = map(int,input().split())
    XH.append([x,h])

XH.sort()

q = deque([])
qs = 0
ans = 0

for i in range(N):

    X = XH[i][0]
    H = XH[i][1]

 
    while len(q) > 0 and q[0][0] < X-D:
        po = q.popleft()
        qs -= po[1] * A

    if H - qs <= 0:
        continue
        
    else:
        pl = updiv(H-qs,A)
        qs += pl * A
        ans += pl
        q.append([X+D,pl])

print (ans)
        

Measured memory_bytes: 84184
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

struct SCC {
    vector<vector<int>> G, G_r, G_out;
    vector<int> vs, used, cmp, sz;
    SCC() = default;
    explicit SCC(int n) : G(n), G_r(n), G_out(n), used(n), cmp(n), sz(n) {}

    void add_edge(int a, int b){
        G[a].emplace_back(b);
        G_r[b].emplace_back(a);
    }

    void dfs(int v){
        used[v] = 1;
        for (auto &&u : G[v]) if(!used[u]) dfs(u);
        vs.emplace_back(v);
    }

    void dfs_r(int v, int k){
        used[v] = 1;
        cmp[v] = k;
        sz[k]++;
        for (auto &&u : G_r[v]) if(!used[u]) dfs_r(u, k);
    }

    int build() {
        int n = G.size();
        for (int i = 0; i < n; ++i) if(!used[i]) dfs(i);
        fill(used.begin(),used.end(), 0);
        int k = 0;
        for (int i = n - 1; i >= 0; --i) {
            if(!used[vs[i]]){
                dfs_r(vs[i], k++);
            }
        }
        G_out.resize(k);
        sz.resize(k);
        for (int i = 0; i < n; ++i) {
            for (auto &&j : G[i]) {
                if(cmp[i] != cmp[j]){
                    G_out[cmp[i]].emplace_back(cmp[j]);
                }
            }
        }
        for (auto &&l : G_out) {
            sort(l.begin(), l.end());
            l.erase(unique(l.begin(), l.end()), l.end());
        }
        return k;
    }

    int operator[](int k) const { return cmp[k]; }
};


int main() {
    int n;
    cin >> n;
    SCC G(n);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if(x%n == 0) ans++;
        else G.add_edge(i, (i+x)%n);
    }
    G.build();

    for (auto &&j : G.sz) {
        if(j != 1) ans += j;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 20332
#include<bits/stdc++.h>
using namespace std;
struct color{
  double l, a, b;
};

double diff(color a, color b){
  return (a.l - b.l)*(a.l - b.l) + (a.a - b.a)*(a.a - b.a) +
    (a.b - b.b)*(a.b - b.b);
}
int main(){
  int n, m;
  std::cin >> n >> m;
  vector<double> l(n), a(n), b(n);
  for (int i = 0; i < n; i++) {
    std::cin >> l[i] >> a[i] >> b[i];
  }
  double ans = 0;
  for (int i = 0; i < (1<<n); i++) {
    if(__builtin_popcount(i) != m)continue;
    vector<color> c;
    for (int j = 0; j < n; j++) {
      if((i & (1<<j)) == 0)continue;
      c.push_back((color){l[j], a[j], b[j]});
    }
    double tmp = 0;
    for (int j = 0; j < c.size(); j++) {
      for (int k = j + 1; k < c.size(); k++) {
        tmp += diff(c[j], c[k]);
      }
    }
    ans = max(ans, tmp);
  }
  printf("%.18lf\n", ans);
  return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;

class Dice{
	public:
	int diceside[6];
	char instruct[100];
	
	void Show();
	void Move();
	void Whatright();
};

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

void Dice::Show(){
    for(int i=0;i<6;i++){
        cout<<diceside[i]<<endl;
    }
}

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

void Dice::Move(){
	
	int d1;
	int d2;
	int d3;
	int d4;
	int d5;
	int d6;
	
//	char instruct[100];
//	cin>>instruct;

	
	for(int i=0;instruct[i]!='\0';i++){
		d1=diceside[0];
		d2=diceside[1];
		d3=diceside[2];
		d4=diceside[3];
		d5=diceside[4];
		d6=diceside[5];
		
		switch(instruct[i]){
			case 'N':
			diceside[0]=d2;
			diceside[1]=d6;
			diceside[2]=d3;
			diceside[3]=d4;
			diceside[4]=d1;
			diceside[5]=d5;break;
			
			case 'E':
			diceside[0]=d4;
			diceside[1]=d2;
			diceside[2]=d1;
			diceside[3]=d6;
			diceside[4]=d5;
			diceside[5]=d3;break;
			
			case 'W':
			diceside[0]=d3;
			diceside[1]=d2;
			diceside[2]=d6;
			diceside[3]=d1;
			diceside[4]=d5;
			diceside[5]=d4;break;
			
			case 'S':
			diceside[0]=d5;
			diceside[1]=d1;
			diceside[2]=d3;
			diceside[3]=d4;
			diceside[4]=d6;
			diceside[5]=d2;break;
		}
	}
	
//	cout<<diceside[0]<<endl;
}

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

void Dice::Whatright(){
	int Qnum;
	int A=0;
	int X,Y;
	cin>>Qnum;

	for(int i=0;i<Qnum;i++){
		cin>>X>>Y;
		if(X==diceside[0]){sprintf(instruct,"%s","\0");}
		else if(X==diceside[1]){sprintf(instruct,"%s","N");}
		else if(X==diceside[2]){sprintf(instruct,"%s","W");}
		else if(X==diceside[3]){sprintf(instruct,"%s","E");}
		else if(X==diceside[4]){sprintf(instruct,"%s","S");}
		else if(X==diceside[5]){sprintf(instruct,"%s","NN");}
		
		Move();
		
		if(Y==diceside[1]){A=diceside[2];}
		else if(Y==diceside[2]){A=diceside[4];}
		else if(Y==diceside[3]){A=diceside[1];}
		else if(Y==diceside[4]){A=diceside[3];}
		
		cout<<A<<endl;
	}
	
	
}

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

int main(void){
	
	int imput;
	Dice dice1;
	for(int i=0;i<6;i++){
		cin>>imput;
		dice1.diceside[i]=imput;
	}
	
	
	dice1.Whatright();
	


	
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(snip_i, n) cin >> h.at(snip_i);
  sort(h.begin(), h.end());
  int ans = 1001001001;
  rep(i, n-k+1){
    int mn = h.at(i), mx = h.at(i+k-1);
    ans = min(ans, mx-mn);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
/*    AUTHOR: julianferres, sáb 29 ago 2020 00:44:30 -03 */
#include <bits/stdc++.h>
using namespace std;

// DEBUGGER
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//END DEBUGGER

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii; typedef vector<bool> vb;
#define FIN ios::sync_with_stdio(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define esta(x,c) ((c).find(x) != (c).end())
const int INF = 1<<30; // const ll INF = 1LL<<60;
const int MOD = 1e9+7; // 998244353
const int MAXN  = 2e5+5;


int main(){  
    FIN;

    int n, x, t; cin >> n >> x >> t;
    cout << (n+x-1)/x*t << "\n";

    return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while(true)
		{
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();
			if(op.charAt(0) != '?')
			{
				if(op.charAt(0) == '+')
				{
					System.out.println(a + b);
				}
				else if(op.charAt(0) == '-')
				{
					System.out.println(a - b);
				}
				else if(op.charAt(0) == '*')
				{
					System.out.println(a * b);
				}
				else if(op.charAt(0) == '/')
				{
					System.out.println(a / b);
				}
			}
			else
			{
				break;
			}
		}
	}
}


Measured memory_bytes: 26272
// Created by arvybhatt

#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define p_b push_back
#define m_p make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

#define ll long long int
using namespace std;


ll power(ll x, ll y) { ll temp; if( y == 0) return 1; temp = power(x, y/2); if (y%2 == 0) return temp*temp; else return x*temp*temp; } 

int main()
{
	fast;

	int n;cin>>n;
	int a=0,b=0,c=0,d=0;
	for(int i=0 ;i<n; i++)
	{
		string s;cin>>s;
		if(s=="AC")
			a++;
		if(s=="WA")
			b++;
		if(s=="TLE")
			c++;
		if(s=="RE")
			d++;
	}
	cout<<"AC x "<<a<<"\n";

	cout<<"WA x "<<b<<"\n";
	cout<<"TLE x "<<c<<"\n";
	cout<<"RE x "<<d<<"\n";
}


Measured memory_bytes: 3584
a,b=map(int,input().split())
s=input()
if '-' not in s or s.count('-')>1 or s[0]=='-' or s[-1]=='-':
    print('No')
    exit()
p=s.split('-')
print('No' if s[a]!='-' or len(p[0])!=a or len(p[1])!=b else 'Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

char choco[11][1001];
int sum[11][1001];

int getwhite(int y2, int x2, int y1, int x1){
	return sum[y2][x2] - sum[y1][x2] - sum[y2][x1] + sum[y1][x1];
}

int main(){
	int h, w, lim, ans = MOD;
	cin >> h >> w >> lim;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			cin >> choco[i][j];
		}
	}

	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
			if (choco[i][j] == '1'){
				sum[i][j]++;
			}
		}
	}

	for (int i = 0; i < (1<<h); i++){
		vector<int> divide;
		divide.push_back(0);
		int tmpans = 0;
		for (int j = 0; j < h; j++){
			if (i & (1<<j)){
				divide.push_back(j+1);
				tmpans++;
			}
		}
		divide.push_back(h);
		bool flg = true;
		int tate = 0;
		for (int j = 0; j < w; j++){
			for (int k = 0; k < divide.size()-1; k++){
				if (getwhite(divide[k+1], j+1, divide[k], tate) > lim){
					if (tate == j){
						j = MOD, k = MOD;
						flg = false;
					}else{
						tate = j;
						tmpans++;
					}
				}
			}
		}
		if (flg){
			ans = min(ans, tmpans);
		}
	}
	cout << ans << endl;
	return 0;
}

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

#undef false
#undef true

using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;

/* [💭] [💡] [🎈] */

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

    int n;
    cin >> n;
    cout << (n + 1) / 2;

    return 0;
}


Measured memory_bytes: 256
num = input().split()
if int(num[0])<int(num[1]):
    x = int(num[1])
    y = int(num[0])
else:
    x = int(num[0])
    y = int(num[1])

end = 0
    
z = x % y
if z == 0:
    print(y)
else:
    while True:
        z1 = y % z
        y1 = z
        if z1 == 0:
            print(z)
            break 
        z = z1
        y = y1    

Measured memory_bytes: 7716
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int N, K;

  cin >> N >> K;

  //cout << (N%K) << endl;
  if (N % K == 0){
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define ll long long
#define ld long double
#define inf 1000000000
using namespace std;
ll read(){
	char ch=getchar(); ll x=0; int op=1;
	for (; !isdigit(ch); ch=getchar()) if (ch=='-') op=-1;
	for (; isdigit(ch); ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 200005
#define lc (o<<1)
#define rc (o<<1|1)
int n,a[N],tr[2][N<<1];
int Min(int x,int y){ return a[x]<a[y]?x:y; }
void up(int typ,int o){ tr[typ][o]=Min(tr[typ][lc],tr[typ][rc]); }
void build(int typ,int o,int l,int r){
	if (l==r){ tr[typ][o]=2*l-typ; return; }
	int mid=l+r>>1;
	build(typ,lc,l,mid); build(typ,rc,mid+1,r);
	up(typ,o);
}
int qry(int typ,int o,int l,int r,int x,int y){
	if (x<=l && r<=y) return tr[typ][o];
	int mid=l+r>>1,ret=0;
	if (x<=mid) ret=Min(ret,qry(typ,lc,l,mid,x,y));
	if (y>mid) ret=Min(ret,qry(typ,rc,mid+1,r,x,y));
	return ret;
}
void modify(int typ,int o,int l,int r,int x){
	if (l==r){ a[l]=inf; return; }
	int mid=l+r>>1;
	if (x<=mid) modify(typ,lc,l,mid,x); else modify(typ,rc,mid+1,r,x);
	up(typ,o);
}
struct node{
	int l,r,x,y,tg; node(){}
	node(int l_,int r_,int tg_){
		l=l_,r=r_,tg=tg_;
		if (l+1==r) x=l,y=r;
		else{
			if (!tg) x=qry(tg^1,1,1,n/2,(l+1)/2,r/2),y=qry(tg,1,1,n/2,(x+1)/2,r/2);
			else x=qry(tg^1,1,1,n/2,(l+1)/2,r/2),y=qry(tg,1,1,n/2,(x+2)/2,(r+1)/2);
			//cerr<<(l+1)/2<<' '<<(r+1)/2<<endl;
			
			//cerr<<"["<<l<<","<<r<<"]: x="<<x<<", y="<<y<<endl;
		}
	}
	bool operator < (const node &t) const{ return a[x]>a[t.x]; }
};
priority_queue<node> q;
void ins(int x,int y,int tg){ if (x<y) q.push(node(x,y,tg)); }
int main(){
	n=read();
	rep (i,1,n) a[i]=read(); a[0]=inf;
	build(1,1,1,n/2); build(0,1,1,n/2);
	q.push(node(1,n,0));
	rep (step,1,n/2){
		node tmp=q.top(); q.pop();
		printf("%d %d ",a[tmp.x],a[tmp.y]);
		//cerr<<tmp.x<<' '<<tmp.y<<endl;
		ins(tmp.l,tmp.x-1,tmp.tg);//1,2
		//cerr<<"ins: ";
		//cerr<<tmp.l<<' '<<tmp.x-1<<endl;
		ins(tmp.x+1,tmp.y-1,tmp.tg^1);//4,7
		//cerr<<tmp.x+1<<' '<<tmp.y-1<<endl;
		ins(tmp.y+1,tmp.r,tmp.tg);//9,8
		//cerr<<tmp.y+1<<' '<<tmp.r<<endl;
		//cerr<<"===="<<endl;
	}
	return 0;
}
/*
4
3 2 4 1
8
4 6 3 2 8 5 7 1
*/

Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}


void solve(long long N, std::vector<long long> A){
    LL s = 0;
    REP(i, N) {
        s += A[i];
    }
    //$(s);
    VI ls(N), rs(N);
    for (LL i = 1; i < N; i++) {
        ls[i] = (i == 1 ? 0 : ls[i - 2]) + A[i - 1] * 2;
    }
    for (LL i = N - 2; i >= 0; i--) {
        rs[i] = (i == N - 2 ? 0 : rs[i + 2]) + A[i] * 2;
    }
    /*REP(i, N) {
        cout << ls[i] << " ";
    }
    cout << endl;
    REP(i, N) {
        cout << rs[i] << " ";
    }
    cout << endl;*/
    REP(i, N) {
        LL ans = s - (i == 0 ? 0 : ls[i - 1]) - (i == N - 1 ? 0 : rs[i + 1]);
        if (i % 2 == 1) {
            ans -= 2 * A[N - 1];
        }
        cout << ans;
        if (i != N - 1) cout << " ";
    }
    cout << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 3712
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)

	counterMap := make(map[string]int)
	for i := 0; i < N; i++ {
		var s string
		fmt.Scanf("%s", &s)
		if _, ok := counterMap[s]; !ok {
			counterMap[s] = 1
			continue
		}
		counterMap[s]++
	}
	fmt.Println(len(counterMap))

}


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

int main()
{
    int x, y;
    scanf("%d%d", &x, &y);
    getchar();
    char a[105][105];
    for(int i = 0; i < x; ++i)
    {
        scanf("%s", a[i]);
        getchar();
    }
    for(int i = 0; i < y + 2; ++i)
    {
        cout << '#';
    }
    cout << endl;
    for(int i = 0; i < x; ++i)
    {
        cout << '#';
        cout << a[i] << '#' << endl;
    }
    for(int i = 0; i < y + 2; ++i)
    {
        cout << '#';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define int long long
#define double long double
#define INF INT_MAX
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, m, a, b, s[100010];
signed main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> a >> b;
		s[a]++;
		s[b]++;
	}
	REP(i, n) {
		if (s[i] % 2) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int main(){
	int n;
	scanf("%d",&n);
	int t;
	scanf("%d",&t);
	int a,b;
	int miloc=-1;
	for(int i=0;i<n;i++){
		scanf("%d %d",&a,&b);
		if(b<=t){
			if(miloc==-1){
				miloc=a;
			}
			else if(miloc!=-1){
				if(a<miloc){
					miloc=a;
				}
			}
		}
	}
	if(miloc!=-1){
		printf("%d\n",miloc);
	}
	else{
		printf("TLE\n");
	}
} 


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

int main(){
    ll a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e - a <= k)
        cout << "Yay!" << "\n";
    else
        cout << ":(" << "\n";
    return 0;
} 


Measured memory_bytes: 256
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))
 
ans = 0
for i in range(N):  # １番短い棒
    for j in range(i + 1, N):  # 真ん中の長さの棒
        ans += bisect_left(L, L[i] + L[j]) - (j + 1)
 
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

//long long a[1002];


int main()
{

	char b;
	cin >> b;
	if (b == 'A') {
		cout << 'T';
	}else if (b == 'T') {
		cout << 'A';
	}else if (b == 'C') {
		cout << 'G';
	}
	else if (b == 'G') {
		cout << 'C';
	}

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
ll mx(ll a,ll b){if(a>=b) return a;return b;}
ll mn(ll a,ll b){if(a<b) return a;return b;}
#define pb push_back
#define mp make_pair
#define M (ll) (1e5+7)
#define INF (3e18)
typedef vector < vector<pll> > vvpll;
int main() {
    ios_base::sync_with_stdio(0),cin.tie(0);
//    freopen("zotiland.gir","r",stdin);
//    freopen("zotiland.cik","w",stdout);
    ll n,k,q;
    cin>>n>>k>>q;
    vi v(n,0);
    for(ll i=0;i<q;i++){
        ll a;cin>>a;
        v[a-1]++;
    }
    for(ll i=0;i<n;i++){
        if(k-(q-v[i])>0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}



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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;
struct UnionFind {
    vector<int> parent; //parent[i]はiの親の番号
    vector<int> rank; // rank[i]は木の深さ
    vector<int> size; // size[i]はグループに含まれている頂点数
    vector<int> loop; // グループに含まれているloopの数

    UnionFind(int n) {
        //コンストラクタは全て自分が根
        parent = vector<int>(n);
        rank = vector<int>(n);
        size = vector<int>(n);
        loop = vector<int>(n);
        for (int i=0;i<n;i++) {
            parent[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }

    int root(int x) { //根を再帰で辿りつつ、探索したものを繋ぎなおし
    if (parent[x] == x) return x;
    return parent[x] = root(parent[x]);
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) {
            loop[rx]++;
            return;
        }
        if (rank[rx] < rank[ry]) {
            parent[rx] = ry;
            size[ry] += size[rx];
            loop[ry] += loop[rx];
        }
        else {
            parent[ry] = rx;
            size[rx] += size[ry];
            loop[rx] += loop[ry];
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int getSize(int x){
        return size[root(x)];
    }

    int getLoopNum(int x){
        return loop[root(x)];
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind uf = UnionFind(N);
    vector<set<int>> good(N);
    for (int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        a--;b--;
        uf.unite(a,b);
        good[a].insert(b);
        good[b].insert(a);
    }
    vector<set<int>> bad(N);
    for (int i=0;i<K;i++){
        int c, d;
        cin >> c >> d;
        c--;d--;
        if (uf.same(c,d)){
            bad[c].insert(d);
            bad[d].insert(c);
        }
    }
    vector<int> ans(N);
    for (int i=0;i<N;i++){
        ans[i] += uf.getSize(i) - 1;
        ans[i] -= good[i].size();
        ans[i] -= bad[i].size();
    }
    for (int i=0;i<N;i++){
        cout << ans[i];
        if (i==N-1) cout << "\n";
        else cout << " ";
    }
}

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

int main(){

    int N;
    cin >> N;
    vector<int> t(N), x(N), y(N);
    for(int i = 0; i < N; i++) cin >> t[i] >> x[i] >> y[i];

    bool ans = true;
    int pt = 0, px = 0, py = 0;
    for(int i = 0; i < N; i++){
        if(abs(px - x[i]) + abs(py - y[i]) <= abs(pt - t[i])){
            if((abs(px - x[i]) + abs(py - y[i])) % 2 == abs(pt - t[i]) % 2){

            }else{
                ans = false;
            }
        }else{
            ans = false;
        }
    }

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


    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>

using namespace std;

int starttime (int time);
int endtime (int time);


int main() {
    int n, k;
    cin >> n >> k;
    
    vector<int> x;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        x.push_back(tmp);
    }
    
    int ans = 0;
    for (int i = 0; i < x.size(); i++) {
        if (k - x[i] <= x[i]) {
            ans += (k - x[i]) * 2;
        }
        else {
            ans += x[i] * 2;
        }
    }
    
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,ra,re) for((i)=ra;(i)<(re);(i)++)
#define _rep(i,ra,re) for((i)=ra;(i)>(re);(i)--)
#define rep_(i,ra,re) for((i)=ra;(i)<=(re);(i)++)
#define _rep_(i,ra,re) for((i)=ra;(i)>=(re);(i)--)
#define put(n) cout << n << " "; 
#define puts(n) cout << n << endl;
#define pu(n) cout << n;
#define mod 1000000007
int i,j,k,l;
static const int MAX_N=10e5;
int B[MAX_N];
int main(void){
	int N;cin >> N;
	long ans=0;rep(i,0,N-1){
		cin >> B[i];}
	rep(i,0,N-2){
		if(B[i]<B[i+1]){
			ans+=B[i];
		}else{
			ans+=B[i+1];
		}
	}
	ans+=(B[N-2]+B[0]);
	puts(ans);
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    ll h;
    cin >> h;
    vector<ll> vec;
    vec.push_back(h);
    if (h == 1){
        cout << 1 << endl;
        return 0;
    }
    while(h != 1){
        h /= 2;
        vec.push_back(h);
    }
    ll kake = 1;
    ll ans  = 0;
    rep(i,vec.size()){
        ans += kake;
        kake *= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import annotation.tailrec
import collection.mutable.ListBuffer
import io.StdIn

object Main extends App {

  @tailrec
  def primeFactRec(acc:ListBuffer[Long], num:Long, root:Long):List[Long] = {

    if(root * root > num) (acc += num).toList
    else {
      if(num % root == 0L) primeFactRec((acc += root), num/root, root)
      else primeFactRec(acc, num, root+1L)
    }
  }

  def callPrimeFactRec(n:Long):List[Long] = {
    val ret = ListBuffer.empty[Long]
    primeFactRec(ret, n, 2L)
  }

  val n = StdIn.readLong

  val ans = callPrimeFactRec(n)
  println(n + ": " + ans.mkString(" "))
}


Measured memory_bytes: 43752
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b,c;
    cin>>a>>b>>c;

    //|a-b|+|b-c|が答えで中間値bは相殺される
    cout<<max(a,max(b,c))-min(a,min(b,c))<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
using namespace std; 
void solve(); 
int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
  
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("error.txt", "w", stderr); 
    freopen("output.txt", "w", stdout); 
#endif 
  
    int t = 1; 
    // cin >> t; 
    while (t--) { 
        solve(); 
    } 
  
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
    return 0; 
} 

void solve() 
{ 
	string s1, s2;
  	cin >> s1 >> s2;
  
  	if (s1 == s2.substr(0,s1.size())) {
      cout << "Yes\n";
      return;
    }
        
    cout << "No\n";
  	
}

Measured memory_bytes: 3844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define inf 10000000000000

int cnt = 0;

void merge(int *A, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1 + 1];
    int R[n2 + 1];
    int i, j;

    for (i = 0; i < n1; i++)
    {
        L[i] = A[left + i];
    }
    for (i = 0; i < n2; i++)
    {
        R[i] = A[mid + i];
    }
    L[n1] = inf;
    R[n2] = inf;
    i = 0;
    j = 0;
    for (int k = left; k < right; k++)
    {
        if (L[i] <= R[j])
        {
            A[k] = L[i];
            i += 1;
        }
        else
        {
            A[k] = R[j];
            j += 1;
        }
        cnt += 1;
    }
}

void mergeSort(int *A, int left, int right)
{
    int mid;
    int cnt;
    if (left + 1 < right)
    {
        mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(void)
{
    int n;
    int S[5000000];

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &S[i]);
    }

    mergeSort(S, 0, n);

    printf("%d", S[0]);
    for (int i = 1; i < n; i++)
    {
        printf("% d", S[i]);
    }
    printf("\n%d\n", cnt);

    return 0;
}


Measured memory_bytes: 5652