akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stack>
#include<string>
#include<cstdio>

using namespace std;

class Stack {
private:
    int m_cnt;
    int m_stack[100000];
public:
    Stack() :m_cnt(0) {
        for (int i = 0; i < 100000; i++) (*this).m_stack[i] = 0;
    };
    void push(int x) {
        (*this).m_stack[(*this).m_cnt] = x;
        (*this).m_cnt++;
    };
    void pop() {
        if ((*this).m_cnt == 0) {
            cout << "Stack is empty." << endl;
        }
        else {
            (*this).m_cnt--;
        }
    };
    int size() {
        return (*this).m_cnt;
    };
    int top() {
        return (*this).m_stack[(*this).m_cnt - 1];
    };
};

int main() {
    Stack stk;
    char s[100];
    int x, ans = 0, i = 0;
    while(scanf("%s",s) != EOF){
        if (s[0] == '+') {
            int x1 = stk.top(); stk.pop();
            int x2 = stk.top(); stk.pop();
            ans = x1 + x2;
            stk.push(ans);
        }
        else if (s[0] == '-') {
            int x1 = stk.top(); stk.pop();
            int x2 = stk.top(); stk.pop();
            ans = x2 - x1;
            stk.push(ans);
        }
        else if (s[0] == '*') {
            int x1 = stk.top(); stk.pop();
            int x2 = stk.top(); stk.pop();
            ans = x1 * x2;
            stk.push(ans);
        }
        else{
            x = atoi(s);
            stk.push(x);
        }
    }
    cout << stk.top() << endl;
    return 0;
}


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

using pint = pair<int,int>;

int N;
vector<vector<pint>> V;

bool judge(int bit) {
  for (int i = 0; i < N; i++) {
    if ( !(bit & (1 << i)) ) continue;
    for (pint X : V[i]) {
      int x = X.first; 
      int y = X.second;
      if (y == 1 && !(bit & (1 << x))) return false;
      if (y == 0 && (bit & (1 << x))) return false;
      }
  }
  return true;
}


int main() {
  cin >> N;
  V.resize(N);
  for (int i = 0; i < N; i++) {
    int A; cin >> A;
    V.at(i).resize(A);
    for (int j = 0; j < A; ++j) {
      cin >> V.at(i).at(j).first >> V.at(i).at(j).second;
      V.at(i).at(j).first--; 
    }
  }

  int ans = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    if (judge(bit)) {
      int count = 0;
      for (int i = 0; i < N; i++) {
        if (bit & (1 << i)) count++;
      }
      ans = max(ans, count);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
using ll=long long;using ull=unsigned long long;
#include<limits>
namespace pcl{template<typename T>constexpr T TNF=std::numeric_limits<T>::max()/2;constexpr int INF=TNF<int>;constexpr ll LNF=TNF<ll>;constexpr double DNF=TNF<double>;constexpr double EPS=1e-8;constexpr int P7=1'000'000'007;constexpr int DX[]={1,0,-1,0,1,1,-1,-1};constexpr int DY[]={0,1,0,-1,-1,1,1,-1};}
#include<algorithm>
#include<cmath>
#include<iostream>
namespace pcl{template<typename T>void updmax(T&a,T const&b){a=std::max(a,b);}template<typename T>void updmin(T&a,T const&b){a=std::min(a,b);}template<typename T,typename U,typename V>bool in_range(T const&begin,U const&mid,V const&end){return begin<=mid&&mid<end;}template<typename T,typename U,typename V>bool in_range(T const&begin,std::initializer_list<U>list,V const&end){auto p=std::minmax_element(list.begin(),list.end());return begin<=*p.first&&*p.second<end;}template<typename T,typename U,typename V>bool in_range_strict(T const&begin,std::initializer_list<U>list,V const&end){if(!std::is_sorted(list.begin(),list.end()))return false;return in_range(begin,list,end);}template<typename T>inline T cget(){T x;std::cin>>x;return x;}}
#include<iostream>
#include<vector>
namespace pcl{template<typename T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){os<<'[';for(size_t i=0;i<v.size();i++){if(i!=0)os<<",";os<<v[i];}os<<']';return os;}template<typename T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(size_t i=0;i<v.size();i++)is>>v[i];return is;}}
#include<bits/stdc++.h>
using namespace std;using namespace pcl;int main(){int N;cin>>N;vector<vector<pair<int,int>>>graph(N);for(int i=0;i<N-1;i++){int u,v,w;cin>>u>>v>>w;u--;v--;graph[u].push_back(make_pair(v,w));graph[v].push_back(make_pair(u,w));}vector<int>color(N,-1);function<void(int,int)>dfs=[&](int curr,int sum){for(auto const&child:graph[curr]){if(color[child.first]!=-1)continue;color[child.first]=(sum+child.second)%2==0;dfs(child.first,sum+child.second);}};color[0]=1;dfs(0,0);for(int c:color)cout<<c<<endl;}


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

int main()
{
  int n,count=0;cin>>n;
  int p[n];
  for(int i=0; i<n;i++)
  {  cin>> p[i];}
  
  for( int i=1;i<n-1;i++)
  {
    vector <int> v;
    v.push_back(p[i]);
        v.push_back(p[i-1]);  v.push_back(p[i+1]);
    sort (v.begin(),v.end());
    if(v.at(1)==p[i])
      count++;
  }
  cout<<count;
}
  


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner sc = new Scanner(System.in);
        int height = sc.nextInt();
        int width = sc.nextInt();
        int line = sc.nextInt();
        int column = sc.nextInt();
        
        System.out.println(height*width - line*width -column*height + line*column);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n; cin>>n;
	string s;
	while(n>0){
		n-=1;
		s+=('a'+n%26);
		n/=26;
	}
	reverse(s.begin(), s.end());
	cout<<s<<endl;
}

Measured memory_bytes: 3528
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
using llong = long long;
const int MOD=1000000007;

int main(int argc, char**argv){
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i+=2){
        cout << s[i];
    }
    cout << endl;

    return 0;
}




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

bool L[600][600][300];
int main()
{
	ll n;
	cin >> n;
	vector<string> s(n);
	for (ll i = 0; i < n; i++)
		cin >> s[i];

	for (ll i = 0; i < n*2; i++)
	{
		for (ll j = 0; j < n*2; j++)
		{
			for (ll k = 1; k < n; k++)
			{
				L[i][j][k] = L[i][j][k - 1] | (s[(i + k) % n][j%n] != s[i%n][(j + k) % n]);
			}
		}
	}

	ll ans = 0;
	for (ll i = 0; i < n; i++)
	{
		for (ll j = 0; j < n; j++)
		{
			bool sum = 0;

			for (ll k = n - 1; k >= 0; k--)
			{
				sum |= L[i+n-k-1][j+n-k-1][k];
				// cout <<L[i][j][k]<<endl;
				if(sum)break;
			}
			// cout << endl;
			if (sum == 0) ans++;
		}
	}
	cout << ans << endl;
}


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

int main() {
  int R; cin >>R;
  if (R<1200) cout <<"ABC" <<endl;
  else if (R<2800) cout <<"ARC" <<endl;
  else cout <<"AGC" <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
inline int getint(){
    char c=getchar();int x=0;bool p=0;
    while((c>'9'||c<'0')&&c!='-')c=getchar();
    if(c=='-')p=1,c=getchar();
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    if(p)x=-x;return x;
}
int main(){
	int n,k;cin>>n>>k;
	cout<<n-k+1<<endl; 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int arr[n + 1];
	ll sum[n + 1] = {};
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		sum[i + 1] = sum[i] + arr[i];
	}
	ll ans = 1e18;

	for (int i = 1; i < n; i++) {
		ans = min(ans, abs((sum[n] - sum[i]) - sum[i]));
	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 5916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += s[i]-'0';
        sum %= 9;
        //cout << sum << endl;
    }
    if(sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3716
s = gets.chop
l = 0
max = 0
(0..s.size - 1).each do |i|
  if s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'
    l += 1
    max = [max, l].max
  else
   l = 0
  end
end
puts max

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

class UnionFind {
private:
  vector<ll> parent;
  vector<ll> rank;

public:
  vector<ll> sz;
  UnionFind(ll size) : parent(size), rank(size, 0), sz(size, 1) {
    for (ll i = 0; i < size; i++) {
      parent[i] = i;
    }
  }

  ll find(ll x) {
    if (parent[x] == x) {
      return x;
    } else {
      return parent[x] = find(parent[x]);
    }
  }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
      parent[x] = y;
      sz[y] += sz[x];
    } else {
      parent[y] = x;
      sz[x] += sz[y];
      if (rank[x] == rank[y]) rank[x]++;
    }
  }

  bool same(ll x, ll y) {
    return find(x) == find(y);
  }
};

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

  ll n, m, k;
  cin >> n >> m >> k;
  vl a(m), b(m), c(k), d(k);
  vector<vl> block(n), tomo(n);

  UnionFind uf(n);

  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    tomo[a[i]].push_back(b[i]);
    tomo[b[i]].push_back(a[i]);
    uf.unite(a[i], b[i]);
  }

  rep(i, k) {
    cin >> c[i] >> d[i];
    c[i]--;
    d[i]--;
  }

  vl ans(n);
  rep(i, n) {
    ans[i] = uf.sz[uf.find(i)]-1;
  }

  rep(i, m) {
    if (uf.same(a[i], b[i])) {
      ans[a[i]]--;
      ans[b[i]]--;
    }
  }
  
  rep(i, k) {
    if (uf.same(c[i], d[i])) {
      ans[c[i]]--;
      ans[d[i]]--;
    }
  }

  rep(i, n) {
    cout << ans[i];
    if (i == n-1) cout << endl;
    else cout << " ";
  }
}


Measured memory_bytes: 15732
# include <bits/stdc++.h>
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG

using namespace std;

const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int n, x, mx;
string s;

int main()
{
    speed;
    /// Author: Dilshod--Imomov
    #ifdef DEBUGd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG
    cin >> n >> s;
    for ( int i = 0; s[i]; i++ ) {
        if ( s[i] == 'I' ) x++;
        else x--;
        mx = max(mx, x);
    }
    cout << mx;
}



Measured memory_bytes: 256
/**
 * D - Water Bottle
 * https://atcoder.jp/contests/abc144/tasks/abc144_d
 **/
#include<iostream>
#include<cmath>
#include<iomanip>


#define PI 3.141592653589793
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    if(x>0.5*a*a*b) {
        double rad = atan(2*(a*a*b-x)/(double(a*a*a)));
        cout << fixed << setprecision(10) << ((rad)/2.0/M_PI)*360.0 << endl;
    } else {
        double rad = atan(0.5*a*b*b/(double)x);
        cout << fixed << setprecision(10) << rad_to_deg(rad) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = input()
M = [map(int, raw_input().split()) for i in xrange(N)]
cache = {}
for i in xrange(N):
    cache[(i, i+1)] = 0
def dfs(left, right):
    if (left, right) in cache:
        return cache[(left, right)]
    min_cost = float("inf")
    for mid in xrange(left+1, right):
        tmp = M[left][0] * M[mid-1][1] * M[right-1][1]
        tmp += dfs(left, mid)
        tmp += dfs(mid, right)
        if min_cost > tmp:
            min_cost = tmp
    cache[(left, right)] = min_cost
    return min_cost
print dfs(0, len(M))

Measured memory_bytes: 4748
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main(){

    ll n;
    L(n);

    for(ll i = -1000;i<=1000;i++){
        for(ll j = -1000;j<=1000;j++){
            ll x = PW(i, 5ll);
            ll y = PW(j, 5ll);
            if(x-y==n){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3692
N,M,X = map(int,input().split(" "))
A = [int(i) for i in input().split(" ")]
low = [0]*(N+1)

for i in A:
    low[i]=1

count1 = 0
count2 = 0

x=X
while(x!=0):
    count1+=low[x]
    x-=1
x=X
while(x!=N):
    count2+=low[x]
    x+=1
if count1<count2:
    print(count1)
else:
    print(count2)

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

using namespace std;

int main(){
    int N, M, X, Y;
    array<int, 100> x, y;
    cin >> N >> M >> X >> Y;
    for (int i = 0; i < N; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> y[i];
    }

    sort(&x[0], &x[N]);
    sort(&y[0], &y[M]);

    for (int i = Y; X < i; --i) {
        if(x[N-1] < i && i <= y[0]){
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a, b;
    int ans;
    
    scanf("%d%d", &a, &b);
    
    ans=fmax(a+b, a-b);
    ans=fmax(ans, a*b);
    
    printf("%d", ans);
    
    return 0;
}



Measured memory_bytes: 2120
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
typedef long long int  ll;
#define loop() for(int i=0; i<(n); i++)
const ll MOD=998244353;
ll fast_exp(ll base, ll exp) 
{
    ll res=1;
    while(exp>0) 
    {
       if(exp%2==1) 
       	res=(res*base)%MOD;
       base=(base*base)%MOD;
       exp/=2;
    }
    return res%MOD;
}

ll gcdExtended(ll a, ll b, ll *x, ll *y);   

ll modInverse(ll b, ll m) 
{ 
    ll x, y; // used in extended GCD algorithm 
    ll g = gcdExtended(b, m, &x, &y); 
  
    // Return -1 if b and m are not co-prime 
    if (g != 1) 
        return -1; 
  
    // m is added to handle negative x 
    return (x%m + m) % m; 
} 
  
// Function to compute a/b under modlo m 
ll modDivide(ll a, ll b, ll m) 
{ 

    a = a % m; 
    ll inv = modInverse(b, m); 
    return (inv * a) % m; 
} 
  
// C function for extended Euclidean Algorithm (used to 
// find modular inverse. 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    // Base Case 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; // To store results of recursive call 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    // Update x and y using results of recursive 
    // call 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}
ll calc(ll diff,ll x)
{
	ll a=fast_exp(x,diff)-1;
	ll b=x-1;
	return modDivide(a,b,MOD);
}


void solve()
{
	//code	
	ll n;
	cin>>n;
	int a[n];
	loop()
	cin>>a[i];
	ll count=0;
	loop()
	{
		if(i%2==0 && a[i]%2==1)
			count++;
	}
	cout<<count<<endl;
	
}


int main(){
	fast
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3648
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main( void ) {

    int r, g, b;
    cin >> r >> g >> b;
    r = r * 100 + g * 10 + b;

    if ( r % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;   
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace arc061_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] formulas = new string[(int)Math.Pow(2,s.Length - 1)];
            int a = 1;
            for (int i = 0; i < s.Length; i++)
            {
                for (int j = 0; j < Math.Pow(2,s.Length - 1); j++)
                {
                    formulas[j] = formulas[j] + s[i];
                    if ((j / a) % 2 == 1) formulas[j] = formulas[j] + '+';
                }
                a *= 2;
            }
            long ret = 0;
            for (int i = 0; i < Math.Pow(2,s.Length - 1); i++)
            {
                long[] x = formulas[i].Split('+').Select(long.Parse).ToArray();
                ret += x.Sum();
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 13396
N = int(input())
number = input().split()
number = [int(s) for s in number]
for i in range(1, 31):
   frag = 0
   for j in range(N):
      if number[j] % (2**i) != 0:
         frag = 1
         break
   if frag == 1:
      print(i - 1)
      break

Measured memory_bytes: 3060
#include <climits>
#include <iostream>
#include <vector>

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  std::vector<int> h(n);
  for (int i = 0; i < n; ++i)
    std::cin >> h.at(i);

  std::vector<int> dp(n, INT_MAX);
  dp.at(0) = 0;
  for (int i = 0; i < n - 1; ++i) {
    dp.at(i + 1) =
        std::min(dp.at(i + 1), dp.at(i) + std::abs(h.at(i) - h.at(i + 1)));
    if (i < n - 2)
      dp.at(i + 2) =
          std::min(dp.at(i + 2), dp.at(i) + std::abs(h.at(i) - h.at(i + 2)));
  }

  std::cout << dp.at(n - 1) << std::endl;
}


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

int main()
{
	int x, y;
	cin >> x >> y;
	bool flag = false;
	for (int i = 0; i <= x; i++) {
		if (2 * i + 4 * (x - i) == y)flag = true;
	}
	if (flag)cout << "Yes";
	else
		cout << "No";

}

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

string chop(string& s, int i, int j) {
    assert(i <= j);
    return s.substr(i, j - i);
}

string _solve(string s) {
    if (s[0] == 'a') {
        vector<int> ap, bp;
        for (int i = 0; i < s.size(); i++) {
            (s[i] == 'a' ? ap : bp).push_back(i);
        }
        string t;
        for (int i = 0; i < ap.size();) {
            t.push_back('a');
            t.push_back('b');
            for (int targ = bp[i]; i < ap.size() && ap[i] <= targ; i++);
        }
        return t;
    } else {
        string t = s;
        for (string u = s; !u.empty();) {
            int i = 0, j = 0;
            while (u[i] != 'a') i++;
            while (u[j] != 'b') j++;
            u = chop(u, 0, min(i, j)) + chop(u, min(i, j) + 1, max(i, j)) + chop(u, max(i, j) + 1, u.size());
            t = max(t, u);
        }
        return t;
    }
}

int main() {
    int n;
    vector<string> parts;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size();) {
        int t = 0, j = i;
        while (j < s.size()) {
            if (!(t += s[j++] == 'b' ? 1 : -1)) break;
        }
        parts.push_back(_solve(chop(s, i, j)));
        i = j;
    }
    string t = "";
    reverse(parts.begin(), parts.end());
    for (string& u: parts) {
        t = max(t, u + t);
    }
    cout << t << '\n';
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int s,h,m;
	scanf("%d",&s);
	
	h=s/3600;
	s=s-h*3600;
	m=s/60;
	s=s-m*60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
s = input()
all_s = []
def ss(index, perm):
    if index == len(s):
        all_s.append(perm)
    else:
        perm1 = [i for i in perm]
        perm1[-1] += s[index]
        ss(index+1, perm1)

        perm2 = [i for i in perm]
        perm2.append(s[index])
        ss(index+1, perm2)

ss(1, [s[0]])
all_sum = 0
for way in all_s:
    tmp = 0
    for n in way:
        tmp += int(n)
    all_sum += tmp
print(all_sum)


Measured memory_bytes: 9116
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int[] a = {1,3,5,7,8,10,12};
		int[] b = {4,6,9,11};
		int[] c = {2};
		int d = sc.nextInt(), e = sc.nextInt();
		boolean ok = (Arrays.binarySearch(a,d)>=0 && Arrays.binarySearch(a,e)>=0)||
		(Arrays.binarySearch(b,d)>=0 && Arrays.binarySearch(b,e)>=0)||(Arrays.binarySearch(c,d)>=0 && Arrays.binarySearch(c,e)>=0); 
		System.out.println(ok ? "Yes" : "No");
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35696
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll N,M,G=0;
    char A[107][17],B[107][17];
    cin>>N;
    rep(i,N){
        cin >> A[i];
    }
    cin >> M;
    rep(i,M){
        cin >> B[i];
    }   
    rep(i,N){
        int L=0;
        rep(j,N){
            if(strcmp(A[i],A[j])==0){
                L++;
            }
        }
        rep(j,M){
            if(strcmp(A[i],B[j])==0){
                L--;
            }
        }
        G=(L>G ? L : G);
    }
    cout << G << endl;
}

Measured memory_bytes: 256
// Oh damn, cann't you see I'm fine?

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

const int max_n = 1e6 + 5;
const int M = 1e9 + 7;

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

	int x;
	cin >> x;
	cout << 1 - x << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 10000
int arr[MAX+2],N;
 
int solve(int p){
    int lp = p, rp = p+1;
 
    while(true){
	if(lp <= 0 || rp >= N+1) break;
	int color = arr[lp],l,r;
	for(l = lp ; arr[l] == color ; l--);
	for(r = rp ; arr[r] == color ; r++);
	if((r-rp)+(lp-l) < 4) break;
	lp = l, rp = r;
    }
    return N - rp + lp + 1;
}
 
int main(){
    while(cin >> N, N){
	memset(arr,0,sizeof(arr));
	for(int i = 1 ; i <= N ; i++){
	    cin >> arr[i]; 
	}
	int ans = MAX;
	for(int i = 1 ; i <= N ; i++){
	    int tmp = arr[i];
	    for(int j = 0 ; j < 3 ; j++){
		if(arr[i] == j+1) continue;
		arr[i] = j+1;
		ans = min(ans,solve(i));   
	    }
	    arr[i] = tmp;
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3116
#include <iostream>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b ) {
  ll t;
  if( a < b ){ t = a; a = b; b = t; }
  while( ( t = a % b ) != 0 ){ a = b; b = t; }
  return b;
}
int main() {
  ios::sync_with_stdio(false);
  int N, A, ret;
  cin >> N;
  cin >> ret;
  for (int i=1; i<N; i++) {
    cin >> A;
    ret = gcd(ret, A);
  }
  cout << ret << endl;
}

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

/*int cal(int m,int l){

}*/
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> count(n + 100);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        count[a[i]]++;
    }
    ll sum = 0;
    for (ll i = 1; i <= n; ++i) {
        sum += count[i] * (count[i] - 1) / 2;
    }
    for (ll i = 0; i < n; ++i) {
        ll diff = count[a[i]] - 1;
        print(sum - diff);
    }

}


Measured memory_bytes: 5760
N = gets.to_i

if N <= 5
  puts [
    [2, 5, 20, 30, 63],
    [2, 5, 20, 63],
    [2, 5, 63],
  ][5 - N].join(' ')
else
  list2 = [*1..3 * N].map { |x| 2 * x }
  list3 = [*1..3 * N].map { |x| 3 * x }

  list2.delete_if { |x| x % 6 == 0 }

  rui2 = [0]
  rui3 = [0]

  (1..list2.size).each do |i|
    rui2[i] = rui2[i - 1] + list2[i - 1]
  end

  (1..list3.size).each do |i|
    rui3[i] = rui3[i - 1] + list3[i - 1]
  end

  (1..N).each do |a|
    b = N - a

    next if rui2[a] % 3 > 0
    next if rui3[b] % 2 > 0
    next if list2[a - 1] > 30_000
    next if list3[b - 1] > 30_000

    puts (list2.take(a) + list3.take(b)).join(' ')

    break
  end
end


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

struct Node {
  int key;
  Node *p, *l, *r;
};

Node *null, *root;

void Print_P(Node *n) {
  if (n == null)
    return;
  printf(" %d", n->key);
  Print_P(n->l);
  Print_P(n->r);
}

void Print_M(Node *n) {
  if (n == null)
    return;
  Print_M(n->l);
  printf(" %d", n->key);
  Print_M(n->r);
}

const char *Find(Node *n, int k) {
  while (n != null && k != n->key) {
    if (k < n->key)
      n = n->l;
    else
      n = n->r;
  }
  if (n != null)
    return "yes";
  else
    return "no";
}

void Insert(int k) {
  Node *y = null, *x = root, *z = (Node *)malloc(sizeof(Node));
  z->key = k, z->l = null, z->r = null;
  while (x != null) {
    y = x;
    if (z->key < x->key)
      x = x->l;
    else
      x = x->r;
  }
  z->p = y;

  if (y == null)
    root = z;
  else if (z->key < y->key)
    y->l = z;
  else
    y->r = z;
}

int main() {
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    char o[7];
    scanf("%s", o);
    if (strcmp(o, "insert") == 0) {
      int k;
      scanf("%d", &k);
      Insert(k);
    } else if (strcmp(o, "find") == 0) {
      int k;
      scanf("%d", &k);
      printf("%s\n", Find(root, k));
    } else {
      Print_M(root);
      printf("\n");
      Print_P(root);
      printf("\n");
    }
  }
}


Measured memory_bytes: 21964
num_line = input().split(" ")
a=int(num_line[0])
b=int(num_line[1])
c=int(num_line[2])
d=int(num_line[3])
ans=0

lista=[]
lista.append(a*c)
lista.append(a*d)
lista.append(b*c)
lista.append(b*d)

lista.sort(reverse=True)

print(lista[0])

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

typedef long long int ll;
typedef long long unsigned int ull;
typedef long double ld;
typedef vector<int> vr;
typedef pair<int, int> pr;
#define pb push_back
#define ff first
#define ss second
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433
#define endl "\n"
//cout << fixed << setprecision(2);

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >> s;
    int len = s.size();
    //cout << len << endl;
    string ke = "keyence";
    int j = 0;
    for(int i = 0; i <= 7; i++){
        //cout << s.substr(0, i) << " = " <<  s.substr(s.size()-7+i) << endl;
        if(s.substr(0, i) + s.substr(s.size()-7+i) == ke){
           cout << "YES" << endl;
           return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int n;
vector<vector<int> >g;
int dist[110];
void bfs(int u) {
    queue<int> q;
    q.push(u);
    rep(i,n) dist[i] = -1;
    dist[u] = 0;
    while(!q.empty()) {
        int v = q.front();q.pop();
        for(int i = 0;i<g[v].size();i++) {
            int nv = g[v][i];
            if(dist[nv] == -1) {
                q.push(nv);
                dist[nv] = dist[v] + 1;
            }               
        }
    }
}
int main() {
    cin >> n;
    g.assign(n,vector<int>());
    rep(i,n) {
        int u,k;
        cin >> u >> k;
        u--;
        rep(j,k) {
            int v;
            cin >> v;
            v--;
            g[u].push_back(v);
        }
    }
    bfs(0);
    rep(i,n) cout << i+1 << " " << dist[i] << endl;
}


Measured memory_bytes: 3156
let m = 1000003

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let to_x = Array.make 128 0

let to_key s =
  let n = String.length s in
  let rec doit i p acc =
    if i = n then acc
    else doit (i + 1) (5*p) (acc + p*(to_x.(Char.code s.[i]))) in
  doit 0 1 0

let to_h1 k = k mod m
let to_h2 k = 1 + (k mod (m - 1))

let insert s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then ()
    else if t.(h) = "\000" then t.(h) <- s
    else doit (i + 1) in
  doit 0

let find s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then true
    else if t.(h) = "\000" then false
    else doit (i + 1) in
  doit 0

let () =
  to_x.(Char.code 'A') <- 1;
  to_x.(Char.code 'C') <- 2;
  to_x.(Char.code 'G') <- 3;
  to_x.(Char.code 'T') <- 4;
  let n = read_int () in
  let t = Array.make m "\000" in
  let rec doit i =
    if i < n then begin
      begin match split (read_line ()) ' ' with
      | ["insert"; s] -> insert s t
      | ["find"; s] -> print_endline (if find s t then "yes" else "no")
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

Measured memory_bytes: 20276
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

bool dfs(vector <vector <pair <int, int>>>& G, int num[], int now, bool judge) {
	rep (i, G[now].size()) {
		if (num[G[now][i].first] == INF) continue;
		judge = judge && ((num[now] - num[G[now][i].first]) == -G[now][i].second);
	}

	rep (i, G[now].size()) {
		if (num[G[now][i].first] != INF) continue;
		num[G[now][i].first] = num[now] + G[now][i].second;
		judge = judge && dfs(G, num, G[now][i].first, judge);
	}

	return judge;
}

signed main() {
	int n, m;
	cin >> n >> m;
	vector <vector <pair <int, int>>> G(n);
	rep (i, m) {
		int l, r, d;
		cin >> l >> r >> d;
		l--; r--;
		G[l].push_back({r, d});
		G[r].push_back({l, -d});
	}
	int num[n];
	bool ans = true;
	fill(num, num + n, INF);
	rep (i, n) {
		if (num[i] != INF) continue;
		num[i] = 0;
		ans = ans && dfs(G, num, i, true);
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

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

#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define clr(x) memset((x), 0, sizeof((x)));
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long i64;
typedef unsigned long long ull;

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

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

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

ll gcd(ll a, ll b) {
    a = abs(a);
    b = abs(b);
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

typedef ld ptdata;

struct pt {
    ptdata x, y;

    pt() {}

    pt(ptdata x, ptdata y) : x(x), y(y) {}

    inline pt operator-(const pt &r) const {
        return pt(x - r.x, y - r.y);
    }

    inline pt operator+(const pt &r) const {
        return pt(x + r.x, y + r.y);
    }

    inline pt operator*(const ptdata &r) const {
        return pt(x * r, y * r);
    }

    inline ptdata sqlen() const {
        return abs(x * x + y * y);
    }

    inline ld len() const {
        return sqrt(sqlen());
    }

    inline bool operator<(const pt &r) const {
        if (x != r.x) return x < r.x;
        return y < r.y;
    }

    inline bool operator==(const pt &r) const {
        return x == r.x && y == r.y;
    }
};

ostream &operator<<(ostream &os, const pt &p) {
    return os << "(" << p.x << "," << p.y << ")";
}

inline ptdata cross(const pt &l, const pt &r) {
    return l.x * r.y - l.y * r.x;
}

inline ptdata dot(const pt &l, const pt &r) {
    return l.x * r.x + l.y * r.y;
}


ll pwmod(ll a, ll n, ll mod) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ret;
}

template<typename T>
inline T sqr(T x) {
    return x * x;
}


inline void solve() {
    int n = nxt();
    vector<int> a(n);
    forn(i, n) {
        a[i] = nxt();
    }
    vector<int> b = a;
    sort(all(b));
    forn(i, n) {
        a[i] = lower_bound(all(b), a[i]) - b.begin();
    }
    ll ans = 0;
    forn(i, n) {
        int ps = abs(i - a[i]);
        if (ps & 1) {
            ans++;
        }
    }
    assert(ans % 2 == 0);
    ans /= 2;
    cout << ans << "\n";
}

void prepare() {

}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);


    prepare();

    int t = 1;
    //cin >> t;
    //t = nxt();
    forn(i, t) {
        solve();
    }

    cerr << "Time " << clock() / (double) CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 1024
//
// tested with : g++ (GCC) 8.3.0
//

#include <iostream>
#include <string>
using namespace std;

int main() {
    string s;
    cin >> s;

    int slength = s.length();
    string ans(slength,' ');
    int j = 0;
    for (int i = 0; i < slength; i++) {
        if (i % 2 == 0) { //0 2 4が奇数文字目。
            ans[j] = s[i];
            j++;
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
	int x[2], y[2];
	for(int i=0; i<2; ++i) cin >> x[i] >> y[i];
	cout << x[1]+y[0]-y[1] << ' ';
	cout << y[1]+x[1]-x[0] << ' ';
	cout << x[0]+y[0]-y[1] << ' ';
	cout << y[0]+x[1]-x[0] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main(){
   int n;
   cin>>n;
    for (int i = 0; i <=n; i++)
    {
        if((int)(i*1.08)==n) {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastio;
    int a, b;
    cin >> a >> b;
    if (a % 2 == 0 || b % 2 == 0)
        cout << "Even" << endl;
    else
        cout << "Odd" << endl;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int max=0;
    if(a==1) {
    	cout<<b;
    	return 0;
	}
    for(int i=1;i<=b/a;i++)
        if(b%i==0)
            if(i>=max) max=i;
	printf("%d",max);
    return 0;
}


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

int main() {
  long long n, m, d; cin >> n >> m >> d;
  double res;
  if (d == 0) res = (double)(m-1) / n;
  else res = (double)(m-1) * 2 * (n-d) / n / n;
  cout << fixed << setprecision(10) << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int inv[100005],finv[100005],f[100005];
int n,a[100005],mod=1000000007;
void C(){
	f[0]=1;finv[0]=1;finv[1]=1;f[1]=1;inv[1]=1;
	FOR(i,2,n){
		f[i]=f[i-1]*i%mod;
		inv[i]=mod-inv[mod%i]*(mod/i)%mod;
		finv[i]=finv[i-1]*inv[i]%mod; 
	}
}
int c(int n,int k){
	if(n<k)return 0;
	return f[n]*(finv[k]*finv[n-k]%mod)%mod;
}
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);int k;
	cin>>n>>k;
	FOR(i,1,n)cin>>a[i];
	sort(a+1,a+n+1);
	C();
	int ans=0;
	FOR(i,1,n){
		ans+=c(i-1,k-1)*a[i]%mod;
		ans=(ans+mod)%mod;
		ans-=c(n-i,k-1)*a[i]%mod;
		ans=(ans+mod)%mod;
	}
	cout<<ans;
	return 0;
}




Measured memory_bytes: 3328
import heapq as hq

num ,m =map(int,input().split())

arr = [-i for i in list(map(int,input().split()))]
hq.heapify(arr)

for i in range(m):
    hq.heappush(arr, -1*(-1*hq.heappop(arr)//2))

    
print(-1*sum(arr))
       

Measured memory_bytes: 73068
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

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

const int N = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

int H1, H2, M1, M2, K;

int main(){
	scanf("%d%d%d%d%d", &H1, &M1, &H2, &M2, &K);
	printf("%d\n", H2 * 60 + M2 - H1 * 60 - M1 - K);
	return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll n,d;
cin >> n >> d;
ll x[n][d];
for (ll i = 0; i < n;i++){
    for (ll j = 0; j < d;j++){
        cin >> x[i][j];
    }
}
ll dist[n][n];
for (ll i = 0; i < n;i++){
    for (ll j = 0; j < n;j++){
        dist[i][j] = 0;
    }
}
for (ll i = 0; i < n;i++){
    for (ll j = i+1; j < n;j++){
        for (ll k = 0; k < d;k++){
            dist[i][j] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
    }
}
ll ans = 0;
for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n;j++){
        for (ll k = 1; k <= 400;k++){
            if (k * k == dist[i][j]) ans++;
        }
    }
}
cout << ans << endl;
}


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
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; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N; cin >> N;
  vector<ll> a(N-1); FOR(i,N-1){ cin >> a[i]; }
  
  //main
  vector<ll> ans(N,0);
  FOR(i,N-1){ ans[a[i]-1] ++; }
  
  
  // output
  FOR(i,N){ cout << ans[i] << endl; } 

  return 0;
}

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

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


Measured memory_bytes: 4796
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, K = Scanner.map_int()
    ans = 0
    N += 1
    for i in range(K, N + 1):
        l = i * (i - 1) // 2
        r = N * i - ((i + 1) * i) // 2
        ans += r - l + 1
        ans %= MOD
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10696
#include <iostream>
using namespace std;
int main() {
  int A,B;
  cin >> A >> B;
  if (A>=13) {
      cout << B << endl;
  }
  else if (A<=5) {
      cout << 0 << endl;
  }
  else {
      cout << B/2 << endl;
  }
  return 0;
}

Measured memory_bytes: 3632