akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	X := readInt()
	Y := readInt()
	A := readInt()
	B := readInt()
	C := readInt()

	p := make([]int, A+1)
	q := make([]int, B+1)
	r := make([]int, C+1)

	for i := 0; i < A; i++ {
		p[i+1] = readInt()
	}
	for i := 0; i < B; i++ {
		q[i+1] = readInt()
	}
	for i := 0; i < C; i++ {
		r[i+1] = readInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(p[1:])))
	sort.Sort(sort.Reverse(sort.IntSlice(q[1:])))
	sort.Sort(sort.Reverse(sort.IntSlice(r[1:])))

	for i := 1; i < A; i++ {
		p[i+1] += p[i]
	}
	for i := 1; i < B; i++ {
		q[i+1] += q[i]
	}
	for i := 1; i < C; i++ {
		r[i+1] += r[i]
	}

	result := 0
	for i := max(0, X-C); i <= X; i++ {
		ok := max(0, Y-(C-(X-i))) - 1
		ng := Y
		for ng-ok != 1 {
			m := ok + (ng-ok)/2
			t0 := q[m] + r[(X-i)+(Y-m)]
			t1 := q[m+1] + r[(X-i)+(Y-(m+1))]
			if t0 < t1 {
				ok = m
			} else {
				ng = m
			}
		}
		j := ok + 1
		result = max(result, p[i]+q[j]+r[(X-i)+(Y-j)])
	}

	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 8812
from collections import *

def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

N = int(input())
edges = [[] for i in range(N)]
edge_id = defaultdict(lambda : -1)
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    edges[a].append(b)
    edges[b].append(a)
    edge_id[(a, b)] = edge_id[(b, a)] = i
path = defaultdict(lambda : -1)

def set_path(r, v, path_):
    visited[v] = 1
    path[(r, v)] = path_
    for u in edges[v]:
        if visited[u] == 0:
            set_path(r, u, path_ | (1 << edge_id[(v, u)]))

for i in range(N):
    visited = [0] * N
    set_path(i, i, 0)
M = int(input())
uv = [list(map(lambda x: int(x)-1, input().split())) for i in range(M)]
ans = pow(2, N-1)
for i in range(1, 1 << M):
    all_path = 0
    for j, (u, v) in enumerate(uv):
        if i & (1 << j):
            all_path |= path[(u, v)]
    if popcnt(i) & 1:
        ans -= pow(2, N-1-popcnt(all_path))
    else:
        ans += pow(2, N-1-popcnt(all_path))
print(ans)


Measured memory_bytes: 48360
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

   // 最小値を探索するときはv_minの初期値をINT_MAXにして,
   // 更新前後の最小値同士を比較して更新していく
   int v_min = INF;
   for(int i = 0; i < (int)s.size() -2; i++)
   {
      // stoi(string)でstring -> intへ
      // substr(切り出し開始位置, 切り出し開始位置+切り出す文字数i)
      int v = abs(stoi(s.substr(i, 3)) - 753);
      v_min = min(v,v_min);
   }
   cout << v_min << endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int A,B;
  cin >> A>>B;

  if(1<=A && A<=9 && 1<=B && B<=9) cout << A*B << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, FN) for(int i = 0; i < ( FN ); i++)

int main() {
    int N;
    cin >> N;
    int d[4];
    FOR(i, 4){
        d[i] = N % 10;
        N /= 10;
    }
    int ans[3];
    FOR(op, 8){
        int hoge = op;
        FOR(i, 3){
            ans[i] = hoge & 0b001;
            hoge >>= 1;
        }
        int sum = d[3];
        for(int i = 2; i >= 0; i--) {
            if(ans[i] == 0) sum += d[i];
            else sum -= d[i];
        }
        if(sum == 7) {
            break;
        }
    }
    cout << d[3];
    FOR(i, 3){
        if(ans[2 - i] == 0) cout << "+" << d[2 - i];
        else cout << "-" << d[2 - i];
    }
    cout << "=" << 7 << endl;

    return 0;
}


Measured memory_bytes: 256
local n = io.read("*n")
io.read("*l")
local arr
do
  local _accum_0 = { }
  local _len_0 = 1
  for e in io.read("*l"):gmatch("%d+") do
    _accum_0[_len_0] = tonumber(e)
    _len_0 = _len_0 + 1
  end
  arr = _accum_0
end
table.sort(arr, function(a, b)
  return a > b
end)
local r = 0
local t = 1
for _index_0 = 1, #arr do
  local e = arr[_index_0]
  r = r + (t * e)
  t = -t
end
return print(r)

Measured memory_bytes: 384
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int N = nextInt();
			if (N == 0) {
				break;
			}
			int M = nextInt();
			ArrayList<Edge> list = new ArrayList<Edge>();

			for (int i = 0; i < M; i++) {
				int a = nextInt() - 1;
				int b = nextInt() - 1;
				int w = nextInt();
				list.add(new Edge(w, a, b));
			}
			Collections.sort(list);

			int ans = Integer.MAX_VALUE;
			for (int i = 0; i < list.size(); i++) {
				// 道iのコストより大きい物だけを使って最小全域木を作ってみる
				if (i > 0 && list.get(i).weight == list.get(i - 1).weight) {
					continue;
				}

				PriorityQueue<Edge> priorityQueue = new PriorityQueue<Edge>();
				for (int j = i; j < list.size(); j++) {
					priorityQueue.add(new Edge(list.get(j).weight, list.get(j).from, list.get(j).to));
				}

				UnionFind uf = new UnionFind(N);
				int max = 0;// 最大コストを調べておく
				while (!priorityQueue.isEmpty()) {
					Edge e = priorityQueue.poll();
					if (!uf.isSame(e.from, e.to)) {
						max = Math.max(max, e.weight);
						uf.unite(e.from, e.to);
					}
				}

				// 全域木になっているかチェック
				boolean allSame = true;
				for (int j = 1; j < N; j++) {
					if (!uf.isSame(0, j)) {
						allSame = false;
						break;
					}
				}

				// 全域木なら解答を更新
				if (allSame) {
					ans = Math.min(ans, max - list.get(i).weight);
				} else {
					break;
				}
			}

			if (ans == Integer.MAX_VALUE) {
				System.out.println(-1);
			} else {
				System.out.println(ans);
			}
		}
	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}
}

class UnionFind {
	int[] parts;

	UnionFind(int n) {
		parts = new int[n];
		for (int i = 0; i < n; i++)
			parts[i] = i;
	}

	public int find(int x) {
		if (parts[x] == x)
			return x;
		return parts[x] = find(parts[x]);
	}

	public Boolean isSame(int x, int y) {
		return find(x) == find(y);
	}

	public void unite(int x, int y) {
		if (find(x) == find(y))
			return;
		parts[find(x)] = find(y);
	}
}

class Edge implements Comparable<Edge> {
	int weight;
	int from, to;

	Edge(int w, int f, int t) {
		this.weight = w;
		this.from = f;
		this.to = t;
	}

	@Override
	public int compareTo(Edge edge) {
		// 昇順
		return this.weight - edge.weight;
	}
}

Measured memory_bytes: 164060
import java.io.BufferedInputStream
import java.util.StringTokenizer

class FastScanner(){
    private val reader = BufferedInputStream(System.`in`).bufferedReader()
    private var st: StringTokenizer? = null
    fun next(): String {
        while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
        return st!!.nextToken()
    }
    fun hasNext(): Boolean {
        while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine() ?: return false)
        return true
    }
}

const val YES = "Yes"
const val NO = "No"

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    fun iterateTokens(): Iterator<String> {
        val reader = BufferedInputStream(System.`in`).bufferedReader()
        return reader.use{ it.readText() }.splitToSequence(" ", "\n").iterator()
    }
    val tokens = FastScanner()
    val N = tokens.next().toLong()
    val A = LongArray(N.toInt())
    val B = LongArray(N.toInt())
    for(i in 0 until N.toInt()){
        A[i] = tokens.next().toLong()
        B[i] = tokens.next().toLong()
    }
    solve(N, A, B)
}

fun solve(N: Long, A: LongArray, B: LongArray){
    val n = N.toInt()
    val ab = Array<Pair<Long, Long>>(n){
            A[it] to B[it]
        }.sortedBy{ it.second }
    var time = 0L
    for ( i in 0 until n){
        time += ab[i].first
        if (time > ab[i].second){
            println(NO)
            return
        }
    }
    println(YES)
    return
}



Measured memory_bytes: 132728
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int N;string s;


int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(NULL);

  cin>>N;cin>>s;
  int i = 0, j = N-1, ans = 0;
  while(i < j) {
    if(s[i] == 'R') {i++;continue;}
    if(s[j] == 'W') {j--;continue;}
    ans++;
    i++;j--;
  }
  cout<<ans;







 return 0;
}


Measured memory_bytes: 3756
import java.util.Scanner;

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

        String S = sc.next();

        System.out.println(solve(S));

        sc.close();
    }

    static int solve(String S) {
        return 700 + S.replace("x", "").length() * 100;
    }
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main() {
	int n, m, k, ans = 0, a;
	cin >> n >> m;
	int like[m] = {0};
	for (int i = 0; i < n; i++) {
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> a;
			like[a - 1]++;
		}
	}
	for (int i = 0; i < m; i++) {
		if (like[i]== n) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    
    int r,g,b;
    cin>>r>>g>>b;
    string ans="NO";
    if((r*100+g*10+b)%4==0)ans="YES";
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int h, w;
    
    while(1){
        cin >> h >> w;
        if(h == 0 && w == 0)
            break;
        else{
            for(int i=0; i < h; i++){
                cout << "#";
                if(i == 0 || i == h-1){
                    for(int j=1; j < w-1; j++){
                        cout << "#";
                    }
                }
                else{
                    for(int j=1; j < w-1; j++){
                        cout << ".";
                    }
                }
                cout << "#" << endl;
            }
            cout << endl;
        }
    }
    
    return 0;
}



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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vvi             vector<vi>
#define vb              vector<bool>
#define vvb             vector<vb>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
  //c_p_c();
  int k;  cin >> k;
  int n = 0;
  if(k%2==0)
  {
    cout<<"-1";
    return 0;
  }
  for (int i = 0; i < pow(10, 6); i++)
  {
    n = (n * 10 + 7) % k;
    if (n == 0)
    {
      cout << i+1;
      break;
    }
  }
  if (n != 0)
    cout << "-1";
  return 0;
}


Measured memory_bytes: 3640
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
Vlist = [int(c) for c in input().split()]
Clist = [int(c) for c in input().split()]
plus = []
for i in range(N):
    a = Vlist[i]-Clist[i]
    plus.append(a)

ans =0
for i in plus:
    if i >= 0:
        ans += i

print(ans)

Measured memory_bytes: 3064
a,b,c = map(int,input().split())

if a <= b and b <= c:
    print(a,b,c,sep=' ')
elif a <= c and c <= b:
    print(a,c,b,sep=' ')
elif b <= a and a <= c:
    print(b,a,c,sep=' ')
elif b <= c and c <= a:
    print(b,c,a,sep=' ')
elif c <= a and a <= b:
    print(c,a,b,sep=' ')
elif c <= b and b <= a:
    print(c,b,a,sep=' ')


Measured memory_bytes: 5596
package main

import "fmt"

type plan struct {
	T int
	X int
	Y int
}

func main() {
	n := 0
	fmt.Scan(&n)

	plans := make([]plan, n)
	for i := range plans {
		fmt.Scan(&plans[i].T, &plans[i].X, &plans[i].Y)
	}

	for _, p := range plans {
		if p.T%2 != (p.X+p.Y)%2 || p.T < (p.X+p.Y) {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 5760
n = int(input())
a = list(map(int, input().split()))
a.insert(0,0)
a.append(0)
lis = [abs(0 - a[0])]
for i in range(n+1):
    lis.append(lis[i] + abs(a[i] - a[i+1]))
# print(lis)
# print(a)

for i in range(1,n+1):
    print(lis[i-1] + abs(a[i-1]-a[i+1]) + (lis[-1] - lis[i+1]))

Measured memory_bytes: 13920
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int a, b;
    while(std::cin >> a >> b)
    {
    if(a == 0 && b == 0)
    {
        continue;
    }
    else
    {
    cout << min(a,b) << ' ' << max(a,b) << endl;
    }
    }
}


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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  int ans=1000;
  for(int i=0;i<N-2;i++){
    int n=100*(S.at(i)-'0')+10*(S.at(i+1)-'0')+(S.at(i+2)-'0');
    n=n-753;
    if(n<0){
      n=-n;
    }
    ans=min(ans,n);
  }
  cout<<ans<<endl;
}


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

int main()
{
	string s;
	cin >> s;
	int a = s[0]-48;
	int b = s[1]-48;
	int c = s[2]-48;
	int d = s[3]-48;
	char x,y,z;
	int ans = 0;
	if (a+b+c+d == 7)
	{
		cout << a << "+"<< b << "+" << c << "+" << d << "=7";
		return 0;
	}
	else
	{
		if (a + b + c - d == 7)
		{
			x = '+'; y = '+'; z = '-';
		}
		if (a + b - c + d == 7)
		{
			x = '+'; y = '-'; z = '+';
		}
		if (a - b + c - d == 7)
		{
			x = '-'; y = '+'; z = '-';
		}
		if (a - b + c + d == 7)
		{
			x = '-'; y = '+'; z = '+';
		}
		if (a - b - c + d == 7)
		{
			x = '-'; y = '-'; z = '+';
		}
		if (a + b - c - d == 7)
		{
			x = '+'; y = '-'; z = '-';
		}
		if (a - b - c - d == 7)
		{
			x = '-'; y = '-'; z = '-';
		}
		cout << a << x << b << y << c << z << d << "=7";
	}
	return (0);
}



Measured memory_bytes: 256
def solve(string):
    n = int(string)

    def f(n):
        return n * (n + 1) // 2

    return str(f(n) - 3 * f(n // 3) - 5 * f(n // 5) + 15 * f(n // 15))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 9096
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np
N,M = map(int, input().split())

counter = np.zeros(N+1)
for m in range(M):
    a, b = map(int, input().split())
    counter[a] += 1
    counter[b] -= 1

cnt = 0
succ = True
for n in range(N+1):
    cnt += counter[n]
    if cnt % 2:
        succ = False
        break
if succ:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 22532
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K, A[5005];

int main(){
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; i++) scanf("%d", A + i);
  sort(A, A + N);

  int sum = 0, ans = N;
  for (int i = N - 1; i >= 0; i--){
    if (sum + A[i] < K) sum += A[i];
    else ans = min(ans, i);
  }
  printf("%d\n", ans);

  return 0;
}


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

int main(void) {
    string S;
    cin >> S;
    char character[2];
    int count[2] = {1, 0};
    character[0] = S[0];
    bool flag = true;
    for (int i = 1; i < 4; i++) {
        if (S[i] == character[0]) {
            ++count[0];
        } else if (count[1] == 0) {
            ++count[1];
            character[1] = S[i];
        } else if (S[i] == character[1]) {
            ++count[1];
        } else {
            flag = false;
            break;
        }
    }
    if (count[0] != 2 || count[1] != 2) {
        flag = false;
    }
    printf("%s\n", (flag ? "Yes" : "No"));
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N = int(input())

if N % 2 == 1:
    print(0)
else:
    i = 1
    ans = 0
    while N > 0:
        N = N // 5
        ans += N // 2
    print(ans)

Measured memory_bytes: 77428
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> V;
  for(int i = 0; i < N; ++i){
    int a, b;
    cin >> a >> b;
    V.emplace_back(b,a);
  }
  sort(V.begin(), V.end());
  long long t = 0;
  for(int i = 0; i < N; ++i){
    t += V[i].second;
    if(t > V[i].first){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

int main() {
  int n, i, a, high = -1, low = 1001;
  cin >> n;
  
  for(i = 0; i < n; i++){
    cin >> a;
    high = max(high, a);
    low = min(low, a);
  }
  
  cout << high - low << endl;
}


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

int main(){
    string S;
    cin>>S;
    bool flag = true;
    if(S.size()%2==1){
        flag = false;
    }else{
        for(int i=0;i<S.size()-1;i++){
            if(S.at(i)=='h'&&S.at(i+1)=='i'){
                i++;
            }else{
                flag = false;
                break;
            }
        }
    }
    
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

using namespace std;

int main(){

	int n, fi=0, se=0, mar;
	vector<int> v;

	cin>> n;
	v.resize(n);
	for(int i=0;i<n;i++){
		cin>> v[i];
		if(fi<=v[i]){
			se=fi;
			fi=v[i];
		}else if(se<=v[i]){
			se=v[i];
		}
	}

	if(se==0 || fi==se){
		for(int i=0;i<n;i++){
			cout<< fi <<endl;
		}
		return 0;
	}

	for(int i=0;i<n;i++){
		if(v[i]==fi) mar=i;
	}

	for(int i=0;i<n;i++){
		if(i!=mar) cout<< fi <<endl;
		else cout<< se << endl;
	}

}

Measured memory_bytes: 2432
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto hw = readln.split.to!(int[]);
    auto H = hw[0];
    auto CS = new long[][](10, 10);
    foreach (i; 0..10) {
        foreach (j, c; readln.split.to!(long[])) CS[i][j] = c;
    }

    foreach (k; 0..10) {
        foreach (i; 0..10) {
            foreach (j; 0..10) {
                if (CS[i][j] > CS[i][k] + CS[k][j]) {
                    CS[i][j] = CS[i][k] + CS[k][j];
                }
            }
        }
    }

    long r;
    foreach (_; 0..H) {
        foreach (n; readln.split.to!(int[])) if (n != -1) {
            r += CS[n][1];
        }
    }
    writeln(r);
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }


int N, K;
int fact[100010], finv[100010];


int extGCD(int a, int b, int &x, int &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    int d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}


void makeFact(int n){
    fact[0] = 1;
    repe(i, 1, n) fact[i] = MUL(i, fact[i-1]);
    extGCD(fact[n], MOD, finv[n], finv[0]);
    finv[0] = 1;
    repr(i, n, 1) finv[i] = MUL(i+1, finv[i+1]);
}


int comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return MUL(fact[n], MUL(finv[k], finv[n-k]));
}


signed main(){
    cin >> N >> K;
    makeFact(N);

    repe(i, 1, K) cout << MUL(comb(N-K+1, i), comb(K-i+i-1, i-1)) << endl;

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = IntArray(n + 1)
    repeat(n) {
        a[it + 1] = readLine()!!.toInt()
    }

    val visited = IntArray(n + 1) { -1 }
    visited[1] = 0

    var cur = 1
    while (true) {
        val next = a[cur]
        if (visited[next] != -1) break
        visited[next] = visited[cur] + 1
        cur = next
    }

    println(visited[2])
}


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

int main() 
{
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		int b = 1000 - a;
		int c = 0;
		c += b / 500;
		b -= b / 500 * 500;
		c += b / 100;
		b -= b / 100 * 100;
		c += b / 50;
		b -= b / 50 * 50;
		c += b / 10;
		b -= b / 10 * 10;
		c += b / 5;
		b -= b / 5 * 5;
		c += b;
		cout << c << endl;
	}
}

Measured memory_bytes: 3100
# 各桁毎に３５７の取り得る総数

# 各桁に３or５or７を割り当てて全列挙
# 桁数が３以上Nの桁数以下且つ
# 値がN以下且つ
# array.uniq.sizeが３以上
# の値が条件を満たす。
# その総数

N = gets.chomp

@count = 0
def dfs(arr = [])
  if arr.size >= 3
    if (num = arr.join('').to_i) <= N.to_i && arr.uniq.size >= 3
      # puts num
      @count += 1
    end
  end
  return if arr.size == N.size
  3.times do |i|
    dfs(arr.dup << 3 + 2 * i)
  end
end

dfs
puts @count

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define INF (int)1e9+1
#define INFLL (int)1e18+1
#define sz(bb) (int)bb.size()
#define all(qq) qq.begin(), qq.end() 
#define Max(a, b, c) max(a, max(b, c))
#define Min(a, b, c) min(a, min(b, c))
const double PI=acos(-1);
// #define int unsigned long long int//used when x<=2^64-1 && x>0
#define int long long//used when x<=2^63-1
//bool cmp if returns true it keeps 1st as first else swaps
typedef long long  ll;

void solve()
{
    int n, k;
    cin>>n>>k;
    int arr[n];
    int mn=INF;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        mn=min(mn, arr[i]);
    }
    int dp[k+1];
    for(int i=1;i<mn;i++)
        dp[i]=1;
    dp[0]=1;
    for(int i=mn;i<=k;i++)
    {
        dp[i]=-1;
        for(int j=0;j<n;j++)
        {
            if(arr[j]>i)
                continue;
            int cur=1^(dp[i-arr[j]]);
            if(cur==0)
                dp[i]=0;
        }
        if(dp[i]==-1)
            dp[i]=1;
    }
    if(dp[k]==0)
        cout<<"First\n";
    else
        cout<<"Second\n";
}
int32_t main()
{
    IOS;
    int t;
    // cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("F:/cpp/input.txt", "r", stdin);
    freopen("F:/cpp/output.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    ll a[n], i, pos = 1, q, r, ans, x = 0;
    for (i=0;i<n;i++)
    cin >> a[i];
    vector <ll> v;
    unordered_map <ll, ll> mp;
    while (mp.find(pos) == mp.end())
    {
        v.push_back(pos);
        mp[pos] = x++;
        pos = a[pos-1];
    }
    q = mp[pos];
    if (k < v.size())
    cout << v[k];
    else
    {
        k -= q;
        r = k%(v.size() - q);
        cout << v[q+r];
    }
    return 0;
}

Measured memory_bytes: 14432
#include <bits/stdc++.h>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;using std::queue;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;using std::swap;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::vector<int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}

namespace ndifix{
template<class T> void sort(T &v){std::sort(v.begin(),v.end());}
template<class T> void rsort(T &v){std::sort(v.rbegin(),v.rend());}
}

int main(){
  int n,d;cin>>n>>d;
  vector<vector<int>> x(n);
  for(int i=0;i<n;i++){
    x[i].resize(d);
    for(int j=0;j<d;j++)cin>>x[i][j];
  }
  int dis;
  int ans=0;
  int buf;
  for(int i=0;i<n;i++){
  for(int j=i+1;j<n;j++){
    dis=0;
    for(int k=0;k<d;k++)dis+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
    buf=std::sqrt(dis);
    if(buf*buf==dis)ans++;
  }}
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
ans="No"

#文字が全部0
if all(a==0 for a in A):
  ans="Yes"

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    ans="Yes"

#abc,abc...,abcという並びに出来て互いに排他的論理和
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if AA[0]^AA[third]==AA[2*third] and \
    AA[third]^AA[2*third]==AA[0] and \
    AA[2*third]^AA[0]==AA[third]:
      ans="Yes"   
print(ans)

Measured memory_bytes: 14460
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,ans=0;
    vector<int>v[200010];
    cin>>n;
    for(int i=1;i<=n;i++)ans+=i*(n-i+1);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--,b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    rep(i,n){
        for(int j:v[i]){
            if(j<i){
                ans-=(j+1)*(n-i);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

// 1 <= ans <= s <= 100

int main() {
  string s, ans;
  cin >> s >> ans;
  vector<char> moji(s.size());
  for (int i=0; i<s.size(); i++) {
    moji.at(i) = s.at(i);
  }
  
  for (int i=0; i<s.size(); i++) {
    char c = moji.at(0);
    moji.erase(moji.begin());
    moji.push_back(c);
    for (int j=0; j<ans.size(); j++) {
      if(ans.at(j) != moji.at(j)) break;
      if(ans.at(j) == moji.at(j) && j+1 == ans.size()) {
        cout << "Yes" << endl;
        goto SKIP;
      }
    }
  }
  cout << "No" << endl;
  SKIP:
  return 0;
}


Measured memory_bytes: 3236
#https://atcoder.jp/contests/abc152/submissions/9607915

N = int(input())
lis = [[0]*10 for _ in range(10)]

for i in range(1,N+1):
    s = str(i)
    lis[int(s[0])][int(s[-1])] += 1

ans = 0
#A,Bになりうる数字の数をカウントして掛け算
for i in range(10):
    for j in range(10):
        ans += lis[i][j]*lis[j][i]
print(ans)

Measured memory_bytes: 3064
/// a.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < ll >
# define pb push_back
# define pdd pair < db , db >
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    static int s[1 << 20];
    IOS;
    fi>>n;
    for (int i = 1;i <= n * 3;++i)
        fi>>s[i];
    sort(s + 1,s + 1 + (3 * n));
    ll ans = 0;
    int cnt = 3 * n + 1;
    for (int i = 1;i <= n;++i)
        ans += s[cnt -= 2];
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


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

using namespace std;

void Main() {
    long long N;
    cin >> N;
    map<long long, long long> bars;
    for (long long i = 0; i < N; ++i) {
        long long A;
        cin >> A;
        if (bars.count(A) == 0) {
            bars.insert(make_pair(A, 0));
        }
        ++bars[A];
    }

    long long longLength = 0;
    long long shortLength = 0;
    for (map<long long, long long>::const_reverse_iterator rit = bars.rbegin(); rit != bars.rend(); ++rit) {
        long long n = rit->second;
        long long length = rit->first;
        if (n >= 4 && longLength == 0) {
            longLength = length;
            shortLength = length;
            break;
        }
        if (n >= 2) {
            if (longLength == 0) {
                longLength = length;
                continue;
            }
            else if (shortLength == 0) {
                shortLength = length;
                break;
            }
        }
    }
    long long s = longLength * shortLength;
    cout << s << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 9736
X=int(input())

bai100=X//100
hasuu=X%100

parts=0
plus=5

while hasuu>0:
    
  while hasuu>0:
    parts+=hasuu//plus
    hasuu%=plus
    plus-=1
    
    if plus==0:
      break

print((parts<=bai100)*1)
  

Measured memory_bytes: 2940
use std::collections::HashSet;
fn main() {
    // loop{ //For test
        solve();
    // }
}

#[allow(dead_code)]
fn solve(){
    let mut n: i64 = read();
    let mut a: Vec<i64> = read_vec();
    let uniq: HashSet<i64> = a.clone().into_iter().collect();
    if a.len() == uniq.len()  {
        println!("YES");
    } else{
        println!("NO");
    }
}

fn is_even(arr: &Vec<i32>) -> bool {
    return arr.iter().all(|x| x%2==0);
}

/// 標準入力から一行を読み取り、指定の型に変換する関数
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    let _ = std::io::stdin().read_line(&mut s);
    s.trim().parse().ok().unwrap()
}

/// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

/// 標準入力からn行を読み取り、各行を空白文字で分割し、各要素を指定の型に変換する関数
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}


Measured memory_bytes: 11440
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  int P[N];
  ll where[N];
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> P[i];
    P[i]--;
    where[P[i]] = i;
  }
  set<int> Set;
  Set.insert(-1);
  Set.insert(N);
  Set.insert(where[N-1]);
  for (ll i = N-2; i >= 0; i--) {
    auto itr3 = Set.lower_bound(where[i]);
    auto itr2 = prev(itr3,1);
    if (*itr3 != N) {
      auto itr4 = next(itr3,1);
      ans += ((ll)*itr4 - (ll)*itr3) * (where[i] - (ll)*itr2) * (i+1);
    }
    if (*itr2 != -1) {
      auto itr1 = prev(itr2,1);
      ans += ((ll)*itr2 - (ll)*itr1) * ((ll)*itr3 - where[i]) * (i+1);
    }
    Set.insert(where[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6144
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n, l;
	vector<string> vect;

	cin >> n >> l;
	vect.reserve(n);

	for (int i = 0; i < n; ++i) {
		string str;
		cin >> str;
		vect.push_back(str);
	}
	sort(vect.begin(), vect.begin() + n);

	for (const string &s : vect) cout << s;
	cout << endl;
    return 0;
}


Measured memory_bytes: 256
n, y = list(map(int, input().split(" ")))

ans = [str(-1), str(-1), str(-1)]

for v in range(n+1):
    for i in range(n+1):
        m = 10000 * v + 5000 * i + 1000 * (n - v - i)
        if m == y:
            t = n - v - i
            if t < 0:
                break
            ans = [str(v),  str(i), str(t)]
            break
ans = " ".join(ans)

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
 
int main(void)
{
 int A[2000];
 int N, i, j, v, k;

 scanf("%d", &N);
  
 for(i = 0; i < N; i++)
 scanf("%d", &A[i]);

for(k = 0; k < N; k++)
 if(k < N-1)
 printf("%d ", A[k]);
 else
 printf("%d", A[k]);

 printf("\n");

 for(i = 1; i < N; i++)
{

 j = i - 1;
 v = A[i];

 while(j >= 0 && A[j] > v)
{
 A[j+1] = A[j];
 j--;
}
 A[j+1] = v;

for(k = 0; k < N; k++)
 if(k < N-1)
 printf("%d ", A[k]);
 else
 printf("%d", A[k]);

 printf("\n");

}


return 0;

}

 


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define LL                  long long
#define ull                 unsigned long long LL
#define scl(n)              scanf("%lld", &n)
#define scf(n)              scanf("%lf", &n)
#define sci(n)              scanf("%d", &n)
#define scii(n,m)           scanf("%d %d",&n,&m)
#define sciii(n,m,p)        scanf("%d %d %d",&n,&m,&p)

#define MOD                 1000000007
#define MODP                99999999999973LL
#define pb                  push_back
#define mp                  make_pair
#define pp                  pair<LL,LL>
#define memo(a,b)           memset(a,b,sizeof(a))
#define INF                 1e9
#define EPS                 1e-8
#define Pi                  acos(-1.0)
LL bigmod(LL b, LL p, LL md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {LL y=bigmod(b,p/2,md);return (y*y)%md;}}
#define N 100002

LL arr[110],val[110];
LL n,W;
LL dp[110][N];

LL solve(int pos,int wt)
{
    if(pos==n)
    {
        return 0;
    }

    if(dp[pos][wt]!=-1)
        return dp[pos][wt];
    LL ans1=0;
    LL ans2=0;

    if(wt+arr[pos]<=W)
            ans1=val[pos] +  solve(pos+1,wt+arr[pos]);
    ans2=solve(pos+1,wt);


    return dp[pos][wt]=max(ans1,ans2);



}

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

    for(int i=0;i<n;i++)
        cin>>arr[i]>>val[i];
    memo(dp,-1);
    LL ans=solve(0,0);
    cout<<ans<<endl;


    return 0;
}



/* LL dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* LL dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* LL dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* LL dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction


Measured memory_bytes: 86272
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long [] s = new long[n + 1];
        for(int i = 1;i <= n;i ++) {
            s[i] = in.nextLong();
            s[i] += s[i - 1];
        }
        int l = 1,r = 3;
        long ans = s[n];
        for(int i = 2;i < n - 1;i ++) {
            long last = s[n];
            while(l < i) {
                long d = Math.abs(s[i] - s[l] * 2);
                if(d > last) break;
                else last = d;
                l ++;
            }
            l --;
            last = s[n];
            while(r < n) {
                long d = Math.abs(s[n] + s[i] - s[r] * 2);
                if(d > last) break;
                else last = d;
                r ++;
            }
            r --;
            long max = Math.max(Math.max(Math.max(s[l], s[i] - s[l]), s[r] - s[i]), s[n] - s[r]);
            long min = Math.min(Math.min(Math.min(s[l], s[i] - s[l]), s[r] - s[i]), s[n] - s[r]);
            ans = Math.min(max - min, ans);
        }
        System.out.println(ans);
    }
}

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

int main(){
    int n;
    cin>>n;
    int a[n];
    int dp[n] = {INT_MAX};
    for(int i = 0;i<n;i++){
        cin>>a[i];
        dp[i] = INT_MAX;
    }
    dp[0] = 0;
    dp[1] = abs(a[1]- a[0]);
    for(int i = 2;i<n;i++){
        dp[i] = min(dp[i], dp[i-1] + abs(a[i] - a[i-1]));
        dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <functional>

using i64 = long long;

const int N = 300000 + 7;

int n, q;
int v[N], w[N];
i64 f[520][N];
int x, c = 100000;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", w + i, v + i);
	for (int i = 1; i <= n && i <= 512; ++i) {
		std::copy(f[i / 2], f[i / 2] + c + 1, f[i]);
		for (int j = c; j >= v[i]; --j)
			f[i][j] = std::max(f[i][j], f[i][j - v[i]] + w[i]);
	}
	scanf("%d", &q);
	while (q--) {
		std::function<i64(int, int)> get = [&](int x, int c) -> i64 {
			if (c < 0) return -1ll << 60;
			return x <= 512 ? f[x][c] : std::max(get(x / 2, c), get(x / 2, c - v[x]) + w[x]);
		};
		scanf("%d%d", &x, &c), printf("%lld\n", get(x, c));
	}
	return 0;
}


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

using namespace std;

#define DIM 407
const long long INF = 1000000000000000007LL;


long long n,k,i,j,res;
long long p[DIM], sum[DIM], f[DIM][DIM];


int main() {
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> p[i];
        sum[i] = sum[i-1] + p[i];
    }

    for(int L = n; L >= 1; L--) {
        f[L][L] = 0;
        for(int R = L+1; R <= n; R++) {
            f[L][R] = INF;
            for(int k = L; k <= R-1; k++) {
                res = f[L][k]+f[k+1][R]+sum[R]-sum[L-1];
                f[L][R] = min(f[L][R], res);
            }
        }
    }
/*
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) cout<<f[i][j]<<' ';
        cout<<endl;
    }
*/
    cout<<f[1][n]<<endl;


    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a,b,x,sum;
cin>>a>>b>>x;
if(a%x==0 && b%x==0){

sum=((b/x)-(a/x))+1;
cout<<sum;
}

else if (a%x!=0 && b%x!=0)
{
	sum=((b/x)-(a/x));
	cout<<sum;
}
else if(a%x==0 &&b%x!=0){
sum=((b/x)-(a/x))+1;
cout<<sum;
}
else if(a%x!=0 &&b%x==0){


	sum=((b/x)-(a/x));
	
cout<<sum;
}	
	
	
	
	
	
	
	
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int c[10][10];
    int H, W, A, res;
    int main()
    {
    cin>>H>>W;
    	for (int i = 0; i < 10; i++)
    		for (int j = 0; j < 10; j++)
    			cin >> c[i][j];
    	for (int k = 0; k < 10; k++)
    		for (int i = 0; i < 10; i++)
    			for (int j = 0; j< 10; j++)
    				c[i][j]=min(c[i][k]+c[k][j],c[i][j]);
    	for (int i = 0; i < H; i++)
    		for (int  j = 0; j < W; j++)
    		{
    			cin >> A;
    			if (A >= 0)res += c[A][1];
    		}
    	cout << res << endl;
    }

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(string s,t;cin>>s>>t,t!="X";){
		vs ss;
		for(int i=0,j=1;i<s.size();j++){
			if(j==s.size() || isupper(s[j])){
				ss.push_back(s.substr(i,j-i));
				i=j;
			}
			if(s[j]=='_'){
				ss.push_back(s.substr(i,j-i));
				i=++j;
			}
		}
		if(t=="U")
			rep(i,ss.size())
				rep(j,ss[i].size())
					putchar(j==0?toupper(ss[i][j]):tolower(ss[i][j]));
		if(t=="L")
			rep(i,ss.size())
				rep(j,ss[i].size())
					putchar(i&&j==0?toupper(ss[i][j]):tolower(ss[i][j]));
		if(t=="D")
			rep(i,ss.size()){
				cout<<(i?"_":"");
				rep(j,ss[i].size())
					putchar(tolower(ss[i][j]));
			}
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196