akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,index=0,ans=0,a,b,c;
    cin>>n>>m;
    multiset<pair<ll,ll> > ms;
    for(int i=0;i<n;i++){
    	cin>>a;
    	ms.insert(make_pair(a,1LL));
    }
    for(int i=0;i<m;i++){
    	cin>>b>>c;
    	ms.insert(make_pair(c,b));
    }
    auto itr=ms.end();
    itr--;
    while(index<n){
    	if(n-index<(*itr).second){
    		ans+=(n-index)*(*itr).first;
    		index=n;
    	}else{
    		ans+=(*itr).first*(*itr).second;
    		index+=(*itr).second;
    		itr--;
    	}
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 12800
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);

        int xa = sc.nextInt();
        int ya = sc.nextInt();
        int xb = sc.nextInt();
        int yb = sc.nextInt();

        int xc, yc, xd, yd;

        int ab_x = xb - xa;
        int ab_y = yb - ya;

        xc = xb - ab_y;
        yc = yb + ab_x;
        xd = xa - ab_y;
        yd = ya + ab_x;

        System.out.println(xc + " " + yc + " " + xd + " " + yd);
    }
}

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

int main(){
  int N, L;
  cin >> N >> L;
  string S[1000];
  for(int i = 0; i < N; i++){
    cin >> S[i];
  }
  sort(S, S + N);
  string ans;
  for(int i = 0; i < N; i++){
    ans += S[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000

// ans = a ? b : c; // to simplify: if (a) ans = b; else ans = c;

int main(int argc, char const *argv[])
{
	int n, m, u, v, r[100];
	scanf("%d %d", &n, &m);

	for(int i=1; i<=n; i++) r[i] = 0;
	for(int i=0; i<m; i++)
	{
		scanf("%d %d", &u, &v);
		r[u]++, r[v]++;
	}
	for(int i=1; i<=n; i++) printf("%d\n", r[i]);

	return 0;
}


Measured memory_bytes: 128
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll A[100010];
    rep(i,0,N) cin >> A[i];
    sort(A, A+N);
    ll lv = 0, rv = 200010;
    while(rv - lv > 1){
        ll mid = (rv + lv) / 2;
        bool ok = true;
        ll total = 0;
        rep(i,0,N){
            ll tt = mid - A[i];
            ll pos = lower_bound(A, A+N, tt) - A;
            ll cnt = N - pos;
            total += cnt;
        }
        if(total >= M){
            ok = true;
        }else{
            ok = false;
        }

        if(ok){
            lv = mid;
        }else{
            rv = mid;
        }
    }
    // print(lv);
    ll res2 = 0;
    ll sum[100010] = {};
    rep(i,0,N) sum[i+1] = sum[i] + A[i];
    ll ans = 0;
    rep(i,0,N){
        ll tt = lv+1 - A[i];
        ll pos = lower_bound(A, A+N, tt) - A;
        res2 += N - pos;
        ans += (N-pos) * A[i] + sum[N] - sum[pos];
    }
    ll diff = M - res2;
    ans += diff * lv;
    print(ans);

    

}

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

typedef long long ll;
typedef vector <bool> v_bool;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

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



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

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int n, d;
  cin >> n >> d;
  int ans = 0;
  while(n > 0) {
    ans++;
    n -= 2*d+1;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    ll n;
    string s;
    cin >> n >> s;
    ll le, ri;
    string ans = s;
    le = ri = 0;
    ll plus = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '(')
        {
            le++;
        }
        if (s[i] == ')')
        {
            if (le > 0)
                le--;
            else
                plus++;
        }
    }
    for (int i = 0; i < plus; i++)
    {
        ans = '(' + ans;
    }
    le = ri = 0;
    plus = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[n - 1 - i] == '(')
        {
            if (ri > 0)
                ri--;
            else
                plus++;
        }
        if (s[n - 1 - i] == ')')
        {
            ri++;
        }
    }
    for (int i = 0; i < plus; i++)
    {
        ans += ')';
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool is_prime(int x){
  if(x<=1) return false;
  for (int i=2; i*i <=x; ++i)
    if(x%i==0) return false;
  return true;
}
int main(){
  int x;
  cin >> x;
  
  int p=x;
  while(!is_prime(p))p++;
  
  cout << p << endl;
  return 0;
}
  


Measured memory_bytes: 256
'use strict'
const Main = (input) => {
  let tmp = input.split('\n');
  let Age = tmp[0].split(' ').map(Number)[0];
  let Cost = tmp[0].split(' ').map(Number)[1];

  if (6 <= Age && Age <= 12) {
    Cost = Cost / 2;
  } else if (Age <= 5) {
    Cost = 0;
  }
  console.log(Cost);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
N = gets.to_i
B = Array.new(N+1)
T = Array.new(N+1, false)
N.times{|n| B[n+1] = gets.to_i}

nxt = B[1]
until nxt == 2 do
  T[nxt] = true
  nxt = B[nxt]
  break if T[nxt]
end

puts nxt == 2 ? T.count(true)+1 : -1


Measured memory_bytes: 3708
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vector<vpll> path;
int main() {
	ll C;
	cin >> N >> C;
	vector<tuple<ll, ll, ll>> P;
	for (i = 0; i < N; i++) {
		ll s, t, c;
		cin >> s >> t >> c;
		c--;
		P.push_back(mt(s, t, c));
	}
	sort(P.begin(), P.end());
	vl R(31);
	vl A(31);
	for (i = 0; i <= 30; i++) {
		R[i] = -1;
		A[i] = -1;
	}
	for (i = 0; i < N; i++) {
		ll start = get<0>(P[i]);
		ll end = get<1>(P[i]);
		ll channel = get<2>(P[i]);
			for (j = 0; j <= 30; j++) {
				if (R[j] < start || (A[channel]==j && R[j] <=start)) {
					A[channel] = j;
					R[j] = end;
					break;
				}
			}
		//debug(i, R, A);
	}
	for (i = 0; i <= 30; i++) {
		if (R[i] != -1) ans++;
	}
	cout << ans;
}

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

string op = "+-*";

int calc(int a, int b, char c){
    if(c == '+')    return a+b;
    if(c == '-')    return a-b;
    return a*b;
}

string s(int x){
    return to_string(x);
}

string s(char x){
    string tmp({x});
    return tmp;
}

int main(){
    vector<int> v(4);
    string ans;
    while(1){
        for(int i = 0; i < 4; i++)  cin >> v[i];
        sort(v.begin(), v.end());
        if(v[0] == 0)   break;
        bool found = false;
        do{
            for(int i = 0; i < 27; i++){
                char a = op[i/9], b = op[(i%9)/3], c = op[i%3];
                if(calc(calc(v[0], calc(v[1],v[2],b), a), v[3], c) == 10){
                    found = true; ans="("+s(v[0])+s(a)+"("+s(v[1])+s(b)+s(v[2])+"))"+s(c)+s(v[3]);
                }
                if(calc(v[0], calc(calc(v[1],v[2],b), v[3], c), a) == 10){
                    found = true; ans=s(v[0])+s(a)+"(("+s(v[1])+s(b)+s(v[2])+")"+s(c)+s(v[3])+")";
                }
                if(calc(calc(calc(v[0],v[1],a), v[2], b), v[3], c) == 10){
                    found = true; ans="(("+s(v[0])+s(a)+s(v[1])+")"+s(b)+s(v[2])+")"+s(c)+s(v[3]);
                }
                if(calc( calc(v[0],v[1],a), calc(v[2],v[3],c), b) == 10){
                    found = true; ans="("+s(v[0])+s(a)+s(v[1])+")"+s(b)+"("+s(v[2])+s(c)+s(v[3])+")";
                }
                if(calc(v[0], calc(v[1], calc(v[2],v[3],c), b), a) == 10){
                    found = true; ans=s(v[0])+s(a)+"("+s(v[1])+s(b)+"("+s(v[2])+s(c)+s(v[3])+"))";
                }
            }
            if(found)   break;
        }while(next_permutation(v.begin(), v.end()));
        if(!found)  cout << 0 << endl;
        else        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

string S;
int main(int argc, char **argv) {
    cin >> S;
    bool res = false;
    for(int i = 0; i < S.size() - 1; ++i)
        if(S[i] == S[i + 1])
            res = true;

    cout << (res ? "Bad" : "Good") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N;
    ll sum = 0;
    vec a(N,0);
    rep(i,N){
        cin>>a[i];
        sum += a[i];
    }
    ll ans = INF, temp = 0;
    rep(i,N - 1){
        temp += a[i];
        ans = min(ans, abs(abs(sum - temp) - temp));
        //cout<<temp<<endl;
    }
    cout<<ans<<endl;
}

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

Measured memory_bytes: 2732
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] str = stdR.readLine().split(" ");
        int N = Integer.parseInt(str[0]);//1-2000 x + y + z = X
        int Y = Integer.parseInt(str[1])/1000;//1-20000 10 5 1　10x + 5y + z = Y
        boolean ok = false;
        for(int i = 0 ; i <= N ; i++) {
            int newX = N - i;
            int newY = Y - i;
            newY -= newX * 5;
            if(newY >= 0 && newY % 5 == 0) {
                if(newX - newY / 5 >= 0) {
                    ok = true;
                    System.out.println((newY / 5)+" "+(newX - newY / 5)+" "+i);
                    break;
                }
            }
        }
        if(!ok) {
            System.out.println("-1 -1 -1");
        }
    }
}


Measured memory_bytes: 22612
n=int(input())
a=map(int,input().split())
val = 1
exceed = 0
for i in a:
	if(exceed==0 or i==0):
		val*=i
	if(val==0):
		print(0)
		exit(0)
	if(val>1000000000000000000):
		exceed=1
if(exceed==0):
	print(val)
else:
	print(-1)

Measured memory_bytes: 19400
package main

import (
	"fmt"
)

func main() {
	var n,v int
	var ans string
	fmt.Scan(&n)
	
	v = 0
	for i := 1; i < 10; i++ {
		//nがiで割り切れれば
		if n % i == 0 {
			//nをiで割った商が答え
			v = n / i
		}
	}
	
	if v > 9 {
		ans = "No"
	} else {
		ans = "Yes"
	}
	
	fmt.Printf("%s", ans)
}

Measured memory_bytes: 512
import sys
import math 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N,M = na()
MOD=1000000007
#壊れいている段の数
a=[]
dp = [0]*(N+1)
dp[0]=1
a = [ni() for i in range(M)]
isbro = [1]*(N+1)
for i in range(M):
    isbro[a[i]]=0
#print(isbro)
for i in range(N):
    if(i-1>=0):
        dp[i+1] = dp[i]*isbro[i] + dp[i-1]*isbro[i-1]
    else:
        dp[i+1] = dp[i]*isbro[i]
    dp[i+1]%=MOD
#print(dp)
print(dp[N])

Measured memory_bytes: 52184
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)

//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

void solve()
{
    IN(n, k);
    double p[n];
    double e[n+1];
    e[0] = 0;
    rep(i, n)
    {
        cin >> p[i];
        e[i+1] = e[i] + (p[i] + 1) / 2;
    }
    double m = 0;
    rep(i, n-k+1)
    {
        chmax(m, e[i+k] - e[i]);
    }
    cout << m << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3328
N, K = map(int, input().split())
mod = 1000000007

E = [[] for i in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  E[a-1].append(b-1)
  E[b-1].append(a-1)
#ここまでで木をリスト化

counts = [False]*N
#各々の頂点について1回ずつ考えるようにTrueになったら進行しないようにコマンド
q = [0]
counts[0] = True
ans = K
while q:
  i = q.pop(0)
  # get_nexts
  js = E[i]
  if i == 0:
    c = K - 1
  else:
    c = K - 2
  for j in js:
    if not(counts[j]):
      counts[j] = True
      ans = (ans * c) % mod
      c -= 1
      q.append(j)
#print(E)      
print(ans)

Measured memory_bytes: 28076
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N;
	cin >> N;
	vector<int>A(N + 1), B(N);
	for (int i = 0; i < N + 1; i++)cin >> A[i];
	for (int i = 0; i < N; i++)cin >> B[i];
	int cnt = 0;
	for (int i = 0; i < N; i++)
	{
		cnt += min(A[i], B[i]);
		cnt += min(A[i + 1], B[i] - min(A[i], B[i]));
		A[i + 1] -= min(A[i + 1], B[i] - min(A[i], B[i]));
	}
	cout << cnt;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
int main(){
  int n,k,c,r=0;
  cin>>n>>k;
  map<int,int> m;
  for(int i=0;i<n;++i){cin>>c;m[c]++;}
  vector<pii> v;
  for(auto&& p:m)v.emplace_back(p);
  sort(v.begin(),v.end(),[](pii a,pii b){return a.second<b.second;});
  if(v.size()>k)for(int i=0;i<v.size()-k;++i)r+=v[i].second;
  cout<<r;
  return 0;
}

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

using namespace std;

int n, x;
int chk[222222];
int an[222222];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d%d",&n,&x);
	if (n == 2){
		if (x == 2) printf("Yes\n1\n2\n3\n");
		else printf("No");
	}
	else if (x == 1 || x == 2 * n - 1) printf("No");
	else{
		printf("Yes\n");
		if (x == 2){
			an[n - 1] = 3;
			an[n] = 2;
			an[n + 1] = 1;
			an[n + 2] = 4;
			chk[1] = chk[2] = chk[3] = chk[4] = 1;
		}
		else{
			an[n - 1] = x - 1;
			an[n] = x;
			an[n + 1] = x + 1;
			an[n + 2] = x - 2;
			chk[x - 2] = chk[x - 1] = chk[x] = chk[x + 1] = 1;
		}
		int cur = 1;
		for(int i = 1; i < 2 * n; ++i){
			if (!an[i]){
				while(chk[cur]) ++cur;
				an[i] = cur;
				++cur;
			}
			printf("%d\n",an[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long L;
    cin >> L;
    double per = L / 3.0 ;
    cout << fixed << setprecision(10) << per * per * per << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>

int main() {

	int a, b, c, d, p;

	std::cin >> a >> b >> c >> d >> p;

	int X = a * p;

	int Y;

	if (p <= c) {
		Y = b;
	}
	else {
		Y = b + (p - c) * d;
	}
	std::cout << std::min(X, Y) << std::endl;

	return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
inline int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
inline int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
inline int mul(int a, int b) {return 1ll * a * b % P;}
inline int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
const int N = 101010;
int n, v[N];
ll c, x[N];
int main(){
	scanf("%d%lld", &n, &c);
	rep(i, 0, n) scanf("%lld%d", x + i, v + i);
	ll ans = 0, s = 0;
	rep(i, 0, n) {
		s += v[i];
		ans = max(ans, s - x[i]);
	}
	s = 0;
	for(int i = n - 1; ~i; i--) {
		s += v[i];
		ans = max(ans, s - (c - x[i]));
	}
	multiset<ll> sum;
	sum.insert(0);
	s = 0;
	for(int i = n - 1; ~i; i--) {
		s += v[i];
		ll t = s - (c - x[i]);
		sum.insert(-t);
	}
	ll ns = 0;
	rep(i, 0, n) {
		ll t = s - (c - x[i]);
		s -= v[i];
		ns += v[i];
		sum.erase(sum.find(-t));
		ans = max(ans, ns - 2 * x[i] - *sum.begin());
	}
	sum.clear();
	sum.insert(0);
	s = 0;
	rep(i, 0, n) {
		s += v[i];
		ll t = s - x[i];
		sum.insert(-t);
	}
	ns = 0;
	for(int i = n - 1; ~i; i--) {
		ns += v[i];
		ll t = s - x[i];
		s -= v[i];
		sum.erase(sum.find(-t));
		ans = max(ans, ns - 2 * (c - x[i]) - *sum.begin());
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
int f[2000010],a1[100],b1[100];
bool c[100];
int len,k;
void solve(int a,int b,int la)
{
	if (len>(1<<n)) return;
	if (la==0) {
		puts("NO"); return;
	}
	if (la==1) 
	{
		f[++len]=a;
		if (b==a) {
		puts("NO"); exit(0);} else f[++len]=b;
		return;
	}
	if (a==b) {
		puts("NO"); exit(0);
	}
	int x=a,y=b;
	for (int i=0;i<n;i++){
		a1[i]=(x&1); x>>=1;
	}
	for (int i=0;i<n;i++){
		b1[i]=(y&1); y>>=1;
	}
	int t;
	for (int i=0;i<n;i++)
	if ((a1[i]!=b1[i])&&(!c[i])) t=i;  	
	bool p=0;
	for (int i=0;i<n;i++) 
	 if ((!c[i])&&(a1[i]==b1[i])) {
	 	c[t]=1;
	 	solve(a,a^(1<<i),la-1);
	 	solve(a^(1<<i)^(1<<t),b,la-1);
	 	p=1; break;
	 }
	if (!p) 
	{
		for (int i=0;i<n;i++)
		if (!c[i]&&i!=t)
		{
			c[t]=1;
			solve(a,a^(1<<i),la-1);
			solve(a^(1<<i)^(1<<t),b,la-1);
		}
	} 
	c[t]=0;
}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	solve(a,b,n);
	puts("YES");
	for (int i=1;i<=(1<<n);i++) printf("%d ",f[i]);
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

/*
int main() {
    int A, B;
    int ad, su, mu;
    std:cin >> A >> B;
    ad = A+B;
    su = A-B;
    mu = A*B;

    std::cout << max({ad, su, mu} )<< std::endl;

    return 0;
}
 */

int main(){
    int K, X;
    std::cin >> K >> X;
    for(int i=X-K+1; i<X+K; i++){
        std::cout << i << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int K = scan.nextInt();

		int ans = 0;

		if (A > K) {
			ans = 1 * K;
			System.out.println(ans);
		} else {
			K = K - A;
			ans = 1 * A;
			if (K == 0) {
				System.out.println(ans);
			} else {
				K = K - B;
				ans = ans + (B * 0);
				if (K <= 0) {
					System.out.println(ans);
				} else {
					ans = ans + (K * -1);
					System.out.println(ans);
				}

			}

		}
	}

}


Measured memory_bytes: 35832
#include <iostream>
#include <queue>

typedef long long ll;
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<ll> que;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        que.push(a);
    }

    for (int i = 0; i < m; i++) {
        ll x = que.top();
        que.pop();
        que.push(x / 2);
    }

    ll ret = 0;
    while (!que.empty()) {
        ret += que.top();
        que.pop();
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

#define INF 1000000

int r, n, m;

int dijk(int s, int e, int d[21][21]) {
  int mi, i, j;
  int c[m + 1] = {};
    
  for(i = 0; i <= m; i++) {
    c[i] = INF;
  }
    
  int f[m + 1] = {};
  mi = s;
  c[s] = 0;

  for(i = 0; i < m; i++){
    f[mi] = 1;

    for(j = 0; j <= m; j++) {
      if(f[j] == 1) continue;
      if(c[j] > d[mi][j] + c[mi]) {
	c[j] = d[mi][j] + c[mi];
	//	cout << j << c[j] << endl;
      }
    }

    int MIN = INF * 2;

    for(j = 0; j <= m; j++) {
      if(f[j] == 1) continue;
      if(MIN > c[j]) {
	MIN = c[j];
	mi = j;
      }
    }
  }
  return c[e];
}

  
int main() {
  int i, j, a,b, cost_c, cost_d, h_cost, re, s, e;
  while(cin >> m >> n) {
    int d[21][21] = {};
    
    for(i = 0; i <= m; i++) {
      for(j = 0;j <= m; j++) {
	d[i][j] = INF;
      }
    }
    
    for(i = 0; i < n; i++) {
      scanf("%d,%d,%d,%d", &a, &b, &cost_c, &cost_d);
      //      cin >> a >> b >> cost_c >> cost_d;
      d[a][b] = cost_c;
      d[b][a] = cost_d;
    }
    scanf("%d,%d,%d,%d", &s, &e, &re, &h_cost);
    //    cin >> s >> e >> re >> h_cost;
    cout << re -dijk(s, e, d) - dijk(e, s, d) - h_cost<< endl;
  }
  return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(),vec.end()
#define ll long long

int main(){
    ll l, r;
    cin >> l >> r;
    ll result = 2018;
    if (r - l > 2019) {
        cout << 0 << endl;
        return 0;
    }
    else {
        for (ll i = l; i <= r; i++){
            for (ll j = i + 1; j <= r; j++)
                result = min(result, (i * j) % 2019);
        }
        cout << result << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,k[200005],num[200005],con,kc[200005],x,y;
bool hh[200005],ch[200005];
set<int>ss[200005];
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&num[i]);
		k[num[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j>=i-k[i]+1;j--)
		{
			hh[max(j,1)]=true;
			kc[max(j,1)]++;		
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(!hh[i])con++;
	}
	for(int i=1;i<=n;i++)
	{
		int ed=max(i-k[i]+1,1);
		for(int j=i;j>=ed;j--)
		{
			if(kc[j]>1)ch[i]=true;		
		}
	}
	//printf("con %d\n",con);
	for(int i=1;i<=m;i++)
	{
		scanf("%d %d",&x,&y);
		int pas=num[x];
		k[y]++;	
		int a=max(pas-k[pas]+1,1),b=max(y-k[y]+1,1);
		num[x]=y;
		k[pas]--;
		kc[a]--;
		kc[b]++;
		if(kc[b]>0)
		{
			if(!hh[b])con--,hh[b]=true;	
		}
		if(kc[a]<=0)
		{
			if(hh[a])con++,hh[a]=false;	
			ch[pas]=false;
		}
		if(kc[a]<=1)ch[pas]=false;
		if(kc[b]>1)ch[y]=true;
		//printf("---%d--- %d %d %d %d\n",con,a,b,kc[a],kc[b]);
		printf("%d\n",con);
	}
}


Measured memory_bytes: 13568
N,Y = map(int,input().split())
for i in range(N+1):
    for j in range(N-i+1):
        k = N - j - i
        if 10000 * i + 5000 * j + 1000 * k == Y:
            print(i," ",j," ",k)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 9184
use std::cmp::min;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let m: usize = read(&mut stdin_lock, &mut buf, b' ');
    let x: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    let mut av = vec![0; n];
    for i in 0..m - 1 {
        av[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    av[m - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let i = av.iter().position(|&a| a > x).unwrap();
    let count_a1 = av[0..i].iter().count();
    let count_a2 = av[i..m].iter().count();
    let ans = min(count_a1, count_a2);
    println!("{}", ans);
}


Measured memory_bytes: 4352
prime = [True]*(10**5+1)
prime[0] = False
prime[1] = False

for a in range(2,318): # >>> gmpy2.isqrt(10**5+1) -> mpz(316)
  if prime[a] == False:
    continue
  else:
    for b in range(a*2,10**5+1,a): 
      prime[b] = False
"""
print prime
import gmpy2

for a in range(0,10**5+1):
  if prime[a] != gmpy2.is_prime(a):
    print "NO"
    print a
"""
ans = [0]*(10**5+1)
now = 0
for a in range(3,10**5+1,2):
  if prime[a] == True and prime[(a+1)/2] == True:
    now = now + 1
  ans[a] = now

q = int(raw_input())
for a in range(q):
  l,r = map(int,raw_input().split(" "))
  x = ans[r] - ans[l]
  if prime[l] == True and prime[(l+1)/2] == True:
    x = x + 1
  print x


Measured memory_bytes: 7804
n = int(input())
x = tuple(map(int,input().split()))
def cost(p):
    s = 0
    for i in range(0,n):
        s = s + (x[i] - p)**2
    return s
mid = round((max(x) + min(x))/2)
if cost(mid) == cost(mid + 1):
    print(cost(mid))
elif cost(mid) > cost(mid + 1):
    para = mid + 1
    for i in range(0,max(x)):
        if cost(para) <= cost(para + 1):
            print(cost(para))
            break
        para = para + 1
else:
    para = mid
    for i in range(0,max(x)):
        if cost(para) <= cost(para - 1):
            print(cost(para))
            break
        para = para - 1

Measured memory_bytes: 3064
n , k , s =map(int,input().split())
list=[]
if s > n :
    for i in range(k):
        list.append(s)
    for i in range(n-k):
        list.append(1)
else:
    for i in range(k):
        list.append(s)
    for i in range(n-k):
        list.append(s+1) 
print(*list)

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

int main() {
	int r;

	scanf("%d", &r);

	if (r < 1200) {
		printf("ABC");
	}
	else if (r < 2800) {
		printf("ARC");
	}
	else {
		printf("AGC");
	}
}

Measured memory_bytes: 1704
import heapq

n, q = map(int, input().split())
stack = [[] for _ in range(n)]
heapq.heapify(stack)

for _ in range(q):
    query = list(map(int, input().split()))
    if query[0] == 0:
        heapq.heappush(stack[query[1]], -query[2])
    elif query[0] == 1:
        if stack[query[1]] == []:
            pass
        else:
            print(-stack[query[1]][0])
    elif query[0] == 2:
        if stack[query[1]] == []:
            pass
        else:
            heapq.heappop(stack[query[1]])


Measured memory_bytes: 13184
N = int(input())
al = list(map(int,input().split()))
ansal = sorted(al)

for i in range(N):
    for j in range(i,N):
        cond_al = al.copy()
        cond_al[i],cond_al[j] = cond_al[j],cond_al[i]
        if(cond_al==ansal):
            print("YES")
            exit(0)

print("NO")


Measured memory_bytes: 3060
#include <iostream>

int main(void)
{
  int a, b;
  std::cin >> a >> b;
  if (a > b) {
    std::cout << "a > b\n";
  } else if (a < b) {
    std::cout << "a < b\n";
  } else {
    std::cout << "a == b\n";
  }
  return 0;
}

Measured memory_bytes: 1124
n, m = map(int, input().split())
lll = []
rrr = []
for _ in range(m):
  lr = list(map(int, input().split()))
  lll.append(lr[0])
  rrr.append(lr[1])
maxl = max(lll)
minr = min(rrr)
count = 0
for i in range(1,n+1):
  if maxl <= i <= minr:
    count += 1
print(count)
  
      
      
      
      
           
  

Measured memory_bytes: 11048
#include <stdio.h>
#include <string.h>

int main(void)

{	
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	
	if(a*b>=c*d){
		printf("%d\n",a*b);
	} else{
		printf("%d\n",c*d);
	}
	return 0;
}


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

using ll = unsigned long long;
ll A[300100];
ll MOD = 1e9 + 7;

int main() {
  int N;

  cin >> N;
  for(int i = 1; i <= N; ++i) {
    cin >> A[i];
  }

  ll total = 0;
  for(ll j = 0; j < 61; ++j) {
    ll bit = 1UL << j;
    ll count = 0;
    for(int i = 1; i <= N; ++i) {
      if(A[i] & bit) {
        count++;
      }
    }
    ll factor = count * (N - count);
    // cout << j << " : " << bit << " : " << factor << endl;
    total += ((bit % MOD) * (factor % MOD)) % MOD;
    total %= MOD;
  }
  cout << total << endl;
  return 0;
}

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

int main() {
    int n, a, b;
    a = 0;
    b = 0;
    cin >> n;
    vector<int> vec(n);

    for(int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }

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

    for(int j = 0; j < n; j++) {
        if(j % 2 == 0) a += vec.at(j);
        else b += vec.at(j);
    }
    cout << a - b << endl;
}

Measured memory_bytes: 256
n = input()
a = list(map(int,input().split()))

def iseven(i,num_list):
  for num in num_list:
    if num % 2 != 0:
      return False
  return True

num_divided = 0

while iseven(n,a) :
  a = list(map(lambda x: x / 2, a ))
  num_divided += 1

print(num_divided)

Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a:
  print(0)
else:
  for i in range(n):
    ans *= a[i]
    if ans > 10**18:
      print(-1)
      break
    if i == n-1:
      print(ans)

Measured memory_bytes: 21640
new Promise(function(resolve, reject) {
    let cin = "";
    process.stdin.on("data", chunk => { cin += chunk; });
    process.stdin.on("end", () => { resolve([cin, process.stdout]); });
}).then(function([cin, cout]) {
    const [[N, W], ...d] = cin.split("\n").map(elt => elt.split(" ").map(e => parseInt(e)));
    const opt = new Array(W + 1).fill(0);
    for (const [v, w] of d.slice(0, N)) {
        for (let i = w; i <= W; ++i) {
            opt[i] = Math.max(opt[i], opt[i - w] + v);
        }
    }
    cout.write(`${opt[W]}\n`);
});



Measured memory_bytes: 20372
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=100005;
int val[maxn*20],hd[maxn],n,m;
int to[maxn*20],ne[maxn*20],num,S;
int XS[maxn],now,ci[20],d[maxn],C[233];
inline void add(int x,int y,int z){ to[++num]=y,ne[num]=hd[x],hd[x]=num,val[num]=z;}

inline void build(){
	for(int i=1;i<ci[15];i++)
	    for(int j=1;j<=15;j++) if(ci[j-1]&i){
	    	now=i^ci[j-1],add(now,i,1);
	    	for(int k=1;k<=15;k++) if(ci[k-1]&now) add(now^ci[k-1]^ci[(j^k)-1],i,1+((now&ci[(j^k)-1])?1:0));
		}
}

inline void spfa(){
	queue<int> q; bool v[maxn];
	memset(d,0x3f,sizeof(d));
	memset(v,0,sizeof(v));
	d[0]=0,q.push(0),v[0]=1;
	
	int x;
	while(!q.empty()){
		x=q.front(),q.pop();
		for(int i=hd[x];i;i=ne[i]) if(d[x]+val[i]<d[to[i]]){
			d[to[i]]=d[x]+val[i];
			if(!v[to[i]]) v[to[i]]=1,q.push(to[i]);
		}
		v[x]=0;
	}
}

inline void init(){
	ci[0]=1;
	for(int i=1;i<=15;i++) ci[i]=ci[i-1]<<1;
	
	build();
	spfa();
}

inline void solve(){
	int uu,vv,ww,ans=1<<30;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d%d",&uu,&vv,&ww);
		uu++,vv++,XS[uu]^=ww,XS[vv]^=ww;
	}
	
	for(int i=1;i<=n;i++) C[XS[i]]++;
	for(int i=1;i<=n;i++){
		C[XS[i]]--;
		
		S=0,now=0;
		for(int j=1;j<=15;j++){
			now+=C[j]>>1;
			S|=(C[j]&1)*ci[j-1];
		}
		now+=d[S];
		ans=min(ans,now);
		
		C[XS[i]]++;
	}
	
	printf("%d\n",ans);
}

int main(){
	init();
	solve();
	return 0;
}

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

typedef long long ll;

int main() {
    int n,q;
    cin>>n>>q;
    
    string s;
    cin>>s;
    
    int index[n];
    index[0]=0;
    
    for(int i=1;i<s.size();i++){
        index[i]=index[i-1];
        if(s[i]=='C' and s[i-1]=='A'){
            index[i]++;
        }
    }
    for(int t=1;t<=q;t++){
        int l,r;
        cin>>l>>r;
        l-=1;
        r-=1;
        if(l>0){
            cout<<index[r]-index[l]<<endl;
        }else{
            cout<<index[r]<<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 1408
n=int(input())
A=list(map(int,input().split()))

cnt1,cnt2,cnt3=0,0,0
for a in A:
  if a%4==0:
    cnt1+=1
  elif a%2==0:
    cnt2+=1
cnt1+=cnt2//2
print('Yes') if cnt1>=n//2 else print('No')


Measured memory_bytes: 15020
function main(input) {
  const lines = input.trim().split("\n");
  let [n, k] = lines[0].split(' ');
  n = +n;
  k = BigInt(k);
  const towns = lines[1].split(' ').map(Number);

  const visited = new Map();
  let pos = 1, i;
  while (i = visited.get(pos), i === undefined && k) {
    visited.set(pos, visited.size);
    pos = towns[pos - 1];
    k--;
  }
  if (k > 0) {
    const cycle = BigInt(visited.size - i);
    const rest = Number( (k % cycle).toString() );
    for (let [key, value] of visited) {
      if (value == i + rest) {
        pos = key;
        break;
      }
    }
  }
  
  console.log(pos);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 70856
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << endl;
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int64_t, int >prime_factor(int64_t n){map< int64_t, int > ret;for(int64_t i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    VI l(n); REP(i,n) cin >> l[i]; SORT(l);

    int ans = 0;
    REP(i,n){
        FOR(j,i+1,n){
            int k = lower_bound(l.begin(),l.end(),l[i]+l[j]) - l.begin();
            ans += max(k-j-1,0LL);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n, m, a[300010];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	m = 0;
	for (int i = 0; i <= m; i++) {
		m = max(a[i] / 10 + i, m);
		if (m >= n)goto heaven1;
	}
	cout << "no\n";
	return 0;
heaven1:m = n - 1;
	for (int i = n - 1; i >= m; i--) {
		m = min(i - a[i] / 10, m);
		if (m <= 0)goto heaven2;
	}
	cout << "no\n";
	return 0;
heaven2:cout << "yes\n";
	return 0;
}


Measured memory_bytes: 4268
#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;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

bool ok[200009];

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

    int x;

    cin >> x;
    if (x <= 2)
        return cout << 2, 0;

    for (int j = 4; j <= 2e5 + 7; j += 2)
        ok[j] = 1;

    for (int i = 3; i * i <= 2e5 + 7; ++i)
        if (!ok[i])
            for  (int j = i * i; j <= 2e5 + 7; j += 2 * i)
                ok[j] = 1;
    while (ok[x])
        ++x;
    cout << x;
    return 0;
}


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

int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 
int k;

int main()
{
	cin >> k;
	cout << a[k-1] << endl;
	return 0;
} 

Measured memory_bytes: 256
def solve():
    a, b, c, d = map(int, input().split())
    ans = [0] * 101
    for i in range(a, b):
        ans[i] += 1
    for i in range(c, d):
        ans[i] += 1
    print(ans.count(2))

if __name__=="__main__":
    solve()

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

int main(){
 int64_t N,c=0,t=0;
  
  cin>>N;

  rep(i,N){
    if((i+1)%3==0 || (i+1)%5==0){
      c=c+i+1;
    }
    t=t+i+1;
  }
  
  cout << t-c << endl;
  
}




Measured memory_bytes: 3632
s = int(input())
ans = []
ans.append(s)
while len(ans) == len(set(ans)):
    tmp = ans[-1]
    if tmp%2 == 0:
        ans.append(tmp//2)
        tmp = tmp//2
    else:
        ans.append(3*tmp+1)
        tmp = 3*tmp+1
print(len(ans))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
				
int32_t main() {
	fast_cin();  
	int k; cin >> k;
	int num = 0;
	for (int i = 1; i <= 1e7; ++i) {
		num = num * 10 + 7;
		num %= k;
		if (num == 0) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

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

typedef long long ll;

int P[100000], Y[100000];
vector<int> yd[100001];

int main()
{
	int N, M; cin >> N >> M;
	
	
	for (int i = 0; i < M; i++) {
		cin >> P[i] >> Y[i];
		yd[P[i]].push_back(Y[i]);
	}
	for (int i = 0; i < N; i++) sort(yd[i + 1].begin(), yd[i + 1].end());
	for (int i = 0; i < M; i++)
		printf("%012lld\n", ll(P[i]) * 1000000 + int(lower_bound(yd[P[i]].begin(),
			yd[P[i]].end(), Y[i]) - yd[P[i]].begin()) + 1);

	return 0;
}


Measured memory_bytes: 7808
#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 ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2003, MOD = 1e9 + 7;
int n, m, mst[N], par[N], sz[N], dif[N], pw[N];
array <int, 3> e[N];
ll X;

void make_set(int x) {
	par[x] = x, sz[x] = 1;
}

int find_set(int x) {
	if (x == par[x]) return x;
	return par[x] = find_set(par[x]);
}

bool union_set(int x, int y) {
	x = find_set(x), y = find_set(y);
	if (x == y) return false;
	if (sz[x] < sz[y]) swap(x, y);
	par[y] = x, sz[x] += sz[y];
	return true;
}

vector <array <int, 2>> g[N];

int dfs(int v, int u, int p = -1) {
	if (v == u) return 0;
	int res = -1;
	for (auto i : g[v]) {
		if (i[0] == p) continue;
		int cur = dfs(i[0], u, v);
		if (cur >= 0) res = max(cur, i[1]);
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	pw[0] = 1;
	for (int i = 1; i < N; i++) pw[i] = pw[i - 1] * 2 % MOD;
	cin >> n >> m >> X;
	for (int i = 0; i < m; i++)
		cin >> e[i][1] >> e[i][2] >> e[i][0];
	sort(e, e + m);
	ll S = 0;
	for (int i = 1; i <= n; i++) make_set(i);
	for (int i = 0; i < m; i++) {
		if (union_set(e[i][1], e[i][2])) {
			mst[i] = 1, S += e[i][0];
			g[e[i][1]].pb({e[i][2], e[i][0]});
			g[e[i][2]].pb({e[i][1], e[i][0]});
		}
	}
	ll D = X - S;
	if (D < 0) return cout << 0, 0;
	int eq = 0, up = 0;
	for (int i = 0; i < m; i++) {
		if (mst[i] == 1) continue;
		dif[i] = e[i][0] - dfs(e[i][1], e[i][2]);
		if (dif[i] == D)
			eq++;
		else if (dif[i] > D)
			up++;
	}
	int res = (ll)2 * (pw[eq] - 1) * pw[up] % MOD;
	if (D == 0)
		res = (res + (ll)(pw[n - 1] - 2 + MOD) * pw[m - (n - 1)]) % MOD;
	cout << res;
}


Measured memory_bytes: 3812
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
d = [a[i + 1] - a[i] for i in range(n - 1)]

mod = 1000000007
def pow(x, n):
    ret = 1
    while n > 0:
        if (n & 1) == 1:
            ret = (ret * x) % mod
        x = (x * x) % mod
        n //= 2
    return ret

fac = [1]
inv = [1]
for i in range(1, n + 1):
    fac.append((fac[-1] * i) % mod)
    inv.append(pow(fac[i], mod - 2))

def cmb(n, k):
    if k < 0 or k > n:
        return 0
    return ((fac[n] * inv[k]) % mod * inv[n - k]) % mod

ret = 0
for i in range(n - 1):
    num = (cmb(n, k) - cmb(i + 1, k) - cmb(n - i - 1, k)) % mod
    ret = (ret + d[i] * num) % mod
print(ret)


Measured memory_bytes: 24416
op = [list(map(int, inp.split())) for inp in open(0)]
a = [op[0], op[1], op[2]]
n = int(op[3][0])
b = []
for i in range(n):
  b.append(int(op[4 + i][0]))
  for j in range(3):
    for k in range(3):
      if a[j][k] == b[i]:
        a[j][k] = -1
res = 'No'
for i in range(3):
  if a[0][i] == a[1][i] == a[2][i] == -1:
    res = 'Yes'
  if a[i][0] == a[i][1] == a[i][2] == -1:
    res = 'Yes'
if a[0][0] == a[1][1] == a[2][2] == -1:
  res = 'Yes'
if a[2][0] == a[1][1] == a[0][2] == -1:
  res = 'Yes'
print(res)

Measured memory_bytes: 3064