akhauriyash/Code-Regression huggingface dataset:
from functools import lru_cache

def calc(n):
    @lru_cache(maxsize=None)
    def rec(n):
        if n <= 0: return 0
        S = [2, 3, 5]
        mi = D * n
        for i, a in enumerate(S):
            for j in range(-a//2, a//2 + 1):
                if (n + j) % a == 0 and (n + j) // a < n:
                    mi = min(mi, rec((n+j) // a) + X[i] + D * abs(j))
        return mi
    return rec(n)

T = int(input())
for _ in range(T):
    N, A, B, C, D = map(int, input().split())
    X = (A, B, C)
    print(calc(N))

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

long long P = 1000000007;

class C {
public:
  int n;
  vector<long long> fac, inv, facInv;
  long long power(long long e, long long x) {
    if (x == 0)
      return 1;
    if (x == 1)
      return e;
    if (x % 2 == 0)
      return power((e * e) % P, x / 2);
    return (e * power(e, x - 1)) % P;
  }
  C(int n_) {
    n = n_;
    fac.resize(n + 1);
    inv.resize(n + 1);
    facInv.resize(n + 1);
    fac[0] = fac[1] = 1;
    for (int i = 2; i <= n; i++)
      fac[i] = (i * fac[i - 1]) % P;
    inv[0] = inv[1] = 1;
    for (int i = 2; i <= n; i++)
      inv[i] = power(i, P - 2);
    facInv[0] = facInv[1] = 1;
    for (int i = 2; i <= n; i++)
      facInv[i] = (inv[i] * facInv[i - 1]) % P;
  }
  long long comb(int N, int K) {
    if (N < K || K < 0 || N < 0)
      return 0;
    if (N == 0 || K == 0 || K == N)
      return 1;
    return ((fac[N] * facInv[K]) % P * facInv[N - K]) % P;
  }
  long long hcomb(int N, int K) {
    if (N == 0 && K == 0)
      return 1;
    return comb(N + K - 1, K);
  }
  long long mul(long long a, long long b) { return (a * b) % P; }
  long long add(long long a, long long b) { return (a + b) % P; }
  // find c
  // where a^c = b (mod P)
  long long dlp(long long a, long long b) {
    long long m = ceil(sqrt(P));
    map<long long, long long> mp;
    for (int i = 0; i < m; i++)
      mp[power(a, i)] = i;
    long long ainvm = power(power(a, m), P - 2);
    cout << m << endl;
    for (int i = 0; i < m; i++) {
      if (mp.find(b) != mp.end()) {
        return i * m + mp[b];
      }
      b = mul(b, ainvm);
    }
    return -1;
  }
};


int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 0;
  ll b2 = 1;
  for (int k = 0; k < 61; k++) {
    ll c = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] & (1LL << k)) c++;
    }
    ll rest = n - c;
    ans += ((c * rest) % P * b2) % P;
    ans %= P;
    b2 *= 2;
    b2 %= P;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <stdio.h>


int main(void){
  int n;
  long long ans=0;
  std::cin >> n;

  for(int i=1;i<n;i++){
    ans += (int)(n-1)/i;
  }

  std::cout << ans;
  return 0;
}

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

int solve(int src, vector<vector<int>> &v, int* dp){
    if(dp[src]!=-1){
        return dp[src];    
    }
    if(v[src].size() == 0){
        dp[src] = 0;
        return dp[src];
    }
    int best = 0;
    // for(auto x:v[src]){
    //     best = max(best,solve(x,v,dp));
    // }
    
    for(auto x:v[src]){
        if(dp[x] == -1)solve(x,v,dp);
    }
    for(auto x:v[src]){
        best = max(best,dp[x]);
    }
    dp[src] = 1 + best;
    return dp[src];
}


int32_t main() {
	int n,e;
	cin>>n>>e;
	vector<vector<int>> v(n+1);
	int i;
	for(i=0;i<e;i++){
	    int a,b;
	    cin>>a>>b;
	    v[a].push_back(b);
	}
	
	int dp[n+1];
	fill(dp,dp+n+1,-1);
	
    // for(i=1;i<=n;i++){
    //     cout<<i<<" -> ";
    //     for(auto x:v[i]){
    //         cout<<x<<" , ";
    //     }
    //     cout<<endl;
    // }
	
	for(i=1;i<=n;i++){
	    solve(i,v,dp);
	}
	
// 	for(i=1;i<=n;i++){
// 	    cout<<dp[i]<<" ";
// 	}
// 	cout<<endl;
	
	int mx = 0;
	for(i=1;i<=n;i++)mx = max(mx,dp[i]);
	cout<<mx<<endl;
	
	return 0;
}


Measured memory_bytes: 9856
(N, K) = map(int, input().split())

types = {}
balls = map(int, input().split())

for ball in balls:
    if ball in types:
        types[ball] += 1
    else:
        types[ball] = 1

ball_nums_sorted = sorted(types.values(), reverse=True)

types_count = len(types.keys())
rewrite_count = 0
while (K < types_count):
    rewrite_count += ball_nums_sorted.pop()
    types_count -= 1

print(rewrite_count)

Measured memory_bytes: 41120
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, a, b;
    cin >> n >> a >> b;
    vector<lint> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    lint ok    = 1000000000;
    lint ng    = 0;
    auto check = [&](lint mid) {
        vector<lint> t = h;
        lint cnt       = 0;
        for (int i = 0; i < n; ++i) {
            t[i] -= b * mid;
            cnt += max(0LL, (t[i] + a - b - 1) / (a - b));
        }
        return cnt <= mid;
    };
    while (abs(ok - ng) != 1) {
        lint mid               = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << "\n";
    return 0;
}

Measured memory_bytes: 1792
import math
from functools import reduce

N = int(input())
A = list(map(int, input().split()))

max_A = max(A)
sqrt_max_A = math.ceil(max_A ** 0.5)
sieve = list(range(2, max_A+1))
prime = list(range(max_A+1))
while len(sieve) > 0 and sieve[0] <= sqrt_max_A:
    p = sieve[0]
    prime[p]= p
    new_sieve = []
    for s in sieve:
        if s % p == 0:
            prime[s] = p
        else:
            new_sieve.append(s)
    sieve = new_sieve

factors = {}
pairwise = True
for a in A:
    while prime[a] != a:
        if prime[a] in factors:
            pairwise = False
            break
        factors[prime[a]] = True
        p = prime[a]
        while a % p == 0:
            a //= p
    if a != 1:
        if a in factors:
            pairwise = False
        else:
            factors[a] = True
    if not pairwise:
        break
if pairwise:
    print('pairwise coprime')
else:
    gcd = reduce(math.gcd, A)
    if gcd == 1:
        print('setwise coprime')
    else:
        print('not coprime')


Measured memory_bytes: 252944
def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    hg = []
    hi = []
    vg = []
    vi = []

    for _s in s:
        gn = 0
        _hi = [0] * w
        _hg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "#":
                _hi[i] = -1
                gn += 1
                _hg.append(c)
                c = 0
                continue
            _hi[i] = gn
            c += 1
        _hg.append(c)
        hg.append(_hg)
        hi.append(_hi)
    for _s in zip(*s):
        gn = 0
        _vi = [0] * h
        _vg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "#":
                _vi[i] = -1
                gn += 1
                _vg.append(c)
                c = 0
                continue
            _vi[i] = gn
            c += 1
        _vg.append(c)
        vg.append(_vg)
        vi.append(_vi)
    ans = 0
    for i in range(h):
        ans = max(ans, max([hg[i][hi[i][j]] + vg[j][vi[j][i]] for j in range(w)]))
    return str(ans - 1)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 198128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using V = vector<int>;
using VV = vector<vector<int>>;
const double pi = 3.14159265358979323846264338;
int Inf = (1<<30);
ll inf = (1LL<<60);
int main() {
	double a, b, x;
	cin >> a >> b >> x;
	x /= a;
	if (a * b == x) {
		cout << 0;
		return 0;
	}
	if (a * b / 2 >= x) { // 半分よりは満たされてない
		double A = x / b * 2;
		cout << fixed << setprecision(8) << atan(b / A) * 180 / pi;
	}
	else { // 半分より満たされてる
		double R = (x * 2) / a - b;
		x -= a * R;
		b -= R;
		double A = x / b * 2;;
		cout << fixed << setprecision(8) << atan(b / A) * 180 / pi;
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
#include <complex>

using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

typedef complex<double> Point;

namespace std {
  bool operator < (const Point& a, const Point& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

struct Line : public vector<Point> {
  Line(const Point &a, const Point &b) {
    push_back(a); push_back(b);
  }
};

struct Circle {
  Point p; double r;
  Circle(const Point &p, double r) : p(p), r(r) { }
};

double norm(const Point& p){
  return p.real() * p.real() + p.imag() * p.imag();
}

double abs(const Point& p){
  return sqrt(norm(p));
}

Point unit(const Point& p){
  return p/abs(p);
}

double cross(const Point& a, const Point& b) {
  return imag(conj(a)*b);
}

double dot(const Point& a, const Point& b) {
  return real(conj(a)*b);
}

int ccw(Point a, Point b, Point c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

int main(){
  double limit_distance;
  while(~scanf("%lf",&limit_distance)){
    if(limit_distance == 0) break;
    double px,py;
    double vx,vy;
    scanf("%lf %lf",&px,&py);
    scanf("%lf %lf",&vx,&vy);

    Circle circle(Point(0,0),1.0);
    Line laser(Point(px,py),Point(px + vx, py + vy));

    int pos = ccw(laser[0],circle.p,laser[1]);
    double distance = 0.0;
    if(pos == -2 || pos == 0){
      distance = abs(laser[0] - circle.p);
    }
    else if(pos == 2){
      distance = 2.0 - abs(laser[0] - circle.p);
    }
    else{
      printf("impossible\n");
      continue;
    }

    if(distance >= limit_distance){
      printf("impossible\n");
    }
    else{
      printf("%.8lf\n",distance);
    }
  }
}

Measured memory_bytes: 1256
from collections import Counter
from bisect import bisect_right

n = int(input())
s = input()
ndict = {str(i):[] for i in range(10)}
for i,c in enumerate(s):
    ndict[c].append(i)

ans = 0
for i in range(1000):
    PIN = str(i).zfill(3)
    idx = -1
    cc = ''
    for c in PIN:
        if ndict[c] == []:
            break
        tmp = bisect_right(ndict[c], idx)
        if tmp >= len(ndict[c]):
            break
        idx = ndict[c][tmp]
        cc = c
    else:        
        ans += 1
print(ans)

Measured memory_bytes: 4724
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


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



Measured memory_bytes: 256
#include<stdio.h>

#define WHITE 0
#define GLAY 1
#define BLACK 2
#define MAX 101
#define TRUE 1
#define FALSE 0

int n;
int color[MAX];
int d[MAX];
int f[MAX];
int G[MAX][MAX];
int time_dfs = 0;

void dfs();
void search(int);

int main(){
  int i,j,id,k,v;

  scanf("%d",&n);

  for(i = 1; i <= n; i++)color[i] = WHITE;

  for(i = 1; i <= n; i++){
    scanf("%d %d", &id, &k);
    for(j = 1; j <= k; j++ ){
      scanf("%d",&v);
      G[id][v] = TRUE;
    }
  }
  dfs(1);
  
  for(i = 1; i <= n; i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
 
  
  return  0;
}

void dfs(){
  int u_i;

  for(u_i = 1; u_i <= n; u_i++){
    if(color[u_i] == WHITE)search(u_i);
  }

  return;
}

void search(int id){
  int v;
  
  color[id] = GLAY;
  d[id] = ++time_dfs;
  for(v = 1; v <= n; v++){
    if(G[id][v] == FALSE)continue;
    if(color[v] == WHITE){
      search(v);
    }
   }
  color[id] = BLACK;
  f[id] = ++time_dfs;
}


Measured memory_bytes: 2104
import heapq

N,M = map(int, input().split())
es = [[] for _ in range(N)]

for i in range(M):
    a,b,c = map(int, input().split())
    es[a-1].append((c, b-1))
    es[b-1].append((c, a-1))


"""
・ノード数が少ないので、全ノード間の最短距離を求めても間に合う
・ある辺eがいずれかの最短距離に含まれる　→　その辺eが結ぶ２ノードの最短距離はeの距離（それぞれの最短距離を束ねてある２ノードの最短距離を作るから）
"""

INF = float("inf")
# 全ノード間の最短距離を求める
d = [[INF for _ in range(N)] for _ in range(N)]

for i in range(N):
    q = []
    d[i][i] = 0
    heapq.heappush(q, (0, i))
    while q:
        cost, a = heapq.heappop(q)
        if d[i][a] < cost:
            continue
        for c,b in es[a]:
            if d[i][a] + c < d[i][b]:
                d[i][b] = d[i][a] + c
                heapq.heappush(q, (d[i][b], b))


# 全ての辺について、その辺の間の距離cがa->bまでの最短距離か確かめる
# ある辺がいずれかのノード間の最短経路に含まれるなら、その辺（が結ぶノード）も最短距離になるから。
cnt = 0
for i in range(N):
    for c, b in es[i]:
        if d[i][b] != c:
            cnt += 1

# 無向グラフなので２方向分カウントされてるから２で割る
print(cnt//2)

Measured memory_bytes: 3568
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int main() {
	scanf("%d%d",&n,&m);
	int a=1,b=1+m,c=b+1,d=c+m-1;
	while (1) {
		if (a<b) printf("%d %d\n",a,b);
		if (c<d) printf("%d %d\n",c,d);
		++a,--b,++c,--d;
		if (a>=b&&c>=d) break;
	} 
	return 0;
}

Measured memory_bytes: 3816
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static int F(int n)
        {
            if (n % 2 == 0)
            {
                return n / 2;
            }
            else
            {
                return 3 * n + 1;
            }
        }

        static void Main()
        {
            IO io = new IO();

            //ここから
            int s = io.ReadLineToInt();
            int ans = 0;

            List<int> a = new List<int>();
            a.Add(s);

            while (true)
            {
                int b = F(a.Last());
                if (a.Any(A => A == b))
                {
                    ans = a.Count + 1;
                    break;
                }

                a.Add(b);
            }

            Console.Write(ans);
            Console.ReadKey();
        }
    }

    //IOを担う関数群
    public class IO
    {
        //stringの入力
        public string ReadLineToString()
        {
            return Console.ReadLine();
        }

        //intの入力
        public int ReadLineToInt()
        {
            return int.Parse(Console.ReadLine());
        }

        //空白区切りの複数の文字列の入力をstring[]にして返す
        public string[] ReadLineToStringArray()
        {
            return Console.ReadLine().Split(' ').ToArray();
        }


        //空白区切りの複数の整数の入力をint[]にして返す
        public int[] ReadLineToIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        //空白区切りの複数の文字列の入力をList<string>で受け取る
        public List<string> ReadLineToStringList()
        {
            return Console.ReadLine().Split(' ').ToList();
        }

        //空白区切りの複数の整数の入力をList<int>で受け取る
        public List<int> ReadLineToIntList()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        }

    }

}


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

#define int long long

int n;
int a[100010];

bool isOK(int idx){
    int now = a[idx];

    for(int i = 0;i < n;i++){
        if(i != idx){
            if(now*2 >= a[i]){
                now += a[i];
            }else{
                return false;
            }
        }
    }

    return true;
}

signed main(){
    cin >> n;

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

    sort(a, a+n);

    int l = -1, r = n;

    while(r-l > 1){
        int mid = (r+l)/2;

        if(isOK(mid)){
            r = mid;
        }else{
            l = mid;
        }
    }

    cout << n-r << endl;

    return 0;
}


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

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

ll N,A,B;
ll h[100001];
ll sum;

bool C(ll x){
	ll l = x;

	rep(i,N){
		ll a = h[i];
		if(a <= B*x){
			continue;
		}

		ll b = a - B*x;
		ll c = b % (A-B) == 0 ? b / (A-B) : b / (A-B) + 1;

		l -= c;
		if(l < 0) return false;
	}
	return true;
}

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

	cin >> N >> A >> B;

	sum = 0;
	rep(i,N){
		cin >> h[i];
		sum += h[i];
	}

	ll cnt = 0;
	rep(i,N) {
		if(h[i] <= B) cnt++;
	}
	if(cnt == N){
		cout << 1 << endl;
		return 0;
	}
	ll lb = 0;
    ll ub = 1e10;
    while(ub - lb > 1){
        ll mid = (lb + ub) / 2;
        // cout << lb << "," << mid << "," << ub << "," << C(mid) << endl;
        if(C(mid)) ub = mid;
        else lb = mid;
    }
	
	cout << ub << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#define INF 1e7
using namespace std;
int dp[100001][2];

int main(void){
	while(1){
		string str;
		cin >> str;
		if(str=="#")break;
		int cnt=0,cnt2=0;
		int now=0;
		for(int i=0;i<=str.size();i++){
			dp[i][0]=dp[i][1]=INF;
		}
		dp[1][0]=0;
		dp[1][1]=0;
		for(int i=1;i<str.size();i++){
			for(int j=0;j<2;j++){
				if(dp[i][j]!=INF){
					dp[i+1][j]=min(dp[i+1][j],dp[i][j]+1);
					if(j==0 && (str[i]-'0'+2)%3>=(str[i-1]-'0'+2)%3){
						dp[i+1][1]=min(dp[i+1][1],dp[i][j]);
					}
					if(j==1 && (str[i]-'0'+2)%3<=(str[i-1]-'0'+2)%3){
						dp[i+1][0]=min(dp[i+1][0],dp[i][j]);
					}
				}
			}		}
		printf("%d\n",min(dp[str.size()][0],dp[str.size()][1]));
	}
	return 0;
}

Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  vector<char> aa(sa.size()), bb(sb.size()), cc(sc.size());
  rep(i,sa.size()){
    aa[i] = sa[i];
  }
  rep(i,sb.size()){
    bb[i] = sb[i];
  }

  rep(i,sc.size()){
    cc[i] = sc[i];
  }
  char start = 'a';
  rep(i,1000100){
    //cout << start << endl;
    //cout << aa.size() << " " << bb.size() << " " << cc.size() << endl;
   
    if(start=='a'){
      if(aa.size()==0){
        cout << "A" << endl;
        break;
      }
      start = aa[0];
      aa.erase(aa.begin());
      continue;
    }
    if(start=='b'){
      if(bb.size()==0){
        cout << "B" << endl;
        break;
      }
      start = bb[0];
      bb.erase(bb.begin());
      continue;
    }
    if(start=='c'){
      if(cc.size()==0){
        cout << "C" << endl;
        break;
      }
      start = cc[0];
      cc.erase(cc.begin());
      continue;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <iterator>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
int main(){
  string S;
  cin >> S;
  map<char,int> charnum;
  charnum['a'] = 0;
  charnum['b'] = 0;
  charnum['c'] = 0;
  FOR(i,0,S.length()){
    charnum[S[i]]++;
  }
  if(charnum['a'] == 1 && charnum['b'] == 1 && charnum['c'] == 1 ){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 380
#include <iostream>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())



template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



int main(void){
  int n, a; scanf("%d", &n);
  Vint A(n), SA(n);
  REP(i, n){
    scanf("%d", &a);
    A[i] = a; SA[i] = a;
  }
  SORT(SA);
  int HMedium = SA[n/2-1], LMedium = SA[n/2];
  REP(i, n){
    if(A[i] <= HMedium) printf("%d\n", LMedium);
    else printf("%d\n", HMedium);
  }
  return 0;
}

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

using namespace std;

using ll=long long;
void solve() {
    int n, X;
    cin >> n >> X;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    ll res = 0;
    if (a[0] > X) {
        res += a[0]-X;
        a[0] = X;
    }
    for (int i = 1; i < n; i++) {
        if (a[i]+a[i-1] > X) {
            int d = a[i]+a[i-1]-X;
            res += d;
            a[i] -= d;
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)1000003;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b=mod-2,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int Q, x, d, n, f[2002002];

signed main() {
    cin >> Q;
    f[0] = 1;
    reps(i,1,2002002) f[i] = f[i-1]*i %mod;
    while (Q--) {
        cin >> x >> d >> n;
        if (x==0) cout << 0 << endl;
        else if (d==0) cout << mop(x,n) << endl;
        else if (mod<=n) cout << 0 << endl;
        else {
            x = x * mop(d) %mod;
            if (x==0 || mod<=x+n-1) cout << 0 << endl;
            else cout << f[x+n-1] * mop(f[x-1]) %mod * mop(d,n) %mod << endl;
        }
    }
}

Measured memory_bytes: 16512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace F
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int sum = x.Sum();
            if (sum % 2 == 0) Console.WriteLine(sum / 2);
            else
            {
                Array.Sort(x);
                int a = 0;
                while (x[a] % 2 == 0) a++;
                Console.WriteLine((sum - x[a]) / 2);
            }
        }
    }
}


Measured memory_bytes: 18364
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

#define ALL(v) v.begin(), v.end()

const int MAX = 1005;
int N,M;

struct Info{
  int sum, tail;
  vector<int> K;
};


void solve(const vector<int>& L){

  vector< Info > v;
  vector<int> tmp(M);
  for(int i = 0; i < L[0]; i++) tmp[i] = 1;
  for(int i = L[0]; i < M; i++) tmp[i] = 0;
  sort(ALL(tmp));

  do{ v.push_back((Info){L[0],0,tmp});}while(next_permutation(ALL(tmp)));

  for(int i = 1; i < N; i++){
    vector< Info > nex;
    for(int j = 0; j < (int)v.size(); j++){
      Info tmp = v[j];
      tmp.sum -= tmp.K[tmp.tail++];
      if(tmp.sum == L[i]){
	tmp.K.push_back(0);
	nex.push_back(tmp);
      }else if(tmp.sum+1 == L[i]){
	tmp.K.push_back(1);
	tmp.sum++;
	nex.push_back(tmp);
      }
    }
    v = nex;
  }
  
  if(v.empty()) cout << "Goofy" << endl;
  else{
    vector<int> ans = v[0].K;
    for(int i = 0; i < (int)ans.size(); i++) cout << ans[i];
    cout << endl;
  }
}

int main(){
  while(cin >> N >> M && (N|M)){
    vector<int> L(N);
    for(int i = 0; i < N; i++) cin >> L[i];
    solve(L);
  }
  return 0;
}

Measured memory_bytes: 1468
n,c=[int(k) for k in raw_input().split(" ")]
t=[]
for i in range(n):
    t+=[tuple([int(k) for k in raw_input().split(" ")])]

ts=sorted(t)
tot=sum([k[1] for k in t])
maxperf=0
mysum=0
mpcw=[0]*n
mpccw=[0]*n
mpcwab=[0]*n
mpccwab=[0]*n

k=0
for i in ts:
    mpccw[k]=tot-mysum - (c-i[0])
    mpccwab[k]=tot-mysum - (c-i[0])*2
    mysum+=i[1]
    mpcw[k]=mysum-i[0]
    mpcwab[k]=mysum-i[0]*2
    k+=1
    
#runningmaxes
 
mpucw=[0]*(n)
mpuccw=[0]*(n)

for i in range(0,n):
    mpucw[i]=max(mpucw[i-1],mpcwab[i]) #best i can get reaching < guy i cw then coming back
    

for i in range(-1,-n-1,-1):
    mpuccw[i]=max(mpuccw[i+1],mpccwab[i]) #best i can get reaching < guy i cw then coming back
    
for i in range(n):
    maxperf=max(maxperf, mpcw[i] + (mpuccw[i+1] if i<n-1 else 0) )
    maxperf=max(maxperf, mpccw[i] + (mpucw[i-1] if i>0 else 0) )

print maxperf

Measured memory_bytes: 33524
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int X = int.Parse(input[0]);
    int Y = int.Parse(input[1]);
    int Z = int.Parse(input[2]);
    Console.WriteLine((X - Z) / (Y + Z));
  }
}

Measured memory_bytes: 13140
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

static sl N;
static string S;

void solve(void) {
  sl res = 0;
  FOR0(i1, 10) {
    FOR0(i2, 10) {
      FOR0(i3, 10) {
        sl j1, j2, j3;
        for (j1 = 0; j1 < N; j1++) {
          if (S[j1] - '0' == i1) {
            break;
          }
        }
        if (S[j1] - '0' != i1 || j1 + 2 >= N) {
          continue;
        }
        for (j2 = j1 + 1; j2 < N; j2++) {
          if (S[j2] - '0' == i2) {
            break;
          }
        }
        if (S[j2] - '0' != i2 || j2 + 1 >= N) {
          continue;
        }
        for (j3 = j2 + 1; j3 < N; j3++) {
          if (S[j3] - '0' == i3) {
            break;
          }
        }
        if (S[j3] - '0' != i3) {
          continue;
        }
        res++;
      }
    }
  }
  cout << res << endl;
}

int main(void) {
  cin >> N;
  cin >> S;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
  int N;
  cin >> N;
  double ans = 0, c = 0;
  vector<int> X(N), Y(N), I(N);
  for(int i = 0; i < N; ++i){
    cin >> X[i] >> Y[i];
    I[i] = i;
  }
  do{
    double l = 0;
    for(int i = 1; i < N; ++i){
      l += hypot(X[I[i]]-X[I[i-1]],Y[I[i]]-Y[I[i-1]]);
    }
    ans += l;
    ++c;
  }while(next_permutation(I.begin(), I.end()));
  printf("%.12f\n",ans/c);
}


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

using namespace std;

int main(){
	
	int A,B;
	
	cin >> A >> B;
	
	if(A<=8 && B<=8){
		cout << "Yay!" << endl;
	}
	else  cout << ":(" << endl;
	
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

toInts :: IO [Int]
toInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

find_x_1 :: [Int] -> Int
find_x_1 ls =
  sum
    [ if even i
      then v
      else (-v)
    | (v, i) <- zip ls [0 ..]
    ]

solver :: [Int] -> Int -> [Int]
solver ls x_1 = x_1 : [(2 * a) - x | (a, x) <- zip ls $ solver ls x_1]

solver2 :: [Int] -> Int -> [Int]
solver2 ls x_1 = scanl (\x -> \a -> (a * 2) - x) x_1 ls

show_ans :: [Int] -> String
show_ans (x:[]) = []
show_ans (v:rest) = (show v) ++ " " ++ (show_ans rest)

main :: IO ()
main = do
  _ <- toInts
  dat <- toInts
  let x_1 = find_x_1 dat
  let ans = solver2 dat x_1
  putStrLn $ show_ans ans

Measured memory_bytes: 13308
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


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


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int dx4[4] = { 1,0,0,-1 };
int dy4[4] = { 0,1,-1,0 };
int dx2[2] = { 1,0 };
int dy2[2] = { 0,1 };

/******************************************************************************************/
typedef tuple<int,int,int> tpl;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

    ll n,k;
    cin >> n >> k;
    
    n-= k*(n/k);

    cout << min(n,abs(n-k)) << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
ll mpow(ll x, ll n, ll p){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % p;
        x = x*x % p;
        n = n >> 1;
    }
    return ans;
}

int main(){
    ll n, p;
    string ss;
    cin >> n >> p >> ss;
    vec<int> s;
    rep(i, n) s.push_back(ss[i]-'0');
    reverse(s.begin(), s.end());
    ll ans;
    if (p==2 || p==5) {
        rep(i, n) {
            if (s[i]%p==0) {
                ans += n - i;
            }
        }
        cout << ans << endl;
        return 0;
    }

    vec<ll> rem(n);
    rem[0] = s[0]%p;
    rep(i, n-1) {
        rem[i+1] = s[i+1] * mpow(10, i+1, p) + rem[i];
        rem[i+1] %= p;
    }

    map<ll, ll> m;
    rep(i, n) m[rem[i]]++;

    map<ll, ll>::iterator it;
    for (it = m.begin(); it != m.end(); it++){
        if (it->first == 0) ans += it->second;
        if (it->second == 1) continue;
        else ans += it->second * (it->second-1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3320
#include <iostream>
#include <cstring>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
 
int main () {
  int k;
  cin >> k;
  int sum = 0;
  for (int i = 1; i<=k; i++){
    for (int j = 1; j<=k; j++){
      for (int l = 1; l<=k; l++){
        sum += __gcd(__gcd(i, j), l);
      }
    }
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 3640
a, b,c,d = map(int, input().split()) 
x=c-a
y=d-b
x2=c-y
x2=str(x2)
y2=d+x
y2=str(y2)
x3=a-y
x3=str(x3)

y3=b+x
y3=str(y3)
print(x2+' '+y2+' '+x3+' '+y3)

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

void swap(int *a, int *b) {
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

int main(void) {
	int *s;
	int n, sum_of_alice = 0, sum_of_bob = 0;
	scanf("%d", &n);
	s = (int *)malloc(sizeof(int)*n);
	for (int i = 0; i < n; i++) {
		scanf("%d", s + i);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - i - 1; j++) {
			if (s[j] < s[j + 1]) {
				swap(s + j, s + j + 1);
			}
		}
	}
	for (int i = 0; i < n; i += 2) {
		sum_of_alice += s[i];
	}
	for (int i = 1; i < n; i += 2) {
		sum_of_bob += s[i];
	}
	printf("%d\n", sum_of_alice - sum_of_bob);
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#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;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    ret += min(x, m - x);
  }
  printf("%d\n", ret * 2);
  return 0;
}


Measured memory_bytes: 256
def prime_factorize(n):
    l = []
    s = '{}:'.format(n)
    i = 2
    while i * i <= n:
        while n % i == 0:
            l.append(i)
            n //= i
        i += 1
    if n != 1:
        l.append(n)
    for i in l:
        s += ' {}'.format(i)
    return s


if __name__ == '__main__':
    print(prime_factorize(int(input())))



Measured memory_bytes: 5596
import math

n = int(input())
arr = [0] * n

for x in range(1,300):
    for y in range(1,300):
        for z in range(1,301):
            ans = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if ans <= n:
                arr[ans - 1] += 1

for i in range(n):
    print(arr[i])

Measured memory_bytes: 73316
class UnionFind():
    def __init__(self, n):
        self.n = n
        # 親の名(いない場合は自分)
        self.parent = list(range(n))
        # 子の数
        self.count = [0] * n

    def root(self, x):
        # xの根を返す
        if self.parent[x] == x:
            return x
        else:
            return self.root(self.parent[x])

    def union(self, x, y):
        # xとyをまとめる
        x0 = self.root(x)
        y0 = self.root(y)
        if x0 == y0:
            return
        if x0 > y0:
            x0, y0 = y0, x0
        self.parent[y0] = x0
        self.count[x0] += self.count[y0] + 1

    def size(self, x):
        # xの属する木の大きさ
        return self.count[self.root(x)] + 1

    def same(self, x, y):
        return self.root(x) == self.root(y)


N, M, K = map(int, input().split())
tree = UnionFind(N)
# 同じグループでの友達の数とブロックの数
F, B = [0] * N, [0] * N
lst = []
for m in range(M):
    a, b = map(int, input().split())
    tree.union(a - 1, b - 1)
    lst.append((a, b))
for a, b in lst:
    if tree.same(a - 1, b - 1):
        F[a - 1] += 1
        F[b - 1] += 1
for k in range(K):
    c, d = map(int, input().split())
    if tree.same(c - 1, d - 1):
        B[c - 1] += 1
        B[d - 1] += 1
# nが属する木の大きさから友達の数とブロックの数と自分を除いたのが答え
print(*[tree.size(n) - F[n] - B[n] - 1 for n in range(N)])

Measured memory_bytes: 26480
import numpy as np
n=int(input())
h=np.array(list(map(int,input().split()))+[0]*2)
dp = np.full(n+2, 10 ** 10, dtype=np.int64)
dp[0] = 0
for i in range(1,n):
    dp[i:i+2]=np.minimum(dp[i:i+2],np.abs(h[i:i+2]-h[i-1])+dp[i-1])
print(dp[n-1])

Measured memory_bytes: 22836
/* Isn't passion overrated?*/

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
double pi = 3.14159265358979323846;
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll a,b,h,m;
    cin>>a>>b>>h>>m;
    double d1 = (h*60+m)/2.0;
    double d2 = 6.0*(m+h*60);
    double angle = min(abs(d1-d2),360.0-abs(d1-d2));
    //out<<angle<<endl;
    angle = pi*angle/180;
    angle = cos(angle);
    double ans = a*a + b*b - angle*2*a*b;
    ans = sqrt(ans);
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}


Measured memory_bytes: 4244
import java.io.*;
public class Main {
    public static void main(String[] args)throws IOException{
        int x;
        String s;
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
        s = buf.readLine();
        x=Integer.parseInt(s);
         
        System.out.println(x*x*x);
         
         
         
         
    }
 
}


Measured memory_bytes: 24212
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    ll n;
    cin >> n;
    if (n == 2) {
        cout << 1 << '\n';
        return 0;
    }
    int cnt = 2;
    for (ll i=2; i*i<=n; i++) {
        if (i*i <= n-1 && (n-1) % i == 0) {
            cnt++;
            if (i != (n-1) / i) cnt++;
        } else if (n % i == 0) {
            ll temp = n;
            while (temp % i == 0) temp /= i;
            if (temp % i == 1) cnt++;
        }
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  int x;
  cin >> x;
  if(x==1){
    cout << "Hello World" << endl;
  }else{
    int a, b;
    cin >> a >> b;
    cout << a+b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int a, b, c;
    cin>>a>>b>>c;
    cout<<min({a + b, b + c, c + a});
    return 0;
}

Measured memory_bytes: 256
n=int(input())
lst=list(map(int,input().split()))
four=0
two=0
odd=0

for i in lst:
    if i%4==0:
        four+=1
    elif i%2==0:
        two+=1
    else:
        odd+=1

if four>=odd:
    print("Yes")
elif four+1==odd:
    if two==0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 85288
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc124_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            if (a == b)
            {
                Console.WriteLine(a + b);
            }
            else
            {
                int c = Math.Max(a, b);
                Console.WriteLine(c * 2 - 1);
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
string s[20];
int maxd=-1;
int g[20][20];
int h,w;
int dx[4]={1,-1,0,0},dy[4]={0,0,-1,1};
inline void bfs(int x,int y)
{
	memset(g,-1,sizeof(g));
	queue<pair<int,int> > q;
	q.push(make_pair(x,y));
	g[x][y]=0;
	while(!q.empty())
	{
		pair<int,int> p=q.front();
		q.pop();
		for(int i=0;i<4;i++)
		{
			int nx=p.first+dx[i],ny=p.second+dy[i];
			if(nx<0||nx>=h||ny<0||ny>=w||s[nx][ny]=='#'||g[nx][ny]!=-1)continue;
			q.push(make_pair(nx,ny));
			g[nx][ny]=g[p.first][p.second]+1;
			maxd=max(maxd,g[nx][ny]);
			//cout<<maxd<<endl;
		}
		//cout<<"ok";
	}
	return;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>h>>w;
	for(int i=0;i<h;i++)
	{
		cin>>s[i];
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(s[i][j]!='#')bfs(i,j);
		}
	}
	cout<<max(maxd,0)<<endl;
	return 0;
 } 

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

int main() {
    int h, n;
    cin >> h >> n;
    const int INF = 1e9 + 5;
    vector<int> dp(h+1, INF);
    dp[0] = 0;
    while (n--) {
        int x, y;
        cin >> x >> y;
        for(int i = 0; i <= h; i++) {
            int j = min(h, i + x);
            dp[j] = min(dp[j], dp[i] + y);
        }
    }

    cout << dp[h] << endl;

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  int *a = new int[n];
  int *ret = new int[n];
  ret[0] = 0;
  a[0] = 0;
  for (int i = 1; i<n; i++){
    ret[i] = 0;
    cin >> a[i];
  }
  
  for(int i=1; i<n; i++){
    //   cout << "ind" << i << ", a[i] " << a[i] << endl;
    ret[a[i]-1]++;
  }
  for(int i=0; i<n; i++){
    cout << ret[i] <<endl;
  }
}


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

int main() {
  int N;   
  cin >> N;
  vector<int> botton(N);

  int i;
  int next;
  for(i=0;i<N;i++){
    cin >> next;
    botton.at(i) = next - 1;
  }
  
  int hop;
  int light;
  hop = 0;
  light = 0;
  for(i=0;i<N;i++){
    if(botton.at(light) == 0){
      hop = -1;
      break;
    }
    if(botton.at(light) == 1){
      hop += 1;
      break;
    }
    next = botton.at(light);
    botton.at(light) = 0;
    light = next;
    hop += 1;  
  }
  cout << hop << endl;
}



Measured memory_bytes: 640