akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<28
#define MAX 100005


typedef long long ll;

int n, a[100005];
int dp[MAX];

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

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

signed main(){
	int X, Y, A, B, C, i;
	scanf("%lld%lld%lld%lld%lld", &X, &Y, &A, &B, &C);
	vector<int> p(A), q(B), r(C);
	for(i = 0; i < A; i++){
		scanf("%lld", &p[i]);
	}
	for(i = 0; i < B; i++){
		scanf("%lld", &q[i]);
	}
	for(i = 0; i < C; i++){
		scanf("%lld", &r[i]);
	}
	sort(p.begin(), p.end(), greater<int>());
	sort(q.begin(), q.end(), greater<int>());
	sort(r.begin(), r.end(), greater<int>());
	int ans = 0, now = 0;
	for(i = 0; i < X; i++){
		now += p[i];
	}
	int a = X, b = 0, c1 = 0, c2 = 0;
	for(i = 0; i < Y; i++){
		if(c2 < C && q[b] < r[c2]){
			now += r[c2];
			c2++;
		}
		else{
			now += q[b];
			b++;
		}
	}
	ans = now;
	while(c1 < X && c1 < C){
		a--;
		now -= p[a];
		if(c1 == c2){
			now += r[c1];
			c1++;
			c2++;
		}
		else if(c2 < C && q[b] < r[c2]){
			now += r[c2];
			c1++;
			c2++;
		}
		else{
			now += q[b];
			c1++;
			b++;
		}
		ans = max(ans, now);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  Int n=s.size();
  Int dp[20][4][2][2][10];
  memset(dp,-1,sizeof(dp));
  function<Int(Int,Int,Int,Int,Int)> dfs=
    [&](Int pos,Int st,Int ok,Int lim,Int pre){
    if(pos==n) return ok;
    Int &res=dp[pos][st][ok][lim][pre];
    if(~res) return res;
    res=0;
    for(Int i=0;i<=(lim?s[pos]-'0':9);i++){
      Int nlim=lim&&(i==s[pos]-'0');
      if(st==0&&i==5){
	res+=dfs(pos+1,1,ok,nlim,i);
      }else if(st==1&&i==1){
	res+=dfs(pos+1,2,ok,nlim,i);
      }else if(st==2){
	res+=dfs(pos+1,3,ok,nlim,i);
      }else if(st==3){
	if(i==3) res+=dfs(pos+1,0,1,nlim,i);
	else if(pre==5&&i==1) res+=dfs(pos+1,2,ok,nlim,i);
	else res+=dfs(pos+1,i==5,ok,nlim,i);
      }else res+=dfs(pos+1,i==5,ok,nlim,i);
    }
    //cout<<pos<<" "<<st<<" "<<ok<<" "<<lim<<" "<<pre<<":"<<res<<endl;
    return res;
  };
  cout<<dfs(0,0,0,1,0)<<endl;
  return 0;
}



Measured memory_bytes: 3252
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;

int main() {
	int n,m;
	cin >> n>>m;
	int ans;
	ans = m * pow(100, n);
	if(m == 100) {
		ans = 101 * pow(100, n);
	}
	cout << ans << endl;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
using namespace std;


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

/* vector<int> A(N); 
　xの二乗:  pow(x, 2.0) 
    小さい順: sort(v.begin(), v.end());
*/
 
int main() {
  
  int N,count=0,c=0;
  cin >> N;
  vector<int> A(N);
  
  rep(i,N){
  	cin >>A.at(i);
  }
  
 sort(A.begin(), A.end());
  
 rep(i,N-1){
 	if(A.at(i)==A.at(i+1))count++;
 }
  
  if(count==0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;

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

Measured memory_bytes: 256
# ABC146d
ans = 1


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())

    n = int(input())

    edges = [list() for _ in range(n)]
    colors = [-1] * (n - 1)

    for i in range(n - 1):
        a, b = map(int, input().split())
        edges[a - 1].append((b - 1, i))
        edges[b - 1].append((a - 1, i))

    def dfs(i, color, pre):
        nc = 0 if color != 0 else 1
        for e in edges[i]:
            if e[0] == pre:
                continue
            global ans
            if ans < len(edges[i]):
                ans = len(edges[i])
            colors[e[1]] = nc
            dfs(e[0], nc, i)
            nc += 1
            if nc == color:
                nc += 1
    dfs(0, -1, -1)
    print(ans)
    for i in colors:
        print(i+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 89848
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

int n , m, cost[mx3], arr[mx3], ans , sum , a , b;
const int inf = 0x3f3f3f3f;
string str;
 
int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		cin>>n>>m;
		int dp[1<<n];
		fo(i,m)
		{
			cin>>cost[i]>>b;
			int tmp=0;
			fo(j,b)
			{
				cin>>a;
				a--;
				tmp|=(1<<a);
			}
			arr[i]=tmp;
		}
		memset(dp,inf,sizeof(dp));
		dp[0]=0;
		fo(i,m)
		{
			fo(j,1<<n)
			{
				dp[j|arr[i]]=min(dp[j|arr[i]],dp[j]+cost[i]);
			}
		}
		//cout<<(1<<n)-1<<" ";
		cout<<(dp[(1<<n)-1]>=inf ? -1 : dp[(1<<n)-1]);
	}
	return 0;
}

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

int64_t GCM(int64_t a,int64_t b){
    if(a<b) swap(a,b);
    int64_t d=a%b;
    if(d==0){
        return b;
    }
    return GCM(b,d);
}

int main(){
    int64_t a,b;
    cin>>a>>b;
    int64_t x=a*b/GCM(a,b);
    cout<<x<<endl;

    // cout<<GCM(5,10)<<endl;
    // cout<<GCM(4,6)<<endl;
    // cout<<GCM(5,12)<<endl;
    // cout<<GCM(12,18)<<endl;
    
    
}

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

using namespace std;

#define INF 1234567890
#define N (int)(2e5 + 5)
const double pi = 3.14159265358979323846;
typedef long long ll;

void solve()
{
    int n;
    double v[101];
    double nr = 0.0, sum = 0.0;
    double m;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
    {
        cin >> v[i];
        sum += v[i];
    }
    for(int i = 1; i <= n; ++i)
        if(v[i] < (1.0 / (4.0 * m)) * sum) continue;else ++nr;
    if(nr >= m) cout << "Yes";else
        cout << "No";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a,a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ll x, ll y, ll a, ll b){ return sqrt((x - a)*(x - a) + (y - b)*(y - b)); }
void debug(ll* a, ll n) { for ( int k = 0; k < n; k++ ){ cout << a[k] << " ";} cerr << "\n"; }

int main() {
	ll a, b; cin >> a >> b;
	vector<ll> div;
	ll y = max(a, b);
	ll x = min(a, b);
	ll ans = 1;
	if (x % 2 == 0){
		if (y % 2 == 0)
			ans++;
		x /= 2;
	}
	while (x % 2 == 0)
		x /= 2;

	for (ll i = 3; i * i <= x; i += 2){
		if (x % i == 0){
			if (y % i == 0)
				ans++;
			x /= i;
		}
		while (x % i == 0)
			x /= i;
	}
	if (x > 2 && y % x == 0)
		ans++;

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
     char x;
     cin >> x;
     if (x=='A') cout << 'T' << endl;
     if (x=='C') cout << 'G' << endl;
     if (x=='T') cout << 'A' << endl;
     if (x=='G') cout << 'C' << endl;
     return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef long long int64;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };

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

	vi vec(3);
	rep(i, 3) {
		cin >> vec.at(i);
	}
	if (vec.at(0) == vec.at(1) && vec.at(0) != vec.at(2)) {
		Yes;
	}
	if (vec.at(0) == vec.at(2) && vec.at(0) != vec.at(1)) {
		Yes;
	}
	if (vec.at(1) == vec.at(2) && vec.at(0) != vec.at(1)) {
		Yes;
	}
	No;
}

Measured memory_bytes: 256
#include<stdio.h>
   
int par[100001];
int sib[100001];
int deg[100001];
int n;
   
int depth(int);
int height(int);
   
int main(int argc,char *argv[]) {
  int i,j;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    par[i] = -1;
    sib[i] = -1;
    deg[i] = 0;
  }
  for(i = 0; i < n; ++i) {
    int id, left, right;
    scanf("%d %d %d", &id, &left, &right);
    if(left != -1) {
      par[left] = id;
      sib[left] = right;
      deg[id]++;
    }
    if(right != -1) {
      par[right] = id;
      sib[right] = left;
      deg[id]++;
    }
  }
   
  for(i = 0; i < n; ++i) {
    int dep = depth(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
           i, par[i], sib[i], deg[i], dep, height(i));
    if(dep == 0) {
      printf("root\n");
    } else if(deg[i] == 0) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }
  return 0;
}
  
int depth(int i) {
  if(par[i] == -1) return 0;
  return depth(par[i]) + 1;
}
   
int height(int i) {
  int j, h = 0;;
  
  for(j = 0; j < n; ++j) {
    if(par[j] == i) {
      int tmp = height(j) + 1;
      if(tmp > h) h = tmp;
    }
  }
  return h;
}




Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
    int n;
    cin >> n;
    if(n < 1000)cout << "ABC" << endl;
    else cout << "ABD" << endl;
    return 0;
}

Measured memory_bytes: 256
#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, M;
    cin >> N >> M;
    vector<pll> jobs(N);

    priority_queue<int> que;

    rep(i, N) {
        int a, b;
        cin >> a >> b;
        jobs[i] = MP(a, b);
    }
    sort(All(jobs));

    int cur = 0;
    ll res = 0;
    for(int i = M - 1; i >= 0; i--) {
        while(cur < jobs.size() && jobs[cur].first <= M - i) {
            que.push(jobs[cur].second);
            cur++;
        }
        if(!que.empty()) {
            res += que.top();
            que.pop();
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2428
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		if(a%3==0||b%3==0||(a+b)%3==0)
		{
			System.out.println("Possible");
		}
		else {
			System.out.println("Impossible");
		}
	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
double x = 1.01;
ll p = 100ll, n;
int main(){
	cin >> n;
	int i = 0;
	for (i = 0; p < n; i++) {
		p = p * x;
	}
	cout << i << endl;
	return 0;
}

Measured memory_bytes: 3644
A, B, C = map(int, input().split())
if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
    print(0)
else:
    array = [A, B, C]
    sort_array = sorted(array, reverse=True)
    print(sort_array[1] * sort_array[2])


Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char ans[101];
char n1[101];
char n2[101];
int main(){
	int d;
	int h1,h2,limit;
	for(cin>>d;d>0;d--){
		for(int j=0;j<100;j++)ans[j]='0';
		scanf("%s",n1);
		scanf("%s",n2);
		h1=strlen(n1)-1;
		h2=strlen(n2)-1;
		limit=max(h1,h2);
		int i;
		bool flg=false;
		for( i=0;i<=limit;i++,h1--,h2--){
			flg=false;
			int n1_tmp = 0;
			int n2_tmp = 0;
			if(h1>=0){
				n1_tmp=n1[h1]-'0';
			}
			if(h2>=0){
				n2_tmp=n2[h2]-'0';
			}
			int sum = n1_tmp + n2_tmp;
			if(sum>=10){
				if(i==79){
					i++;
					flg=true;
					break;
				}
				ans[i+1]+=1;
				sum=sum%10;
				flg=true;
			}

			if(ans[i]-'0'+sum > 9){
				if(i==79){
					i++;
					flg=true;
					break;
				}
				ans[i]=ans[i]+(sum-10);
				ans[i+1]+=1;
				flg=true;
			}
			else ans[i]+=sum;
		}
		if(flg){
			i++;
		}
		ans[i]='\0';
		if(i>80)cout<<"overflow"<<endl;
		else{
			for(--i;i>=0;i--){
				if(i>=0)cout<<ans[i];
			}
			cout<<endl;
		}
//		cout<<"size:"<<strlen(ans)<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


k, a, b = LI()

if b - a <= 2 or a - 1 > k:
    print(1 + k)
    exit()

cnt = a - 1
ans = (b - a) * ((k - cnt) // 2) + a

if (k - cnt) % 2:
    ans += 1

print(ans)

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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int a, b, c;
	cin >> a >> b >> c;

	cout << max(0, (c - (a - b)));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct P{
	double x;
	double y;
};

int ccw(P p0, P p1, P p2)
{
	double dx1 = p1.x-p0.x;
	double dy1 = p1.y-p0.y;
	double dx2 = p2.x-p0.x;
	double dy2 = p2.y-p0.y;
	
	if(dx1*dy2 > dy1*dx2){
		return 1;
	} 
	if(dx1*dy2 < dy1*dx2){
		return -1;
	}
	if((dx1*dx2 < 0) || (dy1*dy2 < 0)){
		return -1;
	}
	if((dx1*dx1+dy1*dy1)<(dx2*dx2+dy2*dy2)){
		return 1;
	}
	
	return 0;
}

int intersect(P p1, P p2, P p3, P p4)
{
	return (((ccw(p1, p2, p3)*ccw(p1, p2, p4)) <= 0)
				 &&((ccw(p3, p4, p1)*ccw(p3, p4, p2)) <= 0));
}

int main()
{
	bool f;
	P pr[3], o, g;
	
	while(cin >> pr[0].x >> pr[0].y >> pr[1].x >> pr[1].y >> pr[2].x >> pr[2].y >> o.x >> o.y){
		f = true;
		g.x = g.y = 0;
		for(int i = 0; i < 3; i++){
			g.x += pr[i].x;
			g.y += pr[i].y;
		}
		g.x /= 3.0;
		g.y /= 3.0;
		
		if(intersect(pr[0], pr[1], o, g) > 0){
			f = false;
		}
		if(f && intersect(pr[0], pr[2], o, g) > 0){
			f = false;
		}
		if(f && intersect(pr[2], pr[1], o, g) > 0){
			f = false;
		}
		if(f){
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
 
using namespace std;
 
signed main()
{
    fast;
    int n;
    cin>>n;

    string s;
    cin>>s;

    if ( n % 2 != 0 )
    {
        cout<<"No"<<endl;
    }
    else
    {
        int found = 0;
        for ( int i = 0 ; i < s.length()/2 ; i++ )
        {
            if ( s[i] != s[i+n/2] )
            {
                found = 1;
                break;
            }
        }

        if ( found == 0 )
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
S = input()
alpha = [chr(ord('a') + i) for i in range(26)]
n=0
c=-1
while c == -1 and n < 26:
  if not alpha[n] in S:
    c = n
    break
  n+=1
if c == -1:
  print('None')
else:
  print(alpha[n])

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

const long long infl = 1LL << 60;


int z(int x)
{
    if(x < 0) return -x;
    else return  x;
}

long long dp[100005];//dp[i]は足場iへのコストの最小値

int main()
{
    int N;
    int K;
    int h[100005];
    cin >> N >> K;
    for(int i = 1; i <= N; i++) cin >> h[i];
    dp[0] = 0;
    dp[1] = 0;
    for(int i = 2; i <= N; i++) dp[i] = infl;
    for(int i = 1; i < N; i++)
    {
        for(int k = 1;k <= K && i + k <= N; k++)
        {
          dp[i + k] = min(dp[i + k],dp[i] + z(h[i] - h[i + k])); 
        }
    }
    cout << dp[N];
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

int a[100005];
int dp[100005];

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


    dp[1] = abs(a[1]-a[0]);
    dp[0] = 0;

    for(int i=2;i<n;i++)
        dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
    
    cout << dp[n-1] << endl;




}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))

ll binPow(ll a, ll q,ll k)
{
    ll MOD = k;
     a %= MOD;
    if (q == 0) return 1;
    return ((q % 2 == 1 ? a : 1) * binPow(a * a, q / 2,k))%MOD ;
}

int main()
{

    ll i,j,k,l,m,n,q,p1,p2,q1,q2,x,ans,l1,l2,l3,l4,l5,l6,l7,l8;

string s;
cin >> n;
cin >> s;

ll L[n+10];

memset(L,0,sizeof L);
s = "*" + s;
for(i=1;i<=n;i++)
{
    if(s[i] == 'R')
    {
        L[i]++;
    }
    L[i] += L[i-1];
}
ans = 0;
l1 = 0;
//for(i=1;i<=n;i++)cout<<L[i]<<" ";

for(i=n;i>=1;i--)
{
 if(L[i]+ans == i)break;
 if(s[i] == 'R')
 {

     ans++;
     l1++;
 }


}

cout << l1 << endl;

}


Measured memory_bytes: 5300
N, M, X = list(map(int, input().split()))
A = [0]*N

for i in range(N):
    A[i] = list(map(int, input().split()))

min_sump = -1
for i in range(2**(N+1)):
    sump = 0
    sume = [0]*M
    for j in range(N):
        ns = "0" + str(N) +"b"
        bi = format(i,ns)
        if bi[-1-j] == "1":
            sump += A[j][0]
            sume = list(map(sum, zip(sume, A[j][1:])))
    if all([i >= X for i in sume]):
        if min_sump == -1:
            min_sump = sump
        else:
            min_sump = min(min_sump,sump)

print(min_sump)

Measured memory_bytes: 9108
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	char c;
	cin >> c;
	
	if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
	{
		cout << "vowel" << endl;
		
	}
	else
	{
		 cout << "consonant" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  
  int N;
  cin >> N;
  double sum = 0;
  
  for(int i = 0 ; i < N ; i++){
    
    double a;
    cin >> a;
    
    sum += 1/a;
    
    if(i == N - 1){
      cout << fixed << setprecision(10);
      cout << 1/sum << endl;
    }
  }
}

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

int main() {
  int n;
  cin>>n;
  int x[n];
  for(int i=0;i<n;i++) cin>>x[i];
  sort(x,x+n);
  int sum=-1;
  for(int i=x[0];i<=x[n-1];i++){
    int temp=0;
    for(int j=0;j<n;j++){
      temp+=(x[j]-i)*(x[j]-i);
    }
    if(sum<0 || temp<sum) sum=temp;
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3

import sys

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

bound = 10**9 + 7
def comb(n, k):
    ans = 1
    upto = min(k, n - k)
    for i in range(0, upto):
        ans *= n - i % bound
    for i in range(0, upto):
        ans //= upto - i
    return ans

def solve(n, k, i):
    red = n - k
    blue = k
    nr_how_sep_red = cmb(red + 1, i, bound)
    nr_how_put_blu = cmb(blue - 1, i - 1, bound)
    return nr_how_sep_red * nr_how_put_blu % bound

def main():
    inputs = [int(s) for s in sys.stdin.readline().rstrip().split(" ")]
    n, k = inputs
    for i in range(0, k):
        print(solve(n, k, i + 1))

main()

Measured memory_bytes: 4584
#include <iostream>
    #include <vector>
    #include <algorithm>
     
    using namespace std;
     
    long long int f(long long n) {
        long long res = 0;
        while (n > 0) {
            res += n % 10;
            n /= 10;
        }
        return res;
    }
     
    double g(long long n) {
        return (double) (n) / f(n);
    }
     
    int main() {
        vector<long long> res;
        long long base = 1;
     
        for (int i = 0; i < 15; ++i) {
            for (int j = 1; j < 150; ++j) {
                res.push_back(base * (j + 1) - 1);
            }
            base *= 10;
        }
        sort(res.begin(), res.end());
        res.erase(unique(res.begin(), res.end()), res.end());
     
        for (long long i = 0; i < res.size(); ++i) {
            for (long long j = i + 1; j < res.size(); ++j) {
                if (g(res[i]) > g(res[j])) {
                    res.erase(res.begin() + i--);
                    break;
                }
            }
        }
     
        long long K;
        cin >> K;
        for (long long i = 0; i < K; ++i) {
            cout << res[i] << endl;
        }
    }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())
#define AsceSort(a) sort(a.begin(),a.end())

using namespace std;
typedef long long ll;

int main(void) {
	int n,T,mina=1005;
	bool ans = true;
	int c[1005], t[1005];
	cin >> n>>T;
	REP(i, n) {
		cin >> c[i] >> t[i];
		if (T >= t[i]) {
			mina = min(mina, c[i]);
			ans = false;
		}

	}
	if (ans) cout << "TLE" << endl;
	else cout << mina << endl;
	return 0;
}



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

#define all(x) (x).begin(),(x).end()
#define init() \
  ios::sync_with_stdio(false); \
  cin.tie(0)

#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

#ifdef LOCAL

template<typename T>
void show(vector<T>& v) {
    cout << '[';
    for (const T& e : v) {
        cout << e << ',';
    }
    cout << ']' << endl;
}

#endif

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
  return a == 0 ? b
    : b == 0 ? a
    : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

template <long long MAX>
class CombinationCalculator {
  long long mod_;
  long long fac[MAX];
  long long finv[MAX];
  long long inv[MAX];

public:
  CombinationCalculator(long long mi = MOD): fac(), finv(), inv() {
    mod_ = mi;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i - 1] * i % mod_;
      inv[i] = mod_ - inv[mod_ % i] * (mod_ / i) % mod_;
      finv[i] = finv[i - 1] * inv[i] % mod_;
    }
  }

  long long c(long long n, long long k) const {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod_) % mod_;
  }
};

template <long long MAX = 210000>
using CC = CombinationCalculator<MAX>;

template<typename T>
T modpow(T a, T n, T mod = MOD) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template<typename T>
T modinv(T a, T m = MOD) {
    T b = m, u = 1, v = 0;
    while (b) {
        T t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

template<typename T>
vector<T> read_n(const size_t n) {
    T dummy;
    vector<T> v(n);
    for (size_t i = 0; i < n; i++) {
        cin >> dummy;
        v[i] = dummy;
    }
    return v;
}

template<typename T>
vector<T> read_n() {
    size_t n;
    cin >> n;
    return read_n<T>(n);
}

int main() {
  init();

  int n;
  cin >> n;
  const int m = 50000;

  for (int i = 0; i <= m; i++) {
      if ((int)(i * 1.08) == n) {
          cout << i << endl;
          return 0;
      }
  }

  cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

bool operater(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}

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

	vector<pair<int, int>> v(N);
	for (int i = 0; i < N; i++) {
		pair<int, int> p;
		cin >> p.first >> p.second;
		v[i] = p;
	}
	sort(v.begin(), v.end(), operater);

	//for (int i = 0; i < N; i++) {
	//	cout << v[i].first << ' ' << v[i].second << endl;
	//}

	int64_t s = 0;
	bool f = true;

	for (int i = 0; i < N; i++) {
		s += (int64_t)v[i].first;
		if (s > v[i].second) {
			f = false;
			break;
		}
	}

	cout << (f ? "Yes" : "No") << endl;
}

Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t N;
  cin>>N;
  int64_t a=N;
  for(int64_t i=1;i*i<=N;i++){
  if(N%i==0)
    a=N/i;
  }string b=to_string(a);
  int ans=b.size();
  cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

string s;
int a[4];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> s;
	FOR(i, 4) a[i] = (int)(s.substr(i,1)[0]-'0');
	FOR(i, 1<<3) {
		int sum = a[0];
		bool flag[3];
		fill(flag, flag+3, false);
		FOR(j, 3) {
			if (i>>j & 1) {
				sum += a[j+1];
				flag[j] = true;
			}
			else sum -= a[j+1];
		}
		if (sum==7) {
			cout << a[0];
			FOR(j, 3) {
				if (flag[j]) cout << "+" << a[j+1];
				else cout << "-" << a[j+1];
			}
			cout << "=7" << endl;
			return 0;
		}
	}
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

#include <bits/stdc++.h>
#define rep(i,a,n) for(ll i = a;i < n;i++)
typedef long long ll;
using namespace std;

int main(){
    
    ll n,k;
    cin >> n >> k;
    ll a[n] = {};
    rep(i,0,n) cin >> a[i];
    ll memo = min(k, 50LL);
    
    rep(i,0,memo){
        ll b[n] = {};
        rep(j,0,n){
            ll left,right;
            left = max(0LL,j-a[j]);
            right = min(n-1,j+a[j]);
            b[left]++;
            if(right+1 < n) b[right+1]--; 
        }

        rep(j,0,n){
            if(j > 0) b[j] += b[j-1];
            a[j] = b[j];
        }
    }

    rep(i,0,n){
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 6660
#include<stdio.h>

int main(){
	int N, s[3], i, n=0;
	
	scanf("%d", &N);

	s[2] = N%10;
	s[1] = (N%100 - s[2]) / 10;
	s[0] = (N - s[1]*10 - s[2]) / 100;
	for(i=0;i<3;i++){
		if(s[i]==1){n++;}
	}
	
	printf("%d\n", n);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
#include<cmath>
#include<string>
#define pb push_back
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
 
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
 
// look for  all edge cases
//search for a pattern

int n;
const static int mod = (int)1e9 + 7;
int dp[2002];

int calc(int now){
	if(now == n){
		return 1;
	}
	if(now > n){
		return 0;
	}
	
	//if(now < 3){
		//return 0;
	//}
	
	if(dp[now] != -1){
		return dp[now];
	}
	
	int ways = 0;
	
	
	for(int i = 3; i <= n ; i++){
		ways = (ways + calc(i + now))%mod;
	}
	
	dp[now] = ways;
	
	return ways;
	
}

signed main() {    
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
		
	cin >> n;
	
	for(int i =0 ;i  < 2002; i++){
		dp[i] = -1;
 	}
	
	
	int ans = calc(0);
	 
	cout<<ans; 
	 
	return 0;
}


Measured memory_bytes: 3672
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// END NO SAD

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

void solve() {
  int n;
  string s;
  cin >> n >> s;
  if(n%2) {
    cout << "No\n";
    return;
  }
  for(int i = 0; i < n/2; i++) {
    if(s[i] != s[i+n/2]) {
      cout << "No\n";
      return;
    }
  }
  cout << "Yes\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


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

const int MAX=510000;
const int MOD=1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

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

long long COM(int n,int k) {
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
    COMinit();
    long long  h,w,a,b,u,d,ans=0;
    scanf("%lld %lld %lld %lld",&h,&w,&a,&b);

    for (long long i=b+1;i<=w;i++) {
        u=COM(h-a+i-2,i-1)%MOD;
        d=COM(a+(w-i)-1,a-1)%MOD;
        ans+=(u*d)%MOD;
    }
    printf("%lld\n",ans%MOD);
    return 0;
}


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

template<class INT>
std::vector<INT> get_primes(INT n){
    std::vector<INT> lp(n + 1), P;
    for (INT i = 2; i <= n; i++){
        if (lp[i] == 0){
            lp[i] = i;
            P.push_back(i);
        }
        for (INT j = 0; j <= P.size() and P[j] <= lp[i] and i * P[j] <= n; j++)
            lp[i * P[j]] = P[j];
    }

    return P;
}

int main(){
    int n;
    cin >> n;
    auto P = get_primes(55555);
    vector<int> A;
    for (const auto &p: P){
        if (p % 5 == 1)
            A.push_back(p);
    }
    copy(A.begin(), A.begin() + n, ostream_iterator<int>(cout, " "));
    cout << endl;
}

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


using namespace std;

#define endl '\n'
#define PB push_back
#define MP make_pair
#define LL long long
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

typedef long long ll;

bool file=0,rt=1;
clock_t tStart ;
void FAST_IO();
////////////////////////

int main() {

    //FAST_IO();
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << setprecision(5);
    cout << fixed;

    char c;
    cin >> c;

    if(c == 'A') {

        cout << 'T' << endl;
    }
    else if(c == 'T') {

        cout << 'A' << endl;
    }
    else if(c == 'C') {

        cout << 'G' << endl;
    }
    else if(c == 'G') {

        cout << 'C' << endl;
    }


    return 0;
}

void FAST_IO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //cout.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(2);
    if(rt && file){ tStart = clock(); }
    if(file){
    #ifndef _offline
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    }
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

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

	map<int, int> m;

	int r = 0;
	int ans = inf;
	for (int l = 0; l < n; l++)
	{
		while (r < n && m.size() < k)
		{
			if (a.at(r) <= k)
			{
				m[a.at(r)]++;
			}
			r++;
		}

		if (m.size() == k)
		{
			ans = min(ans, r - l);
		}

		if (l == r)
		{
			r++;
		}
		else
		{
			if (a.at(l) <= k)
			{
				m[a.at(l)]--;
				if (m[a.at(l)] == 0)
				{
					m.erase(a.at(l));
				}
			}
		}
	}

	if (ans == (int)inf)
	{
		ans = 0;
	}

	cout << ans << endl;
}


Measured memory_bytes: 7816
/*---> 07 March 2020 <--- > 02:20:29 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	int n;
	cin>>n;
	cout<<(n+1)/2<<"\n";
return 0;
}

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

int main(){
    int n, x;
    int i = 0;int j = 0;int k = 0;
    while(1){
        cin >> n >> x;
        int count = 0;
        if(n == 0 && x == 0){
            break;
        }
        for(i = 1; i <= n; ++i){
            for(j = i + 1; j <= n; ++j){
                for(k = j + 1; k <= n; ++k){
                    if(i + j + k == x){
                        count++;
                    }
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

const int N=200000;

int main(void){
	vector<bool> isprime(N+1);
	for(int i=0;i<isprime.size();i++) isprime[i]=true;
	int upto = (int)sqrt(isprime.size());
	isprime[0]=isprime[1]=false;
	for(int i=2;i<=upto;++i){
		if(isprime[i]){//消されてなければその倍数を消す
			for(int j=2;i*j<isprime.size();++j) isprime[i*j] = false;
		}
	}
  
	int n,p;
	while(cin>>n>>p,!(n==-1&&p==-1)){
    vector<int> tmp,ans;
    for(int i=n+1,count=0;count<100;++i){
      if(isprime[i]){
     	 tmp.push_back(i);
     	 ++count;
      }
    }
    for(int i=0;i<100;++i){
      for(int j=i;j<100;++j){
        ans.push_back(tmp[i]+tmp[j]);
      }
    }
    sort(ans.begin(),ans.end());
		cout<<ans[p-1]<<endl;
	}
  return 0;
}

Measured memory_bytes: 1304
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=2005;
const int MOD=1000000007;

int n,k,f[N][N][3];

void updata(int &x,int y)
{
    x+=y;x-=x>=MOD?MOD:0;
}

int main()
{
    scanf("%d%d",&n,&k);
    f[n+1][0][2]=1;
    for (int i=n+1;i>1;i--)
    {
        for (int j=n;j>=0;j--) updata(f[i][j][1],f[i][j+1][1]);
        for (int j=0;j<=n;j++)
            for (int t=1;t<=2;t++)
            {
                updata(f[i-1][j+1][2],f[i][j][t]);
                updata(f[i-1][j][1],f[i][j][t]);
            }
    }
    int ans=f[1][n-k][1];
    for (int j=1;j<=n-k-1;j++) updata(ans,ans);
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 47360
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;

using namespace std;

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

    t += s[0];
    int i = 1;

    while(i < s.size()) {
        if(t.back() != s[i]) {
            t += s[i] ;
            i++;
        } else {
            i++;
        }
    }
    cout << t.size() - 1 << endl;
    return 0;
}


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

using namespace std;

typedef long long LL;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define dump(x)  cerr << #x << " = " << (x) << endl;

struct UnionFind {
  vector<int> par;

  UnionFind(int N) : par(N) {
    REP(i, N) { par[i] = i; }
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> p(N), x(M), y(M);
  REP(i, N) { cin >> p[i]; p[i]--; }

  UnionFind tree(N);

  REP(i, M) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    tree.unite(x, y);
  }

  int res = 0;

  REP(i, N) {
    if (tree.same(p[i], i)) {
      res++;
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <cmath>
#include <chrono>
#include <random>
#include <ctime>
#include <algorithm>
#include <iosfwd>
#include <iostream>
#include <list>
#include <ostream>
#include <streambuf>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fori(i, n) for(ll i = 0; i < (n); ++i)
#define forI(i, n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define ff first
#define ss second

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

#define pt pair<ll, ll>
#define x first
#define y second

pll operator+ (pll a, pll b){ return {a.x + b.x, a.y + b.y}; }

ll rand0m() {
    return (ull(rand()) << 15ull | ull(rand()));
}                   //[0 ... n)
ll rand0m(ll x) {
    return rand0m() % x;
}               //[0 ... n)
ll rand0m(ll minn, ll maxx) {
    return rand0m(maxx - minn + 1) + minn;
}   //[minn ... maxx]

const ll MAXN = 1e5 + 1;
const ll mod = 1e9 + 7;
const ll INF = 2e9 + 1000;

ll n, m;
ll w[101];
ll v[101];
ll bp[101][MAXN];

void solve() {
    ll W;
    cin >> n >> W;
    forI(i, n) cin >> w[i] >> v[i];
    forI(i, n){
        fori(j, W + 1){
            bp[i][j] = bp[i - 1][j];
            if(j - w[i] >= 0) bp[i][j] = max(bp[i][j], bp[i - 1][j - w[i]] + v[i]);
        }
    }
    ll ans = 0;
    fori(i, W + 1) ans = max(ans, bp[n][i]);
    cout << ans;
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    solve();
}

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

typedef long long ll;
vector<ll> v;


ll count_cost(int x) {
    int cost = 0;
    for(int i = 0; i < v.size(); i++) {
        cost += (v[i] - 1)/x;
    }

    return cost;
}


int main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n = 0, k = 0;
    cin >> n >> k;
    v.clear();
    v.assign(n, 0);


    ll mx = -1;
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        mx = max(mx, v[i]);
    }

    int low = 0;
    int high = mx;

    while(high - low > 1) {
        int mid = (low + high)/2;

        int cost = count_cost(mid);

        
        if(cost <= k) {
            high = mid;
        }
        else {
            low = mid;
        }
    }

    cout << high << endl;








    


    return 0;
}

Measured memory_bytes: 4696