akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll INF = 1e18;
#define pu push
#define pb push_back
#define mp make_pair
#define print(x) cout << (x) << endl;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define fi first
#define sc second

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> As(A);
    vector<int> Bs(B);
    vector<int> Ms(M);
    rep(i,A) {
        cin >> As.at(i);
    }
    rep(i,B) {
        cin >> Bs.at(i);
    }
    rep(i,M) {
        int xm, ym, cm;
        cin >> xm >> ym >> cm;
        xm--;
        ym--;
        Ms.at(i) = As.at(xm)+Bs.at(ym)-cm;
    }
    SORT(As);
    SORT(Bs);
    SORT(Ms);
    cout << min(As.at(0)+Bs.at(0), Ms.at(0)) << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
    int n;
    float sum=0.0f;
    
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=1.0f/a[i];
    }
    cout<<(1.0f/sum)<<endl;
    return 0;
}



Measured memory_bytes: 764
X = int(input())

l2 = X % 100
h = X // 100

n = 0
if l2 > 5:
    k = l2 // 5
    n += k
    l2 %= 5
if l2 > 0:
    n += 1

if h >= n:
    print(1)
else:
    print(0)

Measured memory_bytes: 3060
/* 
容易发现这么几个性质：
(1)1一定在基环树的环上。否则在环上的点无法到达1
(2)当环的大小n >= 2时，给每个点按照顺序在mod n意义下标号，那么i + K != j + K(mod n)   <=>   i != j(mod n)。所以环的大小 = 1
那么最终一定呈现这样的结构：1往1连一个自环，剩下的点形成以1为根的深度<= K的树
把1的边连向1得到一棵树，剩下的点从下往上做，当一个点子树深度> K时接向根
*/

#include <cstdio>
#include <algorithm>

using namespace std;
const int Max_N(100050);

int N, K, Ans, Father[Max_N], Head[Max_N], To[Max_N], Next[Max_N];

int dfs(int u)
{
	int Dep(0);
	for (int i = Head[u], v, dep;i;i = Next[i])
	{
		dep = dfs(v = To[i]) + 1;
		if (dep >= K && u != 1)
			++Ans;
		else
			Dep = max(Dep, dep);
	}
	return Dep;
}

int main()
{
	scanf("%d%d", &N, &K);
	for (int i = 1;i <= N;++i)
	{
		scanf("%d", Father + i);
		if (i == 1)
		{
			if (Father[i] != 1)
				++Ans;
		}
		else
			To[i] = i, Next[i] = Head[Father[i]], Head[Father[i]] = i;
	}
	dfs(1);
	printf("%d", Ans);
	return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll H,N;

int main(){

	scanf("%lld %lld",&H,&N);

	ll sum = 0;
	ll tmp;

	for(ll i = 0; i < N; i++){

		scanf("%lld",&tmp);
		sum += tmp;
	}

	if(sum >= H){

		printf("Yes\n");
	}else{

		printf("No\n");
	}

	return 0;
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<std::vector<char> > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int n;
v_int l;
int A, B, C;
int ans = INF;
int cnt = 0;

int solve(v_int &v)
{
    int la = 0, lb = 0, lc = 0;
    int la_cnt = 0, lb_cnt = 0, lc_cnt = 0;
    int mp = 0;
    irep(i, n) {
        if(v[i] == 0) { la += l[i]; la_cnt++; }
        if(v[i] == 1) { lb += l[i]; lb_cnt++; }
        if(v[i] == 2) { lc += l[i]; lc_cnt++; }
    }
    mp = abs(la-A) + abs(lb-B) + abs(lc-C);
    mp += 10 * ((la_cnt-1) + (lb_cnt-1) + (lc_cnt-1));
    if(la_cnt == 0 || lb_cnt == 0 || lc_cnt == 0) {
        return INF;
    } else {
        return mp;
    }
}

void dfs(int i, v_int &v)
{
    if(i == n) {
        ans = min(ans, solve(v));
        return ;
    }
    v[i] = 0;
    dfs(i+1, v);
    v[i] = 1;
    dfs(i+1, v);
    v[i] = 2;
    dfs(i+1, v);
    v[i] = 3;
    dfs(i+1, v);
    return; 
}

int main(void)
{
    cin >> n >> A >> B >> C;
    
    l.resize(n);
    irep(i, n) {
        cin >> l[i];
    }

    v_int v(n);
    dfs(0, v);
    cout << ans << endl;
    return 0;
}
/** atcoder **/


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[]args) {
        Scanner sc = new Scanner(System.in);
        while(true){
        String x = sc.next();
        int y = x.length();
            if (x.equals("0")) {
                break;
            } else {
                int sum = 0;
                for (int i = 0; i < y; i++) {
                    char c = x.charAt(i);
                    int n = c - '0';
                    sum = sum + n;
                }
                System.out.println(sum);
            }
        }
    }
}



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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif

using namespace std;

void solve(ll D) {
    if (D == 25) cout << "Christmas" << endl;
    if (D == 24) cout << "Christmas Eve" << endl;
    if (D == 23) cout << "Christmas Eve Eve" << endl;
    if (D == 22) cout << "Christmas Eve Eve Eve" << endl;

}


void main_(istream &cin) {
    ll D;
    cin >> D;
    solve(D);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 768
/* 
	Name: Mohit Khare
	CSE - MNNIT Allahabad
	never give up!!
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define ALL(x) x.begin(), x.end()
#define fastandfurious ios_base::sync_with_stdio(false);
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp make_pair
#define X first
#define Y second

#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b) for(int i=a;i<b;i++)
#define revr(i,a,b) for(int i=a;i>b;i--)
#define pr1(a) cout<<a<<endl;
#define pr2(a,b) cout<<a<<" "<<b<<endl;

const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
#define linf 99999999999999999ll	
#define PI 3.1415926535897932384626
#define mod 1000000007
const int maxn=1e5+1;

ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

int a[maxn];
int main()
{
	//freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
	fastandfurious
	int n;
	cin>>n;
	rep(i,n)
	cin>>a[i];
	int hash[10],cnt=0;
	memset(hash,0,sizeof(hash));
	rep(i,n)
	{
		if(a[i]>=1 && a[i] <= 399)
			hash[0]++;
		else if(a[i]>=400 && a[i]<=799)
			hash[1]++;
		else if(a[i]>=800 && a[i]<=1199)
			hash[2]++;
		else if(a[i]>=1200 && a[i]<=1599)
			hash[3]++;
		else if(a[i]>=1600 && a[i]<=1999)
			hash[4]++;
		else if(a[i]>=2000 && a[i]<=2399)
			hash[5]++;
		else if(a[i]>=2400 && a[i]<=2799)
			hash[6]++;
		else if(a[i]>=2800 && a[i]<=3199)
			hash[7]++;
		else cnt++;
	}
	int ans = 0;
	rep(i,8)
	{
		if(hash[i]>0)
			ans++;
	}
	if(ans>0)
	{
		cout<<ans<<" ";
	}
	else cout<<"1 ";
	cout<<ans+cnt<<endl;
	return 0;	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
const int INF = 1e9+7;
using namespace std;

int main()
{
	int N, L;
	string S[100];
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	sort(S, S + N);
	for (int i = 0; i < N; i++) {
		cout << S[i];
	}
	
    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc057/tasks/abc057_b

import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n, m = map(int, input().split())

    abl = []
    for _ in range(n):
        a, b = map(int, input().split())
        abl.append((a,b))

    cdl = []
    for i in range(m):
        c, d = map(int, input().split())
        cdl.append((c, d, i))

    for a,b in abl:
        checkpoints = sorted(cdl, key=lambda cd: abs(a - cd[0]) + abs(b - cd[1]))
        print(checkpoints[0][2] + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
//#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
long long read()
{
	long long x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	char s[1000000];
	cin>>s+1;
	int n=strlen(s+1);
	cout<<s[1]<<n-2<<s[n];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;

int n,cnt,u[N],v[N],num;
char s[N];

int main(){
	int i,j,pre,nw;
	scanf("%s",s+1);
	n=strlen(s+1);
	for(i=1;i<=n;++i) s[i]-='0';
	if((!s[1])||(!s[n-1])||(s[n])) {puts("-1");return 0;}
	for(i=2;i<n-i;++i) 
	 if(s[i]!=s[n-i]){puts("-1");return 0;}
	u[++cnt]=1;v[cnt]=2;
	for(pre=1,i=2;i<n;++i){
		for(;i<n && (!s[i]);++i);
		j=i-pre-1;nw=cnt+1;
		for(;j;--j){cnt++;u[cnt]=nw;v[cnt]=cnt+1;}
		u[++cnt]=nw;v[cnt]=cnt+1;
		pre=i;
	}
	for(i=1;i<=cnt;++i) printf("%d %d\n",u[i],v[i]);
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    for(int i=0; i<N; i++) {
        cin >> A[i];
        sum += A[i];
    }

    ll ans = 0;

    for(int i=0; i<N; i++) {
        sum -= A[i];
        ans += (A[i] * (sum % (1000000000 + 7)));
        ans %= (1000000000 + 7);
    }
    cout << ans;
}

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

int main(){
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a+n, greater<int>());
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(!(i%2)) ans += a[i];
        else ans -= a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int i,j,n,m,d,ans=0,s=0,bat[100][100]={0};
char cobra[201];
cin>>n>>m>>d;
for(i=0;i<n;i++){
cin>>cobra;
for(j=0;j<m;j++){
if(cobra[j]=='.')bat[i][j]=1;
}
}
for(i=0;i<n;i++){
s=0;
for(j=0;j<m;j++){
if(bat[i][j]==1)s++;
else s=0;
if(s==d){
ans++;
s--;
}
}
}
for(i=0;i<m;i++){
s=0;
for(j=0;j<n;j++){
if(bat[j][i]==1)s++;
else s=0;
if(s==d){
ans++;
s--;
}
}
}
cout<<ans<<endl;
return 0;
}



Measured memory_bytes: 3100
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
    }
    let mut cnt = vec![0; n];
    for _i in 0..k {
        input! {
            d: usize,
            a: [usize; d],
        }
        for j in 0..d {
            cnt[a[j] - 1] += 1;
        }
    }

    let mut ans = 0;
    for i in 0..n {
        if cnt[i] == 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2196
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(void)
{
    ll n, r = 0;
    
    cin >> n;
    
    
    rrep (i, n) {
        if (i % 3 == 0) continue;
        if (i % 5 == 0) continue;
        r += i;
    }
    
    cout << r;
    
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		//読み込み
		int a[] = new int[n];
		for(int i=0;i<n;i++)
			//格納 
			a[i] = sc.nextInt();
		 
			for(int i=0;i<n;i++){
			//正順
			//System.out.print(" aは"+a[i]);
			//間の空白
			if(i!=0)System.out.print(" ");
			//逆順
			System.out.print(a[n-i-1]);
		}
			
		System.out.println("");
	}

}


Measured memory_bytes: 26228
#r, d, x = map(int,input().split())
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
#s = input()
ls = []
for i in range(n):
  ls.append(v[i]-c[i])
ls = [i for i in ls if i > 0]
print(sum(ls))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=222,maxm=22222;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,m,a[maxn][maxn],b[maxn][maxn],c[maxn][maxn],tmp[maxn];
int s,t,q[maxn],h,r,dis[maxn],el,head[maxn],cur[maxn],to[maxm],nxt[maxm],w[maxm];
bool use[maxm];
inline void add(int u,int v,int w_){
	to[++el]=v;nxt[el]=head[u];head[u]=el;w[el]=w_;
	to[++el]=u;nxt[el]=head[v];head[v]=el;w[el]=0;
}
bool bfs(){
	MEM(dis,-1);
	q[h=r=1]=s;
	dis[s]=0;
	while(h<=r){
		int u=q[h++];
		for(int i=head[u];i;i=nxt[i]) if(w[i]){
			int v=to[i];
			if(dis[v]==-1) dis[v]=dis[u]+1,q[++r]=v;
		}
	}
	return ~dis[t];
}
int dfs(int u,int minres){
	if(u==t || !minres) return minres;
	int f,rtf=0;
	for(int &i=cur[u];i;i=nxt[i]){
		int v=to[i];
		if(dis[v]==dis[u]+1 && (f=dfs(v,min(minres,w[i])))){
			minres-=f;rtf+=f;
			w[i]-=f;w[i^1]+=f;
			if(!minres) break;
		}
	}
	return rtf;
}
int main(){
	n=read();m=read();
	FOR(i,1,n) FOR(j,1,m) a[i][j]=read();
	s=2*n+1;t=2*n+2;
	FOR(i,1,m){
		FOR(i,1,2*n+2) head[i]=0;
		FOR(i,1,el) to[i]=nxt[i]=w[i]=0;
		el=1;
		FOR(i,1,n) add(s,i,1),add(i+n,t,1);
		FOR(i,1,n) FOR(j,1,m) if(!use[a[i][j]]) add(i,(a[i][j]+m-1)/m+n,1);
		int f=0;
		while(bfs()){
			FOR(i,1,2*n+2) cur[i]=head[i];
			f+=dfs(s,1e9);
		}
		assert(f==n);
		FOR(j,1,n) for(int e=head[j];e;e=nxt[e]) if(!w[e]){
			int tp=to[e]-n;
			FOR(k,1,m) if((a[j][k]+m-1)/m==tp && !use[a[j][k]]){
				use[b[j][i]=a[j][k]]=true;break;
			}
		}
	}
	FOR(i,1,n){
		FOR(j,1,m) printf("%d ",b[i][j]);
		puts("");
	}
	FOR(j,1,m){
		FOR(i,1,n) tmp[i]=b[i][j];
		sort(tmp+1,tmp+n+1);
		FOR(i,1,n) c[i][j]=tmp[i];
	}
	FOR(i,1,n){
		FOR(j,1,m) printf("%d ",c[i][j]);
		puts("");
	}
}
// wtf flow

Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define INPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in"
#define OUTPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

bool ispalindrome(int x)
{
    //cout << (x % 10) << " " << (x / 10000) << "\n";
    
    if((x % 10) != (x / 10000))
    {
        return false;
    }
    
    
    
    x -= (x / 10000) * 10000;
    x /= 10;
    //cout << x << "\n";
    //cout << (x % 10) << " " << (x / 100) << "\n";
    
    if((x % 10) != (x / 100))
    {
        return false;
    }
    
    return true;
}

void solve()
{
    int a, b;
    cin >> a >> b;
    int res = 0;
    for(int i = a; i <= b; i++)
    {
        res += ispalindrome(i);
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    //freopen(INPUT, "r", stdin);freopen(OUTPUT, "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}



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

const long long INF = 1e11;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	long long int n,w; cin>>n>>w;
	
	long long int V=0;
	
	vector<pair<long long int,long long int>> a(n);
	
	for(int i=0;i<n;i++){
	    cin>>a[i].first>>a[i].second;
	    V+=a[i].second;
	} 
	
	vector<long long int> dp(V+1,INF);
	dp[0]=0;
	
    for(int i=0;i<n;i++){
        long long int v=a[i].second;
    for(long long int j=V;j>=v;j--){
        if(dp[j-v]!=INF)
           dp[j]=min(dp[j-v]+a[i].first,dp[j]);
     }
   } 
   
    for(long long int i=V;i>=0;i--){
        if(dp[i]<=w){
            cout<<i<<endl;
            break;
        }
    }
	return 0;
}

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

int main(){
    int n;
    int ten[4]={1,10,100,1000};
    int res=-1;
    cin>>n;
        vector<int> d(n);
        for(int i=0;i<n;i++)
            cin>>d[i];
        for(int i=0;i<10000;i++){
            res=i;
            int k;
            if(i<10)
                k=0;
            else if(i<100)
                k=1;
            else if(i<1000)
                k=2;
            else
                k=3;
            for(int j=0;j<n-k;j++){
                int sum=0;
                for(int r=0;r<=k;r++)
                    sum+=d[j+r]*ten[k-r];
                if(sum==i)
                    res=-1;

            }


        if(res>=0)
            break;
        }
        cout<<res<<endl;


    return 0;

}

Measured memory_bytes: 3096
using System;

public class p0101{
	p0101(){
		string str;
		int n;
		
		while((str=Console.ReadLine())!=null){
			n = int.Parse(str);
			while(0 < n--)
				Console.WriteLine("{0}", ((Console.ReadLine()).Replace("Hoshino", "Hoshina")));
		}
	}
	
	public static int Main (string[] args)
	{
		new p0101 ();
		return 0;
	}
}

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

using namespace std;

int main()
{
	unsigned int N;
	cin >> N;
	vector<int> a(N);
	int sum = 0;
	int sq_sum = 0;
	double mean;
	int y;
	for (size_t i = 0; i < N; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	mean = (double)sum / (double)N;
	y = (int)round(mean);
	for (size_t i = 0; i < N; i++)
	{
		sq_sum += (int)pow(a[i] - y, 2);
	}
	cout << sq_sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int i,j,k,n,m,l,count1=0;
void ABC140(void);
void ABC141(void);
void ABC142(void);
void ABC143(void);
void ABC144(void);
void ABC145(void);
void ABC146(void);
void ABC147(void);
void ABC148(void);
void ABC149(void);

int main(void){
    ABC145();
}

void ABC145(){
    int ans=1;
    string s,s1,s2;
    cin>>n;
    cin>>s;
    if(s.length()%2!=0){ans=0;}
    else{
        n=s.length()/2;
        s1=s.substr(0,n);
        s2=s.substr(n,n);
        cerr<<s1<<" "<<s2<<endl;
        for(i=0;i<n;i++){
            if(s1[i]!=s2[i]){
                ans=0;
                break;
            }
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

bool R(pair<string, int> sp1, pair<string, int> sp2){
    if(sp1.first != sp2.first) return sp1.first < sp2.first;
    else return sp1.second > sp2.second; 
}

int N;
vector<pair<string, int> > SP;
map<pair<string, int>, int> order;

int main(){
    cin >> N;

    string s; int p;
    for(int i = 0; i < N; i++){
        cin >> s >> p;
        SP.push_back(make_pair(s, p));
        order[make_pair(s, p)] = i + 1;
    }

    stable_sort(SP.begin(), SP.end(), R);

    for(int i = 0; i < N; i++) cout << order[SP[i]] << "\n";

    return 0;
}

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

int cntDigits(long num)
{
    int count = 0;
    
    while (num > 0) {
        num /= 10;
        count ++;
    }
    
    return count;
}

int main(void)
{
    long N;
    long A, B;
    int ans;
    int cur;
    int digitA, digitB;
    
    scanf("%ld", &N);
    
    ans = cntDigits(N);
    
    for (A = 1; A * A <= N; A ++) {
        if (N % A != 0) {
            continue;
        }
        
        B = N / A;
        
        digitA = cntDigits(A);
        digitB = cntDigits(B);
        
        if (digitA >= digitB) {
            cur = digitA;
        } else {
            cur = digitB;
        }
        
        if (cur < ans) {
            ans = cur;
        }
    }
    
    printf("%d\n", ans);
    

    return 0;
}

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

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> a(n);
        for (int& x : a) cin >> x;
        int sum = accumulate(a.begin(), a.end(), 0);

        int result = 0x7ffffff;
        for (int i = 0; i < (1 << n); i++) {
            int pon = 0;
            for (int j = 0; j < n; j++) {
                if ((i >> j) & 1) {
                    pon += a[j];
                }
            }
            result = min(result, abs(pon - (sum - pon)));
        }
        cout << result << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

class Baseball {
   public Baseball() {
      scoreList.Add(0);
      runnerList[0] = true;
   }

   private List<int> scoreList = new List<int>();
   public List<bool> runnerList = new List<bool>(Enumerable.Repeat(false, 4));

   public int Inning { get; private set; }
   public int[] Score { get { return scoreList.ToArray();} }
   public int OutCount { get; private set; }
   public bool[] Runner { get { return runnerList.ToArray(); } }

   public void Hit()
   {
      int Third = runnerList.Count - 1;
      if (runnerList[Third]) {
         scoreList[Inning]++;
         runnerList[Third] = false;
      }

      for (int i = Third - 1; i >= 0; i--) {
         if (!runnerList[i]) { continue; }

         runnerList[i + 1] = true;
         runnerList[i] = false;
      }
         
      runnerList[0] = true;
   }   

   public void Homerun()
   {
      int Third = runnerList.Count - 1;
      for (int i = 0; i <= Third; i++) {
         if (!runnerList[i]) { continue; }

         scoreList[Inning]++;
         runnerList[i] = false;
      }

      runnerList[0] = true;
   }

   public void Out()
   {
      OutCount++;
      if (OutCount < 3) { return; }

      int Third = runnerList.Count - 1;
      for (int i = 1; i <= Third; i++) {
         runnerList[i] = false;
      }
      scoreList.Add(0);
      Inning++;
      OutCount = 0;
   }   
}

class MainClass
{
   static void Main(string[] args)
   {
      var stringbuilder = new StringBuilder();

      var baseboll = new Baseball();

      int n = int.Parse(Console.ReadLine());
      while (baseboll.Inning < n)
      {   
         string evnt = Console.ReadLine();
         switch (evnt) {
         case "HIT":
            baseboll.Hit();
            break;
         case "HOMERUN":
            baseboll.Homerun();
            break;
         case "OUT":
            baseboll.Out();
            break;
         }
      }

      var scores = baseboll.Score;
      for (int i = 0; i < baseboll.Inning; i++) {
         stringbuilder.AppendLine(scores[i].ToString());
      }

      Console.Write(stringbuilder.ToString());
   }
}

Measured memory_bytes: 9436
a,b,c,d = map(int,input().split(' '))

def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

def lcm(x, y):
    ans = (x * y) // gcd(x, y)
    return ans

l_c = (a-1)//c
l_d = (a-1)//d
l_c_d = (a-1)//lcm(c, d)

l_ans = a - 1 - (l_c + l_d - l_c_d)


g_c = b//c
g_d = b//d
g_c_d = b//lcm(c, d)
g_ans = b - (g_c + g_d - g_c_d)

print(g_ans - l_ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

/*
n h w
a1 b1
.
.
an bn

*/
typedef long long int ll;
int n;
ll h, w;

int main(){
  cin >> n;
  cin >> h;
  cin >> w;

  int cnt = 0;
  for(int i = 0; i < n; i++){
    ll a,b;
    cin >> a;
    cin >> b;
    cerr << "a = " << a << ", b = " << b << endl;
    if(a >= h && b >= w){
      cnt++;
      cerr << "hit\n";
    }

  }

  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <numeric>
#include <cstdio>
#include <queue>


using namespace std;

int main() {

    int N;
    cin >> N;

    vector<int> L(N);
    vector<int>::iterator itr;
    int l;
    for (int i = 0; i < N; i++) {
        scanf("%d", &l);
        L[i] = l;
    }
    
    bool can = true;
    for (int i = N-1; i > 0; i--) {
        int sub = L[i-1] -  L[i];
        if (sub >= 2) {
            can = false;
            break;
        }
        else if (sub == 1) {
            L[i-1]--;
        }
    }

    if (can) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }

}



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

using ll = long long;
using P = pair<int, int>;

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

int bfs(vector<vector<int>> const& board, vector<vector<bool>>& visited, int y, int x) {
    int id = board[y][x];
    bool f = false;
    int res = 1;
    queue<P> que;
    que.push(P{y, x});
    visited[y][x] = true;
    while(!que.empty()) {
        P p = que.front();
        que.pop();
        for(int i=0; i<6; ++i) {
            int ny = p.first + dy[i],
                nx = p.second + dx[i];
            if(ny < 0 || board.size() <= ny || nx < 0 || ny < nx || visited[ny][nx]) {
                continue;
            }
            if(board[ny][nx] != id) {
                f |= board[ny][nx] == 0;
                continue;
            }
            visited[ny][nx] = true;
            res++;
            que.push(P{ny, nx});
        }
    }
    if(f) {
        return 0;
    } else {
        return res;
    }
}
 
int main() {
    int N, C;
    while(cin >> N >> C, N) {
        vector<vector<int>> board(N, vector<int>(N, -1));
        for(int i=1; i<=N; ++i) {
            for(int j=0; j<i; ++j) {
                cin >> board[i-1][j];
            }
        }
        int res = -1e9;
        for(int i=1; i<=N; ++i) {
            for(int j=0; j<i; ++j) {
                if(board[i-1][j] == 0) {
                    vector<vector<bool>> visited(N, vector<bool>(N));
                    board[i-1][j] = C;
                    int t = -bfs(board, visited, i-1, j);
                    for(int k=0; k<6; ++k) {
                        int ny = i-1 + dy[k],
                            nx = j + dx[k];
                        if(ny < 0 || board.size() <= ny || nx < 0 || ny < nx || visited[ny][nx]) {
                            continue;
                        }
                        if(board[ny][nx] == 0) {
                            continue;
                        }
                        t += bfs(board, visited, ny, nx);
                    }
                    res = max(res, t);
                    board[i-1][j] = 0;
                }
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3112
#include<iostream>

using namespace std;

const int N(1e5 + 9);
int n, m, ans;
int a[N], f[N];

int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	f[2] = abs(a[1] - a[2]);
	for (int i=3;i<=n;i++)
	{
		f[i] = f[i - 1] + abs(a[i] - a[i - 1]);
		f[i] = min(f[i], f[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout<<f[n]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int a,b;
int main(){
  scanf("%d %d",&a,&b);
  if((a+b)%3 == 0) {
    printf("Possible\n");
  }
  else if(a % 3 == 0){
    printf("Possible\n");
  }
  else if(b % 3 == 0) {
    printf("Possible\n");
  }
  else {
    printf("Impossible\n");

  }
  


  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int R, G, B, N, ans = 0;
  scanf("%d %d %d %d", &R, &G, &B, &N);
  for(int i = 0; i <= 3000; i++){
    for(int j = 0; j <= 3000; j++){
      int v = R * i + G * j;
      if(N >= v && (N - v) % B == 0) ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1708
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;

int main() {
	char s;
	int count = 0;
	while (cin >> s) {
		if (count % 2 == 0) cout << s ;
		count++;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

int main()
{
	char S[21] = {0};
	scanf("%s", S);

	printf("%c%c%c\n", S[0], S[1], S[2]);
	return 0;
}


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

//#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 100005, mod = 1000000007;
int n, k;
ll cn[MX], res;

ll pot (ll b, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= b) %= mod;
		(b *= b) %= mod;
		p /= 2;
	}
	return res;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> k;

	for (int i = k; i; i--) {
		cn[i] = pot(k / i, n);

		for (int j = 2 * i; j <= k; j += i) {
			cn[i] -= cn[j];
			if (cn[i] < 0) cn[i] += mod;
		}

		(res += i * cn[i]) %= mod;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 4416
/*
 *  * main.cpp
 *   *
 *    */

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<set>
#include<cstring>
#include<string>
#include<cassert>
using namespace std;

long long dp[200003][3];
int main() {
    char s[1000];
    int n;
    char a[1000], b[1000];
    scanf("%d %s %s", &n, a, b);
    int index = 0;
    for (int i = 0; i < n; ++i) s[index++] = a[i], s[index++] = b[i];

    s[index] = '\0';




    printf("%s\n", s);


    return 0;
}


Measured memory_bytes: 256
//Name: The First Acceptance
//Level: 3
//Category: 動的計画法,DP
//Note:

/**
 * B_iの大きい問題を先に解いてから小さい問題を解いても合計時間は変わらないため、B_iの小さい問題から順に解いていけばよい。
 *   dp[i][j] = i問目まででj問のFAを取った時にかかる最短時間
 * とすると、更新式は
 *   dp[i][j] = min(dp[i-1][j], dp[i-1][j-1] + A_i)
 * ただし、minの第2項はB_iを超えてはいけない。
 *
 * オーダーは O(N^2)。
 */
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

template <typename T>
struct Maybe {/*{{{*/
    T val;
    bool valid;

    Maybe() : valid(false) {}
    Maybe(T &t) : val(t), valid(true) {}

    T& operator =(const T &rv) {
        val = rv;
        valid = true;
        return val;
    }
};/*}}}*/

struct Problem {
    int a, b;

    bool operator <(const Problem &p) const {
        return b < p.b;
    }
};

bool solve() {
    int N;
    if(!(cin >> N)) return false;

    vector<Problem> ps(N);
    for(int i = 0; i < N; ++i) {
        cin >> ps[i].a >> ps[i].b;
    }
    sort(begin(ps), end(ps));

    vector<vector<Maybe<long long>>> dp(N, vector<Maybe<long long>>(N+1));
    dp[0][0] = 0LL;
    if(ps[0].b >= ps[0].a) {
        dp[0][1] = ps[0].a;
    }
    for(int i = 1; i < N; ++i) {
        for(int j = 0; j <= N; ++j) {
            dp[i][j] = dp[i-1][j];
            if(j > 0 && dp[i-1][j-1].valid) {
                const long long t = dp[i-1][j-1].val + ps[i].a;
                if(t <= ps[i].b && (!dp[i][j].valid || dp[i][j].val > t)) {
                    dp[i][j] = t;
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i <= N; ++i) {
        if(dp[N-1][i].valid) ans = i;
    }
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1216
n=int(input())
a=list(map(int,input().split()))

babies=[(a,i) for i,a in enumerate(a)]
babies.sort(reverse=True)

dp=[[0]*(n+1) for i in range(n+1)]#左、右から何人いるか dpはl,r埋まってるときの最大スコア 家庭菜園
ans=0
for l in range(n):
    for r in range(n):
        if l+r==n:
            ans=max(ans,dp[l][r])
            break
        activeness,ind=babies[r+l]
        dp[l+1][r]=max(dp[l+1][r],dp[l][r]+abs(ind-l)*activeness)#左を埋める
        dp[l][r+1]=max(dp[l][r+1],dp[l][r]+abs(ind-(n-1-r))*activeness)#右を埋める

print(ans)


Measured memory_bytes: 100660
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 1000000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

int main() {
    int D;
    scanf("%d", &D);
    /* ====================================== */

    if (D == 22) {
        cout << "Christmas Eve Eve Eve";
    } else if (D == 23) {
        cout << "Christmas Eve Eve";
    } else if (D == 24) {
        cout << "Christmas Eve";
    } else if (D == 25) {
        cout << "Christmas";
    }
    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 888
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        sss: [Chars; 3]
    };
    let mut rs = String::new();
    for s in sss {
        rs.push_str(&s[0].to_uppercase().to_string());
    }
    println!("{}", rs);
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int solve(int N){
    int ans = 0;
    int i = 1;

    while (i <= N) {
        if (i % 2) {
            int tmp = 0;
            for (int j = 1; j <= i; j++) {
                if (!(i % j)) tmp++;
            }
            if (tmp == 8) ans++;
        }
        i++;
    }
    return ans;
}

int main(){
  int N;
  cin >> N;
  int ans = solve(N);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;

const int N = 112345;
const int MOD = 1e9 + 7;

inline int getInt() {
  int x;
  scanf("%d", &x);
  return x;
}

int main() {
  int n = getInt();
  vi a(n), b(n);
  for (int &x : a) {
    x = getInt();
  }
  b[1] = abs(a[0] - a[1]);
  for (int i = 2; i < n; i++) {
    b[i] = min(b[i - 1] + abs(a[i] - a[i - 1]), b[i - 2] + abs(a[i] - a[i - 2]));
  }
  printf("%d\n", b[n - 1]);
  return 0;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, M;
    cin >> H >> W >> M;
    vector<int> h(M), w(M);
    rep(i, 0, M) {
        cin >> h[i] >> w[i];
    }
    // yoko
    vector<int> yoko;
    rep(i, 0, M) {
        yoko.push_back(w[i]);
    }
    sort(all(yoko));
    yoko.erase(unique(all(yoko)), yoko.end());
    int yoko_size = (int)yoko.size();
    vector<int> yoko_cnt(yoko_size, 0);
    rep(i, 0, M) {
        ++yoko_cnt[(int)(lower_bound(all(yoko), w[i]) - yoko.begin())];
    }
    // tate
    vector<int> tate;
    rep(i, 0, M) {
        tate.push_back(h[i]);
    }
    sort(all(tate));
    tate.erase(unique(all(tate)), tate.end());
    int tate_size = (int)tate.size();
    vector<int> tate_cnt(tate_size, 0);
    rep(i, 0, M) {
        ++tate_cnt[(int)(lower_bound(all(tate), h[i]) - tate.begin())];
    }
    vector<vector<int>> yoko_pos(tate_size);
    rep(i, 0, M) {
        int h_idx = (int)(lower_bound(all(tate), h[i]) - tate.begin());
        yoko_pos[h_idx].push_back((int)(lower_bound(all(yoko), w[i]) - yoko.begin()));
    }
    int ans = 0;
    multiset<int> others, same;
    rep(i, 0, yoko_size) {
        others.insert(yoko_cnt[i]);
    }
    rep(i, 0, tate_size) {
        // 同じ行のものを分ける
        for (auto& w_idx : yoko_pos[i]) {
            others.erase(others.find(yoko_cnt[w_idx]));
            same.insert(yoko_cnt[w_idx] - 1);
        }
        if (!others.empty()) {
            chmax(ans, tate_cnt[i] + *others.rbegin());
        }
        if (!same.empty()) {
            chmax(ans, tate_cnt[i] + *same.rbegin());
        }
        for (auto& w_idx : yoko_pos[i]) {
            same.erase(same.find(yoko_cnt[w_idx] - 1));
            others.insert(yoko_cnt[w_idx]);
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

	if(sum%10){
		cout<<sum<<endl;
	}else{
		sort(s.begin(), s.end());
		for(int i=0;i<n;i++){
			if(s[i]%10){
				sum-=s[i];
				break;
			}
		}

		if(sum%10)cout<<sum<<endl;
		else cout<<0<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
from itertools import permutations
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
a=0
b=0

for i,p in enumerate(permutations(range(1,N+1))):
    if p==P:
        a = i
    if p==Q:
        b = i

print (abs(a-b))

Measured memory_bytes: 8984
import math

def primelis(n):
    a = []
    if n % 2 == 0:
        a.append(2)
        while n%2==0:
          n=n//2
    f = 3
    while f * f <= n:
      if n%f==0:
        a.append(f)
        while n%f==0:
          n=n//f
    if n != 1:
        a.append(n)
    return a



n=int(input())

A=list(map(int,input().split()))

gcd=A[0]

for i in range(n-1):
  gcd=math.gcd(gcd,A[i+1])

d=[0 for i in range(10**6+1)]

for i in range(2,10**6+1):
  if d[i]==0:
    j=1
    while i*j<=10**6:
      d[i*j]=i
      j+=1

nglis=[0 for i in range(10**6+1)]

if gcd!=1:
  print("not coprime")
else:
  check=0
  for i in range(n):
    if nglis[A[i]]==1:
      check=1
      break
    else:
      ai=A[i]
      while ai!=1:
        j=1
        while d[ai]*j<=10**6:
          nglis[d[ai]*j]=1
          j+=1
        ai=ai//d[ai]
  if check==1:
    print("setwise coprime")
  else:
    print("pairwise coprime")



Measured memory_bytes: 234348
#include <iostream>

using namespace std;

int main()
{
    int n,c=0;
    cin>>n;
    int a[n-1],b[n];
    for(int i=0; i<n-1; i++)
    {
        cin>>a[i];
        if(i==0)
        {
            b[i]=a[i];b[i+1]=a[i];c=c+b[i]+b[i+1];
        }
        else if(a[i]<b[i])
        {
            c=c-b[i];
            b[i]=a[i];
            b[i+1]=a[i];c=c+b[i]+b[i+1];
        }
        else
        {
            b[i+1]=a[i];c=c+b[i+1];
        }
    }cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
from itertools import product
H, W = list(map(int, input().split()))
S = [input() for _ in range(H)]
can = True
S = ['.' * (W + 2)] + ['.' + s + '.' for s in S] + ['.' * (W + 2)]
S = [list(s) for s in S]
dHW = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for h, w in product(range(1, H + 1), range(1, W + 1)):
    if S[h][w] == '#':
        exist = False
        for (dh, dw) in dHW:
            if S[h + dh][w + dw] == '#':
                exist = True
                break
        if exist:
            continue
        else:
            can = False
            break
if can:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 39280
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<cstdlib>
#include<deque>
#include<queue>
#include<bitset>
#include<functional>
#include<utility>
#include<list>
#include<iomanip>
#include<ctime>
#include<cassert>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
const int INF=1e9+1;
int a=-1,b=-1;
int main()
{
	string s;
	cin>>s;
	if(s.size()==2&&s[0]==s[1]) a=1,b=2;
	else if(s.size()>=3)
	for(int i=0;i<s.size()-2;i++)
	{
		int l=s[i],m=s[i+1],r=s[i+2];
		if(l==m||l==r||m==r)
		{
			a=i+1,b=i+3;
			break;
		}
	}
	cout<<a<<" "<<b;
	return 0;
}


Measured memory_bytes: 512
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))

count = 0
for i in range(N):
    if x >= a[i]:
        if i != N-1:
            x -= a[i]
            count += 1
        else:
            if x == a[i]:
                count += 1
    else:
        break
print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxbit = 50;
const int maxn = 100100;
ll cnt[maxbit], n, k;
ll arr[maxn];

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

    ll result = 0LL, sumb = 0LL;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
        result += arr[i];
        for(ll j=0LL;j<=45;j++) {
            if((1LL<<j)&arr[i]) {
                cnt[j]++;
            }
        }
        sumb += (arr[i] ^ k);
    }
    result = max(result, sumb);
    for(ll i=45LL;i>=0LL;i--) {
        // if i is one
        // make this one -> zero
        // on right keep all ones, on left fill optimaly

        if(!(k&(1LL<<i))) continue;

        //cout<<i<<" -\n";

        ll temp = (1LL << i) * cnt[i];
        for(ll j=45LL;j>i;j--) {
            if(k&(1LL<<j)) {
                //cout<<j<<"B: "<<n-cnt[j]<<"\n";
                temp += (1LL << j) * (n - cnt[j]);
            }
            else {
                //cout<<j<<": "<<cnt[j]<<"\n";
                temp += (1LL << j) * cnt[j];
            }
        }

        //cout<<temp<<" -\n ";

        for(ll j=i-1;j>=0LL;j--) {
            ll curr = (1LL << j) * max(cnt[j], n - cnt[j]);
            //cout<<j<<": "<<curr<<"\n";
            temp += curr;
        }
        //cout<<temp<<"\n";
        result = max(result, temp);
    }
    cout<<result<<"\n";

    //cout<<brute_force();

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n,k;
    cin>>n>>k;
    map<int,int> memo;
    rep(i,k){
        int d;
        cin>>d;
        rep(i,d){
            int a;
            cin>>a;
            memo[a]++;
        }
    }
    int Sum=0;
    for(auto itr=memo.begin();itr!=memo.end();itr++){
        Sum++;
    }
    cout<<n-Sum<<endl;
}

Measured memory_bytes: 3608