akhauriyash/Code-Regression huggingface dataset:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

ans = 0
for i in range(A, B+1):
    if str(i) == str(i)[::-1]:
        ans += 1
print(ans)

Measured memory_bytes: 9196
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int res = 0;
    if (a >= b && a >= c) {
        int d = a - max(b, c);
        res += d;
        b += d;
        c += d;
        if ((a - min(b, c)) % 2 == 0) {
            res += (a - min(b, c)) / 2;
        } else {
            res += (a - min(b, c) + 1) / 2 + 1;
        }
    } else if (b >= a && b >= c) {
        int d = b - max(a, c);
        res += d;
        a += d;
        c += d;
        if ((b - min(a, c)) % 2 == 0) {
            res += (b - min(a, c)) / 2;
        } else {
            res += (b - min(a, c) + 1) / 2 + 1;
        }
    } else {
        int d = c - max(a, b);
        res += d;
        a += d;
        b += d;
        if ((c - min(a, b)) % 2 == 0) {
            res += (c - min(a, b)) / 2;
        } else {
            res += (a - min(a, b) + 1) / 2 + 1;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
fn solve(n: u32, y: u32) -> String {
    for ai in 0..=n {
        for bi in 0..=n - ai {
            let ci = n - ai - bi;
            if ai * 10000 + bi * 5000 + ci * 1000 == y {
                return format!("{} {} {}", ai, bi, ci)
            }
        }
    }
    "-1 -1 -1".to_string()
}

fn main() {
    let (n, y) = read_tup2();

    println!("{}", solve(n, y));
}

fn read_tup2<T: std::str::FromStr + Copy>() -> (T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v = s.trim().split_whitespace()
        .map(|c| c.parse().ok().unwrap())
        .collect::<Vec<T>>();
    (v[0], v[1])
}


Measured memory_bytes: 2136
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.nextInt();

        long[] divisors = new long[10000001];
        long[] ans = new long[10000001];
        for (int i = 1; i <= 10000000; i++) {
            for (int j = i; j <= 10000000; j += i) {
                divisors[j]++;
            }
            ans[i] += ans[i - 1] + i * divisors[i];
        }
        out.println(ans[N]);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



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

int main(){
    int N,i,flg=0;
    char S[100],S_L[50],S_R[50];
    scanf("%d",&N);
    scanf("%s",S);
    for(i=0 ; i < 50 ; i++){
        S_L[i] = 0;
        S_R[i] = 0; 
    }
    if(N % 2 != 0){
        printf("No");
    }else{
        for(i = 0 ; i < N/2 ; i++){
            S_L[i]=S[i];
        }
        S_L[i] = '\0';
        for(i = 0 ; i < N/2 ; i++){
            S_R[i] = S[i+N/2];
        }
        S_R[i] = '\0';
        for(i = 0 ; i < N/2 ; i++){
            if(S_R[i] != S_L[i]){
                printf("No");
                flg++;
                break;
            }
        }       
        if(flg == 0){
            printf("Yes");
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
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;} //最小公倍数


int main()
{
  int n ;
  cin >> n ;
  int ans = n ;
  int a = 1 ;
  int b ;
  int aa, bb ;
  
  while(a<n){
    b = n-a ;
    aa = a/100000+a%100000/10000+a%10000/1000+a%1000/100+a%100/10+a%10 ;
    bb = b/100000+b%100000/10000+b%10000/1000+b%1000/100+b%100/10+b%10 ;
    ans = min(ans,aa+bb) ;
    a++ ;
  }
  
  cout << ans <<endl;


  return 0 ;
}



Measured memory_bytes: 256
n = gets.to_i
a = gets.split(" ").map(&:to_i)

status = [1000, 0]
n.times do |i|
  # 最終日ならば全売り
  if i+1 == n then
    status = [status[0] + a[i] * status[1], 0]
    break
  end

  if a[i] < a[i+1] then
    # 全買い
    status = [status[0] % a[i], status[1] + status[0] / a[i]]
  elsif a[i] > a[i+1] then
    # 全売り
    status = [status[0] + a[i] * status[1], 0]
  end
end

puts status[0]


Measured memory_bytes: 14404
function main(input) {
  var a = Math.max(input[0].split(" ")[0]-0, input[0].split(" ")[2]-0);
  var b = Math.min(input[0].split(" ")[1]-0, input[0].split(" ")[3]-0);
  console.log(Math.max(b-a,0));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
using System;
using System.Linq;
class A
{
    static void Main()
    {
        string S = Console.ReadLine();
        string T = Console.ReadLine();
        int c = 0;
        for (int i = 0; i < 3; i++)
        {
            if (S.Substring(i, 1) == T.Substring(i, 1)) c++;
        }
        Console.WriteLine(c);
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(ALL(a));

    //累積和
    vector<ll> sum(n+1,0);
    rep(i,n) sum[i+1]=sum[i]+a[i];

    for(int i=n-1;i>0;i--){
        if(sum[i]*2<a[i]){
            cout<<n-i<<endl;
            return 0;
        }
    }
    cout<<n<<endl;


    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;

int wht[100007];

int fnc(vector<int> store, int n)
{
    int cnt = 0;

    for (int i = 1; i <= n-2; i++) {
        if (i % 2) {
            if (store[i] != store[i+2]) cnt++, store[i+2] = store[i];
        }
        else {
            if (store[i] != store[i+2]) cnt++, store[i+2] = store[i];
        }
    }

    return cnt;
}

int main()
{
    vector<int> store;
    store.push_back(0);
    int n;

    cin >> n;

    //int num1 = 0, num2 = 0;
    for (int i = 1; i <= n; i++) {
        int ttt;
        scanf("%d", &ttt);
        store.push_back(ttt);
        wht[ ttt ]++;
    }

    int num1 = 0, num2 = 0, num1id = 0, num2id = 0;
    for (int i = 1; i <= 1e5; i++) {
        if (wht[i]) {
            if (wht[i] > num1) {

                num2id = num1id;
                num2 = num1;

                num1 = wht[i];
                num1id = i;
            }
            else {
                if (wht[i] > num2) {
                    num2 = wht[i];
                    num2id = i;
                }
            }
        }
    }
//cout << "num1id && num2id :: " << num1id << ' ' << num2id << endl;

    int fs = store[1], sc = store[2];

    int ans = inf;
    if (num1id && num2id) { ///jodi only first 2ta same thake
        int cn = 0;
        if (store[1] != num1id) cn++;
        if (store[2] != num2id) cn++;

        store[1] = num1id;
        store[2] = num2id;
        ans = min(ans, fnc(store, n)+cn);


        cn = 0;
        store[1] = fs, store[2] = sc;
        if (store[1] != num2id) cn++;
        if (store[2] != num1id) cn++;

        store[1] = num2id;
        store[2] = num1id;
        ans = min(ans, fnc(store, n)+cn);
    }

    else if (store[1] == store[2]) { ///jodi arrayr sob element same thake
            store[1] = store[1] + 5;
            ans = min(ans, fnc(store, n)+1);
    }

    store[1] = fs, store[2] = sc;
    if (store[1] != store[2]) ans = min(ans, fnc(store, n));

    cout << ans << endl;
}

/*
8
1 1 2 1 2 1 2 1


4
4 4 4 1
*/


Measured memory_bytes: 1528
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n, q; cin>>n>>q;
    vector<int> a(n);
    vector<ll> sum(n+10, 0), divsum(n+10, 0);
    for(int i=0; i<n; i++){
        cin>>a[i];
        sum[i+1] = sum[i] + a[i];
        divsum[i+1] = a[i];
        if(2 <= i) divsum[i+1] += divsum[i-1]; 
    }

    for(int i=0; i<q; i++){
        int x; cin>>x;
        int ng = 0, ok = n;
        int ub, lb;
        while(ok - ng > 1){
            int mid = (ng + ok) / 2;

            if(a[mid] < x){
                ng = mid;
            }
            else{
                ub = n - mid;
                lb = lower_bound(a.begin(), a.end(), a[mid]) - lower_bound(a.begin(), a.end(), 2 * x - a[mid]) + 1;

                if(lb < ub) ng = mid;
                else ok = mid;
            }
        }

        ll ans = sum[n] - sum[ok];
        int Tturn = n - (n - ok) * 2;
        ans += divsum[max(Tturn, 0)];

        cout << ans << endl;
    }
}

Measured memory_bytes: 3712
n = int(input())
A = list(map(int, input().split()))
even_count = 0
ans_count = 0
for a in A:
    if a%2==0:
        even_count += 1
        if a%3==0 or a%5==0:
            ans_count+=1

        else:
            print('DENIED')
            break
if even_count == ans_count:
    print('APPROVED')
    


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main()
{
    IO;

    int X;
    cin >> X;
    if (X >= 30) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[100005];
int gcd(int a,int b){
	int t;
	while(b){
		t=a;a=b;b=t%b;
	}
	return a;
}
bool calc(){
	int tot=0,one=0,w;ll tota=0;
	for(int i=1;i<=n;i++){
		if(a[i]==1) one=1;
		tota+=a[i];
		if(a[i]&1) tot++,w=i;
	}
	if(one) return 0;
	if(tot!=1) return 0;
	int winner=0;
	int G=0;a[w]--;
	for(int i=1;i<=n;i++) G=gcd(G,a[i]);
	for(int i=1;i<=n;i++) a[i]/=G;
	tot=0;
	for(int i=1;i<=n;i++){
		if(!(a[i]&1)) tot^=1;
	}
	if(!tot) return 1; 
	else return 0;
} 
bool pan(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(n==1) return a[1]!=1;
	int sum=0;
	for(int i=1;i<=n;i++){
		if(!(a[i]&1)) sum^=1;
	}
	if(sum) return 1;
	int winner=0;
	while(calc()){ 
		winner^=1;
	}
	return winner;
}
int main(){
	if(pan()) puts("First");
	else puts("Second");
	return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var N int
	var S string
	fmt.Scan(&N, &S)

	dp1 := [10]bool{}  // 1文字目として登場済みか
	dp2 := [100]bool{} // 1文字目と2文字目
	ans := [1000]bool{}

	for _, r := range S {
		c := int(r - '0')
		for i := 0; i <= 99; i++ {
			if dp2[i] {
				ans[i*10+c] = true
			}
		}
		for i := 0; i <= 9; i++ {
			if dp1[i] {
				dp2[i*10+c] = true
			}
		}
		dp1[c] = true
	}
	cnt := 0
	for i := 0; i <= 999; i++ {
		if ans[i] {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 768
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#define _GLIBCXX_DEBUG
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1001001000;
const int MOD = 1000000007;

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく


//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

bool E[2005][2005];
vector<bool> seen;
typedef pair<int, int> P;
int D[2005];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[101];
int find_time = 0;

int main() {
    long long X, Y; cin >> X >> Y;
    if ((X + Y) % 3 != 0 || X*2 < Y || Y*2 < X) {
        cout << 0 << endl;
        return 0;
    }
    long long move = (X + Y) / 3;
    //どちらの移動をしてもx+1,y+1は必ず行われる
    //よって(x+1,y+2)→(x+0,x+1)、(x+2,y+1)→(x+1,y+0)に簡略化ができる
    X -= move;
    Y -= move;
    cout << nCr(X + Y, min(X, Y))%MOD << endl;
}


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

int main() {
	int k, a, b,flag=0,cnt;
	cin >> k;
	cin >> a >> b;
	if (b < k) {
		cout << "NG" << endl;
		return 0;
	}

	while (a <= b) {
		if (a % k != 0) {
			a++;
		}
		else {
			flag = 1;
			break;
		}
	}
	if (flag == 1) {
		cout << "OK" << endl;
	}
	else {
		cout << "NG" << endl;
	}
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    double xa, ya, xb, yb, xc, yc, xd, yd;
    while (cin >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd)
    {
        if (abs((yb - ya) * (yd - yc) + (xb - xa) * (xd - xc)) < 0.0000000001)
            OP("YES");
        else
            OP("NO");
    }
    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  rep(i, ty - sy) cout << 'U';
  rep(i, tx - sx) cout << 'R';
  rep(i, ty - sy) cout << 'D';
  rep(i, tx - sx) cout << 'L';
  cout << 'L';
  rep(i, ty - sy + 1) cout << 'U';
  rep(i, tx - sx + 1) cout << 'R';
  cout << 'D';
  cout << 'R';
  rep(i, ty - sy + 1) cout << 'D';
  rep(i, tx - sx + 1) cout << 'L';
  cout << 'U' << endl;
  return 0;
}


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

using namespace std;

int T, N, W;
int A[110], B[110];
long long int dp[110][100005];

long long int solve(int id, int remW) {
	if (id == N || remW == 0) return 0;

	if (~dp[id][remW]) return dp[id][remW];
	if (remW < A[id]) return dp[id][remW] = solve(id + 1, remW);

	return dp[id][remW] = max(solve(id + 1, remW), 
						B[id] + solve(id + 1, remW - A[id]));
}

int main() {
		cin >> N >> W;
		for (int i = 0; i < N; i++)
			cin >> A[i] >> B[i];

		memset(dp, -1, sizeof dp);
		cout << solve(0, W) << endl;		
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    int a[mx2];
    for(int i = 0; i < n; i++)
        cin >> a[i];

    int x = *min_element(a, a + n), y = *max_element(a, a + n);
    cout << y - x << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    cout << N /3 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

//	public static int prime(int number) {
//		int count = 0;
//		int j = 2;
//		boolean notPrime = false;
//		while (j < number) {
//			if (number % j == 0) {
//				notPrime = true;
//				break;
//			} else {
//				notPrime = false;
//			}
//			j++;
//
//		}
//		if (notPrime == false) {
//			count++;
//		}
//		return count;
//	}
	public static int prime(int[] number) {
		boolean notPrime = false;
		int count = 0;
//how to remove duplicates
		for (int i = 0; i < number.length; i++) {

			int j = 2;
			int currentNum = number[i];
			if (currentNum == 2) {
				notPrime = false;
			} else {
				while (j <= Math.floor(Math.sqrt(currentNum))) {

					if (currentNum % j == 0) {

						notPrime = true;
						break;
					} else {

						notPrime = false;
					}
					j++;
				}
			}
			if (notPrime == false) {
				count++;
			}
		}
		return count;

	}

	public static void main(String[] args) {
		
		
		
		
		
		
//		/*
//		 * scan numbers into array
//		 * 
//		 */
		Scanner scan = new Scanner(System.in);
		int number = scan.nextInt();
		int numbers[] = new int[number];
		for (int i = 0; i < numbers.length; i++) 
		{
			number = scan.nextInt();
			numbers[i] = number;
		}

		System.out.println(prime(numbers));
		

//		int[] nums = { 5, 2, 3, 4, 5, 6 };
//		int[] nums2 = {11,7,8,9,10,12,13,14,15,16,17};
//		System.out.println(prime(nums));
//		System.out.println(prime(nums2));

	}
}



Measured memory_bytes: 43060
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //個数
		int k = stdIn.nextInt(); //人数
		
		if(k==1){
			System.out.println(0);
		}else{
			System.out.println(n-k);
		}


	}
}

Measured memory_bytes: 21844
swing=[]
throw=[]
import math

n,h=map(int,input().split())
for i in range(n):
    a,b=map(int,input().split())
    swing.append(a)
    throw.append(b)

maxSwing=max(swing)

maxThrow=max(throw)

biggerlist=[]
bigsum=0
if maxSwing>=maxThrow:
    print(math.ceil(h/maxSwing))

elif maxSwing<maxThrow:
    for i in throw:
        if i>maxSwing:
            biggerlist.append(i)
            bigsum+=i
        else:
            continue
    biggerlists=sorted(biggerlist,reverse=True)

    if bigsum>h:
        suming=0
        for num in range(len(biggerlists)):
            suming+=biggerlists[num]
            if suming>=h:
                print(num+1)
                break
    elif bigsum==h:
        print(len(biggerlist))
    elif bigsum<h:
        left=h-bigsum
        lastadd=math.ceil(left/maxSwing)
        print(lastadd+len(biggerlist))
    
    

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

using namespace std;
int main(){
    int a[200+5];
    int k;
    cin>>k;
    for(int i = 0;i < 2*k;i++){
        cin>>a[i];
    }
    sort(a,a+2*k);
    int sum = 0;
    for(int i = 0;i < 2*k;i += 2){
        sum += a[i];
    }
    cout<<sum;
}


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

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

	string ans = "yes";
	set<char> st;
	rep(i, 0, s.size()) {
		if (st.count(s[i])) {
			ans = "no";
			break;
		}
		else st.insert(s[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N;
    cin >> N;
    cout << (N + 999) / 1000 * 1000 - N << endl;
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val X = sc.nextInt

    val s = mutable.HashSet(1)
    for (i <- 2 to 1000) {
      var n = i * i
      while (n <= 1000) {
        s += n
        n *= i
      }
    }
    s.toList.filter(_ <= X).max.toString
  }
}


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

int main(){
    ll n;
    cin>>n;
    bool bol=true;
    bool bl=true;
    string p,q;
    string w[n];
    for(ll i=0;i<n;++i){
        cin>>w[i];
    }

    for(ll i=0;i<n;++i){
        if(i==0){
            continue;
        }
        p=w[i-1];
        q=w[i];
        ll s=i-1;
        for(ll j=0;j<s;++j){
            if(w[j]==q){
                bol=false;
                bl=false;
                break;
            }
        }

        if(bl==false){
            break;
        }

        if(p[p.size()-1]==q[0]){
            continue;
        }else{
            bol=false;
            break;
        }
    }

    if(bol){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;






int ans;

void swap(int *a, int *b) {
	int t = *a;
	*a = *b;
	*b = t;
}

int gcd(int x, int y) {
	if (x < y)swap(&x, &y);
	if (y == 0)return x;
	ans += 1;
	//cout << ans << endl;
	x %= y;
	return gcd(y, x);
}




int main() {
	int x, y;
	while (cin >> x >> y && x > 0 && y > 0) {
		ans = 0;
		int g = gcd(x, y);
		//cout << gcd(x, y) << " " << ans << endl;
		cout << g << " " << ans << endl;
	}
}

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

int r,d,x,arr[2011];

int main(){
	cin>>r>>d>>x;
	arr[2000] = x;
	for(int i = 2001;i <= 2010;i++){
		arr[i] = r * arr[i - 1] - d;
		cout<<arr[i]<<endl;
	}
}


Measured memory_bytes: 256
import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;

bool isPairwiseCoprime(const(int)[] a) {
	auto sieve = new int[10 ^^ 6 + 1];
	auto used = new bool[sieve.length];
	foreach (i, ref e;sieve) {
		e = cast(int)i;
	}
	sieve[1] = 0;

	for (int i = 2;i < sieve.length;++i) {
		if (sieve[i] != i) {
			continue;
		}

		for (int j = i + i;j < sieve.length;j += i) {
			sieve[j] = i;
		}
	}

	auto primeList = new int[32];
	foreach (int e;a) {
		primeList.length = 0;

		while (e > 1) {
			primeList ~= sieve[e];
			e = e / sieve[e];
		}

		auto previous = 0;
		foreach (p;primeList) {
			if (previous != p && used[p]) {
				return false;
			} else {
				used[p] = true;
			}
			previous = p;
		}
	}
	return true;
}

bool isSetwiseCoprime(const(int)[] a) {
	int gcd(int a, int b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	return a.reduce!gcd == 1;
}

void main() {
	readln;
	auto a = readln.chomp.split(' ').map!(to!int).array;

	if (isPairwiseCoprime(a)) {
		writeln("pairwise coprime");
		return;
	}

	if (isSetwiseCoprime(a)) {
		writeln("setwise coprime");
		return;
	}

	writeln("not coprime");
}


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

using namespace std;

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

  int a,b; cin>>a>>b;
  int ans = 0;
  int c = 1;
  while (c < b) {
    c += a-1;
    ans++;
  }
  cout << ans << endl;

  return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define pii pair<int,int>
#define mkp make_pair

int N;
vector<int> rvs[202020];
int prv[202020];
vector<int> chrvs[202020];

int rt[202020];
int mxp[202020];

int mk[202020];
int ct[202020];

int tl1[202020];
int tl2[202020];
int anss[202020];

int i,j,h;

void sett(int n){
    int i;
    fornum(i,0,rvs[n].size()){
        if(prv[n]!=rvs[n][i]){
            {
                int nn = rvs[n][i];
                prv[nn] = n;
                mxp[nn] = n > mxp[n] ? n : mxp[n];
                chrvs[n].push_back(nn);
            }
            sett(rvs[n][i]);
        }
    }
}

void dfs(int n){
    int i;
    fornum(i,0,chrvs[n].size()){
        dfs(chrvs[n][i]);
    }
    tl1[n]++;
    if(n<mxp[prv[n]]){
        if (n> mxp[mxp[n]])
        {
            tl2[prv[n]] += tl1[n];
        }else{
            tl1[prv[n]] += tl1[n];
        }
        tl1[n] = 0;
    }
    if(mxp[n]==prv[n]){
        tl1[n] += tl2[n];
    }else{
        tl2[prv[n]] += tl2[n];
    }
}
void rslt(int n){
    int i;
    anss[n] = anss[prv[n]] + tl1[n];
    fornum(i,0,chrvs[n].size()){
        rslt(chrvs[n][i]);
    }
}


int main(){
    scanf("%d", &N);
    fornum(i,1,N){
        int a, b;
        scanf("%d%d",&a,&b);
        rvs[a].push_back(b);
        rvs[b].push_back(a);
    }

    sett(1);
    /*
    fornum(i,0,N){
        printf("%d,%d,%d_",prv[i+1],mxp[i+1],chrvs[i+1].size() );
    }*/
    dfs(1);
    tl1[1] = 0;
    rslt(1);

    fornum(i,1,N){
        printf("%d ",anss[i+1]);
    }

    return 0;
}

Measured memory_bytes: 48640
#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)
#define MOD 1000000007

signed main(){

	string s;
	cin>>s;
	set<string> ans;

	lli data[26]={0};
	REP(i,0,s.size())data[s.at(i)-'a']++;

	lli cnt=0;

	REP(i,0,26){
		if(data[i]<2)continue;
		cnt += (data[i])*(data[i]-1)/2;
	}

	lli sum = (s.size())*(s.size()-1)/2 + 1;

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

Measured memory_bytes: 640
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		String []s=br.readLine().split(" ");
		Set<Integer> set = new HashSet<Integer>();
		
		for(int i=0;i<N;i++)
			set.add(Integer.parseInt(s[i]));
		
		if(set.size()==N)
			out.println("YES");
		else
			out.println("NO");
		
	}
}




Measured memory_bytes: 61832
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;

int kaijo(int a){
  int i,ans=1;
  for(i=1;i<=a;i++){
  ans*=i;
  }
  return ans;
}

int mathC(int a,int b){

  int i,ans=1;
  if(b>a/2) b=a-b;
  for(i=1;i<=b;i++){
    ans*=(a-i+1);
    ans/=i;
  }
  
  return ans;
}

int max(int x[],int N){
  int i,max=x[0];
	for(i=1;i<N;i++){
      if(max<x[i]) max=x[i];
    }
  return max;
}

int min(int x[],int N){
  int i,min=x[0];
	for(i=1;i<N;i++){
      if(min>x[i]) min=x[i];
    }
  return min;
}

int main(void){
  
  int ans=0;
  char S[3];
  
  cin >> S;
  
  if(S[0]==S[1]) ans++;
  if(S[1]==S[2]) ans++;
  if(S[2]=='A'||S[2]=='B') ans++;
  
  if(ans!=3){
  cout << "Yes" << endl;
  }else{
  cout << "No" << endl;
  }
  
	return 0; 
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      int A = sc.nextInt();
      int B = sc.nextInt();
      int K = sc.nextInt();
      ArrayList<Integer> aList = new ArrayList<Integer>(A);
      ArrayList<Integer> bList = new ArrayList<Integer>(B);
      for(int i = 1; i <= A; i++){
        if(A % i == 0){
          aList.add(i);
        }
      }
      for(int i = 1; i <= B; i++){
        if(B % i == 0){
          bList.add(i);
        }
      }
      //System.out.println(aList);
      //System.out.println(bList);
      for(int i = 0; i < aList.size(); i++){
        if(bList.indexOf(aList.get(i)) == -1){
          aList.remove(aList.get(i));
          i--;
        }
      }
      //System.out.println(aList);
      System.out.println(aList.get(aList.size() - K));
	}
}


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

int main() {
  int N;
  cin>>N;
  string s[N];
  for (int i=0; i<N; i++) {
    cin>>s[i];
  }
  int M;
  cin>>M;
  string t[M];
  for (int i=0; i<M; i++) {
    cin>>t[i];
  }
  int ans=0;
  for (int i=0; i<N; i++) {
    int point=0;
    for (int j=0; j<N; j++) {
      if (s[i]==s[j]) {
        point++;
      }
    }
    for (int j=0; j<M; j++) {
      if (s[i]==t[j]) {
        point--;
      }
    }
    ans=max(ans,point);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector <int> t(n);
    for(int i = 0; i < n; i++){
        cin >> t[i];
    }
    int m;
    cin >> m;
    vector <int> p(m),x(m);
    for(int i = 0; i < m; i++){
        cin >> p[i] >> x[i];
        p[i]--;
    }
    for(int i = 0; i < m; i++){
        long ans = 0;
        for(int j = 0; j < n; j++){
            if(j==p[i]){
                ans += x[i];
            }else{
                ans += t[j];
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(v) v.rbegin(), v.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

#define MAX 10000007

const int MOD = 1e9+7;

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

	ll n; cin >> n;

    if(n&1) cout << "0\n";
    else{
        ll aux = n/2;
        ll cnt = 0;
        for(ll i = 5; i <= aux; i*=5)
            cnt += aux/i;
        cout << cnt << '\n';
    }

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
int n, x;
int a[100];
int main() {
    while (scanf("%d",&n)) {
        if (!n) break;
        for (int i=0; i<n; i++) scanf("%d",&a[i]);
        scanf("%d", &x);
        int lb=0, ub=n-1, res=0;
        while (ub>=lb) {
            res++;
            int mid=floor((lb+ub)/2);
            if (a[mid]<x) {
                lb=mid+1;
            } else if (a[mid]>x) {
                ub=mid-1;
            } else {
                break;
            }
        }
        printf("%d\n",res);
    }
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main()
{
	int m;

	cin >> m;

	cout << 24 + (24 - m) << endl;
}

Measured memory_bytes: 256
using System;
class aoj{
  public static void Main(){
    bool[,] card = new bool[4,13];
    for(int i=0; i<4; i++){
      for(int j=0; j<13; j++){
        card[i,j]=true;
      }
    }
    int n =  int.Parse(Console.ReadLine());
    for(int i=0; i<n; i++){
      String[] str = Console.ReadLine().Split(' ');
      String temp = str[0];
      char c = temp[0];
      int number = int.Parse(str[1]);
      switch(c){
        case 'S':
          card[0,number-1] = false;
          break;
        case 'H':
          card[1,number-1] = false;
          break;
        case 'C':
          card[2,number-1] = false;
          break;
        case 'D':
          card[3,number-1] = false;
          break;
        default:
          break;
      }
    }
    for(int i=0; i<4; i++){
      for(int j=0; j<13; j++){
        if(card[i,j]){
          switch(i){
            case 0:
              Console.WriteLine("S {0}",j+1);
              break;
            case 1:
              Console.WriteLine("H {0}",j+1);
              break;
            case 2:
              Console.WriteLine("C {0}",j+1);
              break;
            case 3:
              Console.WriteLine("D {0}",j+1);
              break;
            default:
              break;
          }
        }
      }
    }
  }
}



Measured memory_bytes: 15928
/*
Author: CNYALI_LK
LANG: C++
PROG: c.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<int,int> pii;
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
int read(){
	int s=0,base=1;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=-base;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	return s*base;
}
char WriteIntBuffer[1024];
template<class T>void write(T a,char end){
	int cnt=0,fu=1;
	if(a<0){putchar('-');fu=-1;}
	do{WriteIntBuffer[++cnt]=fu*(a%10)+'0';a/=10;}while(a);
	while(cnt){putchar(WriteIntBuffer[cnt]);--cnt;}
	putchar(end);
}
bitset<4000100> b;

int main(){
#ifdef cnyali_lk
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
#endif
	b[0]=1;
	int x,s=0,n;
	n=read();
	for(int i=1;i<=n;++i){
		x=read();
		b|=(b<<x);
		s+=x;
	}
	(s+=1)>>=1;
	while(!b[s])++s;
	printf("%d\n",s);

	return 0;
}



Measured memory_bytes: 1664
def main():
    from math import ceil

    n, *csf = map(int, open(0).read().split())
    csf = list(zip(csf[::3], csf[1::3], csf[2::3]))
    ans = ""
    for i in range(n):
        time = 0
        for c, s, f in csf[i:]:
            if time <= s:
                time = s + c
            else:
                time = s + ceil((time - s) / f) * f + c            

        ans += str(time) + '\n'
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;
using Int = long long;
#define DUMP(range) do{for(auto& x:range){cout<<x<<' ';}cout<<endl;}while(0)
int main()
{
    string S; cin >> S;
    Int ans = 0;
    for (int i = 0; i < (1 << (S.size() - 1)); i++) {
        Int sum = 0, num = 0;
        for (int j = 0; j < S.size(); j++) {
            num = num * 10 + S[j] - '0';
            if ((1 << j) & i) {
                sum += num;
                num = 0;
            }
        }
        sum += num;
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
K = "0"*(30-len(bin(K)[2:]))+bin(K)[2:]
A = [list(map(int,input().split())) for _ in range(N)]
B = [["0"*(30-len(bin(x[0])[2:]))+bin(x[0])[2:],x[1]] for x in A]
cmax = 0
cur = 0
while cur<30:
    if cur<29 and K[cur]=="1":
        cnt = 0
        x = K[:cur]+"0"
        for b in B:
            y,p = b[0],b[1]
            flag = 0
            for i in range(cur+1):
                if x[i]=="0" and y[i]=="1":
                    flag=1
                    break
            if flag==0:
                cnt += p
        cmax = max(cmax,cnt)
    elif cur==29 and K[cur]=="0":
        cnt = 0
        x = K[:]
        for b in B:
            y,p = b[0],b[1]
            flag = 0
            for i in range(cur+1):
                if x[i]=="0" and y[i]=="1":
                    flag=1
                    break
            if flag==0:
                cnt += p
        cmax = max(cmax,cnt)
    elif cur==29 and K[cur]=="1":
        cnt = 0
        x = K[:-1]
        for b in B:
            y,p = b[0],b[1]
            flag = 0
            for i in range(cur):
                if x[i]=="0" and y[i]=="1":
                    flag=1
                    break
            if flag==0:
                cnt += p
        cmax = max(cmax,cnt)
    cur += 1
print(cmax)

Measured memory_bytes: 99416
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int a, b;
  cin >> a >> b;
  if (a > 9 || b > 9) {
    cout << -1 << endl;
  } else {
    cout << a * b << endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
//       int n=sc.nextInt();
//       int x=sc.nextInt();
//       int l[]= new int[n];
//        int r[]= new int[n];

//       for (int i=0;i<n;i++){
//           l[i]=sc.nextInt();
//           r[i]=sc.nextInt();
//
//       }
        int n=sc.nextInt();
        int a[]= new int[n];
        int b[]= new int[n];
        int count=0;
        for (int i=0;i<n;i++){
            a[i]=sc.nextInt();
            b[i]=sc.nextInt();
            if (a[i]==b[i])count++;
            else count=0;
            if (count>=3){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");







         out.flush();

    }









    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }
    static void sortReverse(long[] a) {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
//        Collections.sort.(l);
        Collections.sort(l,Collections.reverseOrder());
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long[] readArrayLong(long n) {
            long[] a=new long[(int)n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }


}


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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


int c[1234567];

signed main() {

	int s;
	cin >> s;

	c[s] = 1;
	int i = 1;
	while (true) {

		i++;
		if (s % 2 == 0) s /= 2;
		else s = s * 3 + 1;

		if (c[s] > 0) break;

		c[s]++;
	}

	cout << i << endl;

	return 0;
}


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

int main(void)
{
	long long n, k;
	scanf("%lld %lld", &n, &k);

	if ((n % k) > k)
		printf("%lld", n % k < (n % k) - k ? n % k : (n % k) - k);
	else
		printf("%lld", n % k < k - (n % k) ? n % k : k - (n % k));

	return 0;
}

Measured memory_bytes: 128
while True:
    data = input().split()
    h = int(data[0])
    w = int(data[1])

    if h == 0 and w == 0:
        break

    #1行目
    for i in range(w):
        print('#',end='')
    print()

    for a in range(h-2):
        print('#',end='')
        for i in range(w-2):
            print('.',end='')
        print('#',end='')
        print()

    for i in range(w):
        print('#',end='')
    print()

    print()



Measured memory_bytes: 7000
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int main(){
  int n;
  char line[1000];
  fgets(line,sizeof(line),stdin);
  sscanf(line,"%d",&n);
  char buf[1500];
  for(int i=0;i<n;i++){
    char s[1500];
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf,"%[^\n]",s);
    int j=0;
    while(s[j]!='\0'){
      if(strncmp((s+j),"Hoshino",7)==0){
	s[j+6]='a';
      }
      j++;
    }
    printf("%s\n",s);
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main() {
	int i, j, H, W;
	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++) {
				if ((i + j) % 2==0) {
					printf("#");
				}
				else  {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572