akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(int)(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?1:0)
#define YN(flag) cout<<(flag?"YES":"NO")<<endl;
#define Yn(flag) cout<<(flag?"Yes":"No")<<endl;
#define yn(flag) cout<<(flag?"yes":"no")<<endl;
#define Cout(v) cout<<(v)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ===================

// Template End =========================

int main(void){
  int a,b,c,d; cin>>a>>b>>c>>d;
  Cout(a*b-(a*d+b*c-c*d));
}












Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <math.h>

using namespace std;

int main(){
    double n; cin >> n;
    double one = 3.14 * 1;
    cout << n*n << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  const string t = "keyence";
  bool found = false;
  int len = s.size() - t.size();
  for (int i = 0; len >= 0 && i + len <= s.size(); ++i) {
    string cur = s.substr(0, i) + s.substr(i + len);
    if (cur == t) found = true;
  }
  puts(found ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
solve 0 _ _ = []
solve h w xs = [take w xs] ++ (solve (h-1) w (tail xs))

main = do
    str <- getLine
    let (h:w:_) = map read $ words str
    if (h,w) == (0,0) then
        return ()
    else do
        putStrLn $ unlines $ solve h w (cycle "#.")
        main

Measured memory_bytes: 4076
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


//正剰余
long long mod(long long a, long long b)
{
	return a - (long long)std::floor((double)a / (double)b) * b;
}
ll MOD = 1000000007;
ll inf = 1e18;
int main() {
	
	int A, B,K;
	cin >> K;
	cin >> A >> B;
	repi(i, A, B + 1) {
		if (i % K == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}


Measured memory_bytes: 3560
#include <stdio.h>
#include <stdlib.h>

int x[100003];

int f(int n, int *a) {
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int ai = a[i];
		if (ai == 0) {
			x[0] += 1;
			x[1] += 1;
		} else {
			x[ai-1] += 1;
			x[ai] += 1;
			x[ai+1] += 1;
		}
	}
	for (int i = 1; i < 99999; i++) {
		if (x[i] > ans) ans = x[i];
	}
	return ans;
}

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

	ans = f(n, a);
	
	printf("%d\n", ans);	
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
//#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int k;
struct TheNum
{
	int head;
	int size;
	int vals[110];
};

void makeProgress(TheNum &num) {
	num.size++;
	num.vals[num.size - 1] = 1;
	for (int i = num.size - 2 ; i >= 0 ; i--) {
		num.vals[i] = 0;
	}
}

void getNext(TheNum &num) {
	if (num.size == 0) {
		makeProgress(num);
		return ;
	}
	
	bool hasCarry = false;
	int p = 0;
	num.vals[p]++;
	while (true) {
		if (num.vals[p] > 9) {
			hasCarry = true;
			if (p == (num.size - 1)) {
				makeProgress(num);
				return ;
			} else {
				num.vals[p + 1]++;
				num.vals[p] = num.vals[p + 1] - 1;
				p++;
			}
		} else if (num.vals[p] > (num.vals[p + 1] + 1)) {
			if (p == (num.size - 1))
				break;
				
			hasCarry = true;				
//			if (p == (num.size - 1)) {
//				makeProgress(num);
//				return ;
//			} else {
				num.vals[p + 1]++;
				num.vals[p] = num.vals[p + 1] - 1;
				p++;
//			}
		} else {
			break;
		}
	}
	
	int d = num.vals[p] - 1;
	if (hasCarry) {
		for (int i = p - 1 ; i >= 0 ; i--) {
			num.vals[i] = d;
			d--;
			if (d < 0)
				d = 0;
		}
	}
}

int main()
{
	scanf("%d", &k);
	TheNum num;
	num.head = 0;
	num.size = 0;
	num.vals[0] = 0;
	
	for (int i = 0 ; i < k ; i++) {
		getNext(num);
//		for (int i = num.size - 1 ; i >= 0 ; i--) {
//			printf("%d", num.vals[i]);
//		}
//		printf("\n");
		
	}
	
	for (int i = num.size - 1 ; i >= 0 ; i--) {
		printf("%d", num.vals[i]);
	}
	printf("\n");
	
	return 0;
}

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

int main(){
int A,B,X;
  cin >> A >> B >> X;
  
  if(A > X){
  cout << "NO" << endl;
  }else{
  if(B < X - A){
  cout << "NO" << endl;
  }
  else{
  cout << "YES" << endl;
  }
  }
  return 0;
}

Measured memory_bytes: 256
#include "stdio.h"
#include "string.h"

int main(int argc, char* argv[])
{
	char str[100000];
	int  alp[26] = {0};
	int i, len;

	scanf("%s", str);

	len = strlen(str);

	for (i = 0; i < len; i++) {
		alp[str[i] - 'a']++;
	}

	for (i = 0; i < 26; i++) {
		if (alp[i] == 0) {
			char min = 'a' + i;
			printf("%c\n", min);
			break;
		}
	}

	if (i == 26) 
		printf("None\n");

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int K = cin.nextint;
        int even = K / 2;
        int odd = K - even;

        WriteLine(even * odd);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13140
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;

map<long long int, int>soinnsuu(long long int a) {
	map<long long int, int>ans;
	for (long long i = 2; i*i <= a; ++i) {
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;


	return ans;
}

int main() {
	int N; cin >> N;
	auto mp = soinnsuu(N);
	vector<int>anss;
	for (auto m : mp) {
		for (int i = 0; i < m.second; ++i) {
			anss.emplace_back(m.first);
		}

	}
	cout << N << ":";
	for (auto a : anss) {
		cout << " " << a;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3160
n=int(input())
a=list(map(int,input().split()))
if 1 not in a:
    print(-1)
else:
    cnt=0
    if len(a)==1:
        print(0)
    else:
        f=1
        for i in a:
            if i==f:
                f+=1
            else:
                cnt+=1
        print(cnt)


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


def main():
    """Function."""
    a1, a2, a3 = map(int, input().split())

    print(
          min([
               abs(a2 - a1) + abs(a3 - a2),
               abs(a3 - a1) + abs(a2 - a3),
               abs(a1 - a2) + abs(a3 - a1),
               abs(a3 - a2) + abs(a1 - a3),
               abs(a1 - a3) + abs(a2 - a1),
               abs(a2 - a3) + abs(a1 - a2)
                                         ])
                                          )


if __name__ == "__main__":
    main()


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int k = 0;
int N;

vector<vector<int>> G;

void print() {
   rep (i, k) {
      for (int x : G[i]) {
         cout << x+1 << " ";
      }
      puts("");
   }
}

signed main() {
   cin >> N;

   while (1) {
      if (N == k*(k-1)/2) {
         break;
      }
      if (N < k*(k-1)/2) {
         puts("No");
         return 0;
      }
      k++;
   }

   G = vector<vector<int>>(k, vector<int>(0));
   int pos = 1;
   rep (i, k) {
      repp (j, i+1, k) {
         G[i].push_back(pos);
         G[j].push_back(pos);
         pos++;
      }
   }

   cout << "Yes" << endl;
   cout << k << endl;
   rep (i, k) {
      cout << G[i].size();
      for (int x : G[i]) {
         cout << " " << x;
      }
      puts("");
   }


   return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s[3][3];
  int N;
  int i,j,k;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d",&s[i][j]);
    }
  }
  cin >> N;
  int t[N];
  for(i=0;i<N;i++){
    scanf("%d\n",&t[i]);
  }
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      for(k=0;k<N;k++){
     if(s[i][j]==t[k]){
       s[i][j]=0;
     }
      }
    }
  }
  int cout=0;
  for(i=0;i<3;i++){
    if(s[1][i]==s[2][i] && s[0][i]==s[1][i]){
      printf("Yes\n");
      cout++;
      break;
    }
    if(s[i][1]==s[i][2] && s[i][0]==s[i][1]){
      printf("Yes\n");
      cout++;
      break;
    }
    if(s[0][2]==s[1][1] && s[2][0]==s[1][1]){
      printf("Yes\n");
      cout++;
      break;
    }
    if(s[1][1]==s[2][2] && s[0][0]==s[1][1]){
      printf("Yes\n");
      cout++;
      break;
    }    
  }
  if(cout==0){
    printf("No\n");
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int x;
	cin>>x;
	cout<<1-x<<endl;
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

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

  vector<int> a(N), b(N);
  REP(i, N){
    cin >> a[i] >> b[i];
  }

  sort(ALL(a));
  reverse(ALL(a));

  sort(ALL(b));
  reverse(ALL(b));

  int ans = 0;

  REP(i, N){
    if(b[i] > a[0]){
      H -= b[i];
      ans++;
      if(H<=0){
        cout << ans << endl;
        return 0;
      }
    }else{
      break;
    }
  }

  ans += (H+ (a[0]-1))/a[0];
  cout << ans << endl;
}


Measured memory_bytes: 1024
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy
import heapq
setrecursionlimit(10**6)
input=stdin.readline

n,m=map(int,input().split())
a=[-int(i) for i in input().split()]
heapq.heapify(a)

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

print(-sum(a))

Measured memory_bytes: 14168
import sys
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
for i in range(1000):
  x=list(str(i))
  ct=0
  for j in range(m):
    if len(x)>=l[j][0]:
      if x[l[j][0]-1]==str(l[j][1]):
        ct+=1
  if ct==m and len(x)==n:
    print(i)
    sys.exit()
print(-1)

Measured memory_bytes: 40688
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <cstring>
#include <unordered_set>
#include <unordered_map>

using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

int main(){
    string s;
    int n;
    cin >> s;
    int ans = 0;
    REP(i, s.length()){
        ans += s[i] - '0';
    }
    if(s[0] == '1'){
        bool flag = true;
        FOR(i, 1, s.length()){
            if(s[i] != '0') flag = false;
        }
        if(flag){
            cout << 10 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

// O(HW + HWlogW)

Measured memory_bytes: 256
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

per_s = permutations(range(1, n+1))

c1 = 0
c2 = 0
for i, per in enumerate(per_s):
    if (per == p):
        c1 = i
    if (per == q):
        c2 = i

print(abs(c1 - c2))

Measured memory_bytes: 3064
n, k = map(int,input().split())

l = [list(map(int,input().split())) for i in range(k*2)]
a=[]
for i in range(1,k+1):
    a.append(l[2*i-1])
b = []
for j in a :
    for item in j :
        b.append(item)

ans = 0
for k in range(1,n+1):
    if b.count(k) == 0 :
        ans += 1

print(ans)


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

 using namespace std;

 int main() {
   int W, H, N, i;
   int xLD, yLD, xRU, yRU;
   cin >> W >> H >> N;

   vector<int> x(N);
   vector<int> y(N);
   vector<int> a(N);

   for (i = 0; i < N; i++) cin >> x.at(i) >> y.at(i) >> a.at(i);

   xLD = 0;
   yLD = 0;
   xRU = W;
   yRU = H;

   for (i = 0; i < N; i++) {
     if (a.at(i) == 1) xLD = max(xLD, x.at(i));
     else if (a.at(i) == 2) xRU = min(xRU, x.at(i));
     else if (a.at(i) == 3) yLD = max(yLD, y.at(i));
     else if (a.at(i) == 4) yRU = min(yRU, y.at(i));
   }

   cout << max(0, xRU - xLD) * max(0, yRU - yLD) << endl;
 }


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x<y?y:x;}
	template <class T> inline T cabs(const T &x){return x<0?-x:x;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	const int n=nxi(),q1=nxi(),q2=nxi();
	if(n==1){
		printf("%d\n",cabs(nxi()-q2));
		return 0;
	}
	for(int i=1; i<n-1; ++i) nxi();
	{
		int v1=nxi(),v2=nxi();
		printf("%d\n",std::max(cabs(q2-v2),cabs(v1-v2)));
	}
	return 0;
}


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

int main() {
    int n;
    cin >>n;
    vector<long long> rui={2,1};
    for(int i=0;i<n-1;i++){
        rui.push_back(rui[i]+rui[i+1]);
    }
    /*for(int i=0;i<n+1;i++){
        cout << rui[i] << " ";
    }*/
    cout <<rui[n] << endl;
    return 0;
}


Measured memory_bytes: 256
/*  */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000")

#define sti				set<int>
#define stpii			set<pair<int, int> >
#define mpii			map<int,int>
#define vi				vector<int>
#define pii				pair<int,int>
#define vpii			vector<pair<int,int> >
#define rep(i, a, n) 	for (int i=a;i<n;++i)
#define per(i, a, n) 	for (int i=n-1;i>=a;--i)
#define clr				clear
#define pb 				push_back
#define mp 				make_pair
#define fir				first
#define sec				second
#define all(x) 			(x).begin(),(x).end()
#define SZ(x) 			((int)(x).size())
#define lson			l, mid, rt<<1
#define rson			mid+1, r, rt<<1|1
#define getBits(x)		__builtin_popcount(x)
#define getBitIdx(x)	__builtin_ffs(x)

typedef long long LL;
vector<int> vc[4];
vector<LL> vs[4];
int c[4];
LL w[4];
int n, W;

void solve(int w0) {
	rep(i, 0, 4)
		w[i] = w0+i;
	rep(i, 0, 4) {
		sort(vc[i].begin(), vc[i].end(), greater<int>());
		const int sz = vc[i].size();
		c[i] = sz;
		vs[i].push_back(0LL);
		rep(j, 0, sz) {
			LL x = vs[i][j] + vc[i][j];
			vs[i].push_back(x);
		}
	}
	
	LL ans = 0, tmp;
	
	for (int x=0; x<=c[0]; ++x) {
		if (x*w[0] > W) break;
		for (int y=0; y<=c[1]; ++y) {
			if (x*w[0]+y*w[1] > W) break;
			for (int z=0; z<=c[2]; ++z) {
				if (x*w[0]+y*w[1]+z*w[2] > W) break;
				
				LL p = min((LL)c[3], (W - (x*w[0]+y*w[1]+z*w[2])) / w[3]);
				tmp = vs[0][x] + vs[1][y] + vs[2][z] + vs[3][p];
				ans = max(ans, tmp);
			}
		}
	}
	
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// #ifndef ONLINE_JUDGE
		// freopen("data.in", "r", stdin);
		// freopen("data.out", "w", stdout);
	// #endif
	
	int w, w0, v;
	
	scanf("%d %d", &n, &W);
	rep(i, 0, n) {
		scanf("%d %d", &w, &v);
		if (i == 0)
			w0 = w;
		int cid = w - w0;
		vc[cid].push_back(v);
		// ++c[cid];
	}
	solve(w0);
	
	// #ifndef ONLINE_JUDGE
		// printf("time = %ldms.\n", clock());
	// #endif
	
	return 0;
}


Measured memory_bytes: 256
N,M,Q = map(int,input().split())
ABCD_list = [list(map(int,input().split())) for i in range(Q)]

import itertools

candidateA = [i for i in range(1,M+1)]

answer_candeidates = list(itertools.combinations_with_replacement(candidateA,N))
#print(answer_candeidates)
ans = 0
for answer_candeidate in answer_candeidates:
    tmp_answer = 0
    for abcd in ABCD_list:
        t = answer_candeidate[abcd[1]-1] - answer_candeidate[abcd[0]-1]
        #print(t)
        if t == abcd[2]:
            tmp_answer += abcd[3]
            #print(tmp_answer)
    ans = max(tmp_answer,ans)

print(ans)

Measured memory_bytes: 21616
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	int x,n,k,c=0;
	cin>>n>>k;
	while(n--){
		cin>>x;
		if(x>=k) c++;
		}
	cout<<c<<nw;
	
	return 0;
}

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

int main() {
    int N; cin >> N;
    vector<float> v(N);

    for (int i = 0; i < N; ++i) cin >> v[i];
    sort(v.begin(), v.end());

    for (int j = 0; j < N-1; ++j) {
        v[j+1]=(v[j]+v[j+1])/2;
    }

    cout << v[N-1] << endl;

    return 0;
}

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

int main() {
  string O, E;
  cin >> O >> E;
  int o = O.size();
  int e = E.size();
  
  for(int i=0; i<e; i++){
    cout << O.at(i) << E.at(i);
  }
  
  if(o-e==1)cout << O.at(o-1);
  cout << endl;
}

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

//小文字を大文字に変換する関数
char upper(char c){
  if('a' <= c && c <= 'z'){
    c = c - ('a' - 'A');
  }
  return c;
}

int main() {
  
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  
  cout << upper(s1.at(0)) << upper(s2.at(0)) << upper(s3.at(0)) << endl;
  
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vector<pair<llint, llint>> prime_factorize(llint n) {
    vector<pair<llint, llint> > res;
    llint num;

    for(llint p=2;p*p<=n;p++) {
        if (n%p!=0) continue;
        num = 0;
        while (n%p==0) { ++num; n /= p; }
        res.push_back(make_pair(p,num));
    }
    if (n!=1) res.push_back(make_pair(n,1));
    return res;
}

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

    llint ans = 0, tmp, insqrt;
    for(llint in=1;in<=n-1;++in) {
        tmp = 1;
        auto res =  prime_factorize(in);
        for(auto ires:res) {
            tmp *= ires.second+1;
        }
        ans += tmp;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int N;
string S;
signed main() {
  cin>>N>>S;
  int ans=0;
  for(int i=1;i<N;i++){
    int cur=0;
    for(char c='a';c<='z';c++){
      bool flag1=false,flag2=false;
      for(int k=0;k<i;k++){
        if(S[k]==c) flag1=true;
      }
      for(int k=i;k<N;k++){
        if(S[k]==c) flag2=true;
      }
      if(flag1&&flag2)cur++;
    }
    ans=max(ans,cur);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;



int main(){
   int a,b;
   cin >> a >> b;
   cout << 6-a-b << endl;
   
   
   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))
using ll = long long;
using P = pair<ll, ll>;
using namespace std;

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

int main()
{
    int H, W;
    cin >> H >> W;
    int h, w;
    cin >> h >> w;

    cout << (H*W) - (W*h) - (H*w) + (h*w) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    string s;
    cin>>n;
    cin>>s;
    int prew[n]={0},sufe[n]={0};
    prew[0]=(s[0]=='W');
    sufe[n-1]=(s[n-1]=='E');
    for (i=1;i<n;i++)
    {
        prew[i]=prew[i-1]+(s[i]=='W');
        sufe[n-i-1]=sufe[n-i]+(s[n-i-1]=='E');
    }
    int ans=n+1,tp;
    for (i=0;i<n;i++)
    {
        tp=prew[i]-(s[i]=='W')+sufe[i]-(s[i]=='E');
        ans=min(ans,tp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2964
N,K = map(int,input().split())
R,S,P = map(int,input().split())
D={"r":P,"s":R,"p":S}
T = input().strip()
A = {i:[] for i in range(K)}
for i in range(N):
    A[i%K].append(T[i])
cnt = 0
for k in range(K):
    if len(A[k])>0:
        cnt += D[A[k][0]]
        for i in range(1,len(A[k])):
            if A[k][i]==A[k][i-1]:
                A[k][i] = 0
            elif A[k][i]!=A[k][i-1]:
                cnt += D[A[k][i]]
print(cnt)

Measured memory_bytes: 92020
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int H, W;
    int h,w;

    cin >> H >> W >> h >> w;

    vector<vector<bool>> map(H, vector<bool>(W, true));

    for(int i=0; i<h;i++){
        for(int j=0; j<W; j++){
            map.at(i).at(j)=false;
        }
    }
    for(int i=0; i<H;i++){
        for(int j=0; j<w; j++){
            map.at(i).at(j)=false;
        }
    }

    int count = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(map.at(i).at(j)==true) count++;
        }
    }


    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
ans=0
if n==1 and m==1:
	ans=1
elif n==1 or m==1:
	ans=max(0,max(m,n)-2)
elif n==2 or m==2:
	ans=0
else:
	ans=(n-2)*(m-2)
print(ans)

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    reverse(a.begin(), a.end());
    int k = 1;
    while (a.size() > 0) {
        int v = a.back();
        a.pop_back();
        if (v == k) {
            k++;
        }
    }
    cout << (k == 1 ? -1 : n-k+1) << endl;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,n) for (ll i=a;i<n;i++)
#define loopm(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define tr(container,it)\
for(auto it=container.begin();it!=container.end();it++)
#define SZ(x) ((int)(x).size())
#define WGraph(n) vector < vector < pair < ll , ll > > >(n)
typedef vector<long long> VI;
typedef long long ll;
typedef vector < vector < ll > > VII;
typedef pair<ll,ll> PII;
typedef double db;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,w;
    cin>>n>>w;
    VI cost(n,0);
    VI pages(n,0);
    loop(i,0,n)cin>>cost[i]>>pages[i];

    VI dp(w+1,0);
    loopm(i,0,n){
        VI cop(w+1,0);
        loop(j,0,w+1){
              if(i<n-1){
                   if(j+cost[i]<=w)
                   cop[j]=max(dp[j+cost[i]]+pages[i],dp[j]);
                   else
                    cop[j]=dp[j];

              }
              else{
                   if(j+cost[i]<=w)
                      cop[j]=pages[i];
                   else
                      cop[j]=0;
              }
        }
        dp=cop;
    }
    cout<<dp[0]<<"\n";

}


Measured memory_bytes: 4768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define rep(i,a,n) for(ll i = a ; i <=n;++i)
#define sf(n) scanf("%lld",&n)
#define pf(n) printf("%lld\n",n)
#define bug printf("bug\n")

int main(){

ll n ; sf(n);
ll a[n+2] , b[n+2];
rep(i,0,n-1)
sf(a[i]);
rep(i,0,n-1)
sf(b[i]);

ll ans = 0;
rep(i,0,n-1){
ll ops = 0 ,diff = b[i] - a[i];
if(diff > 0)
    ops = diff/2;
else ops = diff ;
ans+=ops;


}

if(ans<0) cout <<"No"<<endl;
    else cout << "Yes"<<endl;


return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s; cin >> s;
    ll res = 0;
    rep(i, s.size()){
        if(i%2 == 0){
            if(s[i] == 'p') res--;
        }else{
            if(s[i] == 'g') res++;
        }
    }
    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4608
import itertools

n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

seq = []
for i in range(1,n+1):
    seq.append(i)
pat = list(itertools.permutations(seq))

ans = 0
cnt = 0
for i in range(len(pat)):
    if pat[i]==p or pat[i]==q:
        if p==q:
            print(0)
            break
        if cnt==1:
            print(i-ans)
            break
        ans = i
        cnt = 1

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


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

Measured memory_bytes: 3568
import numpy as np

k, q = map(int, input().split())
d = np.array(list(map(int, input().split())))

for i in range(q):
  n, x, m = map(int, input().split())
  mod_d = d % m
  modsum_d = mod_d.cumsum()
  _q, _m = divmod(n - 1, k)
  
  ans = modsum_d[k - 1] * _q
  if _m > 0:
    ans += modsum_d[_m - 1]
  ans = n - 1 - (ans + x % m) // m - np.count_nonzero(mod_d == 0) * _q
  if _m > 0:
    ans -= np.count_nonzero(mod_d[0 : _m] == 0)
  print(ans)

Measured memory_bytes: 12620
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string str;
  cin >> str;
  if(str[0] == str[1]){
    cout << "No" << "\n";
    return 0;
  }
  if(str[1] == str[2]){
    cout << "No" << "\n";
    return 0;
  }
  if(str[2] == str[0]){
    cout << "No" << "\n";
    return 0;
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	double a;
	cin>>n;
	if(n%2==0)
	{
		a=1.0/2;
		cout<<fixed;
		cout<<setprecision(10)<<a;
	}
	else
	{
		a= ((n+1)/2)/double(n) ;
		cout<<fixed<<setprecision(10)<<a;
	}
}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).uniq.sort
n = a.size
x = 1145141919
(n - 1).times do |i|
    x = [x, a[i + 1] - a[i]].min
end
flag = false
n.times do |i|
    if a[i] % x == k % x
        flag = true
        break
    end
end
if flag && k <= a.max
    puts "POSSIBLE"
else
    puts "IMPOSSIBLE"
end

Measured memory_bytes: 15748
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll unsigned long long int
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e18;
int main()
{
IOS
ll n;
cin>>n;
ll cnt=0;
for(ll i=1;i<=n;i++)
{
    ll x;
    cin>>x;
    if(i%2!=0)
    {
        if(x%2!=0)
            cnt++;
    }
}
cout<<cnt;
return 0;
}


Measured memory_bytes: 3648
class PriorityQueue
  
  def initialize
    @heap = Array.new
    @sz = 0
  end
  
  def push x
    i = @sz
    @sz += 1
    while i > 0 do
      p = ( i - 1 ) / 2
      break if @heap[p] <= x
      @heap[i] = @heap[p]
      i = p
    end
    @heap[i] = x
  end
  
  def pop
    
    ret = @heap[0]
    x = @heap[@sz-=1]
    
    i = 0
    while i * 2 + 1 < @sz do
      a = i * 2 + 1
      b = i * 2 + 2
      a = b if b < @sz && @heap[b] < @heap[a]
      break if @heap[a] >= x
      @heap[i] = @heap[a]
      i = a
    end
    
    @heap[i] = x
    @heap.delete_at(-1)
    ret
  end
  
  def top
    @heap[0]
  end
  
  def any?
    @sz > 0
  end
  
  def empty?
    @sz == 0
  end
  
  def all
    @heap
  end
end
 
n, m = gets.to_s.split.map{|t| t.to_i }
# dr   = Array.new(n){ gets.to_s.split.map{|t| t.to_i } }.sort_by{|d,_|d}

ws = Array.new(m+1){ [] }
ws = Hash.new { |h, k| h[k] = [] }
n.times do
  a, b = gets.to_s.split
  a, b = a.to_i, b.to_i
  # a <= m and ws[a] << b
  ws[a] << b if a <= m
end
# p ws
pq = PriorityQueue.new
 
ans = 0
cur = 0
(1..m).each do |i|
  
  ws[i].each{ |v| pq.push(-v) }
  pq.any? and ans -= pq.pop
  # p pq
end

puts ans

Measured memory_bytes: 21372
def gcd(a,b):
    while b != 0:
        a,b = b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

n = int(input())
t = [ int(input()) for _ in range(n)]
ans = 1
for i in range(n):
    ans = lcm(ans, t[i])
print(ans)

Measured memory_bytes: 3060
def solve(x):
    y = x % 100
    ny = y // 5
    if y % 5 != 0:
        ny += 1
    if x // 100 >= ny:
        return 1
    else:
        return 0


def main():
    x = int(input())
    res = solve(x)
    print(res)


def test():
    assert solve(615) == 1
    assert solve(217) == 0


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 2940
N, P = map(int, input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

L = factorization(P)

res = 1
for i in range(len(L)):
	k = L[i][1]//N
	if k > 0:
		res *= L[i][0]**k
print(res)

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


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

    int a,b;
    cin >> a >> b;
    if (a > 2 * b) cout << a - 2 * b << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

class Main {

	
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int x = s.nextInt();
		
		int l = Math.max(x-n+1, -1000000);
		int r = Math.min(x+n-1, 1000000);
		
		for(int i=l;i<=r;i++)
			System.out.print(i+" ");
		
		System.out.println();
		
		
		
		
		
	}
}


Measured memory_bytes: 23124
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#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 <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<iostream>
#include<algorithm>//next_permutation

using namespace std;

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

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var jy=input.trim().split(" ").map(Number);
var j=jy[0];
var y=jy[1];
var sum=j+y;
var all=[];
var loop=function(ary,j,y,J,Y){
   if(ary.length==sum){
      all.push(ary.join(""));  
   }else{
      if(J==5 && Y==5)return;
      if(J==6 || Y==6)return;      
      if(J<=3 && Y==5)return;      
      if(J==5 && Y<=3)return;  
      if(j>=1)loop(ary.concat("A"),j-1,y,J+1,Y);
      if(y>=1)loop(ary.concat("B"),j,y-1,J,Y+1);
   }
};
loop([],j,y,0,0);
all.sort();
all.forEach(function(v){
   console.log(v);
});

Measured memory_bytes: 16604
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = '-' + sr()
T = '-' + sr()
Q = ir()
cnt_S = np.array([[0, 0] for _ in range(len(S))])
cnt_T = np.array([[0, 0] for _ in range(len(S))])
for i, s in enumerate(S[1:], 1):
    if s == 'A':
        cnt_S[i][0] = 1
    else:
        cnt_S[i][1] = 1

for i, t in enumerate(T[1:], 1):
    if t == 'A':
        cnt_T[i][0] = 1
    else:
        cnt_T[i][1] = 1

np.add.accumulate(cnt_S, axis=0, out=cnt_S)
np.add.accumulate(cnt_T, axis=0, out=cnt_T)

answer = []
for _ in range(Q):
    a, b, c, d = lr()
    num_S = cnt_S[b][0] - cnt_S[b][1] - (cnt_S[a-1][0] - cnt_S[a-1][1])
    num_T = cnt_T[d][0] - cnt_T[d][1] - (cnt_T[c-1][0] - cnt_T[c-1][1])
    if (num_S - num_T) % 3 == 0:
        answer.append('YES')
    else:
        answer.append('NO')

print('\n'.join(answer))
# 58

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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n;

double dp[310][310][310];
double rec(int i, int j, int k) {
	if (dp[i][j][k] >= 0) return dp[i][j][k];
	if (i == 0 && j == 0 && k == 0) return 0.0;

	double res = 0.0;
	if (i > 0) res += rec(i - 1, j, k) * i;
	if (j > 0) res += rec(i + 1, j - 1, k) * j;
	if (k > 0) res += rec(i, j + 1, k - 1) * k;

	res += n;
	res *= 1.0 / (i + j + k);

	return dp[i][j][k] = res;
}

int main(void){
	cin>>n;
	int one = 0, two = 0, three = 0;
	for (int i = 0; i < n; i++) {
		int a; cin>>a;
		if (a == 1) one++;
		else if (a == 2) two++;
		else three++;
	}

	memset(dp, -1, sizeof(dp));

	printf("%.12f\n", rec(one, two, three));
	
	return 0;
}

Measured memory_bytes: 233088
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> ans;
    if(n==0){
      cout<<0<<endl;
      return 0;
    }
	int m = n;
	while (m != 0) {
		if (m % 2 == 0) ans.push_back(0);
		else {
			ans.push_back(1);
			m--;
		}
		m /= -2;
	}
	reverse(ans.begin(), ans.end());
	for(ll i=0;i<(ll)ans.size();i++) cout << ans[i];
	cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    string sa,sb,sc;
    cin >> sa >> sb >> sc;
    int a=0,b=0,c=0;

    string cur;
    cur = sa[0];
    a++;

    while(1){
        if(cur == "a"){
            if(a == sa.size()) break;
            cur = sa[a];
            a++;
        }
        if(cur == "b"){
            if(b == sb.size()) break;
            cur = sb[b];
            b++;
        }
        if(cur == "c"){
            if(c == sc.size()) break;
            cur = sc[c];
            c++;
        }
    }

    if(cur == "a") cout << "A" << endl;
    else if(cur == "b") cout << "B" << endl;
    else cout << "C" << endl;
    return 0;
}



Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        a: i32,
        b: i32,
        c: i32,
        k: i32,
    }

    let mut total = 0;
    let mut a_cnt = a;
    let mut b_cnt = b;
    let mut c_cnt = c;
    let mut took = 0;

    for _ in 0..k {
        if a_cnt != 0 && took != k{ 
            total += 1;
            a_cnt -= 1;
            took += 1;
            continue;
        }
        break;
    }
    for _ in 0..k - took {
        if b_cnt != 0 && took != k{
            b_cnt -= 1;
            took += 1;
            continue;
        }
        break;
    }
    for _ in 0..k - took{
        if c_cnt != 0 && took != k{
            total -= 1;
            c_cnt -= 1;
            took += 1;
            continue;
        }
        break;
    }
    println!("{}", total);
}


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

int prime[2 * 123460];
int main() {
  for (int i = 0; i < 2 * 123457; ++i) {
    prime[i] = 1;
  }
  prime[0] = prime[1] = 0;
  for (int i = 2; i < 2 * 123457; ++i) {
    if (!prime[i]) continue;
    for (int j = i + i; j < 2 * 123457; j += i) {
      prime[j] = 0;
    }
  }
  for (int i = 0; i < 2 * 123456; ++i) {
    prime[i + 1] += prime[i];
  }

  int n;
  while (cin >> n, n) {
    cout << prime[2 * n] - prime[n] << endl;
  }
}

Measured memory_bytes: 4088