akhauriyash/Code-Regression huggingface dataset:
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

  
int main()
{
    int n;
    scf(n);
    
    if(n==1)
    cout<<"Hello World";
    
    else
    {
        int a,b;
        scf(a),scf(b);
        
        prin(a+b);
        
 
    }
 
    
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    string S;
    cin >> S;

    ll mx = 0, c = 0;
    REP(i,0,N) {
        c = (S[i] == 'I') ? c+1 : c-1;
        mx = MAX(mx,c);
    }
    PR(mx);

    return 0;
}

/*



*/

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
const int MOD(1e9 + 7), N(22);
int n, dp[1 << N], g[N];
bool p;
long long temp;
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) {
            cin >> p;
            if (p) g[i] |= (1 << j);
        }
    dp[0] = 1;
    for (int x = 1; x < (1 << n); ++x) {
        int i = __builtin_popcount(x);
        temp = 0;
        for (int y = x & g[i-1]; y; y &= y - 1)
            temp += dp[x & ~(y & -y)];
        dp[x] = temp % MOD;
    }
    cout << dp[(1 << n) - 1];
    return 0;
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_size=100000;//количество факториалов, которых посчитает прога
int n;
int main() {
	ios_base::sync_with_stdio(false);
	cin>>n;
	int x,y;
	cin>>x>>y;
	int a[100];
	int h=0,l=0,s=0;
	for(int i=0;i<n;i++){
	    cin>>a[i];
	    if(a[i]<=x)h++;
	    else if(a[i]<=y){
	        l++;
	    }
	    else{
	        s++;
	    }
	}
	cout<<min(min(h,l),s);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>

using namespace std;

#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int long long
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

int dp[100005];


double power(int a, int b){
    if (b==0)
        return 1LL;
    if(b==1)
        return a*1LL;
    if(b%2==0){
        int x = power(a, b/2);
        x=(x*x)%mod;
        return x;
    }
    else{
        int x=power(a, (b-1)/2);
        x=(x*x)%mod;
        return (x*a)%mod;
    }
}

int32_t main() 
{
    fast;
   
	int n, k;
    cin >> n >> k;
    for(int i=k; i>=1; i--){
        dp[i] = power(k/i, n);
        for(int j=2*i; j <= k; j+=i){
            dp[i] -= dp[j];
        }
    }
    int res = 0;
    for(int i = 1; i <= k; i++){
        res = (res+(dp[i]*i)%mod)%mod;
    }
    cout << res%mod;

    return 0;
}

Measured memory_bytes: 4340
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

class Main
{
    double dp[][];
    double prob[];
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int coins=sc.nextInt();
        sc.nextLine();
        Main object=new Main();
        object.prob=new double[coins];
        for(int i=0;i<coins;i++)
        {
          object.prob[i]=sc.nextDouble();
        }
        object.dp=new double[coins+1][coins+1];
        object.dp[0][0]=1;
        for(int i=1;i<=coins;i++)
        {
          for(int j=0;j<=i;j++)
          {
            if(j==0)
              object.dp[i][j]=object.dp[i-1][j]*(1-object.prob[i-1]);
            else
              object.dp[i][j]=object.dp[i-1][j-1]*object.prob[i-1]+object.dp[i-1][j]*(1-object.prob[i-1]);
          }
        }
        double res=0;
        for(int i=coins/2+1;i<=coins;i++)
        {
               res=res+object.dp[coins][i];
        }
        System.out.println(res);
        sc.close();
     }
}

Measured memory_bytes: 118328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		if(N<=999) {
			System.out.println("ABC");
		}else {
			System.out.println("ABD");
		}

	}

}


Measured memory_bytes: 23636
import sys
S = list(input())
T= list(input())

len_T = len(T)
min_count = len_T

for i in range(len(S)-len_T+1):

  temp =len_T
  for j in range(len_T):
    if(S[i+j]==T[j]):
      temp-=1
  if(temp ==0):
    print(0)
    sys.exit()
  if(temp<min_count):
    min_count=temp
    
print(min_count)
    

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

using namespace std;

typedef long long ll;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"




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

    int n;
    cin >> n; n--;
    bool poate2 = true;
    int good1 = 0, good2 = 0;
    for (int i = 0; i <= n; i++) {
        char x;
        cin >> x;
        x -= '0';
        x--;
        if (x == 1)
            poate2 = false;
        if ((i & n) == i) {
            if (x == 1)
                good1 ^= 1;
            if (x == 2)
                good2 ^= 2;
        }
    }
    if (good1)
        cout << 1 << '\n';
    else {
        if (good2 && poate2)
            cout << 2 << "\n";
        else
            cout << 0 << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(),(x).end()
#define pushb(x) push_back(x)
#define popb() pop_back()
#define makep make_pair
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv);
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v);
template<typename T> ll gcd(T a,T b);
template<typename T> ll lcm(T a,T b);
int main(){
    ll n;cin>>n;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    vector<int> ord(n);
    iota(all(ord),0);
    sort(all(ord),[&](int x,int y){
        if(b[x]==b[y])return a[x]>a[y];
        return b[x]>b[y];
    });     
    ll t=pow(10,9);
    for(auto& i:ord){
        t=min(t,b[i])-a[i];
    }
    if(t<0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
    return 0;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << ' ';
    }
    return s;
}
template<typename T> ll gcd(T a,T b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}
template<typename T> ll lcm(T a,T b){
    return a*b/gcd(a,b);
}

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

using LL = long long;

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); --(i))
#define SORT(x) sort(ALL((x)))
#define RSORT(x) sort(RALL((x)))
#define SZ(x) (int)(x).size()
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e18;

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

  int ans;
  int A, B;
  cin >> A >> B;

  ans = (A - 1) * (B - 1);

  cout << ans << '\n';

  return 0;
}

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

#define FOR(i,N) for(int i=0;i<N;i++)

using namespace std;

int main(){
	int N,K;
	long long int ans=0;
	cin>>N>>K;
	ans=K;
	FOR(i,N-1){
		ans*=(K-1);
	}
	cout<<ans;
return 0;
}

Measured memory_bytes: 256
import math


def cmb(n, k, mod):
    numerator = 1
    for i in range(k):
        numerator = (numerator * (n-i)) % mod

    denominator = 1
    for i in range(1, k+1):
        denominator = (denominator * i) % mod

    return (numerator * pow(denominator, mod-2, mod)) % mod


X, Y = map(int, input().split())
mod = 10**9 + 7
if (X + Y) % 3 != 0:
    print(0)
    exit()
else:
    n = int((2 * Y - X) / 3)
    m = int(Y - 2 * n)
    if n < 0 or m < 0:
        print(0)
        exit()
    else:
        print(cmb(m+n, n, mod))


Measured memory_bytes: 3064
#
# 10a
#
import math


def main():
    x1, y1, x2, y2 = map(float, input().split())
    ret = math.sqrt(pow(x1-x2, 2) + pow(y1-y2, 2))
    print(f"{ret: .8f}")


if __name__ == '__main__':
    main()



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


using namespace std;

int main() {
    int n;
    cin>>n;
    int br=0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x%2==0){
            if(x%3==0 || x%5==0){
                
            }else{
                br=1;
            }
        }
    }
    if(br==1){
        cout<<"DENIED";
    }else{
        cout<<"APPROVED";
    }
    
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a+b > c+d) cout << "Left";
  else if (a+b == c+d) cout << "Balanced";
  else cout << "Right";
  cout << endl;
}


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

int main(){

	long  A,B,C,K;
	scanf("%ld%ld%ld%ld",&A,&B,&C,&K);

	if(A+B>K){
		if(A<=K)printf("%ld\n",A);
		else printf("%ld\n",K);
	}
	else {
		printf("%ld\n",A+(A+B-K));
	}
		
	return 0;
}


Measured memory_bytes: 1732
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: usize,
        a: [usize; n],
    }

    let mut b = VecDeque::new();

    for i in 0..n {
        if i % 2 == 0 {
            // 1
            b.push_back(a[i])
        } else {
            // 2
            b.push_front(a[i])
        }
    }

    let ans = if (n - 1) % 2 != 0 {
        b.iter().join(" ")
    } else {
        b.iter().rev().join(" ")
    };

    println!("{}", ans)
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 9712
// https://atcoder.jp/contests/abc117/tasks/abc117_a
// +build ingore

package main

import (
	"fmt"
)

func main(){
	var t, x, ans float64
	fmt.Scanf("%f %f", &t, &x)
	ans = t / x
	fmt.Printf("%.10f\n", ans)
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <stdio.h>
    
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1e6;
const ll LINF = (ll)1e19;

int main() {  
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, C;
    cin >> N >> C;
    vector<int> d(200010,0);
    vector<vector<P>> code(30);
    REP(i, N){
        int s, t, c;
        cin >> s >> t >> c;
        c--;
        code[c].push_back(make_pair(s,t));
    }
    REP(i, C){
        sort(code[i].begin(), code[i].end());
    }
    REP(i, C){
//        cout << i << endl;
        REP(j, code[i].size()){
            //cout << code[i][j].first << "," << code[i][j].second << endl;
            int s = code[i][j].first;
            int t = code[i][j].second;
            s*=2;
            t*=2;
            //t+=2;
            if(j == 0){
                s--;
            }else if(code[i][j-1].second != code[i][j].first){
                s--;
            }else{
                //s+=2;
            }
            d[s]++;
            d[t]--;
        }
    }
    int ans = 0;
    int current = 0;
//    REP(i, 200010){
//    REP(i, 100){
//        if( d[i*2] < 0){
//            cout << i << "    ";
//        }else{
//            cout << i << "   ";
//        }
//
//    }
//    cout << endl;
    REP(i, 200010){
        current += d[i];
        ans = max(ans, current);
//        cout << i << "[";
//        printf("%02.2f", (double)(i)/2.0);
//        cout << "]" << ":" << d[i] << "," << current <<endl;
    }
//    cout << endl;
    cout << ans << endl;
    return 0;    
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main() {
    int n;
    scanf("%d", &n);
    lint x[n], y[n];
    rep(i, n) {
        scanf("%lld%lld", &x[i], &y[i]);
        lint X = x[i] + y[i], Y = x[i] - y[i];
        x[i] = X;
        y[i] = Y;
    }
    sort(x, x + n);
    sort(y, y + n);
    printf("%lld\n", max(abs(x[n - 1] - x[0]), abs(y[n - 1] - y[0])));
}

Measured memory_bytes: 6952
#include<iostream>
#include<queue>
#include<vector>

#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

const int INF = 1001001001;

int main(){
	int x, y, z; cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;

	return 0;
}

Measured memory_bytes: 256
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        x=n/i;
        ans+=i*((x)*(x+1))/2;
    }
    cout<<ans;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

int main(){
  ll N,sum=0;
  cin>>N;
  for(int i=1; i<=N; i++){
    if(!(i%3==0||i%5==0)){
      sum+=i;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3596
from fractions import gcd

A, B, C, D = map(int, input().split())

cnt = B//C -(A - 1)//C + B//D - (A - 1)//D - ((B//((C * D) // gcd(C, D))) - (A - 1)//((C * D) // gcd(C, D)))
cnt1 = B - (A - 1) -cnt

print(cnt1)

Measured memory_bytes: 5216
#include<iostream>
#define Al "Alice"
#define Bo "Borys" 
using namespace std;

// Problem https://atcoder.jp/contests/agc020/tasks/agc020_a

bool solver(int alPos,int boPos){
    bool result ;
    result = false;
    int dist;
    dist = alPos - boPos;
    if((dist%2)==0){
        result = true;
    }
    return result;
}

int main(void){
    bool answer;
    answer = true;
    int N,A,B;
    cin >> N >> A >> B;
    answer = solver(A,B);
    if(answer){
        cout << Al << endl;
    }
    else{
        cout << Bo << endl;
    }
    return 0;
}

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

template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int r;
  while(cin>>r,r){
    vector<Int> w(2),h(2),x(2),y(2);
    vector<vector<vector<Int> > > a(2);
    for(Int k=0;k<2;k++){
      cin>>w[k]>>h[k]>>x[k]>>y[k];
      x[k]--;y[k]--;
      a[k]=vector<vector<Int> >(h[k],vector<Int>(w[k]));
      for(Int i=0;i<h[k];i++)
	for(Int j=0;j<w[k];j++)
	  cin>>a[k][i][j];
    }
    auto dijkstra=[](Int h,Int w,Int y,Int x,auto &a){
      auto dp=a;
      const Int INF = 1e15;
      for(Int i=0;i<h;i++)
	for(Int j=0;j<w;j++)
	  dp[i][j]=INF;

      using T = tuple<Int, Int, Int>;
      priority_queue<T,vector<T>,greater<T> > pq;
      
      dp[y][x]=a[y][x];
      pq.emplace(dp[y][x],y,x);

      Int dy[]={0,0,1,-1};
      Int dx[]={1,-1,0,0};
      auto in=[&](Int y,Int x){return 0<=y&&y<h&&0<=x&&x<w;};
      
      while(!pq.empty()){
	Int d;
	tie(d,y,x)=pq.top();pq.pop();
	if(dp[y][x]<d) continue;
	//cout<<y<<" "<<x<<":"<<d<<endl;
	for(Int k=0;k<4;k++){
	  Int ny=y+dy[k],nx=x+dx[k];
	  if(!in(ny,nx)||dp[ny][nx]<=max(dp[y][x],a[ny][nx])) continue;
	  dp[ny][nx]=max(dp[y][x],a[ny][nx]);
	  pq.emplace(dp[ny][nx],ny,nx);
	}
      }
      
      vector<Int> v(h*w);
      for(Int i=0;i<h;i++)
	for(Int j=0;j<w;j++)
	  v[i*w+j]=dp[i][j];
      sort(v.begin(),v.end());
      return v;
    };
    auto v=dijkstra(h[0],w[0],y[0],x[0],a[0]);
    auto u=dijkstra(h[1],w[1],y[1],x[1],a[1]);
    v.emplace(v.begin(),0);
    u.emplace(u.begin(),0);
    
    Int n=v.size(),m=u.size();
    Int ans=1e15;
    for(Int i=0;i<n;i++){
      Int j=r-i;
      if(0<=j&&j<m) chmin(ans,v[i]+u[j]);
    }
    for(Int i=0;i<m;i++){
      Int j=r-i;
      if(0<=j&&j<n) chmin(ans,v[j]+u[i]);
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 13672
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  map<int,int>A;
  
  for(int i=0;i<N;i++){
    int a;cin>>a;
    A[a]++;
  }
  
  long long res=0;
  
  for(auto p:A){
    auto key=p.first;
    auto value=p.second;
    
    if(key>value){
      res+=value;
      //cout<<"delete "<<key<<endl;
    }
    else{
      res+=value-key;
      //cout<<"reduce "<<key<<" by "<<value-key<<endl;
    }
  }
  
  cout<<res;
}

Measured memory_bytes: 4736
n,k = gets.chomp.split(" ").map(&:to_i)
x = gets.chomp.split(" ").map(&:to_i)
ans = 10**19
for i in 0..n-k
  temp = x[i+k-1]-x[i]
  temp += x[i+k-1].abs < x[i].abs ? x[i+k-1].abs : x[i].abs
  ans = temp if ans > temp
end
puts ans

Measured memory_bytes: 9476
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  int s = 0;
  for (int i = 0; i < 3; i++) {
	  int a;
	  cin >> a;
	  s += a;
	}
  if (s >= 22) {
	  cout << "bust\n";
	} else {
	  cout << "win\n";
	}
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn cost(i: usize, p: &Vec<usize>, x: &Vec<usize>) -> Option<(usize, usize)> {
    let childs: Vec<_> = (0..p.len())
        .filter(|&k| p[k] == i + 1)
        .map(|x| x + 1)
        .collect();
    if childs.is_empty() {
        return Some((x[i], 0));
    }

    let costs: Vec<_> = childs.iter().map(|&c| cost(c, p, x)).collect();
    if costs.iter().any(|c| c.is_none()) {
        None
    } else {
        let costs: Vec<_> = costs.iter().map(|o| o.unwrap()).collect();
        let total = costs.iter().map(|t| t.0 + t.1).sum::<usize>();

        let mut memo: HashSet<usize> = HashSet::new();
        memo.insert(0);
        for &(a, b) in &costs {
            let mut next = HashSet::new();
            for c in &memo {
                if c + a <= x[i] {
                    next.insert(c + a);
                }

                if c + b <= x[i] {
                    next.insert(c + b);
                }
            }
            memo = next;
        }

        memo.iter().max().map(|c| (x[i], total - c))
    }

}

fn main() {
    let n: usize = util::get();
    let p: Vec<usize> = util::gets();
    let x: Vec<usize> = util::gets();

    if cost(0, &p, &x).is_some() {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}


Measured memory_bytes: 4604
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<vector>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int N=300005;
/*int f[N],use[N],a[N],n,mn=1e9,mx=0;
inline void check()
{
	register int i,j,mx1=0,mx2=0;
	for(i=1;i<=n;i++)
	{
		f[i]=1;
		for(j=1;j<i;j++)
			if(a[j]<a[i])	f[i]=max(f[i],f[j]+1);
		mx1=max(mx1,f[i]);
	}
	for(i=1;i<=n;i++)
	{
		f[i]=1;
		for(j=1;j<i;j++)
			if(a[j]>a[i])	f[i]=max(f[i],f[j]+1);
		mx2=max(mx2,f[i]);
	}
	if(mx1+mx2<n/2+2||mx1+mx2>n+1)
	{
//		for(i=1;i<=n;i++)	printf("%d ",a[i]);
//		printf("mx1=%d mx2=%d sum=%d\n",mx1,mx2,mx1+mx2);
	}
	mn=min(mn,mx1+mx2);
	mx=max(mx,mx1+mx2);
}
void dfs(int x)
{
	if(x==n+1)	check();
	else
	{
		for(int i=1;i<=n;i++)	if(!use[i])
		{
			use[i]=1;a[x]=i;
			dfs(x+1);
			use[i]=0;
		}
	}
}*/
vector<int> v[N];
inline void gg()
{
	puts("-1");
	exit(0);
}
int main()
{
/*	n=ri();
	dfs(1);
	printf("mn=%d mx=%d\n",mn,mx);*/
	int n=ri(),a=ri(),b=ri(),j,i,d=n/a,now=n-a+1,tot=d;
	for(i=1;i<=d;i++,now-=a)
		for(j=1;j<=a;j++)
			v[i].push_back(now+j-1);
	if(n%a)
	{
		tot++;
		for(j=1;j<=n%a;j++)
			v[tot].push_back(j);
//		reverse(v[tot].begin(),v[tot].end());
	}
	if(b<tot||a+b>n+1)	gg();b-=tot;
/*	for(i=1;i<=tot;i++)
		for(j=0;j<v[i].size();j++)
			printf("i=%d %d\n",i,v[i][j]);*/
	for(i=tot;i>1;b-=v[i].size()-1,i--)
	{
		if(b<v[i].size()-1)	break;
		reverse(v[i].begin(),v[i].end());
	}
	if(b)
	{
		if(v[i].begin()+b+1>v[i].end())	gg();
		reverse(v[i].begin(),v[i].begin()+b+1);
	}
	for(i=1;i<=tot;i++)
		for(j=0;j<v[i].size();j++)
			printf("%d ",v[i][j]);
	puts("");
	return 0;
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define endl '\n'
#define ff first
#define ss second
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define RAGE ios::sync_with_stdio(0); cin.tie(0);

using namespace std;

const ll inf = 1e18 + 42;

const ll M = 998244353;

ll power(ll x, ll y) {
    if (y == 0) return 1;
    if (y & 1) return (x * power(x, y - 1));
    ll t = power(x, y / 2);
    return (t * t);
}

const ll MAX = 1e5 + 5;

void solve()
{
	ll k; cin >> k;
	ll a, b; cin >> a >> b;
	for(ll i = a; i <= b; i++)
	{
		if(i % k == 0)
		{
			cout << "OK" << endl;
			return;
		}
	}
	cout << "NG" << endl;
}


int main()
{
	RAGE
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	ll t = 1;
	// cin >> t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(a-1); i>=(b); i--)
#define qrep(i, q) for(auto i : q)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define lowbit(x) x&(-x)
#define all(x) x.begin(),x.end()
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 55;
const int logn = (log(maxn)/log(2))+5;
const int inf = 0x3f3f3f3f;
const ld eps = 1e-9;
int a[maxn];
int main()
{
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	int n;
	cin >> n;
	rep(i, 1, n+1) cin >> a[i];
	rep(i, 1, n+1){
		if(a[i] != i) {
			swap(a[i], a[a[i]]);
			break;
		}
	}
	rep(i, 2, n+1){
		if(a[i] < a[i-1]) return cout << "NO" << endl, 0;
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0] * (N + 1)
        self.b = 1 << N.bit_length() - 1

    # a - 1の場所にwを追加する
    def add(self, a, w):
        x = a
        while(x <= self.N):
            self.bit[x] += w
            x += x & -x

    def get(self, a):
        ret, x = 0, a - 1
        while(x > 0):
            ret += self.bit[x]
            x -= x & -x
        return ret

    # 区間[l, r - 2]についての合計を求める
    def cum(self, l, r):
        return self.get(r) - self.get(l)

    def lowerbound(self,w):
        if w <= 0:
            return 0
        x = 0
        k = self.b
        while k > 0:
            if x + k <= self.N and self.bit[x + k] < w:
                w -= self.bit[x + k]
                x += k
            k //= 2
        return x + 1

# BITは前から置いていく
# そのためのクエリソート
N, Q = getNM()
C = getList()
que = [getList() for i in range(Q)]

# que[r]に[l(始点), i(queでのインデックス)]をappend
que_d = defaultdict(list)
for i in range(Q):
    que_d[que[i][1]].append([que[i][0], i])
ans = [0] * Q
# 色iのうち最も右側にあるものはどこにあるか
dic = defaultdict(lambda: -float('inf'))
bit = BIT(N)

for i in range(N):
    # 既に場所が登録されているならそれを削除する
    if dic[C[i]] >= 1:
        bit.add(dic[C[i]], -1)
    # 新しい「良い球」の場所を登録
    # 1-indexで!!
    dic[C[i]] = i + 1
    bit.add(dic[C[i]], 1)

    # queryに答える
    if len(que_d[i + 1]) > 0:
        # 終点rがi + 1であるqueryに答える
        for l, j in que_d[i + 1]:
            # cum(l, r):区間[l - 1, r - 2](0-index)についての合計を求める
            # lは1-indexだがi(r - 1)は0 - index
            ans[j] = bit.cum(l, i + 2)

for i in ans:
    print(i)

Measured memory_bytes: 340120
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int a,b;
	cin>>a>>b;
    float sum;
    bool check=false;

    if(b<10){
        sum=10*a+b;
    }
    else if(9<b&&b<100){
        sum=100*a+b;
    }
    else{
        sum=1000*a+b;
    }
    
    for(int i=0;i<1000;i++){
        if(sum==pow(i,2)){
            check=true;
            break;
        }
    }
    
    cout<<(check?"Yes":"No")<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int a,b;
	cin >> a >> b;
	int sum = a;
	int ans = 1;
	while(sum<b) {
		sum += a-1;
		ans++;
	}
	if(b == 1) cout << 0 << endl;
	else cout << ans << endl;
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i ++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i --)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {T a; K b;};

int main( void ){
	initialize();
	ll N;
	cin >> N;
	cout << (N+1)/2 << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
	cin.tie( 0 );
	ios::sync_with_stdio( false );
}


Measured memory_bytes: 256
import scala.util.control.Breaks
object Main extends App {
  val read = scala.io.StdIn.readLine()
  val NxArray =  read.split(" ").map(_.toInt).toVector
  var sum = 0
  var count = 1
  val read2 = scala.io.StdIn.readLine()
  val LArray =  read2.split(" ").map(_.toInt).toVector

  val b = new Breaks
  b.breakable{
    LArray.foreach { l =>
      if (sum + l > NxArray(1)) {
        b.break()
      } else {
        count = count + 1
        sum = sum + l
      }

    }
  }
  println(count)

}

Measured memory_bytes: 25544
package main

import (
	"fmt"
	"sort"
)

type S struct {
	k, v int
}

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	D := make(map[int]int)
	for i := 0; i < N; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		D[a] += b
	}
	Ss := make([]S, len(D))
	idx := 0
	for k, v := range D {
		Ss[idx] = S{k: k, v: v}
		idx++
	}
	sort.Slice(Ss, func(i, j int) bool { return Ss[i].k < Ss[j].k })
	for i := 1; i < len(Ss); i++ {
		Ss[i].v += Ss[i-1].v
	}
	for _, s := range Ss {
		if K <= s.v {
			fmt.Println(s.k)
			return
		}
	}
	panic("あわわあわわわ、わぁ")
}


Measured memory_bytes: 9800
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector <long long int, long long int> 
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

ll add(ll x, ll y) {ll res=x+y; return(res>=MOD?res-MOD:res);}
ll mul(ll x, ll y) {ll res=x*y; return(res>=MOD?res%MOD:res);}
ll sub(ll x, ll y) {ll res=x-y; return(res<0?res+MOD:res);}
ll lcm(ll x, ll y) {ll res=(x*y)/__gcd(x,y); return res;}
ll power(ll x, ll y) {ll res=1; x%=MOD; while(y){if(y&1)res=mul(res,x); y>>=1; x=mul(x,x);} return res;}
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

int main()
{
	boost;
	int n, h, w;
	cin >> h >> w >> n;
	int x = (n % h ? n / h + 1 : n / h);
	int y = (n % w ? n / w + 1 : n / w);
	cout << min(x, y);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x;
		int max = 0;
		int min = 0;
		long sum = 0;
		int n = scan.nextInt();//??´??°??\???n???
		for (int i = 0; i < n; i++) { //i???n???????°??????????????????°?????????
			x = scan.nextInt();//n????????????????????§??????????°??????\???
			if (i == 0) { //?????????com???????????£??\
				min = max = x;
			}
			if (min > x) { //????°????
				min = x;
			}
			if (max < x) { //?????§???
				max = x;
			}
			sum += x; //????¨????
		}
		System.out.println(min + " " + max + " " + sum);
	}
}

Measured memory_bytes: 41616
#include<bits/stdc++.h>
#define mod 998244353
#define maxn 200005
using namespace std;
int n,k;
long long a[maxn],sum[maxn];
int l[15],r[15];
long long getsum(int pos)
{
	if (pos<0) return 0;
	return sum[pos];
}
int main()
{
	cin>>n>>k;
	for (int i=1;i<=k;i++)
		cin>>l[i]>>r[i];
	a[1]=sum[1]=1;
	for (int i=2;i<=n;i++)
	{
		for (int j=1;j<=k;j++)
		{
			a[i]+=(getsum(i-l[j])-getsum(i-r[j]-1));
			a[i]=(a[i]%mod+mod)%mod;
		}
		sum[i]=((sum[i-1]+a[i])%mod+mod)%mod;
	}
	cout<<a[n]<<endl;
}

Measured memory_bytes: 6752
using System;
using System.Collections.Generic;
public class ABC130A {
    public static void Main() {
        int X, A, ans = 0;
        string[] str = System.Console.ReadLine().Split(' ');
        X = int.Parse(str[0]);
        A = int.Parse(str[1]);

        if (X < A) ans = 0;
        else ans = 10;
        System.Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include<iostream>

using namespace std;

int main()
{
	int n,i;
	double a,b=0;
	int ans;
	
	cin >> n ;
	for(i=0;i<n;i++)
	{
		cin >> a ;
		b+=a/n;
	}
	ans=b;
	cout << ans << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll);

int N;
vector<pii> v;

signed main(){
    cin >> N;
    if(N % 2 == 0){
        for(int i = 1; i <= N; i++){
            for(int j = i + 1; j <= N; j++){
                if(i + j == N + 1)continue;
                v.push_back({i, j});
            }
        }
        cout << (int)v.size() << endl;
        for(int i = 0; i < (int)v.size(); i++){
            cout << v[i].first << " " << v[i].second << endl;
        }
    }
    else {
        for(int i = 1; i <= N; i++){
            for(int j = i + 1; j <= N; j++){
                if(i + j == N)continue;
                v.push_back({i, j});
            }
        }
        cout << (int)v.size() << endl;
        for(int i = 0; i < (int)v.size(); i++){
            cout << v[i].first << " " << v[i].second << endl;
        }
    }


    return 0;
}

Measured memory_bytes: 512
def main():
    num = int(input())
    data = [input() for i in range(num)]

    if len(data) != len(set(data)):
        print('No')
    else:
        flg = 1
        for i in range(num - 1):
            if data[i + 1][0] != data[i][-1]:
                flg = 0
                break

        if flg:
            print('Yes')
        else:
            print('No')




if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
//const long long int MOD = 1000003;
//const int MOD = 998244353;
const long long int MOD = 998244353;

int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	cout << N + M + K - max({ N,M,K }) << endl;
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))

dp = [10**9+1] * N
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i-1]))
    dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i-2]))

print(dp[-1])


Measured memory_bytes: 20568
from collections import deque

N, K = map(int, input().split())
table = list(map(int, input().split()))
jnum = K - sum(1 for i in table if i >= 0)
num_mins = sum(1 for i in table if i < 0)
q_plus = deque(sorted([i for i in table if i >= 0], reverse=True))
q_mins = deque(sorted([-i for i in table if i < 0], reverse=True))
s_plus = []
s_mins = []
total = 1


# if jnum < 0 or jnum % 2 == 0:
if (K % 2 == 1 and N == num_mins) or (N == K and num_mins % 2 == 1):
    for i in range(K):
        if not q_plus:
            total = -total * q_mins.pop() % (10 ** 9 + 7)
        elif not q_mins:
            total = total * q_plus.pop() % (10 ** 9 + 7)
        elif q_plus[-1] > q_mins[-1]:
            total = -total * q_mins.pop() % (10 ** 9 + 7)
        else:
            total = total * q_plus.pop() % (10 ** 9 + 7)
    total = total % (10 ** 9 + 7)
else:
    for i in range(K):
        if not q_plus:
            s_mins.append(q_mins.popleft())
        elif not q_mins:
            s_plus.append(q_plus.popleft())
        elif q_plus[0] > q_mins[0]:
            s_plus.append(q_plus.popleft())
        else:
            s_mins.append(q_mins.popleft())
    if len(s_mins) % 2 == 1:
        if not q_plus:
            s_plus[-1] = q_mins[0]
        elif not q_mins or not s_plus:
            s_mins[-1] = q_plus[0]
        elif q_mins[0] * s_mins[-1] > q_plus[0] * s_plus[-1]:
            s_plus[-1] = q_mins[0]
        else:
            s_mins[-1] = q_plus[0]
    s_plus.extend(s_mins)
    for j in s_plus:
        total = total * j % (10 ** 9 + 7)


print(total)

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

dp = [float("inf")]*(n+2)

dp[0] = 0

for i in range(n-1):
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]))
    if i < n-2:
        dp[i+2] = min(dp[i+2] , dp[i] + abs(h[i] - h[i+2]))

print(dp[n-1])

Measured memory_bytes: 13980
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    vector<int> A;
    int ans = 0;
    int N;
    
    cin >> N;
    
    for ( int i = 0; i < N; i++ ) {
        int a;
        cin >> a;
        A.push_back(a);
        ans+=a;
    }
    
    if ( ans%10 ) { 
        cout << ans << endl;
        return 0;
    }
    
    sort( A.begin(), A.end() );
    
    for ( auto& a : A ) {
        if ( a%10 ) {
            cout << ans - a << endl;
            return 0;
        }
    }
    
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

use std::cmp::{min, max};

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let n = sc.read();
        let mut x: u64 = sc.read();
        let mut y: u64 = sc.read();
        for _ in 1..n {
            let a: u64 = sc.read();
            let b: u64 = sc.read();
            // ak:bk, ak>=x, bk>=y, minimize k
            let k = max((x + a - 1) / a, (y + b - 1) / b);
            x = a * k;
            y = b * k;
        }
        println!("{}", x + y);
    }
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;	

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define nl cout<<"\n"
#define MOD(x) ((x%P)+P)%P
#define vec(v) loop(i,0,v.size()) cout<<v[i]<<" "; nl
const int N = 100005;
const ll P = 1000000007;
const double eps = 1e-6;

int main()
{
	fastio();

	int n; cin>>n;
	vector<ll> v(n+1,0);
	for(int i=1; i<=n; i++)
	{
		cin>>v[i];
		v[i] += v[i-1];
	}
	
	ll dp[n+1][n+1] = {};
	
	for(int len=2; len<=n; len++)
	{
		for(int i=0; i<n-len+1; i++)
		{
			dp[i][i+len-1] = 1e18;
			ll sum = v[i+len]-v[i];
			for(int j=i; j<i+len-1; j++)
				dp[i][i+len-1] = min(dp[i][i+len-1], dp[i][j]+dp[j+1][i+len-1]+sum);
		}
	}

	cout<<dp[0][n-1],nl;
	//cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

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

#define int long long
//typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {

    int m1, d1, m2, d2;
    cin >> m1 >> d1 >>m2>>d2;
    
    if(m1!=m2) cout << 1 << endl;
    else cout << 0 << endl;
    
    
}



Measured memory_bytes: 256