akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[100001];
	int size;
} max_heap;

void push(data x, max_heap* h)
{
	int i = h->size;
	data tmp;
	h->obj[(h->size)++] = x;
	while (1) {
		if (i == 0) break;
		else if (h->obj[i].key > h->obj[(i-1)/2].key) {
			tmp = h->obj[(i-1)/2];
			h->obj[(i-1)/2] = h->obj[i];
			h->obj[i] = tmp;
			i = (i - 1) / 2;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 0, j;
	data output = h->obj[0], tmp;
	h->obj[0] = h->obj[--(h->size)];
	while (1) {
		if (i * 2 + 1 >= h->size) break;
		else if (i * 2 + 2 >= h->size) j = i * 2 + 1;
		else if (h->obj[i*2+1].key > h->obj[i*2+2].key) j = i * 2 + 1;
		else j = i * 2 + 2;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
		} else break;
	}
	return output;
}

void BIT_update(long long BIT[], int n, int i, long long k)
{
	while (i <= n) {
		if (BIT[i] > k) BIT[i] = k;
		i += (i & -i);
	}
}

long long BIT_min(long long BIT[], int r)
{
	long long min = BIT[r];
	while (r > 0) {
		if (BIT[r] < min) min = BIT[r];
		r -= (r & -r);
	}
	return min;
}

int main()
{
	int i, N, M, L[100001], R[100001], C[100001];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) scanf("%d %d %d", &(L[i]), &(R[i]), &(C[i]));
	
	data d;
	max_heap h;
	h.size = 0;
	for (i = 1; i <= M; i++) {
		d.key = R[i];
		d.id = i;
		push(d, &h);
	}
	
	const long long sup = (long long)1 << 60;
	long long min, BIT[100001];
	for (i = 1; i <= N; i++) BIT[i] = sup;
	BIT_update(BIT, N, N, 0);
	while (h.size > 0) {
		d = pop(&h);
		min = BIT_min(BIT, R[d.id]);
		if (BIT_min(BIT, L[d.id]) > min + C[d.id]) BIT_update(BIT, N, L[d.id], min + C[d.id]);
	}

	if (BIT_min(BIT, 1) < sup) printf("%lld\n", BIT_min(BIT, 1));
	else printf("-1\n");
	fflush(stdout);
	return 0;
}

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

ans,cnt,mini=[],0,float('inf')
for a in A:
  if abs(a)!=a: cnt+=1
  ans.append(abs(a))
  mini=min(mini,abs(a))
if cnt%2==0:
  print(sum(ans))
else:
  print(sum(ans)-(mini*2))

Measured memory_bytes: 14224
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int i=0 ; i<b ; i++)scanf("%d",&a[i])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	char a;
	int b[26];
	iniarr(b,26);
	while(scanf("%c",&a)!=EOF)
	{
		forin(j,0,26)
		{
			if(a==97+j || a==65+j)
			{
				b[j]++;
				break;
			}
		}
	}
	forin(i,0,26)
	{
		printf("%c : %d\n",'a'+i,b[i]);
	}
	
	return 0;
}

Measured memory_bytes: 3204
ans = set()
def f(x):
    if len(x) <= 10:
        ans.add(int(x))
        if int(x[-1]) == 0:
            f(x + "1")
            f(x + x[-1])
        elif int(x[-1]) == 9:
            f(x + "8")
            f(x + x[-1])
        else:
            u = str(int(x[-1]) + 1)
            d = str(int(x[-1]) - 1)
            f(x + u)
            f(x + d)
            f(x + x[-1])
for i in range(1,10):
    f(str(i))
ans = list(ans)
ans.sort()
#print(len(ans))
k = int(input())
print(ans[k-1])

Measured memory_bytes: 20888
S = input()

end = len(S)
half = int(end/2)

for i in range(0,half):
    if S[i] is not S[half-1-i]:
        print("No")
        exit()
        
S1 = S[0:half]
S2 = S[half+1:end]

if S1 == S2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import bisect
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A)
B = sorted(B)
C = sorted(C)


def my_func(A, B, C):
    acc_a = [0]*N
    acc_c = [0]*N

    i_a = 0
    i_c = N-1
    for i in range(N):
        b = B[i]
        while i_a < N and A[i_a] < b:
            acc_a[i] += 1
            i_a += 1

    for i in reversed(range(N)):
        b = B[i]
        while i_c >= 0 and C[i_c] > b:
            acc_c[i] += 1
            i_c -= 1

    acc_a = list(accumulate(acc_a))
    acc_c = list(accumulate(acc_c[::-1]))
    acc_c = acc_c[::-1]

    ans = 0
    for a, c in zip(acc_a, acc_c):
        ans += a*c


def bisect_func(A, B, C):
    acc_a = [0]*N
    acc_c = [0]*N
    for i in range(N):
        acc_a[i] = bisect.bisect_left(A, B[i])
        acc_c[i] = N-bisect.bisect_right(C, B[i])

    ans = 0
    for a, c in zip(acc_a, acc_c):
        ans += a*c
    return ans


print(bisect_func(A, B, C))


Measured memory_bytes: 108644
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int asd[12345678];
signed main() {
	int n, d, a, cnt = 0, ans = 0; cin >> n >> d >> a;
	queue<int> v, cost; vector<vector<int>> x(n, vector<int>(2));
	for (int h = 0; h < n; h++) {
		cin >> x[h][0] >> x[h][1];
	}
	sort(x.begin(), x.end());
	for (int h = 0; h < n; h++) {
		while (true) {
			if (v.empty()) { break; }
			if (v.front() < x[h][0]) { cnt -= cost.front(); v.pop(); cost.pop(); }
			else { break; }
		}
		x[h][1] -= cnt;
		if (x[h][1] > 0) {
			ans += (x[h][1] + a - 1) / a;
			v.push(x[h][0] + d + d); cost.push((x[h][1] + a - 1) / a * a);
			cnt += (x[h][1] + a - 1) / a * a;
			//cout << h << ' ' << ans << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(void) {
  int A, B;
  cin >> A >> B;
  int ans = -1001;

  if (ans < A + B) {
    ans = A + B;
  }

  if (ans < A - B) {
    ans = A - B;
  }

  if (ans < A * B) {
    ans = A * B;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
try:
    n = int(input().strip())
    spot = [int(i) for i in input().strip().split(" ")]
    spot.insert(0,0)
    spot.append(0)
    max=0
    for m in range(1,len(spot)):
        max+=abs(spot[m-1] - spot[m])
    for i in range(1,n+1):
        sub1=abs(spot[i-1] - spot[i])
        sub2=abs(spot[i] - spot[i+1])
        add1=abs(spot[i-1] - spot[i+1])
        print(max-sub1-sub2+add1)
except EOFError:
    pass

Measured memory_bytes: 14048
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

#define check cout<<"-------"<<endl
#define debug(x) cout<<x<<endl;
#define loop(i,x,n) for(int i = x; i < n; i++)
#define lop(i,n) repi(i,0,n)
#define fix(x) cout<<fixed<<setprecision(x)

#define R (M_PI / 3)

class Coodinate{
public:
    double x;
    double y;
    
    void print() {
        cout<<x<<' '<<y<<endl;
        return;
    }
};

void kochCurve(int, Coodinate, Coodinate);

int main() {
    fix(8);
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    
    Coodinate s, e;
    s.x = 0;
    s.y = 0;
    e.x = 100;
    e.y = 0;

    s.print();
    kochCurve(n, s, e);
    e.print();
    
    return 0;
}

void kochCurve(int n, Coodinate l, Coodinate r) {
    if(n == 0) return;
    Coodinate a, b, c;
    a.x = l.x + (r.x - l.x) / 3;
    a.y = l.y + (r.y - l.y) / 3;
    c.x = r.x - (r.x - l.x) / 3;
    c.y = r.y - (r.y - l.y) / 3;
    b.x = (c.x - a.x) * cos(R) - (c.y - a.y) * sin(R) + a.x;
    b.y = (c.x - a.x) * sin(R) + (c.y - a.y) * cos(R) + a.y;
    
    
    kochCurve(n-1, l, a);
    a.print();
    kochCurve(n-1,a, b);
    b.print();
    kochCurve(n-1, b, c);
    c.print();
    kochCurve(n-1, c, r);
}



Measured memory_bytes: 3308
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

ll dp[3005][3005], color[3005][3005];
int a[3005];
ll f(int n, int l, int r) {
   if (color[l][r]) return dp[l][r];
   color[l][r] = 1;
   if (l == r) return dp[l][r] = a[l];
   if (n % 2)
      dp[l][r] = min(a[l] - f(n + 1, l + 1, r), a[r] - f(n + 1, l, r - 1));
   return dp[l][r] = max(a[l] - f(n + 1, l + 1, r), a[r] - f(n + 1, l, r - 1));
}
int main() {
   int n;
   cin >> n;
   rep(i, 0, n) cin >> a[i];
   ll ans = f(0, 0, n - 1);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 140032
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

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


Measured memory_bytes: 5580
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }
    
}

fn main(){
    let line: Vec<i32> = read_as_vec();

    let (a, b) = (line[0], line[1]);

    if a == b{
        println!("{}", a+b);
    }else{
        println!("{}", cmp::max(a,b)*2-1);
    }
    
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) {
    int x;
    cin >> x;
    ++a[x-1];
  }
  sort(all(a)); // a: frequencies in increasing order.

  vector<int> s(N+1); // s[i]: sum of [0, i). s[0] = 0.
  rep(i, N) {
    s[i+1] = s[i] + a[i];
  }

  ll ans = N, i = N;
  for (int k = 1; k <= N; ++k) {
    // We want to find the boundary of ok and ng.
    while (1) {
      bool ok = [&](int c) {
        while (i > 0 && a[i-1] >= c) { --i; }
        int sum = c*(N-i) + s[i]; // (N-1)-(i-1) = N-i
        return sum >= c*k;
      }(ans);
      if (ok) { break; }
      --ans;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3200
#include <cstdio>
#include <cstring>
#define MAXN 4010
#define LL long long

const LL P=1000000007;

int n,k;
LL f[MAXN][MAXN],c[MAXN][MAXN],g[MAXN];

void update(LL &x,LL y){ x=(x+y)%P; }

void pre_gao(){
	for(int i=0;i<MAXN;i++){
		c[i][0]=1;
		for(int j=1;j<=i;j++)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%P;
	}
}

LL gay(int x,int y){
	return c[x+y-1][y];
}

LL gao(){
	f[1][1]=1;
	for(int i=2;i<=k;i++){
		for(int j=1;j<i;j++)
			update(f[i][j+1],f[i-1][j]);
		LL temp=0;
		for(int j=i-1;j>=1;j--){
			update(temp,f[i-1][j]);
			update(f[i][j],temp);
		}
		g[i-1]=temp;
	}
	g[0]=1;
	LL ans=g[k-1];
	for(int i=1;i<=k-1;i++){
		int j=k-1-i;
		if(n-2-j>=i){
			LL temp=c[n-2-j][i];
			if(!j) update(ans,temp);
			else{
				for(int l=1;l<=j;l++)
					update(ans,temp*f[j][l]%P*gay(l+1,i));
			}
		}
	}
	for(int i=1;i<n-k;i++) ans=ans*2%P;
	return ans;
}

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	scanf("%d%d",&n,&k);
	pre_gao();
	printf("%lld\n",gao());
}


Measured memory_bytes: 186880
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int W,H;
int field[20][20];
int field2[21][21];
int res;
const int dy[]={-1,0,0,1};
const int dx[]={0,-1,1,0};
bool used[101][101];
int lim;

void fillField(int cy,int cx,int oldc,int newc,bool &ok,bool flag){
  if(!flag)field[cy][cx]=newc;
  else field2[cy][cx]=newc;
  used[cy][cx]=true;
  for(int i=0;i<4;i++){
    int ny=cy+dy[i];
    int nx=cx+dx[i];
    if(ny>=0&&nx>=0&&ny<H&&nx<W&&!used[ny][nx]){
      if(!flag){
	if(field[ny][nx]==oldc)
	  fillField(ny,nx,oldc,newc,ok,flag);
	else if(field[ny][nx]==newc)
	  ok=true;
      }
      else{
	if(field2[ny][nx]==oldc)
	  fillField(ny,nx,oldc,newc,ok,flag);
	else if(field2[ny][nx]==newc)
	  ok=true;
      }
    }
  }
}
void dfs(int cnt){
  if(res<=cnt)return;
  {
    int goal=field[0][0];
    bool ok=true;
    for(int i=0;i<H;i++)
      for(int j=0;j<W;j++)
	if(field[i][j]!=goal)ok=false;
    if(ok){
      res=min(res,cnt);
      return;
    }
  }
  for(int i=0;i<3;i++){
    if(field[0][0]==i)continue;
    int backUp[20][20];
    for(int j=0;j<H;j++)
      for(int k=0;k<W;k++)
	backUp[j][k]=field[j][k];
    bool ok=false;
    // 塗りつぶし
    memset(used,0,sizeof(used));
    fillField(0,0,field[0][0],i,ok,false);
    // もし一つ以上属する色が増えるならdfs
    if(ok)dfs(cnt+1);
    for(int j=0;j<H;j++)
      for(int k=0;k<W;k++)
	field[j][k]=backUp[j][k];
  }
}
int greedy(){
  {
    int goal=field2[0][0];
    bool ok=true;
    for(int i=0;i<H;i++)
      for(int j=0;j<W;j++)
	if(field2[i][j]!=goal)ok=false;
    if(ok)return 0;
  }
  for(int i=0;i<3;i++){
    if(field2[0][0]==i)continue;
    bool ok=false;
    // 塗りつぶし
    fillField(0,0,field2[0][0],i,ok,true);
    // もし一つ以上属する色が増えるならdfs
    if(ok)
      return greedy()+1;
  }
}

int main(){
  while(cin>>W>>H&&(W|H)){
    res=H*W;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	char ch;cin>>ch;
	if(ch=='R')field[i][j]=0;
	else if(ch=='G')field[i][j]=1;
	else if(ch=='B')field[i][j]=2;
	field2[i][j]=field[i][j];
      }
    }
    lim=greedy();
    res=lim;
    dfs(0);
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 924
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int dx[]={0,-1,0,1}, dy[]={-1,0,1,0};

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll H,W,ret=0; cin>>H>>W;
	vector<string> S;
	string cur;
	while(cin>>cur)
		S.push_back(cur);
	H=S.size(); W=S[0].size();
	set<ii> st;
	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			ii key={i,j};
			if(st.count(key))
				continue;
			st.insert(key);
			queue<ii> q; q.push(key);
			ll b=0,w=0;
			while(!q.empty()) {
				ii cur=q.front(); q.pop();
				if(S[cur.first][cur.second]=='#') b++;
				else w++;
				for (int k=0; k<4; k++) {
					ii nxt=cur; nxt.first+=dx[k]; nxt.second+=dy[k];
					if(nxt.first<0||nxt.first>=H||nxt.second<0||nxt.second>=W)
						continue;
					if(S[nxt.first][nxt.second]==S[cur.first][cur.second])
						continue;
					if(st.count(nxt))
						continue;
					st.insert(nxt);
					q.push(nxt);
				}
			}
			ret+=b*w;
		}
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    REP(i, H) cin >> S[i];

    vector<vector<int>> R(H, vector<int>(W)), C(H, vector<int>(W));

    for(int i=0; i<H; i++) {
        int counter = 0, j_begin = 0;
        for(int j=0; j<W; j++) {
            if(S[i][j] == '#') {
                for(int t=j_begin; t<j; t++)
                    R[i][t] = counter;
                j_begin = j+1;
                counter = 0;
            } else if (j==W-1 && S[i][j] == '.') {
                for(int t=j_begin; t<=j; t++)
                    R[i][t] = counter + 1;
            } else {
                counter++;
            }
        }
    }

    for(int j=0; j<W; j++)  {
        int counter = 0, i_begin = 0;
        for(int i=0; i<H; i++) {
            if(S[i][j] == '#') {
                for(int t=i_begin; t<i; t++)
                    C[t][j] = counter;
                i_begin = i+1;
                counter = 0;
            } else if (i==H-1 && S[i][j] == '.') {
                for(int t=i_begin; t<=i; t++)
                    C[t][j] = counter + 1;
            } else {
                counter++;
            }
        }
    }

    // for(int i=0; i<H; i++) {
    //     for(int j=0; j<W; j++) cerr << R[i][j] << " ";
    //     cerr << endl;
    // }

    // cerr << endl;

    // for(int i=0; i<H; i++) {
    //     for(int j=0; j<W; j++) cerr << C[i][j] << " ";
    //     cerr << endl;
    // }

    int ans = 0;
    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++)
            if(R[i][j] + C[i][j] - 1 > ans)
                ans = R[i][j] + C[i][j] - 1;

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

Measured memory_bytes: 35712
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class ECamelTrain {
public:
    static bool cmp(pair<int, pll>& p1, pair<int, pll>& p2){
        return p1.second.first-p1.second.second < p2.second.first-p2.second.second;
    }

    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int tt;
        in>>tt;
        while(tt--){
            int N;
            in>>N;
            vc<pair<int, pll>> L, R;
            REP(i, N){
                int k, l, r;
                in>>k>>l>>r;
                if(l>=r) L.eb(k, pll(l, r));
                else R.eb(N-k, pll(l, r));
            }
            set<int> S1, S2;
            RREP(i, N){
                S1.insert(i);
                S2.insert(i);
            }
            sort(RALL(L), cmp);
            sort(ALL(R), cmp);
            lint ans = 0;
            for(auto& p : L){
                int k = p.first;
                lint l = p.second.first, r = p.second.second;
                auto itr = S1.upper_bound(k);
                if(itr==S1.begin()) ans += r;
                else{
                    ans += l;
                    S1.erase(prev(itr));
                }
            }
            for(auto& p : R){
                int k = p.first;
                lint l = p.second.first, r = p.second.second;
                auto itr = S2.upper_bound(k);
                if(itr==S2.begin()) ans += l;
                else{
                    ans += r;
                    S2.erase(prev(itr));
                }
            }
            out<<ans<<'\n';
        }
    }
};


int main() {
	ECamelTrain solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 26684
#include <iostream>
#include <string>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(var,start,end) for(int var=start; var<end; var++)
#define REP(var,cnt) FOR(var,0,cnt)

int A[110][2];
vector<int> edges[110];

int matched[110];

// https://ikatakos.com/pot/programming_algorithm/graph_theory/bipartite_matching


int dfs(int v, vector<int> &visited) {
	for(int u : edges[v]) {
		if ( std::find(visited.begin(), visited.end(), u) != visited.end()) {
			continue;
		}
		
		visited.push_back(u);
		
		if ( matched[u] == -1 || dfs(matched[u], visited) ) {
			matched[u] = v;
			return 1;
		}
	}
	return 0;
}

int main(void) {
	
	int N;
	cin >> N;
	
	REP(i, N) {
		int x, y;
		cin >> x >> y;
		A[i][0] = x;
		A[i][1] = y;
		
		matched[i] = -1;
	}
	
	REP(i, N) {
		int x, y;
		cin >> x >> y;
		
		REP(j, N) {
			if ( A[j][0] < x && A[j][1] < y ) {
				edges[i].push_back(j);
			}
		}
	}
	
	int ret = 0;
	REP(i, N) {
		vector<int> aa;
		ret += dfs(i, aa);
	}
	
	cout << ret << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;

  cout << (1000 - N % 1000) % 1000 << endl;
}

Measured memory_bytes: 3620
s = gets.chomp
if s == s.reverse
  puts '0'
elsif s.delete('x') != s.delete('x').reverse
  puts '-1'
else
  cnt = 0
  x = ''
  y = ''
  c = (s.delete('x').size / 2.0).ceil
  s.size.times do |i|
    cnt += 1 if s[i] != 'x'
    if cnt == c
      b = i + (s.delete('x').size.even? ? 1 : 0)
      x = s[0..i]
      y = s[b..-1].reverse
      break
    end
  end
  i = 0
  j = 0
  cnt = 0
  while i < x.size
    if x[i] == y[j]
      i += 1
      j += 1
    elsif y[j] == 'x'
      j += 1
      cnt += 1
    elsif x[i] == 'x'
      i += 1
      cnt += 1
    end
  end
  puts cnt
end

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

using namespace std;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}

template<typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif
typedef long long int LL;
typedef unsigned int uint;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<LL> VLL;

const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

#define MP make_pair
#define PB push_back
#define F first
#define S second
#define SZ(x)           x.size()
#define MAX(a, b)      ((a)>(b)?(a):(b))
#define MIN(a, b)      ((a)<(b)?(a):(b))
#define ALL(a)         std::begin(a), std::end(a)
#define Fill(n, x)      memset(n,x,sizeof n);
#define IN_REP         int _t; cin >> _t ; while(_t--)
#define IOS            ios::sync_with_stdio(false);cin.tie(NULL)
#define Cin(a)         cin>>a;
#define Cin2(a, b)      cin>>a>>b;
#define Cin3(a, b, c)    cin>>a>>b>>c;
#define Cin4(a, b, c, d)  cin>>a>>b>>c>>d;
#define Cout(n)           cout<<n<<endl;
#define REP(i, n)       for(int i=0;i<(n);i++)
#define FOR(i, a, b)     for(int i=(a);i<(b);i++)
#define FORR(i, n)      for(int i=(n);i>=0;i--)
#define EPS 1e-9

template<typename T>
inline T GCD(T a, T b) {
    LL t;
    while (a) {
        t = a;
        a = b % a;
        b = t;
    }
    return b;
}

template<typename T>
inline T Pow(T base, T exp) {
    LL result = 1;
    while (exp) {
        if (exp & 1)result *= base;
        exp >>= 1;
        base *= base;
    }
    return result;
}

template<typename T>
inline T Mulmod(T a, T b, T c) {
    LL x = 0, y = a % c;
    while (b > 0) {
        if (b & 1) x = (x + y) % c;
        y = (y << 1) % c;
        b >>= 1;
    }
    return x;
}

template<typename T>
inline T Pow(T base, T exp, T mod) {
    LL x = 1, y = base;
    while (exp > 0) {
        if (exp & 1) x = Mulmod(x, y, mod);
        y = Mulmod(y, y, mod);
        exp >>= 1;
    }
    return x;
}

template<typename T>
inline T Cube(T a) { return a * a * a; }

#define INF 1000000000000000
#define MAXN 5000005
const int MOD = (int) 1e9 + 7;

int main() {
    IOS;
#ifdef RDS
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("log.txt", "w", stderr);
#endif
    LL n, k;
    cin >> n >> k;
    VLL x(n);
    REP(i, n) cin >> x[i];
    LL ans = INF;
  REP(i,n-k+1){
    ans = min(ans,abs(x[i]-x[i+k-1])+abs(x[i]));
  }
  REP(i,n-k+1){
    ans = min(ans,abs(x[i]-x[i+k-1])+abs(x[i+k-1]));
  }
  cout << ans << endl;
#ifdef RDS
    fprintf(stdout,"\nTIME: %.3lf sec\n", (double)clock()/(CLOCKS_PER_SEC));
#endif
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007


int main(){
	ll a,b;
	cin>>a>>b;
	if(a*b<=0){
		cout << "Zero";
		return 0;
	}
	if(a>0){
		cout << "Positive";
		return 0;
	}
	cout <<(abs(b-a)%2==1? "Positive":"Negative");
	
}

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

int main(){
    ll n,c[5];
    cin>>n>>c[0]>>c[1]>>c[2]>>c[3]>>c[4];
    ll minc=1e16;
    for(int i=0;i<5;i++){
        minc=min(minc,c[i]);
    }
    ll ans=4+(n+minc-1)/minc;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int cmp(void const*a,void const*b)
{
    return *(int*)b-*(int*)a;
}
int main()
{
    int s[50],n,k,sum,i;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        sum=0;
        for(i=0;i<n;i++)
            scanf("%d",&s[i]);
        qsort(s,n,sizeof(s[0]),cmp);
        for(i=0;i<k;i++)
            sum+=s[i];
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

constexpr auto INF = INT_MAX/2;
constexpr auto MOD = 1000000007;

int n, m, r;
vvi road;

int main() {

	cin >> n >> m >> r;
	vi vis(r);
	rep(i, r) {
		cin >> vis[i];
		vis[i]--;
	}
	sort(all(vis));

	road.assign(n, vi(n, INF));

	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		road[a][b] = c;
		road[b][a] = c;
	}

	rep(k, n)rep(i, n)rep(j, n)road[i][j] = min(road[i][j], road[i][k] + road[k][j]);
	
	int ans = INF;

	do {
		int len = 0;
		rep(i, r - 1)len += road[vis[i]][vis[i + 1]];
		ans = min(ans, len);

	} while (next_permutation(all(vis)));

	cout << ans << endl;

}

Measured memory_bytes: 384
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    constexpr int INF = 200000;
    vector is_prime(INF, true);
    is_prime[0] = is_prime[1] = false;
    FOR(p, 2, INF / 2)
    {
        if (not is_prime[p])
        {
            continue;
        }
        for (int a = 2; p * a < INF; ++a)
        {
            is_prime[p * a] = false;
        }
    }
    int x;
    cin >> x;
    FOR(y, x, INF)
    {
        if (is_prime[y])
        {
            cout << y << '\n';
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  int H, W, h, w;
  cin >> H >> W;
  cin >> h >> w;
  int ans = H*W - H*w - (W-w)*h;
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
const int N=7;
int dic[N],w,dic2[N];
string s;
int e=0,n=0;
bool ans = false;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int dice[n][7];
	FOR(i,0,n)FOR(j,1,7)cin>>dice[i][j];
	


	FOR(i,0,n)FOR(j,i+1,n){
		FOR(k,1,7)dic[k] = dice[i][k];
		FOR(k,1,7)dic2[k] = dice[j][k];
		s = "EEEESEEEESEEEESEEEESESEEEESEEEESEEEESEEEESESEEEESEEEESEEEESEEEESESEEEESEEEESEEEESEEEESESEEEESEEEESEEEESEEEES";
		FOR(i,0,s.size()){
			if(s[i]=='E'){
				w=dic[1];
				dic[1]=dic[4];
				dic[4]=dic[6];
				dic[6]=dic[3];
				dic[3]=w;
			}else if(s[i]=='W'){
				w=dic[1];
				dic[1]=dic[3];
				dic[3]=dic[6];
				dic[6]=dic[4];
				dic[4]=w;
			}else if(s[i]=='N'){
				w=dic[1];
				dic[1]=dic[2];
				dic[2]=dic[6];
				dic[6]=dic[5];
				dic[5]=w;
			}else{
				w=dic[1];
				dic[1]=dic[5];
				dic[5]=dic[6];
				dic[6]=dic[2];
				dic[2]=w;
			}
			FOR(i,1,7){
				if(dic[i]!=dic2[i])break;
				if(i==6)ans = true;
			}
		}
	}
	if(ans){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
}


Measured memory_bytes: 3240
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;



int main () {
	SpeedForce;
	setIO();
	cin >> n;


	cout << 1000* ((n+999)/1000)-n;

	return Accepted;
}

// B...a

Measured memory_bytes: 17728
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

def rev_mod(num):
	pow_num = MOD - 2
	ret = 1
	while pow_num > 0:
		if pow_num % 2 == 1:
			ret *= num
			ret %= MOD
		num *= num
		num %= MOD
		pow_num /= 2
	return ret

N, A, B, C = map(int, raw_input().split())

ans = 0

for loop in range(2):
    cnt = 0
    P = 1
    comb = 1
    PA = (A * rev_mod(A + B)) % MOD
    PB = (B * rev_mod(A + B)) % MOD
    PCm = 100 * rev_mod(100 - C) % MOD
    for i in range(N - 1):
        P *= PA
        P %= MOD

    for i in range(N):
        ans += PCm * (N + i) % MOD * P % MOD * comb % MOD * PA
        ans %= MOD
        P *= PB
        P %= MOD
        comb *= N + i
        comb *= rev_mod(i + 1)
        comb %= MOD
    A, B = B, A
print ans

Measured memory_bytes: 8040
import sys
from collections import defaultdict
def wi(): return list(map(int, sys.stdin.readline().split()))
def i(): return int(sys.stdin.readline())
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def mip(n): return [wip() for _ in range(n)]

def main():
    n, q = wi()
    ab = mip(n - 1)
    px = mip(q)
    for i in range(q):
        px[i][1] += 1


    cost = [0] * n
    for i in range(q):
        cost[px[i][0]] += px[i][1]

    son = [[] for _ in range(n)]
    for i in range(n - 1):
        son[ab[i][0]].append(ab[i][1])
        son[ab[i][1]].append(ab[i][0])

    flagli = [0] * n
    flagli[0] = 1
    queue = []
    queue.append(0)
    while queue != []:
        po = queue.pop()
        for kk in son[po]:
            if flagli[kk] == 0:
                flagli[kk] = 1
                queue.append(kk)
                cost[kk] += cost[po]

    for i in range(n):
        print(cost[i],"" , end="")

if __name__ == '__main__':
    main()

Measured memory_bytes: 124568
import Data.List                                                                                                           
main :: IO ()                                                                                                              
main = do                                                                                                                  
  [a,b,c] <- sort . map read . words <$> getLine                                                                           
  if a + b == c                                                                                                            
    then putStrLn "Yes"                                                                                                    
    else putStrLn "No"

Measured memory_bytes: 508
L = 1000
@memo = Array.new(3) {[]}

def doit(s, n = 1)
  return (s <= L) ? 1 : 0 if n == 4
  return @memo[n - 1][s] if @memo[n - 1][s]
  co = 0
  a = (s <= L) ? s : L
  (0..a).each do |i|
    co += doit(s - i, n + 1)
  end
  @memo[n - 1][s] = co
end

$<.readlines.map(&:to_i).each do |s|
  puts doit(s)
end


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

using namespace std;

int solve(const int stones_height[], int memo[], const int &n, const int &k){
    int ans;
    if(memo[n] != -1) ans = memo[n];
    else if(n == 1) return 0;
    else{
        ans = abs(stones_height[n] - stones_height[n - 1]) + solve(stones_height, memo, n - 1, k);
        for(int i = 2; n - i >= 1 && i <= k; i++){
            ans = min(ans, abs(stones_height[n] - stones_height[n - i]) + solve(stones_height, memo, n - i, k));
        }
    }
    return memo[n] = ans;
}

int main(){
    int n, k;
    while(scanf("%d %d", &n, &k) != EOF){
        int stones_height[n + 1], memo[n + 1];
        for(int i = 0; i < n; i++){
            scanf("%d", &stones_height[i + 1]);
            memo[i + 1] = -1;
        }
        printf("%d\n", solve(stones_height, memo, n, k));
    }
    return 0;
}

Measured memory_bytes: 13740
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n>>m;
  int days=0;
  int sum=0;
  
  for(int i;i<m;i++){
    cin >> days;
    sum += days;
  }
  if(sum <= n){
    cout << n-sum <<endl;
  }
  else{
    cout << "-1"<<endl;
  }
    

}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> dp(N,INF),V(N);
    rep(i,0,N)cin >> V[i];
    dp[0] = 0;
    dp[1] = abs(V[1] - V[0]);
    rep(i,2,N){
        dp[i] = min(abs(V[i] - V[i-2]) + dp[i-2], abs(V[i] - V[i-1]) + dp[i-1]);
    }
    cout << dp[N-1] << endl;
}

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

int n, a, b, x[200200];
int ca, cb, cc;
int main() {
    scanf("%d%d%d", &n, &a, &b);
    rep(i, n) {
        scanf("%d", &x[i]);
        if(x[i] <= a) ca++;
        else if(x[i] <= b) cb++;
        else cc++;
    }
    printf("%d\n", min(ca, min(cb, cc)));
    
    return 0;
}

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

int main() {
	
	int x, a, b; cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b)) cout << "A" << endl;
	else cout << "B" << endl;  
	return 0;
}

Measured memory_bytes: 3588
//37
#include<iostream>
#include<vector>

using namespace std;

int main(){
  int cmp[1121]={};
  vector<int> prm;
  for(int i=2;i<=1120;i++){
    if(!cmp[i]){
      prm.push_back(i);
      for(int j=2;i*j<=1120;j++){
	cmp[i*j]=true;
      }
    }
  }
  static int dp[1121][200][15];
  dp[0][0][0]=1;
  for(int i=0;i<1121;i++){
    for(int j=0;j<=prm.size();j++){
      for(int l=j+1;l<=prm.size();l++){
	for(int k=0;k<14;k++){
	  if(i+prm[l-1]<=1120){
	    dp[i+prm[l-1]][l][k+1]+=dp[i][j][k];
	  }
	}
      }
    }
  }
  for(int n,k;cin>>n>>k,n|k;){
    int a=0;
    for(int i=0;i<=prm.size();i++){
      a+=dp[n][i][k];
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 13220
N=int(input())
L = [list(map(int, input().split())) for i in range(N)]
dp=[[0 for j in range(3)] for i in range(N)]
ans=[0]*(N+1)
for i in range(N):
  if i==0:
    dp[i][0]=L[i][0]
    dp[i][1]=L[i][1]
    dp[i][2]=L[i][2]
  else:
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+L[i][0]
    dp[i][1]=max(dp[i-1][2],dp[i-1][0])+L[i][1]
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+L[i][2]
  ans=max(dp[i][0],dp[i][1],dp[i][2])
  #print(ans)
print(ans)

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    double w, h, x, y;
    int same;
    cin >> w >> h >> x >> y;
    if(x == w / 2.0 && y == h / 2.0) same = 1;
    else same = 0;
    cout << w * h / 2.0 << ' ' << same << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<long> A(N);
  for(int i=0; i<N; i++)cin>>A[i];
  int c=0;
  while(true){
    bool a=true;
    for(int i=0; i<N; i++){
      if(A[i]%2==0)A[i]/=2;
      else a=false;
    }
    if(a)c++;
    else break;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
auto constexpr infty<int> = 1'100'100'100;
template<>
auto constexpr infty<long long int> = 1'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

namespace { // Graph Basics

template<typename WeightT>
struct Edge {
  int from, to;
  WeightT weight;
  Edge(int s, int d, WeightT w): from(s), to(d), weight(w) {}
};

template<typename WeightT>
bool
operator< (Edge<WeightT> const &lhs, Edge<WeightT> const &rhs) {
  if (lhs.weight != rhs.weight) {
    return lhs.weight < rhs.weight;
  } else if (lhs.from != rhs.from) {
    return lhs.from < rhs.from;
  }
  return lhs.to < rhs.to;
}

template<typename WeightT>
using Edges = std::vector<Edge<WeightT> >;

template<typename WeightT>
using AdjacencyList = std::vector<Edges<WeightT> >;

template<typename WeightT>
void
add_undir_edge(AdjacencyList<WeightT> &graph, int u, int v, WeightT w) {
  graph[u].emplace_back(u, v, w);
  graph[v].emplace_back(v, u, w);
}

} // namespace

namespace { // Dijkstra's algorithm

template<typename WeightT>
struct DijkstraResult {
  std::vector<WeightT> distance;
};

template<typename WeightT>
DijkstraResult<WeightT>
dijkstra_algorithm(AdjacencyList<WeightT> const &g, int start, WeightT inf) {
  int const N = g.size();
  std::vector<bool> done(N, false);
  std::vector<WeightT> dist(N, inf);
  using P = std::tuple<WeightT, int>;
  std::priority_queue<P, std::vector<P>, std::greater<P> > que;
  que.emplace(0, start);
  while (!que.empty()) {
    WeightT dist2u; int u; std::tie(dist2u, u) = que.top();
    que.pop();
    if (dist2u >= dist[u]) {
      continue;
    }
    dist[u] = dist2u;
    for (auto &&e : g[u]) {
      que.emplace(dist2u + e.weight, e.to);
    }
  }
  return {
    dist
  };
}

} // namespace

using namespace std;

using Graph = AdjacencyList<lli>;

void solve(Graph const &g) {
  auto const res = dijkstra_algorithm(g, 0, infty<lli>);
  REP(i, g.size()) {
    cout << (res.distance[i] % 2 == 0 ? 0 : 1) << '\n';
  }
}

int main() {
  // cout << fixed << setprecision(10);

  int N;
  cin >> N;
  Graph g(N);
  REP(i, N-1) {
    int U, V, W;
    cin >> U >> V >> W;
    add_undir_edge(g, --U, --V, (lli)W % 10000);
  }
  solve(g);
  return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

typedef long long ll;

const ll MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  vector<int> x(N);
  REP(i,N) cin >> x[i];

  stack<int> st;
  ll res = 1LL;
  REP(i,N) {
    st.push(x[i]);
    if(st.top() < 2 * st.size() - 1) {
      res = (res * (ll)st.size()) % MOD;
      st.pop();
    }
  }
  REP(i,st.size()) res = (res * (ll)(i + 1)) % MOD;
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;

int main(){
    int r, D, x;
    scanf("%d %d %d", &r, &D, &x);
    for(int i = 0; i < 10; ++i){
        x = r * x - D;
        printf("%d\n", x);
    }
    return 0;
}

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

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

	
	int n;
	while(cin >> n && n != 0){
		vector<int> h(n + 1);
		for(int i = 0; i < n + 1; ++i){
			cin >> h[i];
		}
		for(int i = 0; i < n + 1; ++i){
			vector<int> vec = h;
			vec.erase(vec.begin() + i);
			int d = vec[1] - vec[0];
			bool check = true;
			for(size_t j = 1; j < vec.size(); ++j){
				if(vec[j] - vec[j - 1] != d){
					check = false;
					break;
				}
			}
			if(check){
				cout << h[i] << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <queue>
#include <utility>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

const int MAX = 2000;
const int MOD = 1000000007;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
    int n, k;
    cin >> n >> k;

    // cout << n-k+1 << endl;
    for(int i=1;i<=k;i++) cout << (COM(k-1,i-1)*COM(n-k+1,i))%MOD << endl;

    return 0;
}

Measured memory_bytes: 256