akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node{
  int key;
  struct node *p, *l, *r;
}T_node;
T_node *rt;
void n_insert(T_node *, int);
T_node *n_find(T_node *, int);
void n_delete(T_node *);
T_node *n_suc(T_node *, T_node *);
void n_print(T_node *);
void preo(T_node *);
void ino(T_node *);
void psto(T_node *);
int main(){
  int n;
  scanf("%d", &n);
  char *buf;
  buf = (char *)malloc(sizeof(char) * 256);
  int key;
  rt = NULL;
  int i;
  for(i = n - 1; i >= 0; i--){
    scanf("%s", buf);
    if(!strcmp(buf, "insert")){
      scanf("%d", &key);
      n_insert(rt, key);
    }
    else if(!strcmp(buf, "find")){
      scanf("%d", &key);
      if(n_find(rt, key) != NULL)
	printf("yes\n");
      else
	printf("no\n");
    }
    else if(!strcmp(buf, "delete")){
      scanf("%d", &key);
      T_node *del;
      if((del = n_find(rt, key)) != NULL)
	n_delete(del);
    }
    else if(!strcmp(buf, "print"))
      n_print(rt);
  }
  free(buf);
  return 0;
}

void n_insert(T_node *x, int key){
  T_node *y;
  y = NULL;
  while(x != NULL){
    y = x;
    if(key < x->key)
      x = x->l;
    else
      x = x->r;
  }
  T_node *new;
  new = (T_node *)malloc(sizeof(T_node));
  new->p = y;
  new->key = key;
  new->l = new->r = NULL;
  
  if(y == NULL)
    rt = new;
  else if(key < y->key)
    y->l = new;
  else
    y->r = new;
}

T_node *n_find(T_node *x, int key){
  if(x != NULL){
    if(key == x->key){
      return x;
    }
    if(key < x->key)
      n_find(x->l, key);
    else
      n_find(x->r, key);
  }
  else
    return NULL;
}

void n_delete(T_node *del){
  int d = (del->l != NULL) + (del->r != NULL);
  if(!d){
    if(del == del->p->l)
      del->p->l = NULL;
    else
      del->p->r = NULL;
    free(del);
  }
  else if(d == 1){
    if(del == del->p->l){
      if(del->l != NULL){
	del->p->l = del->l;
	del->l->p = del->p;
      }
      else{
	del->p->l = del->r;
	del->r->p = del->p;
      }
    }
    else{
      if(del->l != NULL){
	del->p->r = del->l;
	del->l->p = del->p;
      }
      else{
	del->p->r = del->r;
	del->r->p = del->p;
      }
    }
    free(del);
  }
  else{
    T_node *suc;
    suc = n_suc(del, del);
    del->key = suc->key;
    n_delete(suc);
  }
}  
T_node *n_suc(T_node *t, T_node *del){
  if(t == del & t->r != NULL)
    return n_suc(t->r, del);
  if(t->l != NULL)
    return n_suc(t->l, del);
  return t;
}

void n_print(T_node *rt){
  if(rt != NULL){
    ino(rt);
    printf("\n");
    preo(rt);
    printf("\n");
  }
}

void preo(T_node *t){
  printf(" %d", t->key);
  if(t->l != NULL)
    preo(t->l);
  if(t->r != NULL)
    preo(t->r);
}
void ino(T_node *t){
  if(t->l != NULL)
    ino(t->l);
  printf(" %d", t->key);
  if(t->r != NULL)
    ino(t->r);
}
void psto(T_node *t){
  if(t->l != NULL)
    psto(t->l);
  if(t->r != NULL)
    psto(t->r);
  printf(" %d", t->key);
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

const int MAX_N = 150000;
double dp[MAX_N];
double dp2[MAX_N];

double dfs(int now, int pre, const Graph& G) {
    if (pre != -1 && G[now].size() == 1) return dp[now] = 0.;
    double& ret = dp[now];
    int num_ch = 0;
    for (auto nxt : G[now]) {
        if (nxt == pre) continue;
        ret += dfs(nxt, now, G);
        num_ch++;
    }
    ret /= num_ch;
    ret += 1.;
    return ret;
}

void dfs2(int now, int pre, const Graph& G) {
    double p = G[pre].size();
    if (pre == 0) {
        if (p == 1) dp2[now] = 1;
        else dp2[now] = 1 + (dp[pre] - (dp[now] + 1) / p) * p / (p - 1);
    }
    else {
        dp2[now] = ((dp2[pre] + 1) + (dp[pre] + 1) * (p - 1) - (dp[now] + 2)) / (p - 1);
    }
    for (auto nxt : G[now]) {
        if (nxt == pre) continue;
        dfs2(nxt, now, G);
    }
}

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

    int n;
    cin >> n;
    Graph G(n);
    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    dfs(0, -1, G);

    // rep(i, n) {
    //     cout << fixed << setprecision(10) << dp[i] << endl;
    // }
    // cout << endl;

    for (auto ch : G[0]) dfs2(ch, 0, G);

    // rep(i, n) {
    //     cout << fixed << setprecision(10) << dp2[i] << endl;
    // }
    // cout << endl;

    rep(i, n) {
        int p = G[i].size();
        double ans = i == 0 ? dp[i] : (dp[i] * (p - 1) + dp2[i]) / p;
        cout << fixed << setprecision(10) << ans << endl;
    }
}


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

using namespace std;

int main()
{
    int n, i, j, a, b, l, sum = 0;
    vector < int > v;

    cin >> n;

    for(i=0; i<n; i++)
    {
        cin >> a;
        v.push_back(a);
    }
    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            sum += v[i]*v[j];
        }
    }

    cout << sum << endl;

    return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_N = 17;
int dp[1 << MAX_N];
int t[MAX_N+1][MAX_N+1];
int N;

int main()
{
  while(cin >> N, N){
    rep(i, 1 << N) dp[i] = INF;
    rep(i, N) rep(j, N+1) cin >> t[i][j];

    dp[0] = 0;
    rep(S, 1 << N) rep(u, N) if(!(S & 1 << u)){
      int mn = t[u][0];
      rep(v, N) if(S & 1 << v) minup(mn, t[u][v + 1]);
      minup(dp[S | 1 << u], dp[S] + mn);
    }

    cout << dp[(1 << N) - 1] << endl;
   }

  return 0;
}

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

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, x[55], y[55];
signed main() {
    cin >> N;
    rep(i, N) { cin >> x[i] >> y[i]; }
    int ans = N;
    rep(i, N) {
        rep(j, N) {
            if (i == j) { continue; }
            int cur = N;
            int p = x[i] - x[j], q = y[i] - y[j];
            rep(k, N) {
                rep(l, N) {
                    if (x[k] - x[l] == p && y[k] - y[l] == q) { cur--; }
                }
            }
            chmin(ans, cur);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var m = nm[1];
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(Max((nm[0] - a.Sum()), -1));
    }
}

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

int main(){
while(1){
	int INF=100000100;
	int n,k,ans[105][105],t,a,b,c;
	scanf("%d%d",&n,&k);
	if(n==0&&k==0)break;
	for(int i=1;i<=n+2;i++){
		for(int j=1;j<=n+2;j++){
			ans[i][j]=INF;
			if(i==j)ans[i][j]=0;
		}
	}
	for(int i=0;i<k;i++){
		scanf("%d",&t);
		if(t==0){
			scanf("%d%d",&a,&b);
			if(ans[a][b]==INF)printf("%d\n",-1);
			else printf("%d\n",ans[a][b]);
		}
		if(t==1){
			scanf("%d%d%d",&a,&b,&c);
			if(ans[a][b]>c){
				ans[a][b]=c;
				ans[b][a]=c;
				for(int i=1;i<=n;i++){
					for(int j=1;j<=n;j++){
						if(ans[i][j]>ans[i][a]+ans[a][b]+ans[b][j])ans[i][j]=ans[i][a]+ans[a][b]+ans[b][j];
						if(ans[i][j]>ans[i][b]+ans[b][a]+ans[a][j])ans[i][j]=ans[i][b]+ans[b][a]+ans[a][j];
					}
				}
			}
		}
	}
}
}

Measured memory_bytes: 1212
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    map<int, int> origin, sorted;
    rep(i, N) { origin.insert(MP(A[i], i % 2)); }
    sort(All(A));
    rep(i, N) { sorted.insert(MP(A[i], i % 2)); }
    int cnt = 0;
    for(auto x : origin) {
        if(x.second != sorted[x.first])
            cnt++;
    }
    cout << cnt / 2 << endl;
    return 0;
}

Measured memory_bytes: 10112
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
#define ll long long int
int main(){
  ll n, m, ans = 0;
  cin >> n >> m;
  vector < pair< ll, ll > > a(n);
  for ( int i = 0; i < n; ++i ) {
    cin >> a[i].first >> a[i].second;  
  }
  sort ( a.begin(), a.end() );
  for ( int i = 0; i < n; ++i ) {
    //cout << "-------------" << endl;
    //cout << "いま"  << m << "本残っています" << endl;
    //cout << "一本" << a[i].first << "円のお店て買おうと思っています" << endl;
    //cout << a[i].second << "本買うことができます" << endl;
    
    m -= a[i].second;
    if ( m >= 0) {
      ans += a[i].second * a[i].first;
    } else {
      m += a[i].second;
      ans += m * a[i].first;
      break;  
    }
    //cout << ans << "円使いました" << endl;
  }
  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

struct node{int key; node *p, *l, *r;};

node *nil, *root;

void preparse(node *root){
    if(root == nil) return;
    cout << " " << root->key;
    preparse(root->l);
    preparse(root->r);
}

void inparse(node *root){
    if(root == nil) return;
    inparse(root->l);
    cout << " " << root->key;
    inparse(root->r);
}

void insert(int k){
    node *y = nil;
    node *x = root;
    node *z;
    z = (node *)malloc(sizeof(node));
    z->key = k;
    z->l = nil;
    z->r = nil;
    while(x != nil){
        y = x;
        if(z->key < x->key) x = x->l;
        else x = x->r;
    }
    z->p = y;
    if(y == nil) root = z;
    else if(z->key < y->key) y->l = z;
    else y->r = z;
}

node * find(int k, node *cur){
   while(cur != nil && k != cur->key){
       if(k < cur->key) cur = cur->l;
       else cur = cur->r;
   }
   return cur;
}

int main(){
    int n, d;
    string com;
    cin >> n;
    rep(i, n){
        cin >> com;
        if(com == "insert"){
            cin >> d;
            insert(d);
        }else if(com == "print"){
            inparse(root);
            cout << endl;
            preparse(root);
            cout << endl;
        }else if(com == "find"){
            cin >> d;
            if(find(d, root) != nil) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
}


Measured memory_bytes: 21900
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> val(n);
	vector<int> dp(n+1,INT_MAX);
	dp[0]=0;
	for(int &i:val) cin>>i;
	for(int i = 0; i < n ; i++) {
		for(int j:{i+1,i+2}){
			if(j<n){
				dp[j]=min(dp[i]+abs(val[i]-val[j]),dp[j]);
			}
		}
	}
	cout<<dp[n-1]<<'\n';
}


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

int main(void){
    string s;
    int ans = 100000;
    cin >> s;
    for(int i = 0; i < 26; i++){
        string str = s;
        int cnt = 0;
        while(1){
            bool flag = true;
            for(int j = 0; j < str.size(); j++){
                if(str[j] - 'a' != i){
                    flag = false;
                    break;
                }
            }
            if(flag){
                ans = min(ans, cnt);
                break;
            }
            for(int j = 1; j < str.size(); j++){
                if(str[j] - 'a' == i) str[j - 1] = i + 'a';
                // cout << str[j] << " ";
            }
            // cout << "==" << endl;
            int index = 0, pos = str.size() - 1;
            while(str[index] - 'a' == i && index < pos){
                index++;
            }
            // while(str[pos] - 'a' == i && pos > 0){
            //     pos--;
            // }
            if(index < str.size() - 1 - pos) str[index] = i + 'a';
            else str[pos] = i + 'a';
            // str[index] = i + 'a';
            cnt++;
        }
        // cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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;
}

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
        return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //COMinit();
    int n; cin>>n;
    vector<int> d(n,0);
    REP(i,n) cin>>d[i];
    int ans=0;
    sort(d.begin(),d.end());
    int left=n/2-1;
    int right=n/2;
    ans=(int)d[right]-d[left];
    cout<<ans<<endl;

    return 0;
    }





Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000000
#define N 10000005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int spf[N];

void sieve() {
    for (int i = 1; i < N; i++)
        spf[i] = 1;
    for (int i = 2; i < N; i++) {
            for (int j = i; j < N; j += i) {
                    spf[j]++;
            }

    }
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   sieve();
   int ans=0;
   for(int i=1;i<=n;i++)
   {
       ans+=(i*spf[i]);
   }
   cout<<ans<<endl;

}


Measured memory_bytes: 81732
// E - Knapsack 2

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

// dp[i][j]: i番目までのアイテムを使用して価値がjとなるときの最小の重み
long long dp[101][100001];

int main() {
	// dpの配列をINFで初期化
	for (int i=0; i<=100; i++) {
		for (int j=0; j<=100000; j++) {
			dp[i][j] = INF;
		}
	}

	int N, W;
	cin >> N >> W;

	int weight[101], value[101];
	for (int i = 1; i <= N; i++) {
		cin >> weight[i] >> value[i];
	}

	dp[0][0] = 0;
	int max_value = 0;
	for (int i=1; i<=N; i++) {
		for (int j=0; j<=max_value; j++) {
			if (dp[i-1][j] != INF) {
				dp[i][j] = min(dp[i][j], dp[i-1][j]); // iを選ばない
				dp[i][j + value[i]] = min(dp[i][j + value[i]], dp[i-1][j] + weight[i]); // iを選ぶ
			}
		}
		max_value += value[i];
	}

	int ans = 0;
	for (int j=0; j<=max_value; j++) {
		if (dp[N][j] <= W) {
			ans = j;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 79104
N = input()

if(N == "SUN"):
    print(7)
elif(N == "MON"):
    print(6)
elif(N == "TUE"):
    print(5)
elif(N == "WED"):
    print(4)
elif(N == "THU"):
    print(3)
elif(N == "FRI"):
    print(2)
elif(N == "SAT"):
    print(1)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

n = int(input())
a = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n)]

def calc_idx(x, y):
    if x > y:
        x, y = y, x
    return x + y*(y-1)//2

n_game = n * (n-1) // 2
edge = [[] for i in range(n_game)]
for i in range(n):
    for j in range(1, n-1):
        g1 = calc_idx(i, a[i][j-1])
        g2 = calc_idx(i, a[i][j])
        edge[g1].append(g2)

indegree = [0] * n_game
for i in range(n_game):
    for v in edge[i]:
        indegree[v] += 1

ans = 0
cand = [i for i in range(n_game) if indegree[i] == 0]
ts = []
while cand:
    ts.extend(cand)
    cand2 = []
    for ci in cand:
        for v in edge[ci]:
            indegree[v] -= 1
            if indegree[v] == 0:
                cand2.append(v)
    cand = cand2
    ans += 1

if len(ts) != n_game:
    ans = -1

print(ans)


Measured memory_bytes: 138460
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

class rep {
	const usize f, l;

public:
	class itr {
		friend rep;
		usize i;
		itr(usize x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		usize operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	rep(usize first, usize last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(f); }
	itr end() const noexcept { return itr(l); }
};
class revrep {
	const usize f, l;

public:
	class itr {
		friend revrep;
		usize i;
		itr(usize x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		usize operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	revrep(usize first, usize last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(l - 1); }
	itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }

#include <algorithm>
#include <iostream>
#include <utility>

int main() {
	u32 n, x;
	::std::cin >> n >> x;
	::std::vector<u32> a(n);
	for (auto &e : a)
		::std::cin >> e;
	::std::sort(a.begin(), a.end());
	u32 cnt = 0;
	bool f = 0;
	for (const auto i:rep(0,n)) {
		if (a[i] <= x)
			++cnt, x -= a[i], a[i] = 0;
	}
	if (a.back() == 0 && x > 0)
		--cnt;
	::std::cout << cnt << ::std::endl;
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
LL h = 0, w, n = 0, m, ans = -INF, f[100] = {}, a[100000][3] = {}, sum = 0, c[100][210000] = {};
int flag = 0;
string str;
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
		c[a[i][2]][a[i][0]*2-1] += 1;
		c[a[i][2]][a[i][1] * 2] += -1;
		h = max(h, a[i][1]*2);
	}
	for (int i = 0; i <= h; i++) {
		sum = 0;
		for (int j = 1; j <= m; j++) {
			f[j] += c[j][i];
			sum += (f[j] > 0 ? 1 : 0);
		}
		ans = max(ans,sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 52352
#include <stdio.h>

int main(void)
{

int a,b;

scanf("%d%d", &a, &b);

if(a == b){
  printf("a == b\n");
}

else{
  if( a < b ){
    printf("a < b\n");
  }
  
  else{
    printf("a > b\n");
  }  
}

return 0;

}

Measured memory_bytes: 580
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<tuple>
#define lson (now<<1)
#define rson ((now<<1)|1)
#define mid ((nl+nr)>>1)
#define maxn 1005
using namespace std;
typedef long long ll;
int n,m,cnt;
int sx,sy,ex,ey;
char s[maxn][maxn];
int col[maxn][maxn];
int dis[maxn*maxn];
queue<pair<int,int> > q;
int fx[maxn]={0,0,1,-1};
int fy[maxn]={1,-1,0,0};
void dfs(int nx,int ny)
{
	col[nx][ny]=cnt;
	for(int i=0;i<4;i++)
	{
		int xx=nx+fx[i],yy=ny+fy[i];
		if(1<=xx && xx<=n && 1<=yy && yy<=m && s[xx][yy]=='.' && !col[xx][yy])
		{
			dfs(xx,yy);
		}
	}
}
int vis[maxn][maxn];
void dfs2(int nx,int ny)
{
	q.push({nx,ny});
	vis[nx][ny]=1;
	for(int i=0;i<4;i++)
	{
		int xx=nx+fx[i],yy=ny+fy[i];
		if(1<=xx && xx<=n && 1<=yy && yy<=m && s[xx][yy]=='.' && col[xx][yy]==col[nx][ny] && !vis[xx][yy])
		{
			dfs2(xx,yy);
		}
	}
}
void bfs()
{
	memset(dis,-1,sizeof(dis));
	dis[col[sx][sy]]=0;
	dfs2(sx,sy);
	while(!q.empty())
	{
		int nx,ny;
		tie(nx,ny)=q.front(); q.pop();
		for(int i=-2;i<=2;i++)
		{
			for(int j=-2;j<=2;j++)
			{
				int xx=nx+i,yy=ny+j;
				if(1<=xx && xx<=n && 1<=yy && yy<=m && s[xx][yy]!='#')
				{
					if(dis[col[xx][yy]]==-1 || dis[col[xx][yy]]>dis[col[nx][ny]]+1)
					{
						dis[col[xx][yy]]=dis[col[nx][ny]]+1;
						dfs2(xx,yy);
					}
				}
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d",&sx,&sy);
	scanf("%d%d",&ex,&ey);
	
	for(int i=1;i<=n;i++)
	scanf("%s",s[i]+1);
	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(s[i][j]=='.' && !col[i][j])
			{
				cnt++;
				dfs(i,j);
			}
		}
	}
	
	bfs();
	
	printf("%d\n",dis[col[ex][ey]]);
}

Measured memory_bytes: 16708
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>  vll;

// code
// ------------------------------------------------
bool dfs(vector<vector<ll>> &Graph, ll pos,ll depth, ll goal)
{
  bool ret = false;
  if(depth < 1)  // 深さが0のときは、dfsを呼ぶ。
  {
    for(auto it: Graph[pos])
    {
      ret = dfs(Graph, it, depth + 1, goal);
      if(ret)
      {
        break;
      }
    }
  }
  else
  {
    for(auto it : Graph[pos])
    {
      if(it == goal)
      {
        ret = true;
      }
    }
  }
  return ret;
}

int main() {

  ll n,m;
  cin >> n >> m;

  vector<vector<ll>> Graph(n);

  rep(i,m)
  {
    ll a,b;
    cin >> a >> b;
    a--;
    b--;

    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }

  bool flg = dfs(Graph, 0, 0, n-1);

  if(flg) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 12776
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
		int max=0;
		int c=0;
		for(int i=0;i<n-1;i++) {
			c=0;

			for(int j=i;j<n-1;j++) {
				if(a[j]>=a[j+1]) {
					c++;
				}else {
					i=j;
					break;
				}

			}

			max=Math.max(max, c);
			if(n-i<max)
				break;

		}
		System.out.println(max);

	}

}

Measured memory_bytes: 50944
n = int(input())
a = [list(map(int,input().split())) for i in range(2)]
lis = []
s = 0
for i in range(n):
    for j  in range(i+1):
        s += a[0][j]
    for k in range(n-i):
        s += a[1][i+k]
    lis.append(s)
    s = 0
print(max(lis))


Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

public class Main {

	static int n, INF = (int) 1e9, a[][], memo[][];

	static int dp(int msk, int idx, int last) {
		if (idx == n)
			return 0;
		if (memo[last][msk] != -1)
			return memo[last][msk];
		int ans = INF;
		for (int put = 0; put < n; put++) {
			if ((msk & 1 << put) != 0)
				continue;
			int all = (1 << (put + 1)) - 1;
			int newPos = put + Integer.bitCount(msk&~all);
//			for (int j = put + 1; j < n; j++)
//				if ((msk & 1 << j) > 0)
//					newPos++;

			int val = a[put][Math.abs(put - idx) % 2];
			if (val >= last) {
				ans = Math.min(ans, dp(msk | 1 << put, idx + 1, val) + Math.abs(newPos - idx));
			}

		}
		return memo[last][msk] = ans;

	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		n = sc.nextInt();
		a = new int[n][2];
		memo = new int[51][1 << n];
		for (int[] x : memo)
			Arrays.fill(x, -1);
		for (int j = 0; j < 2; j++)
			for (int i = 0; i < n; i++)
				a[i][j] = sc.nextInt();
		int ans=dp(0,0,0);
		out.println(ans>=INF?-1:ans);

		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}

}

Measured memory_bytes: 90708
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    auto S = sread();
    auto ss = ["Sunny", "Cloudy", "Rainy"];
    foreach (i; 0 .. 3)
        if (ss[i] == S)
        {
            writeln(ss[(i + 1) % 3]);
        }
}


Measured memory_bytes: 256
//
// Created by iceleo on 2018/4/6.
//
#include <iostream>
#include <numeric>

using namespace std;
int buck[110];
int main(){
    int n,d,x;
    cin>>n>>d>>x;
    for(int i=1;i<=n;++i){
        int t;
        cin>>t;
        for(int j=0;t*j+1<=d;++j){
            ++buck[j*t+1];
        }
    }
    cout<<accumulate(buck+1,buck+d+1,x)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0 , f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{if(ch == '-')	f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 1e5 + 5 , mod = 1e9 + 7;
char s[N];
int ch[N][2] , f[N];
int main()
{
	scanf("%s",s + 1); int n = strlen(s + 1);
	int flag = 0 , sum = 0;
	for(int i = 2;i <= n;i ++) flag += (s[i] == s[i - 1]);
	if(!flag) return puts("1") , 0;
	f[n + 1] = 1;
	for(int i = 1;i <= 2;i ++) for(int j = 0;j < 2;j ++) ch[n + i][j] = n + 2;
	for(int i = n;i >= 1;i --)
	{
		sum = (sum + (s[i] == 'a' ? 1 : 2)) % 3;
		ch[i][0] = s[i] == 'a' ? i + 1 : s[i + 1] == 'b' ? i + 2 : ch[i + 2][0];
		ch[i][1] = s[i] == 'b' ? i + 1 : s[i + 1] == 'a' ? i + 2 : ch[i + 2][1];
		f[i] = (f[ch[i][0]] + f[ch[i][1]] + (sum == 0)) % mod;
	}
	printf("%d\n",(f[1] - (sum == 0) + mod) % mod);
	return 0;
}

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

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >>d;
    while(a>0 && c>0){
        c -= b;
        if(c<=0){
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
    }
    cout << "No" << endl; 
    return 0;
}




Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  
  for (int i = 0; i < N; i++)
  {
    H -= A.at(i);
    if (H <= 0)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 640
s = list(input())
sets = set(s)

if s.count(list(sets)[0]) == len(s):
    print(0)
    exit()

cnt = 10 ** 9
for i in range(len(sets)):
    find = list(sets)[i]
    tmps = s
    tmpCnt = 0
    while True:
        tmp = ''
        for j in range(len(tmps) - 1, 0, -1):
            if s[j - 1] == find:
                tmp += tmps[j - 1]
            else:
                tmp += tmps[j]
        tmpCnt += 1
        tmps = tmp[::-1]
        if tmps.count(find) == len(tmps):
            cnt = min(cnt, tmpCnt)
            break

print(cnt)

Measured memory_bytes: 3064
import itertools

N=int(input())
P=[int(i) for i in input().split(" ")]
Q=[int(i) for i in input().split(" ")]
for i,perm in enumerate(itertools.permutations([i+1 for i in range(N)])):
    if list(perm)==P:
        a=i
    if list(perm)==Q:
        b=i

print(abs(a-b))


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  sort(d.begin(),d.end());

  int ans = d[n/2] - d[n/2-1];
  cout << ans << endl;
}


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

using namespace std;

bool PrimeNumber[10000001];
int Ans[10000001];


void solve() {
	memset(PrimeNumber, true, sizeof(PrimeNumber));
	PrimeNumber[0] = PrimeNumber[1] = false;

	for (int i = 2; i*i < 10000001; ++i) {
		if (!PrimeNumber[i]) {
			continue;
		}
		for (int j = i*i; j < 10000001; j+=i) {
			PrimeNumber[j] = false;
		}
	}

	Ans[13] = 13;
	for (int i = 14; i < 10000001; ++i) {
		Ans[i] = Ans[i - 1];
		if (PrimeNumber[i] && PrimeNumber[i - 2] && PrimeNumber[i - 6] && PrimeNumber[i - 8]) {
			Ans[i] = i;
		}
	}
}

int main() {
	int n;

	solve();
	while (cin >> n, n) {
		cout << Ans[n] << endl;
	}

	return 0;
}


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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t;
  cin >> s >> t;
  cout << t << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
typedef long long ll;
typedef double db;
const int MX=100005;
const int mod=1000000007;
const int inf=1e9;
int dp[MX],a[MX];
int main()
{
    FasterIO;
    int i,j,k,n;
    cin>>n>>k;
    for(i=1;i<=n;i++)cin>>a[i];
    for(i=2;i<=n;i++)
    {
        dp[i]=1000000007;
        for(j=i-1;j>0&&j>=i-k;j--)
        {
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,j,k=0,l,x;
    scanf("%lld\n",&n);

    x=n+1;

    for(i=0;i<n;i++)
    {
        scanf("%lld",&j);
        if(j<x)
        {
            k++;
            x=j;
        }
    }
    printf("%lld",k);
    return 0;
}


Measured memory_bytes: 3796
#include <iostream>

int main() {
    int cnt = 0;
    bool flag = false;
    int a, b;
    int t;
    std :: cin >> t;

    while(t--) {
        std :: cin >> a >> b;

        if(a == b) {
            cnt++;
            if(cnt >= 3) flag = true;
        }
        else cnt = 0;
    }

    std :: cout << (flag ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 3628
#include <stdio.h>
int main(){
  int data[31];
  int d,i;
  for(i=0;i<31;i++)data[i]=0;
 
  for(i=1;i<=28;i++){
    scanf("%d",&d);
    data[d]=1;
  }
  for(i=1;i<=30;i++){
    if(data[i]==0){
      printf("%d\n",i);
    }
  }
  return 0; 
}


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

int main() {
  int N; cin >> N;
  vector<int> S;
  int cnt = 0;
  int point = 0;
  while (point < N) {
    cnt++;
    point += cnt;
    S.push_back(point);
  }
  vector<int> ans;
  int tmp = N;
  while (tmp != 0) {
    int idx = lower_bound(S.begin(), S.end(), tmp) - S.begin();
    ans.push_back(idx + 1);
    tmp -= idx + 1;
  }
  reverse(ans.begin(), ans.end());
  for (int v : ans) cout << v << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[n];
		int count = 0;

		for(int i=0; i<n; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 0; i < n; i++) {

			int day = 1;
			while(day <= d) {
				count++;
				day += a[i];
				if(day > d) {
					break;
				}
			}

		}

		System.out.println(count + x);

	}
}

Measured memory_bytes: 21972
from bisect import bisect
n = int(input())

vals = []
for _ in range(n):
	a = int(input())
	vals.append(a)

max_val = max( vals )
vals_not_max = [a for a in vals if a != max_val]
if len(vals_not_max) < n -1:
	max_val_exclude  = max_val
else:
	max_val_exclude = max(vals_not_max)
	
for a in vals:
	if a == max_val:
		print(max_val_exclude)
	else:
		print(max_val)



Measured memory_bytes: 71000
#include<bits/stdc++.h>
using namespace std;
char s[100];
int main()
{
    int a=0,b,t1=1000,t2=-1,w1=0,w2=0;
    scanf("%s",s);
    b=strlen(s)-1;
    while(a<strlen(s))
    {
        if (s[a]=='C'&&w1==0)
        {
            t1=a;
            w1=1;
        }
        if (s[b]=='F'&&w2==0)
        {
            t2=b;
            w2=1;
        }
        a=a+1;
        b=b-1;
    }
    if (t1<t2)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List

burgersize :: Integer -> Integer
burgersize lv 
  | lv==0 = 1
  | lv>0  = 3 + 2 * burgersize (lv - 1)

pate 0 = 1
pate lv = 1 + 2 * pate (lv-1)

burger :: Integer -> Integer -> Integer
burger 0 0 = 0
burger 0 _ = 1
burger lv x
  | x == 0 = 0
  | x >= thissize = pate lv
  | x <= 1 + lowersize = burger (lv-1) (max 0 (x - 1))
  | otherwise = pate (lv-1) + 1 + burger (lv-1) (max 0 (x - 2 - lowersize))
  where
    thissize = burgersize lv
    lowersize = burgersize (lv-1)
    
solve [n, x] = print $ burger n x

main = map read . words <$> getLine >>= solve

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

int main() {
    int N;
    std::cin >> N;
    int64_t A[N], B[N];

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

    std::sort(A, A + N);
    std::sort(B, B + N);

 
    if (N % 2 == 0) {
        const int64_t mid_low  = (A[N/2] + A[N/2 - 1]);
        const int64_t mid_high = (B[N/2] + B[N/2 - 1]);

        std::cout << (mid_high - mid_low) + 1 << std::endl;
    } else {
        const int64_t mid_low  = A[N/2];
        const int64_t mid_high = B[N/2];
        std::cout << (mid_high - mid_low) + 1 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 6728
d = int(input())#365
clist = list(map(int,input().split()))#満足度の下がりやすさci, clist[i-1]でci
satisfactionlist = []#satisfactionlist[d-1][i-1]でsd,i
for _ in range(d):
    satisfactionlist.append(list(map(int,input().split())))

def decrease(clist,d,lastlist):
    sum = 0
    for i in range(26):
        sum += clist[i]*(d-lastlist[i])
    return sum

def calculate(d,clist,satisfactionlist,orderlist):
    satisfaction = 0
    lastlist = [0 for _ in range(26)]#lastlist[i-1] = last(d,i)
    for j in range(d):
        i = orderlist[j]#コンテストiをd日目にやると
        satisfaction += satisfactionlist[j][i-1]
        lastlist[i-1] = j+1
        satisfaction -= decrease(clist,j+1,lastlist)
    print(satisfaction)
    return satisfaction

orderlist = []

for day in range(d):
    combined1 = [x * y for (x, y) in zip(clist, satisfactionlist[day])]
    max_value = max(combined1)
    max_index = combined1.index(max_value)
    orderlist.append(max_index+1)

# print(orderlist)
# calculate(d,clist,satisfactionlist,orderlist)
for ans in orderlist:
    print(ans)

Measured memory_bytes: 9524
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	vector<int> p(n);
	for(int i=0;i<n;i++) cin>>p[i];
	int ans=0;
	for(int i=0;i+2<n;i++) if((p[i]<p[i+1]&&p[i+1]<p[i+2])||(p[i]>p[i+1]&&p[i+1]>p[i+2]))ans++;
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;


bool check(int acc, int depth, int ans, int A[], int n)
{
    if (depth == n)
        return false;
    if (A[depth] + acc == ans)
        return true;

    return check(acc + A[depth], depth + 1, ans, A, n) || check(acc, depth + 1, ans, A, n);
}


int main(void)
{
    int n, q;
    int A[20], M[200];

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> A[i];
    cin >> q;
    for (int i = 0; i < q; i++) {
        int ans;
        cin >> ans;
        if (check(0, 0, ans, A, n))
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	string s, t;
	cin >> N >> s >> t;

	int x = 0;

	for( int i = 1; i <= N; ++i ) {
		if( s.substr( N-i ) == t.substr( 0, i ) ) {
			x = i;
		}
	}

	cout << 2*(N-x) + x << endl;

	return 0;
}


Measured memory_bytes: 256
//ALDS1_5_B Recursion / Divide and Conquer - Merge Sort
#include <cstdio>
using namespace std;

#define MAX 500000
#define SENTINAL 2000000000

int cnt,n, L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(int *A, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;

    for (int i = 0; i < n1; i++)
    {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; i++)
    {
        R[i] = A[mid + i];
    }
    L[n1] = R[n2] = SENTINAL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++)
    {
        cnt++;
        if (L[i] <= R[j])
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
        }
    }
}

void mergeSort(int *A, int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(void)
{
    int A[MAX];
    cnt = 0;

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &A[i]);
    }

    mergeSort(A, 0, n);
    for (int i = 0; i < n; i++)
    {
        if (i)
            printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 6480