akhauriyash/Code-Regression huggingface dataset:
s = input()
t = input()
def check(a, b):
  if a == '?':
    return True
  else:
    return a == b
  
cand = []
for i in range(len(s)-len(t)+1):
  flag = True
  c = list(s)
  for j in range(len(t)):
    if not check(s[i+j], t[j]):
      flag = False
      break
    c[i+j] = t[j]
  if flag:
    cs = ''.join(c)
    cand.append(cs.replace('?', 'a'))
if len(cand):
  cand.sort()
  print(cand[0])
else:
  print("UNRESTORABLE")
    


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using ll = long long;
#define MOD 1000000007
using namespace std;

int main(){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> A(N);
    A[0] = 0;
    for(int i = 1; i < N; i++)
    {
        A[i] = A[i-1];
        if (S[i-1] == 'A' && S[i] == 'C') {
            A[i]++;
        }
    }
    for(int i = 0; i < Q; i++)
    {
        int l,r;
        cin >> l >> r;
        l--;r--;
        cout << A[r]-A[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
bool isPrime(ll x){
    if(x < 2) return false;
    if(x == 2) return true;
    if(x % 2 == 0) return false;
    for(ll i = 3;i <= sqrt(x) + 1;i += 2) if(x % i == 0) return false;
    return true;
}
int main(){
    ll Q;
    cin >> Q;
    int num[100010] = {};
    for(ll i = 3; i <= 100000; i += 2){
        if(isPrime(i) && isPrime((i+1)/2)) num[i]++; 
    }
    rep(i,0,100001){
        num[i+1] += num[i];
    }
    while(Q--){
        ll l,r;
        cin >> l >> r;
        cout << num[r] - num[l-1] << endl;
        
    }

}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto & a : A) cin >> a;
    int x = 0;
    for (int i = 1; i <= N + 1; ++i){
        x = A[x] - 1;
        if (x == 1){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
for i in sys.stdin:
    a, b, c, d, e, f = map(int, i.split())
    x = (c * e - b * f) / (a * e - b * d)
    y = (c * d - a * f) / (b * d - a * e)
    x = abs(x) if abs(x) < 10e-4 else x
    y = abs(y) if abs(y) < 10e-4 else y
    print("{:.3f} {:.3f}".format(x, y))


Measured memory_bytes: 5620
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#pragma GCC optimize("unroll-loops")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define ST string
#define BS bitset
#define VE vector
#define VL vector<LL>
#define VP vector<pair<LL,LL>>
#define VVL vector<vector<LL>>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define EB emplace_back
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define LB(a,n) *lower_bound(ALL(a),n)
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000000000001
#define NUM 200010
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)printf("Yes\n");else printf("No\n");}
void YN(LL a){if(a)printf("YES\n");else printf("NO\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(m,d);x-=k*y;swap(x,y);}return mod(a*mod(x,MOD),MOD);}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(pair<LL,LL> a,pair<LL,LL> b){if(a.second!=b.second)return a.second<b.second;return a.first<b.first;}

LL POW2(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}

int main(){
  FAST;
  LL i,ans=0,N,P,m[10010]={0},a=0;
  string S;
  cin>>N>>P>>S;
  if(P==2||P==5){
    rep(i,S.size())if((S[i]-'0')%P==0)ans+=i+1;
  }else{
    m[0]++;
    for(i=N-1;i>=0;i--){
      a+=(S[i]-'0')*POW2(10,N-1-i,P);
      m[a%=P]++;
    }
    rep(i,P)ans+=m[i]*(m[i]-1)/2;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 848
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int[] result = new int[10000];
		int index = 0;
		
		int n = stdIn.nextInt();
		int m = stdIn.nextInt();
		int a = stdIn.nextInt();
		while( n != 0 || m != 0 || a != 0 ){
			int[] h = new int[m];
			int[] p = new int[m];
			int[] q = new int[m];
			int[][] check = new int[1001][n+1];
			int hMax = 0;
			for(int i = 0; i < m; i++){
				h[i] = stdIn.nextInt();
				p[i] = stdIn.nextInt();
				q[i] = stdIn.nextInt();
				if( h[i] > hMax ){
					hMax = h[i];
				}
				check[h[i]][p[i]] = q[i];
				check[h[i]][q[i]] = p[i];
			}
			int now = a;
			for(int i = hMax; i > 0; i--){
				if( check[i][now] != 0 ){
					now = check[i][now];
				}
			}
			result[index] = now;
			index++;
			n = stdIn.nextInt();
			m = stdIn.nextInt();
			a = stdIn.nextInt();
		}
		for(int i = 0; i < index; i++){
			System.out.println(result[i]);
		}
	}
}

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

namespace CSharpSample01
{

    class Exchange
    {
        public int point_taro_give = 0;
        public int point_hanako_give = 0;

        public Exchange(int t, int h)
        {
            point_taro_give = t;
            point_hanako_give = h;
        }

    }
    

    class Program
    {
        
        static List<Exchange> ExchangeCard(int[] taro_card, int[] hanako_card)
        {
            List<Exchange> exchange_list = new List<Exchange>();

            int taro_sum = 0;
            int hanako_sum = 0;

            for(int i = 0; i < taro_card.Length; i++)
            {
                taro_sum += taro_card[i];
            }

            for(int j = 0; j < hanako_card.Length; j++)
            {
                hanako_sum += hanako_card[j];
            }

            for(int i = 0; i < taro_card.Length; i++)
            {
                int taro_give = taro_card[i];              
                for(int j = 0; j < hanako_card.Length; j++)
                {
                    int hanako_give = hanako_card[j];
                    if(taro_sum - taro_give + hanako_give == hanako_sum - hanako_give + taro_give)
                    {
                        exchange_list.Add(new Exchange(taro_give, hanako_give));
                    }
                }
            }


            return exchange_list;
        }
        


        static void Main(string[] args)
        {

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                int n = int.Parse(input[0]);
                int m = int.Parse(input[1]);

                if(n == 0 && m == 0)
                {
                    break;
                }

                int[] taro_card = new int[n];
                int[] hanako_card = new int[m];

                for(int i = 0; i < n; i++)
                {
                    taro_card[i] = int.Parse(Console.ReadLine());
                }

                for(int i = 0; i < m; i++)
                {
                    hanako_card[i] = int.Parse(Console.ReadLine());
                }

                List<Exchange> exchange_list = ExchangeCard(taro_card, hanako_card);


                if(exchange_list.Count() == 0)
                {
                    Console.WriteLine("-1");
                }
                else
                {
                    int index_minsum = 0;
                    int min_sum = 1000;
                    for (int i = 0; i < exchange_list.Count(); i++)
                    {
                        Exchange card_pair = exchange_list[i];
                        int sum_pair = card_pair.point_taro_give + card_pair.point_hanako_give;
                        if (sum_pair < min_sum)
                        {
                            min_sum = sum_pair;
                            index_minsum = i;
                        }
                    }
                    Console.WriteLine($"{exchange_list[index_minsum].point_taro_give} {exchange_list[index_minsum].point_hanako_give}");
                }


            }
            
        }
    }
}


Measured memory_bytes: 16268
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	if ((N + M) & 1)cout << "IMPOSSIBLE\n";
	else cout << (N + M) / 2 << endl;
}


Measured memory_bytes: 256
#<100q.全探索（計算量注意）>
a, b, c, x, y = map(int,input().split())
ans1 = a * x + b * y
if x <= y:
    ans2 = c * 2 * x + b * (y - x)
    ans5 = c * 2 * y
else:
    ans2 = c * 2 * y + a * (x - y)
    ans5 = c * 2 * x
ans3 = a * x + c * 2 * y
ans4 = b * y + c * 2 * x
##print(ans1)
##print(ans2)
##print(ans3)
##print(ans4)
##print(ans5)
print(min(ans1,ans2, ans3, ans4, ans5))


Measured memory_bytes: 9188
#include<stdio.h>
int main()
{
    int i,len,count=0;
    char ara[102];
    scanf("%s",&ara);
    len=strlen(ara);
    for(i=0;i<(len/2);i++)
    {
        if(ara[i]!=ara[len-1-i])
        {
            count++;
        }


    }
    printf("%d",count);




    return 0;
}


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

int main(void){
	long e,x,y,z,m,temp;

	while(1){
		cin >> e;
		if(e==0)break;
		
		m=e;
		for(z=0; z*z*z<=e; ++z){
			for(y=0; y*y+z*z*z<=e; ++y){
				x = e-(y*y)-(z*z*z);
				m = min(m,x+y+z);
			}
		}

		cout << m << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);

        string A;
        string B;
        string C;

        A = a.ToString();
        B = b.ToString();
        C = A + B;
        int c = int.Parse(C);

        int sq = (int)System.Math.Sqrt(c);

        if (c == sq * sq)
        {
            Console.WriteLine("Yes");
        }
        else { Console.WriteLine("No"); }
    }
}

Measured memory_bytes: 11092
#!/usr/bin/env python3

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))

if n >= m:
    print(0)
    exit()

x.sort()

diff = [x[i+1]-x[i] for i in range(m-1)]

diff.sort()


print(sum(diff[:m-n]))


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

using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll dp1[100001], dp2[100001];

int main() {
    int n;
    cin >> n;
    vector<int> a, b, c;
    vin(a, n);
    vin(b, n);
    vin(c, n);
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vector<int> bn(n, 0);
    int ai=0;
    rep(i,n) {
        int sum=0;
        while (ai<n and b[i]>a[ai]) { sum++; ai++; }
        if (!i) { bn[i] = sum; dp1[i] = sum; }
        else { bn[i] = dp1[i-1] + sum; dp1[i] = dp1[i-1] + sum; }
    }
    ll ans=0;
    int bi=0;
    rep(i,n) {
        ll sum=0;
        while(bi<n and c[i]>b[bi]) { sum+=bn[bi++]; }
        if (!i) { ans += sum; dp2[i] = sum; }
        else { ans += dp2[i-1] + sum; dp2[i] = dp2[i-1] + sum; }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

# 営業パターン全通りについて利益を計算する
ans_list = []
for i in range(1, 2**10):
    pattern = [0]*10
    for j in range(10):
        if ((i>>j) & 1):
            pattern[j] = 1
    profit = 0
    for k in range(N):
        n_time_both_open = 0
        for l in range(10):
            if pattern[l] & F[k][l] == 1:
                n_time_both_open += 1 
        profit += P[k][n_time_both_open]
    ans_list.append(profit)
    
print(max(ans_list))

Measured memory_bytes: 3064
#include<cstdio>
using namespace std;

int main(){
  char S[15];
  scanf("%s", &S);

  if (S[0] == 'S') printf("Cloudy\n");
  if (S[0] == 'C') printf("Rainy\n");
  if (S[0] == 'R') printf("Sunny\n");

  return 0;
}

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

typedef long long int ll;
typedef pair <ll, ll> pll;

const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const ll Inf = 1LL << 62;

struct Node {
	int s, t, x;
} ar[Max];

int d[Max];

vector <int> L[Max], R[Max];

int main() {
#ifdef Mr_Emrul
	freopen("inputf.in", "r", stdin);
#endif /// Mr_Emrul

	int n, q;
	scanf("%d %d", &n, &q);
	for(int i = 1; i <= n; i++) {
		scanf("%d %d %d", &ar[i].s, &ar[i].t, &ar[i].x);
	}
	for(int i = 1; i <= q; i++) {
		scanf("%d", &d[i]);
	}
	for(int i = 1; i <= n; i++) {
		int l = 1, r = q;
		int mn = -1, mx = -1;
		while(l <= r) {
			int mid = (l + r) >> 1;
			int T = ar[i].x + d[mid];
			if(T >= ar[i].s && T < ar[i].t) {
				mx = mid;
				l = mid + 1;
			}
			else if(T >= ar[i].t) {
				r = mid - 1;
			}
			else {
				l = mid + 1;
			}
		}
		l = 1, r = q;
		while(l <= r) {
			int mid = (l + r) >> 1;
			int T = ar[i].x + d[mid];
			if(T >= ar[i].s && T < ar[i].t) {
				mn = mid;
				r = mid - 1;
			}
			else if(T >= ar[i].t) {
				r = mid - 1;
			}
			else {
				l = mid + 1;
			}
		}
		if(mn != -1) {
			L[mn].push_back(ar[i].x);
			R[mx + 1].push_back(ar[i].x);
		}
		//printf("%d %d\n", mn, mx);
	}
	multiset <int> st;
	for(int i = 1; i <= q; i++) {
		for(int x : L[i]) {
			st.insert(x);
		}
		for(int x : R[i]) {
			st.erase(st.find(x));
		}
		if(st.size() == 0) {
			printf("-1\n");
		}
		else {
			printf("%d\n", *st.begin());
		}
	}
	return 0;
}

Measured memory_bytes: 118004
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, q;
string s;
char t[200000], d[200000];

int check(int pos) {
	int i;
	
	if (pos < 0) return -1;
	if (pos >= n) return 1;
	for (i = 0; i < q; i++) {
		if (t[i] == s[pos]) {
			if (d[i] == 'L') pos--;
			else pos++;
		}
		if (pos < 0) return -1;
		if (pos >= n) return 1;
	}
	return 0;
}

int getL() {
	int st = -1, ed = n, mid;
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (check(mid) == -1) st = mid;
		else ed = mid;
	}
	return st;
}

int getR() {
	int st = -1, ed = n, mid;
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (check(mid) == 1) ed = mid;
		else st = mid;
	}
	return ed;
}

signed main() {
	int i;
	
	cin >> n >> q >> s;
	rep(i, q) cin >> t[i] >> d[i];
	
	int l = getL();
	int r = getR();
	
	cout << max(0, r - l - 1) << endl;
	return 0;
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n, h, w;
    cin >> n >> h >> w;
    int c = 0;
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        if(a >= h && b >= w)
            ++c;
    }
    cout << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main ()
{
    int n,m,c=0;
    double s=0;
    cin>>n>>m;
    double x[n];
    for(int i=0;i<n;i++){
        cin>>x[i];
        s+=x[i];
    }
    sort(x,x+n);
    s=s/(4*m);
    for(int i=n-1;i>=0;i--)
    {
        if(x[i]>=s)c++;
        else break;
    }
 
    if(c>=m)cout<<"Yes\n";
    else cout<<"No\n";
 
    return 0;
}
 

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import heapq

def solve(N: int, M: int, A: "List[int]"):
    a = []
    for i in A:
        heapq.heappush(a, -i)

    for _ in range(M):
        m = heapq.heappop(a)
        heapq.heappush(a, -(-m // 2))

    sum = 0
    for i in a:
        sum += i
    print(-sum)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


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

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

#define LOG(variable) cerr << #variable":\t" << (variable) << "\n"
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cerr << (i) << ":\t" << (container)[(i)] << "\n"
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
signed main() {
  int d, t, s; cin >> d >> t >> s;
  int timetotake = d / s;
  if(d % s) {
    ++timetotake;
  }
  if(t >= timetotake) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] r = new int[4];
        for (;;) {
            int[] l = new int[] { sc.nextInt(), sc.nextInt(), sc.nextInt() };
            Arrays.sort(l);
            if (l[0] + l[1] <= l[2]) {
                r[0] = r[1] + r[2] + r[3];
                for (int i = 0; i < 4; i++) {
                    System.out.print(r[i] + (i == 3 ? "\n" : " "));
                }
                break;
            }
            int a = l[0] * l[0] + l[1] * l[1];
            int b = l[2] * l[2];
            if (a == b) {
                r[1]++;
            } else if (a > b) {
                r[2]++;
            } else {
                r[3]++;
            }
        }

    }
}


Measured memory_bytes: 26388
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int a, b;
	cin >> a >> b;

	cout << (a + b + 1) / 2 << endl;
}

Measured memory_bytes: 3504
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,m,k;
    cin>>n>>m>>k;
    vi a(n),b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    vi A(n+1),B(m+1);
    rep(i,n)A[i+1]=a[i]+A[i];
    rep(i,m)B[i+1]=b[i]+B[i];
    int ans=0;
    rep(i,n+1){
        if(A[i]>k)break;
        int j=--upper_bound(all(B),k-A[i])-B.begin();
        ans=max(ans,i+j);
    }
    cout<<ans<<endl;
}

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

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

    vector<vector<int64_t>> Arr;
    Arr.assign(N, vector<int64_t>(M + 1, 0));

    for (int n = 0; n < N; ++n)
        for (int m = 0; m <= M; ++m)
        {
            cin >> Arr[n][m];
        }

    int64_t value = INT64_MAX;
    for (int bit = 0; bit < (1 << N); ++bit)
    {
        vector<int64_t> sum(M + 1, 0);
        for (int n = 0; n < N; ++n)
        {
            if (bit & (1 << n))
            {
                for (int m = 0; m <= M; ++m)
                    sum[m] += Arr[n][m];
            }
        }
        bool judge = true;
        for (int m = 1; m <= M; ++m)
            if (sum[m] < X)
            {
                judge = false;
                break;
            }
        if (!judge)
            continue;

        value = min(value, sum[0]);
    }
    if (value == INT64_MAX)
        value = -1;

    cout << value << endl;
}

Measured memory_bytes: 3588
import fractions
def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)
a, b, c, d = map(int, input().split())
#aまで
count_c_a = (a-1) // c
count_d_a = (a-1) // d
count_cd_a = (a-1) // lcm(c, d)
#bまで
count_c_b = b // c
count_d_b = b // d
count_cd_b = b // lcm(c, d)

print(b-(a-1) - ((count_c_b+count_d_b-count_c_a-count_d_a) - (count_cd_b-count_cd_a)))

Measured memory_bytes: 63980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;

int main() {
    int a, b;
    cin >> a >> b;
    char c1 = a + '0', c2 = b + '0';
    string s1 = string(b, c1), s2 = string(a, c2);
    if (s1 >= s2)
        cout << s2 << endl;
    else
        cout << s1 << endl;
}

Measured memory_bytes: 256
#include "stdio.h"

int main(void)
{
  int N,N_=0;
  scanf ("%d",&N);
  int V[N];
  int C[N];
  int VC_sa,result=0;
  
  while(N_<N)
  {
    scanf ("%d",&V[N_]);
    N_++;
  }
  N_=0;
  while(N_<N)
  {
    scanf ("%d",&C[N_]);
    VC_sa=(V[N_]-C[N_]);
    if (VC_sa>0) result+=VC_sa;
    N_++;
  }
  N_=0;
  
  printf("%d",result);
  return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> H(N);
  map<int,int> peak;
  for(int i=0; i<N; i++){
    cin >> H.at(i);
    peak[i+1]= H.at(i);
  }
  vector<int> ans(N,1);
  for(int i=0;i<M;i++){
    int A,B;
    cin >> A >> B;
      if(peak.at(A)>=peak.at(B))
        ans.at(B-1)=0;
      if(peak.at(A)<=peak.at(B))
        ans.at(A-1)=0;
  }
  int ans_num=0;
  for(int i=0; i<N; i++){
    ans_num += ans.at(i);
  }
  cout << ans_num << endl;
}


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

ll N, M;
vector<ll> edges[200000];
deque<ll> q;
set<ll> s;

void f(ll cur) {
  for (auto ch : edges[cur])
    if (s.find(ch) == s.end()) {
      q.push_front(ch);
      s.insert(ch);
      f(ch);
      return;
    }
  return;
}

void b(ll cur) {
  for (auto ch : edges[cur])
    if (s.find(ch) == s.end()) {
      q.push_back(ch);
      s.insert(ch);
      b(ch);
      return;
    }
  return;
}

int main(void) {
  cin >> N >> M;
  rep(_, M) {
    ll a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  s.insert(1);
  q.push_back(1);
  f(1);
  b(1);
  cout << q.size() << endl;
  for (auto x : q) {
    cout << x << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 17024
#include <stdio.h>

void exchange(int *lottery, int x, int y);

int main(void)
{
	int w, n;
	int i;
	int x, y;
	int lottery[100];
	
	
	for (i = 1; i <= 100; i++){
		lottery[i - 1] = i;
	}
	scanf("%d", &w);
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d, %d", &x, &y);
		
		exchange(lottery, x, y);
	}
	
	for (i = 0; i < w; i++){
		printf("%d\n", lottery[i]);
	}
	
	return (0);
}

void exchange(int *lottery, int x, int y)
{
	int tmp;
	int i;
	
	tmp = lottery[x - 1];
	lottery[x - 1] = lottery[y - 1];
	lottery[y - 1] = tmp;
	
	
}

Measured memory_bytes: 596
# -*- coding: utf-8 -*-

def my_sort(word):
    sorted_word_list = sorted(word)
    sorted_word = ""
    for letter in sorted_word_list:
        sorted_word += letter
    return sorted_word

n = int(input())
words = {}
for i in range(n):
    word = my_sort(input())
    if word in words.keys():
        words[word] += 1
    else:
        words[word] = 1

for key in words.keys():
    words[key] = max(words[key]*(words[key]-1)//2, 0)

print(sum(words.values()))


Measured memory_bytes: 17808
#include<stdio.h>
int main(void)
{
	int n, h[100];
	int i = 1, j;

	scanf("%d\n", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &h[i]);
	}
	int count = 1;
	for (i = 1; i < n; i++)
	{
		int sum = 0;
		for (j = 0; j < i; j++)
		{
			if (h[j] > h[i])
			{
				sum++;
			}
		}
		if (sum == 0)
		{
			count++;
		}
	}
	printf("%d\n", count);
	return 0;

}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll K,N;
ll ans;
string S;
ll a,b,d;
ll A[1000001];
 
 ll gcd(ll a, ll b)
 {
    if (a%b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a%b));
    }
 }

 ll lcm(ll a, ll b)
 {
    return a * b / gcd(a, b);
 }
int main(){
    cin >> N>>K;
    for(int i=0;i<N;i++){
        if(i==0){
            cin >> a;
            a /= 2;
            ll aa = a;
            while(aa>=0){
                d++;
                if(aa%2==1){
                    break;
                }
                aa = aa/2;
            }
        }else{
            cin >> b;
            b /= 2;
            ll aa = b;
            ll k = 0;
            while(aa>=0){
                k++;
                if(aa%2==1){
                    break;
                }
                aa = aa/2;
            }
            if(k!=d){
                cout << 0 << endl;
                return 0;
            }
            ll c = lcm(a,b);
            if(c > K){
                cout << 0 << endl;
                return 0;
            }else{
                a = c;
            }
        }
        
    }
    cout << (K/a + 1)/2 << endl;
   
    
}


Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    inlis = []

    for i in range(m):
        p, y = map(int, input().split())
        inlis.append([i+1, p, y])

    inlis = sorted(inlis, key = lambda x:x[2])
    anslis = []
    tmpdic = dict()

    for i in range(m):
        j, p, y = inlis[i][0], inlis[i][1], inlis[i][2]
        
        if p not in tmpdic:
            tmpdic[p] = 1
        else:
            tmpdic[p] += 1
        
        num = str(tmpdic[p]).zfill(6)
        ken = str(p).zfill(6)

        ans = ken + num
        anslis.append([j,ans])
    
    anslis = sorted(anslis, key = lambda x:x[0])

    for [city, num] in anslis:
        print(num)


    



if __name__ == "__main__":
    main()


Measured memory_bytes: 120468
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;

void solve() {
	int n, m; cin >> n >> m;
	vector<int> A(m);
	vector<int> num = {0,2,5,5,4,5,6,3,7,6};
	for (int i = 0; i < m; ++i) {
		cin >> A[i];
	}
	string dp[100001];
	for (int i = 1; i <= n; ++i) {
		dp[i] = "!";
	}
	dp[0] = "";
	for (int i = 2; i <= n; ++i) {
		for (int a: A) {
			if (i - num[a] < 0 || dp[i - num[a]] == "!") continue;
			string d2 = dp[i - num[a]];
			d2.push_back('0' + a);
			if (d2.size() > dp[i].size() || d2.size() == dp[i].size() && d2 > dp[i]) {
				dp[i] = d2;
			}
		}
	}
	cout << dp[n] << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 42240
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}

struct edge{
    int to;
    int cost;
};
int E,V;
vector<edge>G[100005];
int d[100005];

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>>pq;
    fill(d,d+V,INF);
    d[s] = 0;
    pq.emplace(0,s);

    while(!pq.empty()){
        P p = pq.top();pq.pop();
        int v = p.second;
        if(d[v]<p.first)continue;

        rep(i,G[v].size()){
            edge e = G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to] = d[v]+e.cost;
                pq.emplace(d[e.to],e.to);
            }
        }
    }
}

int dp[105];
int main(){
    int s;
    cin>>V>>E>>s;
    rep(i,E){
        int a,b,c;cin>>a>>b>>c;
        edge e = {b,c};
        G[a].push_back(e);
    }
    dijkstra(s);
    rep(i,V){
        if(d[i]==INF)cout<<"INF"<<endl;
        else cout<<d[i]<<endl;
    }
}




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

int main() {
  int a, b, c, d, X;
  cin >> X;
  
  b = X;
  c = 100000000;
  for ( ;b != 0; ){
    a += b / c;
    b %= c;
    c /= 10;
  }
  
  
  if (X % a) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
// wake me up, wake me up inside. I cant wake up.
// save me , save me from the nothing ive become;

#include <bits/stdc++.h>

#define s second
#define f first
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define int int64_t

using namespace std;

const int MAX=4e5+20,INF=1e9+1,mod=1e9+7;

int n,m,d,ans,a[MAX],c,b,t[MAX],dis[MAX],sum,del,x,cnt,c2,mn2=INF,mx1=-MAX,mx2=-MAX,l,r,color,sum2,fn,mx=-1,mn=INF,k,y,z;
string s,str,sans;
//set <int> st;
//vector <pii> adj[MAX];
bool mark[MAX],mark2[MAX];
vector <int> adj[MAX];
vector<pii> v;
queue <int> q;
long double a1,a2;
map <int,int> mp;
pii p[MAX];

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

main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> k;
	for(int i=0;i<n;i++)
    {
        cin >> x >> y;
        p[x].f=x;
        p[x].s+=y;
        if(!mark[x])
        {
            mark[x]=1;
            cnt++;
        }
    }
    sort(p+1,p+MAX);
    for(int i=1;i<=MAX;i++)
    {
        if(sum+p[i].s>=k)
        {
            cout << p[i].f;
            return -0;
        }
        sum+=p[i].s;
    }
    return -0;
}



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

    int main() {
      int N; cin >> N;    // ひなあられの個数
      string T = "Three"; // "Three" or "Four"

      rep(i,N){
        string C;cin >> C; // ひなあられの色
        
        if ( C == "Y" ) {
          T = "Four";
          break;
        }
      }
      cout << T << endl;
    }

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int ans = 0;
int main()
{
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n)cin>>p[i];
	For(i,1,n-1){
		int a = p[i-1];
		int b = p[i];
		int c = p[i+1];
		int M = max({a,b,c});
		int m = min({a,b,c});
		if(b != M && b != m){
			ans ++;
		}

	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
def resolve():
    ans = 0
    count = 0
    N = int(input())
    for i in range(N):
        d, D = map(int, input().split())
        if d == D:
            ans += 1
        else:
            ans = 0
        if count < ans:
            count = ans
    print("Yes" if count  >= 3 else "No")
resolve()

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

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

using namespace std;

int main(void) {
    int A, B, C, D;

    cin >> A >> B >> C >> D;

    while (true) {
        C -= B;
        if (C <= 0) {
            break;
        }
        A -= D;
        if (A <= 0) {
            break;
        }
    }

    if (A > 0 && C <= 0) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int n; cin >> n;
	int S[10001];
	for (int i = 0; i < n; i++)cin >> S[i];
	int q; cin >> q;
	int T[501];
	for (int i = 0; i < q; i++)cin >> T[i];

	int cnt = 0;
	for (int i = 0; i < q; i++) {
		for (int j = 0; j < n; j++) {
			if (T[i] == S[j]) {
				//cout << T[i] << " " << S[j] << endl;
				cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1196
import numpy as np
N, x = map(int, input().split())
a = list(map(int, input().split()))
a = np.sort(np.array(a))
cumul = np.cumsum(a)
sign = np.sign(cumul - x)

if np.all(sign == -1):
    print(N - 1)
else:
    print(np.sum(sign <= 0))


Measured memory_bytes: 14408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;

int main() {
	int N;
	cin >> N;
	vector<string>S(N);
	vector<int>T(N);
	rep(i, N) {
		cin >> S[i] >> T[i];
	}
	int ans = 0;
	rep(i, N) {
		ans += T[i];
	}
	string X;
	cin >> X;
	int I = 0;
	rep(i, N) {
		if (S[i] == X) {
			I = i;
		}
	}
	rep(i, I+1) {
		ans -= T[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <utility>
#include <algorithm>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <numeric>
#include <list>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
using namespace std;

int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a * b) / 2 << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int H,W,i,j;
while(1){
   scanf("%d %d",&H,&W);
   if(H==0&&W==0)
   break;
 
for (i = 0; i < H ; i++ ){
    for ( j = 0; j < W; j++ ){
        printf("#");
    }
    printf("\n");
   }
  printf("\n");
 }
return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  auto isSosuu = [](int n) {
    if (n == 1) {
      return false;
    }
    for (int i = 2; i*i <= n; ++i) {
      if (n % i == 0) {
        return false;
      }
    }
    return true;
  };

  set<int> s{};
  for (int i = 1; i <= 100000; i += 2) {
    if (isSosuu(i) && isSosuu((i+1) / 2)) {
      s.emplace(i);
    }
  }
  int Q; cin >> Q;
  for (int _ = 0; _ < Q; ++_) {
    int l, r; cin >> l >> r;
    auto itrL = s.lower_bound(l);
    auto itrR = s.upper_bound(r);
    auto distance = std::distance(itrL, itrR);
    cout << distance << CRLF;
  }

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 640
def main():
    N = int(input())
    *A, = map(int, input().split())

    all_xor = 0
    for x in A:
        all_xor ^= x

    ans = (x ^ all_xor for x in A)

    print(*ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


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

// Disjoint Set
template<typename T>
class UnionFind {
 private:
  T _size;
  vector<T> _parent; // 親の番号（親自身はー（マイナス）集合要素の個数）

 public:
  // n要素で生成
  explicit UnionFind(T n) : _size{n}, _parent{vector<T>(n, -1)} {}

  // 木の根を求める
  T find(T x) {
    if (x < 0 || x >= _size) {
      return x;
    }

    if (_parent[x] < 0) {
      return x;
    }

    return _parent[x] = find(_parent[x]);
  }

  // xとyの属する集合を併合する
  bool unite(T x, T y) {
    if (x < 0 || x >= _size || y < 0 || y >= _size) {
      return false;
    }

    x = find(x);
    y = find(y);
    if (x == y) {
      return false;
    }

    if (size(x) > size(y)) {
      _parent[x] += _parent[y];
      _parent[y] = x;
    } else {
      _parent[y] += _parent[x];
      _parent[x] = y;
    }

    return true;
  }

  // xとyが同じ集合に属するか
  bool same(T x, T y) {
    return find(x) == find(y);
  }

  // xの属する集合の個数を求める
  T size(T x) {
    if (x < 0 || x >= _size) {
      return 1;
    }

    return -_parent[find(x)];
  }

  // 全体の個数を求める
  T size() {
    return _size;
  }
};

static const long MAX_N = 1e5;
static const long MAX_M = 1e5;
long A[MAX_M], B[MAX_M];
long dp[MAX_M+1];

int main() {
  long N, M;
  cin >> N >> M;
  for (long i = 0; i < M; ++i) {
    cin >> A[i] >> B[i];
    --A[i];
    --B[i];
  }

  UnionFind<long> uni(N);

  dp[M-1] = N * (N - 1) / 2;
  for (long i = M - 1; i > 0; --i) {
    dp[i-1] = dp[i];
    if (!uni.same(A[i], B[i])) {
      dp[i-1] -= uni.size(A[i]) * uni.size(B[i]);
      uni.unite(A[i], B[i]);
    }
  }

  for (int i = 0; i < M; ++i) {
    cout << dp[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4480
s = input()[::-1]
len_s = len(s)

a = 'dream'[::-1]
b = 'dreamer'[::-1]
c = 'erase'[::-1]
d = 'eraser'[::-1]

idx = 1
for _ in range(len_s):
    if s[:idx] in [a, b, c, d]:
        s = s[idx:]
        idx = 0
    idx += 1
if s[:idx] in [a, b, c, d]:
    s = []

if len(s) == 0:
    print('YES')
else:
    print('NO')


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

int main(){
    int N;
    cin >> N;
    string list[3] = {"hon", "pon", "bon"};
    int n = N % 10;
    if (n == 2 || n == 4 || n == 5 || n == 7|| n==9 )
    {
        cout << list[0] << endl;
    } else if ( n == 0 || n == 1 || n == 6 || n == 8){
        cout << list[1] << endl;
    } else
    {
        cout << list[2] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.Scanner;



public class Main {
    public static void main(String[] args)throws Exception{
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int max = 0;
        int min = 0;
        int i = 0;
        int x = 0;
        long sum = 0;
        while(i <= n - 1){
            /*maxとminの処理*/
            if(i == 0){
                x = scan.nextInt();
                max = x;
                min = x;
            }else{
                x = scan.nextInt();
                if(x > max){
                    max = x;
                }else if(x < min){
                    min = x;
                }
            }
            /*sumの処理*/
            sum += x;
            /*出力*/
            
            i++;
        }
        System.out.println(min + " " + max + " " + sum);
    }
}



Measured memory_bytes: 43052
#include<stdio.h>
#define INF 2000000001

int t[250],n;

void parent(int x){
  if(x!=0){
    printf("parent key = %d, ",t[(x-1)/2]);
  }
}

void left(int x){
  int y=x*2+1;
  if(y<250&&t[y]!=INF){
    printf("left key = %d, ",t[y]);
  }
}

void right(int x){
  int y=x*2+2;
  if(y<250&&t[y]!=INF){
    printf("right key = %d, ",t[y]);
  }
}

int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&t[i]);
  for(i=n;i<250;i++)t[i]=INF;

  for(i=0;i<n;i++){
    printf("node %d: key = %d, ",i+1,t[i]);
    parent(i);
    left(i);
    right(i);
    printf("\n");
  }
  return 0;
}

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

int main(){
    string s; cin>>s;

    for(int i=0;i<(1<<3);i++){
        int cnt=s[0]-'0';
        string ans;
        ans+=s[0];
        for(int j=0;j<3;j++){
            if(i&(1<<j)){
                cnt-=s[j+1]-'0';
                ans+='-';
                ans+=s[j+1];
            }else{
                cnt+=s[j+1]-'0';
                ans+='+';
                ans+=s[j+1];
            }
        }
        if(cnt==7){
            ans+="=7";
            cout<<ans<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static FastReader in = new FastReader();

	public static void main(String[] args) {
		solve();
	}

	static void solve() {
		int n = in.nextInt();
		int[][] arr = new int[n][3];
		for(int i = 0; i < n; i++) arr[i] = in.readarr(3);
		
		int[][] dp = new int[n][3];
		dp[0][0] = arr[0][0];
		dp[0][1] = arr[0][1];
		dp[0][2] = arr[0][2];
		
		for(int i = 1; i < n; i++)
		{
			dp[i][0] = arr[i][0] + Math.max(dp[i - 1][1], dp[i - 1][2]);
			dp[i][1] = arr[i][1] + Math.max(dp[i - 1][0], dp[i - 1][2]);
			dp[i][2] = arr[i][2] + Math.max(dp[i - 1][0], dp[i - 1][1]);
		}
				
		System.out.println(Math.max(dp[n - 1][0], Math.max(dp[n - 1][1], dp[n - 1][2])));
		
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readarr(int abc) {
			int[] temp = new int[abc];
			for (int i = 0; i < abc; i++)
				temp[i] = nextInt();
			return temp;
		}
	}
}


Measured memory_bytes: 52564