akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
typedef unsigned long long ll;
using namespace std;
# include <algorithm>

int main() {
    ll n, k;
    cin >> n >> k;
    if (k == 1) {cout << 0 << "\n";}
    else {
        ll minVal = min(n % k, k - n%k);
        cout << minVal << "\n";
    }
    return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = int.Parse(Console.ReadLine());
        decimal[] a = Console.ReadLine().Split().Select(decimal.Parse).ToArray();

        Array.Sort(a);

        decimal ans = 1;
        for (int i = 0; i < n; i++)
        {
            try
            {
                checked
                {
                    ans *= a[i];
                }
            }
            catch (OverflowException ex)
            {
                Console.WriteLine(-1);
                return;
            }

            if (ans > 1000000000000000000)
            {
                ans = -1;
                break;
            }
        }


        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 43212
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	char a[2][3];
	REP(i, 2)REP(j, 3) {
		cin >> a[i][j];
	}
	bool ans = true;
	REP(i, 3) {
		if (a[0][i] != a[1][2 - i])ans = false;
	}
	cout << (ans ? "YES" : "NO") << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
const int MOD = 1000000007;

int main(){
    int n; cin >> n;
    vector<int> ar(n+1);
    int r = n;
    int cnt;
    rep(i,n+1) ar[i] = i;
    repp(i,n+1,1){
        ar[i] += ar[i-1];
        if (ar[i] >= n){
            cout << i << endl;
            r -= i;
            cnt = i;
            break;
        }
    }
    while (r > 0){
        cnt--;
        if (cnt <= r){
            r -= cnt;
            cout << cnt << endl;
        }
    }
}

Measured memory_bytes: 39296
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)

void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
char meiro[51][51];
int H,W;
using namespace std;
typedef pair<int,int> vect;
typedef pair<vect,int> seta;
int visited[51][51];
int bfs(){
  queue<seta> que;
  que.push(make_pair(make_pair(0,0),1));
  while(!que.empty()){
    seta tmp;
    vect t;
    int x,y,count;
    tmp = que.front();
    t = tmp.first;
    que.pop();
    x = t.first;
    y = t.second;
    count = tmp.second;
    if(x < 0 || x >=W || y < 0 || y >= H)
      continue;
    else if(meiro[y][x] == '#' || visited[x][y] == 1)
      continue;
    if((x == W-1) && (y==H-1))
      return count;
    visited[x][y] = 1;
    REP(i,4){
      que.push(make_pair(make_pair(x+dx[i],y+dy[i]),count+1));
    }
    
  }
  return 0;

}

int main()
{
  int point = 0;
  REP(i,51)REP(j,51)visited[i][j] = 0;
  cin >> H >> W;
  REP(i,H)
    cin >> meiro[i];
  if((point = bfs()) == 0){
    cout << -1 << endl;
    return 0;
  }
  point = -point;
  REP(i,H)REP(j,W){
    if(meiro[i][j] == '.')
      point++;
  }
  cout << point << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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



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

long long n, k, s;
long long ans = 0;

void dfs (long long cnt, long long min, long long left, vector<long long> st){
	//cout<<"cnt: "<<cnt<<", st.size(): "<<st.size()<<endl;
	
	if (cnt > k || left < 0) {
		return;
	}
	if (left == 0 && cnt == k) {
		/*
	    for(auto itr = st.begin(); itr != st.end();) {
	        cout<<(*itr)<<", ";
	        itr++;
	    }
	    cout<<endl;
	    */
		
		ans++;
		return;
	}
	for(long long i=min; i<=n; i++){
		st.push_back(i);
		dfs(cnt+1, i+1, left-i, st);
		st.pop_back();
	}
	
	return;
}

int main() {
	while(1){
		cin>>n>>k>>s;
		if (n==0 && k==0 && s==0) break;
		ans = 0;
		
		vector<long long> st;
		dfs(0, 1, s, st);
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3020
#include<bits/stdc++.h>
typedef long long     ll;
#define fast          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr            first
#define sc            second
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
using namespace std;
int main()
{
    int a[5];
    com(i,5)
    {
        cin>>a[i];
    }
    com(i,5)
    {
        if(a[i]==0)
        {
            cout << i+1 << endl;
            break;
        }
    }
}


Measured memory_bytes: 3624
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)


#define huge 1000000007
typedef long long ll;

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll K = 0;
	ll M = 0;
	ll X = 0;
	//double a[100000] = {};
	//double b[100000] = {};
	//ll v[100] = {};
	ll *l, *r, *d;
	string S,T,U;
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;

	
	//char p;
	//cin >>N >> M;
	cin >> N;
	//vector<pair<float, float>> is(M);
	//sort(is.begin(), is.end());
	//l = (ll *)malloc(N * sizeof(ll));
	//r = (ll *)malloc(N * sizeof(ll));

	/*rep(i, 0, N) {
		cin >> l[i];
	}*/
	
	//sort(l,l+N);

	if (N < 1200) {
		cout << "ABC"<< endl;
	}
	else if(N<2800){
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}

	
	
	

	//cout << sum << endl;
	
		

	return 0;

}



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

typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> P(N), C(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> C[i];
    ll ans = -1e18;
    rep(i, N) {
        int j = P[i] - 1, t = 1;
        ll s = C[j];
        while (j != i) {
            t++;
            j = P[j] - 1;
            s += C[j];
        }
        //cout << i << " " << s << " " << t << "\n";
        if (s > 0) {
            int q = max(0, K / t - 2);
            ll a0 = s * q;
            ans = max(ans, a0);
            j = i;
            rep(k, K - q * t) {
                j = P[j] - 1;
                a0 += C[j];
                ans = max(ans, a0);
            }
        } else {
            ans = max(ans, C[P[i] - 1]);
            ll a0 = 0;
            rep(k, t) {
                j = P[j] - 1;
                a0 += C[j];
                ans = max(ans, a0);
            }
        }
    }
    cout << ans << "\n";
}

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

int main(void)
{
	int *train;
	int train_no;
	int no;
	int i;
	
	no = 0;
	train = (int *)malloc(sizeof(int));
	while (scanf("%d", &train_no) != EOF){
		if (train_no != 0){
			no++;
		}
		else {
			no--;
			printf("%d\n", train[no]);
		}
		train = (int *)realloc(train, no * sizeof(int));
		if (train_no != 0){
			train[no - 1] = train_no;
		}
	}
	free(train);
	
	return (0);
}

Measured memory_bytes: 600
a = int(input())
b = input() 
def caesar(s, n):
    ns = []
    for ch in s:
        if ('A' <= ch and ch <= 'Z'):
            ns.append(chr((ord(ch) - ord('A') - n) % 26 + ord('A')))
        else:
            ns.append(ch)
    return "".join(ns)

result = caesar(b,-a)
print(result)

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

int main()
{
	int n;

	cin >> n;
	
	while (n > 0) {
		int s[1000], p[1000], q[1000], r[1000];
		int pt, qt, rt, ct;
		bool f = 0;

		for (int i = 0; i < n; i++)
			cin >> s[i] >> p[i] >> q[i] >> r[i];
		cin >> pt >> qt >> rt >> ct;

		for (int i = 0; i < n; i++) {
			int c = (p[i] + r[i]) * 4 + q[i] * 9;
			if (p[i] <= pt && q[i] <= qt && r[i] <= rt && c <= ct) {
				cout << s[i] << endl;
				f = 1;
			}
		}

		if (!f)
			cout << "NA" << endl;

		cin >> n;
	}

	return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m;
vvi a;

int main(){
	cin>>n>>m;
	a=vvi(n,vi(m));
	for(int i=0;i<n;i++) for(int j=0;j<m;j++){
		cin>>a[i][j];
		a[i][j]--;
	}
	vi used(m,1);
	int res=inf;
	for(int i=0;i<m;i++){
		vi b(m);
		for(int j=0;j<n;j++){
			for(int k=0;k<m;k++) if(used[a[j][k]]){
				b[a[j][k]]++;
				break;
			}
		}
		int I,M=0;
		for(int j=0;j<m;j++) if(M<b[j]){
			M=b[j];
			I=j;
		}
		res=min(res,M);
		used[I]--;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main () {
  vector<int> n(3);
  int K;
  cin >> n.at(0) >> n.at(1) >> n.at(2) >> K;
  sort(n.begin(), n.end());
  cout << n.at(0) + n.at(1) + n.at(2) * pow(2, K);
}

/*
3つの数字の大小関係を，
\begin{equation}
\label{abc}
A \leq B \leq C
\end{equation}
と仮定しても一般性を失わない。

$n$回の操作を終えた後の3つの数字の合計としてありうる最大の値を$s_n$とおくと，$s_n$は，
\begin{equation}
S = \{\ 2^a A + 2^b B + 2^c C \ |\ a,b,c \mbox{は非負整数}, a + b + c = n\ \}
\end{equation}
によって定まる集合$S$の要素のうち最大のものであり，並び替え不等式より，
\begin{equation}
s_n = A + B + 2^n C
\end{equation}
である。
*/


Measured memory_bytes: 256
# include<iostream>
# include<vector>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll N = 13;
const ll MOD = 1000000007;
ll dp[100010][13];
int main() {
    ll a;
    scanf("%lld", &a);
    ll ans = 3*a*a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


class Solve{
	static int INF = 10000;
	
	 public void solve() {
		 Scanner sc = new Scanner(System.in) ;
		 int S = sc.nextInt();
		 int f=S/100;
		 int b = S%10+((S/10)%10)*10;
		 
		 if(b>0 &&b<=12) {
			 
			 if(f==0||f>12) {
				 System.out.println("YYMM");
				 
			 }else {
				 System.out.println("AMBIGUOUS");
			 }
		 }else if(f>=1&&f<=12) {
			 if(b==0||b>12) {
				 System.out.println("MMYY");
			 }else {
				 System.out.println("AMBIGUOUS");
			 }
		 }else {
			 System.out.println("NA");
		 }
		 
		 

;
	}
}





public class Main {

	public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();

	}
}

Measured memory_bytes: 21716
#define _USE_MATH_DEFINES
#include<iostream>
#include<math.h>
#include<cmath>
#include <iomanip>
#include<vector>
int main(void) {
	while (1) {
		int n;
		std::cin >> n;
		if (n == 0) { 
			std::cout <<  std::endl;
			break; }
		std::vector<int>s(n,0);
		for (int i = 0; i < n; ++i) {
			std::cin >> s[i];
		}
				double MEAN = 0.;
		for (int i = 0; i< n; ++i) {
			MEAN += s[i];
		}
		MEAN =MEAN/static_cast<double>(n);

		double		standard_deviation = 0.;
		for (int i = 0; i< n; ++i) {
			standard_deviation += (s[i]-MEAN)*(s[i] - MEAN);
		}
		standard_deviation=std::sqrt(standard_deviation / static_cast<double>(n));
		std::cout << std::fixed << std::setprecision(8) << standard_deviation<<std::endl;
}
	//	system("pause");
	return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
typedef long long ll;
 
int main() {
  string s;cin>>s;
  bool ans=false;
  if (s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[3]) ans=true;
  if (s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]) ans=true;
  if (s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1]) ans=true;
  cout<<(ans ? "Yes":"No");
  return 0;
}

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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


int main() {
  ios:: sync_with_stdio(false);
  cin.tie();
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (a[i] > x) {
      ans += a[i] - x;
    }
  }
  cout << ans;
  return 0;
}




Measured memory_bytes: 3620
import string
N = int(input())
S = list(input())
alp = list(string.ascii_uppercase)
lst = []

for i in S:
    tmp = alp.index(i)+N
    if tmp > 25:
        lst.append(tmp - 26)
    else:
        lst.append(tmp)

a = [ alp[i] for i in lst]
print(''.join(a))



Measured memory_bytes: 3832
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
typedef long long ll;

int N;
double x[50], y[50];

double eps = 1e-9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i];
    }
    double ans = 1000000;
    for(int i = 0;i < N; i++){
        for(int j = 0; j < i; j++){
            double mx = (x[i]+x[j])/2;
            double my = (y[i]+y[j])/2;
            double r = sqrt((x[i]-mx)*(x[i]-mx)+(y[i]-my)*(y[i]-my));
            for(int k = 0; k < N; k++){
                double l = sqrt((x[k]-mx)*(x[k]-mx)+(y[k]-my)*(y[k]-my));
                if(l > r+eps) break;
                if(k == N-1) ans = min(ans, r);
            }
        }
    }
    // cout << ans << endl;
    // ans = 1000;
    for(int i = 0;i < N; i++){
        for(int j = 0; j < i; j++){
            for(int k = 0; k < j; k++){
                // cout << i << ' ' << j << ' ' << k << endl;
                // cout << ((x[k]-x[i])*(y[i]-y[j])-(x[j]-x[i])*(y[i]-y[k])) << endl;
                if(abs((x[k]-x[i])*(y[i]-y[j])-(x[j]-x[i])*(y[i]-y[k])) < 0.5) continue;
                // cout << 'H' << endl;
                double my = ((x[k]-x[i])*(x[i]*x[i]+y[i]*y[i]-x[j]*x[j]-y[j]*y[j])-(x[j]-x[i])*(x[i]*x[i]+y[i]*y[i]-x[k]*x[k]-y[k]*y[k]))/(2*(x[k]-x[i])*(y[i]-y[j])-2*(x[j]-x[i])*(y[i]-y[k]));
                double mx;
                if(abs(x[j]-x[i])<0.5){
                    mx = (2*(y[i]-y[k])*my-(x[i]*x[i]+y[i]*y[i]-x[k]*x[k]-y[k]*y[k]))/(2*(x[k]-x[i]));
                }else{
                    mx = (2*(y[i]-y[j])*my-(x[i]*x[i]+y[i]*y[i]-x[j]*x[j]-y[j]*y[j]))/(2*(x[j]-x[i]));
                }
                // cout << mx << ' ' << my << endl;
                double r = sqrt((x[i]-mx)*(x[i]-mx)+(y[i]-my)*(y[i]-my));
                // cout << r << endl;
                for(int l = 0; l < N; l++){
                    double t = sqrt((x[l]-mx)*(x[l]-mx)+(y[l]-my)*(y[l]-my));
                    // cout << t << endl;
                    if(t > r+eps) break;
                    if(l == N-1) ans = min(ans, r);
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char str[11];
	char num[10];
	int i, j;
	
	while (scanf("%s", str) != EOF){
		
		for (i = 0; i < 10; i++){
			num[i] = str[i] - '0';
		}
		
		j = 9;
		while (num[1] != 99){
			for (i = 0; i < j; i++){
				num[i] += num[i + 1];
				if (num[i] > 9){
					num[i] -= 10;
				}
			}
			num[j] = 99;
			j--;
		}
		
		printf("%d\n", num[0]);
	}
	return (0);
}

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

int main(){
  int n;
  cin>>n;
  vector<vector<int>>dp(n,vector<int>(3,0));
  vector<int>a(3);
  cin>>a[0]>>a[1]>>a[2];
  dp[0][0]=a[0];
  dp[0][1]=a[1];
  dp[0][2]=a[2];
  for(int i=1;i<n;i++){
    cin>>a[0]>>a[1]>>a[2];
    for(int j=0;j<3;j++){
      dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[j];
    }
  }
  int ans = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
  cout<<ans<<endl;
}


Measured memory_bytes: 5760
#include<stdio.h>
#include<string.h>
int main(){
	char s;
	int i,j,ans=0,x=0,f=1;
	while(scanf("%c",&s)!=EOF){
		if(s>='0' && s<='9'){
			x*=f;
			x+=s-'0';
			f=10;
		}else{
			if(f==10)ans+=x;
			x=0;f=1;
		}
	}
	if(f==10)ans+=x;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {

    int INF = Integer.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int[][] a = new int[H][W];
        int c = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        String[] S = new String[H * W];
        if (c % 2 == 0) {
            System.out.println();
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (j < W - 1 && a[i][j] % 2 == 1) {
                    a[i][j]--;
                    a[i][j + 1]++;
                    S[c] = ((i + 1) + " " + (j + 1) + " " + (i + 1) + " " + (j + 2));
                    c++;
                } else if (j == W - 1 && a[i][j] % 2 == 1 && i != H - 1) {
                    a[i][j]--;
                    a[i + 1][j]++;
                    S[c] = ((i + 1) + " " + (j + 1) + " " + (i + 2) + " " + (j + 1));
                    c++;
                }
            }
        }
        System.out.println(c);
        for (int i = 0; i < c; i++) {
            System.out.println(S[i]);
        }
    }

}

Measured memory_bytes: 104580
/* AtCoder Beginner Contest agc035
 * Problem B
 * Au: SJoshua
 */
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <stack>

using namespace std;

struct edge {
	int u, v;
	bool rev;
};

struct node {
	int v;
	edge &e;
};

int main(void) {
	int n, m;
	cin >> n >> m;
	vector <edge> edges(m);
	vector <vector <int>> graph(n + 1);
	for (int i = 0; i < m; i++) {
		cin >> edges[i].u >> edges[i].v;
		graph[edges[i].u].push_back(i);
		graph[edges[i].v].push_back(i);
	}

	if (m % 2) {
		cout << -1 << endl;
		return 0;
	}

	vector <bool> vis(n + 1);
	queue <int> q;
	stack <node> tree;

	q.push(1);
	vis[1] = true;

	while (!q.empty()) {
		auto u = q.front();
		q.pop();
		for (auto i: graph[u]) {
			auto &e = edges[i];
			int v = u ^ e.u ^ e.v;
			if (!vis[v]) {
				vis[v] = true;
				q.push(v);
				tree.push({v, e});
			}
		}
	}

	while (!tree.empty()) {
		auto u = tree.top();
		tree.pop();
		int cnt = 0;
		for (auto i: graph[u.v]) {
			auto &e = edges[i];
			cnt += e.rev ^ (e.u == u.v);
		}
		u.e.rev = cnt % 2;
	}

	for (auto e: edges) {
		if (e.rev) {
			cout << e.v << " " << e.u << endl;
		} else {
			cout << e.u << " " << e.v << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 9728
#include<stdio.h>
#define M 100 

struct gif{
  int k;
  int col;
  int r[M];
  int t[2];
};

typedef struct gif fig;
fig A[M];
int T=0;

void dan(int u){
  int x;
  A[u].col=1;
  A[u].t[0]=++T;
  //printf("%d",A[u].t[0]);
  for(x=0;x<A[u].k;x++)if(A[A[u].r[x]-1].col==0)dan(A[u].r[x]-1);
  A[u].t[1]=++T;
};

int main(){
  int a,b,i,j;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    A[i].col=0;
    scanf("%d%d",&b,&A[i].k);
    for(j=0;j<A[i].k;j++)scanf("%d",&A[i].r[j]);
    //A[i].r[j+1]=0;
  }
  for(i=0;i<a;i++)if(A[i].col==0)dan(i);
  for(i=0;i<a;i++)printf("%d %d %d\n",i+1,A[i].t[0],A[i].t[1]);
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define debug(...)
#include <complex.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
vvi g;
int n;

template<typename T>
class Queue {
    int head, tail, capacity;
    T* a;
    public:
    Queue(){
        head = 0 , tail = 0 , capacity = 1;
        a = new T[1];
    }
    T push(T data){
        if(tail == capacity){
            T * tmp = new T[capacity * 2];
            capacity *= 2;
            int id = 0;
            for(int i = head; i < tail; i++){
                tmp[id++] = a[i];
            }
            tail = tail - head;
            head = 0;
            delete[] a;
            a = tmp;
        }
        a[tail++] = data;
    }
    T front(){
        return a[head];
    }
    void pop(){
        head++;
    }
    int size(){
        return tail - head;
    }

};


map<pair<int, int>, int> BFS (int s) {
    vi clr (n + 1, -1);
    const int N = (int) 1e6;
    Queue<int>q;
    q.push (s);
    vi used (n + 1);
    used[s] = 1;
    map<pair<int,int>, int>hhh;
    while (q.size()) {
        int from = q.front();
        q.pop();
        int id = 1;
        for (int to : g[from])
            if (!used[to]) {
                if (id == clr[from])
                    id++;
                used[to] = 1;
                hhh[make_pair (from, to)] = clr[to] = id;
                id++;
                q.push (to);
            }
    }
    return hhh;
}
int32_t main() {
    ios::sync_with_stdio (false);
    cin.tie (0);
#ifdef LOCAL
    freopen ("f.txt", "r", stdin);
    // freopen("g.txt", "w", stdout);
#endif

    cin >> n;
    g =vvi (n + 1);
    size_t mx = 0;
    vector<pair<int, int>>edges;
    for (int i = 1; i < n; i++) {
        int from, to;
        cin >> from >> to;
        g[from].push_back (to);
        g[to].push_back (from);
        mx = max ({mx, g[from].size(), g[to].size() });
        if (from > to)
            swap (from, to);
        edges.emplace_back (from, to);
    }

    map<pair<int, int>, int> clr = BFS (1);
    cout << mx << '\n';
    for (pair<int, int> p : edges) {
        cout << clr[p] << '\n';
    }


    return 0;
}













Measured memory_bytes: 13944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=300;
int dp1[maxn];
int dp2[maxn];
int w[maxn];
int v[maxn];
struct node{
    int w;
    int v;
}p[maxn];
bool cmp(struct node a,struct node b){
    if(a.v==b.v) return a.w<b.w;
    return a.v<b.v;
}
int main()
{
    int a,b,n;
    while(cin>>n>>a>>b){
        n=n-a;
        n=n%b;
        cout<<n<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int p,n,r,c,i,j,k;
        int[] card = new int[51];
        int[] dummy = new int[51];
        Scanner s = new Scanner(System.in);
        while(true){
            n = s.nextInt();
            r = s.nextInt();
            if(n==0&&r==0)break;
            for(i=0;i<n;i++)card[i]=n-i;
            for(i=0;i<r;i++){
                p = s.nextInt();
                c = s.nextInt();
                for(j=0;j<p-1;j++)dummy[j]=card[j];
                for(j=0;j<c;j++)card[j]=card[j+p-1];
                for(j=0;j<p-1;j++)card[j+c]=dummy[j];
            }
            System.out.println(card[0]);
        }
    }
}


Measured memory_bytes: 38220
#include <stdio.h>
#define MAX(x, y) (((x) > (y)) ? (x) : (y))

int main()
{
	int h, w, n, m;
	scanf("%d%d%d", &h, &w, &n);
	m = MAX(h, w);
	printf("%d", n / m + (n / m * m != n));
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int key = abs(a - b);
	if (key % 2 == 1) {
		cout << "Borys" << endl;
	}
	else {
		cout << "Alice" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring> 

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;

long long mod_div(long long a, long long b) {
	if (a % b == 0)return a / b;
	long long tmp = MOD - 2, c = b, ret = 1;
	while (tmp > 0) {
		if (tmp & 1) {
			ret *= c; ret %= MOD;
		}
		c *= c; c %= MOD; tmp >>= 1;
	}
	return a*ret%MOD;
}

char str[100011];
int dp[4][100011];

int main() {

	cin >> str;
	int len = strlen(str);

	ll tmp = 1;
	ll cou = 0;
	REP(i, len) {
		if (str[i] == '?')cou++;
	}
	REP(i, cou) {
		tmp *= 3;
		tmp %= MOD;
	}

	dp[0][0] = tmp;
	REP(i, len) {
		REP(j, 4) {
			if (dp[j][i]) {
				if (j < 3) {
					if (str[i] == 'A' + j) {
						dp[j + 1][i + 1] += dp[j][i];
						dp[j + 1][i + 1] %= MOD;
					}
					else if (str[i] == '?') {
						dp[j + 1][i + 1] += mod_div(dp[j][i], 3);
						dp[j + 1][i + 1] %= MOD;
					}
				}
				dp[j][i + 1] += dp[j][i];
				dp[j][i + 1] %= MOD;
			}
		}
	}

	printf("%d\n", dp[3][len]);

	return 0;
}


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

int main() {
	int h1, s1, h2, s2;
	bool game_over = false;
	bool attack = true;

	cin >> h1 >> s1 >> h2 >> s2;
	
	while(!game_over) {
		if(attack) {
			h2 -= s1;
			attack = false;
		} else {
			h1 -= s2;
			attack = true;
		}
		if(h1 <= 0) {
			cout << "No" << endl;
			game_over = true;
		} else if(h2 <= 0) {
			cout << "Yes" << endl;
			game_over = true;
		}
	}

	return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

constexpr auto M = 1000000007L;

int64_t mpow(int64_t a, int64_t b) {
    if (b == 0) {
        return 1;
    }

    if (b == 1) {
        return a;
    }

    auto t = mpow(a, b / 2);

    return t * t % M * mpow(a, b % 2) % M;
}

int64_t calc_tree_size(const vector<vector<int64_t>>& adjs,
                       vector<int64_t>& tree_size, int64_t v, int64_t p = -1) {
    tree_size[v] = 1;
    for (auto u : adjs[v]) {
        if (u == p) {
            continue;
        }

        tree_size[v] += calc_tree_size(adjs, tree_size, u, v);
    }

    return tree_size[v];
}

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

    vector<vector<int64_t>> adjs(n);
    for (auto _ : irange(0L, n - 1)) {
        int64_t a, b;
        cin >> a >> b;
        --a;
        --b;
        adjs[a].push_back(b);
        adjs[b].push_back(a);
    }

    vector<int64_t> tree_size(n);
    calc_tree_size(adjs, tree_size, 0);

    int64_t inv2 = M / 2 + 1;

    int64_t ans = 0;
    for (auto i : irange(1L, n)) {
        int64_t s1 = tree_size[i];
        int64_t s2 = n - tree_size[i];

        int64_t q1 = (M + 1 - mpow(inv2, s1)) % M;
        int64_t q2 = (M + 1 - mpow(inv2, s2)) % M;

        ans += q1 * q2 % M;
        ans %= M;
    }

    ans = (2 * M + ans + 1 - mpow(inv2, n) - n * inv2 % M) % M;

    cout << ans << endl;
}

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

int main(){
  int n,k,x;
  cin>>n>>k;
  
  vector<int> a(n+1);
  
  for (int j=0;j<k;j++) {
    	int d;
    	cin>>d;
    for (int i=0;i<d;i++) {
    	int b;
    	cin>>b;
    	a.at(b)+=1;
  	}
  }

  for(int l=1;l<n+1;l++){
    if(a.at(l)==0) x++;
  }
  
  cout<<x<<endl;

}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	double N, T, A;
	cin >> N >> T >> A;
	vector<double>H(N);
	rep(i, N) {
		cin >> H[i];
	}
	double m = 1000000;
	rep(i, N) {
		m = min(m, abs(T - H[i] * 0.006 - A));
	}
	rep(i, N) {
		if (abs(T - H[i] * 0.006 - A) == m) {
			cout << i + 1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
    	int N = ni();
    	int[] a = nia(N);

    	int ans = Integer.MAX_VALUE;

    	for (int i=-100; i<=100; i++) {
    		int tmp = 0;
    		for (int j=0; j<N; j++) {
    			tmp += (a[j] - i) * (a[j] - i);
    		}
    		if (tmp < ans) {
    			ans = tmp;
    		}
    	}

    	out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}


Measured memory_bytes: 8020
import sys
input = sys.stdin.readline
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
nums = [int(i) for i in input().split()] # 配列で数字

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


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define PB push_back
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

	int n, m; cin >> n >> m;
	string s; cin >> s;
	vi dp(n+1, -1);
	vi dp2(n+1, 0);

	queue<int> q;
	q.push(0);
	dp[0] = 0;
	for(int i = 1; i <= n; i++){
		if(s[i] == '1') continue;
		while(!q.empty() && q.front()+m<i)
			q.pop();
		if(q.empty()){
			cout << "-1\n";
			return 0;
		}
		dp[i] = dp[q.front()]+1;
		dp2[i] = q.front();
		q.push(i);
	}

	vi ans(1, n);
	int last = n;
	while(last){
		last = dp2[last];
		ans.PB(last);
	}
	reverse(all(ans));

	for(int i = 1; i <= dp[n]; i++){
		cout << ans[i]-ans[i-1] << ' ';
	}

	return 0;
}

Measured memory_bytes: 1868
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	s[k-1] += 32;
	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void print_err() {
	cerr << "\n";
}
template <class T, class... Arg>
void print_err(T x, Arg&&... args) {
	cerr << x << " ";
	print_err(args...);
}
#ifdef local
#define debug(...) print_err(__VA_ARGS__)
#else
#define debug(...)
#endif
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vl vector<ll>
#define vpll vector<pair<ll,ll>>
#define mll map<ll,ll>
#define mllrev map<ll,ll,greater<int>>
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(t) ll t;cin>>t;while(t--)
#define fo(i,n) for(ll i=0;i<n;++i)
#define foab(i,a,b) for(ll i=a;i<b;++i)
#define inp cin>>
#define pr cout<<
#define fastio ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
class Graph {
public:
	list<ll> *adj_list;
	ll v;
	Graph(ll v) {
		this->v = v;
		adj_list = new list<ll>[v];
	}
	void add_edge(ll u, ll v, bool bidirectional = true) {
		adj_list[u].push_back(v);
		if (bidirectional) {
			adj_list[v].push_back(u);
		}
	}
	void print();
	void connected_compo();
	void dfs(ll v, bool visited[]);
	void bfs(ll v, bool visited[]);
};
void solve() {
	// // http://codeforces.com/problemset/problem/445/A
	// inp n >> m;
	// fo(i, n) {
	// 	fo(j, m) {
	// 		inp ch[i][j];
	// 	}
	// }
	ll n, temp;
	inp n;
	vl vect;
	ll dp[n];
	fo(i, n) {
		inp temp;
		dp[i] = 0;
		vect.pb(temp);
	}
	dp[0] = 0; dp[1] = abs(vect[1] - vect[0]);
	for (ll i = 2; i < n; i++) {
		dp[i] = min(abs(vect[i] - vect[i - 1]) + dp[i - 1], abs(vect[i] - vect[i - 2]) + dp[i - 2]);
	}
	// fo(i, n) {
	// 	cout << dp[i] << " ";
	// }
	cout << dp[n - 1] << endl;
	return ;
}
int main() {
	fastio
#ifdef local
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
	solve();
	return 0;
}
// ll n, m;
// char ch[100][100];
// bool istrue = false;
// ll dx[] = { -1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
// void dfs(ll row, ll col, char ch) {
// 	if (ch[row][col] == 'B' or ch[row][col] == 'W' or ch[row][col] == '-' or istrue) {
// 		return;
// 	}
// 	fo(i, 4) {
// 		if (isvalid(ch, row + dx[i], col + dy[i])) {
// 			if (ch == 'B') {
// 				dfs(row + dx[i], col + dy[i], 'W');
// 			} else if (ch == 'W') {
// 				dfs(row + dx[i], col + dy[i], 'B');
// 			}
// 		}
// 	}
// }

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

using namespace std;

int n, m;

int main() {
    scanf("%d %d", &n, &m);
    vector<int> h(n+1);
    vector<int> adjMax(n+1, 0);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &h[i]);
    }

    int u, v;
    for (int i = 0; i < m; ++i) {
        scanf("%d %d", &u, &v);
        adjMax[u] = max(adjMax[u], h[v]);
        adjMax[v] = max(adjMax[v], h[u]);
    }

    long long cnt = 0;
    for (int i = 1; i <= n; ++i) {
        if (h[i] > adjMax[i]) {
            cnt++;
        }
    }
    printf("%lld\n", cnt);
    return 0;
}


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

int main() {
  char c2;
  int x1,x3;
  cin >> x1 >> c2 >> x3;
  if (c2=='+'){
    cout << x1+x3 << endl;
  }else{
    cout << x1-x3 <<endl;
  }
  return 0;
}


Measured memory_bytes: 256
def Word(a):
    res = ""
    for c in a:
        if(ord('A') <= ord(c) <= ord('Z')):
            res += chr(ord(c) - ord('A') + ord('a'))
        else:
            res += c
    return res
 
w = Word(input())
ans = 0
 
while True:
    s = input()
    if s == "END_OF_TEXT":
        break
 
    s = list(map(str, s.split()))
    for x in s:
        if Word(x) == w:
            ans += 1
 
print(ans)


Measured memory_bytes: 5556
require 'openssl'
N,*X = $<.read.split.map &:to_i
M = (10**9+7).to_bn
m = 0.to_bn
F = (1...N).inject(1.to_bn) {|s,i| s.mod_mul(i.to_bn,M)}
p (1...N).inject(m) {|s,i|
	m += F * i.to_bn.mod_inverse(M)
	((m%=M) * (X[i]-X[i-1]).to_bn + s) % M
  }.to_i

Measured memory_bytes: 17276
import sys
n, total = list(map(int, input().split()))
for x in range(n+1):
    for y in range(n-x+1):
        z = n - x - y
        if x*10000 + y*5000 + z*1000 == total:
            print("{} {} {}".format(x, y, z))
            sys.exit()
print("-1 -1 -1")


Measured memory_bytes: 2940
// import kotlin.comparisons.*
// import kotlin.math.*
import java.util.*

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main(args: Array<String>) {
  val (n, r) = readIs()
  println(if (10 <= n) r else r + 100 * (10 - n))
}


Measured memory_bytes: 38056
import sys
s=input()
cnt=0
if s[0]!='A':
    print('WA')
elif s[1].isupper():
    print('WA')
elif s[-1].isupper():
    print('WA')
else:
    for i in range(2,len(s)-1):
        if s[i]=='C':
            cnt+=1
        else:
            if s[i].isupper():
                print('WA')
                sys.exit()
    if cnt==1:
        print('AC')
    else:
        print('WA')

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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> mii;
typedef map<ll,int> mli;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;  ///1e9+7

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll n;
    cin>>n;
    if(n<=599) cout<<8 el;
    else if(n<800) cout<<7 el;
    else if(n<1000) cout<<6 el;
    else if(n<1200) cout<<5 el;
    else if(n<1400) cout<<4 el;
    else if(n<1600) cout<<3 el;
    else if(n<1800) cout<<2 el;
    else cout<<1 el;
}

main()
{
//    fastio();
        _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3592
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split('/').Select(x => int.Parse(x)).ToArray();
            if(input[0] > 2019)
            {
                Console.WriteLine("TBD");
                return;
            }
            if(input[0] < 2019)
            {
                Console.WriteLine("Heisei");
                return;
            }
            if(input[1] > 4)
            {
                Console.WriteLine("TBD");
                return;
            }
            if(input[1] < 4)
            {
                Console.WriteLine("Heisei");
                return;
            }
            if(input[2] > 30)
            {
                Console.WriteLine("TBD");
                return;
            }
            Console.WriteLine("Heisei");
        }
    }
}


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

int main() {
    int a,b;
    cin >> a ;
    string s;
    while (true) {
        cin >> s;
        if (s == "+") {
           cin >> b;
            a+=b;
        }else if (s== "-"){
            cin >> b;
            a-=b;
        }else if (s=="*"){
            cin >> b;
            a*=b;
        }else if (s=="/"){
            cin >> b;
            a/=b;
        }else{
            cout << a << endl;
            break;
        }
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
  ll n, d, x, y;
  int count = 0;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x*x + y*y <= d*d) count++;
  }

  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 3628
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

antenna = [a,b,c,d,e]

isConnection = True

for t in antenna:
    for u in antenna:
        if abs(t-u) > k:
            isConnection = False

if isConnection:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3064