akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j;
	long int countr, countl;
	long int idxr, idxl;
	long int num;
	long int sum[100000] = {0};
	char str[100001];
	
	scanf("%s", str);
	
	num = strlen(str);
	
	countr = countl = 0;
	
	for(i = 0; i < num; i++) {
		if(str[i] == 'L') {
			idxr = i;
			idxl = i - 1;
			countr++;
			for(j = i + 1; j < num; j++) {
				if(str[j] == 'R') {
					sum[idxl] = countl - countl / 2 + countr / 2;
					sum[idxr] = countr - countr / 2 + countl / 2;
					countr = countl = 0;
					i = j;
					break;
				}
				countr++;
			}
			if(j == num) {
				sum[idxl] = countl - countl / 2 + countr / 2;
				sum[idxr] = countr - countr / 2 + countl / 2;
				break;
			}
		}
		countl++;
	}
	
	for(i = 0; i < num; i++) {
		printf("%ld ", sum[i]);
	}
	
	return 0;
}


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

const int INF = 1001001001;

int main(){
    int D;
    cin>>D;
    int c[26];
    for(int i=0;i<26;i++)cin>>c[i];
    int s[D][26];
    for(int i=0;i<D;i++)for(int j=0;j<26;j++){
        cin>>s[i][j];
    }
    int t[D];
    int score=0;
    int last[26]={};
    for(int i=1;i<=D;i++){
        int con=-1,maxs=-INF;
        for(int j=0;j<26;j++){
            int tmp=0;
            tmp+=(i-last[j])*c[j];
            tmp+=s[i-1][j];
            if(tmp>maxs){
                maxs=tmp;
                con=j;
            }
        }
        t[i-1]=con+1;
        score+=s[i-1][con];
        last[con]=i;
        for(int j=0;j<26;j++){
            score-=(i-last[j])*c[j];
        }
        cout<<t[i-1]<<endl;
    }
}

Measured memory_bytes: 3636
//
//  main.cpp
//  Sandglass2
//
//  Created by wenhan on 2017/9/2.
//  Copyright © 2017年 wenhan. All rights reserved.
//

#include <iostream>
using namespace std;
int a,b;
int main() {
    cin>>a>>b;
    if(a>b)
        cout<<a-b<<endl;
    else
        cout<<0<<endl;
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a, b, c, x, count=0;
    scanf("%d %d %d", &a, &b, &c);
    for (x=a; x<=b; x++) {
        if (c%x == 0) {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 596
//AtCoder1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream> 
#include <algorithm>
#include <math.h> 
#include <vector>
#include <string>
using namespace std;

int main()
{
    int X, Y;
    cin >> X >> Y;
    cout << X + Y / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <iostream>
#include <ctype.h>
#include <string>
typedef long long ll;
using namespace std;

int main(){
   int a,b,c;
  cin>>a>>b>>c;
  if(a-b>c)
    cout<<"0"<<endl;
  else
    cout<<c-a+b<<endl;
    
    
  
    
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> ok(m,0);
    vector<int> k(n);
    for(int i=0;i<n;i++){
        cin >> k[i];
        for(int j = 0;j<k[i];j++){
            int a;
            cin >> a;
            ok[a-1] ++;
        }
    }
    int ans = 0;
    for(int i=0;i<m;i++){
        if(ok[i]==n){
            ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	string S;
	cin >> S;
	S = '#' + S + "#";

	char mae = '.';
	int NG = 0;
	for (int i = A + 1; i < C; i++) {
		if (mae == '#' && S[i] == '#') NG = 1;
		mae = S[i];
	}
	mae = '.';
	for (int i = B + 1; i < D; i++) {
		if (mae == '#' && S[i] == '#') NG = 1;
		mae = S[i];
	}
	if (C > D) {
		int OK = 0;
		for (int i = B; i <= D; i++) {
			if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') OK = 1;
		}
		if (OK == 0) NG = 1;
	}

	if (NG) co("No");
	else co("Yes");

	Would you please return 0;
}

Measured memory_bytes: 720
import sys
from collections import deque
readline = sys.stdin.readline
H, W = map(int, readline().split())
G = [list(map(lambda x: 1 if x == '.' else 0, readline().strip())) for _ in range(H)]

dist = [[0]*W for _ in range(H)]

Q = deque([(0, 0)])
used = set(Q)
dim = [(0, 1), (1, 0)]
while Q:
    nx, ny = Q.pop()
    for dx, dy in dim:
        fx, fy = nx+dx, ny+dy
        if not 0 <= fx < H or not 0 <= fy < W:
            continue
        if (fx, fy) in used:
            continue
        used.add((fx, fy))
        if G[nx][ny] == G[fx][fy]:
            dist[fx][fy] = dist[nx][ny]
            Q.append((fx, fy))
        else:
            dist[fx][fy] = 1 + dist[nx][ny]
            Q.appendleft((fx, fy))

K = dist[H-1][W-1]
if G[0][0] == 0:
    K += 1
if G[H-1][W-1] == 0:
    K += 1
print(K//2)

Measured memory_bytes: 42736
#include <stdio.h>
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a>b)?(a):(b))
 
int main() {
    int a, b, c, small, learge;
    scanf("%d %d %d", &a, &b, &c);

    small = MIN(a,b);
    learge = MAX(a,b);

    if (small <= c && c <= learge) {puts("Yes");}
    else {puts("No");}

    return 0;
}


Measured memory_bytes: 128
import std.stdio;
import std.range;
import core.stdc.stdio;
import core.memory;
import std.typecons;
import std.string;
import std.array;
import std.algorithm;
import std.math;
import std.container;

immutable long INF = 100000000000;

void main(){
	GC.disable;

	int n,m,c;
	scanf("%d%d%d",&n,&m,&c);

	alias Tuple!(long,"cost",int,"to") edge;
	edge[][] graph = new edge[][n];

	long sum=0;
	for(int i=0;i<m;i++){
		int a,b;
		long d;
		scanf("%d%d%lld",&a,&b,&d);
		graph[a-1] ~= edge(d,b-1);
		graph[b-1] ~= edge(d,a-1);
		sum += d;
	}

	long[] dist = new long[n];
	dist[] = INF;
	auto pq = new BinaryHeap!(Array!edge,"a>b")();
	pq.insert(edge(0,0));
	while(!pq.empty){
		edge t = pq.front;
		pq.popFront;
		if(t.cost >= dist[t.to])
			continue;
		dist[t.to] = t.cost;
		foreach(e;graph[t.to]){
			if(t.cost+e.cost < dist[e.to])
				pq.insert(edge(t.cost+e.cost,e.to));
		}
	}

	long[] pCost = new long[n];
	pCost[] = 0;
	foreach(i,g;graph){
		foreach(e;g){
			if(dist[i] > dist[e.to] || (dist[i] == dist[e.to] && i < e.to))
				pCost[i] += e.cost;
		}
	}
	int[] order = new int[n];
	for(int i=0;i<n;i++) order[i]=i;
	sort(zip(dist,order));
	long w=0;
	long ans = sum;
	for(int i=0;i<n;i++){
		w=dist[i]*c;
		sum -= pCost[order[i]];
		if(i == n-1 || dist[i+1] != dist[i]){
			ans = min(ans,w+sum);
		}
	}
	ans.writeln;
}

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

signed main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long sum = accumulate(a, a + n, 0L);
	long div = n * (n + 1) / 2;
	if (sum % div) {
		cout << "NO\n";
		return 0;
	}
	long k = sum / div;
	long b[n];
	for (int i = 0; i < n; i++) {
		if (i != n - 1) b[i] = a[i + 1] - a[i] - k;
		else b[i] = a[0] - a[i] - k;
	}
	for (int i = 0; i < n; i++) {
		if (b[i] > 0 || b[i] % n) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		do{
			int x = i;
			if(x%3 == 0){
				System.out.printf(" %d", i);
				continue;
			}
			do{
				if(x%10 == 3){
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			}while(x > 0);
		}while( ++i <= n );
		System.out.printf("\n");
	}
}

Measured memory_bytes: 38436
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

int n, ar[N], l[N], r[N];
lli ans;
stack<int> s;

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> ar[i];
	s.push(0);
	for(int i = 1; i <= n; i++) {
		while(ar[s.top()] > ar[i])
			s.pop();
		l[i] = s.top();
		s.push(i);
	}
	while(s.size())
		s.pop();

	s.push(n + 1);
	for(int i = n; i >= 1; i--) {
		while(ar[s.top()] > ar[i])
			s.pop();
		r[i] = s.top();
		s.push(i);
	}
	for(int i = 1; i <= n; i++)
		ans += 1ll * ar[i] * (r[i] - i) * (i - l[i]);
	cout << ans;
}

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

void Main()
{
    int a, b, k;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++)
    {
        if(i % k == 0){
            cout << "OK" << endl;
            return;
        }
    }
    
    cout << "NG" << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3596
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	if resolve(parseProblem()) {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func parseProblem() (int, []task) {
	n := scanInt(sc)
	result := make([]task, n)
	for i := 0; i < n; i++ {
		result[i] = task{
			take:  scanInt(sc),
			limit: scanInt(sc),
		}
	}
	return n, result
}

type task struct{ take, limit int }
type tasks []task

func (t tasks) Len() int {
	return len(t)
}

func (t tasks) Less(i, j int) bool {
	return t[i].limit < t[j].limit
}

func (t tasks) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

func resolve(n int, ts []task) bool {
	sort.Sort(sort.Reverse(tasks(ts)))
	limit := math.MaxInt32
	for _, t := range ts {
		if t.limit <= limit {
			limit = t.limit
		}
		limit -= t.take
	}
	return limit >= 0
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 7788
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string C[2];

int main()
{
	in >> C[0] >> C[1];

	if (C[0][0] == C[1][2] && C[0][1] == C[1][1] && C[0][2] == C[1][0])
	{
		out << "YES" << std::endl;
	}
	else
	{
		out << "NO" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;

class AOJ{
  static void Main(string[] args)
  {
    int n;
    int A, B;
    int in_a, in_b;

    string[] s;

    while (true){

      n = int.Parse(Console.ReadLine());

      if (n == 0) break;

      A = 0;
      B = 0;

      for (int i = 0; i < n; i++){
        s = Console.ReadLine().Split(' ');

        in_a = int.Parse(s[0]);
        in_b = int.Parse(s[1]);

        if (in_a > in_b)
          A += in_a + in_b;

        else if (in_a < in_b)
          B += in_a + in_b;

        else{
          A += in_a;
          B += in_b;
        }
      }

      Console.WriteLine("{0} {1}", A, B);
    }
  }
}

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

int main(void)
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b&&b==c)cout<<1<<endl;
    if(a==b&&b!=c)cout<<2<<endl;
    if(a!=b&&b==c)cout<<2<<endl;
    if(a!=b&&a==c)cout<<2<<endl;
    if(a!=b&&b!=c&&a!=c)cout<<3<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll INF = 3000;
    for(ll i=-INF;i<=INF;i++){
    	for(ll j=-INF;j<i;j++){
    		if(i*i*i*i*i - j*j*j*j*j == n){
    			cout << i << " " << j << endl; 
    			return 0;
    		}
    	}
    }
    return 0;
}


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

int main(void)
{
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    if(b-a>x) printf("dangerous");
    else if(b<=a) printf("delicious");
    else printf("safe");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

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

    vector<ll> vec;
    vec.push_back(0);
    rep(i, 1, n) {
        if (s[i-1] != s[i]) vec.push_back(i);
    }
    ll m = vec.size();
    rep(i, 0, n+4*k) vec.push_back(n);

    ll ans = 0;
    rep(i, 0, m) {
        ll idx = vec[i];
        if(s[idx] == '0') chmax(ans, vec[i+2*k] - vec[i]);
        if(s[idx] == '1') chmax(ans, vec[i+2*k+1] - vec[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6256
_,*s=*$<
eval"_,*A="+_.split*?,
q=[:Yes]
f=->i{s[i]&.chop&.bytes{|x|A[y=s[i].sum-x-75]+=1;q[i+1]=""<<y+65;f[i+1]if~0<A[x-=65]-=1;A[x]+=1;A[y]-=1}||puts(q)+exit}
f[0]
puts:No

Measured memory_bytes: 155240
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int n,l;
    cin >> n >> l;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        vec[i]=l+i;
    }
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=vec[i];
    }
    int tmp=100100100;
    int minus;
    for(int i=0;i<n;i++){
        if(tmp>abs(vec[i])){
            tmp=abs(vec[i]);
            minus=vec[i];
        }
    }
    cout << sum-minus << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        vector<long long> A(N), B(N);
        for(auto& t : A) cin >> t;
        for(auto& t : B) cin >> t;
        int res = 0;
        long long lack = 0;
        priority_queue<long long> over;
        for(int i=0;i<N;i++){
            if(A[i] < B[i]){
                lack += B[i]-A[i];
                res++;
            } else {
                over.push(A[i]-B[i]);
            }
        }
        while(!over.empty() && lack > 0){
            long long v = over.top(); over.pop();
            lack -= v;
            ++res;
        }
        cout << (lack > 0 ? -1 : res) << endl;
    }
}

Measured memory_bytes: 2936
#include <stdio.h>
int main(void)
{
    int n;
    long long int t;
    scanf("%d%lld", &n,&t);
    long long int a[n];
    for(int i=0; i<n; i++) scanf("%lld", &a[i]);

    int ans;
    long long int min=1000000001,max=0;
    for(int i=0; i<n; i++)
    {
        if(a[i]<min) min=a[i];
        else if(a[i]-min>max)
        {
            max=a[i]-min;
            ans=1;
        }
        else if(a[i]-min==max) ans++; 
    }
    printf("%d", ans);
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back


int main(void){
  ll n, x;
  cin >> n >> x;
  ll ans = 0;
  ll nx = n-x;
  while(nx > 1 && x >1){
    if(nx > x){
      ans += x*3 * (nx/x);
      nx%=x;
    }else if(nx < x){
      ans += nx*3 * (x/nx);
      x%=nx;
    }else{
      ans += x*3;
      nx = 0;
      x = 0;
    }
  }
  cout << ans + nx * x * 3 << endl;
  return 0;
}



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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> t(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int p, x;
        cin >> p >> x;
        int s = 0;
        for (int j = 0; j < n; ++j) {
            if (j == p - 1) {
                s += x;
            } else {
                s += t[j];
            }
        }
        cout << s << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n;cin>>n;
    ll cnt=0;
    rep(i,n){
        ll a;cin>>a;
        if(a%2)cnt++;
    }
    if(cnt%2){
        cout<<"NO"<<endl;
    }else{
        cout<<"YES"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,size[200010],mx[200010];long long ans;
vector <int> des[200010],len[200010];
void prework(int s,int pre)
{
	size[s]=1;
	for (int k=0;k<des[s].size();k++) if (des[s][k]!=pre)
	{
		prework(des[s][k],s);
		size[s]+=size[des[s][k]];
		ans+=2ll*len[s][k]*min(size[des[s][k]],n-size[des[s][k]]);
		mx[s]=max(mx[s],size[des[s][k]]);
	}
	mx[s]=max(mx[s],n-size[s]);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int u,v,w;scanf("%d%d%d",&u,&v,&w);
		des[u].push_back(v);len[u].push_back(w);
		des[v].push_back(u);len[v].push_back(w);
	}
	prework(1,0);int num=2100000000,p1=0,p2=0;
	for (int i=1;i<=n;i++)
	{
		if (mx[i]<num) {num=mx[i];p1=i;p2=0;}
		else if (mx[i]==num) {if (!p1) p1=i;else p2=i;}
	}
	if (!p2)
	{
		int minn=2100000000;
		for (int k=0;k<des[p1].size();k++) minn=min(minn,len[p1][k]);
		ans-=minn;
	}
	else for (int k=0;k<des[p1].size();k++) if (des[p1][k]==p2) ans-=len[p1][k];
	cout<<ans<<endl;
}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

Measured memory_bytes: 23680
$N,$A,$B,$C = gets.split.map(&:to_i)
$L = Array.new($N) {gets.to_i}
$INF = 10**9
$min = $INF

class Node
  attr_accessor :depth, :mp, :a, :b, :c

  def initialize(depth, mp, a, b, c)
    @depth = depth
    @mp = mp
    @a = a
    @b = b
    @c = c
  end
end

def calc(v)
  if [v.a,v.b,v.c].min == 0
    return $INF
  else
    return v.mp + (v.a-$A).abs+(v.b-$B).abs+(v.c-$C).abs
  end
end

def dfs()
  stack = [Node.new(0,-30,0,0,0)]

  while !stack.empty? do

    v = stack.pop()

    if v.depth > $N-1 then
      c = calc(v)
      $min = c if $min > c
    else
      stack.push(Node.new(v.depth+1,v.mp+10,v.a+$L[v.depth-1], v.b, v.c))
      stack.push(Node.new(v.depth+1,v.mp+10,v.a, v.b+$L[v.depth-1], v.c))
      stack.push(Node.new(v.depth+1,v.mp+10,v.a, v.b, v.c+$L[v.depth-1]))
      stack.push(Node.new(v.depth+1,v.mp,v.a, v.b, v.c))
    end
  end
end

dfs()
puts $min

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

int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	vector<int> nvec(n);
	int counter = 0;
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
		if (vec.at(i) != i + 1) {
			counter++;
		}
	}
	if (counter == 2 || counter == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int A, B, C;
    cin >> A >> B >> C;

    int a = max(A, max(B, C));
    int b = min(A, min(B, C));
    int c = A + B + C - a - b;
    cout << 10 * a + c + b << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
int i=0; int num[10];
for(;i<10;i++)
cin>>num[i];
int temp=0,
temp1=0,j=0,k=0;
for(;j<3;j++)
{ for(i=0;i<10;i++)
{ temp1=temp;
temp=temp<num[i]?num[i]:temp;
if(temp>temp1) k=i; }
cout<<num[k]<<endl;
temp=0;
num[k]=0; }
return 0; }

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

constexpr int MAX_XY = 1e5;

struct UnionFind
{
    vector< int > data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = find(x), y = find(y);
        if(x == y) return(false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return(true);
    }

    int find(int k)
    {
        if(data[k] < 0) return(k);
        return(data[k] = find(data[k]));
    }

    int size(int k)
    {
        return(-data[find(k)]);
    }

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

int main() {
    int N; cin >> N;
    vector<tuple<int, int, int>> XY(N);
    // vector<int> X(MAX_XY + 1, 0);
    // vector<int> Y(MAX_XY + 1, 0);
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        XY[i] = tuple<int, int, int>(x, y, i);
        // X[x]++; Y[y]++;
    }
    UnionFind uf = UnionFind(N);
    sort(XY.begin(), XY.end(), less<tuple<int, int, int>>());
    for (int i = 0; i < N-1; i++) {
        if (get<0>(XY[i]) == get<0>(XY[i+1])) {
            uf.unite(get<2>(XY[i]), get<2>(XY[i+1]));
        }
    }
    for (int i = 0; i < N; i++) swap(get<0>(XY[i]), get<1>(XY[i])); // (y, x, i)
    sort(XY.begin(), XY.end(), less<tuple<int, int, int>>());
    for (int i = 0; i < N-1; i++) {
        if (get<0>(XY[i]) == get<0>(XY[i+1])) {
            uf.unite(get<2>(XY[i]), get<2>(XY[i+1]));
        }
    }
    for (int i = 0; i < N; i++) swap(get<0>(XY[i]), get<2>(XY[i])); // (i, x, y)
    sort(XY.begin(), XY.end(), less<tuple<int, int, int>>());
    map<int, set<int>> eachx;
    map<int, set<int>> eachy;
    for (int i = 0; i < N; i++) {
        eachx[uf.find(i)].insert(get<1>(XY[i]));
        eachy[uf.find(i)].insert(get<2>(XY[i]));
    }
    long long ans = 0;
    for (auto x : eachx) {
        int i = x.first;
        ans += (long long)eachx[i].size() * eachy[i].size() - uf.size(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8832
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.Xml;

namespace hello_world
{
	class Program
	{

		static void Main(string[] args)
		{
			var c = Console.Read();
			Console.WriteLine((char)(c + 1));
		}

	}

	}


Measured memory_bytes: 11092
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/
#include<bits/stdc++.h>
#define mem(a) memset(a,0,sizeof(a))
#define INF 0x3f3f3f3f
#define Min 1e-6
#define lowbit(x) ((x)&(-x))
#define ls rt<<1
#define rs rt<<1|1
#define ll long long

using namespace std;

const int N = 2e2 + 7;
const int M = 1e9 + 7;
const ll Mod = 998244353;

int i,j,n,m,t,T,p,l,r,q,len,len1,v,u,k,w,st,res,cnt,tmp,nex,a[N][N],dp[N][N];
string s,s1,s2,s3,ans;
char c;

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(i = 1;i <= n;i++)
        for(j = 1;j <= m;j++){
            cin >> c;
            if(c == '.') a[i][j] = 1;
            else a[i][j] = 0;
        }
    fill(dp[0],dp[0]+N*N,INF);
    dp[1][1] = 1-a[1][1];
    for(i = 1;i <= n;i++){
        for(j = 1;j <= m;j++){
            if(a[i][j]){
                dp[i][j]=min(dp[i][j],min(dp[i-1][j],dp[i][j-1]));
                continue;
            }
            if(a[i][j] == a[i][j-1]) dp[i][j] = min(dp[i][j],dp[i][j-1]);
            else dp[i][j] = min(dp[i][j],dp[i][j-1]+1);
            if(a[i][j] == a[i-1][j]) dp[i][j] = min(dp[i][j],dp[i-1][j]);
            else dp[i][j] = min(dp[i][j],dp[i-1][j]+1);
        }
    }
    cout << dp[n][m];
    return 0;
}








Measured memory_bytes: 512
a[99999],x,r;main(n,m){
for(scanf("%d%d",&n,&m);++x<n;a[x]+=a[x-1])scanf("%d",a+x);
for(n=0;m;m--)scanf("%d",&x),r=(r+abs(a[n+x]-a[n]))%100000,n+=x;
x=!printf("%d\n",r);}

Measured memory_bytes: 984
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = b[a[0] - 1]
for i in range(1, n):
    ans += b[a[i] - 1]
    if a[i] - a[i - 1] == 1:
        ans += c[a[i - 1] - 1]

print(ans)

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

#define N_MAX 100005

using namespace std;

int N, M;
vector <int> G[N_MAX];
int H[N_MAX];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> N >> M;
    for(int i = 1; i <= N; i++) {
        cin >> H[i];
    }

    while(M--) {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    int ans = 0;
    for(int i = 1; i <= N; i++) {
        bool ok = true;
        for(auto it : G[i]) {
            if(H[it] >= H[i]) {
                ok = false;
            }
        }
        if(ok) {
            ans++;
        }
    }

    cout << ans << "\n";
    return 0;
}


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

int sumDigit(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int n, a, b;
    int total = 0;
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++){
        int sum = sumDigit(i); 
        if( a<=sum && b>=sum ){
            total +=i;
        }
    }
    cout << total << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const MOD: u64 = 1_000_000_000 + 7;
fn main() {
    input! {
        n: usize, m: usize,
        a: [usize; m],
    }
    let mut koware = vec![false; n + 1];
    for i in 0..m {
        koware[a[i]] = true;
    }
    let mut dp = vec![0; n + 1];
    dp[0] = 1;

    for i in 1..n + 1 {
        if koware[i] {
            continue;
        }
        dp[i] += dp[i - 1];
        if i >= 2 {
            dp[i] += dp[i - 2];
        }
        dp[i] %= MOD;
    }

    println!("{}", dp[n]);
}


Measured memory_bytes: 6396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main()
{
    int h,w,n;
    cin >> h >> w >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int f[h][w];
    int cnt = 1;
    for(int i = 0; i < h; i++){
        if(i % 2 == 0){
            for(int j = 0; j < w; j++){
                f[i][j] = cnt;
                a[cnt-1]--;
                if(a[cnt-1]==0){
                    cnt++;
                }
            }
        }else{
            for(int j = w-1; j >= 0; j--){
                f[i][j] = cnt;
                a[cnt-1]--;
                if(a[cnt-1]==0){
                    cnt++;
                }
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << f[i][j] << ' ';
        }
        cout << '\n';
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define p pair<int, int>
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

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

Measured memory_bytes: 772
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#include <set>
#include <climits>
#include <bitset>

#define mod 1e9+7
#define mp make_pair
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, n;
    int ans = 0;
    cin >> a >> b >> n;
    if(a < b) swap(a,b);
    if(n%a == 0)  ans = n/a;
    else ans = n/a +1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    /*
    *　参加者数　N
    *　合宿日数　D　
    *　参加者数　i
    *　残り　X
    */
    int man,day,amari;
    int choco = 0;
    scanf("%d",&man);
    scanf("%d",&day);
    scanf("%d",&amari);
    int temp = 0;
    for(int i = 0;i < man;i++){
        scanf("%d",&temp);
        if(temp > day){
            choco += 1;
            //printf("+=1\n");
        }
        else if(day % temp == 0){
            choco += (day / temp);
            //printf("+=%d\n",day / temp);
        }
        else{
            choco += (day / temp + 1);
            //printf("+=%d\n",day / temp + 1);
            
        }
    }
    choco += amari;
    
    
    printf("%d\n",choco);
    
    return 0;
    
}

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

int main() {
  int N;
  int count = 0;
cin >> N;
vector<int> p(N);
vector<int> q(N);
for (int i = 0; i < N; i++) {
  cin >> p.at(i);
}
  for (int i = 0; i < N; i++) {
  q.at(i) = p.at(i);
}
  sort(q.begin(), q.end());
   for (int i = 0; i < N; i++) {
  if(p.at(i) != q.at(i))
    count++;
}
if (count <= 2)
  cout << "YES" << endl;
else
  cout << "NO" << endl;
}


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

int main(){

    char line[256];
    int K,S;
    int i,j,k;
    int count=0;

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%d %d", &K,&S);

    for(i=0;i<=K;i++){
        for(j=0;j<=K;j++){
            k = S - (i+j);
            if(i+j+k == S && k <= K && k >= 0)count += 1;
        }
    }

    printf("%d",count);

    return 0;
}

Measured memory_bytes: 128
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ctr = 0
for i in range(A+1):
	for j in range(B+1):
		for k in range(C+1):
			if 500*i+100*j+50*k == X:
				ctr += 1
print(ctr)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int s,m,l;
typedef pair<int,int> pa;
int main() {
	cin>>m>>m;
	pa v[m];
	for(pa &x:v)cin>>x.second>>x.first;
	sort(v,v+m);
	for(pa x:v)
		if(x.second>=l){
			l=x.first;
			s++;
		}
	cout<<s;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;
using ll = long long int;

int main(void){
    int X;cin>>X;
    ll ans = 0;
    ans += X/500*1000;
    ans += (X%500)/5*5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort()
flags = [False] * 8
min_ans = 1
high_coder = 0
for i in range(N):
    idx = A[i] // 400
    if idx < 8:
        flags[idx] = True
        min_ans = sum(flags)
    else:
        high_coder = N - i
        break

print(min_ans, sum(flags) + high_coder)



Measured memory_bytes: 3060
from collections import deque

# 下右1マスを検索するために必要とする
dis_x = [1, 0]
dis_y = [0, 1]

# 迷路の縦幅,横幅
max_h, max_w = map(int, input().split())

s = []
av_count = 0
for _ in range(max_h):
    line = input()
    av_count += line.count("#")
    # 横1マスを壁でPadding. これでindex out of boundを防ぐ
    s.append(list(".{}.".format(line)))

# 縦1マスを壁でPadding. これでindex out of boundを防ぐ
s = [list("." * (max_w + 2))] + s + [list("." * (max_w + 2))]

# 迷路と同じサイズの距離表を作成.
# 値が0 -> 未訪問, それ以外 -> スタート地点からそれまでの距離となる
dist = [ [0] * (max_w + 2) for _ in range(max_h+2)]

# キューにスタート地点をプッシュ
que = deque([(1, 1)])

# キューに値が格納されている間
while que:
    # 先頭の値を取り出す
    h, w = que.popleft()

    for i in range(2):
        # 移動距離
        dx, dy = dis_x[i], dis_y[i]
        if s[h+dy][w+dx] == '#' and dist[h+dy][w+dx] == 0:
            # ここまでの距離+1して訪問済みに
            dist[h+dy][w+dx] = dist[h][w] + 1
            # キューに加える -> (h+dy, w+dx) を起点にまた上下左右4マスをチェックする,という意味
            que.append((h+dy, w+dx))
            break

dist[1][1] = 1

dis = 0
for line in dist:
  dis += len(list(filter(lambda x : x != 0, line)))

print("Possible" if av_count == dis else "Impossible")


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

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

    cin>>a>>b>>c;
    int tmp;
    tmp=a;
    a=b;
    b=tmp;
    tmp=a;
    a=c;
    c=tmp;

    cout<<a<<" "<<b<<" "<<c<<endl;
}

Measured memory_bytes: 256
import scala.io.Source.stdin

object Main {

  def main(args:Array[String]) = {
    val x = 4.9/(9.8*9.8)
    val b = new StringBuilder
    val f = (v:Double) => Math.ceil((x*v*v+5D)/5D).toInt
    for(i<-stdin.getLines.map(_.toDouble))
      b.append(f(i)+"\n")

    print(b.result)
  }
}

Measured memory_bytes: 43976
# A, B = [int(i) for i in input().split(" ")]
# A = int(input())
# As = [int(i) for i in input().split(" ")]
# Ss = ["".join(sorted(input())) for _ in range(N)]
# from math import factorial
# def nCr(n, r): return factorial(n) // factorial(r) // factorial(n - r)

N = int(input())
As = [int(i) for i in input().split(" ")]

print(1/ sum([1/a for a in As]))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  int a;
  cin >>a;
  while(a>0)
    a-=1000;
  cout << -a << endl;
}

Measured memory_bytes: 3632
# N = int(input())
# N = list(map(int, input().split()))
# N = input().split()
N = input()
ans = ''
if N == 'A':
    ans = 'T'
if N == 'T':
    ans = 'A'
if N == 'C':
    ans = 'G'
if N == 'G':
    ans = 'C'
    

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h> 
#define M 1000000007
#define forz(i,s,n) for(lli i=s;i<n;i++)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef long long int lli; 
 
using namespace std;
 
bool sortbysec(const pair<string, lli> &a,const pair<string, lli> &b){
    return (a.second < b.second);
}
lli highest2(lli n){
    lli x=n;
    while(n){
        x=n;
        n=n&(n-1);
    }
    return x;
}
int main(){
    fast_io;
    lli m,k,t,row,col,n,i,b,p,j,p0,p1,mno,R,r,br,x,count=0;
    string s,y;
    cin>>n>>k;
    lli h[n+2];
    forz(i,1,n+1)cin>>h[i];
    lli dp[n+2];
    
    forz(i,0,n+2){
        dp[i]=10000000000001;
    }
    
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    // dp[3]=min(abs(h[3]-h[1]),dp[2]+abs(h[3]-h[2]));
   
   
    forz(i,3,n+1){
        forz(j,(i-k<1)?1:i-k,i){
            dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
    }
    //cout<<dp[n-1]<<endl;
    cout<<dp[n];
    cout<<endl;      
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	string a,b;
	int x;
	int zh(string s);
	
	cin>>a>>b;   
	
	x=zh(a+b);
	
	if(int(sqrt(x))==sqrt(x))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	
	return 0;
}
 
int zh(string s)   
{
	int tmp=0;
	
	for(int i=0;i<s.size();i++)
		tmp=tmp*10+(s[i]-'0');  
	
	return tmp;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static int[,] s;
    static decimal result;
static Hashtable ht=new Hashtable();
static StringBuilder sb = new StringBuilder();
static int N,M,K;
static long[,] table;
    static void Main()
    {
Read4();
      Read5();
      int tmp,tmpr;
      int[,,] check=new int[K,N,2];//チェック中にタテヨコ届く値を状態保存する。
for(int j=0;j<N;j++){
for(int i=0;i<K;i++){
  tmpr=0;
  tmp=0;
  if(check[i,j,0]>0){tmpr=check[i,j,0];}else{
  for(int x=i;x<K;x++){
if(s[x,j]<0){tmpr=tmp;break;}    
tmp++;    
    if(x==K-1){tmpr=tmp;}
}
for(int x=i;x<K;x++){
  if(s[x,j]<0){break;}
check[x,j,0]=tmp;  
}
  }
  tmp=0;
  if(check[i,j,1]>0){tmpr+=check[i,j,1];}else{
    for(int y=j;y<N;y++){
   if(s[i,y]<0){tmpr+=tmp;break;}   
tmp++;    
          if(y==N-1){tmpr+=tmp;}
}
for(int y=j;y<N;y++){
if(s[i,y]<0){break;}
check[i,y,1]=tmp;  
}
  }
  result=Math.Max(result,tmpr);
}
}
      if(result>0){result--;}//タテヨコで自マスを数えてるので重複分を減
      Console.WriteLine(result.ToString());

    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }
 

    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
      s=new int[K,N];
    }
    static void Read5()//N行K項
    {
for(int i=0;i<N;i++){
        string tmp = Console.ReadLine();
        for(int j=0;j<K;j++){
          if(tmp[j]=='.'){s[j,i]=1;}
            if(tmp[j]=='#'){s[j,i]=-1;}      
        }
}
 
    }
}



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

int N;
vector<int> a;

int main() {
  cin >> N;
  a.resize(N); for (int i = 0; i < N; ++i) cin >> a[i];
  
  int res = 0;
  for (int i = 1; i < N; ++i) {
	if (a[i] == a[i-1]) {
	  a[i] = -1;
	  ++res;
	}
  }
  cout << res << endl;
}	


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
using namespace std;
int main(){
int n,a[101],i,x=0,y=0,j=1;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
for(i=n;i>=1;i--){
if(j%2!=0) x+=a[i];
else y+=a[i];
j++;
}
cout<<x-y<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static Scanner sc;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        int l = sc.nextInt();
        int n = sc.nextInt();
        
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += sc.nextInt() * sc.nextInt();
        }
        
        sum *= -1;
        
        long d = -1;
        long r = -1;
        d = sum / (50000);
        r = sum % (50000);
        
        if (sum != 0) {
            int ans = 1;
            if (r < 0) {
                ans = -1;
                r *= -1;
            }
            
            System.out.println(1 + d);
            System.out.println(ans + " " + r);
            for (int i = 0; i < d; i++) {
                System.out.println(ans + " " + 50000);
            }
        } else {
            System.out.println(0);
        }
    }
    
    public static long lcd(long a, long b) {
        return (a*b)/gcd(a,b);
    }

    public static long gcd(long a, long b) {
        if (a == b) return a;
        if (a > b) {
            return gcd(a - b, b);
        } else {
            return gcd(a, b - a);
        }
    }
    
    public static void calc() {
        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();
        long d = sc.nextInt();
        long e = sc.nextInt();
        long f = sc.nextInt();
        
        // x?????????????§£???
        long k = Math.abs(b)*Math.abs(e)/gcd(Math.abs(b), Math.abs(e));
        long ax = (k/Math.abs(b)) * a;
        long cx = (k/Math.abs(b)) * c;
        long dx = (k/Math.abs(e)) * d;
        long fx = (k/Math.abs(e)) * f;
        float x;
        if (b*e >= 0) {
            x = (cx-fx)/(ax-dx);
        } else {
            x = (cx+fx)/(ax+dx);
        }
        
        // y?????????????§£???
        k = Math.abs(a)*Math.abs(d)/gcd(Math.abs(a), Math.abs(d));
        long by = (k/Math.abs(a)) * b;
        long cy = (k/Math.abs(a)) * c;
        long ey = (k/Math.abs(d)) * e;
        long fy = (k/Math.abs(d)) * f;
        float y;
        if (a*d >= 0) {
            y = (cy-fy)/(by-ey);
        } else {
            y = (cy+fy)/(by+ey);
        }
        
        System.out.println(String.format("%.3f",x) + " " + String.format("%.3f",y));
    }
}

Measured memory_bytes: 26308
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
bit_len = (10 ** 12).to_s(2).size
dp = Array.new(bit_len + 1) { Array.new(2, nil) }
dp[0][0] = 0

bit_len.times do |i|
  mask = 1 << (bit_len - i - 1)

  num = 0
  A.each { |a| num += 1 unless (a & mask).zero? }

  cost0 = mask * num
  cost1 = mask * (N - num)

  if dp[i][1]
    dp[i + 1][1] = [dp[i + 1][1].to_i, dp[i][1] + [cost0, cost1].max].max
  end

  if dp[i][0]
    unless (K & mask).zero?
      dp[i + 1][1] = [dp[i + 1][1].to_i, dp[i][0] + cost0].max
    end
  end

  if dp[i][0]
    unless (K & mask).zero?
      dp[i + 1][0] = [dp[i + 1][0].to_i, dp[i][0] + cost1].max
    else
      dp[i + 1][0] = [dp[i + 1][0].to_i, dp[i][0] + cost0].max
    end
  end
end

puts [dp[bit_len][0].to_i, dp[bit_len][1].to_i].max


Measured memory_bytes: 10932
from collections import Counter

while True:
	n, q = map(int, input().split())
	if (n, q) == (0, 0):
		break
	r = []
	for i in range(n):
		d = list(map(int, input().split()))
		if len(d) > 1:
			r += d[1:]
	r = Counter(r).most_common()
	if len(r) > 0 and r[0][1] >= q:
		print(r[0][0])
	else:
		print(0)

Measured memory_bytes: 7940
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    match s.chars().next().unwrap() {
        'a' | 'e' | 'i' | 'o' | 'u' => println!("vowel"),
        _ => println!("consonant"),
    };
}


Measured memory_bytes: 4352
//
// Created by root on 19/03/26.
//

#include <iostream>
#include <string>

using namespace std;
int main(){
    int max =0;
    int nowL =0;
    string in;
    cin >> in;

    for(int i=0;i<in.size();i++){
        switch(in[i]){
            case 'A':
            case 'C':
            case 'G':
            case 'T':
                nowL++;
                if(nowL>max)max = nowL;
                break;
            default:
                nowL = 0;
                break;
        }
    }

    cout<<max;
    return 0;

}

Measured memory_bytes: 256
//
// ABC179 C - A x B + C
//

#include <bits/stdc++.h>
using namespace std;

int main()
{
    // 標準入力から値を受け取る。
    int n;
    cin >> n;

    // N = A * B + C を満たす正整数の組をカウントする。
    // C = N - (A * B)      --> Cが正の整数になるには N > (A * B) である必要がある。
    // A * B > N            --> これより大きい組み合わせは全て条件を満たさない。
    int ans = 0;
    for (int a = 1; a <= 10e6; a++)
    {
        for (int b = 1; b <= 10e6; b++)
        {
            if (a * b >= n)
            {
                break;
            }
            else
            {
                ans++;
            }
        }
    }

    // 標準出力に結果を出力する。
    cout << ans << endl;

    // 戻り値
    return (0);
}

Measured memory_bytes: 3568