akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();
            var N = int.Parse(ss[0]);
            var D = int.Parse(ss[1]);

            var X = new int[N, D];
            for (int i = 0; i < N; i++)
            {
                ss = Console.ReadLine().Split();
                var j = 0;
                foreach (var item in ss)
                {
                    X[i, j] = int.Parse(item);
                    j++;
                }
            }

            var count = 0;
            for (int i = 0; i < N; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    var sum = 0.0;
                    for (int k = 0; k < D; k++)
                    {
                        sum += Math.Pow(X[i, k] - X[j, k], 2);
                    }

                    var dis = Math.Sqrt(sum);

                    if ((int)dis == dis)
                    {
                        count++;
                    }
                }
            }

            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  ll n,digit=0,digitsum=0;
  cin >> n;
  rep(i,n){
    ll c,d;
    cin >> d >> c;
    digit+=c;
    digitsum+=c*d;
  }

  cout << (digit-1)+(digitsum-1)/9 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
//overflowに注意
int a[300030];
int main() {
    int N;
    cin >> N;
    long long max = 0;
    int n = 3*N;

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

    sort(a, a + n, greater<int>());

    for(int i = 1; i <= N; i++){
        int k = 2*i - 1;
        max += a[k];
    }
    
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 4780
N=int(input())
*A,=map(int,input().split())

S=sum(A)
i=0
while i<N:
    A[i]*=N
    i+=1

now=float('inf')
i=0
while i<N:
    if abs(S-A[i])<now:
        now=abs(S-A[i])
        ans=i
    i+=1

print(ans)

Measured memory_bytes: 9088
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}
template<class T>inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>inline T lcm(T a,T b){return a*b/gcd(b,a%b);}

long K,A,B,C,Y,i;
inline void solve(){
  IN3(K,A,B);
  if(A>=B||B-A==1){
    OUT(K+1);
    return;
  }
  C=1;Y=0;
  REP(i,K){
    if(Y>0){
      Y--;
      C+=B;
    }
    else if(C>=A&&i!=K-1){
      C-=A;
      Y++;
    }else{
      C++;
    }
  }
  OUT(C);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-08 10:18:07
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#include<vector>
const int N=610*610;
int n,d1,d2,col[N],vis[N];
std::vector<int> e[N];
void dfs(int u)
{
	vis[u]=1;
	for(auto v:e[u]) if(!vis[v])
	{
		col[v]|=(col[u]&1)^1; dfs(v);
	}
}
int main()
{
	n=read()*2; d1=read(); d2=read();
	fr(i,1,n) fr(j,1,n)
	{
		for(int k=0,p=n;k*k<=d1&&k<=n;k++)
		{
			while(k*k+p*p>d1&&p>0) p--;
			if(k*k+p*p==d1)
			{
				if(i-k>0&&j-p>0) e[(i-1)*n+j].push_back((i-k-1)*n+(j-p));
				if(i-k>0&&j+p<=n) e[(i-1)*n+j].push_back((i-k-1)*n+(j+p));
				if(i+k<=n&&j-p>0) e[(i-1)*n+j].push_back((i+k-1)*n+(j-p));
				if(i+k<=n&&j+p<=n) e[(i-1)*n+j].push_back((i+k-1)*n+(j+p));
			}
		}
	}
	fr(i,1,n*n) if(!vis[i]) dfs(i);
//	fr(i,1,n) fr(j,1,n) printf("%d%c",col[(i-1)*n+j],j==n?'\n':' ');
	fr(i,1,n*n){ vis[i]=0; col[i]*=2; e[i].clear(); }
	fr(i,1,n) fr(j,1,n)
	{
		for(int k=0,p=n;k*k<=d2&&k<=n;k++)
		{
			while(k*k+p*p>d2&&p>0) p--;
			if(k*k+p*p==d2)
			{
				if(i-k>0&&j-p>0) e[(i-1)*n+j].push_back((i-k-1)*n+(j-p));
				if(i-k>0&&j+p<=n) e[(i-1)*n+j].push_back((i-k-1)*n+(j+p));
				if(i+k<=n&&j-p>0) e[(i-1)*n+j].push_back((i+k-1)*n+(j-p));
				if(i+k<=n&&j+p<=n) e[(i-1)*n+j].push_back((i+k-1)*n+(j+p));
			}
		}
	}
	fr(i,1,n*n) if(!vis[i]) dfs(i);
//	fr(i,1,n) fr(j,1,n) printf("%d%c",col[(i-1)*n+j],j==n?'\n':' ');
	fr(i,0,3)
	{
		int s=0;
		fr(j,1,n) fr(k,1,n) if(col[(j-1)*n+k]==i) s++;
		if(s>=n*n/4)
		{
			s=n*n/4;
			fr(j,1,n) fr(k,1,n) if(col[(j-1)*n+k]==i&&s){ printf("%d %d\n",j-1,k-1); s--; }
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 71680
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s, t;
	cin >> s >> t;

	int n = s.size(), m = t.size();
	
	pair<int, pi> dp[n + 1][m + 1];
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(dp[i - 1][j] < dp[i][j - 1]){
				dp[i][j] = {dp[i][j - 1].first, {i, j - 1}};
			}else{
				dp[i][j] = {dp[i - 1][j].first, {i - 1, j}};
			}
			
			if(s[i - 1] == t[j - 1] && dp[i - 1][j - 1].first + 1 > dp[i][j].first){
				dp[i][j] = {dp[i - 1][j - 1].first + 1, {i - 1, j - 1}};
			}
		}
	}
	
	pi cur = {n, m};
	string ret;
	
	while(cur.first && cur.second){
		pi prv = dp[cur.first][cur.second].second;
		if(prv.first + 1 == cur.first && prv.second + 1 == cur.second) ret += s[prv.first];
		cur = prv;
	}
	
	reverse(ret.begin(), ret.end());
	
	cout << ret << endl;

	return 0;
}

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

const int MAXN = 200000 + 10;

int nextpow(int x) {
    int k = 0;
    while (x > 0) {
        k++;
        x/=2;
    }

    return 1<<k;
}

bool ispow(int x) {
    return ((x-1) & x) == 0;
}

vector<vector<int>> G;
vector<int> dp[2];
vector<bool> vis;
map<int, int> M;
vector<int> v;

void gogo(int x) {
    vis[x] = true;

    for (int y: G[x]) {
        gogo(y);
    }

    int k = M[v[x]];
    if (ispow(v[x])) {

    } else {
        vector<int> z;
        int s = 0;
        for (int y: G[x]) {
            z.push_back(dp[y][0] - dp[y][1]);
            s += dp[y][1];
        }

        sort(begin(z), end(z), greater<int>());
        int ix = 0;
        dp[x][0] = max(dp[x][0], s);
        dp[x][1] = max(dp[x][1], s);
        for (int e: z) {
            s += e;
            if (k >= 1) {
                s++;
                k--;
            }
            dp[x][0] = max(dp[x][0], s + k / 2);
            dp[x][1] = max(dp[x][1], s + (k - 1) / 2);
        }

        

        
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);

    int n;

    cin >> n;

    

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

    for (auto p: M) {
        v.push_back(p.first);
    }

    reverse(begin(v), end(v));
    int res = 0;
    for (auto x: v) {
        
        int y = nextpow(x) - x;
        //cerr << x << " " << y << "\n";
        if (y == x) {
            while (M[x] >= 2) {
                res += 1;
                M[x] -= 2;
            }
        } else {
            while (M[x] >= 1 && M[y] >= 1) {
                res += 1;
                M[x]--;
                M[y]--;
            }
        }
        
    }

    cout << res << "\n";

    /*G.resize(v.size());
    for (int i = 0; i < v.size(); ++i) {
        int x = v[i];
        int y = nextpow(x) - x;
        if (y < x) {
            int p = lower_bound(begin(v), end(v), y) - begin(v);
            if (p != v.size() && v[p] == y) {
                G[y].push_back(x);
            }
        }
    }

    for (int i = 0; i < 2; ++i) {
        dp[i].resize(v.size());
    }
    vis.resize(v.size());

    int res = 0;
    for (int i = 0; i < v.size(); ++i) {
        if (!vis[i]) {
            gogo(i);
        }
    }*/
    


    return 0;
}


Measured memory_bytes: 26864
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;

namespace AtCoderSolve
{
    class Solve
    {

        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;


        static int N, W;
        static long[] w, v;
        
        //static long[] A, B;


        public static void Input()
        {
            var cin = new Scanner();
            var input = cin.SplitReader();
            N = input[0];
            W = input[1];
            w = new long[N];
            v = new long[N];
            for(var i = 0; i < N; i++)
            {
                var p = cin.SplitReaderL();
                w[i] = p[0];
                v[i] = p[1];
            }
        }


        static void Main(string[] args)
        {
            Input();

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            long V = 1000 * N;
            long[,] dp = new long[N + 1, V + 1];
            for(var i = 0; i <= N; i++)
            {
                for(var j = 0; j <= V; j++)
                {
                    dp[i, j] = j == 0 ? 0 : SINF;
                }
            }

            for(var i = 1; i <= N; i++)
            {
                for(var j = 0; j <= V; j++)
                {
                    if (j - v[i - 1] < 0)
                    {
                        dp[i, j] = dp[i - 1, j];
                    }
                    else
                    {
                        dp[i, j] = Min(dp[i - 1, j - v[i - 1]] + w[i - 1], dp[i - 1, j]);
                    }
                }
            }

            long ans = 0;
            for(var i = V; i >= 0; i--)
            {
                if (dp[N, i] <= W)
                {
                    ans = i;
                    break;
                }
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();
        }
    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }
}






Measured memory_bytes: 92000
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
	
def main():
	A, B = map(int, input().split(" "))
	S = input()
	tmp = S.split("-")
	
	if len(tmp) != 2:
		print("No")
		sys.exit()
	
	if tmp[0].isdecimal() == False or tmp[1].isdecimal() == False:
		print("No")
		sys.exit()
	
	if len(tmp[0]) == A and len(tmp[1]) == B:
		print("Yes")
	else:
		print("No")
	
	
if __name__ == "__main__":
	main()


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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define rep(i,n) for(int i= 0;i<(int)(n);i++)
#define pb push_back

int main(){
    int k;
    cin >> k;
    int gusu=0,kisu=0;
    for(int i=1;i<=k;i++){
        if(i%2 == 0){
            gusu++;
        }else{
            kisu++;
        }
    }
    cout << kisu*gusu << endl;
    return 0;
}


Measured memory_bytes: 256
for _ in [0]*input():
  A = '012345678954321'
  a, b = raw_input().split()
  n = 15
  for _ in [0]*A.count(a):
    I = A.index(a)
    A = A[I:]+A[:I]
    I = A.index(b)
    if n>I:
      n = I
      x = A[:I+1]
    A = A[1:]+A[0]
  for e in x:
    print e,
  print

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

typedef pair<int, int> pi;
string s[20];
int h, w;
int bfs(int sy, int sx) {
  int c[h][w];
  int inf = 1e9;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      c[i][j] = inf;
    }
  }
  queue<pi> q;
  q.push(make_pair(sy, sx));
  c[sy][sx] = 0;
  while (!q.empty()) {
    auto front = q.front();
    q.pop();
    int y = front.first;
    int x = front.second;
    if (y > 0 && s[y-1][x] == '.') {
      if (c[y][x] + 1 < c[y-1][x]) {
        c[y-1][x] = c[y][x] + 1;
        q.push(make_pair(y-1, x));
      }
    }
    if (y < h-1 && s[y+1][x] == '.') {
      if (c[y][x] + 1 < c[y+1][x]) {
        c[y+1][x] = c[y][x] + 1;
        q.push(make_pair(y+1, x));
      }
    }
    if (x > 0 && s[y][x-1] == '.') {
      if (c[y][x] + 1 < c[y][x-1]) {
        c[y][x-1] = c[y][x] + 1;
        q.push(make_pair(y, x-1));
      }
    }
    if (x < w-1 && s[y][x+1] == '.') {
      if (c[y][x] + 1 < c[y][x+1]) {
        c[y][x+1] = c[y][x] + 1;
        q.push(make_pair(y, x+1));
      }
    }
  }
  int ret = 0;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (s[i][j] == '.') {
        ret = max(c[i][j], ret);
      }
    }
  }
  return ret;
}
int main() {
  cin>>h>>w;
  for (int i=0; i<h; i++) {
    cin>>s[i];
  }
  int ans = 0;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if(s[i][j] == '.') {
        ans = max(bfs(i, j), ans);
      }
    }
  }
  cout<<ans<<endl;
}

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

int main(){
  int n,k; cin>>n>>k;
  vector<int>A(n);
  rep(i,n) cin>>A[i];
  for(int i=k; i<n; i++){
    if (A[i]>A[i-k]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;


int main(){
  ll n, k;
  cin >> n >> k;
  ll ans = k;
  rep(i, 0, n - 1)ans *= k - 1;
  cout << ans << endl;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INT_INF = 998244353;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    int K = 50;
    int A,B; cin >> A >> B;
    char s[2*K][2*K];
    REP(i,K)REP(j,2*K){s[i][j] = '#'; s[i+K][j] = '.';}
    int I=(A-1)/50, J=(A-1)%50; REP(i,I)REP(j,K) s[2*i][2*j] = '.';
    REP(j,J) s[2*I][2*j] = '.';
    I=(B-1)/50, J=(B-1)%50; REP(i,I)REP(j,K) s[2*i+K+1][2*j] = '#';
    REP(j,J) s[2*I+K+1][2*j] = '#';

    cout << 2*K << " " << 2*K << endl;
    REP(i,2*K){
        REP(j,2*K) cout << s[i][j];
        cout << endl;
    }
    return 0;
}

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

vector<int> val;
vector<vector<int>> g;
void dfs(int u, int p, int sm) {
    val[u] += sm;
    for (int v: g[u]) if (v != p) dfs(v, u, val[u]);
}

int main() {
    int n, q; cin >> n >> q;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    val.assign(n, 0);
    while (q--) {
        int p, x; cin >> p >> x; p--;
        val[p] += x;
    }
    dfs(0, -1, 0);
    for (int i = 0; i < n; i++) cout << val[i] << " \n"[i == n - 1];
    return 0;
}

Measured memory_bytes: 23424
/**
* Think twice, code once.
* 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-19-18.25.37 Thursday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const i64 maxn = (i64)1e5+1000;
i64 N, W, w[maxn], v[maxn], dp[110][maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> N >> W;
    for1(i, N) cin >> w[i] >> v[i];
    ms(dp, 0);
    for (int i = 1; i <= N; ++i) {
        for (int j = W; j >= 0; --j) {
            dp[i][j] = dp[i-1][j];
            if (j >= w[i]) dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]]+v[i]);
        }
    }
    cout << dp[N][W] << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 88320
package main

import "fmt"

func main(){
	var S string
	var s1 string
	var s2 string

	fmt.Scan(&S)

	N := len(S)
	f := 0
	j := N-1
	for i := 0 ; i < N / 2 ; i++ {
	//	fmt.Printf("%c %c\n",S[i], S[j])
		if S[i] != S[j] {
			f = 1
			break	
		}
		j--
	}
//	fmt.Println()
	s1 = S[:(N-1)/2]
	s2 = S[(N+3)/2-1: ]
	// for i := 0 ; i < (N-1)/2 ; i++ {
	// 	s1[i] = S[i]
	// }
	// for i := (N+3)/2 ; i < N ; i++ {
	// 	j := 0
	// 	s2[j] = S[i]
	// 	j++
	// }
	
//	fmt.Println(s1, s2)
	if s1 == s2 && f == 0{
		fmt.Println("Yes")
	}else {
		fmt.Println("No")
	}
}

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

#define each(i, c) for (auto& i : c)

typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll h, n;
  cin >> h >> n;

  vector<pair<ll, ll>> ab(n);
  for (ll i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    ab[i] = make_pair(a, b);
  }

  vector<ll> dp(h+10, 1e18);
  for (ll i = 0; i < h; ++i) {
    for (ll j = 0; j < n; ++j) {
      ll idx = i - ab[j].first;
      dp[i] = min(dp[i], idx < 0 ? ab[j].second : dp[idx] + ab[j].second);
    }
  }

  cout << dp[h-1] << endl;

  return 0;
}

Measured memory_bytes: 384
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


class WeightedUnionFind:
    def __init__(self, N):
        self.par = [i for i in range(N)]
        self.rank = [0] * N
        self.weight = [0] * N  # 親までの距離

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            r = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = r
            return r

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def diff_w(self, x, y):
        return self.weight[x] - self.weight[y]


def main():
    N, M = map(int, readline().split())
    m = map(int, read().split())
    LRD = list(zip(m, m, m))

    D = WeightedUnionFind(N)

    a = []
    for l, r, d in LRD:
        l -= 1
        r -= 1
        D.union(l, r, d)
        a.append(l)
        a.append(r)

    for i in set(a):
        D.find(i)

    for l, r, d in LRD:
        l -= 1
        r -= 1
        if d != D.diff_w(l, r):
            print('No')
            sys.exit()

    print('Yes')


main()


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e9
#define MOD 1000000007

int main()
{

    ll n, m;
    cin >> n >> m;
    vector<ll> v(m+1, 0);
    for(ll i = 0; i < n; i++)
    {

        ll k;
        cin >> k;
        for(ll j = 0; j < k; j++)
        {

            ll x;
            cin >> x;
            v[x]++;
        }
    }
    ll ans = 0;
    for(ll i = 1; i <= m; i++)
        if(v[i] == n) ans++;
    cout << ans;
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n,T = map(int,input().split())
    ans = INF
    for _ in range(n):
        c,t = map(int,input().split())
        if t <= T:
            ans = min(ans,c)
    
    if ans == INF:
        print('TLE')
    else:
        print(ans)
if __name__ =='__main__':
    main()   


Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;


const ll MAX = 1000000;
ll fac[MAX], finv[MAX], inv[MAX];
// nCk初期化
void nCkInit(const ll MOD) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll nCk(ll n, ll k,const ll MOD){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll N,K;
vector<P> edges;
void DispEdges(){
    cout<<edges.size()<<endl;
    for(auto e:edges){
        cout<<e.first<<" "<<e.second<<endl;
    }
}
int main(){
    cin>>N>>K;
    nCkInit(MOD);
    if(nCk(N-1,2,MOD)<K){
        cout<<-1<<endl;
        return 0;
    }
    for(ll i=2;i<=N;i++){
        edges.push_back(P(1,i));
    }
    if(nCk(N-1,2,MOD)==K){
        DispEdges();
        return 0;
    }
    ll counter=0;
    for(ll i=2;i<=N;i++){
        for(ll j=i+1;j<=N;j++){
            edges.push_back(P(i,j));
            counter++;
            if(counter>=nCk(N-1,2,MOD)-K){
                DispEdges();
                return 0;
            }
        }
    }
    cout<<"-1"<<endl;

    return 0;
}

Measured memory_bytes: 23936
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,k;cin>>n>>k;
  if(n==1||k==1){
    cout<<1<<endl;
  }else{
    long long ans=(n*k+1)/2;
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

	static long expo(long base, long exp) {
		long t = 1L;
		while (exp > 0) {
			if (exp % 2 != 0)
				t = (t * base);

			base = (base * base);
			exp /= 2;
		}
		return t;
	}

	public static void main(String args[]) throws Exception {
		MyScanner sc = new MyScanner();
		PrintWriter pr = new PrintWriter(System.out);
		int n = sc.nextInt();
		long k = sc.nextLong();
		int ar[] = new int[n + 1];

		ar[0] = 0;
		HashSet<Integer> selfloop = new HashSet<>();
		for (int i = 1; i <= n; i++) {
			ar[i] = sc.nextInt();
			if (ar[i] == i)
				selfloop.add(i);
		}

		int cyclelen = 0;
		int cyclestart = 0;
		HashSet<Integer> set = new HashSet<>();
		int source = 1;
		set.add(1);
		boolean flag = false;
		while (cyclelen < k) {

			source = ar[source];
			cyclelen++;
			if (selfloop.contains(source)) {
				flag = true;
				break;
			}
			if (set.contains(source)) {
				cyclestart = source;
				break;
			} else
				set.add(source);

		}

		if (flag) {
			System.out.println(source);
			return;
		}

		if (cyclelen == k) {
			System.out.println(source);
			return;
		}

		ArrayList<Integer> cycle = new ArrayList<>();
		cycle.add(cyclestart);
		set.clear();
		set.add(cyclestart);
		int a = cyclestart;
		while (true) {

			a = ar[a];
			if (set.contains(a))
				break;
			else {
				set.add(a);
				cycle.add(a);
			}
		}

		/*
		 * for(int i : cycle) System.out.print(i + " ");
		 */

		k -= cyclelen;
		pr.println(cycle.get((int) (k % cycle.size())));
		pr.close();
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

Measured memory_bytes: 62308
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int M;
  cin>>M;
  ll ans = 0;
  ll sum = 0;
  ll d, c;
  for(int i=0;i<M;++i) {
    cin>>d>>c;
    ans += c;
    sum += d*c;
  }
  ans--;
  if(sum%9==0) cout<<ans+sum/9-1<<endl;
  else cout<<ans+sum/9<<endl;
}



Measured memory_bytes: 3636
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
idxa = 0
idxc = 0
ans = 0
for b in range(N):
    while idxa < N and A[idxa] < B[b]:
        idxa += 1
    while idxc < N and B[b] >= C[idxc]:
        idxc += 1
    ans += idxa * (N - idxc)
print(ans)


Measured memory_bytes: 23328
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

int prefix_w[300001];
int prefix_e[300001];

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (s[0] == 'E')
		prefix_e[0] = 1;
	else
		prefix_w[0] = 1;
	for (int i = 1; i < n; i++) {
		if (s[i] == 'E') {
			prefix_e[i] = prefix_e[i - 1] + 1;
			prefix_w[i] = prefix_w[i - 1];
		}
			
		else if (s[i] == 'W') {
			prefix_w[i] = prefix_w[i - 1] + 1;
			prefix_e[i] = prefix_e[i - 1];
		}
			
	}
	int ans = 987654321;
	for (int i = 1; i < n - 1; i++) {
		int tot = prefix_w[i - 1] + prefix_e[n - 1] - prefix_e[i];
		if (ans > tot)
			ans = tot;
	}
	ans = min(ans, prefix_e[n - 1] - prefix_e[0]);
	ans = min(ans, prefix_w[n - 2]);
	cout << ans;
	return 0;
		

}

	

Measured memory_bytes: 2948
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <unordered_map>
using namespace std;

#define rep_init(i, init, n) for(int i = (init); i < (n); ++i)
#define rep(i, n) rep_init(i, 0, n)

template<typename T>
constexpr T divide_ceil(T a, T b)
{
	T remainder = a % b;
	return remainder == 0 ? a / b : (a + (b - remainder)) / b;
}

void Main()
{
	int N, D, X;
	cin >> N >> D >> X;
	rep(i, N)
	{
		int A;
		cin >> A;
		X += divide_ceil(D, A);
	}

	cout << X << endl;
}

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

	Main();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(long long i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll INF=(1ll<<60);
constexpr ll mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    vector<ll> a(5);
    ll ans=0;
    rep(i,5){
        cin>>a[i];
    }

    ll MIN=11,key;
    rep(i,5){
        if(MIN>(a[i]%10==0?10:a[i]%10)){
            MIN=(a[i]%10==0?10:a[i]%10);
            key=i;
        }
    }

    rep(i,5){
        if(i==key){
            ans+=a[key];
        }else{
            ans+=(a[i]+9)/10*10;
        }
    }

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

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MOD=1000000007;
int INF=100100100100100;
int add(int a,int b){
  return (a+b)%MOD;
}
int prod(int a,int b){
  return (a*b)%MOD;
}

int beki(int a,int b)
{
	if(b==0)return 1;
	int x=beki(a,b/2);
	if(b%2==0)return (x*x)%MOD;
	else return (((a*x)%MOD)*x)%MOD;
}

int inv(int a)
{
	return beki(a,MOD-2);
}

int kaijou(int a)
{
	int ans=1;
	for(int i=1;i<=a;i++)
	{
		ans=(ans*i)%MOD;
	}			
	return ans;
}

/*int combi(int a,int b)
{
	int ret=1;
	for(int i=1;i<=b;i++)
	{
		ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
	}
	return ret;
}*/
/*
const int MAX_a=200010;
int cb[MAX_a+1]
void combi(int a,int b)
{
    int ret=1;
    cb[0]=1;
    for(int i=1;i<=b;i++)
    {
	ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
        cb[i]=ret;
    }
	
}*/

vector<P> prime_factorize(int N)
{
	vector<P> res;
	for(int a=2;a*a<=N;a++)
	{
		if(N%a!=0)continue;
		int ex=0;
		while(N%a==0)
		{
			ex++;N/=a;
		}
		res.push_back(P(a,ex));
	}
	if(N!=1)res.push_back(P(N,1));
	return res;
}

//ここから書く
signed main(){
  int n;cin>>n;
  string s;cin>>s;
  int ans=0;
  rep(i,n){
    int res=0;
    set<char> st;
    rep(j,i){
      st.insert(s[j]);
    }
    for(int j=i;j<n;j++){
      if(st.find(s[j])!=st.end()){
        res++;
        st.erase(s[j]);
      }
    }
    chmax(ans,res);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
using namespace std;
const int MAXN = 10005;
const int INF = 1 << 30;
const int NIL = -1;
struct Node {
	int v, w, next;	//u->v
	friend bool operator<(const Node& a, const Node& b)
	{
		return a.w > b.w;
	}
	Node() {}
	Node(int vv, int ww) : v(vv), w(ww) {}
};
int cnt;
int head[MAXN];
Node edge[MAXN];




int prim(int n)
{
	
	bool vis[MAXN]{ false };
	priority_queue<Node> q;
	vis[1] = true;

	for (int i = head[1]; i != NIL; i = edge[i].next)
		q.push(edge[i]);
	int count = 0;
	int ans = 0;
	Node t;
	while (count < n - 1)
	{
		t = q.top();
		q.pop();
		if (vis[t.v])
			continue;
		vis[t.v] = true;
		ans += t.w;
		++count;
		for (int i = head[t.v]; i != NIL; i = edge[i].next)
			if (!vis[edge[i].v])
				q.push(edge[i]);

	}
	
	return ans;
}


void add(int u, int v, int w)
{
	edge[cnt].v = v;
	edge[cnt].w = w;
	edge[cnt].next = head[u];
	head[u] = cnt++;
}



int main(void)
{
	int n, m, u, v, w;
	scanf("%d", &n);
	int N = n * n;
	for (int i = 0; i <= N; ++i)
		head[i] = NIL;
	cnt = 0;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			scanf("%d", &w);
			if (w != NIL)
				add(i, j, w);
		}
	}
	cout << prim(n) << endl;
	return 0;
}

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

int main(){
  long long n,a,b;
  cin>>n>>a>>b;
  if(n%(a+b)>=a){
    cout<<(n/(a+b))*a+a<<endl;
  }
  else{
    cout<<(n/(a+b))*a+n%(a+b)<<endl;
  }
}
           
           


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
int cnta[100003];
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
	{
		int tmp;
		scanf("%d",&tmp);
		++cnta[tmp];
	}
	int ans=0;
	for (int i=1;i<100000;++i)
		ans=max(ans,cnta[i-1]+cnta[i]+cnta[i+1]);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
const int mod = 1000000007;

int main() {
    string s;
    cin >> s;
    if (s.at(s.size() - 1) == 's') {
        cout << s << "es" << endl;
    }
    else {
        cout << s << "s" << endl;
    }
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int mn = INF;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(mn > p[i]) {
            mn = p[i];
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

#define MAX 100

void initialize(void);
void push(int);
int pop(void);
int isEmpty(int);
int isFull(int);

int top;
int S[1000];

int main(){

  int c = 0;
  int pop2;
  char s;

  initialize();

  while(scanf("%c",&s) != EOF ){
    if(s == ' '){
      if(c!=0)push(c);
      c = 0;
      continue;
    }
    
    if(s == '+'){
      push(pop() + pop());
    }
    else if(s == '*'){
      push(pop() * pop());
    }
    else if(s == '-'){
      pop2 = pop(); //??????push?????????
      push(pop() - pop2);
    }
    else if(s == '\n'){
      printf("%d\n", pop());
      break;
    }
    else {
      c = c * 10 + atoi(&s);
    }
  }
  
  return 0;
}

void initialize(void){
  top = 0;    
}

void push(int x){
  if(isFull(top) == 1){
    printf("??¨?????????????????????????????????\n");
    exit(1);
  }
  S[++top] = x;
}

int pop(void){
  
  if(isEmpty(top) == 1){
    printf("??¨???????????¢?????????????????????\n");
    exit(2);
    return 0;
  }    
  
  top--;
  return S[top+1];
}

int isEmpty(int top){
  if(top == 0) return 1;
  return 0;
}

int isFull(int top){
  if(top >= MAX) return 1;
  return 0;
}

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

int main() {
  long int n,a,b;
  cin >> n >> a >> b;
  if((a-b)%2==0){
    if(a>b){
      cout << (a-b)/2 << endl;
    }else{
      cout << (b-a)/2 << endl;
    }
  }else{
    cout << min((a+b-1)/2,n-(a+b-1)/2) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;

int main(){
    string s;
    cin>>s;
    int n=0;
    int k=7;
    REP(i,SZ(s)){
        if(i==4||i==7)continue;
        n+=(s[i]-'0')*pow(10,k);
        k--;
    }
    if(n>20190430)OUT("TBD");
    else OUT("Heisei");
    return 0;
}

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

using namespace std;
const int INF = 0x3f3f3f3f;
//static const auto _____ = []()
//{
//	ios::sync_with_stdio(false);
//	cin.tie(nullptr);
//	return nullptr;
//}();

int main(int argc, char *argv[]) {
    int N, K;
    cin >> N >> K;
    vector<int> h(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
    }
    vector<int> dp(N + 1, INF);
    dp[1] = 0;
    for (int i = 2; i <= N; i++) {
        for (int k = 1; k <= K; k++) {
            if (i - k < 0) break;
            dp[i] = min(dp[i], dp[i - k] + abs(h[i] - h[i - k]));
        }
    }
    cout << dp[N];
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int i;
  char S[6] = {};
  char c;
  for(i=0;i<6;i++){
    scanf("%c",&c);
    S[i] = c;
  }
  if(S[2] == S[3] && S[4] == S[5]){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 1640
#include<iostream>
using namespace std;
int main()
{
    int x1,x2,x3,x4,x5;
    while(cin>>x1>>x2>>x3>>x4>>x5)
    {
        if(x1==0)
            cout<<"1"<<endl;
        else if(x2==0)
            cout<<"2"<<endl;
        else if(x3==0)
            cout<<"3"<<endl;
        else if(x4==0)
            cout<<"4"<<endl;
        else
            cout<<"5"<<endl;
    }
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf=1e9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};	

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

	string s="";
	for (int i = 0; i < n; i++){
		s+='0';
	}

	pair<int,char> v[10];
	for (int i = 0; i < m; i++){
		cin>>v[i].first>>v[i].second;
		if(v[i].first==1&&v[i].second=='0'&&n>1){
			cout<<-1<<endl;
			return 0;
		}
		s[v[i].first-1]=v[i].second;
	}

	for (int i = 0; i < m; i++){
		if(s[v[i].first-1]!=v[i].second){
			cout<<-1<<endl;
			return 0;
		}
	}

	if(s[0]=='0'&&n>1)s[0]='1';

	cout<<s<<endl;

	return 0;
}



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

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) throws IOException {
        int n = scanner.nextInt();
        double[] d = new double[n];
        for (int i = 0; i < n; i++) {
            d[i] = scanner.nextInt();
        }
        Arrays.sort(d);
        double a = d[0];
        for (int i = 1; i < n; i++) {
            a = (a + d[i]) / 2;
        }
        System.out.println(a);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            return tokenizer.nextToken();
        }

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

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

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

int main()
{
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int sum = 0;
	for (int i = 0; i < A + 1; i++) {
		for (int j = 0; j < B + 1; j++) {
			for (int k = 0; k < C + 1; k++) {
				if (X - i * 500 - j * 100 - k * 50 == 0) {
					sum += 1;
                }
			}
		}
	}
	cout << sum << endl;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
// UnionFind : グループを管理する
// verified: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3168234#1
// 以下の2種類の操作を効率的に行う
// unionSet(x, y) : 頂点xが属するグループと頂点yが属するグループを結合する
// findSet(x, y) : 頂点xが属するグループと頂点yが属するグループが異なるかを返す
// また、次の操作も便利である
// root(x): xのグループ番号(UnionFind木における根の頂点の番号)を返す
// getGroupNum() : 現在のグループ数を返す
// getGroups() : グループを表すvectorを返す([[1, 2], 3] など)
struct UnionFind {
    vector<int> data;
    int gnum;
    UnionFind(int size) : data(size, -1), gnum(size) {}
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
            gnum--;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
    int getGroupNum() {
        return gnum;
    }
    vector<vector<int>> getGroups() {
        int now = 0;
        map<int, vector<int>> G;
        for (int i = 0; i < data.size(); i++) {
            G[root(i)].push_back(i);
        }
        vector<vector<int>> ret;
        for(auto g : G) {
            ret.push_back(g.second);
        }
        return ret;
    }
};


void solve() {
    int N;
    cin >> N;
    UnionFind uf(N);
    if (N % 2 == 0) {
        for (int i = 0; i < N / 2; i++) {
            uf.unionSet(i, N - i - 1);
        }
    } else {
        N--;
        for (int i = 0; i < N / 2; i++) {
            uf.unionSet(i, N - i - 1);
        }
        N++;
    }

    vector<pii> ans;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (uf.root(i) != uf.root(j)) {
                ans.push_back({i,j});
            }
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
    }
    
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 384
N, A, B, C, D = map(int, input().split())

B -= A

ans = "NO"
for k in range(N):
    p = k
    q = N - k - 1
    Upper = D * p - C * q
    Lower = C * p - D * q
    if Lower <= B <= Upper:
        ans = "YES"
        break

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll a,ll b,ll c)
{
    KAKA
    ll sum = a+b+c;
    if(sum >= 22) cout<<"bust"<<"\n";
    else cout<<"win"<<"\n";
}
int main()
{
    KAKA
    ll a,b,c;
    cin>>a>>b>>c;
    Compute(a,b,c);
}

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

using namespace std;

bool dp[10010];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> s(n);
	for (int i = 0; i < n; i++) cin >> s[i];
	dp[0] = true;
	for (int i = 0; i < n; i++) {
		for (int j = 10000; j >= s[i]; j--) {
			dp[j] |= dp[j - s[i]];
		}
	}

	int ans = 0;
	for (int i = 10000; i >= 0; i--) {
		if (dp[i] && i % 10 != 0) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
bool f(string a, string b) {
	for (int i = 0; i < 8; i++)if (a[i] != '*'&&a[i] != b[i])return 0; return 1;
}
string p[123]; int q[123];
signed main() {
	while (1) {
		int n, m, sum = 0;
		cin >> n >> m;
		if (!n)return 0;
		for (int i = 0; i < n; i++)cin >> p[i] >> q[i];
		for (int i = 0; i < m; i++) {
			string k; cin >> k;
			for (int j = 0; j < n; j++)if (f(p[j], k))sum += q[j];
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 3136