akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef pair<ll, pair<int, int>> P;
typedef pair<ll,pair<ll,ll>> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    a.push_back(INF);
    vector<int> sum(0);
    int cnt = 1;
    for(int i = 1; i <= N; i++){
        if(a.at(i-1)!= a.at(i)){
            sum.push_back(cnt);
            cnt = 1;
        }else{
            cnt++;
        }
    }
    int res = 0;
    for(int i = 0; i < sum.size(); i++){
        res += sum.at(i) / 2;
    }
    cout << res << endl;
}


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

#define int long long
#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) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#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 long double PI = 3.1415926535897932384626433832795028L;
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) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &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, K;
signed main() {
    cin >> N >> K;
    int ans = 1;
    while (N /= K) { ans++; }
    cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N){
    cin >> A[i];
  }
  
  map<int, int> count;
  rep(i, N){
    count[A[i]]++;
    count[A[i]+1]++;
    count[A[i]-1]++;
  }
  
  int max_value = 0;
  for (auto p : count) {
    max_value = max(max_value, p.second);
  }
  
  cout << max_value << endl;
    
}


Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<list>
#include<algorithm>
using namespace std;

int main () {
  int K,A,B;
  cin >> K >> A >> B;
  string ans="NG";
  for (int i = A;i<=B;i++) {
    if (i % K ==0) {ans="OK";break;}
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


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

    vector<double> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i] = (p[i]+1.0)/2.0;
    }

    double ans = 0.0;
    double e = 0.0;
    for(int i = 0; i < k; i++){
        e += p[i];
    }
    ans = e;
    for(int i = k; i < n; i++){
        e += p[i];
        e -= p[i-k];
        ans = max(ans, e);
    }

    printf("%.10f\n",ans);
    return 0;

}


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

const int MAXN = 100005;

int n;
pair<int,int> a[MAXN];
int x;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		a[i] = make_pair(x, i);
	}
	sort(a+1, a+n+1);
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		if ((a[i].second+i)&1)
			cnt++;
	assert(cnt%2 == 0);
	cout << cnt/2 << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll x[5];
ll ans;

int main() {
  rep( i, 5 ) {
    std::cin >> x[i];

    if( !x[i] )
      ans = i+1;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3568
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() (string, string) {
	return scanString(sc), scanString(sc)
}

func resolve(s, t string) int {
	opNum := 0
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			opNum++
		}
	}
	return opNum
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

#define MOD 1000000007

int main() {

	int n; cin >> n;
	vector<vector<int>> a(n, vector<int>(n, 0));
	for (int i = 0; i <= n - 1; i++) for (int j = 0; j <= n - 1; j++) cin >> a[i][j];

	vector<long long> dp(1 << n, 0);
	dp[0] = 1;
	long long ans = 0;

	for (int mask = 1; mask <= (1 << n) - 1; mask++) {
		int cnt = __builtin_popcount(mask);

		for (int j = 0; j <= n - 1; j++) {

			if (a[cnt - 1][j] == 1 and (mask & (1 << j)) != 0) {
				dp[mask] += dp[mask - (1 << j)];
				if (dp[mask] >= MOD) dp[mask] %= MOD;
			}
		}

		if (cnt == n) {
			ans += dp[mask];
			if (ans >= MOD) ans %= MOD;
		}
	}

	cout << ans;
	return 0;
}

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

using namespace std ;
#define int long long int

const int maxn = 100;
const int maxw = 1e5 + 5;
const int inf = -1e9 ;
vector< vector<int> > dp(maxn, vector<int>(maxw,inf));
vector<int> w(maxn);
vector<int> v(maxn);
int n , W;

int cnt = 0 ;

int solve(int i , int weight){
   
    if(i >= n){
        return 0;
    }
    int &ans = dp[i][weight] ;
    if(ans != inf) return ans;
    ans = 0;
    ans = max(ans , solve(i+1, weight));
    if(weight + w[i] <= W){
        ans = max(ans, v[i] + solve(i+1, weight + w[i]));
    }
    return ans;
}

int32_t main(){
    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    // #endif
    cin >> n >> W ;
    for(int i = 0 ; i < n ; i++ ){
        cin >> w[i] >> v[i];
    }
    cout<<solve(0,0)<<endl;
    return 0;
}

Measured memory_bytes: 79360
#include<bits/stdc++.h>
#define R register
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
double readdb()
{
    R double x=0,y=0.1,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(x=ch-'0';(ch=getc())>='0'&&ch<='9';x=x*10+ch-'0');
    for(ch=='.'&&(ch=getc());ch>='0'&&ch<='9';x+=(ch-'0')*y,y*=0.1,ch=getc());
    return x*f;
}
const int N=1e5+5;
struct node{
    double x,y;
    inline node(){}
    inline node(R double xx,R double yy):x(xx),y(yy){}
    inline node operator +(const node &b)const{return node(x+b.x,y+b.y);}
    inline node operator -(const node &b)const{return node(x-b.x,y-b.y);}
    inline double operator *(const node &b)const{return x*b.y-y*b.x;}
    inline node operator *(const double &b)const{return node(x*b,y*b);}
    inline double operator ^(const node &b)const{return x*b.x+y*b.y;}
    inline double len2(){return x*x+y*y;}
    inline node rot(){return node(-y,x);}
}p[N],o;
struct Line{
    node p,v;
    inline Line(){}
    inline Line(R node pp,R node vv):p(pp),v(vv){}
    friend node cross(const Line &a,const Line &b){return a.p+a.v*(b.v*(b.p-a.p)/(b.v*a.v));}
};
node circle(const node &a,const node &b,const node &c){
    return cross(Line((a+b)*0.5,(b-a).rot()),Line((a+c)*0.5,(c-a).rot()));
}
int n;double r;
int main(){
//  freopen("testdata.in","r",stdin);
    n=read();
    fp(i,1,n)p[i].x=readdb(),p[i].y=readdb();
    random_shuffle(p+1,p+1+n);
    r=0,o=node(0,0);
    fp(i,1,n)if((p[i]-o).len2()>r){
        o=p[i],r=0;
        fp(j,1,i-1)if((p[j]-o).len2()>r){
            o=(p[i]+p[j])*0.5,r=(p[j]-o).len2();
            fp(k,1,j-1)if((p[k]-o).len2()>r)
                o=circle(p[i],p[j],p[k]),r=(p[k]-o).len2();
        }
    }
    printf("%.10f",sqrt(r));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
const int N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;

int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int ret=1;
	int n,a,sgn=0; cin>>n>>a;
	for(int i=1; i<n; i++) {
		int b;
		cin>>b;
		if(b==a)
          continue;
		if(sgn) {
			if(sgn*(b-a)<0)
				sgn=0, ret++;
		} else sgn=b>a?1:-1;
		a=b;
	}
	cout << ret << endl;

}







Measured memory_bytes: 256
N, X = map(int, input().split())
m_list = [int(input()) for i in range(N)]

mmin = min(m_list)
msum = sum(m_list)
rest_X = X- msum

i = 0

while rest_X >= mmin:
    i += 1
    rest_X -= mmin

print(len(m_list) + i)


Measured memory_bytes: 3060
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque

def run():
    N = input()
    S = input()
    dp = [0] * 1000
    ans = 0
    for n in S:
        n = int(n)
        #print(dp)
        for i in range(1000):
            if i // 100 == n and dp[i] == 0:
                dp[i] = 1
                #print(f'{i} -> 1')
            elif (i // 10) % 10 == n and dp[i] == 1:
                dp[i] = 2
                #print(f'{i} -> 2')
            elif i % 10 == n and dp[i] == 2:
                dp[i] = 3
                #print(f'{i} -> 3')
                ans += 1
    print(ans)

    #print(factorials)
if __name__ == "__main__":
    run()

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    ll N;
    ll A[200000], B[200000];
    ll C[200000];
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i] >> B[i];
    for(int i=0;i<N;i++) C[i]=A[i]+B[i];
    sort(C,C+N);

    ll bsum=0;
    for(int i=0;i<N;i++) bsum += B[i];

    ll pt=0;
    for(int i=N-1;i>=0;i-=2){
        pt += C[i];
    }

    cout << (pt-bsum) << endl;
    
    return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
  FAST/**/
   
   ll x;
   cin>>x;
   
   ll ans = (ll)10 - (x/200);
   cout<<ans;
   
   
   return 0;        
}  
  
          
   

Measured memory_bytes: 3648
import fractions
import itertools
import collections

n = int(input().split()[0])
a_list = list(map(int, input().split()))
sorted_list = sorted(a_list)
min_a, second_min_a = sorted_list[0], sorted_list[1]

def koyakusu(x):
    i = 1
    koyaku_list = []
    while i * i <= x:
        if x % i == 0:
            koyaku_list.append(i)
            koyaku_list.append(x//i)
        i += 1

    koyaku_list = list(set(koyaku_list))
    return koyaku_list

kouho_list = []
# print('{}: {}'.format(min_a, koyakusu(min_a)))
kouho_list += koyakusu(min_a)

# print('{}: {}'.format(second_min_a, koyakusu(second_min_a)))
kouho_list += koyakusu(second_min_a)
kouho_list = list(set(kouho_list))
# print(kouho_list)
ans_kouho_list = []

for kouho in kouho_list:
    x_list = [x for x in a_list if x % kouho == 0]
    # print('kouho {} ({})'.format(kouho, len(x_list)))
    if len(x_list) >= n-1:
        ans_kouho_list.append(kouho)
# print(ans_kouho_list)
ans = max(ans_kouho_list)

print(ans)


Measured memory_bytes: 16152
#include<iostream>
#include<fstream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>
#include<set>

using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl
#define pb push_back
#define mp make_pair

typedef long long tint;
typedef unsigned long long utint;
typedef long double ldouble;

typedef vector<int> vint;

int toNumber (string s)
{
	int Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}

string toString (int number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

int main (){
	tint n,c,k;
	cin>>n>>c>>k;
	vector<tint> s;
	forn(i,n){
		tint p;
		cin>>p;
		s.pb(p);
	}
	sort(s.begin(), s.end());
	if(c==1){
		cout<<n<<endl;
		return 0;
	}
	tint tot=0;
	tint pri;
	tint cant=0;
	tint last=-1;
	forn(i, n){
		cant++;
		if(i==0){
			pri=s[i];
			continue;
		}
		if(cant==c+1){
			//cout<<"tengo muchos "<<s[i]<<endl;
			tot++;
			pri=s[i];
			last=i-1;
			cant=1;
			continue;
		}
		if(s[i]-pri>k){
			//cout<<s[i]<<" dif con "<<pri<<endl;
			tot+=1;
			cant=1;
			pri=s[i];
			last=i-1;
		}
	}
	if(last!=n-1)tot++;
	cout<<tot<<endl;
}


Measured memory_bytes: 1400
/* Collatz Problem */

#include <iostream>
using namespace std;

int func(int n){
    if(n % 2 == 0){
    	return n / 2;
    }else{
    	return 3 * n + 1;
    }
}

int main(){
	int s;
	cin >> s;
	int a[1000001];
	a[0] = s;

	int m = 1;

	while(1){
		a[m] = func(a[m-1]);
		for(int i = 0; i < m; i++){
			if(a[i]==a[m]){
				cout << m + 1 << endl;
				return 0;
			}
		}
		m++;
	}

}

Measured memory_bytes: 256
def solve(ls):
    n = len(ls)
    lim = max(ls)
    sieve = [1] * (lim + 1)
    result = 0
    ls.sort()
    for i in range(n):
        x = ls[i]
        if sieve[x] == 0:
            continue
        # Don't count if ls[i] = ls[i+1]
        if not (i + 1 < n and x == ls[i + 1]):
            result += 1
        y = x
        while y <= lim:
            sieve[y] = 0
            y += x
    return result


def main(istr, ostr):
    n = list(map(int, istr.readline().strip().split()))
    ls = list(map(int, istr.readline().strip().split()))
    result = solve(ls)
    print(result, file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)


Measured memory_bytes: 32180
#include<bits/stdc++.h>
    using namespace std;
    vector<pair<int,int> > add[2000000];
    vector<pair<int,int> > rem[2000000];
     
    long long dp[2000000];
    long long tree[2000000];
    long long lazy[2000000];
    void lzy(int x)
    {
        tree[x]+=lazy[x];
        lazy[x*2]+=lazy[x];
        lazy[x*2+1]+=lazy[x];
        lazy[x]=0;
    }
    void update(int x,int l,int r,int s,int e,long long v)
    {
        lzy(x);
        if (s>r || e<l)return;
        if (l>=s && r<=e)
        {
            lazy[x]=v;
            lzy(x);
            return;
        }
        update(x*2,l,(l+r)/2,s,e,v);
        update(x*2+1,(l+r)/2+1,r,s,e,v);
        tree[x]=max(tree[x*2],tree[x*2+1]);
    }
    long long query(int x,int l,int r,int s,int e)
    {
        lzy(x);
        if (l>e || r<s)return -1e16;
        if (l>=s && r<=e)return tree[x];
        return max(query(x*2,l,(l+r)/2,s,e),query(x*2+1,(l+r)/2+1,r,s,e));
    }
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);cout.tie(0);
        int n,m;
        cin>>n>>m;
        for (int i=0;i<m;i++)
        {
            int l,r,v;
            cin>>l>>r>>v;
            add[l].push_back({l-1,v});
            rem[r].push_back({l-1,-v});
        }
        for (int i=1;i<=n;i++)
        {
            for (auto x:add[i])update(1,0,n,0,x.first,x.second);
            dp[i] = query(1,0,n,0,i-1);
            for (auto x:rem[i])update(1,0,n,0,x.first,x.second);
            update(1,0,n,i,i,dp[i]);
        }
        cout<<*(max_element(dp,dp+n+1))<<endl;
    }

Measured memory_bytes: 128768
// ALDS1_7_D: Reconstruction of the Tree

use std::str::FromStr;

fn scan<T: FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn scan_vec<T: FromStr>() -> Vec<T> {
    let s: String = scan();
    s.split_whitespace().map(|a| T::from_str(a).ok().unwrap()).collect()
}

fn rec(
    preorder: &Vec<usize>,
    inorder: &Vec<usize>,
    postorder: &mut Vec<usize>,
    pos: &mut usize,
    l: usize, 
    r: usize, 
) {
    if l >= r {
        return;
    }
    let c = preorder[*pos];
    let m = inorder.iter().position(|&x| x == c).unwrap();
    *pos += 1;
    rec(preorder, inorder, postorder, pos,  l, m);
    rec(preorder, inorder, postorder, pos,  m + 1, r);
    postorder.push(c);
}

fn solve(
    preorder: &Vec<usize>,
    inorder: &Vec<usize>,
) {
    let mut pos: usize = 0;
    let mut postorder: Vec<usize> = Vec::new();
    rec(preorder, inorder, &mut postorder, &mut pos, 0, preorder.len());
    let ans = postorder.iter().map(|a| a.to_string()).collect::<Vec<String>>().join(" ");
    println!("{}", ans);
}

fn main() {
    let _: usize = scan();
    let preorder: Vec<usize> = scan_vec();
    let inorder: Vec<usize> = scan_vec();
    solve(&preorder, &inorder);
}


Measured memory_bytes: 5032
from operator import itemgetter
N, M = map(int, input().split())
P = [[0, 0, 0] for _ in range(M)]
for i in range(M):
    P[i][0], P[i][1] = map(int, input().split())
    P[i][0] = (6-len(str(P[i][0])))*"0"+str(P[i][0])
    
P_s = sorted(P, key=itemgetter(0, 1))

for i in range(1, M):
    if(P_s[i][0] == P_s[i-1][0]):
        P_s[i][2] = P_s[i-1][2]+1
    
for i in range(M):
    print(P[i][0]+(6-len(str(P[i][2]+1)))*"0"+str(P[i][2]+1))
 

Measured memory_bytes: 32208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication39
{
    class Program
    {
        static void Main(string[] args)
        {
           double[] a = new double[2];
	 a=Console.ReadLine().Split().Select(double.Parse).ToArray();
	 double b = a[0]+a[1];
             Console.WriteLine(Math.Ceiling(b/2));
        }
     }
}


Measured memory_bytes: 13268
import itertools


n,k = map(int,input().split())

d=[]
A=[]

for i  in range(k):
    d.append(int(input()))
    A.append(list(map(int,input().split())))


A=list(itertools.chain.from_iterable(A))

count = 0
for i in range(n):
    if i+1 not in A:
        count +=1

print(count)

Measured memory_bytes: 9104
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
	int n,k;
	cin >> n;
	cin >> k;
	vector<int> a(n);

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

	int sum = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] >= k) {
			sum++;
		}
	}
	cout << sum;
}

Measured memory_bytes: 640
D, N = map(int, input().split())

def calc(n):
    count = 0
    while n % 100 == 0:
        count += 1
        n /= 100
    return count

count = 0
val = 0
while count < N:
    val += 1
    if calc(val) == D:
        count += 1

print(val)

Measured memory_bytes: 3060
import itertools
 
s=input()

s=list(s)

keta = len(s)

pluscheck = []

ans = 0

for i in range(1,keta):
    pluscheck.append(i)

for i in range(keta):
    for j in itertools.combinations(pluscheck,i):
        memo = []
        for k in range(keta):
            if k in j:
                ans += int(''.join(map(str,memo)))
                memo = []
                memo.append(s[k])
            else:
                memo.append(s[k])
        ans += int(''.join(map(str,memo)))
print(ans)

Measured memory_bytes: 41072
//
import java.math.*;
import java.util.*;
import java.io.*;
  
public class Main { 
  
    static BufferedReader in;
    static PrintWriter out = new PrintWriter(System.out);
    static String file = "../in";
    static int test = 10; // 0 for local testing, 1 for std input
    static int inf = 1_000_000, mod = 1_000_000_007;

    void swap(int[]ary, int i, int j)
    {
        int t = ary[i];
        ary[i] = ary[j];
        ary[j] = t;
    }
    
    String[] split() throws Exception
    {
        return in.readLine().split(" ");
    }

    int readInt() throws Exception
    {
        return Integer.valueOf(in.readLine());
    }

    long[] toLongArray() throws Exception
    {
        String[] sp = split();
        int n = sp.length;
        long[] ary = new long[n];
        for(int i = 0; i < n; i++) ary[i] = Long.valueOf(sp[i]);
        return ary;
    }

    int[] toIntArray() throws Exception
    {
        String[] sp = split();
        int n = sp.length;
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) ary[i] = Integer.valueOf(sp[i]);
        return ary;
    }

    String reverse(String str)
    {
        return new StringBuilder(str).reverse().toString();
    }


    long pow(long a, int pow)
    {
        long res = 1;
        while(pow > 0)
        {
            if(pow % 2 != 0) {
                res *= a;
                res %= mod;
            }
            a = a * a;
            a %= mod;
            pow /= 2;
        }

        return res;
    }

    public static void main(String[] args) throws Exception
    {
        int _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
        // System.out.println((-100 + 0) / 2);

        new Main().b();
        out.flush();
    }

    void b() throws Exception
    {
        long[] ary = toLongArray();
        long n = ary[0], a = ary[1], b = ary[2];
        // a blue then b red balls
        // number of blue balls in first N
        long ab = a + b;
        long mult = n / ab;
        long rem = n % ab;
        long ans = mult * a;
        if(rem < a) ans += rem;
        else ans +=a ;
        out.println(ans);
    }

    void a() throws Exception
    {
        String str = in.readLine();
        int a = 0, b = 0;
        for(char c : str.toCharArray())
        {
            if(c == 'A') a++;
            else b++;
        }
        if(a > 0 && b > 0) out.println("Yes");
        else out.println("No");
    }
}

Measured memory_bytes: 23124
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 4;
const int D = 11;

pii c[N][D];
int n, m;
vector<int> g[N];

void read() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        g[a].em_back(b);
        g[b].em_back(a);
    }
}

void push(int u, int v, int d) {
    int tu = c[u][d].first;
    int tv = c[v][d - 1].first;
    if (tu > tv) {
        c[v][d - 1] = c[u][d];
    }
}

void solve() {
    read();

    int q;
    cin >> q;
    for (int i = 1; i <= q; ++i) {
        int v, d, cl;
        cin >> v >> d >> cl;
        c[v][d] = pii(i, cl);
    }

    for (int i = 10; i > 0; --i) {
        for (int u = 1; u <= n; ++u) {
            push(u, u, i);
            for (int to : g[u]) {
                push(u, to, i);
            }
        }
    }

    for (int u = 1; u <= n; ++u) {
        cout << c[u][0].second << "\n";
    }
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  string s,t; cin>>s>>t;
  ll n=s.size();
  rep(i,n){
    if(s==t){
      cout<<"Yes"<<endl;
      return 0;
    }
    s=s[n-1]+s.substr(0,n-1);
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std ;
const int N = 5e5 + 10 ;
vector<int> v[N] ;
int main()
{
  string s ;
  cin >> s ;
  if(s[2] == s[3] && s[4] == s[5]) puts("Yes") ;
  else puts("No") ;
  return 0 ;
}


Measured memory_bytes: 11904
x = int(input())
y = int(input())
z = int(input())
n = int(input())
cnt=0
for i in range(x+1):
    for j in range(y+1):
        for k in range(z+1):
            if 500*i+100*j+50*k == n:
                cnt +=1
print(cnt)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

typedef long long ll;

int main(){
    int n;
    cin >> n;
    int maxx = -1, minx = 99999;
    FOR(i,0,n){
        int in;
        cin >> in;
        maxx = max(maxx, in);
        minx = min(minx, in);
    }
    cout << maxx - minx << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int N, count = 0;
	scanf("%d", &N);
	for (int i = 0; i <= (N / 4); i++) {
		for (int j = 0; j <= (N / 7); j++) {
			if (i * 4 + j * 7 == N) {
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; cin >> N;
  vector<string> S(N); rep(i,N) cin >> S[i];
  set<string> st;
  rep(i,N) st.insert(S[i]);
  cout << sz(st) << endl;
  return 0;
}


Measured memory_bytes: 25108
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;

    ll re = 0, rw = 0;
    for(ll i=0;i<n;++i){
        if(s[i] == 'E'){
            re++;
        }else{
            rw++;
        }
    }

    ll ans = INF;
    ll le = 0, lw = 0;
    for(ll i=0;i<n;++i){
        if(s[i] == 'E'){
            re--;
            ans = min(ans, lw + re);
            le++;
        }else{
            rw--;
            ans = min(ans, lw + re);
            lw++;
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
# define M_PI 3.14159265358979323846
using ll = long long int;
const int MOD = 1e9 + 7;
int gcd(int a, int b) 
{ 
   if (b == 0) 
      return a; 
   return gcd(b, a % b);  
} 
int main()
{
    int k;
    cin>>k;
    ll sum=0;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=k;j++)
        {
            for(int r=1;r<=k;r++)
            {
                sum+=gcd(i,gcd(j,r));
            }
        }
    }
    cout<<sum;
}

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
int main() {
	int ms, mn;
	while (true) {
		int a, b;
		cin >> a >> b;
		if (a == 0)break;
		ms = 0;
		mn = a + b;
		for (int i = 1; i <= 4; ++i) {
			cin >> a >> b;
			int num = a + b;
			if (mn < num) {
				ms = i;
				mn = num;
			}
		}
		cout << (char)('A' + ms) << ' ' << mn << endl;
	}
	return 0;
}

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

int main()
{
        int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        int n;
        cin >> n;
        cout << arr[n-1] << endl;
}


Measured memory_bytes: 256
N, W = map(int, input().split())
wv = [tuple(map(int, input().split()))for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for j in range(W):
        w, v = wv[i]
        if N < i+1:
            continue
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if W < j+w:
            continue
        dp[i+1][j+w] = max(dp[i][j+w], dp[i][j]+v)
print(dp[-1][-1])


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

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

    vector<int> d(n);
    for (int i = 0; i < n; i++) cin >> d.at(i);

    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());

    int c = 1, tmp = d.at(0);
    for (int i = 1; i < n; i++) {
        if (tmp > d.at(i)) {
            tmp = d.at(i);
            c++;
        }
    }

    cout << c << endl;

    return 0;
}


Measured memory_bytes: 3552
s = gets.chomp.split(//)
e = Array.new(s.size * 2 - 1, "")
s.each_with_index do |c, i|
    e[i * 2] = c
end
m = 2 ** (s.size - 1)
sum = 0
m.times do |i|
    j = i.to_s(2)
    if (j.size < s.size - 1)
        j = "0" * (s.size - 1 - j.size) + j
    end
    f = Marshal.load(Marshal.dump(e))
    j.each_char.with_index do |c, i|
        if c == '1'
            f[i * 2 + 1] = "+"
        end
    end
    sum += eval(f.join)
end
p sum

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int a, b; cin >> a >> b;
  int ans = 0;
  if (a == 1) {
    ans=1;
  } else if (a <= b) {
    ans=a;
  } else {
    ans=a-1;
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int N = 1e5+5;
struct Man{
   int a,b;
   bool operator<(const Man &rhs)const{
      return a-b>rhs.a-rhs.b;
   }
}s[N];
int n,c[N],l,ma[N],b[N];
priority_queue<pii>q;
set<pii>se;
int solve(){
  ll up=0,down=0;
  for(int i=1;i<=n;++i){
     if(up+ma[i]>=l)return i;
     up+=s[i].a-s[i].b;
     ll tmp = up-down;
     while(!q.empty()&&q.top().first>=tmp){
         int x = q.top().second;
         q.pop();
         se.erase(make_pair(s[x].b,x));
     }
     if(!se.empty()&&up+(*--se.end()).first>=l)return i;
     down+=c[i];
     if(up<=down)break;
     se.insert(make_pair(s[i].b,i));
     q.push(make_pair(s[i].a-s[i].b,i));
  }
  return -1;
}
int main() {
   scanf("%d%d",&n,&l);
   for(int i=1;i<=n;++i){
      scanf("%d%d",&s[i].a,&s[i].b);
   }
   for(int i=1;i<=n;++i)scanf("%d",&c[i]);
   sort(s+1,s+1+n);
   for(int i=n;i>=1;--i)ma[i]=max(ma[i+1],s[i].a);
   printf("%d\n",solve());
   return 0;
}

Measured memory_bytes: 10016
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")

using namespace std;

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

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;

string s;
int par[N];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s;
	for (int i = 1; i <= s.size(); i++){
		par[i] = par[i - 1];
		if (s[i - 1] == 'B') par[i]++;
	}
	ll ans = 0;
	for (int i = 1; i <= s.size(); i++){
		if (s[i - 1] == 'W') continue;
		int R = s.size() - i;
		ll B = par[s.size()] - par[i];
		ans += R - B;
	}	
	cout << ans;











	return 0;
}


Measured memory_bytes: 1300
n=int(input())
m=list(map(int,input().split()))
for i in range(n):
  a=0
  while m[i]%2==0:
    m[i]//=2
    a+=1
  if a>2:
    a=2
  m[i]=a
if m.count(2)>=m.count(0):
  print("Yes")
elif m.count(0)==0:
  print("Yes")
elif m.count(1)==0 and m.count(2)>=m.count(0)-1:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 14252
N = 10**5
p = [0]*(N+1)
q = [0]*(N+1)

p[2] = 1
primes = [2]

for i in range(3,N+1):
  f = 1
  for t in primes:
    if t*t > i:
      break
    if i%t == 0:
      f = 0
      break
  if f == 1:
    primes.append(i)
    p[i] = 1
    if p[(i+1)//2]:
      q[i] = 1
m = 0
s = [0]*(N+1)
for i in range(1,N+1):
  m += q[i]
  s[i] = m
  
for i in range(int(input())):
  l,r = map(int,input().split())
  print(s[r]-s[l-1])

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

#define P pair<int, int>
#define PP pair<P, int>
#define tPP pair<int, P>
#define mp make_pair
#define pb push_back
#define fn fill_n
#define llong long long 

using namespace std;

int rui[90001];
string in;
int h, w, d, q, l[100000], r[100000];
P place[90000];

void ruiseki(){
	for(int i = 1; i <= d; i++){
		rui[i] = 0;
		for(int j = i + d; j <= h*w; j += d){
			rui[j] = rui[j - d] + abs(place[j].first - place[j - d].first) + abs(place[j].second - place[j - d].second);
		}
	}

	return;
}

int main(){
	cin >> h >> w >> d;
	int in;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> in;
			place[in] = mp(i, j);
		}
	}
	ruiseki();
	cin >> q;
	for(int i = 0; i < q; i++){
		cin >> l[i] >> r[i];
	}
	for(int i = 0; i < q; i++){
		cout << rui[r[i]] - rui[l[i]] << endl;
	}
	// for(int i = 0; i <= h * w; i++){
	// 	cerr << rui[i] << " ";
	// }

	return 0;
}

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

const long long MAX_VAL = 1LL << 60;
int n, k;
long long h[100000];
long long dp[100000];

long long dpmax(int i) {
    long long minc = MAX_VAL;
    long long c = MAX_VAL;
    for (int j = 0; j < min(i, k); j++) {
        minc = min(minc, abs(h[i] - h[i - (j + 1)]) + dp[i - (j + 1)]);
    }
    return minc;
}

void initH() {
    for(int i=0; i<100000; i++) {
        h[i] = MAX_VAL;
    }
}

int main() {
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    dp[0] = 0;

    for(int i = 1; i < n; i++) {
        dp[i] = dpmax(i);
    }

    cout << dp[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <queue>
using namespace std;
int main(){
    int h,w,n;
    cin >> h >> w >> n;
    queue<int> q;
    for (int i=0; i<n; i++){
        int x;
        cin >> x;
        for (int j=0; j<x; j++){
            q.push(i+1);
        }
    }
    for (int i=0; i<h; i++){
        int a[w];
        for (int j=0; j<w; j++){
            a[j]=q.front();
            q.pop();
        }
        if (i%2==0){
            for (int j=0; j<w; j++){
                cout << a[j] <<" " ;
            }
            cout << endl;
        }else {
            for (int j=0; j<w; j++){
                cout <<a[w-j-1] << " ";
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanVecInt(A, N);
    int top_count = 0;
    array<char, 8> flag; flag.fill(false);
    for (auto& a : A){
        if (3200 <= a){
            ++top_count;
        }else{
            flag[a / 400] = true;
        }
    }
    int count = 0;
    for (auto& f : flag){
        if (f) ++count;
    }
    printf("%d %d\n", max(count, 1), count + top_count);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int judge=0,cplace;
    char a[105];
    gets(a);
    for(int i=0;i<strlen(a);i++)
    {
    	if(a[i]=='C')
		{
		 	judge=1;
    		cplace=i;
			break;	
		}
    	
	}
	if(!judge||cplace==strlen(a)-1){
		printf("No");
		return 0;	
	}
	for(int i=cplace+1;i<strlen(a);i++)
	{
		if(a[i]=='F')
		{
		 	printf("Yes");
	 		return 0;	
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;

public class Program{
    public static void Main(){
        int N=int.Parse(Console.ReadLine());
        var v=Console.ReadLine().Split(' ').Select(x=>double.Parse(x)).ToList();
        v.Sort();
        v[0]/=Math.Pow(2,N-1);
        for(int i=1;i<N;i++){
            v[i]/=Math.Pow(2,N-i);
        }
        Console.WriteLine(v.Sum());
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    int maxi = 0;
    cin>>s;
    for(int i=1;i<s.length()-1;i++){
        int f1[26]={0}, f2[26]={0};
        for(int j=0;j<i;j++)    {f1[s[j]-'a']++;}
        //cout<<endl;
        for(int j=i;j<s.length();j++)   {f2[s[j]-'a']++;}
        int cnt = 0;
        for(int k=0;k<26;k++){
            if(f1[k]>0&&f2[k]>0)  {//cout<<k<<" ";
            cnt++;}
        }
        maxi = max(cnt,maxi);
        //cout<<maxi<<endl;
    }
    cout<<maxi;
    return 0;
}

Measured memory_bytes: 256
// Problem : F - Distributing Integers
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_f
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int N;
vector<int> graph[200005];
long long fact[200005];
long long dp[200005];
long long sz[200005];
long long ans[200005];
const long long MOD = 1e9+7;

long long mult(long long a, long long b){
	return (a*b)%MOD;
}

long long qikpow(long long b, long long e){
	if(!e){
		return 1;
	}
	long long ret = qikpow(b, e>>1);
	if(e&1){
		return mult(mult(ret, ret), b);
	}
	return mult(ret, ret);
}

long long divd(long long a, long long b){
	return mult(a, qikpow(b, MOD-2));
}

void dfs1(int n, int p){
	sz[n] = 1;
	dp[n] = 1;
	for(int e : graph[n]){
		if(e != p){
			dfs1(e, n);
			dp[n] = mult(dp[e], dp[n]);
			dp[n] = divd(dp[n], fact[sz[e]]);
			sz[n] += sz[e];
		}
	}
	//cout << n << " " << dp[n] << "\n";
	dp[n] = mult(dp[n], fact[sz[n]-1]);
}

void dfs2(int n, int p){
	dp[n] = fact[N-1];
	for(int e : graph[n]){
		if(e == p){
			dp[n] = mult(dp[e], dp[n]);
			dp[n] = divd(dp[n], fact[N-sz[n]]);
		}
		else{
			dp[n] = mult(dp[e], dp[n]);
			dp[n] = divd(dp[n], fact[sz[e]]);
		}
	}
	ans[n] = dp[n];
	for(int e : graph[n]){
		if(e != p){
			long long olde = dp[e];
			dp[n] = divd(dp[n], fact[N-1]);
			dp[n] = mult(dp[n], fact[N-sz[e]-1]);
			dp[n] = divd(dp[n], dp[e]);
			dp[n] = mult(dp[n], fact[sz[e]]);
			//cout << e << " " << p << " extra: " << dp[n] << "\n";
			dfs2(e, n);
			dp[n] = ans[n];
			dp[e] = olde;
		}
	}
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N;
	for(int i = 1; i<N; i++){
		int a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	fact[0] = 1;
	for(int i = 1; i<=N; i++){
		fact[i] = mult(fact[i-1], i);
	}
	dfs1(1, 0);
	//cout << dp[1] << "\n";
	dfs2(1, 0);
	for(int i = 1; i<=N; i++){
		cout << ans[i] << "\n";
	}
}

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

#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cout<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#define debug2(x, y) cout<<__LINE__<<": "<<#x<<" = "<<x<<\
                                     "  "<<#y<<" = "<<y<<endl;
#define all(c) (c).begin(), (c).end()
#define F first
#define S second
#define UNIQUE(c) \
    sort(all(c)); \
    (c).resize(unique(all(c))-c.begin());

#define PI 3.1415926535897932384626433832795028841971

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

const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;

inline int cmp(double x, double y = 0, double tol = EPS){
  return ((x <= y+tol) ? (x+tol < y) ? -1:0:1);
}

#define MAXN 200000+1
int n;
vector< int > vec;
ll freq[ MAXN ];

int main() {

  cin >> n;
  vec.resize(n);

  rep(i,0,n){
    cin >> vec[i];
    freq[ vec[i] ]++;
  }

  ll global = 0;
  rep(i,0,n + 1){
    global += (freq[i] * (freq[i] - 1))/2;
  }

  vector< ll > ans;
  rep(i,0,n){
    int k = vec[i];
    ll aux = global - (freq[k] * (freq[k] - 1))/2;
    ll fk = freq[ k ] - 1;

    ans.push_back( aux + fk*(fk-1)/2);
  }

  rep(i,0,n) cout << ans[i] << endl;

	return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int cnt1 = C / B;
    if (C % B) cnt1++;

    int cnt2 = A / D;
    if (A % D) cnt2++;

    if (cnt1 <= cnt2) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3564