akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <fstream>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <stack>
#include <map>
#include <set>
#if __cplusplus > 199711L
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//	tree<key, mapped = null_type, cmp = less<key>, rb_tree_tag, tree_order_statistics_node_update> name;
//	order_of_key
//	find_by_order
#endif

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fs first
#define sc second
#define abs(a) ((a) < 0 ? -(a) : (a))
#define sqr(a) ((a) * (a))

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

inline pair<pair<bool, bool>, pair<string, bool> > useinout();

void init() {
#ifdef SOL
	if (useinout().fs.fs)
		freopen("input.txt", "r", stdin);
	if (useinout().fs.sc)
		freopen("output.txt", "w", stdout);
#else
	srand(time(0));
	const string file = useinout().sc.fs;
	if (!file.empty()) {
		freopen((file + ".in").c_str(), "r", stdin);
		freopen((file + ".out").c_str(), "w", stdout);
	}
	if(useinout().sc.sc) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
}

int solve();

void finish(int exitval) {
	fflush(stdout);
#ifdef SOL
	fprintf(stderr, "\nexit value: %d\ntime: %.3lf ms\n", exitval, 1000. * clock() / CLOCKS_PER_SEC);
#endif
}

int main() {
	init();
	int exitval = solve();
	finish(exitval);
	return (0);
}

const double eps = 1e-9;
const int mod = (int) 1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;

inline pair<pair<bool, bool>, pair<string, bool> > useinout() {
	return (mp(mp(0, 0), mp("", 0)));
}



int solve() {

	string s = "CODEFESTIVAL2016";
	string t;
	getline(cin, t);
	int cnt = 0;
	for (int i = 0; i < (int) s.length(); i++) {
		if (s[i] != t[i]) {
			cnt++;
		}
	}
	printf("%d\n", cnt);

	return (0);
}

// by Andrey Kim


Measured memory_bytes: 256
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
# Aは長さn,1以上m以下の単調増加整数列

import itertools

n, m, q = map(int, input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q

for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

As = itertools.combinations_with_replacement(range(m), n)


def calc(A):
    ans = 0
    for i in range(q):
        if (A[b[i]-1] - A[a[i]-1] == c[i]):
            ans += d[i]
    return ans


print(max([calc(A) for A in As]))


Measured memory_bytes: 12572
#include <stdio.h>
int main(void){
    int n,i,cnt=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    for(i=0;i<n;i++){
        if(a[i]!=i+1) cnt++;
    }
    if(cnt<=2) printf("YES");
    else printf("NO");
    return 0;
}

Measured memory_bytes: 128
# -*- coding:utf-8 -*-
r,g,b,n=map(int,input().split(" "))
count=0
r1=n//r
for i in range(0,r1+1):
    g1=(n-i*r)//g+1
    for j in range(0,g1):
        if (n-i*r-j*g)%b==0:
            count=count+1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >>N;
    if(N/10==9 || N%10==9)cout << "Yes" << endl;
    else cout << "No" << endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    string s, t;
    ll k, a = 0, b = 0, c = 0;
    cin >> s >> k;
    int idx = 0;
    if (s[s.size() - 1] == s[0]) {
        int sub = 0;
        while (idx + sub < s.size() && s[idx] == s[idx + sub]) sub++;
        if (sub == s.size()) {
            cout << s.size() * k / 2 << endl;
            return 0;
        }
        ll l = 0, r = 0, ans = 0;
        while (s[0] == s[l]) l++;
        while (s[s.size() - 1] == s[s.size() - 1 - r]) r++;
        idx = l;
        while (idx < s.size() - r) {
            int sub = 0;
            while (idx + sub < s.size() - r && s[idx] == s[idx + sub]) sub++;
            ans += sub / 2;
            idx += sub;
        }
        cout << ans * k + (l + r) / 2 * (k - 1) + l / 2 + r / 2 << endl;
    }
    else {
        ll ans = 0;
        while (idx < s.size()) {
            int sub = 0;
            while (idx + sub < s.size() && s[idx] == s[idx + sub]) sub++;
            ans += sub / 2;
            idx += sub;
        }
        cout << ans * k << endl;
    }


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{long long a,b,x,s,n;
 cin>>a>>b>>x;
 if(a%x==0) s=a/x;
 else s=a/x+1;
 n=b/x;  
 cout<<n-s+1<<endl;
} 

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

int main(){
  int q,c,a,n,ans;

  cin >> q;
  for(int i=0;i<q;i++){
    ans=0;
    cin >> c >> a >> n;
    for(int j=0;j<n;j++){
      if(c>0 && a>0){
	ans++;
	c--;
	a--;
      }
    }
    for(int j=0;j<a;j++){
      if(c>=2){
	ans++;
	c-=2;
      }
    }
    ans+=c/3;
    cout << ans << '\n';
  }
  return 0;
}



Measured memory_bytes: 3104
_, *A = map(int, open(0).read().split())
ans = 1
is_add = False
is_minus = False
tmp = A[0]
for a in A[1:]:
  if tmp > a:
    if is_add:
      ans += 1
      is_add = False
    else:
      is_minus = True
  elif tmp < a:
    if is_minus:
      ans += 1
      is_minus = False
    else:
      is_add = True
  tmp = a
print(ans)

Measured memory_bytes: 14052
package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &slice[i])
	}

	total := 0
	tmp := 0
	for i := n - 1; i >= 1; i-- {
		tmp += slice[i]
		tmp = tmp % (1000000000 + 7)
		total += (tmp * slice[i-1]) % (1000000000 + 7)
		total = total % (1000000000 + 7)
	}

	fmt.Println(total)

}


Measured memory_bytes: 6488
n = int(raw_input())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
c = [a[i] - b[i] for i in xrange(n)]
f = -sum(c)
if f < 0:
    print 'No'
    quit()
t = f
for i in xrange(n):
    if c[i] < 0:
        k = (-c[i] + 1) / 2
        t -= k
        c[i] += k * 2
if t < 0:
    print 'No'
    quit()
s = f
for i in xrange(n):
    s -= c[i]
if s < 0:
    print 'No'
    quit()
if t * 2 == s:
    print 'Yes'
else:
    print 'No'


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 3e5 + 10;
ll fac[maxn], inv[maxn], facinv[maxn], bin[maxn];
void pre()
{
	fac[0] = 1; for(int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;
	inv[1] = 1; for(int i = 2; i < maxn; ++i) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	facinv[0] = 1; for(int i = 1; i < maxn; ++i) facinv[i] = facinv[i - 1] * inv[i] % mod;
	bin[0] = 1; for(int i = 1; i < maxn; ++i) bin[i] = bin[i - 1] * 2 % mod;
}
ll C(int n, int m) { return n < m ? 0 : fac[n] * facinv[m] % mod * facinv[n - m] % mod;}
ll n, a, b, k, ans;
int main()
{
	pre();
	cin >> n >> a >> b >> k;
	for(int x = 0; x <= min(n, k / a); ++x)
		if((k - a * x) % b == 0)
		{
			int y = (k - a * x) / b;
			if(y <= n)
			{
				ans = (ans + C(n, x) * C(n, y) % mod) % mod;
			}
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12916
#include <stdio.h>

int main()
{
    int a, b, c, t;
    int sa, sb, sc;
 
    sa = sb = sc = 0;
    while (10) {
        scanf("%d%d%d", &a, &b, &c);
        if (a + b <= c || b + c <= a || c + a <= b) break;
        if (c < a) t = c, c = a, a = t;
        if (c < b) t = c, c = b, b = t;
        t = a*a + b*b;
        if      (c*c == t) sa++;
        else if (c*c <  t) sb++;
        else               sc++;
    }
    printf("%d %d %d %d\n", sa+sb+sc, sa, sb, sc);
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int a, b, c;
  cin >> a >> b >> c;
  if (a * c <= b) cout << c << endl;
  else cout << b / a << endl;
  return 0;
}


Measured memory_bytes: 256
import operator as op
from functools import reduce

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

n,m = map(int,input().strip().split())
if n<=1 and m <=1:
    print(0)
elif n <= 1:
    print(ncr(m,2))
elif m <= 1:
    print(ncr(n,2))
else:
    print(ncr(m,2) + ncr(n,2))



Measured memory_bytes: 3572
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define setp(x) setprecision(x)
#define nep(x) next_permutation(x);
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
int sum = 0;
void div(ll x){
    if(x % 2 == 1){
        return;
    }
    if(x % 2 == 0) sum++;
    div(x/2);
}
int main() {
   int N;
   cin >> N;
   vector<ll> A(N);
   for(int i = 0; i < N; i++) cin >> A[i];
   for(ll x : A){
       div(x);
   }
   cout << sum << endl;
}


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

a = list(map(int, input().split()))

a = [0] + a

from collections import defaultdict

c = defaultdict(int)

ret = 0
for i in range(1, n + 1):
    c[i + a[i]] += 1

    max_diff = i - a[i]
    ret += c[max_diff]

print(ret)


Measured memory_bytes: 150288
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main() {
    string s,t;
    cin>>s;
    cin>>t;
    int ans=0;
    for(int i=0;i<3;i++){
        if(s.at(i)==t.at(i)){
            ans++;
        }
    }
    cout<<ans<<endl;





    return 0;
}


Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



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

    int N;cin >> N;
    if(N >= 30) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define LL long long
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define mem(a,t) memset(a,t,sizeof(a))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define sz(v) ((int)sizeof(v))
const int inf=1e9;
const int N=1e5+5;
int n,splen=0,spv;
LL ans=0;
vector<pair<int,int> >g[N];
int c[N];

void dfs(int u,int pre,int len){
    c[u]=1;
    int v,w,child=0;
    for(int i=0;i<g[u].size();++i){
        v=g[u][i].fi;
        if(v==pre) continue;
        dfs(v,u,g[u][i].se);
        c[u]+=c[v];
        child=max(child,c[v]);
    }
    child=max(child,n-c[u]);
    if(child<=n/2){
        spv=u;
    }
    if(c[u]*2==n){
        splen=len;
    }
    ans+=2ll*len*min(c[u],n-c[u]);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin>>n;
    int u,v,w;
    rep(i,0,n-1){
        cin>>u>>v>>w;
        g[u].pb(mp(v,w));
        g[v].pb(mp(u,w));
    }
    dfs(1,0,0);
    if(splen){
        cout<<ans-splen<<endl;
    }
    else{
        int mi=1e9;
        for(int i=0;i<g[spv].size();++i){
            mi=min(mi,g[spv][i].se);
        }
        cout<<ans-mi<<endl;
    }
    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <vector>
#include <cctype>
using namespace std;
typedef long long ll;

/*string toLower( string s ) {
    for( int i = 0; i < s.length(); ++i ) {
        if( s[i] >= 'A' && s[i] <= 'Z' ) s[i] += 32;
    }
    return s;
}*/

int main( void ) {
    string s, q, ss;
    int n, a, b;
    cin >> s >> n;
    for( int i = 0; i < n; ++i ) {
        cin >> q >> a >> b;
        if( q == "replace" ) {
            cin >> ss;
            for( int j = a, k = 0; j <= b; ++j, ++k ) s[j] = ss[k];
        }
        else if( q == "reverse" ) {
            while( a < b ) {
                swap( s[a], s[b] );
                ++a, --b;
            }
        }
        else {
            for( int i = a; i <= b; ++i ) cout << s[i];
            cout << '\n';
        }
    }
    return 0;
}



Measured memory_bytes: 3212
N=int(input())
A=input()
B=input()
C=input()
ans=0
for i in range(N):
  if A[i]!=B[i]:
    if A[i]!=C[i] and B[i]!=C[i]:
      ans+=2
    else:
      ans+=1
  elif A[i]!=C[i]:
    ans+=1
print(ans)

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

fn parse_line<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn parse_pair<T: FromStr, U: FromStr>() -> (T, U) {
    let line = parse_line::<String>();
    let mut iter = line.split_whitespace();
    (
        iter.next().unwrap().parse().ok().unwrap(),
        iter.next().unwrap().parse().ok().unwrap(),
    )
}

fn println<T: ToString>(s: T) {
    println!("{}", s.to_string());
}

// ------------------------------------------------------------------------

fn main() {
    let (n, d) = parse_pair::<usize, usize>();

    let range_length = 2 * d + 1;

    println(n / range_length + if n % range_length == 0 { 0 } else { 1 });
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
import numpy

N = int(input())
S = [int(x) for x in input().replace('#', '1').replace('.', '0')]

b_cumsum = numpy.cumsum(S)
w_cumsum = numpy.cumsum(S[::-1])
b_total = b_cumsum[-1]
# print(S)
# print(b_cumsum)
# print(b_total)

ans = N
for i in range(N):

    # for white
    w_num = i + 1
    # w_cur = w_num - res[i]
    w_rev_num = b_cumsum[i]  # w_num - w_cur

    # for black
    b_num = N - w_num
    # b_cur = b_total - b_cumsum[i]
    b_cur = w_cumsum[b_num]
    ans = min(ans, w_rev_num + b_num - b_cur)

print(ans)

Measured memory_bytes: 22220
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
  int N,L;
  cin >> N >> L;
  vector<int> tst(N);
  int dl=100000;
  int sum;
  for(int i=0; i<N; ++i){
    tst[i] = L + i;
  }
  for(int i=0; i<N; ++i){
    if(dl != min(abs(dl), abs(tst[i]))) dl = tst[i];
    sum += tst[i];
  }
//  cout << "sum=" << sum << endl;
//  cout << "dl=" << dl << endl;
  cout << sum - dl << endl;
//  cout << tst[0] << tst[1] << tst[2] << endl;
}

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

int main() {
	string b, b2;
	cin >> b;
	if (b == "A") {
		b2 = "T";
	} else {
		if (b == "C") {
			b2 = "G";
		} else {
			if (b == "G") {
				b2 = "C";
			} else {
				if (b == "T") {
					b2 = "A";
				} else {
					b2 = b;
				}
			}
		}
	}
	cout << b2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

#define PI 3.1415926535

int main(void)
{
	double a, b, c, ang, S, L, h;

	cin >> a >> b >> ang;

	ang = ang * PI / 180;
	c = sqrt(a * a + b * b - 2 * a * b * cos(ang));

	S = a * b * sin(ang) / 2;
	L = a + b + c;
	h = b * sin(ang);

	printf("%.8f\n%.8f\n%.8f\n", S, L ,h);

	return 0;
}

Measured memory_bytes: 1268
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 50+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int a[N];
int main(){
    int n;
    scanf("%d",&n);

    int maxx=-INF;
    int pos=-1;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(abs(a[i])>maxx){
            pos=i;
            maxx=abs(a[i]);
        }
    }

    bool flag=true;
    for(int i=1;i<=n-1;i++)
        if(a[i]>=a[i+1])
            flag=false;

    if(flag)
        printf("0\n");
    else{
        printf("%d\n",2*n-1);
        for(int i=1;i<=n;i++)
            printf("%d %d\n",pos,i);

        if(a[pos]>0)
            for(int i=1;i<=n-1;i++)
                printf("%d %d\n",i,i+1);
        else
            for(int i=n;i>=2;i--)
                printf("%d %d\n",i,i-1);
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main (void) {
    int n;
    int *a;

    scanf ("%d", &n);

    a = (int *) malloc (sizeof(int) * n);
    for (int i=0; i<n; i++) scanf ("%d", &a[i]);

    for (int i=n-1; i>=0; i--) {
        if (i==0) {
            printf ("%d\n", a[i]);
            break;
        }
        printf ("%d ", a[i]);
    }

    free(a);
    
    return 0;
}


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

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

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;



int main(){
  ll N;
  cin >> N;
  vector<ll> A(N,0);
  for(ll i=0;i<N;i++){
      cin>>A[i]
  ;}
  //dp[i]は長さi+1であるような広義単調増加部分列の最後の最小値
  vector<ll> dp(N,INF);
  for(ll i=N-1;i>=0;i--){
      *upper_bound(dp.begin(), dp.end(), A[i])=A[i]
  ;}
  cout<<lower_bound(dp.begin(), dp.end(), INF)-dp.begin()<<endl;
    return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int H,W,A,B; cin >> H >> W >> A >> B;
  if(W/2>=A && H/2>=B);
  else{
    No
    return 0;
  }
  vv<int> field(H,v<int>(W,1));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(i<B && j<A) field[i][j]=0;
      else if(i>=B && j>=A) field[i][j]=0;
    }
  }
  rep(i,H){
    rep(j,W-1){
      cout << field[i][j];
    }
    cout << field[i][W-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 9088
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i = 0; i < n; ++i){
            a[i] = input.nextInt();
            b[i] = a[i];
        }
        Arrays.sort(b);
        int minx = b[n - 2];
        int maxx = b[n - 1];
        for(int i = 0; i < n; ++i){
            if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx);
        }
    }
}


Measured memory_bytes: 94324
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = -2e9, tmp = +2e9;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ans = max(ans, x - tmp);
        tmp = min(tmp, x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3096
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeSet;

fn main() {
    input!{
        n: usize,
        w: [chars; n],
    }

    let ans = w.iter().collect::<BTreeSet<_>>().len() == n
        && (0..n - 1).all(|i| w[i].last() == w[i + 1].first());

    println!("{}", if ans { "Yes" } else { "No" });
}


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

int main()
{
    int N,D,x,y;
    cin>>N>>D;
    int X[20][20];

    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin>>X[i][j];
        }
    }
    int r=0,d=0,p=0;;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int k=0;k<D;k++){
                r=abs(X[i][k]-X[j][k]);
                d+=r*r;
            }
            for(int k=0;k<=d;k++){
                if(k*k==d){
                    p++;
                }
            }
            d=0;

        }
    }
    cout<<p<<endl;

}

Measured memory_bytes: 256
// 解説後
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

// ・互いに区別できるN本の棒から三角形を作る。
// ・2つの三角形を比べたとき、使われる棒が1つでも一方のみに存在する場合、それらの三角形は異なる。
// ・このときに取り得る三角形の個数を計算したい。
// 
// 三角形を作る3つの棒の長さをa,b,c（a <= b <= c）とする。
// cは与えられた条件からa-b < b-a < c < a+bである。
// このとき、b-a <= bなので、b <= c < a+bとなる
// => 長さが[b, a+b)の範囲にある棒の個数を求めれば良い
// 
// 棒の長さのリストをソートすれば、二分探索を使って境界値へのポインタを得られる。
// => 全体としてO(N^2 * logN)で計算できる
int solve_D() {
  size_t N;
  std::cin >> N;

  std::vector<uint32_t> L(N);
  for (auto& L_i : L) {
    std::cin >> L_i;
  }

  // 1. 全探索
  //    O(N^3)くらい => TLE
  auto solver1 = [&]() -> uint64_t {
    struct Triangle {
      Triangle(uint32_t x, uint32_t y, uint32_t z) noexcept {
        if (x > y) std::swap(x, y);
        if (x > z) std::swap(x, z);
        if (y > z) std::swap(y, z);
        a = x;
        b = y;
        c = z;
      }

      bool operator<(const Triangle& other) const noexcept {
        if (a < other.a) return true;
        if (a > other.a) return false;
        if (b < other.b) return true;
        if (b > other.b) return false;
        return c < other.c;
      }

      uint32_t a, b, c;
    };

    std::set<Triangle> set;
    for (size_t i = 0; i < L.size() - 2; ++i) {
      const auto a = L[i];
      for (size_t j = i + 1; j < L.size() - 1; ++j) {
        const auto b = L[j];
        for (size_t k = j + 1; k < L.size(); ++k) {
          const auto c = L[k];
          if (a < b + c &&
              b < c + a &&
              c < a + b) {
            set.emplace(a, b, c);
          }
        }
      }
    }
    return set.size();
  };

  // 2. 二辺の長さから取り得る三角形の個数を数える方法
  auto solver2 = [&]() -> uint64_t {
    constexpr uint32_t MAX_LENGTH = 1000;

    // ソート
    std::sort(L.begin(), L.end());

    // 長さをインデックスとした棒の個数のリストを作る
    std::vector<uint32_t> counts(1001);
    for (const auto L_i : L) {
      counts[L_i]++;
    }

    // 長さをインデックスとした棒の個数の累積和のリストを作る
    std::vector<uint32_t> prefix_sums(counts.size());
    prefix_sums[0] = counts[0];
    for (size_t i = 1; i < counts.size(); ++i) {
      prefix_sums[i] = prefix_sums[i - 1] + counts[i];
    }

    // 取り得るすべての三角形の個数を計算する
    uint64_t result = 0;
    std::vector<uint32_t> used_a(counts.size());
    std::vector<uint32_t> used_b(counts.size());
    for (size_t i = 0; i < N - 1; ++i) {
      const auto a = L[i];

      // 使用済みの棒を数える
      used_a[a]++;

      used_b = used_a;
      for (size_t j = i + 1; j < N; ++j) {
        const auto b = L[j];

        // 使用済みの棒を数える
        used_b[b]++;

        //　b <= c <= (a+b-1)となる三角形の個数を計上する
        result += prefix_sums[std::min(a + b - 1, MAX_LENGTH)] - prefix_sums[b - 1];

        // 組み合わせの重複を避けるため、使用済みの長さbの棒をを差し引く
        result -= used_b[b];
      }
    }

    return result;
  };

  std::cout << solver2();

  return 0;
}

int main() {
  return solve_D();
}


Measured memory_bytes: 256
package main

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

func dfs(start, before int64, arr [][]int64, point []int64) {
	for i := range arr[start] {
		if arr[start][i] == before{
			continue
		}
		point[arr[start][i]] += point[start]
		dfs(int64(arr[start][i]), start, arr, point)
	}
}

func calc(arr [][]int64, point []int64, n int , q int) {
	dfs(0, -1, arr, point)
	for i := range point{
		fmt.Print(point[i])
		fmt.Print(" ")
	}
}

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024*1024)
	strArr := strings.Split(readLine(reader), " ")
	n, _ := strconv.Atoi(strArr[0])
	q, _ := strconv.Atoi(strArr[1])
	arr := make([][]int64, n)
	point := make([]int64, n)

	for i := 0; i< n-1; i++ {
		strArr = strings.Split(readLine(reader), " ")
		tmpA, _ := strconv.ParseInt(strArr[0],10,64)
		tmpB, _ := strconv.ParseInt(strArr[1],10,64)
		arr[tmpA-1] = append(arr[tmpA-1], tmpB-1)
		arr[tmpB-1] = append(arr[tmpB-1], tmpA-1)
	}
	for i := 0; i< q; i++ {
		strArr = strings.Split(readLine(reader), " ")
		tmpP, _ := strconv.Atoi(strArr[0])
		tmpX, _ := strconv.ParseInt(strArr[1],10,64)
		point[tmpP-1] += tmpX
	}
	calc(arr, point, n, q)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}
	return strings.TrimRight(string(str), "\r\n")
}


Measured memory_bytes: 83200
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();

		int i,j,tempL,tempR;
		int L = Integer.MIN_VALUE;
		int R = Integer.MAX_VALUE;

		for(i = 0; i < m; i++) {
			tempL = scan.nextInt();
			tempR = scan.nextInt();
			L = Math.max(L, tempL);
			R = Math.min(R, tempR);
		}

		if(L > R) {
			System.out.println(0);
			return;
		}else {
			System.out.println(R - L + 1);
		}
	}
}


Measured memory_bytes: 65500
import itertools
S = input()
s1 = []
s1.append(S[0])
s1.append(S[1])
s1.append(S[2])
s1.sort()
if [('a', 'b', 'c')] == list(itertools.combinations(s1,3)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
    int M, D, ans = 0;
    cin >> M >> D;
    for (int d = 22; d <= D; d++) {
        int d1 = d % 10, d10 = d / 10;
        if (d1 >= 2 && d10 >= 2 && d1 * d10 <= M) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
total = 0
for i in range(N + 1):
    I = str(i)
    L = len(I)
    sum = 0
    for j in range(L):
        sum = sum + int(I[j])
    if A <= sum <= B:
        total = total + i
print(total)

Measured memory_bytes: 9184
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int MOD = 1000000007;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] b = new long[k + 1];

		//		int blue = k;
		//		int red = n - k;

		b[1] = 1;
		for (int i = 2; i <= k; i++) {

			b[i] = div(kaijou(k - 1), mul(kaijou(k - i), kaijou(i - 1)));

		}
//		System.out.println(div(n,k));
		for (int i = 1; i <= k; i++) {
			if (2 * k >= n) {
				if (i > n + 1 - k) {
					System.out.println("0");
					continue;
				}
			}

			long combi = div(kaijou(n - k + 1), mul(kaijou(n - k + 1 - i), kaijou(i)));

			long ans = mul(combi, b[i]);
//			System.out.println(kaijou(n - k + 1) + "," + kaijou(n - k + 1 - i) + "," + kaijou(i));
//			System.out.println(b[i] + "," + combi + "," + ans);
			System.out.println(ans);
		}

		sc.close();
	}

	public static long kaijou(int base) {

		long ksum = 1;
		for (int i = 1; i <= base; i++) {
			ksum *= i;
			ksum %= MOD;
		}
		return ksum;
	}

	public static long pow (long x, long y) {
		if (y==0) {
			return 1;
		} else if (y%2==0) {
			long tmp = pow(x,y/2);
			return (tmp*tmp%MOD);
		} else {
			long tmp = pow(x,y/2);
			return (tmp*tmp%MOD)*x%MOD;
		}
	}

	public static long div(long a, long b) {

		return mul(a, pow(b, MOD - 2));
	}

	public static long mul(long a, long b) {

		return ((a % MOD) * (b % MOD)) % MOD;
	}

}

Measured memory_bytes: 22356
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int X=sc.nextInt();
        int N=sc.nextInt();
        int pos[]=new int[102];
        for(int i=0;i<N;++i) {
            int no=sc.nextInt();
            pos[no]++;
        }
        int i;
        for(i=X;i>=0;--i) {
            if(pos[i]==0)
                break;
        }
        int j;
        for(j=X+1;j<102;++j) {
            if(pos[j]==0)
                break;
        }
        if(j-X<X-i) {
            System.out.println(j);
        } else {
            System.out.println(i);
        }

    }
}

Measured memory_bytes: 35832
def main():
  N=int(input())
  A=list(map(int,input().split()))
  s=sum(A)
  Q=int(input())
  d=[0]*(10**5 +1)#各数字の個数
  ans=[]
  for i in A:
    d[i]+=1

  for i in range(Q):
    B,C=map(int,input().split())
    s += (C-B)*d[B]
    ans.append(s)
    d[C]+=d[B]
    d[B]=0
    
  print("\n".join(map(str, ans)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 28368
#include<iostream>

using namespace std;

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

    int D[n];

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

    int sum = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1;j < n; j++){
            sum += D[i] * D[j];
        }
    }

    cout << sum << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
   
#define Komachi is retarded
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define bcnt __builtin_popcount
#define clz __builtin_clz
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define LB lower_bound
#define UB upper_bound
#define IN insert
#define rp (p<<1|1)
#define lson l,mid,lp
#define rson mid+1,r,rp
#define LL long long
#define uLL unsigned long long
#define PII pair<int,int>
#define DB double
#define EPS 1e-6
#define INF 0x3f3f3f3f
#define debug(a,p) cerr<<a<<p;
#define REP(i,a,b) for(LL i=(a),i##_end_=(b);i<i##_end_;i++)
#define DREP(i,a,b) for(int i=(a),i##_end_=(b);i>i##_end_;i--)
  
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0;}
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0;}
 
template<class T>void Rd(T &res){
    char c;res=0;
    while((c=getchar())<48);
    do res=(res<<3)+(res<<1)+(c^48);
    while((c=getchar())>47);
}
 
template<class T>void pf(T res){
    if(res<0)putchar('-'),res=-res;
    else if(!res){putchar('0');return ;}
    static int stk[24],tp;
    for(tp=0;res;res/=10)stk[tp++]=res%10;
    while(tp)putchar(stk[--tp]^48);
}

#define M 500004
LL N,A,B,C,D;
int main(){ 
	Rd(N);Rd(A);Rd(B);Rd(C);Rd(D);N--;
    REP(i,0,N){
        LL x=A+i*D-(N-i)*C;
        LL y=A+i*C-(N-i)*D;
        if(B<=max(x,y) && min(x,y)<=B) {printf("YES");return 0;}
    }
    printf("NO");
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {

  var s string
  var t string
  var c int

  fmt.Scan(&s)
  fmt.Scan(&t)

  num := len(s)

  for i := 0; i < num; i++ {
    if s[i] != t[i] {
      c += 1
    }
  }

  fmt.Println(c)
  
}

Measured memory_bytes: 4492
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
#include <chrono>
#include <random>
#include <ctime>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	srand(time(0));
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	ll x = 0;
	for (int i = 2; i < n; i++)x ^= a[i];
	ll s = a[0] + a[1];
	vector<ll> bit(60), a_bit(60), b_bit(60), carry(60);
	ll alra = 0, alrb = 0;
	for (int i = 0; i < 59; i++) {
		if ((x >> i) & 1) {
			bit[i] = 1;
		}
	}
	for (int i = 0; i < 59; i++) {
		if (!bit[i]) {
			if (bit[i + 1] != ((s >> (i+1)) & 1)) {
				a_bit[i] = 1;
				alra += (1LL << i);
				alrb += (1LL << i);
				b_bit[i] = 1;
				//cout << i << "\n";
			}
		}
		if ((bit[i] + carry[i]) % 2 != ((s >> i) & 1)) {
			cout << -1;
			return 0;
		}
		carry[i + 1] = (a_bit[i] + b_bit[i] + carry[i] + bit[i]) / 2;
	}
	if (alra > a[0]) {
		cout << -1;
		return 0;
	}
	for (int i = 59; i >= 0;i--) {
		if (bit[i]) {
			if (alra + (1LL << i) <= a[0]) {
				alra += (1LL << i);
			}
			else {
				alrb += (1LL << i);
			}
		}
	}
	if (alra + alrb != s || alra == 0) {
		cout << -1;
		return 0;
	}
	cout << a[0] - alra;
}

Measured memory_bytes: 3640
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
const int mx = 1000 * 100 + 5, M = 1e9 + 7;
int n, m, s, t, dis[2][mx], cnt[2][mx];
set < pii > ms;
vector < pii > ad[mx];
vector < pair < pii , int > > ed;
void dij(int a, int ind){
	memset(dis[ind], 127, sizeof dis[ind]);
	dis[ind][a] = 0;
	cnt[ind][a] = 1;
	for(int i = 0; i < n; i++)
		ms.insert({dis[ind][i], i});
	while(sz(ms)){
		auto v = ms.begin() -> s;
		ms.erase(ms.begin());
		for(auto u : ad[v]){
			if(dis[ind][v] + u.s < dis[ind][u.f]){
				ms.erase({dis[ind][u.f] , u.f});
				dis[ind][u.f] = dis[ind][v] + u.s;
			//	cnt[ind][u.f] = 0;
				cnt[ind][u.f] = cnt[ind][v];
				ms.insert({dis[ind][u.f] , u.f});
			}
			else if(dis[ind][v] + u.s == dis[ind][u.f]){
				cnt[ind][u.f] += cnt[ind][v];
				(cnt[ind][u.f] >= M ? cnt[ind][u.f] -= M : cnt[ind][u.f] = cnt[ind][u.f]);
			}
		}
	}
	return;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
 	cout.tie(0);
	cin >> n >> m >> s >> t;
	s--, t--;
	int u, v, w;
	for(int i = 0; i < m; i++){
		cin >> u >> v >> w;
		u--, v--;
		ad[u].pb({v , w});
		ad[v].pb({u , w});
		ed.pb({{u , v} , w});
	}
	dij(s , 0);
//	cnt[0][s] = 0;
//	cout << cnt[0][t] << endl;
//	for(int i = 0; i < n; i++)
//		cout << i + 1 << " " << cnt[0][i] << endl;
	dij(t , 1);
//	cnt[1][t] = 0;
//	cout << cnt[1][s] << endl;
	int sum = cnt[0][t] * cnt[1][s] % M;
	for(int i = 0; i < n; i++){
		if(dis[0][i] == dis[1][i] && dis[0][i] + dis[1][i] == dis[0][t]){
			sum += M - cnt[0][i] * cnt[0][i] % M * cnt[1][i] % M * cnt[1][i] % M;
			(sum >= M ? sum -= M : sum = sum);
		}
	}
//	cout << sum << endl;
	for(auto u : ed){
		if (dis[0][u.f.f] > dis[0][u.f.s]) 
			swap(u.f.f , u.f.s);
	//	cout << u.f.f + 1 << " " << u.f.s + 1 << " " << dis[0][u.f.f] << " " << dis[1][u.f.s] << " " << u.s << " " << dis[1][s] << endl;
		if(dis[0][u.f.f] + dis[1][u.f.s] + u.s == dis[1][s] && dis[0][u.f.f] < dis[1][s] / 2 && dis[1][u.f.s] < dis[1][s] / 2){
		//	cout << "aejhgh" << endl;
		//	cout << u.f.f << " " << u.f.s << endl;
		//	cout << cnt[0][u.f.f] << " " << cnt[1][u.f.s] << endl;
			sum += M - cnt[0][u.f.f] * cnt[0][u.f.f] % M * cnt[1][u.f.s] % M * cnt[1][u.f.s] % M;
			(sum >= M ? sum -= M : sum = sum);

		}
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 27436
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

const int MAXN = 50;
const int MAXBITS = 18;

int n, mxchoose, wantand, wantor;
int a[MAXN];

int b[MAXBITS], nb;
int cnt[1 << MAXBITS];
bool valid[MAXN];
int seen[MAXN], nseen;

ll choose[MAXN + 1][MAXN + 1];
ll ways[MAXN + 1];

ll solve() {
	nb = 0;
	REP(i, MAXBITS) {
		int x = (wantand >> i) & 1;
		int y = (wantor >> i) & 1;
		if (x == 1) { if (y == 0) return 0; else continue; }
		if (y == 0) { if (x == 1) return 0; else continue; }
		b[nb++] = i;
	}
	REP(mask, 1 << MAXBITS) cnt[mask] = 0;
	REP(i, n) valid[i] = true;
	REP(i, n) if ((a[i] & wantand) != wantand) valid[i] = false;
	REP(i, n) if ((a[i] | wantor) != wantor) valid[i] = false;
	REPE(i, n) { choose[i][0] = choose[i][i] = 1; FOR(j, 1, i) choose[i][j] = choose[i - 1][j - 1] + choose[i - 1][j]; }
	REPE(i, n) { ways[i] = 0; FORE(j, 1, min(i, mxchoose)) ways[i] += choose[i][j]; }
	ll ret = 0; 
	REP(subset, 1 << nb) {
		int mask = 0, bitcount = 0; REP(i, nb) if (subset&(1 << i)) mask |= 1 << b[i], ++bitcount;
		nseen = 0;
		REP(i, n) if (valid[i]) {
			int idx = a[i] & mask;
			if (cnt[idx] == 0) seen[nseen++] = idx;
			++cnt[idx];
		}
		ll cur = 0;
		REP(i, nseen) {
			int idx = seen[i];
			//printf("\t%x:%d\n", idx, cnt[idx]);
			cur += ways[cnt[idx]];
		}
		//printf("%x: %lld\n", mask, cur);
		if (bitcount % 2 == 0) ret += cur; else ret -= cur;
		REP(i, nseen) cnt[seen[i]] = 0;
	}
	return ret;
}

void run() {
	scanf("%d%d%d%d", &n, &mxchoose, &wantand, &wantor);
	REP(i, n) scanf("%d", &a[i]);
	printf("%lld\n", solve());
}

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


Measured memory_bytes: 4888
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] S = new int[n];
        for (int i = 0; i < n; i++) {
            S[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int[] T = new int[q];
        for (int i = 0; i < q; i++) {
            T[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < T.length; i++) {
            if (binarySearch(S, T[i]) != -1) {
                count++;
            }
        }
        System.out.println(count);
    }

    private static int binarySearch(int[] /*sorted*/ array, int target) {
        int left = 0;
        int right = array.length;
        int mid;
        while (left < right) {
            mid = (left + right) / 2;
            if (array[mid] == target) {
                return mid;
            } else if (array[mid] > target) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return -1;
    }
}

Measured memory_bytes: 81288
#include <stdio.h>

void selectionSort(int A[], int n);

int i, j, n, miji, count = 0;

int main()
{
	int A[100];
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d", &A[i]);
	}
	
	selectionSort(A, n);
	printf("%d\n", count);
	
	return 0;
}

void selectionSort(int A[], int n){
	int save; 
	 for(i = 0; i <= n-1; i++){
		miji = i;
		for(j = i; j <= n-1; j++){
			if(A[j] < A[miji]) miji = j;
		}
		save = A[i];
		A[i] = A[miji];
		A[miji] = save;
		if(i != miji) count ++;
	}
	
	for(i = 0; i < n-1; i ++){
		printf("%d ", A[i]);
	}
	printf("%d\n",A[i]);
}


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

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int ll
#define pw(x) (1LL<<(x))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define dbg(a) cerr << #a << " = " << a << '\n'

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

void open(string file) {
    freopen((file + ".in").c_str(), "r", stdin);
    freopen((file + ".out").c_str(), "w", stdout);
}

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

signed main() {
    //open("cbarn");
    fast_io();
    int n;
    cin >> n;
    vi l(2 * n);
    for (auto& i : l) cin >> i;
    sort(rall(l));
    int ans = 0;
    for (int i = 1; i < 2 * n; i += 2) ans += l[i];
    cout << ans;
    return 0;
}


Measured memory_bytes: 3628
mod=1000000007
n=int(input())
X=list(map(int,input().split()))
L=[]
for  i in range(n-1):
    L.append(X[i+1]-X[i])
for i in range(n-2,0,-1):
    L[i-1]=(L[i-1]+L[i])%mod
l=[1]
for i in range(n-1):
    l.append(l[-1]*(i+1)%mod)
ll=[1]
for i in range(n-1,0,-1):
    ll.append(ll[-1]*i%mod)
ans=0
for i in range(n-1):
    ans=(ans+((L[i]*l[i])%mod)*ll[n-2-i])%mod
print(ans)

Measured memory_bytes: 19244
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val Array(n, k) = StdIn.readLine.split(' ').map(_.toInt)
    val ar = (1 to n map (_ => StdIn.readLine.toInt)).toArray
    var l = 1
    var r = ar.sum
    var ans = 0

    // println(r)

    while (l < r) {
      ans = (r + l) / 2
      if (alloc(ar, n, k, ans)) {
        r = ans
      } else {
        l = ans + 1
      }
    }
    println(l)
  }

  def alloc(arr: Array[Int], len: Int, k: Int, maxAlloc: Int): Boolean = {
    var cache = 0
    var j = 1
    for (a <- arr) {
      if (cache + a <= maxAlloc) {
        cache += a
      } else if (a <= maxAlloc && j < k) {
        cache = a
        j += 1
      } else {
        return false
      }
    }
    true
  }
}



Measured memory_bytes: 107752
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <sstream>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define ios     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll mod=1000000000;
ll INF=1e18;
ll gcd (ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll fastexp(ll x ,ll n)
{
    ll result =1;
    while(n>0)
    {
        if(n%2==1)
            result*=x;
        x*=x;
        n=n/2;
    }
    return result;
}

ll modularExp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=((x%mod)*(x%mod))%mod;
        n=n/2;
    }
    return (result)%mod;
}
bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
bool mycomp(pll &a,pll &b)
{
    if(a.F!=b.F)
        return a.F < b.F;
    else
        return a.S < b.S;
}
vector<ll> par(2005),sz(2005,1);

ll froot(ll x)
{
     if(x==par[x])
          return x;
     return par[x]=froot(par[x]);
}
void solve()
{
     ll n;
     cin>>n;
     ll ans=0;
     ll i;
     for(i=1;i<=n-1;i++)
     {
          ans+=(n-1)/i;
     }
     cout<<ans;
     
}

int main()
{
    ios;
    ll t;
     // cin>>t;
     t=1;
     while(t--)
     {
          solve();
     }
}


Measured memory_bytes: 3636