akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //

int main() {
	in(int, N, T);
	vector<int> cv;
	loop(i, N) {
		int t, c;
		cin >> c >> t;
		if (t <= T)
			cv.push_back(c);
	}
	if (cv.empty()) {
		out("TLE");
	} else {
		out(*min_element(cv.begin(), cv.end()));
	}
}


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 ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a[5], i;
    for(i = 0; i < 5; i++) {
    	cin>>a[i];
    }
    for(i = 0; i < 5; i++) {
    	if(a[i] == 0) {
    		cout<<i + 1<<"\n";
    		return 0;
    	}
    }
}

Measured memory_bytes: 3636
s = gets.split.map(&:to_i)
if s[0]>s[2]
  s[0]=s[0]-s[2]
else
  if s[0]+s[1]>s[2]
    s[1]=s[1]-(s[2]-s[0])
    s[0]=0
  else
    s[0]=0
    s[1]=0
  end
end

print s[0]," ",s[1]

Measured memory_bytes: 1788
def read_input():
    n = int(input())
    d, x = map(int, input().split())
    alist = []
    for i in range(n):
        alist.append(int(input()))

    return n, d, x, alist


def submit():
    n, d, x, alist = read_input()

    choco = 0
    for a in alist:
        i = 0
        while i*a + 1 <= d:
            choco += 1
            i += 1

    print(choco + x)


if __name__ == '__main__':
    submit()


Measured memory_bytes: 3064
// i hope i get better                                                           
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=1e5+9;
ll x[sz],n,a,b;
ll ans;

int main(){
	cin>>n>>a>>b;
	for(int i=0;i<n;++i){
		cin>>x[i];
	}
	for(int i=0;i+1<n;++i){
		ans+=min(b,a*(x[i+1]-x[i]));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
  long long n,t,res=0;
  cin >> n;
  if(n%2==0){
    n/=10;
    res=n;
    while(n>=5){
      n/=5;
      res+=n;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)

ans = 0
for i in cnt:
  if cnt[i] > int(i):
      ans += cnt[i] - int(i)
  elif int(i) > cnt[i]:
      ans += cnt[i]

print(ans)


Measured memory_bytes: 68264
def cal(a,b):
    d=((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
    return d
import math
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
ans=0
nk=math.factorial(n)
for i in range(n):
    for j in range(n):
        ans+=cal(l[i],l[j])
print((n-1)*ans/(n*(n-1)))

Measured memory_bytes: 3064
W,H,x,y,r=map(int,input().split(' '))
ct=x+r
cb=x-r
cl=y-r
cr=y+r


if ct > W:
  print('No')
elif cb <0:
  print('No')
elif cr > H:
  print('No')
elif cr < 0:
  print('No')
else:
  print('Yes')


Measured memory_bytes: 5596
#include<stdio.h>
#define MAX 100005
#define NIL -1

typedef struct{
    int p, l, r;
}Node;

Node T[MAX];
int n, D[MAX];

void print(int u){
    int i, c;
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].p);
    printf("depth = %d, ", D[u]);

    if(T[u].p == NIL) printf("root, ");
    else if(T[u].l == NIL) printf("leaf, ");
    else printf("internal node, ");

    printf("[");
    
    i = 0;
    c = T[u].l;

    while(c != NIL){
        if(i>0) printf(", ");
        printf("%d", c);
        i++;
        c = T[c].r;
    }
    printf("]\n");
}

int rec(int u, int p){
    D[u] = p;
    if(T[u].r != NIL) rec(T[u].r, p);
    if(T[u].l != NIL) rec(T[u].l, p+1);
}

int main(){
    int i, j, d, v, c, l, r;
    scanf("%d", &n);

    for(i=0; i<n; i++){
        T[i].p = NIL;
        T[i].l = NIL;
        T[i].r = NIL;
    }

    for(i=0; i<n; i++){
        scanf("%d %d", &v, &d);
        for(j=0; j<d; j++){
            scanf("%d", &c);
            if(j==0){
                T[v].l = c;
            }else{
                T[l].r = c;
            }
            l=c;
            T[c].p = v;
        }
    }

    for(i=0; i<n; i++){
        if(T[i].p == NIL){
            r=i;
        }
    }

    rec(r, 0);

    for(i=0; i<n; i++){
        print(i);
    }

    return 0;
}


Measured memory_bytes: 6468
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int x;
  cin >> x;
  
  if (x >= -40 && x <= 29) {
    cout << "No" << endl;
  }

  if (x >= 30) {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << "LINE: " << __LINE__ << " " << #x << ": " << x << endl;
#define STDIO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define lu int64_t

using namespace std;

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

    int n, k, arr[200000];
    cin >> n >> k;
    for(int i = 0; i < n; i++)
		cin >> arr[i];
	sort(arr, arr + n);

	size_t moves = 0;
	for(int i = 0; i < n - k; i++)
		moves += arr[i];

	cout << moves << endl;

	return 0;
}


Measured memory_bytes: 1024
lines = $stdin.read
array = lines.split("\n")

X,Y = array[0].split(" ").map(&:to_i)

binarr = (1..60).to_a.map{|b| 2**b}

xarr = binarr.map{|a| a*X}

puts 1 + xarr.index{|x| x > Y}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    auto fail = [](){ cout << "NO\n"; exit(0); };

    int N, M, A, B;
    cin >> N >> M >> A >> B;

    if (A > N * (M / 2)) fail();

    vector<string> res(N, string(M, '.'));
    vi used(M);

    if (N&1) {
        for (int j = 0; A > 0 && j < M / 2; j++) {
            res[used[2 * j]++][2 * j] = '<';
            res[used[2 * j + 1]++][2 * j + 1] = '>';
            A--;
        }
    }
    if (A > 0) {
        for (int j = 0; j < M / 2; j++) {
            int put = min(A, N - used[2 * j]);
            if ((put&1) && (N&1) && (M&1)) put--;
            for (int i = 0; i < put; i++) {
                res[used[2 * j]++][2 * j] = '<';
                res[used[2 * j + 1]++][2 * j + 1] = '>';
                A--;
            }
        }
        if (A) {
            res[++used[M - 2]][M - 2] = '<';
            res[used[M - 2]][M - 1] = '>';
            used[M-2]++;
            used[M-1] = used[M-2];
            A--;

            for (int i = 0; B > 0 && i + 1 < used[M-1] - 1; i += 2) {
                res[i][M-1] = '^';
                res[i+1][M-1] = 'v';
                B--;
            }
        }
    }
    if (A > 0) fail();

    for (int j = 0; j < M; j++) {
        int put = min(B, (N - used[j]) / 2);
        for (int i = 0; i < put; i++) {
            res[used[j]++][j] = '^';
            res[used[j]++][j] = 'v';
            B--;
        }
    }
    if (B > 0) fail();

    cout << "YES\n";
    for (auto s : res) {
        cout << s << "\n";
    }

    return 0;
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n*a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
int main() {
	int N; cin >> N;
	P R[110000];
	rep(i, N) {
		int X, L; cin >> X >> L;
		R[i].first = X + L;
		R[i].second = X - L;
	}
	sort(R, R+ N);
	int ans = 0;
	int rs = R[0].first;
	rep(i, N) {
		if (i == 0) {
			ans++;
		}
		else {
			if (R[i].second >= rs) {
				rs = R[i].first;
				ans++;
			}
		}
	}
	cout << ans << endl;

}


	


		






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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(10);
    
    ll N, A, B;
    cin >> N >> A >> B;
    ll factor = N / ( A + B);
    ll mod = N % (A + B);
    
    ll ans = factor * A + min(mod, A);
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php

function check($T) {
        $memo = $T;
        $T = str_replace("-0", "2", $T);
        $T = str_replace("-1", "1", $T);
        $T = str_replace("-2", "0", $T);
        if($memo !== $T) {
                return check($T);
        }

        $T = str_replace("0*0", "0", $T);
        $T = str_replace("0*1", "0", $T);
        $T = str_replace("0*2", "0", $T);
        $T = str_replace("1*0", "0", $T);
        $T = str_replace("1*1", "1", $T);
        $T = str_replace("1*2", "1", $T);
        $T = str_replace("2*0", "0", $T);
        $T = str_replace("2*1", "1", $T);
        $T = str_replace("2*2", "2", $T);
        if($memo !== $T) {
                return check($T);
        }

        $T = str_replace("0+0", "0", $T);
        $T = str_replace("0+1", "1", $T);
        $T = str_replace("0+2", "2", $T);
        $T = str_replace("1+0", "1", $T);
        $T = str_replace("1+1", "1", $T);
        $T = str_replace("1+2", "2", $T);
        $T = str_replace("2+0", "2", $T);
        $T = str_replace("2+1", "2", $T);
        $T = str_replace("2+2", "2", $T);
        if($memo !== $T) {
                return check($T);
        }


        $T = str_replace("(0)", "0", $T);
        $T = str_replace("(1)", "1", $T);
        $T = str_replace("(2)", "2", $T);
        if($memo !== $T) {
                return check($T);
        }

        return $T;
}

while(true){
        $S = trim(fgets(STDIN));
        if($S === ".") break;
        $ans = 0;
        for($P = 0; $P < 3; $P++){
                for($Q = 0; $Q < 3; $Q++){
                        for($R = 0; $R < 3; $R++){
                                $T = $S;
                                $T = str_replace("P", $P, $T);
                                $T = str_replace("Q", $Q, $T);
                                $T = str_replace("R", $R, $T);
                                if(check($T) === "2") $ans++;
                        }
                }
        }
        echo $ans.PHP_EOL;
}

Measured memory_bytes: 15000
#include<stdio.h>
int main(void){
int n,m;
  scanf("%d%d",&n,&m);
  int a[m],sum=0;
  for(int i=0;i<m;i++){
	scanf("%d",&a[i]);
    sum+=a[i];
  }
  if(sum>n)printf("-1");
  else printf("%d",n-sum);
  return 0;
}
  


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()

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

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    ll a, b, n;
    cin >> a >> b >> n;

    ll x = min(n, b-1);
    cout << (a * x) / b - a * (x / b) << "\n";


    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int32_t N;
	cin >> N;

	vector<string> S(N);
	vector<int64_t> counts(5, 0);
	for (int32_t i = 0; i < N; i++) {
		cin >> S[i];
		switch (S[i][0]) {
		case 'M':
			counts[0]++;
			break;
		case 'A':
			counts[1]++;
			break;
		case 'R':
			counts[2]++;
			break;
		case 'C':
			counts[3]++;
			break;
		case 'H':
			counts[4]++;
			break;
		}
	}

	int64_t total = 0;
	for (int32_t i = 0; i < 5; i++)
		total += counts[i];
	int64_t res = total * (total - 1) * (total - 2) / 6;
	for (int32_t i = 0; i < 5; i++) {
		int64_t count = counts[i];
		if (count < 2)
			continue;
		res -= count * (count - 1) / 2 * (total - count);

		if (count < 3)
			continue;
		res -= count * (count - 1) * (count - 2) / 6;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 6144
N = int(input())
S = input()
 
r = 0
ans = 0
for l in range(N):
 
    while True:
        #print(S.rfind(S[l:r+1]), S[l:r+1], l, r)
 
        if S.rfind(S[l:r+1]) >= r+1:
            r += 1
            ans = max(ans, r-l)
        else:
            break
 
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  int cnt = 0;
  int mx = 0;
  rep(i, N)
  {
    int h;
    cin >> h;
    if (mx <= h)
    {
      cnt++;
      mx = h;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;

int main(){
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v[i];
    int ans = 0;
    for (int i = 0; i < N; i += 2) {
        if (v[i] % 2 == 1)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
package main

import (
	"fmt"
	"math/rand"
)

func main() {
	var D int
	fmt.Scan(&D)
	cs := make([]int, 26)
	for i := 0; i < 26; i++ {
		fmt.Scan(&cs[i])
	}

	ss := make([][26]int, D)
	for i := 0; i < D; i++ {
		for j := 0; j < 26; j++ {
			fmt.Scan(&ss[i][j])
		}
	}

	ts := make([]int, D)
	for d := 0; d < D; d++ {
		sat := int(-1e9)
		t := 0
		for i := 0; i < 26; i++ {
			ts[d] = i + 1
			s := solve(d+1, ts, cs, ss)
			if sat <= s {
				sat = s
				t = ts[d]
			}
		}
		ts[d] = t
	}

	for i := 0; i < 100000; i++ {
		d := rand.Intn(365)
		q := rand.Intn(25) + 1
		sat1 := solve(D, ts, cs, ss)

		t := ts[d]
		ts[d] = q
		sat2 := solve(D, ts, cs, ss)
		if sat1 < sat2 {
			continue
		}

		ts[d] = t
	}

	for i := 0; i < len(ts); i++ {
		fmt.Println(ts[i])
	}
}

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

func solve(D int, ts []int, cs []int, ss [][26]int) int {
	last := [26]int{}
	sat := 0
	for d := 0; d < D; d++ {
		j := ts[d] - 1
		last[j] = d + 1
		for i := 0; i < 26; i++ {
			sat -= (d + 1 - last[i]) * cs[i]
		}
		sat += ss[d][j]
	}

	return sat
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String inputStr = in.next();
        if (!inputStr.equals(" ") && inputStr.length()>=4){
            System.out.println(inputStr.substring(0,4)+" "+inputStr.substring(4));
        }
    }
}

Measured memory_bytes: 10056
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
for(var I=0;I<Arr.length;I++){
   var nx=Arr[I].split(" ").map(Number);
   var n=nx[0];
   var x=nx[1];
   if(n==0 && x==0)break;
   var cnt=0;
   for(var i=1;i<=n;i++){
      for(var j=i+1;j<=n;j++){
         if(i+j>=x)break;
         var k=x-(i+j);
         if(k>j && k<=n)cnt++;
      }
   }
   console.log(cnt);
}

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

template <class T, class F = multiplies<T>>
T power(T a, long long n, F op = multiplies<T>(), T e = {1}) {
  assert(n >= 0);
  T res = e;
  while (n) {
    if (n & 1) res = op(res, a);
    if (n >>= 1) a = op(a, a);
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> es(n - 1);
  vector<vector<int>> g(n);
  for (int id = 0; id < n - 1; ++id) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    es[id] = u ^ v;
    g[u].push_back(id);
    g[v].push_back(id);
  }
  int m;
  cin >> m;
  vector<long long> mask(m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    vector<int> prv(n);
    auto dfs = [&](auto&& self, int v, int p) -> void {
      prv[v] = p;
      for (int id : g[v]) {
        if (id != p) {
          self(self, v ^ es[id], id);
        }
      }
    };
    dfs(dfs, a, -1);
    while (b != a) {
      mask[i] |= 1LL << prv[b];
      b = b ^ es[prv[b]];
    }
  }
  long long res = 0;
  for (int bt = 0; bt < 1 << m; ++bt) {
    long long all = 0;
    for (int i = 0; i < m; ++i) {
      if (bt >> i & 1) {
        all |= mask[i];
      }
    }
    res += power(-1, __builtin_popcount(bt)) * power(2LL, n - 1 - __builtin_popcountll(all));
  }
  cout << res << '\n';
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func dfs(a int, ch []int, t [][]int)  {
	for _, e := range t[a] {
		if ch[e] == 0 {
			ch[e] = 1
			dfs(e,ch,t)
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n := scanInt()
	m := scanInt()

	t := make([][]int,n)
	for i := 0; i < m; i++ {
		x := scanInt() -1
		y := scanInt() -1
		_ = scanInt()
		t[x],t[y] = append(t[x],y),append(t[y],x)
	}
	
	ch := make([]int,n)
	ans := 0
	for i := 0; i < n; i++ {
		if ch[i] == 0 {
			ans++
			ch[i] = 1
			dfs(i,ch,t)
		}
	}
	fmt.Println(ans)

}


Measured memory_bytes: 34688
def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(n ** 0.5) + 1):
        if n % k == 0:
            return False
    return True

p = [0] * (10 ** 5)
for i in range(10**5):
    if i % 2 == 0:
        continue
    if is_prime(i) and is_prime((i+1)//2):
        p[i] = 1

acm = [0] * (10 ** 5 + 1)
for i in range(10**5):
    acm[i+1] = acm[i] + p[i]
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(acm[r+1] - acm[l])

Measured memory_bytes: 13040
N,K = map(int,input().split())
X = list(map(int,input().split()))

ans = 10 ** 9
for i in range(N - K + 1):
  x = X[i]
  y = X[i + K - 1]
  if x * y < 0:
    move = min(abs(x),abs(y)) * 2 + max(abs(x),abs(y))
  else:
    move = max(abs(x),abs(y))
  if move < ans:
    ans = move
    
print(ans)

Measured memory_bytes: 14384
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
#include <numeric>
#include <stack>
using namespace std;

const int M_MAX = 100001;
int N, M;
int a[M_MAX];
long long d[M_MAX];

int main() {
	cin >> N >> M;
	for (int i = 0; i <= N; i++) d[i] = -1;
	for (int i = 0; i < M; i++) {
		cin >> a[i];
		d[a[i]] = 0;
	}

	d[0] = 1;
	if (d[1] != 0) d[1] = 1;
	for (int i = 2; i <= N; i++) {
		if (d[i]!=0) d[i] = (d[i - 1] + d[i - 2]) % 1000000007;
	}
	cout << d[N] << endl;
}

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

typedef long long ll;

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;

ll dp[MAXV];
int N, W, V, wi[MAXN], vi[MAXN];

int main() {
    cin >> N >> W;
    for (int i = 1; i <= N; i++) {
        cin >> wi[i] >> vi[i];
        V += vi[i];
    }

    for (int i = 1; i <= V; i++) dp[i] = INF;
    dp[0] = 0;

    for (int item = 1; item <= N; item++) {
        int w = wi[item], v = vi[item];
        for (int i = V; i >= v; i--) {
            dp[i] = min(dp[i], dp[i - v] + w);
        }
    }

    for (int i = V; i >= 0; i--) {
        if (dp[i] <= W) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 4396
using System;

namespace ITP1_8_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            Console.WriteLine(Contains(s, t));
        }

        static string Contains(string s,string t)
        {
            int lenS = s.Length;
            int lenT = t.Length;
            s += s;
            for (int i = 0; i < lenS; i++)
            {
                string sub = s.Substring(i, lenT);
                if (sub == t)
                {
                    return "Yes";
                }
            }
            return "No";
        }
    }
}

Measured memory_bytes: 8896
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}


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

  string s;
  cin >> s;
  ll K;
  cin >> K;

  vector<ll> str,ans;
  rep(i,s.size()){
    str.pb(26-(s[i]-'a'));
    ans.pb(s[i]-'a');
  }


  rep(i,s.size()){
    str[i]%=26;
  }
  rep(i,str.size()){
    if(str[i]>K) {
      str[i] = 0;
      continue;
    }
    else {
      K-=str[i];
    }
  }

  if(K!=0) str[str.size()-1]+=K;

  rep(i,str.size()){
    ans[i]+=str[i];
    ans[i]%=26;
    s[i] = ans[i]+'a';
  }

  cout << s << endl;
  
  return 0;
}


Measured memory_bytes: 2252
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for a in range(0,A+1):
  for b in range(0,B+1):
    for c in range(0,C+1):
      if X == a*500 + b*100 + c*50:
        count += 1
print(count)

Measured memory_bytes: 3060
import sys
N,K=map(int,input().split())
if K==0:
  print(N**2)
  sys.exit()
ans=0
for b in range(1,N+1):
  v=N//b
  r=N-b*v
  ans+=(v*(max(0,b-K))+max(0,r-K+1))
print(ans)

Measured memory_bytes: 3060
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

string s;
LL ans=0,num1=0,pw2[100010],pw3[100010];

int main()
{
	cin>>s;
	pw2[0]=pw3[0]=1;
	repn(i,100005) pw2[i]=pw2[i-1]*2%MOD,pw3[i]=pw3[i-1]*3%MOD;
	rep(i,s.size())
	{
		if(s[i]=='1') 
		{
			ans=(ans+pw2[num1]*pw3[s.size()-i-1]%MOD)%MOD;
			num1++;
		}
	}
	ans=(ans+pw2[num1])%MOD;
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

std::string s;
int ans = 700;

int main() {
    std::cin >> s;
    for (int i = 0; i < 3; ++i) ans += 100 * (s[i] == 'o');
    printf("%d\n", ans);
    return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    string S; cin >> S;
    int cnt = 0;
    int mn = mod, mx = -mod;
    rep(i, N){
        if(S[i] == '(') cnt++;
        else cnt--;
        mn = min(mn, cnt);
    }
    if(mn < 0) rep(i, -mn) S = "(" + S;
    N = S.length();
    cnt = 0;
    rep(i, N){
        if(S[i] == '(') cnt++;
        else cnt--;
    }
    if(cnt > 0) rep(i, cnt) S += ')';
    cout << S << endl;
    return 0;
}

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

int main(int argc, const char * argv[]) {
    int a, b;
    cin >> a >> b;
    if (a < b) {
        cout << "a < b\n";
    } else if (a > b) {
        cout << "a > b\n";
    } else {
        cout << "a == b\n";
    }
    return 0;
}

Measured memory_bytes: 1124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    ll ba = 0, a = 0, b = 0, ans = 0;
    rep(i,n){
        string si = s[i];
        int sz = si.size();
        rep(j, sz-1){
            if (si.substr(j, 2) == "AB") ans++;
        }
        if (si[0] == 'B' && si[sz-1] == 'A') ba++;
        else if (si[0] == 'B') b++;
        else if (si[sz-1] == 'A') a++;
    }
    if (ba == 0){
        ans += min(a, b);
    }
    else{
        if (a + b == 0){
            ans += ba-1;
        }else{
            ans += ba + min(a, b);
        }
    }
    cout << ans << endl;
    return 0;
}

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

x,y = map(int,input().split())
answer = 10 ** 18
if x <= y:
    answer = min(answer, y-x)
if -x <= y:
    answer = min(answer, 1+x+y)
if x <= -y:
    answer = min(answer, 1-y-x)
if -x <= -y:
    answer = min(answer, 2+x-y)
print(answer)

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c;
  if (a == min({a, b, c})){
    if (b < c){
      cout << a << " " << b << " " << c << endl;
    }
    else{
      cout << a << " " << c << " " << b << endl;
    }
  }
  else if (b == min({a, b, c})){
    if (a < c){
      cout << b << " " << a << " " << c << endl;
    }
    else{
      cout << b << " " << c << " " << a << endl;
    }
  }
  else{
    if (a < b){
      cout << c << " " << a << " " << b << endl;
    }
    else{
      cout << c << " " << b << " " << a << endl;
    }
  }

}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1e9+5;
const int N=2e5+5;
const int mod=1e9+7;

ll n;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	if(n==2) return cout<<1,0;
	ll ans=0;
	for(ll i=2;i*i<=n;++i){
		if(n%i==0){
			ll num=n;
			while(num%i==0){
				num/=i;
			}
			if(num%i==1) ++ans;
		}
	}	
	--n;
	for(ll i=2;i*i<=n;++i){
		if(n%i==0){
			if(n/i==i) ++ans;
			else ans+=2;
		}
	}
	ans+=2;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 100010;

ll n, k;
ll ar[maxn], ps_val[maxn], ps_abs[maxn];

void MAIN() {

    cin >> n >> k;
    fori (i, n) cin >> ar[i];
    fori (i, n) {
        ps_val[i + 1] = ps_val[i] + ar[i];
        ps_abs[i + 1] = ps_abs[i] + max(0LL, ar[i]);
    }
    ll mx = 0;
    fori (i, n - k + 1) {
        smax(mx, ps_abs[n] - (ps_abs[i + k] - ps_abs[i]) + max(0LL, ps_val[i + k] - ps_val[i]));
    }
    cout << mx << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(
10 5
5 -4 -5 -8 -4 7 2 -4 0 7
    )";
    MAIN();
    return 0;
}


Measured memory_bytes: 2560
K = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

i = int(input())

print(K[i-1])

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>

int main(){
  int i,n,d,c=0;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&d);
    c+=isPrime(d);
  }
  
  printf("%d\n",c);
  
  return 0;
}

int isPrime(int d){
  int i;
  if(d==2)return 1;
  if(d<2||d%2==0)return 0;
  i=3;
  while(i<=sqrt(d)){
    if(d%i==0)return 0;
    i=i+2;
  }
  return 1;
}



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

typedef struct _node
{
    int key;
    struct _node *next;
    struct _node *prev;
} node;

node *head;

node *makenode(int);
void insert(int);
void delete(int);
void deleteFirst();
void deleteLast();

int main()
{
    int i, n, a;
    char op[16];
    node *x;
    
    head = makenode(0);
    head->next = head;
    head->prev = head;
    
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
        scanf("%s", op);
        if(strcmp(op, "insert") == 0)
        {
            scanf("%d", &a);
            insert(a);
        }
        else if(strcmp(op, "delete") == 0)
        {
            scanf("%d", &a);
            delete(a);
        }
        else if(strcmp(op, "deleteFirst") == 0)
        {
            deleteFirst();
        }
        else if(strcmp(op, "deleteLast") == 0)
        {
            deleteLast();
        }
    }
    
    x = head;
    while(x->next != head)
    {
        printf("%d", x->next->key);
        x = x->next;
        if(x->next != head)
        {
            printf(" ");
        }
    }
    printf("\n");

    return 0;
}



node *makenode(int a)
{
    node *x;
    x = malloc(sizeof(node));
    x->key = a;
    return x;
}
void insert(int a)
{
    node *x;
    x = makenode(a);
    x->next = head->next;
    head->next->prev = x;
    head->next = x;
    x->prev = head;
}
void delete(int a)
{
    node *x;
    x = head;
    
    while(x->next != head)
    {
        x = x->next;
        if(x->key == a)
        {
            x->prev->next = x->next;
            x->next->prev = x->prev;
            free(x);
            break;
        }
    }
}
void deleteFirst()
{
    node *x;
    x = head->next;
    head->next = x->next;
    x->next->prev = head;
    free(x);
}
void deleteLast()
{
    node *x;
    x = head->prev;
    head->prev = x->prev;
    x->prev->next = head;
    free(x);
}

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

int main()
{
    int a,b;
    cin >> a >> b;
    if(a+b == 15){
        cout << "+" << endl;
    }else if(a* b ==15){
        cout << "*" << endl;
    }else{
        cout << "x" << endl;
    }
    
    return 0;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
int main(){
  int a,b,c,d,e;string s,ss;
  cin>>a;
  if(a<1200)cout<<"ABC"<<endl;
  else if(a<2800)cout<<"ARC"<<endl;
  else cout<<"AGC"<<endl;
  return 0;
}


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

using namespace std;

long long mat[505][505];

long long gcd(long long a,long long b)
{
	return b ? gcd(b,a % b) : a;
}

long long lcm(long long a,long long b)
{
	if(!b || !a) return a + b;
	return a / gcd(a,b) * b;
}

int primes[1050];

void sieve()
{
	int cnt = 0;
	for(int i = 2;cnt <= 1020; ++ i)
	{
		int flg = 0;
		for(int j = 2;j * j <= i; ++ j)
			if(i % j == 0)
			{
				flg = 1;
				break;
			}
		if(!flg) primes[++ cnt] = i;
	}
}

int main()
{
	sieve();
	int n; scanf("%d",&n);
	for(int i = 0;i <= n + 1; ++ i)
		for(int j = 0;j <= n + 1; ++ j)
			mat[i][j] = 1;
	for(int i = 0;i <= n + 1; ++ i)
		for(int j = 0;j <= n + 1; ++ j)
			if((i + j) % 2 == 0)
				mat[i][j] *= primes[(i + j) / 2 + 1],mat[i][j] *= primes[(i + (n - j + 1)) / 2 + (n + 1)];
//	long long maxn = 0;
	for(int i = 1;i <= n; ++ i,printf("\n"))
		for(int j = 1;j <= n; ++ j)
		{
			if((i + j) % 2 == 1)
				mat[i][j] = 1 + lcm(lcm(mat[i - 1][j],mat[i][j - 1]),lcm(mat[i + 1][j],mat[i][j + 1]));
			printf("%lld ",mat[i][j]);
		//	maxn = max(maxn,mat[i][j]);
		}
//	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 5120
// clang-format off
	#include <bits/stdc++.h>
	using namespace std; using ll = long long; using uint = unsigned int;
	#define SFINAE(x, ...)	template <class, class = void> struct x : false_type {}; template <class T> struct x<T, void_t<__VA_ARGS__>> : true_type {};
	SFINAE(DefaultIO, decltype(cout << declval<T &>()))
	SFINAE(IsTuple, typename tuple_size<T>::type)
	SFINAE(Iterable, decltype(begin(declval<T>())))
	template <class T> constexpr char Space(const T &) { return (Iterable<T>::value or IsTuple<T>::value) ? '\n' : ' '; }
	template <auto &os> struct Writer {
		template <class T> void Impl(T const &t) const {
			if constexpr (DefaultIO<T>::value) os << t;
			else if constexpr (Iterable<T>::value) { int i = 0; for (auto &&x : t) ((i++) ? (os << Space(x), Impl(x)) : Impl(x)); }
			else if constexpr (IsTuple<T>::value) apply([this](auto const &... args) { int i = 0; (((i++) ? (os << ' ', Impl(args)) : Impl(args)), ...);}, t);
			else static_assert(IsTuple<T>::value, "No matching type for print");
		}
		template <class F, class... Ts> auto &operator()(F const &f, Ts const &... ts) const { return Impl(f), ((os << ' ', Impl(ts)), ...), os << '\n', *this; }
	};
	template <auto &is> struct Reader {
		template <class T> auto& operator()(T &t) const {
			if constexpr (DefaultIO<T>::value) is >> t;
			else if constexpr (Iterable<T>::value) for (auto &x : t) (*this)(x);
			else if constexpr (IsTuple<T>::value) apply([this](auto &... args) { ((*this)(args), ...); }, t);
			else static_assert(IsTuple<T>::value, "No matching type for read");
			return *this;
		}
	};
	#ifdef NARUT_LOCAL
	#define Debug(...) cerr << "\033[0;31m", Writer<cerr>{}(__VA_ARGS__), cerr << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] constexpr Reader<cin> Cin; [[maybe_unused]] constexpr Writer<cout> Cout;
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)
// clang-format on





auto Main() {
	int n;
	cin>>n;
	vector<int> A(n);
	Cin(A);
	
	auto acc = accumulate(begin(A), end(A),0,bit_xor<>{});
	for(auto& a:A) {
		a^=acc;
	}
	Cout(A);	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Main();
}


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

class Program {
    static void Main(string[] args) {
		new Calc().calc();
    }
	public class Calc {
		public Calc() { }
		public void calc() {
			var NM = ReadLine<int>(' ');
			nodes = new List<int>[NM[0]];
			for (int i = 0; i < NM[0]; i++) {
				nodes[i] = new List<int>();
			}
			for (int i = 0; i < NM[1]; i++) {
				var ab = ReadLine<int>(' ');
				nodes[ab[0] - 1].Add(ab[1] - 1);
				nodes[ab[1] - 1].Add(ab[0] - 1);
			}
			Search(0, "", NM[0]);
			Console.WriteLine(count);
			return;
		}
		List<int>[] nodes;
		private int count = 0;
		public void Search(int node,string recent,int N) {
			foreach (var item in nodes[node]) {
				if(!recent.Contains(item+""))Search(item, recent+node, N);
			}
			recent += node;
			if (recent.Length == N) {
				count++;
				return;
			}
		}
	}

	public static T ReadLine<T>() =>
		(T)Convert.ChangeType(Console.ReadLine(), typeof(T));
	
	public static T[] ReadLine<T>(params char[] separators) =>
		Console.ReadLine()
		.Split(separators)
		.Select(_ => (T)Convert.ChangeType(_, typeof(T)))
		.ToArray();
	
	public static List<T> ReadLines<T>(int readCount) {
		List<T> rt = new List<T>();
		for (int i = 0; i < readCount; i++) {
			rt.Add(ReadLine<T>());
		}
		return rt;
	}
}
public static class Utils {
	public static string Docking<T>(this IEnumerable<T> s, int sequenceRange, Func<T, string> filter = null) {
		string str = "";
		int c = 0;
		foreach (var item in s) {
			str += filter == null ? item.ToString() : filter(item);
			c++;
			if (c == sequenceRange) break;
		}
		return str;
	}

	public static string Docking<T>(this IEnumerable<T> s, Func<T, string> filter = null) {
		return s.Docking(s.Count(), filter);
	}

	public static string RangeDocking<T>(this IEnumerable<T> s,int start,int end,Func<T,string> filter = null) {
		string str = "";
		end = end < s.Count() ? end : s.Count();
		var items = s.ToArray();
		for (int i = start; i < end; i++) {
			str+= filter == null ? items[i].ToString() : filter(items[i]);
		}
		return str;
	}
	/// <summary>
	/// seqコマンドの代わり
	/// </summary>
	/// <param name="N"></param>
	/// <param name="start"></param>
	/// <returns></returns>
	public static List<int> Sequence(this int N,int start=0) {
		List<int> rt = new List<int>();
		for (int i = start; i < N; i++) {
			rt.Add(i);
		}
		return rt;
	}
}

Measured memory_bytes: 17616
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n, d;
  cin >> n >> d;
  int cnt = 0;
  vector<int> a(n);
  for(int k=0; k< n; k++) a[k] = 0;
  
  int sum=0;
  
  for(int i=d; ; i = i+2*d+1){
    if(i > (a.size() - 1)) {
      cnt++;
      break;
    }
    a[i] = 1;
    //cout << "a[" << i << "]=" << a[i] << endl;
    cnt++;
    //cout << "cnt=" << cnt << endl;
    sum++;
    if(sum>=a.size()) break;
    //cout << "sum=" << sum << endl;
    for(int j=1; j <= d; j++){
      //cout << "j=" << j << endl;
      if((i-j) >= 0 && a[i-j] != 1) {
        a[i-j] = 1;
        //cout << "a[" << i-j << "]=" << a[i] << endl;
        sum++;
        //cout << "sum=" << sum << endl;
        if(sum>=a.size()) break;
      }
      if((i+j) <= (a.size() - 1) && a[i+j] != 1) {
        a[i+j] = 1;
        //cout << "a[" << i+j << "]=" << a[i] << endl;
        sum++;
        //cout << "sum=" << sum << endl;
        if(sum>=a.size()) break;
      }
    }
    if(sum>=a.size()) break;

  }
  /*
  n = n-(2*d+1);
  while(n>=0){
    n = n-(d+1);
    if(n>=0) cnt++;
  }
  */
  cout << cnt;
  return 0;
}

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

long long N, K;
vector<long long> a;

bool isNeed(pair<long long, int> x) {
    vector<vector<bool>> dp(N + 1, vector<bool>(K + 1, false));
    //dp[i][j] = i枚目まで見たとき、和がjとなる集合が存在するか
    for (int i = 0; i <= N; i++) {
        dp[i][0] = true;
    }

    for (int i = 1; i <= N; i++) {
        if (i == x.second + 1) {
            //スキップ
            for (int j = 0; j <= K; j++) {
                dp[i][j] = dp[i - 1][j];
            }
            continue;
        }

        for (int j = 0; j <= K; j++) {
            if (j - a[i - 1] < 0) {
                dp[i][j] = dp[i - 1][j];
                continue;
            }
            dp[i][j] = (dp[i - 1][j] || dp[i - 1][j - a[i - 1]]);
        }
    }

    for (int j = K - 1; j >= K - x.first; j--) {
        if (dp[N][j]) {
            return true;
        }
    }

    return false;
}

int main() {
    cin >> N >> K;
    a.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    vector<pair<long long, int>> value_index(N);
    for (int i = 0; i < N; i++) {
        value_index[i].first = a[i];
        value_index[i].second = i;
    }
    sort(value_index.begin(), value_index.end());

    int need = N, not_need = -1;
    while (need - not_need != 1) {
        int mid = (need + not_need) / 2;
        (isNeed(value_index[mid]) ? need = mid : not_need = mid);
    }

    cout << need << endl;
}

Measured memory_bytes: 3740
#include<iostream>
#include<queue>
using namespace std;
struct elem{
	int time;
	string name;
};
int main(){
	queue<elem> que;
	int n,q,curtime=0;
	cin>>n>>q;
	struct elem x;
	for(int i=0;i<n;i++){
		cin>>x.name>>x.time;
		que.push(x);
	}	
	while(!que.empty()){
		x=que.front();
		if(x.time<=q){
			curtime += x.time;
			cout<<x.name<<" "<<curtime<<endl;
		}else{
			x.time -= q;
			curtime += q;
			que.push(x);
		}
		que.pop();
	}
	return 0; 
}

Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> as;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        as.emplace_back(a, b);
    }

    sort(as.begin(), as.end());

    vector<pair<int, int>> bs = {as.front()};
    for (int i = 1; i < m; i++) {
        int id = lower_bound(bs.begin(), bs.end(), as[i]) - bs.begin();
        if (as[i].first < bs[id - 1].second) {
            bs[id - 1].first = as[i].first;
            bs[id - 1].second = min(bs[id - 1].second, as[i].second);
            continue;
        }
        bs.push_back(as[i]);
    }

    cout << bs.size() << endl;
}

Measured memory_bytes: 1400
#include "bits/stdc++.h"
using namespace std;
typedef long long int lli;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define ff first
#define ss second
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5 + 5;


int main() {
	IOS
	int T = 1;
	// cin >> T;
	while(T--) 
	{
		lli n,k;
		cin>>n>>k;
		cout<<min(n%k, k - (n%k));
	}
	return 0;
}


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

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    int N;

    std::cin >> N;

    unordered_map<string, int> count;

    for (int i = 0; i < N; ++i) {
        string str;
        cin >> str;

        count[str]++;
    }

    return count.size();
}

int main()
{
    std::cout << solve() << std::endl;
//    solve();

    return 0;
}

Measured memory_bytes: 17792
gets
_S = gets.split.map(&:to_i).sort
gets
_T = gets.split.map(&:to_i).sort

count = 0
i = 0
_T.each{|t|
  while i < _S.size && _S[i] < t do
    i += 1
  end
  while i < _S.size &&  _S[i] == t do
    i += 1
    count += 1
    break
  end
}
puts count

Measured memory_bytes: 9200
#include <stdio.h>

int main(void)
{
	int h, m, s, rest;
	
	while (1){
		scanf("%d%d%d", &h, &m, &s);
		
		if (h == -1 && m == -1 && s == -1){
			break;
		}
		
		rest = 120 * 60 - (h * 3600 + m * 60 + s);
		
		printf("%02d:%02d:%02d\n", rest / 3600, rest % 3600 / 60, rest % 60);
		
		rest *= 3;
		
		printf("%02d:%02d:%02d\n", rest / 3600, rest % 3600 / 60, rest % 60);
	}
	
	return (0);
}

Measured memory_bytes: 612