akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


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


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


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N, M = map(int, input().split())
    print((N * (N - 1)) // 2 + (M * (M - 1)) // 2)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9876
n = int(input())
A = [0 for i in range(26)]
s = input()
for i in range(len(s)):
  A[ord(s[i]) - 97] += 1
for j in range(1, n):
  B = [0 for i in range(26)]
  s = input()
  for i in range(len(s)):
    B[ord(s[i]) - 97] += 1
  for i in range(26):
    A[i] = min(A[i], B[i])
ans = ""
for i in range(26):
  ans += chr(97+i) * A[i]
print(ans)

Measured memory_bytes: 70860
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
LL a[55];
int n;
int main() {
    while(~scanf("%d", &n)) {
        LL MIN = INF;
        int minsign = -1;
        LL MAX = -INF;
        int maxsign = -1;
        for(int i = 1; i <= n; ++i) {
            scanf("%lld", &a[i]);
            if(MIN > a[i]) {
                MIN = a[i];
                minsign = i;
            }
            if(MAX < a[i]) {
                MAX = a[i];
                maxsign = i;
            }
        }
        printf("%d\n", 2 * n - 1);
        if(abs(MIN) < abs(MAX)) {
            for(int i = 1; i <= n; ++i) {
                if(maxsign == i) continue;
                printf("%d %d\n", maxsign, i);
            }
            printf("%d %d\n", maxsign, maxsign);
            for(int i = 2; i <= n; ++i) {
                printf("%d %d\n", i - 1, i);
            }
        }
        else {
            for(int i = 1; i <= n; ++i) {
                if(minsign == i) continue;
                printf("%d %d\n", minsign, i);
            }
            printf("%d %d\n", minsign, minsign);
            for(int i = n; i > 1; --i) {
                printf("%d %d\n", i, i - 1);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

constexpr int max_n = 200'000 + 5;

int n;
vector<int> cs(max_n);
vector<vector<int>> adjs(max_n);
vector<ll> res(max_n);
// vector<pair<bool,int>> euler_tour; // { is_down, vertex }
// vector<int> et_in(max_n), et_out(max_n);
int et_size;
vector<int> sums(max_n); // sums[c] = 色cの現在の累積和
// vector<int> memo(2 * max_n); // memo[i] = euler_tour[i]でのメモ

void dfs(int cur = 1, int par = 0) {
    int par_color = cs[par], cur_color = cs[cur];
    // int in_i = euler_tour.size();
    int in_i = et_size;
    // memo[in_i] = sums[color];
    int memo = sums[par_color];
    // et_in[cur] = in_i;
    // euler_tour.push_back({true, cur});
    et_size++;
    for (auto ch : adjs[cur]) {
        if (ch == par) { continue; }
        dfs(ch, cur);
    }
    // int out_i = euler_tour.size();
    int out_i = et_size;
    // et_out[cur] = out_i;
    // euler_tour.push_back({false, cur});
    et_size++;

    sums[cur_color]++;
    int tree_size = (out_i - in_i + 1) / 2;
    ll component_size = tree_size - (sums[par_color] - memo);
    res[par_color] += component_size * (component_size + 1) / 2;
    sums[par_color] += component_size; // = tree_size + memo
}

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    cin >> n;
    rep(i, n) {
        int c; cin >> c;
        cs[i+1] = c;
    }
    rep(i, n-1) {
        int a,b; cin >> a >> b;
        adjs[a].push_back(b);
        adjs[b].push_back(a);
    }

    dfs();

    rep(i, n) {
        int tree_size = et_size / 2;
        ll component_size = tree_size - sums[i+1];
        res[i+1] += component_size * (component_size + 1) / 2;
    }

    rep(i, n) {
        res[i + 1] = (ll)n * (n + 1) / 2 - res[i + 1];
        cout << res[i + 1] << '\n';
    }

    return 0;
}


Measured memory_bytes: 32356
from fractions import gcd

def lcm(x, y):
  return (x * y) // gcd(x, y)

MOD = 10 ** 9 + 7  
n = int(input())
A = list(map(int, input().split()))

l = 1
for i in A:
  l = lcm(l, i)
l %= MOD

ans = 0
for i in A:
  ans += l * pow(i, MOD - 2, MOD)
  ans %= MOD
print(ans)


Measured memory_bytes: 6108
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
i64 ans;
set<int> G;
int A[300000], B[300000];

int main(void)
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
	{
		scanf("%d", &A[i]);
		B[A[i]] = i;
	}

	for (int i = 1; i <= N; i++)
	{
		G.insert(B[i]);
		auto itr = G.find(B[i]);
		int l, r;
		
		if (itr == G.begin())
		{
			l = *itr;
		}
		else
		{
			l = *itr - *(--itr);
			++itr;
		}

		++itr;

		if (itr == G.end())
		{
			--itr;
			r = N - *itr + 1;
		}
		else
		{
			r = *itr - *(--itr);
		}
		
		ans += (i64)l * r * i;
	}

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

	return 0;
}

Measured memory_bytes: 11264
#D問題
import sys
A,B,Q = map(int,(input().split()))
si = [-(10**10)]+[int(input()) for _ in range(A)]+[2*(10**10)] # 範囲外に追加して、xの左右に常にデータがあるようにする
ti = [-(10**10)]+[int(input()) for _ in range(B)]+[2*(10**10)]
#xi = [int(input()) for i in range(Q)]
*xi, = map(int,"".join(sys.stdin.readlines()).split())
A +=2
B +=2

for x in xi:
    l = 0
    r = A-1
    while l+1<r:
        i = (l+r)//2
        if si[i]<x:
            l = i
        else:
            r = i
    sl = si[l]
    sr = si[r]
    
    l = 0
    r = B-1
    while l+1<r:
        i = (l+r)//2
        if ti[i]<x:
            l = i
        else:
            r = i
    tl = ti[l]
    tr = ti[r]
    dsl = x-sl
    dsr = sr-x
    dtl = x-tl
    dtr = tr-x
    print(min(max(dsr,dtr),max(dsl,dtl),dsl+dtr+min(dsl,dtr),dsr+dtl+min(dsr,dtl)))

Measured memory_bytes: 22032
import sys
for line in sys.stdin:
    a, b, c, d, e, f = [float(x) for x in line.split()]
    x = (f * b - e * c) / (d * b - a * e)
    y = (c - a * x) / b
    if abs(x) < 0.00001:
        x = 0.000
    if abs(y) < 0.00001:
        y = 0.000
    print("%.3f %.3f" % (x, y) )


Measured memory_bytes: 5592
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1e9+7;

int main(){
  ll n,m;
  cin>>n>>m;
  vector<ll> v;
  for(ll i=1;i*i<=m;i++){
	if(m%i)continue;
	v.push_back(i);
	if(i*i==m)break;
	v.push_back(m/i);
  }
  ll ans=0;
  for(ll i=0;i<v.size();i++){
	if(m/v[i]>=n)ans=max(ans,v[i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;
ll a[100005];
int main() {
    int n,k;
    cin>>n>>k;
    ll sum=0;
    for(int i=1;i<=n;i++) {
        scanf("%lld",&a[i]);
        if(a[i]>0) sum+=a[i];
    }
    ll temp=0,ans=0;
    for(int i=1;i<=k;i++) {
        temp+=a[i];
        if(a[i]>0) sum-=a[i];
    }
    ans=max(ans,max(temp+sum,sum));
    for(int i=2;i<=n-k+1;i++) {
        temp-=a[i-1];
        temp+=a[k+i-1];
        if(a[i-1]>0)
            sum+=a[i-1];
        if(a[i+k-1]>0)
            sum-=a[i+k-1];
        ans=max(ans,max(temp+sum,sum));
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>

int n;
double x[100],y[100];
	
double dist(double p){
	int i;
	long double t=0;
	for(i=0;i<n;i++)t+=pow(fabs(y[i]-x[i]),p);
	return pow(t,1.0/p);
}

int main(){
	int i;
	double maxt=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%lf",&x[i]);
	for(i=0;i<n;i++)scanf("%lf",&y[i]);
	for(i=0;i<n;i++)if(fabs(y[i]-x[i])>maxt)maxt=fabs(y[i]-x[i]);
	printf("%lf\n%lf\n%lf\n%lf\n",dist(1.0),dist(2.0),dist(3.0),maxt);
	return 0;
}
		

Measured memory_bytes: 716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a,b,c;
  cin>>a>>b>>c;
  cout<<(char)toupper(a[0])<<(char)toupper(b[0])<<(char)toupper(c[0])<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, c, we[105], v[105];
long long mem[105][N];
bool vis[105][N];

long long dp(int idx, int w) {
	if (idx == n || w >= c) {
		return 0;
	}
	if (vis[idx][w]) {
		return mem[idx][w];
	}
	vis[idx][w] = true;

	long long ans = dp(idx + 1, w);
	if (w + we[idx] <= c) {
		ans = max(ans, (long long) v[idx] + dp(idx + 1, w + we[idx]));
	}

	return mem[idx][w] = ans;
}

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

	cin >> n >> c;

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

	cout << dp(0, 0) << '\n';

	return 0;
}


Measured memory_bytes: 89856
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2") 
#pragma GCC optimization ("unroll-loops")

using namespace std;
using ll = long long;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ff first
#define ss second
#define Ceil(x, y) ((x+y-1)/y)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x);
const int mod = (int) 1000000007;

set<int> getFact(int n)
{
    set<int> ans;
    while (n % 2 == 0)  
    {  
        ans.insert(2);
        n = n/2;  
    }  

    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        while (n % i == 0)  
        {  
            ans.insert(i);
            n = n/i;  
        }  
    }  
    if (n > 2)  
        ans.insert(n);
    return ans;
}

void solve()
{
    int n;
    cin>>n;
    vector<int> A(n), freq(1e6+10);
    bool st = true, pair = true;
    for(auto &i : A)
        cin>>i;

    int allgcd = A[0];
    for(int i=0; i<n; i++)
    {
        set<int> S = getFact(A[i]);
        for(auto j : S)
        {
            freq[j]++;
            if(freq[j] > 1)
                pair = false;
        }
        if(i > 0)
            allgcd = __gcd(A[i], allgcd);
    }
    if(allgcd > 1)
        st = false;
    if(pair)
        cout<<"pairwise coprime";
    else if(st)
        cout<<"setwise coprime";
    else
        cout<<"not coprime";
}
 

int main(int argc, char *argv[])
{
    clock_t clk_start = clock();
    fast;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
 
    int cases = 1;
    // cin>>cases;
    for(int i=1; i<=cases; i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    cerr<<"Execution Time: "<<fixed<<double(clock() - clk_start)/double(CLOCKS_PER_SEC)<<setprecision(6)<<" sec\n"; 
}

Measured memory_bytes: 11148
#include <stdio.h>

struct player {
	int score;
	int card;
};

int main(void) 
{
	int i, n;
	struct player A;
	struct player B;
	
	while ((scanf("%d", &n), n)) {
		A.score = B.score = 0;

		for (i = 0; i < n; i++) {
			scanf("%d %d", &A.card, &B.card);

			if (A.card > B.card) 
				A.score += A.card + B.card;
			else if (A.card == B.card) {
				A.score += A.card;
				B.score += B.card;
			} else {
				B.score += A.card + B.card;
			}
		}
		printf("%d %d\n", A.score, B.score);
	}

	return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

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

  int K, X;

  cin >> K >> X;

  if (500 * K >= X) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	int i, L, R, d, c = 0;



	cin >> L >> R >> d;
	// vector<int> a(N);
	// vector<int> b(M);
	for (i = L; i <= R; i++){
		if (i % d == 0){
			c++;
		};
	}

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int main() {
  IOS;
  int x;
  cin >> x;
  if (x <= 599)
    cout << 8 << endl;
  else if (x <= 799)
    cout << 7 << endl;
  else if (x <= 999)
    cout << 6 << endl;
  else if (x <= 1199)
    cout << 5 << endl;
  else if (x <= 1399)
    cout << 4 << endl;
  else if (x <= 1599)
    cout << 3 << endl;
  else if (x <= 1799)
    cout << 2 << endl;
  else
    cout << 1 << endl;
}


Measured memory_bytes: 3660
#include <iostream>

using namespace std;

int main()
{
	int r;	// 正解
	int a;	// 回答
	int array_r[4];
	int array_a[4];
	int hit;
	int blow;

	while(1)
	{
		cin >> r;
		cin >> a;
		hit = 0;
		blow = 0;

		if(r == 0 && a == 0)
		{
			break;
		}
		
		for(int i = 0; i < 4; ++i)
		{
			array_r[i] = r % 10;
			array_a[i] = a % 10;
			r /= 10;
			a /= 10;
		}

		for(int index_r = 0; index_r < 4; ++index_r)
		{
			for(int index_a = 0; index_a < 4; ++index_a)
			{
				if(array_r[index_r] == array_a[index_a])
				{
					if(index_r == index_a)
					{
						hit++;
					}
					else
					{
						blow++;
					}
				}
			}
		}
		
		cout << hit << " " << blow << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3088
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  ll n; cin >> n;
  vector<ll> a(n); rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, n) {
    while (a[i] % 2 == 0) {
      ans++;
      a[i] /= 2;
    }
  }
  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 384
N, x = tuple(int(i) for i in input().split())
a = [int(i) for i in input().split()]

def f(a, x):
    if not a:
        return 0

    a.append(x)
    a = sorted(a)
    i = a.index(x)
    if i < len(a)-1:
        return len(a) - 2
    elif a[i-1] == a[i]:
        return len(a) - 2
    return f(a[:i-1], x-a[i-1])


s = sum(a)
if x == s:
    print(N)
elif x > s:
    print(N-1)
else:
    print(f(a, s-x))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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; }


int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int score=0;
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]) score++;
    }
    int ans=min(score+2*k,n-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
using namespace std;
 
int main() {
	int n=0,w=0,s=0,e=0;
    int ns = 0, we = 0;
	string str;
	cin >> str;
    
	for (long unsigned int i = 0; i < str.length(); i++)
	{
		if (str[i] == 'N')n = 1;
		else if (str[i] == 'S')s = 1;
		else if (str[i] == 'W')w = 1;
		else if (str[i] == 'E')e = 1;
	}
       
    ns = s + n;
    we = w + e;
 
	if (ns == 1 || we == 1)cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  double L;
  cin>>L;
  
  double P=L/3;
  double ans=P*P*P;
  cout<<fixed;
  cout<<setprecision(10)<<ans<<endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
ll cnt0[69],cnt1[69];

int main(){
  ll n;
  ll a[300009];
  ll ans=0;
  
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  for(int i=n-1;i>=0;i--){
    for(int j=0;j<=60;j++){
      if((a[i]>>j)&1){
        ans+=cnt0[j]*((1ll<<j)%mod)%mod;
        ans%=mod;
        cnt1[j]++;
      }
      else{
        ans+=cnt1[j]*((1ll<<j)%mod)%mod;
        ans%=mod;
        cnt0[j]++;
      }
    }
  }

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


Measured memory_bytes: 2560
object Main {
    def main(args: Array[String]): Unit = {
        val Array(w, h, x, y, r) = io.StdIn.readLine.split(" ").map(_.toInt)
        if (x-r < 0 || y-r < 0 || x+r > w || y+r > h) println("No")
        else println("Yes")
    }
}

Measured memory_bytes: 43688
#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; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    string S;
    string T;
    cin >> S >> T;
    int ct = 0;
    rep(i,S.size()){
        if(S[i] == T[i])ct++;
    }

    cout << S.size() - ct << endl;
}

Measured memory_bytes: 3844
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
vector<int> P;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  P.resize(N);
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    P[i] = tmp;
  }

  int ans = 0;
  int m = INF;
  for (int i = 0; i < N; i++) {
    if (P[i] <= m) {
      ans++;
    }
    m = min(m, P[i]);
  }

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


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

using namespace std;

int main()
{
	int n, k, x;
  	cin >> n >> k;
  	long long sum = 0;
  	for(int i = 1; i <= n; i ++){
    	cin >> x;
      	sum += min(2 * x, 2 * abs(x - k));
    }
  	cout << sum << "\n";
}


Measured memory_bytes: 256
//abc125_c.cpp
//Tue Apr 30 16:45:30 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

long long gcd (long long a, long long b){ //最大公約数
	if (b == 0){
		return a;
	}
	return gcd(b, a%b);
}

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

	ll a[n];
	ll l[n];
	for (int i=0;i<n;i++){
		cin >> a[i];
		if (i==0){
			l[i]=a[i];
		}else{
			l[i]=gcd(l[i-1],a[i]);
		}
	}

	ll r[n];
	for (int i=n-1;i>=0;i--){
		if (i==n-1){
			r[i] = a[i];
		}else {
			r[i] = gcd(r[i+1],a[i]);
		}
	}

	ll ans = 0;
	for (int i=0;i<n;i++){
		ll temp = 0;
		if (i==0){
			temp = r[1];
		}else if (i==n-1){
			temp = l[n-2];
		}else {
			temp = gcd(l[i-1],r[i+1]);
		}
		if (ans < temp){
			ans = temp;
		}
	}
	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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

int main() {
  string S, T;
  cin >> S >> T;
  if (S.size() < T.size()) {
    if (S == T.erase(S.size(), 1) ) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*4
#define ll long long
#define mod 1000000007
ll qpow(ll x,ll y)
{
	ll res=1;
	while(y)
	{
		if(y&1) res=res*x%mod;
		x=x*x%mod;y=y/2;
	}
	return res;
}
struct segmenttree{
	ll tree[nn*2+10];
	#define lc id<<1
	#define rc id<<1|1
	#define mid (l+r)/2
	void update(int x,int y)
	{
		x=x+nn-1;tree[x]=y;x=x/2;int id=x;
		while(x) tree[x]=tree[lc]+tree[rc],tree[x]%=mod,x=x/2,id=x;
	}
	ll query(int a,int b,int l,int r,int id)
	{
		if(a>b) return 0;
		if(l>=a and r<=b) return tree[id];
		ll sm=0;
		if(a<=mid) sm=sm+query(a,b,l,mid,lc);
		if(b>mid) sm=sm+query(a,b,mid+1,r,rc);
		return sm%mod;
	}
}cnt,trcyx;
ll a[nn];ll n;
ll abv[nn];
ll tot;ll pre[nn];
vector<ll> pos[nn];ll ans;
void solve(int l,int r)
{
//	cout<<-r<<" "<<-l<<"\n";
	for(int ii=-l;ii>-r;ii--)
	{
		for(int j=0;j<pos[ii].size();j++)
		{
			ll i=pos[ii][j];
			trcyx.update(i,qpow(pre[a[i]],mod-2));
		}
	}
	
	for(int ii=-l;ii>-r;ii--)
	{
		for(int j=0;j<pos[ii].size();j++)
		{
			ll i=pos[ii][j];
			ll ct=tot*pre[a[i]]%mod*qpow(2,mod-2)%mod;
			ans+=trcyx.query(1,i-1,1,nn,1)*ct%mod;
			
			ans-=trcyx.query(i+1,n,1,nn,1)*ct%mod;
			ans+=cnt.query(i+1,n,1,nn,1)*tot%mod;
			
			cnt.update(i,0);
			trcyx.update(i,0);
			ans%=mod;
		}
	}
	
}
int main()
{
	scanf("%lld",&n);tot=1;pre[0]=1;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]),abv[a[i]]++,pos[a[i]].push_back(i);
	for(int i=n;i>=1;i--) abv[i]+=abv[i+1],abv[i]%=mod,tot=tot*(abv[i]-(n-i))%mod;
	for(int i=1;i<=n;i++) pre[i]=pre[i-1]*(max(1ll,(abv[i]-(n-i))-1) )%mod*qpow((abv[i]-(n-i)),mod-2)%mod;
	vector<ll> cg;cg.push_back(-0);cg.push_back(-n);
	for(int i=1;i<=n;i++) 
		if(abv[i]-(n-i)==1) 
			cg.push_back(-i+1);
	if(!tot)
	{
		puts("0");
		exit(0);
	}
	
	for(int i=1;i<=n;i++) cnt.update(i,1);
	sort(cg.begin(),cg.end());
	for(int i=0;i<cg.size()-1;i++) solve(cg[i],cg[i+1]);

	printf("%lld\n",(ans+mod)%mod);
	
	return 0;
}

Measured memory_bytes: 28660
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    while(n--) cout<<"ACL";
    return 0;
}


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

using namespace std;
#define long long long

int const N = 1e4 + 10;
int const MOD = 1e9 + 7;

int n, d, dp[N][110][2];
// dp[index of digit][remainder][limited or not]
char s[N];

int Solve(int index, int remainder, int smaller)
{
    if (index == n) {
        if (!remainder) return 1;
        else return 0;
    }

    if (dp[index][remainder][smaller] != -1) return dp[index][remainder][smaller];

    int limit = 9;
    long init_cnt = 0;
    if (smaller) limit = s[index] - '0';
    for (int i = 0; i <= limit; ++i) {
        int check = (i < s[index] - '0' ? 0 : smaller);
        (init_cnt += Solve(index + 1, (remainder + i) % d, check)) %= MOD;
    }
    dp[index][remainder][smaller] = init_cnt;
    return init_cnt;
}

int main()
{
//    freopen("tam.inp", "r", stdin);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> s >> d;
    n = strlen(s);

    memset(dp, -1, sizeof(dp));
    cout << (Solve(0, 0, 1) - 1 + MOD) % MOD;

    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<map>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=2*1e5+5;
int n,a[maxn];
map<int,int>mp;

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline ll get(int x){
	ll ss=1;
	while(ss <= x) ss<<=1;
	return ss;
}

int main(){
	n=rd();
	go(i,n+1,1){
		a[i]=rd(); 
		if(mp.count(a[i])) mp[a[i]]=mp[a[i]]+1;
		else mp[a[i]]=1;
	}
	sort(a+1,a+n+1);
	ll qs=get(a[n]); ll ans=0;
	for(rg int i=n;i>=1;i--){
		if(mp[a[i]] == 0) continue; 
		while((qs>>1) > a[i]) qs>>=1;
		if(mp.count(qs-a[i])){
			if(mp[qs-a[i]] == 0) continue;
			if(qs-a[i] == a[i] && mp[a[i]] <= 1) continue;
			ans++; mp[qs-a[i]]=mp[qs-a[i]]-1; mp[a[i]]=mp[a[i]]-1;
		}
	}
	printf("%lld",ans);
	return 0;
}//Faze


Measured memory_bytes: 10368
using System;
using static System.Console;

class Program
{
    static char nChar(char c, int n)
    {
	char nc = (char) (c + n);
	if (nc > 'Z')
	    nc = (char) (nc - ('Z' + 1) + 'A');
	return nc;
    }
    
    public static void Main()
    {
	int n = int.Parse(ReadLine());
	string s = ReadLine();
	string ans = "";
	
	for (int i = 0; i < s.Length; i++)
	    ans += nChar(s[i], n);
	
	WriteLine(ans);
    }
}

Measured memory_bytes: 36820
#include <iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
        int R[MAX],n;

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

        int maxv = -2000000000;
        int minv = R[0];
        for ( int i = 1; i < n; i++ ) {
                maxv = max(maxv, R[i] - minv);
                minv = min(minv, R[i]);
        }
        cout << maxv << endl;
        return 0;

}


Measured memory_bytes: 3872
# 10010010

# 10101010

# 01010101

s = gets.chomp.split(//).map &:to_i

count01 = 0
count10 = 0
s.each_with_index do |ss, ind|
  is01 = ind % 2
  if (ss != is01)
    count01 += 1
  else
    count10 += 1
  end
end

puts [count01, count10].min


Measured memory_bytes: 7676
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,m;
vector<int>from[15];
int p[15];
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int t;cin>>t;
		while(t--){
			int x;
			cin>>x;
			from[x-1].push_back(i);
		}
	}
	for(int i=1;i<=m;i++)cin>>p[i]; 
	int ans=0;
	for(int i=0;i<(1<<n);++i){
		vector<int>cnt(15,0);
		for(int j=0;j<n;j++)if(i&(1<<j)){
			for(auto x:from[j])cnt[x]++;
		}
		bool ok=true;
		for(int j=1;j<=m;j++)if(cnt[j]%2!=p[j])ok=false;
		ans+=ok;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

vector<int> a;
vector<int> dp;
vector<vector<int>> g;
vector<int> ans;

void dfs(int v, int p = -1){
	int idx = lower_bound(dp.begin(), dp.end(), a[v]) - dp.begin();
	int last = dp[idx];
	dp[idx] = a[v];
	ans[v] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
	for(auto nv : g[v]){
		if(nv == p)continue;
		dfs(nv, v);
	}
	dp[idx] = last;
}

int main(){
  int n; 
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; ++i){
  	cin >> a[i];
  }
  g.resize(n);
  for(int i = 0; i < n - 1; ++i){
  	int u, v;
  	cin >> u >> v;
  	--u;
  	--v;
  	g[u].push_back(v);
  	g[v].push_back(u);
  }

  dp.assign(n, INF);
  ans.resize(n);
  dfs(0);
  for(int i = 0; i < n; ++i){
  	cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 27976
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
	int X = 0,w = 0 ;
	char ch = 0;
	while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
	while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
	return w ? -X : X;
}
int mod=1e9+7;
char maze[1005][1005];
int dp[1005][1005];
int main() 
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>maze[i][j];
		}
	}
	for(int i=0;i<n;i++)
	{
		if(maze[i][0]=='#')
				break;
		dp[i][0]=1;
	}
	for(int i=0;i<m;i++)
	{
		if(maze[0][i]=='#')
				break;
		dp[0][i]=1;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<m;j++)
		{
			if(maze[i][j]=='#')
				continue;
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	cout<<dp[n-1][m-1];
    return 0;
}

Measured memory_bytes: 5120
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N = int(readline())
    if N % 2 == 1:
        print(0)
    else:
        count2 = 0
        count5 = 0
        compare = 1
        while N >= compare * 2:
            compare *= 2
            count2 += N // compare
        compare = 1
        N //= 2
        while N >= compare * 5:
            compare *= 5
            count5 += N // compare
        ans = min(count2, count5)
        print(ans)



if __name__ == '__main__':
    solve()

Measured memory_bytes: 77204
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;
	
	int[long] ac;
	foreach(a; as){
		if(a !in ac) ac[a] = 0;
		ac[a] += 1;
	}
	
	int ans;
	long[] aq = ac.keys;
	aq.sort!"a>b"();
	foreach(a; aq){
		long b = 1;
		while(b <= a) b *= 2;
		b -= a;
		if(b == a) ans += ac[a] / 2;
		else{ // b < a
			if(b in ac){
				if(ac[b] > ac[a]){
					ans += ac[a];
					ac[b] -= ac[a];
				}
				else{
					ans += ac[b];
					ac[b] = 0;
				}
			}
		}
	}
	
	ans.writeln;
	
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

class ModInt {
public:
  static void setMod(int m) {
    mod = m;
  }

  ModInt(int val = 0) : val(val) {}

  const ModInt operator + (const ModInt& rhs) const {
    return ModInt((this->val + rhs.val) % mod);
  }

  const ModInt operator - (const ModInt& rhs) const {
    return ModInt((this->val + mod - rhs.val) % mod);
  }

  const ModInt operator * (const ModInt& rhs) const {
    return ModInt((this->val * rhs.val) % mod);
  }

  ModInt& operator += (const ModInt& rhs) {
    this->val = (this->val + rhs.val) % mod;
    return *this;
  }

  ModInt& operator -= (const ModInt& rhs) {
    this->val = (this->val + mod - rhs.val) % mod;
    return *this;
  }

  ModInt& operator *= (const ModInt& rhs) {
    this->val = (this->val * rhs.val) % mod;
    return *this;
  }

  int val;
  static int mod;
};
int ModInt::mod = MOD;

constexpr int MAX_N = 51;
constexpr int MAX_K = MAX_N*MAX_N;
int N, K;

ModInt dp[MAX_N][MAX_N][MAX_K];

signed main()
{
  cin >> N >> K;
  if(K == 0) {
    cout << 1 << endl;
    return 0;
  }

  dp[0][0][0] = 1;

  FOR(i,1,N+1) {
    REP(j,N+1) {
      REP(k,MAX_K) {
        if(k-2*j>=0) {
          dp[i][j][k] = ModInt(2*j+1)*dp[i-1][j][k-2*j] 
          + ModInt((j+1)*(j+1))*dp[i-1][j+1][k-2*j];
          if(j-1>=0) {
            dp[i][j][k] += dp[i-1][j-1][k-2*j];
          }
        }
      }
    }
  }

  cout << dp[N][0][K].val << endl;

  return 0;
}


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

int main(){
    int w, h;
    char c;
    cin >> w >> h >> c;
    
    printf("+");
    for(int i = 0; i < w-2; i++)    printf("-");
    printf("+\n");

    for(int i = 0; i < h-2; i++){
        for(int j = 0; j < w; j++){
            if(j == 0 || j == w-1)                  printf("|");
            else if(i == (h-2)/2 && j == w/2)   printf("%c", c);
            else                                    printf(".");
        }
        printf("\n");
    }

    printf("+");
    for(int i = 0; i < w-2; i++)    printf("-");
    printf("+\n");

    return 0;
}



Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			double weight = scan.nextDouble();
			if(weight > 91){
				System.out.println("heavy");
			}else if(weight > 81){
				System.out.println("light heavy");
			}else if(weight > 75){
				System.out.println("middle");
			}else if(weight > 69){
				System.out.println("light middle");
			}else if(weight > 64){
				System.out.println("welter");
			}else if(weight > 60){
				System.out.println("light welter");
			}else if(weight > 57){
				System.out.println("light");
			}else if(weight > 54){
				System.out.println("feather");
			}else if(weight > 51){
				System.out.println("bantam");
			}else if(weight > 48){
				System.out.println("fly");
			}else{
				System.out.println("light fly");
			}
		}
	}
}

Measured memory_bytes: 17452
//Totka hai dosto
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int32_t main()
{
	int l,r;
	cin>>l>>r;
	
	int diff=r-l;
	if(diff>=4000)
	{cout<<0;return 0;}
	int ans=1e18;
	ans=ans*4;
	for(int i=l;i<r;i++)
	{
		for(int j=i+1;j<=r;j++)
		{
			ans=min(ans,(i*j)%2019);
		}
	}
	cout<<ans;
	
	
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = A.copy()
    for i in range(N):
        B[i] -= i+1
    B.sort()
    m = B[N//2]
    ans = 0
    for i,a in enumerate(A):
        ans += abs(a-(m+i+1))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 26380
#include <bits/stdc++.h>
int distance(int a, int b) {
  int ans;
  if(a > b) ans = a - b;
  else ans = b - a;
  return ans;
}
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  int sum = 0;
  for(int i = 0; i < N; i++) {
    cin >> x.at(i);
    if(distance(x.at(i), K) > distance(x.at(i), 0)) sum += distance(x.at(i), 0);
    else sum += distance(x.at(i), K);
  }
  cout << sum * 2 << endl;
}

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

const int N = 305;

double dp[N][N][N];
bool udah[N][N][N];

int n;
int arr[N];

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

double solve(int three, int two, int one) {
  int zero = n - three - two - one;
  if (three < 0 || two < 0 || one < 0) return 0;
  if (zero == n) return 0;

  double &ret = dp[three][two][one];
  if (udah[three][two][one]) return ret;
  udah[three][two][one] = 1;

  ret = 1.0 * n;
  ret += 1.0 * three * solve(three-1, two+1, one);
  ret += 1.0 * two * solve(three, two-1, one+1);
  ret += 1.0 * one * solve(three, two, one-1);
  ret /= (n - zero);

  return ret;
}

double work() {
  int cnt[3] = {0};
  for (int i = 0 ; i < n ; i++) {
    cnt[arr[i]-1]++;
  }

  return solve(cnt[2], cnt[1], cnt[0]);
}

int main() {
  read();
  printf("%.13lf\n", work());
  return 0;
}

Measured memory_bytes: 246016
#反転数
import math
n = int(input())
A = list(map(int, input().split()))
C = 0
INFTY = 1e9 + 1

def merge(S, left, mid, right):
    global C
    n1 = mid - left
    n2 = right - mid
    l = S[left:left + n1]
    r = S[mid:mid + n2]
    l.append(INFTY)
    r.append(INFTY)
    i = 0
    j = 0
    for k in range(left, right):
        if l[i] < r[j]:
            S[k] = l[i]
            i += 1
        else:
            S[k] = r[j]
            C += n1 - i
            j += 1
        

def merge_inverse(S, left, right):
    if left + 1 < right:
        mid = math.ceil((left + right) / 2)
        merge_inverse(S, left, mid)
        merge_inverse(S, mid, right)
        merge(S, left, mid, right)
merge_inverse(A, 0, n)
print(C)



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

using namespace std;

int main(int argc, char const *argv[]) {
	long long n,k;
	std::cin >> n >> k;
	long long count = 0;
	long long a,b;
	b = k+1;
	while (b <= n) {
		count = count + (n/b) * (b-k);
		if (n % b >= k) {
			count = count + (n%b - k);
			if (k != 0) {
				count++;
			}
		}
		b++;
	}
	std::cout << count << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A;
        A = new int[N];
        int i;
        for (i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        int count = 0;

        for (int j = 0; j < A.length - 1; j++) {

            int keyindex = j;

            for (int k = j + 1; k < A.length; k++) {

                if (A[keyindex] > A[k]) {

                    keyindex = k;

                }
            }



            if (j == keyindex) {
                continue;
            }
            int temp = A[j];
            A[j] = A[keyindex];
            A[keyindex] = temp;
            count++;
        }


        for (int g = 0; g < N; g++) {
            System.out.print(A[g]);
            if (g < N - 1) {
                System.out.print(" ");
            }
            if (g == N - 1) {
                System.out.println("");
            }

        }

        System.out.println(count);
    }
}



Measured memory_bytes: 26348
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){  
  int h,w;
  cin >> h >> w;
  if(h==2||w==2){ cout << "No" << endl; return 0; }
  set<int> st={4,6,9,11};
  if(st.find(h)!=st.end()){
    if(st.find(w)!=st.end()){
      cout << "Yes" << endl; return 0;
    } else {
      cout << "No" << endl; return 0;
    }
  }
  set<int> et={1,3,5,7,8,10,12};
  if(et.find(h)!=et.end()){
    if(et.find(w)!=et.end()){
      cout << "Yes" << endl; return 0;
    } else {
      cout << "No" << endl; return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <iostream>
//#include <iomanip>
//#include <vector>
//#include <cmath>
//#include <algorithm>
using namespace std;


#define F first
#define PB push_back
#define MP make_pair

typedef unsigned long long ll;

ll p = pow(10, 9) + 7;





int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> vals(N);
    for(int i = 0; i < N; i++)
    {
        cin >> vals[i];
    }
    vector<int> dp(N, INT_MAX);
    dp[0] = 0;

    for(int i = 1; i < N; i++)
    {
       for(int j = i - 1; j >= max(0, i - K); j--)
       {
           dp[i] = min(dp[i], abs(vals[i] - vals[j]) + dp[j]);
       }
    }
    cout << dp[N - 1] << endl;

}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>

using namespace std;

#define long long long
#define ft(i, a, b) for (int i = (long)a ; i <= (long)b ; i++)
#define fd(i, a, b) for (int i = (long)a ; i >= (long)b ; i--)

const int MAXN = 1e5 + 5;
const long oo = 1e15;

long n;
long a[MAXN] , b[MAXN] , c[MAXN] , dp[MAXN][3];

void Solve() {
    dp[1][0] = a[1]; dp[1][1] = b[1]; dp[1][2] = c[1];
    ft(i , 2 , n) {
        dp[i][0] = max(dp[i - 1][1] , dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0] , dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][1] , dp[i - 1][0]) + c[i];
    }
    //cout << dp[2][0];
    cout << max(dp[n][0] , max(dp[n][1] , dp[n][2]));
}

void FastInput() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("VACATION.inp", "r", stdin);
    //freopen("VACATION.out", "w", stdout);
}

void Input() {
    cin >> n;
    ft(i , 1 , n) cin >> a[i] >> b[i] >> c[i];
}

int main() {
    FastInput();
    Input();
    Solve();
}

Measured memory_bytes: 8312
N = gets.to_i
s_list = N.times.map { gets.to_i }
list1 = s_list.select { |s| s % 10 == 0 }
list1_sum = list1.reduce(0, &:+)
list2 = s_list.select { |s| s % 10 != 0 }.sort
list2_sum = list2.reduce(0, &:+)
if list2.size == 0
  puts 0
elsif list2_sum % 10 != 0
  puts list1_sum + list2_sum
else
  ans = list1_sum + list2_sum - list2[0]
  puts ans
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int skor[100010], b, c, d, a;
int main()
{
    cin >> b >> c >> d;
    for (int i = 1; i <= b; i++)
    {
        skor[i] = c - d;
    }
    for (int i = 1; i <= d; i++)
    {
        cin >> a;
        skor[a]++;
    }
    for (int i = 1; i <= b; i++)
    {
        if (skor[i] > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
        
    }
    
}

Measured memory_bytes: 1024
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)
#define int long

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;


int gcd(int a, int b){
	if(a == 0){
		return b;
	}
	return gcd(b % a,a);
}

int findlcm(vector<int> arr, int n){
	int ans = arr[0];
	for(int i = 1 ; i < n ; i++){
		ans = (arr[i] * ans) / gcd(arr[i],ans);
	}
	return ans;
}

//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  long N;
  long M;

  cin >> N >> M;

  vector<long> a;
  a.resize(N);
  for(int i = 0 ; i < N ; i++){
  	cin >> a[i];
  	a[i] = a[i] / 2;
  }
  int lcm = findlcm(a,N);
  if(lcm > M){
    cout << 0 << endl;
    return 0;
  }

  for(auto i : a){
    if(lcm / i % 2 == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  cout << 1 + (M - lcm) / (2 * lcm) << endl;
  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

Measured memory_bytes: 1792