akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using p = pair<int,int>;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int n,m;
  n = c/b;
  if(c%b != 0) n++;
  m = a/d;
  if(a%d != 0) m++;
  if( m >= n ) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout << ((f) ? "Yes" : "No") << endl;
#define YORN(f) cout << ((f) ? "YES" : "NO") << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (int i = m; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];

    int c = 0;
    rep2(i, 1, n - 1)
    {
        if ((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
            (p[i + 1] < p[i] && p[i] < p[i - 1]))
        {
            c++;
        }
    }
    put(c);
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n;
string s;
vector<int> b(26, 1);

int main() {
	cin >> n >> s;
	
	inc(i, n) { b[s[i] - 'a']++; }
	
	LL ans = 1, MOD = 1e9 + 7;
	inc(i, 26) { (ans *= b[i]) %= MOD; }
	(ans += (MOD - 1)) %= MOD;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
/*input
2 3 3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, k; cin >> a >> b >> k;
    if(a < k)
    {
    	k -= a;
    	a = 0;
    }
    else
    {
    	a -= k;
    	k = 0;
    	cout << a << ' ' << b;
    	return 0;
    }
    cout << 0 << ' ' << max(0LL, b - k);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int n, m, x, sum;

int main(){ 
    ios_base::sync_with_stdio(0);

    cin >> n >> m;

    for(int i=0; i < m; ++i) {
        cin >> x;
        sum += x;
    }

    cout << max(-1, n - sum) << endl;


    return 0;
}



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

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

int main() {
 
  string s1 , s2 ;
  cin >> s1 >> s2  ;
  
  
  rep(i,min(s1.size(),s2.size())){
    cout << s1.at(i) << s2.at(i) ;
  }
  
  if(s1.size() >s2.size())
    cout << s1.at(s1.size()-1);


}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;
// mod
int mod = 1e9 + 7;

struct mint {
    unsigned x;

    mint() : x(0) {}

    mint(signed sig) { x = sig < 0 ? sig % mod + mod : sig % mod; }

    mint(signed long long sig) { x = sig < 0 ? sig % mod + mod : sig % mod; }

    int get() const { return (int) x; }

    mint& operator+=(mint that) {
        if ((x += that.x) >= mod) x -= mod;
        return *this;
    }

    mint& operator-=(mint that) {
        if ((x += mod - that.x) >= mod) x -= mod;
        return *this;
    }

    mint& operator*=(mint that) {
        x = (unsigned long long) x * that.x % mod;
        return *this;
    }

    mint& operator/=(mint that) { return *this *= that.inverse(); }

    mint operator+(mint that) const { return mint(*this) += that; }

    mint operator-(mint that) const { return mint(*this) -= that; }

    mint operator*(mint that) const { return mint(*this) *= that; }

    mint operator/(mint that) const { return mint(*this) /= that; }

    mint inverse() const {
        long long a = x, b = mod, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            std::swap(a, b);
            u -= t * v;
            std::swap(u, v);
        }
        return mint(u);
    }

    bool operator==(mint that) const { return x == that.x; }

    bool operator!=(mint that) const { return x != that.x; }

    mint operator-() const {
        mint t;
        t.x = x == 0 ? 0 : mod - x;
        return t;
    }
};


class DSumOfLargeNumbers {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, K;
        cin >> N >> K;

        vector<int> sum(N + 1);
        FOR(i, 1, N) {
            sum[i] += sum[i - 1] + i;
        }

        mint res = 0;
        FOR(i, K, N + 1) {
            mint l = sum[i - 1];
            mint r = sum[N];
            if (N - i >= 0) r -= sum[N - i];
            res += r - l + 1;
        }
        cout << res.get() << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DSumOfLargeNumbers solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 4764
import math
p=[0 for k in range(100000)]
p[1]=1
for k in range(3,100000,2):
    f=1
    for l in range(2,int(math.sqrt(k))+1):
        if k%l==0:
            f=0
            break
    if f==1:
        p[k]=1
c=[0 for k in range(100000)]
c[3]=1
for k in range(3,100000,2):
    if p[k] and p[(k+1)//2]:
        c[k]=1
for k in range(1,100000):
    c[k]+=c[k-1]
for k in range(int(input())):
    l,r=map(int,input().split())
    print(c[r]-c[l-1])


Measured memory_bytes: 7192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (b-a==c-b) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 22224
#include<bits/stdc++.h>
using namespace std;
  int main ()
  {
    int n,i,j,sum,ans;
    sum=0;
    const int mod=2019;
    const int ro=1344;
    vector<int> kai(1345);
    kai.at(0)=1;
    for(i=1;i<1345;i++)
    {
      kai.at(i)=kai.at(i-1)*10%mod;
     // cout << kai.at(i) << endl;
    }
    
    
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    //cout << s;
    n=s.size();
   // cout << n << endl;
    vector<int> R(2019);
    R.at(0)=1;
    for(i=1;i<2019;i++)
    {
     R.at(i)=0;
    }
    for(i=0;i<n;i++)
    {
      j=s.at(i)-'0';
       sum=(sum+kai.at(i%1344)*j)%mod;
       //cout << j << " " << sum << endl;
      R.at(sum)++;
    }
    ans=0;
    for(i=0;i<2019;i++)
    {
      ans+=(R.at(i)-1)*R.at(i)/2;
    }
    cout << ans;
    
    
    
     
    
  }



Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
int L;
int ask(string s){
    cout<<"? "<<s<<endl;
    cout.flush();
    int ans; cin>>ans;
    return ans;
}
bool check(string s){
    if((int)s.size()>128) return false;
    int ans = ask(s);
    if(ans+(int)s.size()==L) return true;
    return false;
}
struct node{
    string s;
    bool friend operator < (const node &p1,const node &p2){
        if(p1.s.size()!=p2.s.size()) return p1.s.size()<p2.s.size();
        else return p1.s<p2.s;
    }
};
node merge(node a,node b){
    string s = a.s;
    int pos = 0;
    for(char c: b.s){
        while(1){
            string t = s.substr(0,pos) + c + s.substr(pos);
            pos++;
            if(pos-1==(int)s.size()||check(t)){
                s = t;
                break;
            }
        }
    }
    return (node){s};
}
int main(){
    L = 1e9;
    string table;
    for(int i=0;i<26;i++) table += char('a'+i), table += char('A'+i);
    for(int i=0;i<10;i++) table += char('0'+i);
    map<char,int> m;
    for(char i: table){
        string s; s+=i;
        L = min(L,m[i]=ask(s));
    }
    L++;
    set<node> st;
    for(char c: table) if(m[c]==L-1){
        string s; s += c;
        while(check(s+c)) s += c;
        st.insert({s});
    }
    while(st.size()!=1){
        node a = *st.begin(); st.erase(a);
        node b = *st.begin(); st.erase(b);
        st.insert(merge(a,b));
    }
    cout<<"! "<<(*st.begin()).s<<endl;
}


Measured memory_bytes: 3808
#include <iostream>
#include <climits>
#include <vector>
#include <algorithm>

using namespace std;

#define whole(xs) (xs).begin(),(xs).end()

// Longest Increasing Subsequence
int LIS(vector<int>& xs) {
    vector<int> L(xs.size(), INT_MAX);
    for (int i = 0; i < xs.size(); i++) {
        (*lower_bound(whole(L), xs[i])) = xs[i];
    }
    return lower_bound(whole(L), INT_MAX) - L.begin();
}

int N;
vector<int> A;
int main() {
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    cout << LIS(A) << endl;
    return 0;
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
const ll MOD = 1000000007;
//const ll MOD = 998244353;

int main() {
	int H, A;
	cin >> H >> A;
	if (H % A == 0) {
		cout << H / A << endl;
	}
	else {
		cout << H / A + 1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <iterator>
#include <cmath>
#include <map>
using namespace std;



void func161b() {
  int n, m, ans = 0, sum = 0;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  for (int i = 0; i < n; i++) {
    if(a[i] >= 0.25*sum/m) {
      ans++;
    }
  }
  if(ans < m) {
    cout << "No" << "\n";
  }else{
    cout << "Yes" << "\n";

  }
}



int main(void) {
  func161b();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;
using mat2d_t = std::vector<std::vector<int64_t>>;

struct fast_combination {
    fast_combination(int n, int mod_) :fac(n+1, 0), finv(n+1, 0), inv(n+1, 0), mod_(mod_) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i=2; i<=n; ++i) {
            fac[i] = fac[i-1] * i % mod_;
            inv[i] = mod_ - inv[mod_%i] * (mod_/i) % mod_;
            finv[i] = finv[i-1] * inv[i] % mod_;
        }
    }

    int64_t operator()(int n, int k) {
        if (n > fac.size()-1) return -1;
        if (n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n-k] % mod_) % mod_;
    }

    std::vector<int64_t> fac, finv, inv;
    int mod_;
};

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

    fast_combination fc(n, mod);
    i64 ans{0};

    for (int i=0; i<min(n,k+1); ++i) {
        ans += fc(n,i) * fc(n-1, n-i-1);
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
import bisect
from collections import Counter
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))

k = II()
print((k//2) ** 2) if k % 2 == 0 else print((k//2) * (k//2 + 1))


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

const int MAXN = 1.1e5;
int N;
vector<int> adj[MAXN];
int par[MAXN];
int sz[MAXN];
void dfs(int cur, int prv) {
	par[cur] = prv;
	sz[cur] = 1;
	for (int nxt : adj[cur]) {
		if (nxt == prv) continue;
		dfs(nxt, cur);
		sz[cur] += sz[nxt];
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N-1; i++) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1, 0);
	vector<int> dq;
	for (int cur = N; cur; cur = par[cur]) {
		dq.push_back(cur);
	}
	assert(dq.back() == 1);
	int s = sz[dq[int(dq.size()) / 2 - 1]];
	if (s >= N - s) {
		cout << "Snuke" << '\n';
	} else {
		cout << "Fennec" << '\n';
	}

	return 0;
}


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

using namespace std;

void No() {
    cout << "No\n";
    exit(0);
}
void Yes() {
    cout << "Yes\n";
    exit(0);
}

struct Cell {
    int x, y, a;
};
bool operator < (Cell c1, Cell c2) {
    return c1.x < c2.x;
}

const long long INF = 1e18;
vector<vector<int> > gr, w;
vector<long long> p, comp;
int numComp;

bool dfs(int v) {
    comp[v] = numComp;    
	for (int i = 0; i < (int)gr[v].size(); ++i) {
        int nv = gr[v][i];
        int nw = p[v] + w[v][i];
        if (p[nv] == INF) {
            p[nv] = nw;
            if (!dfs(nv))
                return false;
        }
        else if (p[nv] != nw)
            return false;
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(0);
    int n, m, q;
    cin >> n >> m >> q;
    vector<Cell> qs;
    for (int i = 0; i < q; ++i) {
        int x, y, a;
        cin >> x >> y >> a;
        --x;
        --y;

        qs.push_back(Cell{x, y, a});
    }

    sort(qs.begin(), qs.end());
    gr.assign(m, vector<int>());
    w.assign(m, vector<int>());

    for (int i = 0; i + 1 < q; ++i)
        if (qs[i].x == qs[i+1].x) {
            gr[qs[i].y].push_back(qs[i+1].y);
            w[qs[i].y].push_back(qs[i+1].a - qs[i].a);
            gr[qs[i+1].y].push_back(qs[i].y);
            w[qs[i+1].y].push_back(qs[i].a - qs[i+1].a);
        }
    p.assign(m, INF);
    comp.assign(m, 0);
    numComp = 0;
    for (int i = 0; i < m; ++i)
        if (p[i] == INF) {
            p[i] = 0;
            ++numComp;
            if (!dfs(i))
                No();
        }
    vector<long long> minNums(numComp + 1, INF);
    for (int i = 0; i < q; ++i)
        minNums[comp[qs[i].y]] = min(minNums[comp[qs[i].y]], p[qs[i].y]);
    for (int i = 0; i < q; ++i)
        if (qs[i].a + minNums[comp[qs[i].y]] - p[qs[i].y] < 0)
            No();
    Yes();
    
    return 0;
}

Measured memory_bytes: 13556
#include <stdio.h>
int main(void)
{
	int a,b,c,d,s;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	if((b<c)||(a>d))
	  s=0;
	else 
	{
		if(a<c)
	      if(b>d)
	        s=d-c;
	      else s=b-c;
	    else if(b<d)
	         s=b-a;
	         else
	         s=d-a;
	}
	printf("%d",s);
	return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll N;
ll P[10];
ll Q[10];
vector<vector<ll>> T;

void dfs(vector<ll> v) {
    if (v.size() == N) {
        T.push_back(v);
        return;
    }

    REP(i, N) {
        bool exist = false;
        REP(j, v.size()) {
            if (v[j] == i + 1)
                exist = true;
        }
        if (exist)
            continue;
        v.push_back(i + 1);
        dfs(v);
        v.pop_back();
    }
    return;
}

int main() {
    cin >> N;
    REP(i, N) {
        cin >> P[i];
    }
    REP(i, N) {
        cin >> Q[i];
    }

    vector<ll> v;
    dfs(v);

    ll a, b;
    REP(i, T.size()) {
        bool p = true;
        REP(j, N) {
            if (T[i][j] != P[j])
                p = false;
        }
        if (p)
            a = i;
        bool q = true;
        REP(j, N) {
            if (T[i][j] != Q[j])
                q = false;
        }
        if (q)
            b = i;
    }

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

    return 0;
}

Measured memory_bytes: 4408
s = list(input())
n = len(s)
news = []
i = 0
while i < n:
    if i != n-1:
        if s[i] == "B" and s[i+1] == "C":
            news.append("X")
            i += 2
        else:
            news.append(s[i])
            i += 1
    else:
        news.append(s[i])
        i += 1

ans = 0
n = len(news)
xcounter = 0
for i in range(n):
    if news[-i-1] == "X":
        xcounter += 1
    elif news[-i-1] == "A":
        if xcounter > 0:
            ans += xcounter
    else:
        xcounter = 0
print(ans)

Measured memory_bytes: 6436
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

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

int main() {
    int n;
    cin>>n;
    int MAX=0;
    for(int i=0;i<=n;i++){
        if((i*(i+1))/2>=n){
            MAX=i;
            break;
        }
    }
    vector<int>vec;
    for(int i=MAX;i>=1;i--){
        if(n-i>=0){
            n-=i;
            cout<<i<<endl;
        }
    }
    // cout<<"AAA"<<MAX<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N , M; cin >> N >> M;
    ll le, ri;
    cin >> le >> ri;
    for(int i=0; i<M-1; i++){
        ll a, b; cin >> a >> b;
        if(a>le){le = a;}
        if(b<ri){ri = b;}
    }
    if(ri - le >= 0){
        cout << ri - le + 1;
    }
    else{
        cout << 0;
    }
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
H,W,D = map(int,input().split())
A = []
for h in range(H):
  A = A + list(map(int,input().split()))
for i in range(H*W):
  A[i]=(A[i], i%W, i//W)
A.sort()
Dist=[0]*(H*W)
for i in range(H*W):
  if i>=D:
    Dist[i] = Dist[i-D] + abs(A[i][1]-A[i-D][1]) + abs(A[i][2]-A[i-D][2])
Q = int(input())
for q in range(Q):
  L,R = map(int,input().split())
  ret = Dist[R-1]-Dist[L-1]
  print(ret)

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

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ldb long double 
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int MOD = 1e9+7;
const int MX = 2e5+5;
const ll INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n)
{
 ll res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a*=a;
  n/=2;
}
return res;
}

ll abst(ll a)
{
 return ((a<0)?(-1*a):(a));
}

int main()
{
    int n,m;
    cin>>n>>m;
    int pen=0,rec=0;
    mi mp;
    for(int i=0;i<m;i++)
    {
        int p;
        str s;
        cin>>p;
        cin>>s;
        if(s=="WA"&&(mp[p]!=-1))
         mp[p]++;
         else
         {
             if(mp[p]!=-1)
             {
                 rec++;
                 pen+=mp[p];
                 mp[p]=-1;
             }
         }
    }
    cout<<rec<<" "<<pen<<"\n";
    return 0;
}

Measured memory_bytes: 4992
n,m = map(int, input().split())
mo = list(map(int,input().split()))
dp = [float("inf") for i in range(n+2)]
dp[0] = 0
for i in range(n+1):
    for j in mo:
        if i+j <= n:
            dp[i+j] = min(dp[i+j],dp[i]+1)
print(dp[n])



Measured memory_bytes: 7388
# -*- coding: utf-8 -*-
from collections import deque

def main():
    N = int(input())
    M = [[]]
    for cm in range(N):
        A = list(map(int,input().split()))
        M.append(A)

    q = deque(range(1, N+1))
    day = [0] * (N+1)
    opponent = [-1] * (N+1)

    while q:
        a = q.popleft()
        if len(M[a]) > 0:
            b = M[a][0]
            if opponent[b] == a:
                day[a] = day[b] = max(day[a],day[b]) + 1
                opponent[a] = opponent[b] = -1
                M[a].pop(0)
                M[b].pop(0)
                q.append(a)
                q.append(b)
            else:
                opponent[a] = b

    remain = max([len(Mx) for Mx in M])
    if remain > 0:
        print(-1)
    else:
        answer = max(day)
        answer = answer if answer > 0 else -1
        print(answer)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 35404
import itertools
 
n,m,q = list(map(int, input().split()))
num_list = [list(map(int,input().split())) for l in range(q)]

result = 0
 
kumi = itertools.combinations_with_replacement(range(1, m+1), n)

for kumi in kumi:
    temp = 0
    for j in range(q):
        if kumi[num_list[j][1]-1] - kumi[num_list[j][0]-1] == num_list[j][2]:
            temp += num_list[j][3]
            result = max(temp,result)

print(result) 

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)

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

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

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

    int dp[11];

    dp[0] = 1;

    for(int i=1;i<=n;i++){
        dp[i] = min(dp[i-1]*2,dp[i-1] + k);
    }  

    cout<<dp[n]<<endl;

}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    if (N % 1000 == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 1000 - (N % 1000) << endl;
    }

    return 0;
}

Measured memory_bytes: 3524
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-27 15:49:30
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n; cin >> n;
  vector<int64> a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];

  int64 add = 0;

  for (int i = n - 1; i >= 0; --i) {
    a[i] += add;
    add += (a[i] + b[i] - 1LL) / b[i] * b[i] - a[i];
  }

  cout << add << endl;

  return 0;
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	var f []int
	fmt.Scan(&n, &k)

	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		f = append(f, a)
	}

	sort.Slice(f, func(i, j int) bool {
		return f[i] < f[j]
	})
	var ret int
	for _, i := range f[:k] {
		ret += i
	}
	fmt.Println(ret)
}


Measured memory_bytes: 1928
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <sstream>
#include <math.h>
#include <functional>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007

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

int main() {
	string s;
	cin >> s;
	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy")
		cout << "Rainy" << endl;
	else
		cout << "Sunny" << endl;

}



Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = IR(n)
    if all([not i&1 for i in a]):
        print("second")
    else:
        print("first")
    return

#Solve
if __name__ == "__main__":
    solve()


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

public class Main {
	public static int n,k;
	//public static int count;
	public static int[] arr,dp;
	public static int frog2(int pos)
	{
		if(pos>=n-1)
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int cost=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
			if(pos+i<n)
			{ cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			}
		return dp[pos]=cost;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		k=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(frog2(0));
	
	}

}


Measured memory_bytes: 71272
#include<stdio.h>
int main()
{
	int tc;
	scanf("%d",&tc);
	char input[105];
	scanf("%s",input);
	int temp = tc/2,flag = 1;
	if(tc % 2 == 1)
	{
		printf("No\n");
	}
	else{
		for(int i = 0,j = temp;i<temp;i++,j++)
		{
			if(input[i] != input[j])
			{
				flag = 0;
				break;
			}
		}
		if(flag == 1)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1632
#include <bits/stdc++.h>
#pragma GCC target ("arch=skylake-avx512")
using namespace std;
using VI = vector<int>;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define all(v) v.begin(), v.end()

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

  int n, q; cin >> n >> q;
  VI c(n); rep(i, n) cin >> c[i];
  vector<pair<int, int>> lr(q); rep(i, q) cin >> lr[i].first >> lr[i].second;
  rep(i, q) lr[i].first--;

  const int sq = 10;
  VI ri(q), lri(q);
  VI cnt(n+1);
  rep(i, q) cnt[lr[i].second]++;
  rep(i, n) cnt[i+1] += cnt[i];
  repr(i, q) ri[--cnt[lr[i].second]] = i;
  fill(all(cnt), 0);
  rep(i, q) cnt[lr[i].first >> sq]++;
  rep(i, n) cnt[i+1] += cnt[i];
  repr(i, q) lri[--cnt[lr[ri[i]].first >> sq]] = ri[i];
  fill(all(cnt), 0);

  VI ans(q);

  int prev = -1;
  int lx, rx;
  int sum = 0;
  for (auto i : lri) {
    auto [l, r] = lr[i];
    if (l >> sq != prev) {
      fill(all(cnt), 0);
      lx = rx = r;
      prev = l >> sq;
      sum = 0;
    }
    int cx;
    while (lx > l) if (cnt[cx=c[--lx]]++ == 0) sum += 1;
    while (lx < l) if (--cnt[c[lx++]] == 0) sum -= 1;
    while (rx < r) if (cnt[cx=c[rx++]]++ == 0) sum += 1;
    ans[i] = sum;
  }
  rep(i, q) cout << ans[i] << "\n";
}


Measured memory_bytes: 17400
#include <bits/stdc++.h>
#include <algorithm>
#include <string>

using namespace std;
int main(void){
    // Your code here!
    int n;
    int b=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++){
        b=a[b]-1;
        if(b==1){
            cout<<i+1<<endl;
            return 0;
        }
    }
    
    
    cout<<-1<<endl;

}


Measured memory_bytes: 640
def solve(n, a):
    honest = [0] * n
    for i0 in range(2):
        for i1 in range(2):
            honest[0] = i0
            honest[1] = i1
            for i in range(1, n-1):
                if honest[i]:
                    if a[i] == 'o':
                        honest[i+1] = honest[i-1]
                    if a[i] == 'x':
                        honest[i+1] = 1 - honest[i-1]
                if not honest[i]:
                    if a[i] == 'o':
                        honest[i+1] = 1 - honest[i-1]
                    if a[i] == 'x':
                        honest[i+1] = honest[i-1]
            ok = True
            if honest[0]:
                if honest[-1] == honest[1]:
                    ok &= a[0] == 'o'
                else:
                    ok &= a[0] == 'x'
            if not honest[0]:
                if honest[-1] == honest[1]:
                    ok &= a[0] == 'x'
                else:
                    ok &= a[0] == 'o'
            # if i1 == 1 and not ok:
            #     print(honest)

            if honest[-1]:
                if honest[-2] == honest[0]:
                    ok &= a[-1] == 'o'
                else:
                    ok &= a[-1] == 'x'
            if not honest[-1]:
                if honest[-2] == honest[0]:
                    ok &= a[-1] == 'x'
                else:
                    ok &= a[-1] == 'o'

            if ok:
                t = 'WS'
                res = ''.join([t[j] for j in honest])
                # print(honest)
                return res
    return -1

n = int(input())
s = input()

res = solve(n, s)
print(res)


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

vector<ll>par(2e5+10);
void init(ll n) {
  for(ll i=0;i<n;i++) {
    par[i]=i;
  }
}

ll root(ll x) {
  if(par[x]==x) {
    return x;
  }
  else {
    return par[x]=root(par[x]);
  }
}

bool same(ll x, ll y) {
  return root(x)==root(y);
}

void unite(ll x, ll y) {
  if(same(x,y)) return;
  par[root(x)]=root(y);
}

int main() {
  ll h,w;
  cin >> h >> w;
  vector<string> box(h);
  for(ll i=0;i<h;i++) {
    cin >> box[i];
  }
  init(h*w);
  vector<ll> idx={1,0,1,0};
  vector<ll> idy={0,1,0,1};
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      for(ll k=0;k<4;k++) {
        ll ny=i+idy[k];
        ll nx=j+idx[k];
        if(ny>-1&&ny<h&&nx>-1&&nx<w) {
          if(box[i][j]!=box[ny][nx]) {
            unite(i*w+j,ny*w+nx);
          }
        }
      }
    }
  }
  map<ll,ll> wn;
  map<ll,ll> bn;
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      if(box[i][j]=='#') {
        bn[root(i*w+j)]++;
      }
      else {
        wn[root(i*w+j)]++;
      }
    }
  }
  ll ans=0;
  for(auto p:bn) {
    ans+=p.second*wn[p.first];
  }
  cout << ans << endl;
}

Measured memory_bytes: 19456
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1111;
const int MOD = 1000000007;
int dp[maxn][20];
int main()
{
    int H , W, K ;
    cin>>H>>W>>K;
    dp[0][0] = 1;
    for(int i = 0 ; i < H ; i ++)
    {
        for(int j = 0 ; j < W ; j ++)
        {
            for(int k = 0 ; k < (1<<(W-1)) ; k ++)
            {
                int ok = 1;
                for(int l = 0 ; l < W-2 ; l++)
                {
                    if(((1<<l)&k) && ((1<<(l+1)) & k)) ok = 0;
                }
                if(ok)
                {
                    if(j-1>=0 && (1<<(j-1) & k))
                    {
                        dp[i+1][j-1] += dp[i][j];
                        dp[i+1][j-1] %= MOD;
                    }
                    else if(j <= W - 2 && ((1<<j) & k))
                    {
                        dp[i+1][j+1] += dp[i][j];
                        dp[i+1][j+1] %= MOD;
                    }
                    else
                    {
                        dp[i+1][j] += dp[i][j];
                        dp[i+1][j] %= MOD;
                    }
                }
            }
        }
    }
    cout<<dp[H][K-1]<<"\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
 if (a==25) cout << "Christmas";
  if (a==24) cout << "Christmas Eve";
  if (a==23) cout << "Christmas Eve Eve";
  if (a==22) cout << "Christmas Eve Eve Eve";
  cout << endl;
  
}


Measured memory_bytes: 256
n = input()
S = map(int, raw_input().split())
q = input()
T = map(int, raw_input().split())

def b_search(key):
    left = 0
    right = n
    while( left < right ) :
        mid =  (left + right) // 2

        if ( key == S[mid] ):
            return 1
        if ( key > S[mid] ):
            left = mid + 1 
        if ( key < S[mid] ):
            right = mid
    return 0

if __name__ == "__main__":
    ans = 0
    for i in T:
        if b_search(i) == 1:
            ans += 1
    print(ans)

Measured memory_bytes: 14780
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;

void cinv(vector<ll> &V){
	ll t;
	cin >> t;
	V.push_back(t);
}

int main()
{
	ll N,M=0,A=0,R=0,C=0,H=0,ANS=0;
	vector<ll> S;
	cin >> N;
	fore(i,0,N){
		string s;
		cin>>s;
		if(s[0]=='M')M++;
		if(s[0]=='A')A++;
		if(s[0]=='R')R++;
		if(s[0]=='C')C++;
		if(s[0]=='H')H++;
	}
	if(M!=0)S.push_back(M);
	if(A!=0)S.push_back(A);
	if(R!=0)S.push_back(R);
	if(C!=0)S.push_back(C);
	if(H!=0)S.push_back(H);

	if(S.size()<=2){
		cout << "0" << endl;
	}
	else{
		if(S.size()==3){
			cout << S[0]*S[1]*S[2] << endl;
		}
		else if(S.size()==4){
			ANS=ANS+S[0]*S[1]*S[2];
			ANS=ANS+S[0]*S[1]*S[3];
			ANS=ANS+S[0]*S[2]*S[3];
			ANS=ANS+S[1]*S[2]*S[3];
			cout << ANS << endl;
		}
		else{
			ANS=ANS+S[0]*S[1]*S[2];
			ANS=ANS+S[0]*S[1]*S[3];
			ANS=ANS+S[0]*S[1]*S[4];
			ANS=ANS+S[0]*S[2]*S[3];
			ANS=ANS+S[0]*S[2]*S[4];
			ANS=ANS+S[0]*S[3]*S[4];
			ANS=ANS+S[1]*S[2]*S[3];
			ANS=ANS+S[1]*S[2]*S[4];
			ANS=ANS+S[1]*S[3]*S[4];
			ANS=ANS+S[2]*S[3]*S[4];
			cout << ANS << endl;
		}
	}

}

Measured memory_bytes: 256
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A, B, C, X = map(int, read().split())

ans = 0
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if X == 500 * i + 100 * j + 50 * k:
                ans += 1
print(ans)


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N >> Q;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	vector< int > sum(N + 1, 0), sum2(N + 1, 0);
	rep(i, N) sum[i + 1] = sum[i] + A[i];
	rep(i, N) sum2[i + 1] = (i > 0 ? sum2[i - 1] : 0) + A[i];
	while (Q--) {
		int x;
		cin >> x;
		int l = 0, r = N;
		while (r - l > 1) {
			int m = (l + r) / 2;
			int b = (lower_bound(A.begin(), A.end(), x * 2 - A[m]) - A.begin());
			if (m - b + 1 >= N - m) {
				r = m;
			} else {
				l = m;
			}
		}
		//cout << r << endl;
		//cout << sum[N] << " " << sum[r] << endl;

		int ans = sum[N] - sum[r] + ((r * 2 - N >= 0) ? sum2[r * 2 - N] : 0);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4096
# C - Tsundoku
def calc_cusum(n):
	cusum = [0] * (n + 1)
	arr = input().split()
	
	for i in range(n):
		cusum[i + 1] = cusum[i] + int(arr[i])
	
	return cusum


def get_max_book(cusum):
  global k
  
  for i in range(len(cusum)):
    if cusum[i] > k:
      return i -1
  
  return len(cusum) - 1


n, m, k = map(int, input().split())
a = calc_cusum(n)
b = calc_cusum(m)

ans = 0
j = get_max_book(b)

for i in range(n + 1):
  while j > 0 and a[i] + b[j] > k:
    j -= 1
  
  if a[i] + b[j] <= k:
    ans = max(ans, i+j)

print(ans)

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

using namespace std;

int main()
{
  int n,a,b;
  int c = 0, d;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (c < a) {
      c = a;
      d = b;
    }
  }
  cout << c+d << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
ll lcm(ll a, ll b)  
 {  
    return (a*b)/__gcd(a, b);  
 } ;

int main() 
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
	cin>>a[i];
	}
	int count=0;
	int k=1;
	for(int i=0;i<n;i++)
	{
		if(a[i]==k)
		{
			k++;
		}
		else
		{
			count++;
		}
	}
	
	    if(count==n)
	    {
	    	cout<<-1;
	    	return 0;
		}
		cout<<count;
		return 0;	
	}
 

Measured memory_bytes: 1024
#include <cstdio>
#include <math.h>
#include <algorithm>
 
const int MAX_N = 200000;
 
long long int p[MAX_N];

int n = 0;
int lowid, midid, highid;
long long int c = 0;
long long int target = 0;

long long int nearPow = 1;

void quickSort(long long int numbers[], int array_size) {
  std::sort(numbers, numbers + array_size);
}

void solve(int x) {
  if (x > 1){
    if (p[x - 1] % 2 == 1) {
      solve(x - 1);
    } else if ((p[x - 1] & (p[x - 1] - 1)) == 0) {
      if (p[x - 2] == p[x - 1]) {
        c += 1;
        solve(x - 2);
      } else {
        solve(x - 1);
      }
    } else {
      nearPow = pow(2.0, (floor(log2(p[x - 1] - 1)) + 1.0));
      target = nearPow - p[x - 1];
  
      highid = x - 2;
      lowid = 0;

      while (lowid <= highid) {
        midid = (lowid + highid) / 2;
        if (p[midid] == target) {
          while (p[midid - 1] == target) {
            midid -= 1;
          }
          p[midid] -= 1;
          c += 1;
          break;
        } else if (p[midid] < target) {
          lowid = midid + 1;
        } else {
          highid = midid - 1;
        }
      }
      solve(x - 1);
    }
  }
}
 
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &p[i]);
  }
  for (int i = 0; i < n; i++) {
    p[i] *= 2;
  }
  quickSort(p, n);
  solve(n);
  printf("%lld\n", c);
 
  return 0;
}


Measured memory_bytes: 1792
def main():
    a, b, c, d = map(int, input().split())

    if b <= c or d <= a:
        print(0)
    elif c <= a and b <= d:
        print(b - a)
    elif a <= c and d <= b:
        print(d - c)
    elif a <= c <= b:
        print(b - c)
    elif c <= a <= d:
        print(d - a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// https://atcoder.jp/contests/abc015/tasks/abc015_4

#include <bits/stdc++.h>

using namespace std;

#define ll long long 
#define REPL(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
static const int MAX = 10010;
static const ll INFTY = 1e12;
static const ll NUMMAX = 1000000007;
static const ll MOD = 1000000007;
#define LOOP 10000000
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 入力
int H, W;
vector<string> field;
int result = 100;
int dfs_res = 0;

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; }
void add(ll &a, ll b) {
    a += b;
    if (a >= MOD) a %= MOD;
}

int main() {


    int H, W;
    cin >> H >> W;
    char grid[H][W];
    ll dp[H+10][W+10];
    //vector<int> dp(N+1, MAX);
    REP(i, H)REP(j, W){ cin >> grid[i][j]; }
    REP(i, H+1)REP(j, W+1){ dp[i][j] = 0; }

    dp[0][0] = 1;
    //REP(i, H){
    //    REP(j, W){
    //        if(i == 0 && j == 0)/*dp[i][j] = 1*/;
    //        else if(i == 0){
    //            if(grid[i][j] == '#'){
    //                dp[i][j] = 0;
    //            } else {
    //                dp[i][j] = dp[i][j-1];
    //            }
    //        }else if(j == 0){
    //            if(grid[i][j] == '#'){
    //                dp[i][j] = 0;
    //            } else {
    //                dp[i][j] = dp[i-1][j];
    //            }
    //        }
    //        else {
    //            if(grid[i-1][j] == '#'){
    //                dp[i][j] = dp[i][j-1];
    //            } else if(grid[i][j-1] == '#'){
    //                dp[i][j] = dp[i-1][j];
    //            } else {
    //                dp[i][j] = dp[i-1][j] + dp[i][j-1];
    //            }
    //       }
    //       dp[i][j] %= MOD;
    //    }
    //}
    //REP(i, H){
    //    REP(j, W){ 
    //        cout << dp[i][j] << " "; 
    //    }cout << endl; 
    //}
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (i+1 < H && grid[i+1][j] == '.') add(dp[i+1][j], dp[i][j]);
            if (j+1 < W && grid[i][j+1] == '.') add(dp[i][j+1], dp[i][j]);
            //dp[i][j] %= MOD;
        }
    }
    cout << dp[H-1][W-1] << endl;

    return 0;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/





Measured memory_bytes: 9216