akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++) 
#define fr(i,a,b) for(int i=a;i<b;i++) 
#define F first 
#define S second 
#define mp make_pair 
#define pb push_back 
#define ll long long 
using namespace std;

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1LL; 
    x = x % p;
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;
        x = (x*x) % p;   
    } 
    return res; 
}

ll gcdExtended(ll a, ll b, ll *x, ll *y); 

int modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    ll res = (x%m + m) % m; 
    return res;
}  
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{  
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1);  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
} 

ll nCr(ll n,ll r,ll p){
	if(r>n-r)r=n-r;
	
	ll num = 1LL;
	ll den = 1LL;
	
	f(i,r){
		ll x = i+1;
		num = (num*(n-x+1))%p;
//		den = den*modInverse(x,p);
		num = (num*modInverse(x,p))%p;
//		num = num%p;
//		den = den%p;
	}
//	num = num*den;
//	num = num%p;
	return num;
}

void test(){
	ll n,a,b;
	cin>>n>>a>>b;
	ll p = 1e9 + 7;
	ll tot = power(2,n,p);
	tot = (tot-1LL+p)%p;
	ll a1 = nCr(n,a,p);
	ll a2 = nCr(n,b,p);
	tot = (tot-a1+p)%p;
	tot = (tot-a2+p)%p;
	cout<<tot<<"\n";
}

int main(){
	int t=1;
//	cin>>t;
	while(t--){
		test();
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	if((x-r < 0 || x+r > w) || (y-r < 0 || y+r > h)){
		printf("No\n");
	}else if((x-r>=0 && x+r<=w) && (y-r>=0 && y+r<=h)){
		printf("Yes\n");
	}
	return 0;

}

Measured memory_bytes: 1812
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int M = sc.nextInt();
    List<Integer> A = new ArrayList<>();
    int[][] BC = new int[M][2];

    for (int i = 0; i < N; i++) {
      A.add(sc.nextInt());
    }

    for (int i = 0; i < M; i++) {
      BC[i][0] = sc.nextInt();
      BC[i][1] = sc.nextInt();
    }

    sc.close();

    Arrays.sort(BC, (a,b) -> Integer.compare(b[1],a[1]));

    int count = 0;

    roop:for (int i = 0; i < M; i++) {
      for (int j = 0; j < BC[i][0]; j++) {
        A.add(BC[i][1]);
        count++;
        if (N <= count) {
          break roop;
        }
      }  
    }

    Collections.sort(A, Comparator.reverseOrder());

    long max = 0;

    for (int i = 0; i < N; i++) {
      max += A.get(i);
    }

    System.out.println(max);

  }

}

Measured memory_bytes: 101812
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define cases int tc;cin>>tc;while(tc--)
#define N 200003
#define M 2003
#define inf 1e18
#define Arena ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//int mod=1e9+7;
//int mod=998244353;

signed main()
{
    Arena
        
    int x,a;
    cin>>x>>a;
    cout<<(x<a ? 0:10);
    
    
    return 0;
}


Measured memory_bytes: 256
# Five, Five Everywhere

#インポート
from math import sqrt, ceil

#55,555以下の素数リスト作成

def sosu_list(N):
    temp = [True]*(N+1)
    temp[0] = temp[1] = False
    for i in range(2, ceil(sqrt(N+1))):
        if temp[i]:
            temp[i+i::i] = [False]*(len(temp[i+i::i]))                            
    primes = [ n for n in range(N+1) if temp[n] ]
    return primes

P = sosu_list(55555)

#5で割って余り1を抽出
P = [i for i in P if i % 5 == 1]

#入力
N = int(input())

#出力
for i in range(N):
	print("{} ".format(P[i]),end ="")

Measured memory_bytes: 3864
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

int main(int argc, const char * argv[]) {



    int a,b,c;
    cin >> a >> b >> c;
    
    if(a<b && b<c)
        cout << "Yes"  << endl;
    else
        cout << "No" <<endl;
    return 0;
    
}



Measured memory_bytes: 3100
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    
    int h;
    bool canlower = true;
    int prev = 0;
    while(cin >> h){
        if(prev > h + 1){
            cout << "No" << endl;
            return 0;
        }
        
        if(prev == h + 1){
            if(canlower){
                canlower = false;
                prev--;
            }else{
                cout << "No" << endl;
                return 0;
            }
        }
        
        if(prev < h){
            prev = h;
            canlower = true;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}


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

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

    int Ans;


    for (int i = 0; i < 10000; i++) {
       
        int Value = pow(K, i);
        Ans = i;

        if (Value > N) {
            break;
        }
    }

    cout << Ans; 

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

struct UnionFind {
  vector<int> c, s;
  UnionFind(size_t n) : c(n), s(n, 1) { iota(begin(c), end(c), 0); }
  int root(int i) { return c[i] == i ? i : (c[i] = root(c[i])); }
  bool same(int i, int j) { return root(i) == root(j); }
  void unite(int i, int j) {
    i = root(i); j = root(j);
    if (i != j) {
      if (s[i] > s[j]) { c[j] = i; s[i] += s[j]; }
      else { c[i] = j; s[j] += s[i]; }
    }
  }
  int size(int i) { return s[root(i)]; }
};
const i64 mod = 1e9 + 7;
i64 n, r;
vector<vector<i64>> g;
int main() {
  cin >> n >> r;

  UnionFind uf(n + 1);
  for (i64 i = 1; i <= n; ++i) {
    i64 p;
    cin >> p;
    uf.unite(i, p);
  }

  vector<bool> b(n + 1);
  vector<i64> ss(n + 1);
  for (i64 i = 1; i <= n; ++i) {
    i64 r = uf.root(i);
    if (!b[r]) {
      b[r] = true;
      ss[uf.size(r)]++;
    }
  }

  vector<i64> dp(n + 1);
  dp[0] = 1;
  for (i64 i = 1; i <= n; ++i) {
    if (ss[i] > 0) {
      vector<i64> dp_to(n + 1);
      for (i64 j = 0; j <= n; ++j) {
        dp_to[j] = dp[j];
        if (j >= i) dp_to[j] += dp_to[j - i];
        i64 k = j - (ss[i] + 1) * i;
        if (k >= 0) dp_to[j] -= dp[k];
        dp_to[j] += mod;
        dp_to[j] %= mod;
      }
      dp = dp_to;
    }
  }
  if (dp[r] > 0) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}



Measured memory_bytes: 12340
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int N, M;
    cin>>N>>M;
    vector<vector<int>> V(N);
    for (int i=0; i<M; i++)
    {
        int x, y;
        cin>>x>>y;
        V[x-1].push_back(y-1);
    }
    vector<int> T(N, -1);

    function<int(int)> f = [&](int p)
    {
        if (T[p] != -1)
            return T[p];
        int ans = 0;
        for (int e: V[p])
            ans = max(ans, f(e)+1);
        return T[p] = ans;
    };
    int ans = 0;
    for (int i=0; i<N; i++)
        ans = max(ans, f(i));
    cout<<ans<<endl;
}


Measured memory_bytes: 8832
import collections

n = input()
al = tuple(x for x in input().split())
aset = set(al)

# {number: count}
ccc = collections.Counter
counts_d = ccc(al)

# Count of count
v_counts = ccc(v for v in counts_d.values())

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]

# 352 ms で Accepted.


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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

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

const double EPS = 1e-10;

const int V = 100;
int n;

typedef struct edge_def {
  int from;
  int to;
  int cost;

  edge_def(int _from, int _to, int _cost) {
    from = _from;
    to   = _to;
    cost = _cost;
  }
} edge;

vector<edge> es[V];
int nm[V][V];

int main() {
  int i, j, k;
  memset(nm, 0, sizeof(nm));
  for (i=0; i<V; i++) es[i].clear();
  scanf("%d ", &n);
  for (i=0; i<n; i++) {
    int u, v;
    scanf("%d ", &u);
    scanf("%d ", &k);
    for (j=0; j<k; j++) {
      scanf("%d ", &v); 
      es[u-1].psb(edge(u-1, v-1, 0));
//      es[v-1].psb(edge(v-1, u-1, 0));
//      nm[u-1][v-1] = nm[v-1][u-1] = 1;
      nm[u-1][v-1] = 1;
    }
  }

  for (i=0; i<n; i++)
    for (j=0; j<n; j++)
      printf("%d%c", nm[i][j], ((j==n-1) ? '\n' : ' '));

	return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}


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

    int ans = 10000;
    rep(i,s.size()-2) {
        string tmp = "";
        int num = (s[i] - '0')*100 + (s[i+1] - '0')*10 + (s[i+2] - '0');
        ans = min(ans, abs(753 - num));
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
int N,M;
int x,y,z;
long long tmp =0;
long long answer=0;
int main(){
  cin >> N >>M;
  vector<vector<long long> > input(4,vector<long long>(N,0));
  vector<long long>ans(N);
  vector<long long>x(N);
  vector<long long>y(N);
  vector<long long>z(N);
  
  for(int i=0; i<N;i++){
    cin >> x.at(i) >>y.at(i) >>z.at(i);
  }
  
  for(int sx=-1; sx<3;sx+=2){
    for(int sy=-1; sy<3;sy+=2){
      for(int sz=-1; sz<3;sz+=2){
        for(int i=0; i<N;i++){
          ans.at(i) = sx*x.at(i) +sy*y.at(i) +sz*z.at(i);
        }
        sort(ans.begin(),ans.end());
        reverse(ans.begin(),ans.end());
        long long sum =0;
        for(int i=0; i<M;i++){
          sum += ans.at(i);
        }
        answer = max(answer,sum);
      }
    }
  }
  cout << answer << endl;
  return 0;
}




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

typedef long long int ll;
int main()
{
	ll a,b,k;
	cin >> a >> b >> k;
	if(k<=a)
	{
		a-=k;
		cout << a << " " << b << endl;
		return 0;
	}
	k-=a;
	a=0;
	if(k<=b)
	{
		b-=k;
		cout << a << " " << b << endl;
		return 0;
	}
	b=0;

	cout << a << " " <<  b << endl;

	return 0;	
}


Measured memory_bytes: 256
def judge(a, i, m, n, v, p):
    if i <= p: return True
    if a[i-1] + m < a[p-1]: return False
    check = (p + n - i)*m
    for j in range(p, i):
        check += a[i-1] + m - a[j-1]
    return check >= m*v

n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reverse=True)
ng = n + 1
ok = 0

while (ng - ok) > 1:
    mid = (ok + ng) // 2
    if judge(a, mid, m, n, v, p):
        ok = mid
    else:
        ng = mid
print(ok)

Measured memory_bytes: 14480
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int a, b;
  cin >> a >> b;
  cout << ceil((double)(a + b) / 2) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <math.h>
#include <cmath>
#include <ctime>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)


const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>void vecin(vector<TT>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}
template<class tt> struct counter {
	map<tt, int>mp;
	bool add(tt t, int xx) {
		if (!mp.count(t)) {
			mp[t] = xx;
			return true;
		}
		mp[t] += xx;
		if (!mp[t]) {
			mp.erase(t);
		}
		return false;
	}
};

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
long long modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

bool chmax(int& xx, int yy) {
	if (xx < yy) {
		xx = yy;
		return true;
	}
	return false;
}
bool chmin(int& xx, int yy) {
	if (xx > yy) {
		xx = yy;
		return true;
	}
	return false;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx <= 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int k, a = 7,b=1;
	set<int>se;
	cin >> k;
	if (k == 1||k==7) {
		cout << 1 << endl;
		return 0;
	}
	a %= k;
	while (!se.count(a)) {
		se.insert(a);
		a *= 10;
		a += 7;
		a %= k;
		if (a == 0) {
			cout << b+1 << endl;
			return 0;
		}
		b++;
	}
	cout << -1 << endl;
}

Measured memory_bytes: 50468
import numpy as np
from numba import jit

@jit('i4[:](i4,i4,i4[:])',cache = True)
def solve(n,k,A):
    l,r=0,0
    for i in range(k):
        B=np.zeros(n+1,dtype=np.int64)
        for x,y in enumerate(list(A)):
            l=max(0,x-y)
            r=min(n,x+y+1)
            B[l]+=1
            B[r]-=1
        A=np.cumsum(B[:-1])
        if A[A==n].size==n:
            break
    return A
n,k=map(int,input().split())
a=list(map(int,input().split()))
A=np.array(a)
X=solve(n,k,A)
print(*X,sep=' ')

Measured memory_bytes: 138628
import java.util.*;


public class Main {
    public static void main(String args[]){
            Scanner sc = new Scanner(System.in);
           
            int n = sc.nextInt();
            int[] color = new int[n];
            for (int i = 0; i < n; i++) {
                color[i] = sc.nextInt();
            }
            Arrays.sort(color);
            List<Integer> hoge = new ArrayList<Integer>();
            int tmp = 0;
            int sum = 0;
            for (int i = 0; i < n; i++) {
                if ((color[i] - sum)%2!=0 && (color[i]-sum) > 0 ) {
                    hoge.add(n-tmp);
                    sum = color[i];
                    tmp++;
                }else{
                    tmp++;
                }
            }

            int cond = 0;
            for (int i = 0; i < hoge.size(); i++) {
                cond = cond^hoge.get(i);
            }
            if (cond != 0) {
                System.out.println("first");
            }else{
                System.out.println("second");
            }
            sc.close();
        }
    
}



Measured memory_bytes: 51336
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

// 素因数分解
map<LL,LL> primeFactor;
void prime_factor(LL n) {
  //map< int64_t, int > ret;
  for(LL i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      primeFactor[i]++;
      n /= i;
    }
  }
  if(n != 1) primeFactor[n]++;
  //return ret;
}

void Main()
{
    LL n;cin>>n;
    prime_factor(n);

    LL result=0;
    for(auto x : primeFactor){
        for(LL i=1;i<=x.second;i++){
            result ++;
            x.second -= i;
        }
    }
    cout<<result<<endl;


	return;
}

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

Measured memory_bytes: 3660
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
int block;
int first[2000010], next[4000010], tail[4000010], ce[4000010], de[4000010], c[2000010], d[2000010], f[2000010][30], dep[2000010];
int x1[1000010], x3[1000010], x4[1000010], t[1000010], x5[1000010];
long long x2[1000010];
int n, Q, edge;
int dfs_clock, arr[2000010], start[2000010], end[2000010];
long long ans[2000010];
inline void addedge(int u, int v, int color, int dist) {
	edge++;
	next[edge] = first[u];
	first[u] = edge;
	tail[edge] = v;
	ce[edge] = color;
	de[edge] = dist;
}
void dfs(int u, int p) {
	dep[u] = dep[p] + 1;
	f[u][0] = p;
	for (int i = 1;i <= 20;i++) f[u][i] = f[f[u][i - 1]][i - 1];

	arr[++dfs_clock] = u;
	start[u] = dfs_clock;
	for (int e = first[u];e;e = next[e]) if (tail[e] != p) {
		int v = tail[e];
		c[v] = ce[e];
		d[v] = de[e];
		dfs(v, u);
	}
	arr[++dfs_clock] = u;
	end[u] = dfs_clock;
}
inline int lca(int u, int v) {
	if (dep[u] < dep[v]) std::swap(u, v);
	for (int i = 20;i >= 0;i--) if (dep[f[u][i]] >= dep[v]) u = f[u][i];
	if (u == v) return u;
	for (int i = 20;i >= 0;i--) if (f[u][i] != f[v][i]) {
		u = f[u][i];
		v = f[v][i];
	}
	return f[u][0];
}
bool comp(int u, int v) {
	if (x3[u] / block == x3[v] / block)
		return x4[u] < x4[v];
	else
		return x3[u] / block < x3[v] / block;
}
bool status[200010];
int count[200010];
long long sum[200010], sigma;
inline void trigger(int u) {
	if (!status[u]) {
		status[u] = true;
		sigma += d[u];
		sum[c[u]] += d[u];
		count[c[u]]++;
	} else {
		status[u] = false;
		sigma -= d[u];
		sum[c[u]] -= d[u];
		count[c[u]]--;
	}
}
int main() {
	edge = 0;
	scanf("%d%d", &n, &Q);
	for (int i = 1;i < n;i++) {
		int u, v, color, dist;
		scanf("%d%d%d%d", &u, &v, &color, &dist);
		addedge(u, v, color, dist);
		addedge(v, u, color, dist);
	}
	dfs_clock = 0;
	dfs(1, 0);
	for (int i = 1;i <= Q;i++) {
		int u, v;
		scanf("%d%lld%d%d", &x1[i], &x2[i], &u, &v);
		if (start[u] > start[v]) std::swap(u, v);
		x5[i] = lca(u, v);
		if (x5[i] == u || x5[i] == v) {
			x3[i] = end[v];
			x4[i] = end[u] - 1;
		} else {
			x3[i] = end[u];
			x4[i] = start[v];
		}
	}
	for (int i = 1;i <= Q;i++) t[i] = i;
	block = sqrt(dfs_clock);
	std::sort(t + 1, t + 1 + Q, comp);
	sigma = 0;
	int l = 1, r = 0;
	for (int i = 1;i <= Q;i++) {
		int u = t[i];
		while (l > x3[u]) {
			l--;
			trigger(arr[l]);
		}
		while (r < x4[u]) {
			r++;
			trigger(arr[r]);
		}
		while (l < x3[u]) {
			trigger(arr[l]);
			l++;
		}
		while (r > x4[u]) {
			trigger(arr[r]);
			r--;
		}
		//trigger(x5[u]);
		ans[u] = sigma - sum[x1[u]] + count[x1[u]] * x2[u];
		//trigger(x5[u]);
	}
	for (int i = 1;i <= Q;i++) printf("%lld\n", ans[i]);
	return 0;
}

Measured memory_bytes: 66944
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const long long MAX_V = 15;
const long long INF = 1LL<<60;

vector<vector<long long>> G(MAX_V, vector<long long>(1<<MAX_V, INF));
vector<vector<long long>> dist(MAX_V, vector<long long>(MAX_V, INF));

int main(){
    
    int V, E;
    cin >> V >> E;
    
    for (int i = 0; i < E; i++){
        long long s, t, d;
        cin >> s >> t >> d;
        
        dist[s][t] = d;
    }
    
    G[0][1] = 0;
    
    //
    for (int s = 0; s < (1<<V); s++){
        
        for (int from = 0; from < V; from++){
            
            for (int to = 0; to < V; to++){
                
                if (!(s & (1<<from))) continue;
                if (s & (1<<to)) continue;
                
                G[to][s | (1<<to)] = min(G[to][s | (1<<to)], G[from][s] + dist[from][to]);
            }
        }
    }
    
    long long ans = INF;
    
    for (int i = 1; i < V; i++){
        ans = min(ans, G[i][(1<<V)-1] + dist[i][0]);
    }
    
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
     
}



Measured memory_bytes: 6956
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int& x : A) cin >> x;

  int ac = accumulate(A.begin(), A.end(), 0LL);
  int sum = 0;
  int ans = 2 * ac;
  for (int i = 0; i < N; i++) {
    sum += A[i];
    ans = min(ans, abs(ac - 2 * sum));
  }
  cout << ans << endl;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
  ll n,k; cin>>n>>k;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  ll ans=0;
  ll ret=0;
  for(int i=40;i>=0;--i){
    ll mask=1LL<<i;
    ll cnt=0; // 現在見ている桁が1である数
    rep(j,n){
      if(a[j]&mask)++cnt;
    }
    if(cnt>=n-cnt){ // 1の方が多いので、反転しない方が得
      ans+=mask*cnt;
    }
    else {
      if(mask+ret<=k){ // 反転した方が得
          ans+=(n-cnt)*mask;
          ret+=mask;
      }
      else ans+=mask*cnt; // maskがkより大きくなるため反転したくてもできない
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
    
int main() {
    int A,B,C;
    cin>>A>>B>>C;
    if (A==B&&B==C&&A%2==0&&B%2==0&&C%2==0) {
        cout << -1 << endl;
        return 0;
    }
    int counter = 0;
    int D,E,F;
    while (A%2==0&&B%2==0&&C%2==0) {
        D=(B+C)/2;
        E=(A+C)/2;
        F=(A+B)/2;
        A=D;
        B=E;
        C=F;
        counter++;
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
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; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール
ll needed_k(vector<ll> &f, vector<ll> &a, ll ans) {

    ll n = a.size();
    vector<ll> b(n);
    REP(i, n) {
        if (a[i] * f[i] > ans) {
            b[i] = ans / f[i];
        } else {
            b[i] = a[i];
        }
    }

    // DUMPALL(b);

    ll bmin = INF;
    ll shugyo = 0;
    RANGE(i, n-1, 0) {
        if (!chmin(bmin, b[i])) {
            b[i] = bmin;
        }
    }
    // DUMPALL(a);
    // DUMPALL(b);
    REP(i, n) {
        shugyo += a[i] - b[i];
    }
    // DUMP(shugyo);

    return shugyo;

}

// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, k; cin >> n >> k;
    vector<ll> a(n), f(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> f[i];
    
    sort(ALL_OF(f), greater<ll>());
    sort(ALL_OF(a));

    ll ok = 1e13, ng = -1;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if (needed_k(f, a, mid) <= k) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;

}

Measured memory_bytes: 4992
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define End return 0;

int main ()
{
   ll a,b,c;
   cin>>a>>b>>c;
   ll p=c+.5;
   a=p/a;
   cout<<a*b<<endl;

    End;
}
/* pray for me
All is well
*/



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

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    for (int i = 0; i < N; i++)cin >> P[i];

    int min = P[0];
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (P[i] <= min) {
            ans++;
            //cout << "i:" << i << endl;
        }
        if (min > P[i]) {
            min = P[i];
           // cout << "max:" << max << endl;
        }
    }
    cout << ans;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

const int N = 1e5 + 10 ;

vi g[N] ;
int n ;
int m ;

void read ()
{
    cin >> n >> m ;

    for ( int i=0 ; i < m ; i ++ )
    {
        int a , b ;
        cin >> a >> b ;

        g[a].pb ( b ) ;
    }
}

int sz[N] ;

void dfs ( int node )
{
    sz[node] = 1 ;

    for ( auto &i : g[node] )
    {
        if ( sz[i] ) C ;
        dfs ( i ) ;
    }

    int maxx = 0 ;
    for ( int &i : g[node] )
    {
        maxx = max ( maxx , sz[i] ) ;
    }

    sz[node] += maxx ;
}

void solve ( int test_case )
{
    read () ;

    for ( int i = 1 ; i <= n ; i ++ )
    {
        if ( sz[i] ) C ;
        dfs ( i ) ;
    }

    int ans = 0 ;
    for ( int i = 1 ; i <= n ; i ++ )
        ans = max ( ans , sz[i] ) ;

    ans -- ;
    cout << ans << "\n" ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 8192
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = Integer.parseInt(s.next());
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            int p = Integer.parseInt(s.next());
            arr[i] = p;
        }
        int ret = Integer.MAX_VALUE;
        for (int x = 1; x <= 100; x++) {
            int tmp = 0;
            for (int a : arr) {
                tmp += Math.pow(a - x, 2);
            }
            if (tmp < ret) {
                ret = tmp;
            }
        }
        System.out.println(ret);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

// auto mod int
const int mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

signed main() {
    int d, t, s;
    cin >> d >> t >> s;
    if (d > t * s) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }
}

Measured memory_bytes: 3632
n = int(input())
a = [int(_) for _ in input().split()]
col = [0] * n
cnt = 0
for i in range(n):
    if a[i] >= 3200:
        col[i] = 8
        cnt += 1
    else:
        col[i] = a[i] // 400
ans_min = len(set(col))
ans_max = ans_min
if cnt == n:
    ans_min = 1
    ans_max = cnt
elif cnt > 0:
    ans_min -= 1
    ans_max = ans_min + cnt
print(ans_min, ans_max)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
n, l = map(int, input().split())
applepie = int(n * (l + (n - 1) / 2))
if l >= 0:
    print(applepie - l)
elif n + l > 0 and l < 0:
    print(applepie)
else:
    print(applepie - (l + n - 1))


Measured memory_bytes: 2940
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long ans = 0;
    
    for(long i=1;i<=n;i++){
      if(i%3 != 0 && i%5 != 0){
        ans += i;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35824
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int n, m;
vv(int) G(n, vector<int>());
int ans = 0;

void	dfs(int now, vector<bool> check)
{
	check[now] = 1;
	for (int i = 0; i < n; ++i)
	{
		if (check[i] == 0)
			break ;
		if (i == n-1)
		{
			++ans;
			return ;
		}
	}
	for (auto v: G[now])
	{
		if (check[v])
			continue ;
		dfs(v, check);
	}
}

int		main(void)
{
	cin >> n >> m;
	G.assign(n, vector<int>());

	vector<bool> check(n);
	for (int i = 0; i < m; ++i)
	{
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0, check);
	cout << ans << endl;
}



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

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

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

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

    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z), ab;
    for(int i = 0; i < x; ++i)  cin >> a[i];
    for(int i = 0; i < y; ++i)  cin >> b[i];
    for(int i = 0; i < z; ++i)  cin >> c[i];
    for(int i = 0; i < x; ++i){
        for(int j = 0; j < y; ++j){
            ab.emplace_back(a[i] + b[j]);
        }
    }
    sort(ab.begin(), ab.end());
    ll lb = 0, ub = 1e+11;
    while(ub - lb > 1){
        ll X = (lb + ub) >> 1;
        int cnt = 0;
        for(int i = 0; i < z; ++i){
            cnt += ab.end() - lower_bound(ab.begin(), ab.end(), X - c[i]);
        }
        if(cnt >= k)    lb = X;
        else    ub = X;
    }
    vector<ll> ans;
    int sz = ab.size();
    for(int i = 0; i < z; ++i){
        int st = lower_bound(ab.begin(), ab.end(), ub - c[i]) - ab.begin();
        for(int j = st; j < sz; ++j){
            ans.emplace_back(c[i] + ab[j]);
        }
    }
    sort(ans.begin(), ans.end(), greater<ll>());
    while(ans.size() < k)   ans.emplace_back(lb);
    for(int i = 0; i < k; ++i)  cout << ans[i] << '\n';
}

Measured memory_bytes: 10608
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int initial(int n){
  while(n>=10){
    n/=10;
  }
  return n;
}

int keta(int n){
  int i=0;
  while(n>=10){
    n/=10;
    i++;
  }
  return i+1;
}

int remove(int n){
  return n%int(pow(10,keta(n)-1))/10;
}

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

  vector<ll> dp(n+1,0);
  dp[0]=0;
  REP2(i,1,n+1){
    ll v;
    if(i%10==0) v=0;
    else if(i<10){
      v=1;
    }else{
      int ini=initial(i),k=keta(i);
      if(i%10==0) v=0;
      else if(ini<i%10) v=222222%int(pow(10,k-2));
      else if(ini>i%10) v=222222%int(pow(10,k-1));
      else{
        v=((k==2)? 3:(remove(i)+111112%int(pow(10,k-2)))*2+1);
      }
    }
    dp[i]=dp[i-1]+v;
    // cout<<dp[i]<<endl;
  }

  cout<<dp[n]<<endl;

  return 0;

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<math.h>
#define N 100005
#define K 200005
#define MOD (int)1e9+7
#define ll long long int
using namespace std;


int main() {
   int n;
   cin>>n;
   vector<double> p(n);
   for(int i=0;i<n;i++)
   {
       cin>>p[i];
   }
   vector<double> dp(n+1);
   dp[0]=1;
  for(int i=0;i<n;i++)
  {
      for(int j=i+1;j>=0;j--)
      {
          dp[j]=(j==0? 0:dp[j-1]*p[i])+dp[j]*(1-p[i]);
      }
  }
    double ans=0;
    for(int i=n/2+1;i<=n;i++)
    {   
       
        ans+=dp[i];
    }
    cout<<setprecision(10)<<fixed<<ans<<endl;
}

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

namespace Application
{
    class MainClass
    {
        const long MOD = 1000000007;

        public static void Main(string[] args)
        {
            var xy = Console.ReadLine().Split();
            var x = long.Parse(xy[0]);
            var y = long.Parse(xy[1]);

            if ((x + y) % 3 != 0)
            {
                Console.WriteLine(0);
                return;
            }

            var n = (2 * y - x) / 3;
            var m = (2 * x - y) / 3;

            if (n < 0 || m < 0)
            {
                Console.WriteLine(0);
                return;
            }

            var ans = divM(
                factM(n + m),
                factM(n) * factM(m) % MOD);

            Console.WriteLine(ans);
        }

        static long factM(long n)
        {
            var ans = 1L;
            for (long i = 2; i <= n; i++)
            {
                ans *= i;
                ans %= MOD;
            }
            return ans;
        }

        static long powM(long n, long m)
        {
            if (m == 0) return 1;
            if (m % 2 == 1) return n * powM(n, m - 1) % MOD;
            var x = powM(n, m / 2);
            return x * x % MOD;
        }

        static long divM(long n, long m)
        {
            return n * powM(m, MOD - 2) % MOD;
        }
    }
}


Measured memory_bytes: 13140
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int a = 0;
    int b = 0;
    for(int i = 0; i < s.length(); i++) {
      if(s.charAt(i) == 'A') {
        a = i;
        break;
      }
    }
    for(int i = s.length() - 1; i >= 0; i--) {
      if(s.charAt(i) == 'Z') {
        b = i;
        break;
      }
    }
    System.out.println(b - a + 1);
  }
}

Measured memory_bytes: 14448
s = gets.chomp
K = gets.chomp.to_i

N = s.size

dp = Array.new(105) { Array.new(4) { Array.new(2, 0)}}
dp[0][0][0] = 1

(0...N).each do |i|
  (0..K).each do |j|
    (0..1).each do |k|
      nd = s[i].to_i
      (0..9).each do |d|
        ni = i + 1
        nj = d != 0 ? j + 1 : j
        nk = k
        next if nj > K
        if k == 0
          next if d > nd
          nk = 1 if d < nd
        end
        dp[ni][nj][nk] += dp[i][j][k]
      end
    end
  end
end

p dp[N][K][0] + dp[N][K][1]


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

int sumOfDigits(int i) {
	int sum = 0;
	while (i > 0) {
		sum += (i % 10);
		i /= 10;
	}
	return sum;
}

int main() {
	int n, a, b;
	int sum = 0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) {
		int tmp = sumOfDigits(i);
		if (a <= tmp && tmp <= b) {
			sum += i;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

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

    if (n == 0) {
        cout << x;
        return 0;
    }

    vector<int> p(102, 0);
    vector<int> d(n, 0);
    int tmp;

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

    int min=1000, max=1000;

    for (int i = x; i >= 0; i--) {
        if (p[i] == 0) {
            min = i;
            break;
        }
    }

    for (int i = x; i <= 101; i++) {
        if (p[i] == 0) {
            max = i;
            break;
        }
    }

    int dmin, dmax;
    dmin = abs(min - x);
    dmax = abs(max - x);
    
    if (dmin <= dmax) {
        cout << min;
    }
    else {
        cout << max;
    }

    return 0;
}

Measured memory_bytes: 3632
#include  <stdio.h>

int main(){
    int a,b;
    scanf ("%d %d %d", &a,&b);
    if (a<10){
    int c = 100*(10-a);
    int d = b+c;
        printf("%d",d);
    }
    else{
        int e = b;
        printf("%d",e);
    }
    return 0;
}

Measured memory_bytes: 1712
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

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

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  std::vector<ll> a(n),b(n),c(n);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n) cin>>c[i];
  // all(sort(a));
  sort(all(a));
  sort(all(b));
  sort(all(c));
  // all(sort(b));
  // all(sort(c));
  ll ans = 0;
  rep(i,n){
    ans += (distance(a.begin(),lower_bound(a.begin(),a.end(),b[i]))) * (n-(distance(c.begin(),upper_bound(c.begin(),c.end(),b[i]))));
    // ans += (distance(a.begin(),upper_bound(a.begin(),a.end(),b[i])-1)) * (n-(distance(c.begin(),upper_bound(c.begin(),c.end(),b[i]))));
    // cout<<(distance(a.begin(),lower_bound(a.begin(),a.end(),b[i])))<<" "<<(n-(distance(c.begin(),upper_bound(c.begin(),c.end(),b[i]))))<<endl;
  }
  cout<<ans<<endl;
}

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


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define int long long
int n,l,r,a[100001],b[100001];
main(){
  int ans=1e9+7;
  cin>>l>>r;
  //int ans=0;
  r(i,2){
    int a=l;
    if(i) a=l*(-1);//cout<<l<<endl;
    int c;
    c=abs(abs(a)-abs(r));//cout<<c<<endl;
    a+=c;
    r(j,2){
      if(j)a*=(-1);
      if(a==r)ans=min(c+i+j,ans);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256