akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const Int MOD = 1000000007;
struct SegTree {
    int N;
    vector<int> A;
    SegTree(int n) {
        N = 1; while (N < n) N *= 2;
        A.resize(2 * N);
    }
    void add(int idx, int val) {
        idx += N;
        A[idx] = (A[idx] + val) % MOD;
        idx >>= 1;
        while (idx > 0) {
            A[idx] = (A[2*idx+0] + A[2*idx+1]) % MOD;
            idx >>= 1;
        }
    }
    int sum(int L, int R) {
        Int ans = 0;
        L += N, R += N;
        while (L < R) {
            if (L & 1) ans = (ans + A[L++]) % MOD;
            if (R & 1) ans = (ans + A[--R]) % MOD;
            L >>= 1, R >>= 1;
        }
        return ans;
    }
};
int main() {
    Int N, A, B; cin >> N >> A >> B;
    vector<Int> S(N); for (auto &s : S) cin >> s;
    S.insert(begin(S), -2e18);
    SegTree X(N + 1), Y(N + 1); // X[j] : (i, j)
    X.add(0, 1);
    Y.add(0, 1);
    int xm = 0, ym = 0;
    for (int i = 2; i <= N; i++) {
        int t = upper_bound(begin(S), end(S), S[i] - B) - begin(S);
        int xs = X.sum(xm, t);
        int u = upper_bound(begin(S), end(S), S[i] - A) - begin(S);
        int ys = Y.sum(ym, u);
        Y.add(i - 1, xs);
        X.add(i - 1, ys);
        if (S[i] - S[i - 1] < A) xm = i - 1;
        if (S[i] - S[i - 1] < B) ym = i - 1;
    }
    cout << (X.sum(xm, N + 1) + Y.sum(ym, N + 1)) % MOD << '\n';
    return 0;
}

Measured memory_bytes: 3060
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Riffle Swap
// 2012/12/15
public class Main{
	Scanner sc=new Scanner(System.in);

	int n;
	int mod=1000003;
	long[] memo;

	void run(){
		n=sc.nextInt();
		solve();
	}

	void solve(){
		memo=new long[n+1];
		fill(memo, -1);
		rec(n);
		long sum=0;
		for(int i=1; i<=n; i++){
			if(memo[i]>0){
				sum=(sum+memo[i]*(i-1)%mod)%mod;
			}
		}
		println(sum+"");
	}

	long rec(int n){
		if(memo[n]>=0){
			return memo[n];
		}
		if(n==1){
			return memo[1]=2;
		}
		long res=powMod(2, n, mod)-2;
		for(int i=2; i*i<=n; i++){
			if(n%i==0){
				res=(res-rec(i)*i%mod+mod)%mod;
				if(n/i!=i){
					res=(res-rec(n/i)*n/i%mod+mod)%mod;
				}
			}
		}
		return memo[n]=res*powMod(n, mod-2, mod)%mod;
	}

	long powMod(long x, int k, int mod){
		if(k==0){
			return 1;
		}else if((k&1)==0){
			return powMod(x*x%mod, k>>>1, mod);
		}else{
			return x*powMod(x, k-1, mod)%mod;
		}
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 20000
#include <iostream>
#include <algorithm>
using namespace std;
string toString(int x)
{
	string s;
	while(x>0)
	{
		char c=(x%10+'0');
		s+=c;
		x=x/10;
	}
	return s;
}
int main()
{
	int a,b,sum=0;
	cin>>a>>b;
	for(int i=a;i<=b;i++)
	{
		string s=toString(i);
		for(int i=0;i<s.length()/2;i++)
			if(s[i]!=s[s.length()-1-i]){
				goto flag;
			}
		sum++;
		flag:{
			
		};
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
// C - Numbers on a Circle
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);

	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	set<pair<int, int>, greater<pair<int, int> > > s;
	for (int i = 0; i < n; i++) s.insert(make_pair(b[i], i));

	long long ans = 0;
	while (!s.empty()) {
		int i = s.begin()->second;
		s.erase(s.begin());
		int d = b[i] - a[i], t = b[(i + 1) % n] + b[(i - 1 + n) % n];
		if (d != 0 && d < t) {
			ans = -1;
			break;
		}
		ans += d / t;
		b[i] -= d / t * t;
		if (b[i] != a[i]) s.insert(make_pair(b[i], i));
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 11264
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main
{
    private static void dfs(int n, int[][] points, ArrayList<Integer> route, List<Double> result)
    {
        if (route.size() == n) {
            double sum = 0;
            int[] last = null;
            for (int i : route) {
                int[] pos = points[i];
                if (last != null) {
                    sum += Math.sqrt(Math.pow(pos[0] - last[0], 2) + Math.pow(pos[1] - last[1], 2));
                }
                last = pos;
            }
            result.add(sum);
            return;
        }

        for (int i = 0; i < n; i++) {
            if (route.contains(i)) {
                continue;
            }
            ArrayList<Integer> newRoute = new ArrayList<>(route);
            newRoute.add(i);
            dfs(n, points, newRoute, result);
        }
    }

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] points = new int[n][];
        for (int i = 0; i < n; i++) {
            points[i] = new int[] { sc.nextInt(), sc.nextInt() };
        }

        List<Double> result = new ArrayList<>();
        dfs(n, points, new ArrayList<>(), result);

        double sum = 0;
        for (double x : result) {
            sum += x;
        }

        System.out.println(sum / result.size());
    }
}


Measured memory_bytes: 46968
import java.util.Scanner;


public class Main {



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		for (int i=0;i<10000;i++) {
			if(a<=0.08*i && 0.08*i<a+1 && b<=0.1*i && 0.1*i<b+1) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}

}

Measured memory_bytes: 23764
from sys import stdin, stdout
import math
import bisect
import queue

N, K = map(int, stdin.readline().strip().split())

ans = 0

for l in range(K, N + 2):
    fi = ((-1 + l) * l) // 2
    se = ((N + (N - l + 1)) * l) // 2
    ans += se - fi + 1
    ans %= 1000000007
    
stdout.writelines(str(ans) + '\n')


Measured memory_bytes: 69008
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

vector<int> dijkstra(int i, int n, vector<vector<pair<int, int>>> graph) {
  vector<int> d(n, INF);
  d[i] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
  q.push(make_pair(0, i));
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : graph[v]) {
      if (d[x.first] > d[v] + x.second) {
        d[x.first] = d[v] + x.second;
        q.push(pair<int, int>(d[x.first], x.first));
      }
    }
  }
  return d;
}

signed main() {
  int N, M;
  cin >> N >> M;

  vector<vector<pair<int, int>>> graph(N);
  REP(i, M){
    int u, v, d;
    cin >> u >> v >> d;
    u--; v--;
    graph[u].emplace_back(v, d);
    graph[v].emplace_back(u, d);
  }
  REP(i, N-1){
    graph[i+1].emplace_back(i, 0);
  }

  auto dist = dijkstra(0, N, graph);
  if(dist[N-1] == INF) dist[N-1] = -1;

  cout << dist[N-1] << "\n";

  return 0;
}

Measured memory_bytes: 20212
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <climits>
#include <string>
#include <set>
#include <numeric>
#include <bitset>
#include <cmath>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <numeric>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define ll long long

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef  pair<int,int> pii;
typedef vector<pii> vp;
typedef pair<ll, ll> pll;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
vi v;
int ji[100000];

int main() {
	int n;
	scanf("%d", &n);
	v.resize(n, 0);
	memset(ji, 0, sizeof(ji));
	rep(i, 0, n) {
		int tmp;
		scanf("%d", &tmp);
		if(tmp > 0) ji[tmp-1]++;
		ji[tmp]++;
		if(tmp < 99999) ji[tmp+1]++;
	}
	printf("%d\n", *max_element(ji, ji+100000));

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n)  for(ll i=0;i<n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int,int> pii;
int main()
{
	IOS;
	//int t; cin>>t;
	//ll M=pow(10,9)+7;
	int t=1;
	while(t)
	{
		int a; cin>>a;
		int ans=a+a*a+a*a*a;
		cout<<ans<<"\n";
		t--;
	}
	return 0;
}

Measured memory_bytes: 3644
from collections import *
from heapq import*
import sys
input=sys.stdin.readline
d=defaultdict(list)
n=int(input())
 
for s in range(n-1):
    a,b,c=map(int,input().split())
    d[a].append([b,c])
    d[b].append([a,c])
#defaultdict(<class 'list'>, {1: [[2, 1], [3, 1]], 2: [[1, 1], [3, 3]], 3: [[1, 1], [2, 3]]})
 
def DIJKSTRA(point,d):
    cost      = {node:float("inf") for node in d.keys()}
    Q         = []  #頂点のリスト
    cost[point]=0  #開始地点のコストをゼロとする（当たり前
    heappush(Q,(point,cost[point]))
    while Q:
        prefnd,tmpC=heappop(Q)
        if cost[prefnd]<tmpC:
            continue
        for node,c in d[prefnd]:
            altC=c+tmpC
            if cost[node]>altC:
                cost[node]=altC
                heappush(Q,(node,altC))
    return cost
 
q,k=map(int,input().split())
y=DIJKSTRA(k,d)
 
for i in range(q):
    a,b=map(int,input().split())
    print(y[a]+y[b])

Measured memory_bytes: 110044
N, A, B = map(int, input().split())
S = input()

cnt = 0
a, b, c = 0, 0, 0
for s in S :
  if s == 'a' :
    a += 1
    if cnt < A + B :
      cnt += 1
      print('Yes')
    else :
      print('No')
  elif s == 'b' :
    b += 1
    if cnt < A + B and b <= B :
      cnt += 1
      print('Yes')
    else :
      print('No')
  else :
    print('No')


Measured memory_bytes: 52952
#include <iostream>
#define int long long
using namespace std;
int32_t main()
{
  int a,b,k; cin>>a>>b>>k;
  int tmp = min(a,k);
  a -= tmp;
  k -= tmp;
  b -= min(b,k);
  cout<<a<< " "<<b;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
		int H,W;
		Scanner sc=new Scanner(System.in);
		while(true){
			H=sc.nextInt();
			W=sc.nextInt();
			if(H==0&&W==0)break;
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					if((i+j)%2==0){
						System.out.print("#");
					}else System.out.print(".");
				}
				System.out.println("");
			}
			System.out.println("");
		}
    }
}



Measured memory_bytes: 33156
let a, b, c, d = Scanf.sscanf (read_line ()) "%d %d %d %d" @@ fun a b c d -> (a, b, c, d)

let rec loop t a c =
  if t then
    if b >= c then "Yes" else loop false a (c - b)
  else
    if d >= a then "No" else loop true (a - d) c

let () = print_endline @@ loop true a c

Measured memory_bytes: 3732
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


#互いに素なa,bについて、a*x+b*y=1の一つの解[x,y]を出力
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]


#aの逆元(mod M)を求める（aとMは互いに素であることが前提）
def mod_inv(a,M=mod):
    x = extgcd(a,M)[0]
    return (M+x%M)%M


N,M = II()

fact = [1]*(N+100)
for i in range(1,N+100):
    fact[i] = fact[i-1]*i %mod

inv = [1]*(N+100)
for i in range(N+100):
    inv[i] = mod_inv(fact[i])

c = Counter(prime_factorize(M))
ans = 1
for k in c.keys():
    i = c[k]
    temp = fact[N-1+i]*inv[i]*inv[N-1]
    ans *= temp
    ans %= mod

print(ans)

Measured memory_bytes: 42860
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String str = sc.next();
    int b = sc.nextInt();
    if(str.charAt(0) == '+'){
      int tmp = a + b;
      System.out.println(tmp);
    }else{
      int tmp = a - b;
      System.out.println(tmp);
    }
  }
}

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

int main() {
	int n;
	cin >> n;
	vector<pair<double, string>> x(n);
	for (int i = 0; i < n; i++)
		cin >> x[i].first >> x[i].second;
	double sum = 0;
	for (int i = 0; i < n; i++) {
		if (x[i].second == "BTC")
			x[i].first *= 380000;
		sum += x[i].first;
	}
	cout << sum << endl;
	return 0;
}

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

int main()
{
    int N, K, answer = 1;
    cin >> N >> K;

    for (int count = 0; count < N; count++)
    {
        if (answer * 2 > answer + K)
        {
            answer += K;
        }
        else
        {
            answer *= 2;
        }
    }

    cout << answer << endl;
}

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

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var a = cin.nextInt();
            var b = cin.nextInt();
            var c = cin.nextInt();
            var d = cin.nextInt();
            Console.WriteLine(Math.Max(0,Math.Min(b,d) - Math.Max(a,c)));
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11220
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            while(sc.hasNext()) {
                int n = sc.nextInt();
                if(n == 0)break;
                
                String f = "";
                int right = 0;
                int left = 0;
                int cnt = 0;
                int step = 0;
                for(int i=1;i<=n;i++) {
                	 f = sc.next();
	                 if(f.equals("lu")) {
	               		 left += 1;
	               		 step++;
	               	 }
	               	 else if(f.equals("ru")) {
	               		 right += 1;
	               		 step++;
	               	 }
	               	 else if(f.equals("ld")) {
	               		 left -= 1;
	               		 step--;
	               	 }
	               	 else {
	               		 right -= 1;
	               		 step--;
	               	 }
	               	 if(left==right && step==2 || step==-2) {
	               		 cnt++;
	               		 step = 0;
	               	 }
                }
                System.out.println(cnt);
            }
        }
    }
}





Measured memory_bytes: 37604
function Main(input){ 
  var inputs = input.split("/");
  for(i=0;i<=2;i++){
    inputs[i] = parseInt(inputs[i],10);
  }
if(inputs[0]<=2019){
  if(inputs[1]<=4){
    if(inputs[2]<=30){
      console.log("Heisei")
    }else{
      console.log("TBD");
    }
  }else{
    console.log("TBD");
  }
}else{
  console.log("TBD");
}

  
}
    Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <set>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < n-1; i++)
    {
        vector<char> mae(i+1),ushiro(n-i-1);
        for(int j = 0; j <= i; j++)
        {
            mae[j] = s[j];
        }
        for(int k = i+1; k < n; k++)
        {
            ushiro[k-i-1] = s[k];
        }
        sort(mae.begin(),mae.end());
        sort(ushiro.begin(), ushiro.end());
        set<char> m(mae.begin(),mae.end());
        set<char> u(ushiro.begin(),ushiro.end());
        int count = 0;
        for(char cm : m)
        {
            for(char cu : u)
            {
                if (cm == cu) {
                    count++;
                }
            }
        }
        ans = max(ans, count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct st{
    long long w,c;
    
};
int main()
{
  long long t,n,i,j,m,k;
  cin>>n>>k;
 struct st s[n];
  for(i=0;i<n;i++){
    cin>>s[i].w;
    cin>>s[i].c;
  }
 long long d[n+1][k+1];
 for(i=0;i<=k;i++)
 d[0][i]=0;
 for(j=0;j<=n;j++)
 d[j][0]=0;
 for(i=1;i<=n;i++)
 {
     for(j=1;j<=k;j++)
     {
         if(j>=s[i-1].w)
         {
             d[i][j]=max(d[i-1][j-s[i-1].w]+s[i-1].c,d[i-1][j]);
         }
         else
         d[i][j]=d[i-1][j];
     }
 }
 cout<<d[n][k];
  return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int sigma(int n){
    int sum=0;
    for (int i=1; i<=(n); i++){
        sum+=i;
    }
    return sum;
}
int distance(int yo,int xo,int yi,int xi){
    return (yo-yi)*(yo-yi)+(xo-xi)*(xo-xi);
}
signed main(){
    int N;
    cin >> N;
    int a[N];
    rep(i,N){
        cin >> a[i] ;
    }
    int ref[N]={0};
    reps(i,N){
        ref[i-1] = i;
    }
    //if((N==1)&&(a[0]==1)){
    //    cout << 0 << endl;
    //    return 0;
    //}
    int j=0,mem=0,count=0;
    rep(i,N){
        if(a[i]==ref[j]){
            count += (i-mem);
            mem = i+1;
            j++;
        }
        else if(i==(N-1)){
            count += (i-mem+1);
        }
    }
    if(j == 0){
        cout << -1 << endl;
        return 0;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int n,k;
    cin>>n>>k;
    k--;
    string s;
    cin>>s;
    if(s.at(k)=='A')s.at(k)='a';
    else if(s.at(k)=='B')s.at(k)='b';
    else if(s.at(k)=='C')s.at(k)='c';
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    ll n,k;cin >>n >> k;
    n %= k;
    n = min(n,abs(n-k));
    cout << n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll D;
  cin >> D;

  cout << "Christmas ";
  if(D <= 24){
    rep(i, 25 - D)
      cout << "Eve ";
  }

  cout << "\n";
  
  return 0;
}


Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s.size()==2)
    cout << s << endl;
  else{
    char x=s[0];
    s[0]=s[2];
    s[2]=x;
    cout << s << endl;
  }
}


Measured memory_bytes: 256
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

char grid[10][10];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int h,w,total(0);
    cin >> h >> w;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cin >> grid[i][j];
            if(grid[i][j]=='#')total++;
        }
    }
    if(total==h+w-1&&grid[0][0]=='#')cout << "Possible" ;
    else cout << "Impossible" ;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    xor = 0

    for ai in a:
        xor ^= ai

    tmp = xor
    ans = list()

    for ai in a:
        xor ^= ai
        ans.append(xor)
        xor = tmp

    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 40884
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m;
  cin>>n>>m;
  
  //n人分の学生の座標を取得
  vector<int> a(n);
  vector<int> b(n);
  for (int i=0;i<n;i++){
  	cin>>a.at(i)>>b.at(i);
  }
  
  //m個のチェックポイントの座標を取得
  vector<int> c(m);
  vector<int> d(m);
  for (int i=0;i<m;i++){
  	cin>>c.at(i)>>d.at(i);
  }
  
   for (int i=0;i<n;i++){
     	int ans=0,kyori=0;
     	
     for (int j=0;j<m;j++){
       	
        if(j==0){
        	kyori=abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j));
            ans=1;
        }else{
        	if(kyori>abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j))){
            	kyori=abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j));
              	ans=j+1;
            }
        }
      } 
  	cout<<ans<<endl;
  }  
}


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

using namespace std;

int main() {
    string s1,s2;
    cin>>s1>>s2;
    if(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]) {
        cout<<"YES"<<endl;
    } else {
        cout<<"NO"<<endl;
    }
    return 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;

void solve(std::vector<std::vector<long long>> A, long long N, std::vector<long long> b){
    auto ok = []() {
        cout << "Yes" << endl;
    };
    rep(y,0,3) {
        bool isValid = true;
        rep(x,0,3) {
            if (find(all(b), A[y][x]) == b.end()) {
                isValid = false;
                break;
            }
        }
        if (isValid) {
            ok();
            return;
        }
    }
    rep(x,0,3) {
        bool isValid = true;
        rep(y,0,3) {
            if (find(all(b), A[y][x]) == b.end()) {
                isValid = false;
                break;
            }
        }
        if (isValid) {
            ok();
            return;
        }
    }
    bool isValid = true;
    rep(y,0,3) {
        if (find(all(b), A[y][2-y]) == b.end()) {
            isValid = false;
            break;
        }
    }
    if (isValid) {
        ok();
        return;
    }
    isValid = true;
    rep(y,0,3) {
        if (find(all(b), A[y][y]) == b.end()) {
            isValid = false;
            break;
        }
    }
    if (isValid) {
        ok();
        return;
    }
    cout << "No" << endl;
}

signed main(){
    std::vector<std::vector<long long>> A(3, std::vector<long long>(3));
    for(int i = 0 ; i < 3 ; i++){
        for(int j = 0 ; j < 3 ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    long long N;
    scanf("%lld",&N);
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&b[i]);
    }
    solve(std::move(A), N, std::move(b));
    return 0;
}


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

int main(){
    int H, W;
    cin >> H >> W;
    string S[H+10];
    int tmp[H+10][W+10];
    string ans[H+10];
    for(int i = 0; i <= W + 1; ++i){
        tmp[0][i] = 0;
        tmp[H+1][i] = 0;
    }
    for(int i = 1; i <= H; ++i){
        tmp[i][0] = 0;
        tmp[i][W+1] = 0;
    }
    for(int i = 1; i <= H; ++i){
        cin >> S[i];
        for(int j = 0; j < W; ++j){
            if(S[i].substr(j,1)=="#") tmp[i][j+1] = 1;
            else  tmp[i][j+1] = 0;
        }
    }
    
    for(int i = 1; i <= H; ++i){
        ans[i-1] = "";
        for(int j = 1; j <= W; ++j){
            int count = tmp[i-1][j-1] + tmp[i-1][j] + tmp[i-1][j+1] + tmp[i][j-1] + tmp[i][j+1] + tmp[i+1][j-1] + tmp[i+1][j] + tmp[i+1][j+1];
            if(tmp[i][j]==1) ans[i-1] += "#";
            else ans[i-1] += to_string(count);
        }
    }
    for(int i = 0; i < H; ++i) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)#必要に応じて

class UnionFind:#再帰上限に引っかかることがあるので
    def __init__(self,n):
        self.l=list(range(n))
        self.n=n
        self.size=[1 for i in range(n)]
    def find(self,x):
        if self.l[x]==x:
            return x
        self.l[x]=self.find(self.l[x])
        return self.l[x]
    def union(self,x,y):
        if x==y:return
        if self.size[x]<self.size[y]:
            return self.union(y,x)
        a,b=self.find(x),self.find(y)
        if self.l[a]!=b:
            self.l[a]=b
            self.size[b]+=self.size[a]
    def isSame(self,x,y):
        return self.find(x)==self.find(y)
    def getsize(self,x):
        return self.size[x]

n,m=map(int,input().split())
u=UnionFind(n)
for i in range(m):
    u.union(*map(lambda z:int(z)-1,input().split()))
ans=1
for i in range(n):
    ans=max(ans,u.size[i])
    #print("size",u.size[i],i)
print(ans)

Measured memory_bytes: 24888
h,w=[int(x) for x in input().rstrip().split()]
l=[list(input()) for i in range(h)]
move=[[1,0],[-1,0],[0,-1],[0,1]]
def bfs(x,y):
  stack=[[x,y]]
  done=[[False]*w for i in range(h)]
  dist=[[0]*w for i in range(h)]
  max_val=0
  while(stack):
    nx,ny=stack.pop(0)
    done[ny][nx]=True
    for dx,dy in move:
      mx=nx+dx
      my=ny+dy
      if not(0<=mx<=w-1) or not(0<=my<=h-1) or done[my][mx]==True or l[my][mx]=="#":
        continue
      done[my][mx]=True
      dist[my][mx]=dist[ny][nx]+1
      max_val=max(max_val,dist[my][mx])
      stack.append([mx,my])
  return max_val

ans=0
for i in range(w):
  for j in range(h):
    if l[j][i]!="#":
      now=bfs(i,j)
      ans=max(ans,now)
print(ans) 

Measured memory_bytes: 3188
#include<iostream>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    ll N;
    cin >> N;
    ll ans = 1;
    for (ll i = 1; i <= N; i++) {
        ans = ((ans % MOD) * (i % MOD)) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = list(input())

rsp = {"r":p, "s":r, "p":s}
ans = 0
for i in range(n):
  if i < k: ans += rsp[t[i]]
  else:
    if t[i] != t[i-k]: ans += rsp[t[i]]
    else: t[i] = "a"
print(ans)

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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;

int main(){
    int s,w;
    std::cin >> s>>w;
    if(s<=w)std::cout << "unsafe" << std::endl;
    else std::cout << "safe" << std::endl;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll k,ans=0;
    scanf("%lld",&k);
    // ll [n];
    rep(i,1,k+1){
        rep(j,1,k+1){
            ll a=gcd(i,j);
            rep(l,1,k+1){
                ans+=gcd(a,l);
            }
        }
    }

    
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1736
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    int r,g;
    cin>>r>>g;
    cout<<2*g-r<<endl;
    return 0;  
    
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	sum := 0
	x := -1
	for i := 1; i <= n; i++ {
		sum += i
		if sum >= n {
			x = i
			break
		}
	}

	remove := sum - n
	for i := 1; i <= x; i++ {
		if i != remove {
			fmt.Println(i)
		}
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll MOD=1e9+7;
#define endl '\n'
#define F first
#define S second
#define pb push_back
const double PI = 3.141592653589793238460;
  void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
    #endif
}
int dp[100005][4];int a[100005][4];int  n,k;
int  Vac(int day, int flag)
{
  if(day>=n)return 0;
  if(dp[day][flag]!=-1)
    return dp[day][flag];
  int maxi=0;
  if(flag==0)
  {
    maxi=max(maxi,a[day][1]+Vac(day+1,1));
     maxi=max(maxi,a[day][2]+Vac(day+1,2));
      maxi=max(maxi,a[day][3]+Vac(day+1,3));
  }
  else if(flag==1)
  {
    maxi=max(maxi,a[day][2]+Vac(day+1,2));
     maxi=max(maxi,a[day][3]+Vac(day+1,3));

  }
    else if(flag==2)
  {
    maxi=max(maxi,a[day][1]+Vac(day+1,1));
     maxi=max(maxi,a[day][3]+Vac(day+1,3));

  }
    else
  {
    maxi=max(maxi,a[day][1]+Vac(day+1,1));
     maxi=max(maxi,a[day][2]+Vac(day+1,2));

  }
  return dp[day][flag]=maxi;


  


}
  
 

int  main()
{
  c_p_c();
 cin>>n;
 memset(dp,-1,sizeof(dp));

 for(int i=0;i<n;i++)
 {
  cin>>a[i][1]>>a[i][2]>>a[i][3];
 }

  cout<<Vac(0,0);

 

  return 0;

}

Measured memory_bytes: 14484
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k,s;
	cin>>n>>k>>s;
	vector<int>ans;
	rep(i,k)ans.push_back(s);
	rep(i,n-k)ans.push_back((s==1?2:s-1));
	rep(i,n-1)cout<<ans[i]<<" ";
	cout<<ans[n-1]<<endl;
}

Measured memory_bytes: 1912
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

int main()
{
	int  a = 0, b = 0;
	int reverse = 0;
	int remaind, tmp;
	int ans = 0;

	std::cin >> a >> b;

	for (int i = 0; i < b - a + 1; i++) {
		tmp = a + i;
		while (tmp != 0) {
			remaind = tmp % 10;
			reverse = reverse * 10 + remaind;
			tmp /= 10;
		}
		if (reverse == a + i) {
		
			ans++;
		}
		remaind = 0;
		reverse = 0;
		tmp = 0;


	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
class Queue:
    def __init__(self, data=[]):
        self.data = data

    def enqueue(self, x):
        self.data.append(x)  # 末尾に追加する

    def dequeue(self):
        return self.data.pop(0)  # 先頭を取り出す

    def is_Empty(self):  # 空であればTrueを返す
        if len(self.data) == 0:
            return True
        else:
            return False


H, W = map(int, input().split())  # H行, W列

gridgraph = [list(input()) for _ in range(H)]

black_count = 0
for i in range(H):
    for j in range(W):
        if gridgraph[i][j] == '#':
            black_count += 1

flag = [[False] * W for _ in range(H)]
counter = [[0] * W for _ in range(H)]
counter[0][0] = 1
flag[0][0] = True
q = Queue()

q.enqueue((0, 0))

adjacent = [(1, 0), (0, 1), (-1, 0), (0, -1)]  # 遷移先を網羅する
while not q.is_Empty():
    cy, cx = q.dequeue()
    for dy, dx in adjacent:
        if cy+dy >= H or cy+dy < 0 or cx+dx >= W or cx+dx < 0:
            continue
        if flag[cy+dy][cx+dx] or gridgraph[cy+dy][cx+dx] == '#':
            continue
        counter[cy+dy][cx+dx] = counter[cy][cx] + 1
        flag[cy+dy][cx+dx] = True
        q.enqueue((cy+dy, cx+dx))

# print(flag)
if flag[H-1][W-1]:
    print(H*W - counter[H-1][W-1] - black_count)
else:
    print(-1)


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

int main(){
    int N, Q;
    cin >> N >> Q;
    lint a[N];
    cins(a, a + N);
    sort(a, a + N);
    for(int i = 0; i < Q; i++){
        int l, r;
        cin >> l >> r;
        cout << int(upper_bound(a, a + N, r) - lower_bound(a, a + N, l)) << endl;
    }
}



Measured memory_bytes: 3948
// C++ 14
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;

#define MAX_N 301
#define MAX_Q (301*300)
#define MAX_C 1000000001

Int N, M, Q;
vector<Int> S(MAX_Q, -1), T(MAX_Q, -1);
ll L;

ll G[MAX_N][MAX_N];
ll COUNT[MAX_N][MAX_N];

void apsp(ll g[MAX_N][MAX_N]) {
  loop(k,0,N) {
    loop(u,0,N) {
      if (g[u][k] == MAX_C) continue;
      loop(v,0,N) {
        if (g[k][v] == MAX_C) continue;
        g[u][v] = min(g[u][v], g[u][k] + g[k][v]);
      }
    }
  }
}

void dump(ll g[MAX_N][MAX_N]) {
  loop(n,0,N) {
    loop(m,0,N) {
      cout << g[n][m] << " ";
    }
    cout << endl;
  }
}

void solve() {
  apsp(G);
  loop(n,0,N) {
    loop(m,0,N) {
      if (G[n][m] <= L) COUNT[n][m] = 1;
    }
  }
  apsp(COUNT);
  loop(q,0,Q) {
    if (COUNT[S[q]][T[q]] == MAX_C) cout << -1 << endl;
    else cout << COUNT[S[q]][T[q]] - 1 << endl;
  }
}

int main() {
  Int a, b;
  ll c;
  cin >> N >> M >> L;
  loop(n,0,N) {
    loop(m,0,N) {
      G[n][m] = COUNT[n][m] = (n == m) ? 0 : MAX_C;
    }
  }
  
  loop(m,0,M) {
    cin >> a >> b >> c;
    G[a-1][b-1] = c;
    G[b-1][a-1] = c;
  }
  
  cin >> Q;
  loop(q,0,Q) {
    cin >> S[q] >> T[q];
    S[q]--;
    T[q]--;
  }
  
  solve();
}

Measured memory_bytes: 2688
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	vector<long long> res(1,0);
	vector<pair<int, int> > u;
	int N; scanf ("%d",&N); while (N--){
		int h,p; scanf ("%d %d",&h,&p);
		u.push_back({h,p});
	}
	sort(u.begin(),u.end(),[](const pair<int, int> &a, const pair<int, int> &b){return a.first+a.second<b.first+b.second;});
	for (auto &v : u){
		int h = v.first, p = v.second;
		for (int i=(int)res.size()-1;i>=0;i--){
			if (res[i] <= h){
				if (i + 1 == res.size()) res.push_back(res[i] + p);
				else if (res[i+1] > res[i] + p) res[i+1] = res[i] + p;
			}
		}
	}

	printf ("%d\n",res.size()-1);
	return 0;
}

Measured memory_bytes: 384