akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

using i64=long long;

const int MOD=1e9+7;

int main() {
    size_t N;
    scanf("%zu", &N);

    vector<i64> P(N);
    int max_=0;

    vector<i64> T(N);
    for (size_t i=0; i<N; ++i) {
        scanf("%lld", &T[i]);
        if (max_ < T[i]) {
            max_ = T[i];
            P[i] = -max_;
        } else {
            P[i] = max_;
        }
    }

    max_ = 0;
    vector<i64> Q(N);
    vector<i64> A(N);

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

    for (size_t i=N; i--;) {
        if (max_ < A[i]) {
            max_ = A[i];
            Q[i] = -max_;
        } else {
            Q[i] = max_;
        }
    }

    vector<i64> R(N);
    for (size_t i=0; i<N; ++i) {
        if (P[i] < 0) {
            if (Q[i] < 0) {
                if (P[i] != Q[i])
                    return !printf("0\n");
            } else {
                if (-P[i] > Q[i])
                    return !printf("0\n");
            }

            R[i] = 1;
        } else {
            if (Q[i] < 0) {
                if (P[i] < -Q[i])
                    return !printf("0\n");

                R[i] = 1;
            } else {
                R[i] = min(P[i], Q[i]);
            }
        }
    }

    i64 res=1;
    for (i64 r: R)
        (res *= r) %= MOD;

    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define repins(a,n) vector<string> a(n);rep(i,n){cin>>a[i];}
#define repind(a,n) vector<double> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define ins(a) string a;cin>>a;
#define ind(a) double a;cin>>a;
template<class T>
inline void out(T a){cout<<a<<endl; }
inline void out(double a){ printf("%.10f\n", a);} 
#define all(x) (x).begin(),(x).end()
#define rep2(i,a,b) for(ll i=(a);i<(b);++i)
#define range(i,s,c) for(ll i=(s);i<(s+c);++i)
using vell = vector<ll>;
using ves = vector<string>;
using ved = vector<double>;

ll mod = 1000000007;

ll mmul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod;}

ll mpow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll d = mpow(a, b / 2);
		return (d * d) % mod;
	}
	return (a * mpow(a, b - 1)) % mod;
}

ll mdiv(ll a, ll b) { return mmul(a, mpow(b, mod - 2)); }

int main()
{
	in(n);
	unordered_map<ll,ll> map;
	rep(i,n){
		ll c;
		cin >> c;
		map[c-1] = i+1;
	}
    rep(i,n){
		out(map[i]);
	}
}

Measured memory_bytes: 4900
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 510000;
static const int INF = (1 << 23);
ll fac[MAX],finv[MAX],inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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


int main() {
    COMinit();
    ll h,w,a,b;
    cin>>h>>w>>a>>b;

    ll ans=0;

    for(int i=b+1;i<=w;i++) {
        ll j=0;

        ll n1=(h-a-1)+(i-1);
        j += COM(n1, i-1);

        j %= MOD;
        ll n2=(a-1)+(w-i);
        j*=COM(n2,a-1);
        j%=MOD;
        ans+=j;
        ans%=MOD;

    }
    cout<<ans<<endl;





    return 0;
}


Measured memory_bytes: 12160
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 200009

int main() {
	int n,i,count[N],max = 0;
	char s[N][11];
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%s",s[i]);
	qsort(s,n,11,strcmp);

	count[0]=1;
	for(i=1;i<n;i++){
		if(!strcmp(s[i-1],s[i]))count[i]=count[i-1]+1;
		else{
			count[i]=1;
			max=(max>count[i-1]?max:count[i-1]);
		}
	}
	max=(max>count[n-1]?max:count[n-1]);
	for(i=0;i<n;i++)if(max==count[i])printf("%s\n",s[i]);
}

Measured memory_bytes: 5692
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    Int a, b,k;
    cin >> a >> b>>k;
    if(k<=a){
        cout << a-k<< ' '  << b << endl;
    }else if (k<=a+b){
        cout << 0 << ' ' << b-(k-a) << endl;
    }else{
        puts("0 0");
    }
}


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

using namespace std;
typedef long long ll;

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    if(A+B+C >= 22){
        cout << "bust" << endl;
    } else
    {
        cout << "win" << endl;
    }
    
}



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

int main()
{
    long N;
    std::cin >> N;
    std::vector<std::vector <long> > x(15,std::vector<long>(15));
    std::vector<std::vector <long> > y(15,std::vector<long>(15));
    std::vector<long> A(15);
    for(long i=0; i<N; i++){
        std::cin >> A[i];
        for(long j=0; j<A[i]; j++){
            std::cin >> x[i][j];
            x[i][j]=x[i][j]-1;
            std::cin >> y[i][j];
        }
    }

    bool boolbox[15];
    long num=1;
    bool breakflag=0;
    long count=0;
    for(long i=0; i<std::pow(2,N); i++){
        for(long j=0; j<N; j++){
            boolbox[j]=1&(i>>j);
        }
        for(long j=0; j<N; j++){
            if(boolbox[j]==1){
                for(long k=0; k<A[j]; k++){
                    if(y[j][k]!=boolbox[x[j][k]]){
                        breakflag=1;
                        break;
                    }
                }
            }
            if(breakflag==1){
                breakflag=0;
                break;
            }
            if(j==N-1){
                long temp=0;
                for(long k=0; k<N; k++){
                    temp+=boolbox[k];
                }
                if(temp>count){
                    count=temp;
                }
            }
        }
    }
    std::cout << count << std::endl;
    return 0;
}

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

namespace ConsoleApp3 {
    class Program {
        static void Main(string[] args) {
            var X = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = X[0];
            int K = X[1];
            int Q = X[2];

            int[] ruikei = new int[N];

            for (int i = 0; i < Q; i++) {
                ruikei[int.Parse(Console.ReadLine()) - 1]++;
            }

            for (int i = 0; i < N; i++) {
                //Console.Write(ruikei[i] + " ");
                if (K - (Q - ruikei[i]) > 0) {
                    Console.WriteLine("Yes");
                } else {
                    Console.WriteLine("No");
                }
            }
        }
    }
}


Measured memory_bytes: 18012
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int k,t;
  cin >> k >> t;
  int a[t];
  REP(i,t) cin >> a[i];
  sort(a,a+t,greater<int>());
  cout << max(2*a[0]-1-k,0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
 int i,n,s,k[25];
 while(cin >> n) {
	 if (n==0) break;
	 for (i=0;i<n;i++) cin >> k[i];
	 s=32; i=0;
	 while (s>0) {
		 s-=(s-1) % 5;
		 cout << s << endl;
		 s=s-k[i]>0 ? s-k[i] : 0;
		 i=(i+1) % n;
		 cout << s << endl;
	 }
 }
return 0;
 }

Measured memory_bytes: 1160
n=int(input())
a=list(map(int,input().split()))
for aa in a:
  if aa==0:
    print(0)
    exit(0)

t=1
for i in range(n):
  if i==0:
    t=a[0]
    if t>10**18:
      print(-1)
      exit(0)
    continue
  t*=a[i]
  if t>10**18:
    print(-1)
    exit(0)
print(t)

Measured memory_bytes: 21468
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

int main() {
	
	int a[] = { 0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1 };
		
	// 配列の添字は 0 から始まるので，a [0] は 0 にしている．
		
	int x, y; 
	
	cin >> x >> y;
		
	cout << (a[x] == a[y] ? " Yes " : " No ") << endl;

	return 0;
	
}



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

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

    double sum = 0.;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        sum += 1.0 / a;
    }
    double ans = 1.0 / sum;
    cout << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define max 500000
#define sentinel 2000000000
int count,L[max/2+2],R[max/2+2];
void merge(int *A,int l,int mid,int r);
void mergesort(int*A,int l,int r);
int main(void){
	int n,A[max];
	memset(A,0,sizeof(A));
	scanf("%d",&n);
	for(int i=0;i<n;i++)	scanf("%d",A+i);
	count=0;
	mergesort(A,0,n);
	for(int i=0;i<n;i++){
		printf("%s%d",i==0? "":" ",A[i]);
	}
	printf("\n%d\n",count);
	return 0; 
}
void mergesort(int*A,int l,int r){
	if(l+1<r){
		int mid=(l+r)/2;
		mergesort(A,l,mid);
		mergesort(A,mid,r);
		merge(A,l,mid,r);
	}
	
}
void merge(int *A,int l,int mid,int r){
	int lenl,lenr,i,j,k;
	lenl=mid-l,lenr=r-mid;
	for(i=0;i<lenl;i++) L[i]=A[l+i];
	for(i=0;i<lenr;i++) R[i]=A[mid+i];
	L[lenl]=R[lenr]=sentinel;
	i=0,j=0;		
	for(k=l;k<r;k++){
		count++;
		if(L[i]<=R[j]) A[k]=L[i++];
		else A[k]=R[j++];
	}	
}


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

int main() {
    char a;
    cin>>a;
    if(a>='A'&&a<='Z'){
        cout<<'A'<<endl;
    }else{
        cout<<'a'<<endl;
    }
}

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

sx,sy,tx,ty = map(int, input().split())

x = tx - sx
y = ty - sy

ans = ""
ans += "U"*y + "R"*x + "D"*y + "L"*x
ans += "L" + "U"*(y+1) + "R"*(x+1) + "D" + "R" + "D"*(y+1) + "L"*(x+1) + "U"

print(ans)

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

using namespace std;

int main(){
  
    int n,m;
	
    cin>>n>>m;
	
    string t = "WBR";
	
    vector<vector<int>> v(n,vector<int>(3,0));
	
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
		
        for(int j=0; j<m; j++){
            for(int k=0; k<3; k++)
			  if(s[j]==t[k]){
                v[i][k]++;
            }
        }
    }
	
    int ans=n*m;
	
    for(int i=1;i<n-1;i++)
	  for(int j=i+1;j<n;j++){
        int cnt=0;
        for(int k=0;k<i;k++)
		  cnt+=v[k][1]+v[k][2];
        
        for(int k=i;k<j;k++)
		  cnt+=v[k][0]+v[k][2];
        
        for(int k=j;k<n;k++){
		  cnt+=v[k][0]+v[k][1];
        }
        ans = min(ans,cnt);
    }
    cout<<ans<<endl;
}



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

int main(){

  int a,b;
  cin >> a >> b;
  
  if( a%2 == 1 && b%2 == 1 ){
    
    cout << "Yes" << endl;
    
  }
  
  else{
    
    cout << "No" << endl;
    
  }
  
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int a,b,c;cin>>a>>b>>c;

    cout<<max(0,c-a+b)<<endl;

}


Measured memory_bytes: 256
macro_rules! input {
    ($ttype:ty) => {
        {
            let mut input = String::new();
            let _= std::io::stdin().read_line(&mut input);
            input.trim().parse::<$ttype>().unwrap()
        }
    };

    ($($ttype:ty),*) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let mut iter = input.trim().split_whitespace();
            (
                $(iter.next().unwrap().parse::<$ttype>().unwrap(),)*
            )
        }
    };

    ($ttype:ty; $x:expr) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let v: Vec<$ttype> = input
                .trim()
                .split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect();
            v
        }
    };

    ($ttype:ty; $x:expr; $y:expr) => {
        {
            use std::io::BufRead;
            let mut matrix = Vec::with_capacity($y);
            for _ in 0..$y {
                let mut input = String::new();
                let stdin = std::io::stdin();
                let _ = stdin.lock().read_line(&mut input);
                let v: Vec<$ttype> = input
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect();
                matrix.push(v);
            }
            matrix
        }
    };
}

fn main() {
    let n = input!(usize);
    let mut lst: Vec<(i32, i32, i32)> = Vec::with_capacity(n);
    for _ in 0..n {
        lst.push(input!(i32, i32, i32));
    }

    let mut now: (i32, i32, i32) = (0, 0, 0);

    for next in lst.iter() {
        let delta_t = next.0 - now.0;
        let delta_x = (next.1 - now.1).abs();
        let delta_y = (next.2 - now.2).abs();
        if delta_x + delta_y > delta_t || (delta_x + delta_y - delta_t) % 2 != 0 {
            println!("No");
            return;
        }
        now = *next;
    }
    println!("Yes");
}

Measured memory_bytes: 4352
N, K = [int(i) for i in input().split()]
hs = [int(input()) for _ in range(N)]
hs.sort()
diffs = []
for lh in range(N):
    rh = lh + K - 1
    if rh >= N:
        break
    diffs.append(hs[rh] - hs[lh])
print(min(diffs))

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

int main(){
  string S;
  int cnt=0;
  cin >> S;
  int len = S.size();
  for(int i=0; i<len/2; i++){
    if(S[i]!=S[len-i-1]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

int main(){
  int x,y;
  cin >> x >> y;
  int max = x+y;
  if(max < x - y)
    max = x -y;
  if(max < x * y)
    max = x * y;
  cout << max << endl;
  return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>

using namespace std;

int dp[100001];

int main()
{
    
    int n,i,j,k;
    
    cin>>n>>k;
    
    int h[n];
    
    for(i=0;i<n;i++)
        cin>>h[i];
    dp[0]=0;
    for(i=1;i<n;i++)
    {
        dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        if(i>=2)    
        for(j=2;j<=min(i,k);j++)
        {
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))   ;
        }
    }
    
    cout<<dp[n-1]<<endl;
    
    
    
    
    return 0;
    
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    //Input
    Scanner scanner = new Scanner(System.in);
    int total_element = scanner.nextInt();
    int[] data_array = new int[total_element];
    for (int i = 0; i < total_element; i++) {
      data_array[i] = scanner.nextInt();
    }


    //selectionSort
    int count = 0;
    for (int i = 0; i < total_element; i++) {
      int min_element = i;
      for (int j = i + 1; j < total_element; j++) {
        if(data_array[j] < data_array[min_element]) {
          min_element = j;
        }
      }
      if(i != min_element) {
        int bf = data_array[i];
        data_array[i] = data_array[min_element];
        data_array[min_element] = bf;
        count++;
      }
    }

    //Output
    
    for (int i = 0; i < total_element - 1; i++) {
      System.out.print(data_array[i] + " ");
    }
    System.out.println(data_array[total_element - 1]);
System.out.println(count);
  }

}



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

int main(){
  int k, x;
  cin >> k >> x;
  int m = max(-1000000, x-k+1);
  int M = min(1000000, x+k-1);
  for(int i=0; i<M-m+1; i++){
    cout << m+i << " ";
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
using namespace std;

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

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define ll long long

int main() {
    ll N, ans = 0;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        if (i % 15 == 0) {
        } else if (i % 5 == 0) {
        } else if (i % 3 == 0) {
        } else {
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;


int main(){
    vi p;
    int n;
    while(cin>>n){
        p.clear();
        rep(i,n){
            int a;
            cin>>a;
            p.pb(a);
        }
        sort(all(p));
        int sum=0;
        int bef=0;
        rep(i,p.sz){
            sum+=bef+p[i];
            bef+=p[i];
//            dump(bef);
        }
        cout<<sum<<endl;
    }

    
    return 0;
}

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

int main()
{
	long long x,y;
	int s=0;
	
	s=1;
	cin>>x>>y; 
	
	while(y>=x*2)
	{
		x=x*2;
		s++;
	}
	
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;

int main() {
    int n; cin >> n;
    deque<int> deq;
    if(n % 2==0){
        for(int i = 0;i < n;i++){
            int x ; cin >> x;
            if(i%2 ==0){
                deq.push_back(x);
            }else{
                deq.push_front(x);
            }
        }
    }else{
        for(int i = 0;i < n;i++){
            int x ; cin >> x;
            if(i%2 ==0){
                deq.push_front(x);
            }else{
                deq.push_back(x);
            }
        }
    }
    for(auto m:deq){
        cout << m << " ";
    }
}




Measured memory_bytes: 2944
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
//  val list = List.fill(3)(sc.nextInt)
  val n, m = sc.nextInt

  val ans = (n - 1) * (m - 1)

  println(ans)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

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

const int MOD = 1000000007;

int main()
{
  long long N;
  cin >> N;
  vector<pair<long long, long long>> data(N);
  for (int i = 0; i < N; i++)
  {
    long long x, l;
    cin >> x >> l;
    data[i].first = x + l;
    data[i].second = x - l;
  }
  sort(data.begin(), data.end());
  long long int ans = 0, work = -1LL << 60;
  for (int i = 0; i < N; i++)
  {
    if (work <= data[i].second)
    {
      ans++;
      work = data[i].first;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons;
const dx = [1,0,-1,0];
const dy = [0,1,0,-1];
void read(T...)(auto ref T args){ 
	auto line = readln().split(); 
	if (line.length < args.length) return;
	foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));
}
struct Info{int dist,cost;}
void main(){	
	int n,m;
	while(read(n,m),n|m){
		Info[] infos;
		foreach(_;n.iota){
			int d,c;read(d,c);
			infos ~= Info(d,c); 
		}
		infos.sort!("a.cost > b.cost");
		int sum = reduce!("a + b.dist * b.cost")(0,infos);
		foreach(info;infos){
			if (m <= 0 ) break;
			int use_m = min(m,info.dist);
			m -= use_m;
			sum -= use_m * info.cost;
		}
		sum.writeln;
	}
}

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

int main(){
    int N;
    int K;
    int num = 1;
    cin >> N;
    cin >> K;
    rep(i, N){
        if (num * 2 >= num + K){
            num += K;   
        }
        else
        {
            num *= 2;
        }
        
    }
    cout << num << endl;
}

Measured memory_bytes: 3612
import java.util.*;
 
public class Main {
	
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int ans = 100000;
		for(int i=0;i<n;i++){
			ans *= 1.05;
			if(ans%1000>0){
				ans = ((ans/1000)+1) * 1000;
			}
		}
		cout(ans);
	}
	
	
	
	public static void cout(int n){
		System.out.println(n);
	}
}

Measured memory_bytes: 26384
#include <stdio.h>
main(){
  int i,n,j,sum,big,a[5555];
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
    }
    big=-100000000;
    for(i=0;i<n;i++){
      sum=0;
      for(j=i;j<n;j++){
	sum+=a[j];
	if(sum>big){
	  big=sum;
	}
      }
    }
    printf("%d\n",big);
  }
  return 0;
}
	
    

Measured memory_bytes: 616
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	int k, s;
	cin >> k >> s;
	long long int ans;
	for(int i = 0; i <= k; i++){
		for(int j = 0; j <= k; j++){
			if(0 <= s-i-j && s-i-j <= k) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    string x; cin >> x;
    long long s_c = 0;
    long long ans = 0;
    for(int i = 0; i < x.size(); i++) {
        if(x[i] == 'S') {
            s_c++;
        } else if(x[i] == 'T') {
            if(s_c >= 1) {
                s_c--;
                ans++;
            }
        }
    }
    cout << x.size() - (ans * 2) << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int i = 0;
  int count = 0;
  while (i <= A && i <= X/500) {
    int j = 0;
    int x = X - 500*i;
    while (j <= B && j <= x/100) {
      int k = 0;
      int y = x - 100*j;
      if (y/50 <= C) {
        count++;
      }
      j++;
    }
    i++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
//#include "pch.h"
//#include "stdafx.h"
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define MIN(a, b)		((a) < (b) ? a : b)
#define MAX(a, b)		((a) > (b) ? a : b)
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)		/* 奇数 */
#define IsEven(x)		(!IsOdd((x)))					/* 偶数 */
#define ArrayLength(x)	(sizeof(x) / sizeof(x[0]))

typedef short SWORD;
typedef unsigned short WORD;
typedef long SDWORD;
typedef unsigned long DWORD;
typedef long long int QWORD;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
DWORD dp[200 * 1000];
int h[200 * 1000];
int main()
{
	int N;
	cin >> N;
	REP(i, N)	cin >> h[i];

	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	REPN(i, 2, N) {
		dp[i] = MIN(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[N - 1];
	cout << endl;
	return 0;
}



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

int main() {
    long long int n,i,j;
    cin>>n;
    long long int a[n],temp[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        temp[a[i]-1]=i+1;
        
    }
    for(i=0;i<n;i++)
    cout<<temp[i]<<" ";

 
     

  return 0;
    
}
    


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    int m1 = x % 100;
    int m2 = x / 100;
    bool f1 = (m1 >= 1 && m1 <= 12);
    bool f2 = (m2 >= 1 && m2 <= 12);
    if (f1 && f2) {
        cout << "AMBIGUOUS\n";
    } else if (f1) {
        cout << "YYMM\n";
    } else if (f2) {
        cout << "MMYY\n";
    } else {
        cout << "NA\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int N;
int r[105],c[105];
ll dp[105][105]={0};

void dbg()
{
	for(int i=0;i<N;i++,puts(""))
		for(int j=0;j<N;j++)
			printf("%7d ",dp[i][j]);
}

int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)
		scanf("%d%d",&r[i],&c[i]);
	for(int i=0;i<N;i++)dp[i][i]=0;
	for(int l=1;l<N;l++)
		for(int i=0;i<N-l;i++)
		{
			int j=i+l;
			dp[i][j]=1e15;
			for(int k=i;k<j;k++)
			{
				//printf("%d %d %d %d\n",i,j,i+l,k);
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*c[k]*c[j]);
			}
		}
	//dbg();
	printf("%lld\n",dp[0][N-1]);
	return 0;
}

Measured memory_bytes: 1272
#include <stdint.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B) {
  vector<ll> sum_a(N + 1);
  sum_a[0] = 0;
  REP(i, N) {
    sum_a[i + 1] = sum_a[i] + A[i];
  }
  vector<ll> sum_b(M + 1);
  sum_b[0] = 0;
  REP(i, M) {
    sum_b[i + 1] = sum_b[i] + B[i];
  }
  ll ans = 0;
  REP(i, N + 1) {
    if (sum_a[i] <= K) {
      ll ng = (ll)sum_b.size();
      ll ok = 0;
      while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (sum_a[i] + sum_b[mid] <= K) {
          ok = mid;
        } else {
          ng = mid;
        }
      }
      ll c = i + ok;
      if (ans < c) {
        ans = c;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &B[i]);
  }
  solve(N, M, K, std::move(A), std::move(B));
  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

int n, m;

void read() {
	cin >> n >> m;
	while (m--) {
		int x;
		cin >> x;
		n -= x;
	}
	chkmax(n, -1);
	cout << n << endl;
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<vector>
#include<cmath>

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

using namespace std;


int main(){

    int n;
    cin >> n;

    int a[n];
    int ans = 0;
    rep(i,0,n){
        cin >> a[i];
        ans += a[i];
    }

    cout << ans-n << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;

/**
 * @author Tran Anh Tai
 * @template for CP codes
 * What a trick prob!
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
    // main solver
    static class Task{
        public void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a =new int[4];
            for (int i = 0; i < n; i++){
                String r = in.nextToken();
                if (r.equals("AC")){
                    a[0]++;
                }
                else if(r.equals("WA")){
                    a[1]++;
                }
                else if (r.equals("TLE")){
                    a[2]++;
                }
                else{
                    a[3]++;
                }
            }
            out.println("AC x " + a[0]);
            out.println("WA x " + a[1]);
            out.println("TLE x " + a[2]);
            out.println("RE x " + a[3]);
        }
    }
    // fast input reader class;
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (line == null) {
                    return null;
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        public long nextLong(){
            return Long.parseLong(nextToken());
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  
  double T;
  T = N;
  
  if(N % 2 ==0){
    cout << 0.5 << endl;
  } else {
    cout << ((T+1)/2)/T << endl;
  }
}


Measured memory_bytes: 3756
a, b = map(float, input().split()) 
a = int(a)
b*=100
b = int(round(b))
# print(a,b)
ans = a*b
ans = ans//100
print(ans)

# import math
# print(0.11*100)
# i = 0.01
# while i <= 1.00:
#     print(round(i*100))
#     i+=0.01

Measured memory_bytes: 9036
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i < (n); i++)
const int INF = 1e9;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  rep(i,h) cin >> g[i];
  vector<vector<int>> cnt(h, vector<int>(w,INF));
  rep(i,h) rep(j,w) {
    if (g[i][j] == '#') continue;
    int c = 0;
    for (int di = -1; di <= 1; di++) {
      for (int dj = -1; dj <= 1; dj++) {
        int ni = i + di;
        int nj = j + dj;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (g[ni][nj] == '#') c++;
      }
    }
    cnt[i][j] = c;
  }
  rep(i,h) {
    rep(j,w) {
      if (cnt[i][j] == INF) cout << '#';
      else cout << cnt[i][j];
    }
    cout << endl;
  }
}

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

int main() {
	// your code goes here
	cin.tie(NULL);
	cout.tie(NULL);
	int n;cin>>n;
	int x=n%10;
	if(x==2 || x==4 || x==5 || x==7 || x==9){
		cout<<"hon";
	}
	 if(x==0 || x==1 || x==6 || x==8 ){
		cout<<"pon";
	}
	if(x==3) cout<<"bon";
}


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

const int MAXN = 100000;

int BobEven(int n, int *A) {
    int M = n / 2;
    int res = INT_MAX;
    for(int i = 1; i <= M; i++)
        res = min(res, A[M+i]-A[i]);
    return res;
}

int AliceOdd(int n, int *A) {
    int M = n / 2;
    for(int i = M + 1; i < n; i++) A[i] = A[i + 1];
    return BobEven(n - 1, A);
}
bool check(int n, int *A, int M) {
    int cnt = 0;
    int last = 1;
    for(int i = 1; i <= n; i++)
        if(A[i] - A[last] > M)
            cnt++, last = i;
    return cnt >= n / 2;
}
int AliceEven(int n, int *A) {
    int L = 1, H = A[n] - A[1];
    while(L<H) {
        int M = L + H >> 1;
        if(check(n, A, M))
            L = M+1;
        else H = M;
    }
    return L;
}
int BobOdd(int n, int *A) {
    return min(AliceEven(n - 1, A), AliceEven(n - 1, A + 1));
}

int n, A[MAXN + 10];

int main() {

    string name;
    cin >> n >> name;
    for(int i = 1; i <= n; i++)
        scanf("%d", &A[i]);

    if(name == "Alice") {
        if(n & 1) cout << AliceOdd(n, A) << endl;
        else cout << AliceEven(n, A) << endl;
    }
    else {
        if(n & 1) cout << BobOdd(n, A) << endl;
        else cout << BobEven(n, A) << endl;
    }

    return 0;
}

Measured memory_bytes: 1644
class Heap
  attr_reader :size

  def initialize
    @heap = []
    @size = 0
  end

  def push(n)
    i = @size
    while i > 0 do
      parent_index = (i - 1) / 2
      break if n >= @heap[parent_index]

      @heap[i] = @heap[parent_index]
      i = parent_index
    end

    @heap[i] = n
    @size += 1
  end

  def pop
    return if @size <= 0
    min_n = @heap[0]
    @size -= 1
    n = @heap[@size]
    i = 0
    while i * 2 + 1 < @size do
      child_index1 = i * 2 + 1
      child_index2 = i * 2 + 2
      if child_index2 < @size && @heap[child_index2] < @heap[child_index1]
        child_index1 = child_index2
      end
      break if @heap[child_index1] >= n

      @heap[i] = @heap[child_index1]
      i = child_index1
    end
    @heap[i] = n
    min_n
  end

  def min; @heap[0] end
  def values; @heap.first(@size) end
  def inspect; "Heap: #{values}" end
end

n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = Heap.new()
e = a.map{|x| b.push(-x)}
m.times do
  c = b.pop
  b.push(-(-c / 2))
end
ans = 0
while b.size > 0
  ans -= b.pop
end
puts ans

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

int d[5][16] = {0};

int main(){
    int n;
    
    
    scanf("%d", &n);
    int i;
    for(i = 0; i < n; i++){
        char c, c1;
        int a;
        scanf(" %c %d", &c, &a);
        // printf("%c %d\n", c, a);
        if(c == 'S') d[0][a - 1] = 1;
        else if(c == 'H') d[1][a - 1] = 1;
        else if(c == 'C') d[2][a - 1] = 1;
        else d[3][a - 1] = 1;
    }
    int j;
    char m;
    for(i = 0; i < 4; i++){
        for(j = 0; j < 13; j++){
            if(d[i][j] == 0){
                if(i == 0){
                    m = 'S';
                }else if(i == 1){
                    m = 'H';
                }else if(i == 2){
                    m = 'C';
                }else{
                    m = 'D';
                }
                printf("%c %d\n", m, j + 1);          
            }
        }
    }
    return 0;
}

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

using namespace std;

void solve() {
    int n; cin >> n;
    int mn = 1e9, ans = 0;
    for (int i = 0; i < n; i++) {
        int v; cin >> v;
        if (v < mn) ans++;
        mn = min(mn, v);
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    for(; ; ){
	c -= b;
	a -= d;
	if(c<=0){
	    cout << "Yes" << endl;
	    return 0;
	}
	else if(a<=0){
	    cout << "No" << endl;
	    return 0;
	}
	
    }


} 




Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <list>
using namespace std;
 
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define pb push_back
 
int INF = INT_MAX / 10;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	string t; cin >> t;
	string s; cin >> s;
	int N = s.length();
	vector<int> a(N + 1);
	a[0] = -1;
	int k = -1;
	rep(i, N) {
		for (; k != -1 && s[k] != s[i]; k = a[k]);
		a[i + 1] = ++k;
	}
	int M = t.length();
	int i = 0, j = 0;
	while (j <= M)
		if (i < N && j < M && s[i] == t[j])
			i++, j++;
		else {
			if (i == N) printf("%d\n", j - N);
			if (i) i = a[i];
			else j++;
		}
}

Measured memory_bytes: 3984
import sys

input = sys.stdin.readline
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
 
ans = -float('inf')
for s in range(N):
    S = [] 
    i = P[s] - 1
    S.append(C[i])
    while i != s:
        i = P[i] - 1
        S.append(S[-1] + C[i])
 
    if K <= len(S):
        tmp = max(S[:K])
    elif S[-1] <= 0:
        tmp = max(S)
    else:
        # ループの中で最大となるところで止める
        tmp1 = S[-1] * (K // len(S) - 1)
        tmp1 += max(S)
        # 限界まで進む
        tmp2 = S[-1] * (K // len(S))
        r = K % len(S)
        if r != 0:
            tmp2 += max(0, max(S[:r]))
        tmp = max(tmp1, tmp2)
 
    ans = max(ans, tmp)
 
print(ans)

Measured memory_bytes: 80884
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

#define MOD 1000000007

int n;
vector<int> edge[100000];



pair<int, int> dfs(int u, int par) {
	bool leaf = true;
	long long w = 1, b = 1;

	for (int v : edge[u]) if (par != v) {
		auto p = dfs(v, u);
		leaf = false;
		(w *= p.first + p.second) %= MOD;
		(b *= p.first) %= MOD;
	}
	if (leaf) {
		return make_pair(1, 1);
	}
	pair<int, int> ret(w, b);
	return ret;
}


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

	cin >> n;
	rep(i, n - 1) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}

	auto p = dfs(0, -1);
	cout << (p.first + p.second)%MOD << endl;

	

	return 0;
}


Measured memory_bytes: 12672
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int n,k;
    cin>>n>>k;
    vector<long long int> v(n),dp(n,999999999999);
    dp[0]=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int i=0;i<n-1;i++){
        for(int j=1;j<=k;j++){
            if(j+i<n){
                dp[j+i]=min(dp[i]+abs(v[i]-v[i+j]),dp[j+i]);
            }

        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
int dx[6]={1,1,0,-1,-1,0},dy[6]={1,0,-1,-1,0,1};

int grid[200][200];

piii makePiii(int a,int b,int c){
  pii A=make_pair(b,c);
  piii res=make_pair(a,A);
  return res;
}

int bfs(int t,int sx,int sy){
  int res=1;
  queue<piii> q;
  q.push(makePiii(0,sx,sy));
  while(!q.empty()){
    int x=q.front().second.first;
    int y=q.front().second.second;
    int cnt=q.front().first;
    q.pop();
    if(cnt == t)continue;
    //cout << "cnt:" << cnt << " q.size:" << q.size()<< endl;

    for(int i=0;i<6;i++){
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(grid[ny][nx]==0){
	//cout << "nx:" << nx << " ny:" << ny << endl;
	grid[ny][nx]=-1;
	res++;
	q.push(makePiii(cnt+1,nx,ny));
      }
    }
  }
  return res;
}
const int base=100;
int main(){
  int t,n;
  while(cin>>t>>n){
    if(t==0 && n==0)break;
    memset(grid,0,sizeof(grid));
    for(int i=0;i<n;i++){
      int x,y;
      cin>>x>>y;
      grid[y+base][x+base]=-1;
    }
    int sx,sy;
    cin>>sx>>sy;
    grid[sy+base][sx+base]=-1;
    cout <<  bfs(t,sx+base,sy+base) << endl;
  }
  return 0;
}

Measured memory_bytes: 1380
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
from itertools import permutations,groupby
import sys
import bisect
import string
alp=string.ascii_lowercase
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7
#mo=998244353
#input=sys.stdin.readline

n=I()
s=list(input())
ans=0
t=[]
l,r=0,0
for i in range(n*2):
    if i==0:
        t+=['L']
        l+=1
        continue
    if ((l-r)%2==1 and s[i]=='W') or ((l-r)%2==0 and s[i]=='B'):
        t+=['L']
        l+=1
    else:
        t+=['R']
        r+=1
if t.count('L')!=n:
    print(0)
    exit()
    
#print(s,t)
L,R=0,0
ans=1
for i in t:
    if i=='L':
        L+=1
    if i=='R':
        ans*=L-R
        ans%=mo
        R+=1
f=1
for i in range(2,n+1):
    f*=i
    f%=mo
print((ans*f)%mo)



Measured memory_bytes: 62412
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    a = (n-1)//2 + 1
    if a>=k:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	int ct=0, abmn=MD;
	ll ans = 0;
	for(auto x: a){
		ct += x < 0;
		abmn = min(abmn, abs(x));
		ans += abs(x);
	}
	if(ct & 1) ans -= 2LL * abmn;
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pr(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
#define BLACK 0
#define WHITE 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    ll N;
    P blue[110], red[110];
    ll i, j;
    cin >> N;
    for(i=0; i<N; i++) {
        cin >> red[i].second >> red[i].first;
    }
    sort(red, red+N);
    
    for(i=0; i<N; i++) {
        cin >> blue[i].first >> blue[i].second;
    }
    sort(blue, blue+N);
    
    ll ans=0;
    for(i=0; i<N; i++) {
        for(j=N-1; j>=0; j--) {
            if(blue[i].first==INF || red[j].first==INF) continue;
            if(red[j].second<blue[i].first && red[j].first<blue[i].second) {
                ans++;
                blue[i].first=INF;
                red[j].first=INF;
            }
        }
    }
    
    pr(ans);
    
    
}

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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    int n, m;
    cin >> n >> m;
    vt<int> a(n);
    for (int &i : a) cin >> i;

    sort(rall(a));
    if (a[m - 1] < (accumulate(all(a), 0) + 4 * m - 1) / (4 * m))
        cout << "No";
    else cout << "Yes";
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int K;  cin >> K;
  int ans = 0;
  for(int i = 1; i <= K; i++)
    for(int j = i + 1; j <= K ; j++)
      if(i % 2 == 0 && j % 2 == 1 || i % 2 == 1 && j % 2 == 0)
        ans += 1;

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

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});
/*
process.on('SIGINT', function(){
    input_stdin_array = input_stdin.split("\n");
    main();
    process.exit();
});
*/
process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////


function main() {
	var N = parseInt(readLine());
	var K = parseInt(readLine());
	var X = parseInt(readLine());
	var Y = parseInt(readLine());
	var res=0;
	
	for (var i=1; i <= N; i++){
		if (i <= K) res += X;
		else res += Y;
	}
	
	console.log(res);
}

Measured memory_bytes: 7880