akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    int mi = INT32_MAX;
    rep(i,N) {
        cin >> H.at(i);
        mi = min(mi, H[i]);
    }
    int step = 0;
    while (mi > 0) {
        rep(i,N) H[i]--;
        mi--;
        step++;
    }

    while (true) {
        int l, r;
        for (l = 0; l < N; l++) {
            if (H[l] > 0) break;
        }
        if (l == N) break;
        for (r = l + 1; r < N; r++) {
            if (H[r] == 0) break;
        }
        r--;
        for (int i = l; i <= r; i++) {
            H[i]--;
        }
        step++;
    }
    cout << step << endl;
}

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


int A, B, M;
vector<int> a, b, c, x, y;


void solve()
{
    int minA = 1e6;
    int minB = 1e6;
    for (int i = 1; i <= A; i++) minA = min(minA, a[i]);
    for (int i = 1; i <= B; i++) minB = min(minB, b[i]);
    int ans = minA + minB;
    for (int i = 1; i <= M; i++) {
        int cost = a[x[i]] + b[y[i]] - c[i];
        ans = min(ans, cost);
    }
    cout << ans << endl;
}


int main()
{
    cin >> A >> B >> M;
    a.resize(A + 1);
    for (int i = 1; i <= A; i++) cin >> a[i];
    b.resize(B + 1);
    for (int i = 1; i <= B; i++) cin >> b[i];
    x.resize(M + 1);
    y.resize(M + 1);
    c.resize(M + 1);
    for (int i = 1; i <= M; i++) cin >> x[i] >> y[i] >> c[i];
    solve();
    return 0;
}


Measured memory_bytes: 2176
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let o = read::<String>();
  let e = read::<String>();

  let o_vec: Vec<char> = o.chars().collect();
  let e_vec: Vec<char> = e.chars().collect();

  let o_len = o_vec.len();
  let e_len = e_vec.len();

  let mut ans = String::from("");

  for i in 0..min(o_len, e_len) {
    ans.push(o_vec[i]);
    ans.push(e_vec[i]);
  }

  if e_len < o_len {
    ans.push(o_vec[o_len as usize - 1]);
  }

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

Measured memory_bytes: 4352
#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 100005
//#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);
}
int H,W;
string s;
void Solve() {
    read(H);read(W);
    for(int i = 1 ; i <= H ; ++i) {
	for(int j = 1 ; j <= W ; ++j) {
	    cin >> s;
	    if(s == "snuke") {
		putchar('A' + j - 1);
		out(i);enter;return;
	    }
	}
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  Int x=k*2-1;
  cout<<(x<=n?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int N;
P s[100];
P t[100];
bool ss[100];
bool tt[100];

int main(){
    cin>>N;
    rep(i,N) cin>>s[i].second>>s[i].first;
    rep(i,N) cin>>t[i].first>>t[i].second;

    sort(s,s+N);
    sort(t,t+N);

    int ans=0;
    rep(i,N){
        int c=t[i].first;
        int d=t[i].second;
        rep(j,N){
            int a=s[N-j-1].second;
            int b=s[N-j-1].first;
            if(a<c && b<d && !tt[i] && !ss[N-j-1]){
                ans++;
                tt[i]=true;
                ss[N-j-1]=true;
                //cout<<"("<<a<<","<<b<<") ("<<c<<","<<d<<")"<<endl;
                break;
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
using namespace std;
double dp[100][5000];
int n, m, K, p[100], q[100], d[100], a, b, c;
int main() {
	while (true) {
		for (int i = 0; i < 100; i++) {
			p[i] = 0; q[i] = 0;
			for (int j = 0; j < 5000; j++)dp[i][j] = 0;
		}
		cin >> n >> m >> K; if (n == 0)break;
		for (int i = 0; i < n; i++)cin >> d[i];
		for (int i = 0; i < K; i++) {
			cin >> a >> b >> c; p[a] = b; q[a] = c;
		}
		dp[0][0] = 1;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < 5000; j++) {
				if (dp[i][j] == 0.0)continue;
				for (int k = 0; k < n; k++) {
					int to = i + d[k]; if (to >= m)to = m;
					if (p[to] == 0)dp[to][j] += dp[i][j] / n;
					if (p[to] == 1)dp[min(to + q[to], m)][j] += dp[i][j] / n;
					if (p[to] == 2)dp[to][j + q[to]] += dp[i][j] / n;
					if (p[to] == 3)dp[to][max(j - q[to], 0)] += dp[i][j] / n;
				}
			}
		}
		double res = 0;
		for (int i = 0; i < 5000; i++)res += i*dp[m][i];
		cout << (int)res << endl;
	}
	return 0;
}

Measured memory_bytes: 5064
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 1024;

int main(void) {
	// in = fopen("A.in", "rt");
	
	int k;
	int h1, m1, h2, m2;
	fscanf(in, "%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
	int diff = (h2 - h1) * 60 + (m2 - m1);
	fprintf(out, "%d\n", diff - k);
	
	return 0;
}

Measured memory_bytes: 1732
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce, lru_cache
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

n = INT()
a = LIST()
b = 0

ans = 0
for i in range(n-2, -1, -1):
    b += a[i+1]
    b %= (pow(10,9)+7) 
    ans += a[i]*b % (pow(10,9)+7)
    ans %= (pow(10,9)+7)

print(ans)

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

long long p[200010][2];
long long r[200010][2];
long long R(long long x,long long f)
{
	return p[x][f]==x?x:p[x][f]=R(p[x][f],f);
}

void unite(long long x,long long y,long long f)
{
	x=R(x, f);
	y=R(y, f);
	if(x==y)
		return;
	if(r[x][f]<r[y][f])
		p[x][f]=y;
	else
	{
		p[y][f]=x;
		if(r[x][f]==r[y][f])
			r[x][f]++;
	}
}

int main()
{
	long long n,k,l,x,y;
	cin>>n>>k>>l;
	
	for(int i=1;i<=n;i++)
		p[i][0]=p[i][1]=i;
	
	for (int i=0;i<k;i++)
	{
		cin>>x>>y;
		unite(x,y,0);
	}
	
	for(int i=0;i<l;i++)
	{
		cin>>x>>y;
		unite(x,y,1);
	}
	
	map<pair<long long,long long>,long long> mp;
	
	long long a,b;
	
	for(int i=1;i<=n;i++)
	{
		a=R(i,0);
		b=R(i,1);
		mp[make_pair(a,b)]++;
	}
	
	for(int i=1;i<=n;i++)
	{
		a=R(i,0);
		b=R(i,1);
		cout<<mp[make_pair(a, b)];
		if (i==n)
			cout<<endl;
		else
			cout<<' ';
	}
	
	return 0;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

int r(){int x;cin>>x;return x;}


void solve() 
{
    int n;cin>>n;
    ll a[n];REP(i,n)cin>>a[i];
    ll ans=0;
    REP(i,60){
        ll num=0;
        REP(j,n)if(a[j]>>i&1)num++;
        num=num*(n-num)%mod;
        REP(j,i)num=num*2%mod;
        ans+=num;
        ans%=mod;
    }
    cout<<ans<<endl;
}

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


Measured memory_bytes: 2560
package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Scan()
	//n, _ := strconv.Atoi(s.Text())
	s.Scan()
	m, _ := strconv.Atoi(s.Text())

	l := make([]int, m)
	r := make([]int, m)
	var min, max int
	max = 0
	min = 100000
	for i := 0; i < m; i++ {
		s.Scan()
		l[i], _ = strconv.Atoi(s.Text())
		if l[i] > max {
			max = l[i]
		}
		s.Scan()
		r[i], _ = strconv.Atoi(s.Text())
		if r[i] < min {
			min = r[i]
		}
	}

	if min >= max {
		fmt.Println(min - max + 1)
	} else {
		fmt.Println(0)
	}

}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c)
#define Scs(s) scanf("%s", s)
#define Scstr(s) scanf("%s", &s)
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

  int N;
  Scd(N);
  vi a(256);
  char s[123];
  Rep(i,N) Scs(s), a[s[0]]++;
  
  printf("AC x %d\n", a['A'] );
  printf("WA x %d\n", a['W'] );
  printf("TLE x %d\n", a['T'] );
  printf("RE x %d\n", a['R'] );
  
  return 0;
  
}


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

int main()
{
  int x, y, size;
  int canvas[10][10];
  int emp, max;
  char comma;
  int i, j;

  for(i=0; i<10; i++){
    for(j=0; j<10; j++) canvas[i][j]=0;
  }
  while(cin >> x >> comma >> y >> comma >> size){
    canvas[x][y]++;
    if(x>0) canvas[x-1][y]++;
    if(x<9) canvas[x+1][y]++;
    if(y>0) canvas[x][y-1]++;
    if(y<9) canvas[x][y+1]++;
    if(size>1){
      for(i=-1; i<=1; i+=2){
        for(j=-1; j<=1; j+=2){
          if(x+i>=0 && x+i<=9 && y+j>=0 && y+j<=9) canvas[x+i][y+j]++;
        }
      }
    }
    if(size>2){
      if(x>1) canvas[x-2][y]++;
      if(x<8) canvas[x+2][y]++;
      if(y>1) canvas[x][y-2]++;
      if(y<8) canvas[x][y+2]++;
    }
  }
  emp=0; max=0;
  for(i=0; i<10; i++){
    for(j=0; j<10; j++){
      if(canvas[i][j]==0) emp++;
      if(max<canvas[i][j]) max=canvas[i][j];
    }
  }
  printf("%d\n%d\n", emp, max);

  return 0;
}

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


int main(){

    int D;
    cin >> D;

    if (D == 22) {
        cout << "Christmas Eve Eve Eve" << endl;
    }
    else if (D == 23) {
        cout << "Christmas Eve Eve" << endl;
    }
    else if (D == 24) {
        cout << "Christmas Eve" << endl;
    }
    else if (D == 25) {
        cout << "Christmas" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NUM 100


int main(){
  int i,n,count=0,flag,hoji;
  int a[NUM];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  flag=1;
  while(flag>0){
    flag=0;
    for(i=n-1;i>=1;i--){
      if(a[i]<a[i-1]){
	hoji=a[i];
	a[i]=a[i-1];
	a[i-1]=hoji;
	count++;
	flag=1;
      }
    }
  }


  for(i=0;i<n;i++){
    if(i!=n && i!=0){
      printf(" ");
    }
    printf("%d",a[i]);
  }

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

  return 0;
}




Measured memory_bytes: 2140
#define DEBUG(...)
/*                        Strip me down and go to town                        */
/*                          Lick me over upside down                          */
/*                     Pound and pound and pound and pound                    */
/*                        Baby make me make that sound                        */
/*                Aaah, aaah, aaah, aaah, aaaaaaaaaaaaaaaaaah!                */
#include<stdio.h>

typedef long long int LL;

const LL MOD = 1000000007;

LL fac[4005];
LL ifac[4005];

LL fexpo(LL base, int p) {
  LL ret = 1;
  while (p) {
    if (p % 2) {
      ret = ret * base % MOD;
    }
    base = base * base % MOD;
    p /= 2;
  }
  return ret;
}

LL comb(int a, int b) {
  if (a < b) return 0;
  return (fac[a] * ifac[b] % MOD) * ifac[a - b] % MOD;
}

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  fac[0] = 1;
  ifac[0] = 1;
  for (int i = 1; i < 4005; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    ifac[i] = fexpo(fac[i], MOD - 2);
  }
  for (int i = 1; i <= k; i++) {
    LL red = comb(n - k + 1, i);
    LL blue = comb(k - 1, i - 1);
    DEBUG(printf("%lld %lld\n", red, blue);)
    printf("%lld\n", red * blue % MOD);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j), ED = (k); i <= ED; ++i)
#define Rep(i, j, k) for(R int i = (j), ED = (k); i >= ED; --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 200011;
const ll INF = 5e16;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread (buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	ll n;
	
	struct Node {
		ll Cost, End;
	} K[N];
	
	inline bool cmp ( Node a, Node b ) {
		return a.End == b.End? a.Cost < b.Cost: a.End < b.End;
	}
	
	int main() {
		ll T = -1;
		n = read();
		For ( i, 1, n ) 
			K[i] = (Node) {read(), read()};
		sort(K + 1, K + n + 1, cmp);
		For ( i, 1, n ) 
			if ((T += K[i].Cost) >= K[i].End) return puts("No"), 0;
		return puts("Yes"), 0;
	}
	
}

int main()
{
	return Cesare::main();
}

/*

*/






Measured memory_bytes: 3328
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
int flag[N];
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, x;
	cin >> n;
	int maxv = 0;
	MEM(flag, 0);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		maxv = max(maxv, a[i]);
	}
	for (int i = 0; i < n; i++)
	{
		if (!flag[a[i]]) flag[a[i]] = 1;
		else if (!flag[maxv - a[i]]) flag[maxv - a[i]] = 1;
		else
		{
			int key = 0;
			for (int j = 0; j <= maxv; j++)
			{
				if (max(j + 1, maxv - j + 1) == a[i]) key = 1;
			}
			if (key == 0)
			{
				puts("Impossible");
				return 0;
			}
		}
	}
	for (int i = 0; i <= maxv; i++)
	{
		if (!flag[i])
		{
			puts("Impossible");
			return 0;
		}
	}
	puts("Possible");
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int>a(N);
	int ans = 0;
	for (int i = 0;i < N;++i) {
		cin >> a[i];
		ans += a[i];
	}
	for (int i = 0;i < N;i++) {
		int l = 0, r = 0;
		for (int j = 0;j < i;j++)l += a[j];
		for (int j = i;j < N;j++)r += a[j];
		ans = min(ans, abs(l - r));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

sum=0
for i in range(0, n):
    ai = a[i] - 1
    if i != 0:
        if a[i] - a[i-1] == 1:
            sum += b[ai] + c[a[i-1]-1]
        else:
            sum += b[ai]
    else:
        sum += b[ai]

print(sum)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
ll A[MAX_N];


ll dp[45][2];

int main2() {
  int N;
  ll K;
  cin >> N >> K;
  REP(i, N) cin >> A[i];

  const ll INF = 1LL << 61;
  REP(i, 45) REP(j, 2) dp[i][j] = -INF;
  dp[44][0] = 0;

  for (int i = 43; i >= 0; i--) 
    REP(isSmaller, 2) {
      if (dp[i+1][isSmaller] < -INF/2) continue;
      ll B = 1LL << i;
      if (isSmaller || (K >> i & 1)) {
        ll v = 0;
        REP(j, N) v += (A[j] & B) ^ B;
        // cout << i << " " << isSmaller << " " << v << endl;
        chmax(dp[i][isSmaller], dp[i+1][isSmaller] + v);
      }
      {
        ll v = 0;
        REP(j, N) v += (A[j] & B);
        // cout << i << " " << isSmaller << " " << v << endl;
        chmax(dp[i][isSmaller], dp[i+1][isSmaller] + v);
        if (K >> i & 1) chmax(dp[i][1], dp[i+1][isSmaller] + v);
      }
    }
  ll ans = max(dp[0][0], dp[0][1]);
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
char z[11];
int main() {
	int a,b,flag=0;
	cin>>a>>b;
	for (int i=1; i<=a+b+1; i++) {
		cin>>z[i];
		if (i!=a+1) {
			if (z[i]>'9'||z[i]<'0') {
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	if (z[a+1]!='-') {
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

int main() {
    int a,b,c,d,k;
    cin >> a >> b >> c >> d >> k;
    a = a * 60 + b;
    c = c * 60 + d;
    cout << c - a - k << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e: a) cin >> e;
    vector<int> b(n);
    for (auto &e: b) cin >> e;

    vector<pair<int, int>> t(n);
    for (int i = 0; i < n; ++i) {
        t[i].first = b[i];
        t[i].second = a[i];
    }
    sort(t.begin(), t.end());
    for (int i = 0; i < n; ++i) {
        a[i] = t[i].second;
        b[i] = t[i].first;
    }

    vector<int> si(n);
    iota(si.begin(), si.end(), 0);
    sort(si.begin(), si.end(), [&](int l, int r){
        return a[l] < a[r];
    });

    for (int i = 0; i < n; ++i) {
        if (a[si[i]] > b[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    int len = 0;
    int cur = si[0];
    while (cur != 0) {
        cur = si[cur];
        ++len;
    }

    if (len < n-1) {
        cout << "Yes" << endl;
        return 0;
    }

    for (int i = 0; i < n-1; ++i) {
        if (a[si[i+1]] <= b[i]) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 2176
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	long ans;
	foreach (i; 1..N+1)
	{
		if (i * i > N) break;
		ans = i * i;
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

bool dp[90][90][10000];

int main(int argc, char const *argv[]) {
    int h,w; cin>>h>>w;
    vector<vector<int>> a(h, vector<int>(w));
    vector<vector<int>> b(h, vector<int>(w));
    rep(i,h) rep(j,w) cin>>a[i][j];
    rep(i,h) rep(j,w) cin>>b[i][j];
    rep(i,90) rep(j,90) rep(k,10000) dp[i][j][k] = false;
    dp[0][0][abs(a[0][0]-b[0][0])] = true;

    rep(i,h) {
        rep(j,w) {
            if (i==0&&j==0) continue;
            int cost = abs(a[i][j]-b[i][j]);
            if (i-1>=0) {
                rep(k,9000) {
                    dp[i][j][k+cost] |= dp[i-1][j][k];
                    dp[i][j][abs(k-cost)] |= dp[i-1][j][k];
                }
            }
            if (j-1>=0) {
                rep(k,9000) {
                    dp[i][j][k+cost] |= dp[i][j-1][k];
                    dp[i][j][abs(k-cost)] |= dp[i][j-1][k];
                }
            }
        }
    }

    int ans = INF;
    rep(k,10000) if (dp[h-1][w-1][k]) chmin(ans,k);
    cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 79360
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;             \
                                   c > 0 ? i < b : i > b; \
                                   i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x)
#define dumpl(x) dump(x) << endl
#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep))
	{
		v.push_back(buffer);
	}
	return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
	return accumulate(begin, end, 0ll);
}

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

template<typename T>
T bit_count(T N) {
	T cnt = 0;
	while (N) {
		if (N & 1) cnt++;
		N >>= 1;
	}
	return cnt;
}

struct Point {
	int y, x;
	bool operator < (const Point& r) {
		if (x < r.x) return true;
		else return false;
	}
};

class Solver {
public:
	int N;
	int t[MAX], x[MAX], y[MAX];

	bool ok() {
		rep(i, N) {
			int a = abs(x[i] - x[i + 1]);
			int b = abs(y[i] - y[i + 1]);
			int diff1 = a + b;
			int diff2 = t[i + 1] - t[i];
			int diff3 = diff2 - diff1;
			if (diff3 < 0) return false;
			if (diff3 % 2 == 1) return false;
		}
		return true;
	}

	void solve() {
		cin >> N;
		t[0] = 0; 
		x[0] = 0; 
		y[0] = 0;		
		rep2(i, 1, N+1) cin >> t[i] >> x[i] >> y[i];
		cout << (ok() ? "Yes" : "No") << endl;
	}
};

signed main()
{
	srand((unsigned int)time(NULL));
	cout << fixed << setprecision(20);
	auto ptr = new Solver();
	ptr->solve();
	delete ptr;
	//while (true) {
	//	if (cin.eof() == true) break;
	//	auto ptr = new Solver();
	//	ptr->solve();
	//	delete ptr;
	//}
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,i,count = 0;
    int a = 0,b = 0;
    cin >> n;
    for(i = 0;i < n;i++){
        cin >> a >> b;
        count = count + b - a + 1;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}

ll dp[110][110000];


int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    
    ll n, W;
    cin >> n >> W;
    fill_n(*dp, 110*110000, 1LL<<60);
    vector<ll> w(n), v(n);
    rep(i, n) cin >> w[i] >> v[i];

    dp[0][0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= n*1000; ++j){
            dp[i+1][j] = dp[i][j];
            if(j < v[i]) continue;
            dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i]);
        }
    }

    vector<ll> res(dp[n], dp[n]+110000);
    auto itr = find_if(res.rbegin(), res.rend(), [W](ll x){return x <= W;});
    cout << itr.base()-1 - res.begin() << '\n';
    
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  string S;
  string CNT;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == "Y") {
      CNT = "Four";
      break;
    } else {
      CNT = "Three";
    }
  }
  
  cout << CNT << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
int fg(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
signed main(){
  int a;
  cin>>a;
  cout<<a+a*a+a*a*a;
}   

Measured memory_bytes: 3632
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
//use std::collections::HashSet;
use std::cmp::*;
//use std::collections::VecDeque;

fn main() {
    input! {
      mut S:i64
    }
    let mut ans = 999;

    while S >= 100 {
        let a = S % 1000;
        ans = min(ans, (a - 753).abs());
        S = S / 10;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    string S;cin >> S;
    string T;cin >> T;
    int A,B;cin >> A >> B;
    string U;cin >> U;
    if(S == U)A -= 1;
    if(T == U)B -= 1;
    cout << A << " " << B << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.S;
		var n=s.Length;
		var m=sc.I;
		var dp=new int[m+1][][];
		for(int i = 0;i<=m;i++) {
			dp[i]=new int[n+1][];
			for(int j = 0;j<n;j++) {
				dp[i][j]=new int[n+1];
				for(int k = 0;k+j<n;k++) {
					if(j==0){dp[i][j][k]=1;}
					else if(j==1){
						if(s[k]==s[k+j]||i>0){dp[i][j][k]=2;}
						else{dp[i][j][k]=1;}
					}
					else if(s[k]==s[k+j]){dp[i][j][k]=dp[i][j-2][k+1]+2;}
					else{
						dp[i][j][k]=Max(dp[i][j-1][k],dp[i][j-1][k+1]);
						if(i>0){dp[i][j][k]=Max(dp[i][j][k],dp[i-1][j-2][k+1]+2);}
					}
				}
			}
		}
		Console.WriteLine("{0}",dp[m][n-1][0]);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 135644
n=int(input())
F=[]
for i in range(n):
  F.append(list(map(int,input().split())))
P=[]
for i in range(n):
  P.append(list(map(int,input().split())))
maxp=-10**11
for i in range(1,2**10):
  prof=0
  s='{0:b}'.format(i)
  S=[]
  for i in range(len(s)):
    S.append(s[i])
  S.reverse()
  for i in range(10-len(s)):
    S.append('0')
  S.reverse()
  for j in range(n):
    count=0
    for k in range(10):
      count+=int(S[k])*F[j][k]
    prof+=P[j][count]
  maxp=max(maxp,prof)
print(maxp)


Measured memory_bytes: 42332
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
int a[100010],b[100010];
signed main() {
	int n;
	cin >> n;
	int s = 0, d = 0;
	rep(i, n) {
		cin >> a[i];
		s += a[i];
	}
	rep(i, n) {
		cin >> b[i];
		d += b[i];
	}
	int ans1 = 0, ans2 = 0;
	rep(i, n) {
		if (a[i] > b[i])ans1 += a[i] - b[i];
		if (a[i] < b[i])ans2 += (b[i] - a[i] + 1) / 2;
	}
	if (d - s >= ans1 && d - s >= ans2)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

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

constexpr ll mod = 1e9+7;

int main(){
    int N;cin>>N;
    vi T(N),A(N);
    rep(i,N)cin>>T[i]>>A[i];

    ll t=T[0],a=A[0];
    for(int i=1;i<N;i++){
        ll x=T[i],y=A[i];
        if(x>=t and y>=a){
            t=x;
            a=y;
            continue;
        }
        else{
//            while(x<t or y<a){
//                x += T[i];
//                y += A[i];
//            }
            if(x < t){
                ll diff = t-x;
                ll tmp;
                if(diff%T[i]==0) tmp = diff/T[i];
                else tmp = diff/T[i] + 1;

                x = x + tmp * T[i];
                y = y + tmp * A[i];
            }
            if(y<a){
                ll diff=a-y;
                ll tmp;
                if(diff%A[i]==0) tmp = diff/A[i];
                else tmp = diff/A[i] + 1;

                x = x + tmp * T[i];
                y = y + tmp * A[i];
            }

            t=x;
            a=y;
            continue;
        }
    }
    cout << t + a << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;
typedef vector <int> ivector;

int main(void){
	int a, b, i=0;
	string s;
	ivector buf(100);
	char *ends;

	while (cin >> s){
		if (s == "+"){
			b = buf[--i];
			a = buf[--i]; 
			buf[i++] = a + b;
		}else if (s == "-"){
			b = buf[--i];
			a = buf[--i]; 
			buf[i++] = a - b;
		}else if (s == "*"){
			b = buf[--i];
			a = buf[--i]; 
			buf[i++] = a * b;
		}else{
			buf[i++] = atoi(s.c_str());
		}
	}
	cout << buf[i-1]  << endl;
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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 (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int64 n; cin >> n;
		vector<int64> a(n);
		rep (i, n) {
			cin >> a[i];
		}
		int64 ans = 0;
		for (int64 i = 0; i < 60; ++i) {
			int64 cnt = 0;
			rep (j, n) {
				//1の個数をカウントする
				cnt += (a[j] >> i & 1);
			}
			//0の個数を算出
			//(0の個数) * (1の個数)でXORした際に1となる組み合わせ数を計算する
			int64 num = cnt * (n - cnt);
			//2を掛けて2^iでXORした際の格桁の数値を求める
			for (int64 j = 0; j < i; ++j) {
				num = (num * 2) % MOD;
			}
			ans += (num % MOD);
		}
		cout << ans % MOD << endl;
    return;
}

int main() {
    solve();
    return 0;
}



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

using namespace std;

int main()
{

	int n;
	cin >> n;

	vector<int> p;
	int wk;
	for (int i = 0; i < n; i++) {
		cin >> wk;
		p.push_back(wk);

	}

	int count = 0;

	for (int i = 0; i < p.size(); i++) {
	
		if (p[i] != i + 1)count++;

		if (count >= 3)break;



	}


	if (count < 3) {
		cout << "YES" << endl;

	}
	else {
		cout << "NO" << endl;
	}




}


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

using namespace std;

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

  // dp[i][j]: length of the longest common subsequence
  // between s[:i] and t[:j]

  string s, t;
  cin >> s >> t;
  int S = s.size();
  int T = t.size();

  vector<string> dp(T+1);

  int a, b, c;
  for (int i = 1; i <= S; ++i) {
    vector<string> newdp(T+1);
    for (int j = 1; j <= T; ++j) {
      a = dp[j-1].size();
      b = newdp[j-1].size();
      c = dp[j].size();
      if (s[i-1]==t[j-1] && a >= b && a >= c) {
        newdp[j] = dp[j-1] + s[i-1];
      }
      else if (b > c) {
        newdp[j] = newdp[j-1];
      }
      else {
        newdp[j] = dp[j];
      }
    }
    dp = newdp;
  }

  cout << dp[T] << '\n';

  return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    double l; cin >> l;
    cout << (l / 3.0) * (l / 3.0) * (l / 3.0) << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = [int(input()) for _ in range(n)]

score = sum(s)
s.sort()

for i in range(n):
    if score % 10 == 0:
        if not s[i] % 10 == 0:
            score -= s[i]
    else:
        break
ans = score if score % 10 != 0 else 0
print(ans)

Measured memory_bytes: 3060
s = input()
a1 = s[0]
a2 = s[1]
a3 = s[2]
a4 = s[3]
alis = set()
alis.add(a1)
alis.add(a2)
alis.add(a3)
alis.add(a4)
if len(alis) == 2 and ((a1 == a2 and a3 == a4) or (a1 == a3 and a2 == a4) or (a1 == a4 and a2 == a3)):
  print('Yes')
else:
  print('No')

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

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

int main(){
int A[100],N,sw;
cin>>N;
for(int i=0;i<N;i++)cin>>A[i];

sw=bubbleSort(A,N);

for(int i=0;i<N;i++){
if(i)cout<<" ";
cout<<A[i];
}
cout<<endl;
cout<<sw<<endl;

return 0;
}

Measured memory_bytes: 3044
import java.util.Scanner;

public class Main{
	
	static StringBuilder sb = new StringBuilder();

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		sb.append('a');
		
		dfs(1,'1',n);
		
		

	}
	
	static void dfs(int cnt,int now ,int n) {
		
		if(sb.length() == n) {
			System.out.println(sb.toString());
			return;
		}
		boolean flag = false;
		
		for(char i = 'a' ; i <= 'a' + now - '0' ;i++)  {
			if(i == 'a' + now - '0') {
				now++;
				flag = true;
			}
			sb.append(i);
			dfs(cnt ,now , n);
			if(flag) {
				now--;
			}
			sb.deleteCharAt(sb.length()-1);
			
		}
		
	}

}


Measured memory_bytes: 46656