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

int main() {
    string A, B;
    cin >> A >> B;
    int sum = 0;
    for(int i = stoi(A); i <= stoi(B); i++){
        bool flag = true;
        string figure = to_string(i);
        for(int j = 0; j < 3; j++){
            if(figure.at(j) != figure.at(4 - j)) flag = false;
        }
        if(flag) sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import System.IO

query i f = do
  print i
  s <- getLine
  case s of
    'V':_ -> return ()
    _ -> f s

test l r s t
  | odd (r-l) = s == t
  | otherwise = s /= t

loop l r s = do
  query m $ \t -> do
  if test l m s t then
    loop l m s
  else
    loop m r t
  where m = (l+r)`div`2

main = do
  hSetBuffering stdout LineBuffering
  n <- readLn
  query 0 $ \s -> do
  query (n-1) $ \_ -> do
  loop 0 (n-1) s


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

#define int long long

void fastio()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	fastio();

	int n;
	cin >> n;
	map<int, int> cnt;
	int sum = 0;
	while (n--)
	{
		int a;
		cin >> a;
		sum += a;
		cnt[a]++;
	}

	int q;
	cin >> q;
	while (q--)
	{
		int b, c;
		cin >> b >> c;
		sum -= b * cnt[b];
		sum += c * cnt[b];
		cnt[c] += cnt[b];
		cnt[b] = 0;
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 8940
#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define DEBUG(...)
#else
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    debug(__VA_ARGS__);                \
    cerr << endl;                      \
  } while (0)
#endif

const int matches[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

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

  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (auto& x : A) cin >> x;
  sort(A.rbegin(), A.rend());

  vector<int> dp(N + 1, -1);
  dp[0] = 0;
  REP(i, N) {
    if (dp[i] == -1) continue;
    REP(k, M) {
      int m = matches[A[k]];
      if (i + m > N) continue;
      dp[i + m] = max(dp[i + m], dp[i] + 1);
    }
  }
  assert(dp[N] >= 1);
  int s = N;
  REP(i, dp[N]) {
    REP(k, M) {
      int m = matches[A[k]];
      if (s - m >= 0 && dp[s - m] == dp[s] - 1) {
        cout << A[k];
        s -= m;
        break;
      }
    }
  }
  cout << '\n';
}


Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;
int F(ll a, ll b) {
	string as = to_string(a);
	string bs = to_string(b);
	return max(as.size(), bs.size());
}
void DigitsinMultiplication(){

	ll  n;
	cin >> n;
	ll sq = sqrt(n);
	int best = INF;
	for (size_t i = 1; i <= sq; i++)
	{
		if (n % i == 0) {
			best = min(best, F(n / i, i));
		}
	}
	cout << best << endl;
}

int main() {
	DigitsinMultiplication();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define y0 y3487465 //y1
#define j0 j1347829 //j1
#define INF 4000000000000000037 //1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

  int R,G;
  cin>>R>>G;

  cout<< R+2*(G-R)<<"\n";

}

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

long long n,m;

int main(){
  cin>>n;
  string s,t;
  int sn = 0;
  int tn = n-1;
  cout<<"0"<<endl;
  cin>>s;
  if(s == "Vacant") return 0;
  cout<<(n-1)<<endl;
  cin>>t;
  if(t == "Vacant") return 0;

  string tmp;
  for(int i=0;i<20;i++){
    int mid = (sn+tn)/2;
    cout<<mid<<endl;
    cin>>tmp;
    if(tmp == "Vacant") return 0;

    bool sett = false;

    if(tmp != t){
      if(((tn - mid + 1)%2) == 1) sett = true;
    }

    if(tmp == t){
      if(((tn - mid + 1)%2) == 0) sett = true;
    }


    //tmp = (tmp == "Male") ? "Female" : "Male";

    if(!sett){
      t = tmp;
      //tn = mid - 1;
      tn = mid;
    } else {
      s = tmp;
      sn = mid;
      //sn = mid + 1;
    }

  }
  return 0;
}

Measured memory_bytes: 852
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        x = 4 * h * n - N * n - N * h
        if x != 0 and N * h * n % x == 0:
            w = N * h * n // x
            if w >= 1:
                print(h, n, w)
                exit()


Measured memory_bytes: 69636
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)2e3 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int ans[N];
int dist[N][N];

int get_dist(int x, int y) {
    if(x > y) swap(x, y);
    return dist[x][y];
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n, x, y;
    cin>>n>>x>>y;
    x--, y--;
    f(i, n) {
        f(j, n) dist[i][j] = abs(i - j);
    }
    dist[x][y] = 1;
    for(int i = y + 1; i < n; i++) dist[x][i] = dist[x][i - 1] + 1;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            int to = get_dist(i, x) + get_dist(x, y) + get_dist(y, j);
            dist[i][j] = min(dist[i][j], to);
        }
    }
    f(i, n) {
        for(int j = i + 1; j < n; j++) ans[dist[i][j]]++;
    }
    for(int i = 1; i < n; i++) cout<<ans[i]<<"\n";
    return 0;
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back

int main()
{
    int N; cin >> N;
    vector<int> h(N);
    rep(i, N){
        cin >> h.at(i);
    }
    int ans=0;
    int active=0;
    rep(i,N){
        if(active>=h.at(i)){
            active=h.at(i);
        }
        else{
            ans+=h.at(i)-active;
            active=h.at(i);
        }
    }
    cout << ans << endl;
}

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

public class Main {

	public static void main(String[] args) {
		Main ans = new Main();
		System.out.println(ans.solve());
	}

	private String solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		int [] array  = new int[N+1];
		for(int i=0;i<N;i++){
			array[i+1] = sc.nextInt();
		}

		int [] dp =new int[K+1];
		dp[0] = 0;

		for(int i=1;i<=K;i++){
			dp[i]=0;
			for(int j=1;j<=N;j++) {
				int x = array[j];
				if (i==x) {
					dp[i]=1;
					continue;
				} else{

					if(i-x<0) continue;
					else {
						if (dp[i-x]==0) {
							dp[i]=1;
							break;
						}else dp[i]=0;
					}
				}
			}
		}

		return dp[K]==1 ? "First" : "Second";
	}

}

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

const int d5 = 100100;
vector<int> edge[d5],num,res;
int cnt=0;
void dfs(int x,int p){
    for(auto it:edge[x]){
        if(res[it]!=-1||p==it)continue;
        dfs(it,x);
    }
    res[x]=num[cnt];
    cnt++;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    num.resize(n);
    res.resize(n,-1);
    for(int i=0;i<n;i++)cin>>num[i];
    sort(All(num));
    res[0]=num[n-1];
    dfs(0,0);
    int ans=0;
    for(int i=0;i<n-1;i++)ans+=num[i];
    cout<<ans<<endl;
    for(int i=0;i<n;i++)cout<<res[i]<<' ';
    cout<<endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll long long
#define maxn (1000+10)
#define mod 10000003
#define lnode node*2,start,mid
#define rnode node*2+1,mid+1,end
using namespace std;
int main()
{   ios::sync_with_stdio(false);
	#define int ll
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n-1;i++) 
	  ans+=i;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
template<class T,class C> T max(T a,C b){ return ((a)>(T)(b) ? (a) : (T)(b)); }
template<class T,class C> T min(T a,C b){ return ((a)<(T)(b) ? (a) : (T)(b)); }
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
const int MAX = 510000;
const int MOD = 1000000007;//998244353;
long long fac[MAX], finv[MAX], inv[MAX];
#define FACT(a) PERM(a,a)
#define modinv(a,mod) modpow((a),(mod)-2,(mod))
#define nHr(n,r) COM((n)+(r)-1,(r))
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
//二項係数計算
ll COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//順列計算
ll PERM(int n, int k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return (fac[n] * finv[n-k]) % MOD;
}
void initialize(){
  COMinit();
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  string s;
  
  cin >> n;
  if(n<=2){
    cout << 0 << endl;
    return 0;
  }
  m = (n+2)/3;
  for(i=1;i<=m;i++){
    result += nHr(i,n-3*i);
    result %= MOD1;
  }
  
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 15580
from collections import Counter

n = int(input())
A = list(map(int, input().split()))

L = [i + a for i, a in enumerate(A)]
R = [i - a for i, a in enumerate(A)]

cL = Counter(L)
cR = Counter(R)

ans = 0
for i in cL.keys():
  ans += cL[i] * cR[i]

print(ans)

Measured memory_bytes: 63464
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    ll X, Y;
    cin >> X >> Y;
    if (X % Y == 0 || Y == 1) {
        cout << -1 << endl;
    } else {
        cout << X * (Y - 1) << endl;
    }
}


Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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; }
typedef pair <ll,ll> P;

int main()
{
    ll c[3][3];
    rep(i, 3)
        rep(j, 3)
            cin >> c[i][j];
    vector<ll> a(3);
    vector<ll> b(3);
    a[0] = 0;
    b[0] = c[0][0];
    b[1] = c[0][1];
    b[2] = c[0][2];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];
    bool flag = false;
    rep(i, 3) {
        rep(j, 3) {
            if (c[i][j] != a[i] + b[j]) flag = true;
        }
    }
    if (!flag) {
        yes;
    } else {
        no;
    }
    return 0;
}


Measured memory_bytes: 256
// AOJ 2118 Oil Company
// 2018.3.10 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*******************************************/
/* Dinic's Max Flow Algorithm 
/*******************************************/

#define INF 0x01010101
#define VMAX 410
typedef struct { int to; int cap; int rev; } EDGE;
EDGE *edge[VMAX]; int hi[VMAX], lim[VMAX];
int V;				// 頂点数
int level[VMAX], iter[VMAX];
int queue[2*VMAX], qtop;

void check_lim(int a)
{
	if (hi[a] < lim[a]) return;
	if (lim[a] == 0) {
		lim[a] = 16, hi[a] = 0;			// 16 ?
		edge[a] = malloc(sizeof(EDGE) *lim[a]);
	} else if (hi[a] == lim[a]) {
		int k = lim[a];
		if (k > 256) k = 256;			// 256 ??
		lim[a] += k;
		edge[a] = realloc(edge[a], sizeof(EDGE) *lim[a]);
	}
}

void add_edge(int from, int to, int cap)
{
	int f, t;
	EDGE *e;

	check_lim(from), check_lim(to);
	f = hi[from]++, t = hi[to]++;
	e = &edge[from][f], e->to = to, e->cap = cap, e->rev = t; 
	e = &edge[to][t], e->to = from, e->cap = 0, e->rev = f;
}

#if 0
void init()
{
	memset(lim, 0, sizeof(lim));
	memset(hi, 0, sizeof(hi));
}
#endif

void bfs(int s)
{
	int i, v;
	EDGE *e;
	
	memset(level, -1, V << 2);
	level[s] = 0;
	queue[0] = s, qtop =1;
	while (qtop) {
		v = queue[--qtop];
		for (i = 0; i < hi[v]; i++) {
			e = &edge[v][i];
			if (e->cap > 0 && level[e->to] < 0) {
				level[e->to] = level[v] + 1;
				queue[qtop++] = e->to;
			}
		}
	}
}
 
int dfs(int v, int t, int f)
{
	int *i, d;
	EDGE *e;
	
	if (v == t) return f;
	for (i = &iter[v]; *i < hi[v]; (*i)++) {
		e = &edge[v][*i];
		if (e->cap > 0 && level[v] < level[e->to]) {
			d = dfs(e->to, t, f <= e->cap? f: e->cap);
			if (d > 0) {
				e->cap -= d;
				edge[e->to][e->rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
 
int maxFlow(int s, int t)
{
	int f, flow = 0;
	while (1) {
		bfs(s);
		if (level[t] < 0) break;
		memset(iter, 0, V << 2);
		while ((f = dfs(s, t, INF)) > 0) flow += f;
	}
	return flow;
}

/**********************************************/

int map[22][22];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int cno, cmax, W, H, i, r, c, nr, nc, s;
	int source, sink;

	cmax = in(); for (cno = 1; cno <= cmax; cno++) {
		W = in(), H = in();
		s = 0; for (r = 0; r < H; r++) for (c = 0; c < W; c++) s += map[r][c] = in();

		source = H*W, sink = source+1, V = sink+1;
		memset(lim, 0, V << 2);
		memset(hi, 0, V << 2);

		for (r = 0; r < H; r++) for (c = 0; c < W; c++) {
			if ((r+c) & 1) add_edge(r*W+c, sink, map[r][c]);
			else {
				add_edge(source, r*W+c, map[r][c]);
				for (i = 0; i < 4; i++) {
					nr = r + mv[i][0], nc = c + mv[i][1];
					if (nr < 0 || nr >= H || nc < 0 || nc >= W) continue;
					add_edge(r*W+c, nr*W+nc, INF);
				}
			}
		}

		printf("Case %d: %d\n", cno, s-maxFlow(source, sink));

		for (i = 0; i < V; i++) if (lim[i]) free(edge[i]);
	}
	return 0;
}


Measured memory_bytes: 2044
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
#include <cstring>

int main() {
	int N, X, T;
	std::cin >> N >> X >> T;
	if(N%X == 0) {
		std::cout << N / X*T << std::endl;
	}
	else {
		std::cout << (N / X + 1)*T << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int num[26];

int main()
{
  int n;
  string s;
  cin>>n>>s;
  REP(i,n) 
    num[s[i]-'a']++;
  
  ll ans = 1ll;
  REP(i,26) {
    ans = ans * (num[i] + 1) % MOD;
  }
  cout<<ans - 1<<endl;
  return 0;
}


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


using namespace std;


int main(){
    
    int L, R;
    cin >> L >> R;
    
    if (R-L >= 2019) {
        
        cout << 0 << endl;
        
    }else{
        
        int ans = 2019;
        int anss = 2019;
        
        for (int i = L; i < R; i++) {
            for (int j = i+1; j <= R; j++) {
                
                anss = (i%2019) * (j%2019);
                anss = anss % 2019;
                
                if (ans > anss) {
                    ans = anss;
                }
            }
            
        }
        
        cout << ans << endl;
        
        
    
    }
    
    
    
    
    
    
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  string n;
  cin >> n;

  rep(i, 3) {
    if (n[i] == '7') {
      cout << "Yes" << '\n';
      return 0;
    }
  }
  cout << "No" << '\n';


  

  
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
 
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
 
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
 
// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD
 
// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;
 
int n,m;
vi g[125252];
 
bool root[125252];
bool used[125252];
bool color[125252];
int sz[125252];
 
bool dfs(int r,int p,bool c){
  bool ret = true;
  sz[r]++;
  used[p]=true;
  color[p]=c;
  for(int to : g[p]){
    if(used[to]){
      if(color[to]==c)ret=false;
    }else{
      if(!dfs(r,to,!c))ret=false;
    }
  }
  return ret;
}
 
int main(){
  scanf("%d%d",&n,&m);
  REP(i,m){
    int a,b;
    scanf("%d%d",&a,&b);
    --a;--b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
 
  int uni=0, tre=0, cyc=0;
  const int T_UNI = 0, T_CYC = 1, T_TRE = 2;
 
  vector<pii> poyo;
 
  REP(i,n)if(!used[i]){
    root[i]=true;
    bool yo = dfs(i,i,false);
    if(sz[i]==1){
      uni++;
      poyo.push_back(pii(T_UNI,sz[i]));
    }else if(!yo){
      cyc++;
      poyo.push_back(pii(T_CYC,sz[i]));
    }else{
      tre++;
      poyo.push_back(pii(T_TRE,sz[i]));
    }
  }
 
  ll ans = 0;
  int rest = n;
  REP(i,poyo.size()){
    int typ = poyo[i].first;
    int siz = poyo[i].second;
    rest -= siz;
    if(typ==T_UNI){
      uni--;
      ans++;
      ans += 2*rest;
    }else if(typ==T_TRE){
      tre--;
      ans += 2;
      ans += 2ll*uni*siz;
      ans += 2ll*tre*2;
      ans += 2ll*cyc;
    }else{
      cyc--;
      ans += 1;
      ans += 2ll*uni*siz;
      ans += 2ll*tre;
      ans += 2ll*cyc;
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 11776
import java.util.*;

public class Main {
	private void doit() {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int [] w = new int[n];
			int [] s = new int[n];
			int [] e = new int[n];
			for(int i =0; i < n;i++){
				w[i] = sc.nextInt();
				s[i] =sc.nextInt();
				e[i] = sc.nextInt();
				
			}
			boolean flg = true;
			for(int i =0; i < n;i++){
				int wei = w[i];
				for(int j =0 ;j < n; j++){
					if(i == j) continue;
					if(s[j] <= s[i] && s[i] < e[j]){
						wei += w[j];
						if(wei > 150){
							flg = false;
							break;
						}
					}
					
				}
				if(! flg){
					break;
				}
			}
			if(flg){
				System.out.println("OK");
			
			}
			else{
				System.out.println("NG");
			}
		}
		
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}


Measured memory_bytes: 52128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

string s;
int nxt[27][500011];
const int INF = int(1e9);
int st[19][500011];

void init()
{
	for(int i=0;i<=s.length();i++) st[0][i] = nxt[26][i];
	for(int i=1;i<19;i++)
	{
		for(int j = 0; j <= s.length(); j++)
		{
			st[i][j]=INF;
			if(st[i-1][j]<INF)
			{
				st[i][j]=st[i-1][st[i-1][j]];
			}
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>s;
	int n = s.length();
	for(int i=0;i<26;i++) nxt[i][n]=INF;
	nxt[26][n] = n;
	for(int i = n - 1; i >= 0; i--)
	{
		for(int j=0;j<=26;j++) nxt[j][i]=INF;
		nxt[s[i]-'a'][i] = i + 1;
		for(int j = s[i]-'a'+1; j <= 26; j++)
		{
			if(nxt[j-1][i]>=INF) nxt[j][i]=INF;
			else nxt[j][i]=nxt[j-1][nxt[j-1][i]];
		}
		if(nxt[26][i]<INF)
		{
			for(int j=0;j<s[i]-'a';j++)
			{
				nxt[j][i]=nxt[j][nxt[26][i]];
			}
		}
	}
	init();
	int q; cin>>q;
	for(int i=0;i<q;i++)
	{
		int l,r;cin>>l>>r;
		l--;
		int cur=l;
		for(int j=18;j>=0;j--)
		{
			if(st[j][cur]<=r)
			{
				cur=st[j][cur];
			}
		}
		cout<<(cur==r?"Yes":"No")<<'\n';
	}
}


Measured memory_bytes: 91164
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
vector<int> parent;
vector<int> nodes;

int getParent(int x) {
  int y = x;
  while (y != parent[y]) {
    y = parent[y];
  }
  parent[x] = y;
  return y;
}

bool unite(int x, int y) {
  x = getParent(x);
  y = getParent(y);
  if (x == y) return false;
  if (nodes[x] < nodes[y]) swap(x, y);
  parent[y] = x;
  nodes[x] += nodes[y];
  return true;
}

int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<int64_t, int>> A(N);
  rep(i, N) {
    int64_t a;
    cin >> a;
    A[i] = {a, i};
  }
  sort(A.begin(), A.end());

  parent.resize(N);
  nodes.resize(N);
  rep(i, N) {
    parent[i] = i;
    nodes[i] = 1;
  }
  int pnum = N;
  rep(i, M) {
    int x, y;
    cin >> x >> y;
    if (unite(x, y)) pnum--;
  }
  if (pnum == 1) {
    cout << 0 << endl;
    return 0;
  }

  vector<bool> usedP(N, false);
  vector<bool> usedA(N, false);
  int64_t answer = 0;
  int count = 0;
  rep(i, N) {
    int x = getParent(A[i].second);
    if (usedP[x]) continue;
    usedP[x] = true;
    usedA[i] = true;
    answer += A[i].first;
    count++;
  }

  int need = 2 * (pnum - 1);
  rep(i, N) {
    if (count == need) break;
    if (usedA[i]) continue;
    answer += A[i].first;
    count++;
  }

  if (count < need) {
    cout << "Impossible" << endl;
  } else {
    cout << answer << endl;
  }
  return 0;
}


Measured memory_bytes: 5604
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vll A(N);
    REP(i, N) cin >> A[i];

    sort(ALL(A));

    ll m = A[N - 1];
    A.pop_back();

    ll k;
    if (m & 1) {
        ll k1 = 0, k2 = INF;

        REP(i, N - 1) {
            if (A[i] <= (m - 1) / 2) k1 = max(k1, A[i]);
            else k2 = min(k2, A[i]);
        }

        k = (m - 1) / 2 - k1 < k2 - (m + 1) / 2 ? k1 : k2;
    } else {
        ll k1 = 0, k2 = INF;

        REP(i, N - 1) {
            if (A[i] <= m / 2) k1 = max(k1, A[i]);
            else k2 = min(k2, A[i]);
        }

        k = m / 2 - k1 < k2 - m / 2 ? k1 : k2;
    }

    cout << m << " " << k << endl;
    
}


Measured memory_bytes: 3944
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

pair<ll, ll> cost[301];

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

    ll N, M, L;
    cin >> N >> M >> L;
    struct Edge {
        Edge(ll t, ll c) : to(t), cost(c) {}
        ll to, cost;
    };
    vector<vector<Edge>> edges(N);
    for (ll i = 0; i < M; i++) {
        ll A, B, C;
        cin >> A >> B >> C;
        A--; B--;
        edges[A].emplace_back(B, C);
        edges[B].emplace_back(A, C);
    }

    ll Q;
    cin >> Q;
    vector<vector<pair<ll, ll>>> query_from(N);
    for (ll i = 0; i < Q; i++) {
        ll s, t;
        cin >> s >> t;
        s--; t--;
        query_from[s].push_back({ t, i });
    }

    vector<ll> ans(Q);

    constexpr ll INF = LLONG_MAX / 10;
    struct Element {
        ll node, refueling_num, curr_l;
        bool operator<(const Element& rhs) const {
            return (refueling_num != rhs.refueling_num ? refueling_num < rhs.refueling_num : curr_l > rhs.curr_l);
        }
        bool operator>(const Element& rhs) const {
            return (refueling_num != rhs.refueling_num ? refueling_num > rhs.refueling_num : curr_l < rhs.curr_l);
        }
    };
    priority_queue<Element, vector<Element>, greater<Element>> pq;

    for (ll i = 0; i < N; i++) {
        if (query_from.empty()) {
            continue;
        }

        for (ll j = 0; j < N; j++) {
            cost[j] = { INF, INF };
        }

        cost[i] = { 0, L };
        pq.push({ i, cost[i].first, cost[i].second });
        while (!pq.empty()) {
            Element top = pq.top();
            pq.pop();
            if (top.refueling_num > cost[top.node].first
                || (top.refueling_num == cost[top.node].first && top.curr_l > cost[top.node].second)) {
                continue;
            }

            for (const Edge& e : edges[top.node]) {
                ll refueling_num = (top.curr_l >= e.cost ? top.refueling_num : top.refueling_num + 1);
                ll curr_l = (top.curr_l >= e.cost ? top.curr_l - e.cost : L - e.cost);
                if (curr_l < 0) {
                    continue;
                }

                pair<ll, ll> p = make_pair(refueling_num, curr_l);
                if (p.first < cost[e.to].first
                    || (p.first == cost[e.to].first && p.second > cost[e.to].second)) {
                    cost[e.to] = p;
                    pq.push({ e.to, p.first, p.second });
                }
            }
        }
        
        for (const pair<ll, ll>& q : query_from[i]) {
            ans[q.second] = cost[q.first].first;
        }
    }

    for (ll i = 0; i < Q; i++) {
        cout << (ans[i] == INF ? -1 : ans[i]) << endl;
    }
}

Measured memory_bytes: 6016
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
static const int Max = 100;
static const int Infinit = 1000000; // ??????
static const int Nil = -1; // 

enum Status {
	Not_Searched = 0,
	Searched = 1,
	Mts = 2 
};

int n;
int M[Max][Max] = {};
Status st[Max] = {}; 
int min_cost[Max] = {}; // i ??????????????????????????§???????°??????????
int parent[Max] = {}; // ??????index

int prim_search() {
	for (int i = 0; i < n; i++) {
		min_cost[i] = Infinit;
		parent[i] = -1;
		st[i] = Not_Searched;
	}
	min_cost[0] = 0;

	while (1) {
		int mincost = Infinit;
		int mincost_idx = -1;

		for (int i = 0; i < n; i++) {
			if (st[i] != Mts && min_cost[i] < mincost) {
				mincost = min_cost[i];
				mincost_idx = i;
			}
		}
		if (mincost_idx == -1) {
			break;
		}
		st[mincost_idx] = Mts;
		for (int i = 0; i < n; i++) {
			if (st[i] != Mts && M[mincost_idx][i] != Infinit) {
				if (min_cost[i] > M[mincost_idx][i]) {
					min_cost[i] = M[mincost_idx][i];
					parent[i] = mincost_idx;
					st[i] = Searched;
				}
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (parent[i] != Nil) sum += M[i][parent[i]];
	}
	return sum;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int e;
			cin >> e;
			M[i][j] = (e == -1) ? Infinit : e;
		}
	}

	cout << prim_search() << endl;
	return 0;
}

Measured memory_bytes: 3056
n=int(input())
mx = 0
t=[]
d={}
for i in range(n):
	s=input()
	t+=[s]
	d[s] = d.get(s,0)+1
	mx = max(mx,d[s])
	
v=[]
d2={}
for s in t:
	if(d[s]==mx and d2.get(s,0)==0):
		v+=[s]
		d2[s] = d2.get(s,0)+1
	
v.sort()
for s in v:
	print(s)


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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b<c+d) {
    cout << "Right" <<endl;
  }
  else if(a+b==c+d){
    cout <<"Balanced" <<endl;
  }
  else if(a+b>c+d){
    cout<< "Left"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define bash push_back
#define all(x) x.begin(),x.end()
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,-1,1,-1,1};
const int INF=1 << 30;
bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vit;
typedef map<string,int> mstit;
typedef priority_queue<int> pqit;
map <int ,int> num[100005];
int pas[100005];
void change(int x){
  int a=x;
  int q=6;
  iFOR(i,1,7){
    a/=10;
    if(!a){
      q=6-i;
      break;
    }
  }
  FOR(i,q) cout <<'0';
  cout <<x;
}

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,m;
  int p[100005],y[100005];
  cin >>n>>m;
  vector<pii> pairs(m);
  FOR(i,m){
    cin >>p[i] >> y[i];
    pairs[i]=make_pair(y[i],p[i]);
  }
  sort(all(pairs));
  FOR(i,m){
    int a= pairs[i].second;
    int b =pairs[i].first;
    num[a][b]=pas[a]+1;
    pas[a]++;
  }
  FOR(i,m){
    int qq=p[i];
    int ww=y[i];
    change(qq);
    change(num[qq][ww]);
    cout <<"\n";
  }
  

  return 0;
}


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

int A[100009], L[100009], R[100009], LL[100009], RR[100009];

struct seg {
    vector<int> T;
    void upd(int idx, int s, int e, int p, int v) {
        if(p < s || e < p) return;
        if(s == e) {
            T[idx] = v;
            return;
        }
        int m = s+e >> 1;
        upd(idx*2, s, m, p, v);
        upd(idx*2+1, m+1, e, p, v);
        T[idx] = max(T[idx*2], T[idx*2+1]);
    }
    int get(int idx, int s, int e, int l, int r) {
        if(r < s || e < l) return -1e9;
        if(l <= s && e <= r) return T[idx];
        int m = s+e >> 1;
        return max(get(idx*2, s, m, l, r), get(idx*2+1, m+1, e, l, r));
    }
    seg(int N) {
        T.resize(4*N);
    }
};

int main() {
    int N; scanf("%d",&N);
    seg ST(N);
    for(int i=1; i<=N; i++) {
        scanf("%d",&A[i]);
        ST.upd(1, 1, N, i, A[i]);
        L[i] = 0; R[i] = N+1;
    }
    vector<int> S;
    for(int i=1; i<=N; i++) {
        while(S.size() && A[S.back()] < A[i]) {
            R[S.back()] = i;
            S.pop_back();
        }
        S.push_back(i);
    }
    S.clear();
    for(int i=N; i>=1; i--) {
        while(S.size() && A[S.back()] < A[i]) {
            L[S.back()] = i;
            S.pop_back();
        }
        S.push_back(i);
    }
    for(int i=1; i<=N; i++) {
        int l = 1, r = L[i] - 1, f = 0;
        while(l <= r) {
            int m = l+r >> 1;
            if(ST.get(1, 1, N, m, L[i]-1) > A[i]) l = m+1, f = m;
            else r = m-1;
        }
        LL[i] = f;
        l = R[i] + 1, r = N, f = N+1;
        while(l <= r) {
            int m = l+r >> 1;
            if(ST.get(1, 1, N, R[i]+1, m) > A[i]) r = m-1, f = m;
            else l = m+1;
        }
        RR[i] = f;
    }
    long long ans = 0;
    for(int i=1; i<=N; i++) {
        if(L[i] != 0) ans += 1LL * A[i] * (L[i] - LL[i]) * (R[i] - i);
        if(R[i] != N+1) ans += 1LL * A[i] * (RR[i] - R[i]) * (i - L[i]);
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 4216
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define modn 1000000007

#define SZ 300005
using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a > 8 || b > 8) cout<<":(";
    else cout<<"Yay!";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

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

    vector<ll> h(n);
    rep2(i, n) cin(h[i]);

    vector<ll> dp(n);
    dp[0] = 0;

    rep3(i, 1, n) {
        ll m = LLONG_MAX;

        erep3(j, 1, k) {
            ll index = i - j;

            if (index >= 0) {
                ll cost = dp[index] + abs(h[i] - h[index]);
                if (cost < m) m = cost;
            }
        }

        dp[i] = m;
    }

    print(dp[n - 1]);
    return 0;
}

Measured memory_bytes: 1792
// Author: 23forever
#include <bits/stdc++.h>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
const int MAXN = 3000;
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

char a[MAXN + 5], b[MAXN + 5];
int dp[MAXN + 5][MAXN + 5], n, m;
pii cur;
vector < char > vec;

void init() {
  scanf("%s%s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  //freopen("test.out", "w", stdout);
#endif  
  init();

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i] == b[j]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }

  pii cur = mp(n, m);
  while (cur.fi && cur.se) {
    if (a[cur.fi] == b[cur.se]) {
      vec.pb(a[cur.fi]);
      --cur.fi;
      --cur.se;
    } else {
      if (dp[cur.fi][cur.se - 1] > dp[cur.fi - 1][cur.se]) {
        --cur.se;
      } else {
        --cur.fi;
      }
    }
  }
  
  for (int i = vec.size() - 1; ~i; --i) putchar(vec[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 35456
class Partition:
    def partion(self, a, p, r): 
        x = a[-1]
        i = p - 1
        for j in range(p, r):
            if a[j] <= x:
                i += 1
                a[i], a[j] = a[j], a[i]
        # a[i + 1], a[-1] = a[-1], a[i + 1]
        return((a, i))

if __name__ == '__main__':
    n = int(input().rstrip())
    a = [int(x) for x in input().rstrip().split(" ")]
    x = Partition()
    a, i = x.partion(a, 0, n)
    res = []
    for j in range(len(a)):
        if j == i:
            res.append("[{}]".format(a[j]))
        else:
            res.append(str(a[j]))
    print(" ".join(res))

Measured memory_bytes: 18744
#include <cstdio>
#include <cctype>
#include <bitset>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
inline int gc()noexcept { return getchar_unlocked(); }
inline int input()noexcept {
	int v = 0; char c = gc();
	for (; isdigit(c); c = gc()) {
		v *= 10;
		v += c - '0';
    }
	return v;
}
bitset<100002> flag;
int main() {
  int n = input(), m = input();
  vector<int> cnt(n);
  int a1 = 0, a2 = 0;
  rep(i, m) {
    int p = input(); --p;
    char c = gc(); gc(); gc();
    if (!flag.test(p)) {
      switch(c) {
        case 'A':
          flag.set(p);
          ++a1;
          break;
        case 'W':
          ++cnt[p];
          break;
      }
    }
  }
  rep(i, n)if (flag.test(i))a2 += cnt[i];
  printf("%d %d", a1, a2);
}

Measured memory_bytes: 640
#include <iostream>

#define MAX_H 50
#define MAX_W 50

int H, W;
int dw[4] = {1, 0, -1, 0}, dh[4] = {0, 1, 0, -1};
char s[MAX_H][MAX_W];

bool judge(int h, int w) {
    bool flag=false;
    for (int i=0; i<4; i++) {
        int nw=w+dw[i], nh=h+dh[i];
        if (0<=nw && nw<W && 0<=nh && nh<H && s[nh][nw] == '#') flag=true;
    }
    return flag;
}

void solve() {
    bool flag = true;
    for (int h=0; h<H; h++) {
        for (int w=0; w<W; w++) {
            if (s[h][w] == '#') {
                flag = judge(h, w);
            }
            if (!flag) break;
        }
        if (!flag) break;
    }

    if (flag) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}

int main() {
    std::cin >> H >> W;
    for (int h=0; h<H; h++) {
        for (int w=0; w<W; w++) {
            std::cin >> s[h][w];
        }
    }

    solve();

    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll L,R;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>L>>R;
	
	R=min(R,L+2019);
	
	ll mi=2019;
	for(ll a=L;a<=R;a++) for(ll b=a+1;b<=R;b++) mi=min(mi,a*b%2019);
	cout<<mi<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
l=[0]*123
while True:
    try:
        a=str(input())
    except:
        break
    m=list(a)
    i=0
    while True:
        try:
            b=m[i]
            l[ord(b)]+=1
            i+=1
        except:
            break
k=97
for j in range(26):
    print(chr(k),':',l[k]+l[k-32])
    k+=1


Measured memory_bytes: 5568
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
char MM[1005][1003];
int MO[1005][1003]={},MJ[1005][1003]={},MI[1005][1003]={};
int main(){

	string str;
	int y,x,n;
	cin>>y>>x;
	cin>>n;
	for(int i=1;i<=y;i++)
	{cin>>str;
	for(int j=0;j<str.size();j++)
		{
			MM[i][j+1]=str[j];
			if(str[j]=='O')MO[i][j+1]++;
			if(str[j]=='J')MJ[i][j+1]++;
			if(str[j]=='I')MI[i][j+1]++;

			MO[i][j+1]+=MO[i][j];
			MJ[i][j+1]+=MJ[i][j];
			MI[i][j+1]+=MI[i][j];


	}
	}
	for(int I=0;I<n;I++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		int J=0,U=0,II=0;
		for(int i=a;i<=c;i++){
			U+=MO[i][d]-MO[i][b-1];
			J+=MJ[i][d]-MJ[i][b-1];
			II+=MI[i][d]-MI[i][b-1];
			/*
			for(int j=b;j<=d;j++){
				if(MM[i][j]=='O')U++;
				if(MM[i][j]=='J')J++;
				if(MM[i][j]=='I')II++;

			//	cout<<MM[i][j];
			}*/
		//	cout<<endl;
		}

			cout<<J<<" "<<U<<" "<<II<<endl;
	}
	return 0;
}

Measured memory_bytes: 13992
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define  fill(st,et,val,arr) for(int i=st;i<=et;i++)arr[i]=val;
template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}
 
const int M=1e9 + 7;
const int MAX=1e5+7;
using namespace std;
bool comp(int a,int b)
{
	return a>b;
}
int32_t main() 
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	string s;cin>>s;
	if(n%2)
	{
		cout<<"No"<<endl;
		return 0;
	}
	int p1=0;
	int p2=n/2;
	while(p2<n)
	{
		if(s[p1++]!=s[p2++])
		{
			cout<<"No"<<endl;
		    return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}
 















 
 

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
N = int(input())
ans = 0
 
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if a * 500 + b * 100 + c * 50 == N:
        ans += 1
 
print(ans)

Measured memory_bytes: 9080
K,N= map(int, input().split())
x = list(map(int, input().split()))
x.append(K+x[0])
sabun=[]
for i in range(N):
  sabun.append(x[i+1]-x[i])
newsabun=sorted(sabun)[::-1]
print(K-newsabun[0])

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

using namespace std;

int main(){

  int a,b,c;
  
  vector <int> num;

  cin >> a >> b >> c;

  num.push_back(a);
  num.push_back(b);
  num.push_back(c);

  sort(num.begin(),num.end());

  for(int i=0;i<3;i++){
    cout <<num[i];
    if(i!=2)
      cout<<" ";
  }

  cout <<endl;

  return 0;

}

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

int main(){
  int N; std::cin >> N;
  std::vector<int> v(N);
  for(auto i=0; i<N; ++i){
    std::cin >> v[i];
  }
  auto r = 0;
  for(auto i=0; i<N-1; ++i){
    if(v[i] == i+1){
      std::swap(v[i], v[i+1]);
      ++r;
    }
  }
  if(v[N-1] == N)
    ++r;
  std::cout << r << '\n';
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef long long LL;
const int MaxN = 2e5;

int n;
LL a[55];
LL ans[55];
LL cnt[55];
int main()
{
	while(scanf("%d", &n) != EOF)	
	{
		for(int i = 1; i <= n; i++)
			scanf("%lld", &a[i]);
		bool flag = 0;
		LL ans = 0;
		LL tot = 0;
		while(true)
		{
			flag = 0;
			tot = 0;
			for(int i = 1; i <= n; i++) {
				cnt[i] = a[i] / n;
				a[i] = a[i] % n;
				ans += cnt[i];
				tot += cnt[i];
			}
			for(int i = 1; i <= n; i++) {
				a[i] += tot - cnt[i];
				if(a[i] >= n) flag = 1;
			}
			if(flag == 0) break;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 128