akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
  int five=0,seven=0,hoka=0,r;
  for(int i=0;i<3;i++){
    scanf("%d",&r);
    if(r == 5) five++;
    else if(r == 7) seven++;
    else hoka++;
  }
  if (hoka>0) printf("NO");
  else if(seven>1) printf("NO");
  else if(seven == 0) printf("NO");
  else printf("YES");
  return 0;
}

Measured memory_bytes: 128
N = int(input())
AB = [[int(i) for i in input().split()] for j in range(N)]

ans = 0
for i in reversed(range(N)):
    Atemp = AB[i][0] + ans
    ans += (0 if Atemp%AB[i][1] == 0 else AB[i][1]-Atemp%AB[i][1])
print(ans)

Measured memory_bytes: 21156
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] h = new int[n];
    long ans = 0;
    for(int i = 0;i < n;i++){
      h[i] = sc.nextInt();
    }
    Arrays.sort(h);
    for(int j = 0;j < n - k;j++){
      ans += h[j];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 84956
#include <vector>
#include <array>
#include <algorithm>
#include <iostream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <assert.h>
#include <queue>
#include <deque>
#include <iomanip>
#include <numeric>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;

#define fi first
#define se second

#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;

typedef pair <int, int> pii;
typedef pair <ll, ll> pll;



int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll a;
    string s;
    cin >> a >> s;
    cout << (a >= 3200 ? s : "red") << endl;

    return 0;
}


Measured memory_bytes: 764
#include <stdio.h>

#define N 100

int count = 0;

void selectionSort(int *,int);
void swap(int *,int *);

int main(){
  int length,A[N],i;

  while(1){
    scanf("%d",&length);
    if(1 <= length && length <= 100) break;
  }

  for(i = 0;i < length;i++){
    scanf("%d",&A[i]);
    if(A[i] < 0 || 100 < A[i]) i = i - 1;
  }
  selectionSort(A,length);

  for(i = 0;i < length - 1;i++) printf("%d ",A[i]);
  printf("%d\n",A[i]);
  printf("%d\n",count);
  return 0;
}

void selectionSort(int *p,int l){
  int i,j,minj;
  for(i = 0;i < l;i++){
    minj = i;
    for(j = i;j < l;j++){
      if(p[j] < p[minj]) minj = j;      
    }
    swap(&p[i],&p[minj]); 
    if(i != minj) count++;
  }
}

void swap(int *q,int *r){
  int tmp;
  tmp = *q;
  *q = *r;
  *r = tmp;
}

Measured memory_bytes: 600
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())
d = getInputListInt()

d.sort()

print(d[0], d[n-1], sum(d))



Measured memory_bytes: 8068
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = readline().decode('utf8').rstrip()
T = readline().decode('utf8').rstrip()

S = S + S
print('Yes' if T in S else 'No')


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

int main() {
  int N,a;
cin>>N;
  for(a=1;a<=9;a++){
    if((N%a)==0&&(N/a)<=9){
   cout<<"Yes"<<endl; 
    break;
    }
 else if(a==9){
 cout<<"No"<<endl; 
  }
 }
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a,b,x;
	cin>>a>>b;
	if(a>b) x=a+a-1;
	else if(a<b) x=b+b-1;
	else x=a+b;
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input => (s: #));

    // 10^i mod 2019
    let mod2019 = (0..210000)
        .scan(1i64, |state, _| {
            let ret = *state;
            *state = (*state * 10) % 2019;
            Some(ret)
        })
        .collect::<Vec<_>>();

    s.chars()
        .map(|c| (c as u32 - '0' as u32) as i64)
        .rev()
        .enumerate()
        .scan(0, |state, (i, x)| {
            *state = (*state + x * mod2019[i]) % 2019;
            Some(*state)
        })
        .fold(
            {
                let mut v = Vec::with_capacity(2019);
                v.resize(2019, 0);
                v[0] = 1;
                v
            },
            |mut acc, x| {
                acc[x as usize] += 1;
                acc
            },
        )
        .into_iter()
        .filter(|&x| x != 0)
        .map(|x| x * (x - 1) / 2)
        .sum::<i64>()
        .to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}
tests! {
    test1: "1817181712114\n" => "3\n",
    test2: "14282668646\n" => "2\n",
    test3: "2119\n" => "0\n",
}


Measured memory_bytes: 4088
#include<cstdio>
#include<iostream>
#include<map>
using namespace std;

#define i64 long long int
#define ran 202202

int n;
int h[ran], a[ran];

map<int, i64> mp;
map<int, i64> ::iterator it, nxt, to_del;

int main() {
	scanf("%d", &n);
	for(int i=0;i<n;i++) scanf("%d", &h[i]);
	for(int i=0;i<n;i++) scanf("%d", &a[i]);
	
	mp[0] = 0;
	for(int i=0;i<n;i++) {
		it = mp.lower_bound(h[i]); 
		
		nxt = it; it--;
		i64 val = (*it).second + a[i];
		
		while(nxt != mp.end() && (*nxt).second < val) {
			to_del = nxt; nxt++;
			mp.erase(to_del);
		}
		
		mp[h[i]] = val;
	}
	
	it = mp.end(); it--;
	cout<< (*it).second<<endl;
	
	return 0;
}

Measured memory_bytes: 14336
# Aizu Problem 0032: Plastic Board
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

rectangles, lozenges = 0, 0
while True:
    try:
        a, b, c = [int(_) for _ in input().split(',')]
    except EOFError:
        break
    if a**2 + b**2 == c**2:
        rectangles += 1
    elif a == b:
        lozenges += 1

print(rectangles)
print(lozenges)

Measured memory_bytes: 7744
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector <long long int, long long int> 
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	char c;
	cin >> c;
	int x = (c - 'a');
	x++;
	cout << char(x + 97);
}

Measured memory_bytes: 256
my ($n, $m) = split(/\s+/, <>);
my @bit = ();

for my $i (0..($m-1)) {
    my ($k, @s) = split(/\s+/, <>);
    for (@s) {
	$bit[$i] |= 1<<($_-1);
    }
}
my @target = split(/\s+/, <>);

my $ans = 0;
for my $i (0..((1<<$n)-1)) {
    my $fail = 0;
    for (my $j=0; $j<$m && !$fail; $j++) {
	$fail = 1 unless (nbit($bit[$j] & $i) % 2 == $target[$j]);
    }
    $ans++ unless $fail;
}
print "$ans\n";

sub nbit {
    my ($x) = @_;
    my $ret = 0;
    while ($x > 0) {
	$ret++;
	$x &= $x-1;
    }
    return $ret;
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> d( N );
	for( int i = 0; i < N; i++ ) {
		cin >> d[i];
	}

	int ans = 0;
	for( int i = 0; i < N - 1; i++ ) {
		for( int j = i + 1; j < N; j++ ) {
			ans += d[i] * d[j];
		}
	}

	cout << ans << endl;
}


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

using namespace std;
 
int main() {
    int n,k,q;
    cin >> n>>k>>q;
    int a[n];
    for(int i = 0;i<n;i++){
      a[i]=k;
    }
    for(int i = 0;i<q;i++){
      int aho= 0;cin>>aho;
      a[aho-1]+=1;
    }
    for(int i = 0;i<n;i++){
      if(a[i]-q <=0) cout<<"No"<<endl;
      else cout<<"Yes"<<endl;
    }
    return 0;
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, l;
    cin >> n >> l;
    vector<string> v;
    rep (i, n) {
      string s;
      cin >> s;
      v.push_back(s);
    }
    sort(v.begin(), v.end());
    rep (i, n) {
      cout << v[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    int X,A;
    cin >> X >> A;
    if(X < A) pr(0);
    else pr(10);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N , M , now = 0 , sum = 0;
    cin >> N >> M;
    for(int i = 1 ; i <= N ; ++i){
        int a;
        cin >> a;
        sum -= max(0 , now - a);
        sum += M;
        now = a + M;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using vi = vector<int>;

int main(){
    int h,n;
    cin >> h >> n;
    const int INF = 1e9;
    vi dp(10100,INF);

    int a,b;
    dp[0] = 0;
    rep(i,n){
        cin >> a >> b;
        rep(j,10100){
            // if(j-a>=0){
            //     dp[j] = min(dp[j-a]+b,dp[j]);
            // }
            
                dp[j] = min(dp[max(j-a,0)]+b,dp[j]);
        }
    }

    // rep(i,h){
    //     cout << i << " " << dp[i] << endl;
    // }

    cout << dp[h] << endl;
    return 0;
}

Measured memory_bytes: 3616
def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()

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

int main() {
  bool cards[4][14];
  int n, rank;
  char suit;
  
  for (int s = 0; s < 4; s++) {
    for (int r = 1; r <= 13; r++) {
      cards[s][r] = 0;
    }
  }
  
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> suit >> rank;
    if (suit == 'S') cards[0][rank] = 1;
    if (suit == 'H') cards[1][rank] = 1;
    if (suit == 'C') cards[2][rank] = 1;
    if (suit == 'D') cards[3][rank] = 1;
  }
  
  for(int s = 0; s < 4; s++) {
    for(int r = 1; r <= 13; r++) {
      if (cards[s][r]) continue;
      if (s == 0) suit = 'S';
      if (s == 1) suit = 'H';
      if (s == 2) suit = 'C';
      if (s == 3) suit = 'D';
      cout << suit << " " << r << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[110];
int main(){
    ll n,m,ans=0,sum=0;
    cin>>n>>m;
    rep(i,0,n){cin>>a[i];ans+=a[i];}
    rep(i,0,n){
        if(a[i]*4*m>=ans)sum++;
    }
    if(sum>=m)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    constexpr ll inf=1000000;

    ll h=in(),w=in();
    vector<string>maze(h);
    for(ll i=0;i<h;++i)cin>>maze[i];

    auto adj=vec2<ll>(h*w,h*w,inf);
    auto dist=vec2<ll>(h*w,h*w,inf);
    for(ll i=0;i<h*w;++i)adj[i][i]=dist[i][i]=0;
    auto to_num=[w](ll x,ll y){return y*w+x;};
    for(ll i=0;i<h;++i){
        for(ll j=0;j<w;++j){
            if(maze[i][j]=='.'){
                ll dx[]={0,-1,0,1},dy[]={1,0,-1,0};
                for(ll k=0;k<4;++k){
                    ll xx=j+dx[k],yy=i+dy[k];
                    if(0<=xx&&xx<w&&0<=yy&&yy<h&&maze[yy][xx]=='.'){
                        adj[to_num(j,i)][to_num(xx,yy)]=
                        adj[to_num(xx,yy)][to_num(j,i)]=
                        dist[to_num(j,i)][to_num(xx,yy)]=
                        dist[to_num(xx,yy)][to_num(j,i)]=
                        1;

                    }
                }
            }
        }
    }
    for(ll k=0;k<h*w;++k){
        for(ll i=0;i<h*w;++i){
            for(ll j=0;j<h*w;++j){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    ll ans=0;
    for(ll i=0;i<h*w;++i){
        for(ll j=0;j<h*w;++j){
            if(dist[i][j]!=inf){
                ans=max(ans,dist[i][j]);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2816
#include <stdio.h>
int main(){
    int N, a[101] = {0};
    int i, j, count = 0;
    int min,temp;
    scanf("%d", &N);
    for(i = 0; i < N; i++){
        scanf("%d", &a[i]);
    }
    for(i = 0; i< N; i++){
        min = i;
        for(j = i; j < N; j++){
            if(a[j] < a[min]){
                min = j;
            } }
        if(a[i] > a[min]){
            temp = a[i];
            a[i] = a[min];
            a[min] = temp;
            count++;
        } }
    for(i = 0; i < N; i++){
        printf("%d", a[i]);
        if(i != N-1){printf(" ");
        } }
    printf("\n%d\n", count);
    return 0; }


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

int main(){
  int n,m;
  cin>>n>>m;
  vector<P> p(n);
  rep(i,n) {
    cin>>p[i].first>>p[i].second;
    p[i].second=p[i].second*(-1);
  }
  sort(p.begin(),p.end());
  int g=0;
  ll ans=0;
  ll c;
  rep(i,n){
    ans=ans+p[i].first*p[i].second*(-1);
    g=g+p[i].second*(-1);
    if(g>=m){
      c=p[i].first;
      break;
    } 
  }
  while(g>m){
    g--;
    ans=ans-c;
  }
  cout<<ans<<endl;
  

  return 0;
}



Measured memory_bytes: 1792
program main
	implicit none
    integer N, K
	read(*, *) N, K
	if(N == K) then
		write(*, *) 1
	else if(mod(N-K,K-1) == 0) then
		write(*, *) (N-K)/(K-1) + 1
	else
		write(*, *) (N-K)/(K-1) + 2
	end if
end program main

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

long long N, M;
int A[(int)1e5];
int B[(int)1e5];

int main() {
    cin >> N >> M;
    rep(i, N) cin >> A[i] >> B[i];

    map<long long, long long> map;
    rep(i, N) {
        map[A[i]] += B[i];
    }

    long long ans = 0;
    for (auto itr = map.begin(); itr != map.end(); itr++) {
        // printf("%d %d\n", itr->first, itr->second);
        long long buy = min(itr->second, M);
        M -= buy;

        // 何個買う？
        ans += buy * itr->first;

        if (M == 0) {
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
using namespace std;
double n,m,d,ans;
int main(void){
    cin>>n>>m>>d;
    if(n<=d){
        cout<<0<<endl;
        return 0;
    }
    if(d!=0)printf("%.7lf\n",(n-d)*2/n/n*(m-1));
    else printf("%.7lf\n",(m-1)/n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);


int main(){

	IOS
	ll x;
	cin>>x;
	ll aa,bb;
    FOR(i,0,1000){
    	FOR(j,-1000,1000){
    		ll tmp=i*i*i*i*i-j*j*j*j*j;
    		if(tmp==x){
    			aa=i;
    			bb=j;
    			break;

    		}
    	}
    }
    cout<<aa<<" "<<bb<<endl;
	
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define maxn 3010
using namespace std;
char a[maxn];
char b[maxn];
int dp[maxn][maxn];
string output = "";

int main()
{
    scanf("%s",a+1);
    scanf("%s",b+1);
    int n = strlen(a+1);
    int m = strlen(b+1);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i]==b[j])
            {
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    while(dp[n][m]>0)
    {
        if(dp[n][m]==dp[n-1][m]) n--;
        else if(dp[n][m]==dp[n][m-1]) m--;
        else
        {
            output.insert(0,string(1,a[n]));
            n--;
            m--;
        }
    }
    cout<<output<<endl;
//    printf("%d\n",dp[n][m]);
}



Measured memory_bytes: 35584
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;


int main()
{
	int n,k; cin>>n>>k;
	if (k>(n-2)*(n-1)/2)
	{
		cout <<-1;
		return 0;
	}
	
	int s=(n-2)*(n-1)/2-k; 
      cout << s+n-1 << endl;
	for (int i=2; i<=n; i++)
	    cout << 1 << ' ' << i << endl;
	    
	for (int i=2; i<=n; i++)
	    for (int j=i+1; j<=n; j++)
	    {
	    	if (s>0)
	        {
	        	cout << i<<' '<< j<<' '<< endl;
	        	s--;
			}
			if (s==0) return 0;
		}
}

Measured memory_bytes: 256
// Shift-JIS（シフトジス）

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

int main()
{
    double N, K, m, P = 0;
    cin >> N >> K;

    for (int i = 1; i <= N; i++) {
        m = 0;
        while (true) {
            if (i * pow(2, m) >= K) {
                break;
            }
            m++;
        }
        P += (1 / N) * pow(0.5, m);
    }

    cout << setprecision(10) << P << endl;
}

Measured memory_bytes: 256
x,n = map(int,input().split())

if n == 0:
  print(x)
else:
  p_list = list(map(int,input().split()))
  result_list = []
  for i in range(0,102):
    if i not in p_list:
      result_list.append([i,abs(x - i)])
    
  result_list.sort(key=lambda x: x[1])
  print(result_list[0][0])

Measured memory_bytes: 9196
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    string S;
    cin>>S;
    ll Maxim=0;
    for(ll i=2; i<S.size()-1; i+=2){
        bool can=true;
        rep(j, i/2){
            if(S[j]!=S[i/2+j]) can=false;
        }
        if(can) Maxim=max(Maxim, i);
    }
    cout<<Maxim<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys, re
#from collections import deque, defaultdict, Counter
#from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
#from itertools import permutations, combinations, product
#from operator import itemgetter, mul
from copy import deepcopy,copy
#from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd


def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

x, a = MAP()

if x < a:
    print(0)
else:
    print(10)

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

using namespace std;
using ll = long long;

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

    vector<ll> X(N);
    for (int i = 0; i < N;i++)
    {
        cin >> X[i];
    }

    ll ans = 0;

    for (int i = 1; i < N;i++)
    {
        ll Acost = A * (X[i] - X[i - 1]);
        ans += Acost < B ? Acost : B;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>

struct Point{
    double x;
    double y;
    void print();
};

void koch(int n,Point p1,Point p2){
    if(n==0){
        return;
    }
    Point s,t,u;
    s.x = (2*p1.x + 1*p2.x) / 3.0;
    s.y = (2*p1.y + 1*p2.y) / 3.0;
    t.x = (1*p1.x + 2*p2.x) / 3.0;
    t.y = (1*p1.y + 2*p2.y) / 3.0;
    u.x = (t.x - s.x) * (1.0/ 2.0) - (t.y - s.y) * (sqrt(3.0) / 2.0) + s.x;
    u.y = (t.x - s.x) * (sqrt(3.0) / 2.0) + (t.y - s.y) *(1.0 / 2.0) + s.y;
    koch(n-1,p1,s);
    s.print();
    koch(n-1,s,u);
    u.print();
    koch(n-1,u,t);
    t.print();
    koch(n-1,t,p2);
}

int main(){
    Point p1,p2;
    p1.x = 0;
    p1.y = 0;
    p2.x = 100;
    p2.y = 0;
    int n;
    std::cin >> n;
    p1.print();
    koch(n,p1,p2);
    p2.print();
    return 0;
}

void Point::print(){
    std::cout << std::fixed;
    std::cout << std::setprecision(8) << x << " ";
    std::cout << std::setprecision(8) << y <<"\n";
}


Measured memory_bytes: 3232
n,m = map(int,input().split())
lst = [0]*(n+1)
for _ in range(m):
    a,b = map(int,input().split())
    lst[a] += 1
    lst[b] += 1
res = True
for i in range(1, n+1):
    if lst[i]%2!=0:
        res=False
        break
print('YES' if res else 'NO')

Measured memory_bytes: 3956
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] oem = line.split("/");
        oem[0]= "2018";
        System.out.println(oem[0]+"/"+oem[1]+"/"+oem[2]);

    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 10 + 5;

char s[MAXN];

int main(void)
{
	scanf("%s",s+1);
	
	for(int i=1; s[i]; i+=2)
		if(s[i]!='h' || s[i+1]!='i')
			return printf("No\n"),0;
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.Bits
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

solve :: Int -> Int -> [[Int]] -> Int
solve bN bK ass = VU.foldl' mAdd 0 theMat
  where
  matE = VU.fromListN (bN*bN) (concat ass)
  mmm = matMul mAdd mMul bN bN bN
  power = iterate (\x -> mmm x x) matE
  seq = [testBit bK i | i <- [0..63]]
  theMat = foldl' mmm (matI bN) [p | (s, p) <- zip seq power, s]

-------------------------------------------------------------------------------

matI n =
  VU.fromListN (n*n)
  [if i == j then 1 else 0 | i <- [0..n-1], j <- [0..n-1]]

matMul opA opM n m p mat1 mat2 =
  VU.fromListN (n*p)
  [foldl' opA 0 [(mat1 VU.! (i*m+k)) `opM` (mat2 VU.! (k*p+j))
                | k <- [0..m-1]]
  | i <- [0..n-1], j <- [0..p-1]]

-------------------------------------------------------------------------------

mPrime = 10^9 + 7

mAdd :: Int -> Int -> Int
mAdd x y = let w = x + y in if w < mPrime then w else w - mPrime
-- mAdd x y = (x + y) `mod` mPrime

mSub :: Int -> Int -> Int
mSub x y = let w = x - y in if w >= 0 then w else w + mPrime
-- mSub x y = (x - y) `mod` mPrime    -- ok even if x < y

mMul :: Int -> Int -> Int
mMul x y = (x * y) `mod` mPrime


readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n,bs_k]:remLines1 = remLines0
      n = readBInt bs_n
      k = readBInt bs_k
      ass = map (map readBInt) remLines1
  in solve n k ass

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


-------------------------------------------------------------------------------

inp1 = "4 2\n0 1 0 0\n0 0 1 1\n0 0 0 1\n1 0 0 0\n"
inp2 = "3 3\n0 1 0\n1 0 1\n0 0 0\n"
inp3 = "6 2\n0 0 0 0 0 0\n0 0 1 0 0 0\n0 0 0 0 0 0\n0 0 0 0 1 0\n0 0 0 0 0 1\n0 0 0 0 0 0\n"
inp4 = "1 1\n0\n"
inp5 = "10 1000000000000000000\n0 0 1 1 0 0 0 1 1 0\n0 0 0 0 0 1 1 1 0 0\n0 1 0 0 0 1 0 1 0 1\n1 1 1 0 1 1 0 1 1 0\n0 1 1 1 0 1 0 1 1 1\n0 0 0 1 0 0 1 0 1 0\n0 0 0 1 1 0 0 1 0 1\n1 0 0 0 1 0 1 0 0 0\n0 0 0 0 0 1 0 0 0 0\n1 0 1 1 1 0 1 1 1 0\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
tv3 = tmain $ B.pack inp3
tv4 = tmain $ B.pack inp4
tv5 = tmain $ B.pack inp5
test1 = tv1 == 6
test2 = tv2 == 3
test3 = tv3 == 1
test4 = tv4 == 0
test5 = tv5 == 957538352
alltest = test1 && test2 && test3 && test4 && test5



Measured memory_bytes: 3452
N = parse(readline())

function f(a,b)
  A = floor(log10(a)+1)
  B = floor(log10(b)+1)
  return max(A,B)
end


ans = 100
for i in 1:sqrt(N)
  if N % i == 0
  	(f(i,N/i) < ans) && (ans = f(i,N/i))
  end
end

println(Int(ans))

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

int main() {
    int n;
    while (cin >> n, n) {
        vi a(n);
        for (int i=0; i<n; ++i) cin >> a[i];

        vvi dp(301, vi(301, 0));
        for (int i=0; i+2<=n; ++i) {
            dp[i][i+2] = (abs(a[i] - a[i+1]) <= 1 ? 2 : 0);
        }
        for (int l=3; l<=n; ++l) {
            for (int i=0; i+l<=n; ++i) {
                if (dp[i+1][i+l-1] == l-2) {
                    dp[i][i+l] = dp[i+1][i+l-1] + (abs(a[i] - a[i+l-1]) <= 1 ? 2 : 0);
                }
                for (int j=i+1; j<i+l; ++j) {
                    dp[i][i+l] = max(dp[i][i+l], dp[i][j] + dp[j][i+l]);
                }
            }
        }
        cout << dp[0][n] << endl;
    }
    return 0;
}


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

int main(){
  int a, b, k;
  
  cin >> a >> b >> k;
  
  int count = 0;
  int res = 0;
  for(int i = min(a,b); i >= 1; i--){
  	 if(a % i == 0 && b % i == 0){
       count++;
       if(count == k){
         res = i;
         break;
       }
     }
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+5;
const lli MOD=1e9+7;

lli t[MAX],a[MAX];
bool tmx[MAX],amx[MAX];

int main(){
	int N;
	cin>>N;
	rep1(i,N){
		cin>>t[i];
		if(t[i-1]<t[i])tmx[i]=true;
	}
	rep1(i,N)cin>>a[i];
	for(int i=N;i>=1;i--){
		if(a[i]>a[i+1])amx[i]=true;
	}
	int ht[MAX];
	rep1(i,N){
		int h;
		if( tmx[i]&& amx[i]){
			if(t[i]!=a[i])h=0;
			else h=1;
		}
		if( tmx[i]&&!amx[i]){
			if(t[i]>a[i])h=0;
			else h=1;
		}
		if(!tmx[i]&& amx[i]){
			if(t[i]<a[i])h=0;
			else h=1;
		}
		if(!tmx[i]&&!amx[i]){
			h=min(t[i],a[i]);
		}
		ht[i]=h;
	}
	lli ans=1;
	rep1(i,N){
		ans=(ans*(lli)ht[i])%MOD;
	}
	cout<<ans;
}

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

using namespace std;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    int min_i = 999;
    for(int i = 0; i <= N - 3; i++){
        int num = (S.at(i) - '0') * 100 + (S.at(i + 1) - '0') * 10 + (S.at(i + 2) - '0');
        min_i = min(min_i, abs(num - 753));
    }
    cout << min_i << endl;
}

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

int main() {
    int n, x[100], y[100];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) cin >> y[i];
    double p1 = 0, p2 = 0, p3 = 0, pInf[n];
    for (int i = 0; i < n; i++){
        p1 += fabs(x[i] - y[i]);
        p2 += pow(x[i] - y[i],2);
        p3 += pow(fabs(x[i] - y[i]),3);
        pInf[i] = fabs(x[i] - y[i]);
    }
    p2 = sqrt(p2);
    p3 = pow(p3,1.0/3);
    double pI = 0;
    for (int i = 0; i < n; i++){
        if (pI < pInf[i]) pI = pInf[i];
    }
    printf("%lf\n%lf\n%lf\n%lf\n",p1,p2,p3,pI);
    return 0;
}

Measured memory_bytes: 3344
#include <cstdlib>
#include <iostream>
#include <vector>
typedef long long LL;

int main() {
  int n; std::cin >> n;
  std::vector<LL> h(n), cost(n);
  for (int i = 0; i < n; ++i) std::cin >> h[i];

  cost[n-1] = 0;
  cost[n-2] = std::abs(h[n-2] - h[n-1]);

  for (int i = n-3; i >= 0; --i) {
    LL cost1 = std::abs(h[i] - h[i+1]) + cost[i+1];
    LL cost2 = std::abs(h[i] - h[i+2]) + cost[i+2];
    cost[i] = std::min(cost1, cost2);
  }

  std::cout << cost[0] << std::endl;
}


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

int main(){
    long long x; cin >> x;
    long long y = 100;
    int ct=1;
    while(1){
        y= floor(y*1.01);
        if(y>=x) break;
        ++ct;
    }
    cout << ct << endl;
    return 0;
}

Measured memory_bytes: 3744
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

struct CombMod{
    fac: Vec<u64>,
    inv: Vec<u64>,
    finv: Vec<u64>,
    mmod: u64,
}

impl CombMod{
    pub fn new(max: u64, m: u64) -> CombMod{
        let max: usize = max as usize;
        let mut fac: Vec<u64> = vec![0;max+1];
        let mut finv: Vec<u64> = vec![0;max+1];
        let mut inv: Vec<u64> = vec![0;max+1];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..max+1{
            fac[i] = fac[i-1] * i as u64 % m;
            inv[i] = m - inv[m as usize %i] * (m/(i as u64)) % m;
            finv[i] = finv[i-1] * inv[i] % m;
        }

        CombMod{
            fac: fac,
            finv: finv,
            inv: inv,
            mmod: m,
        }
    }

    fn get(&self, n: u64, m: u64) -> u64{
        assert!(n >= m && n != 0 && m != 0);
        self.fac[n as usize] * self.finv[m as usize] % self.mmod
            * self.finv[(n-m) as usize] % self.mmod
    }
}

fn main(){
    let line = read_as_vec::<u32>();
    let (k, x) = (line[0], line[1]);

    if 500*k >= x{
        println!("Yes");
    }else{
        println!("No");
    }
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}

int main(){
    ll H, W; cin >> H >> W;
    if(H==1 || W == 1){
        cout << 1 << endl;
        return 0;
    }
    ll ans = 0;
    ll Heven = H/2;
    ll Hodd = H - Heven;
    ll Weven = W/2;
    ll Wodd = W - Weven;
    cout << Hodd*Wodd + Heven*Weven << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,W;
int w[100],v[100];
ll dp[101][100001];
int main(){
  cin >> n >> W;
  for(int i=0;i<n;i++) cin >> w[i] >> v[i];
  memset(dp,0,sizeof(dp));
  for(int i=0;i<n;i++){
    for(int j=0;j<=W;j++){
      if(j<w[i]) dp[i+1][j]=dp[i][j];
      else dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
    }
  }
  cout << dp[n][W] << "\n"; 
  
  return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

int main(void)
{
	int height;
	int i=0;
	std::vector<int> height_array;
	
	while(i<10){
		std::cin >> height;
		height_array.push_back(height);
		i++;
	}
	sort(height_array.begin(), height_array.end(), std::greater<int>());
	for(int i=0; i<3; i++){
		std::cout << height_array[i] << std::endl;
	}
	
	
	return 0;
	
}

Measured memory_bytes: 1216
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Convert;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }


        public void Solve(ConsoleInput cin)
        {
            var _N = cin.Read;
            var N = _N.ToCharArray();
            var A = int.Parse(N[0].ToString());
            var B = int.Parse(N[1].ToString());
            var C = int.Parse(N[2].ToString());
            var D = int.Parse(N[3].ToString());
            var calu = new char[2];
            calu[0] = '+';
            calu[1] = '-';
            for(int i = 0; i < 2; i++)
            {
                for(int j = 0; j < 2; j++)
                {
                    for(int k = 0; k < 2; k++)
                    {
                        var num = A + B * Pow(-1, i) + C * Pow(-1, j) + D * Pow(-1, k);
                        if(num == 7)
                        {
                            var ans = A.ToString() + calu[i] + B.ToString() + calu[j] + C.ToString() + calu[k] + D.ToString() + "=7";
                            WriteLine(ans);
                            return;
                        }
                    }
                }
            }
        }


        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 11348
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
tnp = 0
for i in range(1,n+2):
    tnp += abs(a[i]-a[i-1])
for i in range(n):
    ans = tnp - abs(a[i+1]-a[i]) - abs(a[i+2]-a[i+1]) + abs(a[i+2]-a[i])
    print(ans)

Measured memory_bytes: 20500
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;
	return 0;
}

Measured memory_bytes: 3636
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0, d = 0, e = 0, ans = 0,w=0, x = 0, y = 0, z = 0, N = 0, m = 0, maxy = -1,maxy2=-1, mini = 9999999999, mini2 = 9999999999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremono[1000000], koware[100001];
long long  int iremonokisu[100001], check[100001], xpo[10000001], ypo[10000001], hei[1000001];
std::vector<char>kinds{}, kaku{}, kakutwo{};
char maze[1000];
int sx, sy;
int gx, gy;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
long long int dp[4][100003] ,ire[4][100003];
std::string input[103],one,two,three;
char re;

int H, W;//はんい
bool qw = false, er = false, ty = false, ui = false;
std::string code;
long long int gcd(long long int a, long long int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

	return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a,long long int b)
{
	return a * b / gcd(a, b);
}

int main() {
	cin >> a;
	rep(i, a) {
		cin >> iremono[i];
		if (maxy < iremono[i]) {
			maxy = std::max(maxy, iremono[i]);
			x = i;
		}
	}
		rep(i, a) {
			if (maxy2 < iremono[i]) {
				if (i != x) {
					maxy2 = max(maxy2, iremono[i]);
					y = i;
				}
			}
		}
		rep(i, a) {
			if (i == x) {
				cout << iremono[y] << endl;
			}
			else {
				cout << iremono[x] << endl;
			}
		}
	

}




Measured memory_bytes: 7808
a,b,c,k = map(int, input().split())
def pick(a,b,c,k):
    result = 0
    if (a >= k ):return k
    k -= a
    result += a
    if (b >= k):return result
    k -= b
    return result - k 
print(pick(a,b,c,k))
    

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int mod=1e9+7;
const int N=2e5+100;
ll a[N];
int f[5];
bool cmp(int x,int y)
{
    return abs(x)<abs(y);
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        if(a[i]>=0) f[1]++;
        else f[2]++;
    }
    int l=1,r=n;
    ll ans=1;
     if(!f[1]&&m%2==1){
        sort(a+1,a+1+n,cmp);
        for(int i=1;i<=m;i++){
            ans=a[i]*ans%mod;
        }
    }
    else {
        sort(a+1,a+1+n,greater<int>());
    while(m>0){
        if(m%2) ans=ans*a[l]%mod,l++,m--;
        else if(m>=2){
           if(a[l]*a[l+1]>=a[r]*a[r-1]){
              ans=ans*a[l]%mod*a[l+1]%mod;
              l+=2;
              m-=2;
           }
           else{
            ans=ans*a[r-1]%mod*a[r]%mod;
            r-=2;
            m-=2;
           }
        }
    }
    }
    cout<<(ans%mod+mod)%mod<<endl;
    return 0;
}

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

int main(){
    int N, M, a, b;
    cin >> N >> M;
    vector<int> city(N, 0);
    for(int i = 0; i < M; i++){
        cin >> a >> b;
        city[a-1]++;
        city[b-1]++;
    }
    for(int i = 0; i < N; i++){
        cout << city[i] << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, double> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a.at(i);

	sort(a.begin(), a.end());
	int ma = a.back();
	int mi = a.front();
	int ans = 1001001001;
	for (int i = mi; i < ma + 1; i++) {
		int score = 0;
		rep(j, n) {
			if (a.at(j) == i) continue;
			else {
				score += pow(a.at(j) - i, 2);
			}
		}
		ans = min(ans, score);
	}

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

Measured memory_bytes: 256