akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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 ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;

int N,A,B,C,D;
string S;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> N >> A >> B >> C >> D;
    --A;--B;--C;--D;
    cin >> S;
    if(A < B && B < D && D < C){
        // 3 A < B < D < C
        for(int i = B; i <= D; ++i){
            if(S[i-1]=='.' && S[i]=='.' && S[i+1]=='.'){
                cout << "Yes" << '\n';
                return 0;
            }
        }
        cout << "No" << '\n';
    } else {
        // 1 A < C < B < D, 2 A < B < C < D
        for(int i = A; i < C-1; ++i){
            if(S[i] == '#' && S[i+1] == '#'){
                cout << "No" << '\n';
                return 0;
            }
        }
        for(int i = B; i < D-1; ++i){
            if(S[i] == '#' && S[i+1] == '#'){
                cout << "No" << '\n';
                return 0;
            }
        }
        cout << "Yes" << '\n';
    }

    return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<algorithm>
using namespace std;
void dp(int a[][3],int n){
	for(int i=1;i<n;i++){
		a[i][0]+=max(a[i-1][1],a[i-1][2]);
		a[i][1]+=max(a[i-1][0],a[i-1][2]);
		a[i][2]+=max(a[i-1][0],a[i-1][1]);
	}
	int maximum=max(a[n-1][0],max(a[n-1][1],a[n-1][2]));
	cout<<maximum<<endl;
}
int main(){
	int n;cin>>n;int a[n][3];
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++)
		cin>>a[i][j];
	}
	dp(a,n);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fw(i, l, r) for (int i = l; i < r; i++)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 1e5 + 5;
struct thing {
	int val, ind;
	bool isa;
	bool operator<(const thing &rhs) const { return val < rhs.val; }
};
int n, a[N], b[N], suma = 0, sumb = 0, ans, psum[N], posa[N], posb[N], extra[N];
vector<thing> v;
signed main() {
	cin >> n;
	fw (i, 0, n) cin >> a[i] >> b[i], suma += a[i], sumb += b[i], v.pb({a[i], i, 1}), v.pb({b[i], i, 0});
	ans = min(suma, sumb);
	sort(v.begin(), v.end());
	fw (i, 0, v.size()) {
		if (v[i].isa) posa[v[i].ind] = i;
		else posb[v[i].ind] = i;
	}
	fw (i, 0, n + 1) psum[i] = (i ? psum[i - 1] : 0) + v[i].val;
	int og = 0;
	fw (i, 0, n - 2) og += v[i].val;
	fw (i, 0, n) {
		int res = psum[n - 1], cur = n;
		if (posa[i] >= cur) {
			res -= v[cur - 1].val;
			res += a[i];
			cur--;
		}
		if (posb[i] >= cur) {
			if (!v[cur - 1].isa || v[cur - 1].ind != i) {
				res -= v[cur - 1].val;
				res += b[i];
				cur--;
			} else {
				res -= v[cur - 2].val;
				res += b[i];
			}
		}
		ans = min(ans, res);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 10992
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class C_Splitting_Pile {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            long[] a = new long[n];
            long pre = 0, post = 0;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
                pre = a[0];
                post += a[i];
            }
            long ans = Integer.MAX_VALUE;
            for (int i = 0; i < n - 1; i++) {
                if (i != 0) pre += a[i];
                post -= a[i];
                ans = Math.min(Math.abs(pre - post), ans);
            }
            //out.printLine(r+" "+l);
            out.printLine(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void printLine(long i) {
            writer.println(i);
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer st;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 45652
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main(){
  int n;int sum = 0;int a[100];cin>>n;
  rep(i,n){
    cin>> a[i];sum += a[i];
  }
  int p = sum/n;int aa = 0, bb = 0;
  rep(i,n){
    aa += (a[i]-p) * (a[i]-p);
    bb += (a[i]-p-1) * (a[i]-p-1);
  }
  cout << min(aa, bb) << endl;
}


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

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	double x = 0.08, y = 0.1, i = 1.0;
	while (floor(x * i) != a or floor(y * i) != b) 
	{
		if (floor(x * i) > a ||  floor(y * i) > b)
		{
			puts("-1");
			return 0;
		}
		i++;
	}
	cout << i ;

}

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

#define DEBUG

#ifndef LOCAL
#undef DEBUG
#endif

#ifdef DEBUG
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) ;
#endif

map<int,int> mp;

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		mp[-x]++;
	}
	vector<int> res;
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		if (res.size()>=2) break;
		int x=it->first;
		while (res.size()<2 && mp[x]>=2)
		{
			mp[x]-=2;
			res.push_back(x);
		}
	}
	if (res.size()<2)
	{
		cout<<0<<endl;
	}
	else
	{
		cout<<1ll*res[0]*res[1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4992
import java.math.BigDecimal;
import java.util.*;

public class Main {


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

        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }

        List<Integer> b = new ArrayList(a);

        Collections.sort(b, Collections.reverseOrder());

        for(int i = 0; i < a.size(); i++) {
            if (a.get(i) == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            }
        }


    }


}


Measured memory_bytes: 89884
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int count = 0;
  for(int i = 0; i < S.size(); i++){
  	if(S.at(i) == 'x'){
      count++;
    }
   }
  if(count >= 8){
  	cout << "NO" << endl;
  }
  else{
  	cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
def solve():
    ans = 0
    N = int(input())
    miny = float('inf')
    ans = 0
    x = [0]*N
    y = [0]*N
    for i in range(N):
        x[i],y[i] = map(int, input().split())
    if x==y:
        return 0
    for i in range(N):
        ans += x[i]
        if x[i]>y[i]:
            miny = min(miny,y[i])
    ans -= miny
    return ans
print(solve())

Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const int MOD=1e8;
const int N=1e5+5;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};
ll n,m;
ll fa[N],val[N];
ll Find(ll x)
{
    if(fa[x]==-1) return x;
    ll root=Find(fa[x]);
    val[x]+=val[fa[x]];
    return fa[x]=root;
}
int main()
{
    //fre;
    IO;
    while(cin>>n>>m)
    {
        mem(fa,-1);
        rep(i,1,m+1)
        {
            ll u,v,w;
            cin>>u>>v>>w;
            ll tmp1=Find(u);
            ll tmp2=Find(v);
            if(tmp1!=tmp2)
            {
                val[tmp1]=val[v]-w-val[u];
                fa[tmp1]=tmp2;
            }
            else if(val[v]-val[u]!=w)
            {
                cout<<"No\n";
                return 0;
            }
        }
        cout<<"Yes\n";
    }
    return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 200000 + 5;
int a[N];

int main(){
	int n;
	cin >> n;
	int flag = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a,a+n);
	for(int i = 1; i < n; i++){
		if(a[i] == a[i-1])
			flag = 1;
	}
	if(flag == 1)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
    return 0;
}

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

int main()
{
    int N, count_overlap = 0, count_remove = 0;
    cin >> N;
    vector<pair<int, int>> range(N);

    for (int i = 0; i < N; i++)
    {
        int x, l;
        cin >> x >> l;
        range.at(i) = make_pair(x - l, x + l);
    }

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

    int tmp_range_left = range.at(0).first, tmp_range_right = range.at(0).second;

    int remove_count = 0;

    for (int i = 1; i < N; i++)
    {
        if (range.at(i).first < tmp_range_right)
        {
            if (range.at(i).second < tmp_range_right)
            {
                tmp_range_left = range.at(i).first;
                tmp_range_right = range.at(i).second;
            }
            remove_count++;
        }

        else
        {
            tmp_range_left = range.at(i).first;
            tmp_range_right = range.at(i).second;
        }
    }

    cout << N - remove_count << endl;
}

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

#define int long long
void print(vector<int>& v){
  for (int i:v) cout<<i<<" ";
    cout<<endl;
}
void printv(vector<vector<int>>& dp){
	for (auto x:dp) print(x);
}
int M=1e18+5;

int solve(vector<int>& slimes, int i, int j, vector<vector<int>>& dp){
	auto sum=[&](int L, int R){
		int s=0;
		for (int i=L;i<=R;i++) s=(s%M+slimes[i]%M)%M;
		return s;
	};
	if (i>=j) return 0;
	if (dp[i][j]!=-1) return dp[i][j];
	int s=sum(i,j);
	int ans=M;
	for (int k=i;k<j;k++){
		int left = solve(slimes,i,k,dp);
		int right = solve(slimes,k+1,j,dp);
		ans=min(ans,(left%M+right%M+s%M)%M);
	}
	return dp[i][j]=ans%M;
}

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

	int N;
	cin>>N;
	vector<int> slimes(N);
	for (int i=0;i<N;i++){
		cin>>slimes[i];
	}
	vector<vector<int>>dp(N+1,vector<int>(N,-1));
	cout<<solve(slimes,0,N-1,dp)<<endl;
    return 0; 
}

/*
*/

Measured memory_bytes: 4892
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;

template <typename C>
int mex(C const & xs) {
    int y = 0;
    for (int x : xs) { // xs must be sorted (duplication is permitted)
        if (y <  x) break;
        if (y == x) ++ y;
    }
    return y;
}

vector<int> func(vector<int> a, int n, vector<vector<int> > const & g, vector<vector<int> > const & h) {
    vector<int> outdegree(n);
    queue<int> que;
    repeat (i, n) {
        outdegree[i] = g[i].size();
        for (int j : g[i]) {
            if (a[j] != -1) {
                outdegree[i] -= 1;
            }
        }
        if (outdegree[i] == 0 and a[i] == -1) {
            que.push(i);
        }
    }
    while (not que.empty()) {
        int i = que.front(); que.pop();
        assert (outdegree[i] == 0);
        assert (a[i] == -1);
        set<int> gs;
        for (int j : g[i]) {
            assert (a[j] != -1);
            gs.insert(a[j]);
        }
        a[i] = mex(gs);
        for (int j : h[i]) if (outdegree[j] != 0) {
            outdegree[j] -= 1;
            if (outdegree[j] == 0 and a[j] == -1) {
                que.push(j);
            }
        }
    }
    return a;
}

int mex_node(int i, vector<int> const & a, vector<vector<int> > const & g) {
    set<int> gs;
    for (int j : g[i]) {
        if (a[j] != -1) {
            gs.insert(a[j]);
        }
    }
    return mex(gs);
}

bool solve(int n, vector<vector<int> > const & g, vector<vector<int> > const & h) {
    vector<int> a(n, -1);
    a = func(a, n, g, h);
    if (whole(count, a, -1) == 0) return true;
    int i = -1;
    repeat (k, n) if (a[k] == -1) { i = k; break; }
    assert (i != -1);
    int j = -1;
    for (int k : g[i]) if (a[k] == -1) { j = k; break; }
    assert (j != -1);
    int g1 = mex_node(i, a, g);
    a[j] = g1;
    int g2 = mex_node(i, a, g);
    a[j] = -1;
    for (int a_i : { g1, g2 }) {
        vector<int> b = a;
        b[i] = a_i;
        b = func(b, n, g, h);
        assert (b[j] != -1);
        if (mex_node(i, b, g) == a_i) return true;
    }
    return false;
}

int main() {
    int n; scanf("%d", &n);
    vector<vector<int> > g(n);
    vector<vector<int> > h(n);
    repeat (i, n) {
        int p; scanf("%d", &p); -- p;
        g[p].push_back(i);
        h[i].push_back(p);
    }
    bool result = solve(n, g, h);
    printf("%s\n", result ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 23936
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall

INF = 1001001001
N, M, L = map(int, input().split())

fuel = [[INF] * N for _ in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    fuel[A][B] = C
    fuel[B][A] = C
for i in range(N):
    fuel[i][i] = 0

fuel = floyd_warshall(csgraph_from_dense(fuel))
# for k in range(N):
#     for i in range(N):
#         for j in range(N):
#             fuel[i][j] = min(fuel[i][j], fuel[i][k] + fuel[k][j])

dist = [[INF] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            dist[i][j] = 0
        elif fuel[i][j] <= L:
            dist[i][j] = 1

dist = floyd_warshall(csgraph_from_dense(dist))
# for k in range(N):
#     for i in range(N):
#         for j in range(N):
#             dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

Q = int(input())
for i in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if dist[s][t] == INF:
        print(-1)
    else:
        print(int(dist[s][t]) - 1)


Measured memory_bytes: 19908
import Data.Char

main :: IO ()
main = do
  s <- getLine
  print $ solve s

solve :: String -> Int
solve = patterns . map digitToInt

patterns :: [Int] -> Int
patterns [] = 0
patterns [a] = a
patterns (a:b:as) =
  a * 2^n
  + (patterns $ (10 * a + b):as)
  + (patterns $ b:as)
    where n = length as


Measured memory_bytes: 508
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 1E+05;

ll N;

int A[MAX_N + 2];
ll modfac[MAX_N + 2], modfacinv[MAX_N + 2];

void modfactorInv(ll n);
ll modfactor(ll n);
ll modPow(ll x, ll n);

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

    cin >> N;

    int k, l;

    for (int i = 1; i <= N + 1; i++) {
        int a;
        cin >> a;
        if (A[a] != 0) {
            k = A[a] - 1;
            l = N + 1 - i;
        } else {
            A[a] = i;
        }
    }

    modfactor(N + 1);

    for (int i = 1; i <= N + 1; i++) {
        //cout << "i = " << i << "\n";
        ll ans = ((modfac[N + 1] * modfacinv[i]) % MOD) * modfacinv[N + 1 - i] % MOD;
        //cout << " ans = " << ans << "\n";
        if (i <= k + l + 1) {
            ans = (ans - ((modfac[k + l] * modfacinv[k + l - i + 1]) % MOD) * modfacinv[i - 1] % MOD + MOD) % MOD;
            //cout << " ans = " << ans << "\n";
        }
        cout << ans << "\n";
    }

    return 0;
}

ll modPow(ll x, ll n)
{
    ll res = 1;
    while (n > 0) {
        if (n & 1) {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

// n!を求める
ll modfactor(ll n)
{
    modfac[0] = 1;
    ll p = 1;
    while (p <= n) {
        //cout << p << "\n";
        modfac[p] = (p * modfac[p - 1]) % MOD;
        p++;
    }
    modfacinv[n] = modPow(modfac[n], MOD - 2);
    modfactorInv(n);
    return modfac[n];
}

// (n!)^-1を求める
void modfactorInv(ll n)
{
    ll p = n - 1;
    while (p >= 0) {
        modfacinv[p] = ((p + 1) * modfacinv[p + 1]) % MOD;
        p--;
    }
}

Measured memory_bytes: 5488
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  int d,i,j,k;
  cin >> d;
  double a[1000]={},b[1000]={};
  for(i=0;i<d;i++) cin >> a[i];
  for(i=0;i<d;i++) cin >> b[i];
  double o1=0,o2=0,o3=0,oe=0;
  for(i=0;i<d;i++){
    o1+=fabs(a[i]-b[i]);
    o2+=fabs(a[i]-b[i])*fabs(a[i]-b[i]);
    o3+=fabs(a[i]-b[i])*fabs(a[i]-b[i])*fabs(a[i]-b[i]);
    oe=max(oe,fabs(a[i]-b[i]));
  }
  printf("%.6f\n",o1);
  printf("%.6f\n",sqrt(o2));
  printf("%.6f\n",pow(o3,1.0/3.0));
  printf("%.6f\n",oe);
  return 0;
}


Measured memory_bytes: 3388
#C
n, m, x = list(map(int, input().split()))
c = []
a = []
for i in range(n):
    t = list(map(int, input().split()))
    c.append(t[0])
    a.append(t[1:])
    
    
result = -1
for i in range(1 << n):
    reading_books = [0 for _ in range(m)]
    cost = 0
    for j in range(n):
        if (i >> j) & 1 == 0:
            continue
        cost += c[j]
        for k in range(m):
            reading_books[k] += a[j][k]
        if all(skill >= x for skill in reading_books):
            if result == -1:
                result = cost
            else:
                result = min(result, cost)


print(result)

Measured memory_bytes: 9192
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string A, B, C;
	std::cin >> A >> B >> C;
	if (A.back() == B.front() && B.back() == C.front())
		std::cout << "YES\n";
	else
		std::cout << "NO\n";
}


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

int main() {
  int h,w; cin>>h>>w;
  vector<vector<char>> a(h, vector<char>(w));
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      cin>>a[i][j];
    }
  }
  vector<vector<int>> up(h, vector<int>(w));
  vector<vector<int>> down(h, vector<int>(w));
  vector<vector<int>> right(h, vector<int>(w));
  vector<vector<int>> left(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j]=='#') {
        up[i][j]=0;
        left[i][j]=0;
      }
      else {
        if (i>0) up[i][j]=up[i-1][j]+1;
        else up[i][j]=1;
        if (j>0) left[i][j]=left[i][j-1]+1;
        else left[i][j]=1;
      }
    }
  }
  for (int i = h-1; i >= 0; i--) {
    for (int j = w-1; j >= 0; j--) {
      if (a[i][j]=='#') {
        down[i][j]=0;
        right[i][j]=0;
      }
      else {
        if (i<h-1) down[i][j]=down[i+1][j]+1;
        else down[i][j]=1;
        if (j<w-1) right[i][j]=right[i][j+1]+1;
        else right[i][j]=1;
      }
    }
  }
  int ans=0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j]=='#') continue;
      ans=max(ans, up[i][j]+down[i][j]+right[i][j]+left[i][j]-3);
    }
  }
  cout<<ans<<endl;
}


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

typedef pair <int, int> pii;

const int N = 1e5 + 10;
int n, par[N], high[N], mark[N];
vector <int> adj[N];
set <pii> st;

void make_par(int v = 0, int p = 0, int h = 0) {
	par[v] = p;
	high[v] = h;
	for (int i : adj[v])
		if (i != p)
			make_par(i, v, h + 1);
}

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int v, u;
		cin >> v >> u;
		v--;
		u--;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	make_par();
	
	if (n == 1)
		return cout << "First", 0;
	
	for (int i = 1; i < n; i++)
		if (adj[i].size() == 1)
			st.insert({-high[i], i});
	
	while (st.size()) {
		int v = st.begin() -> second;
		st.erase(st.begin());
		if (mark[v])
			continue;
//		cout << v + 1 << endl;
		
		if (mark[par[v]] || par[v] == v)
			return cout << "First", 0;
		mark[par[v]] = 1;
		mark[v] = 2;
		if (par[par[v]] != par[v])
			st.insert({-high[par[par[v]]], par[par[v]]});
	}
	cout << "Second";
}

Measured memory_bytes: 9088
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll u(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll d(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll z(ll a){
  if(a<0)return -a;
  return a;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
ll nCr(int n,int k){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;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;
  }
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(void){
  int n;
  scanf("%d",&n);
  int a[n],x[n][n],y[n][n];
  FOR(n){
    scanf("%d",&a[i]);
    FORJ(a[i]){
      scanf("%d %d",&x[i][j],&y[i][j]);
      x[i][j]--;
    }
  }
  int b[n],ans=0;
  for(int k=0;k<(int)pow(2,n);k++){
    int c=k,cnt=0;
    FORJ(n){
      b[j]=c%2;
      cnt+=b[j];
      c/=2;
    }
    int flg=1;
    FOR(n){
      if(!b[i])continue;
      FORJ(a[i]){
        if(b[x[i][j]]!=y[i][j])flg=0;
      }
    }
    ans=max(ans,cnt*flg);
  }
  PRN(ans);
  return 0;
}


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

int main(){
  int n,m,sum;
  vector<int> ti,pi,xi; 
  
  cin >> n;
  for(int i=0; i<n; i++){
    int vt;
    cin >> vt;
    ti.push_back(vt);
    sum+=ti[i];
  }
  cin >> m;
  for(int i=0; i<m; i++){
    int vp, vx;
    cin >> vp >> vx;
    pi.push_back(vp);
    xi.push_back(vx);
  }
  for(int i=0; i<m; i++){
     cout << sum-ti[pi[i]-1]+xi[i] <<endl;
   }

}

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

int main() {
    int N, Z, W;
    cin >> N >> Z >> W;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    if (N == 1) {
        cout << abs(a[0] - W) << endl;
    } else {
        cout << max(abs(a[N - 1] - W), abs(a[N - 1] - a[N - 2])) << endl;
    }
}


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

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

    cin >> q;

    for(int i = 0; i < q; i++){
        int b, c;
        cin >> b >> c;
        reverse(v.begin()+b, v.begin()+c);

    }

    for(int i = 0; i < v.size()-1; i++){
        cout << v[i] << " ";
    }
    cout << v[v.size()-1] << endl;
}


Measured memory_bytes: 3096
// luogu-judger-enable-o2
#include <bits/stdc++.h>
#define rep(i, j, k) for(int i = j; i <= k; ++i)
#define dep(i, j, k) for(int i = j; i >= k; --i)
#define SIZE(x) (int)(x.size())

typedef long long ll;

using namespace std;

const int maxn = 2e5 + 5;

int n, a[maxn], b[maxn], L, R;
ll ans = 0, rnt = 0;

inline int read() {
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); }
	while(isdigit(ch))  { u = u * 10 + ch - 48; ch = getchar(); } return u * f;
}

inline ll Solve(int L, int R, int k, int t, ll rnt = 0) {
	int l = n, r = n; b[n] = k;
	while(R - L + 1 >= 2) {
		if(t & 1) {
			rnt += a[R] + a[R - 1] - b[l] - b[r];
			b[++r] = a[R--]; b[--l] = a[R--];
		} else {
			rnt += b[l] + b[r] - a[L] - a[L + 1];
			b[++r] = a[L++]; b[--l] = a[L++];
		} t ^= 1;
	}
	if(R - L + 1 >= 1) rnt += max(abs(b[r] - a[R]), abs(b[l] - a[R]));
	return rnt;
}

int main() {
	n = read();
	rep(i, 1, n) a[i] = read();
	sort(a + 1, a + 1 + n);
	cout << max(Solve(2, n, a[1], 1), Solve(1, n - 1, a[n], 0));
	return 0;
}

Measured memory_bytes: 1024
while 1:
   H, W = map(int,raw_input().split())

   if H ==0 and W == 0:
      break
   for i in range(H):
      if i%2==0:
        if W%2==0:
           print "#."*(W/2)
        elif W%2==1:
           print "#."*(W/2)+"#"
      elif i%2==1:
         if W%2==0:
            print ".#"*(W/2)
         elif W%2==1:
            print ".#"*(W/2)+"."
   print ""

Measured memory_bytes: 6412
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

inline void solve(int n) {
    vector<int> cnt(100010,0);
    REP(i,n) {
        int a,b;
        cin>>a>>b;
        cnt[a]++;
        cnt[b+1]--;
    }
    cnt[0]++;
    REP(i,100010) {
        cnt[i+1]+=cnt[i];
    }
    REPR(i,100010) {
        if(i<=cnt[i]) {
            cout<<i-1<<endl;
            return;
        }
    }
    cout<<0<<endl;
}
signed main() {
    int n;
    cin>>n;
    solve(n);
    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <stdlib.h>
 
int main(){
    int a,b,c;
	scanf("%d",&a);
  	scanf("%d",&b);
	scanf("%d",&c);
  
    int one_nokori = a-b;
    if(one_nokori<=0){
      one_nokori=0;
    }
    int two_nokori =c-one_nokori;
    if(two_nokori>=0){
      printf("%d",two_nokori);
    }else{
      printf("0");
    }
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void) {
	int sum = 0;
	int koka[] = {1,5,10,50,100,500};

	for (int i = 0;i < 6; i++) {
		int c;
		cin >> c;
		sum += c * koka[i];
	}

		cout <<(sum >= 1000 ? "1" : "0") << endl;

	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
using namespace std;
typedef long int li;
#define df 0
int dc=10000000;
int v[4]={7,5,3,0};
li to753(int k){
  dc-=df; if(dc<0){ cout << "err in to753\n"; return 0;}
  li s=0,i=1;
  while(k){
  dc-=df; if(dc<0){ cout << "err in to753\n"; return 0;}
  s+=v[3-k%4]*i;
    i*=10;
    k/=4;
  }
  return s;
}
int check(int k){
  dc-=df; if(dc<0){ cout << "err in check\n"; return 0;}
  int f[4]={};
  while(k){
  dc-=df; if(dc<0){ cout << "err in check\n"; return 0;}
    if(k%4==0)return 0;
    f[k%4]|=1;
    k/=4;
  }
  return(f[1] and f[2] and f[3]);
}
int main(){
  int n; cin >> n;
  int i=0;
  long int x=to753(i);
  int count=0;
  while(x<=n){
  dc-=df; if(dc<0){ cout << "err in AAA\n"; return 0;}
  if(check(i)){
    count++;
    if(df)cout << x << "\n";
  }
    i++;
    x=to753(i);
  }
  cout << count;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
ll N, P;

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
  INCANT;
  cin >> N >> P;
  map<ll, int> ret = prime_factor(P);
  ll ans = 1ll;
  for (auto p: ret) {
    int cnt = p.second;
    while (cnt>=N) {
      ans*=p.first;
      cnt-=N;
    }
  }

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

Measured memory_bytes: 3620
#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;
int dp[1000100][2];
string s;

int Rec(int i , bool exchange){

    if(i < 0)   return exchange;

    if(dp[i][exchange] != -1)  return dp[i][exchange];

    int Res = 1e9 , x = (s[i] - '0') + (exchange == 1);
    Res = min(Res , 10 - x + Rec(i - 1 , 1));
    Res = min(Res , x + Rec(i - 1 , 0));

    return dp[i][exchange] = Res;
}


int main()
{
    memset(dp , -1 , sizeof(dp));
    cin >> s;
    cout << Rec(s.size() - 1 , 0);
    return 0;
}



Measured memory_bytes: 56068
#include <algorithm>　　　 //STL 通用算法
#include <bitset>　　　　　//STL 位集容器
#include <cctype>         //字符处理
#include <cerrno> 　　　　 //定义错误码
#include <cfloat>　　　　 //浮点数处理
#include <ciso646>         //对应各种运算符的宏
#include <climits> 　　　　//定义各种数据类型最值的常量
#include <clocale> 　　　　//定义本地化函数
#include <cmath> 　　　　　//定义数学函数
#include <complex>　　　　 //复数类
#include <csignal>         //信号机制支持
#include <csetjmp>         //异常处理支持
#include <cstdarg>         //不定参数列表支持
#include <cstddef>         //常用常量
#include <cstdio> 　　　　 //定义输入／输出函数
#include <cstdlib> 　　　　//定义杂项函数及内存分配函数
#include <cstring> 　　　　//字符串处理
#include <ctime> 　　　　　//定义关于时间的函数
#include <cwchar> 　　　　 //宽字符处理及输入／输出
#include <cwctype> 　　　　//宽字符分类
#include <deque>　　　　　 //STL 双端队列容器
#include <exception>　　　 //异常处理类
#include <fstream> 　　　 //文件输入／输出
#include <functional>　　　//STL 定义运算函数（代替运算符）
#include <limits> 　　　　 //定义各种数据类型最值常量
#include <list>　　　　　　//STL 线性列表容器
#include <locale>         //本地化特定信息
#include <map>　　　　　　 //STL 映射容器
#include <memory>         //STL通过分配器进行的内存分配
#include<new>            //动态内存分配
#include <numeric>         //STL常用的数字操作
#include <iomanip> 　　　 //参数化输入／输出
#include <ios>　　　　　　 //基本输入／输出支持
#include <iosfwd>　　　　　//输入／输出系统使用的前置声明
#include <iostream> 　　　//数据流输入／输出
#include <istream>　　　　 //基本输入流
#include <iterator>        //STL迭代器
#include <ostream>　　　　 //基本输出流
#include <queue>　　　　　 //STL 队列容器
#include <set>　　　　　　 //STL 集合容器
#include <sstream>　　　　 //基于字符串的流
#include <stack>　　　　　 //STL 堆栈容器
#include <stdexcept>　　　 //标准异常类
#include <streambuf>　　　 //底层输入／输出支持
#include <string>　　　　　//字符串类
#include <typeinfo>        //运行期间类型信息
#include <utility>　　　　 //STL 通用模板类
#include <valarray>        //对包含值的数组的操作
#include <vector>　　　　　//STL 动态数组容器
using namespace std;

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

const int MAXN=1e5+10;
const int MOD=998244353;

inline int read(){
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
inline ll readll(){
	ll x=0;int f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-') f=-1;c=getchar();}
	while(isdigit(c)) x=(x<<3ll)+(x<<1ll)+1ll*(c-'0'),c=getchar();
	return x*f;
}
int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
ll gcd(ll x,ll y){
	return y?gcd(y,x%y):x;
}

int n;
ll ans;

int main(){
	n=read();
	ans=1ll*n*(n+1)*(n+2)/6;
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		if(u>v) swap(u,v);
		ans-=1ll*u*(n-v+1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3612
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
    int x, y;
    cin >> x >> y;
    cout << (x + y/2) << endl;
}


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

using namespace std;

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

        sort(d,d+n);
        cout<<d[n/2]-d[n/2-1]<<endl;

        return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<vector>
//#include<ctime>
#define rg register
typedef long long ll;
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline void mind(T&a,const T b){a=a<b?a:b;}
template <typename T> inline void maxd(T&a,const T b){a=a>b?a:b;}
template <typename T> inline T abs(const T a){return a>0?a:-a;}
template <typename T> inline void swap(T&a,T&b){T c=a;a=b;b=c;}
//template <typename T> inline void swap(T*a,T*b){T c=a;a=b;b=c;}
template <typename T> inline T gcd(const T a,const T b){if(!b)return a;return gcd(b,a%b);}
template <typename T> inline T lcm(const T a,const T b){return a/gcd(a,b)*b;}
template <typename T> inline T square(const T x){return x*x;};
template <typename T> inline void read(T&x)
{
	char cu=getchar();x=0;bool fla=0;
	while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}
	while(isdigit(cu))x=x*10+cu-'0',cu=getchar();
	if(fla)x=-x;
}
template <typename T> inline void printe(const T x)
{
	if(x>=10)printe(x/10);
	putchar(x%10+'0');
}
template <typename T> inline void print(const T x)
{
	if(x<0)putchar('-'),printe(-x);
	else printe(x);
}
int n,A[200001],ans,MI;
int main()
{
	read(n),MI=n+1;
	for(rg int i=1;i<=n;i++)
	{
		read(A[i]);
		if(A[i]<MI)
		{
			ans++;
			MI=A[i];
		}
	}
	print(ans);
	return 0;
}

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

int main(){
	int n,t,result=0;
	while(1){
		cin >> n;
		if(n==0) break;
		for(int i=0;i<n/4;i++){
			cin >> t;
			result+=t;
		}
		cout << result << endl;
		result=0;
	}
}

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

int main() {
	int n;
	cin >> n;
	int out = 0;
	for (int i = 0; i < (n + 1)/2; ++i) {
		int l = 1 + 2 * i;
		int tmp = 0;
		for (int j = 0; j < (l + 1) /2; ++j) {
			int k = 1 + 2 * j;
			if (l % k == 0) tmp += 1;
		}
		if(tmp == 8) out += 1;
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

int N, K;
ll h[101000];
ll dp[101000];

int main() {
    cin >> N >> K;
    rep(i, N) cin >> h[i];

    // DP init
    rep(i, 101000) dp[i] = INF;
    dp[0] = 0;

    // DP loop
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            // 配るDP
            chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << dp[N-1] << endl;
}


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

using namespace std;

int ans, mi, n, x;

int main(){
	mi = 101;
	
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> x;
		if(x % 10 != 0) mi = min(mi, x);
		ans += x;
	}
	if(ans % 10 == 0){
		if(mi != 101) ans -= mi;
		else ans = 0;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
	vector<int> prid(MAX);
	vector<int> pri(MAX);
	int k=1;
	for(int i=0;i<MAX;i++)
		prid[i]=1;
	prid[0]=0;
	prid[1]=0;
	for(int i=0;i*i<MAX;i++){
		if(prid[i]){
			for(int j=i*2;j<MAX;j+=i)
				prid[j]=0;
		}
	}
	for(int i=0;i<MAX;i++)
	if(prid[i])
	pri[k++]=i;
	int x,sum;
	while(cin>>x,x){
		sum=0;
		for(int i=1;i<=x;i++)
		sum+=pri[i];
		
		cout<<sum<<endl;
		
		
		
	}
	
	
	
	return 0;
}

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

    using namespace std;

    vector<int>v[200005];
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n;
        cin>>n;
        vector<int>a(n);
        for(int i=0;i<n-1;i++)
            cin>>a[i];
        for(int i=0;i<n-1;i++){
            v[a[i]].push_back(i+1);
        }
        for(int i=1;i<=n;i++)
            cout<<v[i].size()<<"\n";
        return 0;
    }


Measured memory_bytes: 15000
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pm(m) for(auto itr=(m).begin();itr!=(m).end();itr++){itr->first<<" "<<itr->second<<"\n";}
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x) cout<<(x)<<" ";exit(0);
int mod = 1000000007;
int mod1 = 998244353;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void join(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb])swap(ra,rb);
        v[rb]=ra;
        sz[ra]+=sz[rb];
        
    }
    bool same(int a,int b){
        //same set
        return (root(a)==root(b));
    }
    int size(int a){
        return sz[root(a)];
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};

int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
	
		string s;
		cin>>s;
		int val=0;
		for(int i=0;i<s.length();i++){
		    val+=s[i]-'0';
		}
		if(val%9==0)cout<<"Yes";
		else cout<<"No";
		
	
}

Measured memory_bytes: 6132
#include<stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const char letters[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
int diff[62];char pw[129],query[129];
static inline int ask(void){int x;printf("? %s\n",query);fflush(stdout);return !scanf("%d",&x)?-1:x;}
int main(void)
{
  int total=0,len=0;
  rep(i,62){rep(j,128){query[j]=letters[i];}query[128]=0;diff[i]=128-ask();total+=diff[i];}
  rep(i,62)
  {
    if(len==0){len=diff[i];rep(j,diff[i])pw[j]=letters[i];}
    else
    {
      for(int k=diff[i],l=0;k>=1;k--)
      {
        int r=len;
        while(l<r)
        {
          int mid=(l+r+1)/2;
          rep(j,mid)query[j]=pw[j];
          rep(j,k)query[mid+j]=letters[i];
          query[mid+k]=0;
          if(ask()==total-mid-k)l=mid;else r=mid-1;
        }
        len++;rep(j,len-l){pw[len-j]=pw[len-j-1];}pw[l]=letters[i];
      }
    }
  }
  pw[len]=0;return printf("! %s\n",pw),0;
}

Measured memory_bytes: 3732
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    public static void Main()
    {
        int n = ReadInt();
        int ans = 1;
        for (int i = 2; i < n; i++)
        {
            var dic = new Dictionary<int, int>();
            foreach (var p in MyMath.PrimeFactor(i))
            {
                if (dic.ContainsKey(p)) dic[p]++;
                else dic[p] = 1;
            }
            int m = 1;
            foreach (var x in dic.Values) m *= x + 1;
            ans += m;
        }
        Console.WriteLine(ans);
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
}

static class MyMath
{
    public static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);
    public static int Lcm(int a, int b) => a * b / Gcd(a, b);

    static List<int> fib = new List<int> { 0, 1 };
    public static int Fib(int n)
    {
        for (int i = fib.Count(); i <= n; i++) fib.Add(fib[i - 2] + fib[i - 1]);
        return fib[n];
    }

    public static int NextCombination(int bit)
    {
        int x = bit & -bit;
        int y = x + bit;
        return y | (((bit & ~y) / x) >> 1);
    }

    public static bool IsPrime(int n)
    {
        for (int p = 2; p * p <= n; p++) if (n % p == 0) return false;
        return true;
    }

    public static IEnumerable<int> PrimeFactor(int n)
    {
        int p = 2;
        while (p * p <= n) if (n % p == 0) { n /= p; yield return p; } else p++;
        if (n != 1) yield return n;
    }
}

Measured memory_bytes: 41488
import java.util.Scanner;

/**
 * One Clue
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int K = sc.nextInt();
            int X = sc.nextInt();

            int min = X - K + 1;
            int max = X + K - 1;

            StringBuilder ans = new StringBuilder();
            ans.append(min);
            for (int i = min + 1; i <= max; i++) {
                ans.append(" ").append(i);
            }

            System.out.println(ans.toString());
        }
    }

}


Measured memory_bytes: 22868