akhauriyash/Code-Regression huggingface dataset:
from operator import itemgetter
from itertools import *
from bisect import *
from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10**6)

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 SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x)-1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def SCC(to, ot):
    n = len(to)

    def dfs(u):
        for v in to[u]:
            if com[v]: continue
            com[v] = 1
            dfs(v)
        top.append(u)

    top = []
    com = [0]*n
    for u in range(n):
        if com[u]: continue
        com[u] = 1
        dfs(u)

    def rdfs(u, k):
        for v in ot[u]:
            if com[v] != -1: continue
            com[v] = k
            rdfs(v, k)

    com = [-1]*n
    k = 0
    for u in top[::-1]:
        if com[u] != -1: continue
        com[u] = k
        rdfs(u, k)
        k += 1

    return k, com

class TwoSat:
    def __init__(self, n):
        # to[v][u]...頂点uの値がvのときの遷移先と反転の有無
        self.n = n
        self.to = [[] for _ in range(n*2)]
        self.ot = [[] for _ in range(n*2)]
        self.vals = []

    # uがu_val(0 or 1)ならばvはv_val(0 or 1)
    def add_edge(self, u, u_val, v, v_val):
        self.to[u*2+u_val].append(v*2+v_val)
        self.ot[v*2+v_val].append(u*2+u_val)

    # 条件を満たすかどうかをboolで返す。構成はself.valsに入る
    def satisfy(self):
        k, com = SCC(self.to, self.ot)
        for u in range(self.n):
            if com[u*2]==com[u*2+1]:return False
            self.vals.append(com[u*2]<com[u*2+1])
        return True

n, d = MI()
xy = LLI(n)
ts = TwoSat(n)

for i in range(n):
    x1, y1 = xy[i]
    for j in range(i):
        x2, y2 = xy[j]
        if abs(x1-x2) < d:
            ts.add_edge(i, 0, j, 1)
            ts.add_edge(j, 0, i, 1)
        if abs(x1-y2) < d:
            ts.add_edge(i, 0, j, 0)
            ts.add_edge(j, 1, i, 1)
        if abs(y1-x2) < d:
            ts.add_edge(i, 1, j, 1)
            ts.add_edge(j, 0, i, 0)
        if abs(y1-y2) < d:
            ts.add_edge(i, 1, j, 0)
            ts.add_edge(j, 1, i, 0)

if ts.satisfy():
    print("Yes")
    for j,xyi in zip(ts.vals,xy):print(xyi[j])
else:print("No")


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

int main(){
	int n,m;cin>>n>>m;
	vector<char>a;
	rep(i,n)rep(j,m){char b;cin>>b;a.PB(b);}
	sort(all(a));
	map<char,int>b;
	rep(i,a.size())b[a[i]]++;
	a.erase(unique(all(a)),a.end());
	int cnt4=0;
	rep(i,a.size()){
		while(b[a[i]]>=4){
			cnt4++;
			b[a[i]]-=4;
		}
	}
	int cnt2=0;
	rep(i,a.size()){
		while(b[a[i]]>=2){
			cnt2++;
			b[a[i]]-=2;
		}
	}
	int cnt1=0;
	rep(i,a.size()){
		while(b[a[i]]>=1){
			cnt1++;
			b[a[i]]--;
		}
	}
	if(n%2==0&&m%2==0){
		if(cnt4==n*m/4)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	if(n%2==0&&m%2==1){
		while(cnt4>(n/2)*(m-1)/2){
			cnt4--;
			cnt2+=2;
		}
		if(cnt4==(n/2)*(m-1)/2&&cnt2==n/2)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	if(n%2==1&&m%2==0){
		while(cnt4>(m/2)*(n-1)/2){
			cnt4--;
			cnt2+=2;
		}
		if(cnt4==(m/2)*(n-1)/2&&cnt2==m/2)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	if(n%2==1&&m%2==1){
		while(cnt4>(m-1)*(n-1)/4){
			cnt4--;
			cnt2+=2;
		}
		if(cnt4==(m-1)*(n-1)/4&&cnt2==(m-1)/2+(n-1)/2&&cnt1==1){
			cout<<"Yes"<<endl;
		}
		else cout<<"No"<<endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  double a,b,c,d,e,f,x,y;
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
    y=(a*f-c*d)/(a*e-b*d);
    x=(c-b*y)/a;
    printf("%.3lf %.3lf\n",x,y);
  }
  return 0;
 }

Measured memory_bytes: 648
//
// Noszály Áron 9a Debreceni Fazekas Mihály Gimnázium
//
#include<bits/stdc++.h>
#include<cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;

#define all(s) (s).begin(),(s).end()
#define pb push_back
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define INF std::numeric_limits<int>::max()
#define MINF std::numeric_limits<int>::min()
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define mp make_pair
#define xx first
#define yy second
#define sz(x) (int)(x).size()

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

const long double PI = acos(-1);

int d1[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int d2[8][2]={{1,0},{0,1},{0,-1},{-1,0},{1,1},{-1,1},{1,-1},{-1,-1}};

int main()
{
	IO;
	int n;cin>>n;
	cout<<(n*(n+1)/2)<<"\n";
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int dp[100010];
int main(){
    int N,K; cin >> N >> K;
    vector<int> h(N);
    rep(i,N) cin >> h[i];
    rep(i,100010){
        dp[i] = INF;
    }
    dp[1] = 0;
    repr(i,1,N){
        repr(j,1,K+1){
            if(i+j <= N){
                dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j-1]-h[i-1]));
            }
        }
    }
    cout << dp[N] << endl;
}



Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#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 llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    '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'
};

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }

int main(){
    int H,W,h,w;
    cin >> H >> W;
    cin >> h >> w;
    cout << H * W - (h * W + H * w - h * w) << endl;

    return 0;
}


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

int n, d, a[109][10009], v[109], u[109], s[109], cnt;

int main() {
	while (true) {
		cin >> n >> d; cnt = 0; if (n == 0) break;
		for (int i = 1; i <= n; i++) {
			cin >> v[i]; u[i] = 1; s[i] = 0;
			for (int j = 1; j <= v[i]; j++) { cin >> a[i][v[i] + 1 - j]; cnt++; s[i] += a[i][v[i] + 1 - j]; }
		}
		if (n == 1) { cout << "Yes" << endl; continue; }
		while (true) {
			bool OK = false;
			for (int i = 1; i <= n; i++) {
				if (u[i] > v[i]) continue;
				s[i] -= a[i][u[i]];
				int maxn = -1, minx = 10000000;
				for (int j = 1; j <= n; j++) {
					maxn = max(maxn, s[j]);
					minx = min(minx, s[j]);
				}
				if (maxn - minx > d) { s[i] += a[i][u[i]]; continue; }
				u[i]++; cnt--; OK = true;
				break;
			}
			if (OK == false) break;
		}
		if (cnt == 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;


int n;

bool C(int mid, vector<int> v){
    long long sum = v[mid];
    rep(i,n){
        if(i == mid) continue;
        if(sum * 2 < v[i]) return false;
        sum += v[i];
    }
    return true;
}


int main(){
    cin >> n;

    vector<int> v(n);
    rep(i,n) cin >> v[i];
    sort(all(v));

    int right = n - 1, left = 0;
    rep(i,50){
        int mid = (right + left ) / 2;
        if(C(mid,v)) right = mid;
        else left = mid;
    }
    cout << n - right << endl;
}


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

char s[105];
int check[95], N, num;

int main()
{
    int i;

    cin >> N;
    for(i=0; i<N; i++)
        cin >> s[i];

    for(i=0; i<N; i++)
        if(check[s[i]]==0)
            check[s[i]]=1, num++;

    if(num==3)
        cout << "Three";
    else
        cout << "Four";
    return 0;
}

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

const int MAX_N = 100010;
const int inf = 1000000000;
int N;
int K;
vector<int> h(MAX_N);
vector<int> dp(MAX_N, inf);

int rec(int x) {
  if (dp[x] != inf) return dp[x];
  int res = inf;
  if (x == 0) res = 0;
  else if (x < K) {
    for (int i = 0; i < x; i++) {
      res = min(res, rec(i) + abs(h[x] - h[i]));
    }
  }
  else {
    for (int i = x-K; i < x; i++) {
      res = min(res, rec(i) + abs(h[x] - h[i]));
    }
  }
  return dp[x] = res;
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> h[i];

  cout << rec(N-1) << endl;
}

Measured memory_bytes: 5760
# -*- coding: utf-8 -*-


if __name__ == '__main__':

    
    def lcs(X, Y):
        m = len(X)
        n = len(Y)
        c = [[-1 for i in range(n+1)] for j in range(m+1)]
        X = " " + X
        Y = " " + Y
        for i in range(m+1):
            c[i][0] = 0
        for j in range(1, n+1):
            c[0][j] = 0
        for i  in range(1, m+1):
            for j in range(1, n+1):
                if X[i] == Y[j]:
                    c[i][j] = c[i-1][j-1] + 1
                else:
                    c[i][j] = max(c[i-1][j], c[i][j-1])
        return c[m][n]

    def lcs2(X, Y):
        n = len(Y)
        dp = [0]*(n+1)
    
        for c in X:
            tmp = dp[:]
            for j in range(n):
                if c == Y[j]:
                    dp[j+1] = tmp[j] + 1
                elif dp[j+1] < dp[j]:
                    dp[j+1] = dp[j]
    
        return dp[-1]

    q = int(input())
    for _ in range(q):
        X = input()
        Y = input()
        print(lcs2(X,Y))




Measured memory_bytes: 5640
#include <utility> // pair make_pair
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11

bool check(string str, string tar) {
    int lens = str.length();
    int lent = tar.length();
    int str_index = 0;
    int tar_index = 0;
    while (1) {
        if (tar_index == lent) {
            return true;
        } else if (str_index == lens) {
            return false;
        }
        if (str[str_index] == tar[tar_index]) {
            tar_index++;
        }
        str_index++;
    }
}

int main(void) {
    string s;
    string t;
    cin >> s >> t;
    int slen = s.length();
    string odd = "";
    string even = "";
    FOR(i, 0, slen) {
        if ((i + 1) % 2 == 1) {
            odd += s[i];
        } else {
            even += s[i];
        }
    }
    //cout << s << " " << t << " " << odd << " " << even << endl;
    if (check(t, odd) == true || check(t, even) == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3216
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt=0

for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if X == i*500 + j*100 + k*50:
        cnt+=1
print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
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;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    map<string, int> mp;
    REP(i, N){
        string S;
        cin >> S;
        mp[S]++;
    }
    pr(mp.size());
}

Measured memory_bytes: 19256
def count(counted, cards, is_blue):
    for word in cards:
        if not word in counted:
            counted[word] = 1 if is_blue else -1
        else:
            counted[word] += 1 * (1 if is_blue else -1)
    return counted


counted = {}
n = int(input())
counted = count(counted, [input() for _ in range(n)], True)
m = int(input())
counted = count(counted, [input() for _ in range(m)], False)
high_score = max(sorted(counted.items(), key=lambda x: x[1], reverse=True)[0][1], 0)
print(high_score)

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}



int main(){
    int A[3];
    REP(i,3) cin >> A[i];
    sort(A,A+3);
    int res[3]={0};
    int ans=0;
     REP(i,3) res[i]=A[i]%2;
    while(A[0]!=A[2]){
        if(A[0]+2<=A[2]){
            ++ans;
            A[0]=A[0]+2;
        }
        else{
            ++ans;
            A[0]++;
            A[1]++;
        }
        sort(A,A+3);

    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e7+5;
ll a[100005];
int main(){
	ll n;
	cin>>n; 
	for(int i=1;i<=n;i++) cin>>a[i];
	ll ans=a[1];
	for(int i=2;i<=n;i++){
		ans=__gcd(ans,a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
  int N;
  cin >> N;
  for (int i = 0; i< N; i++) {
    string arare;
    cin >> arare;
    
    if (arare == "Y") {
      cout << "Four" << endl;
      break;
  }
    if (i == N-1) {
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

ll S(ll n) {
    ll result = 0;
    while (n) {
        result += n % 10;
        n /= 10;
    }

    return result;
}

int main() {
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);

    for (ll i = 1; ; i++) {
        if ((i - 1) * K - (i - 2) <= N && N <= i * K - (i - 1)) {
            cout << i << endl;
            return 0;
        }
    }

    ll one_pos = -1;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] == 1) {
            one_pos = i;
            break;
        }
    }

    ll left = one_pos;
    ll right = N - 1 - one_pos;

    ll ans = 0;

    ans += (left % (K - 1) == 0 ? left / (K - 1) : left / (K - 1) + 1);
    right -= (left % (K - 1) == 0 ? 0 : K - 1 - left % (K - 1));
    ans += (right % (K - 1) == 0 ? right / (K - 1) : right / (K - 1) + 1);

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
	char S[4];
	int a;

	scanf("%s", S);
	if (S[0] == 'R' && S[1] == 'R' && S[2] == 'R') {
		a = 3;
	}
	else if (S[1] == 'R' && (S[0] == 'R' || S[2] == 'R')) {
		a = 2;
	}
	else if (S[0] == 'S' && S[1] == 'S' && S[2] == 'S') {
		a = 0;
	}
	else {
		a = 1;
	}
	printf("%d", a);

	return 0;
}


Measured memory_bytes: 1728
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;
const LL mod = 1e9 + 7;

int main()
{
	int n;
	char O[55],E[55];
	while(~scanf("%s%s",O,E)){
		n = strlen(E);
		for(int i = 0;i < n;i++) printf("%c%c",O[i],E[i]);
		if(n < strlen(O)) printf("%c",O[n]); 
		printf("\n");
	}
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main() {
	int A,B;
	scanf("%d %d",&A,&B);
	int ans=0;
	int i=0;
	while(i < 2) {
		if (A >= B) {
			ans += A;
			A--;
		}
		else {
			ans += B;
			B--;
		}
		i++;
	}
	printf("%d\n",ans);
	return 0;
}

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

vector<pair<int, int>> g[111111];
int c[111111];
void f(int p, int u, int b) {
	c[u] = b;
	for (auto v : g[u])
		if (v.first != p)
			f(u, v.first, b^v.second & 1);
}
int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		g[u].emplace_back(v, w);
		g[v].emplace_back(u, w);
	}
	f(0, 1, 0);
	for (int i = 0; i < n; i++)
		cout << c[i + 1] << '\n';
	cout << flush;
	return 0;
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll mod = 1e9+7;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    
    ll ans = 0;
    
    rep(i, n){
        cin >> h[i];
        if(h[i] >= k){
            ans ++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)
n,m=map(int,input().split())
#xyz = [[]for i in range(m)]
g = [[]for i in range(n)]
for i in range(m):
    x,y,z = map(int,input().split())
    g[x-1].append(y-1)
    g[y-1].append(x-1)

seen = [0 for i in range(n)]

def dfs(i):
    for nec in g[i]:
        if seen[nec]!=0:continue
        seen[nec]=1
        dfs(nec)

cnt = 0
for i in range(n):
    if seen[i] == 0:
        seen[i] = 1
        dfs(i)
        cnt+=1

print(cnt)


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

int main(){
  int A,B,C,D;
  
  cin>>A>>B>>C>>D;
  
  bool loop = true;
  
  bool res = true;
  
  while(loop){
    
    C -= B;
    
    if(C <= 0){
      break;
    }
    
    A -= D;
    
    if(A <= 0){
      res = false;
      break;
    }
   
  }

  if(res){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
    
    
  
  return 0;

}

Measured memory_bytes: 3632
/**
  * Created by ui on 2016/03/08.
  */
object Cal {
  val sc = new java.util.Scanner(System.in)

  def input = {
    val a = sc.nextInt()
    val op = sc.next.head
    val b = sc.nextInt()
    (a, op, b)
  }

  def calculate(a:Int, op:Char, b:Int) =
    op match {
      case '+' => a + b
      case '-' => a - b
      case '*' => a * b
      case '/' => a / b
      case _ => 0
    }


  def run: Unit = {
    var t = input
    var a = t._1
    var op = t._2
    var b = t._3
    while (op != '?') {
      println(calculate(a, op, b))
      t = input
       a = t._1
       op = t._2
       b = t._3
    }
  }
}
object Main {
  def main(args: Array[String]) {
    Cal.run
  }

}

Measured memory_bytes: 45096
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<sstream>
#include<numeric>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if
 
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
 
typedef long long ll;
typedef double db;
typedef vector<int> Vi;
typedef pair<int,int> pii;
 
int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}
 
const int N=1e5+19;
 
map<int,int> M,fa,sz;
int A[N],B[N];
int n,c,s,res;
Vi V;
 
int getf(int x){
	return fa[x]==x?x:fa[x]=getf(fa[x]);
}
void Union(int x,int y){
	x=getf(x),y=getf(y);
	if (x!=y) fa[x]=y,sz[y]+=sz[x];
}
 
int main(){
	n=IN();
	For(i,1,n+1) A[i]=IN(),s^=A[i];
	For(i,1,n+1) M[B[i]=IN()]++;
	For(i,1,n+1){
		V.pb(A[i]);
		if (!M[A[i]]) c++;else M[A[i]]--;
	}
	V.pb(s);
	if (!M[s]) c++;else M[s]--;
	if (c>1){
		puts("-1");
		return 0;
	}
	for (int i:V) fa[i]=i,sz[i]=1;
	For(i,1,n+1)
		if (A[i]!=B[i]){
			res++;
			Union(A[i],B[i]);
		}
	for (int i:V) if (fa[i]==i&&sz[i]>1&&i!=getf(s)) res++;
	printf("%d\n",res);
}

Measured memory_bytes: 24824
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
a,b,c,d = i2()
a1 = a//d
a2 = c//b
if a%d != 0:a1 += 1
if c%b != 0:a2 += 1
print("Yes" if a1 >= a2 else "No")

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

using namespace std;

const int MOD = 1e9 + 7;

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

    int n, m;
    cin >> n >> m;

    vector <vector <char> > a(n, vector <char>(m));
    for(auto & v : a)
        for(auto & x : v)
            cin >> x;

    vector <vector <int> > dp(n, vector <int>(m));

    dp[0][0] = 1;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j)
            if(i + j > 0 && a[i][j] == '.')
            {
                if(i)
                    dp[i][j] += dp[i - 1][j];
                if(j)
                    dp[i][j] += dp[i][j - 1];

                if(dp[i][j] >= MOD)
                    dp[i][j] -= MOD;
            }

    cout << dp[n - 1][m - 1] << '\n';

    return 0;
}



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

int main(){
    int h,w; cin>>h>>w;
    vector<vector<char>> a(h,vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }

    for(int i=0;i<w+2;i++) cout<<"#";
    cout<<endl;
    for(int i=0;i<h;i++){
        cout<<"#";
        for(int j=0;j<w;j++){
            cout<<a[i][j];
        }
        cout<<"#"<<endl;
    }
    for(int i=0;i<w+2;i++) cout<<"#";
    cout<<endl;
}

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

int const N = 100000;
int a[N + 1], b[N];

int main(){
	int n;
	scanf("%d", &n);
	f(i, 0, n)scanf("%d", a + i);
	f(i, 0, n)scanf("%d", b + i);
	ll c = 0;
	f(i, 0, n)c += b[i] - a[i];
	if (c > 0) { printf("-1\n"); return 0; }
	f(i, 0, n)a[i] -= b[i];
	sort(a, a + n);
	int j = n, an = 0;
	f(i, 0, n)if (a[i] < 0){
		++an;
		while (a[i] < 0){
			if (a[j] == 0)--j;
			int z = min(-a[i], a[j]);
			a[i] += z;
			a[j] -= z;
		}
	}
	printf("%d\n", an + n - j);
}

Measured memory_bytes: 1024
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 2005
#define oo 2000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, x[maxN], y[maxN], dpX[maxN], dpY[maxN];

int main () {
    scanf("%d%d%d", &n, &x[0], &y[0]);
    fto(i, 1, n) {
        scanf("%d", &x[i]);
        y[i] = x[i];
    }

    fdto(i, n-1, 0) {
        dpX[i] = abs(y[i]-x[n]);
        fto(j, i+1, n-1) dpX[i] = max(dpX[i], dpY[j]);
        dpY[i] = abs(x[i]-y[n]);
        fto(j, i+1, n-1) dpY[i] = min(dpY[i], dpX[j]);
    }

    printf("%d", dpX[0]);


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next())*100;
		int B = Integer.parseInt(sc.next())*100;
		int C = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int E = Integer.parseInt(sc.next());
		int F = Integer.parseInt(sc.next());
		sc.close();

        int water = A, sugar = 0;
        for(int i = 0; i <= F / A; i++){
            for(int j = 0; j <= F / B; j++){
                for(int x = 0; x <= F / C; x++){
                    for(int y = 0; y <= F / D; y++){
                        int a = A * i + B * j;
                        int b = C * x + D * y;
                        if(100 * b <= a * E
                        		&& b * water > a * sugar
                        		&& a + b <= F){
                            water = a;
                            sugar = b;
                        }
                    }
                }
            }
        }
        System.out.println(water + sugar + " " + sugar);
	}
}

Measured memory_bytes: 23636
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(N-1):
    if A[i] + A[i+1] > x:
        # 超えている分を引く
        sa = A[i] + A[i+1] - x
        if A[i+1] >= sa:  # A[i+1]だけでカバーできる場合
            A[i+1] -= sa
            ans += sa
            continue
        else:
            ans += A[i+1]
            sa -= A[i+1]
            A[i+1] = 0
            ans += sa
            A[i] -= sa
    else:
        continue
print(ans)


Measured memory_bytes: 14068
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b=parseMap(split(readline()))
    soinsu1=Set{Int}(1)
    soinsu2=Set{Int}(1)
    for i in 2:trunc(Int,sqrt(a))+1
        while a%i==0
            a÷=i
            push!(soinsu1,i)
        end
    end
    push!(soinsu1,a)
    for i in 2:trunc(Int,sqrt(b))+1
        while b%i==0
            b÷=i
            push!(soinsu2,i)
        end
    end
    push!(soinsu2,b)
    ans=0
    for i in soinsu1
        if i in soinsu2
            ans+=1
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 169988
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
arr=list(ss())
temp=0
centr=0
centl=0
ans=[0]*len(arr)

childeven=0
childodd=0

for i in range(len(arr)):
    if arr[i]=="R":
        if temp==0:
            centr=i
            if i%2==0:
                childeven+=1
            else:
                childodd+=1
        else:
            childeven=0
            childodd=0
            centr=i
            temp=0
            if i%2==0:
                childeven+=1
            else:
                childodd+=1

    else:
        if temp==0:
            temp=1
            centl=i

            if i%2==1:
                ans[centr]+=childeven
                ans[centr+1]+=childodd
            else:
                ans[centr]+=childodd
                ans[centr+1]+=childeven
                
            if (i-centl)%2==0:
                ans[centl]+=1
            else:
                ans[centl-1]+=1

        else:
            if (i-centl)%2==0:
                ans[centl]+=1
            else:
                ans[centl-1]+=1
    #print(ans,childeven,childodd)

print(*ans)

Measured memory_bytes: 77428
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>
 
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define nrep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;
 
ll comb[51][51];
 
void com(int n){
	rep(i,n+1){
		rep(j,i+1){
			if(j==0||j==i){
				comb[i][j]=1LL;
			}
			else comb[i][j]=comb[i-1][j-1]+comb[i-1][j];
		}
	}
}
 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a,b;cin>>n>>a>>b;
	vector<ll> v;
	com(n);
	rep(i,n){
		ll t;cin>>t;
		v.push_back(t);
	}
	sort(v.begin(),v.end(),greater<ll>());
	double sum=0.0;
	rep(i,a)sum+=v[i];
	sum/=a;
	int x=0,y=0;
	rep(i,n){
		if(v[i]==v[a-1]){
			x++;
			if(i<a)y++;
		}
	}
	ll ret=0LL;
	if(v[0]==v[a-1]){
		nrep(i,a,b+1){
			ret+=comb[x][i];
		}
	}
	else{
		ret+=comb[x][y];
	}
printf("%.7f\n%lld\n",sum,ret);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, T; cin >> N >> T;
    ll res = 0;
    ll pre_t = 0;
    for(int i = 0; i  <N;i++){
        ll t; cin >> t;
        if(i == 0){
            pre_t = t;
            continue;
        }else{
            res += min(t- pre_t,T);
            pre_t = t;
        }
    }
    res += T;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
INF = 10**18


if __name__ == "__main__":
    x = int(input())
    if x>=30:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 67896
n=int(input())
b,w=[0],[0]
for i in input():
  if i==".":
    b.append(0)
    w.append(1)
  else:
    b.append(1)
    w.append(0)
b.append(0)
w.append(0)
for i in range(1,n+1):
  b[i]+=b[i-1]
for i in range(n,0,-1):
  w[i]+=w[i+1]
ans=200000
for i in range(1,n+2):
  ans=min(ans,b[i-1]+w[i])
print(ans)


Measured memory_bytes: 18948
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;


int main(){
    int N;
    ll S = 0;
    cin >> N;
    ll T[N];
    rep(i,N){
        ll t;
        cin >> t;
        S += t;
        T[i] = t;
    }
    int M;
    cin >> M;
    ll p, x;
    rep(i, M){
        cin >> p >> x;
        cout << S + x - T[p - 1] << endl;
    }


}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath> 
using namespace std;
int main(){
    int n,k,i,x;
	int d[10];
	cin >> n >> k;
	for(i=0;i<k;i++){
		cin >> d[i];
	}
	int f=1;
	while(f){
		f=0;
		x=n;
		while(x){
			for(i=0;i<k;i++){
				if(d[i]==x%10){
					f=1;
					break;
				}
			}
			x/=10;
		}
		n++;
	}
	cout << n-1 << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> h(N);
  for(int i=0; i<N; i++){
    cin >> h[i];
  }
  int k0=0,k1=max(h[1]-h[0],h[0]-h[1]);
  for(int i=2; i<N; i++){
    int x=k1;
    int a=max(h[i]-h[i-1],h[i-1]-h[i]);
    int b=max(h[i]-h[i-2],h[i-2]-h[i]);
    k1=min(a+k1,b+k0);
    k0=x;
  }
  cout << k1 << endl;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<P> f(m);//b a の順
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        f[i].first = b; f[i].second = a;
    }
    sort(all(f));
    int ans = 0;
    int temp = f[0].first - 1;//b-1番目の橋 
    ++ans;
    rep(i,m-1){
        if(f[i+1].second <= temp) continue;
        else {
            temp = f[i+1].first - 1;
            ++ans;
        }
    }
    cout << ans << endl;      
    return 0;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    writeln!(o, "{}", solve(n)).unwrap();
}
fn solve(n: usize) -> usize {
    let mut ans = 0;
    divisors(n, |x| {
        let m_1 = n / x;
        let m = m_1 - 1;
        if x < m {
            ans += m;
        }
    });
    ans
}
fn divisors<F: FnMut(usize)>(n: usize, mut f: F) {
    fn divisors_by<F: FnMut(usize)>(fs: &[(usize, usize)], mut n: usize, f: &mut F) {
        if fs.is_empty() {
            f(n);
            return;
        }
        let (p, c) = fs[0];
        for _ in 0..c + 1 {
            divisors_by(&fs[1..], n, f);
            n *= p;
        }
    }
    divisors_by(&factorize(n), 1, &mut f)
}
fn factorize(mut n: usize) -> Vec<(usize, usize)> {
    assert!(n != 0);

    fn try_push_factor(n: &mut usize, f: usize, fs: &mut Vec<(usize, usize)>) -> bool {
        let mut c = 0;
        while *n % f == 0 {
            *n /= f;
            c += 1;
        }
        if c != 0 {
            fs.push((f, c));
            true
        } else {
            false
        }
    }
    let mut fs = Vec::new();

    try_push_factor(&mut n, 2, &mut fs);
    let mut f = 3;
    let mut end = (n as f64).sqrt() as usize + 1;
    while f < end {
        if try_push_factor(&mut n, f, &mut fs) {
            end = (n as f64).sqrt() as usize + 1;
        }
        f += 2;
    }
    if n != 1 {
        fs.push((n, 1));
    }
    fs
}


mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


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

using namespace std;

int main() {
  #ifdef _OFFLINE_
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int a, b, c;
  cin >> a >> b >> c;
  cout << (a % 3 == 0 || b % 3 == 0 || (a+b)% 3 == 0 ? "Possible" : "Impossible");
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int a, b, k;
    int i = 0;
    scanf("%d %d %d", &a, &b, &k);

    for (i = 0; 1;) {
        if (a % 2) {
            a--;
        }
        b += a / 2;
        a /= 2;
        i++;
        if (!(i < k)) {
            break;
        }
        if (b % 2) {
            b--;
        }
        a += b / 2;
        b /= 2;
        i++;
        if (!(i < k)) {
            break;
        }
    }

    printf("%d %d\n", a, b);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(std::string S){
  vector<long long> ret(S.size(), 0);
  long long e, o, s;
  e = 0;
  o = 0;
  s = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'L') {
      if ((i-s)%2 == 0) {
        ret[i-1] += o;
        ret[i] += e;
      } else {
        ret[i-1] += e;
        ret[i] += o;
      }
      e = 0;
      o = 0;
      s = i+1;
    } else {
      if ((i-s)%2 == 0) {
        e++;
      } else {
        o++;
      }
    }
  }
  e = 0;
  o = 0;
  s = S.size()-1;
  for (int i = S.size()-1; i >= 0; i--) {
    if (S[i] == 'R') {
      if ((s-i)%2 == 0) {
        ret[i+1] += o;
        ret[i] += e;
      } else {
        ret[i+1] += e;
        ret[i] += o;
      }
      e = 0;
      o = 0;
      s = i-1;
    } else {
      if ((s-i)%2 == 0) {
        e++;
      } else {
        o++;
      }
    }
  }
  for (int i = 0; i < ret.size(); i++) {
    if (i != 0) {
      std::cout << " ";
    }
    std::cout << ret[i];
  }
  std::cout << std::endl;
}

int main(){
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 1408