akhauriyash/Code-Regression huggingface dataset:
n,k,q=map(int,input().split())
s=[int(input()) for i in range(q)]

list_score=[0]*n

for i in range(q):
  list_score[s[i]-1]+=1
for j in range(n):
  if (k-q+list_score[j])>0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 8636
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n, cnt  = 0;
    cin >> n;
    vector<int> p(n);
    for(int i = 0;i < n;i++){
        cin >> p[i];
    }

    for(int i = 0;i < n;i++){
        if(p[i] != i + 1){
            cnt++;
        }
    }

    if(cnt == 2 || cnt == 0){
        cout << "YES";
    }
    else{
        cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
//#include<array>
#include<algorithm>
#include<queue>
#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
//#include<bitset>
//#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//配列,座標
/*array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
array<int, 4>dir_x2 = { 0,0,1,-1 };
array<int, 4>dir_y2 = { 1,-1,0,0 };
char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };*/

//Union Find
/*class UnionFind {
public:
	vector<int>data;
	UnionFind(int size) :data(size, -1) {};
	bool unionset(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x]) {
				swap(x, y);
			}
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}
	bool findset(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};*/

//最大公約数,最小公倍数
/*LLI gcd(LLI x, LLI y) {
	LLI  r;
	if (x < y) {
		swap(x, y);
	}
	r = x % y;
	while (r != 0) {
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}
LLI lcm(LLI x, LLI y) {
	return x / gcd(x, y) * y;
}*/

//組み合わせ
/*long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; i--) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; i++) {
		ans = ans / i;
	}
	return ans;
}
long nHr(int n, int r) {
	n = n + r - 1;
	return nCr(n, r);
}*/

//素数判定
/*bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}*/

//桁数
/*LLI GetDigit(LLI num) {
	LLI digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}*/

//サンプル
/*const int n_max = 8;
array<array<bool, n_max>, n_max>graph;
int dfs(int v,int N,array<bool,n_max>visited) {
	int ret = 0;
	bool all_visited = true;
	for (int i = 0; i < N;i++) {
		if (visited[i] == false) {
			all_visited = false;
		}
	}
	if (all_visited) {
		return 1;
	}
	for (int i = 0; i < N;i++) {
		if (graph[v][i] == false) {
			continue;
		}
		if (visited[i] == true) {
			continue;
		}
		visited[i] = true;
		ret += dfs(i,N,visited);
		visited[i] = false;
	}
	return ret;
}*/

//サンプル
/*vector<vector<int>>sub;
int dfs(int id) {
	if (sub[id].size() == 0) {
		return 1;
	}
	int minP = (int)1e9;
	int maxP = 0;
	for (int i : sub[id]) {
		int P = dfs(i);
		minP = min(minP, P);
		maxP = max(maxP, P);
	}
	return minP + maxP + 1;
}*/

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl
//cout << "Yes" << endl;
//cout << "No" << endl;



int main(void) {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
std::string S;
int main(void){
    std::cin >> S;

    auto memo = std::vector<int>(CHAR_MAX+1, 0);
    for(auto it=S.begin(), _END=S.end(); it!=_END; ++it){
        memo[*it]++;
    }

    bool f = false;
    for(char c = 'a'; c <= 'z'; ++c){
        if(memo[c] == 0){
            std::cout << c << std::endl;
            f = true;
            break;
        }
    }
    if(!f){
        std::cout << "None" << std::endl;
    }
}


Measured memory_bytes: 512
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// IN THE NAME OF GOD
#include <bits/stdc++.h>

#define ff first
#define endl '\n'
#define ss second
#define ll long long
#define pb push_back
#define ld long double
#define pii pair <int, int>
#define pll pair <long long, long long>

using namespace std;
const int N = 1e5 + 15;
int cnt1[N], cnt2[N], X = 0, XX = -1, Y = 0, P = 0, PP = -1, Q = 0, n, x, y;
int main(){
  //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for(int i = 0; i < n / 2; i++){
    cin >> x >> y;
    cnt1[x]++;
    cnt2[y]++;
  }
  for(int i = 1; i < N; i++){
    if(cnt1[i] > X){
      Y = X;
      X = cnt1[i], XX = i;
    }
    else if(cnt1[i] > Y) Y = cnt1[i];

    if(cnt2[i] > P){
      Q = P;
      P = cnt2[i], PP = i;
    }
    else if(cnt2[i] > Q) Q = cnt2[i];
  }
  if(X > 0 && Y > 0 && P > 0 && Q > 0){
    if(XX != PP) return cout << n - X - P << endl, 0;
    else return cout << n - max(X + Q, Y + P) << endl, 0;
  }
  if(X > 0 && Y > 0 && P > 0 && Q <= 0){
    if(XX != PP) return cout << n - X - P << endl, 0;
    else return cout << n - Y - P << endl, 0;
  }
  if(X > 0 && Y <= 0 && P > 0 && Q > 0){
    if(XX != PP) return cout << n - X - P << endl, 0;
    else return cout << n - X - Q << endl, 0;
  }
  if(XX != PP) return cout << n - X - P << endl, 0;
  return cout << n / 2 << endl, 0;
}
//programmer: a_h_k_81
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] ab = str.split(" ");
		int a = Integer.parseInt(ab[0]);
		int b = Integer.parseInt(ab[1]);

		if(a+b < 10){
			System.out.println(a+b);
		}else{
			System.out.println("error");
		}


	}

}


Measured memory_bytes: 21204
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a[] = new int[5];
		for(int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		int k = sc.nextInt();
		int flag = 0;
		for(int i = 0; i < a.length-1; i++) {
			for(int j = i; j < a.length; j++) {
				if(a[i]-a[j] > k || a[j] - a[i] > k) {

					flag++;
				}
			}
		}

		if(flag != 0) {
			System.out.println(":(");
		}else {
			System.out.println("Yay!");
		}
		
	}
}


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

using namespace std;

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

	if(x>=400 && x<=599)
		cout<<8<<endl;
	else if(x>=600 && x<=799)
		cout<<7<<endl;
	else if(x>=800 && x<=999)
		cout<<6<<endl;
	else if(x>=1000 && x<=1199)
		cout<<5<<endl;
	else if(x>=1200 && x<=1399)
		cout<<4<<endl;
	else if(x>=1400 && x<=1599)
		cout<<3<<endl;
	else if(x>=1600 && x<=1799)
		cout<<2<<endl;
	else if(x>=1800 && x<=1999)
		cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int n,num=0;
int main(){
	cin>>n;
	int ans=0;
	while (n--){
		int x;
		cin>>x;
		if (x>=num) ans++;
		num=max(num,x);
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <cmath>
#include <iomanip>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
const int MOD = 1000000007;

void add (int & a, int b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}

int mul (int a, int b) {
    return (int64) a * b % MOD;
}

vector<vector<int>> g;


// first = white, second = black
pair<int, int> Rec (int x, int p) {
    pair<int, int> res = {1, 1};
    int sons = 0;
    for (auto v : g[x]) {
        if (v != p) {
            sons++;
            auto cur = Rec(v, x);
            
            res.first = mul(res.first, cur.first + cur.second);
            res.second = mul(res.second, cur.first);    
        }
    }

    return res;
}

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

    int N;
    cin >> N;
    g.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    auto res = Rec(0, 0);

    cout << (res.first + res.second) % MOD << "\n"; 

    return 0;
}


Measured memory_bytes: 12672
def cal_water(floods):
    fstack = []
    astack = []
    i = 0
    for flood in floods:
        if flood == '\\':
            fstack.append(i)
        elif flood == '/' and len(fstack) > 0:
            s = fstack.pop(-1)
            area = (i - s) * 1
            while len(astack) > 0 and astack[-1][0] > s:
                _, a = astack.pop(-1)
                area += a
            astack.append((s, area))   
        else:
            pass
        i += 1
    
    tot = 0
    tot_area = 0
    out = ''
    while len(astack) > 0:
        _, area = astack.pop()
        tot += 1
        tot_area += area
        out = ' ' + str(area) + out
    
    print(tot_area)
    print(str(tot) +  out)

if __name__ == '__main__':
    floods = input()
    cal_water(floods)


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

#include <iostream>


#define MOD 1000000007

typedef unsigned long long ull;
typedef long long ll;

using namespace std;
auto f=[]()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
};


int main()
{
	f();
	string p;cin>>p;
	list<char> s(p.begin(),p.end());


	int q;cin>>q;
	int rc=0;
	char prev='R';
	while(q--)
	{
		int t;cin>>t;
		if(t==1)
			rc++;
		else{
			int pl;cin>>pl;
			char nch;cin>>nch;
			if(rc%2==1){

				//s.reverse();
				if(prev=='R')
					prev='L';
				else
					prev='R';
			}
			
			if(pl==1 )
			{
				if(prev=='R')
					s.push_front(nch);
				else
					s.push_back(nch);
			}
			else
			{
				if(prev=='R')
					s.push_back(nch);
				else
					s.push_front(nch);
			}

			rc=0;
		}

		//cout<<prev<<'\n';
		//for(auto it=s.begin();it!=s.end();++it)
		//	cout<<*it;

		//cout<<'\n';
	}


	//cout<<"Count: "<<rc<<" Direction: "<<prev<<'\n';
	if((prev=='L' && rc%2==0) || (prev=='R' && rc%2==1))
		s.reverse();
//	if(rc%2==1)
//		s.reverse();
	for(auto it=s.begin();it!=s.end();++it)
		cout<<*it;

	cout<<'\n';

	return 0;
}


Measured memory_bytes: 10064
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

#define CMAX 30
using namespace std;


int cost[CMAX][CMAX];
int initial[CMAX][CMAX];
vector<vector<int> > allCon;
vector<vector<int> > allPer;


// n!
void foreach_permutation(int n)
{
    vector<int> indexes(n, 0);
    for (int i = 0; i < n; i++) indexes[i] = i;
    do {
        allPer.push_back(indexes);
    } while (std::next_permutation(indexes.begin(), indexes.end()));
}

void recursive_comb(vector<int> &indexes, int s, int rest)
{
    if(rest == 0){
        allCon.push_back(indexes);
    }else{
        if(s < 0){
            return;
        }
        recursive_comb(indexes, s - 1, rest);
        indexes[rest - 1] = s;
        recursive_comb(indexes, s - 1, rest - 1);
    }
}

//nCk
void foreach_comb(int n, int k){
    vector<int> indexes(k, 0);
    recursive_comb(indexes, n-1, k);
}

int main(void)
{
    vector<vector<int> >  gp(3, vector<int>(30, 0));
    int n,c;
    cin >>n >>c;
    for(int i = 0; i < c; i++){
        for(int j = 0; j < c; j++){
            cin >>cost[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            int tmp;
            cin >>tmp;
            int r = (i+1+j+1)%3;
            gp[r][tmp-1]++;
        }
    }

    int minCost = INT_MAX;
    foreach_comb(c, 3);
    foreach_permutation(3);

    for(int i = 0; i < allCon.size(); i++){
        for(int j = 0; j < allPer.size(); j++){
            int currentCost = 0;
            for(int k = 0; k < allPer[j].size(); k++){
                int afterColor = allCon[i][allPer[j][k]];
                for(int m = 0; m < gp[k].size(); m++){
                    currentCost += cost[m][afterColor] * gp[k][m];
                }
            }
            minCost = min(minCost, currentCost);
        }
    }

    printf("%d\n", minCost);

    return 0;
}

Measured memory_bytes: 512
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
data=[0]*60
for u in a:
    for i in range(60):
        if (u>>i)&1==1:
            data[i]+=1
lst=[1]*60
for i in range(1,60):
    lst[i]=lst[i-1]*2%mod
    
ans=0
for i in range(60):
    ans=(ans+data[i]*(n-data[i])*lst[i])%mod
print(ans)

Measured memory_bytes: 122936
#include <iostream>


int main() {
    std::string s;
    long long int k;
    std::cin >> s >> k;
    char ans = '1';
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != '1') {
            if (k > i) {
                ans = s[i];
                break;
            }
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
N,M,X=map(int,input().split())
CA=[list(map(int,input().split())) for _ in range(N)]
max_=10**16
ans=max_
for bit in range(2**N):
  check=[0]*M
  ans_=0
  for i in range(N):
    if bit>>i&1:
      ans_+=CA[i][0]
      for j in range(M):
        check[j]+=CA[i][j+1]
  if all([k>=X for k in check]):
    ans=min(ans,ans_)
print(ans if ans!=max_ else -1)


Measured memory_bytes: 9196
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var a,b,c int
    fmt.Scan(&a,&b,&c)
    ans := min32(b/a,c)
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
const int M = 1000005;
int a[M];
using namespace std;
int main(){
	int n,j,i,k=0;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=n;i++){
		if(a[i]==i){
			int t=a[i];a[i]=a[i+1];a[i+1]=t;
			k++;
		} 
	} 
	cout<<k;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  vector<vector<ll> > B(N, vector<ll>(2));

  rep(i, 0, N){
    B[i][0] = -1;
    B[i][1] = 0;
  }

  ll n=0;
  rep(i, 0, N){
    ll tmp;
    cin >> tmp;
    if(tmp!=0 && B[n][0]==0){
      n++;
    }
    B[n][0] = tmp;
    B[n][1]++;
    if(tmp!=0){
      n++;
    }
  }
  if(n < N){
    if(B[n][0]==0){
      ++n;
    }
  }


  ll l=0;
  ll count=0;
  rep(i, 0, n){
    count += (B[i][1]*(B[i][1]+1))/2;
    rep(j, 0, i-l){
      if((B[i-j-1][0]^B[i][0]) == (B[i-j-1][0]+B[i][0])){
        count += B[i-j-1][1]*B[i][1];
      }else{
        l = i-j;
        break;
      }
    }
  }

  cout << count << "\n";

  return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    int cur = 0;
    int flag = 0;
    int ans = 0;
    for (char c : s)
    {
        if (c == 'R')
        {
            cur++;
            cur %= 4;
            flag |= (1 << cur);
            if (cur == 0)
            {
                if (flag == 15)
                {
                    ans++;
                }
                flag = 0;
            }
        }
        else
        {
            cur += 3;
            cur %= 4;
            // flag |= (1 << cur);
            if (cur == 0)
            {
                flag = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
	int n,k;
	cin>>k>>n;
	vector<int> ar(2*k),prefix(2*k);
	for(int i=0;i<n;i++)
	{
		int temp;
		cin>>temp;
		temp%=k;
		ar[temp]=1;
		ar[temp+k]=1;
	}
	prefix[0]=ar[0];
	for(int i=1;i<2*k;i++)
		prefix[i]=prefix[i-1]+ar[i];
	// for(auto i:prefix)
	// 	cout<<i<<" ";
	// cout<<"\n";
	int ans=1e13;
	// ans,min length
	map<int,int> mp;
	for(int i=0;i<2*k;i++)
	{
		mp[prefix[i]]=i;
		if(prefix[i]>=n && mp.count(prefix[i]-n))
			ans=min(ans,i-mp[prefix[i]-n]);
	}
	//ans=min(ans,k-ans);
	cout<<ans-1;
}
int32_t main()
{
    //_READ
    int t;
    t=1;
    while(t--)
        solve();
    return 0;
}
/*
===FOR N-Dimensional Vector===
https://codeforces.com/blog/entry/76149
g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined a.cpp -o a -D_GLIBCXX_DEBUG
*/

Measured memory_bytes: 56448
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] longArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long A = longArray[0];
            long B = longArray[1];
            long K = longArray[2];

            if (A + B <= K)
            {
                Console.WriteLine(0 + " " + 0);
            }
            else if(A <= K)
            {
                B = B - (K - A);
                A = 0;
                Console.WriteLine(A + " " + B);
            }
            else
            {
                Console.WriteLine(A - K + " " + B);
            }
        }
    }
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 27996
N, M = map(int, input().split())

begin = 0 if N == 1 else 10**(N-1)
end = 10**N

result = [set() for _ in range(M)]
ans_set = set(range(begin, end))
for m in range(M):
    s, c = map(int, input().split())
    for n in range(begin, end):
        n_str = "0" + str(n)
        if n_str[s] == str(c):
            result[m].add(n)
    ans_set &= result[m]

ans_list = sorted(list(ans_set))
if len(ans_list) == 0:
    print(-1)
else:
    print(ans_list[0])

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] S = scanner.nextLine().split("");
        int countA = 0;
        int countB = 0;
        for(int x = 0; x<3; x++){
            if(S[x].equals("A")){
                countA++;
            }else{
                countB++;
            }
        }
    
        if(countA == 2 || countB==2){
            System.out.println("Yes");
        }else{
            System.out.print("No");
        }




    }

}


Measured memory_bytes: 22612
using System;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
			for( var i = 1; i <= 9; i++)
			{
				for( var j = 1; j <= 9; j++)
				{
					Console.WriteLine (i+"x"+j +"=" + i*j);
				}
			}
			Console.ReadLine ();
        }
    }
}



Measured memory_bytes: 9052
N,M = map(int, input().split())
red = [0 for i in range(N)]
cnt = [1 for i in range(N)]
red[0] = 1
for i in range(M):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    if red[x] > 0:
        if cnt[x] >= 2:
            cnt[x] -= 1
            cnt[y] += 1
            red[y] = 1
        else:
            cnt[x] -= 1
            cnt[y] += 1
            red[x] = 0
            red[y] = 1
    else:
        cnt[x] -= 1
        cnt[y] += 1

ans = 0
for i in range(N):
    if red[i] > 0:
        ans += 1

print(ans)

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

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

signed main() {
  int N; cin >> N;
  int ans = 0;
  int minusCount = 0;
  int minNum = INF_INT;
  rep(i, N) {
    int a;
    cin >> a;
    if(a < 0){
      minusCount++;
      a = -a;
    }
    chmin(minNum,a);
    ans += a;
  }
  PRINT(ans)
  PRINT(minNum)
  PRINT(minusCount)
  if(minusCount%2 == 1){
    ans -= 2*minNum;
  }

  cout << ans << endl;
}

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

const int N = 100000 + 10;

int x, y, n;

int pos(int a, int b) {
  if (b == 0) return a;
  if (a == x) return b + x;
  if (b == y) return 2 * x + y - a;
  if (a == 0) return 2 * x + 2 * y - b;
  return -1;
}

int main() {
  scanf("%d%d%d", &x, &y, &n);
  std::vector<std::pair<int, int>> pool;
  for (int i = 1; i <= n; ++i) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    int a = pos(x1, y1), b = pos(x2, y2);
    if (a == -1 || b == -1) continue;
    if (a > b) std::swap(a, b);
    pool.emplace_back(a, b);
  }
  std::sort(pool.begin(), pool.end());
  std::stack<int> stk;
  for (auto it : pool) {
    while (!stk.empty() && stk.top() < it.first) stk.pop();
    if (!stk.empty() && it.second > stk.top()) return puts("NO"), 0;
    stk.push(it.second);
  }
  puts("YES");
  return 0;
}


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

#define mp(x, y) make_pair((x), (y))

typedef long long ll;

int n, m;
int a[100005];
vector<int> nex[100005];

int vis[100005];
int nc;
vector<int> comp[100005];
vector<int> rem;

void dfs(int v) {
	vis[v]=1;
	comp[nc].push_back(v);
	for(int i=0; i<nex[v].size(); i++) {
		int s=nex[v][i];
		if(!vis[s]) dfs(s);
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i=0; i<n; i++) scanf("%d", &a[i]);
	for(int i=0; i<m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		nex[u].push_back(v);
		nex[v].push_back(u);
	}
	for(int i=0; i<n; i++) {
		if(!vis[i]) {
			dfs(i);
			nc++;
		}
	}
	if(2*(nc-1)>n) {
		printf("Impossible\n");
		return 0;
	}
	if(nc==1) {
		printf("0\n");
		return 0;
	}
	for(int i=0; i<n; i++) vis[i]=0;
	ll cost=0;
	for(int c=0; c<nc; c++) {
		int cheapest_a, cheapest_v=-1;
		for(int i=0; i<comp[c].size(); i++) {
			int curv=comp[c][i];
			if(cheapest_v==-1 || a[curv]<cheapest_a) {
				cheapest_v=curv;
				cheapest_a=a[curv];
			}
		}
		cost+=cheapest_a;
		vis[cheapest_v]=1;
	}
	for(int i=0; i<n; i++) {
		if(!vis[i]) {
			rem.push_back(a[i]);
		}
	}
	sort(rem.begin(), rem.end());
	for(int i=0; i<nc-2; i++) {
		cost+=rem[i];
	}
	printf("%lld\n", cost);

	return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;








int main() {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;
	a--; b--; c--; d--;
	if (c < d) {
		FOR(i, a, c) {
			if (s.substr(i, 2) == "##") {
				cout << "No" << endl;
				return 0;
			}
		}
		FOR(i, b, d) {
			if (s.substr(i, 2) == "##") {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
		return 0;
	}
	int k = -1;
	FOR(i, b-1, n) {
		if (s.substr(i, 3) == "...") {
			k = i+1;
			break;
		}
	}

	if (k == -1) {
		cout << "No" << endl;
		return 0;
	}
	if (k <= d) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

	

}

Measured memory_bytes: 640
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N,K;
	cin >> N >> K;
	string S;
	cin >> S;

	S[K - 1] += 32;

	cout << S << endl;

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    char ch;
    int i, num, counter[1200] = {0};

    
    while(scanf("%c", &ch) != EOF){

        if('A' <= ch && ch <= 'Z'){
            num = ch - 'A';
            counter[num]++;
        }
        else if('a' <= ch && ch <= 'z'){
            num = ch - 'a';
            counter[num]++;
        }
    }

    for(i = 0, ch = 'a'; i < 26; i++, ch++){
        printf("%c : %d\n", ch, counter[i]);
    }
    
    return 0;
}


Measured memory_bytes: 2100
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m = map(int, input().split())
graph = [0] + [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

from collections import deque

def bfs(graph, queue, prev):
    while queue:
        current = queue.popleft()

        for n in graph[current]:
            if prev[n] != -1:
                continue
            prev[n] = current
            queue.append(n)

queue = deque([1])
prev = [0] + [-1] * n
prev[1] = 0
bfs(graph, queue, prev)

if -1 not in prev:
    print('Yes')
    for i in prev[2:]:
        print(i)
else:
    print('No')


Measured memory_bytes: 92500
#!/usr/bin/env ruby

def make_tree(input)
  tree = []
  lines = parse_input(input)
  lines.each do |line|
    tree[line[0]] = { parent: -1, children: line[2..-1] }
  end
  tree.each_with_index do |node, index|
    node[:children].each do |child|
      tree[child][:parent] = index
    end
  end
  root_index = tree.find_index { |node| node[:parent] == -1 }
  set_type(tree)
  set_depth(root_index, 0, tree)
  printable_tree(tree)
end

def set_type(tree)
  tree.each do |node|
    if node[:parent] == -1
      node[:type] = :root 
    elsif node[:children] == []
      node[:type] = :leaf
    else 
      node[:type] = :internal_node
    end
  end
end

def set_depth(node_index, depth, tree)
  tree[node_index][:depth] = depth
  tree[node_index][:children].each { |child_index| set_depth(child_index, depth+1, tree) }
end

def printable_tree(tree)
  out = []
  tree.each_with_index do |node, index|
    out << "node #{index}: parent = #{node[:parent]}, depth = #{node[:depth]}" +
      ", #{node[:type].to_s.sub('_', ' ')}, #{node[:children].nil? ? [] : node[:children]}"
  end
  out.join("\n")+"\n"
end

def parse_input(input)
  lines = input.split("\n")
  lines[1..-1].map(&:split).map{|line| line.map(&:to_i)}
end

INPUT_1=<<EOS
13
0 3 1 4 10
1 2 2 3
2 0
3 0
4 3 5 6 7
5 0
6 0
7 2 8 9
8 0
9 0
10 2 11 12
11 0
12 0
EOS

OUTPUT_1=<<EOS
node 0: parent = -1, depth = 0, root, [1, 4, 10]
node 1: parent = 0, depth = 1, internal node, [2, 3]
node 2: parent = 1, depth = 2, leaf, []
node 3: parent = 1, depth = 2, leaf, []
node 4: parent = 0, depth = 1, internal node, [5, 6, 7]
node 5: parent = 4, depth = 2, leaf, []
node 6: parent = 4, depth = 2, leaf, []
node 7: parent = 4, depth = 2, internal node, [8, 9]
node 8: parent = 7, depth = 3, leaf, []
node 9: parent = 7, depth = 3, leaf, []
node 10: parent = 0, depth = 1, internal node, [11, 12]
node 11: parent = 10, depth = 2, leaf, []
node 12: parent = 10, depth = 2, leaf, []
EOS

INPUT_2=<<-EOS
4
1 3 3 2 0
0 0
3 0
2 0
EOS

OUTPUT_2=<<-EOS
node 0: parent = 1, depth = 1, leaf, []
node 1: parent = -1, depth = 0, root, [3, 2, 0]
node 2: parent = 1, depth = 1, leaf, []
node 3: parent = 1, depth = 1, leaf, []
EOS

# puts make_tree(INPUT_1)==OUTPUT_1
# puts make_tree(INPUT_2)==OUTPUT_2

puts make_tree(STDIN.read)

Measured memory_bytes: 132260
#include <stdio.h>

int main(){
  char a[256],b,c;
  long i,m,n;
  while(scanf("%ld\n",&n)){
    if(n==0)break;
    for(i=0;i<256;i++)a[i]=i;
    for(i=0;i<n;i++){
      scanf("%c %c\n",&b,&c);
      a[b]=c;
    }
    scanf("%ld\n",&m);
    for(i=0;i<m;i++){
      scanf("%c\n",&b);
      putchar(a[b]);
    }
    putchar('\n');
  }
  return 0;
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define sp              <<" "<<

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}

int main()
{
     fast
     double n,k;
     cin>>n>>k;

     double ans=0;
     double logk=log2(k);
     //cout<<ceil(logk);
     forn(i,1,n+1)
     {
          if(i<k)
        ans+=pow(0.5,ceil((log2(k/i))));
        else
         ans++; 
        //if(i!=1)cout<<ceil((log2(ki)))<<endl;
     }

     ans=(1/n)*ans;
     cout<<fixed<<setprecision(15)<<ans;

     return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    int n;
    cin >>n;
    set<string> st;
    string s;
    rep(i,n){
        cin >>s;
        st.insert(s);
    }
    cout << st.size();
    return 0;
}

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

using namespace std;

const int MOD = 2019;

void Main() {
    string S;
    cin >> S;

    reverse(S.begin(), S.end());

    map<int, int> moduloIndex;
    moduloIndex.insert(make_pair(0, 1));
    int pow10Mod = 1; // first pow(10, 0)
    int prev = 0;
    for (int i = 0; i < S.size(); ++i) {
        int s = atoi(S.substr(i, 1).c_str());
        int m = (s * pow10Mod + prev) % MOD;
        if (moduloIndex.count(m) == 0) {
            moduloIndex.insert(make_pair(m, 1));
        }
        else {
            moduloIndex[m] += 1;
        }
        prev = m;
        pow10Mod *= 10;
        pow10Mod %= MOD;
    }

    long long ans = 0LL;
    for (auto x : moduloIndex) {
        int n = x.second;
        if (n == 1) {
            continue;
        }
        ans += (long long)(n * (n - 1) / 2);
    }

    cout << ans << endl;
}

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


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

int main() {
  int N, D;
  cin >> N >> D;
   
if(N%(2*D+1)==0){
 cout << N/(2*D+1) <<endl;
}
  else{
    cout << N/(2*D+1)+1 <<endl;
  }
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;

}

Node treeMaximum(Node x){
  while(x->right!=NIL)x=x->right;
  return x;


}

Node treeSearch(Node u, int k){
  while(u!=NIL&&k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)return treeMinimum(x->right);

  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL)x=y->left;
  else x=y->right;

  if(x!=NIL)x->parent=y->parent;

  if(y->parent!=NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;

  if(y!=z)z->key=y->key;
  
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)
      x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL)
    root=z;
  else if(z->key<y->key)
    y->left=z;
  else
    y->right=z;
    
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25156
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S; cin >> S;
  int K; cin >> K;
  int N = S.size();
  set<string> res;
  REP(i, N){
    REP(j, min(K, N-i)){
      res.insert(S.substr(i, j+1));
    }
  }
  int cnt = 0;
  for(auto i : res){
    if(cnt == K-1){
      cout << i << endl;
      return 0;
    }
    cnt++;
  }
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



i64 n, k;
void solve(){
	cin >> n >> k;
	
	i64 ans = 0;
	for(i64 i = k; i <= n+1; i++){
		ans += n*i-(i-1)*i + 1;
		ans %= INF;
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

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

#define rep(i, n) for(int i=0; i<n; i++)

int main() {
    int r, d, x; cin >> r >> d >> x;
    rep(i, 10){
        x = r * x - d;
        cout << x << endl;
    } 
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int N, K,i,a,b;
    scanf("%d %d",&N,&K);
    i=0;
    loop:
        a=N/K;
        b=N/K;
        N=b;
        i=i+1;
        if(a!=0)
        goto loop;
    printf("%d",i);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <limits>
#include <vector>
#include <algorithm>

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    std::vector<int> b(n);
    std::vector<int> c(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
        std::cin >> b[i];
        std::cin >> c[i];
    }
    
    int last_a = a[0];
    int last_b = b[0];
    int last_c = c[0];

    for (int i = 1; i < n; ++i) {
        int this_a = a[i] + std::max(last_b, last_c);
        int this_b = b[i] + std::max(last_a, last_c);
        int this_c = c[i] + std::max(last_a, last_b);

        last_a = this_a;
        last_b = this_b;
        last_c = this_c;
    }
    std::cout << std::max(last_a, std::max(last_b, last_c));
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<vector>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;


int main(){
	int ha[200];
	
	while(1){
	rep(i,200) ha[i]=0;
	
	int n,m;
	scanf("%d",&n);
	if(n==0) break;
	
	char a,b;
	rep(i,n){
		cin>>a>>b;
		ha[a]=b;
	}
	
	scanf("%d",&m);
	
	vector<char> str;
	
	rep(i,m){
		cin>>a;
		if(ha[a]!=0){
			a=ha[a];
		}
		str.push_back(a);
	}
	
	rep(i,str.size()) printf("%c",str[i]);
	puts("");
	}
}
/*
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
*/

Measured memory_bytes: 1124
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <array>
#include <map>
#include <set>

using namespace std;

int main()
{
    int n, a;
    cin >> n>> a;
    cout << (a >= n % 500 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
object Main extends App {
	val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	
	val ans1 = if(n <= 1) 0 else combi(n, 2)
	val ans2 = if(m <= 1) 0 else combi(m, 2)

	println(ans1 + ans2)


	def combi(n: Int, r: Int): Int = {
		if(n==r) return 1
		else if(r == 0) return 1
		else if(r == 1) return n
		else return combi(n-1,r-1) + combi(n-1,r)
	}
}

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

using LL = long long;

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

  vector<LL> v(N+1), h(N+1);
  for(auto i = 1; i <= N; ++i) cin >> v[i] >> h[i];

  vector<LL> t(M+1), s(M+1);
  for(auto i = 1; i <= M; ++i) cin >> t[i] >> s[i];

  for(auto i = 1; i <= N; ++i) v[i] += v[i-1];

  vector<LL> cur(N+1, -1);
  cur[0] = 0;
  for(auto i = 0; i < M; ++i) {
    vector<LL> nex(N+1, -1);
    for(auto j = 0; j < N; ++j) if(cur[j] != -1) if(v[j+1] <= t[i+1]) nex[j+1] = max(nex[j+1], cur[j] + h[j+1]);
    for(auto j = 0; j < N; ++j) if(nex[j] != -1) if(v[j+1] <= t[i+1]) nex[j+1] = max(nex[j+1], nex[j] + h[j+1] + abs(h[j+1] - h[j]));
    for(auto j = 0; j <= N; ++j) {
      nex[j] = max(nex[j], cur[j]);
      if(nex[j] < s[i+1]) nex[j] = -1;
    }
    swap(cur, nex);
  }

  LL res = -1;
  for(auto j = 0; j <= N; ++j) if(s.back() <= cur[j]) {
    res = t.back() - v[j];
    break;
  }
  cout << res << endl;
}

Measured memory_bytes: 3184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 120
	// https://atcoder.jp/contests/abc120/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String s = sc.next();
		LinkedList<Integer> stack = new LinkedList<>();
		int res = 0;
		int cnt0 = 0;
		int cnt1 = 0;
		
		for (char c: s.toCharArray()) {
			int code = c - '0';
			if (code == 0) {
				cnt0++;
			} else {
				cnt1++;
			}
		}
		
		System.out.println(2*Math.min(cnt0, cnt1));
	}
	
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}

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

Measured memory_bytes: 25172