akhauriyash/Code-Regression huggingface dataset:
N = int(input())
R = []
B = []
R_tmp = []
for _ in range(N):
    a,b = map(int,input().split())
    R_tmp.append(a)
    R.append([a,b])

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

B = sorted(B)
R = sorted(R)
R_tmp.sort()
from bisect import bisect_left
ans = 0
for x in B:
    index = bisect_left(R_tmp,x[0])
    tmp = R[:index]
    tmp = sorted(tmp,key=lambda x:x[1])
    for i in range(index)[::-1]:
        if tmp[i][1] < x[1]:
            R.remove([tmp[i][0],tmp[i][1]])
            R_tmp.remove(tmp[i][0])
            ans += 1
            break
print(ans)



Measured memory_bytes: 3188
//============================================================================
// Name        : AOJCpp.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 100;

void trace(string A[], int n) {
	for (int j = 0; j < n-1; j++) {
		cout << A[j] << " ";
	}

	cout << A[n-1] << endl;
}
string isStable(string input[], string out[], int n) {
	for(int i1 = 0; i1 < n; i1++) {
		for(int i2 = i1+1; i2 < n; i2++) {
			for(int j1 = 0; j1 < n; j1++) {
				for(int j2 = j1+1; j2 < n; j2++) {
					if(input[i1][1] == input[i2][1] && out[j1][1] == out[j2][1] && input[i1][1] == out[j1][1]) {
						string a,b,c,d;
						a=input[i1][0];
						b=input[i2][0];
						c=out[j1][0];
						d=out[j2][0];
						if((a==c || a==d) && (b==c || b==d)) {

							if(input[i1] != out[j1]) {

								return "Not stable";

							}
						}
					}
				}
			}
		}
	}
	return "Stable";
}
void bsort(string a[], int n) {
	string A[n];
	for(int i=0; i < n; i++) {
		A[i] = a[i];
	}
	int i = 0;
	bool flag = 1;
	while(flag&&i<n) {
		bool flag = 0;
		for(int j = n-1; j>i; j--) {
			if(A[j][1] < A[j-1][1]) {
				string tmp = A[j];
				A[j] = A[j-1];
				A[j-1] = tmp;
				flag = 1;
			}
		}
		i++;
	}


	trace(A,n);
	cout << isStable(a,A,n) << endl;
}
void ssort(string a[], int n) {
	string A[n];
	for(int i=0; i < n; i++) {
		A[i] = a[i];
	}
	for(int i = 0; i < n; i++) {
		int minj = i;
		for(int j = i; j < n; j++) {
			if(A[minj][1]>A[j][1]) {
				minj = j;
			}
		}
		if(minj!=i) {
			string tmp = A[minj];
			A[minj] = A[i];
			A[i] = tmp;
		}

	}
	trace(A,n);

	cout << isStable(a,A,n) << endl;
}

int main() {
	int n;
	string A[MAX];

	cin >> n;

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



	bsort(A, n);
	ssort(A, n);


}





Measured memory_bytes: 3152
// ------------------------------------
// Date:2018/ 3/20
// Problem:ARC 076 Reconciled? c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") <<　endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

static const int MOD = 1e9 + 7;
static const int MAX_N = 1e5 + 1;

ll fact[MAX_N];

void init()
{
  fact[0] = 1;
  FOR(i, 1, MAX_N) {
    fact[i] = fact[i - 1] % MOD * i % MOD;
    fact[i] = (fact[i] % MOD + MOD) % MOD;
    // debug(fact[i]);
  }
}

ll power(ll x, ll n)
{
  ll res = 1;
  while(n > 0) {
    if (n & 1) {
      res = (res % MOD) * (x % MOD) % MOD;
    }
    x = (x % MOD) * (x % MOD) % MOD;
    n >>= 1;
    // debug(res);
  }
  return res % MOD;
}

ll inverse(ll n)
{
  return power(n, MOD - 2) % MOD;
}

ll nCr(ll n, ll r)
{
  // debug((fact[n] % MOD));
  // debug(inverse(fact[n - r]));
  // debug(inverse(fact[r]));
  return (fact[n] % MOD) * inverse(fact[n - r])  * inverse(fact[r]) % MOD;
}

int main()
{
  LCIN(N, M);
  init();
  ll ans = 0ll;
  if (abs(N - M) < 2) {
    ans = power(fact[min(M, N)], 2);
    if (N == M) {
      ans = ans % MOD * 2 % MOD;
    } else {
      ans = (ans % MOD) * (max(M, N) % MOD) % MOD;
    }
    ans = (ans % MOD + MOD) % MOD;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

/**
 * https://abc057.contest.atcoder.jp/tasks/abc057_c
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		sc.close();
		
		long a = (int) Math.sqrt(N)+1;
		long b = 0;
		for(long i=a; i>=1; i--){
			if(N%i==0){
				a=i;
				b=N/i;
				break;
			}
		}
		
		System.out.println(Math.max(String.valueOf(a).length(), String.valueOf(b).length()));
		

	}

}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define MAX 105
#define INF (1e8)
int K,N,M;
int T;

bool g[MAX][MAX];
int G[MAX][MAX];
int C[MAX];
int tmp[MAX][MAX];

bool visited[MAX];
bool used[MAX];

void copyA(){
  for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
      tmp[i][j]=G[i][j];
}
void copyB(){
  for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
      G[i][j]=tmp[i][j];
}



int dfs(int pos,int ti,int f){
  if(pos==ti)return f;
  visited[pos]=true;
  for(int tt=-1;tt<T;tt++){
    int to=tt;
    if(to==-1)to=T;
    
    if(visited[to])continue;
    if(G[pos][to]==0)continue;
    
    int k=dfs(to,ti, min(f,G[pos][to]) );
    if(k>0){
      G[pos][to]-=k;
      G[to][pos]+=k;
      return k;
    }
  }
  return 0;
}

int maxFlow(int si,int ti){
  if(si==ti)return INF;
  int res=0;
  while(1){
    memset(visited,false,sizeof(visited));
    int f=dfs(si,ti,INF);
    if(f==0)break;
    res+=f;

  }
  return res;
}
int calcC(int id){
  if(C[id]!=-1)return C[id];
  copyA();
  if(used[id]){
    C[id]=maxFlow(T,id);
  }else{
    C[id]=maxFlow(id,0);
  }
  copyB();
  return C[id];
}

int main(){
  memset(C,-1,sizeof(C));
  
  bool isOverfuro=false;
  cin>>K>>N>>M;
  T=N+K+1;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==0&&1<=b&&b<=K){
      isOverfuro=true;
    }
    if(b==0&&1<=a&&a<=K){
      isOverfuro=true;
    }
    G[a][b]+=c;
    G[b][a]+=c;
    g[a][b]=true;
    g[b][a]=true;
  }
  
  for(int i=1;i<=K;i++){
    G[T][i]=INF;
  }

  if(isOverfuro){
    cout<<"overfuro"<<endl;
    return 0;
  }

  int F=maxFlow(T,0);
  assert(F>0);
  
  memset(visited,false,sizeof(visited));
  dfs(T,0,INF);
  
  for(int i=0;i<=T;i++){
    used[i]=visited[i];
  }

  C[0]=INF;
  
  int ans=0;
  for(int i=0;i<T;i++){
    for(int j=0;j<T;j++){
      if(i==j)continue;
      if(G[i][j]==0&&g[i][j]==true && used[i]==true && used[j]==false ){
        calcC(i);
        calcC(j);
        ans=max(ans, min(C[i],C[j]) );
      }
    }
  }
  cout<<F+ans<<endl;
  return 0;
}

Measured memory_bytes: 1264
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,k) for(i=0;i<k;i++)
#define P pair<int,int>
ll n, k,b,c,i,j,x,y,z=0,m=0;
ll a[100000], yy[100000] = {};
string s;
P p[100000];
vector<ll> v;

int main() {
	cin >> n >> m;
	b = max(n + m, n - m);
	z = max(b, n * m);


	cout << z;
	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
typedef long long llong;
using namespace std;
int N;
llong A[100010],L[100010],R[100010], M[100010], ans;

llong gcd(llong a, llong b)
{
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(a % b, b);
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	L[1] = A[0];
	for (int i = 2; i < N; i++)
	{
		L[i] = gcd(L[i - 1], A[i - 1]);
	}
	R[N - 2] = A[N - 1];
	for (int i = N - 3; i >= 0; i--)
	{
		R[i] = gcd(R[i + 1], A[i + 1]);
	}

	M[0] = R[0], M[N - 1] = L[N - 1];
	for (int i = 1; i <= N - 2; i++)
	{
		M[i] = gcd(L[i], R[i]);
	}

	for (int i = 0; i < N; i++)
	{
		ans = max(ans, M[i]);
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 5100000;

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(){
  int n; string s; cin >> n >> s;
  vi lb(n+1); //lb[i]:iより左にあるblackの数
  vi rw(n+1); //rw[i]:iより右にあるwhiteの数
  rep(i,n) {
    if(s[i] == '#') lb[i+1] = lb[i] + 1;
    else lb[i+1] = lb[i];
  }
  rrep(i,n) {
    if(s[i] == '.') rw[i] = rw[i+1] + 1;
    else rw[i] = rw[i+1];
  }

  int ans = 1e9;
  rep(i,n+1) chmin(ans, lb[i]+rw[i]);
  cout << ans << endl;
}


Measured memory_bytes: 2180
a,b,c = map(int,input().split())
k = int(input())
total = 0
while True:
    if a >= b:
        b = 2*b
        total += 1
    if b>= c:
        c = 2*c
        total += 1
    if a<b and b<c:
        break
if total<=k:
    print('Yes')
else:
    print('No')

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

typedef long long ll;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

ll mod=1e9+7;

using namespace std;


ll inputValue(){
	ll a;
	cin >> a;
	return a;
};

void inputArray(int * p, ll a){
	rep(i, a){
		cin >> p[i];
	}
};

template<typename T>
void inputVector(vector<T>& p, ll a){
	rep(i, a){
		T input;
		cin >> input;
		p.emplace_back(input);
	}
}


template <typename T>
void output(T a) {
	cout << a << "\n";
}

ll count(ll i,ll j, vector<string>& m)
{
	return 0;     
}



int main(int argc, const char * argv[]) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll w,h,x,y;
	cin >> w >> h >> x >> y;
	double ans;
	
	ans = w*h/2.0;

	

	cout <<fixed << setprecision(10) << ans;
	if(w-x==x && h-y==y) 
		cout << " 1" ;
	else 
		cout << " 0" ;
	cout << endl;
	return 0;

}


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

using namespace std;
int dp[100005];

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        dp[i]=dp[i-1]+1;
        int e=1;
        while(i-pow(6,e)>=0){
            int j=i-pow(6,e);
            dp[i]=min(dp[i],dp[j]+1);
            e++;
        }
        e=1;
        while(i-pow(9,e)>=0){
            int j=i-pow(9,e);
            dp[i]=min(dp[i],dp[j]+1);
            e++;
        }
    }
    cout<<dp[n]<<endl;
}

   


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

int main() {
  char s[200099];
  cin >> s;
  
  int a_position = 0;
  int z_position = 0;
  for (int i = 0; i < strlen(s); i++) {
    if (s[i]=='A') {
      a_position = i;
      break;
    }
  }

  for (int i = strlen(s)-1; a_position < i; i--) {
    if (s[i]=='Z') {
      z_position = i;
      break;
    }
  }

  cout << z_position-a_position+1 << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int N, M;
    cin >> N >> M;
    int a[M], b[M];
    int counta[N];
    int i;
    for(i = 0; i < N; i++){
        counta[i] = 0;
    }
    for(i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        counta[a[i]-1]++;
        counta[b[i]-1]++;
    }
    for(i=0; i<N; i++){
        cout << counta[i] << endl;
    }
    
}


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

using namespace std;

long H, W;
vector < string > S;

int dir_x[4] = {0, 1, 0, -1};
int dir_y[4] = {1, 0, -1, 0};

vector<vector<bool> > visited;
vector<vector<long> > dist;

int bfs(long sx, long sy, long tx, long ty){
    queue<long> q;
    q.push(sx*W+sy);
    while(!q.empty()){
        long p = q.front();
        q.pop();

        long x = p/W;
        long y = p%W;
        //cout<<x<<" "<<y<<endl;
        //cout<<x<<" "<<y<<endl;
        for(int idx=0; idx<4; ++idx){
            if(x+dir_x[idx] >=0 && x+dir_x[idx]<H && y+dir_y[idx] >=0 && y+dir_y[idx]<W){
                if(visited[x+dir_x[idx]][y+dir_y[idx]] == false && S[x+dir_x[idx]][y+dir_y[idx]] == '.'){
                    visited[x+dir_x[idx]][y+dir_y[idx]] = true;
                    dist[x+dir_x[idx]][y+dir_y[idx]] = dist[x][y] + 1;
                    if(x+dir_x[idx]==tx && y+dir_y[idx] == ty){
                        return 0;
                    }
                    
                    //cout<<dist[x+dir_x[idx]][y+dir_y[idx]]<<endl;
                    q.push((x+dir_x[idx])*W+(y+dir_y[idx]));
                }
            }
        }
    }
    return 0;
}

int main(){
    cin>>H>>W;
    S.resize(H);
    for(int i=0; i<H; ++i){
        cin>>S[i];
    }

    long ans = 0;
    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j){
            long sx = i;
            long sy = j;
            if(S[sx][sy] == '#'){
                continue;
            }
            //cout<<"s"<<sx<<" "<<sy<<endl;
            for(int k=0; k<H; ++k){
                for(int l=0; l<W; ++l){
                    long tx = k;
                    long ty = l;
                    if(S[tx][ty] == '#'){
                        continue;
                    }
                    if(sx == tx && sy == ty){
                        continue;
                    }
                    //cout<<"t"<<tx<<" "<<ty<<endl;
                    visited = vector<vector<bool> >(H, vector<bool>(W, false));
                    dist = vector<vector<long> >(H, vector<long>(W, 10000000));
                    visited[sx][sy] = true;
                    dist[sx][sy] = 0;
                    bfs(sx, sy, tx, ty);
                    ans = max(ans, dist[tx][ty]);
                    //cout<<ans<<endl;
                    
                }
            }
            
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 384
let () = Scanf.scanf "%d" (fun k ->
  print_endline "50";
  for i = 0 to 49 do
    Printf.printf "%d " @@
      if i < k mod 50 then 51 + i - k mod 50 + k / 50
      else i - k mod 50 + k / 50
  done)

Measured memory_bytes: 384
from collections import deque

D, G = map(int, input().split())
G //= 100
p = [0]
c = [0]
for _ in range(D):
    pi, ci = map(int, input().split())
    p.append(pi)
    c.append(ci // 100)

q = deque()
q.append((0, 0, 0, " "))
ans = float("inf")
while len(q):
    i, m, g, s = q.pop()
    if i != D:
        q.append((i + 1, m, g, s + "0"))
        q.append((i + 1, m + p[i + 1], g + (i + 1)
                  * p[i + 1] + c[i + 1], s + "1"))
        continue

    if g < G:
        j = s.rfind("0")
        if j < 0:
            continue
        if g + j * (p[j] - 1) < G:
            continue
        m += (G - g + j - 1) // j  # ceil

    ans = min(ans, m)

print(ans)


Measured memory_bytes: 3316
H, W, K = map(int, input().split())
c = [[i == '#' for i in input()] for _ in range(H)]

ret = 0
for x in range(1 << W) :
  for y in range(1 << H) :
    s = 0
    for i in range(W) :
      for j in range(H) :
        if x & (1 << i) or y & (1 << j) : continue
        s += c[j][i]
    if s == K :
      ret += 1
      
print(ret)

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

int main()
{
  int N, K, min, i;
  cin >> N >> K;
  min=1;
  for(i=0;i<N;i++)
  {
    if(2*min<min+K)
      min*=2;
    else
      min+=K;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
const ll MINF= -2000000000;
const ll INF = 4000000000000000002;
int main(){
	vector<pair<ll,ll> >xiyi;

	int N,K; SCD2(N,K);
	ll xa[N];
	ll ya[N];

	ll ans = INF;

	REP(i,N){
		ll x,y;
		SCLLD2(x,y);
		xiyi.PB(MP(x,y));
		xa[i] = x;
		ya[i] = y;
	}

	sort(xa,xa+N);
	sort(ya,ya+N);
	
	FORq(i,0,N-2){
		FORq(j,i+1,N-1){
			FORq(k,0,N-2){
				FORq(l,k+1,N-1){
					ll x1,x2,y1,y2;
					x1 = xa[i];
					x2 = xa[j];
					y1 = ya[k];
					y2 = ya[l];

					int count = 0;
					REP(z,N){
						ll X,Y;
						X = xiyi[z].fst;
						Y = xiyi[z].snd;
						if ((X<=x2) && (x1 <= X) && (Y <= y2) && (y1 <= Y)){
							count++;
						}
					}

				if (count >= K) ans = min(ans,min(ans,abs((x2-x1) * (y2-y1))));
				}
			}
		}
	}

	PRINTLLD(ans);
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int n;
  int a;

  scanf("%d", &n);
  scanf("%d", &a);

  if (n % 500 <= a) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {	
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int N = fs.nextInt();
		int d[] = new int[N];

		for(int i=0; i<N; i++){
			d[i] = fs.nextInt();
		}
		Arrays.sort(d);

		int count = 1;
		for(int i=0; i<N; i++){
			if(i+1<N&&d[i]<d[i+1])
			count++;
		}

		System.out.println(count);


		

	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");

		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) {
				a[i]=nextInt();
			}
			return a;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}
	
}


Measured memory_bytes: 23124
#include<iostream>
using namespace std;
int main()
{
    long long n,i,j,three=0,total,five=0;
    cin>>n;
    for(i=3;i<=n;i+=3)
    {
        three+=i;
    }
    for(j=5;j<=n;j+=5)
    {
        if(j%3!=0)
        {
            five+=j;
        }
    }
    total=(n*(n+1))/2;
    total=total-(three+five);
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 3500
from collections import deque
S=deque(list(input()))
Q=int(input())
rev=1

for _ in range(Q):
  q=input().split()
  if q[0]=="1":
    rev*=-1
  else:
    F,C=int(q[1]),q[2]
    if F==1:
      if rev==1:
        S.appendleft(C)
      else:
        S.append(C)
    else:
      if rev==1:
        S.append(C)
      else:
        S.appendleft(C)

if rev==-1:
  S.reverse()
print("".join(list(S)))

Measured memory_bytes: 8548
#include <bits/stdc++.h>
using namespace std;
int main(){
 long long int n,m,x;
  cin >> n >> m >>x;
  long long int c[n];
  long long int a[n][m];
  bool safe=false;
  long long int answ=LLONG_MAX;
  for(long long int i=0;i<n;i++){
    cin >> c[i];
    for(long long int j=0;j<m;j++){
      cin >> a[i][j];
    }
  }
  for (long long int bit = 0; bit < (1<<n); ++bit) {
        long long int ans[m];
    long long int temp=0;
    for(long long int j=0;j<m;j++)ans[j]=0;
    for (int i = 0; i < n; ++i) {
        if (bit & (1<<i)) { // 列挙に i が含まれるか
          temp+=c[i];
            for(long long int j=0;j<m;j++){
			  ans[j]+=a[i][j];
    		}
        }
    }
	bool ok=true;
        for (long long int j=0;j<m;j++) {
            if(ans[j]<x)ok=false;
        }
        if(ok){
          safe=true;
          answ=min(answ,temp);
        }
    
    }
  if(safe)cout << answ <<endl;
  else cout << -1 <<endl;
}

Measured memory_bytes: 3512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int main(void){
  int n,k;
  scanf("%d %d",&n,&k);
  int a[n];
  FOR(n)scanf("%d",&a[i]);
  qsort(a,n,sizeof(int),u);
  int ans=a[n-1]-a[0];
  FOR(n-k+1)ans=min(ans,a[i+k-1]-a[i]);
  PRN(ans);
  return 0;
}


Measured memory_bytes: 892
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

s = ['Sunny', 'Cloudy', 'Rainy']
a = s[(s.index(input()) + 1) % 3]
print(a)


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

using namespace std;

int main() {
	string str;

	cin >> str;

	int ans = 0,cnt = 0;
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == 'A' || str[i] == 'T' || str[i] == 'G' || str[i] == 'C') {
			cnt++;
		}
		else {
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);

	cout << ans << endl;

	return 0;
}

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

int main()
{
    int N, K, x, A, B;
    cin >> N >> K;
    int sum = 0;

    for(int i=0; i<N; i++){
        cin >> x;
        A = x * 2;
        B = (K - x) * 2;
        if(A >= B)
            sum += B;
        else
            sum += A;
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 256
from copy import deepcopy
n = int(input())
s = []
for i in range(n):
    s.append(list(input()))

alp_origin = []
for i in range(ord("a"), ord("z")+1):
    alp_origin.append(chr(i))

alp = deepcopy(alp_origin)

for i in range(n):
    for a in alp_origin:
        if not(a in s[i]) and a in alp:
            alp.remove(a)

if len(alp) == 0:
    print("")
    exit()

cnt = [100] * len(alp)

for i in range(len(alp)):
    for j in range(n):
        cnt[i] = min(cnt[i], s[j].count(alp[i]))

ans = ""

for i in range(len(alp)):
    for j in range(cnt[i]):
        ans += alp[i]

print(ans)





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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll A, B, C, D;
map<ll, ll> ma;

ll solve_sub(ll N)
{
	if (N == 0) return 0;
	if (ma.count(N)) return ma[N];
	ll res;
	if (N <= 3e9) res = N*D;
	else res = INF;

	for (ll i = -1; i <= 1; ++i)
	{
		ll x = N + i;
		if (x < 0 || x % 2 != 0) continue;
		ll y = x/2;
		if (y < N)
			res = min(res, abs(i)*D + A + solve_sub(y));
	}
	for (ll i = -2; i <= 2; ++i)
	{
		ll x = N + i;
		if (x < 0 || x % 3 != 0) continue;
		ll y = x/3;
		if (y < N)
			res = min(res, abs(i)*D + B + solve_sub(y));
	}
	for (ll i = -4; i <= 4; ++i)
	{
		ll x = N + i;
		if (x < 0 || x % 5 != 0) continue;
		ll y = x/5;
		if (y < N)
			res = min(res, abs(i)*D + C + solve_sub(y));
	}

	return ma[N] = res;
}


ll solve()
{
	ll N; cin >> N;
	cin >> A >> B >> C >> D;
	ma.clear();
	return solve_sub(N);
}

int main(int argc, char **argv)
{
	ll T; cin >> T;
	REP(i, T)
	{
		std::cout << solve() << std::endl;
	}
}


Measured memory_bytes: 4356
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define f0(i,n)for(ll i=0;i<n;i++)
#define f0r(i,n)for(ll i=n-1;i>=0;i--)
#define fc(i,c,n,s)for(ll i=c;i<=n;i+=s)
#define fcr(i,c,n,s)for(ll i=n;i>=c;i-=s)
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef list<ll> LST;
typedef vector<ll> VEC;
typedef map<ll, ll> MAP;

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif
	ll n, h, k;
	cin >> n >> k;
	VEC v(n);
	for (auto& i : v) {
		cin >> i;
	}
	sort(v.rbegin(), v.rend());
	ll ans = 0;
	for (auto& i : v) {
		if (k) {
			k--;
		}
		else {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int linear_search(int *S, int n, int key){
  S[n] = key;
  int i=0;
  while(S[i] != key) i++;
  if(i == n) return -1;
  return i;
}

int main(){
  int n, q, C=0;
  int S[10001];
  
  cin >> n;
  for(int i=0; i<n; i++)
    cin >> S[i];
  cin >> q;
  for(int i=0; i<q; i++){
    int t;
    cin >> t;
    if(linear_search(S, n, t) >= 0) C++;
  }

  cout << C << endl;
  return 0;
}



Measured memory_bytes: 3100
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

int n, m;

bool safe(int x, int y)
{
	return x >= 0 && x < n&&y >= 0 && y < m;
}

int main()
{
	//freopen("input.txt", "r", stdin);

	vector<string> grid;
	int sx, sy;
	int tx, ty;
	const int dx[4] = { 0,0,-1,1 };
	const int dy[4] = { -1,1,0,0};
	const int mx[20] = { -2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2 ,-2,-1,0,1,2 };
	const int my[20] = { -2,-2,-2,-2,-2,-1,-1,-1,-1,0,0,1,1,1,1 ,2,2,2,2,2 };

	scanf("%d %d %d %d %d %d", &n, &m, &sx, &sy, &tx, &ty);
	sx--;
	sy--;
	tx--;
	ty--;

	for (int i = 0; i < n; i++)
	{
		char input[1001];

		scanf("%s", input);
		string str = input;

		grid.push_back(str);
	}

	priority_queue<pair<int,pair<int, int>>> pq;

	int sol[1001][1001];

	memset(sol, -1, sizeof(sol));

	sol[sx][sy] = 0;

	pq.push({ 0,{ sx,sy } });

	while (!pq.empty())
	{
		const int val = -pq.top().first;
		const int x = pq.top().second.first;
		const int y = pq.top().second.second;
		pq.pop();

		if ((x == tx && y == ty) || val > sol[x][y])
		{
			continue;
		}

		for (int i = 0; i < 4; i++)
		{
			const int nx = x + dx[i];
			const int ny = y + dy[i];

			if (safe(nx, ny) && grid[nx][ny]=='.' && (sol[nx][ny] == -1 || val < sol[nx][ny]))
			{
				sol[nx][ny] = val;

				pq.push({ -val,{nx,ny} });
			}
		}

		for (int i = 0; i < 20; i++)
		{
			const int nx = x + mx[i];
			const int ny = y + my[i];

			if (safe(nx, ny) && grid[nx][ny] == '.' && (sol[nx][ny] == -1 || val + 1 < sol[nx][ny]))
			{
				sol[nx][ny] = val + 1;

				pq.push({ -(val + 1),{ nx,ny } });
			}
		}
	}

	printf("%d\n", sol[tx][ty]);

	return 0;
}

Measured memory_bytes: 8352
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1)
    a=14;
    if(b==1)
    b=14;
    if(a>b)
    cout<<"Alice"<<endl;
    else if(a==b)
    cout<<"Draw"<<endl;
    else
    cout<<"Bob"<<endl;
    return 0;
}

 
 

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int a, b;
    cin >> a >> b;
    vector<string> vec(a);
    rep(i, a) cin >> vec[i];

    vector<int> yoko(a, 0);
    vector<int> tate(b, 0);

    rep(i, a)
    {
        rep(j, b)
        {
            if (vec[i][j] == '#')
            {
                yoko[i]++;
                tate[j]++;
            }
        }
    }

    rep(i, a)
    {
        if (yoko[i])
        {
            rep(j, b)
            {
                if (tate[j])
                {
                    cout << vec[i][j];
                }
            }
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
S = list(input())
odd = ['R','U','D']
even  = ['L','U','D']
for i in range(len(S)):
    if i % 2 == 0 : #奇数
        if S[i] not in odd :
            print("No")
            exit()
    else:
        if S[i] not in even:
            print("No")
            exit()
print("Yes")

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

int main() {
  int A, B, T;
  cin >> A >> B >> T;
  
  int bis = 0;
  double sheet = 0;
  
  sheet = (T + 0.5) / A;
  bis = (int)sheet * B;
    cout << bis << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> a(m);
  for(int i=0;i<m;i++){
    cin>>a[i];
  }
  cout<<min(lower_bound(a.begin(),a.end(),x)-a.begin(),a.end()-upper_bound(a.begin(),a.end(),x));
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>

int main(){
	std::string str, tbd = "2019/04/30";
	std::cin >> str;
	if(str <= tbd){
		std::cout << "Heisei" << std::endl;
	}else{
		std::cout << "TBD" << std::endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#define int long long
using namespace std;

signed main() {
    int n, a, b;
    int ans = 0;
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++) {
        int c = 0;
        c += i % 10;
        c += i / 10 % 10;
        c += i / 100 % 10;
        c += i / 1000 % 10;
        c += i / 10000;
        if (a <= c && c <= b) {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        String line = sc.nextLine();

        for (int i = 0; i < line.length(); i++) {
            char c = line.charAt(i);
            String str;

            if (Character.isLowerCase(c)) {
                str = Character.toString(c).toUpperCase();
            } else if (Character.isUpperCase(c)) {
                str = Character.toString(c).toLowerCase();
            } else {
                str = Character.toString(c);
            }

            System.out.print(str);
        }
        System.out.println();

        sc.close();
    }
}


Measured memory_bytes: 27048
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

bool palindrome(string& s){
  for(int i = 0; i < s.length() / 2; i++){
    if(s[i] != s[s.length() - i - 1]){
      return false;
    }
  }
  return true;
}

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

  string s;
  cin >> s;

  if(palindrome(s)){
    cout << 0 << endl;
    return 0;
  }

  string t;
  for(int i = 0; i < s.length(); i++){
    if(s[i] != 'x') t.push_back(s[i]);
  }

  if(!palindrome(t)){
    cout << -1 << endl;
    return 0;
  }

  int count = 0;
  int i = 0, j = s.length() - 1;
  while(i < j){
    if(s[i] == s[j]){
      ++i;  --j;
    }
    else{
      ++count;
      if(s[j] == 'x') --j;
      else ++i;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 704
<?php
define("MOD", 10 ** 9 + 7);
list($n, $p) = ints();
$a = ints();
$cntNoun = $cntOdd = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($a[$i] % 2) ++$cntOdd;
    else ++$cntNoun;
}
// 偶数個の袋は選び方は何でも良い
$k = 2 ** $cntNoun;
init($n);
if ($p) {
    // 奇数個の袋は奇数個選ぶ
    $t = 0;
    for ($i = 1; $i <= $cntOdd; $i += 2) $t += nCr2($cntOdd, $i);
} else {
    // 奇数個の袋は偶数個選ぶ
    $t = 0;
    for ($i = 0; $i <= $cntOdd; $i += 2) $t += nCr2($cntOdd, $i);
}
echo $k * $t;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return modMul($n, modFac($n - 1));
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return modMul(nPr($n, $r - 1), $n - $r + 1);
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modDiv(nPr($n, $r), modFac($r));
}

// 階乗、逆元を前処理
function init($n)
{
    global $fact, $ifact;
    $fact[0] = 1;
    for ($i = 1; $i <= $n; ++$i) $fact[$i] = modMul($fact[$i - 1], $i);
    $ifact[$n] = modDiv(1, $fact[$n]);
    for ($i = $n; $i >= 1; --$i)
        $ifact[$i - 1] = modMul($ifact[$i], $i);
}

// 順列（前処理）
function nPr2($n, $r)
{
    global $fact, $ifact;
    return modMul($fact[$n], $ifact[$n - $r]);
}

// 組み合わせ（前処理）
function nCr2($n, $r)
{
    global $fact, $ifact;
    return modMul(modMul($fact[$n], $ifact[$r]), $ifact[$n - $r]);
}


Measured memory_bytes: 16288
import java.util.Scanner;

public class Main{
    public static void main(String[] arg){
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        
        System.out.println(Math.min(a+b,Math.min(b+c, c+a)));
        
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
long long n,sum,a[13]; 
long long dfs(long long x,long long sum,long long sum1)
{
    if(x==1)
        return 2*sum+sum1+a[x]+sum1*10+a[x];
    return dfs(x-1,sum,sum1*10+a[x])+dfs(x-1,sum+sum1,a[x]); 
}
int main()
{
    cin>>n;
    while(n!=0)
        sum++,a[sum]=n%10,n/=10;
    cout<<dfs(sum,0,0)/2;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    for(int i = 0; i < n; i++) {
        cout << g[i].size() << "\n";
    }
}

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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)

using namespace std;

//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

void solve()
{
    int n, z, w;
    cin >> n >> z >> w;
    int a[n];
    REP(i, n) cin >> a[i];
    if(n == 1) {
        cout << abs(a[0] - w) << endl;
    }
    else{
        cout << max(abs(a[n-1] - w), abs(a[n-1]-a[n-2])) << endl;
    }
}

int main()
{
    solve();
    return 0;
}

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

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


Measured memory_bytes: 1792
//If you are reading this then you are at wrong place.
#include<bits/stdc++.h>
#define mod 1000000007
#define lli long long int
using namespace std;
bool prime [1000001];
void debug(lli a){cout<<a<<endl;}
lli sieve(lli a){memset(prime,true,sizeof(prime));lli p,i;for(p=2;p*p<=a;p++){if(prime[p]==true){for(i=p*2;i<=a;i+=p)prime[i]=false;}}return 0;}
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli find_max(lli __a,lli __b){return __a^((__a^__b) & -(__a<__b));}
lli add(lli __a,lli __b,lli MOD){lli x = (__a+__b)%MOD; return x; }
lli mul(lli a,lli b,lli MOD){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b,lli MOD){lli x = (a-b+MOD)%MOD; return x; }
lli div(lli a,lli b,lli MOD){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}
int n;
int a[10];
int check(int n)
{
	int ans=n;
	int flag=0;
	while(ans>0)
	{
		if(a[ans%10]==1)
			flag=1;
		ans/=10;
	}
	if(flag==0)
		return 1;
	else
		return 0;
}
int solve()
{
	while(1)
	{
		if(check(n)==1)
			break;
		n++;
	}
	cout<<n<<endl;
}
int main()
{
	//ifstream cin("testcase.txt");
	//ofstream cout("output.txt");	
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);	
	cout.precision(20);
	lli t,i,j;
	//cin>>t;
	//memset(dp, -1, sizeof dp);
	t=1;
	lli counter1=0;
	while(t--)
	{
		counter1++;
		int k;
		cin>>n>>k;
		int x;
		memset(a,0,sizeof a);
		for(i=0;i<k;i++)
		{
			cin>>x;
			a[x]=1;
		}
		solve();
		
		//cout<<"Case #"<<counter1<<" ";
		//cout<<endl;	
	}	
}


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

int main(){
  long long h,w,ans=0;
  cin >> h >> w;
  char c[h][w];
  long long yoko[h][w]={},tate[h][w]={};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c[i][j];
    }
  }
  for(int i=0;i<h;i++){
    long long cnt=0;
    for(int j=0;j<w;j++){
      if(c[i][j]=='.'){
        cnt++;
        yoko[i][j]=cnt;
      }else{
        cnt=0;
        yoko[i][j]=0;
      }
    }
    cnt=0;
    for(int j=w-1;j>=0;j--){
      if(yoko[i][j]==0){
        cnt=0;
      }else{
        cnt=max(cnt, yoko[i][j]);
        yoko[i][j]=cnt;
      }
    }
  }
  for(int i=0;i<w;i++){
    long long cnt=0;
    for(int j=0;j<h;j++){
      if(c[j][i]=='.'){
        cnt++;
        tate[j][i]=cnt;
      }else{
        cnt=0;
        tate[j][i]=0;
      }
    }
    cnt=0;
    for(int j=h-1;j>=0;j--){
      if(tate[j][i]==0){
        cnt=0;
      }else{
        cnt=max(cnt, tate[j][i]);
        tate[j][i]=cnt;
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans=max(ans, yoko[i][j]+tate[i][j]-1);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 66688
X, Y, Z, K = [int(x) for x in input().split()]
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
ABC = []
for a in range(len(A)):
    for b in range(len(B)):
        if (a+1)*(b+1) > K:
            break
        for c in range(len(C)):
            if (a+1)*(b+1)*(c+1) > K:
                break
            ABC.append(A[a] + B[b] + C[c])
ABC = sorted(ABC, reverse=True)
for i in range(K):
    print(ABC[i])

Measured memory_bytes: 9544
#include <iostream>
#include <string>

using namespace std;
int main() {
    string S, T;
    cin >> S >> T;

    int res = 0;
    for(int i = 0; i < 3; i++) {
        if(S[i] == T[i]) {
            res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException {
		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str=bfr.readLine();
		String[] mj=str.split(" ");
		int a=Integer.parseInt(mj[0]);
		int b=Integer.parseInt(mj[1]);
		/*boolean ts1=false;
		boolean ts2=false;
		for(int i=1; i<=b-a; i++) {
			ts1=false; ts2=false;
			ts1=isTsumori(a+i);
			ts2=isTsumori(b+i);
			if(ts1==true && ts2==true) {
				System.out.println(i);
				System.exit(0);
			}
		}*/
		int wa=0;
		for(int i=1; i<999; i++) {
			wa+=i;
			if(wa-a>0 && wa+i+1-b>0 && wa-a==wa+i+1-b) {
				System.out.println(wa-a);
			}
		}
	}

	public static boolean isTsumori(int a) {
		for(int i=1; i<=999; i++) {
			if(a==i*(i+1)/2) {
				return true;
			}
			else if(a<i*(i+1)/2) {
				return false;
			}
		}
		return false;
	}


}

Measured memory_bytes: 20948
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------
ll N, M, A[100000 + 100];
ll csum[100000 + 1000];
//f(x) := x以上となる握手を全部やって、(何回の握手, その時の幸せ度)になるか
pair<ll,ll> f(ll x){
    ll sum=0;
    ll ha=0;
    for(int i=0;i<N;i++){
        ll now=(lower_bound(A, A+N, x-A[i]-1, greater<ll>())-A);
        sum+=now;
        ha+=(csum[now]+A[i]*now);
    }
    return mp(sum,ha);
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    cin >> N >> M;
    for (int i = 0; i < N; i++)cin >> A[i];
    sort(A, A + N, greater<ll>());
    csum[0] = 0;
    for (int i = 0; i < N; i++)csum[i + 1] = csum[i] + A[i];
    ll l = 0, u = 100000000000;
    while (u - l > 1) {
        ll mid = (l + u) / 2;
        if (f(mid).first < M)u = mid;
        else l = mid;
    }
    cout << f(l).second - (f(l).first - M) * l << endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef int32_t i32;

#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>=b;i--)
#define FILL(a,b,c) for(ll i=0;i<c;i++) a[i]=b;

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

#define endl "\n"
#define setpri(x) setprecision(x)
#define vp(x) cout<<#x<<" : "<< (x)<<" | "
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define forf(i,a,b) for(int i=a;i<b;i++)

#define INF 1e17+4
#define MINF 
#define MAX_INT 100000
#define MOD 1000000007
ll mod(ll n) { n %= MOD; if (n < 0) return n + MOD; else return n;}
vector<int> adj[1000002];
int vis[1000002],dep[1000002],siz[1000002];

// void dfs(ll cur,ll par)
// {
//     vis[cur]=1;siz[cur]=1;
//     for(auto x:adj[cur])
//     {
//         if(vis[x]!=1)
//         {
//             dep[x]=dep[cur]+1;
//             dfs(x,cur);
//             siz[cur]+=siz[x];
//         }    
//     }
// }

// bool sortfunc(const pair<int,int> &a, const pair<int,int> &b) 
// { 
//     return ;
// }

void solve()
{
    int n,k;
    cin>>n>>k;
    int h[n+1];
    forf(i,1,n+1) cin>>h[i];
    forf(i,0,k)
    {
        int x,y;cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int cnt=0;
    forf(i,1,n+1)
    {
        int el=h[i];
        bool fg=true;
        for(auto x:adj[i])
        {
            if(h[x]>=el)
            {
                fg=false;break;
            }    
        }
        if(fg)
            cnt++;
    }
    cout<<cnt;
    
    
    
    
}

signed main()
{
    FAST;
    
    // ll t;cin>>t;while(t--)
        solve();
 
    return 0;
}

Measured memory_bytes: 31384