akhauriyash/Code-Regression huggingface dataset:
object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }
 
  def solve(input:String):String={
    val List(n,y)=input.split(" ").map(_.toInt).toList;
    f1(n,y,0) match{
      case Some((a,b,c))=>s"${a} ${b} ${c}"
      case None=>"-1 -1 -1"
    }
  }

  def f1(n:Int,y:Int,a:Int):Option[(Int,Int,Int)]={
    if(a<=n){
      f2(n,y,a,0) match{
        case Some(v)=>Some(v)
        case None=>f1(n,y,a+1)
      }
    }else{
      None
    }
  }

  def f2(n:Int,y:Int,a:Int,b:Int):Option[(Int,Int,Int)]={
    if(b<=n-a){
      val c=n-a-b;
      if(a*10000+b*5000+c*1000==y){
        Some((a,b,c))
      }else{
        f2(n,y,a,b+1)
      }
    }else{
      None
    }
  }
 
  val tests=List("""9 45000""" -> """0 9 0""",
    """20 196000""" -> """-1 -1 -1""",
"""1000 1234000"""->"""14 27 959""",
"""2000 20000000"""->"""2000 0 0""");
 
  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}.zipWithIndex.map{case ((input,outputExpect),i)=>{
      val output=solve(input).trim();
      s"test${i+1}:"+(if(output==outputExpect){
        "Passed"
      }else{
        s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
      })
    }}.mkString("\n");
  }
}

Measured memory_bytes: 25664
#include <iostream>

using namespace std;

int main(){
    int S;
    cin >> S;
    int pre_num = -1;
    bool ans = false;
    

    for(int i=0; i<4; i++){
        if(pre_num == S%10){
            ans = true;
        }
        pre_num = S%10;
        S = S/10;
    }
    if(ans){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	int C[4] = {};
	rep(i, N) {
		string S;
		cin >> S;

		if (S == "AC") C[0]++;
		if (S == "WA") C[1]++;
		if (S == "TLE") C[2]++;
		if (S == "RE") C[3]++;
	}

	cout << "AC x " << C[0] << endl;
	cout << "WA x " << C[1] << endl;
	cout << "TLE x " << C[2] << endl;
	cout << "RE x " << C[3] << endl;






	Would you please return 0;
}

Measured memory_bytes: 3656
#include<iostream>
 
using namespace std;
 
int main(){
	int n, m;
	cin >> n >> m;
	int A[100][100];
	int b[100];
	int c[100] = {0};
    for(int i=0;i<n;i++) {
        for(int j=0;j<m;j++){
            cin>>A[i][j];
		}
    }

    for(int i=0;i<m;i++){
        cin>>b[i];
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            c[i] = c[i] + A[i][j] * b[j];
        }
    }
    for (int i=0;i<n;i++)
        cout<<c[i]<<endl;
}

Measured memory_bytes: 1200
n = int(input())

kosu = [0,0,0]
ans = 0
for i in range(n):
    s = input()
    ans += s.count('AB')
    if s[0]=="B" and s[-1]=="A":
        kosu[2] += 1
        continue
    if s[0] == "B":
        kosu[1] += 1
    if s[-1] == "A":
        kosu[0] += 1

if kosu[2] == 0:
    ans += min(kosu[0],kosu[1])
else:
    if kosu[0]+kosu[1] >= 1:
        ans += min(kosu[0], kosu[1])+kosu[2]
    else:
        ans += kosu[2]-1

print(ans)

Measured memory_bytes: 74924
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<set>
#include<iostream>
#include<stdlib.h>
using namespace std;
typedef long long ll;


int main(void) {
	string s, t;
	cin >> s >> t;
	for (int i = 0;i < s.length();i++) {
		char tmp = s[0];
		for (int j = 1;j < s.length();j++) {
			s[j - 1] = s[j];
		}
		s[s.length() - 1] = tmp;
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
g = [[0 for _ in range(n)]for _ in range(max(l))]
for i in range(1,max(l)+1):
    for j in range(n):
        if l[j]>=i:
            g[i-1][j] = 1
        else:
            g[i-1][j] = 0
ans = 0
for line in g:
    last_h = 0
    for h in line:
        if last_h == 0 and h == 1:
            ans+=1
        last_h = h
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define INF 21e8

vector <int> stones;
vector <int> dp;
int n, k;

int main(){

	scanf("%d %d" , &n , &k);
	for(int i = 0 ; i < n ; i++){
		int a;
		scanf("%d" , &a);
		stones.push_back(a);
	}

	dp.push_back(0);
	for(int i = 1 ; i < n ; i++){
		dp.push_back(INF);
		for(int j = 1 ; j <= (i < k ? i : k) ; j++){
			int a = dp[i - j] + abs(stones[i] - stones[i-j]);
			//printf("%d %d\n" , j, a);
			dp[i] = min(dp[i], a);
		}
	}

	printf("%d\n" , dp[n-1]);

	return 0;

}

Measured memory_bytes: 1400
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

if __name__ == "__main__":
    K, N = MI()
    A = LI()
    a = []
    for i in range(N):
        if i != N-1:
            a.append(abs(A[i]-A[i+1]))
        else:
            a.append(abs(A[i]-K-A[0]))
    a.remove(max(a))
    print(sum(a))

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

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

  if (a % 2 == 1 && b % 2 == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <sstream>
#include <cstdio>
using namespace std;
typedef pair <int,int> p;
vector<p> V;

bool compare(p a,p b) {
  if(a.first != b.first) {
    return a.first > b.first;
  }
  else {
    return a.second < b.second;
  }
}

p score(string str) {
  stringstream ss;
  string s;
  int number;
  ss << str;
  ss >> number;
  int frame = 1,play=1,point[11] = {};
  int spare[22] = {},strike[22] = {};
  bool check = true;
  while(ss >> s) {
    int pin = atoi(s.c_str());
    if(check) point[frame] += pin;
    for(int i=1;i<11;i++) {
      if(strike[i]>0) {
	point[i]+=pin;
	strike[i]--;
      }
      if(spare[i]>0) {
	point[i]+=pin;
	spare[i]--;
      }
    }
    if(play==1&&pin==10) {
      strike[frame]=2;
      if(frame!=10) frame++;
      else check = false;
      play=1;
      continue;
    }
    if(play==1&&pin!=10) {
      play++;
      continue;
    }
    if(play==2&&point[frame]==10) {
      spare[frame] = 1;
      if(frame!=10)frame++;
      else check = false;
      play=1;
      continue;      
    }
    if(play==2&&point[frame]!=10) {
      frame++;
      play=1;
      continue;
    }
  }
  int sum=0;
  for(int i=1;i<=10;i++) {
    //  cout << point[i] << " ";
    sum += point[i];
  }
  // cout << sum << endl;
  p ans;
  ans.first = sum;
  ans.second = number;
    return ans;
}
  
int main() {
  int m;
  string str;
  while(scanf("%d\n",&m),m) {
    for(int i=0;i<m;i++) {
      p temp;
      getline(cin,str);
      temp = score(str);
      V.push_back(temp);
    }
    sort(V.begin(),V.end(),compare);
    for(unsigned int i=0;i<V.size();i++) {
      cout << V[i].second << " " << V[i].first << endl;
    }
    V.clear();
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <ctype.h>
int main(){
    int cnt[1201]={};
    int i,j;
    char chara;
    
    while(scanf("%c",&chara)!=EOF){
            if(isalpha(chara)){
                
                if(isupper(chara)){
                    i=chara-'A';
                }
                
                else if(islower(chara)){
                    i=chara-'a';
                }
                
                cnt[i]++;
            }
            else continue;
        }
        
        for(j=0;j<26;j++){
            printf("%c : %d\n",'a'+j,cnt[j]);
        }
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	YN(n>=(2*k-1));
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $N);
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%d", $K);

$arr = str_split($S);
$key = substr($S, $K-1, 1);

for ($i=0; $i < $N; $i++) { 
	$out = ($arr[$i]==$key)?$key:'*';
	printf("%s", $out);
}

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

int main(){
 int N,X;
 cin >> N>>X;
 vector<int>L(N);
 int count = 1;
  int sum = 0;
 for(int i = 0;i < N;i++){
  cin >> L[i];
  sum += L[i];
  if(sum>X){
    break;
  }
  count++;
}
cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,k) for(int i=k; i<n; ++i)
#define drep(i,n,k) for(int i=n; i>k; --i)
using namespace std;

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  if(a > b) swap(a,b);
  int h = 0, ans;
  drep(i,a,0){
    if(a % i == 0 && b % i == 0) h++;
    if(h == k){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

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

int main() {

  int A,B,C=0,K=0,L=0;
  vector<int> X(100);
  
  cin >> A >> B >> K;
  
  if(A>B){
    C=B;
  }
  else{
    C=A;
  }
  for(int i =1;i <= C;i++){
    if(A%i == 0 && B%i == 0){
      X.at(L)= i;
      L +=1;
    }
  }
  if(L-K+1<0){
    cout << 0 <<endl;
  }
  else{
    cout << X.at(L-K)<<endl;
  }
}

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

int main() {
    int n, q; cin >> n >> q;
    vector<vector<int>> A(n);
    while(q--) {
        int k, t; cin >> k >> t;
        if(k == 0) {
            int x; cin >> x;
            A[t].push_back(x);
        } else if(k == 1) {
            for(auto it=A[t].begin(); it != A[t].end(); ++it) {
                if(it != A[t].begin()) cout << ' ';
                cout << *it; 
            }
            cout << endl;
        } else {
            A[t].clear();
        }
    }
}


Measured memory_bytes: 5868
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> b(n-1);
    REP(i, n-1) cin >> b[i];

    vector<ll> a(n, INF);
    REP(i, n-1) {
        chmin(a[i], b[i]);
        chmin(a[i+1], b[i]);
    }
    cout << accumulate(ALL_OF(a), 0LL) << endl;
    
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from fractions import Fraction

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

def nextOrd2(target):
    for i in range(20):
        if 2 ** i >= target:
            return i

ans = Fraction(0, 1)

for i in range(1, N+1):
    p = nextOrd2(K/i)
    ans += Fraction(1, N * 2 ** p)

print('{:.11f}'.format(ans.numerator/ans.denominator))


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

#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int dp[200000];

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	int n,k;
	cin>>n>>k;
	int h[n+1];
	h[0]=0;
	for (int i = 1; i <=n; i++) {
	    cin>>h[i];
	}
	for (int i = 2; i <=n; i++) {
	    //dp[i] = min(dp[i-1] + fabs(h[i] - h[i-1]) , dp[i-2] + fabs(h[i-2] - h[i]));
	    dp[i] = INT_MAX;
	    for(int j = max(1,i - k);j<i;j++)
	    {
	  
	        dp[i] = min(dp[i],(int)(dp[j] + fabs(h[i] - h[j])));
	    }
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <complex>
#include <ctime>
#include <unordered_map>
#pragma comment (linker, "/STACK:256000000")

using namespace std;

const int maxN = 260000;
int n;
int x[maxN];
int a[maxN];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	vector < pair < int, int > > p;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &x[i]);
		p.push_back(make_pair(x[i], i));
	}
	sort(p.begin(), p.end());

	set < int > unused;
	for (int i = 1; i <= n * n; ++i) {
		unused.insert(i);
	}

	for (int i = 0; i < n; ++i) {
		int v = p[i].second;
		int needed = v - 1;
		unused.erase(p[i].first);
		a[p[i].first] = v;

		for (int j = 0; j < needed; ++j) {
			int pos = *unused.begin();
			unused.erase(unused.begin());
			a[pos] = v;
		}
	}

	for (int i = 0; i < n; ++i) {
		int v = p[i].second;
		int needed = n - v;
		for (int j = 0; j < needed; ++j) {
			int pos = *unused.begin();
			unused.erase(unused.begin());
			a[pos] = v;
		}
	}

	vector < vector < int > > q(n + 1);
	for (int i = 1; i <= n * n; ++i) {
		if (a[i] == 0) {
			printf("No\n");
			return 0;
		}
		q[a[i]].push_back(i);
	}

	for (int i = 1; i <= n; ++i) {
		if (q[i].size() != n || q[i][i - 1] != x[i]) {
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");
	for (int i = 1; i <= n * n; ++i) {
		printf("%d", a[i]);
		if (i == n * n) {
			printf("\n");
		} else {
			printf(" ");
		}
	}


	return 0;
}

Measured memory_bytes: 13824
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define ALL(v) v.begin(),v.end()
#define mod 1000000007

ll a[100010]={0};
ll b[100010]={0};
ll c[100010]={0};


int main(){
  ll n;
  cin >> n;
  rep(i,n)cin >> a[i];
  rep(i,n)cin >> b[i];
  rep(i,n)cin >> c[i];
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  //bからの二分探索
  ll ans=0;
  rep(i,n){
    auto apos=lower_bound(a,a+n,b[i]);
    auto cpos=lower_bound(c,c+n,b[i]+1);
    ll aitr=distance(a,apos);
    ll citr=distance(c,cpos);
    ans+=aitr*(n-citr);
  }
  cout << ans << endl;

}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
//printf("%.12lf\n",mid);
//const long long sze = 2*(2^(long long)(ceil(log(100000)/log(2))));
/*
// get part of decimal
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/

const double eps = .0000000001;
inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
};
int n;
bool arr[100][10000];
int ques[100];
vector<int> thiss;
long long sums = 0;
bool found = false;
int val = 0;

int main(){
    prep(); 
    
    cin >> n;
   
    for (int i=0; i<n; i++){
      cin >> ques[i];
      sums += ques[i];
      thiss.push_back(ques[i]);
    }
    if (sums%10 != 0){
      cout << sums;
      return 0;
    }
    arr[0][sums] = true;
    for (int i=1; i<100; i++){
      for (int j=0; j<=sums; j++){
        if (arr[i-1][j]){
          arr[i][j-ques[i-1]] = true;
          arr[i][j] = true;
          if (j%10 != 0){
            if (j > val){
              val = j;
            }
          }
          if ((j-ques[i-1])%10 != 0){
            if (j-ques[i-1] > val){
              val = j-ques[i-1];
            }
          }
        }
      }
    }
    cout << val;
    return 0;
}      

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string s;
    long long k;
    cin >>s;
    cin >>k;

    int oneLength = 0;
    while(s[oneLength] == '1'){
        oneLength++;
    }
    if(k > oneLength){
        printf("%c\n",s[oneLength]);
    }else{
        printf("1\n");
    }
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        printf("%c",(s[i]-'A'+n)%26+'A');
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll elem[105000];
vector<char>ans;
int main()
{
   ll n,x,sum=0,q,y;
   cin>>n;
   for(ll i=0;i<n;i++)
   {
       cin>>x;
       sum+=x;
       elem[x]++;
   }
   cin>>q;
   for(ll i=0;i<q;i++)
   {
       cin>>x>>y;
       sum+=elem[x]*(y-x);
       elem[y]+=elem[x];
       elem[x]=0;
       cout<<sum<<endl;
   }

}


Measured memory_bytes: 4368
n,x,y=map(int,input().split())

cnt=[0 for i in range(n)]

for i in range(1,n+1):
  for j in range(i+1,n+1):
    a=min(abs(x-i),abs(y-i))
    b=min(abs(x-j),abs(y-j))
    l=min(j-i,a+b+1)
    cnt[l] += 1
      
for i in range(1,n):
  print(cnt[i])


Measured memory_bytes: 50524
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CHonestOrUnkind2 {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vvc<pii> G(N);
        REP(i, N){
            int a;
            in>>a;
            G[i].resize(a);
            REP(j, a){
                in>>G[i][j].first>>G[i][j].second;
                G[i][j].first--;
            }
        }
        int ans = 0;
        vc<int> state(N, -1);
        REP(i, 1<<N){
            bool ok = true;
            int cnt = 0;
            REP(j, N){
                if((i>>j&1)==0) continue;
                ++cnt;
                for(auto& k : G[j]){
                    if(k.second==1) ok &= (i>>k.first&1);
                    else ok &= (i>>k.first&1) == 0;
                }
            }
            if(ok) chmax(ans, cnt);
        }
        out<<ans<<'\n';
    }
};


int main() {
	CHonestOrUnkind2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3640
class Combination:
  def __init__(self, n_max, mod=10**9+7):
    self.mod = mod
    self.modinv = self.make_modinv_list(n_max)
    self.fac, self.facinv = self.make_factorial_list(n_max)

  def __call__(self, n, r):
    return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

  def make_factorial_list(self, n):
    # 階乗のリストと階乗のmod逆元のリストを返す O(n)
    # self.make_modinv_list()が先に実行されている必要がある
    fac = [1]
    facinv = [1]
    for i in range(1, n+1):
      fac.append(fac[i-1] * i % self.mod)
      facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
    return fac, facinv

  def make_modinv_list(self, n):
    # 0からnまでのmod逆元のリストを返す O(n)
    modinv = [0] * (n+1)
    modinv[1] = 1
    for i in range(2, n+1):
      modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
    return modinv

N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
MOD = 10**9+7

comb = Combination(10**5+1)

ans = 0
for i in range(N-K+1):
  ans -= A[i] * comb(N - i - 1, K - 1) % MOD
  ans %= MOD

A = A[::-1]
for i in range(N-K+1):
  ans += A[i] * comb(N - i - 1, K - 1) % MOD
  ans %= MOD

print(ans % MOD)

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

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

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main() {
	int w;
	while (cin >> w, ~w) {
		int cost = 1150;
		w -= 10;
		if (w > 0) { cost += 125 * min(w, 10); w -= 10; }
		if (w > 0) { cost += 140 * min(w, 10); w -= 10; }
		if (w > 0) cost += 160 * w;
		cout << 4280 - cost << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<limits>
#include<stack>
//include<bits/stdc++.h>
using namespace std;
int main()
{
	int num;
	cin >> num;
	string str;
	cin >> str;
	int count = 0;
	for (int i = 0; i < num; i++)
	{
		if (str[i] == 'A' && i < num - 2 && str[i + 1] == 'B'&&str[i + 2] == 'C')
		{
			count++;
			i += 2;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) {
	    BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
	    try {
	     
			int n, x;
			int cnt, ave3, ave2;
			String[] tmpArray;  
			while( true ) {
			    String str = kb.readLine();
			    tmpArray = str.split( " " );
			    n = Integer.parseInt( tmpArray[0] );
			    x = Integer.parseInt( tmpArray[1] );
			
			    if( 0 == n && 0 == x ) {  break; }
			
			    cnt = 0;
			    ave3 = x / 3;
			    int i, j, k;
	            for( i=1; i<ave3; i++ ) {
					ave2 = ( x-i ) / 2;
					for( j=i+1; j<=ave2; j++ ) {
						k = x - i - j;
					    if( j < k && k <= n ) {
					        cnt++;
					    }
					}
	            }
	            System.out.println( cnt );    
	        }
	    } catch( IOException e ) {
	        System.err.println( e );
	    }
	}
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())

    out = [1]*(N+1)
    for _ in range(M):
        out[int(input())] = 0
        
    for i in range(2, N+1):
        if out[i] == 1:
            out[i] = (out[i-1] + out[i-2])
    return out[-1]%1000000007
    
if __name__ == '__main__':
    print(main())


Measured memory_bytes: 460020
#Cakes and Donuts
import sys

N = int(input())

def getAns(n) :
    total = 0
    for i in range(n) :
        for j in range(n) :
            total = i * 4 + j * 7
            if total == n :
                return "Yes"
    return "No"

print(getAns(N))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
    int n;
    cin>>n;
    map<string , int> mp; 
    set<string> s;
    for(int i=0;i<n;++i){
        string s1;
        cin>>s1;
        s.insert(s1);
        mp[s1]++;
    }
    int mx = 0;
    for(auto i:s){
        mx = max(mx , mp[i]);
    }
    vector<string> as;
    for(auto i:s){
        if(mp[i]==mx){
            as.push_back(i);
        }
    }
    sort(as.begin(),as.end());
    for(int i=0;i<as.size();++i){
        cout<<as[i]<<'\n';
    }
    return 0;
}

Measured memory_bytes: 34928
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
   
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        string s;cin>>s;
        rep(i,3)cout<<s[i];
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589;

int main(){
  int n;
  cin >> n;
  set<string> a;
  rep(i, n){
    string s;
    cin >> s;
    a.insert(s);
  }
  cout<<a.size()<<endl;
}

Measured memory_bytes: 19048
from functools import lru_cache

MOD = 10 ** 9 + 7

s = input()
s = s[::-1]
dp0 = [0] * len(s)
dp1 = [0] * len(s)  # smaller
if s[0] == "0":
    dp1[0] = 1
else:
    dp1[0] = 3
dp0[0] = 3

for i in range(1, len(s)):
    if s[i] == "1":
        dp1[i] = dp0[i-1] + dp1[i-1] * 2
    else:
        dp1[i] = dp1[i-1]
    dp0[i] = dp0[i-1] * 3

    dp0[i] %= MOD
    dp1[i] %= MOD

print(dp1[-1])


Measured memory_bytes: 11620
open Batteries
let rec collect acc sum = function
  | [] -> (sum + acc)
  | (x::xs) ->
      collect (10*acc+x) sum xs +
      collect x (sum+acc) xs

let (h::s) = Scanf.scanf "%s" String.to_list
  |> List.map (fun d -> int_of_char d - 48)
;;

collect h 0 s |> Printf.printf "%d\n"



Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        int[] p = new int[n+1];
        long[] c = new long[n+1];
        for(int i=1; i<=n; i++) {
            p[i] = Integer.parseInt(sc.next());
        }
        for(int i=1; i<=n; i++) {
            c[i] = Long.parseLong(sc.next());
        }
        
        //全体の最大値
        long ans = 0;
        //iから始めた時の最大値
        long max = 0;
        //総和
        long count = 0;
        //ループ回数
        long roop = 0;
        for(int i=1; i<=n; i++) {
            //いまどこ
            int now = p[i];
            count = c[now];
            max = count;
            if(i == 1) ans = max;
            roop = 1;
            
            while(now != i && roop < k) {
                now = p[now];
                count += c[now];
                if(max < count) max = count;
                roop++;
            }
            if(k > roop) {
                if(count < 0) {
                    if(ans < max) ans = max;
                }else {
                    count = count * (k / roop - 1);
                    roop = roop * (k / roop - 1);
                    if(max < count) max = count;
                    while(roop < k) {
                        now = p[now];
                        count += c[now];
                        if(max < count) max = count;
                        roop++;
                    }
                    if(ans < max) ans = max;
                }
            }else {
                if(ans < max) ans = max;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 43336
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    string s;cin>>s;
    int n=s.size();
    stack<int> l;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    rep(i,n){
        if(s[i]=='\\')l.push(i);
        else if(s[i]=='/'){
            if(l.size()){
                pq.push(mp(l.top(),i));
                l.pop();
            }
        }
    }
    vin ans;int total=0;int sum,tmp;int j=0;
    while(pq.size()){
        sum=0;tmp=pq.top().second;
        while(pq.size()&&pq.top().first<tmp){
            sum+=pq.top().second-pq.top().first;
            pq.pop();
        }
        ans.push_back(sum);
        total+=sum;
    }
    int k=ans.size();
    cout<<total<<endl;
    if(k==0)cout<<k<<endl;
    else{
        cout<<k<<" ";
        rep(i,k-1)cout<<ans[i]<<" ";
        cout<<ans[k-1]<<endl;
    }
}


Measured memory_bytes: 3296
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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; }

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  string a,b,c;
  cin >> a >> b >> c;

  char turn = 'A';
  int na=0, nb=0, nc=0;

  while(1){
    if(turn=='A'){
      if(na==a.size())break;
      na++;
      turn = toupper(a[na-1]);
    }
    else if(turn=='B'){
      if(nb==b.size())break;
      nb++;
      turn = toupper(b[nb-1]);
    }
    if(turn=='C'){
      if(nc==c.size())break;
      nc++;
      turn = toupper(c[nc-1]);
    }
  }

  cout << turn << endl;
  return 0;
} 

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

int main() {
  int N,Y; cin >>N >>Y;
  rep_eq(y,0,N) {
    rep_eq(x,0,N) {
      int z=N-x-y;
      if (z<0) z=0;
      if (x+y+z==N and x*10000+y*5000+z*1000==Y) {
        cout <<x <<' ' <<y <<' ' <<z <<endl;
        return 0;
      }
    }
  }
  cout <<-1 <<' ' <<-1 <<' ' <<-1 <<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	dd=collections.defaultdict(lambda :0)
	for _ in range(n):
		v = int(input())
		dd[v] += 1
	
	ret = 0
	for k in dd:
		if dd[k] % 2 == 1:
			ret += 1
	print(ret)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 87512
using AtCoderBeginnerContest123.Questions;
using AtCoderBeginnerContest123.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest123.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var dishes = new int[5];
            for (int i = 0; i < 5; i++)
            {
                dishes[i] = inputStream.ReadInt();
            }

            yield return Enumerable.Range(0, 5)
                .Min(except => dishes
                    .Take(except)
                    .Concat(dishes.Skip(except + 1))
                    .Sum(d => (int)Math.Ceiling((decimal)d / 10) * 10) + dishes[except]);
        }
    }
}


namespace AtCoderBeginnerContest123
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest123.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest123.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13524
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  double A[N];
  REP(i,N)cin>>A[i];
  double ans=0;
  REP(i,N)ans+=1.0/A[i];
  //固定小数点
  cout<<fixed;
  //桁数固定
  cout<<setprecision(6);
  cout<<1.0/ans<<endl;
  return 0;
}


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

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


signed main() {
	ll N,K;
	cin >> N >> K;
	vector<ll> a(N,0);
	rep(i,N)cin >> a[i];

	if(K==0){
		p(accumulate(a.begin(), a.end(), 0LL));
		return 0;
	}

	ll size=ceil(log2(K));
	size=40;
	vector<ll> bit(size,0);

	rep(i,N){
		rep(j,size){
			if(a[i] & (1LL<<j)){
				bit[j]--;
			}else{
				bit[j]++;
			}
		}
	}

	ll k=0;
	for(ll i=size-1;i>=0;i--){
		if(bit[i]>0 && (k|(1LL<<i))<=K ){
			k|=(1LL<<i);
		}
	}
	debug(bit);
	debug(k);

	ll ans=0;
	rep(i,N){
		ans+=a[i]^k;
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 1024
use std::io::{BufRead, Write};
use std::io;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let _n: usize = buf.trim_right().parse().unwrap();
    buf.clear();
    input.read_line(&mut buf).unwrap();
    let a: Vec<i32> = buf.split_whitespace().map(|s| s.parse().unwrap()).collect();
    let sum = a.iter().fold((0, 0), |(sum, prev), &cur| {
        (sum + (cur - prev).abs(), cur)
    }).0 + a.last().unwrap().abs();
    for i in 0..a.len() {
        let prev = if i == 0 {
            0
        } else {
            a[i - 1]
        };
        let cur = a[i];
        let next = if i == a.len() - 1 {
            0
        } else {
            a[i + 1]
        };
        writeln!(output, "{}", sum - (cur - prev).abs() - (next - cur).abs() + (next - prev).abs()).unwrap();
    }
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "3
3 5 -1
",
            "12
8
10
",
        );
    }

    #[test]
    fn case2() {
        test(
            "5
1 1 1 2 0
",
            "4
4
4
2
4
",
        );
    }

    #[test]
    fn case3() {
        test(
            "6
-679 -2409 -3258 3095 -3291 -4462
",
            "21630
21630
19932
8924
21630
19288
",
        );
    }
}

Measured memory_bytes: 5244
using System;

class _0001
{
    public static void Main()
    {
        int[] height = new int[10];
        for (int i = 0; i < 10; i++) height[i] = Int32.Parse(Console.ReadLine());
        Array.Sort(height);
        Array.Reverse(height);
        for (int i = 0; i < 3; i++) Console.WriteLine(height[i]);
    }
}

Measured memory_bytes: 5752
s = int(input())
a = [0]*(s+5)
a[0] = 1
mod = 10**9 + 7
for i in range(3 , s+1):
    if i < 3 :
        continue

    a[i] = (a[i-1] + a[i-3]) % mod

print(a[s])

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, L;
string S[110];

void solve() {
	cin >> N >> L;
	rep(i, 0, N) cin >> S[i];
	sort(S, S + N);
	string ans = "";
	rep(i, 0, N) ans += S[i];
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int>f;
int n,ans;
int main(){
	scanf("%d",&n);
	int a[100005];
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		f[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		if(f[a[i]]<a[i]&&f[a[i]]!=0)ans+=f[a[i]],f[a[i]]=0;
		else if(f[a[i]]>=a[i]&&f[a[i]]!=0)ans+=f[a[i]]-a[i],f[a[i]]=0;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5120
import math

N = int(input())
N_ = int(math.sqrt(N)) + 1

min_distance = N - 1
for i in range(1, N_):
    p, r = divmod(N, i)
    if r == 0:
        if 1 <= p <= N:
            distance = (i-1) + (p-1)
            min_distance = min(min_distance, distance)
        else:
            continue

print(min_distance)


Measured memory_bytes: 9060
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long

int main() {
  int n;cin>>n;
  vector<double>a(n);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  sort(a.begin(),a.end());
  double ans=(a.at(0)+a.at(1))/2,sum;
 
  for(int i=2;i<n;i++)
  {
    sum+=(ans+a.at(i))/2;
    ans=sum;
    sum=0;
  }
  cout<<ans;
}
  
  
    

  
    
  


Measured memory_bytes: 256