akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;
const ll INF = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2); return sq*sq; } else { return N*RS(N, P - 1); } } //power(repeat-square,fast)
ll nPr(ll n, ll r) { ll ans = 1; rep(i, r) { ans = ans * (n - i); } return ans; } //permutation
ll nCr(ll n, ll r) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1); bunshi = bunshi * (n - i); } return bunshi / bunbo; } //combination
ll RS(ll N, ll P, ll Mod) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination


int main(void) {
  ll N,W; cin >> N >> W;
  ll items[101][2], dp[101][101000];
  rep(i,N) cin >> items[i][0] >> items[i][1];
  rep(w,W+1){
    if (w-items[0][0] >= 0) dp[0][w] = items[0][1];
  }
  
  rep(i,N){
    if (i==0) continue;
    rep(w,W+1){
      dp[i][w] = dp[i-1][w];
      if (w-items[i][0] >= 0){
        chmax(dp[i][w],dp[i-1][w-items[i][0]]+items[i][1]);
      }
    }
  }
  
  cout << dp[N-1][W] << endl;
  return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a,b,c,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;

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

        
       cin >> s;
      bool fl=false;
      bool fll=false;
      if(s.size()%2==0){
          fl=true;
      }
      if(s[0]==s[s.size()-1]){
          fll=true;
      }
      if(fl){
          if(fll){
              Cout("First");
          }
          else{
              Cout("Second");
          }
      }
      else if(fll){
          if(fl){
              Cout("First");
          }
          else{
              Cout("Second");
          }
      }
      else{
          Cout("First");
      }
       
       
return 0;
}


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

using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;

constexpr int NMAX = 2010;

ll _binom[NMAX][NMAX];

ll binom(ll n, ll r) {
    if (n < 0 || r < 0 || r > n) return 0;
    return _binom[n][r];
}

int main() {
    for (int i = 0; i < NMAX; ++i) {
        _binom[i][0] = _binom[i][i] = 1;
        for (int j = 1; j < i; ++j) _binom[i][j] = (_binom[i-1][j] + _binom[i-1][j-1]) % MOD;
    }
    int s; scanf("%d", &s);
    ll ans = 0;
    for (int len = 1; len <= s; ++len) {
        int as = s - 2 * len;
        ans = (ans + binom(as - 1, len - 1)) % MOD;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 26540
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

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

  if (n == 1)
    cout << 1;
  else if (n < 4)
    cout << 2;
  else if (n < 8)
    cout << 4;
  else if (n < 16)
    cout << 8;
  else if (n < 32)
    cout << 16;
  else if (n < 64)
    cout << 32;
  else
    cout << 64;

  return 0;
}


Measured memory_bytes: 256
import kotlin.*
import kotlin.math.abs
import kotlin.math.min


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val x = Array(n) { 0L }
        val y = Array(n) { 0L }
        val p = Array(n) { 0L }
        for (i in 0 until n) {
            x[i] = sc.nextLong()
            y[i] = sc.nextLong()
            p[i] = sc.nextLong()
        }

        val cost = Array(n + 1) { Array(n) { Long.MAX_VALUE } }
        var sum = 0L
        // 線路0本
        for (i in 0 until n) {
            cost[0][i] = min(abs(x[i]), abs(y[i])) * p[i]
            sum += cost[0][i]
        }

        val ans = Array(n + 1) { Long.MAX_VALUE }

        fun go(t: Int, k: Int) {
            ans[k] = min(ans[k], sum)
            if (t >= n) return
            // 縦
            var diff = 0L
            for (i in 0 until n) {
                cost[t + 1][i] = min(cost[t][i], abs(x[i] - x[t]) * p[i])
                diff += cost[t + 1][i] - cost[t][i]
            }

            sum += diff
            go(t + 1, k + 1)
            sum -= diff
            diff = 0

            // 横
            for (i in 0 until n) {
                cost[t + 1][i] = min(cost[t][i], abs(y[i] - y[t]) * p[i])
                diff += cost[t + 1][i] - cost[t][i]
            }

            sum += diff
            go(t + 1, k + 1)
            sum -= diff

            for (i in 0 until n) {
                cost[t + 1][i] = cost[t][i]
            }

            go(t + 1, k)
        }

        go(0, 0)

        println(ans.joinToString("\n"))
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


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

typedef long long int ll;

ll knapSack(ll W, ll wt[], ll val[], ll n) 
{ 
    ll dp[n+1][W+1];

    for(ll i=0; i<n+1; i++){
        for (ll j=0; j<W+1; j++){
            
            if (i==0 || j==0){
                dp[i][j] = 0;
            }
            else if (wt[i-1] > j){
                dp[i][j] = dp[i-1][j];
        
            }
            else {
                dp[i][j] = max(dp[i-1][j], val[i-1]+dp[i-1][j-wt[i-1]]);
            }
        }
    }

    return dp[n][W];   
}



int main(){

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

    ll n, W;
    cin >> n >> W;

    ll wt[n], val[n];

    for (ll i=0; i<n; i++){
        cin >> wt[i];
        cin >> val[i];

    }

    cout << knapSack(W, wt, val, n);

    return 0;

}


Measured memory_bytes: 82464
#include "stdio.h"
#include "stdlib.h"

int N;
int M;
int A[100010];
int temp;
int res;


int binarySearch(int x){
    int left = 0;
    int right = N;
    int mid;
    while(left < right){
        mid = (left + right) / 2;
        if(A[mid] == x){
            return 1;
        } 
        else if(A[mid] > x){
            right = mid;
        }
        else{
            left = mid + 1;
        }
    }
    return 0;
}

int main(){
    //freopen("binarySearch.txt", "r", stdin);
    scanf("%d", &N);
    for(int i=0; i<N; i++){
        scanf("%d", &A[i]);
    }
    scanf("%d", &M);
    for(int i=0; i<M; i++){
        scanf("%d", &temp);
        if(binarySearch(temp)) res++;
    }
    printf("%d\n", res);
    return 0;
}


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

int main(){
    int A,B;
    cin >> A >> B;
    if(A>B){
        cout << 2 * A - 1 << endl;
    }else{
        if(A==B){
            cout << 2 * A << endl;
        }else{
            cout << 2 * B - 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,ans,cnt,sum[2001];
char a[2001][2001];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
			cin>>a[i][j];
	for (int i=1;i<=n;++i)
	{
		cnt=0;
		for (int j=1;j<=m;++j)
		{
			if (a[i][j]=='#')
			{
				cnt=0;
				sum[j]=0;
				continue;
			}
			if (cnt==0)
			{
				for (int k=j;k<=m;++k)
					if (a[i][k]=='#') break;
					else ++cnt;
			}
			if (sum[j]==0)
			{
				for (int k=i;k<=n;++k)
					if (a[k][j]=='#') break;
					else ++sum[j];
			}
			ans=max(ans,cnt+sum[j]-1);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

/*   *   *   *   *   *   *   *   *   *   *   */

ll n, W;
const int MAX_N = 110;
const int MAX_V = 100010;
ll dp[MAX_N][MAX_V];
ll weight[MAX_N], value[MAX_N];

void solve() {
    cin >> n >> W;
    rep(i, 0, n) cin >> weight[i] >> value[i];

    rep(i, 0, MAX_N) rep(j, 0, MAX_V) dp[i][j] = INF;

    dp[0][0] = 0;

    rep(i, 0, n){
        for(int sum_v = 0; sum_v < MAX_V; sum_v++){
            if(sum_v >= value[i])
            chmin(dp[i+1][sum_v], dp[i][sum_v-value[i]]+weight[i]);
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    ll ans = 0;
    rep(sum_v, 0, MAX_V){
        if(dp[n][sum_v] <= W) ans = sum_v;
    }
    cout << ans << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 86272
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int l[n]; for (int i = 0; i < n; i++) cin >> l[i];
    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = i+1; j < n; j++)
            for (int k = j+1; k < n; k++) {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i]
                    && l[i] + l[j] > l[k] && l[i] + l[k] > l[j] &&
                    l[j] + l[k] > l[i])
                    ans++;
            }
    cout << ans << endl;
}


Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <cstdio>
using Int = long long;
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
int main()
{
    Int n, m; cin >> n >> m;
    vector<int> X(n), Y(m);
    REP(i, n) cin >> X[i];
    REP(i, m) cin >> Y[i];
    Int x = 0, y = 0;
    for (int i = 0; n - 2*i > 0; i++) {
        x += (n-1 - 2*i) * (X[n-1-i] - X[i]);
    }
    for (int i = 0; m - 2*i > 0; i++) {
        y += (m-1 - 2*i) * (Y[m-1-i] - Y[i]);
    }
    cout << ((x % MOD) * (y % MOD)) % MOD << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int f[20];
int main(){
    ll n;
    cin>>n;
    int k=0;
    while(n){
        f[k++]=n%10;
        n/=10;
    }
    int t=0,res=0;
    while(t<k-1){
        if(f[t]==9) {t++; continue;}
        f[t++]=9;
        if(f[t]!=0) f[t]--;
        else{
            while(f[t]==0){
                f[t]=9;
                t++;
            }
            f[t]--;
        }
    }
    for(int i=0;i<k;i++)
    res+=f[i];
    printf("%d",res);
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())
    A = [0] * M
    C = [0] * M
    for i in range(M):
        A[i], b = map(int, readline().split())
        C[i] = sum(1 << (int(s) - 1) for s in readline().split())

    dp = [INF] * (1 << N)
    dp[0] = 0
    for S in range(1 << N):
        if dp[S] == INF:
            continue
        for a, c in zip(A, C):
            if dp[S | c] > dp[S] + a:
                dp[S | c] = dp[S] + a

    ans = dp[(1 << N) - 1]
    if ans < INF:
        print(ans)
    else:
        print(-1)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 73624
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define nl '\n'

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int , int> pi;

void solve()
{
	int n, m, k;
	cin>>n>>m>>k;
	int countb = 0;
	char a[n][m];
	int answer = 0;
	for(int i=0; i<n; i++)
	for(int j=0; j<m; j++)
	{
		cin>>a[i][j];
		if(a[i][j] == '#') countb++;
	}
	for(int i=0; i<(1<<n); i++)
	{
		for(int j=0; j<(1<<m); j++)
		{
			int temp = 0;
			for(int ii=0; ii<=6; ii++)
			{
				if(((1<<ii) & i) != 0)
				{
					for(int count=0; count<m; count++)
					{
						if(a[ii][count] == '#') temp++;
					}
				}
			}
			for(int jj=0; jj<=6; jj++)
			{
				if(((1<<jj) & j) != 0)
				{
					for(int count=0; count<n; count++)
					{
						if(a[count][jj] == '#' && ((1<<count)&i) == 0) temp++;
					}
				}
			}
			if(countb-temp == k) answer++;
		}
	}
	cout<<answer<<nl;
}

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


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int a;
    int b;
    int c;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.a = sc.nextInt();
        this.b = sc.nextInt();
        this.c = sc.nextInt();
    }
    
    //解答処理
    private String solve() {
        String answer = "NO";
        if (b-a == c-b) {
        	answer = "YES";
        }
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35800
n = int(input())
h = list(map(int, input().split()))
cnt=0
for i in range(n):
    while h[i] != 0:
        cnt+=1
        for j in range(i, n):
            if h[j] != 0:
                h[j] = h[j] - 1
            elif h[j] == 0:
                break
print(cnt)


Measured memory_bytes: 9160
q,h,s,d = gets.chomp.split(" ").map(&:to_i);
n = gets.to_i

m1 = [4 * q ,2 * h , s].min

r = m1 if n == 1 

if n >= 2
  if 2 * m1 <= d
    r = n * m1
  elsif n % 2 == 0
    r = n * d / 2
  else
    r = (n / 2).floor * d + m1
  end
end

puts r

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

const int inf=1000000007;
const int MOD=1000000007;
const long long INF=1000000000000000007;



int main() {
  int k, x;
  cin >> k >> x;

  for (int i = x - k + 1; i <= x + k - 1; i++) {
    if (i == x + k - 1) {
      cout << i << endl;
      return 0;
    }
    cout << i << " ";
  }
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
    }
    println!("{}", c.min(b / a));

}


Measured memory_bytes: 2088
// Knapsack problem
#include <bits/stdc++.h>
#define ll long long
using namespace std;

// dp[i][j] = max value which you can get with atmost 'i' weight and 0....j items
ll dp[1000001][101], value[101];
int wt[101];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, w;
	cin >> n >> w;
	for(int i = 1; i <= n; i++){
		cin >> wt[i] >> value[i];
	}

	for(int i = 0; i <= w; i++){
		dp[i][0] = 0;
	}
	for(int i = 0; i < n; i++){
		dp[0][i] = 0;
	}

	for(int i = 1; i <= w; i++) {
		for(int j = 1; j <= n; j++) { 
			dp[i][j] = dp[i][j-1];
			if(i >= wt[j] && j > 0)
				dp[i][j] = max(dp[i][j], value[j] + dp[i-wt[j]][j-1]);			
		}
	}
	cout << dp[w][n] << endl;

	return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
constexpr ll MOD = 1e9 + 7;

ll pow(ll x, ll p){
    ll ret = 1;
    rep(i, p) ret *= x;
    return ret;
}

int main(){
    ll h;
    cin >> h;
    ll ans = log2(h)+1;
    ans = pow(2LL, ans) - 1;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M, X;
    cin >> N >> M >> X;
    vll C(N, 0);
    v2ll A(N, vll(M, 0));
    rep(i, N) {
        cin >> C[i];
        rep(j, M) {
            cin >> A[i][j];
        }
    }
    ll ans = LINF;
    rep(i, 1 << N) {
        vll B(M, 0);
        ll cost = 0;
        rep(j, N) {
            int mask = (i >> j) & 0x01;
            if (mask != 0) {
                cost += C[j];
                rep(k, M) B[k] += A[j][k];
            }
        }

        bool is_ok = true;
        rep(k, M) {
            if (B[k] < X) {
                is_ok = false;
                break;
            }
        }
        if (is_ok == true) {
            ans = min(cost, ans);
        }
    }
    if (ans == LINF)
        cout << -1 << endl;
    else
      cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3660
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

i64 modpow(i64 a, i64 p = MOD - 2)
{
	if (p == 0) return 1;
	i64 tmp = modpow(a, p / 2);
	tmp = tmp * tmp % MOD;
	if (p % 2) tmp = tmp * a % MOD;
	return tmp;
}

int N, K;
i64 fact[4040404], frev[4040404];
i64 invs[4040404];

i64 C(int a, int b)
{
	if (a < b) return 0;
	return fact[a] * frev[b] % MOD * frev[a - b] % MOD;
}

i64 dp[4020][2020];

i64 solve(int nz, int nk)
{
	if (dp[nz][nk] != -1) return dp[nz][nk];

	if (nz == N && nk == N) return dp[nz][nk] = 1;

	dp[nz][nk] = 0;
	if (nz < N) {
		ADD(dp[nz][nk], solve(nz + 1, nk));
	}
	if (nk < N && nk < nz) {
	//	printf("%d %d, %d %d\n", nz, nk, N * K - nz - nk * (K - 1) - 1, K - 2);
		ADD(dp[nz][nk], solve(nz, nk + 1) * C(N * K - nz - nk * (K - 1) - 1, K - 2) % MOD);
	}
	//printf("%d %d: %lld\n", nz, nk, dp[nz][nk]);
	return dp[nz][nk];
}

int main()
{
	scanf("%d%d", &N, &K);

	if (K == 1) {
		puts("1");
		return 0;
	}
	fact[0] = 1; frev[0] = 1;
	invs[0] = 1;
	invs[1] = 1;
	for (int i = 2; i < 4040404; ++i) invs[i] = MOD - MOD / i * invs[MOD % i] % MOD;
	for (int i = 1; i < 4040404; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
		frev[i] = frev[i - 1] * invs[i] % MOD;
	}

	for (int i = 0; i <= N + K; ++i) {
		for (int j = 0; j <= N; ++j) dp[i][j] = -1;
	}
	i64 sol = solve(0, 0);
	sol = sol * fact[N] % MOD;
	printf("%lld\n", sol);

	return 0;
}


Measured memory_bytes: 158336
import java.util.Scanner;

public class Main {

	private static final long x = (long) Math.pow(10, 18);

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x[] = new long[n + 1];

		x[0] = 2;
		x[1] = 1;
		long ans = 0;
		for (int i = 2; i <= n; i++) {
			ans =  x[i - 1] + x[i - 2];
			x[i] = ans;
		}

		if (n == 1) {
			System.out.println(1);
		} else {
			System.out.println(ans);
		}

		sc.close();
	}

}


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

int main(){
  int a,b;
  cin >> a >> b;
  if(a<0){
    if(b>0)
      cout << "Zero";
    else{
      int c=a-b;
      if(c%2==0)
        cout << "Negative";
      else
        cout << "Positive";
    }
  }else if(a==0)
    cout << "Zero";
  else
    cout << "Positive";
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+7;

ll dp[50];

ll fib(ll n){
    if(n<=1) return 1;
    if(dp[n]!=-1) return dp[n];
    return dp[n]=fib(n-1)+fib(n-2);
}

int main()
{
    ll n;
    cin >> n;
    rep(i,50){
        dp[i]=-1;
    }
    cout << fib(n) << endl;
    
    return 0;
} 


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

using namespace std;
#define ll long long

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

vector<int> a, b;
vector<pair<int, int> > ac, bc;
int n;

bool count(int& pos, int ab)
{
	if (pos == n / 2) return false;
	auto& v = ab ? a : b;
	auto& vc = ab ? ac : bc;
	int x = v[pos];
	pos++;
	int cnt = 1;
	while (pos < n / 2) {
		if (v[pos] != x) break;
		pos++;
		cnt++;
	}
	vc.PB(MP(-cnt, x));
	return true;
}


void init()
{
	cin >> n;
	a.resize(n/2);
	b.resize(n/2);
	rep(i, n / 2) cin >> a[i] >> b[i];
	sort(all(a));
	sort(all(b));
	int pos = 0;
	while (count(pos, 0));
	pos = 0;
	while (count(pos, 1));
	ac.PB(MP(0, -1));
	bc.PB(MP(0, -2));
	sort(all(ac));
	sort(all(bc));
}

void solve()
{
	int mi = n;
	rep(i, 2) {
		rep(j, 2) {
			if (ac[i].second != bc[j].second) {
				mi = min(mi, n + ac[i].first + bc[j].first);
			}
		}
	}
	cout << mi << endl;
}

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

int main() {
  long n,ans,r=0,g=0,b=0;
  string s;
  cin >> n >> s;
  for(long i=0;i<n;i++) {
    if(s[i]=='R') r++;
    else if(s[i]=='G') g++;
    else b++;
  }
  ans=r*g*b;
  for(long i=0;i*2+3<=n;i++) {
    for(long j=i*2+2;j<n;j++) {
      if(s[j]!=s[j-i-1] && s[j-i-1]!=s[j-(i*2)-2] && s[j-(i*2)-2]!=s[j] ) ans--;
    }
  }
  cout << ans << endl;
}

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

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

  string s;
  int runner = 0, out = 0, score = 0;
  while (cin >> s) {
    if (s == "OUT") {
      ++out;
      if (out >= 3) {
	cout << score << endl;
	runner = out = score = 0;
      }
    } else if (s == "HIT") {
      ++runner;
      if (runner > 3) {
	++score;
	--runner;
      }
    } else {
      score += runner + 1;
      runner = 0;
    }
  }
  return 0;
}

Measured memory_bytes: 0
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break

    s = m + f
    if m == -1 or f == -1:
        print("F")
    elif s >= 80:
        print("A")
    elif s >= 65:
        print("B")
    elif s >= 50:
        print("C")
    elif s >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")



Measured memory_bytes: 5596
#include <stdio.h>

int main(void)
{
    int a, b, i, flag;
    char s[12];
    scanf("%d%d", &a, &b);
    scanf("%s", s);
    flag = 0;
    for (i=0; i<a+b+1; i++)
    {
        if (i==a) {
            if (s[i] != '-') {
                flag = 1;
                break;
            }
        } else {
            if (s[i] == '-') {
                flag = 1;
                break;
            }
        }
    }
    if (flag) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 128
import collections
q = int(input())
dq = collections.deque()
ans = []
while q:
    q -= 1
    s = input().split()
    if s[0] == '0':
        if s[1] == '0':
            dq.appendleft(s[2])
        else:
            dq.append(s[2])
    elif s[0] == '1':
        ans.append(dq[int(s[1])])
    else:
        if s[1] == '0':
            dq.popleft()
        else:
            dq.pop()
print('\n'.join(ans))


Measured memory_bytes: 34656
/********************/
/* K B G D E L T A */
/*     DA-IICT      */
/********************/
 
#include<bits/stdc++.h>
using namespace std;
using   ll=long long;
using   ld=long double;
#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define F(i,n)         for(ll i=0;i<n;i++)
#define rep(i,a,b)     for(ll i=a;i<b;i++)
#define repp(i,a,b)    for(ll i=a;i>=b;i--)
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define f              first
#define s              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323
#define mod            1000000007
 
void solve()
{
    ll ans=0,tt=0;

    string s,t;

    cin>>s>>t;

    vector<vector<ll>> a(26);

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

    ll it;

    for(int i=0;i<t.size();i++)
    {
        it=lower_bound(ALL(a[t[i]-'a']),tt)-a[t[i]-'a'].begin();

        if(it==a[t[i]-'a'].size())
        {
            ans+=s.size();

            tt=0;

            it=lower_bound(ALL(a[t[i]-'a']),tt)-a[t[i]-'a'].begin();

            if(it==a[t[i]-'a'].size())
            {
                cout<<-1;

                return;
            }
        }

        tt=a[t[i]-'a'][it]+1;
    }

    ans+=tt;

    cout<<ans<<endl;
}
 
signed main(){
 
    fast;
 
    ll t=1;
 
    //cin>>t;
 
    while(t--)
    {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+10, mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,i; ll res=0;
	cin>>n;
	int a[n+1],b[n];
	for(i=0;i<=n;i++) cin>>a[i];
	for(i=0;i<n;i++) cin>>b[i];
	
	for(i=n-1;i>=0;i--){
		int x=min(a[i+1],b[i]);

		res+=x;
		a[i+1]-=x;
		b[i]-=x;
		
		x=min(a[i],b[i]);
		res+=x;
		a[i]-=x;
		b[i]-=x;

	}
	cout<<res;
	
}
// check for any potential overflow before submitting


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n, c;
int num[200005] = {0};
vector<pair<int, int>> data[100005];

int solve();

int main() {
  cin >> n >> c;
  for(int i = 0; i < n; ++i) {
    int s, t, x;
    cin >> s >> t >> x;
    data[--x].push_back(make_pair(s, t));
  }
  for(int i = 0; i < c; ++i)
    sort(data[i].begin(), data[i].end());
  cout << solve() << endl;
  return 0;
}

int solve() {
  int ans = 0;
  for(int i = 0; i < c; ++i)
    for(int j = 0; j < data[i].size(); ++j) {
      int s = data[i][j].fi, t = data[i][j].se;
      while(j < data[i].size() - 1 &&
            data[i][j + 1].fi == t) {
        t = data[i][++j].se;
      }
      ++num[s * 2 - 1];
      --num[t * 2];
    }
  for(int i = 1; i <= 200000; ++i) {
    num[i] += num[i - 1];
    ans = max(ans, num[i]);
  }
  return ans;
}

Measured memory_bytes: 4608
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  val seq1 = for(i<-1 to 9) yield List(i,i,i)
  val seq2 = for(i<-1 to 7) yield List(i,i+1,i+2)

  def check(m:List[Int], count:Int,u:Int,v:Int):Boolean =
    if(m.length != count) false
    else if(count==2) m(0)==m(1)
    else (u to 8).exists( i=> check(m diff seq1(i),count-3,i+1,v)) || (v to 6).exists(i=> check(m diff seq2(i),count-3,u,i))

  Iterator.continually(readLine).takeWhile ( _!=null ).foreach { line =>
    val l = line.map(_.asDigit).toList
    val m = (1 to 9).filter { i=> if(l.count( _==i ) >= 4) false else check((i::l).sorted,14,0,0) }
    if(m.length>0) println(m.mkString(" ")) else println(0)
  }
}

Measured memory_bytes: 71976
import java.io.PrintWriter;
import java.util.Scanner;

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

        new Solver().solve(in, out);

        in.close();
        out.flush();
    }

    private static class Solver {
        public void solve(Scanner in, PrintWriter out) {
            int length = in.nextInt();
            int re = in.nextInt();
            int[] ints = new int[length];

            for (int i = 0; i < length; i++) {
                ints[i] = in.nextInt();
            }

            int a = 0;
            int b = 0;
            for (int i = 0; i < length; i++) {
                for (int j = 0; j < length; j++) {
                    if (ints[i] <= ints[j]) continue;
                    a++;
                    if (j > i) b++;
                }
            }
            int mod = 1000000007;
            long counter = 0;
            counter += ((long) b * re) % mod;
            counter += (a * ((re * (re - 1L) / 2) % mod)) % mod;

            out.println(counter % mod);
        }
    }
}

Measured memory_bytes: 26056
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=2e5;
const long inf=1e9;
int main(){
	int N; cin>>N;
	int cnt[70000] = {};
	rep(i,1,100)rep(j,1,100)rep(k,1,100){
		int t = i * i + j * j + k * k + i * j + j * k + k * i;
		cnt[t]++;
	}
	rep(i,1,N+1) cout<<cnt[i]<<endl;
}

Measured memory_bytes: 3864
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

class Solve {
  public:
    long long N;
    std::vector<long long>x, y, h;
    struct ans{
      long long x;
      long long y;
      long long h;
    };

    Solve (long long _N) {
      N = _N;
      x.resize(N);
      y.resize(N);
      h.resize(N);
    }

    void push(long long i, long long _x, long long _y, long long _h){
      x[i] = _x;
      y[i] = _y;
      h[i] = _h;
    }

  private:
    long long judge(long long Cx, long long Cy) {
      long long H;
      for(long long i=0; i<N; i++) {
        if ( h[i] == 0 ) continue;
        else {
          H = std::abs(Cx-x[i]) + std::abs(Cy-y[i]) + h[i];
          break;
        }
      }

      for(long long i=0; i<N; i++) {
        if ( std::max(H-std::abs(Cx-x[i])-std::abs(Cy-y[i]), 0LL) != h[i] ) return 0;
      }
      return H;
    }

  public:
    ans Process() {
      ans rtn;
      for(long long i=0; i<=100; i++) {
        for(long long j=0; j<=100; j++) {
          auto H = judge(i,j);
          if ( H != 0 ) {
            rtn.x = i;
            rtn.y = j;
            rtn.h = H;
            return rtn;
          }
        }
      }
      assert(0);
      return rtn;
    }
};

int main (void) {

  long long N; std::cin >> N;

  Solve ans(N);

  for(auto k=0; k<N; k++) {
    long long x, y, h; std::cin >> x >> y >> h;
    ans.push(k,x,y,h);
  }

  auto k = ans.Process();
  std::cout << k.x << " " << k.y << " " << k.h << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long n; cin >> n;
    vector<long long> odd, even;
    rep (i, 0, n) {
        long long a; cin >> a;
        if (i % 2 != 0) odd.push_back(a);
        else even.push_back(a);
    }

    if (n % 2 == 0) {
        reverse(odd.begin(), odd.end());
        rep (i, 0, odd.size()) cout << odd[i] << " ";
        rep (i, 0, even.size()) cout << even[i] << " ";
    }
    else {
        reverse(even.begin(), even.end());
        rep (i, 0, even.size()) cout << even[i] << " ";
        rep (i, 0, odd.size()) cout << odd[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3948
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>

using namespace std;

vector<int> A;
vector<int> B;

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

    A.resize(N);
    B.resize(N);

    for (int i = 0; i < N;i++)
    {
        cin >> A[i];
        B[N - i - 1] = A[i];
    }

    int mi = distance(A.begin(), min_element(A.begin(), A.end())) + 1;

    int p = 1;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        p = p + (K - 1);
        if(mi <= p)
        {
            ans += i + 1;
            break;
        }
    }

    if (p == N)
    {
        cout << ans << endl;
        return 0;
    }

    int q = p;
    for (int i = 0; i < N; i++)
    {
        q = q + (K - 1);
        if (N <= q)
        {
            ans += i + 1;
            break;
        }
    }

    mi = distance(B.begin(), min_element(B.begin(), B.end())) + 1;
    p = 1;
    int ans2 = 0;
    for (int i = 0; i < N; i++)
    {
        p = p + (K - 1);
        if (mi <= p)
        {
            ans2 += i + 1;
            break;
        }
    }

    if (p == N)
    {
        cout << ans2 << endl;
        return 0;
    }

    q = p;
    for (int i = 0; i < N; i++)
    {
        q = q + (K - 1);
        if (N <= q)
        {
            ans2 += i + 1;
            break;
        }
    }

    cout << min(ans, ans2) << endl;

    return 0;
}
/*
8 3
8 4 3 1 6 5 7 2

8 5
8 4 3 1 6 5 7 2

8 3
8 4 1 3 6 5 7 2

8 3
1 8 4 3 6 5 7 2

*/

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eps 1e-8
#define all(v) (v.begin(),v.end())
#define db double
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const double pi=acos(-1.0);
const double inf = 1e100;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
int n;
int q;
int l;
int v[(1<<18)+10],w[(1<<18)+10];
int dp[(1<<9)+10][100100];
int x[100100],y[100100];
int w1[100010];
vector<int>x1;
vector<pair<int,ll>>x2;
ll maxx; 
int dfs(int x,int l){
	if(x<(1<<9)) return dp[x][l];
	if(w[x]<=l)
	return max(dfs(x/2,l),dfs(x/2,l-w[x])+v[x]);
	return dfs(x/2,l);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    rep(i,1,n+1) cin>>v[i]>>w[i];
	rep(i,1,min(n+1,(1<<9))){
    	rep(j,0,100010){
    		dp[i][j]=dp[i/2][j];
    		if(j>=w[i])
    		dp[i][j]=max(dp[i][j],dp[i/2][j-w[i]]+v[i]);
		}
	}
	cin>>q;
	rep(i,1,q+1){
		int x,y;
		cin>>x>>y;
		if(x<(1<<9)){
			cout<<dp[x][y]<<endl;
		}
		else{
			cout<<dfs(x,y)<<endl; 
		}
	}
    return 0;
}



Measured memory_bytes: 205552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
const int maxn=1e5+5;
int main()
{
    ll ans=0;
    ll n;
    scanf("%lld",&n);
    int mid=(int)sqrt(n);
    for(int i=1;i<=mid;i++)
    {
        if(n%i==0)
        {
            ll m=n/i-1;
            if(m&&(n/m)==(n%m))
            ans+=m;
        }
    }
    printf("%lld\n",ans);
}


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

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

    ll k = n;
    int cnt = 1;
    {
        ll m = 1;
        while (k > 26*m) {
            cnt++;
            m *= 26;
            k -= m;
        }
        k--;
    }

    string s = "";
    rep(i,cnt) {
        char c = 'a' + k%26;
        s = c + s;
        k /= 26;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3636
/**
 *    author:  FromDihPout
 *    created: 2020-08-27
**/

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

long long n, k;
vector<int> a;

bool check(int len) {
    long long moves = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] <= len) break;
        moves += (a[i] - 1) / len;
    }
    return moves <= k;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    
    int l = 1, r = a[n-1], ans = a[n-1];
    while (l <= r) {
        int mid = l + (r - l) / 2;
        if (check(mid)) {
            ans = mid;
            r = mid - 1;
        }
        else {
            l = mid + 1;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3980
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<map>
#include <bits/stdc++.h>
typedef long long ll;
#define N 100010
using namespace std;

void solve()
{
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	int len1=h1*60+m1;
	int len2=h2*60+m2;
	cout<<(len2>len1+k?len2-len1-k:0)<<endl;
}

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

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define long long long
#define ull unsigned long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define V vector
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar

using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }

void input()
{
	string s; cin>>s;
	if (s[0]== s[2]) cout<<"Yes"; else cout<<"No";
}

void solve()
{

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive
    #define TASK "tmp"
    //freopen(TASK".inp","r",stdin);
    //freopen(TASK".out","w",stdout);

    input();
    solve();

    return 0;
}


Measured memory_bytes: 256
n = int(input())
w = [input() for _ in range(n)]
# 同じ文字列が含まれていない
if len(set(w)) != n:
    print('No')
    exit()
# 末尾と先頭の文字が同じ（しりとり）
for i in range(1,n):
    if w[i-1][-1] != w[i][0]:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 9104
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int a[5],k;
    REP(i,5)cin>>a[i];
    cin>>k;
    if(a[4]-a[0]>k){
        cout<<":("<<endl;
        return 0;
    }
    cout<<"Yay!"<<endl;
}

Measured memory_bytes: 256