akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations
from math import hypot

def solve():
    INF = float('inf')
    eps = 10**-6

    N = int(input())
    pts = [tuple(map(int, input().split())) for _ in range(N)]

    if N == 2:
        x1, y1 = pts[0]
        x2, y2 = pts[1]
        ans = hypot(x1-x2, y1-y2) / 2
        print(ans)
        return

    lines = {}
    for i in range(N):
        x1, y1 = pts[i]
        for j in range(i+1, N):
            x2, y2 = pts[j]
            if y1 == y2:
                a = INF
                b = (x1+x2)/2
            else:
                x0, y0 = (x1+x2)/2, (y1+y2)/2
                a = -(x2-x1)/(y2-y1)
                b = y0 - a*x0
            lines[(i, j)] = (a, b)
#    print('lines:', lines)

    ans = INF
    for i, j, k in combinations(range(N), r=3):
        a1, b1 = lines[(i, j)]
        a2, b2 = lines[(i, k)]
        if a1 == a2: continue
        if a1 == INF:
            x = b1
            y = a2*x + b2
        elif a2 == INF:
            x = b2
            y = a1*x + b1
        else:
            x = (b2-b1) / (a1-a2)
            y = (a1*b2-b1*a2) / (a1-a2)
        x1, y1 = pts[i]
        r = hypot(x1-x, y1-y)
#        print('(i, j, k):', (i, j, k), '/ (x,y):', (x, y), '/ r:', r)
        for xi, yi in pts:
            dist = hypot(xi-x, yi-y)
            if dist > r + eps:
                break
        else:
            ans = min(ans, r)

    for i in range(N):
        x1, y1 = pts[i]
        for j in range(i+1, N):
            x2, y2 = pts[j]
            x, y = (x1+x2)/2, (y1+y2)/2
            r = hypot(x1-x, y1-y)
            for xi, yi in pts:
                dist = hypot(xi-x, yi-y)
                if dist > r + eps:
                    break
            else:
                ans = min(ans, r)

    print(ans)


solve()


Measured memory_bytes: 42992
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

ll a[100010];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n, greater<ll>());
	int p = 1e9;
	ll ans;
	for (int i = 1; i < n; i++) {
		if (abs(a[i] - (a[0] - a[i])) < p) {
			p = abs(a[i] - (a[0] - a[i]));
			ans = a[i];
		}
	}
	cout << a[0] <<' '<< ans << endl;
	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 __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define ceil(a,b) (a+b-1)/b
#define endl "\n"
const int N=100005;
const int inf=1e18;
const double eps=1e-9;

#define oa(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define o1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define o2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define o3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define o4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

int power(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
int pow1(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
            res=res*a;
            res%=mod;
        }
        a=a*a;
        a%=mod;
        b>>=1;
    }
    return res;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
    int n;
    cin>>n;
    int a[n];
    for(int x=0;x<n;x++){
        cin>>a[x];
    }
	int c=a[0];
    int ans=0;
    for(int x=1;x<n;x++){
        if(a[x]<c){
            ans+=c-a[x];
        }else{
            c=a[x];
        }
    }
    cout<<ans;








	
return 0;
}


Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
const int N = 100005;
int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    //int t;cin>>t;while(t--)
    {
        int i, j, k, n, m,a,ans = 0, cnt = 0, sum = 0,b = 0,c = 0;
        cin >> n ;
        i = 100;
        while(i < n){
        	i += (0.01 * i);
        	ans++;
        }
        cout << ans ;
    }
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> vec(N);
    vector<int> hoge;
    for(int a = 0;a < N;a++){
        cin >> vec[a];
    }
    hoge = vec;
    sort(vec.begin(), vec.end());
    int median = vec.at(N/2-1);
    int median2 = vec.at(N/2);
    for(int a : hoge){
        if(a > median){
            cout<<median<<" "<<endl;
        }else{
            cout<<median2<<" "<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n, l; cin >> n >> l;
  vector<string> s(n);
  REP(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  REP(i, n) cout << s[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
#from functools import reduce

def solve(A: int, B: int):
    #print(reduce(lambda a, b: a ^ b, range(A, B+1)))
    def sub(X): # F(0, X)
        if X%2 == 0:
            if (X/2)%2 == 0:
                return 0^X
            else:
                return 1^X
        else:
            if ((X+1)/2)%2 == 0:
                return 0
            else:
                return 1

    print(sub(A-1)^sub(B))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
from itertools import combinations_with_replacement


def main():
    N, M, Q = map(int, input().split())
    combination = []
    for i in range(Q):
        a, b, c, d = map(int, input().split())
        a -= 1
        b -= 1
        combination.append((a, b, c, d))
    ans = []
    for p in combinations_with_replacement(list(range(1, M+1)), N):
        cnt = 0
        for a, b, c, d in combination:
            if p[b] - p[a] == c:
                cnt += d
        ans.append(cnt)

    print(max(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 74032
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;
                                                                                                     
ll MOD=1000000007;                                                                                     
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s,t; cin>>s>>t;
    int q,sn=s.size(),tn=t.size(); cin>>q;
    vector<int> ssum(sn+1,0),tsum(tn+1,0);
    rep(i,sn){
        ssum[i+1]=ssum[i];
        if(s[i]=='A') ssum[i+1]+=2;
        else ssum[i+1]++;
    }
    rep(i,tn){
        tsum[i+1]=tsum[i];
        if(t[i]=='A') tsum[i+1]+=2;
        else tsum[i+1]++;
    }
    rep(i,q){
        int a,b,c,d; cin>>a>>b>>c>>d;
        int snum=ssum[b]-ssum[a-1];
        int tnum=tsum[d]-tsum[c-1];
        if(abs(snum-tnum)%3==0) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

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

int main()
{
    ios::sync_with_stdio(0);
    int a,b,res=1;
    cin>>a>>b;
    if(a<=0&&b>=0)puts("Zero");
    else if(a<0&&(b-a)%2==0)puts("Negative");
    else puts("Positive");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a,b,t[100001],n;
bool ch(int x){
    int u=0;
    r(i,n){
        if(t[i]-x*b>0){
            int p=t[i]-b*x;
            u+=p/(a-b);
            if(p%(a-b))u++;
        }
    }
    return u<=x;
}
main(){
    cin>>n>>a>>b;
    r(i,n)cin>>t[i];
    int l=0,r=1e9;
    while(l<r){
        int mid=(l+r)/2;
        if(ch(mid))r=mid;
        else l=mid+1;
    }
    cout<<l<<endl;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    char prev = '\0';
    char now = s[0];
    vs32 pos0;
    vs32 pos1;
    pos1.push_back(0);
    rep (i, n)
    {
        now = s[i];
        if (prev != now)
        {
            if (now == '0')
            {
                pos0.push_back(i);
            }
            else
            {
                pos1.push_back(i);
            }
        }
        prev = now;
    }

    int ans = 0;
    for (auto l : pos1)
    {
        auto itr = lower_bound(pos0.begin(), pos0.end(), l);
        if (itr + k < pos0.end())
        {
            ans = MAX(ans, *(itr + k) - l);
        }
        else
        {
            ans = MAX(ans, n - l);
        }
    }

    cout << ans << "\n";
    return 0;
}



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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

#define int long long

using namespace std;

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

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60, lmod = 1e9+7;
const int MAX_N = 100005;

class Edge{
  public:
    int cost; ll to;
    Edge(int cost,ll to)
      :cost(cost),to(to){}
};

void dijkstra(ll start,unordered_map<ll,vector<Edge>> &graph,unordered_map<ll,int> &dist){
  priority_queue<Pl,vector<Pl>,greater<Pl>> que;
  dist[start] = 0;
  que.push(Pl(0,start));
  while(!que.empty()){
    Pl p=que.top(); que.pop();
    ll v=p.second; //行き先
    if(dist[v]==0&&v!=0LL) dist[v] = INF;
    if(dist[v]<p.first) continue;
    for(Edge e: graph[v]){
      if(dist[e.to]==0&&e.to!=0LL) dist[e.to] = INF;
      if(dist[v]+e.cost<dist[e.to]){
        dist[e.to]=dist[v]+e.cost;
        que.push(P(dist[e.to],e.to));
      }
    }
  }
  return ;
}

void add_edge(ll p,ll q,ll c,unordered_map<ll,vector<Edge>> &graph){
  ll p0,pc,q0,qc;
  p0 = ll(p); q0 = ll(q);
  pc = p0 | (c<<30);
  qc = q0 | (c<<30);
  graph[p0].pb(Edge(1,pc));
  graph[pc].pb(Edge(1,p0));
  graph[pc].pb(Edge(0,qc));
  graph[qc].pb(Edge(0,pc));
  graph[qc].pb(Edge(1,q0));
  graph[q0].pb(Edge(1,qc));
}

signed main(){
  int N,M; cin >> N >> M;
  unordered_map<ll,vector<Edge>> graph;
  unordered_map<ll,int> dist;
  rep(i,M){
    ll p,q,c; scanf("%lld%lld%lld",&p,&q,&c);
    p--; q--;
    add_edge(p,q,c,graph);
  }
  dijkstra(0LL,graph,dist);
  ll ans;
  if(dist[ll(N-1)]!=0 && dist[ll(N-1)]!=INF){
    ans = dist[ll(N-1)]/2LL;
  }else{
    ans = -1LL;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 77172
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n,k;
	cin>>n>>k;
	int cnt = 0;
	while( n > 0 ){
		n = n/k;
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{
    class Program
    {   
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int swapCount = 0;
            
            for(int i = 0; i < n; i++)
            {
                for(int j = n-1; j>i; j--)
                {
                    if (array[j] < array[j - 1])
                    {
                        Swap(ref array[j], ref array[j-1]);

                        swapCount++;

                    }
                }
            }
            for (int i = 0; i < n; i++)
            {
                if (i != n - 1)
                {
                    Console.Write(array[i]+" ");
                }else
                {
                    Console.WriteLine(array[i]);
                }
            }
            Console.WriteLine(swapCount);
        }

        static void Swap(ref int x,ref int y)
        {
            int tmp = x;
            x = y;
            y = tmp;
        }

    }
}

Measured memory_bytes: 9516
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		int n, i, j = 0, pow, k, m, counter;
		try (Scanner sc = new Scanner(System.in)) {
			n = sc.nextInt();
			k = sc.nextInt();
			int[] a = new int[n];
			pow = (int) (Math.pow(2, n));
//			for(Integer output : b) {
//				System.out.print(output + " ");
//			}
			for(i = 0; i < pow; i++) {
				m = i;
				counter = 0;
				for(j = 0; m != 0; j++) {
					if(m % 2 == 1) {
						a[j] = 1;
						counter++;
					}else {
						a[j] = 0;
					}
					m /= 2;
				}
				if(counter != k) continue;
				System.out.print(i + ":");
				for(j = 0; j < a.length; j++) {
					if(a[j] == 1) {
						System.out.print(" " + j);
					}
				}
				System.out.println();
			}
		}
	}
}


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

int main(void){
    int a, b;

    cin >> a >> b;

    int res = 0;
    for(int i = 0; i < 2; i++){
        if(a >= b){
            res += a;
            a--;
        } else {
            res += b;
            b--;
        }
    }
    cout << res << endl;

    return 0;
}

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


int main(){
    int n,h;
    cin >> n >> h;
    int mx = 1e9;
    multiset<P> s;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        s.insert(make_pair(a,mx));
        s.insert(make_pair(b,1));
    }
    int cnt = 0;
    while(h>0){
        P p = *(--s.end());
        s.erase(--s.end());
        if(p.second == 1){
            h -= p.first;
            cnt++;
        }else{
            cnt += (h/p.first);
            if(h%p.first) cnt++;
            h = 0;
        }
    }

    cout << cnt << endl;
    
}


Measured memory_bytes: 12968
s = input()
len_s = len(s)
w = list("keyence")

ans = "NO"
if s[0:7] == "keyence":
    ans = "YES"
elif s[0] == "k" and s[len_s-6:] == "eyence":
    ans = "YES"
elif s[0:2] == "ke" and s[len_s-5:] == "yence":
    ans = "YES"
elif s[0:3] == "key" and s[len_s-4:] == "ence":
    ans = "YES"
elif s[0:4] == "keye" and s[len_s-3:] == "nce":
    ans = "YES"
elif s[0:5] == "keyen" and s[len_s-2:] == "ce":
    ans = "YES"
elif s[0:6] == "keyenc" and s[len_s-1:] == "e":
    ans = "YES"
elif s[len_s-7:] == "keyence":
    ans = "YES"

print(ans)

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

const int MAX = 100002;

void	ComInit(vector<long> &fac, vector<long> &finv, vector<long> &inv) {
	fac.at(0) = 1;
	fac.at(1) = 1;
	finv.at(0) = 1;
	finv.at(1) = 1;
	inv.at(1) = 1;
	for (int i=2; i<MAX; i++) {
		fac.at(i) = (fac.at(i-1)*i) %MOD;
		inv.at(i) = MOD - (inv.at(MOD%i)*(MOD/i)) %MOD;
		finv.at(i) = (finv.at(i-1)*inv.at(i)) %MOD; 
	}
}

long	COM(int N, int K, vector<long> &fac, vector<long> &finv) {
	if (N<K)
		return 0;
	if ((N<0)||(K<0))
		return 0;
	return (fac.at(N) * ((finv.at(K)*finv.at(N-K)) %MOD)) %MOD;
}

int	main() {
	// Array
	vector<long> fac(MAX);
	vector<long> finv(MAX);
	vector<long> inv(MAX);
	// Initialize
	ComInit(fac, finv, inv);
	/*
	// Example
	cout << "N?";
	int i;
	cin >>i;
	for (int j=0; j<=i; j++)
		cout << i << 'C' << j << " = " << COM(i, j, fac, finv) << endl;
	*/
	long n;
	cin >>n;
	vector<long> a(n+2, 0);
	vector<long> b(n+1, 0);
	long l=0;
	long r=0;
	for (int i=1; i<=n+1; i++) {
		cin >>a.at(i);
		if (0==b.at(a.at(i)))
			b.at(a.at(i))=i;
		else {
			l=b.at(a.at(i));
			r=i;
		}
	}
	for (int long i=1; i<=n+1; i++) {
		long S=COM(n+1, i, fac, finv);
		S +=MOD-COM(n-r+l, i-1, fac, finv);
		S %=MOD;
		cout <<S <<endl;
	}
	return 0;
}



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

int main(){
    int N;
    scanf("%d",&N);
    int i;
    double money,ans=0.0;
    char k[4];
    for(i=0;i<N;i++){
        scanf("%lf %s",&money,k);
        if(k[0]=='J') ans += money;
        else ans += money*380000.0;
    }
    printf("%f",ans);
    return 0;
}

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

int main()
{
  double N, sum = 0;
  double a[110];
  cin >> N;
  REP(i, N) {
    cin >> a[i];
    sum += a[i];
  }
  
  double avg_upper, avg_downer;
  avg_upper = ceil(sum / N);
  avg_downer = floor(sum / N);

  if (sum < 0)
    avg_downer -= 1;
 	
  int upper_cost = 0, downer_cost = 0;
  REP(i, N) {
    upper_cost += pow(avg_upper - a[i], 2);
    downer_cost += pow(avg_downer - a[i], 2);
  }
  
  cout << min(upper_cost, downer_cost) << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
h = Hash.new(0)
a.each do |x|
  h[x] += 1
end
f = true
h.each do |k, v|
  if n.odd? && k == 0
    if v != 1
      f = false
      break
    end
  elsif v != 2
    f = false
    break
  end
end
MOD = 1_000_000_007
def mpow(n, p, mod)
  r = 1
  while p > 0
    r = r * n % mod if p & 1 == 1
    n = n * n % mod
    p >>= 1
  end
  r
end
puts (f ? mpow(2, n / 2, MOD) : 0)

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

using namespace std;

class Solution {
public:
	void solve() {
		int a, b, m;
		cin >> a >> b >> m;
		vector<int> ca(a, 0),cb(b,0);
		for(int i=0; i<a; i++)cin >> ca[i];
		for(int i=0; i<b; i++)cin >> cb[i];
		int ans = *min_element(ca.begin(), ca.end()) + *min_element(cb.begin(), cb.end()); 
		for(int i=0; i < m; i++){
			int x, y, c;
			cin >> x >> y >> c;
			x--, y--;
			ans = min(ans, ca[x] + cb[y]-c);
		}
		cout << ans << "\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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


int main (){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(a > 0 && c > 0){
    /*takahashi no kougeki*/
    c -= b;
    if(c <= 0){
      cout << "Yes" << endl;
      break;
    }
    /*aoki no kougeki*/
  	a -= d;
    if(a <= 0){
      cout << "No" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const int DEBUG = 0;

const int N = 400;
int c[N][4];
ll hashes[N];

map<ll, int> dict;
map<ll, int> mult;

pair<ll, int> norm(ll hash) {
  ll mi = hash;
  map<ll, int> t;
  REP(j, 0, 4) {
    if (t.count(hash) == 0) {
      t[hash] = 0;
    }
    t[hash]++;
    mi = min(mi, hash);
    hash = hash * 1000 % 999999999999;
  }
  return pair<ll, int>(mi, t[hash]);
}

ll calc(const VI &cols, int j) { // calucates #ways to fill in the rest 4 squares in [i, n) - {j}
  ll jhash = hashes[j];
  ll prod = 1;
  map<ll, int> alt;
  REP(k, 0, 4) {
    ll hash = cols[k] + cols[4 + k] * 1000;
    hash += ll(cols[4 + ((1 + k) % 4)]) * 1000000;
    hash += ll(cols[(k + 1) % 4]) * 1000000000;
    hash = norm(hash).first;
    if (alt.count(hash) == 0) {
      alt[hash] = 0;
    }
    alt[hash]++;
  }
  for (map<ll, int>::iterator it = alt.begin(); it != alt.end(); ++it) {
    ll hash = it->first;
    int times = it->second;
    if (dict.count(hash) == 0) {
      return 0;
    }
    int numh = dict[hash];
    if (DEBUG) { cerr << "original numh = " << numh << endl; }
    if (jhash == hash) {
      numh--;
    }
    assert (numh >= 0);
    ll tmp = 1;
    REP(k, 0, times) {
      tmp *= numh - k;
      tmp *= mult[hash];
    }
    prod *= tmp;
    if (DEBUG) { cerr << "C(" << numh << "," << times << ") * mult^times=" << tmp << endl; }
  }
  return prod;
}

int main(void){
  int n;
  cin >> n;
  REP(i, 0, n) {
    REP(j, 0, 4) {
      cin >> c[i][j];
    }
  }
  ll sum = 0;
  for (int i = n - 1; i >= 0; --i) { // the top facet is fixed (including its direction)
    if (i < n - 5) {
      REP(j, i + 1, n) { // the bottom facet is fixed
	if (DEBUG) {
	  cerr << "(i, j) = " << i << ", " << j << endl;
	}
	REP(k, 0, 4) { // the direction of the bottom facet is fixed
	  if (DEBUG) { cerr << "rotation " << k << endl; }
	  VI cols(8);
	  REP(l, 0, 4) {
	    cols[l] = c[i][l];
	  }
	  REP(l, 0, 4) {
	    cols[7 - l] = c[j][(l + k) % 4];
	  }
	  sum += calc(cols, j);
	  if (DEBUG) { cerr << "sum = " << sum << endl; }
	}
      }
    }
    ll hash = 0; // c0 + 10^3 c1 + 10^6 c2 + 10^9 c3
    REP(j, 0, 4) {
      hash *= 1000;
      hash += c[i][3 - j];
    }
    pair<ll, int> normed = norm(hash);
    hashes[i] = hash = normed.first;
    if (dict.count(hash) == 0) {
      dict[hash] = 0;
    }
    dict[hash]++;
    mult[hash] = normed.second;
    if (DEBUG) { cerr << "added: " << hash << "[" << dict[hash] << "]" << endl;}

  }
  cout << sum << endl;
}


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

using namespace std;

typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<int, int> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  vector<P> R(N), B(N);
  REP(i, N)
  cin >> R[i].second >> R[i].first;
  REP(i, N)
  cin >> B[i].first >> B[i].second;
  sort(ALL(R));
  reverse(ALL(R)); // 赤い点をy座標の降順にソート
  sort(ALL(B));    // 青い点をx座標の昇順にソート
  int ans = 0;
  REP(i, N)
  {
    REP(j, R.size())
    {
      if (R[j].second < B[i].first && R[j].first < B[i].second)
      {
        ans++;
        R.erase(R.begin() + j);
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

    vector<int> a(n), b(n), c(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }
    for(int i=0; i<n; i++){
        cin >> b.at(i);
    }
    for(int i=0; i<n; i++){
        cin >> c.at(i);
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    long long int count = 0;
    for(int i=0; i<n; i++){
        long long int n_a = lower_bound(a.begin(), a.end(), b.at(i)) - a.begin();
        long long int n_c = c.end() - upper_bound(c.begin(), c.end(), b.at(i));
        count += n_a * n_c;
    }

    cout << count << endl;

}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
const int INF = 1e18;

int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

signed main(){
    int n; cin >> n;
    cout << a[n-1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

class SegmentTree {
  vector<long long> dat;
  int n = 1;
  long long def;
public:
  SegmentTree(int num, long long d) : def(d) {
    while (n < num)
      n <<= 1;
    dat.resize(2 * n - 1, def);
  }
  void update(int i, long long x) {
    i += (n - 1);
    dat[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      dat[i] = max(dat[2 * i + 1], dat[2 * i + 2]);
    }
  }
  long long query(int a, int b, int i = 0, int li = 0, int ri = -1) {
    if (!i) ri = n;
    if (ri <= a || li >= b) return def;
    if (li >= a && ri <= b) return dat[i];
    long long vl = query(a, b, 2 * i + 1, li, (li + ri) / 2);
    long long vr = query(a, b, 2 * i + 2, (li + ri) / 2, ri);
    return max(vl, vr);
  }
  int upper_left(int a, int b, long long x, int i = 0, int li = 0, int ri = -1) {
    if (!i) ri = n;
    if (dat[i] < x || ri <= a || li >= b) return b;
    if (ri - li == 1) return li;
    int vl = upper_left(a, b, x, 2 * i + 1, li, (li + ri) / 2);
    if (vl < b)
      return vl;
    return upper_left(a, b, x, 2 * i + 2, (li + ri) / 2, ri);
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  SegmentTree st(n, 0);
  rep(i, n) {
    int a;
    cin >> a;
    st.update(i, a);
  }
  rep(_, q) {
    int t;
    cin >> t;
    if (t == 1) {
      int x, v;
      cin >> x >> v;
      --x;
      st.update(x, v);
    }
    else if (t == 2) {
      int l, r;
      cin >> l >> r;
      --l;
      cout << st.query(l, r) << '\n';
    }
    else {
      int l, v;
      cin >> l >> v;
      --l;
      cout << st.upper_left(l, n, v)+1 << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 7420
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,count;
  cin >> a >> b >> c;
  count = 0;
  if(a == b){
    count ++;
  }
  if(a == c){
    count ++;
  }
  if(c == b){
    count ++;
  }
  if(count < 2){
   cout << 3-count << endl;
  }else{
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
Z = [0,1,2,3,4,5,5,4,3,2,1,1]
C = [0,1,2,5,6,7]
X = [0,1,2,1,2,3]
C=[0,1,2,3,4,5,6,7,8,9]
X=[0,1,2,3,4,5,6,7,8,9]
def solve_dp(s):
    n = len(s)
    s = [int(c) for c in s]
    inf = 10**9

    dp = [[inf] * 2 for _ in range(n)]

    d0 = s[0]
    dp[0][0] = Z[d0]
    dp[0][1] = Z[d0+1]

    for i in range(1, n):
        for j in range(2):
            d = s[i] + j
            for k in range(10):
                if d + C[k] >= 10:
                    dp[i][j] = min(dp[i][j], dp[i-1][1] + X[k] + Z[d + C[k] - 10])
                else:
                    dp[i][j] = min(dp[i][j], dp[i-1][0] + X[k] + Z[d + C[k]])

    return dp[n-1][0]

if __name__ == '__main__':
    s = input()
    print(solve_dp(s))

Measured memory_bytes: 156424
package main

import (
	"fmt"
)

func main() {
	var a float64
	var b float64

	fmt.Scan(&a)
	fmt.Scan(&b)

	n := 0
	if a <= 5 {
		n = 0
	} else if a >= 6 && a <= 12 {
		n = int(b / 2)
	} else {
		n = int(b)
	}

	fmt.Println(n)
}


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

int main()
{
  vector<int> antenna = vector<int>(5);
  int k;
  
  for(int i = 0; i < 5; i++)
    cin >> antenna.at(i);
  
  cin >> k;
  
  bool b = true;
  for(int i = 0; i < 5; i++)
  {
    for(int j = 0; j < 5; j++)
    {
      if((antenna.at(i) - antenna.at(j)) > k)
      {
        b = false;
        break;
      }
    }
    if(!b)
      break;
  }
  
  if(b)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Array
import Data.Bool

main = sol <$> get <*> get >>= print

get = fmap read . words <$> getLine

sol [n,a] as = dp!(n,0)-1
  where
  bs = (subtract a) <$> as
  ar = listArray (1,n) bs
  mx = n*max (maximum bs) (-minimum bs)
  bnds = ((0,-mx),(n,mx))
  dp = array bnds $ (,) <*> f <$> range bnds
    where
    f (0,0) = 1
    f (0,_) = 0
    f (i,j) = dp!(i-1,j) + bool 0 (dp!(i-1,j-ar!i)) (inRange bnds (i-1,j-ar!i))


Measured memory_bytes: 48380
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		while(scan.hasNext()) {
			int H = scan.nextInt(), W = scan.nextInt();
			if(H == 0 && W == 0) {
				break;
			}else {
				for(int i = 0 ; i < H ; i++) {
					for(int j = 0 ; j < W ; j++) {
						System.out.print("#");
					}
					System.out.println();
				}
				System.out.println();
			}
		}
		scan.close();
	}

}



Measured memory_bytes: 34784
S = input()
K = int(input())
z = ord('z') + 1

res = ""
flg = False
for i,c in enumerate(S):
    if c == 'a':
        res += 'a'
        continue
    elif z - ord(c) <= K:
        res += 'a'
        K -= z-ord(c)
    else:
        res += chr(ord(c))

res = res[:-1] + chr((ord(res[-1])-ord('a') + K) % 26 + ord('a'))
print(res)

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

#include<stdlib.h>
#include<iostream>
#include<math.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define INF 2000000000
#define Min(a,b) (a<b?a:b)
#define Max(a,b) (a>b?a:b)
#define PI 3.1415926535897932
using namespace std;

int main()
{
IOS;
int t;
cin>>t;
string s;
cin>>s;
if(s.size()<=t)
	cout<<s;
else{
	string t1=s.substr(0,t);
	t1+="...";
	cout<<t1;
}




return 0;
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	auto r = vector<int>(n + 1);
	for(auto i = 0; i < m; ++i){
		int a, b;
		cin >> a >> b;
		++r[a];
		++r[b];
	}
	for(auto i = 1; i <= n; ++i){
		cout << r[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = b[a[0]-1]
for i in range(1,n):
  ans += b[a[i]-1]
  if a[i] == a[i-1] + 1:
    ans += c[a[i]-2]
print(ans)

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

const int bit_size = 17;
const int max_n = 1001;

vector<vector<P>> v(bit_size*max_n);
ll dist[bit_size*max_n];
vector<string> str(max_n);


void check(int a, int b, int it){
	int it_a = it;
	int it_b = 0;
	int cou = 0;
	while(it_a < str[a].size() && it_b < str[b].size()){
		if(str[a][it_a] != str[b][it_b])return;
		it_a++;
		it_b++;
		cou++;
	}

	if(it_b == str[b].size())v[bit_size*a+it].EB(bit_size*a+it_a, cou);
	if(it_a == str[a].size())v[bit_size*a+it].EB(bit_size*b+it_b, cou);
}

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

	ll n;cin >> n;
	REP(i, n)cin >> str[i];

	REP(i, n){
		REP(j,str[i].size()){
			REP(k, n)if(j != 0 || i != k)check(i, k, j);
		}
	}

	REP(i, bit_size*max_n)dist[i] = INF;
	priority_queue<P, vector<P>, greater<P>> pq;
	REP(i, n)dist[bit_size*i] = 0, pq.push(MP(0, bit_size*i));

	while(!pq.empty()){
		int d = pq.top().FI;
		int node = pq.top().SE;
		pq.pop();
		if(d > dist[node])continue;
		REP(i, v[node].size()){
			int aite = v[node][i].FI;
			int cost = v[node][i].SE;
			if(dist[aite] > d + cost){
				dist[aite] = d + cost;
				pq.push(MP(dist[aite], aite));
			}
		}
	}

	ll ans = INF;
	REP(i, n)ans = min(ans, dist[bit_size*i+str[i].size()]);
	cout << (ans == INF ? 0 : ans) << endl;

	return 0;
}



Measured memory_bytes: 25180
#include <bits/stdc++.h>
using ll = long long;
const int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i < (n); i++)
using namespace std;
int get_gcd(int a, int b) {
  while(1) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    a %= b;
  }
}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

main () {
  ll n;
  scanf("%lld", &n);

  printf("%lld\n", (n-1)*n/2);

  return 0;
}


Measured memory_bytes: 256
#a,b=(int(x) for x in input().split()) #数値の時

a,b,c,d=(int(x) for x in input().split())

while(True):
    c=c-b

    if(c<=0):
        print("Yes")
        break

    a=a-d
    if(a<=0):
        print("No")
        break




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

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

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
#define int long long
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; }
//lambda: [&](int x, int y){return x<y;}

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

    int both=0,a=0,b=0;
    rep(i,n){
        string s;cin>>s;
        rep(j,s.size()-1)if(s[j]=='A'&&s[j+1]=='B')ans++;
        if(s[0]=='B'&&s.back()=='A')both++;
        else if(s[0]=='B')b++;
        else if(s.back()=='A')a++;
    }
    if(a+b==0)ans+=max(0LL,both-1);
    else ans+=both+min(a,b);
    cout << ans << endl;

}


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

int main() {
	string s;
	cin >> s;
	if (s.size() < 4) {
		cout << 0;
		return 0;
	}
	int cur = 0;
	int res = 0;
	int power = 1;
	unordered_map<int, int> mod;
	mod[0] = 1;
	for (int i = s.size()-1; i >= 0; i--) {
		int dig = s[i] - '0';
		cur = (cur + dig * power) % 2019;
		power = power * 10 % 2019;
		if (mod.find(cur) == mod.end()) {
			mod[cur] = 1;
		}
		else {
			res += mod[cur];
			mod[cur]++;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
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;
    cin >> n;
    cout << n * 3.141592653589 * 2;
}


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


int parent(int x, vector<int>& unionArr)
{
    if(unionArr[x] == x) return x;
    return unionArr[x] = parent(unionArr[x], unionArr);
}

void unioner(int x, int y, vector<int>& unionArr)
{
    unionArr[x] = y;
}

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

    int N, M;
    cin >> N >> M;

    vector<int> unionArr(N+1, 0);
    std::iota(unionArr.begin(), unionArr.end(), 0);

    std::vector<pair<int, int>> roads(M);
    for(int i = 0; i < M; i++)
    {
	int A, B;
	cin >> A >> B;

	roads[i] = {A, B};
    }

    int roadsUsed = 0;
    for(pair<int, int> road : roads)
    {
	int city1 = parent(road.first, unionArr);
	int city2 = parent(road.second, unionArr);

	if(city1 != city2)
	{
	    unioner(city1, city2, unionArr);
	    roadsUsed++;
	}	
    }


    std::cout << (N-1) - roadsUsed << "\n";

    return 0;
}


Measured memory_bytes: 4520
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

VB Eratosthenes(int N) {
	VB prime(N+1, true);
	prime[0] = prime[1] = false;
	FOR(i, 2, sqrt(N)) if(prime[i]) for (int j = 2 * i; j <= N; j += i) prime[j] = false;
	return prime;
}



int main(void){
	
	VB prime = Eratosthenes(100000);
	VI like2017(100000 + 1, 0);
	for (int i = 3; i < 100000 + 1; i += 2) if ((prime[i]) && (prime[(i + 1) / 2])) like2017[i] = 1;
	for (int i = 3; i < 100000 + 1; i++) like2017[i] += like2017[i - 1];
	
	int Q;
	cin >> Q;
	
	VI l(Q), r(Q);
	REP(i, Q) cin >> l[i] >> r[i];
	REP(i, Q) cout << like2017[r[i]] - like2017[l[i] - 1] << endl;
	return 0;
}





Measured memory_bytes: 1792
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
    int N,D,X;
    cin>>N>>D>>X;
    int A[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    int sum=0;
    for(int j=0;j<N;j++){
        if(D%A[j]!=0)
        sum=sum+D/A[j]+1;
        else sum=sum+D/A[j];
    }
    cout<<sum+X;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	vector<int> v(1e6);
	cin >> v[0];
	int min = 0;
	bool loop = true;

	while(loop){
		if(v[min] % 2 == 0)
			v[min + 1] = v[min] / 2;
		else v[min + 1] = 3 * v[min] + 1;
		min++;
		REP(j, min) if(v[j] == v[min]) loop = false;
	}
	cout << min + 1 << endl;
}


Measured memory_bytes: 4096
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#include <time.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;


int main(int argc, char* argv[])
{
    int n; ll d,a;
    scanf("%d%lld%lld", &n, &d, &a);
    map<pair<ll,int>,ll> z;   // x, flag(0:judge, 1:sub), val
    int i;
    for(i=0; i<n; i++) {
        ll x,h;
        scanf("%lld%lld", &x, &h);
        z[make_pair(x,0)]+=h;
    }

    ll curr=0;
    ll cnt=0;
    auto it=z.begin();
    for(; it!=z.end();++it) {
        ll x=it->first.first;
        ll flag=it->first.second;
        ll val=it->second;
        if(flag) {
            curr-=val;
        }
        else {
            val-=curr;
            if(val>0) {
                ll cnt0=(val-1+a)/a;
                cnt+=cnt0;
                curr+=cnt0*a;
                z[make_pair(x+d*2,1)]+=cnt0*a;
            }
        }
    }
    printf("%lld\n", cnt);

    return 0;
}


Measured memory_bytes: 25216
from functools import reduce


def gcd(a, b):
    if b == 0:
        return a
    if b > a:
        return gcd(b, a)
    return gcd(b, a % b)


N = int(input())
A = list(map(int, input().split()))
print(reduce(lambda a, b: gcd(a, b), A))


Measured memory_bytes: 14596
import bisect
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(n):
  a.append(a[i] + A[i])
for i in range(m):
  b.append(b[i] + B[i])
ans = 0
for i in range(n+1):
  if a[i] > k:
    break
  ans = max(ans,i+bisect.bisect(b,k-a[i])-1)
print(ans)

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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int d[3];
	d[0] = a;
	d[1] = b;
	d[2] = c;
	int temp;
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 2; j++){
			if(d[j] > d[j+1]){
				temp = d[j];
				d[j] = d[j+1];
				d[j+1] = temp;
			}
		}
	}
	cout<<d[0]<<" "<<d[1]<<" "<<d[2]<<endl;
	

	return 0;
}

Measured memory_bytes: 3088
#require 'prime'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+(1 if ar[i]=='1').to_i}; s end ###
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
h,w,k=gsmi
s=h.times.map{gs.chars}

# 各列の白累積和
rui=[]
st=s.transpose
w.times do |i|
  tar=st[i]
  ar=rui(tar)
  rui<<ar
end

# 横線引くパターン全探索
pat=2**(h-1)
min=1000+10
pat.times do |i|
  idxs=[]
  h.times do |j|
    idxs<<j+1 if i[j]==1
  end
  #pu idxs:idxs.to_s
  cnt=idxs.size
  w_c_ar=Array.new(cnt+1,0)
  idxs<<h
  w.times do |j|
    cnt_ar=[]
    prev=0
    idxs.each do |kk|
      #pu kk:kk,prev:prev
      c = rui[j][kk]-rui[j][prev]
      cnt_ar << c
      prev=kk
    end

    # １列でkを超える場合はbreak
    if cnt_ar.select{|x|x>k}.any?
      cnt=1000+10
      break
    end

    tmp_ar = w_c_ar.zip(cnt_ar).map{|a,b|a+b}
    #pu tmp_ar:tmp_ar.to_s
    # この列を加えてkを超えたら左に縦線を引く
    if tmp_ar.select{|x|x>k}.any?
      cnt+=1
      w_c_ar=cnt_ar
    else
      w_c_ar=tmp_ar
    end
  end
  #pu cnt:cnt
  min=cnt if min>cnt
end

puts min

Measured memory_bytes: 3580
/*#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")*/
//#pragma GCC optimize("fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#define _CRT_SECURE_NO_WARNINGS
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <math.h>
#include <random>
using namespace std;
typedef long long  ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
#define all(a) a.begin(), a.end()
#define lb(a, x) lower_bound(a.begin(), a.end(), x)
#define pb(x) push_back(x)
#define fr(i, n) for(int i = 0; i < n; ++i)
//typedef cc_hash_table<int, int, hash<int>> hst2;
//typedef cc_hash_table<int, hst2, hash<int>> hst;
typedef pii ord_set_t;
#ifdef ABCD
typedef map<ord_set_t, vi> ordered_set;
int __builtin_popcount(int x)
{
	int cnt = 0;
	for (; x > 0; x >>= 1) cnt += x & 1;
	return cnt;
}
#else
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
mt19937 rnd(239);
using namespace __gnu_pbds;
typedef tree<
	ord_set_t,
	vi,
	less_equal<ord_set_t>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;
#endif
const int N = 300001;
ll a[N], b[N];
ll dp[N][2];
int main()
{

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef ABCD
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else

#endif
	int n; cin >> n;
	fr(i, n + 1) cin >> a[i];
	fr(i, n) cin >> b[i];
	ll sum = 0;
	fr(i, n)
	{
		ll t = min(a[i], b[i]);
		a[i] -= t;
		b[i] -= t;
		sum += t;

		t = min(a[i + 1], b[i]);
		sum += t;
		a[i + 1] -= t;
		b[i] -= t;
	}
	cout << sum;
}


Measured memory_bytes: 4352
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

R = inp()
print(math.pi * 2 * R)



Measured memory_bytes: 9944
implicit none
integer, parameter :: ubnd = 2**10 - 1
integer N
integer,allocatable,dimension(:,:)::f, p
integer,allocatable,dimension(:)::s
integer :: i, j, k, op, g(ubnd)
  read*, n
  allocate(f(n,10),p(n,0:10),s(n))
  do i = 1, n
    read*, f(i,:)
  end do
  do i = 1, n
    read*, p(i,:)
  end do
  g=0
  do k = 1, ubnd
    s = 0
    do j = 1, 10
      if (btest(k,j-1))s = s + f(:,j)
    end do
    do i = 1, n
      g(k) = g(k) + p(i,s(i))
    end do
  end do
  print"(i0)",maxval(g)
end

Measured memory_bytes: 384
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
A_b = [0] * N

if N == K:
    print(1)
else:
    n = 1
    N -= K
    while N > 0:
        N -= (K - 1)
        n += 1
    print(n)


Measured memory_bytes: 13880