stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;



int main() {

    int M = 1 << 18 + 1;

    int N;

    cin >> N;

    vector<int> A(N), a(N), ord(N);

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

        cin >> A[i];

        a[i] = A[i];

    }



    sort(a.begin(), a.end());

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

        ord[i] = lower_bound(a.begin(), a.end(), A[i]) - a.begin();

    }



    ll ans = 0;

    vector<int> bit(M);

    int k,sum;

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

        // add

        k = ord[i] + 1;

        while ( k <= M ) {

            bit[k]++;

            k += k & -k;

        }

        // sum

        sum = 0;

        k = ord[i] + 1;

        while ( k > 0 ) {

            sum += bit[k];

            k -= k & -k;

        }

        

        ans += i + 1 - sum;

    }



    cout << ans << '\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.0863251363054167x):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;



template<typename T> struct BIT {

    int max_n;

    vector<T> data;

    const bool zi;

    const T unit;

    BIT<T>(int n, bool zi = true, T u = T(0)) : max_n(n), zi(zi), unit(u) {

        data.assign(max_n + 1, u);

    }

    void add(int i, T x) {

        if ( zi ) i++;

        assert( i > 0 );

        while ( i <= max_n ) {

            data[i] += x;

            i += i & -i;

        }

    }

    T sum(int i) {

        if ( zi ) i++;

        assert( i > 0 );

        T s = unit;

        while ( i > 0 ) {

            s += data[i];

            i -= i & -i;

        }

        return s;

    }

    vector<T> get_sum_list(int l, int r) {

        vector<T> ret;

        for ( int i = l; i <= r; i++ ) {

            ret.push_back(sum(i));

        }

        return ret;

    }

};



ll solve() {

    ll N;

    cin >> N;

    vector<ll> A(N);

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

        cin >> A[i];

    }



    vector<ll> xs1(A);

    sort(xs1.begin(), xs1.end());

    xs1.erase(unique(xs1.begin(), xs1.end()), xs1.end());

    for ( int ii = 0; ii < A.size(); ii++ ) {

        A[ii] = lower_bound(xs1.begin(), xs1.end(), A[ii]) - xs1.begin();

    }

    

    BIT<ll> bit(N+1);

    ll ans = 0;

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

        ans += i - bit.sum(A[i]);

        bit.add(A[i], 1);

    }



    return ans;

}



int main() {

    auto ans = solve();

    cout << ans << "\n";

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

//#define int long long

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

using namespace std;

#define endl '\n'

#define fori(s,n) for(int i=s;i<n;i++) 

#define forj(s,n) for(int j=s;j<n;j++) 

int OO = 1e9 + 9;

#define vii vector<int>

int n, k;

vii v;

int maxi = 1061109567;

int dp[100000 + 9];

int solve(int x) {



	if (x == n)

		return 0;

	if (x > n)

		return OO;

	int& ret = dp[x];

	if (ret != maxi) return ret;

	int r1 = abs(v[x] - v[x + 1]) + solve(x + 1);

	fori(2, k + 1)

		r1 = min(r1, abs(v[x] - v[x + i]) + solve(x + i));

	return ret = r1;

}

signed main()

{

	fast;

	memset(dp, '?', sizeof(dp));



	cin >> n >> k;

	v = vii(n + 101);

	fori(1, n + 1) cin >> v[i];

	cout << solve(1) << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.4205790702436156x):
/*

 ALLAH is Almighty....

*/

#include <bits/stdc++.h>



#define ll  long long

using namespace std;



const ll mx = 10e5 + 9;

ll n, k;

ll ar[ mx ];

ll dp[ mx ];



void solve( )

{

    cin >> n >> k;

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

        dp[ i ] = 1e12;

        cin >> ar[ i ];

    }



    dp[ 0 ] = 0;

    for ( ll i = 1; i < n; ++i )

        for ( ll j = i - 1; j >= 0 && j >= i - k; --j )

            dp[ i ] = min( dp[ j ] + abs( ar[ i ] - ar[ j ] ), dp[ i ] );



    cout << dp[ n - 1 ] << "\n";

}



int main()         // Md. Inzamam-ul Haque

{

    solve();

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define F first

#define S second

#define PB push_back



using namespace std;



typedef long long ll;



int n, k;

ll h[100005];

ll memo[100005];



ll dp(int i){

	if(i == n-1)	return 0;

	if(i >= n)	return 10000000000;

	if(memo[i] != -1){

		return memo[i];

	}

	

	ll mmin = 1e10;



	for(int j = 1; j <= k; j++){

		mmin = min(abs(h[i] - h[i+j]) + dp(i+j), mmin);

	}



	return memo[i] = mmin;



}



int main(){



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

	

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);



	cin >> n >> k;

	for(int i = 0; i < n; i++){

		cin >> h[i];

	}



	cout << dp(0) << "\n";



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.801659031447751x):
#include <bits/stdc++.h>



#define F first

#define S second

#define PB push_back



using namespace std;



typedef long long ll;



int main(){

	

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);



	int n, k;

	cin >> n >> k;



	int h[n];

	for(int i = 0; i < n; i++){

		cin >> h[i];

	}



	int cost[n];

	cost[0] = 0;



	for(int i = 1; i < n; i++){

		cost[i] = INT_MAX;

		for(int j = 1; j <= k and i-j >= 0; j++){

			cost[i] = min(cost[i-j] + abs(h[i] - h[i-j]), cost[i]);	

		}

	}



	cout << cost[n-1] << "\n";



	return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;



int N;

int mod=1e9+7;

int main(){



    while(cin>>N){

            long long ans=1;

    for(int i=1;i<=N;i++){

        ans*=i;

        if(ans>mod){

            ans%=mod;

        }

    }

    cout<<ans<<endl;

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.931292266155239x):
#include <stdio.h>

int main ()

{

    int i,n;

    long long s;

    scanf("%d", &n);

    s = 1;

    for (i=1; i<=n;i++)

    {

        s *= i;

        s %= (int)1e9+7;

    }

    printf ("%d", s);

}
// Slower C++ solution:
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

ll n;

ll k;

ll h[100005];

ll dp[100005];

ll solve(int idx){

	if(idx == n-1) return 0;

	if(dp[idx]!=-1) return dp[idx];

	ll val = INT_MAX;

	for(int i = 1; i <= k; i++){

		if(idx + i<n){

			val = min(val, abs(h[idx] - h[idx+i]) + solve(idx +i));

		}

	}

	dp[idx] = val;

	return val;

}

int main()

{

	ios::sync_with_stdio(0);

	cin.tie(0);

	for(int i = 0; i < 100005; i++) dp[i] = -1;

	cin >> n >> k;

	for(int i = 0; i < n; i++) cin >> h[i];

	cout << solve(0);	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.790072224290064x):
#include <bits/stdc++.h>

typedef long long ll;

#define mod 1000000007

#define pb push_back

#define mp(a,b) make_pair(a,b)

#define pii pair<int,int>

#define pll pair<ll,ll>

#define vll vector <ll>

#define vii vector <int>

#define vpii vector <pii>

#define vpll vector <pll>

#define ff first

#define ss second

#define matrix vector <vll>

#define all(v) v.begin(),v.end()

#define PQ priority_queue

using namespace std;

ll pow(ll a, ll b){

	ll res = 1;

	while(b > 0){

		if(b&1) res*=a;

		b/=2;

		a*=a;

	}

	return res;

}

int main()

{

	ios::sync_with_stdio(0);

	cin.tie(0);

	ll n, k;

	cin >> n >> k;

	ll h[n], dp[n];

	for(int i = 0; i < n; i++) {

		cin >> h[i];

		dp[i] = INT_MAX;

	}

	dp[0] = 0;

	for(int i = 0; i < n; i++){

		for(int j = 1; j <= k && i+j < n; j++){

			dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]));

		}

	}

	cout << dp[n-1] << "\n";

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)

#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)

#define pb push_back

#define all(v) ((v.begin()),(v.end()))

#define memset(c, value) memset(c, (int)value, sizeof(c))

using namespace std;

typedef long long ll;

const int oo = 1e9;

const ll MOD =1e9+7;

void fast(){

    ios_base :: sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

int n, k;

int h[100005];

bool valid (int r,int c){

    return (r < n && r >= 0 && c >= 0 && c < n);

}

int row[] = {0 , 1 , 0, -1};

int column[] = {1 , 0, -1, 0};

int vis[100002];

int dp(int i){

    if(i == n-1)

        return 0;

    int &ret = vis[i];

    if(ret != -1)

        return ret;



    int path1 = abs(h[i]-h[i+1]) + dp(i+1);

    f(j, 2, k){

        if( i+j < n)

            path1 = min(path1, abs(h[i]-h[i+j]) + dp(i+j));

        else

            break;

    }

    return ret = path1;

}



int main()

{

    fast();

    memset(vis, -1);

    cin>>n>>k;

    ++k;

    f(i,0,n)

        cin>>h[i];

    cout<<dp(0)<<'\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.3991100939773804x):
#include <bits/stdc++.h>

#define IO ios::sync_with_stdio(0), cin.tie(0)

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 5;

const int inf = ~0u >> 1;

int d[maxn], h[maxn];

int main() {

    IO;

    int n, k;

    cin >> n >> k;

    for (int i = 1; i <= n; ++i) {

        cin >> h[i];

    }

    d[1] = 0;

    d[2] = abs(h[2] - h[1]);

    for (int i = 3; i <= n; ++i) {

        d[i] = abs(h[i - 1] - h[i]) + d[i - 1];

        //cout << "i = " << i << " j = " << 1 << " d[i] = "  << d[i] <<endl;

        for (int j = 2; j <= min(k, i - 1); ++j) {

            d[i] = min(d[i], abs(h[i - j] - h[i]) + d[i - j]);

            //cout << "i = " << i << " j = " << j << " d[i] = "  << d[i] <<endl;

        }

    }

    cout << d[n] << endl;

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define max(a,b) ((a)>(b)?(a):(b))

#define min(a,b) ((a)<(b)?(a):(b))

#define swap(x,y) (x^=y^=x^=y)

inline int read()

{

	int x=0,f=1;char ch=getchar();

	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}

	return x*f;

}

#define MN 100005 

int n,m,a[MN],b[MN],c[MN];

int t[MN<<1];

void C(int x){for(;x<MN*2;x+=(x&-x))t[x]++;}

int G(int x){int res=0;for(;x;x-=(x&-x))res+=t[x];return res;}

inline bool check(int x)

{

	ll cnt=0ll;

	register int i;

	for(i=1;i<=n;++i) c[i]=c[i-1]+(a[i]>=x?1:-1);

	memset(t,0,sizeof t);

	for(i=1;i<=n;++i)

	{

		C(c[i-1]+MN);

		cnt+=G(c[i]+MN);

	}

	return cnt*4>=1ll*n*(n+1);

}

int main()

{

	n=read();register int i;

	for(i=1;i<=n;++i) a[i]=b[i]=read();

	std::sort(b+1,b+n+1);

	m=std::unique(b+1,b+n+1)-b-1;

	int l,r,ans;

	for(l=1,r=m,ans=0;l<=r;)

	{

		int mid=l+r>>1;

		if(check(b[mid])) ans=mid,l=mid+1;

		else r=mid-1;

	}

	printf("%d\n",b[ans]);

}

// Faster C++ solution for the same problem (measured speedup: 9.832034972146474x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

#define INF 1000000000;

int a[100005],sum[100005],save[100005];

typedef long long ll;

ll to,to1;

int n;int maxl,minl;

void sortl(int left,int right)

{

    if(left==right)

        return ;

    int mid=(right+left)/2;

    sortl(left,mid);

    sortl(mid+1,right);

    int l=left,l2=mid+1,r=left;

    while(l<=mid&&l2<=right)

    {

        if(sum[l]<sum[l2])

            save[r++]=sum[l++];

        else

        {

            to1+=l-left;

            save[r++]=sum[l2++];

        }

    }

    while(l<=mid)

        save[r++]=sum[l++];

    while(l2<=right)

    {

        to1+=l-left;

        save[r++]=sum[l2++];

    }

    for(int i=left;i<=right;i++)

        sum[i]=save[i];

}

bool ck(int x)

{

    to1=0;

    for(int i=1;i<=n;++i)

        sum[i]=(a[i]<=x?1:-1);

    for(int i=1;i<=n;++i)

        sum[i]+=sum[i-1];

    sortl(0,n);

    return to1>=to/2+1;

}

int main()

{

    maxl=-INF;minl=INF

    scanf("%d",&n);

    to=0;

    for(int i=1;i<=n;++i)

    {

        scanf("%d",&a[i]);

        minl=min(minl,a[i]);

        maxl=max(maxl,a[i]);

        to+=i;

    }

    while(minl<maxl)

    {

        int mid=(minl+maxl)/2;

        if(ck(mid))

            maxl=mid;

        else

            minl=mid+1;

    }

    printf("%d\n",maxl);

}
// Slower C++ solution:
#include <bits/stdc++.h>





using namespace std;

long long n;

long long k;

vector<long long> vec;



long long meme[100007];



long long solve(long long index){



    if(index==n-1){

        return 0;

    }

    

    if(meme[index]!=-1){

        return meme[index];

    }

    

    long long ret = 10000000000000000;

    long long sol = 10000000000000000;

    for(long long i = 1 ;i<=k ; i++){

        if(index+i<n){

            ret = abs (vec[index]- vec[index+i]) + solve(index+i); 

        }

        sol = min(sol,ret);

    }



    return meme[index] = sol;

}



int main(){

    cin>>n;

    cin>>k;

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

    long long num;

    for(long long i = 0 ; i<n ; i++){

        cin>>num;

        vec.push_back(num);

    }

    cout<<solve(0)<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.7820146754130102x):
#include<iostream>

#include<iomanip>

#include<cstdio>

#include<cmath>

#include<vector>

#include<string>

#include<algorithm>

#include<queue>

#include<set>

#include<map>

#include<limits>

#include<stack>



using namespace std;



typedef unsigned long long ll;

typedef pair<int,int> ii;

typedef vector<pair<int,int> > vii;

typedef vector<vii> vvii;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<ll> vll;

typedef vector<vll> vvll;

typedef vector<bool> vb;

typedef vector<vb> vvb;

typedef vector<char> vc;

typedef vector<vc> vvc;

typedef vector<string> vs;



int INF = std::numeric_limits<int>::max();

int NINF = std::numeric_limits<int>::min();

int MOD = 1e9+7;



int col[] = {0,-1,0,1,1,1,-1,-1};

int row[] = {-1,0,1,0,1,-1,1,-1};



//knight moves

int cc[] = {1,2,2,1,-1,-1,-2,-2};

int rr[] = {-2,-1,1,2,-2,2,1,-1};



int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);



    int n,k;

    cin >> n >> k;



    vi hight(n);

    vll cost(n,INF);



    cin >> hight[0];

    cost[0] = 0;



    for(int i = 1 ; i < n ; ++i)

    {

        cin >> hight[i];



        if(i > k)

        {

            for(int j = i-1; j >= i-k ; --j)

            {

                ll one = abs(hight[i]-hight[j]);



                cost[i] = min(one+cost[j],cost[i]);

            }

            //cout << i << " " << cost[i] << endl;

        }

        else

        {

            cost[i] = abs(hight[0]-hight[i]);

        }

    }



    cout << cost[n-1];



    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#include<cmath>

using namespace std;

int main()

{

    int n;

    scanf("%d",&n);

    char s[1000000]={};

    scanf("%s",s);

    int k=strlen(s);

    if(k<=n)

       cout<<s<<endl;

    else if(k>n){

      for(int i=0;i<n;i++){

        printf("%c",s[i]);}

        cout<<"..."<<endl;

    }



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8321575307650277x):
#include<bits/stdc++.h>

#include<cmath>

using namespace std;

int main()

{

    int n;

    scanf("%d",&n);

    char s[100000]={};

    scanf("%s",s);

    int k=strlen(s);

    if(k<=n)

        cout<<s<<endl;

    else if(k>n){

      for(int i=0;i<n;i++){

        printf("%c",s[i]);}

        cout<<"..."<<endl;

    }}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long 

using namespace std;

ll n,k,a[100010],dp[100010];

int main ( )

{

	scanf("%lld%lld",&n,&k);

	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);

	memset(dp,0x7f,sizeof(dp));

	dp[1]=0;

	for(ll i=2;i<=n;i++)

		for(ll j=1;j<=k&&i-j>=1;j++)

		   dp[i]=std::min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));

	cout<<dp[n];

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.7749426926690242x):
//#pragma GCC target("avx2")

//#pragma GCC optimize("O3")

   

//#include <x86intrin.h>

#include <bits/stdc++.h>   

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace __gnu_pbds;

using namespace std;



template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

     

#define F first

#define S second           

#define lb lower_bound               

#define ub upper_bound

#define pb push_back

#define pf push_front    

#define ppb pop_back

#define mp make_pair                                     

#define bpp __builtin_popcountll                                                                                        

#define sqr(x) ((x) * (x)) 

#define al 0x3F3F3F3F

#define sz(x) (int)x.size()

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

#define in insert

#define ppf pop_front

#define endl '\n'

//#define int long long

 

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

typedef pair <int, int> pii;

 

const int mod = (int)1e9 + 7;

const int N = (int)3e5 + 123;

const ll inf = (ll)1e18 + 1;



const double pi = acos (-1.0);

const double eps = 1e-7;                  

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

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



int n, k;

ll h[N];

ll dp[N];



inline void boost () {                    

   ios_base :: sync_with_stdio (NULL);

   cin.tie (NULL), cout.tie (NULL);          

}                                                     



inline void Solve () {

   cin >> n >> k;

   dp[1] = 0;

   for (int i = 1; i <= n; i ++) cin >> h[i];

   for (int i = 2; i <= n; i ++) dp[i] = inf;

   for (int i = 1; i <= n; i ++) {

      for (int j = 1; j <= k; j ++) {

         if (i + j <= n) dp[i + j] = min (dp[i + j], dp[i] + abs (h[i] - h[i + j]));

      }

   }

   cout << dp[n];

}



main () {                                       

// freopen (".in", "r", stdin);    

// freopen (".out", "w", stdout);              

   boost ();

   int tt = 1;

   //cin >> tt;   

   while (tt --) {

      Solve ();

   }                                               

   return 0;      

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main()

{

    int k,x;

    cin>>k>>x;

    int m = x-k+1;

    if(k==1)

    {

        cout<<x<<endl;

    }

    else

    {



        for(int i=1;i<=2*k-1;i++)

        {

            cout<<m<<" ";

             m++;



        }



    }

    return 0;









}


// Faster C++ solution for the same problem (measured speedup: 5.215551750019623x):
////sfef

#include<stdio.h>

int main(){



int k,x,i,p,q,r;

scanf("%d %d",&k,&x);

p=(x-(k-1));

q=(x+(k-2));

r=(x+(k-1));

if(k==1)

{

    printf("%d",x);

}

else{

    for(i=p;i<=q;i++)    

    {

        printf("%d ",i);

    }

    printf("%d",r);

}



return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;



const int N = (1 << 16) + 5;

int arr[16][16];

int n;

ll val[N];

vector<int> m[N];



void get_masks(int idx, int mask, int pos)

{

  if(idx == n)

  {

    if(mask)

      m[pos].push_back(mask);

    return;

  }

  get_masks(idx + 1, mask, pos);

  if(mask & (1 << idx))

    get_masks(idx + 1, mask ^ (1 << idx), pos);

}



ll dp[N];



ll solve(int mask)

{

  if(mask == (1 << n) - 1)

    return 0;

  ll &ans = dp[mask];

  if(~ans)

    return ans;

  ans = 0;

  for(auto &x: m[mask])

  {

    ans = max(ans, solve(mask | x) + val[x]);

  }

  return ans;

}

int main()

{

  cin >> n;

  for(int i = 0; i < n; i++)

    for(int j = 0; j < n; j++)

      cin >> arr[i][j];

  for(int i = 0; i < (1 << n); i++)

  {

    for(int j = 0; j < n; j++)

    {

      for(int k = j + 1; k < n; k++)

      {

        if((i & (1 << j)) && (i & (1 << k)))

          val[i] += arr[j][k];

      }

    }

  }

  for(int i = 0; i < (1 << n); i++)

  {

    int newMask = i;

    for(int j = 0; j < n; j++)

      newMask ^= (1 << j);

    get_masks(0, newMask, i);

  }

  memset(dp, -1, sizeof dp);

  cout << solve(0);

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.198138798901389x):
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;



const int N = (1 << 16) + 5;

int arr[16][16];

int n;

ll val[N];

vector<int> m[N];

ll dp[N];



void get_masks(int idx, int mask, int pos)

{

  if(idx == n)

  {

    if(mask)

      m[pos].push_back(mask);

    return;

  }

  get_masks(idx + 1, mask, pos);

  if(mask & (1 << idx))

    get_masks(idx + 1, mask ^ (1 << idx), pos);

}



int main()

{

  cin >> n;

  for(int i = 0; i < n; i++)

    for(int j = 0; j < n; j++)

      cin >> arr[i][j];

  for(int i = 0; i < (1 << n); i++)

  {

    for(int j = 0; j < n; j++)

    {

      for(int k = j + 1; k < n; k++)

      {

        if((i & (1 << j)) && (i & (1 << k)))

          val[i] += arr[j][k];

      }

    }

  }

  for(int i = 0; i < (1 << n); i++)

  {

    int newMask = i;

    for(int j = 0; j < n; j++)

      newMask ^= (1 << j);

    get_masks(0, newMask, i);

  }

  for(int i = (1 << n) - 2; i >= 0; i--)

  {

    for(auto &x: m[i])

    {

      dp[i] = max(dp[i], dp[i | x] + val[x]);

    }

  }

  cout << dp[0];

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

long long a[55],n,i,x,ans;//

main(){

for(std::cin>>n;i<n;std::cin>>a[++i]);

for(;std::sort(a+1,a+n+1),a[n]>=n;a[n]%=n)for(ans+=x=a[n]/n,i=1;i<n;a[i++]+=x); 

std::cout<<ans<<'\n';

}

// Faster C++ solution for the same problem (measured speedup: 4.812964284846901x):
/*

    数据量很小,直接模拟

    对最大的数-n,其他数+1,直到最大数都小于n

    问操作次数.

    数据量大时,二分也应该可以.

*/

#include<cstdio>

using namespace std;

typedef long long LL;

LL a[55];

int main(){

    LL n, ans = 0;

    scanf("%lld", &n);

    for (int i = 0; i < n;i++){

        scanf("%lld", a + i);

    }

    while(true){

        LL ma = a[0], pos = 0;

        for (int i = 1; i < n;i++){

            if(a[i]>ma){

                ma = a[i];

                pos = i;

            }

        }

        if(ma<n){

            break;

        }

        LL tmp = ma / n;

        a[pos] %= n;

        for (int i = 0; i < n;i++){

            a[i] += tmp;

        }

        a[pos] -= tmp;

        ans += tmp;

    }

    printf("%lld", ans);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

#define pb push_back

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

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

#define reps(i, m, n) for (int i = m; i <= n; ++i)

typedef long long ll;

typedef vector<int> vi;

typedef vector<ll> vl;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 0x3f3f3f3f;

const ll LINF = 0x3f3f3f3f3f3f3f3fLL;



int dp[100010];

int h[100010];



signed main()

{

  ios::sync_with_stdio(false);

  cin.tie(0);

  memset(dp, 0x3f, sizeof(dp));

  dp[1] = 0;

  int n, k;

  cin >> n >> k;

  reps(i, 1, n) cin >> h[i];

  for (int i = 1; i <= n; ++i) {

    for (int j = 1; j <= k; ++j) {

      dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));

    }

  }

  cout << dp[n] << endl;

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3823205728459256x):
#include "bits/stdc++.h"



using namespace std;



#ifndef DEBUG

#define dump(...)

#endif



template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }



constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    size_t N, K;

    cin >> N >> K;



    vector<int64_t> h(N);

    for (auto &hi: h) {

        cin >> hi;

    }



    vector<int64_t> dp(N, LINF);

    dp[0] = 0;

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

        for (size_t j = 1; j <= K; ++j) {

            chmin(dp[i + j], abs(h[i + j] - h[i]) + dp[i]);

        }

    }



    cout << dp[N - 1] << "\n";



    return 0;

}