akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include "bits/stdc++.h"

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
	int n;
	cin >> n;
	string response;
	string s;
	s.resize(n + 1);
	cout << 0 << endl;
	cin >> response;
	if (response[0] == 'V')
		return 0;
	s[0] = response[0];
	s[n] = response[0];
	int l = 0, r = n;
	while (l + 1 < r) {
		int m = (l + r) >> 1;
		cout << m << endl;
		cin >> response;
		s[m] = response[0];
		if (response[0] == 'V')
			return 0;
		if ((s[m] != s[l]) xor ((m - l) & 1)) {
			r = m;
		} else {
			l = m;
		}
	}
	cout << ((l + r) >> 1) << endl;
}


Measured memory_bytes: 980
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define Nmax 55

ll mo;

ll po(ll x,ll y){ if(y<0)cout<<1/0<<endl;
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x;
	x=x*x;
    }
    return res;
}

ll pomo(ll x,ll y){ if(y<0)cout<<1/0<<endl;
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x%mo;
	x=x*x%mo;
    }
    return res;
}

struct matrix{
    ll t[3][3];
};
matrix mul(matrix a,matrix b){
    matrix c;
    for(int i=0;i<3;i++)for(int j=0;j<3;j++){
	ll res=0;
	for(int k=0;k<3;k++){
	    res+=a.t[i][k]*b.t[k][j];
	}
	c.t[i][j]=res%mo;
    }
    return c;
}
ll solve(ll d,ll a,ll b,ll l){
    matrix r[66];
    ll kei[]={1,b%mo,0,0,po(10,d)%mo,0,1,a%mo,1};
    for(int i=0;i<3;i++)for(int j=0;j<3;j++){
	r[0].t[i][j]=kei[i*3+j];
    }
    for(int i=1;i<62;i++)r[i]=mul(r[i-1],r[i-1]);
    matrix res; bool fi=1;
    for(int i=0;i<62;i++){
	if((1LL<<i)&l){
	    if(fi)res=r[i],fi=0;
	    else res=mul(res,r[i]);
	}
    }
    return res.t[2][1];
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll l,a,b;
    cin>>l>>a>>b>>mo;
    ll ans=0;
    ll ruiketa=1;
    for(int d=18;d>=1;d--){
	if(po(10,d)<=a)continue;
	if(a+b*(l-1)<po(10,d-1))continue;
	ll s=a; if(s<po(10,d-1))s=a+(po(10,d-1)-1-a+b)/b*b;
	ll t=a+b*(l-1); if(po(10,d)<=t)t=a+(po(10,d)-1-a)/b*b;
	ll len=(t-s)/b+1;
	if(len>0){
	    ll res=solve(d,s,b,len); //cout<<d<<" "<<s<<" "<<b<<" "<<len<<" "<<res<<endl;
	    ans=ans+ruiketa*res; ans%=mo;
	    ruiketa=ruiketa*pomo(pomo(10,len),d)%mo;
	}
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 256
//Written by Rhitwik Saha//
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vb          vector<bool>
#define vc          vector<char>
#define vii         vector<pii>
//#define mi          map<int,int>
//#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define ub(x)       upper_bound(x)
#define lb(x)       lower_bound(x)
#define endl        '\n'
#define file        freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define fastio      ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// #define N 			1e5+5
#define M           1000000007
#define MAX         100005
#define mem0(a)     memset(a,0,sizeof(a))
#define prec        cout<<std::setprecision(9)<<std::fixed
#define forn(i,a,b)  for(int i=a;i<b;i++)
// const double long rf=14;
int i,j,k;

void Anon_mouS(){
	// string s;
    int n;
    cin>>n;
    prec;
    double l=1.0*n/3;
    cout<<pow(l,3);
}

int32_t main(){
	// func();
    fastio;
    // file;
    // sieve();
    int q=1;
    // cin>>q;
    while(q--)Anon_mouS();
    return 0;
}


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

A = list(map(int,input().split()))
F = list(map(int,input().split()))

A.sort()
F.sort(reverse=True)

def is_ok(x):
    c = 0
    for a, f in zip(A, F):
        c += max(0, a-x//f)
    if c <= k:
        return True
    else:
        return False

ng = -1
ok = 10**18
while ng+1 < ok:
    c = (ng+ok)//2
    if is_ok(c):
        ok = c
    else:
        ng = c
print(ok)


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

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

	vector<int> players(N);
	for (int &x: players)
		cin >> x;

	sort(players.rbegin(), players.rend());

	int64_t ans = 0;
	for (int i = 0, t = 0; t < N - 1; ) {
		ans += players[i];
		if (++t & 1) ++i;
	}

	cout << ans << endl;
}


Measured memory_bytes: 4056
//@author :  |< U $ |-|
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#include<unordered_map>
#define ll long long
#define vi vector<long long>
#define pb push_back
#define po pop_back
#define pi pair<long long ,long long>
#define vp vector<pair<long long,long long> >
#define mkp make_pair
#define in(i,n) for(i=0;i<n;i++)
#define fon(i,n,m) for(i=n;i<m;i++)
#define rfon(i,n,m) for(i=n;i>=m;i--)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);
#define map map<long long,long long>
#define inm1(b)  memset(b,-1,sizeof(b))
#define in0(b) memset(b,0,sizeof(b))
#define ininf(b) memset(b,1000000001,sizeof(b))
#define MOD         1000000007
#define I 1000000000000000001
#define TakeInput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
using namespace std;
ll gcd(ll a, ll b) {  if (a == 0)  return b; return gcd(b % a, a); }

int main()
{
    jaldi
    #ifndef ONLINE_JUDGE
    //TakeInput
    #endif
    double n,m;
    cin>>n>>m;
    cout<<ceil(n/m);
}








 




Measured memory_bytes: 256
#include <iostream>
#include <complex>
using namespace std;
typedef complex<int> C;

int n;

C l[51][11];
int ml[51];

void solve() {
  for (int i = 0; i <= n; i += 1) {
    cin>>ml[i];
    int bx, by; cin>>bx>>by;
    for (int j = 0; j < ml[i]-1; j += 1) {
      int nx, ny; cin>>nx>>ny;
      l[i][j].real() = nx - bx;
      l[i][j].imag() = ny - by;
      bx = nx;
      by = ny;
    }
  }
  
  for (int i = 1; i <= n; i += 1) {
    if (ml[0] != ml[i]) continue;
    bool is_printed = false;
    for (int j = 0; j < 4; j += 1) {
      bool flag = true;
      for (int k = 0; k < ml[0]-1; k += 1) {
        l[i][k] *= C(0,1);
      }
      for (int k = 0; k < ml[0]-1; k += 1) {
        /*
        cout<<i<<"|"<<j<<"|";
        cout<<l[0][k].real()<<","<<l[0][k].imag();
        cout<<l[i][k].real()<<","<<l[i][k].imag()<<endl;
        */
        if (l[0][k] != l[i][k]) {flag = false;break;}
      }
      if (flag) {
        cout<<i<<endl;
        is_printed = true;
        break;
      }
    }
    if (!is_printed) {
      for (int j = 0; j < 4; j += 1) {
        bool flag = true;
        for (int k = 0; k < ml[0]-1; k += 1) {
          l[i][k] *= C(0,1);
        }
        for (int k = 0; k < ml[0]-1; k += 1) {
          /*
          cout<<i<<"|"<<j<<"|";
          cout<<l[0][k].real()<<","<<l[0][k].imag();
          cout<<l[i][ml[0]-2-k].real()<<","<<l[i][ml[0]-2-k].imag()<<endl;
          */
          if (l[0][k] != l[i][ml[0]-2-k]) {flag = false;break;}
        }
        if (flag) {
          cout<<i<<endl;
          break;
        }
      }
    }
  }
  
  cout<<"+++++"<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>n, n) {
    solve();
  }
  return 0;
}

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

int main(){
    long int n,a,b,syo,amari,ans=1;
    //vector<int> box(2,0);
    cin >> n >> a >> b;

    syo=n/(a+b);
    amari=n%(a+b);

    ans=a*syo;

    if((amari-a)>=0){
        ans+=a;
    }else{
        ans+=amari;
    }

    cout << ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
A,B,C,D,E,F = map(int,input().split())
concent = 0
ans = []
for one in range(F//(100*A)+1):
    for two in range((F-100*A*one)//(100*B)+1):
        for three in range((F-100*A*one-100*B*two)//C+1):
            for four in range((F-100*A*one-100*B*two-C*three)//D+1):
                water = 100*A*one+100*B*two
                sugar = C*three+D*four
                all = water + sugar
                if all == 0:
                    continue
                if E*water//100 < sugar or all > F:
                    continue
                if concent < 100*sugar/all:
                    concent = 100*sugar/all
                    ans = [all,sugar]
if len(ans) == 0:
    print(str(100*A)+' '+str(0))
else:
    print(str(ans[0])+' '+str(ans[1]))

Measured memory_bytes: 42204
#include <stdio.h>

int kaibun(int n, char *s){
  int i, judge;
  judge = 1;
  for(i=0; i<n/2; i++){
    if(s[i] != s[n-1-i]){
      judge = 0;
    }
  }
  return judge;
}

int main(void){//文字数nは3から99の奇数
  char s[256];
  int i, n;
  int judge=1;
  scanf("%s", s);
  for(i=0; s[i]!='\0'; i++);
  n = i;
  judge = kaibun(n, s);
  if(judge==0){
    printf("No\n");
  }else{
    judge = kaibun((n-1)/2, s);
    if(judge==0){
      printf("No\n");
    }else{
      printf("Yes\n");
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <iostream>
using namespace std;
int main()
{
	long long int n, a[100010], cnt[100010] = {}, yan = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	if (n % 2) {
		for (int i = 0; i < n; i++) {
			if (i % 2) {
				if (cnt[i]) {
					yan = 1;
					break;
				}
			}
			else {
				if (!i) {
					if (cnt[0] != 1) {
						yan = 1;
						break;
					}
				}
				else {
					if (cnt[i] != 2) {
						yan = 1;
						break;
					}
				}
			}
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			if (i % 2) {
				if (cnt[i] != 2) {
					yan = 1;
					break;
				}
			}
			else {
				if (cnt[i]) {
					yan = 1;
					break;
				}
			}
		}
	}
	long long int ans = 1, mod = 1e9 + 7;
	n /= 2;
	if (yan)cout << 0 << endl;
	else {
		for (int i = 1; i <= n; i++) {
			ans *= 2;
			ans %= mod;
		}
                cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
stack<int> oo;
string u;
int ans=0,j=1;
int b[100010];
int main()
{
	cin>>u;
	for(int i=0;i<u.size();i++)
	{
		b[i]=u[i]-'0';
	}
//	cout<<u.size();
	
	for(int i=0;i<u.size();i++)
	{
		if(oo.empty())
		{
			oo.push(b[i]);
			continue;
		}
		if(b[i]!=oo.top())
		{
			ans+=2;
			oo.pop();
			continue;
		}
		 if(b[i]==oo.top())
		{
			oo.push(b[i]);
			continue;
		}
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 4496
#include <stdio.h>

int main(int argc, char **argv)
{
    int a, b, ans;
    char op;
    scanf("%d %c %d", &a, &op, &b);

    if (op == '+') {
        ans = a + b;
    } else {
        ans = a - b;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,m;
	cin>>n>>m;
	pair<int,int> a[101010]={};
	FOR(i,0,n){
		int aa,aaa;
		cin>>aa>>aaa;
		a[i]=MP(aa,aaa);
	}
	sort(a,a+n);
	LL ans=0;
	FOR(i,0,n){
		if(m>=a[i].ND){
			m-=a[i].ND;
			ans+=1LL*a[i].ST*a[i].ND;
		}else{
			ans+=1LL*a[i].ST*m;
			break;
		}
	}
	cout<<ans;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<map>

using namespace std;

int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}

const int N=1e6+5;
int n,m,fa[N],ans[N],vis[N];

struct Edge
{
	int v,ne;
}e[N];
int head[N],tot;

inline void add(int u,int v);
void bfs();

int main()
{
	n=read();m=read();
	for(int i=1;i<=n;++i)
		fa[i]=i;
	for(int i=1;i<=m;++i)
	{
		int u=read(),v=read();
		add(u,v);
		add(v,u);
	}
	bfs();
	if(m<n-1) printf("No\n");
	else
	{
		printf("Yes\n");
		for(int i=2;i<=n;++i)
			printf("%d\n",ans[i]);
	}
	return 0;
} 

inline void add(int u,int v)
{
	e[++tot]=(Edge){v,head[u]};
	head[u]=tot;
}

void bfs()
{
	queue<int> qu;
	qu.push(1);
	while(!qu.empty())
	{
		int u=qu.front();
		qu.pop();
		for(int i=head[u];i;i=e[i].ne)
		{
			int v=e[i].v;
			if(!vis[v])
			{
				vis[v]=1;
				ans[v]=u;
				qu.push(v);
			}
		}
	}
}

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

int main(void){
	char s[1000];
	int i;
	
	fgets(s,sizeof(s),stdin);
	
	for(i = 0;i < strlen(s);i++){
		if(s[i] >= 'A'&&s[i] <= 'Z')s[i] += 32;
		else if(s[i] >= 'a'&&s[i] <= 'z')s[i] -=32;
	}
	
	printf("%s",s);
	return 0;
}

Measured memory_bytes: 524
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

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

int main()
{
        //input->compute->output//

        int A, B;
        cin >> A >> B;

        if (A == 1 && B == 1)
        {
                cout << "Draw" << endl;
        }
        else if (A == 1)
        {
                cout << "Alice" << endl;
        }
        else if (B == 1)
        {
                cout << "Bob" << endl;
        }
        else
        {
                if (A < B)
                {
                        cout << "Bob" << endl;
                }
                else if (A == B)
                {
                        cout << "Draw" << endl;
                }
                else
                {
                        cout << "Alice" << endl;
                }
        }

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, u, v, z = 1, b[200005] = {};
    vector<int> g[200005] = {};
    cin >> n >> m;
    while (m--) cin >> u >> v, g[u].push_back(v), g[v].push_back(u);
    queue<int> q;
    for (int i = 1; i <= n; i++) if (!b[i]) {
        q.push(i);
        b[i] = 1;
        int c = 1;
        while (!q.empty()) {
            int x = q.front();
            q.pop();
            for (int j : g[x]) if (!b[j]) b[j] = 1, c++, q.push(j);
        }
        z = max(z, c);
    }
    cout << z;
}


Measured memory_bytes: 15756
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(text){console.log(text);}//standard output
//[no]param
//0:noConvert	1:singleNum	2:spaceList	3:newLineList	4:spaceNumList	5:newLineNumList
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,0);
  var output = "Yes";
  if((input.indexOf("N") != -1 && input.indexOf("S") == -1) || 
     (input.indexOf("N") == -1 && input.indexOf("S") != -1) || 
    (input.indexOf("E") != -1 && input.indexOf("W") == -1) || 
    (input.indexOf("E") == -1 && input.indexOf("W") != -1)){
     output = "No";
  }
  myout(output);
}

Main(myin());


Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Combination
{
	vector<ll> fact, inv, invFact;
	int MAX_FACT;
	ll MOD;
	Combination(int n, ll mod) : fact(n + 1), inv(n + 1), invFact(n + 1)
	{
		MAX_FACT = n + 1;
		MOD = mod;
		fact[0] = 1;
		fact[1] = 1;
		invFact[0] = 1;
		invFact[1] = 1;
		inv[1] = 1;
		for (auto i = 2; i < MAX_FACT; ++i)
		{
			fact[i] = fact[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
			invFact[i] = invFact[i - 1] * inv[i] % MOD;
		}
	}

	unsigned long long calcCombination(int n, int k)
	{
		if (n < k)
		{
			return 0;
		}
		if ((n < 0) || (k < 0))
		{
			return 0;
		}

		return fact[n] * (invFact[k] * invFact[n - k] % MOD) % MOD;
	}
};


int main()
{
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

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

	auto mod = (ll)1e9 + 7;
	Combination comb(N, mod);

	vector<ll> sum(N);
	sum[0] = A[0];
	for (auto i = 1; i < N; ++i)
	{
		sum[i] = sum[i - 1] + A[i];
	}

	auto result = 0ll;
	if (K > 1)
	{
		for (auto j = K; j <= N; ++j)
		{
			auto temp = (sum[N - 1] - sum[N - 1 - j + 1] - sum[j - 2]) % mod;
			temp = temp * comb.calcCombination(j - 2, K - 2) % mod;
			result = (result + temp) % mod;
		}
	}

	cout << result << endl;

	return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int ans = 0;
int n;

void dfs(vector<vector<int>> &A, string f) {
	if (sz(f) == n) {
		rep(i, sz(f)) {
			if (f[i] == '0') continue;
			rep(j, sz(f)) {
				if (A[i][j] == -1) continue;
				if (A[i][j] == 0 && f[j] == '1') return;
				if (A[i][j] == 1 && f[j] == '0') return;
			}
		}
		int cnt = 0;
		rep(i, sz(f)) {
			if (f[i] == '1') cnt++;
		}
		ans = max(ans, cnt);
		return;
	}
	dfs(A, f + "0");
	dfs(A, f + "1");
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	cin >> n;
	vector<vector<int>> A(n, vector<int>(n, -1));
	rep(i, n) {
		int a;
		cin >> a;
		rep(j, a) {
			int x, y;
			cin >> x >> y;
			x--;
			A[i][x] = y;
		}
	}

	dfs(A, "");

	out(ans);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int c;

bool ans(int a){
	if(a == 0){
		return 1;
	}
	if(a < 0) return 0;
	return max(ans(a-4), max(ans(a-7), ans(a-11)));
}

int main(){
	cin >> c;
	
	if(ans(c)) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;
 
int main(){
    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i=0; i<H; i++){
        cin >> S[i];
    }
    vector<vector<char>> vec(H, vector<char>(W));
    for(int i=0; i<H; i++){
      for(int j=0; j<W; j++){
          vec[i][j] = S[i][j];
      }
    }
    ll max = 0;
    ll m = 0;
    for(int i=0; i<H; i++){
      for(int j=0; j<W; j++){
          if(m > 0){
              break;
          }
          if(vec[i][j] == '#'){
              continue;
          }
          else{
              int k = 0; int p = i;
              while(0<=p){
                  if(vec[p][j] == '#'){
                      break;
                  }
                  else{
                      p -= 1; k++;
                  }
              }
              p = i;
              while(p < H){
                  if(vec[p][j] == '#'){
                      break;
                  }
                  else{
                      p++; k++;
                  }
              }
              int q = j;
              while(0 <= q){
                  if(vec[i][q] == '#'){
                      break;
                  }
                  else{
                      q -= 1; k++;
                  }
              }
              q = j;
              while(q<W){
                  if(vec[i][q] == '#'){
                      break;
                  }
                  else{
                      q++; k++;
                  }
              }
              k -= 3;
              if(k > max){
                  max = k;
              }
              if(k == H+W-1){
                  m++;
              }
          }
      }
    }
    cout << max;
}

Measured memory_bytes: 8320
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>

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; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

string s, t;

int f(int sc, string& s, char cl, char cr) {
	int cnt = 1;
	sc++;
	while (cnt > 0) {
		if (s[sc] == cl) cnt++;
		if (s[sc] == cr) cnt--;
		sc++;
	}
	return sc;
}

int num(int l, int r, string &s) {
	int res = 0;
	for (int i = l; i < r; i++) {
		res = res * 10 + (s[i] - '0');
	}
	return res;
}

string dfs(int sl, int sr, int tl, int tr) {
	if (sl == sr or tl == tr) return "";

	int sc1 = f(sl, s, '(', ')');
	int tc1 = f(tl, t, '(', ')');
	string L = '(' + dfs(sl + 1, sc1 - 1, tl + 1, tc1 - 1) + ')';
	int sc2 = f(sc1, s, '[', ']');
	int tc2 = f(tc1, t, '[', ']');
	int sn = num(sc1 + 1, sc2 - 1, s);
	int tn = num(tc1 + 1, tc2 - 1, t);
	string M = '[' + to_string(sn + tn) + ']';
	int sc3 = f(sc2, s, '(', ')');
	int tc3 = f(tc2, t, '(', ')');
	string R = '(' + dfs(sc2 + 1, sc3 - 1, tc2 + 1, tc3 - 1) + ')';
	return L + M + R;

}
int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	cin >> s >> t;
	cout << dfs(0, s.size(), 0, t.size()) << endl;
}



Measured memory_bytes: 3308
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll) 1000000007
#define P pair<ll, ll>



string s;
ll dp[110000][2];
int main() {
	cin >> s;
	dp[0][0] = 1;
	REP(i, s.size()) {
		dp[i + 1][1] += dp[i][1] * 3;
		dp[i + 1][1] %= MOD;
		if (s[i] == '1') {
			dp[i + 1][1] += dp[i][0];
			dp[i + 1][1] %= MOD;
			dp[i + 1][0] += dp[i][0] * 2;
			dp[i + 1][0] %= MOD;
		}
		else {
			dp[i + 1][0] += dp[i][0];
			dp[i + 1][0] %= MOD;
		}
	}
	cout << (dp[s.size()][0] + dp[s.size()][1]) % MOD<< endl;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,a;
    while (cin>>n>>m>>a) {
        if (n==0&&m==0&&a==0) {
            break;
        }
        int h,p,q;
        std::multimap<int, pair<int,int>> map;
        std::map<int, int> seen;
        for (int i=0;i<m;i++) {
            cin>>h>>p>>q;
            map.insert(make_pair(h,make_pair(p,q)));
            seen[h]++;
        }
        for (int i=1000;i>0;i--) {
            if (seen[i]!=0) {
                auto e=map.equal_range(i);
                for (auto itr=e.first;itr!=e.second;itr++) {
                    int P=itr->second.first,Q=itr->second.second;
                    if (P==a) {
                        a=Q;
                    } else if (Q==a) {
                        a=P;
                    }
                }
            }
        }
        cout<<a<<endl;
    }
}


Measured memory_bytes: 3132
import java.util.Scanner;
import java.util.stream.IntStream;

@SuppressWarnings("unused")
public class Main {

	public static void main(String[] args) throws Exception {
		Main main = new Main();

		try (Scanner scan = new Scanner(System.in)) {
			main.diceAndCoin(scan);
		}
	}

	private void diceAndCoin(Scanner scan) {
		int n = scan.nextInt();
		int k = scan.nextInt();

		double ans = IntStream.rangeClosed(1, n)
			.mapToDouble(i -> ((double) 1 / n) * powProb(k, i))
			.sum();

		System.out.println(ans);
	}

	private double powProb(int k, int i) {
		return (double) 1 / Math.pow(2, Math.ceil((Math.log(Math.ceil((double) k / i))) / Math.log(2)));
	}

	private void yymmOrMmyy(Scanner scan) {
		String s = scan.next();

		int f = Integer.valueOf(s.substring(0, 2));
		int l = Integer.valueOf(s.substring(2, 4));
		boolean yOkF = true, yOkL = true;

		if (f > 12 || f < 1) {
			yOkF = false;
		}
		if (l > 12 || l < 1) {
			yOkL = false;
		}
		if (yOkF) {
			if (yOkL) {
				System.out.println("AMBIGUOUS");
			} else {
				System.out.println("MMYY");
			}
		} else {
			if (yOkL) {
				System.out.println("YYMM");
			} else {
				System.out.println("NA");
			}
		}

	}

	private void changingACharchter(Scanner scan) {
		scan.nextInt();
		int k = scan.nextInt();
		char[] s = scan.next().toCharArray();

		s[k - 1] = Character.toLowerCase(s[k - 1]);
		System.out.println(new String(s));

	}

}


Measured memory_bytes: 28628
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;}
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    string s; cin >> s;
    ll ans = 0;
    ll cnt = 0;
    rep(i, 3){
        if(s[i] == 'R'){
            cnt++;
        }else{
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;

}

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

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef pair < ll , ll > pp;
const int mod = 1e9 + 7;
const int N   = 2e5 + 5;

int a[5],t;

signed main(){
    cin >> a[1] >> a[2] >> a[3];
    sort(a+1 , a+3+1);
    t = a[3]-a[2] + a[3]-a[1];
    cout << t/2 + (t&1 ? 2 : 0);
    return 0;
}   

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

using ll = long long;

//constant
const double EPS = 1e-10;
ll MOD = 1000000007;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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

// ***************************************

int main(void) {

	int H, W, K;

	cin >> H >> W >> K;

	vector<vector<char>> S(H, vector<char>(W));

	REP(i, H) {
		REP(j, W) {
			cin >> S[i][j];
		}
	}

	ll ans = 1e10;
	for(ll bit = (1<<9)-1; bit >= 0; bit--) {
		ll count_div = 0;
		REP(h, H-1) {
			if (bit & 1 << h) {
				count_div++;
			}
		}
		vector<ll> count(count_div + 1);
		REP(w, W) {
			int groups = 0;
			REP(h, H) {
				if (S[h][w] == '1') {
					count[groups]++;
					if (count[groups] > K) {
						count_div++;
						fill(ALL(count), 0);
						w--;
						break;
					}
				}
				if (bit & 1 << h) {
					groups++;
				}
			}
			if (count_div >= ans) {
				break;
			}
		}
		chmin(ans, count_div);
	}


	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 384
<?php
$N=trim(fgets(STDIN));
$A=trim(fgets(STDIN));
$A=explode(' ',$A,$N);

$out=implode(' ',$A).PHP_EOL;
for($i=1;$i<$N;$i++){
  $v=$A[$i];
  $j=$i-1;
  #A[i]????????§????????????????¶????????????????????§????
  while($j>=0 && $A[$j]>$v){
    $A[$j+1]=$A[$j];
    $j--;
  }
  $A[$j+1]=$v;
  $out.=implode(' ',$A).PHP_EOL;
}

print $out;

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

int main(void){
	char str[11];
	int len;
	long sum = 0, temp;

	scanf("%s", str);

	len = strlen(str);
	for(int i=0; i < 1<<(len-1); i++) {
		temp = str[0] - '0';
		for(int j=0; j < len; j++) {
			if(i & (1<<j)) {
				sum += temp;
				temp = 0;
			}
            if(j == len-1) {
                sum += temp;
                break;
            }
			temp = temp*10 + (str[j+1]-'0');
		}
	}
	printf("%ld", sum);

	return 0;
}


Measured memory_bytes: 128
s=input()
ans='AC'
if s[0]!='A':
  ans='WA'
s=s[1:]
if s[1:-1].count('C')!=1:
  ans='WA'
s=s.replace('C','c')
for i in s:
  if i.islower()==False:
    ans='WA'
    break
print(ans)


Measured memory_bytes: 9032
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

vector<set<int>> adj;
vector<set<int>> adj2;
set<pair<int, int>> edg2;

void Add(int v1, int v2) {
	if (adj[v1].find(v2) != adj[v1].end()) {
		adj[v1].erase(v2);
		adj[v2].erase(v1);

		edg2.insert(mp(min(v1, v2), max(v1, v2)));
		adj2[v1].insert(v2);
		adj2[v2].insert(v1);
	} else {
		adj[v1].insert(v2);
		adj[v2].insert(v1);
	}
}

int main () {
//  ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

	int n;
	cin >> n;

	adj.resize(n);
	adj2.resize(n);
	
	for (int i = 0; i < 2 * (n - 1); ++i) {
		int v1, v2;
		cin >> v1 >> v2;
		--v1, --v2;
	    Add(v1, v2);
	}

	int cnt = 0;
	while (!edg2.empty()) {
		++cnt;

		auto it = edg2.begin();
		int v1 = it->fs;
		int v2 = it->sc;
		edg2.erase(it);
		adj2[v1].erase(v2);
		adj2[v2].erase(v1);

		if (sz(adj[v1]) + sz(adj2[v1]) < sz(adj[v2]) + sz(adj2[v2])) {
			swap(v1, v2);
		}

		for (auto it = adj[v2].begin(); it != adj[v2].end(); ++it) {
			adj[*it].erase(v2);
			Add(*it, v1);
		}
		adj[v2].clear();

		for (auto it = adj2[v2].begin(); it != adj2[v2].end(); ++it) {
			adj2[*it].erase(v2);
			
			adj2[*it].insert(v1);
			adj2[v1].insert(*it);

			edg2.erase(mp(min(*it, v2), max(*it, v2)));
			edg2.insert(mp(min(*it, v1), max(*it, v1)));
		}
		adj2[v2].clear();
	}

	cout << (cnt == n - 1 ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 28416
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int sum[100001];
int main()
{
	int n,a;
	while(cin>>n)
	{
		memset(sum,0,sizeof(sum));
		for(int i=0;i<n;i++)
		{
		    cin>>a;
		    sum[a]++;
		    sum[a-1]++;
		    sum[a+1]++;
		}
		sort(sum,sum+100001);
		cout<<sum[100000]<<endl;
	}
	return 0;
} 

Measured memory_bytes: 640
#なるほど。再帰ねぇ。
iN = int(input())
iAns = 0
def fDFS(s):
    global iAns
    if iN < int(s) :
        return
    else:
        if "3" in s and "5" in s and "7" in s:
            iAns += 1
        fDFS(s + "3")
        fDFS(s + "5")
        fDFS(s + "7")
fDFS("3")
fDFS("5")
fDFS("7")
print(iAns)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define reset(a,b) memset(a,b,sizeof(a))
typedef long long LL;
int main()
{
	LL n,ans,s;
	LL a[200001],sum[100001];
	LL i,j,k;
	cin>>n;
	sum[0]=0;	s=0;	ans=LL(1e18);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
		s+=a[i];
	}
	for(i=1;i<n;i++)
	{
		ans=min(ans,abs(s-2*sum[i]));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
main(){
  string s;
  cin>>s;
  map<char,int>mp;
  for(int i = 0 ; i< s.size() ; i++){
    mp[s[i]]++;
  }
  map<char ,int> ::iterator it = mp.begin();
  vector<int>v;
  for( ; it !=mp.end() ; it++){
    v.push_back(it ->second);
  }
  if(v.size() ==2 && v[0] ==2 && v[1] ==2){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; string s; cin >> n >> s;
    int ans = 1;
    FOR(i, 0, n - 1)ans += s[i] != s[i + 1];
    cout << ans << "\n";
}


Measured memory_bytes: 512
/*
ID: 5ak0
PROG:
LANG: C++11
*/

#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mpr make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;

int n, k, x;
map <int, bool> mp;

bool check(int x){
    while (x){
        if (mp[x % 10] == 1)
            return 0;
        x /= 10;
    }
    return 1;
}

int main(){
    #ifndef SAKO
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    #endif // SAKO
    ios_base::sync_with_stdio(0);

    cin >> n >> k;
    for (int i = 1; i <= k; ++i){
        cin >> x;
        mp[x] = 1;
    }
    for (;; ++n)
        if (check(n))
            return !(cout << n);

    return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> a;
    a.push_back(0);
    for (int i=1; i<n; i++) {
        if (s[i-1] != s[i]) a.push_back(i);
    }
    vector<int> can;
    for (int i=0; i<a.size(); i++) {
        if (s[a[i]] == '0') {
            can.push_back((i+2*k >= a.size() ? n : a[i+2*k]) - a[i]);
        } else {
            can.push_back((i+2*k+1 >= a.size() ? n : a[i+2*k+1]) - a[i]);
        }
    }
    cout << *max_element(can.begin(), can.end()) << endl;
}

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

int main(){
    int a[5];
    int k;
    bool flag = true;
    for (int &i : a){
        cin >> i;
    }
    cin >> k;
    for(int i = 0;i < 5;i++){
        for(int j = 0;j < 5;j++){
            if((abs(a[i]) - a[j]) - k > 0){
                flag = false;
            }
        }
    }
    if(flag){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iterator>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cassert>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <climits>
#include <ctime>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const int maxv = 100000;

void solve() {
	vector<bool> prime(maxv+1, true);
	vector<int> pref(maxv+1, 0);
	prime[0] = prime[1] = false;
	for (int i = 2; i <= maxv; ++i) {
		pref[i] = pref[i-1];
		if (prime[i]) {
			if (prime[(i+1)/2])
				++pref[i];
			for (ll j = ll(i)*i; j <= maxv; j += i)
				prime[j] = false;
		}
	}
	int q;
	scanf("%d", &q);
	while (q--) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", pref[r] - pref[l-1]);
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	solve();

#ifdef LOCAL
	cerr << double(clock()) / CLOCKS_PER_SEC << " sec" << endl;
#endif
	return 0;
}

Measured memory_bytes: 1024
//============================================================================
// Name        : abc107.cpp
// Author      : a
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#define ll long long int
using namespace std;

#define abs(a) ((a) < 0 ? - (a) : (a))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

int main() {
	int N,K;
	cin >> N >> K;
	ll x[N];
	for (int i = 0; i < N; ++i) {
		cin >> x[i];
	}
	ll res=1000000000;
	for (int i = 0; i <= N-K; ++i) {
		ll d = x[i] - x[i+K-1];
//		printf("%d,%d,%d\n",abs(x[i]),abs(x[i+K-1]),MIN(abs(x[i]),abs(x[i+K-1])));
		res = MIN(res,MIN(abs(x[i]),abs(x[i+K-1]))+ abs(d));
	}

	println(res);

	return 0;
}


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

void solve_case()
{
    int n,i,j;
    int a[7];
    for(i=1; i<=5; i++) cin >> a[i];
    for(i=1; i<=5; i++)
    {
        if(a[i]==0)
        {
            cout << i << "\n";
            return;
        }
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    int T = 1;
    //cin >> T;
    while(T--)
    {
        solve_case();
    }
    return 0;
}


Measured memory_bytes: 3580
// Date: 2020-03-14

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n, k, a[N];
LL dp[N], c[N], val[N];

int lowbit(int x) { return x & -x; }

void add(int x, LL v) {
    val[x] += v;
    val[x] %= mod;
    while(x <= k) {
        c[x] = (c[x] + v) % mod;
        x += lowbit(x);
    }
}

LL ask(int x) {
    LL ans = 0;
    while(x) {
        ans = (ans + c[x]) % mod;
        x -= lowbit(x);
    }
    return ans;
}

int main() {
    FIO;
    cin >> n >> k;
    ++k;
    rep(i, 1, n) cin >> a[i];
    add(1, 1);
    rep(i, 1, n) {
        rep(j, 1, k) {
            dp[j] = (ask(j) - ask(max(0, j-a[i]-1)) + mod) % mod;
        }
        rep(j, 1, k) add(j, (dp[j]-val[j]+mod)%mod);
    }
    cout << dp[k];

    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<math.h>

using namespace std;

double PI = acos(-1);

int main() {
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	pair<double, double> jisin, hunsin;
	double ah, am;
	ah = h * 30 + m*0.5;
	am = m * 6;
	jisin = make_pair(a * cos(ah * PI / 180), a * sin(ah * PI / 180));
	hunsin = make_pair(b * cos(am * PI / 180), b * sin(am * PI / 180));
	cout.precision(100);
	cout << sqrt((jisin.first - hunsin.first) * (jisin.first - hunsin.first) + (jisin.second - hunsin.second) * (jisin.second - hunsin.second)) << endl;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a;
  cin>>a;
  if(a%10==9 || a/10==9){
    cout<<"Yes\n";
  }else{
    cout<<"No\n";
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int n,m,o,d[10],a[20],b[20],c[20];
int f(int t){
  int i,j,k;
  if(t==n){
    for(i=0;i<o;i++){
      k=0;
      for(j=a[i]-1;j<b[i];j++)k+=d[j];
      if(k-c[i])break;
    }
    if(i==o){
      for(i=0;i<n-1;i++)printf("%d ",d[i]);
      printf("%d\n",d[i]);
      return 1;
    }
    return 0;
  }
  for(i=m;i>-1;i--){
    d[t]=i;
    if(f(t+1))return 1;
  }
  return 0;
}
int main(){
  int i;
  scanf("%d %d %d",&n,&m,&o);
  for(i=0;i<o;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  if(f(0)==0)printf("-1\n");
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <cmath>
#define MAX_N 200002
using namespace std;

int a[MAX_N];
int box[MAX_N];
int sum[MAX_N];
int n;
void solve()
{
    for(int i = n;i>=1;i--){
        if(a[i] != (sum[i]%2)){
            box[i] = 1;
        }
        else{
            box[i] = 0;
        }
        for(int j = 1;j<=((int)sqrt(i));j++){
            if(j>=i)continue;
            if(i%j==0){
                sum[j]+=box[i];
                if(i/j != j){
                    sum[i/j]+=box[i];
                }
            }
        }
    }
    /*
    for(int i = 1;i<=n;i++){
        cout<< box[i]<< " ";
    }
    */
    int cnt = 0;
    for(int i = 1;i<=n;i++){
        if(box[i]==1)cnt++; 
    }
    cout<<cnt<<endl;
    for(int i = 1;i<=n;i++){
        if(box[i]==1)cout<<i<<" ";
    }
    cout<<endl;
}

int main()
{
    cin>>n;
    for(int i = 1;i<=n;i++)cin>>a[i]; 
    solve();
    return 0;
}


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

int main(){
    ll a,b,ans;
    cin>>a>>b;
    a--;
    if(a%2==0){
        if((a/2)%2==1)a++;
    }
    else{
        if(((a+1)/2)%2==1)a=1;
        else a=0;
    }
    if(b%2==0){
        if((b/2)%2==1)b++;
    }
    else{
        if(((b+1)/2)%2==1)b=1;
        else b=0;
    }
    ans=a^b;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
T=list(T)

score=0

for i in range(N):
    if i-K<0 or T[i-K]!=T[i]:
        if T[i]=="r":
            score+=P
        elif T[i]=="p":
            score+=S
        elif T[i]=="s":
            score+=R
    else:
        T[i]="a"

print(score)
    

Measured memory_bytes: 4084
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

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;
template<class T>bool chmaxj(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; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////


int main() {

	string S;
	cin >> S;
	
	if (S == "ABC")S = "ARC";
	else S = "ABC";

	cout << S << endl;
}


Measured memory_bytes: 3600
#abc129c

n,m=map(int,raw_input().split())
a={int(raw_input()) for i in xrange(m)}

dp=[0]*(n+1)
dp[0]=1
dp[1]=0 if 1 in a else 1
if n==1:
 print dp[1]
else:
 for i in xrange(2,n+1):
  if not i in a:
   dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
 print dp[n]


Measured memory_bytes: 10876