akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N, K;
int a[100];
int cnt[50];
typedef pair<int, int> P;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> K;
    int m = 1000;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        m = min(m, a[i]);
    }
    bool judge = true;
    int sum = 0;
    vector<P> p;
    for(int i = 0; i < N; i++){
        if(a[i] < (K+1)){
            sum += (K+1-a[i]);
            cnt[i] += (K+1-a[i]);
            p.push_back(P(cnt[i], i));
            if((K+1-a[i]) > (K+1)/2) judge = false;
        }
    }
    sort(p.begin(), p.end(), greater<P>());
    vector<int> u;
    for(int i = 0; i < p.size(); i++){
        int n = p[i].second;
        int c = p[i].first;
        for(int j = 0; j < c; j++) u.push_back(n);
    }
    if(sum > K)judge = false;
    if(judge){
        vector<int> v(K);
        int cur = 0;
        for(int i = 0; i < u.size(); i++){
            int idx;
            if(i*2 < K) idx = i*2;
            else{
                int d = (i*2-K)/2;
                idx = d*2+1;
            }
            v[idx] = u[i]+1;
        }
        for(int i = u.size(); i < K; i++){
            int idx;
            if(i*2 < K) idx = i*2;
            else{
                int d = (i*2-K)/2;
                idx = d*2+1;
            }
            v[idx] = -1;
            for(int j = 0; j < N; j++){
                // if(cnt[j] == 0){
                    if(i*2 < K) {
                        v[idx] = j+1;
                        break;
                    }else{
                        if(v[idx-1] != j+1 && (idx+1 >= K || v[idx+1] != j+1)){
                            v[idx] = j+1;
                            break;
                        }
                    }
                // }
            }
            if(v[idx] == -1) return -1;
        }
        vector<int> ans;
        for(int i = 1; i <= N; i++){
            if(i != v[0]) ans.push_back(i);
        }
        for(int i = 1; i < K; i++){
            ans.push_back(v[i-1]);
            for(int j = 1; j <= N; j++){
                if(j != v[i] && j != v[i-1]) ans.push_back(j);
            }
        }
        ans.push_back(v[K-1]);
        for(int j = 1; j <= N; j++){
            if(j != v[K-1]) ans.push_back(j);
        }
        cout << N*(K+1)-K << endl;
        vector<int> s(N+1, 0);
        for(int i = 0; i < ans.size(); i++){
            cout << ans[i] << ' ';
            s[ans[i]]++;
            // if(s[ans[i]] > a[ans[i]-1]) return -1;
        }
        cout << endl;
    }else{
        cout << -1 << endl;
    }
}

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

class Dice{
	public:
		Dice(){
			num = new int[6];
			s = new int[6];
		};
	void setlabel(int n,int number){
		num[n] = number;
	}
	void roll(char ch){
	            for(int i=0;i<6;i++){
	                s[i] = num[i];
	            }
	            switch(ch){
	                case 'N':
	                    changenum(s[1],s[5],s[2],s[3],s[0],s[4]);
	                    break;
	                case 'E':
	                    changenum(s[3],s[1],s[0],s[5],s[4],s[2]);
	                    break;
	                case 'S':
	                    changenum(s[4],s[0],s[2],s[3],s[5],s[1]);
	                    break;
	                case 'W':
	                    changenum(s[2],s[1],s[5],s[0],s[4],s[3]);
	                    break;
	                case 't':
	                    changenum(s[0],s[2],s[4],s[1],s[3],s[5]);
	                    break;
	            }
	        };
	
	int right(){
		return num[2];
	}
	int left(){
		return num[3];
	}
	int front(){
		return num[1];
	}
	int top(){
		return num[0];
	}
	private:	
		void changenum(int n1,int n2,int n3,int n4,int n5,int n6){
			num[0] = n1;
			num[1] = n2;
			num[2] = n3;
			num[3] = n4;
			num[4] = n5;
			num[5] = n6;
		};
		
	private:
		int* num;
		int* s;
};


int main() {
	Dice dice;
	int label,q,n0,n1;
	char ch;
	for(int i=0;i<6;i++){
		cin >> label;
		dice.setlabel(i,label);
	}
	cin >> q;
	for(int i=0;i<q;i++){
		cin >> n0 >> n1;
		if(n0==dice.right()) dice.roll('W');
		if(n0==dice.left()) dice.roll('E');
		while(n0!=dice.top())dice.roll('N');
		while(n1!=dice.front()) dice.roll('t');
		cout << dice.right() << endl;
	}
	return 0;
}


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

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;}

int N;
int h[100010][3];
long long dp[100010][3];

int main(){
    cin >> N;
    for(int i=0;i<N;++i) for(int j=0;j<3;++j) cin >> h[i][j];

    for(int i=0;i<N;++i){
        for(int j=0;j<3;++j){
            for(int k=0;k<3;++k){
                if(j==k) continue;
                chmax(dp[i+1][j],dp[i][k] + h[i][j]);
            }
        }
    }

    long long ans = 0;
    for(int i=0;i<3;++i){
        chmax(ans,dp[N][i]);
    }
    cout << ans << endl;
    return 0;

}



Measured memory_bytes: 3712
#include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
ll N, Y, arr[3];


void solve() {
  ll x, y, Nmx;
  for(x = 0; x <= N; x++) {
    Nmx = N - x;
    for(y = 0; y <= Nmx; y++) {
      if(9000*x + 4000*y + 1000*N == Y) { // 10000*x + 5000*y + 1000*(N-x-y) == Y
	arr[0] = x, arr[1] = y, arr[2] = Nmx - y;
	return;
      }
    }
  }
}

int main() {
  cin >> N >> Y;
  memset(arr, -1, sizeof(arr));
  solve();
  cout << arr[0] << ' ' << arr[1] << ' ' << arr[2] << endl;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
using namespace std;

int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
    return x*f;
}

int N,M;
int num[40];

int main(){
    N=read(),M=read();
    for(int i=1;i<=N;i++){
        int n=read();
        for(int j=1;j<=n;j++){
            int x=read();
            num[x]++;
        }
    }
    int cnt=0;
    for(int i=1;i<=M;i++)
        cnt+=num[i]==N;
    printf("%d",cnt);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
 int A, B, C, result = 0;
 cin >> A >> B >> C;

 result = ((A * 10 + B) + C);
 result = max(result, (A + B * 10) + C);
 result = max(result, A + (B * 10 + C));
 result = max(result, A + (B + C * 10));
 result = max(result, B + (A * 10 + C));
 result = max(result, B + (A + C * 10));

 cout << result << endl;
}


Measured memory_bytes: 256
N = int(input())

A = list(map(int, input().split())) 

B = [0 for i in range(N+1)]

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

def combination(x):
    return int(x * (x-1) / 2)

C = [combination(i) for i in range(N + 1) ]

T = sum([combination(B[i]) for i in range(len(B)) ])
# print(T)

for i in range(N):
    # print(T - C[A[i]])
    print( T - C[B[A[i]]] + C[B[A[i]] - 1] )
    



Measured memory_bytes: 26140
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
//using namespace atcoder;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    deque<ll> m,p;
    rep(i,N){
        if(A[i] >= 0){
            p.push_back(A[i]);
        }else{
            m.push_back(A[i]);
        }
    }
    ll sum = 0;
    vector<Pll> ans;
    sort(m.rbegin(), m.rend());
    sort(p.begin(), p.end());
    while(1){
        if(p.size() + m.size() <= 2) break;
        if(!p.empty() && !m.empty()){
            ll pp = p.front();
            ll mm = m.front();
            p.pop_front();
            m.pop_front();
            if(m.empty()){
                m.push_back(mm - pp);
                ans.push_back({mm,pp});
            }else{
                p.push_back(pp - mm);
                ans.push_back({pp,mm});
            }
        }else if(p.empty()){
            ll m1 = m.front();
            m.pop_front();
            ll m2 = m.front();
            m.pop_front();
            p.push_back(m1-m2);
            ans.push_back({m1,m2});
        }else{
            ll p1 = p.front();
            p.pop_front();
            ll p2 = p.front();
            p.pop_front();
            m.push_back(p1-p2);
            ans.push_back({p1,p2});
        }
    }
    cout << p.front() - m.front() << endl;
    ans.push_back({p.front(), m.front()});
    rep(i,ans.size()){
        cout << ans[i].fi << " " << ans[i].se << endl;
    }
}

Measured memory_bytes: 7004
#include <iostream>
#include <set>
#include <map>

using namespace std;

int main() {
  while(1) {
    int N, M;
    cin >> N >> M;
    if(N == 0 && M == 0) break;
    int H[N], W[M];
    for(int i = 0; i < N; i++) {
      cin >> H[i];
    }
    for(int i = 0; i < M; i++) {
      cin >> W[i];
    }

    set<int> v1, v2;
    map<int, int> m1, m2;
    for(int i = 0; i < N; i++) {
      int bfr = 0;
      for(int j = i; j < N; j++) {
	int temp;
	temp = bfr + H[j];
	bfr = temp;
	v1.insert(temp);
	m1[temp]++;
      }
    }
    for(int i = 0; i < M; i++) {
      int bfr = 0;
      for(int j = i; j < M; j++) {
	int temp;
	temp = bfr + W[j];
	bfr = temp;
	v2.insert(temp);
	m2[temp]++;
      }
    }

    int cnt = 0;
    set<int>::iterator it1 = v1.begin();
    while(it1 != v1.end()) {
      set<int>::iterator it2;
      it2 = v2.find(*it1);
      if(it2 != v2.end()) cnt += m1[*it1]*m2[*it2];
      it1++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 31000
#include <iostream>
#include <vector>
#include <set>
using namespace std;

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

	int h, w;
	cin >> h >> w;
	vector<vector<char>> a(h);
	set<pair<int, int>> p;
	for (int i = 0; i < h; i++) {
		a[i].resize(w);
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#')
				p.insert({ i, j });
		}
	}
	int ans = 0;
	while (!p.empty()) {
		set<pair<int, int>> s;
		for (auto const& x : p) {
			for (int k = x.first - 1; k <= x.first + 1; k++) {
				for (int l = x.second - 1; l <= x.second + 1; l++) {
					if (k >= 0 && k < h && l >= 0 && l < w &&
						(k + l + x.first + x.second) % 2 == 1 && a[k][l] == '.') {
						s.insert({ k,l });
					}

				}
			}
		}
		if (!s.empty()) {
			ans++;
			for (auto const& x : s)
				a[x.first][x.second] = '#';
		}
		p = move(s);
	}
	cout << ans << '\n';

	return 0;
}


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

#define int long long
signed main(){
    int n, m;
    cin >>n >>m;
    int n0, m0,r;
    if(m>n) {
        n0 =m;m0 =n;
    }else{
        n0 =n;m0 =m;
    }
    while(m0 !=0){
        r = n0%m0;
        n0 = m0;
        m0 =r;
    }
    int l =(n*m)/n0;
    int p0 = l/m;
    int q0 =l/n;
    
    int u =(m*n)/l;
    int j =0;
    string p,q;
    cin >> p >>q;
    for(int i =0;i <u;i++){
        if(p[i*p0]!=q[i*q0]){
            j =-1;
            break;
        }

    }
    if(j==-1){
        cout << -1 ;
    }else{
        cout << l;
    }
   
    
    return 0;
    
}

Measured memory_bytes: 512
N = int(input())
A = [int(_) for _ in input().split()]

evens = []
fours = []
for n in range(N):
    if A[n] % 4 == 0:
        fours.append(A[n])
    elif A[n] % 2 == 0 and A[n] % 4 != 0:
        evens.append(A[n])
total = len(evens) // 2 + len(fours)
if total >= N // 2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
import collections

num = int(input())
original = list(map(int, input().split()))
trial_num = int(input())

total = sum(original)
# now_list = original
count_dict = collections.Counter(original)

for i in range(trial_num):
    b, c = list(map(int, input().split()))
    total += (c - b) * count_dict[b]
    print(total)
    
    if c in count_dict.keys():
        count_dict[c] += count_dict[b]
    else:
        count_dict[c] = count_dict[b]
    count_dict[b] = 0

Measured memory_bytes: 24112
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
      String po=sc.next();
      String po2=po.substring(0,n/2);
      String po3=po.substring(n/2);
        System.out.println((po2.equals(po3))?"Yes":"No");
    }
}


Measured memory_bytes: 21844
#include <stdio.h>


int main() 
{
	long long n, ans, t;
		
	scanf("%lld", &n);
	if(n & 1){
		puts("0");
		return 0;
	}
	ans = t = n / 10;
	while(t /= 5) ans += t;
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <map>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;

int main()
{
	string s;
	cin >> s;
	string ans;
	rep(i, s.size())
	{
		if (s[i] == '0') ans.push_back('0');
		else if (s[i] == '1')ans.push_back('1');
		else if (ans.size() != 0) ans.pop_back();
	}
	co(ans);
	return 0;
}


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

void split(const string str,vector<string>&in){
	in.push_back("");
	int index=0;
	for(int i=0;i<str.length();i++){
		if(str[i]==' '){
			in.push_back("");
			index++;
		}else  in[index]+=str[i];
	}
}

int main(){
	int a,b;
	stack<int> st;
	vector<string> in;
	string str;
	getline(cin,str);
	split(str,in);
	for(int i=0;i<in.size();i++){
		if(in[i][0]=='+'){
			a=st.top();
			st.pop();
			b=st.top();
			st.pop();
			st.push(a+b);
		}else if(in[i][0]=='*'){
			a=st.top();
			st.pop();
			b=st.top();
			st.pop();
			st.push(a*b);
		}else if(in[i][0]=='-'){
			a=st.top();
			st.pop();
			b=st.top();
			st.pop();
			st.push(b-a);
		}else  st.push(atoi(in[i].c_str()));
	}
	cout<<st.top()<<endl;
	return 0;
}


Measured memory_bytes: 3172
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)

	grid := make([][]int, n)
	for i := 0; i < n; i++ {
		grid[i] = make([]int, 0)
	}

	for i := 0; i < n; i++ {
		s := getNextString(scanner)
		for j := 0; j < n; j++ {
			if s[j] == '0' {
				continue
			}
			grid[i] = append(grid[i], j)
		}
	}

	sol := Solver{}

	sol.n = n
	sol.grid = grid

	var ans int
	ans = -1

	for i := 0; i < n; i++ {
		sol.color = make([]int, n)
		sol.bfs(i)
		max := -1
		for j := 0; j < n; j++ {
			if sol.color[j] == -1 {
				max = -1
				break
			}
			if max < sol.color[j] {
				max = sol.color[j]
			}
		}
		if ans < max {
			ans = max
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

type Solver struct {
	n     int
	grid  [][]int
	color []int
}

func (sol *Solver) bfs(i int) {
	q := make([]int, 0)
	q = append(q, i)

	sol.color[i] = 1
	for len(q) > 0 {
		p := q[0]
		q = q[1:]
		for _, to := range sol.grid[p] {
			if sol.color[to] != 0 {
				if sol.color[to]%2 == sol.color[p]%2 {
					sol.color[to] = -1
					return
				}
				continue
			}

			sol.color[to] = sol.color[p] + 1
			q = append(q, to)
		}
	}
}


Measured memory_bytes: 2688
#include <stdio.h>
#include <string.h>
char sig[3]={'-','+','*'};
void swap(int *x,int *y){int z=*x;*x=*y;*y=z;}
int calc(int x,int y,int c){
	switch(c){
	case 0:return x-y;
	case 1:return x+y;
	case 2:return x*y;
	}
}
int check(int v,int w,int x,int y){
	int i,j,k,r;
	int a=v,b=w,c=x,d=y;
	for(r=0;r<4;r++){
		for(i=0;i<3;i++){
			for(j=0;j<3;j++){
				for(k=0;k<3;k++){
					if(calc(calc(a,b,i),calc(c,d,j),k)==10){
						printf("((%d %c %d) %c (%d %c %d))\n",a,sig[i],b,sig[k],c,sig[j],d);return 1;}
					if(calc(calc(calc(a,b,i),c,j),d,k)==10){
						printf("(((%d %c %d) %c %d) %c %d)\n",a,sig[i],b,sig[j],c,sig[k],d);return 1;}
				}
			}
		}
		if(r%2==0)swap(&a,&b);else if(r==1)swap(&c,&d);
	}
	return 0;
}
int main(void){
	int a,b,c,d;
	while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF){
		if(a==0 && b==0 && c==0 && d==0)break;
		if(check(a,b,c,d))continue;
		if(check(a,c,b,d))continue;
		if(check(a,d,c,b))continue;
		if(check(c,d,a,b))continue;
		if(check(b,d,a,c))continue;
		if(check(b,c,a,d))continue;
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    int alice=0, bob=0;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for(int i=1; i<=n; i++){
        if(i%2 == 1) alice += a[i-1];
        else        bob += a[i-1];
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
/*  ex9_1
    Graku   */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 100

typedef struct stack {
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

void initialize_stack(stack *stk);
char pop(stack *stk);
void push(stack *stk, char c);
void print_stack(stack *stk);

int main(void) {
    stack stk;
    initialize_stack(&stk);

    char s[SIZE];
    scanf("%s", s);

    for (int i = 0; i < (int)strlen(s); ++i) {
        if (s[i] == 'B') { //delete a element
            if (stk.count > 0) { //stk has elements
                pop(&stk);
            }
        }
        else {
            push(&stk, s[i]); //add a element to stk
        }
    }

    print_stack(&stk);

    return 0;
}

void initialize_stack(stack *stk) {
    stk->size = SIZE;
    stk->count = 0;
    stk->top = stk->data; //stk.data[0] is always empty
}

char pop(stack *stk) {
    char c;
    if (stk->count <= 0) { //stk has no elements
        printf("Error: stack underflow.\n");
        exit(1);
    }
    c = *(stk->top);
    stk->top--;
    stk->count--;
    return c;
}

void push(stack *stk, char c) {
    if (stk->count >= stk->size) { //stk has biggest elements it can have
        printf("Error: stack overflow.\n");
        exit(1);
    }
    *(++stk->top) = c;
    stk->count++;
}

void print_stack(stack *stk) {
    char *p = stk->data;
    for (int i = 0; i < stk->count; ++i) {
        printf("%c", p[i+1]); //stk.data[0] is always empty
    }
    printf("\n");
}

Measured memory_bytes: 1612
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#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 pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;
static const long long LINF = (long long)(1e18+99);
static const int INF = 1000000099;

ll n, a[10005], b[10005];
int main(void) {
  cin >> n;
  
  ll suma = 0, sumb = 0;
  rep(i, 0, n) {cin >> a[i]; suma += a[i];}
  rep(i, 0, n) {cin >> b[i]; sumb += b[i];}
  
  ll t = sumb - suma;
  
  if (t<0) {
    puts("No");
    return 0;
  }
  
  ll ax = 0, bx = 0;
  rep (i, 0, n) {
    ll d = b[i] - a[i];
    if (d<0) {
      bx += d*-1;
    } else {
      if (d%2!=0) {
        ax += d + 1;
        bx++;
      } else {
        ax += d;
      }
      
    }
    //printf("ax %lld, bx %lld\n", ax, bx);
  }
  
  ll at = t*2 - ax;
  ll bt = t - bx;
  
  if (at>=0 && bt>=0 && at==bt) puts("Yes");
  else puts("No");
  
    //cout << ans << endl;
    return 0;
}


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

int main()
{
    int n;
    bool *is_prime = new bool[55600];
    std::vector<int> prime_table;
    std::fill(is_prime, is_prime + 55600, true);
    scanf("%d", &n);
    for (int i = 2; i < 55600; i++)
    {
        if (!is_prime[i]) continue;
        if (i % 5 == 1) prime_table.push_back(i);
        if (prime_table.size() == n) break;
        for (int j = 2 * i; j < 55600; j += i)
        {
            is_prime[j] = false;
        }
    }
    for (auto &e : prime_table)
        printf("%d\n", e);

    delete[] is_prime;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int A, B, C,i,j,k,flag,X;
	flag = 0;
	cin >> A >> B >> C >> X;
	for (i = 0;i <= A;i++) {
		for (j = 0;j <= B;j++) {
			for (k = 0;k <= C;k++) {
				if (500*i + 100*j + 50*k == X) {
					flag++;
				}
			}
		}
    }
	cout << flag << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int a, b;
    cin >> a >> b;

    cout << a * (a - 1) / 2 + b * (b - 1) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>


int main() {
	int n; std::cin >> n;
	std::vector<long long int> series(3 * n);
	for (auto& s : series) std::cin >> s;
	std::priority_queue<int, std::vector<int>, std::greater<>> small;
	std::vector<long long int> forward(n + 1);
	long long int sum{ 0 };
	for (auto i = 0; i < n; ++i) {
		sum += series[i];
		small.push(series[i]);
	}
	for (auto i = 0; i <= n; ++i) {
		forward[i] = sum;
		sum += series[i + n];
		small.push(series[i + n]);
		sum -= small.top(); small.pop();
	}
	std::vector<long long int> backward(n + 1);
	sum = 0;
	std::priority_queue<int> great;
	for (auto i = 0; i < n; ++i) {
		sum += series[series.size() - i - 1];
		great.push(series[series.size() - i - 1]);
	}
	for (auto i = 0; i <= n; ++i) {
		backward[i] = sum;
		sum += series[series.size() - i - n - 1];
		great.push(series[series.size() - i - n - 1]);
		sum -= great.top(); great.pop();
	}
	std::reverse(backward.begin(), backward.end());
	long long int result = LLONG_MIN;
	for (auto i = 0; i <= n; ++i) {
		result = std::max(result, forward[i] - backward[i]);
	}
	std::cout << result << std::endl;

}

Measured memory_bytes: 8216
#include <stdio.h>

int main(){
	int i,n;
	for (i = 0; i < 9; ++i)
	{
		for (n= 0; n < 9; ++n)
		{
			printf("%dx%d=%d\n",i+1,n+1,(i+1)*(n+1) );
		}
	}
	return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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



void solve() {
	double W,H; cin >> W >> H;
    int x, y; cin >> x >> y;
    double res=0; int flg = 0;

    res = W*H/2;
    if(W/2 == x && H/2 == y) flg = 1;

    cout << res << " " << flg << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
var n;
var c = [];
var u = [];
var f = [];

function dist(i, j){
	var s = 0;
	rep(3, function(k){
		var d = c[i][k] - c[j][k];
		s += d * d;	
	});
	s = Math.sqrt(s);
	return Math.max(s - c[i][3] - c[j][3], 0);
}

function main(){
	while(n = scan()){
		rep(n, function(i){
			c[i] = [scan(), scan(), scan(), scan()];
		});

		rep(n, function(i){
			f[i] = Infinity;
		});

		var ans = 0;
		f[0] = 0;
		rep(n, function(){
			var v = -1;
			rep(n, function(i){
				if(!u[i] && (v === -1 || f[i] < f[v])){
					v = i;
				}
			});
			ans += f[v];
			u[v] = true;
			rep(n, function(i){
				f[i] = Math.min(dist(v, i), f[i]);
			});
		});

		ans = Math.round(ans * 1000);
		var ans1 = Math.floor(ans / 1000);
		var ans2 = ans % 1000;
		print(ans1 + '.' + ('00' + ans2).slice(-3));

		u = [];
	}
}

function rep(a, b, c, u){
	if(c === u){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		if(c(i) === false){
			break;
		}
	}
}

var input = '';

function scan(){
	return +input.pop();
}
function scan_string(){
	return input.pop();
} 
function print(val){
	console.log(val);
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.trim().split(/\s+/).reverse();
	main();
});

Measured memory_bytes: 20476
#include <iostream>
#include  <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int sum = 0, j = 0, count = 0;
    while(sum <= x){
        sum += l[j];
        j++;
        count++;
        if(j == n+1) break;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main(void) {

    int N; cin>>N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin>>A[i];
    }
    ll ans = 0;

    vector<ll> L(N+2,0);
    vector<ll> R(N+2,0);

    for (int i = 0; i < N; ++i) {
        L[i+1] = __gcd(L[i],A[i]);
        R[N-i] = __gcd(R[N-i+1],A[N-i-1]);
    }

    for (int i = 0; i < N; ++i) {
        ans = max(__gcd(L[i], R[i+2]), ans);
    }



    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef priority_queue<string, vector<string>, greater<string> > QUE_string;
typedef priority_queue<double, vector<double>, greater<double> > QUE_double;
typedef priority_queue<char, vector<char>, greater<char> > QUE_char;

int main(){
  
  
  ll N;
  cin >> N;
  vector<string> vec_s;
  string s;
  map<string, int> mp;//辞書型みたいな型らしい
  
  for(int i=0; i<N; i++){
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;//map型は０に初期化されているらしい．
  }
  
  ll ans = 0;
  //cout << "mp.size(): " << mp.size() << endl;//2と表示される
  //cout << "mp.at(0).size(): " << mp.at(0).size() << endl;//こんな書き方はない!!エラーでた
  //cout << "mp.first.size(): " << mp.first.size() << endl;//エラー出た
  
  for(auto& p : mp){
    int s = p.second;
    ans += (ll) s*(s-1)/2;// sC2 (Cはcombinationね)
  }
  cout << ans << endl;

  
  
  
  
  
  //char c;
  //priority_queue<string, vector<string>, greater<string> > que;
  //QUE_char que;
  
  /*int ans = 0;
  for(int i=0; i<N; i++){
    cin >> s;
    sort(s.begin(), s.end());
    for(int j=0; j<i; j++){
      if(vec_s.at(j) == s) ans++;
    }
    vec_s.emplace_back(s);
  }
  //for(int i=0; i<N; i++) cout << vec_s.at(i) << " " << endl;
  */
  
  
  /*int ans=0;
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){//計算量は-1+(N-2)+(N-3)+...+1= (N-1)N/2なので,10^8を越えてしまいTLEになる
      if(vec_s.at(i) == vec_s.at(j)) ans++;
    }
  }
  */
  //cout << ans << endl;

}



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

using namespace std;


int main()
{
    long N;
    long now, next, r;

    cin >> N;
    cin >> now;
    for (int i = 0; i < N; i++) {
        cin >> next;
        
        if (now > next) {
        } else {
            long tmp;
            tmp = now;
            now = next;
            next = tmp;
        }

        while (true) { 
            r = now % next;
            if (r == 0) {
                now = next;
                break;
            }
            now = next % r;
            if (now == 0) {
                now = r;
                break;
            }
            //update
            next = now;
            now = r;
        }
        
    }
    
    cout << now << endl;
     
    return 0;   
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int k,n;
  scanf("%d%d",&k,&n);
  int i;
  i = 0;
  int max;
  max = 0;
  int a[n];
  while (i < n)
  {
    scanf("%d", &a[i]);
    if (i > 0 && max < a[i] - a[i - 1])
    {
      max = a[i] - a[i - 1];
    }
    i++;
  }
  if (max < a[0] + k - a[n - 1])
  {
    max = a[0] + k - a[n - 1];
  }
  printf("%d",k-max);
}

Measured memory_bytes: 896
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

   

    
N, M = map(int,input().split())
bridge = []
for i in range(M):
    A, B = map(int,input().split())
    bridge.append((A - 1, B - 1))
    
uf = UnionFind(N)
ans = [N * (N - 1) // 2]
cnt = 0
for i in range(M - 1):
    A, B = bridge[-i-1]
    if not uf.same(A, B):
        cnt += uf.size(A) * uf.size(B)
        uf.union(A, B)
    ans.append(ans[0] - cnt)
for i in range(M):
    print(ans[-i-1])

Measured memory_bytes: 22536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n;

	cin>>n;
	ll ans=0,cnt[3]={};
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s[0]=='B'){
			if(s[s.size()-1]=='A')cnt[0]++;
			else cnt[2]++;
		}else if(s[s.size()-1]=='A')cnt[1]++;
		for(int j=0;j<s.size();j++){
			if(j){
				if(s[j-1]=='A'&&s[j]=='B')ans++;
			}
		}
	}
	//cout<<ans<<endl;
	if(cnt[1]&&cnt[2]){
		ans+=cnt[0]+1;
		cnt[1]--;
		cnt[2]--;
		ans+=min(cnt[1],cnt[2]);
	}else if(cnt[1]==0&&cnt[2]==0)ans+=max(0ll,cnt[0]-1);
	else ans+=cnt[0];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int x,a,b;
	cin>>x>>a>>b;
	cout<<(x-a)%b;
	return 0;
}

Measured memory_bytes: 256
fun visit(node: Int, visited: Array<Boolean>, edges: Array<MutableList<Int>>) {
    if (visited[node]) return
    visited[node] = true
    edges[node].forEach { x -> visit(x, visited, edges) }
}

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val edges = Array(N){mutableListOf<Int>()}
    for (i in 0..M-1){
        val (x, y, z) = readLine()!!.split(" ").map(String::toInt)
        edges[x - 1].add(y - 1)
        edges[y - 1].add(x - 1)
    }

    var cnt = 0
    val visited = Array(N) { false }
    for (i in 0..N-1) {
        if (!visited[i]) {
            visit(i, visited, edges)
            cnt++
        }
    }
    println(cnt)
}

Measured memory_bytes: 88992
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 305;
int a[maxn][maxn];
int cnt[maxn];
bool del[maxn];

int main() {
    #ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
    #else
    #endif
    int n, m;
    cin >> n >> m;
    forn (i, n) {
        forn (j, m) {
            cin >> a[i][j];
            --a[i][j];
        }
    }
    int res = n;
    forn (iter, m) {
        forn (i, m)
            cnt[i] = 0;
        forn (i, n) {
            int j = 0;
            while (del[a[i][j]])
                ++j;
            cnt[a[i][j]]++;
        }
        int mx = -1, who = -1;
        forn (i, m) {
            if (cnt[i] > mx) {
                mx = cnt[i], who = i;
            }
        }
        res = min(res, mx);
        cerr << "del " << who + 1 << endl;
        del[who] = true;
    }
    cout << res << endl;
}


Measured memory_bytes: 640
N = int(input())
d = dict()
for a in map(int,input().split()):
  if a-1 in d:
    d[a-1] += 1
  else:
    d[a-1] = 1
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
  if a+1 in d:
    d[a+1] += 1
  else:
    d[a+1] = 1
print(max(d.values()))

Measured memory_bytes: 22316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);
//cout<<fixed<<setprecision(20);

vector<vector<map<ll,ll>>> dp(310,vector<map<ll,ll>>(310));

signed main(){
    ll n,k;cin>>n>>k;
    vector<ll> h(n);rep(i,0,n)cin>>h[i];
    dp[0][0][0]=0;

    rep(i,0,n){
        rep(j,0,k+1){
            for(auto itr=dp[i][j].begin();itr!=dp[i][j].end();itr++){
                ll add=max(h[i]-(*itr).fs,0ll);

                if(!dp[i+1][j+1].count((*itr).fs))dp[i+1][j+1][(*itr).fs]=dp[i][j][(*itr).fs];
                else chmin(dp[i+1][j+1][(*itr).fs],dp[i][j][(*itr).fs]);
                
                if(!dp[i+1][j].count(h[i]))dp[i+1][j][h[i]]=dp[i][j][(*itr).fs]+add;
                else chmin(dp[i+1][j][h[i]],dp[i][j][(*itr).fs]+add);
            }
        }
    }

    ll ans=LINF;
    for(auto itr=dp[n][k].begin();itr!=dp[n][k].end();itr++){
        ans=min(ans,(*itr).sc);
    }
    cout<<ans<<endl;
}


//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,output_format?

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

int main() {

	int K, S;
	cin >> K >> S;

	int cnt = 0;
	rep(i, 0, K+1) {
		if (i <= S) {
			rep(j, 0, K+1) {
				if (j <= S-i) {
					if (S - i - j <= K)	cnt++;
				}
			}
		}
	}

	cout << cnt << endl;

	return 0;
}

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

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

    vector<pair<int, int> > vec;
    for(int i = 0;i < n;i++){
        int a;
        cin >> a;
        vec.push_back({a, i+1});
    }

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

    for(int i = 0;i < n;i++){
        cout << vec[i].second;
        if(i < n-1){
            cout << " ";
        }else{
            cout << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 1780
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
int main(void)
{
    // Your code here!
    int N;
    cin >> N;
    int cnt = 0;
    std::vector<long> S = {0};
    for (int i = 0; i < N; i++)
    {
        string tmp;
        cin >> tmp;
        long keta = 1;
        long sum = 0;
        for (int j = 0; j < tmp.size(); j++)
        {
            keta = pow(26, j);
            sum += (tmp[j] - ('a' - 1)) * keta;
        }

        //cout << sum << endl;
        auto it = lower_bound(S.begin(), S.end(), sum);
        if (*it != sum)
        {
            S.insert(it, sum);
            cnt++;
        }
    }
    cout << S.size() - 1 << endl;
}

Measured memory_bytes: 5876
/*
https://open.spotify.com/track/1nEjpWJlqcOsf2ZaRQ3XdW?si=gmXBzPYtTPy6Mi9iqI9hvA

In the particularly cold night
Perhaps you couldn’t sleep well
In the bright morning woken up from sleep
You are full of darkness
You, who were so worried for some reason that you
Hugged me tightly and asked for my love

You broke and ruined my everything
My daily life and even my people yeah
I resent you all day
But to leave you I oh I

Don’t worry babe
I love you babe
I’ll be by your side
Maybe

Maybe

Looks about to collapse but remains
And the cycle continues unsteadily
I’m about to give up but when I see you I Oh I

No babe
I love you babe
I’ll hold your hand
Maybe

Maybe
I’ll be by your side
Maybe
I’ll trust you

Stay with me, stay with me
So you won’t think of anything
I’ll stay here pretending to be reluctant
So hold me back
Maybe

Maybe
I will be by your side
Maybe
I’ll trust you

Maybe

*/
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define for1(i, a, b) for(i = a; i <= b; ++i)
#define for0(i, a, b) for(i = a; i < b; ++i)
#define forw1(i, a, b) for(i = a; i >= b; --i)
#define forw0(i, a, b) for(i = a - 1; i >= b; --i)
#define fora(v, a) for(auto v : a)
#define bp __builtin_popcount
#define bpll __builtin_popcountll

using namespace std;
using cd = complex<double>;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<cd> vcd;
typedef vector<ii> vii;
typedef vector<vector<int> > vvi;

const int modd1 = 1e9 + 7, modd2 = 998244353, maxn = 1e5+ 10, mxlog = 20, K = 26;
const double pi = acos(-1);
int n, q, l, nxt[mxlog][maxn];
vi x;

void solve(){
	int i, j, k, r;
	cin >> n ;
	for0(i, 0, n){
		int now; cin >> now; x.pb(now);
	}
	cin >> l;
	for0(i, 0, n){
		int val = upper_bound(x.begin(), x.end(), x[i] + l) - x.begin() - 1;
		nxt[0][i] = val;
	}
	for0(i, 1, 20){
		for0(j, 0, n){
			nxt[i][j] = nxt[i- 1][nxt[i - 1][j]];
		}
	}
	cin >> q;
	while(q--){
		int a, b; cin >> a >> b; a--; b--;
		if(a > b) swap(a, b);
		int ans = 0;
		forw0(i, mxlog, 0){
			if(nxt[i][a] < b){
				ans += (1 << i);
				a = nxt[i][a];
			}
		}
		cout << ans + 1 << '\n';
	}
}

signed main() {
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
}


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

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

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

int main() {
    ll n;
    cin >> n;
    ll ans = n*(n+1)*(n+2)/6;
    for (int i = 0; i < n - 1; ++i) {
        ll a, b;
        scanf("%lld %lld", &a, &b);
        if(a > b) swap(a, b);
        a--; b--;
        ans -= (a+1)*(n-b);
    }
    cout << ans << "\n";
    return 0;
}

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c)

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 100;
int a[maxn];

int main()
{
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for(int i = 2; i <= n ; i++)
  {
    int x;
    cin >> x;
    a[x]++;
  }
  for(int i = 1; i <= n ; i++)
  {
    cout << a[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4344
#include<stdio.h>
int main(){
	int n,a,b=1000000,c=-1000000,i;
	long int d=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%d",&a);
	if(b>a){
		b=a;
		}
	if(c<a){
		c=a;
		}
		d=a+d;
	}
	printf("%d %d %ld\n",b,c,d);
	return 0;
}


Measured memory_bytes: 2120
class BinHeap
  def initialize(n,buf=nil,max=nil)
    @size=n
    @buf=buf||[]
    @max=max||1
  end
  def add(n)
#    print :add_s,n
    a=@buf[i=@max]=n
    @max+=1
    while i>1 && a>b=@buf[i/2]
      @buf[i]=b
      i/=2
    end
    @buf[i]=a
#    print :add_e,n
  end
  def get
#    print :get_s
    ret=@buf[1]
    a=@buf[i=1]=@buf[l=@max-=1]
    while (c=i*2)<l
      c+=1 if c+1<l && @buf[c]<@buf[c+1]
      if a<b=@buf[c]
        @buf[i]=b
        i=c
      else
        break
      end
    end
    @buf[i]=a
#    print :get_e,ret
    ret
  end
  def dup
    BinHeap.new(@size,@buf.dup,@max)
  end
  def buf
    @buf
  end
  def print(*arg)
    p arg*" "
    i=s=1
    while i<@max
      p @buf[i,s]
      i+=s
      s*=2
    end
  end
end

pq=BinHeap.new(2000000)
while gets
  op,arg = $_.split
  case op
  when "insert"
    pq.add arg.to_i
  when "extract"
    p pq.get
  when "end"
  end
end

Measured memory_bytes: 14048
def resolve():
    S = input()
    K = int(input())
    N = len(S)

    # dp[i][j][smaller]
    # i桁目まで見たときに0以外の数字をｊ個使用し、条件を満たす個数
    # smaller:
    # 0:i桁目まで見たときに一致している(次の桁は余裕が無い)
    # 1:次の桁は余裕がある

    dp = [[[0]*2 for _ in range(4)] for _ in range(N+1)]
    dp[0][0][0] = 1

    for i in range(N):
        for j in range(4):
            for smaller in range(2):
                now = int(S[i])
                for d in range(10):
                    ni = i+1
                    nj = j
                    n_smaller = smaller
                    if d != 0:
                        nj += 1
                    if nj > K:
                        continue
                    if smaller == 0:
                        if d > now: # 値を超えている
                            continue
                        if d < now: # 次の桁は余裕がある
                            n_smaller = 1
                    dp[ni][nj][n_smaller] += dp[i][j][smaller]
    ans = dp[N][K][0] + dp[N][K][1]
    print(ans)


if __name__ == "__main__":
    resolve()


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    cout << *max_element(a.begin(), a.end()) -*min_element(a.begin(), a.end()) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
  		long[] a=new long[n];
  		long ans=1;
		for(int c=0;c<n;c++){
    		a[c]=sc.nextLong();
          	if(a[c]==0){
            	ans=0;
            }
    	}
  	if(ans!=0){
		for(int c=0;c<n;c++){
          if(a[c]<=(long)Math.pow(10,18)/ans){
            ans*=a[c];
          }else{
          	ans=-1;
            break;
          }
    	}
    }
    	System.out.println(ans);
    }
}

Measured memory_bytes: 61516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=100005,INF=1<<30;
vector<pair<int,int>> G[MAX];
int A[MAX];

void DFS(int u,int p){
    for(auto to:G[u]){
        if(to.fi==p) continue;
        
        A[to.fi]=to.se;
        DFS(to.fi,u);
        A[u]^=to.se;
    }
}

int dp[1<<16];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b,c;cin>>a>>b>>c;
        G[a].push_back(mp(b,c));
        G[b].push_back(mp(a,c));
    }
    
    DFS(0,-1);
    
    vector<int> cnt(16);
    
    for(int i=1;i<N;i++){
        cnt[A[i]]++;
    }
    int ans=0;
    
    for(int i=1;i<16;i++){
        ans+=cnt[i]/2;
        cnt[i]&=1;
    }
    
    for(int i=0;i<(1<<16);i++){
        dp[i]=INF;
    }
    int rem=1;
    for(int i=1;i<16;i++){
        if(!cnt[i]){
            rem^=(1<<i);
        }
    }
    
    dp[rem]=0;
    
    for(int bit=0;bit<(1<<16);bit++){
        if(dp[bit]==INF) continue;
        int S=(1<<16)-1-bit;
        for(int mask=S;;mask=(mask-1)&S){
            if(mask==0) break;
            int sum=0;
            for(int i=0;i<16;i++){
                if(mask&(1<<i)) sum^=i;
            }
            if(sum==0) chmin(dp[bit^mask],dp[bit]+__builtin_popcount(mask)-1);
            else chmin(dp[bit^mask],dp[bit]+__builtin_popcount(mask));
        }
    }
    
    cout<<ans+dp[(1<<16)-1]<<endl;
}




Measured memory_bytes: 12288
#include <iostream>
#include <cmath>

using namespace std;

int get2(int n){

    int count = 0;

    while (n > 0){
        if (n % 2 == 1){
            break;
        }else{
            count ++;
            n /= 2;
        }
    }

    return count;
}

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

    int ans = 0;

    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        ans += get2(a);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256