akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
using namespace std;
struct node
{
	int v,nxt;
};
node edge[6001];
bool dp[3001];
int n,a[3001],len,head[3001];
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9')
		c=getchar();
	while ('0'<=c&&c<='9')
	{
		sum=sum*10+c-'0';
		c=getchar();
	}
	return sum;
}
void add(int x,int y)
{
	edge[++len].v=y;
	edge[len].nxt=head[x];
	head[x]=len;
	return;
}
bool used[3001];
void dfs(int x)
{
	used[x]=1;
	for (int i=head[x];i>0;i=edge[i].nxt)
		if (!used[edge[i].v])
		{
			dfs(edge[i].v);
			if (!dp[edge[i].v]&&a[edge[i].v]<a[x])
				dp[x]=1;
		}
	return;
}
int main()
{
	int x,y;
	n=read();
	for (int i=1;i<=n;++i)
		a[i]=read();
	for (int i=1;i<=n-1;++i)
	{
		x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	for (int i=1;i<=n;++i)
	{
		for (int j=1;j<=n;++j)
			used[j]=dp[j]=0;
		dfs(i);
		if (dp[i])
			printf("%d ",i);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

bool safe(int N, int C, int k) {
  // A + Ck = N - 1
  int A = N - 1 - C * k;
  if (A <= 0) return false;
  // C = A - B
  int B = A - C;
  if (B <= 0 || B >= A) return false;
  if (A % C != 0) return true;
  return (A / C) > k;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<ll> S(N);
    for (ll& x : S) cin >> x;
    ll res = 0;
    for (int C = 1; C < N; C++) {
      ll sum = 0;
      for (int k = 1; k * C < N; k++) {
        sum += S[k * C] + S[N - 1 - k * C];
        if (safe(N, C, k)) {
          chmax(res, sum);
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
int32_t main()
{


	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int arr[n], count = 0;;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	for (int i = 1; i < n - 1; i++)
	{
		if ((arr[i] > arr[i - 1] && arr[i] < arr[i + 1]) || (arr[i] < arr[i - 1] && arr[i] > arr[i + 1]))
			count++;
	}
	cout << count;
}

Measured memory_bytes: 256
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
inline int read()
{
	int num=0, w=0;
	char ch=0;
	while (!isdigit(ch))
	{
		w|=ch=='-';
		ch = getchar();
	}
	while (isdigit(ch))
	{
		num = (num<<3) + (num<<1) + (ch^48);
		ch = getchar();
	}
	return w? -num: num;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;

const int maxn=2e5+10;
ll a[maxn],pre[maxn],q;
map <ll,int> p;
int ans1=0;
int ans2=0;
int ans3=0;

int main()
{

	ll n,x,m;ans1=ans2=ans3=0;
	cin>>n>>q>>m;ans1=ans2=ans3=0;
	a[1]=q;ans1=ans2=ans3=0;
	pre[1]=a[1];
	p[a[1]]=1;ans1=ans2=ans3=0;
	for(int i=2; i<=n; i++)
	{ans1=ans2=ans3=0;
		a[i]=(a[i-1]*a[i-1])%m;
		if(p[a[i]])
		{ans1=ans2=ans3=0;
			int x=p[a[i]];
ans1=ans2=ans3=0;
ans1=ans2=ans3=0;
			ll tmp=(n-i+1)/(i-x);
			ll ans=pre[i-1];ans1=ans2=ans3=0;
			ll p2=pre[i-1]-pre[x-1];ans1=ans2=ans3=0;
			ans+=p2*tmp;
ans1=ans2=ans3=0;
			tmp=(n-i+1)%(i-x);ans1=ans2=ans3=0;
			ans+=pre[x+tmp-1]-pre[x-1];ans1=ans2=ans3=0;
ans1=ans2=ans3=0;
			cout<<ans<<endl;ans1=ans2=ans3=0;
			return 0;
		}
		p[a[i]]=i;ans1=ans2=ans3=0;
		pre[i]=pre[i-1]+a[i];ans1=ans2=ans3=0;
	}
	cout<<pre[n]+ans1+ans2+ans3<<endl;
	return 0;
}


Measured memory_bytes: 7484
/*
 * Contents   : AOJ DPL 1 C
 * Author     : KitauraHiromi
 * LastUpdate : 20180613
 * Since      : 20180613
 */
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int N, W;
int dp[101][10001]; // dp[i][w]: i種類までの荷物をw kgまで選択できるときの最大価値を保持
int value[101], weight[101];
int main(void){
    cin >> N >> W;
    memset(dp, 0, sizeof(dp));
    for(int i=0; i<N; ++i) cin >> value[i] >> weight[i];
    for(int i=0; i<N; ++i){
        for(int w=0; w<=W; ++w){
            (w >= weight[i]) ? dp[i+1][w] = max(dp[i+1][w-weight[i]] + value[i], dp[i][w]) : dp[i+1][w] = dp[i][w];
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 7056
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.IO;

public class Playground
{
    private static int[] item1;
    private static int[] item2;

    public static void Main(string[] args)
    {
        Input();
        Method();
        System.Console.ReadLine();
    }

    private static void Input()
    {
        Console.ReadLine();
        item1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        Console.ReadLine();
        item2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    }

    private static void Method()
    {
        //int sum = item1.Aggregate(0, (cnt, elem) =>
        //    cnt + item2.Count(y => y == elem)
        //);
        int sum = 0;
        foreach (var s in item2)
        {
            foreach (var t in item1)
            {
                if (s == t)
                {
                    sum++;
break;
                }
            }
        }

        System.Console.WriteLine(sum);
    }
}

Measured memory_bytes: 9740
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define REP(i,a) for(int i=0;i<(a);i++)
#define REPR(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int main () {
  int a,b,t;
  cin >> a >> b >> t;
  int n = t/a;


  pi(n*b); br();
}


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

using namespace std;

void find(int begin, int end, string begin_val);

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

  // 0 の位置の人を確認
  string res;
  cout << 0 << endl;;
  cin >> res;
  if(res == "Vacant") exit(0);

  find(0, n, res);
}

void find(int begin, int end, string begin_val)
{
  // 中央の位置決め
  int center = ((end-begin) / 2) + begin;

  // center を受け取り、空席でないか確認
  string center_val;
  cout << center << endl;
  cin >> center_val;
  if(center_val == "Vacant") exit(0);

  if((center - begin)%2 == 1) { // begin と center が 同性ならその間にいる
    // begin と center が同性か確認して再帰
    if(begin_val == center_val) { // begin center 間に空席が存在
      find(begin, center, begin_val);
    }
    else { // center end 間に 空席が存在
      find(center, end, center_val);
    }
  }
  else { // begin と center が 異性ならその間にいる
    // begin と center が同性か確認して再帰
    if(begin_val != center_val) { // begin center 間に空席が存在
      find(begin, center, begin_val);
    }
    else { // center end 間に 空席が存在
      find(center, end, center_val);
    }
  }
}


Measured memory_bytes: 1228
#include<stdio.h>

int main(void)
{
  int a,b,c,d,frag=0,r1,r2,r3;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(a-b < 0)
    {
      r1 = b-a;
    }
  else
    {
      r1 = a-b;
    }
  if(a-c < 0)
    {
      r3 = c-a;
    }
  else
    {
      r3 = a-c;
    }
  if(r1 <= d)
    {
      frag++;
    }
  if(b-c < 0)
    {
      r2 = c-b;
    }
  else
    {
      r2 = b-c;
    }
  if(r2 <=d)
    {
      frag++;
    }
  if(frag == 2)
    {
      printf("Yes\n");
    }
  else if(r3 <= d)
    {
      printf("Yes\n");
    }
  else
    {
      printf("No\n");
    }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define wrln cout<<'\n';
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) ;
    long long n,res=0,a,dmax=0;
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a;
        dmax=max(dmax,a);
        res+=dmax-a;
    }
    cout<<res;
}





Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n, a, b, kk, ss, aa, bb, mx;
	cin>>n;
	for(int i = 0; i < n; ++i){
		cin>>a>>b;
		if(i == 0){
			aa = a;
			bb = b;
		}
		else{
			if(aa % a == 0)kk = aa / a;
			else kk = aa / a + 1;
			if(bb % b == 0)ss = bb / b;
			else ss = bb / b + 1;
			mx = max(ss, kk);
			aa = a * mx;
			bb = b * mx;
		}
	}
	cout<<aa + bb<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int dp[101][10001];
int main(void){
    // Your code here!
    int n,W;
    int v[101],w[101];
    cin >> n >> W;
    for(int i=0;i<n;i++) cin >> v[i] >> w[i];
    
    for(int i=0;i<n;i++){
        for(int j=0;j<=W;j++){
            if(j < w[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j] , dp[i+1][j-w[i]] + v[i]);
        }
    }
    cout << dp[n][W] << endl;
    return 0;
    
}

Measured memory_bytes: 7012
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define mod 1000000007
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inp_vecN for(int i=0;i<n;i++)cin>>v[i]; 
vector<int> get_Factors(ll n)
{
      vector <int> v;
      for(ll i=2; i<=sqrt(n)+1; i++)
      {
            if(n%i==0)
            {
                  v.push_back(i);
                  v.push_back(n/i);
            }
      }

      v.push_back(1);

      return v;
}
string get_bin(ll n)
{
    string s = "";
    while(n > 0)
    {
        s += ('0' + n%2);
        n /= 2;
    }
    reverse(s.begin(), s.end());
    return s;
}

ll bin_to_dec(string s)
{
    ll ans = 0;
    for(auto ch: s)
    {
        ans *= 2;
        ans += (ch - '0');
    }
    return ans;
}
void PrintVector(vector<int> v,int n)
{

    for(int i=0;i<n;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
int no_of_primeFactors(int n)  
{ 
    int count=0;
    while (n % 2 == 0)  
    {  
        count++;
        n = n/2;  
    }  
   
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    { 
        while (n % i == 0)  
        {  
           count++;
            n = n/i;  
        }  
        
    }  
    if (n > 2)  
        count++;
    return count;
} 
 ll gcd(int a, int b)
{ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
} 
   
  ll lcm(int a, int b)  
{  
    return (a/gcd(a, b)*b);  
}  



ll pwr(ll base,ll expo,ll m)
{
    if(base==0) return 0LL;
    if(expo==0) return (1LL%m);
    if((expo&1)==0) {ll temp=pwr(base,expo>>1,m); return (temp*temp)%m;}
    return ((base%m)*pwr(base,expo-1,m))%m;
}

int main(int argc, char const *argv[])
{
    ios;
    
    int n,k,di;
    cin>>n>>k;
    std::vector<bool> v(n+1,false);
    v[0]=true;
    for(int i=0;i<k;i++)
    {
      cin>>di;
      for(int j=0;j<di;j++)
      {
            int b;
            cin>>b;
            v[b]=true;

      }
    }
     int ans=0;
     for(int i=0;i<v.size();i++)
     {
            if(v[i]==false)
                  ans++;
     }

     cout<<ans;


    return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
int ans=1;
for(int i=0;i<n;i++){
	if(ans>k){
		ans+=k;
	}else{
		ans+=ans;
	}
} 
cout<<ans;
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define bzero(p, n) memset(p, 0, n)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

template <typename T> T gcd(T a, T b) {
	if (b == 0) return abs(a);
	T r; while ((r = a % b) != 0) a = b, b = r;
	return abs(b);
}

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

    int N; cin >>N;
    vector<int> A(N); cin >> A;

    int g = A[0];
    rep1(i, N) {
        g = gcd(g, A[i]);
        if (g == 1)
            break;        
    }    
    cout << g << endl;
}


Measured memory_bytes: 640
abc = list(map(int, input().split()))
abc.sort()
ans = 0
cnt = 0
rest = 0
for i in range(3):
    if abc[i] % 2 == 0:
        cnt += 1
if cnt == 0 or cnt == 3:
    print((abc[2] - abc[1]) // 2 + (abc[2] - abc[0]) // 2)
    exit()
elif cnt == 1:
    rest = 1
for i in range(3):
    if abc[i] % 2 == rest:
        abc[i] += 1
abc.sort()
print((abc[2] - abc[1]) // 2 + (abc[2] - abc[0]) // 2 + 1)

Measured memory_bytes: 3064
from math import floor,ceil
N = int(input())
a_list = list(map(int,input().split()))

for i in range(N):
    a_list[i] -= i+1

a_list.sort()

b = a_list[N//2]

diff = 0
for a in a_list:
    diff += abs(b-a)
print(diff)

Measured memory_bytes: 86612
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second   
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 

#define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef vector<int> vi;
typedef pair<int, int> pii; 
typedef pair<int , pii> piii ; 
typedef unsigned long long ull ;

string s;
void f(int len, int maxx, int n){
    if(len == n){
        cout << s << '\n' ;
        return; 
    }

    rep(i , maxx + 1){
        s.pb('a' + i);
        f(len + 1 , max(maxx , i + 1) , n);
        s.popb();
    }
}
void solve()
{
    int n ;
    cin >> n; 
    f(0 , 0, n);
}   

     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    rep(x, 10) {
        rep(y, 10) {
            if (x * y == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  int flag=0;
  rep(i,s.size()-1){
    if(s.at(i)==s.at(i+1)) flag=1;
  }
  if(flag==0) cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private Scanner sc;

	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		int lim = Integer.parseInt(sc.next());
		
		int max = 0;
		int[] a = new int[lim];
		int[] b = new int[lim];
		
		for (int i = 0; i < lim; i++) {
			a[i] = Integer.parseInt(sc.next());
			if (max < a[i]) max = a[i];
		}
		
		int[] c = new int[max + 1];
		for (int i = 0; i < (max + 1); i++) {
			c[i] = 0;
		}
		
		for (int i = 0; i < lim; i++) {
			c[a[i]] = c[a[i]] + 1;
		}
		
		for (int i = 1; i < (max + 1); i++) {
			c[i] = c[i] + c[i - 1];
		}
		
		for (int i = (lim - 1); i >= 0; i--) {
			b[(c[a[i]] - 1)] = a[i];
			c[a[i]] = c[a[i]] - 1;
		}

		StringBuilder sb = new StringBuilder();
		sb.append(b[0]);
		for (int i = 1; i < lim; i++) {
			sb.append(" " + b[i]);
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 309404
#include <stdio.h>
signed main(){
    int p,n,k,x[1005],ans=0,i,temp;
    scanf("%d %d",&n,&k);
    for(p=0;p<n;p++){
        scanf("%d",&x[p]);
    }
    for(p=0;p<n-1;p++){
        for(i=0;i<n-p-1;i++){
            if(x[i]>x[i+1]){
                temp=x[i];
                x[i]=x[i+1];
                x[i+1]=temp;
            }
        }
    }
    for(p=0;p<k;p++){
        ans+=x[p];
    }
    printf("%d\n",ans);
    return(0);
}

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

int main(){
  int n,m;
  cin>>n>>m;
  if(n>m){
    cout<<0;
    return 0;
  }
  vector<int> a(m),dist(m-1);
  for(int i=0; i<m; i++) cin>>a[i];
  sort(a.begin(),a.end());
  for(int i=0; i<m-1; i++) dist[i] = a[i+1] - a[i];
  sort(dist.begin(),dist.end());
  int ans = a[m-1] - a[0];
  for(int i=m-2; i>m-n-1; i--) ans -= dist[i];
  cout<<ans;
}

Measured memory_bytes: 1024
using System.Collections.Generic;
using static System.Math;
using System;

public class P
{
    public int x { get; set; }
    public int y { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var h = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            if (h == 0 && w == 0) break;
            var d = new Dictionary<char, P>();
            for (int i = 0; i < h; i++)
            {
                var s = Console.ReadLine().Trim();
                for (int j = 0; j < w; j++)
                    if (s[j] != '_') d[s[j]] = new P { x = i, y = j };
            }
            var st = Console.ReadLine().Trim();
            getAns(d, st);
        }
    }
    static void getAns(Dictionary<char, P> d, string s)
    {
        var ans = s.Length;
        var tx = 0; var ty = 0;
        for (int i = 0; i < s.Length; i++)
        {
            var pa = d[s[i]];
            ans += Abs(pa.x - tx) + Abs(pa.y - ty);
            tx = pa.x;
            ty = pa.y;
        }
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 15888
N = int(input())
for i in range(N):
  t, x, y = map(int, input().split())
# x+y > t　No
# x+y とtの偶奇が違うならNo
# ここを思いつけば勝ち！
  if ((x+y) > t) or ((x+y +t)%2):
    print("No") 
    exit()
print("Yes")

Measured memory_bytes: 3060
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: usize = itr.next().unwrap().parse().unwrap();
    let b: usize = itr.next().unwrap().parse().unwrap();
    let mut ans = n / (a + b) * a;
    let rem = n % (a + b);
    if rem > a {
        ans += a;
    } else {
        ans += rem;
    }
    println!("{}", ans);
}


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

int main(int argc, char* argv[]){
    int N, A[100001] = {}, sum = 0, now = 0, tmp1, tmp2;
    bool plused;
    A[0] = 0;
    cin >> N;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
        sum += abs(A[i] - now);
        now = A[i];
    }
    sum += abs(now);


    for(int i = 1; i <= N; i++){
        if((A[i-1] <= A[i] && A[i] <= A[i+1]) || (A[i+1] <= A[i] && A[i] <= A[i-1])){
            cout << sum << endl;
        } else {
            tmp1 = abs(A[i] - A[i-1]);
            tmp2 = abs(A[i] - A[i+1]);
            cout << sum - ((tmp1 < tmp2 ? tmp1 : tmp2) * 2) << endl;
        }
    }
}

Measured memory_bytes: 1664
import sys

input = sys.stdin.readline


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

    all_xor = A[0]
    for a in A[1:]:
        all_xor = all_xor ^ a

    ans = [a ^ all_xor for a in A]
    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 41460
X, Y = gets.split.map(&:to_i)

candidates = []

[true, false].each do |first_B|
  [true, false].each do |last_B|
    x = X
    count = 0

    if first_B
      x *= -1
      count += 1
    end

    abs_diff = (x.abs - Y.abs).abs
    x += abs_diff
    count += abs_diff

    if last_B
      x *= -1
      count += 1
    end

    candidates.push(x == Y ? count : nil)
  end
end

puts candidates.compact.min


Measured memory_bytes: 1788
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,W;
 
 
int32_t main()
{
    cin>>n>>W;
    int w[n+2];
    int v[n+2];
    int dp[n+1][W+1];
    for(int i=1;i<=n;i++){cin>>w[i]>>v[i];}
    for(int wi=0;wi<=W;wi++){
        dp[1][wi] = 0;
    }
    for(int wi = w[1];wi<=W;wi++){
        dp[1][wi] = v[1];
    }
    for(int i=2;i<=n;i++){
        for(int wi = 0; wi<=W;wi++){
            dp[i][wi] = dp[i-1][wi];
            if(wi>=w[i])
            {
                dp[i][wi] = max(dp[i][wi], v[i]+dp[i-1][wi-w[i]]);
            }
        }
    }
    cout<<dp[n][W];
 
 
 
}

Measured memory_bytes: 81564
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    if(a%2 == b%2) {
        out((b-a)/2);
    }
    else {
        out(min(a-1, n-b) + 1 + (b-a-1)/2);
    }

    re0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

pll X[55];

int main()
{
    ll N, W;
    cin >> N >> W;
    REP(i, N)
    {
        cin >> X[i].first >> X[i].second;
    }

    ll n = N / 2;
    vector<pll> p, q;
    REP(i, pow(2, n))
    {
        pll t(0, 0);
        REP(j, n)
        {
            if (((i >> j) & 1) == 1)
            {
                t.first += X[j].first;
                t.second += X[j].second;
            }
        }
        p.push_back(t);
    }
    REP(i, pow(2, N - n))
    {
        pll t(0, 0);
        REP(j, N - n)
        {
            if (((i >> j) & 1) == 1)
            {
                t.first += X[j + n].first;
                t.second += X[j + n].second;
            }
        }
        q.push_back(t);
    }
    sort(q.begin(), q.end(), [](pll a, pll b) { return a.second < b.second; });
    vector<ll> r(q.size());
    r[0] = q[0].first;
    FOR(i, q.size(), 1)
    {
        r[i] = std::max(r[i - 1], q[i].first);
    }

    ll max = 0;
    REP(i, p.size())
    {
        pll a = p[i];
        ll ok = -1, ng = q.size();
        while (abs(ok - ng) > 1)
        {
            ll mid = (ok + ng) / 2;
            if (q[mid].second + a.second <= W)
                ok = mid;
            else
                ng = mid;
        }
        if (ok < 0)
            continue;
        max = std::max(max, r[ok] + a.first);
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 43980
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream &s, const map<T, S> m) { for (pair<T, S> p: m) s << p << endl; return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "\t" << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl << "\t", dump_func(__VA_ARGS__);
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

signed main() {
  int N; cin >> N;
  int ok = false;
  REP (i, N) {
    int a; cin >> a;
    if (a % 2) ok = true;
  }
  cout << (ok ? "first" : "second") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	

	void solve(){
		

		ini(n);
		vi tmp(101);
		FOR(i,0,n){
			in(tmp[i]);
		}
		// sort(all(tmp));
		int tmp1 = 0;
		FOR(i,0,n){
			FOR(i1,i,n){
				FOR(i2,i1,n){
					if(tmp[i]!=tmp[i1] and tmp[i]!=tmp[i2] and tmp[i1]!=tmp[i2]){
						if(tmp[i]+tmp[i1]>tmp[i2] and tmp[i1]+tmp[i2]>tmp[i] and tmp[i]+tmp[i2]>tmp[i1] and abs(tmp[i]-tmp[i1])<tmp[i2] and abs(tmp[i1]-tmp[i2])<tmp[i] and abs(tmp[i]-tmp[i2])<tmp[i1]){
							tmp1++;
							// out(i+1,i1+1,i2+1);
						}
					}
					else{
						continue;
					}
				}
			}
		}
		out(tmp1);
		
			
			
			


				
		


		
		
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const int MAX = 100005;
int h[MAX];
using ll = long long int;
ll dp[MAX];
int main() {
	int n,i,j,k;
	cin>>n>>k;
	for(i=0;i<n;++i) {
		cin>>h[i];
	}
	dp[0] = 0;
	for(i=1;i<n;++i) {
		dp[i] = 1LL<<62;
		for(j=1;j<=k and i-j>=0;++j) {
			dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

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

#define MAX 2000001
#define VMAX 10000

void CountingSort( short *, short *, int );

int n;

int main()
{
  unsigned short *A, *B;
  int i, j, k=0;

  scanf("%d", &n);

  A = malloc( 1 + n * sizeof(short));
  B = malloc( 1 + n * sizeof(short));

  for(  i=1; i<=n; i++ )
    {
      scanf("%hd", &A[i]);
      if( k < A[i] ) k = A[i];
    }

  CountingSort( A, B, k );

  for( i=1; i<n; i++ ) printf("%d ", B[i]);
  printf("%d\n", B[n]);

  return 0;
}


void CountingSort( short *A, short *B, int k )
{
  int i, j, C[k+1];

  for( i=0; i<=k; i++ )
    C[i] = 0;

  for( j=1; j<=n; j++ )
    C[A[j]]++;

  for( i=1; i<=k; i++ )
    C[i] = C[i] + C[i-1];

  for( j=n; j>0; j-- )
    {
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }
}



Measured memory_bytes: 9652
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=500005;
int n,d[N],x,i,j,k;
long double s[N],w,ans;
int main()
{
	scanf("%d%d%d",&n,&d[1],&x);
	for(i=2;i<=2*n;++i)
		d[i]=d[i-1]+x;
	for(i=1,j=0;i<2*n;i+=2,++j)
	{
		k=d[i]+d[i+1];
		s[1]+=2*k;
		s[min(j,n-j-1)+2]-=k;
		s[max(j,n-j-1)+2]-=k;
	}
	/*for(i=2;i<=2*n+1;i+=2)
	{
		w=d[i-1];
		for(j=i-1,k=1;j>1;j-=2,++k)
			w+=1.0*(d[j-2]+d[j-1])/(k+1)/2;
		w+=d[i];
		for(j=i+1,k=1;j<2*n+1;j+=2,++k)
			w+=1.0*(d[j]+d[j+1])/(k+1)/2;
		ans+=w/2;
	}*/
	for(i=1;i<=n;++i)
	{
		s[i]+=s[i-1];
		ans+=(long double)s[i]/(long double)i;
	}
	printf("%.15Lf",ans/(long double)4);
	return 0;
}


Measured memory_bytes: 7552
#include <stdio.h>

int main(void){
	
	char a[21],b[21]={'0'};
	int s,t;
	
	scanf("%s",a);
	
	for(s=0;a[s]!='\0';s++){
	}
	
	for(t=0;a[t]!='\0';t++){
		
		b[s-t-1]=a[t];
		
	}
	
	printf("%s\n",b);
	
	return 0;
}

Measured memory_bytes: 2524
N = int(input())
A = list(map(int,input().split()))
count = 0
while True:
    odd = False
    for i in range (N):
        if A[i]%2 == 1:
            odd = True
    if odd:
        break;
    for i in range (N):
        A[i] /=2
    count +=1
print(count)

Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }
void printYes(bool f) {
	if(f)cout << "Yay!" << endl;
	else cout << ":(" << endl;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<int>a(N); rep(i, 0, N) { cin >> a[i]; }
	int ans = INF;
	int sum = accumulate(all(a), 0ll);
	int x = 0;
	rep(i, 0, N - 1) {
		x += a[i];
		int y = sum - x;
		chmin(ans, abs(x - y));
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
def gcd(x, y):
    a = x % y
    if a == 0:
        return y
    return gcd(y, a)

x, y = map(int, input().split())

z = 0
if x < y:
    z = gcd(y, x)
else:
    z = gcd(x, y)

print(z)


Measured memory_bytes: 5600
#include "bits/stdc++.h"
using namespace std;

#define int long long


/*https://github.com/kurokoji/.cpp-Template/wiki#struct-fast*/
//理解できていないものはコメントアウト
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* short */
//#define pb push_back
//#define eb emplace_back
//#define mp make_pair
//#define Fi first
//#define Se second
#define ALL(v) begin(v), end(v) // sort(ALL(v));みたいに使う
//#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
//#define EACH(i, n) for (auto&& i : n)

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
//using pii = pair<int, int>;
using D = double;
//using P = complex<D>;
using vs = vector<string>;
//template <typename T> using PQ = priority_queue<T>;
//template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
//const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 }, dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };

/* func */
inline bool inside(int y, int x, int H, int W) { return y >= 0 && x >= 0 && y < H && x < W; }
inline int in() { int x; cin >> x; return x; }
//inline vs split(const string& t, char c) { vs v; stringstream s(t); string b; while (getline(s, b, c)) v.eb(b); return v; }
//template <typename T> inline bool chmin(T& a, const T& b) { if (a > b) a = b; return a > b; }
//template <typename T> inline bool chmax(T& a, const T& b) { if (a < b) a = b; return a < b; }
//template <typename T, typename S> inline void print(const pair<T, S>& p) { cout << p.first << " " << p.second << endl; }
template <typename T> inline void print(const T& x) { cout << x << '\n'; }
//template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) { for (auto&& p : v) print(p); }
//template <typename T> inline void print(const vector<T>& v, string s = " ") { REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n"); }

unsigned long long f(unsigned long long x) {
	unsigned long long ans = 0, c = (x + 1) / 2;

	if (c % 2 == 1) { ans = 1; }

	if (x % 2 == 0) {
		ans = ans ^ x; 
	}

	return ans;
}

signed main() {
	unsigned long long  A,B;

	cin >> A >> B;

	unsigned  long long  ansA = f(A - 1), ansB = f(B);

	cout << (ansA^ansB) << endl;

	#ifdef _DEBUG
		system("pause");
	#endif
	return 0;
}



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

int main() {
    int N;
    int sum=0;
    cin >>N;
    int mi = 100000000;
    vector<int>data(N);
    for(int i=0;i<N;i++){
        cin >>data.at(i);
    }
    sort(data.begin(),data.end());
    for(int i=data.at(0);i<=data.at(N-1);i++){
        sum=0;
        for(int j=0;j<N;j++){
            sum += (data.at(j)-i)*(data.at(j)-i);
        }
        mi =min(sum,mi);
    }
    cout<<mi<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  ll len = 0;
  for (ll b = 1; b <= K; b*=2) {
    len++;
  }
  
  ll X = 0;
  for (ll b = len - 1; b >= 0; b--) {
    ll zero = 0 , one = 0;
    for (int i = 0; i < N; i++) {
      if ((A[i] >> b) & 1) {
        one++;
      } else {
        zero++;
      }
    }
    if (zero > one && (X | (1LL << b)) <= K) {
      X |= (1LL << b);
    }
  }
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    sum += A[i] ^ X;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
#define F first
#define S second
#define MK make_pair
const ll E=1e17+7;
const ll MOD=1000000007;





int main(){
    ll n,m;
    cin>>n>>m;
    vector<vector<ll>> a(n);
    for(int i=0;i<m;i++){
        ll s,t;
        cin>>s>>t;
        s--; t--;
        a[s].push_back(i+1);
        a[t].push_back(-1*i-1);
    }
    bool done[1000000]={};
    vector<ll> now;
    ll ans=0;
    for(int i=0;i<n;i++){
        sort(a[i].begin(),a[i].end());
        for(int t=0;t<a[i].size();t++){
            if(a[i][t]>0){now.push_back(a[i][t]);}
            if(a[i][t]<0 && !done[abs(a[i][t])]){
                done[abs(a[i][t])]=true;
                ans+=1;
                for(int h=0;h<now.size();h++){
                    done[now[h]]=true;
                }
                now.clear();
            }
        }
    }
    
    //for(int i=1;i<=m;i++){assert(done[i]);}
    
    cout<<ans<<endl;
    
    
    
    
    return 0;
}

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

int main() {
  string n;
  cin >> n;
  string ans;
  
  if(n.at(0)==n.at(1) ||n.at(2)==n.at(1) || n.at(2)==n.at(3)){
    ans="Bad";
  }else{
    ans="Good";
  }

  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

class Node():
    key = None
    p = None
    left = None
    right = None

    def __init__(self, key):
        self.key = key

class BinarySearchTree():
    root = None

    def insert(self, z):
        y = None
        x = self.root
        while x is not None:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        
        z.p = y

        if y is None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def find(self, k):
        x = self.root
        while x is not None:
            if x.key==k:
                return True
            elif x.key>k:
                x = x.left
            else:
                x = x.right
        return False

    def print_nodes(self):
        inorder = []
        preorder = []

        def dfs(v):
            v_key = v.key
            preorder.append(v_key)
            if v.left is not None:
                dfs(v.left)
            inorder.append(v_key)
            if v.right is not None:
                dfs(v.right)

        dfs(self.root)

        print('', *inorder)
        print('', *preorder)

def resolve():
    m = I()
    T = BinarySearchTree()
    for _ in range(m):
        q = LSS()
        if q[0]=='insert':
            k = int(q[1])
            z = Node(k)
            T.insert(z)
        elif q[0]=='find':
            k = int(q[1])
            if T.find(k):
                print('yes')
            else:
                print('no')
        else:
            T.print_nodes()

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 148724
#include<cstdio>
int a[110000];
int main()
{
    int n,ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
    if(a[a[i]]==i) ans++;
    printf("%d\n",ans/2);
    return 0;
}

Measured memory_bytes: 512
number = int(input())
my_set = set()
for i in range(number):
    input_line = input()
    splitted_line = input_line.split(" ")
    my_set.add((splitted_line[0], - int(splitted_line[1]), i+1))

my_sorted = sorted(my_set)

for item in my_sorted:
    print(item[2])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
#define PII pair<int,int>
const int maxn=100500;
struct node{int x,y,id;}e[maxn];
struct data{int x,id;};
int n,m;
vector<data> g[maxn];
int ans[maxn],d[maxn],vis[maxn],fa[maxn],dep[maxn];
void dfs(int u){
    vis[u]=1;
    for (auto x:g[u]){
        int v=x.x,id=x.id;
        if (vis[v]) continue;
        fa[v]=u; dep[v]=dep[u]+1;
        dfs(v);
    }
}
void dfs2(int u){
    for (auto x:g[u]){
        int v=x.x,id=x.id;
        if (fa[v]==u) dfs2(v);
    }
    for (auto x:g[u]){
        int v=x.x,id=x.id;
        if (v!=fa[u]) continue;
        if (d[u]&1) {
            d[u]++;
            if (e[id].x==u) ans[id]=1;
            else ans[id]=2; 
        }    
        else {
            d[v]++;
            if (e[id].y==u) ans[id]=1;
            else ans[id]=2;
        }
    }
}
int main(){
    scanf("%d%d",&n,&m);
    rep(i,1,m){
        scanf("%d%d",&e[i].x,&e[i].y);
        g[e[i].x].push_back((data){e[i].y,i});
        g[e[i].y].push_back((data){e[i].x,i});
    }
    dfs(1);
   // rep(i,1,n) printf("%d ",d[i]); puts("");
    //rep(i,1,n) printf("%d ",fa[i]); puts("");
    rep(i,1,n) vis[i]=0;
    rep(i,1,m) {
        int x=e[i].x,y=e[i].y;
        if (fa[x]==y||fa[y]==x) continue;
        if (dep[x]<dep[y]) swap(x,y);
        d[x]++;
        if (e[i].x==x) ans[i]=1; else ans[i]=2; 
    }
    //rep(i,1,m) printf("%d ",ans[i]); puts(""); 
    dfs2(1);
    if (d[1]&1) puts("-1");
    else {
        rep(i,1,m) {
            if (ans[i]==1) printf("%d %d\n",e[i].x,e[i].y);
            else printf("%d %d\n",e[i].y,e[i].x);
        } 
    } 
    return 0;
}

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

int main() {
  string s;
  int N;
  cin >> N;
  cin >> s;
  int Rcounter = 0;
  int Bcounter = 0;
  for (int i=0; i<N;i++){
    if (s[i] == 'R') Rcounter++;
    else Bcounter++;
  }
  if(Rcounter > Bcounter) cout << "Yes" << endl;
  else cout << "No"<< endl;

}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cstring>
#include <stdio.h>
#include <string.h>
using namespace std;
#define ll long long



int main() {

    ll n;
    ll m;
    cin>>n>>m;

    priority_queue<ll> pq;

    ll b;
    for(ll i = 0; i < n; i++) {
        cin>>b;
        pq.push(b);

    }

    while(m > 0 && !pq.empty()) {
        ll a = pq.top();
        pq.pop();
        if(a/2 > 0) {
            pq.push(a/2);
        }
        m--;
    }

    ll total = 0;
    while(!pq.empty()) {
        total += pq.top();
        pq.pop();
    }

    cout<<total<<'\n';
    return 0;
}

Measured memory_bytes: 1400