akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>

#define MAX 10000
#define NIL -1

struct Node {
	int parent;
	int left;
	int right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d)
{
	if(u == NIL) {
		return;
	}
	D[u] = d;

	setDepth(T[u].left, d + 1);
	setDepth(T[u].right, d + 1);
}


int setHeight(int u) 
{
	int h1, h2;
	h1 = h2 = 0;

	if (T[u].left != NIL) {
		h1 = setHeight(T[u].left) + 1;
	}
	if (T[u].right != NIL) {
		h2 = setHeight(T[u].right) + 1;
	}

	return H[u] = (h1 > h2) ? h1 : h2;
}

int getSibling(int u)
{
	if (T[u].parent == NIL) {
		return NIL;
	}

	if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) {
		return T[T[u].parent].left;
	}

	if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) {
		return T[T[u].parent].right;
	}


	return NIL;
}

void print(int u)
{
	printf("node %d: ",u);
	printf("parent = %d, ", T[u].parent);
	printf("sibling = %d, ", getSibling(u));

	int deg = 0;

	if (T[u].left != NIL) {
		deg++;
	}
	if (T[u].right != NIL) {
		deg++;
	}

	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ", H[u]);
	
	if (T[u].parent == NIL) {
		printf("root\n");
	}
	else if (T[u].left == NIL && T[u].right == NIL) {
		printf("leaf\n");
	}
	else {
		printf("internal node\n");
	}
}


void preParse(int u) {
	if (u == NIL) {
		return;
	}

	printf(" %d",u);

	preParse(T[u].left);
	preParse(T[u].right);
}

void inParse(int u)
{
	if (u == NIL) {
		return;
	}

	inParse(T[u].left);
	printf(" %d",u);
	inParse(T[u].right);


}

void postParse(int u)
{
	if (u == NIL) {
		return;
	}

	postParse(T[u].left);
	postParse(T[u].right);
	printf(" %d",u);
}


int main(void)
{
	int v, l, r, root = 0;
	scanf("%d",&n);

	for (int i = 0; i < n; i++) {
		T[i].parent = NIL;
	}

	for (int i = 0; i < n; i++) {

	}

	for (int i = 0; i < n; i++) {
		scanf("%d %d %d",&v,&l,&r);
		T[v].left = l;
		T[v].right = r;
		if (l != NIL) {
			T[l].parent = v;
		}
		if (r != NIL) {
			T[r].parent = v;
		}
	}

	for (int i = 0; i < n; i++) {
		if (T[i].parent == NIL) {
			root = i;
			break;
		}
	}

	setDepth(root, 0);
	setHeight(root);

	printf("Preorder\n");
	preParse(root);

	printf("\nInorder\n");
	inParse(root);

	printf("\nPostorder\n");
	postParse(root);
	putchar('\n');

	return 0;

}

Measured memory_bytes: 3212
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var m, x int
	Fscan(in, &m)
	vis := make([]bool, m)
	for i := 1; ; i++ {
		if x = (x*10 + 7) % m; x == 0 {
			Fprint(out, i)
			return
		}
		if vis[x] {
			break
		}
		vis[x] = true
	}
	Fprint(out, -1)
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 2872
n,x = map(int,input().split())
l = list(map(int,input().split()))
ans = 0
if l[0] > x:
  ans += l[0]-x
  l[0] -= ans
for i in range(1,n):
  if l[i]+l[i-1] > x:
    b = l[i]+l[i-1]-x
    ans += b
    l[i] -= b
print(ans)

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

long long int f(long long int x, long long int y) {
	if (x < y)return f(y, x);
	long long int r;
	while (r = x % y) {
		x = y;
		y = r;
	}
	return y;
}

int main() {
	long long int A, B, C, D;
	cin >> A >> B >> C >> D;
	long long int g = C * D / f(C, D);
	long long int c = B / C;
	long long int d = B / D;
	long long int m = B / g;

	long long int ans;
	ans = B - (c + d - m);


	long long int cc = (A-1) / C;
	long long int dd = (A-1) / D;
	long long int mm = (A-1) / g;

	long long int ans1 = (A - 1) - (cc + dd - mm);

	cout << ans - ans1<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
typedef pair<pair<lint, int>, pair<int, int>> ppp;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9 + 7;
const lint INF = mod;
const int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    pair<double, double> p[n];
    rep(i, n){
        double x, y;
        scanf("%lf%lf", &x, &y);
        p[i] = make_pair(x, y);
    }
    sort(p, p+n);
    double ans=0;
    do{
        rep(i, n-1) ans+=sqrt((p[i].fi-p[i+1].fi)*(p[i].fi-p[i+1].fi) + (p[i].se-p[i+1].se)*(p[i].se-p[i+1].se));
    }while(next_permutation(p, p+n));
    For(i, 1, n+1) ans/=(double)i;
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 256
N, K = map(int, input().split())
Alist = list(map(int, input().split()))
path = [0]
next = Alist[0]
seen = set()
seen.add(0)
while (next-1) not in seen:
    seen.add(next-1)
    path.append(next-1)
    next = Alist[next-1]
base = path.index(next-1)
loop_length = len(path) - base
loop = path[base:base+loop_length+1]
# print(path)
# print(loop, loop_length, base)
if K <= base:
    print(path[K]+1)
else:
    K -= base
    print(loop[K%loop_length]+1)


Measured memory_bytes: 40652
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
ll modpow(ll b, ll e ,ll mod) {
	ll ans = 1;
	for (; e; b = b * b % mod, e /= 2)
		if (e & 1) ans = ans * b % mod;
	return ans;
}

/**
 * Description: Class to handle points in the plane.
 * 	T can be e.g. double or long long. (Avoid int.)
 * Status: Works fine, used a lot
 */

template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P normalize(){
		if(x == 0){
			return P(0,1);
		}
		if(y == 0){
			return P(1,0);
		}
		ll gc = __gcd(x,y);
		P k = P(x/gc,y/gc);
		if(k.y < 0) k.x = -k.x , k.y = -k.y;
		return k;
	}
	P perp() const {
		if(x == 0){
			return P(1,0);
		}
		if(y == 0){
			return P(0,1);
		}
		ll gc = __gcd(x,y);
		P k = P(-y/gc,x/gc);
		if(k.y < 0) k.x = -k.x , k.y = -k.y;
		return k;
	}
	
	friend ostream& operator<<(ostream& os, P p) {
		return os << "(" << p.x << "," << p.y << ")"; }
};

typedef Point<ll> P;
const ll mod = 1000000007;



int32_t main(){
	ll ans = 1;
	int n;
	cin >> n;
	map<P, ll> cnt;
	ll f = 0 ;
	vector<P> v(n);
	for(int i = 0 ; i < n; i ++){
		ll x,y;
		cin >> x >> y;
		if(x == 0 && y== 0){
			f ++ ;
		}		
		else{
			cnt[P(x,y).normalize()] ++ ;
		}
	}
	set<P> jf;
	for(auto w : cnt){
		if(!jf.count(w.first)){
			ans  = (ans *(modpow(2, w.second ,mod) + modpow(2 , cnt[w.first.perp()] , mod) - 1 + mod)%mod) % mod;
			jf.insert(w.first);
			jf.insert(w.first.perp());
		}
	}
	ans = (ans + f - 1)%mod;
	if(ans < 0) ans += mod;
	cout << ans << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  vector<vector<int>> T(N + 1);
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    T[A[i]].push_back(B[i]);
    T[B[i]].push_back(A[i]);
  }
  for (int i = 0; i < T[1].size(); i++) {
    int t = T[1][i];
    for (int j = 0; j < T[t].size(); j++) {
      if (T[t][j] == N) {
        cout << "POSSIBLE" << '\n';
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << '\n';
  return 0;
}


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

#define PB push_back
#define MP make_pair
#define fi first
#define se second

typedef long long LL;

const double EPS=1e-9;
const double PI=acos(-1.0);
const int MAXN=100005;
const LL MOD=1000000007;
const int dx[8]={-1, 0, 1, -1, 1, -1, 0, 1}, dy[8]={-1, -1, -1, 0, 0, 1, 1, 1};

void base(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

bool stat[101];

int main(){
	base();
	int n, d, ans=0;
	cin>>n;

	while(n--){
		cin>>d;
		if(!stat[d]){
			ans++;
			stat[d]=1;
		}
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	h := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &h[i])
	}
	sort.Ints(h)
	min := math.MaxInt32
	for i := 0; i < N-K+1; i++ {
		diff := h[i+K-1] - h[i]
		if diff < min {
			min = diff
		}
	}
	fmt.Println(min)
}


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  int f[26] = {};
  for(int i=0; i<n-1; i++){
    f[s[i]-'a']++;
    int b[26] = {};
    for(int j=i+1; j<n; j++){
      b[s[j]-'a']++;
    }
    int tmp = 0;
    for(int k=0; k<26; k++){
      if(f[k]&&b[k]) tmp++;
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    if(s[0]=='0')k--;
    int m=0,p=0;
    vector<int>x(1,-1);
    for(int i=0;i<n;i++){
        if(k<0){
            k++;
            p++;
        }
        if(s[i]=='1' && s[i+1]=='0')k--;
        if(s[i]=='0' && s[i+1]=='1')x.push_back(i);
        m=max(m,i-x[p]);
    }
    cout<<m<<endl;
    return 0;
}

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

#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <set>
typedef long long int ll;
typedef double ld;
using namespace std;

class CFennecVsMonster {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int n,k;
	    in>>n>>k;
	    vector<int>a;
	    for(int i=0;i<n;i++)
        {
	        int temp;
	        in>>temp;
	        a.push_back(temp);
        }

	    if(k>=n)
        {
	        out<<0<<endl;
	        return;
        }

	    sort(a.begin(),a.end());

	    for(int i=0;i<k;i++)
        {
	        a.pop_back();
        }
	    ll sum=0;

	    for(auto f:a)
	        sum+=f;

	    out<<sum<<endl;


	}
};


int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    CFennecVsMonster solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())

using namespace std;

int n, k;
int a[100005];
vector<int> u[100005];
int res = 0;

int go(int i, int pr) {
    int md = 0;
    for (int j : u[i]) {
        int dst = go(j, i);
        md = max(md, dst+1);
    }
    if (md == k-1 && pr != 0) {
        res++;
        md = -1;
    }
    return md;
}

int main() {
    scanf("%d %d", &n, &k);
    FO(i,0,n) {
        scanf("%d", a+i);
        a[i]--;
    }
    if (a[0] != 0) {
        a[0] = 0;
        res++;
    }
    FO(i,1,n) u[a[i]].push_back(i);
    go(0,0);
    printf("%d\n", res);
}


Measured memory_bytes: 10752
#include <stdio.h>
#include <stdlib.h>

int space[8][8] = {0};

void resetSpace()
{
    int i, j;
    for (i = 0; i < 8; i++) for (j = 0; j < 8; j++) space[i][j] = 0;
}

void inputToSpace(char input[], int row)
{
    int i;
    for (i = 0; i < 8; i++){
        space[row][i] = input[i] - '0';
    }
}

int shapeCheck (void)
{
    int i, j, k, flag, found;
    int relativeJ, relativeK;

    flag = 0;
    for (j = 0; j < 8; j++){
        for(k = 0; k < 8; k++){
            if(space[j][k] == 1){
                flag = 1;
                break;
            }
        }
        if (flag == 1) break;
    }

    relativeK = k;
    relativeJ = j;

    if (space[j][k + 1] == 1 && space[j + 1][k] == 1 && space[j + 1][k + 1] == 1) return 0;
    if (space[j + 1][k] == 1 && space[j + 2][k] == 1 && space[j + 1][k] == 1) return 1;
    if (space[j][k + 1] == 1 && space[j][k + 2] == 1 && space[j][k + 3] == 1) return 2;
    if (space[j + 1][k] == 1 && space[j + 1][k - 1] == 1 && space[j + 2][k - 1] == 1) return 3;
    if (space[j][k + 1] == 1 && space[j + 1][k + 1] == 1 && space[j + 1][k + 2] == 1) return 4;
    if (space[j + 1][k] == 1 && space[j + 1][k + 1] == 1 && space[j + 2][k + 1] == 1) return 5;
    if (space[j][k + 1] == 1 && space[j + 1][k] == 1 && space[j + 1][k - 1] == 1) return 6;
}

int main(void)
{
    char input[9];
    int i, j, k, id;

    while(1){
        resetSpace();
        for (i = 0; i < 8; i++){
            if (scanf("%s", input) == EOF) return (0);
            inputToSpace(input, i);
        }

        // for (i = 0; i < 8; i++){
        //     for (j = 0; j < 8; j++){
        //         printf("%d", space[i][j]);
        //     }
        //     putchar('\n');
        // }

        id = shapeCheck();

        if (id == 0) printf("A\n");
        else if (id == 1) printf("B\n");
        else if (id == 2) printf("C\n");
        else if (id == 3) printf("D\n");
        else if (id == 4) printf("E\n");
        else if (id == 5) printf("F\n");
        else if (id == 6) printf("G\n");
        else printf("ERROR\n");
    }

    return (0);
}


Measured memory_bytes: 2032
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

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

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9; 
const int N = 6e5+5;                                         
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}

int p[N];

int get (int x) {
	if(p[x]) return p[x] = get(p[x]);
	return x;
}

int main () {
	SpeedForce;
	
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		int a, b;
		cin >> a >> b;
		if((a=get(a)) == (b=get(b)))
			continue;
		--n;
		p[a] = b;
	}
	cout << n-1 << '\n';
	
	return Accepted;
}

// B...a


Measured memory_bytes: 4012
#include <stdio.h>
     
    int main() {
    	int N, K;
    	scanf ("%d %d", &N, &K);
    	int A[N + 1];	
    	
    	for (int i = 0; i < N; i++) {
    		scanf("%d", &A[i + 1]);
    	}
    	for (int i = K + 1; i <= N; i++) {
    		if ( A[i] > A[i - K]) {
    		    puts("Yes");
    		} else {
    			puts("No");
    		}
    	}
    }

Measured memory_bytes: 2412
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

map<ll,ll>pres, ind;

int main()
{
	FAST_IO;

 	ll n, x, m, sum = 0, ans = 0, b;
 	cin >> n >> x >> m;
 	vector<ll>v;
 	v.pb(x);
 	pres[x] = 1;
 	ind[x] = 0;
 	for(;;)
 	{
 		ll temp = v.back();
 		ll y = (temp * temp) % m;
 		if(pres[y])
 		{
 			b = ind[y];
 			break;
 		}
 		pres[y] = 1;
 		ind[y] = sz(v);
 		v.pb(y); 	
 	}
 	if(n <= b)
 	{
 		for(int i=0;i<n;i++) ans += v[i];
 		cout << ans << endl;
 		return 0;
 	}
 	for(int i=0;i<b;i++) ans += v[i];
 	n -= b;
 	vector<ll>xx;
 	for(int i=b;i<sz(v);i++) xx.pb(v[i]), sum += v[i];
 	ll k = n / sz(xx);
 	ans += k * sum;
 	ll rem = (n % sz(xx));
 	for(int i=0;i<rem;i++) ans += xx[i];
 	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10512
import sys
import bisect
input = sys.stdin.readline
num=0
n=int(input())
top=list(map(int,input().split()))
mid=list(map(int,input().split()))
und=list(map(int,input().split()))
top.sort()
mid.sort()
und.sort()
for i in mid:
    a=bisect.bisect_left(top,i)
    c=n-bisect.bisect_right(und,i)
    num+=a*c
print(num)

Measured memory_bytes: 92516
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        double d = Double.parseDouble(in[1]);
        int c = 0;
        for(int i=0;i<n;i++){
            in = br.readLine().split(" ");
            double x = Double.parseDouble(in[0]);
            double y= Double.parseDouble(in[1]);
            if(Double.compare(d, Math.sqrt(Math.pow(x,2)+Math.pow(y,2)))>=0){
                c++;
            }
        }
            System.out.println(c);

    }
}


Measured memory_bytes: 47012
#include<bits/stdc++.h>
#define int long long
using namespace std;
int nCr[61][61],rr[61];

int cal(int n,int r){
  int res=1;
  vector<int> v;
  for(int i=0;i<r;i++)v.push_back(i+1);
  
  for(int i=n;i>n-r;i--){
    res*=i;
    for(int j=0;j<r;j++){
      int d=__gcd(res,v[j]);
      if(d!=1)v[j]/=d,res/=d;
    }
  }
  return res;
}

signed main(){
  for(int i=0;i<=60;i++)
    for(int j=0;j<=60;j++){
      nCr[i][j]=cal(i,j);
    }
  rr[0]=1;
  for(int i=1;i<=60;i++)rr[i]=rr[i-1]*2;
  int n,m;
  while(cin>>n>>m,n){
    m=rr[n]-m;
    int k;
    for(int i=n;i>=0;i--){
      k=i;
      if(m-nCr[n][i]<0)break;
      m-=nCr[n][i];
    }
    for(int i=n;i>0;i--){
      if(k==0||m>=nCr[i-1][k-1]){
	if(k)m-=nCr[i-1][k-1];
	cout<<0;
      }
      else k--,cout<<1;
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3144
import java.util.Scanner;

public class Main {
	 public static void main(String[] args) {
        String s;
        int m, h;
        Scanner sc = new Scanner(System.in);
        while(true){
            s = sc.next();
            if(s.equals("-")) break;
            m = sc.nextInt();
            for(int i = 0; i < m; i ++){
                h = sc.nextInt();
                s = s.substring(h) + s.substring(0, h);
            }
            System.out.println(s);
        }

    }
}


Measured memory_bytes: 26492
def dfs(l, A):
    for i, val in enumerate(l):
        A.append(val)
        if len(A) == N:
            As.append(A)
            A = A.copy()
            A.pop()
        else:
            sub_l = l[i:]
            A = dfs(sub_l, A)
            A.pop()
    return A


N, M, Q = map(int, input().split())
ls = []
for _ in range(Q):
    a, b, c, d = map(int, input().split())
    ls.append([a, b, c, d])

l = list(range(1, M + 1))
As = []
A = []
_ = dfs(l, A)

ans = 0
for A in As:
    # i=0; A = As[i]
    score = 0
    for i, l in enumerate(ls):
        # i=0; l=ls[i]
        if A[l[1] - 1] - A[l[0] - 1] == l[2]:
            score += l[3]
    if score >= ans:
        ans = score

print(ans)


Measured memory_bytes: 88596
N = int(input())
S = input()
R = [None] * N

for i, s in enumerate(S):
    if i == 0:
        if s == 'I':
            R[i] =  1
        else:
            R[i] = -1
    else:
        if s == 'I':
            R[i] = R[i-1] + 1
        else:
            R[i] = R[i-1] - 1

print(max(0, max(R)))


Measured memory_bytes: 3060
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
#define len(x) (1-(lint)ceil(-log((double)(x))/log(2)))
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

lint func(lint n) {
    if(n==1) return 1;
    else if(n%2) return ((n+1)/2)%2;
    else return n^func(n-1);
}

int main(){
    lint A, B;
    cin >> A >> B;
    cout << ((func(B))^(func(A-1))) << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        a: usize, b: usize, c: usize, d: usize,
    }

    if a + b == c + d {
        println!("Balanced")
    } else if a + b < c + d {
        println!("Right")
    } else {
        println!("Left")
    }
}


Measured memory_bytes: 2152
from bisect import bisect_right

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

for i in range(1, N+1):
    A[i] += A[i-1]

for i in range(1, M+1):
    B[i] += B[i-1]

b_cnt = M

ans = 0
for a_cnt in range(N+1):
    if A[a_cnt] > K:
        continue

    rest = K - A[a_cnt]

    while A[a_cnt] + B[b_cnt] > K:
        b_cnt -= 1

    ans = max(ans, a_cnt + b_cnt)

print(ans)


Measured memory_bytes: 39852
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    string s[N];
    lint t[N];
    for(int i = 0; i < N; i++){
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    int pos = N;
    for(int i = 0; i < N; i++){
        if(s[i] == x){
            pos = i;
            break;
        }
    }
    lint ans = 0;
    for(int i = pos + 1; i < N; i++){
        ans += t[i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<stack>
using namespace std;

int main()
{
    stack<int> S;
    int a,b;
    string s;

    while( cin >> s ){
        if (s[0] == '+') {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(a + b);
        } else if ( s[0] == '-') {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(b - a);
        } else if ( s[0] == '*') {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(a * b);
            
        } else {
            S.push(atoi(s.c_str()));
            
        }
    }
    cout << S.top() << endl;
    return 0;
    
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define lbd(a, x) lower_bound(all(a), x)
const int mod = 1e9 + 7;
int power_mod(int a, int b) {
	int res = 1;
	for(; b; b >>= 1, a = (ll) a * a % mod)
		if(b & 1) res = (ll) res * a % mod;
	return res;
}
#define sz(x) (int)(x).size()
const int N = 410;
int n, C;
int a[N], b[N], pw[N][N];
vector<int> multiply(const vector<int> &a, const vector<int> &b) {
	vector<int> c(sz(a) + sz(b));
	for(int i = 0; i < sz(a); i++)
		for(int j = 0; j < sz(b); j++)
			c[i + j] = (c[i + j] + (ll) a[i] * b[j]) % mod;
	if(c.size() > C + 1) c.resize(C + 1);
	return c;
}
vector<int> work(int l, int r) {
	if(l == r) {
		vector<int> ret(C + 1, 0);
		for(int i = 0; i <= C; i++) {
			ret[i] = (pw[b[l]][i] - pw[a[l]-1][i] + mod) % mod;
		}
		return ret;
	}
	int mid = (l + r) >> 1;
	auto al = work(l, mid);
	auto ar = work(mid + 1, r);
	return multiply(al, ar);
}
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> C;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
		cin >> b[i];
	for(int i = 1; i < N; i++) {
		for(int k = 0; k <= C; k++) {
			pw[i][k] = power_mod(i, k);
			pw[i][k] = (pw[i][k] + pw[i - 1][k]) % mod;
		}
	}
	auto z = work(0, n - 1);
	cout << z[C] << '\n';
	return 0;
}


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

char a[20],b[10]="YAKI";

int main()
{
    scanf("%s",a);
    for(int i=0;i<4;i++)
        if(a[i]!=b[i])
        {
            puts("No");
            return 0;
        }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include <deque>

using namespace std;
typedef long long ll;

vector<ll> vec;

int main() {
	while (1) {
		ll x, y, s, j = 0, ans = 0;
		cin >> x >> y >> s;
		if (x == 0 && y == 0 && s == 0)break;
		for (int i = 1; i < s; i++) {
			double box = (double)((s - (ll)(i*(x + 100) / 100) + 1) * 100) / (double)(x + 100);
			if (ceil(box) == floor(box)) {
				j = (ll)box - 1;
			}
			else {
				j = box;
			}
			if (j > 0 && j < s && i*(x + 100) / 100 + j*(x + 100) / 100 == s)ans = max(ans, i*(y + 100) / 100 + j*(y + 100) / 100);
		}
		vec.push_back(ans);
	}
	for (int i = 0; i < vec.size(); i++)cout << vec[i] << endl;
	return 0;
}


Measured memory_bytes: 3144
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        
        String result = "NO";
        if (a.charAt(a.length()-1) == b.charAt(0) && b.charAt(b.length()-1) == c.charAt(0)) result ="YES";
        
        System.out.println(result);
      
    }
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(T x,T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> T modinv(T x,const T mod){return modpow(x,mod-2,mod);}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

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

const ll MOD=1e9+7;
const int MAX=1e7+100;

int main() {
  // 条件を満たすl,rの組の数
  // sumASを作って、MのMODを取ったものを作る
  // 0~N(idx)で、rを動かして、それより左のl候補のうち、rと同じ数を足していく
  ll N,M;cin>>N>>M;
  vector<ll> AS(N);
  REP(i,N) cin>>AS[i];

  vector<ll> sumAS(N+1,0);
  REP(i,N) sumAS[i+1]=(sumAS[i]+AS[i])%M;
  // DUMP(sumAS);

  ll ans = 0;
  map<ll,ll> mp;
  REP(i,N+1) {
    ans+=mp[sumAS[i]];
    mp[sumAS[i]]++;
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, char const *argv[])
{
    short a,b,c;

    cin >> a >> b >> c;

    if (a < b && b < c)
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
    return 0;
}



Measured memory_bytes: 3028
x, n = gets.split.map(&:to_i)

if n == 0
  puts x
  exit
end

ary = gets.split(" ").map(&:to_i)

if !ary.include?(x)
  puts x
  exit
end

i = 1
while true do
  
  if !ary.include?(x-i)
    puts x-i
    exit
  end
  
  if !ary.include?(x+i)
    puts x+i
    exit
  end
  
  i += 1
  
end

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

int main(){
    int N;
    double a[110];
    scanf("%d", &N);
    int i;
    for(i=0; i<N; i++){
        scanf("%lf", &a[i]);
    }

    double ave=0;
    for(i = 0; i<N; i++){
        ave += a[i];
    }
    ave /= N;

    double min = 100000;
    int num=0;

    for (i=0; i<N; i++){
        if (min > fabs(ave - a[i])){
            min = fabs(ave - a[i]);
            num = i;
        }
    }

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

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
using namespace std;
#define PB push_back
int main() {
	int a,b,c;
	while(scanf("%d %d %d",&a,&b,&c)) {
		if (a==0&&b==0&&c==0) break;
		vector<int> part(a+b+c,2);
		vector<vector<int> > set;
		int N; scanf("%d",&N);
		int i,j,k,l;
		for (int cnt=0; cnt<N; cnt++) {
			scanf("%d %d %d %d",&i,&j,&k,&l);
			if (l==1) {
				part[i-1]=part[j-1]=part[k-1]=1;
			} else {
				vector<int> tmp(3);
				tmp[0]=i-1; tmp[1]=j-1; tmp[2]=k-1;
				set.PB(tmp);
			}
		}
		for (int cnt=0; cnt<set.size(); cnt++) {
			int n=part[set[cnt][0]], m=part[set[cnt][1]], p=part[set[cnt][2]];
			if (n==1&&m==1) part[set[cnt][2]]=0;
			if (n==1&&p==1) part[set[cnt][1]]=0;
			if (p==1&&m==1) part[set[cnt][0]]=0;
		}
		for (int cnt=0; cnt<a+b+c; cnt++) printf("%d\n",part[cnt]);
	}
}

Measured memory_bytes: 0
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int a = n/100;
      int c = n%10;
      int b = (n-100*a-c)/10;
      if(a==b&&b==c)System.out.println(n);
      else if(a<b)System.out.println( (a+1)*111 );
      else if(a>b)System.out.println(a*111);
      else if(a==b&&b>c)System.out.println(a*111);
      else if(a==b&&b<c)System.out.println( (a+1)*111 );
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long n, a, b, e = 0;
	cin >> n;
	int test[100001] = { 0 };
	int uiop[100001] = { 0 };
	for (int h = 1; h <= n; h++) {
		cin >> a >> b;
		test[h] = a;
		uiop[h] = b;
	}
	for (int h = n; h >= 1; h--) {
		if ((test[h] + e) % uiop[h] != 0) {
			e += uiop[h] - ((test[h] + e) % uiop[h]);
		}
	}
	cout << e << endl;
	cin >> e;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18


int main(){
    int N; cin >> N;
    vector<pair<pair<string,int>,int>> SPI(N);
    rep(i,N){
        cin >> SPI[i].first.first >> SPI[i].first.second;
        SPI[i].second = i+1;
        SPI[i].first.second *= -1;
    }
    sort(SPI.begin(),SPI.end());
    rep(i,N){
        cout << SPI[i].second << endl;
    }
}

Measured memory_bytes: 256
h,w = map(int, input().split())
s = [input() for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            flag = False
            for i_new, j_new in [(i+1, j), (i-1, j), (i,j+1), (i,j-1)]:
                if i_new<0 or i_new>=h or j_new<0 or j_new>=w: continue
                if s[i_new][j_new] == "#":
                    flag = True
                    break
            if not flag:
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 9148
s=input()
n = int(input())
s1=""
s2=""
t=0
for i in range(n):
    m=input().split()
    if len(m)==1:
        t=1-t
    else:
        if t==0:
            if int(m[1])==2:
                s2+=m[2]
            else:
                s1+=m[2]
        else:
            if int(m[1])==2:
                s1+=m[2]
            else:
                s2+=m[2]
    #print(s1,s2)
if t==0:
    s3=s1[::-1]
    print(s3+s+s2)
else:
    s=s[::-1]
    s2=s2[::-1]
    print(s2+s+s1)
            
        
            


Measured memory_bytes: 10200
#define NDEBUG
NDEBUG


#include <algorithm>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <random>

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


typedef int64_t int64;


using namespace std;

// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    /// caide keep
    template<int N>
    struct bytetype {
        
    };

    /// caide keep
    template<>
    struct bytetype<4> {
        
    };

    /// caide keep
    template<>
    struct bytetype<3> {
        
    };

    /// caide keep
    template<>
    struct bytetype<2> {
        
    };

    /// caide keep
    template<>
    struct bytetype<1> {
        
    };

    /// caide keep
    template<>
    struct bytetype<0> {
        
    };

    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

template<class T>
vector<T> next_vector(istream& in, size_t n) {
    vector<T> ret(n);
    for (size_t i = 0; i < n; ++i) {
        ret[i] = next<T>(in);
    }
    return ret;
}


void solve(istream& in, ostream& out) {
    int n = next<int>(in);
    int dst = next<int>(in);
    vector<int> d = next_vector<int>(in, n);
    vector<int> prob_d;
    int cur_dst = dst;
    prob_d.push_back(dst);
    for (int dd : d) {
        cur_dst = min(cur_dst, abs(cur_dst - dd));
        prob_d.push_back(cur_dst);
    }
    vector<int64> b(n + 1);
    b[n] = 1;
    for (int i = n-1; i >= 1; --i) {
        if (b[i + 1] <= d[i] / 2) {
            b[i] = b[i + 1];
        } else {
            b[i] = b[i + 1] + d[i];
        }
    }
    int cq = next<int>(in);
    FOR(i, cq) {
        int q = next<int>(in);
        int res = b[q] <= prob_d[q-1];
        out << (res ? "YES" : "NO") << endl;
    }
}


int main() {
    solve(cin, cout);
    return 0;
}



Measured memory_bytes: 9968
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*2
#define REP(i,n) for(long long i = 0;i < n;++i)
unsigned long xor128(void)
{
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
long long cnt[2227] = {};
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	long long ans = 0;
	REP(i, 26) {
		cnt[i]++;
	}
	for (int i = n - 1; i >= 0; --i) {
		long long geko = 1;
		for (int q = 0; q < 26; ++q) {
			if (q != s[i] - 'a') {
				geko *= cnt[q];
				geko %= MAX_MOD;
			}
		}
		cnt[s[i] - 'a']++;
		ans += geko;
		ans %= MAX_MOD;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll INF=100000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}
vector<ll> vectorprime(ll x){
	vector<bool> is_prime(x+1);
	vector<ll> prime;
	rep(i,x+1) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=x;i++){
		if(is_prime[i]){
			prime.pb(i);
		}
		for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
	}
	return prime;
}
//a,b x
int main(){
	ll N; cin>>N;
	vector<ll>B(N+1,100);
	vector<ll>ans;
	rep1(i,N) cin>>B[i];
	
	rep(i,N){
		for(int j=B.sz-1;j>=0;j--){
			if(j==B[j]){
				ans.pb(j);
				B.erase(B.bg+j);
				break;
			}
		}
	}
	if(B.sz==1){
		for(int i=ans.sz-1;i>=0;i--) cout<<ans[i]<<endl;
	}
	else cout<<-1;
}

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

using namespace std;

const int Nmax = 2005, inf = 1e9;

int First, Last, n, i, d, changes, ans = inf, k, j, st[Nmax], dr[Nmax], best, Max;
char a[Nmax], b[Nmax];
vector< pair<int,int> > v;


int main()
{
  //  freopen("input", "r", stdin);

    cin >> (a+1) >> (b+1);
    n = strlen(a+1);

    if(find(b+1, b+n+1, '1') == b+n+1)
    {
        cout << (find(a+1, a+n+1, '1') == a+n+1 ? 0 : -1) << '\n';
        return 0;
    }

    First = n+1, Last = 0;
    for(i=1; i<=n; ++i)
        if(b[i] == '1')
            First = min(First, i), Last = max(Last, i);

    d = n - Last;
    for(i=1; i<=n; ++i)
    {
        ++d;
        if(b[i] == '1') d = 0;
        st[i] = d;
    }

    d = First - 1;
    for(i=n; i; --i)
    {
        ++d;
        if(b[i] == '1') d = 0;
        dr[i] = d;
    }

    for(i=0; i<n; ++i)
    {
        changes = 0; v.clear();
        for(j=1, k = i + 1; j<=n; ++j, ++k)
        {
            if(k == n + 1) k = 1;
            if(b[j] != a[k]) ++changes;

            if(a[k] == '1' && st[k] > i)
                v.push_back({st[k] - i, dr[k]});
        }

        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());

        Max = 0; best = inf;
        for(auto it : v)
        {
            best = min(best, it.first + Max);
            Max = max(Max, it.second);
        }

        best = min(best, Max);
        ans = min(ans, changes + i + 2 * best);
    }

    for(i=1; i<n; ++i)
    {
        changes = 0; v.clear();
        for(j=1, k = n-i+1; j<=n; ++j, ++k)
        {
            if(k == n+1) k = 1;
            if(b[j] != a[k]) ++changes;

            if(a[k] == '1' && dr[k] > i)
                v.push_back({st[k], dr[k] - i});
        }

        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());

        Max = 0; best = inf;
        for(auto it : v)
        {
            best = min(best, it.first + Max);
            Max = max(Max, it.second);
        }

        best = min(best, Max);
        ans = min(ans, changes + i + 2  * best);
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define forn(i,n) for(ll i=0 ; i<n ; i++)
#define arr(a,n) for(ll i=0;i<n;i++){ cin>>a[i]; }
#define ub upper_bound
#define pb push_back
#define pi pair<int,int>
#define mod 1000000007
#define vectormax *max_element
#define vectormin *min_element
#define arraysize 1000000
#define setbit _builtin_popcountll
using namespace std;

ll ipow(ll x, ll n)
{
    ll result = 1;
    while (n) {
        if (n & 1)
            result = result * x % mod;
        n = n / 2;
        x = x * x % mod;
    }
    return result;
}

int main(){
    fio
   string a,b;
   cin>>a>>b;
   int c=0;
   for(int i=0;i<a.length();i++){
    if(a[i]!=b[i])
        c++;
   }
   cout<<c;

  return 0;
}


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

#define    ll     long long int

int main( )
{
    int n, i, j, k;
    int odd = 0, four = 0, two = 0;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> j;
        if (j % 2) {
            odd++;
        }
        else if (j % 4 == 0) {
            four++;
        }
        else {
            two++;
        }
    }
    if (odd <= four) {
        cout << "Yes\n";
    }
    else if (odd - four == 1 && two == 0) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
count=0
#print(p)
p_sorted = sorted(p)
#print(p_sorted)

for i in range(n):
    #print(i)
    if p[i]!=p_sorted[i]:
        count+=1
        #print(count)

if count==0 or count==2:
    print("YES")
else :
    print("NO")

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

int main(){
    string s;
    cin >> s;

    if((s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) ||
    (s[0] == s[2] && s[1] == s[3] && s[1] != s[2]) ||
    (s[0] == s[3] && s[1] == s[2] && s[1] != s[3])){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n,q = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n-1)]
px = [list(map(int, input().split())) for i in range(q)]
parent = [0] * n
ans = [0] * n

for i in ab:
  a,b=i[0],i[1]
  parent[b-1] = a-1
  
for j in px:
  p,x = j[0], j[1]
  ans[p-1] += x

for key, i in enumerate(ans[1:]):
  key += 1
  ans[key] += ans[parent[key]]
print(*ans)


Measured memory_bytes: 121432