akhauriyash/Code-Regression huggingface dataset:
s = raw_input()
word_list = {}
for i in s:
    if not word_list.has_key(i):
        word_list[i] = 1
    else:
        word_list[i] += 1

flag = 0
for i in word_list.values():
    if i % 2 == 1:
        flag = 1

if flag == 1:
    print 'No'
else:
    print 'Yes'


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=1;i<=(n);++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define read(x) scanf("%d",&x)
int A,B,n;
int a[100005],b[100005];
int main(){
	ios::sync_with_stdio(false);
	cin>>A>>B>>n;
	REP(i,A) cin>>a[i];
	REP(i,B) cin>>b[i];
	int ans=*min_element(a+1,a+A+1)+*min_element(b+1,b+B+1);
	REP(i,n){
		int x,y,c;
		cin>>x>>y>>c;
		ans=min(ans,a[x]+b[y]-c);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import Counter

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

C=Counter(A)

C_={}
sum_ = 0
for k in C.keys():
    c=C[k]
    if c == 1:
        C_[k]=0
    else:
        C_[k]=(c*(c-1))//2
        
    sum_ += C_[k]

for a in A:
    ans = sum_-(C[a]-1)
    print(ans)

Measured memory_bytes: 128636
#!/usr/bin/env python3
n, *w = open(0).read().split()
s = set(w)
if len(s) != len(w):
    print("No")
    exit()
for i in range(1, int(n)):
    if w[i][0] != w[i - 1][-1]:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 9076
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	string s;
	cin>>s;
	stack<char>st;
	rep(i,s.size()){
		if(s[i]=='T'&&st.size()&&st.top()=='S')st.pop();
		else st.push(s[i]);
	}
	cout<<st.size()<<endl;
}









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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> graph(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }
  
  int ans = 0;
  vector<int> v(N - 1);
  for (int i = 0; i < N - 1; ++i) v[i] = i + 1;
  do {
    bool judge = true;
    
    int memo = false;
    for (int x : graph[0]) {
      if (x == v[0]) memo = true;
    }
    if (!memo) judge = false;
    
    for (int j = 0; j < N - 2; ++j) {
      int meme = false;
      for (int x : graph[v[j]]) {
        if (x == v[j + 1]) meme = true;
      }
      if (!meme) judge = false;
    }
    
    if (judge) ++ans;
  } while (next_permutation(v.begin(), v.end()));
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{

	int a,b,c;
	int temp;
	scanf( "%d %d %d", &a, &b, &c);
	
	if( a > b ){
		temp = a; a = b; b = temp;
	}
	
	if( b > c ) {
		temp = b; b = c; c = temp;
	}
	if( a > b ){
		temp = a; a = b; b = temp;
	}
	printf( "%d %d %d\n", a, b, c );
	
	return 0;
}


Measured memory_bytes: 2036
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<int> d(N);
  for(int i=0;i<N;++i) cin>>d[i];
  sort(d.begin(), d.end());
  int ans = 0;
  int index;
  for(int k=0;k<=100005;++k) {
    index = lower_bound(d.begin(), d.end(), k) - d.begin();
    if(index==N/2) ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3768
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
	int x,y;cin>>y>>x;
	if((x-2*y)%2!=0){
		cout<<"No"<<endl;
	}
	else if((x-2*y)/2<0){
		cout<<"No"<<endl;
	}else if((x-2*y)/2>y){
		cout<<"No"<<endl;
	}else cout<<"Yes"<<endl;
	
  	return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(15);
  solve();
}


Measured memory_bytes: 3648
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


const char YES = 'Y';
const char NO = 'N';
int N;
int C;
VS M;

VS toVS( string s ) {
    VS res(2,string(C,' '));
    for ( int i = 0; i < 2; ++ i ) {
        for ( int j = 0; j < C; ++ j ) {
            int id = C*i + j;
            res[i][j] = s[id];
        }
    }
    return res;
}

void input() {
    cin >> N;
    C = 2 * N;
    string s;
    cin >> s;
    M = toVS(s);
}

bool checkA() { 
    for ( int i = 0; i < 2; ++ i ) {
        for ( int j = 0; j < C; ++ j ) {
            if ( M[i][j] == YES ) return false;
        }
    }
    return true;
}

bool checkB() { 
    if ( checkA() ) return false;
    for ( int i = 0; i < C; ++ i ) {
        if ( M[1][i] == YES ) return false;
    }
    return true;
}
 
bool checkC() { 
    if ( checkA() ) return false;
    for ( int i = 0; i < C; ++ i ) {
        if ( M[0][i] == YES ) return false;
    }
    return true;
}

int getFirstAppearColumn() {
    for ( int i = 0; i < C; ++ i ) {
        if ( M[0][i] == YES || M[1][i] == YES ) return i;
    }
    return 0;
}

int getLastAppearColumn() {
    for ( int i = C-1; i >= 0; -- i ) {
        if ( M[0][i] == YES || M[1][i] == YES ) return i;
    }
    return 0;
}

int count( int r ) {
    int res = 0;
    for ( int i = 0; i <= N; ++ i ) {
        if ( i == 0 ) {
            if ( M[r][0] == YES ) res ++;
        } else if ( i == N ) {
            if ( M[r][i*2-1] == YES ) res ++;
        } else {
            int left = i * 2 - 1, right = i * 2;
            if ( M[r][left] == YES || M[r][right] == YES ) res ++;
        }
    }
    return res;
}

int solve() {
    if ( checkA() ) {
        return N;
    } else if ( checkB() ) {
        return N + count(0);
    } else if ( checkC() ) {
        return N + 1 + count(1);
    } else {
        int cnt = count(0) + count(1);
        int ret1 = getFirstAppearColumn();
        int ret2 = getLastAppearColumn();
        int cost = 2;
        if ( M[0][ret1] == YES ) cost --;
        if ( M[0][ret2] == YES ) cost --;
        return N + cnt + cost;
    }
    return 0;
}

int main() {
    int tests;
    cin >> tests;
    for ( int i = 0; i < tests; ++ i ) {
        input();
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int Y[]={1,1,0,0,-1,-1};
int X[]={0,1,-1,1,-1,0};
int main(){
  int n,m,ny,nx,i,j,t,r,y[10000],x[10000],a,b;
  while(scanf("%d %d",&n,&m),n){
    int d[200][200]={};
    for(i=0;i<m;i++){
      scanf("%d %d",&a,&b);
      d[b+100][a+100]=1;
    }
    scanf("%d %d",&a,&b);
    d[y[0]=b+100][x[t=0]=a+100]=n+1;
    for(r=1;r-t;t++){
      if(d[y[t]][x[t]]==1)continue;
      for(i=0;i<6;i++){
	ny=y[t]+Y[i];
	nx=x[t]+X[i];
	if(d[ny][nx])continue;
	d[y[r]=ny][x[r]=nx]=d[y[t]][x[t]]-1;
	r++;
      }
    }
    printf("%d\n",r);
  }
  return 0;
}
	

Measured memory_bytes: 796
#include <algorithm>
#include <cmath>
#include<stdio.h>
#include <functional>
#include <fstream>
#include <limits>
#include <sstream>
#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include<map>
using namespace std;
using ll = long long;
const int N = 100005;
int a[N],b[N],dp[N],n;
long long solve(int i){
     if(dp[i]!=-1)return dp[i];
     if(i==n-1)return 0;
     if(i+2<n)
     return dp[i]=min(solve(i+1)+abs(a[i]-a[i+1]),solve(i+2)+abs(a[i]-a[i+2]));
else 
      return dp[i]=solve(i+1)+abs(a[i]-a[i+1]);
       
}
int main(){
        #ifdef MANSOUR
        freopen("input.txt", "r", stdin);
        #endif
       cin>>n;
        for(int i=0;i<N;i++)dp[i]=-1;
       for(int i=0;i<n;i++)cin>>a[i];
        cout<<solve(0);




}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
/*int n,m=INT_MAX,x=INT_MIN;
int A[100];
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
        m = min(m, A[i]);
        x = max(x, A[i]);
    }
    long long ans = INT_MAX;
    for (int i = m; i < x+1; i++)
    {
        long long k = 0;
        for (int j = 0; j < n; j++)
        {
            k += (A[j] - i) * (A[j] - i);
        }
        ans = min(ans, k);
        //cout << ans << " ";
    }
    cout << ans;
}*/ 
#define ll long long
/*long long a, b, c;
//int fac[200001];

long long power(long long x, long long y, long long p)
{
    if (x == 1 and y != 0) return 1;
    long long res = 1;      // Initialize result 

    long long k = x % p;  // Update x if it is more than or 
                // equal to p 
    //cout << "(" << k << "," << y << "," << p << ")=";
    while (y > 0)
    {
        // If y is odd, multiply x with result 
        if (y & 1)
            res = (res * k) % p;
        //cout << y << ":" << res<<","<<k << " ";
        // y must be even now 
        y = y >> 1; // y = y/2  
        k = (k * k) % p;
    }
    //cout << res<<" ";
    return res;
}

long long modInverse(long long n, long long p)
{
    return power(n, p - 2, p);
}

long long nCrModP(long long n, long long r, long long p)
{
    // Base case 
    if (r == 0)
        return 1;
    long long z=1,y=1;
    for (long long i = n; i > n - r; i--)
        z = (z * i) % p;
    for (int i = 2; i <= r; i++)
        y = (y * i) % p;
    long long k= (z * modInverse(y, p))%p;
    //cout << "(" << n << "," << r << ")=" << k;
    return k;
}
int main()
{
    //fac[0] = 1;
    cin >> c >> a >> b;
    int ans = power(2, c, 1000000007)-1;
    //cout << ans << " ";
    ans -= (nCrModP(c, a, 1000000007) + nCrModP(c, b, 1000000007)) % 1000000007;
    //cout << nCrModP(c, a, 1000000007)<<"->";
    //cout << nCrModP(c, b, 1000000007);
    if (ans >= 0)
        cout << ans;
    else cout << ans + 1000000007;
}*/
const int M = 1000000007,N=400000+1;
ll fac[N];

long long power(long long j, int k)
{
    //cout << "power of" << j << ":\n";
    if (j == 1 and k != 0) return 1;
    long long res = 1;
    while (k)
    {
        //cout << k << "->";
        if (k & 1)
            res = (res * j) % M;
        k = k >> 1;
        j = j * j%M;
       // cout << res << "," << j << " ";
    }
   // cout << "\n";
    return res;
}
long long nCr(int a, int b)
{
    if (b == 0)
        return 1;
    //cout << fac[a] << " " << power(fac[b], M - 2) << " " << power(fac[a - b], M - 2) << ":\n";
    return fac[a] * (power(fac[b], M - 2) * power(fac[a - b], M - 2) % M) % M;
}
int main()
{
    fac[0] = 1;
    int n, k;
    cin >> n >> k;
    for (int i = 1; i < N; i++)
    {
        fac[i] = fac[i - 1] * i % M;
    }
    ll ans = nCr(2*n-1,n-1);
    for (++k; k < n; k++)
    {
        ans = (ans + M - nCr(n, k) * nCr(n - 1, n - k - 1)%M)%M;
    }
    cout << ans;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}

using namespace std;

struct UnionFind {
    vector<int> par; 
    vector<int> sizes;
    UnionFind(int N) : par(N),sizes(N,1) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return; 
        if (sizes[rx]<sizes[ry])swap(rx,ry);
        par[ry] = rx; 
        sizes[rx]+=sizes[ry];
    }

    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int size(int x){
        return sizes[root(x)];
    }

};

//最大公約数
int gcd(int a,int b){
    
    if(a==0 || b==0)return 0;
    if(a<b){
        int sw;
        sw=a;
        a=b;
        b=sw;
    }
    
    int r;
    while((r=a%b)!=0){
        a=b;
        b=r;
    }
    return b;
}
//最小公倍数
int lcm(int a,int b){


    if(a==0 || b==0)return 0;

    return a/gcd(a,b)*b;

}

int n,k,ans,sum;

int a[1111111],flag[1111111];

signed main(){
	int maxnum=0;
	cin>>n;
	rep(i,n){
		cin>>a[i];
		maxnum=max(a[i],maxnum);
		flag[a[i]]++;
	}
	int pc=1;
	for(int i=2;i<=maxnum;i++){
		int cnt=0;
		for(int j=0;j<=maxnum;j+=i){
			if(flag[j]){
				cnt+=flag[j];
				//cout<<j<<endl;
			}
		}
		if(cnt>=2){
			pc=0;
			break;
		}
	}
	int sc=1;
	int GCD=a[0];
	rep(i,n){
		GCD=gcd(GCD,a[i]);
	}
	if(GCD!=1)sc=0;
	if(pc==1)cout<<"pairwise coprime"<<endl;
	else if(pc==0 && sc==1)cout<<"setwise coprime"<<endl;
	else cout<<"not coprime"<<endl;
}


Measured memory_bytes: 18984
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  if (n < 1000) dump("ABC");
  else dump("ABD");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
map<ll,int> primeFactor(ll n){
    map<ll,int> res;
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            res[i]++;
            n/=i;
        }
    }
    if(n!=1){
        res[n]=1;
    }
    return res;
}
int main(){
    int n;
    cin>>n;
    map<ll,int> dat;
    FOR(i,1,n+1){
        auto t=primeFactor(i);
        for(auto itr:t){
            dat[itr.fi]+=itr.se;
        }
    }
    vi vec;
    for(auto itr:dat){
        vec.push_back(itr.se);
    }
    map<int,ll> ans;
    ans[1]=1;
    REP(i,vec.size()){
        map<int,ll> next;
        for(auto itr:ans){
            REP(j,vec[i]+1){
                if(itr.fi*(j+1)<=75){
                    next[itr.fi*(j+1)]+=itr.se;
                }
            }
        }
        ans=next;
    }
    cout<<ans[75]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define ss second
#define ff first 
#define ub upper_bound
#define lb lower_bound
// #define mp make_pair
const ll M=1000000007;
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0)return (power((x*x)%M,n/2))%M;else return ((x%M)*power(x,n-1)%M);}
ll ncr(int n,int r){if(r>n)return 0;if(r > n - r) r = n - r;ll ans = 1;
int i;for(i = 1; i <= r; i++){ans *= n - r + i;ans /= i;}return ans;}
ll nCrModpDP(ll n, ll r, ll p){ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1;
    for (ll i = 1; i <= n; i++){ 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll ncrmod(ll n, ll r, ll p){ 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
   return (ncrmod(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p;  
} 
ll modInverse(ll a,ll m) 
{ 
   ll m0 = m; 
   ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
       ll q = a / m; 
       ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
ll fun(ll num[],ll sum,ll n){
map<ll,ll>mp;
for(int i=0; i<n; i++){
mp[num[i]]++;
}
ll ans=0;
for(int i=0; i<n; i++){
if(mp[sum-num[i]]>0&&(sum-num[i]!=num[i])&&(mp[num[i]]>0)){
ans+=1,mp[sum-num[i]]--,mp[num[i]]--;
}
else if(mp[sum-num[i]]>=2&&(sum-num[i]==num[i])){
ans+=1,mp[sum-num[i]]-=2;
}
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
ll num[n],a1=0;
for(int i=0; i<n; i++){
cin>>num[i];
ll a=num[i];
ll ans=0;
while(a%2==0){
ans+=1;
a/=2;
}
a1+=ans;
}
cout<<a1;
return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

const int MOD = 1e9+7;

int main(){
  ll N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  ll ans = 0;
  rep(i, N) {
    int cnt1 = 0, cnt2 = 0;
    for(int j=i+1; j<N; j++) {
      if(A[j] < A[i])
        cnt1++;
    }
    rep(j, N) {
      if(A[j] < A[i])
        cnt2++;
    }
    ans = (ans+cnt1*K+(K*(K-1)/2)%MOD*cnt2)%MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans,rev,sm=0,0,0
for i in range(1,n):
    for j in range(i):
        if a[i]<a[j]: rev+=1
        elif a[i]==a[j]: sm+=1
ans+=rev*k
ans+=(n*(n-1)//2-sm)*(k*(k-1)//2)
print(ans%(10**9+7))

Measured memory_bytes: 3188
N, K = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
mod = 10 ** 9 + 7
for i in range(N):
    #print(cnt)
    for j in range(N):
        if a[i] > a[j]:
            cnt += 1
ans = cnt * ((K - 1) * K) * 500000004 % mod
for i in range(N - 1):
    for j in range(i + 1, N):
        if a[i] > a[j]:
            ans += K % mod
print(ans % mod)

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

using namespace std;

const int mod = 1e9 + 7, mxs = 2e5 + 5;
using ll = long long;

int h, w, n;
vector<int> fac, invf;
vector<pair<int, int>> obs;

int mul(int x, int y){
    return (ll) x * y % mod;
}

int add(int x, int y){
    return ((ll) x + y) % mod;
}
int sub(int x, int y){
    return (add(x, -y) + mod) % mod;
}

int power(int x, int p){
    int res = 1;
    while(p){
        if(p & 1) res = mul(res, x);
        x = mul(x, x);
        p /= 2;
    }
    return res;
}

int inv_fun(int x){
    return power(x, mod - 2);
}

int numofpaths(pair<int, int> x, pair<int, int> y){
    int a = (y.first - x.first);
    int b = (y.second - x.second);
    return mul(fac[a+b], mul(invf[a], invf[b]));
}

int main(){
    cin>>h>>w>>n;
    obs.resize(n), fac.resize(mxs), invf.resize(mxs);
    fac[0] = 1, invf[0] = 1;
    for(int i = 1; i < mxs; i++){
        fac[i] = mul(fac[i-1], i);
        invf[i] = inv_fun(fac[i]);
    }
    for(int i = 0; i < n; i++) cin>>obs[i].first>>obs[i].second;
    sort(obs.begin(), obs.end(), [&](pair<int, int> p1, pair<int, int> p2){
        return p1.first + p1.second < p2.first + p2.second;
    });
    obs.push_back({h, w});
    vector<int> dp(n+1);
    for(int i = 0; i <= n; i++){
        dp[i] = numofpaths({1, 1}, obs[i]);
        for(int j = 0; j < i; j++){
            if(obs[j].first <= obs[i].first && obs[j].second <= obs[i].second)
                dp[i] = sub(dp[i], mul(dp[j], numofpaths(obs[j], obs[i])));
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, K; 
    cin >> N;
    cin >> K;

    ll ans = 1;

    REP(i, N){
        if(ans + K < ans * 2){
            ans += K;
        }
        else{
            ans *= 2;
        }
    }

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

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005];
ll Pow(ll a, int b){
    ll ans = 1;
    while(b){
        if(b&1) ans = ans*a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}
ll cal(ll x){
    ll ans = 0;
    while(x){
        ans += (x % 10); x /= 10;
    }
    return ans;
}
int main(){
    /*
    a[1] = 1;
    for(int i = 2; i <= 100000; ++i){
        a[i] = a[i-1] + Pow(10, floor(i-1)/9);
    }
    */
    int k;
    scanf("%d", &k);
    /*
    a[0] = 0;
    a[1] = 1;
    for(int i = 2; i <= k; ++i){
        a[i] = 1ll * (i % 9 + 1) * Pow(10, (int)floor(1.0*i/9)) - 1;
    }
    for(int i = 1; i <= k; ++i){
        printf("%lld\n", a[i]);
    }
    */
    ll x = 0, x1, x2, m = 1;
    for(int i = 1; i <= k; ++i){
        x1 = x + m, x2 = x + m * 10;
        if(x1*cal(x2) <= x2*cal(x1)) x = x1;
        else{
            x = x2;
            m *= 10;
        }
        printf("%lld\n", x);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(void){
    int N, K;
    cin >> N >> K;
    
    int ans = 0;
    int h;
    for(int i=0; i<N; i++) {
        cin >> h;
        if (h >= K) {
            ans++;
        }
    }
    
    cout << ans;  
    
    
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e9
#define MOD 1000000007

int main()
{

    ll n;
    cin >> n;
    vector< pair< ll, pll > > cr;
    for(ll i = 0; i < n; i++)
    {

        ll x, y, h;
        cin >> x >> y >> h;
        cr.pb(mp(h, mp(x,y)));
    }
    for(ll cx = 0; cx<=100; cx++)
    {

        for(ll cy = 0; cy <= 100; cy++)
        {
            ll hg1=-1;
            vector<ll> ht, zr;
            bool tf = 1;
            for(ll i = 0; i < cr.size(); i++)
            {

                if(cr[i].ff == 0)
                {

                    zr.pb(i);
                    continue;
                }
                ll hg2 = cr[i].ff+abs(cx-cr[i].ss.ff)+abs(cy-cr[i].ss.ss);
                if(hg1==-1)
                {

                    hg1=hg2;
                }
                else
                {

                    if(hg2!= hg1)
                    {

                        tf=0;
                        break;
                    }
                }
            }
            if(tf==0) continue;
            for(ll i = 0; i < zr.size(); i++)
            {

                ll idx = zr[i];
                ll hg = hg1;
                if((hg-abs(cx-cr[idx].ss.ff)-abs(cy-cr[idx].ss.ss)) > 0)
                {

                    tf = 0;
                    break;
                }
            }
            if(tf)
            {

                cout << cx << " " << cy << " " << hg1 << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int k, n,m=0;
	cin >> k >> n;
	vector<int>vec(n);
	vecin(vec);
	rep(i, n - 1) {
		m = max(m, vec[i + 1] - vec[i]);
	}
	m = max(m, vec[0] + (k - vec[n - 1]));
	cout << k - m << endl;
}


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

class Main {




  public static void main(String[] args) {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int N = in.nextInt();
    int[] hs = new int[N];
    for (int i = 0; i < N; i++) {
      hs[i] = in.nextInt();
    }

    int[] dp = new int[N];
    dp[0] = 0;
    dp[1] = Math.abs(hs[1] - hs[0]);


    for (int i = 2; i < N; i++) {
      dp[i] = Math.min(dp[i - 1] + Math.abs(hs[i] - hs[i - 1]), 
                       dp[i - 2] + Math.abs(hs[i] - hs[i - 2]));
    }

    System.out.println(dp[N - 1]);
  }

  

  
}

Measured memory_bytes: 50336
#include <stdio.h>

int main() {

    int x,y,z;
    scanf("%d %d", &x, &y);

    if(y % x == 0) {
        z = x + y;
        printf("%d", z);
    } else {
        z = y - x;
        printf("%d", z);
    }

    return 0;
}

Measured memory_bytes: 1680
import java.util.Scanner;

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

		int n = scan.nextInt();
		String s = scan.next();
		char[] c = s.toCharArray();

		int max = 0;
		int x = 0;
		for(int i = 0; i < n; i++){
			if(c[i] == 'I'){
				x ++;
			}
			else {
				x --;
			}
			if(x > max){
				max = x;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 21332
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    vector<int> an(5);
    int k;
    string ans = "Yay!";
    for (int i = 0; i < 5; i++) {
        cin >> an.at(i);
    }
    cin >> k;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            if ((an.at(j) - an.at(i)) > k) ans = ":(";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))

past = [0 for _ in range(n)]

cnt = 0
now = 1

while(True):
	if past[now-1] == 1:
		print(-1)
		exit(0)
	if now == 2:
		print(cnt)
		exit(0)
	past[now-1] = 1
	cnt += 1
	now = a[now-1]

Measured memory_bytes: 7852
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n;cin >> n;
	set<ll> ans;
	ans.insert(n);
	if(n > 2)ans.insert(n-1);
	ans.insert(2);
	for(ll i = 2;i * i <= n;i++){
		if(n % i)continue;
		ll a = i;
		ll b = n / i;
		while(b % a == 0)b /= a;
		if(b % a == 1)ans.insert(a);
	}
	for(ll i = 2;i * i <= n-1;i++){
		if((n-1) % i)continue;
		ans.insert(i);
		ans.insert((n-1)/i);
	}
	n--;
	for(ll i = 2;i * i <= n;i++){
		while(n % i == 0)n /= i;
	}
	if(n > 1)ans.insert(n);


	cout << ans.size() << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace   std;
#define ff        first
#define ss        second
#define ll        long long
#define double    long double
#define ull       unsigned long long
#define mod       1000000007
#define vi        vector<ll>
#define ppi       pair<ll,pair<ll,ll>>
#define pb        push_back
#define mp        make_pair
#define str       string
#define pi        2*acos(0.0)
#define pr(a,x,n) for(int i=x;i<n;i++){cout<<a[i]<<" ";}
#define p(a)      cout<<a;
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define endl      '\n'
#define all(v)    v.begin(), v.end()
#define test      cout<<"BECOME_EXPERT_FAST_LOL"<<endl;
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
int32_t main(){
	kehsihba();
	ll a;double b;cin>>a>>b;cout<<(ll)(a*b);
}























Measured memory_bytes: 3740
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int main(){
  const int mod = 2019;
  int l, r;
  cin >> l >> r;

  int ans = 2018;
  REP(i,l,r+1)REP(j,i+1,r+1){
    if (ans == 0){
      cout << ans << endl;
      return 0;
    }
    int x = (ll)i * j % mod;
    ans = min(ans, x);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int main(){
	int N;
	scanf("%d",&N);
	if(N&1){
		for(int i=1;i<=N;i++){
			scanf("%d",a+i);
		}
		for(int i=N&1?N:N-1;i>=1;i-=2){
			printf("%d ",a[i]);
		}
		for(int i=2;i<=N;i+=2){
			printf("%d ",a[i]);
		}
		puts("");
	}else{
		for(int i=1;i<=N;i++){
			scanf("%d",a+i);
		}
		for(int i=N&1?N-1:N;i>=2;i-=2){
			printf("%d ",a[i]);
		}
		for(int i=1;i<=N;i+=2){
			printf("%d ",a[i]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2944
//Created Time:2019年12月22日 星期日 21时17分49秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 100005

using namespace std;

int n, l, t;
int res[N], b[N], a[N];

int main(){
	scanf("%d%d%d", &n, &l, &t);
	int cnt = 0; int r = t % l;
	for(int i = 1; i <= n; ++i)
		scanf("%d%d", &a[i], &b[i]), b[i] = b[i] == 1 ? 1 : -1;
	int p = a[1];
	for(int i = 1; i <= n; ++i){
		int x = a[i];
		a[i] = (a[i] + r * b[i] + l) % l;
		if(b[i] == b[1]) continue;
		(cnt += 2 * (t / l) % n) %= n;
		int dis;
		if(b[1] < 0) dis = l - x + p;
		else dis = x - p;
		if(dis <= r * 2){
			(++cnt) %= n; dis += l;
			if(dis <= r * 2) (++cnt) %= n;
		}
	}
	int pos = a[1]; if(!cnt) cnt = n;
	sort(a + 1, a + 1 + n);
//	for(int i = 1; i <= n; ++i) cout << a[i] << endl;
//	return 0;
	for(int i = b[1] < 0 ? 1 : n; b[1] < 0 ? i <= n : i; b[1] < 0 ? ++i : --i)
		if(a[i] == pos){
			pos = i; break;
		}

//	cout << pos << endl;
	int j = (1 + b[1] * cnt + n) % n;
	if(!j) j = n;
	res[j] = a[pos]; j = j % n + 1;
	for(int i = pos % n + 1; i != pos; i = i % n + 1, j = j % n + 1)
		res[j] = a[i];
	for(int i = 1; i <= n; ++i)
		printf("%d\n", res[i]);
	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
using namespace std;
bool b[100001];
int main()
{
	int n,i,j,x,y,ans=0;
	cin>>n;
	for(i=1;i<=100000;i++)
	b[i]=false;
	for(i=1;i<=n;i++)
	{
	cin>>x>>y;
		for(j=x;j<=y;j++)
		{
		if(!b[j]){b[j]=true;ans++;}
		}
	}
	cout<<ans;
	return 0;
}

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

int n, s;

int dfs(int i, int sum, int n) {
    if (i == 10) {
        if (n == 0 && sum == s)
            return 1;
        return 0;
    }
    return dfs(i + 1, sum + i, n - 1) + dfs(i + 1, sum, n);
}

int main(void) {
    while (cin >> n >> s) {
        if (n == 0 && s == 0)
            break;
        cout << dfs(0, 0, n) << endl;
    }
    return 0;
}


Measured memory_bytes: 2992
a,b,c,x,y=map(int,input().split())
ans=2*(max(x,y))*c
temp=0
for i in range(0,2*(max(x,y))+1):#iはABピザの個数。
    if i>=2*x:#いまaピザの個数条件しかかしてないのでこのときbピザが十分存在している時を考慮しないとおかしくなる。
        temp=max(0,(y-(i//2))*b)+i*c
        if temp<=ans:
            ans=temp
    elif i>=2*y:
        temp=max(0,(x-(i//2)))*a+i*c
        if temp<=ans:
            ans=temp
    else:#いまa,bどちらとも不十分の時はまだ場合分けされていない点に留意。
        temp=(x-i//2)*a+(y-i//2)*b+i*c
        if temp<=ans:
            ans=temp
print(ans)

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

int n;
deque<int> que;

int main(void){
	scanf("%d",&n);
	bool flag=true;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		if(flag){
			que.push_back(a);
		}else{
			que.push_front(a);
		}
		flag=!flag;
	}
	if(flag){
		for(int i=0;i<n;i++){
			printf("%d%c",que[i],i==n-1?'\n':' ');
		}
	}
	if(!flag){
		for(int i=n-1;i>=0;i--){
			printf("%d%c",que[i],i==0?'\n':' ');
		}
	}
	return 0;
}


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

using namespace std;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
#define s second
#define f first


struct BIT {
    vector<long long> v;

    BIT(int s) {
        resize(s);
    }

    void clear() {
        v.clear();
    }

    BIT() {
    }

    void resize(int s) {
        s = 1 << (int) ceil(log(1.0 * s) / log(2.) + 1e-9);
        v.resize(s);
    }

    long long get(int i) {
        i++;
        long long r = 0;
        while (i) {
            r += v[i - 1];
            i -= i & -i;
        }
        return r;
    }

    void add(int i, long long val) {
        i++;
        while (i <= (int) v.size()) {
            v[i - 1] += val;
            i += i & -i;
        }
    }

    int find(long long val) {
        int s = 0;
        int m = v.size() >> 1;
        while (m) {
            if (v[s + m - 1] < val)
                val -= v[(s += m) - 1];
            m >>= 1;
        }
        return s;
    }
};


int main() {

    int n, m;
    scanf("%d %d", &n, &m);
    vector<piii> vp(n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &vp[i].second.f, &vp[i].s.s);
        vp[i].first = vp[i].second.s - vp[i].second.f + 1;
    }
    sort(vp.begin(), vp.end());

    BIT bit(400005);
    int ind = 0;
    for (int i = 1; i <= m; i++) {
        while(ind < vp.size() && i > vp[ind].f){
            bit.add(vp[ind].s.f, 1);
            bit.add(vp[ind].s.s+1, -1);
            ind++;
        }
        int res = 0;
        for(int j=i; j<=m; j+=i){
            res += bit.get(j);
        }
        res += (int)vp.size() - ind;
        printf("%d\n", res);
    }
}


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

int main(void) {
    int N, dp[100020], h[100020];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }

    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: 1024
#include <bits/stdc++.h>

#define FOR(i,n) for(int i=0;i<(n);++i)
#define FORU(i,j,k) for(int i=(j);i<=(k);++i)
#define FORD(i,j,k) for(int i=(j);i>=(k);--i)

#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

using namespace std;

using lli = long long int;
using pll = pair<lli, lli>;

string TYPE(int*)  { return "%d";   }
string TYPE(lli*)  { return "%lld"; }
string TYPE(char*) { return "%c";   }

void RD() {}
template<typename T, typename... Args> 
void RD(T* v, Args... args)
{
    scanf((" " + TYPE(v)).c_str(), v);
    RD(args...);
}

void PR(bool nl = true)
{ if(nl) printf("\n"); }
template<typename T, typename... Args> 
void PR(bool nl, T v, Args... args)
{
    printf((TYPE(&v) + "").c_str(), v);
    PR(nl, args...);
}
template<typename... Args> 
void PR(Args... args)
{ PR(true, args...); }

vector<string> split(const string& s, char c)
{
    vector<string> v;
    stringstream ss(s);
    string x;
    while (getline(ss, x, c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args)
{
    cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
    err(++it, args...);
}

const long long int oo = 1000*1000*1000;

struct Pos
{
    int x, y;
	int dist;
	int actu;
    Pos(int x = 0, int y = 0, int dist = 0, int actu = 0) : x(x), y(y), dist(dist), actu(actu) {}
    Pos operator + (const Pos& droite) const
    {
        return Pos(x + droite.x, y + droite.y, dist + droite.dist, actu);
    }
    Pos operator - (const Pos& droite) const
    {
        return Pos(x - droite.x, y - droite.y, dist - droite.dist, actu);
    }
};

struct AB
{
    int k;
    vector<lli> arbre;
    AB(int _k = 20, lli def = 0)
    {
        k = _k;
        FOR(i, 1 << k)
            arbre.push_back(i < (1 << (k-1)) ? 0LL : def);
        FORD(i, ((1 << (k-1)) - 1), 1)
            arbre[i] = arbre[i << 1] + arbre[(i << 1) ^ 1];
    }
    void set(int i, lli x)
    {
        int feuille = i + (1 << (k-1));
        arbre[feuille] = x;
        iset(feuille >> 1);
    }
    void iset(int noeud)
    {
        if(noeud)
        {
            arbre[noeud] = arbre[noeud << 1] + arbre[(noeud << 1)  ^ 1];
            iset(noeud >> 1);
        }
    }
    lli sum(int deb, int fin, int noeud = 1, int p = 0, int q = -1)
    {
        if(q < p)
            q = 1 << (k-1);
        if(deb <= p && q <= fin)
            return arbre[noeud];
        if(deb >= q || fin <= p)
            return 0LL;
        int mil = (p + q) / 2;
        return sum(deb, fin, noeud << 1, p, mil) + sum(deb, fin, (noeud << 1) ^ 1, mil, q);
    }
};

int main()
{
	int x1, y1, x2, y2;
	RD(&x1, &y1, &x2, &y2);
	FOR(i, x2-x1)
		PR(false, 'R');
	FOR(i, y2-y1)
		PR(false, 'U');
	FOR(i, x2-x1)
		PR(false, 'L');
	FOR(i, y2-y1)
		PR(false, 'D');
	PR(false, 'D');
	FOR(i, x2-x1+1)
		PR(false, 'R');
	FOR(i, y2-y1+1)
		PR(false, 'U');
	PR(false, 'L');
	PR(false, 'U');
	FOR(i, x2-x1+1)
		PR(false, 'L');
	FOR(i, y2-y1+1)
		PR(false, 'D');
	PR(false, 'R');
	PR();
    return 0;
}


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

const int INF =1e9;
const int MOD =1e9+7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] ={ 1, 0, -1, 0 };
int dy[4] ={ 0, 1, 0, -1 };

int main()
{
int n,k;
cin>>n>>k;
vector<int> vi(n);
REP(i,n)
cin>>vi[i];
sort(ALL(vi));
int ans=0;
REP(i,k){
    ans+=vi[i];
}
cout<<ans<<endl;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M;
vector <int> Graph[int(2e5+5)];
int Group[int(2e5+5)];
bool visited[int(2e5+5)];
int cnt[int(2e5+5)];

int Solve(int num){
  Group[num] = num;
  visited[num] = true;
  queue <int> que; que.push(num);

  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int next : Graph[Q]){
      if (visited[next]) continue;
      visited[next] = true;
      Group[next] = Group[Q];
      que.push(next);
    }
  }
  return 0;
}

int main(){
  cin >> N >> M;
  for (int i = 0; i < M; i++){
    int A, B; cin >> A >> B;
    Graph[A].push_back(B);
    Graph[B].push_back(A);
  }

  for (int i = 1; i <= N; i++){
    if (visited[i]) continue;
    Solve(i);
  }

  for (int i = 1; i <= N; i++){
    cnt[Group[i]]++;
  }
  int ans = 0;
  for (int i = 1; i <= N; i++){
    ans = max(ans, cnt[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 16016
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}


//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;

int main(){
  int A,B,C,K;cin>>A>>B>>C>>K;
  int cnt=0;
  while(A>=B){
    B*=2;
    cnt++;
  }

  while(B>=C){
    C*=2;
    cnt++;
  }
  if(cnt<=K)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  
}







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

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define FILL0(x) memset(x,0,sizeof(x))
#define FILL1(x) memset(x,-1,sizeof(x))

using namespace std;

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

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;

    for(int i=1;i<=N; i++)
    {
        int ans = 0;
        for(int j=1; j*j<=i; j++)
        {
            for(int k=j; k*k<=i; k++)
            {
                for(int l=k; l*l<=i; l++)
                {
                    int eq = l*l+ j*j + k*k + j*k + k*l + l*j;

                    if(eq==i)
                    {
                        if(l==j && j==k)
                        {
                            ans++;
                        }
                        else if(l==j || j== k || k==l )
                        {
                            ans+=3;
                        }
                        else
                        {
                            ans +=6;
                        }
                        
                    }
                }
            }
        }
        cout << ans << endl;
    }



    return 0;

}



Measured memory_bytes: 3636