akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

void output(int a) {
  cout << a << endl;
}

int slime(vector<int> A, int N){
  // A のうち同じ数が隣り合っているものを見つける
  // もし隣り合っているものが奇数の場合，両端はそのままで間の色を変更するだけで良いので (n - 1)/2の回数で済む
  // もし隣り合っているものが偶数の場合，両端どちらかの色を変えて残りは交互に変化させればよいので n/2回か
  // 22112211 のような並びになっている場合，2313231
  int output = 0;
  int count = 0;
  int cur_color = -1;
  int flag = 0;

  for (int i=0; i<N; i++){
    if (flag == 1){
      if (A[i] == cur_color){
        // 引き続きやね
        count += 1;
      } else{
        // ここでおしまいということや
        if (count % 2 == 0){
          output += count / 2;
        } else{
          output += (count - 1) / 2;
        }
        count = 0;
        flag = 0;
      }
    } else {
      if (A[i] != cur_color){
        // なにもなし
      } else{
        // 出力待機モードにはいる
        count += 2;
        flag = 1;
      }
    }
    cur_color = A[i];
    // 最後の処理だけ
    if (i == N-1){
      if (count % 2 == 0){
        output += count / 2;
      } else{
        output += (count - 1) / 2;
      }
    }
  }
  return output;
}

int main() {
  int N;
  cin >> N;
  vector<int> A;
  A = input(N);
  output(slime(A, N));
}


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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.141592653589793238462643383279;
const int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N, K;
string S;
signed main() {
    cin >> N >> K >> S;
    int k = 0, a = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'L' && S[i - 1] == 'L') { a++; }
        if (S[i] == 'R' && S[i + 1] == 'R') { a++; }
    }
    for (int i = 1; i < S.length(); i++) {
        if (S[i] != S[0] && S[i - 1] == S[0]) { k++; }
    }
    if (K < k) { cout << a + 2 * K << endl; }
    else {
        k *= 2;
        if (S[0] != S[S.length() - 1]) { k--; }
        cout << a + k << endl;
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define MAGIC cin.tie(NULL); ios_base::sync_with_stdio(false)
#define endl '\n'
//#define ll long long
#define mod 1000000007
#define NCONS 100001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
#define int long long
//#define double long double
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;

int gcd(int a, int b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

#define YYYY cout << "YES" << endl
#define NNNN cout << "NO" << endl
#define yyyy cout << "Yes" << endl
#define nnnn cout << "No" << endl

int32_t main()
{
    MAGIC;
    int N; cin >> N; vector<int> B(N-1); for(int i = 0; i < N-1; i++) cin >> B[i];
    int ret = 0;
    
    for(int i = 0; i < N-2; i++)
        ret += min(B[i], B[i+1]);
    ret += B[0]; ret += B[N-2];
    
    cout << ret << endl;
    
    return 0;
}


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

typedef struct {
	bool firstflag;
	bool endflag;
	int firsttime;
	int endtime;
}State;

const int Max = 100;
int map[Max + 1][Max + 1] = { 0 };
std::stack<int> st;
std::vector<State> state;


int main()
{
	int n, k, v, x;
	int cnt = 1;

	std::cin >> n;
	for (int i = 1; i <= n; i++) {
		std::cin >> x >> k;
		for (int j = 1; j <= k; j++) {
			std::cin >> v;
			map[x][v] = 1;
		}
	}

	State s = { false,false,0,0 };
	for (int i = 0; i <= n; i++) {
		state.push_back(s);
	}

	while (1) {
		if (st.empty() == true) {
			if (state[1].endflag == true) {
				bool flag = false;
				for (int i = 1; i <= n; i++) {
					if (state[i].firstflag == false) {
						st.push(i);
						state[i].firstflag = true;
						state[i].firsttime = cnt;
						cnt++;
						flag = true;
						break;
					}
				}
				if (flag == true) {
					continue;
				}
				else {
					break;
				}
			}
			else {
				st.push(1);
				state[1].firstflag = true;
				state[1].firsttime = cnt;
				cnt++;
				continue;
			}
		}

		bool flag = false;
		for (int i = 1; i <= n; i++) {
			if (map[st.top()][i] == 1) {
				if (state[i].firstflag == false) {
					st.push(i);
					state[i].firstflag = true;
					state[i].firsttime = cnt;
					cnt++;
					flag = true;
					break;
				}
			}
		}
		if (flag == true) {
			continue;
		}
		else {
			state[st.top()].endflag = true;
			state[st.top()].endtime = cnt;
			cnt++;
			st.pop();
		}
	}

	for (int i = 1; i <= n; i++) {
		std::cout << i << " " << state[i].firsttime << " " << state[i].endtime << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  double p = 0;
  for (int& xi : x) {
    cin >> xi;
    p += (double)xi;
  }
  p /= (double)n;
  // cout << "p = " << p << endl;
  // mininmize sum (xi - p)^2
  // grad = -2 * sum (xi - p)
  // grad = 0 <=> sum (xi - p) = 0
  // p = x1 + ... / n
  int ret1 = 0;
  int ret2 = 0;
  int p1 = (int)p;
  int p2 = p1 + 1;

  for (int xi : x) {
    ret1 += (xi - p1) * (xi - p1);
    ret2 += (xi - p2) * (xi - p2);
  }
  // cout << ret1 << endl;
  // cout << ret2 << endl;
  cout << (min(ret1, ret2)) << endl;
  return 0;
}


Measured memory_bytes: 3628
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
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	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) {
	n := getNextInt(scanner)
	xx := make([]int64, n)
	sxx := make([]int64, n+1)
	var ans, mod int64
	mod = int64(1e9 + 7)

	for i := 0; i < n; i++ {
		xx[i] = getNextInt64(scanner)
		sxx[i+1] = (sxx[i] + xx[i]) % mod
	}

	tt := make([]int64, n)
	tt[0] = 1
	for i := 1; i < n; i++ {
		tt[i] = (tt[i-1] * 2) % mod
	}
	ff := make([]int64, n)
	ff[0] = 1
	for i := 1; i < n; i++ {
		ff[i] = ff[i-1] * int64(i) % mod
	}

	cm := Com{}
	cm.init(n)
	for i := n - 1; i < n; i++ {
		for j := 0; j < i; j++ {
			rest := j + n - i - 1
			if i != n-1 {
				rest--
			}
			ans += (((ff[rest] * (xx[i] - xx[j]) % mod) * ff[i-j-1]) % mod) * cm.calc(n-1, rest)
			ans %= mod
		}
	}

	for i := 1; i < n-1; i++ {
		rest := n - (i + 2)
		ans += (((ff[rest] * ((sxx[n-1]-sxx[n-1-i]-sxx[i])%mod + mod) % mod) * ff[i-1]) % mod) * cm.calc(n-1, rest)
		ans %= mod
	}
	fmt.Fprintln(writer, ans)
}

// Com ...
type Com struct {
	facs, invs []int64
	mod        int64
}

func (cm *Com) init(n int) {
	cm.facs = make([]int64, n+1)
	cm.invs = make([]int64, n+1)

	cm.facs[0] = 1
	cm.mod = int64(1e9 + 7)
	for i := 1; i <= n; i++ {
		cm.facs[i] = (cm.facs[i-1] * int64(i)) % cm.mod
	}
	cm.invs[n] = cm.inv(cm.facs[n])
	for i := n - 1; i >= 0; i-- {
		cm.invs[i] = cm.invs[i+1] * int64(i+1) % cm.mod
	}
}

func (cm *Com) inv(n int64) int64 {
	var ii [32]int64
	ii[0] = n
	for i := 1; i < 31; i++ {
		ii[i] = (ii[i-1] * ii[i-1]) % cm.mod
	}
	var ans int64
	ans = 1
	m := cm.mod - 2
	for i := 30; i >= 0; i-- {
		for m >= 1<<uint(i) {
			ans = (ans * ii[i]) % cm.mod
			m -= 1 << uint(i)
		}
	}

	return ans
}

func (cm *Com) calc(n, k int) int64 {
	ans := cm.facs[n] * cm.invs[k]
	ans %= cm.mod
	ans = ans * cm.invs[n-k]
	ans %= cm.mod
	return ans
}


Measured memory_bytes: 6400
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String s = sc.next();
        if (a >= 3200) {
            System.out.println(s);
        } else {
            System.out.println("red");
        }
    }
}


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

int main(){
  string S,T;
  int L;
  bool match = true;

  cin >> S;
  cin >> T;
  string subT = T.substr(0, S.length());

  // cout << "subT len : " << subT.length() << endl;

  // cout << "S : " << S << endl;
  // cout << "subT : " << subT << endl;
  if (subT == S){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
    int array[5],x,i;
    for(i=0;i<=4;i++){
        scanf("%d",&array[i]);
    }
    for(i=0;i<=4;i++){
        x=i+1;
        if(array[i]==0) break;
    }
    printf("%d",x);

    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int X, N;
	cin >> X >> N;
	set<int> P;
	for (int i = 0; i < N; ++ i) {
		int x;
		cin >> x;
		P.insert(x);
	}
	for (int i = 0; ; ++ i) {
		if (!P.count(X-i)) {
			cout << X-i << endl;
			return 0;
		}
		if (!P.count(X+i)) {
			cout << X+i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3636
/*
    Written by Kabir Kanha Arora
    @kabirkanha
 */

import java.util.*;

public class Main {
    public static void main(String[] args) {

        // Input
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long x = scanner.nextLong();
        long m = scanner.nextLong();

        HashMap<Long, Long> map = new HashMap<>();
        map.put(x, 0L);
        long curr = x;
        boolean zeroFlag = false;
        long loopStart = 0;
        long loopSize = 1;
        long loopStartElement = x;
        long sum = x;

        for (long i = 1; i < 1e7 && i < n; ++i) {
            curr = ((curr % m) * (curr % m)) % m;
            if (curr == 0) {
                zeroFlag = true;
                System.out.println(sum);
                break;
            }
            if (map.containsKey(curr)) {
                loopStart = map.get(curr);
                loopStartElement = curr;
                loopSize = i - loopStart;
                break;
            } else {
                sum += curr;
                map.put(curr, i);
                loopSize++;
            }
        }
        if (!zeroFlag) {

            // Elements before start of loop
            sum = 0;
            curr = x;
            long i;
            if (loopStart > 0)
                sum += x;
            for (i = 1; i < loopStart; ++i) {
                curr = ((curr % m) * (curr % m)) % m;
                sum += curr;
            }

            // Sum of loop elements
            long loopSum = loopStartElement;
            curr = loopStartElement;
            for (i = 1; i < loopSize; ++i) {
                curr = ((curr % m) * (curr % m)) % m;
                loopSum += curr;
            }
            long loops = (n - loopStart) / loopSize;
            sum += loops * loopSum;


            // Sum of remaining elements
            long rem = n - (loops * loopSize) - loopStart;
            if (rem > 0)
                sum += loopStartElement;
            curr = loopStartElement;
            for (i = 1; i < rem; ++i) {
                curr = ((curr % m) * (curr % m)) % m;
                sum += curr;
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 42876
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define display(v) for (auto x : v) cout << x << ", "
#define print(x) cout << (#x) << " = [ ";display(x); cout << "]\n"
#define endl '\n'
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
 
// DEBUG TEMPLATE by livw
void __print(int x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifdef INCLUDEWHENOFFLINE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int main()
{
    fastio;
    
    ll h, n;
    cin >> h >> n;
    ll sum = 0;
    while (n--)
    {
        ll temp;
        cin >> temp;
        sum += temp;
    }
    if (sum >= h) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


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

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = max({a*c, a*d, b*c, b*d});
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
N,K = map(int,input().split())
H = [0] + list(map(int,input().split()))

INF = float('inf')
dp = [[INF]*(N-K+1) for _ in range(N+1)]
dp[0][0] = 0

for i,h in enumerate(H):
    if i==0: continue
    for j in range(N-K,0,-1):
        for k in range(i):
            c = max(0, h - H[k])
            dp[i][j] = min(dp[i][j], dp[k][j-1] + c)
print(min(row[-1] for row in dp))

Measured memory_bytes: 48604
x, k, d = [int(i) for i in input().split()]
a = min(abs(x) // d, k)
x = x + (d * a) * (1 if x < 0 else -1)
k -= a

if k % 2 == 0:
    print(abs(x))
else:
    print(abs(x + d * (1 if x < 0 else -1)))

Measured memory_bytes: 9124
#include <iostream>
#include<bits/stdc++.h>
#define int long long int
#define e 1000000007
using namespace std;

 
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
 int t;
    t=1;
  while(t--){
    int d,t,s;
    cin>>d>>t>>s;
    if(s*t >= d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
  }
}

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

int main(){
    int N,min=101,sum=0;
    cin>>N;
    vector<int> s(N);
    for(int i=0;i<N;i++){
        cin>>s.at(i);
        sum +=s.at(i);
        if(min>s.at(i)&&s.at(i)%10!=0){
            min=s.at(i);
        }
    }
    if(sum%10!=0){
        cout<<sum<<endl;
    }else if(sum%10==0&&min!=101){
        cout<<sum-min<<endl;
    }else{
        cout<<0<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

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

    int arr1[51];
    int arr2[51];

    for(int i=0;i<n;i++)
    {
        cin>>arr1[i];
        arr2[i]=arr1[i];
    }
    sort(arr2,arr2+n);

    int b=0;

        for(int i=0;i<n;i++)
    {
        if(arr1[i]!=arr2[i])
            b++;
    }

    if(b<=2)
        cout<<"YES";
    else
        cout<<"NO";

return 0;}


int main2() {
    fast
    int n;
    cin>>n;

    int arr[51];

    for(int i=1;i<n;i++)
        cin>>arr[i];
    int cnt=0;
    int rep[2]={0};
    int k=0;
    for(int i=0;i<n-1;i++)
    {
        if(arr[i]>arr[i+1] && k<=1)
            rep[k++]=i;
    }

    //rep[0];
   // rep[1];
    swap(arr[rep[0]],arr[rep[1]]);
    bool b=false;

    for(int i=0;i<n-1;i++){
        if(arr[i]>arr[i+1])
        {
            b=true;
            break;
        }
    }
    if(b)
    {
        cout<<"NO";
    }
    else
        cout<<"YES";


	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    long long cnt = 0;
    cin >> N;
    for(int i = 1; i<=N; i++){
        if(i%3==0){
            continue;
        }
        if(i%5==0){
            continue;
        }
        cnt += i;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3636
//                _                                      
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __  
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \ 
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/ 
//                  |___/                         |_|  
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string n;
    cin>>n;
    ll sum = 0;
    REP(i,0,sz(n)-1) {
    	sum += (n[i]-'0');
    }
    if(sum%9==0) {
    	cout<<"Yes";
    }
    else {
    	cout<<"No";
    }
	return 0;
}

Measured memory_bytes: 3780
def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


def solve(n, k, i, facts, invs, MOD):
    m = n - k - (i - 1)
    if m < 0:
        return 0
    h = k - i
    # print(i, m, i + m)
    ans = facts[i + m] * invs[i] * invs[m] % MOD
    ans = ans * facts[i + h - 1] * invs[i - 1] * invs[h] % MOD
    return ans


n, k = list(map(int, input().split()))
MOD = 10 ** 9 + 7
facts, invs = prepare(n, MOD)
buf = []
for i in range(1, k + 1):
    buf.append(solve(n, k, i, facts, invs, MOD))
print('\n'.join(map(str, buf)))


Measured memory_bytes: 3316
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
int dp[55][55][3000];
string alph("abcdefghijklmnopqrstuvwxyz");
signed main(){
    int n;cin>>n;
    int a[114514],b[114514],c[114514];
    rep(i,0,n){
        cin>>a[i];
    }rep(i,0,n){
        cin>>b[i];
    }rep(i,0,n){
        cin>>c[i];
    }
    sort(a,a+n),sort(b,b+n),sort(c,c+n);
    int ans=0;
    rep(i,0,n){
        ans+=distance(a,lower_bound(a,a+n,b[i]))*distance(upper_bound(c,c+n,b[i]),c+n);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2816
N=int(input())
t=[]
x=[]
y=[]
for i in range(N):
  t1,x1,y1=[int(i) for i in input().split()]
  t.append(t1)
  x.append(x1)
  y.append(y1)
flag=1
for i in range(N):
  if t[i]<x[i]+y[i]:
    flag=0
  if t[i]%2 != (x[i]+y[i])%2:
    flag=0
if flag==1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 11720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (int)(n); i++)
int main(){
	int n,d,c=0;
	cin >> n;
   	cin >> d;
  
  	long long x;
  	long long y;
  
  	rep(i,n){
    	cin >> x;
      	cin >> y;
        if(d >= sqrt(x*x + y*y)){
        	c++;
        }
    }

    	cout << c << endl;
  
  return 0;
}

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

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>


#define INF 10e15
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

typedef struct edge{
    long long int from;
    long long int to;
    long long int cost;
} edge;

int main(){
    long long int n, m;
    cin >> n >> m;

    vector<edge> edges;
    long long int i, j;
    for(i = 0; i < m; i++){
        long long int s, t ,d;
        cin >> s >> t >> d;

        edge e;
        e.from = s-1;
        e.to = t-1;
        e.cost = -d;
        edges.push_back(e);
    }

    long long int dist[n];
    for(i = 0; i < n; i++){
        dist[i] = INF;
    }

    dist[0] = 0;

    for(i = 0; i < n-1; i++){
        for(j = 0; j < m; j++){
            edge e = edges[j];
            if(dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
            }
        }
    }

    for(i = 0; i < n-1; i++){
        for(j = 0; j < m; j++){
            edge e = edges[j];
            if(dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
                if(e.to == n-1){
                    cout << "inf" << endl;
                    return 0;
                }
            }
        }
    }

    cout << -dist[n-1] << endl;
}

Measured memory_bytes: 384
n,a,b=gets.split.map &:to_i
if (a-b).even?
  ans=(a-b).abs/2
else
  a,b=[a,b].minmax
  if a-1<n-b
    ans=(a+b-1)/2
  else
    ans=n-(a+b-1)/2
  end
end
p ans


Measured memory_bytes: 1788
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int N, M;
string s;
vector<vector<int> > G; //
vector<int> visited;
void rec(int v) {
  visited[v] = -1;
  for(auto& to : G[v]) {
    if(visited[to] == -1) {
      cout << "Yes" << endl;
      exit(0);
    } else if(!visited[to]){
      rec(to);
    }
  }
  visited[v] = 1;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M >> s;
  G.resize(N * 2);
  visited.resize(N * 2, false);
  FOR(i,0,M) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    if(s[a]==s[b]) {
      G[a].push_back(b+N);
      G[b].push_back(a+N);
    } else {
      G[a+N].push_back(b);
      G[b+N].push_back(a);
    }
  }
  FOR(i,0,N) {
    if(!visited[i]) {
      rec(i);
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 22096
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readLine().toInt
    val a1 = io.StdIn.readLine().split(' ').map { _.toInt }
    val a2 = io.StdIn.readLine().split(' ').map { _.toInt }

    val b1 = a1.drop(1).scanLeft(a1(0))((a,b) => a+b)
    val b2 = a2.take(n-1).scanRight(a2(n-1))((a,b) => a+b)

    println((b1 zip b2).map({ case (x, y) => x+y }).max)
  }
}

Measured memory_bytes: 25540
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;
signed main()
{
    fast;
   
    ll n,i;
    cin>>n;
    ll sum = 0;
    while(1)
    {
    	if(sum>n) break;
    	if(sum==n)
    	{
    		cout<<"1";
    		return 0;
    	}
    	bool ok = false;
    	sum += 100;
    	ll e1 = sum%100;
    	ll e2 = n%100;
    	if(e1<e2) {
    	for(i=5;i>=1;i--)
    	{
    		if(e1+i <= e2)
    		{
    			sum += i;
    			break;
    		}
    	}
        }
    }
    cout<<"0";
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]
d = a - b

l = 0
r = 1000000000
while 1 < r - l:
    c = (l + r) // 2
    if c < sum(list(map(lambda hi: (hi - b * c + d - 1) // d if 0 < hi - b * c else 0, h))):
        l = c
    else:
        r = c

print(r)

Measured memory_bytes: 121560
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=3e3+5;
ll n  , m , dp[maxN][maxN];
void solve(){
	string s , t ,ans;
	cin>> s >> t ;n=s.length() , m=t.length();
	for(ll i=0;i<=n ;i++){
		for(ll j=0;j<=m ; j++){
			if(i==0 || j==0)dp[i][j]=0;
			else{
				if(s[i-1]==t[j-1])dp[i][j]=1+dp[i-1][j-1];
				else dp[i][j]=max(dp[i-1][j] , dp[i][j-1]);
			}
		}
	}
	ll i=n , j=m ;
	while(i && j){
		if(dp[i][j]==dp[i-1][j])i--;
		else if(dp[i][j]==dp[i][j-1])j--;
		else ans.pb(s[i-1]) , i-- , j-- ;
	}
	reverse(ans.begin() , ans.end());
	cout<<ans<<endl;
}
int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

Measured memory_bytes: 74076
#include<algorithm>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false){
    if(b < a || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

    vector<int> a(n);
    vector<int> id;
    rep(i, n){
        cin >> a[i];
        id.emplace_back(i);
    }

    sort(id.begin(), id.end(), [&](int i, int j){ return a[i] < a[j]; });

    rep(i, n){
        if(i) cout << ' ';
        cout << id[i] + 1;
    }
    cout << endl;

    return 0;
}

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

#define maxn 400010
#define LL long long
#define inf 10000000000
#define mod 100000000
#define pi 3.14159265359
using namespace std;
int dx[24] = { 1,0,-1,0 ,2,0,-2,0 ,-1,-1,-2,-2 ,1,1,2,2    ,-1,-1,-2,-2 ,1,1,2,2 };
int dy[24] = { 0,1,0,-1 ,0,2,0,-2 ,-1,-2,-1,-2 ,-1,-2,-1,-2,1,2,1,2     ,1,2,1,2  };


LL n, m, k;
LL arr[maxn];
//LL arr2[maxn];
//int visit[maxn];
//int cache[maxn];
//int c[maxn];
//int g[maxn];
//int dfsnum = 0;
//vector<vector<int>>rvi;
//vector<vector<int>>scc;
//vector<pair<int, int>>ett;
//stack<int>st;
//bool flg = 1;
//LL s, d;
//
//int findp(int a) {
//	if (c[a] <0)return a;
//	return c[a] = findp(c[a]);
//}
//void unionp(int a, int b) {
//	a = findp(a);
//	b = findp(b);
//
//	if (a != b) {
//		c[a] += c[b];
//		c[b] = a;
//	}
//
//}
//LL power(LL x, LL y) {
//	LL ret = 1;
//	while (y > 0) {
//		if (y % 2) {
//			ret *= x;
//			ret %= mod;
//		}
//		x *= x;
//		x %= mod;
//		y /= 2;
//	}
//	return ret;
//}
//void dfs2(int v) {
//	cache[v] = 1;
//	scc.back().push_back(v);
//	for (int nv : rvi[v]) {
//		if (cache[nv])continue;
//		dfs2(nv);
//	}
//
//}
//LL fac(LL n) {
//	if (n == 1) return 1;        
//	return (n * fac(n - 1) - power(2,n-1) )%mod;
//}
//int fac2(LL n) {
//	LL res, i;
//	if (n == 1)return n;
//	res = n;
//	for (int i = n - 1; i > 0; --i) {
//		res *= i;
//		res %= mod;
//	}
//	return res;
//}

LL gcd(LL a, LL b) {
	while (b != 0) {
		LL r = a % b;
		a = b;
		b = r;
	}
	return a;
}


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

	//int t;   cin >> t; cin.ignore();
	int t = 1;
	for (int test_case = 0; test_case < t; ++test_case) {
		int flg = 0;
		LL ans1 = 0, ans2 = 0;
		string ans[2] = { "No","Yes" };
		string s1, s2 = "";
		int d, t, s;
		cin >> d >> t >> s;
		if (t*s >= d)flg = 1;
		cout << ans[flg];
		cout << '\n';


	}
	return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int mod=1e9+7;
const int maxn=2010;
int n,k;
vector<int> g[maxn];
int dis[maxn][maxn];
void dfs(int rt,int u,int fa,int dep)
{
	dis[rt][u]=dep;
	int sz=(int)g[u].size();
	for(int i=0;i<sz;i++)
	{
		int v=g[u][i];
		if(v==fa) continue;
		dfs(rt,v,u,dep+1);
	}
}
pair<int,int> p[maxn];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		g[a].push_back(b);
		g[b].push_back(a);
		p[i]=make_pair(a,b);
	}
	for(int i=1;i<=n;i++)
		dfs(i,i,-1,0);
	int minx=n;
	for(int i=1;i<=n;i++)
	{
		int cnt=0;
		for(int j=1;j<=n;j++)
			if(dis[j][i]*2>k) cnt++;
		minx=min(minx,cnt);
	}
	for(int i=1;i<=n-1;i++)
	{
		int cnt=0;
		for(int j=1;j<=n;j++)
			if(2*min(dis[j][p[i].first],dis[j][p[i].second])+1>k)
			cnt++;
		minx=min(minx,cnt);
	}
	printf("%d\n",minx);
	return 0;
}

Measured memory_bytes: 16256
use std::fmt::Debug;
use std::str::FromStr;

#[allow(dead_code)]
#[allow(deprecated)]
fn read_line_from_stdin() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    buffer.trim_right().to_owned()
}

#[allow(dead_code)]
#[allow(deprecated)]
fn parse_line_to_single<T>() -> T
where
    T: FromStr,
    T::Err: Debug,
{
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    T::from_str(buffer.trim_right()).unwrap()
}

#[allow(dead_code)]
#[allow(deprecated)]
fn parse_line_to_multiple<T>() -> Vec<T>
where
    T: FromStr,
    T::Err: Debug,
{
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    buffer
        .trim_right()
        .split_whitespace()
        .flat_map(|s| T::from_str(s))
        .collect()
}

#[allow(unused_macros)]
macro_rules! parse_line {
    [$( $x:tt : $t:ty ),+] => {
        //declare variables
        $( let $x: $t; )+
        {
            use std::str::FromStr;
            // read
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            #[allow(deprecated)]
            let mut splits = buf.trim_right().split_whitespace();
            // assign each variable
            $(
                $x = splits.next().and_then(|s| <$t>::from_str(s).ok()).unwrap();
            )+
            // all strs should be used for assignment
            assert!(splits.next().is_none());
        }
    };
}

fn main() {
    parse_line![a: i32, b: i32];

    println!("{}", a * b,);
}


Measured memory_bytes: 2156
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int K; cin >> K;
    while(K--) res += "ACL";
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    //solve<ll>(0);
    cout << fixed << setprecision(12) << solve<string>() << endl;
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  bool flag = true;
  for(long long int i = 0; i < S.size(); i++){
    if((i + 1) % 2 == 0 && S[i] == 'R') flag = false;
    if((i + 1) % 2 == 1 && S[i] == 'L') flag = false;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main(){
  string sa, sb, sc; cin >> sa >> sb >> sc;
  	int i=0, j=0, k=0, l=0;
  	
  	while (1) {
        if (l == 0) {
            if (i == sa.size()) {
                cout << "A\n";
                break;
            }
            l = sa[i] - 'a';
            i++;
        }
        else if (l == 1) {
            if (j == sb.size()) {
                cout << "B\n";
                break;
            }
            l = sb[j] - 'a';
            j++;
        }
        else if (l == 2) {
            if (k == sc.size()) {
                cout << "C\n";
                break;
            }
            l = sc[k] - 'a';
            k++;
        }
  	}
 	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=5*1e5+100;
int sn,n,q,w;
char s[N];
struct node
{
	int sum[27];
	bitset <27> mask;
}sh[1000];
int id(int x)
{
	return (x-1)/sn+1;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%d",&q);
	sn=sqrt(n);
	for (int i=1;i<=n;i+=sn)
	{
		w++;
		for (int j=i;j<=min(n,i+sn-1);j++)
		{
			sh[w].mask|=(1<<(s[j]-'a'));
			sh[w].sum[s[j]-'a']++;
		}
	}
	while (q--)
	{
		int op;
		scanf("%d",&op);
		if (op==1)
		{
			int i,block;char c[4];
			scanf("%d%s",&i,c);
			block=id(i);
			sh[block].sum[s[i]-'a']--;
			if (sh[block].sum[s[i]-'a']==0)
			  sh[block].mask^=(1<<(s[i]-'a'));
			if (sh[block].sum[c[0]-'a']==0)
			  sh[block].mask|=(1<<(c[0]-'a'));
			sh[block].sum[c[0]-'a']++;
			s[i]=c[0];
		}
		if (op==2)
		{
			int l,r;
			bitset <27> m;
			scanf("%d%d",&l,&r);
			if (id(l)==id(r))
			  for (int i=l;i<=r;i++) m|=(1<<(s[i]-'a')); 
			else
			{
				for (int i=id(l)+1;i<=id(r)-1;i++) m|=sh[i].mask;
				for (int i=l;i<=id(l)*sn;i++)m|=(1<<(s[i]-'a'));
				for (int i=(id(r)-1)*sn+1;i<=r;i++) m|=(1<<(s[i]-'a'));
			}
			printf("%d\n",(int)m.count());
		}
	}
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

template<class T,class F>
struct segment_tree{
  std::vector<T> data;
  int n;F f;T identity;
  segment_tree(){}
  segment_tree(int sz,T ide,F _f):f(_f),identity(ide){
    n=1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
  }
  segment_tree(std::vector<T> const& v,T ide,F _f):f(_f),identity(ide){
    build(v);
  }
  void build(std::vector<T> const& v){
    int sz=v.size();
    n=1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
    for(int i=0;i<sz;++i)data[i+n]=v[i];
    for(int i=n-1;i>0;--i)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  void set(int i,T x){
    i+=n;data[i]=x;
    while(i,i>>=1)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  T fold(int l,int r)const{
    l+=n,r+=n;
    T x=identity;
    while(l<r){
      if(l&1)x=f(x,data[l++]);
      if(r&1)x=f(x,data[--r]);
      l>>=1,r>>=1;
    }
    return x;
  }
  T operator[](int i)const{return data[i+n];}
};
template<class T,class F>
auto make_segtree(int n,T ide,F f){
  return segment_tree<T,F>(n,ide,f);
}
template<class T,class F>
auto make_segtree(std::vector<T>const& v,T ide,F f){
  return segment_tree<T,F>(v,ide,f);
}

signed main(){

  int n,t;
  cin>>n>>t;
  vector<ll> a(n);
  cin>>a;
  auto seg = make_segtree<ll>(a,-INF,[](auto a,auto b){return max(a,b);});

  ll max_dif = 0;
  rep(i,n)chmax(max_dif,seg.fold(i+1,n)-a[i]);
  ll ans = 0;
  rep(i,n){
    if(seg.fold(i+1,n)-a[i]==max_dif)ans++;
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 3072
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll a,b,k;cin>>a>>b>>k;
    for(ll i=a;i<=min(a+k-1,b);i++)
        cout<<i<<endl;
    ll mm=max(a+k-1,b-k);
    if(mm<a)
        mm=a;
    for(mm=mm+1;mm<=b;mm++)
        cout<<mm<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  sort(ALL(a));
  if (a[0] == a[1] && a[2] != a[1])
    cout << "Yes" << endl;
  else if (a[1] == a[2] && a[0] != a[1])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

using namespace std;

int N, Z, W;
vector<int> a;

void Main() {
    cin >> N >> Z >> W;
    a = vector<int>(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    if (N == 1) {
        cout << abs(W - a[0]) << endl;
        return;
    }
    int diffLast2 = abs(a[N - 2] - a[N - 1]);
    int diffYvsLast = abs(a[N - 1] - W);
    int ans = max(diffLast2, diffYvsLast);
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3548
from itertools import combinations_with_replacement

def main():
    n, m, q = map(int, input().split())
    abcd = [[int(i) for i in input().split()] for _ in range(q)]
    s = 0
    for p in combinations_with_replacement(range(1, m + 1), n):
        t = 0
        for a, b, c, d in abcd:
            t += d * (p[b - 1] - p[a - 1] == c)
        s = max(s, t)
    print(s)

if __name__ == '__main__':
    main()

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(c) (c).begin(), (c).end()

static constexpr int64_t MOD = 1'000'000'007;

inline int64_t add_mod(int64_t a, int64_t b) { return (a + b) % MOD; }
inline int64_t sub_mod(int64_t a, int64_t b) { return (a - b + MOD) % MOD; }
inline int64_t mul_mod(int64_t a, int64_t b) { return (a * b) % MOD; }

int64_t pow_mod(int64_t n, int64_t p) {
    n %= MOD;
    int64_t ans = 1;
    while (p > 0) {
        if (p & 1) {
            ans = mul_mod(ans, n);
        }
        n = mul_mod(n, n);
        p >>= 1;
    }
    return ans;
}

int main() {
    int N; cin >> N;
    if (N < 2) {
        cout << 0 << endl;
        return 0;
    }
    // 作り方全体 10^N
    // 0 を使わずに作る作り方 9^N
    // 9 を使わずに作る作り方 9^N
    // 0も9も使わずに作る作り方 8^N
    int64_t ans = add_mod(sub_mod(pow_mod(10, N), mul_mod(2, pow_mod(9, N))), pow_mod(8, N));
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

const int MAX = 101;

char data[MAX][MAX];
int w,h;


void solve(int i, int j, char c){
  data[i][j] = '0';
  if(i+1 < w && data[i+1][j] == c) solve(i+1,j,c);
  if(j+1 < h && data[i][j+1] == c) solve(i,j+1,c);
  if(i-1 >=0 && data[i-1][j] == c) solve(i-1,j,c);
  if(j-1 >=0 && data[i][j-1] == c) solve(i,j-1,c);

}

int main(){
  while(cin >> w >> h && w+h){
    for(int i = 0; i < w; i++)
      for(int j = 0; j < h; j++)
	cin >> data[i][j];
    int sum = 0;
    for(int i = 0; i < w; i++)
      for(int j = 0; j < h; j++)
	if(data[i][j] != '0'){
	  solve(i,j,data[i][j]);
	  sum++;
	}
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, K: int):
    mx = max(A, B, C)
    ret = mx * (2 ** K) + A + B + C - mx
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define nmax 2002
using namespace std;

int n,x,y;
int dist[nmax];
vector <int> v[nmax];
map<int,int> m;
bool marc[nmax][nmax];

void bfs(int node){
    for(int i=1;i<=n;i++) {
        if(node != 1) {
            marc[node-1][i]=1;
            if(marc[i][node-1]==0) {
                //cout<<node-1<<" "<<i<<" "<<dist[i]<<"\n";
                m[dist[i]]++;
            }
        }
        dist[i]=1e9;
    }
    //cout<<"\n";
    if(node==n) return;
    dist[node]=0;
    queue<int>q;
    q.push(node);
    while(!q.empty()){
        int aux=q.front();
        q.pop();
        for(auto k: v[aux]){
            if(dist[k] > dist[aux]+1){
                dist[k]=dist[aux]+1;
                q.push(k);
            }
        }
    }
}

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

    cin>>n>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
    for(int i=1;i<n;i++){
        v[i].push_back(i+1);
        v[i+1].push_back(i);
    }
    for(int i=1;i<=n;i++){
        bfs(i);
    }
    for(int i=1;i<n;i++){
        cout<<m[i]<<"\n";
    }
}


Measured memory_bytes: 4352