akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std; 
using lint  =                           long long int;
using pint  =                           pair<int, int>;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD                             1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

lint pow_mod(lint base,lint expo) { 
   lint ret = 1;
   for(;expo;) { 
      if(expo&1)  ret = (ret*base)%MOD; 

      expo = (expo>>1);
      base = (base*base)%MOD;
   }

   return ret;
}

/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

lint a[100100];

void solve(){  
    lint N;
    cin >> N;
    lint K;
    cin >> K;         //distinct integers;

   lint ret = 0;
    for(lint gcd = K;gcd >= 1; --gcd) { 
            a[gcd] = pow_mod(K/gcd,N);

          for(lint exc = gcd*2;exc <= K; exc += gcd) {
             a[gcd] = (a[gcd] - a[exc] + MOD)%MOD;
          }
       ret = (ret + a[gcd]*gcd)%MOD;
    }

    cout << ret << endl;
}

int main(){   
  
 solve();

 return 0;
}


Measured memory_bytes: 4376
using System;

namespace _1_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a, b;
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            Console.WriteLine("{0} {1}",a*b,2*b+2*a);
            Console.ReadLine();


        }
    }
}



Measured memory_bytes: 9092
#include <bits/stdc++.h>
#define int long long
#define dl long double
#define ff first
#define ss second
#define pb push_back
#define inf 1000000007
#define MAXN 200100
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef pair<int,int> pii;
const int M = 1e9+7;
const int N = 2e5 +2;

struct Seg{
	int n;
	vector<int> tree;
	Seg(int tam){
		n = tam;
		tree = vector<int>(2*n,0);
	}
	
	Seg(vector<int> const& values){
        n = values.size();
		tree = vector<int>(2*n,0);
		copy(values.begin(),values.end(),&tree[0]+n);	
		for(int idx = n-1;idx>0;idx--){
			tree[idx] = max(tree[idx*2],tree[idx*2+1]);
		}	
			
	}
	
	void update(int idx,int value){
		idx+=n;
		tree[idx]=value;
		while(idx>1){
			idx/=2;
			tree[idx] = max(tree[idx*2],tree[2*idx+1]);
		}
	}
	
	int maximum(int l,int r){
		int res = -inf;
		l+=n;
		r+=n;
		if(l==r)return tree[l];
		while(l<r){
			if(l&1)res=max(res,tree[l++]);
			if(r&1)res=max(res,tree[--r]);
			l >>= 1;
			r >>= 1;
		}
		return res;
	} 
	
		
};

int dp[N];

int32_t main(){
	fastio;
	int n;
	cin>>n;
	vector<int> h(n+10),a(n+10);
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	Seg arvore(n+10);
	dp[0]=0;
	for(int i=1;i<=n;i++){
		dp[i] = arvore.maximum(0,h[i]) + a[i];
		arvore.update(h[i],dp[i]);
		dp[i] = max(dp[i-1],dp[i]);
	}
	
	cout<<dp[n]<<endl;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

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

    int ma = h[0];
    int ans = 1;

    for (int i = 1; i < n; ++i) {
        if (ma <= h[i]) {
            ++ans;
            ma = h[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long H, long long A){
  cout<<H/A+(H%A>0?1:0)<<endl;
}

int main(){
  cout<<setprecision(1000);
  cin.tie(0);
  ios::sync_with_stdio(false);
    long long H;
    scanf("%lld",&H);
    long long A;
    scanf("%lld",&A);
    solve(H, A);
    return 0;
}


Measured memory_bytes: 256
/* - - - - - - - - - - - - - - -
	User : 		VanishD
	problem :
	Points : 	
- - - - - - - - - - - - - - - */
# include <bits/stdc++.h>
# define 	ll 		long long
using namespace std;
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
int read(){
	int tmp = 0, fh = 1; char ch = getchar();
	while (ch < '0' || ch > '9'){ if (ch == '-') fh = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9'){ tmp = tmp * 10 + ch - '0'; ch = getchar(); }
	return tmp * fh;
}
const int N = 200010;
struct Edge{
	int data, next;
}e[N * 2];
int use[N][2], head[N], flag, n, m, place;
char s[N];
void build(int u, int v){
	e[++place].data = v; e[place].next = head[u]; head[u] = place;
}
void dfs(int x, int tag){
	use[x][tag] = 1;
	for (int ed = head[x]; ed != 0; ed = e[ed].next){
		if (use[e[ed].data][tag ^ 1] == 2) continue;
		if (tag == 1){
			if (s[e[ed].data] == s[x]) continue;
			if (use[e[ed].data][0] == false)
				dfs(e[ed].data, 0);
				else flag = true;
		}
		else {
			if (s[e[ed].data] != s[x]) continue;
			if (use[e[ed].data][1] == false)
				dfs(e[ed].data, 1);
				else flag = true;
		}
	}
	use[x][tag] = 2;
}
int main(){
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(), m = read();
	scanf("\n%s", s + 1);
	for (int i = 1; i <= m; i++){
		int u = read(), v = read();
		build(u, v);
		build(v, u);
	}
	for (int i = 1; i <= n; i++){
		if (use[i][0] == 0) dfs(i, 0);
		if (use[i][1] == 0) dfs(i, 0); 
	}
	if (flag)
		printf("Yes\n");
		else printf("No\n");
	return 0;
}


Measured memory_bytes: 11520
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}

int main(){
    int n;
    cin >> n;
    vector<string>s(n);
    rep(i,n)cin >> s[i];
    int ans = 0;
    rep(i,n){
        int k = (int) s[i].size();
        rep(j,k-1){
            if(s[i][j] == 'A' and s[i][j+1] == 'B')ans++;
        }
    }
    show(ans);
    int a = 0, b = 0, c = 0, d = 0;
    rep(i,n){
        if(s[i][0] == 'B' and s[i].back() == 'A')c++;
        else if(s[i].back() == 'A')a++;
        else if(s[i][0] == 'B')d++;
    }
    show(a,b,c,d);
    if(c==0){
        ans += min(a,d);
    }else{
        ans += c - 1;
        if(a)ans++,a--;
        if(d)ans++,d--;
        ans += min(a,d);
    }
    cout << ans << endl;
    return 0;
}

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

int x[ 110 ];
int y[ 110 ];

int main()
{
int i;
int N;
int M;
int X;
int Y;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> M;
	cin >> x[0];
	cin >> y[0];

	for( i = 1; i <= N;i++ )cin >> x[i];
	for( i = 1; i <= M;i++ )cin >> y[i];

	sort( x, x + N +1);
	sort( y, y + M +1);

	if( x[ N ] <  y[ 0 ]  )
		cout << "No War"<< endl;
	else
		cout << "War"<< endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int n,a[3];
int dp[4][1<<8];

int main(){
	cin>>n>>a[2]>>a[1]>>a[0];
	vector<int>l(n);
	rep(i,n){
		cin>>l[i];
	}
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	rep(i,3)rep(j,1<<n){
		if(dp[i][j]==INF)continue;
		rep(k,1<<n){
			if(k==0)continue;
			if(j&k)continue;
			int cnt=0;
			rep(t,n){
				if(k>>t&1)cnt+=l[t];
			}
			dp[i+1][j|k]=min(dp[i+1][j|k],dp[i][j]+abs(cnt-a[i])+10*(__builtin_popcount(k)-1));
		}
	}
	cout<<*min_element(dp[3],dp[3]+(1<<n))<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
)

const MOD int = 1000000007

func main() {

	var n int

	fmt.Scan(&n)

	m := map[string]int{}
	input := make([]string, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&input[i])
		m[input[i]] += 1
	}

	for key, value := range m {
		if key == "0" {
			if value != 1 {
				fmt.Println("0")
				os.Exit(0)
			}
		} else {
			if value != 2 {
				fmt.Println("0")
				os.Exit(0)
			}
		}
	}

	l := n / 2
	res := 1
	s := 2
	for {
		if l == 0 {
			break
		}
		if (l & 1) == 1 {
			res = (res * s) % MOD
		}
		s = (s * s) % MOD
		l >>= 1
	}
	fmt.Println(res)
}


Measured memory_bytes: 11392
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long times = N / (A + B);
		long m = N % (A + B);
		System.out.println(times * A + Math.min(m, A));
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

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

    while(K--) {
        vector<int> tmp(N+1);
        for(int i=0; i<N; i++) {
            tmp[max(0, i-A[i])]++;
            tmp[min(N, i+A[i]+1)]--;
        }
        partial_sum(tmp.begin(), tmp.end(), tmp.begin());
        A = tmp;
        if(count(A.begin(), A.end()-1, N) == N) break;
    }
    for(int i=0; i<N; i++) {
        cout << A[i] << endl;
    }
    return 0;
}


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

signed main(){
	lint t1, t2; cin >> t1 >> t2;
	lint a1, a2, b1, b2; cin >> a1 >> a2 >> b1 >> b2;
	lint P = (a1 - b1) * t1;
	lint Q = (a2 - b2) * t2;
	if(P > 0) P *= -1, Q *= -1;
	if(P == -Q){
		cout << "infinity" << endl;
		return 0;
	}
	if(P + Q < 0){
		cout << 0 << endl;
		return 0;
	}
	lint ans = 0;
	lint S = -P / (P + Q), T = -P % (P + Q);
	if(T == 0) ans = S * 2;
	else ans = S * 2 + 1;
	cout << ans << endl;
}


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

using namespace std;

#define ll long long

signed main(void) {
    ll n;
    cin >> n;
    ll div5 = 0LL;
    if(n%2LL==1LL){
        cout << 0LL << endl;
        return 0;
    }
    for(ll i=1LL;;i++){
        long double temp = n/pow((long double)5,i);
        if(temp<(long double)1) break;
        div5 += floor(temp/2LL);
    }
    cout << div5 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
	int n, c[120], b, f, r, v, t;
	cin >> n;
	for(int i = 0; i < 120; i++){
		c[i] = 0;
	}
	for(int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		c[(b-1)*30+(f-1)*10+r-1] += v;
	}
	for(int i = 0; i < 15; i++){
		if(i%4 == 3){
			cout << "####################" << endl;
		}else{
			t = i - i/4;
			for(int j = 0; j < 10; j++){
				cout << " " << c[t*10+j];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3080
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

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

// type
#include <cstdint>
#include <functional>

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

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

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

/* ---------- Functions */
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

class UnionFind {
public:
    vector<int> par, rank;
    vector<int> forest_size;
    int forest_cnt;
    int N;

    UnionFind(int n) : forest_cnt(n), N(N) {
        par = vector<int>(n);
        iota(par.begin(), par.end(), 0);
        rank = vector<int>(n, 0);
        forest_size.resize(n, 1);
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        int fsz = forest_size[x] + forest_size[y];
        if (rank[x] < rank[y]) {
            par[x] = y;
            forest_size[y] = fsz;
        } else {
            par[y] = x;
            forest_size[x] = fsz;
            if (rank[x] == rank[y]) rank[x]++;
        }
        forest_cnt--;
    }

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

    int get_forest_size(int x) {
        return forest_size[root(x)];
    }
};

signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int N, M;
    cin >> N >> M;
    auto uf = new UnionFind(N);
    int ret = 0;
    for (int i = 0; i <M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf->unite(a, b);
    }

    for (int i = 0; i < N; i++) {
        ret = max(ret, uf->get_forest_size(i));
    }

    cout << ret << endl;
    return 0;
}

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

vi a, used;
bool ok;
void dfs(int x) {
    if(used[x]) {
        if(a[a[x]] != x) ok = false;
        return;
    }
    used[x] = 1;
    dfs(a[x]);
}
constexpr ll MOD = 1e9 + 7;
ll modpow(ll x, ll n) {
    ll res = 1;
    while(n) {
        if(n & 1) res = x * res % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}
vector<ll> prd(101010), p(101010), iprd(101010);
vector<ll> inv(101010);
ll P(int a, int b) {
    if(b > a or b < 0) return 0;
    return prd[a] * iprd[a - b] % MOD;
}
main() {
    prd[0] = p[0] = inv[1] = 1;
    rep(i, 100010) prd[i + 1] = prd[i] * (i + 1) % MOD;
    rep(i, 100010) p[i + 1] = p[i] * 2 % MOD;
    rep(i, 100010) inv[i + 2] = modpow(i + 2, MOD - 2);
    iprd[0] = 1;
    rep(i, 100010) iprd[i + 1] = iprd[i] * inv[i + 1] % MOD;
    inv[1] = 1;
    while(1) {
        int n;
        cin >> n;
        if(!n) return 0;
        ok = true;
        a.resize(n);
        used = vector<int>(n);
        rep(i, n) cin >> a[i], a[i]--;
        ll k = 0, s = 0;
        vi in(n);
        rep(i, n) in[a[i]]++;
        rep(i, n) if(in[i] > 2) ok = false;
        rep(i, n) {
            if(!used[i] and !in[i]) dfs(i);
        }
        rep(i, n) {
            if(!used[i]) dfs(i);
        }
        rep(i, n) {
            if(a[a[i]] == i) {
                k++;
                if(in[i] == 1 and in[a[i]] == 1) s++;
            }
        }
        k /= 2, s /= 2;
        if(!ok) {
            cout << 0 << endl;
            continue;
        }
        ll ans = prd[k + 1] * p[k] % MOD;
        // cout << k << " " << s << endl;
        if(k == s) {
            if(s & 1)
                ans = ans * inv[2] % MOD;
            else {
                ans = ans * (s + 2) / 2 % MOD * inv[s + 1] % MOD;
            }
        } else {
            for(int i = 1; i <= s; ++i) {
                ll t = P(s, i) * (i + 1) % MOD;
                if(i & 1)
                    t = t * inv[2] % MOD;
                else
                    t = t * i % MOD * inv[2] % MOD * inv[i + 1] % MOD;
                ans -= t * (k - s) % MOD * prd[k - i - 1] % MOD * p[k + 1] % MOD;
                if(ans < 0) ans += MOD;
                if(k - i > 1) ans -= t * (k - s) % MOD * (k - s - 1) % MOD * prd[k - i - 1] % MOD * p[k] % MOD;
                if(ans < 0) ans += MOD;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 7388
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace sample
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = int.Parse(Console.ReadLine());
 
            Console.WriteLine(Calc.Ans(r));
        }
    }
    public static class Calc
    {
        public static int Ans(int r)
        {
            return r * r;
        }
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
int main(void)
{
	int d,t,s,No,time,Yes;
	scanf("%d",&d);
	scanf("%d",&t);
	scanf("%d",&s);
	time=t*s;
	if(d>time) printf("No\n");
	else printf("Yes\n");
	return 0;
}	
	
	
		

Measured memory_bytes: 1644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  prllf("%d",x);
#define pl(x)  prllf("%lld",x);
#define pf(x)  prllf("%.10lf",x);
#define ps(x)  prllf("%s",x);
#define en() prllf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define mod 100000007
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}



bool vis[100000+10];
int main()
{


  int n;
  cin>>n;
  int a1[n],a2[n],a3[n];
  for(int i=0;i<n;i++)
  {
      cin>>a1[i];
  }
    for(int i=0;i<n;i++)
  {
      cin>>a2[i];
      a3[i]=a2[i];
  }

  sort(a3,a3+n);
  vector<int>v[50000];
  for(int i=0;i<n;i++)
    v[0].pb(a3[i]);
    int k=1;
  while(next_permutation(a3,a3+n))
  {
     for(int i=0;i<n;i++)
     {
         v[k].pb(a3[i]);

     }
     k++;
  }
  //cout<<k<<endl;


 int a=0,b=0,f,g;
  for(int i=0;i<k;i++)
  {
      f=0,g=0;
      for(int j=0;j<v[i].size();j++)
      {
          if(v[i][j]!=a1[j]) {f=1; break;}
          //cout<<v[i][j]<<" ";
      }
      if(f==0) a=i+1;

  }
  for(int i=0;i<k;i++)
  {
      f=0,g=0;
      for(int j=0;j<v[i].size();j++)
      {
          if(v[i][j]!=a2[j]) {f=1; break;}
        //  cout<<v[i][j]<<" ";
      }
      if(f==0) b=i+1;

  }
  cout<<abs(a-b)<<endl;


}

















Measured memory_bytes: 3328
import java.util.*;

public class Main {
    //-------------------------------------------------------------//
    public static final void main(String[] args) {
        new Main().solve();
    }
    //-------------------------------------------------------------//
    private final Scanner sc = new Scanner(System.in);

    void solve() {
        int N = sc.nextInt();
        int max, min; max = min = sc.nextInt();
        for (int i = 1; i < N; i++) {
            int in = sc.nextInt();
            max = Math.max(max, in);
            min = Math.min(min, in);
        }
        System.out.println(max - min);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
};
ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}
typedef vector<vector<Edge>> Graph;


signed main(void) {

	int a, p;
	cin >> a >> p;

	cout << (a * 3 + p) / 2 << endl;
	
	return 0;
}


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

int main() {
  string S,T;cin>>S>>T;
  bool can=true;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i)){
      can=false;
      break;
    }
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3604
import sys
def input():
    return sys.stdin.readline()[:-1]
N,A,B,C=map(int,input().split())
pr=10**9+7
def gya(n):
    return pow(n,pr-2,pr)
MAX_NUM = 2*10**5 + 1
fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]
fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % pr
    inv[i] = pr - inv[pr%i] * (pr // i) % pr
    finv[i] = finv[i-1] * inv[i] % pr
def c(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % pr) % pr
a=0
ab=A+B
ap=pow(A,N,pr)
bp=pow(B,N,pr)
abp=1
bap=1
for i in range(N):
    a+=(i+N)*c(N+i-1,N-1)%pr*pow(ab,N-1-i,pr)%pr*(ap*abp+bp*bap)%pr
    abp=abp*B%pr
    bap=bap*A%pr
    a%=pr
a=a*100*gya(pow(ab,2*N,pr))%pr
print(a)

Measured memory_bytes: 57676
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n;
vector<int> par;
vector<int> size;
struct gg{
	long long x,y,id;
}a[100005];
bool wp1(const gg &q,const gg &w){
    return q.x<w.x;
}
bool wp2(const gg &q,const gg &w){
    return q.y<w.y;
}
void init(int n){
	size.assign(n+1,1);
	par.assign(n+1,0);
	for(int i=0;i<=n;i++){
		par[i]=i;
	}
}
int find(int x){
	if(par[x]==x) return par[x];
	par[x]=find(par[x]);
	return par[x];
}
bool issameset(int x,int y){
	return find(x)==find(y);
}
void Union(int x,int y){
	if(!issameset(x,y)){
		size[find(y)]+=size[find(x)];
		par[find(x)]=find(y);
	}
}
int main(){
	cin>>n;
	init(n);
	for(int i=0;i<n;i++){
		cin>>a[i].x>>a[i].y;
		a[i].id=i;
	}
	vector<pair<long long,ii> > edgelist;
	sort(a,a+n,wp1);
	for(int i=1;i<n;i++){
		edgelist.push_back(make_pair(a[i].x-a[i-1].x,ii(a[i].id,a[i-1].id)));
	}
	sort(a,a+n,wp2);
	for(int i=1;i<n;i++){
		edgelist.push_back(make_pair(a[i].y-a[i-1].y,ii(a[i].id,a[i-1].id)));
	}
	sort(edgelist.begin(),edgelist.end());
	long long mst=0;
	for(int i=0;i<edgelist.size();i++){
		pair<long long,ii> front=edgelist[i];
		if(!issameset(front.second.first,front.second.second)){
			Union(front.second.first,front.second.second);
			mst+=front.first;
		}
	}
	cout<<mst;
}

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

int N;

int main(){
    cin>>N;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==N){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
//هوالحق
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2022;

bool A[N][N];
int R[N][N];

int main(){
    int h, w;
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        int b = 0;
        for(int j = 0; j < w; j++){
                char c;
                cin >> c;
                if(c == '#'){
                    A[i][j] = true;
                    for(int k = j - b; k < j; k++)
                        R[i][k] = b;
                    b = 0;
                } else b++;
        }
        for(int k = w - b; k < w; k++) R[i][k] = b;
    }

    for(int i = 0; i < w; i++){
        int b = 0;
        for(int j = 0; j < h; j++){
                if(A[j][i]){
                    for(int k = j - b; k < j; k++)
                        R[k][i] += b;
                    b = 0;
                } else b++;
        }
        for(int k = h - b; k < h; k++) R[k][i] += b;
    }

    int r = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            r = max(r, R[i][j]);
        }
    }
    cout << r - 1;
}


Measured memory_bytes: 20224
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
int t;
int n,m;
int c[3005],w[3005];
ll dp[3005][3005];
ll _dp[3005][3005];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i) scanf("%d%d",&c[i],&w[i]);
    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<=m;++j) dp[i][j] = dp[i-1][j];
        for(int j=m;j>=c[i];--j)
        {
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-c[i]]+w[i]);
        }
    }
    for(int i=n;i>=1;--i)
    {
        for(int j=0;j<=m;++j) _dp[i][j] = _dp[i+1][j];
        for(int j=m;j>=c[i];--j)
        {
            _dp[i][j] = max(_dp[i+1][j],_dp[i+1][j-c[i]]+w[i]);
        }
    }
    ll ans = 0;
    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<m;++j)
        {
            ans = max(ans,dp[i-1][j]+w[i]+_dp[i+1][m-1-j]);
        }
    }
    printf("%lld\n",ans);
}


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

int main() {
  int N;

  std::cin >> N;

  std::vector<int> A(N);

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

  bool finished = false;
  int timesOfSwap = 0;

  while(!finished) {
    finished = true;
    for(int i = 0; i < N - 1; i++) {
      if(A[i] > A[i + 1]) {
        std::swap(A[i], A[i + 1]);
        timesOfSwap += 1;
        finished = false;
      }
    }

  }

  for(int i = 0; i < N; i++) {
    if(i == N - 1) {
      std::cout << A[i] << '\n';
    }else {
      std::cout << A[i] << ' ';
    }
  }
  std::cout << timesOfSwap << '\n';


}

Measured memory_bytes: 3108
import java.math.*;
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	final long M=(long)1e9+7;
	boolean[] isPrime=new boolean[(int)1e6+1];
	int[] cnt=new int[(int)1e6+1];
	{
		int p=0;
		Arrays.fill(isPrime, true);
		isPrime[0]=isPrime[1]=false;
		for(int i=2;i<isPrime.length;++i) {
			if(!isPrime[i])continue;
			++p;
			for(int j=2*i;j<isPrime.length;j+=i) {
				isPrime[j]=false;
			}
		}
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		long[] A=new long[N];
		long[]B=new long[N];
		for(int i=0;i<N;++i) {
			A[i]=sc.nextLong();
		}
		Arrays.sort(A);
		B=Arrays.copyOf(A, A.length);
		for(int i=0;i<A.length;++i) {
			for(int div=2;div*div<=A[i];++div) {
				int sz=0;
				while(A[i]%div==0) {
					A[i]/=div;
					++sz;
				}
				cnt[div]=Math.max(cnt[div], sz);
			}
			if(A[i]>1)cnt[(int)A[i]]=Math.max(cnt[(int)A[i]], 1);;
		}
		long lcm=1;
		for(int i=2;i<cnt.length;++i) {
			if(cnt[i]>0)
			lcm=lcm*pow(i,cnt[i])%M;
		}
		long ans=lcm;
		long coe=0;
		for(int i=0;i<A.length;++i) {
			coe+=inv(B[i]);
			coe%=M;
		}
		ans=ans*coe%M;
		System.out.println(ans);
	}
	
	long inv(long a) {
		return pow(a,M-2);
	}
	
	long pow(long a,long n) {
		long r=1;
		for(;n>0;n>>=1,a=a*a%M)if(n%2==1)r=r*a%M;
		return r;
	}
	
	long lcm(long a,long b) {
		return a/gcd(a,b)*b%M;
	}
	
	long gcd(long a,long b) {
		return a==0?b:gcd(b%a,a);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 37628
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long


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

    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++) cin >> a.at(i);

    vector<int> b(n);

    b.at((n-1)/2) = a.at(0);
    for(int i = 1;i < n;i ++){
        if(i % 2 == 1){
            b.at((n-1)/2 + (i+1)/2) = a.at(i);
        }
        else{
            b.at((n-1)/2 - i/2) = a.at(i);
        }
    }

    if(n % 2 == 0) reverse(b.begin(),b.end());
    for(int i = 0;i < n;i ++){
        cout << b.at(i) << " ";
    }
    cout << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  if (n >= 2 * k - 1) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f3f;
const int maxn = 1e5+500;
ll T,n,m;
int main() {
    string s;
    cin>>n>>s;
    if(n<3200)
    	cout<<"red\n";
    else 
    	cout<<s<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n, i;
  	cin >> n >> i;
  	cout << n - i + 1 << endl;
    return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == c || a + c == b || b + c == a)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
Q = int(input())
K = [int(k) for k in input().split()]

def Counter(S, k):
    Total = 0
    count = [0, 0, 0] #D, M, DMの数
    for i in range(N):
        
        if S[i] == "D": count[0] += 1
        elif S[i] == "M": 
            count[1] += + 1
            count[2] += count[0]
        elif S[i] == "C":
            Total += count[2]
        if i >= k - 1:
            if S[i-k+1] == "D":
                count[0] -= 1
                count[2] -= count[1]
            elif S[i-k+1] == "M":
                count[1] -= 1
    return Total

for i in range(Q):
    print(Counter(S, K[i]))

Measured memory_bytes: 58348
import collections

def main():

    N, H = map(int, input().split())
    sword = []
    for _ in range(N):
        a, b = map(int, input().split())
        sword.append([a, b])
    sword.sort(key = lambda x: x[1], reverse= True)

    count = float('inf')

    # the case with just throwing the swords
    damage = 0
    count1 = 0
    for a, b in sword:
        damage += b
        count1 += 1
        if damage >= H:
            break
    if damage >= H:
        count = min(count, count1)

    # the case with some swinging swords
    sword.sort(key = lambda x: x[0], reverse = True)
    a0, b0 = sword.pop(0) # best sword for swinging
    sword.sort(key = lambda x: x[1], reverse = True)

    damage = 0
    count2 = 0
    i = 0
    while i < len(sword) and sword[i][1] > a0:
        damage += sword[i][1]
        count2 += 1
        i += 1
    if damage + b0 < H:
        c = (H - damage - b0) // a0
        if (H - damage - b0) % a0 != 0:
            c += 1
        count2 += c + 1
        count = min(count, count2)

    return count


if __name__ == '__main__':
    print(main())

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

int main(void){

    string S; cin>>S;
    sort(S.begin(), S.end());
    if(S[0]==S[1] && S[2]==S[3] && S[1]!=S[2]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

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

using namespace std;

const long long MOD=(long long)1000000007;
int dp[101][4][4][4];

int main(){

	int n; 
	cin>>n;
	dp[0][3][3][3] = 1;
	
	map<char, int> m;
	int a=0,g=1,c=2,t=3;

	for (int pos=0;pos<n; pos++) {
		for (int i=0;i<4;i++) {
			for (int j=0;j<4;j++) {
				for (int k=0;k<4;k++) {
					if (dp[pos][i][j][k]==0)
					    continue;
					for (int x=0;x<4;x++) {
						if (j == a && k == g && x == c)
						    continue;
						if (j == a && k == c && x == g)
						    continue;
						if (j == g && k == a && x == c)
						    continue;
						if (i == a && k == g && x == c)
						    continue;
						if (i == a && j == g && x == c)
						    continue;
						dp[pos + 1][j][k][x] += dp[pos][i][j][k];
						dp[pos + 1][j][k][x] %= MOD;
					}
				}
			}
		}
	}

	int ans = 0;

	for (int i=0;i<4;i++) {
		for (int j=0;j<4;j++) {
			for (int k=0;k<4;k++) {
				ans+=dp[n][i][j][k];
				ans%=MOD;
			}
		}
	}

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

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

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var s = input.ReadLine();
                
        StringBuilder bu = new StringBuilder(s);

        for(int i=0; i<s.Length; i++) {
            int c = bu[i] - 'A';
            c = (c + n) % 26;
            c = ('A' + c);
            bu[i] = (char)c;
        }

        return bu;
    }
}

Measured memory_bytes: 13184
#include<stdio.h>

int gcd(int x, int y);

int main() {
	int n;
	int x, y, z;
	scanf("%d", &n);
	int t, s, q;
	s = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				t = gcd(i, j);
				q = gcd(t, k);

				s += q;
			}
		}
	}
	printf("%d", s);

}
int gcd(int x, int y) {
	int t;
	t = x >= y ? x : y;
	if (x != t) {

		t = x;
		x = y;
		y = t;
	}

	while (x % y) {
		t = x % y;
		x = y;
		y = t;

	}
	return y;
}


Measured memory_bytes: 1732
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *v1, const void *v2)
{
	return(*((int *)v1) - *((int *)v2));//昇順ソート
}
int main()
{
	int N, M,sum=0,i;
	int X[100000];
	scanf("%d %d", &N, &M);
	for (i = 0;i < M;i++)scanf("%d", &X[i]);
	qsort(X,M,sizeof(int),cmp);/*昇順ソート(配列名, 配列の数, 
	配列一つのバイト数, 比較関数)*/
	int d[100000];//x間の距離
	for (i = 0;i < M - 1;i++)d[i] = X[i+1] - X[i];
	qsort(d, M, sizeof(int), cmp);//昇順ソート
	for (i = 0;i <= ((M - 1) - (N - 1));i++)sum += d[i];
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 1396
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	ll cost;
	edge(int _t, ll _cost) : t(_t)
		, cost(_cost) {
	}
};


void Solve() {
	int n;
	cin >> n;
	ll h[100010];
	for (size_t i = 0; i < n; i++)
	{
		cin >> h[i];
	}
	ll dp[100010];
	dp[0] = 0;
	dp[1] = abs(h[1] -h[0]);
	for (size_t i = 2; i < n; i++)
	{
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}
	cout << dp[n - 1] << endl;
}
int main() {
	Solve();
	return 0;
}



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


int main(){
	int W,a,b;
	cin >> W >> a >> b;
	
	if(a<b){
		if(b-(a+W)<=0){
			cout << 0 << endl;
		}else{
			cout << b-(a+W) << endl;
		}
	}else{
		if(a-(b+W)<=0){
			cout << 0 << endl;
		}else{
			cout << a-(b+W) << endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K;
	cin >> N >> K;

	vector<Int> h(N+K);
	for (Int i = 0; i < N; i++) {
		cin >> h[i];
	}

	vector<Int> dp(N + K, INF);
	dp[0] = 0;

	for (Int i = 0; i < N-1; i++) {
		for (Int k = 1; k <= K; k++) {
			dp[i + k] = min(dp[i + k], dp[i] + abs(h[i + k] - h[i]));
		}
	}

	cout << dp[N - 1] << "\n";
}

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

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

	// cout<< solve() <<endl;
	// printf("%f\n",solve());
	// cout<<cout<<setprecision(10)<<ans<<endl;
	// solve();
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(int argc, const char * argv[]) {

    int r,c;
    scanf("%d %d",&r,&c);
    
    int hyo[r][c];
    
    int i,j;
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&hyo[i][j]);
        }
    }
    
    int rowSum = 0;
    int colSum[101] = {0};
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            printf("%d ",hyo[i][j]);
            rowSum+=hyo[i][j];
            colSum[j]+=hyo[i][j];
        }
        printf("%d\n",rowSum);
        colSum[c]+=rowSum;
        rowSum = 0;
    }
    
    for(j=0;j<=c;j++){
        printf("%d",colSum[j]);
        if(j==c){
            printf("\n");
        }
        else{
            printf(" ");
        }
    }
    
    return 0;
}

Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i64 = read();
    let m: i64 = read();

    let mut a: Vec<i64> = vec![];

    for i in 0..m {
        a.push(read());
    }
    a.sort();

    let mut b: Vec<i64> = vec![];
    for i in 1..a.len() {
        b.push(a[i] - a[i - 1])
    }

    b.sort();
    if m - n <= 0 {
        println!("{}", 0);
        return;
    }
    b.split_off((m - n) as usize);
    println!("{}", b.iter().sum::<i64>());
}


Measured memory_bytes: 8444
#include <iostream>
#include <cstdio>
#define NO return puts("NO")*0
using namespace std;

string s;
int main() {
	cin >> s;
	int i=0;
	if(s[i]=='A') i++;
	if(s[i]=='K') i++; else NO;
	if(s[i]=='I') i++; else NO;
	if(s[i]=='H') i++; else NO;
	if(s[i]=='A') i++;
	if(s[i]=='B') i++; else NO;
	if(s[i]=='A') i++;
	if(s[i]=='R') i++; else NO;
	if(s[i]=='A') i++;
	puts(i==s.size() ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int inf=1<<29;
class people{
public:
    int num;
    int a,b,c;
    people():num(-1){
        
    }
    int mymin(int k){
        if(num==-1)return min(min(min(a+b,a+c),b+c),inf);
        if(num==-2)return 1;
        if(num<k)return inf;
        else return 0;
    }
};
people line[150000];
vector<int> stock;
bool search(int k,int N){
    int ip=0,ap=(int)stock.size();
    while(ip!=ap){
        int np=(ip+ap)>>1;
        if(k>stock[np]){
            ip=np+1;
        }else{
            ap=np;
        }
    }
    int maxsize=(int)stock.size()-ip;
    int back=N;
    for(int i=0;back-i>2;i+=3){
        line[back].a=line[i].mymin(k);
        line[back].b=line[i+1].mymin(k);
        line[back].c=line[i+2].mymin(k);
        ++back;
    }
    return line[back-1].mymin(k)<=maxsize;
}
int main(){
    int N,M;
    cin>>N>>M;
    int d,p;
    for(int i=0;i<N;++i){
        line[i].num=-2;
    }
    for(int i=0;i<M;++i){
        cin>>d>>p;
        line[p-1].num=d;
    }
    for(int i=0,nmax=N-M;i<nmax;++i){
        cin>>d;
        stock.push_back(d);
    }
    sort(stock.begin(),stock.end());
    int ip=1,ap=1000000001;
    while(ip!=ap){
        int np=(ip+ap)>>1;
        if(search(np,N)){
            ip=np+1;
        }else{
            ap=np;
        }
    }
    cout<<ip-1<<endl;
    return 0;
}

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

void Main() {
	int n,max_num = -1000001, min_num = 1000001, tmp;
	long long sum = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		sum += tmp;
		max_num = max(max_num, tmp);
		min_num = min(min_num, tmp);
	}
	printf("%d %d %lld\n", min_num, max_num, sum);
}

int main() {
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 3220