akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    int s, n;
    cin >> s >> n;

    priority_queue<pair<int, int>> pq;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        pq.emplace(x, i);
    }

    int cnt = 0, last = -1;
    for (int i = 0; i < s; i++) {
        auto top = pq.top(); pq.pop();
        if (top.second == last && !pq.empty()) {
            auto cpy = top;
            top = pq.top(); pq.pop();
            pq.push(cpy);
        }
        if (top.first > 1)
            pq.emplace(top.first - 1, top.second);
        if (top.second == last)
            cnt++;
        last = top.second;
    }

    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(x,n) for(int i=x;i<n;i++)
#define REP(y,n) for(int j=y;j<n;j++)
#define vi vector<int>
#define vvi vector<vector<int>>
signed main(){
  string S;
  int count=0;
  while(true){
    cin>>S;
    if(S=="0")break;
    rep(0,S.size()){
      count+=S[i]-48;
    }
    cout<<count<<endl;
    count=0;
  }
}



Measured memory_bytes: 3196
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
  int i;
  char S[3+2];
  int d;
  long cnt = 0;
  scanf("%d", &d);
  printf("%d\n",d + d * d+d*d*d);
  return 0;
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    int a, b, c; cin >> a >> b >> c;
    if(b / a >= c) cout << c;
    else if(b/a < c and b/a > 0) cout << b/a;
    else cout << 0;
    
    
    
    return 0;
}

Measured memory_bytes: 3624
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
#define PI 3.141592653589793238
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
void solve(){
    string s,t;cin>>s>>t;
    ll n=s.length();
    ll vis[256]={0};
    for(ll i=0;i<n;i++)vis[s[i]]++;
    ll ans=0;
    for(ll i=0;i<n;i++)
        if(s[i]!=t[i])ans++;
    cout<<ans<<endl;
}
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

//    ll t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N; cin >> N;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];

  sort(all(A));

  vector<ll> ansm(N), ansp(N);
  rep(i,N) {
    if (i == 0) ansm[i] = A[(N+1) / 2 - 1]; // 端はマイナスで一番大きいの
    else if (i % 2 == 1) ansm[i] = A[N - (i+1) / 2]; // 大きい方からつめてく
    else ansm[i] = A[i / 2 - 1]; // 小さい方からつめてく
  }
  rep (i,N) {
    if (i == 0) ansp[i] = A[N / 2];
    else if (i % 2 == 1) ansp[i] = A[i / 2];
    else ansp[i] = A[N - i / 2];
  }

  ll big,small;
  big = small = 0;
  rep(i,N) {
    if (i == 0) continue;
    big += abs(ansp[i] - ansp[i-1]);
    small += abs(ansm[i] - ansm[i-1]);
  }

  cout << max(big,small) << endl;
}

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

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    sum += v;
  }
  cout << sum / n << endl;

  return 0;
}


Measured memory_bytes: 3008
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A,B, C;
ll K;

int main() {
  INCANT;
  cin >> A >> B >> C >> K;
  int ans = K%2==0?A-B:B-A;
  cout << ans << "\n";
  return 0;
}

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

#include <iostream>
#include <vector>
// #include <map>
#include <string>
// #include <algorithm>
// #include <numeric>
// #include <limits>

using namespace std;

bool isEvenStr(const string& str) {
	// std::cout << "debug str " << str << std::endl; // debug
	if (str.size() % 2 != 0) {
		return false;
	}
	size_t half = str.size() / 2;
	string front = str.substr(0, half);
	string back = str.substr(half, half);
	// std::cout << "debug front " << front << std::endl; // debug
	return front == back;
}

int main() {
	string str;
	cin >> str;
	size_t len = str.size() - 1;
	for (; len > 1; len--) {
		if (isEvenStr(str.substr(0, len))) {
			cout << len << endl;
			return 0;
		}
	}
	cerr << "Oops" << endl;

	//std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}


Measured memory_bytes: 256
H, W = gets.split.map(&:to_i)
N = gets.to_i
A = gets.split.map(&:to_i)

F = A.zip(1..N).map{|m, n| [n] * m}.flatten
(0...H).each do |i|
  line = F[(i * W), W]
  if i.odd?
    puts line.reverse.join(' ')
  else
    puts line.join(' ')
  end
end

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

namespace ABC049C_Daydream
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] c = Console.ReadLine().ToArray();
            Array.Reverse(c);
            string s = new string(c);
            string[] words = new string[] { "maerd", "remaerd", "esare", "resare" };
            bool flag = true;

            for (int i = 0; i < s.Length;)
            {
                bool flag2 = false;
                foreach(var w in words)
                {
                    if (s.Length - i < w.Length)
                    {
                        continue;
                    }
                    else if (s.Substring(i, w.Length) == w)
                    {
                        flag2 = true;
                        i += w.Length;
                    }
                }
                if (!flag2)
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 13212
#include <stdio.h>
#include <limits.h>

int main(void) {                                                                
    int i, j, n, a[5000], sum, max;                                             
                                                                                
    while (scanf("%d", &n), n) {                                                
        max = INT_MIN;                                                          
        i = 0;                                                                  
        while (i < n) {                                                         
            scanf("%d", &a[i++]);                                               
        }                                                                       
        i = 1;                                                                  
        while (i <= n) {                                                        
            sum = 0;                                                            
            for (j = 0; j < i; j++) {                                           
                sum += a[j];                                                    
            }                                                                   
            max = max < sum ? sum : max;                                        
            for (j = i; j < n; j++) {                                           
                sum += a[j];                                                    
                sum -= a[j - i];                                                
                max = max < sum ? sum : max;                                    
            }                                                                   
            i++;                                                                
        }                                                                       
                                                                                
        printf("%d\n", max);                                                    
    }                                                                           
    return 0;                                                                   
}

Measured memory_bytes: 616
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;
    set<string> strs;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 1; j <= 5; j++) {
            string ss = s.substr(i, j);
            strs.insert(ss);
        }
    }
    int cnt = 0;
    for (auto ss : strs) {
        cnt++;
        if (cnt == k) {
            cout << ss << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1664
using System;
using System.Linq;

namespace C
{
	internal class Program
	{
		private static int h;
		private static int w;

		public static void Main(string[] args)
		{
			var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			var saveH = h = inputs[0];
			var saveW = w = inputs[1];

			if (h % 3 == 0 || w % 3 == 0)
			{
				Console.WriteLine(0);
				return;
			}

			h -= h / 3;
			var result = solve(saveH / 3 * w);
			h--;
			result = Math.Min(result, solve((saveH / 3 + 1) * w));
			h = saveH;
			w -= w / 3;
			result = Math.Min(result, solve(saveW / 3 * h));
			w--;
			result = Math.Min(result, solve((saveW / 3 + 1) * h));

			Console.WriteLine(result);
		}

		public static long solve(long firstSquare)
		{
			if (h % 2 == 0) { return Math.Abs(firstSquare - h / 2 * w); }

			if (w % 2 == 0) { return Math.Abs(firstSquare - w / 2 * h); }

			if (h > w)
			{
				var tmp1 = Math.Abs(firstSquare - h / 2 * w);
				var tmp2 = Math.Abs(firstSquare - (h / 2 + 1) * w);

				return Math.Max(tmp1, tmp2);
			}
			else
			{
				var tmp1 = Math.Abs(firstSquare - w / 2 * h);
				var tmp2 = Math.Abs(firstSquare - (w / 2 + 1) * h);

				return Math.Max(tmp1, tmp2);
			}
		}
	}
}

Measured memory_bytes: 13396
N = int(raw_input())
As = raw_input().split(" ")
Bs = raw_input().split(" ")
Cs = raw_input().split(" ")

As = [(int(i), 2) for i in As]
Bs = [(int(i), 1) for i in Bs]
Cs = [(int(i), 0) for i in Cs]

l = sorted(As + Bs + Cs, key=lambda x: x[0] + x[1] * 0.1)

ac = 0
bc = 0
cc = 0

for i in l:
    if i[1] == 2:
        ac += 1
    elif i[1] == 1:
        bc += ac
    elif i[1] == 0:
        cc += bc
print cc

Measured memory_bytes: 56376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int A = 1, G = 2, C = 3, T = 4;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

void add(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}


long long solve(int N) {
    auto dp = make_vec<long long>(N+1, 5, 5, 5); // dp[i文字][3文字前][2文字前][1文字前]
    dp[0][0][0][0] = 1;
    for (int n = 0; n < N; ++n) {
        for (int i = 0; i < 5; ++i) {
            for (int j = 0; j < 5; ++j) {
                 for (int k = 0; k < 5; ++k) {
                     for (int l = 1; l < 5; ++l) {
                         if (i == A && j == G && l == C) continue; //AG*C  * = k
                         if (i == A && k == G && l == C) continue; //A*GC  * = j
                         if (j == A && k == G && l == C) continue; //AGC
                         if (j == G && k == A && l == C) continue; //GAC
                         if (j == A && k == C && l == G) continue; //ACG
                         add(dp[n+1][j][k][l], dp[n][i][j][k]);
                     }
                }
            }
        }
    }
    long long res = 0;
    for (int i = 1; i < 5; ++i)
        for (int j = 1; j < 5; ++j)
            for (int k = 1; k < 5; ++k)
                add(res, dp[N][i][j][k]);
    return res;
}

int main()
{
    int n; cin >> n;
    cout << solve(n) << endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
	long long N, D;
	cin >> N >> D;
	int ans=0;
	for(int i=0; i<N; i++){
		long long x, y;
		cin >> x >> y;
		if(x*x+y*y<=D*D){
			ans++;
		}
	}
	cout << ans << endl;
}


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

int res;
string s;
int st;

int main()
{
    cin >> s;
    for (int i = 0; i < s.length(); i++)
        if (s[i] == 'S') st++;
        else if (s[i] == 'T')
                if (st > 0) st--;
                else res++;
    res += st;
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include<iostream>
#include <algorithm>
#include <math.h>

using namespace std;
int main(){
	int H,W,N,a_x;
	cin>>H>>W;
	cin>>N;
	int box[10000];
	int x=1,now=0;
	for(int i=0;i<N;i++,x++){
		cin>>a_x;
		for(int j=0;j<a_x;j++){
			box[now+j]=x;
		}
		now+=a_x;
	}
//出力
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(i%2==0){//偶数列
				printf("%d",box[i*W+j]);
			}else{//樹数列
				printf("%d",box[(i+1)*W-1-j]);
			}
			if(j==W-1){break;}else{printf(" ");}
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <list>
#include <stack>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ld eps = (ld)1 / 1e10;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
    fast_io;
    ll a, b;
    cin >> a >> b;
    if (b >= a) cout << "unsafe";
    else cout << "safe";
    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        bitset<16> initial, final;
        for(int i=0; i<n; ++i){
            char c;
            cin >> c;
            initial[i] = (c == 'B');
        }
        for(int i=0; i<n; ++i){
            char c;
            cin >> c;
            final[i] = (c == 'B');
        }

        vector<vector<int> > memo(1<<n, vector<int>(n, INF));
        multimap<int, pair<bitset<16>, int> > mm;
        for(int i=0; i<n; ++i){
            memo[initial.to_ulong()][i] = 0;
            mm.insert(make_pair(0, make_pair(initial, i)));
        }

        for(;;){
            int cost = mm.begin()->first;
            bitset<16> bs = mm.begin()->second.first;
            int pos = mm.begin()->second.second;
            mm.erase(mm.begin());
            if(cost > memo[bs.to_ulong()][pos])
                continue;

            if(bs == final){
                cout << cost << endl;
                break;
            }

            for(int i=0; i<n; ++i){
                for(int j=0; j<n; ++j){
                    if(!(bs[i] ^ bs[j]))
                        continue;

                    int cost2 = cost + abs(pos - i) + abs(i - j);
                    bitset<16> bs2 = bs;
                    bs2[i] = !bs2[i];
                    bs2[j] = !bs2[j];
                    if(cost2 < memo[bs2.to_ulong()][j]){
                        memo[bs2.to_ulong()][j] = cost2;
                        mm.insert(make_pair(cost2, make_pair(bs2, j)));
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 24304
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

ll gcdExtended(ll a, ll b, ll *x, ll *y); 
// Function to find modulo inverse of a 
ll inv(ll a) 
{ 
    ll x, y,m; 
    m=998244353;
    ll g = gcdExtended(a, m, &x, &y); 
    
        ll res = (x%m + m) % m; 
        return res;
     
} 
  
// C function for extended Euclidean Algorithm 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; // To store results of recursive call 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    // Update x and y using results of recursive 
    // call 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}

ll power(ll x, ll y )  
{  
    ll res = 1;     // Initialize result  
    ll p=998244353;
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}

ll fac[3*100000];

int main(){
    ll n,m,k;cin>>n>>m>>k;
	
	if(k==n-1){
		cout<<power(m,n)<<endl;return 0;
	}
	
	if(k==0){
		ll ans=(m*power(m-1,n-1))%998244353;
		cout<<ans<<endl;return 0;
	}
	
	fac[0]=1;fac[1]=1;
	
	for(int i=2;i<=n;i++){
		fac[i]=i*fac[i-1];
		fac[i]%=998244353;
	}
	
	ll ans=0,temp=1;
	
	for(int i=0;i<=k;i++){
		temp=1;
		temp*=fac[n-1];
		temp*=inv(fac[i]);
		temp%=998244353;
		temp*=inv(fac[n-1-i]);
		temp%=998244353;
		temp*=m;
		temp%=998244353;
		temp*=power(m-1,n-1-i);
		temp%=998244353;
		ans+=temp;
		ans%=998244353;
	}
	
	cout<<ans<<endl;	
	return 0;
}

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

#include <bits/stdc++.h>

using namespace std;

class BMixJuice {
public:
    void solve(istream &in, ostream &out) {
        int x, n;
        in >> x >> n;
        vector<int64_t> v(x);
        for (int i = 0; i < x; i++) {
            in >> v[i];
        }
        sort(v.begin(), v.end());
        int64_t sum = 0;
        for (int i = 0; i < x; i++) {
            if (n > 0) {
                sum += v[i];
                n--;
            } else
                break;
        }
        out << sum;
    }
};


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


Measured memory_bytes: 3624
import java.io.PrintWriter
import java.util.*

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val A = nextIntList()
    val map = HashMap<Int, Long>()
    var sum = 0L
    A.forEach { a ->
        map[a] = map.getOrDefault(a, 0L) + 1
        sum += a
    }
    val Q = nextInt()
    repeat(Q) {
        val (B, C) = nextIntList()
        val b = map[B] ?: 0L
        val c = (map[C] ?: 0L) + b
        map[B] = 0L
        map[C] = c
        sum -= B * b
        sum += C * b
        println(sum)
    }
}

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



int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	
	ini(n);
	vpii morty;
	FOR(i,0,n){
		ini(x);
		ini(x1);
		morty.push_back(make_pair(x-x1,x+x1));
	}
	
	sort(all(morty),[&](pair<int,int> x,pair<int,int> x1){return x.second<x1.second;});
	int tmp = -INF;
	int rick = 0;
	FOR(i,0,n){
		if(tmp<=morty[i].first){
			rick++;
			tmp = morty[i].second;
		}
	}
	out(rick);
	
	
















	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
using namespace std;
int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int left=a+b,right=c+d;
  if (left > right) cout << "Left";
  else if (left == right) cout << "Balanced";
  else cout << "Right";
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)

const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
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);
}
int main()
{
    int N;
    cin >> N;
    vll h(N), dp(N, INT_MAX); // dp[i] := 足場iに到着するまでに必要なコスト
    rep(i, N)
    {
        cin >> h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    rep(i, N - 2)
    {
        dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 1] - h[i + 2]));
    }
    cout << dp.back();
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
  int a,b;
  if(scanf("%d",&a)==1 && scanf("%d",&b)){}
  int i;int e=1;int tap;
  if(e==b){
    printf("0");
    return 0;
  }
  for(i=1;i<=20;i++){
    e = e-1+a;
    if(e>=b){
      tap = i;
      break;
    }
  }
  printf("%d",tap);
  return 0;
}

Measured memory_bytes: 128
def check1(H1, H2, W1, W2):
    S_min = 2 ** 50
    S_max = 0
    res1 = H1 * W1
    res2 = H1 * W2
    res3 = H2 * (W1 + W2)
    S_min = min(S_min, res1)
    S_min = min(S_min, res2)
    S_min = min(S_min, res3)
    S_max = max(S_max, res1)
    S_max = max(S_max, res2)
    S_max = max(S_max, res3)
    return S_max - S_min

def check2(H1, H2, W1, W2):
    S_min = 2 ** 50
    S_max = 0
    res1 = H1 * (W1 + W2)
    res2 = H2 * (W1)
    res3 = H2 * W2
    S_min = min(S_min, res1)
    S_min = min(S_min, res2)
    S_min = min(S_min, res3)
    S_max = max(S_max, res1)
    S_max = max(S_max, res2)
    S_max = max(S_max, res3)
    return S_max - S_min

def check3(H1, H2, W1, W2):
    S_min = 2 ** 50
    S_max = 0
    res1 = W1 * (H1 + H2)
    res2 = W2 * H1
    res3 = W2 * H2
    S_min = min(S_min, res1)
    S_min = min(S_min, res2)
    S_min = min(S_min, res3)
    S_max = max(S_max, res1)
    S_max = max(S_max, res2)
    S_max = max(S_max, res3)
    return S_max - S_min

def check4(H1, H2, W1, W2):
    S_min = 2 ** 50
    S_max = 0
    res1 = W2 * (H1 + H2)
    res2 = W1 * H1
    res3 = W1 * H2
    S_min = min(S_min, res1)
    S_min = min(S_min, res2)
    S_min = min(S_min, res3)
    S_max = max(S_max, res1)
    S_max = max(S_max, res2)
    S_max = max(S_max, res3)
    return S_max - S_min

def check_s(tmp1, tmp2, tmp3):
    S_min = 2 ** 50
    S_max = 0
    S_min = min(S_min, tmp1, tmp2, tmp3)
    S_max = max(S_max, tmp1, tmp2, tmp3)
    return S_max - S_min

if __name__ == "__main__":
    H,W = map(int, input().split())
    if (H > W):
        H,W = W,H
    if (H % 3 == 0 or W % 3 == 0):
        print (0)
        exit()
    if (H == 2 and W == 2):
        print (1)
        exit()
    H1 = H // 2
    H2 = H - H1
    W1 = W // 2
    W2 = W - W1
    result = 2 ** 50
    result = min(result, check1(H1, H2, W1, W2))
    result = min(result, check2(H1, H2, W1, W2))
    result = min(result, check3(H1, H2, W1, W2))
    result = min(result, check4(H1, H2, W1, W2))

    for x in range(1, W + 1):
        H1 = H // 2
        H2 = H - H1

        W1 = x
        W2 = W - W1

        W3 = W2 // 2
        W4 = W2 - W3

        tmp1 = W1 * H
        tmp2 = W3 * H
        tmp3 = W4 * H

        result = min(result, check_s(tmp1, tmp2, tmp3))
        tmp1 = W1 * H
        tmp2 = W2 * H1
        tmp3 = W2 * H2
        result = min(result, check_s(tmp1, tmp2, tmp3))

    for y in range(1,  H+ 1):
        H1 = y
        H2 = H - H1

        H3 = H2 // 2
        H4 = H3 - H2

        W1 = W // 2
        W2 = W - W1


        tmp1 = H1 * W
        tmp2 = H3 * W
        tmp3 = H4 * W

        result = min(result, check_s(tmp1, tmp2, tmp3))
        tmp1 = H1 * W
        tmp2 = H2 * W1
        tmp3 = H2 * W2
        result = min(result, check_s(tmp1, tmp2, tmp3))


    print (result)


Measured memory_bytes: 3320
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}
 
 
void solve(){
	int n;
	cin >> n;
	int mx = 0, sum = 0;
	rep(i, n){
		int p;
		cin >> p;
		sum += p;
		ckmax(mx, p);
	}
	cout << sum - mx / 2;
}
 
 
 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

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

int main(){
    //aが白(.)、bが黒(#)
    int a, b;
    cin >> a >> b;
    cout << ((min(a, b) + 23) / 25) * 4  + ((abs(a - b) + 50)/ 50) * 2 << " " << 100 << endl;
    if (b > a){
        int cnt = a - 1;
        while (cnt > 0){
            int tmp = 0;
            for (int i = 0; i < 25; i++){
                if (cnt == 0) break;
                cout << ".###";
                cnt--;
                tmp++;
            }
            for (int i = 0; i < 25 - tmp; i++) cout << "....";
            cout << endl;
            for (int i = 0; i < tmp; i++) cout << ".#.#";
            for (int i = 0; i < 25 - tmp; i++) cout << "....";
            cout << endl;
            for (int i = 0; i < tmp; i++) cout << ".###";
            for (int i = 0; i < 25 - tmp; i++) cout << "....";
            cout << endl;
            for (int i = 0; i < 100; i++) cout << ".";
            cout << endl;
        }
        int rmn = b - a + 1;
        int now = 1;
        while (rmn > 0){
            int tmp = 0;
            now ^= 1;
            for (int i = 0; i < 50; i++){
                if (rmn == 0) break;
                if (now) cout << "#.";
                else cout << ".#";
                rmn--;
                tmp++;
            }
            for (int i = 0; i < 50 - tmp; i++) cout << "..";
            cout << endl;
            for (int i = 0; i < 100; i++) cout << ".";
            cout << endl;
        }
    }
    else{
        int cnt = b - 1;
        while (cnt > 0){
            int tmp = 0;
            for (int i = 0; i < 25; i++){
                if (cnt == 0) break;
                cout << "#...";
                cnt--;
                tmp++;
            }
            for (int i = 0; i < 25 - tmp; i++) cout << "####";
            cout << endl;
            for (int i = 0; i < tmp; i++) cout << "#.#.";
            for (int i = 0; i < 25 - tmp; i++) cout << "####";
            cout << endl;
            for (int i = 0; i < tmp; i++) cout << "#...";
            for (int i = 0; i < 25 - tmp; i++) cout << "####";
            cout << endl;
            for (int i = 0; i < 100; i++) cout << "#";
            cout << endl;
        }
        int rmn = a - b + 1;
        int now = 1;
        while (rmn > 0){
            int tmp = 0;
            now ^= 1;
            for (int i = 0; i < 50; i++){
                if (rmn == 0) break;
                if (now) cout << "#.";
                else cout << ".#";
                rmn--;
                tmp++;
            }
            for (int i = 0; i < 50 - tmp; i++) cout << "##";
            cout << endl;
            for (int i = 0; i < 100; i++) cout << "#";
            cout << endl;
        }
    }
}




Measured memory_bytes: 256
count :: String -> Char -> Int -> [Int]
count [] _ _ = []
count (s:ss) d c = next : count ss d next
  where next = if s == d then c + 1 else c

solve :: [Int] -> [Int] -> [Int]
solve [] _ = []
solve (w:ws) (e:es) = w + e : solve ws es

main :: IO ()
main = do
  getLine
  s <- getLine
  let ws = (0:) . init $ count s 'W' 0
  let es = (++[0]) . tail . reverse $ count (reverse s) 'E' 0
  print . minimum $ solve ws es

Measured memory_bytes: 61820
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);
		
		int K = sc.nextInt();
		int X = sc.nextInt();
		
		for(int i = K-1; i>0 ; i--) {
			if(X-(i) < -1000000) {
				continue;
			}
			System.out.print(X - (i) + " ");
		}
		
		System.out.print(X + " ");
		
		for(int i = 1; i < K ; i++) {
			if(X-(i) > 1000000) {
				continue;
			}
			System.out.print(X + (i) + " ");
		}
		
	}
}

Measured memory_bytes: 23764
#include <stdio.h> 
int main(void)
{
	int a[30],w;
	int i,n;
	int x1,x2,temp;
	
	scanf("%d",&w);
	for(i=1;i<=w;i++)	a[i]=i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d,%d",&x1,&x2);
		temp=a[x1];
		a[x1]=a[x2];
		a[x2]=temp;
	}
	for(i=1;i<=w;i++) printf("%d\n",a[i]);
	
return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	ll n;
	cin >> n;
	ll a = 1,b = n;
	for(ll i = 2; i*i <= n; i++){
		if(n%i == 0){
			a = i;
			b = n/i;
		}
	}
	cout << a+b-2 << endl;
 	return 0;
}

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


int main(void){
    int N=0;
    int Q=0;
    cin >> N;
    vector<int> A(N+1);
    
    for(int i=0;i<N;i++){
        cin >> A.at(i+1);
    }
    cin >> Q;
    vector<int> B(Q+1);
    vector<int> C(Q+1);
    for(int i=0;i<Q;i++){
        cin >> B.at(i+1)>> C.at(i+1);
    }
    
    vector<int>  number(100001);
    for(int i=1;i<=N;i++){
        number.at(A.at(i))++;
    }
    
    long long sum=0;
    for(int i=1;i<=N;i++){
        sum += A.at(i);
    }
    
    for(int i=1;i<=Q;i++){
        sum += number.at(B.at(i))*(C.at(i)-B.at(i));
        cout << sum <<endl;
        number.at(C.at(i))+=number.at(B.at(i));
        number.at(B.at(i))=0;
    
    }
}


Measured memory_bytes: 4748
import collections
n=int(input())
cnt=0
tmp=[]
for i in range(1,n+1,2):
  for j in range(1,n+1):
    if i%j==0:
      tmp.append(i)
      
x=collections.Counter(tmp)
for j in x.values():
  if j==8:
    cnt+=1
print(cnt)

Measured memory_bytes: 3316
A, B, K = map(int, input().split())

if A == 0 and B == 0:
    print(A, B)
    exit()

if A >= K:
    remain_A = A - K
    remain_B = B
else:
    remain_A = 0
    remain_B = B - (K - A)
    if remain_B < 0:
        remain_B = 0

print(remain_A, remain_B)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)

const int M = 1000005;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) {
        cin >> a[i];
    }

    vector<int> cnt(M);
    for (auto x : a) {
        if (cnt[x] != 0) {
            cnt[x] = 2;
            continue;
        }
        for (int i = x; i < M; i += x) {
            cnt[i]++;
        }
    }
    int ans = 0;
    for (auto x : a) {
        if (cnt[x] == 1) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7984
#pragma GCC optimize ("O3")
//#pragma GCC target ("avx2")
#pragma GCC target (sse, sse2, sse3, ssse3, sse4,popcnt,tune=native)

#include <bits/stdc++.h>

#define FOR(i, s, e) for(int i=s; i<e; i++)
#define loop(i, n) for(int i=0; i<n; i++)
#define CIN   ios_base::sync_with_stdio(0); cin.tie(0)
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define SZ(a) (int)(a.size())
#define Read() freopen("input.cpp", "r", stdin)
#define Write() freopen("output.cpp", "w", stdout)
#define mem(a, v) memset(a, v, sizeof(a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define Unique(x)  x.erase(unique(all(x)), x.end())
#define pi acos(-1.0)
#define vec vector
#define mp make_pair
#define paii pair<int, int>
#define padd pair<dd, dd>
#define pall pair<ll, ll>
#define fr first
#define sc second
//#define endl "\n"
#define vec vector

using namespace std;

#define int long long

const int MAXN = 2e5 + 47, inf = 1e17;

void read() {
    int n;
    cin >> n;
    vec<int> val(n);
    for(int &c : val) cin >> c;
    vec<int> ans;
    loop(lvl, n) {
        int ind = -1;
        loop(i, SZ(val)) if(val[i] == i + 1) ind = i;
        if(ind == -1) {
            cout << -1 << endl;
            return;
        }
        vec<int> t;
        loop(i, SZ(val)) if(i != ind) t.pb(val[i]);
        swap(t, val);
        ans.pb(ind + 1);
    }
    reverse(all(ans));
    for(int &c : ans) cout << c << " ";
    cout << endl;
}

void solve() {
}

signed main() {
    #ifdef COFFEE_MACHINE
        Read();
        Write();
    #endif
    CIN;

    int t = 1;
    //cin >> t;
    while(t--) {
        read();
        solve();
    }
}


Measured memory_bytes: 256
/**akshaykumar99**/

#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define pp pop_back()
#define pu(x) push_back(x)
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define all(v) v.begin(),v.end()
#define f(i,x,n) for(i=x;i<n;i++)
#define rall(v) v.rbegin(),v.rend()

const int MOD=1e9+7 , INF=INT_MAX;
const long long LINF=LLONG_MAX;

typedef long long ll;
typedef long double ld;
typedef vector<int> ivc;
typedef pair<int,int> ipr;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,i,ma=0;
    cin>>n;
    int a[n],b[n];
    f(i,0,n)
    {
		cin>>a[i];
		b[i]=a[i];
	}
    sort(b,b+n);
    f(i,0,n)
    {
    	if(a[i]!=b[n-1])
    		cout<<b[n-1]<<endl;
    	else
    		cout<<b[n-2]<<endl;
	}
    

}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X;
  cin >> X;
  for(int a = X; a < 110000; a++){
    int flag = 0;
    for(int i = 2; i < a; i++){
      if(a % i == 0){
        flag = 1;
        break;
      }
    }
    if(flag == 0){
      cout << a << endl;
      break;
    }
  }
}
    
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
signed main()
{
    IOS
    int n; cin>>n;
    cout<<n*n*n;
    return 0;
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;


int main()
{
    lli a, b;
    cin >> a >> b;
    a = __gcd(a, b);
    int ans = 1;
    for(lli i=2; i*i<=a; i++){
        if(a%i == 0){
            ans++;
            while(a%i == 0){
                a /= i;
            }
        }
    }
    if(a > 1LL){
        ans++;
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
n,q = gets.chomp.split(" ").map(&:to_i)

# key: root, value: set(children)
hash = {}

arr = []
(n-1).times do |t|
  a,b = gets.chomp.split(" ").map(&:to_i)
  arr[a] ||= []
  arr[a] << b
end

i_xsum = {}
q.times do |t|
  q,x = gets.chomp.split(" ").map(&:to_i)
  i_xsum[q] ||= 0
  i_xsum[q] += x
end

result = []
(1..n).each do |i|
  xsum = i_xsum[i] || 0
  result << xsum
  (arr[i] || []).each do |a|
    i_xsum[a] ||= 0
    i_xsum[a] += xsum
  end
end

puts result.join(" ")



Measured memory_bytes: 35068
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
int const INF=1000000000;
int DP[100010];
vector<int>H(100000);
typedef long long ll;
int main(){
    int N,K;
    cin>>N>>K;
    for(int i=0;i<=100001;i++){
        DP[i]=INF;
    }
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    DP[0]=0;
    for(int i=0;i<=N;i++){
        for(int j=1;j<=K;j++){
            if(i+j<N){DP[i+j]=min(DP[i+j],DP[i]+abs(H[i]-H[i+j]));}
        }
    }
    cout<<DP[N-1]<<endl;
}

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


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

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int alice = 0;
  int bob = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      alice += a.at(i);
    }
    else bob += a.at(i);
  }
  cout << alice - bob << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    inf = 10 ** 9 + 5
    n = int(input())
    n2 = 2 ** n
    s = list(map(int, input().split()))
    s.sort(reverse=True)
    # print(s)
    pp = [s[0]]
    s[0] = inf
    for _ in range(n):
        pp.sort()
        i = 1
        np = pp[:]
        while pp:
            p = pp.pop()
            while 1:
                if s[i] < p:
                    np.append(s[i])
                    s[i] = inf
                    break
                else:
                    i += 1
                if i == n2:
                    print("No")
                    exit()
        pp = np
    print("Yes")

main()


Measured memory_bytes: 34676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 105;

int n,m,a[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	ll res=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		res+=a[i];
	}
	sort(a+1,a+1+n,greater<int>());
	double t=res*1.0/(4*m);
	ll ans=0;
	bool flag=true;
	for(int i=1;i<=m;i++){
		if(a[i]>=t) continue;
		else flag=false;
	}
	cout<<(flag?"Yes\n":"No\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define MAX 100005

int p[MAX];
int q[MAX];

int find(int x){
  if(p[x]==x)return x;
  return p[x]=find(p[x]);
}

void unite(int x,int y){
  x=find(x);y=find(y);
  if(x==y)return;
  p[x]=y;
  q[y]+=q[x];
}

bool same(int x,int y){
  return (find(x)==find(y));
}

int V,E;
vector<int> G[MAX];
vector<int> nG[MAX];
map<int,bool> used[MAX];

int s[MAX],t[MAX];
int depth[MAX];
int cnt[MAX];
int visited[MAX];
bool flg[MAX];


void dfs(int pos,int prev){
  visited[pos]=true;
  for(int i=0;i<(int)G[pos].size();i++){
    int to=G[pos][i];
    if(to==prev)continue;
    if(!visited[to]){
      depth[to]=depth[pos]+1;
      dfs(to,pos);
      cnt[pos]+=cnt[to];
      if(cnt[to])unite(pos,to);
    }else if(depth[to]<depth[pos]){
      unite(pos,to);
      cnt[pos]++;
      cnt[to]--;
    }else{
      unite(pos,to);
    }
  }
}

P solve(int pos,int prev=-1){
  int res=-1,res2=0,sum=t[pos];
  for(int i=0;i<(int)nG[pos].size();i++){
    int to=nG[pos][i];
    if(to==prev || to==pos)continue;
    P pw=solve(to,pos);
    res=max(res,pw.first);
    if(pw.first!=-1){
      sum+=pw.first;
      res2=max(res2, -pw.first+pw.second);
    }else{
      res2=max(res2,pw.second);
    }
  }
  if(q[pos]==1 && res==-1){
    return P(-1,sum+res2);
  }
  return P(sum,sum+res2);
}

int main(){
  scanf("%d %d",&V,&E);
  for(int i=0;i<V;i++){
    scanf("%d",&s[i]);
    p[i]=i;
    q[i]=1;
  }
  for(int i=0;i<E;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(0,-1);
  for(int pos=0;pos<V;pos++){
    for(int i=0;i<(int)G[pos].size();i++){
      int to=find(G[pos][i]);
      if(used[pos].count(to)>0)continue;
      used[pos][to]=true;
      nG[ find(pos) ].push_back( to );
    }
    t[ find(pos) ]+=s[pos];
  }
  P ans=solve(find(0),-1);
  printf("%d\n", ans.second);
  return 0;
}

Measured memory_bytes: 36756
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

int n,a[1 << 21],m,x;

int32_t main(){_
    //freopen("input","r",stdin);
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> a[i];
	}
	sort(a + 1,a + 1 + n);
	cin >> m;
	vector<int>vec;
	for(int i = 1;i <= m;i++)
	{
		cin >> x;
		vec.pb(x);
	}
	sort(vec.rbegin(),vec.rend());
	for(int i = 1;i <= n;i++)
	{
		if(a[i] == vec.back())
		{
			vec.pop_back();
		}
	}
	rc((sz(vec) ? "NO" : "YES"));
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  set<char> ss({s[0],s[1],s[2]});
  cout<<(ss.size()==3?"Yes":"No")<<endl;
  return 0;
}


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

int main() {
	long N, A, B;
	cin >> N >> A >> B;

	long X, Y;
	X = N / (A + B);
	Y = N % (A + B);
	
	long ans = X * A;
	if (Y > A) {
		ans += A;
	}
	else {
		ans += Y;
	}

	cout << ans;
}

Measured memory_bytes: 256