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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n; cin >> n;
	if (n%1000 == 0)
		std::cout << 0 << std::endl;
	else
		std::cout << 1000 - n%1000 << std::endl;
	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);

  int n,m;cin>>n>>m;
  if(n==m)cout<<"Yes\n";else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 256
X,N=map(int,input().split())
if N!=0:
  ls=list(map(int,input().split()))
  a=0
  for i in range(102):
    if i in ls:
      continue
    else:
      if abs(i-X)<abs(a-X):
        a=i
  else:
    print(a)
else:
  print(X)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 9223372036854775807
#define mini 9223372036854775807
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update>
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll c=power(a,b/2);
	if(b%2==0)
		return ((c%mod)*(c%mod))%mod;
	else
		return ((((c%mod)*(c%mod))%mod)*a)%mod;
}
ll n,k;
ll a[200005][3];
ll dp[200005][4];
ll func(ll i,ll pre)
{
//	cout<<i<<" "<<n<<" "<<dp[i][pre]<<endl;
	if(dp[i][pre]!=-1)
		return dp[i][pre];
	if(i>=n)
		return 0;
//	cout<<"---------------------"<<endl;
	ll ans1=-1;
	ll ans2=-1;
	ll j;
	for(j=0; j<3; j++)
	{
		if(pre!=j)
		{
			ans1=a[i][j]+func(i+1,j);
			ans2=max(ans1,ans2);
		}
	}
	dp[i][pre]=ans2;
	return dp[i][pre];
}
int main()
{
	boost
	cin>>n;
	ll i;
	for(i=0; i<200005; i++)
	{
		dp[i][0]=-1;
		dp[i][1]=-1;
		dp[i][2]=-1;
		dp[i][3]=-1;
	}
	for(i=0; i<n; i++)
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	ll ans=func(0,3);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 18304
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()

cnt = [0] * (10**4+1)


for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            tmp = ((i+j)**2 + (j+k)**2 + (k+i)**2) // 2
            if tmp < 10**4 + 1:
                cnt[tmp] += 1

for i in range(1, N+1):
    print(cnt[i])

Measured memory_bytes: 68800
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,j,k,n,b,f,r,v,a[5][4][11];
	for(i=1;i<=4;i++)	{
		for(j=1;j<=3;j++)	{
			for(k=1;k<=10;k++)	a[i][j][k]=0;
		}
	}
	scanf("%d",&n);
	for(i=0;i<n;i++)	{
		scanf("%d %d %d %d",&b,&f,&r,&v);
		a[b][f][r]+=v;
	}
	for(i=1;i<=4;i++)	{
		for(j=1;j<=3;j++)	{
			for(k=1;k<=10;k++)	{
				printf(" %d",a[i][j][k]);
			}
			printf("\n");
		}
		if(i!=4)	printf("####################\n");
	}	
	return 0;
}


Measured memory_bytes: 2688
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define MOD 1000000007;//1e9+7

int main() {

    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < S.size() / 2; i++)if (S[i] != S[S.size() - 1 - i])ans++;

    cout << ans;
}

Measured memory_bytes: 256
/*
 * 9a.c
 *
 *  Created on: 2017/05/23
 *      Author: Tomohiro
 */

#include <stdio.h>
#include <string.h>
#include <ctype.h>
//#define DEBUG

int main(){

	char strW[11] ={};					//????????????????±?
	char END[12]={"END_OF_TEXT"};		//???????????¶??¨
	char strT[1001]={};					//????????????????????¨

	int i = 0;							//???????????°
	int cnt = 0;						//????????????

	scanf("%s",strW);			//????????????????±?????????????????????????
#ifdef DEBUG
	printf("strW???%s\n",strW);
#endif

	for(i = 0 ; strW[i] != '\0' ; i++){		//strW[i]???\0??????????????§for????????????
			strW[i] = tolower(strW[i]);		//(??§??????????????°)?°?????????????????????????
	}
#ifdef DEBUG
	printf("?°???????????????????????????????strW???%s\n",strW);
#endif


	/*???????????????????????????*/
	while(1){
		scanf("%s",strT);				//?¬?????????????????????????
#ifdef DEBUG
	printf("strT???%s\n",strT);
#endif
		if(!strcmp(strT,END)){			//strT???END_OF_TEXT?????£??????
			printf("%d\n",cnt);			//???????????????????????¨?????????
			return 0;					//?????????????????????????????????
		}

		/*???????????£??????????????¨????°??????????????????????*/
		for(i = 0 ; strT[i] != '\0' ; i++){		//strT[i]???\0??????????????§for????????????
			strT[i] = tolower(strT[i]);		//?????§??????????????°????°?????????????????????????
		}

#ifdef DEBUG
	printf("?°???????????????????????????????strT???%s\n",strT);
#endif

		if(!strcmp(strT,strW)){			//strT???strW??¨?????´????????°strcmp???????????????0
			cnt++;						//????????´?????????????????¢??????
		}

	}//?????????????????????????????§?????????return?????\?????§??????????????¨????????????
	return 0;
}

Measured memory_bytes: 552
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


D = z()
C = zz()
S = defaultdict(list)
for i in range(D):
    S[i + 1] = zz()
# やらなくていいコンテストはやらないC=0
never_held = []
for i, c in enumerate(C):
    if (c == 0):
        never_held.append(i+1)
contest = 0
for _ in range(D):
    while (contest % 26 + 1 in never_held):
        contest += 1
    print(contest % 26 + 1)
    contest += 1


Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };


int main() {
#ifdef _DEBUG
	printf( "debug\n" );
#endif
	for ( int i = 1; i < 10; i++ ) {
		for ( int j = 1; j < 10; j++ ) {
			printf( "%dx%d=%d\n", i, j, i * j );
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

int main() 
{
    ll n, x, y;
    scanf("%lld", &n);
    
    list<ll> l;
    list<ll>::iterator it = l.end();
    
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld", &x);
        
        if(x == 0)
        {
            scanf("%lld", &y);
            l.insert(it, y);
            it--;
        }
        else if(x == 1)
        {
            scanf("%lld", &y);
            advance(it, y);
        }
        else if(x == 2)
        {
            it = l.erase(it);
        }
    }
    
    for(auto z : l)
        printf("%lld\n", z);
        
    return 0;
}


Measured memory_bytes: 18760
#include <iostream>

int main() {
    int a, b, c;
    std::cin >> a; std::cin >> b; std::cin >> c;
    if ( a < b and b < c) {
        std::cout << "Yes" << '\n';
    } else {
        std::cout << "No" << '\n';
    }
    return 0;
}



Measured memory_bytes: 3068
#include <stdio.h>

int main() {
	while (1) {
		int n, m;
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0) break;
		int a[1000];
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		int max = 0;
		bool x = true;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j && a[i] + a[j] <= m && max < a[i] + a[j]) {
					max = a[i] + a[j];
					x = false;
				}
				
			}
		}
		if (x) printf("NONE\n");
		else printf("%d\n", max);

	}

}


Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N, K; cin >> N >> K;
  ll x = N/K;
  if (K%2 == 0) {
    ll y = N/(K/2)-N/K;
    cout << x*x*x+y*y*y << endl;
  } else {
    cout << x*x*x << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<tuple>
#include<set>
#include<cmath>
#include<numeric>
#define ll long long
#define MOD = 1e9+7
 
using namespace std;

int main(){
  string N;
  cin >> N;
  if(N.back()=='3') cout << "bon" << endl;
  else if(N.back()=='0' || N.back()=='1' || N.back()=='6' || N.back()=='8') cout << "pon" << endl;
  else cout << "hon" << endl;
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int k; cin >> k;
    ll now = 7;
    int ans = 1;
    vint check(k,false);
    while (now % k != 0) {
        if (check[now%k]) {cout << -1 << endl; return 0;}
        check[now%k] = true;
        ans++;
        now *= 10;
        now += 7;
        now %= k;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7068
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>

typedef long long ll;

using namespace std;

int main(void)
{
    int a, b;
    cin >> a >> b;
    if(a == b) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

    return 0;
}

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

struct node{
  int key;
  struct node *p;
  struct node *left;
  struct node *right;
};
typedef struct node *Node;

Node root,NIL;
int max;

void insert(int k){
  int T;
  Node x = root;
  Node y = NIL;
  Node z;

  z = malloc(sizeof(struct node));
  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;

  while(x != NIL){
    y = x;
    if(z -> key < x -> key){
      x = x -> left;
  }
  else{
    x = x -> right;
  }
}

z -> p = y;
if ( y == NIL ){
  root = z;
}
else{
  if (z -> key < y -> key) {
    y -> left = z;
  }
  else{
    y -> right = z;
  }
}
}

void in(Node n){
  if (n == NIL) return;
  in(n -> left);
  printf(" %d", n -> key);
  in(n -> right);
}

void out(Node n){
  if (n == NIL) return;
  printf(" %d", n -> key);
  out(n -> left);
  out(n -> right);
}

int main(){
  int l, i, s;
  char M[20];
  scanf("%d",&l);
  max = 0;
  for (i=0 ; i<l ; i++){
    scanf("%s", M);
    if (strcmp(M,"insert") == 0){
      scanf("%d",&s);
      insert(s);
    }
    else if (strcmp(M,"print") == 0){
      in(root);
      printf("\n");
      out(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 25240
#include <iostream>

using namespace std;

int f(int a, int b) {
    int add = a + b;
    int sub = a - b;
    int mul = a * b;

    if (add > sub) {
        if (add > mul) {
            return add;
        } else {
            return mul;
        }
    } else {
        if (sub > mul) {
            return sub;
        } else {
            return mul;
        }
    }

    return mul;
}

int main() {

    int a, b;
    cin >> a >> b;

    int result = f(a, b);
    cout << result << endl;

    return 0;
}


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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

template<class T> inline bool is_overlap(const T& as, const T& ae, const T& bs, const T& be)
{ return bs <=ae && as <= be; }

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int A,B,C,D; cin >>A>>B>>C>>D;

    int ans = 0;
    if (is_overlap(A,B,C,D))
        ans = min(B, D) - max(A, C);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <climits>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

int main(){
    int h, w;
    cin >> h >> w;
    int ret = 0;
    vector< vector<int> > c(10);
    repi(i, c){
        *i = vector<int>(10);
        in_arr(int, *i, 10);
    }
    rep(i, 10){
        rep(j, 10){
            rep(k, 10){
                c[j][k] = min(c[j][i] + c[i][k], c[j][k]);
            }
        }
    }
    rep(i, h){
        rep(j, w){
            int a;
            cin >> a;
            if(a != -1){
                ret += c[a][1];
            }
        }
    }
    
    cout << ret << endl;
    return 0;
}



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

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = min(k, a);
    k -= min(k, a);
    if(k > 0ll){
        k -= b;
    }
    if(k > 0ll){
        ans -= min(k, c);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A,A+N);
  bool ans = true;
  for (int i = 0; i < N - 1; i++) {
    if (A[i] == A[i + 1]) ans = false;
  }
  if (ans) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int n,maxn=-99998989;
int f[100010],cnt,x,y;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		maxn=maxn<y?y:maxn;
		for(int i=x;i<=y;i++)
		  f[i]=1;
	}
	for(int i=1;i<=maxn;i++)
	  if(f[i]==1)
	    cnt++;
	cout<<cnt;
}

Measured memory_bytes: 640
#![allow(unused_imports, dead_code)]
use std::f64::*;
use std::cmp::*;
use std::collections::*;

macro_rules! dump{
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const INF: i64 = 0x3f3f3f3f3f3f3f3f;
const MOD: i64 = 1000000007;
const NOTHING: usize = std::usize::MAX;
const DX: [usize; 4] = [1, 0, std::usize::MAX, 0];
const DY: [usize; 4] = [0, 1, 0, std::usize::MAX];

fn main() {
    let (n, m): (usize, usize) = readln();
    let a: Vec<i64> = readln();
    let a: Vec<i64> = a.iter().map(|x| x - 1).collect();
    let mut diff0: Vec<i64> = vec![0;2 * m];
    let mut diff1: Vec<i64> = vec![0;2 * m];

    let mut base = 0;
    for i in 1..n {
        let d = (a[i] - a[i - 1] + m as i64) % m as i64;
        base += d;
        let l = a[i - 1] as usize + 1;
        let r = a[i - 1] as usize + d as usize + 1;
        diff1[l] -= 1;
        diff1[r] += 1;
        diff0[l] += a[i - 1] + 1;
        diff0[r] -= a[i - 1] + 1;
    }

    let mut cum0: Vec<i64> = vec![0;2 * m];
    let mut cum1: Vec<i64> = vec![0;2 * m];
    cum0[0] = diff0[0];
    cum1[1] = diff1[0];
    for i in 1..2 * m {
        cum1[i] = cum1[i - 1] + diff1[i];
        cum0[i] = cum0[i - 1] + diff0[i];
    }

    let mut res = base;
    for i in 0..m {
        let improvement = cum1[i] * (i as i64) as i64 + cum0[i] + cum1[i + m] * (i + m) as i64 +
                          cum0[i + m];
        res = min(res, base + improvement);
    }

    println!("{}", res);

}

trait Read {
    fn read(s: &str) -> Self;
}

fn readln<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

macro_rules! read_impl{
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl Read for String {
    fn read(s: &str) -> Self {
        s.to_string()
    }
}

impl Read for Vec<char> {
    fn read(s: &str) -> Self {
        s.chars().collect()
    }
}

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}

impl<A: Read, B: Read, C: Read, D: Read> Read for (A, B, C, D) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]), D::read(tokens[3]))
    }
}


Measured memory_bytes: 14588
L,n,m,g;
main(s){
	for(;~scanf("%d",&n);){
		L+=n*s;
		s=-s;
		if(s<0){
			if(!g&&L<1){
				g=m;
			}
			if(++m>12){
				printf(g?"%d\n":"NA\n",g);
				s=1;
				m=L=g=0;
			}
		}
	}
}

Measured memory_bytes: 0
import sys

sys.setrecursionlimit(100000000)

n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n-1)]

neighbors = [[] for _ in range(n)]

for x, y in xys:
    neighbors[x-1].append(y-1)
    neighbors[y-1].append(x-1)

froms = [-1 for _ in range(n)]

froms[0] = -2

def f(x):
    for y in neighbors[x]:
        if froms[y]==-1 :
            froms[y] = x
            f(y)

f(0)

path = [n-1]
while path[-1]!=0:
    if froms[path[-1]]==-1:
        break
    path.append(froms[path[-1]])
path.reverse()

blacks_l = path[:(len(path)+1)//2]
blacks = set(blacks_l)
whites = set(path[(len(path)+1)//2:])

def fennec(x):
    for y in neighbors[x]:
        if not y in blacks and not y in whites:
            blacks.add(y)
            fennec(y)

for b in blacks_l:
    fennec(b)

if len(blacks) > n-len(blacks):
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 146136
h,w = map(int,input().split())
dist = [[float("inf")] * 10 for _ in range(10)]
for i in range(10):
  cost = list(map(int,input().split()))
  for j in range(10):
    dist[i][j] = cost[j]
wall = []
for _ in range(h):
  wall.append(list(map(int,input().split())))
V = 10
for k in range(V):
  for i in range(V):
    for j in range(V):
      if dist[i][k]!=float("inf") and dist[k][j]!=float("inf"):
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
ans = 0
for wa in wall:
  for wi in wa:
    if wi != -1:
      ans += dist[wi][1]
print(ans)



Measured memory_bytes: 74000
#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(){
    int a, b, c, d; cin >> a >> b >> c >> d;

    while(1){
        c -= b;
        if(c<=0){
            cout << "Yes" << endl;
            return 0;
        } 

        a -= d;
        if(a<=0){
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int a[]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main() {
	int n;
	cin>>n;
	cout<<a[n];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m ;
    cin>>m;
    return m ;
}
int main()
{
int t=D();
int n=t;
ll sum=0;
while(t){
    sum+=t%10;
    t/=10;
}
if(n%sum==0)
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
//#include"cpp_kyopro.h"
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include<stdio.h>

using namespace std;

int main(void) {
	int n,a; cin >> n;
	double sum = 0;
	//int a[1000];
	//array<int,1000> c;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		cin >> a;
		v.push_back(a);

	}
	sort(v.begin(),v.end());
	sum = (v[0] + v[1]) / 2.0;
	//cout << sum << endl;
	for (int i = 2; i < n; ++i) {
		sum = (sum + v[i]) / 2.0;
		//cout << v[i]<<"\n"<<sum << endl;
	}
	printf("%.10lf", sum);

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int dist[101][101];

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int H,W; cin >> H >> W;
	vector<string> S(H);
	rep(i,H) cin >> S[i];

	rep(i,H) rep(j,W) dist[i][j] = -1;
	dist[0][0] = S[0][0] == '#' ? 1 : 0;
	deque<pii> deq;
	deq.emplace_back(make_pair(0,0));
	while (!deq.empty()) {
		int y,x;
		tie(y,x) = deq.front(); deq.pop_front();
		if (y+1 < H) {
			if (dist[y+1][x]==-1) {
				if (S[y+1][x] != S[y][x]) {
					dist[y+1][x] = dist[y][x]+1;
					deq.emplace_back(make_pair(y+1,x));
				} else {
					dist[y+1][x] = dist[y][x];
					deq.emplace_front(make_pair(y+1,x));
				}
			}
		}
		if (x+1 < W) {
			if (dist[y][x+1]==-1) {
				if (S[y][x+1] != S[y][x]) {
					dist[y][x+1] = dist[y][x]+1;
					deq.emplace_back(make_pair(y,x+1));
				} else {
					dist[y][x+1] = dist[y][x];
					deq.emplace_front(make_pair(y,x+1));
				}
			}
		}
	}

	cout << (dist[H-1][W-1]+1)/2 << ln;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 9000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;


int main() {
	int N, M;
	cin >> N >> M;
	vi num(N, 0);
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		num[a]++;
		num[b]++;
	}

	rep(i, N) {
		if (num[i] % 2 == 1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int k,s,cnt = 0;
  cin >> k >> s;
  
  for(int i = 0; i <= k; i++) {
    for(int j = 0; j <= k; j++) {
      if(0 <= (s-i-j) & (s-i-j) <= k)
        cnt++;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;



int main(void)
{
    IOS
    const int N = 26;
    string S; cin >> S;
    set<char> st;
    REP(i,N) st.insert(i+'a');

    set<char> st1(st);
    for(auto c:S) st1.erase(c);
    string ans;
    if (st1.empty()) {
        set<char> st2;
        ans = S;
        st2.insert(ans.back());
        ans.pop_back();
        while(ans.size()) {
            char b = *st2.upper_bound(ans.back());
            if (ans.back() < b) {
                ans.back() = b;
                break;
            } else {
                st2.insert(ans.back());
                ans.pop_back();
            }
        }
        if (ans.empty()) ans = "-1";
    } else {
        ans = S + *st1.begin();
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int H, A , count;
  cin >> H >> A;
  count = 1;
  int S = H-A;
  while(S>0){
    count++;
    S-=A;
  }
  cout << count << endl;
}
  
  


Measured memory_bytes: 256
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int NM_MAX = 300002;
const int Q_MAX = 300002;

int n, m, q;

struct Bomb
{
    int a, b;
};

bool operator < (const Bomb &x, const Bomb &y)
{
    return make_pair(x.a, x.b) < make_pair(y.a, y.b);
}

Bomb v[Q_MAX];

set <Bomb> s;

vector <int> va[NM_MAX], vb[NM_MAX];

int cnta[NM_MAX], cntb[NM_MAX];

int c[NM_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> q;
    for(int i = 1; i <= q; i++)
        cin >> v[i].a >> v[i].b;
    for(int i = 1; i <= q; i++)
    {
        cnta[v[i].a]++;
        cntb[v[i].b]++;
        s.insert(v[i]);
        va[v[i].a].push_back(i);
        vb[v[i].b].push_back(i);
    }
    int ans = 0;
    int mxa = 0, mxb = 0;
    for(int i = 1; i <= m; i++)
        if(cntb[i] > cntb[mxb])
            mxb = i;
    int call = 0;
    for(int i = 1; i <= m; i++)
        if(cntb[i] == cntb[mxb])
        {
            call++;
            for(int j : vb[i])
                c[v[j].a]++;
        }
    for(int i = 1; i <= n; i++)
        if(cnta[i] - (c[i] == call) > cnta[mxa] - (c[mxa] == call))
            mxa = i;
    for(int i = 1; i <= m; i++)
        ans = max(ans, cnta[mxa] + cntb[i] - (s.find(Bomb{mxa, i}) != s.end()));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 56364
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int x = tx - sx, y = ty - sy;

    string ans;
    for (int i = 0; i < y; i++) ans += 'U';
    for (int i = 0; i < x; i++) ans += 'R';

    for (int i = 0; i < y; i++) ans += 'D';
    for (int i = 0; i < x; i++) ans += 'L';

    ans += 'L';
    for (int i = 0; i < y+1; i++) ans += 'U';
    for (int i = 0; i < x+1; i++) ans += 'R';
    ans += 'D';

    ans += 'R';
    for (int i = 0; i < y+1; i++) ans += 'D';
    for (int i = 0; i < x+1; i++) ans += 'L';
    ans += 'U';

    cout << ans << '\n';

}

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

    solve();

    return 0;
}

Measured memory_bytes: 3656
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

N, X = map(int, input().split())
x = list(map(int, input().split())) + [X]
D = [0] * N

for i in range(N):
    D[i] = abs(X - x[i])

if N == 1:
    print(D[0])
    exit()

ans = gcd(D[0], D[1])
for j in range(2, N):
    ans = gcd(ans, D[j])

print(ans)

Measured memory_bytes: 14224
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	ll n;
  cin>>n; n;
  vector<ll> x(n);
  vector<ll> l(n);
  rep(i,n){
    cin>>x[i]; x[i];
    cin>>l[i]; l[i];
  }
	vector<pll> ps(n);
	rep(i,n) ps[i]=pll(x[i]-l[i],x[i]+l[i]);
	sort(all(ps),[&](auto p,auto q){ return p.Y<q.Y;});
	out(ps,1);
	ll rb=-1e18;
	int re=0;
	for(auto p:ps){
		if(rb<=p.X){
			++re;
			rb=p.Y;
		}
	}
	cout<<re NL;
	return 0;
}


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

void print( vector<int> &A, int N )
{
	for( int k = 0; k < N; k++ ) {
		cout << A[k];
		if( k < N - 1 ) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}
}

void sort( vector<int> &A, int N )
{
	for( int i = 1; i < N; i++ ) {
		int v = A[i];
		int j = i - 1;
		while( j >= 0 && A[j] > v ) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		print( A, N );
	}
}

int main()
{
	int N;
	cin >> N;
	vector<int> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	print( A, N );

	sort( A, N );
}



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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
   cin >> vec.at(i);
  }
  
  int c = 0;
  int x = 0;
  
  for (int i = 0; i < N; i++) {
    x = 0;
    for (int j = 0; j < N; j++) {
      if (x < vec.at(j))
      x = vec.at(j);
    }
    
    if (x != 0)
      c++;
    
    for (int j = 0; j < N; j++) {
      if (vec.at(j) == x) {
      vec.at(j) = 0;
      }
    }
  }
  cout << c << endl;
}
   
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

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

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

//! [Hの高さまで見たとき][1から出た枝が左からWの位置にいるようなあみだくじ]=の本数
ll dp[105][10];
int H, W, K;

ll c(int n)
{
	if (n == 1)
	{
		return 1;
	}
	if (n == 2)
	{
		return 2;
	}
	if (n == 3)
	{
		return 3;
	}
	if (n == 4)
	{
		return 5;
	}
	if (n == 5)
	{
		return 8;
	}
	if (n == 6)
	{
		return 13;
	}
	if (n == 7)
	{
		return 21;
	}
	return 1;
}

ll calc(int l, int r)
{
	l--; r++;
	ll left = 1, right = 1;
	{
		//! 左側
		left = c(l + 1);
	}
	{
		//! 右側
		right = c(W - r);
	}
	return left*right;
}

int main()
{

	cin >> H >> W >> K;
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	FOR(h, H + 1, 1)
	{
		REP(w, W)
		{
			ll s1 = 0, s2 = 0, s3 = 0;
			//! wに来るのはw-1から来る、w+1から来る、wから来るの3通り
			if (w - 1 >= 0) {
				//! w-1から来る場合
				s1 = (s1 + dp[h - 1][w - 1]) % MOD;
				//! 使っていない部分に適当に線を引く
				s1 = (s1 * calc(w - 1, w)) % MOD;
			}
			if (w + 1 < W)
			{
				//! w+1から来る場合
				s2 = (s2 + dp[h - 1][w + 1]) % MOD;
				//! 使っていない部分に適当に線を引く
				s2 = (s2 * calc(w, w + 1)) % MOD;
			}

			{
				//! wから来る場合
				s3 = (s3 + dp[h - 1][w]) % MOD;
				//! 使っていない部分に適当に線を引く
				s3 = (s3 * calc(w, w)) % MOD;
			}
			dp[h][w] = (s1 + s2 + s3)%MOD;
		}
	}
	cout << dp[H][K - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;

public class Main
{
    int n;
    int a[] = new int[100001];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	int cnt = 0;
	int now = 1;
	
	while(a[now] != -1) {
	    int tmp = now;
	    now = a[now];
	    a[tmp] = -1;
	    cnt++;
	    if(now == 2) break;
	}
	
	if(now == 2) out(cnt);
	else         out(-1);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	for(int i = 1; i <= n; i++) a[i] = sc.nextInt();
    }

    void out()
    {
	
    }
    
    void out(int ans)
    {
	System.out.println(ans);
    }
}


Measured memory_bytes: 50820
#include<stdio.h>
 
int count=0;
void margesort(int *,int,int);
void marge(int *,int,int,int);
 
int S[5000000],L[2500001],R[2500001];
 
int main(){
  int n,i;
  scanf("%d",&n);
   for(i=0;i<n;i++) scanf("%d",&S[i]);
 
   margesort(S,0,n);
 
   for(i=0;i<n-1;i++) printf("%d ",S[i]);
   printf("%d\n",S[i]);
    
   printf("%d\n",count);
    
   return 0;
}
 
void margesort(int *S,int left,int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    margesort(S,left,mid);
    margesort(S,mid,right);
    marge(S,left,mid,right);
  }
}
 
void marge(int *S,int left,int mid,int right){
  int n1,n2;
  int i,j=0,k;
 
  n1 = mid - left;
  n2 = right - mid;
 
  for(i=0;i<n1;i++) L[i] = S[left+i];
  L[n1]=1000000001;
  for(i=0;i<n2;i++) R[i] = S[mid+i];
  R[n2]=1000000001;
 
  i=0;
  for(k=left;k<right;k++){
  if(L[i] <= R[j]){ 
    S[k] = L[i];
    i++;
  }
  else{
    S[k] = R[j];
    j++;
  }
  count++;
  }
}

Measured memory_bytes: 9768
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
#include <stack>
#include <cstring>
 
#define ll long long
#define MP make_pair
#define PB push_back
#define P push
#define f first
#define se second
#define S size()
#define B begin()
#define E end()
#define rB rbegin()
#define rE rend()
#define PI acos(-1)

 
const int N = 1e5 + 100;
const int M = 1e6 + 100;
const ll oo = 1e18;
 
ll n, m, k, t, q, h, a, b, d, c, e, w, x, y, z;
using namespace std;


int dp[N], ar[N];


int main() {


	cin >> n;

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

		if(!i) continue;

		if(i == 1){
			dp[i] = abs(ar[i] - ar[i - 1]);
			continue;
		}

		dp[i] = min(dp[i - 1] + abs(ar[i] - ar[i - 1]), dp[i - 2] + abs(ar[i] - ar[i - 2]));
	}


	cout << dp[n - 1];
    
	
    
    return 0;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T> inline T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,a,b;cin>>n>>a>>b;
  if(a>b)swap(b,a);
  
  if((b-a)%2==0)cout<<(b-a)/2<<ENDL;
  else{
    cout<<min(((b-a-1)/2) +a,((b-a-1)/2) +n-b+1)<<ENDL;
  }
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e6 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M;
string S;
vector<pii> va;
void input() {
  ;
  ;
  cin >> N;
  va.resize(N);
  int x;
  rep(i, 0, N - 1) {
    cin >> x;
    va[i] = pii(x - 1, i);
  }
}
void solve() {
  sort(all(va));
  ;
  for (auto x : va) {
    cout << x.second + 1 << " ";
  }
  cout << endl;

  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <fstream>
#include <sstream>
#include <random>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <iostream>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <set>
#include <iomanip>

#define ll long long
#define mod 1000000007
#define max_limit 1000005
using namespace std;

bool compare(const pair<ll, ll>&i, const pair<ll, ll>&j) {
    return i.first < j.first;
}

int main() {

    ll n;
    cin>>n;
    ll d;
    cin>>d;
    ll a;
    cin>>a;

    pair<ll, ll> post[n];

    for(int i = 0; i < n; i++) {
        cin>>post[i].first>>post[i].second;
    }
    sort(post, post + n, compare);

    // damage, inclusive end of application
    queue<pair<ll, ll>> q;
    ll ans{0};
    ll totalDamage{0};
    for(int i = 0; i < n; i++) {
        while(!q.empty() && post[i].first > q.front().second) {
            totalDamage -= q.front().first;
            q.pop();
        }

        if(post[i].second - totalDamage <= 0) {
            continue;
        }

        ll count{0};
        if((post[i].second - totalDamage)%a != 0) {
            count += 1;
        }
        count += (post[i].second - totalDamage)/a;
        totalDamage += count*a;
        ans += count;
        q.push(make_pair(count*a, post[i].first + 2*d));
    }


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


Measured memory_bytes: 4992
-- [Char]あるいは String を Int にする
toInt :: (String -> Int)
toInt x = read x ::Int

--入力を受け取り、[Int]にする
getInts = do
  x <- getLine
  let y = (map$toInt)$words x -- 半角スペースで分割してInt にする
  return y

main = do
  _ <- getInts
  x <- getInts

  if ok x 0 == 1
    then putStrLn "Yes"
    else putStrLn "No"
  where
    ok x n =
      if null x
        then 1
        else if head x >= n
          then ok (tail x) $ max n $ (head x) - 1
          else 0


Measured memory_bytes: 36220
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	ld n, m, d;
	cin >> n >> m >> d;
	cout << fixed << setprecision(10);
	if (d == 0)
	{
		cout << 1.0 / n*(m - 1) << en;
	}
	else
	{
		cout << (2.0 * (n - d)) / (n * n)*(m - 1) << en;
	}


	return 0;
}



Measured memory_bytes: 3792
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int main(void){
	int n; cin >> n;
	set<pair<int, int> > ss;
	int ans = 0;
	for (int i = 1; i <= n; ++i){
		int t; cin >> t;
		int s = i;
		if(s > t) swap(s, t);
		if(ss.count(make_pair(s, t)) != 0) ans++;
		ss.insert(make_pair(s, t));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	int a,b;
	cin >> a >> b;
	if(a>0){
		cout << "Positive" << endl;
	}
	else if(b >= 0 || a == 0){
		cout << "Zero" << endl;
	}
	else{
		int c = b-a;
		(c%2 == 0)? cout << "Negative" << endl : cout << "Positive" << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;


int main(void) {
	int k, i, t;
	string ans, y, c[9] = { "1","2","3","4","5","6","7","8","9" };
	vector<string> v;

	cin >> k;

	for (i = 0; i < 9; i++) {
		v.push_back(c[i]);
	}

	i = 9;
	t = 0;
	while (i < k) {
		y = v[t];
		if (y[y.size() - 1] > '0') {
			v.push_back(y + (char)(y[y.size() - 1] - 1));
			i++;
		}
		v.push_back(y + y[y.size() - 1]);
		i++;
		if (y[y.size() - 1] < '9') {
			v.push_back(y + (char)(y[y.size() - 1] + 1));
			i++;
		}
		t++;
	}

	cout << v[k - 1] << endl;

	return 0;
}

Measured memory_bytes: 6900