akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize,
        h: [i64; n],
    }

    let mut tbl = vec![0; n + 1];

    for i in 1..n {
        tbl[i] = tbl[i - 1] + (h[i] - h[i - 1]).abs();
        for d in 2..k + 1 {
            if i < d {
                break;
            }
            let j = i - d;
            tbl[i] = std::cmp::min(tbl[i], tbl[j] + (h[i] - h[j]).abs());
        }
    }

    let ans = tbl[n - 1];

    println!("{}", ans);
}


Measured memory_bytes: 6396
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
a = readints()

cnt = 0
while all(x % 2 == 0 for x in a):
    a = [x/2 for x in a]
    cnt += 1
print(cnt)


Measured memory_bytes: 3832
d = int(input())
c = list(map(int,input().split()))
ans = []
fin = [1]*d
pen = [0]*26
sattemp = 0
sat = 0
sl = [list(map(int,input().split())) for i in range(d)]
for k in range(50):
    for i in range(d):
        s = sl[i]
        sp = sum(pen)
        temp = -(10**9)
        for j in range(26):
            if s[j]-(sp-pen[j])**(k*0.1) > temp:
                temp = s[j]-(sp-pen[j])**(k*0.1)
                tempans = j+1
        ans += [tempans]
        sattemp += s[tempans-1]-sp+pen[tempans-1]
        for j in range(26):
            pen[j] += c[j]
            pen[tempans-1] = 0
    if sattemp > sat:
        sat = sattemp
        fin = ans
    ans = []
    pen = [0]*26
    # print(k,sattemp)
    sattemp = 0
for i in fin:
    print(i)
# print(sat)

Measured memory_bytes: 9700
n = gets.to_i

arr = gets.split.map(&:to_i)

i=0
ans=0

n.times{
   k=0
   loop{
       if arr[i]%2 == 0
           arr[i]/=2
           k+=1
       else 
           arr[i] = k
           break
       end
        } 
    
    
i+=1  
}

puts arr.inject(:+)


Measured memory_bytes: 2684
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
vector<int> vec;
vector<int> ans;
bool isPrime(int x){
    if(x <= 6) return false;
    for(int i=0; i*i<vec.size(); i++){
        if(x % vec[i] == 0) return false;
    }
    return true;
}
int main(){
    int n;
    vec.push_back(6);
    for(int i=7; i<=300000; i+=7){
        if(isPrime(i-1)) vec.push_back(i-1);
        if(isPrime(i+1)) vec.push_back(i+1);
    }
    while(cin >> n){
        if(n == 1) break;
        sort(vec.begin(),vec.end());
        rep(i,vec.size()){
            if(vec[i] > n) break;
            if(n % vec[i] == 0) ans.push_back(vec[i]);
        }
        cout << n << ':';
        rep(i,ans.size()){
            cout << " " << ans[i]; 
        }
        cout << endl;
        ans.resize(0);
    }
    return 0;
}



Measured memory_bytes: 3240
n,m = map(int,input().split())
a = set([int(input()) for _ in range(m)])
dp = [0]*(n+1)
INF = 1000000007

dp[0] = 1
if 1 not in a:
  dp[1] = 1

for i in range(2,n+1):
    if i-1 not in a :
      dp[i] += dp[i-1] #n-1 段目が安全なら
    if i-2 not in a :
      dp[i] += dp[i-2] #n-2 段目が安全なら
    dp[i] %= INF

print(dp[n])

Measured memory_bytes: 13216
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;
const double EPS = 1e-8, INF = 1e12, PI = acos(-1.0);
typedef complex<double> P;
namespace std{
	bool operator<(const P& a, const P& b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
inline double cross(const P& a, const P& b){ return imag(conj(a)*b); }
inline double dot(const P& a, const P& b){ return real(conj(a)*b); }

int in(){
	string s; cin >> s;
	int d, l; cin >> d >> l;
	
	const double T = PI / 3;
	double t = s[0] == 'B' ? 2 * T : s[0] == 'C' ? T : 0;
	t -= d * PI / 180;
	P p = P(cos(t), sin(t)) * (double)l;
	P q = P(real(p) * sin(T) - imag(p) * cos(T), imag(p)) / sin(T);
	
	double x = real(q) - round(real(q) / 2) * 2;
	double y = imag(q) - round(imag(q) / 2) * 2;
	if(y < 0) x *= -1, y *= -1;
	//dbg(q, x, y);
	
	if(x < 0){
		x += 1;
		return x + y < 1 ? 0 : 1;
	}
	return x + y < 1 ? 2 : 3;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int p1 = in();
	int p2 = in();
	cout << (p1 == p2 ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 3504
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define each(it,c) for(__typeof(c.begin()) it=c.begin(); it!=c.end(); it++)
#define INF 1<<30
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int, int> > vp;
typedef map<int,int> mpii;
typedef priority_queue<int, vi, greater<int> > pqi;

typedef long long ll;

int main(){
	vi a(3);
	rep(i,3) cin>>a[i];
	sort(all(a));
	if(a[0]==5 && a[1]==5 && a[2]==7) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 764
import sys
sys.setrecursionlimit(1000000)

N = int(input())

adj = [[] for i in range(N)]
for i in range(N - 1):
    a, b, c = map(int, input().split())
    adj[-a].append((b, c))
    adj[-b].append((a, c))

Q, K = map(int, input().split())
query = [tuple(map(int, input().split())) for i in range(Q)]

# dist[-i]:頂点Kから頂点iまでの距離
dist = [0 for i in range(N)]

def dfs(v, prv, ds):
    dist[-v] = ds
    for nxt, c in adj[-v]:
        if nxt != prv:
            dfs(nxt, v, ds + c)

dfs(K, None, 0)

for x, y in query:
    print(dist[-x] + dist[-y])


Measured memory_bytes: 145216
using System;
class Program
 {
        static void Main(string[] args)
        {
    　　int a, p;
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            a = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            p = int.Parse(str[1]);
          
            int pie = (a * 3 + p)/2;
　　　　　　　Console.Write("{0}", pie);//改行なし出力
        }
 }

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
 
int main(void){
 
    int S; cin>>S;
    set<int> a;
 
    while(!a.count(S)){
 
        a.insert(S);
        if(S%2==0){
            S /= 2;
        }else{
            S = 3*S+1;
        }
    }
 
    cout<<a.size()+1<<endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define mp make_pair;

const ll prime = 1000000000 + 7;
const ld PI = 2 * acos(0.0);

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

int main() {

	string s;
	ll n;
	cin >> s;

	if (s == "SUN") {
		n = 7;
	}
	else if (s == "MON") {
		n = 6;
	}
	else if (s == "TUE") {
		n = 5;
	}
	else if (s == "WED") {
		n = 4;
	}
	else if (s == "THU") {
		n = 3;
	}
	else if (s == "FRI") {
		n = 2;
	}
	else {
		n = 1;
	}

	cout << n << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll Z=0;
string s;
cin>>s;
ll r=0;
ll a=0;
ll f=0;
ll l=s.size();
ll b[l+1]={};
ll c[l+1]={};
for (ll i=1;i<=l;i++){
if(s.at(i-1)=='1'){
a++;}
else{
a--;}
b[i]=a;
c[i]=a;
Z=max(Z,a);}
for (ll i=l-1;i>0;i--){
b[i]=max(b[i],b[i+1]);}
for (ll i=1;i<=l;i++){
if(s.at(i-1)=='1'){
r++;}
else if(s.at(i-1)=='0'){
r--;}
else{
if(r-c[i-1]+b[i]+2<=Z){
r++;}
else{
r--;}}
f=min(f,r);}
ll z=Z+1;
ll F=0;
r=0;
for (ll i=1;i<=l;i++){
if(s.at(i-1)=='1'){
r++;}
else if(s.at(i-1)=='0'){
r--;}
else{
if(r+b[i]-c[i-1]+2<=z){
r++;}
else{
r--;}}
F=min(F,r);}
ll o=min(Z-f,z-F);
cout<<o<<endl;}


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

int main()
{
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int x,z,ck=0,ck1=0;

        if(a%c==0){
            x=(a/c);
            z=b/c;
            ck=ck+(z-x)+1;
        }
        if(a%c!=0){
            x=(a/c);
            z=(b/c);
            ck=ck+(z-x);
        }

        if(a%d==0){
            x=(a/d);
            z=b/d;
            ck=ck+(z-x)+1;
        }
        if(a%d!=0){
            x=(a/d);
            z=(b/d);
            ck=ck+(z-x);
        }
    long long int y,hcf, temp;
    hcf = c;
    temp = d;
        while(hcf != temp)
    {
        if(hcf > temp)
            hcf -= temp;
        else
            temp -= hcf;
    }
        y = (c * d) / hcf;
        if(a%y==0){
            x=(a/y);
            z=b/y;
            ck1=ck1+(z-x)+1;
        }
        if(a%y!=0){
            x=(a/y);
            z=(b/y);
            ck1=ck1+(z-x);
        }
    ck=ck-ck1;
    ck=(b-a+1)-ck;
    cout<<ck<<endl;
}



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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int main() {
	// cin.tie(0); // tie
	// ios::sync_with_stdio(false); // sync
	int h, w;
	while (cin >> h >> w, h || w) {
		int d = h * h + w * w;
		int ans_h = 150, ans_w = 150;
		for (int i = 1; i <= 150; ++i) {
			for (int j = i + 1; j <= 150; ++j) {
				int tmp_d = i * i + j * j;
				int ans_d = ans_h * ans_h + ans_w * ans_w;
				if (d < tmp_d || (d == tmp_d && h < i)) {
					if (ans_d > tmp_d || (tmp_d == ans_d && i < ans_h)) {
						ans_h = i; ans_w = j;
					}
				}
			}
		}
		cout << ans_h << ' ' << ans_w << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n; cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    int ans = inf;
    for (int p = x[0]; p <= x.back(); ++p) {
        int t = 0;
        for (int i = 0; i < n; ++i) t += (x[i] - p) * (x[i] - p);
        ans = min(ans, t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
using namespace std;

using ll=long long int;


int main() {

	string s;
	cin >> s;

	bool a[26] = { false };
	

	for (int i = 0; i < s.size(); i++) {
		a[s[i] - 'a'] = true;
	}

	for (int i = 0; i < 26; i++) {
		if (!a[i]) {

			char c = i + 'a';
			cout << c << endl;
			break;
		}

		if (i == 25) {
			cout << "None" << endl;
		}
	}


	return 0;
}





Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>

using namespace std;

typedef long long lint;

using namespace std;

void test_case() {
    lint n;
    string ans = "";
    cin >> n;
    while(n) {
        n--;
        ans = char('a'+((n)%26)) + ans;
        n/=26;
    }
    cout << ans << "\n";

}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int tests=1;
    //cin >> tests;
    for(int test = 0; test < tests; ++test) {
        test_case();
    }
    return 0;
}


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


int main() {
    int A, B, C, K;
    std::cin >> A >> B >> C;
    std::cin >> K;

    int cnt = 0;
    while (B <= A) {
        B *= 2;
        cnt++;
    }
    while (C <= B) {
        C *= 2;
        cnt++;
    }
    if (cnt <= K) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
std::string s;
std::vector<int> xs, ys;
bool dpx[8010][17000], dpy[8010][17000];
int x, y;
int main() {
	std::cin >> s;
	std::cin >> x >> y;
	int tmp = 0;
	bool xyt = true;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s[i] == 'F')tmp++;
		else {
			if (xyt)xs.push_back(tmp);
			else ys.push_back(tmp);
			xyt = !xyt;
			tmp = 0;
		}
	}
	if (xyt)xs.push_back(tmp);
	else ys.push_back(tmp);
	xs.push_back(0);
	ys.push_back(0);
	dpx[0][xs[0] + 8500] = true;
	for (int i = 1; i < (int)xs.size(); i++) {
		for (int j = 0; j < 17000; j++) {
			if (j - xs[i] >= 0) {
				dpx[i][j] = dpx[i - 1][j - xs[i]];
			}
			if (!dpx[i][j]) {
				if (j + xs[i] < 17000) {
					dpx[i][j] = dpx[i - 1][j + xs[i]];
				}
			}
		}
	}
	dpy[0][8500 - ys[0]] = true;
	dpy[0][8500 + ys[0]] = true;
	for (int i = 1; i < (int)ys.size(); i++) {
		for (int j = 0; j < 17000; j++) {
			if (j - ys[i] >= 0) {
				dpy[i][j] = dpy[i - 1][j - ys[i]];
			}
			if (!dpy[i][j]) {
				if (j + ys[i] < 17000) {
					dpy[i][j] = dpy[i - 1][j + ys[i]];
				}
			}
		}
	}
	if (dpy[ys.size() - 1][y + 8500] && dpx[xs.size() - 1][x + 8500]) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 137472
import sys
input = sys.stdin.readline

n=int(input())
b=[int(i) for i in input().split()]

anslist=[]
while len(b) > 0:
    val=110
    for i in range(len(b)-1,-1,-1):
        if i+1==b[i]:
            val=i+1
            break
    anslist.append(val)
    b.pop(i)

if anslist.count(110)>0:
    print(-1)
else:
    for i in (reversed(anslist)):
        print(i)





Measured memory_bytes: 38512
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
sum_res = sum(A)
counter = [0 for _ in range(10 ** 5 + 1)]

for a in A:
    counter[a] += 1

for _ in range(Q):
    B, C = map(int, input().split())
    sum_res = sum_res - (counter[B] * B)
    sum_res = sum_res + (counter[B] * C)
    counter[C] += counter[B]
    counter[B] = 0
    print(sum_res)


Measured memory_bytes: 21120
#include<iostream>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
/* AtCoder Beginner Contest abc132
 * Problem D
 * Au: SJoshua
 */
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

const long long int p = 1000000007;

long long int C[2001][2001];

void init(void) {
	C[0][0] = 1;
	for (int k = 1; k <= 2000; k++) {
		C[k][0] = 1;
		for (int i = 1; i <= k; i++) {
			C[k][i] = (C[k - 1][i - 1] + C[k - 1][i]) % p;
		}
	}
}

int main(void) {
	long long int n, k;
	cin >> n >> k;
	long long int m = n - k;
	init();
	for (int i = 1; i <= k; i++) {
		long long int sum = 0;
		for (int j = 0; m - j >= i - 1; j++) {
			(sum += C[m - j][i - 1]) %= p;
		}
		cout << C[k - 1][i - 1] * sum % p << endl;
	}
	return 0;
}


Measured memory_bytes: 30080
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define se second
#define fi first
using namespace std;
typedef pair<pair<double,int>,pair<int,int> >P;
struct edge{int to,lim;double dist;};
int n,m,st,go,a1,a2,a3,a4;
double d[31][31][31];
int dx[]={-1,0,1};
vector<edge> v[31];
int main(){
  while(cin>>n>>m,n){
    r(i,31)v[i].clear();
    r(i,31)r(j,31)r(k,31)d[i][j][k]=1e12;
    cin>>st>>go;
    r(i,m){
      edge e;
      cin>>a1>>a2>>a3>>a4;
      e.to=a2,e.dist=a3,e.lim=a4;
      v[a1].push_back(e);
      e.to=a1;
      v[a2].push_back(e);
    }
    priority_queue<P,vector<P>,greater<P> >q;
    P xt;xt.fi.fi=0,xt.fi.se=0,xt.se.fi=st,xt.se.se=-1;
    q.push(xt);
    while(!q.empty()){
      P p=q.top();q.pop();
      int cur=p.se.fi,pp=p.se.se;
      if(cur==go&&p.fi.se==1){
        printf("%.9f\n",p.fi.fi);
        goto L;
      }
      r(i,v[cur].size()){
        edge e=v[cur][i];
        if(e.to!=p.se.se)r(j,3){
          int x=p.fi.se+dx[j];
          if(0<x&&x<31&&x<=e.lim){
            if(d[e.to][pp][x]>1.0*e.dist/x+p.fi.fi){
              d[e.to][pp][x]=1.0*e.dist/x+p.fi.fi;
              P xt;xt.fi.fi=d[e.to][pp][x],xt.fi.se=x,xt.se.fi=e.to,xt.se.se=cur;
              q.push(xt);
            }
          }
        }
      }
    }
    cout<<"unreachable"<<endl;L:;
  }
}

Measured memory_bytes: 4536
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 2e3+7;
int n;
int a[N*3];
int dp[N][N], mv[N], curmv[N], curdp[N];
inline void update(int x, int y, int z) {
  if (x > y) swap(x, y);
  if (z <= dp[x][y]) return;
  dp[x][y] = z;
  mv[x] = max(mv[x], z);
  mv[y] = max(mv[y], z);
  #ifdef DEBUG
  // cout << x << " " << y << " " << z << endl;
  #endif
}
#ifdef DEBUG
void print() {
  cout << "***********\n";
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      cout << dp[i][j] << " \n"[j==n];
  for (int i = 1; i <= n; ++i) cout << mv[i] << " \n"[i==n];
  cout << "***********" << endl;
}
#endif

inline void solve() {
  cin >> n;
  for (int i = 1; i <= 3*n; ++i) cin >> a[i];
  memset(dp, 0x9f, sizeof dp);
  //cout<<dp[1][1]<<endl;
  memset(mv, 0x9f, sizeof mv);
  update(a[1], a[2], 0);
  int base = 0;
  for (int i = 3; i+2 <= 3*n; i += 3) {
  	
    if (a[i] == a[i+1] && a[i] == a[i+2]) {
      ++base;
      continue;    }
    int b[3], maxv = 0;
    sort(a+i, a+i+3);
    if (a[i+1] == a[i+2]) swap(a[i], a[i+2]); 
    for (int j = 1; j <= n; ++j) {
      curdp[j] = dp[min(a[i], j)][max(a[i], j)];
      curmv[j] = mv[j];
      maxv = max(maxv, mv[j]);
    }
    for (int j = 0; j < 3; ++j) b[j] = dp[a[i+j]][a[i+j]];
    // spj
    if (a[i] == a[i+1]) for (int j = 1; j <= n; ++j) { 
      update(a[i+2], j, curdp[j]+1); // dp[a[i]][j] -> dp[a[i+2]][j]
    }
    update(a[i+1], a[i+2], b[0]+1); // get three a[i]
    update(a[i], a[i+2], b[1]+1); // get three a[i+1]
    update(a[i], a[i+1], b[2]+1); // get three a[i+2]
    // two of three rest
    update(a[i+1], a[i+2], maxv);
    update(a[i], a[i+2], maxv);
    update(a[i], a[i+1], maxv);
    // one of three rest
    for (int j = 1; j <= n; ++j) {
      update(a[i], j, curmv[j]);
      update(a[i+1], j, curmv[j]);
      update(a[i+2], j, curmv[j]);
    }
#ifdef DEBUG
    cout << i << ":\n"; print();
#endif
  }
  int res = dp[a[3*n]][a[3*n]]+1;
  for (int i = 1; i <= n; ++i) res = max(res, mv[i]);
  cout << res+base << endl;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 19416
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

vector<vector<int>> G(100005);
vector<int> h(100005,0);
vector<int> dist(100005,-1);
vector<int> par(100005,-1);
void dfs(int s, int p, int d){
    dist[s] = d;
  par[s] = p;
    for (auto w:G[s]){
        if (w==p) continue;
        dfs(w,s,d+1);
        h[s] = max(h[s],h[w]+1);
    }
}

int main(){
    int N; cin >> N;
    int u, v; cin >> u >> v; u--; v--;
    REP(i,N-1){
        int a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(v,-1,0);
  //cout << dist[u] << endl;
  //cout << (dist[u]-1)/2 << endl;
  int t = dist[u]-1; t/= 2;
  REP(i,t){
  	u = par[u];
    //cout << u << endl;
  }
  
  //REP(i,N) cout << dist[i]<<" ";cout << endl;
  //REP(i,N) cout <<    h[i]<<" ";cout << endl;
  //REP(i,N) cout <<  par[i]<<" ";cout << endl;
 // cout << u << endl;
    cout << dist[u]+h[u]-1 << endl;
    return 0;
}

Measured memory_bytes: 13312
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
char s[4];
int t[11];
int main(){
	scanf("%s",s);
	for(int i=0;i<3;i++){
		if(s[i]==s[i+1]){puts("Bad");return 0;}
	}
	puts("Good");
	return 0;
}


Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n = str(input().rstrip('\n'))
    t = 0
    for i in range(len(n)):
        t += int(n[i])
    print("Yes" if int(n) % t == 0 else "No")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n,k,ans,a;
    vector<lli> vec;
    lli i,j;
    cin>>n>>k;
    rep(i,0,n){
        cin>>a;
    }
    n-=k;
    ans=1+n/(k-1);
    if(n%(k-1)!=0){
        ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    int n = get<int>();
    vector<int> d(n);
    for (int i = 0; i < n; i++)
        d[i] = get<int>();

    sort(d.begin(), d.end());
    int mid = d.size()/2;
    cout << d[mid] - d[mid-1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define MOD 1000000007
#define DEBUG 0
#define REP(i,n) for(int i=0;i<n;i++)

int main(){

	lli h,w;
	cin>>h>>w;
	lli c[10][10]={0};
	lli a[h][w]={0};

	REP(i,10)REP(j,10)cin>>c[i][j];
	REP(i,h)REP(j,w)cin>>a[i][j];

	lli dp[10][10]={10000000000};

	REP(k,10)REP(i,10)REP(j,10)c[i][j]=min(c[i][j],c[i][k]+c[k][j]);

	lli sum = 0;

	REP(i,h)REP(j,w){
		lli now = a[i][j];
		if(now == -1)continue;
		sum += c[now][1];
	}
	cout<<sum<<endl;


}
 

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		double n = sc.nextDouble();
		int k = sc.nextInt();
		int[] a = new int[(int)n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		n -= k;
		int ans = 1;
		while(n > 0) {
			n -= k-1;
			ans++;
		}
		System.out.println(ans);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


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

int main() {
    int n, m = 1e8, r = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int p;
        scanf("%d", &p);
        if(p < m)
            r++, m = p;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
// HTTF.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define int LL
#define pb emplace_back
#define eb pb

using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 330;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 7 + 1e9;
const LL INF = 1LL << 30;
const long double EPS = 1e-7;
typedef pair<ld, ut> pld;

#define endl "\n" //インタラクティブでは消す
ut N, M, K, L, Q, D, H, W;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], maps2[SIZE2][SIZE2], answer = zero;
LL maps[SIZE2][SIZE2];
LL DP[SIZE];
bool finished[SIZE];
LL DP2[SIZE2][SIZE2];
LL DP3[SIZE3][SIZE3][SIZE3];
LL A[SIZE];
LL solve2(int x) {
	if (finished[x]) return DP[x];
	if (x== 0) return INF;
	if (x == 1) return 0;
	finished[x] = true;
	DP[x] = INF;
	EFOR(i,1, K) {
		if (x - i <= 0) break;
		MN(DP[x], solve2(x - i) + abs(A[x] - A[x - i]));
	}
	return DP[x];
}
LL solve() {
	cin >> N >> K;
	REP(i, N) {
		cin >> A[i+1];

	}
	cout << solve2(N)<<endl;
	return 0;
}




//!!!!!!!!!!!!!!!!!!!実装を詰める!!!!!!!!!!!!!!!!!!!!!!!!!
signed main() {

	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(12);
	solve();
	cin >> N;
	return 0;

}

Measured memory_bytes: 20608
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#define PI acos(-1.0)
using namespace std;
const int inf = 0x3f3f3f3f;
typedef long long ll;
const int N = 100050;
ll dp[N],a[N];
int n,k;
int main() {
	scanf("%d%d",&n,&k);
	for(int i = 1; i<=n; ++i) scanf("%lld",&a[i]);
	for(int i = 2; i<=n; ++i) {
		dp[i] = inf;
		for(int j = 1; j<=k; ++j) {
			if(i-j<1) break;
			dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
		}
	}
	printf("%lld\n",dp[n]);
	return 0;
}


Measured memory_bytes: 5328
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n;
	cin>>n;
	set<string> s;
	for(long long int i=0;i<n;i++){
		string a;
      cin>>a;
		s.insert(a);
	}
	cout<<s.size()<<endl;
		return 0;}
	

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

int top, sta[110];

void push(int x) {
  top++;
  sta[top] = x;
}

int pop() {
  top--;
  return sta[top + 1];
}

int main() {
  int a, b;
  top = 0;
  char s[110];
  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      b = pop();
      a = pop();
      push(a + b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (s[0] == '*') {
      b = pop();
      a = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  cout << sta[1] << endl;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 200005;
const int INF = 10e9 + 5; 
typedef long long ll;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, m, sum = 0;
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    ll x;
    cin >> x;
    sum += x;
  }
  if(sum > n) cout << -1<< endl;
  else cout << n - sum;
  return 0;
}

/*
         ,--"""",--.__,---[],-------._         
       ,"   __,'            \         \--""""""==;-
     ," _,-"  "/---.___     \       ___\   ,-'',"
    /,-'      / ;. ,.--'-.__\  _,-"" ,| `,'   /
   /``""""-._/,-|:\       []\,' ```-/:;-. `. /
             `  ;:::      ||       /:,;  `-.\
                =.,'__,---||-.____',.=
                =(:\_     ||__    ):)=
               ,"::::`----||::`--':::"._
             ,':::::::::::||::::::::::::'.
    .__     ;:::.-.:::::__||___:::::.-.:::\     __,
       """-;:::( O )::::>_|| _<::::( O )::::-"""
   =======;:::::`-`:::::::||':::::::`-`:::::\=======
    ,--"";:::_____________||______________::::""----.          , ,
         ; ::`._(    |    |||     |   )_,'::::\_,,,,,,,,,,____/,'_,
       ,;    :::`--._|____[]|_____|_.-'::::::::::::::::::::::::);_
      ;/ /      :::::::::,||,:::::::::::::::::::::::::::::::::::/
     /; ``''''----------/,'/,__,,,,,____:::::::::::::::::::::,"
     ;/                :);/|_;| ,--.. . ```-.:::::::::::::_,"
    /;                :::):__,'//""\\. ,--.. \:::,:::::_,"
   ;/              :::::/ . . . . . . //""\\. \::":__,"
   ;/          :::::::,' . . . . . . . . . . .:`::\
   ';      :::::::__,'. ,--.. . .,--. . . . . .:`::`
   ';   __,..--'''-. . //""\\. .//""\\ . ,--.. :`:::`
   ;    /  \\ .//""\\ . . . . . . . . . //""\\. :`::`
   ;   /       . . . . . . . . . . . . . . . . .:`::`
   ;   (          . . . . . . . . . . . . . . . ;:::`
   ,:  ;,            . . . . . . . . . . . . . ;':::`
   ,:  ;,             . . . . . . . . . . . . .;`:::
   ,:   ;,             . . . . . . . . . . . . ;`::;`
    ,:  ;             . . . . . . . . . . . . ;':::;`
     :   ;             . . . . . . . . . . . ,':::;
      :   '.          . . . . . . . .. . . .,':::;`
       :    `.       . . . . . . . . . . . ;::::;`
        '.    `-.   . . . . . . . . . . ,-'::::;
          `:_    ``--..___________..--'':::::;'`
             `._::,.:,.:,:_ctr_:,:,.::,.:_;'`
________________`"\/"\/\/'""""`\/"\/""\/"____________________________
 
*/
				

Measured memory_bytes: 3640
//17:30
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;
ll max(ll a, ll b){return(a>b)?a:b;}
ll min(ll a, ll b){return(a<b)?a:b;}
ll abss(ll a){return(a<0)?-a:a;}

int cnt[203];
int main(){
        int N,M,X,Y;
        scanf("%d %d %d %d",&N,&M,&X,&Y);

        int minx=X,maxx=X;
        int miny=Y,maxy=Y;
        int x,y;
        for(int i = 0; i < N; i++){
                scanf("%d",&x);
                minx = min(minx,x);
                maxx = max(maxx,x);
        }
        for(int i = 0; i < M; i++){
                scanf("%d",&y);
                miny = min(miny,y);
                maxy = max(maxy,y);
        }

        memset(cnt,0,sizeof(cnt));
        for(int x = -100; x <= 100; x++){
                if(minx <= x && x <= maxx) cnt[x+100] += 1;
        }
        for(int y = -100; y <= 100; y++){
                if(miny <= y && y <= maxy) cnt[y+100] += 1;
        }
        for(int i = 0; i < 203; i++){
                if(cnt[i] == 2){
                        puts("War");
                        return 0;
                }
        }
        puts("No War");

}

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

int main() {
    int n, mv[2] = {0};
    cin >> n;
    static int ns[100005][2];
    for(int i = 0; i < n; ++i) {
        int v;
        cin >> v;
        ns[v][i % 2]++;
        mv[i % 2] = max(mv[i % 2], v);
    }
    static pair<int, int> ma[2], ma2[2];
    for(int j = 0; j < 2; ++j) {
        for(int i = 1; i <= mv[j]; ++i) {
            if(ma[j].first < ns[i][j]) {
                ma2[j] = ma[j];
                ma[j].first = ns[i][j];
                ma[j].second = i;
            } else {
                if(ma2[j].first < ns[i][j]) {
                    ma2[j].first = ns[i][j];
                    ma2[j].second = i;
                }
            }
        }
    }
    if(ma[0].second != ma[1].second)
        cout << n - ma[0].first - ma[1].first << endl;
    else
        cout << n - max(ma[0].first + ma2[1].first, ma[1].first + ma2[0].first)
             << endl;
    return 0;
}


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

#define MAXN 100010

int n,l,t,x[MAXN],w[MAXN],p[MAXN],delta;

int main()
{
	scanf("%d%d%d",&n,&l,&t);
	for(int i=1;i<=n;++i)scanf("%d%d",x+i,w+i);
	for(int i=1;i<=n;++i)
	{
		if(w[i]==1)p[i]=(x[i]+t)%l;
		else p[i]=((x[i]-t)%l+l)%l;
	}
	for(int i=1;i<=n;++i)
	{
		if(w[i]==1)delta+=(x[i]+t)/l;
		else delta-=(l-x[i]+t-1)/l;
	}
	sort(p+1,p+n+1);
	p[0]=p[n];
	for(int i=1;i<=n;++i)printf("%d\n",p[((i+delta)%n+n)%n]);
}

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

#define int             long long
#define INF             1e18
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)

const int MOD = 1e9 + 7;





int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n, c = 0;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
	{
		if ((i + 1) % 2 && a[i] % 2)
			c++;
	}
	cout << c;

	return 0;
}


Measured memory_bytes: 3616
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        if (a <= 5) {
            System.out.println(0);
        } else if (a <= 12) {
            System.out.println(b / 2);
        } else {
            System.out.println(b);
        }
    }
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
using namespace std;
 
const ll N =(2e5+5);
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll LOG = 29;

long long binpow(long long a, long long b) {
     
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a) ;
        a = (a * a) ;

        
        b >>= 1;
    }
    res;
    return res;
}
void solve(){
    
    ll n;
    cin>>n;
    ll W;
    cin>>W;
    ll wt[n+1],val[n+1];
    for(int i =1;i<=n;i++){
        cin>>wt[i]>>val[i];
    }
    vll v[4];
    ll gg = wt[1];
    v[0].pb(val[1]);
    for(int i =2;i<=n;i++){
        v[wt[i]-gg].pb(val[i]);
    }
    for(int i =0;i<4;i++){
        sort(all(v[i]),greater<ll>());
    }
    ll ans = 0;
    ll pre[4][n+1];
    for(int i = 0;i<4;i++){
        pre[i][0] = 0;
        for(int j =1;j<=v[i].size();j++){
            pre[i][j] = pre[i][j-1] + v[i][j-1]; 
        }
    }
    for(ll a = 0;a<=v[0].size();a++){
        for(ll b = 0;b<=v[1].size();b++){
            for(ll c = 0;c<=v[2].size();c++){
                for(ll d = 0;d<=v[3].size();d++){
                    ll x = gg*(a);
                    ll y = (gg+1)*b;
                    ll z = (gg+2)*c;
                    ll k = (gg+3)*d;
                    x+=y;
                    x+=z;
                    x+=k;
                    if(x<=W){
                        ans = max(ans,pre[0][a]+pre[1][b]+pre[2][c]+pre[3][d]);
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}






int main()
{
    ios_base::sync_with_stdio(0);
     cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }
     
 
 
    return 0;     
    
        
}

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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

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

int main(){
  while(scanf("%d%d", &m, &n) && m+n){
      int x = 1, y = 1, d = 40, k;
      char in[32];
      while(scanf("%s", in) && in[0] != 'S'){
	switch(in[0]){
	case 'F':
	  scanf("%d", &k);
	  x += dx[d%4] * k; y += dy[d%4] * k;
	  break;
	case 'B':
	  scanf("%d", &k);
	  x += dx[d%4] * -k; y += dy[d%4] * -k;
	  break;
	case 'R':
	  d++; 
	  break;
	case 'L':
	  d--;
	  break;
	}
	if(x < 1) x = 1; if(x > m) x = m;
	if(y < 1) y = 1; if(y > n) y = n;
      }
      printf("%d %d\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<string>

int main(){
    std::string S[3];
    for(int i = 0; i < 3; i++) std::cin >> S[i];
    std::string T;
    for(int i = 0; i < 3; i++){
        T += std::toupper(S[i][0]);
    }
    std::cout << T << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;


int main () {
  int H, W;
  int i, j;
  while (1) {
    cin >> H >> W;
    if (H == 0 && W == 0) break;
    rep(i,H) {
      rep(j,W) {
	cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int ans=s.length();
	for(char i='a';i<='z';i++){
		int now=0,mx=0;
		for(auto c:s){
            if(c==i)now=0;
		    else mx=max(mx,++now);
        }
		ans=min(ans,mx);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
//Try until you reach your goal
#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define endl "\n"
# define str string
# define vll vector<ll>
# define pb push_back
# define mll map<ll,ll>
# define mp make_pair
# define ff first
# define ss second
# define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll a[3];
    for(ll i=0;i<3;i++){
        a[i]=0;
    }
    ll k,k1;
    cin>>k>>k1;
    a[k-1]=1;
    a[k1-1]=1;
    for(ll i=0;i<3;i++){
        if(a[i]==0){
            cout<<i+1;
        }
    }
    return 0;
}

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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;

int f(int n) {
    if (n & 1) {
        return 3 * n + 1;
    } else {
        return n / 2;
    }
}

int main() {
    int s;
    cin >> s;
    unordered_set<int> st;
    st.insert(s);
    int a = s;
    int b;
    int m = 2;
    while (true) {
        b = f(a);
        if (st.count(b)) {
            cout << m << endl;
            return 0;
        } else {
            st.insert(b);
        }
        ++m;
        a = b;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

int main(){

 string s;
 cin>>s;

 int len = s.length(),k=0;

 for(int i=0;i<len;i++){
    if(s[i] == '1')
        k++;
 }

 int zeros = len-k;

 if(k > zeros)
    cout<<zeros*2<<endl;
 else if(k < zeros)
    cout<<k*2<<endl;
  else if(k == zeros)
    cout<<k*2<<endl;


return 0;
}


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

int main(void){
  int N, i, n, max=0, a[100000];
  scanf("%d",&N);
  for(i=0;i<100000;i++) a[i]=0;
  for(i=0;i<N;i++){
    scanf("%d",&n);
    a[n]++;
    if(a[n]>max) max=a[n];
    if(n>0){
      a[n-1]++;
      if(a[n-1]>max) max=a[n-1];
    }
    if(n<99999){
      a[n+1]++;
      if(a[n+1]>max) max=a[n+1];
    }    
  }
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
  
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
 
#define pb emplace_back
#define fi first
#define se second

using namespace std;
 
typedef long double ld;
// typedef long long int ll;
typedef __int128 ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
 
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }
ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
 
// head

struct ConvexHullTrick{
  vi st;
  vl a, b;
  int s, t, it;
  void init( int n ){
    st = vi( n );
    a.clear(); b.clear();
    s = t = 0;
  }
  bool check( int i , int j , int k ){
    return ( a[k] - a[i] ) * ( b[i] - b[j] ) > ( b[i] - b[k] ) * ( a[j] - a[i] );
  }
  void add( ll ca , ll cb ){
    a.pb( ca ); b.pb( cb );
    while( s <= t-2 && check( st[t-2] , st[t-1] , SZ(a)-1 ) ) t--;
    st[t++] = SZ(a)-1;
  }
  ll f( int i , ll x ){
    return a[i] * x + b[i];
  }
  ll query( ll x ){
    while( s+1 < t && f(st[s],x) <= f(st[s+1],x) ) s++;
    return f(st[s],x);
  }
};

ConvexHullTrick cht;

ll dp[4000010];

ll n, a;
ll ans;

ll f( ll x , ll y ){
  return dp[x] * ( y - x - a );
}

bool check( ll x ){
  if( x >= n ){
    return true;
  }
  REP( i , 4000010 ){
    if( dp[i] * ( x - i - a ) >= n ){
      return true;
    }
  }
  return false;
}

int main(){

  n = in();
  a = in();

  cht.init( 4000010 );

  FOR( i , 1 , 4000010 ){
    dp[i] = i;
    if( cht.s < cht.t ){
      chmax( dp[i] , cht.query( i ) );
    }
    cht.add( dp[i] , dp[i] * ( - i - a ) );
    if( dp[i] >= n ){
      cout << (long long int)i << endl;
      return 0;
    }
  }

  ll lb = 0, ub = n+1;
  while( ub - lb > 1 ){
    ll md = ( lb + ub ) / 2;
    if( check( md ) ){
      ub = md;
    } else {
      lb = md;
    }
  }

  cout << (long long int)ub << endl;

  // assert( false );

  return 0;
}


Measured memory_bytes: 203580
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int main(){
	map<string,set<int> > data;
	string tmpWord;
	int tmpPage;
	while(cin>>tmpWord>>tmpPage){
		data[tmpWord].insert(tmpPage);
	}
	for(map<string,set<int> >::iterator i=data.begin();i!=data.end();i++){
		cout<<(i->first)<<endl;
		for(set<int>::iterator j=(i->second).begin();j!=(i->second).end();j++){
			if(j!=(i->second).begin())cout<<" ";
			cout<<*j;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1228