akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  string S, T;
  cin>>S>>T;
  int N=S.size();
  vector<char> Scopy(2*N);
  vector<char> Tcopy(N);
  bool onaji=false;
  int count=0;
  for(int i=0; i<2*N; i++){
    if(i<N){
      Scopy.at(i)=S.at(i);
      Tcopy.at(i)=T.at(i);
    } //if
    else Scopy.at(i)=S.at(i-N); //2周分
  } //i
  for(int i=N; i>0; i--){
    for(int j=0; j<N; j++){
      if(Tcopy.at(j)==Scopy.at(j+i)) count++; //Nから、N-1から、、、1から
    } //j
    if(count==N){
      onaji=true;
      break;
    }
    count=0;
  }
  if(onaji) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
C = [[] for _ in range(H)]
for i in range(H):
    C[i] = input()
ans = 0
for h_bit in range(1<<H):
    h_bit = list(bin(h_bit)[2:].zfill(H))
    for w_bit in range(1<<W):
        w_bit = list(bin(w_bit)[2:].zfill(W))
        count = 0
        for i in range(H):
            if h_bit[i] == '1':
                continue
            for w in range(W):
                if w_bit[w] == '1':
                    continue
                if C[i][w] == '#':
                    count += 1
        if count == K:
            ans += 1
print(ans)

Measured memory_bytes: 69488
from collections import deque
n = int(input())
l = [0 for i in range(n)]
l2 = []
l3 = [[] for i in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    l2.append([a,b])
    l3[a].append(b)
    l3[b].append(a)
    l[a-1] += 1
    l[b-1] += 1
a = max(l)
print(a)
rl = [0 for i in range(n+1)]
d = deque()
d.append([1,0])
rl[1] = 1
dic = {}
while len(d):
    now,c = d.popleft()
    rl[now] = 1
    if c == 0:
        count = 1
        for i in l3[now]:
            dic["{0},{1}".format(now,i)] = count
            d.append([i,count])
            count += 1
    else:
        count = 1
        for i in l3[now]:
            if rl[i] == 0:
                if c == count:
                    count += 1
                dic["{0},{1}".format(now,i)] = count
                d.append([i,count])
                count += 1
for i in range(n-1):
    print(dic["{0},{1}".format(l2[i][0],l2[i][1])])

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

int N, C;
int d[500][500];
int f[500][500];
int cost[3][30];
void pre() {
  for (int c = 0; c < C; ++c) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        cost[(i + j) % 3][c] += d[f[i][j]][c];
      }
    }
  }
}

int main() {
  cin >> N >> C;
  for (int i = 0; i < C; ++i) {
    for (int j = 0; j < C; ++j) {
      cin >> d[i][j];
    }
  }
  
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> f[i][j];
      --f[i][j];
    }
  }
  pre();
  
  long mn = 1e10;
  for (int a = 0; a < C; ++a) {
    for (int b = 0; b < C; ++b) {
      if (a == b) continue;
      for (int c = 0; c < C; ++c) {
        if (b == c) continue;
        if (a == c) continue;
        
        long sum = 0;
        sum += cost[0][a];
        sum += cost[1][b];
        sum += cost[2][c];
        mn = min(mn, sum);
      }
    }
  }
  cout << mn << endl;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,m,q,vis[100005],par[100005];
vii v;
int fp(int node){
	if(par[node]==node) return node;
	else return par[node]=fp(par[node]);
}
void merge(int a,int b){
	a=fp(a);
	b=fp(b);
	par[a]=b;
}
void solve(){
	cin>>n>>m>>q;
	rep(i,1,n+1) par[i]=i;
	rep(i,0,q){
		int a,b,c;
		cin>>a>>b>>c;
		a++;
		b++;
		if(c==0){
			merge(a,b);
			vis[a]=1;
			vis[b]=1;
		}
		else v.pb({a,b});
	}
	for(auto i:v){
		if(fp(i.x)==fp(i.y)){
			cout<<"No"<<endl;
			return;
		}
	}
	int rem=0,roots=0;
	rep(i,1,n+1){
		if(vis[i]==0) rem++;
		else if(fp(i)==i) roots++;
	}
	int edges=n-rem-roots;
	if(edges+(rem+roots)*(rem+roots-1)/2<m){
		cout<<"No"<<endl;
		return;
	}
	if(sz(v)==0){
		if(edges>m) cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
		return;
	}
	if(roots==2){
		if(rem==0){
			cout<<"No"<<endl;
			return;	
		}
		else{
			edges+=3;
			if(edges>m) cout<<"No"<<endl;
			else cout<<"Yes"<<endl;
			return;
		}
	}
	set<int> st2;
	for(auto i:v){
		int a=fp(i.x);
		int b=fp(i.y);
		st2.insert(a);
		st2.insert(b);
	}
	if(sz(st2)==2) edges+=3;
	else edges+=sz(st2);
	if(edges>m){
		cout<<"No"<<endl;
		return;
	}
	cout<<"Yes"<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
    // cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 7280
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 1e6 + 10;

vector<int> D(MAX,INF);

void sieve(){

	D[1] = 1;

	for(int i = 2; i < MAX; i++){
		if(D[i] != INF) continue;
		D[i] = i;
		for(int j = 2; j * i < MAX; j++) D[j*i] = min(D[i*j], i);
	}

}

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

	sieve();

	int N;
	cin >> N;

	vector<int> V(N);

	unordered_set<int> GG;

	vector<unordered_set<int>> DIV(N);

	bool pc = 1;
	int sc;

	int i = 0;
	for(auto &x : V) {
		cin >> x;

		if(!i) sc = x;
		else sc = __gcd(sc,x);

		while(x != 1){
			DIV[i].insert(D[x]);
			x /= D[x];
		}

		for(auto y : DIV[i]){
			if(GG.count(y)) pc = 0;
			GG.insert(y);
		}		

		i++;
	}

	if(pc){
		cout << "pairwise coprime\n";
		return 0;
	}

	cout << (sc != 1? "not coprime" : "setwise coprime") << endl;
	return 0;
}


Measured memory_bytes: 277984
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    int N; cin >> N;
    vpl data;
    F0R(i, N) {
        int A, B; cin >> A >> B;
        data.pb(mp(-1*B, A));
    }
    sort(all(data));
    ll totalTime = 0;
    ll lastTime = -1;
    F0R(i, sz(data)) {
        ll start = data[i].f * -1;
        ll time = data[i].s;
        if (lastTime > 0) {
            totalTime -= (lastTime - start);
            totalTime = max(totalTime, 0LL);
        }
        lastTime = start;
        totalTime += time;
        if (totalTime > start) {
            cout << "No" << endl;
            return 0;
        }
    }
    if (totalTime > lastTime) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

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

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

    if (k == 0)
    {
        cout << n*n << endl;
        return 0;
    }

    long long int count = 0;
    for (int b=1; b <= n; ++b)
    {
        long long int temp = n/b*(b-k);
        if (temp > 0)
        {
            count += temp;
        }

        temp = n%b-(k-1);
        if (temp > 0)
        {
            count += temp;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
ans = 193934993409409
for mask in range(2 ** n):
    C = [0] * m
    cst = 0
    for i in range(n):
        if (mask >> i) & 1:
            cst += X[i][0]
            for j in range(1, m + 1):
                C[j - 1] += X[i][j]
    if min(C) >= x:
        ans = min(ans, cst)
if ans < 91912922191:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9216
#include <algorithm>
#include <iostream>
#include <string>
 
using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)
 
using namespace std;
 
// 158 - c
int main(void) {
    int n;
    cin >> n;
 
    bool flg = false;
 
    while (n > 0) {
        int val = n % 10;
        if (val == 7) {
            flg = true;
            break;
        }
        n /= 10;
    }
 
    if (flg)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
 
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn=100005;
int n;
int a[maxn];
int dp[maxn];
int Max;
void init()
{
   Max=1;
   dp[0]=a[0];
}
int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++)
        scanf("%d",&a[i]);
    init();
    for (int i=1;i<n;i++)
    {
        if(dp[Max-1]<a[i])
            dp[Max++]=a[i];
        else
            *lower_bound(dp,dp+Max,a[i])=a[i];
    }
    printf("%d\n",Max);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  
  sort (d.begin(), d.end());
  reverse (d.begin(), d.end());
  
  int r = 1;
  
  for (int i = 0; i < N - 1; i++) {
    if (d.at(i) == d.at(i + 1)) continue;
    else if (d.at(i) > d.at(i + 1)) r++;
    else break;
  }
  cout << r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int maxn=101000;
typedef long long ll;
int len;
int fac[10]= {1,1,2,6,24,120,720,5040,40320};
ll check(int a[]){
    ll res=0;
		for(int i=0;i<len;i++) {
			int temp=0;
			for(int j=i+1;j<len;j++) {
				if(a[i]>a[j]) temp++;
			}
			res+=temp*fac[len-i-1];
		}
		return res+1;
}
int a[10],b[10];
int main()
{

    scanf("%d",&len);
    for(int i=0;i<len;i++)
        scanf("%d",&a[i]);
    for(int i=0;i<len;i++)
        scanf("%d",&b[i]);
    cout<<abs(check(a)-check(b));
    return 0;
}
/*
3
10 3
1 2 3
0 1 2
100 7
3 4 5 6 7 8 9
1 2 3 4 5 6 7
10000 10
1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9
*/



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ll N; cin>>N;
  vector<ll> A(N); rep(i,N) cin>>A[i];
  
  ll ans=0; ll judge=0;
  rep(i,N){
    if(A[i]>=judge) judge=A[i];
    else ans+=judge-A[i];
  }
  
  cout<<ans<<endl;
  return 0;
}

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

int main() {
    ll n;
    cin >> n;
    ll ans;
    for (int i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            ans = i + n / i - 2;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

	int x, y;

	while (true) {

		cin >> x >> y;

		if ((x == 0) && (y == 0)) break;

		if (x < y) cout << x << " " << y << endl;
		else if (x > y) cout << y << " " << x << endl;
		else cout << x << " " << y << endl;

	}

	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
map<string, llint> mp;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	string s;
	for(int i = 1; i <= n; i++){
		cin >> s;
		mp[s]++;
	}
	cout << "AC x " << mp["AC"] << endl;
	cout << "WA x " << mp["WA"] << endl;
	cout << "TLE x " << mp["TLE"] << endl;
	cout << "RE x " << mp["RE"] << endl;
	
	return 0;
}

Measured memory_bytes: 3664
from operator import itemgetter

n = int(input())
a = []

for i in range(n):
    s,p = input().split()
    a.append((s,int(p),i+1))

b = sorted(a,key=itemgetter(1),reverse=True)
xs = sorted(b,key=itemgetter(0))
for x in xs:
    print(x[2])

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c; cin>>a>>b>>c;
	cout<<((c-a)*(b-c)>0?"Yes":"No")<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#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;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
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 SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int
 
#define P pair<int,int>
#define V vector<ll>
#define M map<int,int>
#define S set<int>
#define L list<int>
 
#define pb(a) push_back(a)
#define mp make_pair

V h;
ll n,a,b;
bool Nibutan(ll inp){
  
  ll poll =inp;
  REP(i,n){
    ll poi = max(0LL, h[i] - b*inp);
    poll -= (poi + a - 1) / a;
  }
  // dump(poll);
  return (poll >= 0);
}

int main(){
  cin>>n>>a>>b;h=V(n);VECCIN(h);
  a-=b;
  ll max_=1e9;ll min_=0;//minは自明にNo maxは自明にYes
 
  while(max_-min_>1){
    ll cent= min_ + (max_-min_)/2;
    bool ttt = Nibutan(cent);
    if(ttt)max_ = cent;
    else min_ = cent;
    //dump(max_);
    //dump(min_);
  }
  COUT(max_);

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int H,W;cin >> H >> W;
  vector<int> nums(26,0);
  rep(x,W) rep(y,H){
    char c;cin >> c;
    ++nums[c-'a'];
  }
  int x = 0;
  int y = 0;
  rep(i,26){
    if(nums[i]%4==2) ++x;
    if(nums[i]%2==1) ++y;
  }
  bool sat = true;
  if(H%2 == 0 && W%2 == 0) if(x!=0 || y != 0)sat = false;
  if(H%2 == 0 && W%2 == 1){
    if(y!=0)sat = false;
    if(x>H/2)sat = false;
  }
  if(H%2 == 1 && W%2 == 0){
    if(y!=0)sat = false;
    if(x>W/2)sat = false;
  }
  if(H%2 == 1 && W%2 == 1){
    if(y!=1)sat = false;
    if(x>W/2 + H/2) sat = false;
  }
  YesNo(sat);
  return 0;
}


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


int main(){
    // あとで消す
    //std::ifstream in("ain3.txt");
    //std::cin.rdbuf(in.rdbuf());

    
    int N;
    cin >> N;

    cout << N/2+N%2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using M = map<string,ll>;





int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1,0);
    for(int i=0;i<N;i++){
        cin>>A[i]
    ;}
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    ll counter1=0; ll counter2=0;
    ll B=0,C=0;
    int i=0;

    while(i<N-1){
        if(counter1==0&&A[i]==A[i+1]){counter1++;C=A[i];i++;}
        else if(counter1==1&&A[i]==A[i+1]){counter2++;B=A[i];break;}
        i++
    ;}
    cout<<B*C<<endl;


return 0;


}  



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REP(i, n) for(ll i = 1; i < (ll)(n); i++)
#define P pair<ll, ll>
typedef long long ll;
const ll mod = 1e9+7;

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

//繰り返し自乗法によるmod累乗計算
//a = 底、　n = 指数
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//nCa 
ll comb(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}

ll a[55], p[55];

ll f(ll n, ll x){
  if(n == 0 && x == 1) return 1;
  else if(x == 1) return 0;
  else if(x <= a[n-1] + 1) return f(n-1, x-1);
  else if(x == a[n-1] + 2) return p[n-1]+1;
  else if(x <= a[n-1]*2+2) return f(n-1, x-2-a[n-1]) + p[n-1] + 1;
  else if(x == a[n-1]*2+3) return p[n-1]*2+1;
}

int main(){
  ll n, x;
  cin >> n >> x;
  a[0] = 1; p[0] = 1;
  for(int i = 0; i <= 50; i++){
    a[i+1] = a[i] * 2 + 3;
    p[i+1] = p[i] * 2 + 1;
  }
  ll ans = f(n, x);
  cout << ans << endl;
}






Measured memory_bytes: 256
#include<queue>
#include<cstdio>

#define	mp	make_pair
#define	EMPTY	-1

using namespace std;

typedef	pair<int,int>	pii;

int Numbers(int groupid){
	return groupid%5==1?5:2;
}

int MealTime(int groupid){
	return 17*(groupid%2)+3*(groupid%3)+19;
}

int main()
{
	int counter[17],elapse[17],mealtime[17];
	queue<pii> qu;	// <numbers in a group, group id>

	for(int i=0;i<17;i++)	counter[i]=EMPTY;

	int waittime[100];
	for(int t=0;t<589;t++){
		// enqueue
		if(t%5==0&&t<500){
			qu.push(mp(Numbers(t/5),t/5));
		}

		// going
		for(int i=0;i<17;i++){
			if(counter[i]!=EMPTY){
				elapse[i]++;
				if(elapse[i]==mealtime[i])	counter[i]=EMPTY;
			}
		}

		// coming
		bool came;
		do{
			came=false;
			if(qu.empty())	break;

			pii next=qu.front();
			for(int i=0,cnt=0;i<17;i++){
				if(counter[i]==EMPTY)	cnt++;
				else					cnt=0;

				if(cnt==next.first){
					int mt=MealTime(next.second);
					for(int j=i;j>i-next.first;j--){
						counter[j]=next.second;
						mealtime[j]=MealTime(next.second);
						elapse[j]=0;
					}
					waittime[next.second]=t-5*next.second;
					came=true;
					qu.pop();
					break;
				}
			}
		}while(came);
	}

	for(int n;~scanf("%d",&n);)	printf("%d\n",waittime[n]);

	return 0;
}

Measured memory_bytes: 0
def main():
    n,k = map(int,input().split())
    h = [int(i) for i in input().split()]
    INF =  float('inf')
    dp = [INF for i in range(n)]
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,n):
        dp[i] = min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,min(i,k)+1))
    print(dp[n-1])

main()


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

using namespace std;

int main()
{
  string s1,s2;

  cin >> s1 >> s2;

  if ( s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0] ) cout << "YES\n";
  else cout << "NO\n";
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int N;
	cin >> N;

	if (N % 2 == 0) {
		cout << N / 2 - 1 << endl;
	}
	else {
		cout << N / 2 << endl;
	}

}


Measured memory_bytes: 3576
from sys import stdin
from collections import defaultdict 
# from bisect import *
# from heapq import *
# import math
# mod = 10**9+7

H, W, M = map(int, input().split())
raw = defaultdict(int)
col = defaultdict(int)
hw = set()
for i in range(M):
    h, w = map(int, stdin.readline().split())
    raw[h] += 1
    col[w] += 1
    hw.add((h, w))
mh = max(raw.values())
mw = max(col.values())
rawkey = [h for h in raw.keys() if raw[h] == mh]
colkey = [w for w in col.keys() if col[w] == mw]
for h in rawkey:
    for w in colkey:
        if (h, w) not in hw:
            print(mh + mw)
            exit()
print(mh + mw -1)

Measured memory_bytes: 182776
N=int(input())
l=[0]*1000
def divisor_enu(N):
   l=[]
   for i in range(2,int(N**0.5)+1):
      cnt=0
      if N%i==0:
         while N%i==0:
            cnt+=1
            N//=i
         l.append((i,cnt))
   if N != 1:
      l.append((N,1))
   return l
for i in range(1,N+1):
   s=divisor_enu(i)
   for j in s:
      l[j[0]]+=j[1]
ans=1
mod=10**9+7
for i in l:
   if 0<i:
      ans=ans*(i+1)%mod
print(ans)

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

int main(){
    ll N, M;
    cin >> N >> M;
    ll head = 2 * (M/2) + 1;
    if(M % 2 == 0){
        rep(i, 1, M/2 + 1){
            cout << i << " " << head << endl;
            head--;
        }
        head = 2 * (M/2) + 1 + 2 * (M)/2;
        rep(i, 1, (M)/2 + 1){
            cout << i + 2 * (M/2) + 1 << " " << head << endl;
            head--;
        }
    }else{
        rep(i, 1, M/2 + 1){
            cout << i << " " << head << endl;
            head--;
        }
        head = 2 * (M/2) + 1 + 2 * (M+1)/2;
        rep(i, 1, (M+1)/2 + 1){
            cout << i + 2 * (M/2) + 1 << " " << head << endl;
            head--;
        }
    }
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long n;
    cin>>n;
    long long x[n+1],y[n+1],t[n+1];
    x[0]=0;
    y[0]=0;
    t[0]=0;
    bool f=true;
    f(i,1,n+1){
        cin>>t[i]>>x[i]>>y[i];
    }
    f(i,1,n+1){
        if(t[i]-t[i-1]<abs(x[i]-x[i-1])+abs(y[i]-y[i-1])){
            f=false;
            break;
        }
        else if((t[i]-t[i-1]-abs(x[i]-x[i-1])-abs(y[i]-y[i-1]))%2!=0){
            f=false;
            break;
        }
    }
    if(f){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    ll h, w;

    cin >> n >> h >> w;

    ll x, y;
    int ans = 0;

    while (n--) {
        cin >> y >> x;

        if (h <= y && w <= x) ans++;
    }

    Out(ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n, m, Q;
  cin >> n >> m >> Q;

  int dp[n + 1][n + 1];
  memset(dp, 0, sizeof(dp));

  rep(i, m) {
    int l, r;
    cin >> l >> r;
    dp[l][r]++;
  }

  FOR(i, 1, n + 1) {
    rep(j, n) {
      dp[i][j + 1] += dp[i][j];
    }
  }
  
  rep(k, Q) {
    int p, q;
    cin >> p >> q;

    int ans = 0;
    FOR(i, p, q + 1) {
      ans += dp[i][q] - dp[i][p - 1];
    }
    cout << ans << endl;
  }

  
  return 0;
}

Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int num = sc.nextInt();

			//500で割れる、5で割れる ex 1050
			//500で割れる、5で割れない ex 1000

			//500で割れない、5で割れる ex 300
			//500で割れない、5で割れない ex 0
			int gohyakuEn = 0;
			int goEn = 0;

			if(num/500 >= 1) {
				gohyakuEn = num/500;

				if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				}
			}else if(num/5 >= 1) {
				goEn = num/5;

			}


				System.out.println( (1000 * gohyakuEn) + (5 * goEn) );


		}
}



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

int main() {
   
    int X;
    cin >> X;

    int a = X / 500;

    X -= a*500;

    int b = X / 5;

    int sum = a * 1000 + b * 5;
  
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
/*                                                                                 
	Author :- Gaurang_Kothiya
	
	Quote :- " Practice makes a man perfect. "		
*/  
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  

#define data_set(type) tree<type,null_type,less<type>,rb_tree_tag,tree_order_statistics_node_update>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define ld long double
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(int i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define ook(num) order_of_key(num)
#define fbo(num) find_by_order(num)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846

const int inf= 1e9;
const int inf64= 1e18;
const int MOD= 1e9 +7;


void Solve()
{
	int n,m,k;
	cin>>n>>m>>k;
	char a[n][m];
	int ans=0;
	
	f(i,0,n-1)
	{
		f(j,0,m-1) cin>>a[i][j];
	}
	f(i,0,pow(2,n)-1)
	{
		f(j,0,pow(2,m)-1)
		{
			char b[n][m];
			f(i,0,n-1)
			{
				f(j,0,m-1) b[i][j]=a[i][j];
			}
			
			f(id,0,n-1)
			{
				if(i&(1<<id))
				{
					f(j1,0,m-1) b[id][j1]='.';
				}
			}
			f(id,0,m-1)
			{
				if(j&(1<<id))
				{
					f(i1,0,n-1) b[i1][id]='.';
				}
			}
			int sum=0;
			f(i1,0,n-1)
			{
				f(j1,0,m-1)
				{
					if(b[i1][j1]=='#') sum++;
				}
			}
			if(sum==k) ans++;
		}
	}
	cout<<ans;
}
 
signed main() 
{
	speed		

	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
		
	return 0;
} 

Measured memory_bytes: 4072
def main():
    N = int(input())

    for h in range(1, 3501):
        for n in range(N-h+1, 3501):
            if (4*h*n - N*h - N*n)>0 and N*h*n % (4*h*n - N*h - N*n)==0:
                w = N*h*n // (4*h*n - N*h - N*n)
                print(h, n, w)
                exit()

if __name__ == "__main__":
    main()

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

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int k;
    cin >> k;

    queue<ll> q;
    REP(i, 9) q.push(i+1);

    ll x;
    REP(i, k) {
        x = q.front(); q.pop();
        if (x%10 != 0) q.push(10 * x + x%10 - 1);
        q.push(10 * x + x%10);
        if (x%10 != 9) q.push(10 * x + x%10 + 1);
    }

    cout << x << endl;
    return 0;
}


Measured memory_bytes: 1792
<?php
$input = STDIN;

list($n, $k) = array_map('intval', explode(" ", trim(fgets($input))));
for ($i = 0; $i < $n; $i++) {
    $w[] = (int)trim(fgets($input));
}

$upper= array_sum($w);
if ($k == 1) {
    print "{$upper}\n";
} else {
    // binary search
    $lower = max($w);
    while ($lower < $upper) {
        $mid = (int)(($lower + $upper) / 2);
        $num = 1;
        $tmp_wt = 0;

        foreach ($w as $w_i) {
            if ($tmp_wt + $w_i <= $mid) {
                $tmp_wt += $w_i;
            } else {
                $num++;
                $tmp_wt = $w_i;
            }

            if ($num > $k) break;
        }

        if ($num > $k) {
            $lower = ++$mid;
        } else {
            $upper = $mid;
        }
    }

    // output
    $P = $mid;
    print "{$P}\n";
}


Measured memory_bytes: 23628
N = int(input())
A = list(map(int, input().split()))

A.append(0)
A.insert(0,0)

D = 0
for i in range(N+1):
  D += abs(A[i+1]-A[i])

for i in range(1, N+1):
  print(D - abs(A[i]-A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1]-A[i-1]) )

Measured memory_bytes: 14048
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<string.h>
#include<limits.h>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
const int maxn = 25;
char str[maxn][maxn];
int vis[maxn][maxn];
struct node {
	int x,y,step;
} dot[maxn];
int dir[][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int n,m;
int ans = 0,res = 0;                                  // 找到结束的条件是关键,如何找到呢？
int main(void) {
	int BFS(int start_x,int start_y);
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= n; i ++) {
		for(int j = 0; j <= m; j ++) {
			scanf("%c",&str[i][j]);
		}
	}
	ans = 0;
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= m; j ++) {
			if(str[i][j] == '#') continue;
			res = BFS(i,j);
			ans = max(ans,res);
		}
	}
	cout << ans << endl;
	return 0;
}

bool Check(int x,int y) {
	if(x < 1 || y < 1 || x > n || y > m) return false;
	if(vis[x][y] || str[x][y] == '#') return false;
	if(str[x][y] == '.') return true;
}

int BFS(int start_x,int start_y) {
	memset(vis,0,sizeof(vis));
	int count = 0;                  // 复原
	queue<node>queues;
	while(!queues.empty()) queues.pop();
	node first,second;
	first.x = start_x,first.y = start_y,first.step = 0;
	queues.push(first);
	vis[start_x][start_y] = 1;
	while(!queues.empty()) {
		first = queues.front();
		queues.pop();
		count = max(count,first.step);
		for(int i = 0; i < 4; i ++) {
			second.x = first.x + dir[i][0];
			second.y = first.y + dir[i][1];
			if(!Check(second.x,second.y)) continue;
			second.step = first.step + 1;
			queues.push(second);
			vis[second.x][second.y] = 1;
		}
	}
	return count;
}

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


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	int xd = tx - sx;
	int yd = ty - sy;

	for (int i = 0; i < yd; i++) {
		cout << "U";
	}

	for (int i = 0; i < xd; i++) {
		cout << "R";
	}

	for (int i = 0; i < yd; i++) {
		cout << "D";
	}

	for (int i = 0; i < xd; i++) {
		cout << "L";
	}

	cout << "L";
	for (int i = 0; i < yd+1; i++) {
		cout << "U";
	}

	for (int i = 0; i < xd+1; i++) {
		cout << "R";
	}
	cout << "DR";

	for (int i = 0; i < yd+1; i++) {
		cout << "D";
	}

	for (int i = 0; i < xd+1; i++) {
		cout << "L";
	}
	cout << "U\n";

	return 0;
}

Measured memory_bytes: 256
import sys
 
sys.setrecursionlimit(int(1e6))
 
 
class B_I_T:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
 
    def get_sum(self, i):
        ret = 0
        while i > 0:
            ret += self.data[i]
            i -= (i & -i)
        return ret
 
    def add(self, i, w):
        if i == 0:
            return
        while i <= self.n:
            self.data[i] += w
            i += (i & -i)
 
 
def dfs(u, cnt):
    cnt += 1
    l[u] = cnt
    for c in tree[u]:
        cnt = dfs(c, cnt)
    cnt += 1
    r[u] = cnt
    return cnt
 
 
n = int(input())
l, r = [0] * n, [0] * n
tree = [set(map(int, input().split()[1:])) for _ in range(n)]
 
bit = B_I_T(dfs(0, 1))
 
q = int(input())
for _ in range(q):
    line = list(map(int, input().split()))
    if line[0]:
        print(bit.get_sum(r[line[1]] - 1))
    else:
        bit.add(l[line[1]], line[2])
        bit.add(r[line[1]], -line[2])


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#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 REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
vector<pLL>v;
LL n;
double s=0;
void f(vector<pLL>vt)
{
    LL x=v[0].ff,y=v[0].ss;
    for(LL i=0;i<v.size();i++)
    {
        s+=sqrtl((v[i].ff-x)*(v[i].ff-x)+(v[i].ss-y)*(v[i].ss-y));
    }
}
int main()
{
   cin>>n;
   for(LL i=0;i<n;i++)
   {
       LL x,y;
       cin>>x>>y;
       v.pb({x,y});
   }
   sort(all(v));
   do{
        f(v);

   } while(next_permutation(all(v)));
   LL x=1;
   for(LL i=1;i<=n;i++)
    x=x*i;
//    cout<<s<<" "<<x<<endl;
   cout<<prec(10)<<s/x;


}


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

#define ll long long
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define endl '\n'
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define INF 1e+18

using namespace std;

int main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;  cout.tie( 0 ) ;
    
    int n ;
    cin >> n ;
    int a[n] , dp[n] ;
    for(int i = 0 ; i < n ; i++)
        cin >> a[i] ; 

    dp[0] = 0 ; 

    dp[1] = abs(a[1] - a[0]) ; 

    for(int i = 2 ; i < n ; i++){
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]) , dp[i - 2] + abs(a[i] - a[i - 2])) ; 
    }

    cout << dp[n - 1] << endl ;

    return 0 ; 
}



Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int a[3];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]==a[1]&&a[0]!=a[2])cout<<"Yes";
	else if(a[1]==a[2]&&a[0]!=a[1])cout<<"Yes";
	else cout<<"No";
	return 0;
}


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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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

vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,H)  cin >> S.at(i);

  vector<vector<int>> dist(H,vector<int>(W,1e9));
  priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> pq;
  rep(i,H){
    rep(j,W){
      if(S.at(i).at(j)=='#'){
        dist.at(i).at(j)=0;
        pq.push(m_p(0,m_p(i,j)));
      }
    }
  }
  while(!pq.empty()){
    int c=pq.top().fi;
    int y=pq.top().se.fi;
    int x=pq.top().se.se;
    pq.pop();
    rep(i,4){
      int ny=y+dy.at(i);
      int nx=x+dx.at(i);
      if(ny<0 || ny>=H || nx<0 || nx>=W)  continue;
      int nc=c+1;
      if(dist.at(ny).at(nx)<=nc)  continue;
      dist.at(ny).at(nx)=nc;
      pq.push(m_p(nc,m_p(ny,nx)));
    }
  }
  int ans=0;
  rep(i,H){
    rep(j,W){
      chmax(ans,dist.at(i).at(j));
    }
  }
  cout << ans << endl;

  return 0;
}

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


int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long test;
    test=1;
    // cin>>test;
    while(test--)
    {
        long a,b;
    cin>>a>>b;
    if(a==b)cout<<"Draw";
    else if(a==1 || b==1)
    {
        if(a==1)cout<<"Alice";
        else cout<<"Bob";
    }
    else
    {
        if(a>b)cout<<"Alice";
        else cout<<"Bob";
    }
    
    
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
int n,m,k;
bool solve(){
  REP(y,n+1)REP(x,m+1){
    if(x*(n-y)+y*(m-x)==k)
      return true;
  }
  return false;
}
int main(){ _;
  cin>>n>>m>>k;
  cout<<(solve()?"Yes":"No")<<endl;
}


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

 
 public class Main	{
   static class Pair implements Comparable<Pair>{
   int a;
   int b;
   public Pair(int x,int y){a=x;b=y;}
   public Pair(){}
   public int compareTo(Pair p){
      return Integer.compare(a, p.a);
   }
 }
static class TrieNode{
  TrieNode[]child;
  int w;
  boolean term;
  TrieNode(){
    child = new TrieNode[26];  
  }
}
  public static int gcd(int a,int b)
  {
    if(a<b)

      return gcd(b,a);
    if(b==0)
      return a;
    return gcd(b,a%b);
    
  }
  //static long ans = 0;
  static long mod =(long)(1e9+7); //998244353;//
   
    public static void main(String[] args) throws Exception {
       new Thread(null, null, "Anshum Gupta", 99999999) {
            public void run() {
                try {
                    solve();
                } catch(Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }

static long pow(long x,long y){
    if(y == 0)return 1;
    if(y==1)return x;
    long a = pow(x,y/2);
    a = (a*a)%mod;
    if(y%2==0){
        return a;
    }
    return (a*x)%mod;
}

static long mxx;
static int mxN = (int)(1e5+5);
static long[]fact,inv_fact;
static long my_inv(long a) {
	return pow(a,mod-2);
}
static long bin(int a,int b) {
    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
}

static ArrayList<ArrayList<Integer>>adj ;

 public static void solve() throws Exception {
   // solve the problem here
   MyScanner s = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int t = 1;//s.nextInt();
        mxx = (long)(1e18+5);
 
        while(t-->0){
        	int n = s.nextInt();
        	int d = s.nextInt();
        	int range = 2*d+1;
        	out.println((int)Math.ceil(n*1.0/range));
        }
           
        out.flush();
}
 
     
 
 
 
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
 
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
 
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }
         
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}


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

int Max(int i[3]){
	int max=0,pos;
	for(int n=0;n<3;n++){
		if(max<i[n]){
			max=i[n];
			pos=n;
		}
	}
	return pos;

}

int main(){
	int N;
	cin >> N;
	while(N--){
		int i[3],c;
		int max;
		cin >> i[0] >> i[1] >> i[2];
		max = Max(i);
		c = i[max];
		i[max]=0;
		if(i[0]*i[0]+i[1]*i[1]+i[2]*i[2] == c*c)
			cout<<"YES\n";
		else
			cout<<"NO\n";
	}
}

Measured memory_bytes: 1120
n, m = list(map(int, input().split()))
al = [input() for i in range(n)]
bl = [input() for i in range(m)]

for i in range(n-m+1):
	for j in range(n-m+1):
		for k in range(m):
			if al[i+k][j:j+m] != bl[k]:
				break
		else:
			print("Yes")
			exit()
		#print("Yes")
		#exit()
print("No")


Measured memory_bytes: 3060
import math

A,B,H,M = map(int,input().split())

sita1=M*360/60
sita2=H*360/12+0.5*M

a=abs(sita1-sita2)
if a > 180:
    a = 360 - a
d = math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(a)))

print('{:.20f}'.format(d))


Measured memory_bytes: 9508
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int a,b,s=0;
	cin>>a>>b;
	if(b==100)
	{
		if(a==0)
			s=1;
		if(a==1)
			s=100;
		if(a==2)
			s=10000;
	}
	if(a==0)
		s+=b;
	if(a==1)
		s+=100*b;
	if(a==2)
		s+=10000*b;
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <set>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
using namespace std;
int main() {
	ll n, a, num = 0, b[110], cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		num += a;
		if (a % 10)b[cnt] = a, cnt++;
	}
	sort(b, b + cnt);
	if (num % 10)cout << num << endl;
	else if (cnt)cout << num - b[0] << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256