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

//printVector(配列, 区切り文字)
template <typename T>
void printVector(vector<T> v, string delimiter) {
  for (int i=0; i<v.size(); i++) {
    if (i>0) cout << delimiter;
    cout << v[i];
  }
  cout << endl;
}

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

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

  int minj;
  int cnt = 0;
  for (int i=0; i<n; i++) {
    minj = i;
    for (int j=i; j<n; j++) {
      if (a[j] < a[minj]) {
        minj = j;
      }
    }
    if (minj != i) {
      swap(a[i], a[minj]);
      cnt++;
    }
  }

  printVector(a, " ");
  cout << cnt << endl;
}



Measured memory_bytes: 3168
N,M = map(int,input().split())

pattern = ["."] * N
for i in range(M):
  s,c = input().split()
  s = int(s)
  if pattern[s - 1] not in (".",c):
    print(-1)
    exit(0)
  pattern[s - 1] = c
  
pattern = "".join(pattern)

import re
for i in range(1001):
  res = re.match(pattern, str(i))
  if res:
    print(i)
    break
else:
  print(-1)

Measured memory_bytes: 9932
N,K=map(int,input().split())
X=list(map(int,input().split()))
p=True
for i in range(N):
    if X[i]<0:
        continue
    elif X[i]==0:
        K-=1
        if i<K:
            mX=[0]+[-x for x in X[:i]][::-1]
        else:
            mX=[0]+[-x for x in X[i-K:i]][::-1]
        pX=[0]+X[i+1:i+1+K]
        p=False
        break
    else:
        if i<K:
            mX=[0]+[-x for x in X[:i]][::-1]
        else:
            mX=[0]+[-x for x in X[i-K:i]][::-1]
        pX=[0]+X[i:i+K]
        p=False
        break
if p:
    mX=[0]+[-x for x in X[::-1]]
    pX=[0]
ans=10**9
l=K-(len(pX)-1)
n=len(mX)
for i in range(len(pX)-1,-1,-1):
    if l<n:
        ans=min(ans,pX[i]+mX[l]*2,pX[i]*2+mX[l])
    else:
        break
    l+=1
print(ans)

Measured memory_bytes: 20088
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

ll n, m;
ll seq[100];

inline ll Arith(ll v) {
  ll N = n / v;
  return N * (N - 1) / 2 * v;
}

ll calc1(ll v, int depth) {
  if (depth == m || v > n) { return 0; }
  ll nv = v / __gcd(v, seq[depth]) * seq[depth];
  ll ret = Arith(nv);
  ret -= calc1(nv, depth + 1);
  ret += calc1(v, depth + 1);
  return ret;
}

ll calc2(ll v, int depth) {
  if (depth == m || v > n) { return 0; }
  ll nv = v / __gcd(v, seq[depth]) * seq[depth];
  ll ret = n / nv;
  ret -= calc2(nv, depth + 1);
  ret += calc2(v, depth + 1);
  return ret;
}

int main() {
  while (scanf("%lld %lld", &n, &m), n|m) {
    REP(i, m) {
      scanf("%lld", &seq[i]);
    }
    sort(seq, seq + m);
    if (seq[0] == 1) {
      printf("%.8f\n", 0.0);
      continue;
    }
    ll ans = Arith(1) - calc1(1, 0);
    ll cnt = n - calc2(1, 0);
    //cout << ans << " " << cnt << endl;
    printf("%.8f\n", (double)ans / cnt);
  }
}

Measured memory_bytes: 916
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

// int MOD = 998244353;
int MOD = 1000000007;

//----------------------------------------------------------------
signed main(){

	ll n;
	cin >> n;
	ll m = (1LL<<n);
	vll s(m);
	rep(i,m)cin >> s[i];
	SORT(s);
	ll maxi = s[m-1];

	multiset<ll> parent,child;
	parent.insert(-1*maxi);
	rep(i,m-1)child.insert(-1*s[i]);

	rep(i,n){
		vll tmp;
		for(auto x:parent){
			auto itr = child.lower_bound(x+1);
			if(itr == child.end()){
				cout << "No" << endl;
				return 0;
			}else{
				ll y = *itr;
				tmp.pb(y);
				child.erase(itr);
			}
		}
		for(auto x:tmp)parent.insert(x);
	}
	cout << "Yes" << endl;




	return 0;
}

//----------------------------------------------------------------

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://abc140.contest.atcoder.jp/tasks/abc140_a

Measured memory_bytes: 15616
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];
    
    rep(i,0,k){
        vector<int> d(n+1, 0);//nが境界にはならないから
        rep(j,0,n){
            ll l=max(0, j-a[j]);
            ll r=min(n, j+a[j]+1);
            d[l]++; d[r]--;
        }
        rep(j,1,n) d[j]+=d[j-1];
        d.pop_back();
        swap(a, d);
        if(a==d) break;
    }
    rep(i, 0, n) cout << a[i] << " ";

    return 0;
}

Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
#define A first
#define B second
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define Itype(a) typeof(a.begin()) 
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(Itype(t) i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
const int MOD = 1000000007;

bool ok(char c) {
    return c == 'A' || c == 'C' || c == 'T' || c == 'G';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = SZ(s);
    int ans = 0;
    for(int i = 1;i <= n;i++) {
        for(int j = 0;j < n;j++) {
            if(i + j > n) break;
            bool flg = true;
            for(int k = j;k < i + j;k++) {
                if(!ok(s[k])) flg = false;
            }
            if(flg) ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

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

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}


int gcd(int a,int b){
  if(a%b)return gcd(b,a%b);
  else return b;
}
int main(){
  string s;cin>>s;
  int re = 100000;
  for(int i = 0; s.size()-2 > i; i++){
    int z = (s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    re = min(re,abs(753-z));
  }
  cout << re << endl;
  
}


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

int main() {
	int N;
	long long INF = 1000000000000000000;
	cin >> N;
	vector<long long> A(N);
	vector<pair<long long, int> > VP(N);
	for (int i = 0; i < N; i++) cin >> A[i], VP[i] = { A[i], i };
	sort(VP.begin(), VP.end(), greater<pair<long long, int> >());
	vector<vector<long long> > DP(N + 1, vector<long long>(N + 1, -INF));
	DP[0][N] = 0;
	for (int i = 0; i < N; i++) {
		for (int L = 0; L <= i; L++) {
			int R = N - i + L;
			DP[L + 1][R] = max(DP[L + 1][R], DP[L][R] + VP[i].first * abs(VP[i].second - L));
			DP[L][R - 1] = max(DP[L][R - 1], DP[L][R] + VP[i].first * abs(VP[i].second - (R - 1)));
		}
	}
	long long ANS = -INF;
	for (int i = 0; i <= N; i++) ANS = max(ANS, DP[i][i]);
	cout << ANS << endl;
}

Measured memory_bytes: 34676
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    double h,w,n; cin >> h >> w >> n;
    cout << ceil( (n  / max(h,w)) );
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int keta(int n){
  int sum=0;
  while(n>0){
    sum=sum+n%10;
    n=n/10;
  }
  return sum;
}
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int i,sum=0;
  for(i=1;i<=n;i++){
    if(keta(i)>=a && keta(i)<=b){
      sum+=i;
    }
  }
  cout << sum;
}
  

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

int n,m,flag;
char a[10];

int main()
{
    scanf("%s",a);
    for(int i=1;i<strlen(a);i++)
    	if(a[i]==a[i-1]){
    		flag=1;
    		break;
		}
	if(flag==0)printf("Good");
	else printf("Bad");
    return 0;
}

Measured memory_bytes: 256
#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>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n+1,0),sum(n+1,0);
	FOR(i,1,n+1)cin>>a[i];
	ll dpf[n+1][n+1]={},dps[n+1][n+1]={};
	FOR(i,1,n+1)dpf[i][i]=a[i];
	FOR(i,1,n+1)sum[i]=sum[i-1]+a[i];
	FOR(i,1,n+1){
		for(int j=0;i+j<=n;j++){
			dpf[j][i+j]=max(dps[j+1][i+j]+a[j],dps[j][i+j-1]+a[i+j]);
			dps[j][i+j] = sum[i+j]-sum[j-1] - dpf[j][i+j];
		}
	}
	cout << dpf[1][n]-dps[1][n] << endl;
}


Measured memory_bytes: 141056
prime = [True for i in range(160001)]
prime[0] = prime[1] = False
for i in range(2, 401):
    if prime[i]:
        for j in range(2, 160000 // i + 1):
            prime[i * j] = False

while True:
    n, p = map(int, input().split())
    if n == p == -1:
        break

    pli = list()
    for i in range(p):
        while True:
            n += 1
            if prime[n]:
                pli.append(n)
                break

    numli = list()
    for x in range(p):
        for y in range(x, p):
            numli.append(pli[x] + pli[y])

    numli.sort()
    print(numli[p - 1])


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

using ll = long long;

int main() {
    ll n;
    while(cin >> n, n) {
        ll keta = 2, cnt = 0;
        while(cnt + 9 * 9 * ((1LL << (keta - 1)) - 1) < n) {
            cnt += 9 * 9 * ((1LL << (keta - 1)) - 1);
            keta += 1;
        }
        cnt = n - cnt;

        string ans;
        function<void(int, int, int)> solve = [&] (int d, int a, int b) {
            if(d == keta) return;
            if(a == -1) {
                for(a = 1; a <= 9; ++a) {
                    if(cnt > 9 * ((1LL << (keta - 1)) - 1)) {
                        cnt -= 9 * ((1LL << (keta - 1)) - 1);
                        continue;
                    }
                    break;
                }
                ans += '0' + a;
                solve(d + 1, a, b);
            } else if(b == -1) {
                for(b = 0; b <= 9; ++b) {
                    if(a != b) {
                        if(cnt > (1LL << (keta - d - 1))) {
                            cnt -= 1LL << (keta - d - 1);
                            continue;
                        }
                        break;
                    } else {
                        if(cnt > 9 * ((1LL << (keta - d - 1)) - 1)) {
                            cnt -= 9 * ((1LL << (keta - d - 1)) - 1);
                            continue;
                        }
                        break;
                    }
                }
                ans += '0' + b;
                if(a == b) solve(d + 1, a, -1);
                else       solve(d + 1, a, b);
            } else {
                const int ma = max(a, b), mi = min(a, b);
                if(cnt > (1LL << (keta - d - 1))) {
                    cnt -= 1LL << (keta - d - 1);
                    ans += '0' + ma;
                } else {
                    ans += '0' + mi;
                }
                solve(d + 1, a, b);
            }
        };
        solve(0, -1, -1);

        cout << ans << endl;
    }
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);
long long int combination(long long int,long long int);
long long int arith_sum1(long long int,long long int,long long int);
long long int arith_sum2(long long int,long long int,long long int);
long long int series_sum(long long int);

int main(){
    int n;
    cin>>n;
    ll sum=0;
    vector<ll> vec;
    ll i=1;
    for(i=1;i<=n;i++){
        sum+=i;
        if(sum>=n)break;
    }
    int max=i;
    int d;
    rep(j,max){
        if(sum-j==n){
            d=j;
            //cerr<<d<<endl;
        }
    }
    for(int l=1;l<=max;l++){
        if(l!=d)cout<<l<<endl;
    }
}

Measured memory_bytes: 3596
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=200111;
const int mod=998244353;

int n,p[maxn];
char s[maxn],t[maxn];

map<string,int> fir;
bool check(int q)
{
	int per=__gcd(n,q);
	for(int i=1;i<=per;i++)
	{
		int cur=i,curv=s[i]-'0';
		for(int j=1;j<=n/per;j++)
		{
			t[cur]=curv+'0';
			cur+=q;if(cur>n)cur-=n;
			if(cur<=q)curv^=1;
		}
	}
	for(int i=1;i<=n;i++)if(s[i]!=t[i])return (s[i]>t[i]);
	return true;
}

int calc(int per)
{
	int ret=check(per*2);
	for(int i=1;i<=per;i++)if(s[i]=='1')
	{
		ret+=p[per-i];
		if(ret>=mod)ret-=mod;
	}
	return ret;
}

int main()
{
	p[0]=1;for(int i=1;i<maxn;i++)p[i]=2*p[i-1]%mod;
	scanf("%d",&n);scanf("%s",s+1);
	vector<int> vs,val;for(int i=1;i<=n;i++)if(n%i==0&&i%2==1)vs.pb(n/i);
	reverse(vs.begin(),vs.end());
	
	LL ans=0;
	for(int i=0;i<(int)vs.size();i++)
	{
		val.pb(calc(vs[i]));
		for(int j=0;j<i;j++)if(vs[i]%vs[j]==0)
		{
			val[i]-=val[j];
			if(val[i]<0)val[i]+=mod;
		}
		ans=(ans+(LL)vs[i]*2*val[i])%mod;
	}
	printendl(ans);
	return 0;
}

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

///////////////////////////////////////////
const long long int INF = 1000000000000000000LL;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
///////////////////////////////////////////

int main(){
    string s;
    cin>>s;
    bool a=false,b=false,c=true,key2=false;
    rep(i,s.size()){
        if(s[i]>='A' && s[i]<='Z'){
            if(i==0 && s[i]=='A'){
                a = true;
            }else if((i>1 && i<=s.size()-2) && s[i]=='C' && !key2){
                key2 = true;
                b = true;
            }else if((key2 || i<=1)&& s[i]=='C'){
                b = false;
                key2 = true;
            }else{
                c = false;
            }
        }else{

        }
    }
    if(a&&b&&c){
        cout<<"AC"<<endl;
    }else{
        cout<<"WA"<<endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60; // 十分大きい値とする

int main() {
    // 入力
    int N; cin >> N;
    vector<long long> h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    vector<long long> dp(N+1, INF);

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 1; i < N; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    // 答え
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
const long double eps = 1e-12;
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
	long long n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	string b = s;
	reverse(b.begin(), b.end());
	s += b;
	sort(b.begin(), b.end());
	vector<string> inputs;
	k--;
	k = min(k, 15LL);
	for (int i = 0; i < n+1; ++i) {
		string c;
		for (int q = 0; q < n; ++q) {
			c.push_back(s[i + q]);
		}
		if (k != 0 && c.back() != b[0]) continue;
		if (k != 0) {
			for (int t = 0; t < k - 1; ++t) {
				for (int j = n - 1; j >= 0; --j) {
					if (c[j] != b[0]) {
						//start titenn
						string d;
						for (int t = 0; t < n; ++t) {
							d.push_back(c[t]);
						}
						for (int t = 0; t < n - 1 - j; ++t) {
							d.push_back(b[0]);
						}
						reverse(d.begin(), d.end());
						while (d.size() != n) {
							d.pop_back();
						}
						reverse(d.begin(), d.end());
						c = d;
						break;
					}
				}
			}
		}
		if (k != 0) {
			for (int j = n - 1; j >= 0; --j) {
				if (c[j] != b[0]) {
					//start titenn
					string d;
					for (int q = j + 1; q < n; ++q) {
						d.push_back(c[q]);
					}
					for (int q = n - 1; q >= 0 && d.size() != n; --q) {
						d.push_back(c[q]);
					}
					c = d;
					break;
				}
			}
		}
		inputs.push_back(c);
	}
	sort(inputs.begin(), inputs.end());
	cout << inputs[0] << endl;
}

Measured memory_bytes: 24064
#include <iostream>
using namespace std;
int main(void){
    int i,s[10];
    for(i=1;i<=10;i++){
        cin>>s[i];
    }
    cout<<s[1]+s[2]+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10]<<endl;
}



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


int main(){
    long n, k, r, s, p;
    long res = 0;
    string t;

    cin >> n >> k >> r >> s >> p;
    cin >> t;

    rep(i,n) {
        if(t[i]=='r') t[i] = 'P';
        else if(t[i]=='s') t[i] = 'R';
        else if(t[i]=='p') t[i] = 'S';

        if(i>=k && t[i]==t[i-k]) t[i] = ' ';
    }

    rep(i, n) {
        if(t[i]=='P') res += p;
        else if(t[i]=='S') res += s;
        else if(t[i]=='R') res += r;
    }
    
    cout << res << endl;

    return 0;
}

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

int main() {
string S;
  cin >> S;
  int MMYY=0;
  int YYMM=0;
if (S.at(0)=='0'){
  if (S.at(1)!='0'){
    MMYY++;
  }
}
  if(S.at(0)=='1'){
    if (S.at(1)=='0'){
      MMYY++;
    }
    else if (S.at(1)=='1'){
      MMYY++;
    }
    else if (S.at(1)=='2'){
      MMYY++;
    }
  }
     
     
     if (S.at(2)=='0'){
  if (S.at(3)!='0'){
    YYMM++;
  }
}
  if(S.at(2)=='1'){
    if (S.at(3)=='0'){
      YYMM++;
    }
    else if (S.at(3)=='1'){
      YYMM++;
    }
    else if (S.at(3)=='2'){
      YYMM++;
    }
  }
     if ( MMYY==0 && YYMM ==0){
       cout << "NA" << endl;
     }
     if ( MMYY==1 && YYMM ==0){
       cout << "MMYY" << endl;
     }
          if ( MMYY==0 && YYMM ==1){
       cout << "YYMM" << endl;
     }
          if ( MMYY==1 && YYMM ==1){
       cout << "AMBIGUOUS" << endl;
     }
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

#define MAX(A, B) (A) > (B) ? (A) : (B)

using namespace std;

int dp[1001][1001];
int w[1000], v[1000];

int main() {
	int N, W;
	int c = 0;
	memset(dp, 0, sizeof dp);
	while (cin >> W, W) {
		cin >> N;
		for (int i = 0; i < N; i++) {
			scanf("%d,%d", &v[i], &w[i]);
		}
		for (int i = 0; i < N; i++) {
			for (int j = W; j >= 0; j--) {
				if (j >= w[i])
					dp[i+1][j] = MAX(dp[i][j], dp[i][j-w[i]]+v[i]);
				else
					dp[i+1][j] = dp[i][j];
			}
		}
		while (dp[N][W] == dp[N][W - 1]) W--;
		cout << "Case " << ++c << ':' << endl;
		cout << dp[N][W] << endl << W << endl;
	}

	return 0;
}

Measured memory_bytes: 5172
while True:
    H,W = map(int,input().split())
    if H == 0:
        break
    for i in range(H):
        S = ""
        for j in range(W):
            if (i+j ) % 2 == 0:
                S += "#"
            else:
                S += "."
        print(S)
    print()    
        
        
                
        


Measured memory_bytes: 5612
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
ll i,j,k;
ll n,m;
ll a,b,c;
double v[55];
double sum=0;
ll dp[55][55];
ll ans=0;

ll nc(ll n,ll r){
	if(n==r || r==0){
		return 0;
	}else if(n==1){
		return r;
	}else{
		return nc(n-1,r-1)+nc(n-1,r);
	}
}



int main(){
	
	cin>>n>>a>>b;
	for(i=0;i<n;i++){
		cin>>v[i];
	}
	k=0;
	sort(v,v+n);
	for(i=0;i<n;i++){
		if(i>=n-i-1)break;
		sum=v[i];
		v[i]=v[n-i-1];
		v[n-i-1]=sum;
	}
	sum=0;
	for(i=0;i<a;i++){
		sum+=v[i];
	}
	sum/=a;
	ll kazu=a;
	ll ooi=0,ona=0;
	for(i=0;i<n;i++){
		if(v[i]>v[a-1])ooi++;
		if(v[i]==v[a-1])ona++;
	}
	for(i=0;i<=50;i++){
		for(j=0;j<=i;j++){
			if(i==j || j==0){
				dp[i][j]=1;
			}else{
				dp[i][j]=dp[i-1][j]+dp[i-1][j-1];
			}
		}
	}

	if(ooi==0){
		for(j=a;j<=b;j++){
			ans+=dp[ona][j];
		}
	}else{
		ans=dp[ona][a-ooi];
	}

	cout<<fixed<<setprecision(25)<<sum<<endl;
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    double r = n / 108.0 * 100.0;
    int x1 = r + 1;
    int x2 = r;
    int a1 = x1 * 1.08;
    int a2 = x2 * 1.08;
    if (a1 == n) {
        printf("%d\n", x1);
        return 0;
    }
    if (a2 == n) {
        printf("%d\n", x2);
        return 0;
    }
    printf(":(\n");
    return 0;
}


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

int main() {
  int N, count_tuyoihito = 0;
  cin >> N;
  vector<bool> rate(8, false);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a < 400) rate.at(0) = true;
    else if (a < 800) rate.at(1) = true;
    else if (a < 1200) rate.at(2) = true;
    else if (a < 1600) rate.at(3) = true;
    else if (a < 2000) rate.at(4) = true;
    else if (a < 2400) rate.at(5) = true;
    else if (a < 2800) rate.at(6) = true;
    else if (a < 3200) rate.at(7) = true;
    else count_tuyoihito++;
  }
  
  int count_color = 0;
  for (int i = 0; i < 8; i++) {
    if (rate.at(i)) count_color++;
  }
  
  if (count_color>0) {
    cout << count_color << " " << count_color+count_tuyoihito << endl;
  }
  else {
    cout << 1 << " " << count_tuyoihito << endl;
  }
}

Measured memory_bytes: 256
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18+5;

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

// structs...
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

// functions...
ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans;
}


void task()
{
    //code here...
    
    int x;
    
    cin >> x;
    
    if(x>=30) cout << "Yes\n";
    else cout << "No\n";
}


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

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

    task();

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll DP[200][200][100];
ll V[100];

int main(){
    ll N, K;
    cin >> N >> K;
    REP(i,N){
        cin >> V[i];
    }

    REP(i,200) REP(j,100) REP(k,100)
        DP[i][j][k] = -1e17;

    const ll a = 1;
    DP[0][0][a+N-1] = 0;
    REP(i,K){
        REP(l,N){
            REPi(r,l,N){
                chmax(DP[i+1][l][a+r],   DP[i][l][a+r]);
                chmax(DP[i+1][l+1][a+r], DP[i][l][a+r] + V[l]);
                chmax(DP[i+2][l+1][a+r], DP[i][l][a+r]);
                chmax(DP[i+1][l][a+r-1], DP[i][l][a+r] + V[r]);
                chmax(DP[i+2][l][a+r-1], DP[i][l][a+r]);
            }
        }
    }

    ll ans = 0;
    REP(l,N+1){
        REPi(r,l,N+1){
            chmax(ans, DP[K][l][r]);
        }
    }

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


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

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}

int seg1[800005];
int seg2[800005];
int lz[800005];

void build(int ver,int tl,int tr)
{
    if(tl>tr)
        return ;
    else if(tl==tr)
    {
        seg1[ver]=tl;
        seg2[ver]=0;
    }
    else
    {
        int tm=(tl+tr)/2;
        build(2*ver,tl,tm);
        build(2*ver+1,tm+1,tr);
        seg1[ver]=max(seg1[2*ver],seg1[2*ver+1]);
        seg2[ver]=min(seg2[2*ver],seg2[2*ver+1]);
    }    
}

void push(int ver,int tl,int tm,int tr)
{
    seg1[2*ver]= lz[ver];
    seg1[2*ver+1]=lz[ver];
    seg2[2*ver]=tl-lz[ver];
    seg2[2*ver+1]=tm+1-lz[ver];
    lz[2*ver]=lz[ver];
    lz[2*ver+1]=lz[ver];
    lz[ver]=0;
}

void upd(int ver,int tl,int tr,int l,int r,int val)
{
    if(tl>tr||l>r||tr<l||r<tl)
        return ;
    else if(tl==l&&tr==r)
    {
        seg1[ver]=val;
        seg2[ver]=tl-val;
        lz[ver]=val;
    }
    else
    {
        int tm=(tl+tr)/2;
        if(lz[ver])
            push(ver,tl,tm,tr);
        upd(2*ver,tl,tm,l,min(tm,r),val);
        upd(2*ver+1,tm+1,tr,max(tm+1,l),r,val);
        seg1[ver]=max(seg1[2*ver],seg1[2*ver+1]);
        seg2[ver]=min(seg2[2*ver],seg2[2*ver+1]);
    }    
}

int get1(int ver,int tl,int tr,int l,int r)
{
    if(tl>tr||l>r||tr<l||r<tl)
        return 0;
    else if(tl==l&&tr==r)
        return seg1[ver];
    else
    {
        int tm=(tl+tr)/2;
        if(lz[ver])
            push(ver,tl,tm,tr);
        int z= max(get1(2*ver,tl,tm,l,min(tm,r)),get1(2*ver+1,tm+1,tr,max(tm+1,l),r));
        seg1[ver]=max(seg1[2*ver],seg1[2*ver+1]);
        seg2[ver]=min(seg2[2*ver],seg2[2*ver+1]);
        return z;
    }       
}


int get2(int ver,int tl,int tr,int l,int r)
{
    if(tl>tr||l>r||tr<l||r<tl)
        return 1e9;
    else if(tl==l&&tr==r)
        return seg2[ver];
    else
    {
        int tm=(tl+tr)/2;
        if(lz[ver])
            push(ver,tl,tm,tr);
        int z= min(get2(2*ver,tl,tm,l,min(tm,r)),get2(2*ver+1,tm+1,tr,max(tm+1,l),r));
        seg1[ver]=max(seg1[2*ver],seg1[2*ver+1]);
        seg2[ver]=min(seg2[2*ver],seg2[2*ver+1]);
        return z;
    }       
}


signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n,m;
    cin>>n>>m;
    build(1,1,m);
    int x,y;
    int lft=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y;

        if(x-1<=lft)
        {
            lft=max(lft,y);
            int ans=get2(1,1,m,lft+1,m);
            if(ans==1e9)
                cout<<-1<<'\n';
            else
                cout<<ans+i<<'\n';
            continue;
        }
        int z=get1(1,1,m,lft+1,x-1);
        upd(1,1,m,x,y,z);
        int ans=get2(1,1,m,lft+1,m);
        if(ans==1e9)
            cout<<-1<<'\n';
        else
            cout<<ans+i<<'\n';
    }

}

Measured memory_bytes: 15880
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        int q = sc.nextInt();
        int[] a = new int[q];
        int[] win = new int[n];
        for (int i = 0; i < q; i++) {
            a[i] = sc.nextInt();
        }

        for (int i = 0; i < q; i++) {
            win[a[i] - 1]++;
        }
        for (int i = 0; i < n; i++) {
            if (k - (q - win[i]) > 0) {
                System.out.println("Yes");
                continue;
            }
            System.out.println("No");
        }
    }
    
}


Measured memory_bytes: 62888
#include <bits/stdc++.h>
using namespace std;
 
//#define int long long
#define F first
#define S second

int main() {
	ios::sync_with_stdio(false);
	string s;
	int a;
	cin >> a;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size() - 2; i++)
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
			ans++;
	cout << ans;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;

using ll = long long;
const int INF = (int)10e9;

int main() {
    int A, B, K;
    cin>>A>>B>>K;
    int c = 0;
    for(int i = min(A, B); i >= 0; i--) {
        if(A % i == 0 && B % i == 0) c++;
        if(c == K) {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


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

int main(){
    string a,b;
    cin>>a>>b;
    if(a.size()>b.size()) cout<<"GREATER"<<endl;
    else if(a.size()<b.size()) cout<<"LESS"<<endl;
    else if(a>b) cout<<"GREATER"<<endl;
    else if(b>a) cout<<"LESS"<<endl;
    else cout<<"EQUAL"<<endl;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<numeric>
#include<list>
#include<limits>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<unordered_set>

#define pi 3.141592653589793
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

using namespace std;
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;

const long long MOD = 10e9 + 7;
const long long INF = 10e9 ;

template <typename T>
std::ostream& operator<<(ostream& os, 
                        const vector<T> &v)
{
    for (T const& i: v) {
        os << i << " ";
    }
    os<<endl;
    return os;
}

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
vector<int> sieve(int n){
    vector<bool> s(n, true);
    for(int i =2 ; i*i <= n; i++ )
        if(s[i])
            for(int j=2*i; j< n; j +=i )
                s[j] = false;

    vector<int> primes;
    for(int i =0; i<n; i++)
        if( s[i] )
            primes.push_back(s[i]);

    return primes;
}

int main(){

    int n;
    cin>>n;
    VII ar(n-1);
    vector<int> bosses(n);
    for(auto &i: ar) cin>>i;
    for(auto i: ar)
        bosses[i-1]++;
    for(auto i: bosses)
        cout<<i<<endl;

    return 0;
}

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

using sll = signed long long;

int main() {
	int n;
	std::cin >> n;
	//	constexpr static const auto size = 100000;

	std::vector<std::pair<sll, sll> > v{ static_cast<unsigned>(n) };


	for (auto&e : v)
		std::cin >> e.first >> e.second;

	std::sort(std::rbegin(v), std::rend(v)
		, [](auto x, auto y) {
		return x.first + x.second < y.first + y.second;
	});

	/*
	for (auto&e : v) {
		std::cout << e.first << " " << e.second << "\n";
	}*/

	sll ans{};
	auto turn = true;
	for (int i{}; i < n; ++i) {
		ans += turn ? v[i].first : -v[i].second;
		turn = !turn;
	}

	std::cout << ans << "\n";
	return 0;
}

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

using namespace std;

int n,k,a[100010],dp[100010];

void read()
{
    cin >> n >> k;
    for (int i = 1;i <= n;i++){
        cin >> a[i];
    }
}

void solve()
{
    dp[1] = 0;
    dp[2] = abs(a[1] - a[2]);
    for (int i = 3;i <= n;i++){
        int f = i - k;
        if (f < 1) f = 1;
        long long temp = 9999999999;
        for (int j = f;j < i; j++){
            if (abs(a[j] - a[i]) + dp[j] < temp) temp = abs(a[j] - a[i]) + dp[j];
        }
        dp[i] = temp;
    }
    cout << dp[n];
}

main()
{
    read();
    solve();
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,b)  for(int i=0;i<(int)(b);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
typedef long long ll;
typedef long double ld;

using namespace std;

int main(){
    cs;
    int a,b,c,t;
    cin>>a>>b>>c;
    t=a*b*c;
    t/=2;t/=max(a,max(b,c));
    cout<<t;
}

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

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

int main(){
    int h,w,n;
    cin >> h >> w;//h*wが総和になるようにする。
    cin >> n;
    int out[100][100] = {0};
    vector<int> a(n,0);
    rep(i,n) cin >> a[i];
    int cnt = 0,cnt2 = 0;
    rep(i,h){
        if(i % 2){
            rep(j,w){
                out[i][j] = cnt+1;
                cnt2++;
                if(cnt2 == a[cnt]){
                    cnt++;
                    cnt2 = 0;
                }
            }
        }else{
            for(int j = w-1; j >= 0; j--){
                out[i][j] = cnt+1;
                cnt2++;
                 if(cnt2 == a[cnt]){
                    cnt++;
                    cnt2 = 0;
                }
            }
        }
    }

    rep(i,h){
        rep(j,w){
            cout << out[i][j] << " ";
        }
        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int N,Q;
string S;
vector<char> t,d;

int C(int n) {
    for(int i=0; i<Q; ++i) {
        if(t[i] == S[n]) n += (d[i] == 'R' ? 1 : -1);
    }

    if(n == 0) return -1;
    else if(n == N + 1) return 1;
    else return 0;
}

int solveL() {
    int l = 0, r = N + 1;
    while(r - l > 1) {
        int m = (l + r) / 2;
        if(C(m) == -1) l = m;
        else r = m;
    }
    return l;
}

int solveR() {
    int l = 0, r = N + 1;
    while(r - l > 1) {
        int m = (l + r) / 2;
        if(C(m) == 1) r = m;
        else l = m;
    }
    return r;
}

int main() {
    cin >> N >> Q;
    cin >> S;
    S = '!' + S;
    S += '!';
    t.resize(Q);
    d.resize(Q);
    for(int i=0; i<Q; ++i) cin >> t[i] >> d[i];

    int left = solveL();
    int right = solveR();
    cout << right - 1 - left << endl;
}

Measured memory_bytes: 896
#include<iostream>
using namespace std;
int n,OUT,SCORE;
bool F,S,T;
string str;
int main(){
  cin>>n;
  while(n--){
    OUT=SCORE=0;
    F=S=T=false;
    while(OUT<3){
      cin>>str;
      if(str=="OUT")OUT++;
      else if(str=="HIT"){
	if(T){SCORE++;T=false;}
	if(S){T=true;S=false;}
	if(F){S=true;}
	F=true;
      }else if(str=="HOMERUN"){
	if(T)SCORE++;
	if(S)SCORE++;
	if(F)SCORE++;
	SCORE++;
	T=S=F=false;
      }
    }
    cout<<SCORE<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);  cin.tie(0) ; cout.tie(0);
#define debug(x) cout << #x << " : " << x << endl;
#define pi 3.14159265359
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
using ll = long long int;
using db = double;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
const int MOD = 1e9+9;

void solve()
{
    int n , ans = 0;
    db d;
    cin >> n >> d;
    while(n--)
    {
        db a , b;
        cin >> a >> b;
        if( sqrt(a*a + b*b) <= d)
            ans++;
    }
    cout << ans << endl;
}

int main()
{
//  #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin); 
//     freopen("output.txt", "w", stdout);
//  #endif
    fastio;

    ll t = 1;
    // cin >> t;
    while(t--)
       solve();
    return 0;
}

Measured memory_bytes: 3768
#include <stdio.h>
int main(void){
  int h1,h2,m1,m2,k;
  scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
  printf("%d",(60*h2+m2)-(60*h1+m1)-k);
  return 0;
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

inline bool judge(const str &s) {
    if(s[0] == s[1] && s[1] == s[2]) return false;
    return true;
}

int main() {
    str s;
    cin >> s;
    cout << (judge(s) ? "Yes" : "No") << "\n";

    return 0;
}


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

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 310, Mod = 1e9 + 7;
int f[N][N][N];
struct node {
	int l, x;
};
vector<node> a[N];
int calc(int p1, int p2, int l) {
	return 1 + (p1 >= l) + (p2 >= l);
}
void pls(int &x, int y) { x += y; if (x >= Mod) x -= Mod; }
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>(), m = gi<int>();
	while (m--) {
		int l = gi<int>(), r = gi<int>(), x = gi<int>();
		a[r].push_back((node) {l, x});
	}
	f[1][0][0] = 1;
	for (int z = 0; z < a[1].size(); z++)
		if (a[1][z].x > 1) f[1][0][0] = 0;
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < i - 1; j++)
			for (int k = 0; k < i - 1; k++) {
				pls(f[i][j][k], f[i - 1][j][k]);
				pls(f[i][i - 1][k], f[i - 1][j][k]);
				pls(f[i][j][i - 1], f[i - 1][j][k]);
			}
		for (int j = 0; j < i; j++)
			for (int k = 0; k < i; k++)
				for (int z = 0; z < a[i].size(); z++)
					if (calc(j, k, a[i][z].l) != a[i][z].x)
						f[i][j][k] = 0;
	}
	int res = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)			
			pls(res, f[n][i][j]);
	printf("%d\n", 3ll * res % Mod);
	return 0;
}


Measured memory_bytes: 112896
import sys
sys.setrecursionlimit(10 ** 7)

def solve(index: int, dp: list, footing: list) -> int:
    if dp[index] != -1:
        return dp[index]

    if index == 0:
        return 0
    elif index == 1:
        return abs(footing[1]-footing[0])

    tmp = min(solve(index-1, dp, footing)+abs(footing[index]-footing[index-1]), solve(index-2, dp, footing)+abs(footing[index]-footing[index-2]))
    #print(f'{tmp=}')
    dp[index] = tmp
    return tmp

N = int(input())
footing = list(map(int, input().split()))

dp = [-1] * N

ans = solve(N-1, dp, footing)

print(ans)

Measured memory_bytes: 93972
#include <bits/stdc++.h>
int g[101][101];
using namespace std;

int  main(){
  int N,Ma,Mb;
  cin>>N>>Ma>>Mb;
  std::vector<int> a(N),b(N),c(N);
  for(int i=0;i<N;i++)cin>>a[i]>>b[i]>>c[i];
  for(int i=0;i<101;i++)for(int j=0;j<101;j++)g[i][j]=10000000;
  g[0][0]=0;
  for(int k=0;k<N;k++){
    for(int i=100;i>=0;i--)for(int j=100;j>=0;j--)if(i+a[k]<101&&j+b[k]<101)g[i+a[k]][j+b[k]]=min(g[i+a[k]][j+b[k]],g[i][j]+c[k]);
  }
  int ans=10000000;
  for(int i=1;i<101;i++){
    for(int j=1;j<101;j++){
      if(i*Mb==j*Ma){
        ans=min(ans,g[i][j]);
      }
    }
  }
  if(ans>=10000000)cout<<-1<<endl;
  else cout<<ans<<endl;
}


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

int func_sums(int x) {
    int res = 0;
    while (x != 0) {
        res += x % 10;
        x /= 10;
    }

    return res;
}

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

    int sum = 0, tmp;
    for (int i = 1; i <= n; i++) {
        tmp = func_sums(i);
        if (a <= tmp && tmp <= b) sum += i;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3560