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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

ll dp[1 << 13];

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

  vector<ll> a(M), c(M, 0);
  REP(i, M){
    int b;
    cin >> a[i] >> b;
    REP(j, b){
      int c1;
      cin >> c1;
      c[i] |= (1 << (c1 - 1));
    }
  }

  memset(dp, -1, sizeof(dp));
  REP(i, (1 << N)) dp[i] = longinf;
  dp[0] = 0;

  REP(i, (1 << N)){
    if(dp[i] == longinf) continue;
    REP(j, M){
      chmin(dp[i | c[j]], dp[i] + a[j]);
    }
  }

  if(dp[(1 << N) - 1] == longinf) cout << -1 << endl;
  else cout << dp[(1 << N) - 1] << endl;

  return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#define long int64_t
using namespace std;

struct Solver {
	void solve() {
		string S;
		cin >> S;

		if( S == "RRR" ) { cout << 3 << endl; }
		else if( S == "SSS" ) { cout << 0 << endl; }
		else if( S == "RRS" || S == "SRR" ) { cout << 2 << endl; }
		else { cout << 1 << endl; }
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3656
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sum [] = new int[2];
		for(int i = 0; i < 2; i++){
			for(int j = 0 ;j < 4; j++){
				sum[i] += sc.nextInt(); 
			}
		}
	 System.out.println(Math.max(sum[0],sum[1]));
	}
}

Measured memory_bytes: 26296
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  vi x(n);
  rep(i,n) cin >> x[i];
  
  vi y = x;
  sort(y.begin(), y.end());
  rep(i,n) {
    int ans;
    if (x[i] < y[n/2]) ans = y[n/2];
    else ans = y[n/2-1];
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 200000 + 5;
long long a[maxn];

map<long long, long long> s;
set<long long> q;

int main(){
    int n; cin >> n;
    long long cnt = 0;
    s[0] = 1;
    for(int i = 1; i <= n; i++){
        scanf("%lld", &a[i]);
        a[i] += a[i-1];
        if(!s[a[i]]) s[a[i]] = 1;
        else s[a[i]]++;
        if(!q.count(a[i])) q.insert(a[i]);
    }
    set<long long>::iterator it;
    for(it = q.begin(); it != q.end(); it++){
        //printf("%d ", s[*it]);
        long long k = s[*it];
        cnt += k * (k-1) / 2;
    }
    printf("%lld\n", cnt);
    return 0;
}


Measured memory_bytes: 23680
var
 s:ansistring;
begin
 readln(s);
 if  (pos('W',s)=0) and (pos('N',s)=0)
 and (pos('E',s)=0) and (pos('S',s)=0) then
  begin
   writeln('Yes');
   halt;
  end;
 if pos('W',s)<>0 then
  if pos('E',s)<>0 then 
   if pos('N',s)<>0 then 
    if pos('S',s)<>0 then
     begin
      writeln('Yes');
      halt;
     end;
 if pos('W',s)<>0 then
  if pos('E',s)<>0 then 
   if pos('N',s)=0 then 
    if pos('S',s)=0 then
     begin
      writeln('Yes');
      halt;
     end;
 if pos('N',s)<>0 then
  if pos('S',s)<>0 then 
   if pos('W',s)=0 then 
    if pos('E',s)=0 then
     begin
      writeln('Yes');
      halt;
     end;
 writeln('No');
end.

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

int main(){
  int k,x;
  cin >> k >> x;
  int a,b;
  if ((x-(k-1))<=-100000){
    a=-100000;
  } else {
    a=x-(k-1);
  }
  if ((x+(k-1))>=1000000){
    b=1000000;
  } else {
    b=x+(k-1);
  }
  for (int i=a;i<b+1;i++) cout << i <<" ";
}


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

using namespace std;

 
 
int main() {
   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
     
    long int n;
    cin>>n;
    if(n%2==0)
      cout<<n/2-1;
      
    else
      cout<<n/2;
      
      
	return 0;
	
} 

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

int main() {
  string s;
  cin >> s;
  
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == '1') {
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int N;
    cin >> N;
    vector<int> d(N);
    REP(i, N) cin >> d[i];

    int ans = 0;
    for (int i=0; i<d.size()-1; ++i) {
        for (int j=i+1; j<d.size(); ++j) {
            ans += d[i] * d[j];
        }
    }
    print(ans);
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int m[10000];
int nd[5];
int dgt[5];
int get_dgt_sum(int n) {
	int count = 0;
	while (n>0)
	{
		count += n % 10;
		n /= 10;
	}
	return count;
}
int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int cnt = 0;
	/*int i, j, k;
	int sum = 0;
	
	i = 4;
	while (n>0)
	{
		nd[i--] = n % 10;
		n /= 10;
	}
	int nd_index_start = i + 1;
	int n_len = 5 - nd_index_start;
	for (i = 1;i < n_len;i++) {
		for (j = 1;j < 10;j++) {

		}
	}*/
	for (int i = 1;i <= n;i++) {
		int tmp = get_dgt_sum(i);
		if (tmp >= a && tmp <= b) {
			cnt += i;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int64_t> vec(n + 1);
    vec.at(0) = 2;
    vec.at(1) = 1;

    for (int i = 2; i < n + 1; i++) {
        vec.at(i) = vec.at(i - 1) + vec.at(i - 2);
    }
    cout << vec.at(n) << endl;
}


Measured memory_bytes: 256
(N, M) = [int(n) for n in input().split()]

if N % 2 == 1:
    for m in range(M):
        print('{} {}'.format(m+1, 2*M-m))
else:
    m0 = M // 2 # num of even
    m1 = M - m0 # num of odd
    for m in range(m1):
        print('{} {}'.format(m+1, 2*m1-m))
    base = 2*m1
    for m in range(m0):
        print('{} {}'.format(base+m+1, 2*m0+1-m+base))
        


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

void Main()
{
	char vowels[] = {'a','e','i','o','u'};
	char c; cin >> c;
	cout << (binary_search(vowels, vowels + 5, c) ? "vowel" : "consonant") << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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

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

    if ((s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]) || (s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1]) || (s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

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

    int N; cin >> N;
    VI A(N);
    vector<vector<PII>> info(N);
    VI T(N,-1);
    REP(i,N){
        cin >> A[i];
        REP(j,A[i]){
            int x,y; cin >> x >> y;
            x--;
            info[i].eb(x,y);
        }
    }
    int ans = 0;

    for(int i = 0; i < (1 << N); i++){
        REP(j,N) T[j] = -1;
        int acc = 0;
        bool ok = true;
        REP(j,N){
            if(1 & (i >> j)){
                T[j] = 1;
            }else{
                T[j] = 0;
            }
        }

        REP(j,N){
            if(1 & (i >> j)){
                acc++;
                for(auto p : info[j]){
                    if(T[p.first] != p.second){
                        ok = false;
                    }
                }
            }
        }

        if(!ok) continue;
        chmax(ans,acc);
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
// #define int long long
 
/* short */
#define pb push_back
#define print(x) cout << x << '\n'
 
/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = INT_MAX;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

int Shinobu(int n, int s, int num)
{
  if (n == 0 && s == 0) return (1); // mitukatta
  if (num > 9 || s < 0) return (0);

  return (Shinobu(n, s, num + 1) + Shinobu(n - 1, s - num, num + 1));
}

signed main()
{
  ios::sync_with_stdio(false);

  for (int n, s; cin >> n >> s, n || s; print(Shinobu(n, s, 0)));

  return (0);
}

Measured memory_bytes: 1192
# from math import factorial as fac
from collections import defaultdict
# from copy import deepcopy
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
# print(f.readline())
# sys.setrecursionlimit(10**6)

	
def print_case_iterable(case_num, iterable):
	print("Case #{}: {}".format(case_num," ".join(map(str,iterable))))

def print_case_number(case_num, iterable):
	print("Case #{}: {}".format(case_num,iterable))

def print_iterable(A):
	print (' '.join(A))

def read_int():
	return int(f.readline().strip())
def read_int_array():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def read_string():
	return list(f.readline().strip())
def bi(x):
	return bin(x)[2:]





from collections import deque
import math


def solution(h1,m1,h2,m2,k):
	return 60*(h2-h1) + (m2-m1) - k
	
			


def main():
	T = 1
	for i in range(T):
		h1,m1,h2,m2,k = read_int_array()
	
		x = solution(h1,m1,h2,m2,k)

		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			print >>output,str(x)# "Case #"+str(i+1)+':',
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()

if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
#example usage:
#    for l in res:
#       print >>output, str(len(l)) + ' ' +  ' '.join(l)

if __name__ == '__main__':
	main()



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

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    if (A == 5 && B == 5 && C == 7){
        cout << "YES" << endl;
    }else if (A == 5 && C == 5 && B == 7){
        cout << "YES" << endl;
    }else if (B == 5 && C == 5 && A == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
 public static void main(String[] args)throws IOException{
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  int length,date,i;
  length = Integer.parseInt(br.readLine());
  String[] strAry;
  strAry = br.readLine().split(" ");
  
  for(i=length-1;i>=0;i--){
   if(i<length-1){
    System.out.print(" "+ strAry[i]);
   }else{
    System.out.print(strAry[i]);
   }
  }
  System.out.println("");
    
 }
}

Measured memory_bytes: 24248
#include<bits/stdc++.h>
using namespace std;
int n,k,x,ans;
int main()
{
    scanf("%d%d",&n,&k);
    for(register int i=1;i<=n;++i)
    {
        scanf("%d",&x);
        ans+=2*min(x,k-x);
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        Deque<Integer> deque=new ArrayDeque<>();
        int count=0;
        while(scanner.hasNext()){
            String input=scanner.next();
            //count++;
            //System.out.println(String.format("%d:%s",count,input));
            if(input.charAt(0)=='*'){
                int x=deque.removeFirst();
                int y=deque.removeFirst();
                deque.addFirst(x*y);
            }else if(input.charAt(0)=='+'){
                int x=deque.removeFirst();
                int y=deque.removeFirst();
                deque.addFirst(x+y);

            }else if(input.charAt(0)=='-'){
                int x=deque.removeFirst();
                int y=deque.removeFirst();
                deque.addFirst(y-x);

            }else{
                int i=Integer.parseInt(input);
                deque.addFirst(i);
            }
        }
        //System.out.println(deque);
        System.out.println(deque.removeFirst());
    }
}



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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       s.find(x) != s.end()

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
ll a[SZ];
//ll b[SZ];



int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
    //    ll a, b, d;
    string s, s1, s2;

    cin1(n);
    for1(i, n) cin1(a[i]);

    x = a[1] ^ a[2];
    fora(i, 3, n) {
        x ^= a[i];
    }

    for1(i, n) {
        p = x ^ a[i];
        cout << p << " ";
    }
    cotline;

    return 0;
}



Measured memory_bytes: 5148
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include <iomanip>
#include<sstream>
#include<string.h>
using namespace std;
int main()
{
	string s;
	while (cin >> s)
	{
		if ((s.length() == 6) && (s[2] == s[3]) && (s[4] == s[5]))
			cout << "Yes" << '\n';
		else cout << "No" << '\n';
	}
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
S = list(input())[: -1]
Q = int(input())

class BIT:
  def __init__(self, n):
    self.n = n
    self.data = [0] * (n + 1)
    self.el = [0] * (n + 1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j = None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)

fwks = [BIT(N + 1) for _ in range(26)]
a = ord("a")
for i in range(N):
  j = ord(S[i]) - a
  #print(j)
  fwks[j].add(i + 1, 1)
for _ in range(Q):
  q, x, y = input().split()
  q = int(q)
  if q == 1:
    x = int(x)
    for i in range(26):
      if fwks[i].get(x): fwks[i].add(x, -1)
    fwks[ord(y) - a].add(x, 1)
  else:
    x = int(x)
    y = int(y)
    res = 0
    #print(x, y)
    for i in range(26):
      res += fwks[i].get(x - 1, y) > 0
    print(res)

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    ans += s[i] - '0';
  }
  if (ans % 9 == 0) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3720
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), n=N;
		double K = sc.nextDouble(), t=0;
		Map<Double, Double> m = new HashMap<Double, Double>();
		Queue<Double> minQueue = new PriorityQueue<Double>();
		while (n-->0) {
			double b = sc.nextDouble(), c = sc.nextDouble();
			if (!m.containsKey(b)) minQueue.add(b);
			m.put(b,m.get(b)==null ? c : m.get(b)+c);
		}
		Iterator<Double> i = minQueue.iterator();
		while (i.hasNext()) {
			double k = i.next();
			if (t==K||t+m.get(k)>=K) {
				System.out.println((int)k); System.exit(0);				
			}
			t+=m.get(k);
			i.remove();
		}
		sc.close();		
	}

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

}


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

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

    long long L[N];

    switch(N){
        case 1:cout<<1<<endl;return 0;
    }
    for(int i=0;i<=N;i++){
        if(i==0)
            L[i]=2;
        else if(i==1)
            L[i]=1;
        else{
            L[i]=L[i-1]+L[i-2];
        }
    }

    cout<<L[N]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int h(int x); 

int main(void)
{
    int a,b,x,tou;
    scanf("%d%d",&a,&b);
    x=b-a;
    tou=h(x);
    printf("%d\n",h(x)-b);

    return 0;
}

int h(int x){ 
    if(x==1) return 1;  
    return h(x-1)+x;
}




Measured memory_bytes: 128
x, k, d = map(int, input().split())

cur = abs(x)  # 座標を正にしてしまいます
rem = k  # 残りの移動回数です

cnt = min(cur // d, k)  # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt

# 残り回数が0回の場合分けをする必要はないのですが、一応
if rem > 0:
    if rem % 2 == 1:
        cur = abs(cur - d)

print(cur)

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

int main() {
  int n;
  cin >> n;
  if (n % 10 == 3){
    cout << "bon" << endl;
  } else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

typedef struct{
    int st;
    int des;
    int child;
} lineInfo;

vector<lineInfo> lineinfo;

int dfs(int parent, int node, vector<vector<int>>& line){
    if (parent != -1  && line[node].size() == 1) {
        return 1;
    }
    int childsum = 0;
    int childmax = 0;
    for(auto next: line[node]){
        if (next == parent) continue;
        int score = dfs(node, next, line);
        childsum += score;
        childmax = max(childmax, score);
        lineinfo.push_back({node+1, next+1, score});
    }

    return childsum + 1;
}


mint calprob(int e, int n){
    mint m1(2), m2(2), m3(2);
    return (m1.pow(e) - (mint)1) * (m1.pow(n-e) - (mint)1);  
}

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> line(n);
    rep(i, n-1){
        int tmpa, tmpb;
        cin >> tmpa >> tmpb;
        tmpa--; tmpb--;
        line[tmpa].push_back(tmpb);
        line[tmpb].push_back(tmpa);    
    }

    dfs(-1, 0, line);

    mint ans(0);
    for(auto l: lineinfo){
        //cout << l.st << ":" << l.des << ":" << l.child << endl;
        ans += calprob(l.child, n);       
    }
    ans -= 1;
    mint m(2);
    ans += m.pow(n);
    ans -= m.pow(n) * n / 2;
    ans /= m.pow(n);
    cout << ans.x << endl;
}



Measured memory_bytes: 28916
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

char maze[25][25];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        string line;
        cin >> line;
        for (int j = 0; j < W; j++) {
            maze[i][j] = line[j];
        }
    }

    int ret = 0;

    for (int si = 0; si < H; si++) {
        for (int sj = 0; sj < W; sj++) {
            if (maze[si][sj] == '#') continue;

            queue<P> que;
            que.push(P(si, sj));
            vector<vector<int>> table(H, vector<int>(W, INF));
            table[si][sj] = 0;

            while (!que.empty()) {
                P p = que.front(); que.pop();
                int y = p.first;
                int x = p.second;

                for (int i = 0; i < 4; i++) {
                    int xx = x + dx[i];
                    int yy = y + dy[i];
                    if (xx < 0 || yy < 0 || xx >= W || yy >= H) continue;
                    if (maze[yy][xx] != '.') continue;

                    if (table[y][x] + 1 < table[yy][xx]) {
                        table[yy][xx] = table[y][x] + 1;
                        que.push(P(yy, xx));
                    }
                }
            }

            int tmp = 0;
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if (maze[i][j] != '.') continue;
                    tmp = max(tmp, table[i][j]);
                }
            }
            ret = max(ret, tmp);
        }
    }

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

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

int main() {
    int n, sum = 0, temp = 0, ans = INT_MAX;
    cin >> n;
    vector<int> w(n);
    rep(i, n) {
        cin >> w.at(i);
        sum += w.at(i);
    }
    rep(i, n - 1) {
        temp += w.at(i);
        ans = min(ans, abs(sum - 2 * temp));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll n;
  cin>>n;
  cout<<(n+1)%2;
}



Measured memory_bytes: 3632
import sys
input = sys.stdin.buffer.readline

a, b, q = map(int, input().split())
S = [0]*a
T = [0]*b
for i in range(a):
    s = int(input())
    S[i] = s
for i in range(b):
    t = int(input())
    T[i] = t

S.sort()
T.sort()
S = [-10**18]+S+[10**18]
T = [-10**18]+T+[10**18]
import bisect
for i in range(q):
    x = int(input())
    ans = 10**18
    ids = bisect.bisect_right(S, x)
    idt = bisect.bisect_right(T, x)
    for ks in (-1, 0):
        for kt in (-1, 0):
            s = S[ids+ks]
            t = T[idt+kt]
            temp = min(abs(s-x)+abs(s-t), abs(t-x)+abs(s-t))
            ans = min(ans, temp)
    print(ans)

Measured memory_bytes: 56796
#include <cstdio>
#include <iostream>

int main(void) {
  int n, m;
  while (std::cin >> n >> m) {
    std::string s(n, 0);
    bool ok = true;
    for (int i = 0; i < m; i++) {
      int position;
      int value;
      std::cin >> position >> value;
      position--;
      if (s[position] == 0) {
        s[position] = (char)(value + '0');
      } else {
        ok &= s[position] - '0' == value;
      }
    }
    for (int position = 0; position < n; position++) {
      if (s[position] != 0) {
        continue;
      }
      if (position == 0 && n > 1) {
        s[position] = '1';
      } else {
        s[position] = '0';
      }
    }
    if (s[0] == '0' && n > 1) {
      ok = false;
    }
    if (ok) {
      std::cout << s << std::endl;
    } else {
      std::cout << -1 << std::endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
n=int(input())
MOD = (10**9)+7
res = (10**n)%MOD
res = (res - ((9**n)%MOD))%MOD
res = (res - ((9**n)%MOD))%MOD
res = ((res%MOD) + ((8**n)%MOD) )
if(res<0):
	res+= MOD
print(res%MOD)


Measured memory_bytes: 10668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;
typedef unsigned long long ull;

template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
int memo[2020][2020][5];
char grid[2020][2020];
int n,m;

int dp(int x, int y, int dir) {
    if(x < 0 || y < 0 || x >= n || y >= m) return 0;
    if(grid[x][y] == '#') return 0;
    if(memo[x][y][dir] != -1) return memo[x][y][dir];
    int sm = 1;
    if(dir == 4) {
        rep(i,0,4) {
            sm += dp(x+dx[i], y+dy[i],i);
        }
    } else {
        sm += dp(x+dx[dir], y+dy[dir], dir);
    }
    return memo[x][y][dir] = sm;
}

int main() {
    cin.sync_with_stdio(false);
    memset(memo,-1,sizeof(memo));
    cin >> n >> m;
    rep(i,0,n) rep(j,0,m) cin >> grid[i][j];
    int mx = 0;
    rep(i,0,n) rep(j,0,m) mx = max(mx, dp(i,j,4));
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 84096
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

int main() {
  int n,k;
  cin>>n>>k;
  vi h(n);
  rep(i,n) cin>>h[i];
  vi dp(n);
  rrep(i,n-1){
    rrep(j,k){
      if(i-j<0) continue;
      if(j==1){
        dp[i]=dp[i-j]+abs(h[i-j]-h[i]);
        continue;
      }
      mins(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
    }
  }
  cout<<dp[n-1]<<endl;
}    


Measured memory_bytes: 3984
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX=101;
const int INF=(1<<21);

int main(){

  int n,k;
  int zero_one;
  int a,b;
  int c,d,e;
  int w_f[MAX][MAX];

  

  while(cin>> n>> k){
    if(n==0&&k==0) break;

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	w_f[i][j]=INF;
      }
      w_f[i][i]=0;
    }
    
    for(int i=0;i<k;i++){
    cin>> zero_one;
    if(zero_one==1){
      cin>> c>> d>> e;
      if(w_f[c-1][d-1]>e){
	w_f[c-1][d-1]=e;
	w_f[d-1][c-1]=e;
	for(int j=0;j<n;j++){
	  for(int k=0;k<n;k++){
	    w_f[j][k]=min(w_f[j][k],w_f[j][c-1]+w_f[c-1][k]);
	    w_f[j][k]=w_f[k][j]=min(w_f[j][k],w_f[j][d-1]+w_f[d-1][k]);
	  }
	}
      }
    } else {
      cin>> a>> b;
      if(w_f[a-1][b-1]==1<<21){
	cout<< "-1"<< endl;
      } else {
	cout<< w_f[a-1][b-1]<< endl;
      }
    }
    }
  }
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    map<int, int> s;
    for (int i = 1, sum = 0; i <= 999; i++) {
        sum += i;
        s[sum] = i;
    }
    int a, b;
    cin >> a >> b;
    REP(i, 1, 499501) {
        if (s.count(a + i) && s.count(b + i) && s[b + i] - s[a + i] == 1) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

#define ll  long long
#define pb push_back
#define mp make_pair
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;

int main() {
    
    int t, n, k;
    cin>>n>>k;
    int dp[n+1]={};
    
//Fo(i,n)cout<<dp[n]<<"  ";
//cout<<endl;
    int h[n+1];
    Fo(i,n) cin>>h[i];
    dp[1]=0;
    dp[0]=0;
    Fo(i,n){
        if(i==1) continue;
        int mi =INT_MAX;
        for(int j=1;j<=k;j++){
            if((i-j)>0) mi=min(mi,dp[i-j]+abs(h[i-j]-h[i]));
        }
        dp[i]=mi;
        
    }
    cout<<dp[n]<<"  ";
   
}




Measured memory_bytes: 1024
n,m,c=map(int,input().split())
b=[0 for i in range(m)]
a=[[0 for i in range(m)]for i in range(n)]
k=[0 for i in range(m)]
count=0
b=list(map(int,input().split()))
a=[list(map(int,input().split()))for i in range(n)]
for i in range(n):
  ans=0
  for j in range(m):
    ans=ans+(a[i][j]*b[j])
  if (ans+c)>0:
    count=count+1
print(count)

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

using namespace std;

int main() {
    int n, k, s;
    cin >> n >> k >> s;
    for (int i = 0; i < n; i++) {
        if (i < k) {
            cout << s << " ";
        } else {
            if (s != 1e9) {
                cout << s + 1 << " ";
            } else {
                cout << 1 << " ";
            }
        }
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 1280
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, S := ReadInt(), ReadString()

	m1 := make(map[string]int)
	for bits := 0; bits < 1<<N; bits++ {
		r := ""
		b := ""
		for i := 0; i < N; i++ {
			if bits>>i&1 == 0 {
				r += string(S[i])
			} else {
				b = string(S[i]) + b
			}
		}
		m1[r+":"+b]++
	}

	m2 := make(map[string]int)
	for bits := 0; bits < 1<<N; bits++ {
		r := ""
		b := ""
		for i := 0; i < N; i++ {
			if bits>>i&1 == 0 {
				r += string(S[N+i])
			} else {
				b = string(S[N+i]) + b
			}
		}
		m2[b+":"+r]++
	}

	ans := 0
	for k, c1 := range m1 {
		if c2 := m2[k]; c2 > 0 {
			ans += c1 * c2
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

int main() {
	int N, M;
	cin >> N >> M;
	long x[M], diff[M-1];
	for(int i = 0; i < M; i++) {
		cin >> x[i];
	}
	sort(x, x+M);
	
	for(int i = 0; i < M-1; i++) {
		diff[i] = x[i+1] - x[i];
	}
	sort(diff, diff+M-1);
	long sum = 0;
	for(int i = 0; i < M-N; i++) {
		sum += diff[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

    int sum=0,maxL=0;
    REP(i,N){
        int L; cin>>L;
        sum+=L; 
        maxL=max(maxL,L);
    }
    
    if(maxL<sum-maxL)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}


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

const int N = 200000;
const int INFTY = 1000000001;
long long cnt;

void merge(int left, int mid, int right, int A[]) {
  int i, j, k, n1, n2, *L, *R;
  
  n1 = mid - left;
  n2 = right - mid;
  L = new int[n1+1];
  R = new int[n2+1];

  for (i = 0; i < n1; i++) L[i] = A[left+i];
  for (i = 0; i < n2; i++) R[i] = A[mid+i];
  L[n1] = R[n2] = INFTY;

  j = k = 0;
  for (i = left; i < right; i++) {
    if (L[j] <= R[k]) {
      A[i] = L[j++];
    } else {
      A[i] = R[k++];
      cnt += n1 - j;
    }
  }

  delete [] L;
  delete [] R;
}

void merge_sort(int left, int right, int A[]) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    merge_sort(left, mid, A);
    merge_sort(mid, right, A);
    merge(left, mid, right, A);
  }
}
  

int main() {
  int n;
  int A[N];

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

  cnt = 0;
  merge_sort(0, n, A);

  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 4360
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;
const int MAXN=2e6+1e1;
const int Mod=1e9+7;

lint fac[MAXN];
lint inv[MAXN];

int r1,c1,r2,c2;

lint Ans1,Ans2;

lint qpow(lint A,int B)
{

	lint res=1;

	while(B>0)
	{
		if(B&1) (res*=A)%=Mod;
		(A*=A)%=Mod;
		B>>=1;
	}

	return res;

}

lint C(int A,int B)
{

	return ( A<B ? 0 : (((fac[A]*inv[B])%Mod)*inv[A-B])%Mod );

}

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	scanf("%d%d%d%d",&r1,&c1,&r2,&c2);

	int n=max(c1,c2)+r2+2;

	fac[0]=inv[0]=1;

	for(int i=1;i<=n;i++) fac[i]=(fac[i-1]*i)%Mod;

	inv[n]=qpow(fac[n],Mod-2);

	for(int i=n;i;i--) inv[i-1]=(inv[i]*i)%Mod;

	for(int i=r1;i<=r2;i++) (Ans1+=C(i+c2+1,i+1))%=Mod;

	for(int i=r1;i<=r2;i++) (Ans2+=C(i+c1,i+1))%=Mod;

	printf("%lld\n",(Ans1-Ans2+Mod)%Mod);

	return 0;

}

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

using namespace std;

using ll = long long;


void dfs (vector<vector<int>> &gr, int v = 0)
{
	for (auto it : gr[v])
	{
		gr[it].erase (find (gr[it].begin (), gr[it].end (), v));
		dfs (gr, it);
	}
}


void place (const vector<vector<int>> &gr, vector<ll> &d, vector<ll> &c, int v = 0)
{
	d[v] = c.back ();
	c.pop_back();

	for (auto it : gr[v])
		place (gr, d, c, it);
}


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;

	cin >> n;

	vector<vector<int>> gr (n);

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

		cin >> a >> b;
		a--;
		b--;

		gr[a].push_back (b);
		gr[b].push_back (a);
	}

	vector<ll> c (n);

	for (auto &it : c)
		cin >> it;

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

	cout << accumulate(c.begin (), c.end () - 1, 0ll) << endl;

	vector<ll> d (n);

	dfs (gr);
	place (gr, d, c);

	for (auto it : d)
		cout << it << ' ';
	cout << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	ifstream fin("../input.txt");

	solve(fin);

	cout << setprecision(4) << "clock: " << clock() / (double) CLOCKS_PER_SEC << endl;
#else
	cout << setprecision(20);

	solve();
#endif

	return 0;
}


Measured memory_bytes: 1664
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;
int main()
{

	int n;
	cin >> n;

	int a[1001] = {};

	for (int i = 1; i <= n; i++) {
		//cout << i;
		//i を素因数分解
		int nokori = i;
		for (int j = 2; j <= i; j++) {
			//cout << j;
			while(true){
				if (nokori % j == 0) {
					a[j]++;
					nokori = nokori / j;
				}
				else {
					break; 
				}
			}
		}
	}

	long long kosuu = 1;
	for (int i=1;i <= n; i++){
		kosuu *= (a[i] + 1);
		kosuu = kosuu % 1000000007;
	}
	cout << kosuu;
	int wait;
	cin >> wait;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))

dp = [10**10] * N

dp[0] = 0
for i in range(1,N):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])



Measured memory_bytes: 13924
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;
import static java.util.Arrays.fill;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static int[] compose(int p[], int q[]) {
		int n = p.length;
		int r[] = new int[n];
		for (int i = 0; i < n; i++) {
			r[i] = p[q[i]];
		}
		return r;
	}

	static int[] inv(int p[]) {
		int n = p.length;
		int r[] = new int[n];
		for (int i = 0; i < n; i++) {
			r[p[i]] = i;
		}
		return r;
	}

	static int[] pow(int p[], int m) {
		int n = p.length;
		int r[] = new int[n];
		fill(r, -1);
		int c[] = new int[n];
		for (int i = 0; i < n; i++) {
			if (r[i] >= 0) {
				continue;
			}
			int clen = 0;
			for (int j = i;;) {
				c[clen++] = j;
				j = p[j];
				if (j == i) {
					break;
				}
			}
			for (int j = 0; j < clen; j++) {
				r[c[j]] = c[(j + m) % clen];
			}
		}
		return r;
	}

	static void solve() throws Exception {
		int n = scanInt();
		int k = scanInt() - 1;
		int p[] = new int[n], pi[] = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = scanInt() - 1;
			pi[p[i]] = i;
		}
		int q[] = new int[n], qi[] = new int[n];
		for (int i = 0; i < n; i++) {
			q[i] = scanInt() - 1;
			qi[q[i]] = i;
		}
		int pr[] = pow(compose(compose(compose(q, pi), qi), p), k / 6);
		int su[] = pow(compose(compose(compose(pi, q), p), qi), k / 6);
		int p1[] = compose(compose(pr, p), su);
		int p2[] = compose(compose(pr, q), su);
		int res[];
		if (k % 6 == 0) {
			res = p1;
		} else {
			for (int i = 1; i != k % 6; i++) {
				int p3[] = compose(p2, inv(p1));
				p1 = p2;
				p2 = p3;
			}
			res = p2;
		}
		for (int i = 0; i < n; i++) {
			out.print((res[i] + 1) + " ");
		}
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 49920