akhauriyash/Code-Regression huggingface dataset:
//import java.lang.Math;
import java.util.*;
import java.util.Map.Entry;
//import java.util.ListIterator;
//import java.util.Iterator;
//import java.util.LinkedList;
 
public class Main{
	
	
	
	@SuppressWarnings({ "rawtypes", "unchecked", "resource" })
	public static void main(String[] arg) {
		
		
		TreeMap<String,Integer> map=new TreeMap();
		 Scanner sc = new Scanner(System.in);
	        int cnt = sc.nextInt();
	        for (int i = 0; i < cnt; i++) {
	        
	        int cmt=sc.nextInt();
	        
	        switch(cmt){
	        
	        
	        case 0:
	        	  String str=sc.next();
	              int num=sc.nextInt();
	        
	               map.put(str,num);
	            break;
	        case 1:
	        	str=sc.next();
	        	if(map.containsKey(str))System.out.println(map.get(str));
	        	else System.out.println(0);
	        	break;
	        case 2:
	        	str=sc.next();
	        	map.remove(str);
	        	break;
	        case 3:
	        	String l=sc.next();
	        	String r=sc.next();
	        	NavigableMap<String,Integer> in =map.subMap(l, true, r, true);
	       Iterator<NavigableMap.Entry<String, Integer>> it=in.entrySet().iterator();
	       while(it.hasNext()){
	    	   NavigableMap.Entry<String, Integer> yes=it.next();
	    	   System.out.println(yes.getKey()+" "+yes.getValue());
	       }
	        }
	        
	        
	        }
		
		
		
		
}
	
	
}


Measured memory_bytes: 206412
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    s: String,
  }
  
  use std::iter;
  let x: String = iter::repeat("x").take(s.len()).collect();
  println!("{}", x);
}

Measured memory_bytes: 4476
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int MOD = 1e9 + 7;

typedef long long ll;
typedef pair<int, int> P;

int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];

	ll ans = MOD;
	for (int j = -100; j <= 100; j++) {
		ll sum = 0;
		for (int i = 1; i <= n; i++) {
			sum += (a[i] - j) * (a[i] - j);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

odd = 0
count_two = 0
count_four = 0
for i in range(n):
    if A[i] % 4 == 0:
        count_four += 1
    elif A[i] % 2 == 0:
        count_two += 1
    else:
        odd += 1

ans = 'No'
if count_two == 0:
    if count_four + 1 >= odd:
        ans = 'Yes'
else:
    if count_four >= odd:
        ans = 'Yes'

print(ans)

Measured memory_bytes: 14252
#include<iostream>
using namespace std;
int main(void){
    int n,i,j;
    char Csuit;
    int Isuit;
    int num;
    int cards[4][13];
    for (i=0;i<4;i++){
        for (j=0;j<13;j++){
            cards[i][j]=0;
        }
    }
    
    cin >> n;  //スペード、ハート、クラブ、ダイヤ
    for(i=0;i<n;i++){
        cin >> Csuit >> num;
        switch (Csuit){
            case 'S':
                Isuit=0;
                break;
            case 'H':
                Isuit=1;
                break;
            case 'C':
                Isuit=2;
                break;
            case 'D':
                Isuit=3;
                break;
        }
        cards[Isuit][num-1]=1;
    }
    
   for (j=0;j<13;j++){
       if (cards[0][j]==0){
           cout << "S " << (j+1) << endl;
       }
   }
   for (j=0;j<13;j++){
       if (cards[1][j]==0){
           cout << "H " << (j+1) << endl;
       }
   }
   for (j=0;j<13;j++){
       if (cards[2][j]==0){
           cout << "C " << (j+1) << endl;
       }
   }
   for (j=0;j<13;j++){
       if (cards[3][j]==0){
           cout << "D " << (j+1) << endl;
       }
   }
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool check(long long n, long long d)
{
    while(n%d==0) n/=d;
    n=n%d;
    return n==1;
}

main()
{
    long long n,m,ans; cin>>n>>m;
    n=n%m;
    cout << min(n, m-n) << "\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1E9 + 7;
const int INF = 1 << 29;

struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n / 2);
  x *= x;
  if (n % 2 == 1) x *= 2;
  return x;
}

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i, a) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  mint ans;
  ans = f(n) - 1;
  ans -= choose(n, a);
  ans -= choose(n, b);
  cout << ans.x << endl;
  return 0;
}

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

namespace Bounding
{
    class Program
    {
        /// <summary>
        ///   The main entry point for the application
        /// </summary>
        [STAThread]
        public static void Main(string[] args)
        {
            // var a = int.Parse(Console.ReadLine()); //標準入力
            string[] str1 = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            var n = int.Parse(str1[0]);  //数値で受け取りたい場合は変換する
            var x = int.Parse(str1[1]);
            // Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
            // Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
            string[] str2 = Console.ReadLine().Split(' ');
            int[] l = new int[n+1];
            for(int i = 1; i <= n; i++) {
                l[i] = int.Parse(str2[i-1]);
            }

            int count = 0;
            int[] d = new int[n+2];
            d[1] = 0;
            for(int i = 2; i <= n+1; i++) {
                d[i] = d[i-1] + l[i-1];
            }
            for(int i = 1; i <= n+1; i++, count++) {
                if(d[i] > x) {
                    break;
                }
            }
            Console.Write(count);
        }
    }
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]) {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	while (true)
	{
		c -= b;
		if (c <= 0)
		{
			cout << "Yes" << endl;
			return 0;
		}a -= d;
		if (a<=0)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    ans = 0
    A = [0 for _ in range(N)]
    for i in range(N-1):
        C, S, F = map(int, input().split())
        for j in range(i+1):
            a = A[j]
            if a <= S:
                A[j] += C + (S - a)
            elif a % F == 0:
                A[j] += C
            else:
                A[j] += C + F - (a % F)
    for a in A:
        print(a)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3192
#include<bits/stdc++.h>
// Begin Header {{{
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const double PI = acos(-1);
using namespace std;
using Graph = vector<vector<lli>>;
using P = pair<int, int>;
// }}} End Header

int main(){
	int a, b;
	cin >> a >> b;
	cout << (a-1)*(b-1) << endl;
	return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::vector<long long> A, std::vector<long long> B){
    vector<int> a(N+1), b(N+1);
    rep(i,0,N) {
        a[A[i]]++;
        b[B[i]]++;
    }
    rep(i,1,N+1) {
        if (a[i] + b[i] > N) {
            cout << "No" << endl;
            return;
        }
    }
    int x = -INT_MAX;
    int aSum = 0, bSum = 0;
    rep(i,1,N+1) {
        aSum += a[i];
        bSum += b[i-1];
        x = max<int>(x, aSum - bSum);
    }
    cout << "Yes" << endl;
    assert(x>=0 && x <= N);
    rep(i,0,N) {
        cout << B[(i+N-x)%N] << (i == N-1 ? "\n" : " ");
    }
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 8032
#include <bits/stdc++.h>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 1000000+5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(ll &f){
	f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
struct node{
	ll l,r;
	ll id;
};
node g[DMAX];
ll a[DMAX];
ll tag[DMAX];
ll n,m;
ll tree[DMAX];
ll ans[DMAX]; 
ll lowbit(ll p){
	return p&(-p);
}
bool Cmp(const node &p,const node &q){
	return p.r<q.r;
}
void add(ll pos,ll val){
	for(;pos<=n;pos+=lowbit(pos)){
		tree[pos]+=val;
	}
}
ll query(ll pos){
	ll add=0;
	for(;pos;pos-=lowbit(pos)){
		add+=tree[pos];
	}
	return add;
}
int main(){
	read(n),read(m);
	for(ll i=1;i<=n;i++){
		read(a[i]);
	}
	for(ll i=1;i<=m;i++){
		read(g[i].l),read(g[i].r);
		g[i].id=i;
	}
	sort(g+1,g+m+1,Cmp);
	ll st=1;
	for(ll i=1;i<=m;i++){
		for(ll j=st;j<=g[i].r;j++){
			if(tag[a[j]]){
				add(tag[a[j]],-1);
			}
			add(j,1);
			tag[a[j]]=j;
		}
		st=g[i].r+1;
		ans[g[i].id]=query(g[i].r)-query(g[i].l-1);
	}
	for(ll i=1;i<=m;i++){
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 31180
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

public class Main{

    public static void main(String[] args){
        //START

        Scanner sc=new Scanner(System.in);
        //int N=sc.nextInt();
        String S=sc.next();

        String[] strArray=S.split("");

        int i=0;

        String str="P";

        for(i=0;i<S.length();i++){
            if((strArray[i].equals(str))){
                System.out.print("P");
            }else{
                System.out.print("D");
            }
        }

        //END
    }
}



Measured memory_bytes: 68232
N, M = map(int, input().split())
H = tuple(map(int, input().split()))
T = [set() for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    T[a-1].add(H[b-1])
    T[b-1].add(H[a-1])

count = 0
for i, t in enumerate(T):
    if not t:
        count+=1
        continue
    else:
        h = H[i]
        if h > max(t):
            count += 1

print(count)

Measured memory_bytes: 38892
N = int(raw_input())
line = raw_input()
A = line.strip().split(" ")
A2 = line.strip().split(" ")
for i in range(0, N):
    min_j = i
    for j in range(i, N):
        if int(A2[j][1:]) < int(A2[min_j][1:]):
            min_j = j
    A2[i], A2[min_j] = A2[min_j], A2[i]
select = " ".join(A2)
flag = True
while flag:
    flag = False
    for j in range(N-1, 0, -1):
        if int(A[j][1:]) < int(A[j-1][1:]):
            A[j], A[j-1] = A[j-1], A[j]
            flag = True
bubble = " ".join(A)
print bubble
print "Stable"
print select
if bubble == select:
    print "Stable"
else:
    print "Not stable"

Measured memory_bytes: 6372
#include <stdio.h>


int main(void) {
    long long K, H, N, L;
	long long diff;
	scanf("%lld %lld %lld %lld", &H, &N, &L, &K);
		if (K%2 ==1) diff = N-H;
	else diff = H-N;
/*

	for(int i=1; i<=K; i++) {
		if (i==0) break;
		if(H==N&& N==L) break;
		temp_H=H;
		temp_N=N;
		temp_L=L;
		H=temp_N+temp_L;
		N=temp_H+temp_L;
		L=temp_H+temp_N;
		if(H-N>=1000000000000000000) break;
	}
	
	*/
	if(diff>=1000000000000000000) puts("Unfair");
	printf("%lld", diff);
	
return(0);
}


Measured memory_bytes: 128
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
typedef long long ll;
int main() {
	int N, D;
	cin >> N >> D;
	vector<int> X(N), Y(N);
	for (int i = 0; i < N; ++ i) cin >> X[i] >> Y[i];

	vector<pair<int,int>> a;
	for (int i = 0; i < N; ++ i) {
		a.push_back({X[i], i});
		a.push_back({Y[i], i+N});
	}
	sort(a.begin(), a.end());

	two_sat ts(2*N);
	for (int i = 0; i < N; ++ i) ts.add_clause(i, true, i+N, true);
	for (int i = 0; i < 2*N; ++ i) {
		for (int j = i+1; j < 2*N && a[j].first - a[i].first < D; ++ j) {
			ts.add_clause(a[i].second, false, a[j].second, false);
		}
	}
	if (ts.satisfiable()) {
		cout << "Yes" << endl;
		auto b = ts.answer();
		for (int i = 0; i < N; ++ i) {
			cout << (b[i] ? X[i] : Y[i]) << endl;
		}
	} else {
		cout << "No" << endl;
	}
}


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

using namespace std;

#define MOD 998244353

int n, at;
long long inv[1000005], sum[1000005], ans;
vector<int> v[1000005];
vector<pair<int, int>> vv;
int np[1000005];

void add(long long& a, long long b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
}

long long po(long long b, int p) {
	long long re = 1;
	while (p) {
		if (p % 2)
			re = re * b % MOD;
		b = b * b % MOD;
		p /= 2;
	}
	return re;
}

void go(int a, int b) {
	if (a == vv.size())
		v[at].push_back(b);
	else
		for (int i = 0; i <= vv[a].second; i++) {
			go(a + 1, b);
			b *= vv[a].first;
		}
}

int main() {
	for (int i = 2; i <= 1000; i++)
		if (!np[i])
			for (int j = i * i; j <= 1000000; j += i)
				np[j] = i;
	for (int i = 2; i <= 1000000; i++) {
		if (!np[i])
			np[i] = i;
		vv.clear();
		int tmp = i;
		while (tmp != 1) {
			vv.emplace_back(np[tmp], 0);
			while (tmp % vv.back().first == 0) {
				tmp /= vv.back().first;
				vv.back().second++;
			}
		}
		at = i;
		go(0, 1);
		// v[i].pop_back();
	}
	v[1].push_back(1);
	for (int i = 1; i <= 1000000; i++) {
		inv[i] += po(i, MOD - 2);
		for (int j : v[i])
			if (j != i)
				inv[i] += MOD - inv[j];
		inv[i] %= MOD;
	}
	// for (int i = 1; i <= 10; i++) {for (int j : v[i]) printf("%d ", j); puts("");}
	scanf("%d", &n);
	while (n--) {
		int tmp;
		scanf("%d", &tmp);
		for (int i : v[tmp]) {
			// printf("tmp=%d i=%d sum[%d]=%lld inv[%d]=%lld\n", tmp, i, i, sum[i], i, inv[i]);
			ans = (ans + sum[i] * inv[i] % MOD * tmp) % MOD;
			add(sum[i], tmp);
		}
	//printf("%lld\n", ans);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 126080
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <string>
#include <map>
#include <list>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define LargeNum 1000000007

int main(){
    int N, M, count = 0;
    cin >> N >> M;
    int H[N+1], A, B, yoi[N+1];
    rep(i, N) yoi[i+1] = 1;
    rep(i, N) cin >> H[i+1];
    rep(i, M) {
        cin >> A >> B;
        if (H[A] > H[B]) yoi[B] = 0;
        else if (H[A] < H[B]) yoi[A] = 0;
        else {
            yoi[A] = 0;
            yoi[B] = 0;
        }
    }
    rep(i, N) if (yoi[i+1] == 1) count++;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 4412
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  int n;
  cin >> n;
  cout << (int) pow(n, 3) << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,k,x,y;
    scanf("%d%d%d%d",&n,&k,&x,&y);
    int ans=0;
    if (n>=k){
        ans+=k*x;
        n-=k;
    }
    else {
        ans+=n*x;
        n=0;
    }
    if (n>0){
        ans+=n*y;
    }
    printf("%d\n",ans);

}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int d[51];
P p[51];
int gg[51];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&d[i]);
		p[i]=P(abs(12-d[i]),d[i]);
	}
	p[n]=P(12,0);
	sort(p,p+n+1);
	deque<int> que;
	int s=1;
	for(int i=0;i<=n;i++){
		if(s==1){
			gg[i]=min(p[i].second,24-p[i].second);
		}else{
			gg[i]=max(p[i].second,24-p[i].second);
		}
		s=1-s;
	}
	sort(gg,gg+n+1);
	int diff=24;
	for(int i=0;i<n;i++){
		diff=min(diff,gg[i+1]-gg[i]);
	}
	diff=min(diff,24-gg[n]+gg[0]);
	printf("%d\n",diff);
	return 0;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b; cin >> a >> b;

  int ans = 0;
  if(a-b>=2){
    ans+=a;
    a--;
    ans+=a;
  }
  else if(a-b==0 || abs(a-b)==1){
    ans = a+b;
  }
  else if(b-a>=2){
    ans += b;
    b--;
    ans+=b;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3608
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;
use num::*;


fn main() {
    input! {
        a:usize,
        b:[isize;a],
        c:usize,
        d:[(usize,isize);c],
    }
    let e:isize=b.iter().sum();
    for i in 0..c {
        println!("{}",e-b[d[i].0-1]+d[i].1)
    }
}

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

#define int long long
#define uint unsigned int
#define pii pair<int, int>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin()), ((c).end())

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int N, A[5];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  int num = INF;
  REP(i, 5) {
    cin >> A[i];
    CHMIN(num, A[i]);
  }
  int sum = N + 4*num;
  cout << (sum + num - 1) / num << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s[1] == 'R'){
    if(s[0] == 'R' && s[2] == 'S'){
      cout << "2\n";
      return 0;
    }
    if(s[0] == 'S' && s[2] == 'R'){
      cout << "2\n";
      return 0;
    }if(s[0] == 'S' && s[2] == 'S'){
      cout << "1\n";
      return 0;
    }
    if(s[0] == 'R' && s[2] == 'R'){
      cout << "3\n";
      return 0;
    }
  }
  if(s[0] == 'R' || s[2] == 'R'){
    cout <<"1\n";
    return 0;
  }
  cout << "0\n";
}

Measured memory_bytes: 3620
from collections import Counter
from math import factorial
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

c = Counter(s)
counter = 0


def kza(a, b):
    return (factorial(a) / factorial(a-b)) / factorial(b)


for i in c.values():
    if i == 1:
        continue
    counter += kza(i, 2)


print(int(counter))













Measured memory_bytes: 68696
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
struct PalindromicTree {
    struct node {
        map<char,int> next;
        int len, sufflink,num,first;
    };
    string S;
    vector<node> V;
    int n,s; // num,suff
	
    bool add(int pos) {
        char ch=S[pos];
        int c=s, cl=0;
        while(1) {
            cl=V[c].len;
            if(pos-1-cl>=0 && S[pos-1-cl]==ch) break;
            c=V[c].sufflink;
        }
		
        if(V[c].next.count(ch)) {
            s = V[c].next[ch];
            return false;
        }
		
        s=++n;
        V[n].len=V[c].len+2;
        V[n].first=pos;
        V[c].next[ch]=n;
		
        if(V[n].len==1) { // even length
            V[n].sufflink=2;
            V[n].num=1;
            return true;
        }
		
        while(1) {
            c=V[c].sufflink;
            cl=V[c].len;
            if(pos-1-cl>=0 && S[pos-1-cl]==ch) {
                V[n].sufflink=V[c].next[ch];
                break;
            }
        }
        V[n].num=1+V[V[n].sufflink].num;
        return true;
    }
	
    void init(string S) {
        this->S=S;
        V.clear();
        V.resize(S.size()+10);
		
        n=s=2;
        V[1].first=V[2].first=-1;
        V[1].len=-1;
        V[2].len=0;
        V[1].sufflink=V[2].sufflink=1;
    }
};

int main(){
    string S;
    cin>>S;
    LL n=S.size();
    LL ret=n*(n+1)/2;
    vector<LL> cnt(26,0);
    REP(i,n)cnt[S[i]-'a']++;
    REP(i,26)ret-=cnt[i]*(cnt[i]+1)/2;
     cout<<ret+1<<endl;
    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define sz(a) (int)(a.size())
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long
#define problem ""

template<typename A, typename B, typename C>
struct triple{
    A X;
    B Y;
    C Z;
    triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0){
    return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b){
    if (a.X != b.X)
        return a.X < b.X;
    if (a.Y != b.Y)
        return a.Y < b.Y;
    return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p){
    ofs << "( " << p.F << " , " << p.S << " )";
    return ofs;
}
template<typename T>
void print(T a){
    for (auto i : a)
        cout << i << ' ';
    cout << '\n';
}
template<typename T>
T max(T a, T b, T c){
    return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c){
    return min(a, min(b, c));
}
template<typename T, typename D>
D min(T a){
    return *min_element(all(a));
}
template<typename T, typename D>
D max(T a){
    return *max_element(all(a));
}
struct custom_hash{
    static uint64_t splitmix64(uint64_t x){
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void solve(){
    int n; cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i++)
        for(int j = i; j <= n; j+= i) ans += j;
    
    cout << ans << '\n';
};
signed main()
{
    if(0){
        freopen(problem".in", "r", stdin);
        freopen(problem".out", "w", stdout);
    }
    srand(time(NULL));
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int t = 1; //cin >> t;
    rng(t) solve();
}


Measured memory_bytes: 3624
#include <stdio.h>

int main() {

int a, b, c, d;

scanf("%d %d %d %d\n",&a, &b, &c, &d);

while ( 1 ) {
  c = c - b;

  if (c<=0) {
    printf("Yes\n");
    break;
  }

   a = a - d;
   if (a<=0) {
     printf("No\n" );
     break;
   }


}

  return 0;
}


Measured memory_bytes: 1664
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    points = [int(readline()) for _ in range(n)]
    points.sort()
    ans = sum(points)

    if ans % 10 == 0:
        flag = False
        for point in points:
            if point % 10 != 0:
                ans -= point
                flag = True
                break
        if not flag:
            ans = 0

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61920
local UnionFind={}

UnionFind.create=function(self,n)
    self.par={}
    self.rank={}
    self.size={}
    for i=1,n do
        self.par[i]=i
        self.rank[i]=1
        self.size[i]=1
    end
end

UnionFind.getroot=function(self,x)
    local nx=x
    while self.par[x]~=x do
        x=self.par[x]
    end
    while self.par[nx]~=x do
        self.par[nx],nx=x,self.par[nx]
    end
    return x
end

UnionFind.same=function(self,x,y)
    return self:getroot(x)==self:getroot(y)
end

UnionFind.unite=function(self,x,y)
    x=self:getroot(x)
    y=self:getroot(y)
    if x==y then
        return
    end
    if self.rank[x]>self.rank[y] then
        x,y=y,x
    elseif self.rank[x]==self.rank[y] then
        self.rank[x]=self.rank[x]+1
    end
    self.par[x]=y
    self.size[y]=self.size[y]+self.size[x]
end

UnionFind.getsize=function(self,x)
    return self.size[self:getroot(x)]
end

UnionFind.new=function(self,n)
    local obj={}
    setmetatable(obj,{__index=UnionFind})
    obj:create(n)
    return obj
end

----------

local n,m=io.read("n","n")
local a,b={},{}
for i=1,m do
    a[i],b[i]=io.read("n","n")
end

local t={[m]=n*(n-1)//2}
local uf=UnionFind:new(n)
for i=m-1,1,-1 do
    if uf:same(a[i+1],b[i+1]) then
        t[i]=t[i+1]
    else
        local ua=uf:getsize(a[i+1])
        local ub=uf:getsize(b[i+1])
        uf:unite(a[i+1],b[i+1])
        t[i]=t[i+1]-ua*ub
    end
end

for i=1,m do
    print(t[i])
end

Measured memory_bytes: 20524
#include <iostream>
#include <string>
#include <list>

std::string getFizzBuzzString(int n)
{
    std::string fizzBuzzString;
    
    if(n % 15 == 0)
    {
        fizzBuzzString = "FizzBuzz";
    }
    else if(n % 5 == 0)
    {
        fizzBuzzString = "Buzz";
    }
    else if(n % 3 == 0)
    {
        fizzBuzzString = "Fizz";
    }
    else
    {
        fizzBuzzString = std::to_string(n);
    }
    
    return fizzBuzzString;
}

void fizzBuzzGame(int num_of_players, int num_of_remarks)
{
    std::list<int> player_list;

	/* ?????¬???????????????????????¨???????????¬?????????????????????push?????? */
    for(int i = 1; i <= num_of_players; i++ )
    {
        player_list.push_back(i);
    }

	/* fizz buzz ?????????????§? */
    for(int i = 1; i <= num_of_remarks; i++)
    {
        /* ??\??????????????? */
        std::string remarks;
        std::cin >> remarks;

        /* ?????¬??????????????????????????£?????????????£???°??? */
        if(player_list.size() <= 1)
        {
            continue;
        }

        /* ?????¬?????????????????? */
        int player = *(player_list.begin());
        player_list.pop_front();

        /* ?????????????????? */
        std::string expect_remarks = getFizzBuzzString(i);
        
        /* ??£??????????¨??????????????????°????????????push???????????? */
        /* ????????£????????????????????????push??????????????¨??§??¢??±???????????¨????????? */
        if(remarks == expect_remarks)
        {
            player_list.push_back(player);
        }
    }
    
    /* ???????????????????????£??????????????¬????????????????????????????????? */
    player_list.sort();
	for(auto itr = player_list.begin(); itr != player_list.end(); ++itr)
	{
		if(itr != player_list.begin())
		{
			std::cout << " ";
		}
		std::cout << *itr;
	}
    std::cout << std::endl;
	
	return;
}

void volume2_0221()
{
    int num_of_players;
    int num_of_remarks;
    
    for(;;)
    {
        /* ?????¬???????????°??¨????¨??????°??????????????? */
        std::cin >> num_of_players >> num_of_remarks;
        
        /* ?????¬???????????°???????¨??????°??±??? 0 ????????\????????? */
        if( num_of_players == 0 && num_of_remarks == 0 )
        {
            break;
        }
        
    	/* FizzBuzzGame ?????? */
    	fizzBuzzGame(num_of_players, num_of_remarks);
    }

    return;
}

int main(void)
{
    volume2_0221();
    
    return 0;
}

Measured memory_bytes: 3156
n=int(input())
def make_divisors(n):  
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  # divisors.sort()
  return divisors
l=sorted(make_divisors(n))
print(len(str(l[len(l)//2])))


Measured memory_bytes: 38640
a, b, c = map(int, input().split())
k = int(input())
ans = "No"

while k > 0:
  if not b > a:
    b *= 2
    k -= 1
  elif not c > b:
    c *= 2
    k -= 1
  else:
    ans = "Yes"
    break

if c > b > a:
  ans = "Yes"

print(ans)


Measured memory_bytes: 9180
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll maxi=-1e18;
	maxi=max(maxi,b*d);
	maxi=max(maxi,b*c);
	maxi=max(maxi,a*c);
	maxi=max(maxi,a*d);
	cout<<maxi;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3648
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

vector<ll> vs;

void dfs(const vector<string> &s, int l, int r, int p, ll L) {
  if (l == r) {
    vs.push_back(L);
    return;
  }
  if (int(s[l].size()) <= p) return;
  int i;
  for (i = l; i < r; ++i) {
    if (s[i][p] == '1') break;
  }
  dfs(s, l, i, p + 1, L - 1);
  dfs(s, i, r, p + 1, L - 1);
}

void solve(ll N, ll L, vector<string> s) {
  sort(ALL(s));
  dfs(s, 0, N, 0, L + 1);
  ll res = 0;
  for (ll i: vs) {
    // cout << i << endl;
    ll bit = (i & -i);
    res = res ^ bit;
  }
  if (res == 0) cout << "Bob" << endl;
  else cout << "Alice" << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	ll L;
	scanf("%lld", &N);
	vector<string> s(N-1+1);
	scanf("%lld", &L);
	for (int i = 0 ; i <= N-1 ; i++) {
    cin >> s[i];
	}
	solve(N, L, s);
	return 0;
}


Measured memory_bytes: 7800
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

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

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll A,B;
  cin>>A>>B;

  cout<<A/gcd(A,B)*B<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  int64_t minn = 1e12+1;
  for(int i=1; i<=1000000; i++){
    if(n%i==0){
      int64_t num = n/i;
      minn = min(minn, num+i);
    }
  }
  cout << minn - 2 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# DPL_1_G: Combinatorial - Knapsack Problem with Limitations

from functools import lru_cache
from heapq import heappop, heappush


@lru_cache(maxsize=None)
def index(i, j, sep):
    return (j-i) // sep


def max_value(total_weight, items):
    vs1 = [0] * (total_weight+1)
    vs2 = vs1[:]
    for item in items:
        v, w, m = item
        for i in range(w):
            heap = []
            for j in range(i, total_weight+1, w):
                heappush(heap, (-vs1[j] + index(i, j, w)*v, j))
                x, k = heap[0]
                while index(k, j, w) > m:
                    heappop(heap)
                    x, k = heap[0]
                vs2[j] = vs1[k] + index(k, j, w)*v

        vs1, vs2 = vs2, vs1

    return vs1[total_weight]


def run():
    n, t = [int(i) for i in input().split()]
    vs = []

    for _ in range(n):
        v, w, m = [int(i) for i in input().split()]
        vs.append((v, w, m))

    print(max_value(t, vs))


if __name__ == '__main__':
    run()



Measured memory_bytes: 253516
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {
    long long x, y, z;
	int ans = 0;

	cin >> x >> y >> z;

	for (int i = 1; i <= x; i++) {
		if (y * i + z * (i + 1) <= x) {
			ans = i;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
	ll C[n + 1][k + 1]; 
	ll i, j; 


	for (i = 0; i <= n; i++) 
	{ 
		for (j = 0; j <= min(i, k); j++) 
		{ 
			
			if (j == 0 || j == i) 
				C[i][j] = 1; 

			else
				C[i][j] = (C[i - 1][j - 1] + 
										C[i - 1][j])%MOD; 
		} 
	} 

	return C[n][k]; 
}
bool compare(const string &a , const string&b){
	
}
 
void solve()
{
    int n ; 
    cin>>n ;
    int dp[n] ;
    int h[n] ;
    rep(i , n)cin>>h[i] ;
    dp[0] = 0 ;
    dp[1] = abs(h[1] - h[0]) ;
    repu(i , 2, n-1){
    	dp[i] = min(abs(h[i] - h[i-2])+dp[i-2] , abs(h[i] - h[i-1])+dp[i-1]) ;
    }
    cout<<dp[n-1]<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 4448
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
	bool IsPrime[1000010] = {};
	for (int i = 2; i < 999999; i++)
	{ 
		IsPrime[i] = true;
	}
	for (int i = 2; i*i <= 999999; i++)
	{
		if (IsPrime[i])
		{
			for (int j = i * 2; j <= 999999; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}

	int n;
	while (cin >> n)
	{
		int ans = 0;
		for (int i = 0; i <= n; i++)
		{
			if (IsPrime[i]) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=(1e9)+7;
const int maxn=(2e5)+10;
int n,a[maxn],k;
ll mi[maxn],tmp,ans;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(a[i]);
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	mi[0]=1;
	for (int i=1;i<=n;i++) mi[i]=mi[i-1]*2%mod;
	for (int i=1;i<=n;i++) {
		k=i-1;
		tmp=(mi[k]+(ll)k*mi[k-1])%mod;
		tmp=tmp*a[i]%mod*mi[n-i]%mod;
		ans=(ans+tmp)%mod;
	}
	printf("%lld\n",ans*mi[n]%mod);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

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

int main() {
  int d;
  cin >> d;
  vector<int> c(26), last(26);
  for (int i = 0; i < 26; i++) {
    cin >> c.at(i);
  }
  vector s(d, vector(26, 0));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }
  for (int i = 0; i < d; i++) {
    int vmax = -1e9, tmax = 0;
    for (int t = 0; t < 26; t++) {
      int v = 0;
      last.at(t) = i + 1;
      v += s.at(i).at(t);
      for (int j = 0; j < 26; j++) {
        v -= c.at(j) * (i + 1 - last.at(j));
      }
      if (v > vmax) {
        vmax = v;
        tmax = t;
      }
    }
    cout << tmax + 1 << endl;
  }
}


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

int a, b, c, d;

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

Measured memory_bytes: 3596
#include<bits/stdc++.h>
 
#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define mp make_pair
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)
		
#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container
 
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
//#define mod (((ll)1000000000) * ((ll)1000000000))
using namespace std;
 
typedef  long long     int ll;
typedef unsigned long long int ull;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;
typedef pair < int , int > ii;
const ll mod=1e9+7;
const ll mod2=1e9+9;
const ll maxn = 2e5+5;
const ll maxn1 = 1e7+1;
const int root=1e6+5;
const long long inf = 1e18 + 18;
double pie4=3.1415926535;
vector<ll>v ;
ll a[maxn] ;	
	
int main(){
	
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	
	ll i, n, x, y ;
	
	cin >> n;
	
	for (i = 1; i <= n; i++){

		cin >> a[i] ;
		
		v.eb(a[i]);
	}
	
	sort(v.begin(), v.end());
	
	x = v[n/2-1];
	y = v[n/2] ;
	
	if(x==y){
		
		for(i = 1; i <= n; i++)
		cout << x <<endl ;
	}
	
	else{
		
		for(i = 1; i <=n; i++){
			
			if(a[i] <= x)
			cout << y <<endl ;
			
			else if(a[i] >= y)
			cout << x <<endl;
		}
	}
}
			
			 
	


Measured memory_bytes: 5488
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define prt(x) cout<<x<<endl
#define prk(x) x<<" "
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#ifndef ONLINE_JUDGE
    freopen("A.in", "r", stdin);
#endif
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(0);
}
///////////////////////////
const int N = 5 + 1e5;


int n;
LL a, b;
int main() {
    
    cin >> n;
    while(n--) {
        cin >> a >> b;
        LL m = sqrt(a * b + .1);
        LL ans = 2 * m;
        if(m * m == a * b) {
            ans -= 2;
            if(min(a, b) < m)
                ans--;
        } else {
            if(m * (m + 1) >= a * b) {ans--;}
            if(min(a, b) <= m)
                ans--;
        }
        cout << ans << endl;


    }



    return 0;
}


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

int main(){

    int N,M;
    cin >> N >> M;
    vector<int> A(N);
        int sum=0;
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
        sum += A.at(i);
    }

    int d = 0;
    for(int i = 0; i < N; i++){
        if(4*M*A.at(i) >= sum) d++;
    }

    if(d >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256