akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll N, Q;
string s;

bool checkL(const vector<pair<char, char>>& td, int p) {
    for (int i = 0; i < Q; ++i) {
        if (s[p] == td[i].first) {
            if (td[i].second == 'L') {
                --p;
            } else {
                ++p;
            }
        }
        if (p >= N) {
            return true;
        }
    }
    return false;
}

bool checkR(const vector<pair<char, char>>& td, int p) {
    for (int i = 0; i < Q; ++i) {
        if (s[p] == td[i].first) {
            if (td[i].second == 'R') {
                ++p;
            } else {
                --p;
            }
        }
        if (p < 0) {
            return true;
        }
    }
    return false;
}

int main() {
    cin >> N >> Q;
    cin >> s;
    vector<pair<char, char>> td(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> td[i].first >> td[i].second;
    }
    ll left = 0, right = N - 1;
    ll mid;
    while (left <= right) {
        mid = (right - left) / 2 + left;
        if (checkL(td, mid)) {
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }
    ll ansr = left;
    left = 0;
    right = N - 1;
    while (left <= right) {
        mid = (right - left) / 2 + left;
        if (checkR(td, mid)) {
            left = mid + 1;
        } else {
            right = mid - 1;
        }
    }
    ll ansl = left;
    cout << ansr - ansl << endl;
    return 0;
}

Measured memory_bytes: 900
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
char a[4];
	cin>>a;
	if(a[0]==a[1]&&a[1]==a[2]||a[1]==a[2]&&a[2]==a[3]){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i,m,n) for(LL i=(m);i<(n);i++)
	//i=m -> n-1(昇順)
#define RREP(i,m,n) for(int i=(m);i>=(n);i--)
	//i=m -> n(降順)

int main(){
  LL n;
  LL ans=0;
  cin >> n;
  VLL f(n+1,2);
  f[1] = 1;
  LL end = n/2;
  
  REP(i,2,end+1){
    for(LL j=i*2; j<=n; j += i){
      f[j]++;
    }
  }
  REP(i,1,n+1){
    ans += i*f[i];
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 81280
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int W, H, N;
  cin >> W >> H >> N;
  
  vector<vector<int>> data(N, vector<int>(3));
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
      cin >> data.at(i).at(j);
    }
  }
  
  //最終的な長方形の左端のx座標をX_1,右端のx座標をX_2とする
  //最終的な長方形の下端のx座標をY_1,上端のx座標をY_2とする
  
  int X_1 = 0;
  int X_2 = W;
  int Y_1 = 0;
  int Y_2 = H;
  
  for(int i = 0; i < N; i++){
    if(data.at(i).at(2) == 1){
      if(data.at(i).at(0) >= X_1){
        X_1 = data.at(i).at(0);
      }
    }
  }
  
  for(int i = 0; i < N; i++){
    if(data.at(i).at(2) == 2){
      if(data.at(i).at(0) <= X_2){
        X_2 = data.at(i).at(0);
      }
    }
  }
  
  for(int i = 0; i < N; i++){
    if(data.at(i).at(2) == 3){
      if(data.at(i).at(1) >= Y_1){
        Y_1 = data.at(i).at(1);
      }
    }
  }
  
  for(int i = 0; i < N; i++){
    if(data.at(i).at(2) == 4){
      if(data.at(i).at(1) <= Y_2){
        Y_2 = data.at(i).at(1);
      }
    }
  }
  
  int S = (X_2 - X_1) * (Y_2 - Y_1);
  
  if(X_2 - X_1 >= 0 && Y_2 - Y_1 >= 0){
    cout << S << endl;
  }
  else{
    cout << 0 << endl;
  }
  
}

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

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

using ll = long long;

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

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

int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> vb(60,0LL);
  for(ll i = 0LL; i < N; i++) {
    ll x;
    cin>>x;
    bitset<60> y(x);
    for(ll j = 0LL; j < 60; j++) {
      if(y.test(j)) vb[j]++;
    }
  }
  ll k = 0LL;
  ll ans=0LL;
  for(ll i = 59;i >=0; i--){
    if((1LL<<i)+k<=K&&N-vb[i]>=N/2LL+1LL){
      k+=(1LL<<i);
      ans+=(1LL<<i)*(N-vb[i]);
    }
    else ans+=(1LL<<i)*vb[i];
  }
  cout<<ans <<endl;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	IOS;
	ll n, k;
	cin >> n >> k;
	vector<P> v(n);
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		v[i] = make_pair(a, b);
	}
	sort(ALL(v));
	ll cnt = 0;
	REP(i, n) {
		cnt += v[i].second;
		if (k <= cnt) {
			cout << v[i].first << endl;
			break;
		}
	}
}



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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

string s;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> s;

  int c = 0;
  forn(i,s.size())
    if (s[i] == 'o') c++;

  if (c + 15 - s.size() >= 8)
    cout << "YES\n";
  else
    cout << "NO\n";

  return 0;
}


Measured memory_bytes: 256
n= int(input())
def koch(s,t,n):
    if n==0: #何回思考を繰り返したかを示す変数
        pass
    else:
        x= (t[0]-s[0])/3  # (x,y)は端点を結ぶ線分を三等分した時のベクトル
        y= (t[1]-s[1])/3
        ss= [ s[0]+ x, s[1]+ y ]  #ssはs,tの三等分点のうち、s寄りの点
        tt= [ t[0]- x, t[1]- y ]  #ttはs,tの三等分点のうち、t寄りの点
        st= [ ss[0]+ x/2- (3**0.5)*y/2 , ss[1]+ (3**0.5)*x/2+ y/2 ] #stは三角形の頂点の座標
        
        koch(s,ss,n-1) #1/3線分で再帰。nの値を１減らす
        print(ss[0],ss[1])  #点の座標を表示
        koch(ss,st,n-1)
        print(st[0],st[1])
        koch(st,tt,n-1)
        print(tt[0],tt[1])
        koch(tt,t,n-1)
    


print(0,0)
koch([0,0],[100,0],n)
print(100,0)
    





Measured memory_bytes: 5720
function Main(input) {
      input =  input.split("\n");

	switch( input[0] ) {
              case "Sunny":
                        console.log("Cloudy");
                        break;

              case "Cloudy":
                        console.log("Rainy");
                        break;

              case "Rainy":
                        console.log( "Sunny");
                        break;
        }
	
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,X;
  cin>>A>>B>>C>>X;
  int ans=0;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(X==500*i+100*j+50*k) ans++;
      }
    }
  }
  cout<<ans<<endl;
}

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

int N, M;
const int MAX_N = 1000;
const int MAX_T = 1260 - 540;

void debug(int record[MAX_N+1][MAX_T+1], int max_t){
	cout << "debug : " << endl;
	for(int i = 1 ; i <= N ; i++ ){
		for(int j=0 ; j <= max_t ; j++ ){
			cout << record[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
}


int main(){
	while( cin >> N >> M , N || M ){
		int r, q;
		int max_t = 0;
		
		// record[i][j] := i 番目のPCを時刻 j に使っている学生の番号
		// 使っていないときは 0 
		int record[MAX_N+1][MAX_T+1] = {0};
		int interval[MAX_N+1][MAX_T+1] = {0};
		
		cin >> r;
		for(int i=0 ; i < r ; i++ ){
			int t, n, m, s;
			cin >> t >> n >> m >> s;
			t -= 540;
			// ログインのとき -m , ログアウトのとき m
			if( s == 1 )
				record[n][t+1] = -m ;
			else
				record[n][t] = m ;
			max_t = max( max_t , t );
		}
		
		// record[][] を埋める
		for(int i=0 ; i <= N ; i++ ){
			bool flag = false;
			int m = 0;
			for(int j=0 ; j <= MAX_T ; j++ ){
				if( record[i][j] < 0 ){ // ログインしたとき
					flag = true;
					record[i][j] *= -1;
					m = record[i][j];
				}else if( record[i][j] > 0 ){ // ログアウトしたとき
					flag = false;
					interval[i][j] = m;
				}else if( flag ){ 
					record[i][j] = m;
					interval[i][j] = m;
				}
			}
		}
		//debug( record , max_t );
		
		// 質問数
		cin >> q;
		for(int i=0 ; i < q ; i++ ){
			int ts, te, m;
			cin >> ts >> te >> m;
			ts -= 540;
			te -= 540;
			// 時刻[ts,te] に学生 m が使っている合計時間を求める
			int cnt = 0;
			for(int t = ts ; t <= te ; t++ ){
				for(int n=0 ; n <= N ; n++ ){
					if( record[n][t] == m ){
						cnt++;
						if( t == ts && interval[n][t] == m )
							cnt--;
						//cout << "time : " << t + 540 << endl;
						break;
					}
				}
			}
			cout << cnt << endl;
		}
	}
}

Measured memory_bytes: 6504
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <iomanip>
#include <math.h>
#include <mutex>
#include <algorithm>

//#include "test.h"

//#include "SandBox/StopRangeAccess/StopRangeAccess.h"

//#include "Data.h"


using namespace std;

typedef unsigned long ulong;
typedef unsigned long long ulolong;
typedef long long lolong;


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

	cout << r * 3.141592 * 2.0;
}

Measured memory_bytes: 3788
#include <iostream>
using namespace std;
int n, a[500000], ans, r;
int main(){
    scanf("%d", &n);
    r = 0;
    ans = 0;
    for (int i=1;i<=n;i++){
        scanf("%d", &a[i]);

        if (a[i] == r+1){
            r++;
        } else {
            ans++;
        }
    }

    if (r == 0){
        ans = -1;
    }

    printf("%d\n", ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int K,T;
  cin >> K >> T;
  priority_queue<P> pq;
  rep(i,T) {
    int x;
    cin >> x;
    pq.push(P(x,i));
  }
  int now = -1;
  int ans = 0;
  while(!pq.empty()){
    int num = pq.top().first;
    int color = pq.top().second;
    if(now == color) {
      pq.pop();
      if(pq.empty()) {
        ans += num;
        break;
      }
      int nextNum = pq.top().first;
      int nextColor = pq.top().second;
      pq.pop();
      nextNum--;
      if(nextNum != 0) {
        pq.push(P(nextNum,nextColor));
      }
      pq.push(P(num,color));
      now = nextColor;
    } else {
      pq.pop();
      num--;
      if(num != 0) {
        pq.push(P(num,color));
      }
      now = color;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  string N;
  cin >> N;
  int count = 0;
  for(int i = 0; i < 4; i++)
    if(N.at(i) == '2')
      count++;
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<ll>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc ll t; cin >> t; while(t--)
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
struct tree_node{
    ll mx;
};
const ll N2=300005;
ll A[N2];
tree_node tree[N2*4];
tree_node merge(tree_node &l,tree_node &r){
    tree_node result;
    result.mx=max(l.mx,r.mx);
    return result;
}
void build_tree(ll node,ll l,ll r){
    if(l==r) {tree[node].mx=A[l]; return;}
    build_tree(node*2, l, (l+r)/2);
    build_tree(node*2+1, 1+(l+r)/2, r);
    tree[node]=merge(tree[2*node],tree[node*2+1]);
}

tree_node query(ll node,ll l,ll r,ll x,ll y){
    if(l==x && r==y) return tree[node];
    ll mid=(l+r)/2;
    if(x>mid) return query(2*node+1,mid+1,r,x,y);
    if(y<=mid) return query(2*node,l,mid,x,y);

    tree_node w=query(2*node,l,mid,x,mid);
    tree_node z=query(2*node+1,mid+1,r,mid+1,y);
    tree_node result=merge(w,z);
    return result;
}
void update(ll node,ll l,ll r,ll x,ll val){
    if(l==r) {tree[node].mx=val; return;}
    if (x <= (l+r)/2LL)
        update(2*node, l, (l+r)/2LL, x, val);
    else
        update(2*node+1, (l+r)/2LL+1, r, x, val);
    tree[node].mx=max(tree[2*node].mx,tree[node*2+1].mx);
}
void solve(){
  ll n,k;
  cin>>n>>k;
  ll x;
  build_tree(1,0,N2-1);
  rep(i,0,n){
    cin>>x;
    update(1,0,N2-1,x,query(1,0,N2-1,max(0LL,x-k),min(N2-1,x+k)).mx+1);
  }
  ll mx=0;
  rep(i,0,4*N2) mx=max(mx,tree[i].mx);
  cout<<mx<<endl;
}

int main(){
    optimizeIO();
    solve();
}


Measured memory_bytes: 11824
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
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);
        BTwoColorsCardGame solver = new BTwoColorsCardGame();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTwoColorsCardGame {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            Map<String, Integer> d = new HashMap<>();
            int n = in.nextInt();
            for (int i = 0; i < n; i++) {
                d.merge(in.next(), 1, (v1, v2) -> v1 + v2);
            }
            int m = in.nextInt();
            for (int i = 0; i < m; i++) {
                d.merge(in.next(), -1, (v1, v2) -> v1 + v2);
            }
            int max = 0;
            for (int i : d.values()) {
                max = Math.max(max, i);
            }
            out.println(max);
        }

    }
}



Measured memory_bytes: 26836
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n;
  int ans = 0;
  scanf("%d", &n);
  for (int i = 20; i <= n; i++)
  {
    int flag = 0;
    for (int j = 1; j <= n; j += 2)
    {
      if (i % j == 0)
      {
        flag++;
      }
    }
    if (flag == 8)
      ans++;
  }
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L
const int mxN = 1e9 + 7;

long long check(vector<int> a, int k) {
    sort(a.begin(), a.end());
    long long sum = 0;
    int i = 0;
    int n = a.size();
    while (i < n && a[i] < 0 && k > 0) {
        k--; i++;
    }
    for (i; i < n; i++) sum += a[i];
    return sum;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> money(n);
    for (int i = 0; i < n; i++) cin >> money[i];
    long long ans = 0;

    for (int t = 0; t < min(k, n); t++) {
        vector<int> a;
        for (int i = 0; i < t; i++) {
            a.push_back(money[i]);
            ans = max(ans, check(a, k-t));
        }
        for (int j = n - 1; j >= n - (min(k, n)-t); j--) {
            a.push_back(money[j]);
            ans = max(ans , check(a, k-t- (n-j)));
        }

    }
    reverse(money.begin(), money.end());
    for (int t = 0; t < min(k, n); t++) {
        vector<int> a;
        for (int i = 0; i < t; i++) {
            a.push_back(money[i]);
            ans = max(ans, check(a, k - t));
        }
        for (int j = n - 1; j >= n - (min(k, n) - t); j--) {
            a.push_back(money[j]);
            ans = max(ans, check(a, k - t - (n - j)));
        }

    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3624
N = int(input())
s = []
for i in range(N):
    s.append(input())
M = int(input())
t = []
for i in range(M):
    t.append(input())
ans = []
for i in range(N):
    if s.count(s[i]) - t.count(s[i]) > 0:
        Ans = s.count(s[i]) - t.count(s[i])
        ans.append(Ans)
    else:
        ans.append(0)
print(max(ans))

Measured memory_bytes: 3064
#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> // sqrt
using namespace std;

int main() {
    long N;
    cin >> N;
    long n = N * 100;
    for (long i = n / 108 - 1; i < n + 100; i++) {
        if (n <= 108 * i && i * 108 < n + 100) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

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

Measured memory_bytes: 3592
import java.util.Scanner;
 import java.math.*;


 class Main{

 public static void main(String args[]){

 Scanner sc=new Scanner(System.in);
 int a=sc.nextInt();

  BigInteger b=new BigInteger("0");
  BigInteger c=new BigInteger("0");

  for(int i=1;i<=a;i++){

  b=sc.nextBigInteger(); 
  c=sc.nextBigInteger();


   if((b.toString().length()>80)||(c.toString().length()>80)||(b.add(c).toString().length()>80))

     System.out.println("overflow");
   else
 
    System.out.println(b.add(c));  
   }
  }
 }

Measured memory_bytes: 26240
import bisect

N = int(input())
L = list(map(int, input().split()))

chouhen = []
kosuu = 0

for i in range(N):
    for j in range(i+1, N):
        a, b = min(L[i], L[j]), max(L[i], L[j])
        chouhen.append((a, b))

L.sort()

for hen in chouhen:
    hidari = max(hen[0] - hen[1], hen[1] - hen[0])
    migi = sum(hen)

    hidari_idx = bisect.bisect_right(L, hidari)
    migi_idx = bisect.bisect_left(L, migi)

    # print(hidari, migi, hidari_idx, migi_idx)

    if L[hidari_idx] <= hen[0] <= L[migi_idx - 1]:
        kosuu -= 1
    if L[hidari_idx] <= hen[1] <= L[migi_idx - 1]:
        kosuu -= 1

    kosuu += migi_idx - hidari_idx

print(max(0, kosuu // 3))


Measured memory_bytes: 135420
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    pair<double,double>   pd;
typedef    vector<pd>   vpd;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define all(x) x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(10)<<fixed
const    ld   PI=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}



int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{
ld r;
cin>>r;
ld ans=(2*PI*r);
coutd<<ans;











}return 0;}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll h,w;
    cin>>h>>w;
    vector<string>s;
    string s1;
    for(ll i=0;i<h;i++)
    {
        cin>>s1;
        s.push_back(s1);
    }
    ll dp[h][w];
    if(s[0][0]=='.')
        dp[0][0]=0;
    else
        dp[0][0]=1;
    for(ll i=1;i<w;i++)
    {
        if(s[0][i]=='.')
            dp[0][i]=dp[0][i-1];
        else
        {
            if(s[0][i-1]=='.')
                dp[0][i]=dp[0][i-1]+1;
            else
                dp[0][i]=dp[0][i-1];
        }
    }
    for(ll i=1;i<h;i++)
    {
        if(s[i][0]=='.')
            dp[i][0]=dp[i-1][0];
        else
        {
            if(s[i-1][0]=='.')
                dp[i][0]=dp[i-1][0]+1;
            else
                dp[i][0]=dp[i-1][0];
        }
    }
    for(ll i=1;i<h;i++)
    {
        for(ll j=1;j<w;j++)
        {
            if(s[i][j]=='.')
                dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
            else
            {
                ll val1,val2;
                if(s[i-1][j]=='.')
                    val1=dp[i-1][j]+1;
                else
                    val1=dp[i-1][j];
                if(s[i][j-1]=='.')
                    val2=dp[i][j-1]+1;
                else
                    val2=dp[i][j-1];
                dp[i][j]=min(val1,val2);
            }
        }
    }
    cout<<dp[h-1][w-1];
}

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

namespace ConsoleApplication19
{
    class Program
    {
        static void Main(string[] args)
        {
            string s;
            int b, c;
            b = c = 0;
            while ((s = (Console.ReadLine())) != null)
                
            {
                var a = s.Split(',').Select(int.Parse).ToArray();
                
                if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2])
                    b++;
                if (a[0] == a[1])
                    c++;
              
            }
            Console.WriteLine(b);
            Console.WriteLine(c);
        }

    }
}

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

int main(){
    int m,n;
    int inf = 1000000000;
    
    while(cin>>n>>m && n){
        int dp[150][10][76] = {};
        for(int i=0;i<150;++i){
            for(int j=0;j<10;++j){
                for(int k=0;k<76;++k){
                    dp[i][j][k]=inf;
                }
            }
        }
        int num[150],s[150][10][2];
        for(int i=0;i<n;++i){
            cin>>num[i];
            for(int j=0;j<num[i];++j) cin>>s[i][j][0]>>s[i][j][1];
        }
        for(int i=0;i<num[0];++i) dp[0][i][0]=0;
        for(int i=0;i<num[1];++i) dp[1][i][1]=0;
        for(int i=0;i<n-1;++i){
            for(int j=0;j<num[i];++j){
                for(int k=0;k<num[i+1];++k){
                    for(int sk=0;sk<=m;++sk){
                        dp[i+1][k][sk]=min(dp[i+1][k][sk],dp[i][j][sk]+(s[i][j][1]+s[i+1][k][1])*abs(s[i][j][0]-s[i+1][k][0]));
                    }
                }
                if(i<n-2){
                    for(int k=0;k<num[i+2];++k){
                        for(int sk=0;sk<m;++sk){
                            dp[i+2][k][sk+1]=min(dp[i+2][k][sk+1],dp[i][j][sk]+(s[i][j][1]+s[i+2][k][1])*abs(s[i][j][0]-s[i+2][k][0]));
                        }
                    }
                }
            }
        }
        int ans = inf;
        for(int i=0;i<num[n-1];++i){
            for(int j=0;j<=m;++j) ans = min(ans,dp[n-1][i][j]);
        }
        for(int i=0;i<num[n-2];++i){
            for(int j=0;j<=m-1;++j) ans = min(ans,dp[n-2][i][j]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define f first
#define s second
#define pii pair<int,int>
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MAX_N = 2e6 + 1;
int mod = 1e9 + 7;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    int a[n], b[m];
    map<int, int> mp;
    mp[0] = 0;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
        mp[sum] = i + 1;
    }
    int ans = (--mp.upper_bound(k))->second;
    sum = 0;
    for (int j = 0; j < m; ++j) {
        cin >> b[j];
        sum += b[j];
        if (sum > k)continue;
        ans = max(ans, j + 1 + (--mp.upper_bound(k - sum))->second);
    }
    cout << ans << endl;

}

Measured memory_bytes: 19248
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	if((a - b) % 2){
		cout << "IMPOSSIBLE" << endl;
	}else{
		cout << (a + b) / 2 << endl;
	}
}

Measured memory_bytes: 256
import javax.smartcardio.CommandAPDU;
import java.io.* ;
import java.lang.reflect.Array;
import java.util.* ;
import java.math.* ;
public class Main
{
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input)
    {
        reader = new BufferedReader(new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException
    {
        while (!tokenizer.hasMoreTokens())
        {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static long nextInt() throws IOException
    {
        return Long.parseLong(next());
    }

    public static int ri() throws IOException
    {
        return (int) nextInt();
    }

    public static long rl() throws IOException
    {
        return nextInt();
    }

    public static double rd() throws NumberFormatException, IOException
    {
        return Double.parseDouble(next());
    }

    static void print_a(int[] arr)
    {
        for (int i = 0; i < arr.length; i++)
        {
            print(arr[i] + " ");
        }
        println();
    }

    public static int[] ria(int n) throws IOException
    {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = ri();
        }
        return a;
    }

    public static long[] rla(int n) throws IOException
    {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = rl();
        }
        return a;
    }

    public static int p(int i)
    {
        return (int) Math.pow(2, i);
    }

    static PrintWriter writer;

    static void outit(OutputStream outputStream)
    {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    static void print(Object... objects)
    {
        for (int i = 0; i < objects.length; i++)
        {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }
    static void println(Object... objects)
    {
        print(objects);
        writer.println();
        flush();
    }
    static void close()
    {
        writer.close();
    }

    static void flush()
    {
        writer.flush();
    }

    public static void main(String[] args) throws IOException
    {
        init(System.in);
        outit(System.out);
//        int t = (int) nextInt();
//        for (int i = 0; i < t; i++)
        output();
        flush();
        close();
    }
    static int n ;
    static long mod = 1000000007 ;
    static long [] pre ;
    public static void output() throws IOException
    {
        long q = rl() ;
        long h = rl() ;
        long s = rl() ;
        long d = rl() ;
        long n = rl() ;
        long min_2 = Math.min(8*q,Math.min(4*h,Math.min(2*s,d))) ;
        long ans = (n/2)*min_2 ;
        long min_1 = Math.min(4*q,Math.min(2*h,s)) ;
        ans += n%2*min_1 ;
        println(ans) ;
    }
}

Measured memory_bytes: 23124
n = int(input())
a = list(map(int, input().split()))

total_a = 0
total_b = 0

a.sort(reverse=True)
for i in range((n+1)//2):
    total_a += a[i*2]
for i in range(n//2):
    total_b += a[i*2 + 1]
print(total_a - total_b)

Measured memory_bytes: 3060
list_c = []
for i in range(3):
  temp_c = list(map(int, input().split()))
  list_c.append(temp_c)

list_a = [0 for _ in range(3)]
list_b = [0 for _ in range(3)]
for i in range(3):
  list_b[i] = list_c[i][0]
for i in range(3):
  if i != 0:
    list_a[i] = list_c[0][i] - list_b[0]

for j in range(3):
  for i in range(3):
    if list_c[i][j] != list_a[j] + list_b[i]:
      print("No")
      exit()
print("Yes")

Measured memory_bytes: 3064
n = int(input())
a1 = (list(map(int, input().split())))
a2 = (list(map(int, input().split())))
ans = a1[0] + sum(a2)
tmp = ans
for i in range(1, n):
    tmp += a1[i] - a2[i - 1]
    ans = max(ans, tmp)

print(ans)

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

using namespace std;

#define PI (3.14159265358979323846)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MS multiset
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define SZ(x) ((int)x.size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

const db eps = 0.00001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 750555;
const int M = 1125;

void solve() {
    int n; ll d;
    cin >> n >> d;

    int ans = 0;
    while (n--){
        ll x, y;
        cin >> x >> y;
        if (x*x + y*y <= d*d) ans++;
    }

    cout << ans;


}

int main() {
    ios_base::sync_with_stdio(false);

#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3648
using System.Text;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
            var r = new string[n, 3];
            for (int i = 0; i < n; i++)
            {
                line = Console.ReadLine().Trim().Split(' ');
                for (int j = 0; j < 3; j++) r[i, j] = line[j];
            }
            getAns(r, n, m);
        }
    }
    static bool check(string r, string t)
    {
        for (int i = 0; i < 8; i++)
            if (r[i] != '?' && r[i] != t[i]) return false;
        return true;
    }
    static void getAns(string[,] r, int n, int m)
    {
        var count = 0;
        var sb = new StringBuilder();
        for (int i = 0; i < m; i++)
        {
            var s = Console.ReadLine().Trim();
            string[] line = s.Split(' ');
            var t1 = line[0];
            var t2 = line[1];
            var ok = false;
            for (int j = 0; j < n; j++)
                if (r[j, 0] == "permit")
                {
                    if (check(r[j, 1], t1) && check(r[j, 2], t2)) ok = true;
                }
                else
                {
                    if (check(r[j, 1], t1) && check(r[j, 2], t2)) ok = false;
                }
            if (ok) { count++; sb.Append(s + "\n"); }
        }
        Console.WriteLine(count);
        Console.Write(sb);
    }
}


Measured memory_bytes: 20256
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main() {
    int a, b;
    while(cin >> a >> b) {
        int c = a+b;
        ostringstream os;
        os << c;
        cout << os.str().length() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    double prices[]=new double[N];
     double sum=0;
    String currency[]=new String[N];
    for (int i = 0; i < N; i++) {
      prices[i] = sc.nextDouble();
      currency[i] = sc.next();
    }
    for (int i = 0; i < N; i++) {
      if(currency[i].equals("BTC")){
        sum +=prices[i]*380000;
      }else{
        sum +=prices[i];
      }
    }System.out.println(sum);
  }
}

Measured memory_bytes: 23252
<?php
list($n,$m,$k) = explode(" ",trim(fgets(STDIN)));
$a = explode(" ",trim(fgets(STDIN)));
$b = explode(" ",trim(fgets(STDIN)));
$t=0;
for($i=0; $i<$m; $i++){
    $t += $b[$i];
}
$j = $m;
$ans = 0;
for($h=0; $h<$n+1; $h++){
    while($j>0 && $t>$k){
        --$j;
        $t -= $b[$j];
    }
    if($t > $k){
        break;
    }
    $ans = max($ans, $h+$j);
    if($h == $n){
        break;
    }
    $t += $a[$h];
}
echo $ans;

?>


Measured memory_bytes: 45788
# https://atcoder.jp/contests/abc143/submissions/15557307

"""
タグ: ワーシャルフロイド
"""

class Graph:
    class Edge:
        def __init__(self, to, cost):
            """
            :param to:  終点ノード
            :param cost: 辺の重み
            """
            self.to, self.cost = to, cost

    def __init__(self, n, directed=False, decrement=True, edges=[]):
        self.n = n
        self.directed = directed
        self.decrement = decrement
        self.edges2 = []                            # ワーシャルフロイド用
        for x, y, cost in edges:
            self.add_edge(x, y, cost)

    def add_edge(self, x, y, cost):
        if self.decrement:
            x -= 1
            y -= 1
        self.edges2.append((x, y, cost))
        if self.directed == False:
            self.edges2.append((y, x, cost))     # ワーシャルフロイド用

    def warshall_folyd(self, INF=1<<30):
        """
        :param INF: INF = 10**18 にすると、負のコストがある場合に少し面倒になる
        :return: 頂点 i, j 間の距離を行列として返す
        """
        dist = [[INF] * self.n for _ in range(self.n)]

        for i, j, cost in self.edges2:
            dist[i][j] = cost
        for i in range(self.n):
            dist[i][i] = 0  # 自身のところに行くコストは０

        for k in range(self.n):
            for i in range(self.n):
                for j in range(self.n):
                    if dist[i][j] > dist[i][k] + dist[k][j]:
                        dist[i][j] = dist[i][k] + dist[k][j]
        return dist

def max2(x,y):
    return x if x > y else y

from itertools import combinations

N, M, L = map(int, input().split())
graph = Graph(N, directed=False, decrement=True)
for _ in range(M):
    x, y, cost = map(int, input().split())
    graph.add_edge(x, y, cost)

d = graph.warshall_folyd()

graph2 = Graph(N, directed=False, decrement=False)
for i, j in combinations(range(N), 2):
    if d[i][j] <= L:
        graph2.add_edge(i, j, 1)


d = graph2.warshall_folyd()

for _ in range(int(input())):
    s, t, = map(int, input().split())
    s, t = s-1, t-1
    print(d[s][t]-1 if d[s][t] < 1<<20 else -1)

Measured memory_bytes: 98368
import sys
class Tree():
    def __init__(self):
        self.root = None
    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z
    def find(self, key):
        x = self.root
        while x and x.key != key:
            if x.key < key:
                x = x.right
            else:
                x = x.left
        print('yes' if x else 'no')
    def print(self):
        print('',' '.join(map(str, self.root.inwalk())))
        print('',' '.join(map(str, self.root.prewalk())))
    
class Node():
    def __init__(self, key):
        self.key = key
        self.parent = self.left = self.right = None
    def prewalk(self):
        ret = [self.key]
        if self.left:
            ret += self.left.prewalk()
        if self.right:
            ret += self.right.prewalk()
        return ret
    def inwalk(self):
        ret = []
        if self.left:
            ret += self.left.inwalk()
        ret += [self.key]
        if self.right:
            ret += self.right.inwalk()
        return ret
tree = Tree()
n = sys.stdin.readline()
for line in sys.stdin:
    if line[0] == 'i':
        tree.insert(int(line.split()[1]))
    elif line[0] == 'f':
        tree.find(int(line.split()[1]))
    else:
        tree.print()

Measured memory_bytes: 218656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<string> s(N);
    for (ll i = 0; i < N; i++) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }

    map<string, ll> map;
    for (ll i = 0; i < N; i++) {
        map[s[i]]++;
    }

    ll count = 0;
    for (auto i:map) {
        count += i.second * (i.second-1) / 2;
    }

    cout << count << endl;
}

Measured memory_bytes: 18176
import sys
from io import StringIO
import unittest
import math

def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


def resolve():
    q = int(input())
    lr = [list(map(int, input().split())) for _ in range(q)]

    # 素数のlist
    prime_list = set(primes(10 ** 5 + 1)) # setにしないと、ものすごい遅い

    """
    # 10^5 * 10 ^ 5なので✗
    for l, r in lr:
        tmp = 0
        for i in range(l, r + 1):
            if i in prime_list and (i + 1)/2 in prime_list:
                tmp += 1
        print(tmp)
    """

    cum_2017 = [0, 0]
    # 累積和的に、2017に似た数カウントをする
    tmp = 0
    for i in range(2, 10 ** 5 + 1, 1):
        if i in prime_list and (i + 1) / 2 in prime_list: # (i + 1) // 2 でなく、(i + 1) / 2にすると遅い
            tmp += 1
            cum_2017.append(tmp)
        else:
            cum_2017.append(tmp)

    for l, r in lr:
        print(cum_2017[r] - cum_2017[l - 1])



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1
3 7"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
13 13
7 11
7 11
2017 2017"""
        output = """1
0
0
1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """6
1 53
13 91
37 55
19 51
73 91
13 49"""
        output = """4
4
1
1
1
2"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 82260
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}

string s;
string t;
int k;
int n;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  cin>>s;
  n=s.size();
  rep(_,3){
    rep(i,s.size()){
      t+=s[i];
    }
  }

  int a[3]={};

  rep(i,t.size()){
    if(i&&t[i]==t[i-1]){
      t[i]=' ';
      a[i/n]++;
    }
  }

  cin>>k;

  bool flag=true;
  rep(i,n){
    if(i) flag&=s[i]==s[i-1];
  }
  
  if(flag){
    cout<<n*k/2<<endl;
    return 0;
  }


  int ans=0;
  if(k==1) ans=a[0];
  else ans=a[0]+a[2]+a[1]*(k-2);

  cout<<ans<<endl;


}

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

#define MOD 1000000007

int n;
vector<int> G[100005];
vector<vector<int>> dp(100005, vector<int>(2,1));


void dfs(int x,int t){

    for(int i=0;i<G[x].size();i++)
        if(G[x][i]!=t)
            dfs(G[x][i],x);

    for(int i=0;i<G[x].size();i++)
        if(G[x][i]!=t){

        int y=G[x][i];

        dp[x][0]=(1LL*dp[x][0]*dp[y][1])%MOD;

        dp[x][1]=(1LL*dp[x][1]*(dp[y][0]+dp[y][1]))%MOD;

        }

}

int main(){

    cin>>n;

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

        int x,y;
        cin>>x>>y;

        G[x].push_back(y);
        G[y].push_back(x);

    }

    dfs(1,0);

    cout<<(dp[1][0]+dp[1][1])%MOD;

}


Measured memory_bytes: 18176
using System;
using System.Linq;

namespace _20200419_B
{
    class Program
    {
        static void Main(string[] args)
        {

            long[] inputLongArray1 = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long[] inputLongArray2 = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long n = inputLongArray1[0];
            long sum = 0;
            for(int i=0; i<inputLongArray1[1]; i++)
            {
                sum += inputLongArray2[i];

            }

            if (n - sum < 0) { Console.WriteLine(-1); }
            else { Console.WriteLine(n-sum); }
        }
    }
}


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

#define REP(i, n ,N) for(int i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;

int main(){
	while(1) {
		int n;
		cin >> n;
		if(n==0)break;
		vector<int> word_len(n + 1);
		REP(i, 1, n + 1) {
			string s;
			cin >> s;
			word_len[i] = s.size();
		}

		REP(i, 1, n + 1) {
			int stack = 0;
			int stage = 0;
			REP(j, i, n + 1) {
				if (stage == 0) {
					stack += word_len[j];
					if (stack == 5) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 5)break;
				}
				if (stage == 1) {
					stack += word_len[j];
					if (stack == 7) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 7)break;
				}
				if (stage == 2) {
					stack += word_len[j];
					if (stack == 5) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 5)break;
				}
				if (stage == 3) {
					stack += word_len[j];
					if (stack == 7) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 7)break;
				}
				if (stage == 4) {
					stack += word_len[j];
					if (stack == 7) {
						stage++;
						break;
					}
					if (stack > 7)break;
				}
			}
			if (stage == 5) {
				p(i);
				break;
			}
		}
	}
}


Measured memory_bytes: 3208