akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	char c; cin >> c;
	if ('a' > c) {
		cout << "A" << endl;
	}
	else {
		cout << "a" << endl;
	}

	return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
# DPL_1_I: Combinatorial - Knapsack Problem with Limitations II

from heapq import heappush, heappop


def max_value(t, xs):
    def _cost(weight, value, i):
        for j in range(i, n):
            v, w = xs[j]
            if weight + w > t:
                return (-value, -value - (v/w)*(t-weight))
            weight += w
            value += v
        return (-value, -value*1.0)

    n = len(xs)
    xs.sort(key=lambda x: x[1], reverse=True)
    xs.sort(key=lambda x: x[0]/x[1], reverse=True)
    u, c = _cost(0, 0, 0)
    heap = [(c, u, 0, 0, 0)]
    maxcost = u
    while heap:
        cost, upper, weight, value, i = heappop(heap)
        if cost > maxcost:
            break
        if i < n:
            v, w = xs[i]
            if weight+w <= t:
                heappush(heap, (cost, upper, weight+w, value+v, i+1))
            u, c = _cost(weight, value, i+1)
            if c < maxcost:
                if u < maxcost:
                    maxcost = u
                heappush(heap, (c, u, weight, value, i+1))

    return -maxcost


def run():
    n, t = [int(i) for i in input().split()]
    xs = []

    for _ in range(n):
        v, w, m = [int(i) for i in input().split()]
        for i in range(m.bit_length()-1):
            h = 2**i
            m -= h
            xs.append((v*h, w*h))
        if m > 0:
            xs.append((v*m, w*m))

    print(max_value(t, xs))


if __name__ == '__main__':
    run()



Measured memory_bytes: 5844
import java.util.*;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long D = sc.nextLong();
		int count =0;


//配列にしないと、最後の値だけ反映されるとかそんな感じになる？
		for(int i=0; i<N; i++){
		long X =sc.nextLong();
		long Y=sc.nextLong();
		

			if(X*X+Y*Y<=D*D){
			count++;
			}
		}

		System.out.println(count);				

	}//main

}//Distance


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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ht=a;
    int pt=b;
    int ha=c;
    int pa=d;
    for(int i=0;; i++)
    {
        if(i%2==0)
        {
            ha-=pt;
            if(ha<0 || ha==0)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        else
        {
            ht-=pa;
            if(ht<0 || ht==0)
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    return 0;
}





Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

ll dp[3005][3005][5];

int main()
{
    int r, c, k;
    cin >> r >> c >> k;

    vvint g(r, vint(c));
    rep(i, k)
    {
        int y, x, v;
        cin >> y >> x >> v;
        g[y - 1][x - 1] = v;
    }

    rep(y, r) rep(x, c) rep(i, 4)
    {
        // carry over
        chmax(dp[y][x + 1][i], dp[y][x][i]);
        // take the one we're looking at
        //  came from above
        chmax(dp[y][x + 1][i + 1], dp[y][x + 1][0] + g[y][x]);
        //  came from left
        chmax(dp[y][x + 1][i + 1], dp[y][x][i] + g[y][x]);
        // take n-1 is the same as take n
        chmax(dp[y][x + 1][i + 1], dp[y][x + 1][i]);
        // move down
        chmax(dp[y + 1][x + 1][0], dp[y][x + 1][i]);
    }

    // view(g);
    // rep(y, r + 2)
    // {
    //     rep(x, c + 2)
    //     {
    //         cout << "[";
    //         rep(i, 4)
    //         {
    //             cout << dp[y][x][i] << " ";
    //         }
    //         cout << "]";
    //     }
    //     cout << endl;
    // }

    cout << dp[r][c][0] << endl;

    return 0;
}

Measured memory_bytes: 390760
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll x, y; cin >> x >> y;
    bool jud = true;
    if(y %2 == 1) jud = false;

    if(x*2 > y || x*4 < y) jud = false;

    if(jud){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3632
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << min(A + B, min(B + C, A + C)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  int n,m,v=1;
  cin>>n>>m;
  fr(i,m) v*=2;
  cout<<(1800*m+100*n)*v<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <array>

using namespace std;

#define forange(counter, end) forstep(counter, 0, end)
#define forstep(counter, begin, end) forstep_type(size_t, counter, begin, end)
#define forange_type(type, counter, end) forstep_type(type, counter, 0, end)
#define forstep_type(type, counter, begin, end) for (type counter = begin, forstep_type_end_##counter = end; counter < forstep_type_end_##counter; counter++)

const int D = 365;
const int C = 26;

array<int, C> contest;
array<array<int, C>, D> satisfaction;

int decr(const int c, const int last, const int now) {
	return contest[c] * (now - last);
}

int getScore(const array<short, C>& last, const int open, const int day) {

	int score = 0;

	forange_type(int, c, C)
	{
		if (c == open)
		{
			score += satisfaction[day][c];
		}
		else
		{
			score -= decr(c, last[c], day);
		}
	}

	return score;
}

int getScore(const array<char, D>& cont) {

	int score = 0;
	array<short, C> last;
	last.fill(-1);

	forange_type(short, d, D)
	{
		score += getScore(last, cont[d], d);
		last[cont[d]] = d;
	}

	return 1000000 + score;
}

struct Data {
	Data() {
		last.fill(-1);
		c.fill(0);
	}

	array<short, C> last;
	array<char, D> c;
	int score = 0;

	bool operator<(const Data& o) const {
		return score < o.score;
	}
};

array<char, D> think() {

	priority_queue<Data> qData;
	qData.push(Data());

	const int BeamWidth = 500;

	forange_type(int, d, D)
	{
		decltype(qData) next;
		forange(w, BeamWidth)
		{
			if (qData.empty()) break;

			const auto top = qData.top();
			qData.pop();

			forange_type(char, c, C)
			{
				Data nextData = top;
				const int score = getScore(nextData.last, c, d);

				nextData.last[c] = d;
				nextData.c[d] = c;
				nextData.score += score;

				next.push(nextData);
			}

		}

		qData.swap(next);
	}

	const auto& top = qData.top();

	cerr << "score:" << getScore(top.c) << endl;

	return top.c;
}

int main() {

	int d;
	cin >> d;

	for (auto& c : contest)
	{
		cin >> c;
	}

	forange(d, D)
	{
		forange(s, C)
		{
			cin >> satisfaction[d][s];
		}
	}

	const auto ans = think();

	for (const auto& a : ans)
	{
		cout << (int)(a + 1) << endl;
	}

	return 0;
}


Measured memory_bytes: 20896
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,t,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> a >> b >> t;
	ans = t / a * b;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));

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


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,c,x,y,ans=1000000001,x1,y1;
	cin>>a>>b>>c>>x>>y;
	for(ll i=0;i<10000001;i+=2){
		x1=i;
		if(x<=i/2)x1=2*x;
		y1=i;
		if(y<=i/2)y1=2*y;
		ans=min(ans,(i*c)+a*(x-x1/2)+b*(y-y1/2));
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
import collections 

MINUSINF = '-'

def chmax(a, b):
    if a == MINUSINF:
        return b
    elif len(a) < len(b):
        return b
    elif len(a) == len(b):
        return a if a > b else b
    else:
        return b
        
n, m = [int(s) for s in input().split()]
alist = [int(s) for s in input().split()]

match = [2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [MINUSINF for i in range(11000)]
dp[0] = ''

for i in range(n+1):
    if dp[i] == MINUSINF:
        continue
    for j, a in enumerate(alist):
        dp[i + match[a-1]] = chmax(dp[i + match[a-1]], dp[i] + str(a))

print(dp[n])



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

int main() {
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 0; i < 6; i++) {
		if (S.at(i) == '1') ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include <string.h>
using namespace std;

int main(){
	double i,j,m,n;
	char a,b;
	while(cin>>a>>b){
		if(a=='H'){
			if(b=='H'){
				cout<<"H"<<endl;
			}
			else if(b=='D'){
				cout<<"D"<<endl;
			}
		}else if(a=='D'){
			if(b=='H'){
				cout<<"D"<<endl;
			}
			else if(b=='D'){
				cout<<"H"<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> inline T sqr (T x) { re x * x; }

#define filename ""

int n;
int m;
int x[200];

int main () {
	scanf ("%d", &n); n *= 2;
	for (int i = 0; i < n; i++) scanf ("%d", &x[i]);
	sort (x, x + n);
	reverse (x, x + n);
	int ans = 0;
	for (int i = 1; i < n; i += 2) ans += x[i];
	printf ("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
def main():
    k=int(input())
    l=[[] for _ in range(20)]
    l[1]=[0,1,2,3,4,5,6,7,8,9]
    cnt=9
    if cnt>=k:
        print(l[1][k])
        exit()
    for i in range(2,20):
        for keta in range(1,i):
            for j in l[keta]:
                f=j//10**(i-2)
                if j==0:
                    l[i].append(10**(i-1)+j)
                if f==0:
                    if j//10**(len(str(j))-1)==1:
                        l[i].append(10**(i-1)+j)
                elif f==1:
                    l[i].append(10**(i-1)+j)
                    l[i].append(2*10**(i-1)+j)
                elif f==9:
                    l[i].append(8*10**(i-1)+j)
                    l[i].append(9*10**(i-1)+j)
                elif f>0:
                    l[i].append((f-1)*10**(i-1)+j)
                    l[i].append(f*10**(i-1)+j)
                    l[i].append((f+1)*10**(i-1)+j)
        if cnt+len(l[i])>=k:
            l[i].sort()
            ans=l[i][k-cnt-1]
            if ans==0:
                print(10**(i-1))
            else:
                print(ans)
            exit()
        else:
            cnt+=len(l[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 12384
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 200005;
#define sz(v) ((int)v.size())

struct disj{
	int pa[MAXN];
	void init(int n){
		iota(pa, pa + n + 1, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}disj;

struct func{
	lint out;
	lint B, A; // f(W) = max(W + B, A)
};

int n, m, a[MAXN], b[MAXN];
vector<int> gph[MAXN];
func val[MAXN];

struct edg{
	int s, e, x;
	bool operator<(const edg &ed)const{
		return e < ed.e;
	}
}ed[MAXN];

int rev[MAXN];

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1; i<=n; i++){
		scanf("%d %d",&a[i],&b[i]);
		a[i] = max(a[i], b[i]);
	}
	vector<int> ord(n);
	iota(ord.begin(), ord.end(), 1);
	sort(ord.begin(), ord.end(), [&](const int &x, const int &y){
		return a[x] - b[x] < a[y] - b[y];
	});
	for(int i=0; i<sz(ord); i++) rev[ord[i]] = i;
	for(int i=0; i<m; i++){
		scanf("%d %d",&ed[i].s,&ed[i].e);
		ed[i].s = rev[ed[i].s];
		ed[i].e = rev[ed[i].e];
		if(ed[i].s > ed[i].e) swap(ed[i].s, ed[i].e);
	}
	sort(ed, ed + m);
	disj.init(n);
	for(int i=0; i<m; i++){
		ed[i].s = ord[ed[i].s];
		ed[i].e = ord[ed[i].e];
		if(disj.uni(ed[i].s, ed[i].e)){
			gph[ed[i].e].push_back(ed[i].s);
		}
	}
	disj.init(n);
	for(auto &x : ord){
		vector<func> vect;
		for(auto &i : gph[x]){
			int p = disj.find(i);
			vect.push_back(val[p]);
		}
		if(vect.empty()){
			val[x] = (func){a[x], b[x], a[x]};
			continue;
		}
		lint bsum = 0;
		for(auto &i : vect) bsum += i.B;
		func ret = {(lint)1e18, b[x] + bsum, a[x] + bsum};
		for(auto &i : vect){
			lint cur_out = max(i.out + b[x], 1ll * a[x]);
			cur_out += bsum - i.B;
			ret.out = min(ret.out, cur_out);
		}
	//	printf("%d = %lld %lld %lld\n", x, ret.A, ret.B, ret.out);
		for(auto &i : gph[x]) disj.uni(i, x);
		val[disj.find(x)] = ret;
	}
	cout << val[disj.find(ord.back())].out << endl;
}


Measured memory_bytes: 18168
#include <cstdio>
#include <math.h>

using namespace std;

int main(void){
	int n, i;
	double a, b, c;
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%lf%lf%lf",&a,&b,&c);
		if(pow(a,2.0) + pow(b,2.0) == pow(c,2.0) || pow(b,2.0) + pow(c,2.0) == pow(a,2.0) || pow(c,2.0) + pow(a,2.0) == pow(b,2.0)){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1044
#include <iostream>
#include <set>
#include <string>
#include <queue>
using namespace std;

int h;
int w;

int dist[100][100];

int fie[100][100];

int whi;

int main()
{
	cin >> h >> w;

	for(int i = 0;i < h;i++)
	{
		string s;
		cin >> s;
		for(int j = 0;j < w;j++)
		{
			if(s[j] == '#')
			{
				fie[i][j] = 1;
			}
			else
			{
				whi++;
			}
		}
	}

	typedef pair<int,int> P;
	typedef pair<int,P> P2;

	queue<P2> que;

	que.push(P2(1,P(0,0)));

	for(int i = 0;i < 100;i++)
	{
		for(int j = 0;j < 100;j++)
		{
			dist[i][j] = 1000000;
		}
	}

	dist[0][0] = 1;

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

	while(!que.empty())
	{
		P2 p = que.front();

		que.pop();

		int x = p.second.first;
		int y = p.second.second;
		int d= p.first;

		if(dist[x][y] < d) continue;

		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 && dist[nx][ny] > d + 1 && fie[nx][ny] == 0)
			{
				dist[nx][ny] = d + 1;
				que.push(P2(d + 1,P(nx,ny)));
			}
		}
	}

	if(dist[h - 1][w - 1] == 1000000)
	{
		cout << -1 << endl;
		return 0;
	}



	cout << whi - dist[h - 1][w - 1] << endl;
	return 0;
}



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

using namespace std;

int main() {
  int l, a,b,c,d,i,j;
  i = j = 0;
  cin >> l >> a >> b >> c >> d;
  while(a>0){
    a-=c;i++;
  }
  while(b>0){
    b-=d;j++;
  }
  
  cout <<  l -  max(i, j)  << endl;

  return 0;
}

Measured memory_bytes: 1160
import numpy as np
a,b,h,m = map(int,input().split())

alpha = 2*np.pi*(h+m/60)/12
beta = 2*np.pi*m/60

sa = np.abs(alpha-beta)
if sa >= np.pi:
    sa = 2*np.pi - sa
theta = sa
print(np.sqrt(a**2+b**2-2*a*b*np.cos(theta)))


Measured memory_bytes: 27220
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 1e6 + 5, inf = 1e9;
const ll INF = 1e18;
const ld PI = 3.1415926535897932384626433832795;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

    //////////////////////////////////////////
    //////////////////////////////////////////

    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;

    int res = 0;
    for (int i = 0; i < n; i++) {
        int x = (b[i] != a[i]) + (c[i] != a[i]);
        int y = (a[i] != b[i]) + (c[i] != b[i]);
        int z = (a[i] != c[i]) + (b[i] != c[i]);
        //cout << x << " " << y << " " << z << "\n";
        res += min({x, y, z});
    }

    cout << res << "\n";
}


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

int main(){
	
	string n;
	cin >>n;
	
	for(int i=0; i<3; i++){
		
		if(n.at(i)=='1'){
			
			n.at(i)='9';
			
		}
		else if(n.at(i)=='9'){
			
			n.at(i)='1';
			
		}
		
	}
	
	cout <<n <<endl;
	
}



Measured memory_bytes: 256
/*
	@author: cheerioskun
*/
#pragma GCC target("popcnt")
#include "bits/stdc++.h"
#define f first
#define sc second
#define pb push_back
#define MOD 1000000007L
#define inf 0x3f3f3f3f
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
using namespace std;

int h[100005], dp[100005];

int main(){
	fast_io
	int N;
	cin>>N;
	for(int i = 0;i < N; ++i){
		dp[i] = inf;
		cin>>h[i];
	}
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for(int i = 2;i < N; ++i){
		dp[i] = min(dp[i], min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i])));
	}
	cout<<dp[N - 1]<<endl;
	
	
	
	#ifndef ONLINE_JUDGE
    	cout<<"Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


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



int main(void)
{
	int N;
	int K;
	double sum=0;
	double peropero=0;
	scanf("%d %d",&N,&K);
	int a[N];
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	
	for(int i=0;i<K;i++){
		sum=sum+a[i];
	}
	peropero=sum;
	for(int i=0;i<N-K;i++){
		sum=sum-a[i]+a[i+K];
		if(sum>peropero){
			peropero=sum;
		}
	}
	peropero=peropero/2+0.5*K;
	printf("%lf",peropero);
}
	

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;

int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i, N) cin >> A[i];
  ll ans = 0;
  int prev = 0;
  rep(i, N) {
    prev = max(prev, A[i]);
    ans += prev - A[i];
  }

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


Measured memory_bytes: 3976
N=int(input())
P=input()
P=P.rstrip().split()
P.append('0')

ans=0
l=0
for i in range(N+1):
    
    if l>N-1:
            break
    elif P[l]==str(l+1):
        ans+=1
        l+=2
    else:
        l+=1
        
print(ans)

Measured memory_bytes: 10420
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static boolean solve() {
		int n = in.nextInt();
		if (n == 0) return false;

		int w = in.nextInt(), h = in.nextInt();

		int[][] field = new int[w+2][h+2];
		for (int i=0; i<n; i++) {
			field[in.nextInt()][in.nextInt()]++;
		}

		for (int i=1; i<=w; i++) {
			for (int j=1; j<=h; j++) {
				field[i+1][j] += field[i][j];
				field[i][j+1] += field[i][j];
				field[i+1][j+1] -= field[i][j];
			}
		}

		int s = in.nextInt(), t = in.nextInt();
		int max = 0;
		for (int i=s; i<=w; i++) {
			for (int j=t; j<=h; j++) {
				max = Math.max(max, field[i][j] - field[i-s][j] - field[i][j-t] + field[i-s][j-t]);
			}
		}

		out.println(max);

		return true;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(solve());
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 40568
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    a, b = sc.intarr()

    ans = (a-1) * (b-1)

    print(ans)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int a,b; cin>>a>>b;
    if(a<=b){
        REP(i,b) cout << a;
    }
    else{
        REP(i,a) cout << b;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
 int w,a,b;
 cin>>w>>a>>b;
 if(b>=(a+w))
 {
    cout<<(b-(a+w));
 }
 else if(b+w<=a)
    cout<<a-(b+w);
else
    cout<<0;

    return 0;
}








Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
using vi=vector<int>;
#define PB push_back
#define ALL(x) x.begin(),x.end()
	
const int Nmax=415514;
const int inf=1145141919;
char tree[Nmax],buf[Nmax];
int sub[Nmax],idx;
int dfs1(char*&p){
	if(*++p==')')return 0;
	int v=idx++,res=1;
	REP(_,2){
		res+=dfs1(p);
		p++;
	}
	return sub[v]=res;
}
bool check(int&i,char c){
	if(buf[i]=='?')buf[i]=c;
	else if(buf[i]!=c)return false;
	i++;
	return true;
}
bool dfs2(char*&p,int w,int*i){
	if(*++p==')')return true;
	int v=idx++,tmp=0;
	if(sub[v]%w==0)i=&tmp;
	REP(_,2){
		if(!check(*i,*p))return false;
		if(!dfs2(p,w,i))return false;
		if(!check(*i,*p))return false;
		p++;
	}
	return true;
}

int main(){
	scanf("%s",tree);
	char* beg=tree;
	dfs1(beg);
	int n=sub[0];
	vi canUse;
	FOR(i,1,n+1)if(n%i==0){
		beg=tree;
		REP(j,4*i)buf[j]='?';
		idx=0;
		if(dfs2(beg,i,0))
			canUse.PB(i);
	}
	vi dp(canUse.size(),inf);
	dp[0]=0;
	REP(i,dp.size())FOR(j,i+1,dp.size())if(canUse[j]%canUse[i]==0)
		dp[j]=min(dp[j],dp[i]+canUse[j]/canUse[i]-1);
	cout<<dp.back()<<endl;
}

Measured memory_bytes: 10624
#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

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn, dt;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int H = getint(), W = getint(), D = getint();
	pair<int, int> A[90001];
	A[0] = mp(0, 0);
	rep(i, H) rep(j, W) {
		A[getint()] = mp(i, j);
	}
	vector<int> V[90000];
	int B[90001];
	rep(i, D) {
		int j = i;
		auto a = mp(0, 0);
		int mae = 0;
		while (j <= H * W) {
			B[j] = (mae += (abs(A[j].first - a.first) + abs(A[j].second - a.second)));
			a = A[j];
			j += D;
		}
	}
	int Q = getint();
	rep(i, Q) {
		int l = getint(), r = getint();
		putint(B[r] - B[l]);
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 5248
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())
    S = input()

    counts = []
    if S[0] == '0':
        counts.append(0)
    cnt = 1
    for i in range(1, N):
        if S[i - 1] == S[i]:
            cnt += 1
        else:
            counts.append(cnt)
            cnt = 1
    counts.append(cnt)
    if S[0] == '0':
        counts.append(0)

    cumsum = [0 for _ in range(len(counts) + 1)]
    for i in range(0, len(counts)):
        cumsum[i + 1] = cumsum[i] + counts[i]

    res = 0
    for left in range(0, len(cumsum), 2):
        right = left + 2 * K + 1
        if right >= len(cumsum):
            right = len(cumsum) - 1
        res = max(res, cumsum[right] - cumsum[left])

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47392
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        String s = scan.next();

        if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        scan.close();
        return;
    }
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    int amt = 0;
    while (amt < n)
        amt += 1000;

    cout << amt - n << "\n";

    return 0;
}


Measured memory_bytes: 3648
import collections
n = int(input())
s_list = [input() for _ in range(n)]
m = int(input())
t_list = [input() for _ in range(m)]

cs = dict(collections.Counter(s_list))
ct = dict(collections.Counter(t_list))

count_list = []
for k,v in cs.items():
    if k in ct:
        if ct[k] < v:
            count_list.append(v-ct[k])
    else:
        count_list.append(v)

print(max(count_list) if len(count_list)!= 0 else 0)

Measured memory_bytes: 3316
#include<cstdio>
#include<queue>
#include<iostream>
#include<algorithm>
#include<list>
#include<vector>
using namespace std;
list<int>mylist;
list<int>::iterator i = mylist.end();
int main() {
	int t,b,c;
	cin >> t;
	while (t--)
	{
		int choose;
		cin >> choose;
		switch (choose)
		{
		case 0:
			cin >> b;
			i=mylist.insert(i,b);
			break;
		case 1:
			cin >> b;
			if (b > 0)
			{
				for (int k = 0; k < b; k++)
				{
					i++;
				}
			}
			if (b < 0)
			{
				for (int k = 0; k < -b; k++)
				{
					i--;
				}
			}
			break;
		case 2:
			i=mylist.erase(i);
		}
	}
	for (i = mylist.begin(); i != mylist.end(); i++)
	{
		cout << *i << endl;
	}
}




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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

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

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

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


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


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

    int ans = 0;
    REP(i,s.size()) if(s[i]=='1') ans++;

    pl(ans)

    return 0;
}

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

const int MAX_N = 4e5;
int A[MAX_N],B[MAX_N],a[MAX_N],b[MAX_N];

signed main(void){
  
  int N; cin >> N;
  for(int i = 0; i < N; i++){ cin >> A[i];}
  for(int i = 0; i < N; i++){ cin >> B[i];}
  
  int ans = 0;
  
  for(int bit = 0; bit < 40; bit++){ 
    
   int T = (1LL << (bit) );
    int mask = 2*T-1;
    
    for(int i = 0; i < N; i++){ 
      a[i] = (A[i] & mask);
      b[i] = (B[i] & mask);
      
    }
    
    
    sort(a,a+N);
    sort(b,b+N);
    
    int res = 0;
    
    for(int i = 0; i < N; i++){
      auto it1 = lower_bound(b,b+N,T-a[i]);
      auto it2 = lower_bound(b,b+N,2*T-a[i]);
      
      auto it3 = lower_bound(b,b+N,3*T-a[i]);
      auto it4 = lower_bound(b,b+N,4*T-a[i]);
      
      res += distance(it1,it2);
      res += distance(it3,it4);
      
      
    }
  
    res %= 2;
    
    ans += res*T;
    
  }
  
  cout << ans << endl;
  
  return 0;
  
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/05/19  Problem: ABC 126 D / Link: http://abc126.contest.atcoder.jp/tasks/abc126_d  ----- */


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

	LL N;
	cin >> N;
	vector<vector<PLL>> G(N);
	FOR(i, 0, N-1) {
		int a, b; cin >> a >> b;
		LL w; cin >> w;
		a--, b--;
		G[a].push_back(PLL(b, w));
		G[b].push_back(PLL(a, w));
	}
	VI color(N, 0);
	function<void(int, int, LL)>f = [&](int v, int p, LL ws) {

		for (auto it : G[v]) {
			int nx = it.first;
			LL w = it.second;
			if (p == nx)continue;
			if (w % 2 == 1) {
				color[nx] = !color[v];
			}
			else {
				color[nx] = color[v];
			}
			f(nx, v, ws);
		}
	};
	color[0] = 0;
	f(0, -1, 0);
	FOR(i, 0, N) {
		cout << color[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int q,s,a,b;
int main(){
    cin>>q;
    ll med=0;
    ll sum=0,sl=0,sr=0;
    priority_queue<ll,vector<ll>,greater<ll> > qr;
    priority_queue<ll> ql;
    rep(i,q){
        cin>>s;
        if(s==1){
            cin>>a>>b;
            sum+=b;
            if(i==0) med=a;
            else if(a<med){
                ql.push(a);sl+=a;
            }
            else{
                qr.push(a);sr+=a;
            }
            int d=(int)qr.size()-(int)ql.size();
            if(d>=2){
                ql.push(med);sl+=med;
                med=qr.top();qr.pop();sr-=med;
            }
            else if(d==-1){
                qr.push(med);sr+=med;
                med=ql.top();ql.pop();sl-=med;
            }
        }
        else{
            cout<<med<<" "<<sum+(med*(int)ql.size()-sl)+(sr-med*(int)qr.size())<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define finc(i, a, b) for (int i = a, _b = (b); i <= _b; i++)
#define fdec(i, a, b) for (int i = a, _b = (b); i >= _b; i--)
#define ii pair <int, int>
#define x first
#define y second
#define db(x) cerr << #x << " = " << x << endl;

using namespace std;

inline void read(int &x){register int c = getchar();x = 0; int neg = 0;for (;((c<48 || c>57) && c != '-') ;c = getchar());if(c=='-') {neg=1;c=getchar();}for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}
inline void read(long long &x){register int c = getchar();x = 0; int neg = 0;for (;((c<48 || c>57) && c != '-') ;c = getchar());if(c=='-') {neg=1;c=getchar();}for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}
inline void writeln(long long x){char buffor[21];register int i=0;int neg=0; if (x<0) {neg=1; x= -x;}do{buffor[i++]=(x%10)+'0';x/=10;} while(x);i--;if (neg) putchar('-');while(i>=0) putchar(buffor[i--]);putchar('\n');}
inline void write(long long x){char buffor[21];register int i=0;int neg=0; if (x<0) {neg=1; x= -x;}do{buffor[i++]=(x%10)+'0';x/=10;} while(x);i--;if (neg) putchar('-');while(i>=0) putchar(buffor[i--]);putchar(' ');}

int n, k;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> k;
	if (k & 1){
		cout << 1LL * (n / k) * (n / k) * (n / k);
	}
	else{
		if (n - k / 2 < 0){
			cout << 0;
			return 0;
		}
		int rem = (n - k / 2) / k + 1;
		cout << 1LL * rem * rem * rem + 1LL * (n / k) * (n / k) * (n / k) ;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
typedef long long i64;
int main(){
    string s;
    cin >> s;
    long long int k;
    cin >> k;
    if(s[0]=='1'){
        int one=0;
        for(int i=0;i<s.size();i++){
            if(s[i]=='1')one++;
            else break;
        }
        if(k<=one) cout << 1 << endl;
        else cout << s[one] << endl;
    }else{
        cout << s[0] << endl;
    }
}


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

int main(){
    string S,T;
    cin >> S >> T;

    int N = S.length();
    bool canRegister = true;
    for(int i=0;i<N;i++){
        if(S[i] != T[i]){
            canRegister = false;
        }
    }
    if(canRegister){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
n = int(input())
h = list(map(int,input().split()))

dp = [float("inf")] * (n)
dp[0] = 0
for i in range(1,n):
    if i == 1:
        dp[i] = abs(h[i - 1]- h[i])
    else:
        dp[i] = min(abs(h[i]-h[i-2]) + dp[i-2], abs(h[i]-h[i-1]) + dp[i-1])
print(dp[-1])

Measured memory_bytes: 13908
a, b = map(int, input().split())
A = min(a,b)
B = max(a,b)

def main():
    if A==B:
        print(K)
        return
    elif (A+B)%2 == 0:
        print((A+B)//2)
        return
    else:
        print('IMPOSSIBLE')
        return

main()

Measured memory_bytes: 38384
#include<iostream>
 
using namespace std;
 
int main(void){
  int lot[31];
  for(int i=1;i<=30;i++){
    lot[i]=i;
  }
  int w,n;
  cin>>w>>n;
  for(int i=0;i<n;i++){
    int a,b;
    (cin>>a).ignore()>>b;
    swap(lot[a],lot[b]);
  }
  for(int i=1;i<=w;i++){
    cout<<lot[i]<<endl;
  }
  return 0;
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){
    lli n;
    cin>>n;
    map<string,lli>ans;
    for(lli i=0;i<n;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        ans[s]++;
    }
    lli sum=0;
    for(auto e:ans){
        lli tmp=e.second*(e.second-1)/2;
        sum+=tmp;
    }
    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 11136
while true
  dataset_num = gets.chomp
  break if dataset_num == '0'     #終端に達したらbreak
  dataset = Hash.new(0)
  dataset_num.to_i.times do 
    stdin = gets.chomp
    stdin = stdin.split(' ')
    dataset[stdin[0].to_sym] += stdin[1].to_i * stdin[2].to_i
  end
  flag = true
  dataset.each do |key, value|
    if value >= 1_000_000 
      puts key
      flag = false
    end
  end
  puts 'NA' if flag
end

Measured memory_bytes: 6112
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
long int m,k,n,tmp;
 
scanf("%ld%ld",&n,&k);
 
tmp=n%k;
m=labs(k-tmp);
if(m<tmp){tmp=m;}
 
printf("%ld\n",tmp);
 
return 0;
}

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

int N;

int main()
{
    while (scanf("%d", &N))
    {
        if (N == 0)
            return 0;
        int ans = 0;
        for (int i = 1; 2 * i < N; i++)
        {
            int l = 0, sum = 0, r = i;
            while (sum < N)
                sum += r, l++, r++;
            if (sum == N && l > 1)
                ans++;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define N 200005
int n;
ll h[N],ara[N];
ll tree[N * 4];

ll query(int node, int b, int e, int i, int j)
{
    if (i > e || j < b)
        return 0;
    if (b >= i && e <= j)
        return tree[node];
    int Left = node * 2;
    int Right = node * 2 + 1;
    int mid = (b + e) / 2;
    ll p1 = query(Left, b, mid, i, j);
    ll p2 = query(Right, mid + 1, e, i, j);
    return max(p1 , p2);
}
void update(int node, int b, int e, int i, ll newvalue)
{
    if (i > e || i < b)
        return;
    if (b >= i && e <= i) {
        tree[node] = newvalue;
        return;
    }
    int Left = node * 2;
    int Right = node * 2 + 1;
    int mid = (b + e) / 2;
    update(Left, b, mid, i, newvalue);
    update(Right, mid + 1, e, i, newvalue);
    tree[node] = max(tree[Left] , tree[Right]);
}
int main()
{
    fastio;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>h[i];
    for(int i=1;i<=n;i++) cin>>ara[i];
    for(int i=n;i>=1;i--)
    {
        ll mx=query(1,1,n,h[i],n);
        update(1,1,n,h[i],ara[i]+mx);
    }
    cout<< query(1,1,n,1,n) <<endl;

}


Measured memory_bytes: 10832
#include<cstdio>
#include<algorithm>
using namespace std;
int K, n, w[510][510];
int main() {
	int i, j;
	scanf("%d", &K);
	if (K == 1) {
		printf("1\n1\n");
		return 0;
	}
	n = (K+3) / 4*2;
	printf("%d\n", n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			w[i][j] = (i + j) % n;
			if (i % 2 == 1 && w[i][j] + n < K)w[i][j] += n;
			printf("%d ", w[i][j] + 1);
		}
		puts("");
	}
}

Measured memory_bytes: 2048
using System;
 
class Program
{
    static void Main(string[] args)
    {
        int i, j;
 
        string[] strInput = Console.ReadLine().Split(' ');
        int l = int.Parse(strInput[0]);
        int r = int.Parse(strInput[1]);
        int d = int.Parse(strInput[2]);
 
        int result = 0;
 
        for(i = l; i <= r; i++)
        {
            if(i % d == 0)
            {
                result++;
            }
        }
 
        Console.WriteLine(result);
 
        return;
    }
}

Measured memory_bytes: 27504
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

void c() {
	int n;
	cin >> n;
	vector<pair<int, int> > a;
	for (int i = 1; i <= n; i++) {
		int t;
		cin >> t;
		a.push_back(pair<int, int>(t, i));
	}

	sort(a.begin(), a.end());
	cout << a[0].second;
	for (int i = 1; i < n; i++) {
		cout << " " << a[i].second;
	}
	cout << endl;
}

int main()
{
	c();
}


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

#define int long long
#define MAX_N (300005)
#define INF (1LL<<60)
#define EPS (1e-7)
#define DEBUG(x) cerr << #x <<":"<< x << endl;
#define DEBUGVC(x) cerr << #x <<": "; for(auto p:(x)) cerr << p <<" "; cerr << endl;
#define DEBUGVCP(x) for(auto p:(x)) cerr << #x <<": "<< p.first <<", "<< p.second << endl;
#define DEBUG2(x, y) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y << endl;
#define DEBUG3(x, y, z) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y <<", "<< #z <<" : "<< z << endl;
const int MOD = (int)1e9+7;

signed main() {
    int N;
    cin >> N;
    vector<int> V(N), C(N), d(N);
    for(int i=0; i<N; i++) cin >> V[i];
    for(int i=0; i<N; i++) cin >> C[i];

    for(int i=0; i<N; i++){
        d[i] = V[i] - C[i];
    }
    sort(d.rbegin(), d.rend());

    int ans=0;
    for(int i=0; i<N; i++){
        if(d[i]>0){
            ans += d[i];
        } else {
            break;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 55;

ll dp[N][N * N][2];

int n,x,a[N];

ll f(int cur,int sum) {
  ll &res = dp[cur][abs(sum)][sum > 0];
  if (res != -1)
    return res;
  if (cur == n + 1)
    return res = (sum == 0);
  return res = f(cur + 1,sum) + f(cur + 1,sum + a[cur]);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> x;
  for (int i = 1 ; i <= n ; i++) {
    cin >> a[i];
    a[i] -= x;
  }
  memset(dp,-1,sizeof dp);
  cout << f(1,0) - 1 << endl;
}

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

using namespace std;
const int N = 105;
int a[N];
int b[N];
int main() {
    int n;
    cin >> n;
    for(int i = 1; i < n; i++) cin >> b[i];
    a[1] = a[2] = b[1];
    for(int i = 2; i < n; i++) {
        if(b[i] < a[i]) {
            a[i] = b[i];
        }
        a[i + 1] = max(b[i], a[i + 1]);
    }
    int sum = 0;
    for(int i = 1; i <= n; i++) sum += a[i];
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a[100], p;
  char s[199];
  while(scanf("%s", s) != EOF){
    if(s[0] == '+'){
      a[p-1] = a[p-1] + a[p];
      p--;
    }else if(s[0] == '-'){
      a[p-1] = a[p-1] - a[p];
      p--;
    }else if(s[0] == '*'){
      a[p-1] = a[p-1] * a[p];
      p--;
    }else{
      p++;
      a[p] = atoi(s);
    }
  }
  printf("%d\n", a[p]);
  return 0;
}

Measured memory_bytes: 1764