akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;

/**
 * 二次元累積和を求める s[x][y] := [0, x) x [0, y) の長方形の区間の和
 * 注意：半開区間になっている
 * @param [in] base 元となる二次元データ (h * w)
 * @param [out] base を元に計算された累積和 ((h+1) * (w+1))
 */
vector<vector<int>> create_2d_cumulative_sum(const vector<vector<int>>& base) {
  int h = base.size();
  int w = base[0].size();
  vector<vector<int>> s(h+1, vector<int>(w+1, 0));
  rep(i, h) rep(j, w) {
    s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + base[i][j];
  }
  return s;
}

/**
 * 二次元累積和から指定された区間 [x1, x2) [y1, y2) の和を求める
 */
int get_value(const int& x1, const int& y1, const int& x2, const int& y2, const vector<vector<int>>& s) {
  return s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1];
}

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

  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>> t(n, vector<int>(n, 0));

  rep(i, m) {
    int l, r; cin >> l >> r; l--, r--;
    t[l][r]++;
  }

  auto csum = create_2d_cumulative_sum(t);

  rep(i, q) {
    int l, r; cin >> l >> r; l--, r--;
    int x = get_value(l, l, r+1, r+1, csum);
    cout << x << endl;
  }

  return 0;
}


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

int a[1001][2001]={0};
int main() {
    int N, K;
    int x, y;
    char c;
    scanf("%d %d", &N, &K);
    int i,j;
    for(i=0;i<N;i++) {
        scanf("%d %d %c", &x, &y, &c);
        y%=2*K;
        if(c=='W')x+=K;
        if(y>=K){
            x+=K;
            y-=K;
        }
        a[y+1][x%(2*K)+1]++;
    }

    for(i=1;i<K;i++){
        for(j=1;j<=2*K;j++){
            a[i+1][j]+=a[i][j];
        }
    }
    for(i=1;i<=K;i++){
        for(j=1;j<2*K;j++){
            a[i][j+1]+=a[i][j];
        }
    }

    int ans=0;
    int tmp;
    for(i=1;i<=K;i++){
        for(j=1;j<=2*K;j++){
            if(j<=K+1){
                tmp=a[K][j+K-1]-a[K][j-1]-a[i-1][j+K-1]+a[i-1][j-1];
            }
            else{
                tmp=a[K][2*K]-a[K][j-1]-a[i-1][2*K]+a[i-1][j-1];
                tmp+=a[K][j-K-1]-a[K][0]-a[i-1][j-K-1]+a[i-1][0];
            }
            if(i>1){
                if(j>1&&j<=K+1){
                    tmp+=a[i-1][j-1];
                }
                if(j>1&&j>K+1){
                    tmp+=a[i-1][j-1]-a[i-1][j-K-1];
                }
                if(j<=K){
                    tmp+=a[i-1][2*K]-a[i-1][j+K-1];
                }
            }
            if(ans<tmp)ans=tmp;
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 7936
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  string a,b,c; cin >> a >> b >> c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,m,x;cin >> n >> m >> x;
    vi c(n);
    vii a(n,vi(m));

    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }

    int ans = MINF;
    for(int bit=1;bit<(1<<n);bit++){
        int sum = 0;
        vi und(m);
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                sum += c[i];
                rep(j,m)und[j] += a[i][j];
            }
        }

        bool flag = true;
        rep(i,m){
            if(und[i] < x){
                flag = false;
                break;
            }
        }
        if(flag)chmin(ans,sum);
    }

    cout << (ans != MINF ? ans : -1) << endl;
    return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>
 
int main(void){
    int n,i,min,max;
    long sum;
    scanf("%d",&n);
    long a[10000];
    for(i=0;i<n;i++) scanf("%ld",&a[i]);
 
    min=a[0];
    max=a[0];
    sum=0;
    for(i=0;i<n;i++){
        if(a[i]<min) min=a[i];
        if(a[i]>max) max=a[i];
        sum=sum+a[i];
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}


Measured memory_bytes: 1936
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 1e2+10;
#endif


int main() {
	int n;
	map<int,int> f;
	cin>>n;
	REP(i,1,n) ++f[rd()];
	int ans = 0;
	vector<int> A, B;
	for (auto t:f) {
		while (t.y>2) ++ans, t.y -= 2;
		if (t.y==2) A.pb(t.x);
		else B.pb(t.x);
	}
	ans += (A.size()+1)/2;
	printf("%d\n", n-ans*2);
}






Measured memory_bytes: 5628
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,k,ans;
int main(){
	n=read(),k=read();
	while(n){
		n/=k;
		++ans;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main() {

    ll A,B,K; cin>>A>>B>>K;
    if(A>=K){
        cout<<A-K<<" "<<B<<endl;
    }else if(A+B >= K){
        cout<<0<<" "<<A+B-K<<endl;
    }else{
        cout<<0<<" "<<0<<endl;
    }

    return 0;
}

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


int main() {
  char C[2][3];
  rep(i,2){
    rep(j,3) cin >> C[i][j];
  }
  bool ok = true;
  rep(i,2){
    rep(j,3){
      if(C[i][j] != C[1-i][2-j]) ok = false;
    }
  }
  ok ? cout << "YES" << endl : cout << "NO" << endl;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;

void main(){
	auto S = readln.chomp.to!(char[]);
	int count;
	foreach(i; 0..4){
		if(S[i] == '+') count++;
		else count--;
	}
	writeln(count);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
using namespace std;

const int INF = 1<<28;
const int MAXN = 16;
int N;
string S, T;
int start, goal;
int cost[MAXN][1<<MAXN];

struct State {
  int pos, bit, cost;
  bool operator < (const State &s) const {
    return cost > s.cost;
  }
};


int dijkstra() {
  priority_queue<State> que;
  fill(cost[0], cost[MAXN], INF);
  for(int i = 0; i < N; ++i) {
    que.push((State){i, start, 0});
    cost[i][start] = 0;
  }
  while(que.size()) {
    const State s = que.top();
    que.pop();
    if(cost[s.pos][s.bit] < s.cost) continue;
    if(s.bit == goal) return s.cost;
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < N; ++j) {
        if((s.bit&(1<<i)) ^ (s.bit&(1<<j))); else continue;
        State t = {j, s.bit^(1<<i)^(1<<j), s.cost+abs(i-s.pos)+abs(j-i)};
        if(cost[t.pos][t.bit] <= t.cost) continue;
        que.push(t);
        cost[t.pos][t.bit] = t.cost;
      }
    }
  }
  return INF;
}

int main() {
  while(cin >> N && N) {
    cin >> S >> T;
    start = goal = 0;
    for(int i = 0; i < N; ++i) {
      if(S[i] == 'W') start |= 1<<i;
      if(T[i] == 'W') goal  |= 1<<i;
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

Measured memory_bytes: 26684
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(n,r))

r=input1()
print(2*math.pi*r)

Measured memory_bytes: 27236
# util functions
def dfs( zero_avail, flag, list, history )
  if list == []
    if history.uniq.size == 3
      # print "ok: "
      # p history
      return 1
    else
      # print "ng: "
      # p history      
      return 0
    end
  else
    sum = 0
    next_list = list.clone
    next_list.shift
    sum += dfs( true, true, next_list, history.clone ) if zero_avail
    sum += dfs( false, (flag or (list[0] != 3)), next_list, (history.clone << 3) ) if list[0] >= 3 or flag
    sum += dfs( false, (flag or (list[0] != 5)), next_list, (history.clone << 5) ) if list[0] >= 5 or flag
    sum += dfs( false, (flag or (list[0] != 7)), next_list, (history.clone << 7) ) if list[0] >= 7 or flag   
    return sum
  end
end

# debug
debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if debugFlag

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end
num = inputs[0][0]

# body
if debugFlag
end

list = []
10.times do |i|
  if num >= 10**i 
    elem = (num / (10**i)) % 10
    list << elem
  end
end
list.reverse!

p list if debugFlag

puts dfs( true, false, list, [] )


Measured memory_bytes: 2044
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int N,M,Q,B,C,D;
int A[100010];
std::string S[5];
std::set<int> Union;
std::map<int,int> Hash;

int main(){
    int dim=0;
    cin>>S[0]>>S[1]>>S[2];
    while(1) {
        if(S[dim]==""){
            cout<<char(dim+'A')<<endl;
            return 0;
        }
        DEB(S[dim][0])
        int dim2=S[dim][0]-'a';
        S[dim].erase(S[dim].begin());
        dim=dim2;
        DEB(dim)DEB(dim2)END
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    map<string, bool> id;
    string s;
    //0を入力
    cout << 0 << endl;
    cout << flush;
    cin >> s;
    if (s == "Vacant") return 0;
    if (s == "Male"){
        id["Male"] = 0;
        id["Female"] = 1;
    }
    else {
        id["Male"] = 1;
        id["Female"] = 0;
    }
    //n-1を入力
    cout << n - 1 << endl;
    cout << flush;
    cin >> s;
    if (s == "Vacant") return 0;
    //ここからにぶたん
    int ok = 0;
    int ng = n - 1;
    while (abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        cout << mid << endl;
        cout << flush;
        cin >> s;
        if (s == "Vacant") return 0;
        if (id[s] == mid % 2) ok = mid;
        else ng = mid;
    }
}

Measured memory_bytes: 852
#include <iostream>

using namespace std;

#define endl "\n"

typedef long long ll;

void fast()

{

	ios_base::sync_with_stdio(false);	cout.tie(NULL);

	cin.tie(NULL);

}

int main()

{

	fast();

	ll n;

	cin >> n;

	ll ans = 0;

	for (int i = 1; i < n; i++)

	{

		ans += (n - 1) / i;

	}

	cout << ans << endl;

}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <math.h>
#include <cstdio>
#include <iomanip>
typedef  long long ll;
using namespace std;

int main(void) {
	ll n, ans = 0;
	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		if (i % 2 ==0) continue;
		int cnt = 0;
		for (int j = 1; j <= n; j++)
		{
			if (i % j == 0) cnt++;
		}
		if (cnt == 8) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
awk -M '\
function gcd(a, b, tmp)
{
    if(a<b){tmp=a;a=b;b=tmp}
    if(b == 0)return a;
    return gcd(b, a%b);
}
function lcm(a, b)
{
    return a * b / gcd(a, b);
}
{
    X=$1; Y=$2
    if(X%Y==0){
        print -1;
        exit
    }
    if(X<Y){
        print X;
        exit
    }
    print lcm(X,Y)-X
}'

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

const int N = 2e5 + 5, mod = 1e9 + 7;

int main()
{
    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
    int n, m, c = 0, x;
    map<int, ll> mp;
    mp[0]++;
    cin >> n >> m;
    while (n--)
        cin >> x,
        c += x,
        c %= m,
        mp[c]++;
    ll ans = 0;
    for (auto it: mp)
        ans += it.second * (it.second - 1) / 2;
    cout << ans;
    return 0;
}

Measured memory_bytes: 7372
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(type, v) REP(i, v.size()) { IN(type, _tmp); v.at(i) = _tmp; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

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; }
#pragma endregion

int main() {
  IN(int, N);
  int count = 0;
  int i = 10;
  while (i <= N) {
    count += (int)(i * 0.9);
    i *= 100;
  }
  i /= 10;
  if (N >= i) count += N - i + 1;
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;


int main(){
  ll K;
  cin>>K;
  ll Sv=7;
  ll Now=7;
  ll Cnt=1;
  while(Cnt<=10000000){
    if(Now%K==0){
      cout<<Cnt<<endl;
      return 0;
    }
    Cnt++;
    Sv*=10;
    Sv%=K;
    Now+=Sv;
    Now%=K;

  }
  cout<<-1<<endl;
} 

Measured memory_bytes: 3636
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

pub fn pow(x: i64, n: i64) -> i64 {
    let (mut x, mut y, mut n) = (x % P, 1_i64, n);
    while n > 0 {
        if n % 2 != 0 {
            y = (y * x) % P;
            n -= 1;
        }

        x = (x * x) % P;
        n /= 2;
    }
    y
}

fn main() {
    let (X, Y) = read!(i64, i64);

    let total = (|| {
        if (X + Y) % 3 != 0 {
            return 0;
        }

        let k = ((X + Y) / 3) as usize;
        let a = (2 * X - Y) / 3;
        let b = (2 * Y - X) / 3;
        if a < 0 || b < 0 {
            return 0;
        }

        let M = k + 1;

        let mut fact = vec![0; M];
        fact[0] = 1;
        fact[1] = 1;
        for i in 2..M {
            fact[i] = (i as i64) * fact[i - 1] % P;
        }

        let mut fact_inv = vec![0; M];
        fact_inv[M - 1] = pow(fact[M - 1], P - 2);
        for i in (1..M).rev() {
            fact_inv[i - 1] = (i as i64) * fact_inv[i] % P;
        }

        let mut t = fact[k];
        t *= fact_inv[a as usize];
        t %= P;
        t *= fact_inv[b as usize];
        t % P
    })();

    println!("{}", total)
}


Measured memory_bytes: 16636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpPractice
{
	class Program
	{
		static void Main(string[] args)
		{
			string tmp = "";
			while ((tmp = Console.ReadLine()) != null)
			{
				int n = int.Parse(tmp);
				int ans = 0;
				for (int i = 0; i < 10; i++)
				{
					for (int j = 0; j < 10; j++)
					{
						for (int k = 0; k < 10; k++)
						{
							for (int l = 0; l < 10; l++)
							{
								if (i + j + k + l == n)
								{
									ans++;
								}
							}
						}
					}
				}
				Console.WriteLine(ans);
			}
		}
	}
}

Measured memory_bytes: 13776
from collections import defaultdict

n, k = map(int, input().split())

items = []
for _ in range(n):
    ti, di = map(int, input().split())
    items.append((di, ti))

items.sort(reverse=True)

topics = defaultdict(int)
for _, ti in items[:k]:
    topics[ti] += 1

best_res = sum(v for v, _ in items[:k]) + len(topics) ** 2
curr_res = sum(v for v, _ in items[:k])

i = k - 1
j = k
while i >= 0 and j < n:
    di, ti = items[i]
    if topics[ti] < 2:
        i -= 1
        continue
    dj, tj = items[j]
    if tj in topics:
        j += 1
        continue
    if topics[ti] > 1:
        topics[ti] -= 1
    else:
        del topics[ti]
    topics[tj] += 1
    curr_res -= di
    curr_res += dj
    best_res = max(curr_res + len(topics) ** 2, best_res)
    i -= 1
        
    

print(best_res)


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int N;
int a[100000 + 10] = {};
int b[100000 + 10] = {};
int c[100000 + 10] = {};

int main(void) {
    cin >> N;
    rep(i, N) {
        cin >> a[i + 1] >> b[i + 1] >> c[i + 1];
    }

    int dp[100010][3] = {};
    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];

    for (int i = 2; i <= N; ++i) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }

    cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;;
    return 0;
}

Measured memory_bytes: 2560
icase=0
if icase==0:
    from operator import itemgetter
    n=int(input())
    sp=[]
    for i in range(n):
        si,p=input().split()
        sp.append([si,int(p),i]) 
    sp.sort(key=itemgetter(1),reverse=True)
    sp.sort(key=itemgetter(0))
#    sp.sort()
    for i in range(n):
#        print(sp[i][2]+1,sp[i][0],sp[i][1])
        print(sp[i][2]+1)
              


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int[] a=new int[100000];
        int i=0;
        while(true){
            a[i]=scan.nextInt();
            if(a[i]==0){
                break;
            }
            System.out.println("Case "+(i+1)+":"+" "+a[i]);
            i++;
        }
    }
}


Measured memory_bytes: 42456
#include <bits/stdc++.h>
using namespace std;
long long int Inv(long long int a, long long int m) {
	int c[50];
	long long int e[50];  
	c[0] = (m-2) % 2, e[0] = (m-2) / 2; 
  	for (int i = 0; i < 49; ++i){
     		c[i+1] = e[i] % 2;
     		e[i+1] = e[i] / 2;  
  	}
  	long long int d[50]; 
  	d[0] = a; 
  	for (int j = 0; j < 49; ++j){
     		d[j+1] = (d[j] * d[j]) % m; 
 	}
  	long long int Q; 
  	Q = 1; 
 	for(int k = 0; k < 49; ++k){
  		if (c[k] == 0) Q = Q; 
  		if (c[k] == 1) Q = (Q * d[k]) % m; 
  	}
 	return Q;
}
long long int P = 1e9 + 7; 
long long int Fac[314159]; 
long long int comb(long long int n, long long int r){
	long long int A = Fac[n]; 
	long long int B = Inv(Fac[r], P); 
	long long int C = Inv(Fac[n-r], P); 
	return (((A * B) % P) * C) % P; 
}
int main() {
	Fac[0] = 1; 
	for(int i = 1; i < 314159; i++){
		Fac[i] = (Fac[i-1] * i) % P; 
	}
	long long int H, W, A, B; 
	cin >> H >> W >> A >> B; 
	long long int ans = 0; 
	for(long long int i = 0; i < H - A; i++){
		ans = (ans + (comb(B-1+i, B-1) * comb(H+W-B-2-i, W-B-1))) % P; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std ;

int main(){

    int X,A;

    cin >> X>> A;

    if(X<A){
        cout << 0 << endl;
    } 
    else{
        cout << 10 <<endl;
    }

    


    
    return 0;
}



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


int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string h;
        cin>>h;
        if(h=="Y"){
            cout<<"Four\n"<<endl;
            return 0;
        }
    }
    cout<<"Three\n"<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())

def get_keta(x):
    return len(str(x))

ans = float('inf')
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        ans = min(ans, max(get_keta(i), get_keta(n // i)))

print(ans)


Measured memory_bytes: 39024
import collections
N=int(input())
V=list(map(int,input().split()))
l=N//2
V_odd=[]
V_eve=[]
for i in range(N):
  if i%2==0:
    V_odd.append(V[i])
  else:
    V_eve.append(V[i])

p_odd = list(collections.Counter(V_odd).most_common())
p_eve = list(collections.Counter(V_eve).most_common())
p_odd.append([0,0])
p_eve.append([0,0])

if p_odd[0][0]!=p_eve[0][0]:
  print(N-p_odd[0][1]-p_eve[0][1])
  exit()
else:
  print(min(N-p_odd[0][1]-p_eve[1][1],N-p_odd[1][1]-p_eve[0][1]))


Measured memory_bytes: 21212
use proconio::input;
use std::cmp;

fn main() {
    input! {
        d: usize,
        g: isize,
        pro: [(isize, isize); d],
    }
    let mut min = std::isize::MAX;

    for bit in 0..1 << d {
        let mut score = 0;
        let mut count = 0;
        let mut problem = pro.clone();
        for i in 0..d {
            if (bit >> i) & 1 != 0 {
                score += 100 * (i as isize + 1) * problem[i].0 + problem[i].1;
                count += pro[i].0;
                problem[i].0 = 0;
            }
        }
        if score >= g {
            min = cmp::min(min, count);
            continue;
        }
        let mut remain = g - score;
        //println!("bit {} remain {}, count {}", bit, remain, count);
        //greedy
        for i in (0..d).rev() {
            if problem[i].0 == 0 {
                continue;
            }
            if remain <= 0 {
                min = cmp::min(min, count);
                break;
            }
            let diff = 100 * (i as isize + 1);
            let want = (remain + (diff - 1)) / diff;
            if want > problem[i].0 {
                remain -= diff * problem[i].0 + problem[i].1;
                count += problem[i].0;
                problem[i].0 = 0;
            } else {
                remain -= diff * want;
                count += want;
            }
            //println!("bit {} remain {} count {}", bit, remain, count);
        }
        min = cmp::min(min, count);
    }
    println!("{}", min);
}


Measured memory_bytes: 2100
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int k;
    string s;
    cin>>k>>s;
    if(s.size()<=k)
        cout<<s;
    else{
        for(int i=0;i<k;i++)
        cout<<s[i];
        cout<<"...";
    }          
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
ll INF = 1001001001;
int main() {
  int N; cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  ll count=0, sum = 0;
  ll mini = INF;
  rep(i, N) {
    if(a[i]<0) count++;
    chmin(mini, ll(abs(a[i])));
    sum+=abs(a[i]);}

  if(count%2==0) cout << sum << endl;
  else cout << sum-mini*2 << endl;
}
      

Measured memory_bytes: 640
a = gets.chomp#.split(" ").map(&:to_i)

i = a.size-1

while i > 3
  if a[i-6..i] == "dreamer"
    i-=7
  elsif a[i-5..i] == "eraser"
    i-=6
  elsif a[i-4..i] == "erase"
    i-=5
  elsif a[i-4..i] == "dream"
    i-=5
  else
    break
  end
end

if i==-1
puts "YES"
else
puts "NO"
end


Measured memory_bytes: 2044
#include<stdio.h>
int main(void)
{
  char s[7];
  scanf("%s",s);
  switch(s[0]){
    case 'S':puts("Cloudy");return 0;
    case 'C':puts("Rainy");return 0;
    case 'R':puts("Sunny");return 0;
  }
}


Measured memory_bytes: 128
using System;

public class Hello{
  public static void Main(){
    int K = int.Parse(Console.ReadLine());
    char X;
    int count = 0;
    int abc = 0;
    for(int i = 0; i < K ; i++){
      X=(char)Console.Read();
      if(X == ('A')){
        abc = 1;
      }else if(abc == 1 && X == ('B')){
        abc = 2;
      }else if(abc == 2 && X == ('C')){
        count++;
        abc = 0;
      }else{
        abc = 0;
      }
    }
    Console.Write(count);
  }
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  ll x,ans=0;cin>>x;
  ll w=100;
  while(w<x){
    w*=1.01;
    ans++;
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 3624
def f(n):
    if (n+1) % 4 == 0:
        return 0
    elif (n+1) % 4 == 1:
        return n
    elif (n+1) % 4 == 2:
        return 1
    else:
        return n ^ 1
a, b = map(int, input().split())

print(f(a-1) ^ f(b))

Measured memory_bytes: 3060
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

void pakuri_sort(int N, ll A[]) {
	const int b = 12;
	ll tmp[200001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	ll S[200000];
	int N = 0;
	char c;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';

	rep(i, N) {
		ll s = 1;
		while ((c = getchar_unlocked()) >= 'a') s = s * 26 + c - 'a';
		S[i] = s;
	}

	pakuri_sort(N, S);

	int kotae = 0;
	ll mae = -1;
	rep(i, N) {
		if (mae != S[i]) {
			kotae++;
			mae = S[i];
		}
	}

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


	Would you please return 0;
}

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

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

  int a[N];
  rep(i,N) cin>>a[i];

  bool dp[K+1];

  rep(i,K+1){
    dp[i] = false;
    rep(j,N){
      if(i-a[j] >= 0) dp[i] = dp[i] | !dp[i-a[j]];
    }
  }

  if(dp[K]) cout<<"First";
  else cout<<"Second";

  return 0;

}


Measured memory_bytes: 384
/* ex 4_1
   cy_an  */

#include <stdio.h>
#include <math.h>

int main(void){
    int num_N, work_D, staff;           // 変数宣言
    scanf("%d %d", &num_N, &work_D);    // 入力

    staff = (num_N / (1 + 2 * work_D)); // staffの計算
    if(num_N % (1 + 2 * work_D) == 0){  // 余りが0のとき
        printf("%d", staff);            // staffを出力
    }else{                              // 余りが0でないとき
        printf("%d", ++staff);          // staffに1を足して出力
    }
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  
  int s[n];
  for(int i=0; i<n; i++) cin >> s[i];
  
  int ans=1;
  
  for(int i=0; i<n; i++){
    if(s[i]%2 == 0){
      if(s[i]%3 != 0 && s[i]%5 != 0) ans=ans-1;
      else continue;
    }
  }
  
  if(ans==1) cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
<?php
    fscanf(STDIN,"%d%d%d",$A,$B,$C);
    
    if($A==$B){
        if($B!=$C){
            echo "Yes";
            exit;
        }
    }
    if($A==$C){
        if($B!=$A){
            echo "Yes";
            exit;
        }
    }
    if($C==$B){
        if($A!=$C){
            echo "Yes";
            exit;
        }
    }
    echo "No";
?>

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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    vector<ll> psum(n + 1, 0);
    for(ll i = 1; i <= n; ++i) {
        psum[i] = psum[i - 1] + i;
    }
    for(ll i = k; i <= n; ++i) {
        ll mn = psum[i - 1];
        ll mx = psum[n] - psum[n - i];
        ans += mx - mn + 1;
        ans %= mod;
    }
    cout << ans + 1 << "\n";
    return 0;
}



Measured memory_bytes: 4784
//
// Created on 2020/08/22.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int n,x,t;
    cin>>n>>x>>t;
    int ans_cnt = (n + (x - 1)) / x;
    int ans = ans_cnt * t;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3620
n = gets.chomp.to_i
as = Array.new(n)
n.times do |i|
  as[i] = []
  a = gets.chomp.to_i
  a.times do
    xy = gets.split.map(&:to_i)
    xy[0] -= 1
    xy[1] = xy[1] == 1
    as[i] << xy
  end
end

solve = ->i,s {
  if i == n
    (0...n).select { |j| (s&(1<<j)) != 0 }.each do |j|
      return 0 if as[j].any? { |k, b| ((s&(1<<k)) != 0) != b }
    end.length
  else
    r1 = solve.(i+1, s)
    r2 = solve.(i+1, s | (1<<i))
    r1 > r2 ? r1 : r2
  end
}

puts solve.(0, 0)

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

int main()
{
	int n;
	std::cin >> n;
	int ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;
	for (int i = 0; i < n; i++)
	{
		std::string x;
		std::cin >> x;
		if (x == "AC")
			++ac;
		if (x == "WA")
			++wa;
		if (x == "TLE")
			++tle;
		if (x == "RE")
			++re;
	}
	std::cout << "AC x " << ac << '\n';
	std::cout << "WA x " << wa << '\n';
	std::cout << "TLE x " << tle << '\n';
	std::cout << "RE x " << re << '\n';
	return (0);
}

Measured memory_bytes: 3592
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

#define MOD 1000000007

ll calcz(ll x, ll y){
  ll a = x, b = MOD;
  ll tmp;
  vector<ll> syo;
  while(a > 1){
    syo.push_back(b / a);
    tmp = b % a;
    b = a;
    a = tmp;
  }
  ll dp1 = 0, dp2 = 1;
  rrep(i, syo.size()){
    ll tmp = (dp2 * (-syo[i]) + dp1) % MOD;
    dp1 = dp2;
    dp2 = tmp;
  }
  y = (y + MOD) % MOD;
  dp2 = (dp2 + MOD) % MOD;
  return (y % 10000 * dp2 % MOD + (y / 10000) * dp2 % MOD * 10000) % MOD;
}

ll comb(int n, int r) {
  ll val = 1;
  repi(a, n-r+1, n+1) val = (val * a) % MOD;
  repi(a, 1, r+1) val = calcz(a, val);
  return val;
}

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

  vector<ll> primes;
  for(ll n=2;n*n<=M;n++){
    ll n_pow = 0;
    while(M % n == 0){
      n_pow++;
      M /= n;
    }
    if(n_pow) primes.push_back(n_pow);
  }
  if(M > 1) primes.push_back(1);

  ll ans = 1;
  for(vector<ll>::iterator itr = primes.begin(); itr != primes.end(); ++itr) {
    ans = (ans * comb(N + *itr - 1, *itr)) % MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
M=10**9+7
s=input()
r=range
k=[1]+[0]*12
for c in s:
  l=[0]*13
  for i in r(13):
    if c=='?':
      for j in r(10): l[(i*10+j)%13]+=k[i]
    else: l[(i*10+int(c))%13]+=k[i]
  for i in r(13): k[i]=l[i]%M
print(k[5])

Measured memory_bytes: 43244
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion

int main()
{
	string s; cin >> s;
	int n = s.size();
	string t = s.substr(0, n / 2);
	bool ok = true, okok = true;
	rep(i, n / 2)if (s[i] != s[n - 1 - i])ok = false;
	int m = t.size();
	rep(i, m / 2)if (t[i] != t[m - 1 - i])okok = false;
	if (ok&&okok)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = Long.parseLong(sc.next());
        long NUM = 5_000_000_000_000_000L;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '1' && k == i + 1) {
                System.out.println(s.charAt(i));
                return;
            }
            if (s.charAt(i) != '1') {
                System.out.println(s.charAt(i));
                return;
            }
        }
        System.out.println(1);
    }
}

Measured memory_bytes: 21844
import java.io.*;

public class Main{
    public static void main(String [] args) throws NumberFormatException, IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] st=br.readLine().split(" ");
        int a=Integer.parseInt(st[0]);
        int b=Integer.parseInt(st[1]);
        int c=Integer.parseInt(st[2]);
        System.out.println(a<b&&b<c?"Yes":"No");
    }
}

Measured memory_bytes: 24236
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>

#define INF 100000000

using namespace std;

int main()
{
    double t, x;
    cin >> t >> x;
    cout << t / x << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D2017LikeNumber solver = new D2017LikeNumber();
        solver.solve(1, in, out);
        out.close();
    }

    static class D2017LikeNumber {
        ArrayList<Integer> primes = Prime.eratosthenes(100000);

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int[] acc = new int[100001];
            for (int i = 1; i <= 100000; i++) {
                acc[i] = acc[i - 1] + (isLike(i) && isLike((i + 1) / 2) ? 1 : 0);
            }
            int q = in.nextInt();
            for (int i = 0; i < q; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                out.println(acc[r] - acc[l - 1]);
            }
        }

        boolean isLike(int x) {
            int ng = -1;
            int ok = primes.size();
            while (Math.abs(ok - ng) > 1) {
                int mid = (ok + ng) / 2;
                if (primes.get(mid) > x) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            if (ng == -1) return false;
            return x == primes.get(ng);
        }

    }

    static class Prime {
        public static ArrayList<Integer> eratosthenes(int n) {
            // n以下の素数をすべて列挙する(計算量は O(N log(log N)))
            // ただし10^5が耐用限界っぽい感じはする

            ArrayList<Integer> res = new ArrayList<>();
            ArrayList<Integer> primes = new ArrayList<>();
            for (int i = 2; i <= n; i++) {
                res.add(i);
            }
            while (res.size() > 0) {
                primes.add(res.get(0));
                res.removeIf(a -> a % res.get(0) == 0);
            }
            return primes;
        }

    }
}



Measured memory_bytes: 68828
#include <bits/stdc++.h>
#define xx first
#define yy second
#define ll long long
using namespace std;

struct _in {
	const _in operator , (int &a) const {
		a = 0; char k = getchar (); int f = 1;
		while (k > '9' || k < '0') { if (k == '-') f = -1; k = getchar (); }
		while (k >= '0' && k <= '9') { a = a * 10 + k - '0'; k = getchar (); }
		a *= f;
		return*this;
	}
}in;

//const int N = ;
/*const int mod = ;
inline int add (int u, int v) { return u + v >= mod ? u + v - mod : u + v; }
inline int sub (int u, int v) { return u - v < 0 ? u - v + mod : u - v; }
inline int mul (int u, int v) { return 1LL * u * v % mod; }
inline int qpow (int base, int v) {
	int tot = 1;
	while (v) {
		if (v & 1) tot = mul (tot, base);
		base = mul (base, base);
		v >>= 1;
	}
	return tot;
}*/

const int N = 100000 + 5;
int n, m;
ll sum = 0;
priority_queue<int> Q;

int main () {
	in, n, m;
	for (int i = 1; i <= n; ++i) {
		int x; in, x;
		Q.push (x);
		sum += x;
	}
	while (m--) {
		int k = Q.top (); Q.pop ();
		sum -= k;
		k /= 2;
		Q.push (k);
		sum += k;
	}
	printf ("%lld\n", sum);
	return 0;
}






























Measured memory_bytes: 892
#include<bits/stdc++.h>
#define mtp make_tuple
#define mpr make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
inline void qread(){}
template<class T1, class ...T2>
inline void qread(T1 &IEE, T2&... ls){
	register T1 __ = 0, ___ = 1;
	register char ch;
	while(!isdigit(ch = getchar())) ___ = (ch == '-') ? -___ : ___;
	do{
		__ = (__ << 1) + (__ << 3) + (ch ^ 48);
	}while(isdigit(ch = getchar()));
	__ *= ___;
	IEE = __;
	qread(ls...);
	return ;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
template<class T>
inline T ab(T a){
	return (a > 0) ? a : -a;
}
template<class T>
inline void swa(T &a, T &b){
	a ^= b ^= a ^= b;
	return ;
}
ll tot, ans, n, m, x;
ll cnt[maxn], c[maxn];
ll a[maxm][maxm];
int main(){
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	qread(n, m, x);
	for(int i = 1;i <= n;i++){
		qread(c[i]);
		for(int j = 1;j <= m;j++){
			qread(a[i][j]);
		}
	}
	tot = 0x3f3f3f3f3f3f3f3fll;
	for(int i = 0;i < (1 << n);i++){
		for(int j = 1;j <= m;j++){
			cnt[j] = 0;
		}
		ans = 0;
		for(int j = 0;j < n;j++){
			if((i & (1 << j))){
				ans += c[j + 1];
				for(int k = 1;k <= m;k++){
					cnt[k] += a[j + 1][k];
				}
			}
		}
		bool f = 0;
		for(int j = 1;j <= m;j++){
			if(cnt[j] < x){
				f = 1;
			}
		}
		if(!f) tot = min(tot, ans);
	}
	if(tot == 0x3f3f3f3f3f3f3f3fll){
		puts("-1");
		return 0;
	}
	cout << tot << endl;
	return 0;
}


Measured memory_bytes: 3696
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()

	box := make([]int, n)
	for i := range box {
		box[i] = 1
	}
	exist := make([]bool, n)
	exist[0] = true

	for i := 0; i < m; i++ {
		x, y := nextInt()-1, nextInt()-1
		if exist[x] {
			exist[y] = true
			if box[x] == 1 {
				exist[x] = false
			}
		}
		box[x]--
		box[y]++
	}

	ans := 0
	for i := 0; i < n; i++ {
		if exist[i] {
			ans++
		}
	}
	puts(ans)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 2688
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b)
{
	ll res = 1;
	a %= mod;
	assert(b >= 0);
	for (; b; b >>= 1)
	{
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
	}
	return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

static uint MD = mod;
struct ModInt
{
	using M = ModInt;
	uint v;
	ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
	M &set_v(uint _v)
	{
		v = (_v < MD) ? _v : _v - MD;
		return *this;
	}
	explicit operator bool() const { return v != 0; }
	M operator-() const { return M() - *this; }
	M operator+(const M &r) const { return M().set_v(v + r.v); }
	M operator-(const M &r) const { return M().set_v(v + MD - r.v); }
	M operator*(const M &r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
	M operator/(const M &r) const { return *this * r.inv(); }
	M &operator+=(const M &r) { return *this = *this + r; }
	M &operator-=(const M &r) { return *this = *this - r; }
	M &operator*=(const M &r) { return *this = *this * r; }
	M &operator/=(const M &r) { return *this = *this / r; }
	bool operator==(const M &r) const { return v == r.v; }
	M pow(ll n) const
	{
		M x = *this, r = 1;
		while (n)
		{
			if (n & 1)
				r *= x;
			x *= x;
			n >>= 1;
		}
		return r;
	}
	M inv() const { return pow(MD - 2); }
	friend ostream &operator<<(ostream &os, const M &r) { return os << r.v; }
};
using Mint = ModInt;
//head
// cin >> t;
// for (int cas = 1; cas <= t; ++cas)
// {
// 	cout << "Case #" << cas << ": ";
// }
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	rep(i,0,sz(s)) {
		if(s[i]=='?') cout<<'D';
		else cout<<s[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3772