akhauriyash/Code-Regression huggingface dataset:
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <list>
#include <bitset>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }

#if 1
#include <array>
#include <unordered_set>
#include <unordered_map>
template<class T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif


int N, M;
LL A[100000];
LL B[100000];
LL S[100000];
vector<LL> G[100001];
LL decreasing;
LL W;
LL ans;
int main() {
	cin >> N >> M;
	REP(i, 0, N) {
		cin >> A[i];
		if (i != N - 1) ++S[A[i]];
		if (i != 0) G[A[i]].push_back(i);
	}
	REP(i, 0, N - 1) {
		B[i] = M * (A[i] > A[i + 1]) + A[i + 1] - A[i];
	}

	REP(i, 0, N - 1) {
		W += min(B[i], A[i + 1]);
		if(B[i] >= A[i + 1]) ++decreasing;
	}

	ans = W;
	REP(k, 2, M + 1) {
		for (int a : G[k - 1]) {
			W += B[a - 1] - 1;
		}
		decreasing -= G[k - 1].size();
		W -= decreasing;
		decreasing += S[k - 1];
		ans = min(ans, W);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7296
n = int(input())
ll = [int(input()) for i in range(n)]
llc = ll.copy()
llc.sort()
m1 = llc[n-1]
m2 = llc[n-2]

for l in ll:
    if l == m1:
        print(m2)
    else:
        print(m1)


Measured memory_bytes: 14112
mod = 998244353

n, m, k = map(int, input().split())
count = 0

comb = 1
for i in range(k + 1):
  tmp = comb * m * pow(m-1, n-i-1, mod) % mod
  count = (count + tmp) % mod
  comb = comb * (n - i - 1) * pow(i+1, mod-2, mod) % mod
print(count)

Measured memory_bytes: 9196
#include<iostream>
using namespace std;
int main(){
	int n,m,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>m;
		if(m%2==1)cnt++;
	}
	if(cnt%2==1)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char s[100008];
int a[100008], b[100008], n;
int Check(register int x){
	register int i, j, l;
	memcpy(b, a, sizeof(a));
	for (i = 0, j = x; i <= n; ++i) {
		if (b[i] == 0) continue;
		cmax(j, i + x);
		for (; j <= n && b[j] == 0; ++j);
		if (j > n) break;
		b[i] = b[j] = 0;
	}
	l = n;
	for (i = 0; i <= n; ++i) {
		if (b[i] == 0) continue;
		if ((i << 1) > n) cmin(l, i);
		else cmin(l, n - i);
	}
	if (l >= x) return 1;
	else return 0;
}
int main(){
	register int i, l, r, mid;
	scanf("%s", s + 1);
	n = strlen(s + 1);
	s[0] = '0';
	for (i = 1; i <= n; ++i) a[i - 1] = s[i] ^ s[i - 1];
	a[n] = a[n] ^ '0';
	l = 1, r = n + 1;
	while (r - l > 1) {
		mid = l + r >> 1;
		if (Check(mid)) l = mid;
		else r = mid;
	}
	printf("%d", l);
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
t = 0
if N % 4 == 0 or N % 7 == 0:
  ans = "Yes"
else:
  t = 0
  for i in range(1,(N//7)+1):
    x = (N-7*i)/4
    if x == int(x):
      t += 1
    else:
      continue
  if t > 0:
    ans = "Yes"
  else:
    ans = "No"
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}
ll lcm(ll l,ll a){
    return a/__gcd(l,a)*l;
}
ll exp(ll a, ll b,ll c){
  if(b==0)return 1;
  if(b%2==0){
    ll t =exp(a,b/2,c);
    return t*t%c;
  }
  else return exp(a,b-1,c)*a%c;
}
const ll big=1000000007;


int main(){
    int n;cin >> n;
    map<string,bool> ans;
    rep(i,n){
        string s;
        cin >> s;
        ans[s]=true;
    }
    cout << ans.size() << endl;
}

Measured memory_bytes: 19124
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] d = new int[110];

        for (int i=0; i<N; i++) {
            d[i] = sc.nextInt();
        }

        int[] num = new int[110];

        for (int i=0; i<N; i++) {
            num[d[i]]++;
        }

        int res = 0;
        for (int n : num) {
            res += n > 0 ? 1 : 0;
        }

        System.out.println(res);
    }
}



Measured memory_bytes: 21588
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

class Tree {
    public:
    struct Node {
        std::vector<int> edge;
        int rank;
    };
    std::vector<Node> node;
    Tree() {}
    Tree(const int node_num_max) {
        node.resize(node_num_max);
    }
    void add_directed_edge(const int from, const int to) {
        node[from].edge.push_back(to);
    }
    void add_undirected_edge(const int node1, const int node2) {
        add_directed_edge(node1, node2);
        add_directed_edge(node2, node1);
    }
};

const int MAX_N = 2050;
int N, K, A[MAX_N], B[MAX_N];

Tree tree = Tree(MAX_N);

int R;
std::vector<int> far_node_num;

void set_rank(int n, int rank, int parent, int direction) {
    tree.node[n].rank = rank;

    if (rank == R + 1) {
        far_node_num[direction]++;
    }

    for (int c : tree.node[n].edge) {
        if (c != parent) {
            set_rank(c, rank + 1, n, direction);
        }
    }
}

int main(int argc, char **argv) {
    std::cin >> N >> K;

    for (int i = 1; i <= N - 1; i++) {
        std::cin >> A[i] >> B[i];
    }

    for (int i = 1; i <= N - 1; i++) {
        tree.add_undirected_edge(A[i], B[i]);
    }

    R = K / 2;

    int tmp = 0;
    for (int i = 1; i <= N; i++) {
        far_node_num.clear();
        far_node_num.resize(tree.node[i].edge.size(), 0);

        tree.node[i].rank = 0;
        for (int c = 0; c < tree.node[i].edge.size(); c++) {
            set_rank(tree.node[i].edge[c], 1, i, c);
        }

        //int max = 0;
        //for (int num : far_node_num) {
        //    max = std::max(max, num);
        //}

        int near_num = 0;
        for (int j = 1; j <= N; j++) {
            if (tree.node[j].rank <= R) {
                near_num++;
            }
        }

        //std::cout << i << " " << near_num << std::endl;

        if (K % 2 == 1) {
            near_num += *std::max_element(far_node_num.begin(), far_node_num.end());
        }

        //std::cout << near_num << std::endl;

        tmp = std::max(tmp, near_num);
    }

    std::cout << N - tmp << std::endl;
    
    return 0;
}

Measured memory_bytes: 512
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep = ' ', end = '\n'):
    print(*var, file=sys.stderr, end = end, sep = sep)

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
# from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

a = set(I())
ans = 'No'
if len(a) == 2:
    ans = 'Yes'
print(ans)

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

int main() {
	string a, b;
	cin >> a >> b;
	string s = a + b;
	int x = 0;
	for (int i = 0; i < s.length(); i++) {
		x = x * 10 + (s[i] - '0');
	}
	for (int i = 0; i < 400; i++) {
		if (x == i*i) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int mx=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            mx=mx+a[i]*a[j];
        }
    }
    cout<<mx<<"\n";
}

Measured memory_bytes: 3632
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

MOD = 10**9+7

n,*A = get_all_int()

pow2 = [1] * 61
for i in range(1,61):
    pow2[i] = pow2[i-1] * 2

# ビットごとの出現回数 2**i
bits = [0] * 60

for a in A:
    for i in range(60):
        if pow2[i] & a != 0:
            bits[i] += 1

# その位のビットの1の個数*0の個数 が、そのビットがansに足される回数
ans = sum(( pow(2, i, MOD) * bits[i] * (n-bits[i]) for i in range(60))) % MOD

print(ans)


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

const int maxn = 25;
int N, A[maxn], B[maxn], C[maxn];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    for (int i = 1; i <= N; i++) {
        cin >> B[i];
    }
    for (int i = 1; i <= N; i++) {
        cin >> C[i];
    }
    int sum = 0;
    for (int i = 1; i <= N; i++) {
        int curr = A[i];
        sum += B[curr];
        if (i > 1 && A[i-1] == A[i] - 1) {
            sum += C[A[i-1]];
        }
    }
    cout << sum << '\n';
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int n, k, u, a = 1, b = 2;
int main(){
    scanf("%d%d", &n, &k);
    u = (n-1)*(n-2)/2 - k;
    if(u < 0) return 0*puts("-1");
    printf("%d\n", n-1+u);
    rep(i,n-1) printf("%d %d\n", n, i+1);
    rep(i,u){
        printf("%d %d\n", a, b);
        b++;
        if(b == n){
            a++;
            b = a+1;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

const int MN=100010;
typedef long long ll;
struct unionfind{
	int par[MN];
	int sz[MN];
	int prevt[MN];
	ll sco[MN];
	void init(int N){rep(i,N) par[i]=i,prevt[i]=0,sco[i]=0,sz[i]=1;}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y,int t){
		x=find(x),y=find(y);
		if(x==y) return;
		ll nsco = max(sco[x]+(ll)(t-prevt[x])*sz[x], sco[y]+(ll)(t-prevt[y])*sz[y]);
		int nsz = sz[x]+sz[y];
		int nt = t;

		par[y]=x;
		sco[x]=nsco;
		sz[x]=nsz;
		prevt[x]=nt;
	}
}UF;

typedef pair<int,int> P;
vector<P> G[MN];
int d[MN];
int inf = 1e8;
int N,M,T;
void dijkstra(){
	priority_queue<P,vector<P>,greater<P> > que;
	rep(i,N) d[i]=inf;
	d[0]=0;
	que.push(P(0,0));
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v = p.sc;
		int c = p.fs;
		if(d[v]!=c) continue;
		for(P p:G[v]){
			int to = p.fs;
			if(p.sc<=d[v]) continue;
			if(d[to]>d[v]+1){
				d[to]=d[v]+1;
				que.push(P(d[to],to));
			}
		}
	}
}

vector<P> es[100010];

int main(){
	cin>>N>>M>>T;
	rep(i,M){
		int a,b,t;
		cin>>a>>b>>t;
		a--,b--;
		G[a].pb(P(b,t));
		G[b].pb(P(a,t));
		es[T-t].pb(P(a,b));
	}
	dijkstra();
//	rep(i,N) show(d[i]);

	UF.init(N);
	rep(i,N) if(d[i]==inf) UF.sco[i] = -1e18;
	rep(t,T){
		for(P e:es[t]){
			int a = e.fs,b=e.sc;
			if(UF.same(a,b)) continue;
			UF.unite(a,b,t);
		}
	}
	int r = UF.find(0);
	ll ans = UF.sco[r] + (ll)(T-UF.prevt[r])*N;
	cout<<ans<<endl;
}

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

class UnionFindTree {
private:
    vector<int> parent;
    vector<int> count;

public:
    UnionFindTree(int n) : parent(n), count(n, 1) {
        for (int i = 0; i < n; i++) parent[i] = i;
    }
    int get_root(const int x) {
        if (parent[x] == x) return x;
        return parent[x] = get_root(parent[x]);
    }
    void unite(const int x, const int y) {
        int rx = get_root(x), ry = get_root(y);
        if (rx == ry) return;
        parent[rx] = ry;
        count[ry] += count[rx];
        count[rx] = 0;
    }
    bool is_same_root(const int x, const int y) {
        return get_root(x) == get_root(y);
    }
    int get_size(const int x) { return count[get_root(x)]; }
    void print() {
        for (auto elm : parent) cout << elm << " ";
        cout << endl;
        for (auto elm : count) cout << elm << " ";
        cout << endl;
    }
};
int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> p(n), x(n);
    set<pair<int, int>> y;
    UnionFindTree tree(n);
    for (auto i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        x[i] = {p[i].first, i};
    }
    sort(x.begin(), x.end());
    for (auto i = 0; i < n; i++) {
        auto tmp =
            y.lower_bound({p[x[i].second].second, 0});
        for (auto itr = y.begin(); itr != tmp;) {
            tree.unite(x[i].second, itr->second);
            if (itr == y.begin()) ++itr;
            else
                itr = y.erase(itr);
        }
        if (tmp == y.begin())
            y.insert({p[x[i].second].second, x[i].second});
    }
    for (auto i = 0; i < n; i++)
        cout << tree.get_size(i) << endl;
    return 0;
}

Measured memory_bytes: 13680
a, b = map(int, input().split())

A = []
for i in range(a):
    A.append(list(input()))
B = []
for i in range(b):
    B.append(list(input()))
f = 0
for i in range(a - b + 1):
    for j in range(a - b + 1):
        if A[i][j] == B[0][0]:
            ans = 0
            for k in range(b):
                for l in range(b):
                    if A[i+k][j+l] == B[k][l]:
                        continue
                    else:
                        ans = 1
            if ans == 0 and f == 0:
                print("Yes")
                f = 1
                break
if f == 0:
    print("No")

Measured memory_bytes: 40944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(void){
    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(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<ll>());
    
    ll left = -1;
    ll right = 0;
    rep(i, n) right = max(right, a[i]*f[i]);
    
    while (left+1 != right) {
        ll k_c = k;
        ll center = (left+right)/2;
        
        rep(i, n) {
            if (center < a[i]*f[i])
                k_c -= a[i] - center/f[i];
            
            if (k_c < 0)
                break;
        }
        if (k_c < 0)
            left = center;
        else
            right = center;
    }
    
    cout << right << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

int main()
{
	int n; cin >> n;
	vector<string> S(n);
	for(int i = 0; i < n; i++){
		string tmp;
		cin >> tmp;
		S[i] = tmp;
	}

	map<char, int> hist[n];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < S[i].length(); j++){
			hist[i][S[i][j]]++;
		}
	}

	for(map<char, int>::iterator it = hist[0].begin(); it != hist[0].end(); it++){
		for(int i = 1; i < n; i++){
			it->second = min(it->second, hist[i][it->first]);
		}
	}

	string ans;
	for(map<char, int>::iterator it = hist[0].begin(); it != hist[0].end(); it++){
		for(int i = 0; i < it->second; i++){
			ans.push_back(it->first);
		}
	}

	cout << ans << endl;
	return 0;

	// for(int i = 1; i < n; i++){
	// 	for(map<char, int>::iterator it = hist.begin(); it != hist.end(); it++){
	// 		for(int l = 0; l < it->second; l++){
	// 			bool found = false; /* turn on when it->second is found in S[i]; */
	// 			for(int k = 0; k < S[i].length(); k++){
	// 				/* check if S[i] includes it->second */
	// 				if(S[i][k] == it->second){
	// 					found = true;
	// 					break;
	// 				}
	// 			}
	// 		if(!found) hist[it->first]--;
	// 		}

	// 	}
	// }

	// for(map<char, int>::iterator it = hist.begin())
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool hoge(int n) {
  if (n == 0)
    return true;
  else if(n < 0)
    return false;
  else {
    return hoge(n - 4) || hoge(n - 7);
  }
}

int main() {
  int n;
  cin >> n;
  cout << (hoge(n) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3616
N = int(input())
S = str(input())

M = 0
for n in range(1,N) :
    set1 = set([])
    set2 = set([])
    I = set([])
    for c in (S[:n]) :
        set1.add(c)
    for d in (S[n:]) :
        set2.add(d)
    I = set1 & set2
    if(len(I)>M) :
        M = len(I)
print(M)

Measured memory_bytes: 3064
N,D = list(map(int,input().split()))
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for i in range(N):
  for j in range(i+1,N):
    a = 0
    for d in range(D):
      a += (X[i][d]-X[j][d])**2
    for l in range(a+1):
      if l**2==a:
        ans+=1
print(ans)
    

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

struct el {
	int to, ind;
};

int n;
vector<el> adj[100001];
vector<int> ans;

void dfs(int x, int par=0, int par_c=0) {
	int curr=1;
	for(el i:adj[x]) {
		if(par==i.to) continue ;
		if(curr==par_c) curr++;
		ans[i.ind]=curr;
		dfs(i.to, x, curr);
		curr++;
	}
}

int main() {
	IO;
	cin>>n;
	int mx=0;
	for(int i=1;i<n;++i) {
		int a,b;
		cin>>a>>b;
		adj[a].pb({b,i});
		adj[b].pb({a,i});
		mx=max(mx,sz(adj[a]));
		mx=max(mx,sz(adj[b]));
	}
	ans.resize(n);
	ans[0]=mx;
	dfs(1);
	
	for(auto i:ans) cout<<i<<"\n";
	return 0;
}


Measured memory_bytes: 9344
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(void)
{
  char s[12];
  int i;
  int max = 0;
  int size = 0;
  
  scanf("%s", s);
  
  for (i = 0; i < strlen(s); i++){
    if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G'){
      size++;
    } else {
      if (max < size){
        max = size;
      }
      size = 0;
    }
  }
  if (max < size){
     max = size;
  }
  printf("%d", max);
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3

N = int(input())
D,X = [int(i) for i in input().split()]
A = [int(input()) for _ in range(N)]

X += N
for d in range(2,D+1):
    for a in A:
        if (d - 1) % a == 0:
            X += 1

print(X)


Measured memory_bytes: 9156
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict
from functools import lru_cache


@lru_cache(None)
def gcd(x: int, y: int) -> int:
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x, y = y, r
    return x


def merge_dict(d1, d2):
    for k, v in d2.items():
        d1[k] += v
    return d1


def input():
    return sys.stdin.readline().strip()


def gen_prime_table(last: int, first=2) -> list:
    if last < 1:
        return [None]
    elif last < 2:
        return [None, None]
    table = [None] * (last + 1)

    for i in range(first, last + 1):
        if not table[i]:
            table[i] = i
            for j in range(i * 2, last + 1, i):
                table[j] = i
    return table


def prime_factorization(N: int, min_factor: list) -> dict:
    if N < 2:
        return {1: 1}
    primes = dict()
    primes[1] = 1
    while N != 1:
        p = min_factor[N]
        if p in primes.keys():
            primes[p] += 1
        else:
            primes[p] = 1
        N = N // p
    return primes


def main():
    n = int(input())
    A = [int(i) for i in input().split()]
    primes = defaultdict(int)
    is_pair_gcd = True
    set_gcd = A[0]
    min_factor = gen_prime_table(max(A))  # この部分の計算不可が大きい (n*log_log_n)
    for i in range(n):
        set_gcd = gcd(set_gcd, A[i])
        p = prime_factorization(A[i], min_factor)
        if is_pair_gcd:
            for k, v in p.items():
                if k == 1:
                    continue
                if k in primes.keys():
                    is_pair_gcd = False
                else:
                    primes[k] += v

    if is_pair_gcd:
        print("pairwise coprime")
        return

    if set_gcd == 1:
        print("setwise coprime")
    else:
        print("not coprime")

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 369776
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (n == 26) {
    string t = s;
    bool ret = next_permutation(t.begin(), t.end());
    if (!ret) {
      cout << -1 << endl;
    } else {
      int k;
      for (k = 0; k < n && s[k] == t[k]; ++k);
      t = t.substr(0, k + 1);
      cout << t << endl;
    }
  } else {
    vector<int> cnt(26);
    for (int i = 0; i < s.size(); ++i) {
      cnt[s[i] - 'a']++;
    }
    int k = 0;
    for (; k < 26 && cnt[k]; ++k);
    s += (char)('a' + k);
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# ABC109D Make Them Even Diff: 1198

H, W = map(int, input().split())
a = [[-1]*(W+2) for _ in range(H+2)]
odd_count = 0

for i in range(1, H+1):
    tmp = list(map(int, input().split()))
    for j in range(1, W+1):
        a[i][j] = tmp[j-1]
        odd_count += int(a[i][j] % 2 == 1)

moves = []
routes = []
for h in range(1, H+1):
    tmp = []
    for w in range(1, W+1):
        tmp.append((h, w))
    if h % 2 == 1:
        routes += tmp
    else:
        routes += tmp[::-1]

is_carrying = 0
for i, (h, w) in enumerate(routes):
    if i == H*W-1:
        break
    if a[h][w] % 2 == 1 and not is_carrying and odd_count != 1:
        tmp = (h, w)
        is_carrying = 1
        moves.append((h, w, routes[i+1][0], routes[i+1][1]))
    elif a[h][w] % 2 == 1 and is_carrying and odd_count != 1:
        is_carrying = 0
        odd_count -= 2
        
    elif a[h][w] % 2 == 0 and is_carrying and odd_count != 1:
        moves.append((h, w, routes[i+1][0], routes[i+1][1]))

print(len(moves))
for move in moves:
    print(*move)

Measured memory_bytes: 109648
import sys, math, re
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, K = mi()
    if (N+1)//2 >= K:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9884
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;
//for (int i = 0; i < N; i++){}

int main() {

    // input
    int N , M , C ; cin >> N >> M >> C ;
    vector <int > B (M);
    for ( int i = 0; i < M ; ++ i ) {
    cin >> B [i];
    }
    vector < vector <int >> A (N , vector <int >(M));
    for ( int i = 0; i < N ; ++ i ) {
    for ( int j = 0; j < M ; ++ j ) {
    cin >> A [i][j];
    }
    }
    long long res = 0;
    for (int i = 0; i < N; i++){
        long long sums = 0;
        for (int j = 0; j < M; j++){
            sums += A[i][j]*B[j];
        }
        sums += C;
        if(sums>0){
            res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll x, y;
  x = (a + d - 1) / d;
  y = (c + b - 1) / b;
  if(x>=y)
    printf("Yes\n");
  else
    printf("No\n");
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3636
/// Thank you tanakh!!!
///  https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input!(n: usize, m: usize, a: [usize1; m]);
    let mut ans = 0;
    for &a in a.iter() {
        if a >= m {
            ans += 1;
        }
    }
    println!("{}", ans);
}



Measured memory_bytes: 5028
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

int main(int argc, char **argv)
{
    static const long double pi = 3.141592653589793;
    long double A, B, H, M;
    std::cin >> A >> B >> H >> M;

    long double short_angle = (H * 60.0 + M) * 0.5;
    long double long_angle = M * 6.0;

    //std::cout << short_angle << std::endl;
    //std::cout << long_angle << std::endl;

    long double angle_diff = std::abs(long_angle - short_angle);
    if(angle_diff >= 180){
        angle_diff = 360 - angle_diff;
    }
    //std::cout << angle_diff << std::endl;

    bool donkaku = false;
    if(angle_diff > 90){
        donkaku = true;
        angle_diff = 180 - angle_diff;
    }

    long double rad = angle_diff * 2 * pi / 360;
    //std::cout << rad << std::endl;

    long double c = A * std::cos(rad);
    long double s = A * std::sin(rad);

    long double b = B;
    
    if(donkaku){
        b += c;
    }else{
        b -= c;
    }

    long double d = b * b + s * s;

    std::cout << std::fixed << std::setprecision(21) << std::sqrt(d) << std::endl;
    
}


Measured memory_bytes: 4096
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w,k;
    cin >> h >> w >> k;
    vll s(2),g(2);
    REP(i,2) {cin >> s[i]; s[i]--;}
    REP(i,2) {cin >> g[i]; g[i]--;}
    vector<vector<vector<pair<ll,ll> > > > c(h,vector<vector<pair<ll,ll> > >(w,vector<pair<ll,ll> >(4,make_pair(INF,INF))));
    REP(i,h){
        string ci;
        cin >> ci;
        REP(j,w){
            if(ci[j]=='@'){
                REP(l,4){
                    c[i][j][l] = make_pair(-1LL,-1LL);
                }
            }
        }
    }
    REP(i,4){
        c[s[0]][s[1]][i] = make_pair(0,k);
    }
    queue<pair<ll,ll> > q;
    q.push(make_pair(s[0],s[1]));
    while(!q.empty()){
        auto now = q.front();
        q.pop();
        REP(i,4){
            //行く方向
            ll ni = now.fi+dy[i];
            ll nj = now.se+dx[i];
            if(ni<0||ni>=h||nj<0||nj>=w) continue;
            if(c[ni][nj][0] == make_pair(-1LL,-1LL)) continue;
            REP(j,4){
                //来た方向
                if(i==j&&c[now.fi][now.se][i].se>0&&c[now.fi][now.se][j].fi<INF){
                    ll tf = c[now.fi][now.se][i].fi;
                    ll ts = c[now.fi][now.se][i].se-1;
                    if((tf<c[ni][nj][j].fi)||(tf==c[ni][nj][j].fi&&ts>c[ni][nj][j].se)){
                        c[ni][nj][j].fi = tf;
                        c[ni][nj][j].se = ts;
                        q.push(make_pair(ni,nj));
                    }
                    
                }else{
                    ll tf = c[now.fi][now.se][j].fi+1;
                    ll ts = k-1;
                    if((tf<c[ni][nj][i].fi)||(tf==c[ni][nj][i].fi&&ts>c[ni][nj][i].se)){
                        c[ni][nj][i].fi = tf;
                        c[ni][nj][i].se = ts;
                        q.push(make_pair(ni,nj));
                    }
                }
            } 
        }
    }
    ll ans = LLINF;
    
    REP(i,4){
        ans = min(ans, c[g[0]][g[1]][i].fi);
    }
    if(ans==INF){
        cout << -1 << endl;
    }else{
        cout << ans+1 << endl;
    }


    return 0;
}

Measured memory_bytes: 206484
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;

int T[30],n;

int solve(int i,int m){
    if(m == 0)return 1;
    if(i == n)return 0;

    int res;
    res = solve(i+1,m) || solve(i+1,m-T[i]);
    return res;
    
}

int main() 
{
    cin >> n;
    rep(i,n){
        cin >> T[i];
    }

    int q,m;
    cin >> q;
    rep(i,q){
        cin >> m;
        if(solve(0,m))
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
}


Measured memory_bytes: 3116
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int q = tmp[0], h = tmp[1], s = tmp[2], d = tmp[3];
	int n = int.Parse(ReadLine());

	// best single prise
	long sPrise = Math.Min(s, Math.Min(h*2, q*4));

	// best double prise
	long dPrise = Math.Min(sPrise*2, d);

	long ans = (n/2) * dPrise + (n%2) * sPrise;
	WriteLine(ans);
    }
}


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

int main() {
  int N,M,K;
  long long int *A,*B;
  int i,j;
  long long int input;
  int result;
  scanf("%d %d %d", &N, &M, &K);
  A = (long long int*)malloc(sizeof(long long int)*N+1);
  B = (long long int*)malloc(sizeof(long long int)*M+1);
  A[0] = 0;
  B[0] = 0;
  for ( i = 1; i <= N; i++ ) {
    scanf("%lld", &input);
    A[i] = A[i-1]+input;
  }
  for ( i = 1; i <= M; i++ ) {
    scanf("%lld", &input);
    B[i] = B[i-1]+input;
  }
  
  result = 0;
  /*
  for ( i = N; i >= 0; i-- ) {
    // printf("i = %d\n", i);
    for ( j = M; j >= 0; j-- ) {
      // printf("j = %d\n", j);
      if ( A[i] + B[j] <= K ) {
        result = result>(i+j)?result:(i+j);
        // printf("i = %d, j = %d, res = %d\n", i,j,result);
        break;
      }
    }
    if ( j == M ) {
      break;
    }
  }
  */
  for ( i = 0; i <= N; i++ ) {
    if ( i == 0 ) j = M;
    for ( ; j >= 0; j-- ) {
      if ( A[i] + B[j] <= K ) {
        result = result>(i+j)?result:(i+j);
        break;
      }
    }
  }
  
  printf("%d\n", result);

  free(A);
  free(B);
  return 0;
}


Measured memory_bytes: 4972
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> n >> k;
	vector<int> v(n);
	for(auto &x : v){
		cin >> x;
	}
	sort(all(v));
	int sum = 0;
	for(int i = 0;i < k;i++){
		sum += v[i];
	}
	cout << sum;
}
//.........

Measured memory_bytes: 3624
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

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

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
#define MOD 1000000007
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
template <typename T>
bool isPrime(T n){
  
  for(T i = 2; n >= i+i; i++){
    if(!(n%i)){return false;}
  }
  return true;
}
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  int x;cin>>x;
  while(!isPrime(x))x++;
  cout << x << endl;
}

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

dic = {}

for _ in range(m):
    a,b = map(int,input().split())

    try:
        dic[a] += 1
    except:
        dic[a] = 1

    try:
        dic[b] += 1
    except:
        dic[b] = 1

#dic = sorted(dic.items(),key=lambda x:x[0])

for i in range(1,n+1):
    try:
        print(dic[i])
    except:
        print(0)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int count = 0;
    rep(i,A + 1){
        rep(j,B + 1){
            rep(k,C + 1){
                if(500 * i + 100 * j + 50 * k == X){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}



Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Chat in a Circle
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", as + i);
  sort(as, as + n);

  ll sum = 0;
  for (int i = 1; i < n; i++) sum += as[n - 1 - i / 2];

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 3880
using System;

public class Hello
{
    public static void Main()
    {
        var o =int.Parse( Console.ReadLine());
        var g = Console.ReadLine();


        var s = g.Split(' ');
        int[] e = new int[o];
        for (int i = 0; i < o; i++)
        {
            e[i] = int.Parse(s[i]);
        }

        int h = 100000;
        for (int y = 1; y < o; y++)
        {


            int p = 0;
            int q = 0;

            for (int i = 0; i < y; i++)
            {
                p += e[i];
            }

            for (int i = y; i < o; i++)
            {
                q += e[i];
            }

            if(h > Math.Abs(p - q))
            {
                h = Math.Abs(p - q);
            }
        }
        

        Console.WriteLine(h);
    }

}

Measured memory_bytes: 13140
#include<stdio.h>

int main()
{
    int m,n,i,sum=0;
    scanf("%d %d",&m,&n);
    int a[100005];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    if(sum>=m)
       printf("Yes");
   else
       printf("No");

}

Measured memory_bytes: 512
#include<bits/stdc++.h>>
using namespace std;
int main()
{
    int a[]={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};
    int k;
    cin>>k;
    cout<<a[k-1]<<endl;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l,r,d,i,c=0,j;
    cin>>l>>r>>d;
    j=r/d;
    for(i=1;i<=j;i++)
    {
        if((i*d)>=l&&(i*d)<=r)
            c++;
    }
    cout<<c<<endl;

}


Measured memory_bytes: 3628
#include <iostream>
#include <map>
using namespace std;
int main(void){
    int n,a=0,b=0;
    cin>>n;
    map<int,int> mp;
    for(int i=0;i<n;i++){
        int p;
        cin>>p;
        auto itr = mp.find(p);
        if(itr == mp.end()){
            mp[p]=1;
        }else{
            mp[p]++;
            if(mp[p]%2==0){
                a=max(a,p);
                if(a>b){
                    p=a;a=b;b=p;
                };
            }
        }
    }
    cout<<(unsigned long long)a*(unsigned long long)b;
}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x = n;

        int sum = x % 10;
        while (x >= 10) {
            x /= 10;
            sum += x % 10;
        }

        System.out.println(n % sum == 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 25300
#約数は使わず、素因数分解のみ

#素因数分解
def soinsu_bunkai(m):
    pf={}

    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:
        pf[m]=1
    return pf

#初期入力
N = int(input())
xx =[]
prime_factorization =soinsu_bunkai(N)
count =0
for i in prime_factorization.keys():
    x=1
    while x <= prime_factorization[i]:
        if N % i**x ==0:
            xx.append(i**x)
            count +=1
            N //= i**x
        x +=1
print(count)

Measured memory_bytes: 9380
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

ll root( ll p ){
	ll l = -300, r = 300;
	int cnt = 0;
	while( cnt < 80 ){
		ll mid = (l+r)/2;
		if( mid*mid*mid*mid*mid == p ){
			return (int)mid;
		} else if( p < mid*mid*mid*mid*mid ){
			r = mid;
		} else {	// mid*mid < p
			l = mid;
		}
		++cnt;
	}
	return inf;
}

int main(){
	ll x; cin >> x;
	for( ll b = -300; b <= 300; ++b ){
		ll a = root(x+b*b*b*b*b);
		if( a != inf ){
			cout << a << ' ' << b << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3636
from collections import deque

if __name__ == '__main__':
    N = int(input())
    linked_list = deque()
    
    for i in range(N):
        command = input().split(' ')
        if command[0] == 'insert':
            linked_list.appendleft(command[1])
        elif command[0] == 'delete':
            try:
                linked_list.remove(command[1])
            except ValueError:
                continue
        elif command[0] == 'deleteFirst':
            linked_list.popleft()
        elif command[0] == 'deleteLast':
            linked_list.pop()
    
    print(*linked_list)


Measured memory_bytes: 69732
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

using namespace std;

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

    int n;
    scanf("%d", &n);

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

    vector<int> dp(n + 1, INT_MAX);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j : {i + 1, i + 2}) {
            dp[j] = min({dp[j], dp[i] + abs(costs[i] - costs[j])});
        }
    }

    printf("%d", dp[n - 1]);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n, M;
	cin >> n >> M;
	map<int, pair<string, int>> m;
	int ac = 0, wa = 0;
	while (M--) {
		int i;
		string s;
		cin >> i >> s;
		if (s == "WA") {
			if (m[i].first != "AC") {
				if (!m.count(i))
					m[i] = {s, 1};
				m[i].second++;
			} 
		} else {
			if (m[i].first != "AC") {
				ac++;
				m[i].first = s;
			}
		}
	}
	for (auto p : m) {
		if (p.second.first == "AC")
			wa += p.second.second;
	}
	cout << ac << " " << wa << endl;
}


Measured memory_bytes: 11264
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let mut ans = 0;
    for i in 1..=n {
        ans += i * (n - i + 1);
    }

    for _ in 0..(n - 1) {
        let [u, v]: [usize; 2] = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let mut iter = buf.split_whitespace();
            [
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
            ]
        };
        ans -= if u < v { u * (n - v + 1) } else { v * (n - u + 1)};
    }

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

Measured memory_bytes: 2100