akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
#define ull unsigned long long int
#define ld long double
//Make sure no overflow problems
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define endl '\n'
#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define mod 1000000007
#define MEM(a, b) memset(a, (b), sizeof(a))
#define addmod(a,b,mod) (a%mod + b%mod)%mod
#define submod(a,b,mod) (a%mod - b%mod + mod)%mod
//const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;
const int MAX = 1e6;


int main(){
    ios_base:: sync_with_stdio(0); 
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    int arr[n];
	double total = 0;
    FOR(i,0,n){
		cin >> arr[i];
    	total += arr[i];
	}
	total = total/(4*m*1.0);
	sort(arr, arr+n);
	FORD(i,n-1,n-m){
		if(arr[i] < total){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N,L;
vector<P> a;
ll D[100010],C[100010];
ll l[100010];
ll mx;

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

  cin>>N>>L;
  rep(i,N){
    ll A,B;
    cin>>A>>B;
    a.push_back(P(A,B));
  }
  sort(all(a),[](const P& b,const P& c){ return b.fi-b.se > c.fi-c.se; });
  rep(i,N)D[i+1]=max(0LL,a[i].fi-a[i].se);
  rep(i,N)cin>>C[i+1];
  rep(i,N){
    C[i+1]+=C[i];
    D[i+1]+=D[i];
  }

  repl(i,1,N){
    ll lb=-1,ub=i+1;
    while(ub-lb>1){
      ll X=(lb+ub)/2;
      ll sum=D[i+1]-(D[X+1]-D[X]);
      if(sum>C[i])ub=X;
      else lb=X;
    }
    l[i]=ub;
    if(ub==i+1){
      l[i]=INF;
    }
  }
  l[0]=0;
  rep(i,N)maxch(l[i+1],l[i]);

  ll res=INF;
  rep(i,N){
    ll rest=L-a[i].fi;
    if(rest<=0){
      cout<<1<<endl;
      return 0;
    }
    if(D[i]>=rest){
      ll lb=-1,ub=i;
      while(ub-lb>1){
        ll X=(lb+ub)/2;
        if(D[X]>=rest)ub=X;
        else lb=X;
      }
      if(i<l[ub])continue;
      minch(res,ub+1);
    }else{
      ll lb=i+1,ub=N;
      while(ub-lb>1){
        ll X=(lb+ub)/2;
        if(D[i]+(D[X]-D[i+1])>=rest)ub=X;
        else lb=X;
      }
      if(i<l[ub]||(D[i]+(D[ub]-D[i+1]))<rest)continue;
      minch(res,ub);
    }
  }

  if(res==INF)cout<<-1<<endl;
  else cout<<res<<endl;

  return 0;
}



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

int main(){
  for (int i=0;true;i++){
    int a,b;
    char op;
    cin >> a  >> op >> b;

    if(op == '?') break;
    else if (op == '+'){
      cout << a+b << endl;
    }
    else if (op == '-'){
      cout << a-b << endl;
    }
    else if (op == '*'){
      cout << a*b << endl;
    }
    else {
      cout << a/b << endl;
    }

  }

  return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

int sum[100005];

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

    int n, q;
    string s;
    cin >> n >> q >> s;
    for(int i = 0; i < n-1; ++i){
        if(s[i] == 'A' && s[i+1] == 'C'){
            sum[i+1] = 1;
        }
    }
    for(int i = 0; i < n; ++i){
        sum[i+1] += sum[i];
    }
    for(int i = 0; i < q; ++i){
        int l, r;
        cin >> l >> r;
        --l;
        int res = sum[r] - sum[l];
        if(r < n && s[r-1] == 'A' && s[r] == 'C')   --res;
        cout << res << "\n";
    }
}

Measured memory_bytes: 1488
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int a[][] = new int[n][2];
            int ans[] = new int[n];
            for (int i = 1; i < n; i++) {
                a[i][0] = Integer.parseInt(in.next());
                a[i][1] = 0;
            }

            for (int i = 1; i < n; i++) {
                ans[a[i][0] - 1] += 1;
            }
            // 出力
            for (int i = 0; i < n; i++) {
                out.println(ans[i]);
            }

        }

    }
}



Measured memory_bytes: 67096
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
    
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef _DEBUG
    //freopen("input.txt", "r", stdin);
    #endif
    ll n, x = 0;
    cin >> n;
    for (ll i = 1; i <= n; ++i) {
        for (ll j = 1; j <= n; ++j) {
            ll y = gcd(i, j);
            for (ll k = 1; k <= n; ++k) {
                x += gcd(y, k);
            }
        }
    }
    cout << x << "\n";
    return 0;
}

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

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

  int ans=0;
  char check=S[0];

  rep(i,1,S.size()) {
    if (check!=S[i]) {
      ans++;
      check=S[i];
    }
  }

  cout <<ans <<endl;
  return 0;
}


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

ls = []
k = 1
while True:
    k *= 6
    if k > n:
        break
    ls.append([k, 6])

k = 1
while True:
    k *= 9
    if k > n:
        break
    ls.append([k, 9])
ls.append([1, 1])
ls.sort(key=lambda x: x[0], reverse=True)

res = float('inf')


def dfs(x, count, index):
    global res
    if count > res:
        return
    if index == len(ls):
        if x == 0:
            res = min(res, count)
        return
    k, base = ls[index]
    m = min(x // k, max(base - 1, 5))
    if (m + 1) * k < x:
        return
    for i in range(m, -1, -1):
        dfs(x - i * k, count + i, index + 1)


dfs(n, 0, 0)
print(res)

Measured memory_bytes: 3064
input()
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

m=0
y=-1
for x in A:
    m+=B[x-1]
    if x==y+1:
        m+=C[y-1]
    y=x
print(m)

Measured memory_bytes: 9160
/*** ???????????¨???????????? ***/

#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main(){
	int m;
	
	cin >> m;
	REP(i, 0, m){
		string str;
		cin >> str;
		
		set<string> s;
		REP(j, 1, str.size()){
			string str1, str2, rev_str1, rev_str2;
			str1=str.substr(0, j);
			str2=str.substr(j);
			
			for(int k=str1.size()-1; k>=0; k--) rev_str1 += str1[k];
			for(int k=str2.size()-1; k>=0; k--) rev_str2 += str2[k];
			
			s.insert(str1+str2);
			s.insert(str1+rev_str2);
			s.insert(rev_str1+str2);
			s.insert(rev_str1+rev_str2);
			
			s.insert(str2+str1);
			s.insert(str2+rev_str1);
			s.insert(rev_str2+str1);
			s.insert(rev_str2+rev_str1);
		}
		
		cout << s.size() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;

int main() {
	for(int N; cin >> N, N; ) {
		static int field[1000][1000];
		memset(field, 0, sizeof field);

		for(int i = 0; i < N; i++) {
			string s;
			cin >> s;
			for(int j = 0; j < (int)s.length(); j++)
				field[i][j] = (s[j] == '.' ? 1 : 0);
		}

		static int dp[1000 + 1][1000 + 1];
		memset(dp, 0, sizeof dp);

		dp[1][1] = field[0][0];
		for(int i = 2; i <= N; i++) {
			dp[1][i] = field[0][i - 1] + dp[1][i - 1];
			dp[i][1] = field[i - 1][0] + dp[i - 1][1];
		}

		for(int i = 2; i <= N; i++)
			for(int j = 2; j <= N; j++)
				dp[i][j] = field[i - 1][j - 1] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];

		int maxv = 0;
		for(int k = 1; k <= N; k++) {
			bool f = false;
			for(int i = k; i <= N; i++) {
				for(int j = k; j <= N; j++) {
					if(dp[i][j] - dp[i - k][j] - dp[i][j - k] + dp[i - k][j - k] == k * k) {
						f = true;
						break;
					}
				}
				if(f) break;
			}
			if(f)	maxv = k;
			else	break;
		}
		cout << maxv << endl;
	}
}

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

int main(){
	int n, x, m[100];
	cin >> n >> x;
	for(int i = 0;i < n;i++){
		cin >> m[i];
		x -= m[i];
	}

	sort(m, m + n);
	int ans = n + x / m[0];
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::max;
#[allow(unused_imports)]
use std::fmt;
#[allow(unused_imports)]
use std::fmt::Debug;
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::str::FromStr;

fn main() {
    let n: usize = get_vec_input()[0];
    let mut answer = get_digit(n as i64);

    for a in 2..((n as f64).sqrt() as usize) + 1 {
        if n % a != 0 {
            continue;
        }
        let b = n / a;
        let current: i64;
        if a >= b {
            current = get_digit(a as i64);
        } else {
            current = get_digit(b as i64);
        }
        update_min(&mut answer, current);
    }

    println!("{}", answer);
}

#[allow(dead_code)]
fn get_digit(value: i64) -> i64 {
    let mut digit = 0i64;
    let mut value = value;
    while value != 0 {
        value /= 10;
        digit += 1;
    }
    digit
}

#[allow(dead_code)]
fn sum_digit2(value: String) -> u32 {
    return value.chars().fold(0u32, |a, b| a + b.to_digit(10).unwrap());
}

#[allow(dead_code)]
fn sum_digit(value: i64) -> i64 {
    if value < 10 {
        return value;
    }
    return sum_digit(value / 10) + value % 10;
}

#[allow(dead_code)]
fn update_max<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left < right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn update_min<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left > right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn get_vec_input<T>() -> Vec<T>
where
    T: FromStr,
    T::Err: Debug,
{
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");
    let vec: Vec<T> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    vec
}

#[allow(dead_code)]
fn get_tuple_input() -> (u64, f32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c: u64 = iter.next().unwrap().parse().unwrap();
    let n: f32 = iter.next().unwrap().parse().unwrap();
    (c, n)
}

#[allow(dead_code)]
fn get_string_input() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    s.trim().to_string()
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main(){
  char w[10],t[1000],end[12]="END_OF_TEXT";
  int count=0,size,i;

  scanf("%s",w);
  while(scanf("%s",t) == 1){
    if(strcmp(t,end) == 0) break;
    size = strlen(t);
    for(i=0;i<size;i++){
      if('A' <=t[i] && t[i] <= 'Z') t[i] += 32;
    }
    if(strcmp(t,w) == 0) count++;
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2128
#include <stdio.h>

int main(void){
	int n;
	char str[50];
	int count=0;int flag, i;
	scanf("%d%*c%s", &n, str);
	
	flag=0;
	for(i=0; i< n; i++){
		if(str[i]=='A'){
			flag=1;
		}else if (flag==1 && str[i]=='B'){
			flag=2;
		}else if (flag==2 && str[i]=='C'){
			count += 1;
			flag=0;
		}else{
			flag=0;
		}
		
	}
	
	
	printf("%d", count);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  multiset<int> ans;
  rep(i, N)
  {
    int A;
    cin >> A;
    if (i == 0)
      ans.insert(A);
    else if (*ans.begin() >= A)
      ans.insert(A);
    else
    {
      auto it = ans.lower_bound(A);
      it--;
      ans.erase(it);
      ans.insert(A);
    }
  }
  cout << ans.size() << endl;
  return 0;
}

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

#define IS_EVEN(a) ( ((a)&0x01) == 0 )

int cmp(const void *a, const void *b) {
    return (*(const int*)b)-(*(const int*)a);
}

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

    int a,b,c;
    int a_max,b_max,c_max;
    //a+b+c=n
    //10000*a + 5000*b + 1000*c = y

    a_max = y/10000;
    b_max = y/5000;
    c_max = y/1000;
    for(int i = 0 ; i <= n ; i++) {
        for(int j = 0 ; j <= n-i ; j++) {
            for(int k = 0 ; k <= n-i-j ; k++) {
                if( i*10000+j*5000+k*1000 == y && i+j+k == n) {
                    cout << i << " " << j << " " << k << endl;
                    goto end;
                }
            }
        }
    }
    cout << "-1 -1 -1" << endl;
end:
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;
int main(){
    int N,M,sum,cnt=0;
    cin >> N >> M ;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    sum = accumulate(A.begin(),A.end(),0);
    for(vector<int>::const_iterator itr=A.begin();itr!=A.end();itr++){
        if(*itr >= sum/(4*double(M))){
            cnt++;
        }
    }
    if(cnt >= M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
"""
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
int main()
{
    long N;
    std::cin >> N;
    std::string S;
    std::cin >> S;
    long count=0;
    std::vector<long> counters;
    for(long i=1; i<N; i++){
        if(S[i]=='E'){
            count++;
        }
    }
    counters.push_back(count);
    for(long i=1; i<N; i++){
        if(S[i]=='E'){
            count-=1;
        }
        if(S[i-1]=='W'){
            count++;
        }
        counters.push_back(count);
    }
    std::sort(counters.begin(),counters.end());
    std::cout << counters[0] << std::endl;
    return 0;
}
"""
n=int(input())
s=input()
cnt=0
for i in range(1,n):
  if s[i]=="E":cnt+=1
ans=[]
ans.append(cnt)
for i in range(1,n):
  if s[i]=="E":
    cnt-=1
  if s[i-1]=="W":
    cnt+=1
  ans.append(cnt)
print(min(ans))


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

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

    int n, k; cin >> n >> k;

    vector<int> h(n);
    for(int& x : h) cin >> x;


    vector<int> dp(n, numeric_limits<int>::max());
    dp[n - 1] = 0;

    for(int i = n - 2; i >= 0; --i) {
        for(int j = k; j > 0; --j) {
            if(i + j >= n) continue;
            dp[i] = min(dp[i], dp[i + j] + abs(h[i] - h[i + j]));
        }
    }

    cout << dp[0] << '\n';
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next,cap;
}E[MAXN];
int sumE = 1,head[MAXN];
int H,W,Ncnt,S,T;
char s[105][105];
void add(int u,int v,int c) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    E[sumE].cap = c;
    head[u] = sumE;
}
void addtwo(int u,int v,int c) {
    add(u,v,c);add(v,u,0);
}
int gap[MAXN],dis[MAXN];
int isap(int u,int aug) {
    if(u == T) return aug;
    int flow = 0;
    for(int i = head[u] ; i ;i = E[i].next) {
	int v = E[i].to;
	if(E[i].cap) {
	    if(dis[v] + 1 == dis[u]) {
		
		int t = isap(v,min(aug - flow,E[i].cap));
		flow += t;
		E[i].cap -= t;
		E[i ^ 1].cap += t;
		if(aug == flow) return flow;
		if(dis[S] >= Ncnt) return flow;
	    }
	} 
    }
   
    --gap[dis[u]];
    if(!gap[dis[u]]) {dis[S] = Ncnt;return flow;}
    dis[u]++;
    ++gap[dis[u]];
    return flow;
}
void Solve() {
    read(H);read(W);
    for(int i = 1 ; i <= H ; ++i) {
	scanf("%s",s[i] + 1);
    }
    Ncnt = H + W;
    pii p[2];
    for(int i = 1 ; i <= H ; ++i) {
	for(int j = 1 ; j <= W ; ++j) {
	    if(s[i][j] != '.') {
		++Ncnt;
		int t = 0;
		if(s[i][j] == 'o') t = 1;
		else t = 0x7fffffff;
		addtwo(Ncnt,i,t);addtwo(i,Ncnt,t);
		addtwo(j + H,Ncnt,t);addtwo(Ncnt,j + H,t);
		if(s[i][j] == 'S') {p[0] = mp(i,j);S = Ncnt;}
		if(s[i][j] == 'T') {p[1] = mp(i,j);T = Ncnt;}
	    }
	}
    }
    if(p[0].fi == p[1].fi || p[0].se == p[1].se) {puts("-1");return;}
    int ans = 0;
    while(dis[S] < Ncnt) ans += isap(S,0x7fffffff);
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> card(N);

    for (int i = 0; i < N; i++)
    {
        cin >> card.at(i);
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            if (card.at(i) < card.at(j))
            {
                int a;
                a = card.at(i);
                card.at(i) = card.at(j);
                card.at(j) = a;
            }
        }
    }

    int A, B;
    A = 0;
    B = 0;

    for (int i = 0; i < N; i += 2)
    {
        A += card.at(i);
    }
    for (int i = 1; i < N; i += 2)
    {
        B += card.at(i);
    }

    cout << A - B << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <iomanip>
#include <algorithm>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

typedef long long ll;

const int Maxn = 100005;
const int Maxm = 16;

int n;
int my[Maxn];
int got[1 << Maxm];
int cnt[1 << Maxm];
ll res;

void Gen(int lvl, int mask1, int mask2, int cand)
{
	if (lvl >= Maxm) {
		if (mask2 && cand == 0)
			got[mask1] = min(got[mask1], got[mask1 ^ mask2] + __builtin_popcount(mask2) - 1);
	} else {
		Gen(lvl + 1, mask1, mask2, cand);
		Gen(lvl + 1, mask1 | (1 << lvl), mask2, cand);
		Gen(lvl + 1, mask1 | (1 << lvl), mask2 | (1 << lvl), (cand ^ lvl));
	}
}

int main()
{
	fill(got, got + (1 << Maxm), Maxn);
	got[0] = 0;
	Gen(1, 0, 0, 0);
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int a, b, c; scanf("%d %d %d", &a, &b, &c);
		my[a] ^= c; my[b] ^= c;
	}
	for (int i = 0; i < n; i++)
		if (my[i] != 0) cnt[my[i]]++;
	int lft = 0;
	for (int i = 0; i < 1 << Maxm; i++) {
		res += cnt[i] / 2;
		if (cnt[i] % 2) lft |= 1 << i;
	}
	res += got[lft];
	cout << res << endl;
	return 0;
}

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

const int INF = 1e9+10;


int a[310][310];
int b[310], f[310];
int now[310];

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i=1; i<=n; ++i) {
		for (int j=1; j<=m; ++j) {
			scanf("%d", &a[i][j]);
		}
		b[a[i][1]] ++;
		now[i] = 1;
	}

	memset(f, 0, sizeof f);
	int ans = n;
	int fuck = m;
	while (fuck > 0) {
		int tmp = 0;
		int tmpi = 0;
		for (int i=1; i<=m; ++i) {
			if (tmp < b[i]) {
				tmpi = i;
				tmp = b[i];
			}
		}

		f[tmpi] = 1;
		ans = min(ans, tmp);

		for (int i=1; i<=n; ++i) {
			b[a[i][now[i]]]--;
			while (f[a[i][now[i]]]) now[i]++;
			b[a[i][now[i]]]++;
		}

		fuck--;
	}

	printf("%d\n", ans);

	return 0;
}

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

using namespace std;

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

    int a;
    string s;
    cin>>a>>s;
    if(a>=3200)cout<<s<<endl;
    else cout<<"red\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007
using namespace std;


int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll i,j,k,n,m;
     ll t;
     ll a,b,c,d;
     cin>>a>>b>>c>>d;
     while(a>0 && c>0)
     {
         c=c-b;
         if(c<=0)
         {
             cout<<"Yes";
             return 0;
         }
         a=a-d;
         if(a<=0)
         {
             cout<<"No";
             return 0;
         }
     }
}  


Measured memory_bytes: 3648
n,m=map(int,input().split())
a_list=[]
for i in range(n):
    a_list.append([s for s in input()])
b_list=[]
for i in range(m):
    b_list.append([s for s in input()])

# 基準を全探索
for row in range(n-m+1):
    for col in range(n-m+1):
        # 一致チェック
        blnOK=True
        for m_row in range(m):
            for m_col in range(m):
                if a_list[row+m_row][col+m_col]!=b_list[m_row][m_col]:
                    blnOK=False
                    break
            if not blnOK:
                break
        if blnOK:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	int t[n];
	for (int i = 0; i < n; i++) {
		scanf("%d", &t[i]);
	}
	int m;
	scanf("%d", &m);
	int p[m], x[m];
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &p[i], &x[i]);
	
	}
	ll ans[m];
	for (int i = 0; i < m; i++) {
		ans[i] = 0;
	}
	
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			ans[i] += t[j];
		}
		int tmp = x[i] - t[p[i] -1];
		ans[i] += tmp;
	}
	
	for (int i = 0; i < m; i++) {
		cout << ans[i] << endl;
	}
	
	return 0;
}

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

int main()
{
    int k;
    int n;
    cin >> k >> n;
    int a[n];
    rep(i, n)
    {
        cin >> a[i];
    }
    vector<int> b(n);
    rep(i, n - 1)
    {
        b[i]=(a[i + 1] - a[i]);
    }
    b[n-1] = (a[0] + k - a[n - 1]);
    int ans = k - *std::max_element(b.begin(), b.end());
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;

signed main() {
    ll n;
    cin >> n;
    
    ll r = 0;
    
    vll a(n), b(n);
    
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    
    drep(i, n) {
        a[i] += r;
        r += (b[i] - (a[i] % b[i])) % b[i];
    }
    
    
    mes(r);
    
    
    

}
    
    
    
    
    


Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int MAX_N=1<<20;
int N;
vector<P> dat(2*MAX_N-1);
void rmq_init(int n_){
    N=1;
    while(N<n_) N*=2;
    rep(i,2*N-1) dat[i]=P(INT_MAX,-1);
}
void update(int k,int a){
    int index=k;
    k+=N-1;
    dat[k]=P(a,index);
    while(k>0){
        k=(k-1)/2;
        dat[k]=min(dat[2*k+1],dat[2*k+2]);
    }
}
P subquery(int a,int b,int k=0,int l=0,int r=N){
    if(r<=a||b<=l) return P(INT_MAX,-1);
    if(a<=l&&r<=b) return dat[k];
    else{
        P vl=subquery(a,b,k*2+1,l,(l+r)/2);
        P vr=subquery(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}
int query(int a,int b){
    return subquery(a,b).second;
}
vec G[200001];
int root,vs[400001],depth[400001],id[200001];
void dfs(int v,int p,int d,int &k){
    id[v]=k;
    vs[k]=v;
    depth[k++]=d;
    rep(i,G[v].size()){
        if(G[v][i]!=p){
            dfs(G[v][i],v,d+1,k);
            vs[k]=v;
            depth[k++]=d;
        }
    }
}
void init(int V){
    int k=0;
    dfs(root,-1,0,k);
    rmq_init(V*2-1);
    rep(i,V*2-1) update(i,depth[i]);
}
int lca(int u,int v){
    return vs[query(min(id[u],id[v]),max(id[u],id[v])+1)];
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    rep(i,n){
        int k,v;
        cin>>k;
        rep(j,k) cin>>v,G[i].push_back(v);
    }
    init(n);
    int q;
    cin>>q;
    rep(i,q){
        int u,v;
        cin>>u>>v;
        cout<<lca(u,v)<<"\n";
    }
}


Measured memory_bytes: 53116
#065-C
n,m=map(int,input().split())
if abs(n-m)>1:
    print(0)
else:
    ans=0
    f=[1 for i in range(max(n,m)+1)]
    for i in range(1,max(n,m)+1):
        f[i]=f[i-1]*i%(10**9+7)
    if m==n:
        ans=2*f[m]*f[n]%(10**9+7)
    else:
        ans=f[m]*f[n]%(10**9+7)
    print(ans)

Measured memory_bytes: 7064
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        int a=gi();
        int b=gi();
        int k=gi();
        int i=Math.max(a, b);
        int c=0;
        while(true) {
        	if (a%i==0 && b%i==0) {
        		c++;
        		if(c==k) {
        			break;
        		}
        	}
        	i--;
        }
      
        
	    System.out.println(i);

//        if (s>L[n-2]) {
//        	System.out.println("Yes");
//        }else {
//        	System.out.println("No");
//        }
	}


	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35640
#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    sort(arr,arr+n);
    ll ans=0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if(arr[i]==arr[j] || arr[j]==arr[k] || arr[k]==arr[i])
                continue;
                if(arr[i]+arr[j]>arr[k])
                ans++;
            }
        }
    }
    cout<<ans;
    
    
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int bubbleSort(int a[],int N);
int main(){
	int a[100],N;
	scanf("%d",&N);
	int i;
	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
		
	}
	int t=bubbleSort(a,N);
	for(i=0;i<N-1;i++){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[N-1]);
	printf("%d\n",t);
	return 0;
} 

int bubbleSort(int a[],int N){
	int i,j,temp,flag=0;
	for(i=0;i<N-1;i++){
		for(j=0;j<N-1-i;j++){
			if(a[j]>a[j+1]){
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
				flag++;
			}
		}
	}
	return flag;
}


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

int main() {
	int h, w;
	while (true) {
		cin >> h >> w;

		if (h == 0 && w == 0) break;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i == 0 || i == h - 1) cout << "#";
				else {
					if (j == 0 || j == w - 1) cout << "#";
					else cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define pb push_back
#define opr iterator
typedef long long ll;
using namespace std;
int dp[105][4][4][4];
#define mod 1000000007
int times=0;
// 0-->A, 1-->G, 2-->C,3-->T
bool pan(int a,int b,int c)
{
	if(a==0&&b==1&&c==2)
	{
		return false;
	}
	if(a==0&&b==2&&c==1)
	{
		return false;
	}
	if(a==1&&b==0&&c==2)
	{
		return false;
	}
	return true;
}
bool pan1(int a,int b,int c)
{
	return !(a==0&&b==1&&c==2);
}
int main()
{
	int n;
	cin>>n;
	for(int p=0;p<4;p++)
	{
		for(int q=0;q<4;q++)
		{
			for(int r=0;r<4;r++)
			{
				if(pan(p,q,r))
				{
					dp[3][p][q][r]=1;
				}
			}
		}
	}
	for(int k=4;k<=n;k++)
	{
		for(int p=0;p<4;p++)
		{
			for(int q=0;q<4;q++)
			{
				for(int r=0;r<4;r++)
				{
					if(pan(p,q,r))
					{
						for(int j=0;j<4;j++)
						{
							if(pan(j,p,q)&&pan1(j,q,r)&&pan1(j,p,r))
							{
//								cout<<p<<" "<<q<<" "<<r<<endl;
								dp[k][p][q][r]+=dp[k-1][j][p][q];
								dp[k][p][q][r]%=mod;
							}
							else
							{
								/*cout<<p<<" "<<q<<" "<<r<<" "<<j<<endl;
								cout<<p<<" "<<q<<" "<<j<<endl;
								cout<<p<<" "<<r<<" "<<j<<endl;
								cout<<q<<" "<<r<<" "<<j<<endl;*/
							}
						}
					}
//					cout<<p<<" "<<q<<" "<<r<<endl;
				}
			}
		}
	}
	ll ans=0;
	for(int p=0;p<4;p++)
	{
		for(int q=0;q<4;q++)
		{
			for(int r=0;r<4;r++)
			{
				ans+=dp[n][p][q][r];
				ans%=mod;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

public class MainClass
{
	public const long Giri = 1000000007;

	class ValuePair
	{
		public long Value {get; set;}
		public long Size {get;set;}
	}
	public static void Main(string[] args)
	{
		var p = Input();
		var n = p[0].ToLong();
		var k = p[1].ToLong();
		
		var list = new List<ValuePair>((int)n);
		
		for(int i = 0; i < n; i++)
		{
			p = Input();
			var t = new ValuePair(){Value= p[0].ToLong(), Size=p[1].ToLong()};
			list.Add(t);
		}
		
		list.Sort((a,b) => (int)(a.Value - b.Value));
		long index = 0;
		for(int i = 0; i < n; i++)
		{
			index += list[i].Size;
			if(index >= k)
			{
				Console.WriteLine(list[i].Value);
				return;
			}
		}
	}
	

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



Measured memory_bytes: 20804
n=int(input())
m=n//2*2
ans=[]
for i in range(1,m//2):
  for j in range(1+i,m-i+1):
    ans.append((i,j))
    ans.append((m+1-j,m+1-i))
if n%2:
  for i in range(1,n):
    ans.append((i,n))
print(len(ans))
for i in ans:
  print(*i,sep=" ")

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b,c;
cin >> a >> b >> c;
int ans = a+b;
ans = min(b+c,ans);
ans = min(ans,c+a);
cout << ans << endl;
return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll a,b;
    string s,t,u;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s){
        a--;
    }else{
        b--;
    }
    out2(a,b);
    return  0;
}


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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1e6 + 20;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL MOD)
{
    if(n < 0) a = fp(a, MOD - 2, MOD), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % MOD) if(n & 1) res = res * a % MOD; return res;
}

int n;
LL a[maxn], b[maxn];
LL c[maxn];


void work()
{
    read(n);
    for(int i = 0; i < n; i++) read(a[i]);
    for(int i = 0; i < n; i++) read(b[i]);

    LL ans = 0;
    for(int i = 0; i < 30; i++)
    {
        LL mask = (1LL << (i + 1)) - 1;
        for(int j = 0; j < n; j++) c[j] = a[j] & mask;
        sort(c, c + n);
        LL cnt = 0;

        for(int j = 0; j < n; j++)
        {
            LL v = b[j] & mask;

            cnt += lower_bound(c, c + n, (1LL << i) * 2 - v) - lower_bound(c, c + n, (1LL << i) - v);
            cnt += lower_bound(c, c + n, (1LL << i) * 4 - v) - lower_bound(c, c + n, (1LL << i) * 3 - v);
        }

        ans += (cnt & 1) * (1LL << i);
    }

    cout <<ans <<endl;
}

int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
//    pre();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


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

int n,a,f=1;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {
		scanf("%d",&a);
		if(a%2) continue;
		if(a%3!=0&&a%5!=0) f=0;
	}
	printf(f==1?"APPROVED":"DENIED");
}

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();
    sc.close();
    String s = "";
    for(int i = 0; i < k; i++){
      s += "ACL";
    }
    System.out.println(s);
  }
}

Measured memory_bytes: 38640
import Data.Functor

main = do
  n <- getRows <$> getContents
  mapM_ print $ map (\x -> length $ takeWhile (<= x) primes) n


getRows s = map (read :: (String -> Int)) $ lines s

primes :: Integral int => [int]
primes = wheelSieve 6

wheelSieve :: Integral int
           => Int
           -> [int]
wheelSieve k = reverse ps ++ map head (sieve p (cycle ns))
 where (p:ps,ns) = wheel k
isPrime :: Integral int => int -> Bool
isPrime n | n > 1     = primeFactors n == [n]
          | otherwise = False

primeFactors :: Integral int => int -> [int]
primeFactors n = factors n (wheelSieve 6)
 where
  factors 1 _                  = []
  factors m (p:ps) | m < p*p   = [m]
                   | r == 0    = p : factors q (p:ps)
                   | otherwise = factors m ps
   where (q,r) = quotRem m p
sieve :: (Ord int, Num int) => int -> [int] -> [[int]]
sieve p ns@(m:ms) = spin p ns : sieveComps (p+m) ms (composites p ns)
type Composites int = (Queue int,[[int]])
composites :: (Ord int, Num int) => int -> [int] -> Composites int
composites p ns = (Empty, map comps (spin p ns : sieve p ns))
 where comps xs@(x:_) = map (x*) xs
splitComposites :: Ord int => Composites int -> (int,Composites int)
splitComposites (Empty, xs:xss) = splitComposites (Fork xs [], xss)
splitComposites (queue, xss@((x:xs):yss))
  | x < z     = (x, discard x (enqueue xs queue, yss))
  | otherwise = (z, discard z (enqueue zs queue', xss))
 where (z:zs,queue') = dequeue queue
discard :: Ord int => int -> Composites int -> Composites int
discard n ns | n == m    = discard n ms
             | otherwise = ns
 where (m,ms) = splitComposites ns
sieveComps :: (Ord int, Num int) => int -> [int] -> Composites int -> [[int]]
sieveComps cand ns@(m:ms) xs
  | cand == comp = sieveComps (cand+m) ms ys
  | cand <  comp = spin cand ns : sieveComps (cand+m) ms xs
  | otherwise    = sieveComps cand ns ys
 where (comp,ys) = splitComposites xs
spin :: Num int => int -> [int] -> [int]
spin x (y:ys) = x : spin (x+y) ys
type Wheel int = ([int],[int])
wheel :: Integral int => Int -> Wheel int
wheel n = iterate next ([2],[1]) !! n
next :: Integral int => Wheel int -> Wheel int
next (ps@(p:_),xs) = (py:ps,cancel (product ps) p py ys)
 where (y:ys) = cycle xs
       py = p + y
cancel :: Integral int => int -> int -> int -> [int] -> [int]
cancel 0 _ _ _ = []
cancel m p n (x:ys@(y:zs))
  | nx `mod` p > 0 = x : cancel (m-x) p nx ys
  | otherwise      = cancel m p n (x+y:zs)
 where nx = n + x
data Queue int = Empty | Fork [int] [Queue int]

enqueue :: Ord int => [int] -> Queue int -> Queue int
enqueue ns = merge (Fork ns [])
merge :: Ord int => Queue int -> Queue int -> Queue int
merge Empty y                        = y
merge x     Empty                    = x
merge x     y     | prio x <= prio y = join x y
                  | otherwise        = join y x
 where prio (Fork (n:_) _) = n
       join (Fork ns qs) q = Fork ns (q:qs)
dequeue :: Ord int => Queue int -> ([int], Queue int)
dequeue (Fork ns qs) = (ns,mergeAll qs)
mergeAll :: Ord int => [Queue int] -> Queue int
mergeAll []       = Empty
mergeAll [x]      = x
mergeAll (x:y:qs) = merge (merge x y) (mergeAll qs)

Measured memory_bytes: 5316
class LowLink:
    def __init__(self, v):
        self.size = len(v)
        self.v = v
        self.pre = [None]*self.size
        self.low = [None]*self.size
        self.articulation = []
        self.bridge = []
        for x in range(self.size):
            if self.pre[x] is None:
                self.cnt = 0
                self.dfs(x,None)

    def dfs(self, x, par):
        self.pre[x] = self.low[x] = self.cnt
        self.cnt += 1
        is_articulation = False
        n = 0
        for y in self.v[x]:
            if self.pre[y] is None:
                n += 1
                lowy = self.dfs(y, x)
                if lowy < self.low[x]:
                    self.low[x] = lowy
                if self.pre[x] <= lowy:
                    if self.pre[x]:
                        is_articulation = True
                    if self.pre[x] < lowy:
                        self.bridge.append((x,y))
            else:
                if par != y and self.pre[y] < self.low[x]:
                    self.low[x] = self.pre[y]

        if par is None and n > 1:
            is_articulation = True

        if is_articulation:
            self.articulation.append(x)

        return self.low[x]


n,m = map(int, input().split())
v = [[] for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
ans = LowLink(v)
print(len(ans.bridge))

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
char a(char x){
if(x=='1')cout<<'9';
else cout<<'1';
}
int main(){
  char c[3]; cin>>c; 
  rep(i,3)a(c[i]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main() {
	int n;
	ll ans = 0,in;
	cin >> n;
	rep(i, n) {
		cin >> in;
		ans += in;
		ans--;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define tms(x) ___ = x; while(___--)
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; rep(i, 0, l) cout<<' '<<i<<':'<<*(x+i)<<endl;
#define pb push_back
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int ___;
vector<pii> v;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, y, a, b, c, redPick, greenPick, nonePick, ans;
	redPick = greenPick = nonePick = ans = 0;
	cin>>x>>y>>a>>b>>c;
	rep(i, 0, a) v.pb(pii(next<int>(), 1));
	rep(i, 0, b) v.pb(pii(next<int>(), 2));
	rep(i, 0, c) v.pb(pii(next<int>(), 3));
	sort(v.begin(), v.end());
	for(int i = v.size()-1; i >= 0; i--)
	{
		if (redPick+greenPick+nonePick == x+y) break;
		if (v[i].second == 1 && redPick < x) redPick++, ans += v[i].first;
		else if (v[i].second == 2 && greenPick < y) greenPick++, ans += v[i].first;
		else if (v[i].second == 3) nonePick++, ans += v[i].first;
	}
	cout<<ans<<endl;
	return ~~(0-0);
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}


Measured memory_bytes: 10092