akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
//#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 1000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
int main(){
    int n;
    std::cin >> n;
    int ans=0;
    ans+=(n/500)*1000;
    n%=500;
    std::cout << ans+(n/5)*5 << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
typedef long long int  ll;
int n,k;

ll t[100000];
//pは0～100000*10000の間にある。
int check(ll p){
	int i=0;
    for(int j=0;j<k;j++){
    	ll s=0;
        while(s+t[i]<=p){
        	s+=t[i];
        
        i++;
        if(i==n) return n;
        }
    }    
    return i;
}

int solve(){
	ll left=0;
    ll right=100000*10000;
    ll mid;
    while(right - left>1){
    	mid =(left+right)/2;
        int v=check(mid);
        if(v>=n)right=mid;
        else left=mid;
    }
    return right;
}


int main() {
	cin>>n>>k;
  	for(int i=0;i<n;i++){
    	cin>>t[i];
    }
    ll ans=solve();
    cout<<ans<<endl;
}



Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,i,wa=0,hiku=0,b;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    wa+=a[i];
    if(i%2==1){
      hiku+=a[i];
    }
  }
  b=(wa/2)-hiku;
  for(i=0;i<n;i++){
    cout<<2*b<<" ";
    b=a[i]-b;
  }
}
    


Measured memory_bytes: 1664
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
//#include <boost/multiprecision/cpp_int.hpp>

#define BIT(a) (1 << (a))
#define EPS (1e-10)

using namespace std;
//using namespace boost::multiprecision;

const long long MOD = 1000000007;
const int COUNTER_CLOCKWISE = 1;
const int CLOCKWISE = -1;
const int ONLINE_BACK = 2;
const int ONLINE_FRONT = -2;
const int ON_SEGMENT = 0;

class Point{
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}
    
    Point operator+(Point p){return Point(x + p.x, y + p.y);}
    Point operator-(Point p){return Point(x - p.x, y - p.y);}
    Point operator*(double a){return Point(a * x, a * y);}
    Point operator/(double a){return Point(x / a, y / a);}

    bool operator < (const Point &p) const {
        return y != p.y ? y < p.y : x < p.x;
    }

    double norm(){return x * x + y * y;}
};
typedef Point Vector;
typedef vector<Vector> Polygon;

double cross(Vector a, Vector b){
    return a.x*b.y - a.y*b.x;
}

double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}

int ccw(Point p0, Point p1, Point p2){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if (cross(a, b) > EPS)return COUNTER_CLOCKWISE;
    if (cross(a, b) > -EPS)return CLOCKWISE;
    if (dot(a, b) < -EPS)return ONLINE_BACK;
    if (a.norm() < b.norm())return ONLINE_FRONT;

    return ON_SEGMENT;
}

Polygon andrewScan(Polygon s){
    Polygon u, l;
    if (s.size() < 3) return s;
    sort(s.begin(), s.end());
    u.push_back(s[0]);
    u.push_back(s[1]);
    l.push_back(s[s.size()-1]);
    l.push_back(s[s.size()-2]);
    
    for (size_t i = 2; i < s.size(); i++){
        for (size_t n = u.size(); n >= 2 && ccw(u[n-2], u[n-1], s[i]) == COUNTER_CLOCKWISE; n--){
            u.pop_back();
        }
        u.push_back(s[i]);
    }

    for (int i = (int)s.size() - 3; i >= 0; i--){
        for (size_t n = l.size(); n >= 2 && ccw(l[n-2], l[n-1], s[i]) == COUNTER_CLOCKWISE; n--){
            l.pop_back();
        }
        l.push_back(s[i]);
    }

    reverse(l.begin(), l.end());
    for (size_t i = u.size() - 2; i >= 1; i--) l.push_back(u[i]);

    return l;
}

long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}


int bunpu[10];

int main(void){
    int N;
    cin >> N;
    double tmp[] = {0, 165, 170, 175, 180, 185};
    for (int i = 0; i < N; i++){
        double x;
        cin >> x;
        for (int j = 5; j >= 0; j--){
            if (tmp[j] <= x){
                bunpu[j]++;
                break;
            }
        }
    }
    for (int i = 0; i < 6; i++){
        cout << i+1 << ":";
        for (int j = 0; j < bunpu[i]; j++){
            cout << "*";
        }
        cout << endl;
    }


    return 0;
}   



Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, x;
int l[100];

signed main() {
	int i;
	
	cin >> n >> x;
	rep(i, n) cin >> l[i];
	
	int s = 0;
	rep(i, n) {
		s += l[i];
		if (s > x) break;
	}
	cout << i + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())

X = [int(i) for i in input().split()]

X.sort()

Y = []

for i in range(len(X) - 1):
    Y.append(X[i+1] - X[i])

Y.sort()

if M-N <= 0:
    ans = 0
else:
    ans = sum(Y[:M-N])

print(ans)

Measured memory_bytes: 13840
package main

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

func main() {
	S := ReadInt()
	ans := 0
	for k := 1; k <= S/3; k++ {
		ans += partition(S-k*3, k)
		ans %= Mod
	}
	fmt.Println(ans)
}

func partition(n, k int) int {
	return ModCombination(n+k-1, n)
}

const Mod = int(1e9) + 7

func ModCombination(n, k int) int { return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod }

var fac, finv, inv []int

func init() {
	const MAX = 5 * 1e5
	fac, finv, inv = make([]int, MAX+1), make([]int, MAX+1), make([]int, MAX+1)
	fac[0], fac[1], finv[0], finv[1], inv[1] = 1, 1, 1, 1, 1
	for 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
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 14024
#include<stdio.h>
int main(void){
  int a,b,c,h,g,m,n,k;
  scanf("%d%d%d%d%d", &h, &m, &g, &n, &k);
  a=60*h+m;
  b=60*g+n;
  c=b-a;
  printf("%d", c-k);
  return 0;
}
  

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#define Abra_Ka_Dabra ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

const long long mod = 1e9 + 7;
const double PI = acos(-1);
const double EPS = 1e-9;

bool comp(pair<int, int> a, pair<int, int> b) {
	if (a.second == b.second) return a.first > b.first;
	return a.second < b.second;
}

bool isLeap(int a) {
	if (a % 100 == 0) {
		if (a % 400 == 0) return true;
		else return false;
	} else if (a % 4 == 0) return true;
	return false;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	Abra_Ka_Dabra

	string x;
	cin>>x;
	if(x[2]==x[3] && x[4]==x[5]) cout<<"Yes\n";
	else cout<<"No\n";

	return 0;
}


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

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

  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    int x;
    cin >> x;

    ans+=min(x,k-x);
  }

  cout << ans*2 << endl;  
}

Measured memory_bytes: 384
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
L = LI()
if max(L)*2 < sum(L):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 63340
#include <bits/stdc++.h>
#define DAU  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int mat[4][4], n, x;
bool viz[102], ok1, ok2;
int main() {
    DAU
    for (int i = 1; i <= 3; ++i)
        for (int j = 1; j <= 3; ++j)
            cin >> mat[i][j];
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        viz[x] = true;
    }
    for (int i = 1; i <= 3; ++i) {
        ok1 = ok2 = true;
        for (int j = 1; j <= 3; ++j) {
            if (!viz[mat[i][j]])
                ok1 = false;
            if (!viz[mat[j][i]])
                ok2 = false;
        }
        if (ok1 || ok2) {
            cout << "Yes";
            PLEC
        }
    }
    if ((viz[mat[1][1]] && viz[mat[2][2]] && viz[mat[3][3]]) || (viz[mat[1][3]] && viz[mat[2][2]] && viz[mat[3][1]])) {
        cout << "Yes";
        PLEC
    }
    cout << "No";
    PLEC
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:

ll ary[100010];

int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> ary[i];

	ll ans=ary[0]-1;
	ary[0]=1LL;
	ll limit=2LL;
		
	rep(i,1,n){
		if(ary[i]<limit) continue;
		if(ary[i]==limit){
			limit++;
			continue;
		}

		ans+=(ary[i]-1)/limit;
	}

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e6 + 5, MOD = 1e9 + 7;
ll f[MN], inv[MN];

ll fp(ll x, ll y, ll m = MOD) {
    ll r = 1;
    for (x %= m; y; y >>= 1, x = (x * x) % m) 
        if (y & 1) r = (r * x) % m;
    return r;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    f[0] = 1;
    for (int i = 1; i <= 1e6; i++) f[i] = (f[i - 1] * i) % MOD;
    inv[(int) 1e6] = fp(f[(int) 1e6], MOD - 2);
    for (int i = 1e6 - 1; i >= 0; i--) inv[i] = (inv[i + 1] * (i + 1)) % MOD;
    int X, Y; cin >> X >> Y;
    ll ans = 0;
    for (int i = 0; i <= X / 2; i++) {
        int j = X - i * 2;
        if (i + j * 2 == Y) {
            ans = (ans + (f[i + j] * inv[i] % MOD * inv[j] % MOD)) % MOD;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 19244
def is_prime(n: int):
    """自然数nが素数であるかを判定する
    計算量: O(sqrt(N))
    """
    if n == 1:
        return False
    for k in range(2, int(n**0.5) + 1):
        if n % k == 0:
            return False
    return True


x = int(input())

while True:
    if is_prime(x):
        print(x)
        exit()
    else:
        x += 1

Measured memory_bytes: 38512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <regex>
#include <math.h>
typedef long long ll;
using namespace std;

int main(void){
  ll n , m, sum;
  sum = 0;
  cin >> n;
  vector<ll> t(n);
  for(ll i = 0;i < n; i++){
    cin >> t[i];
    sum += t[i];
  }
  cin >> m;
  vector<ll> p(m),x(m);
  for(ll i = 0;i < m;i++){
    cin >> p[i] >> x[i];
  }
  for(ll i = 0; i < m; i++){
    cout << sum - t[p[i] - 1] + x[i] << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << y1 + x2 - y2 << " " << y2 - x1 + x2 << " " << y1- y2 + x1 << " "  << - x1 + y1 + x2 << endl;
    return 0;
}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll arr[55];
ll arr1[55];

int main() {
	scanf("%lld", &N);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
		arr1[i] = arr[i];
	}
	sort(arr1, arr1 + N);
	ll cnt = 0;
	for(int i = 0; i < N; i++) {
		if(arr[i] != arr1[i]) {
			cnt++;
		}
	}
	if(cnt == 0 || cnt == 2) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

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

    cout << (n*n-a) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int K;
  cin >> K;

  irep(i, K) {
    int a = A;
    int b = B * pow(2, (int)i);
    int c = C * pow(2, (int)(K - i));
    if (a < b && b < c) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
	
int func(int x){
	
	if(x%2==0){
		
		return x/2;
		
	}
	else{
		
		return 3*x+1;
		
	}
	
}

int main() {
	
	int s,t;
	cin >>s;
	
	vector<int> vec(1000000);
	vec.at(0)=s;
	
	bool a=0;
	
	for(int i=0; i<1000000; i++){
		
		if(i==0){
			
			vec.at(i)=s;
			
		}
		else{
			
			vec.at(i)=func(vec.at(i-1));
			for(int j=0; j<1000000; j++){
				
				if(j>=i){
					
					break;
					
				}
				
				if(vec.at(i)==vec.at(j)){
					
					cout <<i+1 <<endl;
					a=1;
					break;
				}
				
			}
			
			if(a){
				
				break;
				
			}
			
		}
		
	}
	
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	ini(n);
	int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	out(a[n-1]);
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

type Graph = Vec<Vec<usize>>;

fn build_graph(n:usize,edges:Vec<(usize,usize)>) -> Graph{
    let mut g = vec![Vec::<usize>::new();n];
    for (a,b) in edges {
        g[a].push(b);
        g[b].push(a);
    }
    g
}

fn dfs_sz(v:usize,pre:usize,g:&Graph,mut sz:&mut Vec<i64>) -> i64{
    sz[v] = 1;
    for &to in &g[v] {
        if pre==to {
            continue
        }
        sz[v] += dfs_sz(to,v,&g,&mut sz);
    }
    sz[v]
}

fn dfs(v:usize,pre:usize,c:&Vec<usize>,g:&Graph,sz:&Vec<i64>,mut vst:&mut Vec<Vec<usize>>,mut buf:&mut Vec<i64>,mut rest:&mut Vec<i64>,mut ans:&mut Vec<i64>){
    vst[c[v]].push(v);
    let mut sum = 0i64;
    let mut sqsum = 0i64;
    for &to in &g[v] {
        if to==pre {
            continue;
        }
        let pre_buf = buf[v];
        dfs(to,v,&c,&g,&sz,&mut vst,&mut buf,&mut rest,&mut ans);
        let rsz = sz[to] - (buf[v] - pre_buf);
        sum+=rsz;
        sqsum+=rsz*rsz;
    }
    vst[c[v]].pop();

    rest[c[v]]-=sz[v]-buf[v];
    ans[c[v]]+=(sz[v]-buf[v])*(rest[c[v]]+1);
    ans[c[v]]+=(sum*sum-sqsum)/2;
    
    if !vst[c[v]].is_empty() {
        let par = *vst[c[v]].last().unwrap();
        buf[par] += sz[v];
    }

}

fn main() {
    let (n,g,c) = {
        input! {
            n:usize,
            mut c:[usize;n],
            mut edges:[(usize,usize);n-1]
        };
        c.iter_mut().for_each(|x|*x-=1);
        edges.iter_mut().for_each(|(a,b)|{*a-=1;*b-=1});
        let g = build_graph(n,edges);
        (n,g,c)
    };
    
    let mut sz = vec![0i64;n];
    dfs_sz(0,n,&g,&mut sz);

    let mut buf = vec![0i64;n];
    let mut rest = vec![n as i64;n];
    let mut ans = vec![0i64;n];
    let mut vst = vec![Vec::<usize>::new();n];
    dfs(0,n,&c,&g,&sz,&mut vst,&mut buf,&mut rest,&mut ans);
    
    
    for v in ans {
        println!("{}",v);
    }

}


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

using namespace std;
using ll = long long;


int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h + 2, vector<char>(w + 2 ,'#'));
    for(int i = 1; i <= h; i++)for(int j = 1; j <= w; j++)cin >> s[i][j];
    vector<vector<int>> sum(h + 2, vector<int>(w + 2));

    for(int i = 1; i <= h+1; i++){
        int cnt = 0;
        int past = 0;
        for(int j = 1; j <= w+1; j++){


            if(s[i][j] == '#'){
                for(int k = past; k < j; k++)sum[i][k] += cnt;
                cnt = 0;
                past = j + 1;
            }else{
                cnt++;
            }

            
        }
    }


    for(int i = 1; i <= w + 1; i++){
        int cnt = 0;
        int past = 0;

        for(int j = 1; j <= h + 1; j++){

            if(s[j][i] == '#'){
                for(int k = past; k < j; k++)sum[k][i] += cnt;
                cnt = 0;
                past = j + 1;
            }else{
                cnt++;
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= h; i++)ans = max(ans, *max_element(sum[i].begin(), sum[i].end()));
    cout << ans - 1 << endl;
}

Measured memory_bytes: 19968
/**********************************/
	#include <bits/stdc++.h>
	#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define lli long long int
	#define pb push_back
	#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
	#include <ext/pb_ds/assoc_container.hpp> 
	#include <ext/pb_ds/tree_policy.hpp>
	#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
	using namespace __gnu_pbds;
	using namespace std;
	const lli MAX=1000000;
	const lli mod=1e9+7;
	/**********************************/
	auto cmp=[](const pair<lli,string>&p1,const pair<lli,string>&p2){return (p1.first>p2.first)||(p1.first==p2.first&&p1.second<p2.second);};
	struct order{
		template<class T>
		bool operator()(T const& a,T const& b){
			if(a.first==b.first)
				return a.second<b.second;
			return a.first>b.first;
		}
	};
	struct HASH{
	  size_t operator()(const pair<lli,lli>&x)const{
	    return hash<lli>()(((long long)x.first)^(((long long)x.second)<<32));
	  }
	};
	/**********************************/

lli maxsubarray(vector<lli> &v,lli n){
	lli max_so_far=v[0],cur_max=v[0],i;
	for(i=1;i<n;i++){
		cur_max = max(v[i],cur_max+v[i]);
		max_so_far=max(cur_max,max_so_far);
	}
	return max_so_far;
}
void multiply(lli F[(lli)2][(lli)2], lli M[(lli)2][(lli)2]); 
  
void power(lli F[(lli)2][(lli)2], lli n); 
  
lli fib(lli n) 
{ 
  lli F[(lli)2][(lli)2] = {{1,1},{1,0}}; 
  if (n == 0) 
    return 0; 
  power(F, n-1); 
  return F[0][0]; 
} 

void power(lli F[(lli)2][(lli)2], lli n) 
{ 
  if( n == 0 || n == 1) 
      return; 
  lli M[(lli)2][(lli)2] = {{1,1},{1,0}}; 
  
  power(F, n/2); 
  multiply(F, F); 
  
  if (n%2 != 0) 
     multiply(F, M); 
} 
  
void multiply(lli F[(lli)2][(lli)2], lli M[(lli)2][(lli)2]) 
{ 
  lli x =  (((F[0][0]%mod)*(M[0][0]%mod))%mod + ((F[0][1]%mod)*(M[1][0]%mod))%mod)%mod;
  lli y =  (((F[0][0]%mod)*(M[0][1]%mod))%mod + ((F[0][1]%mod)*(M[1][1]%mod))%mod)%mod;  
  lli z =  (((F[1][0]%mod)*(M[0][0]%mod))%mod + ((F[1][1]%mod)*(M[1][0]%mod))%mod)%mod; 
  lli w =  (((F[1][0]%mod)*(M[0][1]%mod))%mod + ((F[1][1]%mod)*(M[1][1]%mod))%mod)%mod; 
  
  F[0][0] = x; 
  F[0][1] = y; 
  F[1][0] = z; 
  F[1][1] = w; 
} 
lli dp[100005];
lli solve(lli h[],lli i,lli n){
	if(i>=n-1)
		return 0;
	if(dp[i]!=-1)
		return dp[i];
	lli ans = min((abs(h[i+1]-h[i])+solve(h,i+1,n)),(abs(h[i+2]-h[i])+solve(h,i+2,n)));
	dp[i]=ans;
	return ans;
}

int main(){
	fast;
	lli n,i;
	cin>>n;
	lli h[n];
	for(i=0;i<n;i++){
		cin>>h[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<solve(h,0,n);
}

Measured memory_bytes: 5760
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{

long int a,b,c=0;
cin>>a>>b;
if(b==1)
cout<<c;
else if(b<=a)
cout<<1;
else
{
	if((b-a)%(a-1)!=0)
	c=(b-a)/(a-1)+1;
	else
	c=(b-a)/(a-1);
	cout<<++c;
	}
				return 0;
				}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

template<class T>
T gcd(T n,T m){
    if(n>m) return gcd(m,n);
    else if(n==0) return m;
    else return gcd(m-n*(m/n),n);
}

int main(){
    ll n,a[100010],c[100010]={},d[100010]={},ans=0;
    cin>>n;
    fr(i,n) cin>>a[i];
    fr(i,n) c[i+1]=gcd(c[i],a[i]);
    ifr(i,n) d[i]=gcd(d[i+1],a[i]);
    fr(i,n) ans=max(ans,gcd(c[i],d[i+1]));
    cout<<ans<<endl;
}

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

int val[200010];
vector<int> edge[200010];
int ans[200010];

void dfs(int from, int par, vector<int>& dp) {
	if(dp.back() < val[from]) {
		ans[from] = dp.size();
		dp.push_back(val[from]);
		for(int to : edge[from]) {
			if(to == par) continue;
			dfs(to, from, dp);
		}
		dp.pop_back();
	} else {
		int idx = lower_bound(dp.begin(), dp.end(), val[from]) - dp.begin();
		int pre = dp[idx];
		ans[from] = dp.size() - 1;
		dp[idx] = val[from];
		for(int to : edge[from]) {
			if(to == par) continue;
			dfs(to, from, dp);
		}
		dp[idx] = pre;
	}
}

int main() {
	int n; cin >> n;
	for(int i = 0; i < n; ++i) cin >> val[i];
	for(int i = 0; i < n - 1; ++i) {
		int u, v; cin >> u >> v;
		--u, --v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	vector<int> dp = {0};
	dfs(0, -1, dp);
	for(int i = 0; i < n; ++i) {
		cout << ans[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 30268
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <math.h>
#define llint long long int
using namespace std;

llint ceil1(llint x,llint y){
  if(x%y==0) return x/y;
  else return (x/y)+1;
}

int main(void){
  int i;
  llint a,b,c,t;
  llint T,A;
  int N;

  cin>>N;
  a=1;
  b=1;
  for(i=1;i<=N;i++){
    cin>>T>>A;

    t=(llint)(max(ceil1(a,T),ceil1(b,A)));
    a=t*T;
    b=t*A;
  }
  c=a+b;
  printf("%lld\n",c);
  return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define LL long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)
#define YES "Yes"
#define NO "No"

using namespace std;

typedef pair<int, int> P;

class BCountBalls {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        LL N,A,B;
        cin>>N>>A>>B;
        cout << (N/(A+B)*A+min(A, N%(A+B)));
    }
};

int main() {
	BCountBalls solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n;
	int a[101];
	int total=0;

	cin>>n;

	rep(i,n){
		cin>>a[i];
	}

	sort(a,a+n);

	rep(i,n-1){
		total+=a[i+1]-a[i];
	}

	cout<<total<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class DDivRemNumber {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long N = in.nl();
            long ans = 0;
            for (long div = 1; div * div < N; div++) {
                if (N % div == 0) {
                    long m = N / div - 1;
                    if (div < m) {
                        ans += m;
                    }
                }
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public long nl() {
            return Long.parseLong(ns());
        }

    }
}



Measured memory_bytes: 22484
use proconio::marker::Chars;
use proconio::{fastout, input};
use std::cmp::{max, min};

#[fastout]
fn main() {
    input! {
        s: Chars
    };

    let s: Vec<char> = s;
    let mut result = 753;

    for i in 0..s.len() - 2 {
        let s1: i32 = s[i] as i32 - 48;
        let s2: i32 = s[i + 1] as i32 - 48;
        let s3: i32 = s[i + 2] as i32 - 48;

        let x = s1 * 100 + s2 * 10 + s3;
        result = min(result, (753 - x).abs());
    }

    println!("{}", result)
}


Measured memory_bytes: 2124
import sys
import math

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline


def f(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x / B)


A, B, N = map(int, input().split())
x = N
if N >= B - 1:
    x = B - 1
print(f(A, B, x))


Measured memory_bytes: 9016
program main
  implicit none
  integer(8) :: w, h, x, y, fuku
  real(8) :: half_area
  read (*, *) w, h, x, y
  half_area = dble(w) * dble(h) * 0.5
  if (x * 2 == w .and. y * 2 == h) then
    fuku = 1
  else
    fuku = 0
  end if
  write (*, "(f0.1, ' ', i0)") half_area, fuku
end program main


Measured memory_bytes: 256
#include<stdio.h>

#define PI 3.141592653589

int main(void)
{
	double r,S,L;
	
	scanf("%lf",&r);
	
	S=PI*r*r;
	L=2*PI*r;
	
	printf("%lf %lf\n",S,L);
	
	return 0;
}


Measured memory_bytes: 2116
#include<bits/stdc++.h>
using namespace std;
namespace io{
    const int l=1<<20;
    char buf[l],*s,*t,c;
    inline void gc(){
        if(s==t){
            t=(s=buf)+fread(buf,1,l,stdin);
            c=s==t?EOF:*s++;
        }else c=*s++;
    }
    template<class IT>inline void gi(IT &x){
        x=0;gc();while(c<'0'||c>'9')gc();
        while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);gc();}
    }
    char buf0[20];int a;
    template<class IT>inline void pi(IT x){
        if(x<0){putchar('-');x=-x;}
        do buf0[++a]=x%10+48;while(x/=10);
        while(a)putchar(buf0[a--]);
        putchar('\n');
    }
};
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
typedef vector<int> vi;
typedef vector<ll > vl;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const int N=200005;
ll p[N],s[N];
int a[N];
int main(){
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int m,n,i,x,y;ll d;
    scanf("%d%d",&m,&n);
    rep(i,1,n)scanf("%d",&a[i]);
	d=max(m-a[1],a[n]);
	rep(i,1,n)p[i]=p[i-1]+(   a[i] <<1);
	per(i,n,1)s[i]=s[i+1]+((m-a[i])<<1);
	REP(i,1,n){
		y=(x=(i+n)>>1)+1;
		//printf("%d %d %d %lld\n",i,x,y,p[x]-p[i-1]+s[y]-(((i^n)&1)?(m-a[y]):a[x]));
		cmax(d,p[x]-p[i-1]+s[y]-(((i^n)&1)?(m-a[y]):a[x]));
	}
	rep(i,2,n){
		y=(x= i   >>1)+1;
		//printf("%d %d %d %lld\n",i,x,y,p[x]-s[i+1]+s[y]-(( i   &1)?(m-a[y]):a[x]));
		cmax(d,p[x]-s[i+1]+s[y]-(( i   &1)?(m-a[y]):a[x]));
	}
	printf("%lld",d);
    return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

ll X, Y;

bool slove() {
	if (abs(X - Y) <= 1) {
		return false;
	}
	return true;
}

int main() {
	cin >> X >> Y;
	if (slove()) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Brown" << endl;
	}
	return 0;
}

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

int main()
{
    int x, y;
    cin >> x >> y;
    int ans = -1;
    if (x % y != 0)
    {
        ans = x;
    }
    cout << ans << endl;
}

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

using namespace std;
using pii = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<pii> AB(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    AB[i] = make_pair(a, b);
  }
  sort(AB.begin(), AB.end());
  int ans = 1, right = 100001;
  for (int i = 0; i < M; i++) {
    if (AB[i].first < right)
      right = min(right, AB[i].second);
    else {
      ans++;
      right = AB[i].second;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  long long a,b,c,d;
  scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
  long long x=a*c;
  long long y=a*d;
  long long z=b*c;
  long long t=b*d;
  long long max=x;
  if(y>max)	max=y;
  if(z>max) max=z;
  if(t>max) max=t;
  printf("%lld",max);
}

Measured memory_bytes: 1736
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

const ll INF = 1<<30;
const ll LINF = 1LL<<60;
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(void) {
    int ans = 0;
    REP(i, 5) {
        int a; cin >> a;
        if (a == 0) ans = i + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramD
    {
        static void Main()
        {
            int n = NextInt, q = NextInt;
            var matrix = Enumerable.Range(0, n).Select(_ => new List<int>()).ToArray();
            for (int i = 0; i < n - 1; i++)
            {
                int a = NextInt - 1, b = NextInt - 1;
                matrix[a].Add(b);
                matrix[b].Add(a);
            }
            var array = Enumerable.Repeat(0L, n).ToArray();
            for (int i = 0; i < q; i++)
            {
                int p = NextInt - 1, x = NextInt;
                array[p] += x;
            }

            var queue = new Queue<int>();
            queue.Enqueue(0);
            var visited = Enumerable.Repeat(false, n).ToArray();
            visited[0] = true;

            while (queue.Any())
            {
                var tmp = queue.Dequeue();

                foreach (var next in matrix[tmp].Where(next => !visited[next]))
                {
                    queue.Enqueue(next);
                    visited[next] = true;
                    array[next] += array[tmp];
                }
            }

            System.Console.WriteLine(string.Join(" ", array));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

#define __STDC_FORMAT_MACROS
#define p64 PRId64

using namespace std;
using ll = int64_t;

int main()
{
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    ll ans = 0;
    if (A <= C && B <= C)
    {
        cout << A * X + B * Y << endl;
    }
//    else if (A <= C && C < B)
//    {
//        ll x = max((ll)0, (X - Y));
//        ans = min(A * x + C * 2 * Y, A * X + B * Y);
//        cout << ans << endl;
//    }
//    else if (C < A && B <= C)
//    {
//        ll y = max((ll)0, (Y - X));
//        ans = min(C * 2 * X + B * y, A * X + B * Y);
//        cout << ans << endl;
//    }
    else
    {
        ll xy = max(X, Y);
        ll xymn = min(X, Y);
        ans = min(C * 2 * xy, A * X + B * Y);
        ans = min(ans,
                  C * 2 * xymn
                  + A * max((ll)0, X - xymn)
                  + B * max((ll)0, Y - xymn));
        cout << ans << endl;
    }

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  auto a = vector<int>(n,0);
  for (int i = 0; i < n; i++)
  {
      cin >> a[i];
  }
  
  double sum =0.0;
  for (int i = 0; i < n; i++)
  {
      sum += 1/static_cast<double>(a[i]);
  }
  
  cout << setprecision(16) <<1/sum;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {

	/*

	int D, T, S;
	cin >> D >> T >> S;
	int hour = D / S;
	if (D % S != 0)hour++;
	if (hour <= T) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
	
	*/
	/*
	string S;
	cin >> S;
	if (S == "RRR") {
		cout << 3 << endl;
	}
	else if (S == "SSS") {
		cout << 0 << endl;
	}
	else if (S == "SRR" || S == "RRS") {
		cout << 2 << endl;
	}
	else {
		cout << 1 << endl;
	}
	*/	

	int x;
	cin >> x  ;
	if (x == 1) {
		cout << 0 << endl;
	}
	if (x == 0) {
		cout << 1 << endl;
	}
}



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

ll n;
ll divisor_middle(ll n){
    ll out = 0;
    for(ll i=1; i<=pow(n,0.5); i++){
        if(n%i == 0) out = i;
    }
    return out;
}

int main(void){

    cin >> n;

    ll a = divisor_middle(n);
    ll b = n/a;

    if(a<=9 && b<=9) cout << "Yes";
    else cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include <math.h>
int main(void) {
  int i;
  int tmp, k;
  int sum = 0;
  int m = 0;
  for(i = 0; i < 3; i++) {
    scanf("%d", &tmp);
    if(m < tmp){
      m = tmp;
    }
    sum += tmp;
  }
  scanf("%d", &k);
  sum += m * (int)pow(2,k) - m;
  printf("%d\n", sum);
  return 0;
}

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

int main() {
    long long N; cin >> N;
    vector <long long> a(N + 1); for (int i = 1; i < N + 1; ++i) cin >> a[i];
    long long dp[200000 + 1][2];
    dp[0][0] = 0;
    dp[0][1] = 0;

    // 0 => 砕く, 1 => 砕かない

    for (int i = 1; i < N + 1; ++i) {
        // 砕く
        dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
        // 砕かない
        if (dp[i-1][0] + 1 == a[i] || dp[i-1][1] + 1 == a[i]){
            dp[i][1] = a[i];
        }
        else {
            dp[i][1] = max(dp[i-1][0], dp[i-1][1]);
        }
    }
    // for (int i = 0; i < N + 1; ++i) {
    //     cout << dp[i][0] << " ";
    // }
    // cout << endl;
    // for (int i = 0; i < N + 1; ++i) {
    //     cout << dp[i][1] << " ";
    // }
    if (max(dp[N][0], dp[N][1]) == 0) {
        cout << -1 << endl;
    } 
    else {
        cout << N - max(dp[N][0], dp[N][1]) << endl;
    }
}

Measured memory_bytes: 4992
#pragma GCC optimize("trapv")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,ssse3,popcnt,sse4.1,sse4.2,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1<<18, mod = 119<<23|1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n, x;
ll l[maxn], dp[maxn], pref[maxn], lp[maxn];
ll get(ll l, ll r) {
	return lp[r] - lp[l-1];
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> x;
	for(int i = 1; i <= n; i++) cin >> l[i], lp[i] = l[i] + lp[i-1];
	ll ans = 1ll<<60;
	for(int a = n; a; a--) {
		ll cur = 0;
		/** O(n)
		for(ll t = 0, u = 1, i = n; i; i--) {
			if(u==1) cur += 2ll*l[i];
			cur += (2ll*u + 1)*l[i];
			if(++t == a) u++, t = 0;
		}
		**/
		/** O(n/a). sum_{a = 1..n} ( n/a ) = O(n * log(n)) **/
		ll r = n, l, u = 1;
		while(r > 0) {
			l = max(1ll, r-a+1);
			ll s = get(l, r);
			cur += (u==1)*2ll*s;
			cur += (2ll*u + 1)*s;
			if(cur > ans) break;
			u++;
			r = l-1;
		}
		
		ans = min(ans, cur + a*x);
	}
	cout << ans + n*x;
}
//


Measured memory_bytes: 3840
#include <math.h>

int main(){
  long long int X,i;
  int flag = 0;
  scanf("%lld",&X);
  if(X==2){printf("2\n");return;}
  if(X%2==0)X++;
  while(1){
    for(i=3;i<=sqrt(X);i++){
      if(X%i==0){
        flag = 1;
        break;
      }
    }
    if(flag==0){
      printf("%lld\n",X);
      return;
    }
    flag = 0;
    X+=2;
  }
}

Measured memory_bytes: 128
s = input()
n = len(s)
k = int(input())

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]].append(i)
    else:
        dic[s[i]] = [i]

for i in range(97, 123):
    moji = chr(i)
    if moji not in dic:
        continue
    kouho = dic[moji]
    strings = set([])
    for idx in kouho:
        e = idx+1
        string = set([])
        while e <= n and len(string) <= k:
            string.add(s[idx:e])
            e += 1
        strings = strings | string
    if len(strings) >= k:
        strings = list(strings)
        strings.sort()
        print(strings[k-1])
        exit()
    else:
        k -= len(strings)

Measured memory_bytes: 41200
#include<iostream>
#include<cmath>
#include<algorithm>
#include<climits>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	ll count = INT_MAX, tmp = 0;
	for(int i=1; i<=n; i++){
		ll x;
		cin >> x;
		while(x%2==0){
			x /= 2;
			tmp++;
		}
		count = min(count, tmp);
		tmp = 0;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second

int main(){
        char s[100];
        cin >> s ;

        s[3] = '8';
        cout << s << endl;
        return 0;
}


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

#define rep(i,k,n) for(int i = k; i < n; i++)  
#define repp(i,a,n,k) for(typeof(a) i=a;i!=n;i+=k)

#define int long long
#define all(a) a.begin(),a.end()       

#define pb push_back
typedef long long ll; 
typedef pair<int, int> ii;
typedef pair<int,ii > iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<char> vchar;

#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)

#define ff first
#define ss second

#define lb lower_bound
#define ub upper_bound
#define me max_element

#define INF 1000000000
//#define mod 998244353
#define mod 1000000007
#define endl "\n"


  


int modPow(int a, int b);
int modInv(int a);     




void solve(){
    int x,k,d;
    cin >> x >> k >>d;
    int dd = abs(x) - abs(d*k);
    if(dd>=0){
        cout << dd;
        return;
    }
    if((k - abs(x)/abs(d))%2==0){
        cout << abs(x)%d;
    }else{
        
        cout << abs(d) - abs(x)%d;
    }

}


// Recheck if it is 2^9 or 10^9 
//check for long long overflow
//while adding and subs check if mod becomes -ve
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;




signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed;
    //cout <<setprecision(6);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
  //  int test=1; cin >> test; while(test--)
    solve();
}

int modPow(int a, int b){
    if(b==0)return 1;
    if(b%2==0){
        int x = a*a;
        x%=mod;
        return modPow(x,b/2);
    }
    return (a*modPow(a,b-1))%mod;
}


int modInv(int a){
    return modPow(a,mod-2);
}





Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"YES":"NO");
}
int main() {
  int n;cin>>n;
  set<int> ans;
  rep(i,n){
    int a;cin>>a;
    ans.insert(a);
  }
  cout << btos(n==ans.size()) << endl;
  return 0;
}

Measured memory_bytes: 9600