akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
typedef long long ll;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    ll N;
    cin >> N;
    rep(i,11){
        ll ot = i*1000 - N;
        if(ot >= 0){
            out(ot);
            break;
        }
    }
}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc090.contest.atcoder.jp/tasks/arc090_b>
問題文============================================================
 x 軸上に N 人の人が立っています。 人 i の位置を xi とします。
 任意の i に対して、xi は 0 以上 109 以下の整数です。
 同じ位置に複数の人が立っていることもありえます。
 
 これらの人の位置に関する情報が M 個与えられます。
 このうち i 個めの情報は (Li,Ri,Di) という形をしています。
 この情報は、人 Ri は人 Li よりも距離 Di だけ右にいること、
 すなわち、xRi−xLi=Di が成り立つことを表します。
 
 これら M 個の情報のうちのいくつかに誤りがある可能性があることがわかりました。
 与えられる M 個すべての情報と矛盾しないような値の組 (x1,x2,…,xN) が存在するかどうか判定してください。
=================================================================

解説=============================================================

 互いに到達できる頂点集合の中で、一つの頂点を基準位置として、
 グラフのように各頂点を辿っていきながら矛盾がないかどうか確認していけば良い
 
================================================================
*/
int N,M;
struct edge{
    int L,R,D;
    edge(){}
    edge(int L,int R,int D):L(L),R(R),D(D){}
};
vector<vector<edge>> G;

bool dfs(int n,bool first,vector<int>& checked,vector<ll>& loc){
    if(first) loc[n] = 0;
    checked[n] = 1;
    for(edge& e:G[n]){
        if(checked[e.R] == 0){
            loc[e.R] = loc[e.L] + e.D;
            if(!dfs(e.R,false,checked,loc))return false;
        }else{
            if(loc[e.R] != loc[e.L] + e.D) return false;
        }
    }
    return true;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M;
    G.resize(N);
    for(int i = 0; i < M;i++){
        int L,R,D; cin >> L >> R >> D;
        L--; R--;
        G[L].push_back(edge(L,R,D));
        G[R].push_back(edge(R,L,-D));
    }
    
    vector<int> checked(N,0);
    vector<ll> loc(N,LINF);
    for(int i = 0; i < N;i++){
        if(checked[i]) continue;
        if(!dfs(i,true,checked,loc)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  long long n=0,ans=0;
  for(int i=0; i<s.size()-1; i++)
  {
    if(s.at(i)=='A') n++;
    else if(s.at(i)=='B' && s.at(i+1)=='C') { ans+=n; i++;}
    else n=0;
  }
  cout<<ans;
}

Measured memory_bytes: 640
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	size_t N, A, B;

	scanf("%zu\n%zu\n%zu", &N, &A, &B);

	const size_t max = MIN(A, B);
	size_t min = 0;
	if (N < A + B) {
		min = MAX(MIN(A + B - N, A), MIN(A + B - N, B));
	}

	printf("%zu %zu\n", max, min);

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll X,Y,Z;
    cin >>X>>Y>>Z;
    
    
    cout << (X-Z)/(Y+Z) << endl;


    return 0;
    

}

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

#define llint long long int

using namespace std;

int main() {
    llint X, K, D;

    cin >> X >> K >> D;

    if (X < 0) {
        X = -X;
    }
    if (K < X / D) {
        cout << X - D * K << endl;
    }
    else {
        K -= X / D;
        X -= D * (X / D);

        if (K % 2 == 0) {
            cout << X << endl;
        }
        else {
            cout << D - X << endl;
        }
    }
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

const int L = 100000 + 10;
const ll INF = 1ll << 60;

int main() {
  int N, W;
  while (cin >> N >> W) {
    vector<ll> v(N), w(N);
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];
    vector<ll> dp(L, INF);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
      vector<ll> ndp = dp;
      for (int s = 0; s < L; s++) {
        if (s + v[i] < L) {
          ndp[s + v[i]] = min(ndp[s + v[i]], dp[s] + w[i]);
        }
      }
      dp = ndp;
    }
    ll res = 0;
    for (int s = L - 1; s >= 0; s--) {
      if (dp[s] <= W) {
        res = s;
        break;
      }
    }
    cout << res << endl;
  }
  return 0;
}


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

using namespace std;

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

template<class T>
T read() {
    T x{};
    cin >> x;
    return x;
}

template<class T>
vector<T> read(int N){
    vector<T> x(N);
    for(int i = 0; i < N; ++i){
        cin >> x[i];
    }
    return x;
}

template<class T>
void write(const T &x){ cout << x << endl; }

int main(){
    auto H = read<ll>();
    auto W = read<ll>();
    auto A = read<ll>();
    auto B = read<ll>();
    
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            if(i < B) cout << (j < A);
            else cout << !(j < A);
        }
        cout << endl;
    }
    
}



Measured memory_bytes: 1280
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
  int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int c=0;
for(int i=1;i<n;i++){
  if(a[i]==a[i-1]){
  c++;
    a[i]=0;
  }
}
System.out.println(c);
}}

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

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

const int MOD = 1000000007;

ll f(ll n) {
    ll res = 0;
    while (n > 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

double g(ll n) {
    return double(n) / f(n);
}

int main() {
    vector<ll> res;
    ll base = 1;
    rep(i, 15) {
        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 (ll i = 0; i < res.size(); ++i) {
        for (ll j = i + 1; j < res.size(); ++j) {
            if (g(res[i]) > g(res[j])) {
                res.erase(res.begin() + i--);
                break;
            }
        }
    }

    ll K;
    cin >> K;
    for (ll i = 0; i < K; ++i) {
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


signed main()
{
	fio
	inp(n)
	inpa(a,n+1)
	vector<int> ma(n+1,INF);//,mi(n+1,INF);
	ma.back()=a.back();
	ma[0]=1;
	int ans=0;
	fo(i,n)
	{
		ma[i+1]=min(ma[i+1],(ma[i]-a[i])*2);
		// mi[i+1]=max(mi[i+1],(mi[i]-a[i]));
	}
	// cerr<<ma<<endl;
	for(int i=n;i>0;i--)
	{
		ma[i-1]=min(ma[i-1],ma[i]+a[i-1]);
		// mi[i-1]=max(mi[i-1],(mi[i]-a[i])/2+(mi[i]-a[i])%2);
	}
	
	// cerr<<ma<<endl;
	
	fo(i,n+1)
	{
		if(a[i]>ma[i])
		{
			cout<<-1<<'\n';
			return 0;
		}
	}
	fo(i,n+1)
	{
		ans+=ma[i];
	}
	cout<<ans<<'\n';
	printclock;
}

Measured memory_bytes: 4784
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void solve() {
	int r; cin >> r;
	cout << r * r << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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 all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int k,x;
    cin>>k>>x;
    if(k*500>=x) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3580
d, n = gets.strip.split.map{|x| x.to_i}
if n < 100
    ans = case d
            when 0 then n
            when 1 then n*100
            when 2 then n*(100**2)
          end
else
    ans = case d
            when 0 then n + 1
            when 1 then (n+1)*100
            when 2 then (n+1)*(100**2)
          end
end
puts ans


Measured memory_bytes: 3836
# 参考: White_Pie_46
# https://atcoder.jp/contests/abc176/submissions/16168825
from collections import deque


def main():
    height, width = [int(x) for x in input().split()]
    init_h, init_w = [int(x) - 1 for x in input().split()]
    dest_h, dest_w = [int(x) - 1 for x in input().split()]
    grid = [list(input()) for _ in range(height)]

    adjacents = (
        (1, 0),
        (0, 1),
        (-1, 0),
        (0, -1)
    )

    def gen_warp_can_reach():
        for h in range(-2, 3):
            for w in range(-2, 3):
                if h == 0 == w:
                    continue
                if (h, w) in adjacents:
                    continue
                yield (h, w)
    warp_can_reach = tuple(gen_warp_can_reach())
    qu = deque()
    qu.append((init_h, init_w, 0))  # 座標とワープ回数を保持

    while qu:
        h, w, warps = qu.popleft()
        if h == dest_h and w == dest_w:
            return warps
        if grid[h][w] == 'R':
            # 同じマスを複数回キューに追加しているかもしれない。
            # 短距離で調査済みなら再調査は不要。
            continue
        grid[h][w] = 'R'  # reached

        for h_delta, w_delta in adjacents:
            new_h, new_w = h + h_delta, w + w_delta
            if new_h < 0 or new_h >= height or new_w < 0 or new_w >= width:
                continue
            if grid[new_h][new_w] == '.':
                qu.appendleft((new_h, new_w, warps))

        for h_delta, w_delta in warp_can_reach:
            new_h, new_w = h + h_delta, w + w_delta
            if new_h < 0 or new_h >= height or new_w < 0 or new_w >= width:
                continue
            if grid[new_h][new_w] == '.':
                qu.append((new_h, new_w, warps + 1))
    return -1


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 233792
#include <iostream>
using namespace std;
int main() {
    string str,op,rstr;
    int q,a,b,i;
    cin >> str >> q;
    for (i=0;i<q;i++) {
        cin >> op >> a >> b;
        if (op == "print") {
            cout << str.substr(a, b-a+1) << endl;
        } else if (op == "reverse") {
            rstr = str.substr(a, b-a+1);
            for (int j=0;j<b-a+1;j++) {
                str[a+j] = rstr[b-a-j];
            }
        } else if (op == "replace") {
            cin >> rstr;
            str.replace(a, b-a+1, rstr);
        }
    }
    return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
int main(){
  int a, b, c, x, y, ans=0;
  std::cin >>a>>b>>c>>x>>y;
  if(a+b <= c*2){
    ans = a*x+b*y;
  }else{
    ans += std::min(c*std::max(x, y)*2, c*std::min(x,y)*2+a*(x-std::min(x,y))+b*(y-std::min(x,y)));
  }
  printf("%d\n", ans);
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li h, w, a, b;
    cin >> h >> w >> a >> b;

    string s;
    string s1;
    rep(i, a) {
        s = s + "0";
        s1 = s1 + "1";
    }
    rep(i, w - a) {
        s = s + "1";
        s1 = s1 + "0";
    }
    rep(i, b) {
        cout << s << endl;
    }
    rep(i, h - b) {
        cout << s1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Queue;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());

		ArrayList<Res> ResList = new ArrayList<Res>();

		for(int i = 0;i<N;i++){
			String[] tmp = br.readLine().split(" ");
			Res r = new Res(tmp[0],Integer.parseInt(tmp[1]),i);
			ResList.add(r);
		}

		ResList.sort((a,b) -> a.city.compareTo(b.city));

		Queue<Integer> q = new ArrayDeque<>();
		try{
			int i = 0;

			while(true){
				String nowCity = ResList.get(i).city;
				ArrayList<Res> nowList = new ArrayList<Res>();



				while(true){
					if(i == ResList.size())break;
					if(!ResList.get(i).city.equals(nowCity))break;
					Res r = new Res(ResList.get(i).city,ResList.get(i).point,ResList.get(i).id);
					nowList.add(r);
					i++;
				}

				nowList.sort((a,b) -> b.point - a.point);

				for(int i1 = 0;i1<nowList.size();i1++){
					q.add(nowList.get(i1).id);
				}



			}
		}catch(Exception e){
			e.getMessage();
		}finally{
			while(!q.isEmpty()){
				System.out.println(q.poll() + 1);
			}
		}
	}

	static class Res{
		String city;
		int point;
		int id;

		Res(String c,int p,int i){
			city = c;
			point = p;
			id = i;
		}
	}
}

Measured memory_bytes: 26068
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

typedef long long ll;

int main(){
  ll N, K;
  std::cin >> N >> K;
  std::vector<ll> h(N);
  for(int i = 0 ; i < N ; i++){
    std::cin >> h[i];
  }
  
  std::vector<ll> dp(N, (ll)1e18);
  dp[0] = 0;
  dp[1] = std::fabs(h[1] - h[0]);
  for(int i = 2 ; i < N ; i++){
    for(int j = 1 ; j <= K && i - j >= 0 ; j++){
      dp[i] = std::min(dp[i], dp[i - j] + (ll)std::fabs(h[i] - h[i - j]) );
    }
  }
  std::cout << dp[N - 1] << std::endl;
  return 0;
}


Measured memory_bytes: 4804
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

struct Trie{
	Trie* p[26];
	int x;
	Trie():x(-1){
		memset(p, 0, sizeof(p));
	}
} root;

void add(Trie *p, const string &s, int i, int x){
	if(i == s.size()){
		p->x = x;
	}else{
		if(!p->p[s[i] - 'a']) p->p[s[i] - 'a'] = new Trie();
		add(p->p[s[i] - 'a'], s, i + 1, x);
	}
}

int ans[100005][30][30];

vi dfs(Trie *p){
	if(!p) return vi();
	vector<vi> v(26);
	REP(i, 26)if(p->p[i]){
		v[i] = dfs(p->p[i]);
	}
	REP(i, 26)REP(j, 26)if(i != j){
		for(int t : v[i]) ans[t][i][j] += v[j].size();
	}
	vi res;
	for(auto &it : v){
		if(res.size() < it.size()) swap(res, it);
		for(const int x : it) res.pb(x);
	}
	if(p->x != -1){
		ans[p->x][0][0] += res.size();
		res.pb(p->x);
	}
	return res;
}

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n;
	string s;
	REP(i, n){
		cin >> s;
		add(&root, s, 0, i);
	}
	dfs(&root);
	cin >> m;
	REP(i, m){
		int k;
		cin >> k >> s; k--;
		int x = n-ans[k][0][0];
		REP(i, 26)REP(j, i)
			x -= ans[k][s[j]-'a'][s[i]-'a'];
		printf("%d\n", x);
	}
	return 0;
}


Measured memory_bytes: 394652
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct mint {
    static const long long mod = 998244353;
    long long x;
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint& a) {if ((x += a.x) >= mod) x -= mod; return *this;}
    mint& operator-=(const mint& a) {if ((x += mod - a.x) >= mod) x -= mod; return *this;}
    mint& operator*=(const mint& a) {(x *= a.x) %= mod; return *this;}

    friend const mint operator+(const mint& a, const mint& b) { mint ret = a; return ret += b; }
    friend const mint operator-(const mint& a, const mint& b) { mint ret = a; return ret -= b; }
    friend const mint operator*(const mint& a, const mint& b) { mint ret = a; return ret *= b; }
    friend ostream& operator<<(ostream& s, const mint& a) { return s << a.x; }

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

    // for prime mod
    mint inv() const { return pow(mod - 2);}
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    friend const mint operator/(const mint& a, const mint& b) { mint ret = a; return ret /= b; }
};

void solve() {
    ll n, k;
    cin >> n >> k;
    vll l(k), r(k);
    rep(i, k) cin >> l[i] >> r[i];
    vector<mint> dp(n + 1);
    dp[1] = 1;
    for(int i = 2; i <= n; ++i) {
        dp[i] = dp[i - 1];
        for(int j = 0; j < k; ++j) {
            if(i - l[j] >= 0) dp[i] += dp[i - l[j]];
            if(i - r[j] - 1 >= 0) dp[i] -= dp[i - r[j] - 1];
        }
    }
    cout << dp[n] - dp[n - 1] << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 4772
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

string s;

signed main() {
	cin >> s;
	string ta = s.substr(5, 2);
	if (ta == "01" || ta == "02" || ta == "03" || ta == "04")cout << "Heisei" << endl;
	else cout << "TBD" << endl;
	ggr
}

Measured memory_bytes: 256
#include <cstdio>
#include <deque>

int main()
{
    short input;
    std::deque<short> data;
    while(1)
    {
        scanf("%hd", &input);
        if(input == 0) break;
        data.push_back(input);
    }
    for(size_t i = 0; i < data.size(); ++i)
    {
        printf("Case %zu: %d\n", i+1, data[i]);
    }
}


Measured memory_bytes: 2596
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

// list up all prime factors, including how many times does it have the prime
template <typename T = int>
void primeFactors(T a, map<T, int> &facs) {
    double sqrtA = sqrt(a);
    for (int i = 2; i <= sqrtA + 1e-10; ++i) {
        while (a % i == 0) {
            facs[i]++;
            a /= i;
        }
    }
    if (a > sqrtA)
        facs[a]++;
    return;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    map<lint, int> gcd;
    for (int i = 0; i < n; ++i) {
        map<lint, int> pf;
        primeFactors(a[i], pf);
        for (auto &p : pf) {
            chmax(gcd[p.first], p.second);
        }
    }
    mint g = 1;
    for (auto &p : gcd) {
        g *= mint(p.first).pow(p.second);
    }
    mint ret = 0;
    for (int i = 0; i < n; ++i) {
        ret += g / a[i];
    }
    cout << ret << "\n";
    return 0;
}

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

int N, M;



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

int main() {
	while (cin >> N >> M && N) {
		int d, p;
		int E = 0;
		int P = 0;
		vector< pair<int, int> >vec;
		vec.clear();
		for (int i = 0; i < N; ++i) {
			cin >> d >> p;
			E += d;
			vec.push_back({ d , p });
		}
		E -= M;
		sort(vec.begin(), vec.end(), cmp1);
		for (int i = 0; E > 0 && i< vec.size(); i++) {
			int d = vec[i].first;
			int p = vec[i].second;
			if (E > d) {
				E -= d;
				P += d * p;
			}
			else {
				P += E * p;
				E = 0;
			}
		}
		cout << P << endl;

	}
	return 0;
}



Measured memory_bytes: 3212
N, K, C = map(int, input().split())
S = [1 if a == "o" else 0 for a in input()]

c = 0
X = [0] * N
Y = [0] * N

i = 0
while i < N:
    if S[i]:
        c += 1
        X[i] = 1
        i += C + 1
    else:
        i += 1

if c > K:
    exit()

i = N - 1
while i >= 0:
    if S[i]:
        Y[i] = 1
        i -= C + 1
    else:
        i -= 1

for i in range(N):
    if X[i] and Y[i]:
        print(i + 1)

Measured memory_bytes: 56524
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;
ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    map<ll, ll> m;
    REP(i, N) { m[A[i]]++; }

    vector<ll> smaller(2010);
    REP(i, 2010) { smaller[i + 1] = m[i] + smaller[i]; }

    debug(smaller);
    ll ans = 0;
    REP(i, N) {
        ans += smaller[A[i]];
        ans = ans % MOD;
    }
    debug("1", ans);

    ans = ans * ((K*(K-1)/2) % MOD) % MOD;

    ll in_count = 0;
    // A内の転倒数の計算
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            if (A.at(i) > A.at(j)) {
                in_count++;
            }
        }
    }
    ans = (ans + (in_count * K)) % MOD;
    cout << ans  << endl;

    return 0;
}


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

class Program {
	static void Main(string[] args) {
		new Calc().calc();
	}
	public class Calc {
		public Calc() { }
		public void calc() {
			List<int> list = new List<int>();
			int n;
			do {
				n = ReadLine<int>();
				list.Add(n);
			} while (n != 0);
			list.Remove(0);
			f.Add(1);
			f.Add(2);
			f.Add(4);
			fibo(4, list.Max());
			int y = 3650;
			foreach (var item in list) {
				var get = ((f[item - 1] / y) + (f[item - 1] % y > 0 ? 1 : 0));
				Console.WriteLine(get);
			}
		}
		List<long> f = new List<long>();
		private long fibo(int step, int n) {
			f.Add(f[step - 2] + f[step - 3] + f[step - 4]);
			if (step == n) return f[step - 1];
			return fibo(step + 1, n);
		}
	}

	public static T ReadLine<T>() {
		return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
	}
	public static T[] ReadLine<T>(params char[] separators) {
		return Console.ReadLine()
.Split(separators)
.Select(_ => (T)Convert.ChangeType(_, typeof(T)))
.ToArray();
	}

	public static List<T> ReadLines<T>(int readCount) {
		List<T> rt = new List<T>();
		for (int i = 0; i < readCount; i++) {
			rt.Add(ReadLine<T>());
		}
		return rt;
	}
}

Measured memory_bytes: 10376
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

_int64 a[400000];
_int64 sum1[400000];
_int64 sum2[400000];


int main()
{
  _int64 i,j,n;
  _int64 ans;
  scanf("%lld",&n);
  for (i=0;i<n+n+n;i++)
    scanf("%lld",&a[i]);
  priority_queue<_int64> pq;
  sum1[n-1]=0;
  for (i=0;i<n;i++)
  {
    pq.push(-a[i]);
    sum1[n-1]+=a[i];
  }
  for (i=n;i<n+n+n;i++)
  {
    sum1[i]=sum1[i-1];
    int tmp=pq.top();
    //cout<<tmp<<endl;
    pq.pop();
    sum1[i]+=tmp;
    if (-a[i]<tmp) tmp=-a[i];
    sum1[i]-=tmp;
    pq.push(tmp);
    //printf("%lld\n",sum1[i]);
  }
  priority_queue<_int64> pq2;
  sum2[n+n]=0;
  for (i=n+n;i<n+n+n;i++)
  {
    sum2[n+n]+=a[i];
    pq2.push(a[i]);
  }
  for (i=n+n-1;i>=0;i--)
  {
    sum2[i]=sum2[i+1];
    int tmp=pq2.top();
    pq2.pop();
    sum2[i]-=tmp;
    if (a[i]<tmp) tmp=a[i];
    sum2[i]+=tmp;
    pq2.push(tmp);
    //printf("%lld\n",sum2[i]);
  }
  ans=-(1LL<<60);
  for (i=n-1;i<n+n;i++)
  {
    if (sum1[i]-sum2[i+1]>ans) ans=sum1[i]-sum2[i+1];
  }
  printf("%lld\n",ans);
  return 0;
}

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

#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define vi vector<int>
using namespace std;
int mod = 1'000'000'000 + 7;
namespace uf {
    vector<int> par, rank;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

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

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

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y)return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }
}

ll pow_mod(ll n, ll k, ll m) {
    ll r = 1;
    for (; k > 0; k >>= 1) {
        if (k & 1) r = (r * n) % m;
        n = (n * n) % m;
    }
    return r;
}

ll gcd(ll a, ll b) {
    if (b == 0)return a;
    return gcd(b, a % b);
} // C++17


void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    int A, B;
    cin >> A >> B;
    cout << (A + B) % 24 << endl;
}

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

typedef long long ll;

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

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X);
    vector<ll> B(Y);
    vector<ll> C(Z);
    
    for(int i = 0; i < X; i++) {
        cin >> A[i];
    }

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

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

    vector<ll> D(X * Y);

    for(int i = 0; i < X; i++) {
        for(int j = 0; j < Y; j++) {
            D[i * Y + j] = A[i] + B[j];
        }
    }

    sort(D.begin(), D.end(), greater<ll>());

    int N = D.size();

    if(N > 3000) {
        N = 3000;
    }

    vector<ll> E(N * Z);

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < Z; j++) {
            E[i * Z + j] = D[i] + C[j];
        }
    }

    sort(E.begin(), E.end(), greater<ll>());

    for(int i = 0; i < K; i++) {
        cout << E[i] << endl;
    }
}

Measured memory_bytes: 31616
#include <iostream>

using namespace std;

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

    string s, t;
    cin >> s;
    cin >> t;

    for(int i = 0; i < n; i++){
        if(s.compare(i, n - i, t, 0, n - i) == 0){
            cout << n + i;
            return 0;
        }
    }

    cout << n * 2;


    return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int res = 0;
    if (s[0] == 'R'||s[1] == 'R'||s[2] == 'R') res = 1;
    if (s[0] == 'R' && s[1] == 'R') res = 2;
    if (s[1] == 'R' && s[2] == 'R') res = 2;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') res = 3;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3600
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let p: Vec<i64> = (0..n).map(|_| input()).collect();

    let mut ans = 0;
    let mut q = usize::max_value();
    for i in 0..n {
        if i + 1 == p[i] as usize {
            if q == usize::max_value() || q != i - 1 {
                ans += 1;
                q = i;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  long double ans=0;
  long double a,b;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b;
    ans+=1/b;
  }
  cout<<1/ans<<"\n";
  return(0);
}


Measured memory_bytes: 256
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int i=0 ; i<b ; i++)scanf("%d",&a[i])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	int n,m,l;
	sctd(n,m,l);
	LL a[200][200],b[200][200];
	forin(i,0,n)
	{
		forin(j,0,m)
		scanf("%lld",&a[i][j]);
	}
	forin(i,0,m)
	{
		forin(j,0,l)
		scanf("%lld",&b[i][j]);
	}
	LL c[200][200];
	forin(i,0,n)
	{
		forin(j,0,l)
		{
			forin(k,0,m)
			{
				c[i][j]+=a[i][k]*b[k][j];
			}
		}
	}
	forin(i,0,n)
	{
		forin(j,0,l-1)
		{
			printf("%lld ",c[i][j]);
		}
		printf("%lld\n",c[i][l-1]);
	}
	return 0;
}

Measured memory_bytes: 3672
#include <iostream>
using namespace std;
int main()
{
	int n=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int b[n];
	int c=0;
	if(n%2==1){ //3       1 2 3
		for(int i=n-1;i>=0;i-=2){
			b[c]=a[i];//b[0]=3 b[1]=1
			c++;//1 2
		}
		for(int i=1;i<=n-2;i+=2){
			b[c]=a[i];//b[2]=2
			c++;//3
		}
	}//3 1 2
	else{ //4      1 2 3 4
		for(int i=n-1;i>=1;i-=2){ 
			b[c]=a[i]; //b[0]=4 b[1]=2
			c++; //1 2
		}
		for(int i=0;i<=n-2;i+=2){ 
			b[c]=a[i]; //b[2]=1 b[3]=3
			c++;//3
		}
	}//4 2 1 3
	for(int i=0;i<n;i++){
		cout<<b[i]<<" ";
	}
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
signed main() {
  string s,t ;
  cin >>s>>t ;
  int n=s.size(),m=t.size() ;
  vector<vector<int>>dp(n+1,vector<int>(m+1)) ;
  // dp[i][j]->max subsequence length for substrings s(1..i) and t(1..j) 
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(s[i-1]==t[j-1])
        dp[i][j]=1+dp[i-1][j-1] ;
      else
        dp[i][j]=max(dp[i-1][j],dp[i][j-1])  ;
    }
  }
  string ans ;
  int i=n,j=m ;
  while(i>0||j>0){
    if(i>0&&dp[i-1][j]==dp[i][j])
      --i ;
    else if(j>0&&dp[i][j-1]==dp[i][j])
      --j ;
    else 
      ans+=s[i-1],--i,--j ;
  }
  reverse(ans.begin(),ans.end());
  cout << ans ;
}


Measured memory_bytes: 38536
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll R, ll G) {
  cout << 2*G-R << endl;
}

int main() {
  ll R;
  cin >> R;
  ll G;
  cin >> G;
  solve(R, G);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
//#include <search.h>
#include <algorithm>
//#include <vector>
using namespace std;
int main()
{
    int a,b,c,d,area1,area2;
    cin>>a>>b>>c>>d;
    area1=a*b;
    area2=c*d;
    if(area1>area2) cout<<area1;
    else cout<<area2;



return 0;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())

vD = make_divisors(N)
#print(vD)

res = min(d + N//d - 2 for d in vD)
print(res)


Measured memory_bytes: 3272
using System;

public class Program
{
    static long n;
    static long k;
    static long q;
    static long[] a;

    static string output;

    static long[] score;

    public static void Main(string[] args)
    {
        Input();
        Proc();
        Output();
    }

    static void Input()
    {
        string[] input = null;

        // スペース区切りの整数の入力
        input = Console.ReadLine().Split(' ');
        n = long.Parse(input[0]);
        k = long.Parse(input[1]);
        q = long.Parse(input[2]);

        // スペース区切りの整数の入力
        a = new long[q];
        for (long idx = 0; idx < q; idx++)
        {
            input = Console.ReadLine().Split(' ');
            a[idx] = long.Parse(input[0]);
        }
    }

    static void Proc()
    {
        // スコア初期化
        score = new long[n];
        for (long idx = 0; idx < n; idx++)
        {
            score[idx] = k - q;
        }

        // 回答
        for (long idxA = 0; idxA < q; idxA++)
        {
            long idxAnswer = a[idxA] - 1;

            score[idxAnswer]++;
        }
    }

    static void Output()
    {
        for (long idxScore = 0; idxScore < n; idxScore++)
        {
            if (score[idxScore] > 0)
            {
                output = "Yes";
            }
            else
            {
                output = "No";
            }
            Console.WriteLine(output);
        }
    }
}


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

#define ll long long
#define pll pair<ll,ll> 

vector<ll> S(10000006, 0);
vector<ll> A(10000006, 0);

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

	

	ll n;
	cin>>n;
	
	ll ans=0;
	for(ll i=1;i<=n;i++){
		ll k=n/i;
		ans+=i*k*(k+1)>>1;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 159440
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int rate = sc.nextInt();
    if (rate < 1200) {
      System.out.println("ABC");
    } else if (rate < 2800) {
      System.out.println("ARC");
    } else {
      System.out.println("AGC");
    }
  }
}

Measured memory_bytes: 21716
n = input()

p = list(map(int, input().split()))
counter = 0

for i in range(int(n)-2):
    if (p[i] < p[i+1] and p[i+1] < p[i+2]) or (p[i+2] < p[i+1] and p[i+1] < p[i]):
        counter += 1

print(counter)

Measured memory_bytes: 3060
import collections
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        A = [int(input()) for _ in range(N)]

        cnt = collections.Counter(A)
        ans = 0
        for v in cnt.values():
            if v % 2 == 1:
                ans += 1
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 54748
// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

string str;

bool solve()
{
	string s = str;

	reverse(s.begin(),s.end());

	if(s != str) return 0;

	string t = "";

	for(ll i = 0; i < (str.size() - 1) / 2; i++) t += str[i];

	s = t;

	reverse(s.begin(),s.end());

	if(s != t) return 0;

	t = "";

	for(ll i = str.size() - 1; i >= (str.size() + 3) / 2 - 1; i--) t += str[i];

	s = t;

	reverse(s.begin(),s.end());

//	cout << t << " " << s << endl;

	if(s != t) return 0;

	return 1;

}
int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

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

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

    while(cin >> str)
    {
		if(solve()) cout << "Yes\n";
		else cout << "No\n";
    }


}





Measured memory_bytes: 3592