akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    string t;
    cin >> t;
    for (i = 0; i < t.size(); i++) {
        if (t[i] == '?') t[i] = 'D';
    }
    cout << t << endl;
}

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

int main() {
    string s;
    while(cin >> s, s != "#") {
        const int n = s.size();
        auto museisi = [](char c) {
            return c == 'k' || c == 's' || c == 't' || c == 'h' || c == 'p';
        };
        auto boin = [](char c) {
            return c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o';
        };
        auto read_one = [&](int& p) {
            if(p >= n) throw std::runtime_error("");
            if(s[p] == '\'') {
                p += 1;
                return 0;
            }
            int mu = museisi(s[p]);
            if(s[p] == 'n' && p + 1 < n && (s[p + 1] == '\'' || s[p + 1] == 'n' || !boin(s[p + 1]))) {
                p++;
                return 0;
            }
            bool sokuon = false;
            while(p < n && !boin(s[p]) && (s[p] != 'n' || p - 1 < n && s[p - 1] != 'n') && s[p] != '\'') {
                sokuon |= p != 0 && s[p - 1] == s[p];
                p++;
            };
            p += 1;
            return (sokuon << 1) | mu;
        };
        auto is_aiu = [](char c) { return c == 'a' || c == 'i' || c == 'u'; };

        vector<int> flags, pos;
        vector<bool> f(n);
        int p = 0;
        while(p < n) {
            flags.push_back(read_one(p));
            pos.push_back(p - 1);
        };
        const int m = flags.size();
        for(int i = 0; i < m; ++i) {
            int p = pos[i];
            if(s[p] == 'n' || s[p] == '\'') continue;
            int np = i + 1 < m ? pos[i + 1] : -1;
            bool tyo = (i + 1 != m && p + 1 == np && is_aiu(s[np]));

            if(s[p] == 'a' || s[p] == 'o') {
                if(i + 1 != m && s[np] == s[p] && flags[i + 1] == 1 && (flags[i] & 1) && !tyo) {
                    f[pos[i]] = i == 0 || !f[pos[i - 1]];
                }
            } else if(s[p] == 'i' || s[p] == 'u') {
                if(flags[i] & 1 && (i + 1 == m || flags[i + 1] & 1)) {
                    f[pos[i]] = i == 0 || !f[pos[i - 1]];
                }
            }
            i += tyo;
        }

        for(int i = 0; i < n; ++i) {
            if(f[i]) {
                cout << '(' << s[i] << ')';
            } else {
                cout << s[i];
            }
        }
        cout << endl;
    }
}



Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {

  int n,l;
  string s[101];

  string res="";

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

  sort(s,s+n);
  
  for(int i=0;i<n;i++)res+=s[i];

  cout<<res;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.text.*;
public class Main {
	public static void main(String[] args) throws ParseException{
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
      	String S = sc.next();
      	String S2 = "2019/05/01";
      	SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
      	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd");
      	 Date formatDate = sdf.parse(S); 
      Date formatDate2 = sdf.parse(S2);
      	
      	
      	boolean result = formatDate2.after(formatDate);
      	if(!result){
	        System.out.println("TBD");
        }else{
        	System.out.println("Heisei");
        }
      	
      
    }
}

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

int main(){
	long long int n;
	cin >> n;
	long long int i;
	vector<long long int > arr;
	for(i=0;i<n;i++){
		long long int temp;
		cin >> temp;
		arr.push_back(temp);
	}
	long long int ans=0;
	for(i=0;i<n-1;i++){
		if(arr[i]!=arr[i+1]){
			if(arr[i]>arr[i+1]){
				ans = ans + abs(arr[i]-arr[i+1]);
				arr[i+1] = arr[i];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5260
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main()
{
	long long A, B; cin >> A >> B;
	long long C, D; cin >> C >> D;


	int CD = gcd(C, D);

	long long CD_lcm = C * D / CD;
		
	if (C == D) {
		long long Ccnt = (B / C) - ((A - 1) / C);
		cout << (B - A + 1) - Ccnt;
	}
	else {
		long long Ccnt = (B / C) - ((A - 1) / C);
		long long Dcnt = (B / D) - ((A - 1) / D);
		long long CDcnt = (B / (CD_lcm)) - ((A - 1) / (CD_lcm));
		cout << (B - A + 1) - Ccnt - Dcnt + CDcnt;

	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL((a))), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  string s;
  cin >> s;
  int K;
  cin >> K;
  int len = s.size();
  VB alp(26, false);
  REP(i, len)
  {
    if (alp[s[i]-'a'] == true) continue;
    alp[s[i]-'a'] = true;
  }
  string a = "abcdefghijklmnopqrstuvwxyz";
  VS m(3, "!");
  int idx = 0;
  REP(i, 26)
  {
    if (alp[i] == true)
    {
      m[idx] = a[i];
      idx++;
    }
    if (idx > 2) break;
  }
  VS ans;
  REP(idx, 3)
  {
    ans.push_back(m[idx]);
    REP(i, len)
    {
      if (s[i] == m[idx][0])
      {
        string tmp = m[idx];
        REP2(j, 1, 5)
        {
          if (i + j > len-1) break;
          tmp += s[i+j];
          ans.push_back(tmp);
        }
      }
    }
    UNIQUE(ans);
    if (ans.size() >= K)
    {
      cout << ans[K-1] << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 1404
# C - Bridge
# https://atcoder.jp/contests/abc075/tasks/abc075_c

from collections import deque

def dfs(n, start, graph):
  visited = [False] * n
  stack = deque()
  stack.append(start)
  visited[start] = True
  while stack:
    q = stack.popleft()
    nxts = graph[q]
    for nxt in nxts:
      if not visited[nxt]:
        visited[nxt] = True
        stack.append(nxt)
  return visited

n, m = map(int, input().split())
edge = [list(map(int, input().split())) for _ in range(m)]

ans = 0
for i in range(m):
  graph = [[] for _ in range(n)]
  for itr, (a, b) in enumerate(edge):
    if itr != i:
      graph[a - 1].append(b - 1)
      graph[b - 1].append(a - 1)

  if not all(dfs(n, 0, graph)):
    ans += 1

print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

class UnionFind{
    public:
        vector<int> par;
        vector<int> rank;
        map<int, ll> num;

        UnionFind(int n){
            for(int i = 0; i < n; i++){
                par.push_back(i);
                rank.push_back(0);
                num[i] = 1;
            }
        }

        int find(int x){
            if(x == par[x])
                return x;
            else
                return par[x] = find(par[x]);
        }

        void unite(int x, int y){
            x = find(x);
            y = find(y);
            if(x == y) return;

            if(rank[x] < rank[y]){
                par[x] = y;
                num[y] += num[x];
                num[x] = num[y];
            }
            else{
                par[y] = x;
                num[x] += num[y];
                num[y] = num[x];
                if(rank[x] == rank[y]) rank[x]++;
            }
        }

        bool same(int x, int y){
            return find(x) == find(y);
        }

        ll get_num(int x){
            return num[find(x)];
        }
};

int A[100100];
int B[100100];
ll ANS[100100];
int main(){
    ll N, M;
    cin >> N >> M;
    REP(i,M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        A[i] = a;
        B[i] = b;
    }

    UnionFind uni(N);
    ll ans = N*(N-1)/2;
    for(int i = M-1; i >= 0; i--){
        ANS[i] = ans;
        int a,b;
        a = A[i];
        b = B[i];
        if(uni.same(a,b)) continue;
        ans -= uni.get_num(a) * uni.get_num(b);
        uni.unite(a,b);
    }

    REP(i,M){
        cout << ANS[i] << endl;
    }
    return 0;
}


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

int main(){
  int i,j,cnt=0;
  int n,a,b,c,d;
  string s;
  cin>>n>>a>>b>>c>>d;
  cin>>s;
  s='X'+s+'X';
  for(i=b;i<d;i++){
    if(s[i-1]=='#' && s[i]=='#'){
      cout<<"No";
      return 0;
    }
    if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.')cnt++;
  }
  if(d<c && (s[d-1]=='#' || s[d+1]=='#') && cnt==0){
    cout<<"No";
    return 0;
  }
  for(i=a+1;i<c;i++){
    if(s[i-1]=='#' && s[i]=='#'){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
}

Measured memory_bytes: 772
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        int result = Integer.MAX_VALUE;
        for (int i = -100; i <= 100; i++) {
            int cost = 0;
            for (int num : a) {
                int diff = num - i;
                cost += diff * diff;
            }
            result = Math.min(result, cost);
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
void solve(){
	
	int n; 
	cin>>n;
	int i, count = 0;
 
	for( i = 1; i<=n; i++){
		string x = to_string(i);
		if(x.size()&1) 
			count++;
 
	}
 
	cout << count << endl;
}
 
int main()
{
	
	    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
		int t =1;
			//cin >> t;
		while(t--)
		{
			solve();
		}
		return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int memo[100002];

void solve(long long N, long long M, std::vector<long long> L, std::vector<long long> R){
    REP(i, M){
        memo[L[i]]++;
        memo[R[i]+1]--;
    }

    REP(i, 100000){
        memo[i+1] += memo[i];
    }

    int ans = 0;
    REP(i, 100001){
        if(memo[i] == M) ans++;
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[26];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4;
    //float f,g,h;
    //char now,pre;
    string s,s1;
    cin>>s;
    a=s.size();
    for(i=0;i<a;i++)
    {
        num[s[i]-'a']++;
    }
    for(i=0;i<26;i++)
    {
        if(num[i]==0)
        {
            cout<<(char)('a'+i);
            return 0;
        }
    }
    cout<<"None";
    return 0;
}



Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
  if (ch == 'A') return 1;
  else if (ch == 'C') return 2;
  else if (ch == 'G') return 3;
  else if (ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) {return key % M;}

int h2(int key) {return 1 + (key % (M - 1));}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;;i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0) return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;;i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0) return 1;
    else if (strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++) {
    H[i][0] = '\0';
  }
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);
    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}



Measured memory_bytes: 17068
H,W = map(int,input().split())
if (H == 1)or(W == 1):
    print(1)
else:
    if (H % 2 == 0)and(W % 2 == 0):
        S = H*W
        print(S//2)
    else:
        if (H % 2 == 0):
            tmp = H // 2
            print(tmp*W)
        elif (W % 2 == 0):
            tmp = W // 2
            print(tmp*H)
        else:
            tmp = H // 2
            ans = (2*tmp+1) * (W // 2)
            print(ans+tmp+1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char c=getchar();int fh=1;
	while (!isdigit(c)){if (c=='-')fh=-1;c=getchar();}
	while (isdigit(c))x=x*10+c-'0',c=getchar();
	x*=fh;
}
int n;
vector<pair<int,int> > an;
int main(){
	read(n);
	if (n%2==0){
		for (int i=1;i<=n;i++)
			for (int j=i+1;j<=n;j++)
				if (i!=j&&i+j!=n+1)an.push_back(make_pair(i,j));
	}else{
		for (int i=1;i<n;i++)
			for (int j=i+1;j<n;j++)
				if (i!=j&&i+j!=n)an.push_back(make_pair(i,j));
		for (int i=1;i<n;i++) an.push_back(make_pair(i,n));
	}
	cout<<an.size()<<endl;
	for (int i=0;i<an.size();i++) cout<<an[i].first<<' '<<an[i].second<<endl;
	return 0;
}

Measured memory_bytes: 384
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


w, h, n = LI()
A = [0] * 4
A[1] = w
A[3] = h
for _ in range(n):
    x, y, a = LI()
    a -= 1
    if a == 0:
        A[a] = max(A[a], x)
    elif a == 1:
        A[a] = min(A[a], x)
    elif a == 2:
        A[a] = max(A[a], y)
    else:
        A[a] = min(A[a], y)

print(max(0, A[1] - A[0]) * max(0, A[3] - A[2]))


Measured memory_bytes: 3064
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

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

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n; cin >> n;
    VI P(n);
    REP(i, n)
    {
        cin >> P.at(i);
    }
    int c = 0;
    REP(i, n-2)
    {
        if ((P.at(i) < P.at(i+1) && P.at(i+1)< P.at(i+2)) || (P.at(i) >P.at(i+1) && (P.at(i+1) > P.at(i+2))))
        {
            c++;
        }
    }
    cout << c << endl;
  
    return 0;
}



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

int main()
{
	int n, flag=0;
	std::cin >> n;

	for(int i = 1; i<=9; i++)
	{
		if(!(n%i) && (n/i)<10){
			flag = 1;
			break;
		}
	}

	if(flag)
		std::cout << "Yes\n";
	else
		std::cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;


int main()
{
   int n;
   cin >> n;
   vector<int> w(n);
   rep(i,n)cin>>w[i];
   //sort(w.begin(),w.end());
   rep(i,n-1) w[i+1]+=w[i];
   int MIN=1e6;
   rep(i,n-1){
       if(abs(w[i]-(w[n-1]-w[i]))<MIN)MIN=abs(w[i]-(w[n-1]-w[i]));
   }
   cout<<MIN<<endl;
}


Measured memory_bytes: 3624
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func NextInt() int {
	if sc.Scan() {
		i, e := strconv.Atoi(sc.Text())
		if e == nil {
			return i
		}
	}
	return 0
}

type Node struct {
	Point     *int
	Nodes     []int
	BranchCnt *int
}

func MinInt(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func SetPoint(nodes []Node, points []int) {
	pointIndex := 0
	for _, node := range nodes {
		if *node.BranchCnt < 2 && *node.Point == 0 {
			*node.Point = points[pointIndex]
			for _, targetNode := range node.Nodes {
				*nodes[targetNode].BranchCnt--
			}
			pointIndex++
		}
	}

	if len(points) > pointIndex {
		SetPoint(nodes, points[pointIndex:])
	}
}

func main() {
	sc.Split(bufio.ScanWords)

	n := NextInt()
	nodes := make([]Node, 0)

	// create node list
	for i := 0; i < n; i++ {
		node := Node{
			Point:     new(int),
			Nodes:     make([]int, 0),
			BranchCnt: new(int),
		}
		nodes = append(nodes, node)
	}

	// save connected nodes and number of branches
	for i := 0; i < n-1; i++ {
		start, end := NextInt(), NextInt()
		nodes[start-1].Nodes = append(nodes[start-1].Nodes, end-1)
		nodes[end-1].Nodes = append(nodes[end-1].Nodes, start-1)
		*nodes[start-1].BranchCnt++
		*nodes[end-1].BranchCnt++
	}

	// get all points and sort in asc
	points := make([]int, n)
	for i := 0; i < n; i++ {
		points[i] = NextInt()
	}
	sort.Sort(sort.IntSlice(points))
	//fmt.Println(points)

	// set points
	SetPoint(nodes, points)

	// calculate score
	var score int
	for i := 0; i < n; i++ {
		for _, node := range nodes[i].Nodes {
			if node > i {
				score += MinInt(*nodes[i].Point, *nodes[node].Point)
			}
		}
	}

	// output
	fmt.Println(score)
	for index, node := range nodes {
		fmt.Print(*node.Point)
		if index != n-1 {
			fmt.Print(" ")
		} else {
			fmt.Println("")
		}
	}
}


Measured memory_bytes: 4224
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

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

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

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

  int count = 0;
  for(int i = 0; i < n; i++){
    bool found = false;
    for(int j = 0; j < i; j++){
      if(h[j] > h[i]){
        found = true;
        break;
      }
    }
    if(!found) ++count;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            int x;int a;int b;
            Multi(out x, out a, out b);
            var ans = Math.Abs(x - a) > Math.Abs(x - b) ? "B" : "A";

            Console.WriteLine(ans);


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


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public char GetChar() { return Console.ReadLine().Trim()[0]; }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public Double[] GetDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V,W>(out T a, out U b, out V c, out W d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
        }
        static void Multi<T, U, V, W,X>(out T a, out U b, out V c, out W d,out X e)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);e = cv<X>(ar[4]);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int LCM(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  	cout << fixed << setprecision(15);
    
    int n,k; cin >> n >> k;
    double ans = 0;
    FOR(i,1,n+1){
        int ten = i;
        double tmp = 1.0;
        while(ten < k){
            ten *= 2;
            tmp /= 2.0;
        }
        ans += tmp;
    }
    cout << ans / n << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];
bool visited[MAXN];

vector<pii> query;

struct rw{
    int st,en,idx;
}P[MAXN];

bool rwcmp(rw a,rw b)
{
    return a.idx<b.idx;
}

bool cmp(pii a,pii b){
    if(a.f==b.f)return a.s>b.s;
    return a.f<b.f;
}

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>q;

    for(int i=0;i<n;i++){
        cin>>P[i].st>>P[i].en>>P[i].idx;
    }

    sort(P,P+n,rwcmp);

    for(int i=0;i<n;i++){
        a = P[i].st;
        b = P[i].en;
        A[i] = P[i].idx;
        query.push_back(pii(a-A[i],(i<<1)));
        query.push_back(pii(b-A[i],((i<<1)|1)));
    }

    for(int i=0;i<q;i++){
        cin>>x;
        query.push_back(pii(x,-1));
    }

    sort(query.begin(),query.end(),cmp);

    vector<int> res;

    for(int i=0;i<query.size();i++){
        if(query[i].s==-1){
            while(!pq.empty()){
                cur = -pq.top();
                if(!visited[cur])break;
                pq.pop();
            }
            if(pq.empty())res.push_back(-1);
            else {
                cur = -pq.top();
                res.push_back(A[cur]);
            }
        }
        else if(query[i].s&1){
            visited[(query[i].s>>1)] = true;
        }
        else {
            pq.push(-(query[i].s>>1));
        }
    }

    for(int i=0;i<res.size();i++)
        cout<<res[i]<<"\n";

    return 0;
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    string s;
    cin >> s;

    bool good = true;
    rep(1, s.size()) {
        if (s[i-1] == s[i]) {
            good = false;
            break;
        }
    }
    cout << (good ? "Good" : "Bad") << endl;

    return 0;
}


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

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A==5&&B==5&&C==7){
    cout<<"YES"<<"\n";
  }
 else if(B==5&&C==5&&A==7){
    cout<<"YES"<<"\n";
  }
  else if(C==5&&A==5&&B==7){
    cout<<"YES"<<"\n";
  }
  else{
    cout<<"NO"<<"\n";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
int sum=0;
for(int i=0;i<k;i++)
sum+=a[i];
cout<<sum;
}
  

  

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<fstream>
using namespace std;
//const int N = 1e3 + 5;
int main(){

	int n,d=0,t=0,count=0;
	cin >> n;
	if (0 <= n&&n <= 2){
		cout << 0 << endl;
		return 0;
	}
	while (n)
	{
		n -=3;
		if (n >= 3)
			count++;
		else{
			count++;
			break;
            }
		
	}
	cout << count << endl;





}

Measured memory_bytes: 3636
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  string s; cin >> s;
  int n = s.size();
  for (int i=0; i<n; i+=2) {
    if (s[i] == 'L') {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i=1; i<n; i+=2) {
    if (s[i] == 'R') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3620
H, W = map(int, input().split())
mp = []
for i in range(H):
    mp.append('.' + input() + '.')
mp_num = [[0] * (W+2) for i in range(H+2)]

mp.insert(0, '.'*(W+2))
mp.append('.'*(W+2))

for i in range(1, H+1):
    for j in range(1, W+1):
        if mp[i][j] == '#':
            mp_num[i-1][j-1] += 1
            mp_num[i-1][j] += 1
            mp_num[i-1][j+1] += 1
            mp_num[i][j-1] += 1
            mp_num[i][j+1] += 1
            mp_num[i+1][j-1] += 1
            mp_num[i+1][j] += 1
            mp_num[i+1][j+1] += 1

for i in range(1, H+1):
    for j in range(1, W+1):
        if mp[i][j] == '#':
            mp_num[i][j] = '#'

for i in range(H):
    tmp = [str(a) for a in mp_num[i+1]]
    print(''.join(tmp[1:W+1]))

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


int sort(int* Array, int n);

int main(void){
  while(1){
    int n,a;
    scanf("%d",&n);
    if(n==0){break;}
    int* Array=(int*)malloc(n*sizeof(int));
    for(int i=0;i<n;i++){
      scanf("%d",&a);
      Array[i]=a;
    }
    int retval=sort(Array,n);
    printf("%d\n",retval);
  }
  return 0;
}


int sort(int* Array, int n){
  int swap=0;
  for(int i=n-1;i>=0;i--){
    for(int j=0;j<i;j++){
      if(Array[j]>Array[j+1]){
        int tmp=Array[j];
        Array[j]=Array[j+1];
        Array[j+1]=tmp;
        swap++;
      }
    }
  }
  return swap;
}



Measured memory_bytes: 1992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl



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

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

    ll ng = 0;
    ll ok = 1e9+1;

    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        ll required = 0;
        for(int i = 0; i < n; i++){
            required += a[i]/mid;
            if(a[i]%mid == 0){required--;}
        }
        if (required <= k) ok = mid;
        else ng = mid;
    }

    ll ans = ok;
    cout << ans << endl;


}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  vector<int> N(n); rep(i,n) N.at(i)=i+1;
  vector<int> P(n); rep(i,n) cin>>P.at(i);
  vector<int> Q(n); rep(i,n) cin>>Q.at(i);
  int a,b;
  int m=1;  
  do{
    if(N==P) a=m;
    if(N==Q) b=m;
    m++;
    }while(next_permutation(N.begin(),N.end()));
  cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli solve(){
	lli n;
	cin>>n;
	lli lo = 0;
	lli hi = 50000;
	while(hi > lo){
		lli mid = (lo+hi)/2;
		lli val = (floor)((double)mid*1.08);
		if(val == n){
			cout<<mid<<"\n";
			return 0;
		}
		else if(val > n)
			hi = mid;
		else
			lo = mid+1;
	}
	cout<<":(\n";
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
acc=[0]*(n+1)
pos=[0]*(n+1)
for i in range(n):
    acc[i+1]+=a[i]+acc[i]
    pos[i+1]+=max(a[i],0)+pos[i]

ans=-10**18

for i in range(n-k+1):
    ans=max(ans,acc[i+k]-acc[i]+pos[i]+pos[-1]-pos[i+k])
    ans=max(ans,pos[i]+pos[-1]-pos[i+k])
print(ans)

Measured memory_bytes: 67616
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  vector <int> a(n);
  for (int i = 0; i < n; i++) {
	  cin >> a[i];
	}
  sort(a.begin(), a.end());
  int c   = 0;
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
	  c += a[i];
	  if (c > x) {
		  break;
		}
	  ans++;
	}
  if (x == c + a[n - 1]) {
	  ans++;
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n; cin >> n;
    vector<vector<int>> f(n, vector<int>(10));
    rep(i, n) rep(j, 10) cin >> f[i][j];

    vector<vector<LL>> p(n, vector<LL>(11));
    rep(i, n) rep(j, 11) cin >> p[i][j];

    int ans = -1e9;
    for (int mask = 1; mask < (1 << 10); mask++) {
        int sum = 0;

        rep(i, n) {
            int c = 0;
            rep(j, 10) if (mask & (1 << j)) if (f[i][j]) c++;
            sum += p[i][c];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long d[n];
  long distance[n] = {};
  long i,j;
  long min = 0;
  unsigned long long ans = 1;
  long tmp = 0;
  for(i=0;i<n;i++){
    cin >> d[i];
    distance[d[i]]++;
    if(min<d[i])min = d[i];
  }
  for(i=1;i<=min;i++){
    for(j=0;j<distance[i];j++){
      ans*=distance[i-1];
      ans=ans%998244353;
    }

  }
  ans=ans%998244353;
  if(distance[0]>=2) ans=0;
  if(d[0]!=0) ans = 0;
  cout << ans;

}


Measured memory_bytes: 1792
N, K, C = map(int, input().split())
S = input().strip()
dp1 = [0]*(N+2)
dp2 = [0]*(N+2)
c = 10*18
cc = 0
for i in range(N):
    if S[i] == "o" and c >= C:
        cc += 1
        c = 0
    else:
        c += 1
    dp1[i+1] = cc
c = 10*18
cc = 0
for i in range(N-1, -1, -1):
    if S[i] == "o" and c >= C:
        cc += 1
        c = 0
    else:
        c += 1
    dp2[i+1] = cc
rs = []
for i in range(N):
    if S[i] == "o" and dp1[i] + dp2[i+2] == K-1 and dp1[i+1] + dp2[i+1] - 1 == K:
        rs.append(i+1)

#print(dp1, dp2)
for r in rs:
    print(r)


Measured memory_bytes: 57312
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define MOD 1000000007
typedef long long ll;
using namespace std;

vector<ll> to[200005];
vector<ll> ans;

void dfs(ll v, ll p=-1)
{
	for (ll u : to[v]) {
    	if (u == p) continue;
      	ans[u] += ans[v];
      	dfs(u, v);
    }
}

int main()
{
	ll N, Q; cin >> N >> Q;
  	for (ll i = 0; i < N - 1; i++) {
      	ll a, b; cin >> a >> b;
      	a--; b--;
      	to[a].push_back(b);
      	to[b].push_back(a);
    }
  	ans.resize(N);
  	for (ll i = 0; i < Q; i++) {
    	ll p, x; cin >> p >> x;
      	p--;
      	ans[p] += x;
    }
  	dfs(0);
  	for (ll i = 0; i < N; i++) {
    	cout << ans[i] << endl;
    }
}

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

int a[51];
int main(){
	int n,m;
	int u,v;
	
	cin >> n >> m;
	while(m--){
		cin >> u >> v;
		a[u]++;
		a[v]++;
	}
	for(int i = 1;i<=n;i++){
		cout << a[i] << endl;
	}
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int N, K, H[101010], dp[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;
    rep(i, 0, N) cin >> H[i];
    
    rep(i, 0, N) dp[i] = inf;
    dp[0] = 0;

    rep(i, 0, N) {
        rep(k, 1, K + 1) chmin(dp[i + k], dp[i] + abs(H[i] - H[i + k]));
    }

    cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
    
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}

    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]

        if(way==0):
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c

import random
u,s,e,w,n,d=map(int,input().split())
dice=Dice(u,w,s,e,n,d)
u,s,e,w,n,d=map(int,input().split())
dice_b=Dice(u,w,s,e,n,d)
ok=False
for i in range (1000):
    dice.rot(random.randint(0,3))
    if(dice.u==dice_b.u and dice.d==dice_b.d and dice.w==dice_b.w and dice.s==dice_b.s and dice.e==dice_b.e and dice.n==dice_b.n):
        ok=True
if ok:
    print('Yes')
else :
    print('No')



Measured memory_bytes: 8192
n = int(input())

cnt = 0
L = ["3","5","7"]
def migona(x):
    global cnt
    if int(x) > n:
        return
    if all(str(int(x)).count(i) > 0 for i in "357"):
        cnt +=1
        #print(x)
    
    migona(x+"3")
    migona(x+"5")
    migona(x+"7")
    
    return

migona("0")
print(cnt)

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

int main() {
  int N,K;
  int i;
  int x = 1;
  int a,b;
  
  cin >> N >> K;
  
  for (i = 0; i < N; i++) {
  	a = x * 2;
    b = x + K;
    if (a < b) {
      x = a;
    } else {
      x = b;
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 256
N = int(input())
A_raw = input()
A = [int(i) for i in A_raw.split(' ')]
cnt = 0
first = 0
xsum_old = 0
r_old = 0
for l in range(0, N):
    xsum = xsum_old
    first = A[l]
    cnt += r_old - l
    isBreak = False
    for r in range(r_old, N):
        if xsum & A[r] > 0:
            xsum_old = xsum - first
            r_old = r
            isBreak = True
            break
        xsum += A[r]
        cnt += 1
    if isBreak == False:
        r_old = r
print(cnt)

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

using namespace std;

int main()
{
    int x,y,z,N,visit[10005];
    memset(visit,0,sizeof(visit));
    for(x=1; x<=100; x++)
        for(y=1; y<=100; y++)
            for(z=1; z<=100; z++)
                if(x*x+y*y+z*z+x*y+x*z+y*z<=10000)
                    visit[x*x+y*y+z*z+x*y+x*z+y*z]++;
    cin>>N;
    for(x=1; x<=N; x++)
        printf("%d\n",visit[x]);
    return 0;
}


Measured memory_bytes: 3788
import sys
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    s=list(input())
    cnt=0
    for i in range(len(s)//2):
        if s[i]!=s[-(i+1)]:
            cnt+=1
    print(cnt)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
	string p;
	cin >> p;
	if (p[0] == 'Y' && p[1] == 'A' && p[2] == 'K' && p[3] == 'I') {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	int n;
	cin >> n;
	int temp = 1;
	while(temp*temp <= n)
	{
		temp++;
	}

	temp--;
	cout << temp*temp;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int power(int n){
    int res = 1;
    while(n--){
        res *= 10;
    }
    return res;
}

int f(int n){
    int res = 0;
    while(n){
        n /= 10;
        res++;
    }
    return res;
}

int main(){
    int n,k;
    cin >> n >> k;
    bitset<10> bit;
    bit.set();
    rep(i,k){
        int a;
        cin >> a;
        bit.reset(a);
    }
    bool ok = false;
    string ans ="";
    for(int i=n;i<power(f(n)+1);i++){
        string s = to_string(i);
        //cout << "s is " << s << endl;
        
        bitset<10> v;
        v.reset();
        rep(j,s.size()){
            v.set(s[j]-'0');
        }
        //cout << bit << " " << c << " " << v << endl;
        if(bit==(bit | v) && i>=n){
            //cout << n << " " << i << endl;
            ok = true;
            ans = s;
            break;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int m,n,k,a,b,c,d;
char in[1000][1001];
int JOI[3][1001][1001];

int main(){
  
  scanf("%d%d%d",&m,&n,&k);

  for(int i=0;i<m;i++){
    scanf("%s",in[i]);
  }

  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(in[i-1][j-1]=='J')
	JOI[0][i][j]=1;
      else if(in[i-1][j-1]=='O')
	JOI[1][i][j]=1;
      else if(in[i-1][j-1]=='I')
	JOI[2][i][j]=1;
    }
  }
  
  for(int i=2;i<=m;i++)
    for(int j=1;j<=n;j++){
      for(int l=0;l<3;l++)
	JOI[l][i][j]+=JOI[l][i-1][j];
    }

  for(int i=2;i<=n;i++)
    for(int j=1;j<=m;j++){
      for(int l=0;l<3;l++)
	JOI[l][j][i]+=JOI[l][j][i-1];
    }
  
  for(int i=0;i<k;i++){
    scanf("%d%d%d%d",&a,&b,&c,&d);

    for(int j=0;j<3;j++){
      int ans = JOI[j][c][d]-JOI[j][a-1][d]-JOI[j][c][b-1]+JOI[j][a-1][b-1];
      printf(j<2?"%d ":"%d\n",ans);
    }
  }   
  
  return 0;
}

Measured memory_bytes: 13744
N = int(input())
A = [int(input()) for c in range(N)]
A = sorted(A)

tmp = 1
cnt = 0
for i in range(N):    
    if i+1<N:
        if A[i] == A[i+1]:
            tmp += 1
        else:
            cnt += tmp%2
            tmp = 1
    else:
        cnt += tmp%2

print(cnt)


Measured memory_bytes: 14168
a, b, k = map(int, input().split())
list_result = []
for i in range(a, min(a+k, b)):
  list_result.append(i)
for i in range(max(a, b+1-k), b+1):
  if i not in list_result:
    list_result.append(i)
for one_res in list_result:
  print(one_res)

Measured memory_bytes: 3060
n,m = list(map(int, input().split()))
li,lis,lisa = [],[],[]

for o in range(m):
    a,b,c = list(map(int, input().split()))
    li.append(a)
    lis.append(b)
    lisa.append(c)

cou = [-float('inf') for i in range(n + 1)]
cou[1] = 0
key = True
for i in range(n - 1):
    for k in range(m):
        cou[lis[k]] = max(cou[lis[k]], cou[li[k]] + lisa[k])

co = cou[n]

def ans():
    for l in range(m):
        cou[lis[l]] = max(cou[lis[l]], cou[li[l]] + lisa[l])
    if cou[n] > co:
        return 'inf'
    return cou[n]

print(ans())

Measured memory_bytes: 3328
n, m = map(int, input().split())

A = [1] * (n + 1)
red = [False] * (n + 1)
red[1] = True

for i in range(1, m + 1):
	x, y = map(int, input().split())
	if red[x]:
		red[y] = True
	A[x] -= 1
	A[y] += 1
	if A[x] == 0:
		red[x] = False

print(len([red[i] for i in range(1, n + 1) if red[i]]))

Measured memory_bytes: 54104