akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

const int MAX_N=100000;
int N;

int par[MAX_N]; //　親
int rnk[MAX_N]; // rank, 木の深さ

// N要素で初期化
void init(){
  for(int i=0;i<N;i++){
    par[i]=i;
    rnk[i]=0;
  }
}

// 木の根を求める
int find(int x){
  if (par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

// ｘとｙの属する集合を併合
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rnk[x] < rnk[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}

// ｘとｙが同じ集合に属するかどうか
bool same(int x, int y){
  return find(x) == find(y);
}


const int MAX_E=MAX_N*4;
struct edge {int u, v;ll cost;};

bool comp(const edge& e1, const edge& e2){
  return e1.cost<e2.cost;
}

edge es[MAX_E];
int V,E;

ll kruskal(){
  V=N;
  sort(es,es+E,comp);
  init();
  ll res=0;
  for(int i=0;i<E;i++){
    edge e=es[i];
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res+=e.cost;
    }
  }
  return res;
}


int main(){
  cin>>N;
  vector<pair<ll,int>> x(N), y(N);
  for(int i=0;i<N;i++){
    cin>>x[i].first>>y[i].first;
    x[i].second=y[i].second=i;
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  for(int i=0;i<N-1;i++){
    int a=x[i].second, b=x[i+1].second;
    ll c=x[i+1].first-x[i].first;
    es[i]={a,b,c};
    es[i+N]={b,a,c};
  }
  for(int i=0;i<N-1;i++){
    int a=y[i].second, b=y[i+1].second;
    ll c=y[i+1].first-y[i].first;
    es[i+2*N]={a,b,c};
    es[i+3*N]={b,a,c};
  }
  V=N;
  E=(N-1)*4;
  cout<<kruskal()<<endl;
  return 0;
}


Measured memory_bytes: 10368
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP          #-}
{-# LANGUAGE MagicHash    #-}
{-# LANGUAGE MultiWayIf   #-}

import           Data.Bits
import qualified Data.Vector.Unboxed as U
import           Debug.Trace
import           GHC.Exts

#define MOD 1000000007

main :: IO ()
main = do
    [h, w, k] <- map read.words <$> getLine :: IO [Int]
    print $ solve h w k

solve :: Int -> Int -> Int -> IntMod
solve _ 1 _ = 1
solve h w k = dph U.! (k - 1)
  where
    dp0 = U.fromList . take w $ 1 : repeat 0
    dph = iterate step dp0 !! h
    step :: U.Vector IntMod -> U.Vector IntMod
    step !dp = U.generate w $ \i ->
      if | i == 0 -> dp U.! i *% (table U.! (w - 1))
            +% dp U.! (i + 1) *% (table U.! (w - 2))
         | i == w - 1 -> dp U.! (i - 1) *% (table U.! (w - 2))
            +% dp U.! i *% (table U.! (w - 1))
         | otherwise -> dp U.! (i - 1) *% (table U.! (i - 1)) *% (table U.! (w - i - 1))
            +% dp U.! i *% (table U.! i) *% (table U.! (w - i - 1))
            +% dp U.! (i + 1) *% (table U.! i) *% (table U.! (w - i - 2))

table :: U.Vector IntMod
table = U.fromList . take 10 $ 1 : 1 : mkTable 1 0

mkTable !w !b = (2 *% w +% b) : mkTable (w +% b) w

modulus :: Int
modulus = MOD

infixr 8 ^%
infixl 7 *%, /%
infixl 6 +%, -%

type IntMod = Int

(+%) :: IntMod -> IntMod -> IntMod
(I# x#) +% (I# y#) = I# ((x# +# y#) `remInt#` MOD#)
{-# INLINE (+%) #-}

(-%) :: IntMod -> IntMod -> IntMod
(I# x#) -% (I# y#) = I# ((x# -# y# +# MOD#) `remInt#` MOD#)
{-# INLINE (-%) #-}

(*%) :: IntMod -> IntMod -> IntMod
(I# x#) *% (I# y#) = I# ((x# *# y#) `remInt#` MOD#)
{-# INLINE (*%) #-}

(/%) :: IntMod -> IntMod -> IntMod
(I# x#) /% (I# y#) = go# y# MOD# 1# 0#
  where
    go# a# b# u# v#
        | isTrue# (b# ># 0#) = case a# `quotInt#` b# of
            q# -> go# b# (a# -# (q# *# b#)) v# (u# -# (q# *# v#))
        | otherwise = I# ((x# *# (u# +# MOD#)) `remInt#` MOD#)
{-# INLINE (/%) #-}

(^%) :: IntMod -> Int -> IntMod
x ^% n
    | n > 0 = go 1 x n
    | n == 0 = 1
    | otherwise = go 1 (1 /% x) (-n)
  where
    go !acc !y !m
        | m .&. 1 == 0 = go acc (y *% y) (unsafeShiftR m 1)
        | m == 1 = acc *% y
        | otherwise = go (acc *% y) (y *% y) (unsafeShiftR (m - 1) 1)


Measured memory_bytes: 508
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int n, k, a;
Int dp[108000];
Int sum[108000];
int main(){
  cin >> n >> k;
  dp[0] = 1;
  fill(sum, sum + 108000, 1);
  for(int i = 0;i < n;i++){
    cin >> a;
    for(int j = k;j >= 0;j--){
      dp[j] = sum[j];
      if(j-a > 0)dp[j] -= sum[j-a-1];
      dp[j] %= MOD;
    }
    for(int j = 0;j <= k;j++){
      if(j==0)sum[j] = dp[j];
      else sum[j] = sum[j-1] + dp[j];
      sum[j] %= MOD;
    }
  }
  if(dp[k] < 0)dp[k] += MOD;
  cout << dp[k] << endl;
  
  return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

const ll mod = 1e9 + 7;

int main() {
  ll N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll n = 0; n < N; n++) {
    cin >> A[n];
  }

  ll ans = 0;
  for (ll n = 0; n < N; n++) {
    for (ll m = n + 1; m < N; m++) {
      if (A[n] > A[m]) {
        ans = (ans + K) % mod;
      }
    }
  }
  for (ll n = 0; n < N; n++) {
    for (ll m = 0; m < N; m++) {
      if (A[n] > A[m]) {
        ans = (ans + K * (K - 1) / 2) % mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld ",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define fo(i,a,b) for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define ll long long
const int M=1e9+7;
#define endl "\n"
const double pyi=3.14159265358979323846;


bool vis[100005];

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

    int arr[n],arr1[n];
    for(int i=0;i<n;i++)
    {
    	cin>>arr[i];
    	arr1[i]=arr[i];
    }

    sort(arr,arr+n);
    

    int mx=arr[n-1];
    int mx2=arr[n-2];

    fo(i,0,n)
    {
		if(arr1[i]!=mx)
		d1(mx);
    	else
    		d1(mx2);
    }
    return(0);
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class UnionFind {
    int n;
    vector<int> uni;
public:
    explicit UnionFind(int n) : n(n), uni(n, -1) {};
    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }

    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b){ return root(a) == root(b); }
};

int main() {
    int n, m;
    while(cin >> n >> m, n){
        UnionFind uf(2*n);
        for (int i = 0; i < m; ++i) {
            int u, v;
            cin >> u >> v;
            u--; v--;
            uf.unite(u, n+v);
            uf.unite(v, n+u);
        }
        if(uf.same(0, n)){
            puts("0");
            continue;
        }
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            if(uf.same(0, i)) cnt++;
        }
        vector<int> ans;
        if(cnt%2 == 0) ans.emplace_back(cnt/2);
        if((n-cnt)%2 == 0) ans.emplace_back((n-cnt)/2);
        sort(ans.begin(), ans.end());
        ans.erase(unique(ans.begin(), ans.end()), ans.end());
        cout << ans.size() << "\n";
        for (auto &&i : ans) {
            cout << i << "\n";
        }
    }
    return 0;
}


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

int main(){
  int n, x, m, y = 1e9;
  cin >> n >> x;
  int sum = n;
  for(int i = 0; i < n; i++){
    cin >> m;
    y = min(m, y);
    x -= m;
  }
  cout << sum + x / y << endl;
  return 0;
}


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

using namespace std;

int main(){
	while(true){
		vector<int> yama;
		int n,r;
		cin >> n >> r;
		if(n==0&&r==0)return 0;
		for(int i=n;i>0;i--){
			yama.push_back(i);
		}
		for(int i=0;i<r;i++){
			int p,c;
			vector<int> next;
			cin >> p >> c;
			p--;
						
			for(int k=p;k<p+c;k++){
				next.push_back(yama[k]);
			}
			for(int k=0;k<p;k++){
				next.push_back(yama[k]);
			}
			for(int k=p+c;k<n;k++){
				next.push_back(yama[k]);
			}
			yama=next;
		}
		cout << yama[0] <<endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
 

int main() {
    char s;
    string l = "abcdefghijklmnopqrstuvwxyz";
    cin >> s;
    rep(i,l.size()){
        if(s==l[i]) cout << l[i+1] << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector <int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
  stack<int> S;
  S.push(r);
  color[r] = c;
  while ( !S.empty() ) {
    int u = S.top(); S.pop();
    for ( int i = 0; i < G[u].size(); i++ ) {
      int v = G[u][i];
      if ( color[v] == NIL ) {
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assignColor() {
  int id = 1;
  for ( int i = 0; i < n; i++ ) color[i] = NIL;
  for ( int u = 0; u < n; u++ )
    if ( color[u] == NIL ) dfs(u, id++);
}

int main() {
  int s, t, m, q;

  cin >> n >> m;

  for ( int i = 0; i < m; i++ ) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  for ( int i = 0; i < q; i++ ) {
    cin >> s >> t;
    if ( color[s] == color[t] )
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }

  return 0;
}


Measured memory_bytes: 8984
def main():
  n = int(input())
  l = list(map(int, input().split()))
  l.sort()
  l.append(99999999)
  c = 0
  for i in range(n - 2):
      t = i + 2
      for j in range(i + 1, n - 1):
          for k in range(t, n + 1):
              if l[i] + l[j] <= l[k]:
                  t = k
                  break
          if t > j: c += t - j - 1
          if j + 1 == t: t += 1
  print(c)
if __name__ == "__main__":
  main()


Measured memory_bytes: 3316
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str1[40], str2[40];
	int i, j;
	
	scanf("%s", str1);
	
	i = 0;
	j = strlen(str1);
	while (str1[i] != '\0'){
		str2[j - 1] = str1[i];
		i++;
		j--;
	}
	
	printf("%s\n", str2);
	
	return (0);
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<pair<ll, ll>> aPair;
    REP(i, N)
    {
        ll a;
        cin >> a;
        aPair.push_back(make_pair(a, i));
    }
    sort(ALL(aPair));
    reverse(ALL(aPair));

    REP(i, N)
    {
        ll ans;
        if (i != aPair[0].second) ans = aPair[0].first;
        else ans = aPair[1].first;
        cout << ans << endl;
    }
}


Measured memory_bytes: 6256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(int) A(N);
    READVEC(A);

    int negs = 0, leastAbs = 1 << 30;
    lint ret = 0;
    FOR(i, 0, N) { 
        if (A[i] < 0)
            negs++;

        ret += abs(A[i]);
        leastAbs = min(leastAbs, abs(A[i]));
    }

    if (negs % 2 == 1) {
        ret -= 2 * leastAbs;
    }

    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 640
#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

#define QUEUE_SIZE 100000

struct Queue {
  string name;
  int rest;
};

int head, tail;

Queue Q[QUEUE_SIZE];

void enqueue(string name, int x) {

  // if (tail == head) {
  //   cout << "too many elements are enqueued." << endl;
  //   exit(1);
  // }
  Q[tail % QUEUE_SIZE].name = name;
  Q[tail % QUEUE_SIZE].rest = x;
  tail = (tail + 1) % QUEUE_SIZE;
}

Queue dequeue() {
  Queue queue = Q[head];
  head = (head + 1) % QUEUE_SIZE;
  return queue;
}

int main() {
  head = 0;
  tail = 0;

  int n, q;
  cin >> n >> q;

  int elapsed_time = 0;
  int time;
  string name;
  for (int i = 0; i < n; i++) {
    cin >> name >> time;
    enqueue(name, time);
  }

  while(head != tail) {
    Queue queue = dequeue();
    if (queue.rest <= q) {
      elapsed_time += queue.rest;
      cout << queue.name << " " << elapsed_time << endl;
    } else {
      queue.rest = queue.rest - q;
      elapsed_time += q;
      enqueue(queue.name, queue.rest);
    }
  }

  return 0;
}



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

typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1001001001;

const double PI = 3.14159;

using namespace std;

//vector<ll> memo(1000007, INF);

int main() {

    int n, m;
    cin >> n >> m;

    vector<int> memo(n+1, 0);
    vector<int> wamm(n+1, 0);

    int ac = 0, wa = 0;
    int p;
    string s;
    rep(i, m) {
        cin >> p >> s;

        if (s == "WA") {
            
            if (memo[p] == 0) 
                wamm[p]++;

        } else {

            if (memo[p] == 0) {
                ac++;
                memo[p] = 1;
                wa += wamm[p];
            }
        }
    }

    AA(ac << ' ' << wa);
    
}

Measured memory_bytes: 4024
n, m = map(int, input().split())

mat = []
for i in range(n):
	mat.append(list(map(int, input().split())))

vec = []
for i in range(m):
	vec.append(int(input()))

for i in range(n):
	e = 0
	for j in range(m):
		e += mat[i][j] * vec[j]
	print(e)

Measured memory_bytes: 7992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(){
    int n;
    cin >> n;
    vector<double> p(n);
    for(int i=0;i<n;i++) cin >> p[i];
    vector<vector<double>> dp(n+1,vector<double>(n+1,0));
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=i;j++){
            dp[i+1][j+1]+=dp[i][j]*p[i];
            dp[i+1][j]+=dp[i][j]*(1-p[i]);
        }
    }
    double sum=0;
    for(int i=0;i<=n;i++){
        if(n-1<2*i) sum+=dp[n][i];
    }
    printf("%.10lf\n",sum);

}

Measured memory_bytes: 73816
#define SORT(v) sort(v.begin(), v.end())
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <algorithm>
#include <cstdarg>
#include <cstdio>
#include <numeric>

// #include "ane.cpp"

#define INF (int)1e9
#define INFLL (long long)1e18
#define NMAX 200
#define MMAX 200
#define MOD 100000
using namespace std;

// ??????????????¢??????????????¨db_printf()??????????????????
#define DEBUG

//
//  ???????????????
//

// ????????????????????¨????????¢???
typedef pair<int, int> p;
typedef long long ll;


// ???????????°??¨printf
void db_printf(const char* format, ...){
    #ifndef DEBUG
    return;
    #endif
    va_list arg;
    va_start(arg, format);
    vprintf(format, arg);  // ????????????????????????
    va_end(arg);
}

// n?¬??????????????????????????¬¬????????°???????????????????????¨???????????????????????????
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// Union-Find Tree
class UnionFindTree{
    struct node{
        int par;
    };
    std::vector<node> T;

    public:
    void init(int num){
        T.resize(num+1);    // ignore T[0]
        for (int i = 1; i <= num; ++i)
        {
            T[i].par = i;
        }
    }
    void unite(int x, int y){
        T[find(y)].par = find(x);
    }
    int find(int x){
        if (T[x].par == x) return x;
        else return T[x].par = find(T[x].par);
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

//
// ?????????????????????
//


ll N,M,K,A,B,C,D,E;
int dp[NMAX][MMAX] = {};
UnionFindTree uft;

static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

ll ans = 0;

void solve(){
    // ?§£?????¢?????´?????????
    uft.init(N);
    for (int i = 0; i < M; ++i)
    {
        int c,x,y;
        scanf("%d%d%d", &c,&x,&y);
        if (c)
        {
            printf("%d\n", (int)(uft.same(x, y)));
        }else{
            uft.unite(x, y);
        }
    }
}
void debug(){
    // ???????????°??¨??????
}
void answer(){
    // ?§£?????????
    // printf("%lld\n", ans);
}
int main(int argc, char const *argv[])
{
    // ??\??????????????????????????????

    // Fill(dp, -1);

    scanf("%lld%lld", &N,&M);
    solve();
    #ifdef DEBUG
    debug();
    #endif
    answer();

    return 0;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

ll inf=1e18;

int main() {
  while(1) {
    ll n,m;
    ll mx=255,mi=0;
    cin >> n >> m;
    if(n==0&&m==0) break;
    vector<ll> code(m);
    for(ll i=0;i<m;i++) {
      cin >> code[i];
    }
    vector<ll> a(n);
    for(ll i=0;i<n;i++) {
      cin >> a[i];
    }
    vector<vector<ll>> dp(n+1,vector<ll> (256,inf));
    dp[0][128]=0;
    for(ll i=0;i<n;i++) {
      for(ll j=0;j<256;j++) {
        for(ll k=0;k<m;k++) {
          ll temp=j+code[k];
          temp=max(mi,min(mx,temp));
          dp[i+1][temp]=min(dp[i+1][temp],dp[i][j]+(a[i]-temp)*(a[i]-temp));
        }
      }
    }
    ll ans=inf;
    for(ll i=0;i<256;i++) {
      ans=min(dp[n][i],ans);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 43808
my ($k,$n) = split(/ /,<STDIN>);
my @a = split(/ /,<STDIN>);my @diff= ();my $diff;
while ($n > 0){$diff = abs($a[$n-1]-$a[$n-2]);if($diff>$k-$diff){push(@diff,$k-$diff)} else{push(@diff,$diff)};$n--;}
my @sorted = sort{$a<=>$b}@diff;
print $k-$sorted[n-1],"\n";

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

int main() {
  int X, Y;
  cin >> X >> Y;

  set<int> s1;
  set<int> s2;
  set<int> s3;
  s1.insert({1, 3, 5, 7, 8, 10, 12});
  s2.insert({4, 6, 9, 11});
  s3.insert(2);

  if (s1.find(X) != s1.end() && s1.find(Y) != s1.end()) {
    cout << "Yes" << endl;
  } else if (s2.find(X) != s2.end() && s2.find(Y) != s2.end()) {
    cout << "Yes" << endl;
  } else if (s3.find(X) != s3.end() && s3.find(Y) != s3.end()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

const ll INF = 1e15;

int main() {
  int N, K;
  cin >> N;
  K = 1 + N % 2;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  vector<vector<ll>> dp(N + 1, vector<ll>(K + 2, -INF));

  dp[0][0] = 0;
  for (int i = 0; i <= N - 1; i++) {
    for (int j = 0; j <= K; j++) {
      dp[i + 1][j + 1] = dp[i][j];
      ll now = dp[i][j];
      if ((i + j) % 2 == 0) now += A[i];
      dp[i + 1][j] = max(dp[i + 1][j], now);
    }
  }
  cout << dp[N][K] << endl;
}


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

const int MX = 105, MK = 1e5+10, MOD = 1e9+7;
// dp[i][j]: numbers of ways to distribute j candies to the children from 1 to i
int a[MX];
long long dp[MX][MK], prefix[MX][MK];

int main() {
    //cin.sync_with_stdio(0), cin.tie(0);
    //cout.sync_with_stdio(0), cout.tie(0);
    
    //freopen("demo.in", "r", stdin);
	//freopen("demo.out", "w", stdout);
	
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)
		scanf("%d", a+i);
	
	for (int i = 0; i <= k; i++)
		prefix[0][i] = 1;
	
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= k; j++)
		{
			prefix[i][j+1] = (prefix[i][j] + dp[i-1][j]) % MOD;
 		}
 		for (int j = 0; j <= k; j++)
 		{
			dp[i][j] = prefix[i][j+1] - prefix[i][ max(0, j-a[i]) ];
			dp[i][j] = (dp[i][j] + MOD) % MOD;
		}
	}

	printf("%lld\n", (dp[n][k] + MOD) % MOD);

    return 0;
}


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

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

Measured memory_bytes: 256
H, W, K = map(int, input().strip().split(" "))

C = [[0] * W for _ in range(H)]
cnt = 0
for h in range(H):
    tmp = list(input())
    for w in range(W):
        if tmp[w] == "#":
            C[h][w] = 1

for h in range(2**H-1):
    for w in range(2**W-1):
        b = 0
        for i in range(H):
            if (h>>i) & 1 == 1:
                continue
            for j in range(W):
                if (w>>j) & 1 == 1:
                    continue
                b += C[i][j]
        if K == b:
            cnt += 1

print(cnt)

Measured memory_bytes: 73100
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#define N 100000

using namespace std;
vector<int> v[N];
int group[N]={};
int g=0;

bool search(int s,int t){
  if(group[s]==group[t]&&group[s]>0) return true;
  if(group[s]>0) return false;
  group[s]=++g;
  queue<int> q;
  q.push(s);
  while(!q.empty()){
    int a=q.front();
    for(auto i=v[a].begin();i!=v[a].end();i++){
      if(group[*i]==0){
        group[*i]=g;
        q.push(*i);
      }
    }
    q.pop();
  }
  if(group[s]==group[t]&&group[s]>0){ 
    return true;
  }else{
    return false;
  }
}

int main(){
  int n,m; cin>>n>>m;
  int s,t;
  for(int i=0;i<m;i++){
    cin>>s>>t;
    v[s].push_back(t);
    v[t].push_back(s);
  }

  int q; cin>>q;
  for(int i=0;i<q;i++){
    cin>>s>>t;
    if(search(s,t)){
      cout<<"yes"<<endl;
    }else{
      cout<<"no"<<endl;
    }
  }

}

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

typedef long long ll;

int main() {
    int K, X;
    cin >> K >> X;
    int mi = X - K + 1;
    int ma = X + K - 1;
    for (int i = mi;i<=ma;i++){
        cout << i;
        if (i == ma) {
            cout << endl;
        } else {
            cout << " ";
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
const int maxn=200;
typedef long long ll;
char s[maxn+5];
int n,k;
int L[maxn+5],R[maxn+5];
int main()
{

    scanf("%s",s+1);
    n=strlen(s+1);
    scanf("%d",&k);
    ll tmp=0;
    ll tmp2=0;
    for(int l=1,r;l<=n;l=r+1)
    {
        r=l;
        while(r<n&&s[r+1]==s[r]) ++r;
        for(int i=l;i<=r;++i) L[i]=l,R[i]=r;
        tmp+=(r-l+1)/2;
        if(l!=1&&r!=n) tmp2+=(r-l+1)/2;
    }
    if(s[1]!=s[n]) cout<<tmp*k<<endl;
    else
    {
       // cout<<tmp2<<endl;
        ll a=R[1]-L[1]+1;
        ll b=R[n]-L[n]+1;
        ll ans=tmp2*k+(k-1)*((a+b)/2)+a/2+b/2;
        if(R[1]==n) ans=1LL*n*k/2;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

struct Real{

	long long top, bot;

	Real(long long top, long long bot) : top(top), bot(bot) {
		normalize();
	}

	long long gcd(long long a, long long b){
		if(!a || !b) return a+b;
		if(a < b) return gcd(b, a);
		return gcd(b, a%b);
	}

	void normalize(){
		int divisor = gcd(top, bot);
		top /= divisor;
		bot /= divisor;
	}

	Real operator+(const Real& rhs){
		return Real(top*rhs.bot+rhs.top*bot, bot*rhs.bot);
	}

	Real operator+(long long x){
		return Real(top + x*bot, bot);
	}

	Real operator-(const Real& rhs){
		return Real(top*rhs.bot-rhs.top*bot, bot*rhs.bot);
	}

	Real operator*(const Real& rhs){
		return Real(top*rhs.top, bot*rhs.bot);
	}

	Real operator*(long long x){
		return Real(top*x, bot);
	}

	Real operator/(const Real& rhs){
		return Real(top*rhs.bot, bot*rhs.top);
	}

	Real operator/(long long x){
		return Real(top, bot*x);
	}

	Real operator%(long long x){
		return Real(top % (x*bot), bot);
	}

	bool operator==(Real rhs){
		return top*rhs.bot == rhs.top*bot;
	}

	bool operator<(const Real& rhs) const{
		return top*rhs.bot < rhs.top*bot;
	}

	long long toInt(){
		return top / bot;
	}

	double toDouble(){
		return (double)top / bot;
	}

};

int main() {
	while(true){
		int H, h, m, s;
		scanf("%d %d %d %d", &H, &h, &m, &s);
		if(!H && !h && !m && !s) break;
		Real speedH = Real(1, 10*H);
		Real speedM = Real(1, 10);
		Real speedAvg = (speedH + speedM) / 2;
		Real speedS = Real(6, 1);
		long long past = 3600*h + 60*m + s;
		Real positionAvg = speedAvg * past % 360;
		Real positionS = speedS * past % 360;
//		printf("posAvg : %f, posS : %f\n", positionAvg.toDouble(), positionS.toDouble());
		Real distance = min((positionAvg+540-positionS)%360, (positionAvg+360-positionS)%360);
//		printf("dist : %f\n", distance.toDouble());
		Real final = distance / (speedS - speedAvg) + past;
		if(speedH*final%360 == speedM*final%360 && speedM*final%360 == speedS*final%360){
			distance = (distance+180)%360;
			final = distance / (speedS - speedAvg) + past;
		}
//		printf("past : %lld, final : %f\n", past, (double)final.top / final.bot);
		final = final % (H * 3600);
		long long Hour = final.toInt() / 3600;
		final = final + Hour*-3600;
		long long Minute = final.toInt() / 60;
		final = final + Minute*-60;

		printf("%lld %lld %lld %lld\n", Hour, Minute, final.top, final.bot);
	}
	return 0;
}

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

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

	int ab = a + b, ac = a + c, bc = b + c;

	if (ab < ac) {
		if (ab < bc) {
			cout << ab << endl;
		}
		else {
			cout << bc << endl;
		}
	}
	else {
		if (ac < bc) {
			cout << ac << endl;
		}
		else {
			cout << bc << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApp1
{
    class Program
    {
        static int solve(int n, List<int> d)
        {
            d.Sort();

            int k1 = d[n / 2 - 1];
            int k2 = d[n / 2];


            return k2 - k1;
        }
        static void Main(string[] args)
        {
          
            int n   = int.Parse(Console.ReadLine());
            int[] dd = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            List<int> d = new List<int>();
            for(int i = 0; i < n; i++)
            {
                d.Add(dd[i]);
            }


            int ans = solve(n,d);
            Console.WriteLine(ans);
            
        }


    }
}

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

int main() {
  int t[999] = {1};
  for(int i=1;i<999;i++){
    t[i] = t[i-1]+(i+1);
  }
  
  int a,b; cin >> a>>b;
  int dif = b-a;
  int r = t[dif-1]-b;
  cout << r << endl;
 
}

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


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

    for(int i = 1; i < 4; ++i) {
        if(s[i-1] == s[i]) {
            cout << "Bad\n";
            return 0;
        }
    }

    cout << "Good\n";
    return 0;
}

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll A, B, T;
    cin >> A >> B >> T;

    ll sum = 0;
    ll t = 0;
    while(true){
        t += A;
        if(t<=T){
            sum += B;
        }else{
            break;
        }
    }

    p(sum);
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int K = sc.nextInt();
		// スペース区切りの整数の入力
		int A = sc.nextInt();
		int B = sc.nextInt();

		for(int i = 1; i <= B; i++) {
			if(K*i < A) {
				continue;
			} else if(K*i > B) {
				System.out.println("NG");
				break;
			} else {
				System.out.println("OK");
				break;
			}
		}
	}
}


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

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

    vector<int> p_cnt(M, 0),
                o_cnt(M, 0);
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        int X;
        cin >> X;
        mp[X] ^= 1;
        if (mp[X] == 0) {
            p_cnt[X % M]++;
        }
    }
    for (auto p : mp) o_cnt[p.first % M] += p.second;

    int ans = 0;
    for (int i1 = 0; 2 * i1 <= M; i1++) {
        int i2 = (M - i1) % M;
        if (i1 == i2) {
            ans += (2 * p_cnt[i1] + o_cnt[i1]) / 2;
        } else {
            int num1 = 2 * p_cnt[i1] + o_cnt[i1],
                num2 = 2 * p_cnt[i2] + o_cnt[i2];
            if (num1 < num2) {
                swap(num1, num2);
                swap(p_cnt[i1], p_cnt[i2]);
                swap(o_cnt[i1], o_cnt[i2]);
            }
            ans += min(num1, num2);
            ans += min(p_cnt[i1], (num1 - num2) / 2);
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

string s;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
	for (int i = 0; i < s.size(); ++i)
		if (s[i] == '9') {
			cout<<"Yes\n";
			return 0;
		}
	cout<<"No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
typedef priority_queue<p> pq;
typedef priority_queue<p, vector<p>, greater<p>> gpq;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n;
    cin >> n;

    ll ans = 2e12;

    for (ll a = 1; a < sqrt(n) + 1; a++)
    {
        if(n % a == 0)
        {
            ans = min(ans, a + (n / a) - 2);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a // g * b


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

    ans = A[0]
    for a in A[1:]:
        ans = gcd(ans, a)
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;

    int ans = 0;
    for(int i = 0; i < n - 1; i++){
        if(s[i] != s[i + 1]) ans++;
    }
    ans = max(0, ans - 2 * k);
    cout << n - 1 - ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 2010
using namespace std;
bitset<N*N> dp;
ll n,a[N],sum=0; 
int main(){
	ll i;
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	sum=(sum+1)/2;
	dp[0]=1;
	for(i=0;i<n;i++)
	{
		dp|=(dp<<a[i]);
	}
	for(i=sum;i<=sum*2;i++)
	{
		if(dp[i]==1)
		{
			printf("%lld\n",i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 5284
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int N;
  cin >> N;
  int64_t power = 1;
  rep(i, N){
    power *= (i+1);
    power %= 1000000007;
  }
  cout << power << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,x;
    cin>>n>>x;
    vector<int>a(n+1),b(n);
    rep(i,n)cin>>a[i];
    if(n==1){cout<<abs(x-a[0])<<endl; return 0;}
    a.push_back(x);
    sort(a.rbegin(),a.rend());
    for(int i=1; i<=n; ++i){
        b[i-1]=a[i-1]-a[i];
    }
    int ans=__gcd(b[0],b[1]);
    rep(i,n){
        ans=__gcd(ans,b[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1408
N=int(input())
A=list(input().split())
check=[0]*N
for i in range(N):
	check[int(A[i])-1]+=1
num=0
for i in range(N):
	num+=check[i]*(check[i]-1)//2
for i in range(N):
	if check[int(A[i])-1]!=2:
		print(num-(check[int(A[i])-1]-1))
	else:
		print(num-1)

Measured memory_bytes: 21248
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int mod = 1e9 + 7, N = 2e5 + 7;
int n, A, B, C;
LL fac[N], invfac[N], inv[N], ans;
void add(LL &a, LL b) {
	a += b;
	if(a >= mod) a -= mod;
}
LL Pow(LL a, LL b) {
	LL res = 1ll;
	for(; b; b >>= 1, a = a * a % mod) if(b & 1) res = res * a % mod;
	return res;
}
LL binom(int n, int m) {
	return fac[n] * invfac[n - m] % mod * invfac[m] % mod;
}
int main() {
#ifdef fwat
#endif
	n = gi(), A = gi(), B = gi(), C = gi();
	inv[1] = invfac[0] = fac[0] = 1;
	rep(i, 1, n + n) {
		if(i ^ 1) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		fac[i] = fac[i - 1] * i % mod;
		invfac[i] = invfac[i - 1] * inv[i] % mod;
	}
	LL fm = Pow(A + B, mod - 2);
	LL a = A * fm % mod, b = B * fm % mod;
	rep(m, n, 2 * n - 1) {
		LL E = m * 100 % mod * Pow(100 - C, mod - 2) % mod;
		add(ans, binom(m - 1, n - 1) * (Pow(a, n) * Pow(b, m - n) % mod + Pow(a, m - n) * Pow(b, n) % mod) % mod * E % mod);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef unsigned long long int ll;
using namespace std;
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a; cin>>a;
    long double b; cin>>b;
    long double c=(a*b);
    cout<<(ll)c<<endl;
    // cout<<fixed<<setprecision(0)<<c<<endl;
    
    
}

Measured memory_bytes: 3744
#coding:utf-8
def main():
    N,A,B,C,D = list(map(int,input().split()))
    S = input()
    A -=1
    B -=1
    C -=1
    D -=1
    #C>Dのとき:AがBを追い越す
    prev = -1
    if C < D:  #AがBを追い越さない場合
        
        for i in range(A+1,min(C,B)):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        for i in range(B+1,D):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i

        
        print('Yes')
    prev = -1
    if C > D:  #AがBを追い越す時
        for i in range(A+1,B):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        f = False  #追い越せるか

        prevS = -1
        prevprevS = -1

        for i in range(B-1,D+2):
            if S[i] == '#' :
                if i - prev == 1:
                    print('No')
                    return
                prev = i
            else:
                #print(i,prevS,prevprevS)
                if i - prevS == 1 and prevS - prevprevS ==1:
                    f = True
                prevprevS = prevS
                prevS = i
                
                
                
        # if S[D-1] == '.':
        #     f = True
                
        if not f:
            print('No')
            return
        
        for i in range(D+1,C):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        print('Yes')
if __name__ == '__main__':
    main()
    


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

int main()
{
    int d, n;

    cin >> d >> n;
    switch(d){
        case 0: d = 1;
                break;
        default : d = pow(100, d);
                break;
    }
    if(n != 100)
    {   
        cout << d*n << endl;
    }
    else
    {
        cout << d*(n+1) <<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

n=int(input().rstrip())
a=[int(i) for i in input().split()]
cumxor1=[0]
cumxor2=[0]
ans=[]
for i in a:cumxor1.append(cumxor1[-1]^i)
for i in reversed(a):cumxor2.append(cumxor2[-1]^i)
cumxor2=list(reversed(cumxor2))
for i in range(n):
    ans.append(cumxor1[i]^cumxor2[i+1])
print(*ans)

Measured memory_bytes: 41732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a[400001];
ll b[400001];
ll pb[400001];
ll ppb[400001];
ll s1(int l,int r){
	//cout << "s1 " << (ppb[r]-ppb[l])-l*(pb[r]-pb[l]) << ' ' << l << ' ' << r << endl;
	return (ppb[r]-ppb[l])-l*(pb[r]-pb[l]);
}
ll s2(int l,int r){
	return (r+1)*(pb[r]-pb[l])-(ppb[r]-ppb[l]);
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	int g=1;
	for(int i=1; i<=n ;i++){
		cin >> a[i];
		if(a[i]>a[g]) g=i;
	}
	for(int i=1; i<=n ;i++){
		cin >> b[i];
		b[i]*=2;
	}
	for(int i=1; i<=n ;i++){
		a[n+i]=a[i];
		b[n+i]=b[i];
	}
	for(int i=1; i<=2*n ;i++){
		pb[i]=pb[i-1]+b[i];
		ppb[i]=ppb[i-1]+i*b[i];
	}
	vector<int>v;
	for(int i=g; i<=n+g ;i++){
		while(v.size()>=2){
			int x=v[v.size()-2];
			int y=v.back();
			int z=i;
			ll w1=(z-y)*(a[x]-s1(x,y))+(y-x)*(a[z]-s2(y,z-1));
			ll w2=(z-x)*a[y];
			//cout << x << ' ' << y << ' ' << z << ' ' << w1 << ' ' << w2 << endl;
			if(w1>w2) v.pop_back();
			else break;
		}
		v.push_back(i);
	}
	int ptr=0;
	double tot=0;
	for(int i=g; i<n+g ;i++){
		if(v[ptr+1]==i){
			ptr++;
			tot+=a[i];
		}
		else{
			int x=v[ptr];
			int z=v[ptr+1];
			int y=i;
			ll w1=(z-y)*(a[x]-s1(x,y))+(y-x)*(a[z]-s2(y,z-1));
			//cout << s1(x,y) << endl;
			//cout << x << ' ' << y << ' ' << z << ' ' << w1 << endl;
			tot+=1.0*w1/(z-x);
			//cout << i << ' ' << 1.0*w1/(z-x) << endl;
		}
	}
	tot/=n;
	cout << fixed << setprecision(10) << ' ' << tot << '\n';
}

Measured memory_bytes: 16564
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


int M, N;
int p[10005], c[505], e[505];
int dp[505][10005] = {}, sum[10005] = {};
int main() {
	cin >> M >> N;
	rep(i, M) cin >> p[i];
	rep(i, N) cin >> c[i] >> e[i];
	sort(p, p + M, greater<>());
	rep(i, M) sum[i + 1] += sum[i] + p[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= M; j++) {
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			int tmp = min(j + c[i], M);
			dp[i + 1][tmp] = max(dp[i + 1][tmp], dp[i][j] + sum[tmp] - sum[j] - e[i]);
		}
	}
	int ans = 0;
	rep(i, M + 1) ans = max(ans, dp[N][i]);
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 22792
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>

#define ll long long

using namespace std;


int main()
{
    int d, t, s;
    cin >> d >> t >> s;

    if(t*s >= d) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

int dp[1<<8][1<<3];

signed main(){
    int n,ans=1e9;
    cin>>n;
    int a[3];
    r(i,3)cin>>a[i];
    int l[n];
    r(i,n)cin>>l[i];
    r(i,1<<8)r(j,1<<3)dp[i][j]=1e9;
    dp[0][0]=0;
    r(i,(1<<n)){
        r(j,(1<<n))if(j){
            if(i&j)continue;
            r(k,(1<<3)){
                r(p,3){
                    if(k&(1<<p))continue;
                    int sum=0,co=0,C=0;
                    r(t,n)if(j&(1<<t))sum+=l[t],co++;
                    C=sum;
                    C=abs(a[p]-C)+10*(co-1);
                    dp[i|j][k|(1<<p)]=min(dp[i|j][k|(1<<p)],dp[i][k]+C);
                    //cout<<i<<' '<<j<<' '<<k<<' '<<p<<' '<<C<<' '<<sum<<' '<<10*(co-1)<<endl;
                    if((k|(1<<p))==(1<<3)-1){
                        //cout<<dp[i|j][k|(1<<p)]<<endl;
                        ans=min(ans,dp[i|j][k|(1<<p)]);
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

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

typedef pair<int, int> P;
typedef pair<int, P> P2;

int W, H;

int T[30][30];
int V[30][30];

int DX[4] = {0, -1, 1, 0};
int DY[4] = {-1, 0, 0, 1};

int main() {
  while (cin >> W >> H) {
    if (W == 0 && H == 0) break;
    for (int i=0; i<H; i++) {
      for (int j=0; j<W; j++) {
        T[j][i] = 0, V[j][i] = 0;
      }
    }
    for (int i=0; i<H; i++) {
      for (int j=0; j<W-1; j++) {
        int x; cin >> x;
        if (x == 1) {
          T[j  ][i] |= 4;
          T[j+1][i] |= 2;
        }
      }
      if (i == H-1) continue;
      for (int j=0; j<W; j++) {
        int x; cin >> x;
        if (x == 1) {
          T[j][i  ] |= 8;
          T[j][i+1] |= 1;
        }
      }
    }
    queue<P2> q;
    q.push(P2(1, P(0, 0)));
    while (!q.empty()) {
      int r = q.front().first,
          x = q.front().second.first,
          y = q.front().second.second; q.pop();
      if (V[x][y] != 0) continue;
      V[x][y] = r;

      for (int k=0; k<4; k++) {
        int dx = x + DX[k], dy = y + DY[k];
        if (dx < 0 || dx >= W || dy < 0 || dy >= H) continue;
        if (T[x][y] & (1<<k)) continue;
        q.push(P2(r+1, P(dx, dy)));
      }
    }
    cout << V[W-1][H-1] << "\n";
  }
  return 0;
}

Measured memory_bytes: 3064
s=set(input())
alp={"a","b","c","d","e","f","g",
     "h","i","j","k","l","m","n",
     "o","p","q","r","s","t","u",
     "v","w","x","y","z"}
if len(s) ==26:
  print("None")
else:
  print(sorted(alp-s)[0])

Measured memory_bytes: 3188
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int ans, k;
vector<int> g[N];

void dfs(int u, int p, int pp){
	int c = 2;
	for(auto i: g[u]){
		if(i == p)	continue;
		if(u != 1){
			ans = (ans*(k-c)) % mod;
			c++;
		}
		dfs(i, u, p);
	}
}

signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int x = 0, n;
	cin >> n >> k;
	for(int i = 1; i <= n-1; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
		x = max(x, (int)g[u].size());
		x = max(x, (int)g[v].size());
	}	
	if(x+1 > k)
		return cout << 0, 0;
	ans = 1;
	for(int i = 1; i <= (int)g[1].size() + 1; i++)
		ans = (ans*(k-i+1)) % mod;
	dfs(1, 0, 0);
	cout << ans;
	return 0;
}

Measured memory_bytes: 8320
MOD = 2019
L, R = map(int, input().split())

if R - L > 2019:
    print(0)
    exit()

ans = float('inf')
for i in range(L,R):
    for j in range(i+1,R+1):
        ans = min(ans,(i*j)%MOD)
print(ans)

Measured memory_bytes: 40812
package main

import "fmt"

func main() {
	var w, a, b int
	fmt.Scan(&w, &a, &b)
	if abs(a-b) < w {
		fmt.Println(0)
		return
	}
	fmt.Println(min(abs(b+w-a), abs(a+w-b)))
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  int i = 0;
  string s;
  cin >> s;
  if(s[0] == '1') i++;
  if(s[1] == '1') i++;
  if(s[2] == '1') i++;
  cout << i << endl;
}

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

string n;
int k, len;
vector<long long> dp;

long long f(int x, int y, int z){
    int id = (x + y*len)*2 + z;
    if(y == 0) return 1;
    if(x < 0) return 0;
    if(dp[id] != -1) return dp[id];
    long long res = 0;
    if(z == 0){
        res = f(x-1, y, 0) + f(x-1, y-1, z)*9;
    }else{
        int v = n[len-1-x] - '0';
        if(v > 0){
            res += f(x-1, y, 0) + f(x-1, y-1, 0)*(v-1) + f(x-1, y-1, 1);
        }else{
            res += f(x-1, y, 1);
        }
    }

    return dp[id] = res;
}

int main(void){
    cin >> n >> k;
    len = n.length();
    dp.assign(len*(k+1)*2, -1);
    cout << f(len-1, k, 1) << endl;
}


Measured memory_bytes: 256
n = [int(x) for x in input()]
op_cnt = len(n) - 1  
out=0
for i in range(2 ** op_cnt):
    op = ["+"] * op_cnt  
    box=""
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "" 
        box=""  
    for a,b in zip(n,op+[""]):
        box+=(str(a)+b)
    box=box.split('+')
    ou=0
    for k in box:
        out+=int(k)
print(out)

Measured memory_bytes: 9148
#include<stdio.h>
int main (void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a > b){
        printf("a > b\n");
    }else if(a < b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2616