akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> v(h);

  for (int i=0; i<h; i++) {
    cin >> v[i];
  }

  for (int i=0; i<h+2; i++) {
    if (i==0 || i==h+1) {
      printf("%s\n", string(w+2, '#').c_str());
    } else {
      printf("#%s#\n", v[i-1].c_str());
    }
  }
  return 0;
}

Measured memory_bytes: 256
import Control.Monad

merge :: [(Int, Int)] -> [(Int, Int)] -> [(Int, Int)]
merge xs [] = xs
merge [] ys = ys
merge (x:xs) (y:ys)
    | fst x < fst y = x : merge xs (y:ys)
    | otherwise     = y : merge (x:xs) ys

msort :: [(Int, Int)] -> [(Int, Int)]
msort [] = []
msort [x] = [x]
msort x = merge (msort (take h x)) (msort (drop h x))
    where
        h = length x `div` 2

minus :: Int -> Int -> Int
n `minus` m = if n - m <= 0 then 0 else n - m

getN :: Int -> [(Int, Int)] -> Int
getN 0 (x:xs) = fst x
getN n (x:xs) = if n `minus` snd x == 0 then fst x else getN (n `minus` snd x) xs


main = do
  [n, k] <- map read . words <$> getLine
  numPares <- replicateM n $ do
                [p, q] <- map read . words <$> getLine
                return (p,q)
                
  putStrLn $ show $ getN k (msort numPares)

Measured memory_bytes: 91260
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	int h,w,k;cin>>h>>w>>k;
	vector<string> a;
	int res = 0;
	for(int i = 0; i < h; i++) {
		string x;cin>>x;
		a.pb(x);
	}
	for(int i = 0; i < 1 << h; i++) {
		for(int j = 0; j < 1 << w; j++) {
				int ans = 0;
			for(int k = 0; k < h; k++) {
				for(int l = 0; l < w; l++) {
					if ((i >> k) & 1 && (j >> l) & 1){
						if (a[k][l] == '#'){
							ans ++;
						}
					}
				}
			}
			if(ans == k)res ++;
		}
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    string s;
    cin >> s;
    bool flag = true;
    for(int i=0;i<s.size();i++){
        if((i+1) % 2 == 1){
            if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D'){
                //cout << s[i] << endl;
                continue;
            }else{
                flag = false;
                break;
            }
        }else{
            if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D'){
                //cout << s[i] << 2 << endl;
                continue;
            }else{
                flag = false;
                break;
            }
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

ll N;
string S;

vector<ll> z_algorithm(const string &s) {
  vector<ll> prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      ll k = max(0ll, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (ll) s.size();
  return prefix;
}

int main() {
    cin >> N >> S;
    vector<ll> v = z_algorithm(S); 
    // cout << v[1] << endl;

    ll ans = 0;
    rep(i, N) {
        string target = S.substr(i, N - i);
        vector<ll> v = z_algorithm(target); 
        rep(j, N - i) {
            ans = max(ans, min((ll)j, (ll)v[j]));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline

from collections import defaultdict

H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

cnt = defaultdict(int)
cnt_h = defaultdict(int)
cnt_w = defaultdict(int)

for h, w in hw:
    cnt[(h, w)] += 1
    cnt_h[h] += 1
    cnt_w[w] += 1
cnt_h = list(cnt_h.items())
cnt_w = list(cnt_w.items())
cnt_h.sort(key = lambda x: -x[1])
cnt_w.sort(key = lambda x: -x[1])

max_h = []
max_w = []
for h, n in cnt_h:
    if n == cnt_h[0][1]:
        max_h.append(h)
for w, n in cnt_w:
    if n == cnt_w[0][1]:
        max_w.append(w)

answer = cnt_h[0][1] + cnt_w[0][1]
for mh in max_h:
    for mw in max_w:
        if cnt[(mh, mw)] == 0:
            print(answer)
            exit()

print(answer - 1)

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

// Return the maximum volume. 
double maxvolume(double s) 
{ 
	double length = s / 3; 

	s -= length; 

	// finding breadth 
	double breadth = s / 2; 

	// finding height 
	double height = s - breadth; 

	return length * breadth * height; 
} 

int main() 
{ 
	double s;
    cin >> s;
	cout << fixed << setprecision(12) << maxvolume(s) << endl; 
	return 0; 
} 


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

#endif


void solve(){
    int N, R;
    cin >> N >> R;
    if(N>=10) cout << R << endl;
    else
        cout << R + 100*(10-N) << endl;
    
}

signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 256
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
e = dd(list)
if N == 1:
  print("First")
  exit(0)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append((v, 1))
  e[v].append((u, 1))
import heapq
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s, t):
    d = [float("inf")] * (self.n + 1)
    vis = set()
    d[s] = 0
    h = [s]
    while not t in vis and len(h):
      v = heapq.heappop(h)
      v1 = v % (10 ** 6)
      v0 = v // (10 ** 6)
      if v1 in vis: continue
      vis.add(v1)
      for p in self.e[v1]:
        d[p[0]] = min(d[p[0]], d[v1] + p[1])
        if p[0] in vis: continue
        heapq.heappush(h, d[p[0]] * (10 ** 6) + p[0])
    return d
dij = dijkstra(N, e)
s = 0
d = 0
p = dij.path(1, 0)
for i in range(1, N + 1):
  if p[i] > d:
    s = i
    d = p[i]
p = dij.path(s, 0)
mx = max(p[1: ])
if mx % 3 == 1: print("Second")
else: print("First")

Measured memory_bytes: 130160
import java.util.*;
 
public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] a = new int[N];
        int count2 = 0;
        int count4 = 0;
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            if(a[i] % 4 == 0)
                count4++;
            else{
                if(a[i] % 2 == 0)
                    count2++;
            }    
        }
        sc.close();

        if(count4 > 0 && 2*count4+1 >= N){
            System.out.println("Yes");
            return;
        }
        if(count2 == N){
            System.out.println("Yes");
            return;
        }
        if(count2 > 1 && count4 > 0 && (2*count4+count2 >= N)){
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
        
    }
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s; s[5]=' '; s[13]=' ';
	cout << s << endl;
	return 0;
}


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

typedef long long ll;

int main() {
	ll mat[50][50], _mat[50][50], s[50], _s[50];
	ll n, m, a, b, c, t;
	while(1) {
		cin >> n >> m >> a >> b >> c >> t;
		if(!n&&!m&&!a&&!b&&!c&&!t) break;
		s[0] = s[n+1] = 0;
		for(int i=0; i<n; ++i) cin >> s[i];
		for(int i=0; i<n; ++i) {
			for(int j=0; j<n; ++j) {
				if(i-1==j) mat[i][j] = a;
				else if(i==j) mat[i][j] = b;
				else if(i==j-1) mat[i][j] = c;
				else mat[i][j] = 0;
			}
		}
		while(t) {
			if(t%2) {
				for(int i=0; i<n; ++i) _s[i] = s[i];
				for(int i=0; i<n; ++i) {
					s[i] = 0;
					for(int j=0; j<n; ++j) s[i] = (s[i] + mat[i][j]*_s[j])%m;
				}
			}
			for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) _mat[i][j] = mat[i][j];
			for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) {
				mat[i][j] = 0;
				for(int k=0; k<n; ++k) {
					mat[i][j] = (mat[i][j] + _mat[i][k]*_mat[k][j])%m;
				}
			}
			t/=2;
		}
		for(int i=0; i<n; ++i) cout << (!i?"":" ") << s[i];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
  
using namespace std;

int main()
{
    int n, w, d;
    while(1){
        cin >> n >> w >> d;
        if(n == 0 && w == 0 && d == 0) break;
        vector<int> width;
        vector<int> depth;
        width.push_back(w);
        depth.push_back(d);
        int p, s;
        
        // for(int i = 0; i < width.size(); i++){
        //     cout << width[i] << " " << depth[i] << endl;
        // }
        for(int i = 0; i < n; i++){
            cin >> p >> s;
            vector<int>::iterator nowwit = width.begin() + p - 1;
            vector<int>::iterator nowdit = depth.begin() + p - 1;
            int noww = *nowwit;
            int nowd = *nowdit;
            // cout << noww << " " << nowd << endl;
            width.erase(nowwit);
            depth.erase(nowdit);
            s = s % (noww + nowd);
            int neww1 = noww, newd1 = nowd, neww2 = noww, newd2 = nowd;
            if(s < noww){
                neww1 = s;
                neww2 = noww - s;
            } else {
                s -= noww;
                newd1 = s;
                newd2 = nowd - s;
            }
            // cout << neww1 << newd1 << neww2 << newd2 << endl;
            if(neww1 * newd1 < neww2 * newd2){
                width.push_back(neww1);
                width.push_back(neww2);
                depth.push_back(newd1);
                depth.push_back(newd2);
            } else {
                width.push_back(neww2);
                width.push_back(neww1);
                depth.push_back(newd2);
                depth.push_back(newd1);
            }
            // for(int j = 0; j < width.size(); j++){
            //     cout << width[j] << " " << depth[j] << endl;
            // }
        }
        vector<int> ans;
        for(int i = 0; i < width.size(); i++){
            ans.push_back(width[i] * depth[i]);
        }
        sort(ans.begin(), ans.end());
        for(int i = 0; i < ans.size(); i++){
            if(i == ans.size() - 1) cout << ans[i] << endl;
            else cout << ans[i] << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	int a,b;
	cin>>a>>b;
	int h,m;
	cin>>h>>m;
	double theta1 = 30 * h;
	theta1 += 1.0*m/2.0;
	theta1 *=M_PI/180.0;
	double theta2 = 6.0 * m *M_PI/180.0;
	double xa = a*cos(theta1),ya = a*sin(theta1);
	double xb = b*cos(theta2),yb = b*sin(theta2);
	double res = sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
	cout<<fixed<<setprecision(20)<<res<<endl;

}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 4100
a = []
for i in range(3):
    a.append(list(map(int, input().split())))
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))

for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[j][k] == b[i]:
                a[j][k] = 0

for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == 0:
        print('Yes')
        break
    elif a[0][i] == a[1][i] == a[2][i] == 0:
        print('Yes')
        break
else:
    if a[0][0] == a[1][1] == a[2][2] == 0:
        print('Yes')
    elif a[0][2] == a[1][1] == a[2][0] == 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 38416
<?php

//標準入力
class Scanner {
  private $arr = [];
  private $count = 0;
  private $pointer = 0;
  public function next() {
      if($this->pointer >= $this->count) {
          $str = trim(fgets(STDIN));
          $this->arr = explode(' ', $str);
          $this->count = count($this->arr);
          $this->pointer = 0;
      }
      $result = $this->arr[$this->pointer];
      $this->pointer++;
      return $result;
  }
  public function hasNext() {
      return $this->pointer < $this->count;
  }
  public function nextInt() {
      return (int)$this->next();
  }
  public function nextDouble() {
      return (double)$this->next();
  }
}

//標準出力
class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}



$sc = new Scanner();
$S = $sc->next();

$weather = ['Sunny', 'Cloudy', 'Rainy'];


$ans = $weather[(array_search($S,$weather) + 1) % 3];

echo $ans.PHP_EOL;



Measured memory_bytes: 4728
#include <stdio.h>
#include <iostream>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <limits.h>
#include <map>
#include <string>
#include <bitset>
#include <vector>
using namespace std;
int a[100005], b[100005], c[100005], eat[200005];
bool cmp1(int a,int b) {
    return a < b;
}
bool cmp2(int a,int b) {
    return a > b;
}
int main() {
    int x, y, n1, n2, n3, t = 1;
    long long ans = 0;
    cin >> x >> y >> n1 >> n2 >> n3;
    for (int i = 1; i <= n1; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n2; i++) scanf("%d", &b[i]);
    for (int i = 1; i <= n3; i++) scanf("%d", &c[i]);
    sort(a + 1, a + n1 + 1, cmp2);
    sort(b + 1, b + n2 + 1, cmp2);
    sort(c + 1, c + n3 + 1, cmp2);
    for (int i = 1; i <= x; i++) eat[i] = a[i];
    for (int i = x + 1; i <= x + y; i++) eat[i] = b[i - x];
    sort(eat + 1, eat + x + y + 1, cmp1);
    while (c[t] > eat[t] && t <= x + y && t <= n3) {
        eat[t] = c[t];
        t++;
    }
    for (int i = 1; i <= x + y; i++) ans += eat[i];
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 5604
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
	string arr[100000];
	int countAC = 0, countTLE = 0, countWA = 0 , countRE=0;
	int num;
	cin >> num;
	for (int i = 0; i < num; i++)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < num; i++)
	{
		if (arr[i] == "AC")
			countAC++;
		else if (arr[i] == "TLE")
			countTLE++;
		else if (arr[i] == "WA")
			countWA++;
		else if (arr[i] == "RE")
			countRE++;

	}
	cout << "\nAC"<<" "<<"x"<<" " << countAC;
	cout << "\nWA" << " " << "x" <<" "<< countWA;
	cout << "\nTLE"<<" "<<"x" << " " << countTLE;
	cout << "\n RE " << " " <<"x" << " " << countRE;
	return 0;
}

Measured memory_bytes: 6752
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
#define STDIN freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);
const int N = 2e5 + 10;

int a[N];
int main()
{
    //STDIN
    int n, m;
    cin >> n >> m;
    int sum = 0;
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    for (int i = 1; i <= n; i++)
    {
        if (4*m*a[i] >= sum) cnt++;
    }
    if (cnt >= m) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace AtCoder {
    class Program {
        static void Main(string[] args) {

            var input1 = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray();
            var a = input1[0];
            var b = input1[1];
            var c = input1[2];

            Console.WriteLine(b / a > c ? c : b / a);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#define PIE 3.14159265358979
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;

struct SegmentTree{
private:
    int n;
    vector<ll> node;
public:
    SegmentTree(int sz){
        n = 1;while(n<sz)n*=2;
        node.resize(2*n-1,0);
    }
    SegmentTree(vector<ll> v){
        int sz = v.size();
        n = 1;while(n<sz)n*=2;
        node.resize(2*n-1,0);
        
        for(int i = 0;i < sz;i++)node[i+n-1]=v[i];
        for(int i = n-2;i >=0;i++)node[i]=max(node[2*i+1],node[2*i+2]);
    }
    
    void update(int x, ll val) {
        // 最下段のノードにアクセスする
        x += (n - 1);
        // 最下段のノードを更新したら、あとは親に上って更新していく
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }
    
    // 要求区間 [a, b) 中の要素の最小値を答える
    ll getmax(int a, int b, int k=0, int l=0, int r=-1) {
        // 最初に呼び出されたときの対象区間は [0, n)
        if(r < 0) r = n;
        // 要求区間と対象区間が交わらない -> 適当に返す
        if(r <= a || b <= l) return 0;
        // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
        if(a <= l && r <= b) return node[k];
        // 要求区間が対象区間の一部を被覆 -> 子について探索を行う
        // 左側の子を vl ・ 右側の子を vr としている
        // 新しい対象区間は、現在の対象区間を半分に割ったもの
        ll vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        return max(vl, vr);
    }
};


int main(){
    int N;
    vector<int> h;
    vector<ll> a;
    vector<pair<int,int> > pl;//h,index
    cin>>N;
    h.reserve(N),a.reserve(N);
    int temp;
    for(int i = 0;i < N;i++){
        cin>>temp;
        h.push_back(temp);
        pl.push_back(make_pair(temp,i));
    }
    sort(pl.begin(),pl.end());
    for(int i = 0;i < N;i++){
        cin>>temp;
        a.push_back(temp);
    }
    
    SegmentTree st(N);
    for(int fff = 0;fff < N;fff++){
        int i = pl[fff].second;
        int h = pl[fff].first;
        ll a_in = st.getmax(0,i);
        a_in += a[i];
        st.update(i,a_in);
    }
    ll ans = st.getmax(0,N+1);
    cout<<ans<<endl;

    return 0;
}


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

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;

struct UnionFind {
    vector<ll> d;
    //親(負)…木のsize*(-1)
    //子(正)…親のindex

    UnionFind(ll n){
        d = vector<ll>(n,-1);        
    }
    //初期化

    ll find(ll x){
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    //親のindexを返す

    bool unite(ll x,ll y){
        x = find(x);
        y = find(y);

        if (x == y) return false;

        if (d[x] >d[y]) swap(x,y);

        d[x] += d[y];
        d[y] = x;

        return true;
    }
    //木と木を接続する

    bool same(ll x,ll y){
        return find(x) == find(y) ? true : false;
    }
    //xとyの親が同じか判定する

    ll size(ll x){
        return -d[find(x)];
    }
    //xが属する木のsizeを返す
};

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

    ll n,m;
    cin >> n >> m;

    UnionFind uf(n);

    rep(i,m){
        ll a,b;
        cin >> a >> b;
        a--;b--;

        uf.unite(a,b);
    }

    ll ans = 0;
    rep(i,n){
        ans = max(ans,uf.size(i));
    }

    cout << ans << endl;


}

Measured memory_bytes: 4760
;;(declaim (optimize (speed 0) (safety 3) (debug 3)))
#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))
(declaim (optimize (speed 3) (safety 0) (debug 0)))

(declaim (type (integer 2 200000) *worker-n*))
(defvar *worker-n* (read))

(declaim (type (simple-array fixnum (*)) *bosses*))
(defvar *bosses* (make-array (+ 1 *worker-n*)
			      :element-type 'fixnum))
(loop for i from 2 to *worker-n* do
      (setf (aref *bosses* i) (read)))

(declaim (type (simple-array fixnum (*)) *subs*))
(defvar *subs* (make-array (+ 1 *worker-n*)
			   :initial-element 0
			   :element-type 'fixnum))

(loop for i from *worker-n* downto 2 do
      (incf (aref *subs* (aref *bosses* i))))

(loop for i from 1 to *worker-n* do
      (format t "~a~%" (aref *subs* i)))


Measured memory_bytes: 78768
#include <iostream>

using namespace std;

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

    int index = 1;
    while (s > 4 || s == 3) {  // !(s == 1 || s == 2 || s == 4) と同値
        s = (s % 2 == 0 ? s / 2 : s * 3 + 1);
        ++index;
    }

    cout << index + 3 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000003;
const ll INF = 100000000000000000;
/* END OF TEMPLATE */

// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
// a^n mod を計算する
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

const int MAX = MOD+10;
// fac: n! %mod, finv: (1/n!) %mod, inv: 1/n %mod
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    COMinit();
    int q;
    cin >> q;
    vll x(q), d(q), n(q);
    rep(i, q){
        cin >> x[i] >> d[i] >> n[i];
    }
    rep(i, q){
        if(d[i] == 0){
            cout << modpow(x[i], n[i]) << "\n";
        }else{
            x[i] = x[i] * inv[d[i]] % MOD;
            if(x[i]/MOD == (x[i]+n[i]-1)/MOD && x[i]%MOD)
                cout << (fac[x[i]+n[i]-1]*finv[x[i]-1]%MOD)*modpow(d[i], n[i])%MOD << "\n";
            else
                cout << "0\n";
        }
    }
}

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

int main() {
  string s;
  int q;
  cin >> s >> q;
  deque<char> dq;
  for (int i = 0; i < s.size(); ++i) {
    dq.push_back(s[i]);
  }
  bool rev = false;
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      // reverse(s.begin(), s.end());
      rev = !rev;
    } else {
      int f;
      char c;
      cin >> f >> c;
      if (f == 1) {
        if (!rev) {
          // s = c + s;
          dq.push_front(c);
        } else {
          // s += c;
          dq.push_back(c);
        }
      } else {
        if (!rev) {
          // s += c;
          dq.push_back(c);
        } else {
          // s = c + s;
          dq.push_front(c);
        }
      }
    }
  }
  if (rev) {
    reverse(dq.begin(), dq.end());
  }
  for (int i = 0; i < dq.size(); ++i) {
    cout << dq[i];
  }
  cout << endl;
}


Measured memory_bytes: 896
N = int(input())
x = [None] * N
y = [None] * N
h = [None] * N

for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())    

def height(i, j, xn, yn, hn):
    return abs(j - xn) + abs(i - yn) + hn

def check(i, j, x, y, h, H):
    N = len(x)
    for n in range(N):
        if h[n] > 0:
            if height(i, j, x[n], y[n], h[n]) != H:
                return False
        else:
            if H - abs(j - x[n]) - abs(i - y[n]) > 0:
                return False
    return True


ok = False
for i in range(101):
    for j in range(101):
        for n in range(N):
            if h[n] > 0:
                H = height(i, j, x[n], y[n], h[n])
                ok = check(i, j, x, y, h, H)
                break
            if ok:
                break
        if ok:
            break
    if ok:
        break

print(j, i, H)

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int n=read();
	vi a;
	REP(i,3*n)a.PB(read());
	sort(ALL(a));
	int ans=0;
	REP(i,n)ans+=a[3*n-i*2-2];
	cout<<ans<<endl;
}


Measured memory_bytes: 6384
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define N 500005
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define int ll
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,a[N],l2;
bool cmp(int a,int b){
	return a>b;
}
signed main(){
	n=read();
	F(i,1,n) a[i]=read();
	sort(a+1,a+n+1,cmp);
	int l=1,r=n;
	while (l<r){
		int mid=(l+r+1)>>1;
		if (a[mid]>=mid) l=mid;
		else r=mid-1;
	}
	r=l;
	F(i,l+1,n){
		if (a[i]>=l) r=i;
		else break;
	}
	l2=a[l]-l;
	if (l2%2==1||(r-l)%2==1) puts("First");
	else puts("Second");
	return 0;
}

Measured memory_bytes: 1024
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<pair<int, int> > VPII;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	string s, t;
	cin >> s >> t;

	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());
	if (s < t) {
		O("Yes");
	}
	else
		O("No");

	return 0;
}

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

#define sz(x) static_cast<int>((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using ld = long double;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string inp;
	cin >> inp;
	int ans1 = -1, ans2 = -1;
	for(int i = 0; i + 1 < sz(inp); ++i) {
		if(inp[i] == inp[i + 1]) {
			ans1 = i + 1;
			ans2 = i + 2;
			break;
		}
	}
	if(ans1 == -1) {
		for(int i = 0; i < sz(inp) - 2; ++i) {
			if(inp[i] == inp[i + 2]) {
				ans1 = i + 1;
				ans2 = i + 3;
				break;
			}
		}
	}
	cout << ans1 << ' ' << ans2 << '\n';
	return 0;
}

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

using namespace std;

int main() {
	string str;
	cin >> str;
	int cnt=0;
	if (str[0] == '1')cnt++;
	if (str[1] == '1')cnt++;
	if (str[2] == '1')cnt++;

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
//最小全域木をプリム法で求める。
//計算量O(v^2) (vは頂点の数)

#include <bits/stdc++.h>
using namespace std;

#define MAX 105
#define INFTY 10000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

//Mは隣接行列
int n, M[MAX][MAX];

int prim(){
    int u, minv;
    int d[MAX], p[MAX], color[MAX];

    for(int i=1; i<=n; i++){
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    d[1] = 0;

    while(1){
        minv = INFTY;
        u = -1;
        for(int i=1; i<=n; i++){
            if(minv > d[i]  &&  color[i] != BLACK){
                u = i;
                minv = d[i];
            }
        }
        if(u == -1) break;
        color[u] = BLACK;
        for(int v=1; v<=n; v++){
            if(color[v] != BLACK  &&  M[u][v] != INFTY){
                if(d[v] > M[u][v]){
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }

    }


    int sum = 0;
    for(int i=1; i<=n; i++){
        if(p[i] != -1) sum += M[i][p[i]];
    }

    return sum;
}

int main(){
    cin >> n;

    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            int e;
            cin >> e;
            if(e == -1){
                M[i][j] = INFTY;
            }else{
                M[i][j] = e;
            }
        }
    }

    cout << prim() << endl;

    return 0;
}


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

constexpr int MAX_N = 502020;
constexpr int MAX_ROOT = 23000000;

// https://github.com/anh1l1ator/Spoj/blob/master/Desktop/Codes/DQUERY_Online.cpp
struct Node {
    int cnt, L, R;
    Node() {
        cnt = 0;
        L = R = -1;
    }
    Node(int x, int y, int z) { L = x, R = y, cnt = z; }
} tree[MAX_ROOT];

class DistinctElements {
    int gc = 0, N;
    vector<int> rt;

    int build(int L, int R) {
        gc++;
        if (L == R) return gc;
        int x = gc;
        tree[x] = Node(build(L, (L + R) / 2), build((L + R) / 2 + 1, R), 0);
        return x;
    }

    int update(int L, int R, int root, int idx, int val) {
        assert(root < MAX_ROOT);
        if (L > idx || R < idx) {
            return root;
        }
        gc++;
        if (L == idx && R == idx) {
            tree[gc] = Node(-1, -1, tree[root].cnt + val);
            return gc;
        }
        int x = gc;
        tree[x] = Node(update(L, (L + R) / 2, tree[root].L, idx, val),
                       update((L + R) / 2 + 1, R, tree[root].R, idx, val), tree[root].cnt + val);
        return x;
    }

    int query(int L, int R, int root, int ql, int qr) {
        if (qr < L || ql > R) return 0;
        if (ql <= L && R <= qr) {
            return tree[root].cnt;
        }
        return query(L, (L + R) / 2, tree[root].L, ql, qr) + query((L + R) / 2 + 1, R, tree[root].R, ql, qr);
    }

    int query1idx(int l, int r) { return query(1, N, rt[r], l, r); }

public:
    DistinctElements(const vector<int>& as) {
        N = as.size();
        rt = vector<int>(MAX_N);
        vector<int> G(1 << 20, -1);
        rt[0] = build(1, N);
        for (int i = 1; i <= N; i++) {
            int p = rt[i - 1];
            if (G[as[i - 1]] != -1) {
                p = update(1, N, p, G[as[i - 1]], -1);
            }
            rt[i] = update(1, N, p, i, 1);
            G[as[i - 1]] = i;
        }
    }

    int query(int l, int r) { return query1idx(l + 1, r); }
};

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

    int n, q;
    cin >> n >> q;
    vector<int> cs(n);
    for (int i = 0; i < n; i++) cin >> cs[i];
    DistinctElements hoge(cs);
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        cout << hoge.query(l, r) << '\n';
    }
}


Measured memory_bytes: 280664
#include<stdio.h>
#include<stdlib.h>
void f_post(int *,int *,int,int,int,int*);
void post(int *,int *,int,int,int,int*);
int main(){
  int i,n,count=0;
  int *pre,*in;

  scanf("%d",&n);
  pre = malloc(sizeof(int)*n);
  in = malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&pre[i]);
  for(i=0;i<n;i++) scanf("%d",&in[i]);
  f_post(pre,in,0,n,n,&count);
  free(pre);
  free(in);
  return 0;
}
void f_post(int *pre,int *in,int l,int r,int n,int *count){
  int i,j,m,num;
  if(l>=r)return;
  num = pre[(*count)++];
  for(i=0;i<n;i++){
    if(num == in[i])break;
  }
  post(pre,in,l,i,n,count);
  post(pre,in,i+1,r,n,count);
  printf("%d\n",num);
}
void post(int *pre,int *in,int l,int r,int n,int *count){
  int i,j,m,num;
  if(l>=r)return;
  num = pre[(*count)++];
  for(i=0;i<n;i++){
    if(num == in[i])break;
  }
  post(pre,in,l,i,n,count);
  post(pre,in,i+1,r,n,count);
  printf("%d ",num);
}
       
  
  



Measured memory_bytes: 2140
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
using namespace std;


#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef pair<int, int> Edge;



int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b >= c*a) {
		cout << c << endl;
	}
	else {
		cout << b / a << endl;
	}
}


Measured memory_bytes: 256
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:input()

"""========main code==============="""
t=1
#t=ii()
for _ in range(t):
    n,m,k=ml()
    print(k*(math.ceil(n/m)))

Measured memory_bytes: 65128
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
#define ll long long
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> //lower_bound , upper_bound
// using namespace __gnu_pbds;//kth smallest : *pd.find_by_order(k-1) , no. of elem < X : pd.order_of_key(X) , delete X : pd.erase(X).
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl '\n'
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod=(1e+9)+7;
const ll sz = 2e5+9;
ll gcd(ll a,ll b) {if(b==0)return a;return gcd(b,a%b);}
ll power(ll a,ll b,ll m = mod) {ll res = 1;while(b>0){if(b&1)res = (res*a)%m;b = b>>1;a = (a*a)%m;}return res;}

void solve()
{
    ll tt=1,n;
    //cin>>tt;
    while(tt--)
    {
   ll cap;
        cin>>n>>cap;
        vector <ll> wt(n),val(n);
        f(i,0,n){ cin>>wt[i]>>val[i]; }
        ll ans[n+1][cap+1];
        
        f(i,0,n+1)
        {
            f(w,0,cap+1)
            {
                if (i==0 || w==0) 
               ans[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 ans[i][w] = max(val[i-1] + ans[i-1][w-wt[i-1]],  ans[i-1][w]); 
           else
                 ans[i][w] = ans[i-1][w]; 
            }
        }
        cout<<ans[n][cap]<<nl;
    
    }
    
}
 
int main()
{
    #ifdef JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    clock_t beg = clock();
    solve();
    clock_t end = clock();
    fprintf(stderr, "%.3f sec, Copyright %c 2019 PyThor. \n", double(end - beg) / CLOCKS_PER_SEC , 184);
    return 0;
}


Measured memory_bytes: 79232
#include "bits/stdc++.h"
#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<< endl
#define p2(a, b) cout<<(a) << " " << (b) << endl
using namespace std;
typedef long long ll;

string s;
ll idx;
ll dfs(){
	vector<ll> vt;
	while(s[idx] != ']' && idx < s.size()){
		if(isdigit(s[idx])){
			ll num = 0;
			while(isdigit(s[idx])){
				num = 10*num + (s[idx++] - '0');
			}
			vt.push_back(num / 2 + 1);
		}else{
			idx++;
			ll tmp = dfs();
			vt.push_back(tmp);
		}
	}
	sort(vt.begin(), vt.end());
	ll ret = 0;
	REP(i,0,vt.size()/2+1){
		ret += vt[i];
	}
	idx++;
	return ret;
}

int main() {
	ll n;
	cin >> n;
	REP(i,0,n){
		cin >> s;
		idx = 0;
		p(dfs());
	}
	return 0;
}


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


int main(){
    int n;
    int a[200001];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    long long  ans=0;
    int s=0;
    int j=0;
    for(int i=0;i<n;i++){
        while(j!=n && ((s & a[j])==0) ){
                        s+=a[j];
            j++;
        }
        ans+=(j-i);
        s-=a[i];
    }
    cout<<ans;
    return 0;
}

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

enum SegtreeType{
	CUSTOM,
	RAQ_RMQ,
	RAQ_RSQ,
	RUQ_RMQ,
	RUQ_RSQ,
};
template<SegtreeType ty,class T>
class LazySegtree{
	int n;
	vector<T>dat,lazy;
	T INIT;
	T E0,E1;
	function<T(T,T,int)>F0;
	function<T(T,T)>F1,F2;
public:
	LazySegtree(int n_,T INIT,T E0,T E1
	,function<T(T,T,int)>F0,function<T(T,T)>F1,function<T(T,T)>F2):
		INIT(INIT),E0(E0),E1(E1),F0(F0),F1(F1),F2(F2){
		n=1;while(n<n_)n<<=1;
		dat=lazy=vector<T>(2*n);
		for(int i=0;i<2*n-1;i++){
			dat[i]=INIT;
			lazy[i]=E1;
		}
	}
	LazySegtree(int n_){
		switch(ty){
		case RAQ_RMQ:
			INIT=0;
			E0=numeric_limits<T>::max();
			E1=0;
			F0=[](T a,T b,int s){return a+b;};
			F1=[](T a,T b){return a+b;};
			F2=[](T a,T b){return min(a,b);};
			break;
		case RAQ_RSQ:
			INIT=0;
			E0=0;
			E1=0;
			F0=[](T a,T b,int s){return a+b*s;};
			F1=[](T a,T b){return a+b;};
			F2=[](T a,T b){return a+b;};
			break;
		}
		n=1;while(n<n_)n<<=1;
		dat=lazy=vector<T>(2*n);
		for(int i=0;i<2*n-1;i++){
			dat[i]=INIT;
			lazy[i]=E1;
		}
	}
	inline void push(int k,int s){
		if(lazy[k]==E1)return;
		dat[k]=F0(dat[k],lazy[k],s);
		if(k<n-1){
			lazy[k*2+1]=F1(lazy[k*2+1],lazy[k]);
			lazy[k*2+2]=F1(lazy[k*2+2],lazy[k]);
		}
		lazy[k]=E1;
	}
	inline void upnode(int k){
		dat[k]=F2(dat[k*2+1],dat[k*2+2]);
	}
	inline void update(int a,int b,T x,int k,int l,int r){
		push(k,r-l);
		if(r<=a||b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]=F1(lazy[k],x);
			push(k,r-l);
			return;
		}
		update(a,b,x,k*2+1,l,(l+r)/2);
		update(a,b,x,k*2+2,(l+r)/2,r);
		upnode(k);
	}
	inline T query(int a,int b,int k,int l,int r){
		push(k,r-l);
		if(b<=l||r<=a)return E0;
		if(a<=l&&r<=b)return dat[k];
		T lb=query(a,b,k*2+1,l,(l+r)/2);
		T rb=query(a,b,k*2+2,(l+r)/2,r);
		upnode(k);
		return F2(lb,rb);
	}
	inline void update(int a,int b,T x){
		update(a,b,x,0,0,n);
	}
	inline void update(int a,T x){
		update(a,a+1,x);
	}
	inline T query(int a,int b){
		return query(a,b,0,0,n);
	}
	inline T query(int a){
		return query(a,a+1);
	}
};

int main(){
	int n,q;cin>>n>>q;
	LazySegtree<RAQ_RSQ,ll>seg(n);
	rep(i,q){
		int ty;scanf("%d",&ty);
		if(ty==0){
			int l,r,x;scanf("%d%d%d",&l,&r,&x);l--;
			seg.update(l,r,x);
		}
		else{
			int l,r;scanf("%d%d",&l,&r);l--;
			printf("%lld\n",seg.query(l,r));
		}
	}
}


Measured memory_bytes: 7128
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main(){
	string x, y;
	cin >> x >> y;
	if (x < y) {
		cout << "<";
	}
	else if (x == y) {
		cout << "=";
	}
	else cout << ">";
}


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

int main(){
    int N,K;
    cin >> N >> K;
    double score_be = 1;
    double score_af = 1;

    vector<int> A(N+1);

    A[0] = 1;

    for(int i=1;i<=N;i++){
        cin >> A[i];
    }
    for(int i=K+1;i<=N;i++){
        if(A[i] > A[i-K]){
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4044