akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

signed main()
{
    int N; cin >> N;
    vector<pii> tasks;
    rep(i, N) {
        int a, b; cin >> a >> b;
        tasks.push_back(pii(b, a));
    }
    sort(all(tasks));

    int t = 0;

    rep(i, N) {
        t += tasks[i].second;
        if (t > tasks[i].first) {
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";
}


Measured memory_bytes: 2420
#include <iostream>
using namespace std;
int a[100002];
int kekka[100002];
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		kekka[a[i]]=i;
	}
	cout<<kekka[1];
	for(int i=2;i<=n;i++)
	{
		cout<<" "<<kekka[i];
	}
}

Measured memory_bytes: 1536
(defvar N (read))
(defvar Q (read))

(defvar lst (concatenate 'list (read-line)))

(defvar count-ac 
  (concatenate 'vector
               (cons 0 (loop for si in (cdr lst) 
                             for si-1 
                             in lst
                             with counter = 0 
                             if (and (eq si-1 #\A) (eq si #\C))
                             do (incf counter)
                             collect counter))))

(defun solve (L R)
  (- (aref count-ac (1- R))
     (aref count-ac (1- L))))


(loop repeat Q do
      (princ (solve (read) (read)))
      (terpri))

Measured memory_bytes: 60360
#include<cstdio>

int main()
{
	int x, n, maxv, minv;
	scanf("%d", &n);
	scanf("%d%d", &minv, &x);
	maxv=x-minv;
	if(minv>x) minv=x;
	for(int i=2;i<n;++i)
	{
		scanf("%d", &x);
		maxv=maxv>(x-minv)?maxv:(x-minv);
		minv=minv<x?minv:x;
	}
	printf("%d\n", maxv);
	return 0;
}


Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
int n,m,l[100005],r[100005],ans,x,y;
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++) cin>>l[i]>>r[i];
	ans=r[1]-l[1]+1;
	x=l[1];
	y=r[1];
	for(int i=2;i<=m;i++)
	{
		if(l[i]>x)
		{
			if(l[i]>y) {cout<<0;return 0;}
			else ans-=(l[i]-x);
			x=l[i];
		}
		if(r[i]<y)
		{
			if(r[i]<x) {cout<<0;return 0;}
			else ans-=(y-r[i]);
			y=r[i];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict

n,m,x=map(int, input().split())
c=[]
tab=[]
cost = 10000000000
for i in range(n):
    A=[int(i) for i in input().split()]
    tab.append(A[1:])
    c.append(A[0])
for i in range(1<<n):
    tmp=0
    res = [0]*m
    for j in range(n):
        if(i&(1<<j)):
            tmp+=c[j]
            for k in range(m):
                res[k]+=tab[j][k]
    f=True
    for v in res:
        if v<x:
            f=False

    if f:
        cost = min(cost, tmp)



if cost!=10000000000:
    print(cost)
else:
    print(-1)


Measured memory_bytes: 9452
#include <stdio.h>
int main(){
  int i, j, k;
  int length;
  int key;
  int A[100];
  scanf("%d",&length);
  for( i=0; i <= length-1; i++ )
    {
      scanf("%d", &A[i]);
    }
  for( k = 0; k <= length-1; k++ )
    {
      printf("%d", A[k]);
      if( k != length-1 )
	{
	  printf(" ");
	}
    }
  printf("\n");
  for( i = 1; i <= length-1; i++ )
    {
      key = A[i];
      j = i - 1;
      while( j >= 0 && A[j] > key )
	{
	  A[j+1] = A[j];
	  j--;
	}
      A[j+1] = key;
      for( k = 0; k <= length-1; k++ )
	{
	  printf("%d", A[k]);
	  if( k != length-1 )
	    {
	      printf(" ");
	    }
	}   
      printf("\n");
    }
  return 0;
}

Measured memory_bytes: 604
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

puts gc.sort.join == "abc" ? 'Yes' : 'No'

Measured memory_bytes: 2300
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())

print(l[k-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  int A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;
  int atai=A*X+B*Y;
  int kotae=atai;
  int keisan=INT_MAX;
    rep(i,max(X+1,Y+1)){
      if((X-i)<=0){
        A=0;
      }
      else if((Y-i)<=0){
        B=0;
      }
      keisan=A*(X-i)+B*(Y-i)+i*2*C;
      //cout<<keisan<<endl;
      kotae=min(kotae,keisan);
    }
  cout <<kotae<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

n = int(input())
s = list(input())
s = [int(i) for i in s]


def is_valid(s, pin):
    i, j, k = pin
    s_tmp = s[:]
    if i not in s_tmp:
        return False
    i_idx = s_tmp.index(i)
    s_tmp = s_tmp[i_idx + 1:]
    if j not in s_tmp:
        return False
    j_idx = s_tmp.index(j)
    s_tmp = s_tmp[j_idx + 1:]
    if k not in s_tmp:
        return False
    return True


num = 10
res = 0
for i in range(num):
    for j in range(num):
        for k in range(num):
            pin = [i, j, k]
            if is_valid(s, pin):
                # print(f"{pin} is valid pin")
                res += 1

print(res)


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

using namespace std;

typedef long long LL;

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

  int T = 1;
  // cin >> T;
  string buf;
  typedef complex<double> V;
  const double eps = 1e-9;
  for (int n; T-- > 0 && cin >> n; ) {
    vector<V> pts;
    for (int i = 0, x, y; i < n && cin >> x >> y; ++i) pts.push_back(V(x, y));

    auto test = [&](double r) {
      for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (i != j) {
        if (abs(pts[i] - pts[j]) > r * 2) return false;
        V p = (pts[i] + pts[j]) / 2.0;
        V v = (pts[j] - pts[i]) * V(0, 1.0);
        double d = abs(pts[i] - pts[j]) / 2;
        double l = sqrt(r * r - d * d);
        V o = p + v / abs(v) * l;
        // cout.precision(17);
        // cout << pts[i] << ' ' << pts[j] << ' ' << fixed << r << ' ' << o << endl;
        bool all = true;
        for (int u = 0; u < n; ++u) if (abs(o - pts[u]) > r + eps) {
          all = false;
          break;
        }
        if (all) return true;
      }
      return false;
    };

    double lo = 0, hi = 2000;
    for (int rpt = 300; rpt-- > 0; ) {
      double r = (lo + hi) / 2;
      if (test(r)) hi = r; else lo = r;
    }
    cout.precision(17);
    cout << fixed << hi << '\n';
  }

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	if(a[0]==a[1]||a[1]==a[2]||a[2]==a[3]){
		cout<<"Bad"<<endl;
		return 0;
	}
	cout<<"Good"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)
using namespace std;

int main(){
  	int n,a[200],cnt = 0;
  	cin >> n;
  	
  	rep(i,0,n) cin >> a[i];
  
  	while(1){
      rep(i,0,n){
        if(a[i] % 2 != 0){
          cout << cnt << endl;
          return 0;
        }
      }
      
      rep(i,0,n){
        a[i] = a[i] / 2;
      }
      
      cnt++;
    }
	return 0; 
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int S, A, B, C;
    int a,b,c,d,e,f;
    int M[3][3] = {0};

    scanf("%d%d%d",&A,&B,&C);
    S = 3*C;

    a=S-A-B;
    f=S-C-A;
    c=S-a-f;
    b=S-C-c;
    d=S-A-b;
    e=S-B-C;

    printf("%d %d %d\n", A, B, a);
    printf("%d %d %d\n", b, C, c);
    printf("%d %d %d\n", d, e, f);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(){

  int i,j,n,m;
  while(1){
    scanf("%d%d",&n,&m);
    if(n==0&&m==0){
      // printf("\n");
      break;
    }
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	printf("#");
      }
       printf("\n");
    }
    printf("\n");


  }


  return 0;
}



Measured memory_bytes: 2100
N=int(input())
A=list(map(int,input().split()))
Q=int(input())

from collections import Counter
sum_ = sum(A)

Counter_A = Counter(A)

for q in range(Q):
    B,C = list(map(int,input().split()))
    B_num = Counter_A[B]
       
    sum_ = sum_+(C-B)*B_num
    print(sum_)
    
    #Counter 更新
    Counter_A[B]=0
    Counter_A[C]=Counter_A[C]+B_num

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

using namespace std;

int main ()
{
   int a;
   cin>>a;
   int ar[a];
   for(int i=0;i<a;i++)
   {
       cin>>ar[i];
   }
   sort(ar,ar+a);
   cout<<ar[a-1]-ar[0];
  return 0;
}


Measured memory_bytes: 256
line = gets.chomp.split().map(&:to_i) # [7,3] int
cross = line[0] * line[1]
if line[0] == 1 || line[1] == 1 then
    ans = 1 # 1があると動けないのでまずい
else
   cross.even? ? ans = cross / 2 : ans = (cross / 2) + 1
end

puts ans

Measured memory_bytes: 1788
from heapq import heappush,heappop

N,M,S=map(int,input().split())
edges = [tuple(map(int,input().split())) for _ in range(M)]
cd = [tuple(map(int,input().split())) for _ in range(N)]
INF= 10**15
mod=55

mmax = sum([edges[i][2] for i in range(M)])
if S>mmax:
  S = mmax

G=[{} for _ in range((mmax+1)*mod+N+1)]
for i in range(M):
  u,v,a,b=edges[i]
  for p in range(a,mmax+1):
    G[u+p*mod][v+(p-a)*mod] = b
    G[v+p*mod][u+(p-a)*mod] = b
    
for i in range(N):
  c,d=cd[i]
  for p in range(mmax+1-c):
    G[i+1+p*mod][i+1+(p+c)*mod] = d
    
def dijkstra(start = 0):
    
    d = [INF for i in range(len(G)+1)]
    d[start] = 0
    
    que = []
    heappush(que, (0, start))

    while len(que):
        p = heappop(que)
        v = p[1]
        
        if d[v] < p[0]:
            continue
            
        for u in G[v].keys():
            if d[u] > d[v] + G[v][u]:
                d[u] = d[v] + G[v][u]
                heappush(que, (d[u], u))
    
    return d
  
start = 1+S*mod
d = dijkstra(start)

ans=[INF]*(N+1)
for i in range(2,len(G)+1):
  v = i%mod
  if v>N or v<2:continue
  ans[v] = min(ans[v],d[i])
  
print(*ans[2:])

Measured memory_bytes: 84912
const main = stdin => {
  const input = stdin.trim().split('\n')

  const [A, B, T] = input[0].split(' ').map(x => parseInt(x))
  console.log(Math.floor(T / A) * B)
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 29520
//a<b<c
#include<stdio.h>

int main()
{
	int a,b,c,i;

	scanf("%d %d %d",&a,&b,&c); //3?????°??\???

	if(a<b){					//a<b ?????????Yes ?????????????????\????????? No

			if(b<c){			//b<c ?????????Yes ?????????????????\????????? No
					printf("Yes\n");
				}else{
					printf("No\n");
				}
		}else{
			printf("No\n");	
		}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;//1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> PDL;
typedef pair<LD, LD> PDD;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

template<class Rng>
void in(Rng& x) {
	cin >> x;
}

template<class T1, class T2>
void in(pair<T1, T2>& p) {
	in(p.first);
	in(p.second);
}

template<class Rng>
void in(vector<Rng>& v, LL st = -1, LL en = -1) {
	if (st == -1) {
		st = 0;
		en = v.size() - 1;
	}
	for (LL n = st; n <= en; n++) {
		in(v[n]);
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	VLL A(N*N + 1,-1);
	vector<PLL> V(N+1);
	V[0] = PLL(0, 1e10);
	for (LL n = 1; n <= N; n++) {
		V[n].first = n;
		cin >> V[n].second;
	}
	sort(V.begin(), V.end(), [](PLL a, PLL b) {
		return a.second < b.second;
	});
	LL r = 0;
	for (LL n = 0; n < N; n++) {
		LL i = V[n].first;
		LL xi = V[n].second;
		if (A[xi] == -1) {
			A[xi] = i;
		}
		else {
			cout << "No\n";
			return 0;
		}
		LL t = 0;
		while (t < i - 1) {
			if (xi <= r) {
				cout << "No\n";
				return 0;
			}
			if (A[r + 1] == -1) {
				A[r + 1] = i;
				t++;
			}
			r++;
		}
	}
	LL l = N * N + 1;
	for (LL n = N - 1; n >= 0; n--) {
		LL i = V[n].first;
		LL xi = V[n].second;
		LL t = 0;
		while (t < N - i) {
			if (xi >= l) {
				cout << "No\n";
				return 0;
			}
			if (A[l - 1] == -1) {
				A[l -1] = i;
				t++;
			}
			l--;
		}
	}
	cout << "Yes\n";
	for (LL n = 1; n < N * N; n++) {
		cout << A[n] << " ";
	}
	cout << A.back() << "\n";
	return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

long long H, W;
vector<long long> v;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> H >> W ;
	long long S, s, ans, w, h, a, b ,c;

	if((H % 3) == 0 || (W % 3) == 0){
		ans = 0;
		printf("%lld\n", ans);
		return 0;
	}
	
	w = W / 3;
	h = H / 2;
	for(int i = -1; i <= 1; i++){
		if(w+i<1 || w+i>=W) continue;
		for(long long j = -1; j <= 1; j++){
			if(h+j<1 || h+j>=H) continue;
			a = H * (w+i);
			b = (h+j)*(W-(w+i));
			c = (H-(h+j))*(W-(w+i));
			S = max( a, max( b, c ) );
			s = min( a, min( b, c ) );
			v.push_back(S - s);
		}
	}
	
	h = H / 3;
	w = W / 2;
	for(int i = -1; i <= 1; i++){
		if(h+i<1 || h+i>=H) continue;
		for(long long j = -1; j <= 1; j++){
			if(w+j<1 || w+j>=W) continue;
			a = (h+i) * W;
			b = (H-(h+i))*(w+j);
			c = (H-(h+i))*(W-(w+j));
			S = max( a, max( b, c ) );
			s = min( a, min( b, c ) );
			v.push_back(S - s);
		}
	}

	h = H / 3;
	for(int i = -1; i <= 1; i++){
		for(int j= -1; j <= 1; j++){
			a = (h + i) * W;
			b = (h + j) * W;
			c = (H - (h+i) - (h+j)) * W;
            if(a <= 0 || b <= 0 || c <= 0) continue;
			S = max(a, max(b, c));
			s = min(a, min(b, c));
			v.push_back(S - s);
		}
	}

	w = W / 3;
	for(int i = -1; i <= 1; i++){
		for(int j= -1; j <= 1; j++){
			a = (w + i) * H;
			b = (w + j) * H;
			c = (W - (w+i) - (w+j)) * H;
            if(a <= 0 || b <= 0 || c <= 0) continue;
			S = max(a, max(b, c));
			s = min(a, min(b, c));
			v.push_back(S - s);
		}
	}

	sort(v.begin(), v.end());
	ans = v[0];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    if (a == b) {
        cout << 0 << '\n';
        return 0;
    }
    ll ans = 0;
    ll dif = 0;
    ll s = 1e18, t = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] <= b[i]) {
            ans += a[i];
            dif += b[i] - a[i];
        } else {
            s = min(s, b[i]);
            ans += a[i];
        }
    }
    cout << ans - s << '\n';
    return 0;
}


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

const int MOD = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> dp(n + 2);
  for (int i = 0; i < m; ++i) {
    int a; cin >> a;
    dp[a] = -1;
  }
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    if (dp[i] == -1) continue;
    if (dp[i + 1] != -1) dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
    if (dp[i + 2] != -1) dp[i + 2] = (dp[i + 2] + dp[i]) % MOD;
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 640
r,g,b,n = map(int,input().split())

result = 0
max_r = n // r

for i in range(max_r + 1):
    max_g = (n - i * r) // g
    for j in range(max_g + 1):
        if (n - i * r - j * g ) % b == 0:
            result += 1
print(result)

Measured memory_bytes: 2940
def get_num(n, x):
    ans = 0
    for n3 in range(min(n, x), (x + 2) / 3, -1):
        for n2 in range(n3 - 1, 1, -1):
            for n1 in range(n2 - 1, 0, -1):
                s = n1 + n2 + n3
                if s == x:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x == 0:
        print(0)
    else:
        print(get_num(n, x))

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

int main()
{
	ll N;
	vector<ll> A(5);
	cin >> N;
	for(int i(0); i<5; ++i) cin >> A[i];
	sort(A.begin(),A.end());
	if(N > A[0]){
		if(N%A[0] == 0) {cout << N/A[0] + 4 << endl;}
		else{cout << N/A[0] + 5 << endl;}
	}else{
		cout << 5 << endl;
	}
	return 0;
}

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

int main() {
    int num;
    int point_tarou = 0;
    int point_hanako = 0;
    string t, h;

    cin >> num;

    for (int i = 0; i < num; i++) {
        cin >> t >> h;
        if (t < h) {
            point_hanako += 3;
        } else if (t > h) {
            point_tarou += 3;
        } else {
            point_hanako++;
            point_tarou++;
        }
    }

    cout << point_tarou << " " << point_hanako << endl;
    return 0;
}


Measured memory_bytes: 3132
//
// Created by 永徳泰明 on 2019-01-27.
//

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;
#define dump(x)  cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define fill(x, y) memset(x,y,sizeof(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 999999999;

void readFromInputFile() {
#ifdef LOCAL
    static std::ifstream in("/Users/hoo/CLionProjects/for_atcoder/input");
    std::cin.rdbuf(in.rdbuf());
#endif
}

int main() {
    //readFromInputFile();
    int n;
    string s[3];

    cin>>n;
    rep(i,3){
        cin>>s[i];
    }

    int sum = 0;
    rep(i,n){
        if (s[0][i]==s[1][i] && s[1][i] == s[2][i]) {
            continue;
        } else if (s[0][i]!=s[1][i] && s[1][i] != s[2][i] && s[0][i] != s[2][i]){
            sum += 2;
        } else {
            sum += 1;
        }
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    double x1, y1, x2, y2, xq, yq, m;

    while ((scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq)) != EOF) {
        x2 -= x1;
        y2 -= y1;
        xq -= x1;
        yq -= y1;
        m = (x2 * xq + y2 * yq) / (x2 * x2 + y2 * y2);
        printf("%.6lf %.6lf\n", x1 + 2*m*x2 - xq, y1 + 2*m*y2 - yq);
    }

    return 0;
}

Measured memory_bytes: 656
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    [n, _, w] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    as <- V.fromList . map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    print $ if n == 1
        then abs (w - V.head as)
        else max (abs (V.last as - V.last (V.init as))) (abs (V.last as - w))


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int N, K;
int h[100100];

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K;
    rep(i, N) cin >> h[i];
    sort(h, h+N);
    int ans = 10000000000;
    rep(i, N-K+1) ans = min(ans, h[i+K-1]-h[i]);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>
#include <string> 
using namespace std;

int main(){
	string num;
	getline(cin,num);
			for(int i=0;num[i]!='\0';i++){
				if(num[i]>='a'&& num[i]<='z'){
					num[i]+='A'-'a';
				}
			}
		cout << num << "\n";
	
	return 0;
}

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


vector<double> pros;
vector<vector<double>> record;

double cal(){
    int size = pros.size();
    vector<vector<double> > record = vector<vector<double> >(size+1, vector<double>(size+1, 0));

    record[0][0] = 1;

    for(int i = 1; i <= size; i++){
        for(int j = 0; j <= i; j++){
            if(j != 0){
                record[i][j] += record[i-1][j-1] * pros[i-1];
            }

            record[i][j] += record[i-1][j] * (1-pros[i-1]);
        }
    }

    int larger = (size+1) / 2;
    double sum = 0;
    for(int i = larger; i <= size; i++){
        sum += record[size][i];
    }

    return sum;
}

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

    pros = vector<double>(n);

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

    double result = cal();

    cout << setprecision(10) << result << "\n";

    return 0;
}


Measured memory_bytes: 70656
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VL hash(256, 0);
    REP(i, n) {
        string s;
        cin >> s;
        hash[(int)s[0]]++;
    }
    string march = "MARCH";
    ll ans = 0;
    FOR(i, 0, 4)FOR(j, i + 1, 4)FOR(k, j + 1, 4)
        ans += hash[(int)march[i]] * hash[(int)march[j]] * hash[(int)march[k]];
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define P(x) cout << x << endl
#define D(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(int)(n); i++)
#define DEC(i,n) for (int i=(int)(n); --i>=0;)
#define S(s) (int)((s).size())
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,(v))
#define MA(a,v) a = max(a,(v))
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
const int N=1e5+5;

void print(V<int> a) {
    F(i,S(a)) cout<<a[i]<<" \n"[i==S(a)-1];
}

int numSteps(V<int> a, V<int> b) {
    //print(a); print(b);
    V<int> asort=a, bsort=b;
    sort(ALL(asort)), sort(ALL(bsort));
    if (asort != bsort) return -1;
    int step=0;//, incor=0;
    map<int,V<int>> should;
    F(i,S(a)-1) {
        if (a[i] != b[i]) {
            should[b[i]].pb(i);
            //incor++;
        }
    }
    /*F(i,S(a)) {
        int place = is[b[i]];
        if (place != i)
            should[b[i]] = place;
    }*/
    while (S(should)) {
        step++;
        if (should.count(a.back())) {
            int place = should[a.back()].back();
            should[a.back()].pop_back();
            if (!S(should[a.back()]))
                should.erase(a.back());
            swap(a[place], a.back());
            //incor--;
        } else {
            int place = should.begin()->second[0];
            swap(a[place], a.back());
        }
    }
    return step;
}

V<int> adj[N];
bitset<N> vis;
void dfs(int u, V<int> &cc) {
    if (vis[u]) return;
    vis[u] = true;
    for (int v : adj[u]) dfs(v,cc);
    cc.pb(u);
}
int numSteps2(V<int> a, V<int> b) {
    //print(a); print(b);
    V<int> asort=a, bsort=b;
    sort(ALL(asort)), sort(ALL(bsort));
    if (asort != bsort) return -1;
    int step=0;
    if (a.back() != b.back()) step--;
    map<int,int> first;
    F(i,S(a)) {
        if (!first.count(a[i]))
            first[a[i]] = i;
    }
    F(i,S(a)) {
        if (a[i] != b[i]) {
            adj[first[a[i]]].pb(first[b[i]]);
            adj[first[b[i]]].pb(first[a[i]]);
        }
    }
    map<int,int> occ;
    F(i,S(a)) {
        occ[a[i]]++;
    }
    F(i,S(a)) if (S(adj[i]) && !vis[i]) {
        V<int> cc;
        dfs(i, cc);
        step++;
        int edges=0;
        for (int u : cc) {
            edges += S(adj[u]);
            if (a[u] == a.back())
                step--;
        }
        step += edges/2;
    }
    return step;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    V<int> as,bs;
    int last=0;
    F(i,n) {
        int a; cin>>a;
        as.pb(a);
        last ^= a;
    }
    as.pb(last);
    last=0;
    F(i,n) {
        int b; cin>>b;
        bs.pb(b);
        last ^= b;
    }
    bs.pb(last);
    P(numSteps2(as, bs));
}

Measured memory_bytes: 29172
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();		
		int[] arr = r.ria();
		int[] sizes = r.ria();
		Arrays.sort(sizes);
		int sum = 0;
		for(int i = sizes.length-1; i>=sizes.length-arr[1]; i--)
			sum+=sizes[i];
		print(sum);
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}
	
	public static String al(String s) {
		return s + "\n";
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

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

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
}

Measured memory_bytes: 21460
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#define N 100005
#define mod 1000000007
typedef long long ll;
using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(b/a,c)<<endl;
    return 0;
}


Measured memory_bytes: 256
//
// Created by agatsuma on 19/06/16.
//
#include <cmath>
#include <iostream>
#include <vector>

using ll = long long;

using std::cout;
using std::cin;
using std::endl;

int main() {
    int i;
    std::string s;

    std::cin >> i;
    s = std::to_string(i);
    i = 1;

    if(s[0]==s[1]){
        i=0;
    }
    if(s[1]==s[2]){
        i=0;
    }
    if(s[2]==s[3]){
        i=0;
    }

    if(i==0){
        std::cout << "Bad" << std::endl;
    }else{
        std::cout << "Good" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

template<class T> inline bool cmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool cmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll MAXN=20;
const ll MAXLG=__lg(MAXN)+2;

ll n,a[MAXN][MAXN];
ll dp[1<<MAXN],sm[1<<MAXN];
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> n;
    REP (i,n) {
        REP (j,n) {
            cin >> a[i][j];
        }
    }

    REP (s,1<<n) {
        ll sum = 0;
        REP (i,n) {
            REP(j,i) {
                if ((s&(1<<i)) && (s&(1<<j))) {
                    sum += a[i][j];
                }
            }
        }
        sm[s] = sum;
    }

    vector<ll> pos;
    REP (s,1<<n) {
        pos.clear();
        REP (i,n) {
            if (s & (1<<i)) {
                pos.eb(i);
            }
        }

        REP (ss,1<<SZ(pos)) {
            ll es = 0;
            REP (i,SZ(pos)) {
                if (ss & (1<<i)) {
                    es += 1 << pos[i];
                }
            }
            dp[s] = max(dp[s],dp[s - es] + sm[es]);
        }
    }

    cout << dp[(1<<n)-1] << endl;
    return 0;
}


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

using namespace std;

int dig(long long x) {
	int cnt = 1;
	while (x /= 10) cnt++;
	return cnt;
}

int main() {
	long long n; cin >> n;
	int ans = 100;
	for (long long i = 1; i * i <= n; ++i) {
		if (n % i) continue;
		int tmp = max(dig(i), dig(n / i));
		if (ans > tmp) ans = tmp;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int N;
    cin >> N;
    vector<int> X(N),Y;

    rep(i,0,N) cin >> X[i];
    Y = X;
    sort(all(Y));
    int kijun = Y[N/2 - 1];
    int small = Y[N/2 - 1];
    int big = Y[N/2];

    rep(i,0,N){
        if(X[i] <= kijun){
            cout << big << endl;
        }else{
            cout << small << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define def(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        int ans;
        FOR(i,1,6){
            int x; cin>>x;
            if(x==0) ans=i;
        }
        cout<<ans;
    }   
}



Measured memory_bytes: 3652
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let a:String = read!();
    if a=="a"||a=="i"||a=="u"||a=="e"||a=="o" {
        println!("vowel");
        exit(0);
    }
    println!("consonant");
}

Measured memory_bytes: 2136
import sys
import heapq
import math
import itertools

input = sys.stdin.readline

def make_Graph(N, edges):#頂点の名前はi - 1で受け付ける
    graph = {}
    for i in range(N):
        graph[i] = {}
        for j in range(N):
            graph[i][j] = 0
    for edge in edges:
        a, b, c = edge
        graph[a][b] = c
        graph[b][a] = c
    return graph

def Dijkstra(graph, start):
    N = len(graph)
    d = {}
    prev = {}
    for i in range(N):
        prev[i] = None
        if i == start:
            d[i] = 0
        else:
            d[i] = float('inf')
    Q = []
    heapq.heappush(Q, (0, start))
    while Q:
        d_u, u = heapq.heappop(Q)
        if d[u] < d_u:#ダブりを回避
            continue
        for i in range(N):
            if graph[u][i]:
                temp = d_u + graph[u][i]
                if d[i] > temp:
                    d[i] = temp
                    prev[i] = u
                    heapq.heappush(Q, (d[i], i))
    return (d, prev)

def saitan(start, goal, d, prev):
    temp = goal
    res = [goal]
    while True:
        res.append(prev[temp])
        if prev[temp] == start:
            break
        else:
            temp = prev[temp]
    return res

N,M,rr = (int(i) for i in input().split())
R = [int(i)-1 for i in input().split()]
edges = []
for i in range(M):
    a,b,c = (int(i) for i in input().split())
    edges.append((a-1, b-1, c))

graph = make_Graph(N, edges)

r_edges = []
for r1 in R:
    d, prev = Dijkstra(graph, r1)
    for r2 in R:
        (a,b,c) = r1, r2, d[r2]
        r_edges.append((a,b,c))

r_graph = make_Graph(N, r_edges)

reslis = []
for LL in list(itertools.permutations(R)):
    res = 0
    for i in range(len(LL)-1):
        a, b = (LL[i], LL[i + 1])
        res += r_graph[a][b]
    reslis.append(res)

reslis.sort()
res = reslis[0]
print(res)


Measured memory_bytes: 73308
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#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())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}


void solve(long long N, long long K, std::vector<long long> h){
    VI dp(N);
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2; i <N; i++){
        LL minim = 10e10;
        for(int j=1;j<=min((int)K,i);j++){
            minim=min(minim, dp[i-j]+abs(h[i]-h[i-j]));
        }
        dp[i]=minim;
    }
    cout<<dp[N-1]<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, K, std::move(h));
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define sqr(x) (x)*(x)
using namespace std;

bool check(vi a, vi b){
	for(int i=0; i<a.size(); i++)
		if(a[i]!=b[i]) return 0;
	return 1;
}

int main(){
#ifdef LOCAL
    freopen("inp.txt", "r", stdin );
    freopen("ans.txt", "w", stdout);
#endif
    int n; cin >> n;
    vector<int> a(n), b(n), p(n);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];
    for(int i=0; i<n; i++) p[i]=i+1;
    int pa, pb, cnt = 0;
    do{
    	cnt++;
    	if(check(a, p)) pa = cnt;
    	if(check(b, p)) pb = cnt;
    }while(next_permutation(p.begin(), p.end()));
    cout << abs(pa-pb) << '\n';
}


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

int main() {
	double a=0.0, b=0.0, sum=0.0, sumw=0.0;
	double cnt = 0.0;
	while(scanf("%lf,%lf",&a,&b)!= EOF){
	 sum=sum+a*b;
	 sumw=sumw+b;
	 cnt=cnt+1.0;
	 }

	cout << sum << endl;
	cout << (int) floor((sumw / cnt) + 0.5) << endl;
}

Measured memory_bytes: 3256
#include <stdio.h>

int main(int argc, const char * argv[])
{

    int n, i, j;
    double height;
    int kaikyu[7] = {0};
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%lf", &height);
        if (height >= 185.0) {
            kaikyu[6]++;
        } else if (height >= 180.0) {
            kaikyu[5]++;
        } else if (height >= 175.0) {
            kaikyu[4]++;
        } else if (height >= 170.0) {
            kaikyu[3]++;
        } else if (height >= 165.0) {
            kaikyu[2]++;
        } else {
            kaikyu[1]++;
        }
    }
    
    for (i = 1; i <= 6; i++) {
        printf("%d:", i);
        for (j = 0; j < kaikyu[i]; j++) {
            printf("*");
        }
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
using namespace std;
#define int long long
typedef pair<int, int> P;
int a[200005], dif[200005];
signed main() {
	int n, q, s, t;
	cin >> n >> q >> s >> t;
	int tpw = 0;
	for (int i = 0; i <= n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) {
		dif[i] = a[i + 1] - a[i];
		if (dif[i] > 0)tpw -= dif[i] * s;
		else tpw -= dif[i] * t;
	}
	
	for (int i = 0; i < q; i++) {
		int l, r, x;
		cin >> l >> r >> x;
		if (dif[l - 1] > 0) tpw += dif[l - 1] * s;
		else tpw += dif[l - 1] * t;
		if (r != n) {
			if (dif[r] > 0)tpw += dif[r] * s;
			else tpw += dif[r] * t;
		}
		dif[l - 1] += x;
		dif[r] -= x;
		if (dif[l-1] > 0)tpw -= dif[l-1] * s;
		else tpw -= dif[l-1] * t;
		if (r != n) {
			if (dif[r] > 0)tpw -= dif[r] * s;
			else tpw -= dif[r] * t;
		}
		cout << tpw << endl;
	}
}

Measured memory_bytes: 6212
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

string s;

int main()
{
    _FastIO;
    cin >> s;
    if(s[0] > '2'){
        cout << "TBD" << endl;
        return 0;
    }
    if(s[1] > '0'){
        cout << "TBD" << endl;
        return 0;
    }
    if(s[2] > '1'){
        cout << "TBD" << endl;
        return 0;
    }
    if(s[5] > '0'){
        cout << "TBD" << endl;
        return 0;
    }
    if(s[6] > '4'){
        cout << "TBD" << endl;
        return 0;
    }
    cout << "Heisei" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int sum = 0;
  for (int i = 0; i < n - 1; i++) {
    sum += v[i];
  }
  if (v[n - 1] < sum) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n,k int
	var s string
	fmt.Scan(&n,&k,&s)

	ss := strings.Split(s,"")
	ss[k-1] = strings.ToLower(ss[k-1])

	fmt.Println(strings.Join(ss,""))
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

const int N_MAX = 100010;
vector<int> G[N_MAX];
int D[N_MAX][3];

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

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
    }
    int s, t;
    cin >> s >> t;
    s--; t--;

    queue<P> q;
    q.push({s, 0});
    while(!q.empty()){
        P p = q.front();
        q.pop();
        int now = p.first;
        int cnt = p.second;
        for(int i = 0; i < G[now].size(); i++){
            int to = G[now][i];
            if(D[to][(cnt + 1) % 3]) continue;
            D[to][(cnt + 1) % 3] = D[now][cnt] + 1;
            q.push({to, (cnt + 1) % 3});
        }
    }

    if(D[t][0]) cout << D[t][0] / 3 << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 6912