akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

void make_list(int *list);
void sort_list(int *list);
void search(int *list, int X);

int main(void)
{
	int list[50];
	int X;
	
	scanf("%d", &X);
	if (X < 4){
		printf("%d\n", 1);
		return (0);
	}
	else if (X == 1000){
		printf("1000\n");
		return (0);
	}
	
	make_list(list);
	sort_list(list);
	search(list, X);
	
	return (0);
}

void make_list(int *list)
{
	int i = 0;
	int n = 2;
	int data = 4;
	
	while (n < 32){
		while (data < 1000){
			list[i] = data;
			data *= n;
			i++;
		}
		n++;
		data = n * n;
	}

}
	
void sort_list(int *list)
{
	int i;
	int D = 0;
	int tmp;
	while (D == 0){
		D = 1;
		i = 0;
		while (i < 49){
			if (list[i] < list[i + 1]){
				tmp = list[i];
				list[i] = list[i + 1];
				list[i + 1] = tmp;
				D = 0;
			}
			i++;
		}
	}
	
}

void search(int *list, int X)
{
	int i;
	
	for (i = 0; i < 50; i++){
		 if (list[i] <= X){
		 	printf("%d\n", list[i]);
			break;
		 }
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

int main() {
  int l, n;
  cin >> n >> l;
  vector<string> S(n);
  for (auto& s : S)
    cin >> s;
  sort(S.begin(), S.end());
  cout << accumulate(S.begin(), S.end(), string()) << "\n";

  return 0;
}

         


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<string> vec(H+2);
  for (int i=0; i < W + 2; i++){
  vec.at(0) = vec.at(0) + "#";
    vec.at(H + 1) = vec.at(H + 1) + "#";
  }
  
  for (int i=0; i < H; i++){
  cin >> vec.at( i+1 );
    vec.at( i+1 ) = "#" + vec.at(i+1) + "#";
  }
  
  for (int i=0; i < H + 2; i++){
  cout << vec.at(i) << endl;
  }
  
  
}
 

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

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    bool flag=true;
    for (int i=0; i<n; i++){
        cin >> A.at(i);
        if(A.at(i)%2==0){
            if(A.at(i)%3!=0 && A.at(i)%5!=0) flag=false;
        }
    }
    if(flag==true) cout << "APPROVED";
    else cout << "DENIED";
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}



int main2() {
  int N = nextInt();
  deque<int> b;
  REP(i, N) {
    if (i % 2 == 0) b.push_back(nextInt());
    else b.push_front(nextInt());
  }
  if (b.size() % 2 == 1) reverse(ALL(b));
  REP(i, b.size()) {
    if (i > 0) printf(" ");
    printf("%d", b[i]);
  }
  printf("\n");
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 2944
from sys import stdin
import string
N = int(stdin.readline().rstrip())
alpha = string.ascii_lowercase
ans = ""

  
tmp = N
while N != 0:
    tmp = N % 26
    ans += alpha[tmp-1]
    if tmp == 0:
        N = (N-1) // 26
    else:
        N //= 26

print(ans[::-1])

Measured memory_bytes: 9972
#include <iostream>
#include <string>
#include <memory>
using namespace std;

class Set
{
private:
    struct Node
    {
        Node(shared_ptr<Node> par_, shared_ptr<Node> left_, shared_ptr<Node> right_, int val) :
            par(par_), left(left_), right(right_), key(val){}
        shared_ptr<Node> par, left, right;
        int key;
    };
    
    void preorder(shared_ptr<Node>& x){
        cout << ' ' << x->key;
        if(x->left != nullptr){
            preorder(x->left);
        }
        if(x->right != nullptr){
            preorder(x->right);
        }
    }
    
    void inorder(shared_ptr<Node>& x){
        if(x->left != nullptr){
            inorder(x->left);
        }
        cout << ' ' << x->key;
        if(x->right != nullptr){
            inorder(x->right);
        }
    }
    
public:
    Set():size(0){}
    void insert(int val){
        if(size == 0){
            root = make_shared<Node>(nullptr, nullptr, nullptr, val);
        } else {
            shared_ptr<Node> y = nullptr;
            shared_ptr<Node> x = root;
            while(x != nullptr){
                y = x;
                if(val < x->key){
                    x = x->left;
                } else {
                    x = x->right;
                }
            }
            
            if(val < (y->key)){
               y->left = make_shared<Node>(y,nullptr,nullptr,val);
            } else {
               y->right = make_shared<Node>(y,nullptr,nullptr,val);
            }
        }
        ++size;
    }

    bool find(int val){
        if(size == 0) return false;
        shared_ptr<Node> x = root;
        while(x != nullptr){
            if(x->key == val){
                return true;
            }
            if(val < x->key){
                x = x->left;
            } else {
                x = x->right;
            }
        }
        return false;
    }

    void print(){
        if(size == 0) return;
        inorder(root);
        cout << endl;
        preorder(root);
        cout << endl;
    }
    
private:
    shared_ptr<Node> root;
    int size;
};

int main()
{
    ios_base::sync_with_stdio(false);
    int n, k;
    string s;
    Set set;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> s;
        if(s == "insert"){
           cin >> k;
           set.insert(k);
        } else if(s == "find"){
            cin >> k;
            cout << (set.find(k) ? "yes" : "no") << endl;
        } else if(s == "print"){
            set.print();
        }
    }
}

Measured memory_bytes: 38736
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            for (char c = 'a'; c <= 'z'; c++) {
                int l = 0;
                int r = 0;
                int count = (s[l] == c ? 1 : 0);
                while (r < s.length + 1) {
                    if (l != r && count > (r - l + 1) / 2) {
                        out.printf("%d %d\n", ++l, ++r);
                        return;
                    }
                    if (l == r || s[r] != c) {
                        if (++r == s.length)
                            break;
                        if (s[r] == c)
                            count++;
                    } else if (s[l++] == c)
                        count--;
                }
            }
            out.println("-1 -1");
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isPrintableChar(int c) {
            return c >= 33 && c <= 126;
        }

        public String next() {
            StringBuilder sb = new StringBuilder();

            int b = readByte();
            while (!isPrintableChar(b))
                b = readByte();

            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }

            return sb.toString();
        }

    }
}



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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

int n; ll exponent;
const ll MOD = 1e9+7;
void mult(vector<vll> &A, vector<vll> &B, vector<vll> &C) {
	M00(i, n) {
		M00(j, n) {
			C[i][j] = 0;
			M00(k, n) {
				C[i][j] += A[i][k] * B[k][j];
				C[i][j] %= MOD;
			}
		}
	}
}

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin >> n >> exponent;
	ll k = exponent;

	vector<vll> base(n, vll(n)), res(n, vll(n)), temp(n, vll(n));
	M00(i, n) M00(j, n) cin >> base[i][j];
	M00(i, n) res[i][i] = 1;
	
	while(k) {
		if(k & 1) {
			mult(base, res, temp);
			M00(i, n) M00(j, n) res[i][j] = temp[i][j];
		}
		k /= 2;
		mult(base, base, temp);
		M00(i, n) M00(j, n) base[i][j] = temp[i][j];
	}
	ll ans = 0;
	M00(i, n) {
		M00(j, n) {
			ans += res[i][j];
		}
	}
	ans %= MOD;
	finish(ans);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
//int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};




 
int main() {
    int N;
    cin >> N;
    REP(i, N){
        int x;
        cin >> x;
        if(x & 1){
            print("first");
            return 0;
        }
    }
    print("second");
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>

int main(){
  int K;
  int count = 0;
  std::string S,b;

  std::cin >> K >> S;

  size_t size = S.length();

  if(size<=K){
    std::cout << S << std::endl;
  }else{
    while(count<K){
      b += S[count];
      //std::cout<< S[count] << std::endl;
      //std::cout<< b << std::endl;
      count++;
    }
    std::cout << b << "..."<< std::endl;
  }

}


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;

class Program
{
    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        double[] nums = new double[n];
        double sum = 0;

        for (int i = 0; i < n; i++)
            nums[i] = double.Parse(s[i]);

        for (int i = 0; i < n; i++)
            sum += 1.0 / nums[i];

        Console.WriteLine(1.0 / sum);
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    vector<long long> a(n), t(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> a[i];
        t[i] = (n - i - 1) - a[i];
    }
    sort(t.begin(), t.end());
    long long ans = 0;
    for(int i = n - 1; i >= 0; --i)
    {
        auto f = lower_bound(t.begin(), t.end(), a[i] + (n - 1 - i));
        auto l = upper_bound(t.begin(), t.end(), a[i] + (n - 1 - i));
        ans += l - f;
    }
    cout << ans;
}


Measured memory_bytes: 6368
#include<stdio.h>

int main()
{
	char s[9]; 
	int c = 0, i = 0;
	scanf("%s", s);
	for (; i < 3; i++)
	{
		if (s[i] == '1')
		{
			c++;
		}
	}
	printf("%d", c);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<stack>
#include<algorithm>
#include<list>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
int main(){
	int A,B,C,D;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	if(A+B>C+D)
		printf("Left\n");
	else if(A+B<C+D)
		printf("Right\n");
	else
		printf("Balanced\n");
	cin>>A;
	return 0;
}

Measured memory_bytes: 256
N, T = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,b)]
ls.sort(key=lambda x:x[0])

dp = [[0]*(T) for i in range(N+1)]

for i in range(N):
  a,b = ls[i]
  for j in range(T-1, a-1, -1):
    dp[i+1][j] = max(dp[i][j], dp[i][j-a]+b)

last = [0]*N
last[-1] = ls[-1][1]
for i in range(N-2, -1, -1):
  last[i] = max(last[i+1], ls[i][1])

ans = 0

for i in range(1,N+1):
  ans = max(ans, max(dp[i-1])+last[i-1])

print(ans)


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

#define lld long long
#define pii pair<int,int>
#define pb push_back
#define next nextt
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define Mod 1000000007

using namespace std;

int N,P;

int main(){
	scanf("%d %d",&N,&P);
	lld ans,cnt1,cnt2;
	cnt1 = cnt2=  0;
	for(int i=1; i<=N; i++){
		int x;
		scanf("%d",&x);
		if(x%2 == 0) cnt1++;
		else cnt2++;
	}
	ans = 1;
	if(cnt2 > 0) ans *= ((lld)1<<(cnt2-1));
	ans *= ((lld)1<<cnt1);
	if(P == 1) ans = ((lld)1<<(lld)(N))-ans;
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
H[0] -= 1
count = 0
for i in range(1, N):
    if H[i] > H[i - 1]:
        H[i] -= 1 

for i in range(1, N):
    if H[i] <H[i - 1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 14252
N, A = map(int, input().split())
X = [int(_) - A for _ in input().split()]

dic = {0: 1}
#print(dic.items())

for x in X:
    for i, j in list(dic.items()):
        #print(i, j)
        #print(dic)
        dic[x + i] = dic.get(x+i, 0) + j
print(dic[0] - 1)

Measured memory_bytes: 3188
import java.util.*;

public class Main {
    private class Data {
        int id, value;

        public Data(int id, int value) {
            this.id = id;
            this.value = value;
        }
    }

    public void main(Scanner sc) {
        int n = sc.nextInt();
        Data data[] = new Data[n];
        for (int i = 0; i < n; i++) {
            data[i] = new Data(i, sc.nextInt());
        }

        Arrays.sort(data, (d1, d2) -> d1.value - d2.value);
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt += Math.abs((data[i].id - i)) % 2;
        }

        System.out.println(cnt / 2);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 63400
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int main(){
	int x, a, b;
  cin >> x >> a >> b;
  if(abs(x-a)>abs(x-b))puts("B");
  else puts("A");
	return 0;
}


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

int main(void) {
	int n;
	cin >> n;
	map<int, int> m;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		m[a]++;
	}
	int ans = 0;
	for (int i = 1; i < 100001; i++) {
		int x = m[i-1] + m[i] + m[i+1];
		ans = max(ans, x);
		
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,x;
    vector<int>v;
    deque<int>d;
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&x);
        if (x==0)
            k--;
        else
            v.push_back(x);
    }
    if(k)
    {
        for(int i=0; i<k; i++)
        {
            d.push_back(v[i]);
        }
        int x=d.front();
        int y=d.back();
        long long ans;
        if(y<0)
            ans=abs(x);
        else if(x>0)
            ans=abs(y);
        else
        {
            if(abs(x)<abs(y))
                ans=(2*abs(x))+y;
            else
                ans=abs(x)+(2*abs(y));
        }
        //cout<<ans<<endl;
        for(int i=k; i<v.size(); i++)
        {
            d.pop_front();
            d.push_back(v[i]);
            x=d.front();
            y=d.back();
            //cout<<x<<" "<<y<<endl;
            long long int an;
            if(y<0)
                an=abs(x);
            else if(x>0)
                an=abs(y);
            else
            {
                if(abs(x)<abs(y))
                    an=(2*abs(x))+y;
                else
                    an=abs(x)+(2*abs(y));
            }
            if(an<ans)ans=an;
          //  cout<<ans<<endl;
        }
        printf("%lld",ans);
    }
    else printf("0");
}


Measured memory_bytes: 1016
// G++ MACRO.CPP -STD=C++17
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair
 
 
int main(){
  CIN(n);
  VC2(n,a,b);

  if(a==b)EN(0);

  ll cou = LINF;
  REP(i,n)
    if(a[i] > b[i])
      cou = min(cou,b[i]);

  COUT(accumulate(ALL(a),0LL) - cou);



  return 0;
}

Measured memory_bytes: 512
#include<iostream>

int main(){
	int a=1,b=1,i,n;

	for(i=1;i<=9;i++){
		for(n=1;n<=9;n++){
		std::cout<<a<<"x"<<b<<"="<<a*b<<std::endl;
		b=n+1;
			}
		a=i+1;
		b=1;
		}
	
	return 0;
	}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

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

    // 入力
    int n, a;
    cin >> n >> a;

    // 処理
    // 出力
    cout << n * n - a << endl;

    return 0;
}


Measured memory_bytes: 256
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define ld long double
    #define ss(x) scanf("%s",&x)
    #define sc(x) scanf("%c",&x)
    #define sd(x) scanf("%Lf",&x)
    #define si(x) scanf("%lld",&x)
    #define ps(x) printf("%s\n",x)
    #define pc(x) printf("%c\n",x)
    #define pd(x) printf("%Lf\n",x)
    #define pi(x) printf("%lld\n",x)
    #define all(x) x.begin(),x.end() 
    #define rall(x) x.rbegin(),x.rend()
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
    
    #define XOX 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int INF = 1e15;
    const int MAX = 2e6 + 7;
    const int MOD =  1000000007;
    const long double PI  =3.141592653589793238463;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ DEB $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;


    vector<string> vec_splitter(string s) 
    {
        for(char& c: s) c = c == ','?  ' ': c;
        stringstream ss; ss << s;
        vector<string> res;
        for(string z; ss >> z; res.push_back(z));
        return res;
    }
    void debug_out(vector<string> args, int idx) { cerr << endl; }
    template <typename Head, typename... Tail>
    void debug_out(vector<string> args, int idx, Head H, Tail... T) 
    {
        if(idx > 0) cerr << ", ";
        stringstream ss; ss << H;
        cerr << args[idx] << " = " << ss.str();
        debug_out(args, idx + 1, T...);
    }
    
    #ifdef XOX
    #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
    #else
    #define debug(...) 42
    #endif

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    int cnt,x,nn;
    int mp[MAX];
    void solve()
    {
        cin>>n>>k;
        fo(i,0,k)
        {
            cin>>nn;
            fo(j,0,nn)
            {
                cin>>x;
                mp[x]++;
            }
        }

        fo(i,1,n+1)if(!mp[i])cnt++;
        cout<<cnt<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);

        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 3660
#include <iostream>
#include <cmath>


int main()
{
    int K;
    std::cin >> K;

    int n = 7;
    int i = 1;

    while (n % K != 0) {
        n = (10 * n + 7) % K;
        i++;
        if (i > K) {
            std::cout << "-1" << std::endl;
            return 0;
        }
    }

    std::cout << i << std::endl;
    
    return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

vector<int> bestSeq;
int N,M,Q;

int main() {
    // input, ready
    cin >> N >> M >> Q;
    vector<int> aList(Q);
    vector<int> bList(Q);
    vector<int> cList(Q);
    vector<int> dList(Q);
    for (int i=0; i<Q; i++) {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        aList[i] = a;
        bList[i] = b;
        cList[i] = c;
        dList[i] = d;
    }

    // resolve
    vector<char> seq_seed(N+M-1,'1');
    for (int i=0; i<M-1; i++) seq_seed[i] = '0';
    // 全探索
    ll ans = 0;
    do {
        ll tmp = 0;
        int zero_cnt = 0;
        vector<int> seq;
        for (int i=0; i<N+M-1; i++) {
            if (seq_seed[i] == '0') zero_cnt++;
            else seq.push_back(zero_cnt);
        }
        seq.push_back(zero_cnt);
        for (int i=0; i<Q; i++) {
            if (seq[bList[i]-1] - seq[aList[i]-1] == cList[i]) tmp += dList[i];
        }
        ans = max(ans,tmp);
    } while (next_permutation(seq_seed.begin(), seq_seed.end()));

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int N, L, sum = 0, min = -200, temp;
    cin >> N >> L;
    Fp(i, 1, N + 1){
        temp = L + i - 1;
        sum += temp;
        if(abs(min) > abs(temp)) min = temp;
    }
    sum -= min;
    cout << sum << endl;
}



Measured memory_bytes: 384
def judge?(x1, x2)
  dis = x1.zip(x2).map{|e1, e2| (e1 - e2)**2}.inject(:+)
  (1..dis).any?{|n| n**2==dis}
end

n, d = gets.split.map(&:to_i)
x_arr = n.times.map{gets.split.map(&:to_i)}
puts x_arr.combination(2).count{|x1, x2| judge?(x1, x2)}

Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	cout << lcm(2, n) << endl;
	
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 5e5 + 10;
const ll mod = 1e9 + 7;
int n, m, w;
int r[N], c[N];
vector<int>vc[N];
int main() {
	scanf("%d%d%d", &n, &m, &w);
	for (int i = 0; i < w; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		vc[u].push_back(v);
		c[v]++;
		r[u]++;
	}
	int tmp = 0, ans = 0, ctmp = 0;
	for (int i = 1; i <= m; i++)tmp = max(tmp, c[i]);
	for (int i = 1; i <= m; i++)if (c[i] == tmp)ctmp++;
	for (int i = 1; i <= n; i++) {
		int cnt = 0;
		for (int j : vc[i])if (c[j] == tmp)cnt++;
		int res;
		if (cnt == ctmp)res = r[i] + tmp - 1;
		else res = r[i] + tmp;
		ans = max(ans, res);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 27240
N,K = map(int,input().split())
A = list(map(int,input().split()))

ans = float('inf')
for status in range(1<<N):
    cnt = 0
    tmp = 0
    std = 0
    for mask in range(N):
        if (1<<mask)&status:
            cnt += 1
            if std >= A[mask]:
                tmp += std - A[mask] + 1
                std += 1
        
        std = max(std,A[mask])
    if cnt >= K:
        ans = min(ans,tmp)
    
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main() {
   int n,d;
   cin>>n>>d;
   string str;
   if(d!=100)
   str=to_string(d);
   else str+=to_string(101);
   for(int i=0;i<n;i++)
   str+="00";
   cout<<str;
}


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

int main(void){
    int X,Y;
    cin >> X >> Y;
    bool can = false;
    for(int i=0;i<=X;i++){
        int turu = i;
        int kame = X - turu;
        int sum = turu*2 + kame*4;
        if(sum == Y) can = true;
    }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, a[101010];

int main() {
	cin >> n;
	REP(i, n)cin >> a[i];
	REP(i, n)cout << a[i] << (i != n - 1 ? " " : "\n");
	for (int i = 1; i < n; i++) {
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		REP(i, n)cout << a[i] << (i != n - 1 ? " " : "\n");
	}
}


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

typedef long long LL;

int main(){
    LL K, A, B, KK, ans;
    cin >> K >> A >> B;
    if(B - A <= 2){
        cout << K + 1 << endl;
    }else{
        KK = max((LL)0, (K-(A-1))/2);
        ans = KK * (B - A) + (K - KK*2) + 1;
        cout << ans << endl;
    }
    return 0;

}

Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

int main(){
  int n,a,b,c,r;
  cin >> n >> a >> b;
  REP(j,n){
    int i = j+1;
    c = i%10 + (i/10)%10 + (i/100)%10 + (i/1000)%10 + (i/10000)%10;
    if (a<=c&&c<=b) r+=i;
  }
  cout << r;
  return 0;
}

Measured memory_bytes: 256
let n=read_int()open Array;;let a=init n(fun _->Scanf.scanf"%d "(fun e->e))and b=make n 0and c=make 10001 0;;iter(fun e->c.(e)<-c.(e)+1)a;iteri(fun i _->if i<>0then c.(i)<-c.(i)+c.(i-1))c;for i=n-1downto 0do b.(c.(a.(i))-1)<-a.(i);c.(a.(i))<-c.(a.(i))-1;done;print_int b.(0);for i=1to n-1do print_string" ";print_int b.(i);done;print_newline()

Measured memory_bytes: 36148
n, q = map(int, input().split())

S = [[] for _ in range(n)]


for _ in range(q):

    command, *list_num = input().split()

    t = int(list_num[0])

    if   command == "0":
        # push(t, x)
        x = int(list_num[1])

        S[t].append(x)
    elif command == "1":
        # top(t)
        if S[t]:
            print(S[t][-1])
    elif command == "2":
        # pop(t)
        if S[t]:
            S[t].pop()
    else:
        raise



Measured memory_bytes: 13440
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
    u64 N, S;
    cin >> N >> S;

    vector<u64> A(N);
    for(u64 n=0; n<N; n++) cin >> A[n];
    
    vector<vector<s64>> dp(N+1, vector<s64>(S+1, 0));
    u64 mod = 998244353;
    dp[0][0] = 1;
    
    for(u64 i=0; i<N; i++) {
        for(u64 k=0; k<=S; k++) {
            dp[i+1][k] = (dp[i][k] * 2) % mod;
            if(A[i] <= k) {
                dp[i+1][k] = (dp[i+1][k] + dp[i][k-A[i]]) % mod;
            }
        }
    }

    cout << dp[N][S] << endl;
    return 0;
}

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

using namespace std;

int main() {
	int n, aux, total = 0;
	cin >> n;
	
	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	aux = h[0];
	
	for (int i = 0; i < n; i++) {
		if (h[i] >= aux) {
			total++;
			aux = h[i];
		}
	}
	
	cout << total;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,m;
  cin >> n >> m;
  vector<int>h(n);
  rep(i,n) cin >> h[i];
  vector<int>mx(n,0);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    mx[a]=max(mx[a],h[b]);
    mx[b]=max(mx[b],h[a]);
  }
  int cnt=0;
  rep(i,n){
    if(h[i]>mx[i])cnt++;
  }
   cout << cnt << endl;
  return 0;     
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

int A[81][81], B[81][81];
bool dp[81][81][12801];

int main()
{
    int H, W;
    cin >> H >> W;
    rep(i, H) {
        rep(j, W) {
            cin >> A[i][j];
        }
    }

    rep(i, H) {
        rep(j, W) {
            cin >> B[i][j];
        }
    }

    dp[0][0][abs(A[0][0] - B[0][0])] = true;
    rep(i, H) {
        rep(j, W) {
            rep(k, 12801) {
                if (!dp[i][j][k]) continue;
                if (j <= W - 2) {
                    dp[i][j + 1][k + abs(A[i][j + 1] - B[i][j + 1])] = true;
                    dp[i][j + 1][abs(k - abs(A[i][j + 1] - B[i][j + 1]))] = true;
                }
                if (i <= H - 2) {
                    dp[i + 1][j][k + abs(A[i + 1][j] - B[i + 1][j])] = true;
                    dp[i + 1][j][abs(k - abs(A[i + 1][j] - B[i + 1][j]))] = true;
                }
            }
        }
    }

    ll ans = INF;
    rep(k, 12801) {
        if (dp[H - 1][W - 1][k]) {
            ans = k;
            break;
        }
    }

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

Measured memory_bytes: 81280
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;
// const ll INF = 1e18;

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

  ll ans = 0; // 価値の合計の最大値
  REP(k,0,K+1) {  // K回まで
    REP(X,0,k+1) {  // k回の操作のうちX回は詰める (詰めるのは最後でよい)
      REP(l,0,k+1-X) {  // 残りk-X回
        int r = k - X - l;
        if (l + r < X) continue;
        if (l + r > N) continue;  // 合計N個しか取れない
        // 左からl個・右からr個
        vector<ll> D;
        REP(i,0,l) D.push_back(V[i]);
        RREP(i,N,N-r) D.push_back(V[i]);
        sort(ALL(D));
        // Dの小さい方からX個は捨てる (l+r個残る)
        ll s = 0;  // 価値の合計
        REP(i,X,l+r) s += D[i];
        chmax(ans, s);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

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

    //write your code here
    int n;
    cin>> n;
		int k;
		cin>>k;
    vector<int > v(n,0);
    for(int i=0;i<n;i++)  cin>> v[i];
    vector<int > dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0;i<n-1;i++){
      for(int j=1;j<=k;j++ ){
				if(i+j<=n-1){
					dp[i+j]= min(dp[i+j], dp[i]+abs(v[i]- v[i+j]));
				}
			}
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  
  vector<string> vec(H);
  
  for(int i=0; i<H; i++){
    cin >> vec.at(i);
  }
  
  for(int i=0; i<W+2; i++){
    cout << "#";
  }
  
  cout << endl;
  
  for(int i=0; i<H; i++){
    cout << "#" << vec.at(i) << "#" << endl;
  }
  
  for(int i=0; i<W+2; i++){
    cout << "#";
  }
  
  cout << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

from collections import Counter

CA=Counter(A)
CB=Counter(B)

H=[]

for ca in CA:
    if CA[ca]>0 and CB[ca]>0:
        if CA[ca]+CB[ca]>N:
            print("No")
            sys.exit()
        H.append((-(CA[ca]+CB[ca]),ca))

import heapq
heapq.heapify(H)

ANSDICT=dict()

while len(H)>=2:
    c1,x1=heapq.heappop(H)
    c1=-c1

    c2,x2=heapq.heappop(H)
    c2=-c2

    if x1 in ANSDICT:
        ANSDICT[x1].append(x2)
    else:
        ANSDICT[x1]=[x2]

    if x2 in ANSDICT:
        ANSDICT[x2].append(x1)
    else:
        ANSDICT[x2]=[x1]

    CA[x1]-=1
    CA[x2]-=1
    CB[x1]-=1
    CB[x2]-=1

    if CA[x1]>0 and CB[x1]>0:
        heapq.heappush(H,(-(c1-2),x1))

    if CA[x2]>0 and CB[x2]>0:
        heapq.heappush(H,(-(c2-2),x2))

ANS=[-1]*N

for i in range(N):
    a=A[i]
    if a in ANSDICT and len(ANSDICT[a])!=0:
        
        x=ANSDICT[a].pop()
        ANS[i]=x

if H:
    cc,xx=H[0]
    cc=-cc

    for i in range(N):
        if ANS[i]==-1 and A[i]!=xx:
            ANS[i]=xx
            CB[xx]-=1

            if CB[xx]==0:
                break

ind=0
for cb in CB:
    while CB[cb]!=0:
        while ANS[ind]!=-1:
            ind+=1
        ANS[ind]=cb
        CB[cb]-=1

print("Yes")
print(*ANS)


Measured memory_bytes: 83472
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
#else
	#define DEBUG(x) true
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef pair<int,int> P;
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

//res.first*a+res.second*b == 1 となるresを返す (a,bは互いに素)
pair<long long, long long> extgcd(long long a,long long b)
{
	if(b==1){
		return pair<long long, long long>(0,1);
	}
	pair<long long, long long> t=extgcd(b,a%b);
	return pair<long long, long long>(t.second,t.first-a/b*t.second);
}

//modの逆元を返す
long long inverse(long long mod,long long a)
{
	return (extgcd(mod,a).second+mod)%mod;
}

//xCyを返す
long long Cinv(const long long mod, long long x, long long y){
	long long n = 1 ,r = 1;
	for(int i = 0; i < y; i++){
		n = n*(i+1)%mod;
		r = r*(x-i)%mod;
	}
	return r*inverse(mod,n)%mod;
}

const LL mod = 1e9+7;

int main()
{
	ios_init();
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	w--; h--; a--; b--;
	b++;
	LL ans = 0;
	LL c1 = -1, c2 = -1;
	REP(i,h-a){
		if(i == 0){
			c1 = Cinv(mod,b-1+i,i);
			c2 = Cinv(mod,h-i+w-b,w-b);
		}else{
			c1 = c1*(b-1+i)%mod*inverse(mod,i)%mod;
			c2 = c2*inverse(mod,h-(i-1)+w-b)%mod*(h-i+1)%mod;
		}
		ans += c1*c2%mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
#define BUF (55)
#define ll long long 

int h,w;
char s[BUF][BUF];

typedef struct {
	int first;
	int second;
	int num;
}P;

queue<P> q;

int main(void){
	cin >> h >> w;
	int count=0;

	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin >> s[i][j] ;
			if(s[i][j]=='.')count++;
		}
	}

	for(int i=0;i<BUF;i++) s[0][i]='#';
	for(int i=0;i<BUF;i++) s[i][0]='#';
	for(int i=0;i<BUF;i++) s[i][w+1]='#';
	for(int i=0;i<BUF;i++) s[h+1][i]='#';

	P p;
	p.first = 1;
	p.second = 1;
	p.num=1;

	s[p.first][p.second]='#';
	
	q.push(p);
	int f=0;
	while(!q.empty()){
		p=q.front();
		q.pop();
		if(p.first==h && p.second==w){
			f=p.num;
			break;
		}

	    if( s[p.first  ][p.second-1]=='.' ){
			s[p.first  ][p.second-1]= '#';
			q.push({p.first  ,p.second-1,p.num+1});
		}
	    if( s[p.first-1][p.second  ]=='.' ){	
			s[p.first-1][p.second]= '#';
			q.push({p.first-1,p.second  ,p.num+1});
		}
	    if( s[p.first  ][p.second+1]=='.' ){
			s[p.first  ][p.second+1]= '#';
			q.push({p.first  ,p.second+1,p.num+1});
		}
	    if( s[p.first+1][p.second  ]=='.' ){
			s[p.first+1][p.second  ]= '#';
			q.push({p.first+1,p.second  ,p.num+1});
		}
	}

	if(f==0){
		cout << "-1" << endl;
		return 0 ;
	}
	cout << count-f << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
typedef long long ll;
using namespace std;
ll gcd(ll a,ll b) {
	return b != 0 ? gcd(b, a % b) : a;
}
ll icm(ll a, ll b) {
	return a * b / gcd(a, b);
}
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll e = icm(c, d);
	a = a - 1;
	b = b - b / c - b / d + b / e;
	a = a - a / c - a / d + a / e;
	cout << b-a << endl;

	return 0;
}

Measured memory_bytes: 256
def in_rectangle(w, h, x, y, r):
    # ?????????????????????
    left = x - r
    right = x + r
    floor = y - r
    ceil = y + r

    if 0 <= left and right <= w and 0 <= floor and ceil <= h:
        return True

    return False

w, h, x, y, r = map(int, input().split())
if in_rectangle(w, h, x, y, r):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 7616
# import time

a = int(input())
b = int(input())
c = int(input())
x = int(input())

# start_time = time.time()
z = 0
for i in range(c+1):
    # print(i)
    for j in range(b+1):
        # print(" ", j)
        for k in range(a+1):
            # print("  ", k)
            # print("!",x - 50 * i - 100 * j - 500 * k)
            if x - 50 * i - 100 * j - 500 * k == 0:
                z += 1
print(z)
# end = time.time()
# print(end - start_time)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
    
int main()
{
    int s,k,m,n;
    string str;
    while (1) {
        cin >> str;
        if (str[0]=='-') break;
        n=str.size();
        cin >> s;
        m=0;
        for (int i=0; i<s; i++) {
            cin >> k;
            m += k;
        }   
        k = m % n;      
        for (int i=k; i<n; i++)
            cout << str[i];
        for (int i=0; i<k; i++)
            cout << str[i];
        cout << endl;
    }
    return 0;
}

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

using ll = long long;

ll powm1(ll x){
    return x % 2 ? -1 : 1; }

int main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    a *= 3;
    b *= 3;
    c *= 3;

    ll x = (a + b + c) / 3;

    a -= x;
    b -= x;
    c -= x;

    ll m = powm1(k+1);
    ll ak = m * (-2 * a + b + c);
    ll bk = m * (a + -2 * b + c);
    ll ck = m * (a + b + -2 * c);


    if(abs(ak - bk) / 9 > 1000000000000000000ll) cout << "Unfair";
    else cout << (ak - bk) / 9;

    return 0; }


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
int S,h,m,s;
0<=S<86400;
scanf("%d",&S);
h=S/3600;
m=(S-h*3600)/60;
s=S-(h*3600+m*60);
printf("%d:%d:%d\n",h,m,s);
return 0;
}

Measured memory_bytes: 592