akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).end()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a,n) sort(a, a+n)
#define sortvec(V) sort(all(V))

typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

template <class T>
T fac(T n)      // template function to find factorial of a number
{ 
    T res = 1, i; 
    for (i = 2; i <= n; i++) 
        res *= i; 
    return res; 
}
template<class T>
T lcm(T a, T b)     //template function to find lcm of two numbers 
{
    return (a * b) / __gcd(a,b);
}
template<class T>
T digitsum(T x)
{
    T sum = 0;
    while(x)
    {
        sum += x%10;
        x /= 10;
    }
    return sum;
}
// ternary search
/*double ternary(double l, double r){
    double eps = 1e-9;
    while(r - l > eps){
        double m1 = l + (r - l)/3;
        double m2 = r - (r - l)/3;
        double f1 = f(m1);
        double f2 = f(m2);
        if(f1 < f2)
            l = m1;
        else r = m2;
    }
    return f(l);
}*/
void nPermute(string str, int n)  //function to find nth  lexi string
{ 
    sort(all(str));
    int i = 1; 
    do {
        if (i == n) 
            break; 
  
        i++; 
    } while (next_permutation(str.begin(), str.end())); 
    cout<<str<<endl;
} 
vector<int> factors(int n) 
{ 
    vector<int> f; 
    for(int x = 2; x * x <= n; x++) { 
        while (n % x == 0) { 
            f.push_back(x); 
            n /= x; 
        } 
    } 
    if (n > 1) f.push_back(n); 
    return f; 
}
bool prime(int n) 
{ 
    if (n < 2)
        return false;
    for(int x = 2; x*x <= n; x++) 
        if (n%x == 0) 
            return false; 
    return true; 
}
// binomial coeficient in O(K) 
int ncr(int n, int k){
    int res = 1;
    if(k > n - k)
        k = n - k;
    for(int i = 0; i < k; i++){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}
tuple<int, int, int> Gcd(int a, int b)      //extended Euclids Algorithm
{
    if(b == 0)
        return {1, 0, a};
    else{
        int x, y, g;
        tie(x, y, g) = Gcd(b, a%b);
        return {y, x - (a/b)*y, g};
    }
}
template<class T>       // modular Exponentiation x^n mod m = x^(n mod (m - 1)) mod m : if n  is very large;
T binpow(T a, T b, T m) {
    a %= m;
    T res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
void solve()
{
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}

Measured memory_bytes: 3804
import static java.lang.System.*;
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		String s = sc.next();
		boolean a=false,b=false,c=false;
		if (s.contains("a")) a = true;
		if (s.contains("b")) b = true;
		if (s.contains("c")) c = true;
		
		if (a && b && c) out.println("Yes");
		else out.println("No");
	}
}

Measured memory_bytes: 21716
import sys
input = sys.stdin.readline
#import math #python 3.5~
import fractions #fractions.gcd() python~3.4
sys.setrecursionlimit(1000000)

def main(): 

    A,B = map(int,input().split())
    ans=0
    for i in range(2):
        if A > B:
            ans+=A
            A-=1
        else:
            ans+=B
            B-=1
    print(ans)


if __name__ == "__main__":
    main()
    

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const double PI = acos(-1.0);

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

	int a, b;
	string op;
	while(1) {
		cin >> a >> op >> b;
		int ans;
		if(op == "?") break;
		if(op == "+") ans = a + b;
		if(op == "-") ans = a - b;
		if(op == "*") ans = a * b;
		if(op == "/") ans = a / b;
		cout << ans << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>

using namespace std;

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

        for(int i=0;i<s.size();i++){

             if(s[i]+x<='Z')
                 cout<<(char)(s[i]+x);
             else
             {
                 int temp=x+s[i]-'Z';
                 cout<<(char)('A'+temp-1);



             }



        }

cout<<endl;


    return 0;

}

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

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

#define N_MAX 2010100
ll f[N_MAX],rf[N_MAX];   
//f[n]  := n!
//rf[n] := (n!)^-1

ll modpow(ll a,ll b){    // aのb乗
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

void init(){
    f[0] = 1;
    for(ll i = 1; i < N_MAX; i++){
        f[i] = (i * f[i-1]) % mod;
    }
    for(ll i = 0; i < N_MAX; i++){
        rf[i] = modpow(f[i],mod-2);
    }
}

ll com(ll n, ll k){
    //init();
    ll a = f[n];
    ll b = rf[k];
    ll c = rf[n-k];

    ll bc = (b * c) % mod;

    return ((a * bc) % mod);
}

int main()
{
    ll k; cin >> k;
    string s; cin >> s;
    ll n = s.size();
    init();

    ll ans = 0;

    for(ll i = 0; i <= k; i++){

        ans += com((n-1+k-i),(n-1))*modpow(25,k-i)%mod*modpow(26,i)%mod;
        ans %= mod;
    }
    
    cout << ans<< endl;
}


Measured memory_bytes: 35812
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//static int
//cmp (const void *a, const void *b) {
//    return *(int*)a - *(int*)b;
//}

int main (void) {
    int n, k, i;//, j;
    scanf("%d%d", &n, &k);
    int p[n+1];//, tmp1[k], tmp2[k];
    for ( i=0; i<n; i++ )
        scanf("%d", &p[i]);
    p[n] = 0;

    int ans_head_idx=0, max=0, sum=0;
    for ( i=0; i<k; i++ )
        sum += p[i];
    for ( i=k-1; i<n; i++ ) {
        if ( max < sum ) {
            max = sum;
            ans_head_idx = i-k+1;
        }
        //else if ( max == sum ) {
        //    memcpy(tmp1, &p[i-k+1], k*sizeof(int));
        //    memcpy(tmp2, &p[ans_head_idx], k*sizeof(int));
        //    qsort(tmp1, k, sizeof(int), cmp);
        //    qsort(tmp2, k, sizeof(int), cmp);
        //    for ( j=0; j<k; j++ ) {
        //        if ( tmp1[j] > tmp2[j] ) {
        //            ans_head_idx = i-k+1;
        //            break;
        //        }
        //    }
        //}
        sum += p[i+1] - p[i-k+1];
    }

    double ans=0;
    for ( i=ans_head_idx; i<ans_head_idx+k; i++ ) {
        ans += p[i]/2.0 + 0.5;
    }

    printf("%lf\n", ans);


    return EXIT_SUCCESS;
}


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

using namespace std;

int main()
{
	string s, t("CODEFESTIVAL2016");
	int cnt = 0;
	
	cin >> s;
	
	for (int i = 0; i < 16; i++) {
		if (s[i] != t[i]) cnt++;
	}
	
	cout << cnt << endl;
	
	return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

lli gcd(lli a, lli b){
	if(!b) return a;
	return gcd(b, a%b);
}

int main(){
	ios_base::sync_with_stdio(false);
	lli a, b;
	cin >> a >> b;
	lli g = gcd(a, b);
	lli res=0LL;
	
	for(lli i=2; i*i<g; i++){
		if(g%i == 0){
			while(g%i == 0) g /= i;
			res++;
		}
	}
	if(g > 1) res++;
	cout << res+1;
	return 0;
}

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

		int N = sc.nextInt();
		int K = sc.nextInt();	//K <= N
		int a = N - K;
		int b = K - 1;
		int c = 0;
		if( a%b!=0 ){
			c = 1;
		}
		System.out.println(1+a/b+c);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
ll N,M;
int main(){
	cin>>N>>M;
	if (N>M){
		swap(N,M);
	}
	ll ans;
	if(N==1){
		if (M==1){
			ans=1;
		}else{
			ans=M-2;
		}
	}else{
		ans=(N-2)*(M-2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
ans=0
shogen=[]
n=int(input())
for _ in range(n):
  t=[]
  a=int(input())
  for __ in range(a):
    h=list(map(int,input().split()))
    t.append(h)
  shogen.append(t)
for i in range(2**n):
  flag=True
  for j in range(n):
    if not flag:
      break
    if ((i>>j) & 1):
      for h in shogen[j]:
        if ((i>>h[0]-1)&1) !=h[1]:
          flag=False
  if flag:
    mnt = bin(i).count("1")
    ans=max(ans,mnt)
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

struct Node {
    struct Node* parent;
    struct Node* left;
    struct Node* right;
    int key;
};

static struct Node* Insert(struct Node* tree, struct Node* z) {
    struct Node* ret = NULL;
    struct Node* y = NULL;
    struct Node* x = tree;

    while ( x != NULL ) {
        y = x;
        if ( z->key < x->key ) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;

    if ( y == NULL ) {
        ret = z;
    } else if ( z->key < y->key ) {
        y->left = z;
        ret = tree;
    } else {
        y->right = z;
        ret = tree;
    }

    return ret;
}

static void PrintInorder(struct Node* tree) {

    if ( tree == NULL ) {
        return;
    }

    PrintInorder(tree->left);
    printf(" %d", tree->key);
    PrintInorder(tree->right);

    return;
}

static void PrintPreorder(struct Node* tree) {
    if ( tree == NULL ) {
        return;
    }

    printf(" %d", tree->key);
    PrintPreorder(tree->left);
    PrintPreorder(tree->right);

    return;
}

static struct Node* CreateNode(int key) {
    struct Node* p_node = malloc(sizeof(struct Node));

    p_node->parent = NULL;
    p_node->left   = NULL;
    p_node->right  = NULL;
    p_node->key    = key;

    return p_node;
}

static void DestroyNode(struct Node* p_node) {
    free(p_node);

    return;
}

static void DestroyTree(struct Node* tree) {
    if ( tree == NULL ) {
        return;
    }

    DestroyTree(tree->left);
    DestroyTree(tree->right);
    DestroyNode(tree);

    return;
}

int main(int argc, char* argv[]) {
    int m;
    int i;
    char order[16];
    struct Node* tree = NULL;

    scanf("%d\n", &m);

    for ( i = 0; i < m; i++ ) {
        int key;        
        scanf("%s %d\n", order, &key);
        if ( order[0] == 'i' ) {
            struct Node* p_node = CreateNode(key);
            tree = Insert(tree, p_node);
        } else if ( order[0] == 'p' ) {
            PrintInorder(tree);
            printf("\n");
            PrintPreorder(tree);
            printf("\n");            
        }
    }

    DestroyTree(tree);

    return 0;
}




Measured memory_bytes: 25148
#include <bits/stdc++.h>
using namespace std;
//²¢²»ÐèÒª¼ÆËã×éºÏÊý£¬×îÐ¡(n-1)a+b£¬×î´ó(n-1)b+a 

int main() {
	long long n,a,b;
	cin>>n>>a>>b;
	if(n==1) {
		if(a == b) cout<<"1";
		else cout<<"0";
	} else {
		if(a > b) cout<<"0";
		else
			cout<<(n-1)*b+a - (n-1)*a - b + 1;
	}
	return 0;
} 

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

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  
  int mx = 0;
  vector<int> nums(N);
  for (int n = 0; n < N; ++n) {
    cin >> nums[n];
    mx = max(mx, nums[n]);
  }
  vector<int> mods(mx+1);
  mods[1] = 1;
  for (int i = 2; i <= mx; ++i) {
    if (mods[i] != 0) {
      continue;
    }
    mods[i] = i;
    int tmp = i;
    while (tmp + i <= mx) {
      tmp += i;
      if (mods[tmp] != 0) continue;
      mods[tmp] = i;
    }
  }
  bitset<1000001> already;
  vector<int> cnts(mx+1);
  bool pairwise = true;
  for (int n : nums) {
    while (n > 1) {
      int tmp = mods[n];
      while (n % tmp == 0) {
        n /= tmp;
      }
      if (already.test(tmp)) {
        pairwise = false;
      }
      if (++cnts[tmp] == N) {
        cout << "not coprime" << endl;
        return 0;
      }
      already.set(tmp);
    }
  }
  if (pairwise) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "setwise coprime" << endl;
  }

  return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a[n+1],b[n+1], c[n+1];

    for(int i=1; i<= n; i++)
        cin>>a[i];

    for(int i=1; i<=n; i++)
        cin>>b[i];

    for(int i=1;i<=n-1;i++){
        cin>>c[i];
    }

    int prev = -1;
    int result = 0;
    for(int i=1; i <= n; i++){
        int idx = a[i];

        int temp = b[idx];

        if(idx == prev+1){
            temp += c[prev];
        }

        result += temp;
        prev = idx;
    }

    cout<<result<<endl;
}


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

#define forn(i,e) for(int i = 0; i < e; i++)
typedef long long ll;
const ll inf = 10000000000;

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

	ll h[n+1];
	forn(i,n) cin >> h[i+1];

	ll cost[n+1];
	forn(i,n) cost[i+1]=inf;
	cost[1]=0;

	for(int i=1; i<=n; i++){
		for(int j=i+1; j-i<=k && j<=n; j++){
			cost[j]=min(cost[i]+abs(h[i]-h[j]), cost[j]);
		}
	}

	cout << cost[n] << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

int ans[2005];

int main(){
  int n,x,y;
  cin >> n >> x >> y;
  x--,y--;
  rep(j,n)rep(i,j){
    //cout << i << " " << j << endl;
    int d= INT_INF;
    chmin(d,j-i);
    chmin(d,abs(x-i)+abs(y-j)+1);
    chmin(d,abs(j-x)+abs(i-y)+1);
    ans[d]++;
  }
  for(int i=1;i<n;i++){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int k,x,min,i;
  scanf("%d %d",&k,&x);
  min = x-k+1;
  for(i=0;i<k-1;i++) printf("%d ",min+i);
  for(i=0;i<k;i++) printf("%d ",x+i);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

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

const int OO = (int) 2e9;
const double eps = 1e-9;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	ll s, n = 1e9;
	cin >> s;
	ll y2 = s / n;
	ll x2 = s % n;
	if (x2 != 0)
		y2++, x2 = n - x2;
	cout << "0 0 " << n << " 1 " << x2 << " " << y2 << endl;
	return 0;
}


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

using namespace std;


int main()
{
	int N;
	cin >> N;
	vector<int> L;

	for (int i = 0; i < N; i++)
	{
		int num;
		cin >> num;
		L.push_back(num);
	}

	sort(L.begin(), L.end());

	vector<int>::iterator it_max;
	vector<int>::iterator it_high;
	vector<int>::iterator it_low;

	int count = 0;

	for (it_max = L.end() - 1; it_max > L.begin() + 1; it_max--)
	{
		for (it_high = it_max - 1; it_high > L.begin(); it_high--)
		{
			it_low = lower_bound(L.begin(), it_high, *it_max - *it_high + 1);
			count += distance(it_low, it_high);
			
			/*
			for (it_low = L.begin(); it_low < it_high; it_low++)
			{
				if (*it_low + *it_high > * it_max)
				{
					count += distance(it_low, it_high);
					break;
				}

			}
			*/
		}
	}

	cout << count;
}

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

//ユークリッド互除法(Euclid Algorithm)
template<typename T>
int euc_alg(T a, T b){
    while(1){
        int c = a % b;
        if(c == 0) break;
        a = b;
        b = c;
    }
    return b;
}
template<typename T>
int req_gcd(T a, T b){
    if(a > b) return euc_alg(a, b);
    else return euc_alg(b, a);
}


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    vector<int> r(n), l(n);
    l.at(0) = a.at(0);
    for(int i = 1; i < n; i++){
        l.at(i) = req_gcd(a.at(i), l.at(i - 1));
    }
    r.at(n - 1) = a.at(n - 1);
    for(int i = n - 2; i >= 0; i--){
        r.at(i) = req_gcd(a.at(i), r.at(i + 1));
    }
    int max_gcd = r.at(1);
    int comp_gcd;
    if(max_gcd < l.at(n - 2)) max_gcd = l.at(n - 2);
    for(int i = 1; i < n - 1; i++){
        comp_gcd = req_gcd(l.at(i - 1), r.at(i + 1));
        if(comp_gcd > max_gcd) max_gcd = comp_gcd;
    }
    cout << max_gcd << endl;
}

Measured memory_bytes: 1408
/*input
9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define watch(x) cout << (#x) << " is " << (x) << endl
#define N 100002

using namespace std;
ll dp[10005];

ll find_dp(int x)
{
	if(x<0)
		return 0;
	return dp[x];
}
int main()
{
	fastio
	ll T=1,n,m;string str;
	// cin>>T;
	// cin.ignore(); put after cin, just b4 a getline(cin, s) to avoid getline() directly getting \n
	while(T--)
	{
		ll p=0,q=0,tmp=0,sum=0,count=0; //tmp variable
		int flag=0;
		ll h ;
		cin>>h>>n;
		ll a[n];
		ll b[n];
		for(ll i=0;i < n;i++)
		{
			cin>>a[i]>>b[i];
		}

		// for (int i = 0; i < n; ++i)
		// {
		// 	cin >> b[i];	
		// }

		// for (int i = 0; i < n; ++i)
		// {
		// 	cout << a[i] << " " << b[i] << endl;	
		// }
		dp[0] = 0;

		for (int i = 1; i <=h; ++i)
		{
			ll mn=9999999999999;
			ll num_pos = -1;
			// watch(i);
			for (int j = 0; j < n; ++j)
			{
				if(mn>(b[j]+find_dp(i-a[j])))
				{
					mn = b[j]+find_dp(i-a[j]); 
					// watch(j);
					// watch(b[j]);
					// watch(find_dp(i-a[j]));
					// watch(mn);
					// cout  << endl;
					// num_pos = j;
				}
			}
			dp[i] = mn;

		}
		// for (int i = 0; i < h; ++i)
		// {
		// 	cout << dp[i] << " ";
		// }

		cout << dp[h] << endl;





		
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main()
{
    string s;
    cin>>s;
    ll n=s.size();
    ll count=0;
    ll cw=0;
    for(int i=0;i<n;i++){
        if(s[i]=='W'){
            count+=i;
            cw++;
        }
    }
    cout<<count-cw*(cw-1)/2<<endl;

}



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

#define pb push_back
#define left lleft
#define right rright
#define lld long long

using namespace std;

int N,nn; lld ans;
int a[200002]; lld where[200002];
lld left[200002],right[200002];
int seg[600002];

int tmp;
void get(int node,int l,int r,int s,int e){
	if(r < s || e < l || s > e || seg[node] == 0) return;
	if(s <= l && r <= e){
		tmp = node;
		return;
	}
	int mid = (l+r)/2;
	get(node*2,l,mid,s,e);
	get(node*2+1,mid+1,r,s,e);
}
void get2(int node,int l,int r,int s,int e){
	if(r < s || e < l || s > e || seg[node] == 0) return;
	if(s <= l && r <= e){
		tmp = node;
		return;
	}
	int mid = (l+r)/2;
	get2(node*2+1,mid+1,r,s,e);
	get2(node*2,l,mid,s,e);
}

int main(){
	scanf("%d",&N);
	for(nn=1; nn<N; nn*=2);
	if(N > 200000) while(true);
	for(int i=1; i<=N; i++){
		scanf("%d",&a[i]);
	}

	for(int i=1; i<=N; i++){
		where[a[i]] = i;
	}
	for(int i=1; i<=N; i++){
		if(where[i] == 0) return -1;
		if(seg[1] != i-1) return -1;
		tmp = -1;
		get(1,1,nn,1,where[i]-1);
		while(tmp < nn && tmp != -1){
			if(seg[tmp] <= 0) return -1;
			if(seg[tmp*2+1] != 0){
				tmp = tmp*2+1;
			}else tmp = tmp*2;
		}
		if(tmp == -1) left[i] = 1;
		else if(tmp >= nn) left[i] = tmp-nn+2;
		else return -1;
		tmp = -1;
		get2(1,1,nn,where[i]+1,N);
		while(tmp < nn && tmp != -1){
			if(seg[tmp] <= 0) return -1;
			if(seg[tmp*2] != 0){
				tmp = tmp*2;
			}else tmp = tmp*2+1;
		}
		if(tmp == -1) right[i] = N;
		else if(tmp >= nn) right[i] = tmp-nn;
		else return -1;
		int x = nn+where[i]-1;
		if(x < nn || x > nn+N-1) while(true);
		while(x > 0){
			if(x < 1 || x > 600000) while(true);
			seg[x]++;
			x /= 2;
		}
		if(left[i] > where[i]) while(true);
		if(right[i] < where[i]) return -1;
	}
	for(int i=1; i<=N; i++){
		ans += ((right[i]-where[i]+1)*(where[i]-left[i]+1)*(lld)i);
		//printf("%lld %lld\n",left[i],right[i]);
	}
	printf("%lld\n",ans);

	return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

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

template<int mod> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % mod) {
        if (val < 0) val += mod;
    }
    constexpr int getmod() { return mod; }
    constexpr Fp operator - () const noexcept {
        return val ? mod - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= mod) val -= mod;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % mod;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = mod, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % mod;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<mod>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<mod> modpow(const Fp<mod> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
	friend constexpr Fp<mod> modfac(long long l, long long r) noexcept
	{
		auto res = Fp<mod>(1);
		for (Fp<mod> i = l; i < r; ++i) res *= i;
		return res;
	}
};
using mint = Fp<1000000007>;


int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	mint res(0);
	string S; cin >> S;
	ll N = S.size();
	ll cnt1{0};
	REP(i, N)
	{
		if (S[i] == '1')
		{
			mint tmp = modpow(mint(2), cnt1) * modpow(mint(3), N-i-1);
			res += tmp;
			++cnt1;
		}
	}
	res += modpow(mint(2), cnt1);

	std::cout << res << std::endl; 
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

double dp[305][305][305];
bool visited[305][305][305];

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

    int N;
    cin >> N;
    vector<int> cnt(3, 0);
    for(int i = 0; i < N; ++i){
        int a;
        cin >> a;
        ++cnt[a - 1];
    }
    int S = cnt[0] + cnt[1] + cnt[2];
    auto MemoRec = [&](auto&& self, int i, int j, int k) -> double {
        if(visited[i][j][k])    return dp[i][j][k];
        visited[i][j][k] = true;
        if(i == 0 && j == 0 && k == 0)  return dp[i][j][k] = 0;
        double res = N;
        if(i > 0)   res += i * self(self, i - 1, j, k);
        if(j > 0)   res += j * self(self, i + 1, j - 1, k);
        if(k > 0)   res += k * self(self, i, j + 1, k - 1);
        res /= i + j + k;
        return dp[i][j][k] = res;
    };
    cout << fixed << setprecision(15);
    cout << MemoRec(MemoRec, cnt[0], cnt[1], cnt[2]) << endl;
}

Measured memory_bytes: 127216
#define ll long long int
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ll n,k,x,ans;
    cin>>n>>k;
   /* if(n<k){
        cout<<n;
    }
   // else{
        if(k==1){
        cout<<"0\n";
        }
        else{*/
             x=n%k;
             ans=abs(x-k);
             if(x>ans)
            cout<<ans;
            else
                cout<<x;
        //}
   // }

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long N,K;
  cin >> N >> K;
  pair<long long, long long> vect[N];
  long long a,b;
  for(int i = 0; i < N ; ++i){
    cin >> a >> b ;
    vect[i] = make_pair(a,b);
  }
  long long counter = 0;
  long long answer;
  sort(vect, vect+N);
  for(int i = 0; i < N; ++i){
    auto element = vect[i];
    counter += element.second;
    answer = element.first;
    if(counter >= K) break;
  }
  cout << answer << endl;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,K,X,Y;
    
    cin >> N >> K >> X >> Y;
    
    if(N < K) cout << N * X << endl;
    else cout << K * X + (N - K) * Y << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int n, m, a, i, s[100000], b=1000000007;
    scanf("%d %d", &n, &m);
    for(i = 0; i < n + 1; i++){
        s[i] = 1;
    }
    for(i = 0; i < m; i++){
        scanf("%d", &a);
        s[a] = 0;
    }


    for(i = 2; i < n + 1; i++){
        if(s[i] != 0){
            s[i] = s[i-1] + s[i-2];
            if(s[i] > b){
                s[i] %= b;
            }
        }
    }
    printf("%d", s[n]);
    return 0;
}



Measured memory_bytes: 512
//つるかめ算

#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
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 int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int N, Y;
    cin >> N >> Y;
    int diff = Y-1000*N;
    for(int j=0; j<=N; j++){
        if((diff - 4000*j) % 9000 == 0){
            int k = (diff - 4000*j) / 9000;
            int i = N - j - k;
            int nowdiff = diff - 4000*j - 9000*k;
            if(nowdiff == 0 && i >= 0 && k >= 0){
                cout << k << " " << j << " " << i << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

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

typedef long long ll;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < vl > vvl;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll;
typedef vector < pii > vpii;
typedef vector < vpll > vvpll;
typedef vector < vpii > vvpii;

#define pb push_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x,y) make_pair((x), (y))
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)



void solve(){
    
    int x, y; cin >> x >> y;
    int a = 4 * x - y;
    a /= 2;
    if(a >= 0 && a <= x && 2 * a + 4 * (x - a) == y){
        cout << "Yes\n";
    }
    else
        cout << "No\n";
}


int main(){
	boost;
	int t = 1;
// 	cin >> t;
	
	while(t--){
		solve();
	}
	return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

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

ll N, W;
VL v, w;
vector<VL> dp;

int main() {
    cin >> N >> W;
    dp.assign(N + 1, VL(W + 1, -1));
    REP(i, N) {
        v.emplace_back(IN());
        w.emplace_back(IN());
    }
    fill(All(dp[0]), 0);
    REP(i, N) REP(j, W + 1) {
        if(j < w[i])
            dp[i + 1][j] = dp[i][j];
        else
            dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
    }
    cout << dp[N][W] << "\n";
}



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

long long int knapsack(long long int W, long long int wt[], long long int val[], int n) 
{ 
   long long int i, w; 
   long long int K[n+1][W+1]; 
   for (i = 0; i <= n; i++) { 
       for (w = 0; w <= W; w++) { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 
  
int main() 
{ 
    int n;
    cin >> n;
    long long int W, wt[n], val[n];
    cin >> W;
    for( int i = 0; i < n; i++){
        cin >> wt[i] >> val[i];
    }
    cout << knapsack(W, wt, val, n); 
    return 0; 
}

Measured memory_bytes: 79104
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

ll N;
int ans,cnt;

int main(){
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin>>N;
    ll x[N],y[N];
    pair<ll,ll> dist[N][N];
    rep(i,N)cin>>x[i]>>y[i];
    rep(i,N){
        rep(j,N){
            if(i==j)dist[i][j]=make_pair(INF,INF);
            dist[i][j]=make_pair(x[i]-x[j],y[i]-y[j]);
        }
    }
    rep(i,N){
        rep(j,N){
            if(i==j)continue;
            cnt=1;
            rep(k,N){
                rep(l,N){
                    if(k==l||(i==k&&j==l))continue;
                    if(dist[i][j]==dist[k][l])cnt++;
                }
            }
            ans=max(ans,cnt);
        }
    }
    out(N-ans);

    
    
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

/////////////////////////////////////
vmint f, finv, inv;

void cominit(ll N) {
	f.assign(N + 1, 1);
	finv.assign(N + 1, 1);
	inv.assign(N + 1, 1);
	inv[1] = 1;

	repn(i, N) {
		f[i] = f[i - 1] * i;
		if (i > 1)inv[i] = -inv[MOD % i] * (MOD / i);
		finv[i] = finv[i - 1] * inv[i];
	}
}

mint com(ll a, ll b) {
	if (a < 0 || b < 0 || a < b) { return 0; }
	return f[a] * finv[b] * finv[a - b];
}

int main() {
	ll N;
	cin >> N;

	vll x(N + 1), y(N + 1);
	repn(i, N)cin >> x[i] >> y[i];

	ll px = -INF;
	repn(i, N)px = max(x[i] + y[i], px);
	ll pn = INF;
	repn(i, N)pn = min(x[i] + y[i], pn);

	ll mx = -INF;
	repn(i, N)mx = max(x[i] - y[i], mx);
	ll mn = INF;
	repn(i, N)mn = min(x[i] - y[i], mn);

	cout << max(px - pn, mx - mn) << endl;
}


Measured memory_bytes: 6356
#include "bits/stdc++.h"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
const int MAX = 1000000000;
const int MOD = 1000000007;
ll n,cnt=0;
void count(ll x, bool t, bool f, bool s){
    if(x > n) return;
    else {
        if(t && f && s) cnt++;
        count(x*10+3,1,f,s);
        count(x*10+5,t,1,s);
        count(x*10+7,t,f,1);
    }
}
int main(){
  cin>>n;
  count(0,0,0,0);
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n, x;
    vector<int> l;
    cin >> n >> x;
    l.resize(n);
    for (int &i : l)
    {
        cin >> i;
    }
    int count = 0, now = 0;
    while (now <= x && count <= l.size())
    {
        now += l[count++];
    }
    cout << count;
}

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

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

    int count = 0;
    for(int i = 0; i < N; i++){
        if(s[i] == 'Y'){
            count++;
            break;
        }
    }

    if(count){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }
}

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using pii=pair<int,int>;
using vs=vector<string>;
using vpii=vector<pii>;
using si=set<int>;

#define REP(i,a) for(int i=0;i<a;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rREP(i,a) for(int i=(a)-1;i>=0;i--)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define out(S) cout<<(S)<<endl;
#define beginend(v) (v).begin(),(v).end()
#define IfOut(condition,text) if(condition){out(text);return 0;}
#define IfOutElse(condition,if_text,else_text) if(condition){out(if_text);return 0;}else{out(else_text);return 0;}
#define mod(s) ((s)%(ll)(1e9+7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a*modpow((ll)b,(ll)(1e9+5))))
#define pb(i) push_back(i)
#define fst first
#define snd second
#define Foreach(item,collection) for(auto item:collection)
#define INF (int)1e10
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}
ll sum(vi v) {ll sum=0;Foreach(i,v){sum+=i;}return sum;}
#define ShowAll(v) Foreach(i,v) out(i);


int main(){
    vi ans;
    int n;
    while (cin>>n,n)
    {
        vi a(n);
        REP(i,n)cin>>a[i];
        sort(beginend(a));
        int m=INF;
        REP(i,n-1) m=min(m,a[i+1]-a[i]);
        ans.pb(m);
    }
    
    ShowAll(ans);
    return 0;
}

Measured memory_bytes: 3100
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
using namespace std;

int main()
{
    int n, Y;

    cin >> n >> Y;

    for (int x = 0; x <= n; x++)
    {
        for (int y = 0; y <= n - x; y++)
        {
            int z = n - x - y;
            int sum = x * 10000 + y * 5000 + z * 1000;
            if (sum == Y)
            {
                cout << x << " " << y << " " << z;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <cmath>		// circle math ( sin, con, sinh
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation

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

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

ll dp[101][100001]; //dpテーブル
int v[100],w[100];
int N,W;


ll rec(ll i,ll j){
   
  if(dp[i][j]>-1){
    return dp[i][j];
  }
  ll res;
  if(i==N){
    res= 0;
  }
  else if(j<w[i]){
    res = rec(i+1,j);//入らない時
  }
  else{
    res = max(rec(i+1,j), rec(i+1,j-w[i])+v[i]);//入れると入れないで比較
    }
  return dp[i][j]=res;
  }

int main() {
  
  cin >>N>>W; 
  rep(i,N)
    cin >> w[i] >> v[i];

  for(int i=0;i<101;i++){
    for(int j=0;j<100001;j++){
      dp[i][j]= -1;
    }
  }
  
  
  cout << rec(0,W)<< endl; // 標準出力
}






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

class Node{
public:
  Node* prev;
  Node* next;
  int data;

  Node(int x=0){
    prev=0;
    next=0;
    data=x;
  }
};

class List{
private:
  Node head;
  Node tail;

public:
  List(){
    head.prev=&head;
    head.next=&tail;
    tail.prev=&head;
    tail.next=&tail;
  }

  Node* search(int d){
    Node* tmp=head.next;
    while(tmp!=&tail){
      if(tmp->data==d){
        return tmp;
      }
      tmp=tmp->next;
    }
    return &tail;
  }

  void ins(int x){
    Node* n;
    n=head.next;
    head.next=new Node(x);
    Node* tmp=head.next;
    tmp->prev=&head;
    n->prev=tmp;
    tmp->next=n;
  }

  void del(int x){
    Node* tmp;
    tmp=search(x);
    Node* tmpp;
    Node* tmpn;
    tmpp=tmp->prev;
    tmpp->next=tmp->next;
    tmpn=tmp->next;
    tmpn->prev=tmp->prev;
  }

  void delfirst(){
    Node* tmp=head.next;
    head.next=tmp->next;
    Node* tmpn=tmp->next;
    tmpn->prev=&head;
  }

  void delLast(){
    Node* tmp=tail.prev;
    tail.prev=tmp->prev;
    Node* tmpp=tmp->prev;
    tmpp->next=&tail;
  }

  void print(){
    Node* tmp=head.next;
    while(tmp!=&tail){
      if(tmp->next==&tail){
        cout<<tmp->data;
      }else{
        cout<<tmp->data<<' ';
      }
        tmp=tmp->next;
    }
    cout<<endl;
  }
};

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

  for(int i=0;i<n;i++){
    char c[20];
    int x;
    cin>>c;

    if(c[0]=='i'){
      cin>>x;
      l.ins(x);
    }else{
      if(c[6]=='F'){
        l.delfirst();
      }else if(c[6]=='L'){
        l.delLast();
      }else {
        cin>>x;
        l.del(x);
      }
    }
  }
  l.print();

  return 0;
}




Measured memory_bytes: 37364
import scala.io.StdIn.readLine

object Main {
  def main(args:Array[String]) = {
    val n = readLine.split(" ").map(_.toInt)
    if(n(0) + n(1)*5 + n(2)*10 + n(3)*50 + n(4)*100 + n(5)*500 >= 1000)
      println(1)
    else
      println(0)
  }
}

Measured memory_bytes: 43728
import sys
def binSearch(x,data):
    start = 0
    end = len(data)
    while start <= end:
        mid = int((start + end) / 2)
        if data[mid] == x:
            return 1
        elif int(data[mid]) > int(x):
            end = mid - 1
        else:
            start = mid + 1
    return 0
l = []
for i in sys.stdin:
    l.append(i)
l[1] = l[1].split()
l[3] = l[3].split()
count = 0
for i in range(0,len(l[3])):
    count += binSearch(l[3][i],l[1])
print(count)


Measured memory_bytes: 15172
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;

using namespace std;

string LCS(string a, string b)
{
	int i,j,n1=a.size(),n2=b.size();

    int dp[n1+1][n2+1];
    for(i=0;i<n1+1;i++)dp[i][0]=0;
    for(i=0;i<n2+1;i++)dp[0][i]=0;

    for(i=1;i<n1+1;i++)
    {
        for(j=1;j<n2+1;j++)
        {
            if(a[i-1]==b[j-1])
            dp[i][j]=dp[i-1][j-1]+1;
            else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            //cout<<dp[i][j]<<" ";
        }
       // cout<<endl;
    }

    i=n1;j=n2;
    string s;
    while(i>0&&j>0)
    {
        //cout<<i<<"-"<<j<<endl;
        if(a[i-1]==b[j-1])
        {
            s.push_back(a[i-1]);
            i--;
            j--;
            
        }
        else
        {
            if(dp[i-1][j]>=dp[i][j-1])
            {
                i--;
            }
            else
            {
                j--;
            }
            
        }
    }
    reverse(s.begin(),s.end());

    return s;

}

int main()
{
	FIO
    string a,b;
	cin>>a;
    cin>>b;
    cout<<LCS(a,b)<<endl;

}

Measured memory_bytes: 38804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
ll mod = 1000000007;
ll INF = 1000000099;

vector<vector<ll>> dp;

signed main(){
    ll n,K;
    cin >>n>>K;
    vector<ll> k,v(50,0);

    for(int i=0;i < n;i++)
    {
        ll a,cnt=0;
        cin>>a;
        while(a>0){
            if(a%2==1){
                v.at(cnt)++;
            }
            a/=2;
            cnt++;
        }  
    }


    dp.assign(50,vector<ll>(2,-1));
    dp.at(49).at(0)=0;
    for(int i=48;0<=i;i--)
    {
        if(dp.at(i+1).at(1)>=0) dp.at(i).at(1)= dp.at(i+1).at(1)+max(n-v.at(i),v.at(i))*(1ll<<i);
        //最初からＫ未満なんてことはなく、ぴったりから未満になる

        if(1ll<<i & K){//kのiビット目が１
            dp.at(i).at(1)=max(dp.at(i).at(1),dp.at(i+1).at(0)+v.at(i)*(1ll<<i));
            dp.at(i).at(0)=dp.at(i+1).at(0)+(n-v.at(i))*(1ll<<i);
        }else{
            dp.at(i).at(0)=dp.at(i+1).at(0)+v.at(i)*(1ll<<i);
        }
    }

    ll ans=max(dp.at(0).at(0),dp.at(0).at(1));

    cout << ans << endl;
}

Measured memory_bytes: 384