akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define pb push_back
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 1e5 + 10, MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}


void init() {

}



int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
//    ios_base::sync_with_stdio(0);
    init();
    double a,b; cin >> a>>b;
    printf("%.10f\n", a * 1.0/ b);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;


namespace templete
{
    class BinarySearch
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            int[] num_n = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Console.ReadLine();
            int[] num_q = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int count=0;
            foreach(var key in num_q){
                if(Search(num_n,key))count++;
            }
            Console.WriteLine(count);
        }

        static bool Search(int[] num, int key){
            int left=0;
            int right=num.Length;

            while(left<right){
                int mid = (left+right)/2;
                if(num[mid] == key){
                    return true;
                }else if(num[mid] < key){
                    left = mid+1;
                }else{
                    right = mid;
                }
            }
            return false;
        }
    }
}


Measured memory_bytes: 22852
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int a, b;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> a >> b;


	int sum[999];
	memset(sum, 0, sizeof(sum));
	sum[0] = 1;
	rep(i, 1, 999) sum[i] = sum[i - 1] + (i + 1);

	rep(i, 0, 999) {
		if(sum[i - 1] - a == sum[i] - b) {
			cout << sum[i] - b << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
//aからbに向かう,1なら右回り
int get(int a,int b,int n,bool f){
	/*if(a==0){
	if(f)return b;
	else return n-b;
	}
	if(b==0){
	if(f)return n-a;
	else return a;
	}*/
	if(f){
	if(a>b)return b+n-a;
	else return b-a;
	}
	else{
	if(a>b)return a-b;
	else return a+n-b;
	}
}
int main(){
	int n,m,p,t[120000],ans=pow(2,30);
	int a1=0,a2=0;
	cin>>n>>m>>p;
	for(int i=0;i<m;i++)cin>>t[i];
	sort(t,t+m);
	for(int i=0;i<m;i++){
	a1=max(a1,get(p,t[i],n,1));
	}
	for(int i=0;i<m;i++){
	a2=max(a2,get(p,t[i],n,0));
	}
	ans=min(a2,a1);
	if(ans==0)ans=20*n;
	for(int i=0;i<m;i++){//右回りにt[i]まで行って,左回りにt[i+1]まで行く
	ans=min(ans,get(p,t[i],n,true)*2+get(p,t[i+1],n,false));
	if(i==m-1)ans=min(ans,get(p,t[i],n,1)*2+get(p,t[0],n,false));
	//cout<<p<<" "<<t[i]<<" "<<get(p,t[i],n,1)<<" "<<get(p,t[i+1],n,0)<<endl;
	//cout<<ans<<endl;
	}
	for(int i=m-1;i>=0;i--){//左回りにt[i]まで行って、右回りにt[i-1]まで。
	if(i!=0)ans=min(ans,get(p,t[i],n,0)*2+get(p,t[i-1],n,1));
	else ans=min(ans,get(p,t[i],n,0)*2+get(p,t[m-1],n,1));
	}
	if(m==1)cout<<min(get(p,t[0],n,1),get(p,t[0],n,0))*100<<endl;
	else cout<<ans*100<<endl;
	return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<int> line;
	int pro, time;
	cin >> time;
	for (int i = 0; i < time; ++i) {
		cin >> pro;
		line.push_back(pro);
	}
	vector<int>::iterator he;
	int ans=0;
	vector<int>::iterator doll;
	for (he = line.begin() ; he < (line.end() - 1); ++he) {
		doll = he;
		for (vector<int>::iterator he2 = he+1; he2 != line.end(); ++he2) {
			if (*he2 < *doll) {
				doll = he2;
			}
		}
		if (doll != he) {
			int damy;
			damy = *he;
			*he = *doll;
			*doll = damy;
			++ans;
		}
	}
	for (vector<int>::iterator he5 = line.begin(); he5 != (line.end() - 1); ++he5) {
		cout << *he5 << " ";
	}
	cout << *(line.end() - 1) << endl << ans << endl;
	cin >> time;
	return 0;
}

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

using namespace std;
typedef long long LL;
typedef tuple<string, int, int> T;

int main(){
	int N;
	cin >> N;
	vector<T> sp(N);
	rep(i,N){
		string s;
		int p;
		cin >> s >> p;
		p*=-1;
		sp[i]=T(s,p,i+1);
	}
	sort(sp.begin(),sp.end());
	rep(i,N) cout << get<2>(sp[i]) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if(m < 2*n){
        ans += m/2;
    }else if(m == 2*n){
        ans += n;
    }else{
        ans += n + (m - 2*n)/4;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define INFTY 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
void dijkstra();
int n,M[100][100];
int main(void){
  int i,j,u,k,v,c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INFTY;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }
  dijkstra();
  return 0;
}
void dijkstra(){
  int u,minv,i;
  int d[100],p[100],color[100];
  int v;
  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
     }
    if(u==-1)
      break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK&&M[u][v]!=INFTY){
	if(d[v]>M[u][v]+d[u]){
	  d[v]=M[u][v]+d[u];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
}  

  
  



Measured memory_bytes: 2088
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;



int main() {
  int n;
  cin >>n;
  vector<int> d(n);
  for (int i = 0; i <n; i++) 
  {
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  //reverse(a.begin(),a.end());
  int sum =1;

  for(int i=0;i<n-1;i++){
  
    if(d.at(i)<d.at(i+1)){
      sum++;

  }

  
}
  cout<<sum<<endl;
}

Measured memory_bytes: 3540
#include <stdio.h>
int main(){
  int i,j,minj,N,tmp,flag,cnt=0,A[100];

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<N;i++){
    flag = 0;
    minj = i;

    for(j=i;j<N;j++){
      if(A[j] < A[minj]){
	flag = 1;
	minj = j;
      }
    }

    if(flag==1) cnt++;

    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
  }

  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i!=(N-1)){
      printf(" ");
    }
  }
  printf("\n%d\n",cnt);

  return 0;
}



Measured memory_bytes: 2108
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[]
for _ in range(n):
  d=list(map(int,input().split()))
  a.append(d)
x=0
for i in range(n):
  s=c
  for j in range(m):
    s=s+a[i][j]*b[j]
  if s>0:
    x+=1
print(x)

Measured memory_bytes: 3060
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  auto S = cast(char[])readln.chomp;
  auto N = readln.chomp.to!int;

  void solve() {
    bool inverted = false;
    char[200000] head;
    char[200000] tail;
    int num_head;
    int num_tail;

    foreach(_; 0..N) {
      byte queryType; readf(" %d", &queryType);

      if (queryType == 1) {
        inverted ^= true;
        continue;
      }

      byte forHead;
      char toAppend;
      readf(" %d %c\n", &forHead, &toAppend);

      if ((forHead == 1) ^ inverted) {
          tail[num_tail++] = toAppend;
      } else {
          head[num_head++] = toAppend;
      }
    }

    if (inverted) {
      auto reversed_head = head[0..num_head];
      reversed_head.reverse();
      S.reverse();
      writeln( reversed_head ~ S ~ tail[0..num_tail]);
    } else {
      auto reversed_tail = tail[0..num_tail];
      reversed_tail.reverse();
      writeln(reversed_tail ~ S ~ head[0..num_head]);
    }
  }

  solve();
}


Measured memory_bytes: 3224
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int flag=0;
    for (int c=1;c<=3;c++)
    {
        if (a*b*c%2==1)
        {
            flag=1;
        }
    }
    if (flag==1)
    {
        cout <<"Yes";
    }
    else
    {
        cout <<"No";
    }
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    ll n;
    cin >> n;
    ll res = 0;
    res += n / 25;
    n %= 25;
    res += n / 10;
    n %= 10;
    res += n / 5;
    n %= 5;
    res += n;
    cout << res << endl;
}



Measured memory_bytes: 3212
// Author : Hardik Upadhyay
// college: SVNIT 
// slogan : Ab to phod dunga
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#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 debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MAXN = 100005;
ll mod=1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(( a[0] == a[1] and a[0]!=a[2]) ||( a[1] == a[2] and a[0] != a[1])) cout<<"Yes"<<nl;
	else cout<<"No"<<nl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
#include <stack>
using namespace std;
long long a,b,n,s[100010],l,h=1000000000,ans,mx;
bool check(long long mid){
 long long sum=0;
 for(int i=0;i<n;i++)
  if(s[i]-mid*b>0)
   sum+=(s[i]-mid*b+a-b-1)/(a-b);
 return sum<=mid;
}
int main(){
cin>>n>>a>>b;
for(int i=0;i<n;i++){
 cin>>s[i];
 mx=max(mx,s[i]);
}
long long mid;
while(l<=h){
 mid=(l+h)/2;
 if(check(mid)==1)
 {ans=mid;
  h=mid-1;
 }
 else
  l=mid+1;
}
cout<<ans;
system("pause");
return 0;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    string s;
    cin>>s;
    int a, b;
    a = -1;
    b = -1;
    if(s.size() == 2){
        if(s[0] == s[1]){
            a = 1;
            b = 2;
        }
    }
    else{
        rep(i, s.size()-2){
        if(s[i] == s[i+1] || s[i+1] == s[i+2] || s[i] == s[i+2]){
            a = i+1;
            b = i+3;
            break;
        }
    }
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int a;
    int b;
    ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
    for (int i=0;i<m;i++) {
      a = sc.nextInt();
      b = sc.nextInt();
      ArrayList<Integer> alist = new ArrayList<>();
      alist.add(a); alist.add(b);
      list.add(alist);
    }
    Collections.sort(
        list,
        new Comparator<ArrayList<Integer>>() {
          public int compare(ArrayList<Integer> list1, ArrayList<Integer> list2) {
            return list1.get(0)-list2.get(0);
          }
        }
        );
    List<Integer> al = new ArrayList<>();
    List<Integer> bl = new ArrayList<>();
    al.add(list.get(0).get(0));
    bl.add(list.get(0).get(1));
    int ag;
    int bg;
    int max;
    int min;
loop:
    for (int i=1;i<m;i++) {
      a = list.get(i).get(0);
      b = list.get(i).get(1);
      for (int j=0;j<al.size();j++) {
        ag = al.get(j);
        bg = bl.get(j);
        min = Math.max(a,ag);
        max = Math.min(b,bg);
        if (min<max) {
          al.set(j,min);
          bl.set(j,max);
          continue loop;
        }
      }
      al.add(a);
      bl.add(b);
    }
    System.out.println(al.size());
  }
}


Measured memory_bytes: 103120
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cstdlib>
using namespace std;
const int N=2e5+10;
char s[N];
int main()
{
    long long ans=0,cnt=0;
    int l,i;
    scanf("%s",s);
    l=strlen(s);
    for(i=0;i<l;i++)
    {
        if(s[i]=='A')
            cnt++;
        else
        {
        if(i+1<l&&s[i]=='B'&&s[i+1]=='C')
        {
            ans+=cnt;
            i++;
        }
        else
            cnt=0;
        }
      //  printf("%d %d\n",cnt,ans);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,m;
int res=0;
string tmp;
map<string,int> map_c;
int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> tmp;
    map_c[(tmp)]++;
  }
  scanf("%d",&m);
  for(int i=0;i<m;i++){
    cin >> tmp;
    map_c[(tmp)]--;
  }
  map<string,int>::iterator it=map_c.begin();
  for(;it!=map_c.end();++it){
    res=max((*it).second,res);
  }
  printf("%d",res);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    if(b <= a){
        cout << "delicious" << endl;
    }else if(b-a <= x){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    d = int(input())
    if d == 0:
        return False
    n = int(input())
    m = int(input())
    stores = [int(input()) for _ in range(n-1)]
    stores = [0]+sorted(stores)+[d]

    ret = 0
    for _ in range(m):
        dest = int(input())
        l = bisect.bisect_right(stores, dest)
        dist = min(stores[l]-dest, dest-stores[l-1])
        ret += dist
    return ret


ans = []
while True:
    a = solve()
    if a:
        ans.append(a)
    else:
        break
print("\n".join(map(str, ans)))



Measured memory_bytes: 11008
#include <stdio.h>

int main(void)
{
	int price;
	int n;
	int num = 0;
	int sum = 0;
	int count = 0;
	int ave;
	
	while (scanf("%d,%d", &price, &n) != EOF){
		sum += price * n;
		count += n;
		num++;
	}
	printf("%d\n", sum);
	ave = 1.0 * count / num + 0.5;
	printf("%d\n", ave);
	
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
int N;
int a[100100];
vi g[100100];
int rec(int v){
	vi ret;
	for(int i=0;i<g[v].size();i++){
		ret.pb(rec(g[v][i]));
	}
	if(ret.size()==0)return 0;
	sort(all(ret),greater<int>());
	for(int i=0;i<ret.size();i++){
		ret[i] += i+1;
	}
	int res = *max_element(all(ret));	
	// cout << v << ' ' << res << endl;
	return res;
}
int main(){
	cin >> N;
	for(int i=1;i<N;i++){
		cin >> a[i];
		a[i]--;
		g[a[i]].pb(i);
	}
	cout << rec(0) << endl;
	return 0;
}


Measured memory_bytes: 13952
//Optional FAST
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
 
//Required Libraries
 

#include <bits/stdc++.h>
//#include<iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
 
//Required namespaces
 
using namespace std;
using namespace __gnu_pbds;
//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define pb push_back
#define pf push_front
#define fi first
#define se second
//#define endl '\n'
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
vector<ll> pr; 
//ll z[1001][11]={0};
int main()
{
    /*
    #ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif
    */
    fio;
    ll n;
    cin>>n;
    ll h[n];
    forin(i,0,n-1)
    cin>>h[i];

    ll ans=0;
    vector<ll> dp(n,inf);
    dp[0]=0;
    forin(i,0,n-1)
    {
         forin(j,i+1,i+2)
         {
             if(j<n)
             dp[j]=min(dp[j],dp[i]+abs(abs(h[j]-h[i])));
         }
       
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);

		int A = stdIn.nextInt();
		int B = stdIn.nextInt();


		System.out.println((A-1)*(B-1));

	}

}


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

typedef pair<int,int> P;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int W, H;
int sx, sy, gx, gy;
vector<string> vs;
vector<vector<long double> > gdist;
vector<vector<long double> > sdist;

void make() {
    gdist[gx][gy] = 0;
    queue<P> que;
    que.push(P(gx,gy));
    while (que.size()) {
        P p = que.front(); que.pop();
        int x = p.first, y = p.second;

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && (vs[nx][ny] == '.' || vs[nx][ny] == 's') && gdist[nx][ny] > gdist[x][y] + 1) {
                gdist[nx][ny] = gdist[x][y] + 1;
                que.push(P(nx,ny));
            }
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (vs[i][j] == '*') {
                que.push(P(i,j));
                sdist[i][j] = 0;
            }
        }
    }

    while (que.size()) {
        P p = que.front(); que.pop();
        int x = p.first, y = p.second;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && (vs[nx][ny] == '.' || vs[nx][ny] == 's') && sdist[nx][ny] > sdist[x][y] + 1) {
                sdist[nx][ny] = sdist[x][y] + 1;
                que.push(P(nx,ny));
            }
        }
    }
}

long double check(long double e) {
    long double ret = 0.0;
    int cnt = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (vs[i][j] == '.' || vs[i][j] == 's') {
               long double dist = 1e+50;
               dist = min(dist, gdist[i][j]);
               dist = min(dist, sdist[i][j] + e);
               ret += dist;
               cnt ++;
            }
        }
    }

    return ret / (long double)cnt;
}

int main() {
    cin >> W >> H;
    vs.resize(H);
    gdist.resize(H);
    sdist.resize(H);
    for (auto &i : gdist) i.resize(W, 1e50);
    for (auto &i : sdist) i.resize(W, 1e50);
    for (auto &i : vs) cin >> i;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (vs[i][j] == 'g') gx = i, gy = j;
            if (vs[i][j] == 's') sx = i, sy = j;
        }
    }

    make();

    long double l = 0.0, r = 1e+18;
    for (int c = 0; c < 100; c++) {
        long double m = (l + r)/2.0;
        // printf("%.10Lf\n", m);
        if (check(m) > m) {
            l = m;
        } else {
            r = m;
        }
    }
    printf("%.10Lf\n", min(l + sdist[sx][sy], gdist[sx][sy]));

    return 0;
}

Measured memory_bytes: 11268
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int gcd(int a,int b){
	a=abs(a),b=abs(b);
	if(b==0) return a;
	else if(a<b) return gcd(b,a);
	else return gcd(b,a%b);
}

int main(){
	int n,x; cin>>n>>x;
	int g=0;
	FOR(i,0,n){
		int a; cin>>a;
		g=gcd(g,a-x);
	}
	co(g);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int l;
    cin>>l;
    int c=0;
    for(int i=1;i<=l;i++){
        int ll;
        cin>>ll;
        if(i%2!=0 && ll%2!=0) c++;
    }   
    cout<<c<<endl;
}

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

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> v(h,vector<char>(w,0));
  r(i,h){
	r(j,w)cin >> v.at(i).at(j);
}
  r(i,h){
    r(j,w)cout << v.at(i).at(j);
    cout << endl;
    r(j,w)cout << v.at(i).at(j);
    cout << endl;
  }
  
}

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

int A[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
  int K;
  cin >> K;
    
  cout << A[K -1] << endl;
}


Measured memory_bytes: 256
import numpy as np

N,D = map(int, input().split())
A = np.zeros((N,D))

for i in range(N):
    A[i] = np.array(input().split(), dtype=np.int64)
    
ans = 0
    
for i in range(N):
    for j in range(N):
        B = A[i]
        C = A[j]
        k = np.linalg.norm(C - B, ord=2)
        if k.is_integer() == True:
            ans += 1
            
ans = ans - N
ans = int(ans / 2)
print(ans)

Measured memory_bytes: 12396
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_A
#include <iostream>
using namespace std;
int main(){
  int H, W;
  while (cin >> H >> W) {
    if(H == 0 && W == 0){
      break;
    }
    else{
        for(int i = 0; i < W; i++){
          cout << "#";
        }
        cout << endl; //???????????????
        for(int j = 0; j < H-2; j++){
          cout << "#";
          for(int i=0; i< W-2; i++){
            cout << ".";
          }
          cout << "#" << endl;
        }
      //???????????????
      for(int i = 0; i < W; i++){
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1152
from numpy import*
from scipy.sparse import*
def main():
  f=csgraph.floyd_warshall
  t=int32(open(0).read().split())
  n,m,l=t[:3]
  t=t[3:]
  m*=3
  print('\n'.join(map(str,map(int,f(f(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n)%n-1))))
main()

Measured memory_bytes: 41964
#include<bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include<chrono>
using namespace std;
using namespace std::chrono;
//using namespace __gnu_pbds;
#define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi         first
#define se         second
#define int         long long
#define pb         push_back
#define emp        emplace_back
#define vv(x)      vector<x>
#define mp(x,y)    map<x,y>
#define dq(x)      deque<x>
#define pql(x)     priority_queue<x>
#define pqs(x)     priority_queue<x,vv(x),greater<x> >
#define mod         1000000007
#define forf(i,a,b) for(int i=a;i<b;i++)
#define it(x)      x::iterator
#define ll         long long
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#define vii        vector<int>
#define big        3e18
#define sm         -2e9
#define mkr        make_pair
#define vpi        vector<pair<int,int> >
#define pii        pair<int,int>
#define rng        500005
#define sz(x)      (int)x.size()
#define rv(x)      reverse(x.begin(),x.end())
#define out(x)     cout<<x.fi<<" "<<x.se<<endl;
 
//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
 
void pr_init()
{
 
#ifndef ONLINE_JUDGE
  freopen("gin.txt", "r", stdin);
  freopen("gout.txt", "w", stdout);
 
#endif
}

int dp[81];
void solve()
{
  
int n;
cin >> n;
int a[n];
forf(i,0,n) cin >> a[i];


dp[0]=1000;

for(int i=1;i<n;i++)
{
  for(int j=i-1;j>=0;j--)
  {
    if(a[j] < a[i])
    {
        dp[i] = max(dp[i],(dp[j]/a[j])*a[i]+dp[j] - (dp[j]/a[j])*a[j]);
    }else
    {
        dp[i] = max(dp[i],dp[j]);
    }
  }
}

cout<<dp[n-1];
  
}
 
 
int32_t main()
{
  pr_init();
  //fastio;
 
  auto start = high_resolution_clock::now();
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);
  // cout << "Time taken by function: "
  //       << duration.count() << " microseconds" << endl;
 
}
 

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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   int N;
   cin >> N;
   vector<int> A(N);

   rep(i, N) cin >> A.at(i);

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

   string ans = "YES";
   rep(i, N - 1) {
     if (A.at(i) == A.at(i + 1)) {
       ans = "NO";
       break;
     }
   }
   cout << ans << endl;
 }


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define fill(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    int r=0;
    int w=0;
    rep(i,0,n)
    if(str[i]=='R')
        r++;
    else
        w++;
    int wr=0;
    rep(i,0,r)
    if(str[i]!='R')
        wr++;
    int ww=0;
    repA(i,r,n-1)
    if(str[i]!='W')
        ww++;
    cout<<min(wr,ww)<<endl;
}

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

int main() {
  long long L, R;
  scanf("%lld%lld", &L, &R);

  long long MOD = 2019;

  long long ans = MOD;
  for (long long i = L; i < R && ans > 0; i++) {
    for (long long j = i + 1; j <= R && ans > 0; j++) {
      ans = min((i * j) % MOD, ans);
    }
  }

  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    ll key;
    rep(i, n) {
        cin >> key;
        if(mp.count(key) != 0) {
            mp.erase(key);
        } else {
            mp[key] = 1;
        }
    }
    cout << mp.size();
}


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

int main()
{
    int t,count=0;
    scanf("%d",&t);
    int a[t];

    for(int i=0; i<t; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0; i<t-1; i++)
    {
        for(int j=0; j<t-i-1; j++)
        {
            if(a[j]>a[j+1])
            {
                a[j]=a[j]+a[j+1];
                a[j+1]=a[j]-a[j+1];
                a[j]=a[j]-a[j+1];
                count++;
            }
        }
    }
    for(int i=0; i<t; i++)
    {
        printf("%d",a[i]);
        if(i<t-1)
            printf(" ");

    }
    cout<<endl;
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 3192
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  n%=10;
  if(n==3)cout<<"bon"<<endl;
  else if(n==0||n==1||n==6||n==8)cout<<"pon"<<endl;
  else cout<<"hon"<<endl;
  return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=1;i<=1000;i++)
	{
		if(b*i>=a)
		{
			printf("%d",c*i);
			return 0;
		}
	}
}

Measured memory_bytes: 1712
#include <stdio.h>
int main(void){
    int n;
    while(1){
        scanf("%d",&n);
        int sum=0,ad,max=0,min=1000,suma;
        if(n==0) break;
        for(int i=0;i<n;i++){
	        int s[n];
            scanf("%d",&s[i]);
    	    sum=sum+s[i];
	    	if(s[i]>max) max=s[i];
	    	if(s[i]<min) min=s[i];
		    suma=sum-(max+min);
	    	ad=suma/(n-2);
		}
		printf("%d\n",ad);
	}
	return 0;
}


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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back
#define mid ((l+r)>>1)

const int N = 1000007, inf = 0x3f3f3f3f;
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

int seg[4 * N];
void update(int p, int l, int r, int j, int x) {
	if(r < j or l > j) return;
	if(l == r) {
		seg[p] = x;
	} else {
		update(2 * p, l, mid, j, x);
		update(2 * p + 1, mid+1, r, j, x);
		seg[p] = max(seg[2 * p], seg[2 * p + 1]);
	}
};

int query(int p, int l, int r, int a, int b) {
	if(r < a or l > b) return 0;
	if(l >= a and r <= b) return seg[p];
	return max(query(2 * p, l, mid, a, b), query(2 * p + 1, mid+1, r, a, b));
}

int a[N], f[N], lis[N]; // f eh a lis
vector<int> e[N];
void solve(int u, int best, int p = -1) {

	int x = a[u];
	assert(x <= 300000);
	// cout << u << ' ' << x << endl;
	int bef = query(1, 0, 200000, 0, x-1);
	f[u] = bef + 1;
	lis[u] = max(f[u], best);

	int aux = query(1, 0, 200000, x, x);
	update(1, 0, 200000, x, max(f[u], aux));

	for(int v : e[u]) {
		if(v == p) continue;
		solve(v, lis[u], u);
	}

	update(1, 0, 200000, x, aux);
}


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

	int n; cin >> n;
	vector<int> vec;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		vec.pb(a[i]);
	}

	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());

	for(int i = 1; i <= n; ++i) {
		int j = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin();
		a[i] = j;
	}
	for(int i = 1; i < n; ++i) {
		int u, v; cin >> u >> v;
		e[u].pb(v);
		e[v].pb(u);
	}

	solve(1, 0, -1);

	for(int u = 1; u <= n; ++u) cout << lis[u] << '\n';
}

Measured memory_bytes: 50136
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	long long int n;
	cin >> n;
	long long int ans = 0;
	for (long long int i = 1; i <= n; i++) {
		if (n % i == 0) {
			ans--;
		}
		ans = ans + n / i;
	}
	cout << ans;
}

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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
   long long int ac=0,wa=0,tle=0,re=0,n;
  cin>>n;
  while(n--){
    string a;
    cin>>a;
    //cout<<a;
    if(a[0]=='A')
        ac++;
    if(a[0]=='W' )
        wa++;
    if(a[0]=='T')
        tle++;
    if(a[0]=='R')
        re++;
  }
       cout<<"AC x "<<ac<<endl;
       cout<<"WA x "<<wa<<endl;
       cout<<"TLE x "<<tle<<endl;
       cout<<"RE x "<<re<<endl;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//SOLVE
void solve(void)
{
  int N,K;
  cin>>N>>K;
  vector<int> H (N+1,0); 
  for (int i = 0; i < N; i++)
  {
    cin>>H[i];
  }
  vector<int> DP (N+1,INF);
  DP[0] = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = 1; j <= K; j++)
    {
      int nV = i + j;
      if(nV >= N)continue;
      chmin(DP[nV], DP[i] + abs(H[i] - H[nV]));
    }
      // DEBUG(DP);
  }

  cout<<DP[N-1]<<endl;
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

flag = True
for i in range(min(a-1, b-1), max(c, d)-1):
    if s[i] == '#' and s[i+1] == '#':
        flag = False

if c > d:
    flag2 = False
    for i in range(b-1, d):
        if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.':
            flag2 = True
else:
    flag2 = True

if flag and flag2:
    print('Yes')
else:
    print('No')


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, m, q;
	scanf("%d%d%d", &n, &m, &q);
	vector<vi> cnt(n+1);
	for (int i = 0; i < m; i++) {
		int l, r;
		scanf("%d%d", &l, &r);
		cnt[r].push_back(l);
	}
	for (int i = 1; i <= n; i++)
		sort(all(cnt[i]));

	while (q-- > 0) {
		int x, y;
		scanf("%d%d", &x, &y);
		int answer = 0;
		for (int i = x; i <= y; i++) {
			auto it = lower_bound(all(cnt[i]), x);
			answer += cnt[i].end() - it;
		}
		printf("%d\n", answer);
	}
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
    #define Mod 1000000007
    #define INF 1e9
    #define INFL 9e18
    #define EPS 1e-9
    #define pb push_back
    #define mp make_pair
    #define SET(a) memset(a,-1,sizeof(a))
    #define CLR(a) memset(a,0,sizeof(a))
    #define CPY(a,b) memcpy(a,b,sizeof(a))
    #define all(a) (a).begin(),(a).end()
    #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define N 200005
    #define fs first
    #define sc second
    using namespace std;

    typedef  long long int ll;
    typedef pair<ll,ll> ii;
    typedef vector <ii> vii;
    typedef vector <ll> vi;
   
  

   
    int main()
    {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios;
 set<ll> s;
 ll num,n;
 cin>>n;
 for(int i=0;i<n;i++)
{
  cin>>num;
  s.insert(num);
}
cout<<(ll)s.size()<<endl;














    return 0;


    }

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int n;
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();

        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];

        for(int i=0; i<n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
            c[i] = scanner.nextInt();
        }

        int[][] dp = new int[n][3];
        dp[0][0] = a[0];
        dp[0][1] = b[0];
        dp[0][2] = c[0];
        //dp[1] = Math.abs(a[0]-a[1]);

        for(int i=1; i<n; i++) {
            dp[i][0] = Integer.MIN_VALUE;
            dp[i][1] = Integer.MIN_VALUE;
            dp[i][2] = Integer.MIN_VALUE;

            dp[i][0] = Math.max(a[i] + dp[i-1][1], a[i] + dp[i-1][2]);
            dp[i][1] = Math.max(b[i] + dp[i-1][0], b[i] + dp[i-1][2]);
            dp[i][2] = Math.max(c[i] + dp[i-1][0], c[i] + dp[i-1][1]);
        }

        System.out.println(Math.max(dp[n-1][0],Math.max(dp[n-1][1],dp[n-1][2])));
    }

}


Measured memory_bytes: 93404
#include<bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=n-1;(i)>=0;(i)--)
#define ll long long

using namespace std;
const ll MOD = 1e9+7;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll powmod(ll a, ll b){
    ll c = 1;
    ll ans = 1;
    while(c <= b){
        if(c & b){
            ans *= a;
            ans %= MOD;
        }
        c <<= 1;
        a *= a;
        a %= MOD;
    }
    return ans;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<bool,bool>> X(N*M,{false,false});
    int hoge;
    rep(i,N){
        cin >> hoge;
        if(X[hoge-1].first){
            cout << 0 << endl;
            return 0;
        }
        X[hoge-1].first = true;
    }
    rep(i,M){
        cin >> hoge;
        if(X[hoge-1].second){
            cout << 0 << endl;
            return 0;
        }
        X[hoge-1].second = true;
    }
    ll ans = 1;
    int H=0,W=0,count=0;

    rrep(i,N*M){
        int hoge = 1;
        if(X[i].first)  H += 1;
        if(X[i].second) W += 1;

        if(!X[i].first && !X[i].second){
            ans *= H*W-count;
        }else if(X[i].first && !X[i].second){
            ans *= W;
        }else if(!X[i].first && X[i].second){
            ans *= H;
        }else{
        }

        ans %= MOD;
        count++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2176
#include <iostream>
using namespace std;
int n,cnt[1000005],i,x;
long long ans;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>x;
		cnt[x]++;
	}
	if (n&1)
	{
		for (i=2;i<=n;i+=2)
		{
			if (cnt[i]!=2)
			{
				cout<<0;
				return 0;
			}
		}
		if (cnt[0]!=1)
		{
			cout<<0;
			return 0;
		}
	}
	else
	{
		for (i=1;i<=n;i+=2)
		{
			if (cnt[i]!=2)
			{
				cout<<0;
				return 0;
			}
		}
	}
	ans=1;
	for (i=1;i<=n/2;i++) (ans*=2)%=((long long)1e9+7);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
 
int main(){
  long long N;
  long long A,B,C,D,E;
  cin >> N;
  cin >> A >> B >> C >> D >> E;
  
  long long MinMove = min({ A,B,C,D,E });
  long long ans = ((N + MinMove -1 )/ MinMove) + 4;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int ans[100000];
 
signed main(){
  int n;cin>>n;
  for(int i=1;i<=100;i++){
    for(int j=1;j<=100;j++){
      for(int k=1;k<=100;k++){
        int a=i*i+j*j+k*k+i*j+j*k+k*i;
        ans[a]++;
      }
    }
  }
  for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 3792
mod = 2019
cnt = [0 for i in range(2019)]
cnt[0] = 1
x = 0
ten = 1
ans = 0

for s in input()[::-1]:
    x = (x + int(s) * ten) % mod
    ans += cnt[x]
    cnt[x] += 1
    ten *= 10
    ten %= mod

print(ans)

Measured memory_bytes: 68928
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll a; ll b;
    cin >> a >> b;
    cout << 6 - a -b << endl;
    return 0;
}

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

#define INF (1<<30)

int main(){
	int n,h;	cin>>n>>h;
	priority_queue< pair<int,int> >katana;

	pair<int,int>aMAX={INF,0};
	for(int i=0;i<n;i++){
		int a,b;	cin>>a>>b;
		katana.push({b,a});

		if(aMAX.second<a)aMAX={b,a};
	}

	//printf("MAX{b,a}={%d,%d}\n",aMAX.first, aMAX.second);
	int maxA=aMAX.second;

	int ans=0;
	pair<int,int>t;
	while(katana.empty()==false){
		// 投げれるやつ全部投げる
		t=katana.top(); katana.pop();
		int B=t.first;

		if(B<=maxA){
			// もう振り最強だけでいいよね
			break;
		}

		ans++;
		h-=B;
		if(h<=0){
			cout<<ans<<endl;
			return 0;
		}
	}

	if(h>0){
		
		ans+=(h+maxA-1)/maxA;
	}

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


Measured memory_bytes: 1400