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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int P[1010];
vector<int> E[1010];
int X[1010];
int A[1010],B[1010];

int from[5050];
int to[5050];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>P[i+1];
		E[--P[i+1]].push_back(i+1);
	}
	FOR(i,N) cin>>X[i];
	
	for(i=N-1;i>=0;i--) {
		if(E[i].size()==0) {
			B[i]=0;
			A[i]=X[i];
		}
		else {
			FOR(x,5050) from[x]=1LL<<30;
			from[0]=0;
			FORR(e,E[i]) {
				FOR(x,5050) to[x]=1LL<<30;
				FOR(x,5002) if(from[x]<1LL<<30) {
					to[min(5001,x+A[e])]=min({to[min(5001,x+A[e])],from[x]+B[e],5001});
					to[min(5001,x+B[e])]=min({to[min(5001,x+B[e])],from[x]+A[e],5001});
				}
				swap(from,to);
			}
			B[i]=1LL<<30;
			A[i]=X[i];
			FOR(x,X[i]+1) B[i]=min(B[i],from[x]);
			
			//FOR(x,10) cout<<x<<" "<<from[x]<<endl;
			if(B[i]==1LL<<30) return _P("IMPOSSIBLE\n");
		}
		//cout<<"!"<<i<<" "<<A[i]<<" "<<B[i]<<endl;
	}
	
	cout<<"POSSIBLE"<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 384
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1], reverse=True)
cd.sort()
ans=0
for i in range(n):
    for a in ab:
        if a[0]<cd[i][0] and a[1]<cd[i][1]:
            ab.remove(a)
            ans+=1
            break
print(ans)



Measured memory_bytes: 39152
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

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);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}

//小文字=大文字+32

int main() {
	string s,t;
	cin >> s >> t;
	ll ans=1000;
	ll tmp;
	rep(i,s.size()-t.size()+1) {
		tmp = 0;
		rep(j, t.size()) {
			if (s[i+j] != t[j]) {
				tmp++;
			}
		}
			ans = min(ans, tmp);

	}
	cout << ans;
}
	



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

ll prime_factor(ll n) {
  map<ll, int > ret;
  ll MAX = 0;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      MAX=max(MAX,i);
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1){
    ret[n] = 1;
    MAX=max(MAX,n);
  }
  return MAX;
}

int main()
{
  int N;
  cin >> N;
  if(N%2==0){
    cout << N << " " << N << " " << N/2 << endl;
  }else if(N%3==0){
    cout << N/3 << " " << N*2 << " " <<  N*2 << endl;
  }else{
    int flag = 0;
    ll x=prime_factor(N);
    for(ll k = x;k<=3501;k+=x){
      FOR(i,N/4,3501){
        FOR(j,N/4,3501){
          if(4*k*i*j==N*(k*i+i*j+j*k)){
            cout << k << " " << i << " " << j << endl;
            flag=1;
            break;
          }
        }
        if(flag==1){
          break;
        }
      }
      if(flag==1){
        break;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=500005;
const long MOD=(long)(1e9+7);
vector<int> adj[MAXN];
vector<pair<int,int>> G[MAXN];

Int N,M,K;
Int B,C,H,W;
Int X,Y,Z;
vector<Int> A;

Int ceilS(Int x,Int y){
    return (x+y-1)/y;
}
using D=long double;

Int perform(Int x){
    return (x*(x+1))/2LL;
}

D getExpectation(D x) {
   return perform(x)/x;
}

int main()
{
    D T,X;
    cin>>X>>T;
    D ans=X/T;
    cout<<ans<<"\n";
}

Measured memory_bytes: 27220
import re
ptA = re.compile(r"^>'(=+)#\1~$")
ptB = re.compile(r"^>\^(?:Q=)+~~$")
for i in xrange(input()):
	s = raw_input()
	if ptA.match(s):
		print "A"
	elif ptB.match(s):
		print "B"
	else:
		print "NA"

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


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define mp                                        make_pair
#define pb                                        push_back
#define vii                                       vector<int> 
#define mii                                       map< int, int >
#define msi                                       map< string, int > 
#define mib                                       map< int, bool > 
#define pii                                       pair<int,int>
#define vpii                                      vector< pii >
#define all(v)                                    v.begin(),v.end()
#define loop(i,s,e)                               for(int i=s;i<e;i++)
#define rloop(i,e,s)                              for(int i=e;i>=s;i--)
#define mset(a,f)                                 memset(a,f,sizeof(a))
#define M                                         1000000007
#define prvec(v)                                  loop(i_u_j,0,v.size())cout << v[i_u_j] <<" "; cout << endl;
#define prarr(arr,n)                              loop(i_u_j,0,n)cout << arr[i_u_j] << " "; cout << endl;
#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define Think_Twice_Code_Once                     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)


template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //
const int N = 3e6 + 7;
int n, Q, m;
int arr[N], brr[N];

bool check(int mid)
{     
      int cnt = 0;
      loop(i,0,n)
      {
            int val = (arr[i] * brr[i]);
            // bug(val,mid,cnt);
            if( val > mid )
            {
                  int x = mid/brr[i];
                  cnt += (arr[i] - x);
            }
      }

      return cnt<= m;
}

bool comp(int a,int b)
{
      return a > b;
}

void solve()
{
      cin >> n >> m;
      loop(i,0,n) cin >> arr[i];
      loop(i,0,n) cin >> brr[i];
      sort( arr, arr + n );
      sort( brr, brr + n , comp);


      int s = 0, e = 1e14, ans = 0;

      while( s <= e )
      {
            int m = s +(e-s)/2;
            if( check(m) )
            {
                  ans = m;
                  e = m - 1;
            }
            else s = m + 1;
      }

      cout << ans ;
}

int32_t main()
{

Think_Twice_Code_Once;


  
  int t = 1; 
  //cin>>t;
  
  while(t--) solve();
  
  


}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //















Measured memory_bytes: 6016
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


int n;
char t;
vector<int> a;

int main(){
	cin>>n;
	rep(i,n){
		ll MIN=0,MAX=0;
		a.clear();
		rep(j,8){
			cin>>t;
			//cout<<t-'0'<<endl;
			int t1=t-'0';
			//cout<<t1<<endl;
			a.PB(t1);
			
		}
		
		sort(a.begin(),a.end());
		ll tmp=1;
		//rep(k,8) cout<<a[k]<<" ";
		//cout<<endl;
		rep(k,8){
			if(k==0) tmp=1;
			else tmp*=10;
			MIN+=a[7-k]*tmp;
			MAX+=a[k]*tmp;
			//cout<<MAX<<" "<<MIN<<endl;
		}
		cout<<MAX-MIN<<endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define repc(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef pair<int, pii> pip;
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;

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

int main(){
	int p[5][5][4];
	memset(p, 0, sizeof(p));
	string s;
	rep(i, 9){
		cin>>s;
		rep(j, s.size()){
			if(s[j] == '1'){
				if(i%2 == 0){
					p[i/2][j][0] = 1;
					p[i/2][j + 1][2] = 1;
				}else{
					p[i/2][j][3] = 1;
					p[i/2 + 1][j][1] = 1;
				}
			}
		}
	}

	int dir = 0;
	s ="RULD";
	int x = 0, y = 0;
	while(1){
		if(dir == 0){
			if(p[y][x][1]){
				dir = 1;
			}else if(p[y][x][0]){

			}else if(p[y][x][3]){
				dir = 3;
			}else if(p[y][x][2]){
				dir = 2;
			}
		}else if(dir == 1){
			if(p[y][x][2]){
				dir = 2;
			}else if(p[y][x][1]){

			}else if(p[y][x][0]){
				dir = 0;
			}else if(p[y][x][3]){
				dir = 3;
			}
		}else if(dir == 2){
			if(p[y][x][3]){
				dir = 3;
			}else if(p[y][x][2]){

			}else if(p[y][x][1]){
				dir = 1;
			}else if(p[y][x][0]){
				dir = 0;
			}
		}else{
			if(p[y][x][0]){
				dir = 0;
			}else if(p[y][x][3]){

			}else if(p[y][x][2]){
				dir = 2;
			}else if(p[y][x][1]){
				dir = 1;
			}
		}
		cout<<s[dir];
		x += dx[dir];
		y += dy[dir];
		//printf(" (%d, %d)\n", x, y);
		if(x == 0 && y == 0) break;
	}
	printf("\n");
}

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

using namespace std;
#define int long long
#define inf 999999999999999999
#define N 666666
int arr[N];
vector<int> v; 
map<int,int> vis;
signed main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>arr[i];
	int pos=1;
	v.push_back(1*1ll);
	vis[1]=1;
	int temp=0;
	int flag=0;
	while(1){
		int temp=arr[pos];	
		if(vis[temp]){
			flag=temp; 
			 break;
		}
		vis[temp]=1;
		v.push_back(temp);
		pos=temp;
	} 
	//cout<<flag;
	pos=0;
	for(int i=0;i<v.size();i++){
		if(v[i]==flag){
			pos=i;
			break;
		}
	}
	if(m<=pos+1){
		cout<<v[m];
	}else{
		//cout<<"==";
		cout<<v[pos+(m-pos)%(v.size()-pos)];
	}
	return 0;
}
/*
4 1
3 2 4 1

*/

Measured memory_bytes: 18520
#include <iostream>
#include <vector>
#include <list>
using namespace std;

int main() {
    string s;
    int x, y, j = 0, k = 0;
    cin >> s >> x >> y;
    list<int> nums[2];
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'T') {
            nums[j].emplace_back(k);
            k = 0;
            j = 1 - j;
        } else {
            k++;
        }
    }
    nums[j].emplace_back(k);
    x -= nums[0].front();
    nums[0].pop_front();
    auto knapsack = [&](list<int>& nums, int target)->bool {
        int size = abs(target) * 2 + 1;
        vector<bool> table(size);
        auto dp = [&](int i)->decltype(auto) {
            return table[abs(target) + i];
        };
        dp(0) = true;
        for (int i : nums) {
            vector<bool> next(size);
            for (int j = 0; j < size; j++) {
                if (j - i >= 0) {
                    next[j] = next[j] || table[j - i];
                }
                if (j + i < size) {
                    next[j] = next[j] || table[j + i];
                }
            }
            swap(next, table);
        }
        return dp(target);
    };
    if (knapsack(nums[0], x) && knapsack(nums[1], y)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 512
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]
def SR(n):
    return [S() for _ in range(n)]
def LSR(n):
    return [LS() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007
class SegmentTree:
    def __init__(self, size, f=max, default=0):
        self.size = 2**(size-1).bit_length()
        self.default = default
        self.dat = [default]*(self.size*2)
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def get(self, a, b=None):
        if b is None:
            b = a + 1
        l, r = a + self.size, b + self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res
def solve():
    n,k = LI()
    a = IR(n)
    m = max(a)
    s = SegmentTree(m+1)
    ans = 1

    for i in a:
        l = max(0,i-k)
        r = min(m+1,i+k+1)
        p = s.get(l,r)+1
        s.update(i,p)
        if ans < p:
            ans = p
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main() {
  int ans;
  rep(i,5) {
    int x;
    cin >> x;
    if (x == 0) ans = i+1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
//BISMILLAHIR RAHMANIR RAHIM
                                          //By the name of ALLAH
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<iterator>
#include<numeric>
#define pi acos(-1.0)
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int l=s.size();
    sort(s.begin(),s.end());
            int i,j,c;
       for(i=0;i<l;){
            c=1;
        for(j=i;j<l;j++){
            if(s[j]==s[j+1]){
                c++;
            }
            else
            break;
        }
        if(c%2!=0)
            break;
        else
            i=i+j+1;
       }
       if(c%2!=0)
       cout<<"No"<<endl;
       else
        cout<<"Yes"<<endl;

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


Measured memory_bytes: 3632
from itertools import permutations
from math import sqrt, pow, factorial

N = int(input())
l = [list(map(int, input().split())) for _ in range(N)]

def calc(a, b):
    [x1, y1] = a
    [x2, y2] = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 -y2, 2))
ans = 0
for order in permutations(range(N)):
    tmp = 0
    for i in range(1, N):
        tmp += calc(l[order[i]], l[order[i-1]])
    ans += tmp
print(ans/factorial(N))




Measured memory_bytes: 9260
#include<iostream>
using namespace std;
int main(int argc, char const *argv[]){
    int N,A,B;
    cin >> N >> A >> B;
    char target[6];
    int sum=0;
    int count=0;
    string target_str;
    for (int i=1;i<=N;i++){
        sum=0;
        target_str=to_string(i);
        for(int j=0; j< target_str.size(); j++){
            sum+=int(target_str[j])-48;
        }
        if((sum>=A) && (sum<=B))count+=i;
        // cout<<sum<<endl;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

int main() {
  map<char, int> m;
  string s;
  cin >> s;

  REP(i, s.size()) {
    m[s[i]] += 1;
  }

  if(m.size() == 2) {
    cout << "Yes" << '\n';
  }
  else {
    cout << "No" << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,k,n) for(int i=k;i<n,i++)
using namespace std;

int main(){
  int n,a,b,c,x,i,j;
  int ylist[150];
  cin>>n>>a>>b>>c>>x;
  while(n){
    for(i=0;i<n;i++)
      cin>>ylist[i];
    j=0;
    for(i=0;i<=10000;i++){
      if(x==ylist[j]) {j++;
	if(j>=n) break;
	 x=(a*x+b)%c;
	continue;
      }
      //      cout <<i<<"deb\n";
      x=(a*x+b)%c;
    }
    if(i>10000) cout<<-1<<endl;
    else cout<<i<<endl;
    cin>>n>>a>>b>>c>>x;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void) {
    int x,y,count,temp;
    while (scanf("%d%d",&x,&y)!=EOF&&(x!=0||y!=0)) {
        if (x<y) {
            temp=x;
            x=y;
            y=temp;
        }
        count=0;
        while (y!=0) {
            x%=y;
            temp=x;
            x=y;
            y=temp;
            count++;
        }
        printf("%d %d\n",x,count);
    }
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main()

{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string  s1,s2,s3;
	cin >> s1>> s2;
	s3=s1+s2[s2.size()-1];

	            if(s2==s3)
				{
			      cout << "Yes"<<endl;
				}
			else
				{
		      	  cout << "No"<<endl;
	}
}
		


Measured memory_bytes: 3628
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_060_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(32).
    01 A      PIC X(10).
    01 B      PIC X(10).
    01 C      PIC X(10).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO A B C.

    IF A(FUNCTION STORED-CHAR-LENGTH(A):1) = B(1:1)
        AND B(FUNCTION STORED-CHAR-LENGTH(B):1) = C(1:1) THEN
            DISPLAY "YES"
    ELSE
        DISPLAY "NO"
    END-IF.

    STOP RUN.


Measured memory_bytes: 384
//#include<cstdio>
//#include<cstdlib>
#include <iostream>
#include <vector>
#include <queue>
//#include<bitset>
//#include<string>
//#include<stack>
//#include<set>
//#include<unordered_set>
//#include<map>
//#include<unordered_map>
//#include<cstring>
//#include<complex>
//#include<cmath>
//#include<iomanip>
//#include<numeric>
#include <algorithm>
#include <stdio.h>
//#include<list>
//#include<functional>
//#include<cassert>
using namespace std;
#define ll long long int
#define llu unsigned long long int
void pv(vector<ll> arr, ll size)
{

    for (ll i = 0; i < size; i++)
    {
        cout << arr[i] << ' ';
    }
}
void gv(vector<ll> &arr)
{
    ll size = arr.size();
    for (ll i = 0; i < size; i++)
    {
        cin >> arr[i];
    }
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    vector<ll> arr(n), dp(n);
    gv(arr);
    dp[n - 1] = 0;
    dp[n - 2] = abs(arr[n - 1] - arr[n - 2]);
    for (ll i = n - 3; i >= 0; i--)
    {
        if (i + 2 < n)
            dp[i] = dp[i + 2] + abs(arr[i] - arr[i + 2]);
        dp[i] = min(dp[i], dp[i + 1] + abs(arr[i + 1] - arr[i]));
    }
    cout << dp[0];
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
ll dp[111][111][5555];
int main() {
    int n,a;
    cin>>n>>a;
    vector<int> x(n);
    rep(i,n){
        cin>>x[i];
    }
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
         for(int k=0;k<=5000;k++){
             dp[i+1][j][k]+=dp[i][j][k];
             if(k>=x[i]){
                 dp[i+1][j+1][k]+=dp[i][j][k-x[i]];
             }
         }
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=dp[n][i][i*a];
    }
    cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 211200
#include<bits/stdc++.h>
#pragma GCC optimize("trapv")
#define I inline void 
#define S struct 
#define vi vector<int> 

using namespace std ; 
using ll = long long ; 
using ld = long double ; 

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

// How interesting!

int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ;
	//freopen("in.in" , "r" , stdin) ; 

	ll sum = 0 ; 
	ll ans = 0 ; 
	cin >> n ; 
	for(int i = 0 ;i < n;i++){
		ll x ;
		cin >> x; 
		ans += x * sum ; 
		sum%= mod ; 
		ans%= mod ; 
		sum+= x ; 
	}
	cout<< ans ; 
	return 0 ; 
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int A = Integer.parseInt(scan.next());
	int B = Integer.parseInt(scan.next());

	String result;
	if(A == B) result = "Draw";
	else if(A > B) {
	    if(B == 1) result = "Bob";
	    else result = "Alice";
	} else {
	    if(A == 1) result = "Alice";
	    else result = "Bob";
	}
	
	System.out.println(result);
	scan.close();
    }
}


Measured memory_bytes: 23764
import java.util.*

fun main(args: Array<String>) {
	val scan = Scanner(System.`in`)
	val a = scan.nextInt()
	val b = scan.nextInt()
	val x = scan.nextInt()
	println(if (a + b >= x && !(a > x)) {
		"YES"
	} else {
		"NO"
	})
}

Measured memory_bytes: 31396
#include<iostream>
#define ROOP(N) for(int i=0; i<N; i++)
using namespace std;

bool Existence[8] = { false, false, false, false, false, false, false, false};

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

	int score;
	int highrater = 0;
	ROOP(N) {
		cin >> score;
		score /= 400;
		if (score < 8)
			Existence[score] = true;
		else
			highrater++;
	}

	int ans = 0;
	ROOP(8) {
		if (Existence[i]) ans++;
	}

  int ans2 = (ans == 0) ? 1 : ans;
  cout << ans2 << " " << ans + highrater;
	return 0;
}


Measured memory_bytes: 256
# ABC142E - Get Everything
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    p = 1 << N
    dp = [10 ** 10] * p
    dp[0] = 0
    for _ in range(M):
        a, _ = map(int, input().split())
        x = sum(1 << (i - 1) for i in map(int, input().split()))
        for y in range(p):
            if dp[x | y] > dp[y] + a:
                dp[x | y] = dp[y] + a
    ans = dp[-1] if dp[-1] != 10 ** 10 else -1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
N, Y = map(int, input().split())
for x in range(N + 1):
    for y in range(N - x + 1):
        z = (N - x - y)
        if 0 <= z <= 2000 and Y == 10000 * x + 5000 * y + 1000 * z:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String line;
        while ((line = br.readLine()) != null) {
        
            String ary[] = line.split(" ");
            int num1 = Integer.parseInt(ary[0]);
            String op = ary[1];
            int num2 = Integer.parseInt(ary[2]);
            
            if(op.equals("?")){
                break;
            }
            
            switch (op) {
                case "+":
                    System.out.println(num1 + num2);
                    break;
                case "-":
                    System.out.println(num1 - num2);
                    break;
                case "*":
                    System.out.println(num1 * num2);
                    break;
                case "/":
                    System.out.println(num1 / num2);
                    break;
            }
        }
    }
}

Measured memory_bytes: 24232
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def precompute(S):
    H, W = S.shape
    V = np.zeros((H + 1, W + 1), np.int64)
    V[1:, 1:] = np.cumsum(S, axis=0).cumsum(axis=1)
    Ex = np.zeros((H, W + 1), np.int64)
    Ex[1:, 1:] = np.cumsum(S[:-1] & S[1:], axis=0).cumsum(axis=1)
    Ey = np.zeros((H + 1, W), np.int64)
    Ey[1:, 1:] = np.cumsum(S[:, :-1] & S[:, 1:], axis=0).cumsum(axis=1)
    return V, Ex, Ey

def main(V, Ex, Ey, query):
    for i in range(len(query) // 4):
        a, b, c, d = query[4 * i:4 * i + 4]
        v = V[c, d] + V[a - 1, b - 1] - V[a - 1, d] - V[c, b - 1]
        e1 = Ex[c - 1, d] + Ex[a - 1, b - 1] - Ex[a - 1, d] - Ex[c - 1, b - 1]
        e2 = Ey[c, d - 1] + Ey[a - 1, b - 1] - Ey[a - 1, d - 1] - Ey[c, b - 1]
        print(v - e1 - e2)

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.from_dtype(np.int64)
    signature = (i8[:, :], i8[:, :], i8[:, :], i8[:])

    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()

from my_module import main

H, W, Q = map(int, readline().split())
S = []
for _ in range(H):
    S.append(list(readline().rstrip()))
query = np.array(read().split(), np.int64)

S = (np.concatenate(S) - ord('0')).reshape(H, W)
V, Ex, Ey = precompute(S)

main(V, Ex, Ey, query)

Measured memory_bytes: 244452
n, m = gets.chomp.split(' ').map{|i| i.to_i }
success = 0

k = []
s = []
bulbs_of_switches = {}
m.times{|i|
  ks = gets.chomp.split(' ')
  k[i] = ks.shift.to_i
  s[i] = ks.map{|s1|
    s2 = s1.to_i - 1
    bulbs_of_switches[s2] = [] if bulbs_of_switches[s2].nil?
    bulbs_of_switches[s2].push(i)
    #p bulbs_of_switches
    s2
  }
}

p = gets.chomp.split(' ').map{|i| i.to_i }

(2 ** n).times{|bit|
  s1 = "#{"0" * n}#{bit.to_s(2)}".slice(-n, 2 * n).split('').map{|i| i.to_i }

  ons_of_bulbs = []
  n.times{|i|
    #p i
    #p bulbs_of_switches
    next if bulbs_of_switches[i].nil?
    bulbs_of_switches[i].each{|bulb|
      ons_of_bulbs[bulb] = 0 if ons_of_bulbs[bulb].nil?
      ons_of_bulbs[bulb] += s1[i]
    }
  }
  failed = false
  #p ons_of_bulbs
  m.times{|i|
    tmp = ['ons', p[i], ons_of_bulbs[i]]
    #p tmp
    if ons_of_bulbs[i] % 2 != p[i] then
      failed = true
      break
    end
  }
  success += 1 if !failed
}
puts success


Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define ll  long long
#define ld long double
#define ms(a,v) memset(a,v,sizeof a)
#define pii pair<int, int>
/* * * *   * * *   	* * * */
/* *
 *
 * Author: Hamkor
 *
 * */

int main(){
	int n; scanf("%d", &n);
	int a[n], pre[n], su[n];
	for(int i=0; i<n; ++i) scanf("%d", a+i);
	pre[0] = -2000000; su[n-1] = -2000000;
	for(int i=1; i<n; ++i){
		pre[i] = max(a[i-1], pre[i-1]);
		su[n-i-1] = max(a[n-i], su[n-i]);
	}
	for (int i=0; i<n; ++i)printf("%d\n", max(pre[i], su[i]));
	return 0;
}


Measured memory_bytes: 3968
s = gets.chomp.chars
a = Array.new(s.size + 1, 0)

cnt = 0
s.chunk{|c| c }.each do |c, items|
  l = items.length
  if c == "<"
    a[cnt] = 0
    1.step(l) do |i|
      a[cnt + i] = a[cnt] + i
    end
  else
    a[cnt + l] = 0
    1.step(l) do |i|
      a[cnt + l - i] = [a[cnt + l] + i, a[cnt + l - i]].max
    end
  end
  cnt += l
end
puts a.inject(:+)

Measured memory_bytes: 50264
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = collections.Counter(prime_factorize(int(input())))
ans = 0
for k in c.keys():
    d = c[k]
    m =1
    while d>0:
        d -= m
        if d <= m:
            ans += m
            break
        m += 1
print(ans)

Measured memory_bytes: 9468
#include <stdio.h>

int main(){
  int a,b,c,i,count;
  scanf("%d %d %d",&a,&b,&c);
  count = 0;
  for(i=a;i<=b;i++){
    if(c%i==0) count++;
  }
  printf("%d\n",count);
  return 0;
}

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

typedef long long ll;
ll const mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int h,w;
    cin >> h >> w;
    string a[h];
    vector<vector<int>> dp(h,vector<int>(w,0));
    for (int i = 0;i < h;++i) cin >> a[i];
    dp[0][0] = 1;
    for (int i = 0;i < h;++i) for (int j = 0;j < w;++j) {
        if (i < h-1 && a[i+1][j] == '.') {
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= mod;
        }
        if (j < w-1 && a[i][j+1] == '.') {
            dp[i][j+1] += dp[i][j];
            dp[i][j+1] %= mod;
        }
    }
    cout << dp[h-1][w-1] << endl;
    return 0;
}

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

class Node{
    int id;
    Node parent=this;
    int rank;

    public Node(){}
    public Node(int id){
        this.id=id;
    }

    public Node findRoot(){
        Node root =this;
        while(true){
            if(root==root.parent){
                break;
            }
            root=root.parent;
        }
        return root;
    }
}

// class Tree{
//     int rank;
//     Node root;

//     public Tree(int rank,Node root){
//         this.rank=rank;
//         this.root=root;
//     }
// }

public class Main{
    static int INFTY = Integer.MAX_VALUE;
        
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int q=sc.nextInt();
    //    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    //    try{
    //        int n = Integer.parseInt(br.readLine());
        // } catch (IOException e) {
        //     e.printStackTrace();
        // }
        Node[] nodes = new Node[n];
       // Tree[] tree = new Tree[n];

        for(int i=0;i<n;i++){
            nodes[i]=new Node(i);
         //   tree[i]=new Tree(1,nodes[i]);
        }


        for(int i=0;i<q;i++){
            int command =sc.nextInt();
            int u1=sc.nextInt();
            int u2=sc.nextInt();

            if(command==0){
                unite(nodes[u1],nodes[u2]);
            }
            if(command==1){
                find(nodes[u1],nodes[u2]);
            }
        }
        
    }

    public static void unite(Node u1,Node u2){
        Node root1=u1.findRoot();
        Node root2=u2.findRoot();
        if(root1==root2){
            return;
        }
        if(root1.rank>root2.rank){
            root2.parent=root1;
        }else if(root1.rank<root2.rank){
            root1.parent=root2;
        }else{
            root2.parent=root1;
            root1.rank++;
        }
    }

    public static void find(Node u1,Node u2){
        Node root1=u1.findRoot();
        Node root2=u2.findRoot();
        if(root1==root2){
            System.out.println(1);;
        }else{
            System.out.println(0);
        }
    }
    
}


    


Measured memory_bytes: 102812
n=int(input())
a=list(map(int,input().split()))
a.sort()
ind=0
for iii in range(len(a)):
  if a[iii]>0:
    ind=iii
    break
num=0
lans=[]
mi=min(a)
ma=max(a)
ima=a.index(ma)
imi=a.index(mi)
if n==2:
  print(ma-mi)
  print(str(ma),str(mi))
else:
  if ma<=0:
    num=a[-1]
    for iii in range(len(a)-1):
      lans.append(str(num)+" "+str(a[iii]))
      num-=a[iii]
  else:
    if mi>=0:
      num=mi
      for iii in range(len(a)-2):
        lans.append(str(num)+" "+str(a[-iii-1]))
        num-=a[-iii-1]
      lans.append(str(a[1])+" "+str(num))
      num=a[1]-num
    else:
      num=mi
      for iii in range(len(a)-ind-1):
        lans.append(str(num)+" "+str(a[-iii-1]))
        num-=a[-iii-1]
      for iii in range(ind):
        if iii==0:
          lans.append(str(a[ind])+" "+str(num))
          num=a[ind]-num
        else:
          lans.append(str(num)+" "+str(a[iii]))
          num-=a[iii]
  print(num)
  for iii in range(len(lans)):
    print(lans[iii])

Measured memory_bytes: 16596
N= int(input())
W = list(input() for i in range(N))
ans = True
if len(set(W)) == len(W):
    l = W[0][-1]
    ans = True
    for i in range(len(W)-1):
        if W[i+1][0] == l:
            l = W[i+1][-1]
        else:
            ans = False
            break
    if ans == True:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
# include <iostream>
using namespace std;
int main(){
  int R,G,B,N; cin >> R >> G >> B >> N;
  long ans = 0;
  for(int r = 0; r <= N; r++) {
    if (r*R > N) break;
    else{
      for (int g = 0; g <= N; g++) {
        if (r*R + g*G > N) break;
        else if ((N - r*R - g*G) % B == 0) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, i, j, k, x, best;
	cin >> n;
	vector<int> ct(100010, 0);
	for (i = 0; i < n; i++) {
		cin >> x;
		ct[x]++;
	}
	best = 0;
	for (i = 1; i < 100000; i++) best = max(best, ct[i - 1] + ct[i] + ct[i + 1]);
	cout << best << "\n";

	return 0;
}



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

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

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long fa = 0;
        long fb = 0;
        for(int i=0;i<50;i++){
        	long x = (long)Math.pow(2,i);
        	long count = (a-1) / (2*x);
        	count = count * x;
        	count += (long)Math.max(0, (a-1) - (a-1)/(2*x)*(2*x) - (x-1));
        	if(count%2==1){
        		fa += x;
        	}
        }

        for(int i=0;i<50;i++){
        	long x = (long)Math.pow(2,i);
        	long count = b / (2*x);
        	count = count * x;
        	count += (long)Math.max(0, b - b/(2*x)*(2*x) - (x-1));
        	if(count%2==1){
        		fb += x;
        	}
        }

        System.out.println(fa^fb);
    }
}

Measured memory_bytes: 22612
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		int N=nextInt();
		int K=nextInt();
		int p[]=new int[N];
		int ans=0;
		for(int i=0;i<N;i++){
			p[i]=nextInt();
		}
		Arrays.sort(p);
		for(int i=0;i<K;i++){
			ans+=p[i];
		}
		System.out.println(ans);
		out.flush();
	}
	static boolean isOK(int index,int key,ArrayList<Integer>a){
		if (a.get(index) >= key) return true;
	    else return false;
	}
	static int binary_search(int key,ArrayList<Integer> a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;

	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}


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

#ifdef LOCAL
#include "debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;

const int MAXN = 2e5 + 10;

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // if(argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;

  	int a, b;
	cin >> a >> b;
  	cout << 6 - a - b << endl;

    return 0;
}







































Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b;
    cin >> a >> b;
    if(a + b >= 10)
        cout << "error" << endl;
    else
        cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1000000007;
void files(){
 freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);

}
void fast(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

}

int main(){
 fast();
 string s;
 cin>>s;
 if(s[s.size()-1]=='s'){
    cout<<s<<"es";
 }
 else{cout<<s<<"s";}

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int n,k,lb;
long long int a[222222],b[222222];
int bit[222222];
int lowbit(int x){return x&-x;}
int query(int x){
	int r=0 ;
	while(x){
		r+=bit[x];
		x -= lowbit(x);
	}
	return r;
}
void upd(int x){
	while(x<=lb){
		bit[x]++;
		x+=lowbit(x);
	}
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1; i<=n; i++){
		int x;
		scanf("%d",&x);
		a[i] = a[i-1] + x;
	}
	for(int i=0; i<=n; i++){
		a[i] -= (long long int)i*k;
		b[lb++] = a[i];
	}
	sort(b,b+lb);
	lb=unique(b,b+lb)-b;
	long long int res = 0;
	for(int i=0; i<=n; i++){
		int w = lower_bound(b,b+lb,a[i])-b+1;
		res += query(w);
		upd(w);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 4352
n = int(input())
A = list(map(int, input().split()))
x = A[-1]

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            temp = A[i]
            A[i] = A[j]
            A[j] = temp

    temp = A[i + 1]
    A[i + 1] = A[r]
    A[r] = temp

    return i + 1

idx = partition(A, 0, len(A) - 1)

B = []
for i in range(n):
    if i == idx:
        B.append('[' + str(x) + ']')
    else:
        B.append(str(A[i]))

print(' '.join(B))



Measured memory_bytes: 16592
import string
N = int(input())
S = list(input())

l = list(string.ascii_uppercase)

for i,s in enumerate(S):
  index = l.index(s)
  if index + N >= len(l):
    index = index + N - len(l)
    new_s = l[index]
  else:
    new_s = l[index+N]
  S[i] = new_s

S = ''.join(S)
print(S)
  

Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(){
  int N,M;
  int ans;
  cin >> N >> M;
if(N==0){
  ans = M*(M-1)/2;
}else if(M==0){
  ans = N*(N-1)/2;
}else{
  ans = M*(M-1)/2 + N*(N-1)/2;
}
  
  cout << ans;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int selectionSort(int [], int);

int main(){
  int n, cnt;
  int *A;
  int i;

  scanf("%d",&n);

  A = (int *)malloc(n*sizeof(int));

  for(i=0; i<n; i++)
    scanf("%d",&A[i]);
  
  cnt = selectionSort(A,n);

  for(i=0; i<n; i++){
    printf("%d",A[i]);
    if(i<n-1)
      printf(" ");
  }
  printf("\n%d\n",cnt);
  
  free(A);
  return 0;
}

int selectionSort(int A[],int n){
  int minj, tmp, cnt=0;
  int i, j;

  for(i=0; i<n; i++){
    minj = i;
    
    for(j=i; j<n; j++){
      if(A[j] < A[minj])
	minj = j;
    }

    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;

    if(i!=minj)
      cnt++;
  }
  
  return cnt;
}



Measured memory_bytes: 2124
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int A[100010],B[100010],u[200010],U;
std::vector<int>a,b;
int fa[200010];
int hd(int x){return fa[x]==x?x:fa[x]=hd(fa[x]);}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),XOR=0,xorb=0;
	for(int i=1;i<=n;++i)A[i]=gi(),XOR^=A[i],a.push_back(A[i]),u[++U]=A[i];
	for(int i=1;i<=n;++i)B[i]=gi(),xorb^=B[i],b.push_back(B[i]),u[++U]=B[i];
	u[++U]=XOR;std::sort(u+1,u+U+1);U=std::unique(u+1,u+U+1)-u-1;
	for(int i=1;i<=n;++i)A[i]=std::lower_bound(u+1,u+U+1,A[i])-u;
	for(int i=1;i<=n;++i)B[i]=std::lower_bound(u+1,u+U+1,B[i])-u;
	a.push_back(XOR),b.push_back(xorb);
	std::sort(a.begin(),a.end());
	std::sort(b.begin(),b.end());
	if(a!=b)return puts("-1"),0;
	int ans=-1;
	for(int i=1;i<=U;++i)fa[i]=i;
	for(int i=1;i<=n;++i)if(A[i]!=B[i])++ans,fa[hd(A[i])]=hd(B[i]);
	if(ans==-1)return puts("0"),0;
	for(int i=1;i<=n;++i)
		if(A[i]!=B[i]){
			if(hd(A[i]))fa[hd(A[i])]=0,++ans;
			if(hd(B[i]))fa[hd(B[i])]=0,++ans;
		}
	XOR=std::lower_bound(u+1,u+U+1,XOR)-u;
	if(fa[XOR])++ans;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4728
def move(y, x):
    p[2], p[3] = y, x
    if a[p[0] + y][p[1] + x] == ".":p[0] += y;p[1] += x

def shoot():
    th = p[0] + p[2]
    tw = p[1] + p[3]
    while 1:
        if a[th][tw] == "*":a[th][tw] = ".";break
        elif a[th][tw] == "#":break
        else: th += p[2]; tw += p[3]

for u in range(int(input())):
    if u > 0:print()
    h, w = map(int, input().split())
    a = [["#"] * (w + 2)] + [["#"] + list(input()) + ["#"] for _ in range(h)] + [["#"] * (w + 2)]
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if a[i][j] == ">":p = [i, j, 0, 1];a[i][j] = ".";break
            elif a[i][j] == "^":p = [i, j, -1, 0];a[i][j] = ".";break
            elif a[i][j] == "<":p = [i, j, 0, -1];a[i][j] = ".";break
            elif a[i][j] == "v":p = [i, j, 1, 0];a[i][j] = ".";break
    n, c = int(input()), input()
    for i in range(n):
        if c[i] == "U":move(-1, 0)
        elif c[i] == "R":move(0, 1)
        elif c[i] == "L":move(0, -1)
        elif c[i] == "D":move(1, 0)
        else:shoot()
    if (p[2], p[3]) == (0, 1):a[p[0]][p[1]] = ">"
    elif (p[2], p[3]) == (-1, 0):a[p[0]][p[1]] = "^"
    elif (p[2], p[3]) == (0, -1):a[p[0]][p[1]] = "<"
    else:a[p[0]][p[1]] = "v"
    for i in a[1:-1]:print("".join(i[1:-1]))


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define rep(i,n) for(int i=0;i<(n);i++)
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; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L

int main() {
	ll a,b,c,d;
  	ll p=0;
  
  	cin>>a>>b>>c>>d;
  

  	if(b<0&&d>=0){
    	cout<<max(a*c,b*c)<<endl;
    }
  
  	else if(b>=0&&d<0){
    	cout<<max(a*c,a*d)<<endl;
    }
  
    else if(b<0&&d>=0){
    	cout<<max(p,b*c)<<endl;
    }
  
  	else if(b>=0&&d<0){
    	cout<<max(p,a*d)<<endl;
    }
  	else{
    	cout<<max(a*c,b*d)<<endl;
    }
  
  	
  

}

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


int x,n;
int main(){
	cin>>x>>n;
	int p[n];
	rep(i,n){cin>>p[i];}

	bool diff=false;
	rep(i,n){
		if(x==p[i])diff=true;
	}
	if(!diff){
		cout<<x<<endl;
		return 0;
	}
	rep(j,100){
		rep(i,n){
			if((x-j)==p[i])diff=true;
		}
		if(!diff){
			cout<<x-j<<endl;
			return 0;
		}
      diff=false;
		rep(i,n){
			if((x+j)==p[i])diff=true;
        
		}
		if(!diff){
			cout<<x+j<<endl;
			return 0;
		}
      diff=false;
	}
}





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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x)  (x).begin(),(x).end()

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c){
        cout << "No" << endl;
        return 0;
    }

    if(a != b && a != c && b != c){
        cout << "No" << endl;
        return 0;
    }
 
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256