akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#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++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

int N, K;
vector<vector<int>> tree;

void rec(int v, int p, int d, vector<int> &depth) {
    depth[v] = d;
    for(auto u : tree[v]) {
        if(u == p) continue;
        rec(u, v, d + 1, depth);
    }
}

void solve() {
    cin >> N >> K;
    tree.assign(N, vector<int>());
    rep(i, N - 1) {
        int a, b; cin >> a >> b; a --; b --;
        tree[a].push_back(b); tree[b].push_back(a);
    }
    vector<int> depth(N);
    int ans = N;
    if(K % 2 == 0) {
        rep(v, N) {
            rec(v, -1, 0, depth);
            int cnt = 0;
            rep(u, N) {
                if(depth[u] > K / 2) cnt ++;
            }
            ans = min(ans, cnt);
        }
    } else {
        rep(v, N) {
            for(auto u : tree[v]) {
                rec(u, v, 0, depth); rec(v, u, 0, depth);
                int cnt = 0;
                rep(w, N) {
                    if(depth[w] > K / 2) cnt ++;
                }
                ans = min(ans, cnt);
            }
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

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

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

    int cnt = 0;
    bool flag = true;
    for(int i = 0; i < n; i++){
        int num;
        cin >> num;
        if(num % 2 == 1){
            cnt = 0;
            break;
        }
        else{
            if(flag){
                while(true){
                    if(num % 2 == 1){
                        break;
                    }
                    num /= 2;
                    cnt++;
                }
                flag = false;
            }
            else{
                int tmp = 0;
                while(true){
                    if(num % 2 == 1){
                        break;
                    }
                    num /= 2;
                    tmp++;
                }
                if(tmp < cnt){
                    cnt = tmp;
                }
            }
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
Int const INF = 1e10;

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

    int n; cin>>n; Int a[n];
    for (int i = 0; i < n; i++) cin>>a[i];
    for (int i = 1; i < n; i++) a[i]+=a[i-1];
    Int ans=INF;
    for (int i = 0; i < n-1; i++){
        ans=min(abs(a[i]-(a[n-1]-a[i])),ans);
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 1792
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> a(m);
	rep(i, n) {
		int p, q;
		cin >> p >> q;
		if (p <= m) a[p - 1].push_back(q);
	}
	priority_queue<int> que;
	int ans = 0;
	rep(i, m) {
		for (auto p : a[i]) que.push(p);
		if (!que.empty()) {
			ans += que.top();
			que.pop();
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll d[100005],mod=1e9+7;
map<ll,ll> p;
int main(){
	ll n,m,x;
	cin>>n>>m;
	for(ll i=1;i<=m;i++){
		cin>>x;
		p[x]=1;
	}
	d[0]=1;
	if(p[1]==1) d[1]=0;
	else d[1]=1;
	for(ll i=2;i<=n;i++){
		if(p[i]==1) continue;
		d[i]=(d[i-1]%mod+d[i-2]%mod)%mod;
	}
	cout<<d[n]%mod<<endl;
}

Measured memory_bytes: 7296
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
using namespace std;
int main(){
  string rgb;
  rep(i,0,3){
    string a;
    cin>>a;
    rgb+=a;
  }
  if(stoi(rgb)%4==0)ou("YES");
  else ou("NO");
}

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

int main() {
  int D, E;
  while (cin >> D >> E) {
	if (D == 0) break;
	double res = 1LL<<29;
	for (int i = 0; i <= D; ++i) {
	  double tmp = abs(sqrt(i*i + (D-i)*(D-i)) - E);
	  res = min(res, tmp);
	}
	cout << fixed << setprecision(10) << res << endl;
  }
}



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

int main() {
    long long h;
    cin >> h;
    long long ans, s;
    ans = 0;
    s = 1;
    while (h) {
      h /= 2;
      ans += s;
      s *= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ctime>
#include <sstream>
#define weewoo ios::sync_with_stdio(false);cin.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define ll long long
#define se second
#define fi first
#define ctoi(x) (x-'0')
#define pi (acos(-1))
#define llputin(a,n) for(int i=0;i<n;i++){ll x;cin >> x;a.push_back(x);}
#define iputin(a,n) for(int i=0;i<n;i++){int x;cin >> x;a.push_back(x);}

#define MOD ((ll) 1e9 + (ll) 7)
using namespace std;

ll pw(ll x,ll a){
    if(a==0)
        return 1;
    ll t = pw(x,a/2);
    if(a%2==0)
        return(t*t);
    else
        return(t*t*x);
}

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

bool cmp(const pair<int , int> &a , const pair<int , int> &b){
    return (a.first < b.first);
}

ll lcm(ll a,ll b){
    return ( a*b/__gcd(a,b));
}



int main()
{
    weewoo;
    ll n;
    cin >> n;
    ll ans = 1e18;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ans = min(ans,abs(1-i)+abs(1-n/i));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1000000007;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

int main(void){
    int a,b;
    cin>>a>>b;
    if(a<=8 && b<=8) puts("Yay!");
    else puts(":(");
    return 0;
}

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

int top, s[1000];

int pop(){
	top--;
	return s[top+1];
}

void push(int x){
	s[++top] = x;
}

int main(){
	int a,b;
	top = -1;
	char c[100];
	while(scanf("%s", c) != EOF){
		if(c[0] == '+'){
			a = pop();
			b = pop();
			push(b+a);
		} else if(c[0] == '-'){
			a = pop();
			b = pop();
			push(b-a);
		} else if(c[0] == '*'){
			a = pop();
			b = pop();
			push(b*a);
		} else{
			push(atoi(c));
		}
	}
	printf("%d\n", pop());
	return 0;
}

Measured memory_bytes: 548
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    long n, a, b;
    cin >> n >> a >> b;
    long d = b-a;
    long ans = 0;
    if (d % 2 == 0){
        ans = d/2;
        cout << ans << endl;
    }
    else if (d == 1){
        if (b-1 > n-a){
            ans = n-a;
            cout << ans << endl;
        }
        else{
            ans = b-1;
            cout << ans << endl;
        }
    }
    else{
        if (a-1 > n-b){
            ans = n - b + 1 + (d-1)/2;
            cout << ans << endl;
        }
        else{
            ans = a + (d-1)/2;
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
    
    
int main(){
     
    char a,b,c;
  cin>>a>>b>>c;
  
  if ((a==b)&&(b==c))
  {
    cout<<"No"<<endl;
  }
  else
  {
    cout<<"Yes"<<endl;
  }
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (n-1)/m  + 1 ;
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const int  N = 1e5 + 5;
int a[N] , b[N] , c[N];

signed main(){
	int n;
	cin>>n ;
	f(n) cin>>a[i] ;
	f(n) cin>>b[i] ;
	f(n) cin>>c[i] ;
	sort( a+1 ,a+n+1) ;
	sort( b+1,b+n+1) ;
	sort( c+1 , c+n+1) ;
	int s = 0 ;
	f(n) {
		int idx = lower_bound(a+1 ,a+1 +n , b[i]) - a -1;
		int p  = upper_bound( c+1 , c+1+n , b[i] ) - c ;
		p = n - p+1 ;
		s+= idx*p ;
	}
	cout << s; 
}


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

int main() {
    char s[100010];
    cin >> s;

    for (int i = 0; s[i]!='\0'; i++)
    {
        if(i%2==0) cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <math.h>
#include <numeric>
using namespace std;
typedef long long ll;


int main(void){
    
    ll n;
    cin >> n;
    
    ll p[n];
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    ll count=0, number=0;
    
    for(int i=0; i< n-2; i++){
        if(p[i] <= p[i+1]){
            if(p[i+1] <= p[i+2]){
                count=1;
            }
        }
        
        else if(p[i+2]<=p[i+1]){
            if(p[i+1] <= p[i]){
                count = 1;
            }
        }
        
        if(count ==1){
            number += 1;
        }
        
        count = 0;
    }
    cout << number << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 1e5 + 1;
int n, dp[N][3];

int main(int argc, char** argv)
{
#ifdef LOCAL
  freopen(strcat(argv[0], ".in"), "ab+", stdin);
#endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
   
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;

    dp[i][0] = i ? max(dp[i - 1][1], dp[i - 1][2]) + a : a;
    dp[i][1] = i ? max(dp[i - 1][0], dp[i - 1][2]) + b : b;
    dp[i][2] = i ? max(dp[i - 1][0], dp[i - 1][1]) + c : c;
  }

  cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
  
  return 0;
}


Measured memory_bytes: 1408
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
 
#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 pb push_back
#define pp pop_back
#define F first
#define S second
#define endl "\n"
#define ll long long                                           
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define pss pair<string, string>
#define pll pair<long long, long long> 

//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void INeedIT() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

pll p[123456];

int main () {
	INeedIT();
	int n, m;
	ll ans=0;
	cin>>n>>m;
	for (int i=1;i<=n;i++) {
		ll a, b;
		cin>>a>>b;
		p[i]={a, b};
	}
	sort(p+1, p+n+1);
	for (int i=1;i<=n;i++) {
		if (m==0) {
			break;
		}
		ans+=min((ll)m, p[i].S) * p[i].F;
		m=max((int)0, m-(int)p[i].S);
	}
	cout<<ans;
	return 0;
}	

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private CommonInput cin;

        private void Process()
        {
            this.cin = new CommonInput();

            int a, d, n, count, current;

            bool[] array = new bool[1000001];

            array[0] = array[1] = true;

            for (int i = 2; i <= 1000; i++)
            {
                for (int j = 2; i * j <= 1000000; j++)
                {
                    if (!array[i * j])
                        array[i * j] = true;
                }
            }

            while (true)
            {
                a = cin.GetInt();
                d = cin.GetInt();
                n = cin.GetInt();

                if (a == 0 && d == 0 && n == 0)
                    break;

                count = 0;
                current = 0;

                for (int i = 0; a + d * i < 1000000 && count < n; i++)
                {
                    if (!array[a + d * i])
                    {
                        count++;
                        current = i;
                    }
                }

                Console.WriteLine(a + d * current);
            }
        }
    }

    public class CommonInput
    {
        public CommonInput()
        {
            this._s = new string[0];
            this._i = 0;
        }

        private string[] _s;
        private int _i;
        private char[] _sep = { ' ', ',' };

        public string GetLine()
        {
            if (this._i < this._s.Length)
                return this._s[this._i++];

            string line;
            this._i = 0;
            do
            {
                line = Console.ReadLine();
            } while (line == "");

            this._s = line.Split(this._sep, StringSplitOptions.RemoveEmptyEntries);

            return this._s[this._i++];
        }

        public int GetInt()
        {
            return int.Parse(this.GetLine());
        }

        public long GetLong()
        {
            return long.Parse(this.GetLine());
        }

        public double GetDouble()
        {
            return double.Parse(this.GetLine());
        }
    }
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) auto varfin=freopen(name, "r", stdin);varfin=varfin
#define fout(name) auto varfout=freopen(name, "w", stdout);varfout=varfout
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

ll n, k, cnt[2];

int main() {
//    fin("t.in");
    sync;
    cin >> n >> k;
    cnt[0] = cnt[1] = 0;
    cnt[0] = n / k;
    if (k % 2 == 0)
    	cnt[1] = n / (k / 2) - n / k;
    cout << cnt[0] * cnt[0] * cnt[0] + cnt[1] * cnt[1] * cnt[1] << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools
import math

n=int(input())
townRoot=list(itertools.permutations([i for i in range(1,n+1)]))
townList=[]
for i in range(n):
    townList.append(tuple([int(i) for i in input().split()]))
sumLenght=0
length=0
for root in townRoot:
    for xy in range(n-1):
        town1=root[xy] -1
        town2=root[xy+1] -1
        length += math.sqrt((townList[town1][0] - townList[town2][0])**2 \
                + (townList[town1][1] - townList[town2][1])**2)
    sumLenght += length
    length = 0
print(sumLenght/len(townRoot))



Measured memory_bytes: 7972
n = int(input())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))

b = sorted(a, key = lambda x: (x[0], x[1]))
c = sorted(a, key = lambda x: (x[1], x[0]))

ans = 10**10
for i in range(n-1):
    temp = (b[i+1][0]-b[i][0])**2 + (b[i+1][1]-b[i][1])**2 
    if ans > temp:
        ans = temp
for i in range(n-1):
    temp = (c[i+1][0]-c[i][0])**2 + (c[i+1][1]-c[i][1])**2 
    if ans > temp:
        ans = temp
    
print(ans)


Measured memory_bytes: 139668
//============================================================================
// Name        : Hello5.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <numeric>
#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;
	string s;
	cin>>n>>s;
	int ans=0;
	rep(i,n-2)
	if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
	{
		ans++;
	}
	cout<<ans<<endl;




  return 0;
}


Measured memory_bytes: 256
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, 1000005), 1000005)
	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
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt64(scanner)
	b := getNextInt64(scanner)
	c := getNextInt64(scanner)

	if c-(a+b) >= 0 {
		if 4*a*b < (c-(a+b))*(c-(a+b)) {
			fmt.Fprintln(writer, "Yes")
			return
		}
		fmt.Fprintln(writer, "No")
		return
	}
	fmt.Fprintln(writer, "No")
}


Measured memory_bytes: 640
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <ll MOD>
class Combination {
    ll N;
    V<ll> factv, ifactv;

public:
    Combination<MOD>(ll N) : N(N), factv(N + 1, 1), ifactv(N + 1) {
        for(ll i = 1; i <= N; i++) factv[i] = factv[i - 1] * i % MOD;
        ifactv.back() = inv(factv.back());
        for(ll i = N - 1; 0 <= i; i--) ifactv[i] = (i + 1) * ifactv[i + 1] % MOD;
    }

    ll fact(ll n) { return factv[n]; }

    ll ifact(ll n) { return ifactv[n]; }

    ll pow(ll a, ll b) { return b ? (b & 1 ? a : 1) * pow(a * a % MOD, b / 2) % MOD : 1; }

    ll inv(ll a) { return pow(a, MOD - 2); }

    ll comb(ll n, ll k) { return factv[n] * ifactv[n - k] % MOD * ifactv[k] % MOD; }
};

const size_t SIZE = 1010;
const ll mod = 1e9 + 7;
ll dp[21][SIZE];
Combination<mod> C(SIZE);

int main() {
    dp[0][0] = 1;
    ll N, K;
    cin >> N >> K;
    V<ll> A(K);
    for (ll &e : A) cin >> e;
    for (ll idx = 0; idx < K; idx++) {
        for (ll i = 0; i <= N; i++) {
            ll rest = N - i;
            for (ll j = 0; j <= A[idx] && i + j <= N && j <= rest; j++) {
                ll dstr = A[idx] - j;
                (dp[idx + 1][i + j] += dp[idx][i] * C.comb(rest, j) % mod * C.comb(N - j, dstr) % mod) %= mod;
            }
        }
    }

    cout << dp[K][N] << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define ren(i,n) for(int i=n-1;i>=0;i--)
#define iter(it,v) for(auto it:v)
#define iterp(it,v) for(auto it=v.begin(),it!=v.end();it++)
#define itern(it,v) for(auto it=v.rbegin();it!=v.rend();it++)
#define w(n) while(n--)
#define forp(i,a,b) for(int i=a;i<=b;i++)
#define forn(i,a,b) for(int i=a;i>=b;i--)
#define sc(a) scanf("%d",&a)
#define pf(a) printf("%d",a)
#define init(a,r) for(auto&i:a) i=r;
#define inpt(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define inp(a) for(int&i:a) cin>>i;
#define diss(a) for(int i:a) cout<<i<<' ';
#define disn(a) for(int i:a) cout<<i<<'\n';
#define debug(a) cout<<#a<<": ";for(auto i:a)cout<<i<<" ";cout<<'\n';
#define mpii map<int,int>
#define sii set<int>
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define all(v) v.begin(),v.end()
#define bitc __builtin_popcount
#define fst ios::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define pq priority_queue
#define pii pair<int,int>
#define cs(a) cout<<a<<' '
#define cn(a) cout<<a<<'\n'
#define deb(a,b) cout<<a<<' '<<b<<endl;
#define yy "YES"
#define nn "NO"
#define ff first
#define ss second
typedef long long ll;
const int mod=1e9+7,mod1=998244353;
const int N=2e5+7;
int ar[N];
void a_b_l(){
    int n;
    cin>>n;
    int ar[n];
    inp(ar);
    int dp[n];
    init(dp,INT_MAX);
    dp[0]=0;
    dp[1]=abs(ar[1]-ar[0]);
    forp(i,2,n-1){
        dp[i]=min(dp[i-1]+(abs(ar[i]-ar[i-1])),dp[i-2]+(abs(ar[i]-ar[i-2])));
    }
    cn(dp[n-1]);
}
signed main(){
    fst;
    int t=1;
    //cin>>t;
    w(t)
    	a_b_l();
}

Measured memory_bytes: 1792
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    int r, c, k;
    cin >> r >> c >> k;

    vector<vector<ll>> v(r + 1, vector<ll>(c + 1, 0));
    for (int i = 0; i < k; i++) {
        int rk, ck, vk;
        cin >> rk >> ck >> vk;
        v[--rk][--ck] = vk;
    }

    vector<vector<vector<ll>>> dp(r+1, vector<vector<ll>>(c+1, vector<ll>(5, 0)));
    dp[0][0][1] = v[0][0];

    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            for (int l = 0; l < 4; l++) {
                // (i,j) -> (i,j+1)
                // dont pick
                dp[i][j + 1][l] = max(dp[i][j + 1][l], dp[i][j][l]);
                // pick
                dp[i][j + 1][l + 1] = max(dp[i][j + 1][l + 1], dp[i][j][l] + v[i][j + 1]);

                // (i,j) -> (i+1,j)
                // dont pick
                dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][l]);
                // pick
                dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][l] + v[i + 1][j]);
            }
        }
    }

    ll ans = 0;
    for (int l = 0; l < 4; l++) {
        ans = max(ans, dp[r - 1][c - 1][l]);
    }

    cout << ans << endl;
    return 0;
}

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

int main(){
    long long n, ans=99999999999999;
    cin >> n;
    for(long long i=1;i<=pow(n, 0.5);i++){
       if(n%i==0){
           ans = min(ans, i+(n/i)-2);
       }
    }

    cout << ans << endl;
    return 0;
 
}


Measured memory_bytes: 512
<?php
  list($a, $b) = explode(" ", trim(fgets(STDIN)));

  if($a == $b){
    echo $a;
    exit;
  }
  if($a % 2 == 0){
    if($b % 2 == 1){
      if(($b-$a+1)/2 % 2 == 0){
        echo "0";
      }else{
        echo "1";
      }
    }else{
      if(($b-$a)/2 % 2 == 0){
        echo 0 ^ $b;
      }else{
        echo 1 ^ $b;
      }
    }
  }else{
    if($b % 2 == 1){
      if(($b-$a)/2 % 2 == 0){
        echo 0 ^ $a;
      }else{
        echo 1 ^ $a;
      }
    }else{
      if(($b-$a-1)/2 % 2 == 0){
        echo 0 ^ $a ^ $b;
      }else{
        echo 1 ^ $a ^ $b;
      }
    }
  }

Measured memory_bytes: 16316
# 素数かどうか判定する
import math
def is_prime(n):
    if n ==1: return True
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

x = int(input())

while not is_prime(x):
    x += 1
print(x)

Measured memory_bytes: 2940
#include<stdio.h>
int main()
{
	int n,x,kane=100000;
	double kane2;
	scanf("%d",&n);
	for(x=0; x<n; x++)
	{
		kane=kane+kane*0.05;
		kane+=999;
		kane2=kane*0.001;
		kane=kane2;
		kane*=1000;
	}
	printf("%d\n",kane);
	return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    int now = 0;
    int cnt = 0;
    rep(i,n){
        if(a[i]==now+1)now++,cnt++;
    }
    if(now==0)cout<<-1<<endl;
    else cout<<n-cnt<<endl;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N,M;
	cin>>N>>M;
	vector<pair<int,int>> order(M);
	rep(i,M)cin>>order[i].first>>order[i].second;
	int ans = -1;
	int s = pow(10, N-1), e = pow(10, N)-1;
	if(s == 1)s = 0;
	for(; s<=e; ++s){
		bool ok = true;
		rep(i,M){
			int ind = order[i].first;
			int tar = (s/(int)pow(10,N-ind))%10;
			if(tar != order[i].second)ok = false;
		}
		if(ok){ans = s; break;}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n,m=gets.split(' ').map(&:to_i)
#h=gets.split(' ').map(&:to_i)
#tajigen = Array.new(4) { Array.new(2,0) }

flag = Array.new(n+1,0)
ac=0
wa=0
wa_array = Array.new(n+1,0)
for i in 0..m-1
  string = gets.split(' ')
  pro = string[0].to_i
  result = string[1].to_s

  if result == "AC"
    flag[pro]=1
    wa+=wa_array[pro]
    wa_array[pro]=0
  elsif result=="WA" && flag[pro] == 0
    wa_array[pro]+=1
  end


end

for i in 0..n
  if flag[i]==1
    ac+=1
  end
end

puts flag.count(1)
puts wa


Measured memory_bytes: 3324
#include <algorithm>
#include <cassert>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <vector>

struct Piece {
	int width;
	int height;

	Piece(int width, int height)
		: width(width), height(height)
	{
		assert(width > 0 && height > 0);
	}

	int area() { return width * height; }
};

int main()
{
	std::deque<Piece> pieces;

	while (true) {
		int num_cuts, width, height;
		std::cin >> num_cuts >> width >> height;

		if (width == 0) return 0;

		pieces.clear();
		pieces.push_back(Piece(width, height));

		for (int i = 0; i < num_cuts; i++) {
			int piece_num, cut_pos;
			std::cin >> piece_num >> cut_pos;

			auto pp = pieces.begin() + (piece_num - 1);
			Piece piece = *pp;
			pieces.erase(pp);

			// 1??±??????????????£???????????????????????§
			cut_pos %= (piece.width + piece.height) * 2;

			if (cut_pos > piece.width + piece.height && cut_pos <= piece.width * 2 + piece.height) {
				// ?????¨??\??????????????£???
				cut_pos = piece.width * 2 + piece.height - cut_pos;
			}
			else if (cut_pos > piece.width * 2 + piece.height) {
				cut_pos = piece.width * 3 + piece.height * 2 - cut_pos;
			}

			if (cut_pos <= piece.width) {
				// ????????????
				Piece p1(cut_pos, piece.height);
				Piece p2(piece.width - cut_pos, piece.height);

				if (cut_pos * 2 >= piece.width) {
					// ?????????????????§?????????
					pieces.push_back(p2);
					pieces.push_back(p1);
				}
				else {
					pieces.push_back(p1);
					pieces.push_back(p2);
				}
			}
			else {
				// ?¨??????????
				cut_pos -= piece.width;
				Piece p1(piece.width, cut_pos);
				Piece p2(piece.width, piece.height - cut_pos);

				if (cut_pos * 2 >= piece.height) {
					// ??????????????§??????
					pieces.push_back(p2);
					pieces.push_back(p1);
				}
				else {
					pieces.push_back(p1);
					pieces.push_back(p2);
				}
			}
		}

		std::sort(pieces.begin(), pieces.end(), [](Piece& x, Piece& y) { return x.area() < y.area(); });

		bool is_first = true;
		for (Piece& p : pieces) {
			if (is_first) {
				is_first = false;
			}
			else {
				std::cout << " ";
			}

			std::cout << p.area();
		}
		std::cout << std::endl;
	}
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long modPow(long long a, int p){
    if (p == 0) return 1;
    if (p%2 == 0) {
        long long half = modPow(a, p/2);
        return half * half % mod;
    }
    else return a * modPow(a, p-1) % mod;
}
long long cmb(int n, int r) {
    r = min(r, n-r);
    long long tmpM = 1, tmpD = 1;
    for (int i = 0; i<r; i++) {
        tmpM *= n-i;
        tmpD *= i+1;
        tmpM %= mod;
        tmpD %= mod;
    }
    return tmpM * modPow(tmpD, mod-2) % mod;
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int X, Y;
    cin >> X >> Y;
    long long ans = 0;
    if (X > Y) swap(X, Y);
    if ((2*X-Y)%3 == 0 && Y < 2*X) {
        ans = cmb((2*X-Y)*2/3+Y-X, (2*X-Y)/3);
    }
    if (Y == 2*X) ans = 1;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];

            var m = Math.Max(Math.Max(a, b), c);

            var sum = a + b + c;

            if(3 * m % 2 == sum % 2)
            {
                Console.WriteLine((3 * m - sum) / 2);
            }
            else
            {
                Console.WriteLine((3 * m + 3 - sum) / 2);
            }
        }
    }
}


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

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

    for (int i = 1; i <= n; i++)
    {
        int x = i;
        if (x % 3 == 0)
        {
            cout << " " << i;
            continue;
        }
        while (x)
        {
            if (x % 10 == 3)
            {
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }

    cout << endl;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
const int V = 100100;
vector<int> to[2*V];
bool seen[2*V];
vector<int> cnt(2);
void dfs(int v){
	if(seen[v]) return;
	if(v < V) cnt[0]++;
	else cnt[1]++;
	seen[v] = true;
	for(int u: to[v]){
		dfs(u);
	}
	return ;
}
int main()
{
	int n;
	cin >> n;
	rep(i,n){
		int x, y;
		cin >> x >> y;
		y += V;
		to[x].push_back(y);
		to[y].push_back(x);
	}
	ll ans = 0;
	rep(i,2*V){
		if(seen[i]) continue;
		cnt = vector<int> (2,0);
		dfs(i);
		ans +=(ll) cnt[0] * cnt[1];
	}
	ans -= n;
	cout << ans << endl;

}


Measured memory_bytes: 13380
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n, p; cin >> n >> p;
    vector<int> A(n); rep(i, n) cin >> A[i];

    vector<vector<ll>> dp(n+1, vector<ll>(2, 0));
    dp[0][0] = 1;
    rep(i, n){
        if(A[i]%2 == 0){
            dp[i+1][0] += dp[i][0] *2;
            dp[i+1][1] += dp[i][1] *2;
        }else{
            dp[i+1][0] += dp[i][0] + dp[i][1];
            dp[i+1][1] += dp[i][0] + dp[i][1];
        }
    }
    if(p == 1) cout << dp[n][1] << ln;
    else cout << dp[n][0] << ln;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rrep(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,u,v; cin >> n >> u >> v; u--; v--;
  vector<vector<ll>> G(n);
  rep(i,n-1){
    ll a,b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
  queue<ll> q;
  q.push(u);
  vector<ll> d_u(n, 100000000);
  d_u[u] = 0;
  while(!q.empty()){
    ll now = q.front(); q.pop();
    for(ll next:G[now]){
      if(d_u[next] !=  100000000) continue;
      d_u[next] = d_u[now] + 1;
      q.push(next);
    }
  }
  q.push(v);
  vector<ll> d_v(n, 100000000);
  d_v[v] = 0;;
  while(!q.empty()){
    ll now = q.front(); q.pop();
    for(ll next:G[now]){
      if(d_v[next] !=  100000000) continue;
      d_v[next] = d_v[now] + 1;
      q.push(next);
    }
  }
  ll ans = 0;
  rep(i,n){
    if(d_u[i] < d_v[i]) ans = max(ans,d_v[i]-1);
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 8064
import java.util.*;

public class Main {

    private static class Pair {
        int x;
        int y;


        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null)
                return false;
            Pair other = (Pair) obj;
            if (this.x == other.x && this.y == other.y)
                return true;
            return this.x == other.y && this.y == other.x;
        }

        public int hashCode() {
            return x + y;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numberOfPairs = sc.nextInt();
        List<Integer> lovedOnes = new ArrayList<>();
        for (int i = 0; i < numberOfPairs; i++) {
            lovedOnes.add(sc.nextInt());
        }
        List<Pair> pairs = new ArrayList<>();
        for (int i = 1; i <= numberOfPairs; i++) {
            pairs.add(new Pair(i, lovedOnes.get(i - 1)));
        }
        Set<Pair> pairsSet = new HashSet<>(pairs);
        System.out.println(numberOfPairs - pairsSet.size());
    }
}

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

////////////////////////
// Range Update Query //
////////////////////////

template<typename T = int64_t>
class RUpdQ {
private:
	std::vector<T> num_container_, time_container_;
	const T optional_{-1};
	int update_num_{};

	void build(const unsigned int array_size)
	{
		unsigned int length{1};
		while (length < array_size)
			length <<= 1;
		num_container_.resize(2 * length, optional_);
		time_container_.resize(2 * length, -1);
	}

public:
	RUpdQ(const unsigned int array_size) { build(array_size); }
	RUpdQ(const std::vector<T> &array)
	{
		build(array.size());
		std::copy(array.begin(), array.end(), num_container_.begin() + (num_container_.size() >> 1));
		std::fill(time_container_.begin() + ((int)time_container_.size() >> 1), time_container_.begin() + ((int)time_container_.size() >> 1) + (int)array.size(), update_num_);
		update_num_++;
	}
	// left,rightは0-indexed、[left, right)の半開区間
	void update(const int left, const int right, const T assigned)
	{
		for (int left_i{std::max(0, left) + ((int)num_container_.size() >> 1)}, right_i{std::min((int)num_container_.size() >> 1, right) + ((int)num_container_.size() >> 1)};
			left_i < right_i; left_i >>= 1, right_i >>= 1
			)
		{
			if (left_i & 1)
			{
				num_container_[left_i] = assigned;
				time_container_[left_i] = update_num_;
				left_i++;
			}
			if (right_i & 1)
			{
				right_i--;
				num_container_[right_i] = assigned;
				time_container_[right_i] = update_num_;
			}
		}
		update_num_++;
	}
	// indexは0-indexed
	T get(const int index) const
	{
		T last{optional_};
		int last_time{-1};
		for (int assign_place{index + ((int)num_container_.size() >> 1)}; assign_place > 0; assign_place >>= 1)
			if (time_container_[assign_place] > last_time)
			{
				last = num_container_[assign_place];
				last_time = time_container_[assign_place];
			}
		return last;
	}
};

int main()
{
	int N, Q;
	scanf("%d%d", &N, &Q);
	using i3 = std::array<int64_t, 3>;
	std::vector<i3> XST(N);
	for (auto& e: XST)
	{
		scanf("%lld%lld%lld", &e[1], &e[2], &e[0]);
		e[2] -= e[0];
		e[1] -= e[0];
	}
	std::sort(XST.rbegin(), XST.rend());

	std::vector<int64_t> st(2 * N);
	for (int i{}; i < N; i++)
	{
		st[2 * i] = XST[i][1];
		st[2 * i + 1] = XST[i][2];
	}
	std::sort(st.begin(), st.end());
	st.erase(std::unique(st.begin(), st.end()), st.end());
	int ruq_size{(int)st.size() + 1};

	RUpdQ<int> ruq(ruq_size);
	for (int i{}; i < N; i++)
	{
		int left{std::lower_bound(st.begin(), st.end(), XST[i][1]) - st.begin() + 1};
		int right{std::lower_bound(st.begin(), st.end(), XST[i][2]) - st.begin() + 1};
		ruq.update(left, right, XST[i][0]);
	}
	for (int i{}; i < Q; i++)
	{
		int D;
		scanf("%d", &D);
		int index{std::upper_bound(st.begin(), st.end(), D) - st.begin()};
		printf("%d\n", ruq.get(index));
	}

	return 0;
}

Measured memory_bytes: 17920
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;



int main() {
  //
  int N, K;
  cin >> N >> K;

  int a;
  map<int, int> a_frq_dict;
  for (int i = 0; i < N; ++i) {
    cin >> a;
//    cout << a << endl;
    if(a_frq_dict.find(a) == a_frq_dict.end()){
      a_frq_dict[a] = 1;
    }else{
      a_frq_dict[a]+= 1;
    }
  }

  //
  priority_queue<int, vector<int>, greater<int>> q;
  for (auto a_frq: a_frq_dict) {
//    cout << a_frq.second << endl;
    q.push(a_frq.second);
  }

//  cout << a_frq_dict.size() << endl;

  int ans = 0, lim = a_frq_dict.size() - K;
  for (int i = 0; i < lim; ++i) {
    int frq = q.top(); q.pop();
//    cout << "frq " << frq << endl;
    ans += frq;
  }

//  cout << lim << endl;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 10748
#include<bits/stdc++.h>
using namespace std;
string s; 
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='A' && s[i+1]=='C')
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


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

void showVector(std::vector<int> readVec){
    int length = readVec.size();
    for(int i = 0; i < length; ++i){
        if(length - 1 != i){
            std::cout << readVec.at(i) << " ";
        }else{
            std::cout << readVec.at(i);
        }
    }
    
    std::cout << std::endl;
}

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

    std::vector<int> a(n);
    for(int i = 0; i < n; ++i){
        std::cin >> a.at(i);
    }

    bool flg = true;
    int i, tmp;
    int count = 0;
    while(flg){
        flg = 0;
        for(i = n - 1; 0 < i; --i){
            if(a.at(i) < a.at(i - 1)){
                a.at(i) += a.at(i - 1);
                a.at(i - 1) = a.at(i) - a.at(i - 1);
                a.at(i) = a.at(i) - a.at(i - 1);
                flg = true;
                ++count;
            }
        }
    }
    
    showVector(a);    
    std::cout << count << std::endl;

    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

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

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=300010;

//約数列挙
void devide(ll n, vector<ll> &divisor){
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			divisor.push_back(i);
			if(i!=n/i)divisor.push_back(n/i);
		}
	}
}

//xのy乗%mod（繰り返し二乗法)
ll powll(ll x, ll y){
	ll res=1LL;
	while(y){
		if(y&1LL){
			res*=x;
		}
		x=(x*x);
		y>>=1LL;
	}
	return res;
}

bool kai(ll k, ll n){
	for(ll i=0;i<40;i++){
		ll ki = pow(k,i);
		if(ki>n)break;
		if(n%ki==0 && (n/ki)%k==1)return true;
	}
	return false;
}

int main(){
	ll n;
	cin>>n;
	vector<ll> d1;
	vector<ll> d2;
	devide(n, d1);
	int cnt=0;
	for(int i=0;i<d1.size();i++){
		if(d1[i]==1)continue;
		if(kai(d1[i],n)){
			cnt++;
		}
	}
	devide(n-1,d2);
	for(int i=0;i<d2.size();i++){
		if(d2[i]==1)continue;
		if(kai(d2[i],n)){
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{	rtn
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N + 2];
int pre[N][3], suf[N][3];

void solve()
{
	cin >> n;
	string str;
	cin >> str;

	map<char, int> mp;
	mp['R'] = 0;
	mp['G'] = 1;
	mp['B'] = 2;

	lop(i, 1, n + 1)
	{
		int x = mp[ str[i - 1] ];
		pre[i][ x ]++;
	}

	rlop(i, n, 1)
	{
		int x = mp[ str[i - 1] ];
		suf[i][ x ]++;
	}

	lop(i, 1, n + 1)
	{
		pre[i][0] += pre[i - 1][0];
		pre[i][1] += pre[i - 1][1];
		pre[i][2] += pre[i - 1][2];
	}

	rlop(i, n, 1)
	{
		suf[i][0] += suf[i + 1][0];
		suf[i][1] += suf[i + 1][1];
		suf[i][2] += suf[i + 1][2];
	}
	int ans = 0;

	lop(i, 1, n + 1)
	{
		int x = mp[ str[i - 1] ];
		set<int> st = {0, 1, 2};
		st.erase(x);
		pii p = {*st.begin(), *st.rbegin()};
		ans += pre[i - 1][p.ff] * suf[i + 1][p.ss];
		ans += pre[i - 1][p.ss] * suf[i + 1][p.ff];

		lop(k, 1, n + 1)
		{
			int s = i - k, e = i + k;
			if ( s >= 1 and e <= n)
			{
				if (str[s - 1] == str[i - 1] || str[e - 1] == str[i - 1]) continue;
				if ( str[s - 1] != str[e - 1]) ans--;
			}
		}
	}

	cout << ans;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

	int test = 1;
	// cin >> test;

	// cout << setprecision(9) << fixed;
	// clock_t z = clock();
	while (test--)solve();
	// cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
}





Measured memory_bytes: 3848