akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{

    static long gcd(long a,long b){
        if(b==0)return a;
        return gcd(b,a%b);
    }

    static long lcm(long a,long b){
        return a/gcd(a,b)*b;
    }
    public static void main(String[] srgs){
        Scanner sc=new Scanner(System.in);

        int n=sc.nextInt();
        long[] c=new long[70];
        for(int i=0;i<n;i++){
            long a=sc.nextLong();
            int t=0;
            while(a>0){
                c[t]+=a%2;
                a/=2;
                t+=1;
            }
        }
        long out=0,MOD=1000000007,t=1;
        for(int i=0;i<70;i++){
            out+=c[i]*(n-c[i])%MOD*t%MOD;
            out%=MOD;
            t=t*2%MOD;
        }
        System.out.println(out);
    }
}


Measured memory_bytes: 90720
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
#define INF	100000000
#define pb	push_back
#define fi first
#define sec second
#define SS stringstream
using namespace std;
typedef pair<int, int> P;
typedef long long int	ll;

int w, n;
int t = 0;
int dp[1001][1001];
vector<P> vec;

int rec(int i, int j){
	if(dp[i][j] >= 0) return dp[i][j];
	int res;
	if(i == n) res = 0;
	else if(j < vec[i].sec) res = rec(i+1, j);
	else res = max(rec(i+1, j), rec(i+1, j-vec[i].sec)+vec[i].fi);
	return dp[i][j] = res;
}

int main(){
	while(scanf("%d", &w)){
		t++;
		if(w == 0) break;
		memset(dp, -1, sizeof(dp));
		scanf("%d", &n);
		for(int i = 0; i < n; i++){
			int temp1, temp2;
			char trash;
			scanf("%d%c%d", &temp1, &trash, &temp2);
			vec.pb(P(temp1, temp2));
		}
		printf("Case %d:\n", t);
		printf("%d\n", rec(0, w));
		for(int i = 1; i <= w; i++){
			if(rec(0, w-i) != rec(0,w)){
				printf("%d\n", w-i+1);
				break;
			}
		}
		vec.clear();
	}
}

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

struct node{
	unsigned int k;
	struct node *next, *prev;	
};

typedef struct node * NodePointer;
NodePointer nil;

NodePointer search(int key){
	NodePointer a,b;
	
	b = nil;
	a = b->next;
	
	while(a!=nil){
		if(a->k == key)
			return b;
		b = a;
		a = b->next;
	}
	return NULL;
}

void init(){
	nil = malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
	nil->k = -1;
}

void printList(){
	NodePointer cur = nil->next;
	int isf = 1;
	while(1){
		if ( cur == nil ) break;
		if ( isf == 0) printf(" ");
		printf("%d", cur->k);
		cur = cur->next;
		isf = 0;
	}
	printf("\n");
}

void deleteNode(NodePointer t){
/* your code */
}

void deleteFirst(){
	NodePointer a,b;
	
	a = nil->next;
	b = a->next;
	b->prev = nil;
	nil->next = b;
	
	free(a);
}

void deleteLast(){
	NodePointer a,b;
	
	a = nil->prev;
	b = a->prev;
	b->next = nil;
	nil->prev = b;
	
	free(a);
}

void delete(int key){
	NodePointer a,b,c;
	
	if(nil->next->k == key){
		deleteFirst();
		return;
	}
	
	a = search(key);
	if(a == NULL){
		return;
	}
	
	c = a->next;
	b = a->next->next;
	a->next = b;
	b->prev = a;
	
	free(c);
}

void insert(int key){
	NodePointer a,b;
	a = malloc(sizeof(struct node));
	a->k = key;
	b = nil->next;
	nil->next = a;
	a->prev = nil;
	a->next = b;
	b->prev = a;
	
}

int main(){
	int key, n, i, size, np, nd;
	size = np = nd = 0;
	char inst[20];
	
	scanf("%d", &n);
	init();
	for ( i = 0; i < n; i++ ){
		scanf("%s%d", inst, &key);
		if ( inst[0] == 'i' ) {insert(key); np++; size++;}
		else if ( inst[0] == 'd' ) {
			if (strlen(inst) > 6){
				if ( inst[6] == 'F' ) deleteFirst();
			else if ( inst[6] == 'L' ) deleteLast();
		} else 
			delete(key); nd++;
		size--;
		}
	}
	printList();
		
	return 0;
}


Measured memory_bytes: 32996
#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;

int main() {
	string s;
	cin >> s;
	deque<char> dq;
	for(char c : s)
		dq.push_back(c);
	bool st = 0;
	int q;
	cin >> q;
	while(q--) {
		int x;
		cin >> x;
		if(x == 1)
			st ^= 1;
		else {
			int y;
			cin >> y;
			char c;
			cin >> c;
			if(y == 1) {
				if(st)
					dq.push_back(c);
				else
					dq.push_front(c);
			}
			else {
				if(st)
					dq.push_front(c);
				else
					dq.push_back(c);
			}
		}
	}
	string ans;
	for(char c : dq)
		ans += c;
	if(st)
		reverse(ans.begin(), ans.end());
	cout << ans;
}


Measured memory_bytes: 4224
#from enum import Enum
#from queue import Queue
#import collections

#import sys
#import math

BIG_NUM = 2000000000
#MOD = 1000000007
#EPS = 0.000000001


count = 0
def merge(A, left, mid, right):
    global count
#    n1 = mid - left
#    n2 = right - mid
#    L = list(range(n1+1))
#    R = list(range(n2+1))
#    for i in range(n1):
#        L[i] = A[left + i]
#    for i in range(n2):
#        R[i] = A[mid + i]
#    L[n1] = BIG_NUM
#    R[n2] = BIG_NUM
    L = A[left:mid] + [BIG_NUM]
    R = A[mid:right] + [BIG_NUM]
    i = 0
    j = 0
    for k in range(left,right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

n = int(input())
S = list(map(int,input().split()))

mergeSort(S,0,n)
#for i in range(n-1):
#    print("%d"%(S[i]),end=" ")
#print("%d"%(S[n-1]))
print(*S)
print(count)



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

int main(){
  map<int,int> mymap;
  int n, q, x, sum=0;
  cin >> n;
  while(n--){
    cin >> x;
    mymap[x] = 1;
  }

  cin >> q;
  while(q--){
    cin >> x;
    if(mymap.find(x) != mymap.end())
      sum++;
  }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
    #define F first
    #define S second
    using ll = long long;
    const ll mod = 1000000007;
    const ll infi = 1000000000000000;
    const ll md = 998244353;
    using namespace std;
    using vl = vector<ll>;
    using pll =  pair<ll,ll>;
     
    int main() {
        int a;
        string s;
        cin>>a>>s;
        if(a<3200) cout<<"red";
        else cout<<s;
        return 0;
    } 

Measured memory_bytes: 256
import itertools
import math
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
d = [[0 for _ in range(N)] for _ in range(N)]
# for i in range(N - 1):
#     dx = xy[i+1][0] - xy[i][0]
#     dy = xy[i+1][1] - xy[i][1]
#     d.append(math.sqrt(dx ** 2 + dy ** 2))

a = [i for i in range(N)]
b = list(itertools.permutations(a))

e = []
for i in range(len(b)):
    c = 0
    for j in range(len(b[i]) - 1):
        row = b[i][j]
        column = b[i][j+1]
        if d[row][column] != 0:
            c += d[row][column]
            continue
        dx = xy[row][0] - xy[column][0]
        dy = xy[row][1] - xy[column][1]
        d[row][column] = math.sqrt(dx ** 2 + dy ** 2)
        c += d[row][column]
    e.append(c)
ans = sum(e)/len(e)
print(ans)

Measured memory_bytes: 9252
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
import time
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
#    n = 500
    cos = [min(i//n,n-1-i//n,i%n,n-1-i%n) for i in range(n**2)]
#    p = [i for i in range(n**2)]
    p = [int(i)-1 for i in ipt().split()]
    ans = 0
    q = []
    dr = [-1,-n,1,n]
    al = [False]*(n**2)

    for pi in p:
        ans += cos[pi]
        q.append((cos[pi],pi))
        al[pi] = True
        while q:
            qc,qi = q.pop()
            ad = qc if al[qi] else qc+1
            for d in dr:
                if 0 <= d+qi < n**2 and cos[d+qi] > ad:
                    q.append((ad,d+qi))
                    cos[d+qi] = ad
    print(ans)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 225900
#include <iostream>
using namespace std;
int main(){
    int k, a, b;
    cin >> k >> a >> b;
    if((a%k == 0) || (b%k == 0)){
        cout << "OK";
    }else if((a/k+1)*k <= b){
        cout << "OK";
    }else{
        cout << "NG";
    }

    return 0;
}

Measured memory_bytes: 3636
let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let () =
  let l = read_line () in
  match List.map int_of_string (split l ' ') with
  | [] | [_] -> exit 1
  | r :: c :: _ ->
      let ary = Array.make_matrix (r + 1) (c + 1) 0 in
      for i = 1 to r do
        let l = read_line () in
        let row = Array.of_list (List.map int_of_string (split l ' ')) in
        for j = 1 to c do
          ary.(i - 1).(j - 1) <- row.(j - 1);
          ary.(i - 1).(c) <- ary.(i - 1).(c) + row.(j - 1);
        done;
      done;
      for i = 1 to c do
        for j = 1 to r do
          ary.(r).(i - 1) <- ary.(r).(i - 1) + ary.(j - 1).(i - 1);
        done;
        ary.(r).(c) <- ary.(r).(c) + ary.(r).(i - 1);
      done;
      for i = 0 to r do
        for j = 0 to c do
          if j = 0 then Printf.printf "%d" ary.(i).(j)
          else if j = c then Printf.printf " %d\n" ary.(i).(j)
          else Printf.printf " %d" ary.(i).(j)
        done;
      done

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

int r, l, H, A[500001];

void MaxHeapfy(int i){
  int lagest;
  l = i * 2;
  r = i * 2 + 1;
  lagest = i;
  if(l <= H && A[l] > A[lagest]) lagest = l;
  if(r <= H && A[r] > A[lagest]) lagest = r;

  if( lagest != i) {
    swap(A[lagest], A[i]);
    MaxHeapfy(lagest);
  }
}

void BuildMaxHeap(){
  for(int i = H/2; i > 0; i--){
    MaxHeapfy(i);
  }
}

int main(){
  cin >> H;
  rep(i,H){
    cin >> A[i + 1];
  }
  BuildMaxHeap();
  rep(i,H){
    cout << " " << A[i + 1];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 4968
N=int(input())
A1=[int(s) for s in input().split()]
B1=[int(s) for s in input().split()]
A2=[(A1[i],i) for i in range(N)]
B2=[(B1[i],i) for i in range(N)]
A=sorted(A2)
B=sorted(B2)
#print(A)
#print(B)
for i in range(N):
  if B[i][0]<A[i][0]:
    print("No")
    break
else:
  for i in range(N-1):
    if B[i][0]>=A[i+1][0]:
      print("Yes")
      break
  else:
    C=[(A[i][1],B[i][1]) for i in range(N)]
    C.sort()
#    print(C)
    k=0
    for i in range(N-1):
      k=C[k][1]
      if k==0:
        print("Yes")
        break
    else:
      print("No")
        


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

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

int check(int);
char output(int, int, int, int);

int main()
{
	int m, f, r;
	int ans;
	vector<char> out;

	cin >> m >> f >> r;
	while(m+f+r != -3)
	{
		ans = check(m) + check(f);
		out.push_back(output(ans, m, f, r));
		cin >> m >> f >> r;
	}

	rep(i,out.size())
	{
		cout << out[i] << endl;
	}
}

int check(int n)
{
	int ret;
	if(n < 0) ret = 0;
	else ret = n;
	return ret;
}

char output(int ans, int m, int f, int r)
{
	char out;
	if(m == -1 || f == -1) out = 'F';
	else if(ans >= 80) out = 'A';
	else if(ans >= 65) out = 'B';
	else if(ans >= 50) out = 'C';
	else if(r >= 50) out = 'C';
	else if(ans >= 30) out = 'D';
	else out = 'F';

	return out;
}


Measured memory_bytes: 3108
#include <iostream>

using namespace std;

int main() {
		int N;
		cin >> N;
		int x[N], y[N], h[N];
		for (int i = 0; i < N; i++) cin >> x[i] >> y[i] >> h[i];

		for (int posY = 0; posY <= 100; posY++) {
				for (int posX = 0; posX <= 100; posX++) {

						int needH = 0;

						for (int i = 0; i < N; i++) {
								if (h[i] > 0) {
										int t = h[i] + abs(x[i] - posX) + abs(y[i] - posY);
										if (needH == 0) {
												needH = t;
										} else if (needH != t) {
												needH = -1;
												break;
										}
								}
						}

						if (needH == -1) continue;

						for (int i = 0; i < N; i++) {
								if (h[i] == 0) {
										int dist = abs(x[i] - posX) + abs(y[i] - posY);
										// 0 + abs(x[i]-posX) + abx(y[i]-posY) >= needH
										if (needH > dist) {
												needH = -1;
												break;
										}
								}
						}

						if (needH == -1) continue;

						cout << posX << " " << posY << " " << needH << endl;
				}
		}
		return 0;
}


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

int main(){
   int N;
   cin >> N;
   for(int i = 0;i < N;i++){
       string S,T;
       cin >> S >> T;
       int n = S.size(),m = T.size();
       int dp[1010][1010];
       for(int i = 0;i < n;i++){
           for(int j = 0;j < m;j++){
               if(S[i] == T[j]){
                   dp[i+1][j+1] = dp[i][j]+1;
               }else{
                   dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
               }
           }
        }
    cout << dp[n][m] << endl;
   }
}


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

int main(){
  int h, w;
  while(1){
    cin >> h >> w;
    if(h == 0 && w == 0) break;
    else{
      for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
          if(i == 0 || i == h-1) cout << "#";
          else if(j == 0 || j == w-1) cout << "#";
          else cout << ".";
        }
        cout << "\n";
      }
      cout << "\n";
    }
  }
  return 0;
}



Measured memory_bytes: 3004
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
    ll t=1;
//    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll ans=0;
        for(ll i=1;i<n;i++)
        {
            ll temp=(n/i);
            if(n%i==0)
                temp--;
            ans+=temp;
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

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

inline void fastio () {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
}

#define whats(x) cerr << #x << " = " << (x) << "\n"; 

using LL = long long;
using LD = long double;

const LL INF = LLONG_MAX;
const LL MOD = 998244353;
const LL N = 2e5+1;

int main() {
	fastio();

	LL a, b;
	cin >> a >> b;
	cout << a*b << "\n";
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
void File()
{
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
}
void yAsEr_HaFiz() {
    //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);

 ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 }



typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pair<int,int> > vii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<long, long> mll;
typedef set<int> si;
typedef set<string> st;
typedef set<long> sl;
typedef pair<int, int> pii;
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define rlp(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rng(i,a,b) for(int i = int(a);i <= int(b);i++)
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define setzero(a)	memset(a,0,sizeof(a))
#define bits(a) 	__builtin_popcountll(a)
#define fr first
#define sc second
#define el      	 "\n"
#define pii pair<int, int>
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define ndl puts("")
#define SS stringstream
#define ll long long
#define endl '\n'
#define clr(x, y) memset(x, y, sizeof(x))
#define foreach(it,x) for(__typeof__((x).begin()) it = (x).begin(); it != (x).end(); ++it)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };




int const N = 5e5 + 9, MOD = 1e9+7 , oo = 1e9+7;
//------------------------------------------------------------------------------------






ll target,lo,hi;



bool ok(ll n){

ll s=0;
s+=(n/2)*6+(n/2)*5;
if (n%2)s+=6;
if (s>=target)return 1;
else return 0;
}
int main()
{
    yAsEr_HaFiz();

    cin>>target;
    lo =1,hi=1e15;
    while(lo<hi){
        ll med=(lo+hi)>>1;
        if (ok(med))hi=med;
        else lo=med+1;
    }

    cout<<lo;

















    /*
    */
return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector <int> vec(n);
  for(int i=0; i<n; i++){
    cin >> vec.at(i);
  }
  if(n==1){
    cout << "Yes" << endl;
    return 0;
  }
  bool ans = true;
  int count = 0;
  for(int i=0; i<n; i++){
    count = max(count, vec.at(i));
    if(count - vec.at(i) >= 2){
      ans = false;
      break;
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
int main() {
  string S; cin >> S;
  int count = 0;
  char crntC = S[0];
  rep(i, (int)S.size()){
    if(S[i] == crntC) continue;
    else {crntC = S[i]; count++;}
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3716
#include<stdio.h>

int main(void){
    int n,x,i,m,s;
    int count=0;
    
    while(1){
    scanf("%d%d",&n,&x);
    
    if (n == 0 && x == 0)break;

			for (i = 1; i<n - 1; i++) {
				for (m = i + 1; m<n; m++) {
					s = x - i - m;
					if (s <=n && s!=i &&s !=m&&s>m) {
						count++;
					}
				}
			}
			printf("%d\n", count);
			count=0;
		}
		


    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int mod = A % B;
  int count = A / B;
  if (mod == 0) {
    cout << count << endl;
  } else {
    cout << count + 1 << endl;
  }
}


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

int main() {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if (a == 0) cout << 1 << endl;
    else if (b == 0) cout << 2 << endl;
    else if (c == 0) cout << 3 << endl;
    else if (d == 0) cout << 4 << endl;
    else cout << 5 << endl;
    return 0;
}

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

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

  int d, n;
  cin >> d >> n;

  if (n == 100) n = 101;
  cout << (int)pow(100, d) * n << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] $){
		//入力
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) a[i] = sc.nextInt();
		sc.close();

		//処理
		int ans = 0;
		boolean[] dup = new boolean[100001];
		for(int i = 0; i < 100001; i++) dup[i] = false;
		for(int i = 0; i < n; i++){
			if(dup[a[i]]) ans++;
			else dup[a[i]] = true;
		}

		//出力
		System.out.println(n - 2*((ans+1)/2));
	}
}


Measured memory_bytes: 50684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.nextLine());

		String X, Y;

		for (int i = 0; i < n; i++) {
			X = sc.nextLine();
			Y = sc.nextLine();

			System.out.println(getLcs(X, Y));
		}

		sc.close();
	}

	private static int getLcs(String X, String Y) {
		int m = X.length();
		int n = Y.length();

		char[] x = X.toCharArray();
		char[] y = Y.toCharArray();

		int[][] dp = new int[m + 1][n + 1];

		int max = 0;

		for (int i = 0; i < m + 1; i++) {
			dp[i][0] = 0;
		}

		for (int j = 1; j < n + 1; j++) {
			dp[0][j] = 0;
		}

		for (int i = 1; i < m + 1; i++) {
			for (int j = 1; j < n + 1; j++) {
				if (x[i -1] == y[j -1]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
				} else {
					dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
				}
				max = Math.max(max, dp[i][j]);
			}
		}

		return max;

	}

}



Measured memory_bytes: 63876
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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

ll n,m;

int main(){
    
    cin >> n >> m ;
  
  
    rep(y,0,n+1){
        rep(i,0,n+1-y){
            int h = n - (y + i);
           // PS(y);PS(i);PS(h);P(y*10000+i*5000+h*1000);
            
            if((ll)y*10000+(ll)i*5000+(ll)h*1000 == m){
                PS(y);PS(i);P(h);
                ret 0;
            }
        }
    }
    P("-1 -1 -1");
    return  0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  vector<int> cnt(1);
  ll ans = 0;
  ll N;
  cin >> N;
  if(N == 1){
    cout << "0" << endl;
    return 0;
  }
  ll a = 2;
  ll pre = 2;
  ll id = 0;
  vector<ll> key(1,2);
  while(N >= a * a){
    if(N % a == 0){
      if(pre == a){
        cnt.at(id)++;
      }else{
        cnt.push_back(1);
        id++;
        key.push_back(a);
      }
      N /= a;
      pre = a;
    }else{
      a++;
    }
  }
  rep(i,id +1){
    if(key.at(i) == N){
      cnt.at(i)++;
      break;
    }
    if(i == id){
      if(key.at(i) != N && N > 1){
        cnt.push_back(1);
      }
    }
  }
  rep(i,SZ(cnt)){
    if(cnt.at(i) == 0)continue;
    rep(j,40){
      cnt.at(i) -= j + 1;
      if(cnt.at(i) >= 0){
        ans++;
      }else{
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
double p[maxn];
double dp[3050][3050];
int n;
int main()
{
    gg(n);
    repd(i,1,n)
    {
        scanf("%lf",&p[i]);
    }
    dp[1][1]=p[1];
    dp[1][0]=1.0000000-p[1];

    repd(i,2,n)
    {
        for(int j=0;j<=i;j++)
        {
            if(j==0)
            {
                dp[i][j]=dp[i-1][j]*(1.00000-p[i]);
                continue;
            }
            dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1.0000-p[i]);
//            dp[i][j-1]=dp[i-1][j-1]*(1.000000-p[i]);
        }
    }
    double ans=0.0000000000000000000;
    for(int i=(n+1)/2;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    printf("%.10lf\n", ans);
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 72448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int r,g,b,n,ans = 0;
    cin >> r >> g >> b >> n;
    rep(i, n / r + 1){
        rep(j, n / g + 1){
            if ((n - (r * i + g * j)) % b == 0 && r * i + g * j <= n) {
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int prime[300001];
int main(){
	prime[0]=prime[1]=-1;
	for(int i=6;i<300001;i++){
		if(i%7==1||i%7==6){
			if(!prime[i]){
				prime[i]=1;
				for(int j=6*i;j<300001;j+=i){
					if((j/i)%7==1||(j/i)%7==6)prime[j]=-1;
				}
			}
		}
	}
	int a;
	while(scanf("%d",&a),a-1){
		printf("%d:",a);
		for(int i=1;i<300001;i++){
			if(a%i==0&&prime[i]==1)printf(" %d",i);
		}
		printf("\n");
	}
}

Measured memory_bytes: 2200
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

bool ck(int x){
    bool res=true;
    if(x/10000!=x%10) res=false;
    x%=10000; x-=x%10;
    if(x/1000!=(x%100)/10) res=false;
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b;
    cin>>a>>b;
    
    int cnt=0;
    for(int i=a;i<=b;i++){
        if(ck(i)) cnt++;
    }
    cout1(cnt)
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int>> ab(n,vector<int>(2));
  for(int i=0;i<n;i++)
    cin>>ab.at(i).at(0)>>ab.at(i).at(1);
  sort(ab.begin(),ab.end());
  int64_t s=0;
  int p=0;
  for(int i=0;i<m;i++){
    s+=ab.at(p).at(0);
    ab.at(p).at(1)--;
    if(ab.at(p).at(1)==0)
      p++;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

 	vector<lli> d(n);
 	REP(i,0,n)cin>>d[i];

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

 	lli minAns = d[n/2-1];
 	lli maxAns = d[n/2];

 	cout<<maxAns-minAns<<endl;

	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n;
    cin >> n;
    vector<long double> arr(n);
    F0R(i,n)
        cin >> arr[i];
    sort(arr.begin(),arr.end());
    long double val=arr[0]/2+arr[1]/2;
    // cout << val << endl;
    FOR(i,2,n)
        val=val/2+arr[i]/2;
    cout << val;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <utility>

#define int long long
#define dotimes(i, n) for (int i : range(n))

using namespace std;

class range {
  class iterator {
    int i, s;
  public:
    iterator(int i, int s): i(i), s(s) {}
    int& operator*() {
      return i;
    }
    void operator++() {
      i += s;
    }
    bool operator!=(iterator const& that) {
      return i < that.i;
    }
  };
  iterator b, e;
public:
  range(int e): b({0, 1}), e({e, 1}) {}
  range(int b, int e): b({b, 1}), e({e, 1}) {}
  range(int b, int e, int s): b({b, s}), e({e, s}) {}
  iterator begin() {
    return b;
  }
  iterator end() {
    return e;
  }
};

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

template<typename T>
inline int size(T container) {
  return static_cast<int>(container.size());
}

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

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

signed main() {
  int N = rint();
  int W = rint();
  int dp[W+1] = {};
  dotimes(i, N) {
    int v = rint();
    int w = rint();
    for (int j = W; j >= w; j--)
      maxs(dp[j], dp[j-w] + v);
  }
  wint(dp[W]);
  return 0;
}



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

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n, m;
    cin >> n >> m;
    vector<i64> hs(n);
    for (auto& h : hs) cin >> h;
    vector<i64> is(n);
    iota(begin(is), end(is), 0);
    sort(begin(is), end(is), [&](i64 i, i64 j) { return hs[i] > hs[j]; });

    vector<vector<i64>> p(n);
    for (i64 i = 0; i < m; i++) {
        i64 a, b;
        cin >> a >> b, a--, b--;
        p[a].emplace_back(b);
        p[b].emplace_back(a);
    }

    i64 ans = 0;
    vector<i64> g(n);
    for (auto& i : is) {
        if (g[i]) continue;
        g[i] = 1;
        for (auto& j : p[i]) g[j] = 1;
        ans += all_of(begin(p[i]), end(p[i]), [&](i64 j) { return hs[i] > hs[j]; });
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 1010, M = 1000010;

int n, m;
int g[N][N];
int h[M], e[M], ne[M], idx;
int q[M], f[M], d[M];

void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}

int top_sort(int st)
{
	int hh = 0, tt = -1;
	q[ ++ tt] = st;
	
	while (hh <= tt)
	{
		int t = q[hh ++ ];
		for (int i = h[t]; ~i; i = ne[i])
		{
			int j = e[i];
			
			if ( -- d[j] == 0)
			{
				f[j] = f[t] + 1;
				q[ ++ tt] = j;
			}
		}
	}
	
	int res = 0;
	for (int i = 1; i <= m; i ++ )
		if (!f[i]) return -1;
		else res = max(res, f[i]);
	return res;
}

int main()
{
	memset(h, -1, sizeof h);
	
	cin >> n;

	for (int i = 1; i <= n; i ++ )
		for (int j = i + 1; j <= n; j ++ )
			g[i][j] = g[j][i] = ++ m;
			
	for (int i = 1; i <= n; i ++ )
		for (int j = 0, a = m + 1; j < n - 1; j ++ )
		{
			int t;
			scanf("%d", &t);
			
			int b = g[i][t];
			d[b] ++ ;
			add(a, b);
			a = b;
		}
	
	cout << top_sort(m + 1) << endl;
	return 0;
}

Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define debug(x_) cerr << #x_ << ":" << x_ << endl;
#define debug2(x__) for(auto a__ : x__) cerr << a__ << " "; cerr << endl;
#define debug3(x___ , sx___) rep(i, sx___) cerr << x___[i] << " "; cerr << endl;

vector<pii> around = {MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1)};

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    return b ? gcd(b, a % b) : a;
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int x[n + 1], y[m + 1];
    cin >> x[n] >> y[m];
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    sort(x, x + n + 1);
    sort(y, y + m + 1);
    cout << (x[n] < y[0] ? "No War" : "War") << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	
	while (scanf("%d", &n) != EOF){
		while (n > 0){
			n -= 39;
		}
		n += 39;
		if (n <= 9){
			printf("3C0%d\n", n);
		}
		else {
			printf("3C%d\n", n);
		}
	}
	
	return (0);
}

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

public class Main {
    
    

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		long n = stdIn.nextLong();
		String nishin = Long.toBinaryString(n);
		char c[] = nishin.toCharArray();
		int start = 32 - nishin.length();
		for(int i = 0; i < 32; i++){
		    if(i < start){
		        System.out.print(0);
		    }else{
		        if(c[i - start] == '1'){
		            System.out.print(1);
		        }else{
		            System.out.print(0);
		        }
		    }
		}
		
		System.out.println();
		
		for(int i = 0; i < 32; i++){
		    if(i < start){
		        System.out.print(1);
		    }else{
		        if(c[i - start] == '1'){
		            System.out.print(0);
		        }else{
		            System.out.print(1);
		        }
		    }
		}
		
		System.out.println();
		
		for(int i = 1; i < 32; i++){
		    if(i < start){
		        System.out.print(0);
		    }else{
		        if(c[i - start] == '1'){
		            System.out.print(1);
		        }else{
		            System.out.print(0);
		        }
		    }
		}
		
		System.out.print(0);
		
		System.out.println();
		
		System.out.print(0);
		
		for(int i = 0; i < 31; i++){
		    if(i < start){
		        System.out.print(0);
		    }else{
		        if(c[i - start] == '1'){
		            System.out.print(1);
		        }else{
		            System.out.print(0);
		        }
		    }
		}
		
		System.out.println();
		
		
		
        
		stdIn.close();
	}

}





Measured memory_bytes: 26424
#include <bits/stdc++.h>
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)5e3 + 100;
const int mod = (int)1e9 + 7;
const int P = (int) 1e6 + 7; 
const double pi = acos(-1.0);
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;                        


int n, sum, x;
bitset<2000 * 2000 + 100> dp;
void solve(){
	scanf("%d", &n);
	dp[0] = 1;
	forn(i, 1, n){
		scanf("%d", &x);
		dp |= (dp << x);
		sum += x;
	}
	forn(i, (sum + 1) / 2, sum)
		if(dp[i]){
			printf("%d", i);
			return;
		}
}
int main () {
	int t = 1;
	while(t--)
		solve(); 
}

Measured memory_bytes: 1792
import math
import bisect
def era(n):
    data=[i for i in range(2,n+1)]
    for d in data:
        data=[x for x in data if(x==d or x%d != 0)]
    return data
    
def prime(n):
    max=int(math.sqrt(n))
    li=[i for i in range(2,n+1)]
    primes=[]
    while li[0]<=max:
        primes.append(li[0])
        tmp=li[0]
        li=[i for i in li if i%tmp!=0]
    primes.extend(li)
    return primes

Q=int(input())
l=[]
r=[]
up=0
for i in range(Q):
    a,b=map(int,input().split())
    up=max([up,a,b])
    
    l.append(a)
    r.append(b)
s=prime(up)
like=[]

for i in range(len(s)):#O(10000*log(10000))
    if((s[i]+1)/2==s[bisect.bisect_left(s,(s[i]+1)/2)]):
        like.append(s[i])
        
sumli=[0]*100001
tmp=0
for i in range(2,100001):#O(100000)
    if(i==like[tmp]):
        sumli[i]=sumli[i-1]+1
        if(tmp<(len(like)-1)):
            tmp+=1
    else:
        sumli[i]=sumli[i-1]

for i in range(Q):
    print(sumli[r[i]]-sumli[l[i]-1])

Measured memory_bytes: 15928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int a[maxn];
int main()
{
    int n,mod=1e9+7;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    int ans=a[0];
    for(int i=1;i<n;i++)
        ans=__gcd(ans,a[i]);
    printf("%d\n",ans);

}


Measured memory_bytes: 640
n = int(input())
as_ = list(map(int, input().split()))
as_ = sorted(as_)

num = 0

a_max = max(as_)
a_valid_map = [True] * (a_max + 1)
for i in range(len(as_) - 1):
    a = as_[i]
    if a_valid_map[a]:
        for j in range(a_max // a + 1):
            a_valid_map[a * j] = False
        if a != as_[i + 1]:
            num += 1
if a_valid_map[a_max]:
    num += 1

print(num)



Measured memory_bytes: 117184
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{

    internal class Solution
    {
        public int N, M;
        public int[] C;

        public void Run()
        {
            var line1 = Input.ReadIntArray();
            N = line1[0];
            M = line1[1];
            C = Input.ReadIntArray();

            int[,] dp = new int[N + 1, M + 1];
            for(int i = 0; i <= N; i++)
            for (int j = 0; j <= M; j++)
                dp[i, j] = int.MaxValue;

            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= M; j++)
                {
                    if (j == 0)
                    {
                        if (i == 0)
                            dp[i, j] = 0;
                        else
                            dp[i, j] = int.MaxValue;
                    }
                    else
                    {
                        int c = C[j - 1];
                        if (i < c || dp[i - c, j] == int.MaxValue)
                            dp[i, j] = dp[i, j - 1];
                        else
                            dp[i, j] = Math.Min(dp[i,j - 1], dp[i - c, j] + 1);
                    }
                   
                }
            }

            Console.WriteLine(dp[N, M]);
        }

       
    }

    
    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}


Measured memory_bytes: 13692
import math

A, B= map(int, input().split())

i = 0
if B<=1:
    N = 0
    all_hole = B+1
else:
    N = 0
    hole = [1]
    all_hole = sum(hole)

while all_hole < B:
    hole[i] = A
    all_hole = sum(hole)
    if hole[-1] == A:
        i = 0
        hole = [1]*all_hole
    else:
        i += 1
    N += 1

print(N)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var num = Input.num;
        var hs = Input.ar;
        var ct = 1;
        var max = hs[0];
        for (var i = 1; i < num; i++)
            if (max <= hs[i])
            {
                ct++;
                max = hs[i];
            }
        WriteLine(ct);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


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

using namespace std;

static int mod = 1000000007;

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

    int a[N+1] = {};
    for (int i = 0; i < M; ++i) {
        int b;
        cin >> b;
        a[b] = 1;
    }

    int d[N+1] = {};
    d[0] = 1;
    for (int i = 0; i < N; ++i) {
        if (!a[i + 1]) d[i + 1] = (d[i + 1] + d[i]) % mod;
        if (i+1 < N && !a[i + 2]) d[i + 2] = (d[i + 2] + d[i]) % mod;
    }

    cout << d[N] << endl;
}


Measured memory_bytes: 1024
n = int(input())
P = list(map(int, input().split()))

ans = 0

for i in range(1, n - 1):
    p = P[i - 1 : i + 2]
    p.sort()
    if len(set(p)) > 1 and p.index(P[i]) == 1:
        ans += 1

print(ans)


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

int pnjg, freq [300], jwb;
string input;

int main (){
	cin>>input;
	pnjg=input.length();
	for (int i=0; i<=pnjg-1; i++){
		freq [input [i]-'a']++;
	}
	for (int i=0; i<26; i++){
		if (freq [i]>1){
			jwb=-1;
		}
	}
	if (jwb==-1){
		cout<<"no"<<endl;
	}else{
		cout<<"yes"<<endl;
	}
}

Measured memory_bytes: 3612
import math

if __name__ == '__main__':

	n = input()
	X = list(map(int,input().split()))
	Y = list(map(int,input().split()))

    #マンハッタン距離
	d1 = 0
	for x1,y1 in zip(X,Y):
		d1 += abs(x1-y1)

	print('{:.6f}'.format(d1))

    #ユークリッド距離
	d2_tmp = 0
	for x2,y2 in zip(X,Y):
		d2_tmp += abs(x2-y2)**2
	d2 = math.sqrt(d2_tmp)
	print('{:.6f}'.format(d2))

	#n=3
	d3_tmp = 0
	for x3,y3 in zip(X,Y):
		d3_tmp += abs(x3-y3)**3
	d3 = d3_tmp ** (1/3)
	print('{:.6f}'.format(d3))

	#チェビシェフ距離
	d8 = -1
	for x8,y8 in zip(X,Y):
		d8 = max(d8,abs(x8-y8))

	print('{:.6f}'.format(d8))



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

int bio[110];

int main () {
	
int n;
cin>>n;
string s;
cin>>s;
int l=0,r=0;

for (int i=0; i<n; i++) {
	if (s[i]==')' && bio[i]==0) {
		for (int j=0; j<i; j++) {
			if (s[j]=='(' && bio[j]==0) {
				bio[j]=1;
				bio[i]=1;
				break;
			}
		}
	}
}	
for (int i=n-1; i>=0; i--) {
	if (s[i]=='(' && bio[i]==0) {
		for (int j=n-1; j>i; j--) {
			if (s[j]==')' && bio[j]==0) {
				bio[j]=1;
				bio[i]=1;
				break;
			}
		}
	}
}
for (int i=0; i<n; i++) {
	if (s[i]==')' && bio[i]==0) {
		l++;
	}
	if (s[i]=='(' && bio[i]==0) {
		r++;
	}
}
for (int i=0; i<l; i++) {
	cout<<"(";
}
cout<<s;
for (int i=0; i<r; i++) {
	cout<<")";
}
cout<<endl;
	
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include <utility>
#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 a,b,c;
    cin >> a >> b >> c;

    if(a==b && b==c )
        cout <<"No"<<endl;
    else if(a!=b && a!=c && b!=c)
        cout <<"No"<<endl;
    else
        cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256